1use glib::{prelude::*, translate::*};
4
5use crate::{ffi, prelude::*, Pipeline, PipelineFlags};
6
7impl Pipeline {
8 #[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 #[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 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#[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 #[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 auto_flush_bus_if_some(self, auto_flush_bus: Option<bool>) -> Self {
113 if let Some(auto_flush_bus) = auto_flush_bus {
114 self.auto_flush_bus(auto_flush_bus)
115 } else {
116 self
117 }
118 }
119
120 pub fn delay(self, delay: u64) -> Self {
121 Self {
122 builder: self.builder.property("delay", delay),
123 }
124 }
125
126 pub fn delay_if(self, delay: u64, predicate: bool) -> Self {
127 if predicate {
128 self.delay(delay)
129 } else {
130 self
131 }
132 }
133
134 pub fn delay_if_some(self, delay: Option<u64>) -> Self {
135 if let Some(delay) = delay {
136 self.delay(delay)
137 } else {
138 self
139 }
140 }
141
142 pub fn latency(self, latency: impl Into<Option<crate::ClockTime>>) -> Self {
143 if let Some(latency) = latency.into() {
144 Self {
145 builder: self.builder.property("latency", latency),
146 }
147 } else {
148 self
149 }
150 }
151
152 pub fn latency_if(self, latency: impl Into<Option<crate::ClockTime>>, predicate: bool) -> Self {
153 if predicate {
154 self.latency(latency)
155 } else {
156 self
157 }
158 }
159
160 pub fn latency_if_some(self, latency: Option<crate::ClockTime>) -> Self {
161 if let Some(latency) = latency {
162 self.latency(latency)
163 } else {
164 self
165 }
166 }
167
168 pub fn async_handling(self, async_handling: bool) -> Self {
169 Self {
170 builder: self.builder.property("async-handling", async_handling),
171 }
172 }
173
174 pub fn async_handling_if_some(self, async_handling: Option<bool>) -> Self {
175 if let Some(async_handling) = async_handling {
176 self.async_handling(async_handling)
177 } else {
178 self
179 }
180 }
181
182 pub fn message_forward(self, message_forward: bool) -> Self {
183 Self {
184 builder: self.builder.property("message-forward", message_forward),
185 }
186 }
187
188 pub fn message_forward_if_some(self, message_forward: Option<bool>) -> Self {
189 if let Some(message_forward) = message_forward {
190 self.message_forward(message_forward)
191 } else {
192 self
193 }
194 }
195
196 pub fn name(self, name: impl Into<glib::GString>) -> Self {
197 Self {
198 builder: self.builder.property("name", name.into()),
199 }
200 }
201
202 pub fn name_if(self, name: impl Into<glib::GString>, predicate: bool) -> Self {
203 if predicate {
204 self.name(name)
205 } else {
206 self
207 }
208 }
209
210 pub fn name_if_some(self, name: Option<impl Into<glib::GString>>) -> Self {
211 if let Some(name) = name {
212 self.name(name)
213 } else {
214 self
215 }
216 }
217}