| 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/utf_string_conversions.h" | 9 #include "base/utf_string_conversions.h" |
| 10 #include "media/audio/audio_util.h" | 10 #include "media/audio/audio_util.h" |
| (...skipping 14 matching lines...) Expand all Loading... |
| 25 endpoint_buffer_size_frames_(0), | 25 endpoint_buffer_size_frames_(0), |
| 26 device_id_(device_id), | 26 device_id_(device_id), |
| 27 sink_(NULL) { | 27 sink_(NULL) { |
| 28 DCHECK(manager_); | 28 DCHECK(manager_); |
| 29 | 29 |
| 30 // Load the Avrt DLL if not already loaded. Required to support MMCSS. | 30 // Load the Avrt DLL if not already loaded. Required to support MMCSS. |
| 31 bool avrt_init = avrt::Initialize(); | 31 bool avrt_init = avrt::Initialize(); |
| 32 DCHECK(avrt_init) << "Failed to load the Avrt.dll"; | 32 DCHECK(avrt_init) << "Failed to load the Avrt.dll"; |
| 33 | 33 |
| 34 // Set up the desired capture format specified by the client. | 34 // Set up the desired capture format specified by the client. |
| 35 format_.nSamplesPerSec = params.sample_rate; | 35 format_.nSamplesPerSec = params.sample_rate(); |
| 36 format_.wFormatTag = WAVE_FORMAT_PCM; | 36 format_.wFormatTag = WAVE_FORMAT_PCM; |
| 37 format_.wBitsPerSample = params.bits_per_sample; | 37 format_.wBitsPerSample = params.bits_per_sample(); |
| 38 format_.nChannels = params.channels; | 38 format_.nChannels = params.channels(); |
| 39 format_.nBlockAlign = (format_.wBitsPerSample / 8) * format_.nChannels; | 39 format_.nBlockAlign = (format_.wBitsPerSample / 8) * format_.nChannels; |
| 40 format_.nAvgBytesPerSec = format_.nSamplesPerSec * format_.nBlockAlign; | 40 format_.nAvgBytesPerSec = format_.nSamplesPerSec * format_.nBlockAlign; |
| 41 format_.cbSize = 0; | 41 format_.cbSize = 0; |
| 42 | 42 |
| 43 // Size in bytes of each audio frame. | 43 // Size in bytes of each audio frame. |
| 44 frame_size_ = format_.nBlockAlign; | 44 frame_size_ = format_.nBlockAlign; |
| 45 // Store size of audio packets which we expect to get from the audio | 45 // Store size of audio packets which we expect to get from the audio |
| 46 // endpoint device in each capture event. | 46 // endpoint device in each capture event. |
| 47 packet_size_frames_ = params.GetPacketSize() / format_.nBlockAlign; | 47 packet_size_frames_ = params.GetBytesPerBuffer() / format_.nBlockAlign; |
| 48 packet_size_bytes_ = params.GetPacketSize(); | 48 packet_size_bytes_ = params.GetBytesPerBuffer(); |
| 49 DVLOG(1) << "Number of bytes per audio frame : " << frame_size_; | 49 DVLOG(1) << "Number of bytes per audio frame : " << frame_size_; |
| 50 DVLOG(1) << "Number of audio frames per packet: " << packet_size_frames_; | 50 DVLOG(1) << "Number of audio frames per packet: " << packet_size_frames_; |
| 51 | 51 |
| 52 // All events are auto-reset events and non-signaled initially. | 52 // All events are auto-reset events and non-signaled initially. |
| 53 | 53 |
| 54 // Create the event which the audio engine will signal each time | 54 // Create the event which the audio engine will signal each time |
| 55 // a buffer becomes ready to be processed by the client. | 55 // a buffer becomes ready to be processed by the client. |
| 56 audio_samples_ready_event_.Set(CreateEvent(NULL, FALSE, FALSE, NULL)); | 56 audio_samples_ready_event_.Set(CreateEvent(NULL, FALSE, FALSE, NULL)); |
| 57 DCHECK(audio_samples_ready_event_.IsValid()); | 57 DCHECK(audio_samples_ready_event_.IsValid()); |
| 58 | 58 |
| 59 // Create the event which will be set in Stop() when capturing shall stop. | 59 // Create the event which will be set in Stop() when capturing shall stop. |
| 60 stop_capture_event_.Set(CreateEvent(NULL, FALSE, FALSE, NULL)); | 60 stop_capture_event_.Set(CreateEvent(NULL, FALSE, FALSE, NULL)); |
| 61 DCHECK(stop_capture_event_.IsValid()); | 61 DCHECK(stop_capture_event_.IsValid()); |
| 62 | 62 |
| 63 ms_to_frame_count_ = static_cast<double>(params.sample_rate) / 1000.0; | 63 ms_to_frame_count_ = static_cast<double>(params.sample_rate()) / 1000.0; |
| 64 | 64 |
| 65 LARGE_INTEGER performance_frequency; | 65 LARGE_INTEGER performance_frequency; |
| 66 if (QueryPerformanceFrequency(&performance_frequency)) { | 66 if (QueryPerformanceFrequency(&performance_frequency)) { |
| 67 perf_count_to_100ns_units_ = | 67 perf_count_to_100ns_units_ = |
| 68 (10000000.0 / static_cast<double>(performance_frequency.QuadPart)); | 68 (10000000.0 / static_cast<double>(performance_frequency.QuadPart)); |
| 69 } else { | 69 } else { |
| 70 LOG(ERROR) << "High-resolution performance counters are not supported."; | 70 LOG(ERROR) << "High-resolution performance counters are not supported."; |
| 71 perf_count_to_100ns_units_ = 0.0; | 71 perf_count_to_100ns_units_ = 0.0; |
| 72 } | 72 } |
| 73 } | 73 } |
| (...skipping 140 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 214 | 214 |
| 215 // Retrieve the current volume level. The value is in the range 0.0 to 1.0. | 215 // Retrieve the current volume level. The value is in the range 0.0 to 1.0. |
| 216 float level = 0.0f; | 216 float level = 0.0f; |
| 217 HRESULT hr = simple_audio_volume_->GetMasterVolume(&level); | 217 HRESULT hr = simple_audio_volume_->GetMasterVolume(&level); |
| 218 DLOG_IF(WARNING, FAILED(hr)) << "Failed to get input master volume."; | 218 DLOG_IF(WARNING, FAILED(hr)) << "Failed to get input master volume."; |
| 219 | 219 |
| 220 return static_cast<double>(level); | 220 return static_cast<double>(level); |
| 221 } | 221 } |
| 222 | 222 |
| 223 // static | 223 // static |
| 224 double WASAPIAudioInputStream::HardwareSampleRate( | 224 int WASAPIAudioInputStream::HardwareSampleRate( |
| 225 const std::string& device_id) { | 225 const std::string& device_id) { |
| 226 base::win::ScopedCoMem<WAVEFORMATEX> audio_engine_mix_format; | 226 base::win::ScopedCoMem<WAVEFORMATEX> audio_engine_mix_format; |
| 227 HRESULT hr = GetMixFormat(device_id, &audio_engine_mix_format); | 227 HRESULT hr = GetMixFormat(device_id, &audio_engine_mix_format); |
| 228 if (FAILED(hr)) | 228 if (FAILED(hr)) |
| 229 return 0.0; | 229 return 0; |
| 230 | 230 |
| 231 return static_cast<double>(audio_engine_mix_format->nSamplesPerSec); | 231 return static_cast<int>(audio_engine_mix_format->nSamplesPerSec); |
| 232 } | 232 } |
| 233 | 233 |
| 234 // static | 234 // static |
| 235 uint32 WASAPIAudioInputStream::HardwareChannelCount( | 235 uint32 WASAPIAudioInputStream::HardwareChannelCount( |
| 236 const std::string& device_id) { | 236 const std::string& device_id) { |
| 237 base::win::ScopedCoMem<WAVEFORMATEX> audio_engine_mix_format; | 237 base::win::ScopedCoMem<WAVEFORMATEX> audio_engine_mix_format; |
| 238 HRESULT hr = GetMixFormat(device_id, &audio_engine_mix_format); | 238 HRESULT hr = GetMixFormat(device_id, &audio_engine_mix_format); |
| 239 if (FAILED(hr)) | 239 if (FAILED(hr)) |
| 240 return 0; | 240 return 0; |
| 241 | 241 |
| (...skipping 376 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 618 audio_capture_client_.ReceiveVoid()); | 618 audio_capture_client_.ReceiveVoid()); |
| 619 if (FAILED(hr)) | 619 if (FAILED(hr)) |
| 620 return hr; | 620 return hr; |
| 621 | 621 |
| 622 // Obtain a reference to the ISimpleAudioVolume interface which enables | 622 // Obtain a reference to the ISimpleAudioVolume interface which enables |
| 623 // us to control the master volume level of an audio session. | 623 // us to control the master volume level of an audio session. |
| 624 hr = audio_client_->GetService(__uuidof(ISimpleAudioVolume), | 624 hr = audio_client_->GetService(__uuidof(ISimpleAudioVolume), |
| 625 simple_audio_volume_.ReceiveVoid()); | 625 simple_audio_volume_.ReceiveVoid()); |
| 626 return hr; | 626 return hr; |
| 627 } | 627 } |
| OLD | NEW |