mirror of
https://gitlab.freedesktop.org/gstreamer/gstreamer-rs.git
synced 2024-10-31 22:59:14 +00:00
gstreamer: element: more generic (un)link_many() API
No longer enforces to pass an array of references. Part-of: <https://gitlab.freedesktop.org/gstreamer/gstreamer-rs/-/merge_requests/1230>
This commit is contained in:
parent
c4a968a403
commit
01d3cef73e
16 changed files with 35 additions and 32 deletions
|
@ -50,7 +50,7 @@ fn create_pipeline() -> Result<gst::Pipeline, Error> {
|
|||
let sink = gst::ElementFactory::make("autovideosink").build()?;
|
||||
|
||||
pipeline.add_many([appsrc.upcast_ref(), &videoconvert, &sink])?;
|
||||
gst::Element::link_many(&[appsrc.upcast_ref(), &videoconvert, &sink])?;
|
||||
gst::Element::link_many([appsrc.upcast_ref(), &videoconvert, &sink])?;
|
||||
|
||||
// Our frame counter, that is stored in the mutable environment
|
||||
// of the closure of the need-data callback
|
||||
|
|
|
@ -71,7 +71,7 @@ fn example_main() -> Result<(), Error> {
|
|||
let decodebin = gst::ElementFactory::make("decodebin").build()?;
|
||||
|
||||
pipeline.add_many([&src, &decodebin])?;
|
||||
gst::Element::link_many(&[&src, &decodebin])?;
|
||||
gst::Element::link_many([&src, &decodebin])?;
|
||||
|
||||
// Need to move a new reference into the closure.
|
||||
// !!ATTENTION!!:
|
||||
|
|
|
@ -103,7 +103,7 @@ fn example_main() -> Result<(), Error> {
|
|||
// directly link it to our filesink without problems.
|
||||
// The caps of encodebin's src-pad are set after we configured the encoding-profile.
|
||||
// (But filesink doesn't really care about the caps at its input anyway)
|
||||
gst::Element::link_many(&[&encodebin, &sink])?;
|
||||
gst::Element::link_many([&encodebin, &sink])?;
|
||||
|
||||
// Need to move a new reference into the closure.
|
||||
// !!ATTENTION!!:
|
||||
|
|
|
@ -46,7 +46,7 @@ fn create_receiver_pipeline(
|
|||
let sink = gst::ElementFactory::make("autovideosink").build()?;
|
||||
|
||||
pipeline.add_many([src.upcast_ref(), &filter, &convert, &queue, &sink])?;
|
||||
gst::Element::link_many(&[src.upcast_ref(), &filter, &convert, &queue, &sink])?;
|
||||
gst::Element::link_many([src.upcast_ref(), &filter, &convert, &queue, &sink])?;
|
||||
|
||||
let fd_allocator = gst_allocators::FdAllocator::new();
|
||||
let video_info = video_info.clone();
|
||||
|
@ -116,7 +116,7 @@ fn create_sender_pipeline(
|
|||
.set_caps(Some(&caps));
|
||||
|
||||
pipeline.add_many([&src, &sink])?;
|
||||
gst::Element::link_many(&[&src, &sink])?;
|
||||
gst::Element::link_many([&src, &sink])?;
|
||||
|
||||
let appsink = sink
|
||||
.downcast::<gst_app::AppSink>()
|
||||
|
|
|
@ -78,7 +78,7 @@ fn create_pipeline() -> Result<gst::Pipeline, Error> {
|
|||
let sink = gst::ElementFactory::make("autovideosink").build()?;
|
||||
|
||||
pipeline.add_many([&src, &overlay, &capsfilter, &videoconvert, &sink])?;
|
||||
gst::Element::link_many(&[&src, &overlay, &capsfilter, &videoconvert, &sink])?;
|
||||
gst::Element::link_many([&src, &overlay, &capsfilter, &videoconvert, &sink])?;
|
||||
|
||||
// The PangoFontMap represents the set of fonts available for a particular rendering system.
|
||||
let fontmap = pangocairo::FontMap::new();
|
||||
|
|
|
@ -77,7 +77,7 @@ fn create_pipeline() -> Result<gst::Pipeline, Error> {
|
|||
let sink = gst::ElementFactory::make("autovideosink").build()?;
|
||||
|
||||
pipeline.add_many([&src, &overlay, &capsfilter, &videoconvert, &sink])?;
|
||||
gst::Element::link_many(&[&src, &overlay, &capsfilter, &videoconvert, &sink])?;
|
||||
gst::Element::link_many([&src, &overlay, &capsfilter, &videoconvert, &sink])?;
|
||||
|
||||
// The PangoFontMap represents the set of fonts available for a particular rendering system.
|
||||
let fontmap = pangocairo::FontMap::new();
|
||||
|
|
|
@ -115,7 +115,7 @@ fn example_main() -> Result<(), Error> {
|
|||
.build()?;
|
||||
|
||||
pipeline.add_many([&src, &netsim, &rtpbin, &depay, &dec, &conv, &scale, &filter])?;
|
||||
gst::Element::link_many(&[&depay, &dec, &conv, &scale, &filter])?;
|
||||
gst::Element::link_many([&depay, &dec, &conv, &scale, &filter])?;
|
||||
|
||||
match args[1].as_str() {
|
||||
"play" => {
|
||||
|
@ -133,7 +133,7 @@ fn example_main() -> Result<(), Error> {
|
|||
.build()?;
|
||||
|
||||
pipeline.add_many([&enc, &mux, &sink])?;
|
||||
gst::Element::link_many(&[&filter, &enc, &mux, &sink])?;
|
||||
gst::Element::link_many([&filter, &enc, &mux, &sink])?;
|
||||
eprintln!("Recording to out.mkv");
|
||||
}
|
||||
_ => return Err(Error::from(UsageError(args[0].clone()))),
|
||||
|
|
|
@ -138,7 +138,7 @@ mod media_factory {
|
|||
.unwrap();
|
||||
|
||||
bin.add_many([&src, &enc, &pay]).unwrap();
|
||||
gst::Element::link_many(&[&src, &enc, &pay]).unwrap();
|
||||
gst::Element::link_many([&src, &enc, &pay]).unwrap();
|
||||
|
||||
Some(bin.upcast())
|
||||
}
|
||||
|
|
|
@ -35,7 +35,7 @@ fn example_main() {
|
|||
let decodebin = gst::ElementFactory::make("decodebin").build().unwrap();
|
||||
|
||||
pipeline.add_many([&src, &decodebin]).unwrap();
|
||||
gst::Element::link_many(&[&src, &decodebin]).unwrap();
|
||||
gst::Element::link_many([&src, &decodebin]).unwrap();
|
||||
|
||||
// Need to move a new reference into the closure.
|
||||
// !!ATTENTION!!:
|
||||
|
|
|
@ -33,6 +33,7 @@ paste = "1.0"
|
|||
pretty-hex = "0.3"
|
||||
thiserror = "1"
|
||||
smallvec = { version = "1.0", features = ["write"] }
|
||||
itertools = "0.10"
|
||||
|
||||
[dev-dependencies]
|
||||
ron = "0.8"
|
||||
|
|
|
@ -3,6 +3,7 @@
|
|||
use std::{ffi::CStr, future::Future, mem, num::NonZeroU64, pin::Pin};
|
||||
|
||||
use glib::translate::*;
|
||||
use itertools::Itertools;
|
||||
|
||||
use crate::{
|
||||
format::{
|
||||
|
@ -16,18 +17,20 @@ use crate::{
|
|||
|
||||
impl Element {
|
||||
#[doc(alias = "gst_element_link_many")]
|
||||
pub fn link_many<E: IsA<Element>>(elements: &[&E]) -> Result<(), glib::BoolError> {
|
||||
pub fn link_many(
|
||||
elements: impl IntoIterator<Item = impl AsRef<Element> + Clone>,
|
||||
) -> Result<(), glib::BoolError> {
|
||||
skip_assert_initialized!();
|
||||
for e in elements.windows(2) {
|
||||
for (src, dest) in elements.into_iter().tuple_windows() {
|
||||
unsafe {
|
||||
glib::result_from_gboolean!(
|
||||
ffi::gst_element_link(
|
||||
e[0].as_ref().to_glib_none().0,
|
||||
e[1].as_ref().to_glib_none().0,
|
||||
src.as_ref().to_glib_none().0,
|
||||
dest.as_ref().to_glib_none().0,
|
||||
),
|
||||
"Failed to link elements '{}' and '{}'",
|
||||
e[0].as_ref().name(),
|
||||
e[1].as_ref().name(),
|
||||
src.as_ref().name(),
|
||||
dest.as_ref().name(),
|
||||
)?;
|
||||
}
|
||||
}
|
||||
|
@ -36,13 +39,13 @@ impl Element {
|
|||
}
|
||||
|
||||
#[doc(alias = "gst_element_unlink_many")]
|
||||
pub fn unlink_many<E: IsA<Element>>(elements: &[&E]) {
|
||||
pub fn unlink_many(elements: impl IntoIterator<Item = impl AsRef<Element> + Clone>) {
|
||||
skip_assert_initialized!();
|
||||
for e in elements.windows(2) {
|
||||
for (src, dest) in elements.into_iter().tuple_windows() {
|
||||
unsafe {
|
||||
ffi::gst_element_unlink(
|
||||
e[0].as_ref().to_glib_none().0,
|
||||
e[1].as_ref().to_glib_none().0,
|
||||
src.as_ref().to_glib_none().0,
|
||||
dest.as_ref().to_glib_none().0,
|
||||
);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -735,7 +735,7 @@ mod tests {
|
|||
pipeline
|
||||
.add_many([&src, element.upcast_ref(), &sink])
|
||||
.unwrap();
|
||||
Element::link_many(&[&src, element.upcast_ref(), &sink]).unwrap();
|
||||
Element::link_many([&src, element.upcast_ref(), &sink]).unwrap();
|
||||
|
||||
pipeline.set_state(crate::State::Playing).unwrap();
|
||||
let bus = pipeline.bus().unwrap();
|
||||
|
|
|
@ -37,7 +37,7 @@ fn tutorial_main() {
|
|||
pipeline
|
||||
.add_many([&source, &convert, &resample, &sink])
|
||||
.unwrap();
|
||||
gst::Element::link_many(&[&convert, &resample, &sink]).expect("Elements could not be linked.");
|
||||
gst::Element::link_many([&convert, &resample, &sink]).expect("Elements could not be linked.");
|
||||
|
||||
// Connect the pad-added signal
|
||||
source.connect_pad_added(move |src, src_pad| {
|
||||
|
|
|
@ -71,9 +71,9 @@ fn tutorial_main() {
|
|||
])
|
||||
.unwrap();
|
||||
|
||||
gst::Element::link_many(&[&audio_source, &tee]).unwrap();
|
||||
gst::Element::link_many(&[&audio_queue, &audio_convert, &audio_resample, &audio_sink]).unwrap();
|
||||
gst::Element::link_many(&[&video_queue, &visual, &video_convert, &video_sink]).unwrap();
|
||||
gst::Element::link_many([&audio_source, &tee]).unwrap();
|
||||
gst::Element::link_many([&audio_queue, &audio_convert, &audio_resample, &audio_sink]).unwrap();
|
||||
gst::Element::link_many([&video_queue, &visual, &video_convert, &video_sink]).unwrap();
|
||||
|
||||
let tee_audio_pad = tee.request_pad_simple("src_%u").unwrap();
|
||||
println!(
|
||||
|
|
|
@ -127,10 +127,9 @@ fn main() {
|
|||
])
|
||||
.unwrap();
|
||||
|
||||
gst::Element::link_many(&[appsrc.upcast_ref(), &tee]).unwrap();
|
||||
gst::Element::link_many(&[&audio_queue, &audio_convert1, &audio_resample, &audio_sink])
|
||||
.unwrap();
|
||||
gst::Element::link_many(&[
|
||||
gst::Element::link_many([appsrc.upcast_ref(), &tee]).unwrap();
|
||||
gst::Element::link_many([&audio_queue, &audio_convert1, &audio_resample, &audio_sink]).unwrap();
|
||||
gst::Element::link_many([
|
||||
&video_queue,
|
||||
&audio_convert2,
|
||||
&visual,
|
||||
|
@ -138,7 +137,7 @@ fn main() {
|
|||
&video_sink,
|
||||
])
|
||||
.unwrap();
|
||||
gst::Element::link_many(&[&app_queue, appsink.upcast_ref()]).unwrap();
|
||||
gst::Element::link_many([&app_queue, appsink.upcast_ref()]).unwrap();
|
||||
|
||||
let tee_audio_pad = tee.request_pad_simple("src_%u").unwrap();
|
||||
println!(
|
||||
|
|
|
@ -29,7 +29,7 @@ fn tutorial_main() -> Result<(), Error> {
|
|||
// Create the sink bin, add the elements and link them
|
||||
let bin = gst::Bin::builder().name("audio_sink_bin").build();
|
||||
bin.add_many([&equalizer, &convert, &sink]).unwrap();
|
||||
gst::Element::link_many(&[&equalizer, &convert, &sink]).expect("Failed to link elements.");
|
||||
gst::Element::link_many([&equalizer, &convert, &sink]).expect("Failed to link elements.");
|
||||
|
||||
let pad = equalizer
|
||||
.static_pad("sink")
|
||||
|
|
Loading…
Reference in a new issue