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::{connect_raw, SignalHandlerId},
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 | Writeable
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 | Writeable
171 /// <details><summary><h4>Object</h4></summary>
172 ///
173 ///
174 /// #### `name`
175 /// Readable | Writeable | 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 | Writeable
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 /// Optionally sets the average bitrate detected in media (if non-zero),
274 /// e.g. based on metadata, as it will be posted to the application.
275 ///
276 /// By default, announced average bitrate is estimated. The average bitrate
277 /// is used to estimate the total duration of the stream and to estimate
278 /// a seek position, if there's no index and the format is syncable
279 /// (see [`set_syncable()`][Self::set_syncable()]).
280 /// ## `bitrate`
281 /// average bitrate in bits/second
282 #[doc(alias = "gst_base_parse_set_average_bitrate")]
283 fn set_average_bitrate(&self, bitrate: u32) {
284 unsafe {
285 ffi::gst_base_parse_set_average_bitrate(self.as_ref().to_glib_none().0, bitrate);
286 }
287 }
288
289 /// Set if frames carry timing information which the subclass can (generally)
290 /// parse and provide. In particular, intrinsic (rather than estimated) time
291 /// can be obtained following a seek.
292 /// ## `has_timing`
293 /// whether frames carry timing information
294 #[doc(alias = "gst_base_parse_set_has_timing_info")]
295 fn set_has_timing_info(&self, has_timing: bool) {
296 unsafe {
297 ffi::gst_base_parse_set_has_timing_info(
298 self.as_ref().to_glib_none().0,
299 has_timing.into_glib(),
300 );
301 }
302 }
303
304 /// By default, the base class might try to infer PTS from DTS and vice
305 /// versa. While this is generally correct for audio data, it may not
306 /// be otherwise. Sub-classes implementing such formats should disable
307 /// timestamp inferring.
308 /// ## `infer_ts`
309 /// [`true`] if parser should infer DTS/PTS from each other
310 #[doc(alias = "gst_base_parse_set_infer_ts")]
311 fn set_infer_ts(&self, infer_ts: bool) {
312 unsafe {
313 ffi::gst_base_parse_set_infer_ts(self.as_ref().to_glib_none().0, infer_ts.into_glib());
314 }
315 }
316
317 /// Sets the minimum and maximum (which may likely be equal) latency introduced
318 /// by the parsing process. If there is such a latency, which depends on the
319 /// particular parsing of the format, it typically corresponds to 1 frame duration.
320 ///
321 /// If the provided values changed from previously provided ones, this will
322 /// also post a LATENCY message on the bus so the pipeline can reconfigure its
323 /// global latency.
324 /// ## `min_latency`
325 /// minimum parse latency
326 /// ## `max_latency`
327 /// maximum parse latency
328 #[doc(alias = "gst_base_parse_set_latency")]
329 fn set_latency(
330 &self,
331 min_latency: gst::ClockTime,
332 max_latency: impl Into<Option<gst::ClockTime>>,
333 ) {
334 unsafe {
335 ffi::gst_base_parse_set_latency(
336 self.as_ref().to_glib_none().0,
337 min_latency.into_glib(),
338 max_latency.into().into_glib(),
339 );
340 }
341 }
342
343 /// Subclass can use this function to tell the base class that it needs to
344 /// be given buffers of at least `min_size` bytes.
345 /// ## `min_size`
346 /// Minimum size in bytes of the data that this base class should
347 /// give to subclass.
348 #[doc(alias = "gst_base_parse_set_min_frame_size")]
349 fn set_min_frame_size(&self, min_size: u32) {
350 unsafe {
351 ffi::gst_base_parse_set_min_frame_size(self.as_ref().to_glib_none().0, min_size);
352 }
353 }
354
355 /// Set if the nature of the format or configuration does not allow (much)
356 /// parsing, and the parser should operate in passthrough mode (which only
357 /// applies when operating in push mode). That is, incoming buffers are
358 /// pushed through unmodified, i.e. no `GstBaseParseClass::handle_frame`
359 /// will be invoked, but `GstBaseParseClass::pre_push_frame` will still be
360 /// invoked, so subclass can perform as much or as little is appropriate for
361 /// passthrough semantics in `GstBaseParseClass::pre_push_frame`.
362 /// ## `passthrough`
363 /// [`true`] if parser should run in passthrough mode
364 #[doc(alias = "gst_base_parse_set_passthrough")]
365 fn set_passthrough(&self, passthrough: bool) {
366 unsafe {
367 ffi::gst_base_parse_set_passthrough(
368 self.as_ref().to_glib_none().0,
369 passthrough.into_glib(),
370 );
371 }
372 }
373
374 /// By default, the base class will guess PTS timestamps using a simple
375 /// interpolation (previous timestamp + duration), which is incorrect for
376 /// data streams with reordering, where PTS can go backward. Sub-classes
377 /// implementing such formats should disable PTS interpolation.
378 /// ## `pts_interpolate`
379 /// [`true`] if parser should interpolate PTS timestamps
380 #[doc(alias = "gst_base_parse_set_pts_interpolation")]
381 fn set_pts_interpolation(&self, pts_interpolate: bool) {
382 unsafe {
383 ffi::gst_base_parse_set_pts_interpolation(
384 self.as_ref().to_glib_none().0,
385 pts_interpolate.into_glib(),
386 );
387 }
388 }
389
390 /// Set if frame starts can be identified. This is set by default and
391 /// determines whether seeking based on bitrate averages
392 /// is possible for a format/stream.
393 /// ## `syncable`
394 /// set if frame starts can be identified
395 #[doc(alias = "gst_base_parse_set_syncable")]
396 fn set_syncable(&self, syncable: bool) {
397 unsafe {
398 ffi::gst_base_parse_set_syncable(self.as_ref().to_glib_none().0, syncable.into_glib());
399 }
400 }
401
402 /// This function should only be called from a `handle_frame` implementation.
403 ///
404 /// [`BaseParse`][crate::BaseParse] creates initial timestamps for frames by using the last
405 /// timestamp seen in the stream before the frame starts. In certain
406 /// cases, the correct timestamps will occur in the stream after the
407 /// start of the frame, but before the start of the actual picture data.
408 /// This function can be used to set the timestamps based on the offset
409 /// into the frame data that the picture starts.
410 /// ## `offset`
411 /// offset into current buffer
412 #[doc(alias = "gst_base_parse_set_ts_at_offset")]
413 fn set_ts_at_offset(&self, offset: usize) {
414 unsafe {
415 ffi::gst_base_parse_set_ts_at_offset(self.as_ref().to_glib_none().0, offset);
416 }
417 }
418
419 /// Disable dropping buffers that are out of segment
420 #[cfg(feature = "v1_28")]
421 #[cfg_attr(docsrs, doc(cfg(feature = "v1_28")))]
422 #[doc(alias = "disable-clip")]
423 fn is_disable_clip(&self) -> bool {
424 ObjectExt::property(self.as_ref(), "disable-clip")
425 }
426
427 /// Disable dropping buffers that are out of segment
428 #[cfg(feature = "v1_28")]
429 #[cfg_attr(docsrs, doc(cfg(feature = "v1_28")))]
430 #[doc(alias = "disable-clip")]
431 fn set_disable_clip(&self, disable_clip: bool) {
432 ObjectExt::set_property(self.as_ref(), "disable-clip", disable_clip)
433 }
434
435 /// If set to [`true`], baseparse will unconditionally force parsing of the
436 /// incoming data. This can be required in the rare cases where the incoming
437 /// side-data (caps, pts, dts, ...) is not trusted by the user and wants to
438 /// force validation and parsing of the incoming data.
439 /// If set to [`false`], decision of whether to parse the data or not is up to
440 /// the implementation (standard behaviour).
441 #[doc(alias = "disable-passthrough")]
442 fn is_disable_passthrough(&self) -> bool {
443 ObjectExt::property(self.as_ref(), "disable-passthrough")
444 }
445
446 /// If set to [`true`], baseparse will unconditionally force parsing of the
447 /// incoming data. This can be required in the rare cases where the incoming
448 /// side-data (caps, pts, dts, ...) is not trusted by the user and wants to
449 /// force validation and parsing of the incoming data.
450 /// If set to [`false`], decision of whether to parse the data or not is up to
451 /// the implementation (standard behaviour).
452 #[doc(alias = "disable-passthrough")]
453 fn set_disable_passthrough(&self, disable_passthrough: bool) {
454 ObjectExt::set_property(self.as_ref(), "disable-passthrough", disable_passthrough)
455 }
456
457 #[cfg(feature = "v1_28")]
458 #[cfg_attr(docsrs, doc(cfg(feature = "v1_28")))]
459 #[doc(alias = "disable-clip")]
460 fn connect_disable_clip_notify<F: Fn(&Self) + Send + Sync + 'static>(
461 &self,
462 f: F,
463 ) -> SignalHandlerId {
464 unsafe extern "C" fn notify_disable_clip_trampoline<
465 P: IsA<BaseParse>,
466 F: Fn(&P) + Send + Sync + 'static,
467 >(
468 this: *mut ffi::GstBaseParse,
469 _param_spec: glib::ffi::gpointer,
470 f: glib::ffi::gpointer,
471 ) {
472 let f: &F = &*(f as *const F);
473 f(BaseParse::from_glib_borrow(this).unsafe_cast_ref())
474 }
475 unsafe {
476 let f: Box_<F> = Box_::new(f);
477 connect_raw(
478 self.as_ptr() as *mut _,
479 c"notify::disable-clip".as_ptr() as *const _,
480 Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
481 notify_disable_clip_trampoline::<Self, F> as *const (),
482 )),
483 Box_::into_raw(f),
484 )
485 }
486 }
487
488 #[doc(alias = "disable-passthrough")]
489 fn connect_disable_passthrough_notify<F: Fn(&Self) + Send + Sync + 'static>(
490 &self,
491 f: F,
492 ) -> SignalHandlerId {
493 unsafe extern "C" fn notify_disable_passthrough_trampoline<
494 P: IsA<BaseParse>,
495 F: Fn(&P) + Send + Sync + 'static,
496 >(
497 this: *mut ffi::GstBaseParse,
498 _param_spec: glib::ffi::gpointer,
499 f: glib::ffi::gpointer,
500 ) {
501 let f: &F = &*(f as *const F);
502 f(BaseParse::from_glib_borrow(this).unsafe_cast_ref())
503 }
504 unsafe {
505 let f: Box_<F> = Box_::new(f);
506 connect_raw(
507 self.as_ptr() as *mut _,
508 c"notify::disable-passthrough".as_ptr() as *const _,
509 Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
510 notify_disable_passthrough_trampoline::<Self, F> as *const (),
511 )),
512 Box_::into_raw(f),
513 )
514 }
515 }
516}
517
518impl<O: IsA<BaseParse>> BaseParseExt for O {}