Coverage Report

Created: 2026-05-16 06:35

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/gstreamer/subprojects/gst-plugins-base/gst-libs/gst/audio/gstaudiodecoder.c
Line
Count
Source
1
/* GStreamer
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>
7
 *
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.
12
 *
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.
17
 *
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.
22
 */
23
24
/**
25
 * SECTION:gstaudiodecoder
26
 * @title: GstAudioDecoder
27
 * @short_description: Base class for audio decoders
28
 * @see_also: #GstBaseTransform
29
 *
30
 * This base class is for audio decoders turning encoded data into
31
 * raw audio samples.
32
 *
33
 * GstAudioDecoder and subclass should cooperate as follows.
34
 *
35
 * ## Configuration
36
 *
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
41
 *     @set_format).
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.
47
 *
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.
53
 *
54
 * ## Data processing
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
62
 *       downstream.
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.
71
 *
72
 * ## Shutdown phase
73
 *
74
 *   * GstAudioDecoder class calls @stop to inform the subclass that data
75
 *     parsing will be stopped.
76
 *
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.
82
 *
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.
87
 *
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).
93
 *
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
99
 * buffer size.
100
 *
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
105
 * bitrates.
106
 *
107
 * Things that subclass need to take care of:
108
 *
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.
114
 *
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.
119
 *
120
 */
121
122
#ifdef HAVE_CONFIG_H
123
#include "config.h"
124
#endif
125
126
#include "gstaudiodecoder.h"
127
#include "gstaudioutilsprivate.h"
128
#include <gst/pbutils/descriptions.h>
129
130
#include <string.h>
131
132
GST_DEBUG_CATEGORY (audiodecoder_debug);
133
#define GST_CAT_DEFAULT audiodecoder_debug
134
135
enum
136
{
137
  LAST_SIGNAL
138
};
139
140
enum
141
{
142
  PROP_0,
143
  PROP_LATENCY,
144
  PROP_TOLERANCE,
145
  PROP_PLC,
146
  PROP_MAX_ERRORS
147
};
148
149
90
#define DEFAULT_LATENCY    0
150
90
#define DEFAULT_TOLERANCE  0
151
90
#define DEFAULT_PLC        FALSE
152
86
#define DEFAULT_DRAINABLE  TRUE
153
86
#define DEFAULT_NEEDS_FORMAT  FALSE
154
4
#define DEFAULT_MAX_ERRORS GST_AUDIO_DECODER_MAX_ERRORS
155
156
typedef struct _GstAudioDecoderContext
157
{
158
  /* last negotiated input caps */
159
  GstCaps *input_caps;
160
161
  /* (output) audio format */
162
  GstAudioInfo info;
163
  GstCaps *caps;
164
  gboolean output_format_changed;
165
166
  /* parsing state */
167
  gboolean eos;
168
  gboolean sync;
169
170
  gboolean had_output_data;
171
  gboolean had_input_data;
172
173
  /* misc */
174
  gint delay;
175
176
  /* output */
177
  gboolean do_plc;
178
  gboolean do_estimate_rate;
179
  GstCaps *allocation_caps;
180
  /* MT-protected (with LOCK) */
181
  GstClockTime min_latency;
182
  GstClockTime max_latency;
183
  /* Tracks whether the latency message was posted at least once */
184
  gboolean posted_latency_msg;
185
186
  GstAllocator *allocator;
187
  GstAllocationParams params;
188
} GstAudioDecoderContext;
189
190
struct _GstAudioDecoderPrivate
191
{
192
  /* activation status */
193
  gboolean active;
194
195
  /* input base/first ts as basis for output ts */
196
  GstClockTime base_ts;
197
  /* input samples processed and sent downstream so far (w.r.t. base_ts) */
198
  guint64 samples;
199
200
  /* collected input data */
201
  GstAdapter *adapter;
202
  /* tracking input ts for changes */
203
  GstClockTime prev_ts;
204
  guint64 prev_distance;
205
  /* frames obtained from input */
206
  GQueue frames;
207
  /* collected output data */
208
  GstAdapter *adapter_out;
209
  /* ts and duration for output data collected above */
210
  GstClockTime out_ts, out_dur;
211
  /* mark outgoing discont */
212
  gboolean discont;
213
214
  /* subclass gave all it could already */
215
  gboolean drained;
216
  /* subclass currently being forcibly drained */
217
  gboolean force;
218
  /* input_segment are output_segment identical */
219
  gboolean in_out_segment_sync;
220
  /* TRUE if we have an active set of instant rate flags */
221
  gboolean decode_flags_override;
222
  GstSegmentFlags decode_flags;
223
224
  /* expecting the buffer with DISCONT flag */
225
  gboolean expecting_discont_buf;
226
227
  /* number of samples pushed out via _finish_subframe(), resets on _finish_frame() */
228
  guint subframe_samples;
229
230
  /* input bps estimatation */
231
  /* global in bytes seen */
232
  guint64 bytes_in;
233
  /* global samples sent out */
234
  guint64 samples_out;
235
  /* bytes flushed during parsing */
236
  guint sync_flush;
237
  /* error count */
238
  gint error_count;
239
  /* max errors */
240
  gint max_errors;
241
242
  /* upstream stream tags (global tags are passed through as-is) */
243
  GstTagList *upstream_tags;
244
245
  /* subclass tags */
246
  GstTagList *taglist;          /* FIXME: rename to decoder_tags */
247
  GstTagMergeMode decoder_tags_merge_mode;
248
249
  gboolean taglist_changed;     /* FIXME: rename to tags_changed */
250
251
  /* whether circumstances allow output aggregation */
252
  gint agg;
253
254
  /* reverse playback queues */
255
  /* collect input */
256
  GList *gather;
257
  /* to-be-decoded */
258
  GList *decode;
259
  /* reversed output */
260
  GList *queued;
261
262
  /* context storage */
263
  GstAudioDecoderContext ctx;
264
265
  /* properties */
266
  GstClockTime latency;
267
  GstClockTime tolerance;
268
  gboolean plc;
269
  gboolean drainable;
270
  gboolean needs_format;
271
272
  /* pending serialized sink events, will be sent from finish_frame() */
273
  GList *pending_events;
274
275
  /* flags */
276
  gboolean use_default_pad_acceptcaps;
277
};
278
279
/* cached quark to avoid contention on the global quark table lock */
280
#define META_TAG_AUDIO meta_tag_audio_quark
281
static GQuark meta_tag_audio_quark;
282
283
static void gst_audio_decoder_finalize (GObject * object);
284
static void gst_audio_decoder_set_property (GObject * object,
285
    guint prop_id, const GValue * value, GParamSpec * pspec);
286
static void gst_audio_decoder_get_property (GObject * object,
287
    guint prop_id, GValue * value, GParamSpec * pspec);
288
289
static void gst_audio_decoder_clear_queues (GstAudioDecoder * dec);
290
static GstFlowReturn gst_audio_decoder_chain_reverse (GstAudioDecoder *
291
    dec, GstBuffer * buf);
292
293
static GstStateChangeReturn gst_audio_decoder_change_state (GstElement *
294
    element, GstStateChange transition);
295
static gboolean gst_audio_decoder_sink_eventfunc (GstAudioDecoder * dec,
296
    GstEvent * event);
297
static gboolean gst_audio_decoder_src_eventfunc (GstAudioDecoder * dec,
298
    GstEvent * event);
299
static gboolean gst_audio_decoder_sink_event (GstPad * pad, GstObject * parent,
300
    GstEvent * event);
301
static gboolean gst_audio_decoder_src_event (GstPad * pad, GstObject * parent,
302
    GstEvent * event);
303
static gboolean gst_audio_decoder_sink_setcaps (GstAudioDecoder * dec,
304
    GstCaps * caps);
305
static GstFlowReturn gst_audio_decoder_chain (GstPad * pad, GstObject * parent,
306
    GstBuffer * buf);
307
static gboolean gst_audio_decoder_src_query (GstPad * pad, GstObject * parent,
308
    GstQuery * query);
309
static gboolean gst_audio_decoder_sink_query (GstPad * pad, GstObject * parent,
310
    GstQuery * query);
311
static void gst_audio_decoder_reset (GstAudioDecoder * dec, gboolean full);
312
313
static gboolean gst_audio_decoder_decide_allocation_default (GstAudioDecoder *
314
    dec, GstQuery * query);
315
static gboolean gst_audio_decoder_propose_allocation_default (GstAudioDecoder *
316
    dec, GstQuery * query);
317
static gboolean gst_audio_decoder_negotiate_default (GstAudioDecoder * dec);
318
static gboolean gst_audio_decoder_negotiate_unlocked (GstAudioDecoder * dec);
319
static gboolean gst_audio_decoder_handle_gap (GstAudioDecoder * dec,
320
    GstEvent * event);
321
static gboolean gst_audio_decoder_sink_query_default (GstAudioDecoder * dec,
322
    GstQuery * query);
323
static gboolean gst_audio_decoder_src_query_default (GstAudioDecoder * dec,
324
    GstQuery * query);
325
326
static gboolean gst_audio_decoder_transform_meta_default (GstAudioDecoder *
327
    decoder, GstBuffer * outbuf, GstMeta * meta, GstBuffer * inbuf);
328
329
static GstFlowReturn
330
gst_audio_decoder_finish_frame_or_subframe (GstAudioDecoder * dec,
331
    GstBuffer * buf, gint frames);
332
333
static GstElementClass *parent_class = NULL;
334
static gint private_offset = 0;
335
336
static void gst_audio_decoder_class_init (GstAudioDecoderClass * klass);
337
static void gst_audio_decoder_init (GstAudioDecoder * dec,
338
    GstAudioDecoderClass * klass);
