tests/check/elements/videocrop.c: More tests: check passthrough mode and caps transform in both directions with fixed...

Original commit message from CVS:
* tests/check/elements/videocrop.c: (handoff_cb),
(buffer_probe_cb), (test_caps_transform), (test_passthrough),
(notgst_value_list_get_nth_int), (videocrop_suite):
More tests: check passthrough mode and caps transform in
both directions with fixed values, ranges and lists.
This commit is contained in:
Tim-Philipp Müller 2006-09-03 10:46:17 +00:00
parent acba8c1dbd
commit 27a203a9b0
2 changed files with 327 additions and 0 deletions

View file

@ -1,3 +1,11 @@
2006-09-03 Tim-Philipp Müller <tim at centricular dot net>
* tests/check/elements/videocrop.c: (handoff_cb),
(buffer_probe_cb), (test_caps_transform), (test_passthrough),
(notgst_value_list_get_nth_int), (videocrop_suite):
More tests: check passthrough mode and caps transform in
both directions with fixed values, ranges and lists.
2006-09-02 Tim-Philipp Müller <tim at centricular dot net>
* docs/plugins/Makefile.am:

View file

@ -284,6 +284,323 @@ GST_START_TEST (test_cropping)
GST_END_TEST;
static void
handoff_cb (GstElement * sink, GstBuffer * buf, GstPad * pad,
GstBuffer ** p_buf)
{
gst_buffer_replace (p_buf, buf);
}
static gboolean
buffer_probe_cb (GstPad * pad, GstBuffer * buf, GstBuffer ** p_buf)
{
gst_buffer_replace (p_buf, buf);
return TRUE; /* keep data */
}
GST_START_TEST (test_passthrough)
{
GstStateChangeReturn state_ret;
GstVideoCropTestContext ctx;
GstPad *srcpad;
GstBuffer *gen_buf = NULL; /* buffer generated by videotestsrc */
GstBuffer *buf = NULL;
videocrop_test_cropping_init_context (&ctx);
g_object_set (ctx.src, "num-buffers", 1, NULL);
srcpad = gst_element_get_pad (ctx.src, "src");
fail_unless (srcpad != NULL);
gst_pad_add_buffer_probe (srcpad, G_CALLBACK (buffer_probe_cb), &gen_buf);
gst_object_unref (srcpad);
g_object_set (ctx.crop, "left", 0, "right", 0, "top", 0, "bottom", 0, NULL);
g_object_set (ctx.sink, "signal-handoffs", TRUE, NULL);
g_signal_connect (ctx.sink, "preroll-handoff", G_CALLBACK (handoff_cb), &buf);
state_ret = gst_element_set_state (ctx.pipeline, GST_STATE_PAUSED);
fail_unless (state_ret != GST_STATE_CHANGE_FAILURE,
"couldn't set pipeline to PAUSED state");
state_ret = gst_element_get_state (ctx.pipeline, NULL, NULL, -1);
fail_unless (state_ret == GST_STATE_CHANGE_SUCCESS,
"pipeline failed to go to PAUSED state");
fail_unless (gen_buf != NULL);
fail_unless (buf != NULL);
/* pass through should do nothing */
fail_unless (gen_buf == buf);
videocrop_test_cropping_deinit_context (&ctx);
fail_unless (GST_MINI_OBJECT_REFCOUNT_VALUE (gen_buf) == 2);
gst_buffer_unref (buf);
fail_unless (GST_MINI_OBJECT_REFCOUNT_VALUE (gen_buf) == 1);
gst_buffer_unref (gen_buf);
}
GST_END_TEST;
static gint
notgst_value_list_get_nth_int (const GValue * list_val, guint n)
{
const GValue *v;
fail_unless (GST_VALUE_HOLDS_LIST (list_val));
fail_unless (n < gst_value_list_get_size (list_val));
v = gst_value_list_get_value (list_val, n);
fail_unless (G_VALUE_HOLDS_INT (v));
return g_value_get_int (v);
}
GST_START_TEST (test_caps_transform)
{
GstVideoCropTestContext ctx;
GstBaseTransformClass *klass;
GstBaseTransform *crop;
const GValue *w_val;
const GValue *h_val;
GstCaps *caps, *adj_caps;
videocrop_test_cropping_init_context (&ctx);
crop = GST_BASE_TRANSFORM (ctx.crop);
klass = GST_BASE_TRANSFORM_GET_CLASS (ctx.crop);
fail_unless (klass != NULL);
caps = gst_caps_new_simple ("video/x-raw-yuv",
"format", GST_TYPE_FOURCC, GST_MAKE_FOURCC ('I', '4', '2', '0'),
"framerate", GST_TYPE_FRACTION, 1, 1,
"width", G_TYPE_INT, 200, "height", G_TYPE_INT, 100, NULL);
/* by default, it should be no cropping and hence passthrough */
adj_caps = klass->transform_caps (crop, GST_PAD_SRC, caps);
fail_unless (adj_caps != NULL);
fail_unless (gst_caps_is_equal (adj_caps, caps));
gst_caps_unref (adj_caps);
adj_caps = klass->transform_caps (crop, GST_PAD_SINK, caps);
fail_unless (adj_caps != NULL);
fail_unless (gst_caps_is_equal (adj_caps, caps));
gst_caps_unref (adj_caps);
/* make sure that's still true after changing properties back and forth */
g_object_set (ctx.crop, "left", 1, "right", 3, "top", 5, "bottom", 7, NULL);
g_object_set (ctx.crop, "left", 0, "right", 0, "top", 0, "bottom", 0, NULL);
adj_caps = klass->transform_caps (crop, GST_PAD_SRC, caps);
fail_unless (adj_caps != NULL);
fail_unless (gst_caps_is_equal (adj_caps, caps));
gst_caps_unref (adj_caps);
adj_caps = klass->transform_caps (crop, GST_PAD_SINK, caps);
fail_unless (adj_caps != NULL);
fail_unless (gst_caps_is_equal (adj_caps, caps));
gst_caps_unref (adj_caps);
/* now check adjustments made ... */
g_object_set (ctx.crop, "left", 1, "right", 3, "top", 5, "bottom", 7, NULL);
/* ========= (1) fixed value ============================================= */
/* sink => source, source must be bigger if we crop stuff off */
adj_caps = klass->transform_caps (crop, GST_PAD_SRC, caps);
fail_unless (adj_caps != NULL);
fail_unless (gst_caps_get_size (adj_caps) == 1);
w_val =
gst_structure_get_value (gst_caps_get_structure (adj_caps, 0), "width");
fail_unless (w_val != NULL);
fail_unless (G_VALUE_HOLDS_INT (w_val));
fail_unless_equals_int (g_value_get_int (w_val), 200 + (1 + 3));
h_val =
gst_structure_get_value (gst_caps_get_structure (adj_caps, 0), "height");
fail_unless (h_val != NULL);
fail_unless (G_VALUE_HOLDS_INT (h_val));
fail_unless_equals_int (g_value_get_int (h_val), 100 + (5 + 7));
gst_caps_unref (adj_caps);
/* source => sink becomes smaller */
adj_caps = klass->transform_caps (crop, GST_PAD_SINK, caps);
fail_unless (adj_caps != NULL);
fail_unless (gst_caps_get_size (adj_caps) == 1);
w_val =
gst_structure_get_value (gst_caps_get_structure (adj_caps, 0), "width");
fail_unless (w_val != NULL);
fail_unless (G_VALUE_HOLDS_INT (w_val));
fail_unless_equals_int (g_value_get_int (w_val), 200 - (1 + 3));
h_val =
gst_structure_get_value (gst_caps_get_structure (adj_caps, 0), "height");
fail_unless (h_val != NULL);
fail_unless (G_VALUE_HOLDS_INT (h_val));
fail_unless_equals_int (g_value_get_int (h_val), 100 - (5 + 7));
gst_caps_unref (adj_caps);
/* ========= (2) range (simple adjustment) =============================== */
gst_structure_set (gst_caps_get_structure (caps, 0),
"width", GST_TYPE_INT_RANGE, 1000, 2000,
"height", GST_TYPE_INT_RANGE, 3000, 4000, NULL);
/* sink => source, source must be bigger if we crop stuff off */
adj_caps = klass->transform_caps (crop, GST_PAD_SRC, caps);
fail_unless (adj_caps != NULL);
fail_unless (gst_caps_get_size (adj_caps) == 1);
w_val =
gst_structure_get_value (gst_caps_get_structure (adj_caps, 0), "width");
fail_unless (w_val != NULL);
fail_unless (GST_VALUE_HOLDS_INT_RANGE (w_val));
fail_unless_equals_int (gst_value_get_int_range_min (w_val), 1000 + (1 + 3));
fail_unless_equals_int (gst_value_get_int_range_max (w_val), 2000 + (1 + 3));
h_val =
gst_structure_get_value (gst_caps_get_structure (adj_caps, 0), "height");
fail_unless (h_val != NULL);
fail_unless (GST_VALUE_HOLDS_INT_RANGE (h_val));
fail_unless_equals_int (gst_value_get_int_range_min (h_val), 3000 + (5 + 7));
fail_unless_equals_int (gst_value_get_int_range_max (h_val), 4000 + (5 + 7));
gst_caps_unref (adj_caps);
/* source => sink becomes smaller */
adj_caps = klass->transform_caps (crop, GST_PAD_SINK, caps);
fail_unless (adj_caps != NULL);
fail_unless (gst_caps_get_size (adj_caps) == 1);
w_val =
gst_structure_get_value (gst_caps_get_structure (adj_caps, 0), "width");
fail_unless (w_val != NULL);
fail_unless (GST_VALUE_HOLDS_INT_RANGE (w_val));
fail_unless_equals_int (gst_value_get_int_range_min (w_val), 1000 - (1 + 3));
fail_unless_equals_int (gst_value_get_int_range_max (w_val), 2000 - (1 + 3));
h_val =
gst_structure_get_value (gst_caps_get_structure (adj_caps, 0), "height");
fail_unless (h_val != NULL);
fail_unless (GST_VALUE_HOLDS_INT_RANGE (h_val));
fail_unless_equals_int (gst_value_get_int_range_min (h_val), 3000 - (5 + 7));
fail_unless_equals_int (gst_value_get_int_range_max (h_val), 4000 - (5 + 7));
gst_caps_unref (adj_caps);
/* ========= (3) range (adjustment at boundary) ========================== */
gst_structure_set (gst_caps_get_structure (caps, 0),
"width", GST_TYPE_INT_RANGE, 2, G_MAXINT,
"height", GST_TYPE_INT_RANGE, 2, G_MAXINT, NULL);
/* sink => source, source must be bigger if we crop stuff off */
adj_caps = klass->transform_caps (crop, GST_PAD_SRC, caps);
fail_unless (adj_caps != NULL);
fail_unless (gst_caps_get_size (adj_caps) == 1);
w_val =
gst_structure_get_value (gst_caps_get_structure (adj_caps, 0), "width");
fail_unless (w_val != NULL);
fail_unless (GST_VALUE_HOLDS_INT_RANGE (w_val));
fail_unless_equals_int (gst_value_get_int_range_min (w_val), 2 + (1 + 3));
fail_unless_equals_int (gst_value_get_int_range_max (w_val), G_MAXINT);
h_val =
gst_structure_get_value (gst_caps_get_structure (adj_caps, 0), "height");
fail_unless (h_val != NULL);
fail_unless (GST_VALUE_HOLDS_INT_RANGE (h_val));
fail_unless_equals_int (gst_value_get_int_range_min (h_val), 2 + (5 + 7));
fail_unless_equals_int (gst_value_get_int_range_max (h_val), G_MAXINT);
gst_caps_unref (adj_caps);
/* source => sink becomes smaller */
adj_caps = klass->transform_caps (crop, GST_PAD_SINK, caps);
fail_unless (adj_caps != NULL);
fail_unless (gst_caps_get_size (adj_caps) == 1);
w_val =
gst_structure_get_value (gst_caps_get_structure (adj_caps, 0), "width");
fail_unless (w_val != NULL);
fail_unless (GST_VALUE_HOLDS_INT_RANGE (w_val));
fail_unless_equals_int (gst_value_get_int_range_min (w_val), 1);
fail_unless_equals_int (gst_value_get_int_range_max (w_val),
G_MAXINT - (1 + 3));
h_val =
gst_structure_get_value (gst_caps_get_structure (adj_caps, 0), "height");
fail_unless (h_val != NULL);
fail_unless (GST_VALUE_HOLDS_INT_RANGE (h_val));
fail_unless_equals_int (gst_value_get_int_range_min (h_val), 1);
fail_unless_equals_int (gst_value_get_int_range_max (h_val),
G_MAXINT - (5 + 7));
gst_caps_unref (adj_caps);
/* ========= (4) list of values ========================================== */
{
GValue list = { 0, };
GValue ival = { 0, };
g_value_init (&ival, G_TYPE_INT);
g_value_init (&list, GST_TYPE_LIST);
g_value_set_int (&ival, 2);
gst_value_list_append_value (&list, &ival);
g_value_set_int (&ival, G_MAXINT);
gst_value_list_append_value (&list, &ival);
gst_structure_set_value (gst_caps_get_structure (caps, 0), "width", &list);
g_value_unset (&list);
g_value_unset (&ival);
g_value_init (&ival, G_TYPE_INT);
g_value_init (&list, GST_TYPE_LIST);
g_value_set_int (&ival, 5);
gst_value_list_append_value (&list, &ival);
g_value_set_int (&ival, 1000);
gst_value_list_append_value (&list, &ival);
gst_structure_set_value (gst_caps_get_structure (caps, 0), "height", &list);
g_value_unset (&list);
g_value_unset (&ival);
}
/* sink => source, source must be bigger if we crop stuff off */
adj_caps = klass->transform_caps (crop, GST_PAD_SRC, caps);
fail_unless (adj_caps != NULL);
fail_unless (gst_caps_get_size (adj_caps) == 1);
w_val =
gst_structure_get_value (gst_caps_get_structure (adj_caps, 0), "width");
fail_unless (w_val != NULL);
fail_unless (GST_VALUE_HOLDS_LIST (w_val));
fail_unless_equals_int (notgst_value_list_get_nth_int (w_val, 0),
2 + (1 + 3));
fail_unless_equals_int (notgst_value_list_get_nth_int (w_val, 1), G_MAXINT);
h_val =
gst_structure_get_value (gst_caps_get_structure (adj_caps, 0), "height");
fail_unless (h_val != NULL);
fail_unless (GST_VALUE_HOLDS_LIST (h_val));
fail_unless_equals_int (notgst_value_list_get_nth_int (h_val, 0),
5 + (5 + 7));
fail_unless_equals_int (notgst_value_list_get_nth_int (h_val, 1),
1000 + (5 + 7));
gst_caps_unref (adj_caps);
/* source => sink becomes smaller */
adj_caps = klass->transform_caps (crop, GST_PAD_SINK, caps);
fail_unless (adj_caps != NULL);
fail_unless (gst_caps_get_size (adj_caps) == 1);
w_val =
gst_structure_get_value (gst_caps_get_structure (adj_caps, 0), "width");
fail_unless (w_val != NULL);
fail_unless (GST_VALUE_HOLDS_LIST (w_val));
fail_unless_equals_int (notgst_value_list_get_nth_int (w_val, 0), 1);
fail_unless_equals_int (notgst_value_list_get_nth_int (w_val, 1),
G_MAXINT - (1 + 3));
h_val =
gst_structure_get_value (gst_caps_get_structure (adj_caps, 0), "height");
fail_unless (h_val != NULL);
fail_unless (GST_VALUE_HOLDS_LIST (h_val));
fail_unless_equals_int (notgst_value_list_get_nth_int (h_val, 0), 1);
fail_unless_equals_int (notgst_value_list_get_nth_int (h_val, 1),
1000 - (5 + 7));
gst_caps_unref (adj_caps);
gst_caps_unref (caps);
videocrop_test_cropping_deinit_context (&ctx);
}
GST_END_TEST;
static Suite *
videocrop_suite (void)
{
@ -306,6 +623,8 @@ videocrop_suite (void)
}
suite_add_tcase (s, tc_chain);
tcase_add_test (tc_chain, test_caps_transform);
tcase_add_test (tc_chain, test_passthrough);
tcase_add_test (tc_chain, test_unit_sizes);
tcase_add_test (tc_chain, test_cropping);