From 472fbf4a246c95594143ae3a91f538748abcdb82 Mon Sep 17 00:00:00 2001 From: albfan Date: Sun, 23 Oct 2016 00:30:19 +0200 Subject: [PATCH] Check source UIBC capability If source has no UIBC capability don't try to connect UIBC controller, and listen UIBC setting to disable UIBC relates to #115 --- src/ctl/ctl-sink.c | 26 ++++++++++++++++---------- src/ctl/ctl-sink.h | 3 ++- src/ctl/sinkctl.c | 41 +++++++++++++++++++++-------------------- 3 files changed, 39 insertions(+), 31 deletions(-) diff --git a/src/ctl/ctl-sink.c b/src/ctl/ctl-sink.c index 2d72e18..486456c 100644 --- a/src/ctl/ctl-sink.c +++ b/src/ctl/ctl-sink.c @@ -122,7 +122,7 @@ static void sink_handle_get_parameter(struct ctl_sink *s, } /* wfd_uibc_capability */ - if (rtsp_message_read(m, "{<>}", "wfd_uibc_capability") >= 0 && uibc) { + if (rtsp_message_read(m, "{<>}", "wfd_uibc_capability") >= 0 && uibc_option) { char wfd_uibc_capability[512]; sprintf(wfd_uibc_capability, "wfd_uibc_capability: input_category_list=GENERIC;" @@ -258,16 +258,22 @@ static void sink_handle_set_parameter(struct ctl_sink *s, free(s->uibc_config); s->uibc_config = nu; - char* token = strtok(uibc_config, ";"); + if (!strcasecmp(uibc_config, "none")) { + uibc_enabled = false; + } else { + char* token = strtok(uibc_config, ";"); - while (token) { - if (sscanf(token, "port=%d", &uibc_port)) { - break; - } - token = strtok(0, ";"); - } - - cli_debug("Got URL: %s\n", s->url); + while (token) { + if (sscanf(token, "port=%d", &uibc_port)) { + log_debug("UIBC port: %d\n", uibc_port); + if (uibc_option) { + uibc_enabled = true; + } + break; + } + token = strtok(0, ";"); + } + } } } diff --git a/src/ctl/ctl-sink.h b/src/ctl/ctl-sink.h index 69d0532..7218583 100644 --- a/src/ctl/ctl-sink.h +++ b/src/ctl/ctl-sink.h @@ -40,7 +40,8 @@ #include "wfd.h" extern int rstp_port; -extern bool uibc; +extern bool uibc_option; +extern bool uibc_enabled; extern int uibc_port; struct ctl_sink { diff --git a/src/ctl/sinkctl.c b/src/ctl/sinkctl.c index 5c335f2..f1f6af8 100644 --- a/src/ctl/sinkctl.c +++ b/src/ctl/sinkctl.c @@ -59,7 +59,8 @@ void launch_player(struct ctl_sink *s); char *gst_scale_res; int gst_audio_en = 1; static const int DEFAULT_RSTP_PORT = 1991; -bool uibc; +bool uibc_option; +bool uibc_enabled; int rstp_port; int uibc_port; @@ -388,14 +389,14 @@ void launch_player(struct ctl_sink *s) { char uibc_portStr[64]; int i = 0; char* player; - if (uibc) { + if (uibc_enabled) { player = "uibc-viewer"; } else { player = "miracle-gst"; } argv[i++] = player; - if (uibc) { + if (uibc_enabled) { argv[i++] = s->target; sprintf(uibc_portStr, "%d", uibc_port); argv[i++] = uibc_portStr; @@ -420,29 +421,28 @@ void launch_player(struct ctl_sink *s) { argv[i] = NULL; - i = 0; + i = 0; int size = 0; - while (argv[i]) { + while (argv[i]) { size += strlen(argv[i++] + 1); - } + } char* player_command = malloc(size); - i = 0; + i = 0; strcpy(player_command, argv[i++]); - while (argv[i]) { + while (argv[i]) { strcat(player_command, " "); strcat(player_command, argv[i++]); - } + } log_debug("player command: %s", player_command); - //free(player_command); - if (execvpe(argv[0], argv, environ) < 0) { - cli_debug("stream player failed (%d): %m", errno); - int i = 0; - cli_debug("printing environment: "); - while (environ[i]) { - cli_debug("%s", environ[i++]); - } - } + if (execvpe(argv[0], argv, environ) < 0) { + cli_debug("stream player failed (%d): %m", errno); + int i = 0; + cli_debug("printing environment: "); + while (environ[i]) { + cli_debug("%s", environ[i++]); + } + } } void launch_uibc_daemon(int port) { @@ -771,7 +771,8 @@ static int parse_argv(int argc, char *argv[]) }; int c; - uibc = false; + uibc_option = false; + uibc_enabled = false; rstp_port = DEFAULT_RSTP_PORT; while ((c = getopt_long(argc, argv, "h", options, NULL)) >= 0) { @@ -803,7 +804,7 @@ static int parse_argv(int argc, char *argv[]) rstp_port = atoi(optarg); break; case ARG_UIBC: - uibc = true; + uibc_option = true; break; case '?': return -EINVAL;