From 7dfb903cb4fbb6fbe1ff8bb3152ff78373b06898 Mon Sep 17 00:00:00 2001 From: Thiago Santos Date: Tue, 8 Oct 2013 16:13:58 -0300 Subject: [PATCH] videotestsrc: improve test for backwards playback Improve test by checking that timestamps are decreasing --- tests/check/elements/videotestsrc.c | 47 ++++++++++++++++++++++++++++++++++++- 1 file changed, 46 insertions(+), 1 deletion(-) diff --git a/tests/check/elements/videotestsrc.c b/tests/check/elements/videotestsrc.c index b15fb14..649d38c 100644 --- a/tests/check/elements/videotestsrc.c +++ b/tests/check/elements/videotestsrc.c @@ -366,6 +366,12 @@ GST_START_TEST (test_rgb_formats) GST_END_TEST; +struct BackwardsPlaybackData +{ + GstClockTime last_ts; + const gchar *error_msg; +}; + static gboolean eos_watch (GstBus * bus, GstMessage * message, GMainLoop * loop) { @@ -375,6 +381,27 @@ eos_watch (GstBus * bus, GstMessage * message, GMainLoop * loop) return TRUE; } +static GstPadProbeReturn +backward_check_probe (GstPad * pad, GstPadProbeInfo * info, gpointer udata) +{ + if (info->type & GST_PAD_PROBE_TYPE_BUFFER) { + GstBuffer *buf = info->data; + struct BackwardsPlaybackData *pdata = udata; + + if (GST_BUFFER_TIMESTAMP_IS_VALID (buf)) { + if (GST_CLOCK_TIME_IS_VALID (pdata->last_ts) && + pdata->last_ts < GST_BUFFER_TIMESTAMP (buf)) { + pdata->error_msg = "Received buffer with increasing timestamp"; + } + pdata->last_ts = GST_BUFFER_TIMESTAMP (buf); + } else { + pdata->error_msg = "Received buffer without timestamp"; + } + + } + return GST_PAD_PROBE_OK; +} + GST_START_TEST (test_backward_playback) { GstBus *bus; @@ -383,8 +410,16 @@ GST_START_TEST (test_backward_playback) GMainLoop *loop; guint bus_watch = 0; GstStateChangeReturn ret; + GstElement *src; + GstPad *pad; + gulong pad_probe; + struct BackwardsPlaybackData pdata; - bin = gst_parse_launch ("videotestsrc ! fakesink name=sink", &error); + pdata.last_ts = GST_CLOCK_TIME_NONE; + pdata.error_msg = NULL; + + bin = gst_parse_launch ("videotestsrc name=src ! fakesink name=sink " + "sync=true", &error); /* run until we receive EOS */ loop = g_main_loop_new (NULL, FALSE); @@ -400,6 +435,11 @@ GST_START_TEST (test_backward_playback) fail_if (ret != GST_STATE_CHANGE_SUCCESS, "Could not start test pipeline"); } + src = gst_bin_get_by_name (GST_BIN (bin), "src"); + pad = gst_element_get_static_pad (src, "src"); + pad_probe = gst_pad_add_probe (pad, GST_PAD_PROBE_TYPE_BUFFER, + (GstPadProbeCallback) backward_check_probe, &pdata, NULL); + gst_element_seek (bin, -1.0, GST_FORMAT_TIME, GST_SEEK_FLAG_ACCURATE | GST_SEEK_FLAG_FLUSH, GST_SEEK_TYPE_SET, 0, GST_SEEK_TYPE_SET, 1 * GST_SECOND); @@ -419,7 +459,12 @@ GST_START_TEST (test_backward_playback) fail_if (ret != GST_STATE_CHANGE_SUCCESS, "Could not stop test pipeline"); } + if (pdata.error_msg) + fail ("%s", pdata.error_msg); + /* clean up */ + gst_pad_remove_probe (pad, pad_probe); + gst_object_unref (pad); g_main_loop_unref (loop); g_source_remove (bus_watch); gst_object_unref (bin); -- 2.7.4