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

Side by Side Diff: media/audio/audio_device_thread.cc

Issue 10834033: Move AudioDevice and AudioInputDevice to media. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Addressed comments and fixed a few lint issues Created 8 years, 4 months 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
« no previous file with comments | « media/audio/audio_device_thread.h ('k') | media/audio/audio_input_device.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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
7 #include <algorithm>
6 8
7 #include "base/bind.h" 9 #include "base/bind.h"
8 #include "base/logging.h" 10 #include "base/logging.h"
9 #include "base/message_loop.h" 11 #include "base/message_loop.h"
10 #include "base/threading/platform_thread.h" 12 #include "base/threading/platform_thread.h"
11 #include "base/threading/thread_restrictions.h" 13 #include "base/threading/thread_restrictions.h"
12 #include "media/audio/audio_util.h" 14 #include "media/audio/audio_util.h"
13 15
14 using base::PlatformThread; 16 using base::PlatformThread;
15 17
18 namespace media {
19
16 // The actual worker thread implementation. It's very bare bones and much 20 // The actual worker thread implementation. It's very bare bones and much
17 // simpler than SimpleThread (no synchronization in Start, etc) and supports 21 // simpler than SimpleThread (no synchronization in Start, etc) and supports
18 // joining the thread handle asynchronously via a provided message loop even 22 // joining the thread handle asynchronously via a provided message loop even
19 // after the Thread object itself has been deleted. 23 // after the Thread object itself has been deleted.
20 class AudioDeviceThread::Thread 24 class AudioDeviceThread::Thread
21 : public PlatformThread::Delegate, 25 : public PlatformThread::Delegate,
22 public base::RefCountedThreadSafe<AudioDeviceThread::Thread> { 26 public base::RefCountedThreadSafe<AudioDeviceThread::Thread> {
23 public: 27 public:
24 Thread(AudioDeviceThread::Callback* callback, 28 Thread(AudioDeviceThread::Callback* callback,
25 base::SyncSocket::Handle socket, 29 base::SyncSocket::Handle socket,
(...skipping 137 matching lines...) Expand 10 before | Expand all | Expand 10 after
163 167
164 base::AutoLock auto_lock(callback_lock_); 168 base::AutoLock auto_lock(callback_lock_);
165 if (callback_) 169 if (callback_)
166 callback_->Process(pending_data); 170 callback_->Process(pending_data);
167 } 171 }
168 } 172 }
169 173
170 // AudioDeviceThread::Callback implementation 174 // AudioDeviceThread::Callback implementation
171 175
172 AudioDeviceThread::Callback::Callback( 176 AudioDeviceThread::Callback::Callback(
173 const media::AudioParameters& audio_parameters, 177 const AudioParameters& audio_parameters,
174 base::SharedMemoryHandle memory, int memory_length) 178 base::SharedMemoryHandle memory, int memory_length)
175 : audio_parameters_(audio_parameters), 179 : audio_parameters_(audio_parameters),
176 samples_per_ms_(audio_parameters.sample_rate() / 1000), 180 samples_per_ms_(audio_parameters.sample_rate() / 1000),
177 bytes_per_ms_(audio_parameters.channels() * 181 bytes_per_ms_(audio_parameters.channels() *
178 (audio_parameters_.bits_per_sample() / 8) * 182 (audio_parameters_.bits_per_sample() / 8) *
179 samples_per_ms_), 183 samples_per_ms_),
180 shared_memory_(memory, false), 184 shared_memory_(memory, false),
181 memory_length_(memory_length) { 185 memory_length_(memory_length) {
182 CHECK_NE(bytes_per_ms_, 0); // Catch division by zero early. 186 CHECK_NE(bytes_per_ms_, 0); // Catch division by zero early.
183 CHECK_NE(samples_per_ms_, 0); 187 CHECK_NE(samples_per_ms_, 0);
184 } 188 }
185 189
186 AudioDeviceThread::Callback::~Callback() { 190 AudioDeviceThread::Callback::~Callback() {
187 for (size_t i = 0; i < audio_data_.size(); ++i) 191 for (size_t i = 0; i < audio_data_.size(); ++i)
188 delete [] audio_data_[i]; 192 delete [] audio_data_[i];
189 } 193 }
190 194
191 void AudioDeviceThread::Callback::InitializeOnAudioThread() { 195 void AudioDeviceThread::Callback::InitializeOnAudioThread() {
192 DCHECK(audio_data_.empty()); 196 DCHECK(audio_data_.empty());
193 197
194 MapSharedMemory(); 198 MapSharedMemory();
195 DCHECK(shared_memory_.memory() != NULL); 199 DCHECK(shared_memory_.memory() != NULL);
196 200
197 audio_data_.reserve(audio_parameters_.channels()); 201 audio_data_.reserve(audio_parameters_.channels());
198 for (int i = 0; i < audio_parameters_.channels(); ++i) { 202 for (int i = 0; i < audio_parameters_.channels(); ++i) {
199 float* channel_data = new float[audio_parameters_.frames_per_buffer()]; 203 float* channel_data = new float[audio_parameters_.frames_per_buffer()];
200 audio_data_.push_back(channel_data); 204 audio_data_.push_back(channel_data);
201 } 205 }
202 } 206 }
207
208 } // namespace media.
OLDNEW
« no previous file with comments | « media/audio/audio_device_thread.h ('k') | media/audio/audio_input_device.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698