Jelajahi Sumber

libobs: Add obs_source_get_filter_by_name function

jp9000 10 tahun lalu
induk
melakukan
50a36f45cd
2 mengubah file dengan 28 tambahan dan 0 penghapusan
  1. 24 0
      libobs/obs-source.c
  2. 4 0
      libobs/obs.h

+ 24 - 0
libobs/obs-source.c

@@ -2451,3 +2451,27 @@ void obs_source_enum_filters(obs_source_t *source,
 
 	pthread_mutex_unlock(&source->filter_mutex);
 }
+
+obs_source_t *obs_source_get_filter_by_name(obs_source_t *source,
+		const char *name)
+{
+	obs_source_t *filter = NULL;
+
+	if (!source || !name)
+		return NULL;
+
+	pthread_mutex_lock(&source->filter_mutex);
+
+	for (size_t i = 0; i < source->filters.num; i++) {
+		struct obs_source *cur_filter = source->filters.array[i];
+		if (strcmp(cur_filter->context.name, name) == 0) {
+			filter = cur_filter;
+			obs_source_addref(filter);
+			break;
+		}
+	}
+
+	pthread_mutex_unlock(&source->filter_mutex);
+
+	return filter;
+}

+ 4 - 0
libobs/obs.h

@@ -798,6 +798,10 @@ EXPORT void obs_source_dec_showing(obs_source_t *source);
 EXPORT void obs_source_enum_filters(obs_source_t *source,
 		obs_source_enum_proc_t callback, void *param);
 
+/** Gets a filter of a source by its display name. */
+EXPORT obs_source_t *obs_source_get_filter_by_name(obs_source_t *source,
+		const char *name);
+
 /* ------------------------------------------------------------------------- */
 /* Functions used by sources */