From bd331c8ffe5e705cfdfcd237c7a28aca58099651 Mon Sep 17 00:00:00 2001 From: jp9000 Date: Sat, 5 Apr 2014 01:43:59 -0700 Subject: [PATCH] Remove the weird size stuff from OBS_DECLARE_MODULE Instead of doing this, just use macros to handle this situation. Also, fix a minor bug in AAC encoder --- libobs/obs-encoder.h | 6 ++- libobs/obs-module.c | 69 +++++------------------------ libobs/obs-module.h | 8 +--- libobs/obs-output.h | 6 ++- libobs/obs-source.h | 6 ++- plugins/obs-ffmpeg/obs-ffmpeg-aac.c | 3 +- 6 files changed, 30 insertions(+), 68 deletions(-) diff --git a/libobs/obs-encoder.h b/libobs/obs-encoder.h index 459fe05e3..8d3d5066a 100644 --- a/libobs/obs-encoder.h +++ b/libobs/obs-encoder.h @@ -207,10 +207,14 @@ struct obs_encoder_info { bool (*video_info)(void *data, struct video_scale_info *info); }; +EXPORT void obs_register_encoder_s(const struct obs_encoder_info *info, + size_t size); + /** * Register an encoder definition to the current obs context. This should be * used in obs_module_load. * * @param info Pointer to the source definition structure. */ -EXPORT void obs_register_encoder(const struct obs_encoder_info *info); +#define obs_register_encoder(info) \ + obs_register_encoder_s(info, sizeof(struct obs_encoder_info)) diff --git a/libobs/obs-module.c b/libobs/obs-module.c index 53c87e292..5b8d14af2 100644 --- a/libobs/obs-module.c +++ b/libobs/obs-module.c @@ -24,15 +24,6 @@ extern char *find_plugin(const char *plugin); -/* These variables get the current size of the info structures. Used to - * automatically prevent API breakage in case functions have to be added */ -static size_t cur_source_info_size = 0; -static size_t cur_output_info_size = 0; -static size_t cur_encoder_info_size = 0; -static size_t cur_service_info_size = 0; -static size_t cur_modal_ui_size = 0; -static size_t cur_modeless_ui_size = 0; - static inline int req_func_not_found(const char *name, const char *path) { blog(LOG_ERROR, "Required module function '%s' in module '%s' not " @@ -49,44 +40,17 @@ static inline int req_func_not_found(const char *name, const char *path) static int call_module_load(void *module, const char *path) { bool (*obs_module_load)(uint32_t obs_ver) = NULL; - size_t (*obs_module_source_info_size)(void) = NULL; - size_t (*obs_module_output_info_size)(void) = NULL; - size_t (*obs_module_encoder_info_size)(void) = NULL; - size_t (*obs_module_service_info_size)(void) = NULL; - size_t (*obs_module_modal_ui_size)(void) = NULL; - size_t (*obs_module_modeless_ui_size)(void) = NULL; obs_module_load = os_dlsym(module, "obs_module_load"); if (!obs_module_load) return req_func_not_found("obs_module_load", path); - LOAD_REQ_SIZE_FUNC(obs_module_source_info_size, module, path); - LOAD_REQ_SIZE_FUNC(obs_module_output_info_size, module, path); - LOAD_REQ_SIZE_FUNC(obs_module_encoder_info_size, module, path); - LOAD_REQ_SIZE_FUNC(obs_module_service_info_size, module, path); - LOAD_REQ_SIZE_FUNC(obs_module_modal_ui_size, module, path); - LOAD_REQ_SIZE_FUNC(obs_module_modeless_ui_size, module, path); - - cur_source_info_size = obs_module_source_info_size(); - cur_output_info_size = obs_module_output_info_size(); - cur_encoder_info_size = obs_module_encoder_info_size(); - cur_service_info_size = obs_module_service_info_size(); - cur_modal_ui_size = obs_module_modal_ui_size(); - cur_modeless_ui_size = obs_module_modeless_ui_size(); - if (!obs_module_load(LIBOBS_API_VER)) { blog(LOG_ERROR, "Module '%s' failed to load: " "obs_module_load failed", path); return MODULE_ERROR; } - cur_source_info_size = 0; - cur_output_info_size = 0; - cur_encoder_info_size = 0; - cur_service_info_size = 0; - cur_modal_ui_size = 0; - cur_modeless_ui_size = 0; - return MODULE_SUCCESS; } @@ -155,7 +119,7 @@ void free_module(struct obs_module *mod) } \ } while (false) -void obs_register_source(const struct obs_source_info *info) +void obs_register_source_s(const struct obs_source_info *info, size_t size) { struct obs_source_info data = {0}; struct darray *array; @@ -170,13 +134,7 @@ void obs_register_source(const struct obs_source_info *info) CHECK_REQUIRED_VAL(info, getheight, obs_register_source); } - if (!cur_source_info_size) { - blog(LOG_ERROR, "Tried to register obs_source_info" - " outside of obs_module_load"); - return; - } - - memcpy(&data, info, cur_source_info_size); + memcpy(&data, info, size); if (info->type == OBS_SOURCE_TYPE_INPUT) { array = &obs->input_types.da; @@ -193,7 +151,7 @@ void obs_register_source(const struct obs_source_info *info) darray_push_back(sizeof(struct obs_source_info), array, &data); } -void obs_register_output(const struct obs_output_info *info) +void obs_register_output_s(const struct obs_output_info *info, size_t size) { CHECK_REQUIRED_VAL(info, getname, obs_register_output); CHECK_REQUIRED_VAL(info, create, obs_register_output); @@ -213,43 +171,40 @@ void obs_register_output(const struct obs_output_info *info) obs_register_output); } - REGISTER_OBS_DEF(cur_output_info_size, obs_output_info, - obs->output_types, info); + REGISTER_OBS_DEF(size, obs_output_info, obs->output_types, info); } -void obs_register_encoder(const struct obs_encoder_info *info) +void obs_register_encoder_s(const struct obs_encoder_info *info, size_t size) { CHECK_REQUIRED_VAL(info, getname, obs_register_encoder); CHECK_REQUIRED_VAL(info, create, obs_register_encoder); CHECK_REQUIRED_VAL(info, destroy, obs_register_encoder); CHECK_REQUIRED_VAL(info, encode, obs_register_encoder); - REGISTER_OBS_DEF(cur_encoder_info_size, obs_encoder_info, - obs->encoder_types, info); + REGISTER_OBS_DEF(size, obs_encoder_info, obs->encoder_types, info); } -void obs_register_service(const struct obs_service_info *info) +void obs_register_service_s(const struct obs_service_info *info, size_t size) { /* TODO */ UNUSED_PARAMETER(info); } -void obs_regsiter_modal_ui(const struct obs_modal_ui *info) +void obs_regsiter_modal_ui_s(const struct obs_modal_ui *info, size_t size) { CHECK_REQUIRED_VAL(info, task, obs_regsiter_modal_ui); CHECK_REQUIRED_VAL(info, target, obs_regsiter_modal_ui); CHECK_REQUIRED_VAL(info, exec, obs_regsiter_modal_ui); - REGISTER_OBS_DEF(cur_modal_ui_size, obs_modal_ui, - obs->modal_ui_callbacks, info); + REGISTER_OBS_DEF(size, obs_modal_ui, obs->modal_ui_callbacks, info); } -void obs_regsiter_modeless_ui(const struct obs_modeless_ui *info) +void obs_regsiter_modeless_ui_s(const struct obs_modeless_ui *info, size_t size) { CHECK_REQUIRED_VAL(info, task, obs_regsiter_modeless_ui); CHECK_REQUIRED_VAL(info, target, obs_regsiter_modeless_ui); CHECK_REQUIRED_VAL(info, create, obs_regsiter_modeless_ui); - REGISTER_OBS_DEF(cur_modeless_ui_size, obs_modeless_ui, - obs->modeless_ui_callbacks, info); + REGISTER_OBS_DEF(size, obs_modeless_ui, obs->modeless_ui_callbacks, + info); } diff --git a/libobs/obs-module.h b/libobs/obs-module.h index 03ffb6e5c..5fcf3048c 100644 --- a/libobs/obs-module.h +++ b/libobs/obs-module.h @@ -38,13 +38,7 @@ /** Required: Declares a libobs module. */ #define OBS_DECLARE_MODULE() \ MODULE_EXPORT uint32_t obs_module_ver(void); \ - uint32_t obs_module_ver(void) {return LIBOBS_API_VER;} \ - OBS_SIZE_FUNC(obs_source_info, obs_module_source_info_size) \ - OBS_SIZE_FUNC(obs_output_info, obs_module_output_info_size) \ - OBS_SIZE_FUNC(obs_encoder_info, obs_module_encoder_info_size) \ - OBS_SIZE_FUNC(obs_encoder_info, obs_module_service_info_size) \ - OBS_SIZE_FUNC(obs_modal_ui, obs_module_modal_ui_size) \ - OBS_SIZE_FUNC(obs_modeless_ui, obs_module_modeless_ui_size) + uint32_t obs_module_ver(void) {return LIBOBS_API_VER;} /** * Required: Called when the module is loaded. Use this function to load all diff --git a/libobs/obs-output.h b/libobs/obs-output.h index 64e8be4ca..76b738f44 100644 --- a/libobs/obs-output.h +++ b/libobs/obs-output.h @@ -54,4 +54,8 @@ struct obs_output_info { void (*pause)(void *data); }; -EXPORT void obs_register_output(const struct obs_output_info *info); +EXPORT void obs_register_output_s(const struct obs_output_info *info, + size_t size); + +#define obs_register_output(info) \ + obs_register_output_s(info, sizeof(struct obs_output_info)) diff --git a/libobs/obs-source.h b/libobs/obs-source.h index ac827ed54..55c4f9f3f 100644 --- a/libobs/obs-source.h +++ b/libobs/obs-source.h @@ -256,13 +256,17 @@ struct obs_source_info { void *param); }; +EXPORT void obs_register_source_s(const struct obs_source_info *info, + size_t size); + /** * Regsiters a source definition to the current obs context. This should be * used in obs_module_load. * * @param info Pointer to the source definition structure */ -EXPORT void obs_register_source(const struct obs_source_info *info); +#define obs_register_source(info) \ + obs_register_source_s(info, sizeof(struct obs_source_info)) #ifdef __cplusplus } diff --git a/plugins/obs-ffmpeg/obs-ffmpeg-aac.c b/plugins/obs-ffmpeg/obs-ffmpeg-aac.c index f0cbc32c4..40abef0d3 100644 --- a/plugins/obs-ffmpeg/obs-ffmpeg-aac.c +++ b/plugins/obs-ffmpeg/obs-ffmpeg-aac.c @@ -53,7 +53,7 @@ static void aac_warn(const char *func, const char *format, ...) va_start(args, format); vsnprintf(msg, sizeof(msg), format, args); - blog(LOG_WARNING, "[%s}: %s", func, msg); + blog(LOG_WARNING, "[%s]: %s", func, msg); va_end(args); } @@ -193,6 +193,7 @@ static bool do_aac_encode(struct aac_encoder *enc, packet->pts = rescale_ts(avpacket.pts, enc->context, time_base); packet->dts = rescale_ts(avpacket.dts, enc->context, time_base); packet->data = bmemdup(avpacket.data, avpacket.size); + packet->size = avpacket.size; packet->type = OBS_ENCODER_AUDIO; packet->timebase_num = 1; packet->timebase_den = (int32_t)enc->context->sample_rate;