1 /*****************************************************************************
2 * video_output.h : video output thread
3 * This module describes the programming interface for video output threads.
4 * It includes functions allowing to open a new thread, send pictures to a
5 * thread, and destroy a previously oppenned video output thread.
6 *****************************************************************************
7 * Copyright (C) 1999, 2000 VideoLAN
8 * $Id: video_output.h,v 1.61 2001/05/30 17:03:11 sam Exp $
10 * Authors: Vincent Seguin <seguin@via.ecp.fr>
12 * This program is free software; you can redistribute it and/or modify
13 * it under the terms of the GNU General Public License as published by
14 * the Free Software Foundation; either version 2 of the License, or
15 * (at your option) any later version.
17 * This program is distributed in the hope that it will be useful,
18 * but WITHOUT ANY WARRANTY; without even the implied warranty of
19 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 * GNU General Public License for more details.
22 * You should have received a copy of the GNU General Public License
23 * along with this program; if not, write to the Free Software
24 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111, USA.
25 *****************************************************************************/
27 /*****************************************************************************
28 * vout_bank_t, p_vout_bank (global variable)
29 *****************************************************************************
30 * This global variable is accessed by any function using the video output.
31 *****************************************************************************/
32 typedef struct vout_bank_s
34 /* Array to all the video outputs */
35 struct vout_thread_s *pp_vout[ VOUT_MAX_THREADS ];
38 vlc_mutex_t lock; /* Global lock */
42 extern vout_bank_t *p_vout_bank;
44 /*****************************************************************************
45 * vout_yuv_convert_t: YUV conversion function
46 *****************************************************************************
47 * This is the prototype common to all conversion functions. The type of p_pic
48 * will change depending on the processed screen depth.
50 * p_vout video output thread
51 * p_pic picture address
52 * p_y, p_u, p_v Y,U,V samples addresses
53 * i_width, i_height Y samples extension
54 * i_pic_width, i_pic_height picture extension
55 * i_pic_line_width picture total line width
56 * i_matrix_coefficients matrix coefficients
57 * Picture width and source dimensions must be multiples of 16.
58 *****************************************************************************/
59 typedef void (vout_yuv_convert_t)( p_vout_thread_t p_vout, void *p_pic,
60 yuv_data_t *p_y, yuv_data_t *p_u, yuv_data_t *p_v,
61 int i_width, int i_height,
62 int i_pic_width, int i_pic_height, int i_pic_line_width,
63 int i_matrix_coefficients );
65 /*****************************************************************************
66 * vout_yuv_t: pre-calculated YUV conversion tables
67 *****************************************************************************
68 * These tables are used by conversion and scaling functions.
69 *****************************************************************************/
70 typedef int (yuv_init_t) ( p_vout_thread_t p_vout );
71 typedef int (yuv_reset_t) ( p_vout_thread_t p_vout );
72 typedef void (yuv_end_t) ( p_vout_thread_t p_vout );
74 typedef struct vout_yuv_s
76 /* conversion functions */
77 vout_yuv_convert_t *pf_yuv420; /* YUV 4:2:0 converter */
78 vout_yuv_convert_t *pf_yuv422; /* YUV 4:2:2 converter */
79 vout_yuv_convert_t *pf_yuv444; /* YUV 4:4:4 converter */
81 /* Pre-calculated conversion tables */
82 void * p_base; /* base for all conversion tables */
85 u8 * p_gray8; /* gray 8 bits table */
86 u16 * p_gray16; /* gray 16 bits table */
87 u32 * p_gray32; /* gray 32 bits table */
88 u8 * p_rgb8; /* RGB 8 bits table */
89 u16 * p_rgb16; /* RGB 16 bits table */
90 u32 * p_rgb32; /* RGB 32 bits table */
93 /* Temporary conversion buffer and offset array */
94 void * p_buffer; /* conversion buffer */
95 int * p_offset; /* offset array */
97 /* Plugin used and shortcuts to access its capabilities */
98 struct module_s * p_module;
99 yuv_init_t * pf_init; /* initialize YUV tables */
100 yuv_reset_t * pf_reset; /* reset YUV tables */
101 yuv_end_t * pf_end; /* free YUV tables */
105 /*****************************************************************************
106 * vout_buffer_t: rendering buffer
107 *****************************************************************************
108 * This structure stores information about a buffer. Buffers are not completely
109 * cleared between displays, and modified areas need to be stored.
110 *****************************************************************************/
111 typedef struct vout_buffer_s
114 int i_pic_x, i_pic_y; /* picture position */
115 int i_pic_width, i_pic_height; /* picture size */
117 /* Other areas - only vertical extensions of areas are stored */
118 int i_areas; /* number of areas */
119 int pi_area_begin[VOUT_MAX_AREAS]; /* beginning of area */
120 int pi_area_end[VOUT_MAX_AREAS]; /* end of area */
123 byte_t * p_data; /* memory address */
126 /*****************************************************************************
128 *****************************************************************************/
129 typedef struct vout_fifo_s
131 /* See the fifo types below */
134 int i_fifo; /* Just to keep track of the fifo index */
139 vlc_mutex_t data_lock;
140 vlc_cond_t data_wait;
144 #define VOUT_EMPTY_FIFO 0
145 #define VOUT_YUV_FIFO 1
146 #define VOUT_SPU_FIFO 2
148 /*****************************************************************************
149 * vout_thread_t: video output thread descriptor
150 *****************************************************************************
151 * Any independant video output device, such as an X11 window or a GGI device,
152 * is represented by a video output thread, and described using the following
154 *****************************************************************************/
155 typedef struct vout_thread_s
157 /* Thread properties and lock */
158 boolean_t b_die; /* `die' flag */
159 boolean_t b_error; /* `error' flag */
160 boolean_t b_active; /* `active' flag */
161 vlc_thread_t thread_id; /* id for pthread functions */
162 vlc_mutex_t picture_lock; /* picture heap lock */
163 vlc_mutex_t subpicture_lock; /* subpicture heap lock */
164 vlc_mutex_t change_lock; /* thread change lock */
165 int * pi_status; /* temporary status flag */
166 p_vout_sys_t p_sys; /* system output method */
168 /* Current display properties */
169 u16 i_changes; /* changes made to the thread */
170 int i_width; /* current output method width */
171 int i_height; /* current output method height */
172 int i_bytes_per_line; /* bytes per line (incl. virtual) */
173 int i_screen_depth; /* significant bpp: 8, 15, 16 or 24 */
174 int i_bytes_per_pixel;/* real screen depth: 1, 2, 3 or 4 */
175 float f_gamma; /* gamma */
176 boolean_t b_need_render; /* does the output method need a YUV
179 /* Color masks and shifts in RGB mode - masks are set by system
180 * initialization, shifts are calculated. A pixel color value can be
181 * obtained using the formula ((value >> rshift) << lshift) */
182 u32 i_red_mask; /* red mask */
183 u32 i_green_mask; /* green mask */
184 u32 i_blue_mask; /* blue mask */
185 int i_red_lshift, i_red_rshift; /* red shifts */
186 int i_green_lshift, i_green_rshift; /* green shifts */
187 int i_blue_lshift, i_blue_rshift; /* blue shifts */
189 /* Useful pre-calculated pixel values - these are not supposed to be
190 * accurate values, but rather values looking nice, given their usage. */
191 u32 i_white_pixel; /* white */
192 u32 i_black_pixel; /* black */
193 u32 i_gray_pixel; /* gray */
194 u32 i_blue_pixel; /* blue */
196 /* Plugin used and shortcuts to access its capabilities */
197 struct module_s * p_module;
198 int ( *pf_create ) ( struct vout_thread_s * );
199 int ( *pf_init ) ( struct vout_thread_s * );
200 void ( *pf_end ) ( struct vout_thread_s * );
201 void ( *pf_destroy ) ( struct vout_thread_s * );
202 int ( *pf_manage ) ( struct vout_thread_s * );
203 void ( *pf_display ) ( struct vout_thread_s * );
204 void ( *pf_setpalette ) ( struct vout_thread_s *, u16 *red,
205 u16 *green, u16 *blue, u16 *transp );
206 void ( *pf_setbuffers ) ( struct vout_thread_s *, void *, void * );
208 /* Pictures and rendering properties */
209 boolean_t b_grayscale; /* color or grayscale display */
210 boolean_t b_YCbr; /* use YUV to YCbr instead of RGB */
211 boolean_t b_info; /* print additional information */
212 boolean_t b_interface; /* render interface */
213 boolean_t b_scale; /* allow picture scaling */
214 boolean_t b_fullscreen; /* toogle fullscreen dusplay */
215 mtime_t render_time; /* last picture render time */
218 /* Idle screens management */
219 mtime_t last_display_date; /* last non idle display date */
220 mtime_t last_idle_date; /* last idle display date */
221 mtime_t init_display_date;
223 /* Statistics - these numbers are not supposed to be accurate, but are a
224 * good indication of the thread status */
225 count_t c_fps_samples; /* picture counts */
226 mtime_t p_fps_sample[VOUT_FPS_SAMPLES]; /* FPS samples dates */
228 /* Rendering buffers */
229 int i_buffer_index; /* buffer index */
230 vout_buffer_t p_buffer[2]; /* buffers properties */
232 /* Video heap and translation tables */
233 picture_t p_picture[VOUT_MAX_PICTURES]; /* pictures */
234 subpicture_t p_subpicture[VOUT_MAX_PICTURES]; /* subpictures */
235 int i_pictures; /* current heap size */
236 vout_yuv_t yuv; /* translation tables */
237 picture_t * p_rendered_pic; /* picture currently being rendered */
240 p_vout_font_t p_default_font; /* default font */
241 p_vout_font_t p_large_font; /* large font */
248 /* Flags for changes - these flags are set in the i_changes field when another
249 * thread changed a variable */
250 #define VOUT_INFO_CHANGE 0x0001 /* b_info changed */
251 #define VOUT_GRAYSCALE_CHANGE 0x0002 /* b_grayscale changed */
252 #define VOUT_INTF_CHANGE 0x0004 /* b_interface changed */
253 #define VOUT_SCALE_CHANGE 0x0008 /* b_scale changed */
254 #define VOUT_GAMMA_CHANGE 0x0010 /* gamma changed */
255 #define VOUT_CURSOR_CHANGE 0x0020 /* b_cursor changed */
256 #define VOUT_FULLSCREEN_CHANGE 0x0040 /* b_fullscreen changed */
257 #define VOUT_SIZE_CHANGE 0x0200 /* size changed */
258 #define VOUT_DEPTH_CHANGE 0x0400 /* depth changed */
259 #define VOUT_YUV_CHANGE 0x0800 /* change yuv tables */
261 /* Disabled for thread deadlocks issues --Meuuh */
262 //#define VOUT_NODISPLAY_CHANGE 0xff00 /* changes which forbidden display */
264 /*****************************************************************************
266 *****************************************************************************/
268 /* RGB2PIXEL: assemble RGB components to a pixel value, returns a u32 */
269 #define RGB2PIXEL( p_vout, i_red, i_green, i_blue ) \
270 (((((u32)i_red) >> p_vout->i_red_rshift) << p_vout->i_red_lshift) | \
271 ((((u32)i_green) >> p_vout->i_green_rshift) << p_vout->i_green_lshift) | \
272 ((((u32)i_blue) >> p_vout->i_blue_rshift) << p_vout->i_blue_lshift))
275 /*****************************************************************************
277 *****************************************************************************/
278 void vout_InitBank ( void );
279 void vout_EndBank ( void );
281 vout_thread_t * vout_CreateThread ( int *pi_status );
282 void vout_DestroyThread ( vout_thread_t *p_vout, int *pi_status );
284 vout_fifo_t * vout_CreateFifo ( void );
285 void vout_DestroyFifo ( vout_fifo_t *p_fifo );
286 void vout_FreeFifo ( vout_fifo_t *p_fifo );
288 picture_t * vout_CreatePicture ( vout_thread_t *p_vout, int i_type,
289 int i_width, int i_height );
290 void vout_DestroyPicture ( vout_thread_t *p_vout, picture_t *p_pic );
291 void vout_DisplayPicture ( vout_thread_t *p_vout, picture_t *p_pic );
292 void vout_DatePicture ( vout_thread_t *p_vout, picture_t *p_pic, mtime_t date );
293 void vout_LinkPicture ( vout_thread_t *p_vout, picture_t *p_pic );
294 void vout_UnlinkPicture ( vout_thread_t *p_vout, picture_t *p_pic );
296 subpicture_t * vout_CreateSubPicture ( vout_thread_t *p_vout, int i_type, int i_size );
297 void vout_DestroySubPicture ( vout_thread_t *p_vout, subpicture_t *p_subpic );
298 void vout_DisplaySubPicture ( vout_thread_t *p_vout, subpicture_t *p_subpic );