This commit is contained in:
cxh 2025-10-17 15:38:19 +08:00
parent 5f4518cebf
commit b1d61be69d

View File

@ -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;
}