2 * Copyright (C) 2009 Igalia S.L.
3 * Author: Iago Toral Quiroga <itoral@igalia.com>
4 * Copyright (C) 2011 Mark Nauwelaerts <mark.nauwelaerts@collabora.co.uk>.
5 * Copyright (C) 2011 Nokia Corporation. All rights reserved.
6 * Contact: Stefan Kost <stefan.kost@nokia.com>
8 * This library is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU Library General Public
10 * License as published by the Free Software Foundation; either
11 * version 2 of the License, or (at your option) any later version.
13 * This library is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 * Library General Public License for more details.
18 * You should have received a copy of the GNU Library General Public
19 * License along with this library; if not, write to the
20 * Free Software Foundation, Inc., 51 Franklin St, Fifth Floor,
21 * Boston, MA 02110-1301, USA.
25 * SECTION:gstaudiodecoder
26 * @title: GstAudioDecoder
27 * @short_description: Base class for audio decoders
28 * @see_also: #GstBaseTransform
30 * This base class is for audio decoders turning encoded data into
33 * GstAudioDecoder and subclass should cooperate as follows.
37 * * Initially, GstAudioDecoder calls @start when the decoder element
38 * is activated, which allows subclass to perform any global setup.
39 * Base class (context) parameters can already be set according to subclass
40 * capabilities (or possibly upon receive more information in subsequent
42 * * GstAudioDecoder calls @set_format to inform subclass of the format
43 * of input audio data that it is about to receive.
44 * While unlikely, it might be called more than once, if changing input
45 * parameters require reconfiguration.
46 * * GstAudioDecoder calls @stop at end of all processing.
48 * As of configuration stage, and throughout processing, GstAudioDecoder
49 * provides various (context) parameters, e.g. describing the format of
50 * output audio data (valid when output caps have been set) or current parsing state.
51 * Conversely, subclass can and should configure context to inform
52 * base class of its expectation w.r.t. buffer handling.
55 * * Base class gathers input data, and optionally allows subclass
56 * to parse this into subsequently manageable (as defined by subclass)
57 * chunks. Such chunks are subsequently referred to as 'frames',
58 * though they may or may not correspond to 1 (or more) audio format frame.
59 * * Input frame is provided to subclass' @handle_frame.
60 * * If codec processing results in decoded data, subclass should call
61 * @gst_audio_decoder_finish_frame to have decoded data pushed
63 * * Just prior to actually pushing a buffer downstream,
64 * it is passed to @pre_push. Subclass should either use this callback
65 * to arrange for additional downstream pushing or otherwise ensure such
66 * custom pushing occurs after at least a method call has finished since
67 * setting src pad caps.
68 * * During the parsing process GstAudioDecoderClass will handle both
69 * srcpad and sinkpad events. Sink events will be passed to subclass
70 * if @event callback has been provided.
74 * * GstAudioDecoder class calls @stop to inform the subclass that data
75 * parsing will be stopped.
77 * Subclass is responsible for providing pad template caps for
78 * source and sink pads. The pads need to be named "sink" and "src". It also
79 * needs to set the fixed caps on srcpad, when the format is ensured. This
80 * is typically when base class calls subclass' @set_format function, though
81 * it might be delayed until calling @gst_audio_decoder_finish_frame.
83 * In summary, above process should have subclass concentrating on
84 * codec data processing while leaving other matters to base class,
85 * such as most notably timestamp handling. While it may exert more control
86 * in this area (see e.g. @pre_push), it is very much not recommended.
88 * In particular, base class will try to arrange for perfect output timestamps
89 * as much as possible while tracking upstream timestamps.
90 * To this end, if deviation between the next ideal expected perfect timestamp
91 * and upstream exceeds #GstAudioDecoder:tolerance, then resync to upstream
92 * occurs (which would happen always if the tolerance mechanism is disabled).
94 * In non-live pipelines, baseclass can also (configurably) arrange for
95 * output buffer aggregation which may help to redue large(r) numbers of
96 * small(er) buffers being pushed and processed downstream. Note that this
97 * feature is only available if the buffer layout is interleaved. For planar
98 * buffers, the decoder implementation is fully responsible for the output
101 * On the other hand, it should be noted that baseclass only provides limited
102 * seeking support (upon explicit subclass request), as full-fledged support
103 * should rather be left to upstream demuxer, parser or alike. This simple
104 * approach caters for seeking and duration reporting using estimated input
107 * Things that subclass need to take care of:
109 * * Provide pad templates
110 * * Set source pad caps when appropriate
111 * * Set user-configurable properties to sane defaults for format and
112 * implementing codec at hand, and convey some subclass capabilities and
113 * expectations in context.
115 * * Accept data in @handle_frame and provide encoded results to
116 * @gst_audio_decoder_finish_frame. If it is prepared to perform
117 * PLC, it should also accept NULL data in @handle_frame and provide for
118 * data for indicated duration.
126 #include "gstaudiodecoder.h"
127 #include "gstaudioutilsprivate.h"
128 #include <gst/pbutils/descriptions.h>
132 GST_DEBUG_CATEGORY (audiodecoder_debug);
133 #define GST_CAT_DEFAULT audiodecoder_debug
148 #define DEFAULT_LATENCY 0
149 #define DEFAULT_TOLERANCE 0
150 #define DEFAULT_PLC FALSE
151 #define DEFAULT_DRAINABLE TRUE
152 #define DEFAULT_NEEDS_FORMAT FALSE
154 typedef struct _GstAudioDecoderContext
156 /* last negotiated input caps */
159 /* (output) audio format */
162 gboolean output_format_changed;
168 gboolean had_output_data;
169 gboolean had_input_data;
176 gboolean do_estimate_rate;
178 GstCaps *allocation_caps;
179 /* MT-protected (with LOCK) */
180 GstClockTime min_latency;
181 GstClockTime max_latency;
183 GstAllocator *allocator;
184 GstAllocationParams params;
185 } GstAudioDecoderContext;
187 struct _GstAudioDecoderPrivate
189 /* activation status */
192 /* input base/first ts as basis for output ts */
193 GstClockTime base_ts;
194 /* input samples processed and sent downstream so far (w.r.t. base_ts) */
197 /* collected input data */
199 /* tracking input ts for changes */
200 GstClockTime prev_ts;
201 guint64 prev_distance;
202 /* frames obtained from input */
204 /* collected output data */
205 GstAdapter *adapter_out;
206 /* ts and duration for output data collected above */
207 GstClockTime out_ts, out_dur;
208 /* mark outgoing discont */
211 /* subclass gave all it could already */
213 /* subclass currently being forcibly drained */
215 /* input_segment are output_segment identical */
216 gboolean in_out_segment_sync;
217 /* expecting the buffer with DISCONT flag */
218 gboolean expecting_discont_buf;
220 /* number of samples pushed out via _finish_subframe(), resets on _finish_frame() */
221 guint subframe_samples;
223 /* input bps estimatation */
224 /* global in bytes seen */
226 /* global samples sent out */
228 /* bytes flushed during parsing */
233 /* upstream stream tags (global tags are passed through as-is) */
234 GstTagList *upstream_tags;
237 GstTagList *taglist; /* FIXME: rename to decoder_tags */
238 GstTagMergeMode decoder_tags_merge_mode;
240 gboolean taglist_changed; /* FIXME: rename to tags_changed */
242 /* whether circumstances allow output aggregation */
245 /* reverse playback queues */
250 /* reversed output */
253 /* context storage */
254 GstAudioDecoderContext ctx;
257 GstClockTime latency;
258 GstClockTime tolerance;
261 gboolean needs_format;
263 /* pending serialized sink events, will be sent from finish_frame() */
264 GList *pending_events;
267 gboolean use_default_pad_acceptcaps;
270 static void gst_audio_decoder_finalize (GObject * object);
271 static void gst_audio_decoder_set_property (GObject * object,
272 guint prop_id, const GValue * value, GParamSpec * pspec);
273 static void gst_audio_decoder_get_property (GObject * object,
274 guint prop_id, GValue * value, GParamSpec * pspec);
276 static void gst_audio_decoder_clear_queues (GstAudioDecoder * dec);
277 static GstFlowReturn gst_audio_decoder_chain_reverse (GstAudioDecoder *
278 dec, GstBuffer * buf);
280 static GstStateChangeReturn gst_audio_decoder_change_state (GstElement *
281 element, GstStateChange transition);
282 static gboolean gst_audio_decoder_sink_eventfunc (GstAudioDecoder * dec,
284 static gboolean gst_audio_decoder_src_eventfunc (GstAudioDecoder * dec,
286 static gboolean gst_audio_decoder_sink_event (GstPad * pad, GstObject * parent,
288 static gboolean gst_audio_decoder_src_event (GstPad * pad, GstObject * parent,
290 static gboolean gst_audio_decoder_sink_setcaps (GstAudioDecoder * dec,
292 static GstFlowReturn gst_audio_decoder_chain (GstPad * pad, GstObject * parent,
294 static gboolean gst_audio_decoder_src_query (GstPad * pad, GstObject * parent,
296 static gboolean gst_audio_decoder_sink_query (GstPad * pad, GstObject * parent,
298 static void gst_audio_decoder_reset (GstAudioDecoder * dec, gboolean full);
300 static gboolean gst_audio_decoder_decide_allocation_default (GstAudioDecoder *
301 dec, GstQuery * query);
302 static gboolean gst_audio_decoder_propose_allocation_default (GstAudioDecoder *
303 dec, GstQuery * query);
304 static gboolean gst_audio_decoder_negotiate_default (GstAudioDecoder * dec);
305 static gboolean gst_audio_decoder_negotiate_unlocked (GstAudioDecoder * dec);
306 static gboolean gst_audio_decoder_handle_gap (GstAudioDecoder * dec,
308 static gboolean gst_audio_decoder_sink_query_default (GstAudioDecoder * dec,
310 static gboolean gst_audio_decoder_src_query_default (GstAudioDecoder * dec,
313 static gboolean gst_audio_decoder_transform_meta_default (GstAudioDecoder *
314 decoder, GstBuffer * outbuf, GstMeta * meta, GstBuffer * inbuf);
317 gst_audio_decoder_finish_frame_or_subframe (GstAudioDecoder * dec,
318 GstBuffer * buf, gint frames);
320 static GstElementClass *parent_class = NULL;
321 static gint private_offset = 0;
323 static void gst_audio_decoder_class_init (GstAudioDecoderClass * klass);
324 static void gst_audio_decoder_init (GstAudioDecoder * dec,
325 GstAudioDecoderClass * klass);
328 gst_audio_decoder_get_type (void)
330 static volatile gsize audio_decoder_type = 0;
332 if (g_once_init_enter (&audio_decoder_type)) {
334 static const GTypeInfo audio_decoder_info = {
335 sizeof (GstAudioDecoderClass),
338 (GClassInitFunc) gst_audio_decoder_class_init,
341 sizeof (GstAudioDecoder),
343 (GInstanceInitFunc) gst_audio_decoder_init,
346 _type = g_type_register_static (GST_TYPE_ELEMENT,
347 "GstAudioDecoder", &audio_decoder_info, G_TYPE_FLAG_ABSTRACT);
350 g_type_add_instance_private (_type, sizeof (GstAudioDecoderPrivate));
352 g_once_init_leave (&audio_decoder_type, _type);
354 return audio_decoder_type;
357 static inline GstAudioDecoderPrivate *
358 gst_audio_decoder_get_instance_private (GstAudioDecoder * self)
360 return (G_STRUCT_MEMBER_P (self, private_offset));
364 gst_audio_decoder_class_init (GstAudioDecoderClass * klass)
366 GObjectClass *gobject_class;
367 GstElementClass *element_class;
368 GstAudioDecoderClass *audiodecoder_class;
370 gobject_class = G_OBJECT_CLASS (klass);
371 element_class = GST_ELEMENT_CLASS (klass);
372 audiodecoder_class = GST_AUDIO_DECODER_CLASS (klass);
374 parent_class = g_type_class_peek_parent (klass);
376 if (private_offset != 0)
377 g_type_class_adjust_private_offset (klass, &private_offset);
379 GST_DEBUG_CATEGORY_INIT (audiodecoder_debug, "audiodecoder", 0,
380 "audio decoder base class");
382 gobject_class->set_property = gst_audio_decoder_set_property;
383 gobject_class->get_property = gst_audio_decoder_get_property;
384 gobject_class->finalize = gst_audio_decoder_finalize;
386 element_class->change_state =
387 GST_DEBUG_FUNCPTR (gst_audio_decoder_change_state);
390 g_object_class_install_property (gobject_class, PROP_LATENCY,
391 g_param_spec_int64 ("min-latency", "Minimum Latency",
392 "Aggregate output data to a minimum of latency time (ns)",
393 0, G_MAXINT64, DEFAULT_LATENCY,
394 G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
396 g_object_class_install_property (gobject_class, PROP_TOLERANCE,
397 g_param_spec_int64 ("tolerance", "Tolerance",
398 "Perfect ts while timestamp jitter/imperfection within tolerance (ns)",
399 0, G_MAXINT64, DEFAULT_TOLERANCE,
400 G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
402 g_object_class_install_property (gobject_class, PROP_PLC,
403 g_param_spec_boolean ("plc", "Packet Loss Concealment",
404 "Perform packet loss concealment (if supported)",
405 DEFAULT_PLC, G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
407 audiodecoder_class->sink_event =
408 GST_DEBUG_FUNCPTR (gst_audio_decoder_sink_eventfunc);
409 audiodecoder_class->src_event =
410 GST_DEBUG_FUNCPTR (gst_audio_decoder_src_eventfunc);
411 audiodecoder_class->propose_allocation =
412 GST_DEBUG_FUNCPTR (gst_audio_decoder_propose_allocation_default);
413 audiodecoder_class->decide_allocation =
414 GST_DEBUG_FUNCPTR (gst_audio_decoder_decide_allocation_default);
415 audiodecoder_class->negotiate =
416 GST_DEBUG_FUNCPTR (gst_audio_decoder_negotiate_default);
417 audiodecoder_class->sink_query =
418 GST_DEBUG_FUNCPTR (gst_audio_decoder_sink_query_default);
419 audiodecoder_class->src_query =
420 GST_DEBUG_FUNCPTR (gst_audio_decoder_src_query_default);
421 audiodecoder_class->transform_meta =
422 GST_DEBUG_FUNCPTR (gst_audio_decoder_transform_meta_default);
426 gst_audio_decoder_init (GstAudioDecoder * dec, GstAudioDecoderClass * klass)
428 GstPadTemplate *pad_template;
430 GST_DEBUG_OBJECT (dec, "gst_audio_decoder_init");
432 dec->priv = gst_audio_decoder_get_instance_private (dec);
436 gst_element_class_get_pad_template (GST_ELEMENT_CLASS (klass), "sink");
437 g_return_if_fail (pad_template != NULL);
439 dec->sinkpad = gst_pad_new_from_template (pad_template, "sink");
440 gst_pad_set_event_function (dec->sinkpad,
441 GST_DEBUG_FUNCPTR (gst_audio_decoder_sink_event));
442 gst_pad_set_chain_function (dec->sinkpad,
443 GST_DEBUG_FUNCPTR (gst_audio_decoder_chain));
444 gst_pad_set_query_function (dec->sinkpad,
445 GST_DEBUG_FUNCPTR (gst_audio_decoder_sink_query));
446 gst_element_add_pad (GST_ELEMENT (dec), dec->sinkpad);
447 GST_DEBUG_OBJECT (dec, "sinkpad created");
449 /* Setup source pad */
451 gst_element_class_get_pad_template (GST_ELEMENT_CLASS (klass), "src");
452 g_return_if_fail (pad_template != NULL);
454 dec->srcpad = gst_pad_new_from_template (pad_template, "src");
455 gst_pad_set_event_function (dec->srcpad,
456 GST_DEBUG_FUNCPTR (gst_audio_decoder_src_event));
457 gst_pad_set_query_function (dec->srcpad,
458 GST_DEBUG_FUNCPTR (gst_audio_decoder_src_query));
459 gst_element_add_pad (GST_ELEMENT (dec), dec->srcpad);
460 GST_DEBUG_OBJECT (dec, "srcpad created");
462 dec->priv->adapter = gst_adapter_new ();
463 dec->priv->adapter_out = gst_adapter_new ();
464 g_queue_init (&dec->priv->frames);
466 g_rec_mutex_init (&dec->stream_lock);
468 /* property default */
469 dec->priv->latency = DEFAULT_LATENCY;
470 dec->priv->tolerance = DEFAULT_TOLERANCE;
471 dec->priv->plc = DEFAULT_PLC;
472 dec->priv->drainable = DEFAULT_DRAINABLE;
473 dec->priv->needs_format = DEFAULT_NEEDS_FORMAT;
476 dec->priv->ctx.min_latency = 0;
477 dec->priv->ctx.max_latency = 0;
478 gst_audio_decoder_reset (dec, TRUE);
479 GST_DEBUG_OBJECT (dec, "init ok");
483 gst_audio_decoder_reset (GstAudioDecoder * dec, gboolean full)
485 GST_DEBUG_OBJECT (dec, "gst_audio_decoder_reset");
487 GST_AUDIO_DECODER_STREAM_LOCK (dec);
490 dec->priv->active = FALSE;
491 GST_OBJECT_LOCK (dec);
492 dec->priv->bytes_in = 0;
493 dec->priv->samples_out = 0;
494 GST_OBJECT_UNLOCK (dec);
496 dec->priv->error_count = 0;
497 gst_audio_decoder_clear_queues (dec);
499 if (dec->priv->taglist) {
500 gst_tag_list_unref (dec->priv->taglist);
501 dec->priv->taglist = NULL;
503 dec->priv->decoder_tags_merge_mode = GST_TAG_MERGE_KEEP_ALL;
504 if (dec->priv->upstream_tags) {
505 gst_tag_list_unref (dec->priv->upstream_tags);
506 dec->priv->upstream_tags = NULL;
508 dec->priv->taglist_changed = FALSE;
510 gst_segment_init (&dec->input_segment, GST_FORMAT_TIME);
511 gst_segment_init (&dec->output_segment, GST_FORMAT_TIME);
512 dec->priv->in_out_segment_sync = TRUE;
514 g_list_foreach (dec->priv->pending_events, (GFunc) gst_event_unref, NULL);
515 g_list_free (dec->priv->pending_events);
516 dec->priv->pending_events = NULL;
518 if (dec->priv->ctx.allocator)
519 gst_object_unref (dec->priv->ctx.allocator);
521 GST_OBJECT_LOCK (dec);
522 gst_caps_replace (&dec->priv->ctx.input_caps, NULL);
523 gst_caps_replace (&dec->priv->ctx.caps, NULL);
524 gst_caps_replace (&dec->priv->ctx.allocation_caps, NULL);
526 memset (&dec->priv->ctx, 0, sizeof (dec->priv->ctx));
528 gst_audio_info_init (&dec->priv->ctx.info);
529 GST_OBJECT_UNLOCK (dec);
530 dec->priv->ctx.max_errors = GST_AUDIO_DECODER_MAX_ERRORS;
531 dec->priv->ctx.had_output_data = FALSE;
532 dec->priv->ctx.had_input_data = FALSE;
535 g_queue_foreach (&dec->priv->frames, (GFunc) gst_buffer_unref, NULL);
536 g_queue_clear (&dec->priv->frames);
537 gst_adapter_clear (dec->priv->adapter);
538 gst_adapter_clear (dec->priv->adapter_out);
539 dec->priv->out_ts = GST_CLOCK_TIME_NONE;
540 dec->priv->out_dur = 0;
541 dec->priv->prev_ts = GST_CLOCK_TIME_NONE;
542 dec->priv->prev_distance = 0;
543 dec->priv->drained = TRUE;
544 dec->priv->base_ts = GST_CLOCK_TIME_NONE;
545 dec->priv->samples = 0;
546 dec->priv->discont = TRUE;
547 dec->priv->sync_flush = FALSE;
549 GST_AUDIO_DECODER_STREAM_UNLOCK (dec);
553 gst_audio_decoder_finalize (GObject * object)
555 GstAudioDecoder *dec;
557 g_return_if_fail (GST_IS_AUDIO_DECODER (object));
558 dec = GST_AUDIO_DECODER (object);
560 if (dec->priv->adapter) {
561 g_object_unref (dec->priv->adapter);
563 if (dec->priv->adapter_out) {
564 g_object_unref (dec->priv->adapter_out);
567 g_rec_mutex_clear (&dec->stream_lock);
569 G_OBJECT_CLASS (parent_class)->finalize (object);
573 gst_audio_decoder_create_merged_tags_event (GstAudioDecoder * dec)
575 GstTagList *merged_tags;
577 GST_LOG_OBJECT (dec, "upstream : %" GST_PTR_FORMAT, dec->priv->upstream_tags);
578 GST_LOG_OBJECT (dec, "decoder : %" GST_PTR_FORMAT, dec->priv->taglist);
579 GST_LOG_OBJECT (dec, "mode : %d", dec->priv->decoder_tags_merge_mode);
582 gst_tag_list_merge (dec->priv->upstream_tags,
583 dec->priv->taglist, dec->priv->decoder_tags_merge_mode);
585 GST_DEBUG_OBJECT (dec, "merged : %" GST_PTR_FORMAT, merged_tags);
587 if (merged_tags == NULL)
590 if (gst_tag_list_is_empty (merged_tags)) {
591 gst_tag_list_unref (merged_tags);
595 return gst_event_new_tag (merged_tags);
599 gst_audio_decoder_push_event (GstAudioDecoder * dec, GstEvent * event)
601 switch (GST_EVENT_TYPE (event)) {
602 case GST_EVENT_SEGMENT:{
605 GST_AUDIO_DECODER_STREAM_LOCK (dec);
606 gst_event_copy_segment (event, &seg);
608 GST_DEBUG_OBJECT (dec, "starting segment %" GST_SEGMENT_FORMAT, &seg);
610 dec->output_segment = seg;
611 dec->priv->in_out_segment_sync =
612 gst_segment_is_equal (&dec->input_segment, &seg);
613 GST_AUDIO_DECODER_STREAM_UNLOCK (dec);
620 return gst_pad_push_event (dec->srcpad, event);
624 gst_audio_decoder_negotiate_default (GstAudioDecoder * dec)
626 GstAudioDecoderClass *klass;
630 GstQuery *query = NULL;
631 GstAllocator *allocator;
632 GstAllocationParams params;
634 g_return_val_if_fail (GST_IS_AUDIO_DECODER (dec), FALSE);
635 g_return_val_if_fail (GST_AUDIO_INFO_IS_VALID (&dec->priv->ctx.info), FALSE);
636 g_return_val_if_fail (GST_IS_CAPS (dec->priv->ctx.caps), FALSE);
638 klass = GST_AUDIO_DECODER_GET_CLASS (dec);
640 caps = dec->priv->ctx.caps;
641 if (dec->priv->ctx.allocation_caps == NULL)
642 dec->priv->ctx.allocation_caps = gst_caps_ref (caps);
644 GST_DEBUG_OBJECT (dec, "setting src caps %" GST_PTR_FORMAT, caps);
646 if (dec->priv->pending_events) {
647 GList **pending_events, *l;
649 pending_events = &dec->priv->pending_events;
651 GST_DEBUG_OBJECT (dec, "Pushing pending events");
652 for (l = *pending_events; l;) {
653 GstEvent *event = GST_EVENT (l->data);
656 if (GST_EVENT_TYPE (event) < GST_EVENT_CAPS) {
657 gst_audio_decoder_push_event (dec, l->data);
660 *pending_events = g_list_delete_link (*pending_events, tmp);
667 prevcaps = gst_pad_get_current_caps (dec->srcpad);
668 if (!prevcaps || !gst_caps_is_equal (prevcaps, caps))
669 res = gst_pad_set_caps (dec->srcpad, caps);
671 gst_caps_unref (prevcaps);
675 dec->priv->ctx.output_format_changed = FALSE;
677 query = gst_query_new_allocation (dec->priv->ctx.allocation_caps, TRUE);
678 if (!gst_pad_peer_query (dec->srcpad, query)) {
679 GST_DEBUG_OBJECT (dec, "didn't get downstream ALLOCATION hints");
682 g_assert (klass->decide_allocation != NULL);
683 res = klass->decide_allocation (dec, query);
685 GST_DEBUG_OBJECT (dec, "ALLOCATION (%d) params: %" GST_PTR_FORMAT, res,
689 goto no_decide_allocation;
691 /* we got configuration from our peer or the decide_allocation method,
693 if (gst_query_get_n_allocation_params (query) > 0) {
694 gst_query_parse_nth_allocation_param (query, 0, &allocator, ¶ms);
697 gst_allocation_params_init (¶ms);
700 if (dec->priv->ctx.allocator)
701 gst_object_unref (dec->priv->ctx.allocator);
702 dec->priv->ctx.allocator = allocator;
703 dec->priv->ctx.params = params;
708 gst_query_unref (query);
713 no_decide_allocation:
715 GST_WARNING_OBJECT (dec, "Subclass failed to decide allocation");
721 gst_audio_decoder_negotiate_unlocked (GstAudioDecoder * dec)
723 GstAudioDecoderClass *klass = GST_AUDIO_DECODER_GET_CLASS (dec);
726 if (G_LIKELY (klass->negotiate))
727 ret = klass->negotiate (dec);
733 * gst_audio_decoder_negotiate:
734 * @dec: a #GstAudioDecoder
736 * Negotiate with downstream elements to currently configured #GstAudioInfo.
737 * Unmark GST_PAD_FLAG_NEED_RECONFIGURE in any case. But mark it again if
740 * Returns: %TRUE if the negotiation succeeded, else %FALSE.
743 gst_audio_decoder_negotiate (GstAudioDecoder * dec)
745 GstAudioDecoderClass *klass;
748 g_return_val_if_fail (GST_IS_AUDIO_DECODER (dec), FALSE);
750 klass = GST_AUDIO_DECODER_GET_CLASS (dec);
752 GST_AUDIO_DECODER_STREAM_LOCK (dec);
753 gst_pad_check_reconfigure (dec->srcpad);
754 if (klass->negotiate) {
755 res = klass->negotiate (dec);
757 gst_pad_mark_reconfigure (dec->srcpad);
759 GST_AUDIO_DECODER_STREAM_UNLOCK (dec);
765 * gst_audio_decoder_set_output_format:
766 * @dec: a #GstAudioDecoder
767 * @info: #GstAudioInfo
769 * Configure output info on the srcpad of @dec.
771 * Returns: %TRUE on success.
774 gst_audio_decoder_set_output_format (GstAudioDecoder * dec,
775 const GstAudioInfo * info)
778 GstCaps *caps = NULL;
780 g_return_val_if_fail (GST_IS_AUDIO_DECODER (dec), FALSE);
781 g_return_val_if_fail (GST_AUDIO_INFO_IS_VALID (info), FALSE);
783 /* If the audio info can't be converted to caps,
785 caps = gst_audio_info_to_caps (info);
787 GST_WARNING_OBJECT (dec, "invalid output format");
791 res = gst_audio_decoder_set_output_caps (dec, caps);
792 gst_caps_unref (caps);
798 * gst_audio_decoder_set_output_caps:
799 * @dec: a #GstAudioDecoder
800 * @caps: (transfer none): (fixed) #GstCaps
802 * Configure output caps on the srcpad of @dec. Similar to
803 * gst_audio_decoder_set_output_format(), but allows subclasses to specify
804 * output caps that can't be expressed via #GstAudioInfo e.g. caps that have
807 * Returns: %TRUE on success.
812 gst_audio_decoder_set_output_caps (GstAudioDecoder * dec, GstCaps * caps)
819 g_return_val_if_fail (GST_IS_AUDIO_DECODER (dec), FALSE);
821 GST_DEBUG_OBJECT (dec, "Setting srcpad caps %" GST_PTR_FORMAT, caps);
823 GST_AUDIO_DECODER_STREAM_LOCK (dec);
825 if (!gst_caps_is_fixed (caps))
828 /* check if caps can be parsed */
829 if (!gst_audio_info_from_caps (&info, caps))
832 /* Only allow caps that are a subset of the template caps */
833 templ_caps = gst_pad_get_pad_template_caps (dec->srcpad);
834 if (!gst_caps_is_subset (caps, templ_caps)) {
835 GST_WARNING_OBJECT (dec, "Requested output format %" GST_PTR_FORMAT
836 " do not match template %" GST_PTR_FORMAT, caps, templ_caps);
837 gst_caps_unref (templ_caps);
840 gst_caps_unref (templ_caps);
842 /* adjust ts tracking to new sample rate */
843 old_rate = GST_AUDIO_INFO_RATE (&dec->priv->ctx.info);
844 if (GST_CLOCK_TIME_IS_VALID (dec->priv->base_ts) && old_rate) {
845 dec->priv->base_ts +=
846 GST_FRAMES_TO_CLOCK_TIME (dec->priv->samples, old_rate);
847 dec->priv->samples = 0;
850 /* copy the GstAudioInfo */
851 GST_OBJECT_LOCK (dec);
852 dec->priv->ctx.info = info;
853 GST_OBJECT_UNLOCK (dec);
855 gst_caps_replace (&dec->priv->ctx.caps, caps);
856 dec->priv->ctx.output_format_changed = TRUE;
859 GST_AUDIO_DECODER_STREAM_UNLOCK (dec);
866 GST_WARNING_OBJECT (dec, "invalid output format");
873 gst_audio_decoder_sink_setcaps (GstAudioDecoder * dec, GstCaps * caps)
875 GstAudioDecoderClass *klass;
878 klass = GST_AUDIO_DECODER_GET_CLASS (dec);
880 GST_DEBUG_OBJECT (dec, "caps: %" GST_PTR_FORMAT, caps);
882 GST_AUDIO_DECODER_STREAM_LOCK (dec);
884 if (dec->priv->ctx.input_caps
885 && gst_caps_is_equal (dec->priv->ctx.input_caps, caps)) {
886 GST_DEBUG_OBJECT (dec, "Caps did not change, not setting again");
890 /* NOTE pbutils only needed here */
891 /* TODO maybe (only) upstream demuxer/parser etc should handle this ? */
893 if (!dec->priv->taglist)
894 dec->priv->taglist = gst_tag_list_new ();
895 dec->priv->taglist = gst_tag_list_make_writable (dec->priv->taglist);
896 gst_pb_utils_add_codec_description_to_tag_list (dec->priv->taglist,
897 GST_TAG_AUDIO_CODEC, caps);
898 dec->priv->taglist_changed = TRUE;
901 if (klass->set_format)
902 res = klass->set_format (dec, caps);
905 gst_caps_replace (&dec->priv->ctx.input_caps, caps);
908 GST_AUDIO_DECODER_STREAM_UNLOCK (dec);
914 gst_audio_decoder_setup (GstAudioDecoder * dec)
919 /* check if in live pipeline, then latency messing is no-no */
920 query = gst_query_new_latency ();
921 res = gst_pad_peer_query (dec->sinkpad, query);
923 gst_query_parse_latency (query, &res, NULL, NULL);
926 gst_query_unref (query);
928 /* normalize to bool */
929 dec->priv->agg = ! !res;
933 gst_audio_decoder_push_forward (GstAudioDecoder * dec, GstBuffer * buf)
935 GstAudioDecoderClass *klass;
936 GstAudioDecoderPrivate *priv;
937 GstAudioDecoderContext *ctx;
938 GstFlowReturn ret = GST_FLOW_OK;
941 klass = GST_AUDIO_DECODER_GET_CLASS (dec);
943 ctx = &dec->priv->ctx;
945 g_return_val_if_fail (ctx->info.bpf != 0, GST_FLOW_ERROR);
947 if (G_UNLIKELY (!buf)) {
948 g_assert_not_reached ();
952 ctx->had_output_data = TRUE;
953 ts = GST_BUFFER_TIMESTAMP (buf);
956 "clipping buffer of size %" G_GSIZE_FORMAT " with ts %" GST_TIME_FORMAT
957 ", duration %" GST_TIME_FORMAT, gst_buffer_get_size (buf),
958 GST_TIME_ARGS (GST_BUFFER_TIMESTAMP (buf)),
959 GST_TIME_ARGS (GST_BUFFER_DURATION (buf)));
962 buf = gst_audio_buffer_clip (buf, &dec->output_segment, ctx->info.rate,
964 if (G_UNLIKELY (!buf)) {
965 GST_DEBUG_OBJECT (dec, "no data after clipping to segment");
966 /* only check and return EOS if upstream still
967 * in the same segment and interested as such */
968 if (dec->priv->in_out_segment_sync) {
969 if (dec->output_segment.rate >= 0) {
970 if (ts >= dec->output_segment.stop)
972 } else if (ts < dec->output_segment.start) {
980 if (G_UNLIKELY (priv->discont)) {
981 GST_LOG_OBJECT (dec, "marking discont");
982 GST_BUFFER_FLAG_SET (buf, GST_BUFFER_FLAG_DISCONT);
983 priv->discont = FALSE;
986 /* track where we are */
987 if (G_LIKELY (GST_BUFFER_TIMESTAMP_IS_VALID (buf))) {
988 /* duration should always be valid for raw audio */
989 g_assert (GST_BUFFER_DURATION_IS_VALID (buf));
990 dec->output_segment.position =
991 GST_BUFFER_TIMESTAMP (buf) + GST_BUFFER_DURATION (buf);
994 if (klass->pre_push) {
995 /* last chance for subclass to do some dirty stuff */
996 ret = klass->pre_push (dec, &buf);
997 if (ret != GST_FLOW_OK || !buf) {
998 GST_DEBUG_OBJECT (dec, "subclass returned %s, buf %p",
999 gst_flow_get_name (ret), buf);
1001 gst_buffer_unref (buf);
1006 GST_LOG_OBJECT (dec,
1007 "pushing buffer of size %" G_GSIZE_FORMAT " with ts %" GST_TIME_FORMAT
1008 ", duration %" GST_TIME_FORMAT, gst_buffer_get_size (buf),
1009 GST_TIME_ARGS (GST_BUFFER_TIMESTAMP (buf)),
1010 GST_TIME_ARGS (GST_BUFFER_DURATION (buf)));
1012 ret = gst_pad_push (dec->srcpad, buf);
1018 /* mini aggregator combining output buffers into fewer larger ones,
1019 * if so allowed/configured */
1020 static GstFlowReturn
1021 gst_audio_decoder_output (GstAudioDecoder * dec, GstBuffer * buf)
1023 GstAudioDecoderPrivate *priv;
1024 GstFlowReturn ret = GST_FLOW_OK;
1025 GstBuffer *inbuf = NULL;
1029 if (G_UNLIKELY (priv->agg < 0))
1030 gst_audio_decoder_setup (dec);
1032 if (G_LIKELY (buf)) {
1033 GST_LOG_OBJECT (dec,
1034 "output buffer of size %" G_GSIZE_FORMAT " with ts %" GST_TIME_FORMAT
1035 ", duration %" GST_TIME_FORMAT, gst_buffer_get_size (buf),
1036 GST_TIME_ARGS (GST_BUFFER_TIMESTAMP (buf)),
1037 GST_TIME_ARGS (GST_BUFFER_DURATION (buf)));
1042 if (priv->agg && dec->priv->latency > 0 &&
1043 priv->ctx.info.layout == GST_AUDIO_LAYOUT_INTERLEAVED) {
1045 gboolean assemble = FALSE;
1046 const GstClockTimeDiff tol = 10 * GST_MSECOND;
1047 GstClockTimeDiff diff = -100 * GST_MSECOND;
1049 av = gst_adapter_available (priv->adapter_out);
1050 if (G_UNLIKELY (!buf)) {
1051 /* forcibly send current */
1053 GST_LOG_OBJECT (dec, "forcing fragment flush");
1054 } else if (av && (!GST_BUFFER_TIMESTAMP_IS_VALID (buf) ||
1055 !GST_CLOCK_TIME_IS_VALID (priv->out_ts) ||
1056 ((diff = GST_CLOCK_DIFF (GST_BUFFER_TIMESTAMP (buf),
1057 priv->out_ts + priv->out_dur)) > tol) || diff < -tol)) {
1059 GST_LOG_OBJECT (dec, "buffer %d ms apart from current fragment",
1060 (gint) (diff / GST_MSECOND));
1062 /* add or start collecting */
1064 GST_LOG_OBJECT (dec, "starting new fragment");
1065 priv->out_ts = GST_BUFFER_TIMESTAMP (buf);
1067 GST_LOG_OBJECT (dec, "adding to fragment");
1069 gst_adapter_push (priv->adapter_out, buf);
1070 priv->out_dur += GST_BUFFER_DURATION (buf);
1071 av += gst_buffer_get_size (buf);
1074 if (priv->out_dur > dec->priv->latency)
1076 if (av && assemble) {
1077 GST_LOG_OBJECT (dec, "assembling fragment");
1079 buf = gst_adapter_take_buffer (priv->adapter_out, av);
1080 GST_BUFFER_TIMESTAMP (buf) = priv->out_ts;
1081 GST_BUFFER_DURATION (buf) = priv->out_dur;
1082 priv->out_ts = GST_CLOCK_TIME_NONE;
1087 if (G_LIKELY (buf)) {
1088 if (dec->output_segment.rate > 0.0) {
1089 ret = gst_audio_decoder_push_forward (dec, buf);
1090 GST_LOG_OBJECT (dec, "buffer pushed: %s", gst_flow_get_name (ret));
1093 priv->queued = g_list_prepend (priv->queued, buf);
1094 GST_LOG_OBJECT (dec, "buffer queued");
1107 send_pending_events (GstAudioDecoder * dec)
1109 GstAudioDecoderPrivate *priv = dec->priv;
1110 GList *pending_events, *l;
1112 pending_events = priv->pending_events;
1113 priv->pending_events = NULL;
1115 GST_DEBUG_OBJECT (dec, "Pushing pending events");
1116 for (l = pending_events; l; l = l->next)
1117 gst_audio_decoder_push_event (dec, l->data);
1118 g_list_free (pending_events);
1121 /* Iterate the list of pending events, and ensure
1122 * the current output segment is up to date for
1125 apply_pending_events (GstAudioDecoder * dec)
1127 GstAudioDecoderPrivate *priv = dec->priv;
1130 GST_DEBUG_OBJECT (dec, "Applying pending segments");
1131 for (l = priv->pending_events; l; l = l->next) {
1132 GstEvent *event = GST_EVENT (l->data);
1133 switch (GST_EVENT_TYPE (event)) {
1134 case GST_EVENT_SEGMENT:{
1137 GST_AUDIO_DECODER_STREAM_LOCK (dec);
1138 gst_event_copy_segment (event, &seg);
1140 GST_DEBUG_OBJECT (dec, "starting segment %" GST_SEGMENT_FORMAT, &seg);
1142 dec->output_segment = seg;
1143 dec->priv->in_out_segment_sync =
1144 gst_segment_is_equal (&dec->input_segment, &seg);
1145 GST_AUDIO_DECODER_STREAM_UNLOCK (dec);
1154 static GstFlowReturn
1155 check_pending_reconfigure (GstAudioDecoder * dec)
1157 GstFlowReturn ret = GST_FLOW_OK;
1158 GstAudioDecoderContext *ctx;
1159 gboolean needs_reconfigure;
1161 ctx = &dec->priv->ctx;
1163 needs_reconfigure = gst_pad_check_reconfigure (dec->srcpad);
1164 if (G_UNLIKELY (ctx->output_format_changed ||
1165 (GST_AUDIO_INFO_IS_VALID (&ctx->info)
1166 && needs_reconfigure))) {
1167 if (!gst_audio_decoder_negotiate_unlocked (dec)) {
1168 gst_pad_mark_reconfigure (dec->srcpad);
1169 if (GST_PAD_IS_FLUSHING (dec->srcpad))
1170 ret = GST_FLOW_FLUSHING;
1172 ret = GST_FLOW_NOT_NEGOTIATED;
1179 gst_audio_decoder_transform_meta_default (GstAudioDecoder *
1180 decoder, GstBuffer * outbuf, GstMeta * meta, GstBuffer * inbuf)
1182 const GstMetaInfo *info = meta->info;
1183 const gchar *const *tags;
1185 tags = gst_meta_api_type_get_tags (info->api);
1187 if (!tags || (g_strv_length ((gchar **) tags) == 1
1188 && gst_meta_api_type_has_tag (info->api,
1189 g_quark_from_string (GST_META_TAG_AUDIO_STR))))
1197 GstAudioDecoder *decoder;
1202 foreach_metadata (GstBuffer * inbuf, GstMeta ** meta, gpointer user_data)
1204 CopyMetaData *data = user_data;
1205 GstAudioDecoder *decoder = data->decoder;
1206 GstAudioDecoderClass *klass = GST_AUDIO_DECODER_GET_CLASS (decoder);
1207 GstBuffer *outbuf = data->outbuf;
1208 const GstMetaInfo *info = (*meta)->info;
1209 gboolean do_copy = FALSE;
1211 if (gst_meta_api_type_has_tag (info->api, _gst_meta_tag_memory)) {
1212 /* never call the transform_meta with memory specific metadata */
1213 GST_DEBUG_OBJECT (decoder, "not copying memory specific metadata %s",
1214 g_type_name (info->api));
1216 } else if (klass->transform_meta) {
1217 do_copy = klass->transform_meta (decoder, outbuf, *meta, inbuf);
1218 GST_DEBUG_OBJECT (decoder, "transformed metadata %s: copy: %d",
1219 g_type_name (info->api), do_copy);
1222 /* we only copy metadata when the subclass implemented a transform_meta
1223 * function and when it returns %TRUE */
1224 if (do_copy && info->transform_func) {
1225 GstMetaTransformCopy copy_data = { FALSE, 0, -1 };
1226 GST_DEBUG_OBJECT (decoder, "copy metadata %s", g_type_name (info->api));
1227 /* simply copy then */
1228 info->transform_func (outbuf, *meta, inbuf,
1229 _gst_meta_transform_copy, ©_data);
1235 * gst_audio_decoder_finish_subframe:
1236 * @dec: a #GstAudioDecoder
1237 * @buf: decoded data
1239 * Collects decoded data and pushes it downstream. This function may be called
1240 * multiple times for a given input frame.
1242 * @buf may be NULL in which case it is assumed that the current input frame is
1243 * finished. This is equivalent to calling gst_audio_decoder_finish_subframe()
1244 * with a NULL buffer and frames=1 after having pushed out all decoded audio
1245 * subframes using this function.
1247 * When called with valid data in @buf the source pad caps must have been set
1250 * Note that a frame received in #GstAudioDecoderClass.handle_frame() may be
1251 * invalidated by a call to this function.
1253 * Returns: a #GstFlowReturn that should be escalated to caller (of caller)
1258 gst_audio_decoder_finish_subframe (GstAudioDecoder * dec, GstBuffer * buf)
1260 g_return_val_if_fail (GST_IS_AUDIO_DECODER (dec), GST_FLOW_ERROR);
1263 return gst_audio_decoder_finish_frame_or_subframe (dec, NULL, 1);
1265 return gst_audio_decoder_finish_frame_or_subframe (dec, buf, 0);
1269 * gst_audio_decoder_finish_frame:
1270 * @dec: a #GstAudioDecoder
1271 * @buf: decoded data
1272 * @frames: number of decoded frames represented by decoded data
1274 * Collects decoded data and pushes it downstream.
1276 * @buf may be NULL in which case the indicated number of frames
1277 * are discarded and considered to have produced no output
1278 * (e.g. lead-in or setup frames).
1279 * Otherwise, source pad caps must be set when it is called with valid
1282 * Note that a frame received in #GstAudioDecoderClass.handle_frame() may be
1283 * invalidated by a call to this function.
1285 * Returns: a #GstFlowReturn that should be escalated to caller (of caller)
1288 gst_audio_decoder_finish_frame (GstAudioDecoder * dec, GstBuffer * buf,
1291 g_return_val_if_fail (GST_IS_AUDIO_DECODER (dec), GST_FLOW_ERROR);
1293 /* no dummy calls please */
1294 g_return_val_if_fail (frames != 0, GST_FLOW_ERROR);
1296 return gst_audio_decoder_finish_frame_or_subframe (dec, buf, frames);
1299 /* frames == 0 indicates that this is a sub-frame and further sub-frames may
1300 * follow for the current input frame. */
1301 static GstFlowReturn
1302 gst_audio_decoder_finish_frame_or_subframe (GstAudioDecoder * dec,
1303 GstBuffer * buf, gint frames)
1305 GstAudioDecoderPrivate *priv;
1306 GstAudioDecoderContext *ctx;
1307 GstAudioDecoderClass *klass = GST_AUDIO_DECODER_GET_CLASS (dec);
1309 GstClockTime ts, next_ts;
1310 gsize size, samples = 0;
1311 GstFlowReturn ret = GST_FLOW_OK;
1312 GQueue inbufs = G_QUEUE_INIT;
1313 gboolean is_subframe = (frames == 0);
1314 gboolean do_check_resync;
1316 /* subclass should not hand us no data */
1317 g_return_val_if_fail (buf == NULL || gst_buffer_get_size (buf) > 0,
1320 /* if it's a subframe (frames == 0) we must have a valid buffer */
1321 g_assert (!is_subframe || buf != NULL);
1324 ctx = &dec->priv->ctx;
1325 meta = buf ? gst_buffer_get_audio_meta (buf) : NULL;
1326 size = buf ? gst_buffer_get_size (buf) : 0;
1327 samples = buf ? (meta ? meta->samples : size / ctx->info.bpf) : 0;
1329 /* must know the output format by now */
1330 g_return_val_if_fail (buf == NULL || GST_AUDIO_INFO_IS_VALID (&ctx->info),
1333 GST_LOG_OBJECT (dec,
1334 "accepting %" G_GSIZE_FORMAT " bytes == %" G_GSIZE_FORMAT
1335 " samples for %d frames", buf ? size : 0, samples, frames);
1337 GST_AUDIO_DECODER_STREAM_LOCK (dec);
1339 if (buf != NULL && priv->subframe_samples == 0) {
1340 ret = check_pending_reconfigure (dec);
1341 if (ret == GST_FLOW_FLUSHING || ret == GST_FLOW_NOT_NEGOTIATED) {
1342 gst_buffer_unref (buf);
1346 if (priv->pending_events)
1347 send_pending_events (dec);
1350 /* sanity checking */
1351 if (G_LIKELY (buf && ctx->info.bpf)) {
1352 if (!meta || meta->info.layout == GST_AUDIO_LAYOUT_INTERLEAVED) {
1353 /* output shoud be whole number of sample frames */
1354 if (size % ctx->info.bpf)
1356 /* output should have no additional padding */
1357 if (samples != size / ctx->info.bpf)
1360 /* can't have more samples than what the buffer fits */
1361 if (samples > size / ctx->info.bpf)
1366 /* frame and ts book-keeping */
1367 if (G_UNLIKELY (frames < 0)) {
1368 if (G_UNLIKELY (-frames - 1 > priv->frames.length)) {
1369 GST_ELEMENT_WARNING (dec, STREAM, DECODE,
1370 ("received more decoded frames %d than provided %d", frames,
1371 priv->frames.length), (NULL));
1374 frames = priv->frames.length + frames + 1;
1376 } else if (G_UNLIKELY (frames > priv->frames.length)) {
1377 if (G_LIKELY (!priv->force)) {
1378 GST_ELEMENT_WARNING (dec, STREAM, DECODE,
1379 ("received more decoded frames %d than provided %d", frames,
1380 priv->frames.length), (NULL));
1382 frames = priv->frames.length;
1385 if (G_LIKELY (priv->frames.length))
1386 ts = GST_BUFFER_TIMESTAMP (priv->frames.head->data);
1388 ts = GST_CLOCK_TIME_NONE;
1390 GST_DEBUG_OBJECT (dec, "leading frame ts %" GST_TIME_FORMAT,
1391 GST_TIME_ARGS (ts));
1393 if (is_subframe && priv->frames.length == 0)
1394 goto subframe_without_pending_input_frame;
1396 /* this will be skipped in the is_subframe case because frames will be 0 */
1397 while (priv->frames.length && frames) {
1398 g_queue_push_tail (&inbufs, g_queue_pop_head (&priv->frames));
1399 dec->priv->ctx.delay = dec->priv->frames.length;
1403 if (G_UNLIKELY (!buf))
1407 if (G_UNLIKELY (!GST_CLOCK_TIME_IS_VALID (priv->base_ts))) {
1409 GST_DEBUG_OBJECT (dec, "base_ts now %" GST_TIME_FORMAT, GST_TIME_ARGS (ts));
1412 /* still no valid ts, track the segment one */
1413 if (G_UNLIKELY (!GST_CLOCK_TIME_IS_VALID (priv->base_ts)) &&
1414 dec->output_segment.rate > 0.0) {
1415 priv->base_ts = dec->output_segment.start;
1418 /* only check for resync at the beginning of an input/output frame */
1419 do_check_resync = !is_subframe || priv->subframe_samples == 0;
1421 /* slightly convoluted approach caters for perfect ts if subclass desires. */
1422 if (do_check_resync && GST_CLOCK_TIME_IS_VALID (ts)) {
1423 if (dec->priv->tolerance > 0) {
1424 GstClockTimeDiff diff;
1426 g_assert (GST_CLOCK_TIME_IS_VALID (priv->base_ts));
1427 next_ts = priv->base_ts +
1428 gst_util_uint64_scale (priv->samples, GST_SECOND, ctx->info.rate);
1429 GST_LOG_OBJECT (dec,
1430 "buffer is %" G_GUINT64_FORMAT " samples past base_ts %"
1431 GST_TIME_FORMAT ", expected ts %" GST_TIME_FORMAT, priv->samples,
1432 GST_TIME_ARGS (priv->base_ts), GST_TIME_ARGS (next_ts));
1433 diff = GST_CLOCK_DIFF (next_ts, ts);
1434 GST_LOG_OBJECT (dec, "ts diff %d ms", (gint) (diff / GST_MSECOND));
1435 /* if within tolerance,
1436 * discard buffer ts and carry on producing perfect stream,
1437 * otherwise resync to ts */
1438 if (G_UNLIKELY (diff < (gint64) - dec->priv->tolerance ||
1439 diff > (gint64) dec->priv->tolerance)) {
1440 GST_DEBUG_OBJECT (dec, "base_ts resync");
1445 GST_DEBUG_OBJECT (dec, "base_ts resync");
1451 /* delayed one-shot stuff until confirmed data */
1452 if (priv->taglist && priv->taglist_changed) {
1453 GstEvent *tags_event;
1455 tags_event = gst_audio_decoder_create_merged_tags_event (dec);
1457 if (tags_event != NULL)
1458 gst_audio_decoder_push_event (dec, tags_event);
1460 priv->taglist_changed = FALSE;
1463 buf = gst_buffer_make_writable (buf);
1464 if (G_LIKELY (GST_CLOCK_TIME_IS_VALID (priv->base_ts))) {
1465 GST_BUFFER_TIMESTAMP (buf) =
1467 GST_FRAMES_TO_CLOCK_TIME (priv->samples, ctx->info.rate);
1468 GST_BUFFER_DURATION (buf) = priv->base_ts +
1469 GST_FRAMES_TO_CLOCK_TIME (priv->samples + samples, ctx->info.rate) -
1470 GST_BUFFER_TIMESTAMP (buf);
1472 GST_BUFFER_TIMESTAMP (buf) = GST_CLOCK_TIME_NONE;
1473 GST_BUFFER_DURATION (buf) =
1474 GST_FRAMES_TO_CLOCK_TIME (samples, ctx->info.rate);
1477 if (klass->transform_meta) {
1478 if (inbufs.length) {
1480 for (l = inbufs.head; l; l = l->next) {
1485 gst_buffer_foreach_meta (l->data, foreach_metadata, &data);
1487 } else if (is_subframe) {
1491 /* For subframes we assume a 1:N relationship for now, so we just take
1492 * metas from the first pending input buf */
1493 in_buf = g_queue_peek_head (&priv->frames);
1496 gst_buffer_foreach_meta (in_buf, foreach_metadata, &data);
1498 GST_WARNING_OBJECT (dec,
1499 "Can't copy metadata because input buffers disappeared");
1503 GST_OBJECT_LOCK (dec);
1504 priv->samples += samples;
1505 priv->samples_out += samples;
1506 GST_OBJECT_UNLOCK (dec);
1508 /* we got data, so note things are looking up */
1509 if (G_UNLIKELY (dec->priv->error_count))
1510 dec->priv->error_count = 0;
1512 ret = gst_audio_decoder_output (dec, buf);
1515 g_queue_foreach (&inbufs, (GFunc) gst_buffer_unref, NULL);
1516 g_queue_clear (&inbufs);
1519 dec->priv->subframe_samples += samples;
1521 dec->priv->subframe_samples = 0;
1523 GST_AUDIO_DECODER_STREAM_UNLOCK (dec);
1530 /* arguably more of a programming error? */
1531 GST_ELEMENT_ERROR (dec, STREAM, DECODE, (NULL),
1532 ("buffer size %" G_GSIZE_FORMAT " not a multiple of %d", size,
1534 gst_buffer_unref (buf);
1535 ret = GST_FLOW_ERROR;
1540 /* arguably more of a programming error? */
1541 GST_ELEMENT_ERROR (dec, STREAM, DECODE, (NULL),
1542 ("GstAudioMeta samples (%" G_GSIZE_FORMAT ") are inconsistent with "
1543 "the buffer size and layout (size/bpf = %" G_GSIZE_FORMAT ")",
1544 meta->samples, size / ctx->info.bpf));
1545 gst_buffer_unref (buf);
1546 ret = GST_FLOW_ERROR;
1549 subframe_without_pending_input_frame:
1551 /* arguably more of a programming error? */
1552 GST_ELEMENT_ERROR (dec, STREAM, DECODE, (NULL),
1553 ("Received decoded subframe, but no pending frame"));
1554 gst_buffer_unref (buf);
1555 ret = GST_FLOW_ERROR;
1560 static GstFlowReturn
1561 gst_audio_decoder_handle_frame (GstAudioDecoder * dec,
1562 GstAudioDecoderClass * klass, GstBuffer * buffer)
1564 /* Skip decoding and send a GAP instead if
1565 * GST_SEGMENT_FLAG_TRICKMODE_NO_AUDIO is set and we have timestamps
1566 * FIXME: We only do this for forward playback atm, because reverse
1567 * playback would require accumulating GAP events and pushing them
1568 * out in reverse order as for normal audio samples
1570 if (G_UNLIKELY (dec->input_segment.rate > 0.0
1571 && dec->input_segment.flags & GST_SEGMENT_FLAG_TRICKMODE_NO_AUDIO)) {
1573 GstClockTime ts = GST_BUFFER_PTS (buffer);
1574 if (GST_CLOCK_TIME_IS_VALID (ts)) {
1575 GstEvent *event = gst_event_new_gap (ts, GST_BUFFER_DURATION (buffer));
1577 gst_buffer_unref (buffer);
1578 GST_LOG_OBJECT (dec, "Skipping decode in trickmode and sending gap");
1579 gst_audio_decoder_handle_gap (dec, event);
1585 if (G_LIKELY (buffer)) {
1586 gsize size = gst_buffer_get_size (buffer);
1587 /* keep around for admin */
1588 GST_LOG_OBJECT (dec,
1589 "tracking frame size %" G_GSIZE_FORMAT ", ts %" GST_TIME_FORMAT, size,
1590 GST_TIME_ARGS (GST_BUFFER_TIMESTAMP (buffer)));
1591 g_queue_push_tail (&dec->priv->frames, buffer);
1592 dec->priv->ctx.delay = dec->priv->frames.length;
1593 GST_OBJECT_LOCK (dec);
1594 dec->priv->bytes_in += size;
1595 GST_OBJECT_UNLOCK (dec);
1597 GST_LOG_OBJECT (dec, "providing subclass with NULL frame");
1600 return klass->handle_frame (dec, buffer);
1603 /* maybe subclass configurable instead, but this allows for a whole lot of
1604 * raw samples, so at least quite some encoded ... */
1605 #define GST_AUDIO_DECODER_MAX_SYNC 10 * 8 * 2 * 1024
1607 static GstFlowReturn
1608 gst_audio_decoder_push_buffers (GstAudioDecoder * dec, gboolean force)
1610 GstAudioDecoderClass *klass;
1611 GstAudioDecoderPrivate *priv;
1612 GstAudioDecoderContext *ctx;
1613 GstFlowReturn ret = GST_FLOW_OK;
1617 klass = GST_AUDIO_DECODER_GET_CLASS (dec);
1619 ctx = &dec->priv->ctx;
1621 g_return_val_if_fail (klass->handle_frame != NULL, GST_FLOW_ERROR);
1623 av = gst_adapter_available (priv->adapter);
1624 GST_DEBUG_OBJECT (dec, "available: %d", av);
1626 while (ret == GST_FLOW_OK) {
1631 if (G_LIKELY (av)) {
1636 /* parse if needed */
1640 /* limited (legacy) parsing; avoid whole of baseparse */
1641 GST_DEBUG_OBJECT (dec, "parsing available: %d", av);
1642 /* piggyback sync state on discont */
1643 ctx->sync = !priv->discont;
1644 ret = klass->parse (dec, priv->adapter, &offset, &len);
1646 g_assert (offset <= av);
1649 GST_DEBUG_OBJECT (dec, "skipped %d; setting DISCONT", offset);
1650 gst_adapter_flush (priv->adapter, offset);
1652 /* avoid parsing indefinitely */
1653 priv->sync_flush += offset;
1654 if (priv->sync_flush > GST_AUDIO_DECODER_MAX_SYNC)
1658 if (ret == GST_FLOW_EOS) {
1659 GST_LOG_OBJECT (dec, "no frame yet");
1662 } else if (ret == GST_FLOW_OK) {
1663 GST_LOG_OBJECT (dec, "frame at offset %d of length %d", offset, len);
1665 g_assert (offset + len <= av);
1666 priv->sync_flush = 0;
1673 /* track upstream ts, but do not get stuck if nothing new upstream */
1674 ts = gst_adapter_prev_pts (priv->adapter, &distance);
1675 if (ts != priv->prev_ts || distance <= priv->prev_distance) {
1677 priv->prev_distance = distance;
1679 GST_LOG_OBJECT (dec, "ts == prev_ts; discarding");
1680 ts = GST_CLOCK_TIME_NONE;
1682 buffer = gst_adapter_take_buffer (priv->adapter, len);
1683 buffer = gst_buffer_make_writable (buffer);
1684 GST_BUFFER_TIMESTAMP (buffer) = ts;
1686 priv->force = FALSE;
1690 if (!priv->drainable) {
1691 priv->drained = TRUE;
1698 ret = gst_audio_decoder_handle_frame (dec, klass, buffer);
1700 /* do not keep pushing it ... */
1701 if (G_UNLIKELY (!av)) {
1702 priv->drained = TRUE;
1710 GST_LOG_OBJECT (dec, "done pushing to subclass");
1716 GST_ELEMENT_ERROR (dec, STREAM, DECODE, (NULL), ("failed to parse stream"));
1717 return GST_FLOW_ERROR;
1721 static GstFlowReturn
1722 gst_audio_decoder_drain (GstAudioDecoder * dec)
1726 if (dec->priv->drained && !dec->priv->gather)
1729 /* Apply any pending events before draining, as that
1730 * may update the pending segment info */
1731 apply_pending_events (dec);
1733 /* dispatch reverse pending buffers */
1734 /* chain eventually calls upon drain as well, but by that time
1735 * gather list should be clear, so ok ... */
1736 if (dec->output_segment.rate < 0.0 && dec->priv->gather)
1737 gst_audio_decoder_chain_reverse (dec, NULL);
1738 /* have subclass give all it can */
1739 ret = gst_audio_decoder_push_buffers (dec, TRUE);
1740 if (ret != GST_FLOW_OK) {
1741 GST_WARNING_OBJECT (dec, "audio decoder push buffers failed");
1744 /* ensure all output sent */
1745 ret = gst_audio_decoder_output (dec, NULL);
1746 if (ret != GST_FLOW_OK)
1747 GST_WARNING_OBJECT (dec, "audio decoder output failed");
1750 /* everything should be away now */
1751 if (dec->priv->frames.length) {
1752 /* not fatal/impossible though if subclass/codec eats stuff */
1753 GST_WARNING_OBJECT (dec, "still %d frames left after draining",
1754 dec->priv->frames.length);
1755 g_queue_foreach (&dec->priv->frames, (GFunc) gst_buffer_unref, NULL);
1756 g_queue_clear (&dec->priv->frames);
1759 /* discard (unparsed) leftover */
1760 gst_adapter_clear (dec->priv->adapter);
1764 /* hard == FLUSH, otherwise discont */
1765 static GstFlowReturn
1766 gst_audio_decoder_flush (GstAudioDecoder * dec, gboolean hard)
1768 GstAudioDecoderClass *klass;
1769 GstFlowReturn ret = GST_FLOW_OK;
1771 klass = GST_AUDIO_DECODER_GET_CLASS (dec);
1773 GST_LOG_OBJECT (dec, "flush hard %d", hard);
1776 ret = gst_audio_decoder_drain (dec);
1778 gst_audio_decoder_clear_queues (dec);
1779 gst_segment_init (&dec->input_segment, GST_FORMAT_TIME);
1780 gst_segment_init (&dec->output_segment, GST_FORMAT_TIME);
1781 dec->priv->error_count = 0;
1783 /* only bother subclass with flushing if known it is already alive
1784 * and kicking out stuff */
1785 if (klass->flush && dec->priv->samples_out > 0)
1786 klass->flush (dec, hard);
1787 /* and get (re)set for the sequel */
1788 gst_audio_decoder_reset (dec, FALSE);
1793 static GstFlowReturn
1794 gst_audio_decoder_chain_forward (GstAudioDecoder * dec, GstBuffer * buffer)
1796 GstFlowReturn ret = GST_FLOW_OK;
1798 /* discard silly case, though maybe ts may be of value ?? */
1799 if (G_UNLIKELY (gst_buffer_get_size (buffer) == 0)) {
1800 GST_DEBUG_OBJECT (dec, "discarding empty buffer");
1801 gst_buffer_unref (buffer);
1806 gst_adapter_push (dec->priv->adapter, buffer);
1808 /* new stuff, so we can push subclass again */
1809 dec->priv->drained = FALSE;
1811 /* hand to subclass */
1812 ret = gst_audio_decoder_push_buffers (dec, FALSE);
1815 GST_LOG_OBJECT (dec, "chain-done");
1820 gst_audio_decoder_clear_queues (GstAudioDecoder * dec)
1822 GstAudioDecoderPrivate *priv = dec->priv;
1824 g_list_foreach (priv->queued, (GFunc) gst_mini_object_unref, NULL);
1825 g_list_free (priv->queued);
1826 priv->queued = NULL;
1827 g_list_foreach (priv->gather, (GFunc) gst_mini_object_unref, NULL);
1828 g_list_free (priv->gather);
1829 priv->gather = NULL;
1830 g_list_foreach (priv->decode, (GFunc) gst_mini_object_unref, NULL);
1831 g_list_free (priv->decode);
1832 priv->decode = NULL;
1837 * Buffer decoding order: 7 8 9 4 5 6 3 1 2 EOS
1838 * Discont flag: D D D D
1840 * - Each Discont marks a discont in the decoding order.
1842 * for vorbis, each buffer is a keyframe when we have the previous
1843 * buffer. This means that to decode buffer 7, we need buffer 6, which
1844 * arrives out of order.
1846 * we first gather buffers in the gather queue until we get a DISCONT. We
1847 * prepend each incomming buffer so that they are in reversed order.
1849 * gather queue: 9 8 7
1853 * When a DISCONT is received (buffer 4), we move the gather queue to the
1854 * decode queue. This is simply done be taking the head of the gather queue
1855 * and prepending it to the decode queue. This yields:
1858 * decode queue: 7 8 9
1861 * Then we decode each buffer in the decode queue in order and put the output
1862 * buffer in the output queue. The first buffer (7) will not produce any output
1863 * because it needs the previous buffer (6) which did not arrive yet. This
1867 * decode queue: 7 8 9
1870 * Then we remove the consumed buffers from the decode queue. Buffer 7 is not
1871 * completely consumed, we need to keep it around for when we receive buffer
1878 * Then we accumulate more buffers:
1880 * gather queue: 6 5 4
1884 * prepending to the decode queue on DISCONT yields:
1887 * decode queue: 4 5 6 7
1890 * after decoding and keeping buffer 4:
1894 * output queue: 7 6 5
1898 static GstFlowReturn
1899 gst_audio_decoder_flush_decode (GstAudioDecoder * dec)
1901 GstAudioDecoderPrivate *priv = dec->priv;
1902 GstFlowReturn res = GST_FLOW_OK;
1903 GstClockTime timestamp;
1906 walk = priv->decode;
1908 GST_DEBUG_OBJECT (dec, "flushing buffers to decoder");
1910 /* clear buffer and decoder state */
1911 gst_audio_decoder_flush (dec, FALSE);
1915 GstBuffer *buf = GST_BUFFER_CAST (walk->data);
1917 GST_DEBUG_OBJECT (dec, "decoding buffer %p, ts %" GST_TIME_FORMAT,
1918 buf, GST_TIME_ARGS (GST_BUFFER_TIMESTAMP (buf)));
1920 next = g_list_next (walk);
1921 /* decode buffer, resulting data prepended to output queue */
1922 gst_buffer_ref (buf);
1923 res = gst_audio_decoder_chain_forward (dec, buf);
1925 /* if we generated output, we can discard the buffer, else we
1926 * keep it in the queue */
1928 GST_DEBUG_OBJECT (dec, "decoded buffer to %p", priv->queued->data);
1929 priv->decode = g_list_delete_link (priv->decode, walk);
1930 gst_buffer_unref (buf);
1932 GST_DEBUG_OBJECT (dec, "buffer did not decode, keeping");
1937 /* drain any aggregation (or otherwise) leftover */
1938 gst_audio_decoder_drain (dec);
1940 /* now send queued data downstream */
1941 timestamp = GST_CLOCK_TIME_NONE;
1942 while (priv->queued) {
1943 GstBuffer *buf = GST_BUFFER_CAST (priv->queued->data);
1944 GstClockTime duration;
1946 duration = GST_BUFFER_DURATION (buf);
1948 /* duration should always be valid for raw audio */
1949 g_assert (GST_CLOCK_TIME_IS_VALID (duration));
1951 /* interpolate (backward) if needed */
1952 if (G_LIKELY (timestamp != -1)) {
1953 if (timestamp > duration)
1954 timestamp -= duration;
1959 if (!GST_BUFFER_TIMESTAMP_IS_VALID (buf)) {
1960 GST_LOG_OBJECT (dec, "applying reverse interpolated ts %"
1961 GST_TIME_FORMAT, GST_TIME_ARGS (timestamp));
1962 GST_BUFFER_TIMESTAMP (buf) = timestamp;
1964 /* track otherwise */
1965 timestamp = GST_BUFFER_TIMESTAMP (buf);
1966 GST_LOG_OBJECT (dec, "tracking ts %" GST_TIME_FORMAT,
1967 GST_TIME_ARGS (timestamp));
1970 if (G_LIKELY (res == GST_FLOW_OK)) {
1971 GST_DEBUG_OBJECT (dec, "pushing buffer %p of size %" G_GSIZE_FORMAT ", "
1972 "time %" GST_TIME_FORMAT ", dur %" GST_TIME_FORMAT, buf,
1973 gst_buffer_get_size (buf), GST_TIME_ARGS (GST_BUFFER_TIMESTAMP (buf)),
1974 GST_TIME_ARGS (GST_BUFFER_DURATION (buf)));
1975 /* should be already, but let's be sure */
1976 buf = gst_buffer_make_writable (buf);
1977 /* avoid stray DISCONT from forward processing,
1978 * which have no meaning in reverse pushing */
1979 GST_BUFFER_FLAG_UNSET (buf, GST_BUFFER_FLAG_DISCONT);
1980 res = gst_audio_decoder_push_forward (dec, buf);
1982 gst_buffer_unref (buf);
1985 priv->queued = g_list_delete_link (priv->queued, priv->queued);
1991 static GstFlowReturn
1992 gst_audio_decoder_chain_reverse (GstAudioDecoder * dec, GstBuffer * buf)
1994 GstAudioDecoderPrivate *priv = dec->priv;
1995 GstFlowReturn result = GST_FLOW_OK;
1997 /* if we have a discont, move buffers to the decode list */
1998 if (!buf || GST_BUFFER_FLAG_IS_SET (buf, GST_BUFFER_FLAG_DISCONT)) {
1999 GST_DEBUG_OBJECT (dec, "received discont");
2000 while (priv->gather) {
2003 gbuf = GST_BUFFER_CAST (priv->gather->data);
2004 /* remove from the gather list */
2005 priv->gather = g_list_delete_link (priv->gather, priv->gather);
2006 /* copy to decode queue */
2007 priv->decode = g_list_prepend (priv->decode, gbuf);
2009 /* decode stuff in the decode queue */
2010 gst_audio_decoder_flush_decode (dec);
2013 if (G_LIKELY (buf)) {
2014 GST_DEBUG_OBJECT (dec, "gathering buffer %p of size %" G_GSIZE_FORMAT ", "
2015 "time %" GST_TIME_FORMAT ", dur %" GST_TIME_FORMAT, buf,
2016 gst_buffer_get_size (buf), GST_TIME_ARGS (GST_BUFFER_TIMESTAMP (buf)),
2017 GST_TIME_ARGS (GST_BUFFER_DURATION (buf)));
2019 /* add buffer to gather queue */
2020 priv->gather = g_list_prepend (priv->gather, buf);
2026 static GstFlowReturn
2027 gst_audio_decoder_chain (GstPad * pad, GstObject * parent, GstBuffer * buffer)
2029 GstAudioDecoder *dec;
2032 dec = GST_AUDIO_DECODER (parent);
2034 GST_LOG_OBJECT (dec,
2035 "received buffer of size %" G_GSIZE_FORMAT " with ts %" GST_TIME_FORMAT
2036 ", duration %" GST_TIME_FORMAT, gst_buffer_get_size (buffer),
2037 GST_TIME_ARGS (GST_BUFFER_TIMESTAMP (buffer)),
2038 GST_TIME_ARGS (GST_BUFFER_DURATION (buffer)));
2040 GST_AUDIO_DECODER_STREAM_LOCK (dec);
2042 if (G_UNLIKELY (dec->priv->ctx.input_caps == NULL && dec->priv->needs_format))
2043 goto not_negotiated;
2045 dec->priv->ctx.had_input_data = TRUE;
2047 if (!dec->priv->expecting_discont_buf &&
2048 GST_BUFFER_FLAG_IS_SET (buffer, GST_BUFFER_FLAG_DISCONT)) {
2051 /* track present position */
2052 ts = dec->priv->base_ts;
2053 samples = dec->priv->samples;
2055 GST_DEBUG_OBJECT (dec, "handling discont");
2056 gst_audio_decoder_flush (dec, FALSE);
2057 dec->priv->discont = TRUE;
2059 /* buffer may claim DISCONT loudly, if it can't tell us where we are now,
2060 * we'll stick to where we were ...
2061 * Particularly useful/needed for upstream BYTE based */
2062 if (dec->input_segment.rate > 0.0
2063 && !GST_BUFFER_TIMESTAMP_IS_VALID (buffer)) {
2064 GST_DEBUG_OBJECT (dec, "... but restoring previous ts tracking");
2065 dec->priv->base_ts = ts;
2066 dec->priv->samples = samples;
2069 dec->priv->expecting_discont_buf = FALSE;
2071 if (dec->input_segment.rate > 0.0)
2072 ret = gst_audio_decoder_chain_forward (dec, buffer);
2074 ret = gst_audio_decoder_chain_reverse (dec, buffer);
2076 GST_AUDIO_DECODER_STREAM_UNLOCK (dec);
2083 GST_AUDIO_DECODER_STREAM_UNLOCK (dec);
2084 GST_ELEMENT_ERROR (dec, CORE, NEGOTIATION, (NULL),
2085 ("decoder not initialized"));
2086 gst_buffer_unref (buffer);
2087 return GST_FLOW_NOT_NEGOTIATED;
2091 /* perform upstream byte <-> time conversion (duration, seeking)
2092 * if subclass allows and if enough data for moderately decent conversion */
2093 static inline gboolean
2094 gst_audio_decoder_do_byte (GstAudioDecoder * dec)
2098 GST_OBJECT_LOCK (dec);
2099 ret = dec->priv->ctx.do_estimate_rate && dec->priv->ctx.info.bpf &&
2100 dec->priv->ctx.info.rate <= dec->priv->samples_out;
2101 GST_OBJECT_UNLOCK (dec);
2106 /* Must be called holding the GST_AUDIO_DECODER_STREAM_LOCK */
2108 gst_audio_decoder_negotiate_default_caps (GstAudioDecoder * dec)
2110 GstCaps *caps, *templcaps;
2114 guint64 channel_mask = 0;
2116 GstStructure *structure;
2119 templcaps = gst_pad_get_pad_template_caps (dec->srcpad);
2120 caps = gst_pad_peer_query_caps (dec->srcpad, templcaps);
2122 gst_caps_unref (templcaps);
2127 if (!caps || gst_caps_is_empty (caps) || gst_caps_is_any (caps))
2130 GST_LOG_OBJECT (dec, "peer caps %" GST_PTR_FORMAT, caps);
2132 /* before fixating, try to use whatever upstream provided */
2133 caps = gst_caps_make_writable (caps);
2134 caps_size = gst_caps_get_size (caps);
2135 if (dec->priv->ctx.input_caps) {
2136 GstCaps *sinkcaps = dec->priv->ctx.input_caps;
2137 GstStructure *structure = gst_caps_get_structure (sinkcaps, 0);
2139 if (gst_structure_get_int (structure, "rate", &rate)) {
2140 for (i = 0; i < caps_size; i++) {
2141 gst_structure_set (gst_caps_get_structure (caps, i), "rate",
2142 G_TYPE_INT, rate, NULL);
2146 if (gst_structure_get_int (structure, "channels", &channels)) {
2147 for (i = 0; i < caps_size; i++) {
2148 gst_structure_set (gst_caps_get_structure (caps, i), "channels",
2149 G_TYPE_INT, channels, NULL);
2153 if (gst_structure_get (structure, "channel-mask", GST_TYPE_BITMASK,
2154 &channel_mask, NULL)) {
2155 for (i = 0; i < caps_size; i++) {
2156 gst_structure_set (gst_caps_get_structure (caps, i), "channel-mask",
2157 GST_TYPE_BITMASK, channel_mask, NULL);
2162 for (i = 0; i < caps_size; i++) {
2163 structure = gst_caps_get_structure (caps, i);
2164 if (gst_structure_has_field (structure, "channels"))
2165 gst_structure_fixate_field_nearest_int (structure,
2166 "channels", GST_AUDIO_DEF_CHANNELS);
2168 gst_structure_set (structure, "channels", G_TYPE_INT,
2169 GST_AUDIO_DEF_CHANNELS, NULL);
2170 if (gst_structure_has_field (structure, "rate"))
2171 gst_structure_fixate_field_nearest_int (structure,
2172 "rate", GST_AUDIO_DEF_RATE);
2174 gst_structure_set (structure, "rate", G_TYPE_INT, GST_AUDIO_DEF_RATE,
2177 caps = gst_caps_fixate (caps);
2178 structure = gst_caps_get_structure (caps, 0);
2180 /* Need to add a channel-mask if channels > 2 */
2181 gst_structure_get_int (structure, "channels", &channels);
2182 if (channels > 2 && !gst_structure_has_field (structure, "channel-mask")) {
2183 channel_mask = gst_audio_channel_get_fallback_mask (channels);
2184 if (channel_mask != 0) {
2185 gst_structure_set (structure, "channel-mask",
2186 GST_TYPE_BITMASK, channel_mask, NULL);
2188 GST_WARNING_OBJECT (dec, "No default channel-mask for %d channels",
2193 if (!caps || !gst_audio_info_from_caps (&info, caps))
2196 GST_OBJECT_LOCK (dec);
2197 dec->priv->ctx.info = info;
2198 dec->priv->ctx.caps = caps;
2199 GST_OBJECT_UNLOCK (dec);
2201 GST_INFO_OBJECT (dec,
2202 "Chose default caps %" GST_PTR_FORMAT " for initial gap", caps);
2209 gst_caps_unref (caps);
2215 gst_audio_decoder_handle_gap (GstAudioDecoder * dec, GstEvent * event)
2218 GstClockTime timestamp, duration;
2219 gboolean needs_reconfigure = FALSE;
2221 /* Ensure we have caps first */
2222 GST_AUDIO_DECODER_STREAM_LOCK (dec);
2223 if (!GST_AUDIO_INFO_IS_VALID (&dec->priv->ctx.info)) {
2224 if (!gst_audio_decoder_negotiate_default_caps (dec)) {
2225 GST_AUDIO_DECODER_STREAM_UNLOCK (dec);
2226 GST_ELEMENT_ERROR (dec, STREAM, FORMAT, (NULL),
2227 ("Decoder output not negotiated before GAP event."));
2228 gst_event_unref (event);
2231 needs_reconfigure = TRUE;
2233 needs_reconfigure = gst_pad_check_reconfigure (dec->srcpad)
2234 || needs_reconfigure;
2235 if (G_UNLIKELY (dec->priv->ctx.output_format_changed || needs_reconfigure)) {
2236 if (!gst_audio_decoder_negotiate_unlocked (dec)) {
2237 GST_WARNING_OBJECT (dec, "Failed to negotiate with downstream");
2238 gst_pad_mark_reconfigure (dec->srcpad);
2241 GST_AUDIO_DECODER_STREAM_UNLOCK (dec);
2243 gst_event_parse_gap (event, ×tamp, &duration);
2245 /* time progressed without data, see if we can fill the gap with
2246 * some concealment data */
2247 GST_DEBUG_OBJECT (dec,
2248 "gap event: plc %d, do_plc %d, position %" GST_TIME_FORMAT
2249 " duration %" GST_TIME_FORMAT,
2250 dec->priv->plc, dec->priv->ctx.do_plc,
2251 GST_TIME_ARGS (timestamp), GST_TIME_ARGS (duration));
2253 if (dec->priv->plc && dec->priv->ctx.do_plc && dec->input_segment.rate > 0.0) {
2254 GstAudioDecoderClass *klass = GST_AUDIO_DECODER_GET_CLASS (dec);
2257 /* hand subclass empty frame with duration that needs covering */
2258 buf = gst_buffer_new ();
2259 GST_BUFFER_TIMESTAMP (buf) = timestamp;
2260 GST_BUFFER_DURATION (buf) = duration;
2261 /* best effort, not much error handling */
2262 gst_audio_decoder_handle_frame (dec, klass, buf);
2264 dec->priv->expecting_discont_buf = TRUE;
2265 gst_event_unref (event);
2267 GstFlowReturn flowret;
2269 /* sub-class doesn't know how to handle empty buffers,
2270 * so just try sending GAP downstream */
2271 flowret = check_pending_reconfigure (dec);
2272 if (flowret == GST_FLOW_OK) {
2273 send_pending_events (dec);
2274 ret = gst_audio_decoder_push_event (dec, event);
2277 gst_event_unref (event);
2284 _flush_events (GstPad * pad, GList * events)
2288 for (tmp = events; tmp; tmp = tmp->next) {
2289 if (GST_EVENT_TYPE (tmp->data) != GST_EVENT_EOS &&
2290 GST_EVENT_TYPE (tmp->data) != GST_EVENT_SEGMENT &&
2291 GST_EVENT_IS_STICKY (tmp->data)) {
2292 gst_pad_store_sticky_event (pad, GST_EVENT_CAST (tmp->data));
2294 gst_event_unref (tmp->data);
2296 g_list_free (events);
2302 gst_audio_decoder_sink_eventfunc (GstAudioDecoder * dec, GstEvent * event)
2306 switch (GST_EVENT_TYPE (event)) {
2307 case GST_EVENT_STREAM_START:
2308 GST_AUDIO_DECODER_STREAM_LOCK (dec);
2309 /* finish any data in current segment and clear the decoder
2310 * to be ready for new stream data */
2311 gst_audio_decoder_drain (dec);
2312 gst_audio_decoder_flush (dec, FALSE);
2314 GST_DEBUG_OBJECT (dec, "received STREAM_START. Clearing taglist");
2315 /* Flush upstream tags after a STREAM_START */
2316 if (dec->priv->upstream_tags) {
2317 gst_tag_list_unref (dec->priv->upstream_tags);
2318 dec->priv->upstream_tags = NULL;
2319 dec->priv->taglist_changed = TRUE;
2321 GST_AUDIO_DECODER_STREAM_UNLOCK (dec);
2323 ret = gst_audio_decoder_push_event (dec, event);
2325 case GST_EVENT_SEGMENT:
2330 GST_AUDIO_DECODER_STREAM_LOCK (dec);
2331 gst_event_copy_segment (event, &seg);
2333 format = seg.format;
2334 if (format == GST_FORMAT_TIME) {
2335 GST_DEBUG_OBJECT (dec, "received TIME SEGMENT %" GST_SEGMENT_FORMAT,
2339 GST_DEBUG_OBJECT (dec, "received SEGMENT %" GST_SEGMENT_FORMAT, &seg);
2340 /* handle newsegment resulting from legacy simple seeking */
2341 /* note that we need to convert this whether or not enough data
2342 * to handle initial newsegment */
2343 if (dec->priv->ctx.do_estimate_rate &&
2344 gst_pad_query_convert (dec->sinkpad, GST_FORMAT_BYTES, seg.start,
2345 GST_FORMAT_TIME, &nstart)) {
2346 /* best attempt convert */
2347 /* as these are only estimates, stop is kept open-ended to avoid
2348 * premature cutting */
2349 GST_DEBUG_OBJECT (dec, "converted to TIME start %" GST_TIME_FORMAT,
2350 GST_TIME_ARGS (nstart));
2351 seg.format = GST_FORMAT_TIME;
2354 seg.stop = GST_CLOCK_TIME_NONE;
2356 gst_event_unref (event);
2357 event = gst_event_new_segment (&seg);
2359 GST_DEBUG_OBJECT (dec, "unsupported format; ignoring");
2360 GST_AUDIO_DECODER_STREAM_UNLOCK (dec);
2361 #ifdef TIZEN_FEATURE_AUDIODECODER_MODIFICATION
2362 goto newseg_wrong_format;
2364 gst_event_unref (event);
2371 /* prepare for next segment */
2372 /* Use the segment start as a base timestamp
2373 * in case upstream does not come up with anything better
2374 * (e.g. upstream BYTE) */
2375 if (format != GST_FORMAT_TIME) {
2376 dec->priv->base_ts = seg.start;
2377 dec->priv->samples = 0;
2380 /* and follow along with segment */
2381 dec->priv->in_out_segment_sync = FALSE;
2382 dec->input_segment = seg;
2383 dec->priv->pending_events =
2384 g_list_append (dec->priv->pending_events, event);
2385 GST_AUDIO_DECODER_STREAM_UNLOCK (dec);
2391 ret = gst_audio_decoder_handle_gap (dec, event);
2393 case GST_EVENT_FLUSH_STOP:
2394 GST_AUDIO_DECODER_STREAM_LOCK (dec);
2395 /* prepare for fresh start */
2396 gst_audio_decoder_flush (dec, TRUE);
2398 dec->priv->pending_events = _flush_events (dec->srcpad,
2399 dec->priv->pending_events);
2400 GST_AUDIO_DECODER_STREAM_UNLOCK (dec);
2402 /* Forward FLUSH_STOP, it is expected to be forwarded immediately
2403 * and no buffers are queued anyway. */
2404 ret = gst_audio_decoder_push_event (dec, event);
2407 case GST_EVENT_SEGMENT_DONE:
2408 GST_AUDIO_DECODER_STREAM_LOCK (dec);
2409 gst_audio_decoder_drain (dec);
2410 GST_AUDIO_DECODER_STREAM_UNLOCK (dec);
2412 /* Forward SEGMENT_DONE because no buffer or serialized event might come after
2413 * SEGMENT_DONE and nothing could trigger another _finish_frame() call. */
2414 if (dec->priv->pending_events)
2415 send_pending_events (dec);
2416 ret = gst_audio_decoder_push_event (dec, event);
2420 GST_AUDIO_DECODER_STREAM_LOCK (dec);
2421 gst_audio_decoder_drain (dec);
2422 GST_AUDIO_DECODER_STREAM_UNLOCK (dec);
2424 if (dec->priv->ctx.had_input_data && !dec->priv->ctx.had_output_data) {
2425 GST_ELEMENT_ERROR (dec, STREAM, DECODE,
2426 ("No valid frames decoded before end of stream"),
2427 ("no valid frames found"));
2430 /* Forward EOS because no buffer or serialized event will come after
2431 * EOS and nothing could trigger another _finish_frame() call. */
2432 if (dec->priv->pending_events)
2433 send_pending_events (dec);
2434 ret = gst_audio_decoder_push_event (dec, event);
2437 case GST_EVENT_CAPS:
2441 gst_event_parse_caps (event, &caps);
2442 ret = gst_audio_decoder_sink_setcaps (dec, caps);
2443 gst_event_unref (event);
2450 gst_event_parse_tag (event, &tags);
2452 if (gst_tag_list_get_scope (tags) == GST_TAG_SCOPE_STREAM) {
2453 GST_AUDIO_DECODER_STREAM_LOCK (dec);
2454 if (dec->priv->upstream_tags != tags) {
2455 if (dec->priv->upstream_tags)
2456 gst_tag_list_unref (dec->priv->upstream_tags);
2457 dec->priv->upstream_tags = gst_tag_list_ref (tags);
2458 GST_INFO_OBJECT (dec, "upstream stream tags: %" GST_PTR_FORMAT, tags);
2460 gst_event_unref (event);
2461 event = gst_audio_decoder_create_merged_tags_event (dec);
2462 dec->priv->taglist_changed = FALSE;
2463 GST_AUDIO_DECODER_STREAM_UNLOCK (dec);
2465 /* No tags, go out of here instead of fall through */
2475 if (!GST_EVENT_IS_SERIALIZED (event)) {
2477 gst_pad_event_default (dec->sinkpad, GST_OBJECT_CAST (dec), event);
2479 GST_DEBUG_OBJECT (dec, "Enqueuing event %d, %s", GST_EVENT_TYPE (event),
2480 GST_EVENT_TYPE_NAME (event));
2481 GST_AUDIO_DECODER_STREAM_LOCK (dec);
2482 dec->priv->pending_events =
2483 g_list_append (dec->priv->pending_events, event);
2484 GST_AUDIO_DECODER_STREAM_UNLOCK (dec);
2491 #ifdef TIZEN_FEATURE_AUDIODECODER_MODIFICATION
2492 newseg_wrong_format:
2494 GST_DEBUG_OBJECT (dec, "received non TIME newsegment");
2495 gst_event_unref (event);
2503 gst_audio_decoder_sink_event (GstPad * pad, GstObject * parent,
2506 GstAudioDecoder *dec;
2507 GstAudioDecoderClass *klass;
2510 dec = GST_AUDIO_DECODER (parent);
2511 klass = GST_AUDIO_DECODER_GET_CLASS (dec);
2513 GST_DEBUG_OBJECT (dec, "received event %d, %s", GST_EVENT_TYPE (event),
2514 GST_EVENT_TYPE_NAME (event));
2516 if (klass->sink_event)
2517 ret = klass->sink_event (dec, event);
2519 gst_event_unref (event);
2526 gst_audio_decoder_do_seek (GstAudioDecoder * dec, GstEvent * event)
2529 GstSeekType start_type, end_type;
2532 gint64 start, start_time, end_time;
2533 GstSegment seek_segment;
2536 gst_event_parse_seek (event, &rate, &format, &flags, &start_type,
2537 &start_time, &end_type, &end_time);
2539 /* we'll handle plain open-ended flushing seeks with the simple approach */
2541 GST_DEBUG_OBJECT (dec, "unsupported seek: rate");
2545 if (start_type != GST_SEEK_TYPE_SET) {
2546 GST_DEBUG_OBJECT (dec, "unsupported seek: start time");
2550 if ((end_type != GST_SEEK_TYPE_SET && end_type != GST_SEEK_TYPE_NONE) ||
2551 (end_type == GST_SEEK_TYPE_SET && end_time != GST_CLOCK_TIME_NONE)) {
2552 GST_DEBUG_OBJECT (dec, "unsupported seek: end time");
2556 if (!(flags & GST_SEEK_FLAG_FLUSH)) {
2557 GST_DEBUG_OBJECT (dec, "unsupported seek: not flushing");
2561 memcpy (&seek_segment, &dec->output_segment, sizeof (seek_segment));
2562 gst_segment_do_seek (&seek_segment, rate, format, flags, start_type,
2563 start_time, end_type, end_time, NULL);
2564 start_time = seek_segment.position;
2566 if (!gst_pad_query_convert (dec->sinkpad, GST_FORMAT_TIME, start_time,
2567 GST_FORMAT_BYTES, &start)) {
2568 GST_DEBUG_OBJECT (dec, "conversion failed");
2572 seqnum = gst_event_get_seqnum (event);
2573 event = gst_event_new_seek (1.0, GST_FORMAT_BYTES, flags,
2574 GST_SEEK_TYPE_SET, start, GST_SEEK_TYPE_NONE, -1);
2575 gst_event_set_seqnum (event, seqnum);
2577 GST_DEBUG_OBJECT (dec, "seeking to %" GST_TIME_FORMAT " at byte offset %"
2578 G_GINT64_FORMAT, GST_TIME_ARGS (start_time), start);
2580 return gst_pad_push_event (dec->sinkpad, event);
2584 gst_audio_decoder_src_eventfunc (GstAudioDecoder * dec, GstEvent * event)
2588 switch (GST_EVENT_TYPE (event)) {
2589 case GST_EVENT_SEEK:
2594 GstSeekType start_type, stop_type;
2596 gint64 tstart, tstop;
2599 gst_event_parse_seek (event, &rate, &format, &flags, &start_type, &start,
2601 seqnum = gst_event_get_seqnum (event);
2603 /* upstream gets a chance first */
2604 if ((res = gst_pad_push_event (dec->sinkpad, event)))
2607 /* if upstream fails for a time seek, maybe we can help if allowed */
2608 if (format == GST_FORMAT_TIME) {
2609 if (gst_audio_decoder_do_byte (dec))
2610 res = gst_audio_decoder_do_seek (dec, event);
2614 /* ... though a non-time seek can be aided as well */
2615 /* First bring the requested format to time */
2617 gst_pad_query_convert (dec->srcpad, format, start,
2618 GST_FORMAT_TIME, &tstart)))
2621 gst_pad_query_convert (dec->srcpad, format, stop, GST_FORMAT_TIME,
2625 /* then seek with time on the peer */
2626 event = gst_event_new_seek (rate, GST_FORMAT_TIME,
2627 flags, start_type, tstart, stop_type, tstop);
2628 gst_event_set_seqnum (event, seqnum);
2630 res = gst_pad_push_event (dec->sinkpad, event);
2634 res = gst_pad_event_default (dec->srcpad, GST_OBJECT_CAST (dec), event);
2643 GST_DEBUG_OBJECT (dec, "cannot convert start/stop for seek");
2649 gst_audio_decoder_src_event (GstPad * pad, GstObject * parent, GstEvent * event)
2651 GstAudioDecoder *dec;
2652 GstAudioDecoderClass *klass;
2655 dec = GST_AUDIO_DECODER (parent);
2656 klass = GST_AUDIO_DECODER_GET_CLASS (dec);
2658 GST_DEBUG_OBJECT (dec, "received event %d, %s", GST_EVENT_TYPE (event),
2659 GST_EVENT_TYPE_NAME (event));
2661 if (klass->src_event)
2662 ret = klass->src_event (dec, event);
2664 gst_event_unref (event);
2672 gst_audio_decoder_decide_allocation_default (GstAudioDecoder * dec,
2675 GstAllocator *allocator = NULL;
2676 GstAllocationParams params;
2677 gboolean update_allocator;
2679 /* we got configuration from our peer or the decide_allocation method,
2681 if (gst_query_get_n_allocation_params (query) > 0) {
2682 /* try the allocator */
2683 gst_query_parse_nth_allocation_param (query, 0, &allocator, ¶ms);
2684 update_allocator = TRUE;
2687 gst_allocation_params_init (¶ms);
2688 update_allocator = FALSE;
2691 if (update_allocator)
2692 gst_query_set_nth_allocation_param (query, 0, allocator, ¶ms);
2694 gst_query_add_allocation_param (query, allocator, ¶ms);
2696 gst_object_unref (allocator);
2702 gst_audio_decoder_propose_allocation_default (GstAudioDecoder * dec,
2709 * gst_audio_decoder_proxy_getcaps:
2710 * @decoder: a #GstAudioDecoder
2711 * @caps: (allow-none): initial caps
2712 * @filter: (allow-none): filter caps
2714 * Returns caps that express @caps (or sink template caps if @caps == NULL)
2715 * restricted to rate/channels/... combinations supported by downstream
2718 * Returns: (transfer full): a #GstCaps owned by caller
2723 gst_audio_decoder_proxy_getcaps (GstAudioDecoder * decoder, GstCaps * caps,
2726 return __gst_audio_element_proxy_getcaps (GST_ELEMENT_CAST (decoder),
2727 GST_AUDIO_DECODER_SINK_PAD (decoder),
2728 GST_AUDIO_DECODER_SRC_PAD (decoder), caps, filter);
2732 gst_audio_decoder_sink_getcaps (GstAudioDecoder * decoder, GstCaps * filter)
2734 GstAudioDecoderClass *klass;
2737 klass = GST_AUDIO_DECODER_GET_CLASS (decoder);
2740 caps = klass->getcaps (decoder, filter);
2742 caps = gst_audio_decoder_proxy_getcaps (decoder, NULL, filter);
2744 GST_LOG_OBJECT (decoder, "Returning caps %" GST_PTR_FORMAT, caps);
2750 gst_audio_decoder_sink_query_default (GstAudioDecoder * dec, GstQuery * query)
2752 GstPad *pad = GST_AUDIO_DECODER_SINK_PAD (dec);
2753 gboolean res = FALSE;
2755 GST_LOG_OBJECT (dec, "handling query: %" GST_PTR_FORMAT, query);
2757 switch (GST_QUERY_TYPE (query)) {
2758 case GST_QUERY_FORMATS:
2760 gst_query_set_formats (query, 2, GST_FORMAT_TIME, GST_FORMAT_BYTES);
2764 case GST_QUERY_CONVERT:
2766 GstFormat src_fmt, dest_fmt;
2767 gint64 src_val, dest_val;
2769 gst_query_parse_convert (query, &src_fmt, &src_val, &dest_fmt, &dest_val);
2770 GST_OBJECT_LOCK (dec);
2771 res = __gst_audio_encoded_audio_convert (&dec->priv->ctx.info,
2772 dec->priv->bytes_in, dec->priv->samples_out,
2773 src_fmt, src_val, &dest_fmt, &dest_val);
2774 GST_OBJECT_UNLOCK (dec);
2777 gst_query_set_convert (query, src_fmt, src_val, dest_fmt, dest_val);
2780 case GST_QUERY_ALLOCATION:
2782 GstAudioDecoderClass *klass = GST_AUDIO_DECODER_GET_CLASS (dec);
2784 if (klass->propose_allocation)
2785 res = klass->propose_allocation (dec, query);
2788 case GST_QUERY_CAPS:{
2789 GstCaps *filter, *caps;
2791 gst_query_parse_caps (query, &filter);
2792 caps = gst_audio_decoder_sink_getcaps (dec, filter);
2793 gst_query_set_caps_result (query, caps);
2794 gst_caps_unref (caps);
2798 case GST_QUERY_ACCEPT_CAPS:{
2799 if (dec->priv->use_default_pad_acceptcaps) {
2801 gst_pad_query_default (GST_AUDIO_DECODER_SINK_PAD (dec),
2802 GST_OBJECT_CAST (dec), query);
2805 GstCaps *allowed_caps;
2806 GstCaps *template_caps;
2809 gst_query_parse_accept_caps (query, &caps);
2811 template_caps = gst_pad_get_pad_template_caps (pad);
2812 accept = gst_caps_is_subset (caps, template_caps);
2813 gst_caps_unref (template_caps);
2816 allowed_caps = gst_pad_query_caps (GST_AUDIO_DECODER_SINK_PAD (dec),
2819 accept = gst_caps_can_intersect (caps, allowed_caps);
2821 gst_caps_unref (allowed_caps);
2824 gst_query_set_accept_caps_result (query, accept);
2829 case GST_QUERY_SEEKING:
2833 /* non-TIME segments are discarded, so we won't seek that way either */
2834 gst_query_parse_seeking (query, &format, NULL, NULL, NULL);
2835 if (format != GST_FORMAT_TIME) {
2836 GST_DEBUG_OBJECT (dec, "discarding non-TIME SEEKING query");
2843 res = gst_pad_query_default (pad, GST_OBJECT_CAST (dec), query);
2852 gst_audio_decoder_sink_query (GstPad * pad, GstObject * parent,
2855 GstAudioDecoderClass *dec_class;
2856 GstAudioDecoder *dec;
2857 gboolean ret = FALSE;
2859 dec = GST_AUDIO_DECODER (parent);
2860 dec_class = GST_AUDIO_DECODER_GET_CLASS (dec);
2862 GST_DEBUG_OBJECT (pad, "received query %" GST_PTR_FORMAT, query);
2864 if (dec_class->sink_query)
2865 ret = dec_class->sink_query (dec, query);
2870 /* FIXME ? are any of these queries (other than latency) a decoder's business ??
2871 * also, the conversion stuff might seem to make sense, but seems to not mind
2872 * segment stuff etc at all
2873 * Supposedly that's backward compatibility ... */
2875 gst_audio_decoder_src_query_default (GstAudioDecoder * dec, GstQuery * query)
2877 GstPad *pad = GST_AUDIO_DECODER_SRC_PAD (dec);
2878 gboolean res = FALSE;
2880 GST_LOG_OBJECT (dec, "handling query: %" GST_PTR_FORMAT, query);
2882 switch (GST_QUERY_TYPE (query)) {
2883 case GST_QUERY_DURATION:
2887 /* upstream in any case */
2888 if ((res = gst_pad_query_default (pad, GST_OBJECT_CAST (dec), query)))
2891 gst_query_parse_duration (query, &format, NULL);
2892 /* try answering TIME by converting from BYTE if subclass allows */
2893 if (format == GST_FORMAT_TIME && gst_audio_decoder_do_byte (dec)) {
2896 if (gst_pad_peer_query_duration (dec->sinkpad, GST_FORMAT_BYTES,
2898 GST_LOG_OBJECT (dec, "upstream size %" G_GINT64_FORMAT, value);
2899 if (gst_pad_query_convert (dec->sinkpad, GST_FORMAT_BYTES, value,
2900 GST_FORMAT_TIME, &value)) {
2901 gst_query_set_duration (query, GST_FORMAT_TIME, value);
2908 case GST_QUERY_POSITION:
2913 if ((res = gst_pad_peer_query (dec->sinkpad, query))) {
2914 GST_LOG_OBJECT (dec, "returning peer response");
2918 /* Refuse BYTES format queries. If it made sense to
2919 * answer them, upstream would have already */
2920 gst_query_parse_position (query, &format, NULL);
2922 if (format == GST_FORMAT_BYTES) {
2923 GST_LOG_OBJECT (dec, "Ignoring BYTES position query");
2927 /* we start from the last seen time */
2928 time = dec->output_segment.position;
2929 /* correct for the segment values */
2931 gst_segment_to_stream_time (&dec->output_segment, GST_FORMAT_TIME,
2934 GST_LOG_OBJECT (dec,
2935 "query %p: our time: %" GST_TIME_FORMAT, query, GST_TIME_ARGS (time));
2937 /* and convert to the final format */
2938 if (!(res = gst_pad_query_convert (pad, GST_FORMAT_TIME, time,
2942 gst_query_set_position (query, format, value);
2944 GST_LOG_OBJECT (dec,
2945 "query %p: we return %" G_GINT64_FORMAT " (format %u)", query, value,
2949 case GST_QUERY_FORMATS:
2951 gst_query_set_formats (query, 3,
2952 GST_FORMAT_TIME, GST_FORMAT_BYTES, GST_FORMAT_DEFAULT);
2956 case GST_QUERY_CONVERT:
2958 GstFormat src_fmt, dest_fmt;
2959 gint64 src_val, dest_val;
2961 gst_query_parse_convert (query, &src_fmt, &src_val, &dest_fmt, &dest_val);
2962 GST_OBJECT_LOCK (dec);
2963 res = gst_audio_info_convert (&dec->priv->ctx.info,
2964 src_fmt, src_val, dest_fmt, &dest_val);
2965 GST_OBJECT_UNLOCK (dec);
2968 gst_query_set_convert (query, src_fmt, src_val, dest_fmt, dest_val);
2971 case GST_QUERY_LATENCY:
2973 if ((res = gst_pad_peer_query (dec->sinkpad, query))) {
2975 GstClockTime min_latency, max_latency;
2977 gst_query_parse_latency (query, &live, &min_latency, &max_latency);
2978 GST_DEBUG_OBJECT (dec, "Peer latency: live %d, min %"
2979 GST_TIME_FORMAT " max %" GST_TIME_FORMAT, live,
2980 GST_TIME_ARGS (min_latency), GST_TIME_ARGS (max_latency));
2982 GST_OBJECT_LOCK (dec);
2983 /* add our latency */
2984 min_latency += dec->priv->ctx.min_latency;
2985 if (max_latency == -1 || dec->priv->ctx.max_latency == -1)
2988 max_latency += dec->priv->ctx.max_latency;
2989 GST_OBJECT_UNLOCK (dec);
2991 gst_query_set_latency (query, live, min_latency, max_latency);
2996 res = gst_pad_query_default (pad, GST_OBJECT_CAST (dec), query);
3004 gst_audio_decoder_src_query (GstPad * pad, GstObject * parent, GstQuery * query)
3006 GstAudioDecoder *dec;
3007 GstAudioDecoderClass *dec_class;
3008 gboolean ret = FALSE;
3010 dec = GST_AUDIO_DECODER (parent);
3011 dec_class = GST_AUDIO_DECODER_GET_CLASS (dec);
3013 GST_DEBUG_OBJECT (pad, "received query %" GST_PTR_FORMAT, query);
3015 if (dec_class->src_query)
3016 ret = dec_class->src_query (dec, query);
3022 gst_audio_decoder_stop (GstAudioDecoder * dec)
3024 GstAudioDecoderClass *klass;
3025 gboolean ret = TRUE;
3027 GST_DEBUG_OBJECT (dec, "gst_audio_decoder_stop");
3029 klass = GST_AUDIO_DECODER_GET_CLASS (dec);
3032 ret = klass->stop (dec);
3036 gst_audio_decoder_reset (dec, TRUE);
3039 dec->priv->active = FALSE;
3045 gst_audio_decoder_start (GstAudioDecoder * dec)
3047 GstAudioDecoderClass *klass;
3048 gboolean ret = TRUE;
3050 GST_DEBUG_OBJECT (dec, "gst_audio_decoder_start");
3052 klass = GST_AUDIO_DECODER_GET_CLASS (dec);
3054 /* arrange clean state */
3055 gst_audio_decoder_reset (dec, TRUE);
3058 ret = klass->start (dec);
3062 dec->priv->active = TRUE;
3068 gst_audio_decoder_get_property (GObject * object, guint prop_id,
3069 GValue * value, GParamSpec * pspec)
3071 GstAudioDecoder *dec;
3073 dec = GST_AUDIO_DECODER (object);
3077 g_value_set_int64 (value, dec->priv->latency);
3079 case PROP_TOLERANCE:
3080 g_value_set_int64 (value, dec->priv->tolerance);
3083 g_value_set_boolean (value, dec->priv->plc);
3086 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
3092 gst_audio_decoder_set_property (GObject * object, guint prop_id,
3093 const GValue * value, GParamSpec * pspec)
3095 GstAudioDecoder *dec;
3097 dec = GST_AUDIO_DECODER (object);
3101 dec->priv->latency = g_value_get_int64 (value);
3103 case PROP_TOLERANCE:
3104 dec->priv->tolerance = g_value_get_int64 (value);
3107 dec->priv->plc = g_value_get_boolean (value);
3110 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
3115 static GstStateChangeReturn
3116 gst_audio_decoder_change_state (GstElement * element, GstStateChange transition)
3118 GstAudioDecoder *codec;
3119 GstAudioDecoderClass *klass;
3120 GstStateChangeReturn ret;
3122 codec = GST_AUDIO_DECODER (element);
3123 klass = GST_AUDIO_DECODER_GET_CLASS (codec);
3125 switch (transition) {
3126 case GST_STATE_CHANGE_NULL_TO_READY:
3128 if (!klass->open (codec))
3132 case GST_STATE_CHANGE_READY_TO_PAUSED:
3133 if (!gst_audio_decoder_start (codec)) {
3137 case GST_STATE_CHANGE_PAUSED_TO_PLAYING:
3143 ret = GST_ELEMENT_CLASS (parent_class)->change_state (element, transition);
3145 switch (transition) {
3146 case GST_STATE_CHANGE_PLAYING_TO_PAUSED:
3148 case GST_STATE_CHANGE_PAUSED_TO_READY:
3149 if (!gst_audio_decoder_stop (codec)) {
3153 case GST_STATE_CHANGE_READY_TO_NULL:
3155 if (!klass->close (codec))
3167 GST_ELEMENT_ERROR (codec, LIBRARY, INIT, (NULL), ("Failed to start codec"));
3168 return GST_STATE_CHANGE_FAILURE;
3172 GST_ELEMENT_ERROR (codec, LIBRARY, INIT, (NULL), ("Failed to stop codec"));
3173 return GST_STATE_CHANGE_FAILURE;
3177 GST_ELEMENT_ERROR (codec, LIBRARY, INIT, (NULL), ("Failed to open codec"));
3178 return GST_STATE_CHANGE_FAILURE;
3182 GST_ELEMENT_ERROR (codec, LIBRARY, INIT, (NULL), ("Failed to close codec"));
3183 return GST_STATE_CHANGE_FAILURE;
3188 _gst_audio_decoder_error (GstAudioDecoder * dec, gint weight,
3189 GQuark domain, gint code, gchar * txt, gchar * dbg, const gchar * file,
3190 const gchar * function, gint line)
3193 GST_WARNING_OBJECT (dec, "error: %s", txt);
3195 GST_WARNING_OBJECT (dec, "error: %s", dbg);
3196 dec->priv->error_count += weight;
3197 dec->priv->discont = TRUE;
3198 if (dec->priv->ctx.max_errors >= 0
3199 && dec->priv->ctx.max_errors < dec->priv->error_count) {
3200 gst_element_message_full (GST_ELEMENT (dec), GST_MESSAGE_ERROR, domain,
3201 code, txt, dbg, file, function, line);
3202 return GST_FLOW_ERROR;
3211 * gst_audio_decoder_get_audio_info:
3212 * @dec: a #GstAudioDecoder
3214 * Returns: a #GstAudioInfo describing the input audio format
3217 gst_audio_decoder_get_audio_info (GstAudioDecoder * dec)
3219 g_return_val_if_fail (GST_IS_AUDIO_DECODER (dec), NULL);
3221 return &dec->priv->ctx.info;
3225 * gst_audio_decoder_set_plc_aware:
3226 * @dec: a #GstAudioDecoder
3227 * @plc: new plc state
3229 * Indicates whether or not subclass handles packet loss concealment (plc).
3232 gst_audio_decoder_set_plc_aware (GstAudioDecoder * dec, gboolean plc)
3234 g_return_if_fail (GST_IS_AUDIO_DECODER (dec));
3236 dec->priv->ctx.do_plc = plc;
3240 * gst_audio_decoder_get_plc_aware:
3241 * @dec: a #GstAudioDecoder
3243 * Returns: currently configured plc handling
3246 gst_audio_decoder_get_plc_aware (GstAudioDecoder * dec)
3248 g_return_val_if_fail (GST_IS_AUDIO_DECODER (dec), 0);
3250 return dec->priv->ctx.do_plc;
3254 * gst_audio_decoder_set_estimate_rate:
3255 * @dec: a #GstAudioDecoder
3256 * @enabled: whether to enable byte to time conversion
3258 * Allows baseclass to perform byte to time estimated conversion.
3261 gst_audio_decoder_set_estimate_rate (GstAudioDecoder * dec, gboolean enabled)
3263 g_return_if_fail (GST_IS_AUDIO_DECODER (dec));
3265 dec->priv->ctx.do_estimate_rate = enabled;
3269 * gst_audio_decoder_get_estimate_rate:
3270 * @dec: a #GstAudioDecoder
3272 * Returns: currently configured byte to time conversion setting
3275 gst_audio_decoder_get_estimate_rate (GstAudioDecoder * dec)
3277 g_return_val_if_fail (GST_IS_AUDIO_DECODER (dec), 0);
3279 return dec->priv->ctx.do_estimate_rate;
3283 * gst_audio_decoder_get_delay:
3284 * @dec: a #GstAudioDecoder
3286 * Returns: currently configured decoder delay
3289 gst_audio_decoder_get_delay (GstAudioDecoder * dec)
3291 g_return_val_if_fail (GST_IS_AUDIO_DECODER (dec), 0);
3293 return dec->priv->ctx.delay;
3297 * gst_audio_decoder_set_max_errors:
3298 * @dec: a #GstAudioDecoder
3299 * @num: max tolerated errors
3301 * Sets numbers of tolerated decoder errors, where a tolerated one is then only
3302 * warned about, but more than tolerated will lead to fatal error. You can set
3303 * -1 for never returning fatal errors. Default is set to
3304 * GST_AUDIO_DECODER_MAX_ERRORS.
3307 gst_audio_decoder_set_max_errors (GstAudioDecoder * dec, gint num)
3309 g_return_if_fail (GST_IS_AUDIO_DECODER (dec));
3311 dec->priv->ctx.max_errors = num;
3315 * gst_audio_decoder_get_max_errors:
3316 * @dec: a #GstAudioDecoder
3318 * Returns: currently configured decoder tolerated error count.
3321 gst_audio_decoder_get_max_errors (GstAudioDecoder * dec)
3323 g_return_val_if_fail (GST_IS_AUDIO_DECODER (dec), 0);
3325 return dec->priv->ctx.max_errors;
3329 * gst_audio_decoder_set_latency:
3330 * @dec: a #GstAudioDecoder
3331 * @min: minimum latency
3332 * @max: maximum latency
3334 * Sets decoder latency.
3337 gst_audio_decoder_set_latency (GstAudioDecoder * dec,
3338 GstClockTime min, GstClockTime max)
3340 g_return_if_fail (GST_IS_AUDIO_DECODER (dec));
3341 g_return_if_fail (GST_CLOCK_TIME_IS_VALID (min));
3342 g_return_if_fail (min <= max);
3344 GST_OBJECT_LOCK (dec);
3345 dec->priv->ctx.min_latency = min;
3346 dec->priv->ctx.max_latency = max;
3347 GST_OBJECT_UNLOCK (dec);
3349 /* post latency message on the bus */
3350 gst_element_post_message (GST_ELEMENT (dec),
3351 gst_message_new_latency (GST_OBJECT (dec)));
3355 * gst_audio_decoder_get_latency:
3356 * @dec: a #GstAudioDecoder
3357 * @min: (out) (allow-none): a pointer to storage to hold minimum latency
3358 * @max: (out) (allow-none): a pointer to storage to hold maximum latency
3360 * Sets the variables pointed to by @min and @max to the currently configured
3364 gst_audio_decoder_get_latency (GstAudioDecoder * dec,
3365 GstClockTime * min, GstClockTime * max)
3367 g_return_if_fail (GST_IS_AUDIO_DECODER (dec));
3369 GST_OBJECT_LOCK (dec);
3371 *min = dec->priv->ctx.min_latency;
3373 *max = dec->priv->ctx.max_latency;
3374 GST_OBJECT_UNLOCK (dec);
3378 * gst_audio_decoder_get_parse_state:
3379 * @dec: a #GstAudioDecoder
3380 * @sync: (out) (optional): a pointer to a variable to hold the current sync state
3381 * @eos: (out) (optional): a pointer to a variable to hold the current eos state
3383 * Return current parsing (sync and eos) state.
3386 gst_audio_decoder_get_parse_state (GstAudioDecoder * dec,
3387 gboolean * sync, gboolean * eos)
3389 g_return_if_fail (GST_IS_AUDIO_DECODER (dec));
3392 *sync = dec->priv->ctx.sync;
3394 *eos = dec->priv->ctx.eos;
3398 * gst_audio_decoder_set_allocation_caps:
3399 * @dec: a #GstAudioDecoder
3400 * @allocation_caps: (allow-none): a #GstCaps or %NULL
3402 * Sets a caps in allocation query which are different from the set
3403 * pad's caps. Use this function before calling
3404 * gst_audio_decoder_negotiate(). Setting to %NULL the allocation
3405 * query will use the caps from the pad.
3410 gst_audio_decoder_set_allocation_caps (GstAudioDecoder * dec,
3411 GstCaps * allocation_caps)
3413 g_return_if_fail (GST_IS_AUDIO_DECODER (dec));
3415 gst_caps_replace (&dec->priv->ctx.allocation_caps, allocation_caps);
3419 * gst_audio_decoder_set_plc:
3420 * @dec: a #GstAudioDecoder
3421 * @enabled: new state
3423 * Enable or disable decoder packet loss concealment, provided subclass
3424 * and codec are capable and allow handling plc.
3429 gst_audio_decoder_set_plc (GstAudioDecoder * dec, gboolean enabled)
3431 g_return_if_fail (GST_IS_AUDIO_DECODER (dec));
3433 GST_LOG_OBJECT (dec, "enabled: %d", enabled);
3435 GST_OBJECT_LOCK (dec);
3436 dec->priv->plc = enabled;
3437 GST_OBJECT_UNLOCK (dec);
3441 * gst_audio_decoder_get_plc:
3442 * @dec: a #GstAudioDecoder
3444 * Queries decoder packet loss concealment handling.
3446 * Returns: TRUE if packet loss concealment is enabled.
3451 gst_audio_decoder_get_plc (GstAudioDecoder * dec)
3455 g_return_val_if_fail (GST_IS_AUDIO_DECODER (dec), FALSE);
3457 GST_OBJECT_LOCK (dec);
3458 result = dec->priv->plc;
3459 GST_OBJECT_UNLOCK (dec);
3465 * gst_audio_decoder_set_min_latency:
3466 * @dec: a #GstAudioDecoder
3467 * @num: new minimum latency
3469 * Sets decoder minimum aggregation latency.
3474 gst_audio_decoder_set_min_latency (GstAudioDecoder * dec, GstClockTime num)
3476 g_return_if_fail (GST_IS_AUDIO_DECODER (dec));
3478 GST_OBJECT_LOCK (dec);
3479 dec->priv->latency = num;
3480 GST_OBJECT_UNLOCK (dec);
3484 * gst_audio_decoder_get_min_latency:
3485 * @dec: a #GstAudioDecoder
3487 * Queries decoder's latency aggregation.
3489 * Returns: aggregation latency.
3494 gst_audio_decoder_get_min_latency (GstAudioDecoder * dec)
3496 GstClockTime result;
3498 g_return_val_if_fail (GST_IS_AUDIO_DECODER (dec), FALSE);
3500 GST_OBJECT_LOCK (dec);
3501 result = dec->priv->latency;
3502 GST_OBJECT_UNLOCK (dec);
3508 * gst_audio_decoder_set_tolerance:
3509 * @dec: a #GstAudioDecoder
3510 * @tolerance: new tolerance
3512 * Configures decoder audio jitter tolerance threshold.
3517 gst_audio_decoder_set_tolerance (GstAudioDecoder * dec, GstClockTime tolerance)
3519 g_return_if_fail (GST_IS_AUDIO_DECODER (dec));
3521 GST_OBJECT_LOCK (dec);
3522 dec->priv->tolerance = tolerance;
3523 GST_OBJECT_UNLOCK (dec);
3527 * gst_audio_decoder_get_tolerance:
3528 * @dec: a #GstAudioDecoder
3530 * Queries current audio jitter tolerance threshold.
3532 * Returns: decoder audio jitter tolerance threshold.
3537 gst_audio_decoder_get_tolerance (GstAudioDecoder * dec)
3539 GstClockTime result;
3541 g_return_val_if_fail (GST_IS_AUDIO_DECODER (dec), 0);
3543 GST_OBJECT_LOCK (dec);
3544 result = dec->priv->tolerance;
3545 GST_OBJECT_UNLOCK (dec);
3551 * gst_audio_decoder_set_drainable:
3552 * @dec: a #GstAudioDecoder
3553 * @enabled: new state
3555 * Configures decoder drain handling. If drainable, subclass might
3556 * be handed a NULL buffer to have it return any leftover decoded data.
3557 * Otherwise, it is not considered so capable and will only ever be passed
3563 gst_audio_decoder_set_drainable (GstAudioDecoder * dec, gboolean enabled)
3565 g_return_if_fail (GST_IS_AUDIO_DECODER (dec));
3567 GST_OBJECT_LOCK (dec);
3568 dec->priv->drainable = enabled;
3569 GST_OBJECT_UNLOCK (dec);
3573 * gst_audio_decoder_get_drainable:
3574 * @dec: a #GstAudioDecoder
3576 * Queries decoder drain handling.
3578 * Returns: TRUE if drainable handling is enabled.
3583 gst_audio_decoder_get_drainable (GstAudioDecoder * dec)
3587 g_return_val_if_fail (GST_IS_AUDIO_DECODER (dec), 0);
3589 GST_OBJECT_LOCK (dec);
3590 result = dec->priv->drainable;
3591 GST_OBJECT_UNLOCK (dec);
3597 * gst_audio_decoder_set_needs_format:
3598 * @dec: a #GstAudioDecoder
3599 * @enabled: new state
3601 * Configures decoder format needs. If enabled, subclass needs to be
3602 * negotiated with format caps before it can process any data. It will then
3603 * never be handed any data before it has been configured.
3604 * Otherwise, it might be handed data without having been configured and
3605 * is then expected being able to do so either by default
3606 * or based on the input data.
3611 gst_audio_decoder_set_needs_format (GstAudioDecoder * dec, gboolean enabled)
3613 g_return_if_fail (GST_IS_AUDIO_DECODER (dec));
3615 GST_OBJECT_LOCK (dec);
3616 dec->priv->needs_format = enabled;
3617 GST_OBJECT_UNLOCK (dec);
3621 * gst_audio_decoder_get_needs_format:
3622 * @dec: a #GstAudioDecoder
3624 * Queries decoder required format handling.
3626 * Returns: TRUE if required format handling is enabled.
3631 gst_audio_decoder_get_needs_format (GstAudioDecoder * dec)
3635 g_return_val_if_fail (GST_IS_AUDIO_DECODER (dec), FALSE);
3637 GST_OBJECT_LOCK (dec);
3638 result = dec->priv->needs_format;
3639 GST_OBJECT_UNLOCK (dec);
3645 * gst_audio_decoder_merge_tags:
3646 * @dec: a #GstAudioDecoder
3647 * @tags: (allow-none): a #GstTagList to merge, or NULL
3648 * @mode: the #GstTagMergeMode to use, usually #GST_TAG_MERGE_REPLACE
3650 * Sets the audio decoder tags and how they should be merged with any
3651 * upstream stream tags. This will override any tags previously-set
3652 * with gst_audio_decoder_merge_tags().
3654 * Note that this is provided for convenience, and the subclass is
3655 * not required to use this and can still do tag handling on its own.
3658 gst_audio_decoder_merge_tags (GstAudioDecoder * dec,
3659 const GstTagList * tags, GstTagMergeMode mode)
3661 g_return_if_fail (GST_IS_AUDIO_DECODER (dec));
3662 g_return_if_fail (tags == NULL || GST_IS_TAG_LIST (tags));
3663 g_return_if_fail (mode != GST_TAG_MERGE_UNDEFINED);
3665 GST_AUDIO_DECODER_STREAM_LOCK (dec);
3666 if (dec->priv->taglist != tags) {
3667 if (dec->priv->taglist) {
3668 gst_tag_list_unref (dec->priv->taglist);
3669 dec->priv->taglist = NULL;
3670 dec->priv->decoder_tags_merge_mode = GST_TAG_MERGE_KEEP_ALL;
3673 dec->priv->taglist = gst_tag_list_ref ((GstTagList *) tags);
3674 dec->priv->decoder_tags_merge_mode = mode;
3677 GST_DEBUG_OBJECT (dec, "setting decoder tags to %" GST_PTR_FORMAT, tags);
3678 dec->priv->taglist_changed = TRUE;
3680 GST_AUDIO_DECODER_STREAM_UNLOCK (dec);
3684 * gst_audio_decoder_allocate_output_buffer:
3685 * @dec: a #GstAudioDecoder
3686 * @size: size of the buffer
3688 * Helper function that allocates a buffer to hold an audio frame
3689 * for @dec's current output format.
3691 * Returns: (transfer full): allocated buffer
3694 gst_audio_decoder_allocate_output_buffer (GstAudioDecoder * dec, gsize size)
3696 GstBuffer *buffer = NULL;
3697 gboolean needs_reconfigure = FALSE;
3699 g_return_val_if_fail (size > 0, NULL);
3701 GST_DEBUG ("alloc src buffer");
3703 GST_AUDIO_DECODER_STREAM_LOCK (dec);
3705 needs_reconfigure = gst_pad_check_reconfigure (dec->srcpad);
3706 if (G_UNLIKELY (dec->priv->ctx.output_format_changed ||
3707 (GST_AUDIO_INFO_IS_VALID (&dec->priv->ctx.info)
3708 && needs_reconfigure))) {
3709 if (!gst_audio_decoder_negotiate_unlocked (dec)) {
3710 GST_INFO_OBJECT (dec, "Failed to negotiate, fallback allocation");
3711 gst_pad_mark_reconfigure (dec->srcpad);
3717 gst_buffer_new_allocate (dec->priv->ctx.allocator, size,
3718 &dec->priv->ctx.params);
3720 GST_INFO_OBJECT (dec, "couldn't allocate output buffer");
3724 GST_AUDIO_DECODER_STREAM_UNLOCK (dec);
3728 buffer = gst_buffer_new_allocate (NULL, size, NULL);
3729 GST_AUDIO_DECODER_STREAM_UNLOCK (dec);
3735 * gst_audio_decoder_get_allocator:
3736 * @dec: a #GstAudioDecoder
3737 * @allocator: (out) (allow-none) (transfer full): the #GstAllocator
3739 * @params: (out) (allow-none) (transfer full): the
3740 * #GstAllocationParams of @allocator
3742 * Lets #GstAudioDecoder sub-classes to know the memory @allocator
3743 * used by the base class and its @params.
3745 * Unref the @allocator after use it.
3748 gst_audio_decoder_get_allocator (GstAudioDecoder * dec,
3749 GstAllocator ** allocator, GstAllocationParams * params)
3751 g_return_if_fail (GST_IS_AUDIO_DECODER (dec));
3754 *allocator = dec->priv->ctx.allocator ?
3755 gst_object_ref (dec->priv->ctx.allocator) : NULL;
3758 *params = dec->priv->ctx.params;
3762 * gst_audio_decoder_set_use_default_pad_acceptcaps:
3763 * @decoder: a #GstAudioDecoder
3764 * @use: if the default pad accept-caps query handling should be used
3766 * Lets #GstAudioDecoder sub-classes decide if they want the sink pad
3767 * to use the default pad query handler to reply to accept-caps queries.
3769 * By setting this to true it is possible to further customize the default
3770 * handler with %GST_PAD_SET_ACCEPT_INTERSECT and
3771 * %GST_PAD_SET_ACCEPT_TEMPLATE
3776 gst_audio_decoder_set_use_default_pad_acceptcaps (GstAudioDecoder * decoder,
3779 decoder->priv->use_default_pad_acceptcaps = use;