WebKit Bugzilla
Attachment 371602 Details for
Bug 198577
: mediaDevices.enumerateDevices() doesn't list the system default audio devices with deviceId as "default"
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Requests
|
Help
|
New Account
|
Log In
Remember
[x]
|
Forgot Password
Login:
[x]
[patch]
Patch
bug-198577-20190607121233.patch (text/plain), 9.26 KB, created by
youenn fablet
on 2019-06-07 12:12:33 PDT
(
hide
)
Description:
Patch
Filename:
MIME Type:
Creator:
youenn fablet
Created:
2019-06-07 12:12:33 PDT
Size:
9.26 KB
patch
obsolete
>Subversion Revision: 246170 >diff --git a/Source/WebCore/ChangeLog b/Source/WebCore/ChangeLog >index 2e5a8d1aa0272c1e1fa1d67a884e626595fc4fac..4eee4ee7c77358b5d9ee202806d0267a3b07ab6b 100644 >--- a/Source/WebCore/ChangeLog >+++ b/Source/WebCore/ChangeLog >@@ -1,3 +1,29 @@ >+2019-06-07 Youenn Fablet <youenn@apple.com> >+ >+ mediaDevices.enumerateDevices() doesn't list the system default audio devices with deviceId as "default" >+ https://bugs.webkit.org/show_bug.cgi?id=198577 >+ <rdar://problem/51454067> >+ >+ Reviewed by NOBODY (OOPS!). >+ >+ Make the system default microphone/camera be the first in the list. >+ This ensures that getUserMedia without constraints will pick these devices. >+ This also ensures enumerateDevices will show these default devices as first in the list. >+ Make sure that a default device change will refresh the list. >+ >+ For CoreAudioCaptureSource, we always add the default system input device in the list of capture devices. >+ >+ Covered by manual testing. >+ >+ * platform/mediastream/mac/AVCaptureDeviceManager.h: >+ * platform/mediastream/mac/AVCaptureDeviceManager.mm: >+ (WebCore::toCaptureDevice): >+ (WebCore::AVCaptureDeviceManager::isMatchingExistingCaptureDevice): >+ (WebCore::AVCaptureDeviceManager::refreshCaptureDevices): >+ * platform/mediastream/mac/CoreAudioCaptureDeviceManager.cpp: >+ (WebCore::getDefaultDeviceID): >+ (WebCore::CoreAudioCaptureDeviceManager::refreshAudioCaptureDevices): >+ > 2019-06-05 Said Abou-Hallawa <sabouhallawa@apple.com> > > REGRESSION (r243121): Load event should not be fired while animating the 'externalResourcesRequired' attribute >diff --git a/Source/WebCore/platform/mediastream/mac/AVCaptureDeviceManager.h b/Source/WebCore/platform/mediastream/mac/AVCaptureDeviceManager.h >index 072a259b95e8c69c89eb1e55904d0dc9314bf56f..5ff4a3a3103ab2074c49f3ab7a88aee730568afd 100644 >--- a/Source/WebCore/platform/mediastream/mac/AVCaptureDeviceManager.h >+++ b/Source/WebCore/platform/mediastream/mac/AVCaptureDeviceManager.h >@@ -51,8 +51,6 @@ public: > > static AVCaptureDeviceManager& singleton(); > >- void deviceDisconnected(AVCaptureDevice*); >- > void refreshCaptureDevices(); > > protected: >@@ -64,6 +62,7 @@ protected: > void registerForDeviceNotifications(); > Vector<CaptureDevice>& captureDevicesInternal(); > void updateCachedAVCaptureDevices(); >+ bool isMatchingExistingCaptureDevice(AVCaptureDevice*); > > RetainPtr<WebCoreAVCaptureDeviceManagerObserver> m_objcObserver; > Vector<CaptureDevice> m_devices; >diff --git a/Source/WebCore/platform/mediastream/mac/AVCaptureDeviceManager.mm b/Source/WebCore/platform/mediastream/mac/AVCaptureDeviceManager.mm >index 1c42e20d93b357d24ade6b711c89b4f527b37415..50e459638dd38958a97431397156304967cb0708 100644 >--- a/Source/WebCore/platform/mediastream/mac/AVCaptureDeviceManager.mm >+++ b/Source/WebCore/platform/mediastream/mac/AVCaptureDeviceManager.mm >@@ -122,6 +122,29 @@ void AVCaptureDeviceManager::updateCachedAVCaptureDevices() > > } > >+static inline CaptureDevice toCaptureDevice(AVCaptureDevice *device) >+{ >+ CaptureDevice captureDevice { device.uniqueID, CaptureDevice::DeviceType::Camera, device.localizedName }; >+ captureDevice.setEnabled(deviceIsAvailable(device)); >+ return captureDevice; >+} >+ >+bool AVCaptureDeviceManager::isMatchingExistingCaptureDevice(AVCaptureDevice *device) >+{ >+ auto existingCaptureDevice = captureDeviceFromPersistentID(device.uniqueID); >+ if (!existingCaptureDevice) >+ return false; >+ >+ return deviceIsAvailable(device) == existingCaptureDevice.enabled(); >+} >+ >+static inline bool isDefaultVideoCaptureDeviceFirst(const Vector<CaptureDevice>& devices, const String& defaultDeviceID) >+{ >+ if (devices.isEmpty()) >+ return false; >+ return devices[0].persistentId() == defaultDeviceID; >+} >+ > void AVCaptureDeviceManager::refreshCaptureDevices() > { > if (!m_avCaptureDevices) { >@@ -131,22 +154,27 @@ void AVCaptureDeviceManager::refreshCaptureDevices() > > updateCachedAVCaptureDevices(); > >- bool deviceHasChanged = false; > auto* currentDevices = [PAL::getAVCaptureDeviceClass() devices]; > Vector<CaptureDevice> deviceList; >- for (AVCaptureDevice *platformDevice in currentDevices) { > >+ auto* defaultVideoDevice = [PAL::getAVCaptureDeviceClass() defaultDeviceWithMediaType: AVMediaTypeVideo]; >+ >+ bool deviceHasChanged = false; >+ if (defaultVideoDevice) { >+ deviceList.append(toCaptureDevice(defaultVideoDevice)); >+ deviceHasChanged = !isDefaultVideoCaptureDeviceFirst(captureDevices(), defaultVideoDevice.uniqueID); >+ } >+ for (AVCaptureDevice *platformDevice in currentDevices) { > if (![platformDevice hasMediaType:AVMediaTypeVideo] && ![platformDevice hasMediaType:AVMediaTypeMuxed]) > continue; > >- CaptureDevice captureDevice(platformDevice.uniqueID, CaptureDevice::DeviceType::Camera, platformDevice.localizedName); >- captureDevice.setEnabled(deviceIsAvailable(platformDevice)); >- >- CaptureDevice existingCaptureDevice = captureDeviceFromPersistentID(platformDevice.uniqueID); >- if (!existingCaptureDevice || (existingCaptureDevice && existingCaptureDevice.type() == CaptureDevice::DeviceType::Camera && captureDevice.enabled() != existingCaptureDevice.enabled())) >+ if (!deviceHasChanged && !isMatchingExistingCaptureDevice(platformDevice)) > deviceHasChanged = true; > >- deviceList.append(WTFMove(captureDevice)); >+ if (platformDevice.uniqueID == defaultVideoDevice.uniqueID) >+ continue; >+ >+ deviceList.append(toCaptureDevice(platformDevice)); > } > > if (deviceHasChanged || m_devices.size() != deviceList.size()) { >diff --git a/Source/WebCore/platform/mediastream/mac/CoreAudioCaptureDeviceManager.cpp b/Source/WebCore/platform/mediastream/mac/CoreAudioCaptureDeviceManager.cpp >index 1c78ae50c16c84039514b106abae51ca95f0626f..c54898e8bcc70277ed3d44637b66a38e3b2bd298 100644 >--- a/Source/WebCore/platform/mediastream/mac/CoreAudioCaptureDeviceManager.cpp >+++ b/Source/WebCore/platform/mediastream/mac/CoreAudioCaptureDeviceManager.cpp >@@ -102,6 +102,18 @@ static bool isValidCaptureDevice(const CoreAudioCaptureDevice& device) > return !device.label().isEmpty() && !device.label().startsWith("VPAUAggregateAudioDevice"); > } > >+static inline Optional<CoreAudioCaptureDevice> getDefaultCaptureInputDevice() >+{ >+ AudioObjectPropertyAddress address { kAudioHardwarePropertyDefaultInputDevice, kAudioObjectPropertyScopeGlobal, kAudioObjectPropertyElementMaster }; >+ UInt32 propertySize = sizeof(AudioDeviceID); >+ AudioDeviceID deviceID = kAudioDeviceUnknown; >+ auto err = AudioObjectGetPropertyData(kAudioObjectSystemObject, &address, 0, nullptr, &propertySize, &deviceID); >+ >+ if (err != noErr || deviceID == kAudioDeviceUnknown) >+ return { }; >+ return CoreAudioCaptureDevice::create(deviceID); >+} >+ > Vector<CoreAudioCaptureDevice>& CoreAudioCaptureDeviceManager::coreAudioCaptureDevices() > { > static bool initialized; >@@ -128,7 +140,12 @@ Vector<CoreAudioCaptureDevice>& CoreAudioCaptureDeviceManager::coreAudioCaptureD > AudioObjectPropertyAddress address = { kAudioHardwarePropertyDevices, kAudioObjectPropertyScopeGlobal, kAudioObjectPropertyElementMaster }; > auto err = AudioObjectAddPropertyListenerBlock(kAudioObjectSystemObject, &address, dispatch_get_main_queue(), m_listenerBlock); > if (err) >- LOG_ERROR("CoreAudioCaptureDeviceManager::devices(%p) AudioObjectAddPropertyListener returned error %d (%.4s)", this, (int)err, (char*)&err); >+ LOG_ERROR("CoreAudioCaptureDeviceManager::devices(%p) AudioObjectAddPropertyListener for kAudioHardwarePropertyDevices returned error %d (%.4s)", this, (int)err, (char*)&err); >+ >+ address = { kAudioHardwarePropertyDefaultInputDevice, kAudioObjectPropertyScopeGlobal, kAudioObjectPropertyElementMaster }; >+ err = AudioObjectAddPropertyListenerBlock(kAudioObjectSystemObject, &address, dispatch_get_main_queue(), m_listenerBlock); >+ if (err) >+ LOG_ERROR("CoreAudioCaptureDeviceManager::devices(%p) AudioObjectAddPropertyListener for kAudioHardwarePropertyDefaultInputDevice returned error %d (%.4s)", this, (int)err, (char*)&err); > } > > return m_coreAudioCaptureDevices; >@@ -143,7 +160,6 @@ Optional<CoreAudioCaptureDevice> CoreAudioCaptureDeviceManager::coreAudioDeviceW > return WTF::nullopt; > } > >- > void CoreAudioCaptureDeviceManager::refreshAudioCaptureDevices(NotifyIfDevicesHaveChanged notify) > { > AudioObjectPropertyAddress address = { kAudioHardwarePropertyDevices, kAudioObjectPropertyScopeGlobal, kAudioObjectPropertyElementMaster }; >@@ -162,7 +178,13 @@ void CoreAudioCaptureDeviceManager::refreshAudioCaptureDevices(NotifyIfDevicesHa > return; > } > >+ auto defaultInputDevice = getDefaultCaptureInputDevice(); > bool haveDeviceChanges = false; >+ if (defaultInputDevice && !m_coreAudioCaptureDevices.isEmpty() && m_coreAudioCaptureDevices.first().deviceID() != defaultInputDevice->deviceID()) { >+ m_coreAudioCaptureDevices = Vector<CoreAudioCaptureDevice>::from(WTFMove(*defaultInputDevice)); >+ haveDeviceChanges = true; >+ } >+ > for (size_t i = 0; i < deviceCount; i++) { > AudioObjectID deviceID = deviceIDs[i]; > if (!deviceHasInputStreams(deviceID))
You cannot view the attachment while viewing its details because your browser does not support IFRAMEs.
View the attachment on a separate page
.
View Attachment As Diff
View Attachment As Raw
Actions:
View
|
Formatted Diff
|
Diff
Attachments on
bug 198577
:
371432
|
371433
|
371596
| 371602