From bdce8d7ae82ca3696272581176d297b6043024d8 Mon Sep 17 00:00:00 2001 From: Martin Pulec Date: Mon, 30 Sep 2024 11:07:37 +0200 Subject: [PATCH] tools: add ug_stub.c to substitute host.cpp Because host.cpp has extensive dependencies on UG internals, it is a bit tricky to link-in. Created a replacement instead. --- src/libavcodec/lavc_common.c | 7 +------ src/utils/color_out.cpp | 6 ------ tools/Makefile | 3 ++- tools/ug_stub.c | 21 +++++++++++++++++++++ 4 files changed, 24 insertions(+), 13 deletions(-) create mode 100644 tools/ug_stub.c diff --git a/src/libavcodec/lavc_common.c b/src/libavcodec/lavc_common.c index 1e2adbf36..6683bc954 100644 --- a/src/libavcodec/lavc_common.c +++ b/src/libavcodec/lavc_common.c @@ -178,18 +178,13 @@ static void av_log_ug_callback(void *avcl, int av_level, const char *fmt, va_lis buf[0] = '\0'; } -#ifdef HAVE_CONFIG_H // built inside UG ADD_TO_PARAM("lavc-log-level", "* lavc-log-level=\n" " Set libavcodec log level (FFmpeg range semantics, bypasses UG logger)\n" " - 'D' - use FFmpeg default log handler\n"); -#endif /// Sets specified log level either given explicitly or from UG-wide log_level void ug_set_av_logging() { - const char *param = NULL; -#ifdef HAVE_CONFIG_H // built inside UG - param = get_commandline_param("lavc-log-level"); -#endif + const char *param = get_commandline_param("lavc-log-level"); if (param == NULL) { av_log_set_callback(av_log_ug_callback); return; diff --git a/src/utils/color_out.cpp b/src/utils/color_out.cpp index 4994fbcb0..b3e74cf13 100644 --- a/src/utils/color_out.cpp +++ b/src/utils/color_out.cpp @@ -125,21 +125,16 @@ static bool isMsysPty(int fd) { } #endif // defined _WIN32 -// conditional include here (and below) is to allow compilation outside UG -// without the need to link with host.o, which seems to be tricky -#ifdef HAVE_CONFIG_H ADD_TO_PARAM("log-color", "* log-color[=no]\n" " Force enable/disable ANSI text formatting.\n"); ADD_TO_PARAM("log-nocolor", "* log-nocolor\n" " Force disable ANSI text formatting.\n"); -#endif /** * @returns whether stdout can process ANSI escape sequences */ static bool is_output_color() { -#ifdef HAVE_CONFIG_H const char *const param_val = get_commandline_param("log-color"); if (param_val != nullptr) { return strcmp(param_val, "no") != 0; @@ -150,7 +145,6 @@ is_output_color() "'log-color=no' instead\n"); return false; } -#endif const char *env_val = getenv("ULTRAGRID_COLOR_OUT"); if (env_val != nullptr && strlen(env_val) > 0) { return strcmp(env_val, "0") != 0; diff --git a/tools/Makefile b/tools/Makefile index 32493512b..9303e1eb2 100644 --- a/tools/Makefile +++ b/tools/Makefile @@ -15,7 +15,8 @@ TARGETS=astat_lib astat_test benchmark_ff_convs convert decklink_temperature \ COMMON_OBJS = src/color.o src/debug.o src/video_codec.o src/pixfmt_conv.o \ src/utils/color_out.o src/utils/misc.o src/video_frame.o \ - src/utils/pam.o src/utils/y4m.o + src/utils/pam.o src/utils/y4m.o \ + ug_stub.o OBJS=$(shell find . -name '*.o') diff --git a/tools/ug_stub.c b/tools/ug_stub.c new file mode 100644 index 000000000..bdf90bc2e --- /dev/null +++ b/tools/ug_stub.c @@ -0,0 +1,21 @@ +/** + * @file + * replacement for UltraGrid functions/global objects that are not linked-in, + * usually the ones located in host.cpp + */ + +#include + +const char * +get_commandline_param(const char *key) +{ + (void) key; + return NULL; +} + +void +register_param(const char *param, const char *doc) +{ + (void) param; + (void) doc; +}