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 276 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
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 DCHECK_EQ(buffer->params.size, |
295 segment_length_ - sizeof(AudioInputBufferParameters)); | 295 segment_length_ - sizeof(AudioInputBufferParameters)); |
296 double volume = buffer->params.volume; | 296 double volume = buffer->params.volume; |
| 297 bool key_pressed = buffer->params.key_pressed; |
297 | 298 |
298 int audio_delay_milliseconds = pending_data / bytes_per_ms_; | 299 int audio_delay_milliseconds = pending_data / bytes_per_ms_; |
299 int16* memory = reinterpret_cast<int16*>(&buffer->audio[0]); | 300 int16* memory = reinterpret_cast<int16*>(&buffer->audio[0]); |
300 const int bytes_per_sample = sizeof(memory[0]); | 301 const int bytes_per_sample = sizeof(memory[0]); |
301 | 302 |
302 if (++current_segment_id_ >= total_segments_) | 303 if (++current_segment_id_ >= total_segments_) |
303 current_segment_id_ = 0; | 304 current_segment_id_ = 0; |
304 | 305 |
305 // Deinterleave each channel and convert to 32-bit floating-point | 306 // Deinterleave each channel and convert to 32-bit floating-point |
306 // with nominal range -1.0 -> +1.0. | 307 // with nominal range -1.0 -> +1.0. |
307 audio_bus_->FromInterleaved(memory, audio_bus_->frames(), bytes_per_sample); | 308 audio_bus_->FromInterleaved(memory, audio_bus_->frames(), bytes_per_sample); |
308 | 309 |
309 // Deliver captured data to the client in floating point format | 310 // Deliver captured data to the client in floating point format |
310 // and update the audio-delay measurement. | 311 // and update the audio-delay measurement. |
311 capture_callback_->Capture(audio_bus_.get(), | 312 capture_callback_->Capture( |
312 audio_delay_milliseconds, volume); | 313 audio_bus_.get(), audio_delay_milliseconds, volume, key_pressed); |
313 } | 314 } |
314 | 315 |
315 } // namespace media | 316 } // namespace media |
OLD | NEW |