From c9bb03e6d51010ad0bb0d006fa635421f85a171d Mon Sep 17 00:00:00 2001 From: Clayton Groeneveld Date: Thu, 14 May 2020 00:58:18 -0500 Subject: [PATCH] libobs: Add dsk scene type This adds a downstream keyer scene type. This is part 1 of implementing a dsk. --- libobs/obs-scene.c | 50 +++++++++++++++++++++++++++++++++++++++++++++ libobs/obs-scene.h | 2 ++ libobs/obs-source.c | 2 ++ libobs/obs.c | 2 ++ libobs/obs.h | 8 ++++++++ 5 files changed, 64 insertions(+) diff --git a/libobs/obs-scene.c b/libobs/obs-scene.c index f73eb5c4d44949..6999fdbd7c0b98 100644 --- a/libobs/obs-scene.c +++ b/libobs/obs-scene.c @@ -22,6 +22,7 @@ #include "obs-scene.h" const struct obs_source_info group_info; +const struct obs_source_info dsk_info; static void resize_group(obs_sceneitem_t *group); static void resize_scene(obs_scene_t *scene); @@ -81,6 +82,12 @@ static const char *group_getname(void *unused) return "Group"; } +static const char *dsk_getname(void *unused) +{ + UNUSED_PARAMETER(unused); + return "DSK"; +} + static void *scene_create(obs_data_t *settings, struct obs_source *source) { pthread_mutexattr_t attr; @@ -92,6 +99,8 @@ static void *scene_create(obs_data_t *settings, struct obs_source *source) scene->custom_size = true; scene->cx = 0; scene->cy = 0; + } else if (strcmp(source->info.id, dsk_info.id) == 0) { + scene->is_dsk = true; } signal_handler_add_array(obs_source_get_signal_handler(source), @@ -1199,6 +1208,24 @@ const struct obs_source_info group_info = { .enum_active_sources = scene_enum_active_sources, .enum_all_sources = scene_enum_all_sources}; +const struct obs_source_info dsk_info = { + .id = "dsk", + .type = OBS_SOURCE_TYPE_SCENE, + .output_flags = OBS_SOURCE_VIDEO | OBS_SOURCE_CUSTOM_DRAW | + OBS_SOURCE_COMPOSITE, + .get_name = dsk_getname, + .create = scene_create, + .destroy = scene_destroy, + .video_tick = scene_video_tick, + .video_render = scene_video_render, + .audio_render = scene_audio_render, + .get_width = scene_getwidth, + .get_height = scene_getheight, + .load = scene_load, + .save = scene_save, + .enum_active_sources = scene_enum_active_sources, + .enum_all_sources = scene_enum_all_sources}; + static inline obs_scene_t *create_id(const char *id, const char *name) { struct obs_source *source = obs_source_create(id, name, NULL, NULL); @@ -1221,6 +1248,11 @@ obs_scene_t *obs_scene_create_private(const char *name) return create_private_id("scene", name); } +obs_scene_t *obs_dsk_create(const char *name) +{ + return create_id("dsk", name); +} + static obs_source_t *get_child_at_idx(obs_scene_t *scene, size_t idx) { struct obs_scene_item *item = scene->first_item; @@ -1425,6 +1457,14 @@ obs_scene_t *obs_group_from_source(const obs_source_t *source) return source->context.data; } +obs_scene_t *obs_dsk_from_source(const obs_source_t *source) +{ + if (!source || strcmp(source->info.id, dsk_info.id) != 0) + return NULL; + + return source->context.data; +} + obs_sceneitem_t *obs_scene_find_source(obs_scene_t *scene, const char *name) { struct obs_scene_item *item; @@ -2995,6 +3035,16 @@ bool obs_scene_is_group(const obs_scene_t *scene) return scene ? scene->is_group : false; } +bool obs_source_is_dsk(const obs_source_t *source) +{ + return source && strcmp(source->info.id, dsk_info.id) == 0; +} + +bool obs_scene_is_dsk(const obs_scene_t *scene) +{ + return scene ? scene->is_dsk : false; +} + void obs_sceneitem_group_enum_items(obs_sceneitem_t *group, bool (*callback)(obs_scene_t *, obs_sceneitem_t *, void *), diff --git a/libobs/obs-scene.h b/libobs/obs-scene.h index a9ddf740994373..4349deecea9483 100644 --- a/libobs/obs-scene.h +++ b/libobs/obs-scene.h @@ -97,4 +97,6 @@ struct obs_scene { pthread_mutex_t video_mutex; pthread_mutex_t audio_mutex; struct obs_scene_item *first_item; + + bool is_dsk; }; diff --git a/libobs/obs-source.c b/libobs/obs-source.c index 9aea45c73334b2..81b8b2ed7c133f 100644 --- a/libobs/obs-source.c +++ b/libobs/obs-source.c @@ -541,6 +541,8 @@ obs_source_t *obs_source_duplicate(obs_source_t *source, const char *new_name, } if (!scene) scene = obs_group_from_source(source); + if (!scene) + scene = obs_dsk_from_source(source); if (!scene) return NULL; diff --git a/libobs/obs.c b/libobs/obs.c index 7d32dbe5094794..a504e2b04578f9 100644 --- a/libobs/obs.c +++ b/libobs/obs.c @@ -828,6 +828,7 @@ static inline void obs_free_hotkeys(void) extern const struct obs_source_info scene_info; extern const struct obs_source_info group_info; +extern const struct obs_source_info dsk_info; static const char *submix_name(void *unused) { @@ -875,6 +876,7 @@ static bool obs_init(const char *locale, const char *module_config_path, obs->locale = bstrdup(locale); obs_register_source(&scene_info); obs_register_source(&group_info); + obs_register_source(&dsk_info); obs_register_source(&audio_line_info); add_default_module_paths(); return true; diff --git a/libobs/obs.h b/libobs/obs.h index 6ad9712f37168e..55097d5bb9dd22 100644 --- a/libobs/obs.h +++ b/libobs/obs.h @@ -1499,6 +1499,8 @@ EXPORT void obs_transition_swap_end(obs_source_t *tr_dest, */ EXPORT obs_scene_t *obs_scene_create(const char *name); +EXPORT obs_scene_t *obs_dsk_create(const char *name); + EXPORT obs_scene_t *obs_scene_create_private(const char *name); enum obs_scene_duplicate_type { @@ -1702,6 +1704,12 @@ EXPORT obs_scene_t *obs_group_from_source(const obs_source_t *source); EXPORT void obs_sceneitem_defer_group_resize_begin(obs_sceneitem_t *item); EXPORT void obs_sceneitem_defer_group_resize_end(obs_sceneitem_t *item); +/** Gets the dsk from its source, or NULL if not a dsk */ +EXPORT obs_scene_t *obs_dsk_from_source(const obs_source_t *source); + +EXPORT bool obs_source_is_dsk(const obs_source_t *source); +EXPORT bool obs_scene_is_dsk(const obs_scene_t *scene); + /* ------------------------------------------------------------------------- */ /* Outputs */