diff --git a/src/background-filter.cpp b/src/background-filter.cpp index 908c2c90..5199f347 100644 --- a/src/background-filter.cpp +++ b/src/background-filter.cpp @@ -34,6 +34,7 @@ struct background_removal_filter : public filter_data, public std::enable_shared_from_this { bool enableThreshold = true; + bool stopWhenSourceIsInactive = true; float threshold = 0.5f; cv::Scalar backgroundColor{0, 0, 0, 0}; float contourFilter = 0.05f; @@ -127,6 +128,9 @@ obs_properties_t *background_filter_properties(void *data) obs_property_t *advanced = obs_properties_add_bool(props, "advanced", obs_module_text("Advanced")); + obs_properties_add_bool(props, "stop_when_source_is_inactive", + obs_module_text("Stop filter when source is inactive")); + // If advanced is selected show the advanced settings, otherwise hide them obs_property_set_modified_callback(advanced, enable_advanced_settings); @@ -236,6 +240,7 @@ obs_properties_t *background_filter_properties(void *data) void background_filter_defaults(obs_data_t *settings) { obs_data_set_default_bool(settings, "advanced", false); + obs_data_set_default_bool(settings, "stop_when_source_is_inactive", true); obs_data_set_default_bool(settings, "enable_threshold", true); obs_data_set_default_double(settings, "threshold", 0.5); obs_data_set_default_double(settings, "contour_filter", 0.05); @@ -277,6 +282,7 @@ void background_filter_update(void *data, obs_data_t *settings) tf->isDisabled = true; + tf->stopWhenSourceIsInactive = obs_data_get_bool(settings, "stop_when_source_is_inactive"); tf->enableThreshold = (float)obs_data_get_bool(settings, "enable_threshold"); tf->threshold = (float)obs_data_get_double(settings, "threshold"); @@ -390,30 +396,28 @@ void background_filter_update(void *data, obs_data_t *settings) void background_filter_activate(void *data) { - obs_log(LOG_INFO, "Background filter activated"); - auto *ptr = static_cast *>(data); if (!ptr) { return; } std::shared_ptr tf = *ptr; - if (tf) { + if (tf && tf->stopWhenSourceIsInactive) { + obs_log(LOG_INFO, "Background filter activated"); tf->isDisabled = false; } } void background_filter_deactivate(void *data) { - obs_log(LOG_INFO, "Background filter deactivated"); - auto *ptr = static_cast *>(data); if (!ptr) { return; } std::shared_ptr tf = *ptr; - if (tf) { + if (tf && tf->stopWhenSourceIsInactive) { + obs_log(LOG_INFO, "Background filter deactivated"); tf->isDisabled = true; } }