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 */
353 gst_caps_unref (caps);
357 GST_INFO ("testing format: %" GST_PTR_FORMAT, caps);
359 gst_structure_set (s, "width", G_TYPE_INT, 160,
360 "height", G_TYPE_INT, 160, NULL);
362 videocrop_test_cropping (&ctx, caps, 159, 0, 159, 0, check_1x1_buffer);
363 /* commented out because they don't really add anything useful check-wise:
364 videocrop_test_cropping (&ctx, caps, 0, 159, 0, 159, check_1x1_buffer);
365 videocrop_test_cropping (&ctx, caps, 159, 0, 0, 159, check_1x1_buffer);
366 videocrop_test_cropping (&ctx, caps, 0, 159, 159, 0, check_1x1_buffer);
368 gst_caps_unref (caps);
370 g_list_foreach (caps_list, (GFunc) gst_caps_unref, NULL);
371 g_list_free (caps_list);
373 videocrop_test_cropping_deinit_context (&ctx);
378 GST_START_TEST (test_cropping)
380 GstVideoCropTestContext ctx;
395 GList *caps_list, *node;
398 videocrop_test_cropping_init_context (&ctx);
400 caps_list = video_crop_get_test_caps (ctx.crop);
401 node = g_list_nth (caps_list, __i__);
407 caps = gst_caps_copy (GST_CAPS (node->data));
408 s = gst_caps_get_structure (caps, 0);
409 fail_unless (s != NULL);
411 /* videotestsrc does not support this format, so ignore it */
412 if (!g_str_equal (gst_structure_get_name (s), "video/x-raw-gray")) {
413 GST_INFO ("testing format: %" GST_PTR_FORMAT, caps);
415 for (i = 0; i < G_N_ELEMENTS (sizes_to_try); ++i) {
418 GST_INFO (" - %d x %d", sizes_to_try[i].width, sizes_to_try[i].height);
420 gst_structure_set (s, "width", G_TYPE_INT, sizes_to_try[i].width,
421 "height", G_TYPE_INT, sizes_to_try[i].height, NULL);
422 in_caps = gst_caps_copy (caps);
424 videocrop_test_cropping (&ctx, in_caps, 0, 0, 0, 0, NULL);
425 videocrop_test_cropping (&ctx, in_caps, 1, 0, 0, 0, NULL);
426 videocrop_test_cropping (&ctx, in_caps, 0, 1, 0, 0, NULL);
427 videocrop_test_cropping (&ctx, in_caps, 0, 0, 1, 0, NULL);
428 videocrop_test_cropping (&ctx, in_caps, 0, 0, 0, 1, NULL);
429 videocrop_test_cropping (&ctx, in_caps, 63, 0, 0, 0, NULL);
430 videocrop_test_cropping (&ctx, in_caps, 0, 63, 0, 0, NULL);
431 videocrop_test_cropping (&ctx, in_caps, 0, 0, 63, 0, NULL);
432 videocrop_test_cropping (&ctx, in_caps, 0, 0, 0, 63, NULL);
433 videocrop_test_cropping (&ctx, in_caps, 63, 0, 0, 1, NULL);
434 videocrop_test_cropping (&ctx, in_caps, 0, 63, 1, 0, NULL);
435 videocrop_test_cropping (&ctx, in_caps, 0, 1, 63, 0, NULL);
436 videocrop_test_cropping (&ctx, in_caps, 1, 0, 0, 63, NULL);
437 videocrop_test_cropping (&ctx, in_caps, 0, 0, 0, 0, NULL);
438 videocrop_test_cropping (&ctx, in_caps, 32, 0, 0, 128, NULL);
439 videocrop_test_cropping (&ctx, in_caps, 0, 32, 128, 0, NULL);
440 videocrop_test_cropping (&ctx, in_caps, 0, 128, 32, 0, NULL);
441 videocrop_test_cropping (&ctx, in_caps, 128, 0, 0, 32, NULL);
442 videocrop_test_cropping (&ctx, in_caps, 1, 1, 1, 1, NULL);
443 videocrop_test_cropping (&ctx, in_caps, 63, 63, 63, 63, NULL);
444 videocrop_test_cropping (&ctx, in_caps, 64, 64, 64, 64, NULL);
446 gst_caps_unref (in_caps);
450 gst_caps_unref (caps);
452 GST_INFO ("no caps #%d", __i__);
454 g_list_foreach (caps_list, (GFunc) gst_caps_unref, NULL);
455 g_list_free (caps_list);
457 videocrop_test_cropping_deinit_context (&ctx);
464 buffer_probe_cb (GstPad * pad, GstBuffer * buf, GstBuffer ** p_buf)
466 gst_buffer_replace (p_buf, buf);
467 return TRUE; /* keep data */
470 GST_START_TEST (test_passthrough)
472 GstStateChangeReturn state_ret;
473 GstVideoCropTestContext ctx;
475 GstBuffer *gen_buf = NULL; /* buffer generated by videotestsrc */
477 videocrop_test_cropping_init_context (&ctx);
479 g_object_set (ctx.src, "num-buffers", 1, NULL);
481 srcpad = gst_element_get_static_pad (ctx.src, "src");
482 fail_unless (srcpad != NULL);
483 gst_pad_add_buffer_probe (srcpad, G_CALLBACK (buffer_probe_cb), &gen_buf);
484 gst_object_unref (srcpad);
486 g_object_set (ctx.crop, "left", 0, "right", 0, "top", 0, "bottom", 0, NULL);
488 state_ret = gst_element_set_state (ctx.pipeline, GST_STATE_PAUSED);
489 fail_unless (state_ret != GST_STATE_CHANGE_FAILURE,
490 "couldn't set pipeline to PAUSED state");
492 state_ret = gst_element_get_state (ctx.pipeline, NULL, NULL, -1);
493 fail_unless (state_ret == GST_STATE_CHANGE_SUCCESS,
494 "pipeline failed to go to PAUSED state");
496 fail_unless (gen_buf != NULL);
497 fail_unless (ctx.last_buf != NULL);
499 /* pass through should do nothing */
500 fail_unless (gen_buf == ctx.last_buf);
502 videocrop_test_cropping_deinit_context (&ctx);
504 fail_unless_equals_int (GST_MINI_OBJECT_REFCOUNT_VALUE (gen_buf), 1);
505 gst_buffer_unref (gen_buf);
511 notgst_value_list_get_nth_int (const GValue * list_val, guint n)
515 fail_unless (GST_VALUE_HOLDS_LIST (list_val));
516 fail_unless (n < gst_value_list_get_size (list_val));
518 v = gst_value_list_get_value (list_val, n);
519 fail_unless (G_VALUE_HOLDS_INT (v));
520 return g_value_get_int (v);
523 GST_START_TEST (test_caps_transform)
525 GstVideoCropTestContext ctx;
526 GstBaseTransformClass *klass;
527 GstBaseTransform *crop;
530 GstCaps *caps, *adj_caps;
532 videocrop_test_cropping_init_context (&ctx);
534 crop = GST_BASE_TRANSFORM (ctx.crop);
535 klass = GST_BASE_TRANSFORM_GET_CLASS (ctx.crop);
536 fail_unless (klass != NULL);
538 caps = gst_caps_new_simple ("video/x-raw-yuv",
539 "format", GST_TYPE_FOURCC, GST_MAKE_FOURCC ('I', '4', '2', '0'),
540 "framerate", GST_TYPE_FRACTION, 1, 1,
541 "width", G_TYPE_INT, 200, "height", G_TYPE_INT, 100, NULL);
543 /* by default, it should be no cropping and hence passthrough */
544 adj_caps = klass->transform_caps (crop, GST_PAD_SRC, caps);
545 fail_unless (adj_caps != NULL);
546 fail_unless (gst_caps_is_equal (adj_caps, caps));
547 gst_caps_unref (adj_caps);
549 adj_caps = klass->transform_caps (crop, GST_PAD_SINK, caps);
550 fail_unless (adj_caps != NULL);
551 fail_unless (gst_caps_is_equal (adj_caps, caps));
552 gst_caps_unref (adj_caps);
554 /* make sure that's still true after changing properties back and forth */
555 g_object_set (ctx.crop, "left", 1, "right", 3, "top", 5, "bottom", 7, NULL);
556 g_object_set (ctx.crop, "left", 0, "right", 0, "top", 0, "bottom", 0, NULL);
558 adj_caps = klass->transform_caps (crop, GST_PAD_SRC, caps);
559 fail_unless (adj_caps != NULL);
560 fail_unless (gst_caps_is_equal (adj_caps, caps));
561 gst_caps_unref (adj_caps);
563 adj_caps = klass->transform_caps (crop, GST_PAD_SINK, caps);
564 fail_unless (adj_caps != NULL);
565 fail_unless (gst_caps_is_equal (adj_caps, caps));
566 gst_caps_unref (adj_caps);
568 /* now check adjustments made ... */
569 g_object_set (ctx.crop, "left", 1, "right", 3, "top", 5, "bottom", 7, NULL);
571 /* ========= (1) fixed value ============================================= */
573 /* sink => source, source must be bigger if we crop stuff off */
574 adj_caps = klass->transform_caps (crop, GST_PAD_SRC, caps);
575 fail_unless (adj_caps != NULL);
576 fail_unless (gst_caps_get_size (adj_caps) == 1);
578 gst_structure_get_value (gst_caps_get_structure (adj_caps, 0), "width");
579 fail_unless (w_val != NULL);
580 fail_unless (G_VALUE_HOLDS_INT (w_val));
581 fail_unless_equals_int (g_value_get_int (w_val), 200 + (1 + 3));
583 gst_structure_get_value (gst_caps_get_structure (adj_caps, 0), "height");
584 fail_unless (h_val != NULL);
585 fail_unless (G_VALUE_HOLDS_INT (h_val));
586 fail_unless_equals_int (g_value_get_int (h_val), 100 + (5 + 7));
587 gst_caps_unref (adj_caps);
589 /* source => sink becomes smaller */
590 adj_caps = klass->transform_caps (crop, GST_PAD_SINK, caps);
591 fail_unless (adj_caps != NULL);
592 fail_unless (gst_caps_get_size (adj_caps) == 1);
594 gst_structure_get_value (gst_caps_get_structure (adj_caps, 0), "width");
595 fail_unless (w_val != NULL);
596 fail_unless (G_VALUE_HOLDS_INT (w_val));
597 fail_unless_equals_int (g_value_get_int (w_val), 200 - (1 + 3));
599 gst_structure_get_value (gst_caps_get_structure (adj_caps, 0), "height");
600 fail_unless (h_val != NULL);
601 fail_unless (G_VALUE_HOLDS_INT (h_val));
602 fail_unless_equals_int (g_value_get_int (h_val), 100 - (5 + 7));
603 gst_caps_unref (adj_caps);
605 /* ========= (2) range (simple adjustment) =============================== */
607 gst_structure_set (gst_caps_get_structure (caps, 0),
608 "width", GST_TYPE_INT_RANGE, 1000, 2000,
609 "height", GST_TYPE_INT_RANGE, 3000, 4000, NULL);
611 /* sink => source, source must be bigger if we crop stuff off */
612 adj_caps = klass->transform_caps (crop, GST_PAD_SRC, caps);
613 fail_unless (adj_caps != NULL);
614 fail_unless (gst_caps_get_size (adj_caps) == 1);
616 gst_structure_get_value (gst_caps_get_structure (adj_caps, 0), "width");
617 fail_unless (w_val != NULL);
618 fail_unless (GST_VALUE_HOLDS_INT_RANGE (w_val));
619 fail_unless_equals_int (gst_value_get_int_range_min (w_val), 1000 + (1 + 3));
620 fail_unless_equals_int (gst_value_get_int_range_max (w_val), 2000 + (1 + 3));
622 gst_structure_get_value (gst_caps_get_structure (adj_caps, 0), "height");
623 fail_unless (h_val != NULL);
624 fail_unless (GST_VALUE_HOLDS_INT_RANGE (h_val));
625 fail_unless_equals_int (gst_value_get_int_range_min (h_val), 3000 + (5 + 7));
626 fail_unless_equals_int (gst_value_get_int_range_max (h_val), 4000 + (5 + 7));
627 gst_caps_unref (adj_caps);
629 /* source => sink becomes smaller */
630 adj_caps = klass->transform_caps (crop, GST_PAD_SINK, caps);
631 fail_unless (adj_caps != NULL);
632 fail_unless (gst_caps_get_size (adj_caps) == 1);
634 gst_structure_get_value (gst_caps_get_structure (adj_caps, 0), "width");
635 fail_unless (w_val != NULL);
636 fail_unless (GST_VALUE_HOLDS_INT_RANGE (w_val));
637 fail_unless_equals_int (gst_value_get_int_range_min (w_val), 1000 - (1 + 3));
638 fail_unless_equals_int (gst_value_get_int_range_max (w_val), 2000 - (1 + 3));
640 gst_structure_get_value (gst_caps_get_structure (adj_caps, 0), "height");
641 fail_unless (h_val != NULL);
642 fail_unless (GST_VALUE_HOLDS_INT_RANGE (h_val));
643 fail_unless_equals_int (gst_value_get_int_range_min (h_val), 3000 - (5 + 7));
644 fail_unless_equals_int (gst_value_get_int_range_max (h_val), 4000 - (5 + 7));
645 gst_caps_unref (adj_caps);
647 /* ========= (3) range (adjustment at boundary) ========================== */
649 gst_structure_set (gst_caps_get_structure (caps, 0),
650 "width", GST_TYPE_INT_RANGE, 2, G_MAXINT,
651 "height", GST_TYPE_INT_RANGE, 2, G_MAXINT, NULL);
653 /* sink => source, source must be bigger if we crop stuff off */
654 adj_caps = klass->transform_caps (crop, GST_PAD_SRC, caps);
655 fail_unless (adj_caps != NULL);
656 fail_unless (gst_caps_get_size (adj_caps) == 1);
658 gst_structure_get_value (gst_caps_get_structure (adj_caps, 0), "width");
659 fail_unless (w_val != NULL);
660 fail_unless (GST_VALUE_HOLDS_INT_RANGE (w_val));
661 fail_unless_equals_int (gst_value_get_int_range_min (w_val), 2 + (1 + 3));
662 fail_unless_equals_int (gst_value_get_int_range_max (w_val), G_MAXINT);
664 gst_structure_get_value (gst_caps_get_structure (adj_caps, 0), "height");
665 fail_unless (h_val != NULL);
666 fail_unless (GST_VALUE_HOLDS_INT_RANGE (h_val));
667 fail_unless_equals_int (gst_value_get_int_range_min (h_val), 2 + (5 + 7));
668 fail_unless_equals_int (gst_value_get_int_range_max (h_val), G_MAXINT);
669 gst_caps_unref (adj_caps);
671 /* source => sink becomes smaller */
672 adj_caps = klass->transform_caps (crop, GST_PAD_SINK, caps);
673 fail_unless (adj_caps != NULL);
674 fail_unless (gst_caps_get_size (adj_caps) == 1);
676 gst_structure_get_value (gst_caps_get_structure (adj_caps, 0), "width");
677 fail_unless (w_val != NULL);
678 fail_unless (GST_VALUE_HOLDS_INT_RANGE (w_val));
679 fail_unless_equals_int (gst_value_get_int_range_min (w_val), 1);
680 fail_unless_equals_int (gst_value_get_int_range_max (w_val),
683 gst_structure_get_value (gst_caps_get_structure (adj_caps, 0), "height");
684 fail_unless (h_val != NULL);
685 fail_unless (GST_VALUE_HOLDS_INT_RANGE (h_val));
686 fail_unless_equals_int (gst_value_get_int_range_min (h_val), 1);
687 fail_unless_equals_int (gst_value_get_int_range_max (h_val),
689 gst_caps_unref (adj_caps);
691 /* ========= (4) list of values ========================================== */
694 GValue list = { 0, };
695 GValue ival = { 0, };
697 g_value_init (&ival, G_TYPE_INT);
698 g_value_init (&list, GST_TYPE_LIST);
699 g_value_set_int (&ival, 2);
700 gst_value_list_append_value (&list, &ival);
701 g_value_set_int (&ival, G_MAXINT);
702 gst_value_list_append_value (&list, &ival);
703 gst_structure_set_value (gst_caps_get_structure (caps, 0), "width", &list);
704 g_value_unset (&list);
705 g_value_unset (&ival);
707 g_value_init (&ival, G_TYPE_INT);
708 g_value_init (&list, GST_TYPE_LIST);
709 g_value_set_int (&ival, 5);
710 gst_value_list_append_value (&list, &ival);
711 g_value_set_int (&ival, 1000);
712 gst_value_list_append_value (&list, &ival);
713 gst_structure_set_value (gst_caps_get_structure (caps, 0), "height", &list);
714 g_value_unset (&list);
715 g_value_unset (&ival);
718 /* sink => source, source must be bigger if we crop stuff off */
719 adj_caps = klass->transform_caps (crop, GST_PAD_SRC, caps);
720 fail_unless (adj_caps != NULL);
721 fail_unless (gst_caps_get_size (adj_caps) == 1);
723 gst_structure_get_value (gst_caps_get_structure (adj_caps, 0), "width");
724 fail_unless (w_val != NULL);
725 fail_unless (GST_VALUE_HOLDS_LIST (w_val));
726 fail_unless_equals_int (notgst_value_list_get_nth_int (w_val, 0),
728 fail_unless_equals_int (notgst_value_list_get_nth_int (w_val, 1), G_MAXINT);
730 gst_structure_get_value (gst_caps_get_structure (adj_caps, 0), "height");
731 fail_unless (h_val != NULL);
732 fail_unless (GST_VALUE_HOLDS_LIST (h_val));
733 fail_unless_equals_int (notgst_value_list_get_nth_int (h_val, 0),
735 fail_unless_equals_int (notgst_value_list_get_nth_int (h_val, 1),
737 gst_caps_unref (adj_caps);
739 /* source => sink becomes smaller */
740 adj_caps = klass->transform_caps (crop, GST_PAD_SINK, caps);
741 fail_unless (adj_caps != NULL);
742 fail_unless (gst_caps_get_size (adj_caps) == 1);
744 gst_structure_get_value (gst_caps_get_structure (adj_caps, 0), "width");
745 fail_unless (w_val != NULL);
746 fail_unless (GST_VALUE_HOLDS_LIST (w_val));
747 fail_unless_equals_int (notgst_value_list_get_nth_int (w_val, 0), 1);
748 fail_unless_equals_int (notgst_value_list_get_nth_int (w_val, 1),
751 gst_structure_get_value (gst_caps_get_structure (adj_caps, 0), "height");
752 fail_unless (h_val != NULL);
753 fail_unless (GST_VALUE_HOLDS_LIST (h_val));
754 fail_unless_equals_int (notgst_value_list_get_nth_int (h_val, 0), 1);
755 fail_unless_equals_int (notgst_value_list_get_nth_int (h_val, 1),
757 gst_caps_unref (adj_caps);
759 gst_caps_unref (caps);
760 videocrop_test_cropping_deinit_context (&ctx);
766 videocrop_suite (void)
768 Suite *s = suite_create ("videocrop");
769 TCase *tc_chain = tcase_create ("general");
772 if (RUNNING_ON_VALGRIND) {
773 /* our tests take quite a long time, so increase
774 * timeout (~25 minutes on my 1.6GHz AMD K7) */
775 tcase_set_timeout (tc_chain, 30 * 60);
779 /* increase timeout, these tests take a long time (60 secs here) */
780 tcase_set_timeout (tc_chain, 2 * 60);
783 suite_add_tcase (s, tc_chain);
784 tcase_add_test (tc_chain, test_crop_to_1x1);
785 tcase_add_test (tc_chain, test_caps_transform);
786 tcase_add_test (tc_chain, test_passthrough);
787 tcase_add_test (tc_chain, test_unit_sizes);
788 tcase_add_loop_test (tc_chain, test_cropping, 0, 25);
794 main (int argc, char **argv)
798 Suite *s = videocrop_suite ();
799 SRunner *sr = srunner_create (s);
802 if (RUNNING_ON_VALGRIND) {
803 /* otherwise valgrind errors out when liboil probes CPU extensions
804 * in oil_init() during which it causes SIGILLs etc. to be fired */
805 g_setenv ("OIL_CPU_FLAGS", "0", 0);
809 gst_check_init (&argc, &argv);
811 srunner_run_all (sr, CK_NORMAL);
812 nf = srunner_ntests_failed (sr);