gst: Manually impl Bin & Pipeline constructors

Set `Bin` & `Pipeline` constructors to manual implementation to remove
optional `name` argument (use builder to specify name).

Part-of: <https://gitlab.freedesktop.org/gstreamer/gstreamer-rs/-/merge_requests/1255>
This commit is contained in:
François Laignel 2023-02-25 18:12:42 +01:00 committed by GStreamer Marge Bot
parent ccf3b57a8b
commit 13f0483a44
20 changed files with 81 additions and 36 deletions

View file

@ -1273,7 +1273,7 @@ mod tests {
.unwrap();
let appsink = gst::ElementFactory::make("appsink").build().unwrap();
let pipeline = gst::Pipeline::new(None);
let pipeline = gst::Pipeline::new();
pipeline.add(&videotestsrc).unwrap();
pipeline.add(&appsink).unwrap();

View file

@ -651,7 +651,7 @@ mod tests {
.build()
.unwrap();
let pipeline = gst::Pipeline::new(None);
let pipeline = gst::Pipeline::new();
pipeline.add(&appsrc).unwrap();
pipeline.add(&fakesink).unwrap();

View file

@ -283,7 +283,7 @@ mod tests {
file.write_all(b"succeeds").unwrap();
let runner = crate::Runner::new();
let pipeline = gst::Pipeline::new(None);
let pipeline = gst::Pipeline::new();
let scenario =
crate::Scenario::factory_create(&runner, &pipeline, file.path().to_str().unwrap())
.unwrap();

View file

@ -406,6 +406,11 @@ status = "generate"
name = "Gst.Bin"
status = "generate"
trait_name = "GstBinExt"
[[object.function]]
name = "new"
# Remove the optional `name` argument in favor of using the builder
manual = true
[[object.signal]]
name = "do-latency"
# Use Result<(), glib::BoolError>
@ -1674,13 +1679,13 @@ manual_traits = ["PadExtManual"]
[[object.function]]
name = "new_from_template"
# Also has builder_with_template()
# Also has builder_from_template()
rename = "from_template"
manual = true
[[object.function]]
name = "new_from_static_template"
# Also has builder_with_static_template()
# Also has builder_from_static_template()
rename = "from_static_template"
manual = true
@ -1880,6 +1885,11 @@ status = "generate"
[[object]]
name = "Gst.Pipeline"
status = "generate"
[[object.function]]
name = "new"
# Remove the optional `name` argument in favor of using the builder
manual = true
[[object.function]]
name = "get_delay"
[object.function.return]

View file

@ -22,12 +22,6 @@ glib::wrapper! {
impl Bin {
pub const NONE: Option<&'static Bin> = None;
#[doc(alias = "gst_bin_new")]
pub fn new(name: Option<&str>) -> Bin {
assert_initialized_main_thread!();
unsafe { Element::from_glib_none(ffi::gst_bin_new(name.to_glib_none().0)).unsafe_cast() }
}
}
unsafe impl Send for Bin {}

View file

@ -22,14 +22,6 @@ glib::wrapper! {
impl Pipeline {
pub const NONE: Option<&'static Pipeline> = None;
#[doc(alias = "gst_pipeline_new")]
pub fn new(name: Option<&str>) -> Pipeline {
assert_initialized_main_thread!();
unsafe {
Element::from_glib_none(ffi::gst_pipeline_new(name.to_glib_none().0)).unsafe_cast()
}
}
}
unsafe impl Send for Pipeline {}

View file

@ -12,10 +12,31 @@ use glib::{
use crate::{prelude::*, Bin, BinFlags, Element, LoggableError};
impl Bin {
// rustdoc-stripper-ignore-next
/// Creates a new [`Bin`] object with a default name.
///
/// Use [`Bin::with_name()`] to create a [`Bin`] with a specific name.
/// Use [`Bin::builder()`] for additional configuration.
#[doc(alias = "gst_bin_new")]
pub fn new() -> Bin {
assert_initialized_main_thread!();
unsafe { Element::from_glib_none(ffi::gst_bin_new(std::ptr::null())).unsafe_cast() }
}
// rustdoc-stripper-ignore-next
/// Creates a new [`Bin`] object with the specified name.
///
/// Use [`Bin::builder()`] for additional configuration.
#[doc(alias = "gst_bin_new")]
pub fn with_name(name: &str) -> Bin {
assert_initialized_main_thread!();
unsafe { Element::from_glib_none(ffi::gst_bin_new(name.to_glib_none().0)).unsafe_cast() }
}
// rustdoc-stripper-ignore-next
/// Creates a new builder-pattern struct instance to construct [`Bin`] objects.
///
/// This method returns an instance of [`BinBuilder`](crate::builders::BinBuilder) which can be used to create [`Bin`] objects.
/// This method returns an instance of [`BinBuilder`] which can be used to create [`Bin`] objects.
pub fn builder() -> BinBuilder {
BinBuilder::new()
}
@ -311,7 +332,7 @@ mod tests {
fn test_get_children() {
crate::init().unwrap();
let bin = crate::Bin::new(None);
let bin = crate::Bin::new();
bin.add(
&crate::ElementFactory::make("identity")
.name("identity0")

View file

@ -30,7 +30,7 @@
//! # use gstreamer as gst;
//! # use gst::prelude::ElementExtManual;
//! # gst::init();
//! # let pipeline = gst::Pipeline::new(None);
//! # let pipeline = gst::Pipeline::new();
//! let res = pipeline.query_position::<gst::ClockTime>();
//! ```
//!
@ -40,7 +40,7 @@
//! # use gstreamer as gst;
//! # use gst::{format::prelude::*, prelude::ElementExtManual};
//! # gst::init();
//! # let pipeline = gst::Pipeline::new(None);
//! # let pipeline = gst::Pipeline::new();
//! # let seek_flags = gst::SeekFlags::FLUSH | gst::SeekFlags::KEY_UNIT;
//! let seek_pos = gst::ClockTime::from_seconds(10);
//! let res = pipeline.seek_simple(seek_flags, seek_pos);

View file

@ -803,7 +803,7 @@ mod tests {
crate::init().unwrap();
let bin = crate::Bin::new(None);
let bin = crate::Bin::new();
let id1 = crate::ElementFactory::make("identity").build().unwrap();
let id2 = crate::ElementFactory::make("identity").build().unwrap();
@ -834,7 +834,7 @@ mod tests {
crate::init().unwrap();
let bin = crate::Bin::new(None);
let bin = crate::Bin::new();
let id1 = crate::ElementFactory::make("identity").build().unwrap();
let id2 = crate::ElementFactory::make("identity").build().unwrap();

View file

@ -146,8 +146,10 @@ mod element;
pub mod element_factory;
mod bin;
pub use bin::BinBuilder;
mod pipeline;
pub use pipeline::PipelineBuilder;
mod allocation_params;
pub use self::allocation_params::AllocationParams;

View file

@ -1245,7 +1245,7 @@ mod tests {
trace!(cat, "meh");
memdump!(cat, "meh");
let obj = crate::Bin::new(Some("meh"));
let obj = crate::Bin::with_name("meh");
error!(cat, obj: &obj, "meh");
warning!(cat, obj: &obj, "meh");
@ -1276,7 +1276,7 @@ mod tests {
Some("some debug category"),
);
cat.set_threshold(DebugLevel::Info);
let obj = crate::Bin::new(Some("meh"));
let obj = crate::Bin::with_name("meh");
let (sender, receiver) = mpsc::channel();

View file

@ -138,7 +138,7 @@ mod tests {
fn test_deep_notify() {
crate::init().unwrap();
let bin = crate::Bin::new(None);
let bin = crate::Bin::new();
let identity = crate::ElementFactory::make("identity")
.name("id")
.build()

View file

@ -5,10 +5,36 @@ use glib::{prelude::*, translate::*};
use crate::{prelude::*, Pipeline, PipelineFlags};
impl Pipeline {
// rustdoc-stripper-ignore-next
/// Creates a new [`Pipeline`] object with a default name.
///
/// Use [`Pipeline::with_name()`] to create a [`Pipeline`] with a specific name.
/// Use [`Pipeline::builder()`] to get a [`PipelineBuilder`] and then define a specific name.
#[doc(alias = "gst_pipeline_new")]
pub fn new() -> Pipeline {
assert_initialized_main_thread!();
unsafe {
crate::Element::from_glib_none(ffi::gst_pipeline_new(std::ptr::null())).unsafe_cast()
}
}
// rustdoc-stripper-ignore-next
/// Creates a new [`Pipeline`] object with the specified name.
///
/// Use [`Pipeline::builder()`] for additional configuration.
#[doc(alias = "gst_pipeline_new")]
pub fn with_name(name: &str) -> Pipeline {
assert_initialized_main_thread!();
unsafe {
crate::Element::from_glib_none(ffi::gst_pipeline_new(name.to_glib_none().0))
.unsafe_cast()
}
}
// rustdoc-stripper-ignore-next
/// Creates a new builder-pattern struct instance to construct [`Pipeline`] objects.
///
/// This method returns an instance of [`PipelineBuilder`](crate::builders::PipelineBuilder) which can be used to create [`Pipeline`] objects.
/// This method returns an instance of [`PipelineBuilder`] which can be used to create [`Pipeline`] objects.
pub fn builder() -> PipelineBuilder {
PipelineBuilder::new()
}

View file

@ -725,7 +725,7 @@ mod tests {
Some("Test Element")
);
let pipeline = crate::Pipeline::new(None);
let pipeline = crate::Pipeline::new();
let src = ElementFactory::make("fakesrc")
.property("num-buffers", 100i32)
.build()

View file

@ -19,7 +19,7 @@ fn tutorial_main() {
.expect("Could not create sink element");
// Create the empty pipeline
let pipeline = gst::Pipeline::builder().name("test-pipeline").build();
let pipeline = gst::Pipeline::with_name("test-pipeline");
// Build the pipeline
pipeline.add_many([&source, &sink]).unwrap();

View file

@ -30,7 +30,7 @@ fn tutorial_main() {
.expect("Could not create resample element.");
// Create the empty pipeline
let pipeline = gst::Pipeline::builder().name("test-pipeline").build();
let pipeline = gst::Pipeline::with_name("test-pipeline");
// Build the pipeline Note that we are NOT linking the source at this
// point. We will do it later.

View file

@ -101,7 +101,7 @@ fn tutorial_main() {
.expect("Failed to create sink element");
// Create the empty pipeline
let pipeline = gst::Pipeline::builder().name("test-pipeline").build();
let pipeline = gst::Pipeline::with_name("test-pipeline");
pipeline.add_many([&source, &sink]).unwrap();
source.link(&sink).expect("Elements could not be linked.");

View file

@ -54,7 +54,7 @@ fn tutorial_main() {
.build()
.unwrap();
let pipeline = gst::Pipeline::builder().name("test-pipeline").build();
let pipeline = gst::Pipeline::with_name("test-pipeline");
pipeline
.add_many([

View file

@ -107,7 +107,7 @@ fn main() {
.name("app_sink")
.build();
let pipeline = gst::Pipeline::builder().name("test-pipeline").build();
let pipeline = gst::Pipeline::with_name("test-pipeline");
pipeline
.add_many([

View file

@ -27,7 +27,7 @@ fn tutorial_main() -> Result<(), Error> {
.expect("Could not create autoaudiosink element.");
// Create the sink bin, add the elements and link them
let bin = gst::Bin::builder().name("audio_sink_bin").build();
let bin = gst::Bin::with_name("audio_sink_bin");
bin.add_many([&equalizer, &convert, &sink]).unwrap();
gst::Element::link_many([&equalizer, &convert, &sink]).expect("Failed to link elements.");