From ca51cf25094691da8960638e12481b6c62828e02 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sebastian=20Dr=C3=B6ge?= Date: Tue, 11 Jul 2023 19:47:44 +0300 Subject: [PATCH] webrtcsink: Translate force-keyunit events to force-IDR action signal for NVIDIA encoders NVIDIA's v4l2 encoder elements don't handle the force-keyunit events but instead provide a custom action signal based API for requesting a keyframe. Part-of: --- net/webrtc/src/webrtcsink/imp.rs | 36 ++++++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) diff --git a/net/webrtc/src/webrtcsink/imp.rs b/net/webrtc/src/webrtcsink/imp.rs index e6d13048..daa66558 100644 --- a/net/webrtc/src/webrtcsink/imp.rs +++ b/net/webrtc/src/webrtcsink/imp.rs @@ -456,6 +456,40 @@ fn make_converter_for_video_caps(caps: &gst::Caps) -> Result { + saw_buffer.store(true, atomic::Ordering::SeqCst); + } + Some(gst::PadProbeData::Event(ref ev)) + if gst_video::ForceKeyUnitEvent::is(ev) + && saw_buffer.load(atomic::Ordering::SeqCst) => + { + let enc = pad.parent().unwrap(); + enc.emit_by_name::<()>("force-IDR", &[]); + } + _ => {} + } + + gst::PadProbeReturn::Ok + }, + ) + .unwrap(); +} + /// Default configuration for known encoders, can be disabled /// by returning True from an encoder-setup handler. fn configure_encoder(enc: &gst::Element, start_bitrate: u32) { @@ -504,6 +538,7 @@ fn configure_encoder(enc: &gst::Element, start_bitrate: u32) { enc.set_property("insert-sps-pps", true); enc.set_property("insert-aud", true); enc.set_property_from_str("control-rate", "constant_bitrate"); + add_nv4l2enc_force_keyunit_workaround(enc); } "nvv4l2vp8enc" | "nvv4l2vp9enc" => { enc.set_property("bitrate", start_bitrate); @@ -511,6 +546,7 @@ fn configure_encoder(enc: &gst::Element, start_bitrate: u32) { enc.set_property("maxperf-enable", true); enc.set_property("idrinterval", 256u32); enc.set_property_from_str("control-rate", "constant_bitrate"); + add_nv4l2enc_force_keyunit_workaround(enc); } _ => (), }