From 8d18a54c8d865087f1c5afeb083f7332a667a5f9 Mon Sep 17 00:00:00 2001 From: Thulinma Date: Sat, 24 Sep 2022 00:16:31 +0200 Subject: [PATCH] Updated livepeer process with new "-K" commandline option that forces input start and waits for it to finish boot-up --- src/process/process_livepeer.cpp | 48 ++++++++++++++++++++++++++++---- 1 file changed, 42 insertions(+), 6 deletions(-) diff --git a/src/process/process_livepeer.cpp b/src/process/process_livepeer.cpp index 1da71e24..a60b637d 100644 --- a/src/process/process_livepeer.cpp +++ b/src/process/process_livepeer.cpp @@ -537,8 +537,14 @@ int main(int argc, char *argv[]){ opt["long"] = "json"; opt["short"] = "j"; opt["help"] = "Output connector info in JSON format, then exit."; - opt["value"].append(0); + opt["value"].append(false); config.addOption("json", opt); + opt.null(); + opt["long"] = "kickoff"; + opt["short"] = "K"; + opt["help"] = "Kick off source if not already active"; + opt["value"].append(false); + config.addOption("kickoff", opt); } capa["codecs"][0u][0u].append("H264"); @@ -753,8 +759,30 @@ int main(int argc, char *argv[]){ Util::setStreamName(Mist::opt["source"].asString() + "→" + streamName); } + + const std::string & srcStrm = Mist::opt["source"].asStringRef(); + if (config.getBool("kickoff")){ + if (!Util::startInput(srcStrm, "")){ + FAIL_MSG("Could not connector and/or start source stream!"); + return 1; + } + uint8_t streamStat = Util::getStreamStatus(srcStrm); + size_t sleeps = 0; + while (++sleeps < 2400 && streamStat != STRMSTAT_OFF && streamStat != STRMSTAT_READY){ + if (sleeps >= 16 && (sleeps % 4) == 0){ + INFO_MSG("Waiting for stream to boot... (" PRETTY_PRINT_TIME " / " PRETTY_PRINT_TIME ")", PRETTY_ARG_TIME(sleeps/4), PRETTY_ARG_TIME(2400/4)); + } + Util::sleep(250); + streamStat = Util::getStreamStatus(srcStrm); + } + if (streamStat != STRMSTAT_READY){ + FAIL_MSG("Stream not available!"); + return 1; + } + } + //connect to source metadata - DTSC::Meta M(Mist::opt["source"].asStringRef(), false); + DTSC::Meta M(srcStrm, false); //find source video track std::map targetParams; @@ -767,10 +795,18 @@ int main(int argc, char *argv[]){ if (Mist::opt.isMember("source_track") && Mist::opt["source_track"].isString() && Mist::opt["source_track"]){ targetParams["video"] = Mist::opt["source_track"].asStringRef(); } - std::set vidTrack = Util::wouldSelect(M, targetParams, sourceCapa); - size_t sourceIdx = *(vidTrack.begin()); - if (!M.getWidth(sourceIdx) || !M.getHeight(sourceIdx)){ - FAIL_MSG("Source track does not have a valid width and height"); + size_t sourceIdx = INVALID_TRACK_ID; + size_t sleeps = 0; + while (++sleeps < 60 && (sourceIdx == INVALID_TRACK_ID || !M.getWidth(sourceIdx) || !M.getHeight(sourceIdx))){ + M.reloadReplacedPagesIfNeeded(); + std::set vidTrack = Util::wouldSelect(M, targetParams, sourceCapa); + sourceIdx = vidTrack.size() ? (*(vidTrack.begin())) : INVALID_TRACK_ID; + if (sourceIdx == INVALID_TRACK_ID || !M.getWidth(sourceIdx) || !M.getHeight(sourceIdx)){ + Util::sleep(250); + } + } + if (sourceIdx == INVALID_TRACK_ID || !M.getWidth(sourceIdx) || !M.getHeight(sourceIdx)){ + FAIL_MSG("No valid source track!"); return 1; }