:right-sidebar: True BaseParse =================================================================== .. currentmodule:: gi.repository.GstBase .. class:: BaseParse(**properties: ~typing.Any) :no-contents-entry: Superclasses: :class:`~gi.repository.Gst.Element`, :class:`~gi.repository.Gst.Object`, :class:`~gi.repository.GObject.InitiallyUnowned`, :class:`~gi.repository.GObject.Object` :Constructors: :: BaseParse(**properties) Methods ------- .. rst-class:: interim-class .. class:: BaseParse :no-index: .. method:: add_index_entry(offset: int, ts: int, key: bool, force: bool) -> bool Adds an entry to the index associating ``offset`` to ``ts``. 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. :param offset: offset of entry :param ts: timestamp associated with offset :param key: whether entry refers to keyframe :param force: add entry disregarding sanity checks .. method:: convert_default(src_format: ~gi.repository.Gst.Format, src_value: int, dest_format: ~gi.repository.Gst.Format) -> tuple[bool, int] Default implementation of ``GstBaseParseClass``::convert. :param src_format: :obj:`~gi.repository.Gst.Format` describing the source format. :param src_value: Source value to be converted. :param dest_format: :obj:`~gi.repository.Gst.Format` defining the converted format. .. method:: 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. .. versionadded:: 1.12 .. method:: finish_frame(frame: ~gi.repository.GstBase.BaseParseFrame, size: int) -> ~gi.repository.Gst.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, and ``size`` amount will be flushed from the input data. The output_buffer size can differ from the consumed size indicated by ``size``. 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 on ``frame``'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``. :param frame: a :obj:`~gi.repository.GstBase.BaseParseFrame` :param size: consumed input data represented by frame .. method:: merge_tags(tags: ~gi.repository.Gst.TagList | None, mode: ~gi.repository.Gst.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 :func:`~gi.repository.GstBase.BaseParse.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. .. versionadded:: 1.6 :param tags: a :obj:`~gi.repository.Gst.TagList` to merge, or NULL to unset previously-set tags :param mode: the :obj:`~gi.repository.Gst.TagMergeMode` to use, usually ``GST_TAG_MERGE_REPLACE`` .. method:: push_frame(frame: ~gi.repository.GstBase.BaseParseFrame) -> ~gi.repository.Gst.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. :param frame: a :obj:`~gi.repository.GstBase.BaseParseFrame` .. method:: 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 :func:`~gi.repository.GstBase.BaseParse.set_syncable`). :param bitrate: average bitrate in bits/second .. method:: set_duration(fmt: ~gi.repository.Gst.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 every ``interval`` frames. :param fmt: :obj:`~gi.repository.Gst.Format`. :param duration: duration value. :param interval: how often to update the duration estimate based on bitrate, or 0. .. method:: 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 following ``lead_out`` number of frames to ensure the desired segment is entirely filled upon decoding. :param fps_num: frames per second (numerator). :param fps_den: frames per second (denominator). :param lead_in: frames needed before a segment for subsequent decode :param lead_out: frames needed after a segment .. method:: 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. :param has_timing: whether frames carry timing information .. method:: 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. :param infer_ts: :const:`True` if parser should infer DTS/PTS from each other .. method:: 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. :param min_latency: minimum parse latency :param max_latency: maximum parse latency .. method:: 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. :param min_size: Minimum size in bytes of the data that this base class should give to subclass. .. method:: 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, but ``GstBaseParseClass``::pre_push_frame will still be invoked, so subclass can perform as much or as little is appropriate for passthrough semantics in ``GstBaseParseClass``::pre_push_frame. :param passthrough: :const:`True` if parser should run in passthrough mode .. method:: 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. :param pts_interpolate: :const:`True` if parser should interpolate PTS timestamps .. method:: 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. :param syncable: set if frame starts can be identified .. method:: set_ts_at_offset(offset: int) -> None This function should only be called from a ``handle_frame`` implementation. :obj:`~gi.repository.GstBase.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. .. versionadded:: 1.2 :param offset: offset into current buffer Properties ---------- .. rst-class:: interim-class .. class:: BaseParse :no-index: .. attribute:: props.disable_passthrough :type: bool If set to :const:`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 to :const:`False`, decision of whether to parse the data or not is up to the implementation (standard behaviour). Virtual Methods --------------- .. rst-class:: interim-class .. class:: BaseParse :no-index: .. method:: do_convert(src_format: ~gi.repository.Gst.Format, src_value: int, dest_format: ~gi.repository.Gst.Format, dest_value: int) -> bool Optional. Convert between formats. :param src_format: :param src_value: :param dest_format: :param dest_value: .. method:: do_detect(buffer: ~gi.repository.Gst.Buffer) -> ~gi.repository.Gst.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. :param buffer: .. method:: do_get_sink_caps(filter: ~gi.repository.Gst.Caps) -> ~gi.repository.Gst.Caps Optional. Allows the subclass to do its own sink get caps if needed. :param filter: .. method:: do_handle_frame(frame: ~gi.repository.GstBase.BaseParseFrame) -> tuple[~gi.repository.Gst.FlowReturn, int] Parses the input data into valid frames as defined by subclass which should be passed to :func:`~gi.repository.GstBase.BaseParse.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. :param frame: .. method:: do_pre_push_frame(frame: ~gi.repository.GstBase.BaseParseFrame) -> ~gi.repository.Gst.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). :param frame: .. method:: do_set_sink_caps(caps: ~gi.repository.Gst.Caps) -> bool Optional. Allows the subclass to be notified of the actual caps set. :param caps: .. method:: do_sink_event(event: ~gi.repository.Gst.Event) -> bool Optional. Event handler on the sink pad. This function should chain up to the parent implementation to let the default handler run. :param event: .. method:: do_sink_query(query: ~gi.repository.Gst.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) :param query: .. method:: do_src_event(event: ~gi.repository.Gst.Event) -> bool Optional. Event handler on the source pad. Should chain up to the parent to let the default handler run. :param event: .. method:: do_src_query(query: ~gi.repository.Gst.Query) -> bool Optional. Query handler on the source pad. Should chain up to the parent to let the default handler run (Since: 1.2) :param query: .. method:: do_start() -> bool Optional. Called when the element starts processing. Allows opening external resources. .. method:: do_stop() -> bool Optional. Called when the element stops processing. Allows closing external resources. Fields ------ .. rst-class:: interim-class .. class:: BaseParse :no-index: .. attribute:: element The parent element. .. attribute:: flags .. attribute:: priv .. attribute:: segment .. attribute:: sinkpad .. attribute:: srcpad