This commit is contained in:
cxh 2025-11-21 16:16:43 +08:00
parent 51ab3ab280
commit 5f2110c5fd

View File

@ -32,29 +32,31 @@ GstRTSPMediaFactory *RTSPManager::create_media_factory(const Camera &cam)
std::string launch_str =
"( v4l2src device=" + cam.device +
" ! video/x-raw,format=NV12,width=" + std::to_string(out_width) +
" io-mode=4 is-live=true "
" ! video/x-raw,format=NV12,width=" +
std::to_string(out_width) +
",height=" + std::to_string(out_height) +
",framerate=" + std::to_string(cam.fps) + "/1"
" ! queue max-size-time=100000000"
" ! videoconvert"
" ! queue max-size-buffers=1 leaky=downstream"
" ! mpph264enc rc-mode=cbr bps=" +
std::to_string(cam.bitrate) +
" gop=" + std::to_string(cam.fps) +
" profile=high"
" ! h264parse"
" ! rtph264pay name=pay0 pt=96 )";
" b-frames=0"
" ! h264parse config-interval=1"
" ! rtph264pay name=pay0 pt=96 config-interval=1 )";
GstRTSPMediaFactory *factory = gst_rtsp_media_factory_new();
gst_rtsp_media_factory_set_launch(factory, launch_str.c_str());
// ★ 非共享会导致重复 mount 失败,让它共享
gst_rtsp_media_factory_set_shared(factory, TRUE);
// ★ live source 必须用 RESET不然 UNPREPARE 不会释放 pipeline
gst_rtsp_media_factory_set_suspend_mode(factory, GST_RTSP_SUSPEND_MODE_RESET);
gst_rtsp_media_factory_set_latency(factory, 0);
gst_rtsp_media_factory_set_transport_mode(factory, GST_RTSP_TRANSPORT_MODE_PLAY);
// 监听 pipeline 创建
g_signal_connect_data(factory, "media-configure", G_CALLBACK(on_media_created),
// 绑定创建回调
g_signal_connect_data(factory, "media-configure",
G_CALLBACK(on_media_created),
g_strdup(cam.name.c_str()),
(GClosureNotify)g_free,
(GConnectFlags)0);