Browse Source

libobs: Add obs_source_info.filter_add

If there is filter_remove, it is reasonable to expect that there is also
filter_add. filter_add also enables filters to attach signal handlers
on the parent, and disconnect them in filter_remove.
CodeYan01 2 years ago
parent
commit
a494cf5ce4
3 changed files with 22 additions and 1 deletions
  1. 10 1
      docs/sphinx/reference-sources.rst
  2. 4 0
      libobs/obs-source.c
  3. 8 0
      libobs/obs-source.h

+ 10 - 1
docs/sphinx/reference-sources.rst

@@ -410,6 +410,15 @@ Source Definition Structure (obs_source_info)
    :param event:       Key event properties
    :param focus:       Key event type (true if mouse-up)
 
+.. member:: void (*obs_source_info.filter_add)(void *data, obs_source_t *source)
+
+   Called when the filter is added to a source.
+
+   (Optional)
+
+   :param  data:   Filter data
+   :param  source: Source that the filter is being added to
+
 .. member:: void (*obs_source_info.filter_remove)(void *data, obs_source_t *source)
 
    Called when the filter is removed from a source.
@@ -1547,7 +1556,7 @@ Filters
    reference.
 
    Only guaranteed to be valid inside of the video_render, filter_audio,
-   filter_video, and filter_remove callbacks.
+   filter_video, filter_add, and filter_remove callbacks.
 
 ---------------------
 

+ 4 - 0
libobs/obs-source.c

@@ -3132,6 +3132,10 @@ void obs_source_filter_add(obs_source_t *source, obs_source_t *filter)
 
 	blog(LOG_DEBUG, "- filter '%s' (%s) added to source '%s'",
 	     filter->context.name, filter->info.id, source->context.name);
+
+	if (filter->info.filter_add)
+		filter->info.filter_add(filter->context.data,
+					filter->filter_parent);
 }
 
 static bool obs_source_filter_remove_refless(obs_source_t *source,

+ 8 - 0
libobs/obs-source.h

@@ -552,6 +552,14 @@ struct obs_source_info {
 	enum gs_color_space (*video_get_color_space)(
 		void *data, size_t count,
 		const enum gs_color_space *preferred_spaces);
+
+	/**
+	 * Called when the filter is added to a source
+	 *
+	 * @param  data    Filter data
+	 * @param  source  Source that the filter is being added to
+	 */
+	void (*filter_add)(void *data, obs_source_t *source);
 };
 
 EXPORT void obs_register_source_s(const struct obs_source_info *info,