- // 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();
- ++stream_it) {
- string stream_id = *stream_it;
- fprintf(stderr, "WARNING: stream '%s' disappeared from the configuration file.\n",
- stream_id.c_str());
- fprintf(stderr, " It will not be deleted, but clients will not get any new inputs.\n");
- if (deserialized_inputs.count(stream_id) != 0) {
- delete deserialized_inputs[stream_id];
- deserialized_inputs.erase(stream_id);
- }
- }
-
- // Open a new server socket if we do not already have one, or if we changed ports.
- if (server_sock != -1 && port != old_port) {
- fprintf(stderr, "NOTE: Port changed from %d to %d; opening new socket.\n", old_port, port);
- close(server_sock);
- server_sock = -1;
- }
- if (server_sock == -1) {
- server_sock = create_server_socket(port);
- }
-
- // See if the user wants stats.
- string stats_file = fetch_config_string(config, "stats_file", PARAMETER_OPTIONAL);
- int stats_interval = fetch_config_int(config, "stats_interval", 1, INT_MAX, PARAMETER_OPTIONAL, -1);
- if (stats_interval != -1 && stats_file.empty()) {
- fprintf(stderr, "WARNING: 'stats_interval' given, but no 'stats_file'. No statistics will be written.\n");
- }
-
- servers->run();
-
- pthread_t acceptor_thread;
- pthread_create(&acceptor_thread, NULL, acceptor_thread_run, reinterpret_cast<void *>(server_sock));
-
- // Find all streams in the configuration file, and create inputs for them.
- vector<Input *> inputs;
- for (unsigned i = 0; i < config.size(); ++i) {
- if (config[i].keyword != "stream") {
- continue;
- }
- assert(config[i].arguments.size() == 1);
- string stream_id = config[i].arguments[0];
-
- if (config[i].parameters.count("src") == 0) {
- fprintf(stderr, "WARNING: stream '%s' has no src= attribute, clients will not get any data.\n",
- stream_id.c_str());
- continue;
- }
-
- string src = config[i].parameters["src"];
- Input *input = NULL;
- if (deserialized_inputs.count(stream_id) != 0) {
- input = deserialized_inputs[stream_id];
- if (input->get_url() != src) {
- fprintf(stderr, "INFO: Stream '%s' has changed URL from '%s' to '%s', restarting input.\n",
- stream_id.c_str(), input->get_url().c_str(), src.c_str());
- delete input;
- input = NULL;
- }
- deserialized_inputs.erase(stream_id);
- }
- if (input == NULL) {
- input = new Input(stream_id, src);
- }
- input->run();
- inputs.push_back(input);
- }