Copyright | Will Thompson, Iñaki García Etxebarria and Jonas Platte |
---|---|
License | LGPL-2.1 |
Maintainer | Iñaki García Etxebarria (garetxe@gmail.com) |
Safe Haskell | None |
Language | Haskell2010 |
This base class is for parser elements that process data and splits it into separate audio/video/whatever frames.
It provides for: <itemizedlist> <listitem><para>provides one sink pad and one source pad</para></listitem> <listitem><para>handles state changes</para></listitem> <listitem><para>can operate in pull mode or push mode</para></listitem> <listitem><para>handles seeking in both modes</para></listitem> <listitem><para>handles events (SEGMENT/EOS/FLUSH)</para></listitem> <listitem><para> handles queries (POSITION/DURATION/SEEKING/FORMAT/CONVERT) </para></listitem> <listitem><para>handles flushing</para></listitem> </itemizedlist>
The purpose of this base class is to provide the basic functionality of a parser and share a lot of rather complex code.
Description of the parsing mechanism:
<orderedlist>
<listitem>
<itemizedlist><title>Set-up phase</title>
<listitem><para>
BaseParse
calls start
to inform subclass that data processing is
about to start now.
</para></listitem>
<listitem><para>
BaseParse
class calls setSinkCaps
to inform the subclass about
incoming sinkpad caps. Subclass could already set the srcpad caps
accordingly, but this might be delayed until calling
baseParseFinishFrame
with a non-queued frame.
</para></listitem>
<listitem><para>
At least at this point subclass needs to tell the BaseParse
class
how big data chunks it wants to receive (min_frame_size). It can do
this with baseParseSetMinFrameSize
.
</para></listitem>
<listitem><para>
BaseParse
class sets up appropriate data passing mode (pull/push)
and starts to process the data.
</para></listitem>
</itemizedlist>
</listitem>
<listitem>
<itemizedlist>
<title>Parsing phase</title>
<listitem><para>
BaseParse
gathers at least min_frame_size bytes of data either
by pulling it from upstream or collecting buffers in an internal
Adapter
.
</para></listitem>
<listitem><para>
A buffer of (at least) min_frame_size bytes is passed to subclass with
handleFrame
. Subclass checks the contents and can optionally
return GST_FLOW_OK along with an amount of data to be skipped to find
a valid frame (which will result in a subsequent DISCONT).
If, otherwise, the buffer does not hold a complete frame,
handleFrame
can merely return and will be called again when additional
data is available. In push mode this amounts to an
additional input buffer (thus minimal additional latency), in pull mode
this amounts to some arbitrary reasonable buffer size increase.
Of course, baseParseSetMinFrameSize
could also be used if a
very specific known amount of additional data is required.
If, however, the buffer holds a complete valid frame, it can pass
the size of this frame to baseParseFinishFrame
.
If acting as a converter, it can also merely indicate consumed input data
while simultaneously providing custom output data.
Note that baseclass performs some processing (such as tracking
overall consumed data rate versus duration) for each finished frame,
but other state is only updated upon each call to handleFrame
(such as tracking upstream input timestamp).
</para><para>
Subclass is also responsible for setting the buffer metadata
(e.g. buffer timestamp and duration, or keyframe if applicable).
(although the latter can also be done by BaseParse
if it is
appropriately configured, see below). Frame is provided with
timestamp derived from upstream (as much as generally possible),
duration obtained from configuration (see below), and offset
if meaningful (in pull mode).
</para><para>
Note that checkValidFrame
might receive any small
amount of input data when leftover data is being drained (e.g. at EOS).
</para></listitem>
<listitem><para>
As part of finish frame processing,
just prior to actually pushing the buffer in question,
it is passed to prePushFrame
which gives subclass yet one
last chance to examine buffer metadata, or to send some custom (tag)
events, or to perform custom (segment) filtering.
</para></listitem>
<listitem><para>
During the parsing process BaseParseClass
will handle both srcpad
and sinkpad events. They will be passed to subclass if event
or
srcEvent
callbacks have been provided.
</para></listitem>
</itemizedlist>
</listitem>
<listitem>
<itemizedlist><title>Shutdown phase</title>
<listitem><para>
BaseParse
class calls stop
to inform the subclass that data
parsing will be stopped.
</para></listitem>
</itemizedlist>
</listitem>
</orderedlist>
Subclass is responsible for providing pad template caps for
source and sink pads. The pads need to be named "sink" and "src". It also
needs to set the fixed caps on srcpad, when the format is ensured (e.g.
when base class calls subclass' setSinkCaps
function).
This base class uses FormatDefault
as a meaning of frames. So,
subclass conversion routine needs to know that conversion from
FormatTime
to FormatDefault
must return the
frame number that can be found from the given byte position.
BaseParse
uses subclasses conversion methods also for seeking (or
otherwise uses its own default one, see also below).
Subclass start
and stop
functions will be called to inform the beginning
and end of data processing.
Things that subclass need to take care of:
<itemizedlist>
<listitem><para>Provide pad templates</para></listitem>
<listitem><para>
Fixate the source pad caps when appropriate
</para></listitem>
<listitem><para>
Inform base class how big data chunks should be retrieved. This is
done with baseParseSetMinFrameSize
function.
</para></listitem>
<listitem><para>
Examine data chunks passed to subclass with handleFrame
and pass
proper frame(s) to baseParseFinishFrame
, and setting src pad
caps and timestamps on frame.
</para></listitem>
<listitem><para>Provide conversion functions</para></listitem>
<listitem><para>
Update the duration information with baseParseSetDuration
</para></listitem>
<listitem><para>
Optionally passthrough using baseParseSetPassthrough
</para></listitem>
<listitem><para>
Configure various baseparse parameters using
baseParseSetAverageBitrate
, baseParseSetSyncable
and baseParseSetFrameRate
.
</para></listitem>
<listitem><para>
In particular, if subclass is unable to determine a duration, but
parsing (or specs) yields a frames per seconds rate, then this can be
provided to BaseParse
to enable it to cater for
buffer time metadata (which will be taken from upstream as much as
possible). Internally keeping track of frame durations and respective
sizes that have been pushed provides BaseParse
with an estimated
bitrate. A default convert
(used if not overridden) will then use these
rates to perform obvious conversions. These rates are also used to
update (estimated) duration at regular frame intervals.
</para></listitem>
</itemizedlist>
- newtype BaseParse = BaseParse (ManagedPtr BaseParse)
- class GObject o => IsBaseParse o
- toBaseParse :: IsBaseParse o => o -> IO BaseParse
- noBaseParse :: Maybe BaseParse
- data BaseParseAddIndexEntryMethodInfo
- baseParseAddIndexEntry :: (HasCallStack, MonadIO m, IsBaseParse a) => a -> Word64 -> Word64 -> Bool -> Bool -> m Bool
- data BaseParseConvertDefaultMethodInfo
- baseParseConvertDefault :: (HasCallStack, MonadIO m, IsBaseParse a) => a -> Format -> Int64 -> Format -> Int64 -> m Bool
- data BaseParseFinishFrameMethodInfo
- baseParseFinishFrame :: (HasCallStack, MonadIO m, IsBaseParse a) => a -> BaseParseFrame -> Int32 -> m FlowReturn
- data BaseParseMergeTagsMethodInfo
- baseParseMergeTags :: (HasCallStack, MonadIO m, IsBaseParse a) => a -> Maybe TagList -> TagMergeMode -> m ()
- data BaseParsePushFrameMethodInfo
- baseParsePushFrame :: (HasCallStack, MonadIO m, IsBaseParse a) => a -> BaseParseFrame -> m FlowReturn
- data BaseParseSetAverageBitrateMethodInfo
- baseParseSetAverageBitrate :: (HasCallStack, MonadIO m, IsBaseParse a) => a -> Word32 -> m ()
- data BaseParseSetDurationMethodInfo
- baseParseSetDuration :: (HasCallStack, MonadIO m, IsBaseParse a) => a -> Format -> Int64 -> Int32 -> m ()
- data BaseParseSetFrameRateMethodInfo
- baseParseSetFrameRate :: (HasCallStack, MonadIO m, IsBaseParse a) => a -> Word32 -> Word32 -> Word32 -> Word32 -> m ()
- data BaseParseSetHasTimingInfoMethodInfo
- baseParseSetHasTimingInfo :: (HasCallStack, MonadIO m, IsBaseParse a) => a -> Bool -> m ()
- data BaseParseSetInferTsMethodInfo
- baseParseSetInferTs :: (HasCallStack, MonadIO m, IsBaseParse a) => a -> Bool -> m ()
- data BaseParseSetLatencyMethodInfo
- baseParseSetLatency :: (HasCallStack, MonadIO m, IsBaseParse a) => a -> Word64 -> Word64 -> m ()
- data BaseParseSetMinFrameSizeMethodInfo
- baseParseSetMinFrameSize :: (HasCallStack, MonadIO m, IsBaseParse a) => a -> Word32 -> m ()
- data BaseParseSetPassthroughMethodInfo
- baseParseSetPassthrough :: (HasCallStack, MonadIO m, IsBaseParse a) => a -> Bool -> m ()
- data BaseParseSetPtsInterpolationMethodInfo
- baseParseSetPtsInterpolation :: (HasCallStack, MonadIO m, IsBaseParse a) => a -> Bool -> m ()
- data BaseParseSetSyncableMethodInfo
- baseParseSetSyncable :: (HasCallStack, MonadIO m, IsBaseParse a) => a -> Bool -> m ()
- data BaseParseSetTsAtOffsetMethodInfo
- baseParseSetTsAtOffset :: (HasCallStack, MonadIO m, IsBaseParse a) => a -> Word64 -> m ()
- data BaseParseDisablePassthroughPropertyInfo
- baseParseDisablePassthrough :: AttrLabelProxy "disablePassthrough"
- constructBaseParseDisablePassthrough :: IsBaseParse o => Bool -> IO (GValueConstruct o)
- getBaseParseDisablePassthrough :: (MonadIO m, IsBaseParse o) => o -> m Bool
- setBaseParseDisablePassthrough :: (MonadIO m, IsBaseParse o) => o -> Bool -> m ()
Exported types
GObject BaseParse Source # | |
IsObject BaseParse Source # | |
IsElement BaseParse Source # | |
IsObject BaseParse Source # | |
IsBaseParse BaseParse Source # | |
((~) * info (ResolveBaseParseMethod t BaseParse), MethodInfo * info BaseParse p) => IsLabel t (BaseParse -> p) Source # | |
((~) * info (ResolveBaseParseMethod t BaseParse), MethodInfo * info BaseParse p) => IsLabelProxy t (BaseParse -> p) Source # | |
HasAttributeList * BaseParse Source # | |
type AttributeList BaseParse Source # | |
type SignalList BaseParse Source # | |
class GObject o => IsBaseParse o Source #
toBaseParse :: IsBaseParse o => o -> IO BaseParse Source #
Methods
addIndexEntry
data BaseParseAddIndexEntryMethodInfo Source #
((~) * signature (Word64 -> Word64 -> Bool -> Bool -> m Bool), MonadIO m, IsBaseParse a) => MethodInfo * BaseParseAddIndexEntryMethodInfo a signature Source # | |
baseParseAddIndexEntry Source #
:: (HasCallStack, MonadIO m, IsBaseParse a) | |
=> a |
|
-> Word64 |
|
-> Word64 |
|
-> Bool |
|
-> Bool |
|
-> m Bool | Returns: |
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.
convertDefault
data BaseParseConvertDefaultMethodInfo Source #
((~) * signature (Format -> Int64 -> Format -> Int64 -> m Bool), MonadIO m, IsBaseParse a) => MethodInfo * BaseParseConvertDefaultMethodInfo a signature Source # | |
baseParseConvertDefault Source #
:: (HasCallStack, MonadIO m, IsBaseParse a) | |
=> a |
|
-> Format |
|
-> Int64 |
|
-> Format |
|
-> Int64 |
|
-> m Bool | Returns: |
Default implementation of "convert" vmethod in BaseParse
class.
finishFrame
data BaseParseFinishFrameMethodInfo Source #
((~) * signature (BaseParseFrame -> Int32 -> m FlowReturn), MonadIO m, IsBaseParse a) => MethodInfo * BaseParseFinishFrameMethodInfo a signature Source # | |
:: (HasCallStack, MonadIO m, IsBaseParse a) | |
=> a |
|
-> BaseParseFrame |
|
-> Int32 |
|
-> m FlowReturn | Returns: a |
Collects parsed data and pushes this 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.
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
.
mergeTags
data BaseParseMergeTagsMethodInfo Source #
((~) * signature (Maybe TagList -> TagMergeMode -> m ()), MonadIO m, IsBaseParse a) => MethodInfo * BaseParseMergeTagsMethodInfo a signature Source # | |
:: (HasCallStack, MonadIO m, IsBaseParse a) | |
=> a |
|
-> Maybe TagList |
|
-> TagMergeMode |
|
-> m () |
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 baseParseMergeTags
.
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.
Since: 1.6
pushFrame
data BaseParsePushFrameMethodInfo Source #
((~) * signature (BaseParseFrame -> m FlowReturn), MonadIO m, IsBaseParse a) => MethodInfo * BaseParsePushFrameMethodInfo a signature Source # | |
:: (HasCallStack, MonadIO m, IsBaseParse a) | |
=> a |
|
-> BaseParseFrame |
|
-> m FlowReturn | Returns: |
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.
setAverageBitrate
data BaseParseSetAverageBitrateMethodInfo Source #
((~) * signature (Word32 -> m ()), MonadIO m, IsBaseParse a) => MethodInfo * BaseParseSetAverageBitrateMethodInfo a signature Source # | |
baseParseSetAverageBitrate Source #
:: (HasCallStack, MonadIO m, IsBaseParse a) | |
=> a |
|
-> Word32 |
|
-> m () |
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 baseParseSetSyncable
).
setDuration
data BaseParseSetDurationMethodInfo Source #
((~) * signature (Format -> Int64 -> Int32 -> m ()), MonadIO m, IsBaseParse a) => MethodInfo * BaseParseSetDurationMethodInfo a signature Source # | |
:: (HasCallStack, MonadIO m, IsBaseParse a) | |
=> a |
|
-> Format |
|
-> Int64 |
|
-> Int32 |
|
-> m () |
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.
setFrameRate
data BaseParseSetFrameRateMethodInfo Source #
((~) * signature (Word32 -> Word32 -> Word32 -> Word32 -> m ()), MonadIO m, IsBaseParse a) => MethodInfo * BaseParseSetFrameRateMethodInfo a signature Source # | |
baseParseSetFrameRate Source #
:: (HasCallStack, MonadIO m, IsBaseParse a) | |
=> a |
|
-> Word32 |
|
-> Word32 |
|
-> Word32 |
|
-> Word32 |
|
-> m () |
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 leadIn
and a
following leadOut
number of frames to ensure the desired segment is
entirely filled upon decoding.
setHasTimingInfo
data BaseParseSetHasTimingInfoMethodInfo Source #
((~) * signature (Bool -> m ()), MonadIO m, IsBaseParse a) => MethodInfo * BaseParseSetHasTimingInfoMethodInfo a signature Source # | |
baseParseSetHasTimingInfo Source #
:: (HasCallStack, MonadIO m, IsBaseParse a) | |
=> a |
|
-> Bool |
|
-> m () |
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.
setInferTs
data BaseParseSetInferTsMethodInfo Source #
((~) * signature (Bool -> m ()), MonadIO m, IsBaseParse a) => MethodInfo * BaseParseSetInferTsMethodInfo a signature Source # | |
:: (HasCallStack, MonadIO m, IsBaseParse a) | |
=> a |
|
-> Bool |
|
-> m () |
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.
setLatency
data BaseParseSetLatencyMethodInfo Source #
((~) * signature (Word64 -> Word64 -> m ()), MonadIO m, IsBaseParse a) => MethodInfo * BaseParseSetLatencyMethodInfo a signature Source # | |
:: (HasCallStack, MonadIO m, IsBaseParse a) | |
=> a |
|
-> Word64 |
|
-> Word64 |
|
-> m () |
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.
setMinFrameSize
data BaseParseSetMinFrameSizeMethodInfo Source #
((~) * signature (Word32 -> m ()), MonadIO m, IsBaseParse a) => MethodInfo * BaseParseSetMinFrameSizeMethodInfo a signature Source # | |
baseParseSetMinFrameSize Source #
:: (HasCallStack, MonadIO m, IsBaseParse a) | |
=> a |
|
-> Word32 |
|
-> m () |
Subclass can use this function to tell the base class that it needs to
give at least min_size
buffers.
setPassthrough
data BaseParseSetPassthroughMethodInfo Source #
((~) * signature (Bool -> m ()), MonadIO m, IsBaseParse a) => MethodInfo * BaseParseSetPassthroughMethodInfo a signature Source # | |
baseParseSetPassthrough Source #
:: (HasCallStack, MonadIO m, IsBaseParse a) | |
=> a |
|
-> Bool |
|
-> m () |
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 checkValidFrame
or parseFrame
callbacks will be invoked, but prePushFrame
will still be invoked,
so subclass can perform as much or as little is appropriate for
passthrough semantics in prePushFrame
.
setPtsInterpolation
data BaseParseSetPtsInterpolationMethodInfo Source #
((~) * signature (Bool -> m ()), MonadIO m, IsBaseParse a) => MethodInfo * BaseParseSetPtsInterpolationMethodInfo a signature Source # | |
baseParseSetPtsInterpolation Source #
:: (HasCallStack, MonadIO m, IsBaseParse a) | |
=> a |
|
-> Bool |
|
-> m () |
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.
setSyncable
data BaseParseSetSyncableMethodInfo Source #
((~) * signature (Bool -> m ()), MonadIO m, IsBaseParse a) => MethodInfo * BaseParseSetSyncableMethodInfo a signature Source # | |
:: (HasCallStack, MonadIO m, IsBaseParse a) | |
=> a |
|
-> Bool |
|
-> m () |
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.
setTsAtOffset
data BaseParseSetTsAtOffsetMethodInfo Source #
((~) * signature (Word64 -> m ()), MonadIO m, IsBaseParse a) => MethodInfo * BaseParseSetTsAtOffsetMethodInfo a signature Source # | |
baseParseSetTsAtOffset Source #
:: (HasCallStack, MonadIO m, IsBaseParse a) | |
=> a |
|
-> Word64 |
|
-> m () |
This function should only be called from a handleFrame
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.
Since: 1.2
Properties
disablePassthrough
data BaseParseDisablePassthroughPropertyInfo Source #
baseParseDisablePassthrough :: AttrLabelProxy "disablePassthrough" Source #
constructBaseParseDisablePassthrough :: IsBaseParse o => Bool -> IO (GValueConstruct o) Source #
getBaseParseDisablePassthrough :: (MonadIO m, IsBaseParse o) => o -> m Bool Source #
setBaseParseDisablePassthrough :: (MonadIO m, IsBaseParse o) => o -> Bool -> m () Source #