win-wasapi: Handle changes to the default monitoring device
Splits the WASAPINotify class out of win-wasapi.cpp and makes it a shared object in the plugin, then also creates a callback to reset audio monitoring if the default output device changes.
This commit is contained in:
parent
3b0ca4527a
commit
1d5d4b29e7
5 changed files with 214 additions and 64 deletions
|
|
@ -1,9 +1,12 @@
|
|||
#include "wasapi-notify.hpp"
|
||||
|
||||
#include <obs-module.h>
|
||||
|
||||
#include <util/windows/win-version.h>
|
||||
|
||||
OBS_DECLARE_MODULE()
|
||||
OBS_MODULE_USE_DEFAULT_LOCALE("win-wasapi", "en-US")
|
||||
|
||||
MODULE_EXPORT const char *obs_module_description(void)
|
||||
{
|
||||
return "Windows WASAPI audio input/output sources";
|
||||
|
|
@ -13,6 +16,26 @@ void RegisterWASAPIInput();
|
|||
void RegisterWASAPIDeviceOutput();
|
||||
void RegisterWASAPIProcessOutput();
|
||||
|
||||
WASAPINotify *notify = nullptr;
|
||||
|
||||
static void default_device_changed_callback(EDataFlow flow, ERole, LPCWSTR)
|
||||
{
|
||||
const char *id;
|
||||
obs_get_audio_monitoring_device(nullptr, &id);
|
||||
|
||||
if (!id || strcmp(id, "default") != 0)
|
||||
return;
|
||||
|
||||
if (flow != eRender)
|
||||
return;
|
||||
|
||||
auto task = [](void *) {
|
||||
obs_reset_audio_monitoring();
|
||||
};
|
||||
|
||||
obs_queue_task(OBS_TASK_UI, task, nullptr, false);
|
||||
}
|
||||
|
||||
bool obs_module_load(void)
|
||||
{
|
||||
/* MS says 20348, but process filtering seems to work earlier */
|
||||
|
|
@ -30,5 +53,23 @@ bool obs_module_load(void)
|
|||
RegisterWASAPIDeviceOutput();
|
||||
if (process_filter_supported)
|
||||
RegisterWASAPIProcessOutput();
|
||||
|
||||
notify = new WASAPINotify();
|
||||
notify->AddDefaultDeviceChangedCallback(
|
||||
obs_current_module(), default_device_changed_callback);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
void obs_module_unload(void)
|
||||
{
|
||||
if (notify) {
|
||||
delete notify;
|
||||
notify = nullptr;
|
||||
}
|
||||
}
|
||||
|
||||
WASAPINotify *GetNotify()
|
||||
{
|
||||
return notify;
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue