| 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 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 45 { | 45 { |
| 46 } | 46 } |
| 47 | 47 |
| 48 void AsyncAudioDecoder::decodeAsync(DOMArrayBuffer* audioData, float sampleRate,
AudioBufferCallback* successCallback, AudioBufferCallback* errorCallback, Scrip
tPromiseResolver* resolver, AbstractAudioContext* context) | 48 void AsyncAudioDecoder::decodeAsync(DOMArrayBuffer* audioData, float sampleRate,
AudioBufferCallback* successCallback, AudioBufferCallback* errorCallback, Scrip
tPromiseResolver* resolver, AbstractAudioContext* context) |
| 49 { | 49 { |
| 50 ASSERT(isMainThread()); | 50 ASSERT(isMainThread()); |
| 51 ASSERT(audioData); | 51 ASSERT(audioData); |
| 52 if (!audioData) | 52 if (!audioData) |
| 53 return; | 53 return; |
| 54 | 54 |
| 55 // The leak references to successCallback and errorCallback are picked up on
notifyComplete. | |
| 56 m_thread->getWebTaskRunner()->postTask(BLINK_FROM_HERE, threadSafeBind(&Asyn
cAudioDecoder::decode, wrapCrossThreadPersistent(audioData), sampleRate, wrapCro
ssThreadPersistent(successCallback), wrapCrossThreadPersistent(errorCallback), w
rapCrossThreadPersistent(resolver), wrapCrossThreadPersistent(context))); | 55 m_thread->getWebTaskRunner()->postTask(BLINK_FROM_HERE, threadSafeBind(&Asyn
cAudioDecoder::decode, wrapCrossThreadPersistent(audioData), sampleRate, wrapCro
ssThreadPersistent(successCallback), wrapCrossThreadPersistent(errorCallback), w
rapCrossThreadPersistent(resolver), wrapCrossThreadPersistent(context))); |
| 57 } | 56 } |
| 58 | 57 |
| 59 void AsyncAudioDecoder::decode(DOMArrayBuffer* audioData, float sampleRate, Audi
oBufferCallback* successCallback, AudioBufferCallback* errorCallback, ScriptProm
iseResolver* resolver, AbstractAudioContext* context) | 58 void AsyncAudioDecoder::decode(DOMArrayBuffer* audioData, float sampleRate, Audi
oBufferCallback* successCallback, AudioBufferCallback* errorCallback, ScriptProm
iseResolver* resolver, AbstractAudioContext* context) |
| 60 { | 59 { |
| 61 RefPtr<AudioBus> bus = createBusFromInMemoryAudioFile(audioData->data(), aud
ioData->byteLength(), false, sampleRate); | 60 RefPtr<AudioBus> bus = createBusFromInMemoryAudioFile(audioData->data(), aud
ioData->byteLength(), false, sampleRate); |
| 62 | 61 |
| 63 // Decoding is finished, but we need to do the callbacks on the main thread. | 62 // Decoding is finished, but we need to do the callbacks on the main thread. |
| 64 // The leaked reference to audioBuffer is picked up in notifyComplete. | 63 // A reference to |*bus| is retained by WTF::Function and will be removed af
ter notifyComplete() is done. |
| 65 Platform::current()->mainThread()->getWebTaskRunner()->postTask(BLINK_FROM_H
ERE, threadSafeBind(&AsyncAudioDecoder::notifyComplete, wrapCrossThreadPersisten
t(audioData), wrapCrossThreadPersistent(successCallback), wrapCrossThreadPersist
ent(errorCallback), bus.release().leakRef(), wrapCrossThreadPersistent(resolver)
, wrapCrossThreadPersistent(context))); | 64 Platform::current()->mainThread()->getWebTaskRunner()->postTask(BLINK_FROM_H
ERE, threadSafeBind(&AsyncAudioDecoder::notifyComplete, wrapCrossThreadPersisten
t(audioData), wrapCrossThreadPersistent(successCallback), wrapCrossThreadPersist
ent(errorCallback), bus.release(), wrapCrossThreadPersistent(resolver), wrapCros
sThreadPersistent(context))); |
| 66 } | 65 } |
| 67 | 66 |
| 68 void AsyncAudioDecoder::notifyComplete(DOMArrayBuffer*, AudioBufferCallback* suc
cessCallback, AudioBufferCallback* errorCallback, AudioBus* audioBus, ScriptProm
iseResolver* resolver, AbstractAudioContext* context) | 67 void AsyncAudioDecoder::notifyComplete(DOMArrayBuffer*, AudioBufferCallback* suc
cessCallback, AudioBufferCallback* errorCallback, AudioBus* audioBus, ScriptProm
iseResolver* resolver, AbstractAudioContext* context) |
| 69 { | 68 { |
| 70 ASSERT(isMainThread()); | 69 ASSERT(isMainThread()); |
| 71 | 70 |
| 72 // Adopt references, so everything gets correctly dereffed. | |
| 73 RefPtr<AudioBus> audioBusRef = adoptRef(audioBus); | |
| 74 | |
| 75 AudioBuffer* audioBuffer = AudioBuffer::createFromAudioBus(audioBus); | 71 AudioBuffer* audioBuffer = AudioBuffer::createFromAudioBus(audioBus); |
| 76 | 72 |
| 77 // Let the context finish the notification. | 73 // Let the context finish the notification. |
| 78 context->handleDecodeAudioData(audioBuffer, resolver, successCallback, error
Callback); | 74 context->handleDecodeAudioData(audioBuffer, resolver, successCallback, error
Callback); |
| 79 } | 75 } |
| 80 | 76 |
| 81 } // namespace blink | 77 } // namespace blink |
| OLD | NEW |