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

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

Issue 12379071: Use multiple shared memory buffers cyclically for audio capture. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: aggregate buffers Created 7 years, 9 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
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 "media/audio/audio_output_device.h" 5 #include "media/audio/audio_output_device.h"
6 6
7 #include "base/debug/trace_event.h" 7 #include "base/debug/trace_event.h"
8 #include "base/message_loop.h" 8 #include "base/message_loop.h"
9 #include "base/threading/thread_restrictions.h" 9 #include "base/threading/thread_restrictions.h"
10 #include "base/time.h" 10 #include "base/time.h"
(...skipping 12 matching lines...) Expand all
23 public: 23 public:
24 AudioThreadCallback(const AudioParameters& audio_parameters, 24 AudioThreadCallback(const AudioParameters& audio_parameters,
25 base::SharedMemoryHandle memory, 25 base::SharedMemoryHandle memory,
26 int memory_length, 26 int memory_length,
27 AudioRendererSink::RenderCallback* render_callback); 27 AudioRendererSink::RenderCallback* render_callback);
28 virtual ~AudioThreadCallback(); 28 virtual ~AudioThreadCallback();
29 29
30 virtual void MapSharedMemory() OVERRIDE; 30 virtual void MapSharedMemory() OVERRIDE;
31 31
32 // Called whenever we receive notifications about pending data. 32 // Called whenever we receive notifications about pending data.
33 virtual void Process(int pending_data) OVERRIDE; 33 virtual void Process(int pending_data, int index) OVERRIDE;
34 34
35 private: 35 private:
36 AudioRendererSink::RenderCallback* render_callback_; 36 AudioRendererSink::RenderCallback* render_callback_;
37 scoped_ptr<AudioBus> input_bus_; 37 scoped_ptr<AudioBus> input_bus_;
38 scoped_ptr<AudioBus> output_bus_; 38 scoped_ptr<AudioBus> output_bus_;
39 DISALLOW_COPY_AND_ASSIGN(AudioThreadCallback); 39 DISALLOW_COPY_AND_ASSIGN(AudioThreadCallback);
40 }; 40 };
41 41
42 AudioOutputDevice::AudioOutputDevice( 42 AudioOutputDevice::AudioOutputDevice(
43 AudioOutputIPC* ipc, 43 AudioOutputIPC* ipc,
44 const scoped_refptr<base::MessageLoopProxy>& io_loop) 44 const scoped_refptr<base::MessageLoopProxy>& io_loop)
45 : ScopedLoopObserver(io_loop), 45 : ScopedLoopObserver(io_loop),
46 callback_(NULL), 46 callback_(NULL),
47 ipc_(ipc), 47 ipc_(ipc),
48 stream_id_(0), 48 stream_id_(0),
49 state_(IDLE), 49 state_(IDLE),
50 play_on_start_(true), 50 play_on_start_(true),
51 audio_thread_(false),
51 stopping_hack_(false) { 52 stopping_hack_(false) {
52 CHECK(ipc_); 53 CHECK(ipc_);
53 } 54 }
54 55
55 void AudioOutputDevice::Initialize(const AudioParameters& params, 56 void AudioOutputDevice::Initialize(const AudioParameters& params,
56 RenderCallback* callback) { 57 RenderCallback* callback) {
57 DCHECK(!callback_) << "Calling Initialize() twice?"; 58 DCHECK(!callback_) << "Calling Initialize() twice?";
58 DCHECK(params.IsValid()); 59 DCHECK(params.IsValid());
59 audio_parameters_ = params; 60 audio_parameters_ = params;
60 callback_ = callback; 61 callback_ = callback;
(...skipping 189 matching lines...) Expand 10 before | Expand all | Expand 10 after
250 251
251 // AudioOutputDevice::AudioThreadCallback 252 // AudioOutputDevice::AudioThreadCallback
252 253
253 AudioOutputDevice::AudioThreadCallback::AudioThreadCallback( 254 AudioOutputDevice::AudioThreadCallback::AudioThreadCallback(
254 const AudioParameters& audio_parameters, 255 const AudioParameters& audio_parameters,
255 base::SharedMemoryHandle memory, 256 base::SharedMemoryHandle memory,
256 int memory_length, 257 int memory_length,
257 AudioRendererSink::RenderCallback* render_callback) 258 AudioRendererSink::RenderCallback* render_callback)
258 : AudioDeviceThread::Callback(audio_parameters, 259 : AudioDeviceThread::Callback(audio_parameters,
259 memory, 260 memory,
260 memory_length), 261 memory_length,
262 1),
261 render_callback_(render_callback) { 263 render_callback_(render_callback) {
262 } 264 }
263 265
264 AudioOutputDevice::AudioThreadCallback::~AudioThreadCallback() { 266 AudioOutputDevice::AudioThreadCallback::~AudioThreadCallback() {
265 } 267 }
266 268
267 void AudioOutputDevice::AudioThreadCallback::MapSharedMemory() { 269 void AudioOutputDevice::AudioThreadCallback::MapSharedMemory() {
270 CHECK_EQ(total_segments_, 1);
268 CHECK(shared_memory_.Map(TotalSharedMemorySizeInBytes(memory_length_))); 271 CHECK(shared_memory_.Map(TotalSharedMemorySizeInBytes(memory_length_)));
269 272
270 // Calculate output and input memory size. 273 // Calculate output and input memory size.
271 int output_memory_size = AudioBus::CalculateMemorySize(audio_parameters_); 274 int output_memory_size = AudioBus::CalculateMemorySize(audio_parameters_);
272 int input_channels = audio_parameters_.input_channels(); 275 int input_channels = audio_parameters_.input_channels();
273 int frames = audio_parameters_.frames_per_buffer(); 276 int frames = audio_parameters_.frames_per_buffer();
274 int input_memory_size = 277 int input_memory_size =
275 AudioBus::CalculateMemorySize(input_channels, frames); 278 AudioBus::CalculateMemorySize(input_channels, frames);
276 279
277 int io_size = output_memory_size + input_memory_size; 280 int io_size = output_memory_size + input_memory_size;
278 281
279 DCHECK_EQ(memory_length_, io_size); 282 DCHECK_EQ(memory_length_, io_size);
280 283
281 output_bus_ = 284 output_bus_ =
282 AudioBus::WrapMemory(audio_parameters_, shared_memory_.memory()); 285 AudioBus::WrapMemory(audio_parameters_, shared_memory_.memory());
283 286
284 if (input_channels > 0) { 287 if (input_channels > 0) {
285 // The input data is after the output data. 288 // The input data is after the output data.
286 char* input_data = 289 char* input_data =
287 static_cast<char*>(shared_memory_.memory()) + output_memory_size; 290 static_cast<char*>(shared_memory_.memory()) + output_memory_size;
288 input_bus_ = 291 input_bus_ =
289 AudioBus::WrapMemory(input_channels, frames, input_data); 292 AudioBus::WrapMemory(input_channels, frames, input_data);
290 } 293 }
291 } 294 }
292 295
293 // Called whenever we receive notifications about pending data. 296 // Called whenever we receive notifications about pending data.
294 void AudioOutputDevice::AudioThreadCallback::Process(int pending_data) { 297 void AudioOutputDevice::AudioThreadCallback::Process(
298 int pending_data, int index) {
295 if (pending_data == kPauseMark) { 299 if (pending_data == kPauseMark) {
296 memset(shared_memory_.memory(), 0, memory_length_); 300 memset(shared_memory_.memory(), 0, memory_length_);
297 SetActualDataSizeInBytes(&shared_memory_, memory_length_, 0); 301 SetActualDataSizeInBytes(&shared_memory_, memory_length_, 0);
298 return; 302 return;
299 } 303 }
300 304
301 // Convert the number of pending bytes in the render buffer 305 // Convert the number of pending bytes in the render buffer
302 // into milliseconds. 306 // into milliseconds.
303 int audio_delay_milliseconds = pending_data / bytes_per_ms_; 307 int audio_delay_milliseconds = pending_data / bytes_per_ms_;
304 308
(...skipping 18 matching lines...) Expand all
323 // TODO(dalecurtis): Technically this is not always correct. Due to channel 327 // TODO(dalecurtis): Technically this is not always correct. Due to channel
324 // padding for alignment, there may be more data available than this. We're 328 // padding for alignment, there may be more data available than this. We're
325 // relying on AudioSyncReader::Read() to parse this with that in mind. Rename 329 // relying on AudioSyncReader::Read() to parse this with that in mind. Rename
326 // these methods to Set/GetActualFrameCount(). 330 // these methods to Set/GetActualFrameCount().
327 SetActualDataSizeInBytes( 331 SetActualDataSizeInBytes(
328 &shared_memory_, memory_length_, 332 &shared_memory_, memory_length_,
329 num_frames * sizeof(*output_bus_->channel(0)) * output_bus_->channels()); 333 num_frames * sizeof(*output_bus_->channel(0)) * output_bus_->channels());
330 } 334 }
331 335
332 } // namespace media. 336 } // namespace media.
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698