Modified: trunk/Source/WebCore/ChangeLog (249001 => 249002)
--- trunk/Source/WebCore/ChangeLog 2019-08-22 11:05:12 UTC (rev 249001)
+++ trunk/Source/WebCore/ChangeLog 2019-08-22 11:05:50 UTC (rev 249002)
@@ -1,3 +1,26 @@
+2019-08-22 Youenn Fablet <[email protected]>
+
+ CaptureDeviceManager does not need to be CanMakeWeakPtr
+ https://bugs.webkit.org/show_bug.cgi?id=200936
+
+ Reviewed by Alex Christensen.
+
+ CaptureDeviceManager does not need to create a weak pointer in deviceChanged
+ since it directly calls RealtimeMediaSourceCenter singleton.
+
+ CoreAudioCaptureDeviceManager does not need to create a weak pointer since its only
+ instance is NeverDestroyed.
+ No change of behavior.
+
+ * platform/mediastream/CaptureDeviceManager.cpp:
+ (WebCore::CaptureDeviceManager::deviceChanged):
+ * platform/mediastream/CaptureDeviceManager.h:
+ * platform/mediastream/mac/CoreAudioCaptureDeviceManager.cpp:
+ (WebCore::createAudioObjectPropertyListenerBlock):
+ (WebCore::CoreAudioCaptureDeviceManager::coreAudioCaptureDevices):
+ (WebCore::CoreAudioCaptureDeviceManager::refreshAudioCaptureDevices):
+ * platform/mediastream/mac/CoreAudioCaptureDeviceManager.h:
+
2019-08-22 Chris Dumez <[email protected]>
Fix unsafe usage of MediaStreamTrackPrivate from background thread in MediaStreamTrackPrivate::audioSamplesAvailable()
Modified: trunk/Source/WebCore/platform/mediastream/CaptureDeviceManager.cpp (249001 => 249002)
--- trunk/Source/WebCore/platform/mediastream/CaptureDeviceManager.cpp 2019-08-22 11:05:12 UTC (rev 249001)
+++ trunk/Source/WebCore/platform/mediastream/CaptureDeviceManager.cpp 2019-08-22 11:05:50 UTC (rev 249002)
@@ -52,12 +52,13 @@
void CaptureDeviceManager::deviceChanged()
{
- callOnMainThread([weakThis = makeWeakPtr(*this)] {
- if (!weakThis)
- return;
-
- RealtimeMediaSourceCenter::singleton().captureDevicesChanged();
- });
+ if (!isMainThread()) {
+ callOnMainThread([] {
+ RealtimeMediaSourceCenter::singleton().captureDevicesChanged();
+ });
+ return;
+ }
+ RealtimeMediaSourceCenter::singleton().captureDevicesChanged();
}
} // namespace WebCore
Modified: trunk/Source/WebCore/platform/mediastream/CaptureDeviceManager.h (249001 => 249002)
--- trunk/Source/WebCore/platform/mediastream/CaptureDeviceManager.h 2019-08-22 11:05:12 UTC (rev 249001)
+++ trunk/Source/WebCore/platform/mediastream/CaptureDeviceManager.h 2019-08-22 11:05:50 UTC (rev 249002)
@@ -29,11 +29,10 @@
#include "CaptureDevice.h"
#include "RealtimeMediaSource.h"
-#include <wtf/WeakPtr.h>
namespace WebCore {
-class WEBCORE_EXPORT CaptureDeviceManager : public CanMakeWeakPtr<CaptureDeviceManager> {
+class WEBCORE_EXPORT CaptureDeviceManager {
public:
virtual const Vector<CaptureDevice>& captureDevices() = 0;
virtual Optional<CaptureDevice> captureDeviceWithPersistentID(CaptureDevice::DeviceType, const String&) { return WTF::nullopt; }
Modified: trunk/Source/WebCore/platform/mediastream/mac/CoreAudioCaptureDeviceManager.cpp (249001 => 249002)
--- trunk/Source/WebCore/platform/mediastream/mac/CoreAudioCaptureDeviceManager.cpp 2019-08-22 11:05:12 UTC (rev 249001)
+++ trunk/Source/WebCore/platform/mediastream/mac/CoreAudioCaptureDeviceManager.cpp 2019-08-22 11:05:50 UTC (rev 249002)
@@ -119,13 +119,9 @@
static bool initialized;
if (!initialized) {
initialized = true;
- refreshAudioCaptureDevices(DoNotNotify);
+ refreshAudioCaptureDevices(NotifyIfDevicesHaveChanged::DoNotNotify);
- auto weakThis = makeWeakPtr(*this);
- m_listenerBlock = Block_copy(^(UInt32 count, const AudioObjectPropertyAddress properties[]) {
- if (!weakThis)
- return;
-
+ auto listener = ^(UInt32 count, const AudioObjectPropertyAddress properties[]) {
for (UInt32 i = 0; i < count; ++i) {
const AudioObjectPropertyAddress& property = properties[i];
@@ -132,18 +128,18 @@
if (property.mSelector != kAudioHardwarePropertyDevices)
continue;
- weakThis->refreshAudioCaptureDevices(Notify);
+ CoreAudioCaptureDeviceManager::singleton().refreshAudioCaptureDevices(NotifyIfDevicesHaveChanged::Notify);
return;
}
- });
+ };
AudioObjectPropertyAddress address = { kAudioHardwarePropertyDevices, kAudioObjectPropertyScopeGlobal, kAudioObjectPropertyElementMaster };
- auto err = AudioObjectAddPropertyListenerBlock(kAudioObjectSystemObject, &address, dispatch_get_main_queue(), m_listenerBlock);
+ auto err = AudioObjectAddPropertyListenerBlock(kAudioObjectSystemObject, &address, dispatch_get_main_queue(), listener);
if (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);
+ err = AudioObjectAddPropertyListenerBlock(kAudioObjectSystemObject, &address, dispatch_get_main_queue(), listener);
if (err)
LOG_ERROR("CoreAudioCaptureDeviceManager::devices(%p) AudioObjectAddPropertyListener for kAudioHardwarePropertyDefaultInputDevice returned error %d (%.4s)", this, (int)err, (char*)&err);
}
@@ -220,7 +216,7 @@
m_devices.append(captureDevice);
}
- if (notify == Notify) {
+ if (notify == NotifyIfDevicesHaveChanged::Notify) {
deviceChanged();
CoreAudioCaptureSourceFactory::singleton().devicesChanged(m_devices);
}
Modified: trunk/Source/WebCore/platform/mediastream/mac/CoreAudioCaptureDeviceManager.h (249001 => 249002)
--- trunk/Source/WebCore/platform/mediastream/mac/CoreAudioCaptureDeviceManager.h 2019-08-22 11:05:12 UTC (rev 249001)
+++ trunk/Source/WebCore/platform/mediastream/mac/CoreAudioCaptureDeviceManager.h 2019-08-22 11:05:50 UTC (rev 249002)
@@ -54,13 +54,11 @@
Vector<CoreAudioCaptureDevice>& coreAudioCaptureDevices();
- enum NotifyIfDevicesHaveChanged { Notify, DoNotNotify };
+ enum class NotifyIfDevicesHaveChanged { Notify, DoNotNotify };
void refreshAudioCaptureDevices(NotifyIfDevicesHaveChanged);
Vector<CaptureDevice> m_devices;
Vector<CoreAudioCaptureDevice> m_coreAudioCaptureDevices;
-
- AudioObjectPropertyListenerBlock m_listenerBlock;
};
} // namespace WebCore