Просмотр исходного кода

libobs: Add ability to disable source types

Because it would be troublesome to add the ability to remove source
types (in case for example a script fails to reload), instead make it so
source types can be temporarily disabled while the program is running.
jp9000 7 лет назад
Родитель
Сommit
a730f9d6ce
3 измененных файлов с 20 добавлено и 2 удалено
  1. 1 1
      libobs/obs-internal.h
  2. 14 1
      libobs/obs-source.c
  3. 5 0
      libobs/obs-source.h

+ 1 - 1
libobs/obs-internal.h

@@ -691,7 +691,7 @@ struct obs_source {
 	obs_data_t                      *private_settings;
 	obs_data_t                      *private_settings;
 };
 };
 
 
-extern const struct obs_source_info *get_source_info(const char *id);
+extern struct obs_source_info *get_source_info(const char *id);
 extern bool obs_source_init_context(struct obs_source *source,
 extern bool obs_source_init_context(struct obs_source *source,
 		obs_data_t *settings, const char *name,
 		obs_data_t *settings, const char *name,
 		obs_data_t *hotkey_data, bool private);
 		obs_data_t *hotkey_data, bool private);

+ 14 - 1
libobs/obs-source.c

@@ -39,7 +39,7 @@ static inline bool deinterlacing_enabled(const struct obs_source *source)
 	return source->deinterlace_mode != OBS_DEINTERLACE_MODE_DISABLE;
 	return source->deinterlace_mode != OBS_DEINTERLACE_MODE_DISABLE;
 }
 }
 
 
-const struct obs_source_info *get_source_info(const char *id)
+struct obs_source_info *get_source_info(const char *id)
 {
 {
 	for (size_t i = 0; i < obs->source_types.num; i++) {
 	for (size_t i = 0; i < obs->source_types.num; i++) {
 		struct obs_source_info *info = &obs->source_types.array[i];
 		struct obs_source_info *info = &obs->source_types.array[i];
@@ -4115,3 +4115,16 @@ bool obs_source_async_decoupled(const obs_source_t *source)
 	return obs_source_valid(source, "obs_source_async_decoupled") ?
 	return obs_source_valid(source, "obs_source_async_decoupled") ?
 		source->async_decoupled : false;
 		source->async_decoupled : false;
 }
 }
+
+/* hidden/undocumented export to allow source type redefinition for scripts */
+EXPORT void obs_enable_source_type(const char *name, bool enable)
+{
+	struct obs_source_info *info = get_source_info(name);
+	if (!info)
+		return;
+
+	if (enable)
+		info->output_flags &= ~OBS_SOURCE_CAP_DISABLED;
+	else
+		info->output_flags |= OBS_SOURCE_CAP_DISABLED;
+}

+ 5 - 0
libobs/obs-source.h

@@ -130,6 +130,11 @@ enum obs_source_type {
  */
  */
 #define OBS_SOURCE_DO_NOT_SELF_MONITOR (1<<9)
 #define OBS_SOURCE_DO_NOT_SELF_MONITOR (1<<9)
 
 
+/**
+ * Source type is currently disabled and should not be shown to the user
+ */
+#define OBS_SOURCE_CAP_DISABLED (1<<10)
+
 /** @} */
 /** @} */
 
 
 typedef void (*obs_source_enum_proc_t)(obs_source_t *parent,
 typedef void (*obs_source_enum_proc_t)(obs_source_t *parent,