Skip to content

Commit

Permalink
Bug 1734267 remove unused aWindowId parameter from MediaEngine::Enume…
Browse files Browse the repository at this point in the history
  • Loading branch information
karlt committed Oct 8, 2021
1 parent 53cc513 commit b53e11a
Show file tree
Hide file tree
Showing 7 changed files with 121 additions and 133 deletions.
207 changes: 100 additions & 107 deletions dom/media/MediaManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<uint8_t>(aSrcType),
LOG("%s: aEngine=%p, aSrcType=%" PRIu8 ", aMediaDeviceName=%s", __func__,
aEngine, static_cast<uint8_t>(aSrcType),
aMediaDeviceName ? aMediaDeviceName : "null");
nsTArray<RefPtr<MediaDevice>> 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
Expand Down Expand Up @@ -1803,9 +1800,8 @@ void MediaManager::GuessVideoDeviceGroupIDs(MediaDeviceSet& aDevices,
*/

RefPtr<MediaManager::MgrPromise> 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<MediaDeviceSetRefCnt>& aOutDevices) {
MOZ_ASSERT(NS_IsMainThread());
Expand All @@ -1830,10 +1826,9 @@ RefPtr<MediaManager::MgrPromise> 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<uint8_t>(aVideoInputType),
LOG("%s: aVideoInputType=%" PRIu8 ", aAudioInputType=%" PRIu8
", aVideoInputEnumType=%" PRIu8 ", aAudioInputEnumType=%" PRIu8,
__func__, static_cast<uint8_t>(aVideoInputType),
static_cast<uint8_t>(aAudioInputType),
static_cast<uint8_t>(aVideoInputEnumType),
static_cast<uint8_t>(aAudioInputEnumType));
Expand Down Expand Up @@ -1864,100 +1859,98 @@ RefPtr<MediaManager::MgrPromise> MediaManager::EnumerateRawDevices(
Preferences::GetCString("media.audio_loopback_dev", audioLoopDev);
}

RefPtr<Runnable> 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<MediaEngine> 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<Runnable> 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<MediaEngine> 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<MediaEngine> videoBackend;
RefPtr<MediaEngine> audioBackend;
Maybe<MediaDeviceSet> micsOfVideoBackend;
Maybe<MediaDeviceSet> 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<MediaEngine> videoBackend;
RefPtr<MediaEngine> audioBackend;
Maybe<MediaDeviceSet> micsOfVideoBackend;
Maybe<MediaDeviceSet> 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)) {
Expand Down Expand Up @@ -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);
},
Expand Down Expand Up @@ -3019,7 +3012,7 @@ RefPtr<MediaManager::MgrPromise> MediaManager::EnumerateDevicesImpl(
__func__);
}
return mgr->EnumerateRawDevices(
windowId, aVideoInputType, aAudioInputType, aAudioOutputType,
aVideoInputType, aAudioInputType, aAudioOutputType,
aVideoInputEnumType, aAudioInputEnumType, aForceNoPermRequest,
aOutDevices);
},
Expand Down
2 changes: 1 addition & 1 deletion dom/media/MediaManager.h
Original file line number Diff line number Diff line change
Expand Up @@ -286,7 +286,7 @@ class MediaManager final : public nsIMediaManagerService,

private:
RefPtr<MgrPromise> EnumerateRawDevices(
uint64_t aWindowId, dom::MediaSourceEnum aVideoInputType,
dom::MediaSourceEnum aVideoInputType,
dom::MediaSourceEnum aAudioInputType, MediaSinkEnum aAudioOutputType,
DeviceEnumerationType aVideoInputEnumType,
DeviceEnumerationType aAudioInputEnumType, bool aForceNoPermRequest,
Expand Down
3 changes: 1 addition & 2 deletions dom/media/webrtc/MediaEngine.h
Original file line number Diff line number Diff line change
Expand Up @@ -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<RefPtr<MediaDevice>>*) = 0;

virtual void Shutdown() = 0;
Expand Down
2 changes: 1 addition & 1 deletion dom/media/webrtc/MediaEngineDefault.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -519,7 +519,7 @@ void AudioSourcePullListener::NotifyPull(MediaTrackGraph* aGraph,
}

