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/win/audio_low_latency_input_win.h" | 5 #include "media/audio/win/audio_low_latency_input_win.h" |
6 | 6 |
7 #include "base/logging.h" | 7 #include "base/logging.h" |
8 #include "base/memory/scoped_ptr.h" | 8 #include "base/memory/scoped_ptr.h" |
9 #include "base/strings/utf_string_conversions.h" | 9 #include "base/strings/utf_string_conversions.h" |
10 #include "base/trace_event/trace_event.h" | 10 #include "base/trace_event/trace_event.h" |
(...skipping 273 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
284 | 284 |
285 // Allocate a buffer with a size that enables us to take care of cases like: | 285 // Allocate a buffer with a size that enables us to take care of cases like: |
286 // 1) The recorded buffer size is smaller, or does not match exactly with, | 286 // 1) The recorded buffer size is smaller, or does not match exactly with, |
287 // the selected packet size used in each callback. | 287 // the selected packet size used in each callback. |
288 // 2) The selected buffer size is larger than the recorded buffer size in | 288 // 2) The selected buffer size is larger than the recorded buffer size in |
289 // each event. | 289 // each event. |
290 size_t buffer_frame_index = 0; | 290 size_t buffer_frame_index = 0; |
291 size_t capture_buffer_size = std::max( | 291 size_t capture_buffer_size = std::max( |
292 2 * endpoint_buffer_size_frames_ * frame_size_, | 292 2 * endpoint_buffer_size_frames_ * frame_size_, |
293 2 * packet_size_frames_ * frame_size_); | 293 2 * packet_size_frames_ * frame_size_); |
294 scoped_ptr<uint8[]> capture_buffer(new uint8[capture_buffer_size]); | 294 scoped_ptr<uint8_t[]> capture_buffer(new uint8_t[capture_buffer_size]); |
295 | 295 |
296 LARGE_INTEGER now_count = {}; | 296 LARGE_INTEGER now_count = {}; |
297 bool recording = true; | 297 bool recording = true; |
298 bool error = false; | 298 bool error = false; |
299 double volume = GetVolume(); | 299 double volume = GetVolume(); |
300 HANDLE wait_array[2] = | 300 HANDLE wait_array[2] = |
301 { stop_capture_event_.Get(), audio_samples_ready_event_.Get() }; | 301 { stop_capture_event_.Get(), audio_samples_ready_event_.Get() }; |
302 | 302 |
303 base::win::ScopedComPtr<IAudioClock> audio_clock; | 303 base::win::ScopedComPtr<IAudioClock> audio_clock; |
304 audio_client_->GetService(__uuidof(IAudioClock), audio_clock.ReceiveVoid()); | 304 audio_client_->GetService(__uuidof(IAudioClock), audio_clock.ReceiveVoid()); |
(...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
380 first_audio_frame_timestamp) / 10000.0) * ms_to_frame_count_ + | 380 first_audio_frame_timestamp) / 10000.0) * ms_to_frame_count_ + |
381 buffer_frame_index - num_frames_to_read; | 381 buffer_frame_index - num_frames_to_read; |
382 | 382 |
383 // Get a cached AGC volume level which is updated once every second | 383 // Get a cached AGC volume level which is updated once every second |
384 // on the audio manager thread. Note that, |volume| is also updated | 384 // on the audio manager thread. Note that, |volume| is also updated |
385 // each time SetVolume() is called through IPC by the render-side AGC. | 385 // each time SetVolume() is called through IPC by the render-side AGC. |
386 GetAgcVolume(&volume); | 386 GetAgcVolume(&volume); |
387 | 387 |
388 // Deliver captured data to the registered consumer using a packet | 388 // Deliver captured data to the registered consumer using a packet |
389 // size which was specified at construction. | 389 // size which was specified at construction. |
390 uint32 delay_frames = static_cast<uint32>(audio_delay_frames + 0.5); | 390 uint32_t delay_frames = |
| 391 static_cast<uint32_t>(audio_delay_frames + 0.5); |
391 while (buffer_frame_index >= packet_size_frames_) { | 392 while (buffer_frame_index >= packet_size_frames_) { |
392 // Copy data to audio bus to match the OnData interface. | 393 // Copy data to audio bus to match the OnData interface. |
393 uint8* audio_data = reinterpret_cast<uint8*>(capture_buffer.get()); | 394 uint8_t* audio_data = |
| 395 reinterpret_cast<uint8_t*>(capture_buffer.get()); |
394 audio_bus_->FromInterleaved( | 396 audio_bus_->FromInterleaved( |
395 audio_data, audio_bus_->frames(), format_.wBitsPerSample / 8); | 397 audio_data, audio_bus_->frames(), format_.wBitsPerSample / 8); |
396 | 398 |
397 // Deliver data packet, delay estimation and volume level to | 399 // Deliver data packet, delay estimation and volume level to |
398 // the user. | 400 // the user. |
399 sink_->OnData( | 401 sink_->OnData( |
400 this, audio_bus_.get(), delay_frames * frame_size_, volume); | 402 this, audio_bus_.get(), delay_frames * frame_size_, volume); |
401 | 403 |
402 // Store parts of the recorded data which can't be delivered | 404 // Store parts of the recorded data which can't be delivered |
403 // using the current packet size. The stored section will be used | 405 // using the current packet size. The stored section will be used |
(...skipping 271 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
675 return hr; | 677 return hr; |
676 | 678 |
677 // Obtain a reference to the ISimpleAudioVolume interface which enables | 679 // Obtain a reference to the ISimpleAudioVolume interface which enables |
678 // us to control the master volume level of an audio session. | 680 // us to control the master volume level of an audio session. |
679 hr = audio_client_->GetService(__uuidof(ISimpleAudioVolume), | 681 hr = audio_client_->GetService(__uuidof(ISimpleAudioVolume), |
680 simple_audio_volume_.ReceiveVoid()); | 682 simple_audio_volume_.ReceiveVoid()); |
681 return hr; | 683 return hr; |
682 } | 684 } |
683 | 685 |
684 } // namespace media | 686 } // namespace media |
OLD | NEW |