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 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(ERROR) << "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 HRESULT DefaultAudioDeviceChangeDetector::OnDefaultDeviceChanged( |
| 32 EDataFlow flow, |
| 33 ERole role, |
| 34 LPCWSTR pwstrDefaultDevice) { |
| 35 { |
| 36 base::AutoLock lock(lock_); |
| 37 changed_ = true; |
| 38 } |
| 39 return S_OK; |
| 40 } |
| 41 |
| 42 HRESULT DefaultAudioDeviceChangeDetector::QueryInterface(REFIID iid, |
| 43 void** object) { |
| 44 if (iid == IID_IUnknown || iid == __uuidof(IMMNotificationClient)) { |
| 45 *object = static_cast<IMMNotificationClient*>(this); |
| 46 return S_OK; |
| 47 } |
| 48 *object = nullptr; |
| 49 return E_NOINTERFACE; |
| 50 } |
| 51 |
| 52 bool DefaultAudioDeviceChangeDetector::GetAndReset() { |
| 53 bool result = false; |
| 54 { |
| 55 base::AutoLock lock(lock_); |
| 56 result = changed_; |
| 57 changed_ = false; |
| 58 } |
| 59 return result; |
| 60 } |
| 61 |
| 62 } // namespace remoting |
OLD | NEW |