| 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->Transfer(isolate, buffer_contents)) { |
| 293 DOMArrayBuffer* audio = DOMArrayBuffer::Create(buffer_contents); |
| 294 |
| 295 decode_audio_resolvers_.insert(resolver); |
| 296 audio_decoder_.DecodeAsync(audio, rate, success_callback, error_callback, |
| 297 resolver, this); |
| 298 } else { |
| 299 // If audioData is already detached (neutered) we need to reject the |
| 290 // promise with an error. | 300 // promise with an error. |
| 291 DOMException* error = DOMException::Create( | 301 DOMException* error = DOMException::Create( |
| 292 kDataCloneError, "Cannot decode detached ArrayBuffer"); | 302 kDataCloneError, "Cannot decode detached ArrayBuffer"); |
| 293 resolver->Reject(error); | 303 resolver->Reject(error); |
| 294 if (error_callback) { | 304 if (error_callback) { |
| 295 error_callback->handleEvent(error); | 305 error_callback->handleEvent(error); |
| 296 } | 306 } |
| 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 } | 307 } |
| 308 | 308 |
| 309 return promise; | 309 return promise; |
| 310 } | 310 } |
| 311 | 311 |
| 312 void BaseAudioContext::HandleDecodeAudioData( | 312 void BaseAudioContext::HandleDecodeAudioData( |
| 313 AudioBuffer* audio_buffer, | 313 AudioBuffer* audio_buffer, |
| 314 ScriptPromiseResolver* resolver, | 314 ScriptPromiseResolver* resolver, |
| 315 AudioBufferCallback* success_callback, | 315 AudioBufferCallback* success_callback, |
| 316 AudioBufferCallback* error_callback) { | 316 AudioBufferCallback* error_callback) { |
| (...skipping 602 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 919 } | 919 } |
| 920 | 920 |
| 921 SecurityOrigin* BaseAudioContext::GetSecurityOrigin() const { | 921 SecurityOrigin* BaseAudioContext::GetSecurityOrigin() const { |
| 922 if (GetExecutionContext()) | 922 if (GetExecutionContext()) |
| 923 return GetExecutionContext()->GetSecurityOrigin(); | 923 return GetExecutionContext()->GetSecurityOrigin(); |
| 924 | 924 |
| 925 return nullptr; | 925 return nullptr; |
| 926 } | 926 } |
| 927 | 927 |
| 928 } // namespace blink | 928 } // namespace blink |
| OLD | NEW |