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

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 copyright years 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 219 matching lines...) Expand 10 before | Expand all | Expand 10 after
296 AudioInputDevice::AudioThreadCallback::~AudioThreadCallback() { 281 AudioInputDevice::AudioThreadCallback::~AudioThreadCallback() {
297 } 282 }
298 283
299 void AudioInputDevice::AudioThreadCallback::MapSharedMemory() { 284 void AudioInputDevice::AudioThreadCallback::MapSharedMemory() {
300 shared_memory_.Map(memory_length_); 285 shared_memory_.Map(memory_length_);
301 } 286 }
302 287
303 void AudioInputDevice::AudioThreadCallback::Process(int pending_data) { 288 void AudioInputDevice::AudioThreadCallback::Process(int pending_data) {
304 int audio_delay_milliseconds = pending_data / bytes_per_ms_; 289 int audio_delay_milliseconds = pending_data / bytes_per_ms_;
305 int16* memory = reinterpret_cast<int16*>(shared_memory_.memory()); 290 int16* memory = reinterpret_cast<int16*>(shared_memory_.memory());
306 const size_t number_of_frames = audio_parameters_.samples_per_packet; 291 const size_t number_of_frames = audio_parameters_.frames_per_buffer();
307 const int bytes_per_sample = sizeof(memory[0]); 292 const int bytes_per_sample = sizeof(memory[0]);
308 293
309 // Deinterleave each channel and convert to 32-bit floating-point 294 // Deinterleave each channel and convert to 32-bit floating-point
310 // with nominal range -1.0 -> +1.0. 295 // with nominal range -1.0 -> +1.0.
311 for (int channel_index = 0; channel_index < audio_parameters_.channels; 296 for (int channel_index = 0; channel_index < audio_parameters_.channels();
312 ++channel_index) { 297 ++channel_index) {
313 media::DeinterleaveAudioChannel(memory, 298 media::DeinterleaveAudioChannel(memory,
314 audio_data_[channel_index], 299 audio_data_[channel_index],
315 audio_parameters_.channels, 300 audio_parameters_.channels(),
316 channel_index, 301 channel_index,
317 bytes_per_sample, 302 bytes_per_sample,
318 number_of_frames); 303 number_of_frames);
319 } 304 }
320 305
321 // Deliver captured data to the client in floating point format 306 // Deliver captured data to the client in floating point format
322 // and update the audio-delay measurement. 307 // and update the audio-delay measurement.
323 capture_callback_->Capture(audio_data_, number_of_frames, 308 capture_callback_->Capture(audio_data_, number_of_frames,
324 audio_delay_milliseconds); 309 audio_delay_milliseconds);
325 } 310 }
OLDNEW
« no previous file with comments | « content/renderer/media/audio_input_device.h ('k') | content/renderer/media/audio_renderer_impl.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698