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
8 * $Id: video_output.c,v 1.141 2001/10/01 16:18:49 massiot Exp $
10 * Authors: Vincent Seguin <seguin@via.ecp.fr>
12 * This program is free software; you can redistribute it and/or modify
13 * it under the terms of the GNU General Public License as published by
14 * the Free Software Foundation; either version 2 of the License, or
15 * (at your option) any later version.
17 * This program is distributed in the hope that it will be useful,
18 * but WITHOUT ANY WARRANTY; without even the implied warranty of
19 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 * GNU General Public License for more details.
22 * You should have received a copy of the GNU General Public License
23 * along with this program; if not, write to the Free Software
24 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111, USA.
25 *****************************************************************************/
27 /*****************************************************************************
29 *****************************************************************************/
32 #include <errno.h> /* ENOMEM */
33 #include <stdlib.h> /* free() */
34 #include <stdio.h> /* sprintf() */
35 #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"
55 /*****************************************************************************
57 *****************************************************************************/
58 static int BinaryLog ( u32 i );
59 static void MaskToShift ( int *pi_left, int *pi_right, u32 i_mask );
60 static int InitThread ( vout_thread_t *p_vout );
61 static void RunThread ( vout_thread_t *p_vout );
62 static void ErrorThread ( vout_thread_t *p_vout );
63 static void EndThread ( vout_thread_t *p_vout );
64 static void DestroyThread ( vout_thread_t *p_vout, int i_status );
65 static void Print ( vout_thread_t *p_vout, int i_x, int i_y,
66 int i_h_align, int i_v_align,
67 unsigned char *psz_text );
68 static void SetBuffers ( vout_thread_t *p_vout, void *, void * );
69 static void SetBufferArea ( vout_thread_t *p_vout, int i_x, int i_y,
71 static void SetBufferPicture ( vout_thread_t *p_vout, picture_t *p_pic );
72 static void RenderPicture ( vout_thread_t *p_vout, picture_t *p_pic );
73 static void RenderPictureInfo ( vout_thread_t *p_vout, picture_t *p_pic );
74 static void RenderSubPicture ( vout_thread_t *p_vout, picture_t *p_pic,
75 subpicture_t *p_subpic );
76 static int RenderIdle ( vout_thread_t *p_vout );
77 static void RenderInfo ( vout_thread_t *p_vout );
78 static int Manage ( vout_thread_t *p_vout );
79 static int Align ( vout_thread_t *p_vout, int *pi_x,
80 int *pi_y, int i_width, int i_height,
81 int i_h_align, int i_v_align );
82 static void SetPalette ( p_vout_thread_t p_vout, u16 *red,
83 u16 *green, u16 *blue, u16 *transp );
85 /*****************************************************************************
86 * vout_InitBank: initialize the video output bank.
87 *****************************************************************************/
88 void vout_InitBank ( void )
90 p_vout_bank->i_count = 0;
92 vlc_mutex_init( &p_vout_bank->lock );
95 /*****************************************************************************
96 * vout_EndBank: empty the video output bank.
97 *****************************************************************************
98 * This function ends all unused video outputs and empties the bank in
100 *****************************************************************************/
101 void vout_EndBank ( void )
103 /* Ask all remaining video outputs to die */
104 while( p_vout_bank->i_count )
107 p_vout_bank->pp_vout[ --p_vout_bank->i_count ], NULL );
110 vlc_mutex_destroy( &p_vout_bank->lock );
113 /*****************************************************************************
114 * vout_CreateThread: creates a new video output thread
115 *****************************************************************************
116 * This function creates a new video output thread, and returns a pointer
117 * to its description. On error, it returns NULL.
118 * If pi_status is NULL, then the function will block until the thread is ready.
119 * If not, it will be updated using one of the THREAD_* constants.
120 *****************************************************************************/
121 vout_thread_t * vout_CreateThread ( int *pi_status, int i_width, int i_height )
123 vout_thread_t * p_vout; /* thread descriptor */
124 int i_status; /* thread status */
125 int i_index; /* index for array initialization */
127 /* Allocate descriptor */
128 p_vout = (vout_thread_t *) malloc( sizeof(vout_thread_t) );
131 intf_ErrMsg( "vout error: vout thread creation returned %s",
136 /* Choose the best module */
137 p_vout->p_module = module_Need( MODULE_CAPABILITY_VOUT, NULL );
139 if( p_vout->p_module == NULL )
141 intf_ErrMsg( "vout error: no suitable vout module" );
146 #define f p_vout->p_module->p_functions->vout.functions.vout
147 p_vout->pf_create = f.pf_create;
148 p_vout->pf_init = f.pf_init;
149 p_vout->pf_end = f.pf_end;
150 p_vout->pf_destroy = f.pf_destroy;
151 p_vout->pf_manage = f.pf_manage;
152 p_vout->pf_display = f.pf_display;
153 p_vout->pf_setpalette = f.pf_setpalette;
156 /* Initialize callbacks */
157 p_vout->pf_setbuffers = SetBuffers;
159 if( p_vout->pf_setpalette == NULL )
161 p_vout->pf_setpalette = SetPalette;
164 /* Initialize thread properties - thread id and locks will be initialized
168 p_vout->b_active = 0;
169 p_vout->pi_status = (pi_status != NULL) ? pi_status : &i_status;
170 *p_vout->pi_status = THREAD_CREATE;
172 /* Initialize some fields used by the system-dependant method - these
173 * fields will probably be modified by the method, and are only
175 p_vout->i_changes = 0;
176 p_vout->i_width = main_GetIntVariable( VOUT_WIDTH_VAR, 0 );
177 if( !p_vout->i_width )
179 p_vout->i_width = i_width ? i_width : VOUT_WIDTH_DEFAULT;
181 p_vout->i_height = main_GetIntVariable( VOUT_HEIGHT_VAR, 0 );
182 if( !p_vout->i_height )
184 p_vout->i_height = i_height ? i_height : VOUT_HEIGHT_DEFAULT;
186 p_vout->i_bytes_per_line = p_vout->i_width * 2;
187 p_vout->i_screen_depth = main_GetIntVariable( VOUT_DEPTH_VAR,
188 VOUT_DEPTH_DEFAULT );
189 p_vout->i_bytes_per_pixel = 2;
190 p_vout->f_gamma = VOUT_GAMMA_DEFAULT; // FIXME: replace with
192 p_vout->b_need_render = 1;
195 p_vout->b_grayscale = main_GetIntVariable( VOUT_GRAYSCALE_VAR,
196 VOUT_GRAYSCALE_DEFAULT );
198 p_vout->b_interface = 0;
200 p_vout->b_fullscreen = main_GetIntVariable( VOUT_FULLSCREEN_VAR,
201 VOUT_FULLSCREEN_DEFAULT );
203 intf_WarnMsg( 3, "vout info: asking for %dx%d, %d/%d bpp (%d Bpl)",
204 p_vout->i_width, p_vout->i_height, p_vout->i_screen_depth,
205 p_vout->i_bytes_per_pixel * 8, p_vout->i_bytes_per_line );
207 /* Initialize idle screen */
208 p_vout->last_display_date = 0;
209 p_vout->last_idle_date = 0;
210 p_vout->init_display_date = mdate();
211 p_vout->render_time = 10000;
213 /* Initialize statistics fields */
214 p_vout->c_fps_samples = 0;
215 p_vout->c_pictures = 0;
216 p_vout->c_late_pictures = 0;
217 p_vout->c_jitter_samples = 0;
218 p_vout->display_jitter = 0;
221 /* Initialize buffer index */
222 p_vout->i_buffer_index = 0;
224 /* Initialize fonts */
225 p_vout->p_default_font = NULL;
226 p_vout->p_large_font = NULL;
228 /* Initialize pictures and subpictures - translation tables and functions
229 * will be initialized later in InitThread */
230 for( i_index = 0; i_index < VOUT_MAX_PICTURES; i_index++)
232 p_vout->p_picture[i_index].i_type = EMPTY_PICTURE;
233 p_vout->p_picture[i_index].i_status = FREE_PICTURE;
236 for( i_index = 0; i_index < VOUT_MAX_SUBPICTURES; i_index++)
238 p_vout->p_subpicture[i_index].i_type = EMPTY_SUBPICTURE;
239 p_vout->p_subpicture[i_index].i_status = FREE_SUBPICTURE;
242 p_vout->i_pictures = 0;
244 /* Create thread and set locks */
245 vlc_mutex_init( &p_vout->picture_lock );
246 vlc_mutex_init( &p_vout->subpicture_lock );
247 vlc_mutex_init( &p_vout->change_lock );
249 if( vlc_thread_create( &p_vout->thread_id, "video output",
250 (void *) RunThread, (void *) p_vout) )
252 intf_ErrMsg("vout error: %s", strerror(ENOMEM));
253 module_Unneed( p_vout->p_module );
258 /* If status is NULL, wait until the thread is created */
259 if( pi_status == NULL )
263 msleep( THREAD_SLEEP );
264 }while( (i_status != THREAD_READY) && (i_status != THREAD_ERROR)
265 && (i_status != THREAD_FATAL) );
266 if( i_status != THREAD_READY )
274 /*****************************************************************************
275 * vout_DestroyThread: destroys a previously created thread
276 *****************************************************************************
277 * Destroy a terminated thread.
278 * The function will request a destruction of the specified thread. If pi_error
279 * is NULL, it will return once the thread is destroyed. Else, it will be
280 * update using one of the THREAD_* constants.
281 *****************************************************************************/
282 void vout_DestroyThread( vout_thread_t *p_vout, int *pi_status )
284 int i_status; /* thread status */
288 p_vout->pi_status = (pi_status != NULL) ? pi_status : &i_status;
289 *p_vout->pi_status = THREAD_DESTROY;
291 /* Request thread destruction */
294 /* If status is NULL, wait until thread has been destroyed */
295 if( pi_status == NULL )
299 msleep( THREAD_SLEEP );
300 } while( (i_status != THREAD_OVER) && (i_status != THREAD_ERROR)
301 && (i_status != THREAD_FATAL) );
305 /*****************************************************************************
306 * vout_DisplaySubPicture: display a subpicture unit
307 *****************************************************************************
308 * Remove the reservation flag of a subpicture, which will cause it to be ready
309 * for display. The picture does not need to be locked, since it is ignored by
310 * the output thread if is reserved.
311 *****************************************************************************/
312 void vout_DisplaySubPicture( vout_thread_t *p_vout, subpicture_t *p_subpic )
315 char psz_start[ MSTRTIME_MAX_SIZE ]; /* buffer for date string */
316 char psz_stop[ MSTRTIME_MAX_SIZE ]; /* buffer for date string */
320 /* Check if status is valid */
321 if( p_subpic->i_status != RESERVED_SUBPICTURE )
323 intf_ErrMsg("error: subpicture %p has invalid status %d", p_subpic,
324 p_subpic->i_status );
328 /* Remove reservation flag */
329 p_subpic->i_status = READY_SUBPICTURE;
332 /* Send subpicture information */
333 intf_DbgMsg("subpicture %p: type=%d, begin date=%s, end date=%s",
334 p_subpic, p_subpic->i_type,
335 mstrtime( psz_start, p_subpic->i_start ),
336 mstrtime( psz_stop, p_subpic->i_stop ) );
340 /*****************************************************************************
341 * vout_CreateSubPicture: allocate a subpicture in the video output heap.
342 *****************************************************************************
343 * This function create a reserved subpicture in the video output heap.
344 * A null pointer is returned if the function fails. This method provides an
345 * already allocated zone of memory in the spu data fields. It needs locking
346 * since several pictures can be created by several producers threads.
347 *****************************************************************************/
348 subpicture_t *vout_CreateSubPicture( vout_thread_t *p_vout, int i_type,
351 int i_subpic; /* subpicture index */
352 subpicture_t * p_free_subpic = NULL; /* first free subpicture */
353 subpicture_t * p_destroyed_subpic = NULL; /* first destroyed subpic */
356 vlc_mutex_lock( &p_vout->subpicture_lock );
359 * Look for an empty place
361 for( i_subpic = 0; i_subpic < VOUT_MAX_SUBPICTURES; i_subpic++ )
363 if( p_vout->p_subpicture[i_subpic].i_status == DESTROYED_SUBPICTURE )
365 /* Subpicture is marked for destruction, but is still allocated */
366 if( (p_vout->p_subpicture[i_subpic].i_type == i_type) &&
367 (p_vout->p_subpicture[i_subpic].i_size >= i_size) )
369 /* Memory size do match or is smaller : memory will not be
370 * reallocated, and function can end immediately - this is
371 * the best possible case, since no memory allocation needs
373 p_vout->p_subpicture[i_subpic].i_status = RESERVED_SUBPICTURE;
375 intf_DbgMsg("subpicture %p (in destroyed subpicture slot)",
376 &p_vout->p_subpicture[i_subpic] );
378 vlc_mutex_unlock( &p_vout->subpicture_lock );
379 return( &p_vout->p_subpicture[i_subpic] );
381 else if( p_destroyed_subpic == NULL )
383 /* Memory size do not match, but subpicture index will be kept
384 * in case we find no other place */
385 p_destroyed_subpic = &p_vout->p_subpicture[i_subpic];
388 else if( (p_free_subpic == NULL) &&
389 (p_vout->p_subpicture[i_subpic].i_status == FREE_SUBPICTURE ))
391 /* Subpicture is empty and ready for allocation */
392 p_free_subpic = &p_vout->p_subpicture[i_subpic];
396 /* If no free subpictures are available, use a destroyed subpicture */
397 if( (p_free_subpic == NULL) && (p_destroyed_subpic != NULL ) )
399 /* No free subpicture or matching destroyed subpictures have been
400 * found, but a destroyed subpicture is still avalaible */
401 free( p_destroyed_subpic->p_data );
402 p_free_subpic = p_destroyed_subpic;
408 if( p_free_subpic != NULL )
410 /* Allocate memory */
413 case TEXT_SUBPICTURE: /* text subpicture */
414 p_free_subpic->p_data = memalign( 16, i_size + 1 );
416 case DVD_SUBPICTURE: /* DVD subpicture unit */
417 p_free_subpic->p_data = memalign( 16, i_size );
421 intf_ErrMsg("error: unknown subpicture type %d", i_type );
422 p_free_subpic->p_data = NULL;
427 if( p_free_subpic->p_data != NULL )
429 /* Copy subpicture information, set some default values */
430 p_free_subpic->i_type = i_type;
431 p_free_subpic->i_status = RESERVED_SUBPICTURE;
432 p_free_subpic->i_size = i_size;
433 p_free_subpic->i_x = 0;
434 p_free_subpic->i_y = 0;
435 p_free_subpic->i_width = 0;
436 p_free_subpic->i_height = 0;
437 p_free_subpic->i_horizontal_align = CENTER_RALIGN;
438 p_free_subpic->i_vertical_align = CENTER_RALIGN;
442 /* Memory allocation failed : set subpicture as empty */
443 p_free_subpic->i_type = EMPTY_SUBPICTURE;
444 p_free_subpic->i_status = FREE_SUBPICTURE;
445 p_free_subpic = NULL;
446 intf_ErrMsg( "vout error: spu allocation returned %s",
447 strerror( ENOMEM ) );
451 intf_DbgMsg("subpicture %p (in free subpicture slot)", p_free_subpic );
453 vlc_mutex_unlock( &p_vout->subpicture_lock );
454 return( p_free_subpic );
457 /* No free or destroyed subpicture could be found */
458 intf_DbgMsg( "warning: subpicture heap is full" );
459 vlc_mutex_unlock( &p_vout->subpicture_lock );
463 /*****************************************************************************
464 * vout_DestroySubPicture: remove a subpicture from the heap
465 *****************************************************************************
466 * This function frees a previously reserved subpicture.
467 * It is meant to be used when the construction of a picture aborted.
468 * This function does not need locking since reserved subpictures are ignored
469 * by the output thread.
470 *****************************************************************************/
471 void vout_DestroySubPicture( vout_thread_t *p_vout, subpicture_t *p_subpic )
474 /* Check if status is valid */
475 if( p_subpic->i_status != RESERVED_SUBPICTURE )
477 intf_ErrMsg("error: subpicture %p has invalid status %d",
478 p_subpic, p_subpic->i_status );
482 p_subpic->i_status = DESTROYED_SUBPICTURE;
485 intf_DbgMsg("subpicture %p", p_subpic);
489 /*****************************************************************************
490 * vout_DisplayPicture: display a picture
491 *****************************************************************************
492 * Remove the reservation flag of a picture, which will cause it to be ready for
493 * display. The picture won't be displayed until vout_DatePicture has been
495 *****************************************************************************/
496 void vout_DisplayPicture( vout_thread_t *p_vout, picture_t *p_pic )
498 vlc_mutex_lock( &p_vout->picture_lock );
499 switch( p_pic->i_status )
501 case RESERVED_PICTURE:
502 p_pic->i_status = RESERVED_DISP_PICTURE;
504 case RESERVED_DATED_PICTURE:
505 p_pic->i_status = READY_PICTURE;
509 intf_ErrMsg("error: picture %p has invalid status %d", p_pic, p_pic->i_status );
515 intf_DbgMsg("picture %p", p_pic);
517 vlc_mutex_unlock( &p_vout->picture_lock );
520 /*****************************************************************************
521 * vout_DatePicture: date a picture
522 *****************************************************************************
523 * Remove the reservation flag of a picture, which will cause it to be ready for
524 * display. The picture won't be displayed until vout_DisplayPicture has been
526 *****************************************************************************/
527 void vout_DatePicture( vout_thread_t *p_vout, picture_t *p_pic, mtime_t date )
530 char psz_date[MSTRTIME_MAX_SIZE]; /* date */
533 vlc_mutex_lock( &p_vout->picture_lock );
535 switch( p_pic->i_status )
537 case RESERVED_PICTURE:
538 p_pic->i_status = RESERVED_DATED_PICTURE;
540 case RESERVED_DISP_PICTURE:
541 p_pic->i_status = READY_PICTURE;
545 intf_ErrMsg("error: picture %p has invalid status %d", p_pic, p_pic->i_status );
551 intf_DbgMsg("picture %p, display date: %s", p_pic, mstrtime( psz_date, p_pic->date) );
553 vlc_mutex_unlock( &p_vout->picture_lock );
556 /*****************************************************************************
557 * vout_CreatePicture: allocate a picture in the video output heap.
558 *****************************************************************************
559 * This function create a reserved image in the video output heap.
560 * A null pointer is returned if the function fails. This method provides an
561 * already allocated zone of memory in the picture data fields. It needs locking
562 * since several pictures can be created by several producers threads.
563 *****************************************************************************/
564 picture_t *vout_CreatePicture( vout_thread_t *p_vout, int i_type,
565 int i_width, int i_height )
567 int i_picture; /* picture index */
568 int i_chroma_width = 0; /* chroma width */
569 picture_t * p_free_picture = NULL; /* first free picture */
570 picture_t * p_destroyed_picture = NULL; /* first destroyed picture */
573 vlc_mutex_lock( &p_vout->picture_lock );
576 * Look for an empty place
578 for( i_picture = 0; i_picture < VOUT_MAX_PICTURES; i_picture++ )
580 if( p_vout->p_picture[i_picture].i_status == DESTROYED_PICTURE )
582 /* Picture is marked for destruction, but is still allocated - note
583 * that if width and type are the same for two pictures, chroma_width
584 * should also be the same */
585 if( (p_vout->p_picture[i_picture].i_type == i_type) &&
586 (p_vout->p_picture[i_picture].i_height == i_height) &&
587 (p_vout->p_picture[i_picture].i_width == i_width) )
589 /* Memory size do match : memory will not be reallocated, and function
590 * can end immediately - this is the best possible case, since no
591 * memory allocation needs to be done */
592 p_vout->p_picture[i_picture].i_status = RESERVED_PICTURE;
593 p_vout->i_pictures++;
595 intf_DbgMsg("picture %p (in destroyed picture slot)",
596 &p_vout->p_picture[i_picture] );
598 vlc_mutex_unlock( &p_vout->picture_lock );
599 return( &p_vout->p_picture[i_picture] );
601 else if( p_destroyed_picture == NULL )
603 /* Memory size do not match, but picture index will be kept in
604 * case no other place are left */
605 p_destroyed_picture = &p_vout->p_picture[i_picture];
608 else if( (p_free_picture == NULL) &&
609 (p_vout->p_picture[i_picture].i_status == FREE_PICTURE ))
611 /* Picture is empty and ready for allocation */
612 p_free_picture = &p_vout->p_picture[i_picture];
616 /* If no free picture is available, use a destroyed picture */
617 if( (p_free_picture == NULL) && (p_destroyed_picture != NULL ) )
619 /* No free picture or matching destroyed picture has been found, but
620 * a destroyed picture is still avalaible */
621 free( p_destroyed_picture->p_data );
622 p_free_picture = p_destroyed_picture;
628 if( p_free_picture != NULL )
630 /* Allocate memory */
633 case YUV_420_PICTURE: /* YUV 420: 1,1/4,1/4 samples per pixel */
634 i_chroma_width = i_width / 2;
635 p_free_picture->p_data = memalign( 16, i_height * i_chroma_width
636 * 3 * sizeof( yuv_data_t ) );
637 p_free_picture->p_y = (yuv_data_t *)p_free_picture->p_data;
638 p_free_picture->p_u = (yuv_data_t *)p_free_picture->p_data +i_height*i_chroma_width*4/2;
639 p_free_picture->p_v = (yuv_data_t *)p_free_picture->p_data +i_height*i_chroma_width*5/2;
641 case YUV_422_PICTURE: /* YUV 422: 1,1/2,1/2 samples per pixel */
642 i_chroma_width = i_width / 2;
643 p_free_picture->p_data = memalign( 16, i_height * i_chroma_width
644 * 4 * sizeof( yuv_data_t ) );
645 p_free_picture->p_y = (yuv_data_t *)p_free_picture->p_data;
646 p_free_picture->p_u = (yuv_data_t *)p_free_picture->p_data +i_height*i_chroma_width*2;
647 p_free_picture->p_v = (yuv_data_t *)p_free_picture->p_data +i_height*i_chroma_width*3;
649 case YUV_444_PICTURE: /* YUV 444: 1,1,1 samples per pixel */
650 i_chroma_width = i_width;
651 p_free_picture->p_data = memalign( 16, i_height * i_chroma_width
652 * 3 * sizeof( yuv_data_t ) );
653 p_free_picture->p_y = (yuv_data_t *)p_free_picture->p_data;
654 p_free_picture->p_u = (yuv_data_t *)p_free_picture->p_data +i_height*i_chroma_width;
655 p_free_picture->p_v = (yuv_data_t *)p_free_picture->p_data +i_height*i_chroma_width*2;
659 intf_ErrMsg("error: unknown picture type %d", i_type );
660 p_free_picture->p_data = NULL;
665 if( p_free_picture->p_data != NULL )
667 /* Copy picture information, set some default values */
668 p_free_picture->i_type = i_type;
669 p_free_picture->i_status = RESERVED_PICTURE;
670 p_free_picture->i_matrix_coefficients = 1;
671 p_free_picture->i_width = i_width;
672 p_free_picture->i_height = i_height;
673 p_free_picture->i_chroma_width = i_chroma_width;
674 p_free_picture->i_size = i_width * i_height;
675 p_free_picture->i_chroma_size = i_chroma_width
677 p_free_picture->i_display_horizontal_offset = 0;
678 p_free_picture->i_display_vertical_offset = 0;
679 p_free_picture->i_display_width = i_width;
680 p_free_picture->i_display_height = i_height;
681 p_free_picture->i_aspect_ratio = AR_SQUARE_PICTURE;
682 p_free_picture->i_refcount = 0;
683 p_vout->i_pictures++;
687 /* Memory allocation failed : set picture as empty */
688 p_free_picture->i_type = EMPTY_PICTURE;
689 p_free_picture->i_status = FREE_PICTURE;
690 p_free_picture = NULL;
691 intf_ErrMsg( "vout error: picture allocation returned %s",
692 strerror( ENOMEM ) );
696 intf_DbgMsg("picture %p (in free picture slot)", p_free_picture );
698 vlc_mutex_unlock( &p_vout->picture_lock );
700 return( p_free_picture );
703 /* No free or destroyed picture could be found */
704 intf_DbgMsg( "warning: picture heap is full" );
705 vlc_mutex_unlock( &p_vout->picture_lock );
709 /*****************************************************************************
710 * vout_DestroyPicture: remove a permanent or reserved picture from the heap
711 *****************************************************************************
712 * This function frees a previously reserved picture or a permanent
713 * picture. It is meant to be used when the construction of a picture aborted.
714 * Note that the picture will be destroyed even if it is linked !
715 *****************************************************************************/
716 void vout_DestroyPicture( vout_thread_t *p_vout, picture_t *p_pic )
718 vlc_mutex_lock( &p_vout->picture_lock );
721 /* Check if picture status is valid */
722 if( (p_pic->i_status != RESERVED_PICTURE) &&
723 (p_pic->i_status != RESERVED_DATED_PICTURE) &&
724 (p_pic->i_status != RESERVED_DISP_PICTURE) )
726 intf_ErrMsg("error: picture %p has invalid status %d", p_pic, p_pic->i_status );
730 p_pic->i_status = DESTROYED_PICTURE;
731 p_vout->i_pictures--;
734 intf_DbgMsg("picture %p", p_pic);
737 vlc_mutex_unlock( &p_vout->picture_lock );
740 /*****************************************************************************
741 * vout_LinkPicture: increment reference counter of a picture
742 *****************************************************************************
743 * This function increment the reference counter of a picture in the video
744 * heap. It needs a lock since several producer threads can access the picture.
745 *****************************************************************************/
746 void vout_LinkPicture( vout_thread_t *p_vout, picture_t *p_pic )
748 vlc_mutex_lock( &p_vout->picture_lock );
752 intf_DbgMsg("picture %p refcount=%d", p_pic, p_pic->i_refcount );
755 vlc_mutex_unlock( &p_vout->picture_lock );
758 /*****************************************************************************
759 * vout_UnlinkPicture: decrement reference counter of a picture
760 *****************************************************************************
761 * This function decrement the reference counter of a picture in the video heap.
762 *****************************************************************************/
763 void vout_UnlinkPicture( vout_thread_t *p_vout, picture_t *p_pic )
765 vlc_mutex_lock( &p_vout->picture_lock );
769 if( p_pic->i_refcount < 0 )
771 intf_DbgMsg("error: refcount < 0");
772 p_pic->i_refcount = 0;
776 if( (p_pic->i_refcount == 0) && (p_pic->i_status == DISPLAYED_PICTURE) )
778 p_pic->i_status = DESTROYED_PICTURE;
779 p_vout->i_pictures--;
783 intf_DbgMsg("picture %p refcount=%d", p_pic, p_pic->i_refcount );
786 vlc_mutex_unlock( &p_vout->picture_lock );
789 /*****************************************************************************
790 * vout_Pixel2RGB: return red, green and blue from pixel value
791 *****************************************************************************
792 * Return color values, in 0-255 range, of the decomposition of a pixel. This
793 * is a slow routine and should only be used for initialization phase.
794 *****************************************************************************/
795 void vout_Pixel2RGB( vout_thread_t *p_vout, u32 i_pixel, int *pi_red, int *pi_green, int *pi_blue )
797 *pi_red = i_pixel & p_vout->i_red_mask;
798 *pi_green = i_pixel & p_vout->i_green_mask;
799 *pi_blue = i_pixel & p_vout->i_blue_mask;
802 /* following functions are local */
804 /*****************************************************************************
805 * BinaryLog: computes the base 2 log of a binary value
806 *****************************************************************************
807 * This functions is used by MaskToShift, to get a bit index from a binary
809 *****************************************************************************/
810 static int BinaryLog(u32 i)
835 if (i != ((u32)1 << i_log))
837 intf_DbgMsg("internal error: binary log overflow");
843 /*****************************************************************************
844 * MaskToShift: transform a color mask into right and left shifts
845 *****************************************************************************
846 * This function is used for obtaining color shifts from masks.
847 *****************************************************************************/
848 static void MaskToShift( int *pi_left, int *pi_right, u32 i_mask )
850 u32 i_low, i_high; /* lower hand higher bits of the mask */
853 i_low = i_mask & (- i_mask); /* lower bit of the mask */
854 i_high = i_mask + i_low; /* higher bit of the mask */
856 /* Transform bits into an index */
857 i_low = BinaryLog (i_low);
858 i_high = BinaryLog (i_high);
860 /* Update pointers and return */
862 *pi_right = (8 - i_high + i_low);
865 /*****************************************************************************
866 * InitThread: initialize video output thread
867 *****************************************************************************
868 * This function is called from RunThread and performs the second step of the
869 * initialization. It returns 0 on success. Note that the thread's flag are not
870 * modified inside this function.
871 *****************************************************************************/
872 static int InitThread( vout_thread_t *p_vout )
875 *p_vout->pi_status = THREAD_START;
877 vlc_mutex_lock( &p_vout->change_lock );
879 /* Create and initialize system-dependant method - this function issues its
880 * own error messages */
881 if( p_vout->pf_create( p_vout ) )
883 /* If pf_create has failed then we have to make sure
884 * pf_destroy won't be called, because the plugin should have
885 * cleaned up all its mess */
886 p_vout->pf_destroy = NULL;
890 intf_WarnMsg( 1, "vout: video display initialized (%dx%d, %d/%d bpp)",
891 p_vout->i_width, p_vout->i_height, p_vout->i_screen_depth,
892 p_vout->i_bytes_per_pixel * 8 );
894 intf_WarnMsg( 3, "vout info: got %dx%d, %d/%d bpp (%d Bpl), "
895 "masks: 0x%x/0x%x/0x%x",
896 p_vout->i_width, p_vout->i_height, p_vout->i_screen_depth,
897 p_vout->i_bytes_per_pixel * 8, p_vout->i_bytes_per_line,
898 p_vout->i_red_mask, p_vout->i_green_mask,
899 p_vout->i_blue_mask );
901 /* Calculate shifts from system-updated masks */
902 MaskToShift( &p_vout->i_red_lshift, &p_vout->i_red_rshift,
903 p_vout->i_red_mask );
904 MaskToShift( &p_vout->i_green_lshift, &p_vout->i_green_rshift,
905 p_vout->i_green_mask );
906 MaskToShift( &p_vout->i_blue_lshift, &p_vout->i_blue_rshift,
907 p_vout->i_blue_mask );
909 /* Set some useful colors */
910 p_vout->i_white_pixel = RGB2PIXEL( p_vout, 255, 255, 255 );
911 p_vout->i_black_pixel = RGB2PIXEL( p_vout, 0, 0, 0 );
912 p_vout->i_gray_pixel = RGB2PIXEL( p_vout, 128, 128, 128 );
913 p_vout->i_blue_pixel = RGB2PIXEL( p_vout, 0, 0, 50 );
915 /* Load fonts - fonts must be initialized after the system method since
916 * they may be dependant on screen depth and other thread properties */
917 p_vout->p_default_font = vout_LoadFont( VOUT_DEFAULT_FONT );
918 if( p_vout->p_default_font == NULL )
920 intf_ErrMsg( "vout error: could not load default font" );
923 p_vout->p_large_font = vout_LoadFont( VOUT_LARGE_FONT );
924 if( p_vout->p_large_font == NULL )
926 intf_ErrMsg( "vout error: could not load large font" );
929 /* Initialize output method. This function issues its own error messages */
930 if( p_vout->pf_init( p_vout ) )
932 /* If pf_init has failed then we have to make sure
933 * pf_destroy won't be called, because the plugin should have
934 * cleaned up all its mess */
935 p_vout->pf_destroy = NULL;
939 /* Initialize convertion tables and functions */
940 if( vout_InitYUV( p_vout ) )
942 intf_ErrMsg("vout error: can't allocate YUV translation tables");
943 p_vout->pf_destroy( p_vout );
944 /* Make sure pf_destroy won't be called again */
945 p_vout->pf_destroy = NULL;
949 /* Mark thread as running and return */
950 p_vout->b_active = 1;
951 *p_vout->pi_status = THREAD_READY;
954 intf_DbgMsg("thread ready");
958 /*****************************************************************************
959 * RunThread: video output thread
960 *****************************************************************************
961 * Video output thread. This function does only returns when the thread is
962 * terminated. It handles the pictures arriving in the video heap and the
963 * display device events.
964 *****************************************************************************/
965 static void RunThread( vout_thread_t *p_vout)
967 int i_index; /* index in heap */
968 mtime_t current_date; /* current date */
969 mtime_t display_date; /* display date */
970 boolean_t b_display; /* display flag */
972 picture_t * p_pic; /* picture pointer */
974 subpicture_t * p_subpic; /* subpicture pointer */
975 subpicture_t * p_ephemer; /* youngest ephemer subpicture pointer */
976 mtime_t ephemer_date; /* earliest subpicture date */
981 if( InitThread( p_vout ) )
983 /* Something bad happened */
984 DestroyThread( p_vout, THREAD_ERROR );
988 * Main loop - it is not executed if an error occured during
991 while( (!p_vout->b_die) && (!p_vout->b_error) )
993 /* Initialize loop variables */
994 p_vout->p_rendered_pic = NULL;
1000 current_date = mdate();
1003 if( !(p_vout->c_loops % VOUT_STATS_NB_LOOPS) )
1005 intf_StatMsg( "vout info: picture heap: %d/%d",
1006 p_vout->i_pictures, VOUT_MAX_PICTURES );
1010 * Find the picture to display - this operation does not need lock,
1011 * since only READY_PICTUREs are handled
1013 for( i_index = 0; i_index < VOUT_MAX_PICTURES; i_index++ )
1015 if( (p_vout->p_picture[i_index].i_status == READY_PICTURE) &&
1016 ( (p_pic == NULL) ||
1017 (p_vout->p_picture[i_index].date < display_date) ) )
1019 p_pic = &p_vout->p_picture[i_index];
1020 display_date = p_pic->date;
1026 p_vout->c_pictures++;
1028 /* Computes FPS rate */
1029 p_vout->p_fps_sample[ p_vout->c_fps_samples++ % VOUT_FPS_SAMPLES ] = display_date;
1031 if( display_date < current_date + p_vout->render_time )
1033 /* Picture is late: it will be destroyed and the thread
1034 * will sleep and go to next picture */
1036 vlc_mutex_lock( &p_vout->picture_lock );
1037 if( p_pic->i_refcount )
1039 p_pic->i_status = DISPLAYED_PICTURE;
1043 p_pic->i_status = DESTROYED_PICTURE;
1044 p_vout->i_pictures--;
1046 vlc_mutex_unlock( &p_vout->picture_lock );
1049 "vout warning: late picture skipped (%p)", p_pic );
1050 p_vout->c_late_pictures++;
1054 else if( display_date > current_date + VOUT_DISPLAY_DELAY )
1056 /* A picture is ready to be rendered, but its rendering date
1057 * is far from the current one so the thread will perform an
1058 * empty loop as if no picture were found. The picture state
1066 * Find the subpictures to display - this operation does not need
1067 * lock, since only READY_SUBPICTURE are handled. If no picture
1068 * has been selected, display_date will depend on the subpicture.
1070 * We also check for ephemer DVD subpictures (subpictures that have
1071 * to be removed if a newer one is available), which makes it a lot
1072 * more difficult to guess if a subpicture has to be rendered or not.
1074 * We get an easily parsable chained list of subpictures which
1075 * ends with NULL since p_subpic was initialized to NULL.
1077 for( i_index = 0; i_index < VOUT_MAX_SUBPICTURES; i_index++ )
1079 if( p_vout->p_subpicture[i_index].i_status == READY_SUBPICTURE )
1081 /* If it is a DVD subpicture, check its date */
1082 if( p_vout->p_subpicture[i_index].i_type == DVD_SUBPICTURE )
1084 if( display_date > p_vout->p_subpicture[i_index].i_stop )
1086 /* Too late, destroy the subpic */
1087 vout_DestroySubPicture( p_vout,
1088 &p_vout->p_subpicture[i_index] );
1092 if( display_date < p_vout->p_subpicture[i_index].i_start )
1094 /* Too early, come back next monday */
1098 /* If this is an ephemer subpic, see if it's the
1099 * youngest we have */
1100 if( p_vout->p_subpicture[i_index].b_ephemer )
1102 if( p_ephemer == NULL )
1104 p_ephemer = &p_vout->p_subpicture[i_index];
1108 if( p_vout->p_subpicture[i_index].i_start
1109 < p_ephemer->i_start )
1111 /* Link the previous ephemer subpicture and
1112 * replace it with the current one */
1113 p_ephemer->p_next = p_subpic;
1114 p_subpic = p_ephemer;
1115 p_ephemer = &p_vout->p_subpicture[i_index];
1117 /* If it's the 2nd youngest subpicture,
1118 * register its date */
1120 || ephemer_date > p_subpic->i_start )
1122 ephemer_date = p_subpic->i_start;
1129 p_vout->p_subpicture[i_index].p_next = p_subpic;
1130 p_subpic = &p_vout->p_subpicture[i_index];
1132 /* If it's the 2nd youngest subpicture, register its date */
1133 if( !ephemer_date || ephemer_date > p_subpic->i_start )
1135 ephemer_date = p_subpic->i_start;
1138 /* If it's not a DVD subpicture, just register it */
1141 p_vout->p_subpicture[i_index].p_next = p_subpic;
1142 p_subpic = &p_vout->p_subpicture[i_index];
1147 /* If we found an ephemer subpicture, check if it has to be
1149 if( p_ephemer != NULL )
1151 if( p_ephemer->i_start < ephemer_date )
1153 /* Ephemer subpicture has lived too long */
1154 vout_DestroySubPicture( p_vout, p_ephemer );
1158 /* Ephemer subpicture can still live a bit */
1159 p_ephemer->p_next = p_subpic;
1160 p_subpic = p_ephemer;
1165 * Perform rendering, sleep and display rendered picture
1167 if( p_pic ) /* picture and perhaps subpicture */
1169 b_display = p_vout->b_active;
1170 p_vout->last_display_date = display_date;
1171 p_vout->p_rendered_pic = p_pic;
1173 /* FIXME: if b_need_render == 0 we need to do something with
1174 * the subpictures one day. */
1176 if( p_vout->b_need_render && b_display )
1178 /* Set picture dimensions and clear buffer */
1179 SetBufferPicture( p_vout, p_pic );
1181 /* Render picture and information */
1182 RenderPicture( p_vout, p_pic );
1183 if( p_vout->b_info )
1185 RenderPictureInfo( p_vout, p_pic );
1186 RenderInfo( p_vout );
1189 if( b_display ) /* XXX: quick HACK */
1193 RenderSubPicture( p_vout, p_pic, p_subpic );
1197 else if( p_vout->b_active && p_vout->b_need_render
1198 && p_vout->init_display_date == 0)
1200 /* Idle or interface screen alone */
1202 if( p_vout->b_interface && 0 /* && XXX?? intf_change */ )
1204 /* Interface has changed, so a new rendering is required - force
1205 * it by setting last idle date to 0 */
1206 p_vout->last_idle_date = 0;
1209 /* Render idle screen and update idle date, then render interface if
1211 b_display = RenderIdle( p_vout );
1214 p_vout->last_idle_date = current_date;
1225 * Check for the current time and
1226 * display splash screen if everything is on time
1228 if( p_vout->init_display_date > 0 && p_vout->b_need_render )
1230 p_vout->init_display_date = 0;
1235 * Sleep, wake up and display rendered picture
1238 if( display_date != 0 )
1240 /* Store render time using Bresenham algorithm */
1241 p_vout->render_time += mdate() - current_date;
1242 p_vout->render_time >>= 1;
1245 /* Give back change lock */
1246 vlc_mutex_unlock( &p_vout->change_lock );
1248 /* Sleep a while or until a given date */
1249 if( display_date != 0 )
1251 mwait( display_date - VOUT_MWAIT_TOLERANCE );
1255 msleep( VOUT_IDLE_SLEEP );
1258 /* On awakening, take back lock and send immediately picture to display,
1259 * then swap buffers */
1260 vlc_mutex_lock( &p_vout->change_lock );
1262 intf_DbgMsg( "picture %p, subpicture %p in buffer %d, display=%d", p_pic, p_subpic,
1263 p_vout->i_buffer_index, b_display /* && !(p_vout->i_changes & VOUT_NODISPLAY_CHANGE) */ );
1265 if( b_display /* && !(p_vout->i_changes & VOUT_NODISPLAY_CHANGE) */ )
1269 p_vout->pf_display( p_vout );
1271 p_vout->i_buffer_index = ++p_vout->i_buffer_index & 1;
1274 /* Update statistics */
1275 jitter = display_date - mdate();
1276 if( jitter < 0 ) jitter = -jitter;
1277 p_vout->display_jitter = ((p_vout->display_jitter
1278 * p_vout->c_jitter_samples) + jitter)
1279 / (p_vout->c_jitter_samples + 1);
1280 if( p_vout->c_jitter_samples < MAX_JITTER_SAMPLES )
1282 p_vout->c_jitter_samples++;
1288 /* Remove picture from heap */
1289 vlc_mutex_lock( &p_vout->picture_lock );
1290 if( p_pic->i_refcount )
1292 p_pic->i_status = DISPLAYED_PICTURE;
1296 p_pic->i_status = DESTROYED_PICTURE;
1297 p_vout->i_pictures--;
1299 vlc_mutex_unlock( &p_vout->picture_lock );
1304 * Check events and manage thread
1306 if( p_vout->pf_manage( p_vout ) | Manage( p_vout ) )
1308 /* A fatal error occured, and the thread must terminate immediately
1309 * without displaying anything - setting b_error to 1 cause the
1310 * immediate end of the main while() loop. */
1311 p_vout->b_error = 1;
1316 * Error loop - wait until the thread destruction is requested
1318 if( p_vout->b_error )
1320 ErrorThread( p_vout );
1324 EndThread( p_vout );
1325 DestroyThread( p_vout, THREAD_OVER );
1326 intf_DbgMsg( "thread end" );
1329 /*****************************************************************************
1330 * ErrorThread: RunThread() error loop
1331 *****************************************************************************
1332 * This function is called when an error occured during thread main's loop. The
1333 * thread can still receive feed, but must be ready to terminate as soon as
1335 *****************************************************************************/
1336 static void ErrorThread( vout_thread_t *p_vout )
1338 /* Wait until a `die' order */
1339 while( !p_vout->b_die )
1342 msleep( VOUT_IDLE_SLEEP );
1346 /*****************************************************************************
1347 * EndThread: thread destruction
1348 *****************************************************************************
1349 * This function is called when the thread ends after a sucessful
1350 * initialization. It frees all ressources allocated by InitThread.
1351 *****************************************************************************/
1352 static void EndThread( vout_thread_t *p_vout )
1354 int i_index; /* index in heap */
1357 *p_vout->pi_status = THREAD_END;
1359 if( p_main->b_stats )
1361 struct tms cpu_usage;
1362 times( &cpu_usage );
1364 intf_StatMsg( "vout info: %d loops consuming user: %d, system: %d",
1365 p_vout->c_loops, cpu_usage.tms_utime, cpu_usage.tms_stime );
1366 intf_StatMsg( "vout info: %d pictures received, discarded %d",
1367 p_vout->c_pictures, p_vout->c_late_pictures );
1368 intf_StatMsg( "vout info: average display jitter of %lld µs",
1369 p_vout->display_jitter );
1372 /* Destroy all remaining pictures and subpictures */
1373 for( i_index = 0; i_index < VOUT_MAX_PICTURES; i_index++ )
1375 if( p_vout->p_picture[i_index].i_status != FREE_PICTURE )
1377 free( p_vout->p_picture[i_index].p_data );
1381 for( i_index = 0; i_index < VOUT_MAX_SUBPICTURES; i_index++ )
1383 if( p_vout->p_subpicture[i_index].i_status != FREE_SUBPICTURE )
1385 free( p_vout->p_subpicture[i_index].p_data );
1389 /* Destroy translation tables */
1390 vout_EndYUV( p_vout );
1391 p_vout->pf_end( p_vout );
1393 /* Release the change lock */
1394 vlc_mutex_unlock( &p_vout->change_lock );
1397 /*****************************************************************************
1398 * DestroyThread: thread destruction
1399 *****************************************************************************
1400 * This function is called when the thread ends. It frees all ressources
1401 * allocated by CreateThread. Status is available at this stage.
1402 *****************************************************************************/
1403 static void DestroyThread( vout_thread_t *p_vout, int i_status )
1405 int *pi_status; /* status adress */
1407 /* Store status adress */
1408 pi_status = p_vout->pi_status;
1410 /* Destroy thread structures allocated by Create and InitThread */
1411 vout_UnloadFont( p_vout->p_default_font );
1412 vout_UnloadFont( p_vout->p_large_font );
1413 if( p_vout->pf_destroy != NULL ) p_vout->pf_destroy( p_vout );
1415 /* Destroy the locks */
1416 vlc_mutex_destroy( &p_vout->picture_lock );
1417 vlc_mutex_destroy( &p_vout->subpicture_lock );
1418 vlc_mutex_destroy( &p_vout->change_lock );
1420 /* Release the module */
1421 module_Unneed( p_vout->p_module );
1423 /* Free structure */
1425 *pi_status = i_status;
1428 /*****************************************************************************
1429 * Print: print simple text on a picture
1430 *****************************************************************************
1431 * This function will print a simple text on the picture. It is designed to
1432 * print debugging or general information.
1433 *****************************************************************************/
1434 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 )
1436 int i_text_height; /* total text height */
1437 int i_text_width; /* total text width */
1439 /* Update upper left coordinates according to alignment */
1440 vout_TextSize( p_vout->p_default_font, 0, psz_text, &i_text_width, &i_text_height );
1441 if( !Align( p_vout, &i_x, &i_y, i_text_width, i_text_height, i_h_align, i_v_align ) )
1443 /* Set area and print text */
1444 SetBufferArea( p_vout, i_x, i_y, i_text_width, i_text_height );
1445 vout_Print( p_vout->p_default_font, p_vout->p_buffer[ p_vout->i_buffer_index ].p_data +
1446 i_y * p_vout->i_bytes_per_line + i_x * p_vout->i_bytes_per_pixel,
1447 p_vout->i_bytes_per_pixel, p_vout->i_bytes_per_line,
1448 p_vout->i_white_pixel, 0, 0,
1453 /*****************************************************************************
1454 * SetBuffers: set buffers adresses
1455 *****************************************************************************
1456 * This function is called by system drivers to set buffers video memory
1458 *****************************************************************************/
1459 static void SetBuffers( vout_thread_t *p_vout, void *p_buf1, void *p_buf2 )
1461 /* No picture previously */
1462 p_vout->p_buffer[0].i_pic_x = 0;
1463 p_vout->p_buffer[0].i_pic_y = 0;
1464 p_vout->p_buffer[0].i_pic_width = 0;
1465 p_vout->p_buffer[0].i_pic_height = 0;
1466 p_vout->p_buffer[1].i_pic_x = 0;
1467 p_vout->p_buffer[1].i_pic_y = 0;
1468 p_vout->p_buffer[1].i_pic_width = 0;
1469 p_vout->p_buffer[1].i_pic_height = 0;
1471 /* The first area covers all the screen */
1472 p_vout->p_buffer[0].i_areas = 1;
1473 p_vout->p_buffer[0].pi_area_begin[0] = 0;
1474 p_vout->p_buffer[0].pi_area_end[0] = p_vout->i_height - 1;
1475 p_vout->p_buffer[1].i_areas = 1;
1476 p_vout->p_buffer[1].pi_area_begin[0] = 0;
1477 p_vout->p_buffer[1].pi_area_end[0] = p_vout->i_height - 1;
1480 p_vout->p_buffer[0].p_data = p_buf1;
1481 p_vout->p_buffer[1].p_data = p_buf2;
1484 /*****************************************************************************
1485 * SetBufferArea: activate an area in current buffer
1486 *****************************************************************************
1487 * This function is called when something is rendered on the current buffer.
1488 * It set the area as active and prepare it to be cleared on next rendering.
1489 * Pay attention to the fact that in this functions, i_h is in fact the end y
1490 * coordinate of the new area.
1491 *****************************************************************************/
1492 static void SetBufferArea( vout_thread_t *p_vout, int i_x, int i_y, int i_w, int i_h )
1494 vout_buffer_t * p_buffer; /* current buffer */
1495 int i_area_begin, i_area_end; /* area vertical extension */
1496 int i_area, i_area_copy; /* area index */
1497 int i_area_shift; /* shift distance for areas */
1499 /* Choose buffer and modify h to end of area position */
1500 p_buffer = &p_vout->p_buffer[ p_vout->i_buffer_index ];
1504 * Remove part of the area which is inside the picture - this is done
1505 * by calling again SetBufferArea with the correct areas dimensions.
1507 if( (i_x >= p_buffer->i_pic_x) && (i_x + i_w <= p_buffer->i_pic_x + p_buffer->i_pic_width) )
1509 i_area_begin = p_buffer->i_pic_y;
1510 i_area_end = i_area_begin + p_buffer->i_pic_height - 1;
1512 if( ((i_y >= i_area_begin) && (i_y <= i_area_end)) ||
1513 ((i_h >= i_area_begin) && (i_h <= i_area_end)) ||
1514 ((i_y < i_area_begin) && (i_h > i_area_end)) )
1516 /* Keep the stripe above the picture, if any */
1517 if( i_y < i_area_begin )
1519 SetBufferArea( p_vout, i_x, i_y, i_w, i_area_begin - i_y );
1521 /* Keep the stripe below the picture, if any */
1522 if( i_h > i_area_end )
1524 SetBufferArea( p_vout, i_x, i_area_end, i_w, i_h - i_area_end );
1530 /* Skip some extensions until interesting areas */
1532 (i_area < p_buffer->i_areas) &&
1533 (p_buffer->pi_area_end[i_area] + 1 <= i_y);
1539 if( i_area == p_buffer->i_areas )
1541 /* New area is below all existing ones: just add it at the end of the
1542 * array, if possible - otherwise, append it to the last one */
1543 if( i_area < VOUT_MAX_AREAS )
1545 p_buffer->pi_area_begin[i_area] = i_y;
1546 p_buffer->pi_area_end[i_area] = i_h;
1547 p_buffer->i_areas++;
1552 intf_DbgMsg("area overflow");
1554 p_buffer->pi_area_end[VOUT_MAX_AREAS - 1] = i_h;
1559 i_area_begin = p_buffer->pi_area_begin[i_area];
1560 i_area_end = p_buffer->pi_area_end[i_area];
1562 if( i_y < i_area_begin )
1564 if( i_h >= i_area_begin - 1 )
1566 /* Extend area above */
1567 p_buffer->pi_area_begin[i_area] = i_y;
1571 /* Create a new area above : merge last area if overflow, then
1572 * move all old areas down */
1573 if( p_buffer->i_areas == VOUT_MAX_AREAS )
1576 intf_DbgMsg("areas overflow");
1578 p_buffer->pi_area_end[VOUT_MAX_AREAS - 2] = p_buffer->pi_area_end[VOUT_MAX_AREAS - 1];
1582 p_buffer->i_areas++;
1584 for( i_area_copy = p_buffer->i_areas - 1; i_area_copy > i_area; i_area_copy-- )
1586 p_buffer->pi_area_begin[i_area_copy] = p_buffer->pi_area_begin[i_area_copy - 1];
1587 p_buffer->pi_area_end[i_area_copy] = p_buffer->pi_area_end[i_area_copy - 1];
1589 p_buffer->pi_area_begin[i_area] = i_y;
1590 p_buffer->pi_area_end[i_area] = i_h;
1594 if( i_h > i_area_end )
1596 /* Find further areas which can be merged with the new one */
1597 for( i_area_copy = i_area + 1;
1598 (i_area_copy < p_buffer->i_areas) &&
1599 (p_buffer->pi_area_begin[i_area] <= i_h);
1606 if( i_area_copy != i_area )
1608 /* Merge with last possible areas */
1609 //p_buffer->pi_area_end[i_area] = MAX( i_h, p_buffer->pi_area_end[i_area_copy] );
1611 /* Shift lower areas upward */
1612 i_area_shift = i_area_copy - i_area;
1613 p_buffer->i_areas -= i_area_shift;
1614 for( i_area_copy = i_area + 1; i_area_copy < p_buffer->i_areas; i_area_copy++ )
1616 p_buffer->pi_area_begin[i_area_copy] = p_buffer->pi_area_begin[i_area_copy + i_area_shift];
1617 p_buffer->pi_area_end[i_area_copy] = p_buffer->pi_area_end[i_area_copy + i_area_shift];
1622 /* Extend area below */
1623 p_buffer->pi_area_end[i_area] = i_h;
1629 /*****************************************************************************
1630 * SetBufferPicture: clear buffer and set picture area
1631 *****************************************************************************
1632 * This function is called before any rendering. It clears the current
1633 * rendering buffer and set the new picture area. If the picture pointer is
1634 * NULL, then no picture area is defined. Floating operations are avoided since
1635 * some MMX calculations may follow.
1636 *****************************************************************************/
1637 static void SetBufferPicture( vout_thread_t *p_vout, picture_t *p_pic )
1639 vout_buffer_t * p_buffer; /* current buffer */
1640 int i_pic_x, i_pic_y; /* picture position */
1641 int i_pic_width, i_pic_height; /* picture dimensions */
1642 int i_old_pic_y, i_old_pic_height; /* old picture area */
1643 int i_vout_width, i_vout_height; /* display dimensions */
1644 int i_area; /* area index */
1645 int i_data_index; /* area data index */
1646 int i_data_size; /* area data size, in 256 bytes blocs */
1647 u64 * p_data; /* area data, for clearing */
1648 byte_t * p_data8; /* area data, for clearing (slow) */
1650 /* Choose buffer and set display dimensions */
1651 p_buffer = &p_vout->p_buffer[ p_vout->i_buffer_index ];
1652 i_vout_width = p_vout->i_width;
1653 i_vout_height = p_vout->i_height;
1656 * Computes new picture size
1660 /* Try horizontal scaling first - width must be a mutiple of 16 */
1661 i_pic_width = (( p_vout->b_scale || (p_pic->i_width > i_vout_width)) ?
1662 i_vout_width : p_pic->i_width) & ~0xf;
1663 switch( p_pic->i_aspect_ratio )
1665 case AR_3_4_PICTURE:
1666 i_pic_height = i_pic_width * 3 / 4;
1668 case AR_16_9_PICTURE:
1669 i_pic_height = i_pic_width * 9 / 16;
1671 case AR_221_1_PICTURE:
1672 i_pic_height = i_pic_width * 100 / 221;
1674 case AR_SQUARE_PICTURE:
1676 i_pic_height = p_pic->i_height * i_pic_width / p_pic->i_width;
1680 /* If picture dimensions using horizontal scaling are too large, use
1681 * vertical scaling. Since width must be a multiple of 16, height is
1682 * adjusted again after. */
1683 if( i_pic_height > i_vout_height )
1685 i_pic_height = ( p_vout->b_scale || (p_pic->i_height > i_vout_height)) ?
1686 i_vout_height : p_pic->i_height;
1687 switch( p_pic->i_aspect_ratio )
1689 case AR_3_4_PICTURE:
1690 i_pic_width = (i_pic_height * 4 / 3) & ~0xf;
1691 i_pic_height = i_pic_width * 3 / 4;
1693 case AR_16_9_PICTURE:
1694 i_pic_width = (i_pic_height * 16 / 9) & ~0xf;
1695 i_pic_height = i_pic_width * 9 / 16;
1697 case AR_221_1_PICTURE:
1698 i_pic_width = (i_pic_height * 221 / 100) & ~0xf;
1699 i_pic_height = i_pic_width * 100 / 221;
1701 case AR_SQUARE_PICTURE:
1703 i_pic_width = (p_pic->i_width * i_pic_height / p_pic->i_height) & ~0xf;
1704 i_pic_height = p_pic->i_height * i_pic_width / p_pic->i_width;
1709 /* Set picture position */
1710 i_pic_x = (p_vout->i_width - i_pic_width) / 2;
1711 i_pic_y = (p_vout->i_height - i_pic_height) / 2;
1716 /* No picture: size is 0 */
1724 * Set new picture size - if it is smaller than the previous one, clear
1725 * around it. Since picture are centered, only their size is tested.
1727 if( (p_buffer->i_pic_width > i_pic_width) || (p_buffer->i_pic_height > i_pic_height) )
1729 i_old_pic_y = p_buffer->i_pic_y;
1730 i_old_pic_height = p_buffer->i_pic_height;
1731 p_buffer->i_pic_x = i_pic_x;
1732 p_buffer->i_pic_y = i_pic_y;
1733 p_buffer->i_pic_width = i_pic_width;
1734 p_buffer->i_pic_height = i_pic_height;
1735 SetBufferArea( p_vout, 0, i_old_pic_y, p_vout->i_width, i_old_pic_height );
1739 p_buffer->i_pic_x = i_pic_x;
1740 p_buffer->i_pic_y = i_pic_y;
1741 p_buffer->i_pic_width = i_pic_width;
1742 p_buffer->i_pic_height = i_pic_height;
1748 for( i_area = 0; i_area < p_buffer->i_areas; i_area++ )
1751 intf_DbgMsg("clearing picture %p area in buffer %d: %d-%d", p_pic,
1752 p_vout->i_buffer_index, p_buffer->pi_area_begin[i_area], p_buffer->pi_area_end[i_area] );
1754 i_data_size = (p_buffer->pi_area_end[i_area] - p_buffer->pi_area_begin[i_area] + 1) * p_vout->i_bytes_per_line;
1755 p_data = (u64*) (p_buffer->p_data + p_vout->i_bytes_per_line * p_buffer->pi_area_begin[i_area]);
1757 for( i_data_index = i_data_size / 256; i_data_index-- ; )
1759 /* Clear 256 bytes block */
1760 *p_data++ = 0; *p_data++ = 0; *p_data++ = 0; *p_data++ = 0;
1761 *p_data++ = 0; *p_data++ = 0; *p_data++ = 0; *p_data++ = 0;
1762 *p_data++ = 0; *p_data++ = 0; *p_data++ = 0; *p_data++ = 0;
1763 *p_data++ = 0; *p_data++ = 0; *p_data++ = 0; *p_data++ = 0;
1764 *p_data++ = 0; *p_data++ = 0; *p_data++ = 0; *p_data++ = 0;
1765 *p_data++ = 0; *p_data++ = 0; *p_data++ = 0; *p_data++ = 0;
1766 *p_data++ = 0; *p_data++ = 0; *p_data++ = 0; *p_data++ = 0;
1767 *p_data++ = 0; *p_data++ = 0; *p_data++ = 0; *p_data++ = 0;
1769 for( i_data_index = (i_data_size % 256) / 16; i_data_index--; )
1771 /* Clear remaining 16 bytes blocks */
1772 *p_data++ = 0; *p_data++ = 0;
1774 p_data8 = (byte_t *)p_data;
1775 for( i_data_index = i_data_size % 16; i_data_index--; )
1777 /* Clear remaining bytes */
1785 p_buffer->i_areas = 0;
1788 /*****************************************************************************
1789 * RenderPicture: render a picture
1790 *****************************************************************************
1791 * This function converts a picture from a video heap to a pixel-encoded image
1792 * and copies it to the current rendering buffer. No lock is required, since
1793 * the * rendered picture has been determined as existant, and will only be
1794 * destroyed by the vout thread later.
1795 *****************************************************************************/
1796 static void RenderPicture( vout_thread_t *p_vout, picture_t *p_pic )
1799 char psz_date[MSTRTIME_MAX_SIZE]; /* picture date */
1800 mtime_t render_time; /* picture rendering time */
1802 vout_buffer_t * p_buffer; /* rendering buffer */
1803 byte_t * p_pic_data; /* convertion destination */
1805 /* Get and set rendering information */
1806 p_buffer = &p_vout->p_buffer[ p_vout->i_buffer_index ];
1807 p_pic_data = p_buffer->p_data +
1808 p_buffer->i_pic_x * p_vout->i_bytes_per_pixel +
1809 p_buffer->i_pic_y * p_vout->i_bytes_per_line;
1811 render_time = mdate();
1817 * Choose appropriate rendering function and render picture
1819 switch( p_pic->i_type )
1821 case YUV_420_PICTURE:
1822 p_vout->yuv.pf_yuv420( p_vout, p_pic_data,
1823 p_pic->p_y, p_pic->p_u, p_pic->p_v,
1824 p_pic->i_width, p_pic->i_height,
1825 p_buffer->i_pic_width, p_buffer->i_pic_height,
1826 p_vout->i_bytes_per_line / p_vout->i_bytes_per_pixel,
1827 p_pic->i_matrix_coefficients );
1829 case YUV_422_PICTURE:
1830 p_vout->yuv.pf_yuv422( p_vout, p_pic_data,
1831 p_pic->p_y, p_pic->p_u, p_pic->p_v,
1832 p_pic->i_width, p_pic->i_height,
1833 p_buffer->i_pic_width, p_buffer->i_pic_height,
1834 p_vout->i_bytes_per_line / p_vout->i_bytes_per_pixel,
1835 p_pic->i_matrix_coefficients );
1837 case YUV_444_PICTURE:
1838 p_vout->yuv.pf_yuv444( p_vout, p_pic_data,
1839 p_pic->p_y, p_pic->p_u, p_pic->p_v,
1840 p_pic->i_width, p_pic->i_height,
1841 p_buffer->i_pic_width, p_buffer->i_pic_height,
1842 p_vout->i_bytes_per_line / p_vout->i_bytes_per_pixel,
1843 p_pic->i_matrix_coefficients );
1847 intf_ErrMsg("error: unknown picture type %d", p_pic->i_type );
1853 /* Print picture date and rendering time */
1854 intf_DbgMsg("picture %p rendered in buffer %d (%ld us), display date: %s", p_pic,
1855 p_vout->i_buffer_index, (long) (mdate() - render_time),
1856 mstrtime( psz_date, p_pic->date ));
1860 /*****************************************************************************
1861 * RenderPictureInfo: print additionnal information on a picture
1862 *****************************************************************************
1863 * This function will print information such as fps and other picture
1864 * dependant information.
1865 *****************************************************************************/
1866 static void RenderPictureInfo( vout_thread_t *p_vout, picture_t *p_pic )
1868 char psz_buffer[256]; /* string buffer */
1871 * Print FPS rate in upper right corner
1873 if( p_vout->c_fps_samples > VOUT_FPS_SAMPLES )
1875 long i_fps = VOUT_FPS_SAMPLES * 1000000 * 10 /
1876 ( p_vout->p_fps_sample[ (p_vout->c_fps_samples - 1)
1877 % VOUT_FPS_SAMPLES ] -
1878 p_vout->p_fps_sample[ p_vout->c_fps_samples
1879 % VOUT_FPS_SAMPLES ] );
1880 sprintf( psz_buffer, "%li.%i fps", i_fps / 10, (int)i_fps % 10 );
1881 Print( p_vout, 0, 0, RIGHT_RALIGN, TOP_RALIGN, psz_buffer );
1885 * Print frames count and loop time in upper left corner
1887 sprintf( psz_buffer, "%ld frames, render: %ldus",
1888 (long) p_vout->c_fps_samples, (long) p_vout->render_time );
1889 Print( p_vout, 0, 0, LEFT_RALIGN, TOP_RALIGN, psz_buffer );
1891 if( p_main->b_stats )
1894 * Print picture information in lower right corner
1896 sprintf( psz_buffer, "%s picture %dx%d (%dx%d%+d%+d %s) -> %dx%d+%d+%d",
1897 (p_pic->i_type == YUV_420_PICTURE) ? "4:2:0" :
1898 ((p_pic->i_type == YUV_422_PICTURE) ? "4:2:2" :
1899 ((p_pic->i_type == YUV_444_PICTURE) ? "4:4:4" : "ukn-type")),
1900 p_pic->i_width, p_pic->i_height,
1901 p_pic->i_display_width, p_pic->i_display_height,
1902 p_pic->i_display_horizontal_offset, p_pic->i_display_vertical_offset,
1903 (p_pic->i_aspect_ratio == AR_SQUARE_PICTURE) ? "sq" :
1904 ((p_pic->i_aspect_ratio == AR_3_4_PICTURE) ? "4:3" :
1905 ((p_pic->i_aspect_ratio == AR_16_9_PICTURE) ? "16:9" :
1906 ((p_pic->i_aspect_ratio == AR_221_1_PICTURE) ? "2.21:1" : "ukn-ar" ))),
1907 p_vout->p_buffer[ p_vout->i_buffer_index ].i_pic_width,
1908 p_vout->p_buffer[ p_vout->i_buffer_index ].i_pic_height,
1909 p_vout->p_buffer[ p_vout->i_buffer_index ].i_pic_x,
1910 p_vout->p_buffer[ p_vout->i_buffer_index ].i_pic_y );
1911 Print( p_vout, 0, 0, RIGHT_RALIGN, BOTTOM_RALIGN, psz_buffer );
1915 /*****************************************************************************
1916 * RenderIdle: render idle picture
1917 *****************************************************************************
1918 * This function will print something on the screen. It will return 0 if
1919 * nothing has been rendered, or 1 if something has been changed on the screen.
1920 * Note that if you absolutely want something to be printed, you will have
1921 * to force it by setting the last idle date to 0.
1922 * Unlike other rendering functions, this one calls the SetBufferPicture
1923 * function when needed.
1924 *****************************************************************************/
1925 int RenderIdle( vout_thread_t *p_vout )
1928 int i_x = 0, i_y = 0; /* text position */
1929 int i_width, i_height; /* text size */
1930 int i_amount = 0; /* amount to draw */
1931 char *psz_text = "Waiting for stream"; /* text to display */
1932 char *psz_wtext = "[................]";
1934 mtime_t current_date; /* current date */
1937 memset( p_vout->p_buffer[ p_vout->i_buffer_index ].p_data,
1938 p_vout->i_bytes_per_line * p_vout->i_height, 12);
1941 current_date = mdate();
1942 if( (current_date - p_vout->last_display_date) > VOUT_IDLE_DELAY
1943 // && (current_date - p_vout->last_idle_date) > VOUT_IDLE_DELAY
1946 /* FIXME: idle screen disabled */
1948 SetBufferPicture( p_vout, NULL );
1949 vout_TextSize( p_vout->p_large_font, WIDE_TEXT | OUTLINED_TEXT, psz_text,
1950 &i_width, &i_height );
1951 if( !Align( p_vout, &i_x, &i_y, i_width, i_height * 2, CENTER_RALIGN, CENTER_RALIGN ) )
1953 i_amount = (int) ((current_date - p_vout->last_display_date ) / 5000LL);
1954 vout_Print( p_vout->p_large_font,
1955 p_vout->p_buffer[ p_vout->i_buffer_index ].p_data +
1956 i_x * p_vout->i_bytes_per_pixel + i_y * p_vout->i_bytes_per_line,
1957 p_vout->i_bytes_per_pixel, p_vout->i_bytes_per_line,
1958 p_vout->i_white_pixel, p_vout->i_gray_pixel, 0,
1959 WIDE_TEXT | OUTLINED_TEXT, psz_text, (i_amount / 3 ) %110);
1961 vout_Print( p_vout->p_large_font,
1962 p_vout->p_buffer[ p_vout->i_buffer_index ].p_data +
1963 i_x * p_vout->i_bytes_per_pixel + (i_y + 16) * p_vout->i_bytes_per_line,
1964 p_vout->i_bytes_per_pixel, p_vout->i_bytes_per_line,
1965 p_vout->i_white_pixel, p_vout->i_gray_pixel, 0,
1966 WIDE_TEXT | OUTLINED_TEXT, psz_wtext, (i_amount/5)%110 );
1969 SetBufferArea( p_vout, i_x, i_y, i_width, i_height * 2 );
1977 /*****************************************************************************
1978 * RenderInfo: render additionnal information
1979 *****************************************************************************
1980 * This function renders information which do not depend on the current
1982 *****************************************************************************/
1983 static void RenderInfo( vout_thread_t *p_vout )
1986 char psz_buffer[256]; /* string buffer */
1987 int i_ready_pic = 0; /* ready pictures */
1988 int i_reserved_pic = 0; /* reserved pictures */
1989 int i_picture; /* picture index */
1994 * Print thread state in lower left corner
1996 for( i_picture = 0; i_picture < VOUT_MAX_PICTURES; i_picture++ )
1998 switch( p_vout->p_picture[i_picture].i_status )
2000 case RESERVED_PICTURE:
2001 case RESERVED_DATED_PICTURE:
2002 case RESERVED_DISP_PICTURE:
2010 sprintf( psz_buffer, "pic: %d (%d/%d)/%d",
2011 p_vout->i_pictures, i_reserved_pic, i_ready_pic, VOUT_MAX_PICTURES );
2012 Print( p_vout, 0, 0, LEFT_RALIGN, BOTTOM_RALIGN, psz_buffer );
2016 /*****************************************************************************
2017 * RenderSubPicture: render a subpicture
2018 *****************************************************************************
2019 * This function renders a sub picture unit.
2020 *****************************************************************************/
2021 static void RenderSubPicture( vout_thread_t *p_vout, picture_t *p_pic,
2022 subpicture_t *p_subpic )
2024 p_vout_font_t p_font; /* text font */
2025 int i_width, i_height; /* subpicture dimensions */
2027 while( p_subpic != NULL )
2029 switch( p_subpic->i_type )
2031 case DVD_SUBPICTURE: /* DVD subpicture unit */
2032 if( p_vout->b_need_render )
2034 vout_RenderRGBSPU( p_pic, p_subpic,
2035 &p_vout->p_buffer[ p_vout->i_buffer_index ],
2036 p_vout->i_bytes_per_pixel,
2037 p_vout->i_bytes_per_line );
2041 vout_RenderYUVSPU( p_pic, p_subpic );
2045 case TEXT_SUBPICTURE: /* single line text */
2046 /* Select default font if not specified */
2047 p_font = p_subpic->type.text.p_font;
2048 if( p_font == NULL )
2050 p_font = p_vout->p_default_font;
2053 /* Compute text size (width and height fields are ignored)
2055 vout_TextSize( p_font, p_subpic->type.text.i_style,
2056 p_subpic->p_data, &i_width, &i_height );
2057 if( !Align( p_vout, &p_subpic->i_x, &p_subpic->i_y,
2058 i_width, i_height, p_subpic->i_horizontal_align,
2059 p_subpic->i_vertical_align ) )
2062 p_vout->p_buffer[ p_vout->i_buffer_index ].p_data +
2063 p_subpic->i_x * p_vout->i_bytes_per_pixel +
2064 p_subpic->i_y * p_vout->i_bytes_per_line,
2065 p_vout->i_bytes_per_pixel, p_vout->i_bytes_per_line,
2066 p_subpic->type.text.i_char_color,
2067 p_subpic->type.text.i_border_color,
2068 p_subpic->type.text.i_bg_color,
2069 p_subpic->type.text.i_style, p_subpic->p_data, 100 );
2070 SetBufferArea( p_vout, p_subpic->i_x, p_subpic->i_y,
2071 i_width, i_height );
2077 intf_ErrMsg( "error: unknown subpicture %p type %d",
2078 p_subpic, p_subpic->i_type );
2083 p_subpic = p_subpic->p_next;
2087 /*****************************************************************************
2088 * Manage: manage thread
2089 *****************************************************************************
2090 * This function will handle changes in thread configuration.
2091 *****************************************************************************/
2092 static int Manage( vout_thread_t *p_vout )
2095 if( p_vout->i_changes )
2097 intf_DbgMsg("changes: 0x%x (no display: 0x%x)", p_vout->i_changes,
2098 0 /* p_vout->i_changes & VOUT_NODISPLAY_CHANGE */ );
2102 /* On gamma or grayscale change, rebuild tables */
2103 if( p_vout->i_changes & (VOUT_GAMMA_CHANGE | VOUT_GRAYSCALE_CHANGE |
2106 if( vout_ResetYUV( p_vout ) )
2108 intf_ErrMsg( "vout error: can't rebuild conversion tables" );
2113 /* Clear changes flags which does not need management or have been
2115 p_vout->i_changes &= ~(VOUT_GAMMA_CHANGE | VOUT_GRAYSCALE_CHANGE |
2116 VOUT_YUV_CHANGE | VOUT_INFO_CHANGE |
2117 VOUT_INTF_CHANGE | VOUT_SCALE_CHANGE |
2118 VOUT_CURSOR_CHANGE | VOUT_FULLSCREEN_CHANGE );
2120 /* Detect unauthorized changes */
2121 if( p_vout->i_changes )
2123 /* Some changes were not acknowledged by p_vout->pf_manage or this
2124 * function, it means they should not be authorized */
2125 intf_ErrMsg( "vout error: unauthorized changes in the vout thread" );
2132 /*****************************************************************************
2133 * Align: align a subpicture in the screen
2134 *****************************************************************************
2135 * This function is used for rendering text or subpictures. It returns non 0
2136 * it the final aera is not fully included in display area. Return coordinates
2138 *****************************************************************************/
2139 static int Align( vout_thread_t *p_vout, int *pi_x, int *pi_y,
2140 int i_width, int i_height, int i_h_align, int i_v_align )
2142 /* Align horizontally */
2146 *pi_x -= i_width / 2;
2149 *pi_x += (p_vout->i_width - i_width) / 2;
2155 *pi_x += p_vout->i_width - i_width;
2159 /* Align vertically */
2163 *pi_y -= i_height / 2;
2166 *pi_y += (p_vout->i_height - i_height) / 2;
2172 *pi_y += p_vout->i_height - i_height;
2174 case SUBTITLE_RALIGN:
2175 *pi_y += (p_vout->i_height + p_vout->p_buffer[ p_vout->i_buffer_index ].i_pic_y +
2176 p_vout->p_buffer[ p_vout->i_buffer_index ].i_pic_height - i_height) / 2;
2180 /* Return non 0 if clipping failed */
2181 return( (*pi_x < 0) || (*pi_y < 0) ||
2182 (*pi_x + i_width > p_vout->i_width) || (*pi_y + i_height > p_vout->i_height) );
2185 /*****************************************************************************
2186 * SetPalette: sets an 8 bpp palette
2187 *****************************************************************************
2188 * This function is just a prototype that does nothing. Architectures that
2189 * support palette allocation should override it.
2190 *****************************************************************************/
2191 static void SetPalette ( p_vout_thread_t p_vout, u16 *red,
2192 u16 *green, u16 *blue, u16 *transp )
2194 intf_ErrMsg( "vout error: method does not support palette changing" );