videoflip: add test rotating from tags

Part-of: <https://gitlab.freedesktop.org/gstreamer/gstreamer/-/merge_requests/4377>
This commit is contained in:
Guillaume Desmottes 2023-04-13 11:37:13 +02:00
parent 6c429a5891
commit 61a5da1014

View file

@ -268,6 +268,112 @@ GST_START_TEST (test_stress_change_method)
GST_END_TEST;
// push a buffer to retrieve the new caps from videoflip and check if the frame is rotated or not
static void
caps_update (GstHarness * flip, GstVideoInfo * in_info, gboolean rotate)
{
GstEvent *e;
GstBuffer *buf;
GstCaps *out_caps;
GstVideoInfo out_info;
// push a buffer to get the new caps
buf = create_test_video_buffer_rgba8 (in_info);
fail_unless (gst_harness_push (flip, buf) == GST_FLOW_OK);
e = gst_harness_pull_event (flip);
gst_event_parse_caps (e, &out_caps);
gst_caps_ref (out_caps);
gst_event_unref (e);
buf = gst_harness_pull (flip);
fail_unless (buf != NULL);
gst_buffer_unref (buf);
fail_unless (gst_video_info_from_caps (&out_info, out_caps));
if (rotate) {
fail_unless_equals_int (GST_VIDEO_INFO_WIDTH (in_info),
GST_VIDEO_INFO_HEIGHT (&out_info));
fail_unless_equals_int (GST_VIDEO_INFO_HEIGHT (in_info),
GST_VIDEO_INFO_WIDTH (&out_info));
} else {
fail_unless_equals_int (GST_VIDEO_INFO_WIDTH (in_info),
GST_VIDEO_INFO_WIDTH (&out_info));
fail_unless_equals_int (GST_VIDEO_INFO_HEIGHT (in_info),
GST_VIDEO_INFO_HEIGHT (&out_info));
}
gst_caps_unref (out_caps);
}
static void
send_orientation_tag (GstHarness * flip, const gchar * orientation)
{
GstTagList *tags;
gchar *tmp;
GstEvent *e;
if (orientation) {
tmp = g_strdup_printf ("taglist,image-orientation=%s", orientation);
} else {
tmp = g_strdup ("taglist");
}
tags = gst_tag_list_new_from_string (tmp);
g_free (tmp);
fail_unless (tags != NULL);
gst_harness_push_event (flip, gst_event_new_tag (tags));
e = gst_harness_pull_event (flip);
fail_unless_equals_int (GST_EVENT_TYPE (e), GST_EVENT_TAG);
gst_event_unref (e);
}
// set orientation from tags with videoflip in auto mode
GST_START_TEST (test_orientation_tag)
{
GstHarness *flip = gst_harness_new ("videoflip");
GstVideoInfo in_info, out_info;
GstCaps *in_caps, *out_caps;
GstEvent *e;
g_object_set (flip->element, "video-direction", 8 /* auto */ , NULL);
// downstream accept any resolution
gst_harness_set_sink_caps_str (flip, "video/x-raw");
gst_video_info_set_format (&in_info, GST_VIDEO_FORMAT_RGBA, 4, 9);
in_caps = gst_video_info_to_caps (&in_info);
gst_harness_set_src_caps (flip, in_caps);
e = gst_harness_pull_event (flip);
fail_unless_equals_int (GST_EVENT_TYPE (e), GST_EVENT_STREAM_START);
gst_event_unref (e);
e = gst_harness_pull_event (flip);
fail_unless_equals_int (GST_EVENT_TYPE (e), GST_EVENT_CAPS);
gst_event_parse_caps (e, &out_caps);
fail_unless (gst_video_info_from_caps (&out_info, out_caps));
fail_unless_equals_int (GST_VIDEO_INFO_WIDTH (&in_info),
GST_VIDEO_INFO_WIDTH (&out_info));
fail_unless_equals_int (GST_VIDEO_INFO_HEIGHT (&in_info),
GST_VIDEO_INFO_HEIGHT (&out_info));
gst_event_unref (e);
e = gst_harness_pull_event (flip);
fail_unless_equals_int (GST_EVENT_TYPE (e), GST_EVENT_SEGMENT);
gst_event_unref (e);
send_orientation_tag (flip, "rotate-90");
// caps is updated as the frame is now rotated
caps_update (flip, &in_info, TRUE);
gst_harness_teardown (flip);
}
GST_END_TEST;
static Suite *
videoflip_suite (void)
{
@ -280,6 +386,7 @@ videoflip_suite (void)
tcase_add_test (tc_chain,
test_change_method_twice_same_caps_different_method);
tcase_add_test (tc_chain, test_stress_change_method);
tcase_add_test (tc_chain, test_orientation_tag);
return s;
}