| 1 | // Take a look at the license at the top of the repository in the LICENSE file. |
| 2 | |
| 3 | use glib::{prelude::*, translate::*}; |
| 4 | |
| 5 | use crate::{ffi, prelude::*, Pipeline, PipelineFlags}; |
| 6 | |
| 7 | impl 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 | |
| 43 | mod sealed { |
| 44 | pub trait Sealed {} |
| 45 | impl<T: super::IsA<super::Pipeline>> Sealed for T {} |
| 46 | } |
| 47 | |
| 48 | pub 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 | |
| 75 | impl<O: IsA<Pipeline>> GstPipelineExtManual for O {} |
| 76 | |
| 77 | impl 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" ] |
| 88 | pub struct PipelineBuilder { |
| 89 | builder: glib::object::ObjectBuilder<'static, Pipeline>, |
| 90 | } |
| 91 | |
| 92 | impl 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 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 | } |
| 218 | |