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;