From ee853b1ffbb409f85541b594ef815b8e11663967 Mon Sep 17 00:00:00 2001 From: Marco van Dijk Date: Thu, 19 Sep 2024 16:21:47 +0200 Subject: [PATCH] Change Input::keepRunning to be more generic, override it in MistInBuffer and MistInHLS --- src/input/input.cpp | 16 ++++++++-------- src/input/input.h | 2 +- src/input/input_buffer.cpp | 8 ++++++++ src/input/input_buffer.h | 1 + src/input/input_hls.cpp | 10 ++++++++++ src/input/input_hls.h | 1 + 6 files changed, 29 insertions(+), 9 deletions(-) diff --git a/src/input/input.cpp b/src/input/input.cpp index 368e6066..f2bb0a30 100644 --- a/src/input/input.cpp +++ b/src/input/input.cpp @@ -894,13 +894,6 @@ namespace Mist{ break; } - if (M.getLive() && !internalOnly){ - uint64_t currLastUpdate = M.getLastUpdated(); - if (currLastUpdate > activityCounter){activityCounter = currLastUpdate;} - }else{ - if ((connectedUsers || isAlwaysOn()) && M.getValidTracks().size()){activityCounter = Util::bootSecs();} - } - inputServeStats(); // if not shutting down, wait 1 second before looping preMs = Util::bootMS() - preMs; @@ -944,7 +937,14 @@ namespace Mist{ /// For live streams, this is twice the biggest fragment duration. /// For non-live streams this is INPUT_TIMEOUT seconds. /// The default Pro implementation also allows cancelling the shutdown through the STREAM_UNLOAD trigger. - bool Input::keepRunning(){ + bool Input::keepRunning(bool updateActCtr){ + // Default behaviour to stop an input when there's not activity after X seconds + // This is overriden by certain inputs (buffer, HLS, more) where there is different logic + // for updating 'activityCounter' + if (updateActCtr){ + if ((connectedUsers || isAlwaysOn()) && M.getValidTracks().size()){activityCounter = Util::bootSecs();} + } + // We keep running in serve mode if the config is still active AND either // - INPUT_TIMEOUT seconds haven't passed yet, // - this is a live stream and at least two of the biggest fragment haven't passed yet, diff --git a/src/input/input.h b/src/input/input.h index c7d57de0..c4f6bb0b 100644 --- a/src/input/input.h +++ b/src/input/input.h @@ -74,7 +74,7 @@ namespace Mist{ virtual void getNext(size_t idx = INVALID_TRACK_ID){} virtual void seek(uint64_t seekTime, size_t idx = INVALID_TRACK_ID){} virtual void finish(); - virtual bool keepRunning(); + virtual bool keepRunning(bool updateActCtr = true); virtual bool openStreamSource(){return readHeader();} virtual void closeStreamSource(){} virtual void parseStreamHeader(){} diff --git a/src/input/input_buffer.cpp b/src/input/input_buffer.cpp index 9eac0ef8..45ac78a4 100644 --- a/src/input/input_buffer.cpp +++ b/src/input/input_buffer.cpp @@ -258,6 +258,14 @@ namespace Mist{ meta.setLive(true); } + bool InputBuffer::keepRunning(bool updateActCtr){ + if (M.getLive()){ + uint64_t currLastUpdate = M.getLastUpdated(); + if (currLastUpdate > activityCounter){activityCounter = currLastUpdate;} + } + return Input::keepRunning(false); + } + /// Checks if removing a key from this track is allowed/safe, and if so, removes it. /// Returns true if a key was actually removed, false otherwise /// Aborts if any of the following conditions are true (while active): diff --git a/src/input/input_buffer.h b/src/input/input_buffer.h index 52c2fd88..adb4a687 100644 --- a/src/input/input_buffer.h +++ b/src/input/input_buffer.h @@ -34,6 +34,7 @@ namespace Mist{ bool needHeader(){return false;} void getNext(size_t idx = INVALID_TRACK_ID){}; void seek(uint64_t seekTime, size_t idx = INVALID_TRACK_ID){}; + bool keepRunning(bool updateActCtr = true); void removeTrack(size_t tid); diff --git a/src/input/input_hls.cpp b/src/input/input_hls.cpp index e1e7cb04..4cc7ad82 100644 --- a/src/input/input_hls.cpp +++ b/src/input/input_hls.cpp @@ -1169,6 +1169,16 @@ namespace Mist{ } } + bool InputHLS::keepRunning(bool updateActCtr){ + if (isAlwaysOn()){ + uint64_t currLastUpdate = M.getLastUpdated(); + if (currLastUpdate > activityCounter){activityCounter = currLastUpdate;} + return Input::keepRunning(false); + }else{ + return Input::keepRunning(true); + } + } + /// \brief Applies any offset to the packets original timestamp /// \param packetTime: the original timestamp of the packet /// \param tid: the trackid corresponding to this track and playlist diff --git a/src/input/input_hls.h b/src/input/input_hls.h index 78b4aa75..bccb24a9 100644 --- a/src/input/input_hls.h +++ b/src/input/input_hls.h @@ -147,6 +147,7 @@ namespace Mist{ void postHeader(); void getNext(size_t idx = INVALID_TRACK_ID); void seek(uint64_t seekTime, size_t idx = INVALID_TRACK_ID); + bool keepRunning(bool updateActCtr = true); bool readIndex(); bool initPlaylist(const std::string &uri, bool fullInit = true);