From 201a72bb167e7ba73894fb00da28d895c8f99c0b Mon Sep 17 00:00:00 2001 From: Martin Pulec Date: Tue, 22 Sep 2015 15:04:31 +0200 Subject: [PATCH] Video compress: use new module API --- Makefile.in | 10 +- configure.ac | 13 +- src/lib_common.cpp | 24 +++- src/lib_common.h | 1 + src/video_compress.cpp | 224 +++++------------------------- src/video_compress.h | 12 +- src/video_compress/cuda_dxt.cpp | 14 +- src/video_compress/cuda_dxt.h | 40 ------ src/video_compress/dxt_glsl.cpp | 13 +- src/video_compress/dxt_glsl.h | 40 ------ src/video_compress/jpeg.cpp | 13 +- src/video_compress/jpeg.h | 40 ------ src/video_compress/libavcodec.cpp | 13 +- src/video_compress/libavcodec.h | 40 ------ src/video_compress/none.cpp | 15 +- src/video_compress/none.h | 52 ------- src/video_compress/uyvy.cpp | 13 +- src/video_compress/uyvy.h | 40 ------ 18 files changed, 115 insertions(+), 502 deletions(-) delete mode 100644 src/video_compress/cuda_dxt.h delete mode 100644 src/video_compress/dxt_glsl.h delete mode 100644 src/video_compress/jpeg.h delete mode 100644 src/video_compress/libavcodec.h delete mode 100644 src/video_compress/none.h delete mode 100644 src/video_compress/uyvy.h diff --git a/Makefile.in b/Makefile.in index 2020eecdc..3fc713117 100644 --- a/Makefile.in +++ b/Makefile.in @@ -599,13 +599,13 @@ rtsp_server: @RTSP_SERVER_LIB_TARGET@ $(LINKER) $(LDFLAGS) -shared -Wl,-soname,module_display_sage.so $^ @SAGE_LIB@ -o $@ @RTDXT_COMPRESS_LIB_TARGET@: @GL_COMMON_OBJ@ @X_OBJ@ @RTDXT_COMMON_OBJ@ @RTDXT_COMPRESS_OBJ@ @RTDXT_COMMON_HEADERS@ - $(LINKER) $(LDFLAGS) -shared -Wl,-soname,vcompress_rtdxt.so.@video_compress_abi_version@ @GL_COMMON_OBJ@ @X_OBJ@ @RTDXT_COMMON_OBJ@ @RTDXT_COMPRESS_OBJ@ @RTDXT_LIB@ -o $@ + $(LINKER) $(LDFLAGS) -shared -Wl,-soname,module_vcompress_rtdxt.so @GL_COMMON_OBJ@ @X_OBJ@ @RTDXT_COMMON_OBJ@ @RTDXT_COMPRESS_OBJ@ @RTDXT_LIB@ -o $@ @UYVY_COMPRESS_LIB_TARGET@: @GL_COMMON_OBJ@ @X_OBJ@ @UYVY_COMPRESS_OBJ@ - $(LINKER) $(LDFLAGS) -shared -Wl,-soname,vcompress_uyvy.so.@video_compress_abi_version@ @GL_COMMON_OBJ@ @X_OBJ@ @UYVY_COMPRESS_OBJ@ -o $@ + $(LINKER) $(LDFLAGS) -shared -Wl,-soname,module_vcompress_uyvy.so @GL_COMMON_OBJ@ @X_OBJ@ @UYVY_COMPRESS_OBJ@ -o $@ @LIBAVCODEC_COMPRESS_LIB_TARGET@: @LIBAVCODEC_COMPRESS_OBJ@ - $(LINKER) $(LDFLAGS) -shared -Wl,-soname,vcompress_libavcodec.so.@video_compress_abi_version@ $^ @LIBAVCODEC_LIBS@ -o $@ + $(LINKER) $(LDFLAGS) -shared -Wl,-soname,module_vcompress_libavcodec.so $^ @LIBAVCODEC_LIBS@ -o $@ @LIBAVCODEC_DECOMPRESS_LIB_TARGET@: @LIBAVCODEC_DECOMPRESS_OBJ@ $(LINKER) $(LDFLAGS) -shared -Wl,-soname,module_vdecompress_libavcodec.so $^ @LIBAVCODEC_LIBS@ -o $@ @@ -614,10 +614,10 @@ rtsp_server: @RTSP_SERVER_LIB_TARGET@ $(LINKER) $(LDFLAGS) -shared -Wl,-soname,module_acompress.so $^ @LIBAVCODEC_LIBS@ -o $@ @JPEG_COMPRESS_LIB_TARGET@: @JPEG_COMPRESS_OBJ@ - $(LINKER) $(LDFLAGS) -shared -Wl,-soname,vcompress_jpeg.so.@video_compress_abi_version@ $^ @JPEG_LIB@ -o $@ + $(LINKER) $(LDFLAGS) -shared -Wl,-soname,module_vcompress_jpeg.so $^ @JPEG_LIB@ -o $@ @CUDA_DXT_COMPRESS_LIB_TARGET@: @CUDA_DXT_OBJ@ @CUDA_COMMON_OBJ@ - $(LINKER) $(LDFLAGS) -shared -Wl,-soname,vcompress_cuda_dxt.so.@video_compress_abi_version@ $^ @CUDA_DXT_LIB@ -o $@ + $(LINKER) $(LDFLAGS) -shared -Wl,-soname,module_vcompress_cuda_dxt.so $^ @CUDA_DXT_LIB@ -o $@ @RTDXT_DECOMPRESS_LIB_TARGET@: @GL_COMMON_OBJ@ @X_OBJ@ @RTDXT_COMMON_OBJ@ @RTDXT_DECOMPRESS_OBJ@ @RTDXT_COMMON_HEADERS@ $(LINKER) $(LDFLAGS) -shared -Wl,-soname,module_vdecompress_rtdxt.so @GL_COMMON_OBJ@ @X_OBJ@ @RTDXT_COMMON_OBJ@ @RTDXT_DECOMPRESS_OBJ@ @RTDXT_LIB@ -o $@ diff --git a/configure.ac b/configure.ac index 487826c17..463836b8e 100644 --- a/configure.ac +++ b/configure.ac @@ -440,13 +440,10 @@ then AC_DEFINE([BUILD_LIBRARIES], [1], [Build drivers as a standalone libraries]) fi -video_compress_abi_version=4 video_rxtx_abi_version=1 vo_pp_abi_version=3 -AC_DEFINE_UNQUOTED([VIDEO_COMPRESS_ABI_VERSION], $video_compress_abi_version, [Specifies ABI version for video compression]) AC_DEFINE_UNQUOTED([VIDEO_RXTX_ABI_VERSION], $video_rxtx_abi_version, [Specifies ABI version for video transmission]) AC_DEFINE_UNQUOTED([VO_PP_ABI_VERSION], $vo_pp_abi_version, [Specifies ABI version for video postprocess]) -AC_SUBST(video_compress_abi_version) AC_SUBST(vo_pp_abi_version) # ------------------------------------------------------------------------------------------------ @@ -1908,7 +1905,7 @@ then RTDXT_COMPRESS_OBJ="dxt_compress/dxt_encoder.o src/video_compress/dxt_glsl.o" RTDXT_DECOMPRESS_OBJ="dxt_compress/dxt_decoder.o src/video_decompress/dxt_glsl.o" DXT_GLSL_CFLAGS="-std=gnu99" - AC_SUBST(RTDXT_COMPRESS_LIB_TARGET, "lib/ultragrid/vcompress_rtdxt.so.$video_compress_abi_version") + AC_SUBST(RTDXT_COMPRESS_LIB_TARGET, "lib/ultragrid/module_vcompress_rtdxt.so") AC_SUBST(RTDXT_DECOMPRESS_LIB_TARGET, "lib/ultragrid/module_vdecompress_rtdxt.so") LIB_TARGETS="$LIB_TARGETS $RTDXT_COMPRESS_LIB_TARGET $RTDXT_DECOMPRESS_LIB_TARGET" LIB_OBJS="$LIB_OBJS $RTDXT_COMMON_OBJ $RTDXT_COMPRESS_OBJ $RTDXT_DECOMPRESS_OBJ" @@ -1960,7 +1957,7 @@ if test $uyvy = yes then AC_DEFINE([HAVE_COMPRESS_UYVY], [1], [Build with dummy UYVY compression]) UYVY_COMPRESS_OBJ="src/video_compress/uyvy.o" - AC_SUBST(UYVY_COMPRESS_LIB_TARGET, "lib/ultragrid/vcompress_uyvy.so.$video_compress_abi_version") + AC_SUBST(UYVY_COMPRESS_LIB_TARGET, "lib/ultragrid/module_vcompress_uyvy.so") LIB_TARGETS="$LIB_TARGETS $UYVY_COMPRESS_LIB_TARGET" LIB_OBJS="$LIB_OBJS $UYVY_COMPRESS_OBJ" DEFINE_GL @@ -2101,7 +2098,7 @@ then JPEG_COMPRESS_OBJ="src/video_compress/jpeg.o" JPEG_DECOMPRESS_OBJ="src/video_decompress/jpeg.o " AC_DEFINE([HAVE_JPEG], [1], [Build with JPEG support]) - AC_SUBST(JPEG_COMPRESS_LIB_TARGET, "lib/ultragrid/vcompress_jpeg.so.$video_compress_abi_version") + AC_SUBST(JPEG_COMPRESS_LIB_TARGET, "lib/ultragrid/module_vcompress_jpeg.so") AC_SUBST(JPEG_DECOMPRESS_LIB_TARGET, "lib/ultragrid/module_vdecompress_jpeg.so") LIB_TARGETS="$LIB_TARGETS $JPEG_COMPRESS_LIB_TARGET $JPEG_DECOMPRESS_LIB_TARGET" LIB_OBJS="$LIB_OBJS $JPEG_COMPRESS_OBJ $JPEG_DECOMPRESS_OBJ" @@ -2154,7 +2151,7 @@ then CUDA_DXT_INC=$CUDA_INC CUDA_DXT_OBJ="src/video_compress/cuda_dxt.o cuda_dxt/cuda_dxt.$CU_SUFFIX" AC_DEFINE([HAVE_CUDA_DXT], [1], [Build with CUDA DXT support]) - AC_SUBST(CUDA_DXT_COMPRESS_LIB_TARGET, "lib/ultragrid/vcompress_cuda_dxt.so.$video_compress_abi_version") + AC_SUBST(CUDA_DXT_COMPRESS_LIB_TARGET, "lib/ultragrid/module_vcompress_cuda_dxt.so") LIB_TARGETS="$LIB_TARGETS $CUDA_DXT_COMPRESS_LIB_TARGET" LIB_OBJS="$LIB_OBJS src/video_compress/cuda_dxt.o" ADD_CUDA_DXT_OBJ @@ -2667,7 +2664,7 @@ if test $libavcodec_req != no -a $found_libavcodec = yes -a $found_libavutil = y then LIBAVCODEC_OBJ="src/video_compress/libavcodec.o" AC_DEFINE([HAVE_LAVC], [1], [Build with LAVC support]) - AC_SUBST(LIBAVCODEC_COMPRESS_LIB_TARGET, "lib/ultragrid/vcompress_libavcodec.so.$video_compress_abi_version") + AC_SUBST(LIBAVCODEC_COMPRESS_LIB_TARGET, "lib/ultragrid/module_vcompress_libavcodec.so") AC_SUBST(LIBAVCODEC_DECOMPRESS_LIB_TARGET, "lib/ultragrid/module_vdecompress_libavcodec.so") AC_SUBST(LIBAVCODEC_AUDIO_CODEC_LIB_TARGET, "lib/ultragrid/module_acompress_libavcodec.so") diff --git a/src/lib_common.cpp b/src/lib_common.cpp index 0570f97b8..3050320bc 100644 --- a/src/lib_common.cpp +++ b/src/lib_common.cpp @@ -71,6 +71,7 @@ const map library_class_info = { { LIBRARY_CLASS_VIDEO_DISPLAY, { "Video display device", "display" }}, { LIBRARY_CLASS_AUDIO_COMPRESS, { "Audio compression", "acompress" }}, { LIBRARY_CLASS_VIDEO_DECOMPRESS, { "Video decompression", "vdecompress" }}, + { LIBRARY_CLASS_VIDEO_COMPRESS, { "Video compression", "vcompress" }}, }; static map lib_errors; @@ -165,7 +166,28 @@ struct lib_info { int abi_version; }; -static map> *libraries = nullptr; +// http://stackoverflow.com/questions/1801892/making-mapfind-operation-case-insensitive +/************************************************************************/ +/* Comparator for case-insensitive comparison in STL assos. containers */ +/************************************************************************/ +struct ci_less : std::binary_function +{ + // case-independent (ci) compare_less binary function + struct nocase_compare : public std::binary_function + { + bool operator() (const unsigned char& c1, const unsigned char& c2) const { + return tolower (c1) < tolower (c2); + } + }; + bool operator() (const std::string & s1, const std::string & s2) const { + return std::lexicographical_compare + (s1.begin (), s1.end (), // source range + s2.begin (), s2.end (), // dest range + nocase_compare ()); // comparison + } +}; + +static map> *libraries = nullptr; /** * The purpose of this initializor instead of ordinary static initialization is that register_video_capture_filter() diff --git a/src/lib_common.h b/src/lib_common.h index 9095f68f0..59813b93b 100644 --- a/src/lib_common.h +++ b/src/lib_common.h @@ -74,6 +74,7 @@ enum library_class { LIBRARY_CLASS_VIDEO_DISPLAY, LIBRARY_CLASS_AUDIO_COMPRESS, LIBRARY_CLASS_VIDEO_DECOMPRESS, + LIBRARY_CLASS_VIDEO_COMPRESS, }; void open_all(const char *pattern); const void *load_library(const char *name, enum library_class, int abi_version); diff --git a/src/video_compress.cpp b/src/video_compress.cpp index fe3563242..de0da15a6 100644 --- a/src/video_compress.cpp +++ b/src/video_compress.cpp @@ -58,44 +58,16 @@ #include "utils/worker.h" #include "video.h" #include "video_compress.h" -#include "video_compress/cuda_dxt.h" -#include "video_compress/dxt_glsl.h" -#include "video_compress/libavcodec.h" -#include "video_compress/jpeg.h" -#include "video_compress/none.h" -#include "video_compress/uyvy.h" #include "lib_common.h" using namespace std; namespace { - -/* *_str are symbol names inside library */ -/** - * @brief This struct describes individual compress module - * - * Initially, in this struct are either callbacks or functions names. - * For actual initialization of the callbacks/names, @ref MK_STATIC and @ref MK_NAME - * macros should be used. After initialization, callbacks are set. - * - * There are 2 APIs available - drivers are required to implement one of them. They - * can implement either @ref compress_frame_func or @ref compress_tile_func function. - * The other* shall then be NULL. - */ -struct compress_t { - const char * library_name; ///< If module is dynamically loadable, this is the name of library. - - compress_info_t * compress_info; - const char * compress_info_symbol_name; - - void *handle; ///< for modular build, dynamically loaded library handle -}; - /** * @brief This structure represents real internal compress state */ struct compress_state_real { - struct compress_t *handle; ///< handle for the driver + const video_compress_info *funcs; ///< handle for the driver struct module **state; ///< driver internal states unsigned int state_count; ///< count of compress states (equal to tiles' count) char compress_options[1024]; ///< compress options (for reconfiguration) @@ -122,7 +94,6 @@ typedef struct compress_state compress_state_proxy; ///< Used to emphasize that */ struct module compress_init_noerr; -static void init_compressions(void); static shared_ptr compress_frame_tiles(struct compress_state_real *s, shared_ptr frame, struct module *parent); static int compress_init_real(struct module *parent, const char *config_string, @@ -130,142 +101,25 @@ static int compress_init_real(struct module *parent, const char *config_string, static void compress_done_real(struct compress_state_real *s); static void compress_done(struct module *mod); -/** - * @brief This table contains list of video compress devices compiled with this UltraGrid version. - * @copydetails decoders - */ -struct compress_t compress_modules[] = { -#ifndef UV_IN_YURI -#if defined HAVE_DXT_GLSL || defined BUILD_LIBRARIES - { - "rtdxt", - MK_NAME_REF(rtdxt_info), - NULL, - }, -#endif -#if defined HAVE_JPEG || defined BUILD_LIBRARIES - { - "jpeg", - MK_NAME_REF(jpeg_info), - NULL, - }, -#endif -#if defined HAVE_COMPRESS_UYVY || defined BUILD_LIBRARIES - { - "uyvy", - MK_NAME_REF(uyvy_info), - NULL, - }, -#endif -#if defined HAVE_LAVC || defined BUILD_LIBRARIES - { - "libavcodec", - MK_NAME_REF(libavcodec_info), - NULL, - }, -#endif -#if defined HAVE_CUDA_DXT || defined BUILD_LIBRARIES - { - "cuda_dxt", - MK_NAME_REF(cuda_dxt_info), - NULL, - }, -#endif -#endif - { - NULL, - MK_STATIC_REF(none_info), - NULL, - }, -}; - -#define MAX_COMPRESS_MODULES (sizeof(compress_modules)/sizeof(struct compress_t)) - -/// @brief List of available display devices. -/// -/// initialized automatically -static struct compress_t *available_compress_modules[MAX_COMPRESS_MODULES]; -/// @brief Count of @ref available_compress_modules. -/// -/// initialized automatically -static int compress_modules_count = 0; - -#ifdef BUILD_LIBRARIES -#include -/** Opens compress library of given name. */ -static void *compress_open_library(const char *compress_name) -{ - char name[128]; - snprintf(name, sizeof(name), "vcompress_%s.so.%d", compress_name, VIDEO_COMPRESS_ABI_VERSION); - - return open_library(name); -} - -/** For a given device, load individual functions from library handle (previously opened). */ -static int compress_fill_symbols(struct compress_t *compression) -{ - void *handle = compression->handle; - - compression->compress_info = (compress_info_t *) - dlsym(handle, compression->compress_info_symbol_name); - - if(!compression->compress_info) { - fprintf(stderr, "Library %s opening error: %s \n", compression->library_name, dlerror()); - return FALSE; - } - return TRUE; -} -#endif - -/// @brief guard of @ref available_compress_modules initialization -static pthread_once_t compression_list_initialized = PTHREAD_ONCE_INIT; - -/// @brief initializes @ref available_compress_modules initialization -static void init_compressions(void) -{ - unsigned int i; - for(i = 0; i < sizeof(compress_modules)/sizeof(struct compress_t); ++i) { -#ifdef BUILD_LIBRARIES - if(compress_modules[i].library_name) { - int ret; - compress_modules[i].handle = compress_open_library( - compress_modules[i].library_name); - if(!compress_modules[i].handle) continue; - ret = compress_fill_symbols(&compress_modules[i]); - if(!ret) { - fprintf(stderr, "Opening symbols from library %s failed.\n", - compress_modules[i].library_name); - continue; - } - } -#endif - available_compress_modules[compress_modules_count] = &compress_modules[i]; - compress_modules_count++; - } -} - /// @brief Displays list of available compressions. void show_compress_help() { - int i; - pthread_once(&compression_list_initialized, init_compressions); printf("Possible compression modules (see '-c :help' for options):\n"); - for(i = 0; i < compress_modules_count; ++i) { - printf("\t%s\n", available_compress_modules[i]->compress_info->name); - } + list_modules(LIBRARY_CLASS_VIDEO_COMPRESS, VIDEO_COMPRESS_ABI_VERSION); } list get_compress_capabilities() { list ret; - pthread_once(&compression_list_initialized, init_compressions); + auto compressions = get_libraries_for_class(LIBRARY_CLASS_VIDEO_COMPRESS, VIDEO_COMPRESS_ABI_VERSION); - for (int i = 0; i < compress_modules_count; ++i) { - auto presets = available_compress_modules[i]->compress_info->get_presets(); + for (auto it : compressions) { + auto vci = static_cast(it.second); + auto presets = vci->get_presets(); for (auto const & it : presets) { auto new_elem = it; - new_elem.name = string(available_compress_modules[i]->compress_info->name) + new_elem.name = string(vci->name) + ":" + it.name; ret.push_back(new_elem); } @@ -372,8 +226,8 @@ static int compress_init_real(struct module *parent, const char *config_string, struct compress_state_real **state) { struct compress_state_real *s; - struct video_compress_params params; - const char *compress_options = NULL; + string compress_name; + string compress_options; if(!config_string) return -1; @@ -384,36 +238,31 @@ static int compress_init_real(struct module *parent, const char *config_string, return 1; } - pthread_once(&compression_list_initialized, init_compressions); - - memset(¶ms, 0, sizeof(params)); - - s = (struct compress_state_real *) calloc(1, sizeof(struct compress_state_real)); - - s->state_count = 1; - - for (int i = 0; i < compress_modules_count; ++i) { - if(strncasecmp(config_string, available_compress_modules[i]->compress_info->name, - strlen(available_compress_modules[i]->compress_info->name)) == 0) { - s->handle = available_compress_modules[i]; - if (config_string[strlen(available_compress_modules[i]->compress_info->name)] == ':') - compress_options = config_string + - strlen(available_compress_modules[i]->compress_info->name) + 1; - else - compress_options = ""; - } + char *tmp = strdup(config_string); + if (strchr(tmp, ':')) { + char *opts = strchr(tmp, ':') + 1; + *strchr(tmp, ':') = '\0'; + compress_options = opts; } - if(!s->handle) { + compress_name = tmp; + free(tmp); + + auto vci = static_cast(load_library(compress_name.c_str(), LIBRARY_CLASS_VIDEO_COMPRESS, VIDEO_COMPRESS_ABI_VERSION)); + if(!vci) { fprintf(stderr, "Unknown compression: %s\n", config_string); - free(s); return -1; } - strncpy(s->compress_options, compress_options, sizeof(s->compress_options) - 1); - s->compress_options[sizeof(s->compress_options) - 1] = '\0'; - params.cfg = s->compress_options; - if(s->handle->compress_info->init_func) { + + s = (struct compress_state_real *) calloc(1, sizeof(struct compress_state_real)); + s->state_count = 1; + + s->funcs = vci; + + strncpy(s->compress_options, compress_options.c_str(), sizeof(s->compress_options) - 1); + + if(s->funcs->init_func) { s->state = (struct module **) calloc(1, sizeof(struct module *)); - s->state[0] = s->handle->compress_info->init_func(parent, ¶ms); + s->state[0] = s->funcs->init_func(parent, s->compress_options); if(!s->state[0]) { fprintf(stderr, "Compression initialization failed: %s\n", config_string); free(s->state); @@ -443,7 +292,7 @@ static int compress_init_real(struct module *parent, const char *config_string, const char *get_compress_name(compress_state_proxy *proxy) { if(proxy) - return proxy->ptr->handle->compress_info->name; + return proxy->ptr->funcs->name; else return NULL; } @@ -474,9 +323,9 @@ void compress_frame(compress_state_proxy *proxy, shared_ptr frame) struct compress_state_real *s = proxy->ptr; shared_ptr sync_api_frame; - if (s->handle->compress_info->compress_frame_func) { - sync_api_frame = s->handle->compress_info->compress_frame_func(s->state[0], frame); - } else if(s->handle->compress_info->compress_tile_func) { + if (s->funcs->compress_frame_func) { + sync_api_frame = s->funcs->compress_frame_func(s->state[0], frame); + } else if(s->funcs->compress_tile_func) { sync_api_frame = compress_frame_tiles(s, frame, &proxy->mod); } else { sync_api_frame = {}; @@ -531,13 +380,10 @@ static void *compress_tile_callback(void *arg) { static shared_ptr compress_frame_tiles(struct compress_state_real *s, shared_ptr frame, struct module *parent) { - struct video_compress_params params; - memset(¶ms, 0, sizeof(params)); - params.cfg = s->compress_options; if(frame->tile_count != s->state_count) { s->state = (struct module **) realloc(s->state, frame->tile_count * sizeof(struct module *)); for(unsigned int i = s->state_count; i < frame->tile_count; ++i) { - s->state[i] = s->handle->compress_info->init_func(parent, ¶ms); + s->state[i] = s->funcs->init_func(parent, s->compress_options); if(!s->state[i]) { fprintf(stderr, "Compression initialization failed\n"); return NULL; @@ -557,7 +403,7 @@ static shared_ptr compress_frame_tiles(struct compress_state_real * struct compress_worker_data *data = &data_tile[i]; data->state = s->state[i]; data->frame = separate_tiles[i]; - data->callback = s->handle->compress_info->compress_tile_func; + data->callback = s->funcs->compress_tile_func; task_handle[i] = task_run_async(compress_tile_callback, data); } diff --git a/src/video_compress.h b/src/video_compress.h index feff7a514..98c53430b 100644 --- a/src/video_compress.h +++ b/src/video_compress.h @@ -46,6 +46,8 @@ #include "types.h" +#define VIDEO_COMPRESS_ABI_VERSION 5 + #ifdef __cplusplus extern "C" { #endif @@ -58,10 +60,6 @@ extern struct module compress_init_noerr; /** @name API for capture modules * @{ */ -struct video_compress_params { - const char *cfg; -}; - /** * @brief Initializes video compression * @@ -70,9 +68,7 @@ struct video_compress_params { * @return driver internal state */ typedef struct module *(*compress_init_t)(struct module *parent, - const struct video_compress_params *params); - -typedef bool (*compress_is_supported_t)(void); + const char *cfg); /// @} void show_compress_help(void); @@ -129,7 +125,7 @@ struct compress_preset { compress_prop dec_prop; }; -struct compress_info_t { +struct video_compress_info { const char * name; ///< compress (unique) name compress_init_t init_func; ///< compress driver initialization function compress_frame_t compress_frame_func; ///< compress function for Frame API diff --git a/src/video_compress/cuda_dxt.cpp b/src/video_compress/cuda_dxt.cpp index 97fbe4d48..1fb123ed1 100644 --- a/src/video_compress/cuda_dxt.cpp +++ b/src/video_compress/cuda_dxt.cpp @@ -41,13 +41,12 @@ #include "config_win32.h" #endif // HAVE_CONFIG_H -#include "video_compress/cuda_dxt.h" - #include "cuda_dxt/cuda_dxt.h" #include "cuda_wrapper.h" #include "debug.h" #include "host.h" +#include "lib_common.h" #include "module.h" #include "utils/video_frame_pool.h" #include "video.h" @@ -88,11 +87,10 @@ struct state_video_compress_cuda_dxt { static void cuda_dxt_compress_done(struct module *mod); struct module *cuda_dxt_compress_init(struct module *parent, - const struct video_compress_params *params) + const char *fmt) { state_video_compress_cuda_dxt *s = new state_video_compress_cuda_dxt(); - const char *fmt = params->cfg; s->out_codec = DXT1; if (fmt && fmt[0] != '\0') { @@ -284,9 +282,7 @@ static void cuda_dxt_compress_done(struct module *mod) delete s; } -} // end of anonymous namespace - -struct compress_info_t cuda_dxt_info = { +const struct video_compress_info cuda_dxt_info = { "cuda_dxt", cuda_dxt_compress_init, NULL, @@ -294,3 +290,7 @@ struct compress_info_t cuda_dxt_info = { [] { return list{}; } }; +REGISTER_MODULE(cuda_dxt, &cuda_dxt_info, LIBRARY_CLASS_VIDEO_COMPRESS, VIDEO_COMPRESS_ABI_VERSION); + +} // end of anonymous namespace + diff --git a/src/video_compress/cuda_dxt.h b/src/video_compress/cuda_dxt.h deleted file mode 100644 index d5b643d83..000000000 --- a/src/video_compress/cuda_dxt.h +++ /dev/null @@ -1,40 +0,0 @@ -/** - * @file video_compress/cuda_dxt.h - * @author Martin Pulec - */ -/* - * Copyright (c) 2013-2014 CESNET, z. s. p. o. - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, is permitted provided that the following conditions - * are met: - * - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * - * 3. Neither the name of CESNET nor the names of its contributors may be - * used to endorse or promote products derived from this software without - * specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE AUTHORS AND CONTRIBUTORS - * "AS IS" AND ANY EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, - * BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY - * AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO - * EVENT SHALL THE AUTHORS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, - * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES - * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR - * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN - * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR - * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, - * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ - -struct compress_info_t; -extern compress_info_t cuda_dxt_info; - diff --git a/src/video_compress/dxt_glsl.cpp b/src/video_compress/dxt_glsl.cpp index ce60ae61a..395d365f6 100644 --- a/src/video_compress/dxt_glsl.cpp +++ b/src/video_compress/dxt_glsl.cpp @@ -51,11 +51,11 @@ #include "dxt_compress/dxt_encoder.h" #include "dxt_compress/dxt_util.h" #include "host.h" +#include "lib_common.h" #include "module.h" #include "utils/video_frame_pool.h" #include "video.h" #include "video_compress.h" -#include "video_compress/dxt_glsl.h" #include @@ -217,10 +217,9 @@ static bool dxt_is_supported() } } -struct module *dxt_glsl_compress_init(struct module *parent, const struct video_compress_params *params) +struct module *dxt_glsl_compress_init(struct module *parent, const char *opts) { struct state_video_compress_rtdxt *s; - const char *opts = params->cfg; if(strcmp(opts, "help") == 0) { printf("DXT GLSL comperssion usage:\n"); @@ -324,9 +323,7 @@ static void dxt_glsl_compress_done(struct module *mod) delete s; } -} // end of anonymous namespace - -struct compress_info_t rtdxt_info = { +const struct video_compress_info rtdxt_info = { "RTDXT", dxt_glsl_compress_init, dxt_glsl_compress, @@ -341,3 +338,7 @@ struct compress_info_t rtdxt_info = { } }; +REGISTER_MODULE(rtdxt, &rtdxt_info, LIBRARY_CLASS_VIDEO_COMPRESS, VIDEO_COMPRESS_ABI_VERSION); + +} // end of anonymous namespace + diff --git a/src/video_compress/dxt_glsl.h b/src/video_compress/dxt_glsl.h deleted file mode 100644 index 4b7fba76a..000000000 --- a/src/video_compress/dxt_glsl.h +++ /dev/null @@ -1,40 +0,0 @@ -/** - * @file video_compress/dxt_glsl.h - * @author Martin Pulec - */ -/* - * Copyright (c) 2011-2014 CESNET, z. s. p. o. - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, is permitted provided that the following conditions - * are met: - * - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * - * 3. Neither the name of CESNET nor the names of its contributors may be - * used to endorse or promote products derived from this software without - * specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE AUTHORS AND CONTRIBUTORS - * "AS IS" AND ANY EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, - * BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY - * AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO - * EVENT SHALL THE AUTHORS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, - * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES - * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR - * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN - * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR - * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, - * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ - -struct compress_info_t; -extern compress_info_t rtdxt_info; - diff --git a/src/video_compress/jpeg.cpp b/src/video_compress/jpeg.cpp index a2d94f311..c270629e2 100644 --- a/src/video_compress/jpeg.cpp +++ b/src/video_compress/jpeg.cpp @@ -45,7 +45,7 @@ #include "host.h" #include "video_compress.h" #include "module.h" -#include "video_compress/jpeg.h" +#include "lib_common.h" #include "libgpujpeg/gpujpeg_encoder.h" #include "utils/video_frame_pool.h" #include "video.h" @@ -236,10 +236,9 @@ static bool parse_fmt(struct state_video_compress_jpeg *s, char *fmt) return true; } -struct module * jpeg_compress_init(struct module *parent, const struct video_compress_params *params) +struct module * jpeg_compress_init(struct module *parent, const char *opts) { struct state_video_compress_jpeg *s; - const char *opts = params->cfg; if(opts && strcmp(opts, "help") == 0) { printf("JPEG comperssion usage:\n"); @@ -387,9 +386,7 @@ static void cleanup_state(struct state_video_compress_jpeg *s) s->encoder = NULL; } -} // end of anonymous namespace - -struct compress_info_t jpeg_info = { +const struct video_compress_info jpeg_info = { "JPEG", jpeg_compress_init, jpeg_compress, @@ -406,3 +403,7 @@ struct compress_info_t jpeg_info = { } }; +REGISTER_MODULE(jpeg, &jpeg_info, LIBRARY_CLASS_VIDEO_COMPRESS, VIDEO_COMPRESS_ABI_VERSION); + +} // end of anonymous namespace + diff --git a/src/video_compress/jpeg.h b/src/video_compress/jpeg.h deleted file mode 100644 index ce7a3a64b..000000000 --- a/src/video_compress/jpeg.h +++ /dev/null @@ -1,40 +0,0 @@ -/** - * @file video_compress/jpeg.h - * @author Martin Pulec - */ -/* - * Copyright (c) 2011-2014 CESNET, z. s. p. o. - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, is permitted provided that the following conditions - * are met: - * - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * - * 3. Neither the name of CESNET nor the names of its contributors may be - * used to endorse or promote products derived from this software without - * specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE AUTHORS AND CONTRIBUTORS - * "AS IS" AND ANY EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, - * BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY - * AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO - * EVENT SHALL THE AUTHORS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, - * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES - * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR - * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN - * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR - * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, - * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ - -struct compress_info_t; -extern compress_info_t jpeg_info; - diff --git a/src/video_compress/libavcodec.cpp b/src/video_compress/libavcodec.cpp index 001ad96e6..a8d8b786c 100644 --- a/src/video_compress/libavcodec.cpp +++ b/src/video_compress/libavcodec.cpp @@ -44,12 +44,12 @@ #endif // HAVE_CONFIG_H #include "libavcodec_common.h" -#include "video_compress/libavcodec.h" #include #include "debug.h" #include "host.h" +#include "lib_common.h" #include "messaging.h" #include "module.h" #include "utils/misc.h" @@ -341,10 +341,9 @@ static list get_libavcodec_presets() { return ret; } -struct module * libavcodec_compress_init(struct module *parent, const struct video_compress_params *params) +struct module * libavcodec_compress_init(struct module *parent, const char *opts) { struct state_video_compress_libav *s; - const char *opts = params->cfg; s = new state_video_compress_libav(); s->lavcd_global_lock = rm_acquire_shared_lock(LAVCD_LOCK_NAME); @@ -1184,9 +1183,7 @@ static void libavcodec_check_messages(struct state_video_compress_libav *s) } -} // end of anonymous namespace - -struct compress_info_t libavcodec_info = { +const struct video_compress_info libavcodec_info = { "libavcodec", libavcodec_compress_init, NULL, @@ -1194,3 +1191,7 @@ struct compress_info_t libavcodec_info = { get_libavcodec_presets, }; +REGISTER_MODULE(libavcodec, &libavcodec_info, LIBRARY_CLASS_VIDEO_COMPRESS, VIDEO_COMPRESS_ABI_VERSION); + +} // end of anonymous namespace + diff --git a/src/video_compress/libavcodec.h b/src/video_compress/libavcodec.h deleted file mode 100644 index 9ccf0cb72..000000000 --- a/src/video_compress/libavcodec.h +++ /dev/null @@ -1,40 +0,0 @@ -/** - * @file video_compress/libavcodec.h - * @author Martin Pulec - */ -/* - * Copyright (c) 2013-2014 CESNET, z. s. p. o. - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, is permitted provided that the following conditions - * are met: - * - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * - * 3. Neither the name of CESNET nor the names of its contributors may be - * used to endorse or promote products derived from this software without - * specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE AUTHORS AND CONTRIBUTORS - * "AS IS" AND ANY EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, - * BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY - * AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO - * EVENT SHALL THE AUTHORS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, - * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES - * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR - * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN - * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR - * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, - * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ - -struct compress_info_t; -extern compress_info_t libavcodec_info; - diff --git a/src/video_compress/none.cpp b/src/video_compress/none.cpp index 70f7f6da1..92a873506 100644 --- a/src/video_compress/none.cpp +++ b/src/video_compress/none.cpp @@ -50,12 +50,11 @@ #include "config_unix.h" #endif /* HAVE_CONFIG_H */ -#include "none.h" - #include #include "debug.h" #include "host.h" +#include "lib_common.h" #include "module.h" #include "video_codec.h" #include "video_compress.h" @@ -73,10 +72,8 @@ struct state_video_compress_none { uint32_t magic; }; -struct module * none_compress_init(struct module *parent, const struct video_compress_params *params) +struct module * none_compress_init(struct module *parent, const char *) { - UNUSED(params); - struct state_video_compress_none *s; s = (struct state_video_compress_none *) malloc(sizeof(struct state_video_compress_none)); @@ -108,9 +105,7 @@ static void none_compress_done(struct module *mod) free(s); } -} // end of anonymous namespace - -struct compress_info_t none_info = { +const struct video_compress_info none_info = { "none", none_compress_init, none_compress, @@ -123,3 +118,7 @@ struct compress_info_t none_info = { } }; +REGISTER_MODULE(none, &none_info, LIBRARY_CLASS_VIDEO_COMPRESS, VIDEO_COMPRESS_ABI_VERSION); + +} // end of anonymous namespace + diff --git a/src/video_compress/none.h b/src/video_compress/none.h deleted file mode 100644 index f740434ef..000000000 --- a/src/video_compress/none.h +++ /dev/null @@ -1,52 +0,0 @@ -/** - * @file none.h - * @author Martin Benes - * @author Lukas Hejtmanek - * @author Petr Holub - * @author Milos Liska - * @author Jiri Matela - * @author Dalibor Matura <255899@mail.muni.cz> - * @author Martin Pulec - * @author Ian Wesley-Smith - */ -/* - * Copyright (c) 2005-2014, CESNET z. s. p. o. - * - * Redistribution and use in source and binary forms, with or without - * modification, is permitted provided that the following conditions - * are met: - * - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * - * 3. All advertising materials mentioning features or use of this software - * must display the following acknowledgement: - * - * This product includes software developed by CESNET z.s.p.o. - * - * 4. Neither the name of the CESNET nor the names of its contributors may be - * used to endorse or promote products derived from this software without - * specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE AUTHORS AND CONTRIBUTORS - * "AS IS" AND ANY EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, - * BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY - * AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO - * EVENT SHALL THE AUTHORS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, - * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES - * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR - * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN - * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR - * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, - * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - * - */ - -struct compress_info_t; -extern compress_info_t none_info; - diff --git a/src/video_compress/uyvy.cpp b/src/video_compress/uyvy.cpp index 9db19280f..ba7191a60 100644 --- a/src/video_compress/uyvy.cpp +++ b/src/video_compress/uyvy.cpp @@ -42,10 +42,10 @@ #endif // HAVE_CONFIG_H #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_compress/uyvy.h" #include "compat/platform_semaphore.h" #include "video.h" #include @@ -136,9 +136,8 @@ 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); -struct module * uyvy_compress_init(struct module *parent, const struct video_compress_params *params) +struct module * uyvy_compress_init(struct module *parent, const char *) { - UNUSED(params); struct state_video_compress_uyvy *s; s = (struct state_video_compress_uyvy *) malloc(sizeof(struct state_video_compress_uyvy)); @@ -344,9 +343,7 @@ static void uyvy_compress_done(struct module *mod) free(s); } -} // end of anonymous namespace - -struct compress_info_t uyvy_info = { +const struct video_compress_info uyvy_info = { "UYVY", uyvy_compress_init, uyvy_compress, @@ -354,3 +351,7 @@ struct compress_info_t uyvy_info = { [] {return list{}; } }; +REGISTER_MODULE(uyvy, &uyvy_info, LIBRARY_CLASS_VIDEO_COMPRESS, VIDEO_COMPRESS_ABI_VERSION); + +} // end of anonymous namespace + diff --git a/src/video_compress/uyvy.h b/src/video_compress/uyvy.h deleted file mode 100644 index 2b4096c15..000000000 --- a/src/video_compress/uyvy.h +++ /dev/null @@ -1,40 +0,0 @@ -/** - * @file video_compress/uyvy.h - * @author Martin Pulec - */ -/* - * Copyright (c) 2012-2014 CESNET, z. s. p. o. - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, is permitted provided that the following conditions - * are met: - * - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * - * 3. Neither the name of CESNET nor the names of its contributors may be - * used to endorse or promote products derived from this software without - * specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE AUTHORS AND CONTRIBUTORS - * "AS IS" AND ANY EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, - * BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY - * AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO - * EVENT SHALL THE AUTHORS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, - * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES - * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR - * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN - * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR - * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, - * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ - -struct compress_info_t; -extern compress_info_t uyvy_info; -