mirror of
https://github.com/obsproject/obs-studio.git
synced 2026-09-19 09:41:32 +08:00
UI: Add option to disable audio ducking on windows
The audio subsystem of windows is by default configured to lower the volume of other things while a communications device (mic) is currently active. This patch prevents that from being enabled with OBS. If the user needs audio ducking enabled again for whatever reason, there is now an option to re-enable it in advanced settings. Closes jp9000/obs-studio#884
This commit is contained in:
@@ -30,6 +30,11 @@ using namespace std;
|
||||
#include <shellapi.h>
|
||||
#include <shlobj.h>
|
||||
#include <Dwmapi.h>
|
||||
#include <mmdeviceapi.h>
|
||||
#include <audiopolicy.h>
|
||||
|
||||
#include <util/windows/HRError.hpp>
|
||||
#include <util/windows/ComPtr.hpp>
|
||||
|
||||
static inline bool check_path(const char* data, const char *path,
|
||||
string &output)
|
||||
@@ -216,3 +221,41 @@ void SetWin32DropStyle(QWidget *window)
|
||||
ex_style |= WS_EX_ACCEPTFILES;
|
||||
SetWindowLongPtr(hwnd, GWL_EXSTYLE, ex_style);
|
||||
}
|
||||
|
||||
bool DisableAudioDucking(bool disable)
|
||||
{
|
||||
ComPtr<IMMDeviceEnumerator> devEmum;
|
||||
ComPtr<IMMDevice> device;
|
||||
ComPtr<IAudioSessionManager2> sessionManager2;
|
||||
ComPtr<IAudioSessionControl> sessionControl;
|
||||
ComPtr<IAudioSessionControl2> sessionControl2;
|
||||
|
||||
HRESULT result = CoCreateInstance(__uuidof(MMDeviceEnumerator),
|
||||
nullptr, CLSCTX_INPROC_SERVER,
|
||||
__uuidof(IMMDeviceEnumerator),
|
||||
(void **)&devEmum);
|
||||
if (FAILED(result))
|
||||
return false;
|
||||
|
||||
result = devEmum->GetDefaultAudioEndpoint(eRender, eConsole, &device);
|
||||
if (FAILED(result))
|
||||
return false;
|
||||
|
||||
result = device->Activate(__uuidof(IAudioSessionManager2),
|
||||
CLSCTX_INPROC_SERVER, nullptr,
|
||||
(void **)&sessionManager2);
|
||||
if (FAILED(result))
|
||||
return false;
|
||||
|
||||
result = sessionManager2->GetAudioSessionControl(nullptr, 0,
|
||||
&sessionControl);
|
||||
if (FAILED(result))
|
||||
return false;
|
||||
|
||||
result = sessionControl->QueryInterface(&sessionControl2);
|
||||
if (FAILED(result))
|
||||
return false;
|
||||
|
||||
result = sessionControl2->SetDuckingPreference(disable);
|
||||
return SUCCEEDED(result);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user