From: Steinar H. Gunderson Date: Sun, 26 Aug 2018 14:56:22 +0000 (+0200) Subject: Force input encoding for UDP streams to raw already at config parsing. X-Git-Tag: 1.4.0~2 X-Git-Url: https://git.sesse.net/?p=cubemap;a=commitdiff_plain;h=0f36a8f674788a6ee10ff54ae72619b384c62b9d;ds=inline Force input encoding for UDP streams to raw already at config parsing. Otherwise, it would be counted as src_encoding=metacube at the point where we matched it up with serialized streams, causing problems with the stream being dropped on reload. Bug reported by Tore Sinding Bekkedal. --- diff --git a/config.cpp b/config.cpp index 21e17c9..919f212 100644 --- a/config.cpp +++ b/config.cpp @@ -16,6 +16,7 @@ #include "acceptor.h" #include "config.h" +#include "input.h" #include "log.h" #include "parse.h" @@ -326,12 +327,21 @@ bool parse_stream(const ConfigLine &line, Config *config) stream.url = line.arguments[0]; const auto src_it = line.parameters.find("src"); + bool input_is_udp = false; if (src_it == line.parameters.end()) { log(WARNING, "stream '%s' has no src= attribute, clients will not get any data.", stream.url.c_str()); } else { stream.src = src_it->second; - // TODO: Verify that the URL is parseable? + + string protocol, user, host, port, path; + if (!parse_url(stream.src, &protocol, &user, &host, &port, &path)) { + log(ERROR, "could not parse URL '%s'", stream.src.c_str()); + return false; + } + if (protocol == "udp") { + input_is_udp = true; + } } const auto backlog_it = line.parameters.find("backlog_size"); @@ -362,13 +372,18 @@ bool parse_stream(const ConfigLine &line, Config *config) // Parse input encoding. const auto src_encoding_parm_it = line.parameters.find("src_encoding"); - if (src_encoding_parm_it == line.parameters.end() || - src_encoding_parm_it->second == "metacube") { + if (src_encoding_parm_it == line.parameters.end()) { + stream.src_encoding = input_is_udp ? StreamConfig::STREAM_ENCODING_RAW : StreamConfig::STREAM_ENCODING_METACUBE; + } else if (src_encoding_parm_it->second == "metacube") { + if (input_is_udp) { + log(ERROR, "UDP streams cannot have Metacube input"); + return false; + } stream.src_encoding = StreamConfig::STREAM_ENCODING_METACUBE; } else if (src_encoding_parm_it->second == "raw") { stream.src_encoding = StreamConfig::STREAM_ENCODING_RAW; } else { - log(ERROR, "Parameter 'src_encoding' must be either 'raw' or 'metacube' (default)"); + log(ERROR, "Parameter 'src_encoding' must be either 'raw' (default for UDP) or 'metacube' (default for HTTP)"); return false; } diff --git a/input.cpp b/input.cpp index b434eed..dba6cf3 100644 --- a/input.cpp +++ b/input.cpp @@ -104,7 +104,7 @@ Input *create_input(const string &url, Input::Encoding encoding) return new HTTPInput(url, encoding); } if (protocol == "udp") { - // encoding is ignored; it's never Metacube. + assert(encoding == Input::INPUT_ENCODING_RAW); return new UDPInput(url); } return nullptr;