Changeset 252961 in webkit


Ignore:
Timestamp:
Nov 30, 2019 11:08:09 AM (4 years ago)
Author:
youenn@apple.com
Message:

Simplify CoreAudioCaptureSource suspension logic
https://bugs.webkit.org/show_bug.cgi?id=201720

Reviewed by Eric Carlson.

Instead of going through the source to suspend/resume the audio unit,
we directly go to the shared unit, which nows notifies the clients that they are muted or unmuted.

To simplify things, we no longer schedule tasks to resume/suspend/reconfigure.
All of these orders are started from the main thread synchronously.

No observable change of behavior.

  • platform/mediastream/mac/BaseAudioSharedUnit.cpp:

(WebCore::BaseAudioSharedUnit::startProducingData):
(WebCore::BaseAudioSharedUnit::reconfigure):
(WebCore::BaseAudioSharedUnit::resume):
(WebCore::BaseAudioSharedUnit::suspend):

  • platform/mediastream/mac/BaseAudioSharedUnit.h:
  • platform/mediastream/mac/CoreAudioCaptureSource.cpp:

(WebCore::CoreAudioCaptureSourceFactory::beginInterruption):
(WebCore::CoreAudioCaptureSourceFactory::endInterruption):
(WebCore::CoreAudioCaptureSourceFactory::scheduleReconfiguration):
(WebCore::CoreAudioCaptureSource::initializeToStartProducingData):
(WebCore::CoreAudioCaptureSource::startProducingData):
(WebCore::CoreAudioCaptureSource::stopProducingData):
(WebCore::CoreAudioCaptureSource::settingsDidChange):
(WebCore::CoreAudioCaptureSource::scheduleReconfiguration): Deleted.
(WebCore::CoreAudioCaptureSource::beginInterruption): Deleted.
(WebCore::CoreAudioCaptureSource::endInterruption): Deleted.

  • platform/mediastream/mac/CoreAudioCaptureSource.h:
