]> git.sesse.net Git - vlc/blob - include/vlc_video.h
ed845d688a1887471fb22cdf0500810f3a7d3b52
[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 - 2005 the VideoLAN team
7  * $Id$
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 #include "vlc_es.h"
29
30 /**
31  * Description of a planar graphic field
32  */
33 typedef struct plane_t
34 {
35     uint8_t *p_pixels;                        /**< Start of the plane's data */
36
37     /* Variables used for fast memcpy operations */
38     int i_lines;           /**< Number of lines, including margins */
39     int i_pitch;           /**< Number of bytes in a line, including margins */
40
41     /** Size of a macropixel, defaults to 1 */
42     int i_pixel_pitch;
43
44     /* Variables used for pictures with margins */
45     int i_visible_lines;            /**< How many visible lines are there ? */
46     int i_visible_pitch;            /**< How many visible pixels are there ? */
47
48 } plane_t;
49
50 /**
51  * Video picture
52  *
53  * Any picture destined to be displayed by a video output thread should be
54  * stored in this structure from it's creation to it's effective display.
55  * Picture type and flags should only be modified by the output thread. Note
56  * that an empty picture MUST have its flags set to 0.
57  */
58 struct picture_t
59 {
60     /**
61      * The properties of the picture
62      */
63     video_frame_format_t format;
64
65     /** Picture data - data can always be freely modified, but p_data may
66      * NEVER be modified. A direct buffer can be handled as the plugin
67      * wishes, it can even swap p_pixels buffers. */
68     uint8_t        *p_data;
69     void           *p_data_orig;                /**< pointer before memalign */
70     plane_t         p[ VOUT_MAX_PLANES ];     /**< description of the planes */
71     int             i_planes;                /**< number of allocated planes */
72
73     /** \name Type and flags
74      * Should NOT be modified except by the vout thread
75      * @{*/
76     int             i_status;                             /**< picture flags */
77     int             i_type;                /**< is picture a direct buffer ? */
78     vlc_bool_t      b_slow;                 /**< is picture in slow memory ? */
79     int             i_matrix_coefficients;   /**< in YUV type, encoding type */
80     /**@}*/
81
82     /** \name Picture management properties
83      * These properties can be modified using the video output thread API,
84      * but should never be written directly */
85     /**@{*/
86     int             i_refcount;                  /**< link reference counter */
87     mtime_t         date;                                  /**< display date */
88     vlc_bool_t      b_force;
89     /**@}*/
90
91     /** \name Picture dynamic properties
92      * Those properties can be changed by the decoder
93      * @{
94      */
95     vlc_bool_t      b_progressive;          /**< is it a progressive frame ? */
96     unsigned int    i_nb_fields;                  /**< # of displayed fields */
97     vlc_bool_t      b_top_field_first;             /**< which field is first */
98     /**@}*/
99
100     /** The picture heap we are attached to */
101     picture_heap_t* p_heap;
102
103     /* Some vouts require the picture to be locked before it can be modified */
104     int (* pf_lock) ( vout_thread_t *, picture_t * );
105     int (* pf_unlock) ( vout_thread_t *, picture_t * );
106
107     /** Private data - the video output plugin might want to put stuff here to
108      * keep track of the picture */
109     picture_sys_t * p_sys;
110
111     /** This way the picture_Release can be overloaded */
112     void (*pf_release)( picture_t * );
113
114     /** Next picture in a FIFO a pictures */
115     struct picture_t *p_next;
116 };
117
118 /**
119  * Video picture heap, either render (to store pictures used
120  * by the decoder) or output (to store pictures displayed by the vout plugin)
121  */
122 struct picture_heap_t
123 {
124     int i_pictures;                                   /**< current heap size */
125
126     /* \name Picture static properties
127      * Those properties are fixed at initialization and should NOT be modified
128      * @{
129      */
130     unsigned int i_width;                                 /**< picture width */
131     unsigned int i_height;                               /**< picture height */
132     vlc_fourcc_t i_chroma;                               /**< picture chroma */
133     unsigned int i_aspect;                                 /**< aspect ratio */
134     /**@}*/
135
136     /* Real pictures */
137     picture_t*      pp_picture[VOUT_MAX_PICTURES];             /**< pictures */
138     int             i_last_used_pic;              /**< last used pic in heap */
139     vlc_bool_t      b_allow_modify_pics;
140
141     /* Stuff used for truecolor RGB planes */
142     int i_rmask, i_rrshift, i_lrshift;
143     int i_gmask, i_rgshift, i_lgshift;
144     int i_bmask, i_rbshift, i_lbshift;
145
146     /** Stuff used for palettized RGB planes */
147     void (* pf_setpalette) ( vout_thread_t *, uint16_t *, uint16_t *, uint16_t * );
148 };
149
150 /*****************************************************************************
151  * Flags used to describe the status of a picture
152  *****************************************************************************/
153
154 /* Picture type */
155 #define EMPTY_PICTURE           0                            /* empty buffer */
156 #define MEMORY_PICTURE          100                 /* heap-allocated buffer */
157 #define DIRECT_PICTURE          200                         /* direct buffer */
158
159 /* Picture status */
160 #define FREE_PICTURE            0                  /* free and not allocated */
161 #define RESERVED_PICTURE        1                  /* allocated and reserved */
162 #define RESERVED_DATED_PICTURE  2              /* waiting for DisplayPicture */
163 #define RESERVED_DISP_PICTURE   3               /* waiting for a DatePicture */
164 #define READY_PICTURE           4                       /* ready for display */
165 #define DISPLAYED_PICTURE       5            /* been displayed but is linked */
166 #define DESTROYED_PICTURE       6              /* allocated but no more used */
167
168 /*****************************************************************************
169  * Shortcuts to access image components
170  *****************************************************************************/
171
172 /* Plane indices */
173 #define Y_PLANE      0
174 #define U_PLANE      1
175 #define V_PLANE      2
176 #define A_PLANE      3
177
178 /* Shortcuts */
179 #define Y_PIXELS     p[Y_PLANE].p_pixels
180 #define Y_PITCH      p[Y_PLANE].i_pitch
181 #define U_PIXELS     p[U_PLANE].p_pixels
182 #define U_PITCH      p[U_PLANE].i_pitch
183 #define V_PIXELS     p[V_PLANE].p_pixels
184 #define V_PITCH      p[V_PLANE].i_pitch
185 #define A_PIXELS     p[A_PLANE].p_pixels
186 #define A_PITCH      p[A_PLANE].i_pitch
187
188 /**
189  * \defgroup subpicture Video Subpictures
190  * Subpictures are pictures that should be displayed on top of the video, like
191  * subtitles and OSD
192  * \ingroup video_output
193  * @{
194  */
195
196 /**
197  * Video subtitle region
198  *
199  * A subtitle region is defined by a picture (graphic) and its rendering
200  * coordinates.
201  * Subtitles contain a list of regions.
202  */
203 struct subpicture_region_t
204 {
205     video_format_t  fmt;                          /**< format of the picture */
206     picture_t       picture;             /**< picture comprising this region */
207
208     int             i_x;                             /**< position of region */
209     int             i_y;                             /**< position of region */
210
211     char            *psz_text;       /**< text string comprising this region */
212     int             i_text_color;     /**< text color (RGB native endianess) */
213     int             i_text_alpha;                     /**< text transparency */
214     int             i_text_size;                              /**< text size */
215     int             i_text_align;         /**< horizontal alignment hint for */
216
217     subpicture_region_t *p_next;                /**< next region in the list */
218     subpicture_region_t *p_cache;       /**< modified version of this region */
219 };
220
221 /**
222  * Video subtitle
223  *
224  * Any subtitle destined to be displayed by a video output thread should
225  * be stored in this structure from it's creation to it's effective display.
226  * Subtitle type and flags should only be modified by the output thread. Note
227  * that an empty subtitle MUST have its flags set to 0.
228  */
229 struct subpicture_t
230 {
231     /** \name Channel ID */
232     /**@{*/
233     int             i_channel;                    /**< subpicture channel ID */
234     /**@}*/
235
236     /** \name Type and flags
237        Should NOT be modified except by the vout thread */
238     /**@{*/
239     int             i_type;                                        /**< type */
240     int             i_status;                                     /**< flags */
241     subpicture_t *  p_next;               /**< next subtitle to be displayed */
242     /**@}*/
243
244     /** \name Date properties */
245     /**@{*/
246     mtime_t         i_start;                  /**< beginning of display date */
247     mtime_t         i_stop;                         /**< end of display date */
248     vlc_bool_t      b_ephemer;    /**< If this flag is set to true the subtitle
249                                 will be displayed untill the next one appear */
250     vlc_bool_t      b_fade;                               /**< enable fading */
251     /**@}*/
252
253     subpicture_region_t *p_region;  /**< region list composing this subtitle */
254
255     /** \name Display properties
256      * 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     /**@{*/
260     int          i_x;                    /**< offset from alignment position */
261     int          i_y;                    /**< offset from alignment position */
262     int          i_width;                                 /**< picture width */
263     int          i_height;                               /**< picture height */
264     int          i_alpha;                                  /**< transparency */
265     int          i_original_picture_width;  /**< original width of the movie */
266     int          i_original_picture_height;/**< original height of the movie */
267     vlc_bool_t   b_absolute;                       /**< position is absolute */
268     int          i_flags;                                /**< position flags */
269      /**@}*/
270
271     /** Pointer to function that renders this subtitle in a picture */
272     void ( *pf_render )  ( vout_thread_t *, picture_t *, const subpicture_t * );
273     /** Pointer to function that cleans up the private data of this subtitle */
274     void ( *pf_destroy ) ( subpicture_t * );
275
276     /** Pointer to functions for region management */
277     subpicture_region_t * ( *pf_create_region ) ( vlc_object_t *,
278                                                   video_format_t * );
279     subpicture_region_t * ( *pf_make_region ) ( vlc_object_t *,
280                                                 video_format_t *, picture_t * );
281     void ( *pf_destroy_region ) ( vlc_object_t *, subpicture_region_t * );
282
283     /** Private data - the subtitle plugin might want to put stuff here to
284      * keep track of the subpicture */
285     subpicture_sys_t *p_sys;                              /* subpicture data */
286 };
287
288 /* Subpicture type */
289 #define EMPTY_SUBPICTURE       0     /* subtitle slot is empty and available */
290 #define MEMORY_SUBPICTURE      100            /* subpicture stored in memory */
291
292 /* Default subpicture channel ID */
293 #define DEFAULT_CHAN           1
294
295 /* Subpicture status */
296 #define FREE_SUBPICTURE        0                   /* free and not allocated */
297 #define RESERVED_SUBPICTURE    1                   /* allocated and reserved */
298 #define READY_SUBPICTURE       2                        /* ready for display */
299
300 /* Subpicture position flags */
301 #define SUBPICTURE_ALIGN_LEFT 0x1
302 #define SUBPICTURE_ALIGN_RIGHT 0x2
303 #define SUBPICTURE_ALIGN_TOP 0x4
304 #define SUBPICTURE_ALIGN_BOTTOM 0x8
305
306 /*****************************************************************************
307  * Prototypes
308  *****************************************************************************/
309 /**
310  * vout_CopyPicture
311  *
312  * Copy the source picture onto the destination picture.
313  * \param p_this a vlc object
314  * \param p_dst pointer to the destination picture.
315  * \param p_src pointer to the source picture.
316  */
317 #define vout_CopyPicture(a,b,c) __vout_CopyPicture(VLC_OBJECT(a),b,c)
318 VLC_EXPORT( void, __vout_CopyPicture, ( vlc_object_t *p_this, picture_t *p_dst, picture_t *p_src ) );
319
320 /**
321  * vout_InitPicture
322  *
323  * Initialise different fields of a picture_t (but does not allocate memory).
324  * \param p_this a vlc object
325  * \param p_pic pointer to the picture structure.
326  * \param i_chroma the wanted chroma for the picture.
327  * \param i_width the wanted width for the picture.
328  * \param i_height the wanted height for the picture.
329  * \param i_aspect the wanted aspect ratio for the picture.
330  */
331 #define vout_InitPicture(a,b,c,d,e,f) \
332         __vout_InitPicture(VLC_OBJECT(a),b,c,d,e,f)
333 VLC_EXPORT( int, __vout_InitPicture, ( vlc_object_t *p_this, picture_t *p_pic, uint32_t i_chroma, int i_width, int i_height, int i_aspect ) );
334
335 /**
336  * vout_AllocatePicture
337  *
338  * Initialise different fields of a picture_t and allocates the picture buffer.
339  * \param p_this a vlc object
340  * \param p_pic pointer to the picture structure.
341  * \param i_chroma the wanted chroma for the picture.
342  * \param i_width the wanted width for the picture.
343  * \param i_height the wanted height for the picture.
344  * \param i_aspect the wanted aspect ratio for the picture.
345  */
346 #define vout_AllocatePicture(a,b,c,d,e,f) \
347         __vout_AllocatePicture(VLC_OBJECT(a),b,c,d,e,f)
348 VLC_EXPORT( int, __vout_AllocatePicture,( vlc_object_t *p_this, picture_t *p_pic, uint32_t i_chroma, int i_width, int i_height, int i_aspect ) );
349
350 /**
351  * vout_ShowTextRelative
352  *
353  * Show text on the video for some time
354  * \param p_vout pointer to the vout the text is to be showed on
355  * \param i_channel Subpicture channel
356  * \param psz_string The text to be shown
357  * \param p_style Pointer to a struct with text style info
358  * \param i_flags flags for alignment and such
359  * \param i_hmargin horizontal margin in pixels
360  * \param i_vmargin vertical margin in pixels
361  * \param i_duration Amount of time the text is to be shown.
362  */
363 VLC_EXPORT( int, vout_ShowTextRelative, ( vout_thread_t *, int, char *, text_style_t *, int, int, int, mtime_t ) );
364
365 /**
366  * vout_ShowTextAbsolute
367  *
368  * Show text on the video from a given start date to a given end date
369  * \param p_vout pointer to the vout the text is to be showed on
370  * \param i_channel Subpicture channel
371  * \param psz_string The text to be shown
372  * \param p_style Pointer to a struct with text style info
373  * \param i_flags flags for alignment and such
374  * \param i_hmargin horizontal margin in pixels
375  * \param i_vmargin vertical margin in pixels
376  * \param i_start the time when this string is to appear on the video
377  * \param i_stop the time when this string should stop to be displayed
378  *               if this is 0 the string will be shown untill the next string
379  *               is about to be shown
380  */
381 VLC_EXPORT( int, vout_ShowTextAbsolute, ( vout_thread_t *, int, char *, text_style_t *, int, int, int, mtime_t, mtime_t ) );
382
383 /**
384  * vout_OSDMessage
385  *
386  * Write an informative message at the default location,
387  * for the default duration and only if the OSD option is enabled.
388  * \param p_caller The object that called the function.
389  * \param i_channel Subpicture channel
390  * \param psz_format printf style formatting
391  **/
392 VLC_EXPORT( void,  __vout_OSDMessage, ( vlc_object_t *, int, char *, ... ) );
393
394 /**
395  * Same as __vlc_OSDMessage() but with automatic casting
396  */
397 #if defined(HAVE_VARIADIC_MACROS)
398 #    define vout_OSDMessage( obj, chan, fmt, args...) __vout_OSDMessage( VLC_OBJECT(obj), chan, fmt, ## args )
399 #else
400 #    define vout_OSDMessage __vout_OSDMessage
401 #endif
402
403 /**
404  * vout_OSDSlider
405  *
406  * Display a slider on the video output.
407  * \param p_this    The object that called the function.
408  * \param i_channel Subpicture channel
409  * \param i_postion Current position in the slider
410  * \param i_type    Types are: OSD_HOR_SLIDER and OSD_VERT_SLIDER.
411  * @see vlc_osd.h
412  */
413 VLC_EXPORT( void, vout_OSDSlider, ( vlc_object_t *, int, int , short ) );
414
415 /**
416  * vout_OSDIcon
417  *
418  * Display an Icon on the video output.
419  * \param p_this    The object that called the function.
420  * \param i_channel Subpicture channel
421  * \param i_type    Types are: OSD_PLAY_ICON, OSD_PAUSE_ICON, OSD_SPEAKER_ICON, OSD_MUTE_ICON
422  * @see vlc_osd.h
423  */
424 VLC_EXPORT( void, vout_OSDIcon, ( vlc_object_t *, int, short ) );
425
426 /**@}*/
427
428 #endif /* _VLC_VIDEO_H */