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;
1073 /* FIXME: if b_need_render == 0 we need to do something with
1074 * the subpictures one day. */
1075 if( p_vout->b_need_render && b_display )
1077 /* Set picture dimensions and clear buffer */
1078 SetBufferPicture( p_vout, p_pic );
1080 /* Render picture and information */
1081 RenderPicture( p_vout, p_pic );
1082 if( p_vout->b_info )
1084 RenderPictureInfo( p_vout, p_pic );
1085 RenderInfo( p_vout );
1089 RenderSubPicture( p_vout, p_subpic );
1093 /* Render interface and subpicture */
1094 if( b_display && p_vout->b_interface && p_vout->b_need_render )
1096 RenderInterface( p_vout );
1100 else if( p_vout->b_active && p_vout->b_need_render
1101 && p_vout->init_display_date == 0)
1103 /* Idle or interface screen alone */
1105 if( p_vout->b_interface && 0 /* && XXX?? intf_change */ )
1107 /* Interface has changed, so a new rendering is required - force
1108 * it by setting last idle date to 0 */
1109 p_vout->last_idle_date = 0;
1112 /* Render idle screen and update idle date, then render interface if
1114 b_display = RenderIdle( p_vout );
1117 p_vout->last_idle_date = current_date;
1118 if( p_vout->b_interface )
1120 RenderInterface( p_vout );
1132 * Check for the current time and
1133 * display splash screen if everything is on time
1135 if( p_vout->init_display_date > 0 && p_vout->b_need_render )
1137 if( p_vout->b_active &&
1138 mdate()-p_vout->init_display_date < 5000000)
1140 /* there is something to display ! */
1142 RenderSplash( p_vout );
1145 /* no splash screen ! */
1146 intf_ErrMsgImm("End of splash screen\n");
1147 p_vout->init_display_date=0;
1153 * Sleep, wake up and display rendered picture
1156 if( display_date != 0 )
1158 /* Store render time using Bresenham algorithm */
1159 p_vout->render_time += mdate() - current_date;
1160 p_vout->render_time >>= 1;
1163 /* Give back change lock */
1164 vlc_mutex_unlock( &p_vout->change_lock );
1166 /* Sleep a while or until a given date */
1167 if( display_date != 0 )
1169 mwait( display_date - VOUT_MWAIT_TOLERANCE );
1173 msleep( VOUT_IDLE_SLEEP );
1176 /* On awakening, take back lock and send immediately picture to display,
1177 * then swap buffers */
1178 vlc_mutex_lock( &p_vout->change_lock );
1180 intf_DbgMsg( "picture %p, subpicture %p in buffer %d, display=%d\n", p_pic, p_subpic,
1181 p_vout->i_buffer_index, b_display /* && !(p_vout->i_changes & VOUT_NODISPLAY_CHANGE) */ );
1183 if( b_display /* && !(p_vout->i_changes & VOUT_NODISPLAY_CHANGE) */ )
1185 p_vout->p_sys_display( p_vout );
1187 p_vout->i_buffer_index = ++p_vout->i_buffer_index & 1;
1193 /* Remove picture from heap */
1194 vlc_mutex_lock( &p_vout->picture_lock );
1195 if( p_pic->i_refcount )
1197 p_pic->i_status = DISPLAYED_PICTURE;
1201 p_pic->i_status = DESTROYED_PICTURE;
1202 p_vout->i_pictures--;
1204 vlc_mutex_unlock( &p_vout->picture_lock );
1209 * Check events and manage thread
1211 if( p_vout->p_sys_manage( p_vout ) | Manage( p_vout ) )
1213 /* A fatal error occured, and the thread must terminate immediately,
1214 * without displaying anything - setting b_error to 1 cause the
1215 * immediate end of the main while() loop. */
1216 p_vout->b_error = 1;
1221 * Error loop - wait until the thread destruction is requested
1223 if( p_vout->b_error )
1225 ErrorThread( p_vout );
1229 EndThread( p_vout );
1230 DestroyThread( p_vout, THREAD_OVER );
1231 intf_DbgMsg( "thread end\n" );
1234 /*****************************************************************************
1235 * ErrorThread: RunThread() error loop
1236 *****************************************************************************
1237 * This function is called when an error occured during thread main's loop. The
1238 * thread can still receive feed, but must be ready to terminate as soon as
1240 *****************************************************************************/
1241 static void ErrorThread( vout_thread_t *p_vout )
1243 /* Wait until a `die' order */
1245 while( !p_vout->b_die )
1248 msleep( VOUT_IDLE_SLEEP );
1252 /*****************************************************************************
1253 * EndThread: thread destruction
1254 *****************************************************************************
1255 * This function is called when the thread ends after a sucessful
1256 * initialization. It frees all ressources allocated by InitThread.
1257 *****************************************************************************/
1258 static void EndThread( vout_thread_t *p_vout )
1260 int i_index; /* index in heap */
1264 *p_vout->pi_status = THREAD_END;
1268 struct tms cpu_usage;
1269 times( &cpu_usage );
1271 intf_Msg("vout stats: cpu usage (user: %d, system: %d)\n",
1272 cpu_usage.tms_utime, cpu_usage.tms_stime);
1276 /* Destroy all remaining pictures and subpictures */
1277 for( i_index = 0; i_index < VOUT_MAX_PICTURES; i_index++ )
1279 if( p_vout->p_picture[i_index].i_status != FREE_PICTURE )
1281 free( p_vout->p_picture[i_index].p_data );
1284 for( i_index = 0; i_index < VOUT_MAX_SUBPICTURES; i_index++ )
1286 if( p_vout->p_subpicture[i_index].i_status != FREE_SUBPICTURE )
1288 free( p_vout->p_subpicture[i_index].p_data );
1292 /* Destroy translation tables */
1293 vout_EndYUV( p_vout );
1294 p_vout->p_sys_end( p_vout );
1297 /*****************************************************************************
1298 * DestroyThread: thread destruction
1299 *****************************************************************************
1300 * This function is called when the thread ends. It frees all ressources
1301 * allocated by CreateThread. Status is available at this stage.
1302 *****************************************************************************/
1303 static void DestroyThread( vout_thread_t *p_vout, int i_status )
1305 int *pi_status; /* status adress */
1307 /* Store status adress */
1309 pi_status = p_vout->pi_status;
1311 /* Destroy thread structures allocated by Create and InitThread */
1312 vout_UnloadFont( p_vout->p_default_font );
1313 vout_UnloadFont( p_vout->p_large_font );
1314 p_vout->p_sys_destroy( p_vout );
1316 /* Free structure */
1318 *pi_status = i_status;
1321 /*****************************************************************************
1322 * Print: print simple text on a picture
1323 *****************************************************************************
1324 * This function will print a simple text on the picture. It is designed to
1325 * print debugging or general information.
1326 *****************************************************************************/
1327 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 )
1329 int i_text_height; /* total text height */
1330 int i_text_width; /* total text width */
1332 /* Update upper left coordinates according to alignment */
1333 vout_TextSize( p_vout->p_default_font, 0, psz_text, &i_text_width, &i_text_height );
1334 if( !Align( p_vout, &i_x, &i_y, i_text_width, i_text_height, i_h_align, i_v_align ) )
1336 /* Set area and print text */
1337 SetBufferArea( p_vout, i_x, i_y, i_text_width, i_text_height );
1338 vout_Print( p_vout->p_default_font, p_vout->p_buffer[ p_vout->i_buffer_index ].p_data +
1339 i_y * p_vout->i_bytes_per_line + i_x * p_vout->i_bytes_per_pixel,
1340 p_vout->i_bytes_per_pixel, p_vout->i_bytes_per_line,
1341 p_vout->i_white_pixel, 0, 0,
1346 /*****************************************************************************
1347 * SetBufferArea: activate an area in current buffer
1348 *****************************************************************************
1349 * This function is called when something is rendered on the current buffer.
1350 * It set the area as active and prepare it to be cleared on next rendering.
1351 * Pay attention to the fact that in this functions, i_h is in fact the end y
1352 * coordinate of the new area.
1353 *****************************************************************************/
1354 static void SetBufferArea( vout_thread_t *p_vout, int i_x, int i_y, int i_w, int i_h )
1356 vout_buffer_t * p_buffer; /* current buffer */
1357 int i_area_begin, i_area_end; /* area vertical extension */
1358 int i_area, i_area_copy; /* area index */
1359 int i_area_shift; /* shift distance for areas */
1361 /* Choose buffer and modify h to end of area position */
1362 p_buffer = &p_vout->p_buffer[ p_vout->i_buffer_index ];
1366 * Remove part of the area which is inside the picture - this is done
1367 * by calling again SetBufferArea with the correct areas dimensions.
1369 if( (i_x >= p_buffer->i_pic_x) && (i_x + i_w <= p_buffer->i_pic_x + p_buffer->i_pic_width) )
1371 i_area_begin = p_buffer->i_pic_y;
1372 i_area_end = i_area_begin + p_buffer->i_pic_height - 1;
1374 if( ((i_y >= i_area_begin) && (i_y <= i_area_end)) ||
1375 ((i_h >= i_area_begin) && (i_h <= i_area_end)) ||
1376 ((i_y < i_area_begin) && (i_h > i_area_end)) )
1378 /* Keep the stripe above the picture, if any */
1379 if( i_y < i_area_begin )
1381 SetBufferArea( p_vout, i_x, i_y, i_w, i_area_begin - i_y );
1383 /* Keep the stripe below the picture, if any */
1384 if( i_h > i_area_end )
1386 SetBufferArea( p_vout, i_x, i_area_end, i_w, i_h - i_area_end );
1392 /* Skip some extensions until interesting areas */
1394 (i_area < p_buffer->i_areas) &&
1395 (p_buffer->pi_area_end[i_area] + 1 <= i_y);
1401 if( i_area == p_buffer->i_areas )
1403 /* New area is below all existing ones: just add it at the end of the
1404 * array, if possible - otherwise, append it to the last one */
1405 if( i_area < VOUT_MAX_AREAS )
1407 p_buffer->pi_area_begin[i_area] = i_y;
1408 p_buffer->pi_area_end[i_area] = i_h;
1409 p_buffer->i_areas++;
1414 intf_DbgMsg("area overflow\n");
1416 p_buffer->pi_area_end[VOUT_MAX_AREAS - 1] = i_h;
1421 i_area_begin = p_buffer->pi_area_begin[i_area];
1422 i_area_end = p_buffer->pi_area_end[i_area];
1424 if( i_y < i_area_begin )
1426 if( i_h >= i_area_begin - 1 )
1428 /* Extend area above */
1429 p_buffer->pi_area_begin[i_area] = i_y;
1433 /* Create a new area above : merge last area if overflow, then
1434 * move all old areas down */
1435 if( p_buffer->i_areas == VOUT_MAX_AREAS )
1438 intf_DbgMsg("areas overflow\n");
1440 p_buffer->pi_area_end[VOUT_MAX_AREAS - 2] = p_buffer->pi_area_end[VOUT_MAX_AREAS - 1];
1444 p_buffer->i_areas++;
1446 for( i_area_copy = p_buffer->i_areas - 1; i_area_copy > i_area; i_area_copy-- )
1448 p_buffer->pi_area_begin[i_area_copy] = p_buffer->pi_area_begin[i_area_copy - 1];
1449 p_buffer->pi_area_end[i_area_copy] = p_buffer->pi_area_end[i_area_copy - 1];
1451 p_buffer->pi_area_begin[i_area] = i_y;
1452 p_buffer->pi_area_end[i_area] = i_h;
1456 if( i_h > i_area_end )
1458 /* Find further areas which can be merged with the new one */
1459 for( i_area_copy = i_area + 1;
1460 (i_area_copy < p_buffer->i_areas) &&
1461 (p_buffer->pi_area_begin[i_area] <= i_h);
1468 if( i_area_copy != i_area )
1470 /* Merge with last possible areas */
1471 p_buffer->pi_area_end[i_area] = MAX( i_h, p_buffer->pi_area_end[i_area_copy] );
1473 /* Shift lower areas upward */
1474 i_area_shift = i_area_copy - i_area;
1475 p_buffer->i_areas -= i_area_shift;
1476 for( i_area_copy = i_area + 1; i_area_copy < p_buffer->i_areas; i_area_copy++ )
1478 p_buffer->pi_area_begin[i_area_copy] = p_buffer->pi_area_begin[i_area_copy + i_area_shift];
1479 p_buffer->pi_area_end[i_area_copy] = p_buffer->pi_area_end[i_area_copy + i_area_shift];
1484 /* Extend area below */
1485 p_buffer->pi_area_end[i_area] = i_h;
1491 /*****************************************************************************
1492 * SetBufferPicture: clear buffer and set picture area
1493 *****************************************************************************
1494 * This function is called before any rendering. It clears the current
1495 * rendering buffer and set the new picture area. If the picture pointer is
1496 * NULL, then no picture area is defined. Floating operations are avoided since
1497 * some MMX calculations may follow.
1498 *****************************************************************************/
1499 static void SetBufferPicture( vout_thread_t *p_vout, picture_t *p_pic )
1501 vout_buffer_t * p_buffer; /* current buffer */
1502 int i_pic_x, i_pic_y; /* picture position */
1503 int i_pic_width, i_pic_height; /* picture dimensions */
1504 int i_old_pic_y, i_old_pic_height; /* old picture area */
1505 int i_vout_width, i_vout_height; /* display dimensions */
1506 int i_area; /* area index */
1507 int i_data_index; /* area data index */
1508 int i_data_size; /* area data size, in 256 bytes blocs */
1509 u64 * p_data; /* area data, for clearing */
1510 byte_t * p_data8; /* area data, for clearing (slow) */
1512 /* Choose buffer and set display dimensions */
1513 p_buffer = &p_vout->p_buffer[ p_vout->i_buffer_index ];
1514 i_vout_width = p_vout->i_width;
1515 i_vout_height = p_vout->i_height;
1518 * Computes new picture size
1522 /* Try horizontal scaling first - width must be a mutiple of 16 */
1523 i_pic_width = (( p_vout->b_scale || (p_pic->i_width > i_vout_width)) ?
1524 i_vout_width : p_pic->i_width) & ~0xf;
1525 switch( p_pic->i_aspect_ratio )
1527 case AR_3_4_PICTURE:
1528 i_pic_height = i_pic_width * 3 / 4;
1530 case AR_16_9_PICTURE:
1531 i_pic_height = i_pic_width * 9 / 16;
1533 case AR_221_1_PICTURE:
1534 i_pic_height = i_pic_width * 100 / 221;
1536 case AR_SQUARE_PICTURE:
1538 i_pic_height = p_pic->i_height * i_pic_width / p_pic->i_width;
1542 /* If picture dimensions using horizontal scaling are too large, use
1543 * vertical scaling. Since width must be a multiple of 16, height is
1544 * adjusted again after. */
1545 if( i_pic_height > i_vout_height )
1547 i_pic_height = ( p_vout->b_scale || (p_pic->i_height > i_vout_height)) ?
1548 i_vout_height : p_pic->i_height;
1549 switch( p_pic->i_aspect_ratio )
1551 case AR_3_4_PICTURE:
1552 i_pic_width = (i_pic_height * 4 / 3) & ~0xf;
1553 i_pic_height = i_pic_width * 3 / 4;
1555 case AR_16_9_PICTURE:
1556 i_pic_width = (i_pic_height * 16 / 9) & ~0xf;
1557 i_pic_height = i_pic_width * 9 / 16;
1559 case AR_221_1_PICTURE:
1560 i_pic_width = (i_pic_height * 221 / 100) & ~0xf;
1561 i_pic_height = i_pic_width * 100 / 221;
1563 case AR_SQUARE_PICTURE:
1565 i_pic_width = (p_pic->i_width * i_pic_height / p_pic->i_height) & ~0xf;
1566 i_pic_height = p_pic->i_height * i_pic_width / p_pic->i_width;
1571 /* Set picture position */
1572 i_pic_x = (p_vout->i_width - i_pic_width) / 2;
1573 i_pic_y = (p_vout->i_height - i_pic_height) / 2;
1577 /* No picture: size is 0 */
1585 * Set new picture size - if it is smaller than the previous one, clear
1586 * around it. Since picture are centered, only their size is tested.
1588 if( (p_buffer->i_pic_width > i_pic_width) || (p_buffer->i_pic_height > i_pic_height) )
1590 i_old_pic_y = p_buffer->i_pic_y;
1591 i_old_pic_height = p_buffer->i_pic_height;
1592 p_buffer->i_pic_x = i_pic_x;
1593 p_buffer->i_pic_y = i_pic_y;
1594 p_buffer->i_pic_width = i_pic_width;
1595 p_buffer->i_pic_height = i_pic_height;
1596 SetBufferArea( p_vout, 0, i_old_pic_y, p_vout->i_width, i_old_pic_height );
1600 p_buffer->i_pic_x = i_pic_x;
1601 p_buffer->i_pic_y = i_pic_y;
1602 p_buffer->i_pic_width = i_pic_width;
1603 p_buffer->i_pic_height = i_pic_height;
1609 for( i_area = 0; i_area < p_buffer->i_areas; i_area++ )
1612 intf_DbgMsg("clearing picture %p area in buffer %d: %d-%d\n", p_pic,
1613 p_vout->i_buffer_index, p_buffer->pi_area_begin[i_area], p_buffer->pi_area_end[i_area] );
1615 i_data_size = (p_buffer->pi_area_end[i_area] - p_buffer->pi_area_begin[i_area] + 1) * p_vout->i_bytes_per_line;
1616 p_data = (u64*) (p_buffer->p_data + p_vout->i_bytes_per_line * p_buffer->pi_area_begin[i_area]);
1617 for( i_data_index = i_data_size / 256; i_data_index-- ; )
1619 /* Clear 256 bytes block */
1620 *p_data++ = 0; *p_data++ = 0; *p_data++ = 0; *p_data++ = 0;
1621 *p_data++ = 0; *p_data++ = 0; *p_data++ = 0; *p_data++ = 0;
1622 *p_data++ = 0; *p_data++ = 0; *p_data++ = 0; *p_data++ = 0;
1623 *p_data++ = 0; *p_data++ = 0; *p_data++ = 0; *p_data++ = 0;
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;
1629 for( i_data_index = (i_data_size % 256) / 16; i_data_index--; )
1631 /* Clear remaining 16 bytes blocks */
1632 *p_data++ = 0; *p_data++ = 0;
1634 p_data8 = (byte_t *)p_data;
1635 for( i_data_index = i_data_size % 16; i_data_index--; )
1637 /* Clear remaining bytes */
1645 p_buffer->i_areas = 0;
1648 /*****************************************************************************
1649 * RenderPicture: render a picture
1650 *****************************************************************************
1651 * This function converts a picture from a video heap to a pixel-encoded image
1652 * and copies it to the current rendering buffer. No lock is required, since
1653 * the * rendered picture has been determined as existant, and will only be
1654 * destroyed by the vout thread later.
1655 *****************************************************************************/
1656 static void RenderPicture( vout_thread_t *p_vout, picture_t *p_pic )
1659 char psz_date[MSTRTIME_MAX_SIZE]; /* picture date */
1660 mtime_t render_time; /* picture rendering time */
1662 vout_buffer_t * p_buffer; /* rendering buffer */
1663 byte_t * p_pic_data; /* convertion destination */
1665 /* Get and set rendering information */
1666 p_buffer = &p_vout->p_buffer[ p_vout->i_buffer_index ];
1667 p_pic_data = p_buffer->p_data +
1668 p_buffer->i_pic_x * p_vout->i_bytes_per_pixel +
1669 p_buffer->i_pic_y * p_vout->i_bytes_per_line;
1671 render_time = mdate();
1675 * Choose appropriate rendering function and render picture
1677 switch( p_pic->i_type )
1679 case YUV_420_PICTURE:
1680 p_vout->yuv.p_Convert420( p_vout, p_pic_data,
1681 p_pic->p_y, p_pic->p_u, p_pic->p_v,
1682 p_pic->i_width, p_pic->i_height,
1683 p_buffer->i_pic_width, p_buffer->i_pic_height,
1684 p_vout->i_bytes_per_line / p_vout->i_bytes_per_pixel,
1685 p_pic->i_matrix_coefficients );
1687 case YUV_422_PICTURE:
1688 p_vout->yuv.p_Convert422( p_vout, p_pic_data,
1689 p_pic->p_y, p_pic->p_u, p_pic->p_v,
1690 p_pic->i_width, p_pic->i_height,
1691 p_buffer->i_pic_width, p_buffer->i_pic_height,
1692 p_vout->i_bytes_per_line / p_vout->i_bytes_per_pixel,
1693 p_pic->i_matrix_coefficients );
1695 case YUV_444_PICTURE:
1696 p_vout->yuv.p_Convert444( p_vout, p_pic_data,
1697 p_pic->p_y, p_pic->p_u, p_pic->p_v,
1698 p_pic->i_width, p_pic->i_height,
1699 p_buffer->i_pic_width, p_buffer->i_pic_height,
1700 p_vout->i_bytes_per_line / p_vout->i_bytes_per_pixel,
1701 p_pic->i_matrix_coefficients );
1705 intf_DbgMsg("error: unknown picture type %d\n", p_pic->i_type );
1711 /* Print picture date and rendering time */
1712 intf_DbgMsg("picture %p rendered in buffer %d (%ld us), display date: %s\n", p_pic,
1713 p_vout->i_buffer_index, (long) (mdate() - render_time),
1714 mstrtime( psz_date, p_pic->date ));
1718 /*****************************************************************************
1719 * RenderPictureInfo: print additionnal information on a picture
1720 *****************************************************************************
1721 * This function will print information such as fps and other picture
1722 * dependant information.
1723 *****************************************************************************/
1724 static void RenderPictureInfo( vout_thread_t *p_vout, picture_t *p_pic )
1726 char psz_buffer[256]; /* string buffer */
1729 * Print FPS rate in upper right corner
1731 if( p_vout->c_fps_samples > VOUT_FPS_SAMPLES )
1733 long i_fps = VOUT_FPS_SAMPLES * 1000000 * 10 /
1734 ( p_vout->p_fps_sample[ (p_vout->c_fps_samples - 1)
1735 % VOUT_FPS_SAMPLES ] -
1736 p_vout->p_fps_sample[ p_vout->c_fps_samples
1737 % VOUT_FPS_SAMPLES ] );
1738 sprintf( psz_buffer, "%li.%i fps", i_fps / 10, (int)i_fps % 10 );
1739 Print( p_vout, 0, 0, RIGHT_RALIGN, TOP_RALIGN, psz_buffer );
1743 * Print frames count and loop time in upper left corner
1745 sprintf( psz_buffer, "%ld frames, render: %ldus",
1746 (long) p_vout->c_fps_samples, (long) p_vout->render_time );
1747 Print( p_vout, 0, 0, LEFT_RALIGN, TOP_RALIGN, psz_buffer );
1751 * Print picture information in lower right corner
1753 sprintf( psz_buffer, "%s picture %dx%d (%dx%d%+d%+d %s) -> %dx%d+%d+%d",
1754 (p_pic->i_type == YUV_420_PICTURE) ? "4:2:0" :
1755 ((p_pic->i_type == YUV_422_PICTURE) ? "4:2:2" :
1756 ((p_pic->i_type == YUV_444_PICTURE) ? "4:4:4" : "ukn-type")),
1757 p_pic->i_width, p_pic->i_height,
1758 p_pic->i_display_width, p_pic->i_display_height,
1759 p_pic->i_display_horizontal_offset, p_pic->i_display_vertical_offset,
1760 (p_pic->i_aspect_ratio == AR_SQUARE_PICTURE) ? "sq" :
1761 ((p_pic->i_aspect_ratio == AR_3_4_PICTURE) ? "4:3" :
1762 ((p_pic->i_aspect_ratio == AR_16_9_PICTURE) ? "16:9" :
1763 ((p_pic->i_aspect_ratio == AR_221_1_PICTURE) ? "2.21:1" : "ukn-ar" ))),
1764 p_vout->p_buffer[ p_vout->i_buffer_index ].i_pic_width,
1765 p_vout->p_buffer[ p_vout->i_buffer_index ].i_pic_height,
1766 p_vout->p_buffer[ p_vout->i_buffer_index ].i_pic_x,
1767 p_vout->p_buffer[ p_vout->i_buffer_index ].i_pic_y );
1768 Print( p_vout, 0, 0, RIGHT_RALIGN, BOTTOM_RALIGN, psz_buffer );
1772 /*****************************************************************************
1773 * RenderSplash: render splash picture
1774 *****************************************************************************
1775 * This function will print something on the screen. It will return 0 if
1776 * nothing has been rendered, or 1 if something has been changed on the screen.
1777 * Note that if you absolutely want something to be printed, you will have
1778 * to force it by setting the last idle date to 0.
1779 * Unlike other rendering functions, this one calls the SetBufferPicture
1780 * function when needed.
1781 *****************************************************************************/
1782 int RenderSplash( vout_thread_t *p_vout )
1784 int i_x = 0, i_y = 0; /* text position */
1785 int i_width, i_height; /* text size */
1786 char *psz_text = "VideoLAN Client (" VERSION ")"; /* text to display */
1788 memset( p_vout->p_buffer[ p_vout->i_buffer_index ].p_data,
1789 p_vout->i_bytes_per_line * p_vout->i_height, 12);
1791 // SetBufferPicture( p_vout, NULL );
1792 vout_TextSize( p_vout->p_large_font, WIDE_TEXT | OUTLINED_TEXT, psz_text,
1793 &i_width, &i_height );
1794 if( !Align( p_vout, &i_x, &i_y, i_width, i_height, CENTER_RALIGN, CENTER_RALIGN ) )
1796 vout_Print( p_vout->p_large_font,
1797 p_vout->p_buffer[ p_vout->i_buffer_index ].p_data +
1798 i_x * p_vout->i_bytes_per_pixel + (i_y - 16 ) * p_vout->i_bytes_per_line,
1799 p_vout->i_bytes_per_pixel, p_vout->i_bytes_per_line,
1800 p_vout->i_white_pixel, p_vout->i_gray_pixel, 0,
1801 WIDE_TEXT | OUTLINED_TEXT, psz_text, 100);
1802 SetBufferArea( p_vout, i_x, i_y, i_width, i_height);
1808 /*****************************************************************************
1809 * RenderIdle: render idle picture
1810 *****************************************************************************
1811 * This function will print something on the screen. It will return 0 if
1812 * nothing has been rendered, or 1 if something has been changed on the screen.
1813 * Note that if you absolutely want something to be printed, you will have
1814 * to force it by setting the last idle date to 0.
1815 * Unlike other rendering functions, this one calls the SetBufferPicture
1816 * function when needed.
1817 *****************************************************************************/
1818 int RenderIdle( vout_thread_t *p_vout )
1820 int i_x = 0, i_y = 0; /* text position */
1821 int i_width, i_height; /* text size */
1822 mtime_t current_date; /* current date */
1823 int i_amount = 0; /* amount to draw */
1824 char *psz_text = "Waiting for stream"; /* text to display */
1825 char *psz_wtext = "[................]";
1828 memset( p_vout->p_buffer[ p_vout->i_buffer_index ].p_data,
1829 p_vout->i_bytes_per_line * p_vout->i_height, 12);
1832 current_date = mdate();
1833 if( (current_date - p_vout->last_display_date) > VOUT_IDLE_DELAY
1834 // && (current_date - p_vout->last_idle_date) > VOUT_IDLE_DELAY
1837 SetBufferPicture( p_vout, NULL );
1838 vout_TextSize( p_vout->p_large_font, WIDE_TEXT | OUTLINED_TEXT, psz_text,
1839 &i_width, &i_height );
1840 if( !Align( p_vout, &i_x, &i_y, i_width, i_height * 2, CENTER_RALIGN, CENTER_RALIGN ) )
1842 i_amount = (int) ((current_date - p_vout->last_display_date ) / 5000LL);
1843 vout_Print( p_vout->p_large_font,
1844 p_vout->p_buffer[ p_vout->i_buffer_index ].p_data +
1845 i_x * p_vout->i_bytes_per_pixel + i_y * p_vout->i_bytes_per_line,
1846 p_vout->i_bytes_per_pixel, p_vout->i_bytes_per_line,
1847 p_vout->i_white_pixel, p_vout->i_gray_pixel, 0,
1848 WIDE_TEXT | OUTLINED_TEXT, psz_text, (i_amount / 3 ) %110);
1850 vout_Print( p_vout->p_large_font,
1851 p_vout->p_buffer[ p_vout->i_buffer_index ].p_data +
1852 i_x * p_vout->i_bytes_per_pixel + (i_y + 16) * p_vout->i_bytes_per_line,
1853 p_vout->i_bytes_per_pixel, p_vout->i_bytes_per_line,
1854 p_vout->i_white_pixel, p_vout->i_gray_pixel, 0,
1855 WIDE_TEXT | OUTLINED_TEXT, psz_wtext, (i_amount/5)%110 );
1858 SetBufferArea( p_vout, i_x, i_y, i_width, i_height * 2 );
1865 /*****************************************************************************
1866 * RenderInfo: render additionnal information
1867 *****************************************************************************
1868 * This function renders information which do not depend on the current
1870 *****************************************************************************/
1871 static void RenderInfo( vout_thread_t *p_vout )
1874 char psz_buffer[256]; /* string buffer */
1875 int i_ready_pic = 0; /* ready pictures */
1876 int i_reserved_pic = 0; /* reserved pictures */
1877 int i_picture; /* picture index */
1882 * Print thread state in lower left corner
1884 for( i_picture = 0; i_picture < VOUT_MAX_PICTURES; i_picture++ )
1886 switch( p_vout->p_picture[i_picture].i_status )
1888 case RESERVED_PICTURE:
1889 case RESERVED_DATED_PICTURE:
1890 case RESERVED_DISP_PICTURE:
1898 sprintf( psz_buffer, "pic: %d (%d/%d)/%d",
1899 p_vout->i_pictures, i_reserved_pic, i_ready_pic, VOUT_MAX_PICTURES );
1900 Print( p_vout, 0, 0, LEFT_RALIGN, BOTTOM_RALIGN, psz_buffer );
1904 /*****************************************************************************
1905 * RenderSubPicture: render a subpicture
1906 *****************************************************************************
1907 * This function renders a sub picture unit.
1908 *****************************************************************************/
1909 static void RenderSubPicture( vout_thread_t *p_vout, subpicture_t *p_subpic )
1911 p_vout_font_t p_font; /* text font */
1912 int i_width, i_height; /* subpicture dimensions */
1914 while( p_subpic != NULL )
1916 switch( p_subpic->i_type )
1918 case DVD_SUBPICTURE: /* DVD subpicture unit */
1919 /* test if the picture really has to be displayed */
1920 if( mdate() < p_subpic->begin_date )
1922 /* not yet, see you later */
1925 if( mdate() > p_subpic->end_date )
1927 /* too late, destroying the subpic */
1928 vout_DestroySubPicture( p_vout, p_subpic );
1931 vout_RenderSPU( &p_vout->p_buffer[ p_vout->i_buffer_index ],
1932 p_subpic, p_vout->i_bytes_per_pixel,
1933 p_vout->i_bytes_per_line );
1935 case TEXT_SUBPICTURE: /* single line text */
1936 /* Select default font if not specified */
1937 p_font = p_subpic->type.text.p_font;
1938 if( p_font == NULL )
1940 p_font = p_vout->p_default_font;
1943 /* Compute text size (width and height fields are ignored)
1945 vout_TextSize( p_font, p_subpic->type.text.i_style,
1946 p_subpic->p_data, &i_width, &i_height );
1947 if( !Align( p_vout, &p_subpic->i_x, &p_subpic->i_y,
1948 i_width, i_height, p_subpic->i_horizontal_align,
1949 p_subpic->i_vertical_align ) )
1952 p_vout->p_buffer[ p_vout->i_buffer_index ].p_data +
1953 p_subpic->i_x * p_vout->i_bytes_per_pixel +
1954 p_subpic->i_y * p_vout->i_bytes_per_line,
1955 p_vout->i_bytes_per_pixel, p_vout->i_bytes_per_line,
1956 p_subpic->type.text.i_char_color,
1957 p_subpic->type.text.i_border_color,
1958 p_subpic->type.text.i_bg_color,
1959 p_subpic->type.text.i_style, p_subpic->p_data, 100 );
1960 SetBufferArea( p_vout, p_subpic->i_x, p_subpic->i_y,
1961 i_width, i_height );
1967 intf_DbgMsg( "error: unknown subpicture %p type %d\n",
1968 p_subpic, p_subpic->i_type );
1972 p_subpic = p_subpic->p_next;
1976 /*****************************************************************************
1977 * RenderInterface: render the interface
1978 *****************************************************************************
1979 * This function renders the interface, if any.
1980 *****************************************************************************/
1981 static void RenderInterface( vout_thread_t *p_vout )
1983 int i_height, i_text_height; /* total and text height */
1984 int i_width_1, i_width_2; /* text width */
1985 int i_byte; /* byte index */
1986 const char *psz_text_1 = "[1-9] Channel [i]nfo [c]olor [g/G]amma";
1987 const char *psz_text_2 = "[+/-] Volume [m]ute [s]caling [Q]uit";
1990 vout_TextSize( p_vout->p_large_font, OUTLINED_TEXT, psz_text_1, &i_width_1, &i_height );
1991 vout_TextSize( p_vout->p_large_font, OUTLINED_TEXT, psz_text_2, &i_width_2, &i_text_height );
1992 i_height += i_text_height;
1994 /* Render background */
1995 for( i_byte = (p_vout->i_height - i_height) * p_vout->i_bytes_per_line;
1996 i_byte < p_vout->i_height * p_vout->i_bytes_per_line;
2000 p_vout->p_buffer[ p_vout->i_buffer_index ].p_data[ i_byte ] = p_vout->i_blue_pixel;
2003 /* Render text, if not larger than screen */
2004 if( i_width_1 < p_vout->i_width )
2006 vout_Print( p_vout->p_large_font, p_vout->p_buffer[ p_vout->i_buffer_index ].p_data +
2007 (p_vout->i_height - i_height) * p_vout->i_bytes_per_line,
2008 p_vout->i_bytes_per_pixel, p_vout->i_bytes_per_line,
2009 p_vout->i_white_pixel, p_vout->i_black_pixel, 0,
2010 OUTLINED_TEXT, psz_text_1, 100 );
2012 if( i_width_2 < p_vout->i_width )
2014 vout_Print( p_vout->p_large_font, p_vout->p_buffer[ p_vout->i_buffer_index ].p_data +
2015 (p_vout->i_height - i_height + i_text_height) * p_vout->i_bytes_per_line,
2016 p_vout->i_bytes_per_pixel, p_vout->i_bytes_per_line,
2017 p_vout->i_white_pixel, p_vout->i_black_pixel, 0,
2018 OUTLINED_TEXT, psz_text_2, 100 );
2021 /* Activate modified area */
2022 SetBufferArea( p_vout, 0, p_vout->i_height - i_height, p_vout->i_width, i_height );
2025 /*****************************************************************************
2026 * Manage: manage thread
2027 *****************************************************************************
2028 * This function will handle changes in thread configuration.
2029 *****************************************************************************/
2030 static int Manage( vout_thread_t *p_vout )
2033 if( p_vout->i_changes )
2035 intf_DbgMsg("changes: 0x%x (no display: 0x%x)\n", p_vout->i_changes,
2036 0 /* p_vout->i_changes & VOUT_NODISPLAY_CHANGE */ );
2040 /* On gamma or grayscale change, rebuild tables */
2041 if( p_vout->i_changes & (VOUT_GAMMA_CHANGE | VOUT_GRAYSCALE_CHANGE |
2044 /* Change vdec_DecodeMacroblock when switching between BW and C */
2045 if( !p_vout->b_grayscale )
2047 p_vout->vdec_DecodeMacroblock = vdec_DecodeMacroblockC;
2049 else if( p_vout->b_grayscale)
2051 p_vout->vdec_DecodeMacroblock = vdec_DecodeMacroblockBW;
2053 if( vout_ResetYUV( p_vout ) )
2055 intf_ErrMsg("error: can't rebuild convertion tables\n");
2060 /* Clear changes flags which does not need management or have been
2062 p_vout->i_changes &= ~(VOUT_GAMMA_CHANGE | VOUT_GRAYSCALE_CHANGE |
2063 VOUT_YUV_CHANGE | VOUT_INFO_CHANGE |
2064 VOUT_INTF_CHANGE | VOUT_SCALE_CHANGE );
2066 /* Detect unauthorized changes */
2067 if( p_vout->i_changes )
2069 /* Some changes were not acknowledged by p_vout->p_sys_manage or this
2070 * function, it means they should not be authorized */
2071 intf_ErrMsg( "error: unauthorized changes in the video output thread\n" );
2078 /*****************************************************************************
2079 * Align: align a subpicture in the screen
2080 *****************************************************************************
2081 * This function is used for rendering text or subpictures. It returns non 0
2082 * it the final aera is not fully included in display area. Return coordinates
2084 *****************************************************************************/
2085 static int Align( vout_thread_t *p_vout, int *pi_x, int *pi_y,
2086 int i_width, int i_height, int i_h_align, int i_v_align )
2088 /* Align horizontally */
2092 *pi_x -= i_width / 2;
2095 *pi_x += (p_vout->i_width - i_width) / 2;
2101 *pi_x += p_vout->i_width - i_width;
2105 /* Align vertically */
2109 *pi_y -= i_height / 2;
2112 *pi_y += (p_vout->i_height - i_height) / 2;
2118 *pi_y += p_vout->i_height - i_height;
2120 case SUBTITLE_RALIGN:
2121 *pi_y += (p_vout->i_height + p_vout->p_buffer[ p_vout->i_buffer_index ].i_pic_y +
2122 p_vout->p_buffer[ p_vout->i_buffer_index ].i_pic_height - i_height) / 2;
2126 /* Return non 0 if clipping failed */
2127 return( (*pi_x < 0) || (*pi_y < 0) ||
2128 (*pi_x + i_width > p_vout->i_width) || (*pi_y + i_height > p_vout->i_height) );
2131 /*****************************************************************************
2132 * SetPalette: sets an 8 bpp palette
2133 *****************************************************************************
2134 * This function is just a prototype that does nothing. Architectures that
2135 * support palette allocation should override it.
2136 *****************************************************************************/
2137 static void SetPalette ( p_vout_thread_t p_vout, u16 *red,
2138 u16 *green, u16 *blue, u16 *transp )
2140 intf_ErrMsg( "SetPalette: method does not support palette changing\n" );