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
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>
46 #include "video_output.h"
47 #include "video_text.h"
48 #include "video_spu.h"
49 #include "video_yuv.h"
54 #include "vdec_idct.h"
55 #include "video_decoder.h"
57 /*****************************************************************************
59 *****************************************************************************/
60 static int BinaryLog ( u32 i );
61 static void MaskToShift ( int *pi_left, int *pi_right, u32 i_mask );
62 static int InitThread ( vout_thread_t *p_vout );
63 static void RunThread ( vout_thread_t *p_vout );
64 static void ErrorThread ( vout_thread_t *p_vout );
65 static void EndThread ( vout_thread_t *p_vout );
66 static void DestroyThread ( vout_thread_t *p_vout, int i_status );
67 static void Print ( vout_thread_t *p_vout, int i_x, int i_y,
68 int i_h_align, int i_v_align,
69 unsigned char *psz_text );
70 static void SetBufferArea ( vout_thread_t *p_vout, int i_x, int i_y,
72 static void SetBufferPicture ( vout_thread_t *p_vout, picture_t *p_pic );
73 static void RenderPicture ( vout_thread_t *p_vout, picture_t *p_pic );
74 static void RenderPictureInfo ( vout_thread_t *p_vout, picture_t *p_pic );
75 static void RenderSubPicture ( vout_thread_t *p_vout,
76 subpicture_t *p_subpic );
77 static void RenderInterface ( vout_thread_t *p_vout );
78 static int RenderIdle ( vout_thread_t *p_vout );
79 static int RenderSplash ( vout_thread_t *p_vout );
80 static void RenderInfo ( vout_thread_t *p_vout );
81 static int Manage ( vout_thread_t *p_vout );
82 static int Align ( vout_thread_t *p_vout, int *pi_x,
83 int *pi_y, int i_width, int i_height,
84 int i_h_align, int i_v_align );
85 static void SetPalette ( p_vout_thread_t p_vout, u16 *red,
86 u16 *green, u16 *blue, u16 *transp );
88 /*****************************************************************************
89 * vout_CreateThread: creates a new video output thread
90 *****************************************************************************
91 * This function creates a new video output thread, and returns a pointer
92 * to its description. On error, it returns NULL.
93 * If pi_status is NULL, then the function will block until the thread is ready.
94 * If not, it will be updated using one of the THREAD_* constants.
95 *****************************************************************************/
96 vout_thread_t * vout_CreateThread ( char *psz_display, int i_root_window,
97 int i_width, int i_height, int *pi_status,
98 int i_method, void *p_data )
100 vout_thread_t * p_vout; /* thread descriptor */
101 typedef void ( vout_getplugin_t ) ( vout_thread_t * p_vout );
102 int i_status; /* thread status */
103 int i_index; /* index for array initialization */
104 int i_best_index = 0, i_best_score = 0;
106 /* Allocate descriptor */
108 p_vout = (vout_thread_t *) malloc( sizeof(vout_thread_t) );
111 intf_ErrMsg( "vout error: %s\n", strerror(ENOMEM) );
115 p_vout->p_set_palette = SetPalette;
117 /* Get a suitable video plugin */
118 for( i_index = 0 ; i_index < p_main->p_bank->i_plugin_count ; i_index++ )
120 /* If there's a plugin in p_info ... */
121 if( p_main->p_bank->p_info[ i_index ] != NULL )
123 /* ... and if this plugin provides the functions we want ... */
124 if( p_main->p_bank->p_info[ i_index ]->vout_GetPlugin != NULL )
126 /* ... and if this plugin has a good score ... */
127 if( p_main->p_bank->p_info[ i_index ]->i_score > i_best_score )
129 /* ... then take it */
130 i_best_score = p_main->p_bank->p_info[ i_index ]->i_score;
131 i_best_index = i_index;
137 if( i_best_score == 0 )
143 /* Get the plugin functions */
144 ( (vout_getplugin_t *)
145 p_main->p_bank->p_info[ i_best_index ]->vout_GetPlugin )( p_vout );
147 /* Initialize thread properties - thread id and locks will be initialized
151 p_vout->b_active = 0;
152 p_vout->pi_status = (pi_status != NULL) ? pi_status : &i_status;
153 *p_vout->pi_status = THREAD_CREATE;
155 /* Initialize some fields used by the system-dependant method - these
156 * fields will probably be modified by the method, and are only
158 p_vout->i_changes = 0;
159 p_vout->i_width = i_width;
160 p_vout->i_height = i_height;
161 p_vout->i_bytes_per_line = i_width * 2;
162 p_vout->i_screen_depth = 15;
163 p_vout->i_bytes_per_pixel = 2;
164 p_vout->f_gamma = VOUT_GAMMA;
165 p_vout->b_need_render = 1;
167 p_vout->b_grayscale = main_GetIntVariable( VOUT_GRAYSCALE_VAR,
168 VOUT_GRAYSCALE_DEFAULT );
169 p_vout->vdec_DecodeMacroblock = vdec_DecodeMacroblockC;
171 p_vout->b_interface = 0;
174 intf_DbgMsg( "wished configuration: %dx%d, %d/%d bpp (%d Bpl)\n",
175 p_vout->i_width, p_vout->i_height, p_vout->i_screen_depth,
176 p_vout->i_bytes_per_pixel * 8, p_vout->i_bytes_per_line );
178 /* Initialize idle screen */
179 p_vout->last_display_date = 0;
180 p_vout->last_idle_date = 0;
181 p_vout->init_display_date = mdate();
182 p_vout->render_time = 10000;
184 /* Initialize statistics fields */
185 p_vout->c_fps_samples = 0;
187 /* Initialize buffer index */
188 p_vout->i_buffer_index = 0;
190 /* Initialize pictures and subpictures - translation tables and functions
191 * will be initialized later in InitThread */
192 for( i_index = 0; i_index < VOUT_MAX_PICTURES; i_index++)
194 p_vout->p_picture[i_index].i_type = EMPTY_PICTURE;
195 p_vout->p_picture[i_index].i_status = FREE_PICTURE;
197 for( i_index = 0; i_index < VOUT_MAX_SUBPICTURES; i_index++)
199 p_vout->p_subpicture[i_index].i_type = EMPTY_SUBPICTURE;
200 p_vout->p_subpicture[i_index].i_status= FREE_SUBPICTURE;
202 p_vout->i_pictures = 0;
204 /* Create and initialize system-dependant method - this function issues its
205 * own error messages */
206 if( p_vout->p_sys_create( p_vout, psz_display, i_root_window, p_data ) )
211 intf_DbgMsg( "actual configuration: %dx%d, %d/%d bpp (%d Bpl), "
212 "masks: 0x%x/0x%x/0x%x\n",
213 p_vout->i_width, p_vout->i_height, p_vout->i_screen_depth,
214 p_vout->i_bytes_per_pixel * 8, p_vout->i_bytes_per_line,
215 p_vout->i_red_mask, p_vout->i_green_mask,
216 p_vout->i_blue_mask );
218 /* Calculate shifts from system-updated masks */
219 MaskToShift( &p_vout->i_red_lshift, &p_vout->i_red_rshift,
220 p_vout->i_red_mask );
221 MaskToShift( &p_vout->i_green_lshift, &p_vout->i_green_rshift,
222 p_vout->i_green_mask );
223 MaskToShift( &p_vout->i_blue_lshift, &p_vout->i_blue_rshift,
224 p_vout->i_blue_mask );
226 /* Set some useful colors */
227 p_vout->i_white_pixel = RGB2PIXEL( p_vout, 255, 255, 255 );
228 p_vout->i_black_pixel = RGB2PIXEL( p_vout, 0, 0, 0 );
229 p_vout->i_gray_pixel = RGB2PIXEL( p_vout, 128, 128, 128 );
230 p_vout->i_blue_pixel = RGB2PIXEL( p_vout, 0, 0, 50 );
232 /* Load fonts - fonts must be initialized after the system method since
233 * they may be dependant on screen depth and other thread properties */
234 p_vout->p_default_font = vout_LoadFont( DATA_PATH "/" VOUT_DEFAULT_FONT );
235 if( p_vout->p_default_font == NULL )
237 p_vout->p_default_font = vout_LoadFont( "share/" VOUT_DEFAULT_FONT );
239 if( p_vout->p_default_font == NULL )
241 intf_ErrMsg( "vout error: could not load default font\n" );
242 p_vout->p_sys_destroy( p_vout );
246 p_vout->p_large_font = vout_LoadFont( DATA_PATH "/" VOUT_LARGE_FONT );
247 if( p_vout->p_large_font == NULL )
249 p_vout->p_large_font = vout_LoadFont( "share/" VOUT_LARGE_FONT );
251 if( p_vout->p_large_font == NULL )
253 intf_ErrMsg( "vout error: could not load large font\n" );
254 vout_UnloadFont( p_vout->p_default_font );
255 p_vout->p_sys_destroy( p_vout );
260 /* Create thread and set locks */
261 vlc_mutex_init( &p_vout->picture_lock );
262 vlc_mutex_init( &p_vout->subpicture_lock );
263 vlc_mutex_init( &p_vout->change_lock );
264 vlc_mutex_lock( &p_vout->change_lock );
265 if( vlc_thread_create( &p_vout->thread_id, "video output",
266 (void *) RunThread, (void *) p_vout) )
268 intf_ErrMsg("vout error: %s\n", strerror(ENOMEM));
269 vout_UnloadFont( p_vout->p_default_font );
270 vout_UnloadFont( p_vout->p_large_font );
271 p_vout->p_sys_destroy( p_vout );
276 intf_Msg( "Video display initialized (%dx%d, %d/%d bpp)\n", p_vout->i_width,
277 p_vout->i_height, p_vout->i_screen_depth,
278 p_vout->i_bytes_per_pixel * 8 );
280 /* If status is NULL, wait until the thread is created */
281 if( pi_status == NULL )
285 msleep( THREAD_SLEEP );
286 }while( (i_status != THREAD_READY) && (i_status != THREAD_ERROR)
287 && (i_status != THREAD_FATAL) );
288 if( i_status != THREAD_READY )
296 /*****************************************************************************
297 * vout_DestroyThread: destroys a previously created thread
298 *****************************************************************************
299 * Destroy a terminated thread.
300 * The function will request a destruction of the specified thread. If pi_error
301 * is NULL, it will return once the thread is destroyed. Else, it will be
302 * update using one of the THREAD_* constants.
303 *****************************************************************************/
304 void vout_DestroyThread( vout_thread_t *p_vout, int *pi_status )
306 int i_status; /* thread status */
310 p_vout->pi_status = (pi_status != NULL) ? pi_status : &i_status;
311 *p_vout->pi_status = THREAD_DESTROY;
313 /* Request thread destruction */
316 /* If status is NULL, wait until thread has been destroyed */
317 if( pi_status == NULL )
321 msleep( THREAD_SLEEP );
322 }while( (i_status != THREAD_OVER) && (i_status != THREAD_ERROR)
323 && (i_status != THREAD_FATAL) );
327 /*****************************************************************************
328 * vout_DisplaySubPicture: display a subpicture unit
329 *****************************************************************************
330 * Remove the reservation flag of an subpicture, which will cause it to be ready
331 * for display. The picture does not need to be locked, since it is ignored by
332 * the output thread if is reserved.
333 *****************************************************************************/
334 void vout_DisplaySubPicture( vout_thread_t *p_vout, subpicture_t *p_subpic )
337 char psz_begin_date[MSTRTIME_MAX_SIZE]; /* buffer for date string */
338 char psz_end_date[MSTRTIME_MAX_SIZE]; /* buffer for date string */
342 /* Check if status is valid */
343 if( p_subpic->i_status != RESERVED_SUBPICTURE )
345 intf_DbgMsg("error: subpicture %p has invalid status %d\n", p_subpic,
346 p_subpic->i_status );
350 /* Remove reservation flag */
351 p_subpic->i_status = READY_SUBPICTURE;
354 /* Send subpicture information */
355 intf_DbgMsg("subpicture %p: type=%d, begin date=%s, end date=%s\n",
356 p_subpic, p_subpic->i_type,
357 mstrtime( psz_begin_date, p_subpic->begin_date ),
358 mstrtime( psz_end_date, p_subpic->end_date ) );
362 /*****************************************************************************
363 * vout_CreateSubPicture: allocate a subpicture in the video output heap.
364 *****************************************************************************
365 * This function create a reserved subpicture in the video output heap.
366 * A null pointer is returned if the function fails. This method provides an
367 * already allocated zone of memory in the spu data fields. It needs locking
368 * since several pictures can be created by several producers threads.
369 *****************************************************************************/
370 subpicture_t *vout_CreateSubPicture( vout_thread_t *p_vout, int i_type,
373 int i_subpic; /* subpicture index */
374 subpicture_t * p_free_subpic = NULL; /* first free subpicture */
375 subpicture_t * p_destroyed_subpic = NULL; /* first destroyed subpic */
378 vlc_mutex_lock( &p_vout->subpicture_lock );
381 * Look for an empty place
383 for( i_subpic = 0; i_subpic < VOUT_MAX_SUBPICTURES; i_subpic++ )
385 if( p_vout->p_subpicture[i_subpic].i_status == DESTROYED_SUBPICTURE )
387 /* Subpicture is marked for destruction, but is still allocated */
388 if( (p_vout->p_subpicture[i_subpic].i_type == i_type) &&
389 (p_vout->p_subpicture[i_subpic].i_size >= i_size) )
391 /* Memory size do match or is smaller : memory will not be
392 * reallocated, and function can end immediately - this is
393 * the best possible case, since no memory allocation needs
395 p_vout->p_subpicture[i_subpic].i_status = RESERVED_SUBPICTURE;
397 intf_DbgMsg("subpicture %p (in destroyed subpicture slot)\n",
398 &p_vout->p_subpicture[i_subpic] );
400 vlc_mutex_unlock( &p_vout->subpicture_lock );
401 return( &p_vout->p_subpicture[i_subpic] );
403 else if( p_destroyed_subpic == NULL )
405 /* Memory size do not match, but subpicture index will be kept in
406 * case no other place are left */
407 p_destroyed_subpic = &p_vout->p_subpicture[i_subpic];
410 else if( (p_free_subpic == NULL) &&
411 (p_vout->p_subpicture[i_subpic].i_status == FREE_SUBPICTURE ))
413 /* Subpicture is empty and ready for allocation */
414 p_free_subpic = &p_vout->p_subpicture[i_subpic];
418 /* If no free subpictures are available, use a destroyed subpicture */
419 if( (p_free_subpic == NULL) && (p_destroyed_subpic != NULL ) )
421 /* No free subpicture or matching destroyed subpictures have been
422 * found, but a destroyed subpicture is still avalaible */
423 free( p_destroyed_subpic->p_data );
424 p_free_subpic = p_destroyed_subpic;
430 if( p_free_subpic != NULL )
432 /* Allocate memory */
435 case TEXT_SUBPICTURE: /* text subpicture */
436 p_free_subpic->p_data = malloc( i_size + 1 );
438 case DVD_SUBPICTURE: /* DVD subpicture unit */
439 p_free_subpic->p_data = malloc( i_size );
443 intf_DbgMsg("error: unknown subpicture type %d\n", i_type );
444 p_free_subpic->p_data = NULL;
449 if( p_free_subpic->p_data != NULL )
451 /* Copy subpicture information, set some default values */
452 p_free_subpic->i_type = i_type;
453 p_free_subpic->i_status = RESERVED_SUBPICTURE;
454 p_free_subpic->i_size = i_size;
455 p_free_subpic->i_x = 0;
456 p_free_subpic->i_y = 0;
457 p_free_subpic->i_width = 0;
458 p_free_subpic->i_height = 0;
459 p_free_subpic->i_horizontal_align = CENTER_RALIGN;
460 p_free_subpic->i_vertical_align = CENTER_RALIGN;
464 /* Memory allocation failed : set subpicture as empty */
465 p_free_subpic->i_type = EMPTY_SUBPICTURE;
466 p_free_subpic->i_status = FREE_SUBPICTURE;
467 p_free_subpic = NULL;
468 intf_ErrMsg("spu warning: %s\n", strerror( ENOMEM ) );
472 intf_DbgMsg("subpicture %p (in free subpicture slot)\n", p_free_subpic );
474 vlc_mutex_unlock( &p_vout->subpicture_lock );
475 return( p_free_subpic );
478 /* No free or destroyed subpicture could be found */
479 intf_DbgMsg( "warning: subpicture heap is full\n" );
480 vlc_mutex_unlock( &p_vout->subpicture_lock );
484 /*****************************************************************************
485 * vout_DestroySubPicture: remove a subpicture from the heap
486 *****************************************************************************
487 * This function frees a previously reserved subpicture.
488 * It is meant to be used when the construction of a picture aborted.
489 * This function does not need locking since reserved subpictures are ignored
490 * by the output thread.
491 *****************************************************************************/
492 void vout_DestroySubPicture( vout_thread_t *p_vout, subpicture_t *p_subpic )
495 /* Check if status is valid */
496 if( p_subpic->i_status != RESERVED_SUBPICTURE )
498 intf_DbgMsg("error: subpicture %p has invalid status %d\n",
499 p_subpic, p_subpic->i_status );
503 p_subpic->i_status = DESTROYED_SUBPICTURE;
506 intf_DbgMsg("subpicture %p\n", p_subpic);
510 /*****************************************************************************
511 * vout_DisplayPicture: display a picture
512 *****************************************************************************
513 * Remove the reservation flag of a picture, which will cause it to be ready for
514 * display. The picture won't be displayed until vout_DatePicture has been
516 *****************************************************************************/
517 void vout_DisplayPicture( vout_thread_t *p_vout, picture_t *p_pic )
519 vlc_mutex_lock( &p_vout->picture_lock );
520 switch( p_pic->i_status )
522 case RESERVED_PICTURE:
523 p_pic->i_status = RESERVED_DISP_PICTURE;
525 case RESERVED_DATED_PICTURE:
526 p_pic->i_status = READY_PICTURE;
530 intf_DbgMsg("error: picture %p has invalid status %d\n", p_pic, p_pic->i_status );
536 intf_DbgMsg("picture %p\n", p_pic);
538 vlc_mutex_unlock( &p_vout->picture_lock );
541 /*****************************************************************************
542 * vout_DatePicture: date a picture
543 *****************************************************************************
544 * Remove the reservation flag of a picture, which will cause it to be ready for
545 * display. The picture won't be displayed until vout_DisplayPicture has been
547 *****************************************************************************/
548 void vout_DatePicture( vout_thread_t *p_vout, picture_t *p_pic, mtime_t date )
551 char psz_date[MSTRTIME_MAX_SIZE]; /* date */
554 vlc_mutex_lock( &p_vout->picture_lock );
556 switch( p_pic->i_status )
558 case RESERVED_PICTURE:
559 p_pic->i_status = RESERVED_DATED_PICTURE;
561 case RESERVED_DISP_PICTURE:
562 p_pic->i_status = READY_PICTURE;
566 intf_DbgMsg("error: picture %p has invalid status %d\n", p_pic, p_pic->i_status );
572 intf_DbgMsg("picture %p, display date: %s\n", p_pic, mstrtime( psz_date, p_pic->date) );
574 vlc_mutex_unlock( &p_vout->picture_lock );
577 /*****************************************************************************
578 * vout_CreatePicture: allocate a picture in the video output heap.
579 *****************************************************************************
580 * This function create a reserved image in the video output heap.
581 * A null pointer is returned if the function fails. This method provides an
582 * already allocated zone of memory in the picture data fields. It needs locking
583 * since several pictures can be created by several producers threads.
584 *****************************************************************************/
585 picture_t *vout_CreatePicture( vout_thread_t *p_vout, int i_type,
586 int i_width, int i_height )
588 int i_picture; /* picture index */
589 int i_chroma_width = 0; /* chroma width */
590 picture_t * p_free_picture = NULL; /* first free picture */
591 picture_t * p_destroyed_picture = NULL; /* first destroyed picture */
594 vlc_mutex_lock( &p_vout->picture_lock );
597 * Look for an empty place
599 for( i_picture = 0; i_picture < VOUT_MAX_PICTURES; i_picture++ )
601 if( p_vout->p_picture[i_picture].i_status == DESTROYED_PICTURE )
603 /* Picture is marked for destruction, but is still allocated - note
604 * that if width and type are the same for two pictures, chroma_width
605 * should also be the same */
606 if( (p_vout->p_picture[i_picture].i_type == i_type) &&
607 (p_vout->p_picture[i_picture].i_height == i_height) &&
608 (p_vout->p_picture[i_picture].i_width == i_width) )
610 /* Memory size do match : memory will not be reallocated, and function
611 * can end immediately - this is the best possible case, since no
612 * memory allocation needs to be done */
613 p_vout->p_picture[i_picture].i_status = RESERVED_PICTURE;
614 p_vout->i_pictures++;
616 intf_DbgMsg("picture %p (in destroyed picture slot)\n",
617 &p_vout->p_picture[i_picture] );
619 vlc_mutex_unlock( &p_vout->picture_lock );
620 return( &p_vout->p_picture[i_picture] );
622 else if( p_destroyed_picture == NULL )
624 /* Memory size do not match, but picture index will be kept in
625 * case no other place are left */
626 p_destroyed_picture = &p_vout->p_picture[i_picture];
629 else if( (p_free_picture == NULL) &&
630 (p_vout->p_picture[i_picture].i_status == FREE_PICTURE ))
632 /* Picture is empty and ready for allocation */
633 p_free_picture = &p_vout->p_picture[i_picture];
637 /* If no free picture is available, use a destroyed picture */
638 if( (p_free_picture == NULL) && (p_destroyed_picture != NULL ) )
640 /* No free picture or matching destroyed picture has been found, but
641 * a destroyed picture is still avalaible */
642 free( p_destroyed_picture->p_data );
643 p_free_picture = p_destroyed_picture;
649 if( p_free_picture != NULL )
651 /* Allocate memory */
654 case YUV_420_PICTURE: /* YUV 420: 1,1/4,1/4 samples per pixel */
655 i_chroma_width = i_width / 2;
656 p_free_picture->p_data = malloc( i_height * i_chroma_width * 3 * sizeof( yuv_data_t ) );
657 p_free_picture->p_y = (yuv_data_t *)p_free_picture->p_data;
658 p_free_picture->p_u = (yuv_data_t *)p_free_picture->p_data +i_height*i_chroma_width*4/2;
659 p_free_picture->p_v = (yuv_data_t *)p_free_picture->p_data +i_height*i_chroma_width*5/2;
661 case YUV_422_PICTURE: /* YUV 422: 1,1/2,1/2 samples per pixel */
662 i_chroma_width = i_width / 2;
663 p_free_picture->p_data = malloc( i_height * i_chroma_width * 4 * sizeof( yuv_data_t ) );
664 p_free_picture->p_y = (yuv_data_t *)p_free_picture->p_data;
665 p_free_picture->p_u = (yuv_data_t *)p_free_picture->p_data +i_height*i_chroma_width*2;
666 p_free_picture->p_v = (yuv_data_t *)p_free_picture->p_data +i_height*i_chroma_width*3;
668 case YUV_444_PICTURE: /* YUV 444: 1,1,1 samples per pixel */
669 i_chroma_width = i_width;
670 p_free_picture->p_data = malloc( i_height * i_chroma_width * 3 * sizeof( yuv_data_t ) );
671 p_free_picture->p_y = (yuv_data_t *)p_free_picture->p_data;
672 p_free_picture->p_u = (yuv_data_t *)p_free_picture->p_data +i_height*i_chroma_width;
673 p_free_picture->p_v = (yuv_data_t *)p_free_picture->p_data +i_height*i_chroma_width*2;
677 intf_DbgMsg("error: unknown picture type %d\n", i_type );
678 p_free_picture->p_data = NULL;
683 if( p_free_picture->p_data != NULL )
685 /* Copy picture information, set some default values */
686 p_free_picture->i_type = i_type;
687 p_free_picture->i_status = RESERVED_PICTURE;
688 p_free_picture->i_matrix_coefficients = 1;
689 p_free_picture->i_width = i_width;
690 p_free_picture->i_height = i_height;
691 p_free_picture->i_chroma_width = i_chroma_width;
692 p_free_picture->i_display_horizontal_offset = 0;
693 p_free_picture->i_display_vertical_offset = 0;
694 p_free_picture->i_display_width = i_width;
695 p_free_picture->i_display_height = i_height;
696 p_free_picture->i_aspect_ratio = AR_SQUARE_PICTURE;
697 p_free_picture->i_refcount = 0;
698 p_vout->i_pictures++;
702 /* Memory allocation failed : set picture as empty */
703 p_free_picture->i_type = EMPTY_PICTURE;
704 p_free_picture->i_status = FREE_PICTURE;
705 p_free_picture = NULL;
706 intf_ErrMsg( "vout warning: %s\n", strerror( ENOMEM ) );
710 intf_DbgMsg("picture %p (in free picture slot)\n", p_free_picture );
712 vlc_mutex_unlock( &p_vout->picture_lock );
713 return( p_free_picture );
716 /* No free or destroyed picture could be found */
717 intf_DbgMsg( "warning: picture heap is full\n" );
718 vlc_mutex_unlock( &p_vout->picture_lock );
722 /*****************************************************************************
723 * vout_DestroyPicture: remove a permanent or reserved picture from the heap
724 *****************************************************************************
725 * This function frees a previously reserved picture or a permanent
726 * picture. It is meant to be used when the construction of a picture aborted.
727 * Note that the picture will be destroyed even if it is linked !
728 *****************************************************************************/
729 void vout_DestroyPicture( vout_thread_t *p_vout, picture_t *p_pic )
731 vlc_mutex_lock( &p_vout->picture_lock );
734 /* Check if picture status is valid */
735 if( (p_pic->i_status != RESERVED_PICTURE) &&
736 (p_pic->i_status != RESERVED_DATED_PICTURE) &&
737 (p_pic->i_status != RESERVED_DISP_PICTURE) )
739 intf_DbgMsg("error: picture %p has invalid status %d\n", p_pic, p_pic->i_status );
743 p_pic->i_status = DESTROYED_PICTURE;
744 p_vout->i_pictures--;
747 intf_DbgMsg("picture %p\n", p_pic);
749 vlc_mutex_unlock( &p_vout->picture_lock );
752 /*****************************************************************************
753 * vout_LinkPicture: increment reference counter of a picture
754 *****************************************************************************
755 * This function increment the reference counter of a picture in the video
756 * heap. It needs a lock since several producer threads can access the picture.
757 *****************************************************************************/
758 void vout_LinkPicture( vout_thread_t *p_vout, picture_t *p_pic )
760 vlc_mutex_lock( &p_vout->picture_lock );
764 intf_DbgMsg("picture %p refcount=%d\n", p_pic, p_pic->i_refcount );
767 vlc_mutex_unlock( &p_vout->picture_lock );
770 /*****************************************************************************
771 * vout_UnlinkPicture: decrement reference counter of a picture
772 *****************************************************************************
773 * This function decrement the reference counter of a picture in the video heap.
774 *****************************************************************************/
775 void vout_UnlinkPicture( vout_thread_t *p_vout, picture_t *p_pic )
777 vlc_mutex_lock( &p_vout->picture_lock );
781 if( p_pic->i_refcount < 0 )
783 intf_DbgMsg("error: refcount < 0\n");
784 p_pic->i_refcount = 0;
788 if( (p_pic->i_refcount == 0) && (p_pic->i_status == DISPLAYED_PICTURE) )
790 p_pic->i_status = DESTROYED_PICTURE;
791 p_vout->i_pictures--;
795 intf_DbgMsg("picture %p refcount=%d\n", p_pic, p_pic->i_refcount );
798 vlc_mutex_unlock( &p_vout->picture_lock );
801 /*****************************************************************************
802 * vout_SetBuffers: set buffers adresses
803 *****************************************************************************
804 * This function is called by system drivers to set buffers video memory
806 *****************************************************************************/
807 void vout_SetBuffers( vout_thread_t *p_vout, void *p_buf1, void *p_buf2 )
809 /* No picture previously */
810 p_vout->p_buffer[0].i_pic_x = 0;
811 p_vout->p_buffer[0].i_pic_y = 0;
812 p_vout->p_buffer[0].i_pic_width = 0;
813 p_vout->p_buffer[0].i_pic_height = 0;
814 p_vout->p_buffer[1].i_pic_x = 0;
815 p_vout->p_buffer[1].i_pic_y = 0;
816 p_vout->p_buffer[1].i_pic_width = 0;
817 p_vout->p_buffer[1].i_pic_height = 0;
819 /* The first area covers all the screen */
820 p_vout->p_buffer[0].i_areas = 1;
821 p_vout->p_buffer[0].pi_area_begin[0] = 0;
822 p_vout->p_buffer[0].pi_area_end[0] = p_vout->i_height - 1;
823 p_vout->p_buffer[1].i_areas = 1;
824 p_vout->p_buffer[1].pi_area_begin[0] = 0;
825 p_vout->p_buffer[1].pi_area_end[0] = p_vout->i_height - 1;
828 p_vout->p_buffer[0].p_data = p_buf1;
829 p_vout->p_buffer[1].p_data = p_buf2;
832 /*****************************************************************************
833 * vout_Pixel2RGB: return red, green and blue from pixel value
834 *****************************************************************************
835 * Return color values, in 0-255 range, of the decomposition of a pixel. This
836 * is a slow routine and should only be used for initialization phase.
837 *****************************************************************************/
838 void vout_Pixel2RGB( vout_thread_t *p_vout, u32 i_pixel, int *pi_red, int *pi_green, int *pi_blue )
840 *pi_red = i_pixel & p_vout->i_red_mask;
841 *pi_green = i_pixel & p_vout->i_green_mask;
842 *pi_blue = i_pixel & p_vout->i_blue_mask;
845 /* following functions are local */
847 /*****************************************************************************
848 * BinaryLog: computes the base 2 log of a binary value
849 *****************************************************************************
850 * This functions is used by MaskToShift, to get a bit index from a binary
852 *****************************************************************************/
853 static int BinaryLog(u32 i)
878 if (i != ((u32)1 << i_log))
880 intf_DbgMsg("internal error: binary log overflow\n");
886 /*****************************************************************************
887 * MaskToShift: transform a color mask into right and left shifts
888 *****************************************************************************
889 * This function is used for obtaining color shifts from masks.
890 *****************************************************************************/
891 static void MaskToShift( int *pi_left, int *pi_right, u32 i_mask )
893 u32 i_low, i_high; /* lower hand higher bits of the mask */
896 i_low = i_mask & (- i_mask); /* lower bit of the mask */
897 i_high = i_mask + i_low; /* higher bit of the mask */
899 /* Transform bits into an index */
900 i_low = BinaryLog (i_low);
901 i_high = BinaryLog (i_high);
903 /* Update pointers and return */
905 *pi_right = (8 - i_high + i_low);
908 /*****************************************************************************
909 * InitThread: initialize video output thread
910 *****************************************************************************
911 * This function is called from RunThread and performs the second step of the
912 * initialization. It returns 0 on success. Note that the thread's flag are not
913 * modified inside this function.
914 *****************************************************************************/
915 static int InitThread( vout_thread_t *p_vout )
919 *p_vout->pi_status = THREAD_START;
925 /* Initialize output method - this function issues its own error messages */
926 if( p_vout->p_sys_init( p_vout ) )
931 if( p_vout->b_need_render )
933 /* Initialize convertion tables and functions */
934 if( vout_InitYUV( p_vout ) )
936 intf_ErrMsg("error: can't allocate YUV translation tables\n");
941 /* Mark thread as running and return */
942 p_vout->b_active = 1;
943 *p_vout->pi_status = THREAD_READY;
946 intf_DbgMsg("thread ready\n");
950 /*****************************************************************************
951 * RunThread: video output thread
952 *****************************************************************************
953 * Video output thread. This function does only returns when the thread is
954 * terminated. It handles the pictures arriving in the video heap and the
955 * display device events.
956 *****************************************************************************/
957 static void RunThread( vout_thread_t *p_vout)
959 int i_index; /* index in heap */
960 mtime_t current_date; /* current date */
961 mtime_t display_date; /* display date */
962 boolean_t b_display; /* display flag */
963 picture_t * p_pic; /* picture pointer */
964 subpicture_t * p_subpic; /* subpicture pointer */
969 p_vout->b_error = InitThread( p_vout );
970 if( p_vout->b_error )
972 DestroyThread( p_vout, THREAD_ERROR );
978 * Main loop - it is not executed if an error occured during
981 while( (!p_vout->b_die) && (!p_vout->b_error) )
983 /* Initialize loop variables */
987 current_date = mdate();
990 if( !(p_vout->c_loops % VOUT_STATS_NB_LOOPS) )
992 intf_Msg("vout stats: picture heap: %d/%d\n",
993 p_vout->i_pictures, VOUT_MAX_PICTURES);
998 * Find the picture to display - this operation does not need lock,
999 * since only READY_PICTUREs are handled
1001 for( i_index = 0; i_index < VOUT_MAX_PICTURES; i_index++ )
1003 if( (p_vout->p_picture[i_index].i_status == READY_PICTURE) &&
1004 ( (p_pic == NULL) ||
1005 (p_vout->p_picture[i_index].date < display_date) ) )
1007 p_pic = &p_vout->p_picture[i_index];
1008 display_date = p_pic->date;
1014 /* Computes FPS rate */
1015 p_vout->p_fps_sample[ p_vout->c_fps_samples++ % VOUT_FPS_SAMPLES ] = display_date;
1017 if( display_date < current_date - p_vout->render_time )
1019 /* Picture is late: it will be destroyed and the thread
1020 * will sleep and go to next picture */
1022 vlc_mutex_lock( &p_vout->picture_lock );
1023 if( p_pic->i_refcount )
1025 p_pic->i_status = DISPLAYED_PICTURE;
1029 p_pic->i_status = DESTROYED_PICTURE;
1030 p_vout->i_pictures--;
1033 "warning: late picture skipped (%p)\n", p_pic );
1034 vlc_mutex_unlock( &p_vout->picture_lock );
1038 else if( display_date > current_date + VOUT_DISPLAY_DELAY )
1040 /* A picture is ready to be rendered, but its rendering date
1041 * is far from the current one so the thread will perform an
1042 * empty loop as if no picture were found. The picture state
1049 * Find the subpictures to display - this operation does not need
1050 * lock, since only READY_SUBPICTURE are handled. If no picture
1051 * has been selected, display_date will depend on the subpicture.
1052 * We get an easily parsable chained list of subpictures which
1053 * ends with NULL since p_subpic was initialized to NULL.
1055 for( i_index = 0; i_index < VOUT_MAX_SUBPICTURES; i_index++ )
1057 if( p_vout->p_subpicture[i_index].i_status == READY_SUBPICTURE )
1059 p_vout->p_subpicture[i_index].p_next = p_subpic;
1060 p_subpic = &p_vout->p_subpicture[i_index];
1065 * Perform rendering, sleep and display rendered picture
1067 if( p_pic ) /* picture and perhaps subpicture */
1069 b_display = p_vout->b_active;
1070 p_vout->last_display_date = display_date;
1071 p_vout->p_rendered_pic = p_pic;
1076 /* FIXME: if b_need_render == 0 we need to do something with
1077 * the subpictures one day. */
1078 if( p_vout->b_need_render && b_display )
1080 /* Set picture dimensions and clear buffer */
1081 SetBufferPicture( p_vout, p_pic );
1083 /* Render picture and information */
1084 RenderPicture( p_vout, p_pic );
1085 if( p_vout->b_info )
1087 RenderPictureInfo( p_vout, p_pic );
1088 RenderInfo( p_vout );
1092 RenderSubPicture( p_vout, p_subpic );
1096 /* Render interface and subpicture */
1097 if( b_display && p_vout->b_interface && p_vout->b_need_render )
1099 RenderInterface( p_vout );
1103 else if( p_vout->b_active && p_vout->b_need_render
1104 && p_vout->init_display_date == 0)
1106 /* Idle or interface screen alone */
1108 if( p_vout->b_interface && 0 /* && XXX?? intf_change */ )
1110 /* Interface has changed, so a new rendering is required - force
1111 * it by setting last idle date to 0 */
1112 p_vout->last_idle_date = 0;
1115 /* Render idle screen and update idle date, then render interface if
1117 b_display = RenderIdle( p_vout );
1120 p_vout->last_idle_date = current_date;
1121 if( p_vout->b_interface )
1123 RenderInterface( p_vout );
1135 * Check for the current time and
1136 * display splash screen if everything is on time
1138 if( p_vout->init_display_date > 0 && p_vout->b_need_render )
1140 if( p_vout->b_active &&
1141 mdate()-p_vout->init_display_date < 5000000)
1143 /* there is something to display ! */
1145 RenderSplash( p_vout );
1148 /* no splash screen ! */
1149 intf_ErrMsgImm("End of splash screen\n");
1150 p_vout->init_display_date=0;
1156 * Sleep, wake up and display rendered picture
1159 if( display_date != 0 )
1161 /* Store render time using Bresenham algorithm */
1162 p_vout->render_time += mdate() - current_date;
1163 p_vout->render_time >>= 1;
1166 /* Give back change lock */
1167 vlc_mutex_unlock( &p_vout->change_lock );
1169 /* Sleep a while or until a given date */
1170 if( display_date != 0 )
1172 mwait( display_date - VOUT_MWAIT_TOLERANCE );
1176 msleep( VOUT_IDLE_SLEEP );
1179 /* On awakening, take back lock and send immediately picture to display,
1180 * then swap buffers */
1181 vlc_mutex_lock( &p_vout->change_lock );
1183 intf_DbgMsg( "picture %p, subpicture %p in buffer %d, display=%d\n", p_pic, p_subpic,
1184 p_vout->i_buffer_index, b_display /* && !(p_vout->i_changes & VOUT_NODISPLAY_CHANGE) */ );
1186 if( b_display /* && !(p_vout->i_changes & VOUT_NODISPLAY_CHANGE) */ )
1188 p_vout->p_sys_display( p_vout );
1190 p_vout->i_buffer_index = ++p_vout->i_buffer_index & 1;
1196 /* Remove picture from heap */
1197 vlc_mutex_lock( &p_vout->picture_lock );
1198 if( p_pic->i_refcount )
1200 p_pic->i_status = DISPLAYED_PICTURE;
1204 p_pic->i_status = DESTROYED_PICTURE;
1205 p_vout->i_pictures--;
1207 vlc_mutex_unlock( &p_vout->picture_lock );
1212 * Check events and manage thread
1214 if( p_vout->p_sys_manage( p_vout ) | Manage( p_vout ) )
1216 /* A fatal error occured, and the thread must terminate immediately,
1217 * without displaying anything - setting b_error to 1 cause the
1218 * immediate end of the main while() loop. */
1219 p_vout->b_error = 1;
1224 * Error loop - wait until the thread destruction is requested
1226 if( p_vout->b_error )
1228 ErrorThread( p_vout );
1232 EndThread( p_vout );
1233 DestroyThread( p_vout, THREAD_OVER );
1234 intf_DbgMsg( "thread end\n" );
1237 /*****************************************************************************
1238 * ErrorThread: RunThread() error loop
1239 *****************************************************************************
1240 * This function is called when an error occured during thread main's loop. The
1241 * thread can still receive feed, but must be ready to terminate as soon as
1243 *****************************************************************************/
1244 static void ErrorThread( vout_thread_t *p_vout )
1246 /* Wait until a `die' order */
1248 while( !p_vout->b_die )
1251 msleep( VOUT_IDLE_SLEEP );
1255 /*****************************************************************************
1256 * EndThread: thread destruction
1257 *****************************************************************************
1258 * This function is called when the thread ends after a sucessful
1259 * initialization. It frees all ressources allocated by InitThread.
1260 *****************************************************************************/
1261 static void EndThread( vout_thread_t *p_vout )
1263 int i_index; /* index in heap */
1267 *p_vout->pi_status = THREAD_END;
1271 struct tms cpu_usage;
1272 times( &cpu_usage );
1274 intf_Msg("vout stats: cpu usage (user: %d, system: %d)\n",
1275 cpu_usage.tms_utime, cpu_usage.tms_stime);
1279 /* Destroy all remaining pictures and subpictures */
1280 for( i_index = 0; i_index < VOUT_MAX_PICTURES; i_index++ )
1282 if( p_vout->p_picture[i_index].i_status != FREE_PICTURE )
1284 free( p_vout->p_picture[i_index].p_data );
1287 for( i_index = 0; i_index < VOUT_MAX_SUBPICTURES; i_index++ )
1289 if( p_vout->p_subpicture[i_index].i_status != FREE_SUBPICTURE )
1291 free( p_vout->p_subpicture[i_index].p_data );
1295 /* Destroy translation tables */
1296 vout_EndYUV( p_vout );
1297 p_vout->p_sys_end( p_vout );
1300 /*****************************************************************************
1301 * DestroyThread: thread destruction
1302 *****************************************************************************
1303 * This function is called when the thread ends. It frees all ressources
1304 * allocated by CreateThread. Status is available at this stage.
1305 *****************************************************************************/
1306 static void DestroyThread( vout_thread_t *p_vout, int i_status )
1308 int *pi_status; /* status adress */
1310 /* Store status adress */
1312 pi_status = p_vout->pi_status;
1314 /* Destroy thread structures allocated by Create and InitThread */
1315 vout_UnloadFont( p_vout->p_default_font );
1316 vout_UnloadFont( p_vout->p_large_font );
1317 p_vout->p_sys_destroy( p_vout );
1319 /* Free structure */
1321 *pi_status = i_status;
1324 /*****************************************************************************
1325 * Print: print simple text on a picture
1326 *****************************************************************************
1327 * This function will print a simple text on the picture. It is designed to
1328 * print debugging or general information.
1329 *****************************************************************************/
1330 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 )
1332 int i_text_height; /* total text height */
1333 int i_text_width; /* total text width */
1335 /* Update upper left coordinates according to alignment */
1336 vout_TextSize( p_vout->p_default_font, 0, psz_text, &i_text_width, &i_text_height );
1337 if( !Align( p_vout, &i_x, &i_y, i_text_width, i_text_height, i_h_align, i_v_align ) )
1339 /* Set area and print text */
1340 SetBufferArea( p_vout, i_x, i_y, i_text_width, i_text_height );
1341 vout_Print( p_vout->p_default_font, p_vout->p_buffer[ p_vout->i_buffer_index ].p_data +
1342 i_y * p_vout->i_bytes_per_line + i_x * p_vout->i_bytes_per_pixel,
1343 p_vout->i_bytes_per_pixel, p_vout->i_bytes_per_line,
1344 p_vout->i_white_pixel, 0, 0,
1349 /*****************************************************************************
1350 * SetBufferArea: activate an area in current buffer
1351 *****************************************************************************
1352 * This function is called when something is rendered on the current buffer.
1353 * It set the area as active and prepare it to be cleared on next rendering.
1354 * Pay attention to the fact that in this functions, i_h is in fact the end y
1355 * coordinate of the new area.
1356 *****************************************************************************/
1357 static void SetBufferArea( vout_thread_t *p_vout, int i_x, int i_y, int i_w, int i_h )
1359 vout_buffer_t * p_buffer; /* current buffer */
1360 int i_area_begin, i_area_end; /* area vertical extension */
1361 int i_area, i_area_copy; /* area index */
1362 int i_area_shift; /* shift distance for areas */
1364 /* Choose buffer and modify h to end of area position */
1365 p_buffer = &p_vout->p_buffer[ p_vout->i_buffer_index ];
1369 * Remove part of the area which is inside the picture - this is done
1370 * by calling again SetBufferArea with the correct areas dimensions.
1372 if( (i_x >= p_buffer->i_pic_x) && (i_x + i_w <= p_buffer->i_pic_x + p_buffer->i_pic_width) )
1374 i_area_begin = p_buffer->i_pic_y;
1375 i_area_end = i_area_begin + p_buffer->i_pic_height - 1;
1377 if( ((i_y >= i_area_begin) && (i_y <= i_area_end)) ||
1378 ((i_h >= i_area_begin) && (i_h <= i_area_end)) ||
1379 ((i_y < i_area_begin) && (i_h > i_area_end)) )
1381 /* Keep the stripe above the picture, if any */
1382 if( i_y < i_area_begin )
1384 SetBufferArea( p_vout, i_x, i_y, i_w, i_area_begin - i_y );
1386 /* Keep the stripe below the picture, if any */
1387 if( i_h > i_area_end )
1389 SetBufferArea( p_vout, i_x, i_area_end, i_w, i_h - i_area_end );
1395 /* Skip some extensions until interesting areas */
1397 (i_area < p_buffer->i_areas) &&
1398 (p_buffer->pi_area_end[i_area] + 1 <= i_y);
1404 if( i_area == p_buffer->i_areas )
1406 /* New area is below all existing ones: just add it at the end of the
1407 * array, if possible - otherwise, append it to the last one */
1408 if( i_area < VOUT_MAX_AREAS )
1410 p_buffer->pi_area_begin[i_area] = i_y;
1411 p_buffer->pi_area_end[i_area] = i_h;
1412 p_buffer->i_areas++;
1417 intf_DbgMsg("area overflow\n");
1419 p_buffer->pi_area_end[VOUT_MAX_AREAS - 1] = i_h;
1424 i_area_begin = p_buffer->pi_area_begin[i_area];
1425 i_area_end = p_buffer->pi_area_end[i_area];
1427 if( i_y < i_area_begin )
1429 if( i_h >= i_area_begin - 1 )
1431 /* Extend area above */
1432 p_buffer->pi_area_begin[i_area] = i_y;
1436 /* Create a new area above : merge last area if overflow, then
1437 * move all old areas down */
1438 if( p_buffer->i_areas == VOUT_MAX_AREAS )
1441 intf_DbgMsg("areas overflow\n");
1443 p_buffer->pi_area_end[VOUT_MAX_AREAS - 2] = p_buffer->pi_area_end[VOUT_MAX_AREAS - 1];
1447 p_buffer->i_areas++;
1449 for( i_area_copy = p_buffer->i_areas - 1; i_area_copy > i_area; i_area_copy-- )
1451 p_buffer->pi_area_begin[i_area_copy] = p_buffer->pi_area_begin[i_area_copy - 1];
1452 p_buffer->pi_area_end[i_area_copy] = p_buffer->pi_area_end[i_area_copy - 1];
1454 p_buffer->pi_area_begin[i_area] = i_y;
1455 p_buffer->pi_area_end[i_area] = i_h;
1459 if( i_h > i_area_end )
1461 /* Find further areas which can be merged with the new one */
1462 for( i_area_copy = i_area + 1;
1463 (i_area_copy < p_buffer->i_areas) &&
1464 (p_buffer->pi_area_begin[i_area] <= i_h);
1471 if( i_area_copy != i_area )
1473 /* Merge with last possible areas */
1474 p_buffer->pi_area_end[i_area] = MAX( i_h, p_buffer->pi_area_end[i_area_copy] );
1476 /* Shift lower areas upward */
1477 i_area_shift = i_area_copy - i_area;
1478 p_buffer->i_areas -= i_area_shift;
1479 for( i_area_copy = i_area + 1; i_area_copy < p_buffer->i_areas; i_area_copy++ )
1481 p_buffer->pi_area_begin[i_area_copy] = p_buffer->pi_area_begin[i_area_copy + i_area_shift];
1482 p_buffer->pi_area_end[i_area_copy] = p_buffer->pi_area_end[i_area_copy + i_area_shift];
1487 /* Extend area below */
1488 p_buffer->pi_area_end[i_area] = i_h;
1494 /*****************************************************************************
1495 * SetBufferPicture: clear buffer and set picture area
1496 *****************************************************************************
1497 * This function is called before any rendering. It clears the current
1498 * rendering buffer and set the new picture area. If the picture pointer is
1499 * NULL, then no picture area is defined. Floating operations are avoided since
1500 * some MMX calculations may follow.
1501 *****************************************************************************/
1502 static void SetBufferPicture( vout_thread_t *p_vout, picture_t *p_pic )
1504 vout_buffer_t * p_buffer; /* current buffer */
1505 int i_pic_x, i_pic_y; /* picture position */
1506 int i_pic_width, i_pic_height; /* picture dimensions */
1507 int i_old_pic_y, i_old_pic_height; /* old picture area */
1508 int i_vout_width, i_vout_height; /* display dimensions */
1509 int i_area; /* area index */
1510 int i_data_index; /* area data index */
1511 int i_data_size; /* area data size, in 256 bytes blocs */
1512 u64 * p_data; /* area data, for clearing */
1513 byte_t * p_data8; /* area data, for clearing (slow) */
1515 /* Choose buffer and set display dimensions */
1516 p_buffer = &p_vout->p_buffer[ p_vout->i_buffer_index ];
1517 i_vout_width = p_vout->i_width;
1518 i_vout_height = p_vout->i_height;
1521 * Computes new picture size
1525 /* Try horizontal scaling first - width must be a mutiple of 16 */
1526 i_pic_width = (( p_vout->b_scale || (p_pic->i_width > i_vout_width)) ?
1527 i_vout_width : p_pic->i_width) & ~0xf;
1528 switch( p_pic->i_aspect_ratio )
1530 case AR_3_4_PICTURE:
1531 i_pic_height = i_pic_width * 3 / 4;
1533 case AR_16_9_PICTURE:
1534 i_pic_height = i_pic_width * 9 / 16;
1536 case AR_221_1_PICTURE:
1537 i_pic_height = i_pic_width * 100 / 221;
1539 case AR_SQUARE_PICTURE:
1541 i_pic_height = p_pic->i_height * i_pic_width / p_pic->i_width;
1545 /* If picture dimensions using horizontal scaling are too large, use
1546 * vertical scaling. Since width must be a multiple of 16, height is
1547 * adjusted again after. */
1548 if( i_pic_height > i_vout_height )
1550 i_pic_height = ( p_vout->b_scale || (p_pic->i_height > i_vout_height)) ?
1551 i_vout_height : p_pic->i_height;
1552 switch( p_pic->i_aspect_ratio )
1554 case AR_3_4_PICTURE:
1555 i_pic_width = (i_pic_height * 4 / 3) & ~0xf;
1556 i_pic_height = i_pic_width * 3 / 4;
1558 case AR_16_9_PICTURE:
1559 i_pic_width = (i_pic_height * 16 / 9) & ~0xf;
1560 i_pic_height = i_pic_width * 9 / 16;
1562 case AR_221_1_PICTURE:
1563 i_pic_width = (i_pic_height * 221 / 100) & ~0xf;
1564 i_pic_height = i_pic_width * 100 / 221;
1566 case AR_SQUARE_PICTURE:
1568 i_pic_width = (p_pic->i_width * i_pic_height / p_pic->i_height) & ~0xf;
1569 i_pic_height = p_pic->i_height * i_pic_width / p_pic->i_width;
1574 /* Set picture position */
1575 i_pic_x = (p_vout->i_width - i_pic_width) / 2;
1576 i_pic_y = (p_vout->i_height - i_pic_height) / 2;
1581 /* No picture: size is 0 */
1589 * Set new picture size - if it is smaller than the previous one, clear
1590 * around it. Since picture are centered, only their size is tested.
1592 if( (p_buffer->i_pic_width > i_pic_width) || (p_buffer->i_pic_height > i_pic_height) )
1594 i_old_pic_y = p_buffer->i_pic_y;
1595 i_old_pic_height = p_buffer->i_pic_height;
1596 p_buffer->i_pic_x = i_pic_x;
1597 p_buffer->i_pic_y = i_pic_y;
1598 p_buffer->i_pic_width = i_pic_width;
1599 p_buffer->i_pic_height = i_pic_height;
1600 SetBufferArea( p_vout, 0, i_old_pic_y, p_vout->i_width, i_old_pic_height );
1604 p_buffer->i_pic_x = i_pic_x;
1605 p_buffer->i_pic_y = i_pic_y;
1606 p_buffer->i_pic_width = i_pic_width;
1607 p_buffer->i_pic_height = i_pic_height;
1613 for( i_area = 0; i_area < p_buffer->i_areas; i_area++ )
1616 intf_DbgMsg("clearing picture %p area in buffer %d: %d-%d\n", p_pic,
1617 p_vout->i_buffer_index, p_buffer->pi_area_begin[i_area], p_buffer->pi_area_end[i_area] );
1619 i_data_size = (p_buffer->pi_area_end[i_area] - p_buffer->pi_area_begin[i_area] + 1) * p_vout->i_bytes_per_line;
1620 p_data = (u64*) (p_buffer->p_data + p_vout->i_bytes_per_line * p_buffer->pi_area_begin[i_area]);
1621 for( i_data_index = i_data_size / 256; i_data_index-- ; )
1623 /* Clear 256 bytes block */
1624 *p_data++ = 0; *p_data++ = 0; *p_data++ = 0; *p_data++ = 0;
1625 *p_data++ = 0; *p_data++ = 0; *p_data++ = 0; *p_data++ = 0;
1626 *p_data++ = 0; *p_data++ = 0; *p_data++ = 0; *p_data++ = 0;
1627 *p_data++ = 0; *p_data++ = 0; *p_data++ = 0; *p_data++ = 0;
1628 *p_data++ = 0; *p_data++ = 0; *p_data++ = 0; *p_data++ = 0;
1629 *p_data++ = 0; *p_data++ = 0; *p_data++ = 0; *p_data++ = 0;
1630 *p_data++ = 0; *p_data++ = 0; *p_data++ = 0; *p_data++ = 0;
1631 *p_data++ = 0; *p_data++ = 0; *p_data++ = 0; *p_data++ = 0;
1633 for( i_data_index = (i_data_size % 256) / 16; i_data_index--; )
1635 /* Clear remaining 16 bytes blocks */
1636 *p_data++ = 0; *p_data++ = 0;
1638 p_data8 = (byte_t *)p_data;
1639 for( i_data_index = i_data_size % 16; i_data_index--; )
1641 /* Clear remaining bytes */
1649 p_buffer->i_areas = 0;
1652 /*****************************************************************************
1653 * RenderPicture: render a picture
1654 *****************************************************************************
1655 * This function converts a picture from a video heap to a pixel-encoded image
1656 * and copies it to the current rendering buffer. No lock is required, since
1657 * the * rendered picture has been determined as existant, and will only be
1658 * destroyed by the vout thread later.
1659 *****************************************************************************/
1660 static void RenderPicture( vout_thread_t *p_vout, picture_t *p_pic )
1663 char psz_date[MSTRTIME_MAX_SIZE]; /* picture date */
1664 mtime_t render_time; /* picture rendering time */
1666 vout_buffer_t * p_buffer; /* rendering buffer */
1667 byte_t * p_pic_data; /* convertion destination */
1669 /* Get and set rendering information */
1670 p_buffer = &p_vout->p_buffer[ p_vout->i_buffer_index ];
1671 p_pic_data = p_buffer->p_data +
1672 p_buffer->i_pic_x * p_vout->i_bytes_per_pixel +
1673 p_buffer->i_pic_y * p_vout->i_bytes_per_line;
1675 render_time = mdate();
1681 * Choose appropriate rendering function and render picture
1683 switch( p_pic->i_type )
1685 case YUV_420_PICTURE:
1686 p_vout->yuv.p_Convert420( p_vout, p_pic_data,
1687 p_pic->p_y, p_pic->p_u, p_pic->p_v,
1688 p_pic->i_width, p_pic->i_height,
1689 p_buffer->i_pic_width, p_buffer->i_pic_height,
1690 p_vout->i_bytes_per_line / p_vout->i_bytes_per_pixel,
1691 p_pic->i_matrix_coefficients );
1693 case YUV_422_PICTURE:
1694 p_vout->yuv.p_Convert422( p_vout, p_pic_data,
1695 p_pic->p_y, p_pic->p_u, p_pic->p_v,
1696 p_pic->i_width, p_pic->i_height,
1697 p_buffer->i_pic_width, p_buffer->i_pic_height,
1698 p_vout->i_bytes_per_line / p_vout->i_bytes_per_pixel,
1699 p_pic->i_matrix_coefficients );
1701 case YUV_444_PICTURE:
1702 p_vout->yuv.p_Convert444( 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 );
1711 intf_DbgMsg("error: unknown picture type %d\n", p_pic->i_type );
1717 /* Print picture date and rendering time */
1718 intf_DbgMsg("picture %p rendered in buffer %d (%ld us), display date: %s\n", p_pic,
1719 p_vout->i_buffer_index, (long) (mdate() - render_time),
1720 mstrtime( psz_date, p_pic->date ));
1724 /*****************************************************************************
1725 * RenderPictureInfo: print additionnal information on a picture
1726 *****************************************************************************
1727 * This function will print information such as fps and other picture
1728 * dependant information.
1729 *****************************************************************************/
1730 static void RenderPictureInfo( vout_thread_t *p_vout, picture_t *p_pic )
1732 char psz_buffer[256]; /* string buffer */
1735 * Print FPS rate in upper right corner
1737 if( p_vout->c_fps_samples > VOUT_FPS_SAMPLES )
1739 long i_fps = VOUT_FPS_SAMPLES * 1000000 * 10 /
1740 ( p_vout->p_fps_sample[ (p_vout->c_fps_samples - 1)
1741 % VOUT_FPS_SAMPLES ] -
1742 p_vout->p_fps_sample[ p_vout->c_fps_samples
1743 % VOUT_FPS_SAMPLES ] );
1744 sprintf( psz_buffer, "%li.%i fps", i_fps / 10, (int)i_fps % 10 );
1745 Print( p_vout, 0, 0, RIGHT_RALIGN, TOP_RALIGN, psz_buffer );
1749 * Print frames count and loop time in upper left corner
1751 sprintf( psz_buffer, "%ld frames, render: %ldus",
1752 (long) p_vout->c_fps_samples, (long) p_vout->render_time );
1753 Print( p_vout, 0, 0, LEFT_RALIGN, TOP_RALIGN, psz_buffer );
1757 * Print picture information in lower right corner
1759 sprintf( psz_buffer, "%s picture %dx%d (%dx%d%+d%+d %s) -> %dx%d+%d+%d",
1760 (p_pic->i_type == YUV_420_PICTURE) ? "4:2:0" :
1761 ((p_pic->i_type == YUV_422_PICTURE) ? "4:2:2" :
1762 ((p_pic->i_type == YUV_444_PICTURE) ? "4:4:4" : "ukn-type")),
1763 p_pic->i_width, p_pic->i_height,
1764 p_pic->i_display_width, p_pic->i_display_height,
1765 p_pic->i_display_horizontal_offset, p_pic->i_display_vertical_offset,
1766 (p_pic->i_aspect_ratio == AR_SQUARE_PICTURE) ? "sq" :
1767 ((p_pic->i_aspect_ratio == AR_3_4_PICTURE) ? "4:3" :
1768 ((p_pic->i_aspect_ratio == AR_16_9_PICTURE) ? "16:9" :
1769 ((p_pic->i_aspect_ratio == AR_221_1_PICTURE) ? "2.21:1" : "ukn-ar" ))),
1770 p_vout->p_buffer[ p_vout->i_buffer_index ].i_pic_width,
1771 p_vout->p_buffer[ p_vout->i_buffer_index ].i_pic_height,
1772 p_vout->p_buffer[ p_vout->i_buffer_index ].i_pic_x,
1773 p_vout->p_buffer[ p_vout->i_buffer_index ].i_pic_y );
1774 Print( p_vout, 0, 0, RIGHT_RALIGN, BOTTOM_RALIGN, psz_buffer );
1778 /*****************************************************************************
1779 * RenderSplash: render splash picture
1780 *****************************************************************************
1781 * This function will print something on the screen. It will return 0 if
1782 * nothing has been rendered, or 1 if something has been changed on the screen.
1783 * Note that if you absolutely want something to be printed, you will have
1784 * to force it by setting the last idle date to 0.
1785 * Unlike other rendering functions, this one calls the SetBufferPicture
1786 * function when needed.
1787 *****************************************************************************/
1788 int RenderSplash( vout_thread_t *p_vout )
1790 int i_x = 0, i_y = 0; /* text position */
1791 int i_width, i_height; /* text size */
1792 char *psz_text = "VideoLAN Client (" VERSION ")"; /* text to display */
1794 memset( p_vout->p_buffer[ p_vout->i_buffer_index ].p_data,
1795 p_vout->i_bytes_per_line * p_vout->i_height, 12);
1797 // SetBufferPicture( p_vout, NULL );
1798 vout_TextSize( p_vout->p_large_font, WIDE_TEXT | OUTLINED_TEXT, psz_text,
1799 &i_width, &i_height );
1800 if( !Align( p_vout, &i_x, &i_y, i_width, i_height, CENTER_RALIGN, CENTER_RALIGN ) )
1802 vout_Print( p_vout->p_large_font,
1803 p_vout->p_buffer[ p_vout->i_buffer_index ].p_data +
1804 i_x * p_vout->i_bytes_per_pixel + (i_y - 16 ) * p_vout->i_bytes_per_line,
1805 p_vout->i_bytes_per_pixel, p_vout->i_bytes_per_line,
1806 p_vout->i_white_pixel, p_vout->i_gray_pixel, 0,
1807 WIDE_TEXT | OUTLINED_TEXT, psz_text, 100);
1808 SetBufferArea( p_vout, i_x, i_y, i_width, i_height);
1814 /*****************************************************************************
1815 * RenderIdle: render idle picture
1816 *****************************************************************************
1817 * This function will print something on the screen. It will return 0 if
1818 * nothing has been rendered, or 1 if something has been changed on the screen.
1819 * Note that if you absolutely want something to be printed, you will have
1820 * to force it by setting the last idle date to 0.
1821 * Unlike other rendering functions, this one calls the SetBufferPicture
1822 * function when needed.
1823 *****************************************************************************/
1824 int RenderIdle( vout_thread_t *p_vout )
1826 int i_x = 0, i_y = 0; /* text position */
1827 int i_width, i_height; /* text size */
1828 mtime_t current_date; /* current date */
1829 int i_amount = 0; /* amount to draw */
1830 char *psz_text = "Waiting for stream"; /* text to display */
1831 char *psz_wtext = "[................]";
1834 memset( p_vout->p_buffer[ p_vout->i_buffer_index ].p_data,
1835 p_vout->i_bytes_per_line * p_vout->i_height, 12);
1838 current_date = mdate();
1839 if( (current_date - p_vout->last_display_date) > VOUT_IDLE_DELAY
1840 // && (current_date - p_vout->last_idle_date) > VOUT_IDLE_DELAY
1843 SetBufferPicture( p_vout, NULL );
1844 vout_TextSize( p_vout->p_large_font, WIDE_TEXT | OUTLINED_TEXT, psz_text,
1845 &i_width, &i_height );
1846 if( !Align( p_vout, &i_x, &i_y, i_width, i_height * 2, CENTER_RALIGN, CENTER_RALIGN ) )
1848 i_amount = (int) ((current_date - p_vout->last_display_date ) / 5000LL);
1849 vout_Print( p_vout->p_large_font,
1850 p_vout->p_buffer[ p_vout->i_buffer_index ].p_data +
1851 i_x * p_vout->i_bytes_per_pixel + i_y * p_vout->i_bytes_per_line,
1852 p_vout->i_bytes_per_pixel, p_vout->i_bytes_per_line,
1853 p_vout->i_white_pixel, p_vout->i_gray_pixel, 0,
1854 WIDE_TEXT | OUTLINED_TEXT, psz_text, (i_amount / 3 ) %110);
1856 vout_Print( p_vout->p_large_font,
1857 p_vout->p_buffer[ p_vout->i_buffer_index ].p_data +
1858 i_x * p_vout->i_bytes_per_pixel + (i_y + 16) * p_vout->i_bytes_per_line,
1859 p_vout->i_bytes_per_pixel, p_vout->i_bytes_per_line,
1860 p_vout->i_white_pixel, p_vout->i_gray_pixel, 0,
1861 WIDE_TEXT | OUTLINED_TEXT, psz_wtext, (i_amount/5)%110 );
1864 SetBufferArea( p_vout, i_x, i_y, i_width, i_height * 2 );
1871 /*****************************************************************************
1872 * RenderInfo: render additionnal information
1873 *****************************************************************************
1874 * This function renders information which do not depend on the current
1876 *****************************************************************************/
1877 static void RenderInfo( vout_thread_t *p_vout )
1880 char psz_buffer[256]; /* string buffer */
1881 int i_ready_pic = 0; /* ready pictures */
1882 int i_reserved_pic = 0; /* reserved pictures */
1883 int i_picture; /* picture index */
1888 * Print thread state in lower left corner
1890 for( i_picture = 0; i_picture < VOUT_MAX_PICTURES; i_picture++ )
1892 switch( p_vout->p_picture[i_picture].i_status )
1894 case RESERVED_PICTURE:
1895 case RESERVED_DATED_PICTURE:
1896 case RESERVED_DISP_PICTURE:
1904 sprintf( psz_buffer, "pic: %d (%d/%d)/%d",
1905 p_vout->i_pictures, i_reserved_pic, i_ready_pic, VOUT_MAX_PICTURES );
1906 Print( p_vout, 0, 0, LEFT_RALIGN, BOTTOM_RALIGN, psz_buffer );
1910 /*****************************************************************************
1911 * RenderSubPicture: render a subpicture
1912 *****************************************************************************
1913 * This function renders a sub picture unit.
1914 *****************************************************************************/
1915 static void RenderSubPicture( vout_thread_t *p_vout, subpicture_t *p_subpic )
1917 p_vout_font_t p_font; /* text font */
1918 int i_width, i_height; /* subpicture dimensions */
1920 while( p_subpic != NULL )
1922 switch( p_subpic->i_type )
1924 case DVD_SUBPICTURE: /* DVD subpicture unit */
1925 /* test if the picture really has to be displayed */
1926 if( mdate() < p_subpic->begin_date )
1928 /* not yet, see you later */
1931 if( mdate() > p_subpic->end_date )
1933 /* too late, destroying the subpic */
1934 vout_DestroySubPicture( p_vout, p_subpic );
1937 vout_RenderSPU( &p_vout->p_buffer[ p_vout->i_buffer_index ],
1938 p_subpic, p_vout->i_bytes_per_pixel,
1939 p_vout->i_bytes_per_line );
1941 case TEXT_SUBPICTURE: /* single line text */
1942 /* Select default font if not specified */
1943 p_font = p_subpic->type.text.p_font;
1944 if( p_font == NULL )
1946 p_font = p_vout->p_default_font;
1949 /* Compute text size (width and height fields are ignored)
1951 vout_TextSize( p_font, p_subpic->type.text.i_style,
1952 p_subpic->p_data, &i_width, &i_height );
1953 if( !Align( p_vout, &p_subpic->i_x, &p_subpic->i_y,
1954 i_width, i_height, p_subpic->i_horizontal_align,
1955 p_subpic->i_vertical_align ) )
1958 p_vout->p_buffer[ p_vout->i_buffer_index ].p_data +
1959 p_subpic->i_x * p_vout->i_bytes_per_pixel +
1960 p_subpic->i_y * p_vout->i_bytes_per_line,
1961 p_vout->i_bytes_per_pixel, p_vout->i_bytes_per_line,
1962 p_subpic->type.text.i_char_color,
1963 p_subpic->type.text.i_border_color,
1964 p_subpic->type.text.i_bg_color,
1965 p_subpic->type.text.i_style, p_subpic->p_data, 100 );
1966 SetBufferArea( p_vout, p_subpic->i_x, p_subpic->i_y,
1967 i_width, i_height );
1973 intf_DbgMsg( "error: unknown subpicture %p type %d\n",
1974 p_subpic, p_subpic->i_type );
1978 p_subpic = p_subpic->p_next;
1982 /*****************************************************************************
1983 * RenderInterface: render the interface
1984 *****************************************************************************
1985 * This function renders the interface, if any.
1986 *****************************************************************************/
1987 static void RenderInterface( vout_thread_t *p_vout )
1989 int i_height, i_text_height; /* total and text height */
1990 int i_width_1, i_width_2; /* text width */
1991 int i_byte; /* byte index */
1992 const char *psz_text_1 = "[1-9] Channel [i]nfo [c]olor [g/G]amma";
1993 const char *psz_text_2 = "[+/-] Volume [m]ute [s]caling [Q]uit";
1996 vout_TextSize( p_vout->p_large_font, OUTLINED_TEXT, psz_text_1, &i_width_1, &i_height );
1997 vout_TextSize( p_vout->p_large_font, OUTLINED_TEXT, psz_text_2, &i_width_2, &i_text_height );
1998 i_height += i_text_height;
2000 /* Render background */
2001 for( i_byte = (p_vout->i_height - i_height) * p_vout->i_bytes_per_line;
2002 i_byte < p_vout->i_height * p_vout->i_bytes_per_line;
2006 p_vout->p_buffer[ p_vout->i_buffer_index ].p_data[ i_byte ] = p_vout->i_blue_pixel;
2009 /* Render text, if not larger than screen */
2010 if( i_width_1 < p_vout->i_width )
2012 vout_Print( p_vout->p_large_font, p_vout->p_buffer[ p_vout->i_buffer_index ].p_data +
2013 (p_vout->i_height - i_height) * p_vout->i_bytes_per_line,
2014 p_vout->i_bytes_per_pixel, p_vout->i_bytes_per_line,
2015 p_vout->i_white_pixel, p_vout->i_black_pixel, 0,
2016 OUTLINED_TEXT, psz_text_1, 100 );
2018 if( i_width_2 < p_vout->i_width )
2020 vout_Print( p_vout->p_large_font, p_vout->p_buffer[ p_vout->i_buffer_index ].p_data +
2021 (p_vout->i_height - i_height + i_text_height) * p_vout->i_bytes_per_line,
2022 p_vout->i_bytes_per_pixel, p_vout->i_bytes_per_line,
2023 p_vout->i_white_pixel, p_vout->i_black_pixel, 0,
2024 OUTLINED_TEXT, psz_text_2, 100 );
2027 /* Activate modified area */
2028 SetBufferArea( p_vout, 0, p_vout->i_height - i_height, p_vout->i_width, i_height );
2031 /*****************************************************************************
2032 * Manage: manage thread
2033 *****************************************************************************
2034 * This function will handle changes in thread configuration.
2035 *****************************************************************************/
2036 static int Manage( vout_thread_t *p_vout )
2039 if( p_vout->i_changes )
2041 intf_DbgMsg("changes: 0x%x (no display: 0x%x)\n", p_vout->i_changes,
2042 0 /* p_vout->i_changes & VOUT_NODISPLAY_CHANGE */ );
2046 /* On gamma or grayscale change, rebuild tables */
2047 if( p_vout->i_changes & (VOUT_GAMMA_CHANGE | VOUT_GRAYSCALE_CHANGE |
2050 /* Change vdec_DecodeMacroblock when switching between BW and C */
2051 if( !p_vout->b_grayscale )
2053 p_vout->vdec_DecodeMacroblock = vdec_DecodeMacroblockC;
2055 else if( p_vout->b_grayscale)
2057 p_vout->vdec_DecodeMacroblock = vdec_DecodeMacroblockBW;
2059 if( vout_ResetYUV( p_vout ) )
2061 intf_ErrMsg("error: can't rebuild convertion tables\n");
2066 /* Clear changes flags which does not need management or have been
2068 p_vout->i_changes &= ~(VOUT_GAMMA_CHANGE | VOUT_GRAYSCALE_CHANGE |
2069 VOUT_YUV_CHANGE | VOUT_INFO_CHANGE |
2070 VOUT_INTF_CHANGE | VOUT_SCALE_CHANGE );
2072 /* Detect unauthorized changes */
2073 if( p_vout->i_changes )
2075 /* Some changes were not acknowledged by p_vout->p_sys_manage or this
2076 * function, it means they should not be authorized */
2077 intf_ErrMsg( "error: unauthorized changes in the video output thread\n" );
2084 /*****************************************************************************
2085 * Align: align a subpicture in the screen
2086 *****************************************************************************
2087 * This function is used for rendering text or subpictures. It returns non 0
2088 * it the final aera is not fully included in display area. Return coordinates
2090 *****************************************************************************/
2091 static int Align( vout_thread_t *p_vout, int *pi_x, int *pi_y,
2092 int i_width, int i_height, int i_h_align, int i_v_align )
2094 /* Align horizontally */
2098 *pi_x -= i_width / 2;
2101 *pi_x += (p_vout->i_width - i_width) / 2;
2107 *pi_x += p_vout->i_width - i_width;
2111 /* Align vertically */
2115 *pi_y -= i_height / 2;
2118 *pi_y += (p_vout->i_height - i_height) / 2;
2124 *pi_y += p_vout->i_height - i_height;
2126 case SUBTITLE_RALIGN:
2127 *pi_y += (p_vout->i_height + p_vout->p_buffer[ p_vout->i_buffer_index ].i_pic_y +
2128 p_vout->p_buffer[ p_vout->i_buffer_index ].i_pic_height - i_height) / 2;
2132 /* Return non 0 if clipping failed */
2133 return( (*pi_x < 0) || (*pi_y < 0) ||
2134 (*pi_x + i_width > p_vout->i_width) || (*pi_y + i_height > p_vout->i_height) );
2137 /*****************************************************************************
2138 * SetPalette: sets an 8 bpp palette
2139 *****************************************************************************
2140 * This function is just a prototype that does nothing. Architectures that
2141 * support palette allocation should override it.
2142 *****************************************************************************/
2143 static void SetPalette ( p_vout_thread_t p_vout, u16 *red,
2144 u16 *green, u16 *blue, u16 *transp )
2146 intf_ErrMsg( "SetPalette: method does not support palette changing\n" );