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 // Add a ref to keep audioData alive until completion of decoding. | |
56 RefPtr<DOMArrayBuffer> audioDataRef(audioData); | |
57 | |
58 // The leak references to successCallback and errorCallback are picked up on
notifyComplete. | 55 // The leak references to successCallback and errorCallback are picked up on
notifyComplete. |
59 m_thread->getWebTaskRunner()->postTask(BLINK_FROM_HERE, threadSafeBind(&Asyn
cAudioDecoder::decode, AllowCrossThreadAccess(audioDataRef.release().leakRef()),
sampleRate, successCallback, errorCallback, resolver, context)); | 56 m_thread->getWebTaskRunner()->postTask(BLINK_FROM_HERE, threadSafeBind(&Asyn
cAudioDecoder::decode, AllowCrossThreadAccess(audioData), sampleRate, successCal
lback, errorCallback, resolver, context)); |
60 } | 57 } |
61 | 58 |
62 void AsyncAudioDecoder::decode(DOMArrayBuffer* audioData, float sampleRate, Audi
oBufferCallback* successCallback, AudioBufferCallback* errorCallback, ScriptProm
iseResolver* resolver, AbstractAudioContext* context) | 59 void AsyncAudioDecoder::decode(DOMArrayBuffer* audioData, float sampleRate, Audi
oBufferCallback* successCallback, AudioBufferCallback* errorCallback, ScriptProm
iseResolver* resolver, AbstractAudioContext* context) |
63 { | 60 { |
64 RefPtr<AudioBus> bus = createBusFromInMemoryAudioFile(audioData->data(), aud
ioData->byteLength(), false, sampleRate); | 61 RefPtr<AudioBus> bus = createBusFromInMemoryAudioFile(audioData->data(), aud
ioData->byteLength(), false, sampleRate); |
65 | 62 |
66 // Decoding is finished, but we need to do the callbacks on the main thread. | 63 // Decoding is finished, but we need to do the callbacks on the main thread. |
67 // The leaked reference to audioBuffer is picked up in notifyComplete. | 64 // The leaked reference to audioBuffer is picked up in notifyComplete. |
68 Platform::current()->mainThread()->getWebTaskRunner()->postTask(BLINK_FROM_H
ERE, threadSafeBind(&AsyncAudioDecoder::notifyComplete, AllowCrossThreadAccess(a
udioData), successCallback, errorCallback, bus.release().leakRef(), resolver, co
ntext)); | 65 Platform::current()->mainThread()->getWebTaskRunner()->postTask(BLINK_FROM_H
ERE, threadSafeBind(&AsyncAudioDecoder::notifyComplete, AllowCrossThreadAccess(a
udioData), successCallback, errorCallback, bus.release().leakRef(), resolver, co
ntext)); |
69 } | 66 } |
70 | 67 |
71 void AsyncAudioDecoder::notifyComplete(DOMArrayBuffer* audioData, AudioBufferCal
lback* successCallback, AudioBufferCallback* errorCallback, AudioBus* audioBus,
ScriptPromiseResolver* resolver, AbstractAudioContext* context) | 68 void AsyncAudioDecoder::notifyComplete(DOMArrayBuffer*, AudioBufferCallback* suc
cessCallback, AudioBufferCallback* errorCallback, AudioBus* audioBus, ScriptProm
iseResolver* resolver, AbstractAudioContext* context) |
72 { | 69 { |
73 ASSERT(isMainThread()); | 70 ASSERT(isMainThread()); |
74 | 71 |
75 // Adopt references, so everything gets correctly dereffed. | 72 // Adopt references, so everything gets correctly dereffed. |
76 RefPtr<DOMArrayBuffer> audioDataRef = adoptRef(audioData); | |
77 RefPtr<AudioBus> audioBusRef = adoptRef(audioBus); | 73 RefPtr<AudioBus> audioBusRef = adoptRef(audioBus); |
78 | 74 |
79 AudioBuffer* audioBuffer = AudioBuffer::createFromAudioBus(audioBus); | 75 AudioBuffer* audioBuffer = AudioBuffer::createFromAudioBus(audioBus); |
80 | 76 |
81 // Let the context finish the notification. | 77 // Let the context finish the notification. |
82 context->handleDecodeAudioData(audioBuffer, resolver, successCallback, error
Callback); | 78 context->handleDecodeAudioData(audioBuffer, resolver, successCallback, error
Callback); |
83 } | 79 } |
84 | 80 |
85 } // namespace blink | 81 } // namespace blink |
OLD | NEW |