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-passthrough`
157 /// If set to [`true`], baseparse will unconditionally force parsing of the
158 /// incoming data. This can be required in the rare cases where the incoming
159 /// side-data (caps, pts, dts, ...) is not trusted by the user and wants to
160 /// force validation and parsing of the incoming data.
161 /// If set to [`false`], decision of whether to parse the data or not is up to
162 /// the implementation (standard behaviour).
163 ///
164 /// Readable | Writeable
165 /// <details><summary><h4>Object</h4></summary>
166 ///
167 ///
168 /// #### `name`
169 /// Readable | Writeable | Construct
170 ///
171 ///
172 /// #### `parent`
173 /// The parent of the object. Please note, that when changing the 'parent'
174 /// property, we don't emit [`notify`][struct@crate::glib::Object#notify] and [`deep-notify`][struct@crate::gst::Object#deep-notify]
175 /// signals due to locking issues. In some cases one can use
176 /// `GstBin::element-added` or `GstBin::element-removed` signals on the parent to
177 /// achieve a similar effect.
178 ///
179 /// Readable | Writeable
180 /// </details>
181 ///
182 /// # Implements
183 ///
184 /// [`BaseParseExt`][trait@crate::prelude::BaseParseExt], [`trait@gst::prelude::ElementExt`], [`trait@gst::prelude::ObjectExt`], [`trait@glib::ObjectExt`], [`BaseParseExtManual`][trait@crate::prelude::BaseParseExtManual]
185 #[doc(alias = "GstBaseParse")]
186 pub struct BaseParse(Object<ffi::GstBaseParse, ffi::GstBaseParseClass>) @extends gst::Element, gst::Object;
187
188 match fn {
189 type_ => || ffi::gst_base_parse_get_type(),
190 }
191}
192
193impl BaseParse {
194 pub const NONE: Option<&'static BaseParse> = None;
195}
196
197unsafe impl Send for BaseParse {}
198unsafe impl Sync for BaseParse {}
199
200mod sealed {
201 pub trait Sealed {}
202 impl<T: super::IsA<super::BaseParse>> Sealed for T {}
203}
204
205/// Trait containing all [`struct@BaseParse`] methods.
206///
207/// # Implementors
208///
209/// [`BaseParse`][struct@crate::BaseParse]
210pub trait BaseParseExt: IsA<BaseParse> + sealed::Sealed + 'static {
211 /// Adds an entry to the index associating `offset` to `ts`. It is recommended
212 /// to only add keyframe entries. `force` allows to bypass checks, such as
213 /// whether the stream is (upstream) seekable, another entry is already "close"
214 /// to the new entry, etc.
215 /// ## `offset`
216 /// offset of entry
217 /// ## `ts`
218 /// timestamp associated with offset
219 /// ## `key`
220 /// whether entry refers to keyframe
221 /// ## `force`
222 /// add entry disregarding sanity checks
223 ///
224 /// # Returns
225 ///
226 /// `gboolean` indicating whether entry was added
227 #[doc(alias = "gst_base_parse_add_index_entry")]
228 fn add_index_entry(&self, offset: u64, ts: gst::ClockTime, key: bool, force: bool) -> bool {
229 unsafe {
230 from_glib(ffi::gst_base_parse_add_index_entry(
231 self.as_ref().to_glib_none().0,
232 offset,
233 ts.into_glib(),
234 key.into_glib(),
235 force.into_glib(),
236 ))
237 }
238 }
239
240 /// Drains the adapter until it is empty. It decreases the min_frame_size to
241 /// match the current adapter size and calls chain method until the adapter
242 /// is emptied or chain returns with error.
243 #[doc(alias = "gst_base_parse_drain")]
244 fn drain(&self) {
245 unsafe {
246 ffi::gst_base_parse_drain(self.as_ref().to_glib_none().0);
247 }
248 }
249
250 /// Sets the parser subclass's tags and how they should be merged with any
251 /// upstream stream tags. This will override any tags previously-set
252 /// with [`merge_tags()`][Self::merge_tags()].
253 ///
254 /// Note that this is provided for convenience, and the subclass is
255 /// not required to use this and can still do tag handling on its own.
256 /// ## `tags`
257 /// a [`gst::TagList`][crate::gst::TagList] to merge, or NULL to unset
258 /// previously-set tags
259 /// ## `mode`
260 /// the [`gst::TagMergeMode`][crate::gst::TagMergeMode] to use, usually [`gst::TagMergeMode::Replace`][crate::gst::TagMergeMode::Replace]
261 #[doc(alias = "gst_base_parse_merge_tags")]
262 fn merge_tags(&self, tags: Option<&gst::TagList>, mode: gst::TagMergeMode) {
263 unsafe {
264 ffi::gst_base_parse_merge_tags(
265 self.as_ref().to_glib_none().0,
266 tags.to_glib_none().0,
267 mode.into_glib(),
268 );
269 }
270 }
271
272 /// Optionally sets the average bitrate detected in media (if non-zero),
273 /// e.g. based on metadata, as it will be posted to the application.
274 ///
275 /// By default, announced average bitrate is estimated. The average bitrate
276 /// is used to estimate the total duration of the stream and to estimate
277 /// a seek position, if there's no index and the format is syncable
278 /// (see [`set_syncable()`][Self::set_syncable()]).
279 /// ## `bitrate`
280 /// average bitrate in bits/second
281 #[doc(alias = "gst_base_parse_set_average_bitrate")]
282 fn set_average_bitrate(&self, bitrate: u32) {
283 unsafe {
284 ffi::gst_base_parse_set_average_bitrate(self.as_ref().to_glib_none().0, bitrate);
285 }
286 }
287
288 /// Set if frames carry timing information which the subclass can (generally)
289 /// parse and provide. In particular, intrinsic (rather than estimated) time
290 /// can be obtained following a seek.
291 /// ## `has_timing`
292 /// whether frames carry timing information
293 #[doc(alias = "gst_base_parse_set_has_timing_info")]
294 fn set_has_timing_info(&self, has_timing: bool) {
295 unsafe {
296 ffi::gst_base_parse_set_has_timing_info(
297 self.as_ref().to_glib_none().0,
298 has_timing.into_glib(),
299 );
300 }
301 }
302
303 /// By default, the base class might try to infer PTS from DTS and vice
304 /// versa. While this is generally correct for audio data, it may not
305 /// be otherwise. Sub-classes implementing such formats should disable
306 /// timestamp inferring.
307 /// ## `infer_ts`
308 /// [`true`] if parser should infer DTS/PTS from each other
309 #[doc(alias = "gst_base_parse_set_infer_ts")]
310 fn set_infer_ts(&self, infer_ts: bool) {
311 unsafe {
312 ffi::gst_base_parse_set_infer_ts(self.as_ref().to_glib_none().0, infer_ts.into_glib());
313 }
314 }
315
316 /// Sets the minimum and maximum (which may likely be equal) latency introduced
317 /// by the parsing process. If there is such a latency, which depends on the
318 /// particular parsing of the format, it typically corresponds to 1 frame duration.
319 ///
320 /// If the provided values changed from previously provided ones, this will
321 /// also post a LATENCY message on the bus so the pipeline can reconfigure its
322 /// global latency.
323 /// ## `min_latency`
324 /// minimum parse latency
325 /// ## `max_latency`
326 /// maximum parse latency
327 #[doc(alias = "gst_base_parse_set_latency")]
328 fn set_latency(
329 &self,
330 min_latency: gst::ClockTime,
331 max_latency: impl Into<Option<gst::ClockTime>>,
332 ) {
333 unsafe {
334 ffi::gst_base_parse_set_latency(
335 self.as_ref().to_glib_none().0,
336 min_latency.into_glib(),
337 max_latency.into().into_glib(),
338 );
339 }
340 }
341
342 /// Subclass can use this function to tell the base class that it needs to
343 /// be given buffers of at least `min_size` bytes.
344 /// ## `min_size`
345 /// Minimum size in bytes of the data that this base class should
346 /// give to subclass.
347 #[doc(alias = "gst_base_parse_set_min_frame_size")]
348 fn set_min_frame_size(&self, min_size: u32) {
349 unsafe {
350 ffi::gst_base_parse_set_min_frame_size(self.as_ref().to_glib_none().0, min_size);
351 }
352 }
353
354 /// Set if the nature of the format or configuration does not allow (much)
355 /// parsing, and the parser should operate in passthrough mode (which only
356 /// applies when operating in push mode). That is, incoming buffers are
357 /// pushed through unmodified, i.e. no `GstBaseParseClass::handle_frame`
358 /// will be invoked, but `GstBaseParseClass::pre_push_frame` will still be
359 /// invoked, so subclass can perform as much or as little is appropriate for
360 /// passthrough semantics in `GstBaseParseClass::pre_push_frame`.
361 /// ## `passthrough`
362 /// [`true`] if parser should run in passthrough mode
363 #[doc(alias = "gst_base_parse_set_passthrough")]
364 fn set_passthrough(&self, passthrough: bool) {
365 unsafe {
366 ffi::gst_base_parse_set_passthrough(
367 self.as_ref().to_glib_none().0,
368 passthrough.into_glib(),
369 );
370 }
371 }
372
373 /// By default, the base class will guess PTS timestamps using a simple
374 /// interpolation (previous timestamp + duration), which is incorrect for
375 /// data streams with reordering, where PTS can go backward. Sub-classes
376 /// implementing such formats should disable PTS interpolation.
377 /// ## `pts_interpolate`
378 /// [`true`] if parser should interpolate PTS timestamps
379 #[doc(alias = "gst_base_parse_set_pts_interpolation")]
380 fn set_pts_interpolation(&self, pts_interpolate: bool) {
381 unsafe {
382 ffi::gst_base_parse_set_pts_interpolation(
383 self.as_ref().to_glib_none().0,
384 pts_interpolate.into_glib(),
385 );
386 }
387 }
388
389 /// Set if frame starts can be identified. This is set by default and
390 /// determines whether seeking based on bitrate averages
391 /// is possible for a format/stream.
392 /// ## `syncable`
393 /// set if frame starts can be identified
394 #[doc(alias = "gst_base_parse_set_syncable")]
395 fn set_syncable(&self, syncable: bool) {
396 unsafe {
397 ffi::gst_base_parse_set_syncable(self.as_ref().to_glib_none().0, syncable.into_glib());
398 }
399 }
400
401 /// This function should only be called from a `handle_frame` implementation.
402 ///
403 /// [`BaseParse`][crate::BaseParse] creates initial timestamps for frames by using the last
404 /// timestamp seen in the stream before the frame starts. In certain
405 /// cases, the correct timestamps will occur in the stream after the
406 /// start of the frame, but before the start of the actual picture data.
407 /// This function can be used to set the timestamps based on the offset
408 /// into the frame data that the picture starts.
409 /// ## `offset`
410 /// offset into current buffer
411 #[doc(alias = "gst_base_parse_set_ts_at_offset")]
412 fn set_ts_at_offset(&self, offset: usize) {
413 unsafe {
414 ffi::gst_base_parse_set_ts_at_offset(self.as_ref().to_glib_none().0, offset);
415 }
416 }
417
418 /// If set to [`true`], baseparse will unconditionally force parsing of the
419 /// incoming data. This can be required in the rare cases where the incoming
420 /// side-data (caps, pts, dts, ...) is not trusted by the user and wants to
421 /// force validation and parsing of the incoming data.
422 /// If set to [`false`], decision of whether to parse the data or not is up to
423 /// the implementation (standard behaviour).
424 #[doc(alias = "disable-passthrough")]
425 fn is_disable_passthrough(&self) -> bool {
426 ObjectExt::property(self.as_ref(), "disable-passthrough")
427 }
428
429 /// If set to [`true`], baseparse will unconditionally force parsing of the
430 /// incoming data. This can be required in the rare cases where the incoming
431 /// side-data (caps, pts, dts, ...) is not trusted by the user and wants to
432 /// force validation and parsing of the incoming data.
433 /// If set to [`false`], decision of whether to parse the data or not is up to
434 /// the implementation (standard behaviour).
435 #[doc(alias = "disable-passthrough")]
436 fn set_disable_passthrough(&self, disable_passthrough: bool) {
437 ObjectExt::set_property(self.as_ref(), "disable-passthrough", disable_passthrough)
438 }
439
440 #[doc(alias = "disable-passthrough")]
441 fn connect_disable_passthrough_notify<F: Fn(&Self) + Send + Sync + 'static>(
442 &self,
443 f: F,
444 ) -> SignalHandlerId {
445 unsafe extern "C" fn notify_disable_passthrough_trampoline<
446 P: IsA<BaseParse>,
447 F: Fn(&P) + Send + Sync + 'static,
448 >(
449 this: *mut ffi::GstBaseParse,
450 _param_spec: glib::ffi::gpointer,
451 f: glib::ffi::gpointer,
452 ) {
453 let f: &F = &*(f as *const F);
454 f(BaseParse::from_glib_borrow(this).unsafe_cast_ref())
455 }
456 unsafe {
457 let f: Box_<F> = Box_::new(f);
458 connect_raw(
459 self.as_ptr() as *mut _,
460 b"notify::disable-passthrough\0".as_ptr() as *const _,
461 Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
462 notify_disable_passthrough_trampoline::<Self, F> as *const (),
463 )),
464 Box_::into_raw(f),
465 )
466 }
467 }
468}
469
470impl<O: IsA<BaseParse>> BaseParseExt for O {}