Skip to content

Commit

Permalink
Bug 1769985 add a dummy default audio output device to enumerate devi…
Browse files Browse the repository at this point in the history
…ces results when the first exposed output device is not the default r=jib

This is the simplest of the variations of the proposal at
w3c/mediacapture-output#133 (comment)

Creating the dummy output in FilterExposedDevices(), rather than later in
the enumerateDevices() process, provides a "devicechange" event when an
exposed device becomes or ceases to be the default device.

Differential Revision: https://phabricator.services.mozilla.com/D159013
  • Loading branch information
karlt committed Oct 24, 2022
1 parent 1a5132c commit bd93a71
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 2 deletions.
15 changes: 15 additions & 0 deletions dom/media/MediaDevices.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -236,6 +236,8 @@ RefPtr<MediaDeviceSetRefCnt> MediaDevices::FilterExposedDevices(
// they are exposed only when explicitly and individually allowed by the
// user.
}
bool outputIsDefault = true; // First output is the default.
bool haveDefaultOutput = false;
nsTHashSet<nsString> exposedMicrophoneGroupIds;
for (const auto& device : aDevices) {
switch (device->mKind) {
Expand All @@ -259,8 +261,21 @@ RefPtr<MediaDeviceSetRefCnt> MediaDevices::FilterExposedDevices(
(!mExplicitlyGrantedAudioOutputRawIds.Contains(device->mRawID) &&
// Assumes aDevices order has microphones before speakers.
!exposedMicrophoneGroupIds.Contains(device->mRawGroupID))) {
outputIsDefault = false;
continue;
}
if (!haveDefaultOutput && !outputIsDefault) {
// Insert a virtual default device so that the first enumerated
// device is the default output.
RefPtr info = new AudioDeviceInfo(
nullptr, u""_ns, u""_ns, u""_ns, CUBEB_DEVICE_TYPE_OUTPUT,
CUBEB_DEVICE_STATE_ENABLED, CUBEB_DEVICE_PREF_ALL,
CUBEB_DEVICE_FMT_ALL, CUBEB_DEVICE_FMT_S16NE, 2, 44100, 44100,
44100, 128, 128);
exposed->AppendElement(
new MediaDevice(new MediaEngineFake(), info, u""_ns));
}
haveDefaultOutput = true;
break;
case MediaDeviceKind::EndGuard_:
continue;
Expand Down
7 changes: 5 additions & 2 deletions dom/media/MediaManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2868,8 +2868,11 @@ RefPtr<LocalDeviceSetPromise> MediaManager::AnonymizeDevices(
RefPtr anonymized = new LocalMediaDeviceSetRefCnt();
for (const RefPtr<MediaDevice>& device : *rawDevices) {
nsString id = device->mRawID;
nsContentUtils::AnonymizeId(id, aOriginKey);

// An empty id represents a virtual default device, for which
// the exposed deviceId is the empty string.
if (!id.IsEmpty()) {
nsContentUtils::AnonymizeId(id, aOriginKey);
}
nsString groupId = device->mRawGroupID;
// Use window id to salt group id in order to make it session
// based as required by the spec. This does not provide unique
Expand Down

0 comments on commit bd93a71

Please sign in to comment.