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 266 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
277 DCHECK(isMainThread()); | 277 DCHECK(isMainThread()); |
278 DCHECK(audioData); | 278 DCHECK(audioData); |
279 | 279 |
280 ScriptPromiseResolver* resolver = ScriptPromiseResolver::create(scriptState); | 280 ScriptPromiseResolver* resolver = ScriptPromiseResolver::create(scriptState); |
281 ScriptPromise promise = resolver->promise(); | 281 ScriptPromise promise = resolver->promise(); |
282 | 282 |
283 float rate = isContextClosed() ? closedContextSampleRate() : sampleRate(); | 283 float rate = isContextClosed() ? closedContextSampleRate() : sampleRate(); |
284 | 284 |
285 DCHECK_GT(rate, 0); | 285 DCHECK_GT(rate, 0); |
286 | 286 |
287 m_decodeAudioResolvers.insert(resolver); | 287 if (audioData->isNeutered()) { |
288 m_audioDecoder.decodeAsync(audioData, rate, successCallback, errorCallback, | 288 // If audioData is detached (neutered) we need to reject the |
289 resolver, this); | 289 // promise with an error. |
| 290 DOMException* error = DOMException::create( |
| 291 DataCloneError, "Cannot decode detached ArrayBuffer"); |
| 292 resolver->reject(error); |
| 293 if (errorCallback) { |
| 294 errorCallback->handleEvent(error); |
| 295 } |
| 296 } else { |
| 297 // Detach the audio array buffer from the main thread and start |
| 298 // async decoding of the data. |
| 299 WTF::ArrayBufferContents bufferContents; |
| 300 audioData->transfer(bufferContents); |
| 301 DOMArrayBuffer* audio = DOMArrayBuffer::create(bufferContents); |
| 302 |
| 303 m_decodeAudioResolvers.insert(resolver); |
| 304 m_audioDecoder.decodeAsync(audio, rate, successCallback, errorCallback, |
| 305 resolver, this); |
| 306 } |
290 | 307 |
291 return promise; | 308 return promise; |
292 } | 309 } |
293 | 310 |
294 void BaseAudioContext::handleDecodeAudioData( | 311 void BaseAudioContext::handleDecodeAudioData( |
295 AudioBuffer* audioBuffer, | 312 AudioBuffer* audioBuffer, |
296 ScriptPromiseResolver* resolver, | 313 ScriptPromiseResolver* resolver, |
297 AudioBufferCallback* successCallback, | 314 AudioBufferCallback* successCallback, |
298 AudioBufferCallback* errorCallback) { | 315 AudioBufferCallback* errorCallback) { |
299 DCHECK(isMainThread()); | 316 DCHECK(isMainThread()); |
(...skipping 601 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
901 } | 918 } |
902 | 919 |
903 SecurityOrigin* BaseAudioContext::getSecurityOrigin() const { | 920 SecurityOrigin* BaseAudioContext::getSecurityOrigin() const { |
904 if (getExecutionContext()) | 921 if (getExecutionContext()) |
905 return getExecutionContext()->getSecurityOrigin(); | 922 return getExecutionContext()->getSecurityOrigin(); |
906 | 923 |
907 return nullptr; | 924 return nullptr; |
908 } | 925 } |
909 | 926 |
910 } // namespace blink | 927 } // namespace blink |
OLD | NEW |