diff --git a/src/main.cpp b/src/main.cpp index c2a3f5725..70574c525 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -318,10 +318,8 @@ static void *capture_thread(void *arg) struct wait_obj *wait_obj = wait_obj_init(); steady_clock::time_point t0 = steady_clock::now(); int frames = 0; - char *print_fps_prefix = vidcap_get_fps_print_prefix(uv->capture_device) ? strdupa(vidcap_get_fps_print_prefix(uv->capture_device)) : NULL; - if (print_fps_prefix && print_fps_prefix[strlen(print_fps_prefix) - 1] == ' ') { // trim trailing ' ' - print_fps_prefix[strlen(print_fps_prefix) - 1] = '\0'; - } + const char *print_fps_prefix = + vidcap_get_fps_print_prefix(uv->capture_device); while (!uv->should_exit_capture) { /* Capture and transmit video... */ diff --git a/src/utils/macros.h b/src/utils/macros.h index 2e064fc7f..7e477179b 100644 --- a/src/utils/macros.h +++ b/src/utils/macros.h @@ -128,6 +128,7 @@ /// the following limits are used mostly for static array allocations enum { MAX_CPU_CORES = 256, ///< maximal expected CPU core count + SHORT_STR = 128, STR_LEN = 2048, ///< "standard" string length placeholder }; diff --git a/src/video_capture.cpp b/src/video_capture.cpp index 0089da683..b864f7962 100644 --- a/src/video_capture.cpp +++ b/src/video_capture.cpp @@ -13,7 +13,7 @@ * @ingroup vidcap */ /* - * Copyright (c) 2005-2023 CESNET, z. s. p. o. + * Copyright (c) 2005-2024 CESNET * Copyright (c) 2001-2004 University of Southern California * * Redistribution and use in source and binary forms, with or without @@ -61,6 +61,7 @@ #include "debug.h" #include "lib_common.h" #include "module.h" +#include "utils/macros.h" #include "video_capture.h" #include "video_capture_params.h" @@ -229,12 +230,26 @@ struct video_frame *vidcap_grab(struct vidcap *state, struct audio_frame **audio } /** - * @brief If not-NULL returned, display doesn't hae own FPS indicator and wants - * to use a generic one (prefixed with returned module name) + * @returns nullptr if display has own FPS indicator + * @returns otherwise the prefix (without trailing space, eg. "[GL]") to be used + * in a generic fps indicator */ const char *vidcap_get_fps_print_prefix(struct vidcap *state) { assert(state->magic == VIDCAP_MAGIC); - return state->funcs->generic_fps_indicator_prefix; + if (state->funcs->generic_fps_indicator_prefix == NULL) { + return NULL; + } + thread_local char buf[SHORT_STR]; + + unsigned len = snprintf(buf, sizeof buf, "%s", + state->funcs->generic_fps_indicator_prefix); + if (len > sizeof buf - 1) { // truncated + len = sizeof buf - 1; + } + if (len > 0 && buf[len - 1] == ' ') { // trim trailing ' ' + buf[len - 1] = '\0'; + } + return buf; }