void MediaEngineDefault::EnumerateDevices(
uint64_t aWindowId, MediaSourceEnum aMediaSource, MediaSinkEnum aMediaSink,
MediaSourceEnum aMediaSource, MediaSinkEnum aMediaSink,
nsTArray<RefPtr<MediaDevice>>* aDevices) {
AssertIsOnOwningThread();

Expand Down
2 changes: 1 addition & 1 deletion dom/media/webrtc/MediaEngineDefault.h
Original file line number Diff line number Diff line change
Expand Up @@ -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<RefPtr<MediaDevice>>*) override;
void Shutdown() override {}

Expand Down
27 changes: 13 additions & 14 deletions dom/media/webrtc/MediaEngineWebRTC.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -75,8 +75,7 @@ void MediaEngineWebRTC::SetFakeDeviceChangeEventsEnabled(bool aEnable) {
}

void MediaEngineWebRTC::EnumerateVideoDevices(
uint64_t aWindowId, camera::CaptureEngine aCapEngine,
nsTArray<RefPtr<MediaDevice>>* aDevices) {
camera::CaptureEngine aCapEngine, nsTArray<RefPtr<MediaDevice>>* aDevices) {
AssertIsOnOwningThread();

// flag sources with cross-origin exploit potential
Expand Down Expand Up @@ -163,7 +162,7 @@ void MediaEngineWebRTC::EnumerateVideoDevices(
}

void MediaEngineWebRTC::EnumerateMicrophoneDevices(
uint64_t aWindowId, nsTArray<RefPtr<MediaDevice>>* aDevices) {
nsTArray<RefPtr<MediaDevice>>* aDevices) {
AssertIsOnOwningThread();

nsTArray<RefPtr<AudioDeviceInfo>> devices;
Expand Down Expand Up @@ -214,7 +213,7 @@ void MediaEngineWebRTC::EnumerateMicrophoneDevices(
}

void MediaEngineWebRTC::EnumerateSpeakerDevices(
uint64_t aWindowId, nsTArray<RefPtr<MediaDevice>>* aDevices) {
nsTArray<RefPtr<MediaDevice>>* aDevices) {
AssertIsOnOwningThread();

nsTArray<RefPtr<AudioDeviceInfo>> devices;
Expand Down Expand Up @@ -248,8 +247,8 @@ void MediaEngineWebRTC::EnumerateSpeakerDevices(
}

void MediaEngineWebRTC::EnumerateDevices(
uint64_t aWindowId, dom::MediaSourceEnum aMediaSource,
MediaSinkEnum aMediaSink, nsTArray<RefPtr<MediaDevice>>* aDevices) {
dom::MediaSourceEnum aMediaSource, MediaSinkEnum aMediaSink,
nsTArray<RefPtr<MediaDevice>>* aDevices) {
AssertIsOnOwningThread();
MOZ_ASSERT(aMediaSource != dom::MediaSourceEnum::Other ||
aMediaSink != MediaSinkEnum::Other);
Expand All @@ -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");
Expand All @@ -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);
}
}

Expand Down
11 changes: 4 additions & 7 deletions dom/media/webrtc/MediaEngineWebRTC.h
Original file line number Diff line number Diff line change
Expand Up @@ -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<RefPtr<MediaDevice>>*) override;

MediaEventSource<void>& DeviceListChangeEvent() override {
Expand All @@ -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<RefPtr<MediaDevice>>*);
void EnumerateMicrophoneDevices(uint64_t aWindowId,
nsTArray<RefPtr<MediaDevice>>*);
void EnumerateSpeakerDevices(uint64_t aWindowId,
nsTArray<RefPtr<MediaDevice>>*);
void EnumerateMicrophoneDevices(nsTArray<RefPtr<MediaDevice>>*);
void EnumerateSpeakerDevices(nsTArray<RefPtr<MediaDevice>>*);

void DeviceListChanged() { mDeviceListChangeEvent.Notify(); }

Expand Down

0 comments on commit b53e11a

Please sign in to comment.