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

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

Issue 2866503002: Revert removal of AudioBufferCallback (Closed)
Patch Set: Add AudioBufferCallback.{h,idl} Created 3 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
11 * documentation and/or other materials provided with the distribution. 11 * documentation and/or other materials provided with the distribution.
12 * 12 *
13 * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS'' AND 13 * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS'' AND
14 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 14 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
15 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 15 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
16 * ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS BE LIABLE 16 * ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS BE LIABLE
17 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 17 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
18 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 18 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
19 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 19 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
20 * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 20 * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
21 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 21 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
22 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH 22 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
23 * DAMAGE. 23 * DAMAGE.
24 */ 24 */
25 25
26 #include "modules/webaudio/AsyncAudioDecoder.h" 26 #include "modules/webaudio/AsyncAudioDecoder.h"
27
28 #include "bindings/modules/v8/DecodeErrorCallback.h"
29 #include "bindings/modules/v8/DecodeSuccessCallback.h"
30 #include "core/dom/DOMArrayBuffer.h" 27 #include "core/dom/DOMArrayBuffer.h"
31 #include "modules/webaudio/AudioBuffer.h" 28 #include "modules/webaudio/AudioBuffer.h"
29 #include "modules/webaudio/AudioBufferCallback.h"
32 #include "modules/webaudio/BaseAudioContext.h" 30 #include "modules/webaudio/BaseAudioContext.h"
33 #include "platform/CrossThreadFunctional.h" 31 #include "platform/CrossThreadFunctional.h"
34 #include "platform/audio/AudioBus.h" 32 #include "platform/audio/AudioBus.h"
35 #include "platform/audio/AudioFileReader.h" 33 #include "platform/audio/AudioFileReader.h"
36 #include "platform/threading/BackgroundTaskRunner.h" 34 #include "platform/threading/BackgroundTaskRunner.h"
37 #include "platform/wtf/PtrUtil.h" 35 #include "platform/wtf/PtrUtil.h"
38 #include "public/platform/Platform.h" 36 #include "public/platform/Platform.h"
39 #include "public/platform/WebTraceLocation.h" 37 #include "public/platform/WebTraceLocation.h"
40 38
41 namespace blink { 39 namespace blink {
42 40
43 void AsyncAudioDecoder::DecodeAsync(DOMArrayBuffer* audio_data, 41 void AsyncAudioDecoder::DecodeAsync(DOMArrayBuffer* audio_data,
44 float sample_rate, 42 float sample_rate,
45 DecodeSuccessCallback* success_callback, 43 AudioBufferCallback* success_callback,
46 DecodeErrorCallback* error_callback, 44 AudioBufferCallback* error_callback,
47 ScriptPromiseResolver* resolver, 45 ScriptPromiseResolver* resolver,
48 BaseAudioContext* context) { 46 BaseAudioContext* context) {
49 DCHECK(IsMainThread()); 47 DCHECK(IsMainThread());
50 DCHECK(audio_data); 48 DCHECK(audio_data);
51 if (!audio_data) 49 if (!audio_data)
52 return; 50 return;
53 51
54 BackgroundTaskRunner::PostOnBackgroundThread( 52 BackgroundTaskRunner::PostOnBackgroundThread(
55 BLINK_FROM_HERE, 53 BLINK_FROM_HERE,
56 CrossThreadBind(&AsyncAudioDecoder::DecodeOnBackgroundThread, 54 CrossThreadBind(&AsyncAudioDecoder::DecodeOnBackgroundThread,
57 WrapCrossThreadPersistent(audio_data), sample_rate, 55 WrapCrossThreadPersistent(audio_data), sample_rate,
58 WrapCrossThreadPersistent(success_callback), 56 WrapCrossThreadPersistent(success_callback),
59 WrapCrossThreadPersistent(error_callback), 57 WrapCrossThreadPersistent(error_callback),
60 WrapCrossThreadPersistent(resolver), 58 WrapCrossThreadPersistent(resolver),
61 WrapCrossThreadPersistent(context))); 59 WrapCrossThreadPersistent(context)));
62 } 60 }
63 61
64 void AsyncAudioDecoder::DecodeOnBackgroundThread( 62 void AsyncAudioDecoder::DecodeOnBackgroundThread(
65 DOMArrayBuffer* audio_data, 63 DOMArrayBuffer* audio_data,
66 float sample_rate, 64 float sample_rate,
67 DecodeSuccessCallback* success_callback, 65 AudioBufferCallback* success_callback,
68 DecodeErrorCallback* error_callback, 66 AudioBufferCallback* error_callback,
69 ScriptPromiseResolver* resolver, 67 ScriptPromiseResolver* resolver,
70 BaseAudioContext* context) { 68 BaseAudioContext* context) {
71 DCHECK(!IsMainThread()); 69 DCHECK(!IsMainThread());
72 RefPtr<AudioBus> bus = CreateBusFromInMemoryAudioFile( 70 RefPtr<AudioBus> bus = CreateBusFromInMemoryAudioFile(
73 audio_data->Data(), audio_data->ByteLength(), false, sample_rate); 71 audio_data->Data(), audio_data->ByteLength(), false, sample_rate);
74 72
75 // Decoding is finished, but we need to do the callbacks on the main thread. 73 // Decoding is finished, but we need to do the callbacks on the main thread.
76 // A reference to |*bus| is retained by WTF::Function and will be removed 74 // A reference to |*bus| is retained by WTF::Function and will be removed
77 // after notifyComplete() is done. 75 // after notifyComplete() is done.
78 // 76 //
79 // We also want to avoid notifying the main thread if AudioContext does not 77 // We also want to avoid notifying the main thread if AudioContext does not
80 // exist any more. 78 // exist any more.
81 if (context) { 79 if (context) {
82 Platform::Current()->MainThread()->GetWebTaskRunner()->PostTask( 80 Platform::Current()->MainThread()->GetWebTaskRunner()->PostTask(
83 BLINK_FROM_HERE, 81 BLINK_FROM_HERE,
84 CrossThreadBind(&AsyncAudioDecoder::NotifyComplete, 82 CrossThreadBind(&AsyncAudioDecoder::NotifyComplete,
85 WrapCrossThreadPersistent(audio_data), 83 WrapCrossThreadPersistent(audio_data),
86 WrapCrossThreadPersistent(success_callback), 84 WrapCrossThreadPersistent(success_callback),
87 WrapCrossThreadPersistent(error_callback), 85 WrapCrossThreadPersistent(error_callback),
88 bus.Release(), WrapCrossThreadPersistent(resolver), 86 bus.Release(), WrapCrossThreadPersistent(resolver),
89 WrapCrossThreadPersistent(context))); 87 WrapCrossThreadPersistent(context)));
90 } 88 }
91 } 89 }
92 90
93 void AsyncAudioDecoder::NotifyComplete(DOMArrayBuffer*, 91 void AsyncAudioDecoder::NotifyComplete(DOMArrayBuffer*,
94 DecodeSuccessCallback* success_callback, 92 AudioBufferCallback* success_callback,
95 DecodeErrorCallback* error_callback, 93 AudioBufferCallback* error_callback,
96 AudioBus* audio_bus, 94 AudioBus* audio_bus,
97 ScriptPromiseResolver* resolver, 95 ScriptPromiseResolver* resolver,
98 BaseAudioContext* context) { 96 BaseAudioContext* context) {
99 DCHECK(IsMainThread()); 97 DCHECK(IsMainThread());
100 98
101 AudioBuffer* audio_buffer = AudioBuffer::CreateFromAudioBus(audio_bus); 99 AudioBuffer* audio_buffer = AudioBuffer::CreateFromAudioBus(audio_bus);
102 100
103 // If the context is available, let the context finish the notification. 101 // If the context is available, let the context finish the notification.
104 if (context) { 102 if (context) {
105 context->HandleDecodeAudioData(audio_buffer, resolver, success_callback, 103 context->HandleDecodeAudioData(audio_buffer, resolver, success_callback,
106 error_callback); 104 error_callback);
107 } 105 }
108 } 106 }
109 107
110 } // namespace blink 108 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698