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

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

Issue 2820113006: Remove AudioBufferCallback (Closed)
Patch Set: Slightly reorder BaseAudioContext.idl Created 3 years, 8 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"
27 #include "core/dom/DOMArrayBuffer.h" 30 #include "core/dom/DOMArrayBuffer.h"
28 #include "modules/webaudio/AudioBuffer.h" 31 #include "modules/webaudio/AudioBuffer.h"
29 #include "modules/webaudio/AudioBufferCallback.h"
30 #include "modules/webaudio/BaseAudioContext.h" 32 #include "modules/webaudio/BaseAudioContext.h"
31 #include "platform/CrossThreadFunctional.h" 33 #include "platform/CrossThreadFunctional.h"
32 #include "platform/audio/AudioBus.h" 34 #include "platform/audio/AudioBus.h"
33 #include "platform/audio/AudioFileReader.h" 35 #include "platform/audio/AudioFileReader.h"
34 #include "platform/threading/BackgroundTaskRunner.h" 36 #include "platform/threading/BackgroundTaskRunner.h"
35 #include "platform/wtf/PtrUtil.h" 37 #include "platform/wtf/PtrUtil.h"
36 #include "public/platform/Platform.h" 38 #include "public/platform/Platform.h"
37 #include "public/platform/WebTraceLocation.h" 39 #include "public/platform/WebTraceLocation.h"
38 40
39 namespace blink { 41 namespace blink {
40 42
41 void AsyncAudioDecoder::DecodeAsync(DOMArrayBuffer* audio_data, 43 void AsyncAudioDecoder::DecodeAsync(DOMArrayBuffer* audio_data,
42 float sample_rate, 44 float sample_rate,
43 AudioBufferCallback* success_callback, 45 DecodeSuccessCallback* success_callback,
44 AudioBufferCallback* error_callback, 46 DecodeErrorCallback* error_callback,
45 ScriptPromiseResolver* resolver, 47 ScriptPromiseResolver* resolver,
46 BaseAudioContext* context) { 48 BaseAudioContext* context) {
47 DCHECK(IsMainThread()); 49 DCHECK(IsMainThread());
48 DCHECK(audio_data); 50 DCHECK(audio_data);
49 if (!audio_data) 51 if (!audio_data)
50 return; 52 return;
51 53
52 BackgroundTaskRunner::PostOnBackgroundThread( 54 BackgroundTaskRunner::PostOnBackgroundThread(
53 BLINK_FROM_HERE, 55 BLINK_FROM_HERE,
54 CrossThreadBind(&AsyncAudioDecoder::DecodeOnBackgroundThread, 56 CrossThreadBind(&AsyncAudioDecoder::DecodeOnBackgroundThread,
55 WrapCrossThreadPersistent(audio_data), sample_rate, 57 WrapCrossThreadPersistent(audio_data), sample_rate,
56 WrapCrossThreadPersistent(success_callback), 58 WrapCrossThreadPersistent(success_callback),
57 WrapCrossThreadPersistent(error_callback), 59 WrapCrossThreadPersistent(error_callback),
58 WrapCrossThreadPersistent(resolver), 60 WrapCrossThreadPersistent(resolver),
59 WrapCrossThreadPersistent(context))); 61 WrapCrossThreadPersistent(context)));
60 } 62 }
61 63
62 void AsyncAudioDecoder::DecodeOnBackgroundThread( 64 void AsyncAudioDecoder::DecodeOnBackgroundThread(
63 DOMArrayBuffer* audio_data, 65 DOMArrayBuffer* audio_data,
64 float sample_rate, 66 float sample_rate,
65 AudioBufferCallback* success_callback, 67 DecodeSuccessCallback* success_callback,
66 AudioBufferCallback* error_callback, 68 DecodeErrorCallback* error_callback,
67 ScriptPromiseResolver* resolver, 69 ScriptPromiseResolver* resolver,
68 BaseAudioContext* context) { 70 BaseAudioContext* context) {
69 DCHECK(!IsMainThread()); 71 DCHECK(!IsMainThread());
70 RefPtr<AudioBus> bus = CreateBusFromInMemoryAudioFile( 72 RefPtr<AudioBus> bus = CreateBusFromInMemoryAudioFile(
71 audio_data->Data(), audio_data->ByteLength(), false, sample_rate); 73 audio_data->Data(), audio_data->ByteLength(), false, sample_rate);
72 74
73 // Decoding is finished, but we need to do the callbacks on the main thread. 75 // Decoding is finished, but we need to do the callbacks on the main thread.
74 // A reference to |*bus| is retained by WTF::Function and will be removed 76 // A reference to |*bus| is retained by WTF::Function and will be removed
75 // after notifyComplete() is done. 77 // after notifyComplete() is done.
76 // 78 //
77 // We also want to avoid notifying the main thread if AudioContext does not 79 // We also want to avoid notifying the main thread if AudioContext does not
78 // exist any more. 80 // exist any more.
79 if (context) { 81 if (context) {
80 Platform::Current()->MainThread()->GetWebTaskRunner()->PostTask( 82 Platform::Current()->MainThread()->GetWebTaskRunner()->PostTask(
81 BLINK_FROM_HERE, 83 BLINK_FROM_HERE,
82 CrossThreadBind(&AsyncAudioDecoder::NotifyComplete, 84 CrossThreadBind(&AsyncAudioDecoder::NotifyComplete,
83 WrapCrossThreadPersistent(audio_data), 85 WrapCrossThreadPersistent(audio_data),
84 WrapCrossThreadPersistent(success_callback), 86 WrapCrossThreadPersistent(success_callback),
85 WrapCrossThreadPersistent(error_callback), 87 WrapCrossThreadPersistent(error_callback),
86 bus.Release(), WrapCrossThreadPersistent(resolver), 88 bus.Release(), WrapCrossThreadPersistent(resolver),
87 WrapCrossThreadPersistent(context))); 89 WrapCrossThreadPersistent(context)));
88 } 90 }
89 } 91 }
90 92
91 void AsyncAudioDecoder::NotifyComplete(DOMArrayBuffer*, 93 void AsyncAudioDecoder::NotifyComplete(DOMArrayBuffer*,
92 AudioBufferCallback* success_callback, 94 DecodeSuccessCallback* success_callback,
93 AudioBufferCallback* error_callback, 95 DecodeErrorCallback* error_callback,
94 AudioBus* audio_bus, 96 AudioBus* audio_bus,
95 ScriptPromiseResolver* resolver, 97 ScriptPromiseResolver* resolver,
96 BaseAudioContext* context) { 98 BaseAudioContext* context) {
97 DCHECK(IsMainThread()); 99 DCHECK(IsMainThread());
98 100
99 AudioBuffer* audio_buffer = AudioBuffer::CreateFromAudioBus(audio_bus); 101 AudioBuffer* audio_buffer = AudioBuffer::CreateFromAudioBus(audio_bus);
100 102
101 // If the context is available, let the context finish the notification. 103 // If the context is available, let the context finish the notification.
102 if (context) { 104 if (context) {
103 context->HandleDecodeAudioData(audio_buffer, resolver, success_callback, 105 context->HandleDecodeAudioData(audio_buffer, resolver, success_callback,
104 error_callback); 106 error_callback);
105 } 107 }
106 } 108 }
107 109
108 } // namespace blink 110 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698