Location:
trunk/Source/WebCore
Files:
5 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/WebCore/ChangeLog

    r252960 r252961  
     12019-11-30  youenn fablet  <youenn@apple.com>
     2
     3        Simplify CoreAudioCaptureSource suspension logic
     4        https://bugs.webkit.org/show_bug.cgi?id=201720
     5
     6        Reviewed by Eric Carlson.
     7
     8        Instead of going through the source to suspend/resume the audio unit,
     9        we directly go to the shared unit, which nows notifies the clients that they are muted or unmuted.
     10
     11        To simplify things, we no longer schedule tasks to resume/suspend/reconfigure.
     12        All of these orders are started from the main thread synchronously.
     13
     14        No observable change of behavior.
     15
     16        * platform/mediastream/mac/BaseAudioSharedUnit.cpp:
     17        (WebCore::BaseAudioSharedUnit::startProducingData):
     18        (WebCore::BaseAudioSharedUnit::reconfigure):
     19        (WebCore::BaseAudioSharedUnit::resume):
     20        (WebCore::BaseAudioSharedUnit::suspend):
     21        * platform/mediastream/mac/BaseAudioSharedUnit.h:
     22        * platform/mediastream/mac/CoreAudioCaptureSource.cpp:
     23        (WebCore::CoreAudioCaptureSourceFactory::beginInterruption):
     24        (WebCore::CoreAudioCaptureSourceFactory::endInterruption):
     25        (WebCore::CoreAudioCaptureSourceFactory::scheduleReconfiguration):
     26        (WebCore::CoreAudioCaptureSource::initializeToStartProducingData):
     27        (WebCore::CoreAudioCaptureSource::startProducingData):
     28        (WebCore::CoreAudioCaptureSource::stopProducingData):
     29        (WebCore::CoreAudioCaptureSource::settingsDidChange):
     30        (WebCore::CoreAudioCaptureSource::scheduleReconfiguration): Deleted.
     31        (WebCore::CoreAudioCaptureSource::beginInterruption): Deleted.
     32        (WebCore::CoreAudioCaptureSource::endInterruption): Deleted.
     33        * platform/mediastream/mac/CoreAudioCaptureSource.h:
     34
    1352019-11-30  youenn fablet  <youenn@apple.com>
    236
  • trunk/Source/WebCore/platform/mediastream/mac/BaseAudioSharedUnit.cpp

    r252660 r252961  
    7878        return;
    7979
     80    if (m_suspended) {
     81        RELEASE_LOG_INFO(WebRTC, "BaseAudioSharedUnit::startProducingData - exiting early as suspended");
     82        return;
     83    }
     84
    8085    if (hasAudioUnit()) {
    8186        cleanupAudioUnit();
     
    8590    if (startInternal())
    8691        captureFailed();
    87 }
    88 
    89 OSStatus BaseAudioSharedUnit::resume()
    90 {
    91     ASSERT(isMainThread());
    92     ASSERT(m_suspended);
    93     ASSERT(!isProducingData());
    94 
    95     m_suspended = false;
    96 
    97     if (!hasAudioUnit())
    98         return 0;
    99 
    100     startInternal();
    101 
    102     return 0;
    10392}
    10493
     
    143132}
    144133
     134void BaseAudioSharedUnit::reconfigure()
     135{
     136    ASSERT(isMainThread());
     137    if (m_suspended) {
     138        m_needsReconfiguration = true;
     139        return;
     140    }
     141    reconfigureAudioUnit();
     142}
     143
     144OSStatus BaseAudioSharedUnit::resume()
     145{
     146    ASSERT(isMainThread());
     147    ASSERT(m_suspended);
     148    ASSERT(!isProducingData());
     149
     150    RELEASE_LOG_INFO(WebRTC, "BaseAudioSharedUnit::resume");
     151
     152    m_suspended = false;
     153
     154    if (m_needsReconfiguration) {
     155        m_needsReconfiguration = false;
     156        reconfigure();
     157    }
     158
     159    if (!hasAudioUnit())
     160        return 0;
     161
     162    if (m_producingCount)
     163        startInternal();
     164
     165    forEachClient([](auto& client) {
     166        client.notifyMutedChange(false);
     167    });
     168
     169    return 0;
     170}
     171
    145172OSStatus BaseAudioSharedUnit::suspend()
    146173{
    147174    ASSERT(isMainThread());
    148175
     176    RELEASE_LOG_INFO(WebRTC, "BaseAudioSharedUnit::suspend");
     177
    149178    m_suspended = true;
    150179    stopInternal();
     180
     181    forEachClient([](auto& client) {
     182        client.notifyMutedChange(true);
     183    });
    151184
    152185    return 0;
  • trunk/Source/WebCore/platform/mediastream/mac/BaseAudioSharedUnit.h

    r252660 r252961  
    4242    void startProducingData();
    4343    void stopProducingData();
     44    void reconfigure();
    4445    virtual bool isProducingData() const = 0;
    4546
     
    6768    virtual bool hasAudioUnit() const = 0;
    6869    virtual void setCaptureDevice(String&&, uint32_t) = 0;
    69     virtual OSStatus reconfigureAudioUnit() = 0;
    7070
    7171    virtual CapabilityValueOrRange sampleRateCapacities() const = 0;
     
    7979    virtual OSStatus startInternal() = 0;
    8080    virtual void stopInternal() = 0;
     81    virtual OSStatus reconfigureAudioUnit() = 0;
    8182
    8283    void setSuspended(bool value) { m_suspended = value; }
     
    8990    int m_sampleRate;
    9091    bool m_suspended { false };
     92    bool m_needsReconfiguration { false };
    9193
    9294    int32_t m_producingCount { 0 };
  • trunk/Source/WebCore/platform/mediastream/mac/CoreAudioCaptureSource.cpp

    r252681 r252961  
    278278    }
    279279    m_ioUnitInitialized = true;
    280     setSuspended(false);
    281280
    282281    unduck();
     
    648647        return;
    649648    }
    650     ASSERT(isMainThread());
    651 
    652     if (auto* source = coreAudioActiveSource()) {
    653         source->beginInterruption();
    654         return;
    655     }
    656649    CoreAudioSharedUnit::singleton().suspend();
    657650}
     
    665658        return;
    666659    }
    667     ASSERT(isMainThread());
    668 
    669     if (auto* source = coreAudioActiveSource()) {
    670         source->endInterruption();
    671         return;
    672     }
    673     CoreAudioSharedUnit::singleton().reconfigureAudioUnit();
     660    CoreAudioSharedUnit::singleton().resume();
    674661}
    675662
     
    682669        return;
    683670    }
    684     ASSERT(isMainThread());
    685 
    686     if (auto* source = coreAudioActiveSource()) {
    687         source->scheduleReconfiguration();
    688         return;
    689     }
    690     CoreAudioSharedUnit::singleton().reconfigureAudioUnit();
     671    CoreAudioSharedUnit::singleton().reconfigure();
    691672}
    692673
     
    737718
    738719    if (shouldReconfigure)
    739         scheduleReconfiguration();
     720        unit.reconfigure();
    740721
    741722    unit.addClient(*this);
     
    757738#endif
    758739
    759     auto& unit = this->unit();
    760 
    761     auto isSuspended = unit.isSuspended();
    762     ALWAYS_LOG_IF(loggerPtr(), LOGIDENTIFIER, isSuspended);
    763 
    764     if (isSuspended) {
    765         m_suspendType = SuspensionType::WhilePlaying;
    766         return;
    767     }
    768 
    769740    initializeToStartProducingData();
    770     unit.startProducingData();
     741    unit().startProducingData();
    771742}
    772743
    773744void CoreAudioCaptureSource::stopProducingData()
    774745{
    775     auto& unit = this->unit();
    776 
    777     auto isSuspended = unit.isSuspended();
    778     ALWAYS_LOG_IF(loggerPtr(), LOGIDENTIFIER, isSuspended);
    779 
    780     if (isSuspended) {
    781         m_suspendType = SuspensionType::WhilePaused;
    782         return;
    783     }
    784 
    785     unit.stopProducingData();
     746    unit().stopProducingData();
    786747}
    787748
     
    823784void CoreAudioCaptureSource::settingsDidChange(OptionSet<RealtimeMediaSourceSettings::Flag> settings)
    824785{
     786    bool shouldReconfigure = false;
    825787    if (settings.contains(RealtimeMediaSourceSettings::Flag::EchoCancellation)) {
    826788        unit().setEnableEchoCancellation(echoCancellation());
    827         scheduleReconfiguration();
     789        shouldReconfigure = true;
    828790    }
    829791    if (settings.contains(RealtimeMediaSourceSettings::Flag::SampleRate)) {
    830792        unit().setSampleRate(sampleRate());
    831         scheduleReconfiguration();
    832     }
     793        shouldReconfigure = true;
     794    }
     795    if (shouldReconfigure)
     796        unit().reconfigure();
    833797
    834798    m_currentSettings = WTF::nullopt;
    835799}
    836800
    837 void CoreAudioCaptureSource::scheduleReconfiguration()
    838 {
    839     ALWAYS_LOG_IF(loggerPtr(), LOGIDENTIFIER);
    840 
    841     ASSERT(isMainThread());
    842     auto& unit = this->unit();
    843     if (!unit.hasAudioUnit() || m_reconfigurationState != ReconfigurationState::None)
    844         return;
    845 
    846     m_reconfigurationState = ReconfigurationState::Ongoing;
    847     scheduleDeferredTask([this, &unit] {
    848         if (unit.isSuspended()) {
    849             m_reconfigurationState = ReconfigurationState::Required;
    850             return;
    851         }
    852 
    853         unit.reconfigureAudioUnit();
    854         m_reconfigurationState = ReconfigurationState::None;
    855     });
    856 }
    857 
    858 void CoreAudioCaptureSource::beginInterruption()
    859 {
    860     ALWAYS_LOG_IF(loggerPtr(), LOGIDENTIFIER);
    861 
    862     ASSERT(isMainThread());
    863     auto& unit = this->unit();
    864     if (!unit.hasAudioUnit() || unit.isSuspended() || m_suspendPending)
    865         return;
    866 
    867     m_suspendPending = true;
    868     scheduleDeferredTask([this, &unit] {
    869         m_suspendType = unit.isProducingData() ? SuspensionType::WhilePlaying : SuspensionType::WhilePaused;
    870         unit.suspend();
    871         notifyMutedChange(true);
    872         m_suspendPending = false;
    873     });
    874 }
    875 
    876 void CoreAudioCaptureSource::endInterruption()
    877 {
    878     ALWAYS_LOG_IF(loggerPtr(), LOGIDENTIFIER);
    879 
    880     ASSERT(isMainThread());
    881     auto& unit = this->unit();
    882     if (!unit.hasAudioUnit() || !unit.isSuspended() || m_resumePending)
    883         return;
    884 
    885     auto type = m_suspendType;
    886     m_suspendType = SuspensionType::None;
    887     if (type != SuspensionType::WhilePlaying && m_reconfigurationState != ReconfigurationState::Required)
    888         return;
    889 
    890     m_resumePending = true;
    891     scheduleDeferredTask([this, type, &unit] {
    892         if (m_reconfigurationState == ReconfigurationState::Required)
    893             unit.reconfigureAudioUnit();
    894         if (type == SuspensionType::WhilePlaying) {
    895             unit.resume();
    896             notifyMutedChange(false);
    897         }
    898         m_reconfigurationState = ReconfigurationState::None;
    899         m_resumePending = false;
    900     });
    901 }
    902 
    903801bool CoreAudioCaptureSource::interrupted() const
    904802{
  • trunk/Source/WebCore/platform/mediastream/mac/CoreAudioCaptureSource.h

    r252737 r252961  
    6363    CMClockRef timebaseClock();
    6464
    65     void beginInterruption();
    66     void endInterruption();
    67     void scheduleReconfiguration();
    68 
    6965protected:
    7066    CoreAudioCaptureSource(String&& deviceID, String&& label, String&& hashSalt, uint32_t persistentID);
     
    104100    Optional<RealtimeMediaSourceSettings> m_currentSettings;
    105101
    106     enum class SuspensionType { None, WhilePaused, WhilePlaying };
    107     SuspensionType m_suspendType { SuspensionType::None };
    108 
    109     enum class ReconfigurationState { None, Required, Ongoing };
    110     ReconfigurationState m_reconfigurationState { ReconfigurationState::None };
    111 
    112     bool m_reconfigurationRequired { false };
    113     bool m_suspendPending { false };
    114     bool m_resumePending { false };
    115102    bool m_isReadyToStart { false };
    116103   
Note: See TracChangeset for help on using the changeset viewer.