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 <objbase.h> | 7 #include <objbase.h> |
8 | 8 |
9 #include <cmath> | 9 #include <cmath> |
10 #include <memory> | 10 #include <memory> |
(...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
96 LARGE_INTEGER performance_frequency; | 96 LARGE_INTEGER performance_frequency; |
97 if (QueryPerformanceFrequency(&performance_frequency)) { | 97 if (QueryPerformanceFrequency(&performance_frequency)) { |
98 perf_count_to_100ns_units_ = | 98 perf_count_to_100ns_units_ = |
99 (10000000.0 / static_cast<double>(performance_frequency.QuadPart)); | 99 (10000000.0 / static_cast<double>(performance_frequency.QuadPart)); |
100 } else { | 100 } else { |
101 DLOG(ERROR) << "High-resolution performance counters are not supported."; | 101 DLOG(ERROR) << "High-resolution performance counters are not supported."; |
102 } | 102 } |
103 } | 103 } |
104 | 104 |
105 WASAPIAudioInputStream::~WASAPIAudioInputStream() { | 105 WASAPIAudioInputStream::~WASAPIAudioInputStream() { |
106 DCHECK(CalledOnValidThread()); | 106 DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_); |
107 } | 107 } |
108 | 108 |
109 bool WASAPIAudioInputStream::Open() { | 109 bool WASAPIAudioInputStream::Open() { |
110 DCHECK(CalledOnValidThread()); | 110 DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_); |
111 DCHECK_EQ(OPEN_RESULT_OK, open_result_); | 111 DCHECK_EQ(OPEN_RESULT_OK, open_result_); |
112 | 112 |
113 // Verify that we are not already opened. | 113 // Verify that we are not already opened. |
114 if (opened_) | 114 if (opened_) |
115 return false; | 115 return false; |
116 | 116 |
117 // Obtain a reference to the IMMDevice interface of the capturing | 117 // Obtain a reference to the IMMDevice interface of the capturing |
118 // device with the specified unique identifier or role which was | 118 // device with the specified unique identifier or role which was |
119 // set at construction. | 119 // set at construction. |
120 HRESULT hr = SetCaptureDevice(); | 120 HRESULT hr = SetCaptureDevice(); |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
153 hr = InitializeAudioEngine(); | 153 hr = InitializeAudioEngine(); |
154 if (SUCCEEDED(hr) && converter_) | 154 if (SUCCEEDED(hr) && converter_) |
155 open_result_ = OPEN_RESULT_OK_WITH_RESAMPLING; | 155 open_result_ = OPEN_RESULT_OK_WITH_RESAMPLING; |
156 ReportOpenResult(); // Report before we assign a value to |opened_|. | 156 ReportOpenResult(); // Report before we assign a value to |opened_|. |
157 opened_ = SUCCEEDED(hr); | 157 opened_ = SUCCEEDED(hr); |
158 | 158 |
159 return opened_; | 159 return opened_; |
160 } | 160 } |
161 | 161 |
162 void WASAPIAudioInputStream::Start(AudioInputCallback* callback) { | 162 void WASAPIAudioInputStream::Start(AudioInputCallback* callback) { |
163 DCHECK(CalledOnValidThread()); | 163 DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_); |
164 DCHECK(callback); | 164 DCHECK(callback); |
165 DLOG_IF(ERROR, !opened_) << "Open() has not been called successfully"; | 165 DLOG_IF(ERROR, !opened_) << "Open() has not been called successfully"; |
166 if (!opened_) | 166 if (!opened_) |
167 return; | 167 return; |
168 | 168 |
169 if (started_) | 169 if (started_) |
170 return; | 170 return; |
171 | 171 |
172 if (device_id_ == AudioDeviceDescription::kLoopbackWithMuteDeviceId && | 172 if (device_id_ == AudioDeviceDescription::kLoopbackWithMuteDeviceId && |
173 system_audio_volume_) { | 173 system_audio_volume_) { |
(...skipping 28 matching lines...) Expand all Loading... |
202 HRESULT hr = audio_client_->Start(); | 202 HRESULT hr = audio_client_->Start(); |
203 DLOG_IF(ERROR, FAILED(hr)) << "Failed to start input streaming."; | 203 DLOG_IF(ERROR, FAILED(hr)) << "Failed to start input streaming."; |
204 | 204 |
205 if (SUCCEEDED(hr) && audio_render_client_for_loopback_.Get()) | 205 if (SUCCEEDED(hr) && audio_render_client_for_loopback_.Get()) |
206 hr = audio_render_client_for_loopback_->Start(); | 206 hr = audio_render_client_for_loopback_->Start(); |
207 | 207 |
208 started_ = SUCCEEDED(hr); | 208 started_ = SUCCEEDED(hr); |
209 } | 209 } |
210 | 210 |
211 void WASAPIAudioInputStream::Stop() { | 211 void WASAPIAudioInputStream::Stop() { |
212 DCHECK(CalledOnValidThread()); | 212 DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_); |
213 DVLOG(1) << "WASAPIAudioInputStream::Stop()"; | 213 DVLOG(1) << "WASAPIAudioInputStream::Stop()"; |
214 if (!started_) | 214 if (!started_) |
215 return; | 215 return; |
216 | 216 |
217 // We have muted system audio for capturing, so we need to unmute it when | 217 // We have muted system audio for capturing, so we need to unmute it when |
218 // capturing stops. | 218 // capturing stops. |
219 if (device_id_ == AudioDeviceDescription::kLoopbackWithMuteDeviceId && | 219 if (device_id_ == AudioDeviceDescription::kLoopbackWithMuteDeviceId && |
220 mute_done_) { | 220 mute_done_) { |
221 DCHECK(system_audio_volume_); | 221 DCHECK(system_audio_volume_); |
222 if (system_audio_volume_) { | 222 if (system_audio_volume_) { |
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
271 if (!opened_) | 271 if (!opened_) |
272 return 0.0; | 272 return 0.0; |
273 | 273 |
274 // The effective volume value is always in the range 0.0 to 1.0, hence | 274 // The effective volume value is always in the range 0.0 to 1.0, hence |
275 // we can return a fixed value (=1.0) here. | 275 // we can return a fixed value (=1.0) here. |
276 return 1.0; | 276 return 1.0; |
277 } | 277 } |
278 | 278 |
279 void WASAPIAudioInputStream::SetVolume(double volume) { | 279 void WASAPIAudioInputStream::SetVolume(double volume) { |
280 DVLOG(1) << "SetVolume(volume=" << volume << ")"; | 280 DVLOG(1) << "SetVolume(volume=" << volume << ")"; |
281 DCHECK(CalledOnValidThread()); | 281 DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_); |
282 DCHECK_GE(volume, 0.0); | 282 DCHECK_GE(volume, 0.0); |
283 DCHECK_LE(volume, 1.0); | 283 DCHECK_LE(volume, 1.0); |
284 | 284 |
285 DLOG_IF(ERROR, !opened_) << "Open() has not been called successfully"; | 285 DLOG_IF(ERROR, !opened_) << "Open() has not been called successfully"; |
286 if (!opened_) | 286 if (!opened_) |
287 return; | 287 return; |
288 | 288 |
289 // Set a new master volume level. Valid volume levels are in the range | 289 // Set a new master volume level. Valid volume levels are in the range |
290 // 0.0 to 1.0. Ignore volume-change events. | 290 // 0.0 to 1.0. Ignore volume-change events. |
291 HRESULT hr = | 291 HRESULT hr = |
(...skipping 18 matching lines...) Expand all Loading... |
310 float level = 0.0f; | 310 float level = 0.0f; |
311 HRESULT hr = simple_audio_volume_->GetMasterVolume(&level); | 311 HRESULT hr = simple_audio_volume_->GetMasterVolume(&level); |
312 if (FAILED(hr)) | 312 if (FAILED(hr)) |
313 DLOG(WARNING) << "Failed to get input master volume."; | 313 DLOG(WARNING) << "Failed to get input master volume."; |
314 | 314 |
315 return static_cast<double>(level); | 315 return static_cast<double>(level); |
316 } | 316 } |
317 | 317 |
318 bool WASAPIAudioInputStream::IsMuted() { | 318 bool WASAPIAudioInputStream::IsMuted() { |
319 DCHECK(opened_) << "Open() has not been called successfully"; | 319 DCHECK(opened_) << "Open() has not been called successfully"; |
320 DCHECK(CalledOnValidThread()); | 320 DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_); |
321 if (!opened_) | 321 if (!opened_) |
322 return false; | 322 return false; |
323 | 323 |
324 // Retrieves the current muting state for the audio session. | 324 // Retrieves the current muting state for the audio session. |
325 BOOL is_muted = FALSE; | 325 BOOL is_muted = FALSE; |
326 HRESULT hr = simple_audio_volume_->GetMute(&is_muted); | 326 HRESULT hr = simple_audio_volume_->GetMute(&is_muted); |
327 if (FAILED(hr)) | 327 if (FAILED(hr)) |
328 DLOG(WARNING) << "Failed to get input master volume."; | 328 DLOG(WARNING) << "Failed to get input master volume."; |
329 | 329 |
330 return is_muted != FALSE; | 330 return is_muted != FALSE; |
(...skipping 498 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
829 OPEN_RESULT_MAX + 1); | 829 OPEN_RESULT_MAX + 1); |
830 } | 830 } |
831 | 831 |
832 double WASAPIAudioInputStream::ProvideInput(AudioBus* audio_bus, | 832 double WASAPIAudioInputStream::ProvideInput(AudioBus* audio_bus, |
833 uint32_t frames_delayed) { | 833 uint32_t frames_delayed) { |
834 fifo_->Consume()->CopyTo(audio_bus); | 834 fifo_->Consume()->CopyTo(audio_bus); |
835 return 1.0; | 835 return 1.0; |
836 } | 836 } |
837 | 837 |
838 } // namespace media | 838 } // namespace media |
OLD | NEW |