60b50cf52990c2db7905ae3770798e3ab31392e2
[platform/upstream/gstreamer.git] / gst-libs / gst / video / video.h
1 /* GStreamer
2  * Copyright (C) <2011> Wim Taymans <wim.taymans@gmail.com>
3  *
4  * This library is free software; you can redistribute it and/or
5  * modify it under the terms of the GNU Library General Public
6  * License as published by the Free Software Foundation; either
7  * version 2 of the License, or (at your option) any later version.
8  *
9  * This library is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
12  * Library General Public License for more details.
13  *
14  * You should have received a copy of the GNU Library General Public
15  * License along with this library; if not, write to the
16  * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
17  * Boston, MA 02111-1307, USA.
18  */
19
20 #ifndef __GST_VIDEO_H__
21 #define __GST_VIDEO_H__
22
23 #include <gst/gst.h>
24
25 G_BEGIN_DECLS
26
27 #include <gst/video/video-enumtypes.h>
28
29 /**
30  * GstVideoFormat:
31  * @GST_VIDEO_FORMAT_UNKNOWN: Unknown or unset video format id
32  * @GST_VIDEO_FORMAT_I420: planar 4:2:0 YUV
33  * @GST_VIDEO_FORMAT_YV12: planar 4:2:0 YVU (like I420 but UV planes swapped)
34  * @GST_VIDEO_FORMAT_YUY2: packed 4:2:2 YUV (Y0-U0-Y1-V0 Y2-U2-Y3-V2 Y4 ...)
35  * @GST_VIDEO_FORMAT_UYVY: packed 4:2:2 YUV (U0-Y0-V0-Y1 U2-Y2-V2-Y3 U4 ...)
36  * @GST_VIDEO_FORMAT_AYUV: packed 4:4:4 YUV with alpha channel (A0-Y0-U0-V0 ...)
37  * @GST_VIDEO_FORMAT_RGBx: sparse rgb packed into 32 bit, space last
38  * @GST_VIDEO_FORMAT_BGRx: sparse reverse rgb packed into 32 bit, space last
39  * @GST_VIDEO_FORMAT_xRGB: sparse rgb packed into 32 bit, space first
40  * @GST_VIDEO_FORMAT_xBGR: sparse reverse rgb packed into 32 bit, space first
41  * @GST_VIDEO_FORMAT_RGBA: rgb with alpha channel last
42  * @GST_VIDEO_FORMAT_BGRA: reverse rgb with alpha channel last
43  * @GST_VIDEO_FORMAT_ARGB: rgb with alpha channel first
44  * @GST_VIDEO_FORMAT_ABGR: reverse rgb with alpha channel first
45  * @GST_VIDEO_FORMAT_RGB: rgb
46  * @GST_VIDEO_FORMAT_BGR: reverse rgb
47  * @GST_VIDEO_FORMAT_Y41B: planar 4:1:1 YUV (Since: 0.10.18)
48  * @GST_VIDEO_FORMAT_Y42B: planar 4:2:2 YUV (Since: 0.10.18)
49  * @GST_VIDEO_FORMAT_YVYU: packed 4:2:2 YUV (Y0-V0-Y1-U0 Y2-V2-Y3-U2 Y4 ...) (Since: 0.10.23)
50  * @GST_VIDEO_FORMAT_Y444: planar 4:4:4 YUV (Since: 0.10.24)
51  * @GST_VIDEO_FORMAT_v210: packed 4:2:2 10-bit YUV, complex format (Since: 0.10.24)
52  * @GST_VIDEO_FORMAT_v216: packed 4:2:2 16-bit YUV, Y0-U0-Y1-V1 order (Since: 0.10.24)
53  * @GST_VIDEO_FORMAT_NV12: planar 4:2:0 YUV with interleaved UV plane (Since: 0.10.26)
54  * @GST_VIDEO_FORMAT_NV21: planar 4:2:0 YUV with interleaved VU plane (Since: 0.10.26)
55  * @GST_VIDEO_FORMAT_GRAY8: 8-bit grayscale (Since: 0.10.29)
56  * @GST_VIDEO_FORMAT_GRAY16_BE: 16-bit grayscale, most significant byte first (Since: 0.10.29)
57  * @GST_VIDEO_FORMAT_GRAY16_LE: 16-bit grayscale, least significant byte first (Since: 0.10.29)
58  * @GST_VIDEO_FORMAT_v308: packed 4:4:4 YUV (Since: 0.10.29)
59  * @GST_VIDEO_FORMAT_Y800: same as GST_VIDEO_FORMAT_GRAY8 (Since: 0.10.30)
60  * @GST_VIDEO_FORMAT_Y16: same as GST_VIDEO_FORMAT_GRAY16_LE (Since: 0.10.30)
61  * @GST_VIDEO_FORMAT_RGB16: rgb 5-6-5 bits per component (Since: 0.10.30)
62  * @GST_VIDEO_FORMAT_BGR16: reverse rgb 5-6-5 bits per component (Since: 0.10.30)
63  * @GST_VIDEO_FORMAT_RGB15: rgb 5-5-5 bits per component (Since: 0.10.30)
64  * @GST_VIDEO_FORMAT_BGR15: reverse rgb 5-5-5 bits per component (Since: 0.10.30)
65  * @GST_VIDEO_FORMAT_UYVP: packed 10-bit 4:2:2 YUV (U0-Y0-V0-Y1 U2-Y2-V2-Y3 U4 ...) (Since: 0.10.31)
66  * @GST_VIDEO_FORMAT_A420: planar 4:4:2:0 AYUV (Since: 0.10.31)
67  * @GST_VIDEO_FORMAT_RGB8_PALETTED: 8-bit paletted RGB (Since: 0.10.32)
68  * @GST_VIDEO_FORMAT_YUV9: planar 4:1:0 YUV (Since: 0.10.32)
69  * @GST_VIDEO_FORMAT_YVU9: planar 4:1:0 YUV (like YUV9 but UV planes swapped) (Since: 0.10.32)
70  * @GST_VIDEO_FORMAT_IYU1: packed 4:1:1 YUV (Cb-Y0-Y1-Cr-Y2-Y3 ...) (Since: 0.10.32)
71  * @GST_VIDEO_FORMAT_ARGB64: rgb with alpha channel first, 16 bits per channel (Since: 0.10.33)
72  * @GST_VIDEO_FORMAT_AYUV64: packed 4:4:4 YUV with alpha channel, 16 bits per channel (A0-Y0-U0-V0 ...) (Since: 0.10.33)
73  * @GST_VIDEO_FORMAT_r210: packed 4:4:4 RGB, 10 bits per channel (Since: 0.10.33)
74  *
75  * Enum value describing the most common video formats.
76  */
77 typedef enum {
78   GST_VIDEO_FORMAT_UNKNOWN,
79   GST_VIDEO_FORMAT_I420,
80   GST_VIDEO_FORMAT_YV12,
81   GST_VIDEO_FORMAT_YUY2,
82   GST_VIDEO_FORMAT_UYVY,
83   GST_VIDEO_FORMAT_AYUV,
84   GST_VIDEO_FORMAT_RGBx,
85   GST_VIDEO_FORMAT_BGRx,
86   GST_VIDEO_FORMAT_xRGB,
87   GST_VIDEO_FORMAT_xBGR,
88   GST_VIDEO_FORMAT_RGBA,
89   GST_VIDEO_FORMAT_BGRA,
90   GST_VIDEO_FORMAT_ARGB,
91   GST_VIDEO_FORMAT_ABGR,
92   GST_VIDEO_FORMAT_RGB,
93   GST_VIDEO_FORMAT_BGR,
94   GST_VIDEO_FORMAT_Y41B,
95   GST_VIDEO_FORMAT_Y42B,
96   GST_VIDEO_FORMAT_YVYU,
97   GST_VIDEO_FORMAT_Y444,
98   GST_VIDEO_FORMAT_v210,
99   GST_VIDEO_FORMAT_v216,
100   GST_VIDEO_FORMAT_NV12,
101   GST_VIDEO_FORMAT_NV21,
102   GST_VIDEO_FORMAT_GRAY8,
103   GST_VIDEO_FORMAT_GRAY16_BE,
104   GST_VIDEO_FORMAT_GRAY16_LE,
105   GST_VIDEO_FORMAT_v308,
106   GST_VIDEO_FORMAT_Y800,
107   GST_VIDEO_FORMAT_Y16,
108   GST_VIDEO_FORMAT_RGB16,
109   GST_VIDEO_FORMAT_BGR16,
110   GST_VIDEO_FORMAT_RGB15,
111   GST_VIDEO_FORMAT_BGR15,
112   GST_VIDEO_FORMAT_UYVP,
113   GST_VIDEO_FORMAT_A420,
114   GST_VIDEO_FORMAT_RGB8_PALETTED,
115   GST_VIDEO_FORMAT_YUV9,
116   GST_VIDEO_FORMAT_YVU9,
117   GST_VIDEO_FORMAT_IYU1,
118   GST_VIDEO_FORMAT_ARGB64,
119   GST_VIDEO_FORMAT_AYUV64,
120   GST_VIDEO_FORMAT_r210
121 } GstVideoFormat;
122
123 #define GST_VIDEO_MAX_PLANES 4
124 #define GST_VIDEO_MAX_COMPONENTS 4
125
126 typedef struct _GstVideoFormatInfo GstVideoFormatInfo;
127
128 /**
129  * GstVideoFormatFlags:
130  * @GST_VIDEO_FORMAT_FLAG_YUV: The video format is YUV, components are numbered
131  *   0=Y, 1=U, 2=V.
132  * @GST_VIDEO_FORMAT_FLAG_RGB: The video format is RGB, components are numbered
133  *   0=R, 1=G, 2=B.
134  * @GST_VIDEO_FORMAT_FLAG_GRAY: The video is gray, there is one gray component
135  *   with index 0.
136  * @GST_VIDEO_FORMAT_FLAG_ALPHA: The video format has an alpha components with
137  *   the number 3.
138  * @GST_VIDEO_FORMAT_FLAG_LE: The video format has data stored in little
139  *   endianness.
140  * @GST_VIDEO_FORMAT_FLAG_PALETTE: The video format has a palette.
141  * @GST_VIDEO_FORMAT_FLAG_COMPLEX: The video format has a complex layout that
142  *   can't be described with the usual information in the #GstVideoFormatInfo.
143  *
144  * The different video flags that a format info can have.
145  */
146 typedef enum
147 {
148   GST_VIDEO_FORMAT_FLAG_YUV      = (1 << 0),
149   GST_VIDEO_FORMAT_FLAG_RGB      = (1 << 1),
150   GST_VIDEO_FORMAT_FLAG_GRAY     = (1 << 2),
151   GST_VIDEO_FORMAT_FLAG_ALPHA    = (1 << 3),
152   GST_VIDEO_FORMAT_FLAG_LE       = (1 << 4),
153   GST_VIDEO_FORMAT_FLAG_PALETTE  = (1 << 5),
154   GST_VIDEO_FORMAT_FLAG_COMPLEX  = (1 << 6)
155 } GstVideoFormatFlags;
156
157 #define GST_VIDEO_COMP_Y  0
158 #define GST_VIDEO_COMP_U  1
159 #define GST_VIDEO_COMP_V  2
160
161 #define GST_VIDEO_COMP_R  0
162 #define GST_VIDEO_COMP_G  1
163 #define GST_VIDEO_COMP_B  2
164
165 #define GST_VIDEO_COMP_A  3
166
167 /**
168  * GstVideoFormatUnpack:
169  * @info: a #GstVideoFormatInfo
170  * @dest: a destination array
171  * @data: pointers to the data planes
172  * @stride: strides of the planes
173  * @x: the x position in the image to start from
174  * @y: the y position in the image to start from
175  * @width: the amount of pixels to unpack.
176  *
177  * Unpacks @width pixels from the given planes and strides containing data of
178  * format @info. The pixels will be unpacked into @dest which each component
179  * interleaved. @dest should at least be big enough to hold @width *
180  * n_components * size(unpack_format) bytes.
181  */
182 typedef void (*GstVideoFormatUnpack)         (GstVideoFormatInfo *info, gpointer dest,
183                                               const gpointer data[GST_VIDEO_MAX_PLANES],
184                                               const gint stride[GST_VIDEO_MAX_PLANES],
185                                               gint x, gint y, gint width);
186 /**
187  * GstVideoFormatPack:
188  * @info: a #GstVideoFormatInfo
189  * @src: a source array
190  * @data: pointers to the destination data planes
191  * @stride: strides of the destination planes
192  * @x: the x position in the image to pack to
193  * @y: the y position in the image to pack to
194  * @width: the amount of pixels to pack.
195  *
196  * Packs @width pixels from @src to the given planes and strides in the
197  * format @info. The pixels from source have each component interleaved
198  * and will be packed into the planes in @data.
199  */
200 typedef void (*GstVideoFormatPack)           (GstVideoFormatInfo *info, const gpointer src,
201                                               gpointer data[GST_VIDEO_MAX_PLANES],
202                                               const gint stride[GST_VIDEO_MAX_PLANES],
203                                               gint x, gint y, gint width);
204
205 /**
206  * GstVideoFormatInfo:
207  * @format: #GstVideoFormat
208  * @name: string representation of the format
209  * @description: use readable description of the format
210  * @flags: #GstVideoFormatFlags
211  * @bits: The number of bits used to pack data items. This can be less than 8
212  *    when multiple pixels are stored in a byte. for values > 8 multiple bytes
213  *    should be read according to the endianness flag before applying the shift
214  *    and mask.
215  * @n_components: the number of components in the video format.
216  * @shift: the number of bits to shift away to get the component data
217  * @depth: the depth in bits for each component
218  * @pixel_stride: the pixel stride of each component. This is the amount of
219  *    bytes to the pixel immediately to the right. When bits < 8, the stride is
220  *    expressed in bits.
221  * @n_planes: the number of planes for this format. The number of planes can be
222  *    less than the amount of components when multiple components are packed into
223  *    one plane.
224  * @plane: the plane number where a component can be found
225  * @offset: the offset in the plane where the first pixel of the components
226  *    can be found. If bits < 8 the amount is specified in bits.
227  * @w_sub: subsampling factor of the width for the component. Use
228  *     GST_VIDEO_SUB_SCALE to scale a width.
229  * @h_sub: subsampling factor of the height for the component. Use
230  *     GST_VIDEO_SUB_SCALE to scale a height.
231  * @unpack_format: the format of the unpacked pixels.
232  * @unpack_func: an unpack function for this format
233  * @pack_func: an pack function for this format
234  *
235  * Information for a video format.
236  */
237 struct _GstVideoFormatInfo {
238   GstVideoFormat format;
239   const gchar *name;
240   const gchar *description;
241   GstVideoFormatFlags flags;
242   guint bits;
243   guint n_components;
244   guint shift[GST_VIDEO_MAX_COMPONENTS];
245   guint depth[GST_VIDEO_MAX_COMPONENTS];
246   gint  pixel_stride[GST_VIDEO_MAX_COMPONENTS];
247   guint n_planes;
248   guint plane[GST_VIDEO_MAX_COMPONENTS];
249   guint offset[GST_VIDEO_MAX_COMPONENTS];
250   guint w_sub[GST_VIDEO_MAX_COMPONENTS];
251   guint h_sub[GST_VIDEO_MAX_COMPONENTS];
252
253   GstVideoFormat unpack_format;
254   GstVideoFormatUnpack unpack_func;
255   GstVideoFormatPack pack_func;
256 };
257
258 #define GST_VIDEO_FORMAT_INFO_FORMAT(info)       ((info)->format)
259 #define GST_VIDEO_FORMAT_INFO_NAME(info)         ((info)->name)
260 #define GST_VIDEO_FORMAT_INFO_FLAGS(info)        ((info)->flags)
261
262 #define GST_VIDEO_FORMAT_INFO_IS_YUV(info)       ((info)->flags & GST_VIDEO_FORMAT_FLAG_YUV)
263 #define GST_VIDEO_FORMAT_INFO_IS_RGB(info)       ((info)->flags & GST_VIDEO_FORMAT_FLAG_RGB)
264 #define GST_VIDEO_FORMAT_INFO_IS_GRAY(info)      ((info)->flags & GST_VIDEO_FORMAT_FLAG_GRAY)
265 #define GST_VIDEO_FORMAT_INFO_HAS_ALPHA(info)    ((info)->flags & GST_VIDEO_FORMAT_FLAG_ALPHA)
266 #define GST_VIDEO_FORMAT_INFO_IS_LE(info)        ((info)->flags & GST_VIDEO_FORMAT_FLAG_LE)
267 #define GST_VIDEO_FORMAT_INFO_HAS_PALETTE(info)  ((info)->flags & GST_VIDEO_FORMAT_FLAG_PALETTE)
268
269 #define GST_VIDEO_FORMAT_INFO_BITS(info)         ((info)->bits)
270 #define GST_VIDEO_FORMAT_INFO_N_COMPONENTS(info) ((info)->n_components)
271 #define GST_VIDEO_FORMAT_INFO_SHIFT(info,c)      ((info)->shift[c])
272 #define GST_VIDEO_FORMAT_INFO_DEPTH(info,c)      ((info)->depth[c])
273 #define GST_VIDEO_FORMAT_INFO_PSTRIDE(info,c)    ((info)->pixel_stride[c])
274 #define GST_VIDEO_FORMAT_INFO_N_PLANES(info)     ((info)->n_planes)
275 #define GST_VIDEO_FORMAT_INFO_PLANE(info,c)      ((info)->plane[c])
276 #define GST_VIDEO_FORMAT_INFO_OFFSET(info,c)     ((info)->offset[c])
277 #define GST_VIDEO_FORMAT_INFO_W_SUB(info,c)      ((info)->w_sub[c])
278 #define GST_VIDEO_FORMAT_INFO_H_SUB(info,c)      ((info)->h_sub[c])
279
280 #define GST_VIDEO_SUB_SCALE(scale,val)   (-((-((gint)val))>>(scale)))
281
282 #define GST_VIDEO_FORMAT_INFO_SCALE_WIDTH(info,c,w)  GST_VIDEO_SUB_SCALE ((info)->w_sub[(c)],(w))
283 #define GST_VIDEO_FORMAT_INFO_SCALE_HEIGHT(info,c,h) GST_VIDEO_SUB_SCALE ((info)->h_sub[(c)],(h))
284
285 #define GST_VIDEO_FORMAT_INFO_DATA(info,planes,comp) \
286   (((guint8*)(planes)[info->plane[comp]]) + info->offset[comp])
287 #define GST_VIDEO_FORMAT_INFO_STRIDE(info,strides,comp) ((strides)[info->plane[comp]])
288
289 /* format properties */
290 GstVideoFormat gst_video_format_from_masks           (gint depth, gint bpp, gint endianness,
291                                                       gint red_mask, gint green_mask,
292                                                       gint blue_mask, gint alpha_mask) G_GNUC_CONST;
293
294 GstVideoFormat gst_video_format_from_fourcc          (guint32 fourcc) G_GNUC_CONST;
295 GstVideoFormat gst_video_format_from_string          (const gchar *format) G_GNUC_CONST;
296
297 guint32        gst_video_format_to_fourcc            (GstVideoFormat format) G_GNUC_CONST;
298 const gchar *  gst_video_format_to_string            (GstVideoFormat format) G_GNUC_CONST;
299
300 const GstVideoFormatInfo *
301                gst_video_format_get_info             (GstVideoFormat format) G_GNUC_CONST;
302
303 typedef struct _GstVideoInfo GstVideoInfo;
304 typedef struct _GstVideoFrame GstVideoFrame;
305
306 /**
307  * GstVideoFlags:
308  * @GST_VIDEO_FLAG_NONE: no flags
309  * @GST_VIDEO_FLAG_INTERLACED: The video is interlaced
310  * @GST_VIDEO_FLAG_TFF: The video has the top field first
311  * @GST_VIDEO_FLAG_RFF: The video has the repeat flag
312  * @GST_VIDEO_FLAG_ONEFIELD: one field
313  * @GST_VIDEO_FLAG_TELECINE: telecine
314  * @GST_VIDEO_FLAG_PROGRESSIVE: video is progressive
315  * @GST_VIDEO_FLAG_VARIABLE_FPS: a variable fps is selected, fps_n and fps_d
316  * denote the maximum fps of the video
317  *
318  * Extra video flags
319  */
320 typedef enum {
321   GST_VIDEO_FLAG_NONE         = 0,
322   GST_VIDEO_FLAG_INTERLACED   = (1 << 0),
323   GST_VIDEO_FLAG_TFF          = (1 << 1),
324   GST_VIDEO_FLAG_RFF          = (1 << 2),
325   GST_VIDEO_FLAG_ONEFIELD     = (1 << 3),
326   GST_VIDEO_FLAG_TELECINE     = (1 << 4),
327   GST_VIDEO_FLAG_PROGRESSIVE  = (1 << 5),
328   GST_VIDEO_FLAG_VARIABLE_FPS = (1 << 6)
329 } GstVideoFlags;
330
331 /**
332  * GstVideoChroma:
333  * @GST_VIDEO_CHROMA_SITE_UNKNOWN: unknown cositing
334  * @GST_VIDEO_CHROMA_SITE_NONE: no cositing
335  * @GST_VIDEO_CHROMA_SITE_H_COSITED: chroma is horizontally cosited
336  * @GST_VIDEO_CHROMA_SITE_V_COSITED: chroma is vertically cosited
337  * @GST_VIDEO_CHROMA_SITE_ALT_LINE: choma samples are sited on alternate lines
338  * @GST_VIDEO_CHROMA_SITE_COSITED: chroma samples cosited with luma samples
339  * @GST_VIDEO_CHROMA_SITE_JPEG: jpeg style cositing, also for mpeg1 and mjpeg
340  * @GST_VIDEO_CHROMA_SITE_MPEG2: mpeg2 style cositing
341  * @GST_VIDEO_CHROMA_SITE_DV: DV style cositing
342  *
343  * Various Chroma sitings.
344  */
345 typedef enum {
346   GST_VIDEO_CHROMA_SITE_UNKNOWN   =  0,
347   GST_VIDEO_CHROMA_SITE_NONE      = (1 << 0),
348   GST_VIDEO_CHROMA_SITE_H_COSITED = (1 << 1),
349   GST_VIDEO_CHROMA_SITE_V_COSITED = (1 << 2),
350   GST_VIDEO_CHROMA_SITE_ALT_LINE  = (1 << 3),
351   /* some common chroma cositing */
352   GST_VIDEO_CHROMA_SITE_COSITED   = (GST_VIDEO_CHROMA_SITE_H_COSITED | GST_VIDEO_CHROMA_SITE_V_COSITED),
353   GST_VIDEO_CHROMA_SITE_JPEG      = (GST_VIDEO_CHROMA_SITE_NONE),
354   GST_VIDEO_CHROMA_SITE_MPEG2     = (GST_VIDEO_CHROMA_SITE_H_COSITED),
355   GST_VIDEO_CHROMA_SITE_DV        = (GST_VIDEO_CHROMA_SITE_COSITED | GST_VIDEO_CHROMA_SITE_ALT_LINE),
356 } GstVideoChromaSite;
357
358 /**
359  * GstVideoColorRange:
360  * @GST_VIDEO_COLOR_RANGE_UNKNOWN: unknown range
361  * @GST_VIDEO_COLOR_RANGE_0_255: [0..255] for 8 bit components
362  * @GST_VIDEO_COLOR_RANGE_16_235: [16..235] for 8 bit components. Chroma has
363  *                 [16..240] range.
364  *
365  * Possible color range values. These constants are defined for 8 bit color
366  * values and can be scaled for other bit depths.
367  */
368 typedef enum {
369   GST_VIDEO_COLOR_RANGE_UNKNOWN = 0,
370   GST_VIDEO_COLOR_RANGE_0_255,
371   GST_VIDEO_COLOR_RANGE_16_235
372 } GstVideoColorRange;
373
374 /**
375  * GstVideoColorMatrix:
376  * @GST_VIDEO_COLOR_MATRIX_UNKNOWN: unknown matrix
377  * @GST_VIDEO_COLOR_MATRIX_RGB: identity matrix
378  * @GST_VIDEO_COLOR_MATRIX_FCC: FCC color matrix
379  * @GST_VIDEO_COLOR_MATRIX_BT709: ITU-R BT.709 color matrix
380  * @GST_VIDEO_COLOR_MATRIX_BT601: ITU-R BT.601 color matrix
381  * @GST_VIDEO_COLOR_MATRIX_SMPTE240M: SMPTE 240M color matrix
382  *
383  * The color matrix is used to convert between Y'PbPr and
384  * non-linear RGB (R'G'B')
385  */
386 typedef enum {
387   GST_VIDEO_COLOR_MATRIX_UNKNOWN = 0,
388   GST_VIDEO_COLOR_MATRIX_RGB,
389   GST_VIDEO_COLOR_MATRIX_FCC,
390   GST_VIDEO_COLOR_MATRIX_BT709,
391   GST_VIDEO_COLOR_MATRIX_BT601,
392   GST_VIDEO_COLOR_MATRIX_SMPTE240M
393 } GstVideoColorMatrix;
394
395 /**
396  * GstVideoTransferFunction:
397  * @GST_VIDEO_TRANSFER_UNKNOWN: unknown transfer function
398  * @GST_VIDEO_TRANSFER_GAMMA10: linear RGB, gamma 1.0 curve
399  * @GST_VIDEO_TRANSFER_GAMMA18: Gamma 1.8 curve
400  * @GST_VIDEO_TRANSFER_GAMMA20: Gamma 2.0 curve
401  * @GST_VIDEO_TRANSFER_GAMMA22: Gamma 2.2 curve
402  * @GST_VIDEO_TRANSFER_BT709: Gamma 2.2 curve with a linear segment in the lower
403  *                           range
404  * @GST_VIDEO_TRANSFER_SMPTE240M: Gamma 2.2 curve with a linear segment in the
405  *                               lower range
406  * @GST_VIDEO_TRANSFER_SRGB: Gamma 2.4 curve with a linear segment in the lower
407  *                          range
408  * @GST_VIDEO_TRANSFER_GAMMA28: Gamma 2.8 curve
409  * @GST_VIDEO_TRANSFER_LOG100: Logarithmic transfer characteristic
410  *                             100:1 range
411  * @GST_VIDEO_TRANSFER_LOG316: Logarithmic transfer characteristic
412  *                             316.22777:1 range
413  *
414  * The video transfer function defines the formula for converting between
415  * non-linear RGB (R'G'B') and linear RGB
416  */
417 typedef enum {
418   GST_VIDEO_TRANSFER_UNKNOWN = 0,
419   GST_VIDEO_TRANSFER_GAMMA10,
420   GST_VIDEO_TRANSFER_GAMMA18,
421   GST_VIDEO_TRANSFER_GAMMA20,
422   GST_VIDEO_TRANSFER_GAMMA22,
423   GST_VIDEO_TRANSFER_BT709,
424   GST_VIDEO_TRANSFER_SMPTE240M,
425   GST_VIDEO_TRANSFER_SRGB,
426   GST_VIDEO_TRANSFER_GAMMA28,
427   GST_VIDEO_TRANSFER_LOG100,
428   GST_VIDEO_TRANSFER_LOG316
429 } GstVideoTransferFunction;
430
431 /**
432  * GstVideoColorPrimaries:
433  * @GST_VIDEO_COLOR_PRIMARIES_UNKNOWN: unknown color primaries
434  * @GST_VIDEO_COLOR_PRIMARIES_BT709: BT709 primaries
435  * @GST_VIDEO_COLOR_PRIMARIES_BT470M: BT470M primaries
436  * @GST_VIDEO_COLOR_PRIMARIES_BT470BG: BT470BG primaries
437  * @GST_VIDEO_COLOR_PRIMARIES_SMPTE170M: SMPTE170M primaries
438  * @GST_VIDEO_COLOR_PRIMARIES_SMPTE240M: SMPTE240M primaries
439  *
440  * The color primaries define the how to transform linear RGB values to and from
441  * the CIE XYZ colorspace.
442  */
443 typedef enum {
444   GST_VIDEO_COLOR_PRIMARIES_UNKNOWN = 0,
445   GST_VIDEO_COLOR_PRIMARIES_BT709,
446   GST_VIDEO_COLOR_PRIMARIES_BT470M,
447   GST_VIDEO_COLOR_PRIMARIES_BT470BG,
448   GST_VIDEO_COLOR_PRIMARIES_SMPTE170M,
449   GST_VIDEO_COLOR_PRIMARIES_SMPTE240M
450 } GstVideoColorPrimaries;
451
452 /**
453  * GstVideoColorimetry:
454  * @range: the color range. This is the valid range for the samples.
455  *         It is used to convert the samples to Y'PbPr values.
456  * @matrix: the color matrix. Used to convert between Y'PbPr and
457  *          non-linear RGB (R'G'B')
458  * @transfer: the transfer function. used to convert between R'G'B' and RGB
459  * @primaries: color primaries. used to convert between R'G'B' and CIE XYZ
460  *
461  * Structure describing the color info.
462  */
463 typedef struct {
464   GstVideoColorRange        range;
465   GstVideoColorMatrix       matrix;
466   GstVideoTransferFunction  transfer;
467   GstVideoColorPrimaries    primaries;
468 } GstVideoColorimetry;
469
470 /* predefined colorimetry */
471 #define GST_VIDEO_COLORIMETRY_BT601       "bt601"
472 #define GST_VIDEO_COLORIMETRY_BT709       "bt709"
473 #define GST_VIDEO_COLORIMETRY_SMPTE240M   "smpte240m"
474
475 gboolean     gst_video_colorimetry_matches     (GstVideoColorimetry *cinfo, const gchar *color);
476 gboolean     gst_video_colorimetry_from_string (GstVideoColorimetry *cinfo, const gchar *color);
477 gchar *      gst_video_colorimetry_to_string   (GstVideoColorimetry *cinfo);
478
479 /**
480  * GstVideoInfo:
481  * @finfo: the format info of the video
482  * @flags: additional video flags
483  * @width: the width of the video
484  * @height: the height of the video
485  * @views: the number of views for multiview video
486  * @size: the default size of one frame
487  * @chroma_site: a #GstVideoChromaSite.
488  * @colorimetry: the colorimetry info
489  * @palette: a buffer with palette data
490  * @par_n: the pixel-aspect-ratio numerator
491  * @par_d: the pixel-aspect-ratio demnominator
492  * @fps_n: the framerate numerator
493  * @fps_d: the framerate demnominator
494  * @offset: offsets of the planes
495  * @stride: strides of the planes
496  *
497  * Information describing image properties. This information can be filled
498  * in from GstCaps with gst_video_info_from_caps(). The information is also used
499  * to store the specific video info when mapping a video frame with
500  * gst_video_frame_map().
501  *
502  * Use the provided macros to access the info in this structure.
503  */
504 struct _GstVideoInfo {
505   const GstVideoFormatInfo *finfo;
506   GstVideoFlags             flags;
507   gint                      width;
508   gint                      height;
509   gsize                     size;
510   gint                      views;
511
512   GstVideoChromaSite        chroma_site;
513   GstVideoColorimetry       colorimetry;
514
515   GstBuffer                *palette;
516
517   gint                      par_n;
518   gint                      par_d;
519   gint                      fps_n;
520   gint                      fps_d;
521
522   gsize                     offset[GST_VIDEO_MAX_PLANES];
523   gint                      stride[GST_VIDEO_MAX_PLANES];
524 };
525
526 /* general info */
527 #define GST_VIDEO_INFO_FORMAT(i)         (GST_VIDEO_FORMAT_INFO_FORMAT((i)->finfo))
528 #define GST_VIDEO_INFO_NAME(i)           (GST_VIDEO_FORMAT_INFO_NAME((i)->finfo))
529 #define GST_VIDEO_INFO_IS_YUV(i)         (GST_VIDEO_FORMAT_INFO_IS_YUV((i)->finfo))
530 #define GST_VIDEO_INFO_IS_RGB(i)         (GST_VIDEO_FORMAT_INFO_IS_RGB((i)->finfo))
531 #define GST_VIDEO_INFO_IS_GRAY(i)        (GST_VIDEO_FORMAT_INFO_IS_GRAY((i)->finfo))
532 #define GST_VIDEO_INFO_HAS_ALPHA(i)      (GST_VIDEO_FORMAT_INFO_HAS_ALPHA((i)->finfo))
533
534 #define GST_VIDEO_INFO_FLAGS(i)          ((i)->flags)
535 #define GST_VIDEO_INFO_WIDTH(i)          ((i)->width)
536 #define GST_VIDEO_INFO_HEIGHT(i)         ((i)->height)
537 #define GST_VIDEO_INFO_SIZE(i)           ((i)->size)
538 #define GST_VIDEO_INFO_VIEWS(i)          ((i)->views)
539 #define GST_VIDEO_INFO_PAR_N(i)          ((i)->par_n)
540 #define GST_VIDEO_INFO_PAR_D(i)          ((i)->par_d)
541 #define GST_VIDEO_INFO_FPS_N(i)          ((i)->fps_n)
542 #define GST_VIDEO_INFO_FPS_D(i)          ((i)->fps_d)
543
544 /* dealing with GstVideoInfo flags */
545 #define GST_VIDEO_INFO_FLAG_IS_SET(i,flag) ((GST_VIDEO_INFO_FLAGS(i) & (flag)) == (flag))
546 #define GST_VIDEO_INFO_FLAG_SET(i,flag)    (GST_VIDEO_INFO_FLAGS(i) |= (flag))
547 #define GST_VIDEO_INFO_FLAG_UNSET(i,flag)  (GST_VIDEO_INFO_FLAGS(i) &= ~(flag))
548
549 /* dealing with planes */
550 #define GST_VIDEO_INFO_N_PLANES(i)       (GST_VIDEO_FORMAT_INFO_N_PLANES((i)->finfo))
551 #define GST_VIDEO_INFO_PLANE_OFFSET(i,p) ((i)->offset[p])
552 #define GST_VIDEO_INFO_PLANE_STRIDE(i,p) ((i)->stride[p])
553
554 /* dealing with components */
555 #define GST_VIDEO_INFO_N_COMPONENTS(i)   GST_VIDEO_FORMAT_INFO_N_COMPONENTS((i)->finfo)
556 #define GST_VIDEO_INFO_COMP_DATA(i,d,c)  GST_VIDEO_FORMAT_INFO_DATA((i)->finfo,d,c)
557 #define GST_VIDEO_INFO_COMP_STRIDE(i,c)  GST_VIDEO_FORMAT_INFO_STRIDE((i)->finfo,(i)->stride,c)
558 #define GST_VIDEO_INFO_COMP_WIDTH(i,c)   GST_VIDEO_FORMAT_INFO_SCALE_WIDTH((i)->finfo,c,(i)->width)
559 #define GST_VIDEO_INFO_COMP_HEIGHT(i,c)  GST_VIDEO_FORMAT_INFO_SCALE_HEIGHT((i)->finfo,c,(i)->height)
560 #define GST_VIDEO_INFO_COMP_PLANE(i,c)   GST_VIDEO_FORMAT_INFO_PLANE((i)->finfo,c)
561 #define GST_VIDEO_INFO_COMP_OFFSET(i,c)  GST_VIDEO_FORMAT_INFO_OFFSET((i)->finfo,c)
562 #define GST_VIDEO_INFO_COMP_PSTRIDE(i,c) GST_VIDEO_FORMAT_INFO_PSTRIDE((i)->finfo,c)
563
564 void         gst_video_info_init        (GstVideoInfo *info);
565
566 void         gst_video_info_set_format  (GstVideoInfo *info, GstVideoFormat format,
567                                          guint width, guint height);
568
569 gboolean     gst_video_info_from_caps   (GstVideoInfo *info, const GstCaps  * caps);
570
571 GstCaps *    gst_video_info_to_caps     (GstVideoInfo *info);
572
573 gboolean     gst_video_info_convert     (GstVideoInfo *info,
574                                          GstFormat     src_format,
575                                          gint64        src_value,
576                                          GstFormat     dest_format,
577                                          gint64       *dest_value);
578
579 /**
580  * GstVideoFrame:
581  * @info: the #GstVideoInfo
582  * @buffer: the mapped buffer
583  * @meta: pointer to metadata if any
584  * @id: id of the mapped frame. the id can for example be used to
585  *   indentify the frame in case of multiview video.
586  * @data: pointers to the plane data
587  *
588  * A video frame obtained from gst_video_frame_map()
589  */
590 struct _GstVideoFrame {
591   GstVideoInfo info;
592
593   GstBuffer *buffer;
594   gpointer   meta;
595   gint       id;
596
597   gpointer   data[GST_VIDEO_MAX_PLANES];
598 };
599
600 gboolean    gst_video_frame_map           (GstVideoFrame *frame, GstVideoInfo *info,
601                                            GstBuffer *buffer, GstMapFlags flags);
602 gboolean    gst_video_frame_map_id        (GstVideoFrame *frame, GstVideoInfo *info,
603                                            GstBuffer *buffer, gint id, GstMapFlags flags);
604 void        gst_video_frame_unmap         (GstVideoFrame *frame);
605
606 gboolean    gst_video_frame_copy          (GstVideoFrame *dest, const GstVideoFrame *src);
607
608 /* general info */
609 #define GST_VIDEO_FRAME_FORMAT(f)         (GST_VIDEO_INFO_FORMAT(&(f)->info))
610 #define GST_VIDEO_FRAME_WIDTH(f)          (GST_VIDEO_INFO_WIDTH(&(f)->info))
611 #define GST_VIDEO_FRAME_HEIGHT(f)         (GST_VIDEO_INFO_HEIGHT(&(f)->info))
612 #define GST_VIDEO_FRAME_SIZE(f)           (GST_VIDEO_INFO_SIZE(&(f)->info))
613
614 /* dealing with planes */
615 #define GST_VIDEO_FRAME_N_PLANES(f)       (GST_VIDEO_INFO_N_PLANES(&(f)->info))
616 #define GST_VIDEO_FRAME_PLANE_DATA(f,p)   ((f)->data[p])
617 #define GST_VIDEO_FRAME_PLANE_OFFSET(f,p) (GST_VIDEO_INFO_PLANE_OFFSET(&(f)->info,p))
618 #define GST_VIDEO_FRAME_PLANE_STRIDE(f,p) (GST_VIDEO_INFO_PLANE_STRIDE(&(f)->info,p))
619
620 /* dealing with components */
621 #define GST_VIDEO_FRAME_N_COMPONENTS(f)   GST_VIDEO_INFO_N_COMPONENTS(&(f)->info)
622 #define GST_VIDEO_FRAME_COMP_DATA(f,c)    GST_VIDEO_INFO_COMP_DATA(&(f)->info,(f)->data,c)
623 #define GST_VIDEO_FRAME_COMP_STRIDE(f,c)  GST_VIDEO_INFO_COMP_STRIDE(&(f)->info,c)
624 #define GST_VIDEO_FRAME_COMP_WIDTH(f,c)   GST_VIDEO_INFO_COMP_WIDTH(&(f)->info,c)
625 #define GST_VIDEO_FRAME_COMP_HEIGHT(f,c)  GST_VIDEO_INFO_COMP_HEIGHT(&(f)->info,c)
626 #define GST_VIDEO_FRAME_COMP_PLANE(f,c)   GST_VIDEO_INFO_COMP_PLANE(&(f)->info,c)
627 #define GST_VIDEO_FRAME_COMP_OFFSET(f,c)  GST_VIDEO_INFO_COMP_OFFSET(&(f)->info,c)
628 #define GST_VIDEO_FRAME_COMP_PSTRIDE(f,c) GST_VIDEO_INFO_COMP_PSTRIDE(&(f)->info,c)
629
630 #define GST_VIDEO_SIZE_RANGE "(int) [ 1, max ]"
631 #define GST_VIDEO_FPS_RANGE "(fraction) [ 0, max ]"
632
633 #if G_BYTE_ORDER == G_LITTLE_ENDIAN
634 # define GST_VIDEO_NE(s) G_STRINGIFY(s)"_LE"
635 # define GST_VIDEO_OE(s) G_STRINGIFY(s)"_BE"
636 #else
637 # define GST_VIDEO_NE(s) G_STRINGIFY(s)"_BE"
638 # define GST_VIDEO_OE(s) G_STRINGIFY(s)"_LE"
639 #endif
640
641 #define GST_VIDEO_FORMATS_ALL "{ I420, YV12, YUY2, UYVY, AYUV, RGBx, "  \
642     "BGRx, xRGB, xBGR, RGBA, BGRA, ARGB, ABGR, RGB, BGR, Y41B, Y42B, "  \
643     "YVYU, Y444, v210, v216, NV12, NV21, GRAY8, GRAY16_BE, GRAY16_LE, " \
644     "v308, Y800, Y16, RGB16, BGR16, RGB15, BGR15, UYVP, A420, "         \
645     "RGB8_PALETTED, YUV9, YVU9, IYU1, ARGB64, AYUV64, r210 }"
646
647 /**
648  * GST_VIDEO_CAPS_MAKE:
649  * @format: string format that describes the pixel layout, as string
650  *     (e.g. "I420", "RGB", "YV12", "YUY2", "AYUV", etc.)
651  *
652  * Generic caps string for video, for use in pad templates.
653  */
654 #define GST_VIDEO_CAPS_MAKE(format)                                     \
655     "video/x-raw, "                                                     \
656     "format = (string) " format ", "                                    \
657     "width = " GST_VIDEO_SIZE_RANGE ", "                                \
658     "height = " GST_VIDEO_SIZE_RANGE ", "                               \
659     "framerate = " GST_VIDEO_FPS_RANGE
660
661 /* buffer flags */
662
663 /**
664  * GstVideoBufferFlags:
665  * @GST_VIDEO_BUFFER_FLAG_TFF:         If the #GstBuffer is interlaced, then the first field
666  *                                     in the video frame is the top field.  If unset, the
667  *                                     bottom field is first.
668  * @GST_VIDEO_BUFFER_FLAG_RFF:         If the #GstBuffer is interlaced, then the first field
669  *                                     (as defined by the %GST_VIDEO_BUFFER_TFF flag setting)
670  *                                     is repeated.
671  * @GST_VIDEO_BUFFER_FLAG_ONEFIELD:    If the #GstBuffer is interlaced, then only the
672  *                                     first field (as defined by the %GST_VIDEO_BUFFER_TFF
673  *                                     flag setting) is to be displayed.
674  * @GST_VIDEO_BUFFER_FLAG_PROGRESSIVE: If the #GstBuffer is telecined, then the
675  *                                     buffer is progressive if the %GST_VIDEO_BUFFER_PROGRESSIVE
676  *                                     flag is set, else it is telecine mixed.
677  *
678  * Additional video buffer flags.
679  */
680 typedef enum {
681   GST_VIDEO_BUFFER_FLAG_TFF         = (GST_BUFFER_FLAG_LAST << 0),
682   GST_VIDEO_BUFFER_FLAG_RFF         = (GST_BUFFER_FLAG_LAST << 1),
683   GST_VIDEO_BUFFER_FLAG_ONEFIELD    = (GST_BUFFER_FLAG_LAST << 2),
684   GST_VIDEO_BUFFER_FLAG_PROGRESSIVE = (GST_BUFFER_FLAG_LAST << 3),
685
686   GST_VIDEO_BUFFER_FLAG_LAST        = (GST_BUFFER_FLAG_LAST << 8)
687 } GstVideoBufferFlags;
688
689 /* some helper functions */
690 gboolean       gst_video_calculate_display_ratio (guint * dar_n,
691                                                   guint * dar_d,
692                                                   guint   video_width,
693                                                   guint   video_height,
694                                                   guint   video_par_n,
695                                                   guint   video_par_d,
696                                                   guint   display_par_n,
697                                                   guint   display_par_d);
698
699 GstBuffer *    gst_video_parse_caps_palette      (GstCaps * caps);
700
701 /* video still frame event creation and parsing */
702
703 GstEvent *     gst_video_event_new_still_frame   (gboolean in_still);
704
705 gboolean       gst_video_event_parse_still_frame (GstEvent * event, gboolean * in_still);
706
707 /* video force key unit event creation and parsing */
708
709 GstEvent * gst_video_event_new_downstream_force_key_unit (GstClockTime timestamp,
710                                                           GstClockTime streamtime,
711                                                           GstClockTime runningtime,
712                                                           gboolean all_headers,
713                                                           guint count);
714
715 gboolean gst_video_event_parse_downstream_force_key_unit (GstEvent * event,
716                                                           GstClockTime * timestamp,
717                                                           GstClockTime * streamtime,
718                                                           GstClockTime * runningtime,
719                                                           gboolean * all_headers,
720                                                           guint * count);
721
722 GstEvent * gst_video_event_new_upstream_force_key_unit (GstClockTime running_time,
723                                                         gboolean all_headers,
724                                                         guint count);
725
726 gboolean gst_video_event_parse_upstream_force_key_unit (GstEvent * event,
727                                                         GstClockTime * running_time,
728                                                         gboolean * all_headers,
729                                                         guint * count);
730
731 gboolean gst_video_event_is_force_key_unit(GstEvent *event);
732
733 /* convert/encode video sample from one format to another */
734
735 typedef void (*GstVideoConvertSampleCallback) (GstSample * sample, GError *error, gpointer user_data);
736
737 void          gst_video_convert_sample_async (GstSample                    * sample,
738                                               const GstCaps                * to_caps,
739                                               GstClockTime                   timeout,
740                                               GstVideoConvertSampleCallback  callback,
741                                               gpointer                       user_data,
742                                               GDestroyNotify                 destroy_notify);
743
744 GstSample *   gst_video_convert_sample       (GstSample     * sample,
745                                               const GstCaps * to_caps,
746                                               GstClockTime    timeout,
747                                               GError       ** error);
748 G_END_DECLS
749
750 #endif /* __GST_VIDEO_H__ */