|
34 | 34 |
|
35 | 35 | struct background_removal_filter : public filter_data, public std::enable_shared_from_this<background_removal_filter> { |
36 | 36 | bool enableThreshold = true; |
| 37 | + bool stopWhenSourceIsInactive = true; |
37 | 38 | float threshold = 0.5f; |
38 | 39 | cv::Scalar backgroundColor{0, 0, 0, 0}; |
39 | 40 | float contourFilter = 0.05f; |
@@ -127,6 +128,9 @@ obs_properties_t *background_filter_properties(void *data) |
127 | 128 |
|
128 | 129 | obs_property_t *advanced = obs_properties_add_bool(props, "advanced", obs_module_text("Advanced")); |
129 | 130 |
|
| 131 | + obs_properties_add_bool(props, "stop_when_source_is_inactive", |
| 132 | + obs_module_text("Stop filter when source is inactive")); |
| 133 | + |
130 | 134 | // If advanced is selected show the advanced settings, otherwise hide them |
131 | 135 | obs_property_set_modified_callback(advanced, enable_advanced_settings); |
132 | 136 |
|
@@ -236,6 +240,7 @@ obs_properties_t *background_filter_properties(void *data) |
236 | 240 | void background_filter_defaults(obs_data_t *settings) |
237 | 241 | { |
238 | 242 | obs_data_set_default_bool(settings, "advanced", false); |
| 243 | + obs_data_set_default_bool(settings, "stop_when_source_is_inactive", true); |
239 | 244 | obs_data_set_default_bool(settings, "enable_threshold", true); |
240 | 245 | obs_data_set_default_double(settings, "threshold", 0.5); |
241 | 246 | obs_data_set_default_double(settings, "contour_filter", 0.05); |
@@ -277,6 +282,7 @@ void background_filter_update(void *data, obs_data_t *settings) |
277 | 282 |
|
278 | 283 | tf->isDisabled = true; |
279 | 284 |
|
| 285 | + tf->stopWhenSourceIsInactive = obs_data_get_bool(settings, "stop_when_source_is_inactive"); |
280 | 286 | tf->enableThreshold = (float)obs_data_get_bool(settings, "enable_threshold"); |
281 | 287 | tf->threshold = (float)obs_data_get_double(settings, "threshold"); |
282 | 288 |
|
@@ -390,30 +396,28 @@ void background_filter_update(void *data, obs_data_t *settings) |
390 | 396 |
|
391 | 397 | void background_filter_activate(void *data) |
392 | 398 | { |
393 | | - obs_log(LOG_INFO, "Background filter activated"); |
394 | | - |
395 | 399 | auto *ptr = static_cast<std::shared_ptr<background_removal_filter> *>(data); |
396 | 400 | if (!ptr) { |
397 | 401 | return; |
398 | 402 | } |
399 | 403 |
|
400 | 404 | std::shared_ptr<background_removal_filter> tf = *ptr; |
401 | | - if (tf) { |
| 405 | + if (tf && tf->stopWhenSourceIsInactive) { |
| 406 | + obs_log(LOG_INFO, "Background filter activated"); |
402 | 407 | tf->isDisabled = false; |
403 | 408 | } |
404 | 409 | } |
405 | 410 |
|
406 | 411 | void background_filter_deactivate(void *data) |
407 | 412 | { |
408 | | - obs_log(LOG_INFO, "Background filter deactivated"); |
409 | | - |
410 | 413 | auto *ptr = static_cast<std::shared_ptr<background_removal_filter> *>(data); |
411 | 414 | if (!ptr) { |
412 | 415 | return; |
413 | 416 | } |
414 | 417 |
|
415 | 418 | std::shared_ptr<background_removal_filter> tf = *ptr; |
416 | | - if (tf) { |
| 419 | + if (tf && tf->stopWhenSourceIsInactive) { |
| 420 | + obs_log(LOG_INFO, "Background filter deactivated"); |
417 | 421 | tf->isDisabled = true; |
418 | 422 | } |
419 | 423 | } |
|
0 commit comments