1// Take a look at the license at the top of the repository in the LICENSE file.
2
3use glib::{prelude::*, translate::*};
4
5use crate::{prelude::*, Pipeline, PipelineFlags};
6
7impl Pipeline {
8 // rustdoc-stripper-ignore-next
9 /// Creates a new [`Pipeline`] object with a default name.
10 ///
11 /// Use [`Pipeline::with_name()`] to create a [`Pipeline`] with a specific name.
12 /// Use [`Pipeline::builder()`] to get a [`PipelineBuilder`] and then define a specific name.
13 #[doc(alias = "gst_pipeline_new")]
14 pub fn new() -> Pipeline {
15 assert_initialized_main_thread!();
16 unsafe {
17 crate::Element::from_glib_none(ffi::gst_pipeline_new(std::ptr::null())).unsafe_cast()
18 }
19 }
20
21 // rustdoc-stripper-ignore-next
22 /// Creates a new [`Pipeline`] object with the specified name.
23 ///
24 /// Use [`Pipeline::builder()`] for additional configuration.
25 #[doc(alias = "gst_pipeline_new")]
26 pub fn with_name(name: &str) -> Pipeline {
27 assert_initialized_main_thread!();
28 unsafe {
29 crate::Element::from_glib_none(ffi::gst_pipeline_new(name.to_glib_none().0))
30 .unsafe_cast()
31 }
32 }
33
34 // rustdoc-stripper-ignore-next
35 /// Creates a new builder-pattern struct instance to construct [`Pipeline`] objects.
36 ///
37 /// This method returns an instance of [`PipelineBuilder`] which can be used to create [`Pipeline`] objects.
38 pub fn builder() -> PipelineBuilder {
39 PipelineBuilder::new()
40 }
41}
42
43mod sealed {
44 pub trait Sealed {}
45 impl<T: super::IsA<super::Pipeline>> Sealed for T {}
46}
47
48pub trait GstPipelineExtManual: sealed::Sealed + IsA<Pipeline> + 'static {
49 fn set_pipeline_flags(&self, flags: PipelineFlags) {
50 unsafe {
51 let ptr: *mut ffi::GstObject = self.as_ptr() as *mut _;
52 let _guard = self.as_ref().object_lock();
53 (*ptr).flags |= flags.into_glib();
54 }
55 }
56
57 fn unset_pipeline_flags(&self, flags: PipelineFlags) {
58 unsafe {
59 let ptr: *mut ffi::GstObject = self.as_ptr() as *mut _;
60 let _guard = self.as_ref().object_lock();
61 (*ptr).flags &= !flags.into_glib();
62 }
63 }
64
65 #[doc(alias = "get_pipeline_flags")]
66 fn pipeline_flags(&self) -> PipelineFlags {
67 unsafe {
68 let ptr: *mut ffi::GstObject = self.as_ptr() as *mut _;
69 let _guard = self.as_ref().object_lock();
70 from_glib((*ptr).flags)
71 }
72 }
73}
74
75impl<O: IsA<Pipeline>> GstPipelineExtManual for O {}
76
77impl Default for Pipeline {
78 fn default() -> Self {
79 glib::object::Object::new()
80 }
81}
82
83// rustdoc-stripper-ignore-next
84/// A [builder-pattern] type to construct [`Pipeline`] objects.
85///
86/// [builder-pattern]: https://doc.rust-lang.org/1.0.0/style/ownership/builders.html
87#[must_use = "The builder must be built to be used"]
88pub struct PipelineBuilder {
89 builder: glib::object::ObjectBuilder<'static, Pipeline>,
90}
91
92impl PipelineBuilder {
93 fn new() -> Self {
94 Self {
95 builder: glib::Object::builder(),
96 }
97 }
98
99 // rustdoc-stripper-ignore-next
100 /// Build the [`Pipeline`].
101 #[must_use = "Building the object from the builder is usually expensive and is not expected to have side effects"]
102 pub fn build(self) -> Pipeline {
103 self.builder.build()
104 }
105
106 pub fn auto_flush_bus(self, auto_flush_bus: bool) -> Self {
107 Self {
108 builder: self.builder.property("auto-flush-bus", auto_flush_bus),
109 }
110 }
111
112 pub fn delay(self, delay: u64) -> Self {
113 Self {
114 builder: self.builder.property("delay", delay),
115 }
116 }
117
118 pub fn latency(self, latency: crate::ClockTime) -> Self {
119 Self {
120 builder: self.builder.property("latency", latency),
121 }
122 }
123
124 pub fn async_handling(self, async_handling: bool) -> Self {
125 Self {
126 builder: self.builder.property("async-handling", async_handling),
127 }
128 }
129
130 pub fn message_forward(self, message_forward: bool) -> Self {
131 Self {
132 builder: self.builder.property("message-forward", message_forward),
133 }
134 }
135
136 pub fn name(self, name: impl Into<glib::GString>) -> Self {
137 Self {
138 builder: self.builder.property("name", name.into()),
139 }
140 }
141}
142