]> git.sesse.net Git - vlc/blob - include/vlc_vout.h
Merge branch 1.0-bugfix (early part) into master
[vlc] / include / vlc_vout.h
1 /*****************************************************************************
2  * vlc_video.h: common video definitions
3  *****************************************************************************
4  * Copyright (C) 1999 - 2008 the VideoLAN team
5  * $Id$
6  *
7  * Authors: Vincent Seguin <seguin@via.ecp.fr>
8  *          Samuel Hocevar <sam@via.ecp.fr>
9  *          Olivier Aubert <oaubert 47 videolan d07 org>
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., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
24  *****************************************************************************/
25
26 #ifndef VLC_VOUT_H_
27 #define VLC_VOUT_H_ 1
28
29 /**
30  * \file
31  * This file defines common video output structures and functions in vlc
32  */
33
34 #include <vlc_picture.h>
35 #include <vlc_filter.h>
36 #include <vlc_subpicture.h>
37
38 /**
39  * Video picture heap, either render (to store pictures used
40  * by the decoder) or output (to store pictures displayed by the vout plugin)
41  */
42 struct picture_heap_t
43 {
44     int i_pictures;                                   /**< current heap size */
45
46     /* \name Picture static properties
47      * Those properties are fixed at initialization and should NOT be modified
48      * @{
49      */
50     unsigned int i_width;                                 /**< picture width */
51     unsigned int i_height;                               /**< picture height */
52     vlc_fourcc_t i_chroma;                               /**< picture chroma */
53     unsigned int i_aspect;                                 /**< aspect ratio */
54     /**@}*/
55
56     /* Real pictures */
57     picture_t*      pp_picture[VOUT_MAX_PICTURES];             /**< pictures */
58     int             i_last_used_pic;              /**< last used pic in heap */
59     bool            b_allow_modify_pics;
60
61     /* Stuff used for truecolor RGB planes */
62     uint32_t i_rmask; int i_rrshift, i_lrshift;
63     uint32_t i_gmask; int i_rgshift, i_lgshift;
64     uint32_t i_bmask; int i_rbshift, i_lbshift;
65
66     /** Stuff used for palettized RGB planes */
67     void (* pf_setpalette) ( vout_thread_t *, uint16_t *, uint16_t *, uint16_t * );
68 };
69
70 /* Default subpicture channel ID */
71 #define DEFAULT_CHAN           1
72
73 /*****************************************************************************
74  * Prototypes
75  *****************************************************************************/
76
77 /**
78  * Initialise different fields of a picture_t and allocates the picture buffer.
79  * \param p_this a vlc object
80  * \param p_pic pointer to the picture structure.
81  * \param i_chroma the wanted chroma for the picture.
82  * \param i_width the wanted width for the picture.
83  * \param i_height the wanted height for the picture.
84  * \param i_aspect the wanted aspect ratio for the picture.
85  */
86 #define vout_AllocatePicture(a,b,c,d,e,f) \
87         __vout_AllocatePicture(VLC_OBJECT(a),b,c,d,e,f)
88 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 ) );
89
90
91 /**
92  * \defgroup video_output Video Output
93  * This module describes the programming interface for video output threads.
94  * It includes functions allowing to open a new thread, send pictures to a
95  * thread, and destroy a previously opened video output thread.
96  * @{
97  */
98
99 /**
100  * Video ouput thread private structure
101  */
102 typedef struct vout_thread_sys_t vout_thread_sys_t;
103
104 /**
105  * Video output thread descriptor
106  *
107  * Any independent video output device, such as an X11 window or a GGI device,
108  * is represented by a video output thread, and described using the following
109  * structure.
110  */
111 struct vout_thread_t
112 {
113     VLC_COMMON_MEMBERS
114
115     /** \name Thread properties and locks */
116     /**@{*/
117     vlc_mutex_t         picture_lock;                 /**< picture heap lock */
118     vlc_mutex_t         change_lock;                 /**< thread change lock */
119     vout_sys_t *        p_sys;                     /**< system output method */
120     /**@}*/
121
122     /** \name Current display properties */
123     /**@{*/
124     uint16_t            i_changes;          /**< changes made to the thread.
125                                                       \see \ref vout_changes */
126     unsigned            b_fullscreen:1;       /**< toogle fullscreen display */
127     unsigned            b_autoscale:1;      /**< auto scaling picture or not */
128     unsigned            b_on_top:1; /**< stay always on top of other windows */
129     int                 i_zoom;               /**< scaling factor if no auto */
130     unsigned int        i_window_width;              /**< video window width */
131     unsigned int        i_window_height;            /**< video window height */
132     unsigned int        i_alignment;          /**< video alignment in window */
133
134     /**@}*/
135
136     /** \name Plugin used and shortcuts to access its capabilities */
137     /**@{*/
138     module_t *   p_module;
139     int       ( *pf_init )       ( vout_thread_t * );
140     void      ( *pf_end )        ( vout_thread_t * );
141     int       ( *pf_manage )     ( vout_thread_t * );
142     void      ( *pf_render )     ( vout_thread_t *, picture_t * );
143     void      ( *pf_display )    ( vout_thread_t *, picture_t * );
144     void      ( *pf_swap )       ( vout_thread_t * );         /* OpenGL only */
145     int       ( *pf_lock )       ( vout_thread_t * );         /* OpenGL only */
146     void      ( *pf_unlock )     ( vout_thread_t * );         /* OpenGL only */
147     int       ( *pf_control )    ( vout_thread_t *, int, va_list );
148     /**@}*/
149
150     /** \name Video heap and translation tables */
151     /**@{*/
152     int                 i_heap_size;                          /**< heap size */
153     picture_heap_t      render;                       /**< rendered pictures */
154     picture_heap_t      output;                          /**< direct buffers */
155
156     video_format_t      fmt_render;      /* render format (from the decoder) */
157     video_format_t      fmt_in;            /* input (modified render) format */
158     video_format_t      fmt_out;     /* output format (for the video output) */
159     /**@}*/
160
161     /* Picture heap */
162     picture_t           p_picture[2*VOUT_MAX_PICTURES+1];      /**< pictures */
163
164     /* Subpicture unit */
165     spu_t          *p_spu;
166
167     /* Video output configuration */
168     config_chain_t *p_cfg;
169
170     /* Private vout_thread data */
171     vout_thread_sys_t *p;
172 };
173
174 #define I_OUTPUTPICTURES p_vout->output.i_pictures
175 #define PP_OUTPUTPICTURE p_vout->output.pp_picture
176 #define I_RENDERPICTURES p_vout->render.i_pictures
177 #define PP_RENDERPICTURE p_vout->render.pp_picture
178
179 /** \defgroup vout_changes Flags for changes
180  * These flags are set in the vout_thread_t::i_changes field when another
181  * thread changed a variable
182  * @{
183  */
184 /** b_info changed */
185 #define VOUT_INFO_CHANGE        0x0001
186 /** b_interface changed */
187 #define VOUT_INTF_CHANGE        0x0004
188 /** b_autoscale changed */
189 #define VOUT_SCALE_CHANGE       0x0008
190 /** b_on_top changed */
191 #define VOUT_ON_TOP_CHANGE      0x0010
192 /** b_cursor changed */
193 #define VOUT_CURSOR_CHANGE      0x0020
194 /** b_fullscreen changed */
195 #define VOUT_FULLSCREEN_CHANGE  0x0040
196 /** i_zoom changed */
197 #define VOUT_ZOOM_CHANGE        0x0080
198 /** size changed */
199 #define VOUT_SIZE_CHANGE        0x0200
200 /** depth changed */
201 #define VOUT_DEPTH_CHANGE       0x0400
202 /** change chroma tables */
203 #define VOUT_CHROMA_CHANGE      0x0800
204 /** cropping parameters changed */
205 #define VOUT_CROP_CHANGE        0x1000
206 /** aspect ratio changed */
207 #define VOUT_ASPECT_CHANGE      0x2000
208 /** change/recreate picture buffers */
209 #define VOUT_PICTURE_BUFFERS_CHANGE 0x4000
210 /**@}*/
211
212 /* Alignment flags */
213 #define VOUT_ALIGN_LEFT         0x0001
214 #define VOUT_ALIGN_RIGHT        0x0002
215 #define VOUT_ALIGN_HMASK        0x0003
216 #define VOUT_ALIGN_TOP          0x0004
217 #define VOUT_ALIGN_BOTTOM       0x0008
218 #define VOUT_ALIGN_VMASK        0x000C
219
220 #define MAX_JITTER_SAMPLES      20
221
222 /* scaling factor (applied to i_zoom in vout_thread_t) */
223 #define ZOOM_FP_FACTOR          1000
224
225 /*****************************************************************************
226  * Prototypes
227  *****************************************************************************/
228
229 /**
230  * This function will
231  *  - returns a suitable vout (if requested by a non NULL p_fmt)
232  *  - recycles an old vout (if given) by either destroying it or by saving it
233  *  for latter usage.
234  *
235  * The purpose of this function is to avoid unnecessary creation/destruction of
236  * vout (and to allow optional vout reusing).
237  *
238  * You can call vout_Request on a vout created by vout_Create or by a previous
239  * call to vout_Request.
240  * You can release the returned value either by vout_Request or vout_Close()
241  * followed by a vlc_object_release() or shorter vout_CloseAndRelease()
242  *
243  * \param p_this a vlc object
244  * \param p_vout a vout candidate
245  * \param p_fmt the video format requested or NULL
246  * \return a vout if p_fmt is non NULL and the request is successfull, NULL
247  * otherwise
248  */
249 #define vout_Request(a,b,c) __vout_Request(VLC_OBJECT(a),b,c)
250 VLC_EXPORT( vout_thread_t *, __vout_Request,    ( vlc_object_t *p_this, vout_thread_t *p_vout, video_format_t *p_fmt ) );
251
252 /**
253  * This function will create a suitable vout for a given p_fmt. It will never
254  * reuse an already existing unused vout.
255  *
256  * You have to call either vout_Close or vout_Request on the returned value
257  * \param p_this a vlc object to which the returned vout will be attached
258  * \param p_fmt the video format requested
259  * \return a vout if the request is successfull, NULL otherwise
260  */
261 #define vout_Create(a,b) __vout_Create(VLC_OBJECT(a),b)
262 VLC_EXPORT( vout_thread_t *, __vout_Create,       ( vlc_object_t *p_this, video_format_t *p_fmt ) );
263
264 /**
265  * This function will close a vout created by vout_Create or vout_Request.
266  * The associated vout module is closed.
267  * Note: It is not released yet, you'll have to call vlc_object_release()
268  * or use the convenient vout_CloseAndRelease().
269  *
270  * \param p_vout the vout to close
271  */
272 VLC_EXPORT( void,            vout_Close,        ( vout_thread_t *p_vout ) );
273
274 /**
275  * This function will close a vout created by vout_Create
276  * and then release it.
277  *
278  * \param p_vout the vout to close and release
279  */
280 static inline void vout_CloseAndRelease( vout_thread_t *p_vout )
281 {
282     vout_Close( p_vout );
283     vlc_object_release( p_vout );
284 }
285
286 /**
287  * This function will handle a snapshot request.
288  *
289  * pp_image, pp_picture and p_fmt can be NULL otherwise they will be
290  * set with returned value in case of success.
291  *
292  * pp_image will hold an encoded picture in psz_format format.
293  *
294  * i_timeout specifies the time the function will wait for a snapshot to be
295  * available.
296  *
297  */
298 VLC_EXPORT( int, vout_GetSnapshot, ( vout_thread_t *p_vout,
299                                      block_t **pp_image, picture_t **pp_picture,
300                                      video_format_t *p_fmt,
301                                      const char *psz_format, mtime_t i_timeout ) );
302
303 /* */
304 VLC_EXPORT( int,             vout_ChromaCmp,      ( uint32_t, uint32_t ) );
305
306 VLC_EXPORT( picture_t *,     vout_CreatePicture,  ( vout_thread_t *, bool, bool, unsigned int ) );
307 VLC_EXPORT( void,            vout_DestroyPicture, ( vout_thread_t *, picture_t * ) );
308 VLC_EXPORT( void,            vout_DisplayPicture, ( vout_thread_t *, picture_t * ) );
309 VLC_EXPORT( void,            vout_LinkPicture,    ( vout_thread_t *, picture_t * ) );
310 VLC_EXPORT( void,            vout_UnlinkPicture,  ( vout_thread_t *, picture_t * ) );
311 VLC_EXPORT( void,            vout_PlacePicture,   ( const vout_thread_t *, unsigned int, unsigned int, unsigned int *, unsigned int *, unsigned int *, unsigned int * ) );
312
313 void vout_IntfInit( vout_thread_t * );
314 VLC_EXPORT( void, vout_EnableFilter, ( vout_thread_t *, char *,bool , bool  ) );
315
316
317 static inline int vout_vaControl( vout_thread_t *p_vout, int i_query,
318                                   va_list args )
319 {
320     if( p_vout->pf_control )
321         return p_vout->pf_control( p_vout, i_query, args );
322     else
323         return VLC_EGENERIC;
324 }
325
326 static inline int vout_Control( vout_thread_t *p_vout, int i_query, ... )
327 {
328     va_list args;
329     int i_result;
330
331     va_start( args, i_query );
332     i_result = vout_vaControl( p_vout, i_query, args );
333     va_end( args );
334     return i_result;
335 }
336
337 enum output_query_e
338 {
339     VOUT_SET_SIZE,         /* arg1= unsigned int, arg2= unsigned int, res= */
340     VOUT_SET_STAY_ON_TOP,  /* arg1= bool       res=    */
341     VOUT_SET_VIEWPORT,      /* arg1= view rect, arg2=clip rect, res= */
342     VOUT_REDRAW_RECT,       /* arg1= area rect, res= */
343 };
344
345 /**@}*/
346
347 #endif /* _VLC_VIDEO_H */