From c36a5ae92b32d7b8401c468c7f20fabeb05d775f Mon Sep 17 00:00:00 2001 From: gxalpha Date: Sun, 7 Nov 2021 12:51:41 +0100 Subject: [PATCH] libobs: Add obs_get_transition_by_name --- docs/sphinx/reference-core.rst | 9 +++++++++ libobs/obs.c | 21 +++++++++++++++++++++ libobs/obs.h | 3 +++ 3 files changed, 33 insertions(+) diff --git a/docs/sphinx/reference-core.rst b/docs/sphinx/reference-core.rst index 31a61aae6..3d246851e 100644 --- a/docs/sphinx/reference-core.rst +++ b/docs/sphinx/reference-core.rst @@ -262,6 +262,15 @@ Libobs Objects --------------------- +.. function:: obs_source_t *obs_get_transition_by_name(const char *name) + + Gets a transition by its name. + + Increments the source reference counter, use + :c:func:`obs_source_release()` to release it when complete. + +--------------------- + .. function:: obs_output_t *obs_get_output_by_name(const char *name) Gets an output by its name. diff --git a/libobs/obs.c b/libobs/obs.c index d62e729cf..1c2a714f7 100644 --- a/libobs/obs.c +++ b/libobs/obs.c @@ -1593,6 +1593,27 @@ obs_source_t *obs_get_source_by_name(const char *name) obs_source_addref_safe_); } +obs_source_t *obs_get_transition_by_name(const char *name) +{ + struct obs_source **first = &obs->data.first_source; + struct obs_source *source; + + pthread_mutex_lock(&obs->data.sources_mutex); + + source = *first; + while (source) { + if (source->info.type == OBS_SOURCE_TYPE_TRANSITION && + strcmp(source->context.name, name) == 0) { + source = obs_source_addref_safe_(source); + break; + } + source = (void *)source->context.next; + } + + pthread_mutex_unlock(&obs->data.sources_mutex); + return source; +} + obs_output_t *obs_get_output_by_name(const char *name) { return get_context_by_name(&obs->data.first_output, name, diff --git a/libobs/obs.h b/libobs/obs.h index 4f015130f..da7e4dd4e 100644 --- a/libobs/obs.h +++ b/libobs/obs.h @@ -636,6 +636,9 @@ EXPORT void obs_enum_services(bool (*enum_proc)(void *, obs_service_t *), */ EXPORT obs_source_t *obs_get_source_by_name(const char *name); +/** Get a transition source by its name. */ +EXPORT obs_source_t *obs_get_transition_by_name(const char *name); + /** Gets an output by its name. */ EXPORT obs_output_t *obs_get_output_by_name(const char *name);