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

Side by Side Diff: third_party/WebKit/Source/modules/webaudio/BaseAudioContext.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) 2010, Google Inc. All rights reserved. 2 * Copyright (C) 2010, 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 11 matching lines...) Expand all
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/BaseAudioContext.h" 26 #include "modules/webaudio/BaseAudioContext.h"
27 27
28 #include "bindings/core/v8/Dictionary.h" 28 #include "bindings/core/v8/Dictionary.h"
29 #include "bindings/core/v8/ExceptionMessages.h" 29 #include "bindings/core/v8/ExceptionMessages.h"
30 #include "bindings/core/v8/ExceptionState.h" 30 #include "bindings/core/v8/ExceptionState.h"
31 #include "bindings/core/v8/ScriptPromiseResolver.h" 31 #include "bindings/core/v8/ScriptPromiseResolver.h"
32 #include "bindings/modules/v8/DecodeErrorCallback.h"
33 #include "bindings/modules/v8/DecodeSuccessCallback.h"
34 #include "core/dom/DOMException.h" 32 #include "core/dom/DOMException.h"
35 #include "core/dom/Document.h" 33 #include "core/dom/Document.h"
36 #include "core/dom/ExceptionCode.h" 34 #include "core/dom/ExceptionCode.h"
37 #include "core/dom/TaskRunnerHelper.h" 35 #include "core/dom/TaskRunnerHelper.h"
38 #include "core/frame/Settings.h" 36 #include "core/frame/Settings.h"
39 #include "core/html/HTMLMediaElement.h" 37 #include "core/html/HTMLMediaElement.h"
40 #include "core/inspector/ConsoleMessage.h" 38 #include "core/inspector/ConsoleMessage.h"
41 #include "core/inspector/ConsoleTypes.h" 39 #include "core/inspector/ConsoleTypes.h"
42 #include "modules/mediastream/MediaStream.h" 40 #include "modules/mediastream/MediaStream.h"
43 #include "modules/webaudio/AnalyserNode.h" 41 #include "modules/webaudio/AnalyserNode.h"
44 #include "modules/webaudio/AudioBuffer.h" 42 #include "modules/webaudio/AudioBuffer.h"
43 #include "modules/webaudio/AudioBufferCallback.h"
45 #include "modules/webaudio/AudioBufferSourceNode.h" 44 #include "modules/webaudio/AudioBufferSourceNode.h"
46 #include "modules/webaudio/AudioContext.h" 45 #include "modules/webaudio/AudioContext.h"
47 #include "modules/webaudio/AudioListener.h" 46 #include "modules/webaudio/AudioListener.h"
48 #include "modules/webaudio/AudioNodeInput.h" 47 #include "modules/webaudio/AudioNodeInput.h"
49 #include "modules/webaudio/AudioNodeOutput.h" 48 #include "modules/webaudio/AudioNodeOutput.h"
50 #include "modules/webaudio/BiquadFilterNode.h" 49 #include "modules/webaudio/BiquadFilterNode.h"
51 #include "modules/webaudio/ChannelMergerNode.h" 50 #include "modules/webaudio/ChannelMergerNode.h"
52 #include "modules/webaudio/ChannelSplitterNode.h" 51 #include "modules/webaudio/ChannelSplitterNode.h"
53 #include "modules/webaudio/ConstantSourceNode.h" 52 #include "modules/webaudio/ConstantSourceNode.h"
54 #include "modules/webaudio/ConvolverNode.h" 53 #include "modules/webaudio/ConvolverNode.h"
(...skipping 211 matching lines...) Expand 10 before | Expand all | Expand 10 after
266 static_cast<int>(0.5 + ratio)); 265 static_cast<int>(0.5 + ratio));
267 } 266 }
268 } 267 }
269 268
270 return buffer; 269 return buffer;
271 } 270 }
272 271
273 ScriptPromise BaseAudioContext::decodeAudioData( 272 ScriptPromise BaseAudioContext::decodeAudioData(
274 ScriptState* script_state, 273 ScriptState* script_state,
275 DOMArrayBuffer* audio_data, 274 DOMArrayBuffer* audio_data,
276 ExceptionState& exception_state) { 275 AudioBufferCallback* success_callback,
277 return decodeAudioData(script_state, audio_data, nullptr, nullptr, 276 AudioBufferCallback* error_callback,
278 exception_state);
279 }
280
281 ScriptPromise BaseAudioContext::decodeAudioData(
282 ScriptState* script_state,
283 DOMArrayBuffer* audio_data,
284 DecodeSuccessCallback* success_callback,
285 ExceptionState& exception_state) {
286 return decodeAudioData(script_state, audio_data, success_callback, nullptr,
287 exception_state);
288 }
289
290 ScriptPromise BaseAudioContext::decodeAudioData(
291 ScriptState* script_state,
292 DOMArrayBuffer* audio_data,
293 DecodeSuccessCallback* success_callback,
294 DecodeErrorCallback* error_callback,
295 ExceptionState& exception_state) { 277 ExceptionState& exception_state) {
296 DCHECK(IsMainThread()); 278 DCHECK(IsMainThread());
297 DCHECK(audio_data); 279 DCHECK(audio_data);
298 280
299 ScriptPromiseResolver* resolver = ScriptPromiseResolver::Create(script_state); 281 ScriptPromiseResolver* resolver = ScriptPromiseResolver::Create(script_state);
300 ScriptPromise promise = resolver->Promise(); 282 ScriptPromise promise = resolver->Promise();
301 283
302 float rate = IsContextClosed() ? ClosedContextSampleRate() : sampleRate(); 284 float rate = IsContextClosed() ? ClosedContextSampleRate() : sampleRate();
303 285
304 DCHECK_GT(rate, 0); 286 DCHECK_GT(rate, 0);
305 287
306 v8::Isolate* isolate = script_state->GetIsolate(); 288 v8::Isolate* isolate = script_state->GetIsolate();
307 WTF::ArrayBufferContents buffer_contents; 289 WTF::ArrayBufferContents buffer_contents;
308 // Detach the audio array buffer from the main thread and start 290 // Detach the audio array buffer from the main thread and start
309 // async decoding of the data. 291 // async decoding of the data.
310 if (audio_data->IsNeuterable(isolate) && 292 if (audio_data->IsNeuterable(isolate) &&
311 audio_data->Transfer(isolate, buffer_contents)) { 293 audio_data->Transfer(isolate, buffer_contents)) {
312 DOMArrayBuffer* audio = DOMArrayBuffer::Create(buffer_contents); 294 DOMArrayBuffer* audio = DOMArrayBuffer::Create(buffer_contents);
313 295
314 decode_audio_resolvers_.insert(resolver); 296 decode_audio_resolvers_.insert(resolver);
315 audio_decoder_.DecodeAsync(audio, rate, success_callback, error_callback, 297 audio_decoder_.DecodeAsync(audio, rate, success_callback, error_callback,
316 resolver, this); 298 resolver, this);
317 } else { 299 } else {
318 // If audioData is already detached (neutered) we need to reject the 300 // If audioData is already detached (neutered) we need to reject the
319 // promise with an error. 301 // promise with an error.
320 DOMException* error = DOMException::Create( 302 DOMException* error = DOMException::Create(
321 kDataCloneError, "Cannot decode detached ArrayBuffer"); 303 kDataCloneError, "Cannot decode detached ArrayBuffer");
322 resolver->Reject(error); 304 resolver->Reject(error);
323 if (error_callback) { 305 if (error_callback) {
324 error_callback->call(this, error); 306 error_callback->handleEvent(error);
325 } 307 }
326 } 308 }
327 309
328 return promise; 310 return promise;
329 } 311 }
330 312
331 void BaseAudioContext::HandleDecodeAudioData( 313 void BaseAudioContext::HandleDecodeAudioData(
332 AudioBuffer* audio_buffer, 314 AudioBuffer* audio_buffer,
333 ScriptPromiseResolver* resolver, 315 ScriptPromiseResolver* resolver,
334 DecodeSuccessCallback* success_callback, 316 AudioBufferCallback* success_callback,
335 DecodeErrorCallback* error_callback) { 317 AudioBufferCallback* error_callback) {
336 DCHECK(IsMainThread()); 318 DCHECK(IsMainThread());
337 319
338 if (audio_buffer) { 320 if (audio_buffer) {
339 // Resolve promise successfully and run the success callback 321 // Resolve promise successfully and run the success callback
340 resolver->Resolve(audio_buffer); 322 resolver->Resolve(audio_buffer);
341 if (success_callback) 323 if (success_callback)
342 success_callback->call(this, audio_buffer); 324 success_callback->handleEvent(audio_buffer);
343 } else { 325 } else {
344 // Reject the promise and run the error callback 326 // Reject the promise and run the error callback
345 DOMException* error = 327 DOMException* error =
346 DOMException::Create(kEncodingError, "Unable to decode audio data"); 328 DOMException::Create(kEncodingError, "Unable to decode audio data");
347 resolver->Reject(error); 329 resolver->Reject(error);
348 if (error_callback) 330 if (error_callback)
349 error_callback->call(this, error); 331 error_callback->handleEvent(error);
350 } 332 }
351 333
352 // We've resolved the promise. Remove it now. 334 // We've resolved the promise. Remove it now.
353 DCHECK(decode_audio_resolvers_.Contains(resolver)); 335 DCHECK(decode_audio_resolvers_.Contains(resolver));
354 decode_audio_resolvers_.erase(resolver); 336 decode_audio_resolvers_.erase(resolver);
355 } 337 }
356 338
357 AudioBufferSourceNode* BaseAudioContext::createBufferSource( 339 AudioBufferSourceNode* BaseAudioContext::createBufferSource(
358 ExceptionState& exception_state) { 340 ExceptionState& exception_state) {
359 DCHECK(IsMainThread()); 341 DCHECK(IsMainThread());
(...skipping 577 matching lines...) Expand 10 before | Expand all | Expand 10 after
937 } 919 }
938 920
939 SecurityOrigin* BaseAudioContext::GetSecurityOrigin() const { 921 SecurityOrigin* BaseAudioContext::GetSecurityOrigin() const {
940 if (GetExecutionContext()) 922 if (GetExecutionContext())
941 return GetExecutionContext()->GetSecurityOrigin(); 923 return GetExecutionContext()->GetSecurityOrigin();
942 924
943 return nullptr; 925 return nullptr;
944 } 926 }
945 927
946 } // namespace blink 928 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698