diff --git a/tests/ANSCV-UnitTest/ANSCV-UnitTest.cpp b/tests/ANSCV-UnitTest/ANSCV-UnitTest.cpp index 39897f8..512116d 100644 --- a/tests/ANSCV-UnitTest/ANSCV-UnitTest.cpp +++ b/tests/ANSCV-UnitTest/ANSCV-UnitTest.cpp @@ -877,7 +877,32 @@ int RSTPTestCVClient() { //if ((index == 2000) || (index == 2300) || (index == 2700)) { StartRTSP(&rtspClient); } //if (index > 20000) break; auto loopStart = std::chrono::steady_clock::now(); - auto getStart = loopStart; + + // ── Camera-dead watchdog (mirrors ANSVIS production behaviour) ────── + // ANSRTSPClient does NOT auto-reconnect by design: the application + // layer polls frame age and calls ReconnectRTSP. Without this, a dead + // session (camera reboot, network drop, laptop standby killing the TCP + // connection) leaves the client returning the cached last frame + // forever. Threshold is 20 s: the decoder's corruption keyframe gate + // can legitimately hold delivery for up to ~12 s (300-frame safety + // valve) during heavy packet loss, and a reconnect mid-gate would + // throw away a recovery that was about to complete. Retry at most + // every 15 s so a camera that is genuinely off doesn't get hammered. + { + static auto lastReconnectAttempt = std::chrono::steady_clock::now(); + const double frameAgeMs = GetRTSPLastFrameAgeMs(&rtspClient); + if (frameAgeMs >= 20000.0 && + loopStart - lastReconnectAttempt > std::chrono::seconds(15)) { + lastReconnectAttempt = loopStart; + const std::time_t t = std::time(nullptr); + char ts[32]; std::strftime(ts, sizeof ts, "%Y-%m-%d %H:%M:%S", std::localtime(&t)); + printf("[%s] [WATCHDOG] no decoded frame for %.0f s -- calling ReconnectRTSP\n", + ts, frameAgeMs / 1000.0); + ReconnectRTSP(&rtspClient); + } + } + + auto getStart = std::chrono::steady_clock::now(); cv::Mat* image = nullptr; // ✅ Use a pointer to hold the allocated image GetRTSPCVImage(&rtspClient, width, height, pts,&image); auto getEnd = std::chrono::steady_clock::now();