BaseParse

This base class is for parser elements that process data and splits it into separate audio/video/whatever frames.

It provides for:

* provides one sink pad and one source pad * handles state changes * can operate in pull mode or push mode * handles seeking in both modes * handles events (SEGMENT/EOS/FLUSH) * handles queries (POSITION/DURATION/SEEKING/FORMAT/CONVERT) * handles flushing

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:

Set-up phase

* gst.BaseParse.BaseParse calls GstBaseParseClas.start|GstBaseParseClas.starts to inform subclass that data processing is about to start now.

* gst.BaseParse.BaseParse class calls GstBaseParseClas.set_sink_caps|GstBaseParseClas.set_sink_capss to inform the subclass about incoming sinkpad caps. Subclass could already set the srcpad caps accordingly, but this might be delayed until calling BaseParse.finishFrame with a non-queued frame.

* At least at this point subclass needs to tell the gst.BaseParse.BaseParse class how big data chunks it wants to receive (minimum frame size ). It can do this with BaseParse.setMinFrameSize.

* gst.BaseParse.BaseParse class sets up appropriate data passing mode (pull/push) and starts to process the data.

Parsing phase

* gst.BaseParse.BaseParse gathers at least min_frame_size bytes of data either by pulling it from upstream or collecting buffers in an internal gst.Adapter.Adapter

* A buffer of (at least) min_frame_size bytes is passed to subclass with GstBaseParseClas.handle_frame|GstBaseParseClas.handle_frames. 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, GstBaseParseClas.handle_frame|GstBaseParseClas.handle_frames 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, BaseParse.setMinFrameSize 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 BaseParse.finishFrame.

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 GstBaseParseClas.handle_frame|GstBaseParseClas.handle_frames (such as tracking upstream input timestamp).

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 gst.BaseParse.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).

Note that GstBaseParseClas.handle_frame|GstBaseParseClas.handle_frames might receive any small amount of input data when leftover data is being drained (e.g. at EOS).

* As part of finish frame processing, just prior to actually pushing the buffer in question, it is passed to GstBaseParseClas.pre_push_frame|GstBaseParseClas.pre_push_frames which gives subclass yet one last chance to examine buffer metadata, or to send some custom (tag) events, or to perform custom (segment) filtering.

* During the parsing process GstBaseParseClass will handle both srcpad and sinkpad events. They will be passed to subclass if GstBaseParseClas.event|GstBaseParseClas.events or GstBaseParseClas.src_event|GstBaseParseClas.src_events implementations have been provided.

Shutdown phase

* gst.BaseParse.BaseParse class calls GstBaseParseClas.stop|GstBaseParseClas.stops to inform the subclass that data parsing will be stopped.

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' GstBaseParseClas.set_sink_caps|GstBaseParseClas.set_sink_capss function).

This base class uses GST_FORMAT_DEFAULT as a meaning of frames. So, subclass conversion routine needs to know that conversion from GST_FORMAT_TIME to GST_FORMAT_DEFAULT must return the frame number that can be found from the given byte position.

gst.BaseParse.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:

* Provide pad templates * Fixate the source pad caps when appropriate * Inform base class how big data chunks should be retrieved. This is done with BaseParse.setMinFrameSize function. * Examine data chunks passed to subclass with GstBaseParseClas.handle_frame|GstBaseParseClas.handle_frames and pass proper frame(s) to BaseParse.finishFrame, and setting src pad caps and timestamps on frame. * Provide conversion functions * Update the duration information with BaseParse.setDuration * Optionally passthrough using BaseParse.setPassthrough * Configure various baseparse parameters using BaseParse.setAverageBitrate, BaseParse.setSyncable and BaseParse.setFrameRate.

