mirror of
https://gitlab.freedesktop.org/gstreamer/gst-plugins-rs.git
synced 2024-11-29 15:01:07 +00:00
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: <https://gitlab.freedesktop.org/gstreamer/gst-plugins-rs/-/merge_requests/1274>
This commit is contained in:
parent
89002b4562
commit
ca51cf2509
1 changed files with 36 additions and 0 deletions
|
@ -456,6 +456,40 @@ fn make_converter_for_video_caps(caps: &gst::Caps) -> Result<gst::Element, Error
|
|||
Ok(ret.upcast())
|
||||
}
|
||||
|
||||
/// Add a pad probe to convert force-keyunit events to the custom action signal based NVIDIA
|
||||
/// encoder API.
|
||||
fn add_nv4l2enc_force_keyunit_workaround(enc: &gst::Element) {
|
||||
use std::sync::atomic::{self, AtomicBool};
|
||||
|
||||
let srcpad = enc.static_pad("src").unwrap();
|
||||
let saw_buffer = AtomicBool::new(false);
|
||||
srcpad
|
||||
.add_probe(
|
||||
gst::PadProbeType::BUFFER
|
||||
| gst::PadProbeType::BUFFER_LIST
|
||||
| gst::PadProbeType::EVENT_UPSTREAM,
|
||||
move |pad, info| {
|
||||
match info.data {
|
||||
Some(gst::PadProbeData::Buffer(..))
|
||||
| Some(gst::PadProbeData::BufferList(..)) => {
|
||||
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);
|
||||
}
|
||||
_ => (),
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue