From 0b60b8a9af72757ecfcef6f9ef5f6ca55d31ed23 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jo=C3=A3o=20Ant=C3=B4nio=20Cardoso?= Date: Fri, 8 Mar 2024 17:43:09 -0300 Subject: [PATCH 1/2] src: stream: pipeline: Fix wrong frame duration --- src/stream/pipeline/v4l_pipeline.rs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/stream/pipeline/v4l_pipeline.rs b/src/stream/pipeline/v4l_pipeline.rs index 4d5b3922..68b52c59 100644 --- a/src/stream/pipeline/v4l_pipeline.rs +++ b/src/stream/pipeline/v4l_pipeline.rs @@ -56,7 +56,7 @@ impl V4lPipeline { VideoEncodeType::H264 => { format!( concat!( - "v4l2src device={device} do-timestamp=false", + "v4l2src device={device} do-timestamp=true", " ! h264parse", // Here we need the parse to help the stream-format and alignment part, which is being fixed here because avc/au seems to reduce the CPU usage in the RTP payloading part. " ! capsfilter name={filter_name} caps=video/x-h264,stream-format=avc,alignment=au,width={width},height={height},framerate={interval_denominator}/{interval_numerator}", " ! tee name={video_tee_name} allow-not-linked=true", @@ -76,7 +76,7 @@ impl V4lPipeline { VideoEncodeType::Yuyv => { format!( concat!( - "v4l2src device={device} do-timestamp=false", + "v4l2src device={device} do-timestamp=true", " ! videoconvert", " ! capsfilter name={filter_name} caps=video/x-raw,format=I420,width={width},height={height},framerate={interval_denominator}/{interval_numerator}", " ! tee name={video_tee_name} allow-not-linked=true", @@ -96,7 +96,7 @@ impl V4lPipeline { VideoEncodeType::Mjpg => { format!( concat!( - "v4l2src device={device} do-timestamp=false", + "v4l2src device={device} do-timestamp=true", // We don't need a jpegparse, as it leads to incompatible caps, spoiling the negotiation. " ! capsfilter name={filter_name} caps=image/jpeg,width={width},height={height},framerate={interval_denominator}/{interval_numerator}", " ! tee name={video_tee_name} allow-not-linked=true", From 68e6a459b5b9267abf5dcdc63ad1e6d5f865dac9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jo=C3=A3o=20Ant=C3=B4nio=20Cardoso?= Date: Fri, 8 Mar 2024 19:14:37 -0300 Subject: [PATCH 2/2] src: stream: sink: Use pipeline clock for the WebRTC's RTP --- src/stream/sink/webrtc_sink.rs | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/src/stream/sink/webrtc_sink.rs b/src/stream/sink/webrtc_sink.rs index 27ef9e5c..b8ba5108 100644 --- a/src/stream/sink/webrtc_sink.rs +++ b/src/stream/sink/webrtc_sink.rs @@ -342,6 +342,20 @@ impl WebRTCSink { rx.recv()?? }; + // Configure RTP + let webrtcbin = webrtcbin.downcast::().unwrap(); + webrtcbin + .iterate_elements() + .filter(|e| e.name().starts_with("rtpbin")) + .into_iter() + .for_each(|res| { + let Ok(rtp_bin) = res else { return }; + + // Use the pipeline clock time. This will ensure that the timestamps from the source are correct. + rtp_bin.set_property_from_str("ntp-time-source", "clock-time"); + }); + let webrtcbin = webrtcbin.upcast::(); + let webrtcbin_sink_pad = webrtcbin .request_pad_simple("sink_%u") .context("Failed requesting sink pad for webrtcsink")?;