VirtualBox

source: vbox/trunk/src/VBox/Devices/Audio/VBoxMMNotificationClient.cpp@ 70470

Last change on this file since 70470 was 70470, checked in by vboxsync, 7 years ago

Audio/VBoxMMNotificationClient.cpp: Set m_fRegisteredClient if we successfully registered a notification client.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 4.5 KB
Line 
1/* $Id: VBoxMMNotificationClient.cpp 70470 2018-01-05 15:24:56Z vboxsync $ */
2/** @file
3 * VBoxMMNotificationClient.cpp - Implementation of the IMMNotificationClient interface
4 * to detect audio endpoint changes.
5 */
6
7/*
8 * Copyright (C) 2017-2018 Oracle Corporation
9 *
10 * This file is part of VirtualBox Open Source Edition (OSE), as
11 * available from http://www.virtualbox.org. This file is free software;
12 * you can redistribute it and/or modify it under the terms of the GNU
13 * General Public License (GPL) as published by the Free Software
14 * Foundation, in version 2 as it comes in the "COPYING" file of the
15 * VirtualBox OSE distribution. VirtualBox OSE is distributed in the
16 * hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
17 */
18
19#include "VBoxMMNotificationClient.h"
20
21#include <iprt/win/windows.h>
22
23#pragma warning(push)
24#pragma warning(disable: 4201)
25#include <mmdeviceapi.h>
26#include <endpointvolume.h>
27#pragma warning(pop)
28
29#ifdef LOG_GROUP
30# undef LOG_GROUP
31#endif
32#define LOG_GROUP LOG_GROUP_DRV_HOST_AUDIO
33#include <VBox/log.h>
34
35VBoxMMNotificationClient::VBoxMMNotificationClient(void)
36 : m_fRegisteredClient(false)
37 , m_cRef(1)
38{
39}
40
41VBoxMMNotificationClient::~VBoxMMNotificationClient(void)
42{
43}
44
45void VBoxMMNotificationClient::Dispose(void)
46{
47 DetachFromEndpoint();
48
49 if (m_fRegisteredClient)
50 {
51 m_pEnum->UnregisterEndpointNotificationCallback(this);
52
53 m_fRegisteredClient = false;
54 }
55}
56
57HRESULT VBoxMMNotificationClient::Initialize(void)
58{
59 HRESULT hr = CoCreateInstance(__uuidof(MMDeviceEnumerator), 0, CLSCTX_ALL, __uuidof(IMMDeviceEnumerator),
60 (void **)&m_pEnum);
61 if (SUCCEEDED(hr))
62 {
63 hr = m_pEnum->RegisterEndpointNotificationCallback(this);
64 if (SUCCEEDED(hr))
65 {
66 m_fRegisteredClient = true;
67
68 hr = AttachToDefaultEndpoint();
69 }
70 }
71
72 LogFunc(("Returning %Rhrc\n", hr));
73 return hr;
74}
75
76int VBoxMMNotificationClient::RegisterCallback(PPDMDRVINS pDrvIns, PFNPDMHOSTAUDIOCALLBACK pfnCallback)
77{
78 this->m_pDrvIns = pDrvIns;
79 this->m_pfnCallback = pfnCallback;
80
81 return VINF_SUCCESS;
82}
83
84void VBoxMMNotificationClient::UnregisterCallback(void)
85{
86 this->m_pDrvIns = NULL;
87 this->m_pfnCallback = NULL;
88}
89
90HRESULT VBoxMMNotificationClient::AttachToDefaultEndpoint(void)
91{
92 return S_OK;
93}
94
95void VBoxMMNotificationClient::DetachFromEndpoint(void)
96{
97
98}
99
100STDMETHODIMP VBoxMMNotificationClient::OnDeviceStateChanged(LPCWSTR pwstrDeviceId, DWORD dwNewState)
101{
102 char *pszState = "unknown";
103
104 switch (dwNewState)
105 {
106 case DEVICE_STATE_ACTIVE:
107 pszState = "active";
108 break;
109 case DEVICE_STATE_DISABLED:
110 pszState = "disabled";
111 break;
112 case DEVICE_STATE_NOTPRESENT:
113 pszState = "not present";
114 break;
115 case DEVICE_STATE_UNPLUGGED:
116 pszState = "unplugged";
117 break;
118 default:
119 break;
120 }
121
122 LogRel2(("Audio: Device '%ls' has changed state to '%s'\n", pwstrDeviceId, pszState));
123
124#ifdef VBOX_WITH_AUDIO_CALLBACKS
125 AssertPtr(this->m_pDrvIns);
126 AssertPtr(this->m_pfnCallback);
127
128 if (this->m_pfnCallback)
129 /* Ignore rc */ this->m_pfnCallback(this->m_pDrvIns, PDMAUDIOBACKENDCBTYPE_DEVICES_CHANGED, NULL, 0);
130#endif
131
132 return S_OK;
133}
134
135STDMETHODIMP VBoxMMNotificationClient::OnDeviceAdded(LPCWSTR pwstrDeviceId)
136{
137 RT_NOREF(pwstrDeviceId);
138 LogFunc(("%ls\n", pwstrDeviceId));
139 return S_OK;
140}
141
142STDMETHODIMP VBoxMMNotificationClient::OnDeviceRemoved(LPCWSTR pwstrDeviceId)
143{
144 RT_NOREF(pwstrDeviceId);
145 LogFunc(("%ls\n", pwstrDeviceId));
146 return S_OK;
147}
148
149STDMETHODIMP VBoxMMNotificationClient::OnDefaultDeviceChanged(EDataFlow eFlow, ERole eRole, LPCWSTR pwstrDefaultDeviceId)
150{
151 RT_NOREF(eFlow, eRole, pwstrDefaultDeviceId);
152
153 if (eFlow == eRender)
154 {
155
156 }
157
158 return S_OK;
159}
160
161STDMETHODIMP VBoxMMNotificationClient::QueryInterface(REFIID interfaceID, void **ppvInterface)
162{
163 const IID IID_IMMNotificationClient = __uuidof(IMMNotificationClient);
164
165 if ( IsEqualIID(interfaceID, IID_IUnknown)
166 || IsEqualIID(interfaceID, IID_IMMNotificationClient))
167 {
168 *ppvInterface = static_cast<IMMNotificationClient*>(this);
169 AddRef();
170 return S_OK;
171 }
172
173 *ppvInterface = NULL;
174 return E_NOINTERFACE;
175}
176
177STDMETHODIMP_(ULONG) VBoxMMNotificationClient::AddRef(void)
178{
179 return InterlockedIncrement(&m_cRef);
180}
181
182STDMETHODIMP_(ULONG) VBoxMMNotificationClient::Release(void)
183{
184 long lRef = InterlockedDecrement(&m_cRef);
185 if (lRef == 0)
186 delete this;
187
188 return lRef;
189}
190
Note: See TracBrowser for help on using the repository browser.

© 2025 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette