From e460dfeb83eb047c84e646a75e783835b88231d6 Mon Sep 17 00:00:00 2001 From: jp9000 Date: Sun, 3 Apr 2016 15:55:15 -0700 Subject: [PATCH] win-dshow: Add 'deactivate when not showing' option Useful for two purposes: 1.) When many devices are hooked up to the system and used in separate scenes, but only one device active at once is desired 2.) Allows users who are dependent on outputting audio to desktop to disable that audio (via disabling that device) when the device isn't being displayed --- plugins/win-dshow/data/locale/en-US.ini | 1 + plugins/win-dshow/win-dshow.cpp | 24 ++++++++++++++++++++++++ 2 files changed, 25 insertions(+) diff --git a/plugins/win-dshow/data/locale/en-US.ini b/plugins/win-dshow/data/locale/en-US.ini index 340d729c8..dca867eb1 100644 --- a/plugins/win-dshow/data/locale/en-US.ini +++ b/plugins/win-dshow/data/locale/en-US.ini @@ -31,6 +31,7 @@ Buffering.Disable="Disable" Activate="Activate" Deactivate="Deactivate" FlipVertically="Flip Vertically" +DeactivateWhenNotShowing="Deactivate when not showing" # encoder text Bitrate="Bitrate" diff --git a/plugins/win-dshow/win-dshow.cpp b/plugins/win-dshow/win-dshow.cpp index 7816073f6..4944398cc 100644 --- a/plugins/win-dshow/win-dshow.cpp +++ b/plugins/win-dshow/win-dshow.cpp @@ -43,6 +43,7 @@ using namespace DShow; #define AUDIO_DEVICE_ID "audio_device_id" #define COLOR_SPACE "color_space" #define COLOR_RANGE "color_range" +#define DEACTIVATE_WNS "deactivate_when_not_showing" #define TEXT_INPUT_NAME obs_module_text("VideoCaptureDevice") #define TEXT_DEVICE obs_module_text("Device") @@ -74,6 +75,7 @@ using namespace DShow; #define TEXT_COLOR_RANGE obs_module_text("ColorRange") #define TEXT_RANGE_PARTIAL obs_module_text("ColorRange.Partial") #define TEXT_RANGE_FULL obs_module_text("ColorRange.Full") +#define TEXT_DWNS obs_module_text("DeactivateWhenNotShowing") enum ResType { ResType_Preferred, @@ -160,6 +162,7 @@ static DWORD CALLBACK DShowThread(LPVOID ptr); struct DShowInput { obs_source_t *source; Device device; + bool deactivateWhenNotShowing = false; bool deviceHasAudio = false; bool flip = false; bool active = false; @@ -747,6 +750,7 @@ static DStr GetVideoFormatName(VideoFormat format); bool DShowInput::UpdateVideoConfig(obs_data_t *settings) { string video_device_id = obs_data_get_string(settings, VIDEO_DEVICE_ID); + deactivateWhenNotShowing = obs_data_get_bool(settings, DEACTIVATE_WNS); flip = obs_data_get_bool(settings, FLIP_IMAGE); DeviceId id; @@ -1742,6 +1746,8 @@ static obs_properties_t *GetDShowProperties(void *obj) obs_properties_add_button(ppts, "xbar_config", TEXT_CONFIG_XBAR, CrossbarConfigClicked); + obs_properties_add_bool(ppts, DEACTIVATE_WNS, TEXT_DWNS); + /* ------------------------------------- */ /* video settings */ @@ -1838,6 +1844,22 @@ void DShowModuleLogCallback(LogType type, const wchar_t *msg, void *param) UNUSED_PARAMETER(param); } +static void HideDShowInput(void *data) +{ + DShowInput *input = reinterpret_cast(data); + + if (input->deactivateWhenNotShowing && input->active) + input->QueueAction(Action::Deactivate); +} + +static void ShowDShowInput(void *data) +{ + DShowInput *input = reinterpret_cast(data); + + if (input->deactivateWhenNotShowing && input->active) + input->QueueAction(Action::Activate); +} + void RegisterDShowSource() { SetLogCallback(DShowModuleLogCallback, nullptr); @@ -1849,6 +1871,8 @@ void RegisterDShowSource() OBS_SOURCE_AUDIO | OBS_SOURCE_ASYNC | OBS_SOURCE_DO_NOT_DUPLICATE; + info.show = ShowDShowInput; + info.hide = HideDShowInput; info.get_name = GetDShowInputName; info.create = CreateDShowInput; info.destroy = DestroyDShowInput;