This commit is contained in:
cxh 2025-10-15 13:31:50 +08:00
parent 7e9690e621
commit 4244123191

View File

@ -142,6 +142,9 @@ void RTMPManager::stream_loop(Camera cam, StreamType type, const std::string &se
bool first_frame_received = false; bool first_frame_received = false;
bool stop_flag = false; bool stop_flag = false;
const int FIRST_FRAME_TIMEOUT_SEC = 5; // 等待第一帧最大秒数
auto first_frame_start = std::chrono::steady_clock::now();
while (!stop_flag) while (!stop_flag)
{ {
GstMessage *msg = gst_bus_timed_pop_filtered( 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<std::chrono::seconds>(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) if (!msg)
continue; continue;