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/base/gstbasetransform.h>
33 /* return a list of caps where we only need to set
34 * width and height to get fixed caps */
36 video_crop_get_test_caps (GstElement * videocrop)
38 const GstCaps *allowed_caps;
43 srcpad = gst_element_get_static_pad (videocrop, "src");
44 fail_unless (srcpad != NULL);
45 allowed_caps = gst_pad_get_pad_template_caps (srcpad);
46 fail_unless (allowed_caps != NULL);
48 for (i = 0; i < gst_caps_get_size (allowed_caps); ++i) {
49 GstStructure *new_structure;
52 single_caps = gst_caps_new_empty ();
54 gst_structure_copy (gst_caps_get_structure (allowed_caps, i));
55 gst_structure_set (new_structure, "framerate", GST_TYPE_FRACTION,
57 gst_structure_remove_field (new_structure, "width");
58 gst_structure_remove_field (new_structure, "height");
59 gst_caps_append_structure (single_caps, new_structure);
61 /* should be fixed without width/height */
62 fail_unless (gst_caps_is_fixed (single_caps));
64 list = g_list_prepend (list, single_caps);
67 gst_object_unref (srcpad);
72 GST_START_TEST (test_unit_sizes)
74 GstBaseTransformClass *csp_klass, *vcrop_klass;
75 GstElement *videocrop, *csp;
78 videocrop = gst_element_factory_make ("videocrop", "videocrop");
79 fail_unless (videocrop != NULL, "Failed to create videocrop element");
80 vcrop_klass = GST_BASE_TRANSFORM_GET_CLASS (videocrop);
82 csp = gst_element_factory_make ("ffmpegcolorspace", "csp");
83 fail_unless (csp != NULL, "Failed to create ffmpegcolorspace element");
84 csp_klass = GST_BASE_TRANSFORM_GET_CLASS (csp);
86 caps_list = video_crop_get_test_caps (videocrop);
88 for (l = caps_list; l != NULL; l = l->next) {
107 caps = gst_caps_copy (GST_CAPS (l->data));
108 s = gst_caps_get_structure (caps, 0);
109 fail_unless (s != NULL);
111 for (i = 0; i < G_N_ELEMENTS (sizes_to_try); ++i) {
116 gst_structure_set (s, "width", G_TYPE_INT, sizes_to_try[i].width,
117 "height", G_TYPE_INT, sizes_to_try[i].height, NULL);
119 caps_str = gst_caps_to_string (caps);
120 GST_INFO ("Testing unit size for %s", caps_str);
122 /* skip if ffmpegcolorspace doesn't support these caps
123 * (only works with gst-plugins-base 0.10.9.1 or later) */
124 if (!csp_klass->get_unit_size ((GstBaseTransform *) csp, caps, &csp_size)) {
125 GST_INFO ("ffmpegcolorspace does not support format %s", caps_str);
130 fail_unless (vcrop_klass->get_unit_size ((GstBaseTransform *) videocrop,
133 fail_unless (vc_size == csp_size,
134 "videocrop and ffmpegcolorspace return different unit sizes for "
135 "caps %s: vc_size=%d, csp_size=%d", caps_str, vc_size, csp_size);
140 gst_caps_unref (caps);
143 g_list_foreach (caps_list, (GFunc) gst_caps_unref, NULL);
144 g_list_free (caps_list);
146 gst_object_unref (csp);
147 gst_object_unref (videocrop);
154 GstElement *pipeline;
160 } GstVideoCropTestContext;
163 handoff_cb (GstElement * sink, GstBuffer * buf, GstPad * pad,
166 gst_buffer_replace (p_buf, buf);
170 videocrop_test_cropping_init_context (GstVideoCropTestContext * ctx)
172 fail_unless (ctx != NULL);
174 ctx->pipeline = gst_pipeline_new ("pipeline");
175 fail_unless (ctx->pipeline != NULL);
176 ctx->src = gst_element_factory_make ("videotestsrc", "src");
177 fail_unless (ctx->src != NULL, "Failed to create videotestsrc element");
178 ctx->filter = gst_element_factory_make ("capsfilter", "filter");
179 fail_unless (ctx->filter != NULL, "Failed to create capsfilter element");
180 ctx->crop = gst_element_factory_make ("videocrop", "crop");
181 fail_unless (ctx->crop != NULL, "Failed to create videocrop element");
182 ctx->sink = gst_element_factory_make ("fakesink", "sink");
183 fail_unless (ctx->sink != NULL, "Failed to create fakesink element");
185 gst_bin_add_many (GST_BIN (ctx->pipeline), ctx->src, ctx->filter,
186 ctx->crop, ctx->sink, NULL);
187 gst_element_link_many (ctx->src, ctx->filter, ctx->crop, ctx->sink, NULL);
189 /* set pattern to 'red' - for our purposes it doesn't matter anyway */
190 g_object_set (ctx->src, "pattern", 4, NULL);
192 g_object_set (ctx->sink, "signal-handoffs", TRUE, NULL);
193 g_signal_connect (ctx->sink, "preroll-handoff", G_CALLBACK (handoff_cb),
196 ctx->last_buf = NULL;
198 GST_LOG ("context inited");
202 videocrop_test_cropping_deinit_context (GstVideoCropTestContext * ctx)
204 GST_LOG ("deiniting context");
206 gst_element_set_state (ctx->pipeline, GST_STATE_NULL);
207 gst_object_unref (ctx->pipeline);
208 gst_buffer_replace (&ctx->last_buf, NULL);
209 memset (ctx, 0x00, sizeof (GstVideoCropTestContext));
212 typedef void (*GstVideoCropTestBufferFunc) (GstBuffer * buffer);
215 videocrop_test_cropping (GstVideoCropTestContext * ctx, GstCaps * in_caps,
216 gint left, gint right, gint top, gint bottom,
217 GstVideoCropTestBufferFunc func)
219 GST_LOG ("lrtb = %03u %03u %03u %03u, caps = %" GST_PTR_FORMAT, left, right,
220 top, bottom, in_caps);
222 g_object_set (ctx->filter, "caps", in_caps, NULL);
224 g_object_set (ctx->crop, "left", left, "right", right, "top", top,
225 "bottom", bottom, NULL);
227 /* this will fail if videotestsrc doesn't support our format; we need
228 * videotestsrc from -base CVS 0.10.9.1 with RGBA and AYUV support */
229 fail_unless (gst_element_set_state (ctx->pipeline,
230 GST_STATE_PAUSED) != GST_STATE_CHANGE_FAILURE);
231 fail_unless (gst_element_get_state (ctx->pipeline, NULL, NULL,
232 -1) == GST_STATE_CHANGE_SUCCESS);
235 func (ctx->last_buf);
238 gst_element_set_state (ctx->pipeline, GST_STATE_NULL);
242 check_1x1_buffer (GstBuffer * buf)
246 fail_unless (buf != NULL);
247 fail_unless (GST_BUFFER_CAPS (buf) != NULL);
249 s = gst_caps_get_structure (GST_BUFFER_CAPS (buf), 0);
250 if (gst_structure_has_name (s, "video/x-raw-yuv")) {
253 fail_unless (gst_structure_get_fourcc (s, "format", &format));
255 /* the exact values we check for come from videotestsrc */
257 case GST_MAKE_FOURCC ('I', '4', '2', '0'):
258 fail_unless_equals_int (GST_BUFFER_DATA (buf)[0], 81);
259 fail_unless_equals_int (GST_BUFFER_DATA (buf)[8], 90);
260 fail_unless_equals_int (GST_BUFFER_DATA (buf)[12], 240);
262 case GST_MAKE_FOURCC ('Y', 'V', '1', '2'):
263 fail_unless_equals_int (GST_BUFFER_DATA (buf)[0], 81);
264 fail_unless_equals_int (GST_BUFFER_DATA (buf)[8], 240);
265 fail_unless_equals_int (GST_BUFFER_DATA (buf)[12], 90);
267 case GST_MAKE_FOURCC ('Y', '8', '0', '0'):
268 fail_unless_equals_int (GST_BUFFER_DATA (buf)[0], 81);
269 /* no chroma planes */
271 case GST_MAKE_FOURCC ('A', 'Y', 'U', 'V'):
272 fail_unless_equals_int (GST_BUFFER_DATA (buf)[1], 81);
273 fail_unless_equals_int (GST_BUFFER_DATA (buf)[2], 90);
274 fail_unless_equals_int (GST_BUFFER_DATA (buf)[3], 240);
275 /* no chroma planes */
278 GST_LOG ("not checking %" GST_FOURCC_FORMAT, GST_FOURCC_ARGS (format));
281 } else if (gst_structure_has_name (s, "video/x-raw-rgb")) {
283 gint rmask = 0, bmask = 0, gmask = 0, endianness = 0, bpp = 0;
284 gint rshift, gshift, bshift;
286 fail_unless (gst_structure_get_int (s, "red_mask", &rmask));
287 fail_unless (gst_structure_get_int (s, "blue_mask", &bmask));
288 fail_unless (gst_structure_get_int (s, "green_mask", &gmask));
289 fail_unless (gst_structure_get_int (s, "bpp", &bpp));
290 fail_unless (gst_structure_get_int (s, "endianness", &endianness));
292 fail_unless (rmask != 0);
293 fail_unless (gmask != 0);
294 fail_unless (bmask != 0);
295 fail_unless (bpp != 0);
296 fail_unless (endianness != 0);
298 rshift = g_bit_nth_lsf (rmask, -1);
299 gshift = g_bit_nth_lsf (gmask, -1);
300 bshift = g_bit_nth_lsf (bmask, -1);
304 if (endianness == G_LITTLE_ENDIAN)
305 pixel = GST_READ_UINT32_LE (GST_BUFFER_DATA (buf));
307 pixel = GST_READ_UINT32_BE (GST_BUFFER_DATA (buf));
311 if (endianness == G_BIG_ENDIAN) {
312 pixel = (GST_READ_UINT8 (GST_BUFFER_DATA (buf)) << 16) |
313 (GST_READ_UINT8 (GST_BUFFER_DATA (buf) + 1) << 8) |
314 (GST_READ_UINT8 (GST_BUFFER_DATA (buf) + 2) << 0);
316 pixel = (GST_READ_UINT8 (GST_BUFFER_DATA (buf) + 2) << 16) |
317 (GST_READ_UINT8 (GST_BUFFER_DATA (buf) + 1) << 8) |
318 (GST_READ_UINT8 (GST_BUFFER_DATA (buf) + 0) << 0);
323 GST_LOG ("not checking RGB-format buffer with %ubpp", bpp);
328 fail_unless_equals_int ((pixel & rmask) >> rshift, 0xff);
329 fail_unless_equals_int ((pixel & gmask) >> gshift, 0x00);
330 fail_unless_equals_int ((pixel & bmask) >> bshift, 0x00);
334 GST_START_TEST (test_crop_to_1x1)
336 GstVideoCropTestContext ctx;
337 GList *caps_list, *node;
339 videocrop_test_cropping_init_context (&ctx);
341 caps_list = video_crop_get_test_caps (ctx.crop);
343 for (node = caps_list; node != NULL; node = node->next) {
347 caps = gst_caps_copy (GST_CAPS (node->data));
348 s = gst_caps_get_structure (caps, 0);
349 fail_unless (s != NULL);
351 if (g_strcmp0 (gst_structure_get_name (s), "video/x-raw-gray") == 0) {
352 /* videotestsrc does not support this format */
356 GST_INFO ("testing format: %" GST_PTR_FORMAT, caps);
358 gst_structure_set (s, "width", G_TYPE_INT, 160,
359 "height", G_TYPE_INT, 160, NULL);
361 videocrop_test_cropping (&ctx, caps, 159, 0, 159, 0, check_1x1_buffer);
362 /* commented out because they don't really add anything useful check-wise:
363 videocrop_test_cropping (&ctx, caps, 0, 159, 0, 159, check_1x1_buffer);
364 videocrop_test_cropping (&ctx, caps, 159, 0, 0, 159, check_1x1_buffer);
365 videocrop_test_cropping (&ctx, caps, 0, 159, 159, 0, check_1x1_buffer);
367 gst_caps_unref (caps);
369 g_list_foreach (caps_list, (GFunc) gst_caps_unref, NULL);
370 g_list_free (caps_list);
372 videocrop_test_cropping_deinit_context (&ctx);
377 GST_START_TEST (test_cropping)
379 GstVideoCropTestContext ctx;
394 GList *caps_list, *node;
397 videocrop_test_cropping_init_context (&ctx);
399 caps_list = video_crop_get_test_caps (ctx.crop);
400 node = g_list_nth (caps_list, __i__);
406 caps = gst_caps_copy (GST_CAPS (node->data));
407 s = gst_caps_get_structure (caps, 0);
408 fail_unless (s != NULL);
410 /* videotestsrc does not support this format, so ignore it */
411 if (!g_str_equal (gst_structure_get_name (s), "video/x-raw-gray")) {
412 GST_INFO ("testing format: %" GST_PTR_FORMAT, caps);
414 for (i = 0; i < G_N_ELEMENTS (sizes_to_try); ++i) {
417 GST_INFO (" - %d x %d", sizes_to_try[i].width, sizes_to_try[i].height);
419 gst_structure_set (s, "width", G_TYPE_INT, sizes_to_try[i].width,
420 "height", G_TYPE_INT, sizes_to_try[i].height, NULL);
421 in_caps = gst_caps_copy (caps);
423 videocrop_test_cropping (&ctx, in_caps, 0, 0, 0, 0, NULL);
424 videocrop_test_cropping (&ctx, in_caps, 1, 0, 0, 0, NULL);
425 videocrop_test_cropping (&ctx, in_caps, 0, 1, 0, 0, NULL);
426 videocrop_test_cropping (&ctx, in_caps, 0, 0, 1, 0, NULL);
427 videocrop_test_cropping (&ctx, in_caps, 0, 0, 0, 1, NULL);
428 videocrop_test_cropping (&ctx, in_caps, 63, 0, 0, 0, NULL);
429 videocrop_test_cropping (&ctx, in_caps, 0, 63, 0, 0, NULL);
430 videocrop_test_cropping (&ctx, in_caps, 0, 0, 63, 0, NULL);
431 videocrop_test_cropping (&ctx, in_caps, 0, 0, 0, 63, NULL);
432 videocrop_test_cropping (&ctx, in_caps, 63, 0, 0, 1, NULL);
433 videocrop_test_cropping (&ctx, in_caps, 0, 63, 1, 0, NULL);
434 videocrop_test_cropping (&ctx, in_caps, 0, 1, 63, 0, NULL);
435 videocrop_test_cropping (&ctx, in_caps, 1, 0, 0, 63, NULL);
436 videocrop_test_cropping (&ctx, in_caps, 0, 0, 0, 0, NULL);
437 videocrop_test_cropping (&ctx, in_caps, 32, 0, 0, 128, NULL);
438 videocrop_test_cropping (&ctx, in_caps, 0, 32, 128, 0, NULL);
439 videocrop_test_cropping (&ctx, in_caps, 0, 128, 32, 0, NULL);
440 videocrop_test_cropping (&ctx, in_caps, 128, 0, 0, 32, NULL);
441 videocrop_test_cropping (&ctx, in_caps, 1, 1, 1, 1, NULL);
442 videocrop_test_cropping (&ctx, in_caps, 63, 63, 63, 63, NULL);
443 videocrop_test_cropping (&ctx, in_caps, 64, 64, 64, 64, NULL);
445 gst_caps_unref (in_caps);
449 gst_caps_unref (caps);
451 GST_INFO ("no caps #%d", __i__);
453 g_list_foreach (caps_list, (GFunc) gst_caps_unref, NULL);
454 g_list_free (caps_list);
456 videocrop_test_cropping_deinit_context (&ctx);
463 buffer_probe_cb (GstPad * pad, GstBuffer * buf, GstBuffer ** p_buf)
465 gst_buffer_replace (p_buf, buf);
466 return TRUE; /* keep data */
469 GST_START_TEST (test_passthrough)
471 GstStateChangeReturn state_ret;
472 GstVideoCropTestContext ctx;
474 GstBuffer *gen_buf = NULL; /* buffer generated by videotestsrc */
476 videocrop_test_cropping_init_context (&ctx);
478 g_object_set (ctx.src, "num-buffers", 1, NULL);
480 srcpad = gst_element_get_static_pad (ctx.src, "src");
481 fail_unless (srcpad != NULL);
482 gst_pad_add_buffer_probe (srcpad, G_CALLBACK (buffer_probe_cb), &gen_buf);
483 gst_object_unref (srcpad);
485 g_object_set (ctx.crop, "left", 0, "right", 0, "top", 0, "bottom", 0, NULL);
487 state_ret = gst_element_set_state (ctx.pipeline, GST_STATE_PAUSED);
488 fail_unless (state_ret != GST_STATE_CHANGE_FAILURE,
489 "couldn't set pipeline to PAUSED state");
491 state_ret = gst_element_get_state (ctx.pipeline, NULL, NULL, -1);
492 fail_unless (state_ret == GST_STATE_CHANGE_SUCCESS,
493 "pipeline failed to go to PAUSED state");
495 fail_unless (gen_buf != NULL);
496 fail_unless (ctx.last_buf != NULL);
498 /* pass through should do nothing */
499 fail_unless (gen_buf == ctx.last_buf);
501 videocrop_test_cropping_deinit_context (&ctx);
503 fail_unless_equals_int (GST_MINI_OBJECT_REFCOUNT_VALUE (gen_buf), 1);
504 gst_buffer_unref (gen_buf);
510 notgst_value_list_get_nth_int (const GValue * list_val, guint n)
514 fail_unless (GST_VALUE_HOLDS_LIST (list_val));
515 fail_unless (n < gst_value_list_get_size (list_val));
517 v = gst_value_list_get_value (list_val, n);
518 fail_unless (G_VALUE_HOLDS_INT (v));
519 return g_value_get_int (v);
522 GST_START_TEST (test_caps_transform)
524 GstVideoCropTestContext ctx;
525 GstBaseTransformClass *klass;
526 GstBaseTransform *crop;
529 GstCaps *caps, *adj_caps;
531 videocrop_test_cropping_init_context (&ctx);
533 crop = GST_BASE_TRANSFORM (ctx.crop);
534 klass = GST_BASE_TRANSFORM_GET_CLASS (ctx.crop);
535 fail_unless (klass != NULL);
537 caps = gst_caps_new_simple ("video/x-raw-yuv",
538 "format", GST_TYPE_FOURCC, GST_MAKE_FOURCC ('I', '4', '2', '0'),
539 "framerate", GST_TYPE_FRACTION, 1, 1,
540 "width", G_TYPE_INT, 200, "height", G_TYPE_INT, 100, NULL);
542 /* by default, it should be no cropping and hence passthrough */
543 adj_caps = klass->transform_caps (crop, GST_PAD_SRC, caps);
544 fail_unless (adj_caps != NULL);
545 fail_unless (gst_caps_is_equal (adj_caps, caps));
546 gst_caps_unref (adj_caps);
548 adj_caps = klass->transform_caps (crop, GST_PAD_SINK, caps);
549 fail_unless (adj_caps != NULL);
550 fail_unless (gst_caps_is_equal (adj_caps, caps));
551 gst_caps_unref (adj_caps);
553 /* make sure that's still true after changing properties back and forth */
554 g_object_set (ctx.crop, "left", 1, "right", 3, "top", 5, "bottom", 7, NULL);
555 g_object_set (ctx.crop, "left", 0, "right", 0, "top", 0, "bottom", 0, NULL);
557 adj_caps = klass->transform_caps (crop, GST_PAD_SRC, caps);
558 fail_unless (adj_caps != NULL);
559 fail_unless (gst_caps_is_equal (adj_caps, caps));
560 gst_caps_unref (adj_caps);
562 adj_caps = klass->transform_caps (crop, GST_PAD_SINK, caps);
563 fail_unless (adj_caps != NULL);
564 fail_unless (gst_caps_is_equal (adj_caps, caps));
565 gst_caps_unref (adj_caps);
567 /* now check adjustments made ... */
568 g_object_set (ctx.crop, "left", 1, "right", 3, "top", 5, "bottom", 7, NULL);
570 /* ========= (1) fixed value ============================================= */
572 /* sink => source, source must be bigger if we crop stuff off */
573 adj_caps = klass->transform_caps (crop, GST_PAD_SRC, caps);
574 fail_unless (adj_caps != NULL);
575 fail_unless (gst_caps_get_size (adj_caps) == 1);
577 gst_structure_get_value (gst_caps_get_structure (adj_caps, 0), "width");
578 fail_unless (w_val != NULL);
579 fail_unless (G_VALUE_HOLDS_INT (w_val));
580 fail_unless_equals_int (g_value_get_int (w_val), 200 + (1 + 3));
582 gst_structure_get_value (gst_caps_get_structure (adj_caps, 0), "height");
583 fail_unless (h_val != NULL);
584 fail_unless (G_VALUE_HOLDS_INT (h_val));
585 fail_unless_equals_int (g_value_get_int (h_val), 100 + (5 + 7));
586 gst_caps_unref (adj_caps);
588 /* source => sink becomes smaller */
589 adj_caps = klass->transform_caps (crop, GST_PAD_SINK, caps);
590 fail_unless (adj_caps != NULL);
591 fail_unless (gst_caps_get_size (adj_caps) == 1);
593 gst_structure_get_value (gst_caps_get_structure (adj_caps, 0), "width");
594 fail_unless (w_val != NULL);
595 fail_unless (G_VALUE_HOLDS_INT (w_val));
596 fail_unless_equals_int (g_value_get_int (w_val), 200 - (1 + 3));
598 gst_structure_get_value (gst_caps_get_structure (adj_caps, 0), "height");
599 fail_unless (h_val != NULL);
600 fail_unless (G_VALUE_HOLDS_INT (h_val));
601 fail_unless_equals_int (g_value_get_int (h_val), 100 - (5 + 7));
602 gst_caps_unref (adj_caps);
604 /* ========= (2) range (simple adjustment) =============================== */
606 gst_structure_set (gst_caps_get_structure (caps, 0),
607 "width", GST_TYPE_INT_RANGE, 1000, 2000,
608 "height", GST_TYPE_INT_RANGE, 3000, 4000, NULL);
610 /* sink => source, source must be bigger if we crop stuff off */
611 adj_caps = klass->transform_caps (crop, GST_PAD_SRC, caps);
612 fail_unless (adj_caps != NULL);
613 fail_unless (gst_caps_get_size (adj_caps) == 1);
615 gst_structure_get_value (gst_caps_get_structure (adj_caps, 0), "width");
616 fail_unless (w_val != NULL);
617 fail_unless (GST_VALUE_HOLDS_INT_RANGE (w_val));
618 fail_unless_equals_int (gst_value_get_int_range_min (w_val), 1000 + (1 + 3));
619 fail_unless_equals_int (gst_value_get_int_range_max (w_val), 2000 + (1 + 3));
621 gst_structure_get_value (gst_caps_get_structure (adj_caps, 0), "height");
622 fail_unless (h_val != NULL);
623 fail_unless (GST_VALUE_HOLDS_INT_RANGE (h_val));
624 fail_unless_equals_int (gst_value_get_int_range_min (h_val), 3000 + (5 + 7));
625 fail_unless_equals_int (gst_value_get_int_range_max (h_val), 4000 + (5 + 7));
626 gst_caps_unref (adj_caps);
628 /* source => sink becomes smaller */
629 adj_caps = klass->transform_caps (crop, GST_PAD_SINK, caps);
630 fail_unless (adj_caps != NULL);
631 fail_unless (gst_caps_get_size (adj_caps) == 1);
633 gst_structure_get_value (gst_caps_get_structure (adj_caps, 0), "width");
634 fail_unless (w_val != NULL);
635 fail_unless (GST_VALUE_HOLDS_INT_RANGE (w_val));
636 fail_unless_equals_int (gst_value_get_int_range_min (w_val), 1000 - (1 + 3));
637 fail_unless_equals_int (gst_value_get_int_range_max (w_val), 2000 - (1 + 3));
639 gst_structure_get_value (gst_caps_get_structure (adj_caps, 0), "height");
640 fail_unless (h_val != NULL);
641 fail_unless (GST_VALUE_HOLDS_INT_RANGE (h_val));
642 fail_unless_equals_int (gst_value_get_int_range_min (h_val), 3000 - (5 + 7));
643 fail_unless_equals_int (gst_value_get_int_range_max (h_val), 4000 - (5 + 7));
644 gst_caps_unref (adj_caps);
646 /* ========= (3) range (adjustment at boundary) ========================== */
648 gst_structure_set (gst_caps_get_structure (caps, 0),
649 "width", GST_TYPE_INT_RANGE, 2, G_MAXINT,
650 "height", GST_TYPE_INT_RANGE, 2, G_MAXINT, NULL);
652 /* sink => source, source must be bigger if we crop stuff off */
653 adj_caps = klass->transform_caps (crop, GST_PAD_SRC, caps);
654 fail_unless (adj_caps != NULL);
655 fail_unless (gst_caps_get_size (adj_caps) == 1);
657 gst_structure_get_value (gst_caps_get_structure (adj_caps, 0), "width");
658 fail_unless (w_val != NULL);
659 fail_unless (GST_VALUE_HOLDS_INT_RANGE (w_val));
660 fail_unless_equals_int (gst_value_get_int_range_min (w_val), 2 + (1 + 3));
661 fail_unless_equals_int (gst_value_get_int_range_max (w_val), G_MAXINT);
663 gst_structure_get_value (gst_caps_get_structure (adj_caps, 0), "height");
664 fail_unless (h_val != NULL);
665 fail_unless (GST_VALUE_HOLDS_INT_RANGE (h_val));
666 fail_unless_equals_int (gst_value_get_int_range_min (h_val), 2 + (5 + 7));
667 fail_unless_equals_int (gst_value_get_int_range_max (h_val), G_MAXINT);
668 gst_caps_unref (adj_caps);
670 /* source => sink becomes smaller */
671 adj_caps = klass->transform_caps (crop, GST_PAD_SINK, caps);
672 fail_unless (adj_caps != NULL);
673 fail_unless (gst_caps_get_size (adj_caps) == 1);
675 gst_structure_get_value (gst_caps_get_structure (adj_caps, 0), "width");
676 fail_unless (w_val != NULL);
677 fail_unless (GST_VALUE_HOLDS_INT_RANGE (w_val));
678 fail_unless_equals_int (gst_value_get_int_range_min (w_val), 1);
679 fail_unless_equals_int (gst_value_get_int_range_max (w_val),
682 gst_structure_get_value (gst_caps_get_structure (adj_caps, 0), "height");
683 fail_unless (h_val != NULL);
684 fail_unless (GST_VALUE_HOLDS_INT_RANGE (h_val));
685 fail_unless_equals_int (gst_value_get_int_range_min (h_val), 1);
686 fail_unless_equals_int (gst_value_get_int_range_max (h_val),
688 gst_caps_unref (adj_caps);
690 /* ========= (4) list of values ========================================== */
693 GValue list = { 0, };
694 GValue ival = { 0, };
696 g_value_init (&ival, G_TYPE_INT);
697 g_value_init (&list, GST_TYPE_LIST);
698 g_value_set_int (&ival, 2);
699 gst_value_list_append_value (&list, &ival);
700 g_value_set_int (&ival, G_MAXINT);
701 gst_value_list_append_value (&list, &ival);
702 gst_structure_set_value (gst_caps_get_structure (caps, 0), "width", &list);
703 g_value_unset (&list);
704 g_value_unset (&ival);
706 g_value_init (&ival, G_TYPE_INT);
707 g_value_init (&list, GST_TYPE_LIST);
708 g_value_set_int (&ival, 5);
709 gst_value_list_append_value (&list, &ival);
710 g_value_set_int (&ival, 1000);
711 gst_value_list_append_value (&list, &ival);
712 gst_structure_set_value (gst_caps_get_structure (caps, 0), "height", &list);
713 g_value_unset (&list);
714 g_value_unset (&ival);
717 /* sink => source, source must be bigger if we crop stuff off */
718 adj_caps = klass->transform_caps (crop, GST_PAD_SRC, caps);
719 fail_unless (adj_caps != NULL);
720 fail_unless (gst_caps_get_size (adj_caps) == 1);
722 gst_structure_get_value (gst_caps_get_structure (adj_caps, 0), "width");
723 fail_unless (w_val != NULL);
724 fail_unless (GST_VALUE_HOLDS_LIST (w_val));
725 fail_unless_equals_int (notgst_value_list_get_nth_int (w_val, 0),
727 fail_unless_equals_int (notgst_value_list_get_nth_int (w_val, 1), G_MAXINT);
729 gst_structure_get_value (gst_caps_get_structure (adj_caps, 0), "height");
730 fail_unless (h_val != NULL);
731 fail_unless (GST_VALUE_HOLDS_LIST (h_val));
732 fail_unless_equals_int (notgst_value_list_get_nth_int (h_val, 0),
734 fail_unless_equals_int (notgst_value_list_get_nth_int (h_val, 1),
736 gst_caps_unref (adj_caps);
738 /* source => sink becomes smaller */
739 adj_caps = klass->transform_caps (crop, GST_PAD_SINK, caps);
740 fail_unless (adj_caps != NULL);
741 fail_unless (gst_caps_get_size (adj_caps) == 1);
743 gst_structure_get_value (gst_caps_get_structure (adj_caps, 0), "width");
744 fail_unless (w_val != NULL);
745 fail_unless (GST_VALUE_HOLDS_LIST (w_val));
746 fail_unless_equals_int (notgst_value_list_get_nth_int (w_val, 0), 1);
747 fail_unless_equals_int (notgst_value_list_get_nth_int (w_val, 1),
750 gst_structure_get_value (gst_caps_get_structure (adj_caps, 0), "height");
751 fail_unless (h_val != NULL);
752 fail_unless (GST_VALUE_HOLDS_LIST (h_val));
753 fail_unless_equals_int (notgst_value_list_get_nth_int (h_val, 0), 1);
754 fail_unless_equals_int (notgst_value_list_get_nth_int (h_val, 1),
756 gst_caps_unref (adj_caps);
758 gst_caps_unref (caps);
759 videocrop_test_cropping_deinit_context (&ctx);
765 videocrop_suite (void)
767 Suite *s = suite_create ("videocrop");
768 TCase *tc_chain = tcase_create ("general");
771 if (RUNNING_ON_VALGRIND) {
772 /* our tests take quite a long time, so increase
773 * timeout (~25 minutes on my 1.6GHz AMD K7) */
774 tcase_set_timeout (tc_chain, 30 * 60);
778 /* increase timeout, these tests take a long time (60 secs here) */
779 tcase_set_timeout (tc_chain, 2 * 60);
782 suite_add_tcase (s, tc_chain);
783 tcase_add_test (tc_chain, test_crop_to_1x1);
784 tcase_add_test (tc_chain, test_caps_transform);
785 tcase_add_test (tc_chain, test_passthrough);
786 tcase_add_test (tc_chain, test_unit_sizes);
787 tcase_add_loop_test (tc_chain, test_cropping, 0, 25);
793 main (int argc, char **argv)
797 Suite *s = videocrop_suite ();
798 SRunner *sr = srunner_create (s);
801 if (RUNNING_ON_VALGRIND) {
802 /* otherwise valgrind errors out when liboil probes CPU extensions
803 * in oil_init() during which it causes SIGILLs etc. to be fired */
804 g_setenv ("OIL_CPU_FLAGS", "0", 0);
808 gst_check_init (&argc, &argv);
810 srunner_run_all (sr, CK_NORMAL);
811 nf = srunner_ntests_failed (sr);