| 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/memory/scoped_vector.h" | 9 #include "base/memory/scoped_vector.h" |
| 10 #include "base/threading/thread_restrictions.h" | 10 #include "base/threading/thread_restrictions.h" |
| (...skipping 291 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 302 uint8* ptr = static_cast<uint8*>(shared_memory_.memory()); | 302 uint8* ptr = static_cast<uint8*>(shared_memory_.memory()); |
| 303 ptr += current_segment_id_ * segment_length_; | 303 ptr += current_segment_id_ * segment_length_; |
| 304 AudioInputBuffer* buffer = reinterpret_cast<AudioInputBuffer*>(ptr); | 304 AudioInputBuffer* buffer = reinterpret_cast<AudioInputBuffer*>(ptr); |
| 305 // Usually this will be equal but in the case of low sample rate (e.g. 8kHz, | 305 // Usually this will be equal but in the case of low sample rate (e.g. 8kHz, |
| 306 // the buffer may be bigger (on mac at least)). | 306 // the buffer may be bigger (on mac at least)). |
| 307 DCHECK_GE(buffer->params.size, | 307 DCHECK_GE(buffer->params.size, |
| 308 segment_length_ - sizeof(AudioInputBufferParameters)); | 308 segment_length_ - sizeof(AudioInputBufferParameters)); |
| 309 double volume = buffer->params.volume; | 309 double volume = buffer->params.volume; |
| 310 bool key_pressed = buffer->params.key_pressed; | 310 bool key_pressed = buffer->params.key_pressed; |
| 311 | 311 |
| 312 // Reset the size of the buffer to 0 to notify the browser that |
| 313 // the buffer has been consumed. |
| 314 buffer->params.size = 0; |
| 315 |
| 312 // Use pre-allocated audio bus wrapping existing block of shared memory. | 316 // Use pre-allocated audio bus wrapping existing block of shared memory. |
| 313 media::AudioBus* audio_bus = audio_buses_[current_segment_id_]; | 317 media::AudioBus* audio_bus = audio_buses_[current_segment_id_]; |
| 314 | 318 |
| 315 // Deliver captured data to the client in floating point format | 319 // Deliver captured data to the client in floating point format |
| 316 // and update the audio-delay measurement. | 320 // and update the audio-delay measurement. |
| 317 int audio_delay_milliseconds = pending_data / bytes_per_ms_; | 321 int audio_delay_milliseconds = pending_data / bytes_per_ms_; |
| 318 capture_callback_->Capture( | 322 capture_callback_->Capture( |
| 319 audio_bus, audio_delay_milliseconds, volume, key_pressed); | 323 audio_bus, audio_delay_milliseconds, volume, key_pressed); |
| 320 | 324 |
| 321 if (++current_segment_id_ >= total_segments_) | 325 if (++current_segment_id_ >= total_segments_) |
| 322 current_segment_id_ = 0; | 326 current_segment_id_ = 0; |
| 323 } | 327 } |
| 324 | 328 |
| 325 } // namespace media | 329 } // namespace media |
| OLD | NEW |