339
340
GType
341
gst_audio_decoder_get_type (void)
342
780
{
343
780
  static gsize audio_decoder_type = 0;
344
345
780
  if (g_once_init_enter (&audio_decoder_type)) {
346
4
    GType _type;
347
4
    static const GTypeInfo audio_decoder_info = {
348
4
      sizeof (GstAudioDecoderClass),
349
4
      NULL,
350
4
      NULL,
351
4
      (GClassInitFunc) gst_audio_decoder_class_init,
352
4
      NULL,
353
4
      NULL,
354
4
      sizeof (GstAudioDecoder),
355
4
      0,
356
4
      (GInstanceInitFunc) gst_audio_decoder_init,
357
4
    };
358
359
4
    _type = g_type_register_static (GST_TYPE_ELEMENT,
360
4
        "GstAudioDecoder", &audio_decoder_info, G_TYPE_FLAG_ABSTRACT);
361
362
4
    private_offset =
363
4
        g_type_add_instance_private (_type, sizeof (GstAudioDecoderPrivate));
364
365
4
    g_once_init_leave (&audio_decoder_type, _type);
366
4
  }
367
780
  return audio_decoder_type;
368
780
}
369
370
static inline GstAudioDecoderPrivate *
371
gst_audio_decoder_get_instance_private (GstAudioDecoder * self)
372
86
{
373
86
  return (G_STRUCT_MEMBER_P (self, private_offset));
374
86
}
375
376
static void
377
gst_audio_decoder_class_init (GstAudioDecoderClass * klass)
378
4
{
379
4
  GObjectClass *gobject_class;
380
4
  GstElementClass *element_class;
381
4
  GstAudioDecoderClass *audiodecoder_class;
382
383
4
  gobject_class = G_OBJECT_CLASS (klass);
384
4
  element_class = GST_ELEMENT_CLASS (klass);
385
4
  audiodecoder_class = GST_AUDIO_DECODER_CLASS (klass);
386
387
4
  parent_class = g_type_class_peek_parent (klass);
388
389
4
  if (private_offset != 0)
390
4
    g_type_class_adjust_private_offset (klass, &private_offset);
391
392
4
  GST_DEBUG_CATEGORY_INIT (audiodecoder_debug, "audiodecoder", 0,
393
4
      "audio decoder base class");
394
395
4
  gobject_class->set_property = gst_audio_decoder_set_property;
396
4
  gobject_class->get_property = gst_audio_decoder_get_property;
397
4
  gobject_class->finalize = gst_audio_decoder_finalize;
398
399
4
  element_class->change_state =
400
4
      GST_DEBUG_FUNCPTR (gst_audio_decoder_change_state);
401
402
  /* Properties */
403
4
  g_object_class_install_property (gobject_class, PROP_LATENCY,
404
4
      g_param_spec_int64 ("min-latency", "Minimum Latency",
405
4
          "Aggregate output data to a minimum of latency time (ns)",
406
4
          0, G_MAXINT64, DEFAULT_LATENCY,
407
4
          G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
408
409
4
  g_object_class_install_property (gobject_class, PROP_TOLERANCE,
410
4
      g_param_spec_int64 ("tolerance", "Tolerance",
411
4
          "Perfect ts while timestamp jitter/imperfection within tolerance (ns)",
412
4
          0, G_MAXINT64, DEFAULT_TOLERANCE,
413
4
          G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
414
415
4
  g_object_class_install_property (gobject_class, PROP_PLC,
416
4
      g_param_spec_boolean ("plc", "Packet Loss Concealment",
417
4
          "Perform packet loss concealment (if supported)",
418
4
          DEFAULT_PLC, G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
419
420
  /**
421
   * GstAudioDecoder:max-errors:
422
   *
423
   * Maximum number of tolerated consecutive decode errors. See
424
   * gst_audio_decoder_set_max_errors() for more details.
425
   *
426
   * Since: 1.18
427
   */
428
4
  g_object_class_install_property (gobject_class, PROP_MAX_ERRORS,
429
4
      g_param_spec_int ("max-errors", "Max errors",
430
4
          "Max consecutive decoder errors before returning flow error",
431
4
          -1, G_MAXINT, DEFAULT_MAX_ERRORS,
432
4
          G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
433
434
4
  audiodecoder_class->sink_event =
435
4
      GST_DEBUG_FUNCPTR (gst_audio_decoder_sink_eventfunc);
436
4
  audiodecoder_class->src_event =
437
4
      GST_DEBUG_FUNCPTR (gst_audio_decoder_src_eventfunc);
438
4
  audiodecoder_class->propose_allocation =
439
4
      GST_DEBUG_FUNCPTR (gst_audio_decoder_propose_allocation_default);
440
4
  audiodecoder_class->decide_allocation =
441
4
      GST_DEBUG_FUNCPTR (gst_audio_decoder_decide_allocation_default);
442
4
  audiodecoder_class->negotiate =
443
4
      GST_DEBUG_FUNCPTR (gst_audio_decoder_negotiate_default);
444
4
  audiodecoder_class->sink_query =
445
4
      GST_DEBUG_FUNCPTR (gst_audio_decoder_sink_query_default);
446
4
  audiodecoder_class->src_query =
447
4
      GST_DEBUG_FUNCPTR (gst_audio_decoder_src_query_default);
448
4
  audiodecoder_class->transform_meta =
449
4
      GST_DEBUG_FUNCPTR (gst_audio_decoder_transform_meta_default);
450
451
4
  meta_tag_audio_quark = g_quark_from_static_string (GST_META_TAG_AUDIO_STR);
452
4
}
453
454
static void
455
gst_audio_decoder_init (GstAudioDecoder * dec, GstAudioDecoderClass * klass)
456
86
{
457
86
  GstPadTemplate *pad_template;
458
459
86
  GST_DEBUG_OBJECT (dec, "gst_audio_decoder_init");
460
461
86
  dec->priv = gst_audio_decoder_get_instance_private (dec);
462
463
  /* Setup sink pad */
464
86
  pad_template =
465
86
      gst_element_class_get_pad_template (GST_ELEMENT_CLASS (klass), "sink");
466
86
  g_return_if_fail (pad_template != NULL);
467
468
86
  dec->sinkpad = gst_pad_new_from_template (pad_template, "sink");
469
86
  gst_pad_set_event_function (dec->sinkpad,
470
86
      GST_DEBUG_FUNCPTR (gst_audio_decoder_sink_event));
471
86
  gst_pad_set_chain_function (dec->sinkpad,
472
86
      GST_DEBUG_FUNCPTR (gst_audio_decoder_chain));
473
86
  gst_pad_set_query_function (dec->sinkpad,
474
86
      GST_DEBUG_FUNCPTR (gst_audio_decoder_sink_query));
475
86
  gst_element_add_pad (GST_ELEMENT (dec), dec->sinkpad);
476
86
  GST_DEBUG_OBJECT (dec, "sinkpad created");
477
478
  /* Setup source pad */
479
86
  pad_template =
480
86
      gst_element_class_get_pad_template (GST_ELEMENT_CLASS (klass), "src");
481
86
  g_return_if_fail (pad_template != NULL);
482
483
86
  dec->srcpad = gst_pad_new_from_template (pad_template, "src");
484
86
  gst_pad_set_event_function (dec->srcpad,
485
86
      GST_DEBUG_FUNCPTR (gst_audio_decoder_src_event));
486
86
  gst_pad_set_query_function (dec->srcpad,
487
86
      GST_DEBUG_FUNCPTR (gst_audio_decoder_src_query));
488
86
  gst_element_add_pad (GST_ELEMENT (dec), dec->srcpad);
489
86
  GST_DEBUG_OBJECT (dec, "srcpad created");
490
491
86
  dec->priv->adapter = gst_adapter_new ();
492
86
  dec->priv->adapter_out = gst_adapter_new ();
493
86
  g_queue_init (&dec->priv->frames);
494
495
86
  g_rec_mutex_init (&dec->stream_lock);
496
497
  /* property default */
498
86
  dec->priv->latency = DEFAULT_LATENCY;
499
86
  dec->priv->tolerance = DEFAULT_TOLERANCE;
500
86
  dec->priv->plc = DEFAULT_PLC;
501
86
  dec->priv->drainable = DEFAULT_DRAINABLE;
502
86
  dec->priv->needs_format = DEFAULT_NEEDS_FORMAT;
503
86
  dec->priv->max_errors = GST_AUDIO_DECODER_MAX_ERRORS;
504
505
  /* init state */
506
86
  dec->priv->ctx.min_latency = 0;
507
86
  dec->priv->ctx.max_latency = 0;
508
86
  gst_audio_decoder_reset (dec, TRUE);
509
86
  GST_DEBUG_OBJECT (dec, "init ok");
510
86
}
511
512
static void
513
gst_audio_decoder_reset (GstAudioDecoder * dec, gboolean full)
514
808
{
515
808
  GST_DEBUG_OBJECT (dec, "gst_audio_decoder_reset");
516
517
808
  GST_AUDIO_DECODER_STREAM_LOCK (dec);
518
519
808
  if (full) {
520
258
    dec->priv->active = FALSE;
521
258
    GST_OBJECT_LOCK (dec);
522
258
    dec->priv->bytes_in = 0;
523
258
    dec->priv->samples_out = 0;
524
258
    GST_OBJECT_UNLOCK (dec);
525
258
    dec->priv->agg = -1;
526
258
    dec->priv->error_count = 0;
527
258
    gst_audio_decoder_clear_queues (dec);
528
529
258
    if (dec->priv->taglist) {
530
72
      gst_tag_list_unref (dec->priv->taglist);
531
72
      dec->priv->taglist = NULL;
532
72
    }
533
258
    dec->priv->decoder_tags_merge_mode = GST_TAG_MERGE_KEEP_ALL;
534
258
    if (dec->priv->upstream_tags) {
535
72
      gst_tag_list_unref (dec->priv->upstream_tags);
536
72
      dec->priv->upstream_tags = NULL;
537
72
    }
538
258
    dec->priv->taglist_changed = FALSE;
539
540
258
    gst_segment_init (&dec->input_segment, GST_FORMAT_TIME);
541
258
    gst_segment_init (&dec->output_segment, GST_FORMAT_TIME);
542
258
    dec->priv->in_out_segment_sync = TRUE;
543
544
258
    g_list_foreach (dec->priv->pending_events, (GFunc) gst_event_unref, NULL);
545
258
    g_list_free (dec->priv->pending_events);
546
258
    dec->priv->pending_events = NULL;
547
548
258
    if (dec->priv->ctx.allocator)
549
0
      gst_object_unref (dec->priv->ctx.allocator);
550
551
258
    GST_OBJECT_LOCK (dec);
552
258
    dec->priv->decode_flags_override = FALSE;
553
258
    gst_caps_replace (&dec->priv->ctx.input_caps, NULL);
554
258
    gst_caps_replace (&dec->priv->ctx.caps, NULL);
555
258
    gst_caps_replace (&dec->priv->ctx.allocation_caps, NULL);
556
557
258
    memset (&dec->priv->ctx, 0, sizeof (dec->priv->ctx));
558
559
258
    gst_audio_info_init (&dec->priv->ctx.info);
560
258
    dec->priv->ctx.posted_latency_msg = FALSE;
561
258
    GST_OBJECT_UNLOCK (dec);
562
258
    dec->priv->ctx.had_output_data = FALSE;
563
258
    dec->priv->ctx.had_input_data = FALSE;
564
258
  }
565
566
808
  g_queue_foreach (&dec->priv->frames, (GFunc) gst_buffer_unref, NULL);
567
808
  g_queue_clear (&dec->priv->frames);
568
808
  gst_adapter_clear (dec->priv->adapter);
569
808
  gst_adapter_clear (dec->priv->adapter_out);
570
808
  dec->priv->out_ts = GST_CLOCK_TIME_NONE;
571
808
  dec->priv->out_dur = 0;
572
808
  dec->priv->prev_ts = GST_CLOCK_TIME_NONE;
573
808
  dec->priv->prev_distance = 0;
574
808
  dec->priv->drained = TRUE;
575
808
  dec->priv->base_ts = GST_CLOCK_TIME_NONE;
576
808
  dec->priv->samples = 0;
577
808
  dec->priv->discont = TRUE;
578
808
  dec->priv->sync_flush = FALSE;
579
580
808
  GST_AUDIO_DECODER_STREAM_UNLOCK (dec);
581
808
}
582
583
static void
584
gst_audio_decoder_finalize (GObject * object)
585
86
{
586
86
  GstAudioDecoder *dec;
587
588
86
  g_return_if_fail (GST_IS_AUDIO_DECODER (object));
589
86
  dec = GST_AUDIO_DECODER (object);
590
591
86
  if (dec->priv->adapter) {
592
86
    g_object_unref (dec->priv->adapter);
593
86
  }
594
86
  if (dec->priv->adapter_out) {
595
86
    g_object_unref (dec->priv->adapter_out);
596
86
  }
597
598
86
  g_rec_mutex_clear (&dec->stream_lock);
599
600
86
  G_OBJECT_CLASS (parent_class)->finalize (object);
601
86
}
602
603
static GstEvent *
604
gst_audio_decoder_create_merged_tags_event (GstAudioDecoder * dec)
605
140
{
606
140
  GstTagList *merged_tags;
607
608
140
  GST_LOG_OBJECT (dec, "upstream : %" GST_PTR_FORMAT, dec->priv->upstream_tags);
609
140
  GST_LOG_OBJECT (dec, "decoder  : %" GST_PTR_FORMAT, dec->priv->taglist);
610
140
  GST_LOG_OBJECT (dec, "mode     : %d", dec->priv->decoder_tags_merge_mode);
611
612
140
  merged_tags =
613
140
      gst_tag_list_merge (dec->priv->upstream_tags,
614
140
      dec->priv->taglist, dec->priv->decoder_tags_merge_mode);
615
616
140
  GST_DEBUG_OBJECT (dec, "merged   : %" GST_PTR_FORMAT, merged_tags);
617
618
140
  if (merged_tags == NULL)
619
0
    return NULL;
620
621
140
  if (gst_tag_list_is_empty (merged_tags)) {
622
0
    gst_tag_list_unref (merged_tags);
623
0
    return NULL;
624
0
  }
625
626
140
  return gst_event_new_tag (merged_tags);
627
140
}
628
629
static gboolean
630
gst_audio_decoder_push_event (GstAudioDecoder * dec, GstEvent * event)
631
509
{
632
509
  switch (GST_EVENT_TYPE (event)) {
633
81
    case GST_EVENT_SEGMENT:{
634
81
      GstSegment seg;
635
636
81
      GST_AUDIO_DECODER_STREAM_LOCK (dec);
637
81
      gst_event_copy_segment (event, &seg);
638
639
81
      GST_DEBUG_OBJECT (dec, "starting segment %" GST_SEGMENT_FORMAT, &seg);
640
641
81
      dec->output_segment = seg;
642
81
      dec->priv->in_out_segment_sync =
643
81
          gst_segment_is_equal (&dec->input_segment, &seg);
644
81
      GST_AUDIO_DECODER_STREAM_UNLOCK (dec);
645
81
      break;
646
0
    }
647
428
    default:
648
428
      break;
649
509
  }
650
651
509
  return gst_pad_push_event (dec->srcpad, event);
652
509
}
653
654
static gboolean
655
gst_audio_decoder_negotiate_default (GstAudioDecoder * dec)
656
97
{
657
97
  GstAudioDecoderClass *klass;
658
97
  gboolean res = TRUE;
659
97
  GstCaps *caps;
660
97
  GstCaps *prevcaps;
661
97
  GstQuery *query = NULL;
662
97
  GstAllocator *allocator;
663
97
  GstAllocationParams params;
664
665
97
  g_return_val_if_fail (GST_IS_AUDIO_DECODER (dec), FALSE);
666
97
  g_return_val_if_fail (GST_AUDIO_INFO_IS_VALID (&dec->priv->ctx.info), FALSE);
667
97
  g_return_val_if_fail (GST_IS_CAPS (dec->priv->ctx.caps), FALSE);
668
669
97
  klass = GST_AUDIO_DECODER_GET_CLASS (dec);
670
671
97
  caps = dec->priv->ctx.caps;
672
97
  if (dec->priv->ctx.allocation_caps == NULL)
673
68
    dec->priv->ctx.allocation_caps = gst_caps_ref (caps);
674
675
97
  GST_DEBUG_OBJECT (dec, "setting src caps %" GST_PTR_FORMAT, caps);
676
677
97
  if (dec->priv->pending_events) {
678
97
    GList **pending_events, *l;
679
680
97
    pending_events = &dec->priv->pending_events;
681
682
97
    GST_DEBUG_OBJECT (dec, "Pushing pending events");
683
388
    for (l = *pending_events; l;) {
684
291
      GstEvent *event = GST_EVENT (l->data);
685
291
      GList *tmp;
686
687
291
      if (GST_EVENT_TYPE (event) < GST_EVENT_CAPS) {
688
0
        gst_audio_decoder_push_event (dec, l->data);
689
0
        tmp = l;
690
0
        l = l->next;
691
0
        *pending_events = g_list_delete_link (*pending_events, tmp);
692
291
      } else {
693
291
        l = l->next;
694
291
      }
695
291
    }
696
97
  }
697
698
97
  prevcaps = gst_pad_get_current_caps (dec->srcpad);
699
97
  if (!prevcaps || !gst_caps_is_equal (prevcaps, caps))
700
68
    res = gst_pad_set_caps (dec->srcpad, caps);
701
97
  if (prevcaps)
702
29
    gst_caps_unref (prevcaps);
703
704
97
  if (!res)
705
0
    goto done;
706
97
  dec->priv->ctx.output_format_changed = FALSE;
707
708
97
  query = gst_query_new_allocation (dec->priv->ctx.allocation_caps, TRUE);
709
97
  if (!gst_pad_peer_query (dec->srcpad, query)) {
710
97
    GST_DEBUG_OBJECT (dec, "didn't get downstream ALLOCATION hints");
711
97
  }
712
713
97
  g_assert (klass->decide_allocation != NULL);
714
97
  res = klass->decide_allocation (dec, query);
715
716
97
  GST_DEBUG_OBJECT (dec, "ALLOCATION (%d) params: %" GST_PTR_FORMAT, res,
717
97
      query);
718
719
97
  if (!res)
720
0
    goto no_decide_allocation;
721
722
  /* we got configuration from our peer or the decide_allocation method,
723
   * parse them */
724
97
  if (gst_query_get_n_allocation_params (query) > 0) {
725
97
    gst_query_parse_nth_allocation_param (query, 0, &allocator, &params);
726
97
  } else {
727
0
    allocator = NULL;
728
0
    gst_allocation_params_init (&params);
729
0
  }
730
731
97
  if (dec->priv->ctx.allocator)
732
0
    gst_object_unref (dec->priv->ctx.allocator);
733
97
  dec->priv->ctx.allocator = allocator;
734
97
  dec->priv->ctx.params = params;
735
736
97
done:
737
738
97
  if (query)
739
97
    gst_query_unref (query);
740
741
97
  return res;
742
743
  /* ERRORS */
744
0
no_decide_allocation:
745
0
  {
746
0
    GST_WARNING_OBJECT (dec, "Subclass failed to decide allocation");
747
0
    goto done;
748
97
  }
749
97
}
750
751
static gboolean
752
gst_audio_decoder_negotiate_unlocked (GstAudioDecoder * dec)
753
97
{
754
97
  GstAudioDecoderClass *klass = GST_AUDIO_DECODER_GET_CLASS (dec);
755
97
  gboolean ret = TRUE;
756
757
97
  if (G_LIKELY (klass->negotiate))
758
97
    ret = klass->negotiate (dec);
759
760
97
  return ret;
761
97
}
762
763
/**
764
 * gst_audio_decoder_negotiate:
765
 * @dec: a #GstAudioDecoder
766
 *
767
 * Negotiate with downstream elements to currently configured #GstAudioInfo.
768
 * Unmark GST_PAD_FLAG_NEED_RECONFIGURE in any case. But mark it again if
769
 * negotiate fails.
770
 *
771
 * Returns: %TRUE if the negotiation succeeded, else %FALSE.
772
 */
773
gboolean
774
gst_audio_decoder_negotiate (GstAudioDecoder * dec)
775
0
{
776
0
  GstAudioDecoderClass *klass;
777
0
  gboolean res = TRUE;
778
779
0
  g_return_val_if_fail (GST_IS_AUDIO_DECODER (dec), FALSE);
780
781
0
  klass = GST_AUDIO_DECODER_GET_CLASS (dec);
782
783
0
  GST_AUDIO_DECODER_STREAM_LOCK (dec);
784
0
  gst_pad_check_reconfigure (dec->srcpad);
785
0
  if (klass->negotiate) {
786
0
    res = klass->negotiate (dec);
787
0
    if (!res)
788
0
      gst_pad_mark_reconfigure (dec->srcpad);
789
0
  }
790
0
  GST_AUDIO_DECODER_STREAM_UNLOCK (dec);
791
792
0
  return res;
793
0
}
794
795
/**
796
 * gst_audio_decoder_set_output_format:
797
 * @dec: a #GstAudioDecoder
798
 * @info: #GstAudioInfo
799
 *
800
 * Configure output info on the srcpad of @dec.
801
 *
802
 * Returns: %TRUE on success.
803
 **/
804
gboolean
805
gst_audio_decoder_set_output_format (GstAudioDecoder * dec,
806
    const GstAudioInfo * info)
807
73
{
808
73
  gboolean res = TRUE;
809
73
  GstCaps *caps = NULL;
810
811
73
  g_return_val_if_fail (GST_IS_AUDIO_DECODER (dec), FALSE);
812
73
  g_return_val_if_fail (GST_AUDIO_INFO_IS_VALID (info), FALSE);
813
814
  /* If the audio info can't be converted to caps,
815
   * it was invalid */
816
73
  caps = gst_audio_info_to_caps (info);
817
73
  if (!caps) {
818
0
    GST_WARNING_OBJECT (dec, "invalid output format");
819
0
    return FALSE;
820
0
  }
821
822
73
  res = gst_audio_decoder_set_output_caps (dec, caps);
823
73
  gst_caps_unref (caps);
824
825
73
  return res;
826
73
}
827
828
/**
829
 * gst_audio_decoder_set_output_caps:
830
 * @dec: a #GstAudioDecoder
831
 * @caps: (transfer none): (fixed) #GstCaps
832
 *
833
 * Configure output caps on the srcpad of @dec. Similar to
834
 * gst_audio_decoder_set_output_format(), but allows subclasses to specify
835
 * output caps that can't be expressed via #GstAudioInfo e.g. caps that have
836
 * caps features.
837
 *
838
 * Returns: %TRUE on success.
839
 *
840
 * Since: 1.16
841
 **/
842
gboolean
843
gst_audio_decoder_set_output_caps (GstAudioDecoder * dec, GstCaps * caps)
844
73
{
845
73
  gboolean res = TRUE;
846
73
  guint old_rate;
847
73
  GstCaps *templ_caps;
848
73
  GstAudioInfo info;
849
850
73
  g_return_val_if_fail (GST_IS_AUDIO_DECODER (dec), FALSE);
851
852
73
  GST_DEBUG_OBJECT (dec, "Setting srcpad caps %" GST_PTR_FORMAT, caps);
853
854
73
  GST_AUDIO_DECODER_STREAM_LOCK (dec);
855
856
73
  if (!gst_caps_is_fixed (caps))
857
0
    goto refuse_caps;
858
859
  /* check if caps can be parsed */
860
73
  if (!gst_audio_info_from_caps (&info, caps))
861
0
    goto refuse_caps;
862
863
  /* Only allow caps that are a subset of the template caps */
864
73
  templ_caps = gst_pad_get_pad_template_caps (dec->srcpad);
865
73
  if (!gst_caps_is_subset (caps, templ_caps)) {
866
0
    GST_WARNING_OBJECT (dec, "Requested output format %" GST_PTR_FORMAT
867
0
        " do not match template %" GST_PTR_FORMAT, caps, templ_caps);
868
0
    gst_caps_unref (templ_caps);
869
0
    goto refuse_caps;
870
0
  }
871
73
  gst_caps_unref (templ_caps);
872
873
  /* adjust ts tracking to new sample rate */
874
73
  old_rate = GST_AUDIO_INFO_RATE (&dec->priv->ctx.info);
875
73
  if (GST_CLOCK_TIME_IS_VALID (dec->priv->base_ts) && old_rate) {
876
0
    dec->priv->base_ts +=
877
0
        GST_FRAMES_TO_CLOCK_TIME (dec->priv->samples, old_rate);
878
0
    dec->priv->samples = 0;
879
0
  }
880
881
  /* copy the GstAudioInfo */
882
73
  GST_OBJECT_LOCK (dec);
883
73
  dec->priv->ctx.info = info;
884
73
  GST_OBJECT_UNLOCK (dec);
885
886
73
  gst_caps_replace (&dec->priv->ctx.caps, caps);
887
73
  dec->priv->ctx.output_format_changed = TRUE;
888
889
73
done:
890
73
  GST_AUDIO_DECODER_STREAM_UNLOCK (dec);
891
892
73
  return res;
893
894
  /* ERRORS */
895
0
refuse_caps:
896
0
  {
897
0
    GST_WARNING_OBJECT (dec, "invalid output format");
898
0
    res = FALSE;
899
0
    goto done;
900
73
  }
901
73
}
902
903
static gboolean
904
gst_audio_decoder_sink_setcaps (GstAudioDecoder * dec, GstCaps * caps)
905
166
{
906
166
  GstAudioDecoderClass *klass;
907
166
  gboolean res = TRUE;
908
909
166
  klass = GST_AUDIO_DECODER_GET_CLASS (dec);
910
911
166
  GST_DEBUG_OBJECT (dec, "caps: %" GST_PTR_FORMAT, caps);
912
913
166
  GST_AUDIO_DECODER_STREAM_LOCK (dec);
914
915
166
  if (dec->priv->ctx.input_caps
916
82
      && gst_caps_is_equal (dec->priv->ctx.input_caps, caps)) {
917
82
    GST_DEBUG_OBJECT (dec, "Caps did not change, not setting again");
918
82
    goto done;
919
82
  }
920
921
  /* NOTE pbutils only needed here */
922
  /* TODO maybe (only) upstream demuxer/parser etc should handle this ? */
923
#if 0
924
  if (!dec->priv->taglist)
925
    dec->priv->taglist = gst_tag_list_new ();
926
  dec->priv->taglist = gst_tag_list_make_writable (dec->priv->taglist);
927
  gst_pb_utils_add_codec_description_to_tag_list (dec->priv->taglist,
928
      GST_TAG_AUDIO_CODEC, caps);
929
  dec->priv->taglist_changed = TRUE;
930
#endif
931
932
84
  if (klass->set_format)
933
84
    res = klass->set_format (dec, caps);
934
935
84
  if (res)
936
84
    gst_caps_replace (&dec->priv->ctx.input_caps, caps);
937
938
166
done:
939
166
  GST_AUDIO_DECODER_STREAM_UNLOCK (dec);
940
941
166
  return res;
942
84
}
943
944
static void
945
gst_audio_decoder_setup (GstAudioDecoder * dec)
946
82
{
947
82
  GstQuery *query;
948
82
  gboolean res;
949
950
  /* check if in live pipeline, then latency messing is no-no */
951
82
  query = gst_query_new_latency ();
952
82
  res = gst_pad_peer_query (dec->sinkpad, query);
953
82
  if (res) {
954
82
    gst_query_parse_latency (query, &res, NULL, NULL);
955
82
    res = !res;
956
82
  }
957
82
  gst_query_unref (query);
958
959
  /* normalize to bool */
960
82
  dec->priv->agg = !!res;
961
82
}
962
963
static GstFlowReturn
964
gst_audio_decoder_push_forward (GstAudioDecoder * dec, GstBuffer * buf)
965
68
{
966
68
  GstAudioDecoderClass *klass;
967
68
  GstAudioDecoderPrivate *priv;
968
68
  GstAudioDecoderContext *ctx;
969
68
  GstFlowReturn ret = GST_FLOW_OK;
970
68
  GstClockTime ts;
971
972
68
  klass = GST_AUDIO_DECODER_GET_CLASS (dec);
973
68
  priv = dec->priv;
974
68
  ctx = &dec->priv->ctx;
975
976
68
  g_return_val_if_fail (ctx->info.bpf != 0, GST_FLOW_ERROR);
977
978
68
  if (G_UNLIKELY (!buf)) {
979
0
    g_assert_not_reached ();
980
0
    return GST_FLOW_OK;
981
0
  }
982
983
68
  ctx->had_output_data = TRUE;
984
68
  ts = GST_BUFFER_PTS (buf);
985
986
68
  GST_LOG_OBJECT (dec,
987
68
      "clipping buffer of size %" G_GSIZE_FORMAT " with ts %" GST_TIME_FORMAT
988
68
      ", duration %" GST_TIME_FORMAT, gst_buffer_get_size (buf),
989
68
      GST_TIME_ARGS (GST_BUFFER_PTS (buf)),
990
68
      GST_TIME_ARGS (GST_BUFFER_DURATION (buf)));
991
992
  /* clip buffer */
993
68
  buf = gst_audio_buffer_clip (buf, &dec->output_segment, ctx->info.rate,
994
68
      ctx->info.bpf);
995
68
  if (G_UNLIKELY (!buf)) {
996
0
    GST_DEBUG_OBJECT (dec, "no data after clipping to segment");
997
    /* only check and return EOS if upstream still
998
     * in the same segment and interested as such */
999
0
    if (dec->priv->in_out_segment_sync) {
1000
0
      if (dec->output_segment.rate >= 0) {
1001
0
        if (ts >= dec->output_segment.stop)
1002
0
          ret = GST_FLOW_EOS;
1003
0
      } else if (ts < dec->output_segment.start) {
1004
0
        ret = GST_FLOW_EOS;
1005
0
      }
1006
0
    }
1007
0
    goto exit;
1008
0
  }
1009
1010
  /* decorate */
1011
68
  if (G_UNLIKELY (priv->discont)) {
1012
68
    GST_LOG_OBJECT (dec, "marking discont");
1013
68
    GST_BUFFER_FLAG_SET (buf, GST_BUFFER_FLAG_DISCONT);
1014
68
    priv->discont = FALSE;
1015
68
  }
1016
1017
  /* track where we are */
1018
68
  if (G_LIKELY (GST_BUFFER_PTS_IS_VALID (buf))) {
1019
    /* duration should always be valid for raw audio */
1020
68
    g_assert (GST_BUFFER_DURATION_IS_VALID (buf));
1021
68
    dec->output_segment.position =
1022
68
        GST_BUFFER_PTS (buf) + GST_BUFFER_DURATION (buf);
1023
68
  }
1024
1025
68
  if (klass->pre_push) {
1026
    /* last chance for subclass to do some dirty stuff */
1027
0
    ret = klass->pre_push (dec, &buf);
1028
0
    if (ret != GST_FLOW_OK || !buf) {
1029
0
      GST_DEBUG_OBJECT (dec, "subclass returned %s, buf %p",
1030
0
          gst_flow_get_name (ret), buf);
1031
0
      if (buf)
1032
0
        gst_buffer_unref (buf);
1033
0
      goto exit;
1034
0
    }
1035
0
  }
1036
1037
68
  GST_LOG_OBJECT (dec,
1038
68
      "pushing buffer of size %" G_GSIZE_FORMAT " with ts %" GST_TIME_FORMAT
1039
68
      ", duration %" GST_TIME_FORMAT, gst_buffer_get_size (buf),
1040
68
      GST_TIME_ARGS (GST_BUFFER_PTS (buf)),
1041
68
      GST_TIME_ARGS (GST_BUFFER_DURATION (buf)));
1042
1043
68
  ret = gst_pad_push (dec->srcpad, buf);
1044
1045
68
exit:
1046
68
  return ret;
1047
68
}
1048
1049
/* mini aggregator combining output buffers into fewer larger ones,
1050
 * if so allowed/configured */
1051
static GstFlowReturn
1052
gst_audio_decoder_output (GstAudioDecoder * dec, GstBuffer * buf)
1053
402
{
1054
402
  GstAudioDecoderPrivate *priv;
1055
402
  GstFlowReturn ret = GST_FLOW_OK;
1056
402
  GstBuffer *inbuf = NULL;
1057
1058
402
  priv = dec->priv;
1059
1060
402
  if (G_UNLIKELY (priv->agg < 0))
1061
82
    gst_audio_decoder_setup (dec);
1062
1063
402
  if (G_LIKELY (buf)) {
1064
68
    GST_LOG_OBJECT (dec,
1065
68
        "output buffer of size %" G_GSIZE_FORMAT " with ts %" GST_TIME_FORMAT
1066
68
        ", duration %" GST_TIME_FORMAT, gst_buffer_get_size (buf),
1067
68
        GST_TIME_ARGS (GST_BUFFER_PTS (buf)),
1068
68
        GST_TIME_ARGS (GST_BUFFER_DURATION (buf)));
1069
68
  }
1070
1071
402
again:
1072
402
  inbuf = NULL;
1073
402
  if (priv->agg && dec->priv->latency > 0 &&
1074
0
      priv->ctx.info.layout == GST_AUDIO_LAYOUT_INTERLEAVED) {
1075
0
    gint av;
1076
0
    gboolean assemble = FALSE;
1077
0
    const GstClockTimeDiff tol = 10 * GST_MSECOND;
1078
0
    GstClockTimeDiff diff = -100 * GST_MSECOND;
1079
1080
0
    av = gst_adapter_available (priv->adapter_out);
1081
0
    if (G_UNLIKELY (!buf)) {
1082
      /* forcibly send current */
1083
0
      assemble = TRUE;
1084
0
      GST_LOG_OBJECT (dec, "forcing fragment flush");
1085
0
    } else if (av && (!GST_BUFFER_PTS_IS_VALID (buf) ||
1086
0
            !GST_CLOCK_TIME_IS_VALID (priv->out_ts) ||
1087
0
            ((diff = GST_CLOCK_DIFF (GST_BUFFER_PTS (buf),
1088
0
                        priv->out_ts + priv->out_dur)) > tol) || diff < -tol)) {
1089
0
      assemble = TRUE;
1090
0
      GST_LOG_OBJECT (dec, "buffer %d ms apart from current fragment",
1091
0
          (gint) (diff / GST_MSECOND));
1092
0
    } else {
1093
      /* add or start collecting */
1094
0
      if (!av) {
1095
0
        GST_LOG_OBJECT (dec, "starting new fragment");
1096
0
        priv->out_ts = GST_BUFFER_PTS (buf);
1097
0
      } else {
1098
0
        GST_LOG_OBJECT (dec, "adding to fragment");
1099
0
      }
1100
0
      gst_adapter_push (priv->adapter_out, buf);
1101
0
      priv->out_dur += GST_BUFFER_DURATION (buf);
1102
0
      av += gst_buffer_get_size (buf);
1103
0
      buf = NULL;
1104
0
    }
1105
0
    if (priv->out_dur > dec->priv->latency)
1106
0
      assemble = TRUE;
1107
0
    if (av && assemble) {
1108
0
      GST_LOG_OBJECT (dec, "assembling fragment");
1109
0
      inbuf = buf;
1110
0
      buf = gst_adapter_take_buffer (priv->adapter_out, av);
1111
0
      GST_BUFFER_PTS (buf) = priv->out_ts;
1112
0
      GST_BUFFER_DURATION (buf) = priv->out_dur;
1113
0
      priv->out_ts = GST_CLOCK_TIME_NONE;
1114
0
      priv->out_dur = 0;
1115
0
    }
1116
0
  }
1117
1118
402
  if (G_LIKELY (buf)) {
1119
68
    if (dec->output_segment.rate > 0.0) {
1120
68
      ret = gst_audio_decoder_push_forward (dec, buf);
1121
68
      GST_LOG_OBJECT (dec, "buffer pushed: %s", gst_flow_get_name (ret));
1122
68
    } else {
1123
0
      ret = GST_FLOW_OK;
1124
0
      priv->queued = g_list_prepend (priv->queued, buf);
1125
0
      GST_LOG_OBJECT (dec, "buffer queued");
1126
0
    }
1127
1128
68
    if (inbuf) {
1129
0
      buf = inbuf;
1130
0
      goto again;
1131
0
    }
1132
68
  }
1133
1134
402
  return ret;
1135
402
}
1136
1137
static void
1138
send_pending_events (GstAudioDecoder * dec)
1139
81
{
1140
81
  GstAudioDecoderPrivate *priv = dec->priv;
1141
81
  GList *pending_events, *l;
1142
1143
81
  pending_events = priv->pending_events;
1144
81
  priv->pending_events = NULL;
1145
1146
81
  GST_DEBUG_OBJECT (dec, "Pushing pending events");
1147
314
  for (l = pending_events; l; l = l->next)
1148
233
    gst_audio_decoder_push_event (dec, l->data);
1149
81
  g_list_free (pending_events);
1150
81
}
1151
1152
/* Iterate the list of pending events, and ensure
1153
 * the current output segment is up to date for
1154
 * decoding */
1155
static void
1156
apply_pending_events (GstAudioDecoder * dec)
1157
334
{
1158
334
  GstAudioDecoderPrivate *priv = dec->priv;
1159
334
  GList *l;
1160
1161
334
  GST_DEBUG_OBJECT (dec, "Applying pending segments");
1162
1.23k
  for (l = priv->pending_events; l; l = l->next) {
1163
905
    GstEvent *event = GST_EVENT (l->data);
1164
905
    switch (GST_EVENT_TYPE (event)) {
1165
305
      case GST_EVENT_SEGMENT:{
1166
305
        GstSegment seg;
1167
1168
305
        GST_AUDIO_DECODER_STREAM_LOCK (dec);
1169
305
        gst_event_copy_segment (event, &seg);
1170
1171
305
        GST_DEBUG_OBJECT (dec, "starting segment %" GST_SEGMENT_FORMAT, &seg);
1172
1173
305
        dec->output_segment = seg;
1174
305
        dec->priv->in_out_segment_sync =
1175
305
            gst_segment_is_equal (&dec->input_segment, &seg);
1176
305
        GST_AUDIO_DECODER_STREAM_UNLOCK (dec);
1177
305
        break;
1178
0
      }
1179
600
      default:
1180
600
        break;
1181
905
    }
1182
905
  }
1183
334
}
1184
1185
static GstFlowReturn
1186
check_pending_reconfigure (GstAudioDecoder * dec)
1187
68
{
1188
68
  GstFlowReturn ret = GST_FLOW_OK;
1189
68
  GstAudioDecoderContext *ctx;
1190
68
  gboolean needs_reconfigure;
1191
1192
68
  ctx = &dec->priv->ctx;
1193
1194
68
  needs_reconfigure = gst_pad_check_reconfigure (dec->srcpad);
1195
68
  if (G_UNLIKELY (ctx->output_format_changed ||
1196
68
          (GST_AUDIO_INFO_IS_VALID (&ctx->info)
1197
68
              && needs_reconfigure))) {
1198
29
    if (!gst_audio_decoder_negotiate_unlocked (dec)) {
1199
0
      gst_pad_mark_reconfigure (dec->srcpad);
1200
0
      if (GST_PAD_IS_FLUSHING (dec->srcpad))
1201
0
        ret = GST_FLOW_FLUSHING;
1202
0
      else
1203
0
        ret = GST_FLOW_NOT_NEGOTIATED;
1204
0
    }
1205
29
  }
1206
68
  return ret;
1207
68
}
1208
1209
static gboolean
1210
gst_audio_decoder_transform_meta_default (GstAudioDecoder *
1211
    decoder, GstBuffer * outbuf, GstMeta * meta, GstBuffer * inbuf)
1212
0
{
1213
0
  const GstMetaInfo *info = meta->info;
1214
0
  const gchar *const *tags;
1215
0
  const gchar *const supported_tags[] = {
1216
0
    GST_META_TAG_AUDIO_STR,
1217
0
    GST_META_TAG_AUDIO_CHANNELS_STR,
1218
0
    NULL,
1219
0
  };
1220
1221
0
  tags = gst_meta_api_type_get_tags (info->api);
1222
1223
0
  if (!tags)
1224
0
    return TRUE;
1225
1226
0
  while (*tags) {
1227
0
    if (!g_strv_contains (supported_tags, *tags))
1228
0
      return FALSE;
1229
0
    tags++;
1230
0
  }
1231
1232
0
  return TRUE;
1233
0
}
1234
1235
typedef struct
1236
{
1237
  GstAudioDecoder *decoder;
1238
  GstBuffer *outbuf;
1239
} CopyMetaData;
1240
1241
static gboolean
1242
foreach_metadata (GstBuffer * inbuf, GstMeta ** meta, gpointer user_data)
1243
0
{
1244
0
  CopyMetaData *data = user_data;
1245
0
  GstAudioDecoder *decoder = data->decoder;
1246
0
  GstAudioDecoderClass *klass = GST_AUDIO_DECODER_GET_CLASS (decoder);
1247
0
  GstBuffer *outbuf = data->outbuf;
1248
0
  const GstMetaInfo *info = (*meta)->info;
1249
0
  gboolean do_copy = FALSE;
1250
1251
0
  if (gst_meta_api_type_has_tag (info->api, _gst_meta_tag_memory)
1252
0
      || gst_meta_api_type_has_tag (info->api, _gst_meta_tag_memory_reference)) {
1253
    /* never call the transform_meta with memory specific metadata */
1254
0
    GST_DEBUG_OBJECT (decoder, "not copying memory specific metadata %s",
1255
0
        g_type_name (info->api));
1256
0
    do_copy = FALSE;
1257
0
  } else if (klass->transform_meta) {
1258
0
    do_copy = klass->transform_meta (decoder, outbuf, *meta, inbuf);
1259
0
    GST_DEBUG_OBJECT (decoder, "transformed metadata %s: copy: %d",
1260
0
        g_type_name (info->api), do_copy);
1261
0
  }
1262
1263
  /* we only copy metadata when the subclass implemented a transform_meta
1264
   * function and when it returns %TRUE */
1265
0
  if (do_copy && info->transform_func) {
1266
0
    GstMetaTransformCopy copy_data = { FALSE, 0, -1 };
1267
0
    GST_DEBUG_OBJECT (decoder, "copy metadata %s", g_type_name (info->api));
1268
    /* simply copy then */
1269
0
    info->transform_func (outbuf, *meta, inbuf,
1270
0
        _gst_meta_transform_copy, &copy_data);
1271
0
  }
1272
0
  return TRUE;
1273
0
}
1274
1275
/**
1276
 * gst_audio_decoder_finish_subframe:
1277
 * @dec: a #GstAudioDecoder
1278
 * @buf: (transfer full) (nullable): decoded data
1279
 *
1280
 * Collects decoded data and pushes it downstream. This function may be called
1281
 * multiple times for a given input frame.
1282
 *
1283
 * @buf may be NULL in which case it is assumed that the current input frame is
1284
 * finished. This is equivalent to calling gst_audio_decoder_finish_subframe()
1285
 * with a NULL buffer and frames=1 after having pushed out all decoded audio
1286
 * subframes using this function.
1287
 *
1288
 * When called with valid data in @buf the source pad caps must have been set
1289
 * already.
1290
 *
1291
 * Note that a frame received in #GstAudioDecoderClass.handle_frame() may be
1292
 * invalidated by a call to this function.
1293
 *
1294
 * Returns: a #GstFlowReturn that should be escalated to caller (of caller)
1295
 *
1296
 * Since: 1.16
1297
 */
1298
GstFlowReturn
1299
gst_audio_decoder_finish_subframe (GstAudioDecoder * dec, GstBuffer * buf)
1300
0
{
1301
0
  g_return_val_if_fail (GST_IS_AUDIO_DECODER (dec), GST_FLOW_ERROR);
1302
1303
0
  if (buf == NULL)
1304
0
    return gst_audio_decoder_finish_frame_or_subframe (dec, NULL, 1);
1305
0
  else
1306
0
    return gst_audio_decoder_finish_frame_or_subframe (dec, buf, 0);
1307
0
}
1308
1309
/**
1310
 * gst_audio_decoder_finish_frame:
1311
 * @dec: a #GstAudioDecoder
1312
 * @buf: (transfer full) (nullable): decoded data
1313
 * @frames: number of decoded frames represented by decoded data
1314
 *
1315
 * Collects decoded data and pushes it downstream.
1316
 *
1317
 * @buf may be NULL in which case the indicated number of frames
1318
 * are discarded and considered to have produced no output
1319
 * (e.g. lead-in or setup frames).
1320
 * Otherwise, source pad caps must be set when it is called with valid
1321
 * data in @buf.
1322
 *
1323
 * Note that a frame received in #GstAudioDecoderClass.handle_frame() may be
1324
 * invalidated by a call to this function.
1325
 *
1326
 * Returns: a #GstFlowReturn that should be escalated to caller (of caller)
1327
 */
1328
GstFlowReturn
1329
gst_audio_decoder_finish_frame (GstAudioDecoder * dec, GstBuffer * buf,
1330
    gint frames)
1331
374
{
1332
374
  g_return_val_if_fail (GST_IS_AUDIO_DECODER (dec), GST_FLOW_ERROR);
1333
1334
  /* no dummy calls please */
1335
374
  g_return_val_if_fail (frames != 0, GST_FLOW_ERROR);
1336
1337
374
  return gst_audio_decoder_finish_frame_or_subframe (dec, buf, frames);
1338
374
}
1339
1340
/* frames == 0 indicates that this is a sub-frame and further sub-frames may
1341
 * follow for the current input frame. */
1342
static GstFlowReturn
1343
gst_audio_decoder_finish_frame_or_subframe (GstAudioDecoder * dec,
1344
    GstBuffer * buf, gint frames)
1345
374
{
1346
374
  GstAudioDecoderPrivate *priv;
1347
374
  GstAudioDecoderContext *ctx;
1348
374
  GstAudioDecoderClass *klass = GST_AUDIO_DECODER_GET_CLASS (dec);
1349
374
  GstAudioMeta *meta;
1350
374
  GstClockTime ts, next_ts;
1351
374
  gsize size, samples = 0;
1352
374
  GstFlowReturn ret = GST_FLOW_OK;
1353
374
  GQueue inbufs = G_QUEUE_INIT;
1354
374
  gboolean is_subframe = (frames == 0);
1355
374
  gboolean do_check_resync;
1356
1357
  /* subclass should not hand us no data */
1358
374
  g_return_val_if_fail (buf == NULL || gst_buffer_get_size (buf) > 0,
1359
374
      GST_FLOW_ERROR);
1360
1361
  /* if it's a subframe (frames == 0) we must have a valid buffer */
1362
374
  g_assert (!is_subframe || buf != NULL);
1363
1364
374
  priv = dec->priv;
1365
374
  ctx = &dec->priv->ctx;
1366
374
  meta = buf ? gst_buffer_get_audio_meta (buf) : NULL;
1367
374
  size = buf ? gst_buffer_get_size (buf) : 0;
1368
374
  samples = buf ? (meta ? meta->samples : size / ctx->info.bpf) : 0;
1369
1370
  /* must know the output format by now */
1371
374
  g_return_val_if_fail (buf == NULL || GST_AUDIO_INFO_IS_VALID (&ctx->info),
1372
374
      GST_FLOW_ERROR);
1373
1374
374
  GST_LOG_OBJECT (dec,
1375
374
      "accepting %" G_GSIZE_FORMAT " bytes == %" G_GSIZE_FORMAT
1376
374
      " samples for %d frames", buf ? size : 0, samples, frames);
1377
1378
374
  GST_AUDIO_DECODER_STREAM_LOCK (dec);
1379
1380
374
  if (buf != NULL && priv->subframe_samples == 0) {
1381
68
    ret = check_pending_reconfigure (dec);
1382
68
    if (ret == GST_FLOW_FLUSHING || ret == GST_FLOW_NOT_NEGOTIATED) {
1383
0
      gst_buffer_unref (buf);
1384
0
      goto exit;
1385
0
    }
1386
1387
    /* FIXME: This is wrong if multiple full frames are pending */
1388
68
    if (priv->pending_events)
1389
68
      send_pending_events (dec);
1390
68
  }
1391
1392
  /* sanity checking */
1393
374
  if (G_LIKELY (buf && ctx->info.bpf)) {
1394
68
    if (!meta || meta->info.layout == GST_AUDIO_LAYOUT_INTERLEAVED) {
1395
      /* output should be whole number of sample frames */
1396
68
      if (size % ctx->info.bpf)
1397
0
        goto wrong_buffer;
1398
      /* output should have no additional padding */
1399
68
      if (samples != size / ctx->info.bpf)
1400
0
        goto wrong_samples;
1401
68
    } else {
1402
      /* can't have more samples than what the buffer fits */
1403
0
      if (samples > size / ctx->info.bpf)
1404
0
        goto wrong_samples;
1405
0
    }
1406
68
  }
1407
1408
  /* frame and ts book-keeping */
1409
374
  if (G_UNLIKELY (frames < 0)) {
1410
0
    if (G_UNLIKELY (-frames - 1 > priv->frames.length)) {
1411
0
      GST_ELEMENT_WARNING (dec, STREAM, DECODE,
1412
0
          ("received more decoded frames %d than provided %d", frames,
1413
0
              priv->frames.length), (NULL));
1414
0
      frames = 0;
1415
0
    } else {
1416
0
      frames = priv->frames.length + frames + 1;
1417
0
    }
1418
374
  } else if (G_UNLIKELY (frames > priv->frames.length)) {
1419
0
    if (G_LIKELY (!priv->force)) {
1420
0
      GST_ELEMENT_WARNING (dec, STREAM, DECODE,
1421
0
          ("received more decoded frames %d than provided %d", frames,
1422
0
              priv->frames.length), (NULL));
1423
0
    }
1424
0
    frames = priv->frames.length;
1425
0
  }
1426
1427
374
  if (G_LIKELY (buf))
1428
68
    buf = gst_buffer_make_writable (buf);
1429
1430
374
  if (G_LIKELY (priv->frames.length)) {
1431
374
    ts = GST_BUFFER_PTS (priv->frames.head->data);
1432
374
    if (G_LIKELY (buf)) {
1433
      /* propagate RESYNC flag to output buffer */
1434
68
      if (GST_BUFFER_FLAG_IS_SET (priv->frames.head->data,
1435
68
              GST_BUFFER_FLAG_RESYNC))
1436
68
        GST_BUFFER_FLAG_SET (buf, GST_BUFFER_FLAG_RESYNC);
1437
68
      if (is_subframe) {
1438
0
        priv->frames.head->data =
1439
0
            gst_buffer_make_writable (priv->frames.head->data);
1440
0
        GST_BUFFER_FLAG_UNSET (priv->frames.head->data, GST_BUFFER_FLAG_RESYNC);
1441
0
      }
1442
68
    }
1443
374
  } else
1444
0
    ts = GST_CLOCK_TIME_NONE;
1445
1446
374
  GST_DEBUG_OBJECT (dec, "leading frame ts %" GST_TIME_FORMAT,
1447
374
      GST_TIME_ARGS (ts));
1448
1449
374
  if (is_subframe && priv->frames.length == 0)
1450
0
    goto subframe_without_pending_input_frame;
1451
1452
  /* this will be skipped in the is_subframe case because frames will be 0 */
1453
748
  while (priv->frames.length && frames) {
1454
374
    g_queue_push_tail (&inbufs, g_queue_pop_head (&priv->frames));
1455
374
    dec->priv->ctx.delay = dec->priv->frames.length;
1456
374
    frames--;
1457
374
  }
1458
1459
374
  if (G_UNLIKELY (!buf))
1460
306
    goto exit;
1461
1462
  /* lock on */
1463
68
  if (G_UNLIKELY (!GST_CLOCK_TIME_IS_VALID (priv->base_ts))) {
1464
68
    priv->base_ts = ts;
1465
68
    GST_DEBUG_OBJECT (dec, "base_ts now %" GST_TIME_FORMAT, GST_TIME_ARGS (ts));
1466
68
  }
1467
1468
  /* still no valid ts, track the segment one */
1469
68
  if (G_UNLIKELY (!GST_CLOCK_TIME_IS_VALID (priv->base_ts)) &&
1470
0
      dec->output_segment.rate > 0.0) {
1471
0
    priv->base_ts = dec->output_segment.start;
1472
0
  }
1473
1474
  /* only check for resync at the beginning of an input/output frame */
1475
68
  do_check_resync = !is_subframe || priv->subframe_samples == 0;
1476
1477
  /* slightly convoluted approach caters for perfect ts if subclass desires. */
1478
68
  if (do_check_resync && GST_CLOCK_TIME_IS_VALID (ts)) {
1479
68
    if (dec->priv->tolerance > 0) {
1480
0
      GstClockTimeDiff diff;
1481
1482
0
      g_assert (GST_CLOCK_TIME_IS_VALID (priv->base_ts));
1483
0
      next_ts = priv->base_ts +
1484
0
          gst_util_uint64_scale (priv->samples, GST_SECOND, ctx->info.rate);
1485
0
      GST_LOG_OBJECT (dec,
1486
0
          "buffer is %" G_GUINT64_FORMAT " samples past base_ts %"
1487
0
          GST_TIME_FORMAT ", expected ts %" GST_TIME_FORMAT, priv->samples,
1488
0
          GST_TIME_ARGS (priv->base_ts), GST_TIME_ARGS (next_ts));
1489
0
      diff = GST_CLOCK_DIFF (next_ts, ts);
1490
0
      GST_LOG_OBJECT (dec, "ts diff %d ms", (gint) (diff / GST_MSECOND));
1491
      /* if within tolerance,
1492
       * discard buffer ts and carry on producing perfect stream,
1493
       * otherwise resync to ts */
1494
0
      if (G_UNLIKELY (diff < (gint64) - dec->priv->tolerance ||
1495
0
              diff > (gint64) dec->priv->tolerance ||
1496
0
              GST_BUFFER_FLAG_IS_SET (buf, GST_BUFFER_FLAG_RESYNC))) {
1497
0
        GST_DEBUG_OBJECT (dec, "base_ts resync");
1498
0
        priv->base_ts = ts;
1499
0
        priv->samples = 0;
1500
0
      }
1501
68
    } else {
1502
68
      GST_DEBUG_OBJECT (dec, "base_ts resync");
1503
68
      priv->base_ts = ts;
1504
68
      priv->samples = 0;
1505
68
    }
1506
68
  }
1507
1508
  /* delayed one-shot stuff until confirmed data */
1509
68
  if (priv->taglist && priv->taglist_changed) {
1510
68
    GstEvent *tags_event;
1511
1512
68
    tags_event = gst_audio_decoder_create_merged_tags_event (dec);
1513
1514
68
    if (tags_event != NULL)
1515
68
      gst_audio_decoder_push_event (dec, tags_event);
1516
1517
68
    priv->taglist_changed = FALSE;
1518
68
  }
1519
1520
68
  if (G_LIKELY (GST_CLOCK_TIME_IS_VALID (priv->base_ts))) {
1521
68
    GST_BUFFER_PTS (buf) =
1522
68
        priv->base_ts +
1523
68
        GST_FRAMES_TO_CLOCK_TIME (priv->samples, ctx->info.rate);
1524
68
    GST_BUFFER_DURATION (buf) = priv->base_ts +
1525
68
        GST_FRAMES_TO_CLOCK_TIME (priv->samples + samples, ctx->info.rate) -
1526
68
        GST_BUFFER_PTS (buf);
1527
68
  } else {
1528
0
    GST_BUFFER_PTS (buf) = GST_CLOCK_TIME_NONE;
1529
0
    GST_BUFFER_DURATION (buf) =
1530
0
        GST_FRAMES_TO_CLOCK_TIME (samples, ctx->info.rate);
1531
0
  }
1532
1533
68
  if (klass->transform_meta) {
1534
68
    if (inbufs.length) {
1535
68
      GList *l;
1536
136
      for (l = inbufs.head; l; l = l->next) {
1537
68
        CopyMetaData data;
1538
1539
68
        data.decoder = dec;
1540
68
        data.outbuf = buf;
1541
68
        gst_buffer_foreach_meta (l->data, foreach_metadata, &data);
1542
68
      }
1543
68
    } else if (is_subframe) {
1544
0
      CopyMetaData data;
1545
0
      GstBuffer *in_buf;
1546
1547
      /* For subframes we assume a 1:N relationship for now, so we just take
1548
       * metas from the first pending input buf */
1549
0
      in_buf = g_queue_peek_head (&priv->frames);
1550
0
      data.decoder = dec;
1551
0
      data.outbuf = buf;
1552
0
      gst_buffer_foreach_meta (in_buf, foreach_metadata, &data);
1553
0
    } else {
1554
0
      GST_WARNING_OBJECT (dec,
1555
0
          "Can't copy metadata because input buffers disappeared");
1556
0
    }
1557
68
  }
1558
1559
68
  GST_OBJECT_LOCK (dec);
1560
68
  priv->samples += samples;
1561
68
  priv->samples_out += samples;
1562
68
  GST_OBJECT_UNLOCK (dec);
1563
1564
  /* we got data, so note things are looking up */
1565
68
  if (G_UNLIKELY (dec->priv->error_count))
1566
0
    dec->priv->error_count = 0;
1567
1568
68
  ret = gst_audio_decoder_output (dec, buf);
1569
1570
374
exit:
1571
374
  g_queue_foreach (&inbufs, (GFunc) gst_buffer_unref, NULL);
1572
374
  g_queue_clear (&inbufs);
1573
1574
374
  if (is_subframe)
1575
0
    dec->priv->subframe_samples += samples;
1576
374
  else
1577
374
    dec->priv->subframe_samples = 0;
1578
1579
374
  GST_AUDIO_DECODER_STREAM_UNLOCK (dec);
1580
1581
374
  return ret;
1582
1583
  /* ERRORS */
1584
0
wrong_buffer:
1585
0
  {
1586
    /* arguably more of a programming error? */
1587
0
    GST_ELEMENT_ERROR (dec, STREAM, DECODE, (NULL),
1588
0
        ("buffer size %" G_GSIZE_FORMAT " not a multiple of %d", size,
1589
0
            ctx->info.bpf));
1590
0
    gst_buffer_unref (buf);
1591
0
    ret = GST_FLOW_ERROR;
1592
0
    goto exit;
1593
68
  }
1594
0
wrong_samples:
1595
0
  {
1596
    /* arguably more of a programming error? */
1597
0
    GST_ELEMENT_ERROR (dec, STREAM, DECODE, (NULL),
1598
0
        ("GstAudioMeta samples (%" G_GSIZE_FORMAT ") are inconsistent with "
1599
0
            "the buffer size and layout (size/bpf = %" G_GSIZE_FORMAT ")",
1600
0
            meta->samples, size / ctx->info.bpf));
1601
0
    gst_buffer_unref (buf);
1602
0
    ret = GST_FLOW_ERROR;
1603
0
    goto exit;
1604
68
  }
1605
0
subframe_without_pending_input_frame:
1606
0
  {
1607
    /* arguably more of a programming error? */
1608
0
    GST_ELEMENT_ERROR (dec, STREAM, DECODE, (NULL),
1609
0
        ("Received decoded subframe, but no pending frame"));
1610
0
    gst_buffer_unref (buf);
1611
0
    ret = GST_FLOW_ERROR;
1612
0
    goto exit;
1613
68
  }
1614
68
}
1615
1616
static GstFlowReturn
1617
gst_audio_decoder_handle_frame (GstAudioDecoder * dec,
1618
    GstAudioDecoderClass * klass, GstBuffer * buffer)
1619
708
{
1620
  /* Skip decoding and send a GAP instead if
1621
   * GST_SEGMENT_FLAG_TRICKMODE_NO_AUDIO is set and we have timestamps
1622
   * FIXME: We only do this for forward playback atm, because reverse
1623
   * playback would require accumulating GAP events and pushing them
1624
   * out in reverse order as for normal audio samples
1625
   */
1626
708
  if (G_UNLIKELY (dec->input_segment.rate > 0.0
1627
708
          && dec->input_segment.flags & GST_SEGMENT_FLAG_TRICKMODE_NO_AUDIO)) {
1628
0
    if (buffer) {
1629
0
      GstClockTime ts = GST_BUFFER_PTS (buffer);
1630
0
      if (GST_CLOCK_TIME_IS_VALID (ts)) {
1631
0
        GstEvent *event = gst_event_new_gap (ts, GST_BUFFER_DURATION (buffer));
1632
1633
0
        gst_buffer_unref (buffer);
1634
0
        GST_LOG_OBJECT (dec, "Skipping decode in trickmode and sending gap");
1635
0
        gst_audio_decoder_handle_gap (dec, event);
1636
0
        return GST_FLOW_OK;
1637
0
      }
1638
0
    }
1639
0
  }
1640
1641
708
  if (G_LIKELY (buffer)) {
1642
374
    gsize size = gst_buffer_get_size (buffer);
1643
    /* keep around for admin */
1644
374
    GST_LOG_OBJECT (dec,
1645
374
        "tracking frame size %" G_GSIZE_FORMAT ", ts %" GST_TIME_FORMAT, size,
1646
374
        GST_TIME_ARGS (GST_BUFFER_PTS (buffer)));
1647
374
    g_queue_push_tail (&dec->priv->frames, buffer);
1648
374
    dec->priv->ctx.delay = dec->priv->frames.length;
1649
374
    GST_OBJECT_LOCK (dec);
1650
374
    dec->priv->bytes_in += size;
1651
374
    GST_OBJECT_UNLOCK (dec);
1652
374
  } else {
1653
334
    GST_LOG_OBJECT (dec, "providing subclass with NULL frame");
1654
334
  }
1655
1656
708
  return klass->handle_frame (dec, buffer);
1657
708
}
1658
1659
/* maybe subclass configurable instead, but this allows for a whole lot of
1660
 * raw samples, so at least quite some encoded ... */
1661
0
#define GST_AUDIO_DECODER_MAX_SYNC     10 * 8 * 2 * 1024
1662
1663
static GstFlowReturn
1664
gst_audio_decoder_push_buffers (GstAudioDecoder * dec, gboolean force)
1665
708
{
1666
708
  GstAudioDecoderClass *klass;
1667
708
  GstAudioDecoderPrivate *priv;
1668
708
  GstAudioDecoderContext *ctx;
1669
708
  GstFlowReturn ret = GST_FLOW_OK;
1670
708
  GstBuffer *buffer;
1671
708
  gint av, flush;
1672
1673
708
  klass = GST_AUDIO_DECODER_GET_CLASS (dec);
1674
708
  priv = dec->priv;
1675
708
  ctx = &dec->priv->ctx;
1676
1677
708
  g_return_val_if_fail (klass->handle_frame != NULL, GST_FLOW_ERROR);
1678
1679
708
  av = gst_adapter_available (priv->adapter);
1680
708
  GST_DEBUG_OBJECT (dec, "available: %d", av);
1681
1682
1.08k
  while (ret == GST_FLOW_OK) {
1683
1684
1.04k
    flush = 0;
1685
1.04k
    ctx->eos = force;
1686
1687
1.04k
    if (G_LIKELY (av)) {
1688
374
      gint len;
1689
374
      GstClockTime ts;
1690
374
      guint64 distance;
1691
1692
      /* parse if needed */
1693
374
      if (klass->parse) {
1694
0
        gint offset = 0;
1695
1696
        /* limited (legacy) parsing; avoid whole of baseparse */
1697
0
        GST_DEBUG_OBJECT (dec, "parsing available: %d", av);
1698
        /* piggyback sync state on discont */
1699
0
        ctx->sync = !priv->discont;
1700
0
        ret = klass->parse (dec, priv->adapter, &offset, &len);
1701
1702
0
        g_assert (offset <= av);
1703
0
        if (offset) {
1704
          /* jumped a bit */
1705
0
          GST_DEBUG_OBJECT (dec, "skipped %d; setting DISCONT", offset);
1706
0
          gst_adapter_flush (priv->adapter, offset);
1707
0
          flush = offset;
1708
          /* avoid parsing indefinitely */
1709
0
          priv->sync_flush += offset;
1710
0
          if (priv->sync_flush > GST_AUDIO_DECODER_MAX_SYNC)
1711
0
            goto parse_failed;
1712
0
        }
1713
1714
0
        if (ret == GST_FLOW_EOS) {
1715
0
          GST_LOG_OBJECT (dec, "no frame yet");
1716
0
          ret = GST_FLOW_OK;
1717
0
          break;
1718
0
        } else if (ret == GST_FLOW_OK) {
1719
0
          GST_LOG_OBJECT (dec, "frame at offset %d of length %d", offset, len);
1720
0
          g_assert (len);
1721
0
          g_assert (offset + len <= av);
1722
0
          priv->sync_flush = 0;
1723
0
        } else {
1724
0
          break;
1725
0
        }
1726
374
      } else {
1727
374
        len = av;
1728
374
      }
1729
      /* track upstream ts, but do not get stuck if nothing new upstream */
1730
374
      ts = gst_adapter_prev_pts (priv->adapter, &distance);
1731
374
      if (ts != priv->prev_ts || distance <= priv->prev_distance) {
1732
374
        priv->prev_ts = ts;
1733
374
        priv->prev_distance = distance;
1734
374
      } else {
1735
0
        GST_LOG_OBJECT (dec, "ts == prev_ts; discarding");
1736
0
        ts = GST_CLOCK_TIME_NONE;
1737
0
      }
1738
374
      buffer = gst_adapter_take_buffer (priv->adapter, len);
1739
374
      buffer = gst_buffer_make_writable (buffer);
1740
374
      GST_BUFFER_PTS (buffer) = ts;
1741
374
      flush += len;
1742
374
      priv->force = FALSE;
1743
668
    } else {
1744
668
      if (!force)
1745
334
        break;
1746
334
      if (!priv->drainable) {
1747
0
        priv->drained = TRUE;
1748
0
        break;
1749
0
      }
1750
334
      buffer = NULL;
1751
334
      priv->force = TRUE;
1752
334
    }
1753
1754
708
    ret = gst_audio_decoder_handle_frame (dec, klass, buffer);
1755
1756
    /* do not keep pushing it ... */
1757
708
    if (G_UNLIKELY (!av)) {
1758
334
      priv->drained = TRUE;
1759
334
      break;
1760
334
    }
1761
1762
374
    av -= flush;
1763
374
    g_assert (av >= 0);
1764
374
  }
1765
1766
708
  GST_LOG_OBJECT (dec, "done pushing to subclass");
1767
708
  return ret;
1768
1769
  /* ERRORS */
1770
0
parse_failed:
1771
0
  {
1772
0
    GST_ELEMENT_ERROR (dec, STREAM, DECODE, (NULL), ("failed to parse stream"));
1773
0
    return GST_FLOW_ERROR;
1774
708
  }
1775
708
}
1776
1777
static GstFlowReturn
1778
gst_audio_decoder_drain (GstAudioDecoder * dec)
1779
758
{
1780
758
  GstFlowReturn ret;
1781
1782
758
  if (dec->priv->drained && !dec->priv->gather)
1783
424
    return GST_FLOW_OK;
1784
1785
  /* Apply any pending events before draining, as that
1786
   * may update the pending segment info */
1787
334
  apply_pending_events (dec);
1788
1789
  /* dispatch reverse pending buffers */
1790
  /* chain eventually calls upon drain as well, but by that time
1791
   * gather list should be clear, so ok ... */
1792
334
  if (dec->output_segment.rate < 0.0 && dec->priv->gather)
1793
0
    gst_audio_decoder_chain_reverse (dec, NULL);
1794
  /* have subclass give all it can */
1795
334
  ret = gst_audio_decoder_push_buffers (dec, TRUE);
1796
334
  if (ret != GST_FLOW_OK) {
1797
0
    GST_WARNING_OBJECT (dec, "audio decoder push buffers failed");
1798
0
    goto drain_failed;
1799
0
  }
1800
  /* ensure all output sent */
1801
334
  ret = gst_audio_decoder_output (dec, NULL);
1802
334
  if (ret != GST_FLOW_OK)
1803
334
    GST_WARNING_OBJECT (dec, "audio decoder output failed");
1804
1805
334
drain_failed:
1806
  /* everything should be away now */
1807
334
  if (dec->priv->frames.length) {
1808
    /* not fatal/impossible though if subclass/codec eats stuff */
1809
0
    GST_WARNING_OBJECT (dec, "still %d frames left after draining",
1810
0
        dec->priv->frames.length);
1811
0
    g_queue_foreach (&dec->priv->frames, (GFunc) gst_buffer_unref, NULL);
1812
0
    g_queue_clear (&dec->priv->frames);
1813
0
  }
1814
1815
  /* discard (unparsed) leftover */
1816
334
  gst_adapter_clear (dec->priv->adapter);
1817
334
  return ret;
1818
334
}
1819
1820
/* hard == FLUSH, otherwise discont */
1821
static GstFlowReturn
1822
gst_audio_decoder_flush (GstAudioDecoder * dec, gboolean hard)
1823
550
{
1824
550
  GstAudioDecoderClass *klass;
1825
550
  GstFlowReturn ret = GST_FLOW_OK;
1826
1827
550
  klass = GST_AUDIO_DECODER_GET_CLASS (dec);
1828
1829
550
  GST_LOG_OBJECT (dec, "flush hard %d", hard);
1830
1831
550
  if (!hard) {
1832
550
    ret = gst_audio_decoder_drain (dec);
1833
550
  } else {
1834
0
    gst_audio_decoder_clear_queues (dec);
1835
0
    gst_segment_init (&dec->input_segment, GST_FORMAT_TIME);
1836
0
    gst_segment_init (&dec->output_segment, GST_FORMAT_TIME);
1837
0
    dec->priv->error_count = 0;
1838
0
  }
1839
  /* only bother subclass with flushing if known it is already alive
1840
   * and kicking out stuff */
1841
550
  if (klass->flush && dec->priv->samples_out > 0)
1842
0
    klass->flush (dec, hard);
1843
  /* and get (re)set for the sequel */
1844
550
  gst_audio_decoder_reset (dec, FALSE);
1845
1846
550
  return ret;
1847
550
}
1848
1849
static GstFlowReturn
1850
gst_audio_decoder_chain_forward (GstAudioDecoder * dec, GstBuffer * buffer)
1851
418
{
1852
418
  GstFlowReturn ret = GST_FLOW_OK;
1853
1854
  /* discard silly case, though maybe ts may be of value ?? */
1855
418
  if (G_UNLIKELY (gst_buffer_get_size (buffer) == 0)) {
1856
44
    GST_DEBUG_OBJECT (dec, "discarding empty buffer");
1857
44
    gst_buffer_unref (buffer);
1858
44
    goto exit;
1859
44
  }
1860
1861
  /* grab buffer */
1862
374
  gst_adapter_push (dec->priv->adapter, buffer);
1863
374
  buffer = NULL;
1864
  /* new stuff, so we can push subclass again */
1865
374
  dec->priv->drained = FALSE;
1866
1867
  /* hand to subclass */
1868
374
  ret = gst_audio_decoder_push_buffers (dec, FALSE);
1869
1870
418
exit:
1871
418
  GST_LOG_OBJECT (dec, "chain-done");
1872
418
  return ret;
1873
374
}
1874
1875
static void
1876
gst_audio_decoder_clear_queues (GstAudioDecoder * dec)
1877
258
{
1878
258
  GstAudioDecoderPrivate *priv = dec->priv;
1879
1880
258
  g_list_foreach (priv->queued, (GFunc) gst_mini_object_unref, NULL);
1881
258
  g_list_free (priv->queued);
1882
258
  priv->queued = NULL;
1883
258
  g_list_foreach (priv->gather, (GFunc) gst_mini_object_unref, NULL);
1884
258
  g_list_free (priv->gather);
1885
258
  priv->gather = NULL;
1886
258
  g_list_foreach (priv->decode, (GFunc) gst_mini_object_unref, NULL);
1887
258
  g_list_free (priv->decode);
1888
258
  priv->decode = NULL;
1889
258
}
1890
1891
/*
1892
 * Input:
1893
 *  Buffer decoding order:  7  8  9  4  5  6  3  1  2  EOS
1894
 *  Discont flag:           D        D        D  D
1895
 *
1896
 * - Each Discont marks a discont in the decoding order.
1897
 *
1898
 * for vorbis, each buffer is a keyframe when we have the previous
1899
 * buffer. This means that to decode buffer 7, we need buffer 6, which
1900
 * arrives out of order.
1901
 *
1902
 * we first gather buffers in the gather queue until we get a DISCONT. We
1903
 * prepend each incoming buffer so that they are in reversed order.
1904
 *
1905
 *    gather queue:    9  8  7
1906
 *    decode queue:
1907
 *    output queue:
1908
 *
1909
 * When a DISCONT is received (buffer 4), we move the gather queue to the
1910
 * decode queue. This is simply done be taking the head of the gather queue
1911
 * and prepending it to the decode queue. This yields:
1912
 *
1913
 *    gather queue:
1914
 *    decode queue:    7  8  9
1915
 *    output queue:
1916
 *
1917
 * Then we decode each buffer in the decode queue in order and put the output
1918
 * buffer in the output queue. The first buffer (7) will not produce any output
1919
 * because it needs the previous buffer (6) which did not arrive yet. This
1920
 * yields:
1921
 *
1922
 *    gather queue:
1923
 *    decode queue:    7  8  9
1924
 *    output queue:    9  8
1925
 *
1926
 * Then we remove the consumed buffers from the decode queue. Buffer 7 is not
1927
 * completely consumed, we need to keep it around for when we receive buffer
1928
 * 6. This yields:
1929
 *
1930
 *    gather queue:
1931
 *    decode queue:    7
1932
 *    output queue:    9  8
1933
 *
1934
 * Then we accumulate more buffers:
1935
 *
1936
 *    gather queue:    6  5  4
1937
 *    decode queue:    7
1938
 *    output queue:
1939
 *
1940
 * prepending to the decode queue on DISCONT yields:
1941
 *
1942
 *    gather queue:
1943
 *    decode queue:    4  5  6  7
1944
 *    output queue:
1945
 *
1946
 * after decoding and keeping buffer 4:
1947
 *
1948
 *    gather queue:
1949
 *    decode queue:    4
1950
 *    output queue:    7  6  5
1951
 *
1952
 * Etc..
1953
 */
1954
static GstFlowReturn
1955
gst_audio_decoder_flush_decode (GstAudioDecoder * dec)
1956
0
{
1957
0
  GstAudioDecoderPrivate *priv = dec->priv;
1958
0
  GstFlowReturn res = GST_FLOW_OK;
1959
0
  GstClockTime timestamp;
1960
0
  GList *walk;
1961
1962
0
  walk = priv->decode;
1963
1964
0
  GST_DEBUG_OBJECT (dec, "flushing buffers to decoder");
1965
1966
  /* clear buffer and decoder state */
1967
0
  gst_audio_decoder_flush (dec, FALSE);
1968
1969
0
  while (walk) {
1970
0
    GList *next;
1971
0
    GstBuffer *buf = GST_BUFFER_CAST (walk->data);
1972
1973
0
    GST_DEBUG_OBJECT (dec, "decoding buffer %p, ts %" GST_TIME_FORMAT,
1974
0
        buf, GST_TIME_ARGS (GST_BUFFER_PTS (buf)));
1975
1976
0
    next = g_list_next (walk);
1977
    /* decode buffer, resulting data prepended to output queue */
1978
0
    gst_buffer_ref (buf);
1979
0
    res = gst_audio_decoder_chain_forward (dec, buf);
1980
1981
    /* if we generated output, we can discard the buffer, else we
1982
     * keep it in the queue */
1983
0
    if (priv->queued) {
1984
0
      GST_DEBUG_OBJECT (dec, "decoded buffer to %p", priv->queued->data);
1985
0
      priv->decode = g_list_delete_link (priv->decode, walk);
1986
0
      gst_buffer_unref (buf);
1987
0
    } else {
1988
0
      GST_DEBUG_OBJECT (dec, "buffer did not decode, keeping");
1989
0
    }
1990
0
    walk = next;
1991
0
  }
1992
1993
  /* drain any aggregation (or otherwise) leftover */
1994
0
  gst_audio_decoder_drain (dec);
1995
1996
  /* now send queued data downstream */
1997
0
  timestamp = GST_CLOCK_TIME_NONE;
1998
0
  while (priv->queued) {
1999
0
    GstBuffer *buf = GST_BUFFER_CAST (priv->queued->data);
2000
0
    GstClockTime duration;
2001
2002
0
    duration = GST_BUFFER_DURATION (buf);
2003
2004
    /* duration should always be valid for raw audio */
2005
0
    g_assert (GST_CLOCK_TIME_IS_VALID (duration));
2006
2007
    /* interpolate (backward) if needed */
2008
0
    if (G_LIKELY (timestamp != -1)) {
2009
0
      if (timestamp > duration)
2010
0
        timestamp -= duration;
2011
0
      else
2012
0
        timestamp = 0;
2013
0
    }
2014
2015
0
    if (!GST_BUFFER_PTS_IS_VALID (buf)) {
2016
0
      GST_LOG_OBJECT (dec, "applying reverse interpolated ts %"
2017
0
          GST_TIME_FORMAT, GST_TIME_ARGS (timestamp));
2018
0
      GST_BUFFER_PTS (buf) = timestamp;
2019
0
    } else {
2020
      /* track otherwise */
2021
0
      timestamp = GST_BUFFER_PTS (buf);
2022
0
      GST_LOG_OBJECT (dec, "tracking ts %" GST_TIME_FORMAT,
2023
0
          GST_TIME_ARGS (timestamp));
2024
0
    }
2025
2026
0
    if (G_LIKELY (res == GST_FLOW_OK)) {
2027
0
      GST_DEBUG_OBJECT (dec, "pushing buffer %p of size %" G_GSIZE_FORMAT ", "
2028
0
          "time %" GST_TIME_FORMAT ", dur %" GST_TIME_FORMAT, buf,
2029
0
          gst_buffer_get_size (buf), GST_TIME_ARGS (GST_BUFFER_PTS (buf)),
2030
0
          GST_TIME_ARGS (GST_BUFFER_DURATION (buf)));
2031
      /* should be already, but let's be sure */
2032
0
      buf = gst_buffer_make_writable (buf);
2033
      /* avoid stray DISCONT from forward processing,
2034
       * which have no meaning in reverse pushing */
2035
0
      GST_BUFFER_FLAG_UNSET (buf, GST_BUFFER_FLAG_DISCONT);
2036
0
      res = gst_audio_decoder_push_forward (dec, buf);
2037
0
    } else {
2038
0
      gst_buffer_unref (buf);
2039
0
    }
2040
2041
0
    priv->queued = g_list_delete_link (priv->queued, priv->queued);
2042
0
  }
2043
2044
0
  return res;
2045
0
}
2046
2047
static GstFlowReturn
2048
gst_audio_decoder_chain_reverse (GstAudioDecoder * dec, GstBuffer * buf)
2049
0
{
2050
0
  GstAudioDecoderPrivate *priv = dec->priv;
2051
0
  GstFlowReturn result = GST_FLOW_OK;
2052
2053
  /* if we have a discont, move buffers to the decode list */
2054
0
  if (!buf || GST_BUFFER_FLAG_IS_SET (buf, GST_BUFFER_FLAG_DISCONT)) {
2055
0
    GST_DEBUG_OBJECT (dec, "received discont");
2056
0
    while (priv->gather) {
2057
0
      GstBuffer *gbuf;
2058
2059
0
      gbuf = GST_BUFFER_CAST (priv->gather->data);
2060
      /* remove from the gather list */
2061
0
      priv->gather = g_list_delete_link (priv->gather, priv->gather);
2062
      /* copy to decode queue */
2063
0
      priv->decode = g_list_prepend (priv->decode, gbuf);
2064
0
    }
2065
    /* decode stuff in the decode queue */
2066
0
    gst_audio_decoder_flush_decode (dec);
2067
0
  }
2068
2069
0
  if (G_LIKELY (buf)) {
2070
0
    GST_DEBUG_OBJECT (dec, "gathering buffer %p of size %" G_GSIZE_FORMAT ", "
2071
0
        "time %" GST_TIME_FORMAT ", dur %" GST_TIME_FORMAT, buf,
2072
0
        gst_buffer_get_size (buf), GST_TIME_ARGS (GST_BUFFER_PTS (buf)),
2073
0
        GST_TIME_ARGS (GST_BUFFER_DURATION (buf)));
2074
2075
    /* add buffer to gather queue */
2076
0
    priv->gather = g_list_prepend (priv->gather, buf);
2077
0
  }
2078
2079
0
  return result;
2080
0
}
2081
2082
static GstFlowReturn
2083
gst_audio_decoder_chain (GstPad * pad, GstObject * parent, GstBuffer * buffer)
2084
418
{
2085
418
  GstAudioDecoder *dec;
2086
418
  GstFlowReturn ret;
2087
2088
418
  dec = GST_AUDIO_DECODER (parent);
2089
2090
418
  GST_LOG_OBJECT (dec,
2091
418
      "received buffer of size %" G_GSIZE_FORMAT " with ts %" GST_TIME_FORMAT
2092
418
      ", duration %" GST_TIME_FORMAT, gst_buffer_get_size (buffer),
2093
418
      GST_TIME_ARGS (GST_BUFFER_PTS (buffer)),
2094
418
      GST_TIME_ARGS (GST_BUFFER_DURATION (buffer)));
2095
2096
418
  GST_AUDIO_DECODER_STREAM_LOCK (dec);
2097
2098
418
  if (G_UNLIKELY (dec->priv->ctx.input_caps == NULL && dec->priv->needs_format))
2099
0
    goto not_negotiated;
2100
2101
418
  dec->priv->ctx.had_input_data = TRUE;
2102
2103
418
  if (!dec->priv->expecting_discont_buf &&
2104
418
      GST_BUFFER_FLAG_IS_SET (buffer, GST_BUFFER_FLAG_DISCONT)) {
2105
384
    gint64 samples, ts;
2106
2107
    /* track present position */
2108
384
    ts = dec->priv->base_ts;
2109
384
    samples = dec->priv->samples;
2110
2111
384
    GST_DEBUG_OBJECT (dec, "handling discont");
2112
384
    gst_audio_decoder_flush (dec, FALSE);
2113
384
    dec->priv->discont = TRUE;
2114
2115
    /* buffer may claim DISCONT loudly, if it can't tell us where we are now,
2116
     * we'll stick to where we were ...
2117
     * Particularly useful/needed for upstream BYTE based */
2118
384
    if (dec->input_segment.rate > 0.0 && !GST_BUFFER_PTS_IS_VALID (buffer)) {
2119
234
      GST_DEBUG_OBJECT (dec, "... but restoring previous ts tracking");
2120
234
      dec->priv->base_ts = ts;
2121
234
      dec->priv->samples = samples;
2122
234
    }
2123
384
  }
2124
418
  dec->priv->expecting_discont_buf = FALSE;
2125
2126
418
  if (dec->input_segment.rate > 0.0)
2127
418
    ret = gst_audio_decoder_chain_forward (dec, buffer);
2128
0
  else
2129
0
    ret = gst_audio_decoder_chain_reverse (dec, buffer);
2130
2131
418
  GST_AUDIO_DECODER_STREAM_UNLOCK (dec);
2132
2133
418
  return ret;
2134
2135
  /* ERRORS */
2136
0
not_negotiated:
2137
0
  {
2138
0
    GST_AUDIO_DECODER_STREAM_UNLOCK (dec);
2139
0
    GST_ELEMENT_ERROR (dec, CORE, NEGOTIATION, (NULL),
2140
0
        ("decoder not initialized"));
2141
0
    gst_buffer_unref (buffer);
2142
0
    return GST_FLOW_NOT_NEGOTIATED;
2143
418
  }
2144
418
}
2145
2146
/* perform upstream byte <-> time conversion (duration, seeking)
2147
 * if subclass allows and if enough data for moderately decent conversion */
2148
static inline gboolean
2149
gst_audio_decoder_do_byte (GstAudioDecoder * dec)
2150
2
{
2151
2
  gboolean ret;
2152
2153
2
  GST_OBJECT_LOCK (dec);
2154
2
  ret = dec->priv->ctx.do_estimate_rate && dec->priv->ctx.info.bpf &&
2155
0
      dec->priv->ctx.info.rate <= dec->priv->samples_out;
2156
2
  GST_OBJECT_UNLOCK (dec);
2157
2158
2
  return ret;
2159
2
}
2160
2161
/* Must be called holding the GST_AUDIO_DECODER_STREAM_LOCK */
2162
static gboolean
2163
gst_audio_decoder_negotiate_default_caps (GstAudioDecoder * dec)
2164
0
{
2165
0
  GstCaps *caps, *templcaps;
2166
0
  gint i;
2167
0
  gint channels = 0;
2168
0
  gint rate;
2169
0
  guint64 channel_mask = 0;
2170
0
  gint caps_size;
2171
0
  GstStructure *structure;
2172
0
  GstAudioInfo info;
2173
2174
0
  templcaps = gst_pad_get_pad_template_caps (dec->srcpad);
2175
0
  caps = gst_pad_peer_query_caps (dec->srcpad, templcaps);
2176
0
  if (caps)
2177
0
    gst_caps_unref (templcaps);
2178
0
  else
2179
0
    caps = templcaps;
2180
0
  templcaps = NULL;
2181
2182
0
  if (!caps || gst_caps_is_empty (caps) || gst_caps_is_any (caps))
2183
0
    goto caps_error;
2184
2185
0
  GST_LOG_OBJECT (dec, "peer caps  %" GST_PTR_FORMAT, caps);
2186
2187
  /* before fixating, try to use whatever upstream provided */
2188
0
  caps = gst_caps_make_writable (caps);
2189
0
  caps_size = gst_caps_get_size (caps);
2190
0
  if (dec->priv->ctx.input_caps) {
2191
0
    GstCaps *sinkcaps = dec->priv->ctx.input_caps;
2192
0
    GstStructure *structure = gst_caps_get_structure (sinkcaps, 0);
2193
2194
0
    if (gst_structure_get_int (structure, "rate", &rate)) {
2195
0
      for (i = 0; i < caps_size; i++) {
2196
0
        gst_structure_set (gst_caps_get_structure (caps, i), "rate",
2197
0
            G_TYPE_INT, rate, NULL);
2198
0
      }
2199
0
    }
2200
2201
0
    if (gst_structure_get_int (structure, "channels", &channels)) {
2202
0
      for (i = 0; i < caps_size; i++) {
2203
0
        gst_structure_set (gst_caps_get_structure (caps, i), "channels",
2204
0
            G_TYPE_INT, channels, NULL);
2205
0
      }
2206
0
    }
2207
2208
0
    if (gst_structure_get (structure, "channel-mask", GST_TYPE_BITMASK,
2209
0
            &channel_mask, NULL)) {
2210
0
      for (i = 0; i < caps_size; i++) {
2211
0
        gst_structure_set (gst_caps_get_structure (caps, i), "channel-mask",
2212
0
            GST_TYPE_BITMASK, channel_mask, NULL);
2213
0
      }
2214
0
    }
2215
0
  }
2216
2217
0
  for (i = 0; i < caps_size; i++) {
2218
0
    structure = gst_caps_get_structure (caps, i);
2219
0
    if (gst_structure_has_field (structure, "channels"))
2220
0
      gst_structure_fixate_field_nearest_int (structure,
2221
0
          "channels", GST_AUDIO_DEF_CHANNELS);
2222
0
    else
2223
0
      gst_structure_set (structure, "channels", G_TYPE_INT,
2224
0
          GST_AUDIO_DEF_CHANNELS, NULL);
2225
0
    if (gst_structure_has_field (structure, "rate"))
2226
0
      gst_structure_fixate_field_nearest_int (structure,
2227
0
          "rate", GST_AUDIO_DEF_RATE);
2228
0
    else
2229
0
      gst_structure_set (structure, "rate", G_TYPE_INT, GST_AUDIO_DEF_RATE,
2230
0
          NULL);
2231
0
  }
2232
0
  caps = gst_caps_fixate (caps);
2233
0
  structure = gst_caps_get_structure (caps, 0);
2234
2235
  /* Need to add a channel-mask if channels > 2 */
2236
0
  gst_structure_get_int (structure, "channels", &channels);
2237
0
  if (channels > 2 && !gst_structure_has_field (structure, "channel-mask")) {
2238
0
    channel_mask = gst_audio_channel_get_fallback_mask (channels);
2239
0
    if (channel_mask != 0) {
2240
0
      gst_structure_set (structure, "channel-mask",
2241
0
          GST_TYPE_BITMASK, channel_mask, NULL);
2242
0
    } else {
2243
0
      GST_WARNING_OBJECT (dec, "No default channel-mask for %d channels",
2244
0
          channels);
2245
0
    }
2246
0
  }
2247
2248
0
  if (!caps || !gst_audio_info_from_caps (&info, caps))
2249
0
    goto caps_error;
2250
2251
0
  GST_OBJECT_LOCK (dec);
2252
0
  dec->priv->ctx.info = info;
2253
0
  dec->priv->ctx.caps = caps;
2254
0
  GST_OBJECT_UNLOCK (dec);
2255
2256
0
  GST_INFO_OBJECT (dec,
2257
0
      "Chose default caps %" GST_PTR_FORMAT " for initial gap", caps);
2258
2259
0
  return TRUE;
2260
2261
0
caps_error:
2262
0
  {
2263
0
    if (caps)
2264
0
      gst_caps_unref (caps);
2265
0
    return FALSE;
2266
0
  }
2267
0
}
2268
2269
static gboolean
2270
gst_audio_decoder_handle_gap (GstAudioDecoder * dec, GstEvent * event)
2271
0
{
2272
0
  gboolean ret;
2273
0
  GstClockTime timestamp, duration;
2274
0
  gboolean needs_reconfigure = FALSE;
2275
2276
  /* Ensure we have caps first */
2277
0
  GST_AUDIO_DECODER_STREAM_LOCK (dec);
2278
0
  if (!GST_AUDIO_INFO_IS_VALID (&dec->priv->ctx.info)) {
2279
0
    if (!gst_audio_decoder_negotiate_default_caps (dec)) {
2280
0
      GST_AUDIO_DECODER_STREAM_UNLOCK (dec);
2281
0
      GST_ELEMENT_ERROR (dec, STREAM, FORMAT, (NULL),
2282
0
          ("Decoder output not negotiated before GAP event."));
2283
0
      gst_event_unref (event);
2284
0
      return FALSE;
2285
0
    }
2286
0
    needs_reconfigure = TRUE;
2287
0
  }
2288
0
  needs_reconfigure = gst_pad_check_reconfigure (dec->srcpad)
2289
0
      || needs_reconfigure;
2290
0
  if (G_UNLIKELY (dec->priv->ctx.output_format_changed || needs_reconfigure)) {
2291
0
    if (!gst_audio_decoder_negotiate_unlocked (dec)) {
2292
0
      GST_WARNING_OBJECT (dec, "Failed to negotiate with downstream");
2293
0
      gst_pad_mark_reconfigure (dec->srcpad);
2294
0
    }
2295
0
  }
2296
0
  GST_AUDIO_DECODER_STREAM_UNLOCK (dec);
2297
2298
0
  gst_event_parse_gap (event, &timestamp, &duration);
2299
2300
  /* time progressed without data, see if we can fill the gap with
2301
   * some concealment data */
2302
0
  GST_DEBUG_OBJECT (dec,
2303
0
      "gap event: plc %d, do_plc %d, position %" GST_TIME_FORMAT
2304
0
      " duration %" GST_TIME_FORMAT,
2305
0
      dec->priv->plc, dec->priv->ctx.do_plc,
2306
0
      GST_TIME_ARGS (timestamp), GST_TIME_ARGS (duration));
2307
2308
0
  if (dec->priv->plc && dec->priv->ctx.do_plc && dec->input_segment.rate > 0.0) {
2309
0
    GstAudioDecoderClass *klass = GST_AUDIO_DECODER_GET_CLASS (dec);
2310
0
    GstBuffer *buf;
2311
2312
    /* hand subclass empty frame with duration that needs covering */
2313
0
    buf = gst_buffer_new ();
2314
0
    GST_BUFFER_PTS (buf) = timestamp;
2315
0
    GST_BUFFER_DURATION (buf) = duration;
2316
    /* best effort, not much error handling */
2317
0
    gst_audio_decoder_handle_frame (dec, klass, buf);
2318
0
    ret = TRUE;
2319
0
    dec->priv->expecting_discont_buf = TRUE;
2320
0
    gst_event_unref (event);
2321
0
  } else {
2322
0
    GstFlowReturn flowret;
2323
2324
    /* sub-class doesn't know how to handle empty buffers,
2325
     * so just try sending GAP downstream */
2326
0
    flowret = check_pending_reconfigure (dec);
2327
0
    if (flowret == GST_FLOW_OK) {
2328
      /* Only forward the gap event immediately if no frames are currently
2329
       * pending, otherwise it needs to be queued up instead. This mirrors
2330
       * the code in gst_audio_decoder_finish_frame_or_subframe().
2331
       *
2332
       * FIXME: This is wrong if multiple full frames are pending.
2333
       */
2334
0
      if (dec->priv->subframe_samples == 0) {
2335
0
        send_pending_events (dec);
2336
0
        ret = gst_audio_decoder_push_event (dec, event);
2337
0
      } else {
2338
0
        dec->priv->pending_events =
2339
0
            g_list_append (dec->priv->pending_events, event);
2340
0
        gst_event_unref (event);
2341
0
        ret = TRUE;
2342
0
      }
2343
0
    } else {
2344
0
      ret = FALSE;
2345
0
      gst_event_unref (event);
2346
0
    }
2347
0
  }
2348
0
  return ret;
2349
0
}
2350
2351
static GList *
2352
_flush_events (GstPad * pad, GList * events)
2353
0
{
2354
0
  GList *tmp;
2355
2356
0
  for (tmp = events; tmp; tmp = tmp->next) {
2357
0
    if (GST_EVENT_TYPE (tmp->data) != GST_EVENT_EOS &&
2358
0
        GST_EVENT_TYPE (tmp->data) != GST_EVENT_SEGMENT &&
2359
0
        GST_EVENT_IS_STICKY (tmp->data)) {
2360
0
      gst_pad_store_sticky_event (pad, GST_EVENT_CAST (tmp->data));
2361
0
    }
2362
0
    gst_event_unref (tmp->data);
2363
0
  }
2364
0
  g_list_free (events);
2365
2366
0
  return NULL;
2367
0
}
2368
2369
static gboolean
2370
gst_audio_decoder_sink_eventfunc (GstAudioDecoder * dec, GstEvent * event)
2371
610
{
2372
610
  gboolean ret;
2373
2374
610
  switch (GST_EVENT_TYPE (event)) {
2375
166
    case GST_EVENT_STREAM_START:
2376
166
      GST_AUDIO_DECODER_STREAM_LOCK (dec);
2377
      /* finish any data in current segment and clear the decoder
2378
       * to be ready for new stream data */
2379
166
      gst_audio_decoder_drain (dec);
2380
166
      gst_audio_decoder_flush (dec, FALSE);
2381
2382
166
      GST_DEBUG_OBJECT (dec, "received STREAM_START. Clearing taglist");
2383
      /* Flush upstream tags after a STREAM_START */
2384
166
      if (dec->priv->upstream_tags) {
2385
0
        gst_tag_list_unref (dec->priv->upstream_tags);
2386
0
        dec->priv->upstream_tags = NULL;
2387
0
        dec->priv->taglist_changed = TRUE;
2388
0
      }
2389
166
      GST_AUDIO_DECODER_STREAM_UNLOCK (dec);
2390
2391
166
      ret = gst_audio_decoder_push_event (dec, event);
2392
166
      break;
2393
82
    case GST_EVENT_SEGMENT:
2394
82
    {
2395
82
      GstSegment seg;
2396
82
      GstFormat format;
2397
82
      guint32 seqnum;
2398
2399
82
      GST_AUDIO_DECODER_STREAM_LOCK (dec);
2400
82
      gst_event_copy_segment (event, &seg);
2401
82
      seqnum = gst_event_get_seqnum (event);
2402
2403
82
      format = seg.format;
2404
82
      if (format == GST_FORMAT_TIME) {
2405
82
        GST_DEBUG_OBJECT (dec, "received TIME SEGMENT %" GST_SEGMENT_FORMAT,
2406
82
            &seg);
2407
82
      } else {
2408
0
        gint64 nstart;
2409
0
        GST_DEBUG_OBJECT (dec, "received SEGMENT %" GST_SEGMENT_FORMAT, &seg);
2410
        /* handle newsegment resulting from legacy simple seeking */
2411
        /* note that we need to convert this whether or not enough data
2412
         * to handle initial newsegment */
2413
0
        if (dec->priv->ctx.do_estimate_rate &&
2414
0
            gst_pad_query_convert (dec->sinkpad, GST_FORMAT_BYTES, seg.start,
2415
0
                GST_FORMAT_TIME, &nstart)) {
2416
          /* best attempt convert */
2417
          /* as these are only estimates, stop is kept open-ended to avoid
2418
           * premature cutting */
2419
0
          GST_DEBUG_OBJECT (dec, "converted to TIME start %" GST_TIME_FORMAT,
2420
0
              GST_TIME_ARGS (nstart));
2421
0
          seg.format = GST_FORMAT_TIME;
2422
0
          seg.start = nstart;
2423
0
          seg.time = nstart;
2424
0
          seg.stop = GST_CLOCK_TIME_NONE;
2425
          /* replace event */
2426
0
          gst_event_unref (event);
2427
0
          event = gst_event_new_segment (&seg);
2428
0
          gst_event_set_seqnum (event, seqnum);
2429
0
        } else {
2430
0
          GST_DEBUG_OBJECT (dec, "unsupported format; ignoring");
2431
0
          GST_AUDIO_DECODER_STREAM_UNLOCK (dec);
2432
0
          gst_event_unref (event);
2433
0
          ret = FALSE;
2434
0
          break;
2435
0
        }
2436
0
      }
2437
2438
      /* prepare for next segment */
2439
      /* Use the segment start as a base timestamp
2440
       * in case upstream does not come up with anything better
2441
       * (e.g. upstream BYTE) */
2442
82
      if (format != GST_FORMAT_TIME) {
2443
0
        dec->priv->base_ts = seg.start;
2444
0
        dec->priv->samples = 0;
2445
0
      }
2446
2447
      /* Update the decode flags in the segment if we have an instant-rate
2448
       * override active */
2449
82
      GST_OBJECT_LOCK (dec);
2450
82
      if (dec->priv->decode_flags_override) {
2451
0
        seg.flags &= ~GST_SEGMENT_INSTANT_FLAGS;
2452
0
        seg.flags |= dec->priv->decode_flags & GST_SEGMENT_INSTANT_FLAGS;
2453
0
      }
2454
2455
      /* and follow along with segment */
2456
82
      dec->priv->in_out_segment_sync = FALSE;
2457
82
      dec->input_segment = seg;
2458
82
      GST_OBJECT_UNLOCK (dec);
2459
2460
82
      dec->priv->pending_events =
2461
82
          g_list_append (dec->priv->pending_events, event);
2462
82
      GST_AUDIO_DECODER_STREAM_UNLOCK (dec);
2463
2464
82
      ret = TRUE;
2465
82
      break;
2466
82
    }
2467
0
    case GST_EVENT_INSTANT_RATE_CHANGE:
2468
0
    {
2469
0
      GstSegmentFlags flags;
2470
0
      GstSegment *seg;
2471
2472
0
      gst_event_parse_instant_rate_change (event, NULL, &flags);
2473
2474
0
      GST_OBJECT_LOCK (dec);
2475
0
      dec->priv->decode_flags_override = TRUE;
2476
0
      dec->priv->decode_flags = flags;
2477
2478
      /* Update the input segment flags */
2479
0
      seg = &dec->input_segment;
2480
0
      seg->flags &= ~GST_SEGMENT_INSTANT_FLAGS;
2481
0
      seg->flags |= dec->priv->decode_flags & GST_SEGMENT_INSTANT_FLAGS;
2482
0
      GST_OBJECT_UNLOCK (dec);
2483
2484
      /* Forward downstream */
2485
0
      ret = gst_pad_event_default (dec->sinkpad, GST_OBJECT_CAST (dec), event);
2486
0
      break;
2487
82
    }
2488
0
    case GST_EVENT_GAP:
2489
0
      ret = gst_audio_decoder_handle_gap (dec, event);
2490
0
      break;
2491
0
    case GST_EVENT_FLUSH_STOP:
2492
0
      GST_AUDIO_DECODER_STREAM_LOCK (dec);
2493
      /* prepare for fresh start */
2494
0
      gst_audio_decoder_flush (dec, TRUE);
2495
2496
0
      dec->priv->pending_events = _flush_events (dec->srcpad,
2497
0
          dec->priv->pending_events);
2498
0
      GST_AUDIO_DECODER_STREAM_UNLOCK (dec);
2499
2500
      /* Forward FLUSH_STOP, it is expected to be forwarded immediately
2501
       * and no buffers are queued anyway. */
2502
0
      ret = gst_audio_decoder_push_event (dec, event);
2503
0
      break;
2504
2505
0
    case GST_EVENT_SEGMENT_DONE:
2506
0
      GST_AUDIO_DECODER_STREAM_LOCK (dec);
2507
0
      gst_audio_decoder_drain (dec);
2508
0
      GST_AUDIO_DECODER_STREAM_UNLOCK (dec);
2509
2510
      /* Forward SEGMENT_DONE because no buffer or serialized event might come after
2511
       * SEGMENT_DONE and nothing could trigger another _finish_frame() call. */
2512
0
      if (dec->priv->pending_events)
2513
0
        send_pending_events (dec);
2514
0
      ret = gst_audio_decoder_push_event (dec, event);
2515
0
      break;
2516
2517
42
    case GST_EVENT_EOS:
2518
42
      GST_AUDIO_DECODER_STREAM_LOCK (dec);
2519
42
      gst_audio_decoder_drain (dec);
2520
42
      GST_AUDIO_DECODER_STREAM_UNLOCK (dec);
2521
2522
42
      if (dec->priv->ctx.had_input_data && !dec->priv->ctx.had_output_data) {
2523
13
        GST_ELEMENT_ERROR (dec, STREAM, DECODE,
2524
13
            ("No valid frames decoded before end of stream"),
2525
13
            ("no valid frames found"));
2526
13
      }
2527
2528
      /* Forward EOS because no buffer or serialized event will come after
2529
       * EOS and nothing could trigger another _finish_frame() call. */
2530
42
      if (dec->priv->pending_events)
2531
13
        send_pending_events (dec);
2532
42
      ret = gst_audio_decoder_push_event (dec, event);
2533
42
      break;
2534
2535
166
    case GST_EVENT_CAPS:
2536
166
    {
2537
166
      GstCaps *caps;
2538
2539
166
      gst_event_parse_caps (event, &caps);
2540
166
      ret = gst_audio_decoder_sink_setcaps (dec, caps);
2541
166
      gst_event_unref (event);
2542
166
      break;
2543
82
    }
2544
154
    case GST_EVENT_TAG:
2545
154
    {
2546
154
      GstTagList *tags;
2547
2548
154
      gst_event_parse_tag (event, &tags);
2549
2550
154
      if (gst_tag_list_get_scope (tags) == GST_TAG_SCOPE_STREAM) {
2551
72
        GST_AUDIO_DECODER_STREAM_LOCK (dec);
2552
72
        if (dec->priv->upstream_tags != tags) {
2553
72
          if (dec->priv->upstream_tags)
2554
0
            gst_tag_list_unref (dec->priv->upstream_tags);
2555
72
          dec->priv->upstream_tags = gst_tag_list_ref (tags);
2556
72
          GST_INFO_OBJECT (dec, "upstream stream tags: %" GST_PTR_FORMAT, tags);
2557
72
        }
2558
72
        gst_event_unref (event);
2559
72
        event = gst_audio_decoder_create_merged_tags_event (dec);
2560
72
        dec->priv->taglist_changed = FALSE;
2561
72
        GST_AUDIO_DECODER_STREAM_UNLOCK (dec);
2562
2563
        /* No tags, go out of here instead of fall through */
2564
72
        if (!event) {
2565
0
          ret = TRUE;
2566
0
          break;
2567
0
        }
2568
72
      }
2569
154
    }
2570
      /* FALLTHROUGH */
2571
154
    default:
2572
154
      if (!GST_EVENT_IS_SERIALIZED (event)) {
2573
0
        ret =
2574
0
            gst_pad_event_default (dec->sinkpad, GST_OBJECT_CAST (dec), event);
2575
154
      } else {
2576
154
        GST_DEBUG_OBJECT (dec, "Enqueuing event %d, %s", GST_EVENT_TYPE (event),
2577
154
            GST_EVENT_TYPE_NAME (event));
2578
154
        GST_AUDIO_DECODER_STREAM_LOCK (dec);
2579
154
        dec->priv->pending_events =
2580
154
            g_list_append (dec->priv->pending_events, event);
2581
154
        GST_AUDIO_DECODER_STREAM_UNLOCK (dec);
2582
154
        ret = TRUE;
2583
154
      }
2584
154
      break;
2585
610
  }
2586
610
  return ret;
2587
610
}
2588
2589
static gboolean
2590
gst_audio_decoder_sink_event (GstPad * pad, GstObject * parent,
2591
    GstEvent * event)
2592
610
{
2593
610
  GstAudioDecoder *dec;
2594
610
  GstAudioDecoderClass *klass;
2595
610
  gboolean ret;
2596
2597
610
  dec = GST_AUDIO_DECODER (parent);
2598
610
  klass = GST_AUDIO_DECODER_GET_CLASS (dec);
2599
2600
610
  GST_DEBUG_OBJECT (dec, "received event %d, %s", GST_EVENT_TYPE (event),
2601
610
      GST_EVENT_TYPE_NAME (event));
2602
2603
610
  if (klass->sink_event)
2604
610
    ret = klass->sink_event (dec, event);
2605
0
  else {
2606
0
    gst_event_unref (event);
2607
0
    ret = FALSE;
2608
0
  }
2609
610
  return ret;
2610
610
}
2611
2612
static gboolean
2613
gst_audio_decoder_do_seek (GstAudioDecoder * dec, GstEvent * event)
2614
0
{
2615
0
  GstSeekFlags flags;
2616
0
  GstSeekType start_type, end_type;
2617
0
  GstFormat format;
2618
0
  gdouble rate;
2619
0
  gint64 start, start_time, end_time;
2620
0
  GstSegment seek_segment;
2621
0
  guint32 seqnum;
2622
2623
0
  gst_event_parse_seek (event, &rate, &format, &flags, &start_type,
2624
0
      &start_time, &end_type, &end_time);
2625
2626
  /* we'll handle plain open-ended flushing seeks with the simple approach */
2627
0
  if (rate != 1.0) {
2628
0
    GST_DEBUG_OBJECT (dec, "unsupported seek: rate");
2629
0
    return FALSE;
2630
0
  }
2631
2632
0
  if (start_type != GST_SEEK_TYPE_SET) {
2633
0
    GST_DEBUG_OBJECT (dec, "unsupported seek: start time");
2634
0
    return FALSE;
2635
0
  }
2636
2637
0
  if ((end_type != GST_SEEK_TYPE_SET && end_type != GST_SEEK_TYPE_NONE) ||
2638
0
      (end_type == GST_SEEK_TYPE_SET && end_time != GST_CLOCK_TIME_NONE)) {
2639
0
    GST_DEBUG_OBJECT (dec, "unsupported seek: end time");
2640
0
    return FALSE;
2641
0
  }
2642
2643
0
  if (!(flags & GST_SEEK_FLAG_FLUSH)) {
2644
0
    GST_DEBUG_OBJECT (dec, "unsupported seek: not flushing");
2645
0
    return FALSE;
2646
0
  }
2647
2648
0
  memcpy (&seek_segment, &dec->output_segment, sizeof (seek_segment));
2649
0
  gst_segment_do_seek (&seek_segment, rate, format, flags, start_type,
2650
0
      start_time, end_type, end_time, NULL);
2651
0
  start_time = seek_segment.position;
2652
2653
0
  if (!gst_pad_query_convert (dec->sinkpad, GST_FORMAT_TIME, start_time,
2654
0
          GST_FORMAT_BYTES, &start)) {
2655
0
    GST_DEBUG_OBJECT (dec, "conversion failed");
2656
0
    return FALSE;
2657
0
  }
2658
2659
0
  seqnum = gst_event_get_seqnum (event);
2660
0
  event = gst_event_new_seek (1.0, GST_FORMAT_BYTES, flags,
2661
0
      GST_SEEK_TYPE_SET, start, GST_SEEK_TYPE_NONE, -1);
2662
0
  gst_event_set_seqnum (event, seqnum);
2663
2664
0
  GST_DEBUG_OBJECT (dec, "seeking to %" GST_TIME_FORMAT " at byte offset %"
2665
0
      G_GINT64_FORMAT, GST_TIME_ARGS (start_time), start);
2666
2667
0
  return gst_pad_push_event (dec->sinkpad, event);
2668
0
}
2669
2670
static gboolean
2671
gst_audio_decoder_src_eventfunc (GstAudioDecoder * dec, GstEvent * event)
2672
63
{
2673
63
  gboolean res;
2674
2675
63
  switch (GST_EVENT_TYPE (event)) {
2676
0
    case GST_EVENT_SEEK:
2677
0
    {
2678
0
      GstFormat format;
2679
0
      gdouble rate;
2680
0
      GstSeekFlags flags;
2681
0
      GstSeekType start_type, stop_type;
2682
0
      gint64 start, stop;
2683
0
      gint64 tstart, tstop;
2684
0
      guint32 seqnum;
2685
2686
0
      gst_event_parse_seek (event, &rate, &format, &flags, &start_type, &start,
2687
0
          &stop_type, &stop);
2688
0
      seqnum = gst_event_get_seqnum (event);
2689
2690
      /* upstream gets a chance first */
2691
0
      if ((res = gst_pad_push_event (dec->sinkpad, event)))
2692
0
        break;
2693
2694
      /* if upstream fails for a time seek, maybe we can help if allowed */
2695
0
      if (format == GST_FORMAT_TIME) {
2696
0
        if (gst_audio_decoder_do_byte (dec))
2697
0
          res = gst_audio_decoder_do_seek (dec, event);
2698
0
        break;
2699
0
      }
2700
2701
      /* ... though a non-time seek can be aided as well */
2702
      /* First bring the requested format to time */
2703
0
      if (!(res =
2704
0
              gst_pad_query_convert (dec->srcpad, format, start,
2705
0
                  GST_FORMAT_TIME, &tstart)))
2706
0
        goto convert_error;
2707
0
      if (!(res =
2708
0
              gst_pad_query_convert (dec->srcpad, format, stop, GST_FORMAT_TIME,
2709
0
                  &tstop)))
2710
0
        goto convert_error;
2711
2712
      /* then seek with time on the peer */
2713
0
      event = gst_event_new_seek (rate, GST_FORMAT_TIME,
2714
0
          flags, start_type, tstart, stop_type, tstop);
2715
0
      gst_event_set_seqnum (event, seqnum);
2716
2717
0
      res = gst_pad_push_event (dec->sinkpad, event);
2718
0
      break;
2719
0
    }
2720
63
    default:
2721
63
      res = gst_pad_event_default (dec->srcpad, GST_OBJECT_CAST (dec), event);
2722
63
      break;
2723
63
  }
2724
63
done:
2725
63
  return res;
2726
2727
  /* ERRORS */
2728
0
convert_error:
2729
0
  {
2730
0
    GST_DEBUG_OBJECT (dec, "cannot convert start/stop for seek");
2731
0
    goto done;
2732
63
  }
2733
63
}
2734
2735
static gboolean
2736
gst_audio_decoder_src_event (GstPad * pad, GstObject * parent, GstEvent * event)
2737
63
{
2738
63
  GstAudioDecoder *dec;
2739
63
  GstAudioDecoderClass *klass;
2740
63
  gboolean ret;
2741
2742
63
  dec = GST_AUDIO_DECODER (parent);
2743
63
  klass = GST_AUDIO_DECODER_GET_CLASS (dec);
2744
2745
63
  GST_DEBUG_OBJECT (dec, "received event %d, %s", GST_EVENT_TYPE (event),
2746
63
      GST_EVENT_TYPE_NAME (event));
2747
2748
63
  if (klass->src_event)
2749
63
    ret = klass->src_event (dec, event);
2750
0
  else {
2751
0
    gst_event_unref (event);
2752
0
    ret = FALSE;
2753
0
  }
2754
2755
63
  return ret;
2756
63
}
2757
2758
static gboolean
2759
gst_audio_decoder_decide_allocation_default (GstAudioDecoder * dec,
2760
    GstQuery * query)
2761
97
{
2762
97
  GstAllocator *allocator = NULL;
2763
97
  GstAllocationParams params;
2764
97
  gboolean update_allocator;
2765
2766
  /* we got configuration from our peer or the decide_allocation method,
2767
   * parse them */
2768
97
  if (gst_query_get_n_allocation_params (query) > 0) {
2769
    /* try the allocator */
2770
0
    gst_query_parse_nth_allocation_param (query, 0, &allocator, &params);
2771
0
    update_allocator = TRUE;
2772
97
  } else {
2773
97
    allocator = NULL;
2774
97
    gst_allocation_params_init (&params);
2775
97
    update_allocator = FALSE;
2776
97
  }
2777
2778
97
  if (update_allocator)
2779
0
    gst_query_set_nth_allocation_param (query, 0, allocator, &params);
2780
97
  else
2781
97
    gst_query_add_allocation_param (query, allocator, &params);
2782
97
  if (allocator)
2783
0
    gst_object_unref (allocator);
2784
2785
97
  return TRUE;
2786
97
}
2787
2788
static gboolean
2789
gst_audio_decoder_propose_allocation_default (GstAudioDecoder * dec,
2790
    GstQuery * query)
2791
0
{
2792
0
  return TRUE;
2793
0
}
2794
2795
/**
2796
 * gst_audio_decoder_proxy_getcaps:
2797
 * @decoder: a #GstAudioDecoder
2798
 * @caps: (nullable): initial caps
2799
 * @filter: (nullable): filter caps
2800
 *
2801
 * Returns caps that express @caps (or sink template caps if @caps == NULL)
2802
 * restricted to rate/channels/... combinations supported by downstream
2803
 * elements.
2804
 *
2805
 * Returns: (transfer full): a #GstCaps owned by caller
2806
 *
2807
 * Since: 1.6
2808
 */
2809
GstCaps *
2810
gst_audio_decoder_proxy_getcaps (GstAudioDecoder * decoder, GstCaps * caps,
2811
    GstCaps * filter)
2812
0
{
2813
0
  return __gst_audio_element_proxy_getcaps (GST_ELEMENT_CAST (decoder),
2814
0
      GST_AUDIO_DECODER_SINK_PAD (decoder),
2815
0
      GST_AUDIO_DECODER_SRC_PAD (decoder), caps, filter);
2816
0
}
2817
2818
static GstCaps *
2819
gst_audio_decoder_sink_getcaps (GstAudioDecoder * decoder, GstCaps * filter)
2820
0
{
2821
0
  GstAudioDecoderClass *klass;
2822
0
  GstCaps *caps;
2823
2824
0
  klass = GST_AUDIO_DECODER_GET_CLASS (decoder);
2825
2826
0
  if (klass->getcaps)
2827
0
    caps = klass->getcaps (decoder, filter);
2828
0
  else
2829
0
    caps = gst_audio_decoder_proxy_getcaps (decoder, NULL, filter);
2830
2831
0
  GST_LOG_OBJECT (decoder, "Returning caps %" GST_PTR_FORMAT, caps);
2832
2833
0
  return caps;
2834
0
}
2835
2836
static gboolean
2837
gst_audio_decoder_sink_query_default (GstAudioDecoder * dec, GstQuery * query)
2838
335
{
2839
335
  GstPad *pad = GST_AUDIO_DECODER_SINK_PAD (dec);
2840
335
  gboolean res = FALSE;
2841
2842
335
  GST_LOG_OBJECT (dec, "handling query: %" GST_PTR_FORMAT, query);
2843
2844
335
  switch (GST_QUERY_TYPE (query)) {
2845
0
    case GST_QUERY_FORMATS:
2846
0
    {
2847
0
      gst_query_set_formats (query, 2, GST_FORMAT_TIME, GST_FORMAT_BYTES);
2848
0
      res = TRUE;
2849
0
      break;
2850
0
    }
2851
0
    case GST_QUERY_CONVERT:
2852
0
    {
2853
0
      GstFormat src_fmt, dest_fmt;
2854
0
      gint64 src_val, dest_val;
2855
2856
0
      gst_query_parse_convert (query, &src_fmt, &src_val, &dest_fmt, &dest_val);
2857
0
      GST_OBJECT_LOCK (dec);
2858
0
      res = __gst_audio_encoded_audio_convert (&dec->priv->ctx.info,
2859
0
          dec->priv->bytes_in, dec->priv->samples_out,
2860
0
          src_fmt, src_val, &dest_fmt, &dest_val);
2861
0
      GST_OBJECT_UNLOCK (dec);
2862
0
      if (!res)
2863
0
        goto error;
2864
0
      gst_query_set_convert (query, src_fmt, src_val, dest_fmt, dest_val);
2865
0
      break;
2866
0
    }
2867
0
    case GST_QUERY_ALLOCATION:
2868
0
    {
2869
0
      GstAudioDecoderClass *klass = GST_AUDIO_DECODER_GET_CLASS (dec);
2870
2871
0
      if (klass->propose_allocation)
2872
0
        res = klass->propose_allocation (dec, query);
2873
0
      break;
2874
0
    }
2875
0
    case GST_QUERY_CAPS:{
2876
0
      GstCaps *filter, *caps;
2877
2878
0
      gst_query_parse_caps (query, &filter);
2879
0
      caps = gst_audio_decoder_sink_getcaps (dec, filter);
2880
0
      gst_query_set_caps_result (query, caps);
2881
0
      gst_caps_unref (caps);
2882
0
      res = TRUE;
2883
0
      break;
2884
0
    }
2885
335
    case GST_QUERY_ACCEPT_CAPS:{
2886
335
      if (dec->priv->use_default_pad_acceptcaps) {
2887
335
        res =
2888
335
            gst_pad_query_default (GST_AUDIO_DECODER_SINK_PAD (dec),
2889
335
            GST_OBJECT_CAST (dec), query);
2890
335
      } else {
2891
0
        GstCaps *caps;
2892
0
        GstCaps *allowed_caps;
2893
0
        GstCaps *template_caps;
2894
0
        gboolean accept;
2895
2896
0
        gst_query_parse_accept_caps (query, &caps);
2897
2898
0
        template_caps = gst_pad_get_pad_template_caps (pad);
2899
0
        accept = gst_caps_is_subset (caps, template_caps);
2900
0
        gst_caps_unref (template_caps);
2901
2902
0
        if (accept) {
2903
0
          allowed_caps = gst_pad_query_caps (GST_AUDIO_DECODER_SINK_PAD (dec),
2904
0
              caps);
2905
2906
0
          accept = gst_caps_can_intersect (caps, allowed_caps);
2907
2908
0
          gst_caps_unref (allowed_caps);
2909
0
        }
2910
2911
0
        gst_query_set_accept_caps_result (query, accept);
2912
0
        res = TRUE;
2913
0
      }
2914
335
      break;
2915
0
    }
2916
0
    case GST_QUERY_SEEKING:
2917
0
    {
2918
0
      GstFormat format;
2919
2920
      /* non-TIME segments are discarded, so we won't seek that way either */
2921
0
      gst_query_parse_seeking (query, &format, NULL, NULL, NULL);
2922
0
      if (format != GST_FORMAT_TIME) {
2923
0
        GST_DEBUG_OBJECT (dec, "discarding non-TIME SEEKING query");
2924
0
        res = FALSE;
2925
0
        break;
2926
0
      }
2927
0
    }
2928
      /* FALLTHROUGH */
2929
0
    default:
2930
0
      res = gst_pad_query_default (pad, GST_OBJECT_CAST (dec), query);
2931
0
      break;
2932
335
  }
2933
2934
335
error:
2935
335
  return res;
2936
335
}
2937
2938
static gboolean
2939
gst_audio_decoder_sink_query (GstPad * pad, GstObject * parent,
2940
    GstQuery * query)
2941
335
{
2942
335
  GstAudioDecoderClass *dec_class;
2943
335
  GstAudioDecoder *dec;
2944
335
  gboolean ret = FALSE;
2945
2946
335
  dec = GST_AUDIO_DECODER (parent);
2947
335
  dec_class = GST_AUDIO_DECODER_GET_CLASS (dec);
2948
2949
335
  GST_DEBUG_OBJECT (pad, "received query %" GST_PTR_FORMAT, query);
2950
2951
335
  if (dec_class->sink_query)
2952
335
    ret = dec_class->sink_query (dec, query);
2953
2954
335
  return ret;
2955
335
}
2956
2957
/* FIXME ? are any of these queries (other than latency) a decoder's business ??
2958
 * also, the conversion stuff might seem to make sense, but seems to not mind
2959
 * segment stuff etc at all
2960
 * Supposedly that's backward compatibility ... */
2961
static gboolean
2962
gst_audio_decoder_src_query_default (GstAudioDecoder * dec, GstQuery * query)
2963
178
{
2964
178
  GstPad *pad = GST_AUDIO_DECODER_SRC_PAD (dec);
2965
178
  gboolean res = FALSE;
2966
2967
178
  GST_LOG_OBJECT (dec, "handling query: %" GST_PTR_FORMAT, query);
2968
2969
178
  switch (GST_QUERY_TYPE (query)) {
2970
2
    case GST_QUERY_DURATION:
2971
2
    {
2972
2
      GstFormat format;
2973
2974
      /* upstream in any case */
2975
2
      if ((res = gst_pad_query_default (pad, GST_OBJECT_CAST (dec), query)))
2976
0
        break;
2977
2978
2
      gst_query_parse_duration (query, &format, NULL);
2979
      /* try answering TIME by converting from BYTE if subclass allows  */
2980
2
      if (format == GST_FORMAT_TIME && gst_audio_decoder_do_byte (dec)) {
2981
0
        gint64 value;
2982
2983
0
        if (gst_pad_peer_query_duration (dec->sinkpad, GST_FORMAT_BYTES,
2984
0
                &value)) {
2985
0
          GST_LOG_OBJECT (dec, "upstream size %" G_GINT64_FORMAT, value);
2986
0
          if (gst_pad_query_convert (dec->sinkpad, GST_FORMAT_BYTES, value,
2987
0
                  GST_FORMAT_TIME, &value)) {
2988
0
            gst_query_set_duration (query, GST_FORMAT_TIME, value);
2989
0
            res = TRUE;
2990
0
          }
2991
0
        }
2992
0
      }
2993
2
      break;
2994
2
    }
2995
0
    case GST_QUERY_POSITION:
2996
0
    {
2997
0
      GstFormat format;
2998
0
      gint64 time, value;
2999
3000
0
      if ((res = gst_pad_peer_query (dec->sinkpad, query))) {
3001
0
        GST_LOG_OBJECT (dec, "returning peer response");
3002
0
        break;
3003
0
      }
3004
3005
      /* Refuse BYTES format queries. If it made sense to
3006
       * answer them, upstream would have already */
3007
0
      gst_query_parse_position (query, &format, NULL);
3008
3009
0
      if (format == GST_FORMAT_BYTES) {
3010
0
        GST_LOG_OBJECT (dec, "Ignoring BYTES position query");
3011
0
        break;
3012
0
      }
3013
3014
      /* we start from the last seen time */
3015
0
      time = dec->output_segment.position;
3016
      /* correct for the segment values */
3017
0
      time =
3018
0
          gst_segment_to_stream_time (&dec->output_segment, GST_FORMAT_TIME,
3019
0
          time);
3020
3021
0
      GST_LOG_OBJECT (dec,
3022
0
          "query %p: our time: %" GST_TIME_FORMAT, query, GST_TIME_ARGS (time));
3023
3024
      /* and convert to the final format */
3025
0
      if (!(res = gst_pad_query_convert (pad, GST_FORMAT_TIME, time,
3026
0
                  format, &value)))
3027
0
        break;
3028
3029
0
      gst_query_set_position (query, format, value);
3030
3031
0
      GST_LOG_OBJECT (dec,
3032
0
          "query %p: we return %" G_GINT64_FORMAT " (format %u)", query, value,
3033
0
          format);
3034
0
      break;
3035
0
    }
3036
0
    case GST_QUERY_FORMATS:
3037
0
    {
3038
0
      gst_query_set_formats (query, 3,
3039
0
          GST_FORMAT_TIME, GST_FORMAT_BYTES, GST_FORMAT_DEFAULT);
3040
0
      res = TRUE;
3041
0
      break;
3042
0
    }
3043
0
    case GST_QUERY_CONVERT:
3044
0
    {
3045
0
      GstFormat src_fmt, dest_fmt;
3046
0
      gint64 src_val, dest_val;
3047
3048
0
      gst_query_parse_convert (query, &src_fmt, &src_val, &dest_fmt, &dest_val);
3049
0
      GST_OBJECT_LOCK (dec);
3050
0
      res = gst_audio_info_convert (&dec->priv->ctx.info,
3051
0
          src_fmt, src_val, dest_fmt, &dest_val);
3052
0
      GST_OBJECT_UNLOCK (dec);
3053
0
      if (!res)
3054
0
        break;
3055
0
      gst_query_set_convert (query, src_fmt, src_val, dest_fmt, dest_val);
3056
0
      break;
3057
0
    }
3058
0
    case GST_QUERY_LATENCY:
3059
0
    {
3060
0
      if ((res = gst_pad_peer_query (dec->sinkpad, query))) {
3061
0
        gboolean live;
3062
0
        GstClockTime min_latency, max_latency;
3063
3064
0
        gst_query_parse_latency (query, &live, &min_latency, &max_latency);
3065
0
        GST_DEBUG_OBJECT (dec, "Peer latency: live %d, min %"
3066
0
            GST_TIME_FORMAT " max %" GST_TIME_FORMAT, live,
3067
0
            GST_TIME_ARGS (min_latency), GST_TIME_ARGS (max_latency));
3068
3069
0
        GST_OBJECT_LOCK (dec);
3070
        /* add our latency */
3071
0
        min_latency += dec->priv->ctx.min_latency;
3072
0
        if (max_latency == -1 || dec->priv->ctx.max_latency == -1)
3073
0
          max_latency = -1;
3074
0
        else
3075
0
          max_latency += dec->priv->ctx.max_latency;
3076
0
        GST_OBJECT_UNLOCK (dec);
3077
3078
0
        gst_query_set_latency (query, live, min_latency, max_latency);
3079
0
      }
3080
0
      break;
3081
0
    }
3082
176
    default:
3083
176
      res = gst_pad_query_default (pad, GST_OBJECT_CAST (dec), query);
3084
176
      break;
3085
178
  }
3086
3087
178
  return res;
3088
178
}
3089
3090
static gboolean
3091
gst_audio_decoder_src_query (GstPad * pad, GstObject * parent, GstQuery * query)
3092
178
{
3093
178
  GstAudioDecoder *dec;
3094
178
  GstAudioDecoderClass *dec_class;
3095
178
  gboolean ret = FALSE;
3096
3097
178
  dec = GST_AUDIO_DECODER (parent);
3098
178
  dec_class = GST_AUDIO_DECODER_GET_CLASS (dec);
3099
3100
178
  GST_DEBUG_OBJECT (pad, "received query %" GST_PTR_FORMAT, query);
3101
3102
178
  if (dec_class->src_query)
3103
178
    ret = dec_class->src_query (dec, query);
3104
3105
178
  return ret;
3106
178
}
3107
3108
static gboolean
3109
gst_audio_decoder_stop (GstAudioDecoder * dec)
3110
86
{
3111
86
  GstAudioDecoderClass *klass;
3112
86
  gboolean ret = TRUE;
3113
3114
86
  GST_DEBUG_OBJECT (dec, "gst_audio_decoder_stop");
3115
3116
86
  klass = GST_AUDIO_DECODER_GET_CLASS (dec);
3117
3118
86
  if (klass->stop) {
3119
86
    ret = klass->stop (dec);
3120
86
  }
3121
3122
  /* clean up */
3123
86
  gst_audio_decoder_reset (dec, TRUE);
3124
3125
86
  if (ret)
3126
86
    dec->priv->active = FALSE;
3127
3128
86
  return ret;
3129
86
}
3130
3131
static gboolean
3132
gst_audio_decoder_start (GstAudioDecoder * dec)
3133
86
{
3134
86
  GstAudioDecoderClass *klass;
3135
86
  gboolean ret = TRUE;
3136
3137
86
  GST_DEBUG_OBJECT (dec, "gst_audio_decoder_start");
3138
3139
86
  klass = GST_AUDIO_DECODER_GET_CLASS (dec);
3140
3141
  /* arrange clean state */
3142
86
  gst_audio_decoder_reset (dec, TRUE);
3143
3144
86
  if (klass->start) {
3145
86
    ret = klass->start (dec);
3146
86
  }
3147
3148
86
  if (ret)
3149
86
    dec->priv->active = TRUE;
3150
3151
86
  return ret;
3152
86
}
3153
3154
static void
3155
gst_audio_decoder_get_property (GObject * object, guint prop_id,
3156
    GValue * value, GParamSpec * pspec)
3157
0
{
3158
0
  GstAudioDecoder *dec;
3159
3160
0
  dec = GST_AUDIO_DECODER (object);
3161
3162
0
  switch (prop_id) {
3163
0
    case PROP_LATENCY:
3164
0
      g_value_set_int64 (value, dec->priv->latency);
3165
0
      break;
3166
0
    case PROP_TOLERANCE:
3167
0
      g_value_set_int64 (value, dec->priv->tolerance);
3168
0
      break;
3169
0
    case PROP_PLC:
3170
0
      g_value_set_boolean (value, dec->priv->plc);
3171
0
      break;
3172
0
    case PROP_MAX_ERRORS:
3173
0
      g_value_set_int (value, gst_audio_decoder_get_max_errors (dec));
3174
0
      break;
3175
0
    default:
3176
0
      G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
3177
0
      break;
3178
0
  }
3179
0
}
3180
3181
static void
3182
gst_audio_decoder_set_property (GObject * object, guint prop_id,
3183
    const GValue * value, GParamSpec * pspec)
3184
0
{
3185
0
  GstAudioDecoder *dec;
3186
3187
0
  dec = GST_AUDIO_DECODER (object);
3188
3189
0
  switch (prop_id) {
3190
0
    case PROP_LATENCY:
3191
0
      dec->priv->latency = g_value_get_int64 (value);
3192
0
      break;
3193
0
    case PROP_TOLERANCE:
3194
0
      dec->priv->tolerance = g_value_get_int64 (value);
3195
0
      break;
3196
0
    case PROP_PLC:
3197
0
      dec->priv->plc = g_value_get_boolean (value);
3198
0
      break;
3199
0
    case PROP_MAX_ERRORS:
3200
0
      gst_audio_decoder_set_max_errors (dec, g_value_get_int (value));
3201
0
      break;
3202
0
    default:
3203
0
      G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
3204
0
      break;
3205
0
  }
3206
0
}
3207
3208
static GstStateChangeReturn
3209
gst_audio_decoder_change_state (GstElement * element, GstStateChange transition)
3210
403
{
3211
403
  GstAudioDecoder *codec;
3212
403
  GstAudioDecoderClass *klass;
3213
403
  GstStateChangeReturn ret;
3214
3215
403
  codec = GST_AUDIO_DECODER (element);
3216
403
  klass = GST_AUDIO_DECODER_GET_CLASS (codec);
3217
3218
403
  switch (transition) {
3219
86
    case GST_STATE_CHANGE_NULL_TO_READY:
3220
86
      if (klass->open) {
3221
0
        if (!klass->open (codec))
3222
0
          goto open_failed;
3223
0
      }
3224
86
      break;
3225
86
    case GST_STATE_CHANGE_READY_TO_PAUSED:
3226
86
      if (!gst_audio_decoder_start (codec)) {
3227
0
        goto start_failed;
3228
0
      }
3229
86
      break;
3230
86
    case GST_STATE_CHANGE_PAUSED_TO_PLAYING:
3231
0
      break;
3232
231
    default:
3233
231
      break;
3234
403
  }
3235
3236
403
  ret = GST_ELEMENT_CLASS (parent_class)->change_state (element, transition);
3237
3238
403
  switch (transition) {
3239
0
    case GST_STATE_CHANGE_PLAYING_TO_PAUSED:
3240
0
      break;
3241
86
    case GST_STATE_CHANGE_PAUSED_TO_READY:
3242
86
      if (!gst_audio_decoder_stop (codec)) {
3243
0
        goto stop_failed;
3244
0
      }
3245
86
      break;
3246
86
    case GST_STATE_CHANGE_READY_TO_NULL:
3247
86
      if (klass->close) {
3248
0
        if (!klass->close (codec))
3249
0
          goto close_failed;
3250
0
      }
3251
86
      break;
3252
231
    default:
3253
231
      break;
3254
403
  }
3255
3256
403
  return ret;
3257
3258
0
start_failed:
3259
0
  {
3260
0
    GST_ELEMENT_ERROR (codec, LIBRARY, INIT, (NULL), ("Failed to start codec"));
3261
0
    return GST_STATE_CHANGE_FAILURE;
3262
403
  }
3263
0
stop_failed:
3264
0
  {
3265
0
    GST_ELEMENT_ERROR (codec, LIBRARY, INIT, (NULL), ("Failed to stop codec"));
3266
0
    return GST_STATE_CHANGE_FAILURE;
3267
403
  }
3268
0
open_failed:
3269
0
  {
3270
0
    GST_ELEMENT_ERROR (codec, LIBRARY, INIT, (NULL), ("Failed to open codec"));
3271
0
    return GST_STATE_CHANGE_FAILURE;
3272
403
  }
3273
0
close_failed:
3274
0
  {
3275
0
    GST_ELEMENT_ERROR (codec, LIBRARY, INIT, (NULL), ("Failed to close codec"));
3276
0
    return GST_STATE_CHANGE_FAILURE;
3277
403
  }
3278
403
}
3279
3280
GstFlowReturn
3281
_gst_audio_decoder_error (GstAudioDecoder * dec, gint weight,
3282
    GQuark domain, gint code, gchar * txt, gchar * dbg, const gchar * file,
3283
    const gchar * function, gint line)
3284
0
{
3285
0
  if (txt)
3286
0
    GST_WARNING_OBJECT (dec, "error: %s", txt);
3287
0
  if (dbg)
3288
0
    GST_WARNING_OBJECT (dec, "error: %s", dbg);
3289
0
  dec->priv->error_count += weight;
3290
0
  dec->priv->discont = TRUE;
3291
0
  if (dec->priv->max_errors >= 0
3292
0
      && dec->priv->max_errors < dec->priv->error_count) {
3293
0
    gst_element_message_full (GST_ELEMENT (dec), GST_MESSAGE_ERROR, domain,
3294
0
        code, txt, dbg, file, function, line);
3295
0
    return GST_FLOW_ERROR;
3296
0
  } else {
3297
0
    g_free (txt);
3298
0
    g_free (dbg);
3299
0
    return GST_FLOW_OK;
3300
0
  }
3301
0
}
3302
3303
/**
3304
 * gst_audio_decoder_get_audio_info:
3305
 * @dec: a #GstAudioDecoder
3306
 *
3307
 * Returns: (transfer none): a #GstAudioInfo describing the input audio format
3308
 */
3309
GstAudioInfo *
3310
gst_audio_decoder_get_audio_info (GstAudioDecoder * dec)
3311
0
{
3312
0
  g_return_val_if_fail (GST_IS_AUDIO_DECODER (dec), NULL);
3313
3314
0
  return &dec->priv->ctx.info;
3315
0
}
3316
3317
/**
3318
 * gst_audio_decoder_set_plc_aware:
3319
 * @dec: a #GstAudioDecoder
3320
 * @plc: new plc state
3321
 *
3322
 * Indicates whether or not subclass handles packet loss concealment (plc).
3323
 */
3324
void
3325
gst_audio_decoder_set_plc_aware (GstAudioDecoder * dec, gboolean plc)
3326
0
{
3327
0
  g_return_if_fail (GST_IS_AUDIO_DECODER (dec));
3328
3329
0
  dec->priv->ctx.do_plc = plc;
3330
0
}
3331
3332
/**
3333
 * gst_audio_decoder_get_plc_aware:
3334
 * @dec: a #GstAudioDecoder
3335
 *
3336
 * Returns: currently configured plc handling
3337
 */
3338
gint
3339
gst_audio_decoder_get_plc_aware (GstAudioDecoder * dec)
3340
0
{
3341
0
  g_return_val_if_fail (GST_IS_AUDIO_DECODER (dec), 0);
3342
3343
0
  return dec->priv->ctx.do_plc;
3344
0
}
3345
3346
/**
3347
 * gst_audio_decoder_set_estimate_rate:
3348
 * @dec: a #GstAudioDecoder
3349
 * @enabled: whether to enable byte to time conversion
3350
 *
3351
 * Allows baseclass to perform byte to time estimated conversion.
3352
 */
3353
void
3354
gst_audio_decoder_set_estimate_rate (GstAudioDecoder * dec, gboolean enabled)
3355
0
{
3356
0
  g_return_if_fail (GST_IS_AUDIO_DECODER (dec));
3357
3358
0
  dec->priv->ctx.do_estimate_rate = enabled;
3359
0
}
3360
3361
/**
3362
 * gst_audio_decoder_get_estimate_rate:
3363
 * @dec: a #GstAudioDecoder
3364
 *
3365
 * Returns: currently configured byte to time conversion setting
3366
 */
3367
gint
3368
gst_audio_decoder_get_estimate_rate (GstAudioDecoder * dec)
3369
0
{
3370
0
  g_return_val_if_fail (GST_IS_AUDIO_DECODER (dec), 0);
3371
3372
0
  return dec->priv->ctx.do_estimate_rate;
3373
0
}
3374
3375
/**
3376
 * gst_audio_decoder_get_delay:
3377
 * @dec: a #GstAudioDecoder
3378
 *
3379
 * Returns: currently configured decoder delay
3380
 */
3381
gint
3382
gst_audio_decoder_get_delay (GstAudioDecoder * dec)
3383
0
{
3384
0
  g_return_val_if_fail (GST_IS_AUDIO_DECODER (dec), 0);
3385
3386
0
  return dec->priv->ctx.delay;
3387
0
}
3388
3389
/**
3390
 * gst_audio_decoder_set_max_errors:
3391
 * @dec: a #GstAudioDecoder
3392
 * @num: max tolerated errors
3393
 *
3394
 * Sets numbers of tolerated decoder errors, where a tolerated one is then only
3395
 * warned about, but more than tolerated will lead to fatal error. You can set
3396
 * -1 for never returning fatal errors. Default is set to
3397
 * GST_AUDIO_DECODER_MAX_ERRORS.
3398
 */
3399
void
3400
gst_audio_decoder_set_max_errors (GstAudioDecoder * dec, gint num)
3401
0
{
3402
0
  g_return_if_fail (GST_IS_AUDIO_DECODER (dec));
3403
3404
0
  dec->priv->max_errors = num;
3405
0
}
3406
3407
/**
3408
 * gst_audio_decoder_get_max_errors:
3409
 * @dec: a #GstAudioDecoder
3410
 *
3411
 * Returns: currently configured decoder tolerated error count.
3412
 */
3413
gint
3414
gst_audio_decoder_get_max_errors (GstAudioDecoder * dec)
3415
0
{
3416
0
  g_return_val_if_fail (GST_IS_AUDIO_DECODER (dec), 0);
3417
3418
0
  return dec->priv->max_errors;
3419
0
}
3420
3421
/**
3422
 * gst_audio_decoder_set_latency:
3423
 * @dec: a #GstAudioDecoder
3424
 * @min: minimum latency
3425
 * @max: maximum latency
3426
 *
3427
 * Sets decoder latency. If the provided values changed from
3428
 * previously provided ones, this will also post a LATENCY message on the bus
3429
 * so the pipeline can reconfigure its global latency.
3430
 */
3431
void
3432
gst_audio_decoder_set_latency (GstAudioDecoder * dec,
3433
    GstClockTime min, GstClockTime max)
3434
0
{
3435
0
  gboolean post_message = FALSE;
3436
3437
0
  g_return_if_fail (GST_IS_AUDIO_DECODER (dec));
3438
0
  g_return_if_fail (GST_CLOCK_TIME_IS_VALID (min));
3439
0
  g_return_if_fail (min <= max);
3440
3441
0
  GST_DEBUG_OBJECT (dec,
3442
0
      "min_latency:%" GST_TIME_FORMAT " max_latency:%" GST_TIME_FORMAT,
3443
0
      GST_TIME_ARGS (min), GST_TIME_ARGS (max));
3444
3445
0
  GST_OBJECT_LOCK (dec);
3446
0
  if (dec->priv->ctx.min_latency != min) {
3447
0
    dec->priv->ctx.min_latency = min;
3448
0
    post_message = TRUE;
3449
0
  }
3450
0
  if (dec->priv->ctx.max_latency != max) {
3451
0
    dec->priv->ctx.max_latency = max;
3452
0
    post_message = TRUE;
3453
0
  }
3454
0
  if (!dec->priv->ctx.posted_latency_msg) {
3455
0
    dec->priv->ctx.posted_latency_msg = TRUE;
3456
0
    post_message = TRUE;
3457
0
  }
3458
0
  GST_OBJECT_UNLOCK (dec);
3459
3460
  /* post latency message on the bus */
3461
0
  if (post_message)
3462
0
    gst_element_post_message (GST_ELEMENT (dec),
3463
0
        gst_message_new_latency (GST_OBJECT (dec)));
3464
0
}
3465
3466
/**
3467
 * gst_audio_decoder_get_latency:
3468
 * @dec: a #GstAudioDecoder
3469
 * @min: (out) (optional): a pointer to storage to hold minimum latency
3470
 * @max: (out) (optional): a pointer to storage to hold maximum latency
3471
 *
3472
 * Sets the variables pointed to by @min and @max to the currently configured
3473
 * latency.
3474
 */
3475
void
3476
gst_audio_decoder_get_latency (GstAudioDecoder * dec,
3477
    GstClockTime * min, GstClockTime * max)
3478
0
{
3479
0
  g_return_if_fail (GST_IS_AUDIO_DECODER (dec));
3480
3481
0
  GST_OBJECT_LOCK (dec);
3482
0
  if (min)
3483
0
    *min = dec->priv->ctx.min_latency;
3484
0
  if (max)
3485
0
    *max = dec->priv->ctx.max_latency;
3486
0
  GST_OBJECT_UNLOCK (dec);
3487
0
}
3488
3489
/**
3490
 * gst_audio_decoder_get_parse_state:
3491
 * @dec: a #GstAudioDecoder
3492
 * @sync: (out) (optional): a pointer to a variable to hold the current sync state
3493
 * @eos: (out) (optional): a pointer to a variable to hold the current eos state
3494
 *
3495
 * Return current parsing (sync and eos) state.
3496
 */
3497
void
3498
gst_audio_decoder_get_parse_state (GstAudioDecoder * dec,
3499
    gboolean * sync, gboolean * eos)
3500
0
{
3501
0
  g_return_if_fail (GST_IS_AUDIO_DECODER (dec));
3502
3503
0
  if (sync)
3504
0
    *sync = dec->priv->ctx.sync;
3505
0
  if (eos)
3506
0
    *eos = dec->priv->ctx.eos;
3507
0
}
3508
3509
/**
3510
 * gst_audio_decoder_set_allocation_caps:
3511
 * @dec: a #GstAudioDecoder
3512
 * @allocation_caps: (nullable): a #GstCaps or %NULL
3513
 *
3514
 * Sets a caps in allocation query which are different from the set
3515
 * pad's caps. Use this function before calling
3516
 * gst_audio_decoder_negotiate(). Setting to %NULL the allocation
3517
 * query will use the caps from the pad.
3518
 *
3519
 * Since: 1.10
3520
 */
3521
void
3522
gst_audio_decoder_set_allocation_caps (GstAudioDecoder * dec,
3523
    GstCaps * allocation_caps)
3524
0
{
3525
0
  g_return_if_fail (GST_IS_AUDIO_DECODER (dec));
3526
3527
0
  gst_caps_replace (&dec->priv->ctx.allocation_caps, allocation_caps);
3528
0
}
3529
3530
/**
3531
 * gst_audio_decoder_set_plc:
3532
 * @dec: a #GstAudioDecoder
3533
 * @enabled: new state
3534
 *
3535
 * Enable or disable decoder packet loss concealment, provided subclass
3536
 * and codec are capable and allow handling plc.
3537
 *
3538
 * MT safe.
3539
 */
3540
void
3541
gst_audio_decoder_set_plc (GstAudioDecoder * dec, gboolean enabled)
3542
0
{
3543
0
  g_return_if_fail (GST_IS_AUDIO_DECODER (dec));
3544
3545
0
  GST_LOG_OBJECT (dec, "enabled: %d", enabled);
3546
3547
0
  GST_OBJECT_LOCK (dec);
3548
0
  dec->priv->plc = enabled;
3549
0
  GST_OBJECT_UNLOCK (dec);
3550
0
}
3551
3552
/**
3553
 * gst_audio_decoder_get_plc:
3554
 * @dec: a #GstAudioDecoder
3555
 *
3556
 * Queries decoder packet loss concealment handling.
3557
 *
3558
 * Returns: TRUE if packet loss concealment is enabled.
3559
 *
3560
 * MT safe.
3561
 */
3562
gboolean
3563
gst_audio_decoder_get_plc (GstAudioDecoder * dec)
3564
0
{
3565
0
  gboolean result;
3566
3567
0
  g_return_val_if_fail (GST_IS_AUDIO_DECODER (dec), FALSE);
3568
3569
0
  GST_OBJECT_LOCK (dec);
3570
0
  result = dec->priv->plc;
3571
0
  GST_OBJECT_UNLOCK (dec);
3572
3573
0
  return result;
3574
0
}
3575
3576
/**
3577
 * gst_audio_decoder_set_min_latency:
3578
 * @dec: a #GstAudioDecoder
3579
 * @num: new minimum latency
3580
 *
3581
 * Sets decoder minimum aggregation latency.
3582
 *
3583
 * MT safe.
3584
 */
3585
void
3586
gst_audio_decoder_set_min_latency (GstAudioDecoder * dec, GstClockTime num)
3587
0
{
3588
0
  g_return_if_fail (GST_IS_AUDIO_DECODER (dec));
3589
0
  g_return_if_fail (GST_CLOCK_TIME_IS_VALID (num));
3590
3591
0
  GST_OBJECT_LOCK (dec);
3592
0
  dec->priv->latency = num;
3593
0
  GST_OBJECT_UNLOCK (dec);
3594
0
}
3595
3596
/**
3597
 * gst_audio_decoder_get_min_latency:
3598
 * @dec: a #GstAudioDecoder
3599
 *
3600
 * Queries decoder's latency aggregation.
3601
 *
3602
 * Returns: aggregation latency.
3603
 *
3604
 * MT safe.
3605
 */
3606
GstClockTime
3607
gst_audio_decoder_get_min_latency (GstAudioDecoder * dec)
3608
0
{
3609
0
  GstClockTime result;
3610
3611
0
  g_return_val_if_fail (GST_IS_AUDIO_DECODER (dec), FALSE);
3612
3613
0
  GST_OBJECT_LOCK (dec);
3614
0
  result = dec->priv->latency;
3615
0
  GST_OBJECT_UNLOCK (dec);
3616
3617
0
  return result;
3618
0
}
3619
3620
/**
3621
 * gst_audio_decoder_set_tolerance:
3622
 * @dec: a #GstAudioDecoder
3623
 * @tolerance: new tolerance
3624
 *
3625
 * Configures decoder audio jitter tolerance threshold.
3626
 *
3627
 * MT safe.
3628
 */
3629
void
3630
gst_audio_decoder_set_tolerance (GstAudioDecoder * dec, GstClockTime tolerance)
3631
0
{
3632
0
  g_return_if_fail (GST_IS_AUDIO_DECODER (dec));
3633
0
  g_return_if_fail (GST_CLOCK_TIME_IS_VALID (tolerance));
3634
3635
0
  GST_OBJECT_LOCK (dec);
3636
0
  dec->priv->tolerance = tolerance;
3637
0
  GST_OBJECT_UNLOCK (dec);
3638
0
}
3639
3640
/**
3641
 * gst_audio_decoder_get_tolerance:
3642
 * @dec: a #GstAudioDecoder
3643
 *
3644
 * Queries current audio jitter tolerance threshold.
3645
 *
3646
 * Returns: decoder audio jitter tolerance threshold.
3647
 *
3648
 * MT safe.
3649
 */
3650
GstClockTime
3651
gst_audio_decoder_get_tolerance (GstAudioDecoder * dec)
3652
0
{
3653
0
  GstClockTime result;
3654
3655
0
  g_return_val_if_fail (GST_IS_AUDIO_DECODER (dec), 0);
3656
3657
0
  GST_OBJECT_LOCK (dec);
3658
0
  result = dec->priv->tolerance;
3659
0
  GST_OBJECT_UNLOCK (dec);
3660
3661
0
  return result;
3662
0
}
3663
3664
/**
3665
 * gst_audio_decoder_set_drainable:
3666
 * @dec: a #GstAudioDecoder
3667
 * @enabled: new state
3668
 *
3669
 * Configures decoder drain handling.  If drainable, subclass might
3670
 * be handed a NULL buffer to have it return any leftover decoded data.
3671
 * Otherwise, it is not considered so capable and will only ever be passed
3672
 * real data.
3673
 *
3674
 * MT safe.
3675
 */
3676
void
3677
gst_audio_decoder_set_drainable (GstAudioDecoder * dec, gboolean enabled)
3678
0
{
3679
0
  g_return_if_fail (GST_IS_AUDIO_DECODER (dec));
3680
3681
0
  GST_OBJECT_LOCK (dec);
3682
0
  dec->priv->drainable = enabled;
3683
0
  GST_OBJECT_UNLOCK (dec);
3684
0
}
3685
3686
/**
3687
 * gst_audio_decoder_get_drainable:
3688
 * @dec: a #GstAudioDecoder
3689
 *
3690
 * Queries decoder drain handling.
3691
 *
3692
 * Returns: TRUE if drainable handling is enabled.
3693
 *
3694
 * MT safe.
3695
 */
3696
gboolean
3697
gst_audio_decoder_get_drainable (GstAudioDecoder * dec)
3698
0
{
3699
0
  gboolean result;
3700
3701
0
  g_return_val_if_fail (GST_IS_AUDIO_DECODER (dec), 0);
3702
3703
0
  GST_OBJECT_LOCK (dec);
3704
0
  result = dec->priv->drainable;
3705
0
  GST_OBJECT_UNLOCK (dec);
3706
3707
0
  return result;
3708
0
}
3709
3710
/**
3711
 * gst_audio_decoder_set_needs_format:
3712
 * @dec: a #GstAudioDecoder
3713
 * @enabled: new state
3714
 *
3715
 * Configures decoder format needs.  If enabled, subclass needs to be
3716
 * negotiated with format caps before it can process any data.  It will then
3717
 * never be handed any data before it has been configured.
3718
 * Otherwise, it might be handed data without having been configured and
3719
 * is then expected being able to do so either by default
3720
 * or based on the input data.
3721
 *
3722
 * MT safe.
3723
 */
3724
void
3725
gst_audio_decoder_set_needs_format (GstAudioDecoder * dec, gboolean enabled)
3726
0
{
3727
0
  g_return_if_fail (GST_IS_AUDIO_DECODER (dec));
3728
3729
0
  GST_OBJECT_LOCK (dec);
3730
0
  dec->priv->needs_format = enabled;
3731
0
  GST_OBJECT_UNLOCK (dec);
3732
0
}
3733
3734
/**
3735
 * gst_audio_decoder_get_needs_format:
3736
 * @dec: a #GstAudioDecoder
3737
 *
3738
 * Queries decoder required format handling.
3739
 *
3740
 * Returns: TRUE if required format handling is enabled.
3741
 *
3742
 * MT safe.
3743
 */
3744
gboolean
3745
gst_audio_decoder_get_needs_format (GstAudioDecoder * dec)
3746
0
{
3747
0
  gboolean result;
3748
3749
0
  g_return_val_if_fail (GST_IS_AUDIO_DECODER (dec), FALSE);
3750
3751
0
  GST_OBJECT_LOCK (dec);
3752
0
  result = dec->priv->needs_format;
3753
0
  GST_OBJECT_UNLOCK (dec);
3754
3755
0
  return result;
3756
0
}
3757
3758
/**
3759
 * gst_audio_decoder_merge_tags:
3760
 * @dec: a #GstAudioDecoder
3761
 * @tags: (nullable): a #GstTagList to merge, or NULL
3762
 * @mode: the #GstTagMergeMode to use, usually #GST_TAG_MERGE_REPLACE
3763
 *
3764
 * Sets the audio decoder tags and how they should be merged with any
3765
 * upstream stream tags. This will override any tags previously-set
3766
 * with gst_audio_decoder_merge_tags().
3767
 *
3768
 * Note that this is provided for convenience, and the subclass is
3769
 * not required to use this and can still do tag handling on its own.
3770
 */
3771
void
3772
gst_audio_decoder_merge_tags (GstAudioDecoder * dec,
3773
    const GstTagList * tags, GstTagMergeMode mode)
3774
73
{
3775
73
  g_return_if_fail (GST_IS_AUDIO_DECODER (dec));
3776
73
  g_return_if_fail (tags == NULL || GST_IS_TAG_LIST (tags));
3777
73
  g_return_if_fail (mode != GST_TAG_MERGE_UNDEFINED);
3778
3779
73
  GST_AUDIO_DECODER_STREAM_LOCK (dec);
3780
73
  if (dec->priv->taglist != tags) {
3781
73
    if (dec->priv->taglist) {
3782
1
      gst_tag_list_unref (dec->priv->taglist);
3783
1
      dec->priv->taglist = NULL;
3784
1
      dec->priv->decoder_tags_merge_mode = GST_TAG_MERGE_KEEP_ALL;
3785
1
    }
3786
73
    if (tags) {
3787
73
      dec->priv->taglist = gst_tag_list_ref ((GstTagList *) tags);
3788
73
      dec->priv->decoder_tags_merge_mode = mode;
3789
73
    }
3790
3791
73
    GST_DEBUG_OBJECT (dec, "setting decoder tags to %" GST_PTR_FORMAT, tags);
3792
73
    dec->priv->taglist_changed = TRUE;
3793
73
  }
3794
73
  GST_AUDIO_DECODER_STREAM_UNLOCK (dec);
3795
73
}
3796
3797
/**
3798
 * gst_audio_decoder_allocate_output_buffer:
3799
 * @dec: a #GstAudioDecoder
3800
 * @size: size of the buffer
3801
 *
3802
 * Helper function that allocates a buffer to hold an audio frame
3803
 * for @dec's current output format.
3804
 *
3805
 * Returns: (transfer full): allocated buffer
3806
 */
3807
GstBuffer *
3808
gst_audio_decoder_allocate_output_buffer (GstAudioDecoder * dec, gsize size)
3809
68
{
3810
68
  GstBuffer *buffer = NULL;
3811
68
  gboolean needs_reconfigure = FALSE;
3812
3813
68
  g_return_val_if_fail (size > 0, NULL);
3814
3815
68
  GST_DEBUG ("alloc src buffer");
3816
3817
68
  GST_AUDIO_DECODER_STREAM_LOCK (dec);
3818
3819
68
  needs_reconfigure = gst_pad_check_reconfigure (dec->srcpad);
3820
68
  if (G_UNLIKELY (dec->priv->ctx.output_format_changed ||
3821
68
          (GST_AUDIO_INFO_IS_VALID (&dec->priv->ctx.info)
3822
68
              && needs_reconfigure))) {
3823
68
    if (!gst_audio_decoder_negotiate_unlocked (dec)) {
3824
0
      GST_INFO_OBJECT (dec, "Failed to negotiate, fallback allocation");
3825
0
      gst_pad_mark_reconfigure (dec->srcpad);
3826
0
      goto fallback;
3827
0
    }
3828
68
  }
3829
3830
68
  buffer =
3831
68
      gst_buffer_new_allocate (dec->priv->ctx.allocator, size,
3832
68
      &dec->priv->ctx.params);
3833
68
  if (!buffer) {
3834
0
    GST_INFO_OBJECT (dec, "couldn't allocate output buffer");
3835
0
    goto fallback;
3836
0
  }
3837
3838
68
  GST_AUDIO_DECODER_STREAM_UNLOCK (dec);
3839
3840
68
  return buffer;
3841
0
fallback:
3842
0
  buffer = gst_buffer_new_allocate (NULL, size, NULL);
3843
0
  GST_AUDIO_DECODER_STREAM_UNLOCK (dec);
3844
3845
0
  return buffer;
3846
68
}
3847
3848
/**
3849
 * gst_audio_decoder_get_allocator:
3850
 * @dec: a #GstAudioDecoder
3851
 * @allocator: (out) (optional) (nullable) (transfer full): the #GstAllocator
3852
 * used
3853
 * @params: (out) (optional) (transfer full): the
3854
 * #GstAllocationParams of @allocator
3855
 *
3856
 * Lets #GstAudioDecoder sub-classes to know the memory @allocator
3857
 * used by the base class and its @params.
3858
 *
3859
 * Unref the @allocator after use it.
3860
 */
3861
void
3862
gst_audio_decoder_get_allocator (GstAudioDecoder * dec,
3863
    GstAllocator ** allocator, GstAllocationParams * params)
3864
0
{
3865
0
  g_return_if_fail (GST_IS_AUDIO_DECODER (dec));
3866
3867
0
  if (allocator)
3868
0
    *allocator = dec->priv->ctx.allocator ?
3869
0
        gst_object_ref (dec->priv->ctx.allocator) : NULL;
3870
3871
0
  if (params)
3872
0
    *params = dec->priv->ctx.params;
3873
0
}
3874
3875
/**
3876
 * gst_audio_decoder_set_use_default_pad_acceptcaps:
3877
 * @decoder: a #GstAudioDecoder
3878
 * @use: if the default pad accept-caps query handling should be used
3879
 *
3880
 * Lets #GstAudioDecoder sub-classes decide if they want the sink pad
3881
 * to use the default pad query handler to reply to accept-caps queries.
3882
 *
3883
 * By setting this to true it is possible to further customize the default
3884
 * handler with %GST_PAD_SET_ACCEPT_INTERSECT and
3885
 * %GST_PAD_SET_ACCEPT_TEMPLATE
3886
 *
3887
 * Since: 1.6
3888
 */
3889
void
3890
gst_audio_decoder_set_use_default_pad_acceptcaps (GstAudioDecoder * decoder,
3891
    gboolean use)
3892
86
{
3893
86
  decoder->priv->use_default_pad_acceptcaps = use;
3894
86
}