]> git.sesse.net Git - cubemap/commitdiff
Force input encoding for UDP streams to raw already at config parsing.
authorSteinar H. Gunderson <sgunderson@bigfoot.com>
Sun, 26 Aug 2018 14:56:22 +0000 (16:56 +0200)
committerSteinar H. Gunderson <sgunderson@bigfoot.com>
Sun, 26 Aug 2018 14:56:22 +0000 (16:56 +0200)
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.

config.cpp
input.cpp

index 21e17c988d7137b68b7b4c869fcffb077a3da3cf..919f21256bd650655985fd9873ec61dcb65f5a8b 100644 (file)
@@ -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;
        }
 
index b434eedfe1307cc8bd51dfca83ab38dfda9f4f9b..dba6cf38b26b3ca87a6a953c8842600012e0124b 100644 (file)
--- 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;