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
162/// Trait containing all [`struct@BaseTransform`] methods.
163///
164/// # Implementors
165///
166/// [`BaseTransform`][struct@crate::BaseTransform]
167pub trait BaseTransformExt: IsA<BaseTransform> + 'static {
168 ///
169 /// # Returns
170 ///
171 /// the instance of the [`gst::BufferPool`][crate::gst::BufferPool] used
172 /// by `self`; free it after use
173 #[doc(alias = "gst_base_transform_get_buffer_pool")]
174 #[doc(alias = "get_buffer_pool")]
175 fn buffer_pool(&self) -> Option<gst::BufferPool> {
176 unsafe {
177 from_glib_full(ffi::gst_base_transform_get_buffer_pool(
178 self.as_ref().to_glib_none().0,
179 ))
180 }
181 }
182
183 /// See if `self` is configured as a in_place transform.
184 ///
185 /// # Returns
186 ///
187 /// [`true`] if the transform is configured in in_place mode.
188 ///
189 /// MT safe.
190 #[doc(alias = "gst_base_transform_is_in_place")]
191 fn is_in_place(&self) -> bool {
192 unsafe {
193 from_glib(ffi::gst_base_transform_is_in_place(
194 self.as_ref().to_glib_none().0,
195 ))
196 }
197 }
198
199 /// See if `self` is configured as a passthrough transform.
200 ///
201 /// # Returns
202 ///
203 /// [`true`] if the transform is configured in passthrough mode.
204 ///
205 /// MT safe.
206 #[doc(alias = "gst_base_transform_is_passthrough")]
207 fn is_passthrough(&self) -> bool {
208 unsafe {
209 from_glib(ffi::gst_base_transform_is_passthrough(
210 self.as_ref().to_glib_none().0,
211 ))
212 }
213 }
214
215 /// Negotiates src pad caps with downstream elements if the source pad is
216 /// marked as needing reconfiguring. Unmarks GST_PAD_FLAG_NEED_RECONFIGURE in
217 /// any case. But marks it again if negotiation fails.
218 ///
219 /// Do not call this in the `GstBaseTransformClass::transform` or
220 /// `GstBaseTransformClass::transform_ip` vmethod. Call this in
221 /// `GstBaseTransformClass::submit_input_buffer`,
222 /// `GstBaseTransformClass::prepare_output_buffer` or in
223 /// `GstBaseTransformClass::generate_output` _before_ any output buffer is
224 /// allocated.
225 ///
226 /// It will be default be called when handling an ALLOCATION query or at the
227 /// very beginning of the default `GstBaseTransformClass::submit_input_buffer`
228 /// implementation.
229 ///
230 /// # Returns
231 ///
232 /// [`true`] if the negotiation succeeded, else [`false`].
233 #[cfg(feature = "v1_18")]
234 #[cfg_attr(docsrs, doc(cfg(feature = "v1_18")))]
235 #[doc(alias = "gst_base_transform_reconfigure")]
236 fn reconfigure(&self) -> bool {
237 unsafe {
238 from_glib(ffi::gst_base_transform_reconfigure(
239 self.as_ref().to_glib_none().0,
240 ))
241 }
242 }
243
244 /// Instructs `self` to request renegotiation upstream. This function is
245 /// typically called after properties on the transform were set that
246 /// influence the input format.
247 #[doc(alias = "gst_base_transform_reconfigure_sink")]
248 fn reconfigure_sink(&self) {
249 unsafe {
250 ffi::gst_base_transform_reconfigure_sink(self.as_ref().to_glib_none().0);
251 }
252 }
253
254 /// Instructs `self` to renegotiate a new downstream transform on the next
255 /// buffer. This function is typically called after properties on the transform
256 /// were set that influence the output format.
257 #[doc(alias = "gst_base_transform_reconfigure_src")]
258 fn reconfigure_src(&self) {
259 unsafe {
260 ffi::gst_base_transform_reconfigure_src(self.as_ref().to_glib_none().0);
261 }
262 }
263
264 /// If `gap_aware` is [`false`] (the default), output buffers will have the
265 /// [`gst::BufferFlags::GAP`][crate::gst::BufferFlags::GAP] flag unset.
266 ///
267 /// If set to [`true`], the element must handle output buffers with this flag set
268 /// correctly, i.e. it can assume that the buffer contains neutral data but must
269 /// unset the flag if the output is no neutral data.
270 ///
271 /// MT safe.
272 /// ## `gap_aware`
273 /// New state
274 #[doc(alias = "gst_base_transform_set_gap_aware")]
275 fn set_gap_aware(&self, gap_aware: bool) {
276 unsafe {
277 ffi::gst_base_transform_set_gap_aware(
278 self.as_ref().to_glib_none().0,
279 gap_aware.into_glib(),
280 );
281 }
282 }
283
284 /// Determines whether a non-writable buffer will be copied before passing
285 /// to the transform_ip function.
286 ///
287 /// * Always [`true`] if no transform function is implemented.
288 /// * Always [`false`] if ONLY transform function is implemented.
289 ///
290 /// MT safe.
291 /// ## `in_place`
292 /// Boolean value indicating that we would like to operate
293 /// on in_place buffers.
294 #[doc(alias = "gst_base_transform_set_in_place")]
295 fn set_in_place(&self, in_place: bool) {
296 unsafe {
297 ffi::gst_base_transform_set_in_place(
298 self.as_ref().to_glib_none().0,
299 in_place.into_glib(),
300 );
301 }
302 }
303
304 /// Set passthrough mode for this filter by default. This is mostly
305 /// useful for filters that do not care about negotiation.
306 ///
307 /// Always [`true`] for filters which don't implement either a transform
308 /// or transform_ip or generate_output method.
309 ///
310 /// MT safe.
311 /// ## `passthrough`
312 /// boolean indicating passthrough mode.
313 #[doc(alias = "gst_base_transform_set_passthrough")]
314 fn set_passthrough(&self, passthrough: bool) {
315 unsafe {
316 ffi::gst_base_transform_set_passthrough(
317 self.as_ref().to_glib_none().0,
318 passthrough.into_glib(),
319 );
320 }
321 }
322
323 /// If `prefer_passthrough` is [`true`] (the default), `self` will check and
324 /// prefer passthrough caps from the list of caps returned by the
325 /// transform_caps vmethod.
326 ///
327 /// If set to [`false`], the element must order the caps returned from the
328 /// transform_caps function in such a way that the preferred format is
329 /// first in the list. This can be interesting for transforms that can do
330 /// passthrough transforms but prefer to do something else, like a
331 /// capsfilter.
332 ///
333 /// MT safe.
334 /// ## `prefer_passthrough`
335 /// New state
336 #[doc(alias = "gst_base_transform_set_prefer_passthrough")]
337 fn set_prefer_passthrough(&self, prefer_passthrough: bool) {
338 unsafe {
339 ffi::gst_base_transform_set_prefer_passthrough(
340 self.as_ref().to_glib_none().0,
341 prefer_passthrough.into_glib(),
342 );
343 }
344 }
345
346 /// Set the QoS parameters in the transform. This function is called internally
347 /// when a QOS event is received but subclasses can provide custom information
348 /// when needed.
349 ///
350 /// MT safe.
351 /// ## `proportion`
352 /// the proportion
353 /// ## `diff`
354 /// the diff against the clock
355 /// ## `timestamp`
356 /// the timestamp of the buffer generating the QoS expressed in
357 /// running_time.
358 #[doc(alias = "gst_base_transform_update_qos")]
359 fn update_qos(&self, proportion: f64, diff: gst::ClockTimeDiff, timestamp: gst::ClockTime) {
360 unsafe {
361 ffi::gst_base_transform_update_qos(
362 self.as_ref().to_glib_none().0,
363 proportion,
364 diff,
365 timestamp.into_glib(),
366 );
367 }
368 }
369
370 /// Updates the srcpad caps and sends the caps downstream. This function
371 /// can be used by subclasses when they have already negotiated their caps
372 /// but found a change in them (or computed new information). This way,
373 /// they can notify downstream about that change without losing any
374 /// buffer.
375 /// ## `updated_caps`
376 /// An updated version of the srcpad caps to be pushed
377 /// downstream
378 ///
379 /// # Returns
380 ///
381 /// [`true`] if the caps could be sent downstream [`false`] otherwise
382 #[doc(alias = "gst_base_transform_update_src_caps")]
383 fn update_src_caps(&self, updated_caps: &gst::Caps) -> Result<(), glib::error::BoolError> {
384 unsafe {
385 glib::result_from_gboolean!(
386 ffi::gst_base_transform_update_src_caps(
387 self.as_ref().to_glib_none().0,
388 updated_caps.to_glib_none().0
389 ),
390 "Failed to update src caps"
391 )
392 }
393 }
394
395 fn is_qos(&self) -> bool {
396 ObjectExt::property(self.as_ref(), "qos")
397 }
398
399 fn set_qos(&self, qos: bool) {
400 ObjectExt::set_property(self.as_ref(), "qos", qos)
401 }
402
403 #[doc(alias = "qos")]
404 fn connect_qos_notify<F: Fn(&Self) + Send + Sync + 'static>(&self, f: F) -> SignalHandlerId {
405 unsafe extern "C" fn notify_qos_trampoline<
406 P: IsA<BaseTransform>,
407 F: Fn(&P) + Send + Sync + 'static,
408 >(
409 this: *mut ffi::GstBaseTransform,
410 _param_spec: glib::ffi::gpointer,
411 f: glib::ffi::gpointer,
412 ) {
413 let f: &F = &*(f as *const F);
414 f(BaseTransform::from_glib_borrow(this).unsafe_cast_ref())
415 }
416 unsafe {
417 let f: Box_<F> = Box_::new(f);
418 connect_raw(
419 self.as_ptr() as *mut _,
420 c"notify::qos".as_ptr() as *const _,
421 Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
422 notify_qos_trampoline::<Self, F> as *const (),
423 )),
424 Box_::into_raw(f),
425 )
426 }
427 }
428}
429
430impl<O: IsA<BaseTransform>> BaseTransformExt for O {}