gstreamer/
pipeline.rs

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::{ffi, 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<'a>() -> PipelineBuilder<'a> {
39        assert_initialized_main_thread!();
40        PipelineBuilder {
41            builder: crate::Object::builder(),
42        }
43    }
44}
45
46pub trait GstPipelineExtManual: IsA<Pipeline> + 'static {
47    fn set_pipeline_flags(&self, flags: PipelineFlags) {
48        unsafe {
49            let ptr: *mut ffi::GstObject = self.as_ptr() as *mut _;
50            let _guard = self.as_ref().object_lock();
51            (*ptr).flags |= flags.into_glib();
52        }
53    }
54
55    fn unset_pipeline_flags(&self, flags: PipelineFlags) {
56        unsafe {
57            let ptr: *mut ffi::GstObject = self.as_ptr() as *mut _;
58            let _guard = self.as_ref().object_lock();
59            (*ptr).flags &= !flags.into_glib();
60        }
61    }
62
63    #[doc(alias = "get_pipeline_flags")]
64    fn pipeline_flags(&self) -> PipelineFlags {
65        unsafe {
66            let ptr: *mut ffi::GstObject = self.as_ptr() as *mut _;
67            let _guard = self.as_ref().object_lock();
68            from_glib((*ptr).flags)
69        }
70    }
71}
72
73impl<O: IsA<Pipeline>> GstPipelineExtManual for O {}
74
75impl Default for Pipeline {
76    fn default() -> Self {
77        glib::object::Object::new()
78    }
79}
80
81// rustdoc-stripper-ignore-next
82/// A [builder-pattern] type to construct [`Pipeline`] objects.
83///
84/// [builder-pattern]: https://doc.rust-lang.org/1.0.0/style/ownership/builders.html
85#[must_use = "The builder must be built to be used"]
86pub struct PipelineBuilder<'a> {
87    builder: crate::gobject::GObjectBuilder<'a, Pipeline>,
88}
89
90impl<'a> PipelineBuilder<'a> {
91    // rustdoc-stripper-ignore-next
92    /// Build the [`Pipeline`].
93    ///
94    /// # Panics
95    ///
96    /// This panics if the [`Pipeline`] doesn't have all the given properties or
97    /// property values of the wrong type are provided.
98    #[must_use = "Building the object from the builder is usually expensive and is not expected to have side effects"]
99    pub fn build(self) -> Pipeline {
100        self.builder.build().unwrap()
101    }
102
103    pub fn auto_flush_bus(self, auto_flush_bus: bool) -> Self {
104        Self {
105            builder: self.builder.property("auto-flush-bus", auto_flush_bus),
106        }
107    }
108
109    pub fn auto_flush_bus_if_some(self, auto_flush_bus: Option<bool>) -> Self {
110        if let Some(auto_flush_bus) = auto_flush_bus {
111            self.auto_flush_bus(auto_flush_bus)
112        } else {
113            self
114        }
115    }
116
117    pub fn delay(self, delay: u64) -> Self {
118        Self {
119            builder: self.builder.property("delay", delay),
120        }
121    }
122
123    pub fn delay_if(self, delay: u64, predicate: bool) -> Self {
124        if predicate {
125            self.delay(delay)
126        } else {
127            self
128        }
129    }
130
131    pub fn delay_if_some(self, delay: Option<u64>) -> Self {
132        if let Some(delay) = delay {
133            self.delay(delay)
134        } else {
135            self
136        }
137    }
138
139    pub fn latency(self, latency: impl Into<Option<crate::ClockTime>>) -> Self {
140        if let Some(latency) = latency.into() {
141            Self {
142                builder: self.builder.property("latency", latency),
143            }
144        } else {
145            self
146        }
147    }
148
149    pub fn latency_if(self, latency: impl Into<Option<crate::ClockTime>>, predicate: bool) -> Self {
150        if predicate {
151            self.latency(latency)
152        } else {
153            self
154        }
155    }
156
157    pub fn latency_if_some(self, latency: Option<crate::ClockTime>) -> Self {
158        if let Some(latency) = latency {
159            self.latency(latency)
160        } else {
161            self
162        }
163    }
164
165    pub fn async_handling(self, async_handling: bool) -> Self {
166        Self {
167            builder: self.builder.property("async-handling", async_handling),
168        }
169    }
170
171    pub fn async_handling_if_some(self, async_handling: Option<bool>) -> Self {
172        if let Some(async_handling) = async_handling {
173            self.async_handling(async_handling)
174        } else {
175            self
176        }
177    }
178
179    pub fn message_forward(self, message_forward: bool) -> Self {
180        Self {
181            builder: self.builder.property("message-forward", message_forward),
182        }
183    }
184
185    pub fn message_forward_if_some(self, message_forward: Option<bool>) -> Self {
186        if let Some(message_forward) = message_forward {
187            self.message_forward(message_forward)
188        } else {
189            self
190        }
191    }
192
193    // rustdoc-stripper-ignore-next
194    /// Sets property `name` to the given value `value`.
195    ///
196    /// Overrides any default or previously defined value for `name`.
197    #[inline]
198    pub fn property(self, name: &'a str, value: impl Into<glib::Value> + 'a) -> Self {
199        Self {
200            builder: self.builder.property(name, value),
201        }
202    }
203
204    // rustdoc-stripper-ignore-next
205    /// Sets property `name` to the given string value `value`.
206    #[inline]
207    pub fn property_from_str(self, name: &'a str, value: &'a str) -> Self {
208        Self {
209            builder: self.builder.property_from_str(name, value),
210        }
211    }
212
213    impl_builder_gvalue_extra_setters!(property_and_name);
214}