Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/mpc-hc/sanear.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAlex Marsev <alex.marsev@gmail.com>2015-09-17 22:22:41 +0300
committerAlex Marsev <alex.marsev@gmail.com>2015-09-18 07:24:04 +0300
commit65d1c3b1fb7802f420602db94ace04f6ad999712 (patch)
treee2dfefe9bd49f4df9b426cfb84f950f512e70199
parent70189e6d1a9753f8e1f0b87627c64f69ca021358 (diff)
Don't expose notification client in global factory
It's not needed there and has potential issues with COM apartments. Also follow-up refactoring to the latest pull request.
-rw-r--r--TODO.txt1
-rw-r--r--dll/src/sanear-dll/OuterFilter.cpp14
-rw-r--r--dll/src/sanear-dll/OuterFilter.h2
-rw-r--r--sanear.vcxproj2
-rw-r--r--sanear.vcxproj.filters6
-rw-r--r--src/AudioDevice.h2
-rw-r--r--src/AudioDeviceManager.cpp94
-rw-r--r--src/AudioDeviceManager.h33
-rw-r--r--src/AudioRenderer.cpp58
-rw-r--r--src/AudioRenderer.h2
-rw-r--r--src/Factory.cpp32
-rw-r--r--src/Factory.h3
-rw-r--r--src/MMNotificationClient.cpp99
-rw-r--r--src/MMNotificationClient.h28
-rw-r--r--src/pch.h1
15 files changed, 153 insertions, 224 deletions
diff --git a/TODO.txt b/TODO.txt
index d0cf75a..ae6cadf 100644
--- a/TODO.txt
+++ b/TODO.txt
@@ -1,5 +1,4 @@
- design and implement "guided reclock" interface
- - detect default audio device modification in exclusive mode
- don't recreate the device when media type changes during playback and the old one can be used
- enable zero-padding after stream discontinuity
- override advise portion of IReferenceClock interface
diff --git a/dll/src/sanear-dll/OuterFilter.cpp b/dll/src/sanear-dll/OuterFilter.cpp
index 9daeb19..fdd6b73 100644
--- a/dll/src/sanear-dll/OuterFilter.cpp
+++ b/dll/src/sanear-dll/OuterFilter.cpp
@@ -46,13 +46,6 @@ namespace SaneAudioRenderer
m_settings->GetCrossfeedSettings(&uintValue1, &uintValue2);
m_registryKey.SetUint(CrossfeedCutoffFrequency, uintValue1);
m_registryKey.SetUint(CrossfeedLevel, uintValue2);
-
- //Unregister Notifications
- IMMDeviceEnumeratorPtr pDeviceEnumerator;
- if (SUCCEEDED(pDeviceEnumerator.CreateInstance(__uuidof(MMDeviceEnumerator))))
- {
- pDeviceEnumerator->UnregisterEndpointNotificationCallback(m_notification);
- }
}
STDMETHODIMP OuterFilter::NonDelegatingQueryInterface(REFIID riid, void** ppv)
@@ -77,13 +70,6 @@ namespace SaneAudioRenderer
ReturnIfFailed(Factory::CreateFilterAggregated(GetOwner(), m_guid, m_settings, &m_innerFilter));
ReturnIfFailed(m_registryKey.Open(HKEY_CURRENT_USER, L"Software\\sanear"));
ReturnIfFailed(m_trayWindow.Init(m_settings));
- ReturnIfFailed(Factory::CreateNotificationClient(m_settings, &m_notification));
-
- //Register Notifications
- IMMDeviceEnumeratorPtr pDeviceEnumerator;
- ReturnIfFailed(pDeviceEnumerator.CreateInstance(__uuidof(MMDeviceEnumerator)));
-
- pDeviceEnumerator->RegisterEndpointNotificationCallback(m_notification);
m_initialized = true;
diff --git a/dll/src/sanear-dll/OuterFilter.h b/dll/src/sanear-dll/OuterFilter.h
index e5ec79d..cf4de20 100644
--- a/dll/src/sanear-dll/OuterFilter.h
+++ b/dll/src/sanear-dll/OuterFilter.h
@@ -4,7 +4,6 @@
#include "TrayWindow.h"
#include "../../../src/Interfaces.h"
-#include "../../../src/MMNotificationClient.h"
namespace SaneAudioRenderer
{
@@ -32,6 +31,5 @@ namespace SaneAudioRenderer
ISettingsPtr m_settings;
IUnknownPtr m_innerFilter;
TrayWindow m_trayWindow;
- IMMNotificationClientPtr m_notification;
};
}
diff --git a/sanear.vcxproj b/sanear.vcxproj
index bb7fa47..eb6d000 100644
--- a/sanear.vcxproj
+++ b/sanear.vcxproj
@@ -113,7 +113,6 @@
<ClInclude Include="src\DspRealtimeRate.h" />
<ClInclude Include="src\DspVolume.h" />
<ClInclude Include="src\Interfaces.h" />
- <ClInclude Include="src\MMNotificationClient.h" />
<ClInclude Include="src\MyBasicAudio.h" />
<ClInclude Include="src\MyPropertyPage.h" />
<ClInclude Include="src\MyTestClock.h" />
@@ -139,7 +138,6 @@
<ClCompile Include="src\DspTempo.cpp" />
<ClCompile Include="src\DspRealtimeRate.cpp" />
<ClCompile Include="src\DspVolume.cpp" />
- <ClCompile Include="src\MMNotificationClient.cpp" />
<ClCompile Include="src\MyBasicAudio.cpp" />
<ClCompile Include="src\MyFilter.cpp" />
<ClCompile Include="src\MyClock.cpp" />
diff --git a/sanear.vcxproj.filters b/sanear.vcxproj.filters
index 4cb7f94..aa707a8 100644
--- a/sanear.vcxproj.filters
+++ b/sanear.vcxproj.filters
@@ -68,9 +68,6 @@
<ClCompile Include="src\DspRealtimeRate.cpp">
<Filter>Processors</Filter>
</ClCompile>
- <ClCompile Include="src\MMNotificationClient.cpp">
- <Filter>Renderer</Filter>
- </ClCompile>
</ItemGroup>
<ItemGroup>
<ClInclude Include="src\DspMatrix.h">
@@ -150,9 +147,6 @@
<ClInclude Include="src\DspRealtimeRate.h">
<Filter>Processors</Filter>
</ClInclude>
- <ClInclude Include="src\MMNotificationClient.h">
- <Filter>Renderer</Filter>
- </ClInclude>
</ItemGroup>
<ItemGroup>
<Filter Include="DirectShow">
diff --git a/src/AudioDevice.h b/src/AudioDevice.h
index f858a67..b2990bf 100644
--- a/src/AudioDevice.h
+++ b/src/AudioDevice.h
@@ -22,7 +22,6 @@ namespace SaneAudioRenderer
bool exclusive;
bool bitstream;
bool realtime;
- bool default;
};
class AudioDevice final
@@ -59,7 +58,6 @@ namespace SaneAudioRenderer
bool IsExclusive() const { return m_backend->exclusive; }
bool IsBitstream() const { return m_backend->bitstream; }
bool IsRealtime() const { return m_backend->realtime; }
- bool IsDefault() const { return m_backend->default; }
private:
diff --git a/src/AudioDeviceManager.cpp b/src/AudioDeviceManager.cpp
index a7076b1..e6384ce 100644
--- a/src/AudioDeviceManager.cpp
+++ b/src/AudioDeviceManager.cpp
@@ -48,19 +48,15 @@ namespace SaneAudioRenderer
return ret;
}
- void CreateAudioClient(AudioDeviceBackend& backend)
+ void CreateAudioClient(IMMDeviceEnumerator* pEnumerator, AudioDeviceBackend& backend)
{
- IMMDeviceEnumeratorPtr enumerator;
- ThrowIfFailed(CoCreateInstance(__uuidof(MMDeviceEnumerator), nullptr,
- CLSCTX_INPROC_SERVER, IID_PPV_ARGS(&enumerator)));
+ assert(pEnumerator);
IMMDevicePtr device;
if (!backend.id || backend.id->empty())
{
- backend.default = true;
-
- ThrowIfFailed(enumerator->GetDefaultAudioEndpoint(eRender, eMultimedia, &device));
+ ThrowIfFailed(pEnumerator->GetDefaultAudioEndpoint(eRender, eMultimedia, &device));
LPWSTR pDeviceId = nullptr;
ThrowIfFailed(device->GetId(&pDeviceId));
@@ -69,10 +65,8 @@ namespace SaneAudioRenderer
}
else
{
- backend.default = false;
-
IMMDeviceCollectionPtr collection;
- ThrowIfFailed(enumerator->EnumAudioEndpoints(eRender, DEVICE_STATE_ACTIVE, &collection));
+ ThrowIfFailed(pEnumerator->EnumAudioEndpoints(eRender, DEVICE_STATE_ACTIVE, &collection));
UINT count = 0;
ThrowIfFailed(collection->GetCount(&count));
@@ -105,8 +99,9 @@ namespace SaneAudioRenderer
CLSCTX_INPROC_SERVER, nullptr, (void**)&backend.audioClient));
}
- HRESULT CheckBitstreamFormat(SharedWaveFormat format, ISettings* pSettings)
+ HRESULT CheckBitstreamFormat(IMMDeviceEnumerator* pEnumerator, SharedWaveFormat format, ISettings* pSettings)
{
+ assert(pEnumerator);
assert(format);
assert(pSettings);
@@ -122,7 +117,7 @@ namespace SaneAudioRenderer
device.id = std::make_shared<std::wstring>(pDeviceId);
}
- CreateAudioClient(device);
+ CreateAudioClient(pEnumerator, device);
if (!device.audioClient)
return E_FAIL;
@@ -135,9 +130,11 @@ namespace SaneAudioRenderer
}
}
- HRESULT CreateAudioDeviceBackend(SharedWaveFormat format, bool realtime, ISettings* pSettings,
+ HRESULT CreateAudioDeviceBackend(IMMDeviceEnumerator* pEnumerator,
+ SharedWaveFormat format, bool realtime, ISettings* pSettings,
std::shared_ptr<AudioDeviceBackend>& backend)
{
+ assert(pEnumerator);
assert(format);
assert(pSettings);
@@ -158,7 +155,7 @@ namespace SaneAudioRenderer
backend->bufferDuration = buffer;
}
- CreateAudioClient(*backend);
+ CreateAudioClient(pEnumerator, *backend);
if (!backend->audioClient)
return E_FAIL;
@@ -249,6 +246,28 @@ namespace SaneAudioRenderer
}
}
+ AudioDeviceNotificationClient::AudioDeviceNotificationClient(std::atomic<uint32_t>& defaultDeviceSerial)
+ : CUnknown("SaneAudioRenderer::AudioDeviceNotificationClient", nullptr)
+ , m_defaultDeviceSerial(defaultDeviceSerial)
+ {
+ }
+
+ STDMETHODIMP AudioDeviceNotificationClient::NonDelegatingQueryInterface(REFIID riid, void** ppv)
+ {
+ if (riid == __uuidof(IMMNotificationClient))
+ return GetInterface(static_cast<IMMNotificationClient*>(this), ppv);
+
+ return CUnknown::NonDelegatingQueryInterface(riid, ppv);
+ }
+
+ STDMETHODIMP AudioDeviceNotificationClient::OnDefaultDeviceChanged(EDataFlow flow, ERole role, LPCWSTR)
+ {
+ if (flow == eRender && role == eMultimedia)
+ m_defaultDeviceSerial++;
+
+ return S_OK;
+ }
+
AudioDeviceManager::AudioDeviceManager(HRESULT& result)
{
if (FAILED(result))
@@ -280,6 +299,27 @@ namespace SaneAudioRenderer
}
}
);
+
+ {
+ m_function = [&] { return CoCreateInstance(__uuidof(MMDeviceEnumerator), nullptr,
+ CLSCTX_INPROC_SERVER, IID_PPV_ARGS(&m_enumerator)); };
+ m_wake.Set();
+ m_done.Wait();
+ ThrowIfFailed(m_result);
+ assert(m_enumerator);
+ }
+
+ {
+ auto pNotificationClient = new AudioDeviceNotificationClient(m_defaultDeviceSerial);
+
+ pNotificationClient->NonDelegatingAddRef();
+
+ ThrowIfFailed(pNotificationClient->NonDelegatingQueryInterface(IID_PPV_ARGS(&m_notificationClient)));
+
+ pNotificationClient->NonDelegatingRelease();
+
+ ThrowIfFailed(m_enumerator->RegisterEndpointNotificationCallback(m_notificationClient));
+ }
}
catch (HRESULT ex)
{
@@ -293,6 +333,9 @@ namespace SaneAudioRenderer
AudioDeviceManager::~AudioDeviceManager()
{
+ if (m_enumerator && m_notificationClient)
+ m_enumerator->UnregisterEndpointNotificationCallback(m_notificationClient);
+
m_exit = true;
m_wake.Set();
@@ -305,7 +348,7 @@ namespace SaneAudioRenderer
assert(format);
assert(pSettings);
- m_function = [&] { return CheckBitstreamFormat(format, pSettings); };
+ m_function = [&] { return CheckBitstreamFormat(m_enumerator, format, pSettings); };
m_wake.Set();
m_done.Wait();
@@ -320,7 +363,7 @@ namespace SaneAudioRenderer
std::shared_ptr<AudioDeviceBackend> backend;
- m_function = [&] { return CreateAudioDeviceBackend(format, realtime, pSettings, backend); };
+ m_function = [&] { return CreateAudioDeviceBackend(m_enumerator, format, realtime, pSettings, backend); };
m_wake.Set();
m_done.Wait();
@@ -340,4 +383,23 @@ namespace SaneAudioRenderer
return nullptr;
}
}
+
+ std::unique_ptr<WCHAR, CoTaskMemFreeDeleter> AudioDeviceManager::GetDefaultDeviceId()
+ {
+ assert(m_enumerator);
+
+ try
+ {
+ IMMDevicePtr device;
+ ThrowIfFailed(m_enumerator->GetDefaultAudioEndpoint(eRender, eMultimedia, &device));
+
+ LPWSTR pDeviceId = nullptr;
+ ThrowIfFailed(device->GetId(&pDeviceId));
+ return std::unique_ptr<WCHAR, CoTaskMemFreeDeleter>(pDeviceId);
+ }
+ catch (HRESULT)
+ {
+ return nullptr;
+ }
+ }
}
diff --git a/src/AudioDeviceManager.h b/src/AudioDeviceManager.h
index d8b8708..7cff1b5 100644
--- a/src/AudioDeviceManager.h
+++ b/src/AudioDeviceManager.h
@@ -5,6 +5,31 @@
namespace SaneAudioRenderer
{
+ class AudioDeviceNotificationClient final
+ : public CUnknown
+ , public IMMNotificationClient
+ {
+ public:
+
+ DECLARE_IUNKNOWN
+
+ AudioDeviceNotificationClient(std::atomic<uint32_t>& defaultDeviceSerial);
+ AudioDeviceNotificationClient(const AudioDeviceNotificationClient&) = delete;
+ AudioDeviceNotificationClient& operator=(const AudioDeviceNotificationClient&) = delete;
+
+ STDMETHODIMP NonDelegatingQueryInterface(REFIID riid, void** ppv) override;
+
+ STDMETHODIMP OnDeviceStateChanged(LPCWSTR, DWORD) override { return S_OK; }
+ STDMETHODIMP OnDeviceAdded(LPCWSTR) override { return S_OK; }
+ STDMETHODIMP OnDeviceRemoved(LPCWSTR) override { return S_OK; }
+ STDMETHODIMP OnDefaultDeviceChanged(EDataFlow flow, ERole role, LPCWSTR);
+ STDMETHODIMP OnPropertyValueChanged(LPCWSTR, const PROPERTYKEY) override { return S_OK; }
+
+ private:
+
+ std::atomic<uint32_t>& m_defaultDeviceSerial;
+ };
+
class AudioDeviceManager final
{
public:
@@ -17,6 +42,9 @@ namespace SaneAudioRenderer
bool BitstreamFormatSupported(SharedWaveFormat format, ISettings* pSettings);
std::unique_ptr<AudioDevice> CreateDevice(SharedWaveFormat format, bool realtime, ISettings* pSettings);
+ uint32_t GetDefaultDeviceSerial() { return m_defaultDeviceSerial; }
+ std::unique_ptr<WCHAR, CoTaskMemFreeDeleter> GetDefaultDeviceId();
+
private:
std::thread m_thread;
@@ -26,5 +54,10 @@ namespace SaneAudioRenderer
std::function<HRESULT(void)> m_function;
HRESULT m_result = S_OK;
+
+ IMMDeviceEnumeratorPtr m_enumerator;
+
+ IMMNotificationClientPtr m_notificationClient;
+ std::atomic<uint32_t> m_defaultDeviceSerial = 0;
};
}
diff --git a/src/AudioRenderer.cpp b/src/AudioRenderer.cpp
index 961c4a8..a6e95b9 100644
--- a/src/AudioRenderer.cpp
+++ b/src/AudioRenderer.cpp
@@ -369,29 +369,48 @@ namespace SaneAudioRenderer
{
CAutoLock objectLock(this);
- UINT32 serial = m_settings->GetSerial();
+ UINT32 newSettingsSerial = m_settings->GetSerial();
+ uint32_t newDefaultDeviceSerial = m_deviceManager.GetDefaultDeviceSerial();
- if (m_device && m_deviceSettingsSerial != serial)
+ if (m_device && (m_deviceSettingsSerial != newSettingsSerial ||
+ m_defaultDeviceSerial != newDefaultDeviceSerial))
{
- LPWSTR pDeviceId = nullptr;
- BOOL exclusive;
- UINT32 buffer;
- if (SUCCEEDED(m_settings->GetOuputDevice(&pDeviceId, &exclusive, &buffer)))
+ bool settingsDeviceDefault;
+ std::unique_ptr<WCHAR, CoTaskMemFreeDeleter> settingsDeviceId;
+ BOOL settingsDeviceExclusive;
+ UINT32 settingsDeviceBuffer;
+
{
- std::unique_ptr<WCHAR, CoTaskMemFreeDeleter> holder(pDeviceId);
+ LPWSTR pDeviceId = nullptr;
- if (m_device->IsExclusive() != !!exclusive ||
- m_device->GetBufferDuration() != buffer ||
- (pDeviceId && *pDeviceId && (m_device->IsDefault() || *m_device->GetId() != pDeviceId)) ||
- ((!pDeviceId || !*pDeviceId) && !m_device->IsDefault()))
- {
- ClearDevice();
- assert(!m_device);
- }
- else
- {
- m_deviceSettingsSerial = serial;
- }
+ if (FAILED(m_settings->GetOuputDevice(&pDeviceId, &settingsDeviceExclusive, &settingsDeviceBuffer)))
+ return;
+
+ settingsDeviceDefault = (!pDeviceId || !*pDeviceId);
+ settingsDeviceId.reset(pDeviceId);
+
+ m_deviceSettingsSerial = newSettingsSerial;
+ }
+
+ std::unique_ptr<WCHAR, CoTaskMemFreeDeleter> systemDeviceId;;
+
+ if (settingsDeviceDefault)
+ {
+ systemDeviceId = m_deviceManager.GetDefaultDeviceId();
+
+ if (!systemDeviceId)
+ return;
+ }
+
+ m_defaultDeviceSerial = newDefaultDeviceSerial;
+
+ if ((m_device->IsExclusive() != !!settingsDeviceExclusive) ||
+ (m_device->GetBufferDuration() != settingsDeviceBuffer) ||
+ (!settingsDeviceDefault && *m_device->GetId() != settingsDeviceId.get()) ||
+ (settingsDeviceDefault && *m_device->GetId() != systemDeviceId.get()))
+ {
+ ClearDevice();
+ assert(!m_device);
}
}
}
@@ -417,6 +436,7 @@ namespace SaneAudioRenderer
assert(m_inputFormat);
m_deviceSettingsSerial = m_settings->GetSerial();
+ m_defaultDeviceSerial = m_deviceManager.GetDefaultDeviceSerial();
m_device = m_deviceManager.CreateDevice(m_inputFormat, m_live || m_externalClock, m_settings);
if (m_device)
diff --git a/src/AudioRenderer.h b/src/AudioRenderer.h
index f0788ea..7dd8138 100644
--- a/src/AudioRenderer.h
+++ b/src/AudioRenderer.h
@@ -119,6 +119,8 @@ namespace SaneAudioRenderer
ISettingsPtr m_settings;
UINT32 m_deviceSettingsSerial = 0;
+ uint32_t m_defaultDeviceSerial = 0;
+
std::atomic<float> m_volume = 1.0f;
std::atomic<float> m_balance = 0.0f;
double m_rate = 1.0;
diff --git a/src/Factory.cpp b/src/Factory.cpp
index 12d2db4..a93ebf7 100644
--- a/src/Factory.cpp
+++ b/src/Factory.cpp
@@ -3,7 +3,6 @@
#include "MyFilter.h"
#include "Settings.h"
-#include "MMNotificationClient.h"
namespace SaneAudioRenderer
{
@@ -34,37 +33,6 @@ namespace SaneAudioRenderer
return result;
}
- HRESULT Factory::CreateNotificationClient(ISettings* pSettings, IMMNotificationClient** ppOut)
- {
- IUnknownPtr unknown;
- ReturnIfFailed(CreateNotificationClientAggregated(pSettings, &unknown));
- return unknown->QueryInterface(IID_PPV_ARGS(ppOut));
- }
-
- HRESULT Factory::CreateNotificationClientAggregated(ISettings* pSettings, IUnknown** ppOut)
- {
- CheckPointer(ppOut, E_POINTER);
- CheckPointer(pSettings, E_POINTER);
-
- *ppOut = nullptr;
-
- auto pNotifclient = new(std::nothrow) CMMNotificationClient;
-
- if (!pNotifclient)
- return E_OUTOFMEMORY;
-
- pNotifclient->AddRef();
-
- HRESULT result = pNotifclient->Init(pSettings);
-
- if (SUCCEEDED(result))
- result = pNotifclient->QueryInterface(IID_PPV_ARGS(ppOut));
-
- pNotifclient->Release();
-
- return result;
- }
-
HRESULT Factory::CreateFilter(ISettings* pSettings, IBaseFilter** ppOut)
{
IUnknownPtr unknown;
diff --git a/src/Factory.h b/src/Factory.h
index d12cc5d..178620b 100644
--- a/src/Factory.h
+++ b/src/Factory.h
@@ -16,9 +16,6 @@ namespace SaneAudioRenderer
static HRESULT CreateSettings(ISettings** ppOut);
static HRESULT CreateSettingsAggregated(IUnknown* pOwner, IUnknown** ppOut);
- static HRESULT CreateNotificationClient(__in ISettings* pSettings, __out IMMNotificationClient** ppOut);
- static HRESULT CreateNotificationClientAggregated(__in ISettings* pSettings, __out IUnknown** ppOut);
-
static HRESULT CreateFilter(ISettings* pSettings, IBaseFilter** ppOut);
static HRESULT CreateFilterAggregated(IUnknown* pOwner, const GUID& guid,
ISettings* pSettings, IUnknown** ppOut);
diff --git a/src/MMNotificationClient.cpp b/src/MMNotificationClient.cpp
deleted file mode 100644
index d8cb896..0000000
--- a/src/MMNotificationClient.cpp
+++ /dev/null
@@ -1,99 +0,0 @@
-#include "pch.h"
-#include "MMNotificationClient.h"
-
-namespace SaneAudioRenderer
-{
- HRESULT CMMNotificationClient::QueryInterface(const IID& riid, void** ppvInterface)
- {
- if (IID_IUnknown == riid)
- {
- AddRef();
- *ppvInterface = static_cast<IUnknown*>(this);
- }
- else if (__uuidof(IMMNotificationClient) == riid)
- {
- AddRef();
- *ppvInterface = static_cast<IMMNotificationClient*>(this);
- }
- else
- {
- *ppvInterface = nullptr;
- return E_NOINTERFACE;
- }
- return S_OK;
- }
-
- ULONG CMMNotificationClient::AddRef()
- {
- return InterlockedIncrement(&m_cRef);
- }
-
- ULONG CMMNotificationClient::Release()
- {
- ULONG ulRef = InterlockedDecrement(&m_cRef);
- if (0 == ulRef)
- {
- delete this;
- }
- return ulRef;
- }
-
- HRESULT CMMNotificationClient::OnDeviceStateChanged(LPCWSTR pwstrDeviceId, DWORD dwNewState)
- {
- return S_OK;
- }
-
- HRESULT CMMNotificationClient::OnDeviceAdded(LPCWSTR pwstrDeviceId)
- {
- return S_OK;
- }
-
- HRESULT CMMNotificationClient::OnDeviceRemoved(LPCWSTR pwstrDeviceId)
- {
- return S_OK;
- }
-
- HRESULT CMMNotificationClient::OnDefaultDeviceChanged(EDataFlow flow, ERole role, LPCWSTR pwstrDefaultDeviceId)
- {
- //Not interested in Recording devices
- if (flow == eCapture)
- return S_FALSE;
- //Not interested in Communications devices, only Multimedia and Console
- if (role == ::eCommunications)
- return S_FALSE;
-
- LPWSTR pDeviceId = nullptr;
- BOOL exclusive;
- UINT32 buffer;
- m_settings->GetOuputDevice(&pDeviceId, &exclusive, &buffer);
- std::unique_ptr<WCHAR, CoTaskMemFreeDeleter> holder(pDeviceId);
-
- if (!pDeviceId || pwstrDefaultDeviceId != pDeviceId)
- {
- m_settings->SetOuputDevice(pwstrDefaultDeviceId, exclusive, buffer);
- return S_OK;
- }
- return S_FALSE;
- }
-
- HRESULT CMMNotificationClient::OnPropertyValueChanged(LPCWSTR pwstrDeviceId, const PROPERTYKEY key)
- {
- return S_OK;
- }
-
- HRESULT CMMNotificationClient::Init(ISettings* pSettings)
- {
- CheckPointer(pSettings, E_POINTER);
- ReturnIfFailed(pSettings->QueryInterface(IID_PPV_ARGS(&m_settings)));
- return S_OK;
- }
-
- CMMNotificationClient::CMMNotificationClient() : m_cRef(0)
- {
- }
-
-
- CMMNotificationClient::~CMMNotificationClient()
- {
- }
-}
diff --git a/src/MMNotificationClient.h b/src/MMNotificationClient.h
deleted file mode 100644
index 349657a..0000000
--- a/src/MMNotificationClient.h
+++ /dev/null
@@ -1,28 +0,0 @@
-#pragma once
-#include <comdef.h>
-#include "../../../src/Settings.h"
-
-namespace SaneAudioRenderer
-{
- _COM_SMARTPTR_TYPEDEF(IMMDeviceEnumerator, __uuidof(IMMDeviceEnumerator));
- _COM_SMARTPTR_TYPEDEF(IMMNotificationClient, __uuidof(IMMNotificationClient));
-
- class CMMNotificationClient : public IMMNotificationClient
- {
- public:
- HRESULT STDMETHODCALLTYPE QueryInterface(const IID& riid, void** ppvObject) override;
- ULONG STDMETHODCALLTYPE AddRef() override;
- ULONG STDMETHODCALLTYPE Release() override;
- HRESULT STDMETHODCALLTYPE OnDeviceStateChanged(LPCWSTR pwstrDeviceId, DWORD dwNewState) override;
- HRESULT STDMETHODCALLTYPE OnDeviceAdded(LPCWSTR pwstrDeviceId) override;
- HRESULT STDMETHODCALLTYPE OnDeviceRemoved(LPCWSTR pwstrDeviceId) override;
- HRESULT STDMETHODCALLTYPE OnDefaultDeviceChanged(EDataFlow flow, ERole role, LPCWSTR pwstrDefaultDeviceId) override;
- HRESULT STDMETHODCALLTYPE OnPropertyValueChanged(LPCWSTR pwstrDeviceId, const PROPERTYKEY key) override;
- HRESULT Init(ISettings* pSettings);
- CMMNotificationClient();
- virtual ~CMMNotificationClient();
- private:
- LONG m_cRef;
- ISettingsPtr m_settings;
- };
-}
diff --git a/src/pch.h b/src/pch.h
index d61fdd6..530d9ac 100644
--- a/src/pch.h
+++ b/src/pch.h
@@ -38,6 +38,7 @@ namespace SaneAudioRenderer
_COM_SMARTPTR_TYPEDEF(IMMDeviceEnumerator, __uuidof(IMMDeviceEnumerator));
_COM_SMARTPTR_TYPEDEF(IMMDeviceCollection, __uuidof(IMMDeviceCollection));
_COM_SMARTPTR_TYPEDEF(IMMDevice, __uuidof(IMMDevice));
+ _COM_SMARTPTR_TYPEDEF(IMMNotificationClient, __uuidof(IMMNotificationClient));
_COM_SMARTPTR_TYPEDEF(IAudioClient, __uuidof(IAudioClient));
_COM_SMARTPTR_TYPEDEF(IAudioRenderClient, __uuidof(IAudioRenderClient));