Fix FSF address
[platform/upstream/gstreamer.git] / gst-libs / gst / video / video-info.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., 51 Franklin St, Fifth Floor,
17  * Boston, MA 02110-1301, USA.
18  */
19
20 #ifndef __GST_VIDEO_INFO_H__
21 #define __GST_VIDEO_INFO_H__
22
23 #include <gst/gst.h>
24 #include <gst/video/video-format.h>
25 #include <gst/video/video-color.h>
26
27 G_BEGIN_DECLS
28
29 #include <gst/video/video-enumtypes.h>
30
31 typedef struct _GstVideoInfo GstVideoInfo;
32
33 /**
34  * GstVideoInterlaceMode:
35  * @GST_VIDEO_INTERLACE_MODE_PROGRESSIVE: all frames are progressive
36  * @GST_VIDEO_INTERLACE_MODE_INTERLEAVED: 2 fields are interleaved in one video
37  *     frame. Extra buffer flags describe the field order.
38  * @GST_VIDEO_INTERLACE_MODE_MIXED: frames contains both interlaced and
39  *     progressive video, the buffer flags describe the frame and fields.
40  * @GST_VIDEO_INTERLACE_MODE_FIELDS: 2 fields are stored in one buffer, use the
41  *     frame ID to get access to the required field. For multiview (the
42  *     'views' property > 1) the fields of view N can be found at frame ID
43  *     (N * 2) and (N * 2) + 1.
44  *     Each field has only half the amount of lines as noted in the
45  *     height property. This mode requires multiple GstVideoMeta metadata
46  *     to describe the fields.
47  *
48  * The possible values of the #GstVideoInterlaceMode describing the interlace
49  * mode of the stream.
50  */
51 typedef enum {
52   GST_VIDEO_INTERLACE_MODE_PROGRESSIVE = 0,
53   GST_VIDEO_INTERLACE_MODE_INTERLEAVED,
54   GST_VIDEO_INTERLACE_MODE_MIXED,
55   GST_VIDEO_INTERLACE_MODE_FIELDS
56 } GstVideoInterlaceMode;
57
58 /**
59  * GstVideoFlags:
60  * @GST_VIDEO_FLAG_NONE: no flags
61  * @GST_VIDEO_FLAG_VARIABLE_FPS: a variable fps is selected, fps_n and fps_d
62  *     denote the maximum fps of the video
63  * @GST_VIDEO_FLAG_PREMULTIPLIED_ALPHA: Each color has been scaled by the alpha
64  *     value.
65  *
66  * Extra video flags
67  */
68 typedef enum {
69   GST_VIDEO_FLAG_NONE                = 0,
70   GST_VIDEO_FLAG_VARIABLE_FPS        = (1 << 0),
71   GST_VIDEO_FLAG_PREMULTIPLIED_ALPHA = (1 << 1)
72 } GstVideoFlags;
73
74 /**
75  * GstVideoInfo:
76  * @finfo: the format info of the video
77  * @interlace_mode: the interlace mode
78  * @flags: additional video flags
79  * @width: the width of the video
80  * @height: the height of the video
81  * @views: the number of views for multiview video
82  * @size: the default size of one frame
83  * @chroma_site: a #GstVideoChromaSite.
84  * @colorimetry: the colorimetry info
85  * @par_n: the pixel-aspect-ratio numerator
86  * @par_d: the pixel-aspect-ratio demnominator
87  * @fps_n: the framerate numerator
88  * @fps_d: the framerate demnominator
89  * @offset: offsets of the planes
90  * @stride: strides of the planes
91  *
92  * Information describing image properties. This information can be filled
93  * in from GstCaps with gst_video_info_from_caps(). The information is also used
94  * to store the specific video info when mapping a video frame with
95  * gst_video_frame_map().
96  *
97  * Use the provided macros to access the info in this structure.
98  */
99 struct _GstVideoInfo {
100   const GstVideoFormatInfo *finfo;
101
102   GstVideoInterlaceMode     interlace_mode;
103   GstVideoFlags             flags;
104   gint                      width;
105   gint                      height;
106   gsize                     size;
107   gint                      views;
108
109   GstVideoChromaSite        chroma_site;
110   GstVideoColorimetry       colorimetry;
111
112   gint                      par_n;
113   gint                      par_d;
114   gint                      fps_n;
115   gint                      fps_d;
116
117   gsize                     offset[GST_VIDEO_MAX_PLANES];
118   gint                      stride[GST_VIDEO_MAX_PLANES];
119
120   /*< private >*/
121   gpointer _gst_reserved[GST_PADDING];
122 };
123
124 /* general info */
125 #define GST_VIDEO_INFO_FORMAT(i)         (GST_VIDEO_FORMAT_INFO_FORMAT((i)->finfo))
126 #define GST_VIDEO_INFO_NAME(i)           (GST_VIDEO_FORMAT_INFO_NAME((i)->finfo))
127 #define GST_VIDEO_INFO_IS_YUV(i)         (GST_VIDEO_FORMAT_INFO_IS_YUV((i)->finfo))
128 #define GST_VIDEO_INFO_IS_RGB(i)         (GST_VIDEO_FORMAT_INFO_IS_RGB((i)->finfo))
129 #define GST_VIDEO_INFO_IS_GRAY(i)        (GST_VIDEO_FORMAT_INFO_IS_GRAY((i)->finfo))
130 #define GST_VIDEO_INFO_HAS_ALPHA(i)      (GST_VIDEO_FORMAT_INFO_HAS_ALPHA((i)->finfo))
131
132 #define GST_VIDEO_INFO_INTERLACE_MODE(i) ((i)->interlace_mode)
133 #define GST_VIDEO_INFO_IS_INTERLACED(i)  ((i)->interlace_mode != GST_VIDEO_INTERLACE_MODE_PROGRESSIVE)
134 #define GST_VIDEO_INFO_FLAGS(i)          ((i)->flags)
135 #define GST_VIDEO_INFO_WIDTH(i)          ((i)->width)
136 #define GST_VIDEO_INFO_HEIGHT(i)         ((i)->height)
137 #define GST_VIDEO_INFO_SIZE(i)           ((i)->size)
138 #define GST_VIDEO_INFO_VIEWS(i)          ((i)->views)
139 #define GST_VIDEO_INFO_PAR_N(i)          ((i)->par_n)
140 #define GST_VIDEO_INFO_PAR_D(i)          ((i)->par_d)
141 #define GST_VIDEO_INFO_FPS_N(i)          ((i)->fps_n)
142 #define GST_VIDEO_INFO_FPS_D(i)          ((i)->fps_d)
143
144 /* dealing with GstVideoInfo flags */
145 #define GST_VIDEO_INFO_FLAG_IS_SET(i,flag) ((GST_VIDEO_INFO_FLAGS(i) & (flag)) == (flag))
146 #define GST_VIDEO_INFO_FLAG_SET(i,flag)    (GST_VIDEO_INFO_FLAGS(i) |= (flag))
147 #define GST_VIDEO_INFO_FLAG_UNSET(i,flag)  (GST_VIDEO_INFO_FLAGS(i) &= ~(flag))
148
149 /* dealing with planes */
150 #define GST_VIDEO_INFO_N_PLANES(i)       (GST_VIDEO_FORMAT_INFO_N_PLANES((i)->finfo))
151 #define GST_VIDEO_INFO_PLANE_OFFSET(i,p) ((i)->offset[p])
152 #define GST_VIDEO_INFO_PLANE_STRIDE(i,p) ((i)->stride[p])
153
154 /* dealing with components */
155 #define GST_VIDEO_INFO_N_COMPONENTS(i)   GST_VIDEO_FORMAT_INFO_N_COMPONENTS((i)->finfo)
156 #define GST_VIDEO_INFO_COMP_DEPTH(i,c)   GST_VIDEO_FORMAT_INFO_DEPTH((i)->finfo,(c))
157 #define GST_VIDEO_INFO_COMP_DATA(i,d,c)  GST_VIDEO_FORMAT_INFO_DATA((i)->finfo,d,(c))
158 #define GST_VIDEO_INFO_COMP_OFFSET(i,c)  GST_VIDEO_FORMAT_INFO_OFFSET((i)->finfo,(i)->offset,(c))
159 #define GST_VIDEO_INFO_COMP_STRIDE(i,c)  GST_VIDEO_FORMAT_INFO_STRIDE((i)->finfo,(i)->stride,(c))
160 #define GST_VIDEO_INFO_COMP_WIDTH(i,c)   GST_VIDEO_FORMAT_INFO_SCALE_WIDTH((i)->finfo,(c),(i)->width)
161 #define GST_VIDEO_INFO_COMP_HEIGHT(i,c)  GST_VIDEO_FORMAT_INFO_SCALE_HEIGHT((i)->finfo,(c),(i)->height)
162 #define GST_VIDEO_INFO_COMP_PLANE(i,c)   GST_VIDEO_FORMAT_INFO_PLANE((i)->finfo,(c))
163 #define GST_VIDEO_INFO_COMP_PSTRIDE(i,c) GST_VIDEO_FORMAT_INFO_PSTRIDE((i)->finfo,(c))
164 #define GST_VIDEO_INFO_COMP_POFFSET(i,c) GST_VIDEO_FORMAT_INFO_POFFSET((i)->finfo,(c))
165
166 void         gst_video_info_init        (GstVideoInfo *info);
167
168 void         gst_video_info_set_format  (GstVideoInfo *info, GstVideoFormat format,
169                                          guint width, guint height);
170
171 gboolean     gst_video_info_from_caps   (GstVideoInfo *info, const GstCaps  * caps);
172
173 GstCaps *    gst_video_info_to_caps     (GstVideoInfo *info);
174
175 gboolean     gst_video_info_convert     (GstVideoInfo *info,
176                                          GstFormat     src_format,
177                                          gint64        src_value,
178                                          GstFormat     dest_format,
179                                          gint64       *dest_value);
180 gboolean     gst_video_info_is_equal    (const GstVideoInfo *info,
181                                          const GstVideoInfo *other);
182
183 #include <gst/video/video.h>
184
185 void         gst_video_info_align       (GstVideoInfo * info, GstVideoAlignment * align);
186
187
188 G_END_DECLS
189
190 #endif /* __GST_VIDEO_INFO_H__ */