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 "media/audio/audio_input_device.h" | 5 #include "media/audio/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" |
11 #include "media/audio/audio_manager_base.h" | 11 #include "media/audio/audio_manager_base.h" |
12 #include "media/audio/audio_util.h" | 12 #include "media/audio/audio_util.h" |
| 13 #include "media/base/audio_bus.h" |
13 | 14 |
14 namespace media { | 15 namespace media { |
15 | 16 |
16 AudioInputDevice::CaptureCallback::~CaptureCallback() {} | 17 AudioInputDevice::CaptureCallback::~CaptureCallback() {} |
17 AudioInputDevice::CaptureEventHandler::~CaptureEventHandler() {} | 18 AudioInputDevice::CaptureEventHandler::~CaptureEventHandler() {} |
18 | 19 |
19 // Takes care of invoking the capture callback on the audio thread. | 20 // Takes care of invoking the capture callback on the audio thread. |
20 // An instance of this class is created for each capture stream in | 21 // An instance of this class is created for each capture stream in |
21 // OnLowLatencyCreated(). | 22 // OnLowLatencyCreated(). |
22 class AudioInputDevice::AudioThreadCallback | 23 class AudioInputDevice::AudioThreadCallback |
(...skipping 298 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
321 // actual data buffer containing audio data. Map the memory into this | 322 // actual data buffer containing audio data. Map the memory into this |
322 // structure and parse out parameters and the data area. | 323 // structure and parse out parameters and the data area. |
323 AudioInputBuffer* buffer = | 324 AudioInputBuffer* buffer = |
324 reinterpret_cast<AudioInputBuffer*>(shared_memory_.memory()); | 325 reinterpret_cast<AudioInputBuffer*>(shared_memory_.memory()); |
325 DCHECK_EQ(buffer->params.size, | 326 DCHECK_EQ(buffer->params.size, |
326 memory_length_ - sizeof(AudioInputBufferParameters)); | 327 memory_length_ - sizeof(AudioInputBufferParameters)); |
327 double volume = buffer->params.volume; | 328 double volume = buffer->params.volume; |
328 | 329 |
329 int audio_delay_milliseconds = pending_data / bytes_per_ms_; | 330 int audio_delay_milliseconds = pending_data / bytes_per_ms_; |
330 int16* memory = reinterpret_cast<int16*>(&buffer->audio[0]); | 331 int16* memory = reinterpret_cast<int16*>(&buffer->audio[0]); |
331 const size_t number_of_frames = audio_parameters_.frames_per_buffer(); | |
332 const int bytes_per_sample = sizeof(memory[0]); | 332 const int bytes_per_sample = sizeof(memory[0]); |
333 | 333 |
334 // Deinterleave each channel and convert to 32-bit floating-point | 334 // Deinterleave each channel and convert to 32-bit floating-point |
335 // with nominal range -1.0 -> +1.0. | 335 // with nominal range -1.0 -> +1.0. |
336 for (int channel_index = 0; channel_index < audio_parameters_.channels(); | 336 for (int channel_index = 0; channel_index < audio_bus_->channels(); |
337 ++channel_index) { | 337 ++channel_index) { |
338 DeinterleaveAudioChannel(memory, | 338 DeinterleaveAudioChannel(memory, |
339 audio_data_[channel_index], | 339 audio_bus_->channel(channel_index), |
340 audio_parameters_.channels(), | 340 audio_bus_->channels(), |
341 channel_index, | 341 channel_index, |
342 bytes_per_sample, | 342 bytes_per_sample, |
343 number_of_frames); | 343 audio_bus_->frames()); |
344 } | 344 } |
345 | 345 |
346 // Deliver captured data to the client in floating point format | 346 // Deliver captured data to the client in floating point format |
347 // and update the audio-delay measurement. | 347 // and update the audio-delay measurement. |
348 capture_callback_->Capture(audio_data_, number_of_frames, | 348 capture_callback_->Capture(audio_bus_.get(), audio_bus_->frames(), |
349 audio_delay_milliseconds, volume); | 349 audio_delay_milliseconds, volume); |
350 } | 350 } |
351 | 351 |
352 } // namespace media | 352 } // namespace media |
OLD | NEW |