Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(268)

Side by Side Diff: third_party/WebKit/Source/modules/webaudio/AsyncAudioDecoder.cpp

Issue 1964183004: Revert of Move DOMArrayBuffer, DOMArrayBufferViews and DataView to the heap. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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
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
55 // The leak references to successCallback and errorCallback are picked up on notifyComplete. 58 // The leak references to successCallback and errorCallback are picked up on notifyComplete.
56 m_thread->getWebTaskRunner()->postTask(BLINK_FROM_HERE, threadSafeBind(&Asyn cAudioDecoder::decode, AllowCrossThreadAccess(audioData), sampleRate, successCal lback, errorCallback, resolver, context)); 59 m_thread->getWebTaskRunner()->postTask(BLINK_FROM_HERE, threadSafeBind(&Asyn cAudioDecoder::decode, AllowCrossThreadAccess(audioDataRef.release().leakRef()), sampleRate, successCallback, errorCallback, resolver, context));
57 } 60 }
58 61
59 void AsyncAudioDecoder::decode(DOMArrayBuffer* audioData, float sampleRate, Audi oBufferCallback* successCallback, AudioBufferCallback* errorCallback, ScriptProm iseResolver* resolver, AbstractAudioContext* context) 62 void AsyncAudioDecoder::decode(DOMArrayBuffer* audioData, float sampleRate, Audi oBufferCallback* successCallback, AudioBufferCallback* errorCallback, ScriptProm iseResolver* resolver, AbstractAudioContext* context)
60 { 63 {
61 RefPtr<AudioBus> bus = createBusFromInMemoryAudioFile(audioData->data(), aud ioData->byteLength(), false, sampleRate); 64 RefPtr<AudioBus> bus = createBusFromInMemoryAudioFile(audioData->data(), aud ioData->byteLength(), false, sampleRate);
62 65
63 // Decoding is finished, but we need to do the callbacks on the main thread. 66 // 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. 67 // The leaked reference to audioBuffer is picked up in notifyComplete.
65 Platform::current()->mainThread()->getWebTaskRunner()->postTask(BLINK_FROM_H ERE, threadSafeBind(&AsyncAudioDecoder::notifyComplete, AllowCrossThreadAccess(a udioData), successCallback, errorCallback, bus.release().leakRef(), resolver, co ntext)); 68 Platform::current()->mainThread()->getWebTaskRunner()->postTask(BLINK_FROM_H ERE, threadSafeBind(&AsyncAudioDecoder::notifyComplete, AllowCrossThreadAccess(a udioData), successCallback, errorCallback, bus.release().leakRef(), resolver, co ntext));
66 } 69 }
67 70
68 void AsyncAudioDecoder::notifyComplete(DOMArrayBuffer*, AudioBufferCallback* suc cessCallback, AudioBufferCallback* errorCallback, AudioBus* audioBus, ScriptProm iseResolver* resolver, AbstractAudioContext* context) 71 void AsyncAudioDecoder::notifyComplete(DOMArrayBuffer* audioData, AudioBufferCal lback* successCallback, AudioBufferCallback* errorCallback, AudioBus* audioBus, ScriptPromiseResolver* resolver, AbstractAudioContext* context)
69 { 72 {
70 ASSERT(isMainThread()); 73 ASSERT(isMainThread());
71 74
72 // Adopt references, so everything gets correctly dereffed. 75 // Adopt references, so everything gets correctly dereffed.
76 RefPtr<DOMArrayBuffer> audioDataRef = adoptRef(audioData);
73 RefPtr<AudioBus> audioBusRef = adoptRef(audioBus); 77 RefPtr<AudioBus> audioBusRef = adoptRef(audioBus);
74 78
75 AudioBuffer* audioBuffer = AudioBuffer::createFromAudioBus(audioBus); 79 AudioBuffer* audioBuffer = AudioBuffer::createFromAudioBus(audioBus);
76 80
77 // Let the context finish the notification. 81 // Let the context finish the notification.
78 context->handleDecodeAudioData(audioBuffer, resolver, successCallback, error Callback); 82 context->handleDecodeAudioData(audioBuffer, resolver, successCallback, error Callback);
79 } 83 }
80 84
81 } // namespace blink 85 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698