From ab477ca497dda0730842755fa6a8619af6d2249f Mon Sep 17 00:00:00 2001 From: Claude Date: Wed, 2 Dec 2026 14:07:12 +0000 Subject: [PATCH] Video stream: restart only after a lasting stall, not after one 5 s gap Field log: the PTZ re-init now keeps the camera and its stream (15:36), but at 16:02:30 "Video Stalled" restarted the live555 stream, which cut the recording. streamHandler::validate() (module factory, every ~5 s) restarted the stream as soon as one validation saw no new frame, i.e. after a single gap of ~5 s. That is normal now and then for a camera on a mobile link. - The stream is restarted after STREAM_STALL_CHECKS (3) validations in a row without a new frame (~15 s): "Video Stalled (no frame for N s) - restarting the stream". Shorter gaps are logged ("Video: no new frame for N s (k/3)", "Video: frames again after N s"). - m_nValidatorFrameCounter is initialised (it was not). Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_0139veDo3XyavMuVhdnHcN16 --- lib/App/common/streamHandler.cpp | 28 +++++++++++++++++++++++++--- lib/App/common/streamHandler.h | 8 ++++++++ 2 files changed, 33 insertions(+), 3 deletions(-) diff --git a/lib/App/common/streamHandler.cpp b/lib/App/common/streamHandler.cpp index 701bc23d..6239e6fe 100644 --- a/lib/App/common/streamHandler.cpp +++ b/lib/App/common/streamHandler.cpp @@ -69,6 +69,9 @@ streamHandler::streamHandler(kernelModuleEmbedVideo * ptr, MS_WORK_MODE M, uint8 memset(&m_sStreamData, 0, sizeof(DBC_MEDIA_STREAM_DATA)); m_pSource = NULL; + m_nValidatorFrameCounter = 0; + m_nStallChecks = 0; + m_tLastFrameProgress = time(NULL); m_bEvtMarkerCounter = 0; m_bCamMoveCounter = 0; m_bFlipMode = flip_mode; @@ -3751,12 +3754,31 @@ bool streamHandler::validate(void) { // Frames Received from a source if (m_nGlobalFrameCounter == m_nValidatorFrameCounter) { - // Video Stalled! - LOG_ERROR("Video Stalled"); - return false; // Try use System to recuperate + // No new frame since the last validation: restart only when it lasts (STREAM_STALL_CHECKS) + char tB[128]; + long tSec = (long) (time(NULL) - m_tLastFrameProgress); + if (++m_nStallChecks < STREAM_STALL_CHECKS) + { + snprintf(tB, sizeof(tB), "Video: no new frame for %ld s (%u/%u)", tSec, (unsigned) m_nStallChecks, (unsigned) STREAM_STALL_CHECKS); + LOG(tB); + } + else + { + snprintf(tB, sizeof(tB), "Video Stalled (no frame for %ld s) - restarting the stream", tSec); + LOG_ERROR(tB); + return false; // Try use System to recuperate + }; } else { + if (m_nStallChecks) + { + char tB[96]; + snprintf(tB, sizeof(tB), "Video: frames again after %ld s", (long) (time(NULL) - m_tLastFrameProgress)); + LOG(tB); + }; + m_nStallChecks = 0; + m_tLastFrameProgress = time(NULL); m_nValidatorFrameCounter = m_nGlobalFrameCounter; } }; diff --git a/lib/App/common/streamHandler.h b/lib/App/common/streamHandler.h index c1f732b0..7e114b87 100644 --- a/lib/App/common/streamHandler.h +++ b/lib/App/common/streamHandler.h @@ -27,6 +27,12 @@ //Predefine Classess class kernelModuleEmbedVideo; +// A stream is restarted only after this many validations in a row (module factory: every ~5 s) without a +// new frame. One gap of ~5 s (a camera on a mobile link) restarted the stream and cut the recording. +#ifndef STREAM_STALL_CHECKS + #define STREAM_STALL_CHECKS 3 +#endif + class streamHandler; #define FILESTREAMBUFFERSZ 1048576 @@ -241,6 +247,8 @@ class streamHandler : basicMutex m_mFrameCounterProtector; uint64_t m_nGlobalFrameCounter; uint64_t m_nValidatorFrameCounter; + uint8_t m_nStallChecks; // validate() calls in a row without a new frame + time_t m_tLastFrameProgress; // last validate() that saw new frames #ifndef EVE_SEQUENTAL_OUTPUT uint32_t m_nSegAFrameCounter; uint32_t m_nSegBFrameCounter;