tracers: buffer-lateness: do not report proper latency if modified by a pad probe
A common pattern to increase one element latency is to use a pad probe modifying the LATENCY query. See this example:
use gst::prelude::*;
fn main() {
gst::init().unwrap();
let playbin = gst::parse_launch(
"videotestsrc is-live=true num-buffers=1000 ! x264enc name=x264enc speed-preset=ultrafast tune=zerolatency ! fakesink",
)
.unwrap();
let playbin = playbin.downcast::<gst::Pipeline>().unwrap();
let encoder = playbin.by_name("x264enc").unwrap();
let pad = encoder.static_pad("src").unwrap();
increase_reported_latency(&pad, gst::ClockTime::from_seconds(1));
let bus = playbin.bus().unwrap();
playbin.set_state(gst::State::Playing).unwrap();
for msg in bus.iter_timed(gst::ClockTime::NONE) {
use gst::MessageView;
match msg.view() {
MessageView::Eos(..) => {
println!("eos");
break;
}
MessageView::Error(err) => {
println!(
"Error from {:?}: {} ({:?})",
err.src().map(|s| s.path_string()),
err.error(),
err.debug()
);
break;
}
_ => (),
}
}
playbin.set_state(gst::State::Null).unwrap();
unsafe {
gst::deinit();
}
}
fn increase_reported_latency(srcpad: &gst::Pad, extra_latency: gst::ClockTime) {
srcpad.add_probe(gst::PadProbeType::QUERY_UPSTREAM, move |_pad, info| {
if !info.mask.contains(gst::PadProbeType::PULL) {
return gst::PadProbeReturn::Ok;
}
if let Some(gst::PadProbeData::Query(ref mut q)) = info.data {
if let gst::QueryViewMut::Latency(q) = q.view_mut() {
let (live, min, max) = q.result();
let new_latency = min + extra_latency;
dbg!((min, new_latency));
q.set(live, new_latency, max);
return gst::PadProbeReturn::Handled;
}
}
gst::PadProbeReturn::Ok
});
}
Unfortunately the buffer-lateness
tracer keeps reporting the original latency (0 here):
819605088,x264enc:src,0x55868fe8c570,220760571144512,220760405882664,-165261848,0
The problem is GST_TRACER_PAD_QUERY_POST
being called before PROBE_PUSH
so the tracer gets the query before the pad probe.
Edited by Guillaume Desmottes