Skip to content

Commit 39883a1

Browse files
sobalapmen232
andauthored
Add an option to keep the filter enabled when scene becomes inactive (#747)
* Add Keep Alive property to background filter This property ensures that the background filter remains active even after switching to another scene in OBS * run clang-format on src/background-filter.cpp * run clang-format on src/background-filter.cpp * Invert the keepalive property logic * Run clang-format on background-filter.cpp --------- Co-authored-by: Andrew L <[email protected]>
1 parent 84b864d commit 39883a1

File tree

1 file changed

+10
-6
lines changed

1 file changed

+10
-6
lines changed

src/background-filter.cpp

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@
3434

3535
struct background_removal_filter : public filter_data, public std::enable_shared_from_this<background_removal_filter> {
3636
bool enableThreshold = true;
37+
bool stopWhenSourceIsInactive = true;
3738
float threshold = 0.5f;
3839
cv::Scalar backgroundColor{0, 0, 0, 0};
3940
float contourFilter = 0.05f;
@@ -127,6 +128,9 @@ obs_properties_t *background_filter_properties(void *data)
127128

128129
obs_property_t *advanced = obs_properties_add_bool(props, "advanced", obs_module_text("Advanced"));
129130

131+
obs_properties_add_bool(props, "stop_when_source_is_inactive",
132+
obs_module_text("Stop filter when source is inactive"));
133+
130134
// If advanced is selected show the advanced settings, otherwise hide them
131135
obs_property_set_modified_callback(advanced, enable_advanced_settings);
132136

@@ -236,6 +240,7 @@ obs_properties_t *background_filter_properties(void *data)
236240
void background_filter_defaults(obs_data_t *settings)
237241
{
238242
obs_data_set_default_bool(settings, "advanced", false);
243+
obs_data_set_default_bool(settings, "stop_when_source_is_inactive", true);
239244
obs_data_set_default_bool(settings, "enable_threshold", true);
240245
obs_data_set_default_double(settings, "threshold", 0.5);
241246
obs_data_set_default_double(settings, "contour_filter", 0.05);
@@ -277,6 +282,7 @@ void background_filter_update(void *data, obs_data_t *settings)
277282

278283
tf->isDisabled = true;
279284

285+
tf->stopWhenSourceIsInactive = obs_data_get_bool(settings, "stop_when_source_is_inactive");
280286
tf->enableThreshold = (float)obs_data_get_bool(settings, "enable_threshold");
281287
tf->threshold = (float)obs_data_get_double(settings, "threshold");
282288

@@ -390,30 +396,28 @@ void background_filter_update(void *data, obs_data_t *settings)
390396

391397
void background_filter_activate(void *data)
392398
{
393-
obs_log(LOG_INFO, "Background filter activated");
394-
395399
auto *ptr = static_cast<std::shared_ptr<background_removal_filter> *>(data);
396400
if (!ptr) {
397401
return;
398402
}
399403

400404
std::shared_ptr<background_removal_filter> tf = *ptr;
401-
if (tf) {
405+
if (tf && tf->stopWhenSourceIsInactive) {
406+
obs_log(LOG_INFO, "Background filter activated");
402407
tf->isDisabled = false;
403408
}
404409
}
405410

406411
void background_filter_deactivate(void *data)
407412
{
408-
obs_log(LOG_INFO, "Background filter deactivated");
409-
410413
auto *ptr = static_cast<std::shared_ptr<background_removal_filter> *>(data);
411414
if (!ptr) {
412415
return;
413416
}
414417

415418
std::shared_ptr<background_removal_filter> tf = *ptr;
416-
if (tf) {
419+
if (tf && tf->stopWhenSourceIsInactive) {
420+
obs_log(LOG_INFO, "Background filter deactivated");
417421
tf->isDisabled = true;
418422
}
419423
}

0 commit comments

Comments
 (0)