mirror of
https://gitlab.freedesktop.org/gstreamer/gstreamer.git
synced 2024-11-27 12:11:13 +00:00
audioparsers: refactor existing unit tests using common helper
This commit is contained in:
parent
589c455ccb
commit
edb495646d
4 changed files with 714 additions and 832 deletions
|
@ -24,7 +24,7 @@
|
|||
*/
|
||||
|
||||
#include <gst/check/gstcheck.h>
|
||||
#include "aacparse_data.h"
|
||||
#include "parser.h"
|
||||
|
||||
#define SRC_CAPS_CDATA "audio/mpeg, framed=(boolean)false, codec_data=(buffer)1190"
|
||||
#define SRC_CAPS_TMPL "audio/mpeg, framed=(boolean)false, mpegversion=(int){2,4}"
|
||||
|
@ -37,163 +37,36 @@
|
|||
"audio/mpeg, framed=(boolean)true, mpegversion=4, rate=96000, channels=2"
|
||||
#define SINK_CAPS_TMPL "audio/mpeg, framed=(boolean)true, mpegversion=(int){2,4}"
|
||||
|
||||
GList *current_buf = NULL;
|
||||
|
||||
GstPad *srcpad, *sinkpad;
|
||||
guint dataoffset = 0;
|
||||
GstClockTime ts_counter = 0;
|
||||
gint64 offset_counter = 0;
|
||||
guint buffer_counter = 0;
|
||||
|
||||
static GstStaticPadTemplate sinktemplate = GST_STATIC_PAD_TEMPLATE ("sink",
|
||||
GstStaticPadTemplate sinktemplate = GST_STATIC_PAD_TEMPLATE ("sink",
|
||||
GST_PAD_SINK,
|
||||
GST_PAD_ALWAYS,
|
||||
GST_STATIC_CAPS (SINK_CAPS_TMPL)
|
||||
);
|
||||
|
||||
static GstStaticPadTemplate srctemplate = GST_STATIC_PAD_TEMPLATE ("src",
|
||||
GstStaticPadTemplate srctemplate = GST_STATIC_PAD_TEMPLATE ("src",
|
||||
GST_PAD_SRC,
|
||||
GST_PAD_ALWAYS,
|
||||
GST_STATIC_CAPS (SRC_CAPS_TMPL)
|
||||
);
|
||||
|
||||
typedef struct
|
||||
{
|
||||
guint buffers_before_offset_skip;
|
||||
guint offset_skip_amount;
|
||||
const unsigned char *data_to_verify;
|
||||
GstCaps *caps;
|
||||
} buffer_verify_data_s;
|
||||
/* some data */
|
||||
static guint8 adif_header[] = {
|
||||
'A', 'D', 'I', 'F'
|
||||
};
|
||||
|
||||
/* takes a copy of the passed buffer data */
|
||||
static GstBuffer *
|
||||
buffer_new (const unsigned char *buffer_data, guint size)
|
||||
{
|
||||
GstBuffer *buffer;
|
||||
static guint8 adts_frame_mpeg2[] = {
|
||||
0xff, 0xf9, 0x4c, 0x80, 0x01, 0xff, 0xfc, 0x21, 0x10, 0xd3, 0x20, 0x0c,
|
||||
0x32, 0x00, 0xc7
|
||||
};
|
||||
|
||||
buffer = gst_buffer_new_and_alloc (size);
|
||||
if (buffer_data) {
|
||||
memcpy (GST_BUFFER_DATA (buffer), buffer_data, size);
|
||||
} else {
|
||||
guint i;
|
||||
/* Create a recognizable pattern (loop 0x00 -> 0xff) in the data block */
|
||||
for (i = 0; i < size; i++) {
|
||||
GST_BUFFER_DATA (buffer)[i] = i % 0x100;
|
||||
}
|
||||
}
|
||||
|
||||
gst_buffer_set_caps (buffer, GST_PAD_CAPS (srcpad));
|
||||
GST_BUFFER_OFFSET (buffer) = dataoffset;
|
||||
dataoffset += size;
|
||||
return buffer;
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* Count buffer sizes together.
|
||||
*/
|
||||
static void
|
||||
buffer_count_size (void *buffer, void *user_data)
|
||||
{
|
||||
guint *sum = (guint *) user_data;
|
||||
*sum += GST_BUFFER_SIZE (buffer);
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* Verify that given buffer contains predefined ADTS frame.
|
||||
*/
|
||||
static void
|
||||
buffer_verify_adts (void *buffer, void *user_data)
|
||||
{
|
||||
buffer_verify_data_s *vdata;
|
||||
|
||||
if (!user_data) {
|
||||
return;
|
||||
}
|
||||
|
||||
vdata = (buffer_verify_data_s *) user_data;
|
||||
|
||||
fail_unless (memcmp (GST_BUFFER_DATA (buffer), vdata->data_to_verify,
|
||||
ADTS_FRAME_LEN) == 0);
|
||||
|
||||
fail_unless (GST_BUFFER_TIMESTAMP (buffer) == ts_counter);
|
||||
fail_unless (GST_BUFFER_DURATION (buffer) != 0);
|
||||
|
||||
if (vdata->buffers_before_offset_skip) {
|
||||
/* This is for skipping the garbage in some test cases */
|
||||
if (buffer_counter == vdata->buffers_before_offset_skip) {
|
||||
offset_counter += vdata->offset_skip_amount;
|
||||
}
|
||||
}
|
||||
fail_unless (GST_BUFFER_OFFSET (buffer) == offset_counter);
|
||||
|
||||
if (vdata->caps) {
|
||||
gchar *bcaps = gst_caps_to_string (GST_BUFFER_CAPS (buffer));
|
||||
g_free (bcaps);
|
||||
|
||||
GST_LOG ("%" GST_PTR_FORMAT " = %" GST_PTR_FORMAT " ?",
|
||||
GST_BUFFER_CAPS (buffer), vdata->caps);
|
||||
fail_unless (gst_caps_is_equal (GST_BUFFER_CAPS (buffer), vdata->caps));
|
||||
}
|
||||
|
||||
ts_counter += GST_BUFFER_DURATION (buffer);
|
||||
offset_counter += ADTS_FRAME_LEN;
|
||||
buffer_counter++;
|
||||
}
|
||||
|
||||
static GstElement *
|
||||
setup_aacparse (const gchar * src_caps_str)
|
||||
{
|
||||
GstElement *aacparse;
|
||||
GstCaps *srccaps = NULL;
|
||||
GstBus *bus;
|
||||
|
||||
if (src_caps_str) {
|
||||
srccaps = gst_caps_from_string (src_caps_str);
|
||||
fail_unless (srccaps != NULL);
|
||||
}
|
||||
|
||||
aacparse = gst_check_setup_element ("aacparse");
|
||||
srcpad = gst_check_setup_src_pad (aacparse, &srctemplate, srccaps);
|
||||
sinkpad = gst_check_setup_sink_pad (aacparse, &sinktemplate, NULL);
|
||||
gst_pad_set_active (srcpad, TRUE);
|
||||
gst_pad_set_active (sinkpad, TRUE);
|
||||
|
||||
bus = gst_bus_new ();
|
||||
gst_element_set_bus (aacparse, bus);
|
||||
|
||||
fail_unless (gst_element_set_state (aacparse,
|
||||
GST_STATE_PLAYING) != GST_STATE_CHANGE_FAILURE,
|
||||
"could not set to playing");
|
||||
|
||||
if (srccaps) {
|
||||
gst_caps_unref (srccaps);
|
||||
}
|
||||
ts_counter = offset_counter = buffer_counter = 0;
|
||||
buffers = NULL;
|
||||
return aacparse;
|
||||
}
|
||||
|
||||
static void
|
||||
cleanup_aacparse (GstElement * aacparse)
|
||||
{
|
||||
GstBus *bus;
|
||||
|
||||
/* Free parsed buffers */
|
||||
gst_check_drop_buffers ();
|
||||
|
||||
bus = GST_ELEMENT_BUS (aacparse);
|
||||
gst_bus_set_flushing (bus, TRUE);
|
||||
gst_object_unref (bus);
|
||||
|
||||
gst_pad_set_active (srcpad, FALSE);
|
||||
gst_pad_set_active (sinkpad, FALSE);
|
||||
gst_check_teardown_src_pad (aacparse);
|
||||
gst_check_teardown_sink_pad (aacparse);
|
||||
gst_check_teardown_element (aacparse);
|
||||
}
|
||||
static guint8 adts_frame_mpeg4[] = {
|
||||
0xff, 0xf1, 0x4c, 0x80, 0x01, 0xff, 0xfc, 0x21, 0x10, 0xd3, 0x20, 0x0c,
|
||||
0x32, 0x00, 0xc7
|
||||
};
|
||||
|
||||
static guint8 garbage_frame[] = {
|
||||
0xff, 0xff, 0xff, 0xff, 0xff
|
||||
};
|
||||
|
||||
/*
|
||||
* Test if the parser pushes data with ADIF header properly and detects the
|
||||
|
@ -201,194 +74,65 @@ cleanup_aacparse (GstElement * aacparse)
|
|||
*/
|
||||
GST_START_TEST (test_parse_adif_normal)
|
||||
{
|
||||
GstElement *aacparse;
|
||||
GstBuffer *buffer;
|
||||
GstCaps *scaps, *sinkcaps;
|
||||
guint datasum = 0;
|
||||
guint i;
|
||||
|
||||
aacparse = setup_aacparse (NULL);
|
||||
|
||||
buffer = buffer_new (adif_header, ADIF_HEADER_LEN);
|
||||
fail_unless_equals_int (gst_pad_push (srcpad, buffer), GST_FLOW_OK);
|
||||
|
||||
for (i = 0; i < 3; i++) {
|
||||
buffer = buffer_new (NULL, 100);
|
||||
fail_unless_equals_int (gst_pad_push (srcpad, buffer), GST_FLOW_OK);
|
||||
}
|
||||
gst_pad_push_event (srcpad, gst_event_new_eos ());
|
||||
|
||||
/* Calculate the outputted buffer sizes */
|
||||
g_list_foreach (buffers, buffer_count_size, &datasum);
|
||||
|
||||
/* ADIF is not a framed format, and therefore we cannot expect the
|
||||
same amount of output buffers as we pushed. However, all data should
|
||||
still come through, including the header bytes */
|
||||
fail_unless_equals_int (datasum, 3 * 100 + ADIF_HEADER_LEN);
|
||||
GstParserTest ptest;
|
||||
|
||||
/* ADIF header */
|
||||
gst_parser_test_init (&ptest, adif_header, sizeof (adif_header), 1);
|
||||
/* well, no garbage, followed by random data */
|
||||
ptest.series[2].size = 100;
|
||||
ptest.series[2].num = 3;
|
||||
/* and we do not really expect output frames */
|
||||
ptest.framed = FALSE;
|
||||
/* Check that the negotiated caps are as expected */
|
||||
/* For ADIF parser assumes that data is always version 4 */
|
||||
scaps = gst_caps_from_string (SINK_CAPS_MPEG4 ", stream-format=(string)adif");
|
||||
sinkcaps = gst_pad_get_negotiated_caps (sinkpad);
|
||||
ptest.sink_caps =
|
||||
gst_caps_from_string (SINK_CAPS_MPEG4 ", stream-format=(string)adif");
|
||||
|
||||
GST_LOG ("%" GST_PTR_FORMAT " = %" GST_PTR_FORMAT " ?", sinkcaps, scaps);
|
||||
fail_unless (gst_caps_is_equal (sinkcaps, scaps));
|
||||
gst_caps_unref (sinkcaps);
|
||||
gst_caps_unref (scaps);
|
||||
gst_parser_test_run (&ptest, NULL);
|
||||
|
||||
cleanup_aacparse (aacparse);
|
||||
gst_caps_unref (ptest.sink_caps);
|
||||
}
|
||||
|
||||
GST_END_TEST;
|
||||
|
||||
|
||||
/*
|
||||
* Test if the parser pushes data with ADTS frames properly.
|
||||
*/
|
||||
GST_START_TEST (test_parse_adts_normal)
|
||||
{
|
||||
buffer_verify_data_s vdata = { 0, 0, adts_frame_mpeg4, NULL };
|
||||
GstElement *aacparse;
|
||||
GstBuffer *buffer;
|
||||
guint i;
|
||||
|
||||
aacparse = setup_aacparse (NULL);
|
||||
|
||||
for (i = 0; i < 10; i++) {
|
||||
buffer = buffer_new (adts_frame_mpeg4, ADTS_FRAME_LEN);
|
||||
fail_unless_equals_int (gst_pad_push (srcpad, buffer), GST_FLOW_OK);
|
||||
}
|
||||
gst_pad_push_event (srcpad, gst_event_new_eos ());
|
||||
|
||||
fail_unless_equals_int (g_list_length (buffers), 10);
|
||||
g_list_foreach (buffers, buffer_verify_adts, &vdata);
|
||||
|
||||
cleanup_aacparse (aacparse);
|
||||
gst_parser_test_normal (adts_frame_mpeg4, sizeof (adts_frame_mpeg4));
|
||||
}
|
||||
|
||||
GST_END_TEST;
|
||||
|
||||
|
||||
/*
|
||||
* Test if ADTS parser drains its buffers properly. Even one single frame
|
||||
* should be drained and pushed forward when EOS occurs. This single frame
|
||||
* case is special, since normally the parser needs more data to be sure
|
||||
* about stream format. But it should still push the frame forward in EOS.
|
||||
*/
|
||||
GST_START_TEST (test_parse_adts_drain_single)
|
||||
{
|
||||
buffer_verify_data_s vdata = { 0, 0, adts_frame_mpeg4, NULL };
|
||||
GstElement *aacparse;
|
||||
GstBuffer *buffer;
|
||||
|
||||
aacparse = setup_aacparse (NULL);
|
||||
|
||||
buffer = buffer_new (adts_frame_mpeg4, ADTS_FRAME_LEN);
|
||||
fail_unless_equals_int (gst_pad_push (srcpad, buffer), GST_FLOW_OK);
|
||||
gst_pad_push_event (srcpad, gst_event_new_eos ());
|
||||
|
||||
fail_unless_equals_int (g_list_length (buffers), 1);
|
||||
g_list_foreach (buffers, buffer_verify_adts, &vdata);
|
||||
|
||||
cleanup_aacparse (aacparse);
|
||||
gst_parser_test_drain_single (adts_frame_mpeg4, sizeof (adts_frame_mpeg4));
|
||||
}
|
||||
|
||||
GST_END_TEST;
|
||||
|
||||
|
||||
/*
|
||||
* Make sure that parser does not drain garbage when EOS occurs.
|
||||
*/
|
||||
GST_START_TEST (test_parse_adts_drain_garbage)
|
||||
{
|
||||
buffer_verify_data_s vdata = { 0, 0, adts_frame_mpeg4, NULL };
|
||||
GstElement *aacparse;
|
||||
GstBuffer *buffer;
|
||||
guint i;
|
||||
|
||||
aacparse = setup_aacparse (NULL);
|
||||
|
||||
for (i = 0; i < 10; i++) {
|
||||
buffer = buffer_new (adts_frame_mpeg4, ADTS_FRAME_LEN);
|
||||
fail_unless_equals_int (gst_pad_push (srcpad, buffer), GST_FLOW_OK);
|
||||
}
|
||||
|
||||
/* Push one garbage frame and then EOS */
|
||||
buffer = buffer_new (garbage_frame, GARBAGE_FRAME_LEN);
|
||||
fail_unless_equals_int (gst_pad_push (srcpad, buffer), GST_FLOW_OK);
|
||||
gst_pad_push_event (srcpad, gst_event_new_eos ());
|
||||
|
||||
fail_unless_equals_int (g_list_length (buffers), 10);
|
||||
g_list_foreach (buffers, buffer_verify_adts, &vdata);
|
||||
|
||||
cleanup_aacparse (aacparse);
|
||||
gst_parser_test_drain_garbage (adts_frame_mpeg4, sizeof (adts_frame_mpeg4),
|
||||
garbage_frame, sizeof (garbage_frame));
|
||||
}
|
||||
|
||||
GST_END_TEST;
|
||||
|
||||
|
||||
/*
|
||||
* Test if ADTS parser splits a buffer that contains two frames into two
|
||||
* separate buffers properly.
|
||||
*/
|
||||
GST_START_TEST (test_parse_adts_split)
|
||||
{
|
||||
buffer_verify_data_s vdata = { 0, 0, adts_frame_mpeg4, NULL };
|
||||
GstElement *aacparse;
|
||||
GstBuffer *buffer;
|
||||
guint i;
|
||||
|
||||
aacparse = setup_aacparse (NULL);
|
||||
|
||||
for (i = 0; i < 5; i++) {
|
||||
buffer = buffer_new (adts_frame_mpeg4, ADTS_FRAME_LEN * 2);
|
||||
memcpy (GST_BUFFER_DATA (buffer) + ADTS_FRAME_LEN,
|
||||
adts_frame_mpeg4, ADTS_FRAME_LEN);
|
||||
fail_unless_equals_int (gst_pad_push (srcpad, buffer), GST_FLOW_OK);
|
||||
}
|
||||
gst_pad_push_event (srcpad, gst_event_new_eos ());
|
||||
|
||||
fail_unless_equals_int (g_list_length (buffers), 10);
|
||||
g_list_foreach (buffers, buffer_verify_adts, &vdata);
|
||||
|
||||
cleanup_aacparse (aacparse);
|
||||
gst_parser_test_split (adts_frame_mpeg4, sizeof (adts_frame_mpeg4));
|
||||
}
|
||||
|
||||
GST_END_TEST;
|
||||
|
||||
|
||||
/*
|
||||
* Test if the ADTS parser skips garbage between frames properly.
|
||||
*/
|
||||
GST_START_TEST (test_parse_adts_skip_garbage)
|
||||
{
|
||||
buffer_verify_data_s vdata =
|
||||
{ 10, GARBAGE_FRAME_LEN, adts_frame_mpeg4, NULL };
|
||||
GstElement *aacparse;
|
||||
GstBuffer *buffer;
|
||||
guint i;
|
||||
|
||||
aacparse = setup_aacparse (NULL);
|
||||
|
||||
for (i = 0; i < 10; i++) {
|
||||
buffer = buffer_new (adts_frame_mpeg4, ADTS_FRAME_LEN);
|
||||
fail_unless_equals_int (gst_pad_push (srcpad, buffer), GST_FLOW_OK);
|
||||
}
|
||||
|
||||
/* push garbage */
|
||||
buffer = buffer_new (garbage_frame, GARBAGE_FRAME_LEN);
|
||||
fail_unless_equals_int (gst_pad_push (srcpad, buffer), GST_FLOW_OK);
|
||||
|
||||
for (i = 0; i < 10; i++) {
|
||||
buffer = buffer_new (adts_frame_mpeg4, ADTS_FRAME_LEN);
|
||||
fail_unless_equals_int (gst_pad_push (srcpad, buffer), GST_FLOW_OK);
|
||||
}
|
||||
gst_pad_push_event (srcpad, gst_event_new_eos ());
|
||||
|
||||
fail_unless_equals_int (g_list_length (buffers), 20);
|
||||
g_list_foreach (buffers, buffer_verify_adts, &vdata);
|
||||
|
||||
cleanup_aacparse (aacparse);
|
||||
gst_parser_test_skip_garbage (adts_frame_mpeg4, sizeof (adts_frame_mpeg4),
|
||||
garbage_frame, sizeof (garbage_frame));
|
||||
}
|
||||
|
||||
GST_END_TEST;
|
||||
|
@ -399,36 +143,8 @@ GST_END_TEST;
|
|||
*/
|
||||
GST_START_TEST (test_parse_adts_detect_mpeg_version)
|
||||
{
|
||||
buffer_verify_data_s vdata = { 0, 0, adts_frame_mpeg2, NULL };
|
||||
GstElement *aacparse;
|
||||
GstBuffer *buffer;
|
||||
GstCaps *sinkcaps;
|
||||
guint i;
|
||||
|
||||
aacparse = setup_aacparse (NULL);
|
||||
|
||||
/* buffer_verify_adts will check if the caps are equal */
|
||||
vdata.caps = gst_caps_from_string (SINK_CAPS_MPEG2
|
||||
", stream-format=(string)adts");
|
||||
|
||||
for (i = 0; i < 10; i++) {
|
||||
/* Push MPEG version 2 frames. */
|
||||
buffer = buffer_new (adts_frame_mpeg2, ADTS_FRAME_LEN);
|
||||
fail_unless_equals_int (gst_pad_push (srcpad, buffer), GST_FLOW_OK);
|
||||
}
|
||||
gst_pad_push_event (srcpad, gst_event_new_eos ());
|
||||
|
||||
/* Check that the negotiated caps are as expected */
|
||||
sinkcaps = gst_pad_get_negotiated_caps (sinkpad);
|
||||
GST_LOG ("%" GST_PTR_FORMAT " = %" GST_PTR_FORMAT "?", sinkcaps, vdata.caps);
|
||||
fail_unless (gst_caps_is_equal (sinkcaps, vdata.caps));
|
||||
gst_caps_unref (sinkcaps);
|
||||
|
||||
fail_unless_equals_int (g_list_length (buffers), 10);
|
||||
g_list_foreach (buffers, buffer_verify_adts, &vdata);
|
||||
|
||||
gst_caps_unref (vdata.caps);
|
||||
cleanup_aacparse (aacparse);
|
||||
gst_parser_test_output_caps (adts_frame_mpeg2, sizeof (adts_frame_mpeg2),
|
||||
NULL, SINK_CAPS_MPEG2 ", stream-format=(string)adts");
|
||||
}
|
||||
|
||||
GST_END_TEST;
|
||||
|
@ -442,29 +158,19 @@ GST_END_TEST;
|
|||
*/
|
||||
GST_START_TEST (test_parse_handle_codec_data)
|
||||
{
|
||||
GstElement *aacparse;
|
||||
GstBuffer *buffer;
|
||||
GstCaps *sinkcaps;
|
||||
GstCaps *caps;
|
||||
GstStructure *s;
|
||||
guint datasum = 0;
|
||||
guint i;
|
||||
const gchar *stream_format;
|
||||
|
||||
aacparse = setup_aacparse (SRC_CAPS_CDATA);
|
||||
|
||||
for (i = 0; i < 10; i++) {
|
||||
/* Push random data. It should get through since the parser should be
|
||||
initialized because it got codec_data in the caps */
|
||||
buffer = buffer_new (NULL, 100);
|
||||
fail_unless_equals_int (gst_pad_push (srcpad, buffer), GST_FLOW_OK);
|
||||
}
|
||||
gst_pad_push_event (srcpad, gst_event_new_eos ());
|
||||
* initialized because it got codec_data in the caps */
|
||||
caps = gst_parser_test_get_output_caps (NULL, 100, SRC_CAPS_CDATA);
|
||||
fail_unless (caps != NULL);
|
||||
|
||||
/* Check that the negotiated caps are as expected */
|
||||
/* When codec_data is present, parser assumes that data is version 4 */
|
||||
sinkcaps = gst_pad_get_negotiated_caps (sinkpad);
|
||||
GST_LOG ("aac output caps: %" GST_PTR_FORMAT, sinkcaps);
|
||||
s = gst_caps_get_structure (sinkcaps, 0);
|
||||
GST_LOG ("aac output caps: %" GST_PTR_FORMAT, caps);
|
||||
s = gst_caps_get_structure (caps, 0);
|
||||
fail_unless (gst_structure_has_name (s, "audio/mpeg"));
|
||||
fail_unless_structure_field_int_equals (s, "mpegversion", 4);
|
||||
fail_unless_structure_field_int_equals (s, "channels", 2);
|
||||
|
@ -474,12 +180,7 @@ GST_START_TEST (test_parse_handle_codec_data)
|
|||
stream_format = gst_structure_get_string (s, "stream-format");
|
||||
fail_unless (strcmp (stream_format, "raw") == 0);
|
||||
|
||||
gst_caps_unref (sinkcaps);
|
||||
|
||||
g_list_foreach (buffers, buffer_count_size, &datasum);
|
||||
fail_unless_equals_int (datasum, 10 * 100);
|
||||
|
||||
cleanup_aacparse (aacparse);
|
||||
gst_caps_unref (caps);
|
||||
}
|
||||
|
||||
GST_END_TEST;
|
||||
|
@ -516,4 +217,24 @@ aacparse_suite (void)
|
|||
* * Pull-mode & EOS
|
||||
*/
|
||||
|
||||
GST_CHECK_MAIN (aacparse);
|
||||
int
|
||||
main (int argc, char **argv)
|
||||
{
|
||||
int nf;
|
||||
|
||||
Suite *s = aacparse_suite ();
|
||||
SRunner *sr = srunner_create (s);
|
||||
|
||||
gst_check_init (&argc, &argv);
|
||||
|
||||
/* init test context */
|
||||
ctx_factory = "aacparse";
|
||||
ctx_sink_template = &sinktemplate;
|
||||
ctx_src_template = &srctemplate;
|
||||
|
||||
srunner_run_all (sr, CK_NORMAL);
|
||||
nf = srunner_ntests_failed (sr);
|
||||
srunner_free (sr);
|
||||
|
||||
return nf;
|
||||
}
|
||||
|
|
|
@ -24,7 +24,7 @@
|
|||
*/
|
||||
|
||||
#include <gst/check/gstcheck.h>
|
||||
#include "amrparse_data.h"
|
||||
#include "parser.h"
|
||||
|
||||
#define SRC_CAPS_NB "audio/x-amr-nb-sh"
|
||||
#define SRC_CAPS_WB "audio/x-amr-wb-sh"
|
||||
|
@ -36,14 +36,6 @@
|
|||
|
||||
#define AMR_FRAME_DURATION (GST_SECOND/50)
|
||||
|
||||
GList *current_buf = NULL;
|
||||
|
||||
GstPad *srcpad, *sinkpad;
|
||||
guint dataoffset = 0;
|
||||
GstClockTime ts_counter = 0;
|
||||
gint64 offset_counter = 0;
|
||||
guint buffer_counter = 0;
|
||||
|
||||
static GstStaticPadTemplate sinktemplate_nb = GST_STATIC_PAD_TEMPLATE ("sink",
|
||||
GST_PAD_SINK,
|
||||
GST_PAD_ALWAYS,
|
||||
|
@ -56,12 +48,6 @@ static GstStaticPadTemplate sinktemplate_wb = GST_STATIC_PAD_TEMPLATE ("sink",
|
|||
GST_STATIC_CAPS (SINK_CAPS_WB)
|
||||
);
|
||||
|
||||
static GstStaticPadTemplate sinktemplate_any = GST_STATIC_PAD_TEMPLATE ("sink",
|
||||
GST_PAD_SINK,
|
||||
GST_PAD_ALWAYS,
|
||||
GST_STATIC_CAPS (SINK_CAPS_ANY)
|
||||
);
|
||||
|
||||
static GstStaticPadTemplate srctemplate_nb = GST_STATIC_PAD_TEMPLATE ("src",
|
||||
GST_PAD_SRC,
|
||||
GST_PAD_ALWAYS,
|
||||
|
@ -74,555 +60,193 @@ static GstStaticPadTemplate srctemplate_wb = GST_STATIC_PAD_TEMPLATE ("src",
|
|||
GST_STATIC_CAPS (SRC_CAPS_WB)
|
||||
);
|
||||
|
||||
static GstStaticPadTemplate srctemplate_any = GST_STATIC_PAD_TEMPLATE ("src",
|
||||
GST_PAD_SRC,
|
||||
GST_PAD_ALWAYS,
|
||||
GST_STATIC_CAPS (SRC_CAPS_ANY)
|
||||
);
|
||||
|
||||
typedef struct
|
||||
{
|
||||
guint buffers_before_offset_skip;
|
||||
guint offset_skip_amount;
|
||||
} buffer_verify_data_s;
|
||||
/* some data */
|
||||
|
||||
/*
|
||||
* Create a GstBuffer of the given data and set the caps, if not NULL.
|
||||
*/
|
||||
static GstBuffer *
|
||||
buffer_new (const unsigned char *buffer_data, guint size,
|
||||
const gchar * caps_str)
|
||||
{
|
||||
GstBuffer *buffer;
|
||||
GstCaps *caps;
|
||||
static guint8 frame_data_nb[] = {
|
||||
0x0c, 0x56, 0x3c, 0x52, 0xe0, 0x61, 0xbc, 0x45,
|
||||
0x0f, 0x98, 0x2e, 0x01, 0x42, 0x02
|
||||
};
|
||||
|
||||
buffer = gst_buffer_new_and_alloc (size);
|
||||
memcpy (GST_BUFFER_DATA (buffer), buffer_data, size);
|
||||
if (caps_str) {
|
||||
caps = gst_caps_from_string (caps_str);
|
||||
gst_buffer_set_caps (buffer, caps);
|
||||
gst_caps_unref (caps);
|
||||
}
|
||||
GST_BUFFER_OFFSET (buffer) = dataoffset;
|
||||
dataoffset += size;
|
||||
return buffer;
|
||||
}
|
||||
static guint8 frame_data_wb[] = {
|
||||
0x08, 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06,
|
||||
0x07, 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e,
|
||||
0x0f, 0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16
|
||||
};
|
||||
|
||||
static guint8 frame_hdr_nb[] = {
|
||||
'#', '!', 'A', 'M', 'R', '\n'
|
||||
};
|
||||
|
||||
static guint8 frame_hdr_wb[] = {
|
||||
'#', '!', 'A', 'M', 'R', '-', 'W', 'B', '\n'
|
||||
};
|
||||
|
||||
static guint8 garbage_frame[] = {
|
||||
0xff, 0xff, 0xff, 0xff, 0xff
|
||||
};
|
||||
|
||||
|
||||
/*
|
||||
* Unrefs given buffer.
|
||||
*/
|
||||
static void
|
||||
buffer_unref (void *buffer, void *user_data)
|
||||
{
|
||||
gst_buffer_unref (GST_BUFFER (buffer));
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* Verify that given buffer contains predefined AMR-NB frame.
|
||||
*/
|
||||
static void
|
||||
buffer_verify_nb (void *buffer, void *user_data)
|
||||
{
|
||||
fail_unless (memcmp (GST_BUFFER_DATA (buffer), frame_data_nb,
|
||||
FRAME_DATA_NB_LEN) == 0);
|
||||
fail_unless (GST_BUFFER_TIMESTAMP (buffer) == ts_counter);
|
||||
fail_unless (GST_BUFFER_DURATION (buffer) == AMR_FRAME_DURATION);
|
||||
ts_counter += AMR_FRAME_DURATION;
|
||||
|
||||
if (user_data) {
|
||||
buffer_verify_data_s *vdata = (buffer_verify_data_s *) user_data;
|
||||
|
||||
/* This is for skipping the garbage in some test cases */
|
||||
if (buffer_counter == vdata->buffers_before_offset_skip) {
|
||||
offset_counter += vdata->offset_skip_amount;
|
||||
}
|
||||
}
|
||||
fail_unless (GST_BUFFER_OFFSET (buffer) == offset_counter);
|
||||
offset_counter += FRAME_DATA_NB_LEN;
|
||||
buffer_counter++;
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* Verify that given buffer contains predefined AMR-WB frame.
|
||||
*/
|
||||
static void
|
||||
buffer_verify_wb (void *buffer, void *user_data)
|
||||
{
|
||||
fail_unless (memcmp (GST_BUFFER_DATA (buffer), frame_data_wb,
|
||||
FRAME_DATA_WB_LEN) == 0);
|
||||
fail_unless (GST_BUFFER_TIMESTAMP (buffer) == ts_counter);
|
||||
fail_unless (GST_BUFFER_DURATION (buffer) == AMR_FRAME_DURATION);
|
||||
|
||||
if (user_data) {
|
||||
buffer_verify_data_s *vdata = (buffer_verify_data_s *) user_data;
|
||||
|
||||
/* This is for skipping the garbage in some test cases */
|
||||
if (buffer_counter == vdata->buffers_before_offset_skip) {
|
||||
offset_counter += vdata->offset_skip_amount;
|
||||
}
|
||||
}
|
||||
fail_unless (GST_BUFFER_OFFSET (buffer) == offset_counter);
|
||||
offset_counter += FRAME_DATA_WB_LEN;
|
||||
ts_counter += AMR_FRAME_DURATION;
|
||||
buffer_counter++;
|
||||
}
|
||||
|
||||
/*
|
||||
* Create a parser and pads according to given templates.
|
||||
*/
|
||||
static GstElement *
|
||||
setup_amrparse (GstStaticPadTemplate * srctemplate,
|
||||
GstStaticPadTemplate * sinktemplate)
|
||||
{
|
||||
GstElement *amrparse;
|
||||
GstBus *bus;
|
||||
|
||||
GST_DEBUG ("setup_amrparse");
|
||||
amrparse = gst_check_setup_element ("amrparse");
|
||||
srcpad = gst_check_setup_src_pad (amrparse, srctemplate, NULL);
|
||||
sinkpad = gst_check_setup_sink_pad (amrparse, sinktemplate, NULL);
|
||||
gst_pad_set_active (srcpad, TRUE);
|
||||
gst_pad_set_active (sinkpad, TRUE);
|
||||
|
||||
bus = gst_bus_new ();
|
||||
gst_element_set_bus (amrparse, bus);
|
||||
|
||||
fail_unless (gst_element_set_state (amrparse,
|
||||
GST_STATE_PLAYING) != GST_STATE_CHANGE_FAILURE,
|
||||
"could not set to playing");
|
||||
|
||||
ts_counter = offset_counter = buffer_counter = 0;
|
||||
buffers = NULL;
|
||||
return amrparse;
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* Delete parser and all related resources.
|
||||
*/
|
||||
static void
|
||||
cleanup_amrparse (GstElement * amrparse)
|
||||
{
|
||||
GstBus *bus;
|
||||
|
||||
/* free parsed buffers */
|
||||
g_list_foreach (buffers, buffer_unref, NULL);
|
||||
g_list_free (buffers);
|
||||
buffers = NULL;
|
||||
|
||||
bus = GST_ELEMENT_BUS (amrparse);
|
||||
gst_bus_set_flushing (bus, TRUE);
|
||||
gst_object_unref (bus);
|
||||
|
||||
GST_DEBUG ("cleanup_amrparse");
|
||||
gst_pad_set_active (srcpad, FALSE);
|
||||
gst_pad_set_active (sinkpad, FALSE);
|
||||
gst_check_teardown_src_pad (amrparse);
|
||||
gst_check_teardown_sink_pad (amrparse);
|
||||
gst_check_teardown_element (amrparse);
|
||||
srcpad = NULL;
|
||||
sinkpad = NULL;
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* Test if NB parser manages to find all frames and pushes them forward.
|
||||
*/
|
||||
GST_START_TEST (test_parse_nb_normal)
|
||||
{
|
||||
GstElement *amrparse;
|
||||
GstBuffer *buffer;
|
||||
guint i;
|
||||
|
||||
amrparse = setup_amrparse (&srctemplate_nb, &sinktemplate_nb);
|
||||
|
||||
/* Push the header */
|
||||
buffer = buffer_new (frame_hdr_nb, FRAME_HDR_NB_LEN, SRC_CAPS_NB);
|
||||
fail_unless_equals_int (gst_pad_push (srcpad, buffer), GST_FLOW_OK);
|
||||
offset_counter = FRAME_HDR_NB_LEN;
|
||||
|
||||
for (i = 0; i < 10; i++) {
|
||||
buffer = buffer_new (frame_data_nb, FRAME_DATA_NB_LEN, SRC_CAPS_NB);
|
||||
fail_unless_equals_int (gst_pad_push (srcpad, buffer), GST_FLOW_OK);
|
||||
}
|
||||
gst_pad_push_event (srcpad, gst_event_new_eos ());
|
||||
|
||||
fail_unless_equals_int (g_list_length (buffers), 10);
|
||||
g_list_foreach (buffers, buffer_verify_nb, NULL);
|
||||
|
||||
cleanup_amrparse (amrparse);
|
||||
gst_parser_test_normal (frame_data_nb, sizeof (frame_data_nb));
|
||||
}
|
||||
|
||||
GST_END_TEST;
|
||||
|
||||
|
||||
/*
|
||||
* Test if NB parser drains its buffers properly. Even one single buffer
|
||||
* should be drained and pushed forward when EOS occurs. This single buffer
|
||||
* case is special, since normally the parser needs more data to be sure
|
||||
* about stream format. But it should still push the frame forward in EOS.
|
||||
*/
|
||||
GST_START_TEST (test_parse_nb_drain_single)
|
||||
{
|
||||
GstElement *amrparse;
|
||||
GstBuffer *buffer;
|
||||
|
||||
amrparse = setup_amrparse (&srctemplate_nb, &sinktemplate_nb);
|
||||
|
||||
buffer = buffer_new (frame_data_nb, FRAME_DATA_NB_LEN, SRC_CAPS_NB);
|
||||
fail_unless_equals_int (gst_pad_push (srcpad, buffer), GST_FLOW_OK);
|
||||
gst_pad_push_event (srcpad, gst_event_new_eos ());
|
||||
|
||||
fail_unless_equals_int (g_list_length (buffers), 1);
|
||||
g_list_foreach (buffers, buffer_verify_nb, NULL);
|
||||
|
||||
cleanup_amrparse (amrparse);
|
||||
gst_parser_test_drain_single (frame_data_nb, sizeof (frame_data_nb));
|
||||
}
|
||||
|
||||
GST_END_TEST;
|
||||
|
||||
|
||||
/*
|
||||
* Make sure that parser does not drain garbage when EOS occurs.
|
||||
*/
|
||||
GST_START_TEST (test_parse_nb_drain_garbage)
|
||||
{
|
||||
GstElement *amrparse;
|
||||
GstBuffer *buffer;
|
||||
guint i;
|
||||
|
||||
amrparse = setup_amrparse (&srctemplate_nb, &sinktemplate_nb);
|
||||
|
||||
for (i = 0; i < 10; i++) {
|
||||
buffer = buffer_new (frame_data_nb, FRAME_DATA_NB_LEN, SRC_CAPS_NB);
|
||||
fail_unless_equals_int (gst_pad_push (srcpad, buffer), GST_FLOW_OK);
|
||||
}
|
||||
|
||||
/* Now push one garbage frame and then EOS */
|
||||
buffer = buffer_new (garbage_frame, GARBAGE_FRAME_LEN, SRC_CAPS_NB);
|
||||
fail_unless_equals_int (gst_pad_push (srcpad, buffer), GST_FLOW_OK);
|
||||
gst_pad_push_event (srcpad, gst_event_new_eos ());
|
||||
|
||||
/* parser should have pushed only the valid frames */
|
||||
fail_unless_equals_int (g_list_length (buffers), 10);
|
||||
g_list_foreach (buffers, buffer_verify_nb, NULL);
|
||||
|
||||
cleanup_amrparse (amrparse);
|
||||
gst_parser_test_drain_garbage (frame_data_nb, sizeof (frame_data_nb),
|
||||
garbage_frame, sizeof (garbage_frame));
|
||||
}
|
||||
|
||||
GST_END_TEST;
|
||||
|
||||
|
||||
/*
|
||||
* Test if NB parser splits a buffer that contains two frames into two
|
||||
* separate buffers properly.
|
||||
*/
|
||||
GST_START_TEST (test_parse_nb_split)
|
||||
{
|
||||
GstElement *amrparse;
|
||||
GstBuffer *buffer;
|
||||
guint i;
|
||||
|
||||
amrparse = setup_amrparse (&srctemplate_nb, &sinktemplate_nb);
|
||||
|
||||
for (i = 0; i < 10; i++) {
|
||||
/* Put two frames in one buffer */
|
||||
buffer = buffer_new (frame_data_nb, 2 * FRAME_DATA_NB_LEN, SRC_CAPS_NB);
|
||||
memcpy (GST_BUFFER_DATA (buffer) + FRAME_DATA_NB_LEN,
|
||||
frame_data_nb, FRAME_DATA_NB_LEN);
|
||||
fail_unless_equals_int (gst_pad_push (srcpad, buffer), GST_FLOW_OK);
|
||||
}
|
||||
gst_pad_push_event (srcpad, gst_event_new_eos ());
|
||||
|
||||
fail_unless_equals_int (g_list_length (buffers), 20);
|
||||
|
||||
/* Does output buffers contain correct frame data? */
|
||||
g_list_foreach (buffers, buffer_verify_nb, NULL);
|
||||
|
||||
cleanup_amrparse (amrparse);
|
||||
gst_parser_test_split (frame_data_nb, sizeof (frame_data_nb));
|
||||
}
|
||||
|
||||
GST_END_TEST;
|
||||
|
||||
|
||||
/*
|
||||
* Test if NB parser detects the format correctly.
|
||||
*/
|
||||
GST_START_TEST (test_parse_nb_detect_stream)
|
||||
{
|
||||
GstElement *amrparse;
|
||||
GstBuffer *buffer;
|
||||
GstCaps *caps, *mycaps;
|
||||
guint i;
|
||||
|
||||
amrparse = setup_amrparse (&srctemplate_any, &sinktemplate_any);
|
||||
|
||||
/* Push the header */
|
||||
buffer = buffer_new (frame_hdr_nb, FRAME_HDR_NB_LEN, NULL);
|
||||
fail_unless_equals_int (gst_pad_push (srcpad, buffer), GST_FLOW_OK);
|
||||
|
||||
for (i = 0; i < 10; i++) {
|
||||
buffer = buffer_new (frame_data_nb, FRAME_DATA_NB_LEN, NULL);
|
||||
fail_unless_equals_int (gst_pad_push (srcpad, buffer), GST_FLOW_OK);
|
||||
}
|
||||
gst_pad_push_event (srcpad, gst_event_new_eos ());
|
||||
|
||||
caps = GST_PAD_CAPS (sinkpad);
|
||||
mycaps = gst_caps_from_string (SINK_CAPS_NB);
|
||||
fail_unless (gst_caps_is_equal (caps, mycaps));
|
||||
gst_caps_unref (mycaps);
|
||||
|
||||
cleanup_amrparse (amrparse);
|
||||
}
|
||||
|
||||
GST_END_TEST;
|
||||
|
||||
|
||||
/*
|
||||
* Test if NB parser skips garbage in the datastream correctly and still
|
||||
* finds all correct frames.
|
||||
*/
|
||||
GST_START_TEST (test_parse_nb_skip_garbage)
|
||||
{
|
||||
buffer_verify_data_s vdata = { 5, GARBAGE_FRAME_LEN };
|
||||
GstElement *amrparse;
|
||||
GstBuffer *buffer;
|
||||
guint i;
|
||||
|
||||
amrparse = setup_amrparse (&srctemplate_nb, &sinktemplate_nb);
|
||||
|
||||
/* First push 5 healthy frames */
|
||||
for (i = 0; i < 5; i++) {
|
||||
buffer = buffer_new (frame_data_nb, FRAME_DATA_NB_LEN, SRC_CAPS_NB);
|
||||
fail_unless_equals_int (gst_pad_push (srcpad, buffer), GST_FLOW_OK);
|
||||
}
|
||||
|
||||
/* Then push some garbage */
|
||||
buffer = buffer_new (garbage_frame, GARBAGE_FRAME_LEN, SRC_CAPS_NB);
|
||||
fail_unless_equals_int (gst_pad_push (srcpad, buffer), GST_FLOW_OK);
|
||||
|
||||
/* Again, healthy frames */
|
||||
for (i = 0; i < 5; i++) {
|
||||
buffer = buffer_new (frame_data_nb, FRAME_DATA_NB_LEN, SRC_CAPS_NB);
|
||||
fail_unless_equals_int (gst_pad_push (srcpad, buffer), GST_FLOW_OK);
|
||||
}
|
||||
|
||||
gst_pad_push_event (srcpad, gst_event_new_eos ());
|
||||
|
||||
/* Did it find all 10 healthy frames? */
|
||||
fail_unless_equals_int (g_list_length (buffers), 10);
|
||||
g_list_foreach (buffers, buffer_verify_nb, &vdata);
|
||||
|
||||
cleanup_amrparse (amrparse);
|
||||
gst_parser_test_skip_garbage (frame_data_nb, sizeof (frame_data_nb),
|
||||
garbage_frame, sizeof (garbage_frame));
|
||||
}
|
||||
|
||||
GST_END_TEST;
|
||||
|
||||
|
||||
GST_START_TEST (test_parse_nb_detect_stream)
|
||||
{
|
||||
GstParserTest ptest;
|
||||
GstCaps *old_ctx_caps;
|
||||
|
||||
/* no input caps, override ctx */
|
||||
old_ctx_caps = ctx_input_caps;
|
||||
ctx_input_caps = NULL;
|
||||
|
||||
/* AMR-NB header */
|
||||
gst_parser_test_init (&ptest, frame_hdr_nb, sizeof (frame_hdr_nb), 1);
|
||||
/* well, no garbage, followed by real data */
|
||||
ptest.series[2].data = frame_data_nb;
|
||||
ptest.series[2].size = sizeof (frame_data_nb);
|
||||
ptest.series[2].num = 10;
|
||||
/* header gets dropped, so ... */
|
||||
/* buffer count will not match */
|
||||
ptest.framed = FALSE;
|
||||
/* total size a bit less */
|
||||
ptest.dropped = sizeof (frame_hdr_nb);
|
||||
|
||||
/* Check that the negotiated caps are as expected */
|
||||
ptest.sink_caps = gst_caps_from_string (SINK_CAPS_NB);
|
||||
|
||||
gst_parser_test_run (&ptest, NULL);
|
||||
|
||||
gst_caps_unref (ptest.sink_caps);
|
||||
|
||||
ctx_input_caps = old_ctx_caps;
|
||||
}
|
||||
|
||||
GST_END_TEST;
|
||||
|
||||
|
||||
/*
|
||||
* Test if WB parser manages to find all frames and pushes them forward.
|
||||
*/
|
||||
GST_START_TEST (test_parse_wb_normal)
|
||||
{
|
||||
GstElement *amrparse;
|
||||
GstBuffer *buffer;
|
||||
guint i;
|
||||
|
||||
amrparse = setup_amrparse (&srctemplate_wb, &sinktemplate_wb);
|
||||
|
||||
/* Push the header */
|
||||
buffer = buffer_new (frame_hdr_wb, FRAME_HDR_WB_LEN, SRC_CAPS_WB);
|
||||
fail_unless_equals_int (gst_pad_push (srcpad, buffer), GST_FLOW_OK);
|
||||
offset_counter = FRAME_HDR_WB_LEN;
|
||||
|
||||
for (i = 0; i < 10; i++) {
|
||||
buffer = buffer_new (frame_data_wb, FRAME_DATA_WB_LEN, SRC_CAPS_WB);
|
||||
fail_unless_equals_int (gst_pad_push (srcpad, buffer), GST_FLOW_OK);
|
||||
}
|
||||
gst_pad_push_event (srcpad, gst_event_new_eos ());
|
||||
|
||||
fail_unless_equals_int (g_list_length (buffers), 10);
|
||||
g_list_foreach (buffers, buffer_verify_wb, NULL);
|
||||
|
||||
cleanup_amrparse (amrparse);
|
||||
gst_parser_test_normal (frame_data_wb, sizeof (frame_data_wb));
|
||||
}
|
||||
|
||||
GST_END_TEST;
|
||||
|
||||
|
||||
/*
|
||||
* Test if WB parser drains its buffers properly. Even one single buffer
|
||||
* should be drained and pushed forward when EOS occurs. This single buffer
|
||||
* case is special, since normally the parser needs more data to be sure
|
||||
* about stream format. But it should still push the frame forward in EOS.
|
||||
*/
|
||||
GST_START_TEST (test_parse_wb_drain_single)
|
||||
{
|
||||
GstElement *amrparse;
|
||||
GstBuffer *buffer;
|
||||
|
||||
amrparse = setup_amrparse (&srctemplate_wb, &sinktemplate_wb);
|
||||
|
||||
buffer = buffer_new (frame_data_wb, FRAME_DATA_WB_LEN, SRC_CAPS_WB);
|
||||
fail_unless_equals_int (gst_pad_push (srcpad, buffer), GST_FLOW_OK);
|
||||
gst_pad_push_event (srcpad, gst_event_new_eos ());
|
||||
|
||||
fail_unless_equals_int (g_list_length (buffers), 1);
|
||||
g_list_foreach (buffers, buffer_verify_wb, NULL);
|
||||
|
||||
cleanup_amrparse (amrparse);
|
||||
gst_parser_test_drain_single (frame_data_wb, sizeof (frame_data_wb));
|
||||
}
|
||||
|
||||
GST_END_TEST;
|
||||
|
||||
|
||||
/*
|
||||
* Make sure that parser does not drain garbage when EOS occurs.
|
||||
*/
|
||||
GST_START_TEST (test_parse_wb_drain_garbage)
|
||||
{
|
||||
GstElement *amrparse;
|
||||
GstBuffer *buffer;
|
||||
guint i;
|
||||
|
||||
amrparse = setup_amrparse (&srctemplate_wb, &sinktemplate_wb);
|
||||
|
||||
for (i = 0; i < 10; i++) {
|
||||
buffer = buffer_new (frame_data_wb, FRAME_DATA_WB_LEN, SRC_CAPS_WB);
|
||||
fail_unless_equals_int (gst_pad_push (srcpad, buffer), GST_FLOW_OK);
|
||||
}
|
||||
|
||||
/* Now push one garbage frame and then EOS */
|
||||
buffer = buffer_new (garbage_frame, GARBAGE_FRAME_LEN, SRC_CAPS_WB);
|
||||
fail_unless_equals_int (gst_pad_push (srcpad, buffer), GST_FLOW_OK);
|
||||
gst_pad_push_event (srcpad, gst_event_new_eos ());
|
||||
|
||||
/* parser should have pushed only the valid frames */
|
||||
fail_unless_equals_int (g_list_length (buffers), 10);
|
||||
g_list_foreach (buffers, buffer_verify_wb, NULL);
|
||||
|
||||
cleanup_amrparse (amrparse);
|
||||
gst_parser_test_drain_garbage (frame_data_wb, sizeof (frame_data_wb),
|
||||
garbage_frame, sizeof (garbage_frame));
|
||||
}
|
||||
|
||||
GST_END_TEST;
|
||||
|
||||
|
||||
/*
|
||||
* Test if WB parser splits a buffer that contains two frames into two
|
||||
* separate buffers properly.
|
||||
*/
|
||||
GST_START_TEST (test_parse_wb_split)
|
||||
{
|
||||
GstElement *amrparse;
|
||||
GstBuffer *buffer;
|
||||
guint i;
|
||||
|
||||
amrparse = setup_amrparse (&srctemplate_wb, &sinktemplate_wb);
|
||||
|
||||
for (i = 0; i < 10; i++) {
|
||||
/* Put two frames in one buffer */
|
||||
buffer = buffer_new (frame_data_wb, 2 * FRAME_DATA_WB_LEN, SRC_CAPS_WB);
|
||||
memcpy (GST_BUFFER_DATA (buffer) + FRAME_DATA_WB_LEN,
|
||||
frame_data_wb, FRAME_DATA_WB_LEN);
|
||||
fail_unless_equals_int (gst_pad_push (srcpad, buffer), GST_FLOW_OK);
|
||||
}
|
||||
gst_pad_push_event (srcpad, gst_event_new_eos ());
|
||||
|
||||
fail_unless_equals_int (g_list_length (buffers), 20);
|
||||
|
||||
/* Does output buffers contain correct frame data? */
|
||||
g_list_foreach (buffers, buffer_verify_wb, NULL);
|
||||
|
||||
cleanup_amrparse (amrparse);
|
||||
gst_parser_test_split (frame_data_wb, sizeof (frame_data_wb));
|
||||
}
|
||||
|
||||
GST_END_TEST;
|
||||
|
||||
|
||||
/*
|
||||
* Test if WB parser detects the format correctly.
|
||||
*/
|
||||
GST_START_TEST (test_parse_wb_detect_stream)
|
||||
{
|
||||
GstElement *amrparse;
|
||||
GstBuffer *buffer;
|
||||
GstCaps *caps, *mycaps;
|
||||
guint i;
|
||||
|
||||
amrparse = setup_amrparse (&srctemplate_any, &sinktemplate_any);
|
||||
|
||||
/* Push the header */
|
||||
buffer = buffer_new (frame_hdr_wb, FRAME_HDR_WB_LEN, NULL);
|
||||
fail_unless_equals_int (gst_pad_push (srcpad, buffer), GST_FLOW_OK);
|
||||
|
||||
for (i = 0; i < 10; i++) {
|
||||
buffer = buffer_new (frame_data_wb, FRAME_DATA_WB_LEN, NULL);
|
||||
fail_unless_equals_int (gst_pad_push (srcpad, buffer), GST_FLOW_OK);
|
||||
}
|
||||
gst_pad_push_event (srcpad, gst_event_new_eos ());
|
||||
|
||||
caps = GST_PAD_CAPS (sinkpad);
|
||||
mycaps = gst_caps_from_string (SINK_CAPS_WB);
|
||||
fail_unless (gst_caps_is_equal (caps, mycaps));
|
||||
gst_caps_unref (mycaps);
|
||||
|
||||
cleanup_amrparse (amrparse);
|
||||
}
|
||||
|
||||
GST_END_TEST;
|
||||
|
||||
|
||||
/*
|
||||
* Test if WB parser skips garbage in the datastream correctly and still
|
||||
* finds all correct frames.
|
||||
*/
|
||||
GST_START_TEST (test_parse_wb_skip_garbage)
|
||||
{
|
||||
buffer_verify_data_s vdata = { 5, GARBAGE_FRAME_LEN };
|
||||
GstElement *amrparse;
|
||||
GstBuffer *buffer;
|
||||
guint i;
|
||||
|
||||
amrparse = setup_amrparse (&srctemplate_wb, &sinktemplate_wb);
|
||||
|
||||
/* First push 5 healthy frames */
|
||||
for (i = 0; i < 5; i++) {
|
||||
buffer = buffer_new (frame_data_wb, FRAME_DATA_WB_LEN, SRC_CAPS_WB);
|
||||
fail_unless_equals_int (gst_pad_push (srcpad, buffer), GST_FLOW_OK);
|
||||
}
|
||||
|
||||
/* Then push some garbage */
|
||||
buffer = buffer_new (garbage_frame, GARBAGE_FRAME_LEN, SRC_CAPS_WB);
|
||||
fail_unless_equals_int (gst_pad_push (srcpad, buffer), GST_FLOW_OK);
|
||||
|
||||
/* Again, healthy frames */
|
||||
for (i = 0; i < 5; i++) {
|
||||
buffer = buffer_new (frame_data_wb, FRAME_DATA_WB_LEN, SRC_CAPS_WB);
|
||||
fail_unless_equals_int (gst_pad_push (srcpad, buffer), GST_FLOW_OK);
|
||||
}
|
||||
|
||||
gst_pad_push_event (srcpad, gst_event_new_eos ());
|
||||
|
||||
/* Did it find all 10 healthy frames? */
|
||||
fail_unless_equals_int (g_list_length (buffers), 10);
|
||||
g_list_foreach (buffers, buffer_verify_wb, &vdata);
|
||||
|
||||
cleanup_amrparse (amrparse);
|
||||
gst_parser_test_skip_garbage (frame_data_wb, sizeof (frame_data_wb),
|
||||
garbage_frame, sizeof (garbage_frame));
|
||||
}
|
||||
|
||||
GST_END_TEST;
|
||||
|
||||
|
||||
GST_START_TEST (test_parse_wb_detect_stream)
|
||||
{
|
||||
GstParserTest ptest;
|
||||
GstCaps *old_ctx_caps;
|
||||
|
||||
/* no input caps, override ctx */
|
||||
old_ctx_caps = ctx_input_caps;
|
||||
ctx_input_caps = NULL;
|
||||
|
||||
/* AMR-WB header */
|
||||
gst_parser_test_init (&ptest, frame_hdr_wb, sizeof (frame_hdr_wb), 1);
|
||||
/* well, no garbage, followed by real data */
|
||||
ptest.series[2].data = frame_data_wb;
|
||||
ptest.series[2].size = sizeof (frame_data_wb);
|
||||
ptest.series[2].num = 10;
|
||||
/* header gets dropped, so ... */
|
||||
/* buffer count will not match */
|
||||
ptest.framed = FALSE;
|
||||
/* total size a bit less */
|
||||
ptest.dropped = sizeof (frame_hdr_wb);
|
||||
|
||||
/* Check that the negotiated caps are as expected */
|
||||
ptest.sink_caps = gst_caps_from_string (SINK_CAPS_WB);
|
||||
|
||||
gst_parser_test_run (&ptest, NULL);
|
||||
|
||||
gst_caps_unref (ptest.sink_caps);
|
||||
|
||||
ctx_input_caps = old_ctx_caps;
|
||||
}
|
||||
|
||||
GST_END_TEST;
|
||||
|
||||
|
||||
|
||||
/*
|
||||
* Create test suite.
|
||||
*/
|
||||
static Suite *
|
||||
amrparse_suite (void)
|
||||
amrnb_parse_suite (void)
|
||||
{
|
||||
Suite *s = suite_create ("amrparse");
|
||||
Suite *s = suite_create ("amrwb_parse");
|
||||
TCase *tc_chain = tcase_create ("general");
|
||||
|
||||
suite_add_tcase (s, tc_chain);
|
||||
|
@ -634,6 +258,16 @@ amrparse_suite (void)
|
|||
tcase_add_test (tc_chain, test_parse_nb_detect_stream);
|
||||
tcase_add_test (tc_chain, test_parse_nb_skip_garbage);
|
||||
|
||||
return s;
|
||||
}
|
||||
|
||||
static Suite *
|
||||
amrwb_parse_suite (void)
|
||||
{
|
||||
Suite *s = suite_create ("amrnb_parse");
|
||||
TCase *tc_chain = tcase_create ("general");
|
||||
|
||||
suite_add_tcase (s, tc_chain);
|
||||
/* AMR-WB tests */
|
||||
tcase_add_test (tc_chain, test_parse_wb_normal);
|
||||
tcase_add_test (tc_chain, test_parse_wb_drain_single);
|
||||
|
@ -641,6 +275,7 @@ amrparse_suite (void)
|
|||
tcase_add_test (tc_chain, test_parse_wb_split);
|
||||
tcase_add_test (tc_chain, test_parse_wb_detect_stream);
|
||||
tcase_add_test (tc_chain, test_parse_wb_skip_garbage);
|
||||
|
||||
return s;
|
||||
}
|
||||
|
||||
|
@ -650,4 +285,43 @@ amrparse_suite (void)
|
|||
* * Pull-mode & EOS
|
||||
*/
|
||||
|
||||
GST_CHECK_MAIN (amrparse);
|
||||
int
|
||||
main (int argc, char **argv)
|
||||
{
|
||||
int nf;
|
||||
GstCaps *caps;
|
||||
|
||||
Suite *s = amrnb_parse_suite ();
|
||||
SRunner *sr = srunner_create (s);
|
||||
|
||||
gst_check_init (&argc, &argv);
|
||||
|
||||
/* init test context */
|
||||
ctx_factory = "amrparse";
|
||||
ctx_sink_template = &sinktemplate_nb;
|
||||
ctx_src_template = &srctemplate_nb;
|
||||
caps = gst_caps_from_string (SRC_CAPS_NB);
|
||||
g_assert (caps);
|
||||
ctx_input_caps = caps;
|
||||
|
||||
srunner_run_all (sr, CK_NORMAL);
|
||||
nf = srunner_ntests_failed (sr);
|
||||
srunner_free (sr);
|
||||
gst_caps_unref (caps);
|
||||
|
||||
s = amrwb_parse_suite ();
|
||||
sr = srunner_create (s);
|
||||
|
||||
ctx_sink_template = &sinktemplate_wb;
|
||||
ctx_src_template = &srctemplate_wb;
|
||||
caps = gst_caps_from_string (SRC_CAPS_WB);
|
||||
g_assert (caps);
|
||||
ctx_input_caps = caps;
|
||||
|
||||
srunner_run_all (sr, CK_NORMAL);
|
||||
nf += srunner_ntests_failed (sr);
|
||||
srunner_free (sr);
|
||||
gst_caps_unref (caps);
|
||||
|
||||
return nf;
|
||||
}
|
||||
|
|
407
tests/check/elements/parser.c
Normal file
407
tests/check/elements/parser.c
Normal file
|
@ -0,0 +1,407 @@
|
|||
/*
|
||||
* GStreamer
|
||||
*
|
||||
* unit test for (audio) parser
|
||||
*
|
||||
* Copyright (C) 2008 Nokia Corporation. All rights reserved.
|
||||
*
|
||||
* Contact: Stefan Kost <stefan.kost@nokia.com>
|
||||
*
|
||||
* 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>
|
||||
#include "parser.h"
|
||||
|
||||
|
||||
/* context state variables */
|
||||
const gchar *ctx_factory;
|
||||
GstStaticPadTemplate *ctx_sink_template;
|
||||
GstStaticPadTemplate *ctx_src_template;
|
||||
GstCaps *ctx_input_caps;
|
||||
GstCaps *ctx_output_caps;
|
||||
|
||||
|
||||
/* helper variables */
|
||||
GList *current_buf = NULL;
|
||||
|
||||
GstPad *srcpad, *sinkpad;
|
||||
guint dataoffset = 0;
|
||||
GstClockTime ts_counter = 0;
|
||||
gint64 offset_counter = 0;
|
||||
guint buffer_counter = 0;
|
||||
|
||||
typedef struct
|
||||
{
|
||||
guint buffers_before_offset_skip;
|
||||
guint offset_skip_amount;
|
||||
const guint8 *data_to_verify;
|
||||
guint data_to_verify_size;
|
||||
GstCaps *caps;
|
||||
} buffer_verify_data_s;
|
||||
|
||||
/* takes a copy of the passed buffer data */
|
||||
static GstBuffer *
|
||||
buffer_new (const unsigned char *buffer_data, guint size)
|
||||
{
|
||||
GstBuffer *buffer;
|
||||
|
||||
buffer = gst_buffer_new_and_alloc (size);
|
||||
if (buffer_data) {
|
||||
memcpy (GST_BUFFER_DATA (buffer), buffer_data, size);
|
||||
} else {
|
||||
guint i;
|
||||
/* Create a recognizable pattern (loop 0x00 -> 0xff) in the data block */
|
||||
for (i = 0; i < size; i++) {
|
||||
GST_BUFFER_DATA (buffer)[i] = i % 0x100;
|
||||
}
|
||||
}
|
||||
|
||||
gst_buffer_set_caps (buffer, GST_PAD_CAPS (srcpad));
|
||||
GST_BUFFER_OFFSET (buffer) = dataoffset;
|
||||
dataoffset += size;
|
||||
return buffer;
|
||||
}
|
||||
|
||||
/*
|
||||
* Adds buffer sizes together.
|
||||
*/
|
||||
static void
|
||||
buffer_count_size (void *buffer, void *user_data)
|
||||
{
|
||||
guint *sum = (guint *) user_data;
|
||||
*sum += GST_BUFFER_SIZE (buffer);
|
||||
}
|
||||
|
||||
/*
|
||||
* Verify that given buffer contains predefined ADTS frame.
|
||||
*/
|
||||
static void
|
||||
buffer_verify_data (void *buffer, void *user_data)
|
||||
{
|
||||
buffer_verify_data_s *vdata;
|
||||
|
||||
if (!user_data) {
|
||||
return;
|
||||
}
|
||||
|
||||
vdata = (buffer_verify_data_s *) user_data;
|
||||
|
||||
fail_unless (GST_BUFFER_SIZE (buffer) == vdata->data_to_verify_size);
|
||||
fail_unless (memcmp (GST_BUFFER_DATA (buffer), vdata->data_to_verify,
|
||||
vdata->data_to_verify_size) == 0);
|
||||
|
||||
fail_unless (GST_BUFFER_TIMESTAMP (buffer) == ts_counter);
|
||||
fail_unless (GST_BUFFER_DURATION (buffer) != 0);
|
||||
|
||||
if (vdata->buffers_before_offset_skip) {
|
||||
/* This is for skipping the garbage in some test cases */
|
||||
if (buffer_counter == vdata->buffers_before_offset_skip) {
|
||||
offset_counter += vdata->offset_skip_amount;
|
||||
}
|
||||
}
|
||||
fail_unless (GST_BUFFER_OFFSET (buffer) == offset_counter);
|
||||
|
||||
if (vdata->caps) {
|
||||
GST_LOG ("%" GST_PTR_FORMAT " = %" GST_PTR_FORMAT " ?",
|
||||
GST_BUFFER_CAPS (buffer), vdata->caps);
|
||||
fail_unless (gst_caps_is_equal (GST_BUFFER_CAPS (buffer), vdata->caps));
|
||||
}
|
||||
|
||||
ts_counter += GST_BUFFER_DURATION (buffer);
|
||||
offset_counter += GST_BUFFER_SIZE (buffer);
|
||||
buffer_counter++;
|
||||
}
|
||||
|
||||
static GstElement *
|
||||
setup_element (const gchar * factory, GstStaticPadTemplate * sink_template,
|
||||
GstCaps * sink_caps, GstStaticPadTemplate * src_template,
|
||||
GstCaps * src_caps)
|
||||
{
|
||||
GstElement *element;
|
||||
GstBus *bus;
|
||||
|
||||
element = gst_check_setup_element (factory);
|
||||
srcpad = gst_check_setup_src_pad (element, src_template, src_caps);
|
||||
sinkpad = gst_check_setup_sink_pad (element, sink_template, sink_caps);
|
||||
gst_pad_set_active (srcpad, TRUE);
|
||||
gst_pad_set_active (sinkpad, TRUE);
|
||||
|
||||
bus = gst_bus_new ();
|
||||
gst_element_set_bus (element, bus);
|
||||
|
||||
fail_unless (gst_element_set_state (element,
|
||||
GST_STATE_PLAYING) != GST_STATE_CHANGE_FAILURE,
|
||||
"could not set to playing");
|
||||
|
||||
ts_counter = offset_counter = buffer_counter = 0;
|
||||
buffers = NULL;
|
||||
return element;
|
||||
}
|
||||
|
||||
static void
|
||||
cleanup_element (GstElement * element)
|
||||
{
|
||||
GstBus *bus;
|
||||
|
||||
/* Free parsed buffers */
|
||||
gst_check_drop_buffers ();
|
||||
|
||||
bus = GST_ELEMENT_BUS (element);
|
||||
gst_bus_set_flushing (bus, TRUE);
|
||||
gst_object_unref (bus);
|
||||
|
||||
gst_pad_set_active (srcpad, FALSE);
|
||||
gst_pad_set_active (sinkpad, FALSE);
|
||||
gst_check_teardown_src_pad (element);
|
||||
gst_check_teardown_sink_pad (element);
|
||||
gst_check_teardown_element (element);
|
||||
}
|
||||
|
||||
/* inits a standard test */
|
||||
void
|
||||
gst_parser_test_init (GstParserTest * ptest, guint8 * data, guint size,
|
||||
guint num)
|
||||
{
|
||||
/* need these */
|
||||
fail_unless (ctx_factory != NULL);
|
||||
fail_unless (ctx_src_template != NULL);
|
||||
fail_unless (ctx_sink_template != NULL);
|
||||
|
||||
/* basics */
|
||||
memset (ptest, 0, sizeof (*ptest));
|
||||
ptest->factory = ctx_factory;
|
||||
ptest->sink_template = ctx_sink_template;
|
||||
ptest->src_template = ctx_src_template;
|
||||
ptest->framed = TRUE;
|
||||
/* could be NULL if not relevant/needed */
|
||||
ptest->src_caps = ctx_input_caps;
|
||||
ptest->sink_caps = ctx_output_caps;
|
||||
/* some data that pleases caller */
|
||||
ptest->series[0].data = data;
|
||||
ptest->series[0].size = size;
|
||||
ptest->series[0].num = num;
|
||||
ptest->series[0].fpb = 1;
|
||||
ptest->series[1].fpb = 1;
|
||||
ptest->series[2].fpb = 1;
|
||||
}
|
||||
|
||||
/*
|
||||
* Test if the parser pushes clean data properly.
|
||||
*/
|
||||
void
|
||||
gst_parser_test_run (GstParserTest * test, GstCaps ** out_caps)
|
||||
{
|
||||
buffer_verify_data_s vdata = { 0, 0, NULL, 0, NULL };
|
||||
GstElement *element;
|
||||
GstBuffer *buffer = NULL;
|
||||
GstCaps *src_caps;
|
||||
guint i, j, k;
|
||||
guint frames = 0, size = 0;
|
||||
|
||||
element = setup_element (test->factory, test->sink_template, NULL,
|
||||
test->src_template, test->src_caps);
|
||||
|
||||
for (j = 0; j < 3; j++) {
|
||||
for (i = 0; i < test->series[j].num; i++) {
|
||||
/* sanity enforcing */
|
||||
for (k = 0; k < MAX (1, test->series[j].fpb); k++) {
|
||||
if (!k)
|
||||
buffer = buffer_new (test->series[j].data, test->series[j].size);
|
||||
else {
|
||||
GstCaps *caps = gst_buffer_get_caps (buffer);
|
||||
|
||||
buffer = gst_buffer_join (buffer,
|
||||
buffer_new (test->series[j].data, test->series[j].size));
|
||||
if (caps) {
|
||||
gst_buffer_set_caps (buffer, caps);
|
||||
gst_caps_unref (caps);
|
||||
}
|
||||
}
|
||||
}
|
||||
fail_unless_equals_int (gst_pad_push (srcpad, buffer), GST_FLOW_OK);
|
||||
if (j == 0)
|
||||
vdata.buffers_before_offset_skip++;
|
||||
else if (j == 1)
|
||||
vdata.offset_skip_amount += test->series[j].size * test->series[j].fpb;
|
||||
if (j != 1) {
|
||||
frames += test->series[j].fpb;
|
||||
size += test->series[j].size * test->series[j].fpb;
|
||||
}
|
||||
}
|
||||
}
|
||||
gst_pad_push_event (srcpad, gst_event_new_eos ());
|
||||
|
||||
if (G_LIKELY (test->framed))
|
||||
fail_unless_equals_int (g_list_length (buffers), frames);
|
||||
|
||||
/* if all frames are identical, do extended test,
|
||||
* otherwise only verify total data size */
|
||||
if (test->series[0].data && test->series[2].data &&
|
||||
test->series[0].size == test->series[2].size &&
|
||||
!memcmp (test->series[0].data, test->series[2].data,
|
||||
test->series[0].size)) {
|
||||
vdata.data_to_verify = test->series[0].data;
|
||||
vdata.data_to_verify_size = test->series[0].size;
|
||||
vdata.caps = test->sink_caps;
|
||||
g_list_foreach (buffers, buffer_verify_data, &vdata);
|
||||
} else {
|
||||
guint datasum = 0;
|
||||
|
||||
g_list_foreach (buffers, buffer_count_size, &datasum);
|
||||
size -= test->dropped;
|
||||
fail_unless_equals_int (datasum, size);
|
||||
}
|
||||
|
||||
src_caps = gst_pad_get_negotiated_caps (sinkpad);
|
||||
GST_LOG ("output caps: %" GST_PTR_FORMAT, src_caps);
|
||||
|
||||
if (test->sink_caps) {
|
||||
GST_LOG ("%" GST_PTR_FORMAT " = %" GST_PTR_FORMAT " ?", src_caps,
|
||||
test->sink_caps);
|
||||
fail_unless (gst_caps_is_equal (src_caps, test->sink_caps));
|
||||
}
|
||||
|
||||
if (out_caps)
|
||||
*out_caps = src_caps;
|
||||
else
|
||||
gst_caps_unref (src_caps);
|
||||
|
||||
cleanup_element (element);
|
||||
}
|
||||
|
||||
/*
|
||||
* Test if the parser pushes clean data properly.
|
||||
*/
|
||||
void
|
||||
gst_parser_test_normal (guint8 * data, guint size)
|
||||
{
|
||||
GstParserTest ptest;
|
||||
|
||||
gst_parser_test_init (&ptest, data, size, 10);
|
||||
gst_parser_test_run (&ptest, NULL);
|
||||
}
|
||||
|
||||
/*
|
||||
* Test if parser drains its buffers properly. Even one single frame
|
||||
* should be drained and pushed forward when EOS occurs. This single frame
|
||||
* case is special, since normally the parser needs more data to be sure
|
||||
* about stream format. But it should still push the frame forward in EOS.
|
||||
*/
|
||||
void
|
||||
gst_parser_test_drain_single (guint8 * data, guint size)
|
||||
{
|
||||
GstParserTest ptest;
|
||||
|
||||
gst_parser_test_init (&ptest, data, size, 1);
|
||||
gst_parser_test_run (&ptest, NULL);
|
||||
}
|
||||
|
||||
/*
|
||||
* Make sure that parser does not drain garbage when EOS occurs.
|
||||
*/
|
||||
void
|
||||
gst_parser_test_drain_garbage (guint8 * data, guint size, guint8 * garbage,
|
||||
guint gsize)
|
||||
{
|
||||
GstParserTest ptest;
|
||||
|
||||
gst_parser_test_init (&ptest, data, size, 1);
|
||||
ptest.series[1].data = garbage;
|
||||
ptest.series[1].size = gsize;
|
||||
ptest.series[1].num = 1;
|
||||
gst_parser_test_run (&ptest, NULL);
|
||||
}
|
||||
|
||||
/*
|
||||
* Test if parser splits a buffer that contains two frames into two
|
||||
* separate buffers properly.
|
||||
*/
|
||||
void
|
||||
gst_parser_test_split (guint8 * data, guint size)
|
||||
{
|
||||
GstParserTest ptest;
|
||||
|
||||
gst_parser_test_init (&ptest, data, size, 10);
|
||||
ptest.series[0].fpb = 2;
|
||||
gst_parser_test_run (&ptest, NULL);
|
||||
}
|
||||
|
||||
/*
|
||||
* Test if the parser skips garbage between frames properly.
|
||||
*/
|
||||
void
|
||||
gst_parser_test_skip_garbage (guint8 * data, guint size, guint8 * garbage,
|
||||
guint gsize)
|
||||
{
|
||||
GstParserTest ptest;
|
||||
|
||||
gst_parser_test_init (&ptest, data, size, 10);
|
||||
ptest.series[1].data = garbage;
|
||||
ptest.series[1].size = gsize;
|
||||
ptest.series[1].num = 1;
|
||||
ptest.series[2].data = data;
|
||||
ptest.series[2].size = size;
|
||||
ptest.series[2].num = 10;
|
||||
gst_parser_test_run (&ptest, NULL);
|
||||
}
|
||||
|
||||
/*
|
||||
* Test if the src caps are set according to stream format.
|
||||
*/
|
||||
void
|
||||
gst_parser_test_output_caps (guint8 * data, guint size,
|
||||
const gchar * input_caps, const gchar * output_caps)
|
||||
{
|
||||
GstParserTest ptest;
|
||||
|
||||
gst_parser_test_init (&ptest, data, size, 10);
|
||||
if (input_caps) {
|
||||
ptest.src_caps = gst_caps_from_string (input_caps);
|
||||
fail_unless (ptest.src_caps != NULL);
|
||||
}
|
||||
if (output_caps) {
|
||||
ptest.sink_caps = gst_caps_from_string (output_caps);
|
||||
fail_unless (ptest.sink_caps != NULL);
|
||||
}
|
||||
gst_parser_test_run (&ptest, NULL);
|
||||
if (ptest.sink_caps)
|
||||
gst_caps_unref (ptest.sink_caps);
|
||||
if (ptest.src_caps)
|
||||
gst_caps_unref (ptest.src_caps);
|
||||
}
|
||||
|
||||
/*
|
||||
* Test if the src caps are set according to stream format.
|
||||
*/
|
||||
GstCaps *
|
||||
gst_parser_test_get_output_caps (guint8 * data, guint size,
|
||||
const gchar * input_caps)
|
||||
{
|
||||
GstParserTest ptest;
|
||||
GstCaps *out_caps;
|
||||
|
||||
gst_parser_test_init (&ptest, data, size, 10);
|
||||
if (input_caps) {
|
||||
ptest.src_caps = gst_caps_from_string (input_caps);
|
||||
fail_unless (ptest.src_caps != NULL);
|
||||
}
|
||||
gst_parser_test_run (&ptest, &out_caps);
|
||||
if (ptest.src_caps)
|
||||
gst_caps_unref (ptest.src_caps);
|
||||
|
||||
return out_caps;
|
||||
}
|
80
tests/check/elements/parser.h
Normal file
80
tests/check/elements/parser.h
Normal file
|
@ -0,0 +1,80 @@
|
|||
/*
|
||||
* GStreamer
|
||||
*
|
||||
* unit test for (audio) parser
|
||||
*
|
||||
* Copyright (C) 2008 Nokia Corporation. All rights reserved.
|
||||
*
|
||||
* Contact: Stefan Kost <stefan.kost@nokia.com>
|
||||
*
|
||||
* 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>
|
||||
|
||||
/* context state variables; to be set by test using this helper */
|
||||
/* mandatory */
|
||||
extern const gchar *ctx_factory;
|
||||
extern GstStaticPadTemplate *ctx_sink_template;
|
||||
extern GstStaticPadTemplate *ctx_src_template;
|
||||
/* optional */
|
||||
extern GstCaps *ctx_input_caps;
|
||||
extern GstCaps *ctx_output_caps;
|
||||
|
||||
/* no refs taken/kept, all up to caller */
|
||||
typedef struct
|
||||
{
|
||||
const gchar *factory;
|
||||
GstStaticPadTemplate *sink_template;
|
||||
GstStaticPadTemplate *src_template;
|
||||
/* caps that go into element */
|
||||
GstCaps *src_caps;
|
||||
/* optional: output caps to verify */
|
||||
GstCaps *sink_caps;
|
||||
/* series of buffers; middle series considered garbage */
|
||||
struct {
|
||||
/* data and size */
|
||||
guint8 *data;
|
||||
guint size;
|
||||
/* num of frames with above data per buffer */
|
||||
guint fpb;
|
||||
/* num of buffers */
|
||||
guint num;
|
||||
} series[3];
|
||||
/* sigh, weird cases */
|
||||
gboolean framed;
|
||||
guint dropped;
|
||||
} GstParserTest;
|
||||
|
||||
void gst_parser_test_init (GstParserTest * ptest, guint8 * data, guint size, guint num);
|
||||
|
||||
void gst_parser_test_run (GstParserTest * test, GstCaps ** out_caps);
|
||||
|
||||
void gst_parser_test_normal (guint8 *data, guint size);
|
||||
|
||||
void gst_parser_test_drain_single (guint8 *data, guint size);
|
||||
|
||||
void gst_parser_test_drain_garbage (guint8 *data, guint size, guint8 *garbage, guint gsize);
|
||||
|
||||
void gst_parser_test_split (guint8 *data, guint size);
|
||||
|
||||
void gst_parser_test_skip_garbage (guint8 *data, guint size, guint8 *garbage, guint gsize);
|
||||
|
||||
void gst_parser_test_output_caps (guint8 *data, guint size, const gchar * input_caps,
|
||||
const gchar * output_caps);
|
||||
|
||||
GstCaps *gst_parser_test_get_output_caps (guint8 *data, guint size, const gchar * input_caps);
|
||||
|
Loading…
Reference in a new issue