OLD | NEW |
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 285 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
296 DCHECK(IsMainThread()); | 296 DCHECK(IsMainThread()); |
297 DCHECK(audio_data); | 297 DCHECK(audio_data); |
298 | 298 |
299 ScriptPromiseResolver* resolver = ScriptPromiseResolver::Create(script_state); | 299 ScriptPromiseResolver* resolver = ScriptPromiseResolver::Create(script_state); |
300 ScriptPromise promise = resolver->Promise(); | 300 ScriptPromise promise = resolver->Promise(); |
301 | 301 |
302 float rate = IsContextClosed() ? ClosedContextSampleRate() : sampleRate(); | 302 float rate = IsContextClosed() ? ClosedContextSampleRate() : sampleRate(); |
303 | 303 |
304 DCHECK_GT(rate, 0); | 304 DCHECK_GT(rate, 0); |
305 | 305 |
306 if (audio_data->IsNeutered()) { | 306 v8::Isolate* isolate = script_state->GetIsolate(); |
307 // If audioData is detached (neutered) we need to reject the | 307 WTF::ArrayBufferContents buffer_contents; |
| 308 // Detach the audio array buffer from the main thread and start |
| 309 // async decoding of the data. |
| 310 if (audio_data->IsNeuterable(isolate) && |
| 311 audio_data->Transfer(isolate, buffer_contents)) { |
| 312 DOMArrayBuffer* audio = DOMArrayBuffer::Create(buffer_contents); |
| 313 |
| 314 decode_audio_resolvers_.insert(resolver); |
| 315 audio_decoder_.DecodeAsync(audio, rate, success_callback, error_callback, |
| 316 resolver, this); |
| 317 } else { |
| 318 // If audioData is already detached (neutered) we need to reject the |
308 // promise with an error. | 319 // promise with an error. |
309 DOMException* error = DOMException::Create( | 320 DOMException* error = DOMException::Create( |
310 kDataCloneError, "Cannot decode detached ArrayBuffer"); | 321 kDataCloneError, "Cannot decode detached ArrayBuffer"); |
311 resolver->Reject(error); | 322 resolver->Reject(error); |
312 if (error_callback) { | 323 if (error_callback) { |
313 error_callback->call(this, error); | 324 error_callback->call(this, error); |
314 } | 325 } |
315 } else { | |
316 // Detach the audio array buffer from the main thread and start | |
317 // async decoding of the data. | |
318 WTF::ArrayBufferContents buffer_contents; | |
319 audio_data->Transfer(buffer_contents); | |
320 DOMArrayBuffer* audio = DOMArrayBuffer::Create(buffer_contents); | |
321 | |
322 decode_audio_resolvers_.insert(resolver); | |
323 audio_decoder_.DecodeAsync(audio, rate, success_callback, error_callback, | |
324 resolver, this); | |
325 } | 326 } |
326 | 327 |
327 return promise; | 328 return promise; |
328 } | 329 } |
329 | 330 |
330 void BaseAudioContext::HandleDecodeAudioData( | 331 void BaseAudioContext::HandleDecodeAudioData( |
331 AudioBuffer* audio_buffer, | 332 AudioBuffer* audio_buffer, |
332 ScriptPromiseResolver* resolver, | 333 ScriptPromiseResolver* resolver, |
333 DecodeSuccessCallback* success_callback, | 334 DecodeSuccessCallback* success_callback, |
334 DecodeErrorCallback* error_callback) { | 335 DecodeErrorCallback* error_callback) { |
(...skipping 602 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
937 } | 938 } |
938 | 939 |
939 SecurityOrigin* BaseAudioContext::GetSecurityOrigin() const { | 940 SecurityOrigin* BaseAudioContext::GetSecurityOrigin() const { |
940 if (GetExecutionContext()) | 941 if (GetExecutionContext()) |
941 return GetExecutionContext()->GetSecurityOrigin(); | 942 return GetExecutionContext()->GetSecurityOrigin(); |
942 | 943 |
943 return nullptr; | 944 return nullptr; |
944 } | 945 } |
945 | 946 |
946 } // namespace blink | 947 } // namespace blink |
OLD | NEW |