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

Side by Side Diff: content/renderer/media/audio_input_device.cc

Issue 9655018: Make AudioParameters a class instead of a struct (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Fix tests Created 8 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 "content/renderer/media/audio_input_device.h" 5 #include "content/renderer/media/audio_input_device.h"
6 6
7 #include "base/bind.h" 7 #include "base/bind.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 19 matching lines...) Expand all
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) OVERRIDE;
34 34
35 private: 35 private:
36 CaptureCallback* capture_callback_; 36 CaptureCallback* capture_callback_;
37 DISALLOW_COPY_AND_ASSIGN(AudioThreadCallback); 37 DISALLOW_COPY_AND_ASSIGN(AudioThreadCallback);
38 }; 38 };
39 39
40 AudioInputDevice::AudioInputDevice(size_t buffer_size, 40 AudioInputDevice::AudioInputDevice(const AudioParameters& params,
41 int channels,
42 double sample_rate,
43 CaptureCallback* callback, 41 CaptureCallback* callback,
44 CaptureEventHandler* event_handler) 42 CaptureEventHandler* event_handler)
45 : ScopedLoopObserver(ChildProcess::current()->io_message_loop()), 43 : ScopedLoopObserver(ChildProcess::current()->io_message_loop()),
44 audio_parameters_(params),
46 callback_(callback), 45 callback_(callback),
47 event_handler_(event_handler), 46 event_handler_(event_handler),
48 volume_(1.0), 47 volume_(1.0),
49 stream_id_(0), 48 stream_id_(0),
50 session_id_(0), 49 session_id_(0),
51 pending_device_ready_(false) { 50 pending_device_ready_(false) {
52 filter_ = RenderThreadImpl::current()->audio_input_message_filter(); 51 filter_ = RenderThreadImpl::current()->audio_input_message_filter();
53 #if defined(OS_MACOSX)
54 DVLOG(1) << "Using AUDIO_PCM_LOW_LATENCY as input mode on Mac OS X.";
55 audio_parameters_.format = AudioParameters::AUDIO_PCM_LOW_LATENCY;
56 #elif defined(OS_WIN)
57 DVLOG(1) << "Using AUDIO_PCM_LOW_LATENCY as input mode on Windows.";
58 audio_parameters_.format = AudioParameters::AUDIO_PCM_LOW_LATENCY;
59 #else
60 // TODO(henrika): add support for AUDIO_PCM_LOW_LATENCY on Linux as well.
61 audio_parameters_.format = AudioParameters::AUDIO_PCM_LINEAR;
62 #endif
63 audio_parameters_.channels = channels;
64 audio_parameters_.sample_rate = static_cast<int>(sample_rate);
65 audio_parameters_.bits_per_sample = 16;
66 audio_parameters_.samples_per_packet = buffer_size;
67 } 52 }
68 53
69 AudioInputDevice::~AudioInputDevice() { 54 AudioInputDevice::~AudioInputDevice() {
70 // TODO(henrika): The current design requires that the user calls 55 // TODO(henrika): The current design requires that the user calls
71 // Stop before deleting this class. 56 // Stop before deleting this class.
72 CHECK_EQ(0, stream_id_); 57 CHECK_EQ(0, stream_id_);
73 } 58 }
74 59
75 void AudioInputDevice::Start() { 60 void AudioInputDevice::Start() {
76 DVLOG(1) << "Start()"; 61 DVLOG(1) << "Start()";
(...skipping 208 matching lines...) Expand 10 before | Expand all | Expand 10 after
285 AudioInputDevice::AudioThreadCallback::~AudioThreadCallback() { 270 AudioInputDevice::AudioThreadCallback::~AudioThreadCallback() {
286 } 271 }
287 272
288 void AudioInputDevice::AudioThreadCallback::MapSharedMemory() { 273 void AudioInputDevice::AudioThreadCallback::MapSharedMemory() {
289 shared_memory_.Map(memory_length_); 274 shared_memory_.Map(memory_length_);
290 } 275 }
291 276
292 void AudioInputDevice::AudioThreadCallback::Process(int pending_data) { 277 void AudioInputDevice::AudioThreadCallback::Process(int pending_data) {
293 int audio_delay_milliseconds = pending_data / bytes_per_ms_; 278 int audio_delay_milliseconds = pending_data / bytes_per_ms_;
294 int16* memory = reinterpret_cast<int16*>(shared_memory_.memory()); 279 int16* memory = reinterpret_cast<int16*>(shared_memory_.memory());
295 const size_t number_of_frames = audio_parameters_.samples_per_packet; 280 const size_t number_of_frames = audio_parameters_.samples_per_packet();
296 const int bytes_per_sample = sizeof(memory[0]); 281 const int bytes_per_sample = sizeof(memory[0]);
297 282
298 // Deinterleave each channel and convert to 32-bit floating-point 283 // Deinterleave each channel and convert to 32-bit floating-point
299 // with nominal range -1.0 -> +1.0. 284 // with nominal range -1.0 -> +1.0.
300 for (int channel_index = 0; channel_index < audio_parameters_.channels; 285 for (int channel_index = 0; channel_index < audio_parameters_.channels();
301 ++channel_index) { 286 ++channel_index) {
302 media::DeinterleaveAudioChannel(memory, 287 media::DeinterleaveAudioChannel(memory,
303 audio_data_[channel_index], 288 audio_data_[channel_index],
304 audio_parameters_.channels, 289 audio_parameters_.channels(),
305 channel_index, 290 channel_index,
306 bytes_per_sample, 291 bytes_per_sample,
307 number_of_frames); 292 number_of_frames);
308 } 293 }
309 294
310 // Deliver captured data to the client in floating point format 295 // Deliver captured data to the client in floating point format
311 // and update the audio-delay measurement. 296 // and update the audio-delay measurement.
312 capture_callback_->Capture(audio_data_, number_of_frames, 297 capture_callback_->Capture(audio_data_, number_of_frames,
313 audio_delay_milliseconds); 298 audio_delay_milliseconds);
314 } 299 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698