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_device_listener_win.h" | 5 #include "media/audio/win/audio_device_listener_win.h" |
6 | 6 |
7 #include <Audioclient.h> | 7 #include <Audioclient.h> |
8 | 8 |
9 #include "base/logging.h" | 9 #include "base/logging.h" |
10 #include "base/strings/utf_string_conversions.h" | 10 #include "base/strings/utf_string_conversions.h" |
(...skipping 19 matching lines...) Expand all Loading... |
30 default: return "undefined"; | 30 default: return "undefined"; |
31 } | 31 } |
32 } | 32 } |
33 | 33 |
34 AudioDeviceListenerWin::AudioDeviceListenerWin(const base::Closure& listener_cb) | 34 AudioDeviceListenerWin::AudioDeviceListenerWin(const base::Closure& listener_cb) |
35 : listener_cb_(listener_cb), tick_clock_(new base::DefaultTickClock()) { | 35 : listener_cb_(listener_cb), tick_clock_(new base::DefaultTickClock()) { |
36 // CreateDeviceEnumerator can fail on some installations of Windows such | 36 // CreateDeviceEnumerator can fail on some installations of Windows such |
37 // as "Windows Server 2008 R2" where the desktop experience isn't available. | 37 // as "Windows Server 2008 R2" where the desktop experience isn't available. |
38 ScopedComPtr<IMMDeviceEnumerator> device_enumerator( | 38 ScopedComPtr<IMMDeviceEnumerator> device_enumerator( |
39 CoreAudioUtil::CreateDeviceEnumerator()); | 39 CoreAudioUtil::CreateDeviceEnumerator()); |
40 if (!device_enumerator.get()) | 40 if (!device_enumerator.Get()) |
41 return; | 41 return; |
42 | 42 |
43 HRESULT hr = device_enumerator->RegisterEndpointNotificationCallback(this); | 43 HRESULT hr = device_enumerator->RegisterEndpointNotificationCallback(this); |
44 if (FAILED(hr)) { | 44 if (FAILED(hr)) { |
45 LOG(ERROR) << "RegisterEndpointNotificationCallback failed: " | 45 LOG(ERROR) << "RegisterEndpointNotificationCallback failed: " |
46 << std::hex << hr; | 46 << std::hex << hr; |
47 return; | 47 return; |
48 } | 48 } |
49 | 49 |
50 device_enumerator_ = device_enumerator; | 50 device_enumerator_ = device_enumerator; |
51 } | 51 } |
52 | 52 |
53 AudioDeviceListenerWin::~AudioDeviceListenerWin() { | 53 AudioDeviceListenerWin::~AudioDeviceListenerWin() { |
54 DCHECK(thread_checker_.CalledOnValidThread()); | 54 DCHECK(thread_checker_.CalledOnValidThread()); |
55 if (device_enumerator_.get()) { | 55 if (device_enumerator_.Get()) { |
56 HRESULT hr = | 56 HRESULT hr = |
57 device_enumerator_->UnregisterEndpointNotificationCallback(this); | 57 device_enumerator_->UnregisterEndpointNotificationCallback(this); |
58 LOG_IF(ERROR, FAILED(hr)) << "UnregisterEndpointNotificationCallback() " | 58 LOG_IF(ERROR, FAILED(hr)) << "UnregisterEndpointNotificationCallback() " |
59 << "failed: " << std::hex << hr; | 59 << "failed: " << std::hex << hr; |
60 } | 60 } |
61 } | 61 } |
62 | 62 |
63 STDMETHODIMP_(ULONG) AudioDeviceListenerWin::AddRef() { | 63 STDMETHODIMP_(ULONG) AudioDeviceListenerWin::AddRef() { |
64 return 1; | 64 return 1; |
65 } | 65 } |
(...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
141 ? CoreAudioUtil::GetFriendlyName(new_device_id) | 141 ? CoreAudioUtil::GetFriendlyName(new_device_id) |
142 : "no device") | 142 : "no device") |
143 << ", flow: " << FlowToString(flow) | 143 << ", flow: " << FlowToString(flow) |
144 << ", role: " << RoleToString(role) | 144 << ", role: " << RoleToString(role) |
145 << ", notified manager: " << (did_run_listener_cb ? "Yes" : "No"); | 145 << ", notified manager: " << (did_run_listener_cb ? "Yes" : "No"); |
146 | 146 |
147 return S_OK; | 147 return S_OK; |
148 } | 148 } |
149 | 149 |
150 } // namespace media | 150 } // namespace media |
OLD | NEW |