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 int current_segment_id_; | 47 int current_segment_id_; |
48 uint32_t last_buffer_id_; | 48 uint32_t last_buffer_id_; |
49 ScopedVector<media::AudioBus> audio_buses_; | 49 ScopedVector<media::AudioBus> audio_buses_; |
50 CaptureCallback* capture_callback_; | 50 CaptureCallback* capture_callback_; |
51 | 51 |
52 DISALLOW_COPY_AND_ASSIGN(AudioThreadCallback); | 52 DISALLOW_COPY_AND_ASSIGN(AudioThreadCallback); |
53 }; | 53 }; |
54 | 54 |
(...skipping 240 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
295 for (int i = 0; i < total_segments_; ++i) { | 295 for (int i = 0; i < total_segments_; ++i) { |
296 media::AudioInputBuffer* buffer = | 296 media::AudioInputBuffer* buffer = |
297 reinterpret_cast<media::AudioInputBuffer*>(ptr); | 297 reinterpret_cast<media::AudioInputBuffer*>(ptr); |
298 std::unique_ptr<media::AudioBus> audio_bus = | 298 std::unique_ptr<media::AudioBus> audio_bus = |
299 media::AudioBus::WrapMemory(audio_parameters_, buffer->audio); | 299 media::AudioBus::WrapMemory(audio_parameters_, buffer->audio); |
300 audio_buses_.push_back(std::move(audio_bus)); | 300 audio_buses_.push_back(std::move(audio_bus)); |
301 ptr += segment_length_; | 301 ptr += segment_length_; |
302 } | 302 } |
303 } | 303 } |
304 | 304 |
305 void AudioInputDevice::AudioThreadCallback::Process(uint32_t pending_data) { | 305 void AudioInputDevice::AudioThreadCallback::Process( |
| 306 uint32_t pending_data, |
| 307 const AudioTimestamp& timestamp) { |
306 // The shared memory represents parameters, size of the data buffer and the | 308 // The shared memory represents parameters, size of the data buffer and the |
307 // actual data buffer containing audio data. Map the memory into this | 309 // actual data buffer containing audio data. Map the memory into this |
308 // structure and parse out parameters and the data area. | 310 // structure and parse out parameters and the data area. |
309 uint8_t* ptr = static_cast<uint8_t*>(shared_memory_.memory()); | 311 uint8_t* ptr = static_cast<uint8_t*>(shared_memory_.memory()); |
310 ptr += current_segment_id_ * segment_length_; | 312 ptr += current_segment_id_ * segment_length_; |
311 AudioInputBuffer* buffer = reinterpret_cast<AudioInputBuffer*>(ptr); | 313 AudioInputBuffer* buffer = reinterpret_cast<AudioInputBuffer*>(ptr); |
312 | 314 |
313 // Usually this will be equal but in the case of low sample rate (e.g. 8kHz, | 315 // Usually this will be equal but in the case of low sample rate (e.g. 8kHz, |
314 // the buffer may be bigger (on mac at least)). | 316 // the buffer may be bigger (on mac at least)). |
315 DCHECK_GE(buffer->params.size, | 317 DCHECK_GE(buffer->params.size, |
(...skipping 24 matching lines...) Expand all Loading... |
340 capture_callback_->Capture( | 342 capture_callback_->Capture( |
341 audio_bus, | 343 audio_bus, |
342 buffer->params.hardware_delay_bytes / bytes_per_ms_, // Delay in ms | 344 buffer->params.hardware_delay_bytes / bytes_per_ms_, // Delay in ms |
343 buffer->params.volume, buffer->params.key_pressed); | 345 buffer->params.volume, buffer->params.key_pressed); |
344 | 346 |
345 if (++current_segment_id_ >= total_segments_) | 347 if (++current_segment_id_ >= total_segments_) |
346 current_segment_id_ = 0; | 348 current_segment_id_ = 0; |
347 } | 349 } |
348 | 350 |
349 } // namespace media | 351 } // namespace media |
OLD | NEW |