video: add some more macros
[platform/upstream/gstreamer.git] / gst-libs / gst / video / video.h
1 /* GStreamer
2  * Copyright (C) <1999> Erik Walthinsen <omega@cse.ogi.edu>
3  * Library       <2002> Ronald Bultje <rbultje@ronald.bitfreak.net>
4  *
5  * This library is free software; you can redistribute it and/or
6  * modify it under the terms of the GNU Library General Public
7  * License as published by the Free Software Foundation; either
8  * version 2 of the License, or (at your option) any later version.
9  *
10  * This library is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
13  * Library General Public License for more details.
14  *
15  * You should have received a copy of the GNU Library General Public
16  * License along with this library; if not, write to the
17  * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
18  * Boston, MA 02111-1307, USA.
19  */
20
21 #ifndef __GST_VIDEO_H__
22 #define __GST_VIDEO_H__
23
24 #include <gst/gst.h>
25
26 G_BEGIN_DECLS
27
28 #include <gst/video/video-enumtypes.h>
29
30 /**
31  * GstVideoFormat:
32  * @GST_VIDEO_FORMAT_UNKNOWN: Unknown or unset video format id
33  * @GST_VIDEO_FORMAT_I420: planar 4:2:0 YUV
34  * @GST_VIDEO_FORMAT_YV12: planar 4:2:0 YVU (like I420 but UV planes swapped)
35  * @GST_VIDEO_FORMAT_YUY2: packed 4:2:2 YUV (Y0-U0-Y1-V0 Y2-U2-Y3-V2 Y4 ...)
36  * @GST_VIDEO_FORMAT_UYVY: packed 4:2:2 YUV (U0-Y0-V0-Y1 U2-Y2-V2-Y3 U4 ...)
37  * @GST_VIDEO_FORMAT_AYUV: packed 4:4:4 YUV with alpha channel (A0-Y0-U0-V0 ...)
38  * @GST_VIDEO_FORMAT_RGBx: sparse rgb packed into 32 bit, space last
39  * @GST_VIDEO_FORMAT_BGRx: sparse reverse rgb packed into 32 bit, space last
40  * @GST_VIDEO_FORMAT_xRGB: sparse rgb packed into 32 bit, space first
41  * @GST_VIDEO_FORMAT_xBGR: sparse reverse rgb packed into 32 bit, space first
42  * @GST_VIDEO_FORMAT_RGBA: rgb with alpha channel last
43  * @GST_VIDEO_FORMAT_BGRA: reverse rgb with alpha channel last
44  * @GST_VIDEO_FORMAT_ARGB: rgb with alpha channel first
45  * @GST_VIDEO_FORMAT_ABGR: reverse rgb with alpha channel first
46  * @GST_VIDEO_FORMAT_RGB: rgb
47  * @GST_VIDEO_FORMAT_BGR: reverse rgb
48  * @GST_VIDEO_FORMAT_Y41B: planar 4:1:1 YUV (Since: 0.10.18)
49  * @GST_VIDEO_FORMAT_Y42B: planar 4:2:2 YUV (Since: 0.10.18)
50  * @GST_VIDEO_FORMAT_YVYU: packed 4:2:2 YUV (Y0-V0-Y1-U0 Y2-V2-Y3-U2 Y4 ...) (Since: 0.10.23)
51  * @GST_VIDEO_FORMAT_Y444: planar 4:4:4 YUV (Since: 0.10.24)
52  * @GST_VIDEO_FORMAT_v210: packed 4:2:2 10-bit YUV, complex format (Since: 0.10.24)
53  * @GST_VIDEO_FORMAT_v216: packed 4:2:2 16-bit YUV, Y0-U0-Y1-V1 order (Since: 0.10.24)
54  * @GST_VIDEO_FORMAT_NV12: planar 4:2:0 YUV with interleaved UV plane (Since: 0.10.26)
55  * @GST_VIDEO_FORMAT_NV21: planar 4:2:0 YUV with interleaved VU plane (Since: 0.10.26)
56  * @GST_VIDEO_FORMAT_GRAY8: 8-bit grayscale (Since: 0.10.29)
57  * @GST_VIDEO_FORMAT_GRAY16_BE: 16-bit grayscale, most significant byte first (Since: 0.10.29)
58  * @GST_VIDEO_FORMAT_GRAY16_LE: 16-bit grayscale, least significant byte first (Since: 0.10.29)
59  * @GST_VIDEO_FORMAT_v308: packed 4:4:4 YUV (Since: 0.10.29)
60  * @GST_VIDEO_FORMAT_Y800: same as GST_VIDEO_FORMAT_GRAY8 (Since: 0.10.30)
61  * @GST_VIDEO_FORMAT_Y16: same as GST_VIDEO_FORMAT_GRAY16_LE (Since: 0.10.30)
62  * @GST_VIDEO_FORMAT_RGB16: rgb 5-6-5 bits per component (Since: 0.10.30)
63  * @GST_VIDEO_FORMAT_BGR16: reverse rgb 5-6-5 bits per component (Since: 0.10.30)
64  * @GST_VIDEO_FORMAT_RGB15: rgb 5-5-5 bits per component (Since: 0.10.30)
65  * @GST_VIDEO_FORMAT_BGR15: reverse rgb 5-5-5 bits per component (Since: 0.10.30)
66  * @GST_VIDEO_FORMAT_UYVP: packed 10-bit 4:2:2 YUV (U0-Y0-V0-Y1 U2-Y2-V2-Y3 U4 ...) (Since: 0.10.31)
67  * @GST_VIDEO_FORMAT_A420: planar 4:4:2:0 AYUV (Since: 0.10.31)
68  * @GST_VIDEO_FORMAT_RGB8_PALETTED: 8-bit paletted RGB (Since: 0.10.32)
69  * @GST_VIDEO_FORMAT_YUV9: planar 4:1:0 YUV (Since: 0.10.32)
70  * @GST_VIDEO_FORMAT_YVU9: planar 4:1:0 YUV (like YUV9 but UV planes swapped) (Since: 0.10.32)
71  * @GST_VIDEO_FORMAT_IYU1: packed 4:1:1 YUV (Cb-Y0-Y1-Cr-Y2-Y3 ...) (Since: 0.10.32)
72  * @GST_VIDEO_FORMAT_ARGB64: rgb with alpha channel first, 16 bits per channel (Since: 0.10.33)
73  * @GST_VIDEO_FORMAT_AYUV64: packed 4:4:4 YUV with alpha channel, 16 bits per channel (A0-Y0-U0-V0 ...) (Since: 0.10.33)
74  * @GST_VIDEO_FORMAT_r210: packed 4:4:4 RGB, 10 bits per channel (Since: 0.10.33)
75  *
76  * Enum value describing the most common video formats.
77  */
78 typedef enum {
79   GST_VIDEO_FORMAT_UNKNOWN,
80   GST_VIDEO_FORMAT_I420,
81   GST_VIDEO_FORMAT_YV12,
82   GST_VIDEO_FORMAT_YUY2,
83   GST_VIDEO_FORMAT_UYVY,
84   GST_VIDEO_FORMAT_AYUV,
85   GST_VIDEO_FORMAT_RGBx,
86   GST_VIDEO_FORMAT_BGRx,
87   GST_VIDEO_FORMAT_xRGB,
88   GST_VIDEO_FORMAT_xBGR,
89   GST_VIDEO_FORMAT_RGBA,
90   GST_VIDEO_FORMAT_BGRA,
91   GST_VIDEO_FORMAT_ARGB,
92   GST_VIDEO_FORMAT_ABGR,
93   GST_VIDEO_FORMAT_RGB,
94   GST_VIDEO_FORMAT_BGR,
95   GST_VIDEO_FORMAT_Y41B,
96   GST_VIDEO_FORMAT_Y42B,
97   GST_VIDEO_FORMAT_YVYU,
98   GST_VIDEO_FORMAT_Y444,
99   GST_VIDEO_FORMAT_v210,
100   GST_VIDEO_FORMAT_v216,
101   GST_VIDEO_FORMAT_NV12,
102   GST_VIDEO_FORMAT_NV21,
103   GST_VIDEO_FORMAT_GRAY8,
104   GST_VIDEO_FORMAT_GRAY16_BE,
105   GST_VIDEO_FORMAT_GRAY16_LE,
106   GST_VIDEO_FORMAT_v308,
107   GST_VIDEO_FORMAT_Y800,
108   GST_VIDEO_FORMAT_Y16,
109   GST_VIDEO_FORMAT_RGB16,
110   GST_VIDEO_FORMAT_BGR16,
111   GST_VIDEO_FORMAT_RGB15,
112   GST_VIDEO_FORMAT_BGR15,
113   GST_VIDEO_FORMAT_UYVP,
114   GST_VIDEO_FORMAT_A420,
115   GST_VIDEO_FORMAT_RGB8_PALETTED,
116   GST_VIDEO_FORMAT_YUV9,
117   GST_VIDEO_FORMAT_YVU9,
118   GST_VIDEO_FORMAT_IYU1,
119   GST_VIDEO_FORMAT_ARGB64,
120   GST_VIDEO_FORMAT_AYUV64,
121   GST_VIDEO_FORMAT_r210
122 } GstVideoFormat;
123
124 #define GST_VIDEO_MAX_PLANES 4
125 #define GST_VIDEO_MAX_COMPONENTS 4
126
127 typedef struct _GstVideoFormatInfo GstVideoFormatInfo;
128
129 /**
130  * GstVideoFormatFlags:
131  * @GST_VIDEO_FORMAT_FLAG_YUV: The video format is YUV, components are numbered
132  *   0=Y, 1=U, 2=V.
133  * @GST_VIDEO_FORMAT_FLAG_RGB: The video format is RGB, components are numbered
134  *   0=R, 1=G, 2=B.
135  * @GST_VIDEO_FORMAT_FLAG_GRAY: The video is gray, there is one gray component
136  *   with index 0.
137  * @GST_VIDEO_FORMAT_FLAG_ALPHA: The video format has an alpha components with
138  *   the number 3.
139  * @GST_VIDEO_FORMAT_FLAG_LE: The video format has data stored in little
140  *   endianness.
141  * @GST_VIDEO_FORMAT_FLAG_PALETTE: The video format has a palette.
142  * @GST_VIDEO_FORMAT_FLAG_COMPLEX: The video format has a complex layout that
143  *   can't be described with the usual information in the #GstVideoFormatInfo.
144  *
145  * The different video flags that a format info can have.
146  */
147 typedef enum
148 {
149   GST_VIDEO_FORMAT_FLAG_YUV      = (1 << 0),
150   GST_VIDEO_FORMAT_FLAG_RGB      = (1 << 1),
151   GST_VIDEO_FORMAT_FLAG_GRAY     = (1 << 2),
152   GST_VIDEO_FORMAT_FLAG_ALPHA    = (1 << 3),
153   GST_VIDEO_FORMAT_FLAG_LE       = (1 << 4),
154   GST_VIDEO_FORMAT_FLAG_PALETTE  = (1 << 5),
155   GST_VIDEO_FORMAT_FLAG_COMPLEX  = (1 << 6)
156 } GstVideoFormatFlags;
157
158 #define GST_VIDEO_COMP_Y  0
159 #define GST_VIDEO_COMP_U  1
160 #define GST_VIDEO_COMP_V  2
161
162 #define GST_VIDEO_COMP_R  0
163 #define GST_VIDEO_COMP_G  1
164 #define GST_VIDEO_COMP_B  2
165
166 #define GST_VIDEO_COMP_A  3
167
168 /**
169  * GstVideoFormatUnpack:
170  * @info: a #GstVideoFormatInfo
171  * @dest: a destination array
172  * @data: pointers to the data planes
173  * @stride: strides of the planes
174  * @x: the x position in the image to start from
175  * @y: the y position in the image to start from
176  * @width: the amount of pixels to unpack.
177  *
178  * Unpacks @width pixels from the given planes and strides containing data of
179  * format @info. The pixels will be unpacked into @dest which each component
180  * interleaved. @dest should at least be big enough to hold @width *
181  * n_components * unpack_size bytes.
182  */
183 typedef void (*GstVideoFormatUnpack)         (GstVideoFormatInfo *info, gpointer dest,
184                                               const gpointer data[GST_VIDEO_MAX_PLANES],
185                                               const gint stride[GST_VIDEO_MAX_PLANES],
186                                               gint x, gint y, gint width);
187 /**
188  * GstVideoFormatPack:
189  * @info: a #GstVideoFormatInfo
190  * @src: a source array
191  * @data: pointers to the destination data planes
192  * @stride: strides of the destination planes
193  * @x: the x position in the image to pack to
194  * @y: the y position in the image to pack to
195  * @width: the amount of pixels to pack.
196  *
197  * Packs @width pixels from @src to the given planes and strides in the
198  * format @info. The pixels from source have each component interleaved
199  * and will be packed into @src.
200  */
201 typedef void (*GstVideoFormatPack)           (GstVideoFormatInfo *info, const gpointer src,
202                                               gpointer data[GST_VIDEO_MAX_PLANES],
203                                               const gint stride[GST_VIDEO_MAX_PLANES],
204                                               gint x, gint y, gint width);
205
206 /**
207  * GstVideoFormatInfo:
208  * @format: #GstVideoFormat
209  * @name: string representation of the format
210  * @flags: #GstVideoFormatFlags
211  * @bits: The number of bits used to pack data items. This can be 8 when the
212  *    pixels are stored in bytes. for values > 8 multiple bytes should be read
213  *    according to the endianness flag before applying the shift and mask.
214  * @n_components: the number of components in the video format.
215  * @shift: the number of bits to shift away to get the component data
216  * @depth: the depth in bits for each component
217  * @pixel_stride: the pixel stride of each component. This is the amount of
218  *    bytes to the pixel immediately to the right. When bits < 8, the stride is
219  *    expressed in bits.
220  * @n_planes: the number of planes for this format. The number of planes can be
221  *    less than the amount of components when multiple components are packed into
222  *    one plane.
223  * @plane: the plane number where a component can be found
224  * @offset: the offset in the plane where the first pixel of the components
225  *    can be found. If bits < 8 the amount is specified in bits.
226  * @w_sub: subsampling factor of the width for the component. Use
227  *     GST_VIDEO_SUB_SCALE to scale a width.
228  * @h_sub: subsampling factor of the height for the component. Use
229  *     GST_VIDEO_SUB_SCALE to scale a height.
230  * @unpack_size: the size in bytes of each component item in the unpacked
231  *     format.
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   GstVideoFormatFlags flags;
241   guint bits;
242   guint n_components;
243   guint shift[GST_VIDEO_MAX_COMPONENTS];
244   guint depth[GST_VIDEO_MAX_COMPONENTS];
245   gint  pixel_stride[GST_VIDEO_MAX_COMPONENTS];
246   guint n_planes;
247   guint plane[GST_VIDEO_MAX_COMPONENTS];
248   guint offset[GST_VIDEO_MAX_COMPONENTS];
249   guint w_sub[GST_VIDEO_MAX_COMPONENTS];
250   guint h_sub[GST_VIDEO_MAX_COMPONENTS];
251
252   guint unpack_size;
253   GstVideoFormatUnpack unpack_func;
254   GstVideoFormatPack pack_func;
255 };
256
257 #define GST_VIDEO_FORMAT_INFO_FORMAT(info)       ((info)->format)
258 #define GST_VIDEO_FORMAT_INFO_NAME(info)         ((info)->name)
259 #define GST_VIDEO_FORMAT_INFO_FLAGS(info)        ((info)->flags)
260
261 #define GST_VIDEO_FORMAT_INFO_IS_YUV(info)       ((info)->flags & GST_VIDEO_FORMAT_FLAG_YUV)
262 #define GST_VIDEO_FORMAT_INFO_IS_RGB(info)       ((info)->flags & GST_VIDEO_FORMAT_FLAG_RGB)
263 #define GST_VIDEO_FORMAT_INFO_IS_GRAY(info)      ((info)->flags & GST_VIDEO_FORMAT_FLAG_GRAY)
264 #define GST_VIDEO_FORMAT_INFO_HAS_ALPHA(info)    ((info)->flags & GST_VIDEO_FORMAT_FLAG_ALPHA)
265
266 #define GST_VIDEO_FORMAT_INFO_N_COMPONENTS(info) ((info)->n_components)
267 #define GST_VIDEO_FORMAT_INFO_DEPTH(info,c)      ((info)->depth[c])
268 #define GST_VIDEO_FORMAT_INFO_PSTRIDE(info,c)    ((info)->pixel_stride[c])
269 #define GST_VIDEO_FORMAT_INFO_N_PLANES(info)     ((info)->n_planes)
270 #define GST_VIDEO_FORMAT_INFO_PLANE(info,c)      ((info)->plane[c])
271 #define GST_VIDEO_FORMAT_INFO_OFFSET(info,c)     ((info)->offset[c])
272 #define GST_VIDEO_FORMAT_INFO_W_SUB(info,c)      ((info)->w_sub[c])
273 #define GST_VIDEO_FORMAT_INFO_H_SUB(info,c)      ((info)->h_sub[c])
274
275 #define GST_VIDEO_SUB_SCALE(scale,val)   (-((-((gint)val))>>(scale)))
276
277 #define GST_VIDEO_FORMAT_INFO_SCALE_WIDTH(info,c,w)  GST_VIDEO_SUB_SCALE ((info)->w_sub[(c)],(w))
278 #define GST_VIDEO_FORMAT_INFO_SCALE_HEIGHT(info,c,h) GST_VIDEO_SUB_SCALE ((info)->h_sub[(c)],(h))
279
280 #define GST_VIDEO_FORMAT_INFO_DATA(info,planes,comp) \
281   (((guint8*)(planes)[info->plane[comp]]) + info->offset[comp])
282 #define GST_VIDEO_FORMAT_INFO_STRIDE(info,strides,comp) ((strides)[info->plane[comp]])
283
284 /* format properties */
285 GstVideoFormat gst_video_format_from_masks           (gint depth, gint bpp, gint endianness,
286                                                       gint red_mask, gint green_mask,
287                                                       gint blue_mask, gint alpha_mask) G_GNUC_CONST;
288
289 GstVideoFormat gst_video_format_from_fourcc          (guint32 fourcc) G_GNUC_CONST;
290 GstVideoFormat gst_video_format_from_string          (const gchar *format) G_GNUC_CONST;
291
292 guint32        gst_video_format_to_fourcc            (GstVideoFormat format) G_GNUC_CONST;
293 const gchar *  gst_video_format_to_string            (GstVideoFormat format) G_GNUC_CONST;
294
295 const GstVideoFormatInfo *
296                gst_video_format_get_info             (GstVideoFormat format) G_GNUC_CONST;
297
298 typedef struct _GstVideoInfo GstVideoInfo;
299 typedef struct _GstVideoFrame GstVideoFrame;
300
301 /**
302  * GstVideoFlags:
303  * @GST_META_VIDEO_FLAG_NONE: no flags
304  * @GST_META_VIDEO_FLAG_INTERLACED:
305  * @GST_META_VIDEO_FLAG_TTF:
306  * @GST_META_VIDEO_FLAG_RFF:
307  * @GST_META_VIDEO_FLAG_ONEFIELD:
308  * @GST_META_VIDEO_FLAG_TELECINE:
309  * @GST_META_VIDEO_FLAG_PROGRESSIVE:
310  *
311  * Extra video flags
312  */
313 typedef enum {
314   GST_VIDEO_FLAG_NONE        = 0,
315   GST_VIDEO_FLAG_INTERLACED  = (1 << 0),
316   GST_VIDEO_FLAG_TTF         = (1 << 1),
317   GST_VIDEO_FLAG_RFF         = (1 << 2),
318   GST_VIDEO_FLAG_ONEFIELD    = (1 << 3),
319   GST_VIDEO_FLAG_TELECINE    = (1 << 4),
320   GST_VIDEO_FLAG_PROGRESSIVE = (1 << 5)
321 } GstVideoFlags;
322
323 /**
324  * GstVideoInfo:
325  * @finfo: the format info of the video
326  * @flags: additional video flags
327  * @width: the width of the video
328  * @height: the height of the video
329  * @size: the default size of one frame
330  * @color_matrix: the color matrix.  Possible values are
331  *   "sdtv" for the standard definition color matrix (as specified in
332  *   Rec. ITU-R BT.470-6) or "hdtv" for the high definition color
333  *   matrix (as specified in Rec. ITU-R BT.709)
334  * @chroma_site: the chroma siting. Possible values are
335  *   "mpeg2" for MPEG-2 style chroma siting (co-sited horizontally,
336  *   halfway-sited vertically), "jpeg" for JPEG and Theora style
337  *   chroma siting (halfway-sited both horizontally and vertically).
338  *   Other chroma site values are possible, but uncommon.
339  * @palette: a buffer with palette data
340  * @par_n: the pixel-aspect-ratio numerator
341  * @par_d: the pixel-aspect-ratio demnominator
342  * @fps_n: the framerate numerator
343  * @fps_d: the framerate demnominator
344  * @offset: offsets of the planes
345  * @stride: strides of the planes
346  *
347  * Information describing image properties. This information can be filled
348  * in from GstCaps with gst_video_info_from_caps(). The information is also used
349  * to store the specific video info when mapping a video frame with
350  * gst_video_frame_map().
351  *
352  * Use the provided macros to access the info in this structure.
353  */
354 struct _GstVideoInfo {
355   const GstVideoFormatInfo *finfo;
356   GstVideoFlags             flags;
357   gint                      width;
358   gint                      height;
359   gsize                     size;
360
361   const gchar              *color_matrix;
362   const gchar              *chroma_site;
363   GstBuffer                *palette;
364
365   gint                      par_n;
366   gint                      par_d;
367   gint                      fps_n;
368   gint                      fps_d;
369
370   gsize                     offset[GST_VIDEO_MAX_PLANES];
371   gint                      stride[GST_VIDEO_MAX_PLANES];
372 };
373
374 /* general info */
375 #define GST_VIDEO_INFO_FORMAT(i)         (GST_VIDEO_FORMAT_INFO_FORMAT((i)->finfo))
376 #define GST_VIDEO_INFO_NAME(i)           (GST_VIDEO_FORMAT_INFO_NAME((i)->finfo))
377 #define GST_VIDEO_INFO_IS_YUV(i)         (GST_VIDEO_FORMAT_INFO_IS_YUV((i)->finfo))
378 #define GST_VIDEO_INFO_IS_RGB(i)         (GST_VIDEO_FORMAT_INFO_IS_RGB((i)->finfo))
379 #define GST_VIDEO_INFO_IS_GRAY(i)        (GST_VIDEO_FORMAT_INFO_IS_GRAY((i)->finfo))
380 #define GST_VIDEO_INFO_HAS_ALPHA(i)      (GST_VIDEO_FORMAT_INFO_HAS_ALPHA((i)->finfo))
381
382 #define GST_VIDEO_INFO_FLAGS(i)          ((i)->flags)
383 #define GST_VIDEO_INFO_WIDTH(i)          ((i)->width)
384 #define GST_VIDEO_INFO_HEIGHT(i)         ((i)->height)
385 #define GST_VIDEO_INFO_SIZE(i)           ((i)->size)
386 #define GST_VIDEO_INFO_PAR_N(i)          ((i)->par_n)
387 #define GST_VIDEO_INFO_PAR_D(i)          ((i)->par_d)
388 #define GST_VIDEO_INFO_FPS_N(i)          ((i)->fps_n)
389 #define GST_VIDEO_INFO_FPS_D(i)          ((i)->fps_d)
390
391 /* dealing with planes */
392 #define GST_VIDEO_INFO_N_PLANES(i)       (GST_VIDEO_FORMAT_INFO_N_PLANES((i)->finfo))
393 #define GST_VIDEO_INFO_PLANE_OFFSET(i,p) ((i)->offset[p])
394 #define GST_VIDEO_INFO_PLANE_STRIDE(i,p) ((i)->stride[p])
395
396 /* dealing with components */
397 #define GST_VIDEO_INFO_N_COMPONENTS(i)   GST_VIDEO_FORMAT_INFO_N_COMPONENTS((i)->finfo)
398 #define GST_VIDEO_INFO_COMP_DATA(i,d,c)  GST_VIDEO_FORMAT_INFO_DATA((i)->finfo,d,c)
399 #define GST_VIDEO_INFO_COMP_STRIDE(i,c)  GST_VIDEO_FORMAT_INFO_STRIDE((i)->finfo,(i)->stride,c)
400 #define GST_VIDEO_INFO_COMP_WIDTH(i,c)   GST_VIDEO_FORMAT_INFO_SCALE_WIDTH((i)->finfo,c,(i)->width)
401 #define GST_VIDEO_INFO_COMP_HEIGHT(i,c)  GST_VIDEO_FORMAT_INFO_SCALE_HEIGHT((i)->finfo,c,(i)->height)
402 #define GST_VIDEO_INFO_COMP_PLANE(i,c)   GST_VIDEO_FORMAT_INFO_PLANE((i)->finfo,c)
403 #define GST_VIDEO_INFO_COMP_OFFSET(i,c)  GST_VIDEO_FORMAT_INFO_OFFSET((i)->finfo,c)
404 #define GST_VIDEO_INFO_COMP_PSTRIDE(i,c) GST_VIDEO_FORMAT_INFO_PSTRIDE((i)->finfo,c)
405
406 void         gst_video_info_init        (GstVideoInfo *info);
407
408 void         gst_video_info_set_format  (GstVideoInfo *info, GstVideoFormat format,
409                                          guint width, guint height);
410
411 gboolean     gst_video_info_from_caps   (GstVideoInfo *info, const GstCaps  * caps);
412
413 GstCaps *    gst_video_info_to_caps     (GstVideoInfo *info);
414
415 gboolean     gst_video_info_convert     (GstVideoInfo *info,
416                                          GstFormat     src_format,
417                                          gint64        src_value,
418                                          GstFormat     dest_format,
419                                          gint64       *dest_value);
420
421 /**
422  * GstVideoFrame:
423  * @info: the #GstVideoInfo
424  * @buffer: the mapped buffer
425  * @meta: pointer to metadata if any
426  * @data: pointers to the plane data
427  *
428  * A video frame obtained from gst_video_frame_map()
429  */
430 struct _GstVideoFrame {
431   GstVideoInfo info;
432
433   GstBuffer *buffer;
434   gpointer   meta;
435
436   gpointer   data[GST_VIDEO_MAX_PLANES];
437 };
438
439 gboolean    gst_video_frame_map           (GstVideoFrame *frame, GstVideoInfo *info,
440                                            GstBuffer *buffer, GstMapFlags flags);
441 void        gst_video_frame_unmap         (GstVideoFrame *frame);
442
443 gboolean    gst_video_frame_copy          (GstVideoFrame *dest, const GstVideoFrame *src);
444
445 /* general info */
446 #define GST_VIDEO_FRAME_FORMAT(f)         (GST_VIDEO_INFO_FORMAT(&(f)->info))
447 #define GST_VIDEO_FRAME_WIDTH(f)          (GST_VIDEO_INFO_WIDTH(&(f)->info))
448 #define GST_VIDEO_FRAME_HEIGHT(f)         (GST_VIDEO_INFO_HEIGHT(&(f)->info))
449 #define GST_VIDEO_FRAME_SIZE(f)           (GST_VIDEO_INFO_SIZE(&(f)->info))
450
451 /* dealing with planes */
452 #define GST_VIDEO_FRAME_N_PLANES(f)       (GST_VIDEO_INFO_N_PLANES(&(f)->info))
453 #define GST_VIDEO_FRAME_PLANE_DATA(f,p)   ((f)->data[p])
454 #define GST_VIDEO_FRAME_PLANE_OFFSET(f,p) (GST_VIDEO_INFO_PLANE_OFFSET(&(f)->info,p))
455 #define GST_VIDEO_FRAME_PLANE_STRIDE(f,p) (GST_VIDEO_INFO_PLANE_STRIDE(&(f)->info,p))
456
457 /* dealing with components */
458 #define GST_VIDEO_FRAME_N_COMPONENTS(f)   GST_VIDEO_INFO_N_COMPONENTS(&(f)->info)
459 #define GST_VIDEO_FRAME_COMP_DATA(f,c)    GST_VIDEO_INFO_COMP_DATA(&(f)->info,(f)->data,c)
460 #define GST_VIDEO_FRAME_COMP_STRIDE(f,c)  GST_VIDEO_INFO_COMP_STRIDE(&(f)->info,c)
461 #define GST_VIDEO_FRAME_COMP_WIDTH(f,c)   GST_VIDEO_INFO_COMP_WIDTH(&(f)->info,c)
462 #define GST_VIDEO_FRAME_COMP_HEIGHT(f,c)  GST_VIDEO_INFO_COMP_HEIGHT(&(f)->info,c)
463 #define GST_VIDEO_FRAME_COMP_PLANE(f,c)   GST_VIDEO_INFO_COMP_PLANE(&(f)->info,c)
464 #define GST_VIDEO_FRAME_COMP_OFFSET(f,c)  GST_VIDEO_INFO_COMP_OFFSET(&(f)->info,c)
465 #define GST_VIDEO_FRAME_COMP_PSTRIDE(f,c) GST_VIDEO_INFO_COMP_PSTRIDE(&(f)->info,c)
466
467 #define GST_VIDEO_SIZE_RANGE "(int) [ 1, max ]"
468 #define GST_VIDEO_FPS_RANGE "(fraction) [ 0, max ]"
469
470 #define GST_VIDEO_FORMATS_ALL "{ I420, YV12, YUY2, UYVY, AYUV, RGBx, "  \
471     "BGRx, xRGB, xBGR, RGBA, BGRA, ARGB, ABGR, RGB, BGR, Y41B, Y42B, "  \
472     "YVYU, Y444, v210, v216, NV12, NV21, GRAY8, GRAY16_BE, GRAY16_LE, " \
473     "v308, Y800, Y16, RGB16, BGR16, RGB15, BGR15, UYVP, A420, "         \
474     "RGB8_PALETTED, YUV9, YVU9, IYU1, ARGB64, AYUV64, r210 }"
475
476 /**
477  * GST_VIDEO_CAPS_MAKE:
478  * @format: string format that describes the pixel layout, as string
479  *     (e.g. "I420", "RGB", "YV12", "YUY2", "AYUV", etc.)
480  *
481  * Generic caps string for video, for use in pad templates.
482  */
483 #define GST_VIDEO_CAPS_MAKE(format)                                     \
484     "video/x-raw, "                                                     \
485     "format = (string) " format ", "                                    \
486     "width = " GST_VIDEO_SIZE_RANGE ", "                                \
487     "height = " GST_VIDEO_SIZE_RANGE ", "                               \
488     "framerate = " GST_VIDEO_FPS_RANGE
489
490 /* buffer flags */
491
492 /**
493  * GST_VIDEO_BUFFER_TFF:
494  *
495  * If the #GstBuffer is interlaced, then the first field in the video frame is
496  * the top field.  If unset, the bottom field is first.
497  *
498  * Since: 0.10.23
499  */
500 #define GST_VIDEO_BUFFER_TFF GST_BUFFER_FLAG_MEDIA1
501
502 /**
503  * GST_VIDEO_BUFFER_RFF:
504  *
505  * If the #GstBuffer is interlaced, then the first field (as defined by the
506  * %GST_VIDEO_BUFFER_TFF flag setting) is repeated.
507  *
508  * Since: 0.10.23
509  */
510 #define GST_VIDEO_BUFFER_RFF GST_BUFFER_FLAG_MEDIA2
511
512 /**
513  * GST_VIDEO_BUFFER_ONEFIELD:
514  *
515  * If the #GstBuffer is interlaced, then only the first field (as defined by the
516  * %GST_VIDEO_BUFFER_TFF flag setting) is to be displayed.
517  *
518  * Since: 0.10.23
519  */
520 #define GST_VIDEO_BUFFER_ONEFIELD GST_BUFFER_FLAG_MEDIA3
521
522 /**
523  * GST_VIDEO_BUFFER_PROGRESSIVE:
524  *
525  * If the #GstBuffer is telecined, then the buffer is progressive if the
526  * %GST_VIDEO_BUFFER_PROGRESSIVE flag is set, else it is telecine mixed.
527  *
528  * Since: 0.10.33
529  */
530 #define GST_VIDEO_BUFFER_PROGRESSIVE GST_BUFFER_FLAG_MEDIA4
531
532 /* functions */
533 gboolean       gst_video_calculate_display_ratio (guint * dar_n,
534                                                   guint * dar_d,
535                                                   guint   video_width,
536                                                   guint   video_height,
537                                                   guint   video_par_n,
538                                                   guint   video_par_d,
539                                                   guint   display_par_n,
540                                                   guint   display_par_d);
541
542 gboolean       gst_video_parse_caps_framerate    (GstCaps * caps, int *fps_n, int *fps_d);
543 GstBuffer *    gst_video_parse_caps_palette      (GstCaps * caps);
544
545 /* video still frame event creation and parsing */
546
547 GstEvent *     gst_video_event_new_still_frame   (gboolean in_still);
548
549 gboolean       gst_video_event_parse_still_frame (GstEvent * event, gboolean * in_still);
550
551
552 /* convert/encode video frame from one format to another */
553
554 typedef void (*GstVideoConvertFrameCallback) (GstBuffer * buf, GError *error, gpointer user_data);
555
556 void           gst_video_convert_frame_async (GstBuffer                    * buf,
557                                               GstCaps                      * from_caps,
558                                               const GstCaps                * to_caps,
559                                               GstClockTime                   timeout,
560                                               GstVideoConvertFrameCallback   callback,
561                                               gpointer                       user_data,
562                                               GDestroyNotify                 destroy_notify);
563
564 GstBuffer *    gst_video_convert_frame       (GstBuffer     * buf,
565                                               GstCaps       * from_caps,
566                                               const GstCaps * to_caps,
567                                               GstClockTime    timeout,
568                                               GError       ** error);
569 G_END_DECLS
570
571 #endif /* __GST_VIDEO_H__ */