From fdcca0c76b8974235197303ba719e5cce9a2defa Mon Sep 17 00:00:00 2001 From: Joose Sainio Date: Mon, 17 Jun 2024 12:24:24 +0300 Subject: [PATCH] Add option for skipping input, when encoding real-time input but the encoder is not fast enough also clean up CMakeLists.txt --- CMakeLists.txt | 3 --- src/cli.c | 3 +++ src/cli.h | 2 ++ src/encmain.c | 11 ++++++++++- 4 files changed, 15 insertions(+), 4 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 87d56401..cad2a70e 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -144,7 +144,6 @@ endif() target_include_directories(uvg266 PUBLIC src) target_include_directories(uvg266 PUBLIC src/extras) target_include_directories(uvg266 PUBLIC src/strategies) -target_include_directories(uvg266 PUBLIC "G:/Local/sainio/Documents/libzmq/out/install/include") file(GLOB LIB_SOURCES_STRATEGIES_AVX2 RELATIVE ${PROJECT_SOURCE_DIR} "src/strategies/avx2/*.c") file(GLOB LIB_SOURCES_STRATEGIES_SSE41 RELATIVE ${PROJECT_SOURCE_DIR} "src/strategies/sse41/*.c") @@ -166,8 +165,6 @@ endif() add_executable(uvg266-bin ${CLI_SOURCES}) -target_link_libraries(uvg266-bin PUBLIC uvg266 "G:/Local/sainio/Documents/libzmq/out/install/lib/libzmq-mt-4_3_6.lib") - set_target_properties(uvg266-bin PROPERTIES OUTPUT_NAME uvg266) set_target_properties(uvg266-bin PROPERTIES RUNTIME_OUTPUT_NAME uvg266) diff --git a/src/cli.c b/src/cli.c index 6e66f77e..e614f558 100644 --- a/src/cli.c +++ b/src/cli.c @@ -117,6 +117,7 @@ static const struct option long_options[] = { { "version", no_argument, NULL, 0 }, { "help", no_argument, NULL, 0 }, { "loop-input", no_argument, NULL, 0 }, + { "skip-input", no_argument, NULL, 0 }, { "mv-constraint", required_argument, NULL, 0 }, { "hash", required_argument, NULL, 0 }, {"cu-split-termination",required_argument, NULL, 0 }, @@ -339,6 +340,8 @@ cmdline_opts_t* cmdline_opts_parse(const uvg_api *const api, int argc, char *arg goto done; } else if (!strcmp(name, "loop-input")) { opts->loop_input = true; + } else if (!strcmp(name, "skip-input")) { + opts->skip_input = true; } else if (!api->config_parse(opts->config, name, optarg)) { fprintf(stderr, "invalid argument: %s=%s\n", name, optarg); ok = 0; diff --git a/src/cli.h b/src/cli.h index 73912bd1..7ef91854 100644 --- a/src/cli.h +++ b/src/cli.h @@ -59,6 +59,8 @@ typedef struct cmdline_opts_t { bool version; /** \brief Whether to loop input */ bool loop_input; + + bool skip_input; } cmdline_opts_t; cmdline_opts_t* cmdline_opts_parse(const uvg_api *api, int argc, char *argv[]); diff --git a/src/encmain.c b/src/encmain.c index 857e38e6..52455945 100644 --- a/src/encmain.c +++ b/src/encmain.c @@ -271,11 +271,20 @@ static void* input_read_thread(void* in_args) } #if defined(__GNUC__) && !defined(__MINGW32__) - usleep(33000); + // usleep(33000); #else // Sleep(33); #endif + if (!args->opts->skip_input) { + uvg_sem_wait(args->available_input_slots); + args->img_in = frame_in; + args->retval = retval; + // Unlock main_thread_mutex to notify main thread that the new img_in + // and retval have been placed to args. + uvg_sem_post(args->filled_input_slots); + frame_in = NULL; + } else // Wait until main thread is ready to receive the next frame. if (uvg_sem_trywait(args->available_input_slots) == 0) { args->img_in = frame_in;