From aee84cc743621a46b4f4e1bdf2522c93b4dfa868 Mon Sep 17 00:00:00 2001 From: jp9000 Date: Fri, 26 Jul 2019 00:02:31 -0700 Subject: [PATCH] libobs: Add "monitoring by default" source cap (This also modifies the UI module) Adds the ability for a source to monitor by default. This is mainly aimed at browser sources, so that they do not stop outputting audio by default like they used to. --- UI/window-basic-source-select.cpp | 8 ++++++++ libobs/obs-source.h | 6 ++++++ libobs/obs.c | 15 +++++++++++++++ 3 files changed, 29 insertions(+) diff --git a/UI/window-basic-source-select.cpp b/UI/window-basic-source-select.cpp index b5d14b301..b7dba9792 100644 --- a/UI/window-basic-source-select.cpp +++ b/UI/window-basic-source-select.cpp @@ -197,6 +197,14 @@ bool AddNew(QWidget *parent, const char *id, const char *name, newSource = source; + /* set monitoring if source monitors by default */ + uint32_t flags = obs_source_get_output_flags(source); + if ((flags & OBS_SOURCE_MONITOR_BY_DEFAULT) != 0) { + obs_source_set_monitoring_type( + source, + OBS_MONITORING_TYPE_MONITOR_ONLY); + } + success = true; } } diff --git a/libobs/obs-source.h b/libobs/obs-source.h index b328e1252..34a1efec5 100644 --- a/libobs/obs-source.h +++ b/libobs/obs-source.h @@ -139,6 +139,12 @@ enum obs_balance_type { */ #define OBS_SOURCE_CAP_DISABLED (1 << 10) +/** + * Source should enable monitoring by default. Monitoring should be set by the + * frontend if this flag is set. + */ +#define OBS_SOURCE_MONITOR_BY_DEFAULT (1 << 11) + /** @} */ typedef void (*obs_source_enum_proc_t)(obs_source_t *parent, diff --git a/libobs/obs.c b/libobs/obs.c index e3d084798..1d33fcfb1 100644 --- a/libobs/obs.c +++ b/libobs/obs.c @@ -1733,6 +1733,8 @@ static obs_source_t *obs_load_source_type(obs_data_t *source_data) double volume; double balance; int64_t sync; + uint32_t prev_ver; + uint32_t caps; uint32_t flags; uint32_t mixers; int di_order; @@ -1743,6 +1745,9 @@ static obs_source_t *obs_load_source_type(obs_data_t *source_data) obs_data_release(hotkeys); + prev_ver = (uint32_t)obs_data_get_int(source_data, "prev_ver"); + caps = obs_source_get_output_flags(source); + obs_data_set_default_double(source_data, "volume", 1.0); volume = obs_data_get_double(source_data, "volume"); obs_source_set_volume(source, (float)volume); @@ -1795,6 +1800,14 @@ static obs_source_t *obs_load_source_type(obs_data_t *source_data) source, (enum obs_deinterlace_field_order)di_order); monitoring_type = (int)obs_data_get_int(source_data, "monitoring_type"); + if (prev_ver < MAKE_SEMANTIC_VERSION(24, 0, 0)) { + if ((caps & OBS_SOURCE_MONITOR_BY_DEFAULT) != 0) { + /* updates older sources to enable monitoring + * automatically if they added monitoring by default in + * version 24 */ + monitoring_type = OBS_MONITORING_TYPE_MONITOR_ONLY; + } + } obs_source_set_monitoring_type( source, (enum obs_monitoring_type)monitoring_type); @@ -1921,6 +1934,8 @@ obs_data_t *obs_save_source(obs_source_t *source) hotkey_data = hotkeys; } + obs_data_set_int(source_data, "prev_ver", LIBOBS_API_VER); + obs_data_set_string(source_data, "name", name); obs_data_set_string(source_data, "id", id); obs_data_set_obj(source_data, "settings", settings);