| Differences between
and this patch
- a/Source/WebCore/platform/audio/cocoa/CARingBuffer.cpp -2 / +7 lines
Lines 381-395 void CARingBuffer::updateFrameBounds() a/Source/WebCore/platform/audio/cocoa/CARingBuffer.cpp_sec1
381
    m_buffers->updateFrameBounds();
381
    m_buffers->updateFrameBounds();
382
}
382
}
383
383
384
bool CARingBuffer::fetchIfHasEnoughData(AudioBufferList* list, size_t frameCount, uint64_t startFrame, FetchMode mode)
384
bool CARingBuffer::fetchIfHasEnoughData(AudioBufferList* list, size_t frameCount, uint64_t startFrame, FetchMode mode, uint64_t* remainingFrames)
385
{
385
{
386
    // When the RingBuffer is backed by shared memory, getCurrentFrameBounds() makes sure we pull frame bounds from shared memory before fetching.
386
    // When the RingBuffer is backed by shared memory, getCurrentFrameBounds() makes sure we pull frame bounds from shared memory before fetching.
387
    uint64_t start, end;
387
    uint64_t start, end;
388
    getCurrentFrameBounds(start, end);
388
    getCurrentFrameBounds(start, end);
389
    if (startFrame < start || startFrame + frameCount > end)
389
    if (startFrame < start || startFrame + frameCount > end) {
390
        if (remainingFrames)
391
            *remainingFrames = end - std::min(std::max(startFrame, start), end);
390
        return false;
392
        return false;
393
    }
391
394
392
    fetchInternal(list, frameCount, startFrame, mode);
395
    fetchInternal(list, frameCount, startFrame, mode);
396
    if (remainingFrames)
397
        *remainingFrames = end - (startFrame + frameCount);
393
    return true;
398
    return true;
394
}
399
}
395
400
- a/Source/WebCore/platform/audio/cocoa/CARingBuffer.h -1 / +1 lines
Lines 108-114 public: a/Source/WebCore/platform/audio/cocoa/CARingBuffer.h_sec1
108
    WEBCORE_EXPORT Error store(const AudioBufferList*, size_t frameCount, uint64_t startFrame);
108
    WEBCORE_EXPORT Error store(const AudioBufferList*, size_t frameCount, uint64_t startFrame);
109
109
110
    enum FetchMode { Copy, Mix };
110
    enum FetchMode { Copy, Mix };
111
    WEBCORE_EXPORT bool fetchIfHasEnoughData(AudioBufferList*, size_t frameCount, uint64_t startFrame, FetchMode = Copy);
111
    WEBCORE_EXPORT bool fetchIfHasEnoughData(AudioBufferList*, size_t frameCount, uint64_t startFrame, FetchMode = Copy, uint64_t* remainingFrames = nullptr);
112
112
113
    // Fills buffer with silence if there is not enough data.
113
    // Fills buffer with silence if there is not enough data.
114
    WEBCORE_EXPORT void fetch(AudioBufferList*, size_t frameCount, uint64_t startFrame, FetchMode = Copy);
114
    WEBCORE_EXPORT void fetch(AudioBufferList*, size_t frameCount, uint64_t startFrame, FetchMode = Copy);
- a/Source/WebKit/GPUProcess/media/RemoteAudioDestinationManager.cpp -2 / +15 lines
Lines 43-48 a/Source/WebKit/GPUProcess/media/RemoteAudioDestinationManager.cpp_sec1
43
43
44
namespace WebKit {
44
namespace WebKit {
45
45
46
static constexpr unsigned defaultNumberOfQuantumsToWriteAhead = 2;
47
static constexpr unsigned maxNumberOfQuantumsToWriteAhead = 10;
48
46
class RemoteAudioDestination final
49
class RemoteAudioDestination final
47
#if PLATFORM(COCOA)
50
#if PLATFORM(COCOA)
48
    : public WebCore::AudioUnitRenderer
51
    : public WebCore::AudioUnitRenderer
Lines 107-119 private: a/Source/WebKit/GPUProcess/media/RemoteAudioDestinationManager.cpp_sec2
107
    {
110
    {
108
        ASSERT(!isMainRunLoop());
111
        ASSERT(!isMainRunLoop());
109
112
113
        unsigned numberOfFramesToRequestFromRemote = numberOfFrames;
110
        OSStatus status = -1;
114
        OSStatus status = -1;
111
        if (m_ringBuffer->fetchIfHasEnoughData(ioData, numberOfFrames, m_startFrame)) {
115
        uint64_t remainingFramesInRingBuffer = 0;
116
        if (m_ringBuffer->fetchIfHasEnoughData(ioData, numberOfFrames, m_startFrame, WebCore::CARingBuffer::Copy, &remainingFramesInRingBuffer)) {
112
            m_startFrame += numberOfFrames;
117
            m_startFrame += numberOfFrames;
113
            status = noErr;
118
            status = noErr;
119
120
            if (remainingFramesInRingBuffer >= numberOfFrames * m_numberOfQuantumsToWriteAhead)
121
                numberOfFramesToRequestFromRemote = 0; // Do not let the writer get more than |m_numberOfQuantumsToWriteAhead| quantums ahead.
122
        } else if (m_startFrame) {
123
            // It seems we hit a case where the WebProcess is not filling in the ring buffer fast enough to keep up with the reader
124
            // so we allow the writer to write ahead an extra rendering quantum.
125
            m_numberOfQuantumsToWriteAhead = std::min(m_numberOfQuantumsToWriteAhead + 1, maxNumberOfQuantumsToWriteAhead);
114
        }
126
        }
115
127
116
        for (unsigned i = 0; i < numberOfFrames; i += WebCore::AudioUtilities::renderQuantumSize) {
128
        for (unsigned i = 0; i < numberOfFramesToRequestFromRemote; i += WebCore::AudioUtilities::renderQuantumSize) {
117
            // Ask the audio thread in the WebContent process to render a quantum.
129
            // Ask the audio thread in the WebContent process to render a quantum.
118
            m_renderSemaphore.signal();
130
            m_renderSemaphore.signal();
119
        }
131
        }
Lines 133-138 private: a/Source/WebKit/GPUProcess/media/RemoteAudioDestinationManager.cpp_sec3
133
    IPC::Semaphore m_renderSemaphore;
145
    IPC::Semaphore m_renderSemaphore;
134
146
135
    bool m_isPlaying { false };
147
    bool m_isPlaying { false };
148
    unsigned m_numberOfQuantumsToWriteAhead { defaultNumberOfQuantumsToWriteAhead };
136
};
149
};
137
150
138
RemoteAudioDestinationManager::RemoteAudioDestinationManager(GPUConnectionToWebProcess& connection)
151
RemoteAudioDestinationManager::RemoteAudioDestinationManager(GPUConnectionToWebProcess& connection)

Return to Bug 232728