Skip to main content

gstreamer_base/auto/
base_parse.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::{SignalHandlerId, connect_raw},
10    translate::*,
11};
12use std::boxed::Box as Box_;
13
14glib::wrapper! {
15    /// This base class is for parser elements that process data and splits it
16    /// into separate audio/video/whatever frames.
17    ///
18    /// It provides for:
19    ///
20    ///  * provides one sink pad and one source pad
21    ///  * handles state changes
22    ///  * can operate in pull mode or push mode
23    ///  * handles seeking in both modes
24    ///  * handles events (SEGMENT/EOS/FLUSH)
25    ///  * handles queries (POSITION/DURATION/SEEKING/FORMAT/CONVERT)
26    ///  * handles flushing
27    ///
28    /// The purpose of this base class is to provide the basic functionality of
29    /// a parser and share a lot of rather complex code.
30    ///
31    /// # Description of the parsing mechanism:
32    ///
33    /// ## Set-up phase
34    ///
35    ///  * [`BaseParse`][crate::BaseParse] calls `GstBaseParseClass::start` to inform subclass
36    ///  that data processing is about to start now.
37    ///
38    ///  * [`BaseParse`][crate::BaseParse] class calls `GstBaseParseClass::set_sink_caps` to
39    ///  inform the subclass about incoming sinkpad caps. Subclass could
40    ///  already set the srcpad caps accordingly, but this might be delayed
41    ///  until calling [`BaseParseExtManual::finish_frame()`][crate::prelude::BaseParseExtManual::finish_frame()] with a non-queued frame.
42    ///
43    ///  * At least at this point subclass needs to tell the [`BaseParse`][crate::BaseParse] class
44    ///  how big data chunks it wants to receive (minimum frame size ). It can
45    ///  do this with [`BaseParseExt::set_min_frame_size()`][crate::prelude::BaseParseExt::set_min_frame_size()].
46    ///
47    ///  * [`BaseParse`][crate::BaseParse] class sets up appropriate data passing mode (pull/push)
48    ///  and starts to process the data.
49    ///
50    /// ## Parsing phase
51    ///
52    ///  * [`BaseParse`][crate::BaseParse] gathers at least min_frame_size bytes of data either
53    ///  by pulling it from upstream or collecting buffers in an internal
54    ///  [`Adapter`][crate::Adapter].
55    ///
56    ///  * A buffer of (at least) min_frame_size bytes is passed to subclass
57    ///  with `GstBaseParseClass::handle_frame`. Subclass checks the contents
58    ///  and can optionally return [`gst::FlowReturn::Ok`][crate::gst::FlowReturn::Ok] along with an amount of data
59    ///  to be skipped to find a valid frame (which will result in a
60    ///  subsequent DISCONT). If, otherwise, the buffer does not hold a
61    ///  complete frame, `GstBaseParseClass::handle_frame` can merely return
62    ///  and will be called again when additional data is available. In push
63    ///  mode this amounts to an additional input buffer (thus minimal
64    ///  additional latency), in pull mode this amounts to some arbitrary
65    ///  reasonable buffer size increase.
66    ///
67    ///  Of course, [`BaseParseExt::set_min_frame_size()`][crate::prelude::BaseParseExt::set_min_frame_size()] could also be used if
68    ///  a very specific known amount of additional data is required. If,
69    ///  however, the buffer holds a complete valid frame, it can pass the
70    ///  size of this frame to [`BaseParseExtManual::finish_frame()`][crate::prelude::BaseParseExtManual::finish_frame()].
71    ///
72    ///  If acting as a converter, it can also merely indicate consumed input
73    ///  data while simultaneously providing custom output data. Note that
74    ///  baseclass performs some processing (such as tracking overall consumed
75    ///  data rate versus duration) for each finished frame, but other state
76    ///  is only updated upon each call to `GstBaseParseClass::handle_frame`
77    ///  (such as tracking upstream input timestamp).
78    ///
79    ///  Subclass is also responsible for setting the buffer metadata
80    ///  (e.g. buffer timestamp and duration, or keyframe if applicable).
81    ///  (although the latter can also be done by [`BaseParse`][crate::BaseParse] if it is
82    ///  appropriately configured, see below). Frame is provided with
83    ///  timestamp derived from upstream (as much as generally possible),
84    ///  duration obtained from configuration (see below), and offset
85    ///  if meaningful (in pull mode).
86    ///
87    ///  Note that `GstBaseParseClass::handle_frame` might receive any small
88    ///  amount of input data when leftover data is being drained (e.g. at
89    ///  EOS).
90    ///
91    ///  * As part of finish frame processing, just prior to actually pushing
92    ///  the buffer in question, it is passed to
93    ///  `GstBaseParseClass::pre_push_frame` which gives subclass yet one last
94    ///  chance to examine buffer metadata, or to send some custom (tag)
95    ///  events, or to perform custom (segment) filtering.
96    ///
97    ///  * During the parsing process `GstBaseParseClass` will handle both srcpad
98    ///  and sinkpad events. They will be passed to subclass if
99    ///  `GstBaseParseClass::sink_event` or `GstBaseParseClass::src_event`
100    ///  implementations have been provided.
101    ///
102    /// ## Shutdown phase
103    ///
104    /// * [`BaseParse`][crate::BaseParse] class calls `GstBaseParseClass::stop` to inform the
105    ///  subclass that data parsing will be stopped.
106    ///
107    /// Subclass is responsible for providing pad template caps for source and
108    /// sink pads. The pads need to be named "sink" and "src". It also needs to
109    /// set the fixed caps on srcpad, when the format is ensured (e.g. when
110    /// base class calls subclass' `GstBaseParseClass::set_sink_caps` function).
111    ///
112    /// This base class uses [`gst::Format::Default`][crate::gst::Format::Default] as a meaning of frames. So,
113    /// subclass conversion routine needs to know that conversion from
114    /// [`gst::Format::Time`][crate::gst::Format::Time] to [`gst::Format::Default`][crate::gst::Format::Default] must return the
115    /// frame number that can be found from the given byte position.
116    ///
117    /// [`BaseParse`][crate::BaseParse] uses subclasses conversion methods also for seeking (or
118    /// otherwise uses its own default one, see also below).
119    ///
120    /// Subclass `start` and `stop` functions will be called to inform the beginning
121    /// and end of data processing.
122    ///
123    /// Things that subclass need to take care of:
124    ///
125    /// * Provide pad templates
126    /// * Fixate the source pad caps when appropriate
127    /// * Inform base class how big data chunks should be retrieved. This is
128    ///  done with [`BaseParseExt::set_min_frame_size()`][crate::prelude::BaseParseExt::set_min_frame_size()] function.
129    /// * Examine data chunks passed to subclass with
130    ///  `GstBaseParseClass::handle_frame` and pass proper frame(s) to
131    ///  [`BaseParseExtManual::finish_frame()`][crate::prelude::BaseParseExtManual::finish_frame()], and setting src pad caps and timestamps
132    ///  on frame.
133    /// * Provide conversion functions
134    /// * Update the duration information with [`BaseParseExtManual::set_duration()`][crate::prelude::BaseParseExtManual::set_duration()]
135    /// * Optionally passthrough using [`BaseParseExt::set_passthrough()`][crate::prelude::BaseParseExt::set_passthrough()]
136    /// * Configure various baseparse parameters using
137    ///  [`BaseParseExt::set_average_bitrate()`][crate::prelude::BaseParseExt::set_average_bitrate()], [`BaseParseExt::set_syncable()`][crate::prelude::BaseParseExt::set_syncable()]
138    ///  and [`BaseParseExtManual::set_frame_rate()`][crate::prelude::BaseParseExtManual::set_frame_rate()].
139    ///
140    /// * In particular, if subclass is unable to determine a duration, but
141    ///  parsing (or specs) yields a frames per seconds rate, then this can be
142    ///  provided to [`BaseParse`][crate::BaseParse] to enable it to cater for buffer time
143    ///  metadata (which will be taken from upstream as much as
144    ///  possible). Internally keeping track of frame durations and respective
145    ///  sizes that have been pushed provides [`BaseParse`][crate::BaseParse] with an estimated
146    ///  bitrate. A default `GstBaseParseClass::convert` (used if not
147    ///  overridden) will then use these rates to perform obvious conversions.
148    ///  These rates are also used to update (estimated) duration at regular
149    ///  frame intervals.
150    ///
151    /// This is an Abstract Base Class, you cannot instantiate it.
152    ///
153    /// ## Properties
154    ///
155    ///
156    /// #### `disable-clip`
157    ///  Disable dropping buffers that are out of segment
158    ///
159    /// Readable | Writable
160    ///
161    ///
162    /// #### `disable-passthrough`
163    ///  If set to [`true`], baseparse will unconditionally force parsing of the
164    /// incoming data. This can be required in the rare cases where the incoming
165    /// side-data (caps, pts, dts, ...) is not trusted by the user and wants to
166    /// force validation and parsing of the incoming data.
167    /// If set to [`false`], decision of whether to parse the data or not is up to
168    /// the implementation (standard behaviour).
169    ///
170    /// Readable | Writable
171    /// <details><summary><h4>Object</h4></summary>
172    ///
173    ///
174    /// #### `name`
175    ///  Readable | Writable | Construct
176    ///
177    ///
178    /// #### `parent`
179    ///  The parent of the object. Please note, that when changing the 'parent'
180    /// property, we don't emit [`notify`][struct@crate::glib::Object#notify] and [`deep-notify`][struct@crate::gst::Object#deep-notify]
181    /// signals due to locking issues. In some cases one can use
182    /// `GstBin::element-added` or `GstBin::element-removed` signals on the parent to
183    /// achieve a similar effect.
184    ///
185    /// Readable | Writable
186    /// </details>
187    ///
188    /// # Implements
189    ///
190    /// [`BaseParseExt`][trait@crate::prelude::BaseParseExt], [`trait@gst::prelude::ElementExt`], [`trait@gst::prelude::ObjectExt`], [`trait@glib::ObjectExt`], [`BaseParseExtManual`][trait@crate::prelude::BaseParseExtManual]
191    #[doc(alias = "GstBaseParse")]
192    pub struct BaseParse(Object<ffi::GstBaseParse, ffi::GstBaseParseClass>) @extends gst::Element, gst::Object;
193
194    match fn {
195        type_ => || ffi::gst_base_parse_get_type(),
196    }
197}
198
199impl BaseParse {
200    pub const NONE: Option<&'static BaseParse> = None;
201}
202
203unsafe impl Send for BaseParse {}
204unsafe impl Sync for BaseParse {}
205
206/// Trait containing all [`struct@BaseParse`] methods.
207///
208/// # Implementors
209///
210/// [`BaseParse`][struct@crate::BaseParse]
211pub trait BaseParseExt: IsA<BaseParse> + 'static {
212    /// Adds an entry to the index associating `offset` to `ts`. It is recommended
213    /// to only add keyframe entries. `force` allows to bypass checks, such as
214    /// whether the stream is (upstream) seekable, another entry is already "close"
215    /// to the new entry, etc.
216    /// ## `offset`
217    /// offset of entry
218    /// ## `ts`
219    /// timestamp associated with offset
220    /// ## `key`
221    /// whether entry refers to keyframe
222    /// ## `force`
223    /// add entry disregarding sanity checks
224    ///
225    /// # Returns
226    ///
227    /// `gboolean` indicating whether entry was added
228    #[doc(alias = "gst_base_parse_add_index_entry")]
229    fn add_index_entry(&self, offset: u64, ts: gst::ClockTime, key: bool, force: bool) -> bool {
230        unsafe {
231            from_glib(ffi::gst_base_parse_add_index_entry(
232                self.as_ref().to_glib_none().0,
233                offset,
234                ts.into_glib(),
235                key.into_glib(),
236                force.into_glib(),
237            ))
238        }
239    }
240
241    /// Drains the adapter until it is empty. It decreases the min_frame_size to
242    /// match the current adapter size and calls chain method until the adapter
243    /// is emptied or chain returns with error.
244    #[doc(alias = "gst_base_parse_drain")]
245    fn drain(&self) {
246        unsafe {
247            ffi::gst_base_parse_drain(self.as_ref().to_glib_none().0);
248        }
249    }
250
251    /// Sets the parser subclass's tags and how they should be merged with any
252    /// upstream stream tags. This will override any tags previously-set
253    /// with [`merge_tags()`][Self::merge_tags()].
254    ///
255    /// Note that this is provided for convenience, and the subclass is
256    /// not required to use this and can still do tag handling on its own.
257    /// ## `tags`
258    /// a [`gst::TagList`][crate::gst::TagList] to merge, or NULL to unset
259    ///  previously-set tags
260    /// ## `mode`
261    /// the [`gst::TagMergeMode`][crate::gst::TagMergeMode] to use, usually [`gst::TagMergeMode::Replace`][crate::gst::TagMergeMode::Replace]
262    #[doc(alias = "gst_base_parse_merge_tags")]
263    fn merge_tags(&self, tags: Option<&gst::TagList>, mode: gst::TagMergeMode) {
264        unsafe {
265            ffi::gst_base_parse_merge_tags(
266                self.as_ref().to_glib_none().0,
267                tags.to_glib_none().0,
268                mode.into_glib(),
269            );
270        }
271    }
272
273    /// READY state changes. Subclasses
274    /// can call this function from their instance init function.
275    /// ## `allow_duplicated_pts`
276    /// [`true`] if parser should allow duplicated PTS on the output
277    #[cfg(feature = "v1_30")]
278    #[cfg_attr(docsrs, doc(cfg(feature = "v1_30")))]
279    #[doc(alias = "gst_base_parse_set_allow_duplicated_pts")]
280    fn set_allow_duplicated_pts(&self, allow_duplicated_pts: bool) {
281        unsafe {
282            ffi::gst_base_parse_set_allow_duplicated_pts(
283                self.as_ref().to_glib_none().0,
284                allow_duplicated_pts.into_glib(),
285            );
286        }
287    }
288
289    /// READY state changes. Subclasses must
290    /// call this function from `GstBaseParseClass::start` if they want to set a static value.
291    /// ## `bitrate`
292    /// average bitrate in bits/second
293    #[doc(alias = "gst_base_parse_set_average_bitrate")]
294    fn set_average_bitrate(&self, bitrate: u32) {
295        unsafe {
296            ffi::gst_base_parse_set_average_bitrate(self.as_ref().to_glib_none().0, bitrate);
297        }
298    }
299
300    /// READY state changes. Subclasses must
301    /// call this function from `GstBaseParseClass::start` if they want to set a static value.
302    /// ## `has_timing`
303    /// whether frames carry timing information
304    #[doc(alias = "gst_base_parse_set_has_timing_info")]
305    fn set_has_timing_info(&self, has_timing: bool) {
306        unsafe {
307            ffi::gst_base_parse_set_has_timing_info(
308                self.as_ref().to_glib_none().0,
309                has_timing.into_glib(),
310            );
311        }
312    }
313
314    /// READY state changes. Subclasses
315    /// can call this function from their instance init function.
316    /// ## `infer_ts`
317    /// [`true`] if parser should infer DTS/PTS from each other
318    #[doc(alias = "gst_base_parse_set_infer_ts")]
319    fn set_infer_ts(&self, infer_ts: bool) {
320        unsafe {
321            ffi::gst_base_parse_set_infer_ts(self.as_ref().to_glib_none().0, infer_ts.into_glib());
322        }
323    }
324
325    /// READY state changes. Subclasses
326    /// can call this function from their instance init function.
327    /// ## `min_latency`
328    /// minimum parse latency
329    /// ## `max_latency`
330    /// maximum parse latency
331    #[doc(alias = "gst_base_parse_set_latency")]
332    fn set_latency(
333        &self,
334        min_latency: gst::ClockTime,
335        max_latency: impl Into<Option<gst::ClockTime>>,
336    ) {
337        unsafe {
338            ffi::gst_base_parse_set_latency(
339                self.as_ref().to_glib_none().0,
340                min_latency.into_glib(),
341                max_latency.into().into_glib(),
342            );
343        }
344    }
345
346    /// READY state changes. Subclasses must
347    /// call this function from `GstBaseParseClass::start` if they want to set a static value.
348    /// ## `min_size`
349    /// Minimum size in bytes of the data that this base class should
350    ///  give to subclass.
351    #[doc(alias = "gst_base_parse_set_min_frame_size")]
352    fn set_min_frame_size(&self, min_size: u32) {
353        unsafe {
354            ffi::gst_base_parse_set_min_frame_size(self.as_ref().to_glib_none().0, min_size);
355        }
356    }
357
358    /// READY state changes. Subclasses must
359    /// call this function from `GstBaseParseClass::start` if they want to set a static value.
360    /// ## `passthrough`
361    /// [`true`] if parser should run in passthrough mode
362    #[doc(alias = "gst_base_parse_set_passthrough")]
363    fn set_passthrough(&self, passthrough: bool) {
364        unsafe {
365            ffi::gst_base_parse_set_passthrough(
366                self.as_ref().to_glib_none().0,
367                passthrough.into_glib(),
368            );
369        }
370    }
371
372    /// READY state changes. Subclasses
373    /// can call this function from their instance init function.
374    /// ## `pts_interpolate`
375    /// [`true`] if parser should interpolate PTS timestamps
376    #[doc(alias = "gst_base_parse_set_pts_interpolation")]
377    fn set_pts_interpolation(&self, pts_interpolate: bool) {
378        unsafe {
379            ffi::gst_base_parse_set_pts_interpolation(
380                self.as_ref().to_glib_none().0,
381                pts_interpolate.into_glib(),
382            );
383        }
384    }
385
386    /// READY state changes. Subclasses must
387    /// call this function from `GstBaseParseClass::start` if they want to set a static value.
388    /// ## `syncable`
389    /// set if frame starts can be identified
390    #[doc(alias = "gst_base_parse_set_syncable")]
391    fn set_syncable(&self, syncable: bool) {
392        unsafe {
393            ffi::gst_base_parse_set_syncable(self.as_ref().to_glib_none().0, syncable.into_glib());
394        }
395    }
396
397    /// This function should only be called from a `handle_frame` implementation.
398    ///
399    /// [`BaseParse`][crate::BaseParse] creates initial timestamps for frames by using the last
400    /// timestamp seen in the stream before the frame starts. In certain
401    /// cases, the correct timestamps will occur in the stream after the
402    /// start of the frame, but before the start of the actual picture data.
403    /// This function can be used to set the timestamps based on the offset
404    /// into the frame data that the picture starts.
405    /// ## `offset`
406    /// offset into current buffer
407    #[doc(alias = "gst_base_parse_set_ts_at_offset")]
408    fn set_ts_at_offset(&self, offset: usize) {
409        unsafe {
410            ffi::gst_base_parse_set_ts_at_offset(self.as_ref().to_glib_none().0, offset);
411        }
412    }
413
414    /// Disable dropping buffers that are out of segment
415    #[cfg(feature = "v1_28")]
416    #[cfg_attr(docsrs, doc(cfg(feature = "v1_28")))]
417    #[doc(alias = "disable-clip")]
418    fn is_disable_clip(&self) -> bool {
419        ObjectExt::property(self.as_ref(), "disable-clip")
420    }
421
422    /// Disable dropping buffers that are out of segment
423    #[cfg(feature = "v1_28")]
424    #[cfg_attr(docsrs, doc(cfg(feature = "v1_28")))]
425    #[doc(alias = "disable-clip")]
426    fn set_disable_clip(&self, disable_clip: bool) {
427        ObjectExt::set_property(self.as_ref(), "disable-clip", disable_clip)
428    }
429
430    /// If set to [`true`], baseparse will unconditionally force parsing of the
431    /// incoming data. This can be required in the rare cases where the incoming
432    /// side-data (caps, pts, dts, ...) is not trusted by the user and wants to
433    /// force validation and parsing of the incoming data.
434    /// If set to [`false`], decision of whether to parse the data or not is up to
435    /// the implementation (standard behaviour).
436    #[doc(alias = "disable-passthrough")]
437    fn is_disable_passthrough(&self) -> bool {
438        ObjectExt::property(self.as_ref(), "disable-passthrough")
439    }
440
441    /// If set to [`true`], baseparse will unconditionally force parsing of the
442    /// incoming data. This can be required in the rare cases where the incoming
443    /// side-data (caps, pts, dts, ...) is not trusted by the user and wants to
444    /// force validation and parsing of the incoming data.
445    /// If set to [`false`], decision of whether to parse the data or not is up to
446    /// the implementation (standard behaviour).
447    #[doc(alias = "disable-passthrough")]
448    fn set_disable_passthrough(&self, disable_passthrough: bool) {
449        ObjectExt::set_property(self.as_ref(), "disable-passthrough", disable_passthrough)
450    }
451
452    #[cfg(feature = "v1_28")]
453    #[cfg_attr(docsrs, doc(cfg(feature = "v1_28")))]
454    #[doc(alias = "disable-clip")]
455    fn connect_disable_clip_notify<F: Fn(&Self) + Send + Sync + 'static>(
456        &self,
457        f: F,
458    ) -> SignalHandlerId {
459        unsafe extern "C" fn notify_disable_clip_trampoline<
460            P: IsA<BaseParse>,
461            F: Fn(&P) + Send + Sync + 'static,
462        >(
463            this: *mut ffi::GstBaseParse,
464            _param_spec: glib::ffi::gpointer,
465            f: glib::ffi::gpointer,
466        ) {
467            unsafe {
468                let f: &F = &*(f as *const F);
469                f(BaseParse::from_glib_borrow(this).unsafe_cast_ref())
470            }
471        }
472        unsafe {
473            let f: Box_<F> = Box_::new(f);
474            connect_raw(
475                self.as_ptr() as *mut _,
476                c"notify::disable-clip".as_ptr(),
477                Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
478                    notify_disable_clip_trampoline::<Self, F> as *const (),
479                )),
480                Box_::into_raw(f),
481            )
482        }
483    }
484
485    #[doc(alias = "disable-passthrough")]
486    fn connect_disable_passthrough_notify<F: Fn(&Self) + Send + Sync + 'static>(
487        &self,
488        f: F,
489    ) -> SignalHandlerId {
490        unsafe extern "C" fn notify_disable_passthrough_trampoline<
491            P: IsA<BaseParse>,
492            F: Fn(&P) + Send + Sync + 'static,
493        >(
494            this: *mut ffi::GstBaseParse,
495            _param_spec: glib::ffi::gpointer,
496            f: glib::ffi::gpointer,
497        ) {
498            unsafe {
499                let f: &F = &*(f as *const F);
500                f(BaseParse::from_glib_borrow(this).unsafe_cast_ref())
501            }
502        }
503        unsafe {
504            let f: Box_<F> = Box_::new(f);
505            connect_raw(
506                self.as_ptr() as *mut _,
507                c"notify::disable-passthrough".as_ptr(),
508                Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
509                    notify_disable_passthrough_trampoline::<Self, F> as *const (),
510                )),
511                Box_::into_raw(f),
512            )
513        }
514    }
515}
516
517impl<O: IsA<BaseParse>> BaseParseExt for O {}