OLD | NEW |
(Empty) | |
| 1 // Copyright 2017 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #include "remoting/host/win/default_audio_device_change_detector.h" |
| 6 |
| 7 #include <unknwn.h> |
| 8 |
| 9 #include "base/logging.h" |
| 10 |
| 11 namespace remoting { |
| 12 |
| 13 DefaultAudioDeviceChangeDetector::DefaultAudioDeviceChangeDetector( |
| 14 const base::win::ScopedComPtr<IMMDeviceEnumerator>& enumerator) |
| 15 : enumerator_(enumerator) { |
| 16 DCHECK(enumerator_); |
| 17 HRESULT hr = enumerator_->RegisterEndpointNotificationCallback(this); |
| 18 if (FAILED(hr)) { |
| 19 // We cannot predict which kind of error the API may return, but this is not |
| 20 // a fatal error. |
| 21 LOG(WARNING) << "Failed to register IMMNotificationClient, we may not be " |
| 22 "able to detect the new default audio device. Error " |
| 23 << hr; |
| 24 } |
| 25 } |
| 26 |
| 27 DefaultAudioDeviceChangeDetector::~DefaultAudioDeviceChangeDetector() { |
| 28 enumerator_->UnregisterEndpointNotificationCallback(this); |
| 29 } |
| 30 |
| 31 bool DefaultAudioDeviceChangeDetector::GetAndReset() { |
| 32 bool result = false; |
| 33 { |
| 34 base::AutoLock lock(lock_); |
| 35 result = changed_; |
| 36 changed_ = false; |
| 37 } |
| 38 return result; |
| 39 } |
| 40 |
| 41 HRESULT DefaultAudioDeviceChangeDetector::OnDefaultDeviceChanged( |
| 42 EDataFlow flow, |
| 43 ERole role, |
| 44 LPCWSTR pwstrDefaultDevice) { |
| 45 { |
| 46 base::AutoLock lock(lock_); |
| 47 changed_ = true; |
| 48 } |
| 49 return S_OK; |
| 50 } |
| 51 |
| 52 HRESULT DefaultAudioDeviceChangeDetector::QueryInterface(REFIID iid, |
| 53 void** object) { |
| 54 if (iid == IID_IUnknown || iid == __uuidof(IMMNotificationClient)) { |
| 55 *object = static_cast<IMMNotificationClient*>(this); |
| 56 return S_OK; |
| 57 } |
| 58 *object = nullptr; |
| 59 return E_NOINTERFACE; |
| 60 } |
| 61 |
| 62 HRESULT DefaultAudioDeviceChangeDetector::OnDeviceAdded(LPCWSTR pwstrDeviceId) { |
| 63 return S_OK; |
| 64 } |
| 65 |
| 66 HRESULT DefaultAudioDeviceChangeDetector::OnDeviceRemoved( |
| 67 LPCWSTR pwstrDeviceId) { |
| 68 return S_OK; |
| 69 } |
| 70 |
| 71 HRESULT DefaultAudioDeviceChangeDetector::OnDeviceStateChanged( |
| 72 LPCWSTR pwstrDeviceId, |
| 73 DWORD dwNewState) { |
| 74 return S_OK; |
| 75 } |
| 76 |
| 77 HRESULT DefaultAudioDeviceChangeDetector::OnPropertyValueChanged( |
| 78 LPCWSTR pwstrDeviceId, |
| 79 const PROPERTYKEY key) { |
| 80 return S_OK; |
| 81 } |
| 82 |
| 83 ULONG DefaultAudioDeviceChangeDetector::AddRef() { return 1; } |
| 84 |
| 85 ULONG DefaultAudioDeviceChangeDetector::Release() { return 1; } |
| 86 |
| 87 } // namespace remoting |
OLD | NEW |