diff --git a/lib/stream.cpp b/lib/stream.cpp index 7da8159f..47ec83c6 100644 --- a/lib/stream.cpp +++ b/lib/stream.cpp @@ -363,6 +363,7 @@ bool Util::startInput(std::string streamname, std::string filename, bool forkFir // check required parameters if (input.isMember("required")){ jsonForEachConst(input["required"], prm){ + if (!prm->isMember("option")){continue;} const std::string opt = (*prm)["option"].asStringRef(); // check for overrides if (overrides.count(opt)){ @@ -379,6 +380,7 @@ bool Util::startInput(std::string streamname, std::string filename, bool forkFir // check optional parameters if (input.isMember("optional")){ jsonForEachConst(input["optional"], prm){ + if (!prm->isMember("option")){continue;} const std::string opt = (*prm)["option"].asStringRef(); // check for overrides if (overrides.count(opt)){ diff --git a/src/input/input_buffer.cpp b/src/input/input_buffer.cpp index eacd4ed1..539c2eae 100644 --- a/src/input/input_buffer.cpp +++ b/src/input/input_buffer.cpp @@ -82,6 +82,11 @@ namespace Mist { capa["optional"]["segmentsize"]["option"] = "--segment-size"; capa["optional"]["segmentsize"]["type"] = "uint"; capa["optional"]["segmentsize"]["default"] = 1900; + + capa["optional"]["fallback_stream"]["name"] = "Fallback stream"; + capa["optional"]["fallback_stream"]["help"] = "Alternative stream to load for playback when there is no active broadcast"; + capa["optional"]["fallback_stream"]["type"] = "str"; + capa["optional"]["fallback_stream"]["default"] = ""; option.null(); /*LTS-end*/ diff --git a/src/output/output.cpp b/src/output/output.cpp index 222c1b73..5285b636 100644 --- a/src/output/output.cpp +++ b/src/output/output.cpp @@ -372,6 +372,19 @@ namespace Mist{ } }else{ if (!Util::startInput(streamName, "", true, isPushing())){ + //If stream is configured, use fallback stream setting, if set. + JSON::Value strCnf = Util::getStreamConfig(streamName); + if (strCnf && strCnf["fallback_stream"].asStringRef().size()){ + streamName = strCnf["fallback_stream"].asStringRef(); + Util::Config::streamName = streamName; + INFO_MSG("Switching to configured fallback stream '%s'", streamName.c_str()); + reconnect(); + return; + } + + //Not configured or no fallback stream? Use the default stream handler instead + //Note: Since fallback stream is handled recursively, the defaultStream handler + //may still be triggered for the fallback stream! This is intentional. JSON::Value defStrmJson = Util::getGlobalConfig("defaultStream"); std::string defStrm = defStrmJson.asString(); if(Triggers::shouldTrigger("DEFAULT_STREAM", streamName)){ diff --git a/src/output/output_hls.cpp b/src/output/output_hls.cpp index cce50237..fe2e4a39 100644 --- a/src/output/output_hls.cpp +++ b/src/output/output_hls.cpp @@ -433,7 +433,8 @@ namespace Mist { H.Clean(); //clean for any possible next requests return; }else if (HTTP::URL(H.url).getExt().substr(0, 3) != "m3u") { - std::string tmpStr = H.getUrl().substr(5 + streamName.size()); + size_t slashPos = H.getUrl().find('/', 5); + std::string tmpStr = H.getUrl().substr(slashPos); long long unsigned int from; if (sscanf(tmpStr.c_str(), "/%u_%u/%llu_%llu.ts", &vidTrack, &audTrack, &from, &until) != 4) { if (sscanf(tmpStr.c_str(), "/%u/%llu_%llu.ts", &vidTrack, &from, &until) != 3) {