VirtualBox

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

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

Build fix.

  • 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 68749 2017-09-13 17:37:47Z vboxsync $ */
2/** @file
3 * VBoxMMNotificationClient.cpp - Implementation of the IMMNotificationClient interface
4 * to detect audio endpoint changes.
5 */
6
7/*
8 * Copyright (C) 2017 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 hr = AttachToDefaultEndpoint();
67 }
68 }
69
70 LogFunc(("Returning %Rhrc\n", hr));
71 return hr;
72}
73
74int VBoxMMNotificationClient::RegisterCallback(PPDMDRVINS pDrvIns, PFNPDMHOSTAUDIOCALLBACK pfnCallback)
75{
76 this->m_pDrvIns = pDrvIns;
77 this->m_pfnCallback = pfnCallback;
78
79 return VINF_SUCCESS;
80}
81
82void VBoxMMNotificationClient::UnregisterCallback(void)
83{
84 this->m_pDrvIns = NULL;
85 this->m_pfnCallback = NULL;
86}
87
88HRESULT VBoxMMNotificationClient::AttachToDefaultEndpoint(void)
89{
90 return S_OK;
91}
92
93void VBoxMMNotificationClient::DetachFromEndpoint(void)
94{
95
96}
97
98STDMETHODIMP VBoxMMNotificationClient::OnDeviceStateChanged(LPCWSTR pwstrDeviceId, DWORD dwNewState)
99{
100 char *pszState = "unknown";
101
102 switch (dwNewState)
103 {
104 case DEVICE_STATE_ACTIVE:
105 pszState = "active";
106 break;
107 case DEVICE_STATE_DISABLED:
108 pszState = "disabled";
109 break;
110 case DEVICE_STATE_NOTPRESENT:
111 pszState = "not present";
112 break;
113 case DEVICE_STATE_UNPLUGGED:
114 pszState = "unplugged";
115 break;
116 default:
117 break;
118 }
119
120 LogRel2(("Audio: Device '%ls' has changed state to '%s'\n", pwstrDeviceId, pszState));
121
122#ifdef VBOX_WITH_AUDIO_CALLBACKS
123 AssertPtr(this->m_pDrvIns);
124 AssertPtr(this->m_pfnCallback);
125
126 if (this->m_pfnCallback)
127 /* Ignore rc */ this->m_pfnCallback(this->m_pDrvIns, PDMAUDIOBACKENDCBTYPE_DEVICES_CHANGED, NULL, 0);
128#endif
129
130 return S_OK;
131}
132
133STDMETHODIMP VBoxMMNotificationClient::OnDeviceAdded(LPCWSTR pwstrDeviceId)
134{
135 RT_NOREF(pwstrDeviceId);
136 LogFunc(("%ls\n", pwstrDeviceId));
137 return S_OK;
138}
139
140STDMETHODIMP VBoxMMNotificationClient::OnDeviceRemoved(LPCWSTR pwstrDeviceId)
141{
142 RT_NOREF(pwstrDeviceId);
143 LogFunc(("%ls\n", pwstrDeviceId));
144 return S_OK;
145}
146
147STDMETHODIMP VBoxMMNotificationClient::OnDefaultDeviceChanged(EDataFlow eFlow, ERole eRole, LPCWSTR pwstrDefaultDeviceId)
148{
149 RT_NOREF(eFlow, eRole, pwstrDefaultDeviceId);
150
151 if (eFlow == eRender)
152 {
153
154 }
155
156 return S_OK;
157}
158
159STDMETHODIMP VBoxMMNotificationClient::QueryInterface(REFIID interfaceID, void **ppvInterface)
160{
161 const IID IID_IMMNotificationClient = __uuidof(IMMNotificationClient);
162
163 if ( IsEqualIID(interfaceID, IID_IUnknown)
164 || IsEqualIID(interfaceID, IID_IMMNotificationClient))
165 {
166 *ppvInterface = static_cast<IMMNotificationClient*>(this);
167 AddRef();
168 return S_OK;
169 }
170
171 *ppvInterface = NULL;
172 return E_NOINTERFACE;
173}
174
175STDMETHODIMP_(ULONG) VBoxMMNotificationClient::AddRef(void)
176{
177 return InterlockedIncrement(&m_cRef);
178}
179
180STDMETHODIMP_(ULONG) VBoxMMNotificationClient::Release(void)
181{
182 long lRef = InterlockedDecrement(&m_cRef);
183 if (lRef == 0)
184 delete this;
185
186 return lRef;
187}
188
Note: See TracBrowser for help on using the repository browser.

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