1
This commit is contained in:
parent
843dbd09c6
commit
42bad1d949
@ -58,6 +58,7 @@ void RTSPManager::init()
|
||||
|
||||
GstRTSPMediaFactory *RTSPManager::create_media_factory(const Camera &cam)
|
||||
{
|
||||
// 程序启动时设置一次 v4l2 格式
|
||||
if (!set_v4l2_format(cam.device, cam.width, cam.height))
|
||||
{
|
||||
LOG_ERROR("[RTSP] Failed to set V4L2 format for " + cam.name);
|
||||
@ -66,15 +67,26 @@ GstRTSPMediaFactory *RTSPManager::create_media_factory(const Camera &cam)
|
||||
int out_width = cam.width;
|
||||
int out_height = cam.height;
|
||||
|
||||
std::string launch_str =
|
||||
"( v4l2src device=" + cam.device +
|
||||
" io-mode=2"
|
||||
" ! video/x-raw,format=NV12,width=" +
|
||||
// 先拼 caps,方便看
|
||||
std::string caps =
|
||||
"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-buffers=1 leaky=downstream"
|
||||
" ! mpph264enc rc-mode=cbr bps=" +
|
||||
",framerate=" + std::to_string(cam.fps) + "/1";
|
||||
|
||||
// 关键改动:
|
||||
// 1) v4l2src 加 is-live / do-timestamp,避免 preroll 卡死
|
||||
// 2) queue 放宽限制,避免首帧被丢导致 pipeline 出错
|
||||
// 3) suspend_mode 改为 NONE,避免客户端断开时 RESET pipeline 导致反复 s_stream(0/1)
|
||||
std::string launch_str =
|
||||
"( v4l2src device=" + cam.device +
|
||||
" io-mode=2 is-live=true do-timestamp=true"
|
||||
" ! " +
|
||||
caps +
|
||||
" ! queue max-size-buffers=0 max-size-bytes=0 max-size-time=0"
|
||||
" ! mpph264enc rc-mode=cbr"
|
||||
" bps=" +
|
||||
std::to_string(cam.bitrate) +
|
||||
" gop=" + std::to_string(cam.fps) +
|
||||
" header-mode=1"
|
||||
@ -84,7 +96,9 @@ GstRTSPMediaFactory *RTSPManager::create_media_factory(const Camera &cam)
|
||||
GstRTSPMediaFactory *factory = gst_rtsp_media_factory_new();
|
||||
gst_rtsp_media_factory_set_launch(factory, launch_str.c_str());
|
||||
gst_rtsp_media_factory_set_shared(factory, TRUE);
|
||||
gst_rtsp_media_factory_set_suspend_mode(factory, GST_RTSP_SUSPEND_MODE_RESET);
|
||||
|
||||
// 不再在客户端断开时 RESET / 销毁 pipeline,避免频繁触发 MIPI / maxim4c 重新配置
|
||||
gst_rtsp_media_factory_set_suspend_mode(factory, GST_RTSP_SUSPEND_MODE_NONE);
|
||||
|
||||
g_signal_connect_data(factory,
|
||||
"media-configure",
|
||||
|
||||
Loading…
Reference in New Issue
Block a user