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 <stdint.h> | 7 #include <stdint.h> |
8 #include <utility> | 8 #include <utility> |
9 | 9 |
10 #include "base/bind.h" | 10 #include "base/bind.h" |
(...skipping 23 matching lines...) Expand all Loading... |
34 AudioThreadCallback(const AudioParameters& audio_parameters, | 34 AudioThreadCallback(const AudioParameters& audio_parameters, |
35 base::SharedMemoryHandle memory, | 35 base::SharedMemoryHandle memory, |
36 int memory_length, | 36 int memory_length, |
37 int total_segments, | 37 int total_segments, |
38 CaptureCallback* capture_callback); | 38 CaptureCallback* capture_callback); |
39 ~AudioThreadCallback() override; | 39 ~AudioThreadCallback() override; |
40 | 40 |
41 void MapSharedMemory() override; | 41 void MapSharedMemory() override; |
42 | 42 |
43 // Called whenever we receive notifications about pending data. | 43 // Called whenever we receive notifications about pending data. |
44 void Process(uint32_t pending_data) override; | 44 void Process(uint32_t pending_data, const AudioTimestamp& timestamp) override; |
45 | 45 |
46 private: | 46 private: |
47 const double bytes_per_ms_; | 47 const double bytes_per_ms_; |
48 int current_segment_id_; | 48 int current_segment_id_; |
49 uint32_t last_buffer_id_; | 49 uint32_t last_buffer_id_; |
50 ScopedVector<media::AudioBus> audio_buses_; | 50 ScopedVector<media::AudioBus> audio_buses_; |
51 CaptureCallback* capture_callback_; | 51 CaptureCallback* capture_callback_; |
52 | 52 |
53 DISALLOW_COPY_AND_ASSIGN(AudioThreadCallback); | 53 DISALLOW_COPY_AND_ASSIGN(AudioThreadCallback); |
54 }; | 54 }; |
(...skipping 245 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
300 for (int i = 0; i < total_segments_; ++i) { | 300 for (int i = 0; i < total_segments_; ++i) { |
301 media::AudioInputBuffer* buffer = | 301 media::AudioInputBuffer* buffer = |
302 reinterpret_cast<media::AudioInputBuffer*>(ptr); | 302 reinterpret_cast<media::AudioInputBuffer*>(ptr); |
303 std::unique_ptr<media::AudioBus> audio_bus = | 303 std::unique_ptr<media::AudioBus> audio_bus = |
304 media::AudioBus::WrapMemory(audio_parameters_, buffer->audio); | 304 media::AudioBus::WrapMemory(audio_parameters_, buffer->audio); |
305 audio_buses_.push_back(std::move(audio_bus)); | 305 audio_buses_.push_back(std::move(audio_bus)); |
306 ptr += segment_length_; | 306 ptr += segment_length_; |
307 } | 307 } |
308 } | 308 } |
309 | 309 |
310 void AudioInputDevice::AudioThreadCallback::Process(uint32_t pending_data) { | 310 void AudioInputDevice::AudioThreadCallback::Process( |
| 311 uint32_t pending_data, |
| 312 const AudioTimestamp& timestamp) { |
311 // The shared memory represents parameters, size of the data buffer and the | 313 // The shared memory represents parameters, size of the data buffer and the |
312 // actual data buffer containing audio data. Map the memory into this | 314 // actual data buffer containing audio data. Map the memory into this |
313 // structure and parse out parameters and the data area. | 315 // structure and parse out parameters and the data area. |
314 uint8_t* ptr = static_cast<uint8_t*>(shared_memory_.memory()); | 316 uint8_t* ptr = static_cast<uint8_t*>(shared_memory_.memory()); |
315 ptr += current_segment_id_ * segment_length_; | 317 ptr += current_segment_id_ * segment_length_; |
316 AudioInputBuffer* buffer = reinterpret_cast<AudioInputBuffer*>(ptr); | 318 AudioInputBuffer* buffer = reinterpret_cast<AudioInputBuffer*>(ptr); |
317 | 319 |
318 // Usually this will be equal but in the case of low sample rate (e.g. 8kHz, | 320 // Usually this will be equal but in the case of low sample rate (e.g. 8kHz, |
319 // the buffer may be bigger (on mac at least)). | 321 // the buffer may be bigger (on mac at least)). |
320 DCHECK_GE(buffer->params.size, | 322 DCHECK_GE(buffer->params.size, |
(...skipping 24 matching lines...) Expand all Loading... |
345 capture_callback_->Capture( | 347 capture_callback_->Capture( |
346 audio_bus, | 348 audio_bus, |
347 buffer->params.hardware_delay_bytes / bytes_per_ms_, // Delay in ms | 349 buffer->params.hardware_delay_bytes / bytes_per_ms_, // Delay in ms |
348 buffer->params.volume, buffer->params.key_pressed); | 350 buffer->params.volume, buffer->params.key_pressed); |
349 | 351 |
350 if (++current_segment_id_ >= total_segments_) | 352 if (++current_segment_id_ >= total_segments_) |
351 current_segment_id_ = 0; | 353 current_segment_id_ = 0; |
352 } | 354 } |
353 | 355 |
354 } // namespace media | 356 } // namespace media |
OLD | NEW |