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