diff options
author | Alex Marsev <alex.marsev@gmail.com> | 2013-09-02 20:46:09 +0400 |
---|---|---|
committer | Alex Marsev <alex.marsev@gmail.com> | 2013-09-04 01:01:01 +0400 |
commit | 95fea6b284162e4235fb1aabdfb14d86d33c4d45 (patch) | |
tree | 61f315bfa0b807a90ba6f90e7b94219e7a40cbc0 /src | |
parent | 62ed8de61e8c6501be08bb2bda3e4aa6b03a9ad7 (diff) |
ShockwaveGraph: restore process volume on exit
Applies to Vista and later.
Fixes #2852
Diffstat (limited to 'src')
-rw-r--r-- | src/mpc-hc/ShockwaveGraph.cpp | 63 | ||||
-rw-r--r-- | src/mpc-hc/ShockwaveGraph.h | 5 |
2 files changed, 55 insertions, 13 deletions
diff --git a/src/mpc-hc/ShockwaveGraph.cpp b/src/mpc-hc/ShockwaveGraph.cpp index 2269741bc..7462b4fee 100644 --- a/src/mpc-hc/ShockwaveGraph.cpp +++ b/src/mpc-hc/ShockwaveGraph.cpp @@ -23,13 +23,16 @@ #include "ShockwaveGraph.h"
#include "resource.h"
#include "DSUtil.h"
+#include "SysVersion.h"
#include <math.h>
+#include <Audiopolicy.h>
+#include <Mmdeviceapi.h>
using namespace DSObjects;
-
CShockwaveGraph::CShockwaveGraph(HWND hParent, HRESULT& hr)
: m_fs(State_Stopped)
+ , m_fInitialVolume(1)
{
hr = S_OK;
@@ -45,12 +48,32 @@ CShockwaveGraph::CShockwaveGraph(HWND hParent, HRESULT& hr) return;
}
m_wndDestFrame.put_BackgroundColor(0);
+
+ if (SysVersion::IsVistaOrLater()) {
+ CComPtr<IMMDeviceEnumerator> pDeviceEnumerator;
+ if (SUCCEEDED(pDeviceEnumerator.CoCreateInstance(__uuidof(MMDeviceEnumerator)))) {
+ CComPtr<IMMDevice> pDevice;
+ if (SUCCEEDED(pDeviceEnumerator->GetDefaultAudioEndpoint(eRender, eConsole, &pDevice))) {
+ CComPtr<IAudioSessionManager> pSessionManager;
+ if (SUCCEEDED(pDevice->Activate(__uuidof(IAudioSessionManager), CLSCTX_ALL, nullptr,
+ reinterpret_cast<void**>(&pSessionManager)))) {
+ if (SUCCEEDED(pSessionManager->GetSimpleAudioVolume(nullptr, FALSE, &m_pSimpleVolume))) {
+ VERIFY(SUCCEEDED(m_pSimpleVolume->GetMasterVolume(&m_fInitialVolume)));
+ }
+ }
+ }
+ }
+ ASSERT(m_pSimpleVolume);
+ }
}
CShockwaveGraph::~CShockwaveGraph()
{
m_wndDestFrame.DestroyWindow();
m_wndWindowFrame.DestroyWindow();
+ if (m_pSimpleVolume) {
+ VERIFY(SUCCEEDED(m_pSimpleVolume->SetMasterVolume(m_fInitialVolume, nullptr)));
+ }
}
// IGraphBuilder
@@ -249,27 +272,43 @@ STDMETHODIMP CShockwaveGraph::GetVideoSize(long* pWidth, long* pHeight) // IBasicAudio
STDMETHODIMP CShockwaveGraph::put_Volume(long lVolume)
{
- lVolume = (lVolume <= -10000) ? 0 : (long)(pow(10.0, lVolume / 4000.0) * 100);
- lVolume = lVolume * 0x10000 / 100;
- lVolume = max(min(lVolume, 0xffff), 0);
- waveOutSetVolume(0, (lVolume << 16) | lVolume);
+ HRESULT hr = S_OK;
- return S_OK;
+ if (m_pSimpleVolume) {
+ float fVolume = (lVolume <= -10000) ? 0 : (lVolume >= 0) ? 1 : pow(10.f, lVolume / 4000.f);
+ hr = m_pSimpleVolume->SetMasterVolume(fVolume, nullptr);
+ } else {
+ lVolume = (lVolume <= -10000) ? 0 : (long)(pow(10.0, lVolume / 4000.0) * 100);
+ lVolume = lVolume * 0x10000 / 100;
+ lVolume = max(min(lVolume, 0xffff), 0);
+ waveOutSetVolume(0, (lVolume << 16) | lVolume);
+ }
+
+ return hr;
}
STDMETHODIMP CShockwaveGraph::get_Volume(long* plVolume)
{
CheckPointer(plVolume, E_POINTER);
+ HRESULT hr = S_OK;
- waveOutGetVolume(0, (DWORD*)plVolume);
- *plVolume = (*plVolume & 0xffff + ((*plVolume >> 16) & 0xffff)) / 2 * 100 / 0x10000;
- if (*plVolume > 0) {
- *plVolume = min((long)(4000 * log10(*plVolume / 100.0f)), 0);
+ if (m_pSimpleVolume) {
+ float fVolume;
+ hr = m_pSimpleVolume->GetMasterVolume(&fVolume);
+ if (SUCCEEDED(hr)) {
+ *plVolume = (fVolume == 0) ? -10000 : long(4000 * log10(fVolume));
+ }
} else {
- *plVolume = -10000;
+ waveOutGetVolume(0, (DWORD*)plVolume);
+ *plVolume = (*plVolume & 0xffff + ((*plVolume >> 16) & 0xffff)) / 2 * 100 / 0x10000;
+ if (*plVolume > 0) {
+ *plVolume = min((long)(4000 * log10(*plVolume / 100.0f)), 0);
+ } else {
+ *plVolume = -10000;
+ }
}
- return S_OK;
+ return hr;
}
// IAMOpenProgress
diff --git a/src/mpc-hc/ShockwaveGraph.h b/src/mpc-hc/ShockwaveGraph.h index 091df80f9..3998fc43d 100644 --- a/src/mpc-hc/ShockwaveGraph.h +++ b/src/mpc-hc/ShockwaveGraph.h @@ -23,7 +23,7 @@ #include "BaseGraph.h"
#include "CShockwaveFlash.h"
-
+#include <Audioclient.h>
namespace DSObjects
{
@@ -35,6 +35,9 @@ namespace DSObjects FILTER_STATE m_fs;
+ CComPtr<ISimpleAudioVolume> m_pSimpleVolume;
+ float m_fInitialVolume;
+
public:
CShockwaveGraph(HWND hParent, HRESULT& hr);
virtual ~CShockwaveGraph();
|