]> git.sesse.net Git - vlc/blob - include/vlc_video.h
66b3564f1c20aff3b5bf7a3005756cb12154f8a2
[vlc] / include / vlc_video.h
1 /*****************************************************************************
2  * vlc_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: vlc_video.h,v 1.5 2003/10/24 21:27:06 gbazin 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 #ifndef _VLC_VIDEO_H
26 #define _VLC_VIDEO_H 1
27
28 /**
29  * Description of a video frame
30  */
31 struct video_frame_format_t
32 {
33     vlc_fourcc_t i_chroma;                               /**< picture chroma */
34     unsigned int i_aspect;                                 /**< aspect ratio */
35
36     unsigned int i_width;                                 /**< picture width */
37     unsigned int i_height;                               /**< picture height */
38     unsigned int i_x_offset;               /**< start offset of visible area */
39     unsigned int i_y_offset;               /**< start offset of visible area */
40     unsigned int i_visible_width;                 /**< width of visible area */
41     unsigned int i_visible_height;               /**< height of visible area */
42
43     unsigned int i_bits_per_pixel;             /**< number of bits per pixel */
44
45 };
46
47 /**
48  * Description of a planar graphic field
49  */
50 typedef struct plane_t
51 {
52     uint8_t *p_pixels;                        /**< Start of the plane's data */
53
54     /* Variables used for fast memcpy operations */
55     int i_lines;                                        /**< Number of lines */
56     int i_pitch;           /**< Number of bytes in a line, including margins */
57
58     /** Size of a macropixel, defaults to 1 */
59     int i_pixel_pitch;
60
61     /* Variables used for pictures with margins */
62     int i_visible_pitch;            /**< How many visible pixels are there ? */
63
64 } plane_t;
65
66 /**
67  * Video picture
68  *
69  * Any picture destined to be displayed by a video output thread should be
70  * stored in this structure from it's creation to it's effective display.
71  * Picture type and flags should only be modified by the output thread. Note
72  * that an empty picture MUST have its flags set to 0.
73  */
74 struct picture_t
75 {
76     /** \name Picture format
77      * Describes the properties of the picture
78      * @{*/
79     video_frame_format_t format;
80     /**@}*/
81
82     /** Picture data - data can always be freely modified, but p_data may
83      * NEVER be modified. A direct buffer can be handled as the plugin
84      * wishes, it can even swap p_pixels buffers. */
85     uint8_t        *p_data;
86     void           *p_data_orig;                /**< pointer before memalign */
87     plane_t         p[ VOUT_MAX_PLANES ];     /**< description of the planes */
88     int             i_planes;                /**< number of allocated planes */
89
90     /** \name Type and flags
91      * Should NOT be modified except by the vout thread
92      * @{*/
93     int             i_status;                             /**< picture flags */
94     int             i_type;                /**< is picture a direct buffer ? */
95     int             i_matrix_coefficients;   /**< in YUV type, encoding type */
96     /**@}*/
97
98     /** \name Picture management properties
99      * These properties can be modified using the video output thread API,
100      * but should never be written directly */
101     /**@{*/
102     int             i_refcount;                  /**< link reference counter */
103     mtime_t         date;                                  /**< display date */
104     vlc_bool_t      b_force;
105     /**@}*/
106
107     /** \name Picture dynamic properties
108      * Those properties can be changed by the decoder
109      * @{
110      */
111     vlc_bool_t      b_progressive;          /**< is it a progressive frame ? */
112     unsigned int    i_nb_fields;                  /**< # of displayed fields */
113     vlc_bool_t      b_top_field_first;             /**< which field is first */
114     /**@}*/
115     
116     /** The picture heap we are attached to */
117     picture_heap_t* p_heap;
118
119     /* Some vouts require the picture to be locked before it can be modified */
120     int (* pf_lock) ( vout_thread_t *, picture_t * );
121     int (* pf_unlock) ( vout_thread_t *, picture_t * );
122
123     /** Private data - the video output plugin might want to put stuff here to
124      * keep track of the picture */
125     picture_sys_t * p_sys;
126 };
127
128 /**
129  * Video picture heap, either render (to store pictures used
130  * by the decoder) or output (to store pictures displayed by the vout plugin)
131  */
132 struct picture_heap_t
133 {
134     int i_pictures;                                   /**< current heap size */
135
136     /* \name Picture static properties
137      * Those properties are fixed at initialization and should NOT be modified
138      * @{
139      */
140     unsigned int i_width;                                 /**< picture width */
141     unsigned int i_height;                               /**< picture height */
142     vlc_fourcc_t i_chroma;                               /**< picture chroma */
143     unsigned int i_aspect;                                 /**< aspect ratio */
144     /**@}*/
145
146     /* Real pictures */
147     picture_t*      pp_picture[VOUT_MAX_PICTURES];             /**< pictures */
148     int             i_last_used_pic;              /**< last used pic in heap */
149     vlc_bool_t      b_allow_modify_pics;
150
151     /* Stuff used for truecolor RGB planes */
152     int i_rmask, i_rrshift, i_lrshift;
153     int i_gmask, i_rgshift, i_lgshift;
154     int i_bmask, i_rbshift, i_lbshift;
155
156     /** Stuff used for palettized RGB planes */
157     void (* pf_setpalette) ( vout_thread_t *, uint16_t *, uint16_t *, uint16_t * );
158 };
159
160 /*****************************************************************************
161  * Flags used to describe the status of a picture
162  *****************************************************************************/
163
164 /* Picture type */
165 #define EMPTY_PICTURE           0                            /* empty buffer */
166 #define MEMORY_PICTURE          100                 /* heap-allocated buffer */
167 #define DIRECT_PICTURE          200                         /* direct buffer */
168
169 /* Picture status */
170 #define FREE_PICTURE            0                  /* free and not allocated */
171 #define RESERVED_PICTURE        1                  /* allocated and reserved */
172 #define RESERVED_DATED_PICTURE  2              /* waiting for DisplayPicture */
173 #define RESERVED_DISP_PICTURE   3               /* waiting for a DatePicture */
174 #define READY_PICTURE           4                       /* ready for display */
175 #define DISPLAYED_PICTURE       5            /* been displayed but is linked */
176 #define DESTROYED_PICTURE       6              /* allocated but no more used */
177
178 /*****************************************************************************
179  * Shortcuts to access image components
180  *****************************************************************************/
181
182 /* Plane indices */
183 #define Y_PLANE      0
184 #define U_PLANE      1
185 #define V_PLANE      2
186
187 /* Shortcuts */
188 #define Y_PIXELS     p[Y_PLANE].p_pixels
189 #define Y_PITCH      p[Y_PLANE].i_pitch
190 #define U_PIXELS     p[U_PLANE].p_pixels
191 #define U_PITCH      p[U_PLANE].i_pitch
192 #define V_PIXELS     p[V_PLANE].p_pixels
193 #define V_PITCH      p[V_PLANE].i_pitch
194
195 /**
196  * \defgroup subpicture Video Subpictures
197  * Subpictures are pictures that should be displayed on top of the video, like
198  * subtitles and OSD
199  * \ingroup video_output
200  * @{
201  */
202
203 /**
204  * Video subtitle
205  *
206  * Any subtitle destined to be displayed by a video output thread should
207  * be stored in this structure from it's creation to it's effective display.
208  * Subtitle type and flags should only be modified by the output thread. Note
209  * that an empty subtitle MUST have its flags set to 0.
210  */
211 struct subpicture_t
212 {
213     /** \name Type and flags
214        Should NOT be modified except by the vout thread */
215     /**@{*/
216     int             i_type;                                        /**< type */
217     int             i_status;                                     /**< flags */
218     subpicture_t *  p_next;               /**< next subtitle to be displayed */
219     /**@}*/
220
221     /** \name Date properties */
222     /**@{*/
223     mtime_t         i_start;                  /**< beginning of display date */
224     mtime_t         i_stop;                         /**< end of display date */
225     vlc_bool_t      b_ephemer;     /**< If this flag is set to true
226                                       the subtitle will be displayed
227                                       untill the next one appear */
228     /**@}*/
229
230     /** \name Display properties
231      * These properties are only indicative and may be
232      * changed by the video output thread, or simply ignored depending of the
233      * subtitle type. */
234     /**@{*/
235     int             i_x;                 /**< offset from alignment position */
236     int             i_y;                 /**< offset from alignment position */
237     int             i_width;                              /**< picture width */
238     int             i_height;                            /**< picture height */
239     /**@}*/
240
241     /** Pointer to function that renders this subtitle in a picture */
242     void ( *pf_render )  ( vout_thread_t *, picture_t *, const subpicture_t * );
243     /** Pointer to function that cleans up the private data of this subtitle */
244     void ( *pf_destroy ) ( subpicture_t * );
245
246     /** Private data - the subtitle plugin might want to put stuff here to
247      * keep track of the subpicture */
248     subpicture_sys_t *p_sys;                              /* subpicture data */
249 };
250
251 /* Subpicture type */
252 #define EMPTY_SUBPICTURE       0     /* subtitle slot is empty and available */
253 #define MEMORY_SUBPICTURE      100            /* subpicture stored in memory */
254
255 /* Subpicture status */
256 #define FREE_SUBPICTURE        0                   /* free and not allocated */
257 #define RESERVED_SUBPICTURE    1                   /* allocated and reserved */
258 #define READY_SUBPICTURE       2                        /* ready for display */
259
260 /**@}*/
261
262 #endif /* _VLC_VIDEO_H */