win32: Add the new audio symbols to the list of exported symbols
[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  * @poffset: 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 poffset[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_POFFSET(info,c)    ((info)->poffset[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->poffset[comp])
287 #define GST_VIDEO_FORMAT_INFO_STRIDE(info,strides,comp) ((strides)[info->plane[comp]])
288 #define GST_VIDEO_FORMAT_INFO_OFFSET(info,offsets,comp) \
289   (((offsets)[info->plane[comp]]) + info->poffset[comp])
290
291 /* format properties */
292 GstVideoFormat gst_video_format_from_masks           (gint depth, gint bpp, gint endianness,
293                                                       gint red_mask, gint green_mask,
294                                                       gint blue_mask, gint alpha_mask) G_GNUC_CONST;
295
296 GstVideoFormat gst_video_format_from_fourcc          (guint32 fourcc) G_GNUC_CONST;
297 GstVideoFormat gst_video_format_from_string          (const gchar *format) G_GNUC_CONST;
298
299 guint32        gst_video_format_to_fourcc            (GstVideoFormat format) G_GNUC_CONST;
300 const gchar *  gst_video_format_to_string            (GstVideoFormat format) G_GNUC_CONST;
301
302 const GstVideoFormatInfo *
303                gst_video_format_get_info             (GstVideoFormat format) G_GNUC_CONST;
304
305 typedef struct _GstVideoInfo GstVideoInfo;
306 typedef struct _GstVideoFrame GstVideoFrame;
307
308 /**
309  * GstVideoInterlaceMode:
310  * @GST_VIDEO_INTERLACE_MODE_PROGRESSIVE: all frames are progressive
311  * @GST_VIDEO_INTERLACE_MODE_INTERLEAVED: video is interlaced and all fields
312  *     are interlaced in one frame.
313  * @GST_VIDEO_INTERLACE_MODE_MIXED: video contains both interlaced and
314  *     progressive frames, the buffer flags describe the frame and fields.
315  * @GST_VIDEO_INTERLACE_MODE_FIELDS: video is interlaced and fields are stored
316  *     separately. Use the id property to get access to the required field.
317  *
318  * The possible values of the #GstVideoInterlaceMode describing the interlace
319  * mode of the stream.
320  */
321 typedef enum {
322   GST_VIDEO_INTERLACE_MODE_PROGRESSIVE = 0,
323   GST_VIDEO_INTERLACE_MODE_INTERLEAVED,
324   GST_VIDEO_INTERLACE_MODE_MIXED,
325   GST_VIDEO_INTERLACE_MODE_FIELDS
326 } GstVideoInterlaceMode;
327
328 /**
329  * GstVideoFlags:
330  * @GST_VIDEO_FLAG_NONE: no flags
331  * @GST_VIDEO_FLAG_INTERLACED: The video is interlaced
332  * @GST_VIDEO_FLAG_TFF: The video has the top field first
333  * @GST_VIDEO_FLAG_RFF: The video has the repeat flag
334  * @GST_VIDEO_FLAG_ONEFIELD: one field
335  * @GST_VIDEO_FLAG_VARIABLE_FPS: a variable fps is selected, fps_n and fps_d
336  * denote the maximum fps of the video
337  *
338  * Extra video flags
339  */
340 typedef enum {
341   GST_VIDEO_FLAG_NONE         = 0,
342   GST_VIDEO_FLAG_INTERLACED   = (1 << 0),
343   GST_VIDEO_FLAG_TFF          = (1 << 1),
344   GST_VIDEO_FLAG_RFF          = (1 << 2),
345   GST_VIDEO_FLAG_ONEFIELD     = (1 << 3),
346   GST_VIDEO_FLAG_VARIABLE_FPS = (1 << 4)
347 } GstVideoFlags;
348
349 /**
350  * GstVideoChroma:
351  * @GST_VIDEO_CHROMA_SITE_UNKNOWN: unknown cositing
352  * @GST_VIDEO_CHROMA_SITE_NONE: no cositing
353  * @GST_VIDEO_CHROMA_SITE_H_COSITED: chroma is horizontally cosited
354  * @GST_VIDEO_CHROMA_SITE_V_COSITED: chroma is vertically cosited
355  * @GST_VIDEO_CHROMA_SITE_ALT_LINE: choma samples are sited on alternate lines
356  * @GST_VIDEO_CHROMA_SITE_COSITED: chroma samples cosited with luma samples
357  * @GST_VIDEO_CHROMA_SITE_JPEG: jpeg style cositing, also for mpeg1 and mjpeg
358  * @GST_VIDEO_CHROMA_SITE_MPEG2: mpeg2 style cositing
359  * @GST_VIDEO_CHROMA_SITE_DV: DV style cositing
360  *
361  * Various Chroma sitings.
362  */
363 typedef enum {
364   GST_VIDEO_CHROMA_SITE_UNKNOWN   =  0,
365   GST_VIDEO_CHROMA_SITE_NONE      = (1 << 0),
366   GST_VIDEO_CHROMA_SITE_H_COSITED = (1 << 1),
367   GST_VIDEO_CHROMA_SITE_V_COSITED = (1 << 2),
368   GST_VIDEO_CHROMA_SITE_ALT_LINE  = (1 << 3),
369   /* some common chroma cositing */
370   GST_VIDEO_CHROMA_SITE_COSITED   = (GST_VIDEO_CHROMA_SITE_H_COSITED | GST_VIDEO_CHROMA_SITE_V_COSITED),
371   GST_VIDEO_CHROMA_SITE_JPEG      = (GST_VIDEO_CHROMA_SITE_NONE),
372   GST_VIDEO_CHROMA_SITE_MPEG2     = (GST_VIDEO_CHROMA_SITE_H_COSITED),
373   GST_VIDEO_CHROMA_SITE_DV        = (GST_VIDEO_CHROMA_SITE_COSITED | GST_VIDEO_CHROMA_SITE_ALT_LINE),
374 } GstVideoChromaSite;
375
376 /**
377  * GstVideoColorRange:
378  * @GST_VIDEO_COLOR_RANGE_UNKNOWN: unknown range
379  * @GST_VIDEO_COLOR_RANGE_0_255: [0..255] for 8 bit components
380  * @GST_VIDEO_COLOR_RANGE_16_235: [16..235] for 8 bit components. Chroma has
381  *                 [16..240] range.
382  *
383  * Possible color range values. These constants are defined for 8 bit color
384  * values and can be scaled for other bit depths.
385  */
386 typedef enum {
387   GST_VIDEO_COLOR_RANGE_UNKNOWN = 0,
388   GST_VIDEO_COLOR_RANGE_0_255,
389   GST_VIDEO_COLOR_RANGE_16_235
390 } GstVideoColorRange;
391
392 /**
393  * GstVideoColorMatrix:
394  * @GST_VIDEO_COLOR_MATRIX_UNKNOWN: unknown matrix
395  * @GST_VIDEO_COLOR_MATRIX_RGB: identity matrix
396  * @GST_VIDEO_COLOR_MATRIX_FCC: FCC color matrix
397  * @GST_VIDEO_COLOR_MATRIX_BT709: ITU-R BT.709 color matrix
398  * @GST_VIDEO_COLOR_MATRIX_BT601: ITU-R BT.601 color matrix
399  * @GST_VIDEO_COLOR_MATRIX_SMPTE240M: SMPTE 240M color matrix
400  *
401  * The color matrix is used to convert between Y'PbPr and
402  * non-linear RGB (R'G'B')
403  */
404 typedef enum {
405   GST_VIDEO_COLOR_MATRIX_UNKNOWN = 0,
406   GST_VIDEO_COLOR_MATRIX_RGB,
407   GST_VIDEO_COLOR_MATRIX_FCC,
408   GST_VIDEO_COLOR_MATRIX_BT709,
409   GST_VIDEO_COLOR_MATRIX_BT601,
410   GST_VIDEO_COLOR_MATRIX_SMPTE240M
411 } GstVideoColorMatrix;
412
413 /**
414  * GstVideoTransferFunction:
415  * @GST_VIDEO_TRANSFER_UNKNOWN: unknown transfer function
416  * @GST_VIDEO_TRANSFER_GAMMA10: linear RGB, gamma 1.0 curve
417  * @GST_VIDEO_TRANSFER_GAMMA18: Gamma 1.8 curve
418  * @GST_VIDEO_TRANSFER_GAMMA20: Gamma 2.0 curve
419  * @GST_VIDEO_TRANSFER_GAMMA22: Gamma 2.2 curve
420  * @GST_VIDEO_TRANSFER_BT709: Gamma 2.2 curve with a linear segment in the lower
421  *                           range
422  * @GST_VIDEO_TRANSFER_SMPTE240M: Gamma 2.2 curve with a linear segment in the
423  *                               lower range
424  * @GST_VIDEO_TRANSFER_SRGB: Gamma 2.4 curve with a linear segment in the lower
425  *                          range
426  * @GST_VIDEO_TRANSFER_GAMMA28: Gamma 2.8 curve
427  * @GST_VIDEO_TRANSFER_LOG100: Logarithmic transfer characteristic
428  *                             100:1 range
429  * @GST_VIDEO_TRANSFER_LOG316: Logarithmic transfer characteristic
430  *                             316.22777:1 range
431  *
432  * The video transfer function defines the formula for converting between
433  * non-linear RGB (R'G'B') and linear RGB
434  */
435 typedef enum {
436   GST_VIDEO_TRANSFER_UNKNOWN = 0,
437   GST_VIDEO_TRANSFER_GAMMA10,
438   GST_VIDEO_TRANSFER_GAMMA18,
439   GST_VIDEO_TRANSFER_GAMMA20,
440   GST_VIDEO_TRANSFER_GAMMA22,
441   GST_VIDEO_TRANSFER_BT709,
442   GST_VIDEO_TRANSFER_SMPTE240M,
443   GST_VIDEO_TRANSFER_SRGB,
444   GST_VIDEO_TRANSFER_GAMMA28,
445   GST_VIDEO_TRANSFER_LOG100,
446   GST_VIDEO_TRANSFER_LOG316
447 } GstVideoTransferFunction;
448
449 /**
450  * GstVideoColorPrimaries:
451  * @GST_VIDEO_COLOR_PRIMARIES_UNKNOWN: unknown color primaries
452  * @GST_VIDEO_COLOR_PRIMARIES_BT709: BT709 primaries
453  * @GST_VIDEO_COLOR_PRIMARIES_BT470M: BT470M primaries
454  * @GST_VIDEO_COLOR_PRIMARIES_BT470BG: BT470BG primaries
455  * @GST_VIDEO_COLOR_PRIMARIES_SMPTE170M: SMPTE170M primaries
456  * @GST_VIDEO_COLOR_PRIMARIES_SMPTE240M: SMPTE240M primaries
457  *
458  * The color primaries define the how to transform linear RGB values to and from
459  * the CIE XYZ colorspace.
460  */
461 typedef enum {
462   GST_VIDEO_COLOR_PRIMARIES_UNKNOWN = 0,
463   GST_VIDEO_COLOR_PRIMARIES_BT709,
464   GST_VIDEO_COLOR_PRIMARIES_BT470M,
465   GST_VIDEO_COLOR_PRIMARIES_BT470BG,
466   GST_VIDEO_COLOR_PRIMARIES_SMPTE170M,
467   GST_VIDEO_COLOR_PRIMARIES_SMPTE240M
468 } GstVideoColorPrimaries;
469
470 /**
471  * GstVideoColorimetry:
472  * @range: the color range. This is the valid range for the samples.
473  *         It is used to convert the samples to Y'PbPr values.
474  * @matrix: the color matrix. Used to convert between Y'PbPr and
475  *          non-linear RGB (R'G'B')
476  * @transfer: the transfer function. used to convert between R'G'B' and RGB
477  * @primaries: color primaries. used to convert between R'G'B' and CIE XYZ
478  *
479  * Structure describing the color info.
480  */
481 typedef struct {
482   GstVideoColorRange        range;
483   GstVideoColorMatrix       matrix;
484   GstVideoTransferFunction  transfer;
485   GstVideoColorPrimaries    primaries;
486 } GstVideoColorimetry;
487
488 /* predefined colorimetry */
489 #define GST_VIDEO_COLORIMETRY_BT601       "bt601"
490 #define GST_VIDEO_COLORIMETRY_BT709       "bt709"
491 #define GST_VIDEO_COLORIMETRY_SMPTE240M   "smpte240m"
492
493 gboolean     gst_video_colorimetry_matches     (GstVideoColorimetry *cinfo, const gchar *color);
494 gboolean     gst_video_colorimetry_from_string (GstVideoColorimetry *cinfo, const gchar *color);
495 gchar *      gst_video_colorimetry_to_string   (GstVideoColorimetry *cinfo);
496
497 /**
498  * GstVideoInfo:
499  * @finfo: the format info of the video
500  * @interlace_mode: the interlace mode
501  * @flags: additional video flags
502  * @width: the width of the video
503  * @height: the height of the video
504  * @views: the number of views for multiview video
505  * @size: the default size of one frame
506  * @chroma_site: a #GstVideoChromaSite.
507  * @colorimetry: the colorimetry info
508  * @palette: a buffer with palette data
509  * @par_n: the pixel-aspect-ratio numerator
510  * @par_d: the pixel-aspect-ratio demnominator
511  * @fps_n: the framerate numerator
512  * @fps_d: the framerate demnominator
513  * @offset: offsets of the planes
514  * @stride: strides of the planes
515  *
516  * Information describing image properties. This information can be filled
517  * in from GstCaps with gst_video_info_from_caps(). The information is also used
518  * to store the specific video info when mapping a video frame with
519  * gst_video_frame_map().
520  *
521  * Use the provided macros to access the info in this structure.
522  */
523 struct _GstVideoInfo {
524   const GstVideoFormatInfo *finfo;
525
526   GstVideoInterlaceMode     interlace_mode;
527   GstVideoFlags             flags;
528   gint                      width;
529   gint                      height;
530   gsize                     size;
531   gint                      views;
532
533   GstVideoChromaSite        chroma_site;
534   GstVideoColorimetry       colorimetry;
535
536   GstBuffer                *palette;
537
538   gint                      par_n;
539   gint                      par_d;
540   gint                      fps_n;
541   gint                      fps_d;
542
543   gsize                     offset[GST_VIDEO_MAX_PLANES];
544   gint                      stride[GST_VIDEO_MAX_PLANES];
545 };
546
547 /* general info */
548 #define GST_VIDEO_INFO_FORMAT(i)         (GST_VIDEO_FORMAT_INFO_FORMAT((i)->finfo))
549 #define GST_VIDEO_INFO_NAME(i)           (GST_VIDEO_FORMAT_INFO_NAME((i)->finfo))
550 #define GST_VIDEO_INFO_IS_YUV(i)         (GST_VIDEO_FORMAT_INFO_IS_YUV((i)->finfo))
551 #define GST_VIDEO_INFO_IS_RGB(i)         (GST_VIDEO_FORMAT_INFO_IS_RGB((i)->finfo))
552 #define GST_VIDEO_INFO_IS_GRAY(i)        (GST_VIDEO_FORMAT_INFO_IS_GRAY((i)->finfo))
553 #define GST_VIDEO_INFO_HAS_ALPHA(i)      (GST_VIDEO_FORMAT_INFO_HAS_ALPHA((i)->finfo))
554
555 #define GST_VIDEO_INFO_INTERLACE_MODE(i) ((i)->interlace_mode)
556 #define GST_VIDEO_INFO_IS_INTERLACED(i)  ((i)->interlace_mode != GST_VIDEO_INTERLACE_MODE_PROGRESSIVE)
557 #define GST_VIDEO_INFO_FLAGS(i)          ((i)->flags)
558 #define GST_VIDEO_INFO_WIDTH(i)          ((i)->width)
559 #define GST_VIDEO_INFO_HEIGHT(i)         ((i)->height)
560 #define GST_VIDEO_INFO_SIZE(i)           ((i)->size)
561 #define GST_VIDEO_INFO_VIEWS(i)          ((i)->views)
562 #define GST_VIDEO_INFO_PAR_N(i)          ((i)->par_n)
563 #define GST_VIDEO_INFO_PAR_D(i)          ((i)->par_d)
564 #define GST_VIDEO_INFO_FPS_N(i)          ((i)->fps_n)
565 #define GST_VIDEO_INFO_FPS_D(i)          ((i)->fps_d)
566
567 /* dealing with GstVideoInfo flags */
568 #define GST_VIDEO_INFO_FLAG_IS_SET(i,flag) ((GST_VIDEO_INFO_FLAGS(i) & (flag)) == (flag))
569 #define GST_VIDEO_INFO_FLAG_SET(i,flag)    (GST_VIDEO_INFO_FLAGS(i) |= (flag))
570 #define GST_VIDEO_INFO_FLAG_UNSET(i,flag)  (GST_VIDEO_INFO_FLAGS(i) &= ~(flag))
571
572 /* dealing with planes */
573 #define GST_VIDEO_INFO_N_PLANES(i)       (GST_VIDEO_FORMAT_INFO_N_PLANES((i)->finfo))
574 #define GST_VIDEO_INFO_PLANE_OFFSET(i,p) ((i)->offset[p])
575 #define GST_VIDEO_INFO_PLANE_STRIDE(i,p) ((i)->stride[p])
576
577 /* dealing with components */
578 #define GST_VIDEO_INFO_N_COMPONENTS(i)   GST_VIDEO_FORMAT_INFO_N_COMPONENTS((i)->finfo)
579 #define GST_VIDEO_INFO_COMP_DATA(i,d,c)  GST_VIDEO_FORMAT_INFO_DATA((i)->finfo,d,c)
580 #define GST_VIDEO_INFO_COMP_OFFSET(i,c)  GST_VIDEO_FORMAT_INFO_OFFSET((i)->finfo,(i)->offset,c)
581 #define GST_VIDEO_INFO_COMP_STRIDE(i,c)  GST_VIDEO_FORMAT_INFO_STRIDE((i)->finfo,(i)->stride,c)
582 #define GST_VIDEO_INFO_COMP_WIDTH(i,c)   GST_VIDEO_FORMAT_INFO_SCALE_WIDTH((i)->finfo,c,(i)->width)
583 #define GST_VIDEO_INFO_COMP_HEIGHT(i,c)  GST_VIDEO_FORMAT_INFO_SCALE_HEIGHT((i)->finfo,c,(i)->height)
584 #define GST_VIDEO_INFO_COMP_PLANE(i,c)   GST_VIDEO_FORMAT_INFO_PLANE((i)->finfo,c)
585 #define GST_VIDEO_INFO_COMP_PSTRIDE(i,c) GST_VIDEO_FORMAT_INFO_PSTRIDE((i)->finfo,c)
586 #define GST_VIDEO_INFO_COMP_POFFSET(i,c) GST_VIDEO_FORMAT_INFO_POFFSET((i)->finfo,c)
587
588 void         gst_video_info_init        (GstVideoInfo *info);
589
590 void         gst_video_info_set_format  (GstVideoInfo *info, GstVideoFormat format,
591                                          guint width, guint height);
592
593 gboolean     gst_video_info_from_caps   (GstVideoInfo *info, const GstCaps  * caps);
594
595 GstCaps *    gst_video_info_to_caps     (GstVideoInfo *info);
596
597 gboolean     gst_video_info_convert     (GstVideoInfo *info,
598                                          GstFormat     src_format,
599                                          gint64        src_value,
600                                          GstFormat     dest_format,
601                                          gint64       *dest_value);
602
603 /**
604  * GstVideoFrame:
605  * @info: the #GstVideoInfo
606  * @buffer: the mapped buffer
607  * @meta: pointer to metadata if any
608  * @id: id of the mapped frame. the id can for example be used to
609  *   indentify the frame in case of multiview video.
610  * @data: pointers to the plane data
611  *
612  * A video frame obtained from gst_video_frame_map()
613  */
614 struct _GstVideoFrame {
615   GstVideoInfo info;
616
617   GstBuffer *buffer;
618   gpointer   meta;
619   gint       id;
620
621   gpointer   data[GST_VIDEO_MAX_PLANES];
622 };
623
624 gboolean    gst_video_frame_map           (GstVideoFrame *frame, GstVideoInfo *info,
625                                            GstBuffer *buffer, GstMapFlags flags);
626 gboolean    gst_video_frame_map_id        (GstVideoFrame *frame, GstVideoInfo *info,
627                                            GstBuffer *buffer, gint id, GstMapFlags flags);
628 void        gst_video_frame_unmap         (GstVideoFrame *frame);
629
630 gboolean    gst_video_frame_copy          (GstVideoFrame *dest, const GstVideoFrame *src);
631
632 /* general info */
633 #define GST_VIDEO_FRAME_FORMAT(f)         (GST_VIDEO_INFO_FORMAT(&(f)->info))
634 #define GST_VIDEO_FRAME_WIDTH(f)          (GST_VIDEO_INFO_WIDTH(&(f)->info))
635 #define GST_VIDEO_FRAME_HEIGHT(f)         (GST_VIDEO_INFO_HEIGHT(&(f)->info))
636 #define GST_VIDEO_FRAME_SIZE(f)           (GST_VIDEO_INFO_SIZE(&(f)->info))
637
638 /* dealing with planes */
639 #define GST_VIDEO_FRAME_N_PLANES(f)       (GST_VIDEO_INFO_N_PLANES(&(f)->info))
640 #define GST_VIDEO_FRAME_PLANE_DATA(f,p)   ((f)->data[p])
641 #define GST_VIDEO_FRAME_PLANE_OFFSET(f,p) (GST_VIDEO_INFO_PLANE_OFFSET(&(f)->info,p))
642 #define GST_VIDEO_FRAME_PLANE_STRIDE(f,p) (GST_VIDEO_INFO_PLANE_STRIDE(&(f)->info,p))
643
644 /* dealing with components */
645 #define GST_VIDEO_FRAME_N_COMPONENTS(f)   GST_VIDEO_INFO_N_COMPONENTS(&(f)->info)
646 #define GST_VIDEO_FRAME_COMP_DATA(f,c)    GST_VIDEO_INFO_COMP_DATA(&(f)->info,(f)->data,c)
647 #define GST_VIDEO_FRAME_COMP_STRIDE(f,c)  GST_VIDEO_INFO_COMP_STRIDE(&(f)->info,c)
648 #define GST_VIDEO_FRAME_COMP_OFFSET(f,c)  GST_VIDEO_INFO_COMP_OFFSET(&(f)->info,c)
649 #define GST_VIDEO_FRAME_COMP_WIDTH(f,c)   GST_VIDEO_INFO_COMP_WIDTH(&(f)->info,c)
650 #define GST_VIDEO_FRAME_COMP_HEIGHT(f,c)  GST_VIDEO_INFO_COMP_HEIGHT(&(f)->info,c)
651 #define GST_VIDEO_FRAME_COMP_PLANE(f,c)   GST_VIDEO_INFO_COMP_PLANE(&(f)->info,c)
652 #define GST_VIDEO_FRAME_COMP_PSTRIDE(f,c) GST_VIDEO_INFO_COMP_PSTRIDE(&(f)->info,c)
653 #define GST_VIDEO_FRAME_COMP_POFFSET(f,c) GST_VIDEO_INFO_COMP_POFFSET(&(f)->info,c)
654
655 #define GST_VIDEO_SIZE_RANGE "(int) [ 1, max ]"
656 #define GST_VIDEO_FPS_RANGE "(fraction) [ 0, max ]"
657
658 #if G_BYTE_ORDER == G_LITTLE_ENDIAN
659 # define GST_VIDEO_NE(s) G_STRINGIFY(s)"_LE"
660 # define GST_VIDEO_OE(s) G_STRINGIFY(s)"_BE"
661 #else
662 # define GST_VIDEO_NE(s) G_STRINGIFY(s)"_BE"
663 # define GST_VIDEO_OE(s) G_STRINGIFY(s)"_LE"
664 #endif
665
666 #define GST_VIDEO_FORMATS_ALL "{ I420, YV12, YUY2, UYVY, AYUV, RGBx, "  \
667     "BGRx, xRGB, xBGR, RGBA, BGRA, ARGB, ABGR, RGB, BGR, Y41B, Y42B, "  \
668     "YVYU, Y444, v210, v216, NV12, NV21, GRAY8, GRAY16_BE, GRAY16_LE, " \
669     "v308, Y800, Y16, RGB16, BGR16, RGB15, BGR15, UYVP, A420, "         \
670     "RGB8_PALETTED, YUV9, YVU9, IYU1, ARGB64, AYUV64, r210 }"
671
672 /**
673  * GST_VIDEO_CAPS_MAKE:
674  * @format: string format that describes the pixel layout, as string
675  *     (e.g. "I420", "RGB", "YV12", "YUY2", "AYUV", etc.)
676  *
677  * Generic caps string for video, for use in pad templates.
678  */
679 #define GST_VIDEO_CAPS_MAKE(format)                                     \
680     "video/x-raw, "                                                     \
681     "format = (string) " format ", "                                    \
682     "width = " GST_VIDEO_SIZE_RANGE ", "                                \
683     "height = " GST_VIDEO_SIZE_RANGE ", "                               \
684     "framerate = " GST_VIDEO_FPS_RANGE
685
686 /* buffer flags */
687
688 /**
689  * GstVideoBufferFlags:
690  * @GST_VIDEO_BUFFER_FLAG_INTERLACED:  Mark #GstBuffer as interlaced
691  * @GST_VIDEO_BUFFER_FLAG_TFF:         If the #GstBuffer is interlaced, then the first field
692  *                                     in the video frame is the top field.  If unset, the
693  *                                     bottom field is first.
694  * @GST_VIDEO_BUFFER_FLAG_RFF:         If the #GstBuffer is interlaced, then the first field
695  *                                     (as defined by the %GST_VIDEO_BUFFER_TFF flag setting)
696  *                                     is repeated.
697  * @GST_VIDEO_BUFFER_FLAG_ONEFIELD:    If the #GstBuffer is interlaced, then only the
698  *                                     first field (as defined by the %GST_VIDEO_BUFFER_TFF
699  *                                     flag setting) is to be displayed.
700  *
701  * Additional video buffer flags.
702  */
703 typedef enum {
704   GST_VIDEO_BUFFER_FLAG_INTERLACED  = (GST_BUFFER_FLAG_LAST << 0),
705   GST_VIDEO_BUFFER_FLAG_TFF         = (GST_BUFFER_FLAG_LAST << 1),
706   GST_VIDEO_BUFFER_FLAG_RFF         = (GST_BUFFER_FLAG_LAST << 2),
707   GST_VIDEO_BUFFER_FLAG_ONEFIELD    = (GST_BUFFER_FLAG_LAST << 3),
708
709   GST_VIDEO_BUFFER_FLAG_LAST        = (GST_BUFFER_FLAG_LAST << 8)
710 } GstVideoBufferFlags;
711
712 /* some helper functions */
713 gboolean       gst_video_calculate_display_ratio (guint * dar_n,
714                                                   guint * dar_d,
715                                                   guint   video_width,
716                                                   guint   video_height,
717                                                   guint   video_par_n,
718                                                   guint   video_par_d,
719                                                   guint   display_par_n,
720                                                   guint   display_par_d);
721
722 GstBuffer *    gst_video_parse_caps_palette      (GstCaps * caps);
723
724 /* video still frame event creation and parsing */
725
726 GstEvent *     gst_video_event_new_still_frame   (gboolean in_still);
727
728 gboolean       gst_video_event_parse_still_frame (GstEvent * event, gboolean * in_still);
729
730 /* video force key unit event creation and parsing */
731
732 GstEvent * gst_video_event_new_downstream_force_key_unit (GstClockTime timestamp,
733                                                           GstClockTime stream_time,
734                                                           GstClockTime running_time,
735                                                           gboolean all_headers,
736                                                           guint count);
737
738 gboolean gst_video_event_parse_downstream_force_key_unit (GstEvent * event,
739                                                           GstClockTime * timestamp,
740                                                           GstClockTime * stream_time,
741                                                           GstClockTime * running_time,
742                                                           gboolean * all_headers,
743                                                           guint * count);
744
745 GstEvent * gst_video_event_new_upstream_force_key_unit (GstClockTime running_time,
746                                                         gboolean all_headers,
747                                                         guint count);
748
749 gboolean gst_video_event_parse_upstream_force_key_unit (GstEvent * event,
750                                                         GstClockTime * running_time,
751                                                         gboolean * all_headers,
752                                                         guint * count);
753
754 gboolean gst_video_event_is_force_key_unit(GstEvent *event);
755
756 /* convert/encode video sample from one format to another */
757
758 typedef void (*GstVideoConvertSampleCallback) (GstSample * sample, GError *error, gpointer user_data);
759
760 void          gst_video_convert_sample_async (GstSample                    * sample,
761                                               const GstCaps                * to_caps,
762                                               GstClockTime                   timeout,
763                                               GstVideoConvertSampleCallback  callback,
764                                               gpointer                       user_data,
765                                               GDestroyNotify                 destroy_notify);
766
767 GstSample *   gst_video_convert_sample       (GstSample     * sample,
768                                               const GstCaps * to_caps,
769                                               GstClockTime    timeout,
770                                               GError       ** error);
771 G_END_DECLS
772
773 #endif /* __GST_VIDEO_H__ */