diff --git a/dom/media/AudioDeviceInfo.cpp b/dom/media/AudioDeviceInfo.cpp index 7d62c7ae80a4..5aa51ba46ea8 100644 --- a/dom/media/AudioDeviceInfo.cpp +++ b/dom/media/AudioDeviceInfo.cpp @@ -101,6 +101,11 @@ uint32_t AudioDeviceInfo::State() const return mState; } +bool AudioDeviceInfo::Preferred() const +{ + return mPreferred; +} + /* readonly attribute DOMString name; */ NS_IMETHODIMP AudioDeviceInfo::GetName(nsAString& aName) diff --git a/dom/media/AudioDeviceInfo.h b/dom/media/AudioDeviceInfo.h index d2e0fbc14539..01de5d420c98 100644 --- a/dom/media/AudioDeviceInfo.h +++ b/dom/media/AudioDeviceInfo.h @@ -41,6 +41,7 @@ public: uint32_t MaxChannels() const; uint32_t Type() const; uint32_t State() const; + bool Preferred() const; private: virtual ~AudioDeviceInfo() = default; diff --git a/dom/media/webrtc/MediaEngineWebRTC.cpp b/dom/media/webrtc/MediaEngineWebRTC.cpp index 089b6c507455..326685dddbad 100644 --- a/dom/media/webrtc/MediaEngineWebRTC.cpp +++ b/dom/media/webrtc/MediaEngineWebRTC.cpp @@ -206,14 +206,31 @@ MediaEngineWebRTC::EnumerateMicrophoneDevices(uint64_t aWindowId, MOZ_ASSERT(devices[i]->Type() == CUBEB_DEVICE_TYPE_INPUT); RefPtr source = new MediaEngineWebRTCMicrophoneSource( - devices[i], - devices[i]->Name(), - // Lie and provide the name as UUID - NS_LossyConvertUTF16toASCII(devices[i]->Name()), - devices[i]->MaxChannels(), - mDelayAgnostic, - mExtendedFilter); - aDevices->AppendElement(source); + devices[i], + devices[i]->Name(), + // Lie and provide the name as UUID + NS_ConvertUTF16toUTF8(devices[i]->Name()), + devices[i]->MaxChannels(), + mDelayAgnostic, + mExtendedFilter); + RefPtr device = MakeRefPtr( + source, + source->GetName(), + NS_ConvertUTF8toUTF16(source->GetUUID())); + if (devices[i]->Preferred()) { +#ifdef DEBUG + if (!foundPreferredDevice) { + foundPreferredDevice = true; + } else { + MOZ_ASSERT(!foundPreferredDevice, + "Found more than one preferred audio input device" + "while enumerating"); + } +#endif + aDevices->InsertElementAt(0, device); + } else { + aDevices->AppendElement(device); + } } } } @@ -225,16 +242,15 @@ MediaEngineWebRTC::EnumerateSpeakerDevices(uint64_t aWindowId, nsTArray> devices; CubebUtils::GetDeviceCollection(devices, CubebUtils::Output); for (auto& device : devices) { - MOZ_ASSERT(device->GetDeviceID().isSome()); if (device->State() == CUBEB_DEVICE_STATE_ENABLED) { MOZ_ASSERT(device->Type() == CUBEB_DEVICE_TYPE_OUTPUT); - nsString uuid(device->FriendlyName()); + nsString uuid(device->Name()); // If, for example, input and output are in the same device, uuid // would be the same for both which ends up to create the same // deviceIDs (in JS). uuid.Append(NS_LITERAL_STRING("_Speaker")); aDevices->AppendElement(MakeRefPtr( - device->FriendlyName(), + device->Name(), dom::MediaDeviceKind::Audiooutput, uuid)); }