⚠ Archived content — this site is no longer maintained.   Current WebKit documentation is at docs.webkit.org.

Changeset 249002 in webkit


Ignore:
Timestamp:
Aug 22, 2019, 4:05:50 AM (7 years ago)
Author:
youenn@apple.com
Message:

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:
Location:
trunk/Source/WebCore
Files:
5 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/WebCore/ChangeLog

    r249000 r249002  
     12019-08-22  Youenn Fablet  <youenn@apple.com>
     2
     3        CaptureDeviceManager does not need to be CanMakeWeakPtr
     4        https://bugs.webkit.org/show_bug.cgi?id=200936
     5
     6        Reviewed by Alex Christensen.
     7
     8        CaptureDeviceManager does not need to create a weak pointer in deviceChanged
     9        since it directly calls RealtimeMediaSourceCenter singleton.
     10
     11        CoreAudioCaptureDeviceManager does not need to create a weak pointer since its only
     12        instance is NeverDestroyed.
     13        No change of behavior.
     14
     15        * platform/mediastream/CaptureDeviceManager.cpp:
     16        (WebCore::CaptureDeviceManager::deviceChanged):
     17        * platform/mediastream/CaptureDeviceManager.h:
     18        * platform/mediastream/mac/CoreAudioCaptureDeviceManager.cpp:
     19        (WebCore::createAudioObjectPropertyListenerBlock):
     20        (WebCore::CoreAudioCaptureDeviceManager::coreAudioCaptureDevices):
     21        (WebCore::CoreAudioCaptureDeviceManager::refreshAudioCaptureDevices):
     22        * platform/mediastream/mac/CoreAudioCaptureDeviceManager.h:
     23
    1242019-08-22  Chris Dumez  <cdumez@apple.com>
    225
  • trunk/Source/WebCore/platform/mediastream/CaptureDeviceManager.cpp

    r235115 r249002  
    5353void CaptureDeviceManager::deviceChanged()
    5454{
    55     callOnMainThread([weakThis = makeWeakPtr(*this)] {
    56         if (!weakThis)
    57             return;
    58 
    59         RealtimeMediaSourceCenter::singleton().captureDevicesChanged();
    60     });
     55    if (!isMainThread()) {
     56        callOnMainThread([] {
     57            RealtimeMediaSourceCenter::singleton().captureDevicesChanged();
     58        });
     59        return;
     60    }
     61    RealtimeMediaSourceCenter::singleton().captureDevicesChanged();
    6162}
    6263
  • trunk/Source/WebCore/platform/mediastream/CaptureDeviceManager.h

    r239427 r249002  
    3030#include "CaptureDevice.h"
    3131#include "RealtimeMediaSource.h"
    32 #include <wtf/WeakPtr.h>
    3332
    3433namespace WebCore {
    3534
    36 class WEBCORE_EXPORT CaptureDeviceManager : public CanMakeWeakPtr<CaptureDeviceManager> {
     35class WEBCORE_EXPORT CaptureDeviceManager {
    3736public:
    3837    virtual const Vector<CaptureDevice>& captureDevices() = 0;
  • trunk/Source/WebCore/platform/mediastream/mac/CoreAudioCaptureDeviceManager.cpp

    r246215 r249002  
    120120    if (!initialized) {
    121121        initialized = true;
    122         refreshAudioCaptureDevices(DoNotNotify);
    123 
    124         auto weakThis = makeWeakPtr(*this);
    125         m_listenerBlock = Block_copy(^(UInt32 count, const AudioObjectPropertyAddress properties[]) {
    126             if (!weakThis)
    127                 return;
    128 
     122        refreshAudioCaptureDevices(NotifyIfDevicesHaveChanged::DoNotNotify);
     123
     124        auto listener = ^(UInt32 count, const AudioObjectPropertyAddress properties[]) {
    129125            for (UInt32 i = 0; i < count; ++i) {
    130126                const AudioObjectPropertyAddress& property = properties[i];
     
    133129                    continue;
    134130
    135                 weakThis->refreshAudioCaptureDevices(Notify);
     131                CoreAudioCaptureDeviceManager::singleton().refreshAudioCaptureDevices(NotifyIfDevicesHaveChanged::Notify);
    136132                return;
    137133            }
    138         });
     134        };
    139135
    140136        AudioObjectPropertyAddress address = { kAudioHardwarePropertyDevices, kAudioObjectPropertyScopeGlobal, kAudioObjectPropertyElementMaster };
    141         auto err = AudioObjectAddPropertyListenerBlock(kAudioObjectSystemObject, &address, dispatch_get_main_queue(), m_listenerBlock);
     137        auto err = AudioObjectAddPropertyListenerBlock(kAudioObjectSystemObject, &address, dispatch_get_main_queue(), listener);
    142138        if (err)
    143139            LOG_ERROR("CoreAudioCaptureDeviceManager::devices(%p) AudioObjectAddPropertyListener for kAudioHardwarePropertyDevices returned error %d (%.4s)", this, (int)err, (char*)&err);
    144140
    145141        address = { kAudioHardwarePropertyDefaultInputDevice, kAudioObjectPropertyScopeGlobal, kAudioObjectPropertyElementMaster };
    146         err = AudioObjectAddPropertyListenerBlock(kAudioObjectSystemObject, &address, dispatch_get_main_queue(), m_listenerBlock);
     142        err = AudioObjectAddPropertyListenerBlock(kAudioObjectSystemObject, &address, dispatch_get_main_queue(), listener);
    147143        if (err)
    148144            LOG_ERROR("CoreAudioCaptureDeviceManager::devices(%p) AudioObjectAddPropertyListener for kAudioHardwarePropertyDefaultInputDevice returned error %d (%.4s)", this, (int)err, (char*)&err);
     
    221217    }
    222218
    223     if (notify == Notify) {
     219    if (notify == NotifyIfDevicesHaveChanged::Notify) {
    224220        deviceChanged();
    225221        CoreAudioCaptureSourceFactory::singleton().devicesChanged(m_devices);
  • trunk/Source/WebCore/platform/mediastream/mac/CoreAudioCaptureDeviceManager.h

    r239531 r249002  
    5555    Vector<CoreAudioCaptureDevice>& coreAudioCaptureDevices();
    5656
    57     enum NotifyIfDevicesHaveChanged { Notify, DoNotNotify };
     57    enum class NotifyIfDevicesHaveChanged { Notify, DoNotNotify };
    5858    void refreshAudioCaptureDevices(NotifyIfDevicesHaveChanged);
    5959
    6060    Vector<CaptureDevice> m_devices;
    6161    Vector<CoreAudioCaptureDevice> m_coreAudioCaptureDevices;
    62 
    63     AudioObjectPropertyListenerBlock m_listenerBlock;
    6462};
    6563
Note: See TracChangeset for help on using the changeset viewer.