Changeset 215546 in webkit


Ignore:
Timestamp:
Apr 19, 2017 5:53:37 PM (7 years ago)
Author:
eric.carlson@apple.com
Message:

Another deadlock in CoreAudioCaptureSource
https://bugs.webkit.org/show_bug.cgi?id=171001

Fix another regression introduced by r215201, plus make changes suggested
in the review of 170771.

Reviewed by Youenn Fablet.

  • platform/mediastream/mac/CoreAudioCaptureSource.cpp:

(WebCore::CoreAudioCaptureSource::configureSpeakerProc): Assert if the lock is no held.
(WebCore::CoreAudioCaptureSource::provideSpeakerData): Don't reset the buffer.
(WebCore::CoreAudioCaptureSource::processMicrophoneSamples): Take the state lock. Don't
reset the buffer. No more microphone callbacks.
(WebCore::CoreAudioCaptureSource::stopProducingData): Return early if the io unit isn't
running. Drop the lock before calling setMuted to avoid another deadlock.
(WebCore::CoreAudioCaptureSource::addMicrophoneDataConsumer): Deleted.
(WebCore::CoreAudioCaptureSource::removeMicrophoneDataConsumer): Deleted.

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

Legend:

Unmodified
Added
Removed
  • trunk/Source/WebCore/ChangeLog

    r215541 r215546  
     12017-04-19  Eric Carlson  <eric.carlson@apple.com>
     2
     3        Another deadlock in CoreAudioCaptureSource
     4        https://bugs.webkit.org/show_bug.cgi?id=171001
     5
     6        Fix another regression introduced by r215201, plus make changes suggested
     7        in the review of 170771.
     8
     9        Reviewed by Youenn Fablet.
     10
     11        * platform/mediastream/mac/CoreAudioCaptureSource.cpp:
     12        (WebCore::CoreAudioCaptureSource::configureSpeakerProc): Assert if the lock is no held.
     13        (WebCore::CoreAudioCaptureSource::provideSpeakerData): Don't reset the buffer.
     14        (WebCore::CoreAudioCaptureSource::processMicrophoneSamples): Take the state lock. Don't
     15        reset the buffer. No more microphone callbacks.
     16        (WebCore::CoreAudioCaptureSource::stopProducingData): Return early if the io unit isn't
     17        running. Drop the lock before calling setMuted to avoid another deadlock.
     18        (WebCore::CoreAudioCaptureSource::addMicrophoneDataConsumer): Deleted.
     19        (WebCore::CoreAudioCaptureSource::removeMicrophoneDataConsumer): Deleted.
     20        * platform/mediastream/mac/CoreAudioCaptureSource.h:
     21
    1222017-04-19  Anders Carlsson  <andersca@apple.com>
    223
  • trunk/Source/WebCore/platform/mediastream/mac/CoreAudioCaptureSource.cpp

    r215485 r215546  
    171171OSStatus CoreAudioCaptureSource::configureSpeakerProc()
    172172{
     173    ASSERT(m_internalStateLock.isHeld());
     174
    173175    AURenderCallbackStruct callback = { speakerCallback, this };
    174176    auto err = AudioUnitSetProperty(m_ioUnit, kAudioUnitProperty_SetRenderCallback, kAudioUnitScope_Global, outputBus, &callback, sizeof(callback));
     
    192194    return err;
    193195}
    194 
    195 uint64_t CoreAudioCaptureSource::addMicrophoneDataConsumer(MicrophoneDataCallback&& callback)
    196 {
    197     std::lock_guard<Lock> lock(m_pendingSourceQueueLock);
    198     m_microphoneDataCallbacks.add(++m_nextMicrophoneDataCallbackID, callback);
    199 
    200     return m_nextMicrophoneDataCallbackID;
    201 }
    202 
    203 void CoreAudioCaptureSource::removeMicrophoneDataConsumer(uint64_t callbackID)
    204 {
    205     std::lock_guard<Lock> lock(m_pendingSourceQueueLock);
    206     m_microphoneDataCallbacks.remove(callbackID);
    207 }   
    208196
    209197void CoreAudioCaptureSource::addEchoCancellationSource(AudioSampleDataSource& source)
     
    265253    uint64_t sampleTime = timeStamp.mSampleTime;
    266254    checkTimestamps(timeStamp, sampleTime, adjustedHostTime);
    267 
    268     m_speakerSampleBuffer->reset();
    269255    m_speakerSampleBuffer->setTimes(adjustedHostTime, sampleTime);
    270256
     
    292278OSStatus CoreAudioCaptureSource::processMicrophoneSamples(AudioUnitRenderActionFlags& ioActionFlags, const AudioTimeStamp& timeStamp, UInt32 inBusNumber, UInt32 inNumberFrames, AudioBufferList* /*ioData*/)
    293279{
     280    std::lock_guard<Lock> lock(m_internalStateLock);
     281
    294282    ++m_microphoneProcsCalled;
    295283
    296284    // Pull through the vpio unit to our mic buffer.
    297     m_microphoneSampleBuffer->reset();
    298285    AudioBufferList& bufferList = m_microphoneSampleBuffer->bufferList();
    299286    auto err = AudioUnitRender(m_ioUnit, &ioActionFlags, &timeStamp, inBusNumber, inNumberFrames, &bufferList);
     
    307294    checkTimestamps(timeStamp, sampleTime, adjustedHostTime);
    308295    m_latestMicTimeStamp = sampleTime;
    309 
    310296    m_microphoneSampleBuffer->setTimes(adjustedHostTime, sampleTime);
    311297
    312298    audioSamplesAvailable(MediaTime(sampleTime, m_microphoneProcFormat.sampleRate()), m_microphoneSampleBuffer->bufferList(), m_microphoneProcFormat, inNumberFrames);
    313 
    314     if (m_microphoneDataCallbacks.isEmpty())
    315         return 0;
    316 
    317     for (auto& callback : m_microphoneDataCallbacks.values())
    318         callback(MediaTime(sampleTime, m_microphoneProcFormat.sampleRate()), m_microphoneSampleBuffer->bufferList(), m_microphoneProcFormat, inNumberFrames);
    319299
    320300    return noErr;
     
    468448void CoreAudioCaptureSource::stopProducingData()
    469449{
    470     std::lock_guard<Lock> lock(m_internalStateLock);
    471 
    472     if (!m_ioUnit)
     450    if (!m_ioUnit || !m_ioUnitStarted)
    473451        return;
    474452
    475     auto err = AudioOutputUnitStop(m_ioUnit);
    476     if (err) {
    477         LOG(Media, "CoreAudioCaptureSource::stop(%p) AudioOutputUnitStop failed with error %d (%.4s)", this, (int)err, (char*)&err);
    478         return;
    479     }
    480     m_ioUnitStarted = false;
     453    {
     454        std::lock_guard<Lock> lock(m_internalStateLock);
     455
     456        auto err = AudioOutputUnitStop(m_ioUnit);
     457        if (err) {
     458            LOG(Media, "CoreAudioCaptureSource::stop(%p) AudioOutputUnitStop failed with error %d (%.4s)", this, (int)err, (char*)&err);
     459            return;
     460        }
     461        m_ioUnitStarted = false;
     462    }
     463
    481464    setMuted(true);
    482465}
  • trunk/Source/WebCore/platform/mediastream/mac/CoreAudioCaptureSource.h

    r215485 r215546  
    116116    uint64_t m_latestMicTimeStamp { 0 };
    117117
    118     HashMap<uint64_t, MicrophoneDataCallback> m_microphoneDataCallbacks;
    119     uint64_t m_nextMicrophoneDataCallbackID { 0 };
    120 
    121118    CAAudioStreamDescription m_speakerProcFormat;
    122119    RefPtr<AudioSampleBufferList> m_speakerSampleBuffer;
Note: See TracChangeset for help on using the changeset viewer.