OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "content/renderer/media/audio_device_thread.h" | 5 #include "media/audio/audio_device_thread.h" |
6 | 6 |
7 #include "base/bind.h" | 7 #include "base/bind.h" |
8 #include "base/logging.h" | 8 #include "base/logging.h" |
9 #include "base/message_loop.h" | 9 #include "base/message_loop.h" |
10 #include "base/threading/platform_thread.h" | 10 #include "base/threading/platform_thread.h" |
11 #include "base/threading/thread_restrictions.h" | 11 #include "base/threading/thread_restrictions.h" |
12 #include "media/audio/audio_util.h" | 12 #include "media/audio/audio_util.h" |
13 | 13 |
14 using base::PlatformThread; | 14 using base::PlatformThread; |
15 | 15 |
| 16 namespace media { |
| 17 |
16 // The actual worker thread implementation. It's very bare bones and much | 18 // The actual worker thread implementation. It's very bare bones and much |
17 // simpler than SimpleThread (no synchronization in Start, etc) and supports | 19 // simpler than SimpleThread (no synchronization in Start, etc) and supports |
18 // joining the thread handle asynchronously via a provided message loop even | 20 // joining the thread handle asynchronously via a provided message loop even |
19 // after the Thread object itself has been deleted. | 21 // after the Thread object itself has been deleted. |
20 class AudioDeviceThread::Thread | 22 class AudioDeviceThread::Thread |
21 : public PlatformThread::Delegate, | 23 : public PlatformThread::Delegate, |
22 public base::RefCountedThreadSafe<AudioDeviceThread::Thread> { | 24 public base::RefCountedThreadSafe<AudioDeviceThread::Thread> { |
23 public: | 25 public: |
24 Thread(AudioDeviceThread::Callback* callback, | 26 Thread(AudioDeviceThread::Callback* callback, |
25 base::SyncSocket::Handle socket, | 27 base::SyncSocket::Handle socket, |
(...skipping 137 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
163 | 165 |
164 base::AutoLock auto_lock(callback_lock_); | 166 base::AutoLock auto_lock(callback_lock_); |
165 if (callback_) | 167 if (callback_) |
166 callback_->Process(pending_data); | 168 callback_->Process(pending_data); |
167 } | 169 } |
168 } | 170 } |
169 | 171 |
170 // AudioDeviceThread::Callback implementation | 172 // AudioDeviceThread::Callback implementation |
171 | 173 |
172 AudioDeviceThread::Callback::Callback( | 174 AudioDeviceThread::Callback::Callback( |
173 const media::AudioParameters& audio_parameters, | 175 const AudioParameters& audio_parameters, |
174 base::SharedMemoryHandle memory, int memory_length) | 176 base::SharedMemoryHandle memory, int memory_length) |
175 : audio_parameters_(audio_parameters), | 177 : audio_parameters_(audio_parameters), |
176 samples_per_ms_(audio_parameters.sample_rate() / 1000), | 178 samples_per_ms_(audio_parameters.sample_rate() / 1000), |
177 bytes_per_ms_(audio_parameters.channels() * | 179 bytes_per_ms_(audio_parameters.channels() * |
178 (audio_parameters_.bits_per_sample() / 8) * | 180 (audio_parameters_.bits_per_sample() / 8) * |
179 samples_per_ms_), | 181 samples_per_ms_), |
180 shared_memory_(memory, false), | 182 shared_memory_(memory, false), |
181 memory_length_(memory_length) { | 183 memory_length_(memory_length) { |
182 CHECK_NE(bytes_per_ms_, 0); // Catch division by zero early. | 184 CHECK_NE(bytes_per_ms_, 0); // Catch division by zero early. |
183 CHECK_NE(samples_per_ms_, 0); | 185 CHECK_NE(samples_per_ms_, 0); |
184 } | 186 } |
185 | 187 |
186 AudioDeviceThread::Callback::~Callback() { | 188 AudioDeviceThread::Callback::~Callback() { |
187 for (size_t i = 0; i < audio_data_.size(); ++i) | 189 for (size_t i = 0; i < audio_data_.size(); ++i) |
188 delete [] audio_data_[i]; | 190 delete [] audio_data_[i]; |
189 } | 191 } |
190 | 192 |
191 void AudioDeviceThread::Callback::InitializeOnAudioThread() { | 193 void AudioDeviceThread::Callback::InitializeOnAudioThread() { |
192 DCHECK(audio_data_.empty()); | 194 DCHECK(audio_data_.empty()); |
193 | 195 |
194 MapSharedMemory(); | 196 MapSharedMemory(); |
195 DCHECK(shared_memory_.memory() != NULL); | 197 DCHECK(shared_memory_.memory() != NULL); |
196 | 198 |
197 audio_data_.reserve(audio_parameters_.channels()); | 199 audio_data_.reserve(audio_parameters_.channels()); |
198 for (int i = 0; i < audio_parameters_.channels(); ++i) { | 200 for (int i = 0; i < audio_parameters_.channels(); ++i) { |
199 float* channel_data = new float[audio_parameters_.frames_per_buffer()]; | 201 float* channel_data = new float[audio_parameters_.frames_per_buffer()]; |
200 audio_data_.push_back(channel_data); | 202 audio_data_.push_back(channel_data); |
201 } | 203 } |
202 } | 204 } |
| 205 |
| 206 } // namespace media. |
OLD | NEW |