X-Git-Url: https://git.sesse.net/?p=cubemap;a=blobdiff_plain;f=input.cpp;h=d37b7d997e16f41f5afbe6d4421e5d669ad4d516;hp=00b654734f2aac406dd0bc34826b13fc76d4d61a;hb=f8e6be4ca4d53ca6dbb9a56063c7dfca9b6760c9;hpb=7c4707af4ea7af05e34bc0414d18d9fd54e4f23e diff --git a/input.cpp b/input.cpp index 00b6547..d37b7d9 100644 --- a/input.cpp +++ b/input.cpp @@ -1,27 +1,28 @@ -#include +#include #include #include "httpinput.h" #include "input.h" #include "state.pb.h" +#include "udpinput.h" using namespace std; // Extremely rudimentary URL parsing. bool parse_url(const string &url, string *protocol, string *host, string *port, string *path) { - if (url.find("http://") != 0) { + size_t split = url.find("://"); + if (split == string::npos) { return false; } + *protocol = string(url.begin(), url.begin() + split); - *protocol = "http"; - - string rest = url.substr(strlen("http://")); - size_t split = rest.find_first_of(":/"); + string rest = string(url.begin() + split + 3, url.end()); + split = rest.find_first_of(":/"); if (split == string::npos) { // http://foo *host = rest; - *port = "http"; + *port = *protocol; *path = "/"; return true; } @@ -47,19 +48,22 @@ bool parse_url(const string &url, string *protocol, string *host, string *port, } // http://foo/bar - *port = "http"; - *path = rest; + *port = *protocol; + *path = "/" + rest; return true; } -Input *create_input(const std::string &stream_id, const std::string &url) +Input *create_input(const std::string &url) { string protocol, host, port, path; if (!parse_url(url, &protocol, &host, &port, &path)) { return NULL; } if (protocol == "http") { - return new HTTPInput(stream_id, url); + return new HTTPInput(url); + } + if (protocol == "udp") { + return new UDPInput(url); } return NULL; } @@ -73,6 +77,9 @@ Input *create_input(const InputProto &serialized) if (protocol == "http") { return new HTTPInput(serialized); } + if (protocol == "udp") { + return new UDPInput(serialized); + } return NULL; }