mirror of
https://gitlab.freedesktop.org/gstreamer/gstreamer.git
synced 2024-12-18 14:26:43 +00:00
tests: videodecoder: add check for serialization of events
Tests that events are properly serialized with buffers, also checks that the usual events are sent (stream start, caps, segment and eos).
This commit is contained in:
parent
27530a0196
commit
c564d5b2c9
1 changed files with 154 additions and 12 deletions
|
@ -29,6 +29,7 @@
|
||||||
|
|
||||||
static GstPad *mysrcpad, *mysinkpad;
|
static GstPad *mysrcpad, *mysinkpad;
|
||||||
static GstElement *dec;
|
static GstElement *dec;
|
||||||
|
static GList *events = NULL;
|
||||||
|
|
||||||
#define TEST_VIDEO_WIDTH 640
|
#define TEST_VIDEO_WIDTH 640
|
||||||
#define TEST_VIDEO_HEIGHT 480
|
#define TEST_VIDEO_HEIGHT 480
|
||||||
|
@ -133,6 +134,13 @@ gst_video_decoder_tester_init (GstVideoDecoderTester * tester)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static gboolean
|
||||||
|
_mysinkpad_event (GstPad * pad, GstObject * parent, GstEvent * event)
|
||||||
|
{
|
||||||
|
events = g_list_append (events, event);
|
||||||
|
return TRUE;
|
||||||
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
setup_videodecodertester (void)
|
setup_videodecodertester (void)
|
||||||
{
|
{
|
||||||
|
@ -150,6 +158,8 @@ setup_videodecodertester (void)
|
||||||
dec = g_object_new (GST_VIDEO_DECODER_TESTER_TYPE, NULL);
|
dec = g_object_new (GST_VIDEO_DECODER_TESTER_TYPE, NULL);
|
||||||
mysrcpad = gst_check_setup_src_pad (dec, &srctemplate);
|
mysrcpad = gst_check_setup_src_pad (dec, &srctemplate);
|
||||||
mysinkpad = gst_check_setup_sink_pad (dec, &sinktemplate);
|
mysinkpad = gst_check_setup_sink_pad (dec, &sinktemplate);
|
||||||
|
|
||||||
|
gst_pad_set_event_function (mysinkpad, _mysinkpad_event);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
|
@ -162,20 +172,10 @@ cleanup_videodecodertest (void)
|
||||||
gst_check_teardown_element (dec);
|
gst_check_teardown_element (dec);
|
||||||
}
|
}
|
||||||
|
|
||||||
#define NUM_BUFFERS 1000
|
static void
|
||||||
GST_START_TEST (videodecoder_playback)
|
send_startup_events (void)
|
||||||
{
|
{
|
||||||
GstSegment segment;
|
|
||||||
GstCaps *caps;
|
GstCaps *caps;
|
||||||
GstBuffer *buffer;
|
|
||||||
guint64 i;
|
|
||||||
GList *iter;
|
|
||||||
|
|
||||||
setup_videodecodertester ();
|
|
||||||
|
|
||||||
gst_pad_set_active (mysrcpad, TRUE);
|
|
||||||
gst_element_set_state (dec, GST_STATE_PLAYING);
|
|
||||||
gst_pad_set_active (mysinkpad, TRUE);
|
|
||||||
|
|
||||||
fail_unless (gst_pad_push_event (mysrcpad,
|
fail_unless (gst_pad_push_event (mysrcpad,
|
||||||
gst_event_new_stream_start ("randomvalue")));
|
gst_event_new_stream_start ("randomvalue")));
|
||||||
|
@ -187,6 +187,24 @@ GST_START_TEST (videodecoder_playback)
|
||||||
GST_TYPE_FRACTION, TEST_VIDEO_FPS_N, TEST_VIDEO_FPS_D, NULL);
|
GST_TYPE_FRACTION, TEST_VIDEO_FPS_N, TEST_VIDEO_FPS_D, NULL);
|
||||||
fail_unless (gst_pad_push_event (mysrcpad, gst_event_new_caps (caps)));
|
fail_unless (gst_pad_push_event (mysrcpad, gst_event_new_caps (caps)));
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
#define NUM_BUFFERS 1000
|
||||||
|
GST_START_TEST (videodecoder_playback)
|
||||||
|
{
|
||||||
|
GstSegment segment;
|
||||||
|
GstBuffer *buffer;
|
||||||
|
guint64 i;
|
||||||
|
GList *iter;
|
||||||
|
|
||||||
|
setup_videodecodertester ();
|
||||||
|
|
||||||
|
gst_pad_set_active (mysrcpad, TRUE);
|
||||||
|
gst_element_set_state (dec, GST_STATE_PLAYING);
|
||||||
|
gst_pad_set_active (mysinkpad, TRUE);
|
||||||
|
|
||||||
|
send_startup_events ();
|
||||||
|
|
||||||
/* push a new segment */
|
/* push a new segment */
|
||||||
gst_segment_init (&segment, GST_FORMAT_TIME);
|
gst_segment_init (&segment, GST_FORMAT_TIME);
|
||||||
fail_unless (gst_pad_push_event (mysrcpad, gst_event_new_segment (&segment)));
|
fail_unless (gst_pad_push_event (mysrcpad, gst_event_new_segment (&segment)));
|
||||||
|
@ -243,6 +261,129 @@ GST_START_TEST (videodecoder_playback)
|
||||||
|
|
||||||
GST_END_TEST;
|
GST_END_TEST;
|
||||||
|
|
||||||
|
|
||||||
|
GST_START_TEST (videodecoder_playback_with_events)
|
||||||
|
{
|
||||||
|
GstSegment segment;
|
||||||
|
GstBuffer *buffer;
|
||||||
|
guint64 i;
|
||||||
|
GList *iter;
|
||||||
|
GList *events_iter;
|
||||||
|
|
||||||
|
setup_videodecodertester ();
|
||||||
|
|
||||||
|
gst_pad_set_active (mysrcpad, TRUE);
|
||||||
|
gst_element_set_state (dec, GST_STATE_PLAYING);
|
||||||
|
gst_pad_set_active (mysinkpad, TRUE);
|
||||||
|
|
||||||
|
send_startup_events ();
|
||||||
|
|
||||||
|
/* push a new segment */
|
||||||
|
gst_segment_init (&segment, GST_FORMAT_TIME);
|
||||||
|
fail_unless (gst_pad_push_event (mysrcpad, gst_event_new_segment (&segment)));
|
||||||
|
|
||||||
|
/* push buffers, the data is actually a number so we can track them */
|
||||||
|
for (i = 0; i < NUM_BUFFERS; i++) {
|
||||||
|
if (i % 10 == 0) {
|
||||||
|
GstTagList *tags;
|
||||||
|
|
||||||
|
tags = gst_tag_list_new (GST_TAG_TRACK_NUMBER, i, NULL);
|
||||||
|
fail_unless (gst_pad_push_event (mysrcpad, gst_event_new_tag (tags)));
|
||||||
|
} else {
|
||||||
|
guint64 *data = g_malloc (sizeof (guint64));
|
||||||
|
|
||||||
|
*data = i;
|
||||||
|
|
||||||
|
buffer = gst_buffer_new_wrapped (data, sizeof (guint64));
|
||||||
|
|
||||||
|
GST_BUFFER_PTS (buffer) =
|
||||||
|
gst_util_uint64_scale_round (i, GST_SECOND * TEST_VIDEO_FPS_D,
|
||||||
|
TEST_VIDEO_FPS_N);
|
||||||
|
GST_BUFFER_DURATION (buffer) =
|
||||||
|
gst_util_uint64_scale_round (GST_SECOND, TEST_VIDEO_FPS_D,
|
||||||
|
TEST_VIDEO_FPS_N);
|
||||||
|
|
||||||
|
fail_unless (gst_pad_push (mysrcpad, buffer) == GST_FLOW_OK);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fail_unless (gst_pad_push_event (mysrcpad, gst_event_new_eos ()));
|
||||||
|
|
||||||
|
events_iter = events;
|
||||||
|
/* make sure the usual events have been received */
|
||||||
|
{
|
||||||
|
GstEvent *sstart = events_iter->data;
|
||||||
|
fail_unless (GST_EVENT_TYPE (sstart) == GST_EVENT_STREAM_START);
|
||||||
|
events_iter = g_list_next (events_iter);
|
||||||
|
}
|
||||||
|
{
|
||||||
|
GstEvent *caps_event = events_iter->data;
|
||||||
|
fail_unless (GST_EVENT_TYPE (caps_event) == GST_EVENT_CAPS);
|
||||||
|
events_iter = g_list_next (events_iter);
|
||||||
|
}
|
||||||
|
{
|
||||||
|
GstEvent *segment_event = events_iter->data;
|
||||||
|
fail_unless (GST_EVENT_TYPE (segment_event) == GST_EVENT_SEGMENT);
|
||||||
|
events_iter = g_list_next (events_iter);
|
||||||
|
}
|
||||||
|
|
||||||
|
/* check that all buffers were received by our source pad */
|
||||||
|
iter = buffers;
|
||||||
|
for (i = 0; i < NUM_BUFFERS; i++) {
|
||||||
|
if (i % 10 == 0) {
|
||||||
|
guint tag_v;
|
||||||
|
GstEvent *tag_event = events_iter->data;
|
||||||
|
GstTagList *taglist = NULL;
|
||||||
|
|
||||||
|
gst_event_parse_tag (tag_event, &taglist);
|
||||||
|
|
||||||
|
fail_unless (gst_tag_list_get_uint (taglist, GST_TAG_TRACK_NUMBER,
|
||||||
|
&tag_v));
|
||||||
|
fail_unless (tag_v == i);
|
||||||
|
|
||||||
|
events_iter = g_list_next (events_iter);
|
||||||
|
} else {
|
||||||
|
GstMapInfo map;
|
||||||
|
guint64 num;
|
||||||
|
|
||||||
|
buffer = iter->data;
|
||||||
|
|
||||||
|
gst_buffer_map (buffer, &map, GST_MAP_READ);
|
||||||
|
|
||||||
|
num = *(guint64 *) map.data;
|
||||||
|
fail_unless (i == num);
|
||||||
|
fail_unless (GST_BUFFER_PTS (buffer) == gst_util_uint64_scale_round (i,
|
||||||
|
GST_SECOND * TEST_VIDEO_FPS_D, TEST_VIDEO_FPS_N));
|
||||||
|
fail_unless (GST_BUFFER_DURATION (buffer) ==
|
||||||
|
gst_util_uint64_scale_round (GST_SECOND, TEST_VIDEO_FPS_D,
|
||||||
|
TEST_VIDEO_FPS_N));
|
||||||
|
|
||||||
|
gst_buffer_unmap (buffer, &map);
|
||||||
|
iter = g_list_next (iter);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
fail_unless (iter == NULL);
|
||||||
|
|
||||||
|
/* check that EOS was received */
|
||||||
|
{
|
||||||
|
GstEvent *eos = events_iter->data;
|
||||||
|
|
||||||
|
fail_unless (GST_EVENT_TYPE (eos) == GST_EVENT_EOS);
|
||||||
|
events_iter = g_list_next (events_iter);
|
||||||
|
}
|
||||||
|
|
||||||
|
fail_unless (events_iter == NULL);
|
||||||
|
|
||||||
|
g_list_free_full (buffers, (GDestroyNotify) gst_buffer_unref);
|
||||||
|
g_list_free_full (events, (GDestroyNotify) gst_event_unref);
|
||||||
|
buffers = NULL;
|
||||||
|
events = NULL;
|
||||||
|
|
||||||
|
cleanup_videodecodertest ();
|
||||||
|
}
|
||||||
|
|
||||||
|
GST_END_TEST;
|
||||||
|
|
||||||
static Suite *
|
static Suite *
|
||||||
gst_videodecoder_suite (void)
|
gst_videodecoder_suite (void)
|
||||||
{
|
{
|
||||||
|
@ -251,6 +392,7 @@ gst_videodecoder_suite (void)
|
||||||
|
|
||||||
suite_add_tcase (s, tc);
|
suite_add_tcase (s, tc);
|
||||||
tcase_add_test (tc, videodecoder_playback);
|
tcase_add_test (tc, videodecoder_playback);
|
||||||
|
tcase_add_test (tc, videodecoder_playback_with_events);
|
||||||
|
|
||||||
return s;
|
return s;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue