2008-01-23 10:11:44 +00:00
|
|
|
/* GStreamer
|
|
|
|
*
|
|
|
|
* Copyright (C) 2008 Sebastian Dröge <slomo@circular-chaos.org>
|
|
|
|
*
|
|
|
|
* xingmux.c: Unit test for the xingmux element
|
|
|
|
*
|
|
|
|
* This library is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU Lesser General Public License
|
|
|
|
* as published by the Free Software Foundation; either version 2.1 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
|
|
|
|
* Lesser General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU Lesser General Public
|
|
|
|
* License along with this library; if not, write to the Free Software
|
|
|
|
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
|
|
|
|
* 02110-1301 USA
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <gst/gst.h>
|
|
|
|
#include <gst/base/gstbasetransform.h>
|
|
|
|
#include <gst/check/gstcheck.h>
|
|
|
|
|
|
|
|
#include <math.h>
|
|
|
|
|
|
|
|
#include "xingmux_testdata.h"
|
|
|
|
|
|
|
|
/* For ease of programming we use globals to keep refs for our floating
|
|
|
|
* src and sink pads we create; otherwise we always have to do get_pad,
|
|
|
|
* get_peer, and then remove references in every test function */
|
|
|
|
GstPad *mysrcpad, *mysinkpad;
|
|
|
|
|
|
|
|
static GstStaticPadTemplate sinktemplate = GST_STATIC_PAD_TEMPLATE ("sink",
|
|
|
|
GST_PAD_SINK,
|
|
|
|
GST_PAD_ALWAYS,
|
|
|
|
GST_STATIC_CAPS ("audio/mpeg, " "mpegversion = (int) 1," "layer = (int) 3")
|
|
|
|
);
|
|
|
|
static GstStaticPadTemplate srctemplate = GST_STATIC_PAD_TEMPLATE ("src",
|
|
|
|
GST_PAD_SRC,
|
|
|
|
GST_PAD_ALWAYS,
|
|
|
|
GST_STATIC_CAPS ("audio/mpeg, " "mpegversion = (int) 1," "layer = (int) 3")
|
|
|
|
);
|
|
|
|
|
|
|
|
GstElement *
|
|
|
|
setup_xingmux ()
|
|
|
|
{
|
|
|
|
GstElement *xingmux;
|
|
|
|
|
|
|
|
GST_DEBUG ("setup_xingmux");
|
|
|
|
xingmux = gst_check_setup_element ("xingmux");
|
2011-11-24 20:41:55 +00:00
|
|
|
mysrcpad = gst_check_setup_src_pad (xingmux, &srctemplate);
|
|
|
|
mysinkpad = gst_check_setup_sink_pad (xingmux, &sinktemplate);
|
2008-01-23 10:11:44 +00:00
|
|
|
gst_pad_set_active (mysrcpad, TRUE);
|
|
|
|
gst_pad_set_active (mysinkpad, TRUE);
|
|
|
|
|
|
|
|
return xingmux;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
cleanup_xingmux (GstElement * xingmux)
|
|
|
|
{
|
|
|
|
GST_DEBUG ("cleanup_xingmux");
|
|
|
|
|
|
|
|
g_list_foreach (buffers, (GFunc) gst_mini_object_unref, NULL);
|
|
|
|
g_list_free (buffers);
|
|
|
|
buffers = NULL;
|
|
|
|
|
|
|
|
gst_pad_set_active (mysrcpad, FALSE);
|
|
|
|
gst_pad_set_active (mysinkpad, FALSE);
|
|
|
|
gst_check_teardown_src_pad (xingmux);
|
|
|
|
gst_check_teardown_sink_pad (xingmux);
|
|
|
|
gst_check_teardown_element (xingmux);
|
|
|
|
}
|
|
|
|
|
|
|
|
GST_START_TEST (test_xing_remux)
|
|
|
|
{
|
|
|
|
GstElement *xingmux;
|
|
|
|
GstBuffer *inbuffer;
|
|
|
|
GList *it;
|
2008-01-23 10:34:40 +00:00
|
|
|
const guint8 *verify_data;
|
2008-01-23 10:11:44 +00:00
|
|
|
|
|
|
|
xingmux = setup_xingmux ();
|
|
|
|
|
2008-01-23 10:34:40 +00:00
|
|
|
fail_unless (gst_element_set_state (xingmux,
|
|
|
|
GST_STATE_PLAYING) == GST_STATE_CHANGE_SUCCESS,
|
|
|
|
"could not set to playing");
|
|
|
|
|
2008-01-23 10:11:44 +00:00
|
|
|
inbuffer = gst_buffer_new_and_alloc (sizeof (test_xing));
|
2012-01-04 09:33:27 +00:00
|
|
|
gst_buffer_fill (inbuffer, 0, test_xing, sizeof (test_xing));
|
2008-01-23 10:11:44 +00:00
|
|
|
|
|
|
|
ASSERT_BUFFER_REFCOUNT (inbuffer, "inbuffer", 1);
|
|
|
|
|
|
|
|
/* pushing gives away my reference ... */
|
|
|
|
fail_unless (gst_pad_push (mysrcpad, inbuffer) == GST_FLOW_OK);
|
|
|
|
fail_unless (gst_pad_push_event (mysrcpad, gst_event_new_eos ()));
|
|
|
|
/* ... and puts a new buffer on the global list */
|
|
|
|
fail_unless_equals_int (g_list_length (buffers), 93);
|
|
|
|
|
|
|
|
verify_data = test_xing;
|
|
|
|
for (it = buffers; it != NULL; it = it->next) {
|
|
|
|
GstBuffer *outbuffer = (GstBuffer *) it->data;
|
2012-01-04 09:33:27 +00:00
|
|
|
gsize size;
|
|
|
|
guint8 *data;
|
|
|
|
|
|
|
|
data = gst_buffer_map (outbuffer, &size, NULL, GST_MAP_READ);
|
2008-01-23 10:11:44 +00:00
|
|
|
|
|
|
|
if (it == buffers) {
|
|
|
|
gint j;
|
|
|
|
|
|
|
|
/* Empty Xing header, should be the same as input data until the "Xing" marker
|
|
|
|
* and zeroes afterwards. */
|
2012-01-04 09:33:27 +00:00
|
|
|
fail_unless (memcmp (data, test_xing, 25) == 0);
|
|
|
|
for (j = 26; j < size; j++)
|
|
|
|
fail_unless (data[j] == 0);
|
|
|
|
verify_data += size;
|
2008-01-23 10:11:44 +00:00
|
|
|
} else if (it->next != NULL) {
|
|
|
|
/* Should contain the raw MP3 data without changes */
|
2012-01-04 09:33:27 +00:00
|
|
|
fail_unless (memcmp (data, verify_data, size) == 0);
|
|
|
|
verify_data += size;
|
2008-01-23 10:11:44 +00:00
|
|
|
} else {
|
|
|
|
/* Last buffer is the rewrite of the first buffer and should be exactly the same
|
|
|
|
* as the old Xing header we had */
|
2012-01-04 09:33:27 +00:00
|
|
|
fail_unless (memcmp (test_xing, data, size) == 0);
|
2008-01-23 10:11:44 +00:00
|
|
|
}
|
2012-01-04 09:33:27 +00:00
|
|
|
gst_buffer_unmap (outbuffer, data, size);
|
2008-01-23 10:11:44 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* cleanup */
|
|
|
|
cleanup_xingmux (xingmux);
|
|
|
|
}
|
|
|
|
|
|
|
|
GST_END_TEST;
|
|
|
|
|
|
|
|
Suite *
|
|
|
|
xingmux_suite (void)
|
|
|
|
{
|
|
|
|
Suite *s = suite_create ("xingmux");
|
|
|
|
TCase *tc_chain = tcase_create ("general");
|
|
|
|
|
|
|
|
suite_add_tcase (s, tc_chain);
|
|
|
|
tcase_add_test (tc_chain, test_xing_remux);
|
|
|
|
|
|
|
|
return s;
|
|
|
|
}
|
|
|
|
|
|
|
|
int
|
|
|
|
main (int argc, char **argv)
|
|
|
|
{
|
|
|
|
int nf;
|
|
|
|
|
|
|
|
Suite *s = xingmux_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;
|
|
|
|
}
|