This source file includes following definitions.
- decodeAsync
- decode
- notifyComplete
#include "config.h"
#if ENABLE(WEB_AUDIO)
#include "modules/webaudio/AsyncAudioDecoder.h"
#include "modules/webaudio/AudioBuffer.h"
#include "modules/webaudio/AudioBufferCallback.h"
#include "platform/Task.h"
#include "public/platform/Platform.h"
#include "wtf/ArrayBuffer.h"
#include "wtf/MainThread.h"
#include "wtf/PassOwnPtr.h"
namespace WebCore {
AsyncAudioDecoder::AsyncAudioDecoder()
: m_thread(adoptPtr(blink::Platform::current()->createThread("Audio Decoder")))
{
}
AsyncAudioDecoder::~AsyncAudioDecoder()
{
}
void AsyncAudioDecoder::decodeAsync(ArrayBuffer* audioData, float sampleRate, PassOwnPtr<AudioBufferCallback> successCallback, PassOwnPtr<AudioBufferCallback> errorCallback)
{
ASSERT(isMainThread());
ASSERT(audioData);
if (!audioData)
return;
RefPtr<ArrayBuffer> audioDataRef(audioData);
m_thread->postTask(new Task(WTF::bind(&AsyncAudioDecoder::decode, audioDataRef.release().leakRef(), sampleRate, successCallback.leakPtr(), errorCallback.leakPtr())));
}
void AsyncAudioDecoder::decode(ArrayBuffer* audioData, float sampleRate, AudioBufferCallback* successCallback, AudioBufferCallback* errorCallback)
{
RefPtr<AudioBuffer> audioBuffer = AudioBuffer::createFromAudioFileData(audioData->data(), audioData->byteLength(), false, sampleRate);
callOnMainThread(WTF::bind(&AsyncAudioDecoder::notifyComplete, audioData, successCallback, errorCallback, audioBuffer.release().leakRef()));
}
void AsyncAudioDecoder::notifyComplete(ArrayBuffer* audioData, AudioBufferCallback* successCallback, AudioBufferCallback* errorCallback, AudioBuffer* audioBuffer)
{
RefPtr<ArrayBuffer> audioDataRef = adoptRef(audioData);
OwnPtr<AudioBufferCallback> successCallbackPtr = adoptPtr(successCallback);
OwnPtr<AudioBufferCallback> errorCallbackPtr = adoptPtr(errorCallback);
RefPtr<AudioBuffer> audioBufferRef = adoptRef(audioBuffer);
if (audioBuffer && successCallback)
successCallback->handleEvent(audioBuffer);
else if (errorCallback)
errorCallback->handleEvent(audioBuffer);
}
}
#endif