diff --git a/libobs/obs-scene.c b/libobs/obs-scene.c index b2a18f2c5..81824519f 100644 --- a/libobs/obs-scene.c +++ b/libobs/obs-scene.c @@ -467,7 +467,7 @@ const struct obs_source_info scene_info = .get_height = scene_getheight, .load = scene_load, .save = scene_save, - .enum_sources = scene_enum_sources + .enum_active_sources = scene_enum_sources }; obs_scene_t *obs_scene_create(const char *name) @@ -681,7 +681,7 @@ obs_sceneitem_t *obs_scene_add(obs_scene_t *scene, obs_source_t *source) return NULL; } - if (!obs_source_add_child(scene->source, source)) { + if (!obs_source_add_active_child(scene->source, source)) { blog(LOG_WARNING, "Failed to add source to scene due to " "infinite source recursion"); return NULL; @@ -772,7 +772,7 @@ void obs_sceneitem_remove(obs_sceneitem_t *item) assert(scene != NULL); assert(scene->source != NULL); - obs_source_remove_child(scene->source, item->source); + obs_source_remove_active_child(scene->source, item->source); signal_item_remove(item); detach_sceneitem(item); diff --git a/libobs/obs-source.c b/libobs/obs-source.c index b1cfb414a..032d669c7 100644 --- a/libobs/obs-source.c +++ b/libobs/obs-source.c @@ -737,12 +737,13 @@ void obs_source_activate(obs_source_t *source, enum view_type type) return; if (os_atomic_inc_long(&source->show_refs) == 1) { - obs_source_enum_tree(source, show_tree, NULL); + obs_source_enum_active_tree(source, show_tree, NULL); } if (type == MAIN_VIEW) { if (os_atomic_inc_long(&source->activate_refs) == 1) { - obs_source_enum_tree(source, activate_tree, NULL); + obs_source_enum_active_tree(source, activate_tree, + NULL); } } } @@ -753,12 +754,13 @@ void obs_source_deactivate(obs_source_t *source, enum view_type type) return; if (os_atomic_dec_long(&source->show_refs) == 0) { - obs_source_enum_tree(source, hide_tree, NULL); + obs_source_enum_active_tree(source, hide_tree, NULL); } if (type == MAIN_VIEW) { if (os_atomic_dec_long(&source->activate_refs) == 0) { - obs_source_enum_tree(source, deactivate_tree, NULL); + obs_source_enum_active_tree(source, deactivate_tree, + NULL); } } } @@ -2585,9 +2587,9 @@ static void enum_source_tree_callback(obs_source_t *parent, obs_source_t *child, { struct source_enum_data *data = param; - if (child->info.enum_sources) { + if (child->info.enum_active_sources) { if (child->context.data) { - child->info.enum_sources(child->context.data, + child->info.enum_active_sources(child->context.data, enum_source_tree_callback, data); } } @@ -2595,36 +2597,37 @@ static void enum_source_tree_callback(obs_source_t *parent, obs_source_t *child, data->enum_callback(parent, child, data->param); } -void obs_source_enum_sources(obs_source_t *source, +void obs_source_enum_active_sources(obs_source_t *source, obs_source_enum_proc_t enum_callback, void *param) { - if (!data_valid(source, "obs_source_enum_sources")) + if (!data_valid(source, "obs_source_enum_active_sources")) return; - if (!source->info.enum_sources) + if (!source->info.enum_active_sources) return; obs_source_addref(source); - source->info.enum_sources(source->context.data, enum_callback, param); + source->info.enum_active_sources(source->context.data, enum_callback, + param); obs_source_release(source); } -void obs_source_enum_tree(obs_source_t *source, +void obs_source_enum_active_tree(obs_source_t *source, obs_source_enum_proc_t enum_callback, void *param) { struct source_enum_data data = {enum_callback, param}; - if (!data_valid(source, "obs_source_enum_tree")) + if (!data_valid(source, "obs_source_enum_active_tree")) return; - if (!source->info.enum_sources) + if (!source->info.enum_active_sources) return; obs_source_addref(source); - source->info.enum_sources(source->context.data, + source->info.enum_active_sources(source->context.data, enum_source_tree_callback, &data); @@ -2644,20 +2647,21 @@ static void check_descendant(obs_source_t *parent, obs_source_t *child, info->exists = true; } -bool obs_source_add_child(obs_source_t *parent, obs_source_t *child) +bool obs_source_add_active_child(obs_source_t *parent, obs_source_t *child) { struct descendant_info info = {false, parent}; - if (!obs_ptr_valid(parent, "obs_source_add_child")) + if (!obs_ptr_valid(parent, "obs_source_add_active_child")) return false; - if (!obs_ptr_valid(parent, "obs_source_add_child")) + if (!obs_ptr_valid(child, "obs_source_add_active_child")) return false; if (parent == child) { - blog(LOG_WARNING, "obs_source_add_child: parent == child"); + blog(LOG_WARNING, "obs_source_add_active_child: " + "parent == child"); return false; } - obs_source_enum_tree(child, check_descendant, &info); + obs_source_enum_active_tree(child, check_descendant, &info); if (info.exists) return false; @@ -2670,11 +2674,11 @@ bool obs_source_add_child(obs_source_t *parent, obs_source_t *child) return true; } -void obs_source_remove_child(obs_source_t *parent, obs_source_t *child) +void obs_source_remove_active_child(obs_source_t *parent, obs_source_t *child) { - if (!obs_ptr_valid(parent, "obs_source_remove_child")) + if (!obs_ptr_valid(parent, "obs_source_remove_active_child")) return; - if (!obs_ptr_valid(parent, "obs_source_remove_child")) + if (!obs_ptr_valid(child, "obs_source_remove_active_child")) return; for (int i = 0; i < parent->show_refs; i++) { @@ -2918,8 +2922,8 @@ float obs_source_get_target_volume(obs_source_t *source, obs_source_t *target) if (source == target) return 1.0f; - if (source->info.enum_sources) { - source->info.enum_sources(source->context.data, + if (source->info.enum_active_sources) { + source->info.enum_active_sources(source->context.data, transition ? get_transition_child_vol : get_source_base_vol, diff --git a/libobs/obs-source.h b/libobs/obs-source.h index 74898bce5..577ce2d9f 100644 --- a/libobs/obs-source.h +++ b/libobs/obs-source.h @@ -271,14 +271,15 @@ struct obs_source_info { struct obs_audio_data *audio); /** - * Called to enumerate all sources being used within this source. - * If the source has children it must implement this callback. + * Called to enumerate all active sources being used within this + * source. If the source has children that render audio/video it must + * implement this callback. * * @param data Filter data * @param enum_callback Enumeration callback * @param param User data to pass to callback */ - void (*enum_sources)(void *data, + void (*enum_active_sources)(void *data, obs_source_enum_proc_t enum_callback, void *param); diff --git a/libobs/obs.h b/libobs/obs.h index 99da46e51..c2cf70426 100644 --- a/libobs/obs.h +++ b/libobs/obs.h @@ -773,13 +773,13 @@ EXPORT void obs_source_set_sync_offset(obs_source_t *source, int64_t offset); /** Gets the audio sync offset (in nanoseconds) for a source */ EXPORT int64_t obs_source_get_sync_offset(const obs_source_t *source); -/** Enumerates child sources used by this source */ -EXPORT void obs_source_enum_sources(obs_source_t *source, +/** Enumerates active child sources used by this source */ +EXPORT void obs_source_enum_active_sources(obs_source_t *source, obs_source_enum_proc_t enum_callback, void *param); -/** Enumerates the entire child source tree used by this source */ -EXPORT void obs_source_enum_tree(obs_source_t *source, +/** Enumerates the entire active child source tree used by this source */ +EXPORT void obs_source_enum_active_tree(obs_source_t *source, obs_source_enum_proc_t enum_callback, void *param); @@ -953,20 +953,22 @@ EXPORT void obs_source_process_filter_end(obs_source_t *filter, EXPORT void obs_source_skip_video_filter(obs_source_t *filter); /** - * Adds a child source. Must be called by parent sources on child sources - * when the child is added. This ensures that the source is properly activated - * if the parent is active. + * Adds an active child source. Must be called by parent sources on child + * sources when the child is added and active. This ensures that the source is + * properly activated if the parent is active. * * @returns true if source can be added, false if it causes recursion */ -EXPORT bool obs_source_add_child(obs_source_t *parent, obs_source_t *child); +EXPORT bool obs_source_add_active_child(obs_source_t *parent, + obs_source_t *child); /** - * Removes a child source. Must be called by parent sources on child sources - * when the child is removed. This ensures that the source is properly - * deactivated if the parent is active. + * Removes an active child source. Must be called by parent sources on child + * sources when the child is removed or inactive. This ensures that the source + * is properly deactivated if the parent is no longer active. */ -EXPORT void obs_source_remove_child(obs_source_t *parent, obs_source_t *child); +EXPORT void obs_source_remove_active_child(obs_source_t *parent, + obs_source_t *child); /** Sends a mouse down/up event to a source */ EXPORT void obs_source_send_mouse_click(obs_source_t *source,