utils: streamproducer: add API to retrieve last sample from producer

This may be used for example to easily generate thumbnails from video
producers.
This commit is contained in:
Guillaume Desmottes 2022-07-05 12:35:01 +02:00
parent 0e17878bed
commit fbceaab941

View file

@ -210,6 +210,11 @@ impl StreamProducer {
let _ = consumer.post_message(msg_builder.build());
}
}
/// The last sample produced by this producer.
pub fn last_sample(&self) -> Option<gst::Sample> {
self.appsink.property("last-sample")
}
}
impl<'a> From<&'a gst_app::AppSink> for StreamProducer {
@ -611,6 +616,8 @@ mod tests {
.expect("Couldn't set producer pipeline state");
consumers.push(consumer);
assert!(producer.last_sample().is_none());
for i in 0..10 {
let caps = gst::Caps::from_str(&format!("test,n={}", i)).unwrap();
producer_src.set_caps(Some(&caps));
@ -639,6 +646,8 @@ mod tests {
}
}
assert!(producer.last_sample().is_some());
assert_eq!(link1.pushed(), 6);
assert_eq!(link1.dropped(), 0);
assert_eq!(link2.pushed(), 10);