2 * Copyright (C) <1999> Erik Walthinsen <omega@cse.ogi.edu>
3 * Library <2002> Ronald Bultje <rbultje@ronald.bitfreak.net>
4 * Copyright (C) 2007 David A. Schleef <ds@schleef.org>
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Library General Public
8 * License as published by the Free Software Foundation; either
9 * version 2 of the License, or (at your option) any later version.
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Library General Public License for more details.
16 * You should have received a copy of the GNU Library General Public
17 * License along with this library; if not, write to the
18 * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
19 * Boston, MA 02111-1307, USA.
29 #include "gstmetavideo.h"
31 static int fill_planes (GstVideoInfo * info);
36 GstVideoFormatInfo info;
39 /* depths: bits, n_components, shift, depth */
40 #define DPTH0 0, 0, { 0, 0, 0, 0 }, { 0, 0, 0, 0 }
41 #define DPTH8 8, 1, { 0, 0, 0, 0 }, { 8, 0, 0, 0 }
42 #define DPTH888 8, 3, { 0, 0, 0, 0 }, { 8, 8, 8, 0 }
43 #define DPTH8888 8, 4, { 0, 0, 0, 0 }, { 8, 8, 8, 8 }
44 #define DPTH10_10_10 10, 3, { 0, 0, 0, 0 }, { 10, 10, 10, 0 }
45 #define DPTH16 16, 1, { 0, 0, 0, 0 }, { 16, 0, 0, 0 }
46 #define DPTH16_16_16 16, 3, { 0, 0, 0, 0 }, { 16, 16, 16, 0 }
47 #define DPTH16_16_16_16 16, 4, { 0, 0, 0, 0 }, { 16, 16, 16, 16 }
48 #define DPTH555 16, 3, { 10, 5, 0, 0 }, { 5, 5, 5, 0 }
49 #define DPTH565 16, 3, { 11, 5, 0, 0 }, { 5, 6, 5, 0 }
52 #define PSTR0 { 0, 0, 0, 0 }
53 #define PSTR1 { 1, 0, 0, 0 }
54 #define PSTR111 { 1, 1, 1, 0 }
55 #define PSTR1111 { 1, 1, 1, 1 }
56 #define PSTR122 { 1, 2, 2, 0 }
57 #define PSTR2 { 2, 0, 0, 0 }
58 #define PSTR222 { 2, 2, 2, 0 }
59 #define PSTR244 { 2, 4, 4, 0 }
60 #define PSTR444 { 4, 4, 4, 0 }
61 #define PSTR4444 { 4, 4, 4, 4 }
62 #define PSTR333 { 3, 3, 3, 0 }
63 #define PSTR488 { 4, 8, 8, 0 }
64 #define PSTR8888 { 8, 8, 8, 8 }
67 #define PLANE_NA 0, { 0, 0, 0, 0 }
68 #define PLANE0 1, { 0, 0, 0, 0 }
69 #define PLANE011 2, { 0, 1, 1, 0 }
70 #define PLANE012 3, { 0, 1, 2, 0 }
71 #define PLANE0123 4, { 0, 1, 2, 3 }
72 #define PLANE021 3, { 0, 2, 1, 0 }
75 #define OFFS0 { 0, 0, 0, 0 }
76 #define OFFS013 { 0, 1, 3, 0 }
77 #define OFFS102 { 1, 0, 2, 0 }
78 #define OFFS1230 { 1, 2, 3, 0 }
79 #define OFFS012 { 0, 1, 2, 0 }
80 #define OFFS210 { 2, 1, 0, 0 }
81 #define OFFS123 { 1, 2, 3, 0 }
82 #define OFFS321 { 3, 2, 1, 0 }
83 #define OFFS0123 { 0, 1, 2, 3 }
84 #define OFFS2103 { 2, 1, 0, 3 }
85 #define OFFS3210 { 3, 2, 1, 0 }
86 #define OFFS031 { 0, 3, 1, 0 }
87 #define OFFS026 { 0, 2, 6, 0 }
88 #define OFFS001 { 0, 0, 1, 0 }
89 #define OFFS010 { 0, 1, 0, 0 }
90 #define OFFS104 { 1, 0, 4, 0 }
91 #define OFFS2460 { 2, 4, 6, 0 }
94 #define SUB410 { 0, 2, 2, 0 }, { 0, 2, 2, 0 }
95 #define SUB411 { 0, 2, 2, 0 }, { 0, 0, 0, 0 }
96 #define SUB420 { 0, 1, 1, 0 }, { 0, 1, 1, 0 }
97 #define SUB422 { 0, 1, 1, 0 }, { 0, 0, 0, 0 }
98 #define SUB4 { 0, 0, 0, 0 }, { 0, 0, 0, 0 }
99 #define SUB444 { 0, 0, 0, 0 }, { 0, 0, 0, 0 }
100 #define SUB4444 { 0, 0, 0, 0 }, { 0, 0, 0, 0 }
101 #define SUB4204 { 0, 1, 1, 0 }, { 0, 1, 1, 0 }
103 #define MAKE_YUV_FORMAT(name, desc, fourcc, depth, pstride, plane, offs, sub ) \
104 { fourcc, {GST_VIDEO_FORMAT_ ##name, G_STRINGIFY(name), desc, GST_VIDEO_FORMAT_FLAG_YUV, depth, pstride, plane, offs, sub } }
105 #define MAKE_YUVA_FORMAT(name, desc, fourcc, depth, pstride, plane, offs, sub) \
106 { fourcc, {GST_VIDEO_FORMAT_ ##name, G_STRINGIFY(name), desc, GST_VIDEO_FORMAT_FLAG_YUV | GST_VIDEO_FORMAT_FLAG_ALPHA, depth, pstride, plane, offs, sub } }
108 #define MAKE_RGB_FORMAT(name, desc, depth, pstride, plane, offs, sub) \
109 { 0x00000000, {GST_VIDEO_FORMAT_ ##name, G_STRINGIFY(name), desc, GST_VIDEO_FORMAT_FLAG_RGB, depth, pstride, plane, offs, sub } }
110 #define MAKE_RGBA_FORMAT(name, desc, depth, pstride, plane, offs, sub) \
111 { 0x00000000, {GST_VIDEO_FORMAT_ ##name, G_STRINGIFY(name), desc, GST_VIDEO_FORMAT_FLAG_RGB | GST_VIDEO_FORMAT_FLAG_ALPHA, depth, pstride, plane, offs, sub } }
113 #define MAKE_GRAY_FORMAT(name, desc, depth, pstride, plane, offs, sub) \
114 { 0x00000000, {GST_VIDEO_FORMAT_ ##name, G_STRINGIFY(name), desc, GST_VIDEO_FORMAT_FLAG_GRAY, depth, pstride, plane, offs, sub } }
116 static VideoFormat formats[] = {
117 {0x00000000, {GST_VIDEO_FORMAT_UNKNOWN, "UNKNOWN", "unknown video", 0, DPTH0,
121 MAKE_YUV_FORMAT (I420, "raw video", GST_MAKE_FOURCC ('I', '4', '2', '0'),
123 PLANE012, OFFS0, SUB420),
124 MAKE_YUV_FORMAT (YV12, "raw video", GST_MAKE_FOURCC ('Y', 'V', '1', '2'),
126 PLANE021, OFFS0, SUB420),
127 MAKE_YUV_FORMAT (YUY2, "raw video", GST_MAKE_FOURCC ('Y', 'U', 'Y', '2'),
129 PLANE0, OFFS013, SUB422),
130 MAKE_YUV_FORMAT (UYVY, "raw video", GST_MAKE_FOURCC ('U', 'Y', 'V', 'Y'),
132 PLANE0, OFFS102, SUB422),
133 MAKE_YUVA_FORMAT (AYUV, "raw video", GST_MAKE_FOURCC ('A', 'Y', 'U', 'V'),
135 PSTR4444, PLANE0, OFFS1230, SUB4444),
136 MAKE_RGB_FORMAT (RGBx, "raw video", DPTH888, PSTR444, PLANE0, OFFS012,
138 MAKE_RGB_FORMAT (BGRx, "raw video", DPTH888, PSTR444, PLANE0, OFFS210,
140 MAKE_RGB_FORMAT (xRGB, "raw video", DPTH888, PSTR444, PLANE0, OFFS123,
142 MAKE_RGB_FORMAT (xBGR, "raw video", DPTH888, PSTR444, PLANE0, OFFS321,
144 MAKE_RGBA_FORMAT (RGBA, "raw video", DPTH8888, PSTR4444, PLANE0, OFFS0123,
146 MAKE_RGBA_FORMAT (BGRA, "raw video", DPTH8888, PSTR4444, PLANE0, OFFS2103,
148 MAKE_RGBA_FORMAT (ARGB, "raw video", DPTH8888, PSTR4444, PLANE0, OFFS1230,
150 MAKE_RGBA_FORMAT (ABGR, "raw video", DPTH8888, PSTR4444, PLANE0, OFFS3210,
152 MAKE_RGB_FORMAT (RGB, "raw video", DPTH888, PSTR333, PLANE0, OFFS012, SUB444),
153 MAKE_RGB_FORMAT (BGR, "raw video", DPTH888, PSTR333, PLANE0, OFFS210, SUB444),
155 MAKE_YUV_FORMAT (Y41B, "raw video", GST_MAKE_FOURCC ('Y', '4', '1', 'B'),
157 PLANE012, OFFS0, SUB411),
158 MAKE_YUV_FORMAT (Y42B, "raw video", GST_MAKE_FOURCC ('Y', '4', '2', 'B'),
160 PLANE012, OFFS0, SUB422),
161 MAKE_YUV_FORMAT (YVYU, "raw video", GST_MAKE_FOURCC ('Y', 'V', 'Y', 'U'),
163 PLANE0, OFFS031, SUB422),
164 MAKE_YUV_FORMAT (Y444, "raw video", GST_MAKE_FOURCC ('Y', '4', '4', '4'),
166 PLANE012, OFFS0, SUB444),
167 MAKE_YUV_FORMAT (v210, "raw video", GST_MAKE_FOURCC ('v', '2', '1', '0'),
169 PSTR0, PLANE0, OFFS0, SUB422),
170 MAKE_YUV_FORMAT (v216, "raw video", GST_MAKE_FOURCC ('v', '2', '1', '6'),
172 PSTR488, PLANE0, OFFS026, SUB422),
173 MAKE_YUV_FORMAT (NV12, "raw video", GST_MAKE_FOURCC ('N', 'V', '1', '2'),
175 PLANE011, OFFS001, SUB420),
176 MAKE_YUV_FORMAT (NV21, "raw video", GST_MAKE_FOURCC ('N', 'V', '2', '1'),
178 PLANE011, OFFS010, SUB420),
180 MAKE_GRAY_FORMAT (GRAY8, "raw video", DPTH8, PSTR1, PLANE0, OFFS0, SUB4),
181 MAKE_GRAY_FORMAT (GRAY16_BE, "raw video", DPTH16, PSTR2, PLANE0, OFFS0, SUB4),
182 MAKE_GRAY_FORMAT (GRAY16_LE, "raw video", DPTH16, PSTR2, PLANE0, OFFS0, SUB4),
184 MAKE_YUV_FORMAT (v308, "raw video", GST_MAKE_FOURCC ('v', '3', '0', '8'),
186 PLANE0, OFFS012, SUB444),
187 MAKE_YUV_FORMAT (Y800, "raw video", GST_MAKE_FOURCC ('Y', '8', '0', '0'),
189 PLANE0, OFFS0, SUB4),
190 MAKE_YUV_FORMAT (Y16, "raw video", GST_MAKE_FOURCC ('Y', '1', '6', ' '),
192 PLANE0, OFFS0, SUB4),
194 MAKE_RGB_FORMAT (RGB16, "raw video", DPTH565, PSTR222, PLANE0, OFFS0, SUB444),
195 MAKE_RGB_FORMAT (BGR16, "raw video", DPTH565, PSTR222, PLANE0, OFFS0, SUB444),
196 MAKE_RGB_FORMAT (RGB15, "raw video", DPTH555, PSTR222, PLANE0, OFFS0, SUB444),
197 MAKE_RGB_FORMAT (BGR15, "raw video", DPTH555, PSTR222, PLANE0, OFFS0, SUB444),
199 MAKE_YUV_FORMAT (UYVP, "raw video", GST_MAKE_FOURCC ('U', 'Y', 'V', 'P'),
201 PSTR0, PLANE0, OFFS0, SUB422),
202 MAKE_YUVA_FORMAT (A420, "raw video", GST_MAKE_FOURCC ('A', '4', '2', '0'),
204 PSTR1111, PLANE0123, OFFS0, SUB4204),
205 MAKE_RGBA_FORMAT (RGB8_PALETTED, "raw video", DPTH8888, PSTR1111, PLANE0,
207 MAKE_YUV_FORMAT (YUV9, "raw video", GST_MAKE_FOURCC ('Y', 'U', 'V', '9'),
209 PLANE012, OFFS0, SUB410),
210 MAKE_YUV_FORMAT (YVU9, "raw video", GST_MAKE_FOURCC ('Y', 'V', 'U', '9'),
212 PLANE021, OFFS0, SUB410),
213 MAKE_YUV_FORMAT (IYU1, "raw video", GST_MAKE_FOURCC ('I', 'Y', 'U', '1'),
215 PLANE0, OFFS104, SUB411),
216 MAKE_RGBA_FORMAT (ARGB64, "raw video", DPTH16_16_16_16, PSTR8888, PLANE0,
219 MAKE_YUVA_FORMAT (AYUV64, "raw video", 0x00000000, DPTH16_16_16_16, PSTR8888,
222 MAKE_YUV_FORMAT (r210, "raw video", GST_MAKE_FOURCC ('r', '2', '1', '0'),
224 PSTR444, PLANE0, OFFS0, SUB444),
229 * @short_description: Support library for video operations
233 * This library contains some helper functions and includes the
234 * videosink and videofilter base classes.
240 * gst_video_calculate_display_ratio:
241 * @dar_n: Numerator of the calculated display_ratio
242 * @dar_d: Denominator of the calculated display_ratio
243 * @video_width: Width of the video frame in pixels
244 * @video_height: Height of the video frame in pixels
245 * @video_par_n: Numerator of the pixel aspect ratio of the input video.
246 * @video_par_d: Denominator of the pixel aspect ratio of the input video.
247 * @display_par_n: Numerator of the pixel aspect ratio of the display device
248 * @display_par_d: Denominator of the pixel aspect ratio of the display device
250 * Given the Pixel Aspect Ratio and size of an input video frame, and the
251 * pixel aspect ratio of the intended display device, calculates the actual
252 * display ratio the video will be rendered with.
254 * Returns: A boolean indicating success and a calculated Display Ratio in the
255 * dar_n and dar_d parameters.
256 * The return value is FALSE in the case of integer overflow or other error.
261 gst_video_calculate_display_ratio (guint * dar_n, guint * dar_d,
262 guint video_width, guint video_height,
263 guint video_par_n, guint video_par_d,
264 guint display_par_n, guint display_par_d)
269 g_return_val_if_fail (dar_n != NULL, FALSE);
270 g_return_val_if_fail (dar_d != NULL, FALSE);
272 /* Calculate (video_width * video_par_n * display_par_d) /
273 * (video_height * video_par_d * display_par_n) */
274 if (!gst_util_fraction_multiply (video_width, video_height, video_par_n,
275 video_par_d, &tmp_n, &tmp_d))
278 if (!gst_util_fraction_multiply (tmp_n, tmp_d, display_par_d, display_par_n,
282 g_return_val_if_fail (num > 0, FALSE);
283 g_return_val_if_fail (den > 0, FALSE);
293 GST_WARNING ("overflow in multiply");
298 static GstVideoFormat
299 gst_video_format_from_rgb32_masks (int red_mask, int green_mask, int blue_mask)
301 if (red_mask == 0xff000000 && green_mask == 0x00ff0000 &&
302 blue_mask == 0x0000ff00) {
303 return GST_VIDEO_FORMAT_RGBx;
305 if (red_mask == 0x0000ff00 && green_mask == 0x00ff0000 &&
306 blue_mask == 0xff000000) {
307 return GST_VIDEO_FORMAT_BGRx;
309 if (red_mask == 0x00ff0000 && green_mask == 0x0000ff00 &&
310 blue_mask == 0x000000ff) {
311 return GST_VIDEO_FORMAT_xRGB;
313 if (red_mask == 0x000000ff && green_mask == 0x0000ff00 &&
314 blue_mask == 0x00ff0000) {
315 return GST_VIDEO_FORMAT_xBGR;
318 return GST_VIDEO_FORMAT_UNKNOWN;
321 static GstVideoFormat
322 gst_video_format_from_rgba32_masks (int red_mask, int green_mask,
323 int blue_mask, int alpha_mask)
325 if (red_mask == 0xff000000 && green_mask == 0x00ff0000 &&
326 blue_mask == 0x0000ff00 && alpha_mask == 0x000000ff) {
327 return GST_VIDEO_FORMAT_RGBA;
329 if (red_mask == 0x0000ff00 && green_mask == 0x00ff0000 &&
330 blue_mask == 0xff000000 && alpha_mask == 0x000000ff) {
331 return GST_VIDEO_FORMAT_BGRA;
333 if (red_mask == 0x00ff0000 && green_mask == 0x0000ff00 &&
334 blue_mask == 0x000000ff && alpha_mask == 0xff000000) {
335 return GST_VIDEO_FORMAT_ARGB;
337 if (red_mask == 0x000000ff && green_mask == 0x0000ff00 &&
338 blue_mask == 0x00ff0000 && alpha_mask == 0xff000000) {
339 return GST_VIDEO_FORMAT_ABGR;
341 return GST_VIDEO_FORMAT_UNKNOWN;
344 static GstVideoFormat
345 gst_video_format_from_rgb24_masks (int red_mask, int green_mask, int blue_mask)
347 if (red_mask == 0xff0000 && green_mask == 0x00ff00 && blue_mask == 0x0000ff) {
348 return GST_VIDEO_FORMAT_RGB;
350 if (red_mask == 0x0000ff && green_mask == 0x00ff00 && blue_mask == 0xff0000) {
351 return GST_VIDEO_FORMAT_BGR;
354 return GST_VIDEO_FORMAT_UNKNOWN;
357 #define GST_VIDEO_COMP1_MASK_16_INT 0xf800
358 #define GST_VIDEO_COMP2_MASK_16_INT 0x07e0
359 #define GST_VIDEO_COMP3_MASK_16_INT 0x001f
361 #define GST_VIDEO_COMP1_MASK_15_INT 0x7c00
362 #define GST_VIDEO_COMP2_MASK_15_INT 0x03e0
363 #define GST_VIDEO_COMP3_MASK_15_INT 0x001f
365 static GstVideoFormat
366 gst_video_format_from_rgb16_masks (int red_mask, int green_mask, int blue_mask)
368 if (red_mask == GST_VIDEO_COMP1_MASK_16_INT
369 && green_mask == GST_VIDEO_COMP2_MASK_16_INT
370 && blue_mask == GST_VIDEO_COMP3_MASK_16_INT) {
371 return GST_VIDEO_FORMAT_RGB16;
373 if (red_mask == GST_VIDEO_COMP3_MASK_16_INT
374 && green_mask == GST_VIDEO_COMP2_MASK_16_INT
375 && blue_mask == GST_VIDEO_COMP1_MASK_16_INT) {
376 return GST_VIDEO_FORMAT_BGR16;
378 if (red_mask == GST_VIDEO_COMP1_MASK_15_INT
379 && green_mask == GST_VIDEO_COMP2_MASK_15_INT
380 && blue_mask == GST_VIDEO_COMP3_MASK_15_INT) {
381 return GST_VIDEO_FORMAT_RGB15;
383 if (red_mask == GST_VIDEO_COMP3_MASK_15_INT
384 && green_mask == GST_VIDEO_COMP2_MASK_15_INT
385 && blue_mask == GST_VIDEO_COMP1_MASK_15_INT) {
386 return GST_VIDEO_FORMAT_BGR15;
388 return GST_VIDEO_FORMAT_UNKNOWN;
392 * gst_video_format_from_masks:
393 * @depth: the amount of bits used for a pixel
394 * @bpp: the amount of bits used to store a pixel. This value is bigger than
396 * @endianness: the endianness of the masks
397 * @red_mask: the red mask
398 * @green_mask: the green mask
399 * @blue_mask: the blue mask
400 * @alpha_mask: the optional alpha mask
402 * Find the #GstVideoFormat for the given parameters.
404 * Returns: a #GstVideoFormat or GST_VIDEO_FORMAT_UNKNOWN when the parameters to
405 * not specify a known format.
408 gst_video_format_from_masks (gint depth, gint bpp, gint endianness,
409 gint red_mask, gint green_mask, gint blue_mask, gint alpha_mask)
411 GstVideoFormat format;
413 /* our caps system handles 24/32bpp RGB as big-endian. */
414 if ((bpp == 24 || bpp == 32) && endianness == G_LITTLE_ENDIAN) {
415 red_mask = GUINT32_TO_BE (red_mask);
416 green_mask = GUINT32_TO_BE (green_mask);
417 blue_mask = GUINT32_TO_BE (blue_mask);
418 endianness = G_BIG_ENDIAN;
426 if (depth == 30 && bpp == 32) {
427 format = GST_VIDEO_FORMAT_r210;
428 } else if (depth == 24 && bpp == 32) {
429 format = gst_video_format_from_rgb32_masks (red_mask, green_mask,
431 } else if (depth == 32 && bpp == 32 && alpha_mask) {
432 format = gst_video_format_from_rgba32_masks (red_mask, green_mask,
433 blue_mask, alpha_mask);
434 } else if (depth == 24 && bpp == 24) {
435 format = gst_video_format_from_rgb24_masks (red_mask, green_mask,
437 } else if ((depth == 15 || depth == 16) && bpp == 16 &&
438 endianness == G_BYTE_ORDER) {
439 format = gst_video_format_from_rgb16_masks (red_mask, green_mask,
441 } else if (depth == 8 && bpp == 8) {
442 format = GST_VIDEO_FORMAT_RGB8_PALETTED;
443 } else if (depth == 64 && bpp == 64) {
444 format = gst_video_format_from_rgba32_masks (red_mask, green_mask,
445 blue_mask, alpha_mask);
446 if (format == GST_VIDEO_FORMAT_ARGB) {
447 format = GST_VIDEO_FORMAT_ARGB64;
449 format = GST_VIDEO_FORMAT_UNKNOWN;
452 format = GST_VIDEO_FORMAT_UNKNOWN;
458 * gst_video_format_from_fourcc:
459 * @fourcc: a FOURCC value representing raw YUV video
461 * Converts a FOURCC value into the corresponding #GstVideoFormat.
462 * If the FOURCC cannot be represented by #GstVideoFormat,
463 * #GST_VIDEO_FORMAT_UNKNOWN is returned.
467 * Returns: the #GstVideoFormat describing the FOURCC value
470 gst_video_format_from_fourcc (guint32 fourcc)
473 case GST_MAKE_FOURCC ('I', '4', '2', '0'):
474 return GST_VIDEO_FORMAT_I420;
475 case GST_MAKE_FOURCC ('Y', 'V', '1', '2'):
476 return GST_VIDEO_FORMAT_YV12;
477 case GST_MAKE_FOURCC ('Y', 'U', 'Y', '2'):
478 return GST_VIDEO_FORMAT_YUY2;
479 case GST_MAKE_FOURCC ('Y', 'V', 'Y', 'U'):
480 return GST_VIDEO_FORMAT_YVYU;
481 case GST_MAKE_FOURCC ('U', 'Y', 'V', 'Y'):
482 return GST_VIDEO_FORMAT_UYVY;
483 case GST_MAKE_FOURCC ('A', 'Y', 'U', 'V'):
484 return GST_VIDEO_FORMAT_AYUV;
485 case GST_MAKE_FOURCC ('Y', '4', '1', 'B'):
486 return GST_VIDEO_FORMAT_Y41B;
487 case GST_MAKE_FOURCC ('Y', '4', '2', 'B'):
488 return GST_VIDEO_FORMAT_Y42B;
489 case GST_MAKE_FOURCC ('Y', '4', '4', '4'):
490 return GST_VIDEO_FORMAT_Y444;
491 case GST_MAKE_FOURCC ('v', '2', '1', '0'):
492 return GST_VIDEO_FORMAT_v210;
493 case GST_MAKE_FOURCC ('v', '2', '1', '6'):
494 return GST_VIDEO_FORMAT_v216;
495 case GST_MAKE_FOURCC ('N', 'V', '1', '2'):
496 return GST_VIDEO_FORMAT_NV12;
497 case GST_MAKE_FOURCC ('N', 'V', '2', '1'):
498 return GST_VIDEO_FORMAT_NV21;
499 case GST_MAKE_FOURCC ('v', '3', '0', '8'):
500 return GST_VIDEO_FORMAT_v308;
501 case GST_MAKE_FOURCC ('Y', '8', '0', '0'):
502 case GST_MAKE_FOURCC ('Y', '8', ' ', ' '):
503 case GST_MAKE_FOURCC ('G', 'R', 'E', 'Y'):
504 return GST_VIDEO_FORMAT_Y800;
505 case GST_MAKE_FOURCC ('Y', '1', '6', ' '):
506 return GST_VIDEO_FORMAT_Y16;
507 case GST_MAKE_FOURCC ('U', 'Y', 'V', 'P'):
508 return GST_VIDEO_FORMAT_UYVP;
509 case GST_MAKE_FOURCC ('A', '4', '2', '0'):
510 return GST_VIDEO_FORMAT_A420;
511 case GST_MAKE_FOURCC ('Y', 'U', 'V', '9'):
512 return GST_VIDEO_FORMAT_YUV9;
513 case GST_MAKE_FOURCC ('Y', 'V', 'U', '9'):
514 return GST_VIDEO_FORMAT_YVU9;
515 case GST_MAKE_FOURCC ('I', 'Y', 'U', '1'):
516 return GST_VIDEO_FORMAT_IYU1;
517 case GST_MAKE_FOURCC ('A', 'Y', '6', '4'):
518 return GST_VIDEO_FORMAT_AYUV64;
520 return GST_VIDEO_FORMAT_UNKNOWN;
525 * gst_video_format_from_string:
526 * @format: a format string
528 * Convert the @format string to its #GstVideoFormat.
530 * Returns: the #GstVideoFormat for @format or GST_VIDEO_FORMAT_UNKNOWN when the
531 * string is not a known format.
534 gst_video_format_from_string (const gchar * format)
538 for (i = 0; i < G_N_ELEMENTS (formats); i++) {
539 if (strcmp (GST_VIDEO_FORMAT_INFO_NAME (&formats[i].info), format) == 0)
540 return GST_VIDEO_FORMAT_INFO_FORMAT (&formats[i].info);
542 return GST_VIDEO_FORMAT_UNKNOWN;
547 * gst_video_format_to_fourcc:
548 * @format: a #GstVideoFormat video format
550 * Converts a #GstVideoFormat value into the corresponding FOURCC. Only
551 * a few YUV formats have corresponding FOURCC values. If @format has
552 * no corresponding FOURCC value, 0 is returned.
556 * Returns: the FOURCC corresponding to @format
559 gst_video_format_to_fourcc (GstVideoFormat format)
561 g_return_val_if_fail (format != GST_VIDEO_FORMAT_UNKNOWN, 0);
563 if (format >= G_N_ELEMENTS (formats))
566 return formats[format].fourcc;
570 gst_video_format_to_string (GstVideoFormat format)
572 g_return_val_if_fail (format != GST_VIDEO_FORMAT_UNKNOWN, NULL);
574 if (format >= G_N_ELEMENTS (formats))
577 return GST_VIDEO_FORMAT_INFO_NAME (&formats[format].info);
581 * gst_video_format_get_info:
582 * @format: a #GstVideoFormat
584 * Get the #GstVideoFormatInfo for @format
586 * Returns: The #GstVideoFormatInfo for @format.
588 const GstVideoFormatInfo *
589 gst_video_format_get_info (GstVideoFormat format)
591 g_return_val_if_fail (format != GST_VIDEO_FORMAT_UNKNOWN, NULL);
592 g_return_val_if_fail (format < G_N_ELEMENTS (formats), NULL);
594 return &formats[format].info;
598 * gst_video_info_init:
599 * @info: a #GstVideoInfo
601 * Initialize @info with default values.
604 gst_video_info_init (GstVideoInfo * info)
606 g_return_if_fail (info != NULL);
608 memset (info, 0, sizeof (GstVideoInfo));
610 /* arrange for sensible defaults, e.g. if turned into caps */
618 * gst_video_info_set_format:
619 * @info: a #GstVideoInfo
620 * @format: the format
624 * Set the default info for a video frame of @format and @width and @height.
627 gst_video_info_set_format (GstVideoInfo * info, GstVideoFormat format,
628 guint width, guint height)
630 const GstVideoFormatInfo *finfo;
632 g_return_if_fail (info != NULL);
633 g_return_if_fail (format != GST_VIDEO_FORMAT_UNKNOWN);
635 finfo = &formats[format].info;
640 info->height = height;
648 GstVideoChromaSite site;
651 static const ChromaSiteInfo chromasite[] = {
652 {"jpeg", GST_VIDEO_CHROMA_SITE_JPEG},
653 {"mpeg2", GST_VIDEO_CHROMA_SITE_MPEG2},
654 {"dv", GST_VIDEO_CHROMA_SITE_DV}
657 static GstVideoChromaSite
658 gst_video_chroma_from_string (const gchar * s)
661 for (i = 0; i < G_N_ELEMENTS (chromasite); i++) {
662 if (g_str_equal (chromasite[i].name, s))
663 return chromasite[i].site;
665 return GST_VIDEO_CHROMA_SITE_UNKNOWN;
669 gst_video_chroma_to_string (GstVideoChromaSite site)
672 for (i = 0; i < G_N_ELEMENTS (chromasite); i++) {
673 if (chromasite[i].site == site)
674 return chromasite[i].name;
682 GstVideoColorimetry color;
685 #define MAKE_COLORIMETRY(n,r,m,t,p) { GST_VIDEO_COLORIMETRY_ ##n, \
686 { GST_VIDEO_COLOR_RANGE ##r, GST_VIDEO_COLOR_MATRIX_ ##m, \
687 GST_VIDEO_TRANSFER_ ##t, GST_VIDEO_COLOR_PRIMARIES_ ##p } }
689 static const ColorimetryInfo colorimetry[] = {
690 MAKE_COLORIMETRY (BT601, _16_235, BT601, BT709, BT470M),
691 MAKE_COLORIMETRY (BT709, _16_235, BT709, BT709, BT709),
692 MAKE_COLORIMETRY (SMPTE240M, _16_235, SMPTE240M, SMPTE240M, SMPTE240M),
695 static const ColorimetryInfo *
696 gst_video_get_colorimetry (const gchar * s)
700 for (i = 0; i < G_N_ELEMENTS (colorimetry); i++) {
701 if (g_str_equal (colorimetry[i].name, s))
702 return &colorimetry[i];
707 #define IS_EQUAL(ci,i) (((ci)->color.range == (i)->range) && \
708 ((ci)->color.matrix == (i)->matrix) && \
709 ((ci)->color.transfer == (i)->transfer) && \
710 ((ci)->color.primaries == (i)->primaries))
714 * gst_video_colorimetry_from_string
715 * @cinfo: a #GstVideoColorimetry
716 * @color: a colorimetry string
718 * Parse the colorimetry string and update @cinfo with the parsed
721 * Returns: #TRUE if @color points to valid colorimetry info.
724 gst_video_colorimetry_from_string (GstVideoColorimetry * cinfo,
727 const ColorimetryInfo *ci;
729 if ((ci = gst_video_get_colorimetry (color))) {
732 /* FIXME, split and parse */
733 cinfo->range = GST_VIDEO_COLOR_RANGE_16_235;
734 cinfo->matrix = GST_VIDEO_COLOR_MATRIX_BT601;
735 cinfo->transfer = GST_VIDEO_TRANSFER_BT709;
736 cinfo->primaries = GST_VIDEO_COLOR_PRIMARIES_BT709;
742 gst_video_caps_set_colorimetry (GstCaps * caps, GstVideoColorimetry * cinfo)
746 for (i = 0; i < G_N_ELEMENTS (colorimetry); i++) {
747 if (IS_EQUAL (&colorimetry[i], cinfo)) {
748 gst_caps_set_simple (caps, "colorimetry", G_TYPE_STRING,
749 colorimetry[i].name, NULL);
753 /* FIXME, construct colorimetry */
757 * gst_video_colorimetry_matches:
758 * @info: a #GstVideoInfo
759 * @color: a colorimetry string
761 * Check if the colorimetry information in @info matches that of the
764 * Returns: #TRUE if @color conveys the same colorimetry info as the color
765 * information in @info.
768 gst_video_colorimetry_matches (GstVideoColorimetry * cinfo, const gchar * color)
770 const ColorimetryInfo *ci;
772 if ((ci = gst_video_get_colorimetry (color)))
773 return IS_EQUAL (ci, cinfo);
779 * gst_video_info_from_caps:
780 * @info: a #GstVideoInfo
783 * Parse @caps and update @info.
785 * Returns: TRUE if @caps could be parsed
788 gst_video_info_from_caps (GstVideoInfo * info, const GstCaps * caps)
790 GstStructure *structure;
792 GstVideoFormat format;
793 gint width, height, views;
798 g_return_val_if_fail (info != NULL, FALSE);
799 g_return_val_if_fail (caps != NULL, FALSE);
800 g_return_val_if_fail (gst_caps_is_fixed (caps), FALSE);
802 GST_DEBUG ("parsing caps %" GST_PTR_FORMAT, caps);
804 structure = gst_caps_get_structure (caps, 0);
806 if (!gst_structure_has_name (structure, "video/x-raw"))
809 if (!(s = gst_structure_get_string (structure, "format")))
812 format = gst_video_format_from_string (s);
813 if (format == GST_VIDEO_FORMAT_UNKNOWN)
816 if (!gst_structure_get_int (structure, "width", &width))
818 if (!gst_structure_get_int (structure, "height", &height))
821 gst_video_info_set_format (info, format, width, height);
823 if (gst_structure_get_fraction (structure, "framerate", &fps_n, &fps_d)) {
831 if (!gst_structure_get_boolean (structure, "interlaced", &interlaced))
834 info->flags |= GST_VIDEO_FLAG_INTERLACED;
836 info->flags &= ~GST_VIDEO_FLAG_INTERLACED;
838 if (gst_structure_get_int (structure, "views", &views))
843 if ((s = gst_structure_get_string (structure, "chroma-site")))
844 info->chroma_site = gst_video_chroma_from_string (s);
846 if ((s = gst_structure_get_string (structure, "colorimetry")))
847 gst_video_colorimetry_from_string (&info->colorimetry, s);
849 if (gst_structure_get_fraction (structure, "pixel-aspect-ratio",
862 GST_ERROR ("wrong name, expected video/x-raw");
867 GST_ERROR ("no format given");
872 GST_ERROR ("unknown format given");
877 GST_ERROR ("no width property given");
882 GST_ERROR ("no height property given");
888 * gst_video_info_to_caps:
889 * @info: a #GstVideoInfo
891 * Convert the values of @info into a #GstCaps.
893 * Returns: a new #GstCaps containing the info of @info.
896 gst_video_info_to_caps (GstVideoInfo * info)
901 g_return_val_if_fail (info != NULL, NULL);
902 g_return_val_if_fail (info->finfo != NULL, NULL);
903 g_return_val_if_fail (info->finfo->format != GST_VIDEO_FORMAT_UNKNOWN, NULL);
905 format = gst_video_format_to_string (info->finfo->format);
906 g_return_val_if_fail (format != NULL, NULL);
908 caps = gst_caps_new_simple ("video/x-raw",
909 "format", G_TYPE_STRING, format,
910 "width", G_TYPE_INT, info->width,
911 "height", G_TYPE_INT, info->height,
912 "framerate", GST_TYPE_FRACTION, info->fps_n, info->fps_d,
913 "pixel-aspect-ratio", GST_TYPE_FRACTION, info->par_n, info->par_d, NULL);
915 if (info->flags & GST_VIDEO_FLAG_INTERLACED)
916 gst_caps_set_simple (caps, "interlaced", G_TYPE_BOOLEAN, TRUE, NULL);
918 if (info->chroma_site != GST_VIDEO_CHROMA_SITE_UNKNOWN)
919 gst_caps_set_simple (caps, "chroma-site", G_TYPE_STRING,
920 gst_video_chroma_to_string (info->chroma_site), NULL);
922 gst_video_caps_set_colorimetry (caps, &info->colorimetry);
925 gst_caps_set_simple (caps, "views", G_TYPE_INT, info->views, NULL);
931 * gst_video_frame_map_id:
932 * @frame: pointer to #GstVideoFrame
933 * @info: a #GstVideoInfo
934 * @buffer: the buffer to map
935 * @id: the frame id to map
936 * @flags: #GstMapFlags
938 * Use @info and @buffer to fill in the values of @frame with the video frame
939 * information of frame @id.
941 * When @id is -1, the default frame is mapped. When @id != -1, this function
942 * will return %FALSE when there is no GstMetaVideo with that id.
944 * All video planes of @buffer will be mapped and the pointers will be set in
947 * Returns: %TRUE on success.
950 gst_video_frame_map_id (GstVideoFrame * frame, GstVideoInfo * info,
951 GstBuffer * buffer, gint id, GstMapFlags flags)
958 g_return_val_if_fail (frame != NULL, FALSE);
959 g_return_val_if_fail (info != NULL, FALSE);
960 g_return_val_if_fail (GST_IS_BUFFER (buffer), FALSE);
963 meta = gst_buffer_get_meta_video (buffer);
965 meta = gst_buffer_get_meta_video_id (buffer, id);
967 frame->buffer = buffer;
971 frame->info.flags = meta->flags;
972 frame->info.finfo = &formats[meta->format].info;
973 frame->info.width = meta->width;
974 frame->info.height = meta->height;
975 frame->id = meta->id;
977 for (i = 0; i < info->finfo->n_planes; i++) {
979 gst_meta_video_map (meta, i, &frame->info.stride[i], flags);
982 /* no metadata, we really need to have the metadata when the id is
991 data = gst_buffer_map (buffer, &size, NULL, flags);
993 /* do some sanity checks */
994 if (size < info->size)
997 /* set up pointers */
998 for (i = 0; i < info->finfo->n_planes; i++) {
999 frame->data[i] = data + info->offset[i];
1007 GST_ERROR ("no GstMetaVideo for id", id);
1012 GST_ERROR ("invalid buffer size %" G_GSIZE_FORMAT " < %" G_GSIZE_FORMAT,
1014 gst_buffer_unmap (buffer, data, size);
1020 * gst_video_frame_map:
1021 * @frame: pointer to #GstVideoFrame
1022 * @info: a #GstVideoInfo
1023 * @buffer: the buffer to map
1024 * @flags: #GstMapFlags
1026 * Use @info and @buffer to fill in the values of @frame.
1028 * All video planes of @buffer will be mapped and the pointers will be set in
1031 * Returns: %TRUE on success.
1034 gst_video_frame_map (GstVideoFrame * frame, GstVideoInfo * info,
1035 GstBuffer * buffer, GstMapFlags flags)
1037 return gst_video_frame_map_id (frame, info, buffer, -1, flags);
1041 * gst_video_frame_unmap:
1042 * @frame: a #GstVideoFrame
1044 * Unmap the memory previously mapped with gst_video_frame_map.
1047 gst_video_frame_unmap (GstVideoFrame * frame)
1053 g_return_if_fail (frame != NULL);
1055 buffer = frame->buffer;
1059 for (i = 0; i < frame->info.finfo->n_planes; i++) {
1060 gst_meta_video_unmap (meta, i, frame->data[i]);
1065 data = frame->data[0];
1066 data -= frame->info.offset[0];
1067 gst_buffer_unmap (buffer, data, -1);
1072 * gst_video_frame_copy:
1073 * @dest: a #GstVideoFrame
1074 * @src: a #GstVideoFrame
1076 * Copy the contents from @src to @dest.
1078 * Returns: TRUE if the contents could be copied.
1081 gst_video_frame_copy (GstVideoFrame * dest, const GstVideoFrame * src)
1084 const GstVideoInfo *sinfo;
1085 GstVideoInfo *dinfo;
1088 dinfo = &dest->info;
1090 g_return_val_if_fail (dinfo->finfo->format == sinfo->finfo->format, FALSE);
1091 g_return_val_if_fail (dinfo->width == sinfo->width
1092 && dinfo->height == sinfo->height, FALSE);
1094 n_planes = dinfo->finfo->n_planes;
1096 for (i = 0; i < n_planes; i++) {
1104 ss = sinfo->stride[i];
1105 ds = dinfo->stride[i];
1107 w = MIN (ABS (ss), ABS (ds));
1108 h = GST_VIDEO_FRAME_COMP_HEIGHT (dest, i);
1110 GST_DEBUG ("w %d h %d", w, h);
1112 for (j = 0; j < h; j++) {
1122 fill_planes (GstVideoInfo * info)
1126 width = info->width;
1127 height = info->height;
1129 switch (info->finfo->format) {
1130 case GST_VIDEO_FORMAT_YUY2:
1131 case GST_VIDEO_FORMAT_YVYU:
1132 case GST_VIDEO_FORMAT_UYVY:
1133 info->stride[0] = GST_ROUND_UP_4 (width * 2);
1134 info->offset[0] = 0;
1135 info->size = info->stride[0] * height;
1137 case GST_VIDEO_FORMAT_AYUV:
1138 case GST_VIDEO_FORMAT_RGBx:
1139 case GST_VIDEO_FORMAT_RGBA:
1140 case GST_VIDEO_FORMAT_BGRx:
1141 case GST_VIDEO_FORMAT_BGRA:
1142 case GST_VIDEO_FORMAT_xRGB:
1143 case GST_VIDEO_FORMAT_ARGB:
1144 case GST_VIDEO_FORMAT_xBGR:
1145 case GST_VIDEO_FORMAT_ABGR:
1146 case GST_VIDEO_FORMAT_r210:
1147 info->stride[0] = width * 4;
1148 info->offset[0] = 0;
1149 info->size = info->stride[0] * height;
1151 case GST_VIDEO_FORMAT_RGB16:
1152 case GST_VIDEO_FORMAT_BGR16:
1153 case GST_VIDEO_FORMAT_RGB15:
1154 case GST_VIDEO_FORMAT_BGR15:
1155 info->stride[0] = GST_ROUND_UP_4 (width * 2);
1156 info->offset[0] = 0;
1157 info->size = info->stride[0] * height;
1159 case GST_VIDEO_FORMAT_RGB:
1160 case GST_VIDEO_FORMAT_BGR:
1161 case GST_VIDEO_FORMAT_v308:
1162 info->stride[0] = GST_ROUND_UP_4 (width * 3);
1163 info->offset[0] = 0;
1164 info->size = info->stride[0] * height;
1166 case GST_VIDEO_FORMAT_v210:
1167 info->stride[0] = ((width + 47) / 48) * 128;
1168 info->offset[0] = 0;
1169 info->size = info->stride[0] * height;
1171 case GST_VIDEO_FORMAT_v216:
1172 info->stride[0] = GST_ROUND_UP_8 (width * 4);
1173 info->offset[0] = 0;
1174 info->size = info->stride[0] * height;
1176 case GST_VIDEO_FORMAT_GRAY8:
1177 case GST_VIDEO_FORMAT_Y800:
1178 info->stride[0] = GST_ROUND_UP_4 (width);
1179 info->offset[0] = 0;
1180 info->size = info->stride[0] * height;
1182 case GST_VIDEO_FORMAT_GRAY16_BE:
1183 case GST_VIDEO_FORMAT_GRAY16_LE:
1184 case GST_VIDEO_FORMAT_Y16:
1185 info->stride[0] = GST_ROUND_UP_4 (width * 2);
1186 info->offset[0] = 0;
1187 info->size = info->stride[0] * height;
1189 case GST_VIDEO_FORMAT_UYVP:
1190 info->stride[0] = GST_ROUND_UP_4 ((width * 2 * 5 + 3) / 4);
1191 info->offset[0] = 0;
1192 info->size = info->stride[0] * height;
1194 case GST_VIDEO_FORMAT_RGB8_PALETTED:
1195 info->stride[0] = GST_ROUND_UP_4 (width);
1196 info->offset[0] = 0;
1197 info->size = info->stride[0] * height;
1199 case GST_VIDEO_FORMAT_IYU1:
1200 info->stride[0] = GST_ROUND_UP_4 (GST_ROUND_UP_4 (width) +
1201 GST_ROUND_UP_4 (width) / 2);
1202 info->offset[0] = 0;
1203 info->size = info->stride[0] * height;
1205 case GST_VIDEO_FORMAT_ARGB64:
1206 case GST_VIDEO_FORMAT_AYUV64:
1207 info->stride[0] = width * 8;
1208 info->offset[0] = 0;
1209 info->size = info->stride[0] * height;
1211 case GST_VIDEO_FORMAT_I420:
1212 info->stride[0] = GST_ROUND_UP_4 (width);
1213 info->stride[1] = GST_ROUND_UP_4 (GST_ROUND_UP_2 (width) / 2);
1214 info->stride[2] = info->stride[1];
1215 info->offset[0] = 0;
1216 info->offset[1] = info->stride[0] * GST_ROUND_UP_2 (height);
1217 info->offset[2] = info->offset[1] +
1218 info->stride[1] * (GST_ROUND_UP_2 (height) / 2);
1219 info->size = info->offset[2] +
1220 info->stride[2] * (GST_ROUND_UP_2 (height) / 2);
1222 case GST_VIDEO_FORMAT_YV12: /* same as I420, but plane 1+2 swapped */
1223 info->stride[0] = GST_ROUND_UP_4 (width);
1224 info->stride[1] = GST_ROUND_UP_4 (GST_ROUND_UP_2 (width) / 2);
1225 info->stride[2] = info->stride[1];
1226 info->offset[0] = 0;
1227 info->offset[2] = info->stride[0] * GST_ROUND_UP_2 (height);
1228 info->offset[1] = info->offset[2] +
1229 info->stride[1] * (GST_ROUND_UP_2 (height) / 2);
1230 info->size = info->offset[1] +
1231 info->stride[2] * (GST_ROUND_UP_2 (height) / 2);
1233 case GST_VIDEO_FORMAT_Y41B:
1234 info->stride[0] = GST_ROUND_UP_4 (width);
1235 info->stride[1] = GST_ROUND_UP_16 (width) / 4;
1236 info->stride[2] = info->stride[1];
1237 info->offset[0] = 0;
1238 info->offset[1] = info->stride[0] * height;
1239 info->offset[2] = info->offset[1] + info->stride[1] * height;
1240 /* simplification of ROUNDUP4(w)*h + 2*((ROUNDUP16(w)/4)*h */
1241 info->size = (info->stride[0] + (GST_ROUND_UP_16 (width) / 2)) * height;
1243 case GST_VIDEO_FORMAT_Y42B:
1244 info->stride[0] = GST_ROUND_UP_4 (width);
1245 info->stride[1] = GST_ROUND_UP_8 (width) / 2;
1246 info->stride[2] = info->stride[1];
1247 info->offset[0] = 0;
1248 info->offset[1] = info->stride[0] * height;
1249 info->offset[2] = info->offset[1] + info->stride[1] * height;
1250 /* simplification of ROUNDUP4(w)*h + 2*(ROUNDUP8(w)/2)*h */
1251 info->size = (info->stride[0] + GST_ROUND_UP_8 (width)) * height;
1253 case GST_VIDEO_FORMAT_Y444:
1254 info->stride[0] = GST_ROUND_UP_4 (width);
1255 info->stride[1] = info->stride[0];
1256 info->stride[2] = info->stride[0];
1257 info->offset[0] = 0;
1258 info->offset[1] = info->stride[0] * height;
1259 info->offset[2] = info->offset[1] * 2;
1260 info->size = info->stride[0] * height * 3;
1262 case GST_VIDEO_FORMAT_NV12:
1263 case GST_VIDEO_FORMAT_NV21:
1264 info->stride[0] = GST_ROUND_UP_4 (width);
1265 info->stride[1] = info->stride[0];
1266 info->offset[0] = 0;
1267 info->offset[1] = info->stride[0] * GST_ROUND_UP_2 (height);
1268 info->size = info->stride[0] * GST_ROUND_UP_2 (height) * 3 / 2;
1270 case GST_VIDEO_FORMAT_A420:
1271 info->stride[0] = GST_ROUND_UP_4 (width);
1272 info->stride[1] = GST_ROUND_UP_4 (GST_ROUND_UP_2 (width) / 2);
1273 info->stride[2] = info->stride[1];
1274 info->stride[3] = info->stride[0];
1275 info->offset[0] = 0;
1276 info->offset[1] = info->stride[0] * GST_ROUND_UP_2 (height);
1277 info->offset[2] = info->offset[1] +
1278 info->stride[1] * (GST_ROUND_UP_2 (height) / 2);
1279 info->offset[3] = info->offset[2] +
1280 info->stride[2] * (GST_ROUND_UP_2 (height) / 2);
1281 info->size = info->offset[3] + info->stride[0];
1283 case GST_VIDEO_FORMAT_YUV9:
1284 info->stride[0] = GST_ROUND_UP_4 (width);
1285 info->stride[1] = GST_ROUND_UP_4 (GST_ROUND_UP_4 (width) / 4);
1286 info->stride[2] = info->stride[1];
1287 info->offset[0] = 0;
1288 info->offset[1] = info->stride[0] * height;
1289 info->offset[2] = info->offset[1] +
1290 info->stride[1] * (GST_ROUND_UP_4 (height) / 4);
1291 info->size = info->offset[2] +
1292 info->stride[2] * (GST_ROUND_UP_4 (height) / 4);
1294 case GST_VIDEO_FORMAT_YVU9:
1295 info->stride[0] = GST_ROUND_UP_4 (width);
1296 info->stride[1] = GST_ROUND_UP_4 (GST_ROUND_UP_4 (width) / 4);
1297 info->stride[2] = info->stride[1];
1298 info->offset[0] = 0;
1299 info->offset[2] = info->stride[0] * height;
1300 info->offset[1] = info->offset[2] +
1301 info->stride[1] * (GST_ROUND_UP_4 (height) / 4);
1302 info->size = info->offset[2] +
1303 info->stride[2] * (GST_ROUND_UP_4 (height) / 4);
1305 case GST_VIDEO_FORMAT_UNKNOWN:
1306 GST_ERROR ("invalid format");
1307 g_warning ("invalid format");
1314 * gst_video_format_convert:
1315 * @info: a #GstVideoInfo
1316 * @src_format: #GstFormat of the @src_value
1317 * @src_value: value to convert
1318 * @dest_format: #GstFormat of the @dest_value
1319 * @dest_value: pointer to destination value
1321 * Converts among various #GstFormat types. This function handles
1322 * GST_FORMAT_BYTES, GST_FORMAT_TIME, and GST_FORMAT_DEFAULT. For
1323 * raw video, GST_FORMAT_DEFAULT corresponds to video frames. This
1324 * function can be used to handle pad queries of the type GST_QUERY_CONVERT.
1328 * Returns: TRUE if the conversion was successful.
1331 gst_video_info_convert (GstVideoInfo * info,
1332 GstFormat src_format, gint64 src_value,
1333 GstFormat dest_format, gint64 * dest_value)
1335 gboolean ret = FALSE;
1336 int size, fps_n, fps_d;
1338 g_return_val_if_fail (info != NULL, 0);
1339 g_return_val_if_fail (info->finfo != NULL, 0);
1340 g_return_val_if_fail (info->finfo->format != GST_VIDEO_FORMAT_UNKNOWN, 0);
1341 g_return_val_if_fail (info->size > 0, 0);
1344 fps_n = info->fps_n;
1345 fps_d = info->fps_d;
1347 GST_DEBUG ("converting value %" G_GINT64_FORMAT " from %s to %s",
1348 src_value, gst_format_get_name (src_format),
1349 gst_format_get_name (dest_format));
1351 if (src_format == dest_format) {
1352 *dest_value = src_value;
1357 if (src_value == -1) {
1363 /* bytes to frames */
1364 if (src_format == GST_FORMAT_BYTES && dest_format == GST_FORMAT_DEFAULT) {
1366 *dest_value = gst_util_uint64_scale_int (src_value, 1, size);
1368 GST_ERROR ("blocksize is 0");
1375 /* frames to bytes */
1376 if (src_format == GST_FORMAT_DEFAULT && dest_format == GST_FORMAT_BYTES) {
1377 *dest_value = gst_util_uint64_scale_int (src_value, size, 1);
1382 /* time to frames */
1383 if (src_format == GST_FORMAT_TIME && dest_format == GST_FORMAT_DEFAULT) {
1385 *dest_value = gst_util_uint64_scale (src_value,
1386 fps_n, GST_SECOND * fps_d);
1388 GST_ERROR ("framerate denominator is 0");
1395 /* frames to time */
1396 if (src_format == GST_FORMAT_DEFAULT && dest_format == GST_FORMAT_TIME) {
1398 *dest_value = gst_util_uint64_scale (src_value,
1399 GST_SECOND * fps_d, fps_n);
1401 GST_ERROR ("framerate numerator is 0");
1409 if (src_format == GST_FORMAT_TIME && dest_format == GST_FORMAT_BYTES) {
1411 *dest_value = gst_util_uint64_scale (src_value,
1412 fps_n * size, GST_SECOND * fps_d);
1414 GST_ERROR ("framerate denominator is 0");
1422 if (src_format == GST_FORMAT_BYTES && dest_format == GST_FORMAT_TIME) {
1423 if (fps_n != 0 && size != 0) {
1424 *dest_value = gst_util_uint64_scale (src_value,
1425 GST_SECOND * fps_d, fps_n * size);
1427 GST_ERROR ("framerate denominator and/or blocksize is 0");
1435 GST_DEBUG ("ret=%d result %" G_GINT64_FORMAT, ret, *dest_value);
1440 #define GST_VIDEO_EVENT_STILL_STATE_NAME "GstEventStillFrame"
1443 * gst_video_event_new_still_frame:
1444 * @in_still: boolean value for the still-frame state of the event.
1446 * Creates a new Still Frame event. If @in_still is %TRUE, then the event
1447 * represents the start of a still frame sequence. If it is %FALSE, then
1448 * the event ends a still frame sequence.
1450 * To parse an event created by gst_video_event_new_still_frame() use
1451 * gst_video_event_parse_still_frame().
1453 * Returns: The new GstEvent
1457 gst_video_event_new_still_frame (gboolean in_still)
1459 GstEvent *still_event;
1462 s = gst_structure_new (GST_VIDEO_EVENT_STILL_STATE_NAME,
1463 "still-state", G_TYPE_BOOLEAN, in_still, NULL);
1464 still_event = gst_event_new_custom (GST_EVENT_CUSTOM_DOWNSTREAM, s);
1470 * gst_video_event_parse_still_frame:
1471 * @event: A #GstEvent to parse
1472 * @in_still: A boolean to receive the still-frame status from the event, or NULL
1474 * Parse a #GstEvent, identify if it is a Still Frame event, and
1475 * return the still-frame state from the event if it is.
1476 * If the event represents the start of a still frame, the in_still
1477 * variable will be set to TRUE, otherwise FALSE. It is OK to pass NULL for the
1478 * in_still variable order to just check whether the event is a valid still-frame
1481 * Create a still frame event using gst_video_event_new_still_frame()
1483 * Returns: %TRUE if the event is a valid still-frame event. %FALSE if not
1487 gst_video_event_parse_still_frame (GstEvent * event, gboolean * in_still)
1489 const GstStructure *s;
1490 gboolean ev_still_state;
1492 g_return_val_if_fail (event != NULL, FALSE);
1494 if (GST_EVENT_TYPE (event) != GST_EVENT_CUSTOM_DOWNSTREAM)
1495 return FALSE; /* Not a still frame event */
1497 s = gst_event_get_structure (event);
1499 || !gst_structure_has_name (s, GST_VIDEO_EVENT_STILL_STATE_NAME))
1500 return FALSE; /* Not a still frame event */
1501 if (!gst_structure_get_boolean (s, "still-state", &ev_still_state))
1502 return FALSE; /* Not a still frame event */
1504 *in_still = ev_still_state;
1509 * gst_video_parse_caps_palette:
1510 * @caps: #GstCaps to parse
1512 * Returns the palette data from the caps as a #GstBuffer. For
1513 * #GST_VIDEO_FORMAT_RGB8_PALETTED this is containing 256 #guint32
1514 * values, each containing ARGB colors in native endianness.
1516 * Returns: a #GstBuffer containing the palette data. Unref after usage.
1520 gst_video_parse_caps_palette (GstCaps * caps)
1526 if (!gst_caps_is_fixed (caps))
1529 s = gst_caps_get_structure (caps, 0);
1531 p_v = gst_structure_get_value (s, "palette_data");
1532 if (!p_v || !GST_VALUE_HOLDS_BUFFER (p_v))
1535 p = g_value_dup_boxed (p_v);