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 267 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
278 DCHECK(IsMainThread()); | 278 DCHECK(IsMainThread()); |
279 DCHECK(audio_data); | 279 DCHECK(audio_data); |
280 | 280 |
281 ScriptPromiseResolver* resolver = ScriptPromiseResolver::Create(script_state); | 281 ScriptPromiseResolver* resolver = ScriptPromiseResolver::Create(script_state); |
282 ScriptPromise promise = resolver->Promise(); | 282 ScriptPromise promise = resolver->Promise(); |
283 | 283 |
284 float rate = IsContextClosed() ? ClosedContextSampleRate() : sampleRate(); | 284 float rate = IsContextClosed() ? ClosedContextSampleRate() : sampleRate(); |
285 | 285 |
286 DCHECK_GT(rate, 0); | 286 DCHECK_GT(rate, 0); |
287 | 287 |
288 if (audio_data->IsNeutered()) { | 288 v8::Isolate* isolate = script_state->GetIsolate(); |
289 // If audioData is detached (neutered) we need to reject the | 289 WTF::ArrayBufferContents buffer_contents; |
| 290 // Detach the audio array buffer from the main thread and start |
| 291 // async decoding of the data. |
| 292 if (audio_data->IsNeuterable(isolate) && |
| 293 audio_data->Transfer(isolate, buffer_contents)) { |
| 294 DOMArrayBuffer* audio = DOMArrayBuffer::Create(buffer_contents); |
| 295 |
| 296 decode_audio_resolvers_.insert(resolver); |
| 297 audio_decoder_.DecodeAsync(audio, rate, success_callback, error_callback, |
| 298 resolver, this); |
| 299 } else { |
| 300 // If audioData is already detached (neutered) we need to reject the |
290 // promise with an error. | 301 // promise with an error. |
291 DOMException* error = DOMException::Create( | 302 DOMException* error = DOMException::Create( |
292 kDataCloneError, "Cannot decode detached ArrayBuffer"); | 303 kDataCloneError, "Cannot decode detached ArrayBuffer"); |
293 resolver->Reject(error); | 304 resolver->Reject(error); |
294 if (error_callback) { | 305 if (error_callback) { |
295 error_callback->handleEvent(error); | 306 error_callback->handleEvent(error); |
296 } | 307 } |
297 } else { | |
298 // Detach the audio array buffer from the main thread and start | |
299 // async decoding of the data. | |
300 WTF::ArrayBufferContents buffer_contents; | |
301 audio_data->Transfer(buffer_contents); | |
302 DOMArrayBuffer* audio = DOMArrayBuffer::Create(buffer_contents); | |
303 | |
304 decode_audio_resolvers_.insert(resolver); | |
305 audio_decoder_.DecodeAsync(audio, rate, success_callback, error_callback, | |
306 resolver, this); | |
307 } | 308 } |
308 | 309 |
309 return promise; | 310 return promise; |
310 } | 311 } |
311 | 312 |
312 void BaseAudioContext::HandleDecodeAudioData( | 313 void BaseAudioContext::HandleDecodeAudioData( |
313 AudioBuffer* audio_buffer, | 314 AudioBuffer* audio_buffer, |
314 ScriptPromiseResolver* resolver, | 315 ScriptPromiseResolver* resolver, |
315 AudioBufferCallback* success_callback, | 316 AudioBufferCallback* success_callback, |
316 AudioBufferCallback* error_callback) { | 317 AudioBufferCallback* error_callback) { |
(...skipping 602 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
919 } | 920 } |
920 | 921 |
921 SecurityOrigin* BaseAudioContext::GetSecurityOrigin() const { | 922 SecurityOrigin* BaseAudioContext::GetSecurityOrigin() const { |
922 if (GetExecutionContext()) | 923 if (GetExecutionContext()) |
923 return GetExecutionContext()->GetSecurityOrigin(); | 924 return GetExecutionContext()->GetSecurityOrigin(); |
924 | 925 |
925 return nullptr; | 926 return nullptr; |
926 } | 927 } |
927 | 928 |
928 } // namespace blink | 929 } // namespace blink |
OLD | NEW |