diff --git a/src/rtmp_manager.cpp b/src/rtmp_manager.cpp index 92589aa..f1f9983 100644 --- a/src/rtmp_manager.cpp +++ b/src/rtmp_manager.cpp @@ -142,6 +142,9 @@ void RTMPManager::stream_loop(Camera cam, StreamType type, const std::string &se bool first_frame_received = false; bool stop_flag = false; + const int FIRST_FRAME_TIMEOUT_SEC = 5; // 等待第一帧最大秒数 + auto first_frame_start = std::chrono::steady_clock::now(); + while (!stop_flag) { GstMessage *msg = gst_bus_timed_pop_filtered( @@ -158,6 +161,19 @@ void RTMPManager::stream_loop(Camera cam, StreamType type, const std::string &se } } + if (!first_frame_received) + { + auto elapsed = std::chrono::steady_clock::now() - first_frame_start; + if (std::chrono::duration_cast(elapsed).count() > FIRST_FRAME_TIMEOUT_SEC) + { + std::string reason = "No frames received within timeout"; + LOG_WARN("[RTMP] " + key + ": " + reason); + update_status(key, {false, StreamResult::TIMEOUT, reason}); + publish_stream_status(cam.name, type, seqNo, false, reason); + stop_flag = true; + } + } + if (!msg) continue;