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 const GstCaps *allowed_caps;
44 srcpad = gst_element_get_static_pad (videocrop, "src");
45 fail_unless (srcpad != NULL);
46 allowed_caps = gst_pad_get_pad_template_caps (srcpad);
47 fail_unless (allowed_caps != NULL);
49 for (i = 0; i < gst_caps_get_size (allowed_caps); ++i) {
50 GstStructure *new_structure;
53 single_caps = gst_caps_new_empty ();
55 gst_structure_copy (gst_caps_get_structure (allowed_caps, i));
56 gst_structure_set (new_structure, "framerate", GST_TYPE_FRACTION,
58 gst_structure_remove_field (new_structure, "width");
59 gst_structure_remove_field (new_structure, "height");
60 gst_caps_append_structure (single_caps, new_structure);
62 /* should be fixed without width/height */
63 fail_unless (gst_caps_is_fixed (single_caps));
65 list = g_list_prepend (list, single_caps);
68 gst_object_unref (srcpad);
73 GST_START_TEST (test_unit_sizes)
75 GstBaseTransformClass *csp_klass, *vcrop_klass;
76 GstElement *videocrop, *csp;
79 videocrop = gst_element_factory_make ("videocrop", "videocrop");
80 fail_unless (videocrop != NULL, "Failed to create videocrop element");
81 vcrop_klass = GST_BASE_TRANSFORM_GET_CLASS (videocrop);
83 csp = gst_element_factory_make ("ffmpegcolorspace", "csp");
84 fail_unless (csp != NULL, "Failed to create ffmpegcolorspace element");
85 csp_klass = GST_BASE_TRANSFORM_GET_CLASS (csp);
87 caps_list = video_crop_get_test_caps (videocrop);
89 for (l = caps_list; l != NULL; l = l->next) {
108 caps = gst_caps_copy (GST_CAPS (l->data));
109 s = gst_caps_get_structure (caps, 0);
110 fail_unless (s != NULL);
112 for (i = 0; i < G_N_ELEMENTS (sizes_to_try); ++i) {
117 gst_structure_set (s, "width", G_TYPE_INT, sizes_to_try[i].width,
118 "height", G_TYPE_INT, sizes_to_try[i].height, NULL);
120 caps_str = gst_caps_to_string (caps);
121 GST_INFO ("Testing unit size for %s", caps_str);
123 /* skip if ffmpegcolorspace doesn't support these caps
124 * (only works with gst-plugins-base 0.10.9.1 or later) */
125 if (!csp_klass->get_unit_size ((GstBaseTransform *) csp, caps, &csp_size)) {
126 GST_INFO ("ffmpegcolorspace does not support format %s", caps_str);
131 fail_unless (vcrop_klass->get_unit_size ((GstBaseTransform *) videocrop,
134 fail_unless (vc_size == csp_size,
135 "videocrop and ffmpegcolorspace return different unit sizes for "
136 "caps %s: vc_size=%d, csp_size=%d", caps_str, vc_size, csp_size);
141 gst_caps_unref (caps);
144 g_list_foreach (caps_list, (GFunc) gst_caps_unref, NULL);
145 g_list_free (caps_list);
147 gst_object_unref (csp);
148 gst_object_unref (videocrop);
155 GstElement *pipeline;
162 } GstVideoCropTestContext;
165 handoff_cb (GstElement * sink, GstBuffer * buf, GstPad * pad,
166 GstVideoCropTestContext * ctx)
170 gst_buffer_replace (&ctx->last_buf, buf);
171 caps = gst_pad_get_current_caps (pad);
172 gst_caps_replace (&ctx->last_caps, caps);
173 gst_caps_unref (caps);
177 videocrop_test_cropping_init_context (GstVideoCropTestContext * ctx)
179 fail_unless (ctx != NULL);
181 ctx->pipeline = gst_pipeline_new ("pipeline");
182 fail_unless (ctx->pipeline != NULL);
183 ctx->src = gst_element_factory_make ("videotestsrc", "src");
184 fail_unless (ctx->src != NULL, "Failed to create videotestsrc element");
185 ctx->filter = gst_element_factory_make ("capsfilter", "filter");
186 fail_unless (ctx->filter != NULL, "Failed to create capsfilter element");
187 ctx->crop = gst_element_factory_make ("videocrop", "crop");
188 fail_unless (ctx->crop != NULL, "Failed to create videocrop element");
189 ctx->sink = gst_element_factory_make ("fakesink", "sink");
190 fail_unless (ctx->sink != NULL, "Failed to create fakesink element");
192 gst_bin_add_many (GST_BIN (ctx->pipeline), ctx->src, ctx->filter,
193 ctx->crop, ctx->sink, NULL);
194 gst_element_link_many (ctx->src, ctx->filter, ctx->crop, ctx->sink, NULL);
196 /* set pattern to 'red' - for our purposes it doesn't matter anyway */
197 g_object_set (ctx->src, "pattern", 4, NULL);
199 g_object_set (ctx->sink, "signal-handoffs", TRUE, NULL);
200 g_signal_connect (ctx->sink, "preroll-handoff", G_CALLBACK (handoff_cb), ctx);
202 ctx->last_buf = NULL;
203 ctx->last_caps = NULL;
205 GST_LOG ("context inited");
209 videocrop_test_cropping_deinit_context (GstVideoCropTestContext * ctx)
211 GST_LOG ("deiniting context");
213 gst_element_set_state (ctx->pipeline, GST_STATE_NULL);
214 gst_object_unref (ctx->pipeline);
215 gst_buffer_replace (&ctx->last_buf, NULL);
216 memset (ctx, 0x00, sizeof (GstVideoCropTestContext));
219 typedef void (*GstVideoCropTestBufferFunc) (GstBuffer * buffer, GstCaps * caps);
222 videocrop_test_cropping (GstVideoCropTestContext * ctx, GstCaps * in_caps,
223 gint left, gint right, gint top, gint bottom,
224 GstVideoCropTestBufferFunc func)
226 GST_LOG ("lrtb = %03u %03u %03u %03u, caps = %" GST_PTR_FORMAT, left, right,
227 top, bottom, in_caps);
229 g_object_set (ctx->filter, "caps", in_caps, NULL);
231 g_object_set (ctx->crop, "left", left, "right", right, "top", top,
232 "bottom", bottom, NULL);
234 /* this will fail if videotestsrc doesn't support our format; we need
235 * videotestsrc from -base CVS 0.10.9.1 with RGBA and AYUV support */
236 fail_unless (gst_element_set_state (ctx->pipeline,
237 GST_STATE_PAUSED) != GST_STATE_CHANGE_FAILURE);
238 fail_unless (gst_element_get_state (ctx->pipeline, NULL, NULL,
239 -1) == GST_STATE_CHANGE_SUCCESS);
242 func (ctx->last_buf, ctx->last_caps);
245 gst_element_set_state (ctx->pipeline, GST_STATE_NULL);
249 check_1x1_buffer (GstBuffer * buf, GstCaps * caps)
253 /* the exact values we check for come from videotestsrc */
254 static const guint yuv_values[] = { 81, 90, 240, 0 };
255 static const guint rgb_values[] = { 0xff, 0, 0, 0 };
259 fail_unless (buf != NULL);
260 fail_unless (caps != NULL);
262 fail_unless (gst_video_info_from_caps (&info, caps));
263 fail_unless (gst_video_frame_map (&frame, &info, buf, GST_MAP_READ));
265 if (GST_VIDEO_INFO_IS_YUV (&info))
270 for (i = 0; i < GST_VIDEO_FRAME_N_COMPONENTS (&frame); i++) {
271 guint8 *data = GST_VIDEO_FRAME_COMP_DATA (&frame, i);
273 fail_unless_equals_int (data[0], values[i]);
277 fail_unless_equals_int ((pixel & rmask) >> rshift, 0xff);
278 fail_unless_equals_int ((pixel & gmask) >> gshift, 0x00);
279 fail_unless_equals_int ((pixel & bmask) >> bshift, 0x00);
283 GST_START_TEST (test_crop_to_1x1)
285 GstVideoCropTestContext ctx;
286 GList *caps_list, *node;
288 videocrop_test_cropping_init_context (&ctx);
290 caps_list = video_crop_get_test_caps (ctx.crop);
292 for (node = caps_list; node != NULL; node = node->next) {
296 caps = gst_caps_copy (GST_CAPS (node->data));
297 s = gst_caps_get_structure (caps, 0);
298 fail_unless (s != NULL);
300 if (g_strcmp0 (gst_structure_get_name (s), "video/x-raw-gray") == 0) {
301 /* videotestsrc does not support this format */
302 gst_caps_unref (caps);
306 GST_INFO ("testing format: %" GST_PTR_FORMAT, caps);
308 gst_structure_set (s, "width", G_TYPE_INT, 160,
309 "height", G_TYPE_INT, 160, NULL);
311 videocrop_test_cropping (&ctx, caps, 159, 0, 159, 0, check_1x1_buffer);
312 /* commented out because they don't really add anything useful check-wise:
313 videocrop_test_cropping (&ctx, caps, 0, 159, 0, 159, check_1x1_buffer);
314 videocrop_test_cropping (&ctx, caps, 159, 0, 0, 159, check_1x1_buffer);
315 videocrop_test_cropping (&ctx, caps, 0, 159, 159, 0, check_1x1_buffer);
317 gst_caps_unref (caps);
319 g_list_foreach (caps_list, (GFunc) gst_caps_unref, NULL);
320 g_list_free (caps_list);
322 videocrop_test_cropping_deinit_context (&ctx);
327 GST_START_TEST (test_cropping)
329 GstVideoCropTestContext ctx;
344 GList *caps_list, *node;
347 videocrop_test_cropping_init_context (&ctx);
349 caps_list = video_crop_get_test_caps (ctx.crop);
350 node = g_list_nth (caps_list, __i__);
356 caps = gst_caps_copy (GST_CAPS (node->data));
357 s = gst_caps_get_structure (caps, 0);
358 fail_unless (s != NULL);
360 /* videotestsrc does not support this format, so ignore it */
361 if (!g_str_equal (gst_structure_get_name (s), "video/x-raw-gray")) {
362 GST_INFO ("testing format: %" GST_PTR_FORMAT, caps);
364 for (i = 0; i < G_N_ELEMENTS (sizes_to_try); ++i) {
367 GST_INFO (" - %d x %d", sizes_to_try[i].width, sizes_to_try[i].height);
369 gst_structure_set (s, "width", G_TYPE_INT, sizes_to_try[i].width,
370 "height", G_TYPE_INT, sizes_to_try[i].height, NULL);
371 in_caps = gst_caps_copy (caps);
373 videocrop_test_cropping (&ctx, in_caps, 0, 0, 0, 0, NULL);
374 videocrop_test_cropping (&ctx, in_caps, 1, 0, 0, 0, NULL);
375 videocrop_test_cropping (&ctx, in_caps, 0, 1, 0, 0, NULL);
376 videocrop_test_cropping (&ctx, in_caps, 0, 0, 1, 0, NULL);
377 videocrop_test_cropping (&ctx, in_caps, 0, 0, 0, 1, NULL);
378 videocrop_test_cropping (&ctx, in_caps, 63, 0, 0, 0, NULL);
379 videocrop_test_cropping (&ctx, in_caps, 0, 63, 0, 0, NULL);
380 videocrop_test_cropping (&ctx, in_caps, 0, 0, 63, 0, NULL);
381 videocrop_test_cropping (&ctx, in_caps, 0, 0, 0, 63, NULL);
382 videocrop_test_cropping (&ctx, in_caps, 63, 0, 0, 1, NULL);
383 videocrop_test_cropping (&ctx, in_caps, 0, 63, 1, 0, NULL);
384 videocrop_test_cropping (&ctx, in_caps, 0, 1, 63, 0, NULL);
385 videocrop_test_cropping (&ctx, in_caps, 1, 0, 0, 63, NULL);
386 videocrop_test_cropping (&ctx, in_caps, 0, 0, 0, 0, NULL);
387 videocrop_test_cropping (&ctx, in_caps, 32, 0, 0, 128, NULL);
388 videocrop_test_cropping (&ctx, in_caps, 0, 32, 128, 0, NULL);
389 videocrop_test_cropping (&ctx, in_caps, 0, 128, 32, 0, NULL);
390 videocrop_test_cropping (&ctx, in_caps, 128, 0, 0, 32, NULL);
391 videocrop_test_cropping (&ctx, in_caps, 1, 1, 1, 1, NULL);
392 videocrop_test_cropping (&ctx, in_caps, 63, 63, 63, 63, NULL);
393 videocrop_test_cropping (&ctx, in_caps, 64, 64, 64, 64, NULL);
395 gst_caps_unref (in_caps);
399 gst_caps_unref (caps);
401 GST_INFO ("no caps #%d", __i__);
403 g_list_foreach (caps_list, (GFunc) gst_caps_unref, NULL);
404 g_list_free (caps_list);
406 videocrop_test_cropping_deinit_context (&ctx);
412 static GstPadProbeReturn
413 buffer_probe_cb (GstPad * pad, GstPadProbeInfo * info, gpointer data)
415 GstBuffer **p_buf = data;
416 GstBuffer *buf = GST_PAD_PROBE_INFO_BUFFER (info);
418 gst_buffer_replace (p_buf, buf);
420 return GST_PAD_PROBE_OK; /* keep data */
423 GST_START_TEST (test_passthrough)
425 GstStateChangeReturn state_ret;
426 GstVideoCropTestContext ctx;
428 GstBuffer *gen_buf = NULL; /* buffer generated by videotestsrc */
430 videocrop_test_cropping_init_context (&ctx);
432 g_object_set (ctx.src, "num-buffers", 1, NULL);
434 srcpad = gst_element_get_static_pad (ctx.src, "src");
435 fail_unless (srcpad != NULL);
436 gst_pad_add_probe (srcpad, GST_PAD_PROBE_TYPE_BUFFER, buffer_probe_cb,
438 gst_object_unref (srcpad);
440 g_object_set (ctx.crop, "left", 0, "right", 0, "top", 0, "bottom", 0, NULL);
442 state_ret = gst_element_set_state (ctx.pipeline, GST_STATE_PAUSED);
443 fail_unless (state_ret != GST_STATE_CHANGE_FAILURE,
444 "couldn't set pipeline to PAUSED state");
446 state_ret = gst_element_get_state (ctx.pipeline, NULL, NULL, -1);
447 fail_unless (state_ret == GST_STATE_CHANGE_SUCCESS,
448 "pipeline failed to go to PAUSED state");
450 fail_unless (gen_buf != NULL);
451 fail_unless (ctx.last_buf != NULL);
453 /* pass through should do nothing */
454 fail_unless (gen_buf == ctx.last_buf);
456 videocrop_test_cropping_deinit_context (&ctx);
458 fail_unless_equals_int (GST_MINI_OBJECT_REFCOUNT_VALUE (gen_buf), 1);
459 gst_buffer_unref (gen_buf);
465 notgst_value_list_get_nth_int (const GValue * list_val, guint n)
469 fail_unless (GST_VALUE_HOLDS_LIST (list_val));
470 fail_unless (n < gst_value_list_get_size (list_val));
472 v = gst_value_list_get_value (list_val, n);
473 fail_unless (G_VALUE_HOLDS_INT (v));
474 return g_value_get_int (v);
477 GST_START_TEST (test_caps_transform)
479 GstVideoCropTestContext ctx;
480 GstBaseTransformClass *klass;
481 GstBaseTransform *crop;
484 GstCaps *caps, *adj_caps;
486 videocrop_test_cropping_init_context (&ctx);
488 crop = GST_BASE_TRANSFORM (ctx.crop);
489 klass = GST_BASE_TRANSFORM_GET_CLASS (ctx.crop);
490 fail_unless (klass != NULL);
492 caps = gst_caps_new_simple ("video/x-raw-yuv",
493 "format", G_TYPE_STRING, "I420",
494 "framerate", GST_TYPE_FRACTION, 1, 1,
495 "width", G_TYPE_INT, 200, "height", G_TYPE_INT, 100, NULL);
497 /* by default, it should be no cropping and hence passthrough */
498 adj_caps = klass->transform_caps (crop, GST_PAD_SRC, caps, NULL);
499 fail_unless (adj_caps != NULL);
500 fail_unless (gst_caps_is_equal (adj_caps, caps));
501 gst_caps_unref (adj_caps);
503 adj_caps = klass->transform_caps (crop, GST_PAD_SINK, caps, NULL);
504 fail_unless (adj_caps != NULL);
505 fail_unless (gst_caps_is_equal (adj_caps, caps));
506 gst_caps_unref (adj_caps);
508 /* make sure that's still true after changing properties back and forth */
509 g_object_set (ctx.crop, "left", 1, "right", 3, "top", 5, "bottom", 7, NULL);
510 g_object_set (ctx.crop, "left", 0, "right", 0, "top", 0, "bottom", 0, NULL);
512 adj_caps = klass->transform_caps (crop, GST_PAD_SRC, caps, NULL);
513 fail_unless (adj_caps != NULL);
514 fail_unless (gst_caps_is_equal (adj_caps, caps));
515 gst_caps_unref (adj_caps);
517 adj_caps = klass->transform_caps (crop, GST_PAD_SINK, caps, NULL);
518 fail_unless (adj_caps != NULL);
519 fail_unless (gst_caps_is_equal (adj_caps, caps));
520 gst_caps_unref (adj_caps);
522 /* now check adjustments made ... */
523 g_object_set (ctx.crop, "left", 1, "right", 3, "top", 5, "bottom", 7, NULL);
525 /* ========= (1) fixed value ============================================= */
527 /* sink => source, source must be bigger if we crop stuff off */
528 adj_caps = klass->transform_caps (crop, GST_PAD_SRC, caps, NULL);
529 fail_unless (adj_caps != NULL);
530 fail_unless (gst_caps_get_size (adj_caps) == 1);
532 gst_structure_get_value (gst_caps_get_structure (adj_caps, 0), "width");
533 fail_unless (w_val != NULL);
534 fail_unless (G_VALUE_HOLDS_INT (w_val));
535 fail_unless_equals_int (g_value_get_int (w_val), 200 + (1 + 3));
537 gst_structure_get_value (gst_caps_get_structure (adj_caps, 0), "height");
538 fail_unless (h_val != NULL);
539 fail_unless (G_VALUE_HOLDS_INT (h_val));
540 fail_unless_equals_int (g_value_get_int (h_val), 100 + (5 + 7));
541 gst_caps_unref (adj_caps);
543 /* source => sink becomes smaller */
544 adj_caps = klass->transform_caps (crop, GST_PAD_SINK, caps, NULL);
545 fail_unless (adj_caps != NULL);
546 fail_unless (gst_caps_get_size (adj_caps) == 1);
548 gst_structure_get_value (gst_caps_get_structure (adj_caps, 0), "width");
549 fail_unless (w_val != NULL);
550 fail_unless (G_VALUE_HOLDS_INT (w_val));
551 fail_unless_equals_int (g_value_get_int (w_val), 200 - (1 + 3));
553 gst_structure_get_value (gst_caps_get_structure (adj_caps, 0), "height");
554 fail_unless (h_val != NULL);
555 fail_unless (G_VALUE_HOLDS_INT (h_val));
556 fail_unless_equals_int (g_value_get_int (h_val), 100 - (5 + 7));
557 gst_caps_unref (adj_caps);
559 /* ========= (2) range (simple adjustment) =============================== */
561 gst_structure_set (gst_caps_get_structure (caps, 0),
562 "width", GST_TYPE_INT_RANGE, 1000, 2000,
563 "height", GST_TYPE_INT_RANGE, 3000, 4000, NULL);
565 /* sink => source, source must be bigger if we crop stuff off */
566 adj_caps = klass->transform_caps (crop, GST_PAD_SRC, caps, NULL);
567 fail_unless (adj_caps != NULL);
568 fail_unless (gst_caps_get_size (adj_caps) == 1);
570 gst_structure_get_value (gst_caps_get_structure (adj_caps, 0), "width");
571 fail_unless (w_val != NULL);
572 fail_unless (GST_VALUE_HOLDS_INT_RANGE (w_val));
573 fail_unless_equals_int (gst_value_get_int_range_min (w_val), 1000 + (1 + 3));
574 fail_unless_equals_int (gst_value_get_int_range_max (w_val), 2000 + (1 + 3));
576 gst_structure_get_value (gst_caps_get_structure (adj_caps, 0), "height");
577 fail_unless (h_val != NULL);
578 fail_unless (GST_VALUE_HOLDS_INT_RANGE (h_val));
579 fail_unless_equals_int (gst_value_get_int_range_min (h_val), 3000 + (5 + 7));
580 fail_unless_equals_int (gst_value_get_int_range_max (h_val), 4000 + (5 + 7));
581 gst_caps_unref (adj_caps);
583 /* source => sink becomes smaller */
584 adj_caps = klass->transform_caps (crop, GST_PAD_SINK, caps, NULL);
585 fail_unless (adj_caps != NULL);
586 fail_unless (gst_caps_get_size (adj_caps) == 1);
588 gst_structure_get_value (gst_caps_get_structure (adj_caps, 0), "width");
589 fail_unless (w_val != NULL);
590 fail_unless (GST_VALUE_HOLDS_INT_RANGE (w_val));
591 fail_unless_equals_int (gst_value_get_int_range_min (w_val), 1000 - (1 + 3));
592 fail_unless_equals_int (gst_value_get_int_range_max (w_val), 2000 - (1 + 3));
594 gst_structure_get_value (gst_caps_get_structure (adj_caps, 0), "height");
595 fail_unless (h_val != NULL);
596 fail_unless (GST_VALUE_HOLDS_INT_RANGE (h_val));
597 fail_unless_equals_int (gst_value_get_int_range_min (h_val), 3000 - (5 + 7));
598 fail_unless_equals_int (gst_value_get_int_range_max (h_val), 4000 - (5 + 7));
599 gst_caps_unref (adj_caps);
601 /* ========= (3) range (adjustment at boundary) ========================== */
603 gst_structure_set (gst_caps_get_structure (caps, 0),
604 "width", GST_TYPE_INT_RANGE, 2, G_MAXINT,
605 "height", GST_TYPE_INT_RANGE, 2, G_MAXINT, NULL);
607 /* sink => source, source must be bigger if we crop stuff off */
608 adj_caps = klass->transform_caps (crop, GST_PAD_SRC, caps, NULL);
609 fail_unless (adj_caps != NULL);
610 fail_unless (gst_caps_get_size (adj_caps) == 1);
612 gst_structure_get_value (gst_caps_get_structure (adj_caps, 0), "width");
613 fail_unless (w_val != NULL);
614 fail_unless (GST_VALUE_HOLDS_INT_RANGE (w_val));
615 fail_unless_equals_int (gst_value_get_int_range_min (w_val), 2 + (1 + 3));
616 fail_unless_equals_int (gst_value_get_int_range_max (w_val), G_MAXINT);
618 gst_structure_get_value (gst_caps_get_structure (adj_caps, 0), "height");
619 fail_unless (h_val != NULL);
620 fail_unless (GST_VALUE_HOLDS_INT_RANGE (h_val));
621 fail_unless_equals_int (gst_value_get_int_range_min (h_val), 2 + (5 + 7));
622 fail_unless_equals_int (gst_value_get_int_range_max (h_val), G_MAXINT);
623 gst_caps_unref (adj_caps);
625 /* source => sink becomes smaller */
626 adj_caps = klass->transform_caps (crop, GST_PAD_SINK, caps, NULL);
627 fail_unless (adj_caps != NULL);
628 fail_unless (gst_caps_get_size (adj_caps) == 1);
630 gst_structure_get_value (gst_caps_get_structure (adj_caps, 0), "width");
631 fail_unless (w_val != NULL);
632 fail_unless (GST_VALUE_HOLDS_INT_RANGE (w_val));
633 fail_unless_equals_int (gst_value_get_int_range_min (w_val), 1);
634 fail_unless_equals_int (gst_value_get_int_range_max (w_val),
637 gst_structure_get_value (gst_caps_get_structure (adj_caps, 0), "height");
638 fail_unless (h_val != NULL);
639 fail_unless (GST_VALUE_HOLDS_INT_RANGE (h_val));
640 fail_unless_equals_int (gst_value_get_int_range_min (h_val), 1);
641 fail_unless_equals_int (gst_value_get_int_range_max (h_val),
643 gst_caps_unref (adj_caps);
645 /* ========= (4) list of values ========================================== */
648 GValue list = { 0, };
649 GValue ival = { 0, };
651 g_value_init (&ival, G_TYPE_INT);
652 g_value_init (&list, GST_TYPE_LIST);
653 g_value_set_int (&ival, 2);
654 gst_value_list_append_value (&list, &ival);
655 g_value_set_int (&ival, G_MAXINT);
656 gst_value_list_append_value (&list, &ival);
657 gst_structure_set_value (gst_caps_get_structure (caps, 0), "width", &list);
658 g_value_unset (&list);
659 g_value_unset (&ival);
661 g_value_init (&ival, G_TYPE_INT);
662 g_value_init (&list, GST_TYPE_LIST);
663 g_value_set_int (&ival, 5);
664 gst_value_list_append_value (&list, &ival);
665 g_value_set_int (&ival, 1000);
666 gst_value_list_append_value (&list, &ival);
667 gst_structure_set_value (gst_caps_get_structure (caps, 0), "height", &list);
668 g_value_unset (&list);
669 g_value_unset (&ival);
672 /* sink => source, source must be bigger if we crop stuff off */
673 adj_caps = klass->transform_caps (crop, GST_PAD_SRC, caps, NULL);
674 fail_unless (adj_caps != NULL);
675 fail_unless (gst_caps_get_size (adj_caps) == 1);
677 gst_structure_get_value (gst_caps_get_structure (adj_caps, 0), "width");
678 fail_unless (w_val != NULL);
679 fail_unless (GST_VALUE_HOLDS_LIST (w_val));
680 fail_unless_equals_int (notgst_value_list_get_nth_int (w_val, 0),
682 fail_unless_equals_int (notgst_value_list_get_nth_int (w_val, 1), G_MAXINT);
684 gst_structure_get_value (gst_caps_get_structure (adj_caps, 0), "height");
685 fail_unless (h_val != NULL);
686 fail_unless (GST_VALUE_HOLDS_LIST (h_val));
687 fail_unless_equals_int (notgst_value_list_get_nth_int (h_val, 0),
689 fail_unless_equals_int (notgst_value_list_get_nth_int (h_val, 1),
691 gst_caps_unref (adj_caps);
693 /* source => sink becomes smaller */
694 adj_caps = klass->transform_caps (crop, GST_PAD_SINK, caps, NULL);
695 fail_unless (adj_caps != NULL);
696 fail_unless (gst_caps_get_size (adj_caps) == 1);
698 gst_structure_get_value (gst_caps_get_structure (adj_caps, 0), "width");
699 fail_unless (w_val != NULL);
700 fail_unless (GST_VALUE_HOLDS_LIST (w_val));
701 fail_unless_equals_int (notgst_value_list_get_nth_int (w_val, 0), 1);
702 fail_unless_equals_int (notgst_value_list_get_nth_int (w_val, 1),
705 gst_structure_get_value (gst_caps_get_structure (adj_caps, 0), "height");
706 fail_unless (h_val != NULL);
707 fail_unless (GST_VALUE_HOLDS_LIST (h_val));
708 fail_unless_equals_int (notgst_value_list_get_nth_int (h_val, 0), 1);
709 fail_unless_equals_int (notgst_value_list_get_nth_int (h_val, 1),
711 gst_caps_unref (adj_caps);
713 gst_caps_unref (caps);
714 videocrop_test_cropping_deinit_context (&ctx);
720 videocrop_suite (void)
722 Suite *s = suite_create ("videocrop");
723 TCase *tc_chain = tcase_create ("general");
726 if (RUNNING_ON_VALGRIND) {
727 /* our tests take quite a long time, so increase
728 * timeout (~25 minutes on my 1.6GHz AMD K7) */
729 tcase_set_timeout (tc_chain, 30 * 60);
733 /* increase timeout, these tests take a long time (60 secs here) */
734 tcase_set_timeout (tc_chain, 2 * 60);
737 suite_add_tcase (s, tc_chain);
738 tcase_add_test (tc_chain, test_crop_to_1x1);
739 tcase_add_test (tc_chain, test_caps_transform);
740 tcase_add_test (tc_chain, test_passthrough);
741 tcase_add_test (tc_chain, test_unit_sizes);
742 tcase_add_loop_test (tc_chain, test_cropping, 0, 25);
748 main (int argc, char **argv)
752 Suite *s = videocrop_suite ();
753 SRunner *sr = srunner_create (s);
756 if (RUNNING_ON_VALGRIND) {
757 /* otherwise valgrind errors out when liboil probes CPU extensions
758 * in oil_init() during which it causes SIGILLs etc. to be fired */
759 g_setenv ("OIL_CPU_FLAGS", "0", 0);
763 gst_check_init (&argc, &argv);
765 srunner_run_all (sr, CK_NORMAL);
766 nf = srunner_ntests_failed (sr);