Revamp API and start using doxygen
The API used to be designed in such a way to where it would expect exports for each individual source/output/encoder/etc. You would export functions for each and it would automatically load those functions based on a specific naming scheme from the module. The idea behind this was that I wanted to limit the usage of structures in the API so only functions could be used. It was an interesting idea in theory, but this idea turned out to be flawed in a number of ways: 1.) Requiring exports to create sources/outputs/encoders/etc meant that you could not create them by any other means, which meant that things like faruton's .net plugin would become difficult. 2.) Export function declarations could not be checked, therefore if you created a function with the wrong parameters and parameter types, the compiler wouldn't know how to check for that. 3.) Required overly complex load functions in libobs just to handle it. It makes much more sense to just have a load function that you call manually. Complexity is the bane of all good programs. 4.) It required that you have functions of specific names, which looked and felt somewhat unsightly. So, to fix these issues, I replaced it with a more commonly used API scheme, seen commonly in places like kernels and typical C libraries with abstraction. You simply create a structure that contains the callback definitions, and you pass it to a function to register that definition (such as obs_register_source), which you call in the obs_module_load of the module. It will also automatically check the structure size and ensure that it only loads the required values if the structure happened to add new values in an API change. The "main" source file for each module must include obs-module.h, and must use OBS_DECLARE_MODULE() within that source file. Also, started writing some doxygen documentation in to the main library headers. Will add more detailed documentation as I go.
This commit is contained in:
@@ -81,11 +81,6 @@ static void scene_destroy(void *data)
|
||||
bfree(scene);
|
||||
}
|
||||
|
||||
static uint32_t scene_get_output_flags(void *data)
|
||||
{
|
||||
return SOURCE_VIDEO;
|
||||
}
|
||||
|
||||
static inline void detach_sceneitem(struct obs_scene_item *item)
|
||||
{
|
||||
if (item->prev)
|
||||
@@ -115,7 +110,7 @@ static inline void attach_sceneitem(struct obs_scene_item *item,
|
||||
}
|
||||
}
|
||||
|
||||
static void scene_video_render(void *data)
|
||||
static void scene_video_render(void *data, effect_t effect)
|
||||
{
|
||||
struct obs_scene *scene = data;
|
||||
struct obs_scene_item *item;
|
||||
@@ -154,16 +149,17 @@ static uint32_t scene_getsize(void *data)
|
||||
return 0;
|
||||
}
|
||||
|
||||
static const struct source_info scene_info =
|
||||
static const struct obs_source_info scene_info =
|
||||
{
|
||||
.id = "scene",
|
||||
.getname = scene_getname,
|
||||
.create = scene_create,
|
||||
.destroy = scene_destroy,
|
||||
.get_output_flags = scene_get_output_flags,
|
||||
.video_render = scene_video_render,
|
||||
.getwidth = scene_getsize,
|
||||
.getheight = scene_getsize,
|
||||
.id = "scene",
|
||||
.type = OBS_SOURCE_TYPE_SCENE,
|
||||
.output_flags = OBS_SOURCE_VIDEO | OBS_SOURCE_CUSTOM_DRAW,
|
||||
.getname = scene_getname,
|
||||
.create = scene_create,
|
||||
.destroy = scene_destroy,
|
||||
.video_render = scene_video_render,
|
||||
.getwidth = scene_getsize,
|
||||
.getheight = scene_getsize,
|
||||
};
|
||||
|
||||
obs_scene_t obs_scene_create(const char *name)
|
||||
@@ -188,11 +184,11 @@ obs_scene_t obs_scene_create(const char *name)
|
||||
}
|
||||
|
||||
source->name = bstrdup(name);
|
||||
source->type = SOURCE_SCENE;
|
||||
source->type = OBS_SOURCE_TYPE_SCENE;
|
||||
|
||||
scene->source = source;
|
||||
obs_source_init(source, &scene_info);
|
||||
memcpy(&source->callbacks, &scene_info, sizeof(struct source_info));
|
||||
memcpy(&source->info, &scene_info, sizeof(struct obs_source_info));
|
||||
return scene;
|
||||
}
|
||||
|
||||
@@ -215,7 +211,7 @@ obs_source_t obs_scene_getsource(obs_scene_t scene)
|
||||
|
||||
obs_scene_t obs_scene_fromsource(obs_source_t source)
|
||||
{
|
||||
if (source->type != SOURCE_SCENE)
|
||||
if (source->type != OBS_SOURCE_TYPE_SCENE)
|
||||
return NULL;
|
||||
|
||||
return source->data;
|
||||
|
Reference in New Issue
Block a user