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

Side by Side Diff: Source/modules/webaudio/AsyncAudioDecoder.cpp

Issue 85263006: Make IDL Callbacks non-refcounted by default (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: Patch for landing Created 7 years 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 | Annotate | Revision Log
OLDNEW
1 /* 1 /*
2 * Copyright (C) 2011, Google Inc. All rights reserved. 2 * Copyright (C) 2011, 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 29 matching lines...) Expand all
40 40
41 AsyncAudioDecoder::AsyncAudioDecoder() 41 AsyncAudioDecoder::AsyncAudioDecoder()
42 : m_thread(adoptPtr(blink::Platform::current()->createThread("Audio Decoder" ))) 42 : m_thread(adoptPtr(blink::Platform::current()->createThread("Audio Decoder" )))
43 { 43 {
44 } 44 }
45 45
46 AsyncAudioDecoder::~AsyncAudioDecoder() 46 AsyncAudioDecoder::~AsyncAudioDecoder()
47 { 47 {
48 } 48 }
49 49
50 void AsyncAudioDecoder::decodeAsync(ArrayBuffer* audioData, float sampleRate, Pa ssRefPtr<AudioBufferCallback> successCallback, PassRefPtr<AudioBufferCallback> e rrorCallback) 50 void AsyncAudioDecoder::decodeAsync(ArrayBuffer* audioData, float sampleRate, Pa ssOwnPtr<AudioBufferCallback> successCallback, PassOwnPtr<AudioBufferCallback> e rrorCallback)
51 { 51 {
52 ASSERT(isMainThread()); 52 ASSERT(isMainThread());
53 ASSERT(audioData); 53 ASSERT(audioData);
54 if (!audioData) 54 if (!audioData)
55 return; 55 return;
56 56
57 // Add a ref to keep audioData alive until completion of decoding. 57 // Add a ref to keep audioData alive until completion of decoding.
58 RefPtr<ArrayBuffer> audioDataRef(audioData); 58 RefPtr<ArrayBuffer> audioDataRef(audioData);
59 59
60 // The leak references to successCallback and errorCallback are picked up on notifyComplete. 60 // The leak references to successCallback and errorCallback are picked up on notifyComplete.
61 m_thread->postTask(new Task(WTF::bind(&AsyncAudioDecoder::decode, audioDataR ef.release().leakRef(), sampleRate, successCallback.leakRef(), errorCallback.lea kRef()))); 61 m_thread->postTask(new Task(WTF::bind(&AsyncAudioDecoder::decode, audioDataR ef.release().leakRef(), sampleRate, successCallback.leakPtr(), errorCallback.lea kPtr())));
62 } 62 }
63 63
64 void AsyncAudioDecoder::decode(ArrayBuffer* audioData, float sampleRate, AudioBu fferCallback* successCallback, AudioBufferCallback* errorCallback) 64 void AsyncAudioDecoder::decode(ArrayBuffer* audioData, float sampleRate, AudioBu fferCallback* successCallback, AudioBufferCallback* errorCallback)
65 { 65 {
66 // Do the actual decoding and invoke the callback. 66 // Do the actual decoding and invoke the callback.
67 RefPtr<AudioBuffer> audioBuffer = AudioBuffer::createFromAudioFileData(audio Data->data(), audioData->byteLength(), false, sampleRate); 67 RefPtr<AudioBuffer> audioBuffer = AudioBuffer::createFromAudioFileData(audio Data->data(), audioData->byteLength(), false, sampleRate);
68 68
69 // Decoding is finished, but we need to do the callbacks on the main thread. 69 // Decoding is finished, but we need to do the callbacks on the main thread.
70 // The leaked reference to audioBuffer is picked up in notifyComplete. 70 // The leaked reference to audioBuffer is picked up in notifyComplete.
71 callOnMainThread(WTF::bind(&AsyncAudioDecoder::notifyComplete, audioData, su ccessCallback, errorCallback, audioBuffer.release().leakRef())); 71 callOnMainThread(WTF::bind(&AsyncAudioDecoder::notifyComplete, audioData, su ccessCallback, errorCallback, audioBuffer.release().leakRef()));
72 } 72 }
73 73
74 void AsyncAudioDecoder::notifyComplete(ArrayBuffer* audioData, AudioBufferCallba ck* successCallback, AudioBufferCallback* errorCallback, AudioBuffer* audioBuffe r) 74 void AsyncAudioDecoder::notifyComplete(ArrayBuffer* audioData, AudioBufferCallba ck* successCallback, AudioBufferCallback* errorCallback, AudioBuffer* audioBuffe r)
75 { 75 {
76 // Adopt references, so everything gets correctly dereffed. 76 // Adopt references, so everything gets correctly dereffed.
77 RefPtr<ArrayBuffer> audioDataRef = adoptRef(audioData); 77 RefPtr<ArrayBuffer> audioDataRef = adoptRef(audioData);
78 RefPtr<AudioBufferCallback> successCallbackRef = adoptRef(successCallback); 78 OwnPtr<AudioBufferCallback> successCallbackPtr = adoptPtr(successCallback);
79 RefPtr<AudioBufferCallback> errorCallbackRef = adoptRef(errorCallback); 79 OwnPtr<AudioBufferCallback> errorCallbackPtr = adoptPtr(errorCallback);
80 RefPtr<AudioBuffer> audioBufferRef = adoptRef(audioBuffer); 80 RefPtr<AudioBuffer> audioBufferRef = adoptRef(audioBuffer);
81 81
82 if (audioBuffer && successCallback) 82 if (audioBuffer && successCallback)
83 successCallback->handleEvent(audioBuffer); 83 successCallback->handleEvent(audioBuffer);
84 else if (errorCallback) 84 else if (errorCallback)
85 errorCallback->handleEvent(audioBuffer); 85 errorCallback->handleEvent(audioBuffer);
86 } 86 }
87 87
88 } // namespace WebCore 88 } // namespace WebCore
89 89
90 #endif // ENABLE(WEB_AUDIO) 90 #endif // ENABLE(WEB_AUDIO)
OLDNEW
« no previous file with comments | « Source/modules/webaudio/AsyncAudioDecoder.h ('k') | Source/modules/webaudio/AudioBufferCallback.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698