* 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 gst.BaseParse.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 gst.BaseParse.BaseParse with an estimated bitrate. A default GstBaseParseClas.convert|GstBaseParseClas.converts (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.

Constructors

this
this(GstBaseParse* gstBaseParse, bool ownedRef)

Sets our main struct and passes it to the parent class.

Members

Functions

addIndexEntry
bool addIndexEntry(ulong offset, GstClockTime ts, bool key, bool force)

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
bool convertDefault(GstFormat srcFormat, long srcValue, GstFormat destFormat, long destValue)

Default implementation of GstBaseParseClas.convert|GstBaseParseClas.converts.

drain
void drain()

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.

finishFrame
GstFlowReturn finishFrame(BaseParseFrame frame, int size)

Collects parsed data and pushes this downstream. Source pad caps must be set when this is called.

getBaseParseStruct
GstBaseParse* getBaseParseStruct(bool transferOwnership)

Get the main Gtk struct

getStruct
void* getStruct()

the main Gtk struct as a void*

mergeTags
void mergeTags(TagList tags, GstTagMergeMode mode)

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 BaseParse.mergeTags.

pushFrame
GstFlowReturn pushFrame(BaseParseFrame frame)

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.

setAverageBitrate
void setAverageBitrate(uint bitrate)

Optionally sets the average bitrate detected in media (if non-zero), e.g. based on metadata, as it will be posted to the application.

setDuration
void setDuration(GstFormat fmt, long duration, int interval)

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
void setFrameRate(uint fpsNum, uint fpsDen, uint leadIn, uint leadOut)

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.

setHasTimingInfo
void setHasTimingInfo(bool hasTiming)

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
void setInferTs(bool inferTs)

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
void setLatency(GstClockTime minLatency, GstClockTime maxLatency)

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
void setMinFrameSize(uint minSize)

Subclass can use this function to tell the base class that it needs to be given buffers of at least min_size bytes.

setPassthrough
void setPassthrough(bool passthrough)

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 GstBaseParseClas.handle_frame|GstBaseParseClas.handle_frames will be invoked, but GstBaseParseClas.pre_push_frame|GstBaseParseClas.pre_push_frames will still be invoked, so subclass can perform as much or as little is appropriate for passthrough semantics in GstBaseParseClas.pre_push_frame|GstBaseParseClas.pre_push_frames.

setPtsInterpolation
void setPtsInterpolation(bool ptsInterpolate)

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
void setSyncable(bool syncable)

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
void setTsAtOffset(size_t offset)

This function should only be called from a handle_frame implementation.

Static functions

getType
GType getType()

Variables

gstBaseParse
GstBaseParse* gstBaseParse;

the main Gtk struct

Inherited Members

From Element

gstElement
GstElement* gstElement;

the main Gtk struct

getElementStruct
GstElement* getElementStruct(bool transferOwnership)

Get the main Gtk struct

getStruct
void* getStruct()

the main Gtk struct as a void*

queryPosition
long queryPosition()

Queries an element for the stream position. This is a convenience function for gstreamerD.

queryDuration
long queryDuration()

Queries an element for the stream duration. This is a convenience function for gstreamerD.

location
void location(string set)

This set's the filename for a filesrc element.

caps
void caps(Caps cp)

Set the caps property of an Element.

seek
int seek(long time_nanoseconds)

For your convenience in gstreamerD: you can seek to the position of the pipeline measured in time_nanoseconds.

pads
Pad[] pads()

Get's all the pads from an element in a Pad[].

getType
GType getType()
makeFromUri
Element makeFromUri(GstURIType type, string uri, string elementname)

Creates an element for handling the given URI.

register
bool register(Plugin plugin, string name, uint rank, GType type)

Create a new elementfactory capable of instantiating objects of the type and add the factory to plugin.

stateChangeReturnGetName
string stateChangeReturnGetName(GstStateChangeReturn stateRet)

Gets a string representing the given state change result.

stateGetName
string stateGetName(GstState state)

Gets a string representing the given state.

abortState
void abortState()

Abort the state change of the element. This function is used by elements that do asynchronous state changes and find out something is wrong.

addPad
bool addPad(Pad pad)

Adds a pad (link point) to element. pad's parent will be set to element; see gst_object_set_parent() for refcounting information.

addPropertyDeepNotifyWatch
gulong addPropertyDeepNotifyWatch(string propertyName, bool includeValue)
addPropertyNotifyWatch
gulong addPropertyNotifyWatch(string propertyName, bool includeValue)
callAsync
void callAsync(GstElementCallAsyncFunc func, void* userData, GDestroyNotify destroyNotify)

Calls func from another thread and passes user_data to it. This is to be used for cases when a state change has to be performed from a streaming thread, directly via Element.setState or indirectly e.g. via SEEK events.

changeState
GstStateChangeReturn changeState(GstStateChange transition)

Perform transition on element.

continueState
GstStateChangeReturn continueState(GstStateChangeReturn ret)

Commit the state change of the element and proceed to the next pending state if any. This function is used by elements that do asynchronous state changes. The core will normally call this method automatically when an element returned GST_STATE_CHANGE_SUCCESS from the state change function.

createAllPads
void createAllPads()

Creates a pad for each pad template that is always available. This function is only useful during object initialization of subclasses of gstreamer.Element

foreachPad
bool foreachPad(GstElementForeachPadFunc func, void* userData)

Call func with user_data for each of element's pads. func will be called exactly once for each pad that exists at the time of this call, unless one of the calls to func returns FALSE in which case we will stop iterating pads and return early. If new pads are added or pads are removed while pads are being iterated, this will not be taken into account until next time this function is used.

foreachSinkPad
bool foreachSinkPad(GstElementForeachPadFunc func, void* userData)

Call func with user_data for each of element's sink pads. func will be called exactly once for each sink pad that exists at the time of this call, unless one of the calls to func returns FALSE in which case we will stop iterating pads and return early. If new sink pads are added or sink pads are removed while the sink pads are being iterated, this will not be taken into account until next time this function is used.

foreachSrcPad
bool foreachSrcPad(GstElementForeachPadFunc func, void* userData)

Call func with user_data for each of element's source pads. func will be called exactly once for each source pad that exists at the time of this call, unless one of the calls to func returns FALSE in which case we will stop iterating pads and return early. If new source pads are added or source pads are removed while the source pads are being iterated, this will not be taken into account until next time this function is used.

getBaseTime
GstClockTime getBaseTime()

Returns the base time of the element. The base time is the absolute time of the clock when this element was last put to PLAYING. Subtracting the base time from the clock time gives the running time of the element.

getBus
Bus getBus()

Returns the bus of the element. Note that only a gstreamer.Pipeline will provide a bus for the application.

getClock
Clock getClock()

Gets the currently configured clock of the element. This is the clock as was last set with Element.setClock.

getCompatiblePad
Pad getCompatiblePad(Pad pad, Caps caps)

Looks for an unlinked pad to which the given pad can link. It is not guaranteed that linking the pads will work, though it should work in most cases.

getCompatiblePadTemplate
PadTemplate getCompatiblePadTemplate(PadTemplate compattempl)

Retrieves a pad template from element that is compatible with compattempl. Pads from compatible templates can be linked together.

getContext
Context getContext(string contextType)

Gets the context with context_type set on the element or NULL.

getContextUnlocked
Context getContextUnlocked(string contextType)

Gets the context with context_type set on the element or NULL.

getContexts
ListG getContexts()

Gets the contexts set on the element.

getFactory
ElementFactory getFactory()

Retrieves the factory that was used to create this element.

getMetadata
string getMetadata(string key)

Get metadata with key in klass.

getPadTemplate
PadTemplate getPadTemplate(string name)

Retrieves a padtemplate from element with the given name.

getPadTemplateList
ListG getPadTemplateList()

Retrieves a list of the pad templates associated with element. The list must not be modified by the calling code.

getRequestPad
Pad getRequestPad(string name)

Retrieves a pad from the element by name (e.g. "src_\d"). This version only retrieves request pads. The pad should be released with Element.releaseRequestPad.

getStartTime
GstClockTime getStartTime()

Returns the start time of the element. The start time is the running time of the clock when this element was last put to PAUSED.

getState
GstStateChangeReturn getState(GstState state, GstState pending, GstClockTime timeout)

Gets the state of the element.

getStaticPad
Pad getStaticPad(string name)

Retrieves a pad from element by name. This version only retrieves already-existing (i.e. 'static') pads.

isLockedState
bool isLockedState()

Checks if the state of an element is locked. If the state of an element is locked, state changes of the parent don't affect the element. This way you can leave currently unused elements inside bins. Just lock their state before changing the state from GST_STATE_NULL

iteratePads
Iterator iteratePads()

Retrieves an iterator of element's pads. The iterator should be freed after usage. Also more specialized iterators exists such as Element.iterateSrcPads or Element.iterateSinkPads.

iterateSinkPads
Iterator iterateSinkPads()

Retrieves an iterator of element's sink pads.

iterateSrcPads
Iterator iterateSrcPads()

Retrieves an iterator of element's source pads.

link
bool link(Element dest)

Links src to dest. The link must be from source to destination; the other direction will not be tried. The function looks for existing pads that aren't linked yet. It will request new pads if necessary. Such pads need to be released manually when unlinking. If multiple links are possible, only one is established.

linkFiltered
bool linkFiltered(Element dest, Caps filter)

Links src to dest using the given caps as filtercaps. The link must be from source to destination; the other direction will not be tried. The function looks for existing pads that aren't linked yet. It will request new pads if necessary. If multiple links are possible, only one is established.

linkPads
bool linkPads(string srcpadname, Element dest, string destpadname)

Links the two named pads of the source and destination elements. Side effect is that if one of the pads has no parent, it becomes a child of the parent of the other element. If they have different parents, the link fails.

linkPadsFiltered
bool linkPadsFiltered(string srcpadname, Element dest, string destpadname, Caps filter)

Links the two named pads of the source and destination elements. Side effect is that if one of the pads has no parent, it becomes a child of the parent of the other element. If they have different parents, the link fails. If caps is not NULL, makes sure that the caps of the link is a subset of caps.

linkPadsFull
bool linkPadsFull(string srcpadname, Element dest, string destpadname, GstPadLinkCheck flags)

Links the two named pads of the source and destination elements. Side effect is that if one of the pads has no parent, it becomes a child of the parent of the other element. If they have different parents, the link fails.

lostState
void lostState()

Brings the element to the lost state. The current state of the element is copied to the pending state so that any call to Element.getState will return GST_STATE_CHANGE_ASYNC.

messageFull
void messageFull(GstMessageType type, GQuark domain, int code, string text, string debug_, string file, string function_, int line)

Post an error, warning or info message on the bus from inside an element.

messageFullWithDetails
void messageFullWithDetails(GstMessageType type, GQuark domain, int code, string text, string debug_, string file, string function_, int line, Structure structure)

Post an error, warning or info message on the bus from inside an element.

noMorePads
void noMorePads()

Use this function to signal that the element does not expect any more pads to show up in the current pipeline. This function should be called whenever pads have been added by the element itself. Elements with GST_PAD_SOMETIMES pad templates use this in combination with autopluggers to figure out that the element is done initializing its pads.

postMessage
bool postMessage(Message message)

Post a message on the element's gstreamer.Bus This function takes ownership of the message; if you want to access the message after this call, you should add an additional reference before calling.

provideClock
Clock provideClock()

Get the clock provided by the given element. > An element is only required to provide a clock in the PAUSED > state. Some elements can provide a clock in other states.

query
bool query(Query query)

Performs a query on the given element.

queryConvert
bool queryConvert(GstFormat srcFormat, long srcVal, GstFormat destFormat, long destVal)

Queries an element to convert src_val in src_format to dest_format.

queryDuration
bool queryDuration(GstFormat format, long duration)

Queries an element (usually top-level pipeline or playbin element) for the total stream duration in nanoseconds. This query will only work once the pipeline is prerolled (i.e. reached PAUSED or PLAYING state). The application will receive an ASYNC_DONE message on the pipeline bus when that is the case.

queryPosition
bool queryPosition(GstFormat format, long cur)

Queries an element (usually top-level pipeline or playbin element) for the stream position in nanoseconds. This will be a value between 0 and the stream duration (if the stream duration is known). This query will usually only work once the pipeline is prerolled (i.e. reached PAUSED or PLAYING state). The application will receive an ASYNC_DONE message on the pipeline bus when that is the case.

releaseRequestPad
void releaseRequestPad(Pad pad)

Makes the element free the previously requested pad as obtained with Element.requestPad.

removePad
bool removePad(Pad pad)

Removes pad from element. pad will be destroyed if it has not been referenced elsewhere using gst_object_unparent().

removePropertyNotifyWatch
void removePropertyNotifyWatch(gulong watchId)
requestPad
Pad requestPad(PadTemplate templ, string name, Caps caps)

Retrieves a request pad from the element according to the provided template. Pad templates can be looked up using Element.factoryGetStaticPadTemplates.

seek
bool seek(double rate, GstFormat format, GstSeekFlags flags, GstSeekType startType, long start, GstSeekType stopType, long stop)

Sends a seek event to an element. See Event.newSeek for the details of the parameters. The seek event is sent to the element using Element.sendEvent.

seekSimple
bool seekSimple(GstFormat format, GstSeekFlags seekFlags, long seekPos)

Simple API to perform a seek on the given element, meaning it just seeks to the given position relative to the start of the stream. For more complex operations like segment seeks (e.g. for looping) or changing the playback rate or seeking relative to the last configured playback segment you should use Element.seek.

sendEvent
bool sendEvent(Event event)

Sends an event to an element. If the element doesn't implement an event handler, the event will be pushed on a random linked sink pad for downstream events or a random linked source pad for upstream events.

setBaseTime
void setBaseTime(GstClockTime time)

Set the base time of an element. See Element.getBaseTime.

setBus
void setBus(Bus bus)

Sets the bus of the element. Increases the refcount on the bus. For internal use only, unless you're testing elements.

setClock
bool setClock(Clock clock)

Sets the clock for the element. This function increases the refcount on the clock. Any previously set clock on the object is unreffed.

setContext
void setContext(Context context)

Sets the context of the element. Increases the refcount of the context.

setLockedState
bool setLockedState(bool lockedState)

Locks the state of an element, so state changes of the parent don't affect this element anymore.

setStartTime
void setStartTime(GstClockTime time)

Set the start time of an element. The start time of the element is the running time of the element when it last went to the PAUSED state. In READY or after a flushing seek, it is set to 0.

setState
GstStateChangeReturn setState(GstState state)

Sets the state of the element. This function will try to set the requested state by going through all the intermediary states and calling the class's state change function for each.

syncStateWithParent
bool syncStateWithParent()

Tries to change the state of the element to the same as its parent. If this function returns FALSE, the state of element is undefined.

unlink
void unlink(Element dest)

Unlinks all source pads of the source element with all sink pads of the sink element to which they are linked.

unlinkPads
void unlinkPads(string srcpadname, Element dest, string destpadname)

Unlinks the two named pads of the source and destination elements.

addOnNoMorePads
gulong addOnNoMorePads(void delegate(Element) dlg, ConnectFlags connectFlags)

This signals that the element will not generate more dynamic pads. Note that this signal will usually be emitted from the context of the streaming thread.

addOnPadAdded
gulong addOnPadAdded(void delegate(Pad, Element) dlg, ConnectFlags connectFlags)

a new gstreamer.Pad has been added to the element. Note that this signal will usually be emitted from the context of the streaming thread. Also keep in mind that if you add new elements to the pipeline in the signal handler you will need to set them to the desired target state with Element.setState or Element.syncStateWithParent.

addOnPadRemoved
gulong addOnPadRemoved(void delegate(Pad, Element) dlg, ConnectFlags connectFlags)

a gstreamer.Pad has been removed from the element