diff --git a/dom/media/MediaManager.cpp b/dom/media/MediaManager.cpp index 10bd854881fed..be32bf72c8f18 100644 --- a/dom/media/MediaManager.cpp +++ b/dom/media/MediaManager.cpp @@ -1162,19 +1162,16 @@ static const MediaTrackConstraints& GetInvariant( // Source getter returning full list -static void GetMediaDevices(MediaEngine* aEngine, uint64_t aWindowId, - MediaSourceEnum aSrcType, +static void GetMediaDevices(MediaEngine* aEngine, MediaSourceEnum aSrcType, MediaManager::MediaDeviceSet& aResult, const char* aMediaDeviceName = nullptr) { MOZ_ASSERT(MediaManager::IsInMediaThread()); - LOG("%s: aEngine=%p, aWindowId=%" PRIu64 ", aSrcType=%" PRIu8 - ", aMediaDeviceName=%s", - __func__, aEngine, aWindowId, static_cast(aSrcType), + LOG("%s: aEngine=%p, aSrcType=%" PRIu8 ", aMediaDeviceName=%s", __func__, + aEngine, static_cast(aSrcType), aMediaDeviceName ? aMediaDeviceName : "null"); nsTArray> devices; - aEngine->EnumerateDevices(aWindowId, aSrcType, MediaSinkEnum::Other, - &devices); + aEngine->EnumerateDevices(aSrcType, MediaSinkEnum::Other, &devices); /* * We're allowing multiple tabs to access the same camera for parity @@ -1803,9 +1800,8 @@ void MediaManager::GuessVideoDeviceGroupIDs(MediaDeviceSet& aDevices, */ RefPtr MediaManager::EnumerateRawDevices( - uint64_t aWindowId, MediaSourceEnum aVideoInputType, - MediaSourceEnum aAudioInputType, MediaSinkEnum aAudioOutputType, - DeviceEnumerationType aVideoInputEnumType, + MediaSourceEnum aVideoInputType, MediaSourceEnum aAudioInputType, + MediaSinkEnum aAudioOutputType, DeviceEnumerationType aVideoInputEnumType, DeviceEnumerationType aAudioInputEnumType, bool aForceNoPermRequest, const RefPtr& aOutDevices) { MOZ_ASSERT(NS_IsMainThread()); @@ -1830,10 +1826,9 @@ RefPtr MediaManager::EnumerateRawDevices( aAudioInputType == MediaSourceEnum::Microphone, "If loopback audio is requested audio type should be microphone!"); - LOG("%s: aWindowId=%" PRIu64 ", aVideoInputType=%" PRIu8 - ", aAudioInputType=%" PRIu8 ", aVideoInputEnumType=%" PRIu8 - ", aAudioInputEnumType=%" PRIu8, - __func__, aWindowId, static_cast(aVideoInputType), + LOG("%s: aVideoInputType=%" PRIu8 ", aAudioInputType=%" PRIu8 + ", aVideoInputEnumType=%" PRIu8 ", aAudioInputEnumType=%" PRIu8, + __func__, static_cast(aVideoInputType), static_cast(aAudioInputType), static_cast(aVideoInputEnumType), static_cast(aAudioInputEnumType)); @@ -1864,100 +1859,98 @@ RefPtr MediaManager::EnumerateRawDevices( Preferences::GetCString("media.audio_loopback_dev", audioLoopDev); } - RefPtr task = NewTaskFrom([holder = std::move(holder), aWindowId, - aVideoInputType, aAudioInputType, - aVideoInputEnumType, aAudioInputEnumType, - videoLoopDev, audioLoopDev, hasVideo, - hasAudio, hasAudioOutput, - fakeDeviceRequested, realDeviceRequested, - aOutDevices]() mutable { - // Only enumerate what's asked for, and only fake cams and mics. - RefPtr fakeBackend, realBackend; - if (fakeDeviceRequested) { - fakeBackend = new MediaEngineDefault(); - } - if (realDeviceRequested) { - MediaManager* manager = MediaManager::GetIfExists(); - MOZ_RELEASE_ASSERT(manager); // Must exist while media thread is alive - realBackend = manager->GetBackend(); - } + RefPtr task = NewTaskFrom( + [holder = std::move(holder), aVideoInputType, aAudioInputType, + aVideoInputEnumType, aAudioInputEnumType, videoLoopDev, audioLoopDev, + hasVideo, hasAudio, hasAudioOutput, fakeDeviceRequested, + realDeviceRequested, aOutDevices]() mutable { + // Only enumerate what's asked for, and only fake cams and mics. + RefPtr fakeBackend, realBackend; + if (fakeDeviceRequested) { + fakeBackend = new MediaEngineDefault(); + } + if (realDeviceRequested) { + MediaManager* manager = MediaManager::GetIfExists(); + MOZ_RELEASE_ASSERT(manager, "Must exist while media thread is alive"); + realBackend = manager->GetBackend(); + } - RefPtr videoBackend; - RefPtr audioBackend; - Maybe micsOfVideoBackend; - Maybe speakers; - - if (hasVideo) { - videoBackend = aVideoInputEnumType == DeviceEnumerationType::Fake - ? fakeBackend - : realBackend; - MediaDeviceSet videos; - LOG("EnumerateRawDevices Task: Getting video sources with %s backend", - videoBackend == fakeBackend ? "fake" : "real"); - GetMediaDevices(videoBackend, aWindowId, aVideoInputType, videos, - videoLoopDev.get()); - aOutDevices->AppendElements(videos); - } - if (hasAudio) { - audioBackend = aAudioInputEnumType == DeviceEnumerationType::Fake - ? fakeBackend - : realBackend; - MediaDeviceSet audios; - LOG("EnumerateRawDevices Task: Getting audio sources with %s backend", - audioBackend == fakeBackend ? "fake" : "real"); - GetMediaDevices(audioBackend, aWindowId, aAudioInputType, audios, - audioLoopDev.get()); - if (aAudioInputType == MediaSourceEnum::Microphone && - audioBackend == videoBackend) { - micsOfVideoBackend = Some(MediaDeviceSet()); - micsOfVideoBackend->AppendElements(audios); - } - aOutDevices->AppendElements(audios); - } - if (hasAudioOutput) { - MediaDeviceSet outputs; - MOZ_ASSERT(realBackend); - realBackend->EnumerateDevices(aWindowId, MediaSourceEnum::Other, - MediaSinkEnum::Speaker, &outputs); - speakers = Some(MediaDeviceSet()); - speakers->AppendElements(outputs); - aOutDevices->AppendElements(outputs); - } - if (hasVideo && aVideoInputType == MediaSourceEnum::Camera) { - MediaDeviceSet audios; - LOG("EnumerateRawDevices Task: Getting audio sources with %s backend " - "for " - "groupId correlation", - videoBackend == fakeBackend ? "fake" : "real"); - // We need to correlate cameras with audio groupIds. We use the backend - // of the camera to always do correlation on devices in the same scope. - // If we don't do this, video-only getUserMedia will not apply groupId - // constraints to the same set of groupIds as gets returned by - // enumerateDevices. - if (micsOfVideoBackend.isSome()) { - // Microphones from the same backend used for the cameras have already - // been enumerated. Avoid doing it again. - audios.AppendElements(*micsOfVideoBackend); - } else { - GetMediaDevices(videoBackend, aWindowId, MediaSourceEnum::Microphone, - audios, audioLoopDev.get()); - } - if (videoBackend == realBackend) { - // When using the real backend for video, there could also be speakers - // to correlate with. There are no fake speakers. - if (speakers.isSome()) { - // Speakers have already been enumerated. Avoid doing it again. - audios.AppendElements(*speakers); - } else { - realBackend->EnumerateDevices(aWindowId, MediaSourceEnum::Other, - MediaSinkEnum::Speaker, &audios); + RefPtr videoBackend; + RefPtr audioBackend; + Maybe micsOfVideoBackend; + Maybe speakers; + + if (hasVideo) { + videoBackend = aVideoInputEnumType == DeviceEnumerationType::Fake + ? fakeBackend + : realBackend; + MediaDeviceSet videos; + LOG("EnumerateRawDevices Task: Getting video sources with %s backend", + videoBackend == fakeBackend ? "fake" : "real"); + GetMediaDevices(videoBackend, aVideoInputType, videos, + videoLoopDev.get()); + aOutDevices->AppendElements(videos); + } + if (hasAudio) { + audioBackend = aAudioInputEnumType == DeviceEnumerationType::Fake + ? fakeBackend + : realBackend; + MediaDeviceSet audios; + LOG("EnumerateRawDevices Task: Getting audio sources with %s backend", + audioBackend == fakeBackend ? "fake" : "real"); + GetMediaDevices(audioBackend, aAudioInputType, audios, + audioLoopDev.get()); + if (aAudioInputType == MediaSourceEnum::Microphone && + audioBackend == videoBackend) { + micsOfVideoBackend = Some(MediaDeviceSet()); + micsOfVideoBackend->AppendElements(audios); + } + aOutDevices->AppendElements(audios); + } + if (hasAudioOutput) { + MediaDeviceSet outputs; + MOZ_ASSERT(realBackend); + realBackend->EnumerateDevices(MediaSourceEnum::Other, + MediaSinkEnum::Speaker, &outputs); + speakers = Some(MediaDeviceSet()); + speakers->AppendElements(outputs); + aOutDevices->AppendElements(outputs); + } + if (hasVideo && aVideoInputType == MediaSourceEnum::Camera) { + MediaDeviceSet audios; + LOG("EnumerateRawDevices Task: Getting audio sources with %s backend " + "for " + "groupId correlation", + videoBackend == fakeBackend ? "fake" : "real"); + // We need to correlate cameras with audio groupIds. We use the + // backend of the camera to always do correlation on devices in the + // same scope. If we don't do this, video-only getUserMedia will not + // apply groupId constraints to the same set of groupIds as gets + // returned by enumerateDevices. + if (micsOfVideoBackend.isSome()) { + // Microphones from the same backend used for the cameras have + // already been enumerated. Avoid doing it again. + audios.AppendElements(*micsOfVideoBackend); + } else { + GetMediaDevices(videoBackend, MediaSourceEnum::Microphone, audios, + audioLoopDev.get()); + } + if (videoBackend == realBackend) { + // When using the real backend for video, there could also be + // speakers to correlate with. There are no fake speakers. + if (speakers.isSome()) { + // Speakers have already been enumerated. Avoid doing it again. + audios.AppendElements(*speakers); + } else { + realBackend->EnumerateDevices(MediaSourceEnum::Other, + MediaSinkEnum::Speaker, &audios); + } + } + GuessVideoDeviceGroupIDs(*aOutDevices, audios); } - } - GuessVideoDeviceGroupIDs(*aOutDevices, audios); - } - holder.Resolve(false, __func__); - }); + holder.Resolve(false, __func__); + }); if (realDeviceRequested && aForceNoPermRequest && Preferences::GetBool("media.navigator.permission.device", false)) { @@ -2266,7 +2259,7 @@ void MediaManager::DeviceListChanged() { __func__); } return EnumerateRawDevices( - 0, MediaSourceEnum::Camera, MediaSourceEnum::Microphone, + MediaSourceEnum::Camera, MediaSourceEnum::Microphone, MediaSinkEnum::Speaker, DeviceEnumerationType::Normal, DeviceEnumerationType::Normal, false, devices); }, @@ -3019,7 +3012,7 @@ RefPtr MediaManager::EnumerateDevicesImpl( __func__); } return mgr->EnumerateRawDevices( - windowId, aVideoInputType, aAudioInputType, aAudioOutputType, + aVideoInputType, aAudioInputType, aAudioOutputType, aVideoInputEnumType, aAudioInputEnumType, aForceNoPermRequest, aOutDevices); }, diff --git a/dom/media/MediaManager.h b/dom/media/MediaManager.h index c0961ccd6d617..3b250261a6ba2 100644 --- a/dom/media/MediaManager.h +++ b/dom/media/MediaManager.h @@ -286,7 +286,7 @@ class MediaManager final : public nsIMediaManagerService, private: RefPtr EnumerateRawDevices( - uint64_t aWindowId, dom::MediaSourceEnum aVideoInputType, + dom::MediaSourceEnum aVideoInputType, dom::MediaSourceEnum aAudioInputType, MediaSinkEnum aAudioOutputType, DeviceEnumerationType aVideoInputEnumType, DeviceEnumerationType aAudioInputEnumType, bool aForceNoPermRequest, diff --git a/dom/media/webrtc/MediaEngine.h b/dom/media/webrtc/MediaEngine.h index 75b39e8433246..ed569a4c10bb3 100644 --- a/dom/media/webrtc/MediaEngine.h +++ b/dom/media/webrtc/MediaEngine.h @@ -41,8 +41,7 @@ class MediaEngine { * Populate an array of sources of the requested type in the nsTArray. * Also include devices that are currently unavailable. */ - virtual void EnumerateDevices(uint64_t aWindowId, dom::MediaSourceEnum, - MediaSinkEnum, + virtual void EnumerateDevices(dom::MediaSourceEnum, MediaSinkEnum, nsTArray>*) = 0; virtual void Shutdown() = 0; diff --git a/dom/media/webrtc/MediaEngineDefault.cpp b/dom/media/webrtc/MediaEngineDefault.cpp index fd3124fc3a94c..a75977e208109 100644 --- a/dom/media/webrtc/MediaEngineDefault.cpp +++ b/dom/media/webrtc/MediaEngineDefault.cpp @@ -519,7 +519,7 @@ void AudioSourcePullListener::NotifyPull(MediaTrackGraph* aGraph, } void MediaEngineDefault::EnumerateDevices( - uint64_t aWindowId, MediaSourceEnum aMediaSource, MediaSinkEnum aMediaSink, + MediaSourceEnum aMediaSource, MediaSinkEnum aMediaSink, nsTArray>* aDevices) { AssertIsOnOwningThread(); diff --git a/dom/media/webrtc/MediaEngineDefault.h b/dom/media/webrtc/MediaEngineDefault.h index 5a6ade8c001ad..573d8cc5563e4 100644 --- a/dom/media/webrtc/MediaEngineDefault.h +++ b/dom/media/webrtc/MediaEngineDefault.h @@ -136,7 +136,7 @@ class MediaEngineDefault : public MediaEngine { public: MediaEngineDefault() = default; - void EnumerateDevices(uint64_t aWindowId, dom::MediaSourceEnum, MediaSinkEnum, + void EnumerateDevices(dom::MediaSourceEnum, MediaSinkEnum, nsTArray>*) override; void Shutdown() override {} diff --git a/dom/media/webrtc/MediaEngineWebRTC.cpp b/dom/media/webrtc/MediaEngineWebRTC.cpp index c896a481e41a4..c13d024c50586 100644 --- a/dom/media/webrtc/MediaEngineWebRTC.cpp +++ b/dom/media/webrtc/MediaEngineWebRTC.cpp @@ -75,8 +75,7 @@ void MediaEngineWebRTC::SetFakeDeviceChangeEventsEnabled(bool aEnable) { } void MediaEngineWebRTC::EnumerateVideoDevices( - uint64_t aWindowId, camera::CaptureEngine aCapEngine, - nsTArray>* aDevices) { + camera::CaptureEngine aCapEngine, nsTArray>* aDevices) { AssertIsOnOwningThread(); // flag sources with cross-origin exploit potential @@ -163,7 +162,7 @@ void MediaEngineWebRTC::EnumerateVideoDevices( } void MediaEngineWebRTC::EnumerateMicrophoneDevices( - uint64_t aWindowId, nsTArray>* aDevices) { + nsTArray>* aDevices) { AssertIsOnOwningThread(); nsTArray> devices; @@ -214,7 +213,7 @@ void MediaEngineWebRTC::EnumerateMicrophoneDevices( } void MediaEngineWebRTC::EnumerateSpeakerDevices( - uint64_t aWindowId, nsTArray>* aDevices) { + nsTArray>* aDevices) { AssertIsOnOwningThread(); nsTArray> devices; @@ -248,8 +247,8 @@ void MediaEngineWebRTC::EnumerateSpeakerDevices( } void MediaEngineWebRTC::EnumerateDevices( - uint64_t aWindowId, dom::MediaSourceEnum aMediaSource, - MediaSinkEnum aMediaSink, nsTArray>* aDevices) { + dom::MediaSourceEnum aMediaSource, MediaSinkEnum aMediaSink, + nsTArray>* aDevices) { AssertIsOnOwningThread(); MOZ_ASSERT(aMediaSource != dom::MediaSourceEnum::Other || aMediaSink != MediaSinkEnum::Other); @@ -260,18 +259,18 @@ void MediaEngineWebRTC::EnumerateDevices( // value as a request for getDisplayMedia-equivalent sharing: Combine // window and fullscreen into a single list of choices. The other values // are still useful for testing. - EnumerateVideoDevices(aWindowId, camera::WinEngine, aDevices); - EnumerateVideoDevices(aWindowId, camera::BrowserEngine, aDevices); - EnumerateVideoDevices(aWindowId, camera::ScreenEngine, aDevices); + EnumerateVideoDevices(camera::WinEngine, aDevices); + EnumerateVideoDevices(camera::BrowserEngine, aDevices); + EnumerateVideoDevices(camera::ScreenEngine, aDevices); break; case dom::MediaSourceEnum::Screen: - EnumerateVideoDevices(aWindowId, camera::ScreenEngine, aDevices); + EnumerateVideoDevices(camera::ScreenEngine, aDevices); break; case dom::MediaSourceEnum::Browser: - EnumerateVideoDevices(aWindowId, camera::BrowserEngine, aDevices); + EnumerateVideoDevices(camera::BrowserEngine, aDevices); break; case dom::MediaSourceEnum::Camera: - EnumerateVideoDevices(aWindowId, camera::CameraEngine, aDevices); + EnumerateVideoDevices(camera::CameraEngine, aDevices); break; default: MOZ_CRASH("No valid video source"); @@ -285,11 +284,11 @@ void MediaEngineWebRTC::EnumerateDevices( NS_ConvertUTF8toUTF16(audioCaptureSource->GetUUID()), audioCaptureSource->GetGroupId(), u""_ns)); } else if (aMediaSource == dom::MediaSourceEnum::Microphone) { - EnumerateMicrophoneDevices(aWindowId, aDevices); + EnumerateMicrophoneDevices(aDevices); } if (aMediaSink == MediaSinkEnum::Speaker) { - EnumerateSpeakerDevices(aWindowId, aDevices); + EnumerateSpeakerDevices(aDevices); } } diff --git a/dom/media/webrtc/MediaEngineWebRTC.h b/dom/media/webrtc/MediaEngineWebRTC.h index d7d87dcc766f0..5f30488e1a3ad 100644 --- a/dom/media/webrtc/MediaEngineWebRTC.h +++ b/dom/media/webrtc/MediaEngineWebRTC.h @@ -60,7 +60,7 @@ class MediaEngineWebRTC : public MediaEngine { // Returns whether the host supports duplex audio track. bool SupportsDuplex(); - void EnumerateDevices(uint64_t aWindowId, dom::MediaSourceEnum, MediaSinkEnum, + void EnumerateDevices(dom::MediaSourceEnum, MediaSinkEnum, nsTArray>*) override; MediaEventSource& DeviceListChangeEvent() override { @@ -69,13 +69,10 @@ class MediaEngineWebRTC : public MediaEngine { private: ~MediaEngineWebRTC() = default; - void EnumerateVideoDevices(uint64_t aWindowId, - camera::CaptureEngine aCapEngine, + void EnumerateVideoDevices(camera::CaptureEngine aCapEngine, nsTArray>*); - void EnumerateMicrophoneDevices(uint64_t aWindowId, - nsTArray>*); - void EnumerateSpeakerDevices(uint64_t aWindowId, - nsTArray>*); + void EnumerateMicrophoneDevices(nsTArray>*); + void EnumerateSpeakerDevices(nsTArray>*); void DeviceListChanged() { mDeviceListChangeEvent.Notify(); }