I am trying to create two pipelines and dynamically link them using the StreamProducer::add_consumer method, and it seems to work fine as long as I set the “do-timestamp” property on the source to “false”.
I have created a simplified code example (see line 19). As soon as I set the property to true, I start receiving following warnings, and the video output seems to be lagged:
WARN basesink gstbasesink.c:3147:gst_base_sink_is_too_late: warning: A lot of buffers are being dropped.
WARN basesink gstbasesink.c:3147:gst_base_sink_is_too_late: warning: There may be a timestamping problem, or this computer is too slow.
Has anyone encountered anything similar. Am I doing something obviously wrong? Can you help me bring this about.
The code example follows:
use std::time::Duration;
use gst::{
ClockTime,
prelude::ElementExtManual,
traits::{ClockExt, ElementExt, GstBinExt, PipelineExt},
};
use gst_app::{AppSink, AppSrc};
use gst_utils::StreamProducer;
fn main() {
gst::init().unwrap();
let pipeline1 = gst::Pipeline::new();
let pipeline2 = gst::Pipeline::new();
let src = gst::ElementFactory::make("videotestsrc")
.property("is-live", true)
.property("do-timestamp", false) // setting this to true causes lag and warnings
.build()
.unwrap();
pipeline1.add(&src).unwrap();
let clocksync = gst::ElementFactory::make("clocksync").build().unwrap();
pipeline1.add(&clocksync).unwrap();
src.link(&clocksync).unwrap();
let asink = AppSink::builder()
.caps(
&gst::Caps::builder("video/x-raw")
.field("format", "I420")
.build(),
)
.build();
let produ = StreamProducer::from(&asink);
pipeline1.add(&asink).unwrap();
clocksync.link(&asink).unwrap();
pipeline1.set_state(gst::State::Playing).unwrap();
std::thread::sleep(Duration::from_secs(2));
/////////
let asrc = AppSrc::builder()
//.min_latency(2_000_000_000)
//.max_latency(3_000_000_000)
.build();
pipeline2.add(&asrc).unwrap();
let _link = produ.add_consumer(&asrc);
let sin = gst::ElementFactory::make("autovideosink").build().unwrap();
pipeline2.add(&sin).unwrap();
asrc.link(&sin).unwrap();
pipeline2.use_clock(pipeline1.clock().as_ref());
pipeline2.set_base_time(pipeline1.base_time().unwrap());
pipeline2.set_start_time(ClockTime::NONE);
pipeline2.set_state(gst::State::Playing).unwrap();
loop {
std::thread::sleep(Duration::from_secs(99));
//pipeline1.recalculate_latency().unwrap();
//pipeline2.recalculate_latency().unwrap();
}
}