OLD | NEW |
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 Loading... |
40 AsyncAudioDecoder::AsyncAudioDecoder() | 40 AsyncAudioDecoder::AsyncAudioDecoder() |
41 { | 41 { |
42 // Start worker thread. | 42 // Start worker thread. |
43 MutexLocker lock(m_threadCreationMutex); | 43 MutexLocker lock(m_threadCreationMutex); |
44 m_threadID = createThread(AsyncAudioDecoder::threadEntry, this, "Audio Decod
er"); | 44 m_threadID = createThread(AsyncAudioDecoder::threadEntry, this, "Audio Decod
er"); |
45 } | 45 } |
46 | 46 |
47 AsyncAudioDecoder::~AsyncAudioDecoder() | 47 AsyncAudioDecoder::~AsyncAudioDecoder() |
48 { | 48 { |
49 m_queue.kill(); | 49 m_queue.kill(); |
50 | 50 |
51 // Stop thread. | 51 // Stop thread. |
52 waitForThreadCompletion(m_threadID); | 52 waitForThreadCompletion(m_threadID); |
53 m_threadID = 0; | 53 m_threadID = 0; |
54 } | 54 } |
55 | 55 |
56 void AsyncAudioDecoder::decodeAsync(ArrayBuffer* audioData, float sampleRate, Pa
ssRefPtr<AudioBufferCallback> successCallback, PassRefPtr<AudioBufferCallback> e
rrorCallback) | 56 void AsyncAudioDecoder::decodeAsync(ArrayBuffer* audioData, float sampleRate, Pa
ssRefPtr<AudioBufferCallback> successCallback, PassRefPtr<AudioBufferCallback> e
rrorCallback) |
57 { | 57 { |
58 ASSERT(isMainThread()); | 58 ASSERT(isMainThread()); |
59 ASSERT(audioData); | 59 ASSERT(audioData); |
60 if (!audioData) | 60 if (!audioData) |
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
103 } | 103 } |
104 | 104 |
105 void AsyncAudioDecoder::DecodingTask::decode() | 105 void AsyncAudioDecoder::DecodingTask::decode() |
106 { | 106 { |
107 ASSERT(m_audioData.get()); | 107 ASSERT(m_audioData.get()); |
108 if (!m_audioData.get()) | 108 if (!m_audioData.get()) |
109 return; | 109 return; |
110 | 110 |
111 // Do the actual decoding and invoke the callback. | 111 // Do the actual decoding and invoke the callback. |
112 m_audioBuffer = AudioBuffer::createFromAudioFileData(m_audioData->data(), m_
audioData->byteLength(), false, sampleRate()); | 112 m_audioBuffer = AudioBuffer::createFromAudioFileData(m_audioData->data(), m_
audioData->byteLength(), false, sampleRate()); |
113 | 113 |
114 // Decoding is finished, but we need to do the callbacks on the main thread. | 114 // Decoding is finished, but we need to do the callbacks on the main thread. |
115 callOnMainThread(notifyCompleteDispatch, this); | 115 callOnMainThread(notifyCompleteDispatch, this); |
116 } | 116 } |
117 | 117 |
118 void AsyncAudioDecoder::DecodingTask::notifyCompleteDispatch(void* userData) | 118 void AsyncAudioDecoder::DecodingTask::notifyCompleteDispatch(void* userData) |
119 { | 119 { |
120 AsyncAudioDecoder::DecodingTask* task = reinterpret_cast<AsyncAudioDecoder::
DecodingTask*>(userData); | 120 AsyncAudioDecoder::DecodingTask* task = reinterpret_cast<AsyncAudioDecoder::
DecodingTask*>(userData); |
121 ASSERT(task); | 121 ASSERT(task); |
122 if (!task) | 122 if (!task) |
123 return; | 123 return; |
124 | 124 |
125 task->notifyComplete(); | 125 task->notifyComplete(); |
126 } | 126 } |
127 | 127 |
128 void AsyncAudioDecoder::DecodingTask::notifyComplete() | 128 void AsyncAudioDecoder::DecodingTask::notifyComplete() |
129 { | 129 { |
130 if (audioBuffer() && successCallback()) | 130 if (audioBuffer() && successCallback()) |
131 successCallback()->handleEvent(audioBuffer()); | 131 successCallback()->handleEvent(audioBuffer()); |
132 else if (errorCallback()) | 132 else if (errorCallback()) |
133 errorCallback()->handleEvent(audioBuffer()); | 133 errorCallback()->handleEvent(audioBuffer()); |
134 | 134 |
135 // Our ownership was given up in AsyncAudioDecoder::runLoop() | 135 // Our ownership was given up in AsyncAudioDecoder::runLoop() |
136 // Make sure to clean up here. | 136 // Make sure to clean up here. |
137 delete this; | 137 delete this; |
138 } | 138 } |
139 | 139 |
140 } // namespace WebCore | 140 } // namespace WebCore |
141 | 141 |
142 #endif // ENABLE(WEB_AUDIO) | 142 #endif // ENABLE(WEB_AUDIO) |
OLD | NEW |