1 /* GStreamer unit test for the videocrop element
2 * Copyright (C) 2006 Tim-Philipp Müller <tim centricular net>
4 * This library is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Library General Public
6 * License as published by the Free Software Foundation; either
7 * version 2 of the License, or (at your option) any later version.
9 * This library is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * Library General Public License for more details.
14 * You should have received a copy of the GNU Library General Public
15 * License along with this library; if not, write to the
16 * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
17 * Boston, MA 02111-1307, USA.
25 # include <valgrind/valgrind.h>
30 #include <gst/check/gstcheck.h>
31 #include <gst/video/video.h>
32 #include <gst/base/gstbasetransform.h>
34 /* return a list of caps where we only need to set
35 * width and height to get fixed caps */
37 video_crop_get_test_caps (GstElement * videocrop)
39 GstCaps *templ, *allowed_caps;
44 srcpad = gst_element_get_static_pad (videocrop, "src");
45 fail_unless (srcpad != NULL);
46 templ = gst_pad_get_pad_template_caps (srcpad);
47 fail_unless (templ != NULL);
49 allowed_caps = gst_caps_normalize (templ);
51 for (i = 0; i < gst_caps_get_size (allowed_caps); ++i) {
52 GstStructure *new_structure;
55 single_caps = gst_caps_new_empty ();
57 gst_structure_copy (gst_caps_get_structure (allowed_caps, i));
58 gst_structure_set (new_structure, "framerate", GST_TYPE_FRACTION,
60 gst_structure_remove_field (new_structure, "width");
61 gst_structure_remove_field (new_structure, "height");
62 gst_caps_append_structure (single_caps, new_structure);
64 GST_DEBUG ("have caps %" GST_PTR_FORMAT, single_caps);
65 /* should be fixed without width/height */
66 fail_unless (gst_caps_is_fixed (single_caps));
68 list = g_list_prepend (list, single_caps);
71 gst_caps_unref (allowed_caps);
72 gst_object_unref (srcpad);
77 GST_START_TEST (test_unit_sizes)
79 GstBaseTransformClass *csp_klass, *vcrop_klass;
80 GstElement *videocrop, *csp;
83 videocrop = gst_element_factory_make ("videocrop", "videocrop");
84 fail_unless (videocrop != NULL, "Failed to create videocrop element");
85 vcrop_klass = GST_BASE_TRANSFORM_GET_CLASS (videocrop);
87 csp = gst_element_factory_make ("videoconvert", "csp");
88 fail_unless (csp != NULL, "Failed to create videoconvert element");
89 csp_klass = GST_BASE_TRANSFORM_GET_CLASS (csp);
91 caps_list = video_crop_get_test_caps (videocrop);
93 for (l = caps_list; l != NULL; l = l->next) {
112 caps = gst_caps_copy (GST_CAPS (l->data));
113 s = gst_caps_get_structure (caps, 0);
114 fail_unless (s != NULL);
116 for (i = 0; i < G_N_ELEMENTS (sizes_to_try); ++i) {
121 gst_structure_set (s, "width", G_TYPE_INT, sizes_to_try[i].width,
122 "height", G_TYPE_INT, sizes_to_try[i].height, NULL);
124 caps_str = gst_caps_to_string (caps);
125 GST_INFO ("Testing unit size for %s", caps_str);
127 /* skip if videoconvert doesn't support these caps
128 * (only works with gst-plugins-base 0.10.9.1 or later) */
129 if (!csp_klass->get_unit_size ((GstBaseTransform *) csp, caps, &csp_size)) {
130 GST_INFO ("videoconvert does not support format %s", caps_str);
135 fail_unless (vcrop_klass->get_unit_size ((GstBaseTransform *) videocrop,
138 fail_unless (vc_size == csp_size,
139 "videocrop and videoconvert return different unit sizes for "
140 "caps %s: vc_size=%d, csp_size=%d", caps_str, vc_size, csp_size);
145 gst_caps_unref (caps);
148 g_list_foreach (caps_list, (GFunc) gst_caps_unref, NULL);
149 g_list_free (caps_list);
151 gst_object_unref (csp);
152 gst_object_unref (videocrop);
159 GstElement *pipeline;
166 } GstVideoCropTestContext;
169 handoff_cb (GstElement * sink, GstBuffer * buf, GstPad * pad,
170 GstVideoCropTestContext * ctx)
174 gst_buffer_replace (&ctx->last_buf, buf);
175 caps = gst_pad_get_current_caps (pad);
176 gst_caps_replace (&ctx->last_caps, caps);
177 gst_caps_unref (caps);
181 videocrop_test_cropping_init_context (GstVideoCropTestContext * ctx)
183 fail_unless (ctx != NULL);
185 ctx->pipeline = gst_pipeline_new ("pipeline");
186 fail_unless (ctx->pipeline != NULL);
187 ctx->src = gst_element_factory_make ("videotestsrc", "src");
188 fail_unless (ctx->src != NULL, "Failed to create videotestsrc element");
189 ctx->filter = gst_element_factory_make ("capsfilter", "filter");
190 fail_unless (ctx->filter != NULL, "Failed to create capsfilter element");
191 ctx->crop = gst_element_factory_make ("videocrop", "crop");
192 fail_unless (ctx->crop != NULL, "Failed to create videocrop element");
193 ctx->sink = gst_element_factory_make ("fakesink", "sink");
194 fail_unless (ctx->sink != NULL, "Failed to create fakesink element");
196 gst_bin_add_many (GST_BIN (ctx->pipeline), ctx->src, ctx->filter,
197 ctx->crop, ctx->sink, NULL);
198 gst_element_link_many (ctx->src, ctx->filter, ctx->crop, ctx->sink, NULL);
200 /* set pattern to 'red' - for our purposes it doesn't matter anyway */
201 g_object_set (ctx->src, "pattern", 4, NULL);
203 g_object_set (ctx->sink, "signal-handoffs", TRUE, NULL);
204 g_signal_connect (ctx->sink, "preroll-handoff", G_CALLBACK (handoff_cb), ctx);
206 ctx->last_buf = NULL;
207 ctx->last_caps = NULL;
209 GST_LOG ("context inited");
213 videocrop_test_cropping_deinit_context (GstVideoCropTestContext * ctx)
215 GST_LOG ("deiniting context");
217 gst_element_set_state (ctx->pipeline, GST_STATE_NULL);
218 gst_object_unref (ctx->pipeline);
219 gst_buffer_replace (&ctx->last_buf, NULL);
220 gst_caps_replace (&ctx->last_caps, NULL);
221 memset (ctx, 0x00, sizeof (GstVideoCropTestContext));
224 typedef void (*GstVideoCropTestBufferFunc) (GstBuffer * buffer, GstCaps * caps);
227 videocrop_test_cropping (GstVideoCropTestContext * ctx, GstCaps * in_caps,
228 gint left, gint right, gint top, gint bottom,
229 GstVideoCropTestBufferFunc func)
231 GST_LOG ("lrtb = %03u %03u %03u %03u, caps = %" GST_PTR_FORMAT, left, right,
232 top, bottom, in_caps);
234 g_object_set (ctx->filter, "caps", in_caps, NULL);
236 g_object_set (ctx->crop, "left", left, "right", right, "top", top,
237 "bottom", bottom, NULL);
239 /* this will fail if videotestsrc doesn't support our format; we need
240 * videotestsrc from -base CVS 0.10.9.1 with RGBA and AYUV support */
241 fail_unless (gst_element_set_state (ctx->pipeline,
242 GST_STATE_PAUSED) != GST_STATE_CHANGE_FAILURE);
243 fail_unless (gst_element_get_state (ctx->pipeline, NULL, NULL,
244 -1) == GST_STATE_CHANGE_SUCCESS);
247 func (ctx->last_buf, ctx->last_caps);
250 gst_element_set_state (ctx->pipeline, GST_STATE_NULL);
254 check_1x1_buffer (GstBuffer * buf, GstCaps * caps)
258 /* the exact values we check for come from videotestsrc */
259 static const guint yuv_values[] = { 81, 90, 240, 255 };
260 static const guint rgb_values[] = { 0xff, 0, 0, 255 };
261 static const guint gray_values[] = { 63, 63, 63, 255 };
264 const GstVideoFormatInfo *finfo;
266 fail_unless (buf != NULL);
267 fail_unless (caps != NULL);
269 fail_unless (gst_video_info_from_caps (&info, caps));
270 fail_unless (gst_video_frame_map (&frame, &info, buf, GST_MAP_READ));
275 if (GST_VIDEO_INFO_FORMAT (&info) == GST_VIDEO_FORMAT_Y800)
276 values = gray_values;
277 else if (GST_VIDEO_INFO_IS_YUV (&info))
279 else if (GST_VIDEO_INFO_IS_GRAY (&info))
280 values = gray_values;
284 GST_MEMDUMP ("buffer", GST_VIDEO_FRAME_PLANE_DATA (&frame, 0), 8);
286 for (i = 0; i < GST_VIDEO_FRAME_N_COMPONENTS (&frame); i++) {
287 guint8 *data = GST_VIDEO_FRAME_COMP_DATA (&frame, i);
289 GST_DEBUG ("W: %d", GST_VIDEO_FORMAT_INFO_W_SUB (finfo, i));
290 GST_DEBUG ("H: %d", GST_VIDEO_FORMAT_INFO_H_SUB (finfo, i));
292 if (GST_VIDEO_FORMAT_INFO_W_SUB (finfo,
293 i) >= GST_VIDEO_FRAME_WIDTH (&frame))
295 if (GST_VIDEO_FORMAT_INFO_H_SUB (finfo,
296 i) >= GST_VIDEO_FRAME_HEIGHT (&frame))
299 if (GST_VIDEO_FORMAT_INFO_BITS (finfo) == 8) {
300 fail_unless_equals_int (data[0], values[i]);
301 } else if (GST_VIDEO_FORMAT_INFO_BITS (finfo) == 16) {
305 if (GST_VIDEO_FORMAT_INFO_IS_LE (finfo))
306 pixels = GST_READ_UINT16_LE (data);
308 pixels = GST_READ_UINT16_BE (data);
310 depth = GST_VIDEO_FORMAT_INFO_DEPTH (finfo, i);
311 val = pixels >> GST_VIDEO_FORMAT_INFO_SHIFT (finfo, i);
312 val = val & ((1 << depth) - 1);
314 GST_DEBUG ("val %08x %d : %d", pixels, i, val);
315 fail_unless_equals_int (val, values[i] >> (8 - depth));
320 gst_video_frame_unmap (&frame);
323 fail_unless_equals_int ((pixel & rmask) >> rshift, 0xff);
324 fail_unless_equals_int ((pixel & gmask) >> gshift, 0x00);
325 fail_unless_equals_int ((pixel & bmask) >> bshift, 0x00);
329 GST_START_TEST (test_crop_to_1x1)
331 GstVideoCropTestContext ctx;
332 GList *caps_list, *node;
334 videocrop_test_cropping_init_context (&ctx);
336 caps_list = video_crop_get_test_caps (ctx.crop);
338 for (node = caps_list; node != NULL; node = node->next) {
342 caps = gst_caps_copy (GST_CAPS (node->data));
343 s = gst_caps_get_structure (caps, 0);
344 fail_unless (s != NULL);
346 GST_INFO ("testing format: %" GST_PTR_FORMAT, caps);
348 gst_structure_set (s, "width", G_TYPE_INT, 160,
349 "height", G_TYPE_INT, 160, NULL);
351 videocrop_test_cropping (&ctx, caps, 159, 0, 159, 0, check_1x1_buffer);
352 /* commented out because they don't really add anything useful check-wise:
353 videocrop_test_cropping (&ctx, caps, 0, 159, 0, 159, check_1x1_buffer);
354 videocrop_test_cropping (&ctx, caps, 159, 0, 0, 159, check_1x1_buffer);
355 videocrop_test_cropping (&ctx, caps, 0, 159, 159, 0, check_1x1_buffer);
357 gst_caps_unref (caps);
359 g_list_foreach (caps_list, (GFunc) gst_caps_unref, NULL);
360 g_list_free (caps_list);
362 videocrop_test_cropping_deinit_context (&ctx);
367 GST_START_TEST (test_cropping)
369 GstVideoCropTestContext ctx;
384 GList *caps_list, *node;
387 videocrop_test_cropping_init_context (&ctx);
389 caps_list = video_crop_get_test_caps (ctx.crop);
390 node = g_list_nth (caps_list, __i__);
396 caps = gst_caps_copy (GST_CAPS (node->data));
397 s = gst_caps_get_structure (caps, 0);
398 fail_unless (s != NULL);
400 GST_INFO ("testing format: %" GST_PTR_FORMAT, caps);
402 for (i = 0; i < G_N_ELEMENTS (sizes_to_try); ++i) {
405 GST_INFO (" - %d x %d", sizes_to_try[i].width, sizes_to_try[i].height);
407 gst_structure_set (s, "width", G_TYPE_INT, sizes_to_try[i].width,
408 "height", G_TYPE_INT, sizes_to_try[i].height, NULL);
409 in_caps = gst_caps_copy (caps);
411 videocrop_test_cropping (&ctx, in_caps, 0, 0, 0, 0, NULL);
412 videocrop_test_cropping (&ctx, in_caps, 1, 0, 0, 0, NULL);
413 videocrop_test_cropping (&ctx, in_caps, 0, 1, 0, 0, NULL);
414 videocrop_test_cropping (&ctx, in_caps, 0, 0, 1, 0, NULL);
415 videocrop_test_cropping (&ctx, in_caps, 0, 0, 0, 1, NULL);
416 videocrop_test_cropping (&ctx, in_caps, 63, 0, 0, 0, NULL);
417 videocrop_test_cropping (&ctx, in_caps, 0, 63, 0, 0, NULL);
418 videocrop_test_cropping (&ctx, in_caps, 0, 0, 63, 0, NULL);
419 videocrop_test_cropping (&ctx, in_caps, 0, 0, 0, 63, NULL);
420 videocrop_test_cropping (&ctx, in_caps, 63, 0, 0, 1, NULL);
421 videocrop_test_cropping (&ctx, in_caps, 0, 63, 1, 0, NULL);
422 videocrop_test_cropping (&ctx, in_caps, 0, 1, 63, 0, NULL);
423 videocrop_test_cropping (&ctx, in_caps, 1, 0, 0, 63, NULL);
424 videocrop_test_cropping (&ctx, in_caps, 0, 0, 0, 0, NULL);
425 videocrop_test_cropping (&ctx, in_caps, 32, 0, 0, 128, NULL);
426 videocrop_test_cropping (&ctx, in_caps, 0, 32, 128, 0, NULL);
427 videocrop_test_cropping (&ctx, in_caps, 0, 128, 32, 0, NULL);
428 videocrop_test_cropping (&ctx, in_caps, 128, 0, 0, 32, NULL);
429 videocrop_test_cropping (&ctx, in_caps, 1, 1, 1, 1, NULL);
430 videocrop_test_cropping (&ctx, in_caps, 63, 63, 63, 63, NULL);
431 videocrop_test_cropping (&ctx, in_caps, 64, 64, 64, 64, NULL);
433 gst_caps_unref (in_caps);
436 gst_caps_unref (caps);
438 GST_INFO ("no caps #%d", __i__);
440 g_list_foreach (caps_list, (GFunc) gst_caps_unref, NULL);
441 g_list_free (caps_list);
443 videocrop_test_cropping_deinit_context (&ctx);
449 static GstPadProbeReturn
450 buffer_probe_cb (GstPad * pad, GstPadProbeInfo * info, gpointer data)
452 GstBuffer **p_buf = data;
453 GstBuffer *buf = GST_PAD_PROBE_INFO_BUFFER (info);
455 gst_buffer_replace (p_buf, buf);
457 return GST_PAD_PROBE_OK; /* keep data */
460 GST_START_TEST (test_passthrough)
462 GstStateChangeReturn state_ret;
463 GstVideoCropTestContext ctx;
465 GstBuffer *gen_buf = NULL; /* buffer generated by videotestsrc */
467 videocrop_test_cropping_init_context (&ctx);
469 g_object_set (ctx.src, "num-buffers", 1, NULL);
471 srcpad = gst_element_get_static_pad (ctx.src, "src");
472 fail_unless (srcpad != NULL);
473 gst_pad_add_probe (srcpad, GST_PAD_PROBE_TYPE_BUFFER, buffer_probe_cb,
475 gst_object_unref (srcpad);
477 g_object_set (ctx.crop, "left", 0, "right", 0, "top", 0, "bottom", 0, NULL);
479 state_ret = gst_element_set_state (ctx.pipeline, GST_STATE_PAUSED);
480 fail_unless (state_ret != GST_STATE_CHANGE_FAILURE,
481 "couldn't set pipeline to PAUSED state");
483 state_ret = gst_element_get_state (ctx.pipeline, NULL, NULL, -1);
484 fail_unless (state_ret == GST_STATE_CHANGE_SUCCESS,
485 "pipeline failed to go to PAUSED state");
487 fail_unless (gen_buf != NULL);
488 fail_unless (ctx.last_buf != NULL);
490 /* pass through should do nothing */
491 fail_unless (gen_buf == ctx.last_buf);
493 videocrop_test_cropping_deinit_context (&ctx);
495 fail_unless_equals_int (GST_MINI_OBJECT_REFCOUNT_VALUE (gen_buf), 1);
496 gst_buffer_unref (gen_buf);
502 notgst_value_list_get_nth_int (const GValue * list_val, guint n)
506 fail_unless (GST_VALUE_HOLDS_LIST (list_val));
507 fail_unless (n < gst_value_list_get_size (list_val));
509 v = gst_value_list_get_value (list_val, n);
510 fail_unless (G_VALUE_HOLDS_INT (v));
511 return g_value_get_int (v);
514 GST_START_TEST (test_caps_transform)
516 GstVideoCropTestContext ctx;
517 GstBaseTransformClass *klass;
518 GstBaseTransform *crop;
521 GstCaps *caps, *adj_caps;
523 videocrop_test_cropping_init_context (&ctx);
525 crop = GST_BASE_TRANSFORM (ctx.crop);
526 klass = GST_BASE_TRANSFORM_GET_CLASS (ctx.crop);
527 fail_unless (klass != NULL);
529 caps = gst_caps_new_simple ("video/x-raw",
530 "format", G_TYPE_STRING, "I420",
531 "framerate", GST_TYPE_FRACTION, 1, 1,
532 "width", G_TYPE_INT, 200, "height", G_TYPE_INT, 100, NULL);
534 /* by default, it should be no cropping and hence passthrough */
535 adj_caps = klass->transform_caps (crop, GST_PAD_SRC, caps, NULL);
536 fail_unless (adj_caps != NULL);
537 fail_unless (gst_caps_is_equal (adj_caps, caps));
538 gst_caps_unref (adj_caps);
540 adj_caps = klass->transform_caps (crop, GST_PAD_SINK, caps, NULL);
541 fail_unless (adj_caps != NULL);
542 fail_unless (gst_caps_is_equal (adj_caps, caps));
543 gst_caps_unref (adj_caps);
545 /* make sure that's still true after changing properties back and forth */
546 g_object_set (ctx.crop, "left", 1, "right", 3, "top", 5, "bottom", 7, NULL);
547 g_object_set (ctx.crop, "left", 0, "right", 0, "top", 0, "bottom", 0, NULL);
549 adj_caps = klass->transform_caps (crop, GST_PAD_SRC, caps, NULL);
550 fail_unless (adj_caps != NULL);
551 fail_unless (gst_caps_is_equal (adj_caps, caps));
552 gst_caps_unref (adj_caps);
554 adj_caps = klass->transform_caps (crop, GST_PAD_SINK, caps, NULL);
555 fail_unless (adj_caps != NULL);
556 fail_unless (gst_caps_is_equal (adj_caps, caps));
557 gst_caps_unref (adj_caps);
559 /* now check adjustments made ... */
560 g_object_set (ctx.crop, "left", 1, "right", 3, "top", 5, "bottom", 7, NULL);
562 /* ========= (1) fixed value ============================================= */
564 /* sink => source, source must be bigger if we crop stuff off */
565 adj_caps = klass->transform_caps (crop, GST_PAD_SRC, caps, NULL);
566 fail_unless (adj_caps != NULL);
567 fail_unless (gst_caps_get_size (adj_caps) == 1);
569 gst_structure_get_value (gst_caps_get_structure (adj_caps, 0), "width");
570 fail_unless (w_val != NULL);
571 fail_unless (G_VALUE_HOLDS_INT (w_val));
572 fail_unless_equals_int (g_value_get_int (w_val), 200 + (1 + 3));
574 gst_structure_get_value (gst_caps_get_structure (adj_caps, 0), "height");
575 fail_unless (h_val != NULL);
576 fail_unless (G_VALUE_HOLDS_INT (h_val));
577 fail_unless_equals_int (g_value_get_int (h_val), 100 + (5 + 7));
578 gst_caps_unref (adj_caps);
580 /* source => sink becomes smaller */
581 adj_caps = klass->transform_caps (crop, GST_PAD_SINK, caps, NULL);
582 fail_unless (adj_caps != NULL);
583 fail_unless (gst_caps_get_size (adj_caps) == 1);
585 gst_structure_get_value (gst_caps_get_structure (adj_caps, 0), "width");
586 fail_unless (w_val != NULL);
587 fail_unless (G_VALUE_HOLDS_INT (w_val));
588 fail_unless_equals_int (g_value_get_int (w_val), 200 - (1 + 3));
590 gst_structure_get_value (gst_caps_get_structure (adj_caps, 0), "height");
591 fail_unless (h_val != NULL);
592 fail_unless (G_VALUE_HOLDS_INT (h_val));
593 fail_unless_equals_int (g_value_get_int (h_val), 100 - (5 + 7));
594 gst_caps_unref (adj_caps);
596 /* ========= (2) range (simple adjustment) =============================== */
598 gst_structure_set (gst_caps_get_structure (caps, 0),
599 "width", GST_TYPE_INT_RANGE, 1000, 2000,
600 "height", GST_TYPE_INT_RANGE, 3000, 4000, NULL);
602 /* sink => source, source must be bigger if we crop stuff off */
603 adj_caps = klass->transform_caps (crop, GST_PAD_SRC, caps, NULL);
604 fail_unless (adj_caps != NULL);
605 fail_unless (gst_caps_get_size (adj_caps) == 1);
607 gst_structure_get_value (gst_caps_get_structure (adj_caps, 0), "width");
608 fail_unless (w_val != NULL);
609 fail_unless (GST_VALUE_HOLDS_INT_RANGE (w_val));
610 fail_unless_equals_int (gst_value_get_int_range_min (w_val), 1000 + (1 + 3));
611 fail_unless_equals_int (gst_value_get_int_range_max (w_val), 2000 + (1 + 3));
613 gst_structure_get_value (gst_caps_get_structure (adj_caps, 0), "height");
614 fail_unless (h_val != NULL);
615 fail_unless (GST_VALUE_HOLDS_INT_RANGE (h_val));
616 fail_unless_equals_int (gst_value_get_int_range_min (h_val), 3000 + (5 + 7));
617 fail_unless_equals_int (gst_value_get_int_range_max (h_val), 4000 + (5 + 7));
618 gst_caps_unref (adj_caps);
620 /* source => sink becomes smaller */
621 adj_caps = klass->transform_caps (crop, GST_PAD_SINK, caps, NULL);
622 fail_unless (adj_caps != NULL);
623 fail_unless (gst_caps_get_size (adj_caps) == 1);
625 gst_structure_get_value (gst_caps_get_structure (adj_caps, 0), "width");
626 fail_unless (w_val != NULL);
627 fail_unless (GST_VALUE_HOLDS_INT_RANGE (w_val));
628 fail_unless_equals_int (gst_value_get_int_range_min (w_val), 1000 - (1 + 3));
629 fail_unless_equals_int (gst_value_get_int_range_max (w_val), 2000 - (1 + 3));
631 gst_structure_get_value (gst_caps_get_structure (adj_caps, 0), "height");
632 fail_unless (h_val != NULL);
633 fail_unless (GST_VALUE_HOLDS_INT_RANGE (h_val));
634 fail_unless_equals_int (gst_value_get_int_range_min (h_val), 3000 - (5 + 7));
635 fail_unless_equals_int (gst_value_get_int_range_max (h_val), 4000 - (5 + 7));
636 gst_caps_unref (adj_caps);
638 /* ========= (3) range (adjustment at boundary) ========================== */
640 gst_structure_set (gst_caps_get_structure (caps, 0),
641 "width", GST_TYPE_INT_RANGE, 2, G_MAXINT,
642 "height", GST_TYPE_INT_RANGE, 2, G_MAXINT, NULL);
644 /* sink => source, source must be bigger if we crop stuff off */
645 adj_caps = klass->transform_caps (crop, GST_PAD_SRC, caps, NULL);
646 fail_unless (adj_caps != NULL);
647 fail_unless (gst_caps_get_size (adj_caps) == 1);
649 gst_structure_get_value (gst_caps_get_structure (adj_caps, 0), "width");
650 fail_unless (w_val != NULL);
651 fail_unless (GST_VALUE_HOLDS_INT_RANGE (w_val));
652 fail_unless_equals_int (gst_value_get_int_range_min (w_val), 2 + (1 + 3));
653 fail_unless_equals_int (gst_value_get_int_range_max (w_val), G_MAXINT);
655 gst_structure_get_value (gst_caps_get_structure (adj_caps, 0), "height");
656 fail_unless (h_val != NULL);
657 fail_unless (GST_VALUE_HOLDS_INT_RANGE (h_val));
658 fail_unless_equals_int (gst_value_get_int_range_min (h_val), 2 + (5 + 7));
659 fail_unless_equals_int (gst_value_get_int_range_max (h_val), G_MAXINT);
660 gst_caps_unref (adj_caps);
662 /* source => sink becomes smaller */
663 adj_caps = klass->transform_caps (crop, GST_PAD_SINK, caps, NULL);
664 fail_unless (adj_caps != NULL);
665 fail_unless (gst_caps_get_size (adj_caps) == 1);
667 gst_structure_get_value (gst_caps_get_structure (adj_caps, 0), "width");
668 fail_unless (w_val != NULL);
669 fail_unless (GST_VALUE_HOLDS_INT_RANGE (w_val));
670 fail_unless_equals_int (gst_value_get_int_range_min (w_val), 1);
671 fail_unless_equals_int (gst_value_get_int_range_max (w_val),
674 gst_structure_get_value (gst_caps_get_structure (adj_caps, 0), "height");
675 fail_unless (h_val != NULL);
676 fail_unless (GST_VALUE_HOLDS_INT_RANGE (h_val));
677 fail_unless_equals_int (gst_value_get_int_range_min (h_val), 1);
678 fail_unless_equals_int (gst_value_get_int_range_max (h_val),
680 gst_caps_unref (adj_caps);
682 /* ========= (4) list of values ========================================== */
685 GValue list = { 0, };
686 GValue ival = { 0, };
688 g_value_init (&ival, G_TYPE_INT);
689 g_value_init (&list, GST_TYPE_LIST);
690 g_value_set_int (&ival, 2);
691 gst_value_list_append_value (&list, &ival);
692 g_value_set_int (&ival, G_MAXINT);
693 gst_value_list_append_value (&list, &ival);
694 gst_structure_set_value (gst_caps_get_structure (caps, 0), "width", &list);
695 g_value_unset (&list);
696 g_value_unset (&ival);
698 g_value_init (&ival, G_TYPE_INT);
699 g_value_init (&list, GST_TYPE_LIST);
700 g_value_set_int (&ival, 5);
701 gst_value_list_append_value (&list, &ival);
702 g_value_set_int (&ival, 1000);
703 gst_value_list_append_value (&list, &ival);
704 gst_structure_set_value (gst_caps_get_structure (caps, 0), "height", &list);
705 g_value_unset (&list);
706 g_value_unset (&ival);
709 /* sink => source, source must be bigger if we crop stuff off */
710 adj_caps = klass->transform_caps (crop, GST_PAD_SRC, caps, NULL);
711 fail_unless (adj_caps != NULL);
712 fail_unless (gst_caps_get_size (adj_caps) == 1);
714 gst_structure_get_value (gst_caps_get_structure (adj_caps, 0), "width");
715 fail_unless (w_val != NULL);
716 fail_unless (GST_VALUE_HOLDS_LIST (w_val));
717 fail_unless_equals_int (notgst_value_list_get_nth_int (w_val, 0),
719 fail_unless_equals_int (notgst_value_list_get_nth_int (w_val, 1), G_MAXINT);
721 gst_structure_get_value (gst_caps_get_structure (adj_caps, 0), "height");
722 fail_unless (h_val != NULL);
723 fail_unless (GST_VALUE_HOLDS_LIST (h_val));
724 fail_unless_equals_int (notgst_value_list_get_nth_int (h_val, 0),
726 fail_unless_equals_int (notgst_value_list_get_nth_int (h_val, 1),
728 gst_caps_unref (adj_caps);
730 /* source => sink becomes smaller */
731 adj_caps = klass->transform_caps (crop, GST_PAD_SINK, caps, NULL);
732 fail_unless (adj_caps != NULL);
733 fail_unless (gst_caps_get_size (adj_caps) == 1);
735 gst_structure_get_value (gst_caps_get_structure (adj_caps, 0), "width");
736 fail_unless (w_val != NULL);
737 fail_unless (GST_VALUE_HOLDS_LIST (w_val));
738 fail_unless_equals_int (notgst_value_list_get_nth_int (w_val, 0), 1);
739 fail_unless_equals_int (notgst_value_list_get_nth_int (w_val, 1),
742 gst_structure_get_value (gst_caps_get_structure (adj_caps, 0), "height");
743 fail_unless (h_val != NULL);
744 fail_unless (GST_VALUE_HOLDS_LIST (h_val));
745 fail_unless_equals_int (notgst_value_list_get_nth_int (h_val, 0), 1);
746 fail_unless_equals_int (notgst_value_list_get_nth_int (h_val, 1),
748 gst_caps_unref (adj_caps);
750 gst_caps_unref (caps);
751 videocrop_test_cropping_deinit_context (&ctx);
757 videocrop_suite (void)
759 Suite *s = suite_create ("videocrop");
760 TCase *tc_chain = tcase_create ("general");
763 if (RUNNING_ON_VALGRIND) {
764 /* our tests take quite a long time, so increase
765 * timeout (~25 minutes on my 1.6GHz AMD K7) */
766 tcase_set_timeout (tc_chain, 30 * 60);
770 /* increase timeout, these tests take a long time (60 secs here) */
771 tcase_set_timeout (tc_chain, 2 * 60);
774 suite_add_tcase (s, tc_chain);
775 tcase_add_test (tc_chain, test_crop_to_1x1);
776 tcase_add_test (tc_chain, test_caps_transform);
777 tcase_add_test (tc_chain, test_passthrough);
778 tcase_add_test (tc_chain, test_unit_sizes);
779 tcase_add_loop_test (tc_chain, test_cropping, 0, 25);
785 main (int argc, char **argv)
789 Suite *s = videocrop_suite ();
790 SRunner *sr = srunner_create (s);
793 if (RUNNING_ON_VALGRIND) {
794 /* otherwise valgrind errors out when liboil probes CPU extensions
795 * in oil_init() during which it causes SIGILLs etc. to be fired */
796 g_setenv ("OIL_CPU_FLAGS", "0", 0);
800 gst_check_init (&argc, &argv);
802 srunner_run_all (sr, CK_NORMAL);
803 nf = srunner_ntests_failed (sr);