1 /* GStreamer unit test for video
3 * Copyright (C) <2003> David A. Schleef <ds@schleef.org>
4 * Copyright (C) <2006> Jan Schmidt <thaytan@mad.scientist.com>
5 * Copyright (C) <2008,2011> Tim-Philipp Müller <tim centricular net>
6 * Copyright (C) <2012> Collabora Ltd. <tim.muller@collabora.co.uk>
8 * This library is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU Library General Public
10 * License as published by the Free Software Foundation; either
11 * version 2 of the License, or (at your option) any later version.
13 * This library is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 * Library General Public License for more details.
18 * You should have received a copy of the GNU Library General Public
19 * License along with this library; if not, write to the
20 * Free Software Foundation, Inc., 51 Franklin St, Fifth Floor,
21 * Boston, MA 02110-1301, USA.
29 # include <valgrind/valgrind.h>
32 #include <gst/check/gstcheck.h>
34 #include <gst/video/video.h>
35 #include <gst/video/gstvideometa.h>
36 #include <gst/video/video-overlay-composition.h>
39 /* These are from the current/old videotestsrc; we check our new public API
40 * in libgstvideo against the old one to make sure the sizes and offsets
43 typedef struct paintinfo_struct paintinfo;
44 struct paintinfo_struct
46 unsigned char *dest; /* pointer to first byte of video data */
47 unsigned char *yp, *up, *vp; /* pointers to first byte of each component
48 * for both packed/planar YUV and RGB */
49 unsigned char *ap; /* pointer to first byte of alpha component */
50 unsigned char *endptr; /* pointer to byte beyond last video data */
58 struct fourcc_list_struct
63 void (*paint_setup) (paintinfo * p, unsigned char *dest);
66 static void paint_setup_I420 (paintinfo * p, unsigned char *dest);
67 static void paint_setup_YV12 (paintinfo * p, unsigned char *dest);
68 static void paint_setup_YUY2 (paintinfo * p, unsigned char *dest);
69 static void paint_setup_UYVY (paintinfo * p, unsigned char *dest);
70 static void paint_setup_YVYU (paintinfo * p, unsigned char *dest);
71 static void paint_setup_IYU2 (paintinfo * p, unsigned char *dest);
72 static void paint_setup_Y41B (paintinfo * p, unsigned char *dest);
73 static void paint_setup_Y42B (paintinfo * p, unsigned char *dest);
74 static void paint_setup_GRAY8 (paintinfo * p, unsigned char *dest);
75 static void paint_setup_AYUV (paintinfo * p, unsigned char *dest);
78 static void paint_setup_IMC1 (paintinfo * p, unsigned char *dest);
79 static void paint_setup_IMC2 (paintinfo * p, unsigned char *dest);
80 static void paint_setup_IMC3 (paintinfo * p, unsigned char *dest);
81 static void paint_setup_IMC4 (paintinfo * p, unsigned char *dest);
83 static void paint_setup_YUV9 (paintinfo * p, unsigned char *dest);
84 static void paint_setup_YVU9 (paintinfo * p, unsigned char *dest);
86 int fourcc_get_size (struct fourcc_list_struct *fourcc, int w, int h);
88 struct fourcc_list_struct fourcc_list[] = {
90 {"YUY2", "YUY2", 16, paint_setup_YUY2},
91 {"UYVY", "UYVY", 16, paint_setup_UYVY},
92 {"Y422", "Y422", 16, paint_setup_UYVY},
93 {"UYNV", "UYNV", 16, paint_setup_UYVY}, /* FIXME: UYNV? */
94 {"YVYU", "YVYU", 16, paint_setup_YVYU},
95 {"AYUV", "AYUV", 32, paint_setup_AYUV},
98 /*{ "IUYV", "IUY2", 16, paint_setup_YVYU }, */
101 /*{ "cyuv", "cyuv", 16, paint_setup_YVYU }, */
103 /*{ "Y41P", "Y41P", 12, paint_setup_YVYU }, */
106 /*{ "IY41", "IY41", 12, paint_setup_YVYU }, */
108 /*{ "Y211", "Y211", 8, paint_setup_YVYU }, */
110 /*{ "Y41T", "Y41T", 12, paint_setup_YVYU }, */
111 /*{ "Y42P", "Y42P", 16, paint_setup_YVYU }, */
112 /*{ "CLJR", "CLJR", 8, paint_setup_YVYU }, */
113 /*{ "IYU1", "IYU1", 12, paint_setup_YVYU }, */
114 {"IYU2", "IYU2", 24, paint_setup_IYU2},
118 {"YVU9", "YVU9", 9, paint_setup_YVU9},
120 {"YUV9", "YUV9", 9, paint_setup_YUV9},
123 {"YV12", "YV12", 12, paint_setup_YV12},
125 {"I420", "I420", 12, paint_setup_I420},
130 {"IMC1", "IMC1", 16, paint_setup_IMC1},
132 {"IMC2", "IMC2", 12, paint_setup_IMC2},
134 {"IMC3", "IMC3", 16, paint_setup_IMC3},
136 {"IMC4", "IMC4", 12, paint_setup_IMC4},
140 {"Y41B", "Y41B", 12, paint_setup_Y41B},
142 {"Y42B", "Y42B", 16, paint_setup_Y42B},
143 /* GRAY8 grayscale */
144 {"GRAY8", "GRAY8", 8, paint_setup_GRAY8}
147 /* returns the size in bytes for one video frame of the given dimensions
148 * given the fourcc */
150 fourcc_get_size (struct fourcc_list_struct *fourcc, int w, int h)
152 paintinfo pi = { NULL, };
158 fourcc->paint_setup (p, NULL);
160 return GPOINTER_TO_INT (p->endptr);
164 paint_setup_I420 (paintinfo * p, unsigned char *dest)
167 p->ystride = GST_ROUND_UP_4 (p->width);
168 p->up = p->yp + p->ystride * GST_ROUND_UP_2 (p->height);
169 p->ustride = GST_ROUND_UP_8 (p->width) / 2;
170 p->vp = p->up + p->ustride * GST_ROUND_UP_2 (p->height) / 2;
171 p->vstride = GST_ROUND_UP_8 (p->ystride) / 2;
172 p->endptr = p->vp + p->vstride * GST_ROUND_UP_2 (p->height) / 2;
176 paint_setup_YV12 (paintinfo * p, unsigned char *dest)
179 p->ystride = GST_ROUND_UP_4 (p->width);
180 p->vp = p->yp + p->ystride * GST_ROUND_UP_2 (p->height);
181 p->vstride = GST_ROUND_UP_8 (p->ystride) / 2;
182 p->up = p->vp + p->vstride * GST_ROUND_UP_2 (p->height) / 2;
183 p->ustride = GST_ROUND_UP_8 (p->ystride) / 2;
184 p->endptr = p->up + p->ustride * GST_ROUND_UP_2 (p->height) / 2;
188 paint_setup_AYUV (paintinfo * p, unsigned char *dest)
194 p->ystride = p->width * 4;
195 p->endptr = dest + p->ystride * p->height;
199 paint_setup_YUY2 (paintinfo * p, unsigned char *dest)
204 p->ystride = GST_ROUND_UP_2 (p->width) * 2;
205 p->endptr = dest + p->ystride * p->height;
209 paint_setup_UYVY (paintinfo * p, unsigned char *dest)
214 p->ystride = GST_ROUND_UP_2 (p->width) * 2;
215 p->endptr = dest + p->ystride * p->height;
219 paint_setup_YVYU (paintinfo * p, unsigned char *dest)
224 p->ystride = GST_ROUND_UP_2 (p->width) * 2;
225 p->endptr = dest + p->ystride * p->height;
229 paint_setup_IYU2 (paintinfo * p, unsigned char *dest)
235 p->ystride = GST_ROUND_UP_4 (p->width * 3);
236 p->endptr = dest + p->ystride * p->height;
240 paint_setup_Y41B (paintinfo * p, unsigned char *dest)
243 p->ystride = GST_ROUND_UP_4 (p->width);
244 p->up = p->yp + p->ystride * p->height;
245 p->ustride = GST_ROUND_UP_16 (p->width) / 4;
246 p->vp = p->up + p->ustride * p->height;
247 p->vstride = GST_ROUND_UP_16 (p->width) / 4;
248 p->endptr = p->vp + p->vstride * p->height;
252 paint_setup_Y42B (paintinfo * p, unsigned char *dest)
255 p->ystride = GST_ROUND_UP_4 (p->width);
256 p->up = p->yp + p->ystride * p->height;
257 p->ustride = GST_ROUND_UP_8 (p->width) / 2;
258 p->vp = p->up + p->ustride * p->height;
259 p->vstride = GST_ROUND_UP_8 (p->width) / 2;
260 p->endptr = p->vp + p->vstride * p->height;
264 paint_setup_GRAY8 (paintinfo * p, unsigned char *dest)
268 p->ystride = GST_ROUND_UP_4 (p->width);
269 p->endptr = dest + p->ystride * p->height;
274 paint_setup_IMC1 (paintinfo * p, unsigned char *dest)
277 p->up = dest + p->width * p->height;
278 p->vp = dest + p->width * p->height + p->width * p->height / 2;
282 paint_setup_IMC2 (paintinfo * p, unsigned char *dest)
285 p->vp = dest + p->width * p->height;
286 p->up = dest + p->width * p->height + p->width / 2;
290 paint_setup_IMC3 (paintinfo * p, unsigned char *dest)
293 p->up = dest + p->width * p->height + p->width * p->height / 2;
294 p->vp = dest + p->width * p->height;
298 paint_setup_IMC4 (paintinfo * p, unsigned char *dest)
301 p->vp = dest + p->width * p->height + p->width / 2;
302 p->up = dest + p->width * p->height;
307 paint_setup_YVU9 (paintinfo * p, unsigned char *dest)
310 p->ystride = GST_ROUND_UP_4 (p->width);
311 p->vp = p->yp + p->ystride * p->height;
312 p->vstride = GST_ROUND_UP_4 (p->ystride / 4);
313 p->up = p->vp + p->vstride * (GST_ROUND_UP_4 (p->height) / 4);
314 p->ustride = GST_ROUND_UP_4 (p->ystride / 4);
315 p->endptr = p->up + p->ustride * (GST_ROUND_UP_4 (p->height) / 4);
319 paint_setup_YUV9 (paintinfo * p, unsigned char *dest)
322 p->ystride = GST_ROUND_UP_4 (p->width);
323 p->up = p->yp + p->ystride * p->height;
324 p->ustride = GST_ROUND_UP_4 (p->ystride / 4);
325 p->vp = p->up + p->ustride * (GST_ROUND_UP_4 (p->height) / 4);
326 p->vstride = GST_ROUND_UP_4 (p->ystride / 4);
327 p->endptr = p->vp + p->vstride * (GST_ROUND_UP_4 (p->height) / 4);
330 #define gst_video_format_is_packed video_format_is_packed
332 video_format_is_packed (GstVideoFormat fmt)
335 case GST_VIDEO_FORMAT_I420:
336 case GST_VIDEO_FORMAT_YV12:
337 case GST_VIDEO_FORMAT_Y41B:
338 case GST_VIDEO_FORMAT_Y42B:
339 case GST_VIDEO_FORMAT_GRAY8:
340 case GST_VIDEO_FORMAT_YUV9:
341 case GST_VIDEO_FORMAT_YVU9:
343 case GST_VIDEO_FORMAT_IYU1:
344 case GST_VIDEO_FORMAT_IYU2:
345 case GST_VIDEO_FORMAT_YUY2:
346 case GST_VIDEO_FORMAT_YVYU:
347 case GST_VIDEO_FORMAT_UYVY:
348 case GST_VIDEO_FORMAT_VYUY:
349 case GST_VIDEO_FORMAT_AYUV:
350 case GST_VIDEO_FORMAT_RGBx:
351 case GST_VIDEO_FORMAT_BGRx:
352 case GST_VIDEO_FORMAT_xRGB:
353 case GST_VIDEO_FORMAT_xBGR:
354 case GST_VIDEO_FORMAT_RGBA:
355 case GST_VIDEO_FORMAT_BGRA:
356 case GST_VIDEO_FORMAT_ARGB:
357 case GST_VIDEO_FORMAT_ABGR:
358 case GST_VIDEO_FORMAT_RGB:
359 case GST_VIDEO_FORMAT_BGR:
360 case GST_VIDEO_FORMAT_RGB8P:
363 g_return_val_if_reached (FALSE);
369 get_num_formats (void)
371 gint num_formats = 100;
372 fail_unless (gst_video_format_to_string (num_formats) == NULL);
373 while (gst_video_format_to_string (num_formats) == NULL)
375 GST_INFO ("number of known video formats: %d", num_formats);
376 return num_formats + 1;
379 GST_START_TEST (test_video_formats_all)
382 const GValue *val, *list_val;
384 guint num, n, num_formats;
386 num_formats = get_num_formats ();
388 caps = gst_caps_from_string ("video/x-raw, format=" GST_VIDEO_FORMATS_ALL);
389 s = gst_caps_get_structure (caps, 0);
390 val = gst_structure_get_value (s, "format");
391 fail_unless (val != NULL);
392 fail_unless (GST_VALUE_HOLDS_LIST (val));
393 num = gst_value_list_get_size (val);
394 fail_unless (num > 0);
395 for (n = 0; n < num; ++n) {
396 const gchar *fmt_str;
398 list_val = gst_value_list_get_value (val, n);
399 fail_unless (G_VALUE_HOLDS_STRING (list_val));
400 fmt_str = g_value_get_string (list_val);
401 GST_INFO ("format: %s", fmt_str);
402 fail_if (gst_video_format_from_string (fmt_str) ==
403 GST_VIDEO_FORMAT_UNKNOWN);
405 /* Take into account GST_VIDEO_FORMAT_ENCODED and UNKNOWN */
406 fail_unless_equals_int (num, num_formats - 2);
408 gst_caps_unref (caps);
415 GST_START_TEST (test_video_formats_pack_unpack)
417 guint n, num_formats;
419 num_formats = get_num_formats ();
421 for (n = GST_VIDEO_FORMAT_ENCODED + 1; n < num_formats; ++n) {
422 const GstVideoFormatInfo *vfinfo, *unpackinfo;
423 GstVideoFormat fmt = n;
425 gpointer data[GST_VIDEO_MAX_PLANES];
426 gint stride[GST_VIDEO_MAX_PLANES];
427 guint8 *vdata, *unpack_data;
428 gsize vsize, unpack_size;
431 GST_INFO ("testing %s", gst_video_format_to_string (fmt));
433 vfinfo = gst_video_format_get_info (fmt);
434 fail_unless (vfinfo != NULL);
436 unpackinfo = gst_video_format_get_info (vfinfo->unpack_format);
437 fail_unless (unpackinfo != NULL);
439 gst_video_info_init (&vinfo);
440 fail_unless (gst_video_info_set_format (&vinfo, fmt, WIDTH, HEIGHT));
441 vsize = GST_VIDEO_INFO_SIZE (&vinfo);
442 vdata = g_malloc (vsize);
443 memset (vdata, 0x99, vsize);
445 g_assert (vfinfo->pack_lines == 1);
448 GST_VIDEO_FORMAT_INFO_BITS (unpackinfo) *
449 GST_VIDEO_FORMAT_INFO_N_COMPONENTS (unpackinfo) *
450 GST_ROUND_UP_16 (WIDTH);
451 unpack_data = g_malloc (unpack_size);
453 for (p = 0; p < GST_VIDEO_INFO_N_PLANES (&vinfo); ++p) {
454 data[p] = vdata + GST_VIDEO_INFO_PLANE_OFFSET (&vinfo, p);
455 stride[p] = GST_VIDEO_INFO_PLANE_STRIDE (&vinfo, p);
459 vfinfo->unpack_func (vfinfo, GST_VIDEO_PACK_FLAG_NONE, unpack_data, data,
460 stride, 0, 0, WIDTH);
463 vfinfo->pack_func (vfinfo, GST_VIDEO_PACK_FLAG_NONE, unpack_data,
464 unpack_size, data, stride, GST_VIDEO_CHROMA_SITE_UNKNOWN, 0, WIDTH);
467 vfinfo->unpack_func (vfinfo, GST_VIDEO_PACK_FLAG_NONE, unpack_data, data,
468 stride, 0, HEIGHT - 1, WIDTH);
471 vfinfo->pack_func (vfinfo, GST_VIDEO_PACK_FLAG_NONE, unpack_data,
472 unpack_size, data, stride, GST_VIDEO_CHROMA_SITE_UNKNOWN, HEIGHT - 1,
475 g_free (unpack_data);
484 GST_START_TEST (test_video_formats)
488 for (i = 0; i < G_N_ELEMENTS (fourcc_list); ++i) {
489 const GstVideoFormatInfo *vf_info;
495 s = fourcc_list[i].fourcc;
496 fourcc = GST_MAKE_FOURCC (s[0], s[1], s[2], s[3]);
497 fmt = gst_video_format_from_fourcc (fourcc);
499 if (fmt == GST_VIDEO_FORMAT_UNKNOWN) {
500 GST_DEBUG ("Unknown format %s, skipping tests", fourcc_list[i].fourcc);
504 vf_info = gst_video_format_get_info (fmt);
505 fail_unless (vf_info != NULL);
507 fail_unless_equals_int (GST_VIDEO_FORMAT_INFO_FORMAT (vf_info), fmt);
509 GST_INFO ("Fourcc %s, packed=%d", fourcc_list[i].fourcc,
510 gst_video_format_is_packed (fmt));
512 fail_unless (GST_VIDEO_FORMAT_INFO_IS_YUV (vf_info));
514 /* use any non-NULL pointer so we can compare against NULL */
516 paintinfo paintinfo = { 0, };
517 fourcc_list[i].paint_setup (&paintinfo, (unsigned char *) s);
518 if (paintinfo.ap != NULL) {
519 fail_unless (GST_VIDEO_FORMAT_INFO_HAS_ALPHA (vf_info));
521 fail_if (GST_VIDEO_FORMAT_INFO_HAS_ALPHA (vf_info));
525 for (w = 1; w <= 65; ++w) {
526 for (h = 1; h <= 65; ++h) {
528 paintinfo paintinfo = { 0, };
529 guint off0, off1, off2, off3;
530 guint cs0, cs1, cs2, cs3;
533 GST_LOG ("%s, %dx%d", fourcc_list[i].fourcc, w, h);
535 gst_video_info_init (&vinfo);
536 fail_unless (gst_video_info_set_format (&vinfo, fmt, w, h));
539 paintinfo.height = h;
540 fourcc_list[i].paint_setup (&paintinfo, NULL);
541 fail_unless_equals_int (GST_VIDEO_INFO_COMP_STRIDE (&vinfo, 0),
543 if (!gst_video_format_is_packed (fmt)
544 && GST_VIDEO_INFO_N_PLANES (&vinfo) <= 2) {
546 fail_unless_equals_int (GST_VIDEO_INFO_COMP_STRIDE (&vinfo, 1),
548 fail_unless_equals_int (GST_VIDEO_INFO_COMP_STRIDE (&vinfo, 2),
550 /* check component_width * height against offsets/size somehow? */
553 size = GST_VIDEO_INFO_SIZE (&vinfo);
554 off0 = GST_VIDEO_INFO_COMP_OFFSET (&vinfo, 0);
555 off1 = GST_VIDEO_INFO_COMP_OFFSET (&vinfo, 1);
556 off2 = GST_VIDEO_INFO_COMP_OFFSET (&vinfo, 2);
558 GST_TRACE ("size %d <> %d", size, GPOINTER_TO_INT (paintinfo.endptr));
559 GST_TRACE ("off0 %d <> %d", off0, GPOINTER_TO_INT (paintinfo.yp));
560 GST_TRACE ("off1 %d <> %d", off1, GPOINTER_TO_INT (paintinfo.up));
561 GST_TRACE ("off2 %d <> %d", off2, GPOINTER_TO_INT (paintinfo.vp));
563 fail_unless_equals_int (size, GPOINTER_TO_INT (paintinfo.endptr));
564 fail_unless_equals_int (off0, GPOINTER_TO_INT (paintinfo.yp));
565 fail_unless_equals_int (off1, GPOINTER_TO_INT (paintinfo.up));
566 fail_unless_equals_int (off2, GPOINTER_TO_INT (paintinfo.vp));
568 /* should be 0 if there's no alpha component */
569 off3 = GST_VIDEO_INFO_COMP_OFFSET (&vinfo, 3);
570 fail_unless_equals_int (off3, GPOINTER_TO_INT (paintinfo.ap));
572 cs0 = GST_VIDEO_INFO_COMP_WIDTH (&vinfo, 0) *
573 GST_VIDEO_INFO_COMP_HEIGHT (&vinfo, 0);
574 cs1 = GST_VIDEO_INFO_COMP_WIDTH (&vinfo, 1) *
575 GST_VIDEO_INFO_COMP_HEIGHT (&vinfo, 1);
576 cs2 = GST_VIDEO_INFO_COMP_WIDTH (&vinfo, 2) *
577 GST_VIDEO_INFO_COMP_HEIGHT (&vinfo, 2);
579 /* GST_LOG ("cs0=%d,cs1=%d,cs2=%d,off0=%d,off1=%d,off2=%d,size=%d",
580 cs0, cs1, cs2, off0, off1, off2, size); */
582 if (!gst_video_format_is_packed (fmt))
583 fail_unless (cs0 <= off1);
585 if (GST_VIDEO_FORMAT_INFO_HAS_ALPHA (vinfo.finfo)) {
586 cs3 = GST_VIDEO_INFO_COMP_WIDTH (&vinfo, 3) *
587 GST_VIDEO_INFO_COMP_HEIGHT (&vinfo, 2);
588 fail_unless (cs3 < size);
589 /* U/V/alpha shouldn't take up more space than the Y component */
590 fail_if (cs1 > cs0, "cs1 (%d) should be <= cs0 (%d)", cs1, cs0);
591 fail_if (cs2 > cs0, "cs2 (%d) should be <= cs0 (%d)", cs2, cs0);
592 fail_if (cs3 > cs0, "cs3 (%d) should be <= cs0 (%d)", cs3, cs0);
594 /* all components together shouldn't take up more space than size */
595 fail_unless (cs0 + cs1 + cs2 + cs3 <= size);
597 /* U/V shouldn't take up more space than the Y component */
598 fail_if (cs1 > cs0, "cs1 (%d) should be <= cs0 (%d)", cs1, cs0);
599 fail_if (cs2 > cs0, "cs2 (%d) should be <= cs0 (%d)", cs2, cs0);
601 /* all components together shouldn't take up more space than size */
602 fail_unless (cs0 + cs1 + cs2 <= size,
603 "cs0 (%d) + cs1 (%d) + cs2 (%d) should be <= size (%d)",
604 cs0, cs1, cs2, size);
613 GST_START_TEST (test_video_formats_overflow)
617 gst_video_info_init (&vinfo);
619 fail_unless (gst_video_info_set_format (&vinfo, GST_VIDEO_FORMAT_ARGB, 32768,
621 /* fails due to simplification: we forbid some things that would in theory be fine.
622 * We assume a 128 byte alignment for the width currently
623 * fail_unless (gst_video_info_set_format (&vinfo, GST_VIDEO_FORMAT_ARGB, 32767, 32768));
625 fail_if (gst_video_info_set_format (&vinfo, GST_VIDEO_FORMAT_ARGB, 32768,
628 fail_if (gst_video_info_set_format (&vinfo, GST_VIDEO_FORMAT_ARGB,
629 G_MAXINT / 2, G_MAXINT));
630 fail_if (gst_video_info_set_format (&vinfo, GST_VIDEO_FORMAT_ARGB, G_MAXINT,
632 fail_if (gst_video_info_set_format (&vinfo, GST_VIDEO_FORMAT_ARGB,
633 G_MAXINT / 2, G_MAXINT / 2));
634 fail_if (gst_video_info_set_format (&vinfo, GST_VIDEO_FORMAT_ARGB, G_MAXINT,
636 fail_if (gst_video_info_set_format (&vinfo, GST_VIDEO_FORMAT_ARGB,
637 G_MAXUINT / 2, G_MAXUINT));
638 fail_if (gst_video_info_set_format (&vinfo, GST_VIDEO_FORMAT_ARGB, G_MAXUINT,
640 fail_if (gst_video_info_set_format (&vinfo, GST_VIDEO_FORMAT_ARGB,
641 G_MAXUINT / 2, G_MAXUINT / 2));
642 fail_if (gst_video_info_set_format (&vinfo, GST_VIDEO_FORMAT_ARGB, G_MAXUINT,
645 fail_unless (gst_video_info_set_format (&vinfo, GST_VIDEO_FORMAT_ARGB,
646 1073741824 - 128, 1));
647 fail_if (gst_video_info_set_format (&vinfo, GST_VIDEO_FORMAT_ARGB, 1073741824,
654 GST_START_TEST (test_video_formats_rgb)
657 gint width, height, framerate_n, framerate_d, par_n, par_d;
659 GstStructure *structure;
661 gst_video_info_init (&vinfo);
662 fail_unless (gst_video_info_set_format (&vinfo, GST_VIDEO_FORMAT_RGB, 800,
668 caps = gst_video_info_to_caps (&vinfo);
669 structure = gst_caps_get_structure (caps, 0);
671 fail_unless (gst_structure_get_int (structure, "width", &width));
672 fail_unless (gst_structure_get_int (structure, "height", &height));
673 fail_unless (gst_structure_get_fraction (structure, "framerate", &framerate_n,
675 fail_unless (gst_structure_get_fraction (structure, "pixel-aspect-ratio",
678 fail_unless (width == 800);
679 fail_unless (height == 600);
680 fail_unless (framerate_n == 0);
681 fail_unless (framerate_d == 1);
682 fail_unless (par_n == 1);
683 fail_unless (par_d == 1);
685 gst_caps_unref (caps);
691 GST_START_TEST (test_video_formats_rgba_large_dimension)
694 gint width, height, framerate_n, framerate_d, par_n, par_d;
696 GstStructure *structure;
698 gst_video_info_init (&vinfo);
699 fail_unless (gst_video_info_set_format (&vinfo, GST_VIDEO_FORMAT_RGBA, 29700,
705 caps = gst_video_info_to_caps (&vinfo);
706 structure = gst_caps_get_structure (caps, 0);
708 fail_unless (gst_structure_get_int (structure, "width", &width));
709 fail_unless (gst_structure_get_int (structure, "height", &height));
710 fail_unless (gst_structure_get_fraction (structure, "framerate", &framerate_n,
712 fail_unless (gst_structure_get_fraction (structure, "pixel-aspect-ratio",
715 fail_unless (width == 29700);
716 fail_unless (height == 21000);
717 fail_unless (framerate_n == 0);
718 fail_unless (framerate_d == 1);
719 fail_unless (par_n == 1);
720 fail_unless (par_d == 1);
721 fail_unless (vinfo.size == (gsize) 29700 * 21000 * 4);
723 gst_caps_unref (caps);
728 GST_START_TEST (test_guess_framerate)
730 /* Check some obvious exact framerates */
732 fail_unless (gst_video_guess_framerate (GST_SECOND / 24, &fps_n, &fps_d));
733 fail_unless (fps_n == 24 && fps_d == 1);
735 fail_unless (gst_video_guess_framerate (GST_SECOND / 30, &fps_n, &fps_d));
736 fail_unless (fps_n == 30 && fps_d == 1);
738 fail_unless (gst_video_guess_framerate (GST_SECOND / 25, &fps_n, &fps_d));
739 fail_unless (fps_n == 25 && fps_d == 1);
741 /* Some NTSC rates: */
742 fail_unless (gst_video_guess_framerate (GST_SECOND * 1001 / 30000, &fps_n,
744 fail_unless (fps_n == 30000 && fps_d == 1001);
746 fail_unless (gst_video_guess_framerate (GST_SECOND * 1001 / 24000, &fps_n,
748 fail_unless (fps_n == 24000 && fps_d == 1001);
750 fail_unless (gst_video_guess_framerate (GST_SECOND * 1001 / 60000, &fps_n,
752 fail_unless (fps_n == 60000 && fps_d == 1001);
754 /* Check some high FPS, low durations */
755 fail_unless (gst_video_guess_framerate (GST_SECOND / 9000, &fps_n, &fps_d));
756 fail_unless (fps_n == 9000 && fps_d == 1);
757 fail_unless (gst_video_guess_framerate (GST_SECOND / 10000, &fps_n, &fps_d));
758 fail_unless (fps_n == 10000 && fps_d == 1);
759 fail_unless (gst_video_guess_framerate (GST_SECOND / 11000, &fps_n, &fps_d));
760 fail_unless (fps_n == 11000 && fps_d == 1);
761 fail_unless (gst_video_guess_framerate (GST_SECOND / 20000, &fps_n, &fps_d));
762 fail_unless (fps_n == 20000 && fps_d == 1);
763 fail_unless (gst_video_guess_framerate (GST_SECOND / 100000, &fps_n, &fps_d));
764 fail_unless (fps_n == 100000 && fps_d == 1);
769 GST_START_TEST (test_dar_calc)
771 guint display_ratio_n, display_ratio_d;
773 /* Ensure that various Display Ratio calculations are correctly done */
774 /* video 768x576, par 16/15, display par 16/15 = 4/3 */
775 fail_unless (gst_video_calculate_display_ratio (&display_ratio_n,
776 &display_ratio_d, 768, 576, 16, 15, 16, 15));
777 fail_unless (display_ratio_n == 4 && display_ratio_d == 3);
779 /* video 720x480, par 32/27, display par 1/1 = 16/9 */
780 fail_unless (gst_video_calculate_display_ratio (&display_ratio_n,
781 &display_ratio_d, 720, 480, 32, 27, 1, 1));
782 fail_unless (display_ratio_n == 16 && display_ratio_d == 9);
784 /* video 360x288, par 533333/500000, display par 16/15 =
785 * dar 1599999/1600000 */
786 fail_unless (gst_video_calculate_display_ratio (&display_ratio_n,
787 &display_ratio_d, 360, 288, 533333, 500000, 16, 15));
788 fail_unless (display_ratio_n == 1599999 && display_ratio_d == 1280000);
793 GST_START_TEST (test_parse_caps_rgb)
797 const gchar *tmpl_caps_string;
802 GST_VIDEO_CAPS_MAKE ("RGB"), GST_VIDEO_FORMAT_RGB}, {
803 GST_VIDEO_CAPS_MAKE ("BGR"), GST_VIDEO_FORMAT_BGR},
804 /* 32 bit (no alpha) */
806 GST_VIDEO_CAPS_MAKE ("RGBx"), GST_VIDEO_FORMAT_RGBx}, {
807 GST_VIDEO_CAPS_MAKE ("xRGB"), GST_VIDEO_FORMAT_xRGB}, {
808 GST_VIDEO_CAPS_MAKE ("BGRx"), GST_VIDEO_FORMAT_BGRx}, {
809 GST_VIDEO_CAPS_MAKE ("xBGR"), GST_VIDEO_FORMAT_xBGR},
810 /* 32 bit (with alpha) */
812 GST_VIDEO_CAPS_MAKE ("RGBA"), GST_VIDEO_FORMAT_RGBA}, {
813 GST_VIDEO_CAPS_MAKE ("ARGB"), GST_VIDEO_FORMAT_ARGB}, {
814 GST_VIDEO_CAPS_MAKE ("BGRA"), GST_VIDEO_FORMAT_BGRA}, {
815 GST_VIDEO_CAPS_MAKE ("ABGR"), GST_VIDEO_FORMAT_ABGR},
818 GST_VIDEO_CAPS_MAKE ("RGB16"), GST_VIDEO_FORMAT_RGB16}, {
819 GST_VIDEO_CAPS_MAKE ("BGR16"), GST_VIDEO_FORMAT_BGR16}, {
820 GST_VIDEO_CAPS_MAKE ("RGB15"), GST_VIDEO_FORMAT_RGB15}, {
821 GST_VIDEO_CAPS_MAKE ("BGR15"), GST_VIDEO_FORMAT_BGR15}
825 for (i = 0; i < G_N_ELEMENTS (formats); ++i) {
827 GstCaps *caps, *caps2;
829 caps = gst_caps_from_string (formats[i].tmpl_caps_string);
830 fail_unless (caps != NULL);
831 gst_caps_set_simple (caps, "width", G_TYPE_INT, 2 * (i + 1), "height",
832 G_TYPE_INT, i + 1, "framerate", GST_TYPE_FRACTION, 15, 1,
833 "pixel-aspect-ratio", GST_TYPE_FRACTION, 1, 1,
834 "interlace-mode", G_TYPE_STRING, "progressive",
835 "colorimetry", G_TYPE_STRING, "1:1:0:0",
836 "multiview-mode", G_TYPE_STRING, "mono",
837 "multiview-flags", GST_TYPE_VIDEO_MULTIVIEW_FLAGSET, 0,
838 GST_FLAG_SET_MASK_EXACT, NULL);
839 g_assert (gst_caps_is_fixed (caps));
841 GST_DEBUG ("testing caps: %" GST_PTR_FORMAT, caps);
843 gst_video_info_init (&vinfo);
844 fail_unless (gst_video_info_from_caps (&vinfo, caps));
845 fail_unless_equals_int (GST_VIDEO_INFO_FORMAT (&vinfo), formats[i].fmt);
846 fail_unless_equals_int (GST_VIDEO_INFO_WIDTH (&vinfo), 2 * (i + 1));
847 fail_unless_equals_int (GST_VIDEO_INFO_HEIGHT (&vinfo), i + 1);
849 /* make sure they're serialised back correctly */
850 caps2 = gst_video_info_to_caps (&vinfo);
851 fail_unless (caps2 != NULL);
852 if (!gst_caps_is_equal (caps, caps2)) {
853 gchar *caps1s = gst_caps_to_string (caps);
854 gchar *caps2s = gst_caps_to_string (caps2);
855 fail ("caps [%s] not equal to caps2 [%s]", caps1s, caps2s);
860 gst_caps_unref (caps);
861 gst_caps_unref (caps2);
867 GST_START_TEST (test_parse_caps_multiview)
870 GstVideoMultiviewMode modes[] = {
871 GST_VIDEO_MULTIVIEW_MODE_MONO,
872 GST_VIDEO_MULTIVIEW_MODE_LEFT,
873 GST_VIDEO_MULTIVIEW_MODE_RIGHT,
874 GST_VIDEO_MULTIVIEW_MODE_SIDE_BY_SIDE,
875 GST_VIDEO_MULTIVIEW_MODE_SIDE_BY_SIDE_QUINCUNX,
876 GST_VIDEO_MULTIVIEW_MODE_COLUMN_INTERLEAVED,
877 GST_VIDEO_MULTIVIEW_MODE_ROW_INTERLEAVED,
878 GST_VIDEO_MULTIVIEW_MODE_TOP_BOTTOM,
879 GST_VIDEO_MULTIVIEW_MODE_CHECKERBOARD,
880 GST_VIDEO_MULTIVIEW_MODE_FRAME_BY_FRAME,
881 GST_VIDEO_MULTIVIEW_MODE_MULTIVIEW_FRAME_BY_FRAME,
882 GST_VIDEO_MULTIVIEW_MODE_SEPARATED,
884 GstVideoMultiviewFlags flags[] = {
885 GST_VIDEO_MULTIVIEW_FLAGS_NONE,
886 GST_VIDEO_MULTIVIEW_FLAGS_RIGHT_VIEW_FIRST,
887 GST_VIDEO_MULTIVIEW_FLAGS_LEFT_FLIPPED,
888 GST_VIDEO_MULTIVIEW_FLAGS_LEFT_FLOPPED,
889 GST_VIDEO_MULTIVIEW_FLAGS_RIGHT_FLIPPED,
890 GST_VIDEO_MULTIVIEW_FLAGS_RIGHT_FLOPPED,
891 GST_VIDEO_MULTIVIEW_FLAGS_MIXED_MONO,
892 GST_VIDEO_MULTIVIEW_FLAGS_MIXED_MONO |
893 GST_VIDEO_MULTIVIEW_FLAGS_RIGHT_VIEW_FIRST,
894 GST_VIDEO_MULTIVIEW_FLAGS_MIXED_MONO |
895 GST_VIDEO_MULTIVIEW_FLAGS_LEFT_FLIPPED
898 for (i = 0; i < G_N_ELEMENTS (modes); i++) {
899 for (j = 0; j < G_N_ELEMENTS (flags); j++) {
903 gst_video_info_init (&vinfo);
904 fail_unless (gst_video_info_set_format (&vinfo, GST_VIDEO_FORMAT_I420,
907 GST_VIDEO_INFO_MULTIVIEW_MODE (&vinfo) = modes[i];
908 GST_VIDEO_INFO_MULTIVIEW_FLAGS (&vinfo) = flags[j];
910 caps = gst_video_info_to_caps (&vinfo);
911 fail_if (caps == NULL);
912 GST_LOG ("mview mode %d flags %x -> caps %" GST_PTR_FORMAT,
913 modes[i], flags[j], caps);
915 fail_unless (gst_video_info_from_caps (&vinfo, caps));
917 GST_LOG ("mview mode %d flags %x -> info mode %d flags %x",
918 modes[i], flags[j], GST_VIDEO_INFO_MULTIVIEW_MODE (&vinfo),
919 GST_VIDEO_INFO_MULTIVIEW_FLAGS (&vinfo));
921 fail_unless (GST_VIDEO_INFO_MULTIVIEW_MODE (&vinfo) == modes[i],
922 "Expected multiview mode %d got mode %d", modes[i],
923 GST_VIDEO_INFO_MULTIVIEW_MODE (&vinfo));
924 fail_unless (GST_VIDEO_INFO_MULTIVIEW_FLAGS (&vinfo) == flags[j],
925 "Expected multiview flags 0x%x got 0x%x", flags[j],
926 GST_VIDEO_INFO_MULTIVIEW_FLAGS (&vinfo));
928 gst_caps_unref (caps);
937 const gchar *string_from;
938 const gchar *string_to;
940 GstVideoColorimetry color;
943 #define MAKE_COLORIMETRY_TEST(s1,s2,n,r,m,t,p) { s1, s2, n, \
944 { GST_VIDEO_COLOR_RANGE ##r, GST_VIDEO_COLOR_MATRIX_ ##m, \
945 GST_VIDEO_TRANSFER_ ##t, GST_VIDEO_COLOR_PRIMARIES_ ##p } }
947 GST_START_TEST (test_parse_colorimetry)
949 ColorimetryTest tests[] = {
950 MAKE_COLORIMETRY_TEST ("bt601", "bt601", "bt601",
951 _16_235, BT601, BT601, SMPTE170M),
952 MAKE_COLORIMETRY_TEST ("2:4:5:4", "2:4:5:4", NULL,
953 _16_235, BT601, BT709, SMPTE170M),
954 MAKE_COLORIMETRY_TEST ("bt709", "bt709", "bt709",
955 _16_235, BT709, BT709, BT709),
956 MAKE_COLORIMETRY_TEST ("smpte240m", "smpte240m", "smpte240m",
957 _16_235, SMPTE240M, SMPTE240M, SMPTE240M),
958 MAKE_COLORIMETRY_TEST ("sRGB", "sRGB", "sRGB",
959 _0_255, RGB, SRGB, BT709),
960 MAKE_COLORIMETRY_TEST ("bt2020", "bt2020", "bt2020",
961 _16_235, BT2020, BT2020_12, BT2020),
962 MAKE_COLORIMETRY_TEST ("1:4:0:0", "1:4:0:0", NULL,
963 _0_255, BT601, UNKNOWN, UNKNOWN),
967 for (i = 0; i < G_N_ELEMENTS (tests); i++) {
968 const ColorimetryTest *test = &tests[i];
969 GstVideoColorimetry color;
972 fail_unless (gst_video_colorimetry_from_string (&color, test->string_from));
973 fail_unless_equals_int (color.range, test->color.range);
974 fail_unless_equals_int (color.matrix, test->color.matrix);
975 fail_unless_equals_int (color.transfer, test->color.transfer);
976 fail_unless_equals_int (color.primaries, test->color.primaries);
978 string = gst_video_colorimetry_to_string (&color);
979 fail_unless_equals_string (string, test->string_to);
982 fail_unless (gst_video_colorimetry_is_equal (&color, &test->color));
985 fail_unless (gst_video_colorimetry_matches (&color, test->name));
991 GST_START_TEST (test_events)
996 e = gst_video_event_new_still_frame (TRUE);
997 fail_if (e == NULL, "Failed to create still frame event");
998 fail_unless (gst_video_event_parse_still_frame (e, &in_still),
999 "Failed to parse still frame event");
1000 fail_unless (gst_video_event_parse_still_frame (e, NULL),
1001 "Failed to parse still frame event w/ in_still == NULL");
1002 fail_unless (in_still == TRUE);
1003 gst_event_unref (e);
1005 e = gst_video_event_new_still_frame (FALSE);
1006 fail_if (e == NULL, "Failed to create still frame event");
1007 fail_unless (gst_video_event_parse_still_frame (e, &in_still),
1008 "Failed to parse still frame event");
1009 fail_unless (gst_video_event_parse_still_frame (e, NULL),
1010 "Failed to parse still frame event w/ in_still == NULL");
1011 fail_unless (in_still == FALSE);
1012 gst_event_unref (e);
1017 GST_START_TEST (test_convert_frame)
1020 GstCaps *from_caps, *to_caps;
1021 GstBuffer *from_buffer;
1022 GstSample *from_sample, *to_sample;
1023 GError *error = NULL;
1027 gst_debug_set_threshold_for_name ("default", GST_LEVEL_NONE);
1029 from_buffer = gst_buffer_new_and_alloc (640 * 480 * 4);
1031 gst_buffer_map (from_buffer, &map, GST_MAP_WRITE);
1032 for (i = 0; i < 640 * 480; i++) {
1033 map.data[4 * i + 0] = 0; /* x */
1034 map.data[4 * i + 1] = 255; /* R */
1035 map.data[4 * i + 2] = 0; /* G */
1036 map.data[4 * i + 3] = 0; /* B */
1038 gst_buffer_unmap (from_buffer, &map);
1040 gst_video_info_init (&vinfo);
1041 fail_unless (gst_video_info_set_format (&vinfo, GST_VIDEO_FORMAT_xRGB, 640,
1047 from_caps = gst_video_info_to_caps (&vinfo);
1049 from_sample = gst_sample_new (from_buffer, from_caps, NULL, NULL);
1052 gst_caps_from_string
1053 ("something/that, does=(string)not, exist=(boolean)FALSE");
1056 gst_video_convert_sample (from_sample, to_caps,
1057 GST_CLOCK_TIME_NONE, &error);
1058 fail_if (to_sample != NULL);
1059 fail_unless (error != NULL);
1060 g_error_free (error);
1063 gst_caps_unref (to_caps);
1064 fail_unless (gst_video_info_set_format (&vinfo, GST_VIDEO_FORMAT_I420, 240,
1070 to_caps = gst_video_info_to_caps (&vinfo);
1073 gst_video_convert_sample (from_sample, to_caps,
1074 GST_CLOCK_TIME_NONE, &error);
1075 fail_unless (to_sample != NULL);
1076 fail_unless (error == NULL);
1078 gst_buffer_unref (from_buffer);
1079 gst_caps_unref (from_caps);
1080 gst_sample_unref (from_sample);
1081 gst_sample_unref (to_sample);
1082 gst_caps_unref (to_caps);
1092 } ConvertFrameContext;
1095 convert_sample_async_callback (GstSample * sample, GError * err,
1096 ConvertFrameContext * cf_data)
1098 cf_data->sample = sample;
1099 cf_data->error = err;
1101 g_main_loop_quit (cf_data->loop);
1104 GST_START_TEST (test_convert_frame_async)
1107 GstCaps *from_caps, *to_caps;
1108 GstBuffer *from_buffer;
1109 GstSample *from_sample;
1113 ConvertFrameContext cf_data = { NULL, NULL, NULL };
1115 gst_debug_set_threshold_for_name ("default", GST_LEVEL_NONE);
1117 from_buffer = gst_buffer_new_and_alloc (640 * 480 * 4);
1119 gst_buffer_map (from_buffer, &map, GST_MAP_WRITE);
1120 for (i = 0; i < 640 * 480; i++) {
1121 map.data[4 * i + 0] = 0; /* x */
1122 map.data[4 * i + 1] = 255; /* R */
1123 map.data[4 * i + 2] = 0; /* G */
1124 map.data[4 * i + 3] = 0; /* B */
1126 gst_buffer_unmap (from_buffer, &map);
1128 loop = cf_data.loop = g_main_loop_new (NULL, FALSE);
1130 gst_video_info_init (&vinfo);
1131 fail_unless (gst_video_info_set_format (&vinfo, GST_VIDEO_FORMAT_xRGB, 640,
1137 from_caps = gst_video_info_to_caps (&vinfo);
1139 from_sample = gst_sample_new (from_buffer, from_caps, NULL, NULL);
1140 gst_buffer_unref (from_buffer);
1141 gst_caps_unref (from_caps);
1143 gst_video_info_init (&vinfo);
1144 fail_unless (gst_video_info_set_format (&vinfo, GST_VIDEO_FORMAT_I420, 240,
1150 to_caps = gst_video_info_to_caps (&vinfo);
1151 gst_video_convert_sample_async (from_sample, to_caps,
1152 GST_CLOCK_TIME_NONE,
1153 (GstVideoConvertSampleCallback) convert_sample_async_callback, &cf_data,
1155 g_main_loop_run (loop);
1156 fail_unless (cf_data.sample != NULL);
1157 fail_unless (cf_data.error == NULL);
1159 gst_sample_unref (cf_data.sample);
1160 gst_caps_unref (to_caps);
1161 gst_sample_unref (from_sample);
1163 g_main_loop_unref (loop);
1168 GST_START_TEST (test_convert_frame_async_error)
1171 GstCaps *from_caps, *to_caps;
1172 GstBuffer *from_buffer;
1173 GstSample *from_sample;
1177 ConvertFrameContext cf_data = { NULL, NULL, NULL };
1179 gst_debug_set_threshold_for_name ("default", GST_LEVEL_NONE);
1181 from_buffer = gst_buffer_new_and_alloc (640 * 480 * 4);
1183 gst_buffer_map (from_buffer, &map, GST_MAP_WRITE);
1184 for (i = 0; i < 640 * 480; i++) {
1185 map.data[4 * i + 0] = 0; /* x */
1186 map.data[4 * i + 1] = 255; /* R */
1187 map.data[4 * i + 2] = 0; /* G */
1188 map.data[4 * i + 3] = 0; /* B */
1190 gst_buffer_unmap (from_buffer, &map);
1192 gst_video_info_init (&vinfo);
1193 fail_unless (gst_video_info_set_format (&vinfo, GST_VIDEO_FORMAT_xRGB, 640,
1199 from_caps = gst_video_info_to_caps (&vinfo);
1202 gst_caps_from_string
1203 ("something/that, does=(string)not, exist=(boolean)FALSE");
1205 loop = cf_data.loop = g_main_loop_new (NULL, FALSE);
1207 from_sample = gst_sample_new (from_buffer, from_caps, NULL, NULL);
1208 gst_buffer_unref (from_buffer);
1209 gst_caps_unref (from_caps);
1211 gst_video_convert_sample_async (from_sample, to_caps,
1212 GST_CLOCK_TIME_NONE,
1213 (GstVideoConvertSampleCallback) convert_sample_async_callback, &cf_data,
1216 g_main_loop_run (loop);
1218 fail_if (cf_data.sample != NULL);
1219 fail_unless (cf_data.error != NULL);
1220 g_error_free (cf_data.error);
1221 cf_data.error = NULL;
1223 gst_caps_unref (to_caps);
1224 gst_sample_unref (from_sample);
1226 g_main_loop_unref (loop);
1231 GST_START_TEST (test_video_size_from_caps)
1236 caps = gst_caps_new_simple ("video/x-raw",
1237 "format", G_TYPE_STRING, "YV12",
1238 "width", G_TYPE_INT, 640,
1239 "height", G_TYPE_INT, 480, "framerate", GST_TYPE_FRACTION, 25, 1, NULL);
1241 gst_video_info_init (&vinfo);
1242 fail_unless (gst_video_info_from_caps (&vinfo, caps));
1243 fail_unless (GST_VIDEO_INFO_SIZE (&vinfo) == (640 * 480 * 12 / 8));
1245 gst_caps_unref (caps);
1250 GST_START_TEST (test_interlace_mode)
1254 GstStructure *structure;
1255 GstCapsFeatures *features;
1256 const char *mode_str, *order_str;
1258 GstVideoFieldOrder order;
1260 gst_video_info_init (&vinfo);
1263 fail_unless (gst_video_info_set_interlaced_format (&vinfo,
1264 GST_VIDEO_FORMAT_YV12, GST_VIDEO_INTERLACE_MODE_PROGRESSIVE, 320,
1266 fail_unless (GST_VIDEO_INFO_SIZE (&vinfo) == 115200);
1268 caps = gst_video_info_to_caps (&vinfo);
1269 fail_unless (caps != NULL);
1270 structure = gst_caps_get_structure (caps, 0);
1271 fail_unless (structure != NULL);
1272 mode_str = gst_structure_get_string (structure, "interlace-mode");
1273 mode = gst_video_interlace_mode_from_string (mode_str);
1274 fail_unless (mode == GST_VIDEO_INTERLACE_MODE_PROGRESSIVE);
1276 /* Converting back to video info */
1277 fail_unless (gst_video_info_from_caps (&vinfo, caps));
1278 fail_unless (GST_VIDEO_INFO_INTERLACE_MODE (&vinfo) ==
1279 GST_VIDEO_INTERLACE_MODE_PROGRESSIVE);
1281 gst_caps_unref (caps);
1283 /* Interlaced with alternate frame on buffers */
1284 fail_unless (gst_video_info_set_interlaced_format (&vinfo,
1285 GST_VIDEO_FORMAT_YV12, GST_VIDEO_INTERLACE_MODE_ALTERNATE, 320, 240));
1286 fail_unless (GST_VIDEO_INFO_SIZE (&vinfo) == 57600);
1287 GST_VIDEO_INFO_FIELD_ORDER (&vinfo) = GST_VIDEO_FIELD_ORDER_TOP_FIELD_FIRST;
1289 caps = gst_video_info_to_caps (&vinfo);
1290 fail_unless (caps != NULL);
1291 structure = gst_caps_get_structure (caps, 0);
1292 fail_unless (structure != NULL);
1293 mode_str = gst_structure_get_string (structure, "interlace-mode");
1294 mode = gst_video_interlace_mode_from_string (mode_str);
1295 fail_unless (mode == GST_VIDEO_INTERLACE_MODE_ALTERNATE);
1296 order_str = gst_structure_get_string (structure, "field-order");
1297 order = gst_video_field_order_from_string (order_str);
1298 fail_unless (order == GST_VIDEO_FIELD_ORDER_TOP_FIELD_FIRST);
1299 /* 'alternate' mode must always be accompanied by interlaced caps feature. */
1300 features = gst_caps_get_features (caps, 0);
1301 fail_unless (gst_caps_features_contains (features,
1302 GST_CAPS_FEATURE_FORMAT_INTERLACED));
1304 /* Converting back to video info */
1305 fail_unless (gst_video_info_from_caps (&vinfo, caps));
1306 fail_unless (GST_VIDEO_INFO_INTERLACE_MODE (&vinfo) ==
1307 GST_VIDEO_INTERLACE_MODE_ALTERNATE);
1308 fail_unless (GST_VIDEO_INFO_FIELD_ORDER (&vinfo) ==
1309 GST_VIDEO_FIELD_ORDER_TOP_FIELD_FIRST);
1311 gst_caps_unref (caps);
1313 /* gst_video_info_from_caps() fails if an alternate stream doesn't contain
1314 * the caps feature. */
1316 gst_caps_from_string
1317 ("video/x-raw, format=NV12, width=320, height=240, interlace-mode=alternate");
1320 fail_if (gst_video_info_from_caps (&vinfo, caps));
1321 gst_caps_unref (caps);
1323 /* ... but it's ok for encoded video */
1325 gst_caps_from_string
1326 ("video/x-h265, width=320, height=240, interlace-mode=alternate");
1329 fail_unless (gst_video_info_from_caps (&vinfo, caps));
1330 gst_caps_unref (caps);
1335 GST_START_TEST (test_overlay_composition)
1337 GstVideoOverlayComposition *comp1, *comp2;
1338 GstVideoOverlayRectangle *rect1, *rect2;
1339 GstVideoOverlayCompositionMeta *ometa;
1340 GstBuffer *pix1, *pix2, *buf;
1341 GstVideoMeta *vmeta;
1347 pix1 = gst_buffer_new_and_alloc (200 * sizeof (guint32) * 50);
1348 gst_buffer_memset (pix1, 0, 0, gst_buffer_get_size (pix1));
1350 gst_buffer_add_video_meta (pix1, GST_VIDEO_FRAME_FLAG_NONE,
1351 GST_VIDEO_OVERLAY_COMPOSITION_FORMAT_RGB, 200, 50);
1352 rect1 = gst_video_overlay_rectangle_new_raw (pix1,
1353 600, 50, 300, 50, GST_VIDEO_OVERLAY_FORMAT_FLAG_NONE);
1355 gst_buffer_unref (pix1);
1358 comp1 = gst_video_overlay_composition_new (rect1);
1359 fail_unless (gst_video_overlay_composition_n_rectangles (comp1) == 1);
1360 fail_unless (gst_video_overlay_composition_get_rectangle (comp1, 0) == rect1);
1361 fail_unless (gst_video_overlay_composition_get_rectangle (comp1, 1) == NULL);
1363 /* rectangle was created first, sequence number should be smaller */
1364 seq1 = gst_video_overlay_rectangle_get_seqnum (rect1);
1365 seq2 = gst_video_overlay_composition_get_seqnum (comp1);
1366 fail_unless (seq1 < seq2);
1368 /* composition took own ref, so refcount is 2 now, so this should fail */
1369 ASSERT_CRITICAL (gst_video_overlay_rectangle_set_render_rectangle (rect1, 50,
1372 /* drop our ref, so refcount is 1 (we know it will continue to be valid) */
1373 gst_video_overlay_rectangle_unref (rect1);
1374 gst_video_overlay_rectangle_set_render_rectangle (rect1, 50, 600, 300, 50);
1376 comp2 = gst_video_overlay_composition_new (rect1);
1377 fail_unless (gst_video_overlay_composition_n_rectangles (comp2) == 1);
1378 fail_unless (gst_video_overlay_composition_get_rectangle (comp2, 0) == rect1);
1379 fail_unless (gst_video_overlay_composition_get_rectangle (comp2, 1) == NULL);
1381 fail_unless (seq1 < gst_video_overlay_composition_get_seqnum (comp2));
1382 fail_unless (seq2 < gst_video_overlay_composition_get_seqnum (comp2));
1384 /* now refcount is 2 again because comp2 has also taken a ref, so must fail */
1385 ASSERT_CRITICAL (gst_video_overlay_rectangle_set_render_rectangle (rect1, 0,
1388 /* this should make a copy of the rectangles so drop the original
1389 * second ref on rect1 */
1390 comp2 = gst_video_overlay_composition_make_writable (comp2);
1391 gst_video_overlay_rectangle_set_render_rectangle (rect1, 51, 601, 301, 51);
1393 rect2 = gst_video_overlay_composition_get_rectangle (comp2, 0);
1394 fail_unless (gst_video_overlay_composition_n_rectangles (comp2) == 1);
1395 fail_unless (gst_video_overlay_composition_get_rectangle (comp2, 0) == rect2);
1396 fail_unless (gst_video_overlay_composition_get_rectangle (comp2, 1) == NULL);
1397 fail_unless (rect1 != rect2);
1399 gst_video_overlay_composition_add_rectangle (comp1, rect2);
1400 gst_video_overlay_composition_ref (comp1);
1401 ASSERT_CRITICAL (gst_video_overlay_composition_add_rectangle (comp1, rect2));
1402 gst_video_overlay_composition_unref (comp1);
1404 /* make sure the copy really worked */
1405 gst_video_overlay_rectangle_get_render_rectangle (rect1, &x, &y, &w, &h);
1406 fail_unless_equals_int (x, 51);
1407 fail_unless_equals_int (y, 601);
1408 fail_unless_equals_int (w, 301);
1409 fail_unless_equals_int (h, 51);
1411 /* get scaled pixbuf and touch last byte */
1412 pix1 = gst_video_overlay_rectangle_get_pixels_raw (rect1,
1413 GST_VIDEO_OVERLAY_FORMAT_FLAG_NONE);
1415 fail_unless (gst_buffer_get_size (pix1) > ((h - 1) * stride + (w * 4) - 1),
1416 "size %u vs. last pixel offset %u", gst_buffer_get_size (pix1),
1417 ((h - 1) * stride + (w * 4) - 1));
1418 gst_buffer_extract (pix1, ((h - 1) * stride + (w * 4) - 1), &val, 1);
1419 fail_unless_equals_int (val, 0);
1421 gst_video_overlay_rectangle_get_render_rectangle (rect2, &x, &y, &w, &h);
1422 fail_unless_equals_int (x, 50);
1423 fail_unless_equals_int (y, 600);
1424 fail_unless_equals_int (w, 300);
1425 fail_unless_equals_int (h, 50);
1427 /* get scaled pixbuf and touch last byte */
1428 pix2 = gst_video_overlay_rectangle_get_pixels_raw (rect2,
1429 GST_VIDEO_OVERLAY_FORMAT_FLAG_NONE);
1431 fail_unless (gst_buffer_get_size (pix2) > ((h - 1) * stride + (w * 4) - 1),
1432 "size %u vs. last pixel offset %u", gst_buffer_get_size (pix1),
1433 ((h - 1) * stride + (w * 4) - 1));
1434 gst_buffer_extract (pix2, ((h - 1) * stride + (w * 4) - 1), &val, 1);
1435 fail_unless_equals_int (val, 0);
1437 /* get scaled pixbuf again, should be the same buffer as before (caching) */
1438 pix1 = gst_video_overlay_rectangle_get_pixels_raw (rect2,
1439 GST_VIDEO_OVERLAY_FORMAT_FLAG_NONE);
1440 fail_unless (pix1 == pix2);
1442 /* get in different format */
1443 pix1 = gst_video_overlay_rectangle_get_pixels_ayuv (rect2,
1444 GST_VIDEO_OVERLAY_FORMAT_FLAG_NONE);
1445 fail_unless (pix1 != pix2);
1446 /* get it again, should be same (caching) */
1447 pix2 = gst_video_overlay_rectangle_get_pixels_ayuv (rect2,
1448 GST_VIDEO_OVERLAY_FORMAT_FLAG_NONE);
1449 fail_unless (pix1 == pix2);
1450 /* get unscaled, should be different */
1451 pix2 = gst_video_overlay_rectangle_get_pixels_unscaled_ayuv (rect2,
1452 GST_VIDEO_OVERLAY_FORMAT_FLAG_NONE);
1453 fail_unless (pix1 != pix2);
1454 /* but should be cached */
1455 pix1 = gst_video_overlay_rectangle_get_pixels_unscaled_ayuv (rect2,
1456 GST_VIDEO_OVERLAY_FORMAT_FLAG_NONE);
1457 fail_unless (pix1 == pix2);
1459 vmeta = gst_buffer_get_video_meta (pix1);
1460 fail_unless (vmeta != NULL);
1463 fail_unless_equals_int (w, 200);
1464 fail_unless_equals_int (h, 50);
1465 fail_unless_equals_int (vmeta->format,
1466 GST_VIDEO_OVERLAY_COMPOSITION_FORMAT_YUV);
1467 fail_unless (gst_buffer_get_size (pix1) == w * h * 4);
1468 gst_buffer_extract (pix1, 0, &seq1, 4);
1469 fail_unless (seq1 != 0);
1471 /* now compare the original unscaled ones */
1472 pix1 = gst_video_overlay_rectangle_get_pixels_unscaled_raw (rect1,
1473 GST_VIDEO_OVERLAY_FORMAT_FLAG_NONE);
1474 pix2 = gst_video_overlay_rectangle_get_pixels_unscaled_raw (rect2,
1475 GST_VIDEO_OVERLAY_FORMAT_FLAG_NONE);
1477 vmeta = gst_buffer_get_video_meta (pix2);
1478 fail_unless (vmeta != NULL);
1482 /* the original pixel buffers should be identical */
1483 fail_unless (pix1 == pix2);
1484 fail_unless_equals_int (w, 200);
1485 fail_unless_equals_int (h, 50);
1488 /* touch last byte */
1489 fail_unless (gst_buffer_get_size (pix1) > ((h - 1) * stride + (w * 4) - 1),
1490 "size %u vs. last pixel offset %u", gst_buffer_get_size (pix1),
1491 ((h - 1) * stride + (w * 4) - 1));
1492 gst_buffer_extract (pix1, ((h - 1) * stride + (w * 4) - 1), &val, 1);
1493 fail_unless_equals_int (val, 0);
1495 /* test attaching and retrieving of compositions to/from buffers */
1496 buf = gst_buffer_new ();
1497 fail_unless (gst_buffer_get_video_overlay_composition_meta (buf) == NULL);
1499 gst_buffer_ref (buf);
1500 /* buffer now has refcount of 2, so its metadata is not writable.
1501 * only check this if we are not running in valgrind, as it leaks */
1502 #ifdef HAVE_VALGRIND
1503 if (!RUNNING_ON_VALGRIND) {
1504 ASSERT_CRITICAL (gst_buffer_add_video_overlay_composition_meta (buf,
1508 gst_buffer_unref (buf);
1509 gst_buffer_add_video_overlay_composition_meta (buf, comp1);
1510 ometa = gst_buffer_get_video_overlay_composition_meta (buf);
1511 fail_unless (ometa != NULL);
1512 fail_unless (ometa->overlay == comp1);
1513 fail_unless (gst_buffer_remove_video_overlay_composition_meta (buf, ometa));
1514 gst_buffer_add_video_overlay_composition_meta (buf, comp2);
1515 ometa = gst_buffer_get_video_overlay_composition_meta (buf);
1516 fail_unless (ometa->overlay == comp2);
1517 fail_unless (gst_buffer_remove_video_overlay_composition_meta (buf, ometa));
1518 fail_unless (gst_buffer_get_video_overlay_composition_meta (buf) == NULL);
1520 /* make sure the buffer cleans up its composition ref when unreffed */
1521 gst_buffer_add_video_overlay_composition_meta (buf, comp2);
1522 gst_buffer_unref (buf);
1524 gst_video_overlay_composition_unref (comp2);
1525 gst_video_overlay_composition_unref (comp1);
1530 GST_START_TEST (test_overlay_composition_premultiplied_alpha)
1532 GstVideoOverlayRectangle *rect1;
1533 GstVideoMeta *vmeta;
1534 GstBuffer *pix1, *pix2, *pix3, *pix4, *pix5;
1535 GstBuffer *pix6, *pix7, *pix8, *pix9, *pix10;
1536 guint8 *data5, *data7;
1540 pix1 = gst_buffer_new_and_alloc (200 * sizeof (guint32) * 50);
1541 gst_buffer_memset (pix1, 0, 0x80, gst_buffer_get_size (pix1));
1543 gst_buffer_add_video_meta (pix1, GST_VIDEO_FRAME_FLAG_NONE,
1544 GST_VIDEO_OVERLAY_COMPOSITION_FORMAT_RGB, 200, 50);
1545 rect1 = gst_video_overlay_rectangle_new_raw (pix1,
1546 600, 50, 300, 50, GST_VIDEO_OVERLAY_FORMAT_FLAG_NONE);
1547 gst_buffer_unref (pix1);
1549 /* same flags, unscaled, should be the same buffer */
1550 pix2 = gst_video_overlay_rectangle_get_pixels_unscaled_raw (rect1,
1551 GST_VIDEO_OVERLAY_FORMAT_FLAG_NONE);
1552 fail_unless (pix1 == pix2);
1554 /* same flags, but scaled */
1555 pix3 = gst_video_overlay_rectangle_get_pixels_raw (rect1,
1556 GST_VIDEO_OVERLAY_FORMAT_FLAG_NONE);
1557 fail_if (pix3 == pix1 || pix3 == pix2);
1559 /* same again, should hopefully get the same (cached) buffer as before */
1560 pix4 = gst_video_overlay_rectangle_get_pixels_raw (rect1,
1561 GST_VIDEO_OVERLAY_FORMAT_FLAG_NONE);
1562 fail_unless (pix4 == pix3);
1564 /* just to update the vars */
1565 pix2 = gst_video_overlay_rectangle_get_pixels_unscaled_raw (rect1,
1566 GST_VIDEO_OVERLAY_FORMAT_FLAG_NONE);
1568 vmeta = gst_buffer_get_video_meta (pix2);
1569 fail_unless (vmeta != NULL);
1573 /* now, let's try to get premultiplied alpha from the unpremultiplied input */
1574 pix5 = gst_video_overlay_rectangle_get_pixels_unscaled_raw (rect1,
1575 GST_VIDEO_OVERLAY_FORMAT_FLAG_PREMULTIPLIED_ALPHA);
1576 fail_if (pix5 == pix1 || pix5 == pix2 || pix5 == pix3);
1577 vmeta = gst_buffer_get_video_meta (pix5);
1578 fail_unless (vmeta != NULL);
1581 fail_unless_equals_int (w, w2);
1582 fail_unless_equals_int (h, h2);
1583 fail_unless_equals_int (gst_buffer_get_size (pix2),
1584 gst_buffer_get_size (pix5));
1585 gst_buffer_map (pix5, &map, GST_MAP_READ);
1586 fail_if (gst_buffer_memcmp (pix2, 0, map.data, map.size) == 0);
1587 /* make sure it actually did what we expected it to do (input=0x80808080) */
1589 #if G_BYTE_ORDER == G_LITTLE_ENDIAN
1591 fail_unless_equals_int (data5[0], 0x40);
1592 fail_unless_equals_int (data5[1], 0x40);
1593 fail_unless_equals_int (data5[2], 0x40);
1594 fail_unless_equals_int (data5[3], 0x80);
1597 fail_unless_equals_int (data5[0], 0x80);
1598 fail_unless_equals_int (data5[1], 0x40);
1599 fail_unless_equals_int (data5[2], 0x40);
1600 fail_unless_equals_int (data5[3], 0x40);
1602 gst_buffer_unmap (pix5, &map);
1604 /* same again, now we should be getting back the same buffer as before,
1605 * as it should have been cached */
1606 pix6 = gst_video_overlay_rectangle_get_pixels_unscaled_raw (rect1,
1607 GST_VIDEO_OVERLAY_FORMAT_FLAG_PREMULTIPLIED_ALPHA);
1608 fail_unless (pix6 == pix5);
1610 /* just to update the stride var */
1611 pix3 = gst_video_overlay_rectangle_get_pixels_raw (rect1,
1612 GST_VIDEO_OVERLAY_FORMAT_FLAG_NONE);
1613 fail_unless (pix3 == pix4);
1615 /* now try to get scaled premultiplied alpha from unpremultiplied input */
1616 pix7 = gst_video_overlay_rectangle_get_pixels_raw (rect1,
1617 GST_VIDEO_OVERLAY_FORMAT_FLAG_PREMULTIPLIED_ALPHA);
1618 fail_if (pix7 == pix1 || pix7 == pix2 || pix7 == pix3 || pix7 == pix5);
1620 gst_buffer_map (pix7, &map, GST_MAP_READ);
1622 /* make sure it actually did what we expected it to do (input=0x80808080)
1623 * hoping that the scaling didn't mess up our values */
1624 #if G_BYTE_ORDER == G_LITTLE_ENDIAN
1626 fail_unless_equals_int (data7[0], 0x40);
1627 fail_unless_equals_int (data7[1], 0x40);
1628 fail_unless_equals_int (data7[2], 0x40);
1629 fail_unless_equals_int (data7[3], 0x80);
1632 fail_unless_equals_int (data7[0], 0x80);
1633 fail_unless_equals_int (data7[1], 0x40);
1634 fail_unless_equals_int (data7[2], 0x40);
1635 fail_unless_equals_int (data7[3], 0x40);
1637 gst_buffer_unmap (pix7, &map);
1639 /* and the same again, it should be cached now */
1640 pix8 = gst_video_overlay_rectangle_get_pixels_raw (rect1,
1641 GST_VIDEO_OVERLAY_FORMAT_FLAG_PREMULTIPLIED_ALPHA);
1642 fail_unless (pix8 == pix7);
1644 /* make sure other cached stuff is still there */
1645 pix9 = gst_video_overlay_rectangle_get_pixels_raw (rect1,
1646 GST_VIDEO_OVERLAY_FORMAT_FLAG_NONE);
1647 fail_unless (pix9 == pix3);
1648 pix10 = gst_video_overlay_rectangle_get_pixels_unscaled_raw (rect1,
1649 GST_VIDEO_OVERLAY_FORMAT_FLAG_PREMULTIPLIED_ALPHA);
1650 fail_unless (pix10 == pix5);
1652 gst_video_overlay_rectangle_unref (rect1);
1657 GST_START_TEST (test_overlay_composition_global_alpha)
1659 GstVideoOverlayRectangle *rect1;
1660 GstBuffer *pix1, *pix2, *pix3, *pix4, *pix5;
1661 GstVideoMeta *vmeta;
1662 guint8 *data2, *data4, *data5;
1666 GstVideoOverlayFormatFlags flags1;
1669 pix1 = gst_buffer_new_and_alloc (200 * sizeof (guint32) * 50);
1670 gst_buffer_memset (pix1, 0, 0x80, gst_buffer_get_size (pix1));
1672 gst_buffer_add_video_meta (pix1, GST_VIDEO_FRAME_FLAG_NONE,
1673 GST_VIDEO_OVERLAY_COMPOSITION_FORMAT_RGB, 200, 50);
1674 rect1 = gst_video_overlay_rectangle_new_raw (pix1,
1675 600, 50, 300, 50, GST_VIDEO_OVERLAY_FORMAT_FLAG_NONE);
1676 gst_buffer_unref (pix1);
1678 /* same flags, unscaled, should be the same buffer */
1679 pix2 = gst_video_overlay_rectangle_get_pixels_unscaled_raw (rect1,
1680 GST_VIDEO_OVERLAY_FORMAT_FLAG_NONE);
1681 fail_unless (pix1 == pix2);
1683 vmeta = gst_buffer_get_video_meta (pix2);
1684 fail_unless (vmeta != NULL);
1688 /* same flags, but scaled */
1689 pix3 = gst_video_overlay_rectangle_get_pixels_raw (rect1,
1690 GST_VIDEO_OVERLAY_FORMAT_FLAG_NONE);
1691 fail_if (pix3 == pix1 || pix3 == pix2);
1693 /* get unscaled premultiplied data, new cached rectangle should be created */
1694 pix4 = gst_video_overlay_rectangle_get_pixels_unscaled_raw (rect1,
1695 GST_VIDEO_OVERLAY_FORMAT_FLAG_PREMULTIPLIED_ALPHA);
1696 fail_if (pix4 == pix2 || pix4 == pix3);
1697 vmeta = gst_buffer_get_video_meta (pix4);
1698 fail_unless (vmeta != NULL);
1701 fail_unless_equals_int (w, w4);
1702 fail_unless_equals_int (h, h4);
1703 fail_unless_equals_int (gst_buffer_get_size (pix2),
1704 gst_buffer_get_size (pix4));
1705 gst_buffer_map (pix4, &map, GST_MAP_READ);
1706 fail_if (gst_buffer_memcmp (pix1, 0, map.data, map.size) == 0);
1707 /* make sure it actually did what we expected it to do (input=0x80808080) */
1709 #if G_BYTE_ORDER == G_LITTLE_ENDIAN
1711 fail_unless_equals_int (data4[0], 0x40);
1712 fail_unless_equals_int (data4[1], 0x40);
1713 fail_unless_equals_int (data4[2], 0x40);
1714 fail_unless_equals_int (data4[3], 0x80);
1717 fail_unless_equals_int (data4[0], 0x80);
1718 fail_unless_equals_int (data4[1], 0x40);
1719 fail_unless_equals_int (data4[2], 0x40);
1720 fail_unless_equals_int (data4[3], 0x40);
1722 gst_buffer_unmap (pix4, &map);
1724 /* now premultiplied and scaled, again a new cached rectangle should be cached */
1725 pix5 = gst_video_overlay_rectangle_get_pixels_raw (rect1,
1726 GST_VIDEO_OVERLAY_FORMAT_FLAG_PREMULTIPLIED_ALPHA);
1727 fail_if (pix5 == pix2 || pix5 == pix3 || pix5 == pix4);
1728 /* stride and size should be equal to the first scaled rect */
1729 fail_unless_equals_int (gst_buffer_get_size (pix5),
1730 gst_buffer_get_size (pix3));
1731 /* data should be different (premutliplied) though */
1732 gst_buffer_map (pix5, &map, GST_MAP_READ);
1733 fail_if (gst_buffer_memcmp (pix3, 0, map.data, map.size) == 0);
1734 /* make sure it actually did what we expected it to do (input=0x80808080) */
1736 #if G_BYTE_ORDER == G_LITTLE_ENDIAN
1738 fail_unless_equals_int (data5[0], 0x40);
1739 fail_unless_equals_int (data5[1], 0x40);
1740 fail_unless_equals_int (data5[2], 0x40);
1741 fail_unless_equals_int (data5[3], 0x80);
1744 fail_unless_equals_int (data5[0], 0x80);
1745 fail_unless_equals_int (data5[1], 0x40);
1746 fail_unless_equals_int (data5[2], 0x40);
1747 fail_unless_equals_int (data5[3], 0x40);
1749 gst_buffer_unmap (pix5, &map);
1751 /* global_alpha should initially be 1.0 */
1752 ga1 = gst_video_overlay_rectangle_get_global_alpha (rect1);
1753 fail_unless_equals_float (ga1, 1.0);
1755 /* now set global_alpha */
1756 seq1 = gst_video_overlay_rectangle_get_seqnum (rect1);
1757 gst_video_overlay_rectangle_set_global_alpha (rect1, 0.5);
1758 ga2 = gst_video_overlay_rectangle_get_global_alpha (rect1);
1759 fail_unless_equals_float (ga2, 0.5);
1761 /* seqnum should have changed */
1762 seq2 = gst_video_overlay_rectangle_get_seqnum (rect1);
1763 fail_unless (seq1 < seq2);
1765 /* internal flags should have been set */
1766 flags1 = gst_video_overlay_rectangle_get_flags (rect1);
1767 fail_unless_equals_int (flags1, GST_VIDEO_OVERLAY_FORMAT_FLAG_GLOBAL_ALPHA);
1769 /* request unscaled pixel-data, global-alpha not applied */
1770 pix2 = gst_video_overlay_rectangle_get_pixels_unscaled_raw (rect1,
1771 GST_VIDEO_OVERLAY_FORMAT_FLAG_GLOBAL_ALPHA);
1772 /* this should just return the same buffer */
1773 fail_unless (pix2 == pix1);
1774 /* make sure we got the initial data (input=0x80808080) */
1775 gst_buffer_map (pix2, &map, GST_MAP_READ);
1777 #if G_BYTE_ORDER == G_LITTLE_ENDIAN
1779 fail_unless_equals_int (data2[0], 0x80);
1780 fail_unless_equals_int (data2[1], 0x80);
1781 fail_unless_equals_int (data2[2], 0x80);
1782 fail_unless_equals_int (data2[3], 0x80);
1785 fail_unless_equals_int (data2[0], 0x80);
1786 fail_unless_equals_int (data2[1], 0x80);
1787 fail_unless_equals_int (data2[2], 0x80);
1788 fail_unless_equals_int (data2[3], 0x80);
1790 gst_buffer_unmap (pix2, &map);
1792 /* unscaled pixel-data, global-alpha applied */
1793 pix2 = gst_video_overlay_rectangle_get_pixels_unscaled_raw (rect1,
1794 GST_VIDEO_OVERLAY_FORMAT_FLAG_NONE);
1795 /* this should be the same buffer with on-the-fly modified alpha-channel */
1796 fail_unless (pix2 == pix1);
1797 gst_buffer_map (pix2, &map, GST_MAP_READ);
1799 /* make sure we got the initial data with adjusted alpha-channel */
1800 #if G_BYTE_ORDER == G_LITTLE_ENDIAN
1802 fail_unless_equals_int (data2[0], 0x80);
1803 fail_unless_equals_int (data2[1], 0x80);
1804 fail_unless_equals_int (data2[2], 0x80);
1805 fail_unless_equals_int (data2[3], 0x40);
1808 fail_unless_equals_int (data2[0], 0x40);
1809 fail_unless_equals_int (data2[1], 0x80);
1810 fail_unless_equals_int (data2[2], 0x80);
1811 fail_unless_equals_int (data2[3], 0x80);
1813 gst_buffer_unmap (pix2, &map);
1815 /* adjust global_alpha once more */
1816 gst_video_overlay_rectangle_set_global_alpha (rect1, 0.25);
1817 ga2 = gst_video_overlay_rectangle_get_global_alpha (rect1);
1818 fail_unless_equals_float (ga2, 0.25);
1819 /* and again request unscaled pixel-data, global-alpha applied */
1820 pix2 = gst_video_overlay_rectangle_get_pixels_unscaled_raw (rect1,
1821 GST_VIDEO_OVERLAY_FORMAT_FLAG_NONE);
1822 fail_unless (pix2 == pix1);
1823 /* make sure we got the initial data with adjusted alpha-channel */
1824 gst_buffer_map (pix2, &map, GST_MAP_READ);
1826 #if G_BYTE_ORDER == G_LITTLE_ENDIAN
1828 fail_unless_equals_int (data2[0], 0x80);
1829 fail_unless_equals_int (data2[1], 0x80);
1830 fail_unless_equals_int (data2[2], 0x80);
1831 fail_unless_equals_int (data2[3], 0x20);
1834 fail_unless_equals_int (data2[0], 0x20);
1835 fail_unless_equals_int (data2[1], 0x80);
1836 fail_unless_equals_int (data2[2], 0x80);
1837 fail_unless_equals_int (data2[3], 0x80);
1839 gst_buffer_unmap (pix2, &map);
1841 /* again: unscaled pixel-data, global-alpha not applied,
1842 * this should revert alpha-channel to initial values */
1843 pix2 = gst_video_overlay_rectangle_get_pixels_unscaled_raw (rect1,
1844 GST_VIDEO_OVERLAY_FORMAT_FLAG_GLOBAL_ALPHA);
1845 fail_unless (pix2 == pix1);
1846 /* make sure we got the initial data (input=0x80808080) */
1847 gst_buffer_map (pix2, &map, GST_MAP_READ);
1849 #if G_BYTE_ORDER == G_LITTLE_ENDIAN
1851 fail_unless_equals_int (data2[0], 0x80);
1852 fail_unless_equals_int (data2[1], 0x80);
1853 fail_unless_equals_int (data2[2], 0x80);
1854 fail_unless_equals_int (data2[3], 0x80);
1857 fail_unless_equals_int (data2[0], 0x80);
1858 fail_unless_equals_int (data2[1], 0x80);
1859 fail_unless_equals_int (data2[2], 0x80);
1860 fail_unless_equals_int (data2[3], 0x80);
1862 gst_buffer_unmap (pix2, &map);
1864 /* now scaled, global-alpha not applied */
1865 pix2 = gst_video_overlay_rectangle_get_pixels_raw (rect1,
1866 GST_VIDEO_OVERLAY_FORMAT_FLAG_GLOBAL_ALPHA);
1867 /* this should just return the rect/buffer, that was cached for these
1868 * scaling dimensions */
1869 fail_unless (pix2 == pix3);
1870 /* make sure we got the initial data (input=0x80808080) */
1871 gst_buffer_map (pix2, &map, GST_MAP_READ);
1873 #if G_BYTE_ORDER == G_LITTLE_ENDIAN
1875 fail_unless_equals_int (data2[0], 0x80);
1876 fail_unless_equals_int (data2[1], 0x80);
1877 fail_unless_equals_int (data2[2], 0x80);
1878 fail_unless_equals_int (data2[3], 0x80);
1881 fail_unless_equals_int (data2[0], 0x80);
1882 fail_unless_equals_int (data2[1], 0x80);
1883 fail_unless_equals_int (data2[2], 0x80);
1884 fail_unless_equals_int (data2[3], 0x80);
1886 gst_buffer_unmap (pix2, &map);
1888 /* scaled, global-alpha (0.25) applied */
1889 pix2 = gst_video_overlay_rectangle_get_pixels_raw (rect1,
1890 GST_VIDEO_OVERLAY_FORMAT_FLAG_NONE);
1891 /* this should just return the rect/buffer, that was cached for these
1892 * scaling dimensions with modified alpha channel */
1893 fail_unless (pix2 == pix3);
1894 /* make sure we got the data we expect for global-alpha=0.25 */
1895 gst_buffer_map (pix2, &map, GST_MAP_READ);
1897 #if G_BYTE_ORDER == G_LITTLE_ENDIAN
1899 fail_unless_equals_int (data2[0], 0x80);
1900 fail_unless_equals_int (data2[1], 0x80);
1901 fail_unless_equals_int (data2[2], 0x80);
1902 fail_unless_equals_int (data2[3], 0x20);
1905 fail_unless_equals_int (data2[0], 0x20);
1906 fail_unless_equals_int (data2[1], 0x80);
1907 fail_unless_equals_int (data2[2], 0x80);
1908 fail_unless_equals_int (data2[3], 0x80);
1910 gst_buffer_unmap (pix2, &map);
1912 /* now unscaled premultiplied data, global-alpha not applied,
1913 * is this really a valid use case?*/
1914 pix2 = gst_video_overlay_rectangle_get_pixels_unscaled_raw (rect1,
1915 GST_VIDEO_OVERLAY_FORMAT_FLAG_PREMULTIPLIED_ALPHA |
1916 GST_VIDEO_OVERLAY_FORMAT_FLAG_GLOBAL_ALPHA);
1917 /* this should just return the rect/buffer, that was cached for the
1918 * premultiplied data */
1919 fail_unless (pix2 == pix4);
1920 /* make sure we got what we expected */
1921 gst_buffer_map (pix2, &map, GST_MAP_READ);
1923 #if G_BYTE_ORDER == G_LITTLE_ENDIAN
1925 fail_unless_equals_int (data2[0], 0x40);
1926 fail_unless_equals_int (data2[1], 0x40);
1927 fail_unless_equals_int (data2[2], 0x40);
1928 fail_unless_equals_int (data2[3], 0x80);
1931 fail_unless_equals_int (data2[0], 0x80);
1932 fail_unless_equals_int (data2[1], 0x40);
1933 fail_unless_equals_int (data2[2], 0x40);
1934 fail_unless_equals_int (data2[3], 0x40);
1936 gst_buffer_unmap (pix2, &map);
1938 /* unscaled premultiplied data, global-alpha (0.25) applied */
1939 pix2 = gst_video_overlay_rectangle_get_pixels_unscaled_raw (rect1,
1940 GST_VIDEO_OVERLAY_FORMAT_FLAG_PREMULTIPLIED_ALPHA);
1941 /* this should just return the rect/buffer, that was cached for the
1942 * premultiplied data */
1943 fail_unless (pix2 == pix4);
1944 /* make sure we got what we expected:
1945 * (0x40 / (0x80/0xFF) * (0x20/0xFF) = 0x10
1946 * NOTE: unless we are using round() for the premultiplied case
1947 * in gst_video_overlay_rectangle_apply_global_alpha() we get rounding
1948 * error, i.e. 0x0F here */
1949 gst_buffer_map (pix2, &map, GST_MAP_READ);
1951 #if G_BYTE_ORDER == G_LITTLE_ENDIAN
1953 fail_unless_equals_int (data2[0], 0x0F);
1954 fail_unless_equals_int (data2[1], 0x0F);
1955 fail_unless_equals_int (data2[2], 0x0F);
1956 fail_unless_equals_int (data2[3], 0x20);
1959 fail_unless_equals_int (data2[0], 0x20);
1960 fail_unless_equals_int (data2[1], 0x0F);
1961 fail_unless_equals_int (data2[2], 0x0F);
1962 fail_unless_equals_int (data2[3], 0x0F);
1964 gst_buffer_unmap (pix2, &map);
1966 /* set global_alpha once more */
1967 gst_video_overlay_rectangle_set_global_alpha (rect1, 0.75);
1968 /* and verify that also premultiplied data is adjusted
1969 * correspondingly (though with increasing rounding errors) */
1970 pix2 = gst_video_overlay_rectangle_get_pixels_unscaled_raw (rect1,
1971 GST_VIDEO_OVERLAY_FORMAT_FLAG_PREMULTIPLIED_ALPHA);
1972 /* this should just return the rect/buffer, that was cached for the
1973 * premultiplied data */
1974 fail_unless (pix2 == pix4);
1975 /* make sure we got what we expected:
1976 * (0x0F / (0x20/0xFF) * (0x60/0xFF) = 0x2D
1977 * NOTE: using floats everywhere we would get 0x30
1978 * here we will actually end up with 0x2C */
1979 gst_buffer_map (pix2, &map, GST_MAP_READ);
1981 #if G_BYTE_ORDER == G_LITTLE_ENDIAN
1983 fail_unless_equals_int (data2[0], 0x2C);
1984 fail_unless_equals_int (data2[1], 0x2C);
1985 fail_unless_equals_int (data2[2], 0x2C);
1986 fail_unless_equals_int (data2[3], 0x60);
1989 fail_unless_equals_int (data2[0], 0x60);
1990 fail_unless_equals_int (data2[1], 0x2C);
1991 fail_unless_equals_int (data2[2], 0x2C);
1992 fail_unless_equals_int (data2[3], 0x2C);
1994 gst_buffer_unmap (pix2, &map);
1996 /* now scaled and premultiplied data, global-alpha not applied,
1997 * is this really a valid use case?*/
1998 pix2 = gst_video_overlay_rectangle_get_pixels_raw (rect1,
1999 GST_VIDEO_OVERLAY_FORMAT_FLAG_PREMULTIPLIED_ALPHA |
2000 GST_VIDEO_OVERLAY_FORMAT_FLAG_GLOBAL_ALPHA);
2001 /* this should just return the rect/buffer, that was cached for the
2002 * first premultiplied+scaled rect*/
2003 fail_unless (pix2 == pix5);
2004 /* make sure we got what we expected */
2005 gst_buffer_map (pix2, &map, GST_MAP_READ);
2007 #if G_BYTE_ORDER == G_LITTLE_ENDIAN
2009 fail_unless_equals_int (data2[0], 0x40);
2010 fail_unless_equals_int (data2[1], 0x40);
2011 fail_unless_equals_int (data2[2], 0x40);
2012 fail_unless_equals_int (data2[3], 0x80);
2015 fail_unless_equals_int (data2[0], 0x80);
2016 fail_unless_equals_int (data2[1], 0x40);
2017 fail_unless_equals_int (data2[2], 0x40);
2018 fail_unless_equals_int (data2[3], 0x40);
2020 gst_buffer_unmap (pix2, &map);
2022 /* scaled and premultiplied data, global-alpha applied */
2023 pix2 = gst_video_overlay_rectangle_get_pixels_raw (rect1,
2024 GST_VIDEO_OVERLAY_FORMAT_FLAG_PREMULTIPLIED_ALPHA);
2025 /* this should just return the rect/buffer, that was cached for the
2026 * first premultiplied+scaled rect*/
2027 fail_unless (pix2 == pix5);
2028 /* make sure we got what we expected; see above note about rounding errors! */
2029 gst_buffer_map (pix2, &map, GST_MAP_READ);
2031 #if G_BYTE_ORDER == G_LITTLE_ENDIAN
2033 fail_unless_equals_int (data2[0], 0x2F);
2034 fail_unless_equals_int (data2[1], 0x2F);
2035 fail_unless_equals_int (data2[2], 0x2F);
2036 fail_unless_equals_int (data2[3], 0x60);
2039 fail_unless_equals_int (data2[0], 0x60);
2040 fail_unless_equals_int (data2[1], 0x2F);
2041 fail_unless_equals_int (data2[2], 0x2F);
2042 fail_unless_equals_int (data2[3], 0x2F);
2044 gst_buffer_unmap (pix2, &map);
2046 gst_video_overlay_rectangle_unref (rect1);
2052 make_pixels (gint depth, gint width, gint height)
2054 guint32 color = 0xff000000;
2058 guint8 *pixels = g_malloc (width * height * 4);
2059 for (i = 0; i < height; i++) {
2060 for (j = 0; j < width; j++) {
2061 pixels[(i * width + j) * 4 + 0] = ((color >> 24) & 0xff);
2062 pixels[(i * width + j) * 4 + 1] = ((color >> 16) & 0xff);
2063 pixels[(i * width + j) * 4 + 2] = ((color >> 8) & 0xff);
2064 pixels[(i * width + j) * 4 + 3] = (color & 0xff);
2070 #define TO16(a) (((a)<<8)|(a))
2071 guint16 *pixels = g_malloc (width * height * 8);
2072 for (i = 0; i < height; i++) {
2073 for (j = 0; j < width; j++) {
2074 pixels[(i * width + j) * 4 + 0] = TO16 ((color >> 24) & 0xff);
2075 pixels[(i * width + j) * 4 + 1] = TO16 ((color >> 16) & 0xff);
2076 pixels[(i * width + j) * 4 + 2] = TO16 ((color >> 8) & 0xff);
2077 pixels[(i * width + j) * 4 + 3] = TO16 (color & 0xff);
2082 return (guint8 *) pixels;
2086 #define HS(x,o) ((x)&hs[o])
2087 #define WS(x,o) ((x)&ws[o])
2088 #define IN(i,j,o) (in[(HS(i, o)*width + WS(j,o))*4+(o)] & mask[o])
2089 #define OUT(i,j,o) (out[((i)*width + (j))*4+o] & mask[o])
2091 compare_frame (const GstVideoFormatInfo * finfo, gint depth, guint8 * outpixels,
2092 guint8 * pixels, gint width, gint height)
2095 guint ws[4], hs[4], mask[4];
2097 for (k = 0; k < 4; k++) {
2098 hs[k] = G_MAXUINT << finfo->h_sub[(3 + k) % 4];
2099 ws[k] = G_MAXUINT << finfo->w_sub[(3 + k) % 4];
2100 mask[k] = G_MAXUINT << (depth - finfo->depth[(3 + k) % 4]);
2104 guint8 *in = pixels;
2105 guint8 *out = outpixels;
2107 for (i = 0; i < height; i++) {
2108 for (j = 0; j < width; j++) {
2109 for (k = 0; k < 4; k++) {
2110 diff += IN (i, j, k) != OUT (i, j, k);
2115 guint16 *in = (guint16 *) pixels;
2116 guint16 *out = (guint16 *) outpixels;
2118 for (i = 0; i < height; i++) {
2119 for (j = 0; j < width; j++) {
2120 for (k = 0; k < 4; k++) {
2121 diff += IN (i, j, k) != OUT (i, j, k);
2136 GstVideoFormat infmt;
2137 GstVideoFormat outfmt;
2139 gdouble convert_sec;
2142 #define SIGN(a,b) ((a) < (b) ? -1 : (a) > (b) ? 1 : 0)
2145 compare_result (gconstpointer a, gconstpointer b)
2147 const ConvertResult *ap = a;
2148 const ConvertResult *bp = b;
2150 return SIGN (ap->convert_sec, bp->convert_sec);
2153 #define UNPACK_FRAME(frame,dest,line,x,width) \
2154 (frame)->info.finfo->unpack_func ((frame)->info.finfo, \
2155 (GST_VIDEO_FRAME_IS_INTERLACED (frame) ? \
2156 GST_VIDEO_PACK_FLAG_INTERLACED : \
2157 GST_VIDEO_PACK_FLAG_NONE), \
2158 dest, (frame)->data, (frame)->info.stride, x, \
2160 #define PACK_FRAME(frame,src,line,width) \
2161 (frame)->info.finfo->pack_func ((frame)->info.finfo, \
2162 (GST_VIDEO_FRAME_IS_INTERLACED (frame) ? \
2163 GST_VIDEO_PACK_FLAG_INTERLACED : \
2164 GST_VIDEO_PACK_FLAG_NONE), \
2165 src, 0, (frame)->data, (frame)->info.stride, \
2166 (frame)->info.chroma_site, line, width);
2168 GST_START_TEST (test_video_pack_unpack2)
2170 GstVideoFormat format;
2172 gint num_formats, i;
2173 GArray *packarray, *unpackarray;
2177 /* set to something larger to do benchmarks */
2180 timer = g_timer_new ();
2181 packarray = g_array_new (FALSE, FALSE, sizeof (ConvertResult));
2182 unpackarray = g_array_new (FALSE, FALSE, sizeof (ConvertResult));
2184 num_formats = get_num_formats ();
2186 GST_DEBUG ("pack/sec\t unpack/sec \tpack GB/sec\tunpack GB/sec\tformat");
2188 for (format = GST_VIDEO_FORMAT_I420; format < num_formats; format++) {
2190 const GstVideoFormatInfo *finfo, *fuinfo;
2192 GstVideoFrame frame;
2193 gint k, stride, count, diff, depth;
2194 guint8 *pixels, *outpixels;
2196 gdouble unpack_sec, pack_sec;
2199 finfo = gst_video_format_get_info (format);
2200 fail_unless (finfo != NULL);
2202 if (GST_VIDEO_FORMAT_INFO_HAS_PALETTE (finfo))
2205 fuinfo = gst_video_format_get_info (finfo->unpack_format);
2206 fail_unless (fuinfo != NULL);
2208 depth = GST_VIDEO_FORMAT_INFO_BITS (fuinfo);
2209 fail_unless (depth == 8 || depth == 16);
2211 pixels = make_pixels (depth, WIDTH, HEIGHT);
2212 stride = WIDTH * (depth >> 1);
2214 fail_unless (gst_video_info_set_format (&info, format, WIDTH, HEIGHT));
2215 buffer = gst_buffer_new_and_alloc (info.size);
2216 gst_video_frame_map (&frame, &info, buffer, GST_MAP_READWRITE);
2218 /* pack the frame into the target format */
2220 PACK_FRAME (&frame, pixels, 0, WIDTH);
2223 g_timer_start (timer);
2225 for (k = 0; k < HEIGHT; k += finfo->pack_lines) {
2226 PACK_FRAME (&frame, pixels + k * stride, k, WIDTH);
2229 elapsed = g_timer_elapsed (timer, NULL);
2230 if (elapsed >= TIME)
2233 unpack_sec = count / elapsed;
2236 res.outfmt = finfo->unpack_format;
2237 res.convert_sec = unpack_sec;
2238 g_array_append_val (unpackarray, res);
2240 outpixels = g_malloc0 (HEIGHT * stride);
2242 /* unpack the frame */
2244 UNPACK_FRAME (&frame, outpixels, 0, 0, WIDTH);
2247 g_timer_start (timer);
2249 for (k = 0; k < HEIGHT; k += finfo->pack_lines) {
2250 UNPACK_FRAME (&frame, outpixels + k * stride, k, 0, WIDTH);
2253 elapsed = g_timer_elapsed (timer, NULL);
2254 if (elapsed >= TIME)
2257 pack_sec = count / elapsed;
2259 res.outfmt = format;
2260 res.infmt = finfo->unpack_format;
2261 res.convert_sec = pack_sec;
2262 g_array_append_val (packarray, res);
2264 /* compare the frame */
2265 diff = compare_frame (finfo, depth, outpixels, pixels, WIDTH, HEIGHT);
2267 GST_DEBUG ("%f \t %f \t %f \t %f \t %s %d/%f", pack_sec, unpack_sec,
2268 info.size * pack_sec, info.size * unpack_sec, finfo->name, count,
2272 gst_util_dump_mem (outpixels, 128);
2273 gst_util_dump_mem (pixels, 128);
2274 fail_if (diff != 0);
2276 gst_video_frame_unmap (&frame);
2277 gst_buffer_unref (buffer);
2282 g_array_sort (packarray, compare_result);
2283 for (i = 0; i < packarray->len; i++) {
2284 ConvertResult *res = &g_array_index (packarray, ConvertResult, i);
2286 GST_DEBUG ("%f pack/sec %s->%s", res->convert_sec,
2287 gst_video_format_to_string (res->infmt),
2288 gst_video_format_to_string (res->outfmt));
2291 g_array_sort (unpackarray, compare_result);
2292 for (i = 0; i < unpackarray->len; i++) {
2293 ConvertResult *res = &g_array_index (unpackarray, ConvertResult, i);
2295 GST_DEBUG ("%f unpack/sec %s->%s", res->convert_sec,
2296 gst_video_format_to_string (res->infmt),
2297 gst_video_format_to_string (res->outfmt));
2300 g_timer_destroy (timer);
2301 g_array_free (packarray, TRUE);
2302 g_array_free (unpackarray, TRUE);
2313 #define GET_LINE(l) (pixels + CLAMP (l, 0, HEIGHT-1) * WIDTH * 4)
2314 GST_START_TEST (test_video_chroma)
2318 gint i, j, k, offset, count;
2321 gdouble elapsed, subsample_sec;
2322 GstVideoChromaSite sites[] = {
2323 GST_VIDEO_CHROMA_SITE_NONE,
2324 GST_VIDEO_CHROMA_SITE_H_COSITED,
2327 timer = g_timer_new ();
2328 pixels = make_pixels (8, WIDTH, HEIGHT);
2330 for (k = 0; k < G_N_ELEMENTS (sites); k++) {
2331 GstVideoChromaResample *resample;
2333 resample = gst_video_chroma_resample_new (GST_VIDEO_CHROMA_METHOD_LINEAR,
2334 sites[k], GST_VIDEO_CHROMA_FLAG_NONE, GST_VIDEO_FORMAT_AYUV, -1, -1);
2336 gst_video_chroma_resample_get_info (resample, &n_lines, &offset);
2337 fail_unless (n_lines < 10);
2340 for (j = 0; j < n_lines; j++)
2341 lines[j] = GET_LINE (offset + j);
2342 gst_video_chroma_resample (resample, lines, WIDTH);
2345 g_timer_start (timer);
2347 for (i = 0; i < HEIGHT; i += n_lines) {
2348 for (j = 0; j < n_lines; j++)
2349 lines[j] = GET_LINE (i + offset + j);
2351 gst_video_chroma_resample (resample, lines, WIDTH);
2354 elapsed = g_timer_elapsed (timer, NULL);
2355 if (elapsed >= TIME)
2358 subsample_sec = count / elapsed;
2359 GST_DEBUG ("%f downsamples/sec %d/%f", subsample_sec, count, elapsed);
2360 gst_video_chroma_resample_free (resample);
2362 resample = gst_video_chroma_resample_new (GST_VIDEO_CHROMA_METHOD_LINEAR,
2363 sites[k], GST_VIDEO_CHROMA_FLAG_NONE, GST_VIDEO_FORMAT_AYUV, 1, 1);
2365 gst_video_chroma_resample_get_info (resample, &n_lines, &offset);
2366 fail_unless (n_lines < 10);
2369 for (j = 0; j < n_lines; j++)
2370 lines[j] = GET_LINE (offset + j);
2371 gst_video_chroma_resample (resample, lines, WIDTH);
2374 g_timer_start (timer);
2376 for (i = 0; i < HEIGHT; i += n_lines) {
2377 for (j = 0; j < n_lines; j++)
2378 lines[j] = GET_LINE (i + offset + j);
2380 gst_video_chroma_resample (resample, lines, WIDTH);
2383 elapsed = g_timer_elapsed (timer, NULL);
2384 if (elapsed >= TIME)
2387 subsample_sec = count / elapsed;
2388 GST_DEBUG ("%f upsamples/sec %d/%f", subsample_sec, count, elapsed);
2389 gst_video_chroma_resample_free (resample);
2393 g_timer_destroy (timer);
2401 GST_START_TEST (test_video_scaler)
2403 GstVideoScaler *scale;
2405 scale = gst_video_scaler_new (GST_VIDEO_RESAMPLER_METHOD_LINEAR,
2406 GST_VIDEO_SCALER_FLAG_NONE, 2, 10, 5, NULL);
2407 gst_video_scaler_free (scale);
2409 scale = gst_video_scaler_new (GST_VIDEO_RESAMPLER_METHOD_LINEAR,
2410 GST_VIDEO_SCALER_FLAG_NONE, 2, 15, 5, NULL);
2411 gst_video_scaler_free (scale);
2427 check_video_format_is_type (GstVideoFormat fmt, ColorType fmt_type)
2429 const GstVideoFormatInfo *info = gst_video_format_get_info (fmt);
2430 gboolean is_rgb = GST_VIDEO_FORMAT_INFO_IS_RGB (info);
2431 gboolean is_yuv = GST_VIDEO_FORMAT_INFO_IS_YUV (info);
2441 return !is_rgb && !is_yuv;
2445 run_video_color_convert (ColorType in_type, ColorType out_type)
2447 GstVideoFormat infmt, outfmt;
2450 num_formats = get_num_formats ();
2452 for (infmt = GST_VIDEO_FORMAT_I420; infmt < num_formats; infmt++) {
2453 GstVideoInfo ininfo;
2454 GstVideoFrame inframe;
2455 GstBuffer *inbuffer;
2457 if (!check_video_format_is_type (infmt, in_type))
2460 fail_unless (gst_video_info_set_format (&ininfo, infmt, WIDTH, HEIGHT));
2461 inbuffer = gst_buffer_new_and_alloc (ininfo.size);
2462 gst_buffer_memset (inbuffer, 0, 0, -1);
2463 gst_video_frame_map (&inframe, &ininfo, inbuffer, GST_MAP_READ);
2465 for (outfmt = GST_VIDEO_FORMAT_I420; outfmt < num_formats; outfmt++) {
2466 GstVideoInfo outinfo;
2467 GstVideoFrame outframe;
2468 GstBuffer *outbuffer;
2469 GstVideoConverter *convert;
2471 if (!check_video_format_is_type (outfmt, out_type))
2474 GST_LOG ("%s -> %s @ %ux%u", gst_video_format_to_string (infmt),
2475 gst_video_format_to_string (outfmt), WIDTH, HEIGHT);
2477 fail_unless (gst_video_info_set_format (&outinfo, outfmt, WIDTH, HEIGHT));
2478 outbuffer = gst_buffer_new_and_alloc (outinfo.size);
2479 gst_video_frame_map (&outframe, &outinfo, outbuffer, GST_MAP_WRITE);
2481 convert = gst_video_converter_new (&ininfo, &outinfo, NULL);
2483 gst_video_converter_frame (convert, &inframe, &outframe);
2485 gst_video_converter_free (convert);
2487 gst_video_frame_unmap (&outframe);
2488 gst_buffer_unref (outbuffer);
2490 gst_video_frame_unmap (&inframe);
2491 gst_buffer_unref (inbuffer);
2495 GST_START_TEST (test_video_color_convert_rgb_rgb)
2497 run_video_color_convert (RGB, RGB);
2502 GST_START_TEST (test_video_color_convert_rgb_yuv)
2504 run_video_color_convert (RGB, YUV);
2509 GST_START_TEST (test_video_color_convert_yuv_yuv)
2511 run_video_color_convert (YUV, YUV);
2516 GST_START_TEST (test_video_color_convert_yuv_rgb)
2518 run_video_color_convert (YUV, RGB);
2523 GST_START_TEST (test_video_color_convert_other)
2525 run_video_color_convert (OTHER, RGB);
2526 run_video_color_convert (RGB, OTHER);
2527 run_video_color_convert (OTHER, YUV);
2528 run_video_color_convert (YUV, OTHER);
2529 run_video_color_convert (OTHER, OTHER);
2536 #define WIDTH_IN 320
2537 #define HEIGHT_IN 240
2538 #define WIDTH_OUT 400
2539 #define HEIGHT_OUT 300
2542 GST_START_TEST (test_video_size_convert)
2544 GstVideoFormat infmt, outfmt;
2546 gint num_formats, i;
2549 array = g_array_new (FALSE, FALSE, sizeof (ConvertResult));
2551 timer = g_timer_new ();
2553 num_formats = get_num_formats ();
2555 for (infmt = GST_VIDEO_FORMAT_I420; infmt < num_formats; infmt++) {
2556 GstVideoInfo ininfo, outinfo;
2557 GstVideoFrame inframe, outframe;
2558 GstBuffer *inbuffer, *outbuffer;
2559 GstVideoConverter *convert;
2564 fail_unless (gst_video_info_set_format (&ininfo, infmt, WIDTH_IN,
2566 inbuffer = gst_buffer_new_and_alloc (ininfo.size);
2567 gst_buffer_memset (inbuffer, 0, 0, -1);
2568 gst_video_frame_map (&inframe, &ininfo, inbuffer, GST_MAP_READ);
2571 fail_unless (gst_video_info_set_format (&outinfo, outfmt, WIDTH_OUT,
2573 outbuffer = gst_buffer_new_and_alloc (outinfo.size);
2574 gst_video_frame_map (&outframe, &outinfo, outbuffer, GST_MAP_WRITE);
2576 for (method = 0; method < 4; method++) {
2577 convert = gst_video_converter_new (&ininfo, &outinfo,
2578 gst_structure_new ("options",
2579 GST_VIDEO_CONVERTER_OPT_RESAMPLER_METHOD,
2580 GST_TYPE_VIDEO_RESAMPLER_METHOD, method, NULL));
2583 gst_video_converter_frame (convert, &inframe, &outframe);
2586 g_timer_start (timer);
2588 gst_video_converter_frame (convert, &inframe, &outframe);
2591 elapsed = g_timer_elapsed (timer, NULL);
2592 if (elapsed >= TIME)
2597 res.outfmt = outfmt;
2598 res.method = method;
2599 res.convert_sec = count / elapsed;
2601 GST_DEBUG ("%f resize/sec %s->%s, %d, %d/%f", res.convert_sec,
2602 gst_video_format_to_string (infmt),
2603 gst_video_format_to_string (outfmt), method, count, elapsed);
2605 g_array_append_val (array, res);
2607 gst_video_converter_free (convert);
2609 gst_video_frame_unmap (&outframe);
2610 gst_buffer_unref (outbuffer);
2611 gst_video_frame_unmap (&inframe);
2612 gst_buffer_unref (inbuffer);
2615 g_array_sort (array, compare_result);
2617 for (i = 0; i < array->len; i++) {
2618 ConvertResult *res = &g_array_index (array, ConvertResult, i);
2620 GST_DEBUG ("%f method %d, resize/sec %s->%s", res->convert_sec, res->method,
2621 gst_video_format_to_string (res->infmt),
2622 gst_video_format_to_string (res->outfmt));
2625 g_array_free (array, TRUE);
2627 g_timer_destroy (timer);
2634 GST_START_TEST (test_video_convert)
2636 GstVideoInfo ininfo, outinfo;
2637 GstVideoFrame inframe, outframe;
2638 GstBuffer *inbuffer, *outbuffer;
2639 GstVideoConverter *convert;
2641 fail_unless (gst_video_info_set_format (&ininfo, GST_VIDEO_FORMAT_ARGB, 320,
2643 inbuffer = gst_buffer_new_and_alloc (ininfo.size);
2644 gst_buffer_memset (inbuffer, 0, 0, -1);
2645 gst_video_frame_map (&inframe, &ininfo, inbuffer, GST_MAP_READ);
2647 fail_unless (gst_video_info_set_format (&outinfo, GST_VIDEO_FORMAT_BGRx, 400,
2649 outbuffer = gst_buffer_new_and_alloc (outinfo.size);
2650 gst_video_frame_map (&outframe, &outinfo, outbuffer, GST_MAP_WRITE);
2652 /* see that we don't reuse the source line directly because we need
2653 * to add borders to it */
2654 convert = gst_video_converter_new (&ininfo, &outinfo,
2655 gst_structure_new ("options",
2656 GST_VIDEO_CONVERTER_OPT_RESAMPLER_METHOD,
2657 GST_TYPE_VIDEO_RESAMPLER_METHOD, 3,
2658 GST_VIDEO_CONVERTER_OPT_SRC_X, G_TYPE_INT, 10,
2659 GST_VIDEO_CONVERTER_OPT_SRC_Y, G_TYPE_INT, 0,
2660 GST_VIDEO_CONVERTER_OPT_SRC_WIDTH, G_TYPE_INT, 300,
2661 GST_VIDEO_CONVERTER_OPT_SRC_HEIGHT, G_TYPE_INT, 220,
2662 GST_VIDEO_CONVERTER_OPT_DEST_X, G_TYPE_INT, 80,
2663 GST_VIDEO_CONVERTER_OPT_DEST_Y, G_TYPE_INT, 60,
2664 GST_VIDEO_CONVERTER_OPT_DEST_WIDTH, G_TYPE_INT, 300,
2665 GST_VIDEO_CONVERTER_OPT_DEST_HEIGHT, G_TYPE_INT, 220, NULL));
2667 gst_video_converter_frame (convert, &inframe, &outframe);
2668 gst_video_converter_free (convert);
2670 /* see that we reuse the source line directly because we need to scale
2672 convert = gst_video_converter_new (&ininfo, &outinfo,
2673 gst_structure_new ("options",
2674 GST_VIDEO_CONVERTER_OPT_RESAMPLER_METHOD,
2675 GST_TYPE_VIDEO_RESAMPLER_METHOD, 3,
2676 GST_VIDEO_CONVERTER_OPT_SRC_X, G_TYPE_INT, 10,
2677 GST_VIDEO_CONVERTER_OPT_SRC_Y, G_TYPE_INT, 0,
2678 GST_VIDEO_CONVERTER_OPT_SRC_WIDTH, G_TYPE_INT, 300,
2679 GST_VIDEO_CONVERTER_OPT_SRC_HEIGHT, G_TYPE_INT, 220,
2680 GST_VIDEO_CONVERTER_OPT_DEST_X, G_TYPE_INT, 80,
2681 GST_VIDEO_CONVERTER_OPT_DEST_Y, G_TYPE_INT, 60,
2682 GST_VIDEO_CONVERTER_OPT_DEST_WIDTH, G_TYPE_INT, 310,
2683 GST_VIDEO_CONVERTER_OPT_DEST_HEIGHT, G_TYPE_INT, 230, NULL));
2685 gst_video_converter_frame (convert, &inframe, &outframe);
2687 /* Check that video convert doesn't crash if we give it frames with different info
2688 * than we configured it with by swapping width/height */
2689 gst_video_frame_unmap (&inframe);
2690 fail_unless (gst_video_info_set_format (&ininfo, GST_VIDEO_FORMAT_ARGB, 240,
2692 gst_video_frame_map (&inframe, &ininfo, inbuffer, GST_MAP_READ);
2693 ASSERT_CRITICAL (gst_video_converter_frame (convert, &inframe, &outframe));
2694 gst_video_converter_free (convert);
2696 /* Make sure we can crop the entire frame away without dying */
2697 convert = gst_video_converter_new (&ininfo, &outinfo,
2698 gst_structure_new ("options",
2699 GST_VIDEO_CONVERTER_OPT_RESAMPLER_METHOD,
2700 GST_TYPE_VIDEO_RESAMPLER_METHOD, 3,
2701 GST_VIDEO_CONVERTER_OPT_SRC_X, G_TYPE_INT, -500,
2702 GST_VIDEO_CONVERTER_OPT_SRC_Y, G_TYPE_INT, -500,
2703 GST_VIDEO_CONVERTER_OPT_SRC_WIDTH, G_TYPE_INT, 300,
2704 GST_VIDEO_CONVERTER_OPT_SRC_HEIGHT, G_TYPE_INT, 220,
2705 GST_VIDEO_CONVERTER_OPT_DEST_X, G_TYPE_INT, 800,
2706 GST_VIDEO_CONVERTER_OPT_DEST_Y, G_TYPE_INT, 600,
2707 GST_VIDEO_CONVERTER_OPT_DEST_WIDTH, G_TYPE_INT, 310,
2708 GST_VIDEO_CONVERTER_OPT_DEST_HEIGHT, G_TYPE_INT, 230, NULL));
2710 gst_video_converter_frame (convert, &inframe, &outframe);
2711 gst_video_converter_free (convert);
2713 gst_video_frame_unmap (&outframe);
2714 gst_buffer_unref (outbuffer);
2715 gst_video_frame_unmap (&inframe);
2716 gst_buffer_unref (inbuffer);
2722 GST_START_TEST (test_video_transfer)
2726 for (j = GST_VIDEO_TRANSFER_GAMMA10; j <= GST_VIDEO_TRANSFER_ARIB_STD_B67;
2728 for (i = 0; i < 256; i++) {
2731 val1 = gst_video_color_transfer_encode (j, i / 255.0);
2732 fail_if (val1 < 0.0 || val1 > 1.0);
2734 val2 = gst_video_color_transfer_decode (j, val1);
2735 fail_if (val2 < 0.0 || val2 > 1.0);
2737 GST_DEBUG ("%d: %d %f->%f->%f %d", j, i, i / 255.0, val1, val2,
2738 (int) lrint (val2 * 255.0));
2740 fail_if (val2 != 0.0);
2742 fail_if (lrint (val2 * 255.0) != i);
2749 GST_START_TEST (test_video_center_rect)
2751 GstVideoRectangle src, dest, result, expected;
2753 #define NEW_RECT(x,y,w,h) ((GstVideoRectangle) {x,y,w,h})
2754 #define CHECK_RECT(res, exp) \
2755 fail_unless_equals_int(exp.x, res.x);\
2756 fail_unless_equals_int(exp.y, res.y);\
2757 fail_unless_equals_int(exp.w, res.w);\
2758 fail_unless_equals_int(exp.h, res.h);
2760 /* 1:1 Aspect Ratio */
2761 src = NEW_RECT (0, 0, 100, 100);
2762 dest = NEW_RECT (0, 0, 100, 100);
2763 expected = NEW_RECT (0, 0, 100, 100);
2764 gst_video_sink_center_rect (src, dest, &result, TRUE);
2765 CHECK_RECT (result, expected);
2767 src = NEW_RECT (0, 0, 100, 100);
2768 dest = NEW_RECT (0, 0, 50, 50);
2769 expected = NEW_RECT (0, 0, 50, 50);
2770 gst_video_sink_center_rect (src, dest, &result, TRUE);
2771 CHECK_RECT (result, expected);
2773 src = NEW_RECT (0, 0, 100, 100);
2774 dest = NEW_RECT (50, 50, 100, 100);
2775 expected = NEW_RECT (50, 50, 100, 100);
2776 gst_video_sink_center_rect (src, dest, &result, TRUE);
2777 CHECK_RECT (result, expected);
2779 /* Aspect ratio scaling (tall) */
2780 src = NEW_RECT (0, 0, 50, 100);
2781 dest = NEW_RECT (0, 0, 50, 50);
2782 expected = NEW_RECT (12, 0, 25, 50);
2783 gst_video_sink_center_rect (src, dest, &result, TRUE);
2784 CHECK_RECT (result, expected);
2786 src = NEW_RECT (0, 0, 50, 100);
2787 dest = NEW_RECT (50, 50, 50, 50);
2788 expected = NEW_RECT (62, 50, 25, 50);
2789 gst_video_sink_center_rect (src, dest, &result, TRUE);
2790 CHECK_RECT (result, expected);
2792 /* Aspect ratio scaling (wide) */
2793 src = NEW_RECT (0, 0, 100, 50);
2794 dest = NEW_RECT (0, 0, 50, 50);
2795 expected = NEW_RECT (0, 12, 50, 25);
2796 gst_video_sink_center_rect (src, dest, &result, TRUE);
2797 CHECK_RECT (result, expected);
2799 src = NEW_RECT (0, 0, 100, 50);
2800 dest = NEW_RECT (50, 50, 50, 50);
2801 expected = NEW_RECT (50, 62, 50, 25);
2802 gst_video_sink_center_rect (src, dest, &result, TRUE);
2803 CHECK_RECT (result, expected);
2808 void test_overlay_blend_rect (gint x, gint y, gint width, gint height,
2809 GstVideoFrame * video_frame);
2810 void test_overlay_blend_rect_verify (gint x, gint y, gint width,
2811 gint height, GstVideoFrame * video_frame);
2812 #define VIDEO_WIDTH 320
2813 #define VIDEO_HEIGHT 240
2816 test_overlay_blend_rect_verify (gint x, gint y, gint width, gint height,
2817 GstVideoFrame * video_frame)
2820 gint i = 0, prev_i = 0;
2822 gint temp_width = 0, temp_height = 0;
2824 data = GST_VIDEO_FRAME_PLANE_DATA (video_frame, 0);
2825 size = GST_VIDEO_FRAME_SIZE (video_frame);
2827 if (x + width < 0 || y + height < 0 || x >= VIDEO_WIDTH || y >= VIDEO_HEIGHT)
2830 temp_width = width + x;
2831 else if (x > 0 && (x + width) <= VIDEO_WIDTH)
2834 temp_width = VIDEO_WIDTH - x;
2836 temp_height = height + y;
2837 else if (y > 0 && (y + height) <= VIDEO_HEIGHT)
2838 temp_height = height;
2840 temp_height = VIDEO_HEIGHT - y;
2842 if (x <= 0 && y <= 0)
2845 i = (((x <= 0) ? 0 : x) + (((y <= 0) ? 0 : y) * VIDEO_WIDTH)) * 4;
2848 for (; i < size - 4; i += 4) {
2849 #if G_BYTE_ORDER == G_LITTLE_ENDIAN
2851 fail_unless_equals_int (data[i], 0x80);
2852 fail_unless_equals_int (data[i + 1], 0x80);
2853 fail_unless_equals_int (data[i + 2], 0x80);
2854 fail_unless_equals_int (data[i + 3], 0x80);
2857 fail_unless_equals_int (data[i], 0x80);
2858 fail_unless_equals_int (data[i + 1], 0x80);
2859 fail_unless_equals_int (data[i + 2], 0x80);
2860 fail_unless_equals_int (data[i + 3], 0x80);
2862 if ((i + 4) == (4 * (((((y > 0) ? (y + temp_height) : temp_height) -
2863 1) * VIDEO_WIDTH) + ((x >
2864 0) ? (x + temp_width) : temp_width))))
2866 if ((i + 4 - prev_i) == ((temp_width) * 4)) {
2867 i += ((VIDEO_WIDTH - (temp_width)) * 4);
2875 test_overlay_blend_rect (gint x, gint y, gint width, gint height,
2876 GstVideoFrame * video_frame)
2878 GstVideoOverlayComposition *comp1;
2879 GstVideoOverlayRectangle *rect1;
2880 GstBuffer *pix, *pix1;
2883 memset (video_frame, 0, sizeof (GstVideoFrame));
2885 gst_buffer_new_and_alloc (VIDEO_WIDTH * VIDEO_HEIGHT * sizeof (guint32));
2886 gst_buffer_memset (pix, 0, 0, gst_buffer_get_size (pix));
2887 gst_video_info_init (&vinfo);
2888 fail_unless (gst_video_info_set_format (&vinfo,
2889 GST_VIDEO_OVERLAY_COMPOSITION_FORMAT_RGB, VIDEO_WIDTH, VIDEO_HEIGHT));
2890 gst_video_frame_map (video_frame, &vinfo, pix, GST_MAP_READWRITE);
2891 gst_buffer_unref (pix);
2894 pix1 = gst_buffer_new_and_alloc (width * height * sizeof (guint32));
2895 gst_buffer_memset (pix1, 0, 0x80, gst_buffer_get_size (pix1));
2896 gst_buffer_add_video_meta (pix1, GST_VIDEO_FRAME_FLAG_NONE,
2897 GST_VIDEO_OVERLAY_COMPOSITION_FORMAT_RGB, width, height);
2898 rect1 = gst_video_overlay_rectangle_new_raw (pix1,
2899 x, y, width, height, GST_VIDEO_OVERLAY_FORMAT_FLAG_NONE);
2900 gst_buffer_unref (pix1);
2903 comp1 = gst_video_overlay_composition_new (rect1);
2904 fail_unless (gst_video_overlay_composition_blend (comp1, video_frame));
2905 gst_video_overlay_composition_unref (comp1);
2906 gst_video_overlay_rectangle_unref (rect1);
2908 test_overlay_blend_rect_verify (x, y, width, height, video_frame);
2909 gst_video_frame_unmap (video_frame);
2912 GST_START_TEST (test_overlay_blend)
2914 GstVideoFrame video_frame;
2916 /* Overlay width & height smaller than video width & height */
2917 /* Overlay rendered completely left of video surface
2918 * x + overlay_width <= 0 */
2919 test_overlay_blend_rect (-60, 50, 50, 50, &video_frame);
2920 /* Overlay rendered completely right of video surface
2921 * x >= video_width */
2922 test_overlay_blend_rect (330, 50, 50, 50, &video_frame);
2923 /* Overlay rendered completely top of video surface
2924 * y + overlay_height <= 0 */
2925 test_overlay_blend_rect (50, -60, 50, 50, &video_frame);
2926 /* Overlay rendered completely bottom of video surface
2927 * y >= video_height */
2928 test_overlay_blend_rect (50, 250, 50, 50, &video_frame);
2929 /* Overlay rendered partially left of video surface
2930 * x < 0 && -x < overlay_width */
2931 test_overlay_blend_rect (-40, 50, 50, 50, &video_frame);
2932 /* Overlay rendered partially right of video surface
2933 * x < video_width && (overlay_width + x) > video_width */
2934 test_overlay_blend_rect (300, 50, 50, 50, &video_frame);
2935 /* Overlay rendered partially top of video surface
2936 * y < 0 && -y < overlay_height */
2937 test_overlay_blend_rect (50, -40, 50, 50, &video_frame);
2938 /* Overlay rendered partially bottom of video surface
2939 * y < video_height && (overlay_height + y) > video_height */
2940 test_overlay_blend_rect (50, 220, 50, 50, &video_frame);
2942 /* Overlay width & height bigger than video width & height */
2943 /* Overlay rendered completely left of video surface
2944 * x + overlay_width <= 0 */
2945 test_overlay_blend_rect (-360, 50, 350, 250, &video_frame);
2946 /* Overlay rendered completely right of video surface
2947 * x >= video_width */
2948 test_overlay_blend_rect (330, 50, 350, 250, &video_frame);
2949 /* Overlay rendered completely top of video surface
2950 * y + overlay_height <= 0 */
2951 test_overlay_blend_rect (50, -260, 350, 250, &video_frame);
2952 /* Overlay rendered completely bottom of video surface
2953 * y >= video_height */
2954 test_overlay_blend_rect (50, 250, 350, 250, &video_frame);
2955 /* Overlay rendered partially left of video surface
2956 * x < 0 && -x < overlay_width */
2957 test_overlay_blend_rect (-40, 50, 350, 250, &video_frame);
2958 /* Overlay rendered partially right of video surface
2959 * x < video_width && (overlay_width + x) > video_width */
2960 test_overlay_blend_rect (300, 50, 350, 250, &video_frame);
2961 /* Overlay rendered partially top of video surface
2962 * y < 0 && -y < overlay_height */
2963 test_overlay_blend_rect (50, -40, 350, 250, &video_frame);
2964 /* Overlay rendered partially bottom of video surface
2965 * y < video_height && (overlay_height + y) > video_height */
2966 test_overlay_blend_rect (50, 220, 350, 250, &video_frame);
2971 GST_START_TEST (test_overlay_composition_over_transparency)
2973 GstVideoOverlayComposition *comp1;
2974 GstVideoOverlayRectangle *rect1;
2975 GstBuffer *pix1, *pix2;
2979 GstVideoFrame video_frame;
2980 guint fwidth = 200, height = 50, swidth = 100;
2982 memset (&video_frame, 0, sizeof (GstVideoFrame));
2984 pix1 = gst_buffer_new_and_alloc (fwidth * sizeof (guint32) * height);
2985 gst_buffer_memset (pix1, 0, 0x00, gst_buffer_get_size (pix1));
2986 gst_video_info_init (&vinfo);
2987 fail_unless (gst_video_info_set_format (&vinfo,
2988 GST_VIDEO_OVERLAY_COMPOSITION_FORMAT_RGB, fwidth, height));
2989 gst_video_frame_map (&video_frame, &vinfo, pix1, GST_MAP_READWRITE);
2990 gst_buffer_unref (pix1);
2992 pix2 = gst_buffer_new_and_alloc (swidth * sizeof (guint32) * height);
2993 gst_buffer_memset (pix2, 0, 0xFF, gst_buffer_get_size (pix2));
2994 gst_buffer_add_video_meta (pix2, GST_VIDEO_FRAME_FLAG_NONE,
2995 GST_VIDEO_OVERLAY_COMPOSITION_FORMAT_RGB, swidth, height);
2996 rect1 = gst_video_overlay_rectangle_new_raw (pix2, swidth, 0,
2997 swidth, height, GST_VIDEO_OVERLAY_FORMAT_FLAG_NONE);
2999 comp1 = gst_video_overlay_composition_new (rect1);
3000 fail_unless (gst_video_overlay_composition_blend (comp1, &video_frame));
3001 gst_video_overlay_composition_unref (comp1);
3002 gst_video_overlay_rectangle_unref (rect1);
3003 gst_buffer_unref (pix2);
3005 data = GST_VIDEO_FRAME_PLANE_DATA (&video_frame, 0);
3007 fail_unless_equals_int (data[0], 0x00);
3008 fail_unless_equals_int (data[1], 0x00);
3009 fail_unless_equals_int (data[2], 0x00);
3010 fail_unless_equals_int (data[3], 0x00);
3012 data += swidth * sizeof (guint32);
3014 fail_unless_equals_int (data[0], 0xFF);
3015 fail_unless_equals_int (data[1], 0xFF);
3016 fail_unless_equals_int (data[2], 0xFF);
3017 fail_unless_equals_int (data[3], 0xFF);
3019 gst_video_frame_unmap (&video_frame);
3024 GST_START_TEST (test_video_format_enum_stability)
3026 /* When adding new formats, adding a format in the middle of the enum will
3027 * break the API. This check picks the last known format and checks that
3028 * it's value isn't changing. This test should ideall be updated when a new
3029 * format is added, though will stay valid. */
3030 fail_unless_equals_int (GST_VIDEO_FORMAT_Y210, 82);
3035 GST_START_TEST (test_video_formats_pstrides)
3037 GstVideoFormat fmt = GST_VIDEO_FORMAT_I420;
3040 while ((gst_video_format_to_string (fmt) != NULL)) {
3041 const GstVideoFormatInfo *vf_info = gst_video_format_get_info (fmt);
3042 guint n_comps = GST_VIDEO_FORMAT_INFO_N_COMPONENTS (vf_info);
3044 GST_LOG ("format: %s (%d), n_comps = %u", vf_info->name, fmt, n_comps);
3046 if (fmt == GST_VIDEO_FORMAT_v210
3047 || fmt == GST_VIDEO_FORMAT_UYVP
3048 || fmt == GST_VIDEO_FORMAT_IYU1
3049 || fmt == GST_VIDEO_FORMAT_GRAY10_LE32
3050 || fmt == GST_VIDEO_FORMAT_NV12_64Z32
3051 || fmt == GST_VIDEO_FORMAT_NV12_10LE32
3052 || fmt == GST_VIDEO_FORMAT_NV16_10LE32
3053 || fmt == GST_VIDEO_FORMAT_NV12_10LE40
3054 || fmt == GST_VIDEO_FORMAT_Y410) {
3061 fail_unless (GST_VIDEO_FORMAT_INFO_PSTRIDE (vf_info, 3) > 0);
3064 fail_unless (GST_VIDEO_FORMAT_INFO_PSTRIDE (vf_info, 2) > 0);
3067 fail_unless (GST_VIDEO_FORMAT_INFO_PSTRIDE (vf_info, 1) > 0);
3070 fail_unless (GST_VIDEO_FORMAT_INFO_PSTRIDE (vf_info, 0) > 0);
3080 GST_START_TEST (test_hdr)
3083 GstCaps *other_caps;
3084 GstVideoMasteringDisplayInfo minfo;
3085 GstVideoMasteringDisplayInfo other_minfo;
3086 GstVideoMasteringDisplayInfo minfo_from_caps;
3087 GstVideoContentLightLevel level;
3088 GstVideoContentLightLevel other_level;
3089 GstVideoContentLightLevel level_from_caps;
3090 GstStructure *s = NULL;
3092 gchar *level_str = NULL;
3097 gst_video_mastering_display_info_init (&minfo);
3098 gst_video_mastering_display_info_init (&other_minfo);
3100 /* Test GstVideoMasteringDisplayInfo, initialize with random values
3101 * just for comparison */
3103 for (i = 0; i < G_N_ELEMENTS (minfo.display_primaries); i++) {
3104 minfo.display_primaries[i].x = val++;
3105 minfo.display_primaries[i].y = val++;
3107 minfo.white_point.x = val++;
3108 minfo.white_point.y = val++;
3109 minfo.max_display_mastering_luminance = val++;
3110 minfo.min_display_mastering_luminance = val++;
3112 caps = gst_caps_new_empty_simple ("video/x-raw");
3113 minfo_str = gst_video_mastering_display_info_to_string (&minfo);
3114 fail_unless (minfo_str != NULL, "cannot convert info to string");
3115 GST_DEBUG ("converted mastering info string %s", minfo_str);
3117 gst_caps_set_simple (caps, "mastering-display-info",
3118 G_TYPE_STRING, minfo_str, NULL);
3122 /* manually parsing mastering info from string */
3123 s = gst_caps_get_structure (caps, 0);
3124 minfo_str = (gchar *) gst_structure_get_string (s, "mastering-display-info");
3125 fail_unless (minfo_str != NULL);
3126 fail_unless (gst_video_mastering_display_info_from_string
3127 (&other_minfo, minfo_str), "cannot get mastering info from string");
3128 GST_DEBUG ("extracted info string %s", minfo_str);
3130 fail_unless (gst_video_mastering_display_info_is_equal (&minfo,
3131 &other_minfo), "Extracted mastering info is not equal to original");
3133 /* simplified version for caps use case */
3134 fail_unless (gst_video_mastering_display_info_from_caps (&minfo_from_caps,
3135 caps), "cannot parse mastering info from caps");
3136 fail_unless (gst_video_mastering_display_info_is_equal (&minfo,
3138 "Extracted mastering info is not equal to original");
3140 /* check _add_to_caps () and manually created one */
3141 other_caps = gst_caps_new_empty_simple ("video/x-raw");
3142 fail_unless (gst_video_mastering_display_info_add_to_caps (&other_minfo,
3144 fail_unless (gst_caps_is_equal (caps, other_caps));
3146 gst_caps_unref (caps);
3147 gst_caps_unref (other_caps);
3149 /* Test GstVideoContentLightLevel */
3150 gst_video_content_light_level_init (&level);
3151 gst_video_content_light_level_init (&other_level);
3153 level.max_content_light_level = 1000;
3154 level.max_frame_average_light_level = 300;
3156 caps = gst_caps_new_empty_simple ("video/x-raw");
3157 level_str = gst_video_content_light_level_to_string (&level);
3158 fail_unless (level_str != NULL);
3160 gst_caps_set_simple (caps, "content-light-level",
3161 G_TYPE_STRING, level_str, NULL);
3164 /* manually parsing CLL info from string */
3165 s = gst_caps_get_structure (caps, 0);
3166 fail_unless (gst_structure_get (s, "content-light-level",
3167 G_TYPE_STRING, &level_str, NULL), "Failed to get level from caps");
3168 fail_unless (gst_video_content_light_level_from_string (&other_level,
3172 fail_unless_equals_int (level.max_content_light_level,
3173 other_level.max_content_light_level);
3174 fail_unless_equals_int (level.max_frame_average_light_level,
3175 other_level.max_frame_average_light_level);
3177 /* simplified version for caps use case */
3178 fail_unless (gst_video_content_light_level_from_caps (&level_from_caps,
3180 fail_unless_equals_int (level.max_content_light_level,
3181 level_from_caps.max_content_light_level);
3182 fail_unless_equals_int (level.max_frame_average_light_level,
3183 level_from_caps.max_frame_average_light_level);
3185 /* check _add_to_caps () and manually created one */
3186 other_caps = gst_caps_new_empty_simple ("video/x-raw");
3187 fail_unless (gst_video_content_light_level_add_to_caps (&other_level,
3189 fail_unless (gst_caps_is_equal (caps, other_caps));
3191 gst_caps_unref (caps);
3192 gst_caps_unref (other_caps);
3197 GST_START_TEST (test_video_color_from_to_iso)
3201 #define ISO_IEC_UNSPECIFIED_COLOR_VALUE 2
3203 for (i = 0; i <= GST_VIDEO_COLOR_MATRIX_BT2020; i++) {
3204 guint matrix_val = gst_video_color_matrix_to_iso (i);
3205 fail_unless_equals_int (gst_video_color_matrix_from_iso (matrix_val), i);
3208 for (i = 0; i <= GST_VIDEO_TRANSFER_ARIB_STD_B67; i++) {
3209 guint transfer_val = gst_video_color_transfer_to_iso (i);
3211 /* don't know how to map below values to spec. */
3212 if (i == GST_VIDEO_TRANSFER_GAMMA18 || i == GST_VIDEO_TRANSFER_GAMMA20
3213 || i == GST_VIDEO_TRANSFER_ADOBERGB) {
3214 fail_unless_equals_int (transfer_val, ISO_IEC_UNSPECIFIED_COLOR_VALUE);
3218 fail_unless_equals_int (gst_video_color_transfer_from_iso (transfer_val),
3222 for (i = 0; i <= GST_VIDEO_COLOR_PRIMARIES_EBU3213; i++) {
3223 guint primaries_val = gst_video_color_primaries_to_iso (i);
3225 /* don't know how to map below value to spec. */
3226 if (i == GST_VIDEO_COLOR_PRIMARIES_ADOBERGB) {
3227 fail_unless_equals_int (primaries_val, ISO_IEC_UNSPECIFIED_COLOR_VALUE);
3231 fail_unless_equals_int (gst_video_color_primaries_from_iso (primaries_val),
3234 #undef ISO_IEC_UNSPECIFIED_COLOR_VALUE
3239 GST_START_TEST (test_video_format_info_plane_to_components)
3241 const GstVideoFormatInfo *info;
3242 gint comps[GST_VIDEO_MAX_COMPONENTS];
3244 /* RGB: 1 plane, 3 components */
3245 info = gst_video_format_get_info (GST_VIDEO_FORMAT_RGB);
3247 gst_video_format_info_component (info, 0, comps);
3248 g_assert_cmpint (comps[0], ==, 0);
3249 g_assert_cmpint (comps[1], ==, 1);
3250 g_assert_cmpint (comps[2], ==, 2);
3251 g_assert_cmpint (comps[3], ==, -1);
3253 gst_video_format_info_component (info, 1, comps);
3254 g_assert_cmpint (comps[0], ==, -1);
3255 g_assert_cmpint (comps[1], ==, -1);
3256 g_assert_cmpint (comps[2], ==, -1);
3257 g_assert_cmpint (comps[3], ==, -1);
3259 gst_video_format_info_component (info, 2, comps);
3260 g_assert_cmpint (comps[0], ==, -1);
3261 g_assert_cmpint (comps[1], ==, -1);
3262 g_assert_cmpint (comps[2], ==, -1);
3263 g_assert_cmpint (comps[3], ==, -1);
3265 gst_video_format_info_component (info, 3, comps);
3266 g_assert_cmpint (comps[0], ==, -1);
3267 g_assert_cmpint (comps[1], ==, -1);
3268 g_assert_cmpint (comps[2], ==, -1);
3269 g_assert_cmpint (comps[3], ==, -1);
3271 /* I420: 3 planes, 3 components */
3272 info = gst_video_format_get_info (GST_VIDEO_FORMAT_I420);
3274 gst_video_format_info_component (info, 0, comps);
3275 g_assert_cmpint (comps[0], ==, 0);
3276 g_assert_cmpint (comps[1], ==, -1);
3277 g_assert_cmpint (comps[2], ==, -1);
3278 g_assert_cmpint (comps[3], ==, -1);
3280 gst_video_format_info_component (info, 1, comps);
3281 g_assert_cmpint (comps[0], ==, 1);
3282 g_assert_cmpint (comps[1], ==, -1);
3283 g_assert_cmpint (comps[2], ==, -1);
3284 g_assert_cmpint (comps[3], ==, -1);
3286 gst_video_format_info_component (info, 2, comps);
3287 g_assert_cmpint (comps[0], ==, 2);
3288 g_assert_cmpint (comps[1], ==, -1);
3289 g_assert_cmpint (comps[2], ==, -1);
3290 g_assert_cmpint (comps[3], ==, -1);
3292 gst_video_format_info_component (info, 3, comps);
3293 g_assert_cmpint (comps[0], ==, -1);
3294 g_assert_cmpint (comps[1], ==, -1);
3295 g_assert_cmpint (comps[2], ==, -1);
3296 g_assert_cmpint (comps[3], ==, -1);
3298 /* NV12: 2 planes, 3 components */
3299 info = gst_video_format_get_info (GST_VIDEO_FORMAT_NV12);
3301 gst_video_format_info_component (info, 0, comps);
3302 g_assert_cmpint (comps[0], ==, 0);
3303 g_assert_cmpint (comps[1], ==, -1);
3304 g_assert_cmpint (comps[2], ==, -1);
3305 g_assert_cmpint (comps[3], ==, -1);
3307 gst_video_format_info_component (info, 1, comps);
3308 g_assert_cmpint (comps[0], ==, 1);
3309 g_assert_cmpint (comps[1], ==, 2);
3310 g_assert_cmpint (comps[2], ==, -1);
3311 g_assert_cmpint (comps[3], ==, -1);
3313 gst_video_format_info_component (info, 2, comps);
3314 g_assert_cmpint (comps[0], ==, -1);
3315 g_assert_cmpint (comps[1], ==, -1);
3316 g_assert_cmpint (comps[2], ==, -1);
3317 g_assert_cmpint (comps[3], ==, -1);
3319 gst_video_format_info_component (info, 3, comps);
3320 g_assert_cmpint (comps[0], ==, -1);
3321 g_assert_cmpint (comps[1], ==, -1);
3322 g_assert_cmpint (comps[2], ==, -1);
3323 g_assert_cmpint (comps[3], ==, -1);
3328 GST_START_TEST (test_video_info_align)
3331 GstVideoAlignment align;
3332 gsize plane_size[GST_VIDEO_MAX_PLANES];
3335 gst_video_info_init (&info);
3336 gst_video_info_set_format (&info, GST_VIDEO_FORMAT_NV12, 1920, 1080);
3338 g_assert_cmpuint (GST_VIDEO_INFO_HEIGHT (&info), ==, 1080);
3339 g_assert_cmpuint (GST_VIDEO_INFO_FIELD_HEIGHT (&info), ==, 1080);
3340 g_assert_cmpuint (GST_VIDEO_INFO_SIZE (&info), ==, 1920 * 1080 * 1.5);
3342 gst_video_alignment_reset (&align);
3343 /* Align with no padding to retrieve the plane heights */
3344 g_assert (gst_video_info_align_full (&info, &align, plane_size));
3346 g_assert_cmpuint (plane_size[0], ==, 1920 * 1080);
3347 g_assert_cmpuint (plane_size[1], ==, 1920 * 1080 / 2);
3348 g_assert_cmpuint (plane_size[2], ==, 0);
3349 g_assert_cmpuint (plane_size[3], ==, 0);
3351 g_assert_cmpuint (GST_VIDEO_INFO_PLANE_STRIDE (&info, 0), ==, 1920);
3352 g_assert_cmpuint (GST_VIDEO_INFO_PLANE_STRIDE (&info, 1), ==, 1920);
3353 g_assert_cmpuint (GST_VIDEO_INFO_PLANE_STRIDE (&info, 2), ==, 0);
3354 g_assert_cmpuint (GST_VIDEO_INFO_PLANE_STRIDE (&info, 3), ==, 0);
3355 g_assert_cmpuint (GST_VIDEO_INFO_PLANE_HEIGHT (&info, 0, plane_size), ==,
3357 g_assert_cmpuint (GST_VIDEO_INFO_PLANE_HEIGHT (&info, 1, plane_size), ==,
3359 g_assert_cmpuint (GST_VIDEO_INFO_PLANE_HEIGHT (&info, 2, plane_size), ==, 0);
3360 g_assert_cmpuint (GST_VIDEO_INFO_PLANE_HEIGHT (&info, 3, plane_size), ==, 0);
3362 gst_video_alignment_reset (&align);
3363 align.padding_bottom = 8;
3364 g_assert (gst_video_info_align_full (&info, &align, plane_size));
3366 g_assert_cmpuint (plane_size[0], ==, 1920 * 1088);
3367 g_assert_cmpuint (plane_size[1], ==, 1920 * 1088 / 2);
3368 g_assert_cmpuint (plane_size[2], ==, 0);
3369 g_assert_cmpuint (plane_size[3], ==, 0);
3371 g_assert_cmpuint (GST_VIDEO_INFO_HEIGHT (&info), ==, 1080);
3372 g_assert_cmpuint (GST_VIDEO_INFO_FIELD_HEIGHT (&info), ==, 1080);
3373 g_assert_cmpuint (GST_VIDEO_INFO_SIZE (&info), ==, 1920 * 1088 * 1.5);
3375 g_assert_cmpuint (GST_VIDEO_INFO_PLANE_STRIDE (&info, 0), ==, 1920);
3376 g_assert_cmpuint (GST_VIDEO_INFO_PLANE_STRIDE (&info, 1), ==, 1920);
3377 g_assert_cmpuint (GST_VIDEO_INFO_PLANE_STRIDE (&info, 2), ==, 0);
3378 g_assert_cmpuint (GST_VIDEO_INFO_PLANE_STRIDE (&info, 3), ==, 0);
3379 g_assert_cmpuint (GST_VIDEO_INFO_PLANE_HEIGHT (&info, 0, plane_size), ==,
3381 g_assert_cmpuint (GST_VIDEO_INFO_PLANE_HEIGHT (&info, 1, plane_size), ==,
3383 g_assert_cmpuint (GST_VIDEO_INFO_PLANE_HEIGHT (&info, 2, plane_size), ==, 0);
3384 g_assert_cmpuint (GST_VIDEO_INFO_PLANE_HEIGHT (&info, 3, plane_size), ==, 0);
3387 gst_video_info_init (&info);
3388 gst_video_info_set_format (&info, GST_VIDEO_FORMAT_NV16, 1920, 1080);
3390 g_assert_cmpuint (GST_VIDEO_INFO_HEIGHT (&info), ==, 1080);
3391 g_assert_cmpuint (GST_VIDEO_INFO_FIELD_HEIGHT (&info), ==, 1080);
3392 g_assert_cmpuint (GST_VIDEO_INFO_SIZE (&info), ==, 1920 * 1080 * 2);
3394 gst_video_alignment_reset (&align);
3395 /* Align with no padding to retrieve the plane heights */
3396 g_assert (gst_video_info_align_full (&info, &align, plane_size));
3398 g_assert_cmpuint (plane_size[0], ==, 1920 * 1080);
3399 g_assert_cmpuint (plane_size[1], ==, 1920 * 1080);
3400 g_assert_cmpuint (plane_size[2], ==, 0);
3401 g_assert_cmpuint (plane_size[3], ==, 0);
3403 g_assert_cmpuint (GST_VIDEO_INFO_PLANE_STRIDE (&info, 0), ==, 1920);
3404 g_assert_cmpuint (GST_VIDEO_INFO_PLANE_STRIDE (&info, 1), ==, 1920);
3405 g_assert_cmpuint (GST_VIDEO_INFO_PLANE_STRIDE (&info, 2), ==, 0);
3406 g_assert_cmpuint (GST_VIDEO_INFO_PLANE_STRIDE (&info, 3), ==, 0);
3407 g_assert_cmpuint (GST_VIDEO_INFO_PLANE_HEIGHT (&info, 0, plane_size), ==,
3409 g_assert_cmpuint (GST_VIDEO_INFO_PLANE_HEIGHT (&info, 1, plane_size), ==,
3411 g_assert_cmpuint (GST_VIDEO_INFO_PLANE_HEIGHT (&info, 2, plane_size), ==, 0);
3412 g_assert_cmpuint (GST_VIDEO_INFO_PLANE_HEIGHT (&info, 3, plane_size), ==, 0);
3414 gst_video_alignment_reset (&align);
3415 align.padding_bottom = 8;
3416 g_assert (gst_video_info_align_full (&info, &align, plane_size));
3418 g_assert_cmpuint (GST_VIDEO_INFO_HEIGHT (&info), ==, 1080);
3419 g_assert_cmpuint (GST_VIDEO_INFO_FIELD_HEIGHT (&info), ==, 1080);
3420 g_assert_cmpuint (GST_VIDEO_INFO_SIZE (&info), ==, 1920 * 1088 * 2);
3422 g_assert_cmpuint (plane_size[0], ==, 1920 * 1088);
3423 g_assert_cmpuint (plane_size[1], ==, 1920 * 1088);
3424 g_assert_cmpuint (plane_size[2], ==, 0);
3425 g_assert_cmpuint (plane_size[3], ==, 0);
3427 g_assert_cmpuint (GST_VIDEO_INFO_PLANE_STRIDE (&info, 0), ==, 1920);
3428 g_assert_cmpuint (GST_VIDEO_INFO_PLANE_STRIDE (&info, 1), ==, 1920);
3429 g_assert_cmpuint (GST_VIDEO_INFO_PLANE_STRIDE (&info, 2), ==, 0);
3430 g_assert_cmpuint (GST_VIDEO_INFO_PLANE_STRIDE (&info, 3), ==, 0);
3431 g_assert_cmpuint (GST_VIDEO_INFO_PLANE_HEIGHT (&info, 0, plane_size), ==,
3433 g_assert_cmpuint (GST_VIDEO_INFO_PLANE_HEIGHT (&info, 1, plane_size), ==,
3435 g_assert_cmpuint (GST_VIDEO_INFO_PLANE_HEIGHT (&info, 2, plane_size), ==, 0);
3436 g_assert_cmpuint (GST_VIDEO_INFO_PLANE_HEIGHT (&info, 3, plane_size), ==, 0);
3439 gst_video_info_init (&info);
3440 gst_video_info_set_format (&info, GST_VIDEO_FORMAT_RGB, 1920, 1080);
3442 g_assert_cmpuint (GST_VIDEO_INFO_HEIGHT (&info), ==, 1080);
3443 g_assert_cmpuint (GST_VIDEO_INFO_FIELD_HEIGHT (&info), ==, 1080);
3444 g_assert_cmpuint (GST_VIDEO_INFO_SIZE (&info), ==, 1920 * 1080 * 3);
3446 gst_video_alignment_reset (&align);
3447 /* Align with no padding to retrieve the plane heights */
3448 g_assert (gst_video_info_align_full (&info, &align, plane_size));
3450 g_assert_cmpuint (plane_size[0], ==, 1920 * 1080 * 3);
3451 g_assert_cmpuint (plane_size[1], ==, 0);
3452 g_assert_cmpuint (plane_size[2], ==, 0);
3453 g_assert_cmpuint (plane_size[3], ==, 0);
3455 g_assert_cmpuint (GST_VIDEO_INFO_PLANE_STRIDE (&info, 0), ==, 5760);
3456 g_assert_cmpuint (GST_VIDEO_INFO_PLANE_STRIDE (&info, 1), ==, 0);
3457 g_assert_cmpuint (GST_VIDEO_INFO_PLANE_STRIDE (&info, 2), ==, 0);
3458 g_assert_cmpuint (GST_VIDEO_INFO_PLANE_STRIDE (&info, 3), ==, 0);
3459 g_assert_cmpuint (GST_VIDEO_INFO_PLANE_HEIGHT (&info, 0, plane_size), ==,
3461 g_assert_cmpuint (GST_VIDEO_INFO_PLANE_HEIGHT (&info, 1, plane_size), ==, 0);
3462 g_assert_cmpuint (GST_VIDEO_INFO_PLANE_HEIGHT (&info, 2, plane_size), ==, 0);
3463 g_assert_cmpuint (GST_VIDEO_INFO_PLANE_HEIGHT (&info, 3, plane_size), ==, 0);
3465 gst_video_alignment_reset (&align);
3466 align.padding_bottom = 8;
3467 g_assert (gst_video_info_align_full (&info, &align, plane_size));
3469 g_assert_cmpuint (GST_VIDEO_INFO_HEIGHT (&info), ==, 1080);
3470 g_assert_cmpuint (GST_VIDEO_INFO_FIELD_HEIGHT (&info), ==, 1080);
3471 g_assert_cmpuint (GST_VIDEO_INFO_SIZE (&info), ==, 1920 * 1088 * 3);
3473 g_assert_cmpuint (plane_size[0], ==, 1920 * 1088 * 3);
3474 g_assert_cmpuint (plane_size[1], ==, 0);
3475 g_assert_cmpuint (plane_size[2], ==, 0);
3476 g_assert_cmpuint (plane_size[3], ==, 0);
3478 g_assert_cmpuint (GST_VIDEO_INFO_PLANE_STRIDE (&info, 0), ==, 5760);
3479 g_assert_cmpuint (GST_VIDEO_INFO_PLANE_STRIDE (&info, 1), ==, 0);
3480 g_assert_cmpuint (GST_VIDEO_INFO_PLANE_STRIDE (&info, 2), ==, 0);
3481 g_assert_cmpuint (GST_VIDEO_INFO_PLANE_STRIDE (&info, 3), ==, 0);
3482 g_assert_cmpuint (GST_VIDEO_INFO_PLANE_HEIGHT (&info, 0, plane_size), ==,
3484 g_assert_cmpuint (GST_VIDEO_INFO_PLANE_HEIGHT (&info, 1, plane_size), ==, 0);
3485 g_assert_cmpuint (GST_VIDEO_INFO_PLANE_HEIGHT (&info, 2, plane_size), ==, 0);
3486 g_assert_cmpuint (GST_VIDEO_INFO_PLANE_HEIGHT (&info, 3, plane_size), ==, 0);
3489 gst_video_info_init (&info);
3490 gst_video_info_set_format (&info, GST_VIDEO_FORMAT_I420, 1920, 1080);
3492 g_assert_cmpuint (GST_VIDEO_INFO_HEIGHT (&info), ==, 1080);
3493 g_assert_cmpuint (GST_VIDEO_INFO_FIELD_HEIGHT (&info), ==, 1080);
3494 g_assert_cmpuint (GST_VIDEO_INFO_SIZE (&info), ==, 1920 * 1080 * 1.5);
3496 gst_video_alignment_reset (&align);
3497 /* Align with no padding to retrieve the plane heights */
3498 g_assert (gst_video_info_align_full (&info, &align, plane_size));
3500 g_assert_cmpuint (plane_size[0], ==, 1920 * 1080);
3501 g_assert_cmpuint (plane_size[1], ==, 1920 * 1080 / 4);
3502 g_assert_cmpuint (plane_size[2], ==, 1920 * 1080 / 4);
3503 g_assert_cmpuint (plane_size[3], ==, 0);
3505 g_assert_cmpuint (GST_VIDEO_INFO_PLANE_STRIDE (&info, 0), ==, 1920);
3506 g_assert_cmpuint (GST_VIDEO_INFO_PLANE_STRIDE (&info, 1), ==, 960);
3507 g_assert_cmpuint (GST_VIDEO_INFO_PLANE_STRIDE (&info, 2), ==, 960);
3508 g_assert_cmpuint (GST_VIDEO_INFO_PLANE_STRIDE (&info, 3), ==, 0);
3509 g_assert_cmpuint (GST_VIDEO_INFO_PLANE_HEIGHT (&info, 0, plane_size), ==,
3511 g_assert_cmpuint (GST_VIDEO_INFO_PLANE_HEIGHT (&info, 1, plane_size), ==,
3513 g_assert_cmpuint (GST_VIDEO_INFO_PLANE_HEIGHT (&info, 2, plane_size), ==,
3515 g_assert_cmpuint (GST_VIDEO_INFO_PLANE_HEIGHT (&info, 3, plane_size), ==, 0);
3517 gst_video_alignment_reset (&align);
3518 align.padding_bottom = 8;
3519 g_assert (gst_video_info_align_full (&info, &align, plane_size));
3521 g_assert_cmpuint (GST_VIDEO_INFO_HEIGHT (&info), ==, 1080);
3522 g_assert_cmpuint (GST_VIDEO_INFO_FIELD_HEIGHT (&info), ==, 1080);
3523 g_assert_cmpuint (GST_VIDEO_INFO_SIZE (&info), ==, 1920 * 1088 * 1.5);
3525 g_assert_cmpuint (plane_size[0], ==, 1920 * 1088);
3526 g_assert_cmpuint (plane_size[1], ==, 1920 * 1088 / 4);
3527 g_assert_cmpuint (plane_size[2], ==, 1920 * 1088 / 4);
3528 g_assert_cmpuint (plane_size[3], ==, 0);
3530 g_assert_cmpuint (GST_VIDEO_INFO_PLANE_STRIDE (&info, 0), ==, 1920);
3531 g_assert_cmpuint (GST_VIDEO_INFO_PLANE_STRIDE (&info, 1), ==, 960);
3532 g_assert_cmpuint (GST_VIDEO_INFO_PLANE_STRIDE (&info, 2), ==, 960);
3533 g_assert_cmpuint (GST_VIDEO_INFO_PLANE_STRIDE (&info, 3), ==, 0);
3534 g_assert_cmpuint (GST_VIDEO_INFO_PLANE_HEIGHT (&info, 0, plane_size), ==,
3536 g_assert_cmpuint (GST_VIDEO_INFO_PLANE_HEIGHT (&info, 1, plane_size), ==,
3538 g_assert_cmpuint (GST_VIDEO_INFO_PLANE_HEIGHT (&info, 2, plane_size), ==,
3540 g_assert_cmpuint (GST_VIDEO_INFO_PLANE_HEIGHT (&info, 3, plane_size), ==, 0);
3542 /* NV16 alternate */
3543 gst_video_info_init (&info);
3544 gst_video_info_set_interlaced_format (&info, GST_VIDEO_FORMAT_NV16,
3545 GST_VIDEO_INTERLACE_MODE_ALTERNATE, 1920, 1080);
3547 g_assert_cmpuint (GST_VIDEO_INFO_HEIGHT (&info), ==, 1080);
3548 g_assert_cmpuint (GST_VIDEO_INFO_FIELD_HEIGHT (&info), ==, 540);
3549 g_assert_cmpuint (GST_VIDEO_INFO_SIZE (&info), ==, 1920 * 540 * 2);
3551 gst_video_alignment_reset (&align);
3552 /* Align with no padding to retrieve the plane heights */
3553 g_assert (gst_video_info_align_full (&info, &align, plane_size));
3555 g_assert_cmpuint (plane_size[0], ==, 1920 * 540);
3556 g_assert_cmpuint (plane_size[1], ==, 1920 * 540);
3557 g_assert_cmpuint (plane_size[2], ==, 0);
3558 g_assert_cmpuint (plane_size[3], ==, 0);
3560 g_assert_cmpuint (GST_VIDEO_INFO_PLANE_STRIDE (&info, 0), ==, 1920);
3561 g_assert_cmpuint (GST_VIDEO_INFO_PLANE_STRIDE (&info, 1), ==, 1920);
3562 g_assert_cmpuint (GST_VIDEO_INFO_PLANE_STRIDE (&info, 2), ==, 0);
3563 g_assert_cmpuint (GST_VIDEO_INFO_PLANE_STRIDE (&info, 3), ==, 0);
3564 g_assert_cmpuint (GST_VIDEO_INFO_PLANE_HEIGHT (&info, 0, plane_size), ==,
3566 g_assert_cmpuint (GST_VIDEO_INFO_PLANE_HEIGHT (&info, 1, plane_size), ==,
3568 g_assert_cmpuint (GST_VIDEO_INFO_PLANE_HEIGHT (&info, 2, plane_size), ==, 0);
3569 g_assert_cmpuint (GST_VIDEO_INFO_PLANE_HEIGHT (&info, 3, plane_size), ==, 0);
3571 gst_video_alignment_reset (&align);
3572 align.padding_bottom = 8;
3573 g_assert (gst_video_info_align_full (&info, &align, plane_size));
3575 g_assert_cmpuint (GST_VIDEO_INFO_HEIGHT (&info), ==, 1080);
3576 g_assert_cmpuint (GST_VIDEO_INFO_FIELD_HEIGHT (&info), ==, 540);
3577 g_assert_cmpuint (GST_VIDEO_INFO_SIZE (&info), ==, 1920 * 544 * 2);
3579 g_assert_cmpuint (plane_size[0], ==, 1920 * 544);
3580 g_assert_cmpuint (plane_size[1], ==, 1920 * 544);
3581 g_assert_cmpuint (plane_size[2], ==, 0);
3582 g_assert_cmpuint (plane_size[3], ==, 0);
3584 g_assert_cmpuint (GST_VIDEO_INFO_PLANE_STRIDE (&info, 0), ==, 1920);
3585 g_assert_cmpuint (GST_VIDEO_INFO_PLANE_STRIDE (&info, 1), ==, 1920);
3586 g_assert_cmpuint (GST_VIDEO_INFO_PLANE_STRIDE (&info, 2), ==, 0);
3587 g_assert_cmpuint (GST_VIDEO_INFO_PLANE_STRIDE (&info, 3), ==, 0);
3588 g_assert_cmpuint (GST_VIDEO_INFO_PLANE_HEIGHT (&info, 0, plane_size), ==,
3590 g_assert_cmpuint (GST_VIDEO_INFO_PLANE_HEIGHT (&info, 1, plane_size), ==,
3592 g_assert_cmpuint (GST_VIDEO_INFO_PLANE_HEIGHT (&info, 2, plane_size), ==, 0);
3593 g_assert_cmpuint (GST_VIDEO_INFO_PLANE_HEIGHT (&info, 3, plane_size), ==, 0);
3595 /* NV16 alternate with an odd height */
3596 gst_video_info_init (&info);
3597 gst_video_info_set_interlaced_format (&info, GST_VIDEO_FORMAT_NV16,
3598 GST_VIDEO_INTERLACE_MODE_ALTERNATE, 1920, 1081);
3600 g_assert_cmpuint (GST_VIDEO_INFO_HEIGHT (&info), ==, 1081);
3601 g_assert_cmpuint (GST_VIDEO_INFO_FIELD_HEIGHT (&info), ==, 541);
3602 g_assert_cmpuint (GST_VIDEO_INFO_SIZE (&info), ==, 1920 * 541 * 2);
3604 gst_video_alignment_reset (&align);
3605 /* Align with no padding to retrieve the plane heights */
3606 g_assert (gst_video_info_align_full (&info, &align, plane_size));
3608 g_assert_cmpuint (plane_size[0], ==, 1920 * 541);
3609 g_assert_cmpuint (plane_size[1], ==, 1920 * 541);
3610 g_assert_cmpuint (plane_size[2], ==, 0);
3611 g_assert_cmpuint (plane_size[3], ==, 0);
3613 g_assert_cmpuint (GST_VIDEO_INFO_PLANE_STRIDE (&info, 0), ==, 1920);
3614 g_assert_cmpuint (GST_VIDEO_INFO_PLANE_STRIDE (&info, 1), ==, 1920);
3615 g_assert_cmpuint (GST_VIDEO_INFO_PLANE_STRIDE (&info, 2), ==, 0);
3616 g_assert_cmpuint (GST_VIDEO_INFO_PLANE_STRIDE (&info, 3), ==, 0);
3617 g_assert_cmpuint (GST_VIDEO_INFO_PLANE_HEIGHT (&info, 0, plane_size), ==,
3619 g_assert_cmpuint (GST_VIDEO_INFO_PLANE_HEIGHT (&info, 1, plane_size), ==,
3621 g_assert_cmpuint (GST_VIDEO_INFO_PLANE_HEIGHT (&info, 2, plane_size), ==, 0);
3622 g_assert_cmpuint (GST_VIDEO_INFO_PLANE_HEIGHT (&info, 3, plane_size), ==, 0);
3624 gst_video_alignment_reset (&align);
3625 align.padding_bottom = 2;
3626 g_assert (gst_video_info_align_full (&info, &align, plane_size));
3628 g_assert_cmpuint (GST_VIDEO_INFO_HEIGHT (&info), ==, 1081);
3629 g_assert_cmpuint (GST_VIDEO_INFO_FIELD_HEIGHT (&info), ==, 541);
3630 g_assert_cmpuint (GST_VIDEO_INFO_SIZE (&info), ==, 1920 * 542 * 2);
3632 g_assert_cmpuint (plane_size[0], ==, 1920 * 542);
3633 g_assert_cmpuint (plane_size[1], ==, 1920 * 542);
3634 g_assert_cmpuint (plane_size[2], ==, 0);
3635 g_assert_cmpuint (plane_size[3], ==, 0);
3637 g_assert_cmpuint (GST_VIDEO_INFO_PLANE_STRIDE (&info, 0), ==, 1920);
3638 g_assert_cmpuint (GST_VIDEO_INFO_PLANE_STRIDE (&info, 1), ==, 1920);
3639 g_assert_cmpuint (GST_VIDEO_INFO_PLANE_STRIDE (&info, 2), ==, 0);
3640 g_assert_cmpuint (GST_VIDEO_INFO_PLANE_STRIDE (&info, 3), ==, 0);
3641 g_assert_cmpuint (GST_VIDEO_INFO_PLANE_HEIGHT (&info, 0, plane_size), ==,
3643 g_assert_cmpuint (GST_VIDEO_INFO_PLANE_HEIGHT (&info, 1, plane_size), ==,
3645 g_assert_cmpuint (GST_VIDEO_INFO_PLANE_HEIGHT (&info, 2, plane_size), ==, 0);
3646 g_assert_cmpuint (GST_VIDEO_INFO_PLANE_HEIGHT (&info, 3, plane_size), ==, 0);
3651 GST_START_TEST (test_video_meta_align)
3656 gsize plane_size[GST_VIDEO_MAX_PLANES];
3657 guint plane_height[GST_VIDEO_MAX_PLANES];
3658 GstVideoAlignment alig;
3660 buf = gst_buffer_new ();
3662 /* NV12 no alignment */
3663 gst_video_info_init (&info);
3664 gst_video_info_set_format (&info, GST_VIDEO_FORMAT_NV12, 1920, 1080);
3666 meta = gst_buffer_add_video_meta_full (buf, GST_VIDEO_FRAME_FLAG_NONE,
3667 GST_VIDEO_INFO_FORMAT (&info), GST_VIDEO_INFO_WIDTH (&info),
3668 GST_VIDEO_INFO_HEIGHT (&info), GST_VIDEO_INFO_N_PLANES (&info),
3669 info.offset, info.stride);
3671 g_assert_cmpuint (meta->alignment.padding_top, ==, 0);
3672 g_assert_cmpuint (meta->alignment.padding_bottom, ==, 0);
3673 g_assert_cmpuint (meta->alignment.padding_left, ==, 0);
3674 g_assert_cmpuint (meta->alignment.padding_right, ==, 0);
3676 g_assert (gst_video_meta_get_plane_size (meta, plane_size));
3677 g_assert_cmpuint (plane_size[0], ==, 1920 * 1080);
3678 g_assert_cmpuint (plane_size[1], ==, 1920 * 1080 * 0.5);
3679 g_assert_cmpuint (plane_size[2], ==, 0);
3680 g_assert_cmpuint (plane_size[3], ==, 0);
3682 g_assert (gst_video_meta_get_plane_height (meta, plane_height));
3683 g_assert_cmpuint (plane_height[0], ==, 1080);
3684 g_assert_cmpuint (plane_height[1], ==, 540);
3685 g_assert_cmpuint (plane_height[2], ==, 0);
3686 g_assert_cmpuint (plane_height[3], ==, 0);
3688 /* horizontal alignment */
3689 gst_video_info_init (&info);
3690 gst_video_info_set_format (&info, GST_VIDEO_FORMAT_NV12, 1920, 1080);
3692 gst_video_alignment_reset (&alig);
3693 alig.padding_left = 2;
3694 alig.padding_right = 6;
3696 g_assert (gst_video_info_align (&info, &alig));
3698 meta = gst_buffer_add_video_meta_full (buf, GST_VIDEO_FRAME_FLAG_NONE,
3699 GST_VIDEO_INFO_FORMAT (&info), GST_VIDEO_INFO_WIDTH (&info),
3700 GST_VIDEO_INFO_HEIGHT (&info), GST_VIDEO_INFO_N_PLANES (&info),
3701 info.offset, info.stride);
3702 g_assert (gst_video_meta_set_alignment (meta, alig));
3704 g_assert_cmpuint (meta->alignment.padding_top, ==, 0);
3705 g_assert_cmpuint (meta->alignment.padding_bottom, ==, 0);
3706 g_assert_cmpuint (meta->alignment.padding_left, ==, 2);
3707 g_assert_cmpuint (meta->alignment.padding_right, ==, 6);
3709 g_assert (gst_video_meta_get_plane_size (meta, plane_size));
3710 g_assert_cmpuint (plane_size[0], ==, 1928 * 1080);
3711 g_assert_cmpuint (plane_size[1], ==, 1928 * 1080 * 0.5);
3712 g_assert_cmpuint (plane_size[2], ==, 0);
3713 g_assert_cmpuint (plane_size[3], ==, 0);
3715 g_assert (gst_video_meta_get_plane_height (meta, plane_height));
3716 g_assert_cmpuint (plane_height[0], ==, 1080);
3717 g_assert_cmpuint (plane_height[1], ==, 540);
3718 g_assert_cmpuint (plane_height[2], ==, 0);
3719 g_assert_cmpuint (plane_height[3], ==, 0);
3721 /* vertical alignment */
3722 gst_video_info_init (&info);
3723 gst_video_info_set_format (&info, GST_VIDEO_FORMAT_NV12, 1920, 1080);
3725 gst_video_alignment_reset (&alig);
3726 alig.padding_top = 2;
3727 alig.padding_bottom = 6;
3729 g_assert (gst_video_info_align (&info, &alig));
3731 meta = gst_buffer_add_video_meta_full (buf, GST_VIDEO_FRAME_FLAG_NONE,
3732 GST_VIDEO_INFO_FORMAT (&info), GST_VIDEO_INFO_WIDTH (&info),
3733 GST_VIDEO_INFO_HEIGHT (&info), GST_VIDEO_INFO_N_PLANES (&info),
3734 info.offset, info.stride);
3735 g_assert (gst_video_meta_set_alignment (meta, alig));
3737 g_assert_cmpuint (meta->alignment.padding_top, ==, 2);
3738 g_assert_cmpuint (meta->alignment.padding_bottom, ==, 6);
3739 g_assert_cmpuint (meta->alignment.padding_left, ==, 0);
3740 g_assert_cmpuint (meta->alignment.padding_right, ==, 0);
3742 g_assert (gst_video_meta_get_plane_size (meta, plane_size));
3743 g_assert_cmpuint (plane_size[0], ==, 1920 * 1088);
3744 g_assert_cmpuint (plane_size[1], ==, 1920 * 1088 * 0.5);
3745 g_assert_cmpuint (plane_size[2], ==, 0);
3746 g_assert_cmpuint (plane_size[3], ==, 0);
3748 g_assert (gst_video_meta_get_plane_height (meta, plane_height));
3749 g_assert_cmpuint (plane_height[0], ==, 1088);
3750 g_assert_cmpuint (plane_height[1], ==, 544);
3751 g_assert_cmpuint (plane_height[2], ==, 0);
3752 g_assert_cmpuint (plane_height[3], ==, 0);
3754 /* incompatible alignment */
3755 gst_video_info_init (&info);
3756 gst_video_info_set_format (&info, GST_VIDEO_FORMAT_NV12, 1920, 1080);
3758 gst_video_alignment_reset (&alig);
3759 alig.padding_right = 2;
3761 meta = gst_buffer_add_video_meta_full (buf, GST_VIDEO_FRAME_FLAG_NONE,
3762 GST_VIDEO_INFO_FORMAT (&info), GST_VIDEO_INFO_WIDTH (&info),
3763 GST_VIDEO_INFO_HEIGHT (&info), GST_VIDEO_INFO_N_PLANES (&info),
3764 info.offset, info.stride);
3765 g_assert (!gst_video_meta_set_alignment (meta, alig));
3767 gst_buffer_unref (buf);
3772 GST_START_TEST (test_video_flags)
3776 GstVideoFrame frame;
3778 gst_video_info_init (&info);
3779 fail_unless (gst_video_info_set_interlaced_format (&info,
3780 GST_VIDEO_FORMAT_RGB, GST_VIDEO_INTERLACE_MODE_ALTERNATE, 4, 4));
3782 buf = gst_buffer_new_and_alloc (GST_VIDEO_INFO_SIZE (&info));
3783 fail_unless (!GST_VIDEO_BUFFER_IS_TOP_FIELD (buf));
3784 fail_unless (!GST_VIDEO_BUFFER_IS_BOTTOM_FIELD (buf));
3785 fail_unless (gst_video_frame_map (&frame, &info, buf, GST_MAP_READ));
3786 fail_unless (!GST_VIDEO_FRAME_IS_TOP_FIELD (&frame));
3787 fail_unless (!GST_VIDEO_FRAME_IS_BOTTOM_FIELD (&frame));
3788 gst_video_frame_unmap (&frame);
3789 gst_buffer_unref (buf);
3791 buf = gst_buffer_new_and_alloc (GST_VIDEO_INFO_SIZE (&info));
3792 GST_BUFFER_FLAG_SET (buf, GST_VIDEO_BUFFER_FLAG_TOP_FIELD);
3793 fail_unless (GST_VIDEO_BUFFER_IS_TOP_FIELD (buf));
3794 fail_unless (!GST_VIDEO_BUFFER_IS_BOTTOM_FIELD (buf));
3795 fail_unless (gst_video_frame_map (&frame, &info, buf, GST_MAP_READ));
3796 fail_unless (GST_VIDEO_FRAME_IS_TOP_FIELD (&frame));
3797 fail_unless (!GST_VIDEO_FRAME_IS_BOTTOM_FIELD (&frame));
3798 gst_video_frame_unmap (&frame);
3799 gst_buffer_unref (buf);
3801 buf = gst_buffer_new_and_alloc (GST_VIDEO_INFO_SIZE (&info));
3802 GST_BUFFER_FLAG_SET (buf, GST_VIDEO_BUFFER_FLAG_BOTTOM_FIELD);
3803 fail_unless (!GST_VIDEO_BUFFER_IS_TOP_FIELD (buf));
3804 fail_unless (GST_VIDEO_BUFFER_IS_BOTTOM_FIELD (buf));
3805 fail_unless (gst_video_frame_map (&frame, &info, buf, GST_MAP_READ));
3806 fail_unless (!GST_VIDEO_FRAME_IS_TOP_FIELD (&frame));
3807 fail_unless (GST_VIDEO_FRAME_IS_BOTTOM_FIELD (&frame));
3808 gst_video_frame_unmap (&frame);
3809 gst_buffer_unref (buf);
3814 GST_START_TEST (test_video_make_raw_caps)
3816 GstCaps *caps, *expected;
3817 GstVideoFormat f1[] = { GST_VIDEO_FORMAT_NV12 };
3818 GstVideoFormat f2[] = { GST_VIDEO_FORMAT_NV12, GST_VIDEO_FORMAT_NV16 };
3820 caps = gst_video_make_raw_caps (f1, G_N_ELEMENTS (f1));
3821 expected = gst_caps_from_string (GST_VIDEO_CAPS_MAKE ("NV12"));
3822 fail_unless (gst_caps_is_equal (caps, expected));
3823 gst_caps_unref (caps);
3824 gst_caps_unref (expected);
3826 caps = gst_video_make_raw_caps (f2, G_N_ELEMENTS (f2));
3827 expected = gst_caps_from_string (GST_VIDEO_CAPS_MAKE ("{ NV12, NV16 }"));
3828 fail_unless (gst_caps_is_equal (caps, expected));
3829 gst_caps_unref (caps);
3830 gst_caps_unref (expected);
3832 caps = gst_video_make_raw_caps (NULL, 0);
3833 expected = gst_caps_from_string (GST_VIDEO_CAPS_MAKE (GST_VIDEO_FORMATS_ALL));
3834 fail_unless (gst_caps_is_equal (caps, expected));
3835 gst_caps_unref (caps);
3836 gst_caps_unref (expected);
3839 gst_video_make_raw_caps_with_features (NULL, 0,
3840 gst_caps_features_new_any ());
3842 gst_caps_from_string (GST_VIDEO_CAPS_MAKE_WITH_FEATURES ("ANY",
3843 GST_VIDEO_FORMATS_ALL));
3844 fail_unless (gst_caps_is_equal (caps, expected));
3845 gst_caps_unref (caps);
3846 gst_caps_unref (expected);
3854 Suite *s = suite_create ("video support library");
3855 TCase *tc_chain = tcase_create ("general");
3857 tcase_set_timeout (tc_chain, 60 * 60);
3859 suite_add_tcase (s, tc_chain);
3860 tcase_add_test (tc_chain, test_video_formats);
3861 tcase_add_test (tc_chain, test_video_formats_overflow);
3862 tcase_add_test (tc_chain, test_video_formats_rgb);
3863 tcase_add_test (tc_chain, test_video_formats_rgba_large_dimension);
3864 tcase_add_test (tc_chain, test_video_formats_all);
3865 tcase_add_test (tc_chain, test_video_formats_pack_unpack);
3866 tcase_add_test (tc_chain, test_guess_framerate);
3867 tcase_add_test (tc_chain, test_dar_calc);
3868 tcase_add_test (tc_chain, test_parse_caps_rgb);
3869 tcase_add_test (tc_chain, test_parse_caps_multiview);
3870 tcase_add_test (tc_chain, test_parse_colorimetry);
3871 tcase_add_test (tc_chain, test_events);
3872 tcase_add_test (tc_chain, test_convert_frame);
3873 tcase_add_test (tc_chain, test_convert_frame_async);
3874 tcase_add_test (tc_chain, test_convert_frame_async_error);
3875 tcase_add_test (tc_chain, test_video_size_from_caps);
3876 tcase_add_test (tc_chain, test_interlace_mode);
3877 tcase_add_test (tc_chain, test_overlay_composition);
3878 tcase_add_test (tc_chain, test_overlay_composition_premultiplied_alpha);
3879 tcase_add_test (tc_chain, test_overlay_composition_global_alpha);
3880 tcase_add_test (tc_chain, test_video_pack_unpack2);
3881 tcase_add_test (tc_chain, test_video_chroma);
3882 tcase_add_test (tc_chain, test_video_scaler);
3883 tcase_add_test (tc_chain, test_video_color_convert_rgb_rgb);
3884 tcase_add_test (tc_chain, test_video_color_convert_rgb_yuv);
3885 tcase_add_test (tc_chain, test_video_color_convert_yuv_yuv);
3886 tcase_add_test (tc_chain, test_video_color_convert_yuv_rgb);
3887 tcase_add_test (tc_chain, test_video_color_convert_other);
3888 tcase_add_test (tc_chain, test_video_size_convert);
3889 tcase_add_test (tc_chain, test_video_convert);
3890 tcase_add_test (tc_chain, test_video_transfer);
3891 tcase_add_test (tc_chain, test_overlay_blend);
3892 tcase_add_test (tc_chain, test_video_center_rect);
3893 tcase_add_test (tc_chain, test_overlay_composition_over_transparency);
3894 tcase_add_test (tc_chain, test_video_format_enum_stability);
3895 tcase_add_test (tc_chain, test_video_formats_pstrides);
3896 tcase_add_test (tc_chain, test_hdr);
3897 tcase_add_test (tc_chain, test_video_color_from_to_iso);
3898 tcase_add_test (tc_chain, test_video_format_info_plane_to_components);
3899 tcase_add_test (tc_chain, test_video_info_align);
3900 tcase_add_test (tc_chain, test_video_meta_align);
3901 tcase_add_test (tc_chain, test_video_flags);
3902 tcase_add_test (tc_chain, test_video_make_raw_caps);
3907 GST_CHECK_MAIN (video);