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.41 2002/01/07 02:12:29 sam Exp $
9 * Authors: Vincent Seguin <seguin@via.ecp.fr>
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.
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.
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 *****************************************************************************/
26 /*****************************************************************************
27 * plane_t: description of a planar graphic field
28 *****************************************************************************/
29 typedef struct plane_s
31 u8 *p_pixels; /* Start of the plane's data */
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 */
37 /* Size of a macropixel, defaults to 1 */
40 /* Is there a margin ? defaults to no */
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 ? */
47 /* Variables used for RGB planes */
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
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. */
68 plane_t p[ VOUT_MAX_PLANES ]; /* description of the planes */
69 int i_planes; /* number of allocated planes */
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 */
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 */
81 /* Picture dynamic properties - those properties can be changed by the
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 */
87 /* Macroblock counter - the decoder uses it to verify if it has
88 * decoded all the macroblocks of the picture */
90 vlc_mutex_t lock_deccount;
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;
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
104 int i_pictures; /* current heap size */
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 */
114 picture_t* pp_picture[VOUT_MAX_PICTURES]; /* pictures */
118 /*****************************************************************************
119 * Flags used to describe the status of a picture
120 *****************************************************************************/
123 #define EMPTY_PICTURE 0 /* empty buffer */
124 #define MEMORY_PICTURE 100 /* heap-allocated buffer */
125 #define DIRECT_PICTURE 200 /* direct buffer */
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 */
136 /*****************************************************************************
137 * Flags used to describe picture format - see http://www.webartz.com/fourcc/
138 *****************************************************************************/
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 */
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 */
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 */
163 /* Custom formats which we use but which don't exist in the fourcc database */
164 #define FOURCC_YMGA 0x41474d59 /* Planar Y, packed UV, from Matrox */
165 #define FOURCC_I422 0x32323449 /* Planar 4:2:2, Y:U:V */
166 #define FOURCC_I444 0x34343449 /* Planar 4:4:4, Y:U:V */
174 #define Y_PIXELS p[Y_PLANE].p_pixels
175 #define U_PIXELS p[U_PLANE].p_pixels
176 #define V_PIXELS p[V_PLANE].p_pixels
178 static __inline__ int vout_ChromaCmp( u32 i_chroma, u32 i_amorhc )
180 /* If they are the same, they are the same ! */
181 if( i_chroma == i_amorhc )
186 /* Check for equivalence classes */
234 /*****************************************************************************
235 * vout_CopyPicture: copy a picture to another one
236 *****************************************************************************
237 * This function takes advantage of the image format, and reduces the
238 * number of calls to memcpy() to the minimum. Source and destination
239 * images must have same width, height, and chroma.
240 *****************************************************************************/
241 static __inline__ void vout_CopyPicture( picture_t *p_src, picture_t *p_dest )
245 for( i = 0; i < p_src->i_planes ; i++ )
247 if( p_src->p[i].i_pitch == p_dest->p[i].i_pitch )
249 if( p_src->p[i].b_margin )
251 /* If p_src->b_margin is set, p_dest->b_margin must be set */
252 if( p_dest->p[i].b_hidden )
254 /* There are margins, but they are hidden : perfect ! */
255 FAST_MEMCPY( p_dest->p[i].p_pixels, p_src->p[i].p_pixels,
256 p_src->p[i].i_pitch * p_src->p[i].i_lines );
261 /* We can't directly copy the margin. Too bad. */
266 /* Same pitch, no margins : perfect ! */
267 FAST_MEMCPY( p_dest->p[i].p_pixels, p_src->p[i].p_pixels,
268 p_src->p[i].i_pitch * p_src->p[i].i_lines );
274 /* Pitch values are different */
277 /* We need to proceed line by line */
279 u8 *p_in = p_src->p[i].p_pixels, *p_out = p_dest->p[i].p_pixels;
282 for( i_line = p_src->p[i].i_lines; i_line--; )
284 FAST_MEMCPY( p_out, p_in, p_src->p[i].i_visible_bytes );
285 p_in += p_src->p[i].i_pitch;
286 p_out += p_dest->p[i].i_pitch;
292 /*****************************************************************************
293 * subpicture_t: video subtitle
294 *****************************************************************************
295 * Any subtitle destined to be displayed by a video output thread should
296 * be stored in this structure from it's creation to it's effective display.
297 * Subtitle type and flags should only be modified by the output thread. Note
298 * that an empty subtitle MUST have its flags set to 0.
299 *****************************************************************************/
300 typedef struct subpicture_s
302 /* Type and flags - should NOT be modified except by the vout thread */
303 int i_type; /* type */
304 int i_status; /* flags */
305 int i_size; /* data size */
306 struct subpicture_s * p_next; /* next subtitle to be displayed */
308 /* Date properties */
309 mtime_t i_start; /* beginning of display date */
310 mtime_t i_stop; /* end of display date */
311 boolean_t b_ephemer; /* does the subtitle have a TTL ? */
313 /* Display properties - these properties are only indicative and may be
314 * changed by the video output thread, or simply ignored depending of the
316 int i_x; /* offset from alignment position */
317 int i_y; /* offset from alignment position */
318 int i_width; /* picture width */
319 int i_height; /* picture height */
320 int i_horizontal_align; /* horizontal alignment */
321 int i_vertical_align; /* vertical alignment */
323 /* Additionnal properties depending of the subpicture type */
326 /* Text subpictures properties - text is stored in data area, in ASCIIZ
330 p_vout_font_t p_font; /* font, NULL for default */
331 int i_style; /* text style */
332 u32 i_char_color; /* character color */
333 u32 i_border_color; /* border color */
334 u32 i_bg_color; /* background color */
336 /* DVD subpicture units properties */
339 int i_offset[2]; /* byte offsets to data */
343 /* Subpicture data, format depends of type - data can always be freely
344 * modified. p_data itself (the pointer) should NEVER be modified. */
345 void * p_data; /* subpicture data */
348 /* Subpicture type */
349 #define EMPTY_SUBPICTURE 0 /* subtitle slot is empty and available */
350 #define DVD_SUBPICTURE 100 /* DVD subpicture unit */
351 #define TEXT_SUBPICTURE 200 /* single line text */
353 /* Subpicture status */
354 #define FREE_SUBPICTURE 0 /* free and not allocated */
355 #define RESERVED_SUBPICTURE 1 /* allocated and reserved */
356 #define READY_SUBPICTURE 2 /* ready for display */
357 #define DESTROYED_SUBPICTURE 3 /* allocated but not used anymore */
359 /* Alignment types */
360 #define RIGHT_ALIGN 10 /* x is absolute for right */
361 #define LEFT_ALIGN 11 /* x is absolute for left */
362 #define RIGHT_RALIGN 12 /* x is relative for right from right */
363 #define LEFT_RALIGN 13 /* x is relative for left from left */
365 #define CENTER_ALIGN 20 /* x, y are absolute for center */
366 #define CENTER_RALIGN 21 /* x,y are relative for center from center */
368 #define BOTTOM_ALIGN 30 /* y is absolute for bottom */
369 #define TOP_ALIGN 31 /* y is absolute for top */
370 #define BOTTOM_RALIGN 32 /* y is relative for bottom from bottom */
371 #define TOP_RALIGN 33 /* y is relative for top from top */
372 #define SUBTITLE_RALIGN 34 /* y is relative for center from subtitle */