1 /*****************************************************************************
2 * video_output.c : 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 oppened video output thread.
6 *****************************************************************************
7 * Copyright (C) 2000 VideoLAN
9 * Authors: Vincent Seguin <seguin@via.ecp.fr>
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., 59 Temple Place - Suite 330, Boston, MA 02111, USA.
24 *****************************************************************************/
26 /*****************************************************************************
28 *****************************************************************************/
31 #include <errno.h> /* ENOMEM */
32 #include <stdlib.h> /* free() */
33 #include <stdio.h> /* sprintf() */
34 #include <string.h> /* strerror() */
37 # include <sys/times.h>
47 #include "video_output.h"
48 #include "video_text.h"
49 #include "video_spu.h"
50 #include "video_yuv.h"
56 /*****************************************************************************
58 *****************************************************************************/
59 static int BinaryLog ( u32 i );
60 static void MaskToShift ( int *pi_left, int *pi_right, u32 i_mask );
61 static int InitThread ( vout_thread_t *p_vout );
62 static void RunThread ( vout_thread_t *p_vout );
63 static void ErrorThread ( vout_thread_t *p_vout );
64 static void EndThread ( vout_thread_t *p_vout );
65 static void DestroyThread ( vout_thread_t *p_vout, int i_status );
66 static void Print ( vout_thread_t *p_vout, int i_x, int i_y,
67 int i_h_align, int i_v_align,
68 unsigned char *psz_text );
69 static void SetBufferArea ( vout_thread_t *p_vout, int i_x, int i_y,
71 static void SetBufferPicture ( vout_thread_t *p_vout, picture_t *p_pic );
72 static void RenderPicture ( vout_thread_t *p_vout, picture_t *p_pic );
73 static void RenderPictureInfo ( vout_thread_t *p_vout, picture_t *p_pic );
74 static void RenderSubPicture ( vout_thread_t *p_vout,
75 subpicture_t *p_subpic );
76 static void RenderInterface ( vout_thread_t *p_vout );
77 static int RenderIdle ( vout_thread_t *p_vout );
78 static int RenderSplash ( vout_thread_t *p_vout );
79 static void RenderInfo ( vout_thread_t *p_vout );
80 static int Manage ( vout_thread_t *p_vout );
81 static int Align ( vout_thread_t *p_vout, int *pi_x,
82 int *pi_y, int i_width, int i_height,
83 int i_h_align, int i_v_align );
84 static void SetPalette ( p_vout_thread_t p_vout, u16 *red,
85 u16 *green, u16 *blue, u16 *transp );
87 /*****************************************************************************
88 * vout_CreateThread: creates a new video output thread
89 *****************************************************************************
90 * This function creates a new video output thread, and returns a pointer
91 * to its description. On error, it returns NULL.
92 * If pi_status is NULL, then the function will block until the thread is ready.
93 * If not, it will be updated using one of the THREAD_* constants.
94 *****************************************************************************/
95 vout_thread_t * vout_CreateThread ( int *pi_status )
97 vout_thread_t * p_vout; /* thread descriptor */
98 int i_status; /* thread status */
99 int i_index; /* index for array initialization */
101 /* Allocate descriptor */
102 p_vout = (vout_thread_t *) malloc( sizeof(vout_thread_t) );
105 intf_ErrMsg( "vout error: vout thread creation returned %s",
110 /* Choose the best module */
111 p_vout->p_module = module_Need( p_main->p_bank,
112 MODULE_CAPABILITY_VOUT, NULL );
114 if( p_vout->p_module == NULL )
116 intf_ErrMsg( "vout error: no suitable vout module" );
121 #define f p_vout->p_module->p_functions->vout.functions.vout
122 p_vout->pf_create = f.pf_create;
123 p_vout->pf_init = f.pf_init;
124 p_vout->pf_end = f.pf_end;
125 p_vout->pf_destroy = f.pf_destroy;
126 p_vout->pf_manage = f.pf_manage;
127 p_vout->pf_display = f.pf_display;
128 p_vout->pf_setpalette = f.pf_setpalette;
131 if( p_vout->pf_setpalette == NULL )
133 p_vout->pf_setpalette = SetPalette;
136 /* Initialize thread properties - thread id and locks will be initialized
140 p_vout->b_active = 0;
141 p_vout->pi_status = (pi_status != NULL) ? pi_status : &i_status;
142 *p_vout->pi_status = THREAD_CREATE;
144 /* Initialize some fields used by the system-dependant method - these
145 * fields will probably be modified by the method, and are only
147 p_vout->i_changes = 0;
148 p_vout->i_width = main_GetIntVariable( VOUT_WIDTH_VAR,
149 VOUT_WIDTH_DEFAULT );
150 p_vout->i_height = main_GetIntVariable( VOUT_HEIGHT_VAR,
151 VOUT_HEIGHT_DEFAULT );
152 p_vout->i_bytes_per_line = p_vout->i_width * 2;
153 p_vout->i_screen_depth = 15;
154 p_vout->i_bytes_per_pixel = 2;
155 p_vout->f_gamma = VOUT_GAMMA;
156 p_vout->b_need_render = 1;
158 p_vout->b_grayscale = main_GetIntVariable( VOUT_GRAYSCALE_VAR,
159 VOUT_GRAYSCALE_DEFAULT );
161 p_vout->b_interface = 0;
164 intf_WarnMsg( 1, "wished configuration: %dx%d, %d/%d bpp (%d Bpl)",
165 p_vout->i_width, p_vout->i_height, p_vout->i_screen_depth,
166 p_vout->i_bytes_per_pixel * 8, p_vout->i_bytes_per_line );
168 /* Initialize idle screen */
169 p_vout->last_display_date = 0;
170 p_vout->last_idle_date = 0;
171 p_vout->init_display_date = mdate();
172 p_vout->render_time = 10000;
174 /* Initialize statistics fields */
175 p_vout->c_fps_samples = 0;
177 /* Initialize buffer index */
178 p_vout->i_buffer_index = 0;
180 /* Initialize pictures and subpictures - translation tables and functions
181 * will be initialized later in InitThread */
182 for( i_index = 0; i_index < VOUT_MAX_PICTURES; i_index++)
184 p_vout->p_picture[i_index].i_type = EMPTY_PICTURE;
185 p_vout->p_picture[i_index].i_status = FREE_PICTURE;
187 for( i_index = 0; i_index < VOUT_MAX_SUBPICTURES; i_index++)
189 p_vout->p_subpicture[i_index].i_type = EMPTY_SUBPICTURE;
190 p_vout->p_subpicture[i_index].i_status= FREE_SUBPICTURE;
192 p_vout->i_pictures = 0;
194 /* Create and initialize system-dependant method - this function issues its
195 * own error messages */
196 if( p_vout->pf_create( p_vout ) )
198 module_Unneed( p_main->p_bank, p_vout->p_module );
202 intf_WarnMsg( 1, "actual configuration: %dx%d, %d/%d bpp (%d Bpl), "
203 "masks: 0x%x/0x%x/0x%x",
204 p_vout->i_width, p_vout->i_height, p_vout->i_screen_depth,
205 p_vout->i_bytes_per_pixel * 8, p_vout->i_bytes_per_line,
206 p_vout->i_red_mask, p_vout->i_green_mask,
207 p_vout->i_blue_mask );
209 /* Calculate shifts from system-updated masks */
210 MaskToShift( &p_vout->i_red_lshift, &p_vout->i_red_rshift,
211 p_vout->i_red_mask );
212 MaskToShift( &p_vout->i_green_lshift, &p_vout->i_green_rshift,
213 p_vout->i_green_mask );
214 MaskToShift( &p_vout->i_blue_lshift, &p_vout->i_blue_rshift,
215 p_vout->i_blue_mask );
217 /* Set some useful colors */
218 p_vout->i_white_pixel = RGB2PIXEL( p_vout, 255, 255, 255 );
219 p_vout->i_black_pixel = RGB2PIXEL( p_vout, 0, 0, 0 );
220 p_vout->i_gray_pixel = RGB2PIXEL( p_vout, 128, 128, 128 );
221 p_vout->i_blue_pixel = RGB2PIXEL( p_vout, 0, 0, 50 );
223 /* Load fonts - fonts must be initialized after the system method since
224 * they may be dependant on screen depth and other thread properties */
225 p_vout->p_default_font = vout_LoadFont( VOUT_DEFAULT_FONT );
226 if( p_vout->p_default_font == NULL )
228 intf_ErrMsg( "vout error: could not load default font" );
229 p_vout->pf_destroy( p_vout );
234 p_vout->p_large_font = vout_LoadFont( VOUT_LARGE_FONT );
235 if( p_vout->p_large_font == NULL )
237 intf_ErrMsg( "vout error: could not load large font" );
238 vout_UnloadFont( p_vout->p_default_font );
239 p_vout->pf_destroy( p_vout );
244 /* Create thread and set locks */
245 vlc_mutex_init( &p_vout->picture_lock );
246 vlc_mutex_init( &p_vout->subpicture_lock );
247 vlc_mutex_init( &p_vout->change_lock );
249 if( vlc_thread_create( &p_vout->thread_id, "video output",
250 (void *) RunThread, (void *) p_vout) )
252 intf_ErrMsg("vout error: %s", strerror(ENOMEM));
253 vout_UnloadFont( p_vout->p_default_font );
254 vout_UnloadFont( p_vout->p_large_font );
255 p_vout->pf_destroy( p_vout );
260 intf_Msg( "vout: video display initialized (%dx%d, %d/%d bpp)",
261 p_vout->i_width, p_vout->i_height, p_vout->i_screen_depth,
262 p_vout->i_bytes_per_pixel * 8 );
264 /* If status is NULL, wait until the thread is created */
265 if( pi_status == NULL )
269 msleep( THREAD_SLEEP );
270 }while( (i_status != THREAD_READY) && (i_status != THREAD_ERROR)
271 && (i_status != THREAD_FATAL) );
272 if( i_status != THREAD_READY )
280 /*****************************************************************************
281 * vout_DestroyThread: destroys a previously created thread
282 *****************************************************************************
283 * Destroy a terminated thread.
284 * The function will request a destruction of the specified thread. If pi_error
285 * is NULL, it will return once the thread is destroyed. Else, it will be
286 * update using one of the THREAD_* constants.
287 *****************************************************************************/
288 void vout_DestroyThread( vout_thread_t *p_vout, int *pi_status )
290 int i_status; /* thread status */
294 p_vout->pi_status = (pi_status != NULL) ? pi_status : &i_status;
295 *p_vout->pi_status = THREAD_DESTROY;
297 /* Request thread destruction */
300 /* If status is NULL, wait until thread has been destroyed */
301 if( pi_status == NULL )
305 msleep( THREAD_SLEEP );
306 }while( (i_status != THREAD_OVER) && (i_status != THREAD_ERROR)
307 && (i_status != THREAD_FATAL) );
311 /*****************************************************************************
312 * vout_DisplaySubPicture: display a subpicture unit
313 *****************************************************************************
314 * Remove the reservation flag of an subpicture, which will cause it to be ready
315 * for display. The picture does not need to be locked, since it is ignored by
316 * the output thread if is reserved.
317 *****************************************************************************/
318 void vout_DisplaySubPicture( vout_thread_t *p_vout, subpicture_t *p_subpic )
321 char psz_begin_date[MSTRTIME_MAX_SIZE]; /* buffer for date string */
322 char psz_end_date[MSTRTIME_MAX_SIZE]; /* buffer for date string */
326 /* Check if status is valid */
327 if( p_subpic->i_status != RESERVED_SUBPICTURE )
329 intf_DbgMsg("error: subpicture %p has invalid status %d", p_subpic,
330 p_subpic->i_status );
334 /* Remove reservation flag */
335 p_subpic->i_status = READY_SUBPICTURE;
338 /* Send subpicture information */
339 intf_DbgMsg("subpicture %p: type=%d, begin date=%s, end date=%s",
340 p_subpic, p_subpic->i_type,
341 mstrtime( psz_begin_date, p_subpic->begin_date ),
342 mstrtime( psz_end_date, p_subpic->end_date ) );
346 /*****************************************************************************
347 * vout_CreateSubPicture: allocate a subpicture in the video output heap.
348 *****************************************************************************
349 * This function create a reserved subpicture in the video output heap.
350 * A null pointer is returned if the function fails. This method provides an
351 * already allocated zone of memory in the spu data fields. It needs locking
352 * since several pictures can be created by several producers threads.
353 *****************************************************************************/
354 subpicture_t *vout_CreateSubPicture( vout_thread_t *p_vout, int i_type,
357 int i_subpic; /* subpicture index */
358 subpicture_t * p_free_subpic = NULL; /* first free subpicture */
359 subpicture_t * p_destroyed_subpic = NULL; /* first destroyed subpic */
362 vlc_mutex_lock( &p_vout->subpicture_lock );
365 * Look for an empty place
367 for( i_subpic = 0; i_subpic < VOUT_MAX_SUBPICTURES; i_subpic++ )
369 if( p_vout->p_subpicture[i_subpic].i_status == DESTROYED_SUBPICTURE )
371 /* Subpicture is marked for destruction, but is still allocated */
372 if( (p_vout->p_subpicture[i_subpic].i_type == i_type) &&
373 (p_vout->p_subpicture[i_subpic].i_size >= i_size) )
375 /* Memory size do match or is smaller : memory will not be
376 * reallocated, and function can end immediately - this is
377 * the best possible case, since no memory allocation needs
379 p_vout->p_subpicture[i_subpic].i_status = RESERVED_SUBPICTURE;
381 intf_DbgMsg("subpicture %p (in destroyed subpicture slot)",
382 &p_vout->p_subpicture[i_subpic] );
384 vlc_mutex_unlock( &p_vout->subpicture_lock );
385 return( &p_vout->p_subpicture[i_subpic] );
387 else if( p_destroyed_subpic == NULL )
389 /* Memory size do not match, but subpicture index will be kept in
390 * case no other place are left */
391 p_destroyed_subpic = &p_vout->p_subpicture[i_subpic];
394 else if( (p_free_subpic == NULL) &&
395 (p_vout->p_subpicture[i_subpic].i_status == FREE_SUBPICTURE ))
397 /* Subpicture is empty and ready for allocation */
398 p_free_subpic = &p_vout->p_subpicture[i_subpic];
402 /* If no free subpictures are available, use a destroyed subpicture */
403 if( (p_free_subpic == NULL) && (p_destroyed_subpic != NULL ) )
405 /* No free subpicture or matching destroyed subpictures have been
406 * found, but a destroyed subpicture is still avalaible */
407 free( p_destroyed_subpic->p_data );
408 p_free_subpic = p_destroyed_subpic;
414 if( p_free_subpic != NULL )
416 /* Allocate memory */
419 case TEXT_SUBPICTURE: /* text subpicture */
420 p_free_subpic->p_data = malloc( i_size + 1 );
422 case DVD_SUBPICTURE: /* DVD subpicture unit */
423 p_free_subpic->p_data = malloc( i_size );
427 intf_DbgMsg("error: unknown subpicture type %d", i_type );
428 p_free_subpic->p_data = NULL;
433 if( p_free_subpic->p_data != NULL )
435 /* Copy subpicture information, set some default values */
436 p_free_subpic->i_type = i_type;
437 p_free_subpic->i_status = RESERVED_SUBPICTURE;
438 p_free_subpic->i_size = i_size;
439 p_free_subpic->i_x = 0;
440 p_free_subpic->i_y = 0;
441 p_free_subpic->i_width = 0;
442 p_free_subpic->i_height = 0;
443 p_free_subpic->i_horizontal_align = CENTER_RALIGN;
444 p_free_subpic->i_vertical_align = CENTER_RALIGN;
448 /* Memory allocation failed : set subpicture as empty */
449 p_free_subpic->i_type = EMPTY_SUBPICTURE;
450 p_free_subpic->i_status = FREE_SUBPICTURE;
451 p_free_subpic = NULL;
452 intf_ErrMsg( "vout error: spu allocation returned %s",
453 strerror( ENOMEM ) );
457 intf_DbgMsg("subpicture %p (in free subpicture slot)", p_free_subpic );
459 vlc_mutex_unlock( &p_vout->subpicture_lock );
460 return( p_free_subpic );
463 /* No free or destroyed subpicture could be found */
464 intf_DbgMsg( "warning: subpicture heap is full" );
465 vlc_mutex_unlock( &p_vout->subpicture_lock );
469 /*****************************************************************************
470 * vout_DestroySubPicture: remove a subpicture from the heap
471 *****************************************************************************
472 * This function frees a previously reserved subpicture.
473 * It is meant to be used when the construction of a picture aborted.
474 * This function does not need locking since reserved subpictures are ignored
475 * by the output thread.
476 *****************************************************************************/
477 void vout_DestroySubPicture( vout_thread_t *p_vout, subpicture_t *p_subpic )
480 /* Check if status is valid */
481 if( p_subpic->i_status != RESERVED_SUBPICTURE )
483 intf_DbgMsg("error: subpicture %p has invalid status %d",
484 p_subpic, p_subpic->i_status );
488 p_subpic->i_status = DESTROYED_SUBPICTURE;
491 intf_DbgMsg("subpicture %p", p_subpic);
495 /*****************************************************************************
496 * vout_DisplayPicture: display a picture
497 *****************************************************************************
498 * Remove the reservation flag of a picture, which will cause it to be ready for
499 * display. The picture won't be displayed until vout_DatePicture has been
501 *****************************************************************************/
502 void vout_DisplayPicture( vout_thread_t *p_vout, picture_t *p_pic )
504 vlc_mutex_lock( &p_vout->picture_lock );
505 switch( p_pic->i_status )
507 case RESERVED_PICTURE:
508 p_pic->i_status = RESERVED_DISP_PICTURE;
510 case RESERVED_DATED_PICTURE:
511 p_pic->i_status = READY_PICTURE;
515 intf_DbgMsg("error: picture %p has invalid status %d", p_pic, p_pic->i_status );
521 intf_DbgMsg("picture %p", p_pic);
523 vlc_mutex_unlock( &p_vout->picture_lock );
526 /*****************************************************************************
527 * vout_DatePicture: date a picture
528 *****************************************************************************
529 * Remove the reservation flag of a picture, which will cause it to be ready for
530 * display. The picture won't be displayed until vout_DisplayPicture has been
532 *****************************************************************************/
533 void vout_DatePicture( vout_thread_t *p_vout, picture_t *p_pic, mtime_t date )
536 char psz_date[MSTRTIME_MAX_SIZE]; /* date */
539 vlc_mutex_lock( &p_vout->picture_lock );
541 switch( p_pic->i_status )
543 case RESERVED_PICTURE:
544 p_pic->i_status = RESERVED_DATED_PICTURE;
546 case RESERVED_DISP_PICTURE:
547 p_pic->i_status = READY_PICTURE;
551 intf_DbgMsg("error: picture %p has invalid status %d", p_pic, p_pic->i_status );
557 intf_DbgMsg("picture %p, display date: %s", p_pic, mstrtime( psz_date, p_pic->date) );
559 vlc_mutex_unlock( &p_vout->picture_lock );
562 /*****************************************************************************
563 * vout_CreatePicture: allocate a picture in the video output heap.
564 *****************************************************************************
565 * This function create a reserved image in the video output heap.
566 * A null pointer is returned if the function fails. This method provides an
567 * already allocated zone of memory in the picture data fields. It needs locking
568 * since several pictures can be created by several producers threads.
569 *****************************************************************************/
570 picture_t *vout_CreatePicture( vout_thread_t *p_vout, int i_type,
571 int i_width, int i_height )
573 int i_picture; /* picture index */
574 int i_chroma_width = 0; /* chroma width */
575 picture_t * p_free_picture = NULL; /* first free picture */
576 picture_t * p_destroyed_picture = NULL; /* first destroyed picture */
579 vlc_mutex_lock( &p_vout->picture_lock );
582 * Look for an empty place
584 for( i_picture = 0; i_picture < VOUT_MAX_PICTURES; i_picture++ )
586 if( p_vout->p_picture[i_picture].i_status == DESTROYED_PICTURE )
588 /* Picture is marked for destruction, but is still allocated - note
589 * that if width and type are the same for two pictures, chroma_width
590 * should also be the same */
591 if( (p_vout->p_picture[i_picture].i_type == i_type) &&
592 (p_vout->p_picture[i_picture].i_height == i_height) &&
593 (p_vout->p_picture[i_picture].i_width == i_width) )
595 /* Memory size do match : memory will not be reallocated, and function
596 * can end immediately - this is the best possible case, since no
597 * memory allocation needs to be done */
598 p_vout->p_picture[i_picture].i_status = RESERVED_PICTURE;
599 p_vout->i_pictures++;
601 intf_DbgMsg("picture %p (in destroyed picture slot)",
602 &p_vout->p_picture[i_picture] );
604 vlc_mutex_unlock( &p_vout->picture_lock );
605 return( &p_vout->p_picture[i_picture] );
607 else if( p_destroyed_picture == NULL )
609 /* Memory size do not match, but picture index will be kept in
610 * case no other place are left */
611 p_destroyed_picture = &p_vout->p_picture[i_picture];
614 else if( (p_free_picture == NULL) &&
615 (p_vout->p_picture[i_picture].i_status == FREE_PICTURE ))
617 /* Picture is empty and ready for allocation */
618 p_free_picture = &p_vout->p_picture[i_picture];
622 /* If no free picture is available, use a destroyed picture */
623 if( (p_free_picture == NULL) && (p_destroyed_picture != NULL ) )
625 /* No free picture or matching destroyed picture has been found, but
626 * a destroyed picture is still avalaible */
627 free( p_destroyed_picture->p_data );
628 p_free_picture = p_destroyed_picture;
634 if( p_free_picture != NULL )
636 /* Allocate memory */
639 case YUV_420_PICTURE: /* YUV 420: 1,1/4,1/4 samples per pixel */
640 i_chroma_width = i_width / 2;
641 p_free_picture->p_data = malloc( i_height * i_chroma_width * 3 * sizeof( yuv_data_t ) );
642 p_free_picture->p_y = (yuv_data_t *)p_free_picture->p_data;
643 p_free_picture->p_u = (yuv_data_t *)p_free_picture->p_data +i_height*i_chroma_width*4/2;
644 p_free_picture->p_v = (yuv_data_t *)p_free_picture->p_data +i_height*i_chroma_width*5/2;
646 case YUV_422_PICTURE: /* YUV 422: 1,1/2,1/2 samples per pixel */
647 i_chroma_width = i_width / 2;
648 p_free_picture->p_data = malloc( i_height * i_chroma_width * 4 * sizeof( yuv_data_t ) );
649 p_free_picture->p_y = (yuv_data_t *)p_free_picture->p_data;
650 p_free_picture->p_u = (yuv_data_t *)p_free_picture->p_data +i_height*i_chroma_width*2;
651 p_free_picture->p_v = (yuv_data_t *)p_free_picture->p_data +i_height*i_chroma_width*3;
653 case YUV_444_PICTURE: /* YUV 444: 1,1,1 samples per pixel */
654 i_chroma_width = i_width;
655 p_free_picture->p_data = malloc( i_height * i_chroma_width * 3 * sizeof( yuv_data_t ) );
656 p_free_picture->p_y = (yuv_data_t *)p_free_picture->p_data;
657 p_free_picture->p_u = (yuv_data_t *)p_free_picture->p_data +i_height*i_chroma_width;
658 p_free_picture->p_v = (yuv_data_t *)p_free_picture->p_data +i_height*i_chroma_width*2;
662 intf_DbgMsg("error: unknown picture type %d", i_type );
663 p_free_picture->p_data = NULL;
668 if( p_free_picture->p_data != NULL )
670 /* Copy picture information, set some default values */
671 p_free_picture->i_type = i_type;
672 p_free_picture->i_status = RESERVED_PICTURE;
673 p_free_picture->i_matrix_coefficients = 1;
674 p_free_picture->i_width = i_width;
675 p_free_picture->i_height = i_height;
676 p_free_picture->i_chroma_width = i_chroma_width;
677 p_free_picture->i_size = i_width * i_height;
678 p_free_picture->i_chroma_size = i_chroma_width
680 p_free_picture->i_display_horizontal_offset = 0;
681 p_free_picture->i_display_vertical_offset = 0;
682 p_free_picture->i_display_width = i_width;
683 p_free_picture->i_display_height = i_height;
684 p_free_picture->i_aspect_ratio = AR_SQUARE_PICTURE;
685 p_free_picture->i_refcount = 0;
686 p_vout->i_pictures++;
690 /* Memory allocation failed : set picture as empty */
691 p_free_picture->i_type = EMPTY_PICTURE;
692 p_free_picture->i_status = FREE_PICTURE;
693 p_free_picture = NULL;
694 intf_ErrMsg( "vout error: picture allocation returned %s",
695 strerror( ENOMEM ) );
699 intf_DbgMsg("picture %p (in free picture slot)", p_free_picture );
701 vlc_mutex_unlock( &p_vout->picture_lock );
703 /* Initialize mutex */
704 vlc_mutex_init( &(p_free_picture->lock_deccount) );
706 return( p_free_picture );
709 /* No free or destroyed picture could be found */
710 intf_DbgMsg( "warning: picture heap is full" );
711 vlc_mutex_unlock( &p_vout->picture_lock );
715 /*****************************************************************************
716 * vout_DestroyPicture: remove a permanent or reserved picture from the heap
717 *****************************************************************************
718 * This function frees a previously reserved picture or a permanent
719 * picture. It is meant to be used when the construction of a picture aborted.
720 * Note that the picture will be destroyed even if it is linked !
721 *****************************************************************************/
722 void vout_DestroyPicture( vout_thread_t *p_vout, picture_t *p_pic )
724 vlc_mutex_lock( &p_vout->picture_lock );
727 /* Check if picture status is valid */
728 if( (p_pic->i_status != RESERVED_PICTURE) &&
729 (p_pic->i_status != RESERVED_DATED_PICTURE) &&
730 (p_pic->i_status != RESERVED_DISP_PICTURE) )
732 intf_DbgMsg("error: picture %p has invalid status %d", p_pic, p_pic->i_status );
736 p_pic->i_status = DESTROYED_PICTURE;
737 p_vout->i_pictures--;
740 intf_DbgMsg("picture %p", p_pic);
743 /* destroy the lock that had been initialized in CreatePicture */
744 vlc_mutex_destroy( &(p_pic->lock_deccount) );
746 vlc_mutex_unlock( &p_vout->picture_lock );
749 /*****************************************************************************
750 * vout_LinkPicture: increment reference counter of a picture
751 *****************************************************************************
752 * This function increment the reference counter of a picture in the video
753 * heap. It needs a lock since several producer threads can access the picture.
754 *****************************************************************************/
755 void vout_LinkPicture( vout_thread_t *p_vout, picture_t *p_pic )
757 vlc_mutex_lock( &p_vout->picture_lock );
761 intf_DbgMsg("picture %p refcount=%d", p_pic, p_pic->i_refcount );
764 vlc_mutex_unlock( &p_vout->picture_lock );
767 /*****************************************************************************
768 * vout_UnlinkPicture: decrement reference counter of a picture
769 *****************************************************************************
770 * This function decrement the reference counter of a picture in the video heap.
771 *****************************************************************************/
772 void vout_UnlinkPicture( vout_thread_t *p_vout, picture_t *p_pic )
774 vlc_mutex_lock( &p_vout->picture_lock );
778 if( p_pic->i_refcount < 0 )
780 intf_DbgMsg("error: refcount < 0");
781 p_pic->i_refcount = 0;
785 if( (p_pic->i_refcount == 0) && (p_pic->i_status == DISPLAYED_PICTURE) )
787 p_pic->i_status = DESTROYED_PICTURE;
788 p_vout->i_pictures--;
792 intf_DbgMsg("picture %p refcount=%d", p_pic, p_pic->i_refcount );
795 vlc_mutex_unlock( &p_vout->picture_lock );
798 /*****************************************************************************
799 * vout_SetBuffers: set buffers adresses
800 *****************************************************************************
801 * This function is called by system drivers to set buffers video memory
803 *****************************************************************************/
804 void vout_SetBuffers( vout_thread_t *p_vout, void *p_buf1, void *p_buf2 )
806 /* No picture previously */
807 p_vout->p_buffer[0].i_pic_x = 0;
808 p_vout->p_buffer[0].i_pic_y = 0;
809 p_vout->p_buffer[0].i_pic_width = 0;
810 p_vout->p_buffer[0].i_pic_height = 0;
811 p_vout->p_buffer[1].i_pic_x = 0;
812 p_vout->p_buffer[1].i_pic_y = 0;
813 p_vout->p_buffer[1].i_pic_width = 0;
814 p_vout->p_buffer[1].i_pic_height = 0;
816 /* The first area covers all the screen */
817 p_vout->p_buffer[0].i_areas = 1;
818 p_vout->p_buffer[0].pi_area_begin[0] = 0;
819 p_vout->p_buffer[0].pi_area_end[0] = p_vout->i_height - 1;
820 p_vout->p_buffer[1].i_areas = 1;
821 p_vout->p_buffer[1].pi_area_begin[0] = 0;
822 p_vout->p_buffer[1].pi_area_end[0] = p_vout->i_height - 1;
825 p_vout->p_buffer[0].p_data = p_buf1;
826 p_vout->p_buffer[1].p_data = p_buf2;
829 /*****************************************************************************
830 * vout_Pixel2RGB: return red, green and blue from pixel value
831 *****************************************************************************
832 * Return color values, in 0-255 range, of the decomposition of a pixel. This
833 * is a slow routine and should only be used for initialization phase.
834 *****************************************************************************/
835 void vout_Pixel2RGB( vout_thread_t *p_vout, u32 i_pixel, int *pi_red, int *pi_green, int *pi_blue )
837 *pi_red = i_pixel & p_vout->i_red_mask;
838 *pi_green = i_pixel & p_vout->i_green_mask;
839 *pi_blue = i_pixel & p_vout->i_blue_mask;
842 /* following functions are local */
844 /*****************************************************************************
845 * BinaryLog: computes the base 2 log of a binary value
846 *****************************************************************************
847 * This functions is used by MaskToShift, to get a bit index from a binary
849 *****************************************************************************/
850 static int BinaryLog(u32 i)
875 if (i != ((u32)1 << i_log))
877 intf_DbgMsg("internal error: binary log overflow");
883 /*****************************************************************************
884 * MaskToShift: transform a color mask into right and left shifts
885 *****************************************************************************
886 * This function is used for obtaining color shifts from masks.
887 *****************************************************************************/
888 static void MaskToShift( int *pi_left, int *pi_right, u32 i_mask )
890 u32 i_low, i_high; /* lower hand higher bits of the mask */
893 i_low = i_mask & (- i_mask); /* lower bit of the mask */
894 i_high = i_mask + i_low; /* higher bit of the mask */
896 /* Transform bits into an index */
897 i_low = BinaryLog (i_low);
898 i_high = BinaryLog (i_high);
900 /* Update pointers and return */
902 *pi_right = (8 - i_high + i_low);
905 /*****************************************************************************
906 * InitThread: initialize video output thread
907 *****************************************************************************
908 * This function is called from RunThread and performs the second step of the
909 * initialization. It returns 0 on success. Note that the thread's flag are not
910 * modified inside this function.
911 *****************************************************************************/
912 static int InitThread( vout_thread_t *p_vout )
915 *p_vout->pi_status = THREAD_START;
917 vlc_mutex_lock( &p_vout->change_lock );
923 /* Initialize output method - this function issues its own error messages */
924 if( p_vout->pf_init( p_vout ) )
929 /* Initialize convertion tables and functions */
930 if( vout_InitYUV( p_vout ) )
932 intf_ErrMsg("vout error: can't allocate YUV translation tables");
936 /* Mark thread as running and return */
937 p_vout->b_active = 1;
938 *p_vout->pi_status = THREAD_READY;
941 intf_DbgMsg("thread ready");
945 /*****************************************************************************
946 * RunThread: video output thread
947 *****************************************************************************
948 * Video output thread. This function does only returns when the thread is
949 * terminated. It handles the pictures arriving in the video heap and the
950 * display device events.
951 *****************************************************************************/
952 static void RunThread( vout_thread_t *p_vout)
954 int i_index; /* index in heap */
955 mtime_t current_date; /* current date */
956 mtime_t display_date; /* display date */
957 boolean_t b_display; /* display flag */
958 picture_t * p_pic; /* picture pointer */
959 subpicture_t * p_subpic; /* subpicture pointer */
964 p_vout->b_error = InitThread( p_vout );
965 if( p_vout->b_error )
967 DestroyThread( p_vout, THREAD_ERROR );
972 * Main loop - it is not executed if an error occured during
975 while( (!p_vout->b_die) && (!p_vout->b_error) )
977 /* Initialize loop variables */
981 current_date = mdate();
984 if( !(p_vout->c_loops % VOUT_STATS_NB_LOOPS) )
987 intf_Msg("vout stats: picture heap: %d/%d",
988 p_vout->i_pictures, VOUT_MAX_PICTURES);
993 long i_fps = VOUT_FPS_SAMPLES * 1000000 * 10 /
994 ( p_vout->p_fps_sample[ (p_vout->c_fps_samples - 1)
995 % VOUT_FPS_SAMPLES ] -
996 p_vout->p_fps_sample[ p_vout->c_fps_samples
997 % VOUT_FPS_SAMPLES ] );
998 intf_Msg( "vout stats: %li.%i fps",
999 i_fps / 10, (int)i_fps % 10 );
1005 * Find the picture to display - this operation does not need lock,
1006 * since only READY_PICTUREs are handled
1008 for( i_index = 0; i_index < VOUT_MAX_PICTURES; i_index++ )
1010 if( (p_vout->p_picture[i_index].i_status == READY_PICTURE) &&
1011 ( (p_pic == NULL) ||
1012 (p_vout->p_picture[i_index].date < display_date) ) )
1014 p_pic = &p_vout->p_picture[i_index];
1015 display_date = p_pic->date;
1021 /* Computes FPS rate */
1022 p_vout->p_fps_sample[ p_vout->c_fps_samples++ % VOUT_FPS_SAMPLES ] = display_date;
1024 if( display_date < current_date - p_vout->render_time )
1026 /* Picture is late: it will be destroyed and the thread
1027 * will sleep and go to next picture */
1029 vlc_mutex_lock( &p_vout->picture_lock );
1030 if( p_pic->i_refcount )
1032 p_pic->i_status = DISPLAYED_PICTURE;
1036 p_pic->i_status = DESTROYED_PICTURE;
1037 p_vout->i_pictures--;
1040 "warning: late picture skipped (%p)", p_pic );
1041 vlc_mutex_unlock( &p_vout->picture_lock );
1045 else if( display_date > current_date + VOUT_DISPLAY_DELAY )
1047 /* A picture is ready to be rendered, but its rendering date
1048 * is far from the current one so the thread will perform an
1049 * empty loop as if no picture were found. The picture state
1056 * Find the subpictures to display - this operation does not need
1057 * lock, since only READY_SUBPICTURE are handled. If no picture
1058 * has been selected, display_date will depend on the subpicture.
1059 * We get an easily parsable chained list of subpictures which
1060 * ends with NULL since p_subpic was initialized to NULL.
1062 for( i_index = 0; i_index < VOUT_MAX_SUBPICTURES; i_index++ )
1064 if( p_vout->p_subpicture[i_index].i_status == READY_SUBPICTURE )
1066 p_vout->p_subpicture[i_index].p_next = p_subpic;
1067 p_subpic = &p_vout->p_subpicture[i_index];
1072 * Perform rendering, sleep and display rendered picture
1074 if( p_pic ) /* picture and perhaps subpicture */
1076 b_display = p_vout->b_active;
1077 p_vout->last_display_date = display_date;
1078 p_vout->p_rendered_pic = p_pic;
1083 /* Set picture dimensions and clear buffer */
1084 SetBufferPicture( p_vout, p_pic );
1086 /* FIXME: if b_need_render == 0 we need to do something with
1087 * the subpictures one day. */
1089 if( p_vout->b_need_render && b_display )
1091 /* Render picture and information */
1092 RenderPicture( p_vout, p_pic );
1093 if( p_vout->b_info )
1095 RenderPictureInfo( p_vout, p_pic );
1096 RenderInfo( p_vout );
1100 RenderSubPicture( p_vout, p_subpic );
1104 /* Render interface and subpicture */
1105 if( b_display && p_vout->b_interface && p_vout->b_need_render )
1107 RenderInterface( p_vout );
1111 else if( p_vout->b_active && p_vout->b_need_render
1112 && p_vout->init_display_date == 0)
1114 /* Idle or interface screen alone */
1116 if( p_vout->b_interface && 0 /* && XXX?? intf_change */ )
1118 /* Interface has changed, so a new rendering is required - force
1119 * it by setting last idle date to 0 */
1120 p_vout->last_idle_date = 0;
1123 /* Render idle screen and update idle date, then render interface if
1125 b_display = RenderIdle( p_vout );
1128 p_vout->last_idle_date = current_date;
1129 if( p_vout->b_interface )
1131 RenderInterface( p_vout );
1143 * Check for the current time and
1144 * display splash screen if everything is on time
1146 if( p_vout->init_display_date > 0 && p_vout->b_need_render )
1148 if( p_vout->b_active &&
1149 mdate()-p_vout->init_display_date < 5000000)
1151 /* there is something to display ! */
1153 RenderSplash( p_vout );
1156 /* no splash screen ! */
1157 p_vout->init_display_date=0;
1163 * Sleep, wake up and display rendered picture
1166 if( display_date != 0 )
1168 /* Store render time using Bresenham algorithm */
1169 p_vout->render_time += mdate() - current_date;
1170 p_vout->render_time >>= 1;
1173 /* Give back change lock */
1174 vlc_mutex_unlock( &p_vout->change_lock );
1176 /* Sleep a while or until a given date */
1177 if( display_date != 0 )
1179 mwait( display_date - VOUT_MWAIT_TOLERANCE );
1183 msleep( VOUT_IDLE_SLEEP );
1186 /* On awakening, take back lock and send immediately picture to display,
1187 * then swap buffers */
1188 vlc_mutex_lock( &p_vout->change_lock );
1190 intf_DbgMsg( "picture %p, subpicture %p in buffer %d, display=%d", p_pic, p_subpic,
1191 p_vout->i_buffer_index, b_display /* && !(p_vout->i_changes & VOUT_NODISPLAY_CHANGE) */ );
1193 if( b_display /* && !(p_vout->i_changes & VOUT_NODISPLAY_CHANGE) */ )
1195 p_vout->pf_display( p_vout );
1197 p_vout->i_buffer_index = ++p_vout->i_buffer_index & 1;
1203 /* Remove picture from heap */
1204 vlc_mutex_lock( &p_vout->picture_lock );
1205 if( p_pic->i_refcount )
1207 p_pic->i_status = DISPLAYED_PICTURE;
1211 p_pic->i_status = DESTROYED_PICTURE;
1212 p_vout->i_pictures--;
1214 vlc_mutex_unlock( &p_vout->picture_lock );
1219 * Check events and manage thread
1221 if( p_vout->pf_manage( p_vout ) | Manage( p_vout ) )
1223 /* A fatal error occured, and the thread must terminate immediately,
1224 * without displaying anything - setting b_error to 1 cause the
1225 * immediate end of the main while() loop. */
1226 p_vout->b_error = 1;
1231 * Error loop - wait until the thread destruction is requested
1233 if( p_vout->b_error )
1235 ErrorThread( p_vout );
1239 EndThread( p_vout );
1240 DestroyThread( p_vout, THREAD_OVER );
1241 intf_DbgMsg( "thread end" );
1244 /*****************************************************************************
1245 * ErrorThread: RunThread() error loop
1246 *****************************************************************************
1247 * This function is called when an error occured during thread main's loop. The
1248 * thread can still receive feed, but must be ready to terminate as soon as
1250 *****************************************************************************/
1251 static void ErrorThread( vout_thread_t *p_vout )
1253 /* Wait until a `die' order */
1254 while( !p_vout->b_die )
1257 msleep( VOUT_IDLE_SLEEP );
1261 /*****************************************************************************
1262 * EndThread: thread destruction
1263 *****************************************************************************
1264 * This function is called when the thread ends after a sucessful
1265 * initialization. It frees all ressources allocated by InitThread.
1266 *****************************************************************************/
1267 static void EndThread( vout_thread_t *p_vout )
1269 int i_index; /* index in heap */
1272 *p_vout->pi_status = THREAD_END;
1276 struct tms cpu_usage;
1277 times( &cpu_usage );
1279 intf_Msg( "vout stats: cpu usage (user: %d, system: %d)",
1280 cpu_usage.tms_utime, cpu_usage.tms_stime );
1284 /* Destroy all remaining pictures and subpictures */
1285 for( i_index = 0; i_index < VOUT_MAX_PICTURES; i_index++ )
1287 if( p_vout->p_picture[i_index].i_status != FREE_PICTURE )
1289 free( p_vout->p_picture[i_index].p_data );
1293 for( i_index = 0; i_index < VOUT_MAX_SUBPICTURES; i_index++ )
1295 if( p_vout->p_subpicture[i_index].i_status != FREE_SUBPICTURE )
1297 free( p_vout->p_subpicture[i_index].p_data );
1301 /* Destroy translation tables */
1302 vout_EndYUV( p_vout );
1303 p_vout->pf_end( p_vout );
1305 /* Release the change lock */
1306 vlc_mutex_unlock( &p_vout->change_lock );
1309 /*****************************************************************************
1310 * DestroyThread: thread destruction
1311 *****************************************************************************
1312 * This function is called when the thread ends. It frees all ressources
1313 * allocated by CreateThread. Status is available at this stage.
1314 *****************************************************************************/
1315 static void DestroyThread( vout_thread_t *p_vout, int i_status )
1317 int *pi_status; /* status adress */
1319 /* Store status adress */
1320 pi_status = p_vout->pi_status;
1322 /* Destroy thread structures allocated by Create and InitThread */
1323 vout_UnloadFont( p_vout->p_default_font );
1324 vout_UnloadFont( p_vout->p_large_font );
1325 p_vout->pf_destroy( p_vout );
1327 /* Destroy the locks */
1328 vlc_mutex_destroy( &p_vout->picture_lock );
1329 vlc_mutex_destroy( &p_vout->subpicture_lock );
1330 vlc_mutex_destroy( &p_vout->change_lock );
1332 /* Release the module */
1333 module_Unneed( p_main->p_bank, p_vout->p_module );
1335 /* Free structure */
1337 *pi_status = i_status;
1340 /*****************************************************************************
1341 * Print: print simple text on a picture
1342 *****************************************************************************
1343 * This function will print a simple text on the picture. It is designed to
1344 * print debugging or general information.
1345 *****************************************************************************/
1346 void Print( vout_thread_t *p_vout, int i_x, int i_y, int i_h_align, int i_v_align, unsigned char *psz_text )
1348 int i_text_height; /* total text height */
1349 int i_text_width; /* total text width */
1351 /* Update upper left coordinates according to alignment */
1352 vout_TextSize( p_vout->p_default_font, 0, psz_text, &i_text_width, &i_text_height );
1353 if( !Align( p_vout, &i_x, &i_y, i_text_width, i_text_height, i_h_align, i_v_align ) )
1355 /* Set area and print text */
1356 SetBufferArea( p_vout, i_x, i_y, i_text_width, i_text_height );
1357 vout_Print( p_vout->p_default_font, p_vout->p_buffer[ p_vout->i_buffer_index ].p_data +
1358 i_y * p_vout->i_bytes_per_line + i_x * p_vout->i_bytes_per_pixel,
1359 p_vout->i_bytes_per_pixel, p_vout->i_bytes_per_line,
1360 p_vout->i_white_pixel, 0, 0,
1365 /*****************************************************************************
1366 * SetBufferArea: activate an area in current buffer
1367 *****************************************************************************
1368 * This function is called when something is rendered on the current buffer.
1369 * It set the area as active and prepare it to be cleared on next rendering.
1370 * Pay attention to the fact that in this functions, i_h is in fact the end y
1371 * coordinate of the new area.
1372 *****************************************************************************/
1373 static void SetBufferArea( vout_thread_t *p_vout, int i_x, int i_y, int i_w, int i_h )
1375 vout_buffer_t * p_buffer; /* current buffer */
1376 int i_area_begin, i_area_end; /* area vertical extension */
1377 int i_area, i_area_copy; /* area index */
1378 int i_area_shift; /* shift distance for areas */
1380 /* Choose buffer and modify h to end of area position */
1381 p_buffer = &p_vout->p_buffer[ p_vout->i_buffer_index ];
1385 * Remove part of the area which is inside the picture - this is done
1386 * by calling again SetBufferArea with the correct areas dimensions.
1388 if( (i_x >= p_buffer->i_pic_x) && (i_x + i_w <= p_buffer->i_pic_x + p_buffer->i_pic_width) )
1390 i_area_begin = p_buffer->i_pic_y;
1391 i_area_end = i_area_begin + p_buffer->i_pic_height - 1;
1393 if( ((i_y >= i_area_begin) && (i_y <= i_area_end)) ||
1394 ((i_h >= i_area_begin) && (i_h <= i_area_end)) ||
1395 ((i_y < i_area_begin) && (i_h > i_area_end)) )
1397 /* Keep the stripe above the picture, if any */
1398 if( i_y < i_area_begin )
1400 SetBufferArea( p_vout, i_x, i_y, i_w, i_area_begin - i_y );
1402 /* Keep the stripe below the picture, if any */
1403 if( i_h > i_area_end )
1405 SetBufferArea( p_vout, i_x, i_area_end, i_w, i_h - i_area_end );
1411 /* Skip some extensions until interesting areas */
1413 (i_area < p_buffer->i_areas) &&
1414 (p_buffer->pi_area_end[i_area] + 1 <= i_y);
1420 if( i_area == p_buffer->i_areas )
1422 /* New area is below all existing ones: just add it at the end of the
1423 * array, if possible - otherwise, append it to the last one */
1424 if( i_area < VOUT_MAX_AREAS )
1426 p_buffer->pi_area_begin[i_area] = i_y;
1427 p_buffer->pi_area_end[i_area] = i_h;
1428 p_buffer->i_areas++;
1433 intf_DbgMsg("area overflow");
1435 p_buffer->pi_area_end[VOUT_MAX_AREAS - 1] = i_h;
1440 i_area_begin = p_buffer->pi_area_begin[i_area];
1441 i_area_end = p_buffer->pi_area_end[i_area];
1443 if( i_y < i_area_begin )
1445 if( i_h >= i_area_begin - 1 )
1447 /* Extend area above */
1448 p_buffer->pi_area_begin[i_area] = i_y;
1452 /* Create a new area above : merge last area if overflow, then
1453 * move all old areas down */
1454 if( p_buffer->i_areas == VOUT_MAX_AREAS )
1457 intf_DbgMsg("areas overflow");
1459 p_buffer->pi_area_end[VOUT_MAX_AREAS - 2] = p_buffer->pi_area_end[VOUT_MAX_AREAS - 1];
1463 p_buffer->i_areas++;
1465 for( i_area_copy = p_buffer->i_areas - 1; i_area_copy > i_area; i_area_copy-- )
1467 p_buffer->pi_area_begin[i_area_copy] = p_buffer->pi_area_begin[i_area_copy - 1];
1468 p_buffer->pi_area_end[i_area_copy] = p_buffer->pi_area_end[i_area_copy - 1];
1470 p_buffer->pi_area_begin[i_area] = i_y;
1471 p_buffer->pi_area_end[i_area] = i_h;
1475 if( i_h > i_area_end )
1477 /* Find further areas which can be merged with the new one */
1478 for( i_area_copy = i_area + 1;
1479 (i_area_copy < p_buffer->i_areas) &&
1480 (p_buffer->pi_area_begin[i_area] <= i_h);
1487 if( i_area_copy != i_area )
1489 /* Merge with last possible areas */
1490 p_buffer->pi_area_end[i_area] = MAX( i_h, p_buffer->pi_area_end[i_area_copy] );
1492 /* Shift lower areas upward */
1493 i_area_shift = i_area_copy - i_area;
1494 p_buffer->i_areas -= i_area_shift;
1495 for( i_area_copy = i_area + 1; i_area_copy < p_buffer->i_areas; i_area_copy++ )
1497 p_buffer->pi_area_begin[i_area_copy] = p_buffer->pi_area_begin[i_area_copy + i_area_shift];
1498 p_buffer->pi_area_end[i_area_copy] = p_buffer->pi_area_end[i_area_copy + i_area_shift];
1503 /* Extend area below */
1504 p_buffer->pi_area_end[i_area] = i_h;
1510 /*****************************************************************************
1511 * SetBufferPicture: clear buffer and set picture area
1512 *****************************************************************************
1513 * This function is called before any rendering. It clears the current
1514 * rendering buffer and set the new picture area. If the picture pointer is
1515 * NULL, then no picture area is defined. Floating operations are avoided since
1516 * some MMX calculations may follow.
1517 *****************************************************************************/
1518 static void SetBufferPicture( vout_thread_t *p_vout, picture_t *p_pic )
1520 vout_buffer_t * p_buffer; /* current buffer */
1521 int i_pic_x, i_pic_y; /* picture position */
1522 int i_pic_width, i_pic_height; /* picture dimensions */
1523 int i_old_pic_y, i_old_pic_height; /* old picture area */
1524 int i_vout_width, i_vout_height; /* display dimensions */
1525 int i_area; /* area index */
1526 int i_data_index; /* area data index */
1527 int i_data_size; /* area data size, in 256 bytes blocs */
1528 u64 * p_data; /* area data, for clearing */
1529 byte_t * p_data8; /* area data, for clearing (slow) */
1531 /* Choose buffer and set display dimensions */
1532 p_buffer = &p_vout->p_buffer[ p_vout->i_buffer_index ];
1533 i_vout_width = p_vout->i_width;
1534 i_vout_height = p_vout->i_height;
1537 * Computes new picture size
1541 /* Try horizontal scaling first - width must be a mutiple of 16 */
1542 i_pic_width = (( p_vout->b_scale || (p_pic->i_width > i_vout_width)) ?
1543 i_vout_width : p_pic->i_width) & ~0xf;
1544 switch( p_pic->i_aspect_ratio )
1546 case AR_3_4_PICTURE:
1547 i_pic_height = i_pic_width * 3 / 4;
1549 case AR_16_9_PICTURE:
1550 i_pic_height = i_pic_width * 9 / 16;
1552 case AR_221_1_PICTURE:
1553 i_pic_height = i_pic_width * 100 / 221;
1555 case AR_SQUARE_PICTURE:
1557 i_pic_height = p_pic->i_height * i_pic_width / p_pic->i_width;
1561 /* If picture dimensions using horizontal scaling are too large, use
1562 * vertical scaling. Since width must be a multiple of 16, height is
1563 * adjusted again after. */
1564 if( i_pic_height > i_vout_height )
1566 i_pic_height = ( p_vout->b_scale || (p_pic->i_height > i_vout_height)) ?
1567 i_vout_height : p_pic->i_height;
1568 switch( p_pic->i_aspect_ratio )
1570 case AR_3_4_PICTURE:
1571 i_pic_width = (i_pic_height * 4 / 3) & ~0xf;
1572 i_pic_height = i_pic_width * 3 / 4;
1574 case AR_16_9_PICTURE:
1575 i_pic_width = (i_pic_height * 16 / 9) & ~0xf;
1576 i_pic_height = i_pic_width * 9 / 16;
1578 case AR_221_1_PICTURE:
1579 i_pic_width = (i_pic_height * 221 / 100) & ~0xf;
1580 i_pic_height = i_pic_width * 100 / 221;
1582 case AR_SQUARE_PICTURE:
1584 i_pic_width = (p_pic->i_width * i_pic_height / p_pic->i_height) & ~0xf;
1585 i_pic_height = p_pic->i_height * i_pic_width / p_pic->i_width;
1590 /* Set picture position */
1591 i_pic_x = (p_vout->i_width - i_pic_width) / 2;
1592 i_pic_y = (p_vout->i_height - i_pic_height) / 2;
1597 /* No picture: size is 0 */
1605 * Set new picture size - if it is smaller than the previous one, clear
1606 * around it. Since picture are centered, only their size is tested.
1608 if( (p_buffer->i_pic_width > i_pic_width) || (p_buffer->i_pic_height > i_pic_height) )
1610 i_old_pic_y = p_buffer->i_pic_y;
1611 i_old_pic_height = p_buffer->i_pic_height;
1612 p_buffer->i_pic_x = i_pic_x;
1613 p_buffer->i_pic_y = i_pic_y;
1614 p_buffer->i_pic_width = i_pic_width;
1615 p_buffer->i_pic_height = i_pic_height;
1616 SetBufferArea( p_vout, 0, i_old_pic_y, p_vout->i_width, i_old_pic_height );
1620 p_buffer->i_pic_x = i_pic_x;
1621 p_buffer->i_pic_y = i_pic_y;
1622 p_buffer->i_pic_width = i_pic_width;
1623 p_buffer->i_pic_height = i_pic_height;
1629 for( i_area = 0; i_area < p_buffer->i_areas; i_area++ )
1632 intf_DbgMsg("clearing picture %p area in buffer %d: %d-%d", p_pic,
1633 p_vout->i_buffer_index, p_buffer->pi_area_begin[i_area], p_buffer->pi_area_end[i_area] );
1635 i_data_size = (p_buffer->pi_area_end[i_area] - p_buffer->pi_area_begin[i_area] + 1) * p_vout->i_bytes_per_line;
1636 p_data = (u64*) (p_buffer->p_data + p_vout->i_bytes_per_line * p_buffer->pi_area_begin[i_area]);
1637 for( i_data_index = i_data_size / 256; i_data_index-- ; )
1639 /* Clear 256 bytes block */
1640 *p_data++ = 0; *p_data++ = 0; *p_data++ = 0; *p_data++ = 0;
1641 *p_data++ = 0; *p_data++ = 0; *p_data++ = 0; *p_data++ = 0;
1642 *p_data++ = 0; *p_data++ = 0; *p_data++ = 0; *p_data++ = 0;
1643 *p_data++ = 0; *p_data++ = 0; *p_data++ = 0; *p_data++ = 0;
1644 *p_data++ = 0; *p_data++ = 0; *p_data++ = 0; *p_data++ = 0;
1645 *p_data++ = 0; *p_data++ = 0; *p_data++ = 0; *p_data++ = 0;
1646 *p_data++ = 0; *p_data++ = 0; *p_data++ = 0; *p_data++ = 0;
1647 *p_data++ = 0; *p_data++ = 0; *p_data++ = 0; *p_data++ = 0;
1649 for( i_data_index = (i_data_size % 256) / 16; i_data_index--; )
1651 /* Clear remaining 16 bytes blocks */
1652 *p_data++ = 0; *p_data++ = 0;
1654 p_data8 = (byte_t *)p_data;
1655 for( i_data_index = i_data_size % 16; i_data_index--; )
1657 /* Clear remaining bytes */
1665 p_buffer->i_areas = 0;
1668 /*****************************************************************************
1669 * RenderPicture: render a picture
1670 *****************************************************************************
1671 * This function converts a picture from a video heap to a pixel-encoded image
1672 * and copies it to the current rendering buffer. No lock is required, since
1673 * the * rendered picture has been determined as existant, and will only be
1674 * destroyed by the vout thread later.
1675 *****************************************************************************/
1676 static void RenderPicture( vout_thread_t *p_vout, picture_t *p_pic )
1679 char psz_date[MSTRTIME_MAX_SIZE]; /* picture date */
1680 mtime_t render_time; /* picture rendering time */
1682 vout_buffer_t * p_buffer; /* rendering buffer */
1683 byte_t * p_pic_data; /* convertion destination */
1685 /* Get and set rendering information */
1686 p_buffer = &p_vout->p_buffer[ p_vout->i_buffer_index ];
1687 p_pic_data = p_buffer->p_data +
1688 p_buffer->i_pic_x * p_vout->i_bytes_per_pixel +
1689 p_buffer->i_pic_y * p_vout->i_bytes_per_line;
1691 render_time = mdate();
1697 * Choose appropriate rendering function and render picture
1699 switch( p_pic->i_type )
1701 case YUV_420_PICTURE:
1702 p_vout->yuv.p_Convert420( p_vout, p_pic_data,
1703 p_pic->p_y, p_pic->p_u, p_pic->p_v,
1704 p_pic->i_width, p_pic->i_height,
1705 p_buffer->i_pic_width, p_buffer->i_pic_height,
1706 p_vout->i_bytes_per_line / p_vout->i_bytes_per_pixel,
1707 p_pic->i_matrix_coefficients );
1709 case YUV_422_PICTURE:
1710 p_vout->yuv.p_Convert422( p_vout, p_pic_data,
1711 p_pic->p_y, p_pic->p_u, p_pic->p_v,
1712 p_pic->i_width, p_pic->i_height,
1713 p_buffer->i_pic_width, p_buffer->i_pic_height,
1714 p_vout->i_bytes_per_line / p_vout->i_bytes_per_pixel,
1715 p_pic->i_matrix_coefficients );
1717 case YUV_444_PICTURE:
1718 p_vout->yuv.p_Convert444( p_vout, p_pic_data,
1719 p_pic->p_y, p_pic->p_u, p_pic->p_v,
1720 p_pic->i_width, p_pic->i_height,
1721 p_buffer->i_pic_width, p_buffer->i_pic_height,
1722 p_vout->i_bytes_per_line / p_vout->i_bytes_per_pixel,
1723 p_pic->i_matrix_coefficients );
1727 intf_DbgMsg("error: unknown picture type %d", p_pic->i_type );
1733 /* Print picture date and rendering time */
1734 intf_DbgMsg("picture %p rendered in buffer %d (%ld us), display date: %s", p_pic,
1735 p_vout->i_buffer_index, (long) (mdate() - render_time),
1736 mstrtime( psz_date, p_pic->date ));
1740 /*****************************************************************************
1741 * RenderPictureInfo: print additionnal information on a picture
1742 *****************************************************************************
1743 * This function will print information such as fps and other picture
1744 * dependant information.
1745 *****************************************************************************/
1746 static void RenderPictureInfo( vout_thread_t *p_vout, picture_t *p_pic )
1748 char psz_buffer[256]; /* string buffer */
1751 * Print FPS rate in upper right corner
1753 if( p_vout->c_fps_samples > VOUT_FPS_SAMPLES )
1755 long i_fps = VOUT_FPS_SAMPLES * 1000000 * 10 /
1756 ( p_vout->p_fps_sample[ (p_vout->c_fps_samples - 1)
1757 % VOUT_FPS_SAMPLES ] -
1758 p_vout->p_fps_sample[ p_vout->c_fps_samples
1759 % VOUT_FPS_SAMPLES ] );
1760 sprintf( psz_buffer, "%li.%i fps", i_fps / 10, (int)i_fps % 10 );
1761 Print( p_vout, 0, 0, RIGHT_RALIGN, TOP_RALIGN, psz_buffer );
1765 * Print frames count and loop time in upper left corner
1767 sprintf( psz_buffer, "%ld frames, render: %ldus",
1768 (long) p_vout->c_fps_samples, (long) p_vout->render_time );
1769 Print( p_vout, 0, 0, LEFT_RALIGN, TOP_RALIGN, psz_buffer );
1773 * Print picture information in lower right corner
1775 sprintf( psz_buffer, "%s picture %dx%d (%dx%d%+d%+d %s) -> %dx%d+%d+%d",
1776 (p_pic->i_type == YUV_420_PICTURE) ? "4:2:0" :
1777 ((p_pic->i_type == YUV_422_PICTURE) ? "4:2:2" :
1778 ((p_pic->i_type == YUV_444_PICTURE) ? "4:4:4" : "ukn-type")),
1779 p_pic->i_width, p_pic->i_height,
1780 p_pic->i_display_width, p_pic->i_display_height,
1781 p_pic->i_display_horizontal_offset, p_pic->i_display_vertical_offset,
1782 (p_pic->i_aspect_ratio == AR_SQUARE_PICTURE) ? "sq" :
1783 ((p_pic->i_aspect_ratio == AR_3_4_PICTURE) ? "4:3" :
1784 ((p_pic->i_aspect_ratio == AR_16_9_PICTURE) ? "16:9" :
1785 ((p_pic->i_aspect_ratio == AR_221_1_PICTURE) ? "2.21:1" : "ukn-ar" ))),
1786 p_vout->p_buffer[ p_vout->i_buffer_index ].i_pic_width,
1787 p_vout->p_buffer[ p_vout->i_buffer_index ].i_pic_height,
1788 p_vout->p_buffer[ p_vout->i_buffer_index ].i_pic_x,
1789 p_vout->p_buffer[ p_vout->i_buffer_index ].i_pic_y );
1790 Print( p_vout, 0, 0, RIGHT_RALIGN, BOTTOM_RALIGN, psz_buffer );
1794 /*****************************************************************************
1795 * RenderSplash: render splash picture
1796 *****************************************************************************
1797 * This function will print something on the screen. It will return 0 if
1798 * nothing has been rendered, or 1 if something has been changed on the screen.
1799 * Note that if you absolutely want something to be printed, you will have
1800 * to force it by setting the last idle date to 0.
1801 * Unlike other rendering functions, this one calls the SetBufferPicture
1802 * function when needed.
1803 *****************************************************************************/
1804 int RenderSplash( vout_thread_t *p_vout )
1806 int i_x = 0, i_y = 0; /* text position */
1807 int i_width, i_height; /* text size */
1808 char *psz_text = "VideoLAN Client (" VERSION ")"; /* text to display */
1810 memset( p_vout->p_buffer[ p_vout->i_buffer_index ].p_data,
1811 p_vout->i_bytes_per_line * p_vout->i_height, 12);
1813 // SetBufferPicture( p_vout, NULL );
1814 vout_TextSize( p_vout->p_large_font, WIDE_TEXT | OUTLINED_TEXT, psz_text,
1815 &i_width, &i_height );
1816 if( !Align( p_vout, &i_x, &i_y, i_width, i_height, CENTER_RALIGN, CENTER_RALIGN ) )
1818 vout_Print( p_vout->p_large_font,
1819 p_vout->p_buffer[ p_vout->i_buffer_index ].p_data +
1820 i_x * p_vout->i_bytes_per_pixel + (i_y - 16 ) * p_vout->i_bytes_per_line,
1821 p_vout->i_bytes_per_pixel, p_vout->i_bytes_per_line,
1822 p_vout->i_white_pixel, p_vout->i_gray_pixel, 0,
1823 WIDE_TEXT | OUTLINED_TEXT, psz_text, 100);
1824 SetBufferArea( p_vout, i_x, i_y, i_width, i_height);
1830 /*****************************************************************************
1831 * RenderIdle: render idle picture
1832 *****************************************************************************
1833 * This function will print something on the screen. It will return 0 if
1834 * nothing has been rendered, or 1 if something has been changed on the screen.
1835 * Note that if you absolutely want something to be printed, you will have
1836 * to force it by setting the last idle date to 0.
1837 * Unlike other rendering functions, this one calls the SetBufferPicture
1838 * function when needed.
1839 *****************************************************************************/
1840 int RenderIdle( vout_thread_t *p_vout )
1843 int i_x = 0, i_y = 0; /* text position */
1844 int i_width, i_height; /* text size */
1845 int i_amount = 0; /* amount to draw */
1846 char *psz_text = "Waiting for stream"; /* text to display */
1847 char *psz_wtext = "[................]";
1849 mtime_t current_date; /* current date */
1852 memset( p_vout->p_buffer[ p_vout->i_buffer_index ].p_data,
1853 p_vout->i_bytes_per_line * p_vout->i_height, 12);
1856 current_date = mdate();
1857 if( (current_date - p_vout->last_display_date) > VOUT_IDLE_DELAY
1858 // && (current_date - p_vout->last_idle_date) > VOUT_IDLE_DELAY
1861 /* FIXME: idle screen disabled */
1863 SetBufferPicture( p_vout, NULL );
1864 vout_TextSize( p_vout->p_large_font, WIDE_TEXT | OUTLINED_TEXT, psz_text,
1865 &i_width, &i_height );
1866 if( !Align( p_vout, &i_x, &i_y, i_width, i_height * 2, CENTER_RALIGN, CENTER_RALIGN ) )
1868 i_amount = (int) ((current_date - p_vout->last_display_date ) / 5000LL);
1869 vout_Print( p_vout->p_large_font,
1870 p_vout->p_buffer[ p_vout->i_buffer_index ].p_data +
1871 i_x * p_vout->i_bytes_per_pixel + i_y * p_vout->i_bytes_per_line,
1872 p_vout->i_bytes_per_pixel, p_vout->i_bytes_per_line,
1873 p_vout->i_white_pixel, p_vout->i_gray_pixel, 0,
1874 WIDE_TEXT | OUTLINED_TEXT, psz_text, (i_amount / 3 ) %110);
1876 vout_Print( p_vout->p_large_font,
1877 p_vout->p_buffer[ p_vout->i_buffer_index ].p_data +
1878 i_x * p_vout->i_bytes_per_pixel + (i_y + 16) * p_vout->i_bytes_per_line,
1879 p_vout->i_bytes_per_pixel, p_vout->i_bytes_per_line,
1880 p_vout->i_white_pixel, p_vout->i_gray_pixel, 0,
1881 WIDE_TEXT | OUTLINED_TEXT, psz_wtext, (i_amount/5)%110 );
1884 SetBufferArea( p_vout, i_x, i_y, i_width, i_height * 2 );
1892 /*****************************************************************************
1893 * RenderInfo: render additionnal information
1894 *****************************************************************************
1895 * This function renders information which do not depend on the current
1897 *****************************************************************************/
1898 static void RenderInfo( vout_thread_t *p_vout )
1901 char psz_buffer[256]; /* string buffer */
1902 int i_ready_pic = 0; /* ready pictures */
1903 int i_reserved_pic = 0; /* reserved pictures */
1904 int i_picture; /* picture index */
1909 * Print thread state in lower left corner
1911 for( i_picture = 0; i_picture < VOUT_MAX_PICTURES; i_picture++ )
1913 switch( p_vout->p_picture[i_picture].i_status )
1915 case RESERVED_PICTURE:
1916 case RESERVED_DATED_PICTURE:
1917 case RESERVED_DISP_PICTURE:
1925 sprintf( psz_buffer, "pic: %d (%d/%d)/%d",
1926 p_vout->i_pictures, i_reserved_pic, i_ready_pic, VOUT_MAX_PICTURES );
1927 Print( p_vout, 0, 0, LEFT_RALIGN, BOTTOM_RALIGN, psz_buffer );
1931 /*****************************************************************************
1932 * RenderSubPicture: render a subpicture
1933 *****************************************************************************
1934 * This function renders a sub picture unit.
1935 *****************************************************************************/
1936 static void RenderSubPicture( vout_thread_t *p_vout, subpicture_t *p_subpic )
1938 p_vout_font_t p_font; /* text font */
1939 int i_width, i_height; /* subpicture dimensions */
1941 while( p_subpic != NULL )
1943 switch( p_subpic->i_type )
1945 case DVD_SUBPICTURE: /* DVD subpicture unit */
1946 /* test if the picture really has to be displayed */
1947 if( mdate() < p_subpic->begin_date )
1949 /* not yet, see you later */
1952 if( mdate() > p_subpic->end_date )
1954 /* too late, destroying the subpic */
1955 vout_DestroySubPicture( p_vout, p_subpic );
1958 vout_RenderSPU( &p_vout->p_buffer[ p_vout->i_buffer_index ],
1959 p_subpic, p_vout->i_bytes_per_pixel,
1960 p_vout->i_bytes_per_line );
1962 case TEXT_SUBPICTURE: /* single line text */
1963 /* Select default font if not specified */
1964 p_font = p_subpic->type.text.p_font;
1965 if( p_font == NULL )
1967 p_font = p_vout->p_default_font;
1970 /* Compute text size (width and height fields are ignored)
1972 vout_TextSize( p_font, p_subpic->type.text.i_style,
1973 p_subpic->p_data, &i_width, &i_height );
1974 if( !Align( p_vout, &p_subpic->i_x, &p_subpic->i_y,
1975 i_width, i_height, p_subpic->i_horizontal_align,
1976 p_subpic->i_vertical_align ) )
1979 p_vout->p_buffer[ p_vout->i_buffer_index ].p_data +
1980 p_subpic->i_x * p_vout->i_bytes_per_pixel +
1981 p_subpic->i_y * p_vout->i_bytes_per_line,
1982 p_vout->i_bytes_per_pixel, p_vout->i_bytes_per_line,
1983 p_subpic->type.text.i_char_color,
1984 p_subpic->type.text.i_border_color,
1985 p_subpic->type.text.i_bg_color,
1986 p_subpic->type.text.i_style, p_subpic->p_data, 100 );
1987 SetBufferArea( p_vout, p_subpic->i_x, p_subpic->i_y,
1988 i_width, i_height );
1994 intf_DbgMsg( "error: unknown subpicture %p type %d",
1995 p_subpic, p_subpic->i_type );
1999 p_subpic = p_subpic->p_next;
2003 /*****************************************************************************
2004 * RenderInterface: render the interface
2005 *****************************************************************************
2006 * This function renders the interface, if any.
2007 *****************************************************************************/
2008 static void RenderInterface( vout_thread_t *p_vout )
2010 int i_height, i_text_height; /* total and text height */
2011 int i_width_1, i_width_2; /* text width */
2012 int i_byte; /* byte index */
2013 const char *psz_text_1 = "[1-9] Channel [i]nfo [c]olor [g/G]amma";
2014 const char *psz_text_2 = "[+/-] Volume [m]ute [s]caling [Q]uit";
2017 vout_TextSize( p_vout->p_large_font, OUTLINED_TEXT, psz_text_1, &i_width_1, &i_height );
2018 vout_TextSize( p_vout->p_large_font, OUTLINED_TEXT, psz_text_2, &i_width_2, &i_text_height );
2019 i_height += i_text_height;
2021 /* Render background */
2022 for( i_byte = (p_vout->i_height - i_height) * p_vout->i_bytes_per_line;
2023 i_byte < p_vout->i_height * p_vout->i_bytes_per_line;
2027 p_vout->p_buffer[ p_vout->i_buffer_index ].p_data[ i_byte ] = p_vout->i_blue_pixel;
2030 /* Render text, if not larger than screen */
2031 if( i_width_1 < p_vout->i_width )
2033 vout_Print( p_vout->p_large_font, p_vout->p_buffer[ p_vout->i_buffer_index ].p_data +
2034 (p_vout->i_height - i_height) * p_vout->i_bytes_per_line,
2035 p_vout->i_bytes_per_pixel, p_vout->i_bytes_per_line,
2036 p_vout->i_white_pixel, p_vout->i_black_pixel, 0,
2037 OUTLINED_TEXT, psz_text_1, 100 );
2039 if( i_width_2 < p_vout->i_width )
2041 vout_Print( p_vout->p_large_font, p_vout->p_buffer[ p_vout->i_buffer_index ].p_data +
2042 (p_vout->i_height - i_height + i_text_height) * p_vout->i_bytes_per_line,
2043 p_vout->i_bytes_per_pixel, p_vout->i_bytes_per_line,
2044 p_vout->i_white_pixel, p_vout->i_black_pixel, 0,
2045 OUTLINED_TEXT, psz_text_2, 100 );
2048 /* Activate modified area */
2049 SetBufferArea( p_vout, 0, p_vout->i_height - i_height, p_vout->i_width, i_height );
2052 /*****************************************************************************
2053 * Manage: manage thread
2054 *****************************************************************************
2055 * This function will handle changes in thread configuration.
2056 *****************************************************************************/
2057 static int Manage( vout_thread_t *p_vout )
2060 if( p_vout->i_changes )
2062 intf_DbgMsg("changes: 0x%x (no display: 0x%x)", p_vout->i_changes,
2063 0 /* p_vout->i_changes & VOUT_NODISPLAY_CHANGE */ );
2067 /* On gamma or grayscale change, rebuild tables */
2068 if( p_vout->i_changes & (VOUT_GAMMA_CHANGE | VOUT_GRAYSCALE_CHANGE |
2071 if( vout_ResetYUV( p_vout ) )
2073 intf_ErrMsg( "vout error: can't rebuild conversion tables" );
2078 /* Clear changes flags which does not need management or have been
2080 p_vout->i_changes &= ~(VOUT_GAMMA_CHANGE | VOUT_GRAYSCALE_CHANGE |
2081 VOUT_YUV_CHANGE | VOUT_INFO_CHANGE |
2082 VOUT_INTF_CHANGE | VOUT_SCALE_CHANGE |
2083 VOUT_CURSOR_CHANGE | VOUT_FULLSCREEN_CHANGE );
2085 /* Detect unauthorized changes */
2086 if( p_vout->i_changes )
2088 /* Some changes were not acknowledged by p_vout->pf_manage or this
2089 * function, it means they should not be authorized */
2090 intf_ErrMsg( "vout error: unauthorized changes in the vout thread" );
2097 /*****************************************************************************
2098 * Align: align a subpicture in the screen
2099 *****************************************************************************
2100 * This function is used for rendering text or subpictures. It returns non 0
2101 * it the final aera is not fully included in display area. Return coordinates
2103 *****************************************************************************/
2104 static int Align( vout_thread_t *p_vout, int *pi_x, int *pi_y,
2105 int i_width, int i_height, int i_h_align, int i_v_align )
2107 /* Align horizontally */
2111 *pi_x -= i_width / 2;
2114 *pi_x += (p_vout->i_width - i_width) / 2;
2120 *pi_x += p_vout->i_width - i_width;
2124 /* Align vertically */
2128 *pi_y -= i_height / 2;
2131 *pi_y += (p_vout->i_height - i_height) / 2;
2137 *pi_y += p_vout->i_height - i_height;
2139 case SUBTITLE_RALIGN:
2140 *pi_y += (p_vout->i_height + p_vout->p_buffer[ p_vout->i_buffer_index ].i_pic_y +
2141 p_vout->p_buffer[ p_vout->i_buffer_index ].i_pic_height - i_height) / 2;
2145 /* Return non 0 if clipping failed */
2146 return( (*pi_x < 0) || (*pi_y < 0) ||
2147 (*pi_x + i_width > p_vout->i_width) || (*pi_y + i_height > p_vout->i_height) );
2150 /*****************************************************************************
2151 * SetPalette: sets an 8 bpp palette
2152 *****************************************************************************
2153 * This function is just a prototype that does nothing. Architectures that
2154 * support palette allocation should override it.
2155 *****************************************************************************/
2156 static void SetPalette ( p_vout_thread_t p_vout, u16 *red,
2157 u16 *green, u16 *blue, u16 *transp )
2159 intf_ErrMsg( "vout error: method does not support palette changing" );