gstreamer_base/auto/
base_transform.rs

1// This file was generated by gir (https://github.com/gtk-rs/gir)
2// from gir-files (https://github.com/gtk-rs/gir-files)
3// from gst-gir-files (https://gitlab.freedesktop.org/gstreamer/gir-files-rs.git)
4// DO NOT EDIT
5
6use crate::ffi;
7use glib::{
8    prelude::*,
9    signal::{connect_raw, SignalHandlerId},
10    translate::*,
11};
12use std::boxed::Box as Box_;
13
14glib::wrapper! {
15    /// This base class is for filter elements that process data. Elements
16    /// that are suitable for implementation using [`BaseTransform`][crate::BaseTransform] are ones
17    /// where the size and caps of the output is known entirely from the input
18    /// caps and buffer sizes. These include elements that directly transform
19    /// one buffer into another, modify the contents of a buffer in-place, as
20    /// well as elements that collate multiple input buffers into one output buffer,
21    /// or that expand one input buffer into multiple output buffers. See below
22    /// for more concrete use cases.
23    ///
24    /// It provides for:
25    ///
26    /// * one sinkpad and one srcpad
27    /// * Possible formats on sink and source pad implemented
28    ///  with custom transform_caps function. By default uses
29    ///  same format on sink and source.
30    ///
31    /// * Handles state changes
32    /// * Does flushing
33    /// * Push mode
34    /// * Pull mode if the sub-class transform can operate on arbitrary data
35    ///
36    /// # Use Cases
37    ///
38    /// ## Passthrough mode
39    ///
40    ///  * Element has no interest in modifying the buffer. It may want to inspect it,
41    ///  in which case the element should have a transform_ip function. If there
42    ///  is no transform_ip function in passthrough mode, the buffer is pushed
43    ///  intact.
44    ///
45    ///  * The `GstBaseTransformClass.passthrough_on_same_caps` variable
46    ///  will automatically set/unset passthrough based on whether the
47    ///  element negotiates the same caps on both pads.
48    ///
49    ///  * `GstBaseTransformClass.passthrough_on_same_caps` on an element that
50    ///  doesn't implement a transform_caps function is useful for elements that
51    ///  only inspect data (such as level)
52    ///
53    ///  * Example elements
54    ///
55    ///  * Level
56    ///  * Videoscale, audioconvert, videoconvert, audioresample in certain modes.
57    ///
58    /// ## Modifications in-place - input buffer and output buffer are the same thing.
59    ///
60    /// * The element must implement a transform_ip function.
61    /// * Output buffer size must <= input buffer size
62    /// * If the always_in_place flag is set, non-writable buffers will be copied
63    ///  and passed to the transform_ip function, otherwise a new buffer will be
64    ///  created and the transform function called.
65    ///
66    /// * Incoming writable buffers will be passed to the transform_ip function
67    ///  immediately.
68    /// * only implementing transform_ip and not transform implies always_in_place = [`true`]
69    ///
70    ///  * Example elements:
71    ///  * Volume
72    ///  * Audioconvert in certain modes (signed/unsigned conversion)
73    ///  * videoconvert in certain modes (endianness swapping)
74    ///
75    /// ## Modifications only to the caps/metadata of a buffer
76    ///
77    /// * The element does not require writable data, but non-writable buffers
78    ///  should be subbuffered so that the meta-information can be replaced.
79    ///
80    /// * Elements wishing to operate in this mode should replace the
81    ///  prepare_output_buffer method to create subbuffers of the input buffer
82    ///  and set always_in_place to [`true`]
83    ///
84    /// * Example elements
85    ///  * Capsfilter when setting caps on outgoing buffers that have
86    ///  none.
87    ///  * identity when it is going to re-timestamp buffers by
88    ///  datarate.
89    ///
90    /// ## Normal mode
91    ///  * always_in_place flag is not set, or there is no transform_ip function
92    ///  * Element will receive an input buffer and output buffer to operate on.
93    ///  * Output buffer is allocated by calling the prepare_output_buffer function.
94    ///  * Example elements:
95    ///  * Videoscale, videoconvert, audioconvert when doing
96    ///  scaling/conversions
97    ///
98    /// ## Special output buffer allocations
99    ///  * Elements which need to do special allocation of their output buffers
100    ///  beyond allocating output buffers via the negotiated allocator or
101    ///  buffer pool should implement the prepare_output_buffer method.
102    ///
103    ///  * Example elements:
104    ///  * efence
105    ///
106    /// # Sub-class settable flags on GstBaseTransform
107    ///
108    /// * passthrough
109    ///
110    ///  * Implies that in the current configuration, the sub-class is not interested in modifying the buffers.
111    ///  * Elements which are always in passthrough mode whenever the same caps has been negotiated on both pads can set the class variable passthrough_on_same_caps to have this behaviour automatically.
112    ///
113    /// * always_in_place
114    ///  * Determines whether a non-writable buffer will be copied before passing
115    ///  to the transform_ip function.
116    ///
117    ///  * Implied [`true`] if no transform function is implemented.
118    ///  * Implied [`false`] if ONLY transform function is implemented.
119    ///
120    /// This is an Abstract Base Class, you cannot instantiate it.
121    ///
122    /// ## Properties
123    ///
124    ///
125    /// #### `qos`
126    ///  Readable | Writeable
127    /// <details><summary><h4>Object</h4></summary>
128    ///
129    ///
130    /// #### `name`
131    ///  Readable | Writeable | Construct
132    ///
133    ///
134    /// #### `parent`
135    ///  The parent of the object. Please note, that when changing the 'parent'
136    /// property, we don't emit [`notify`][struct@crate::glib::Object#notify] and [`deep-notify`][struct@crate::gst::Object#deep-notify]
137    /// signals due to locking issues. In some cases one can use
138    /// `GstBin::element-added` or `GstBin::element-removed` signals on the parent to
139    /// achieve a similar effect.
140    ///
141    /// Readable | Writeable
142    /// </details>
143    ///
144    /// # Implements
145    ///
146    /// [`BaseTransformExt`][trait@crate::prelude::BaseTransformExt], [`trait@gst::prelude::ElementExt`], [`trait@gst::prelude::ObjectExt`], [`trait@glib::ObjectExt`], [`BaseTransformExtManual`][trait@crate::prelude::BaseTransformExtManual]
147    #[doc(alias = "GstBaseTransform")]
148    pub struct BaseTransform(Object<ffi::GstBaseTransform, ffi::GstBaseTransformClass>) @extends gst::Element, gst::Object;
149
150    match fn {
151        type_ => || ffi::gst_base_transform_get_type(),
152    }
153}
154
155impl BaseTransform {
156    pub const NONE: Option<&'static BaseTransform> = None;
157}
158
159unsafe impl Send for BaseTransform {}
160unsafe impl Sync for BaseTransform {}
161
162mod sealed {
163    pub trait Sealed {}
164    impl<T: super::IsA<super::BaseTransform>> Sealed for T {}
165}
166
167/// Trait containing all [`struct@BaseTransform`] methods.
168///
169/// # Implementors
170///
171/// [`BaseTransform`][struct@crate::BaseTransform]
172pub trait BaseTransformExt: IsA<BaseTransform> + sealed::Sealed + 'static {
173    ///
174    /// # Returns
175    ///
176    /// the instance of the [`gst::BufferPool`][crate::gst::BufferPool] used
177    /// by `self`; free it after use
178    #[doc(alias = "gst_base_transform_get_buffer_pool")]
179    #[doc(alias = "get_buffer_pool")]
180    fn buffer_pool(&self) -> Option<gst::BufferPool> {
181        unsafe {
182            from_glib_full(ffi::gst_base_transform_get_buffer_pool(
183                self.as_ref().to_glib_none().0,
184            ))
185        }
186    }
187
188    /// See if `self` is configured as a in_place transform.
189    ///
190    /// # Returns
191    ///
192    /// [`true`] if the transform is configured in in_place mode.
193    ///
194    /// MT safe.
195    #[doc(alias = "gst_base_transform_is_in_place")]
196    fn is_in_place(&self) -> bool {
197        unsafe {
198            from_glib(ffi::gst_base_transform_is_in_place(
199                self.as_ref().to_glib_none().0,
200            ))
201        }
202    }
203
204    /// See if `self` is configured as a passthrough transform.
205    ///
206    /// # Returns
207    ///
208    /// [`true`] if the transform is configured in passthrough mode.
209    ///
210    /// MT safe.
211    #[doc(alias = "gst_base_transform_is_passthrough")]
212    fn is_passthrough(&self) -> bool {
213        unsafe {
214            from_glib(ffi::gst_base_transform_is_passthrough(
215                self.as_ref().to_glib_none().0,
216            ))
217        }
218    }
219
220    /// Negotiates src pad caps with downstream elements if the source pad is
221    /// marked as needing reconfiguring. Unmarks GST_PAD_FLAG_NEED_RECONFIGURE in
222    /// any case. But marks it again if negotiation fails.
223    ///
224    /// Do not call this in the `GstBaseTransformClass::transform` or
225    /// `GstBaseTransformClass::transform_ip` vmethod. Call this in
226    /// `GstBaseTransformClass::submit_input_buffer`,
227    /// `GstBaseTransformClass::prepare_output_buffer` or in
228    /// `GstBaseTransformClass::generate_output` _before_ any output buffer is
229    /// allocated.
230    ///
231    /// It will be default be called when handling an ALLOCATION query or at the
232    /// very beginning of the default `GstBaseTransformClass::submit_input_buffer`
233    /// implementation.
234    ///
235    /// # Returns
236    ///
237    /// [`true`] if the negotiation succeeded, else [`false`].
238    #[cfg(feature = "v1_18")]
239    #[cfg_attr(docsrs, doc(cfg(feature = "v1_18")))]
240    #[doc(alias = "gst_base_transform_reconfigure")]
241    fn reconfigure(&self) -> bool {
242        unsafe {
243            from_glib(ffi::gst_base_transform_reconfigure(
244                self.as_ref().to_glib_none().0,
245            ))
246        }
247    }
248
249    /// Instructs `self` to request renegotiation upstream. This function is
250    /// typically called after properties on the transform were set that
251    /// influence the input format.
252    #[doc(alias = "gst_base_transform_reconfigure_sink")]
253    fn reconfigure_sink(&self) {
254        unsafe {
255            ffi::gst_base_transform_reconfigure_sink(self.as_ref().to_glib_none().0);
256        }
257    }
258
259    /// Instructs `self` to renegotiate a new downstream transform on the next
260    /// buffer. This function is typically called after properties on the transform
261    /// were set that influence the output format.
262    #[doc(alias = "gst_base_transform_reconfigure_src")]
263    fn reconfigure_src(&self) {
264        unsafe {
265            ffi::gst_base_transform_reconfigure_src(self.as_ref().to_glib_none().0);
266        }
267    }
268
269    /// If `gap_aware` is [`false`] (the default), output buffers will have the
270    /// [`gst::BufferFlags::GAP`][crate::gst::BufferFlags::GAP] flag unset.
271    ///
272    /// If set to [`true`], the element must handle output buffers with this flag set
273    /// correctly, i.e. it can assume that the buffer contains neutral data but must
274    /// unset the flag if the output is no neutral data.
275    ///
276    /// MT safe.
277    /// ## `gap_aware`
278    /// New state
279    #[doc(alias = "gst_base_transform_set_gap_aware")]
280    fn set_gap_aware(&self, gap_aware: bool) {
281        unsafe {
282            ffi::gst_base_transform_set_gap_aware(
283                self.as_ref().to_glib_none().0,
284                gap_aware.into_glib(),
285            );
286        }
287    }
288
289    /// Determines whether a non-writable buffer will be copied before passing
290    /// to the transform_ip function.
291    ///
292    ///  * Always [`true`] if no transform function is implemented.
293    ///  * Always [`false`] if ONLY transform function is implemented.
294    ///
295    /// MT safe.
296    /// ## `in_place`
297    /// Boolean value indicating that we would like to operate
298    /// on in_place buffers.
299    #[doc(alias = "gst_base_transform_set_in_place")]
300    fn set_in_place(&self, in_place: bool) {
301        unsafe {
302            ffi::gst_base_transform_set_in_place(
303                self.as_ref().to_glib_none().0,
304                in_place.into_glib(),
305            );
306        }
307    }
308
309    /// Set passthrough mode for this filter by default. This is mostly
310    /// useful for filters that do not care about negotiation.
311    ///
312    /// Always [`true`] for filters which don't implement either a transform
313    /// or transform_ip or generate_output method.
314    ///
315    /// MT safe.
316    /// ## `passthrough`
317    /// boolean indicating passthrough mode.
318    #[doc(alias = "gst_base_transform_set_passthrough")]
319    fn set_passthrough(&self, passthrough: bool) {
320        unsafe {
321            ffi::gst_base_transform_set_passthrough(
322                self.as_ref().to_glib_none().0,
323                passthrough.into_glib(),
324            );
325        }
326    }
327
328    /// If `prefer_passthrough` is [`true`] (the default), `self` will check and
329    /// prefer passthrough caps from the list of caps returned by the
330    /// transform_caps vmethod.
331    ///
332    /// If set to [`false`], the element must order the caps returned from the
333    /// transform_caps function in such a way that the preferred format is
334    /// first in the list. This can be interesting for transforms that can do
335    /// passthrough transforms but prefer to do something else, like a
336    /// capsfilter.
337    ///
338    /// MT safe.
339    /// ## `prefer_passthrough`
340    /// New state
341    #[doc(alias = "gst_base_transform_set_prefer_passthrough")]
342    fn set_prefer_passthrough(&self, prefer_passthrough: bool) {
343        unsafe {
344            ffi::gst_base_transform_set_prefer_passthrough(
345                self.as_ref().to_glib_none().0,
346                prefer_passthrough.into_glib(),
347            );
348        }
349    }
350
351    /// Set the QoS parameters in the transform. This function is called internally
352    /// when a QOS event is received but subclasses can provide custom information
353    /// when needed.
354    ///
355    /// MT safe.
356    /// ## `proportion`
357    /// the proportion
358    /// ## `diff`
359    /// the diff against the clock
360    /// ## `timestamp`
361    /// the timestamp of the buffer generating the QoS expressed in
362    /// running_time.
363    #[doc(alias = "gst_base_transform_update_qos")]
364    fn update_qos(&self, proportion: f64, diff: gst::ClockTimeDiff, timestamp: gst::ClockTime) {
365        unsafe {
366            ffi::gst_base_transform_update_qos(
367                self.as_ref().to_glib_none().0,
368                proportion,
369                diff,
370                timestamp.into_glib(),
371            );
372        }
373    }
374
375    /// Updates the srcpad caps and sends the caps downstream. This function
376    /// can be used by subclasses when they have already negotiated their caps
377    /// but found a change in them (or computed new information). This way,
378    /// they can notify downstream about that change without losing any
379    /// buffer.
380    /// ## `updated_caps`
381    /// An updated version of the srcpad caps to be pushed
382    /// downstream
383    ///
384    /// # Returns
385    ///
386    /// [`true`] if the caps could be sent downstream [`false`] otherwise
387    #[doc(alias = "gst_base_transform_update_src_caps")]
388    fn update_src_caps(&self, updated_caps: &gst::Caps) -> Result<(), glib::error::BoolError> {
389        unsafe {
390            glib::result_from_gboolean!(
391                ffi::gst_base_transform_update_src_caps(
392                    self.as_ref().to_glib_none().0,
393                    updated_caps.to_glib_none().0
394                ),
395                "Failed to update src caps"
396            )
397        }
398    }
399
400    fn is_qos(&self) -> bool {
401        ObjectExt::property(self.as_ref(), "qos")
402    }
403
404    fn set_qos(&self, qos: bool) {
405        ObjectExt::set_property(self.as_ref(), "qos", qos)
406    }
407
408    #[doc(alias = "qos")]
409    fn connect_qos_notify<F: Fn(&Self) + Send + Sync + 'static>(&self, f: F) -> SignalHandlerId {
410        unsafe extern "C" fn notify_qos_trampoline<
411            P: IsA<BaseTransform>,
412            F: Fn(&P) + Send + Sync + 'static,
413        >(
414            this: *mut ffi::GstBaseTransform,
415            _param_spec: glib::ffi::gpointer,
416            f: glib::ffi::gpointer,
417        ) {
418            let f: &F = &*(f as *const F);
419            f(BaseTransform::from_glib_borrow(this).unsafe_cast_ref())
420        }
421        unsafe {
422            let f: Box_<F> = Box_::new(f);
423            connect_raw(
424                self.as_ptr() as *mut _,
425                b"notify::qos\0".as_ptr() as *const _,
426                Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
427                    notify_qos_trampoline::<Self, F> as *const (),
428                )),
429                Box_::into_raw(f),
430            )
431        }
432    }
433}
434
435impl<O: IsA<BaseTransform>> BaseTransformExt for O {}