Refer to streams internally mostly by an index, not the stream_id.
[cubemap] / main.cpp
index c89ec72..5ec0cb4 100644 (file)
--- a/main.cpp
+++ b/main.cpp
@@ -136,7 +136,7 @@ void create_config_inputs(const Config &config, multimap<string, InputWithRefcou
 }
 
 void create_streams(const Config &config,
-                    const set<string> &deserialized_stream_ids,
+                    const set<string> &deserialized_urls,
                     multimap<string, InputWithRefcount> *inputs)
 {
        for (unsigned i = 0; i < config.mark_pools.size(); ++i) {
@@ -144,43 +144,45 @@ void create_streams(const Config &config,
                mark_pools.push_back(new MarkPool(mp_config.from, mp_config.to));
        }
 
-       set<string> expecting_stream_ids = deserialized_stream_ids;
+       set<string> expecting_urls = deserialized_urls;
        for (unsigned i = 0; i < config.streams.size(); ++i) {
                const StreamConfig &stream_config = config.streams[i];
-               if (deserialized_stream_ids.count(stream_config.stream_id) == 0) {
-                       servers->add_stream(stream_config.stream_id,
-                                           stream_config.backlog_size,
-                                           Stream::Encoding(stream_config.encoding));
+               int stream_index;
+               if (deserialized_urls.count(stream_config.url) == 0) {
+                       stream_index = servers->add_stream(stream_config.url,
+                                                          stream_config.backlog_size,
+                                                          Stream::Encoding(stream_config.encoding));
                } else {
-                       servers->set_backlog_size(stream_config.stream_id, stream_config.backlog_size);
-                       servers->set_encoding(stream_config.stream_id,
+                       stream_index = servers->lookup_stream_by_url(stream_config.url);
+                       assert(stream_index != -1);
+                       servers->set_backlog_size(stream_index, stream_config.backlog_size);
+                       servers->set_encoding(stream_index,
                                              Stream::Encoding(stream_config.encoding));
                }
-               expecting_stream_ids.erase(stream_config.stream_id);
+               expecting_urls.erase(stream_config.url);
 
                if (stream_config.mark_pool != -1) {
-                       servers->set_mark_pool(stream_config.stream_id,
-                                              mark_pools[stream_config.mark_pool]);
+                       servers->set_mark_pool(stream_index, mark_pools[stream_config.mark_pool]);
                }
 
                string src = stream_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_config.stream_id);
+                       input_it->second.input->add_destination(stream_index);
                        ++input_it->second.refcount;
                }
        }
 
        // Warn about any servers we've lost.
        // TODO: Make an option (delete=yes?) to actually shut down streams.
-       for (set<string>::const_iterator stream_it = expecting_stream_ids.begin();
-            stream_it != expecting_stream_ids.end();
+       for (set<string>::const_iterator stream_it = expecting_urls.begin();
+            stream_it != expecting_urls.end();
             ++stream_it) {
-               string stream_id = *stream_it;
+               string url = *stream_it;
                log(WARNING, "stream '%s' disappeared from the configuration file. "
                             "It will not be deleted, but clients will not get any new inputs.",
-                            stream_id.c_str());
+                            url.c_str());
        }
 }
        
@@ -328,7 +330,7 @@ start:
 
        CubemapStateProto loaded_state;
        struct timeval serialize_start;
-       set<string> deserialized_stream_ids;
+       set<string> deserialized_urls;
        map<int, Acceptor *> deserialized_acceptors;
        multimap<string, InputWithRefcount> inputs;  // multimap due to older versions without deduplication.
        if (state_fd != -1) {
@@ -361,7 +363,7 @@ start:
                        }
 
                        servers->add_stream_from_serialized(stream, data_fds);
-                       deserialized_stream_ids.insert(stream.stream_id());
+                       deserialized_urls.insert(stream.url());
                }
 
                // Deserialize the inputs. Note that we don't actually add them to any stream yet.
@@ -386,7 +388,7 @@ start:
        create_config_inputs(config, &inputs);
        
        // Find all streams in the configuration file, create them, and connect to the inputs.
-       create_streams(config, deserialized_stream_ids, &inputs);
+       create_streams(config, deserialized_urls, &inputs);
        vector<Acceptor *> acceptors = create_acceptors(config, &deserialized_acceptors);
        
        // Put back the existing clients. It doesn't matter which server we