mirror of
https://gitlab.freedesktop.org/gstreamer/gstreamer-rs.git
synced 2024-11-25 19:11:06 +00:00
streamproducer: expose set_forward_preroll() API
This is useful to decide whether the preroll sample should be forwarded to consumers when prerolling or only once it is time to render it. Part-of: <https://gitlab.freedesktop.org/gstreamer/gstreamer-rs/-/merge_requests/1439>
This commit is contained in:
parent
455996c60b
commit
0ef80c4fe7
1 changed files with 14 additions and 2 deletions
|
@ -364,6 +364,11 @@ impl StreamProducer {
|
||||||
self.consumers.lock().unwrap().events_to_forward = events_to_forward.into_iter().collect();
|
self.consumers.lock().unwrap().events_to_forward = events_to_forward.into_iter().collect();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// configure whether the preroll sample should be forwarded (default: `true`)
|
||||||
|
pub fn set_forward_preroll(&self, forward_preroll: bool) {
|
||||||
|
self.consumers.lock().unwrap().forward_preroll = forward_preroll;
|
||||||
|
}
|
||||||
|
|
||||||
/// Get the GStreamer `appsink` wrapped by this producer
|
/// Get the GStreamer `appsink` wrapped by this producer
|
||||||
pub fn appsink(&self) -> &gst_app::AppSink {
|
pub fn appsink(&self) -> &gst_app::AppSink {
|
||||||
&self.appsink
|
&self.appsink
|
||||||
|
@ -399,6 +404,7 @@ impl<'a> From<&'a gst_app::AppSink> for StreamProducer {
|
||||||
// it would make sense to automatically forward more events such as Tag but that would break
|
// it would make sense to automatically forward more events such as Tag but that would break
|
||||||
// with older GStreamer, see https://gitlab.freedesktop.org/gstreamer/gstreamer/-/merge_requests/4297
|
// with older GStreamer, see https://gitlab.freedesktop.org/gstreamer/gstreamer/-/merge_requests/4297
|
||||||
events_to_forward: vec![gst::EventType::Eos],
|
events_to_forward: vec![gst::EventType::Eos],
|
||||||
|
forward_preroll: true,
|
||||||
just_forwarded_preroll: false,
|
just_forwarded_preroll: false,
|
||||||
}));
|
}));
|
||||||
|
|
||||||
|
@ -434,9 +440,13 @@ impl<'a> From<&'a gst_app::AppSink> for StreamProducer {
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
consumers.just_forwarded_preroll = true;
|
if consumers.forward_preroll {
|
||||||
|
consumers.just_forwarded_preroll = true;
|
||||||
|
|
||||||
StreamProducer::process_sample(sample, appsink, consumers)
|
StreamProducer::process_sample(sample, appsink, consumers)
|
||||||
|
} else {
|
||||||
|
Ok(gst::FlowSuccess::Ok)
|
||||||
|
}
|
||||||
}))
|
}))
|
||||||
.new_event(glib::clone!(@strong consumers => move |appsink| {
|
.new_event(glib::clone!(@strong consumers => move |appsink| {
|
||||||
match appsink.pull_object().map(|obj| obj.downcast::<gst::Event>()) {
|
match appsink.pull_object().map(|obj| obj.downcast::<gst::Event>()) {
|
||||||
|
@ -525,6 +535,8 @@ struct StreamConsumers {
|
||||||
consumers: HashMap<gst_app::AppSrc, StreamConsumer>,
|
consumers: HashMap<gst_app::AppSrc, StreamConsumer>,
|
||||||
/// What events should be forwarded to consumers
|
/// What events should be forwarded to consumers
|
||||||
events_to_forward: Vec<gst::EventType>,
|
events_to_forward: Vec<gst::EventType>,
|
||||||
|
/// Whether the preroll sample should be forwarded at all
|
||||||
|
forward_preroll: bool,
|
||||||
/// Whether we just forwarded the preroll sample. When we did we want to
|
/// Whether we just forwarded the preroll sample. When we did we want to
|
||||||
/// discard the next sample from on_new_sample as it would cause us to
|
/// discard the next sample from on_new_sample as it would cause us to
|
||||||
/// otherwise push out the same sample twice to consumers.
|
/// otherwise push out the same sample twice to consumers.
|
||||||
|
|
Loading…
Reference in a new issue