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);
2404 GstVideoChromaSite site;
2407 GST_START_TEST (test_video_chroma_site)
2409 ChromaSiteElem valid_sites[] = {
2410 /* pre-defined flags */
2411 {"jpeg", GST_VIDEO_CHROMA_SITE_JPEG},
2412 {"mpeg2", GST_VIDEO_CHROMA_SITE_MPEG2},
2413 {"dv", GST_VIDEO_CHROMA_SITE_DV},
2414 {"alt-line", GST_VIDEO_CHROMA_SITE_ALT_LINE},
2415 {"cosited", GST_VIDEO_CHROMA_SITE_COSITED},
2417 {"v-cosited", GST_VIDEO_CHROMA_SITE_V_COSITED},
2418 {"v-cosited+alt-line",
2419 GST_VIDEO_CHROMA_SITE_V_COSITED | GST_VIDEO_CHROMA_SITE_ALT_LINE},
2421 ChromaSiteElem unknown_sites[] = {
2422 {NULL, GST_VIDEO_CHROMA_SITE_UNKNOWN},
2423 /* Any combination with GST_VIDEO_CHROMA_SITE_NONE doesn' make sense */
2424 {NULL, GST_VIDEO_CHROMA_SITE_NONE | GST_VIDEO_CHROMA_SITE_H_COSITED},
2428 for (i = 0; i < G_N_ELEMENTS (valid_sites); i++) {
2429 gchar *site = gst_video_chroma_site_to_string (valid_sites[i].site);
2431 fail_unless (site != NULL);
2432 fail_unless (g_strcmp0 (site, valid_sites[i].name) == 0);
2433 fail_unless (gst_video_chroma_site_from_string (site) ==
2434 valid_sites[i].site);
2438 for (i = 0; i < G_N_ELEMENTS (unknown_sites); i++) {
2439 gchar *site = gst_video_chroma_site_to_string (unknown_sites[i].site);
2440 fail_unless (site == NULL);
2443 /* totally wrong string */
2444 fail_unless (gst_video_chroma_site_from_string ("foo/bar") ==
2445 GST_VIDEO_CHROMA_SITE_UNKNOWN);
2448 fail_unless (gst_video_chroma_site_from_string ("jpeg") ==
2449 GST_VIDEO_CHROMA_SITE_NONE);
2450 fail_unless (gst_video_chroma_site_from_string ("none") ==
2451 GST_VIDEO_CHROMA_SITE_NONE);
2453 fail_unless (gst_video_chroma_site_from_string ("mpeg2") ==
2454 GST_VIDEO_CHROMA_SITE_H_COSITED);
2455 fail_unless (gst_video_chroma_site_from_string ("h-cosited") ==
2456 GST_VIDEO_CHROMA_SITE_H_COSITED);
2458 /* Equal to "cosited" */
2459 fail_unless (gst_video_chroma_site_from_string ("v-cosited+h-cosited") ==
2460 GST_VIDEO_CHROMA_SITE_COSITED);
2462 fail_unless (gst_video_chroma_site_from_string ("v-cosited") ==
2463 GST_VIDEO_CHROMA_SITE_V_COSITED);
2465 /* none + something doesn't make sense */
2466 fail_unless (gst_video_chroma_site_from_string ("none+v-cosited") ==
2467 GST_VIDEO_CHROMA_SITE_UNKNOWN);
2469 /* mix of valid and invalid strings */
2470 fail_unless (gst_video_chroma_site_from_string ("mpeg2+foo/bar") ==
2471 GST_VIDEO_CHROMA_SITE_UNKNOWN);
2476 GST_START_TEST (test_video_scaler)
2478 GstVideoScaler *scale;
2480 scale = gst_video_scaler_new (GST_VIDEO_RESAMPLER_METHOD_LINEAR,
2481 GST_VIDEO_SCALER_FLAG_NONE, 2, 10, 5, NULL);
2482 gst_video_scaler_free (scale);
2484 scale = gst_video_scaler_new (GST_VIDEO_RESAMPLER_METHOD_LINEAR,
2485 GST_VIDEO_SCALER_FLAG_NONE, 2, 15, 5, NULL);
2486 gst_video_scaler_free (scale);
2502 check_video_format_is_type (GstVideoFormat fmt, ColorType fmt_type)
2504 const GstVideoFormatInfo *info = gst_video_format_get_info (fmt);
2505 gboolean is_rgb = GST_VIDEO_FORMAT_INFO_IS_RGB (info);
2506 gboolean is_yuv = GST_VIDEO_FORMAT_INFO_IS_YUV (info);
2516 return !is_rgb && !is_yuv;
2520 run_video_color_convert (ColorType in_type, ColorType out_type)
2522 GstVideoFormat infmt, outfmt;
2525 num_formats = get_num_formats ();
2527 for (infmt = GST_VIDEO_FORMAT_I420; infmt < num_formats; infmt++) {
2528 GstVideoInfo ininfo;
2529 GstVideoFrame inframe;
2530 GstBuffer *inbuffer;
2532 if (!check_video_format_is_type (infmt, in_type))
2535 fail_unless (gst_video_info_set_format (&ininfo, infmt, WIDTH, HEIGHT));
2536 inbuffer = gst_buffer_new_and_alloc (ininfo.size);
2537 gst_buffer_memset (inbuffer, 0, 0, -1);
2538 gst_video_frame_map (&inframe, &ininfo, inbuffer, GST_MAP_READ);
2540 for (outfmt = GST_VIDEO_FORMAT_I420; outfmt < num_formats; outfmt++) {
2541 GstVideoInfo outinfo;
2542 GstVideoFrame outframe;
2543 GstBuffer *outbuffer;
2544 GstVideoConverter *convert;
2546 if (!check_video_format_is_type (outfmt, out_type))
2549 GST_LOG ("%s -> %s @ %ux%u", gst_video_format_to_string (infmt),
2550 gst_video_format_to_string (outfmt), WIDTH, HEIGHT);
2552 fail_unless (gst_video_info_set_format (&outinfo, outfmt, WIDTH, HEIGHT));
2553 outbuffer = gst_buffer_new_and_alloc (outinfo.size);
2554 gst_video_frame_map (&outframe, &outinfo, outbuffer, GST_MAP_WRITE);
2556 convert = gst_video_converter_new (&ininfo, &outinfo, NULL);
2558 gst_video_converter_frame (convert, &inframe, &outframe);
2560 gst_video_converter_free (convert);
2562 gst_video_frame_unmap (&outframe);
2563 gst_buffer_unref (outbuffer);
2565 gst_video_frame_unmap (&inframe);
2566 gst_buffer_unref (inbuffer);
2570 GST_START_TEST (test_video_color_convert_rgb_rgb)
2572 run_video_color_convert (RGB, RGB);
2577 GST_START_TEST (test_video_color_convert_rgb_yuv)
2579 run_video_color_convert (RGB, YUV);
2584 GST_START_TEST (test_video_color_convert_yuv_yuv)
2586 run_video_color_convert (YUV, YUV);
2591 GST_START_TEST (test_video_color_convert_yuv_rgb)
2593 run_video_color_convert (YUV, RGB);
2598 GST_START_TEST (test_video_color_convert_other)
2600 run_video_color_convert (OTHER, RGB);
2601 run_video_color_convert (RGB, OTHER);
2602 run_video_color_convert (OTHER, YUV);
2603 run_video_color_convert (YUV, OTHER);
2604 run_video_color_convert (OTHER, OTHER);
2611 #define WIDTH_IN 320
2612 #define HEIGHT_IN 240
2613 #define WIDTH_OUT 400
2614 #define HEIGHT_OUT 300
2617 GST_START_TEST (test_video_size_convert)
2619 GstVideoFormat infmt, outfmt;
2621 gint num_formats, i;
2624 array = g_array_new (FALSE, FALSE, sizeof (ConvertResult));
2626 timer = g_timer_new ();
2628 num_formats = get_num_formats ();
2630 for (infmt = GST_VIDEO_FORMAT_I420; infmt < num_formats; infmt++) {
2631 GstVideoInfo ininfo, outinfo;
2632 GstVideoFrame inframe, outframe;
2633 GstBuffer *inbuffer, *outbuffer;
2634 GstVideoConverter *convert;
2639 fail_unless (gst_video_info_set_format (&ininfo, infmt, WIDTH_IN,
2641 inbuffer = gst_buffer_new_and_alloc (ininfo.size);
2642 gst_buffer_memset (inbuffer, 0, 0, -1);
2643 gst_video_frame_map (&inframe, &ininfo, inbuffer, GST_MAP_READ);
2646 fail_unless (gst_video_info_set_format (&outinfo, outfmt, WIDTH_OUT,
2648 outbuffer = gst_buffer_new_and_alloc (outinfo.size);
2649 gst_video_frame_map (&outframe, &outinfo, outbuffer, GST_MAP_WRITE);
2651 for (method = 0; method < 4; method++) {
2652 convert = gst_video_converter_new (&ininfo, &outinfo,
2653 gst_structure_new ("options",
2654 GST_VIDEO_CONVERTER_OPT_RESAMPLER_METHOD,
2655 GST_TYPE_VIDEO_RESAMPLER_METHOD, method, NULL));
2658 gst_video_converter_frame (convert, &inframe, &outframe);
2661 g_timer_start (timer);
2663 gst_video_converter_frame (convert, &inframe, &outframe);
2666 elapsed = g_timer_elapsed (timer, NULL);
2667 if (elapsed >= TIME)
2672 res.outfmt = outfmt;
2673 res.method = method;
2674 res.convert_sec = count / elapsed;
2676 GST_DEBUG ("%f resize/sec %s->%s, %d, %d/%f", res.convert_sec,
2677 gst_video_format_to_string (infmt),
2678 gst_video_format_to_string (outfmt), method, count, elapsed);
2680 g_array_append_val (array, res);
2682 gst_video_converter_free (convert);
2684 gst_video_frame_unmap (&outframe);
2685 gst_buffer_unref (outbuffer);
2686 gst_video_frame_unmap (&inframe);
2687 gst_buffer_unref (inbuffer);
2690 g_array_sort (array, compare_result);
2692 for (i = 0; i < array->len; i++) {
2693 ConvertResult *res = &g_array_index (array, ConvertResult, i);
2695 GST_DEBUG ("%f method %d, resize/sec %s->%s", res->convert_sec, res->method,
2696 gst_video_format_to_string (res->infmt),
2697 gst_video_format_to_string (res->outfmt));
2700 g_array_free (array, TRUE);
2702 g_timer_destroy (timer);
2709 GST_START_TEST (test_video_convert)
2711 GstVideoInfo ininfo, outinfo;
2712 GstVideoFrame inframe, outframe;
2713 GstBuffer *inbuffer, *outbuffer;
2714 GstVideoConverter *convert;
2716 fail_unless (gst_video_info_set_format (&ininfo, GST_VIDEO_FORMAT_ARGB, 320,
2718 inbuffer = gst_buffer_new_and_alloc (ininfo.size);
2719 gst_buffer_memset (inbuffer, 0, 0, -1);
2720 gst_video_frame_map (&inframe, &ininfo, inbuffer, GST_MAP_READ);
2722 fail_unless (gst_video_info_set_format (&outinfo, GST_VIDEO_FORMAT_BGRx, 400,
2724 outbuffer = gst_buffer_new_and_alloc (outinfo.size);
2725 gst_video_frame_map (&outframe, &outinfo, outbuffer, GST_MAP_WRITE);
2727 /* see that we don't reuse the source line directly because we need
2728 * to add borders to it */
2729 convert = gst_video_converter_new (&ininfo, &outinfo,
2730 gst_structure_new ("options",
2731 GST_VIDEO_CONVERTER_OPT_RESAMPLER_METHOD,
2732 GST_TYPE_VIDEO_RESAMPLER_METHOD, 3,
2733 GST_VIDEO_CONVERTER_OPT_SRC_X, G_TYPE_INT, 10,
2734 GST_VIDEO_CONVERTER_OPT_SRC_Y, G_TYPE_INT, 0,
2735 GST_VIDEO_CONVERTER_OPT_SRC_WIDTH, G_TYPE_INT, 300,
2736 GST_VIDEO_CONVERTER_OPT_SRC_HEIGHT, G_TYPE_INT, 220,
2737 GST_VIDEO_CONVERTER_OPT_DEST_X, G_TYPE_INT, 80,
2738 GST_VIDEO_CONVERTER_OPT_DEST_Y, G_TYPE_INT, 60,
2739 GST_VIDEO_CONVERTER_OPT_DEST_WIDTH, G_TYPE_INT, 300,
2740 GST_VIDEO_CONVERTER_OPT_DEST_HEIGHT, G_TYPE_INT, 220, NULL));
2742 gst_video_converter_frame (convert, &inframe, &outframe);
2743 gst_video_converter_free (convert);
2745 /* see that we reuse the source line directly because we need to scale
2747 convert = gst_video_converter_new (&ininfo, &outinfo,
2748 gst_structure_new ("options",
2749 GST_VIDEO_CONVERTER_OPT_RESAMPLER_METHOD,
2750 GST_TYPE_VIDEO_RESAMPLER_METHOD, 3,
2751 GST_VIDEO_CONVERTER_OPT_SRC_X, G_TYPE_INT, 10,
2752 GST_VIDEO_CONVERTER_OPT_SRC_Y, G_TYPE_INT, 0,
2753 GST_VIDEO_CONVERTER_OPT_SRC_WIDTH, G_TYPE_INT, 300,
2754 GST_VIDEO_CONVERTER_OPT_SRC_HEIGHT, G_TYPE_INT, 220,
2755 GST_VIDEO_CONVERTER_OPT_DEST_X, G_TYPE_INT, 80,
2756 GST_VIDEO_CONVERTER_OPT_DEST_Y, G_TYPE_INT, 60,
2757 GST_VIDEO_CONVERTER_OPT_DEST_WIDTH, G_TYPE_INT, 310,
2758 GST_VIDEO_CONVERTER_OPT_DEST_HEIGHT, G_TYPE_INT, 230, NULL));
2760 gst_video_converter_frame (convert, &inframe, &outframe);
2762 /* Check that video convert doesn't crash if we give it frames with different info
2763 * than we configured it with by swapping width/height */
2764 gst_video_frame_unmap (&inframe);
2765 fail_unless (gst_video_info_set_format (&ininfo, GST_VIDEO_FORMAT_ARGB, 240,
2767 gst_video_frame_map (&inframe, &ininfo, inbuffer, GST_MAP_READ);
2768 ASSERT_CRITICAL (gst_video_converter_frame (convert, &inframe, &outframe));
2769 gst_video_converter_free (convert);
2771 /* Make sure we can crop the entire frame away without dying */
2772 convert = gst_video_converter_new (&ininfo, &outinfo,
2773 gst_structure_new ("options",
2774 GST_VIDEO_CONVERTER_OPT_RESAMPLER_METHOD,
2775 GST_TYPE_VIDEO_RESAMPLER_METHOD, 3,
2776 GST_VIDEO_CONVERTER_OPT_SRC_X, G_TYPE_INT, -500,
2777 GST_VIDEO_CONVERTER_OPT_SRC_Y, G_TYPE_INT, -500,
2778 GST_VIDEO_CONVERTER_OPT_SRC_WIDTH, G_TYPE_INT, 300,
2779 GST_VIDEO_CONVERTER_OPT_SRC_HEIGHT, G_TYPE_INT, 220,
2780 GST_VIDEO_CONVERTER_OPT_DEST_X, G_TYPE_INT, 800,
2781 GST_VIDEO_CONVERTER_OPT_DEST_Y, G_TYPE_INT, 600,
2782 GST_VIDEO_CONVERTER_OPT_DEST_WIDTH, G_TYPE_INT, 310,
2783 GST_VIDEO_CONVERTER_OPT_DEST_HEIGHT, G_TYPE_INT, 230, NULL));
2785 gst_video_converter_frame (convert, &inframe, &outframe);
2786 gst_video_converter_free (convert);
2788 gst_video_frame_unmap (&outframe);
2789 gst_buffer_unref (outbuffer);
2790 gst_video_frame_unmap (&inframe);
2791 gst_buffer_unref (inbuffer);
2797 GST_START_TEST (test_video_convert_multithreading)
2799 GstVideoInfo ininfo, outinfo;
2800 GstVideoFrame inframe, outframe, refframe;
2801 GstBuffer *inbuffer, *outbuffer, *refbuffer;
2802 GstVideoConverter *convert;
2806 /* Large enough input resolution for video-converter to actually use
2807 * 4 threads if required */
2808 fail_unless (gst_video_info_set_format (&ininfo, GST_VIDEO_FORMAT_ARGB, 1280,
2810 inbuffer = gst_buffer_new_and_alloc (ininfo.size);
2811 gst_buffer_memset (inbuffer, 0, 0, -1);
2812 gst_video_frame_map (&inframe, &ininfo, inbuffer, GST_MAP_READ);
2814 fail_unless (gst_video_info_set_format (&outinfo, GST_VIDEO_FORMAT_BGRx, 400,
2816 outbuffer = gst_buffer_new_and_alloc (outinfo.size);
2817 refbuffer = gst_buffer_new_and_alloc (outinfo.size);
2819 gst_video_frame_map (&outframe, &outinfo, outbuffer, GST_MAP_WRITE);
2820 gst_video_frame_map (&refframe, &outinfo, refbuffer, GST_MAP_WRITE);
2822 /* Single threaded-conversion */
2823 convert = gst_video_converter_new (&ininfo, &outinfo,
2824 gst_structure_new_empty ("options"));
2825 gst_video_converter_frame (convert, &inframe, &refframe);
2826 gst_video_converter_free (convert);
2828 /* Multithreaded conversion, converter creates pool */
2829 convert = gst_video_converter_new (&ininfo, &outinfo,
2830 gst_structure_new ("options",
2831 GST_VIDEO_CONVERTER_OPT_THREADS, G_TYPE_UINT, 4, NULL)
2833 gst_video_converter_frame (convert, &inframe, &outframe);
2834 gst_video_converter_free (convert);
2836 gst_video_frame_unmap (&outframe);
2837 gst_video_frame_unmap (&refframe);
2839 gst_buffer_map (outbuffer, &info, GST_MAP_READ);
2840 fail_unless (gst_buffer_memcmp (refbuffer, 0, info.data, info.size) == 0);
2841 gst_buffer_unmap (outbuffer, &info);
2843 gst_video_frame_map (&outframe, &outinfo, outbuffer, GST_MAP_WRITE);
2844 gst_video_frame_map (&refframe, &outinfo, refbuffer, GST_MAP_WRITE);
2846 /* Multi-threaded conversion, user-provided pool */
2847 pool = gst_shared_task_pool_new ();
2848 gst_shared_task_pool_set_max_threads (GST_SHARED_TASK_POOL (pool), 4);
2849 gst_task_pool_prepare (pool, NULL);
2850 convert = gst_video_converter_new_with_pool (&ininfo, &outinfo,
2851 gst_structure_new ("options",
2852 GST_VIDEO_CONVERTER_OPT_THREADS, G_TYPE_UINT, 4, NULL), pool);
2853 gst_video_converter_frame (convert, &inframe, &outframe);
2854 gst_video_converter_free (convert);
2855 gst_task_pool_cleanup (pool);
2856 gst_object_unref (pool);
2858 gst_video_frame_unmap (&outframe);
2859 gst_video_frame_unmap (&refframe);
2861 gst_buffer_map (outbuffer, &info, GST_MAP_READ);
2862 fail_unless (gst_buffer_memcmp (refbuffer, 0, info.data, info.size) == 0);
2863 gst_buffer_unmap (outbuffer, &info);
2866 gst_buffer_unref (refbuffer);
2867 gst_buffer_unref (outbuffer);
2868 gst_video_frame_unmap (&inframe);
2869 gst_buffer_unref (inbuffer);
2875 GST_START_TEST (test_video_transfer)
2879 for (j = GST_VIDEO_TRANSFER_GAMMA10; j <= GST_VIDEO_TRANSFER_ARIB_STD_B67;
2881 for (i = 0; i < 256; i++) {
2884 val1 = gst_video_transfer_function_encode (j, i / 255.0);
2885 fail_if (val1 < 0.0 || val1 > 1.0);
2887 val2 = gst_video_transfer_function_decode (j, val1);
2888 fail_if (val2 < 0.0 || val2 > 1.0);
2890 GST_DEBUG ("%d: %d %f->%f->%f %d", j, i, i / 255.0, val1, val2,
2891 (int) lrint (val2 * 255.0));
2893 fail_if (val2 != 0.0);
2895 fail_if (lrint (val2 * 255.0) != i);
2902 GST_START_TEST (test_video_center_rect)
2904 GstVideoRectangle src, dest, result, expected;
2906 #define NEW_RECT(x,y,w,h) ((GstVideoRectangle) {x,y,w,h})
2907 #define CHECK_RECT(res, exp) \
2908 fail_unless_equals_int(exp.x, res.x);\
2909 fail_unless_equals_int(exp.y, res.y);\
2910 fail_unless_equals_int(exp.w, res.w);\
2911 fail_unless_equals_int(exp.h, res.h);
2913 /* 1:1 Aspect Ratio */
2914 src = NEW_RECT (0, 0, 100, 100);
2915 dest = NEW_RECT (0, 0, 100, 100);
2916 expected = NEW_RECT (0, 0, 100, 100);
2917 gst_video_sink_center_rect (src, dest, &result, TRUE);
2918 CHECK_RECT (result, expected);
2920 src = NEW_RECT (0, 0, 100, 100);
2921 dest = NEW_RECT (0, 0, 50, 50);
2922 expected = NEW_RECT (0, 0, 50, 50);
2923 gst_video_sink_center_rect (src, dest, &result, TRUE);
2924 CHECK_RECT (result, expected);
2926 src = NEW_RECT (0, 0, 100, 100);
2927 dest = NEW_RECT (50, 50, 100, 100);
2928 expected = NEW_RECT (50, 50, 100, 100);
2929 gst_video_sink_center_rect (src, dest, &result, TRUE);
2930 CHECK_RECT (result, expected);
2932 /* Aspect ratio scaling (tall) */
2933 src = NEW_RECT (0, 0, 50, 100);
2934 dest = NEW_RECT (0, 0, 50, 50);
2935 expected = NEW_RECT (12, 0, 25, 50);
2936 gst_video_sink_center_rect (src, dest, &result, TRUE);
2937 CHECK_RECT (result, expected);
2939 src = NEW_RECT (0, 0, 50, 100);
2940 dest = NEW_RECT (50, 50, 50, 50);
2941 expected = NEW_RECT (62, 50, 25, 50);
2942 gst_video_sink_center_rect (src, dest, &result, TRUE);
2943 CHECK_RECT (result, expected);
2945 /* Aspect ratio scaling (wide) */
2946 src = NEW_RECT (0, 0, 100, 50);
2947 dest = NEW_RECT (0, 0, 50, 50);
2948 expected = NEW_RECT (0, 12, 50, 25);
2949 gst_video_sink_center_rect (src, dest, &result, TRUE);
2950 CHECK_RECT (result, expected);
2952 src = NEW_RECT (0, 0, 100, 50);
2953 dest = NEW_RECT (50, 50, 50, 50);
2954 expected = NEW_RECT (50, 62, 50, 25);
2955 gst_video_sink_center_rect (src, dest, &result, TRUE);
2956 CHECK_RECT (result, expected);
2961 void test_overlay_blend_rect (gint x, gint y, gint width, gint height,
2962 GstVideoFrame * video_frame);
2963 void test_overlay_blend_rect_verify (gint x, gint y, gint width,
2964 gint height, GstVideoFrame * video_frame);
2965 #define VIDEO_WIDTH 320
2966 #define VIDEO_HEIGHT 240
2969 test_overlay_blend_rect_verify (gint x, gint y, gint width, gint height,
2970 GstVideoFrame * video_frame)
2973 gint i = 0, prev_i = 0;
2975 gint temp_width = 0, temp_height = 0;
2977 data = GST_VIDEO_FRAME_PLANE_DATA (video_frame, 0);
2978 size = GST_VIDEO_FRAME_SIZE (video_frame);
2980 if (x + width < 0 || y + height < 0 || x >= VIDEO_WIDTH || y >= VIDEO_HEIGHT)
2983 temp_width = width + x;
2984 else if (x > 0 && (x + width) <= VIDEO_WIDTH)
2987 temp_width = VIDEO_WIDTH - x;
2989 temp_height = height + y;
2990 else if (y > 0 && (y + height) <= VIDEO_HEIGHT)
2991 temp_height = height;
2993 temp_height = VIDEO_HEIGHT - y;
2995 if (x <= 0 && y <= 0)
2998 i = (((x <= 0) ? 0 : x) + (((y <= 0) ? 0 : y) * VIDEO_WIDTH)) * 4;
3001 for (; i < size - 4; i += 4) {
3002 #if G_BYTE_ORDER == G_LITTLE_ENDIAN
3004 fail_unless_equals_int (data[i], 0x80);
3005 fail_unless_equals_int (data[i + 1], 0x80);
3006 fail_unless_equals_int (data[i + 2], 0x80);
3007 fail_unless_equals_int (data[i + 3], 0x80);
3010 fail_unless_equals_int (data[i], 0x80);
3011 fail_unless_equals_int (data[i + 1], 0x80);
3012 fail_unless_equals_int (data[i + 2], 0x80);
3013 fail_unless_equals_int (data[i + 3], 0x80);
3015 if ((i + 4) == (4 * (((((y > 0) ? (y + temp_height) : temp_height) -
3016 1) * VIDEO_WIDTH) + ((x >
3017 0) ? (x + temp_width) : temp_width))))
3019 if ((i + 4 - prev_i) == ((temp_width) * 4)) {
3020 i += ((VIDEO_WIDTH - (temp_width)) * 4);
3028 test_overlay_blend_rect (gint x, gint y, gint width, gint height,
3029 GstVideoFrame * video_frame)
3031 GstVideoOverlayComposition *comp1;
3032 GstVideoOverlayRectangle *rect1;
3033 GstBuffer *pix, *pix1;
3036 memset (video_frame, 0, sizeof (GstVideoFrame));
3038 gst_buffer_new_and_alloc (VIDEO_WIDTH * VIDEO_HEIGHT * sizeof (guint32));
3039 gst_buffer_memset (pix, 0, 0, gst_buffer_get_size (pix));
3040 gst_video_info_init (&vinfo);
3041 fail_unless (gst_video_info_set_format (&vinfo,
3042 GST_VIDEO_OVERLAY_COMPOSITION_FORMAT_RGB, VIDEO_WIDTH, VIDEO_HEIGHT));
3043 gst_video_frame_map (video_frame, &vinfo, pix, GST_MAP_READWRITE);
3044 gst_buffer_unref (pix);
3047 pix1 = gst_buffer_new_and_alloc (width * height * sizeof (guint32));
3048 gst_buffer_memset (pix1, 0, 0x80, gst_buffer_get_size (pix1));
3049 gst_buffer_add_video_meta (pix1, GST_VIDEO_FRAME_FLAG_NONE,
3050 GST_VIDEO_OVERLAY_COMPOSITION_FORMAT_RGB, width, height);
3051 rect1 = gst_video_overlay_rectangle_new_raw (pix1,
3052 x, y, width, height, GST_VIDEO_OVERLAY_FORMAT_FLAG_NONE);
3053 gst_buffer_unref (pix1);
3056 comp1 = gst_video_overlay_composition_new (rect1);
3057 fail_unless (gst_video_overlay_composition_blend (comp1, video_frame));
3058 gst_video_overlay_composition_unref (comp1);
3059 gst_video_overlay_rectangle_unref (rect1);
3061 test_overlay_blend_rect_verify (x, y, width, height, video_frame);
3062 gst_video_frame_unmap (video_frame);
3065 GST_START_TEST (test_overlay_blend)
3067 GstVideoFrame video_frame;
3069 /* Overlay width & height smaller than video width & height */
3070 /* Overlay rendered completely left of video surface
3071 * x + overlay_width <= 0 */
3072 test_overlay_blend_rect (-60, 50, 50, 50, &video_frame);
3073 /* Overlay rendered completely right of video surface
3074 * x >= video_width */
3075 test_overlay_blend_rect (330, 50, 50, 50, &video_frame);
3076 /* Overlay rendered completely top of video surface
3077 * y + overlay_height <= 0 */
3078 test_overlay_blend_rect (50, -60, 50, 50, &video_frame);
3079 /* Overlay rendered completely bottom of video surface
3080 * y >= video_height */
3081 test_overlay_blend_rect (50, 250, 50, 50, &video_frame);
3082 /* Overlay rendered partially left of video surface
3083 * x < 0 && -x < overlay_width */
3084 test_overlay_blend_rect (-40, 50, 50, 50, &video_frame);
3085 /* Overlay rendered partially right of video surface
3086 * x < video_width && (overlay_width + x) > video_width */
3087 test_overlay_blend_rect (300, 50, 50, 50, &video_frame);
3088 /* Overlay rendered partially top of video surface
3089 * y < 0 && -y < overlay_height */
3090 test_overlay_blend_rect (50, -40, 50, 50, &video_frame);
3091 /* Overlay rendered partially bottom of video surface
3092 * y < video_height && (overlay_height + y) > video_height */
3093 test_overlay_blend_rect (50, 220, 50, 50, &video_frame);
3095 /* Overlay width & height bigger than video width & height */
3096 /* Overlay rendered completely left of video surface
3097 * x + overlay_width <= 0 */
3098 test_overlay_blend_rect (-360, 50, 350, 250, &video_frame);
3099 /* Overlay rendered completely right of video surface
3100 * x >= video_width */
3101 test_overlay_blend_rect (330, 50, 350, 250, &video_frame);
3102 /* Overlay rendered completely top of video surface
3103 * y + overlay_height <= 0 */
3104 test_overlay_blend_rect (50, -260, 350, 250, &video_frame);
3105 /* Overlay rendered completely bottom of video surface
3106 * y >= video_height */
3107 test_overlay_blend_rect (50, 250, 350, 250, &video_frame);
3108 /* Overlay rendered partially left of video surface
3109 * x < 0 && -x < overlay_width */
3110 test_overlay_blend_rect (-40, 50, 350, 250, &video_frame);
3111 /* Overlay rendered partially right of video surface
3112 * x < video_width && (overlay_width + x) > video_width */
3113 test_overlay_blend_rect (300, 50, 350, 250, &video_frame);
3114 /* Overlay rendered partially top of video surface
3115 * y < 0 && -y < overlay_height */
3116 test_overlay_blend_rect (50, -40, 350, 250, &video_frame);
3117 /* Overlay rendered partially bottom of video surface
3118 * y < video_height && (overlay_height + y) > video_height */
3119 test_overlay_blend_rect (50, 220, 350, 250, &video_frame);
3124 GST_START_TEST (test_overlay_composition_over_transparency)
3126 GstVideoOverlayComposition *comp1;
3127 GstVideoOverlayRectangle *rect1;
3128 GstBuffer *pix1, *pix2;
3132 GstVideoFrame video_frame;
3133 guint fwidth = 200, height = 50, swidth = 100;
3135 memset (&video_frame, 0, sizeof (GstVideoFrame));
3137 pix1 = gst_buffer_new_and_alloc (fwidth * sizeof (guint32) * height);
3138 gst_buffer_memset (pix1, 0, 0x00, gst_buffer_get_size (pix1));
3139 gst_video_info_init (&vinfo);
3140 fail_unless (gst_video_info_set_format (&vinfo,
3141 GST_VIDEO_OVERLAY_COMPOSITION_FORMAT_RGB, fwidth, height));
3142 gst_video_frame_map (&video_frame, &vinfo, pix1, GST_MAP_READWRITE);
3143 gst_buffer_unref (pix1);
3145 pix2 = gst_buffer_new_and_alloc (swidth * sizeof (guint32) * height);
3146 gst_buffer_memset (pix2, 0, 0xFF, gst_buffer_get_size (pix2));
3147 gst_buffer_add_video_meta (pix2, GST_VIDEO_FRAME_FLAG_NONE,
3148 GST_VIDEO_OVERLAY_COMPOSITION_FORMAT_RGB, swidth, height);
3149 rect1 = gst_video_overlay_rectangle_new_raw (pix2, swidth, 0,
3150 swidth, height, GST_VIDEO_OVERLAY_FORMAT_FLAG_NONE);
3152 comp1 = gst_video_overlay_composition_new (rect1);
3153 fail_unless (gst_video_overlay_composition_blend (comp1, &video_frame));
3154 gst_video_overlay_composition_unref (comp1);
3155 gst_video_overlay_rectangle_unref (rect1);
3156 gst_buffer_unref (pix2);
3158 data = GST_VIDEO_FRAME_PLANE_DATA (&video_frame, 0);
3160 fail_unless_equals_int (data[0], 0x00);
3161 fail_unless_equals_int (data[1], 0x00);
3162 fail_unless_equals_int (data[2], 0x00);
3163 fail_unless_equals_int (data[3], 0x00);
3165 data += swidth * sizeof (guint32);
3167 fail_unless_equals_int (data[0], 0xFF);
3168 fail_unless_equals_int (data[1], 0xFF);
3169 fail_unless_equals_int (data[2], 0xFF);
3170 fail_unless_equals_int (data[3], 0xFF);
3172 gst_video_frame_unmap (&video_frame);
3177 GST_START_TEST (test_video_format_enum_stability)
3179 /* When adding new formats, adding a format in the middle of the enum will
3180 * break the API. This check picks the last known format and checks that
3181 * it's value isn't changing. This test should ideall be updated when a new
3182 * format is added, though will stay valid. */
3183 fail_unless_equals_int (GST_VIDEO_FORMAT_Y210, 82);
3188 GST_START_TEST (test_video_formats_pstrides)
3190 GstVideoFormat fmt = GST_VIDEO_FORMAT_I420;
3193 while ((gst_video_format_to_string (fmt) != NULL)) {
3194 const GstVideoFormatInfo *vf_info = gst_video_format_get_info (fmt);
3195 guint n_comps = GST_VIDEO_FORMAT_INFO_N_COMPONENTS (vf_info);
3197 GST_LOG ("format: %s (%d), n_comps = %u", vf_info->name, fmt, n_comps);
3199 if (fmt == GST_VIDEO_FORMAT_v210
3200 || fmt == GST_VIDEO_FORMAT_UYVP
3201 || fmt == GST_VIDEO_FORMAT_IYU1
3202 || fmt == GST_VIDEO_FORMAT_GRAY10_LE32
3203 || fmt == GST_VIDEO_FORMAT_NV12_64Z32
3204 || fmt == GST_VIDEO_FORMAT_NV12_4L4
3205 || fmt == GST_VIDEO_FORMAT_NV12_32L32
3206 || fmt == GST_VIDEO_FORMAT_NV12_10LE32
3207 || fmt == GST_VIDEO_FORMAT_NV16_10LE32
3208 || fmt == GST_VIDEO_FORMAT_NV12_10LE40
3209 || fmt == GST_VIDEO_FORMAT_Y410) {
3216 fail_unless (GST_VIDEO_FORMAT_INFO_PSTRIDE (vf_info, 3) > 0);
3219 fail_unless (GST_VIDEO_FORMAT_INFO_PSTRIDE (vf_info, 2) > 0);
3222 fail_unless (GST_VIDEO_FORMAT_INFO_PSTRIDE (vf_info, 1) > 0);
3225 fail_unless (GST_VIDEO_FORMAT_INFO_PSTRIDE (vf_info, 0) > 0);
3235 GST_START_TEST (test_hdr)
3238 GstCaps *other_caps;
3239 GstVideoMasteringDisplayInfo minfo;
3240 GstVideoMasteringDisplayInfo other_minfo;
3241 GstVideoMasteringDisplayInfo minfo_from_caps;
3242 GstVideoContentLightLevel level;
3243 GstVideoContentLightLevel other_level;
3244 GstVideoContentLightLevel level_from_caps;
3245 GstStructure *s = NULL;
3247 gchar *level_str = NULL;
3252 gst_video_mastering_display_info_init (&minfo);
3253 gst_video_mastering_display_info_init (&other_minfo);
3255 /* Test GstVideoMasteringDisplayInfo, initialize with random values
3256 * just for comparison */
3258 for (i = 0; i < G_N_ELEMENTS (minfo.display_primaries); i++) {
3259 minfo.display_primaries[i].x = val++;
3260 minfo.display_primaries[i].y = val++;
3262 minfo.white_point.x = val++;
3263 minfo.white_point.y = val++;
3264 minfo.max_display_mastering_luminance = val++;
3265 minfo.min_display_mastering_luminance = val++;
3267 caps = gst_caps_new_empty_simple ("video/x-raw");
3268 minfo_str = gst_video_mastering_display_info_to_string (&minfo);
3269 fail_unless (minfo_str != NULL, "cannot convert info to string");
3270 GST_DEBUG ("converted mastering info string %s", minfo_str);
3272 gst_caps_set_simple (caps, "mastering-display-info",
3273 G_TYPE_STRING, minfo_str, NULL);
3277 /* manually parsing mastering info from string */
3278 s = gst_caps_get_structure (caps, 0);
3279 minfo_str = (gchar *) gst_structure_get_string (s, "mastering-display-info");
3280 fail_unless (minfo_str != NULL);
3281 fail_unless (gst_video_mastering_display_info_from_string
3282 (&other_minfo, minfo_str), "cannot get mastering info from string");
3283 GST_DEBUG ("extracted info string %s", minfo_str);
3285 fail_unless (gst_video_mastering_display_info_is_equal (&minfo,
3286 &other_minfo), "Extracted mastering info is not equal to original");
3288 /* simplified version for caps use case */
3289 fail_unless (gst_video_mastering_display_info_from_caps (&minfo_from_caps,
3290 caps), "cannot parse mastering info from caps");
3291 fail_unless (gst_video_mastering_display_info_is_equal (&minfo,
3293 "Extracted mastering info is not equal to original");
3295 /* check _add_to_caps () and manually created one */
3296 other_caps = gst_caps_new_empty_simple ("video/x-raw");
3297 fail_unless (gst_video_mastering_display_info_add_to_caps (&other_minfo,
3299 fail_unless (gst_caps_is_equal (caps, other_caps));
3301 gst_caps_unref (caps);
3302 gst_caps_unref (other_caps);
3304 /* Test GstVideoContentLightLevel */
3305 gst_video_content_light_level_init (&level);
3306 gst_video_content_light_level_init (&other_level);
3308 level.max_content_light_level = 1000;
3309 level.max_frame_average_light_level = 300;
3311 caps = gst_caps_new_empty_simple ("video/x-raw");
3312 level_str = gst_video_content_light_level_to_string (&level);
3313 fail_unless (level_str != NULL);
3315 gst_caps_set_simple (caps, "content-light-level",
3316 G_TYPE_STRING, level_str, NULL);
3319 /* manually parsing CLL info from string */
3320 s = gst_caps_get_structure (caps, 0);
3321 fail_unless (gst_structure_get (s, "content-light-level",
3322 G_TYPE_STRING, &level_str, NULL), "Failed to get level from caps");
3323 fail_unless (gst_video_content_light_level_from_string (&other_level,
3327 fail_unless_equals_int (level.max_content_light_level,
3328 other_level.max_content_light_level);
3329 fail_unless_equals_int (level.max_frame_average_light_level,
3330 other_level.max_frame_average_light_level);
3332 /* simplified version for caps use case */
3333 fail_unless (gst_video_content_light_level_from_caps (&level_from_caps,
3335 fail_unless_equals_int (level.max_content_light_level,
3336 level_from_caps.max_content_light_level);
3337 fail_unless_equals_int (level.max_frame_average_light_level,
3338 level_from_caps.max_frame_average_light_level);
3340 /* check _add_to_caps () and manually created one */
3341 other_caps = gst_caps_new_empty_simple ("video/x-raw");
3342 fail_unless (gst_video_content_light_level_add_to_caps (&other_level,
3344 fail_unless (gst_caps_is_equal (caps, other_caps));
3346 gst_caps_unref (caps);
3347 gst_caps_unref (other_caps);
3352 GST_START_TEST (test_video_color_from_to_iso)
3356 #define ISO_IEC_UNSPECIFIED_COLOR_VALUE 2
3358 for (i = 0; i <= GST_VIDEO_COLOR_MATRIX_BT2020; i++) {
3359 guint matrix_val = gst_video_color_matrix_to_iso (i);
3360 fail_unless_equals_int (gst_video_color_matrix_from_iso (matrix_val), i);
3363 for (i = 0; i <= GST_VIDEO_TRANSFER_ARIB_STD_B67; i++) {
3364 guint transfer_val = gst_video_transfer_function_to_iso (i);
3366 /* don't know how to map below values to spec. */
3367 if (i == GST_VIDEO_TRANSFER_GAMMA18 || i == GST_VIDEO_TRANSFER_GAMMA20
3368 || i == GST_VIDEO_TRANSFER_ADOBERGB) {
3369 fail_unless_equals_int (transfer_val, ISO_IEC_UNSPECIFIED_COLOR_VALUE);
3373 fail_unless_equals_int (gst_video_transfer_function_from_iso (transfer_val),
3377 for (i = 0; i <= GST_VIDEO_COLOR_PRIMARIES_EBU3213; i++) {
3378 guint primaries_val = gst_video_color_primaries_to_iso (i);
3380 /* don't know how to map below value to spec. */
3381 if (i == GST_VIDEO_COLOR_PRIMARIES_ADOBERGB) {
3382 fail_unless_equals_int (primaries_val, ISO_IEC_UNSPECIFIED_COLOR_VALUE);
3386 fail_unless_equals_int (gst_video_color_primaries_from_iso (primaries_val),
3389 #undef ISO_IEC_UNSPECIFIED_COLOR_VALUE
3394 GST_START_TEST (test_video_format_info_plane_to_components)
3396 const GstVideoFormatInfo *info;
3397 gint comps[GST_VIDEO_MAX_COMPONENTS];
3399 /* RGB: 1 plane, 3 components */
3400 info = gst_video_format_get_info (GST_VIDEO_FORMAT_RGB);
3402 gst_video_format_info_component (info, 0, comps);
3403 g_assert_cmpint (comps[0], ==, 0);
3404 g_assert_cmpint (comps[1], ==, 1);
3405 g_assert_cmpint (comps[2], ==, 2);
3406 g_assert_cmpint (comps[3], ==, -1);
3408 gst_video_format_info_component (info, 1, comps);
3409 g_assert_cmpint (comps[0], ==, -1);
3410 g_assert_cmpint (comps[1], ==, -1);
3411 g_assert_cmpint (comps[2], ==, -1);
3412 g_assert_cmpint (comps[3], ==, -1);
3414 gst_video_format_info_component (info, 2, comps);
3415 g_assert_cmpint (comps[0], ==, -1);
3416 g_assert_cmpint (comps[1], ==, -1);
3417 g_assert_cmpint (comps[2], ==, -1);
3418 g_assert_cmpint (comps[3], ==, -1);
3420 gst_video_format_info_component (info, 3, comps);
3421 g_assert_cmpint (comps[0], ==, -1);
3422 g_assert_cmpint (comps[1], ==, -1);
3423 g_assert_cmpint (comps[2], ==, -1);
3424 g_assert_cmpint (comps[3], ==, -1);
3426 /* I420: 3 planes, 3 components */
3427 info = gst_video_format_get_info (GST_VIDEO_FORMAT_I420);
3429 gst_video_format_info_component (info, 0, comps);
3430 g_assert_cmpint (comps[0], ==, 0);
3431 g_assert_cmpint (comps[1], ==, -1);
3432 g_assert_cmpint (comps[2], ==, -1);
3433 g_assert_cmpint (comps[3], ==, -1);
3435 gst_video_format_info_component (info, 1, comps);
3436 g_assert_cmpint (comps[0], ==, 1);
3437 g_assert_cmpint (comps[1], ==, -1);
3438 g_assert_cmpint (comps[2], ==, -1);
3439 g_assert_cmpint (comps[3], ==, -1);
3441 gst_video_format_info_component (info, 2, comps);
3442 g_assert_cmpint (comps[0], ==, 2);
3443 g_assert_cmpint (comps[1], ==, -1);
3444 g_assert_cmpint (comps[2], ==, -1);
3445 g_assert_cmpint (comps[3], ==, -1);
3447 gst_video_format_info_component (info, 3, comps);
3448 g_assert_cmpint (comps[0], ==, -1);
3449 g_assert_cmpint (comps[1], ==, -1);
3450 g_assert_cmpint (comps[2], ==, -1);
3451 g_assert_cmpint (comps[3], ==, -1);
3453 /* NV12: 2 planes, 3 components */
3454 info = gst_video_format_get_info (GST_VIDEO_FORMAT_NV12);
3456 gst_video_format_info_component (info, 0, comps);
3457 g_assert_cmpint (comps[0], ==, 0);
3458 g_assert_cmpint (comps[1], ==, -1);
3459 g_assert_cmpint (comps[2], ==, -1);
3460 g_assert_cmpint (comps[3], ==, -1);
3462 gst_video_format_info_component (info, 1, comps);
3463 g_assert_cmpint (comps[0], ==, 1);
3464 g_assert_cmpint (comps[1], ==, 2);
3465 g_assert_cmpint (comps[2], ==, -1);
3466 g_assert_cmpint (comps[3], ==, -1);
3468 gst_video_format_info_component (info, 2, comps);
3469 g_assert_cmpint (comps[0], ==, -1);
3470 g_assert_cmpint (comps[1], ==, -1);
3471 g_assert_cmpint (comps[2], ==, -1);
3472 g_assert_cmpint (comps[3], ==, -1);
3474 gst_video_format_info_component (info, 3, comps);
3475 g_assert_cmpint (comps[0], ==, -1);
3476 g_assert_cmpint (comps[1], ==, -1);
3477 g_assert_cmpint (comps[2], ==, -1);
3478 g_assert_cmpint (comps[3], ==, -1);
3483 GST_START_TEST (test_video_info_align)
3486 GstVideoAlignment align;
3487 gsize plane_size[GST_VIDEO_MAX_PLANES];
3490 gst_video_info_init (&info);
3491 gst_video_info_set_format (&info, GST_VIDEO_FORMAT_NV12, 1920, 1080);
3493 g_assert_cmpuint (GST_VIDEO_INFO_HEIGHT (&info), ==, 1080);
3494 g_assert_cmpuint (GST_VIDEO_INFO_FIELD_HEIGHT (&info), ==, 1080);
3495 g_assert_cmpuint (GST_VIDEO_INFO_SIZE (&info), ==, 1920 * 1080 * 1.5);
3497 gst_video_alignment_reset (&align);
3498 /* Align with no padding to retrieve the plane heights */
3499 g_assert (gst_video_info_align_full (&info, &align, plane_size));
3501 g_assert_cmpuint (plane_size[0], ==, 1920 * 1080);
3502 g_assert_cmpuint (plane_size[1], ==, 1920 * 1080 / 2);
3503 g_assert_cmpuint (plane_size[2], ==, 0);
3504 g_assert_cmpuint (plane_size[3], ==, 0);
3506 g_assert_cmpuint (GST_VIDEO_INFO_PLANE_STRIDE (&info, 0), ==, 1920);
3507 g_assert_cmpuint (GST_VIDEO_INFO_PLANE_STRIDE (&info, 1), ==, 1920);
3508 g_assert_cmpuint (GST_VIDEO_INFO_PLANE_STRIDE (&info, 2), ==, 0);
3509 g_assert_cmpuint (GST_VIDEO_INFO_PLANE_STRIDE (&info, 3), ==, 0);
3510 g_assert_cmpuint (GST_VIDEO_INFO_PLANE_HEIGHT (&info, 0, plane_size), ==,
3512 g_assert_cmpuint (GST_VIDEO_INFO_PLANE_HEIGHT (&info, 1, plane_size), ==,
3514 g_assert_cmpuint (GST_VIDEO_INFO_PLANE_HEIGHT (&info, 2, plane_size), ==, 0);
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 (plane_size[0], ==, 1920 * 1088);
3522 g_assert_cmpuint (plane_size[1], ==, 1920 * 1088 / 2);
3523 g_assert_cmpuint (plane_size[2], ==, 0);
3524 g_assert_cmpuint (plane_size[3], ==, 0);
3526 g_assert_cmpuint (GST_VIDEO_INFO_HEIGHT (&info), ==, 1080);
3527 g_assert_cmpuint (GST_VIDEO_INFO_FIELD_HEIGHT (&info), ==, 1080);
3528 g_assert_cmpuint (GST_VIDEO_INFO_SIZE (&info), ==, 1920 * 1088 * 1.5);
3530 g_assert_cmpuint (GST_VIDEO_INFO_PLANE_STRIDE (&info, 0), ==, 1920);
3531 g_assert_cmpuint (GST_VIDEO_INFO_PLANE_STRIDE (&info, 1), ==, 1920);
3532 g_assert_cmpuint (GST_VIDEO_INFO_PLANE_STRIDE (&info, 2), ==, 0);
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), ==, 0);
3539 g_assert_cmpuint (GST_VIDEO_INFO_PLANE_HEIGHT (&info, 3, plane_size), ==, 0);
3542 gst_video_info_init (&info);
3543 gst_video_info_set_format (&info, GST_VIDEO_FORMAT_NV16, 1920, 1080);
3545 g_assert_cmpuint (GST_VIDEO_INFO_HEIGHT (&info), ==, 1080);
3546 g_assert_cmpuint (GST_VIDEO_INFO_FIELD_HEIGHT (&info), ==, 1080);
3547 g_assert_cmpuint (GST_VIDEO_INFO_SIZE (&info), ==, 1920 * 1080 * 2);
3549 gst_video_alignment_reset (&align);
3550 /* Align with no padding to retrieve the plane heights */
3551 g_assert (gst_video_info_align_full (&info, &align, plane_size));
3553 g_assert_cmpuint (plane_size[0], ==, 1920 * 1080);
3554 g_assert_cmpuint (plane_size[1], ==, 1920 * 1080);
3555 g_assert_cmpuint (plane_size[2], ==, 0);
3556 g_assert_cmpuint (plane_size[3], ==, 0);
3558 g_assert_cmpuint (GST_VIDEO_INFO_PLANE_STRIDE (&info, 0), ==, 1920);
3559 g_assert_cmpuint (GST_VIDEO_INFO_PLANE_STRIDE (&info, 1), ==, 1920);
3560 g_assert_cmpuint (GST_VIDEO_INFO_PLANE_STRIDE (&info, 2), ==, 0);
3561 g_assert_cmpuint (GST_VIDEO_INFO_PLANE_STRIDE (&info, 3), ==, 0);
3562 g_assert_cmpuint (GST_VIDEO_INFO_PLANE_HEIGHT (&info, 0, plane_size), ==,
3564 g_assert_cmpuint (GST_VIDEO_INFO_PLANE_HEIGHT (&info, 1, plane_size), ==,
3566 g_assert_cmpuint (GST_VIDEO_INFO_PLANE_HEIGHT (&info, 2, plane_size), ==, 0);
3567 g_assert_cmpuint (GST_VIDEO_INFO_PLANE_HEIGHT (&info, 3, plane_size), ==, 0);
3569 gst_video_alignment_reset (&align);
3570 align.padding_bottom = 8;
3571 g_assert (gst_video_info_align_full (&info, &align, plane_size));
3573 g_assert_cmpuint (GST_VIDEO_INFO_HEIGHT (&info), ==, 1080);
3574 g_assert_cmpuint (GST_VIDEO_INFO_FIELD_HEIGHT (&info), ==, 1080);
3575 g_assert_cmpuint (GST_VIDEO_INFO_SIZE (&info), ==, 1920 * 1088 * 2);
3577 g_assert_cmpuint (plane_size[0], ==, 1920 * 1088);
3578 g_assert_cmpuint (plane_size[1], ==, 1920 * 1088);
3579 g_assert_cmpuint (plane_size[2], ==, 0);
3580 g_assert_cmpuint (plane_size[3], ==, 0);
3582 g_assert_cmpuint (GST_VIDEO_INFO_PLANE_STRIDE (&info, 0), ==, 1920);
3583 g_assert_cmpuint (GST_VIDEO_INFO_PLANE_STRIDE (&info, 1), ==, 1920);
3584 g_assert_cmpuint (GST_VIDEO_INFO_PLANE_STRIDE (&info, 2), ==, 0);
3585 g_assert_cmpuint (GST_VIDEO_INFO_PLANE_STRIDE (&info, 3), ==, 0);
3586 g_assert_cmpuint (GST_VIDEO_INFO_PLANE_HEIGHT (&info, 0, plane_size), ==,
3588 g_assert_cmpuint (GST_VIDEO_INFO_PLANE_HEIGHT (&info, 1, plane_size), ==,
3590 g_assert_cmpuint (GST_VIDEO_INFO_PLANE_HEIGHT (&info, 2, plane_size), ==, 0);
3591 g_assert_cmpuint (GST_VIDEO_INFO_PLANE_HEIGHT (&info, 3, plane_size), ==, 0);
3594 gst_video_info_init (&info);
3595 gst_video_info_set_format (&info, GST_VIDEO_FORMAT_RGB, 1920, 1080);
3597 g_assert_cmpuint (GST_VIDEO_INFO_HEIGHT (&info), ==, 1080);
3598 g_assert_cmpuint (GST_VIDEO_INFO_FIELD_HEIGHT (&info), ==, 1080);
3599 g_assert_cmpuint (GST_VIDEO_INFO_SIZE (&info), ==, 1920 * 1080 * 3);
3601 gst_video_alignment_reset (&align);
3602 /* Align with no padding to retrieve the plane heights */
3603 g_assert (gst_video_info_align_full (&info, &align, plane_size));
3605 g_assert_cmpuint (plane_size[0], ==, 1920 * 1080 * 3);
3606 g_assert_cmpuint (plane_size[1], ==, 0);
3607 g_assert_cmpuint (plane_size[2], ==, 0);
3608 g_assert_cmpuint (plane_size[3], ==, 0);
3610 g_assert_cmpuint (GST_VIDEO_INFO_PLANE_STRIDE (&info, 0), ==, 5760);
3611 g_assert_cmpuint (GST_VIDEO_INFO_PLANE_STRIDE (&info, 1), ==, 0);
3612 g_assert_cmpuint (GST_VIDEO_INFO_PLANE_STRIDE (&info, 2), ==, 0);
3613 g_assert_cmpuint (GST_VIDEO_INFO_PLANE_STRIDE (&info, 3), ==, 0);
3614 g_assert_cmpuint (GST_VIDEO_INFO_PLANE_HEIGHT (&info, 0, plane_size), ==,
3616 g_assert_cmpuint (GST_VIDEO_INFO_PLANE_HEIGHT (&info, 1, plane_size), ==, 0);
3617 g_assert_cmpuint (GST_VIDEO_INFO_PLANE_HEIGHT (&info, 2, plane_size), ==, 0);
3618 g_assert_cmpuint (GST_VIDEO_INFO_PLANE_HEIGHT (&info, 3, plane_size), ==, 0);
3620 gst_video_alignment_reset (&align);
3621 align.padding_bottom = 8;
3622 g_assert (gst_video_info_align_full (&info, &align, plane_size));
3624 g_assert_cmpuint (GST_VIDEO_INFO_HEIGHT (&info), ==, 1080);
3625 g_assert_cmpuint (GST_VIDEO_INFO_FIELD_HEIGHT (&info), ==, 1080);
3626 g_assert_cmpuint (GST_VIDEO_INFO_SIZE (&info), ==, 1920 * 1088 * 3);
3628 g_assert_cmpuint (plane_size[0], ==, 1920 * 1088 * 3);
3629 g_assert_cmpuint (plane_size[1], ==, 0);
3630 g_assert_cmpuint (plane_size[2], ==, 0);
3631 g_assert_cmpuint (plane_size[3], ==, 0);
3633 g_assert_cmpuint (GST_VIDEO_INFO_PLANE_STRIDE (&info, 0), ==, 5760);
3634 g_assert_cmpuint (GST_VIDEO_INFO_PLANE_STRIDE (&info, 1), ==, 0);
3635 g_assert_cmpuint (GST_VIDEO_INFO_PLANE_STRIDE (&info, 2), ==, 0);
3636 g_assert_cmpuint (GST_VIDEO_INFO_PLANE_STRIDE (&info, 3), ==, 0);
3637 g_assert_cmpuint (GST_VIDEO_INFO_PLANE_HEIGHT (&info, 0, plane_size), ==,
3639 g_assert_cmpuint (GST_VIDEO_INFO_PLANE_HEIGHT (&info, 1, plane_size), ==, 0);
3640 g_assert_cmpuint (GST_VIDEO_INFO_PLANE_HEIGHT (&info, 2, plane_size), ==, 0);
3641 g_assert_cmpuint (GST_VIDEO_INFO_PLANE_HEIGHT (&info, 3, plane_size), ==, 0);
3644 gst_video_info_init (&info);
3645 gst_video_info_set_format (&info, GST_VIDEO_FORMAT_I420, 1920, 1080);
3647 g_assert_cmpuint (GST_VIDEO_INFO_HEIGHT (&info), ==, 1080);
3648 g_assert_cmpuint (GST_VIDEO_INFO_FIELD_HEIGHT (&info), ==, 1080);
3649 g_assert_cmpuint (GST_VIDEO_INFO_SIZE (&info), ==, 1920 * 1080 * 1.5);
3651 gst_video_alignment_reset (&align);
3652 /* Align with no padding to retrieve the plane heights */
3653 g_assert (gst_video_info_align_full (&info, &align, plane_size));
3655 g_assert_cmpuint (plane_size[0], ==, 1920 * 1080);
3656 g_assert_cmpuint (plane_size[1], ==, 1920 * 1080 / 4);
3657 g_assert_cmpuint (plane_size[2], ==, 1920 * 1080 / 4);
3658 g_assert_cmpuint (plane_size[3], ==, 0);
3660 g_assert_cmpuint (GST_VIDEO_INFO_PLANE_STRIDE (&info, 0), ==, 1920);
3661 g_assert_cmpuint (GST_VIDEO_INFO_PLANE_STRIDE (&info, 1), ==, 960);
3662 g_assert_cmpuint (GST_VIDEO_INFO_PLANE_STRIDE (&info, 2), ==, 960);
3663 g_assert_cmpuint (GST_VIDEO_INFO_PLANE_STRIDE (&info, 3), ==, 0);
3664 g_assert_cmpuint (GST_VIDEO_INFO_PLANE_HEIGHT (&info, 0, plane_size), ==,
3666 g_assert_cmpuint (GST_VIDEO_INFO_PLANE_HEIGHT (&info, 1, plane_size), ==,
3668 g_assert_cmpuint (GST_VIDEO_INFO_PLANE_HEIGHT (&info, 2, plane_size), ==,
3670 g_assert_cmpuint (GST_VIDEO_INFO_PLANE_HEIGHT (&info, 3, plane_size), ==, 0);
3672 gst_video_alignment_reset (&align);
3673 align.padding_bottom = 8;
3674 g_assert (gst_video_info_align_full (&info, &align, plane_size));
3676 g_assert_cmpuint (GST_VIDEO_INFO_HEIGHT (&info), ==, 1080);
3677 g_assert_cmpuint (GST_VIDEO_INFO_FIELD_HEIGHT (&info), ==, 1080);
3678 g_assert_cmpuint (GST_VIDEO_INFO_SIZE (&info), ==, 1920 * 1088 * 1.5);
3680 g_assert_cmpuint (plane_size[0], ==, 1920 * 1088);
3681 g_assert_cmpuint (plane_size[1], ==, 1920 * 1088 / 4);
3682 g_assert_cmpuint (plane_size[2], ==, 1920 * 1088 / 4);
3683 g_assert_cmpuint (plane_size[3], ==, 0);
3685 g_assert_cmpuint (GST_VIDEO_INFO_PLANE_STRIDE (&info, 0), ==, 1920);
3686 g_assert_cmpuint (GST_VIDEO_INFO_PLANE_STRIDE (&info, 1), ==, 960);
3687 g_assert_cmpuint (GST_VIDEO_INFO_PLANE_STRIDE (&info, 2), ==, 960);
3688 g_assert_cmpuint (GST_VIDEO_INFO_PLANE_STRIDE (&info, 3), ==, 0);
3689 g_assert_cmpuint (GST_VIDEO_INFO_PLANE_HEIGHT (&info, 0, plane_size), ==,
3691 g_assert_cmpuint (GST_VIDEO_INFO_PLANE_HEIGHT (&info, 1, plane_size), ==,
3693 g_assert_cmpuint (GST_VIDEO_INFO_PLANE_HEIGHT (&info, 2, plane_size), ==,
3695 g_assert_cmpuint (GST_VIDEO_INFO_PLANE_HEIGHT (&info, 3, plane_size), ==, 0);
3697 /* NV16 alternate */
3698 gst_video_info_init (&info);
3699 gst_video_info_set_interlaced_format (&info, GST_VIDEO_FORMAT_NV16,
3700 GST_VIDEO_INTERLACE_MODE_ALTERNATE, 1920, 1080);
3702 g_assert_cmpuint (GST_VIDEO_INFO_HEIGHT (&info), ==, 1080);
3703 g_assert_cmpuint (GST_VIDEO_INFO_FIELD_HEIGHT (&info), ==, 540);
3704 g_assert_cmpuint (GST_VIDEO_INFO_SIZE (&info), ==, 1920 * 540 * 2);
3706 gst_video_alignment_reset (&align);
3707 /* Align with no padding to retrieve the plane heights */
3708 g_assert (gst_video_info_align_full (&info, &align, plane_size));
3710 g_assert_cmpuint (plane_size[0], ==, 1920 * 540);
3711 g_assert_cmpuint (plane_size[1], ==, 1920 * 540);
3712 g_assert_cmpuint (plane_size[2], ==, 0);
3713 g_assert_cmpuint (plane_size[3], ==, 0);
3715 g_assert_cmpuint (GST_VIDEO_INFO_PLANE_STRIDE (&info, 0), ==, 1920);
3716 g_assert_cmpuint (GST_VIDEO_INFO_PLANE_STRIDE (&info, 1), ==, 1920);
3717 g_assert_cmpuint (GST_VIDEO_INFO_PLANE_STRIDE (&info, 2), ==, 0);
3718 g_assert_cmpuint (GST_VIDEO_INFO_PLANE_STRIDE (&info, 3), ==, 0);
3719 g_assert_cmpuint (GST_VIDEO_INFO_PLANE_HEIGHT (&info, 0, plane_size), ==,
3721 g_assert_cmpuint (GST_VIDEO_INFO_PLANE_HEIGHT (&info, 1, plane_size), ==,
3723 g_assert_cmpuint (GST_VIDEO_INFO_PLANE_HEIGHT (&info, 2, plane_size), ==, 0);
3724 g_assert_cmpuint (GST_VIDEO_INFO_PLANE_HEIGHT (&info, 3, plane_size), ==, 0);
3726 gst_video_alignment_reset (&align);
3727 align.padding_bottom = 8;
3728 g_assert (gst_video_info_align_full (&info, &align, plane_size));
3730 g_assert_cmpuint (GST_VIDEO_INFO_HEIGHT (&info), ==, 1080);
3731 g_assert_cmpuint (GST_VIDEO_INFO_FIELD_HEIGHT (&info), ==, 540);
3732 g_assert_cmpuint (GST_VIDEO_INFO_SIZE (&info), ==, 1920 * 544 * 2);
3734 g_assert_cmpuint (plane_size[0], ==, 1920 * 544);
3735 g_assert_cmpuint (plane_size[1], ==, 1920 * 544);
3736 g_assert_cmpuint (plane_size[2], ==, 0);
3737 g_assert_cmpuint (plane_size[3], ==, 0);
3739 g_assert_cmpuint (GST_VIDEO_INFO_PLANE_STRIDE (&info, 0), ==, 1920);
3740 g_assert_cmpuint (GST_VIDEO_INFO_PLANE_STRIDE (&info, 1), ==, 1920);
3741 g_assert_cmpuint (GST_VIDEO_INFO_PLANE_STRIDE (&info, 2), ==, 0);
3742 g_assert_cmpuint (GST_VIDEO_INFO_PLANE_STRIDE (&info, 3), ==, 0);
3743 g_assert_cmpuint (GST_VIDEO_INFO_PLANE_HEIGHT (&info, 0, plane_size), ==,
3745 g_assert_cmpuint (GST_VIDEO_INFO_PLANE_HEIGHT (&info, 1, plane_size), ==,
3747 g_assert_cmpuint (GST_VIDEO_INFO_PLANE_HEIGHT (&info, 2, plane_size), ==, 0);
3748 g_assert_cmpuint (GST_VIDEO_INFO_PLANE_HEIGHT (&info, 3, plane_size), ==, 0);
3750 /* NV16 alternate with an odd height */
3751 gst_video_info_init (&info);
3752 gst_video_info_set_interlaced_format (&info, GST_VIDEO_FORMAT_NV16,
3753 GST_VIDEO_INTERLACE_MODE_ALTERNATE, 1920, 1081);
3755 g_assert_cmpuint (GST_VIDEO_INFO_HEIGHT (&info), ==, 1081);
3756 g_assert_cmpuint (GST_VIDEO_INFO_FIELD_HEIGHT (&info), ==, 541);
3757 g_assert_cmpuint (GST_VIDEO_INFO_SIZE (&info), ==, 1920 * 541 * 2);
3759 gst_video_alignment_reset (&align);
3760 /* Align with no padding to retrieve the plane heights */
3761 g_assert (gst_video_info_align_full (&info, &align, plane_size));
3763 g_assert_cmpuint (plane_size[0], ==, 1920 * 541);
3764 g_assert_cmpuint (plane_size[1], ==, 1920 * 541);
3765 g_assert_cmpuint (plane_size[2], ==, 0);
3766 g_assert_cmpuint (plane_size[3], ==, 0);
3768 g_assert_cmpuint (GST_VIDEO_INFO_PLANE_STRIDE (&info, 0), ==, 1920);
3769 g_assert_cmpuint (GST_VIDEO_INFO_PLANE_STRIDE (&info, 1), ==, 1920);
3770 g_assert_cmpuint (GST_VIDEO_INFO_PLANE_STRIDE (&info, 2), ==, 0);
3771 g_assert_cmpuint (GST_VIDEO_INFO_PLANE_STRIDE (&info, 3), ==, 0);
3772 g_assert_cmpuint (GST_VIDEO_INFO_PLANE_HEIGHT (&info, 0, plane_size), ==,
3774 g_assert_cmpuint (GST_VIDEO_INFO_PLANE_HEIGHT (&info, 1, plane_size), ==,
3776 g_assert_cmpuint (GST_VIDEO_INFO_PLANE_HEIGHT (&info, 2, plane_size), ==, 0);
3777 g_assert_cmpuint (GST_VIDEO_INFO_PLANE_HEIGHT (&info, 3, plane_size), ==, 0);
3779 gst_video_alignment_reset (&align);
3780 align.padding_bottom = 2;
3781 g_assert (gst_video_info_align_full (&info, &align, plane_size));
3783 g_assert_cmpuint (GST_VIDEO_INFO_HEIGHT (&info), ==, 1081);
3784 g_assert_cmpuint (GST_VIDEO_INFO_FIELD_HEIGHT (&info), ==, 541);
3785 g_assert_cmpuint (GST_VIDEO_INFO_SIZE (&info), ==, 1920 * 542 * 2);
3787 g_assert_cmpuint (plane_size[0], ==, 1920 * 542);
3788 g_assert_cmpuint (plane_size[1], ==, 1920 * 542);
3789 g_assert_cmpuint (plane_size[2], ==, 0);
3790 g_assert_cmpuint (plane_size[3], ==, 0);
3792 g_assert_cmpuint (GST_VIDEO_INFO_PLANE_STRIDE (&info, 0), ==, 1920);
3793 g_assert_cmpuint (GST_VIDEO_INFO_PLANE_STRIDE (&info, 1), ==, 1920);
3794 g_assert_cmpuint (GST_VIDEO_INFO_PLANE_STRIDE (&info, 2), ==, 0);
3795 g_assert_cmpuint (GST_VIDEO_INFO_PLANE_STRIDE (&info, 3), ==, 0);
3796 g_assert_cmpuint (GST_VIDEO_INFO_PLANE_HEIGHT (&info, 0, plane_size), ==,
3798 g_assert_cmpuint (GST_VIDEO_INFO_PLANE_HEIGHT (&info, 1, plane_size), ==,
3800 g_assert_cmpuint (GST_VIDEO_INFO_PLANE_HEIGHT (&info, 2, plane_size), ==, 0);
3801 g_assert_cmpuint (GST_VIDEO_INFO_PLANE_HEIGHT (&info, 3, plane_size), ==, 0);
3806 GST_START_TEST (test_video_meta_align)
3811 gsize plane_size[GST_VIDEO_MAX_PLANES];
3812 guint plane_height[GST_VIDEO_MAX_PLANES];
3813 GstVideoAlignment alig;
3815 buf = gst_buffer_new ();
3817 /* NV12 no alignment */
3818 gst_video_info_init (&info);
3819 gst_video_info_set_format (&info, GST_VIDEO_FORMAT_NV12, 1920, 1080);
3821 meta = gst_buffer_add_video_meta_full (buf, GST_VIDEO_FRAME_FLAG_NONE,
3822 GST_VIDEO_INFO_FORMAT (&info), GST_VIDEO_INFO_WIDTH (&info),
3823 GST_VIDEO_INFO_HEIGHT (&info), GST_VIDEO_INFO_N_PLANES (&info),
3824 info.offset, info.stride);
3826 g_assert_cmpuint (meta->alignment.padding_top, ==, 0);
3827 g_assert_cmpuint (meta->alignment.padding_bottom, ==, 0);
3828 g_assert_cmpuint (meta->alignment.padding_left, ==, 0);
3829 g_assert_cmpuint (meta->alignment.padding_right, ==, 0);
3831 g_assert (gst_video_meta_get_plane_size (meta, plane_size));
3832 g_assert_cmpuint (plane_size[0], ==, 1920 * 1080);
3833 g_assert_cmpuint (plane_size[1], ==, 1920 * 1080 * 0.5);
3834 g_assert_cmpuint (plane_size[2], ==, 0);
3835 g_assert_cmpuint (plane_size[3], ==, 0);
3837 g_assert (gst_video_meta_get_plane_height (meta, plane_height));
3838 g_assert_cmpuint (plane_height[0], ==, 1080);
3839 g_assert_cmpuint (plane_height[1], ==, 540);
3840 g_assert_cmpuint (plane_height[2], ==, 0);
3841 g_assert_cmpuint (plane_height[3], ==, 0);
3843 /* horizontal alignment */
3844 gst_video_info_init (&info);
3845 gst_video_info_set_format (&info, GST_VIDEO_FORMAT_NV12, 1920, 1080);
3847 gst_video_alignment_reset (&alig);
3848 alig.padding_left = 2;
3849 alig.padding_right = 6;
3851 g_assert (gst_video_info_align (&info, &alig));
3853 meta = gst_buffer_add_video_meta_full (buf, GST_VIDEO_FRAME_FLAG_NONE,
3854 GST_VIDEO_INFO_FORMAT (&info), GST_VIDEO_INFO_WIDTH (&info),
3855 GST_VIDEO_INFO_HEIGHT (&info), GST_VIDEO_INFO_N_PLANES (&info),
3856 info.offset, info.stride);
3857 g_assert (gst_video_meta_set_alignment (meta, alig));
3859 g_assert_cmpuint (meta->alignment.padding_top, ==, 0);
3860 g_assert_cmpuint (meta->alignment.padding_bottom, ==, 0);
3861 g_assert_cmpuint (meta->alignment.padding_left, ==, 2);
3862 g_assert_cmpuint (meta->alignment.padding_right, ==, 6);
3864 g_assert (gst_video_meta_get_plane_size (meta, plane_size));
3865 g_assert_cmpuint (plane_size[0], ==, 1928 * 1080);
3866 g_assert_cmpuint (plane_size[1], ==, 1928 * 1080 * 0.5);
3867 g_assert_cmpuint (plane_size[2], ==, 0);
3868 g_assert_cmpuint (plane_size[3], ==, 0);
3870 g_assert (gst_video_meta_get_plane_height (meta, plane_height));
3871 g_assert_cmpuint (plane_height[0], ==, 1080);
3872 g_assert_cmpuint (plane_height[1], ==, 540);
3873 g_assert_cmpuint (plane_height[2], ==, 0);
3874 g_assert_cmpuint (plane_height[3], ==, 0);
3876 /* vertical alignment */
3877 gst_video_info_init (&info);
3878 gst_video_info_set_format (&info, GST_VIDEO_FORMAT_NV12, 1920, 1080);
3880 gst_video_alignment_reset (&alig);
3881 alig.padding_top = 2;
3882 alig.padding_bottom = 6;
3884 g_assert (gst_video_info_align (&info, &alig));
3886 meta = gst_buffer_add_video_meta_full (buf, GST_VIDEO_FRAME_FLAG_NONE,
3887 GST_VIDEO_INFO_FORMAT (&info), GST_VIDEO_INFO_WIDTH (&info),
3888 GST_VIDEO_INFO_HEIGHT (&info), GST_VIDEO_INFO_N_PLANES (&info),
3889 info.offset, info.stride);
3890 g_assert (gst_video_meta_set_alignment (meta, alig));
3892 g_assert_cmpuint (meta->alignment.padding_top, ==, 2);
3893 g_assert_cmpuint (meta->alignment.padding_bottom, ==, 6);
3894 g_assert_cmpuint (meta->alignment.padding_left, ==, 0);
3895 g_assert_cmpuint (meta->alignment.padding_right, ==, 0);
3897 g_assert (gst_video_meta_get_plane_size (meta, plane_size));
3898 g_assert_cmpuint (plane_size[0], ==, 1920 * 1088);
3899 g_assert_cmpuint (plane_size[1], ==, 1920 * 1088 * 0.5);
3900 g_assert_cmpuint (plane_size[2], ==, 0);
3901 g_assert_cmpuint (plane_size[3], ==, 0);
3903 g_assert (gst_video_meta_get_plane_height (meta, plane_height));
3904 g_assert_cmpuint (plane_height[0], ==, 1088);
3905 g_assert_cmpuint (plane_height[1], ==, 544);
3906 g_assert_cmpuint (plane_height[2], ==, 0);
3907 g_assert_cmpuint (plane_height[3], ==, 0);
3909 /* incompatible alignment */
3910 gst_video_info_init (&info);
3911 gst_video_info_set_format (&info, GST_VIDEO_FORMAT_NV12, 1920, 1080);
3913 gst_video_alignment_reset (&alig);
3914 alig.padding_right = 2;
3916 meta = gst_buffer_add_video_meta_full (buf, GST_VIDEO_FRAME_FLAG_NONE,
3917 GST_VIDEO_INFO_FORMAT (&info), GST_VIDEO_INFO_WIDTH (&info),
3918 GST_VIDEO_INFO_HEIGHT (&info), GST_VIDEO_INFO_N_PLANES (&info),
3919 info.offset, info.stride);
3920 g_assert (!gst_video_meta_set_alignment (meta, alig));
3922 gst_buffer_unref (buf);
3927 GST_START_TEST (test_video_flags)
3931 GstVideoFrame frame;
3933 gst_video_info_init (&info);
3934 fail_unless (gst_video_info_set_interlaced_format (&info,
3935 GST_VIDEO_FORMAT_RGB, GST_VIDEO_INTERLACE_MODE_ALTERNATE, 4, 4));
3937 buf = gst_buffer_new_and_alloc (GST_VIDEO_INFO_SIZE (&info));
3938 fail_unless (!GST_VIDEO_BUFFER_IS_TOP_FIELD (buf));
3939 fail_unless (!GST_VIDEO_BUFFER_IS_BOTTOM_FIELD (buf));
3940 fail_unless (gst_video_frame_map (&frame, &info, buf, GST_MAP_READ));
3941 fail_unless (!GST_VIDEO_FRAME_IS_TOP_FIELD (&frame));
3942 fail_unless (!GST_VIDEO_FRAME_IS_BOTTOM_FIELD (&frame));
3943 gst_video_frame_unmap (&frame);
3944 gst_buffer_unref (buf);
3946 buf = gst_buffer_new_and_alloc (GST_VIDEO_INFO_SIZE (&info));
3947 GST_BUFFER_FLAG_SET (buf, GST_VIDEO_BUFFER_FLAG_TOP_FIELD);
3948 fail_unless (GST_VIDEO_BUFFER_IS_TOP_FIELD (buf));
3949 fail_unless (!GST_VIDEO_BUFFER_IS_BOTTOM_FIELD (buf));
3950 fail_unless (gst_video_frame_map (&frame, &info, buf, GST_MAP_READ));
3951 fail_unless (GST_VIDEO_FRAME_IS_TOP_FIELD (&frame));
3952 fail_unless (!GST_VIDEO_FRAME_IS_BOTTOM_FIELD (&frame));
3953 gst_video_frame_unmap (&frame);
3954 gst_buffer_unref (buf);
3956 buf = gst_buffer_new_and_alloc (GST_VIDEO_INFO_SIZE (&info));
3957 GST_BUFFER_FLAG_SET (buf, GST_VIDEO_BUFFER_FLAG_BOTTOM_FIELD);
3958 fail_unless (!GST_VIDEO_BUFFER_IS_TOP_FIELD (buf));
3959 fail_unless (GST_VIDEO_BUFFER_IS_BOTTOM_FIELD (buf));
3960 fail_unless (gst_video_frame_map (&frame, &info, buf, GST_MAP_READ));
3961 fail_unless (!GST_VIDEO_FRAME_IS_TOP_FIELD (&frame));
3962 fail_unless (GST_VIDEO_FRAME_IS_BOTTOM_FIELD (&frame));
3963 gst_video_frame_unmap (&frame);
3964 gst_buffer_unref (buf);
3969 GST_START_TEST (test_video_make_raw_caps)
3971 GstCaps *caps, *expected;
3972 GstVideoFormat f1[] = { GST_VIDEO_FORMAT_NV12 };
3973 GstVideoFormat f2[] = { GST_VIDEO_FORMAT_NV12, GST_VIDEO_FORMAT_NV16 };
3975 caps = gst_video_make_raw_caps (f1, G_N_ELEMENTS (f1));
3976 expected = gst_caps_from_string (GST_VIDEO_CAPS_MAKE ("NV12"));
3977 fail_unless (gst_caps_is_equal (caps, expected));
3978 gst_caps_unref (caps);
3979 gst_caps_unref (expected);
3981 caps = gst_video_make_raw_caps (f2, G_N_ELEMENTS (f2));
3982 expected = gst_caps_from_string (GST_VIDEO_CAPS_MAKE ("{ NV12, NV16 }"));
3983 fail_unless (gst_caps_is_equal (caps, expected));
3984 gst_caps_unref (caps);
3985 gst_caps_unref (expected);
3987 caps = gst_video_make_raw_caps (NULL, 0);
3988 expected = gst_caps_from_string (GST_VIDEO_CAPS_MAKE (GST_VIDEO_FORMATS_ALL));
3989 fail_unless (gst_caps_is_equal (caps, expected));
3990 gst_caps_unref (caps);
3991 gst_caps_unref (expected);
3994 gst_video_make_raw_caps_with_features (NULL, 0,
3995 gst_caps_features_new_any ());
3997 gst_caps_from_string (GST_VIDEO_CAPS_MAKE_WITH_FEATURES ("ANY",
3998 GST_VIDEO_FORMATS_ALL));
3999 fail_unless (gst_caps_is_equal (caps, expected));
4000 gst_caps_unref (caps);
4001 gst_caps_unref (expected);
4009 Suite *s = suite_create ("video support library");
4010 TCase *tc_chain = tcase_create ("general");
4012 tcase_set_timeout (tc_chain, 60 * 60);
4014 suite_add_tcase (s, tc_chain);
4015 tcase_add_test (tc_chain, test_video_formats);
4016 tcase_add_test (tc_chain, test_video_formats_overflow);
4017 tcase_add_test (tc_chain, test_video_formats_rgb);
4018 tcase_add_test (tc_chain, test_video_formats_rgba_large_dimension);
4019 tcase_add_test (tc_chain, test_video_formats_all);
4020 tcase_add_test (tc_chain, test_video_formats_pack_unpack);
4021 tcase_add_test (tc_chain, test_guess_framerate);
4022 tcase_add_test (tc_chain, test_dar_calc);
4023 tcase_add_test (tc_chain, test_parse_caps_rgb);
4024 tcase_add_test (tc_chain, test_parse_caps_multiview);
4025 tcase_add_test (tc_chain, test_parse_colorimetry);
4026 tcase_add_test (tc_chain, test_events);
4027 tcase_add_test (tc_chain, test_convert_frame);
4028 tcase_add_test (tc_chain, test_convert_frame_async);
4029 tcase_add_test (tc_chain, test_convert_frame_async_error);
4030 tcase_add_test (tc_chain, test_video_size_from_caps);
4031 tcase_add_test (tc_chain, test_interlace_mode);
4032 tcase_add_test (tc_chain, test_overlay_composition);
4033 tcase_add_test (tc_chain, test_overlay_composition_premultiplied_alpha);
4034 tcase_add_test (tc_chain, test_overlay_composition_global_alpha);
4035 tcase_add_test (tc_chain, test_video_pack_unpack2);
4036 tcase_add_test (tc_chain, test_video_chroma);
4037 tcase_add_test (tc_chain, test_video_chroma_site);
4038 tcase_add_test (tc_chain, test_video_scaler);
4039 tcase_add_test (tc_chain, test_video_color_convert_rgb_rgb);
4040 tcase_add_test (tc_chain, test_video_color_convert_rgb_yuv);
4041 tcase_add_test (tc_chain, test_video_color_convert_yuv_yuv);
4042 tcase_add_test (tc_chain, test_video_color_convert_yuv_rgb);
4043 tcase_add_test (tc_chain, test_video_color_convert_other);
4044 tcase_add_test (tc_chain, test_video_size_convert);
4045 tcase_add_test (tc_chain, test_video_convert);
4046 tcase_add_test (tc_chain, test_video_convert_multithreading);
4047 tcase_add_test (tc_chain, test_video_transfer);
4048 tcase_add_test (tc_chain, test_overlay_blend);
4049 tcase_add_test (tc_chain, test_video_center_rect);
4050 tcase_add_test (tc_chain, test_overlay_composition_over_transparency);
4051 tcase_add_test (tc_chain, test_video_format_enum_stability);
4052 tcase_add_test (tc_chain, test_video_formats_pstrides);
4053 tcase_add_test (tc_chain, test_hdr);
4054 tcase_add_test (tc_chain, test_video_color_from_to_iso);
4055 tcase_add_test (tc_chain, test_video_format_info_plane_to_components);
4056 tcase_add_test (tc_chain, test_video_info_align);
4057 tcase_add_test (tc_chain, test_video_meta_align);
4058 tcase_add_test (tc_chain, test_video_flags);
4059 tcase_add_test (tc_chain, test_video_make_raw_caps);
4064 GST_CHECK_MAIN (video);