2009-03-03 09:14:02 +00:00
|
|
|
/* GStreamer
|
|
|
|
* Copyright (C) 2009 Thomas Vander Stichele <thomas at apestaart dot org>
|
|
|
|
*
|
|
|
|
* 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/check/gstcheck.h>
|
2012-01-03 13:16:28 +00:00
|
|
|
#include <gst/audio/audio.h>
|
2009-05-15 16:11:27 +00:00
|
|
|
#include <glib/gstdio.h>
|
2009-03-03 09:14:02 +00:00
|
|
|
|
2009-05-13 08:24:26 +00:00
|
|
|
static guint16
|
2012-01-03 13:16:28 +00:00
|
|
|
_get_first_sample (GstSample * sample)
|
2009-05-13 08:24:26 +00:00
|
|
|
{
|
2012-01-03 13:16:28 +00:00
|
|
|
GstAudioInfo info;
|
|
|
|
GstCaps *caps;
|
|
|
|
GstBuffer *buf;
|
|
|
|
guint8 *data;
|
|
|
|
gsize size;
|
|
|
|
guint16 res;
|
2009-05-13 08:24:26 +00:00
|
|
|
|
2012-01-03 13:16:28 +00:00
|
|
|
fail_unless (sample != NULL, "NULL sample");
|
2009-05-13 08:24:26 +00:00
|
|
|
|
2012-01-03 13:16:28 +00:00
|
|
|
caps = gst_sample_get_caps (sample);
|
|
|
|
fail_unless (caps != NULL, "sample without caps");
|
|
|
|
|
|
|
|
buf = gst_sample_get_buffer (sample);
|
2009-05-13 08:24:26 +00:00
|
|
|
GST_DEBUG ("buffer with size=%u, caps=%" GST_PTR_FORMAT,
|
2012-01-03 13:16:28 +00:00
|
|
|
gst_buffer_get_size (buf), caps);
|
|
|
|
|
|
|
|
data = gst_buffer_map (buf, &size, NULL, GST_MAP_READ);
|
|
|
|
/* log buffer details */
|
|
|
|
GST_MEMDUMP ("buffer data from decoder", data, size);
|
2009-05-13 08:24:26 +00:00
|
|
|
|
|
|
|
/* make sure it's the format we expect */
|
2012-01-03 13:16:28 +00:00
|
|
|
fail_unless (gst_audio_info_from_caps (&info, caps));
|
|
|
|
|
|
|
|
fail_unless_equals_int (GST_AUDIO_INFO_WIDTH (&info), 16);
|
|
|
|
fail_unless_equals_int (GST_AUDIO_INFO_DEPTH (&info), 16);
|
|
|
|
fail_unless_equals_int (GST_AUDIO_INFO_RATE (&info), 44100);
|
|
|
|
fail_unless_equals_int (GST_AUDIO_INFO_CHANNELS (&info), 1);
|
|
|
|
|
|
|
|
if (GST_AUDIO_INFO_IS_LITTLE_ENDIAN (&info))
|
|
|
|
res = GST_READ_UINT16_LE (data);
|
2009-05-13 08:24:26 +00:00
|
|
|
else
|
2012-01-03 13:16:28 +00:00
|
|
|
res = GST_READ_UINT16_BE (data);
|
|
|
|
|
|
|
|
gst_buffer_unmap (buf, data, size);
|
|
|
|
|
|
|
|
return res;
|
2009-05-13 08:24:26 +00:00
|
|
|
}
|
|
|
|
|
2009-03-03 09:14:02 +00:00
|
|
|
GST_START_TEST (test_decode)
|
|
|
|
{
|
|
|
|
GstElement *pipeline;
|
|
|
|
GstElement *appsink;
|
2012-01-03 13:16:28 +00:00
|
|
|
GstSample *sample = NULL;
|
2009-05-13 08:24:26 +00:00
|
|
|
guint16 first_sample = 0;
|
2009-03-03 09:14:02 +00:00
|
|
|
guint size = 0;
|
2009-05-16 01:37:06 +00:00
|
|
|
gchar *path =
|
|
|
|
g_build_filename (GST_TEST_FILES_PATH, "audiotestsrc.flac", NULL);
|
|
|
|
gchar *pipe_desc =
|
|
|
|
g_strdup_printf ("filesrc location=\"%s\" ! flacdec ! appsink name=sink",
|
|
|
|
path);
|
2009-03-03 09:14:02 +00:00
|
|
|
|
2009-05-16 01:37:06 +00:00
|
|
|
pipeline = gst_parse_launch (pipe_desc, NULL);
|
2009-03-03 09:14:02 +00:00
|
|
|
fail_unless (pipeline != NULL);
|
|
|
|
|
2009-05-16 01:37:06 +00:00
|
|
|
g_free (path);
|
|
|
|
g_free (pipe_desc);
|
|
|
|
|
2009-03-03 09:14:02 +00:00
|
|
|
appsink = gst_bin_get_by_name (GST_BIN (pipeline), "sink");
|
|
|
|
fail_unless (appsink != NULL);
|
|
|
|
|
|
|
|
gst_element_set_state (pipeline, GST_STATE_PLAYING);
|
|
|
|
|
|
|
|
do {
|
2012-01-03 13:16:28 +00:00
|
|
|
g_signal_emit_by_name (appsink, "pull-sample", &sample);
|
|
|
|
if (sample == NULL)
|
2009-03-03 09:14:02 +00:00
|
|
|
break;
|
2009-05-13 08:24:26 +00:00
|
|
|
if (first_sample == 0)
|
2012-01-03 13:16:28 +00:00
|
|
|
first_sample = _get_first_sample (sample);
|
|
|
|
|
|
|
|
size += gst_buffer_get_size (gst_sample_get_buffer (sample));
|
2009-05-13 08:24:26 +00:00
|
|
|
|
2012-01-03 13:16:28 +00:00
|
|
|
gst_sample_unref (sample);
|
|
|
|
sample = NULL;
|
2009-03-03 09:14:02 +00:00
|
|
|
}
|
|
|
|
while (TRUE);
|
|
|
|
|
|
|
|
/* audiotestsrc with samplesperbuffer 1024 and 10 num-buffers */
|
|
|
|
fail_unless_equals_int (size, 20480);
|
2009-05-13 08:24:26 +00:00
|
|
|
fail_unless_equals_int (first_sample, 0x066a);
|
2009-03-03 09:14:02 +00:00
|
|
|
|
|
|
|
gst_element_set_state (pipeline, GST_STATE_NULL);
|
|
|
|
g_object_unref (pipeline);
|
2009-05-13 08:24:26 +00:00
|
|
|
g_object_unref (appsink);
|
2009-03-03 09:14:02 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
GST_END_TEST;
|
|
|
|
|
|
|
|
GST_START_TEST (test_decode_seek_full)
|
|
|
|
{
|
|
|
|
GstElement *pipeline;
|
|
|
|
GstElement *appsink;
|
|
|
|
GstEvent *event;
|
2012-01-03 13:16:28 +00:00
|
|
|
GstSample *sample = NULL;
|
2009-05-13 08:24:26 +00:00
|
|
|
guint16 first_sample = 0;
|
2009-03-03 09:14:02 +00:00
|
|
|
guint size = 0;
|
2009-05-16 01:37:06 +00:00
|
|
|
gchar *path =
|
|
|
|
g_build_filename (GST_TEST_FILES_PATH, "audiotestsrc.flac", NULL);
|
|
|
|
gchar *pipe_desc =
|
|
|
|
g_strdup_printf ("filesrc location=\"%s\" ! flacdec ! appsink name=sink",
|
|
|
|
path);
|
2009-03-03 09:14:02 +00:00
|
|
|
|
2009-05-16 01:37:06 +00:00
|
|
|
pipeline = gst_parse_launch (pipe_desc, NULL);
|
2009-03-03 09:14:02 +00:00
|
|
|
fail_unless (pipeline != NULL);
|
|
|
|
|
2009-05-16 01:37:06 +00:00
|
|
|
g_free (pipe_desc);
|
|
|
|
g_free (path);
|
|
|
|
|
2009-03-03 09:14:02 +00:00
|
|
|
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);
|
2011-04-15 13:11:35 +00:00
|
|
|
fail_unless (gst_element_send_event (appsink, event));
|
2009-03-03 09:14:02 +00:00
|
|
|
|
|
|
|
gst_element_set_state (pipeline, GST_STATE_PLAYING);
|
|
|
|
|
|
|
|
do {
|
2012-01-03 13:16:28 +00:00
|
|
|
g_signal_emit_by_name (appsink, "pull-sample", &sample);
|
|
|
|
if (sample == NULL)
|
2009-03-03 09:14:02 +00:00
|
|
|
break;
|
2009-05-13 08:24:26 +00:00
|
|
|
if (first_sample == 0)
|
2012-01-03 13:16:28 +00:00
|
|
|
first_sample = _get_first_sample (sample);
|
|
|
|
size += gst_buffer_get_size (gst_sample_get_buffer (sample));
|
2009-05-13 08:24:26 +00:00
|
|
|
|
2012-01-03 13:16:28 +00:00
|
|
|
gst_sample_unref (sample);
|
|
|
|
sample = NULL;
|
2009-03-03 09:14:02 +00:00
|
|
|
}
|
|
|
|
while (TRUE);
|
|
|
|
|
|
|
|
/* file was generated with audiotestsrc
|
|
|
|
* with 1024 samplesperbuffer and 10 num-buffers in 16 bit audio */
|
|
|
|
fail_unless_equals_int (size, 20480);
|
2009-05-13 08:24:26 +00:00
|
|
|
fail_unless_equals_int (first_sample, 0x066a);
|
2009-03-03 09:14:02 +00:00
|
|
|
|
|
|
|
gst_element_set_state (pipeline, GST_STATE_NULL);
|
|
|
|
|
|
|
|
g_object_unref (pipeline);
|
2009-05-13 08:24:26 +00:00
|
|
|
g_object_unref (appsink);
|
2009-03-03 09:14:02 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
GST_END_TEST;
|
|
|
|
|
|
|
|
GST_START_TEST (test_decode_seek_partial)
|
|
|
|
{
|
|
|
|
GstElement *pipeline;
|
|
|
|
GstElement *appsink;
|
|
|
|
GstEvent *event;
|
2012-01-03 13:16:28 +00:00
|
|
|
GstSample *sample = NULL;
|
2009-03-03 09:14:02 +00:00
|
|
|
guint size = 0;
|
2009-05-13 08:24:26 +00:00
|
|
|
guint16 first_sample = 0;
|
2009-05-16 01:37:06 +00:00
|
|
|
gchar *path =
|
|
|
|
g_build_filename (GST_TEST_FILES_PATH, "audiotestsrc.flac", NULL);
|
|
|
|
gchar *pipe_desc =
|
|
|
|
g_strdup_printf ("filesrc location=\"%s\" ! flacdec ! appsink name=sink",
|
|
|
|
path);
|
2009-03-03 09:14:02 +00:00
|
|
|
|
2009-05-16 01:37:06 +00:00
|
|
|
pipeline = gst_parse_launch (pipe_desc, NULL);
|
2009-03-03 09:14:02 +00:00
|
|
|
fail_unless (pipeline != NULL);
|
|
|
|
|
2009-05-16 01:37:06 +00:00
|
|
|
g_free (path);
|
|
|
|
g_free (pipe_desc);
|
|
|
|
|
2009-03-03 09:14:02 +00:00
|
|
|
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);
|
2009-03-15 20:31:49 +00:00
|
|
|
GST_DEBUG ("seeking");
|
2011-04-15 13:11:35 +00:00
|
|
|
fail_unless (gst_element_send_event (appsink, event));
|
2009-03-15 20:31:49 +00:00
|
|
|
GST_DEBUG ("seeked");
|
2009-03-03 09:14:02 +00:00
|
|
|
|
|
|
|
gst_element_set_state (pipeline, GST_STATE_PLAYING);
|
|
|
|
|
|
|
|
do {
|
2012-01-03 13:16:28 +00:00
|
|
|
GST_DEBUG ("pulling sample");
|
|
|
|
g_signal_emit_by_name (appsink, "pull-sample", &sample);
|
|
|
|
GST_DEBUG ("pulled sample %p", sample);
|
|
|
|
if (sample == NULL)
|
2009-03-03 09:14:02 +00:00
|
|
|
break;
|
2009-05-13 08:24:26 +00:00
|
|
|
if (first_sample == 0) {
|
2012-01-03 13:16:28 +00:00
|
|
|
// fail_unless_equals_int (GST_BUFFER_OFFSET (buffer), 0L);
|
|
|
|
first_sample = _get_first_sample (sample);
|
2009-03-15 20:31:49 +00:00
|
|
|
}
|
2012-01-03 13:16:28 +00:00
|
|
|
size += gst_buffer_get_size (gst_sample_get_buffer (sample));
|
2009-05-13 08:24:26 +00:00
|
|
|
|
2012-01-03 13:16:28 +00:00
|
|
|
gst_sample_unref (sample);
|
|
|
|
sample = NULL;
|
2009-03-03 09:14:02 +00:00
|
|
|
}
|
|
|
|
while (TRUE);
|
|
|
|
|
|
|
|
fail_unless_equals_int (size, 2048);
|
2009-05-13 08:24:26 +00:00
|
|
|
fail_unless_equals_int (first_sample, 0x066a);
|
2009-03-03 09:14:02 +00:00
|
|
|
|
|
|
|
gst_element_set_state (pipeline, GST_STATE_NULL);
|
|
|
|
|
|
|
|
g_object_unref (pipeline);
|
2009-05-13 08:24:26 +00:00
|
|
|
g_object_unref (appsink);
|
2009-03-03 09:14:02 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
GST_END_TEST;
|
|
|
|
|
|
|
|
|
2009-05-15 16:11:27 +00:00
|
|
|
static Suite *
|
2009-03-03 09:14:02 +00:00
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
2009-05-15 16:11:27 +00:00
|
|
|
GST_CHECK_MAIN (flacdec);
|