Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 /* | 1 /* |
| 2 * Copyright (C) 2011, Google Inc. All rights reserved. | 2 * Copyright (C) 2011, Google Inc. All rights reserved. |
| 3 * | 3 * |
| 4 * Redistribution and use in source and binary forms, with or without | 4 * Redistribution and use in source and binary forms, with or without |
| 5 * modification, are permitted provided that the following conditions | 5 * modification, are permitted provided that the following conditions |
| 6 * are met: | 6 * are met: |
| 7 * 1. Redistributions of source code must retain the above copyright | 7 * 1. Redistributions of source code must retain the above copyright |
| 8 * notice, this list of conditions and the following disclaimer. | 8 * notice, this list of conditions and the following disclaimer. |
| 9 * 2. Redistributions in binary form must reproduce the above copyright | 9 * 2. Redistributions in binary form must reproduce the above copyright |
| 10 * notice, this list of conditions and the following disclaimer in the | 10 * notice, this list of conditions and the following disclaimer in the |
| (...skipping 12 matching lines...) Expand all Loading... | |
| 23 */ | 23 */ |
| 24 | 24 |
| 25 #include "core/dom/DOMArrayBuffer.h" | 25 #include "core/dom/DOMArrayBuffer.h" |
| 26 #include "modules/webaudio/AsyncAudioDecoder.h" | 26 #include "modules/webaudio/AsyncAudioDecoder.h" |
| 27 #include "modules/webaudio/AudioBuffer.h" | 27 #include "modules/webaudio/AudioBuffer.h" |
| 28 #include "modules/webaudio/AudioBufferCallback.h" | 28 #include "modules/webaudio/AudioBufferCallback.h" |
| 29 #include "modules/webaudio/BaseAudioContext.h" | 29 #include "modules/webaudio/BaseAudioContext.h" |
| 30 #include "platform/CrossThreadFunctional.h" | 30 #include "platform/CrossThreadFunctional.h" |
| 31 #include "platform/audio/AudioBus.h" | 31 #include "platform/audio/AudioBus.h" |
| 32 #include "platform/audio/AudioFileReader.h" | 32 #include "platform/audio/AudioFileReader.h" |
| 33 #include "platform/threading/BackgroundTaskRunner.h" | |
| 33 #include "public/platform/Platform.h" | 34 #include "public/platform/Platform.h" |
| 34 #include "public/platform/WebTraceLocation.h" | 35 #include "public/platform/WebTraceLocation.h" |
| 35 #include "wtf/PtrUtil.h" | 36 #include "wtf/PtrUtil.h" |
| 36 | 37 |
| 37 namespace blink { | 38 namespace blink { |
| 38 | 39 |
| 39 AsyncAudioDecoder::AsyncAudioDecoder() | |
| 40 : m_thread(wrapUnique(Platform::current()->createThread("Audio Decoder"))) | |
| 41 { | |
| 42 } | |
| 43 | |
| 44 AsyncAudioDecoder::~AsyncAudioDecoder() | |
| 45 { | |
| 46 } | |
| 47 | |
| 48 void AsyncAudioDecoder::decodeAsync(DOMArrayBuffer* audioData, float sampleRate, AudioBufferCallback* successCallback, AudioBufferCallback* errorCallback, Scrip tPromiseResolver* resolver, BaseAudioContext* context) | 40 void AsyncAudioDecoder::decodeAsync(DOMArrayBuffer* audioData, float sampleRate, AudioBufferCallback* successCallback, AudioBufferCallback* errorCallback, Scrip tPromiseResolver* resolver, BaseAudioContext* context) |
| 49 { | 41 { |
| 50 DCHECK(isMainThread()); | 42 DCHECK(isMainThread()); |
| 51 DCHECK(audioData); | 43 DCHECK(audioData); |
| 52 if (!audioData) | 44 if (!audioData) |
| 53 return; | 45 return; |
| 54 | 46 |
| 55 m_thread->getWebTaskRunner()->postTask(BLINK_FROM_HERE, crossThreadBind(&Asy ncAudioDecoder::decode, wrapCrossThreadPersistent(audioData), sampleRate, wrapCr ossThreadPersistent(successCallback), wrapCrossThreadPersistent(errorCallback), wrapCrossThreadPersistent(resolver), wrapCrossThreadPersistent(context))); | 47 BackgroundTaskRunner::TaskSize taskSize = BackgroundTaskRunner::TaskSizeShor tRunningTask; |
|
Raymond Toy
2016/08/24 23:08:46
Why short? Decoding long files is probably not a
hongchan
2016/08/24 23:10:19
TODO: The threshold for long/short task needs to b
| |
| 48 BackgroundTaskRunner::postOnBackgroundThread(BLINK_FROM_HERE, crossThreadBin d(&AsyncAudioDecoder::decodeOnBackgroundThread, wrapCrossThreadPersistent(audioD ata), sampleRate, wrapCrossThreadPersistent(successCallback), wrapCrossThreadPer sistent(errorCallback), wrapCrossThreadPersistent(resolver), wrapCrossThreadPers istent(context)), taskSize); | |
| 56 } | 49 } |
| 57 | 50 |
| 58 void AsyncAudioDecoder::decode(DOMArrayBuffer* audioData, float sampleRate, Audi oBufferCallback* successCallback, AudioBufferCallback* errorCallback, ScriptProm iseResolver* resolver, BaseAudioContext* context) | 51 void AsyncAudioDecoder::decodeOnBackgroundThread(DOMArrayBuffer* audioData, floa t sampleRate, AudioBufferCallback* successCallback, AudioBufferCallback* errorCa llback, ScriptPromiseResolver* resolver, BaseAudioContext* context) |
| 59 { | 52 { |
| 53 DCHECK(!isMainThread()); | |
| 60 RefPtr<AudioBus> bus = createBusFromInMemoryAudioFile(audioData->data(), aud ioData->byteLength(), false, sampleRate); | 54 RefPtr<AudioBus> bus = createBusFromInMemoryAudioFile(audioData->data(), aud ioData->byteLength(), false, sampleRate); |
| 61 | 55 |
| 62 // Decoding is finished, but we need to do the callbacks on the main thread. | 56 // Decoding is finished, but we need to do the callbacks on the main thread. |
| 63 // A reference to |*bus| is retained by WTF::Function and will be removed af ter notifyComplete() is done. | 57 // A reference to |*bus| is retained by WTF::Function and will be removed af ter notifyComplete() is done. |
| 64 Platform::current()->mainThread()->getWebTaskRunner()->postTask(BLINK_FROM_H ERE, crossThreadBind(&AsyncAudioDecoder::notifyComplete, wrapCrossThreadPersiste nt(audioData), wrapCrossThreadPersistent(successCallback), wrapCrossThreadPersis tent(errorCallback), bus.release(), wrapCrossThreadPersistent(resolver), wrapCro ssThreadPersistent(context))); | 58 Platform::current()->mainThread()->getWebTaskRunner()->postTask(BLINK_FROM_H ERE, crossThreadBind(&AsyncAudioDecoder::notifyComplete, wrapCrossThreadPersiste nt(audioData), wrapCrossThreadPersistent(successCallback), wrapCrossThreadPersis tent(errorCallback), bus.release(), wrapCrossThreadPersistent(resolver), wrapCro ssThreadPersistent(context))); |
| 65 } | 59 } |
| 66 | 60 |
| 67 void AsyncAudioDecoder::notifyComplete(DOMArrayBuffer*, AudioBufferCallback* suc cessCallback, AudioBufferCallback* errorCallback, AudioBus* audioBus, ScriptProm iseResolver* resolver, BaseAudioContext* context) | 61 void AsyncAudioDecoder::notifyComplete(DOMArrayBuffer*, AudioBufferCallback* suc cessCallback, AudioBufferCallback* errorCallback, AudioBus* audioBus, ScriptProm iseResolver* resolver, BaseAudioContext* context) |
| 68 { | 62 { |
| 69 DCHECK(isMainThread()); | 63 DCHECK(isMainThread()); |
| 70 | 64 |
| 71 AudioBuffer* audioBuffer = AudioBuffer::createFromAudioBus(audioBus); | 65 AudioBuffer* audioBuffer = AudioBuffer::createFromAudioBus(audioBus); |
| 72 | 66 |
| 73 // Let the context finish the notification. | 67 // Let the context finish the notification. |
| 74 context->handleDecodeAudioData(audioBuffer, resolver, successCallback, error Callback); | 68 context->handleDecodeAudioData(audioBuffer, resolver, successCallback, error Callback); |
| 75 } | 69 } |
| 76 | 70 |
| 77 } // namespace blink | 71 } // namespace blink |
| OLD | NEW |