BaseParse
Superclasses: Element
, Object
, InitiallyUnowned
, Object
- Constructors:
BaseParse(**properties)
Methods
- class BaseParse
- add_index_entry(offset: int, ts: int, key: bool, force: bool) bool
Adds an entry to the index associating
offset
tots
. It is recommended to only add keyframe entries.force
allows to bypass checks, such as whether the stream is (upstream) seekable, another entry is already “close” to the new entry, etc.- Parameters:
offset – offset of entry
ts – timestamp associated with offset
key – whether entry refers to keyframe
force – add entry disregarding sanity checks
- convert_default(src_format: Format, src_value: int, dest_format: Format) tuple[bool, int]
Default implementation of
GstBaseParseClass
::convert.
- drain() None
Drains the adapter until it is empty. It decreases the min_frame_size to match the current adapter size and calls chain method until the adapter is emptied or chain returns with error.
Added in version 1.12.
- finish_frame(frame: BaseParseFrame, size: int) FlowReturn
Collects parsed data and pushes it downstream. Source pad caps must be set when this is called.
If
frame
’s out_buffer is set, that will be used as subsequent frame data, andsize
amount will be flushed from the input data. The output_buffer size can differ from the consumed size indicated bysize
.Otherwise,
size
samples will be taken from the input and used for output, and the output’s metadata (timestamps etc) will be taken as (optionally) set by the subclass onframe
’s (input) buffer (which is otherwise ignored for any but the above purpose/information).Note that the latter buffer is invalidated by this call, whereas the caller retains ownership of
frame
.- Parameters:
frame – a
BaseParseFrame
size – consumed input data represented by frame
- merge_tags(tags: TagList | None, mode: TagMergeMode) None
Sets the parser subclass’s tags and how they should be merged with any upstream stream tags. This will override any tags previously-set with
merge_tags()
.Note that this is provided for convenience, and the subclass is not required to use this and can still do tag handling on its own.
Added in version 1.6.
- Parameters:
tags – a
TagList
to merge, or NULL to unset previously-set tagsmode – the
TagMergeMode
to use, usuallyGST_TAG_MERGE_REPLACE
- push_frame(frame: BaseParseFrame) FlowReturn
Pushes the frame’s buffer downstream, sends any pending events and does some timestamp and segment handling. Takes ownership of frame’s buffer, though caller retains ownership of
frame
.This must be called with sinkpad STREAM_LOCK held.
- Parameters:
frame – a
BaseParseFrame
- set_average_bitrate(bitrate: int) None
Optionally sets the average bitrate detected in media (if non-zero), e.g. based on metadata, as it will be posted to the application.
By default, announced average bitrate is estimated. The average bitrate is used to estimate the total duration of the stream and to estimate a seek position, if there’s no index and the format is syncable (see
set_syncable()
).- Parameters:
bitrate – average bitrate in bits/second
- set_duration(fmt: Format, duration: int, interval: int) None
Sets the duration of the currently playing media. Subclass can use this when it is able to determine duration and/or notices a change in the media duration. Alternatively, if
interval
is non-zero (default), then stream duration is determined based on estimated bitrate, and updated everyinterval
frames.- Parameters:
fmt –
Format
.duration – duration value.
interval – how often to update the duration estimate based on bitrate, or 0.
- set_frame_rate(fps_num: int, fps_den: int, lead_in: int, lead_out: int) None
If frames per second is configured, parser can take care of buffer duration and timestamping. When performing segment clipping, or seeking to a specific location, a corresponding decoder might need an initial
lead_in
and a followinglead_out
number of frames to ensure the desired segment is entirely filled upon decoding.- Parameters:
fps_num – frames per second (numerator).
fps_den – frames per second (denominator).
lead_in – frames needed before a segment for subsequent decode
lead_out – frames needed after a segment
- set_has_timing_info(has_timing: bool) None
Set if frames carry timing information which the subclass can (generally) parse and provide. In particular, intrinsic (rather than estimated) time can be obtained following a seek.
- Parameters:
has_timing – whether frames carry timing information
- set_infer_ts(infer_ts: bool) None
By default, the base class might try to infer PTS from DTS and vice versa. While this is generally correct for audio data, it may not be otherwise. Sub-classes implementing such formats should disable timestamp inferring.
- Parameters:
infer_ts –
True
if parser should infer DTS/PTS from each other
- set_latency(min_latency: int, max_latency: int) None
Sets the minimum and maximum (which may likely be equal) latency introduced by the parsing process. If there is such a latency, which depends on the particular parsing of the format, it typically corresponds to 1 frame duration.
If the provided values changed from previously provided ones, this will also post a LATENCY message on the bus so the pipeline can reconfigure its global latency.
- Parameters:
min_latency – minimum parse latency
max_latency – maximum parse latency
- set_min_frame_size(min_size: int) None
Subclass can use this function to tell the base class that it needs to be given buffers of at least
min_size
bytes.- Parameters:
min_size – Minimum size in bytes of the data that this base class should give to subclass.
- set_passthrough(passthrough: bool) None
Set if the nature of the format or configuration does not allow (much) parsing, and the parser should operate in passthrough mode (which only applies when operating in push mode). That is, incoming buffers are pushed through unmodified, i.e. no
GstBaseParseClass
::handle_frame will be invoked, butGstBaseParseClass
::pre_push_frame will still be invoked, so subclass can perform as much or as little is appropriate for passthrough semantics inGstBaseParseClass
::pre_push_frame.- Parameters:
passthrough –
True
if parser should run in passthrough mode
- set_pts_interpolation(pts_interpolate: bool) None
By default, the base class will guess PTS timestamps using a simple interpolation (previous timestamp + duration), which is incorrect for data streams with reordering, where PTS can go backward. Sub-classes implementing such formats should disable PTS interpolation.
- Parameters:
pts_interpolate –
True
if parser should interpolate PTS timestamps
- set_syncable(syncable: bool) None
Set if frame starts can be identified. This is set by default and determines whether seeking based on bitrate averages is possible for a format/stream.
- Parameters:
syncable – set if frame starts can be identified
- set_ts_at_offset(offset: int) None
This function should only be called from a
handle_frame
implementation.BaseParse
creates initial timestamps for frames by using the last timestamp seen in the stream before the frame starts. In certain cases, the correct timestamps will occur in the stream after the start of the frame, but before the start of the actual picture data. This function can be used to set the timestamps based on the offset into the frame data that the picture starts.Added in version 1.2.
- Parameters:
offset – offset into current buffer
Properties
- class BaseParse
- props.disable_passthrough: bool
If set to
True
, baseparse will unconditionally force parsing of the incoming data. This can be required in the rare cases where the incoming side-data (caps, pts, dts, …) is not trusted by the user and wants to force validation and parsing of the incoming data. If set toFalse
, decision of whether to parse the data or not is up to the implementation (standard behaviour).
Virtual Methods
- class BaseParse
- do_convert(src_format: Format, src_value: int, dest_format: Format, dest_value: int) bool
Optional. Convert between formats.
- Parameters:
src_format
src_value
dest_format
dest_value
- do_detect(buffer: Buffer) FlowReturn
Optional. Called until it doesn’t return GST_FLOW_OK anymore for the first buffers. Can be used by the subclass to detect the stream format.
- Parameters:
buffer
- do_get_sink_caps(filter: Caps) Caps
Optional. Allows the subclass to do its own sink get caps if needed.
- Parameters:
filter
- do_handle_frame(frame: BaseParseFrame) tuple[FlowReturn, int]
Parses the input data into valid frames as defined by subclass which should be passed to
finish_frame()
. The frame’s input buffer is guaranteed writable, whereas the input frame ownership is held by caller (so subclass should make a copy if it needs to hang on). Input buffer (data) is provided by baseclass with as much metadata set as possible by baseclass according to upstream information and/or subclass settings, though subclass may still set buffer timestamp and duration if desired.- Parameters:
frame
- do_pre_push_frame(frame: BaseParseFrame) FlowReturn
Optional. Called just prior to pushing a frame (after any pending events have been sent) to give subclass a chance to perform additional actions at this time (e.g. tag sending) or to decide whether this buffer should be dropped or not (e.g. custom segment clipping).
- Parameters:
frame
- do_set_sink_caps(caps: Caps) bool
Optional. Allows the subclass to be notified of the actual caps set.
- Parameters:
caps
- do_sink_event(event: Event) bool
Optional. Event handler on the sink pad. This function should chain up to the parent implementation to let the default handler run.
- Parameters:
event
- do_sink_query(query: Query) bool
Optional. Query handler on the sink pad. This function should chain up to the parent implementation to let the default handler run (Since: 1.2)
- Parameters:
query
- do_src_event(event: Event) bool
Optional. Event handler on the source pad. Should chain up to the parent to let the default handler run.
- Parameters:
event
- do_src_query(query: Query) bool
Optional. Query handler on the source pad. Should chain up to the parent to let the default handler run (Since: 1.2)
- Parameters:
query