]> git.sesse.net Git - cubemap/blobdiff - main.cpp
Add support for UDP outputs.
[cubemap] / main.cpp
index 5ec0cb487269649c59c32dde293b3c42133ab2a7..8d60826fb3d7a8436607446f27b572ba294bc237 100644 (file)
--- a/main.cpp
+++ b/main.cpp
@@ -109,29 +109,36 @@ vector<Acceptor *> create_acceptors(
        return acceptors;
 }
 
+void create_config_input(const string &src, multimap<string, InputWithRefcount> *inputs)
+{
+       if (src.empty()) {
+               return;
+       }
+       if (inputs->count(src) != 0) {
+               return;
+       }
+
+       InputWithRefcount iwr;
+       iwr.input = create_input(src);
+       if (iwr.input == NULL) {
+               log(ERROR, "did not understand URL '%s', clients will not get any data.",
+                       src.c_str());
+               return;
+       }
+       iwr.refcount = 0;
+       inputs->insert(make_pair(src, iwr));
+}
+
 // Find all streams in the configuration file, and create inputs for them.
 void create_config_inputs(const Config &config, multimap<string, InputWithRefcount> *inputs)
 {
        for (unsigned i = 0; i < config.streams.size(); ++i) {
                const StreamConfig &stream_config = config.streams[i];
-               if (stream_config.src.empty()) {
-                       continue;
-               }
-
-               string src = stream_config.src;
-               if (inputs->count(src) != 0) {
-                       continue;
-               }
-
-               InputWithRefcount iwr;
-               iwr.input = create_input(src);
-               if (iwr.input == NULL) {
-                       log(ERROR, "did not understand URL '%s', clients will not get any data.",
-                               src.c_str());
-                       continue;
-               }
-               iwr.refcount = 0;
-               inputs->insert(make_pair(src, iwr));
+               create_config_input(stream_config.src, inputs);
+       }
+       for (unsigned i = 0; i < config.udpstreams.size(); ++i) {
+               const UDPStreamConfig &udpstream_config = config.udpstreams[i];
+               create_config_input(udpstream_config.src, inputs);
        }
 }
 
@@ -144,6 +151,7 @@ void create_streams(const Config &config,
                mark_pools.push_back(new MarkPool(mp_config.from, mp_config.to));
        }
 
+       // HTTP streams.
        set<string> expecting_urls = deserialized_urls;
        for (unsigned i = 0; i < config.streams.size(); ++i) {
                const StreamConfig &stream_config = config.streams[i];
@@ -174,7 +182,7 @@ void create_streams(const Config &config,
                }
        }
 
-       // Warn about any servers we've lost.
+       // Warn about any HTTP servers we've lost.
        // TODO: Make an option (delete=yes?) to actually shut down streams.
        for (set<string>::const_iterator stream_it = expecting_urls.begin();
             stream_it != expecting_urls.end();
@@ -184,6 +192,24 @@ void create_streams(const Config &config,
                             "It will not be deleted, but clients will not get any new inputs.",
                             url.c_str());
        }
+
+       // UDP streams.
+       for (unsigned i = 0; i < config.udpstreams.size(); ++i) {
+               const UDPStreamConfig &udpstream_config = config.udpstreams[i];
+               MarkPool *mark_pool = NULL;
+               if (udpstream_config.mark_pool != -1) {
+                       mark_pool = mark_pools[udpstream_config.mark_pool];
+               }
+               int stream_index = servers->add_udpstream(udpstream_config.dst, mark_pool);
+
+               string src = udpstream_config.src;
+               if (!src.empty()) {
+                       multimap<string, InputWithRefcount>::iterator input_it = inputs->find(src);
+                       assert(input_it != inputs->end());
+                       input_it->second.input->add_destination(stream_index);
+                       ++input_it->second.refcount;
+               }
+       }
 }
        
 void open_logs(const vector<LogConfig> &log_destinations)