]> git.sesse.net Git - cubemap/commitdiff
More support for multiple input types.
authorSteinar H. Gunderson <sgunderson@bigfoot.com>
Thu, 11 Apr 2013 19:31:11 +0000 (21:31 +0200)
committerSteinar H. Gunderson <sgunderson@bigfoot.com>
Thu, 11 Apr 2013 19:31:11 +0000 (21:31 +0200)
input.cpp
input.h
main.cpp

index 1e617807d0058c88b92d6b5f8b13da97c0c837c2..00b654734f2aac406dd0bc34826b13fc76d4d61a 100644 (file)
--- a/input.cpp
+++ b/input.cpp
@@ -1,7 +1,9 @@
 #include <string.h>
 #include <string>
 
+#include "httpinput.h"
 #include "input.h"
+#include "state.pb.h"
 
 using namespace std;
 
@@ -50,5 +52,29 @@ bool parse_url(const string &url, string *protocol, string *host, string *port,
        return true;
 }
 
+Input *create_input(const std::string &stream_id, 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 NULL;
+}
+
+Input *create_input(const InputProto &serialized)
+{
+       string protocol, host, port, path;
+       if (!parse_url(serialized.url(), &protocol, &host, &port, &path)) {
+               return NULL;
+       }
+       if (protocol == "http") {
+               return new HTTPInput(serialized);
+       }
+       return NULL;
+}
+
 Input::~Input() {}
 
diff --git a/input.h b/input.h
index 3e8651057e95bf39cb23d4d4e654bb12730448fb..50cfeaa4545b3e7e889e97b4064af384d18bb692 100644 (file)
--- a/input.h
+++ b/input.h
@@ -5,11 +5,17 @@
 
 #include "thread.h"
 
+class Input;
 class InputProto;
 
 // Extremely rudimentary URL parsing.
 bool parse_url(const std::string &url, std::string *protocol, std::string *host, std::string *port, std::string *path);
 
+// Figure out the right type of input based on the URL, and create a new Input of the right type.
+// Will return NULL if unknown.
+Input *create_input(const std::string &stream_id, const std::string &url);
+Input *create_input(const InputProto &serialized);
+
 class Input : public Thread {
 public:
        virtual ~Input();
index e258c86424dddcdd614dd3784d4ef59d40c50725..03ef0d7aaa5ef587cd2547be0b07b38abe0f7183 100644 (file)
--- a/main.cpp
+++ b/main.cpp
@@ -25,7 +25,6 @@
 #include "server.h"
 #include "serverpool.h"
 #include "input.h"
-#include "httpinput.h"
 #include "stats.h"
 #include "version.h"
 #include "state.pb.h"
@@ -269,7 +268,7 @@ vector<Input *> create_inputs(const vector<ConfigLine> &config,
                        deserialized_inputs->erase(deserialized_input_it);
                }
                if (input == NULL) {
-                       input = new HTTPInput(stream_id, src);
+                       input = create_input(stream_id, src);
                }
                input->run();
                inputs.push_back(input);
@@ -360,7 +359,7 @@ int main(int argc, char **argv)
                for (int i = 0; i < loaded_state.inputs_size(); ++i) {
                        deserialized_inputs.insert(make_pair(
                                loaded_state.inputs(i).stream_id(),
-                               new HTTPInput(loaded_state.inputs(i))));
+                               create_input(loaded_state.inputs(i))));
                } 
 
                // Convert the acceptor from older serialized formats.