mirror of
https://gitlab.freedesktop.org/gstreamer/gstreamer.git
synced 2024-11-23 10:11:08 +00:00
videotestsrc: implement duration query
Add duration query to videotestsrc, it can answer this query when the num-buffers property is set. https://bugzilla.gnome.org/show_bug.cgi?id=709646
This commit is contained in:
parent
8bcd1a2f8d
commit
c2eb3d4e71
2 changed files with 60 additions and 0 deletions
|
@ -773,6 +773,16 @@ gst_video_test_src_query (GstBaseSrc * bsrc, GstQuery * query)
|
|||
gst_query_set_convert (query, src_fmt, src_val, dest_fmt, dest_val);
|
||||
break;
|
||||
}
|
||||
case GST_QUERY_DURATION:{
|
||||
if (bsrc->num_buffers != -1) {
|
||||
gint64 dur = gst_util_uint64_scale_int_round (bsrc->num_buffers
|
||||
* GST_SECOND, src->info.fps_d, src->info.fps_n);
|
||||
res = TRUE;
|
||||
gst_query_set_duration (query, GST_FORMAT_TIME, dur);
|
||||
break;
|
||||
}
|
||||
/* fall through */
|
||||
}
|
||||
default:
|
||||
res = GST_BASE_SRC_CLASS (parent_class)->query (bsrc, query);
|
||||
break;
|
||||
|
|
|
@ -427,6 +427,55 @@ GST_START_TEST (test_backward_playback)
|
|||
|
||||
GST_END_TEST;
|
||||
|
||||
GST_START_TEST (test_duration_query)
|
||||
{
|
||||
GstElement *bin;
|
||||
GError *error = NULL;
|
||||
GstStateChangeReturn ret;
|
||||
gboolean queryret;
|
||||
gint64 duration = -1;
|
||||
|
||||
bin =
|
||||
gst_parse_launch ("videotestsrc ! fakesink name=sink sync=true", &error);
|
||||
ret = gst_element_set_state (bin, GST_STATE_PAUSED);
|
||||
if (ret == GST_STATE_CHANGE_ASYNC) {
|
||||
ret = gst_element_get_state (bin, NULL, NULL, GST_CLOCK_TIME_NONE);
|
||||
fail_if (ret != GST_STATE_CHANGE_SUCCESS, "Could not start test pipeline");
|
||||
}
|
||||
queryret = gst_element_query_duration (bin, GST_FORMAT_TIME, &duration);
|
||||
/* should have unknown duration */
|
||||
if (queryret && duration != -1) {
|
||||
fail ("Should return false on duration query");
|
||||
}
|
||||
gst_element_set_state (bin, GST_STATE_NULL);
|
||||
gst_object_unref (bin);
|
||||
|
||||
bin = gst_parse_launch ("videotestsrc num-buffers=100 ! capsfilter "
|
||||
"caps=\"video/x-raw,framerate=(fraction)10/1\" ! "
|
||||
"fakesink name=sink sync=true", &error);
|
||||
ret = gst_element_set_state (bin, GST_STATE_PAUSED);
|
||||
if (ret == GST_STATE_CHANGE_ASYNC) {
|
||||
ret = gst_element_get_state (bin, NULL, NULL, GST_CLOCK_TIME_NONE);
|
||||
fail_if (ret != GST_STATE_CHANGE_SUCCESS, "Could not start test pipeline");
|
||||
}
|
||||
queryret = gst_element_query_duration (bin, GST_FORMAT_TIME, &duration);
|
||||
fail_unless (queryret, "Duration should be returned");
|
||||
fail_unless (duration == GST_SECOND * 10, "Expected duration didn't match");
|
||||
|
||||
/* reverse playback should have no impact on duration */
|
||||
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);
|
||||
queryret = gst_element_query_duration (bin, GST_FORMAT_TIME, &duration);
|
||||
fail_unless (queryret, "Duration should be returned");
|
||||
fail_unless (duration == GST_SECOND * 10, "Expected duration didn't match");
|
||||
|
||||
gst_element_set_state (bin, GST_STATE_NULL);
|
||||
gst_object_unref (bin);
|
||||
}
|
||||
|
||||
GST_END_TEST;
|
||||
|
||||
|
||||
/* FIXME: add tests for YUV formats */
|
||||
|
||||
|
@ -448,6 +497,7 @@ videotestsrc_suite (void)
|
|||
tcase_add_test (tc_chain, test_all_patterns);
|
||||
tcase_add_test (tc_chain, test_rgb_formats);
|
||||
tcase_add_test (tc_chain, test_backward_playback);
|
||||
tcase_add_test (tc_chain, test_duration_query);
|
||||
|
||||
return s;
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue