1 /*****************************************************************************
2 * vlc_video.h: common video definitions
3 *****************************************************************************
4 * Copyright (C) 1999 - 2005 the VideoLAN team
7 * Authors: Vincent Seguin <seguin@via.ecp.fr>
8 * Samuel Hocevar <sam@via.ecp.fr>
9 * Olivier Aubert <oaubert 47 videolan d07 org>
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., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
24 *****************************************************************************/
26 #define _VLC_VOUT_H_ 1
30 /** Description of a planar graphic field */
31 typedef struct plane_t
33 uint8_t *p_pixels; /**< Start of the plane's data */
35 /* Variables used for fast memcpy operations */
36 int i_lines; /**< Number of lines, including margins */
37 int i_pitch; /**< Number of bytes in a line, including margins */
39 /** Size of a macropixel, defaults to 1 */
42 /* Variables used for pictures with margins */
43 int i_visible_lines; /**< How many visible lines are there ? */
44 int i_visible_pitch; /**< How many visible pixels are there ? */
51 * Any picture destined to be displayed by a video output thread should be
52 * stored in this structure from it's creation to it's effective display.
53 * Picture type and flags should only be modified by the output thread. Note
54 * that an empty picture MUST have its flags set to 0.
59 * The properties of the picture
61 video_frame_format_t format;
63 /** Picture data - data can always be freely modified, but p_data may
64 * NEVER be modified. A direct buffer can be handled as the plugin
65 * wishes, it can even swap p_pixels buffers. */
67 void *p_data_orig; /**< pointer before memalign */
68 plane_t p[ VOUT_MAX_PLANES ]; /**< description of the planes */
69 int i_planes; /**< number of allocated planes */
71 /** \name Type and flags
72 * Should NOT be modified except by the vout thread
74 int i_status; /**< picture flags */
75 int i_type; /**< is picture a direct buffer ? */
76 vlc_bool_t b_slow; /**< is picture in slow memory ? */
77 int i_matrix_coefficients; /**< in YUV type, encoding type */
80 /** \name Picture management properties
81 * These properties can be modified using the video output thread API,
82 * but should never be written directly */
84 int i_refcount; /**< link reference counter */
85 mtime_t date; /**< display date */
89 /** \name Picture dynamic properties
90 * Those properties can be changed by the decoder
93 vlc_bool_t b_progressive; /**< is it a progressive frame ? */
94 unsigned int i_nb_fields; /**< # of displayed fields */
95 vlc_bool_t b_top_field_first; /**< which field is first */
98 /** The picture heap we are attached to */
99 picture_heap_t* p_heap;
101 /* Some vouts require the picture to be locked before it can be modified */
102 int (* pf_lock) ( vout_thread_t *, picture_t * );
103 int (* pf_unlock) ( vout_thread_t *, picture_t * );
105 /** Private data - the video output plugin might want to put stuff here to
106 * keep track of the picture */
107 picture_sys_t * p_sys;
109 /** This way the picture_Release can be overloaded */
110 void (*pf_release)( picture_t * );
112 /** Next picture in a FIFO a pictures */
113 struct picture_t *p_next;
117 * Video picture heap, either render (to store pictures used
118 * by the decoder) or output (to store pictures displayed by the vout plugin)
120 struct picture_heap_t
122 int i_pictures; /**< current heap size */
124 /* \name Picture static properties
125 * Those properties are fixed at initialization and should NOT be modified
128 unsigned int i_width; /**< picture width */
129 unsigned int i_height; /**< picture height */
130 vlc_fourcc_t i_chroma; /**< picture chroma */
131 unsigned int i_aspect; /**< aspect ratio */
135 picture_t* pp_picture[VOUT_MAX_PICTURES]; /**< pictures */
136 int i_last_used_pic; /**< last used pic in heap */
137 vlc_bool_t b_allow_modify_pics;
139 /* Stuff used for truecolor RGB planes */
140 uint32_t i_rmask; int i_rrshift, i_lrshift;
141 uint32_t i_gmask; int i_rgshift, i_lgshift;
142 uint32_t i_bmask; int i_rbshift, i_lbshift;
144 /** Stuff used for palettized RGB planes */
145 void (* pf_setpalette) ( vout_thread_t *, uint16_t *, uint16_t *, uint16_t * );
148 /*****************************************************************************
149 * Flags used to describe the status of a picture
150 *****************************************************************************/
153 #define EMPTY_PICTURE 0 /* empty buffer */
154 #define MEMORY_PICTURE 100 /* heap-allocated buffer */
155 #define DIRECT_PICTURE 200 /* direct buffer */
158 #define FREE_PICTURE 0 /* free and not allocated */
159 #define RESERVED_PICTURE 1 /* allocated and reserved */
160 #define RESERVED_DATED_PICTURE 2 /* waiting for DisplayPicture */
161 #define RESERVED_DISP_PICTURE 3 /* waiting for a DatePicture */
162 #define READY_PICTURE 4 /* ready for display */
163 #define DISPLAYED_PICTURE 5 /* been displayed but is linked */
164 #define DESTROYED_PICTURE 6 /* allocated but no more used */
166 /*****************************************************************************
167 * Shortcuts to access image components
168 *****************************************************************************/
177 #define Y_PIXELS p[Y_PLANE].p_pixels
178 #define Y_PITCH p[Y_PLANE].i_pitch
179 #define U_PIXELS p[U_PLANE].p_pixels
180 #define U_PITCH p[U_PLANE].i_pitch
181 #define V_PIXELS p[V_PLANE].p_pixels
182 #define V_PITCH p[V_PLANE].i_pitch
183 #define A_PIXELS p[A_PLANE].p_pixels
184 #define A_PITCH p[A_PLANE].i_pitch
187 * \defgroup subpicture Video Subpictures
188 * Subpictures are pictures that should be displayed on top of the video, like
190 * \ingroup video_output
195 * Video subtitle region
197 * A subtitle region is defined by a picture (graphic) and its rendering
199 * Subtitles contain a list of regions.
201 struct subpicture_region_t
203 video_format_t fmt; /**< format of the picture */
204 picture_t picture; /**< picture comprising this region */
206 int i_x; /**< position of region */
207 int i_y; /**< position of region */
208 int i_align; /**< alignment within a region */
210 char *psz_text; /**< text string comprising this region */
211 text_style_t *p_style; /* a description of the text style formatting */
213 subpicture_region_t *p_next; /**< next region in the list */
214 subpicture_region_t *p_cache; /**< modified version of this region */
220 * Any subtitle destined to be displayed by a video output thread should
221 * be stored in this structure from it's creation to it's effective display.
222 * Subtitle type and flags should only be modified by the output thread. Note
223 * that an empty subtitle MUST have its flags set to 0.
227 /** \name Channel ID */
229 int i_channel; /**< subpicture channel ID */
232 /** \name Type and flags
233 Should NOT be modified except by the vout thread */
235 int i_type; /**< type */
236 int i_status; /**< flags */
237 subpicture_t * p_next; /**< next subtitle to be displayed */
240 /** \name Date properties */
242 mtime_t i_start; /**< beginning of display date */
243 mtime_t i_stop; /**< end of display date */
244 vlc_bool_t b_ephemer; /**< If this flag is set to true the subtitle
245 will be displayed untill the next one appear */
246 vlc_bool_t b_fade; /**< enable fading */
247 vlc_bool_t b_pausable; /**< subpicture will be paused if
251 subpicture_region_t *p_region; /**< region list composing this subtitle */
253 /** \name Display properties
254 * These properties are only indicative and may be
255 * changed by the video output thread, or simply ignored depending of the
258 int i_x; /**< offset from alignment position */
259 int i_y; /**< offset from alignment position */
260 int i_width; /**< picture width */
261 int i_height; /**< picture height */
262 int i_alpha; /**< transparency */
263 int i_original_picture_width; /**< original width of the movie */
264 int i_original_picture_height;/**< original height of the movie */
265 vlc_bool_t b_absolute; /**< position is absolute */
266 int i_flags; /**< position flags */
269 /** Pointer to function that renders this subtitle in a picture */
270 void ( *pf_render ) ( vout_thread_t *, picture_t *, const subpicture_t * );
271 /** Pointer to function that cleans up the private data of this subtitle */
272 void ( *pf_destroy ) ( subpicture_t * );
274 /** Pointer to functions for region management */
275 subpicture_region_t * ( *pf_create_region ) ( vlc_object_t *,
277 subpicture_region_t * ( *pf_make_region ) ( vlc_object_t *,
278 video_format_t *, picture_t * );
279 void ( *pf_destroy_region ) ( vlc_object_t *, subpicture_region_t * );
281 /** Private data - the subtitle plugin might want to put stuff here to
282 * keep track of the subpicture */
283 subpicture_sys_t *p_sys; /* subpicture data */
286 /* Subpicture type */
287 #define EMPTY_SUBPICTURE 0 /* subtitle slot is empty and available */
288 #define MEMORY_SUBPICTURE 100 /* subpicture stored in memory */
290 /* Default subpicture channel ID */
291 #define DEFAULT_CHAN 1
293 /* Subpicture status */
294 #define FREE_SUBPICTURE 0 /* free and not allocated */
295 #define RESERVED_SUBPICTURE 1 /* allocated and reserved */
296 #define READY_SUBPICTURE 2 /* ready for display */
298 /* Subpicture position flags */
299 #define SUBPICTURE_ALIGN_LEFT 0x1
300 #define SUBPICTURE_ALIGN_RIGHT 0x2
301 #define SUBPICTURE_ALIGN_TOP 0x4
302 #define SUBPICTURE_ALIGN_BOTTOM 0x8
304 /*****************************************************************************
306 *****************************************************************************/
309 * Copy the source picture onto the destination picture.
310 * \param p_this a vlc object
311 * \param p_dst pointer to the destination picture.
312 * \param p_src pointer to the source picture.
314 #define vout_CopyPicture(a,b,c) __vout_CopyPicture(VLC_OBJECT(a),b,c)
315 VLC_EXPORT( void, __vout_CopyPicture, ( vlc_object_t *p_this, picture_t *p_dst, picture_t *p_src ) );
318 * Initialise different fields of a picture_t (but does not allocate memory).
319 * \param p_this a vlc object
320 * \param p_pic pointer to the picture structure.
321 * \param i_chroma the wanted chroma for the picture.
322 * \param i_width the wanted width for the picture.
323 * \param i_height the wanted height for the picture.
324 * \param i_aspect the wanted aspect ratio for the picture.
326 #define vout_InitPicture(a,b,c,d,e,f) \
327 __vout_InitPicture(VLC_OBJECT(a),b,c,d,e,f)
328 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 ) );
331 * Initialise different fields of a picture_t and allocates the picture buffer.
332 * \param p_this a vlc object
333 * \param p_pic pointer to the picture structure.
334 * \param i_chroma the wanted chroma for the picture.
335 * \param i_width the wanted width for the picture.
336 * \param i_height the wanted height for the picture.
337 * \param i_aspect the wanted aspect ratio for the picture.
339 #define vout_AllocatePicture(a,b,c,d,e,f) \
340 __vout_AllocatePicture(VLC_OBJECT(a),b,c,d,e,f)
341 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 ) );
345 * \defgroup video_output Video Output
346 * This module describes the programming interface for video output threads.
347 * It includes functions allowing to open a new thread, send pictures to a
348 * thread, and destroy a previously opened video output thread.
353 * Chroma conversion function
355 * This is the prototype common to all conversion functions.
356 * \param p_vout video output thread
357 * \param p_source source picture
358 * \param p_dest destination picture
359 * Picture width and source dimensions must be multiples of 16.
361 typedef void (vout_chroma_convert_t)( vout_thread_t *,
362 picture_t *, picture_t * );
364 typedef struct vout_chroma_t
366 /** conversion functions */
367 vout_chroma_convert_t *pf_convert;
369 /** Private module-dependant data */
370 chroma_sys_t * p_sys; /* private data */
372 /** Plugin used and shortcuts to access its capabilities */
377 /** Maximum numbers of video filters2 that can be attached to a vout */
378 #define MAX_VFILTERS 10
381 * Video output thread descriptor
383 * Any independant video output device, such as an X11 window or a GGI device,
384 * is represented by a video output thread, and described using the following
391 /** \name Thread properties and locks */
393 vlc_mutex_t picture_lock; /**< picture heap lock */
394 vlc_mutex_t subpicture_lock; /**< subpicture heap lock */
395 vlc_mutex_t change_lock; /**< thread change lock */
396 vout_sys_t * p_sys; /**< system output method */
399 /** \name Current display properties */
401 uint16_t i_changes; /**< changes made to the thread.
402 \see \ref vout_changes */
403 float f_gamma; /**< gamma */
404 vlc_bool_t b_grayscale; /**< color or grayscale display */
405 vlc_bool_t b_info; /**< print additional information */
406 vlc_bool_t b_interface; /**< render interface */
407 vlc_bool_t b_scale; /**< allow picture scaling */
408 vlc_bool_t b_fullscreen; /**< toogle fullscreen display */
409 uint32_t render_time; /**< last picture render time */
410 unsigned int i_window_width; /**< video window width */
411 unsigned int i_window_height; /**< video window height */
412 unsigned int i_alignment; /**< video alignment in window */
413 unsigned int i_par_num; /**< monitor pixel aspect-ratio */
414 unsigned int i_par_den; /**< monitor pixel aspect-ratio */
416 intf_thread_t *p_parent_intf; /**< parent interface for embedded
420 /** \name Plugin used and shortcuts to access its capabilities */
423 int ( *pf_init ) ( vout_thread_t * );
424 void ( *pf_end ) ( vout_thread_t * );
425 int ( *pf_manage ) ( vout_thread_t * );
426 void ( *pf_render ) ( vout_thread_t *, picture_t * );
427 void ( *pf_display ) ( vout_thread_t *, picture_t * );
428 void ( *pf_swap ) ( vout_thread_t * ); /* OpenGL only */
429 int ( *pf_lock ) ( vout_thread_t * ); /* OpenGL only */
430 void ( *pf_unlock ) ( vout_thread_t * ); /* OpenGL only */
431 int ( *pf_control ) ( vout_thread_t *, int, va_list );
435 * These numbers are not supposed to be accurate, but are a
436 * good indication of the thread status */
438 count_t c_fps_samples; /**< picture counts */
439 mtime_t p_fps_sample[VOUT_FPS_SAMPLES]; /**< FPS samples dates */
442 /** \name Video heap and translation tables */
444 int i_heap_size; /**< heap size */
445 picture_heap_t render; /**< rendered pictures */
446 picture_heap_t output; /**< direct buffers */
447 vlc_bool_t b_direct; /**< rendered are like direct ? */
448 vout_chroma_t chroma; /**< translation tables */
450 video_format_t fmt_render; /* render format (from the decoder) */
451 video_format_t fmt_in; /* input (modified render) format */
452 video_format_t fmt_out; /* output format (for the video output) */
456 picture_t p_picture[2*VOUT_MAX_PICTURES+1]; /**< pictures */
458 /* Subpicture unit */
463 count_t c_pictures, c_late_pictures;
464 mtime_t display_jitter; /**< average deviation from the PTS */
465 count_t c_jitter_samples; /**< number of samples used
466 for the calculation of the
468 /** delay created by internal caching */
472 char *psz_filter_chain;
473 vlc_bool_t b_filter_change;
475 /* Video filter2 chain
476 * these are handled like in transcode.c
477 * XXX: we might need to merge the two chains (v1 and v2 filters) */
478 char *psz_vfilters[MAX_VFILTERS];
479 config_chain_t *p_vfilters_cfg[MAX_VFILTERS];
482 filter_t *pp_vfilters[MAX_VFILTERS];
485 vlc_bool_t b_vfilter_change;
488 vlc_bool_t b_snapshot; /**< take one snapshot on the next loop */
491 #define I_OUTPUTPICTURES p_vout->output.i_pictures
492 #define PP_OUTPUTPICTURE p_vout->output.pp_picture
493 #define I_RENDERPICTURES p_vout->render.i_pictures
494 #define PP_RENDERPICTURE p_vout->render.pp_picture
496 /** \defgroup vout_changes Flags for changes
497 * These flags are set in the vout_thread_t::i_changes field when another
498 * thread changed a variable
501 /** b_info changed */
502 #define VOUT_INFO_CHANGE 0x0001
503 /** b_grayscale changed */
504 #define VOUT_GRAYSCALE_CHANGE 0x0002
505 /** b_interface changed */
506 #define VOUT_INTF_CHANGE 0x0004
507 /** b_scale changed */
508 #define VOUT_SCALE_CHANGE 0x0008
510 #define VOUT_GAMMA_CHANGE 0x0010
511 /** b_cursor changed */
512 #define VOUT_CURSOR_CHANGE 0x0020
513 /** b_fullscreen changed */
514 #define VOUT_FULLSCREEN_CHANGE 0x0040
516 #define VOUT_SIZE_CHANGE 0x0200
518 #define VOUT_DEPTH_CHANGE 0x0400
519 /** change chroma tables */
520 #define VOUT_CHROMA_CHANGE 0x0800
521 /** cropping parameters changed */
522 #define VOUT_CROP_CHANGE 0x1000
523 /** aspect ratio changed */
524 #define VOUT_ASPECT_CHANGE 0x2000
525 /** change/recreate picture buffers */
526 #define VOUT_PICTURE_BUFFERS_CHANGE 0x4000
529 /* Alignment flags */
530 #define VOUT_ALIGN_LEFT 0x0001
531 #define VOUT_ALIGN_RIGHT 0x0002
532 #define VOUT_ALIGN_HMASK 0x0003
533 #define VOUT_ALIGN_TOP 0x0004
534 #define VOUT_ALIGN_BOTTOM 0x0008
535 #define VOUT_ALIGN_VMASK 0x000C
537 #define MAX_JITTER_SAMPLES 20
539 /*****************************************************************************
541 *****************************************************************************/
542 #define vout_Request(a,b,c) __vout_Request(VLC_OBJECT(a),b,c)
543 VLC_EXPORT( vout_thread_t *, __vout_Request, ( vlc_object_t *, vout_thread_t *, video_format_t * ) );
544 #define vout_Create(a,b) __vout_Create(VLC_OBJECT(a),b)
545 VLC_EXPORT( vout_thread_t *, __vout_Create, ( vlc_object_t *, video_format_t * ) );
546 VLC_EXPORT( void, vout_Destroy, ( vout_thread_t * ) );
547 VLC_EXPORT( int, vout_VarCallback, ( vlc_object_t *, const char *, vlc_value_t, vlc_value_t, void * ) );
549 VLC_EXPORT( int, vout_ChromaCmp, ( uint32_t, uint32_t ) );
551 VLC_EXPORT( picture_t *, vout_CreatePicture, ( vout_thread_t *, vlc_bool_t, vlc_bool_t, unsigned int ) );
552 VLC_EXPORT( void, vout_InitFormat, ( video_frame_format_t *, uint32_t, int, int, int ) );
553 VLC_EXPORT( void, vout_DestroyPicture, ( vout_thread_t *, picture_t * ) );
554 VLC_EXPORT( void, vout_DisplayPicture, ( vout_thread_t *, picture_t * ) );
555 VLC_EXPORT( void, vout_DatePicture, ( vout_thread_t *, picture_t *, mtime_t ) );
556 VLC_EXPORT( void, vout_LinkPicture, ( vout_thread_t *, picture_t * ) );
557 VLC_EXPORT( void, vout_UnlinkPicture, ( vout_thread_t *, picture_t * ) );
558 VLC_EXPORT( void, vout_PlacePicture, ( vout_thread_t *, unsigned int, unsigned int, unsigned int *, unsigned int *, unsigned int *, unsigned int * ) );
559 picture_t * vout_RenderPicture ( vout_thread_t *, picture_t *,
562 VLC_EXPORT( int, vout_vaControlDefault, ( vout_thread_t *, int, va_list ) );
563 VLC_EXPORT( void *, vout_RequestWindow, ( vout_thread_t *, int *, int *, unsigned int *, unsigned int * ) );
564 VLC_EXPORT( void, vout_ReleaseWindow, ( vout_thread_t *, void * ) );
565 VLC_EXPORT( int, vout_ControlWindow, ( vout_thread_t *, void *, int, va_list ) );
566 void vout_IntfInit( vout_thread_t * );
567 VLC_EXPORT( int, vout_Snapshot, ( vout_thread_t *p_vout, picture_t *p_pic ) );
568 VLC_EXPORT( void, vout_EnableFilter, ( vout_thread_t *, char *,vlc_bool_t , vlc_bool_t ) );
571 static inline int vout_vaControl( vout_thread_t *p_vout, int i_query,
574 if( p_vout->pf_control )
575 return p_vout->pf_control( p_vout, i_query, args );
580 static inline int vout_Control( vout_thread_t *p_vout, int i_query, ... )
585 va_start( args, i_query );
586 i_result = vout_vaControl( p_vout, i_query, args );
593 VOUT_GET_SIZE, /* arg1= unsigned int*, arg2= unsigned int*, res= */
594 VOUT_SET_SIZE, /* arg1= unsigned int, arg2= unsigned int, res= */
595 VOUT_SET_STAY_ON_TOP, /* arg1= vlc_bool_t res= */
599 VOUT_SET_FOCUS, /* arg1= vlc_bool_t res= */
600 VOUT_SET_VIEWPORT /* arg1= view rect, arg2=clip rect, res= */
603 typedef struct snapshot_t {
604 char *p_data; /* Data area */
606 int i_width; /* In pixels */
607 int i_height; /* In pixels */
608 int i_datasize; /* In bytes */
609 mtime_t date; /* Presentation time */
614 #endif /* _VLC_VIDEO_H */