Bug 1769985 add a dummy default audio output device to enumerate devices results when the first exposed output device is not the default r=jib

This is the simplest of the variations of the proposal at
https://github.com/w3c/mediacapture-output/issues/133#issuecomment-1271122304

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
This commit is contained in:
Karl Tomlinson 2022-10-24 23:35:03 +00:00
parent 1a5132c440
commit bd93a7111f
2 changed files with 20 additions and 2 deletions

View File

@ -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) {
@ -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;

View File

@ -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