From a51235048d68d44d1d58bdf28e22b19c735ae2ec Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sebastian=20Dr=C3=B6ge?= Date: Thu, 12 May 2022 10:29:28 +0300 Subject: [PATCH] utils/streamproducer: Add `StreamProducer::configure_consumer()` This allows configuring an `appsrc` before actually adding it as consumer at a later time, and can be useful if the pipeline with the source should be started earlier than adding it to a consumer. Also use strongly-typed property API for the `appsrc` properties. --- gstreamer-utils/Cargo.toml | 12 ++++-------- gstreamer-utils/src/streamproducer.rs | 27 ++++++++++++++++++--------- 2 files changed, 22 insertions(+), 17 deletions(-) diff --git a/gstreamer-utils/Cargo.toml b/gstreamer-utils/Cargo.toml index abd6f0d76..58ec22c9d 100644 --- a/gstreamer-utils/Cargo.toml +++ b/gstreamer-utils/Cargo.toml @@ -16,18 +16,14 @@ rust-version = "1.57" # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html [dependencies] -gst = { package = "gstreamer", path = "../gstreamer" } -gst_app = { package = "gstreamer-app", path = "../gstreamer-app" } -gst_video = { package = "gstreamer-video", path = "../gstreamer-video" } +gst = { package = "gstreamer", path = "../gstreamer", features = ["v1_20"] } +gst_app = { package = "gstreamer-app", path = "../gstreamer-app", features = ["v1_20"] } +gst_video = { package = "gstreamer-video", path = "../gstreamer-video", features = ["v1_20"] } once_cell = "1" [dev-dependencies] futures = { version = "0.3", features = ["executor"] } -gst_app = { package = "gstreamer-app", path = "../gstreamer-app" } [features] default = [] -v1_16 = [] -v1_18 = ['v1_16'] -v1_20 = ['v1_18'] -v1_22 = ['v1_20'] +v1_22 = [] diff --git a/gstreamer-utils/src/streamproducer.rs b/gstreamer-utils/src/streamproducer.rs index 2eed66239..5e91ede8e 100644 --- a/gstreamer-utils/src/streamproducer.rs +++ b/gstreamer-utils/src/streamproducer.rs @@ -36,6 +36,23 @@ impl PartialEq for StreamProducer { impl Eq for StreamProducer {} impl StreamProducer { + /// Configure a consumer `appsrc` for later use in a `StreamProducer` + /// + /// This is automatically called when calling `add_consumer()`. + pub fn configure_consumer(consumer: &gst_app::AppSrc) { + // Latency on the appsrc is set by the publisher before the first buffer + // and whenever it changes + consumer.set_latency(gst::ClockTime::ZERO, gst::ClockTime::NONE); + consumer.set_format(gst::Format::Time); + consumer.set_is_live(true); + consumer.set_handle_segment_change(true); + consumer.set_max_buffers(0); + consumer.set_max_bytes(0); + consumer.set_max_time(500 * gst::ClockTime::MSECOND); + consumer.set_leaky_type(gst_app::AppLeakyType::Downstream); + consumer.set_automatic_eos(false); + } + /// Add an appsrc to dispatch data to pub fn add_consumer(&self, consumer: &gst_app::AppSrc) { let mut consumers = self.consumers.lock().unwrap(); @@ -50,15 +67,7 @@ impl StreamProducer { gst::debug!(CAT, obj: &self.appsink, "Adding consumer"); - consumer.set_property("max-buffers", 0u64); - consumer.set_property("max-bytes", 0u64); - consumer.set_property("max-time", gst::ClockTime::from_mseconds(500)); - consumer.set_property("format", gst::Format::Time); - consumer.set_property_from_str("leaky-type", "downstream"); - consumer - .try_set_property("handle-segment-change", true) - .ok(); - consumer.set_automatic_eos(false); + Self::configure_consumer(consumer); // Forward force-keyunit events upstream to the appsink let srcpad = consumer.static_pad("src").unwrap();