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

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

Powered by Google App Engine
This is Rietveld 408576698