gstaudio.audio_decoder
Module for [AudioDecoder] class
Types 3
This base class is for audio decoders turning encoded data into raw audio samples.
GstAudioDecoder and subclass should cooperate as follows.
Configuration
- Initially, GstAudioDecoder calls @start when the decoder element
is activated, which allows subclass to perform any global setup. Base class (context) parameters can already be set according to subclass capabilities (or possibly upon receive more information in subsequent @set_format).
- GstAudioDecoder calls @set_format to inform subclass of the format
of input audio data that it is about to receive. While unlikely, it might be called more than once, if changing input parameters require reconfiguration.
- GstAudioDecoder calls @stop at end of all processing.
As of configuration stage, and throughout processing, GstAudioDecoder provides various (context) parameters, e.g. describing the format of output audio data (valid when output caps have been set) or current parsing state. Conversely, subclass can and should configure context to inform base class of its expectation w.r.t. buffer handling.
Data processing
- Base class gathers input data, and optionally allows subclass
to parse this into subsequently manageable (as defined by subclass) chunks. Such chunks are subsequently referred to as 'frames', though they may or may not correspond to 1 (or more) audio format frame.
- Input frame is provided to subclass' @handle_frame.
- If codec processing results in decoded data, subclass should call
@gst_audio_decoder_finish_frame to have decoded data pushed downstream.
- Just prior to actually pushing a buffer downstream,
it is passed to @pre_push. Subclass should either use this callback to arrange for additional downstream pushing or otherwise ensure such custom pushing occurs after at least a method call has finished since setting src pad caps.
- During the parsing process GstAudioDecoderClass will handle both
srcpad and sinkpad events. Sink events will be passed to subclass if @event callback has been provided.
Shutdown phase
- GstAudioDecoder class calls @stop 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. This is typically when base class calls subclass' @set_format function, though it might be delayed until calling @gst_audio_decoder_finish_frame.
In summary, above process should have subclass concentrating on codec data processing while leaving other matters to base class, such as most notably timestamp handling. While it may exert more control in this area (see e.g. @pre_push), it is very much not recommended.
In particular, base class will try to arrange for perfect output timestamps as much as possible while tracking upstream timestamps. To this end, if deviation between the next ideal expected perfect timestamp and upstream exceeds #GstAudioDecoder:tolerance, then resync to upstream occurs (which would happen always if the tolerance mechanism is disabled).
In non-live pipelines, baseclass can also (configurably) arrange for output buffer aggregation which may help to redue large(r) numbers of small(er) buffers being pushed and processed downstream. Note that this feature is only available if the buffer layout is interleaved. For planar buffers, the decoder implementation is fully responsible for the output buffer size.
On the other hand, it should be noted that baseclass only provides limited seeking support (upon explicit subclass request), as full-fledged support should rather be left to upstream demuxer, parser or alike. This simple approach caters for seeking and duration reporting using estimated input bitrates.
Things that subclass need to take care of:
- Provide pad templates
- Set source pad caps when appropriate
- Set user-configurable properties to sane defaults for format and
implementing codec at hand, and convey some subclass capabilities and expectations in context.
- Accept data in @handle_frame and provide encoded results to
@gst_audio_decoder_finish_frame. If it is prepared to perform PLC, it should also accept NULL data in @handle_frame and provide for data for indicated duration.
AudioDecoder self()Returns `this`, for use in `with` statements.AudioDecoderGidBuilder builder()Get builder for [gstaudio.audio_decoder.AudioDecoder] Returns: New builder objectint maxErrors() @propertyGet `maxErrors` property. Returns: Maximum number of tolerated consecutive decode errors. See [gstaudio.audio_decoder.AudioDecoder.setMaxErrors] for more details.void maxErrors(int propval) @propertySet `maxErrors` property. Params: propval = Maximum number of tolerated consecutive decode errors. See [gstaudio.audio_decoder.AudioDecoder.setMaxErrors] for more details.long minLatency() @propertyvoid minLatency(long propval) @propertybool plc() @propertyvoid plc(bool propval) @propertylong tolerance() @propertyvoid tolerance(long propval) @propertygst.buffer.Buffer allocateOutputBuffer(size_t size)Helper function that allocates a buffer to hold an audio frame for dec's current output format.gst.types.FlowReturn finishFrame(gst.buffer.Buffer buf, int frames)Collects decoded data and pushes it downstream.gst.types.FlowReturn finishSubframe(gst.buffer.Buffer buf = null)Collects decoded data and pushes it downstream. This function may be called multiple times for a given input frame.void getAllocator(out gst.allocator.Allocator allocator, out gst.allocation_params.AllocationParams params)Lets #GstAudioDecoder sub-classes to know the memory allocator used by the base class and its params.int getDelay()bool getDrainable()Queries decoder drain handling. Returns: TRUE if drainable handling is enabled.int getEstimateRate()void getLatency(out gst.types.ClockTime min, out gst.types.ClockTime max)Sets the variables pointed to by min and max to the currently configured latency.int getMaxErrors()gst.types.ClockTime getMinLatency()Queries decoder's latency aggregation. Returns: aggregation latency.bool getNeedsFormat()Queries decoder required format handling. Returns: TRUE if required format handling is enabled.void getParseState(out bool sync, out bool eos)Return current parsing (sync and eos) state.bool getPlc()Queries decoder packet loss concealment handling. Returns: TRUE if packet loss concealment is enabled.int getPlcAware()gst.types.ClockTime getTolerance()Queries current audio jitter tolerance threshold. Returns: decoder audio jitter tolerance threshold.void mergeTags(gst.tag_list.TagList tags, gst.types.TagMergeMode mode)Sets the audio decoder tags and how they should be merged with any upstream stream tags. This will override any tags previously-set with [gstaudio.audio_decoder.AudioDecoder.mergeTags].bool negotiate()Negotiate with downstream elements to currently configured #GstAudioInfo. Unmark GSTPADFLAGNEEDRECONFIGURE in any case. But mark it again if negotiate fails. Returns: true if the negotiation succee...gst.caps.Caps proxyGetcaps(gst.caps.Caps caps = null, gst.caps.Caps filter = null)Returns caps that express caps (or sink template caps if caps == NULL) restricted to rate/channels/... combinations supported by downstream elements.void setAllocationCaps(gst.caps.Caps allocationCaps = null)Sets a caps in allocation query which are different from the set pad's caps. Use this function before calling [gstaudio.audio_decoder.AudioDecoder.negotiate]. Setting to null the allocation query w...void setDrainable(bool enabled)Configures decoder drain handling. If drainable, subclass might be handed a NULL buffer to have it return any leftover decoded data. Otherwise, it is not considered so capable and will only ever b...void setEstimateRate(bool enabled)Allows baseclass to perform byte to time estimated conversion.void setLatency(gst.types.ClockTime min, gst.types.ClockTime max)Sets decoder latency. 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.void setMaxErrors(int num)Sets numbers of tolerated decoder errors, where a tolerated one is then only warned about, but more than tolerated will lead to fatal error. You can set -1 for never returning fatal errors. Default...void setMinLatency(gst.types.ClockTime num)Sets decoder minimum aggregation latency.void setNeedsFormat(bool enabled)Configures decoder format needs. If enabled, subclass needs to be negotiated with format caps before it can process any data. It will then never be handed any data before it has been configured. ...bool setOutputCaps(gst.caps.Caps caps)Configure output caps on the srcpad of dec. Similar to [gstaudio.audio_decoder.AudioDecoder.setOutputFormat], but allows subclasses to specify output caps that can't be expressed via #GstAudioInfo ...bool setOutputFormat(gstaudio.audio_info.AudioInfo info)Configure output info on the srcpad of dec.void setPlc(bool enabled)Enable or disable decoder packet loss concealment, provided subclass and codec are capable and allow handling plc.void setPlcAware(bool plc)Indicates whether or not subclass handles packet loss concealment (plc).void setTolerance(gst.types.ClockTime tolerance)Configures decoder audio jitter tolerance threshold.void setUseDefaultPadAcceptcaps(bool use)Lets #GstAudioDecoder sub-classes decide if they want the sink pad to use the default pad query handler to reply to accept-caps queries.T maxErrors(int propval)Set `maxErrors` property. Params: propval = Maximum number of tolerated consecutive decode errors. See [gstaudio.audio_decoder.AudioDecoder.setMaxErrors] for more details. Returns: Builder instance...T minLatency(long propval)T plc(bool propval)T tolerance(long propval)Fluent builder for [gstaudio.audio_decoder.AudioDecoder]