From b1d61be69d5d200d57e4f896d36d5e8431125efc Mon Sep 17 00:00:00 2001 From: cxh Date: Fri, 17 Oct 2025 15:38:19 +0800 Subject: [PATCH] 1 --- src/rtmp_manager.cpp | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) diff --git a/src/rtmp_manager.cpp b/src/rtmp_manager.cpp index 00efd09..94bf4cf 100644 --- a/src/rtmp_manager.cpp +++ b/src/rtmp_manager.cpp @@ -120,10 +120,27 @@ void RTMPManager::stream_loop(Camera cam, StreamContext *ctx) GstBus *bus = gst_element_get_bus(pipeline); gst_element_set_state(pipeline, GST_STATE_PLAYING); + + // -------- 等待状态切换结果 -------- + GstStateChangeReturn ret = gst_element_get_state(pipeline, nullptr, nullptr, 3 * GST_SECOND); + + if (ret != GST_STATE_CHANGE_SUCCESS) + { + ctx->status.running = false; + ctx->status.last_error = "Pipeline failed to reach PLAYING"; + LOG_ERROR("[RTMP] " + key + " failed to start (no video signal?)"); + gst_element_set_state(pipeline, GST_STATE_NULL); + gst_object_unref(bus); + gst_object_unref(pipeline); + std::this_thread::sleep_for(std::chrono::seconds(3)); + continue; + } + ctx->status.running = true; ctx->status.last_error.clear(); LOG_INFO("[RTMP] Started stream for " + key); + // -------- 主循环 -------- bool need_restart = false; while (ctx->running) { @@ -153,8 +170,8 @@ void RTMPManager::stream_loop(Camera cam, StreamContext *ctx) default: break; } - gst_message_unref(msg); + gst_message_unref(msg); if (need_restart) break; }