diff --git a/src/input/input.cpp b/src/input/input.cpp index 2d3e6a0a..062f4cbe 100644 --- a/src/input/input.cpp +++ b/src/input/input.cpp @@ -180,6 +180,8 @@ namespace Mist{ hasSrt = false; srtTrack = 0; + lastBufferCheck = 0; + bufferPid = 0; } void Input::checkHeaderTimes(std::string streamFile){ @@ -734,7 +736,7 @@ namespace Mist{ } overrides["singular"] = ""; if (!Util::startInput(streamName, "push://INTERNAL_ONLY:" + config->getString("input"), true, - true, overrides)){// manually override stream url to start the buffer + true, overrides, &bufferPid)){// manually override stream url to start the buffer WARN_MSG("Could not start buffer, cancelling"); return; } @@ -782,6 +784,13 @@ namespace Mist{ return; } + bool Input::bufferActive(){ + if (bufferPid && Util::bootSecs() > lastBufferCheck){ + if (!Util::Procs::isRunning(bufferPid)){bufferPid = 0;} + } + return bufferPid; + } + void Input::streamMainLoop(){ uint64_t statTimer = 0; uint64_t startTime = Util::bootSecs(); @@ -795,6 +804,10 @@ namespace Mist{ Util::logExitReason("buffer requested shutdown"); break; } + if (!bufferActive()){ + Util::logExitReason("Buffer shut down"); + return; + } bufferLivePacket(thisPacket); getNext(); if (!thisPacket){ diff --git a/src/input/input.h b/src/input/input.h index 23729878..28880337 100644 --- a/src/input/input.h +++ b/src/input/input.h @@ -102,6 +102,9 @@ namespace Mist{ uint64_t simStartTime; IPC::sharedPage pidPage; ///Stores responsible input process PID + bool bufferActive(); ///< Returns true if the buffer process for this stream input is alive. + pid_t bufferPid; + uint64_t lastBufferCheck;///< Time of last buffer liveness check. void handleBuyDRM(); };