]> git.sesse.net Git - vlc/blob - include/video.h
* ./BUGS: added a list of known bugs. Please add your findings!
[vlc] / include / video.h
1 /*****************************************************************************
2  * video.h: common video definitions
3  * This header is required by all modules which have to handle pictures. It
4  * includes all common video types and constants.
5  *****************************************************************************
6  * Copyright (C) 1999, 2000 VideoLAN
7  * $Id: video.h,v 1.39 2002/01/04 14:01:34 sam Exp $
8  *
9  * Authors: Vincent Seguin <seguin@via.ecp.fr>
10  *
11  * This program is free software; you can redistribute it and/or modify
12  * it under the terms of the GNU General Public License as published by
13  * the Free Software Foundation; either version 2 of the License, or
14  * (at your option) any later version.
15  * 
16  * This program is distributed in the hope that it will be useful,
17  * but WITHOUT ANY WARRANTY; without even the implied warranty of
18  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
19  * GNU General Public License for more details.
20  *
21  * You should have received a copy of the GNU General Public License
22  * along with this program; if not, write to the Free Software
23  * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111, USA.
24  *****************************************************************************/
25
26 /*****************************************************************************
27  * plane_t: description of a planar graphic field
28  *****************************************************************************/
29 typedef struct plane_s
30 {
31     u8 *p_pixels;                               /* Start of the plane's data */
32
33     /* Variables used for fast memcpy operations */
34     int i_lines;                                          /* Number of lines */
35     int i_pitch;             /* Number of bytes in a line, including margins */
36
37     /* Size of a macropixel, defaults to 1 */
38     int i_pixel_bytes;
39
40     /* Is there a margin ? defaults to no */
41     boolean_t b_margin;
42
43     /* Variables used for pictures with margins */
44     int i_visible_bytes;                 /* How many real pixels are there ? */
45     boolean_t b_hidden;           /* Are we allowed to write to the margin ? */
46
47     /* Variables used for RGB planes */
48     int i_red_mask;
49     int i_green_mask;
50     int i_blue_mask;
51
52 } plane_t;
53
54 /*****************************************************************************
55  * picture_t: video picture
56  *****************************************************************************
57  * Any picture destined to be displayed by a video output thread should be
58  * stored in this structure from it's creation to it's effective display.
59  * Picture type and flags should only be modified by the output thread. Note
60  * that an empty picture MUST have its flags set to 0.
61  *****************************************************************************/
62 typedef struct picture_s
63 {
64     /* Picture data - data can always be freely modified, but p_data may
65      * NEVER be modified. A direct buffer can be handled as the plugin
66      * wishes, it can even swap p_pixels buffers. */
67     u8             *p_data;
68     plane_t         p[ VOUT_MAX_PLANES ];       /* description of the planes */
69     int             i_planes;                  /* number of allocated planes */
70
71     /* Type and flags - should NOT be modified except by the vout thread */
72     int             i_status;                               /* picture flags */
73     int             i_type;                  /* is picture a direct buffer ? */
74     int             i_matrix_coefficients;     /* in YUV type, encoding type */
75
76     /* Picture management properties - these properties can be modified using
77      * the video output thread API, but should never be written directly */
78     int             i_refcount;                    /* link reference counter */
79     mtime_t         date;                                    /* display date */
80
81     /* Picture dynamic properties - those properties can be changed by the
82      * decoder */
83     boolean_t       b_progressive;            /* is it a progressive frame ? */
84     boolean_t       b_repeat_first_field;                         /* RFF bit */
85     boolean_t       b_top_field_first;               /* which field is first */
86
87     /* Macroblock counter - the decoder uses it to verify if it has
88      * decoded all the macroblocks of the picture */
89     int             i_deccount;
90     vlc_mutex_t     lock_deccount;
91
92     /* Private data - the video output plugin might want to put stuff here to
93      * keep track of the picture */
94     struct picture_sys_s *p_sys;
95
96 } picture_t;
97
98 /*****************************************************************************
99  * picture_heap_t: video picture heap, either render (to store pictures used
100  * by the decoder) or output (to store pictures displayed by the vout plugin)
101  *****************************************************************************/
102 typedef struct picture_heap_s
103 {
104     int             i_pictures;                         /* current heap size */
105
106     /* Picture static properties - those properties are fixed at initialization
107      * and should NOT be modified */
108     int             i_width;                                /* picture width */
109     int             i_height;                              /* picture height */
110     u32             i_chroma;                              /* picture chroma */
111     int             i_aspect;                                /* aspect ratio */
112
113     /* Real pictures */
114     picture_t*      pp_picture[VOUT_MAX_PICTURES];               /* pictures */
115
116 } picture_heap_t;
117
118 /*****************************************************************************
119  * Flags used to describe the status of a picture
120  *****************************************************************************/
121
122 /* Picture type */
123 #define EMPTY_PICTURE           0                            /* empty buffer */
124 #define MEMORY_PICTURE          100                 /* heap-allocated buffer */
125 #define DIRECT_PICTURE          200                         /* direct buffer */
126
127 /* Picture status */
128 #define FREE_PICTURE            0                  /* free and not allocated */
129 #define RESERVED_PICTURE        1                  /* allocated and reserved */
130 #define RESERVED_DATED_PICTURE  2              /* waiting for DisplayPicture */
131 #define RESERVED_DISP_PICTURE   3               /* waiting for a DatePicture */
132 #define READY_PICTURE           4                       /* ready for display */
133 #define DISPLAYED_PICTURE       5            /* been displayed but is linked */
134 #define DESTROYED_PICTURE       6              /* allocated but no more used */
135
136 /*****************************************************************************
137  * Flags used to describe picture format - see http://www.webartz.com/fourcc/
138  *****************************************************************************/
139
140 /* Packed RGB formats */
141 #define FOURCC_BI_RGB        0x00000000                      /* RGB for 8bpp */
142 #define FOURCC_RGB           0x32424752                  /* alias for BI_RGB */
143 #define FOURCC_BI_BITFIELDS  0x00000003            /* RGB, for 16, 24, 32bpp */
144 #define FOURCC_RV15          0x35315652    /* RGB 15bpp, 0x1f, 0x7e0, 0xf800 */
145 #define FOURCC_RV16          0x36315652    /* RGB 16bpp, 0x1f, 0x3e0, 0x7c00 */
146
147 /* Planar YUV formats */
148 #define FOURCC_I420          0x30323449               /* Planar 4:2:0, Y:U:V */
149 #define FOURCC_IYUV          0x56555949                    /* alias for I420 */
150 #define FOURCC_YV12          0x32315659               /* Planar 4:2:0, Y:V:U */
151
152 /* Packed YUV formats */
153 #define FOURCC_IUYV          0x56595549 /* Packed 4:2:2, U:Y:V:Y, interlaced */
154 #define FOURCC_UYVY          0x59565955             /* Packed 4:2:2, U:Y:V:Y */
155 #define FOURCC_UYNV          0x564e5955                    /* alias for UYVY */
156 #define FOURCC_Y422          0x32323459                    /* alias for UYVY */
157 #define FOURCC_cyuv          0x76757963   /* Packed 4:2:2, U:Y:V:Y, reverted */
158 #define FOURCC_YUY2          0x32595559             /* Packed 4:2:2, Y:U:Y:V */
159 #define FOURCC_YUNV          0x564e5559                    /* alias for YUY2 */
160 #define FOURCC_YVYU          0x55585659             /* Packed 4:2:2, Y:V:Y:U */
161 #define FOURCC_Y211          0x31313259             /* Packed 2:1:1, Y:U:Y:V */
162
163 /* Custom formats which we use but which don't exist in the fourcc database */
164 #define FOURCC_I422          0x32323449               /* Planar 4:2:2, Y:U:V */
165 #define FOURCC_I444          0x34343449               /* Planar 4:4:4, Y:U:V */
166
167 /* Plane indices */
168 #define Y_PLANE      0
169 #define U_PLANE      1
170 #define V_PLANE      2
171
172 /* Shortcuts */
173 #define Y_PIXELS     p[Y_PLANE].p_pixels
174 #define U_PIXELS     p[U_PLANE].p_pixels
175 #define V_PIXELS     p[V_PLANE].p_pixels
176
177 /*****************************************************************************
178  * vout_CopyPicture: copy a picture to another one
179  *****************************************************************************
180  * This function takes advantage of the image format, and reduces the
181  * number of calls to memcpy() to the minimum. Source and destination
182  * images must have same width, height, and chroma.
183  *****************************************************************************/
184 static __inline__ void vout_CopyPicture( picture_t *p_src, picture_t *p_dest )
185 {
186     int i;
187
188     for( i = 0; i < p_src->i_planes ; i++ )
189     {
190         if( p_src->p[i].i_pitch == p_dest->p[i].i_pitch )
191         {
192             if( p_src->p[i].b_margin )
193             {
194                 /* If p_src->b_margin is set, p_dest->b_margin must be set */
195                 if( p_dest->p[i].b_hidden )
196                 {
197                     /* There are margins, but they are hidden : perfect ! */
198                     FAST_MEMCPY( p_dest->p[i].p_pixels, p_src->p[i].p_pixels,
199                                  p_src->p[i].i_pitch * p_src->p[i].i_lines );
200                     continue;
201                 }
202                 else
203                 {
204                     /* We can't directly copy the margin. Too bad. */
205                 }
206             }
207             else
208             {
209                 /* Same pitch, no margins : perfect ! */
210                 FAST_MEMCPY( p_dest->p[i].p_pixels, p_src->p[i].p_pixels,
211                              p_src->p[i].i_pitch * p_src->p[i].i_lines );
212                 continue;
213             }
214         }
215         else
216         {
217             /* Pitch values are different */
218         }
219
220         /* We need to proceed line by line */
221         {
222             u8 *p_in = p_src->p[i].p_pixels, *p_out = p_dest->p[i].p_pixels;
223             int i_line;
224
225             for( i_line = p_src->p[i].i_lines; i_line--; )
226             {
227                 FAST_MEMCPY( p_out, p_in, p_src->p[i].i_visible_bytes );
228                 p_in += p_src->p[i].i_pitch;
229                 p_out += p_dest->p[i].i_pitch;
230             }
231         }
232     }
233 }
234
235 /*****************************************************************************
236  * subpicture_t: video subtitle
237  *****************************************************************************
238  * Any subtitle destined to be displayed by a video output thread should
239  * be stored in this structure from it's creation to it's effective display.
240  * Subtitle type and flags should only be modified by the output thread. Note
241  * that an empty subtitle MUST have its flags set to 0.
242  *****************************************************************************/
243 typedef struct subpicture_s
244 {
245     /* Type and flags - should NOT be modified except by the vout thread */
246     int             i_type;                                          /* type */
247     int             i_status;                                       /* flags */
248     int             i_size;                                     /* data size */
249     struct subpicture_s *   p_next;         /* next subtitle to be displayed */
250
251     /* Date properties */
252     mtime_t         i_start;                    /* beginning of display date */
253     mtime_t         i_stop;                           /* end of display date */
254     boolean_t       b_ephemer;             /* does the subtitle have a TTL ? */
255
256     /* Display properties - these properties are only indicative and may be
257      * changed by the video output thread, or simply ignored depending of the
258      * subtitle type. */
259     int             i_x;                   /* offset from alignment position */
260     int             i_y;                   /* offset from alignment position */
261     int             i_width;                                /* picture width */
262     int             i_height;                              /* picture height */
263     int             i_horizontal_align;              /* horizontal alignment */
264     int             i_vertical_align;                  /* vertical alignment */
265
266     /* Additionnal properties depending of the subpicture type */
267     union
268     {
269         /* Text subpictures properties - text is stored in data area, in ASCIIZ
270          * format */
271         struct
272         {
273             p_vout_font_t       p_font;            /* font, NULL for default */
274             int                 i_style;                       /* text style */
275             u32                 i_char_color;             /* character color */
276             u32                 i_border_color;              /* border color */
277             u32                 i_bg_color;              /* background color */
278         } text;
279         /* DVD subpicture units properties */
280         struct
281         {
282             int                 i_offset[2];         /* byte offsets to data */
283         } spu;
284     } type;
285
286     /* Subpicture data, format depends of type - data can always be freely
287      * modified. p_data itself (the pointer) should NEVER be modified. */
288     void *          p_data;                               /* subpicture data */
289 } subpicture_t;
290
291 /* Subpicture type */
292 #define EMPTY_SUBPICTURE       0     /* subtitle slot is empty and available */
293 #define DVD_SUBPICTURE         100                    /* DVD subpicture unit */
294 #define TEXT_SUBPICTURE        200                       /* single line text */
295
296 /* Subpicture status */
297 #define FREE_SUBPICTURE        0                   /* free and not allocated */
298 #define RESERVED_SUBPICTURE    1                   /* allocated and reserved */
299 #define READY_SUBPICTURE       2                        /* ready for display */
300 #define DESTROYED_SUBPICTURE   3           /* allocated but not used anymore */
301
302 /* Alignment types */
303 #define RIGHT_ALIGN            10                 /* x is absolute for right */
304 #define LEFT_ALIGN             11                  /* x is absolute for left */
305 #define RIGHT_RALIGN           12      /* x is relative for right from right */
306 #define LEFT_RALIGN            13        /* x is relative for left from left */
307
308 #define CENTER_ALIGN           20            /* x, y are absolute for center */
309 #define CENTER_RALIGN          21 /* x,y are relative for center from center */
310
311 #define BOTTOM_ALIGN           30                /* y is absolute for bottom */
312 #define TOP_ALIGN              31                   /* y is absolute for top */
313 #define BOTTOM_RALIGN          32    /* y is relative for bottom from bottom */
314 #define TOP_RALIGN             33          /* y is relative for top from top */
315 #define SUBTITLE_RALIGN        34  /* y is relative for center from subtitle */
316
317