From 1bf1084f2b10c3b47fd1a588d85d21ed0eb41d0c Mon Sep 17 00:00:00 2001 From: Lorry Tar Creator Date: Tue, 27 Jun 2017 06:07:23 +0000 Subject: webkitgtk-2.16.5 --- .../WebCore/Modules/webaudio/AsyncAudioDecoder.cpp | 44 ++++++---------------- 1 file changed, 12 insertions(+), 32 deletions(-) (limited to 'Source/WebCore/Modules/webaudio/AsyncAudioDecoder.cpp') diff --git a/Source/WebCore/Modules/webaudio/AsyncAudioDecoder.cpp b/Source/WebCore/Modules/webaudio/AsyncAudioDecoder.cpp index 3698bf5ef..292f05b8c 100644 --- a/Source/WebCore/Modules/webaudio/AsyncAudioDecoder.cpp +++ b/Source/WebCore/Modules/webaudio/AsyncAudioDecoder.cpp @@ -38,7 +38,7 @@ namespace WebCore { AsyncAudioDecoder::AsyncAudioDecoder() { // Start worker thread. - MutexLocker lock(m_threadCreationMutex); + LockHolder lock(m_threadCreationMutex); m_threadID = createThread(AsyncAudioDecoder::threadEntry, this, "Audio Decoder"); } @@ -51,15 +51,12 @@ AsyncAudioDecoder::~AsyncAudioDecoder() m_threadID = 0; } -void AsyncAudioDecoder::decodeAsync(ArrayBuffer* audioData, float sampleRate, PassRefPtr successCallback, PassRefPtr errorCallback) +void AsyncAudioDecoder::decodeAsync(Ref&& audioData, float sampleRate, RefPtr&& successCallback, RefPtr&& errorCallback) { ASSERT(isMainThread()); - ASSERT(audioData); - if (!audioData) - return; - auto decodingTask = DecodingTask::create(audioData, sampleRate, successCallback, errorCallback); - m_queue.append(std::move(decodingTask)); // note that ownership of the task is effectively taken by the queue. + auto decodingTask = std::make_unique(WTFMove(audioData), sampleRate, WTFMove(successCallback), WTFMove(errorCallback)); + m_queue.append(WTFMove(decodingTask)); // note that ownership of the task is effectively taken by the queue. } // Asynchronously decode in this thread. @@ -76,7 +73,7 @@ void AsyncAudioDecoder::runLoop() { // Wait for until we have m_threadID established before starting the run loop. - MutexLocker lock(m_threadCreationMutex); + LockHolder lock(m_threadCreationMutex); } // Keep running decoding tasks until we're killed. @@ -87,40 +84,23 @@ void AsyncAudioDecoder::runLoop() } } -std::unique_ptr AsyncAudioDecoder::DecodingTask::create(ArrayBuffer* audioData, float sampleRate, PassRefPtr successCallback, PassRefPtr errorCallback) -{ - return std::unique_ptr(new DecodingTask(audioData, sampleRate, successCallback, errorCallback)); -} - -AsyncAudioDecoder::DecodingTask::DecodingTask(ArrayBuffer* audioData, float sampleRate, PassRefPtr successCallback, PassRefPtr errorCallback) - : m_audioData(audioData) +AsyncAudioDecoder::DecodingTask::DecodingTask(Ref&& audioData, float sampleRate, RefPtr&& successCallback, RefPtr&& errorCallback) + : m_audioData(WTFMove(audioData)) , m_sampleRate(sampleRate) - , m_successCallback(successCallback) - , m_errorCallback(errorCallback) + , m_successCallback(WTFMove(successCallback)) + , m_errorCallback(WTFMove(errorCallback)) { } void AsyncAudioDecoder::DecodingTask::decode() { - ASSERT(m_audioData.get()); - if (!m_audioData.get()) - return; - // Do the actual decoding and invoke the callback. m_audioBuffer = AudioBuffer::createFromAudioFileData(m_audioData->data(), m_audioData->byteLength(), false, sampleRate()); // Decoding is finished, but we need to do the callbacks on the main thread. - callOnMainThread(notifyCompleteDispatch, this); -} - -void AsyncAudioDecoder::DecodingTask::notifyCompleteDispatch(void* userData) -{ - AsyncAudioDecoder::DecodingTask* task = reinterpret_cast(userData); - ASSERT(task); - if (!task) - return; - - task->notifyComplete(); + callOnMainThread([this] { + notifyComplete(); + }); } void AsyncAudioDecoder::DecodingTask::notifyComplete() -- cgit v1.2.1