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_output_win.h" | 5 #include "media/audio/win/audio_low_latency_output_win.h" |
6 | 6 |
7 #include <Functiondiscoverykeys_devpkey.h> | 7 #include <Functiondiscoverykeys_devpkey.h> |
8 | 8 |
9 #include "base/command_line.h" | 9 #include "base/command_line.h" |
10 #include "base/logging.h" | 10 #include "base/logging.h" |
(...skipping 274 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
285 } | 285 } |
286 | 286 |
287 // Initialize the audio stream between the client and the device using | 287 // Initialize the audio stream between the client and the device using |
288 // shared or exclusive mode and a lowest possible glitch-free latency. | 288 // shared or exclusive mode and a lowest possible glitch-free latency. |
289 // We will enter different code paths depending on the specified share mode. | 289 // We will enter different code paths depending on the specified share mode. |
290 hr = InitializeAudioEngine(); | 290 hr = InitializeAudioEngine(); |
291 if (FAILED(hr)) { | 291 if (FAILED(hr)) { |
292 return false; | 292 return false; |
293 } | 293 } |
294 | 294 |
295 // Register this client as an IMMNotificationClient implementation. | |
296 // Only OnDefaultDeviceChanged() and OnDeviceStateChanged() and are | |
297 // non-trivial. | |
298 hr = device_enumerator_->RegisterEndpointNotificationCallback(this); | |
299 | |
300 opened_ = true; | 295 opened_ = true; |
301 return SUCCEEDED(hr); | 296 return true; |
302 } | 297 } |
303 | 298 |
304 void WASAPIAudioOutputStream::Start(AudioSourceCallback* callback) { | 299 void WASAPIAudioOutputStream::Start(AudioSourceCallback* callback) { |
305 DCHECK_EQ(GetCurrentThreadId(), creating_thread_id_); | 300 DCHECK_EQ(GetCurrentThreadId(), creating_thread_id_); |
306 CHECK(callback); | 301 CHECK(callback); |
307 CHECK(opened_); | 302 CHECK(opened_); |
308 | 303 |
309 if (render_thread_.get()) { | 304 if (render_thread_.get()) { |
310 CHECK_EQ(callback, source_); | 305 CHECK_EQ(callback, source_); |
311 return; | 306 return; |
(...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
404 } | 399 } |
405 } | 400 } |
406 | 401 |
407 void WASAPIAudioOutputStream::Close() { | 402 void WASAPIAudioOutputStream::Close() { |
408 DCHECK_EQ(GetCurrentThreadId(), creating_thread_id_); | 403 DCHECK_EQ(GetCurrentThreadId(), creating_thread_id_); |
409 | 404 |
410 // It is valid to call Close() before calling open or Start(). | 405 // It is valid to call Close() before calling open or Start(). |
411 // It is also valid to call Close() after Start() has been called. | 406 // It is also valid to call Close() after Start() has been called. |
412 Stop(); | 407 Stop(); |
413 | 408 |
414 if (opened_ && device_enumerator_) { | |
415 // De-register the IMMNotificationClient callback interface. | |
416 HRESULT hr = device_enumerator_->UnregisterEndpointNotificationCallback( | |
417 this); | |
418 DLOG_IF(ERROR, FAILED(hr)) << "Failed to disable device notifications: " | |
419 << std::hex << hr; | |
420 } | |
421 | |
422 // Inform the audio manager that we have been closed. This will cause our | 409 // Inform the audio manager that we have been closed. This will cause our |
423 // destruction. | 410 // destruction. |
424 manager_->ReleaseOutputStream(this); | 411 manager_->ReleaseOutputStream(this); |
425 } | 412 } |
426 | 413 |
427 void WASAPIAudioOutputStream::SetVolume(double volume) { | 414 void WASAPIAudioOutputStream::SetVolume(double volume) { |
428 DVLOG(1) << "SetVolume(volume=" << volume << ")"; | 415 DVLOG(1) << "SetVolume(volume=" << volume << ")"; |
429 float volume_float = static_cast<float>(volume); | 416 float volume_float = static_cast<float>(volume); |
430 if (volume_float < 0.0f || volume_float > 1.0f) { | 417 if (volume_float < 0.0f || volume_float > 1.0f) { |
431 return; | 418 return; |
(...skipping 681 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1113 // are now re-initiated and it is now possible to re-start audio rendering. | 1100 // are now re-initiated and it is now possible to re-start audio rendering. |
1114 | 1101 |
1115 // Start rendering again using the new default audio endpoint. | 1102 // Start rendering again using the new default audio endpoint. |
1116 hr = audio_client_->Start(); | 1103 hr = audio_client_->Start(); |
1117 | 1104 |
1118 restart_rendering_mode_ = false; | 1105 restart_rendering_mode_ = false; |
1119 return SUCCEEDED(hr); | 1106 return SUCCEEDED(hr); |
1120 } | 1107 } |
1121 | 1108 |
1122 } // namespace media | 1109 } // namespace media |
OLD | NEW |