• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /* GStreamer
2  *
3  * Copyright (C) 2014 Samsung Electronics. All rights reserved.
4  *   Author: Thiago Santos <ts.santos@sisa.samsung.com>
5  *
6  * This library is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU Library General Public
8  * License as published by the Free Software Foundation; either
9  * version 2 of the License, or (at your option) any later version.
10  *
11  * This library is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
14  * Library General Public License for more details.
15  *
16  * You should have received a copy of the GNU Library General Public
17  * License along with this library; if not, write to the
18  * Free Software Foundation, Inc., 51 Franklin St, Fifth Floor,
19  * Boston, MA 02110-1301, USA.
20  */
21 
22 #ifdef HAVE_CONFIG_H
23 #include "config.h"
24 #endif
25 #include <gst/gst.h>
26 #include <gst/check/gstcheck.h>
27 #include <gst/check/gstharness.h>
28 #include <gst/audio/audio.h>
29 #include <gst/app/app.h>
30 
31 #define TEST_MSECS_PER_SAMPLE 44100
32 
33 #define RESTRICTED_CAPS_RATE 44100
34 #define RESTRICTED_CAPS_CHANNELS 6
35 static GstStaticPadTemplate sinktemplate_restricted =
36 GST_STATIC_PAD_TEMPLATE ("sink",
37     GST_PAD_SINK,
38     GST_PAD_ALWAYS,
39     GST_STATIC_CAPS ("audio/x-raw, rate=(int)44100, channels=(int)6")
40     );
41 
42 static GstStaticPadTemplate sinktemplate_with_range =
43 GST_STATIC_PAD_TEMPLATE ("sink",
44     GST_PAD_SINK,
45     GST_PAD_ALWAYS,
46     GST_STATIC_CAPS ("audio/x-raw, rate=(int)[1,44100], channels=(int)[1,6]")
47     );
48 
49 static GstStaticPadTemplate sinktemplate_default =
50 GST_STATIC_PAD_TEMPLATE ("sink",
51     GST_PAD_SINK,
52     GST_PAD_ALWAYS,
53     GST_STATIC_CAPS ("audio/x-raw, format=(string)S32LE, "
54         "rate=(int)[1, 320000], channels=(int)[1, 32],"
55         "layout=(string)interleaved")
56     );
57 static GstStaticPadTemplate srctemplate_default =
58 GST_STATIC_PAD_TEMPLATE ("src",
59     GST_PAD_SRC,
60     GST_PAD_ALWAYS,
61     GST_STATIC_CAPS ("audio/x-test-custom")
62     );
63 
64 #define GST_AUDIO_DECODER_TESTER_TYPE gst_audio_decoder_tester_get_type()
65 static GType gst_audio_decoder_tester_get_type (void);
66 
67 typedef struct _GstAudioDecoderTester GstAudioDecoderTester;
68 typedef struct _GstAudioDecoderTesterClass GstAudioDecoderTesterClass;
69 
70 struct _GstAudioDecoderTester
71 {
72   GstAudioDecoder parent;
73 
74   gboolean setoutputformat_on_decoding;
75   gboolean output_too_many_frames;
76   gboolean delay_decoding;
77   GstBuffer *prev_buf;
78 };
79 
80 struct _GstAudioDecoderTesterClass
81 {
82   GstAudioDecoderClass parent_class;
83 };
84 
85 G_DEFINE_TYPE (GstAudioDecoderTester, gst_audio_decoder_tester,
86     GST_TYPE_AUDIO_DECODER);
87 
88 static gboolean
gst_audio_decoder_tester_start(GstAudioDecoder * dec)89 gst_audio_decoder_tester_start (GstAudioDecoder * dec)
90 {
91   return TRUE;
92 }
93 
94 static gboolean
gst_audio_decoder_tester_stop(GstAudioDecoder * dec)95 gst_audio_decoder_tester_stop (GstAudioDecoder * dec)
96 {
97   GstAudioDecoderTester *tester = (GstAudioDecoderTester *) dec;
98   if (tester->prev_buf) {
99     gst_buffer_unref (tester->prev_buf);
100     tester->prev_buf = NULL;
101   }
102   return TRUE;
103 }
104 
105 static void
gst_audio_decoder_tester_flush(GstAudioDecoder * dec,gboolean hard)106 gst_audio_decoder_tester_flush (GstAudioDecoder * dec, gboolean hard)
107 {
108 }
109 
110 static gboolean
gst_audio_decoder_tester_set_format(GstAudioDecoder * dec,GstCaps * caps)111 gst_audio_decoder_tester_set_format (GstAudioDecoder * dec, GstCaps * caps)
112 {
113   GstAudioDecoderTester *tester = (GstAudioDecoderTester *) dec;
114   GstAudioInfo info;
115 
116   if (!tester->setoutputformat_on_decoding) {
117     caps = gst_caps_new_simple ("audio/x-raw", "format", G_TYPE_STRING, "S32LE",
118         "channels", G_TYPE_INT, 2, "rate", G_TYPE_INT, 44100,
119         "layout", G_TYPE_STRING, "interleaved", NULL);
120     gst_audio_info_from_caps (&info, caps);
121     gst_caps_unref (caps);
122 
123     gst_audio_decoder_set_output_format (dec, &info);
124   }
125   return TRUE;
126 }
127 
128 static GstFlowReturn
gst_audio_decoder_tester_handle_frame(GstAudioDecoder * dec,GstBuffer * buffer)129 gst_audio_decoder_tester_handle_frame (GstAudioDecoder * dec,
130     GstBuffer * buffer)
131 {
132   GstAudioDecoderTester *tester = (GstAudioDecoderTester *) dec;
133   guint8 *data;
134   gint size;
135   GstMapInfo map;
136   GstBuffer *output_buffer;
137   GstFlowReturn ret = GST_FLOW_OK;
138   gboolean do_plc = gst_audio_decoder_get_plc (dec) &&
139       gst_audio_decoder_get_plc_aware (dec);
140 
141   if (buffer == NULL || (!do_plc && gst_buffer_get_size (buffer) == 0))
142     return GST_FLOW_OK;
143 
144   gst_buffer_ref (buffer);
145   if (tester->setoutputformat_on_decoding) {
146     GstCaps *caps;
147     GstAudioInfo info;
148 
149     caps = gst_caps_new_simple ("audio/x-raw", "format", G_TYPE_STRING, "S32LE",
150         "channels", G_TYPE_INT, 2, "rate", G_TYPE_INT, 44100,
151         "layout", G_TYPE_STRING, "interleaved", NULL);
152     gst_audio_info_from_caps (&info, caps);
153     gst_caps_unref (caps);
154 
155     gst_audio_decoder_set_output_format (dec, &info);
156   }
157   if ((tester->delay_decoding && tester->prev_buf != NULL) ||
158       !tester->delay_decoding) {
159     gsize buf_num = tester->delay_decoding ? 2 : 1;
160     gint i;
161 
162     for (i = 0; i != buf_num; ++i) {
163       GstBuffer *cur_buf = buf_num == 1 || i != 0 ? buffer : tester->prev_buf;
164       gst_buffer_map (cur_buf, &map, GST_MAP_READ);
165 
166       /* the output is SE32LE stereo 44100 Hz */
167       size = 2 * 4;
168       g_assert (size == sizeof (guint64));
169       data = g_malloc0 (size);
170 
171       if (map.size) {
172         g_assert_cmpint (map.size, >=, sizeof (guint64));
173         memcpy (data, map.data, sizeof (guint64));
174       }
175 
176       output_buffer = gst_buffer_new_wrapped (data, size);
177 
178       gst_buffer_unmap (cur_buf, &map);
179 
180       if (tester->output_too_many_frames) {
181         ret = gst_audio_decoder_finish_frame (dec, output_buffer, 2);
182       } else {
183         ret = gst_audio_decoder_finish_frame (dec, output_buffer, 1);
184       }
185       if (ret != GST_FLOW_OK)
186         break;
187     }
188     tester->delay_decoding = FALSE;
189   }
190 
191   if (tester->prev_buf)
192     gst_buffer_unref (tester->prev_buf);
193   tester->prev_buf = NULL;
194   if (tester->delay_decoding)
195     tester->prev_buf = buffer;
196   else
197     gst_buffer_unref (buffer);
198   return ret;
199 }
200 
201 static void
gst_audio_decoder_tester_class_init(GstAudioDecoderTesterClass * klass)202 gst_audio_decoder_tester_class_init (GstAudioDecoderTesterClass * klass)
203 {
204   GstElementClass *element_class = GST_ELEMENT_CLASS (klass);
205   GstAudioDecoderClass *audiosink_class = GST_AUDIO_DECODER_CLASS (klass);
206 
207   static GstStaticPadTemplate sink_templ = GST_STATIC_PAD_TEMPLATE ("sink",
208       GST_PAD_SINK, GST_PAD_ALWAYS,
209       GST_STATIC_CAPS ("audio/x-test-custom"));
210 
211   static GstStaticPadTemplate src_templ = GST_STATIC_PAD_TEMPLATE ("src",
212       GST_PAD_SRC, GST_PAD_ALWAYS,
213       GST_STATIC_CAPS ("audio/x-raw"));
214 
215   gst_element_class_add_static_pad_template (element_class, &sink_templ);
216   gst_element_class_add_static_pad_template (element_class, &src_templ);
217 
218   gst_element_class_set_metadata (element_class,
219       "AudioDecoderTester", "Decoder/Audio", "yep", "me");
220 
221   audiosink_class->start = gst_audio_decoder_tester_start;
222   audiosink_class->stop = gst_audio_decoder_tester_stop;
223   audiosink_class->flush = gst_audio_decoder_tester_flush;
224   audiosink_class->handle_frame = gst_audio_decoder_tester_handle_frame;
225   audiosink_class->set_format = gst_audio_decoder_tester_set_format;
226 }
227 
228 static void
gst_audio_decoder_tester_init(GstAudioDecoderTester * tester)229 gst_audio_decoder_tester_init (GstAudioDecoderTester * tester)
230 {
231 }
232 
233 static GstHarness *
setup_audiodecodertester(GstStaticPadTemplate * sinktemplate,GstStaticPadTemplate * srctemplate)234 setup_audiodecodertester (GstStaticPadTemplate * sinktemplate,
235     GstStaticPadTemplate * srctemplate)
236 {
237   GstHarness *h;
238   GstElement *dec;
239 
240   if (sinktemplate == NULL)
241     sinktemplate = &sinktemplate_default;
242   if (srctemplate == NULL)
243     srctemplate = &srctemplate_default;
244 
245   dec = g_object_new (GST_AUDIO_DECODER_TESTER_TYPE, NULL);
246   h = gst_harness_new_full (dec, srctemplate, "sink", sinktemplate, "src");
247 
248   gst_harness_set_src_caps (h,
249       gst_caps_new_simple ("audio/x-test-custom",
250           "channels", G_TYPE_INT, 2, "rate", G_TYPE_INT, 44100, NULL));
251 
252   gst_object_unref (dec);
253   return h;
254 }
255 
256 static GstBuffer *
create_test_buffer(guint64 num)257 create_test_buffer (guint64 num)
258 {
259   GstBuffer *buffer;
260   guint64 *data = g_malloc (sizeof (guint64));
261 
262   *data = num;
263 
264   buffer = gst_buffer_new_wrapped (data, sizeof (guint64));
265 
266   GST_BUFFER_PTS (buffer) =
267       gst_util_uint64_scale_round (num, GST_SECOND, TEST_MSECS_PER_SAMPLE);
268   GST_BUFFER_DURATION (buffer) =
269       gst_util_uint64_scale_round (1, GST_SECOND, TEST_MSECS_PER_SAMPLE);
270 
271   return buffer;
272 }
273 
274 #define NUM_BUFFERS 10
275 
GST_START_TEST(audiodecoder_playback)276 GST_START_TEST (audiodecoder_playback)
277 {
278   GstBuffer *buffer;
279   guint64 i;
280 
281   GstHarness *h = setup_audiodecodertester (NULL, NULL);
282 
283   /* push buffers, the data is actually a number so we can track them */
284   for (i = 0; i < NUM_BUFFERS; i++) {
285     GstMapInfo map;
286     guint64 num;
287 
288     fail_unless (gst_harness_push (h, create_test_buffer (i)) == GST_FLOW_OK);
289 
290     /* check that buffer was received by our source pad */
291     buffer = gst_harness_pull (h);
292 
293     gst_buffer_map (buffer, &map, GST_MAP_READ);
294 
295     num = *(guint64 *) map.data;
296     fail_unless_equals_uint64 (i, num);
297     fail_unless_equals_uint64 (GST_BUFFER_PTS (buffer),
298         gst_util_uint64_scale_round (i, GST_SECOND, TEST_MSECS_PER_SAMPLE));
299     fail_unless_equals_uint64 (GST_BUFFER_DURATION (buffer),
300         gst_util_uint64_scale_round (1, GST_SECOND, TEST_MSECS_PER_SAMPLE));
301 
302     gst_buffer_unmap (buffer, &map);
303 
304     gst_buffer_unref (buffer);
305   }
306 
307   fail_unless (gst_harness_push_event (h, gst_event_new_eos ()));
308 
309   fail_unless_equals_int (0, gst_harness_buffers_in_queue (h));
310 
311   gst_harness_teardown (h);
312 }
313 
314 GST_END_TEST;
315 
316 
317 static void
check_audiodecoder_negotiation(GstHarness * h)318 check_audiodecoder_negotiation (GstHarness * h)
319 {
320   gboolean received_caps = FALSE;
321   guint i;
322   guint events_received = gst_harness_events_received (h);
323 
324   for (i = 0; i < events_received; i++) {
325     GstEvent *event = gst_harness_pull_event (h);
326 
327     if (GST_EVENT_TYPE (event) == GST_EVENT_CAPS) {
328       GstCaps *caps;
329       GstStructure *structure;
330       gint channels;
331       gint rate;
332 
333       gst_event_parse_caps (event, &caps);
334       structure = gst_caps_get_structure (caps, 0);
335 
336       fail_unless (gst_structure_get_int (structure, "rate", &rate));
337       fail_unless (gst_structure_get_int (structure, "channels", &channels));
338 
339       fail_unless (rate == 44100, "%d != %d", rate, 44100);
340       fail_unless (channels == 2, "%d != %d", channels, 2);
341 
342       received_caps = TRUE;
343       gst_event_unref (event);
344       break;
345     }
346     gst_event_unref (event);
347   }
348   fail_unless (received_caps);
349 }
350 
GST_START_TEST(audiodecoder_negotiation_with_buffer)351 GST_START_TEST (audiodecoder_negotiation_with_buffer)
352 {
353   GstHarness *h = setup_audiodecodertester (NULL, NULL);
354 
355   /* push a buffer event to force audiodecoder to push a caps event */
356   fail_unless (gst_harness_push (h, create_test_buffer (0)) == GST_FLOW_OK);
357 
358   check_audiodecoder_negotiation (h);
359 
360   gst_harness_teardown (h);
361 }
362 
363 GST_END_TEST;
364 
GST_START_TEST(audiodecoder_negotiation_with_gap_event)365 GST_START_TEST (audiodecoder_negotiation_with_gap_event)
366 {
367   GstHarness *h = setup_audiodecodertester (NULL, NULL);
368 
369   /* push a gap event to force audiodecoder to push a caps event */
370   fail_unless (gst_harness_push_event (h, gst_event_new_gap (0, GST_SECOND)));
371   fail_unless_equals_int (0, gst_harness_buffers_in_queue (h));
372 
373   check_audiodecoder_negotiation (h);
374 
375   gst_harness_teardown (h);
376 }
377 
378 GST_END_TEST;
379 
GST_START_TEST(audiodecoder_delayed_negotiation_with_gap_event)380 GST_START_TEST (audiodecoder_delayed_negotiation_with_gap_event)
381 {
382   GstHarness *h = setup_audiodecodertester (NULL, NULL);
383 
384   ((GstAudioDecoderTester *) h->element)->setoutputformat_on_decoding = TRUE;
385 
386   /* push a gap event to force audiodecoder to push a caps event */
387   fail_unless (gst_harness_push_event (h, gst_event_new_gap (0, GST_SECOND)));
388   fail_unless_equals_int (0, gst_harness_buffers_in_queue (h));
389 
390   check_audiodecoder_negotiation (h);
391 
392   gst_harness_teardown (h);
393 }
394 
395 GST_END_TEST;
396 
397 /* make sure that the segment event is pushed before the gap */
GST_START_TEST(audiodecoder_first_data_is_gap)398 GST_START_TEST (audiodecoder_first_data_is_gap)
399 {
400   GstHarness *h = setup_audiodecodertester (NULL, NULL);
401 
402   /* push a gap */
403   fail_unless (gst_harness_push_event (h, gst_event_new_gap (0, GST_SECOND)));
404 
405   /* make sure the usual events have been received */
406   {
407     GstEvent *sstart = gst_harness_pull_event (h);
408     fail_unless (GST_EVENT_TYPE (sstart) == GST_EVENT_STREAM_START);
409     gst_event_unref (sstart);
410   }
411   {
412     GstEvent *caps_event = gst_harness_pull_event (h);
413     fail_unless (GST_EVENT_TYPE (caps_event) == GST_EVENT_CAPS);
414     gst_event_unref (caps_event);
415   }
416   {
417     GstEvent *segment_event = gst_harness_pull_event (h);
418     fail_unless (GST_EVENT_TYPE (segment_event) == GST_EVENT_SEGMENT);
419     gst_event_unref (segment_event);
420   }
421 
422   /* Make sure the gap was pushed */
423   {
424     GstEvent *gap = gst_harness_pull_event (h);
425     fail_unless (GST_EVENT_TYPE (gap) == GST_EVENT_GAP);
426     gst_event_unref (gap);
427   }
428   fail_unless_equals_int (0, gst_harness_events_in_queue (h));
429 
430   gst_harness_teardown (h);
431 }
432 
433 GST_END_TEST;
434 
435 /*
436 
437 */
438 
439 static void
_audiodecoder_flush_events(gboolean send_buffers)440 _audiodecoder_flush_events (gboolean send_buffers)
441 {
442   guint i;
443   GstMessage *msg;
444 
445   GstHarness *h = setup_audiodecodertester (NULL, NULL);
446 
447   if (send_buffers) {
448     /* push buffers, the data is actually a number so we can track them */
449     for (i = 0; i < NUM_BUFFERS; i++) {
450       if (i % 10 == 0) {
451         GstTagList *tags;
452 
453         tags = gst_tag_list_new (GST_TAG_TRACK_NUMBER, i, NULL);
454         fail_unless (gst_harness_push_event (h, gst_event_new_tag (tags)));
455       } else {
456         fail_unless (gst_harness_push (h,
457                 create_test_buffer (i)) == GST_FLOW_OK);
458       }
459     }
460   } else {
461     /* push sticky event */
462     GstTagList *tags;
463     tags = gst_tag_list_new (GST_TAG_TRACK_NUMBER, 0, NULL);
464     fail_unless (gst_harness_push_event (h, gst_event_new_tag (tags)));
465   }
466 
467   msg = gst_message_new_element (GST_OBJECT (h->element),
468       gst_structure_new_empty ("test"));
469   fail_unless (gst_harness_push_event (h,
470           gst_event_new_sink_message ("test", msg)));
471   gst_message_unref (msg);
472 
473   fail_unless (gst_harness_push_event (h, gst_event_new_eos ()));
474 
475   /* make sure the usual events have been received */
476   {
477     GstEvent *sstart = gst_harness_pull_event (h);
478     fail_unless (GST_EVENT_TYPE (sstart) == GST_EVENT_STREAM_START);
479     gst_event_unref (sstart);
480   }
481   if (send_buffers) {
482     {
483       GstEvent *caps_event = gst_harness_pull_event (h);
484       fail_unless (GST_EVENT_TYPE (caps_event) == GST_EVENT_CAPS);
485       gst_event_unref (caps_event);
486     }
487     {
488       GstEvent *segment_event = gst_harness_pull_event (h);
489       fail_unless (GST_EVENT_TYPE (segment_event) == GST_EVENT_SEGMENT);
490       gst_event_unref (segment_event);
491     }
492 
493     for (i = 0; i < NUM_BUFFERS / 10; i++) {
494       GstEvent *tag_event = gst_harness_pull_event (h);
495       fail_unless (GST_EVENT_TYPE (tag_event) == GST_EVENT_TAG);
496       gst_event_unref (tag_event);
497     }
498   } else {
499     {
500       GstEvent *segment_event = gst_harness_pull_event (h);
501       fail_unless (GST_EVENT_TYPE (segment_event) == GST_EVENT_SEGMENT);
502       gst_event_unref (segment_event);
503     }
504     {
505       GstEvent *tag_event = gst_harness_pull_event (h);
506       fail_unless (GST_EVENT_TYPE (tag_event) == GST_EVENT_TAG);
507       gst_event_unref (tag_event);
508     }
509   }
510 
511   {
512     GstEvent *sink_msg_event = gst_harness_pull_event (h);
513     fail_unless (GST_EVENT_TYPE (sink_msg_event) == GST_EVENT_SINK_MESSAGE);
514     gst_event_unref (sink_msg_event);
515   }
516 
517   {
518     GstEvent *eos_event = gst_harness_pull_event (h);
519     fail_unless (GST_EVENT_TYPE (eos_event) == GST_EVENT_EOS);
520     gst_event_unref (eos_event);
521   }
522 
523   /* check that EOS was received */
524   fail_unless (GST_PAD_IS_EOS (h->srcpad));
525   fail_unless (gst_harness_push_event (h, gst_event_new_flush_start ()));
526   fail_unless (GST_PAD_IS_EOS (h->srcpad));
527 
528   /* Check that we have tags */
529   {
530     GstEvent *tags = gst_pad_get_sticky_event (h->srcpad, GST_EVENT_TAG, 0);
531     fail_unless (tags != NULL);
532     gst_event_unref (tags);
533   }
534 
535   /* Check that we still have a segment set */
536   {
537     GstEvent *segment =
538         gst_pad_get_sticky_event (h->srcpad, GST_EVENT_SEGMENT, 0);
539     fail_unless (segment != NULL);
540     gst_event_unref (segment);
541   }
542 
543   fail_unless (gst_harness_push_event (h, gst_event_new_flush_stop (TRUE)));
544   fail_if (GST_PAD_IS_EOS (h->srcpad));
545 
546   /* Check that the segment was flushed on FLUSH_STOP */
547   {
548     GstEvent *segment =
549         gst_pad_get_sticky_event (h->srcpad, GST_EVENT_SEGMENT, 0);
550     fail_unless (segment == NULL);
551   }
552 
553   /* Check the tags were not lost on FLUSH_STOP */
554   {
555     GstEvent *tags = gst_pad_get_sticky_event (h->srcpad, GST_EVENT_TAG, 0);
556     fail_unless (tags != NULL);
557     gst_event_unref (tags);
558   }
559 
560   if (send_buffers) {
561     fail_unless_equals_int (NUM_BUFFERS - NUM_BUFFERS / 10,
562         gst_harness_buffers_in_queue (h));
563   } else {
564     fail_unless_equals_int (0, gst_harness_buffers_in_queue (h));
565   }
566 
567   fail_unless_equals_int (2, gst_harness_events_in_queue (h));
568 
569   gst_harness_teardown (h);
570 }
571 
GST_START_TEST(audiodecoder_flush_events_no_buffers)572 GST_START_TEST (audiodecoder_flush_events_no_buffers)
573 {
574   _audiodecoder_flush_events (FALSE);
575 }
576 
577 GST_END_TEST;
578 
GST_START_TEST(audiodecoder_flush_events)579 GST_START_TEST (audiodecoder_flush_events)
580 {
581   _audiodecoder_flush_events (TRUE);
582 }
583 
584 GST_END_TEST;
585 
586 /* An element should always push its segment before sending EOS */
GST_START_TEST(audiodecoder_eos_events_no_buffers)587 GST_START_TEST (audiodecoder_eos_events_no_buffers)
588 {
589   GstHarness *h = setup_audiodecodertester (NULL, NULL);
590 
591   fail_unless (gst_harness_push_event (h, gst_event_new_eos ()));
592   fail_unless (GST_PAD_IS_EOS (h->sinkpad));
593 
594   {
595     GstEvent *segment_event =
596         gst_pad_get_sticky_event (h->sinkpad, GST_EVENT_SEGMENT, 0);
597     fail_unless (segment_event != NULL);
598     gst_event_unref (segment_event);
599   }
600 
601   gst_harness_teardown (h);
602 }
603 
604 GST_END_TEST;
605 
GST_START_TEST(audiodecoder_buffer_after_segment)606 GST_START_TEST (audiodecoder_buffer_after_segment)
607 {
608   GstSegment segment;
609   GstBuffer *buffer;
610   guint64 i;
611   GstClockTime pos;
612 
613 #define SEGMENT_STOP (GST_MSECOND * 10)
614 
615   GstHarness *h = setup_audiodecodertester (NULL, NULL);
616 
617   /* push a new segment */
618   gst_segment_init (&segment, GST_FORMAT_TIME);
619   segment.stop = SEGMENT_STOP;
620   fail_unless (gst_harness_push_event (h, gst_event_new_segment (&segment)));
621 
622   /* push buffers, the data is actually a number so we can track them */
623   i = 0;
624   pos = 0;
625   while (pos < SEGMENT_STOP) {
626     GstMapInfo map;
627     guint64 num;
628 
629     buffer = create_test_buffer (i);
630     pos = GST_BUFFER_TIMESTAMP (buffer) + GST_BUFFER_DURATION (buffer);
631 
632     fail_unless (gst_harness_push (h, buffer) == GST_FLOW_OK);
633 
634     /* check that buffer was received by our source pad */
635     buffer = gst_harness_pull (h);
636 
637     gst_buffer_map (buffer, &map, GST_MAP_READ);
638 
639     num = *(guint64 *) map.data;
640     fail_unless_equals_uint64 (i, num);
641     fail_unless_equals_uint64 (GST_BUFFER_PTS (buffer),
642         gst_util_uint64_scale_round (i, GST_SECOND, TEST_MSECS_PER_SAMPLE));
643     fail_unless_equals_uint64 (GST_BUFFER_DURATION (buffer),
644         gst_util_uint64_scale_round (1, GST_SECOND, TEST_MSECS_PER_SAMPLE));
645 
646     gst_buffer_unmap (buffer, &map);
647 
648     gst_buffer_unref (buffer);
649     i++;
650   }
651 
652   /* this buffer is after the segment */
653   buffer = create_test_buffer (i++);
654   fail_unless (gst_harness_push (h, buffer) == GST_FLOW_EOS);
655 
656   fail_unless (gst_harness_push_event (h, gst_event_new_eos ()));
657   fail_unless_equals_int (0, gst_harness_buffers_in_queue (h));
658 
659   gst_harness_teardown (h);
660 }
661 
662 GST_END_TEST;
663 
GST_START_TEST(audiodecoder_output_too_many_frames)664 GST_START_TEST (audiodecoder_output_too_many_frames)
665 {
666   GstBuffer *buffer;
667   guint64 i;
668 
669   GstHarness *h = setup_audiodecodertester (NULL, NULL);
670 
671   ((GstAudioDecoderTester *) h->element)->output_too_many_frames = TRUE;
672 
673   /* push buffers, the data is actually a number so we can track them */
674   for (i = 0; i < 3; i++) {
675     GstMapInfo map;
676     guint64 num;
677 
678     fail_unless (gst_harness_push (h, create_test_buffer (i)) == GST_FLOW_OK);
679 
680     /* check that buffer was received by our source pad */
681     buffer = gst_harness_pull (h);
682 
683     gst_buffer_map (buffer, &map, GST_MAP_READ);
684 
685     num = *(guint64 *) map.data;
686     fail_unless_equals_uint64 (i, num);
687     fail_unless_equals_uint64 (GST_BUFFER_PTS (buffer),
688         gst_util_uint64_scale_round (i, GST_SECOND, TEST_MSECS_PER_SAMPLE));
689     fail_unless_equals_uint64 (GST_BUFFER_DURATION (buffer),
690         gst_util_uint64_scale_round (1, GST_SECOND, TEST_MSECS_PER_SAMPLE));
691 
692     gst_buffer_unmap (buffer, &map);
693 
694     gst_buffer_unref (buffer);
695   }
696 
697   fail_unless (gst_harness_push_event (h, gst_event_new_eos ()));
698   fail_unless_equals_int (0, gst_harness_buffers_in_queue (h));
699 
700   gst_harness_teardown (h);
701 }
702 
703 GST_END_TEST;
704 
GST_START_TEST(audiodecoder_query_caps_with_fixed_caps_peer)705 GST_START_TEST (audiodecoder_query_caps_with_fixed_caps_peer)
706 {
707   GstCaps *caps;
708   GstCaps *filter;
709   GstStructure *structure;
710   gint rate, channels;
711 
712   GstHarness *h = setup_audiodecodertester (&sinktemplate_restricted, NULL);
713 
714   caps = gst_pad_peer_query_caps (h->srcpad, NULL);
715   fail_unless (caps != NULL);
716 
717   structure = gst_caps_get_structure (caps, 0);
718   fail_unless (gst_structure_get_int (structure, "rate", &rate));
719   fail_unless (gst_structure_get_int (structure, "channels", &channels));
720 
721   /* match our restricted caps values */
722   fail_unless (channels == RESTRICTED_CAPS_CHANNELS);
723   fail_unless (rate == RESTRICTED_CAPS_RATE);
724   gst_caps_unref (caps);
725 
726   filter = gst_caps_new_simple ("audio/x-custom-test", "rate", G_TYPE_INT,
727       10000, "channels", G_TYPE_INT, 12, NULL);
728   caps = gst_pad_peer_query_caps (h->srcpad, filter);
729   fail_unless (caps != NULL);
730   fail_unless (gst_caps_is_empty (caps));
731   gst_caps_unref (caps);
732   gst_caps_unref (filter);
733 
734   gst_harness_teardown (h);
735 }
736 
737 GST_END_TEST;
738 
739 
740 static void
_get_int_range(GstStructure * s,const gchar * field,gint * min_v,gint * max_v)741 _get_int_range (GstStructure * s, const gchar * field, gint * min_v,
742     gint * max_v)
743 {
744   const GValue *value;
745 
746   value = gst_structure_get_value (s, field);
747   fail_unless (value != NULL);
748   fail_unless (GST_VALUE_HOLDS_INT_RANGE (value));
749 
750   *min_v = gst_value_get_int_range_min (value);
751   *max_v = gst_value_get_int_range_max (value);
752 }
753 
GST_START_TEST(audiodecoder_query_caps_with_range_caps_peer)754 GST_START_TEST (audiodecoder_query_caps_with_range_caps_peer)
755 {
756   GstCaps *caps;
757   GstCaps *filter;
758   GstStructure *structure;
759   gint rate, channels;
760   gint rate_min, channels_min;
761   gint rate_max, channels_max;
762 
763   GstHarness *h = setup_audiodecodertester (&sinktemplate_with_range, NULL);
764 
765   caps = gst_pad_peer_query_caps (h->srcpad, NULL);
766   fail_unless (caps != NULL);
767 
768   structure = gst_caps_get_structure (caps, 0);
769   _get_int_range (structure, "rate", &rate_min, &rate_max);
770   _get_int_range (structure, "channels", &channels_min, &channels_max);
771   fail_unless (rate_min == 1);
772   fail_unless (rate_max == RESTRICTED_CAPS_RATE);
773   fail_unless (channels_min == 1);
774   fail_unless (channels_max == RESTRICTED_CAPS_CHANNELS);
775   gst_caps_unref (caps);
776 
777   /* query with a fixed filter */
778   filter = gst_caps_new_simple ("audio/x-test-custom", "rate", G_TYPE_INT,
779       RESTRICTED_CAPS_RATE, "channels", G_TYPE_INT, RESTRICTED_CAPS_CHANNELS,
780       NULL);
781   caps = gst_pad_peer_query_caps (h->srcpad, filter);
782   fail_unless (caps != NULL);
783   structure = gst_caps_get_structure (caps, 0);
784   fail_unless (gst_structure_get_int (structure, "rate", &rate));
785   fail_unless (gst_structure_get_int (structure, "channels", &channels));
786   fail_unless (rate == RESTRICTED_CAPS_RATE);
787   fail_unless (channels == RESTRICTED_CAPS_CHANNELS);
788   gst_caps_unref (caps);
789   gst_caps_unref (filter);
790 
791   /* query with a fixed filter that will lead to empty result */
792   filter = gst_caps_new_simple ("audio/x-test-custom", "rate", G_TYPE_INT,
793       10000, "channels", G_TYPE_INT, 12, NULL);
794   caps = gst_pad_peer_query_caps (h->srcpad, filter);
795   fail_unless (caps != NULL);
796   fail_unless (gst_caps_is_empty (caps));
797   gst_caps_unref (caps);
798   gst_caps_unref (filter);
799 
800   gst_harness_teardown (h);
801 }
802 
803 GST_END_TEST;
804 
805 #define GETCAPS_CAPS_STR "audio/x-test-custom, somefield=(string)getcaps"
806 static GstCaps *
_custom_audio_decoder_getcaps(GstAudioDecoder * dec,GstCaps * filter)807 _custom_audio_decoder_getcaps (GstAudioDecoder * dec, GstCaps * filter)
808 {
809   return gst_caps_from_string (GETCAPS_CAPS_STR);
810 }
811 
GST_START_TEST(audiodecoder_query_caps_with_custom_getcaps)812 GST_START_TEST (audiodecoder_query_caps_with_custom_getcaps)
813 {
814   GstCaps *caps;
815   GstAudioDecoderClass *klass;
816   GstCaps *expected_caps;
817 
818   GstHarness *h = setup_audiodecodertester (&sinktemplate_restricted, NULL);
819 
820   klass = GST_AUDIO_DECODER_CLASS (GST_AUDIO_DECODER_GET_CLASS (h->element));
821   klass->getcaps = _custom_audio_decoder_getcaps;
822 
823   caps = gst_pad_peer_query_caps (h->srcpad, NULL);
824   fail_unless (caps != NULL);
825 
826   expected_caps = gst_caps_from_string (GETCAPS_CAPS_STR);
827   fail_unless (gst_caps_is_equal (expected_caps, caps));
828   gst_caps_unref (expected_caps);
829   gst_caps_unref (caps);
830 
831   gst_harness_teardown (h);
832 }
833 
834 GST_END_TEST;
835 
836 static GstTagList *
pad_get_sticky_tags(GstPad * pad,GstTagScope scope)837 pad_get_sticky_tags (GstPad * pad, GstTagScope scope)
838 {
839   GstTagList *tags = NULL;
840   GstEvent *event;
841   guint i = 0;
842 
843   do {
844     event = gst_pad_get_sticky_event (pad, GST_EVENT_TAG, i++);
845     if (event == NULL)
846       break;
847     gst_event_parse_tag (event, &tags);
848     if (scope == gst_tag_list_get_scope (tags))
849       tags = gst_tag_list_ref (tags);
850     else
851       tags = NULL;
852     gst_event_unref (event);
853   }
854   while (tags == NULL);
855 
856   return tags;
857 }
858 
859 #define tag_list_peek_string(list,tag,p_s) \
860     gst_tag_list_peek_string_index(list,tag,0,p_s)
861 
862 /* Check tag transformations and updates */
GST_START_TEST(audiodecoder_tag_handling)863 GST_START_TEST (audiodecoder_tag_handling)
864 {
865   GstTagList *global_tags;
866   GstTagList *tags;
867   const gchar *s = NULL;
868   guint u = 0;
869 
870   GstHarness *h = setup_audiodecodertester (NULL, NULL);
871 
872   /* =======================================================================
873    * SCENARIO 0: global tags passthrough; check upstream/decoder tag merging
874    * ======================================================================= */
875 
876   /* push some global tags (these should be passed through and not messed with) */
877   global_tags = gst_tag_list_new (GST_TAG_TITLE, "Global", NULL);
878   gst_tag_list_set_scope (global_tags, GST_TAG_SCOPE_GLOBAL);
879   fail_unless (gst_harness_push_event (h,
880           gst_event_new_tag (gst_tag_list_ref (global_tags))));
881 
882   /* create some (upstream) stream tags */
883   tags = gst_tag_list_new (GST_TAG_AUDIO_CODEC, "Upstream Codec",
884       GST_TAG_DESCRIPTION, "Upstream Description", NULL);
885   gst_tag_list_set_scope (tags, GST_TAG_SCOPE_STREAM);
886   fail_unless (gst_harness_push_event (h, gst_event_new_tag (tags)));
887   tags = NULL;
888 
889   /* decoder tags: override/add AUDIO_CODEC, BITRATE and MAXIMUM_BITRATE */
890   {
891     GstTagList *decoder_tags;
892 
893     decoder_tags = gst_tag_list_new (GST_TAG_AUDIO_CODEC, "Decoder Codec",
894         GST_TAG_BITRATE, 250000, GST_TAG_MAXIMUM_BITRATE, 255000, NULL);
895     gst_audio_decoder_merge_tags (GST_AUDIO_DECODER (h->element),
896         decoder_tags, GST_TAG_MERGE_REPLACE);
897     gst_tag_list_unref (decoder_tags);
898   }
899 
900   /* push buffer (this will call gst_audio_decoder_merge_tags with the above) */
901   fail_unless (gst_harness_push (h, create_test_buffer (0)) == GST_FLOW_OK);
902   gst_buffer_unref (gst_harness_pull (h));
903 
904   /* check global tags: should not have been tampered with */
905   tags = pad_get_sticky_tags (h->sinkpad, GST_TAG_SCOPE_GLOBAL);
906   fail_unless (tags != NULL);
907   GST_INFO ("global tags: %" GST_PTR_FORMAT, tags);
908   fail_unless (gst_tag_list_is_equal (tags, global_tags));
909   gst_tag_list_unref (tags);
910 
911   /* check merged stream tags */
912   tags = pad_get_sticky_tags (h->sinkpad, GST_TAG_SCOPE_STREAM);
913   fail_unless (tags != NULL);
914   GST_INFO ("stream tags: %" GST_PTR_FORMAT, tags);
915   /* upstream audio codec should've been replaced with audiodecoder one */
916   fail_unless (tag_list_peek_string (tags, GST_TAG_AUDIO_CODEC, &s));
917   fail_unless_equals_string (s, "Decoder Codec");
918   /* no upstream bitrate, so audiodecoder one should've been added */
919   fail_unless (gst_tag_list_get_uint (tags, GST_TAG_BITRATE, &u));
920   fail_unless_equals_int (u, 250000);
921   /* no upstream maximum-bitrate, so audiodecoder one should've been added */
922   fail_unless (gst_tag_list_get_uint (tags, GST_TAG_MAXIMUM_BITRATE, &u));
923   fail_unless_equals_int (u, 255000);
924   fail_unless (gst_tag_list_get_tag_size (tags, GST_TAG_AUDIO_CODEC) == 1);
925   fail_unless (gst_tag_list_get_tag_size (tags, GST_TAG_BITRATE) == 1);
926   fail_unless (gst_tag_list_get_tag_size (tags, GST_TAG_MAXIMUM_BITRATE) == 1);
927   /* upstream description should've been maintained */
928   fail_unless (gst_tag_list_get_tag_size (tags, GST_TAG_DESCRIPTION) == 1);
929   /* and that should be all: AUDIO_CODEC, DESCRIPTION, BITRATE, MAX BITRATE */
930   fail_unless_equals_int (gst_tag_list_n_tags (tags), 4);
931   gst_tag_list_unref (tags);
932   s = NULL;
933 
934   /* ===================================================================
935    * SCENARIO 1: upstream sends updated tags, decoder tags stay the same
936    * =================================================================== */
937 
938   /* push same upstream stream tags again */
939   tags = gst_tag_list_new (GST_TAG_AUDIO_CODEC, "Upstream Codec",
940       GST_TAG_DESCRIPTION, "Upstream Description", NULL);
941   fail_unless (gst_harness_push_event (h, gst_event_new_tag (tags)));
942   tags = NULL;
943 
944   /* decoder tags are still:
945    * audio-codec = "Decoder Codec", bitrate=250000, maximum-bitrate=255000 */
946 
947   /* check possibly updated merged stream tags, should be same as before */
948   tags = pad_get_sticky_tags (h->sinkpad, GST_TAG_SCOPE_STREAM);
949   fail_unless (tags != NULL);
950   GST_INFO ("stream tags: %" GST_PTR_FORMAT, tags);
951   /* upstream audio codec still be the one merge-replaced by the subclass */
952   fail_unless (tag_list_peek_string (tags, GST_TAG_AUDIO_CODEC, &s));
953   fail_unless_equals_string (s, "Decoder Codec");
954   /* no upstream bitrate, so audiodecoder one should've been added */
955   fail_unless (gst_tag_list_get_uint (tags, GST_TAG_BITRATE, &u));
956   fail_unless_equals_int (u, 250000);
957   fail_unless (gst_tag_list_get_tag_size (tags, GST_TAG_AUDIO_CODEC) == 1);
958   fail_unless (gst_tag_list_get_tag_size (tags, GST_TAG_BITRATE) == 1);
959   fail_unless (gst_tag_list_get_tag_size (tags, GST_TAG_MAXIMUM_BITRATE) == 1);
960   /* upstream description should've been maintained */
961   fail_unless (gst_tag_list_get_tag_size (tags, GST_TAG_DESCRIPTION) == 1);
962   /* and that should be all: AUDIO_CODEC, DESCRIPTION, BITRATE, MAX BITRATE */
963   fail_unless_equals_int (gst_tag_list_n_tags (tags), 4);
964   gst_tag_list_unref (tags);
965   s = NULL;
966 
967   /* =============================================================
968    * SCENARIO 2: decoder updates tags, upstream tags stay the same
969    * ============================================================= */
970 
971   /* new decoder tags: override AUDIO_CODEC, update/add BITRATE,
972    * no MAXIMUM_BITRATE this time (which means it should not appear
973    * any longer in the output tags now) (bitrate is a different value now) */
974   {
975     GstTagList *decoder_tags;
976 
977     decoder_tags = gst_tag_list_new (GST_TAG_AUDIO_CODEC, "Decoder Codec",
978         GST_TAG_BITRATE, 275000, NULL);
979     gst_audio_decoder_merge_tags (GST_AUDIO_DECODER (h->element),
980         decoder_tags, GST_TAG_MERGE_REPLACE);
981     gst_tag_list_unref (decoder_tags);
982   }
983 
984   /* push another buffer to make decoder update tags */
985   fail_unless (gst_harness_push (h, create_test_buffer (2)) == GST_FLOW_OK);
986   gst_buffer_unref (gst_harness_pull (h));
987 
988   /* check updated merged stream tags, the decoder bits should be different */
989   tags = pad_get_sticky_tags (h->sinkpad, GST_TAG_SCOPE_STREAM);
990   fail_unless (tags != NULL);
991   GST_INFO ("stream tags: %" GST_PTR_FORMAT, tags);
992   /* upstream audio codec still replaced by the subclass's (wasn't updated) */
993   fail_unless (tag_list_peek_string (tags, GST_TAG_AUDIO_CODEC, &s));
994   fail_unless_equals_string (s, "Decoder Codec");
995   /* no upstream bitrate, so audiodecoder one should've been added, was updated */
996   fail_unless (gst_tag_list_get_uint (tags, GST_TAG_BITRATE, &u));
997   fail_unless_equals_int (u, 275000);
998   /* no upstream maximum-bitrate, and audiodecoder removed it now */
999   fail_unless (!gst_tag_list_get_uint (tags, GST_TAG_MAXIMUM_BITRATE, &u));
1000   fail_unless (gst_tag_list_get_tag_size (tags, GST_TAG_AUDIO_CODEC) == 1);
1001   fail_unless (gst_tag_list_get_tag_size (tags, GST_TAG_BITRATE) == 1);
1002   /* upstream description should've been maintained */
1003   fail_unless (gst_tag_list_get_tag_size (tags, GST_TAG_DESCRIPTION) == 1);
1004   /* and that should be all, just AUDIO_CODEC, DESCRIPTION, BITRATE */
1005   fail_unless_equals_int (gst_tag_list_n_tags (tags), 3);
1006   gst_tag_list_unref (tags);
1007   s = NULL;
1008 
1009   /* =================================================================
1010    * SCENARIO 3: stream-start event should clear upstream tags
1011    * ================================================================= */
1012 
1013   /* also tests if the stream-start event clears the upstream tags */
1014   fail_unless (gst_harness_push_event (h, gst_event_new_stream_start ("x")));
1015 
1016   /* push another buffer to make decoder update tags */
1017   fail_unless (gst_harness_push (h, create_test_buffer (3)) == GST_FLOW_OK);
1018   gst_buffer_unref (gst_harness_pull (h));
1019 
1020   /* check updated merged stream tags, should be just decoder tags now */
1021   tags = pad_get_sticky_tags (h->sinkpad, GST_TAG_SCOPE_STREAM);
1022   fail_unless (tags != NULL);
1023   GST_INFO ("stream tags: %" GST_PTR_FORMAT, tags);
1024   fail_unless (tag_list_peek_string (tags, GST_TAG_AUDIO_CODEC, &s));
1025   fail_unless_equals_string (s, "Decoder Codec");
1026   fail_unless (gst_tag_list_get_uint (tags, GST_TAG_BITRATE, &u));
1027   fail_unless_equals_int (u, 275000);
1028   /* no upstream maximum-bitrate, and audiodecoder removed it now */
1029   fail_unless (!gst_tag_list_get_uint (tags, GST_TAG_MAXIMUM_BITRATE, &u));
1030   fail_unless (gst_tag_list_get_tag_size (tags, GST_TAG_AUDIO_CODEC) == 1);
1031   fail_unless (gst_tag_list_get_tag_size (tags, GST_TAG_BITRATE) == 1);
1032   /* no more description tag since no more upstream tags */
1033   fail_unless (gst_tag_list_get_tag_size (tags, GST_TAG_DESCRIPTION) == 0);
1034   /* and that should be all, just AUDIO_CODEC, BITRATE */
1035   fail_unless_equals_int (gst_tag_list_n_tags (tags), 2);
1036   gst_tag_list_unref (tags);
1037   s = NULL;
1038 
1039   /* clean up */
1040   fail_unless (gst_harness_push_event (h, gst_event_new_eos ()));
1041   fail_unless_equals_int (0, gst_harness_buffers_in_queue (h));
1042 
1043   gst_tag_list_unref (global_tags);
1044   gst_harness_teardown (h);
1045 }
1046 
1047 GST_END_TEST;
1048 
GST_START_TEST(audiodecoder_plc_on_gap_event)1049 GST_START_TEST (audiodecoder_plc_on_gap_event)
1050 {
1051   /* GstAudioDecoder should not mark the stream DISCOUNT flag when
1052      concealed audio eliminate discontinuity. More important it should not
1053      mess with the timestamps */
1054 
1055   GstClockTime pts;
1056   GstClockTime dur =
1057       gst_util_uint64_scale_round (1, GST_SECOND, TEST_MSECS_PER_SAMPLE);
1058   GstBuffer *buf;
1059   GstHarness *h = setup_audiodecodertester (NULL, NULL);
1060   gst_audio_decoder_set_plc_aware (GST_AUDIO_DECODER (h->element), TRUE);
1061   gst_audio_decoder_set_plc (GST_AUDIO_DECODER (h->element), TRUE);
1062 
1063   pts = gst_util_uint64_scale_round (0, GST_SECOND, TEST_MSECS_PER_SAMPLE);
1064   gst_harness_push (h, create_test_buffer (0));
1065   buf = gst_harness_pull (h);
1066   fail_unless_equals_int (pts, GST_BUFFER_PTS (buf));
1067   fail_unless_equals_int (dur, GST_BUFFER_DURATION (buf));
1068   fail_unless (GST_BUFFER_FLAG_IS_SET (buf, GST_BUFFER_FLAG_DISCONT));
1069   gst_buffer_unref (buf);
1070 
1071   pts = gst_util_uint64_scale_round (1, GST_SECOND, TEST_MSECS_PER_SAMPLE);
1072   gst_harness_push_event (h, gst_event_new_gap (pts, dur));
1073   buf = gst_harness_pull (h);
1074   fail_unless_equals_int (pts, GST_BUFFER_PTS (buf));
1075   fail_unless_equals_int (dur, GST_BUFFER_DURATION (buf));
1076   fail_unless (!GST_BUFFER_FLAG_IS_SET (buf, GST_BUFFER_FLAG_DISCONT));
1077   gst_buffer_unref (buf);
1078 
1079   pts = gst_util_uint64_scale_round (2, GST_SECOND, TEST_MSECS_PER_SAMPLE);
1080   buf = create_test_buffer (2);
1081   GST_BUFFER_FLAG_SET (buf, GST_BUFFER_FLAG_DISCONT);
1082   gst_harness_push (h, buf);
1083   buf = gst_harness_pull (h);
1084   fail_unless_equals_int (pts, GST_BUFFER_PTS (buf));
1085   fail_unless_equals_int (dur, GST_BUFFER_DURATION (buf));
1086   fail_unless (!GST_BUFFER_FLAG_IS_SET (buf, GST_BUFFER_FLAG_DISCONT));
1087   gst_buffer_unref (buf);
1088   gst_harness_teardown (h);
1089 }
1090 
1091 GST_END_TEST;
1092 
GST_START_TEST(audiodecoder_plc_on_gap_event_with_delay)1093 GST_START_TEST (audiodecoder_plc_on_gap_event_with_delay)
1094 {
1095   /* The same thing as in audiodecoder_plc_on_gap_event, but GstAudioDecoder
1096      subclass delays the decoding
1097    */
1098   GstClockTime pts0, pts1;
1099   GstClockTime dur =
1100       gst_util_uint64_scale_round (1, GST_SECOND, TEST_MSECS_PER_SAMPLE);
1101   GstBuffer *buf;
1102   GstHarness *h = setup_audiodecodertester (NULL, NULL);
1103   gst_audio_decoder_set_plc_aware (GST_AUDIO_DECODER (h->element), TRUE);
1104   gst_audio_decoder_set_plc (GST_AUDIO_DECODER (h->element), TRUE);
1105 
1106   pts0 = gst_util_uint64_scale_round (0, GST_SECOND, TEST_MSECS_PER_SAMPLE);;
1107   gst_harness_push (h, create_test_buffer (0));
1108   buf = gst_harness_pull (h);
1109   fail_unless_equals_int (pts0, GST_BUFFER_PTS (buf));
1110   fail_unless_equals_int (dur, GST_BUFFER_DURATION (buf));
1111   fail_unless (GST_BUFFER_FLAG_IS_SET (buf, GST_BUFFER_FLAG_DISCONT));
1112   gst_buffer_unref (buf);
1113 
1114   ((GstAudioDecoderTester *) h->element)->delay_decoding = TRUE;
1115   pts0 = gst_util_uint64_scale_round (1, GST_SECOND, TEST_MSECS_PER_SAMPLE);
1116   gst_harness_push_event (h, gst_event_new_gap (pts0, dur));
1117   fail_unless_equals_int (0, gst_harness_buffers_in_queue (h));
1118 
1119   pts1 = gst_util_uint64_scale_round (2, GST_SECOND, TEST_MSECS_PER_SAMPLE);
1120   buf = create_test_buffer (2);
1121   GST_BUFFER_FLAG_SET (buf, GST_BUFFER_FLAG_DISCONT);
1122   gst_harness_push (h, buf);
1123   buf = gst_harness_pull (h);
1124   fail_unless_equals_int (pts0, GST_BUFFER_PTS (buf));
1125   fail_unless_equals_int (dur, GST_BUFFER_DURATION (buf));
1126   fail_unless (!GST_BUFFER_FLAG_IS_SET (buf, GST_BUFFER_FLAG_DISCONT));
1127   gst_buffer_unref (buf);
1128 
1129   buf = gst_harness_pull (h);
1130   fail_unless_equals_int (pts1, GST_BUFFER_PTS (buf));
1131   fail_unless_equals_int (dur, GST_BUFFER_DURATION (buf));
1132   fail_unless (!GST_BUFFER_FLAG_IS_SET (buf, GST_BUFFER_FLAG_DISCONT));
1133   gst_buffer_unref (buf);
1134   gst_harness_teardown (h);
1135 }
1136 
1137 GST_END_TEST;
1138 
1139 static Suite *
gst_audiodecoder_suite(void)1140 gst_audiodecoder_suite (void)
1141 {
1142   Suite *s = suite_create ("GstAudioDecoder");
1143   TCase *tc = tcase_create ("general");
1144 
1145   suite_add_tcase (s, tc);
1146   tcase_add_test (tc, audiodecoder_playback);
1147   tcase_add_test (tc, audiodecoder_negotiation_with_buffer);
1148 
1149   tcase_add_test (tc, audiodecoder_negotiation_with_gap_event);
1150   tcase_add_test (tc, audiodecoder_delayed_negotiation_with_gap_event);
1151   tcase_add_test (tc, audiodecoder_first_data_is_gap);
1152 
1153   tcase_add_test (tc, audiodecoder_flush_events_no_buffers);
1154   tcase_add_test (tc, audiodecoder_flush_events);
1155 
1156   tcase_add_test (tc, audiodecoder_eos_events_no_buffers);
1157   tcase_add_test (tc, audiodecoder_buffer_after_segment);
1158   tcase_add_test (tc, audiodecoder_output_too_many_frames);
1159 
1160   tcase_add_test (tc, audiodecoder_query_caps_with_fixed_caps_peer);
1161   tcase_add_test (tc, audiodecoder_query_caps_with_range_caps_peer);
1162   tcase_add_test (tc, audiodecoder_query_caps_with_custom_getcaps);
1163 
1164   tcase_add_test (tc, audiodecoder_tag_handling);
1165 
1166   tcase_add_test (tc, audiodecoder_plc_on_gap_event);
1167   tcase_add_test (tc, audiodecoder_plc_on_gap_event_with_delay);
1168 
1169   return s;
1170 }
1171 
1172 GST_CHECK_MAIN (gst_audiodecoder);
1173