From be94a147ba68d48a519e3653a3063c233186f2a8 Mon Sep 17 00:00:00 2001 From: Thomas Vander Stichele Date: Tue, 3 Mar 2009 10:14:02 +0100 Subject: [PATCH] add a test to check that we get all decoded bytes from a 10-buffer audiotestsrc flac, in the case of: - a full decode - a decode of a seek for the full file - a decode of a seek for a small part, smaller than the first buffer The test fails because flacdec drops the first outgoing buffer on a seek --- tests/check/Makefile.am | 3 +- tests/check/audiotestsrc.flac | Bin 0 -> 4708 bytes tests/check/pipelines/flacdec.c | 204 ++++++++++++++++++++++++++++++++ 3 files changed, 206 insertions(+), 1 deletion(-) create mode 100644 tests/check/audiotestsrc.flac create mode 100644 tests/check/pipelines/flacdec.c diff --git a/tests/check/Makefile.am b/tests/check/Makefile.am index 418c28d297..87cf69de31 100644 --- a/tests/check/Makefile.am +++ b/tests/check/Makefile.am @@ -13,7 +13,7 @@ TESTS_ENVIRONMENT = \ GST_TEST_FILES_PATH=$(TEST_FILES_DIRECTORY) \ STATE_IGNORE_ELEMENTS="aasink autoaudiosrc autoaudiosink autovideosrc autovideosink cacasink cairotextoverlay gconfaudiosrc gconfvideosrc gconfaudiosink gconfvideosink halaudiosrc halaudiosink v4l2src osssrc osssink pulsesink pulsesrc pulsemixer" -EXTRA_DIST = test-cert.pem test-key.pem +EXTRA_DIST = test-cert.pem test-key.pem audiotestsrc.flac # ths core dumps of some machines have PIDs appended CLEANFILES = core.* test-registry.* @@ -98,6 +98,7 @@ check_PROGRAMS = \ elements/videocrop \ elements/videofilter \ pipelines/simple-launch-lines \ + pipelines/flacdec \ $(check_gdkpixbuf) \ $(check_soup) \ $(check_sunaudio) \ diff --git a/tests/check/audiotestsrc.flac b/tests/check/audiotestsrc.flac new file mode 100644 index 0000000000000000000000000000000000000000..2f12c3f7667d59f82036609e3a80d5ddd0886f9c GIT binary patch literal 4708 zcmds5?Nb})y(L)HEM$AHWMNn_ZbxEaWdRbq3aX8bI|0Fhj0EK+#JpD8Xl-6x6JtV5 zZk(w>RwT407UD%H;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AUHx3}Q68e*H`{dW3e47xG z{tZ=OaFBD3f({EVG-zo!nY3RWizS1EMDl&kr}2b=d2~=wwXn5NrK`Y#Bc;VfcvL#Q zC&>e$U|~84i*w%7_jO!7U^kjXj*lTlk-0&?03Vy6&r*R-m+L<5|kIyAd0l*t)^WP0!YTe57Q z&u;3reFlIfQbgRzi7#e%#-S7(Phjk=K!6{Yo|5a(%W#!UcADgmADW=*l=aRe7!qUy@fp8^V)+cd?va$!*{jl(i+4d;r21z_ zuC@soOUcmStXYudu3=w3Kqr2=jZ*OD>eb(G28}uHuNAVF6@3lV3_>xOnHyLW`P-7o F{{_i+)i(eD literal 0 HcmV?d00001 diff --git a/tests/check/pipelines/flacdec.c b/tests/check/pipelines/flacdec.c new file mode 100644 index 0000000000..fb5d50309f --- /dev/null +++ b/tests/check/pipelines/flacdec.c @@ -0,0 +1,204 @@ +/* GStreamer + * Copyright (C) 2009 Thomas Vander Stichele + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Library General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Library General Public License for more details. + * + * You should have received a copy of the GNU Library General Public + * License along with this library; if not, write to the + * Free Software Foundation, Inc., 59 Temple Place - Suite 330, + * Boston, MA 02111-1307, USA. + */ + +#include + +GST_START_TEST (test_decode) +{ + GstElement *pipeline; + + GstElement *appsink; + + GstBuffer *buffer = NULL; + + guint8 firstbyte = 0; + guint size = 0; + + pipeline = gst_parse_launch ("filesrc location=audiotestsrc.flac" + " ! flacdec ! appsink name=sink", NULL); + fail_unless (pipeline != NULL); + + appsink = gst_bin_get_by_name (GST_BIN (pipeline), "sink"); + fail_unless (appsink != NULL); + + gst_element_set_state (pipeline, GST_STATE_PLAYING); + + do { + g_signal_emit_by_name (appsink, "pull-buffer", &buffer); + if (buffer == NULL) + break; + if (firstbyte == 0) + firstbyte = GST_BUFFER_DATA (buffer)[0]; + g_print ("buffer: %d\n", buffer->size); + g_print ("buffer: %08x\n", GST_BUFFER_DATA (buffer)[0]); + size += buffer->size; + } + while (TRUE); + + /* audiotestsrc with samplesperbuffer 1024 and 10 num-buffers */ + fail_unless_equals_int (size, 20480); + fail_unless_equals_int (firstbyte, 0x6a); + + gst_element_set_state (pipeline, GST_STATE_NULL); + g_object_unref (pipeline); +} + +GST_END_TEST; + +GST_START_TEST (test_decode_seek_full) +{ + GstElement *pipeline; + + GstElement *appsink; + + GstEvent *event; + + GstBuffer *buffer = NULL; + + guint8 firstbyte = 0; + + gboolean result; + guint size = 0; + + pipeline = gst_parse_launch ("filesrc location=audiotestsrc.flac" + " ! flacdec ! appsink name=sink", NULL); + fail_unless (pipeline != NULL); + + appsink = gst_bin_get_by_name (GST_BIN (pipeline), "sink"); + fail_unless (appsink != NULL); + + gst_element_set_state (pipeline, GST_STATE_PAUSED); + gst_element_get_state (pipeline, NULL, NULL, GST_CLOCK_TIME_NONE); + + /* do a seek that should give us the complete output */ + event = gst_event_new_seek (1.0, GST_FORMAT_DEFAULT, GST_SEEK_FLAG_FLUSH, + GST_SEEK_TYPE_SET, 0, GST_SEEK_TYPE_SET, 20480); + result = gst_element_send_event (appsink, event); + + gst_element_set_state (pipeline, GST_STATE_PLAYING); + + do { + g_signal_emit_by_name (appsink, "pull-buffer", &buffer); + if (buffer == NULL) + break; + if (firstbyte == 0) + firstbyte = GST_BUFFER_DATA (buffer)[0]; + size += buffer->size; + } + while (TRUE); + + /* file was generated with audiotestsrc + * with 1024 samplesperbuffer and 10 num-buffers in 16 bit audio */ + fail_unless_equals_int (size, 20480); + fail_unless_equals_int (firstbyte, 0x6a); + + gst_element_set_state (pipeline, GST_STATE_NULL); + + g_object_unref (pipeline); +} + +GST_END_TEST; + +GST_START_TEST (test_decode_seek_partial) +{ + GstElement *pipeline; + + GstElement *appsink; + + GstEvent *event; + + GstBuffer *buffer = NULL; + + gboolean result; + guint size = 0; + guint8 firstbyte = 0; + + pipeline = gst_parse_launch ("filesrc location=audiotestsrc.flac" + " ! flacdec ! appsink name=sink", NULL); + fail_unless (pipeline != NULL); + + appsink = gst_bin_get_by_name (GST_BIN (pipeline), "sink"); + fail_unless (appsink != NULL); + + gst_element_set_state (pipeline, GST_STATE_PAUSED); + gst_element_get_state (pipeline, NULL, NULL, GST_CLOCK_TIME_NONE); + + /* do a partial seek to get the first 1024 samples or 2048 bytes */ + event = gst_event_new_seek (1.0, GST_FORMAT_DEFAULT, GST_SEEK_FLAG_FLUSH, + GST_SEEK_TYPE_SET, 0, GST_SEEK_TYPE_SET, 1024); + result = gst_element_send_event (appsink, event); + + gst_element_set_state (pipeline, GST_STATE_PLAYING); + + do { + g_signal_emit_by_name (appsink, "pull-buffer", &buffer); + if (buffer == NULL) + break; + if (firstbyte == 0) + firstbyte = GST_BUFFER_DATA (buffer)[0]; + size += buffer->size; + } + while (TRUE); + + fail_unless_equals_int (size, 2048); + fail_unless_equals_int (firstbyte, 0x6a); + + gst_element_set_state (pipeline, GST_STATE_NULL); + + g_object_unref (pipeline); +} + +GST_END_TEST; + + +Suite * +flacdec_suite (void) +{ + Suite *s = suite_create ("flacdec"); + + TCase *tc_chain = tcase_create ("linear"); + + /* time out after 60s, not the default 3 */ + tcase_set_timeout (tc_chain, 60); + + suite_add_tcase (s, tc_chain); + tcase_add_test (tc_chain, test_decode); + tcase_add_test (tc_chain, test_decode_seek_full); + tcase_add_test (tc_chain, test_decode_seek_partial); + + return s; +} + +int +main (int argc, char **argv) +{ + int nf; + + Suite *s = flacdec_suite (); + + SRunner *sr = srunner_create (s); + + gst_check_init (&argc, &argv); + + srunner_run_all (sr, CK_NORMAL); + nf = srunner_ntests_failed (sr); + srunner_free (sr); + + return nf; +}