1 /* GStreamer unit test for video
2 *
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>
7 *
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.
12 *
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.
17 *
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.
22 */
23
24 #ifdef HAVE_CONFIG_H
25 #include "config.h"
26 #endif
27
28 #ifdef HAVE_VALGRIND
29 # include <valgrind/valgrind.h>
30 #endif
31
32 #include <gst/check/gstcheck.h>
33
34 #include <gst/video/video.h>
35 #include <gst/video/gstvideometa.h>
36 #include <gst/video/video-overlay-composition.h>
37 #include <string.h>
38
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
41 * end up the same */
42
43 typedef struct paintinfo_struct paintinfo;
44 struct paintinfo_struct
45 {
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 */
51 int ystride;
52 int ustride;
53 int vstride;
54 int width;
55 int height;
56 };
57
58 struct fourcc_list_struct
59 {
60 const char *fourcc;
61 const char *name;
62 int bitspp;
63 void (*paint_setup) (paintinfo * p, unsigned char *dest);
64 };
65
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);
76
77 #if 0
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);
82 #endif
83 static void paint_setup_YUV9 (paintinfo * p, unsigned char *dest);
84 static void paint_setup_YVU9 (paintinfo * p, unsigned char *dest);
85
86 int fourcc_get_size (struct fourcc_list_struct *fourcc, int w, int h);
87
88 struct fourcc_list_struct fourcc_list[] = {
89 /* packed */
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},
96
97 /* interlaced */
98 /*{ "IUYV", "IUY2", 16, paint_setup_YVYU }, */
99
100 /* inverted */
101 /*{ "cyuv", "cyuv", 16, paint_setup_YVYU }, */
102
103 /*{ "Y41P", "Y41P", 12, paint_setup_YVYU }, */
104
105 /* interlaced */
106 /*{ "IY41", "IY41", 12, paint_setup_YVYU }, */
107
108 /*{ "Y211", "Y211", 8, paint_setup_YVYU }, */
109
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},
115
116 /* planar */
117 /* YVU9 */
118 {"YVU9", "YVU9", 9, paint_setup_YVU9},
119 /* YUV9 */
120 {"YUV9", "YUV9", 9, paint_setup_YUV9},
121 /* IF09 */
122 /* YV12 */
123 {"YV12", "YV12", 12, paint_setup_YV12},
124 /* I420 */
125 {"I420", "I420", 12, paint_setup_I420},
126 /* NV12 */
127 /* NV21 */
128 #if 0
129 /* IMC1 */
130 {"IMC1", "IMC1", 16, paint_setup_IMC1},
131 /* IMC2 */
132 {"IMC2", "IMC2", 12, paint_setup_IMC2},
133 /* IMC3 */
134 {"IMC3", "IMC3", 16, paint_setup_IMC3},
135 /* IMC4 */
136 {"IMC4", "IMC4", 12, paint_setup_IMC4},
137 #endif
138 /* CLPL */
139 /* Y41B */
140 {"Y41B", "Y41B", 12, paint_setup_Y41B},
141 /* Y42B */
142 {"Y42B", "Y42B", 16, paint_setup_Y42B},
143 /* GRAY8 grayscale */
144 {"GRAY8", "GRAY8", 8, paint_setup_GRAY8}
145 };
146
147 /* returns the size in bytes for one video frame of the given dimensions
148 * given the fourcc */
149 int
fourcc_get_size(struct fourcc_list_struct * fourcc,int w,int h)150 fourcc_get_size (struct fourcc_list_struct *fourcc, int w, int h)
151 {
152 paintinfo pi = { NULL, };
153 paintinfo *p = π
154
155 p->width = w;
156 p->height = h;
157
158 fourcc->paint_setup (p, NULL);
159
160 return GPOINTER_TO_INT (p->endptr);
161 }
162
163 static void
paint_setup_I420(paintinfo * p,unsigned char * dest)164 paint_setup_I420 (paintinfo * p, unsigned char *dest)
165 {
166 p->yp = 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;
173 }
174
175 static void
paint_setup_YV12(paintinfo * p,unsigned char * dest)176 paint_setup_YV12 (paintinfo * p, unsigned char *dest)
177 {
178 p->yp = 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;
185 }
186
187 static void
paint_setup_AYUV(paintinfo * p,unsigned char * dest)188 paint_setup_AYUV (paintinfo * p, unsigned char *dest)
189 {
190 p->ap = dest;
191 p->yp = dest + 1;
192 p->up = dest + 2;
193 p->vp = dest + 3;
194 p->ystride = p->width * 4;
195 p->endptr = dest + p->ystride * p->height;
196 }
197
198 static void
paint_setup_YUY2(paintinfo * p,unsigned char * dest)199 paint_setup_YUY2 (paintinfo * p, unsigned char *dest)
200 {
201 p->yp = dest;
202 p->up = dest + 1;
203 p->vp = dest + 3;
204 p->ystride = GST_ROUND_UP_2 (p->width) * 2;
205 p->endptr = dest + p->ystride * p->height;
206 }
207
208 static void
paint_setup_UYVY(paintinfo * p,unsigned char * dest)209 paint_setup_UYVY (paintinfo * p, unsigned char *dest)
210 {
211 p->yp = dest + 1;
212 p->up = dest;
213 p->vp = dest + 2;
214 p->ystride = GST_ROUND_UP_2 (p->width) * 2;
215 p->endptr = dest + p->ystride * p->height;
216 }
217
218 static void
paint_setup_YVYU(paintinfo * p,unsigned char * dest)219 paint_setup_YVYU (paintinfo * p, unsigned char *dest)
220 {
221 p->yp = dest;
222 p->up = dest + 3;
223 p->vp = dest + 1;
224 p->ystride = GST_ROUND_UP_2 (p->width) * 2;
225 p->endptr = dest + p->ystride * p->height;
226 }
227
228 static void
paint_setup_IYU2(paintinfo * p,unsigned char * dest)229 paint_setup_IYU2 (paintinfo * p, unsigned char *dest)
230 {
231 /* untested */
232 p->yp = dest + 1;
233 p->up = dest + 0;
234 p->vp = dest + 2;
235 p->ystride = GST_ROUND_UP_4 (p->width * 3);
236 p->endptr = dest + p->ystride * p->height;
237 }
238
239 static void
paint_setup_Y41B(paintinfo * p,unsigned char * dest)240 paint_setup_Y41B (paintinfo * p, unsigned char *dest)
241 {
242 p->yp = 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;
249 }
250
251 static void
paint_setup_Y42B(paintinfo * p,unsigned char * dest)252 paint_setup_Y42B (paintinfo * p, unsigned char *dest)
253 {
254 p->yp = 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;
261 }
262
263 static void
paint_setup_GRAY8(paintinfo * p,unsigned char * dest)264 paint_setup_GRAY8 (paintinfo * p, unsigned char *dest)
265 {
266 /* untested */
267 p->yp = dest;
268 p->ystride = GST_ROUND_UP_4 (p->width);
269 p->endptr = dest + p->ystride * p->height;
270 }
271
272 #if 0
273 static void
274 paint_setup_IMC1 (paintinfo * p, unsigned char *dest)
275 {
276 p->yp = dest;
277 p->up = dest + p->width * p->height;
278 p->vp = dest + p->width * p->height + p->width * p->height / 2;
279 }
280
281 static void
282 paint_setup_IMC2 (paintinfo * p, unsigned char *dest)
283 {
284 p->yp = dest;
285 p->vp = dest + p->width * p->height;
286 p->up = dest + p->width * p->height + p->width / 2;
287 }
288
289 static void
290 paint_setup_IMC3 (paintinfo * p, unsigned char *dest)
291 {
292 p->yp = dest;
293 p->up = dest + p->width * p->height + p->width * p->height / 2;
294 p->vp = dest + p->width * p->height;
295 }
296
297 static void
298 paint_setup_IMC4 (paintinfo * p, unsigned char *dest)
299 {
300 p->yp = dest;
301 p->vp = dest + p->width * p->height + p->width / 2;
302 p->up = dest + p->width * p->height;
303 }
304 #endif
305
306 static void
paint_setup_YVU9(paintinfo * p,unsigned char * dest)307 paint_setup_YVU9 (paintinfo * p, unsigned char *dest)
308 {
309 p->yp = 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);
316 }
317
318 static void
paint_setup_YUV9(paintinfo * p,unsigned char * dest)319 paint_setup_YUV9 (paintinfo * p, unsigned char *dest)
320 {
321 p->yp = 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);
328 }
329
330 #define gst_video_format_is_packed video_format_is_packed
331 static gboolean
video_format_is_packed(GstVideoFormat fmt)332 video_format_is_packed (GstVideoFormat fmt)
333 {
334 switch (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:
342 return FALSE;
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:
361 return TRUE;
362 default:
363 g_return_val_if_reached (FALSE);
364 }
365 return FALSE;
366 }
367
368 static gint
get_num_formats(void)369 get_num_formats (void)
370 {
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)
374 --num_formats;
375 GST_INFO ("number of known video formats: %d", num_formats);
376 return num_formats + 1;
377 }
378
GST_START_TEST(test_video_formats_all)379 GST_START_TEST (test_video_formats_all)
380 {
381 GstStructure *s;
382 const GValue *val, *list_val;
383 GstCaps *caps;
384 guint num, n, num_formats;
385
386 num_formats = get_num_formats ();
387
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;
397
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);
404 }
405 /* Take into account GST_VIDEO_FORMAT_ENCODED and UNKNOWN */
406 fail_unless_equals_int (num, num_formats - 2);
407
408 gst_caps_unref (caps);
409 }
410
411 GST_END_TEST;
412
413 #define WIDTH 77
414 #define HEIGHT 20
GST_START_TEST(test_video_formats_pack_unpack)415 GST_START_TEST (test_video_formats_pack_unpack)
416 {
417 guint n, num_formats;
418
419 num_formats = get_num_formats ();
420
421 for (n = GST_VIDEO_FORMAT_ENCODED + 1; n < num_formats; ++n) {
422 const GstVideoFormatInfo *vfinfo, *unpackinfo;
423 GstVideoFormat fmt = n;
424 GstVideoInfo vinfo;
425 gpointer data[GST_VIDEO_MAX_PLANES];
426 gint stride[GST_VIDEO_MAX_PLANES];
427 guint8 *vdata, *unpack_data;
428 gsize vsize, unpack_size;
429 guint p;
430
431 GST_INFO ("testing %s", gst_video_format_to_string (fmt));
432
433 vfinfo = gst_video_format_get_info (fmt);
434 fail_unless (vfinfo != NULL);
435
436 unpackinfo = gst_video_format_get_info (vfinfo->unpack_format);
437 fail_unless (unpackinfo != NULL);
438
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);
444
445 g_assert (vfinfo->pack_lines == 1);
446
447 unpack_size =
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);
452
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);
456 }
457
458 /* now unpack */
459 vfinfo->unpack_func (vfinfo, GST_VIDEO_PACK_FLAG_NONE, unpack_data, data,
460 stride, 0, 0, WIDTH);
461
462 /* and pack */
463 vfinfo->pack_func (vfinfo, GST_VIDEO_PACK_FLAG_NONE, unpack_data,
464 unpack_size, data, stride, GST_VIDEO_CHROMA_SITE_UNKNOWN, 0, WIDTH);
465
466 /* now unpack */
467 vfinfo->unpack_func (vfinfo, GST_VIDEO_PACK_FLAG_NONE, unpack_data, data,
468 stride, 0, HEIGHT - 1, WIDTH);
469
470 /* and pack */
471 vfinfo->pack_func (vfinfo, GST_VIDEO_PACK_FLAG_NONE, unpack_data,
472 unpack_size, data, stride, GST_VIDEO_CHROMA_SITE_UNKNOWN, HEIGHT - 1,
473 WIDTH);
474
475 g_free (unpack_data);
476 g_free (vdata);
477 }
478 }
479
480 GST_END_TEST;
481 #undef WIDTH
482 #undef HEIGHT
483
GST_START_TEST(test_video_formats)484 GST_START_TEST (test_video_formats)
485 {
486 guint i;
487
488 for (i = 0; i < G_N_ELEMENTS (fourcc_list); ++i) {
489 const GstVideoFormatInfo *vf_info;
490 GstVideoFormat fmt;
491 const gchar *s;
492 guint32 fourcc;
493 guint w, h;
494
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);
498
499 if (fmt == GST_VIDEO_FORMAT_UNKNOWN) {
500 GST_DEBUG ("Unknown format %s, skipping tests", fourcc_list[i].fourcc);
501 continue;
502 }
503
504 vf_info = gst_video_format_get_info (fmt);
505 fail_unless (vf_info != NULL);
506
507 fail_unless_equals_int (GST_VIDEO_FORMAT_INFO_FORMAT (vf_info), fmt);
508
509 GST_INFO ("Fourcc %s, packed=%d", fourcc_list[i].fourcc,
510 gst_video_format_is_packed (fmt));
511
512 fail_unless (GST_VIDEO_FORMAT_INFO_IS_YUV (vf_info));
513
514 /* use any non-NULL pointer so we can compare against NULL */
515 {
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));
520 } else {
521 fail_if (GST_VIDEO_FORMAT_INFO_HAS_ALPHA (vf_info));
522 }
523 }
524
525 for (w = 1; w <= 65; ++w) {
526 for (h = 1; h <= 65; ++h) {
527 GstVideoInfo vinfo;
528 paintinfo paintinfo = { 0, };
529 guint off0, off1, off2, off3;
530 guint cs0, cs1, cs2, cs3;
531 guint size;
532
533 GST_LOG ("%s, %dx%d", fourcc_list[i].fourcc, w, h);
534
535 gst_video_info_init (&vinfo);
536 fail_unless (gst_video_info_set_format (&vinfo, fmt, w, h));
537
538 paintinfo.width = w;
539 paintinfo.height = h;
540 fourcc_list[i].paint_setup (&paintinfo, NULL);
541 fail_unless_equals_int (GST_VIDEO_INFO_COMP_STRIDE (&vinfo, 0),
542 paintinfo.ystride);
543 if (!gst_video_format_is_packed (fmt)
544 && GST_VIDEO_INFO_N_PLANES (&vinfo) <= 2) {
545 /* planar */
546 fail_unless_equals_int (GST_VIDEO_INFO_COMP_STRIDE (&vinfo, 1),
547 paintinfo.ustride);
548 fail_unless_equals_int (GST_VIDEO_INFO_COMP_STRIDE (&vinfo, 2),
549 paintinfo.vstride);
550 /* check component_width * height against offsets/size somehow? */
551 }
552
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);
557
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));
562
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));
567
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));
571
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);
578
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); */
581
582 if (!gst_video_format_is_packed (fmt))
583 fail_unless (cs0 <= off1);
584
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);
593
594 /* all components together shouldn't take up more space than size */
595 fail_unless (cs0 + cs1 + cs2 + cs3 <= size);
596 } else {
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);
600
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);
605 }
606 }
607 }
608 }
609 }
610
611 GST_END_TEST;
612
GST_START_TEST(test_video_formats_overflow)613 GST_START_TEST (test_video_formats_overflow)
614 {
615 GstVideoInfo vinfo;
616
617 gst_video_info_init (&vinfo);
618
619 fail_unless (gst_video_info_set_format (&vinfo, GST_VIDEO_FORMAT_ARGB, 32768,
620 32767));
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));
624 */
625 fail_if (gst_video_info_set_format (&vinfo, GST_VIDEO_FORMAT_ARGB, 32768,
626 32768));
627
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,
631 G_MAXINT / 2));
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,
635 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,
639 G_MAXUINT / 2));
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,
643 G_MAXUINT));
644
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,
648 1));
649
650 }
651
652 GST_END_TEST;
653
GST_START_TEST(test_video_formats_rgb)654 GST_START_TEST (test_video_formats_rgb)
655 {
656 GstVideoInfo vinfo;
657 gint width, height, framerate_n, framerate_d, par_n, par_d;
658 GstCaps *caps;
659 GstStructure *structure;
660
661 gst_video_info_init (&vinfo);
662 fail_unless (gst_video_info_set_format (&vinfo, GST_VIDEO_FORMAT_RGB, 800,
663 600));
664 vinfo.par_n = 1;
665 vinfo.par_d = 1;
666 vinfo.fps_n = 0;
667 vinfo.fps_d = 1;
668 caps = gst_video_info_to_caps (&vinfo);
669 structure = gst_caps_get_structure (caps, 0);
670
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,
674 &framerate_d));
675 fail_unless (gst_structure_get_fraction (structure, "pixel-aspect-ratio",
676 &par_n, &par_d));
677
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);
684
685 gst_caps_unref (caps);
686 }
687
688 GST_END_TEST;
689
690
GST_START_TEST(test_video_formats_rgba_large_dimension)691 GST_START_TEST (test_video_formats_rgba_large_dimension)
692 {
693 GstVideoInfo vinfo;
694 gint width, height, framerate_n, framerate_d, par_n, par_d;
695 GstCaps *caps;
696 GstStructure *structure;
697
698 gst_video_info_init (&vinfo);
699 fail_unless (gst_video_info_set_format (&vinfo, GST_VIDEO_FORMAT_RGBA, 29700,
700 21000));
701 vinfo.par_n = 1;
702 vinfo.par_d = 1;
703 vinfo.fps_n = 0;
704 vinfo.fps_d = 1;
705 caps = gst_video_info_to_caps (&vinfo);
706 structure = gst_caps_get_structure (caps, 0);
707
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,
711 &framerate_d));
712 fail_unless (gst_structure_get_fraction (structure, "pixel-aspect-ratio",
713 &par_n, &par_d));
714
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);
722
723 gst_caps_unref (caps);
724 }
725
726 GST_END_TEST;
727
GST_START_TEST(test_guess_framerate)728 GST_START_TEST (test_guess_framerate)
729 {
730 /* Check some obvious exact framerates */
731 gint fps_n, fps_d;
732 fail_unless (gst_video_guess_framerate (GST_SECOND / 24, &fps_n, &fps_d));
733 fail_unless (fps_n == 24 && fps_d == 1);
734
735 fail_unless (gst_video_guess_framerate (GST_SECOND / 30, &fps_n, &fps_d));
736 fail_unless (fps_n == 30 && fps_d == 1);
737
738 fail_unless (gst_video_guess_framerate (GST_SECOND / 25, &fps_n, &fps_d));
739 fail_unless (fps_n == 25 && fps_d == 1);
740
741 /* Some NTSC rates: */
742 fail_unless (gst_video_guess_framerate (GST_SECOND * 1001 / 30000, &fps_n,
743 &fps_d));
744 fail_unless (fps_n == 30000 && fps_d == 1001);
745
746 fail_unless (gst_video_guess_framerate (GST_SECOND * 1001 / 24000, &fps_n,
747 &fps_d));
748 fail_unless (fps_n == 24000 && fps_d == 1001);
749
750 fail_unless (gst_video_guess_framerate (GST_SECOND * 1001 / 60000, &fps_n,
751 &fps_d));
752 fail_unless (fps_n == 60000 && fps_d == 1001);
753
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);
765 }
766
767 GST_END_TEST;
768
GST_START_TEST(test_dar_calc)769 GST_START_TEST (test_dar_calc)
770 {
771 guint display_ratio_n, display_ratio_d;
772
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);
778
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);
783
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);
789 }
790
791 GST_END_TEST;
792
GST_START_TEST(test_parse_caps_rgb)793 GST_START_TEST (test_parse_caps_rgb)
794 {
795 struct
796 {
797 const gchar *tmpl_caps_string;
798 GstVideoFormat fmt;
799 } formats[] = {
800 /* 24 bit */
801 {
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) */
805 {
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) */
811 {
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},
816 /* 16 bit */
817 {
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}
822 };
823 gint i;
824
825 for (i = 0; i < G_N_ELEMENTS (formats); ++i) {
826 GstVideoInfo vinfo;
827 GstCaps *caps, *caps2;
828
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));
840
841 GST_DEBUG ("testing caps: %" GST_PTR_FORMAT, caps);
842
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);
848
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);
856 g_free (caps1s);
857 g_free (caps2s);
858 }
859
860 gst_caps_unref (caps);
861 gst_caps_unref (caps2);
862 }
863 }
864
865 GST_END_TEST;
866
GST_START_TEST(test_parse_caps_multiview)867 GST_START_TEST (test_parse_caps_multiview)
868 {
869 gint i, j;
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,
883 };
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
896 };
897
898 for (i = 0; i < G_N_ELEMENTS (modes); i++) {
899 for (j = 0; j < G_N_ELEMENTS (flags); j++) {
900 GstVideoInfo vinfo;
901 GstCaps *caps;
902
903 gst_video_info_init (&vinfo);
904 fail_unless (gst_video_info_set_format (&vinfo, GST_VIDEO_FORMAT_I420,
905 320, 240));
906
907 GST_VIDEO_INFO_MULTIVIEW_MODE (&vinfo) = modes[i];
908 GST_VIDEO_INFO_MULTIVIEW_FLAGS (&vinfo) = flags[j];
909
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);
914
915 fail_unless (gst_video_info_from_caps (&vinfo, caps));
916
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));
920
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));
927
928 gst_caps_unref (caps);
929 }
930 }
931 }
932
933 GST_END_TEST;
934
935 typedef struct
936 {
937 const gchar *string_from;
938 const gchar *string_to;
939 const gchar *name;
940 GstVideoColorimetry color;
941 } ColorimetryTest;
942
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 } }
946
GST_START_TEST(test_parse_colorimetry)947 GST_START_TEST (test_parse_colorimetry)
948 {
949 ColorimetryTest tests[] = {
950 MAKE_COLORIMETRY_TEST ("bt601", "bt601", "bt601",
951 _16_235, BT601, BT709, SMPTE170M),
952 MAKE_COLORIMETRY_TEST ("2:4:5:4", "bt601", "bt601",
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),
964 };
965 gint i;
966
967 for (i = 0; i < G_N_ELEMENTS (tests); i++) {
968 const ColorimetryTest *test = &tests[i];
969 GstVideoColorimetry color;
970 gchar *string;
971
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);
977
978 string = gst_video_colorimetry_to_string (&color);
979 fail_unless_equals_string (string, test->string_to);
980 g_free (string);
981
982 fail_unless (gst_video_colorimetry_is_equal (&color, &test->color));
983
984 if (test->name)
985 fail_unless (gst_video_colorimetry_matches (&color, test->name));
986 }
987 }
988
989 GST_END_TEST;
990
GST_START_TEST(test_events)991 GST_START_TEST (test_events)
992 {
993 GstEvent *e;
994 gboolean in_still;
995
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);
1004
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);
1013 }
1014
1015 GST_END_TEST;
1016
GST_START_TEST(test_convert_frame)1017 GST_START_TEST (test_convert_frame)
1018 {
1019 GstVideoInfo vinfo;
1020 GstCaps *from_caps, *to_caps;
1021 GstBuffer *from_buffer;
1022 GstSample *from_sample, *to_sample;
1023 GError *error = NULL;
1024 gint i;
1025 GstMapInfo map;
1026
1027 gst_debug_set_threshold_for_name ("default", GST_LEVEL_NONE);
1028
1029 from_buffer = gst_buffer_new_and_alloc (640 * 480 * 4);
1030
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 */
1037 }
1038 gst_buffer_unmap (from_buffer, &map);
1039
1040 gst_video_info_init (&vinfo);
1041 fail_unless (gst_video_info_set_format (&vinfo, GST_VIDEO_FORMAT_xRGB, 640,
1042 480));
1043 vinfo.fps_n = 25;
1044 vinfo.fps_d = 1;
1045 vinfo.par_n = 1;
1046 vinfo.par_d = 1;
1047 from_caps = gst_video_info_to_caps (&vinfo);
1048
1049 from_sample = gst_sample_new (from_buffer, from_caps, NULL, NULL);
1050
1051 to_caps =
1052 gst_caps_from_string
1053 ("something/that, does=(string)not, exist=(boolean)FALSE");
1054
1055 to_sample =
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);
1061 error = NULL;
1062
1063 gst_caps_unref (to_caps);
1064 fail_unless (gst_video_info_set_format (&vinfo, GST_VIDEO_FORMAT_I420, 240,
1065 320));
1066 vinfo.fps_n = 25;
1067 vinfo.fps_d = 1;
1068 vinfo.par_n = 1;
1069 vinfo.par_d = 2;
1070 to_caps = gst_video_info_to_caps (&vinfo);
1071
1072 to_sample =
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);
1077
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);
1083 }
1084
1085 GST_END_TEST;
1086
1087 typedef struct
1088 {
1089 GMainLoop *loop;
1090 GstSample *sample;
1091 GError *error;
1092 } ConvertFrameContext;
1093
1094 static void
convert_sample_async_callback(GstSample * sample,GError * err,ConvertFrameContext * cf_data)1095 convert_sample_async_callback (GstSample * sample, GError * err,
1096 ConvertFrameContext * cf_data)
1097 {
1098 cf_data->sample = sample;
1099 cf_data->error = err;
1100
1101 g_main_loop_quit (cf_data->loop);
1102 }
1103
GST_START_TEST(test_convert_frame_async)1104 GST_START_TEST (test_convert_frame_async)
1105 {
1106 GstVideoInfo vinfo;
1107 GstCaps *from_caps, *to_caps;
1108 GstBuffer *from_buffer;
1109 GstSample *from_sample;
1110 gint i;
1111 GstMapInfo map;
1112 GMainLoop *loop;
1113 ConvertFrameContext cf_data = { NULL, NULL, NULL };
1114
1115 gst_debug_set_threshold_for_name ("default", GST_LEVEL_NONE);
1116
1117 from_buffer = gst_buffer_new_and_alloc (640 * 480 * 4);
1118
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 */
1125 }
1126 gst_buffer_unmap (from_buffer, &map);
1127
1128 loop = cf_data.loop = g_main_loop_new (NULL, FALSE);
1129
1130 gst_video_info_init (&vinfo);
1131 fail_unless (gst_video_info_set_format (&vinfo, GST_VIDEO_FORMAT_xRGB, 640,
1132 470));
1133 vinfo.par_n = 1;
1134 vinfo.par_d = 1;
1135 vinfo.fps_n = 25;
1136 vinfo.fps_d = 1;
1137 from_caps = gst_video_info_to_caps (&vinfo);
1138
1139 from_sample = gst_sample_new (from_buffer, from_caps, NULL, NULL);
1140 gst_buffer_unref (from_buffer);
1141 gst_caps_unref (from_caps);
1142
1143 gst_video_info_init (&vinfo);
1144 fail_unless (gst_video_info_set_format (&vinfo, GST_VIDEO_FORMAT_I420, 240,
1145 320));
1146 vinfo.par_n = 1;
1147 vinfo.par_d = 2;
1148 vinfo.fps_n = 25;
1149 vinfo.fps_d = 1;
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,
1154 NULL);
1155 g_main_loop_run (loop);
1156 fail_unless (cf_data.sample != NULL);
1157 fail_unless (cf_data.error == NULL);
1158
1159 gst_sample_unref (cf_data.sample);
1160 gst_caps_unref (to_caps);
1161 gst_sample_unref (from_sample);
1162
1163 g_main_loop_unref (loop);
1164 }
1165
1166 GST_END_TEST;
1167
GST_START_TEST(test_convert_frame_async_error)1168 GST_START_TEST (test_convert_frame_async_error)
1169 {
1170 GstVideoInfo vinfo;
1171 GstCaps *from_caps, *to_caps;
1172 GstBuffer *from_buffer;
1173 GstSample *from_sample;
1174 gint i;
1175 GstMapInfo map;
1176 GMainLoop *loop;
1177 ConvertFrameContext cf_data = { NULL, NULL, NULL };
1178
1179 gst_debug_set_threshold_for_name ("default", GST_LEVEL_NONE);
1180
1181 from_buffer = gst_buffer_new_and_alloc (640 * 480 * 4);
1182
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 */
1189 }
1190 gst_buffer_unmap (from_buffer, &map);
1191
1192 gst_video_info_init (&vinfo);
1193 fail_unless (gst_video_info_set_format (&vinfo, GST_VIDEO_FORMAT_xRGB, 640,
1194 470));
1195 vinfo.par_n = 1;
1196 vinfo.par_d = 1;
1197 vinfo.fps_n = 25;
1198 vinfo.fps_d = 1;
1199 from_caps = gst_video_info_to_caps (&vinfo);
1200
1201 to_caps =
1202 gst_caps_from_string
1203 ("something/that, does=(string)not, exist=(boolean)FALSE");
1204
1205 loop = cf_data.loop = g_main_loop_new (NULL, FALSE);
1206
1207 from_sample = gst_sample_new (from_buffer, from_caps, NULL, NULL);
1208 gst_buffer_unref (from_buffer);
1209 gst_caps_unref (from_caps);
1210
1211 gst_video_convert_sample_async (from_sample, to_caps,
1212 GST_CLOCK_TIME_NONE,
1213 (GstVideoConvertSampleCallback) convert_sample_async_callback, &cf_data,
1214 NULL);
1215
1216 g_main_loop_run (loop);
1217
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;
1222
1223 gst_caps_unref (to_caps);
1224 gst_sample_unref (from_sample);
1225
1226 g_main_loop_unref (loop);
1227 }
1228
1229 GST_END_TEST;
1230
GST_START_TEST(test_video_size_from_caps)1231 GST_START_TEST (test_video_size_from_caps)
1232 {
1233 GstVideoInfo vinfo;
1234 GstCaps *caps;
1235
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);
1240
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));
1244
1245 gst_caps_unref (caps);
1246 }
1247
1248 GST_END_TEST;
1249
GST_START_TEST(test_interlace_mode)1250 GST_START_TEST (test_interlace_mode)
1251 {
1252 GstVideoInfo vinfo;
1253 GstCaps *caps;
1254 GstStructure *structure;
1255 GstCapsFeatures *features;
1256 const char *mode_str, *order_str;
1257 int mode;
1258 GstVideoFieldOrder order;
1259
1260 gst_video_info_init (&vinfo);
1261
1262 /* Progressive */
1263 fail_unless (gst_video_info_set_interlaced_format (&vinfo,
1264 GST_VIDEO_FORMAT_YV12, GST_VIDEO_INTERLACE_MODE_PROGRESSIVE, 320,
1265 240));
1266 fail_unless (GST_VIDEO_INFO_SIZE (&vinfo) == 115200);
1267
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);
1275
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);
1280
1281 gst_caps_unref (caps);
1282
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;
1288
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));
1303
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);
1310
1311 gst_caps_unref (caps);
1312
1313 /* gst_video_info_from_caps() fails if an alternate stream doesn't contain
1314 * the caps feature. */
1315 caps =
1316 gst_caps_from_string
1317 ("video/x-raw, format=NV12, width=320, height=240, interlace-mode=alternate");
1318 fail_unless (caps);
1319
1320 fail_if (gst_video_info_from_caps (&vinfo, caps));
1321 gst_caps_unref (caps);
1322
1323 /* ... but it's ok for encoded video */
1324 caps =
1325 gst_caps_from_string
1326 ("video/x-h265, width=320, height=240, interlace-mode=alternate");
1327 fail_unless (caps);
1328
1329 fail_unless (gst_video_info_from_caps (&vinfo, caps));
1330 gst_caps_unref (caps);
1331 }
1332
1333 GST_END_TEST;
1334
GST_START_TEST(test_overlay_composition)1335 GST_START_TEST (test_overlay_composition)
1336 {
1337 GstVideoOverlayComposition *comp1, *comp2;
1338 GstVideoOverlayRectangle *rect1, *rect2;
1339 GstVideoOverlayCompositionMeta *ometa;
1340 GstBuffer *pix1, *pix2, *buf;
1341 GstVideoMeta *vmeta;
1342 guint seq1, seq2;
1343 guint w, h, stride;
1344 gint x, y;
1345 guint8 val;
1346
1347 pix1 = gst_buffer_new_and_alloc (200 * sizeof (guint32) * 50);
1348 gst_buffer_memset (pix1, 0, 0, gst_buffer_get_size (pix1));
1349
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);
1354
1355 gst_buffer_unref (pix1);
1356 pix1 = NULL;
1357
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);
1362
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);
1367
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,
1370 600, 300, 50));
1371
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);
1375
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);
1380
1381 fail_unless (seq1 < gst_video_overlay_composition_get_seqnum (comp2));
1382 fail_unless (seq2 < gst_video_overlay_composition_get_seqnum (comp2));
1383
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,
1386 0, 1, 1));
1387
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);
1392
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);
1398
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);
1403
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);
1410
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);
1414 stride = 4 * w;
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);
1420
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);
1426
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);
1430 stride = 4 * w;
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);
1436
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);
1441
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);
1458
1459 vmeta = gst_buffer_get_video_meta (pix1);
1460 fail_unless (vmeta != NULL);
1461 w = vmeta->width;
1462 h = vmeta->height;
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);
1470
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);
1476
1477 vmeta = gst_buffer_get_video_meta (pix2);
1478 fail_unless (vmeta != NULL);
1479 w = vmeta->width;
1480 h = vmeta->height;
1481
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);
1486 stride = 4 * w;
1487
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);
1494
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);
1498
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,
1505 comp1));
1506 }
1507 #endif
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);
1519
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);
1523
1524 gst_video_overlay_composition_unref (comp2);
1525 gst_video_overlay_composition_unref (comp1);
1526 }
1527
1528 GST_END_TEST;
1529
GST_START_TEST(test_overlay_composition_premultiplied_alpha)1530 GST_START_TEST (test_overlay_composition_premultiplied_alpha)
1531 {
1532 GstVideoOverlayRectangle *rect1;
1533 GstVideoMeta *vmeta;
1534 GstBuffer *pix1, *pix2, *pix3, *pix4, *pix5;
1535 GstBuffer *pix6, *pix7, *pix8, *pix9, *pix10;
1536 guint8 *data5, *data7;
1537 guint w, h, w2, h2;
1538 GstMapInfo map;
1539
1540 pix1 = gst_buffer_new_and_alloc (200 * sizeof (guint32) * 50);
1541 gst_buffer_memset (pix1, 0, 0x80, gst_buffer_get_size (pix1));
1542
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);
1548
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);
1553
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);
1558
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);
1563
1564 /* just to update the vars */
1565 pix2 = gst_video_overlay_rectangle_get_pixels_unscaled_raw (rect1,
1566 GST_VIDEO_OVERLAY_FORMAT_FLAG_NONE);
1567
1568 vmeta = gst_buffer_get_video_meta (pix2);
1569 fail_unless (vmeta != NULL);
1570 w = vmeta->width;
1571 h = vmeta->height;
1572
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);
1579 w2 = vmeta->width;
1580 h2 = vmeta->height;
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) */
1588 data5 = map.data;
1589 #if G_BYTE_ORDER == G_LITTLE_ENDIAN
1590 /* B - G - R - A */
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);
1595 #else
1596 /* A - R - G - B */
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);
1601 #endif
1602 gst_buffer_unmap (pix5, &map);
1603
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);
1609
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);
1614
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);
1619
1620 gst_buffer_map (pix7, &map, GST_MAP_READ);
1621 data7 = map.data;
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
1625 /* B - G - R - A */
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);
1630 #else
1631 /* A - R - G - B */
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);
1636 #endif
1637 gst_buffer_unmap (pix7, &map);
1638
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);
1643
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);
1651
1652 gst_video_overlay_rectangle_unref (rect1);
1653 }
1654
1655 GST_END_TEST;
1656
GST_START_TEST(test_overlay_composition_global_alpha)1657 GST_START_TEST (test_overlay_composition_global_alpha)
1658 {
1659 GstVideoOverlayRectangle *rect1;
1660 GstBuffer *pix1, *pix2, *pix3, *pix4, *pix5;
1661 GstVideoMeta *vmeta;
1662 guint8 *data2, *data4, *data5;
1663 guint w, h, w4, h4;
1664 guint seq1, seq2;
1665 gfloat ga1, ga2;
1666 GstVideoOverlayFormatFlags flags1;
1667 GstMapInfo map;
1668
1669 pix1 = gst_buffer_new_and_alloc (200 * sizeof (guint32) * 50);
1670 gst_buffer_memset (pix1, 0, 0x80, gst_buffer_get_size (pix1));
1671
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);
1677
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);
1682
1683 vmeta = gst_buffer_get_video_meta (pix2);
1684 fail_unless (vmeta != NULL);
1685 w = vmeta->width;
1686 h = vmeta->height;
1687
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);
1692
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);
1699 w4 = vmeta->width;
1700 h4 = vmeta->height;
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) */
1708 data4 = map.data;
1709 #if G_BYTE_ORDER == G_LITTLE_ENDIAN
1710 /* B - G - R - A */
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);
1715 #else
1716 /* A - R - G - B */
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);
1721 #endif
1722 gst_buffer_unmap (pix4, &map);
1723
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) */
1735 data5 = map.data;
1736 #if G_BYTE_ORDER == G_LITTLE_ENDIAN
1737 /* B - G - R - A */
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);
1742 #else
1743 /* A - R - G - B */
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);
1748 #endif
1749 gst_buffer_unmap (pix5, &map);
1750
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);
1754
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);
1760
1761 /* seqnum should have changed */
1762 seq2 = gst_video_overlay_rectangle_get_seqnum (rect1);
1763 fail_unless (seq1 < seq2);
1764
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);
1768
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);
1776 data2 = map.data;
1777 #if G_BYTE_ORDER == G_LITTLE_ENDIAN
1778 /* B - G - R - A */
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);
1783 #else
1784 /* A - R - G - B */
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);
1789 #endif
1790 gst_buffer_unmap (pix2, &map);
1791
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);
1798 data2 = map.data;
1799 /* make sure we got the initial data with adjusted alpha-channel */
1800 #if G_BYTE_ORDER == G_LITTLE_ENDIAN
1801 /* B - G - R - A */
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);
1806 #else
1807 /* A - R - G - B */
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);
1812 #endif
1813 gst_buffer_unmap (pix2, &map);
1814
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);
1825 data2 = map.data;
1826 #if G_BYTE_ORDER == G_LITTLE_ENDIAN
1827 /* B - G - R - A */
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);
1832 #else
1833 /* A - R - G - B */
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);
1838 #endif
1839 gst_buffer_unmap (pix2, &map);
1840
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);
1848 data2 = map.data;
1849 #if G_BYTE_ORDER == G_LITTLE_ENDIAN
1850 /* B - G - R - A */
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);
1855 #else
1856 /* A - R - G - B */
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);
1861 #endif
1862 gst_buffer_unmap (pix2, &map);
1863
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);
1872 data2 = map.data;
1873 #if G_BYTE_ORDER == G_LITTLE_ENDIAN
1874 /* B - G - R - A */
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);
1879 #else
1880 /* A - R - G - B */
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);
1885 #endif
1886 gst_buffer_unmap (pix2, &map);
1887
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);
1896 data2 = map.data;
1897 #if G_BYTE_ORDER == G_LITTLE_ENDIAN
1898 /* B - G - R - A */
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);
1903 #else
1904 /* A - R - G - B */
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);
1909 #endif
1910 gst_buffer_unmap (pix2, &map);
1911
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);
1922 data2 = map.data;
1923 #if G_BYTE_ORDER == G_LITTLE_ENDIAN
1924 /* B - G - R - A */
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);
1929 #else
1930 /* A - R - G - B */
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);
1935 #endif
1936 gst_buffer_unmap (pix2, &map);
1937
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);
1950 data2 = map.data;
1951 #if G_BYTE_ORDER == G_LITTLE_ENDIAN
1952 /* B - G - R - A */
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);
1957 #else
1958 /* A - R - G - B */
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);
1963 #endif
1964 gst_buffer_unmap (pix2, &map);
1965
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);
1980 data2 = map.data;
1981 #if G_BYTE_ORDER == G_LITTLE_ENDIAN
1982 /* B - G - R - A */
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);
1987 #else
1988 /* A - R - G - B */
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);
1993 #endif
1994 gst_buffer_unmap (pix2, &map);
1995
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);
2006 data2 = map.data;
2007 #if G_BYTE_ORDER == G_LITTLE_ENDIAN
2008 /* B - G - R - A */
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);
2013 #else
2014 /* A - R - G - B */
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);
2019 #endif
2020 gst_buffer_unmap (pix2, &map);
2021
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);
2030 data2 = map.data;
2031 #if G_BYTE_ORDER == G_LITTLE_ENDIAN
2032 /* B - G - R - A */
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);
2037 #else
2038 /* A - R - G - B */
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);
2043 #endif
2044 gst_buffer_unmap (pix2, &map);
2045
2046 gst_video_overlay_rectangle_unref (rect1);
2047 }
2048
2049 GST_END_TEST;
2050
2051 static guint8 *
make_pixels(gint depth,gint width,gint height)2052 make_pixels (gint depth, gint width, gint height)
2053 {
2054 guint32 color = 0xff000000;
2055 gint i, j;
2056
2057 if (depth == 8) {
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);
2065 color++;
2066 }
2067 }
2068 return pixels;
2069 } else {
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);
2078 color++;
2079 }
2080 }
2081 #undef TO16
2082 return (guint8 *) pixels;
2083 }
2084 }
2085
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])
2090 static gint
compare_frame(const GstVideoFormatInfo * finfo,gint depth,guint8 * outpixels,guint8 * pixels,gint width,gint height)2091 compare_frame (const GstVideoFormatInfo * finfo, gint depth, guint8 * outpixels,
2092 guint8 * pixels, gint width, gint height)
2093 {
2094 gint diff, i, j, k;
2095 guint ws[4], hs[4], mask[4];
2096
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]);
2101 }
2102 diff = 0;
2103 if (depth == 8) {
2104 guint8 *in = pixels;
2105 guint8 *out = outpixels;
2106
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);
2111 }
2112 }
2113 }
2114 } else {
2115 guint16 *in = (guint16 *) pixels;
2116 guint16 *out = (guint16 *) outpixels;
2117
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);
2122 }
2123 }
2124 }
2125 }
2126 return diff;
2127 }
2128
2129 #undef WS
2130 #undef HS
2131 #undef IN
2132 #undef OUT
2133
2134 typedef struct
2135 {
2136 GstVideoFormat infmt;
2137 GstVideoFormat outfmt;
2138 gint method;
2139 gdouble convert_sec;
2140 } ConvertResult;
2141
2142 #define SIGN(a,b) ((a) < (b) ? -1 : (a) > (b) ? 1 : 0)
2143
2144 static gint
compare_result(gconstpointer a,gconstpointer b)2145 compare_result (gconstpointer a, gconstpointer b)
2146 {
2147 const ConvertResult *ap = a;
2148 const ConvertResult *bp = b;
2149
2150 return SIGN (ap->convert_sec, bp->convert_sec);
2151 }
2152
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, \
2159 line, width)
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);
2167
GST_START_TEST(test_video_pack_unpack2)2168 GST_START_TEST (test_video_pack_unpack2)
2169 {
2170 GstVideoFormat format;
2171 GTimer *timer;
2172 gint num_formats, i;
2173 GArray *packarray, *unpackarray;
2174
2175 #define WIDTH 320
2176 #define HEIGHT 240
2177 /* set to something larger to do benchmarks */
2178 #define TIME 0.01
2179
2180 timer = g_timer_new ();
2181 packarray = g_array_new (FALSE, FALSE, sizeof (ConvertResult));
2182 unpackarray = g_array_new (FALSE, FALSE, sizeof (ConvertResult));
2183
2184 num_formats = get_num_formats ();
2185
2186 GST_DEBUG ("pack/sec\t unpack/sec \tpack GB/sec\tunpack GB/sec\tformat");
2187
2188 for (format = GST_VIDEO_FORMAT_I420; format < num_formats; format++) {
2189 GstVideoInfo info;
2190 const GstVideoFormatInfo *finfo, *fuinfo;
2191 GstBuffer *buffer;
2192 GstVideoFrame frame;
2193 gint k, stride, count, diff, depth;
2194 guint8 *pixels, *outpixels;
2195 gdouble elapsed;
2196 gdouble unpack_sec, pack_sec;
2197 ConvertResult res;
2198
2199 finfo = gst_video_format_get_info (format);
2200 fail_unless (finfo != NULL);
2201
2202 if (GST_VIDEO_FORMAT_INFO_HAS_PALETTE (finfo))
2203 continue;
2204
2205 fuinfo = gst_video_format_get_info (finfo->unpack_format);
2206 fail_unless (fuinfo != NULL);
2207
2208 depth = GST_VIDEO_FORMAT_INFO_BITS (fuinfo);
2209 fail_unless (depth == 8 || depth == 16);
2210
2211 pixels = make_pixels (depth, WIDTH, HEIGHT);
2212 stride = WIDTH * (depth >> 1);
2213
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);
2217
2218 /* pack the frame into the target format */
2219 /* warmup */
2220 PACK_FRAME (&frame, pixels, 0, WIDTH);
2221
2222 count = 0;
2223 g_timer_start (timer);
2224 while (TRUE) {
2225 for (k = 0; k < HEIGHT; k += finfo->pack_lines) {
2226 PACK_FRAME (&frame, pixels + k * stride, k, WIDTH);
2227 }
2228 count++;
2229 elapsed = g_timer_elapsed (timer, NULL);
2230 if (elapsed >= TIME)
2231 break;
2232 }
2233 unpack_sec = count / elapsed;
2234
2235 res.infmt = format;
2236 res.outfmt = finfo->unpack_format;
2237 res.convert_sec = unpack_sec;
2238 g_array_append_val (unpackarray, res);
2239
2240 outpixels = g_malloc0 (HEIGHT * stride);
2241
2242 /* unpack the frame */
2243 /* warmup */
2244 UNPACK_FRAME (&frame, outpixels, 0, 0, WIDTH);
2245
2246 count = 0;
2247 g_timer_start (timer);
2248 while (TRUE) {
2249 for (k = 0; k < HEIGHT; k += finfo->pack_lines) {
2250 UNPACK_FRAME (&frame, outpixels + k * stride, k, 0, WIDTH);
2251 }
2252 count++;
2253 elapsed = g_timer_elapsed (timer, NULL);
2254 if (elapsed >= TIME)
2255 break;
2256 }
2257 pack_sec = count / elapsed;
2258
2259 res.outfmt = format;
2260 res.infmt = finfo->unpack_format;
2261 res.convert_sec = pack_sec;
2262 g_array_append_val (packarray, res);
2263
2264 /* compare the frame */
2265 diff = compare_frame (finfo, depth, outpixels, pixels, WIDTH, HEIGHT);
2266
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,
2269 elapsed);
2270
2271 if (diff != 0) {
2272 gst_util_dump_mem (outpixels, 128);
2273 gst_util_dump_mem (pixels, 128);
2274 fail_if (diff != 0);
2275 }
2276 gst_video_frame_unmap (&frame);
2277 gst_buffer_unref (buffer);
2278 g_free (pixels);
2279 g_free (outpixels);
2280 }
2281
2282 g_array_sort (packarray, compare_result);
2283 for (i = 0; i < packarray->len; i++) {
2284 ConvertResult *res = &g_array_index (packarray, ConvertResult, i);
2285
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));
2289 }
2290
2291 g_array_sort (unpackarray, compare_result);
2292 for (i = 0; i < unpackarray->len; i++) {
2293 ConvertResult *res = &g_array_index (unpackarray, ConvertResult, i);
2294
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));
2298 }
2299
2300 g_timer_destroy (timer);
2301 g_array_free (packarray, TRUE);
2302 g_array_free (unpackarray, TRUE);
2303 }
2304
2305 GST_END_TEST;
2306 #undef WIDTH
2307 #undef HEIGHT
2308 #undef TIME
2309
2310 #define WIDTH 320
2311 #define HEIGHT 240
2312 #define TIME 0.1
2313 #define GET_LINE(l) (pixels + CLAMP (l, 0, HEIGHT-1) * WIDTH * 4)
GST_START_TEST(test_video_chroma)2314 GST_START_TEST (test_video_chroma)
2315 {
2316 guint8 *pixels;
2317 guint n_lines;
2318 gint i, j, k, offset, count;
2319 gpointer lines[10];
2320 GTimer *timer;
2321 gdouble elapsed, subsample_sec;
2322 GstVideoChromaSite sites[] = {
2323 GST_VIDEO_CHROMA_SITE_NONE,
2324 GST_VIDEO_CHROMA_SITE_H_COSITED,
2325 };
2326
2327 timer = g_timer_new ();
2328 pixels = make_pixels (8, WIDTH, HEIGHT);
2329
2330 for (k = 0; k < G_N_ELEMENTS (sites); k++) {
2331 GstVideoChromaResample *resample;
2332
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);
2335
2336 gst_video_chroma_resample_get_info (resample, &n_lines, &offset);
2337 fail_unless (n_lines < 10);
2338
2339 /* warmup */
2340 for (j = 0; j < n_lines; j++)
2341 lines[j] = GET_LINE (offset + j);
2342 gst_video_chroma_resample (resample, lines, WIDTH);
2343
2344 count = 0;
2345 g_timer_start (timer);
2346 while (TRUE) {
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);
2350
2351 gst_video_chroma_resample (resample, lines, WIDTH);
2352 }
2353 count++;
2354 elapsed = g_timer_elapsed (timer, NULL);
2355 if (elapsed >= TIME)
2356 break;
2357 }
2358 subsample_sec = count / elapsed;
2359 GST_DEBUG ("%f downsamples/sec %d/%f", subsample_sec, count, elapsed);
2360 gst_video_chroma_resample_free (resample);
2361
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);
2364
2365 gst_video_chroma_resample_get_info (resample, &n_lines, &offset);
2366 fail_unless (n_lines < 10);
2367
2368 /* warmup */
2369 for (j = 0; j < n_lines; j++)
2370 lines[j] = GET_LINE (offset + j);
2371 gst_video_chroma_resample (resample, lines, WIDTH);
2372
2373 count = 0;
2374 g_timer_start (timer);
2375 while (TRUE) {
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);
2379
2380 gst_video_chroma_resample (resample, lines, WIDTH);
2381 }
2382 count++;
2383 elapsed = g_timer_elapsed (timer, NULL);
2384 if (elapsed >= TIME)
2385 break;
2386 }
2387 subsample_sec = count / elapsed;
2388 GST_DEBUG ("%f upsamples/sec %d/%f", subsample_sec, count, elapsed);
2389 gst_video_chroma_resample_free (resample);
2390 }
2391
2392 g_free (pixels);
2393 g_timer_destroy (timer);
2394 }
2395
2396 GST_END_TEST;
2397 #undef WIDTH
2398 #undef HEIGHT
2399 #undef TIME
2400
GST_START_TEST(test_video_scaler)2401 GST_START_TEST (test_video_scaler)
2402 {
2403 GstVideoScaler *scale;
2404
2405 scale = gst_video_scaler_new (GST_VIDEO_RESAMPLER_METHOD_LINEAR,
2406 GST_VIDEO_SCALER_FLAG_NONE, 2, 10, 5, NULL);
2407 gst_video_scaler_free (scale);
2408
2409 scale = gst_video_scaler_new (GST_VIDEO_RESAMPLER_METHOD_LINEAR,
2410 GST_VIDEO_SCALER_FLAG_NONE, 2, 15, 5, NULL);
2411 gst_video_scaler_free (scale);
2412 }
2413
2414 GST_END_TEST;
2415
2416 typedef enum
2417 {
2418 RGB,
2419 YUV,
2420 OTHER
2421 } ColorType;
2422
2423 #define WIDTH 320
2424 #define HEIGHT 240
2425
2426 static gboolean
check_video_format_is_type(GstVideoFormat fmt,ColorType fmt_type)2427 check_video_format_is_type (GstVideoFormat fmt, ColorType fmt_type)
2428 {
2429 const GstVideoFormatInfo *info = gst_video_format_get_info (fmt);
2430 gboolean is_rgb = GST_VIDEO_FORMAT_INFO_IS_RGB (info);
2431 gboolean is_yuv = GST_VIDEO_FORMAT_INFO_IS_YUV (info);
2432
2433 switch (fmt_type) {
2434 case RGB:
2435 return is_rgb;
2436 case YUV:
2437 return is_yuv;
2438 case OTHER:
2439 break;
2440 }
2441 return !is_rgb && !is_yuv;
2442 }
2443
2444 static void
run_video_color_convert(ColorType in_type,ColorType out_type)2445 run_video_color_convert (ColorType in_type, ColorType out_type)
2446 {
2447 GstVideoFormat infmt, outfmt;
2448 gint num_formats;
2449
2450 num_formats = get_num_formats ();
2451
2452 for (infmt = GST_VIDEO_FORMAT_I420; infmt < num_formats; infmt++) {
2453 GstVideoInfo ininfo;
2454 GstVideoFrame inframe;
2455 GstBuffer *inbuffer;
2456
2457 if (!check_video_format_is_type (infmt, in_type))
2458 continue;
2459
2460 fail_unless (gst_video_info_set_format (&ininfo, infmt, WIDTH, HEIGHT));
2461 inbuffer = gst_buffer_new_and_alloc (ininfo.size);
2462 gst_buffer_memset (inbuffer, 0, 0, -1);
2463 gst_video_frame_map (&inframe, &ininfo, inbuffer, GST_MAP_READ);
2464
2465 for (outfmt = GST_VIDEO_FORMAT_I420; outfmt < num_formats; outfmt++) {
2466 GstVideoInfo outinfo;
2467 GstVideoFrame outframe;
2468 GstBuffer *outbuffer;
2469 GstVideoConverter *convert;
2470
2471 if (!check_video_format_is_type (outfmt, out_type))
2472 continue;
2473
2474 GST_LOG ("%s -> %s @ %ux%u", gst_video_format_to_string (infmt),
2475 gst_video_format_to_string (outfmt), WIDTH, HEIGHT);
2476
2477 fail_unless (gst_video_info_set_format (&outinfo, outfmt, WIDTH, HEIGHT));
2478 outbuffer = gst_buffer_new_and_alloc (outinfo.size);
2479 gst_video_frame_map (&outframe, &outinfo, outbuffer, GST_MAP_WRITE);
2480
2481 convert = gst_video_converter_new (&ininfo, &outinfo, NULL);
2482
2483 gst_video_converter_frame (convert, &inframe, &outframe);
2484
2485 gst_video_converter_free (convert);
2486
2487 gst_video_frame_unmap (&outframe);
2488 gst_buffer_unref (outbuffer);
2489 }
2490 gst_video_frame_unmap (&inframe);
2491 gst_buffer_unref (inbuffer);
2492 }
2493 }
2494
GST_START_TEST(test_video_color_convert_rgb_rgb)2495 GST_START_TEST (test_video_color_convert_rgb_rgb)
2496 {
2497 run_video_color_convert (RGB, RGB);
2498 }
2499
2500 GST_END_TEST;
2501
GST_START_TEST(test_video_color_convert_rgb_yuv)2502 GST_START_TEST (test_video_color_convert_rgb_yuv)
2503 {
2504 run_video_color_convert (RGB, YUV);
2505 }
2506
2507 GST_END_TEST;
2508
GST_START_TEST(test_video_color_convert_yuv_yuv)2509 GST_START_TEST (test_video_color_convert_yuv_yuv)
2510 {
2511 run_video_color_convert (YUV, YUV);
2512 }
2513
2514 GST_END_TEST;
2515
GST_START_TEST(test_video_color_convert_yuv_rgb)2516 GST_START_TEST (test_video_color_convert_yuv_rgb)
2517 {
2518 run_video_color_convert (YUV, RGB);
2519 }
2520
2521 GST_END_TEST;
2522
GST_START_TEST(test_video_color_convert_other)2523 GST_START_TEST (test_video_color_convert_other)
2524 {
2525 run_video_color_convert (OTHER, RGB);
2526 run_video_color_convert (RGB, OTHER);
2527 run_video_color_convert (OTHER, YUV);
2528 run_video_color_convert (YUV, OTHER);
2529 run_video_color_convert (OTHER, OTHER);
2530 }
2531
2532 GST_END_TEST;
2533 #undef WIDTH
2534 #undef HEIGHT
2535
2536 #define WIDTH_IN 320
2537 #define HEIGHT_IN 240
2538 #define WIDTH_OUT 400
2539 #define HEIGHT_OUT 300
2540 #define TIME 0.01
2541
GST_START_TEST(test_video_size_convert)2542 GST_START_TEST (test_video_size_convert)
2543 {
2544 GstVideoFormat infmt, outfmt;
2545 GTimer *timer;
2546 gint num_formats, i;
2547 GArray *array;
2548
2549 array = g_array_new (FALSE, FALSE, sizeof (ConvertResult));
2550
2551 timer = g_timer_new ();
2552
2553 num_formats = get_num_formats ();
2554
2555 for (infmt = GST_VIDEO_FORMAT_I420; infmt < num_formats; infmt++) {
2556 GstVideoInfo ininfo, outinfo;
2557 GstVideoFrame inframe, outframe;
2558 GstBuffer *inbuffer, *outbuffer;
2559 GstVideoConverter *convert;
2560 gdouble elapsed;
2561 gint count, method;
2562 ConvertResult res;
2563
2564 fail_unless (gst_video_info_set_format (&ininfo, infmt, WIDTH_IN,
2565 HEIGHT_IN));
2566 inbuffer = gst_buffer_new_and_alloc (ininfo.size);
2567 gst_buffer_memset (inbuffer, 0, 0, -1);
2568 gst_video_frame_map (&inframe, &ininfo, inbuffer, GST_MAP_READ);
2569
2570 outfmt = infmt;
2571 fail_unless (gst_video_info_set_format (&outinfo, outfmt, WIDTH_OUT,
2572 HEIGHT_OUT));
2573 outbuffer = gst_buffer_new_and_alloc (outinfo.size);
2574 gst_video_frame_map (&outframe, &outinfo, outbuffer, GST_MAP_WRITE);
2575
2576 for (method = 0; method < 4; method++) {
2577 convert = gst_video_converter_new (&ininfo, &outinfo,
2578 gst_structure_new ("options",
2579 GST_VIDEO_CONVERTER_OPT_RESAMPLER_METHOD,
2580 GST_TYPE_VIDEO_RESAMPLER_METHOD, method, NULL));
2581
2582 /* warmup */
2583 gst_video_converter_frame (convert, &inframe, &outframe);
2584
2585 count = 0;
2586 g_timer_start (timer);
2587 while (TRUE) {
2588 gst_video_converter_frame (convert, &inframe, &outframe);
2589
2590 count++;
2591 elapsed = g_timer_elapsed (timer, NULL);
2592 if (elapsed >= TIME)
2593 break;
2594 }
2595
2596 res.infmt = infmt;
2597 res.outfmt = outfmt;
2598 res.method = method;
2599 res.convert_sec = count / elapsed;
2600
2601 GST_DEBUG ("%f resize/sec %s->%s, %d, %d/%f", res.convert_sec,
2602 gst_video_format_to_string (infmt),
2603 gst_video_format_to_string (outfmt), method, count, elapsed);
2604
2605 g_array_append_val (array, res);
2606
2607 gst_video_converter_free (convert);
2608 }
2609 gst_video_frame_unmap (&outframe);
2610 gst_buffer_unref (outbuffer);
2611 gst_video_frame_unmap (&inframe);
2612 gst_buffer_unref (inbuffer);
2613 }
2614
2615 g_array_sort (array, compare_result);
2616
2617 for (i = 0; i < array->len; i++) {
2618 ConvertResult *res = &g_array_index (array, ConvertResult, i);
2619
2620 GST_DEBUG ("%f method %d, resize/sec %s->%s", res->convert_sec, res->method,
2621 gst_video_format_to_string (res->infmt),
2622 gst_video_format_to_string (res->outfmt));
2623 }
2624
2625 g_array_free (array, TRUE);
2626
2627 g_timer_destroy (timer);
2628 }
2629
2630 GST_END_TEST;
2631 #undef WIDTH
2632 #undef HEIGHT
2633
GST_START_TEST(test_video_convert)2634 GST_START_TEST (test_video_convert)
2635 {
2636 GstVideoInfo ininfo, outinfo;
2637 GstVideoFrame inframe, outframe;
2638 GstBuffer *inbuffer, *outbuffer;
2639 GstVideoConverter *convert;
2640
2641 fail_unless (gst_video_info_set_format (&ininfo, GST_VIDEO_FORMAT_ARGB, 320,
2642 240));
2643 inbuffer = gst_buffer_new_and_alloc (ininfo.size);
2644 gst_buffer_memset (inbuffer, 0, 0, -1);
2645 gst_video_frame_map (&inframe, &ininfo, inbuffer, GST_MAP_READ);
2646
2647 fail_unless (gst_video_info_set_format (&outinfo, GST_VIDEO_FORMAT_BGRx, 400,
2648 300));
2649 outbuffer = gst_buffer_new_and_alloc (outinfo.size);
2650 gst_video_frame_map (&outframe, &outinfo, outbuffer, GST_MAP_WRITE);
2651
2652 /* see that we don't reuse the source line directly because we need
2653 * to add borders to it */
2654 convert = gst_video_converter_new (&ininfo, &outinfo,
2655 gst_structure_new ("options",
2656 GST_VIDEO_CONVERTER_OPT_RESAMPLER_METHOD,
2657 GST_TYPE_VIDEO_RESAMPLER_METHOD, 3,
2658 GST_VIDEO_CONVERTER_OPT_SRC_X, G_TYPE_INT, 10,
2659 GST_VIDEO_CONVERTER_OPT_SRC_Y, G_TYPE_INT, 0,
2660 GST_VIDEO_CONVERTER_OPT_SRC_WIDTH, G_TYPE_INT, 300,
2661 GST_VIDEO_CONVERTER_OPT_SRC_HEIGHT, G_TYPE_INT, 220,
2662 GST_VIDEO_CONVERTER_OPT_DEST_X, G_TYPE_INT, 80,
2663 GST_VIDEO_CONVERTER_OPT_DEST_Y, G_TYPE_INT, 60,
2664 GST_VIDEO_CONVERTER_OPT_DEST_WIDTH, G_TYPE_INT, 300,
2665 GST_VIDEO_CONVERTER_OPT_DEST_HEIGHT, G_TYPE_INT, 220, NULL));
2666
2667 gst_video_converter_frame (convert, &inframe, &outframe);
2668 gst_video_converter_free (convert);
2669
2670 /* see that we reuse the source line directly because we need to scale
2671 * it first */
2672 convert = gst_video_converter_new (&ininfo, &outinfo,
2673 gst_structure_new ("options",
2674 GST_VIDEO_CONVERTER_OPT_RESAMPLER_METHOD,
2675 GST_TYPE_VIDEO_RESAMPLER_METHOD, 3,
2676 GST_VIDEO_CONVERTER_OPT_SRC_X, G_TYPE_INT, 10,
2677 GST_VIDEO_CONVERTER_OPT_SRC_Y, G_TYPE_INT, 0,
2678 GST_VIDEO_CONVERTER_OPT_SRC_WIDTH, G_TYPE_INT, 300,
2679 GST_VIDEO_CONVERTER_OPT_SRC_HEIGHT, G_TYPE_INT, 220,
2680 GST_VIDEO_CONVERTER_OPT_DEST_X, G_TYPE_INT, 80,
2681 GST_VIDEO_CONVERTER_OPT_DEST_Y, G_TYPE_INT, 60,
2682 GST_VIDEO_CONVERTER_OPT_DEST_WIDTH, G_TYPE_INT, 310,
2683 GST_VIDEO_CONVERTER_OPT_DEST_HEIGHT, G_TYPE_INT, 230, NULL));
2684
2685 gst_video_converter_frame (convert, &inframe, &outframe);
2686 gst_video_converter_free (convert);
2687
2688 gst_video_frame_unmap (&outframe);
2689 gst_buffer_unref (outbuffer);
2690 gst_video_frame_unmap (&inframe);
2691 gst_buffer_unref (inbuffer);
2692
2693 }
2694
2695 GST_END_TEST;
2696
GST_START_TEST(test_video_transfer)2697 GST_START_TEST (test_video_transfer)
2698 {
2699 gint i, j;
2700
2701 for (j = GST_VIDEO_TRANSFER_GAMMA10; j <= GST_VIDEO_TRANSFER_LOG316; j++) {
2702 for (i = 0; i < 256; i++) {
2703 gdouble val1, val2;
2704
2705 val1 = gst_video_color_transfer_encode (j, i / 255.0);
2706 fail_if (val1 < 0.0 || val1 > 1.0);
2707
2708 val2 = gst_video_color_transfer_decode (j, val1);
2709 fail_if (val2 < 0.0 || val2 > 1.0);
2710
2711 GST_DEBUG ("%d: %d %f->%f->%f %d", j, i, i / 255.0, val1, val2,
2712 (int) lrint (val2 * 255.0));
2713 if (val1 == 0.0)
2714 fail_if (val2 != 0.0);
2715 else
2716 fail_if (lrint (val2 * 255.0) != i);
2717 }
2718 }
2719 }
2720
2721 GST_END_TEST;
2722
GST_START_TEST(test_video_center_rect)2723 GST_START_TEST (test_video_center_rect)
2724 {
2725 GstVideoRectangle src, dest, result, expected;
2726
2727 #define NEW_RECT(x,y,w,h) ((GstVideoRectangle) {x,y,w,h})
2728 #define CHECK_RECT(res, exp) \
2729 fail_unless_equals_int(exp.x, res.x);\
2730 fail_unless_equals_int(exp.y, res.y);\
2731 fail_unless_equals_int(exp.w, res.w);\
2732 fail_unless_equals_int(exp.h, res.h);
2733
2734 /* 1:1 Aspect Ratio */
2735 src = NEW_RECT (0, 0, 100, 100);
2736 dest = NEW_RECT (0, 0, 100, 100);
2737 expected = NEW_RECT (0, 0, 100, 100);
2738 gst_video_sink_center_rect (src, dest, &result, TRUE);
2739 CHECK_RECT (result, expected);
2740
2741 src = NEW_RECT (0, 0, 100, 100);
2742 dest = NEW_RECT (0, 0, 50, 50);
2743 expected = NEW_RECT (0, 0, 50, 50);
2744 gst_video_sink_center_rect (src, dest, &result, TRUE);
2745 CHECK_RECT (result, expected);
2746
2747 src = NEW_RECT (0, 0, 100, 100);
2748 dest = NEW_RECT (50, 50, 100, 100);
2749 expected = NEW_RECT (50, 50, 100, 100);
2750 gst_video_sink_center_rect (src, dest, &result, TRUE);
2751 CHECK_RECT (result, expected);
2752
2753 /* Aspect ratio scaling (tall) */
2754 src = NEW_RECT (0, 0, 50, 100);
2755 dest = NEW_RECT (0, 0, 50, 50);
2756 expected = NEW_RECT (12, 0, 25, 50);
2757 gst_video_sink_center_rect (src, dest, &result, TRUE);
2758 CHECK_RECT (result, expected);
2759
2760 src = NEW_RECT (0, 0, 50, 100);
2761 dest = NEW_RECT (50, 50, 50, 50);
2762 expected = NEW_RECT (62, 50, 25, 50);
2763 gst_video_sink_center_rect (src, dest, &result, TRUE);
2764 CHECK_RECT (result, expected);
2765
2766 /* Aspect ratio scaling (wide) */
2767 src = NEW_RECT (0, 0, 100, 50);
2768 dest = NEW_RECT (0, 0, 50, 50);
2769 expected = NEW_RECT (0, 12, 50, 25);
2770 gst_video_sink_center_rect (src, dest, &result, TRUE);
2771 CHECK_RECT (result, expected);
2772
2773 src = NEW_RECT (0, 0, 100, 50);
2774 dest = NEW_RECT (50, 50, 50, 50);
2775 expected = NEW_RECT (50, 62, 50, 25);
2776 gst_video_sink_center_rect (src, dest, &result, TRUE);
2777 CHECK_RECT (result, expected);
2778 }
2779
2780 GST_END_TEST;
2781
2782 void test_overlay_blend_rect (gint x, gint y, gint width, gint height,
2783 GstVideoFrame * video_frame);
2784 void test_overlay_blend_rect_verify (gint x, gint y, gint width,
2785 gint height, GstVideoFrame * video_frame);
2786 #define VIDEO_WIDTH 320
2787 #define VIDEO_HEIGHT 240
2788
2789 void
test_overlay_blend_rect_verify(gint x,gint y,gint width,gint height,GstVideoFrame * video_frame)2790 test_overlay_blend_rect_verify (gint x, gint y, gint width, gint height,
2791 GstVideoFrame * video_frame)
2792 {
2793 guint8 *data;
2794 gint i = 0, prev_i = 0;
2795 gint size = 0;
2796 gint temp_width = 0, temp_height = 0;
2797
2798 data = GST_VIDEO_FRAME_PLANE_DATA (video_frame, 0);
2799 size = GST_VIDEO_FRAME_SIZE (video_frame);
2800
2801 if (x + width < 0 || y + height < 0 || x >= VIDEO_WIDTH || y >= VIDEO_HEIGHT)
2802 return;
2803 if (x <= 0)
2804 temp_width = width + x;
2805 else if (x > 0 && (x + width) <= VIDEO_WIDTH)
2806 temp_width = width;
2807 else
2808 temp_width = VIDEO_WIDTH - x;
2809 if (y <= 0)
2810 temp_height = height + y;
2811 else if (y > 0 && (y + height) <= VIDEO_HEIGHT)
2812 temp_height = height;
2813 else
2814 temp_height = VIDEO_HEIGHT - y;
2815
2816 if (x <= 0 && y <= 0)
2817 i = 0;
2818 else
2819 i = (((x <= 0) ? 0 : x) + (((y <= 0) ? 0 : y) * VIDEO_WIDTH)) * 4;
2820 prev_i = i;
2821
2822 for (; i < size - 4; i += 4) {
2823 #if G_BYTE_ORDER == G_LITTLE_ENDIAN
2824 /* B - G - R - A */
2825 fail_unless_equals_int (data[i], 0x80);
2826 fail_unless_equals_int (data[i + 1], 0x80);
2827 fail_unless_equals_int (data[i + 2], 0x80);
2828 fail_unless_equals_int (data[i + 3], 0x80);
2829 #else
2830 /* A - R - G - B */
2831 fail_unless_equals_int (data[i], 0x80);
2832 fail_unless_equals_int (data[i + 1], 0x80);
2833 fail_unless_equals_int (data[i + 2], 0x80);
2834 fail_unless_equals_int (data[i + 3], 0x80);
2835 #endif
2836 if ((i + 4) == (4 * (((((y > 0) ? (y + temp_height) : temp_height) -
2837 1) * VIDEO_WIDTH) + ((x >
2838 0) ? (x + temp_width) : temp_width))))
2839 break;
2840 if ((i + 4 - prev_i) == ((temp_width) * 4)) {
2841 i += ((VIDEO_WIDTH - (temp_width)) * 4);
2842 prev_i = i + 4;
2843 }
2844
2845 }
2846 }
2847
2848 void
test_overlay_blend_rect(gint x,gint y,gint width,gint height,GstVideoFrame * video_frame)2849 test_overlay_blend_rect (gint x, gint y, gint width, gint height,
2850 GstVideoFrame * video_frame)
2851 {
2852 GstVideoOverlayComposition *comp1;
2853 GstVideoOverlayRectangle *rect1;
2854 GstBuffer *pix, *pix1;
2855 GstVideoInfo vinfo;
2856
2857 memset (video_frame, 0, sizeof (GstVideoFrame));
2858 pix =
2859 gst_buffer_new_and_alloc (VIDEO_WIDTH * VIDEO_HEIGHT * sizeof (guint32));
2860 gst_buffer_memset (pix, 0, 0, gst_buffer_get_size (pix));
2861 gst_video_info_init (&vinfo);
2862 fail_unless (gst_video_info_set_format (&vinfo,
2863 GST_VIDEO_OVERLAY_COMPOSITION_FORMAT_RGB, VIDEO_WIDTH, VIDEO_HEIGHT));
2864 gst_video_frame_map (video_frame, &vinfo, pix, GST_MAP_READWRITE);
2865 gst_buffer_unref (pix);
2866 pix = NULL;
2867
2868 pix1 = gst_buffer_new_and_alloc (width * height * sizeof (guint32));
2869 gst_buffer_memset (pix1, 0, 0x80, gst_buffer_get_size (pix1));
2870 gst_buffer_add_video_meta (pix1, GST_VIDEO_FRAME_FLAG_NONE,
2871 GST_VIDEO_OVERLAY_COMPOSITION_FORMAT_RGB, width, height);
2872 rect1 = gst_video_overlay_rectangle_new_raw (pix1,
2873 x, y, width, height, GST_VIDEO_OVERLAY_FORMAT_FLAG_NONE);
2874 gst_buffer_unref (pix1);
2875 pix1 = NULL;
2876
2877 comp1 = gst_video_overlay_composition_new (rect1);
2878 fail_unless (gst_video_overlay_composition_blend (comp1, video_frame));
2879 gst_video_overlay_composition_unref (comp1);
2880 gst_video_overlay_rectangle_unref (rect1);
2881
2882 test_overlay_blend_rect_verify (x, y, width, height, video_frame);
2883 gst_video_frame_unmap (video_frame);
2884 }
2885
GST_START_TEST(test_overlay_blend)2886 GST_START_TEST (test_overlay_blend)
2887 {
2888 GstVideoFrame video_frame;
2889
2890 /* Overlay width & height smaller than video width & height */
2891 /* Overlay rendered completely left of video surface
2892 * x + overlay_width <= 0 */
2893 test_overlay_blend_rect (-60, 50, 50, 50, &video_frame);
2894 /* Overlay rendered completely right of video surface
2895 * x >= video_width */
2896 test_overlay_blend_rect (330, 50, 50, 50, &video_frame);
2897 /* Overlay rendered completely top of video surface
2898 * y + overlay_height <= 0 */
2899 test_overlay_blend_rect (50, -60, 50, 50, &video_frame);
2900 /* Overlay rendered completely bottom of video surface
2901 * y >= video_height */
2902 test_overlay_blend_rect (50, 250, 50, 50, &video_frame);
2903 /* Overlay rendered partially left of video surface
2904 * x < 0 && -x < overlay_width */
2905 test_overlay_blend_rect (-40, 50, 50, 50, &video_frame);
2906 /* Overlay rendered partially right of video surface
2907 * x < video_width && (overlay_width + x) > video_width */
2908 test_overlay_blend_rect (300, 50, 50, 50, &video_frame);
2909 /* Overlay rendered partially top of video surface
2910 * y < 0 && -y < overlay_height */
2911 test_overlay_blend_rect (50, -40, 50, 50, &video_frame);
2912 /* Overlay rendered partially bottom of video surface
2913 * y < video_height && (overlay_height + y) > video_height */
2914 test_overlay_blend_rect (50, 220, 50, 50, &video_frame);
2915
2916 /* Overlay width & height bigger than video width & height */
2917 /* Overlay rendered completely left of video surface
2918 * x + overlay_width <= 0 */
2919 test_overlay_blend_rect (-360, 50, 350, 250, &video_frame);
2920 /* Overlay rendered completely right of video surface
2921 * x >= video_width */
2922 test_overlay_blend_rect (330, 50, 350, 250, &video_frame);
2923 /* Overlay rendered completely top of video surface
2924 * y + overlay_height <= 0 */
2925 test_overlay_blend_rect (50, -260, 350, 250, &video_frame);
2926 /* Overlay rendered completely bottom of video surface
2927 * y >= video_height */
2928 test_overlay_blend_rect (50, 250, 350, 250, &video_frame);
2929 /* Overlay rendered partially left of video surface
2930 * x < 0 && -x < overlay_width */
2931 test_overlay_blend_rect (-40, 50, 350, 250, &video_frame);
2932 /* Overlay rendered partially right of video surface
2933 * x < video_width && (overlay_width + x) > video_width */
2934 test_overlay_blend_rect (300, 50, 350, 250, &video_frame);
2935 /* Overlay rendered partially top of video surface
2936 * y < 0 && -y < overlay_height */
2937 test_overlay_blend_rect (50, -40, 350, 250, &video_frame);
2938 /* Overlay rendered partially bottom of video surface
2939 * y < video_height && (overlay_height + y) > video_height */
2940 test_overlay_blend_rect (50, 220, 350, 250, &video_frame);
2941 }
2942
2943 GST_END_TEST;
2944
GST_START_TEST(test_overlay_composition_over_transparency)2945 GST_START_TEST (test_overlay_composition_over_transparency)
2946 {
2947 GstVideoOverlayComposition *comp1;
2948 GstVideoOverlayRectangle *rect1;
2949 GstBuffer *pix1, *pix2;
2950 GstVideoInfo vinfo;
2951 guint8 *data;
2952
2953 GstVideoFrame video_frame;
2954 guint fwidth = 200, height = 50, swidth = 100;
2955
2956 memset (&video_frame, 0, sizeof (GstVideoFrame));
2957
2958 pix1 = gst_buffer_new_and_alloc (fwidth * sizeof (guint32) * height);
2959 gst_buffer_memset (pix1, 0, 0x00, gst_buffer_get_size (pix1));
2960 gst_video_info_init (&vinfo);
2961 fail_unless (gst_video_info_set_format (&vinfo,
2962 GST_VIDEO_OVERLAY_COMPOSITION_FORMAT_RGB, fwidth, height));
2963 gst_video_frame_map (&video_frame, &vinfo, pix1, GST_MAP_READWRITE);
2964 gst_buffer_unref (pix1);
2965
2966 pix2 = gst_buffer_new_and_alloc (swidth * sizeof (guint32) * height);
2967 gst_buffer_memset (pix2, 0, 0xFF, gst_buffer_get_size (pix2));
2968 gst_buffer_add_video_meta (pix2, GST_VIDEO_FRAME_FLAG_NONE,
2969 GST_VIDEO_OVERLAY_COMPOSITION_FORMAT_RGB, swidth, height);
2970 rect1 = gst_video_overlay_rectangle_new_raw (pix2, swidth, 0,
2971 swidth, height, GST_VIDEO_OVERLAY_FORMAT_FLAG_NONE);
2972
2973 comp1 = gst_video_overlay_composition_new (rect1);
2974 fail_unless (gst_video_overlay_composition_blend (comp1, &video_frame));
2975 gst_video_overlay_composition_unref (comp1);
2976 gst_video_overlay_rectangle_unref (rect1);
2977 gst_buffer_unref (pix2);
2978
2979 data = GST_VIDEO_FRAME_PLANE_DATA (&video_frame, 0);
2980
2981 fail_unless_equals_int (data[0], 0x00);
2982 fail_unless_equals_int (data[1], 0x00);
2983 fail_unless_equals_int (data[2], 0x00);
2984 fail_unless_equals_int (data[3], 0x00);
2985
2986 data += swidth * sizeof (guint32);
2987
2988 fail_unless_equals_int (data[0], 0xFF);
2989 fail_unless_equals_int (data[1], 0xFF);
2990 fail_unless_equals_int (data[2], 0xFF);
2991 fail_unless_equals_int (data[3], 0xFF);
2992
2993 gst_video_frame_unmap (&video_frame);
2994 }
2995
2996 GST_END_TEST;
2997
GST_START_TEST(test_video_format_enum_stability)2998 GST_START_TEST (test_video_format_enum_stability)
2999 {
3000 /* When adding new formats, adding a format in the middle of the enum will
3001 * break the API. This check picks the last known format and checks that
3002 * it's value isn't changing. This test should ideall be updated when a new
3003 * format is added, though will stay valid. */
3004 fail_unless_equals_int (GST_VIDEO_FORMAT_Y210, 82);
3005 }
3006
3007 GST_END_TEST;
3008
GST_START_TEST(test_video_formats_pstrides)3009 GST_START_TEST (test_video_formats_pstrides)
3010 {
3011 GstVideoFormat fmt = GST_VIDEO_FORMAT_I420;
3012
3013
3014 while ((gst_video_format_to_string (fmt) != NULL)) {
3015 const GstVideoFormatInfo *vf_info = gst_video_format_get_info (fmt);
3016 guint n_comps = GST_VIDEO_FORMAT_INFO_N_COMPONENTS (vf_info);
3017
3018 GST_LOG ("format: %s (%d), n_comps = %u", vf_info->name, fmt, n_comps);
3019
3020 if (fmt == GST_VIDEO_FORMAT_v210
3021 || fmt == GST_VIDEO_FORMAT_UYVP
3022 || fmt == GST_VIDEO_FORMAT_IYU1
3023 || fmt == GST_VIDEO_FORMAT_GRAY10_LE32
3024 || fmt == GST_VIDEO_FORMAT_NV12_64Z32
3025 || fmt == GST_VIDEO_FORMAT_NV12_10LE32
3026 || fmt == GST_VIDEO_FORMAT_NV16_10LE32
3027 || fmt == GST_VIDEO_FORMAT_NV12_10LE40
3028 || fmt == GST_VIDEO_FORMAT_Y410) {
3029 fmt++;
3030 continue;
3031 }
3032
3033 switch (n_comps) {
3034 case 4:
3035 fail_unless (GST_VIDEO_FORMAT_INFO_PSTRIDE (vf_info, 3) > 0);
3036 /* fall through */
3037 case 3:
3038 fail_unless (GST_VIDEO_FORMAT_INFO_PSTRIDE (vf_info, 2) > 0);
3039 /* fall through */
3040 case 2:
3041 fail_unless (GST_VIDEO_FORMAT_INFO_PSTRIDE (vf_info, 1) > 0);
3042 /* fall through */
3043 case 1:
3044 fail_unless (GST_VIDEO_FORMAT_INFO_PSTRIDE (vf_info, 0) > 0);
3045 break;
3046 }
3047
3048 fmt++;
3049 }
3050 }
3051
3052 GST_END_TEST;
3053
3054 static Suite *
video_suite(void)3055 video_suite (void)
3056 {
3057 Suite *s = suite_create ("video support library");
3058 TCase *tc_chain = tcase_create ("general");
3059
3060 tcase_set_timeout (tc_chain, 60 * 60);
3061
3062 suite_add_tcase (s, tc_chain);
3063 tcase_add_test (tc_chain, test_video_formats);
3064 tcase_add_test (tc_chain, test_video_formats_overflow);
3065 tcase_add_test (tc_chain, test_video_formats_rgb);
3066 tcase_add_test (tc_chain, test_video_formats_rgba_large_dimension);
3067 tcase_add_test (tc_chain, test_video_formats_all);
3068 tcase_add_test (tc_chain, test_video_formats_pack_unpack);
3069 tcase_add_test (tc_chain, test_guess_framerate);
3070 tcase_add_test (tc_chain, test_dar_calc);
3071 tcase_add_test (tc_chain, test_parse_caps_rgb);
3072 tcase_add_test (tc_chain, test_parse_caps_multiview);
3073 tcase_add_test (tc_chain, test_parse_colorimetry);
3074 tcase_add_test (tc_chain, test_events);
3075 tcase_add_test (tc_chain, test_convert_frame);
3076 tcase_add_test (tc_chain, test_convert_frame_async);
3077 tcase_add_test (tc_chain, test_convert_frame_async_error);
3078 tcase_add_test (tc_chain, test_video_size_from_caps);
3079 tcase_add_test (tc_chain, test_interlace_mode);
3080 tcase_add_test (tc_chain, test_overlay_composition);
3081 tcase_add_test (tc_chain, test_overlay_composition_premultiplied_alpha);
3082 tcase_add_test (tc_chain, test_overlay_composition_global_alpha);
3083 tcase_add_test (tc_chain, test_video_pack_unpack2);
3084 tcase_add_test (tc_chain, test_video_chroma);
3085 tcase_add_test (tc_chain, test_video_scaler);
3086 tcase_add_test (tc_chain, test_video_color_convert_rgb_rgb);
3087 tcase_add_test (tc_chain, test_video_color_convert_rgb_yuv);
3088 tcase_add_test (tc_chain, test_video_color_convert_yuv_yuv);
3089 tcase_add_test (tc_chain, test_video_color_convert_yuv_rgb);
3090 tcase_add_test (tc_chain, test_video_color_convert_other);
3091 tcase_add_test (tc_chain, test_video_size_convert);
3092 tcase_add_test (tc_chain, test_video_convert);
3093 tcase_add_test (tc_chain, test_video_transfer);
3094 tcase_add_test (tc_chain, test_overlay_blend);
3095 tcase_add_test (tc_chain, test_video_center_rect);
3096 tcase_add_test (tc_chain, test_overlay_composition_over_transparency);
3097 tcase_add_test (tc_chain, test_video_format_enum_stability);
3098 tcase_add_test (tc_chain, test_video_formats_pstrides);
3099
3100 return s;
3101 }
3102
3103 GST_CHECK_MAIN (video);
3104