diff --git a/src/video_compress.cpp b/src/video_compress.cpp index e9aabf25d..d02055fe0 100644 --- a/src/video_compress.cpp +++ b/src/video_compress.cpp @@ -6,7 +6,7 @@ * @brief Video compress functions. */ /* - * Copyright (c) 2011-2024 CESNET z.s.p.o. + * Copyright (c) 2011-2025 CESNET * All rights reserved. * * Redistribution and use in source and binary forms, with or without @@ -86,7 +86,7 @@ public: } ~compress_state_real(); const video_compress_info *funcs; ///< handle for the driver - vector state; ///< driver internal states + vector state; ///< driver internal states string compress_options; ///< compress options (for reconfiguration) volatile bool discard_frames; ///< this class is no longer active }; @@ -147,7 +147,9 @@ static void compress_process_message(struct compress_state *proxy, struct msg_ch tmp_data->what = data->what; strncpy(tmp_data->config_string, data->config_string, sizeof(tmp_data->config_string)); - struct response *resp = send_message_to_receiver(proxy->ptr->state[i], + char receiver[100]; + snprintf(receiver, sizeof receiver, "data[%u]", i); + struct response *resp = send_message(&proxy->mod, receiver, (struct message *) tmp_data); /// @todo /// Handle responses more intelligently (eg. aggregate). @@ -397,7 +399,7 @@ void compress_frame(struct compress_state *proxy, shared_ptr frame) * @brief Auxiliary structure passed to worker thread. */ struct compress_worker_data { - struct module *state; ///< compress driver status + void *state; ///< compress driver status shared_ptr frame; ///< uncompressed tile to be compressed compress_tile_t callback; ///< tile compress callback @@ -506,7 +508,7 @@ compress_state_real::~compress_state_real() } for(unsigned int i = 0; i < state.size(); ++i) { - module_done(state[i]); + funcs->done(state[i]); } } diff --git a/src/video_compress.h b/src/video_compress.h index c27fa415e..32d640f28 100644 --- a/src/video_compress.h +++ b/src/video_compress.h @@ -68,7 +68,7 @@ #include "types.h" -#define VIDEO_COMPRESS_ABI_VERSION 12 +#define VIDEO_COMPRESS_ABI_VERSION 13 #ifdef __cplusplus extern "C" { @@ -109,9 +109,12 @@ std::shared_ptr compress_pop(struct compress_state *); * @param[in] cfg configuration string * @return driver internal state */ -typedef struct module *(*compress_init_t)(struct module *parent, +typedef void *(*compress_init_t)(struct module *parent, const char *cfg); +/// destroys the state create by @ref compress_init_t +typedef void (*compress_done_t)(void *state); + /** * @brief Compresses video frame * @@ -120,7 +123,7 @@ typedef struct module *(*compress_init_t)(struct module *parent, * empty shared_ptr to fetch further compressed frames * @return compressed frame, may be NULL if compression failed or no compressed frame was output */ -typedef std::shared_ptr (*compress_frame_t)(struct module *state, std::shared_ptr frame); +typedef std::shared_ptr (*compress_frame_t)(void *state, std::shared_ptr frame); /** * @brief Compresses tile of a video frame @@ -130,7 +133,7 @@ typedef std::shared_ptr (*compress_frame_t)(struct module *state, * empty shared_ptr to fetch remaining tiles * @return compressed frame with one tile, may be NULL if compression failed or no compressed frame was output */ -typedef std::shared_ptr (*compress_tile_t)(struct module *state, std::shared_ptr in_frame); +typedef std::shared_ptr (*compress_tile_t)(void *state, std::shared_ptr in_frame); /** * @brief Passes frame to compress module for async processing. @@ -140,7 +143,7 @@ typedef std::shared_ptr (*compress_tile_t)(struct module *state, s * @param[in] state driver internal state * @param[in] in_frame uncompressed frame or empty shared_ptr to pass a poisoned pile */ -typedef void (*compress_frame_async_push_t)(struct module *state, std::shared_ptr in_frame); +typedef void (*compress_frame_async_push_t)(void *state, std::shared_ptr in_frame); /** * @brief Fetches compressed frame passed with compress_frame_async_push() @@ -149,7 +152,7 @@ typedef void (*compress_frame_async_push_t)(struct module *state, std::shared_pt * @return compressed frame, empty shared_ptr corresponding with poisoned * pill can be also returned */ -typedef std::shared_ptr (*compress_frame_async_pop_t)(struct module *state); +typedef std::shared_ptr (*compress_frame_async_pop_t)(void *state); /** * @brief Passes tile to compress module for async processing. @@ -159,7 +162,7 @@ typedef std::shared_ptr (*compress_frame_async_pop_t)(struct modul * @param[in] state driver internal state * @param[in] in_frame uncompressed frame or empty shared_ptr to pass a poisoned pile */ -typedef void (*compress_tile_async_push_t)(struct module *state, std::shared_ptr in_frame); +typedef void (*compress_tile_async_push_t)(void *state, std::shared_ptr in_frame); /** * @brief Fetches compressed tile passed with compress_tile_async_push() @@ -168,7 +171,7 @@ typedef void (*compress_tile_async_push_t)(struct module *state, std::shared_ptr * @return compressed frame, empty shared_ptr corresponding with poisoned * pill can be also returned */ -typedef std::shared_ptr (*compress_tile_async_pop_t)(struct module *state); +typedef std::shared_ptr (*compress_tile_async_pop_t)(void *state); struct module_option{ std::string display_name; //Name displayed to user @@ -213,8 +216,8 @@ struct compress_module_info{ * 4. Async tile API - compress a tile asynchronously */ struct video_compress_info { - const char * name; ///< not used compress_init_t init_func; ///< compress driver initialization function + compress_done_t done; compress_frame_t compress_frame_func; ///< compress function for Frame API diff --git a/src/video_compress/cineform.cpp b/src/video_compress/cineform.cpp index 6dbbddeff..397bc8aed 100644 --- a/src/video_compress/cineform.cpp +++ b/src/video_compress/cineform.cpp @@ -3,7 +3,7 @@ * @author Martin Piatka * */ -/* Copyright (c) 2019-2023 CESNET z.s.p.o. +/* Copyright (c) 2019-2025 CESNET * * Redistribution and use in source and binary forms, with or without * modification, is permitted provided that the following conditions @@ -49,7 +49,6 @@ #include "debug.h" #include "host.h" #include "lib_common.h" -#include "module.h" #include "tv.h" #include "video_compress.h" @@ -76,8 +75,6 @@ #define MOD_NAME "[cineform] " struct state_video_compress_cineform{ - struct module module_data; - std::mutex mutex; struct video_desc saved_desc; @@ -107,8 +104,8 @@ struct state_video_compress_cineform{ #endif }; -static void cineform_compress_done(struct module *mod){ - struct state_video_compress_cineform *s = (struct state_video_compress_cineform *) mod->priv_data; +static void cineform_compress_done(void *state) { + auto *s = (struct state_video_compress_cineform *) state; s->mutex.lock(); @@ -175,8 +172,9 @@ static int parse_fmt(struct state_video_compress_cineform *s, char *fmt) { return 0; } -static struct module * cineform_compress_init(struct module *parent, const char *opts) +static void * cineform_compress_init(struct module *parent, const char *opts) { + (void) parent; struct state_video_compress_cineform *s; s = new state_video_compress_cineform(); @@ -191,7 +189,7 @@ static struct module * cineform_compress_init(struct module *parent, const char free(fmt); if(ret != 0) { delete s; - return ret > 0 ? static_cast(INIT_NOERR) : nullptr; + return ret > 0 ? INIT_NOERR : nullptr; } log_msg(LOG_LEVEL_NOTICE, "[cineform] : Threads: %d.\n", s->requested_threads); @@ -218,13 +216,7 @@ static struct module * cineform_compress_init(struct module *parent, const char s->started = false; s->stop = false; - module_init_default(&s->module_data); - s->module_data.cls = MODULE_CLASS_DATA; - s->module_data.priv_data = s; - s->module_data.deleter = cineform_compress_done; - module_register(&s->module_data, parent); - - return &s->module_data; + return s; } static struct { @@ -349,9 +341,9 @@ static video_frame *get_copy(struct state_video_compress_cineform *s, video_fram return ret; } -static void cineform_compress_push(struct module *state, std::shared_ptr tx) +static void cineform_compress_push(void *state, std::shared_ptr tx) { - struct state_video_compress_cineform *s = (struct state_video_compress_cineform *) state->priv_data; + auto *s = (struct state_video_compress_cineform *) state; CFHD_Error status = CFHD_ERROR_OKAY; std::unique_lock lock(s->mutex); @@ -435,9 +427,9 @@ static void timespec_diff(struct timespec *start, struct timespec *stop, } #endif -static std::shared_ptr cineform_compress_pop(struct module *state) +static std::shared_ptr cineform_compress_pop(void *state) { - struct state_video_compress_cineform *s = (struct state_video_compress_cineform *) state->priv_data; + auto *s = (struct state_video_compress_cineform *) state; std::unique_lock lock(s->mutex); @@ -531,8 +523,8 @@ static compress_module_info get_cineform_module_info(){ } const struct video_compress_info cineform_info = { - "cineform", cineform_compress_init, + cineform_compress_done, NULL, NULL, NULL, diff --git a/src/video_compress/cmpto_j2k.cpp b/src/video_compress/cmpto_j2k.cpp index c60ce0fb0..886604186 100644 --- a/src/video_compress/cmpto_j2k.cpp +++ b/src/video_compress/cmpto_j2k.cpp @@ -69,7 +69,6 @@ #include "debug.h" #include "host.h" #include "lib_common.h" -#include "module.h" #include "tv.h" #include "utils/color_out.h" #include "utils/macros.h" // for IS_KEY_PREFIX, TOSTRING @@ -278,7 +277,6 @@ get_supported_technology(const char *name) } struct state_video_compress_j2k { - struct module module_data{}; const struct cmpto_j2k_technology *tech = nullptr; struct cmpto_j2k_enc_ctx *context{}; struct cmpto_j2k_enc_cfg *enc_settings{}; @@ -310,7 +308,7 @@ struct state_video_compress_j2k { // prototypes static void j2k_compressed_frame_dispose(struct video_frame *frame); -static void j2k_compress_done(struct module *mod); +static void j2k_compress_done(void *state); static void cleanup_common(struct state_video_compress_j2k *s); static void parallel_conv(video_frame *dst, video_frame *src){ @@ -562,7 +560,7 @@ struct custom_data { * pipeline. Because of that goto + start label is used. */ #define HANDLE_ERROR_COMPRESS_POP do { cmpto_j2k_enc_img_destroy(img); goto start; } while (0) -static std::shared_ptr j2k_compress_pop(struct module *state) +static std::shared_ptr j2k_compress_pop(void *state) { auto *s = (struct state_video_compress_j2k *) state; start: @@ -733,15 +731,16 @@ static void usage(bool full) { (var) = val; \ } while (0) -static struct module * j2k_compress_init(struct module *parent, const char *c_cfg) +static void * j2k_compress_init(struct module *parent, const char *c_cfg) { + (void) parent; const auto *version = cmpto_j2k_enc_get_version(); LOG(LOG_LEVEL_INFO) << MOD_NAME << "Using codec version: " << (version == nullptr ? "(unknown)" : version->name) << "\n"; if (strcasecmp(c_cfg, "help") == 0 || strcasecmp(c_cfg, "fullhelp") == 0) { usage(strcasecmp(c_cfg, "fullhelp") == 0); - return static_cast(INIT_NOERR); + return INIT_NOERR; } const char *req_technology = nullptr; @@ -772,7 +771,7 @@ static struct module * j2k_compress_init(struct module *parent, const char *c_cf ASSIGN_CHECK_VAL(s->thread_count, strchr(item, '=') + 1, 0); } else { log_msg(LOG_LEVEL_ERROR, "[J2K] Wrong option: %s\n", item); - j2k_compress_done((struct module *) s); + j2k_compress_done(s); return nullptr; } } @@ -780,14 +779,14 @@ static struct module * j2k_compress_init(struct module *parent, const char *c_cf if (!s->lossless) { if (s->quality < 0.0 || s->quality > 1.0) { LOG(LOG_LEVEL_ERROR) << "[J2K] Quality should be in interval [0-1]!\n"; - j2k_compress_done((struct module *) s); + j2k_compress_done(s); return nullptr; } } s->tech = get_supported_technology(req_technology); if (s->tech == nullptr) { - j2k_compress_done((struct module *) s); + j2k_compress_done(s); return nullptr; } MSG(INFO, "Using technology: %s\n", s->tech->name); @@ -799,13 +798,7 @@ static struct module * j2k_compress_init(struct module *parent, const char *c_cf s->img_tile_limit = (int) s->tech->default_img_tile_limit; } - module_init_default(&s->module_data); - s->module_data.cls = MODULE_CLASS_DATA; - s->module_data.priv_data = s; - s->module_data.deleter = j2k_compress_done; - module_register(&s->module_data, parent); - - return &s->module_data; + return s; } static void j2k_compressed_frame_dispose(struct video_frame *frame) @@ -838,7 +831,7 @@ release_cstream_cuda(void *img_custom_data, size_t img_custom_data_size, } \ return -static void j2k_compress_push(struct module *state, std::shared_ptr tx) +static void j2k_compress_push(void *state, std::shared_ptr tx) { struct state_video_compress_j2k *s = (struct state_video_compress_j2k *) state; @@ -932,9 +925,9 @@ static void j2k_compress_push(struct module *state, std::shared_ptr } -static void j2k_compress_done(struct module *mod) +static void j2k_compress_done(void *state) { - auto *s = (struct state_video_compress_j2k *) mod; + auto *s = (struct state_video_compress_j2k *) state; cleanup_common(s); delete s; } @@ -973,8 +966,8 @@ static compress_module_info get_cmpto_j2k_module_info(){ } static struct video_compress_info j2k_compress_info = { - "cmpto_j2k", j2k_compress_init, + j2k_compress_done, NULL, NULL, NULL, diff --git a/src/video_compress/cuda_dxt.cpp b/src/video_compress/cuda_dxt.cpp index fc902cd7a..55b1b817c 100644 --- a/src/video_compress/cuda_dxt.cpp +++ b/src/video_compress/cuda_dxt.cpp @@ -3,7 +3,7 @@ * @author Martin Pulec */ /* - * Copyright (c) 2012-2023 CESNET z. s. p. o. + * Copyright (c) 2012-2025 CESNET * All rights reserved. * * Redistribution and use in source and binary forms, with or without @@ -45,7 +45,6 @@ #include "debug.h" #include "host.h" #include "lib_common.h" -#include "module.h" #include "pixfmt_conv.h" // for get_decoder_from_to, decoder_t #include "types.h" // for tile, video_frame, video_desc #include "utils/video_frame_pool.h" @@ -75,7 +74,6 @@ struct cuda_buffer_data_allocator : public video_frame_pool_allocator { }; struct state_video_compress_cuda_dxt { - struct module module_data; struct video_desc saved_desc; char *in_buffer; ///< for decoded data char *cuda_uyvy_buffer; ///< same as in_buffer but in device memory @@ -88,11 +86,12 @@ struct state_video_compress_cuda_dxt { video_frame_pool pool{0, cuda_buffer_data_allocator()}; }; -static void cuda_dxt_compress_done(struct module *mod); +static void cuda_dxt_compress_done(void *state); -struct module *cuda_dxt_compress_init(struct module *parent, +void *cuda_dxt_compress_init(struct module *parent, const char *fmt) { + (void) parent; state_video_compress_cuda_dxt *s = new state_video_compress_cuda_dxt(); s->out_codec = DXT1; @@ -110,13 +109,7 @@ struct module *cuda_dxt_compress_init(struct module *parent, } } - module_init_default(&s->module_data); - s->module_data.cls = MODULE_CLASS_DATA; - s->module_data.priv_data = s; - s->module_data.deleter = cuda_dxt_compress_done; - module_register(&s->module_data, parent); - - return &s->module_data; + return s; } static void cleanup(struct state_video_compress_cuda_dxt *s) @@ -188,14 +181,13 @@ static bool configure_with(struct state_video_compress_cuda_dxt *s, struct video return true; } -shared_ptr cuda_dxt_compress_tile(struct module *mod, shared_ptr tx) +shared_ptr cuda_dxt_compress_tile(void *state, shared_ptr tx) { if (!tx) { return {}; } - struct state_video_compress_cuda_dxt *s = - (struct state_video_compress_cuda_dxt *) mod->priv_data; + auto *s = (struct state_video_compress_cuda_dxt *) state; cuda_wrapper_set_device(cuda_devices[0]); @@ -281,19 +273,16 @@ shared_ptr cuda_dxt_compress_tile(struct module *mod, shared_ptrpriv_data; - + auto *s = (struct state_video_compress_cuda_dxt *) state; cleanup(s); - delete s; } const struct video_compress_info cuda_dxt_info = { - "cuda_dxt", cuda_dxt_compress_init, + cuda_dxt_compress_done, NULL, cuda_dxt_compress_tile, NULL, diff --git a/src/video_compress/dxt_glsl.cpp b/src/video_compress/dxt_glsl.cpp index 97e150aaa..173cfa4ca 100644 --- a/src/video_compress/dxt_glsl.cpp +++ b/src/video_compress/dxt_glsl.cpp @@ -3,7 +3,7 @@ * @author Martin Pulec */ /* - * Copyright (c) 2011-2023 CESNET, z. s. p. o. + * Copyright (c) 2011-2025 CESNET * All rights reserved. * * Redistribution and use in source and binary forms, with or without @@ -49,7 +49,6 @@ #include "gl_context.h" #include "host.h" #include "lib_common.h" -#include "module.h" #include "pixfmt_conv.h" // for get_decoder_from_to, decoder_t #include "types.h" // for tile, video_frame, video_desc #include "utils/video_frame_pool.h" @@ -62,8 +61,6 @@ using namespace std; namespace { struct state_video_compress_rtdxt { - struct module module_data; - struct dxt_encoder **encoder; int encoder_count; @@ -81,7 +78,7 @@ struct state_video_compress_rtdxt { }; static int configure_with(struct state_video_compress_rtdxt *s, struct video_frame *frame); -static void dxt_glsl_compress_done(struct module *mod); +static void dxt_glsl_compress_done(void *state); static int configure_with(struct state_video_compress_rtdxt *s, struct video_frame *frame) { @@ -212,8 +209,9 @@ static int configure_with(struct state_video_compress_rtdxt *s, struct video_fra return true; } -struct module *dxt_glsl_compress_init(struct module *parent, const char *opts) +void *dxt_glsl_compress_init(struct module *parent, const char *opts) { + (void) parent; struct state_video_compress_rtdxt *s; if(strcmp(opts, "help") == 0) { @@ -251,22 +249,16 @@ struct module *dxt_glsl_compress_init(struct module *parent, const char *opts) gl_context_make_current(NULL); - module_init_default(&s->module_data); - s->module_data.cls = MODULE_CLASS_DATA; - s->module_data.priv_data = s; - s->module_data.deleter = dxt_glsl_compress_done; - module_register(&s->module_data, parent); - - return &s->module_data; + return s; } -shared_ptr dxt_glsl_compress(struct module *mod, shared_ptr tx) +shared_ptr dxt_glsl_compress(void *state, shared_ptr tx) { if (!tx) { return {}; } - struct state_video_compress_rtdxt *s = (struct state_video_compress_rtdxt *) mod->priv_data; + auto *s = (struct state_video_compress_rtdxt *) state; int i; unsigned char *line1, *line2; @@ -311,9 +303,9 @@ shared_ptr dxt_glsl_compress(struct module *mod, shared_ptrpriv_data; + auto *s = (struct state_video_compress_rtdxt *) state; if(s->encoder) { for(int i = 0; i < s->encoder_count; ++i) { @@ -327,8 +319,8 @@ static void dxt_glsl_compress_done(struct module *mod) } const struct video_compress_info rtdxt_info = { - "RTDXT", dxt_glsl_compress_init, + dxt_glsl_compress_done, dxt_glsl_compress, NULL, NULL, diff --git a/src/video_compress/gpujpeg.cpp b/src/video_compress/gpujpeg.cpp index a03d07946..b81db8340 100644 --- a/src/video_compress/gpujpeg.cpp +++ b/src/video_compress/gpujpeg.cpp @@ -3,7 +3,7 @@ * @author Martin Pulec */ /* - * Copyright (c) 2011-2024 CESNET + * Copyright (c) 2011-2025 CESNET * All rights reserved. * * Redistribution and use in source and binary forms, with or without @@ -38,6 +38,7 @@ #include #include #include +#include #include #include #include @@ -52,7 +53,6 @@ #include "debug.h" #include "host.h" #include "lib_common.h" -#include "module.h" #include "tv.h" #include "utils/color_out.h" #include "utils/macros.h" @@ -153,7 +153,6 @@ public: void push(std::shared_ptr in_frame); std::shared_ptr pop(); - struct module m_module_data; int m_restart_interval; int m_quality; bool m_force_interleaved = false; @@ -419,8 +418,9 @@ bool state_video_compress_gpujpeg::parse_fmt(char *fmt) state_video_compress_gpujpeg::state_video_compress_gpujpeg(struct module *parent, const char *opts) : m_uses_worker_threads{}, m_in_seq{}, m_out_seq{}, m_ended_count{}, - m_module_data{}, m_restart_interval(UNDEF), m_quality(-1) + m_restart_interval(UNDEF), m_quality(-1) { + (void) parent; if(opts && opts[0] != '\0') { char *fmt = strdup(opts); if (!parse_fmt(fmt)) { @@ -429,17 +429,6 @@ state_video_compress_gpujpeg::state_video_compress_gpujpeg(struct module *parent } free(fmt); } - - module_init_default(&m_module_data); - m_module_data.cls = MODULE_CLASS_DATA; - m_module_data.priv_data = this; - static auto deleter = [](struct module *mod) { - struct state_video_compress_gpujpeg *s = (struct state_video_compress_gpujpeg *) mod->priv_data; - delete s; - }; - m_module_data.deleter = deleter; - - module_register(&m_module_data, parent); } /** @@ -503,7 +492,8 @@ static const struct { ":alpha", true, ""}, }; -struct module * gpujpeg_compress_init(struct module *parent, const char *opts) +void * +gpujpeg_compress_init(struct module *parent, const char *opts) { if (gpujpeg_version() >> 8 != GPUJPEG_VERSION_INT >> 8) { LOG(LOG_LEVEL_WARNING) << "GPUJPEG API version mismatch! (compiled: " << @@ -527,19 +517,19 @@ struct module * gpujpeg_compress_init(struct module *parent, const char *opts) } col() << "\n"; - return static_cast(INIT_NOERR); + return INIT_NOERR; } if (opts && strcmp(opts, "check") == 0) { auto device_info = gpujpeg_get_devices_info(); - return device_info.device_count == 0 ? nullptr : static_cast(INIT_NOERR); + return device_info.device_count == 0 ? nullptr : INIT_NOERR; } if (opts && strcmp(opts, "list_devices") == 0) { printf("CUDA devices:\n"); #if GPUJPEG_VERSION_INT >= GPUJPEG_MK_VERSION_INT(0, 16, 0) - return gpujpeg_print_devices_info() == 0 ? static_cast(INIT_NOERR) : nullptr; + return gpujpeg_print_devices_info() == 0 ? INIT_NOERR : nullptr; #else gpujpeg_print_devices_info(); - return static_cast(INIT_NOERR); + return INIT_NOERR; #endif } @@ -549,7 +539,7 @@ struct module * gpujpeg_compress_init(struct module *parent, const char *opts) return NULL; } - return &s->m_module_data; + return s; } /** @@ -746,17 +736,23 @@ static compress_module_info get_gpujpeg_module_info(){ return module_info; } -static auto gpujpeg_compress_push(struct module *mod, std::shared_ptr in_frame) { - static_cast(mod->priv_data)->push(std::move(in_frame)); +static auto gpujpeg_compress_push(void *state, std::shared_ptr in_frame) { + static_cast(state)->push(std::move(in_frame)); } -static auto gpujpeg_compress_pull (struct module *mod) { - return static_cast(mod->priv_data)->pop(); +static auto gpujpeg_compress_pull (void *state) { + return static_cast(state)->pop(); +} + +static void +gpujpeg_compress_done(void *state) +{ + delete (struct state_video_compress_gpujpeg *) state; } const struct video_compress_info gpujpeg_info = { - "GPUJPEG", gpujpeg_compress_init, + gpujpeg_compress_done, NULL, NULL, gpujpeg_compress_push, @@ -772,8 +768,8 @@ static auto gpujpeg_compress_init_deprecated(struct module *parent, const char * } const struct video_compress_info deprecated_jpeg_info = { - "JPEG", gpujpeg_compress_init_deprecated, + gpujpeg_compress_done, NULL, NULL, gpujpeg_compress_push, diff --git a/src/video_compress/libavcodec.cpp b/src/video_compress/libavcodec.cpp index 8ca1291c2..0646352a4 100644 --- a/src/video_compress/libavcodec.cpp +++ b/src/video_compress/libavcodec.cpp @@ -3,7 +3,7 @@ * @author Martin Pulec */ /* - * Copyright (c) 2013-2024 CESNET, z. s. p. o. + * Copyright (c) 2013-2025 CESNET * All rights reserved. * * Redistribution and use in source and binary forms, with or without @@ -176,7 +176,7 @@ typedef struct { } codec_params_t; static void libavcodec_check_messages(struct state_video_compress_libav *s); -static void libavcodec_compress_done(struct module *mod); +static void libavcodec_compress_done(void *state); static void setparam_default(AVCodecContext *, struct setparam_param *); static void setparam_h264_h265_av1(AVCodecContext *, struct setparam_param *); static void setparam_jpeg(AVCodecContext *, struct setparam_param *); @@ -269,7 +269,6 @@ struct state_video_compress_libav { module_init_default(&module_data); module_data.cls = MODULE_CLASS_DATA; module_data.priv_data = this; - module_data.deleter = libavcodec_compress_done; module_register(&module_data, parent); } ~state_video_compress_libav() { @@ -688,7 +687,7 @@ static compress_module_info get_libavcodec_module_info(){ ADD_TO_PARAM("keep-pixfmt", "* keep-pixfmt\n" " Signalize input pixel format to receiver and try\n"); -struct module * libavcodec_compress_init(struct module *parent, const char *opts) +void* libavcodec_compress_init(struct module *parent, const char *opts) { ug_set_av_logging(); #if LIBAVCODEC_VERSION_INT <= AV_VERSION_INT(58, 9, 100) @@ -708,8 +707,8 @@ struct module * libavcodec_compress_init(struct module *parent, const char *opts } free(fmt); if (ret != 0) { - module_done(&s->module_data); - return ret > 0 ? static_cast(INIT_NOERR) : NULL; + libavcodec_compress_done(s); + return ret > 0 ? INIT_NOERR : NULL; } return &s->module_data; @@ -1530,9 +1529,9 @@ receive_packet(state_video_compress_libav *s) return out_vf_from_pkt(s, s->pkt); } -static shared_ptr libavcodec_compress_tile(struct module *mod, shared_ptr tx) +static shared_ptr libavcodec_compress_tile(void *state, shared_ptr tx) { - auto *s = (state_video_compress_libav *) mod->priv_data; + auto *s = (state_video_compress_libav *) state; list> cleanup_callbacks; // at function exit handlers libavcodec_check_messages(s); @@ -1636,9 +1635,9 @@ static void cleanup(struct state_video_compress_libav *s) #endif //HAVE_SWSCALE } -static void libavcodec_compress_done(struct module *mod) +static void libavcodec_compress_done(void *state) { - struct state_video_compress_libav *s = (struct state_video_compress_libav *) mod->priv_data; + auto *s = (struct state_video_compress_libav *) state; cleanup(s); @@ -2312,8 +2311,8 @@ static void libavcodec_check_messages(struct state_video_compress_libav *s) } const struct video_compress_info libavcodec_info = { - "libavcodec", libavcodec_compress_init, + libavcodec_compress_done, NULL, libavcodec_compress_tile, NULL, @@ -2324,8 +2323,8 @@ const struct video_compress_info libavcodec_info = { }; const struct video_compress_info lavc_info = { - "lavc", libavcodec_compress_init, + libavcodec_compress_done, nullptr, libavcodec_compress_tile, nullptr, diff --git a/src/video_compress/none.cpp b/src/video_compress/none.cpp index c139c157e..0490ff6c0 100644 --- a/src/video_compress/none.cpp +++ b/src/video_compress/none.cpp @@ -3,7 +3,7 @@ * @author Martin Pulec */ /* - * Copyright (c) 2012-2023 CESNET, z. s. p. o. + * Copyright (c) 2012-2025 CESNET * All rights reserved. * * Redistribution and use in source and binary forms, with or without @@ -46,7 +46,6 @@ #include "debug.h" #include "host.h" #include "lib_common.h" -#include "module.h" #include "video_codec.h" #include "video_compress.h" #include "video_frame.h" @@ -55,41 +54,34 @@ namespace { #define MAGIC 0x45bb3321 -static void none_compress_done(struct module *mod); +static void none_compress_done(void *state); struct state_video_compress_none { - struct module module_data; - uint32_t magic; }; -struct module * none_compress_init(struct module *parent, const char *) +void* none_compress_init(module *parent, const char *) { - struct state_video_compress_none *s; - - s = (struct state_video_compress_none *) malloc(sizeof(struct state_video_compress_none)); + (void) parent; + auto *s = (struct state_video_compress_none *) malloc( + sizeof(struct state_video_compress_none)); s->magic = MAGIC; - module_init_default(&s->module_data); - s->module_data.cls = MODULE_CLASS_DATA; - s->module_data.priv_data = s; - s->module_data.deleter = none_compress_done; - module_register(&s->module_data, parent); - return &s->module_data; + return s; } -std::shared_ptr none_compress(struct module *mod, std::shared_ptr tx) +std::shared_ptr none_compress(void *state, std::shared_ptr tx) { - struct state_video_compress_none *s = (struct state_video_compress_none *) mod->priv_data; + auto *s = (struct state_video_compress_none *) state; assert(s->magic == MAGIC); return tx; } -static void none_compress_done(struct module *mod) +static void none_compress_done(void *state) { - struct state_video_compress_none *s = (struct state_video_compress_none *) mod->priv_data; + auto *s = (struct state_video_compress_none *) state; assert(s->magic == MAGIC); @@ -97,8 +89,8 @@ static void none_compress_done(struct module *mod) } const struct video_compress_info none_info = { - "none", none_compress_init, + none_compress_done, none_compress, NULL, NULL, diff --git a/src/video_compress/uyvy.cpp b/src/video_compress/uyvy.cpp index ecf9c2585..fcaa03ffe 100644 --- a/src/video_compress/uyvy.cpp +++ b/src/video_compress/uyvy.cpp @@ -3,7 +3,7 @@ * @author Martin Pulec */ /* - * Copyright (c) 2013-2023 CESNET, z. s. p. o. + * Copyright (c) 2013-2025 CESNET * All rights reserved. * * Redistribution and use in source and binary forms, with or without @@ -43,7 +43,6 @@ #include "debug.h" #include "host.h" #include "lib_common.h" -#include "module.h" #include "utils/video_frame_pool.h" #include "video_compress.h" #include "video.h" @@ -107,8 +106,6 @@ static const char fp_display_rgba_to_yuv422_legacy[] = struct state_video_compress_uyvy { - struct module module_data; - unsigned int configured:1; struct video_desc saved_desc; @@ -126,13 +123,14 @@ struct state_video_compress_uyvy { }; int uyvy_configure_with(struct state_video_compress_uyvy *s, struct video_frame *tx); -static void uyvy_compress_done(struct module *mod); +static void uyvy_compress_done(void *mod); -struct module * uyvy_compress_init(struct module *parent, const char *) +void * +uyvy_compress_init(struct module *parent, const char *) { - struct state_video_compress_uyvy *s; - - s = (struct state_video_compress_uyvy *) malloc(sizeof(struct state_video_compress_uyvy)); + (void) parent; + auto *s = (struct state_video_compress_uyvy *) malloc( + sizeof(struct state_video_compress_uyvy)); if(!init_gl_context(&s->context, GL_CONTEXT_LEGACY)) abort(); @@ -156,13 +154,7 @@ struct module * uyvy_compress_init(struct module *parent, const char *) s->pool = new video_frame_pool(); - module_init_default(&s->module_data); - s->module_data.cls = MODULE_CLASS_DATA; - s->module_data.priv_data = s; - s->module_data.deleter = uyvy_compress_done; - module_register(&s->module_data, parent); - - return &s->module_data; + return s; } int uyvy_configure_with(struct state_video_compress_uyvy *s, struct video_frame *tx) @@ -227,12 +219,12 @@ int uyvy_configure_with(struct state_video_compress_uyvy *s, struct video_frame return true; } -shared_ptr uyvy_compress(struct module *mod, shared_ptr tx) +shared_ptr uyvy_compress(void *state, shared_ptr tx) { if (!tx) { return {}; } - struct state_video_compress_uyvy *s = (struct state_video_compress_uyvy *) mod->priv_data; + auto *s = (struct state_video_compress_uyvy *) state; gl_context_make_current(&s->context); @@ -286,9 +278,9 @@ shared_ptr uyvy_compress(struct module *mod, shared_ptrpriv_data; + auto *s = (struct state_video_compress_uyvy *) state; glDeleteFramebuffers(1, &s->fbo); glDeleteTextures(1, &s->texture_rgba); @@ -301,8 +293,8 @@ static void uyvy_compress_done(struct module *mod) } const struct video_compress_info uyvy_info = { - "UYVY", uyvy_compress_init, + uyvy_compress_done, uyvy_compress, NULL, NULL,