From 57fe2cef91fb6b1aafae28603c222da0f67d79ef Mon Sep 17 00:00:00 2001 From: Martin Pulec Date: Wed, 23 Mar 2016 14:24:39 +0100 Subject: [PATCH] Added --param cmdline param to modify UG intenals These options are now available: decoder - to force user selected decoder (eg. libavcodec instead of gpujpeg, which would be chosen by default) drop-policy - to allow non-blocking put frame (effectively drops frames that cannot be displayed immediately, eg. when display frame rate is lower than video frame rate) --- src/debug.h | 4 ++-- src/host.cpp | 2 ++ src/host.h | 6 ++++++ src/main.cpp | 21 +++++++++++++++++++++ src/rtp/video_decoders.cpp | 10 ++++++++-- src/video_decompress.cpp | 6 ++++++ 6 files changed, 45 insertions(+), 4 deletions(-) diff --git a/src/debug.h b/src/debug.h index 64a9c0941..7041b3b20 100644 --- a/src/debug.h +++ b/src/debug.h @@ -42,14 +42,14 @@ #define UNUSED(x) (x=x) +#include "host.h" + #ifdef __cplusplus extern "C" { #endif void debug_dump(void*lp, int len); -#include "host.h" - #define error_msg(...) log_msg(LOG_LEVEL_ERROR, __VA_ARGS__) #define verbose_msg(...) log_msg(LOG_LEVEL_VERBOSE, __VA_ARGS__) ///#define debug_msg(...) log_msg(LOG_LEVEL_DEBUG, "[pid/%d +%d %s] ", getpid(), __LINE__, __FILE__), log_msg(LOG_LEVEL_DEBUG, __VA_ARGS__) diff --git a/src/host.cpp b/src/host.cpp index ba33f8d89..35d75ca81 100644 --- a/src/host.cpp +++ b/src/host.cpp @@ -58,6 +58,8 @@ bool ldgm_device_gpu = false; const char *window_title = NULL; +std::unordered_map commandline_params; + static void common_cleanup() { #ifdef USE_MTRACE diff --git a/src/host.h b/src/host.h index 7d2043dd0..4de088087 100644 --- a/src/host.h +++ b/src/host.h @@ -136,4 +136,10 @@ void print_version(void); } #endif +#ifdef __cplusplus +#include +#include +extern std::unordered_map commandline_params; +#endif + #endif diff --git a/src/main.cpp b/src/main.cpp index 6972b8f89..9c10bf805 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -120,6 +120,7 @@ static constexpr const char *DEFAULT_AUDIO_CODEC = "PCM"; #define OPT_DISABLE_KEY_CTRL (('D' << 8) | 'K') #define OPT_START_PAUSED (('S' << 8) | 'P') #define OPT_PROTOCOL (('P' << 8) | 'R') +#define OPT_PARAM (('O' << 8) | 'P') #define MAX_CAPTURE_COUNT 17 @@ -410,6 +411,22 @@ bool parse_audio_capture_format(const char *optarg) return true; } +static void parse_params(char *optarg) +{ + char *item, *save_ptr; + while ((item = strtok_r(optarg, ":", &save_ptr))) { + char *key_cstr = item; + if (strchr(item, '=')) { + char *val_cstr = strchr(item, '=') + 1; + *strchr(item, '=') = '\0'; + commandline_params[key_cstr] = val_cstr; + } else { + commandline_params[key_cstr] = string(); + } + optarg = NULL; + } +} + int main(int argc, char *argv[]) { #if defined HAVE_SCHED_SETSCHEDULER && defined USE_RT @@ -529,6 +546,7 @@ int main(int argc, char *argv[]) {"start-paused", no_argument, 0, OPT_START_PAUSED}, {"protocol", required_argument, 0, OPT_PROTOCOL}, {"rtsp-server", optional_argument, 0, 'H'}, + {"param", required_argument, 0, OPT_PARAM}, {0, 0, 0, 0} }; int option_index = 0; @@ -798,6 +816,9 @@ int main(int argc, char *argv[]) case OPT_START_PAUSED: start_paused = true; break; + case OPT_PARAM: + parse_params(optarg); + break; case '?': default: usage(); diff --git a/src/rtp/video_decoders.cpp b/src/rtp/video_decoders.cpp index a62b5298f..5701c1820 100644 --- a/src/rtp/video_decoders.cpp +++ b/src/rtp/video_decoders.cpp @@ -570,12 +570,18 @@ static void *decompress_thread(void *args) { } { - int putf_flags = 0; + int putf_flags = PUTF_BLOCKING; - if(is_codec_interframe(decoder->received_vid_desc.color_spec)) { + if (is_codec_interframe(decoder->received_vid_desc.color_spec)) { putf_flags = PUTF_NONBLOCK; } + if (commandline_params.find("drop-policy") != commandline_params.end()) { + if (commandline_params.at("drop-policy") == "nonblock") { + putf_flags = PUTF_NONBLOCK; + } + } + decoder->frame->ssrc = msg->nofec_frame->ssrc; int ret = display_put_frame(decoder->display, decoder->frame, putf_flags); diff --git a/src/video_decompress.cpp b/src/video_decompress.cpp index da48412a4..0f0b42e29 100644 --- a/src/video_decompress.cpp +++ b/src/video_decompress.cpp @@ -78,6 +78,12 @@ static int find_best_decompress(codec_t in_codec, codec_t out_codec, int best_priority = prio_max + 1; for (const auto & d : decomps) { + // if user has explicitly requested decoder, skip all others + if (commandline_params.find("decoder") != commandline_params.end()) { + if (d.first != commandline_params.at("decoder")) { + continue; + } + } // first pass - find the one with best priority (least) const struct decode_from_to *f = static_cast(d.second)->available_decoders; while (f->from != VIDEO_CODEC_NONE) {