videotestsrc: improve test for backwards playback

Improve test by checking that timestamps are decreasing
This commit is contained in:
Thiago Santos 2013-10-08 16:13:58 -03:00
parent c2eb3d4e71
commit 7dfb903cb4

View file

@ -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);