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.
This commit is contained in:
Sebastian Dröge 2022-05-12 10:29:28 +03:00
parent f3bba21faa
commit a51235048d
2 changed files with 22 additions and 17 deletions

View file

@ -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 = []

View file

@ -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();