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/basictypes.h" | 7 #include "base/basictypes.h" |
8 #include "base/bind.h" | 8 #include "base/bind.h" |
9 #include "base/message_loop/message_loop.h" | 9 #include "base/message_loop/message_loop.h" |
10 #include "base/threading/thread_restrictions.h" | 10 #include "base/threading/thread_restrictions.h" |
(...skipping 273 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
284 shared_memory_.Map(memory_length_); | 284 shared_memory_.Map(memory_length_); |
285 } | 285 } |
286 | 286 |
287 void AudioInputDevice::AudioThreadCallback::Process(int pending_data) { | 287 void AudioInputDevice::AudioThreadCallback::Process(int pending_data) { |
288 // The shared memory represents parameters, size of the data buffer and the | 288 // The shared memory represents parameters, size of the data buffer and the |
289 // actual data buffer containing audio data. Map the memory into this | 289 // actual data buffer containing audio data. Map the memory into this |
290 // structure and parse out parameters and the data area. | 290 // structure and parse out parameters and the data area. |
291 uint8* ptr = static_cast<uint8*>(shared_memory_.memory()); | 291 uint8* ptr = static_cast<uint8*>(shared_memory_.memory()); |
292 ptr += current_segment_id_ * segment_length_; | 292 ptr += current_segment_id_ * segment_length_; |
293 AudioInputBuffer* buffer = reinterpret_cast<AudioInputBuffer*>(ptr); | 293 AudioInputBuffer* buffer = reinterpret_cast<AudioInputBuffer*>(ptr); |
294 DCHECK_EQ(buffer->params.size, | 294 // Usually this will be equal but in the case of low sample rate (e.g. 8kHz, |
| 295 // the buffer may be bigger (on mac at least)). |
| 296 DCHECK_GE(buffer->params.size, |
295 segment_length_ - sizeof(AudioInputBufferParameters)); | 297 segment_length_ - sizeof(AudioInputBufferParameters)); |
296 double volume = buffer->params.volume; | 298 double volume = buffer->params.volume; |
297 bool key_pressed = buffer->params.key_pressed; | 299 bool key_pressed = buffer->params.key_pressed; |
298 | 300 |
299 int audio_delay_milliseconds = pending_data / bytes_per_ms_; | 301 int audio_delay_milliseconds = pending_data / bytes_per_ms_; |
300 int16* memory = reinterpret_cast<int16*>(&buffer->audio[0]); | 302 int16* memory = reinterpret_cast<int16*>(&buffer->audio[0]); |
301 const int bytes_per_sample = sizeof(memory[0]); | 303 const int bytes_per_sample = sizeof(memory[0]); |
302 | 304 |
303 if (++current_segment_id_ >= total_segments_) | 305 if (++current_segment_id_ >= total_segments_) |
304 current_segment_id_ = 0; | 306 current_segment_id_ = 0; |
305 | 307 |
306 // Deinterleave each channel and convert to 32-bit floating-point | 308 // Deinterleave each channel and convert to 32-bit floating-point |
307 // with nominal range -1.0 -> +1.0. | 309 // with nominal range -1.0 -> +1.0. |
308 audio_bus_->FromInterleaved(memory, audio_bus_->frames(), bytes_per_sample); | 310 audio_bus_->FromInterleaved(memory, audio_bus_->frames(), bytes_per_sample); |
309 | 311 |
310 // Deliver captured data to the client in floating point format | 312 // Deliver captured data to the client in floating point format |
311 // and update the audio-delay measurement. | 313 // and update the audio-delay measurement. |
312 capture_callback_->Capture( | 314 capture_callback_->Capture( |
313 audio_bus_.get(), audio_delay_milliseconds, volume, key_pressed); | 315 audio_bus_.get(), audio_delay_milliseconds, volume, key_pressed); |
314 } | 316 } |
315 | 317 |
316 } // namespace media | 318 } // namespace media |
OLD | NEW |