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>
47 #include "video_output.h"
48 #include "video_text.h"
49 #include "video_spu.h"
50 #include "video_yuv.h"
56 /*****************************************************************************
58 *****************************************************************************/
59 static int BinaryLog ( u32 i );
60 static void MaskToShift ( int *pi_left, int *pi_right, u32 i_mask );
61 static int InitThread ( vout_thread_t *p_vout );
62 static void RunThread ( vout_thread_t *p_vout );
63 static void ErrorThread ( vout_thread_t *p_vout );
64 static void EndThread ( vout_thread_t *p_vout );
65 static void DestroyThread ( vout_thread_t *p_vout, int i_status );
66 static void Print ( vout_thread_t *p_vout, int i_x, int i_y,
67 int i_h_align, int i_v_align,
68 unsigned char *psz_text );
69 static void SetBufferArea ( vout_thread_t *p_vout, int i_x, int i_y,
71 static void SetBufferPicture ( vout_thread_t *p_vout, picture_t *p_pic );
72 static void RenderPicture ( vout_thread_t *p_vout, picture_t *p_pic );
73 static void RenderPictureInfo ( vout_thread_t *p_vout, picture_t *p_pic );
74 static void RenderSubPicture ( vout_thread_t *p_vout,
75 subpicture_t *p_subpic );
76 static void RenderInterface ( vout_thread_t *p_vout );
77 static int RenderIdle ( vout_thread_t *p_vout );
78 static int RenderSplash ( vout_thread_t *p_vout );
79 static void RenderInfo ( vout_thread_t *p_vout );
80 static int Manage ( vout_thread_t *p_vout );
81 static int Align ( vout_thread_t *p_vout, int *pi_x,
82 int *pi_y, int i_width, int i_height,
83 int i_h_align, int i_v_align );
84 static void SetPalette ( p_vout_thread_t p_vout, u16 *red,
85 u16 *green, u16 *blue, u16 *transp );
87 /*****************************************************************************
88 * vout_CreateThread: creates a new video output thread
89 *****************************************************************************
90 * This function creates a new video output thread, and returns a pointer
91 * to its description. On error, it returns NULL.
92 * If pi_status is NULL, then the function will block until the thread is ready.
93 * If not, it will be updated using one of the THREAD_* constants.
94 *****************************************************************************/
95 vout_thread_t * vout_CreateThread ( int *pi_status )
97 vout_thread_t * p_vout; /* thread descriptor */
98 int i_status; /* thread status */
99 int i_index; /* index for array initialization */
101 /* Allocate descriptor */
102 p_vout = (vout_thread_t *) malloc( sizeof(vout_thread_t) );
105 intf_ErrMsg( "vout error: vout thread creation returned %s",
110 /* Choose the best module */
111 p_vout->p_module = module_Need( p_main->p_bank,
112 MODULE_CAPABILITY_VOUT, NULL );
114 if( p_vout->p_module == NULL )
116 intf_ErrMsg( "vout error: no suitable vout module" );
121 #define f p_vout->p_module->p_functions->vout.functions.vout
122 p_vout->pf_create = f.pf_create;
123 p_vout->pf_init = f.pf_init;
124 p_vout->pf_end = f.pf_end;
125 p_vout->pf_destroy = f.pf_destroy;
126 p_vout->pf_manage = f.pf_manage;
127 p_vout->pf_display = f.pf_display;
128 p_vout->pf_setpalette = f.pf_setpalette;
131 if( p_vout->pf_setpalette == NULL )
133 p_vout->pf_setpalette = SetPalette;
136 /* Initialize thread properties - thread id and locks will be initialized
140 p_vout->b_active = 0;
141 p_vout->pi_status = (pi_status != NULL) ? pi_status : &i_status;
142 *p_vout->pi_status = THREAD_CREATE;
144 /* Initialize some fields used by the system-dependant method - these
145 * fields will probably be modified by the method, and are only
147 p_vout->i_changes = 0;
148 p_vout->i_width = main_GetIntVariable( VOUT_WIDTH_VAR,
149 VOUT_WIDTH_DEFAULT );
150 p_vout->i_height = main_GetIntVariable( VOUT_HEIGHT_VAR,
151 VOUT_HEIGHT_DEFAULT );
152 p_vout->i_bytes_per_line = p_vout->i_width * 2;
153 p_vout->i_screen_depth = 15;
154 p_vout->i_bytes_per_pixel = 2;
155 p_vout->f_gamma = VOUT_GAMMA;
156 p_vout->b_need_render = 1;
158 p_vout->b_grayscale = main_GetIntVariable( VOUT_GRAYSCALE_VAR,
159 VOUT_GRAYSCALE_DEFAULT );
161 p_vout->b_interface = 0;
164 intf_DbgMsg( "wished configuration: %dx%d, %d/%d bpp (%d Bpl)",
165 p_vout->i_width, p_vout->i_height, p_vout->i_screen_depth,
166 p_vout->i_bytes_per_pixel * 8, p_vout->i_bytes_per_line );
168 /* Initialize idle screen */
169 p_vout->last_display_date = 0;
170 p_vout->last_idle_date = 0;
171 p_vout->init_display_date = mdate();
172 p_vout->render_time = 10000;
174 /* Initialize statistics fields */
175 p_vout->c_fps_samples = 0;
177 /* Initialize buffer index */
178 p_vout->i_buffer_index = 0;
180 /* Initialize pictures and subpictures - translation tables and functions
181 * will be initialized later in InitThread */
182 for( i_index = 0; i_index < VOUT_MAX_PICTURES; i_index++)
184 p_vout->p_picture[i_index].i_type = EMPTY_PICTURE;
185 p_vout->p_picture[i_index].i_status = FREE_PICTURE;
187 for( i_index = 0; i_index < VOUT_MAX_SUBPICTURES; i_index++)
189 p_vout->p_subpicture[i_index].i_type = EMPTY_SUBPICTURE;
190 p_vout->p_subpicture[i_index].i_status= FREE_SUBPICTURE;
192 p_vout->i_pictures = 0;
194 /* Create and initialize system-dependant method - this function issues its
195 * own error messages */
196 if( p_vout->pf_create( p_vout ) )
198 module_Unneed( p_main->p_bank, p_vout->p_module );
202 intf_DbgMsg( "actual configuration: %dx%d, %d/%d bpp (%d Bpl), "
203 "masks: 0x%x/0x%x/0x%x",
204 p_vout->i_width, p_vout->i_height, p_vout->i_screen_depth,
205 p_vout->i_bytes_per_pixel * 8, p_vout->i_bytes_per_line,
206 p_vout->i_red_mask, p_vout->i_green_mask,
207 p_vout->i_blue_mask );
209 /* Calculate shifts from system-updated masks */
210 MaskToShift( &p_vout->i_red_lshift, &p_vout->i_red_rshift,
211 p_vout->i_red_mask );
212 MaskToShift( &p_vout->i_green_lshift, &p_vout->i_green_rshift,
213 p_vout->i_green_mask );
214 MaskToShift( &p_vout->i_blue_lshift, &p_vout->i_blue_rshift,
215 p_vout->i_blue_mask );
217 /* Set some useful colors */
218 p_vout->i_white_pixel = RGB2PIXEL( p_vout, 255, 255, 255 );
219 p_vout->i_black_pixel = RGB2PIXEL( p_vout, 0, 0, 0 );
220 p_vout->i_gray_pixel = RGB2PIXEL( p_vout, 128, 128, 128 );
221 p_vout->i_blue_pixel = RGB2PIXEL( p_vout, 0, 0, 50 );
223 /* Load fonts - fonts must be initialized after the system method since
224 * they may be dependant on screen depth and other thread properties */
225 p_vout->p_default_font = vout_LoadFont( DATA_PATH "/" VOUT_DEFAULT_FONT );
226 if( p_vout->p_default_font == NULL )
228 p_vout->p_default_font = vout_LoadFont( "share/" VOUT_DEFAULT_FONT );
230 if( p_vout->p_default_font == NULL )
232 intf_ErrMsg( "vout error: could not load default font" );
233 p_vout->pf_destroy( p_vout );
237 p_vout->p_large_font = vout_LoadFont( DATA_PATH "/" VOUT_LARGE_FONT );
238 if( p_vout->p_large_font == NULL )
240 p_vout->p_large_font = vout_LoadFont( "share/" VOUT_LARGE_FONT );
242 if( p_vout->p_large_font == NULL )
244 intf_ErrMsg( "vout error: could not load large font" );
245 vout_UnloadFont( p_vout->p_default_font );
246 p_vout->pf_destroy( p_vout );
251 /* Create thread and set locks */
252 vlc_mutex_init( &p_vout->picture_lock );
253 vlc_mutex_init( &p_vout->subpicture_lock );
254 vlc_mutex_init( &p_vout->change_lock );
256 if( vlc_thread_create( &p_vout->thread_id, "video output",
257 (void *) RunThread, (void *) p_vout) )
259 intf_ErrMsg("vout error: %s", strerror(ENOMEM));
260 vout_UnloadFont( p_vout->p_default_font );
261 vout_UnloadFont( p_vout->p_large_font );
262 p_vout->pf_destroy( p_vout );
267 intf_Msg( "vout: video display initialized (%dx%d, %d/%d bpp)",
268 p_vout->i_width, p_vout->i_height, p_vout->i_screen_depth,
269 p_vout->i_bytes_per_pixel * 8 );
271 /* If status is NULL, wait until the thread is created */
272 if( pi_status == NULL )
276 msleep( THREAD_SLEEP );
277 }while( (i_status != THREAD_READY) && (i_status != THREAD_ERROR)
278 && (i_status != THREAD_FATAL) );
279 if( i_status != THREAD_READY )
287 /*****************************************************************************
288 * vout_DestroyThread: destroys a previously created thread
289 *****************************************************************************
290 * Destroy a terminated thread.
291 * The function will request a destruction of the specified thread. If pi_error
292 * is NULL, it will return once the thread is destroyed. Else, it will be
293 * update using one of the THREAD_* constants.
294 *****************************************************************************/
295 void vout_DestroyThread( vout_thread_t *p_vout, int *pi_status )
297 int i_status; /* thread status */
301 p_vout->pi_status = (pi_status != NULL) ? pi_status : &i_status;
302 *p_vout->pi_status = THREAD_DESTROY;
304 /* Request thread destruction */
307 /* If status is NULL, wait until thread has been destroyed */
308 if( pi_status == NULL )
312 msleep( THREAD_SLEEP );
313 }while( (i_status != THREAD_OVER) && (i_status != THREAD_ERROR)
314 && (i_status != THREAD_FATAL) );
318 /*****************************************************************************
319 * vout_DisplaySubPicture: display a subpicture unit
320 *****************************************************************************
321 * Remove the reservation flag of an subpicture, which will cause it to be ready
322 * for display. The picture does not need to be locked, since it is ignored by
323 * the output thread if is reserved.
324 *****************************************************************************/
325 void vout_DisplaySubPicture( vout_thread_t *p_vout, subpicture_t *p_subpic )
328 char psz_begin_date[MSTRTIME_MAX_SIZE]; /* buffer for date string */
329 char psz_end_date[MSTRTIME_MAX_SIZE]; /* buffer for date string */
333 /* Check if status is valid */
334 if( p_subpic->i_status != RESERVED_SUBPICTURE )
336 intf_DbgMsg("error: subpicture %p has invalid status %d", p_subpic,
337 p_subpic->i_status );
341 /* Remove reservation flag */
342 p_subpic->i_status = READY_SUBPICTURE;
345 /* Send subpicture information */
346 intf_DbgMsg("subpicture %p: type=%d, begin date=%s, end date=%s",
347 p_subpic, p_subpic->i_type,
348 mstrtime( psz_begin_date, p_subpic->begin_date ),
349 mstrtime( psz_end_date, p_subpic->end_date ) );
353 /*****************************************************************************
354 * vout_CreateSubPicture: allocate a subpicture in the video output heap.
355 *****************************************************************************
356 * This function create a reserved subpicture in the video output heap.
357 * A null pointer is returned if the function fails. This method provides an
358 * already allocated zone of memory in the spu data fields. It needs locking
359 * since several pictures can be created by several producers threads.
360 *****************************************************************************/
361 subpicture_t *vout_CreateSubPicture( vout_thread_t *p_vout, int i_type,
364 int i_subpic; /* subpicture index */
365 subpicture_t * p_free_subpic = NULL; /* first free subpicture */
366 subpicture_t * p_destroyed_subpic = NULL; /* first destroyed subpic */
369 vlc_mutex_lock( &p_vout->subpicture_lock );
372 * Look for an empty place
374 for( i_subpic = 0; i_subpic < VOUT_MAX_SUBPICTURES; i_subpic++ )
376 if( p_vout->p_subpicture[i_subpic].i_status == DESTROYED_SUBPICTURE )
378 /* Subpicture is marked for destruction, but is still allocated */
379 if( (p_vout->p_subpicture[i_subpic].i_type == i_type) &&
380 (p_vout->p_subpicture[i_subpic].i_size >= i_size) )
382 /* Memory size do match or is smaller : memory will not be
383 * reallocated, and function can end immediately - this is
384 * the best possible case, since no memory allocation needs
386 p_vout->p_subpicture[i_subpic].i_status = RESERVED_SUBPICTURE;
388 intf_DbgMsg("subpicture %p (in destroyed subpicture slot)",
389 &p_vout->p_subpicture[i_subpic] );
391 vlc_mutex_unlock( &p_vout->subpicture_lock );
392 return( &p_vout->p_subpicture[i_subpic] );
394 else if( p_destroyed_subpic == NULL )
396 /* Memory size do not match, but subpicture index will be kept in
397 * case no other place are left */
398 p_destroyed_subpic = &p_vout->p_subpicture[i_subpic];
401 else if( (p_free_subpic == NULL) &&
402 (p_vout->p_subpicture[i_subpic].i_status == FREE_SUBPICTURE ))
404 /* Subpicture is empty and ready for allocation */
405 p_free_subpic = &p_vout->p_subpicture[i_subpic];
409 /* If no free subpictures are available, use a destroyed subpicture */
410 if( (p_free_subpic == NULL) && (p_destroyed_subpic != NULL ) )
412 /* No free subpicture or matching destroyed subpictures have been
413 * found, but a destroyed subpicture is still avalaible */
414 free( p_destroyed_subpic->p_data );
415 p_free_subpic = p_destroyed_subpic;
421 if( p_free_subpic != NULL )
423 /* Allocate memory */
426 case TEXT_SUBPICTURE: /* text subpicture */
427 p_free_subpic->p_data = malloc( i_size + 1 );
429 case DVD_SUBPICTURE: /* DVD subpicture unit */
430 p_free_subpic->p_data = malloc( i_size );
434 intf_DbgMsg("error: unknown subpicture type %d", i_type );
435 p_free_subpic->p_data = NULL;
440 if( p_free_subpic->p_data != NULL )
442 /* Copy subpicture information, set some default values */
443 p_free_subpic->i_type = i_type;
444 p_free_subpic->i_status = RESERVED_SUBPICTURE;
445 p_free_subpic->i_size = i_size;
446 p_free_subpic->i_x = 0;
447 p_free_subpic->i_y = 0;
448 p_free_subpic->i_width = 0;
449 p_free_subpic->i_height = 0;
450 p_free_subpic->i_horizontal_align = CENTER_RALIGN;
451 p_free_subpic->i_vertical_align = CENTER_RALIGN;
455 /* Memory allocation failed : set subpicture as empty */
456 p_free_subpic->i_type = EMPTY_SUBPICTURE;
457 p_free_subpic->i_status = FREE_SUBPICTURE;
458 p_free_subpic = NULL;
459 intf_ErrMsg( "vout error: spu allocation returned %s",
460 strerror( ENOMEM ) );
464 intf_DbgMsg("subpicture %p (in free subpicture slot)", p_free_subpic );
466 vlc_mutex_unlock( &p_vout->subpicture_lock );
467 return( p_free_subpic );
470 /* No free or destroyed subpicture could be found */
471 intf_DbgMsg( "warning: subpicture heap is full" );
472 vlc_mutex_unlock( &p_vout->subpicture_lock );
476 /*****************************************************************************
477 * vout_DestroySubPicture: remove a subpicture from the heap
478 *****************************************************************************
479 * This function frees a previously reserved subpicture.
480 * It is meant to be used when the construction of a picture aborted.
481 * This function does not need locking since reserved subpictures are ignored
482 * by the output thread.
483 *****************************************************************************/
484 void vout_DestroySubPicture( vout_thread_t *p_vout, subpicture_t *p_subpic )
487 /* Check if status is valid */
488 if( p_subpic->i_status != RESERVED_SUBPICTURE )
490 intf_DbgMsg("error: subpicture %p has invalid status %d",
491 p_subpic, p_subpic->i_status );
495 p_subpic->i_status = DESTROYED_SUBPICTURE;
498 intf_DbgMsg("subpicture %p", p_subpic);
502 /*****************************************************************************
503 * vout_DisplayPicture: display a picture
504 *****************************************************************************
505 * Remove the reservation flag of a picture, which will cause it to be ready for
506 * display. The picture won't be displayed until vout_DatePicture has been
508 *****************************************************************************/
509 void vout_DisplayPicture( vout_thread_t *p_vout, picture_t *p_pic )
511 vlc_mutex_lock( &p_vout->picture_lock );
512 switch( p_pic->i_status )
514 case RESERVED_PICTURE:
515 p_pic->i_status = RESERVED_DISP_PICTURE;
517 case RESERVED_DATED_PICTURE:
518 p_pic->i_status = READY_PICTURE;
522 intf_DbgMsg("error: picture %p has invalid status %d", p_pic, p_pic->i_status );
528 intf_DbgMsg("picture %p", p_pic);
530 vlc_mutex_unlock( &p_vout->picture_lock );
533 /*****************************************************************************
534 * vout_DatePicture: date a picture
535 *****************************************************************************
536 * Remove the reservation flag of a picture, which will cause it to be ready for
537 * display. The picture won't be displayed until vout_DisplayPicture has been
539 *****************************************************************************/
540 void vout_DatePicture( vout_thread_t *p_vout, picture_t *p_pic, mtime_t date )
543 char psz_date[MSTRTIME_MAX_SIZE]; /* date */
546 vlc_mutex_lock( &p_vout->picture_lock );
548 switch( p_pic->i_status )
550 case RESERVED_PICTURE:
551 p_pic->i_status = RESERVED_DATED_PICTURE;
553 case RESERVED_DISP_PICTURE:
554 p_pic->i_status = READY_PICTURE;
558 intf_DbgMsg("error: picture %p has invalid status %d", p_pic, p_pic->i_status );
564 intf_DbgMsg("picture %p, display date: %s", p_pic, mstrtime( psz_date, p_pic->date) );
566 vlc_mutex_unlock( &p_vout->picture_lock );
569 /*****************************************************************************
570 * vout_CreatePicture: allocate a picture in the video output heap.
571 *****************************************************************************
572 * This function create a reserved image in the video output heap.
573 * A null pointer is returned if the function fails. This method provides an
574 * already allocated zone of memory in the picture data fields. It needs locking
575 * since several pictures can be created by several producers threads.
576 *****************************************************************************/
577 picture_t *vout_CreatePicture( vout_thread_t *p_vout, int i_type,
578 int i_width, int i_height )
580 int i_picture; /* picture index */
581 int i_chroma_width = 0; /* chroma width */
582 picture_t * p_free_picture = NULL; /* first free picture */
583 picture_t * p_destroyed_picture = NULL; /* first destroyed picture */
586 vlc_mutex_lock( &p_vout->picture_lock );
589 * Look for an empty place
591 for( i_picture = 0; i_picture < VOUT_MAX_PICTURES; i_picture++ )
593 if( p_vout->p_picture[i_picture].i_status == DESTROYED_PICTURE )
595 /* Picture is marked for destruction, but is still allocated - note
596 * that if width and type are the same for two pictures, chroma_width
597 * should also be the same */
598 if( (p_vout->p_picture[i_picture].i_type == i_type) &&
599 (p_vout->p_picture[i_picture].i_height == i_height) &&
600 (p_vout->p_picture[i_picture].i_width == i_width) )
602 /* Memory size do match : memory will not be reallocated, and function
603 * can end immediately - this is the best possible case, since no
604 * memory allocation needs to be done */
605 p_vout->p_picture[i_picture].i_status = RESERVED_PICTURE;
606 p_vout->i_pictures++;
608 intf_DbgMsg("picture %p (in destroyed picture slot)",
609 &p_vout->p_picture[i_picture] );
611 vlc_mutex_unlock( &p_vout->picture_lock );
612 return( &p_vout->p_picture[i_picture] );
614 else if( p_destroyed_picture == NULL )
616 /* Memory size do not match, but picture index will be kept in
617 * case no other place are left */
618 p_destroyed_picture = &p_vout->p_picture[i_picture];
621 else if( (p_free_picture == NULL) &&
622 (p_vout->p_picture[i_picture].i_status == FREE_PICTURE ))
624 /* Picture is empty and ready for allocation */
625 p_free_picture = &p_vout->p_picture[i_picture];
629 /* If no free picture is available, use a destroyed picture */
630 if( (p_free_picture == NULL) && (p_destroyed_picture != NULL ) )
632 /* No free picture or matching destroyed picture has been found, but
633 * a destroyed picture is still avalaible */
634 free( p_destroyed_picture->p_data );
635 p_free_picture = p_destroyed_picture;
641 if( p_free_picture != NULL )
643 /* Allocate memory */
646 case YUV_420_PICTURE: /* YUV 420: 1,1/4,1/4 samples per pixel */
647 i_chroma_width = i_width / 2;
648 p_free_picture->p_data = malloc( i_height * i_chroma_width * 3 * sizeof( yuv_data_t ) );
649 p_free_picture->p_y = (yuv_data_t *)p_free_picture->p_data;
650 p_free_picture->p_u = (yuv_data_t *)p_free_picture->p_data +i_height*i_chroma_width*4/2;
651 p_free_picture->p_v = (yuv_data_t *)p_free_picture->p_data +i_height*i_chroma_width*5/2;
653 case YUV_422_PICTURE: /* YUV 422: 1,1/2,1/2 samples per pixel */
654 i_chroma_width = i_width / 2;
655 p_free_picture->p_data = malloc( i_height * i_chroma_width * 4 * sizeof( yuv_data_t ) );
656 p_free_picture->p_y = (yuv_data_t *)p_free_picture->p_data;
657 p_free_picture->p_u = (yuv_data_t *)p_free_picture->p_data +i_height*i_chroma_width*2;
658 p_free_picture->p_v = (yuv_data_t *)p_free_picture->p_data +i_height*i_chroma_width*3;
660 case YUV_444_PICTURE: /* YUV 444: 1,1,1 samples per pixel */
661 i_chroma_width = i_width;
662 p_free_picture->p_data = malloc( i_height * i_chroma_width * 3 * sizeof( yuv_data_t ) );
663 p_free_picture->p_y = (yuv_data_t *)p_free_picture->p_data;
664 p_free_picture->p_u = (yuv_data_t *)p_free_picture->p_data +i_height*i_chroma_width;
665 p_free_picture->p_v = (yuv_data_t *)p_free_picture->p_data +i_height*i_chroma_width*2;
669 intf_DbgMsg("error: unknown picture type %d", i_type );
670 p_free_picture->p_data = NULL;
675 if( p_free_picture->p_data != NULL )
677 /* Copy picture information, set some default values */
678 p_free_picture->i_type = i_type;
679 p_free_picture->i_status = RESERVED_PICTURE;
680 p_free_picture->i_matrix_coefficients = 1;
681 p_free_picture->i_width = i_width;
682 p_free_picture->i_height = i_height;
683 p_free_picture->i_chroma_width = i_chroma_width;
684 p_free_picture->i_display_horizontal_offset = 0;
685 p_free_picture->i_display_vertical_offset = 0;
686 p_free_picture->i_display_width = i_width;
687 p_free_picture->i_display_height = i_height;
688 p_free_picture->i_aspect_ratio = AR_SQUARE_PICTURE;
689 p_free_picture->i_refcount = 0;
690 p_vout->i_pictures++;
694 /* Memory allocation failed : set picture as empty */
695 p_free_picture->i_type = EMPTY_PICTURE;
696 p_free_picture->i_status = FREE_PICTURE;
697 p_free_picture = NULL;
698 intf_ErrMsg( "vout error: picture allocation returned %s",
699 strerror( ENOMEM ) );
703 intf_DbgMsg("picture %p (in free picture slot)", p_free_picture );
705 vlc_mutex_unlock( &p_vout->picture_lock );
707 /* Initialize mutex */
708 vlc_mutex_init( &(p_free_picture->lock_deccount) );
710 return( p_free_picture );
713 /* No free or destroyed picture could be found */
714 intf_DbgMsg( "warning: picture heap is full" );
715 vlc_mutex_unlock( &p_vout->picture_lock );
719 /*****************************************************************************
720 * vout_DestroyPicture: remove a permanent or reserved picture from the heap
721 *****************************************************************************
722 * This function frees a previously reserved picture or a permanent
723 * picture. It is meant to be used when the construction of a picture aborted.
724 * Note that the picture will be destroyed even if it is linked !
725 *****************************************************************************/
726 void vout_DestroyPicture( vout_thread_t *p_vout, picture_t *p_pic )
728 vlc_mutex_lock( &p_vout->picture_lock );
731 /* Check if picture status is valid */
732 if( (p_pic->i_status != RESERVED_PICTURE) &&
733 (p_pic->i_status != RESERVED_DATED_PICTURE) &&
734 (p_pic->i_status != RESERVED_DISP_PICTURE) )
736 intf_DbgMsg("error: picture %p has invalid status %d", p_pic, p_pic->i_status );
740 p_pic->i_status = DESTROYED_PICTURE;
741 p_vout->i_pictures--;
744 intf_DbgMsg("picture %p", p_pic);
747 /* destroy the lock that had been initialized in CreatePicture */
748 vlc_mutex_destroy( &(p_pic->lock_deccount) );
750 vlc_mutex_unlock( &p_vout->picture_lock );
753 /*****************************************************************************
754 * vout_LinkPicture: increment reference counter of a picture
755 *****************************************************************************
756 * This function increment the reference counter of a picture in the video
757 * heap. It needs a lock since several producer threads can access the picture.
758 *****************************************************************************/
759 void vout_LinkPicture( vout_thread_t *p_vout, picture_t *p_pic )
761 vlc_mutex_lock( &p_vout->picture_lock );
765 intf_DbgMsg("picture %p refcount=%d", p_pic, p_pic->i_refcount );
768 vlc_mutex_unlock( &p_vout->picture_lock );
771 /*****************************************************************************
772 * vout_UnlinkPicture: decrement reference counter of a picture
773 *****************************************************************************
774 * This function decrement the reference counter of a picture in the video heap.
775 *****************************************************************************/
776 void vout_UnlinkPicture( vout_thread_t *p_vout, picture_t *p_pic )
778 vlc_mutex_lock( &p_vout->picture_lock );
782 if( p_pic->i_refcount < 0 )
784 intf_DbgMsg("error: refcount < 0");
785 p_pic->i_refcount = 0;
789 if( (p_pic->i_refcount == 0) && (p_pic->i_status == DISPLAYED_PICTURE) )
791 p_pic->i_status = DESTROYED_PICTURE;
792 p_vout->i_pictures--;
796 intf_DbgMsg("picture %p refcount=%d", p_pic, p_pic->i_refcount );
799 vlc_mutex_unlock( &p_vout->picture_lock );
802 /*****************************************************************************
803 * vout_SetBuffers: set buffers adresses
804 *****************************************************************************
805 * This function is called by system drivers to set buffers video memory
807 *****************************************************************************/
808 void vout_SetBuffers( vout_thread_t *p_vout, void *p_buf1, void *p_buf2 )
810 /* No picture previously */
811 p_vout->p_buffer[0].i_pic_x = 0;
812 p_vout->p_buffer[0].i_pic_y = 0;
813 p_vout->p_buffer[0].i_pic_width = 0;
814 p_vout->p_buffer[0].i_pic_height = 0;
815 p_vout->p_buffer[1].i_pic_x = 0;
816 p_vout->p_buffer[1].i_pic_y = 0;
817 p_vout->p_buffer[1].i_pic_width = 0;
818 p_vout->p_buffer[1].i_pic_height = 0;
820 /* The first area covers all the screen */
821 p_vout->p_buffer[0].i_areas = 1;
822 p_vout->p_buffer[0].pi_area_begin[0] = 0;
823 p_vout->p_buffer[0].pi_area_end[0] = p_vout->i_height - 1;
824 p_vout->p_buffer[1].i_areas = 1;
825 p_vout->p_buffer[1].pi_area_begin[0] = 0;
826 p_vout->p_buffer[1].pi_area_end[0] = p_vout->i_height - 1;
829 p_vout->p_buffer[0].p_data = p_buf1;
830 p_vout->p_buffer[1].p_data = p_buf2;
833 /*****************************************************************************
834 * vout_Pixel2RGB: return red, green and blue from pixel value
835 *****************************************************************************
836 * Return color values, in 0-255 range, of the decomposition of a pixel. This
837 * is a slow routine and should only be used for initialization phase.
838 *****************************************************************************/
839 void vout_Pixel2RGB( vout_thread_t *p_vout, u32 i_pixel, int *pi_red, int *pi_green, int *pi_blue )
841 *pi_red = i_pixel & p_vout->i_red_mask;
842 *pi_green = i_pixel & p_vout->i_green_mask;
843 *pi_blue = i_pixel & p_vout->i_blue_mask;
846 /* following functions are local */
848 /*****************************************************************************
849 * BinaryLog: computes the base 2 log of a binary value
850 *****************************************************************************
851 * This functions is used by MaskToShift, to get a bit index from a binary
853 *****************************************************************************/
854 static int BinaryLog(u32 i)
879 if (i != ((u32)1 << i_log))
881 intf_DbgMsg("internal error: binary log overflow");
887 /*****************************************************************************
888 * MaskToShift: transform a color mask into right and left shifts
889 *****************************************************************************
890 * This function is used for obtaining color shifts from masks.
891 *****************************************************************************/
892 static void MaskToShift( int *pi_left, int *pi_right, u32 i_mask )
894 u32 i_low, i_high; /* lower hand higher bits of the mask */
897 i_low = i_mask & (- i_mask); /* lower bit of the mask */
898 i_high = i_mask + i_low; /* higher bit of the mask */
900 /* Transform bits into an index */
901 i_low = BinaryLog (i_low);
902 i_high = BinaryLog (i_high);
904 /* Update pointers and return */
906 *pi_right = (8 - i_high + i_low);
909 /*****************************************************************************
910 * InitThread: initialize video output thread
911 *****************************************************************************
912 * This function is called from RunThread and performs the second step of the
913 * initialization. It returns 0 on success. Note that the thread's flag are not
914 * modified inside this function.
915 *****************************************************************************/
916 static int InitThread( vout_thread_t *p_vout )
919 *p_vout->pi_status = THREAD_START;
921 vlc_mutex_lock( &p_vout->change_lock );
927 /* Initialize output method - this function issues its own error messages */
928 if( p_vout->pf_init( p_vout ) )
933 if( p_vout->b_need_render )
935 /* Initialize convertion tables and functions */
936 if( vout_InitYUV( p_vout ) )
938 intf_ErrMsg("vout error: can't allocate YUV translation tables");
943 /* Mark thread as running and return */
944 p_vout->b_active = 1;
945 *p_vout->pi_status = THREAD_READY;
948 intf_DbgMsg("thread ready");
952 /*****************************************************************************
953 * RunThread: video output thread
954 *****************************************************************************
955 * Video output thread. This function does only returns when the thread is
956 * terminated. It handles the pictures arriving in the video heap and the
957 * display device events.
958 *****************************************************************************/
959 static void RunThread( vout_thread_t *p_vout)
961 int i_index; /* index in heap */
962 mtime_t current_date; /* current date */
963 mtime_t display_date; /* display date */
964 boolean_t b_display; /* display flag */
965 picture_t * p_pic; /* picture pointer */
966 subpicture_t * p_subpic; /* subpicture pointer */
971 p_vout->b_error = InitThread( p_vout );
972 if( p_vout->b_error )
974 DestroyThread( p_vout, THREAD_ERROR );
979 * Main loop - it is not executed if an error occured during
982 while( (!p_vout->b_die) && (!p_vout->b_error) )
984 /* Initialize loop variables */
988 current_date = mdate();
991 if( !(p_vout->c_loops % VOUT_STATS_NB_LOOPS) )
993 intf_Msg("vout stats: picture heap: %d/%d",
994 p_vout->i_pictures, VOUT_MAX_PICTURES);
999 * Find the picture to display - this operation does not need lock,
1000 * since only READY_PICTUREs are handled
1002 for( i_index = 0; i_index < VOUT_MAX_PICTURES; i_index++ )
1004 if( (p_vout->p_picture[i_index].i_status == READY_PICTURE) &&
1005 ( (p_pic == NULL) ||
1006 (p_vout->p_picture[i_index].date < display_date) ) )
1008 p_pic = &p_vout->p_picture[i_index];
1009 display_date = p_pic->date;
1015 /* Computes FPS rate */
1016 p_vout->p_fps_sample[ p_vout->c_fps_samples++ % VOUT_FPS_SAMPLES ] = display_date;
1018 if( display_date < current_date - p_vout->render_time )
1020 /* Picture is late: it will be destroyed and the thread
1021 * will sleep and go to next picture */
1023 vlc_mutex_lock( &p_vout->picture_lock );
1024 if( p_pic->i_refcount )
1026 p_pic->i_status = DISPLAYED_PICTURE;
1030 p_pic->i_status = DESTROYED_PICTURE;
1031 p_vout->i_pictures--;
1034 "warning: late picture skipped (%p)", p_pic );
1035 vlc_mutex_unlock( &p_vout->picture_lock );
1039 else if( display_date > current_date + VOUT_DISPLAY_DELAY )
1041 /* A picture is ready to be rendered, but its rendering date
1042 * is far from the current one so the thread will perform an
1043 * empty loop as if no picture were found. The picture state
1050 * Find the subpictures to display - this operation does not need
1051 * lock, since only READY_SUBPICTURE are handled. If no picture
1052 * has been selected, display_date will depend on the subpicture.
1053 * We get an easily parsable chained list of subpictures which
1054 * ends with NULL since p_subpic was initialized to NULL.
1056 for( i_index = 0; i_index < VOUT_MAX_SUBPICTURES; i_index++ )
1058 if( p_vout->p_subpicture[i_index].i_status == READY_SUBPICTURE )
1060 p_vout->p_subpicture[i_index].p_next = p_subpic;
1061 p_subpic = &p_vout->p_subpicture[i_index];
1066 * Perform rendering, sleep and display rendered picture
1068 if( p_pic ) /* picture and perhaps subpicture */
1070 b_display = p_vout->b_active;
1071 p_vout->last_display_date = display_date;
1072 p_vout->p_rendered_pic = p_pic;
1077 /* Set picture dimensions and clear buffer */
1078 SetBufferPicture( p_vout, p_pic );
1080 /* FIXME: if b_need_render == 0 we need to do something with
1081 * the subpictures one day. */
1083 if( p_vout->b_need_render && b_display )
1085 /* Render picture and information */
1086 RenderPicture( p_vout, p_pic );
1087 if( p_vout->b_info )
1089 RenderPictureInfo( p_vout, p_pic );
1090 RenderInfo( p_vout );
1094 RenderSubPicture( p_vout, p_subpic );
1098 /* Render interface and subpicture */
1099 if( b_display && p_vout->b_interface && p_vout->b_need_render )
1101 RenderInterface( p_vout );
1105 else if( p_vout->b_active && p_vout->b_need_render
1106 && p_vout->init_display_date == 0)
1108 /* Idle or interface screen alone */
1110 if( p_vout->b_interface && 0 /* && XXX?? intf_change */ )
1112 /* Interface has changed, so a new rendering is required - force
1113 * it by setting last idle date to 0 */
1114 p_vout->last_idle_date = 0;
1117 /* Render idle screen and update idle date, then render interface if
1119 b_display = RenderIdle( p_vout );
1122 p_vout->last_idle_date = current_date;
1123 if( p_vout->b_interface )
1125 RenderInterface( p_vout );
1137 * Check for the current time and
1138 * display splash screen if everything is on time
1140 if( p_vout->init_display_date > 0 && p_vout->b_need_render )
1142 if( p_vout->b_active &&
1143 mdate()-p_vout->init_display_date < 5000000)
1145 /* there is something to display ! */
1147 RenderSplash( p_vout );
1150 /* no splash screen ! */
1151 p_vout->init_display_date=0;
1157 * Sleep, wake up and display rendered picture
1160 if( display_date != 0 )
1162 /* Store render time using Bresenham algorithm */
1163 p_vout->render_time += mdate() - current_date;
1164 p_vout->render_time >>= 1;
1167 /* Give back change lock */
1168 vlc_mutex_unlock( &p_vout->change_lock );
1170 /* Sleep a while or until a given date */
1171 if( display_date != 0 )
1173 mwait( display_date - VOUT_MWAIT_TOLERANCE );
1177 msleep( VOUT_IDLE_SLEEP );
1180 /* On awakening, take back lock and send immediately picture to display,
1181 * then swap buffers */
1182 vlc_mutex_lock( &p_vout->change_lock );
1184 intf_DbgMsg( "picture %p, subpicture %p in buffer %d, display=%d", p_pic, p_subpic,
1185 p_vout->i_buffer_index, b_display /* && !(p_vout->i_changes & VOUT_NODISPLAY_CHANGE) */ );
1187 if( b_display /* && !(p_vout->i_changes & VOUT_NODISPLAY_CHANGE) */ )
1189 p_vout->pf_display( p_vout );
1191 p_vout->i_buffer_index = ++p_vout->i_buffer_index & 1;
1197 /* Remove picture from heap */
1198 vlc_mutex_lock( &p_vout->picture_lock );
1199 if( p_pic->i_refcount )
1201 p_pic->i_status = DISPLAYED_PICTURE;
1205 p_pic->i_status = DESTROYED_PICTURE;
1206 p_vout->i_pictures--;
1208 vlc_mutex_unlock( &p_vout->picture_lock );
1213 * Check events and manage thread
1215 if( p_vout->pf_manage( p_vout ) | Manage( p_vout ) )
1217 /* A fatal error occured, and the thread must terminate immediately,
1218 * without displaying anything - setting b_error to 1 cause the
1219 * immediate end of the main while() loop. */
1220 p_vout->b_error = 1;
1225 * Error loop - wait until the thread destruction is requested
1227 if( p_vout->b_error )
1229 ErrorThread( p_vout );
1233 EndThread( p_vout );
1234 DestroyThread( p_vout, THREAD_OVER );
1235 intf_DbgMsg( "thread end" );
1238 /*****************************************************************************
1239 * ErrorThread: RunThread() error loop
1240 *****************************************************************************
1241 * This function is called when an error occured during thread main's loop. The
1242 * thread can still receive feed, but must be ready to terminate as soon as
1244 *****************************************************************************/
1245 static void ErrorThread( vout_thread_t *p_vout )
1247 /* Wait until a `die' order */
1248 while( !p_vout->b_die )
1251 msleep( VOUT_IDLE_SLEEP );
1255 /*****************************************************************************
1256 * EndThread: thread destruction
1257 *****************************************************************************
1258 * This function is called when the thread ends after a sucessful
1259 * initialization. It frees all ressources allocated by InitThread.
1260 *****************************************************************************/
1261 static void EndThread( vout_thread_t *p_vout )
1263 int i_index; /* index in heap */
1266 *p_vout->pi_status = THREAD_END;
1270 struct tms cpu_usage;
1271 times( &cpu_usage );
1273 intf_Msg( "vout stats: cpu usage (user: %d, system: %d)",
1274 cpu_usage.tms_utime, cpu_usage.tms_stime );
1278 /* Destroy all remaining pictures and subpictures */
1279 for( i_index = 0; i_index < VOUT_MAX_PICTURES; i_index++ )
1281 if( p_vout->p_picture[i_index].i_status != FREE_PICTURE )
1283 free( p_vout->p_picture[i_index].p_data );
1287 for( i_index = 0; i_index < VOUT_MAX_SUBPICTURES; i_index++ )
1289 if( p_vout->p_subpicture[i_index].i_status != FREE_SUBPICTURE )
1291 free( p_vout->p_subpicture[i_index].p_data );
1295 /* Destroy translation tables */
1296 vout_EndYUV( p_vout );
1297 p_vout->pf_end( p_vout );
1299 /* Release the change lock */
1300 vlc_mutex_unlock( &p_vout->change_lock );
1303 /*****************************************************************************
1304 * DestroyThread: thread destruction
1305 *****************************************************************************
1306 * This function is called when the thread ends. It frees all ressources
1307 * allocated by CreateThread. Status is available at this stage.
1308 *****************************************************************************/
1309 static void DestroyThread( vout_thread_t *p_vout, int i_status )
1311 int *pi_status; /* status adress */
1313 /* Store status adress */
1314 pi_status = p_vout->pi_status;
1316 /* Destroy thread structures allocated by Create and InitThread */
1317 vout_UnloadFont( p_vout->p_default_font );
1318 vout_UnloadFont( p_vout->p_large_font );
1319 p_vout->pf_destroy( p_vout );
1321 /* Destroy the locks */
1322 vlc_mutex_destroy( &p_vout->picture_lock );
1323 vlc_mutex_destroy( &p_vout->subpicture_lock );
1324 vlc_mutex_destroy( &p_vout->change_lock );
1326 /* Release the module */
1327 module_Unneed( p_main->p_bank, p_vout->p_module );
1329 /* Free structure */
1331 *pi_status = i_status;
1334 /*****************************************************************************
1335 * Print: print simple text on a picture
1336 *****************************************************************************
1337 * This function will print a simple text on the picture. It is designed to
1338 * print debugging or general information.
1339 *****************************************************************************/
1340 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 )
1342 int i_text_height; /* total text height */
1343 int i_text_width; /* total text width */
1345 /* Update upper left coordinates according to alignment */
1346 vout_TextSize( p_vout->p_default_font, 0, psz_text, &i_text_width, &i_text_height );
1347 if( !Align( p_vout, &i_x, &i_y, i_text_width, i_text_height, i_h_align, i_v_align ) )
1349 /* Set area and print text */
1350 SetBufferArea( p_vout, i_x, i_y, i_text_width, i_text_height );
1351 vout_Print( p_vout->p_default_font, p_vout->p_buffer[ p_vout->i_buffer_index ].p_data +
1352 i_y * p_vout->i_bytes_per_line + i_x * p_vout->i_bytes_per_pixel,
1353 p_vout->i_bytes_per_pixel, p_vout->i_bytes_per_line,
1354 p_vout->i_white_pixel, 0, 0,
1359 /*****************************************************************************
1360 * SetBufferArea: activate an area in current buffer
1361 *****************************************************************************
1362 * This function is called when something is rendered on the current buffer.
1363 * It set the area as active and prepare it to be cleared on next rendering.
1364 * Pay attention to the fact that in this functions, i_h is in fact the end y
1365 * coordinate of the new area.
1366 *****************************************************************************/
1367 static void SetBufferArea( vout_thread_t *p_vout, int i_x, int i_y, int i_w, int i_h )
1369 vout_buffer_t * p_buffer; /* current buffer */
1370 int i_area_begin, i_area_end; /* area vertical extension */
1371 int i_area, i_area_copy; /* area index */
1372 int i_area_shift; /* shift distance for areas */
1374 /* Choose buffer and modify h to end of area position */
1375 p_buffer = &p_vout->p_buffer[ p_vout->i_buffer_index ];
1379 * Remove part of the area which is inside the picture - this is done
1380 * by calling again SetBufferArea with the correct areas dimensions.
1382 if( (i_x >= p_buffer->i_pic_x) && (i_x + i_w <= p_buffer->i_pic_x + p_buffer->i_pic_width) )
1384 i_area_begin = p_buffer->i_pic_y;
1385 i_area_end = i_area_begin + p_buffer->i_pic_height - 1;
1387 if( ((i_y >= i_area_begin) && (i_y <= i_area_end)) ||
1388 ((i_h >= i_area_begin) && (i_h <= i_area_end)) ||
1389 ((i_y < i_area_begin) && (i_h > i_area_end)) )
1391 /* Keep the stripe above the picture, if any */
1392 if( i_y < i_area_begin )
1394 SetBufferArea( p_vout, i_x, i_y, i_w, i_area_begin - i_y );
1396 /* Keep the stripe below the picture, if any */
1397 if( i_h > i_area_end )
1399 SetBufferArea( p_vout, i_x, i_area_end, i_w, i_h - i_area_end );
1405 /* Skip some extensions until interesting areas */
1407 (i_area < p_buffer->i_areas) &&
1408 (p_buffer->pi_area_end[i_area] + 1 <= i_y);
1414 if( i_area == p_buffer->i_areas )
1416 /* New area is below all existing ones: just add it at the end of the
1417 * array, if possible - otherwise, append it to the last one */
1418 if( i_area < VOUT_MAX_AREAS )
1420 p_buffer->pi_area_begin[i_area] = i_y;
1421 p_buffer->pi_area_end[i_area] = i_h;
1422 p_buffer->i_areas++;
1427 intf_DbgMsg("area overflow");
1429 p_buffer->pi_area_end[VOUT_MAX_AREAS - 1] = i_h;
1434 i_area_begin = p_buffer->pi_area_begin[i_area];
1435 i_area_end = p_buffer->pi_area_end[i_area];
1437 if( i_y < i_area_begin )
1439 if( i_h >= i_area_begin - 1 )
1441 /* Extend area above */
1442 p_buffer->pi_area_begin[i_area] = i_y;
1446 /* Create a new area above : merge last area if overflow, then
1447 * move all old areas down */
1448 if( p_buffer->i_areas == VOUT_MAX_AREAS )
1451 intf_DbgMsg("areas overflow");
1453 p_buffer->pi_area_end[VOUT_MAX_AREAS - 2] = p_buffer->pi_area_end[VOUT_MAX_AREAS - 1];
1457 p_buffer->i_areas++;
1459 for( i_area_copy = p_buffer->i_areas - 1; i_area_copy > i_area; i_area_copy-- )
1461 p_buffer->pi_area_begin[i_area_copy] = p_buffer->pi_area_begin[i_area_copy - 1];
1462 p_buffer->pi_area_end[i_area_copy] = p_buffer->pi_area_end[i_area_copy - 1];
1464 p_buffer->pi_area_begin[i_area] = i_y;
1465 p_buffer->pi_area_end[i_area] = i_h;
1469 if( i_h > i_area_end )
1471 /* Find further areas which can be merged with the new one */
1472 for( i_area_copy = i_area + 1;
1473 (i_area_copy < p_buffer->i_areas) &&
1474 (p_buffer->pi_area_begin[i_area] <= i_h);
1481 if( i_area_copy != i_area )
1483 /* Merge with last possible areas */
1484 p_buffer->pi_area_end[i_area] = MAX( i_h, p_buffer->pi_area_end[i_area_copy] );
1486 /* Shift lower areas upward */
1487 i_area_shift = i_area_copy - i_area;
1488 p_buffer->i_areas -= i_area_shift;
1489 for( i_area_copy = i_area + 1; i_area_copy < p_buffer->i_areas; i_area_copy++ )
1491 p_buffer->pi_area_begin[i_area_copy] = p_buffer->pi_area_begin[i_area_copy + i_area_shift];
1492 p_buffer->pi_area_end[i_area_copy] = p_buffer->pi_area_end[i_area_copy + i_area_shift];
1497 /* Extend area below */
1498 p_buffer->pi_area_end[i_area] = i_h;
1504 /*****************************************************************************
1505 * SetBufferPicture: clear buffer and set picture area
1506 *****************************************************************************
1507 * This function is called before any rendering. It clears the current
1508 * rendering buffer and set the new picture area. If the picture pointer is
1509 * NULL, then no picture area is defined. Floating operations are avoided since
1510 * some MMX calculations may follow.
1511 *****************************************************************************/
1512 static void SetBufferPicture( vout_thread_t *p_vout, picture_t *p_pic )
1514 vout_buffer_t * p_buffer; /* current buffer */
1515 int i_pic_x, i_pic_y; /* picture position */
1516 int i_pic_width, i_pic_height; /* picture dimensions */
1517 int i_old_pic_y, i_old_pic_height; /* old picture area */
1518 int i_vout_width, i_vout_height; /* display dimensions */
1519 int i_area; /* area index */
1520 int i_data_index; /* area data index */
1521 int i_data_size; /* area data size, in 256 bytes blocs */
1522 u64 * p_data; /* area data, for clearing */
1523 byte_t * p_data8; /* area data, for clearing (slow) */
1525 /* Choose buffer and set display dimensions */
1526 p_buffer = &p_vout->p_buffer[ p_vout->i_buffer_index ];
1527 i_vout_width = p_vout->i_width;
1528 i_vout_height = p_vout->i_height;
1531 * Computes new picture size
1535 /* Try horizontal scaling first - width must be a mutiple of 16 */
1536 i_pic_width = (( p_vout->b_scale || (p_pic->i_width > i_vout_width)) ?
1537 i_vout_width : p_pic->i_width) & ~0xf;
1538 switch( p_pic->i_aspect_ratio )
1540 case AR_3_4_PICTURE:
1541 i_pic_height = i_pic_width * 3 / 4;
1543 case AR_16_9_PICTURE:
1544 i_pic_height = i_pic_width * 9 / 16;
1546 case AR_221_1_PICTURE:
1547 i_pic_height = i_pic_width * 100 / 221;
1549 case AR_SQUARE_PICTURE:
1551 i_pic_height = p_pic->i_height * i_pic_width / p_pic->i_width;
1555 /* If picture dimensions using horizontal scaling are too large, use
1556 * vertical scaling. Since width must be a multiple of 16, height is
1557 * adjusted again after. */
1558 if( i_pic_height > i_vout_height )
1560 i_pic_height = ( p_vout->b_scale || (p_pic->i_height > i_vout_height)) ?
1561 i_vout_height : p_pic->i_height;
1562 switch( p_pic->i_aspect_ratio )
1564 case AR_3_4_PICTURE:
1565 i_pic_width = (i_pic_height * 4 / 3) & ~0xf;
1566 i_pic_height = i_pic_width * 3 / 4;
1568 case AR_16_9_PICTURE:
1569 i_pic_width = (i_pic_height * 16 / 9) & ~0xf;
1570 i_pic_height = i_pic_width * 9 / 16;
1572 case AR_221_1_PICTURE:
1573 i_pic_width = (i_pic_height * 221 / 100) & ~0xf;
1574 i_pic_height = i_pic_width * 100 / 221;
1576 case AR_SQUARE_PICTURE:
1578 i_pic_width = (p_pic->i_width * i_pic_height / p_pic->i_height) & ~0xf;
1579 i_pic_height = p_pic->i_height * i_pic_width / p_pic->i_width;
1584 /* Set picture position */
1585 i_pic_x = (p_vout->i_width - i_pic_width) / 2;
1586 i_pic_y = (p_vout->i_height - i_pic_height) / 2;
1591 /* No picture: size is 0 */
1599 * Set new picture size - if it is smaller than the previous one, clear
1600 * around it. Since picture are centered, only their size is tested.
1602 if( (p_buffer->i_pic_width > i_pic_width) || (p_buffer->i_pic_height > i_pic_height) )
1604 i_old_pic_y = p_buffer->i_pic_y;
1605 i_old_pic_height = p_buffer->i_pic_height;
1606 p_buffer->i_pic_x = i_pic_x;
1607 p_buffer->i_pic_y = i_pic_y;
1608 p_buffer->i_pic_width = i_pic_width;
1609 p_buffer->i_pic_height = i_pic_height;
1610 SetBufferArea( p_vout, 0, i_old_pic_y, p_vout->i_width, i_old_pic_height );
1614 p_buffer->i_pic_x = i_pic_x;
1615 p_buffer->i_pic_y = i_pic_y;
1616 p_buffer->i_pic_width = i_pic_width;
1617 p_buffer->i_pic_height = i_pic_height;
1623 for( i_area = 0; i_area < p_buffer->i_areas; i_area++ )
1626 intf_DbgMsg("clearing picture %p area in buffer %d: %d-%d", p_pic,
1627 p_vout->i_buffer_index, p_buffer->pi_area_begin[i_area], p_buffer->pi_area_end[i_area] );
1629 i_data_size = (p_buffer->pi_area_end[i_area] - p_buffer->pi_area_begin[i_area] + 1) * p_vout->i_bytes_per_line;
1630 p_data = (u64*) (p_buffer->p_data + p_vout->i_bytes_per_line * p_buffer->pi_area_begin[i_area]);
1631 for( i_data_index = i_data_size / 256; i_data_index-- ; )
1633 /* Clear 256 bytes block */
1634 *p_data++ = 0; *p_data++ = 0; *p_data++ = 0; *p_data++ = 0;
1635 *p_data++ = 0; *p_data++ = 0; *p_data++ = 0; *p_data++ = 0;
1636 *p_data++ = 0; *p_data++ = 0; *p_data++ = 0; *p_data++ = 0;
1637 *p_data++ = 0; *p_data++ = 0; *p_data++ = 0; *p_data++ = 0;
1638 *p_data++ = 0; *p_data++ = 0; *p_data++ = 0; *p_data++ = 0;
1639 *p_data++ = 0; *p_data++ = 0; *p_data++ = 0; *p_data++ = 0;
1640 *p_data++ = 0; *p_data++ = 0; *p_data++ = 0; *p_data++ = 0;
1641 *p_data++ = 0; *p_data++ = 0; *p_data++ = 0; *p_data++ = 0;
1643 for( i_data_index = (i_data_size % 256) / 16; i_data_index--; )
1645 /* Clear remaining 16 bytes blocks */
1646 *p_data++ = 0; *p_data++ = 0;
1648 p_data8 = (byte_t *)p_data;
1649 for( i_data_index = i_data_size % 16; i_data_index--; )
1651 /* Clear remaining bytes */
1659 p_buffer->i_areas = 0;
1662 /*****************************************************************************
1663 * RenderPicture: render a picture
1664 *****************************************************************************
1665 * This function converts a picture from a video heap to a pixel-encoded image
1666 * and copies it to the current rendering buffer. No lock is required, since
1667 * the * rendered picture has been determined as existant, and will only be
1668 * destroyed by the vout thread later.
1669 *****************************************************************************/
1670 static void RenderPicture( vout_thread_t *p_vout, picture_t *p_pic )
1673 char psz_date[MSTRTIME_MAX_SIZE]; /* picture date */
1674 mtime_t render_time; /* picture rendering time */
1676 vout_buffer_t * p_buffer; /* rendering buffer */
1677 byte_t * p_pic_data; /* convertion destination */
1679 /* Get and set rendering information */
1680 p_buffer = &p_vout->p_buffer[ p_vout->i_buffer_index ];
1681 p_pic_data = p_buffer->p_data +
1682 p_buffer->i_pic_x * p_vout->i_bytes_per_pixel +
1683 p_buffer->i_pic_y * p_vout->i_bytes_per_line;
1685 render_time = mdate();
1691 * Choose appropriate rendering function and render picture
1693 switch( p_pic->i_type )
1695 case YUV_420_PICTURE:
1696 p_vout->yuv.p_Convert420( 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 );
1703 case YUV_422_PICTURE:
1704 p_vout->yuv.p_Convert422( p_vout, p_pic_data,
1705 p_pic->p_y, p_pic->p_u, p_pic->p_v,
1706 p_pic->i_width, p_pic->i_height,
1707 p_buffer->i_pic_width, p_buffer->i_pic_height,
1708 p_vout->i_bytes_per_line / p_vout->i_bytes_per_pixel,
1709 p_pic->i_matrix_coefficients );
1711 case YUV_444_PICTURE:
1712 p_vout->yuv.p_Convert444( p_vout, p_pic_data,
1713 p_pic->p_y, p_pic->p_u, p_pic->p_v,
1714 p_pic->i_width, p_pic->i_height,
1715 p_buffer->i_pic_width, p_buffer->i_pic_height,
1716 p_vout->i_bytes_per_line / p_vout->i_bytes_per_pixel,
1717 p_pic->i_matrix_coefficients );
1721 intf_DbgMsg("error: unknown picture type %d", p_pic->i_type );
1727 /* Print picture date and rendering time */
1728 intf_DbgMsg("picture %p rendered in buffer %d (%ld us), display date: %s", p_pic,
1729 p_vout->i_buffer_index, (long) (mdate() - render_time),
1730 mstrtime( psz_date, p_pic->date ));
1734 /*****************************************************************************
1735 * RenderPictureInfo: print additionnal information on a picture
1736 *****************************************************************************
1737 * This function will print information such as fps and other picture
1738 * dependant information.
1739 *****************************************************************************/
1740 static void RenderPictureInfo( vout_thread_t *p_vout, picture_t *p_pic )
1742 char psz_buffer[256]; /* string buffer */
1745 * Print FPS rate in upper right corner
1747 if( p_vout->c_fps_samples > VOUT_FPS_SAMPLES )
1749 long i_fps = VOUT_FPS_SAMPLES * 1000000 * 10 /
1750 ( p_vout->p_fps_sample[ (p_vout->c_fps_samples - 1)
1751 % VOUT_FPS_SAMPLES ] -
1752 p_vout->p_fps_sample[ p_vout->c_fps_samples
1753 % VOUT_FPS_SAMPLES ] );
1754 sprintf( psz_buffer, "%li.%i fps", i_fps / 10, (int)i_fps % 10 );
1755 Print( p_vout, 0, 0, RIGHT_RALIGN, TOP_RALIGN, psz_buffer );
1759 * Print frames count and loop time in upper left corner
1761 sprintf( psz_buffer, "%ld frames, render: %ldus",
1762 (long) p_vout->c_fps_samples, (long) p_vout->render_time );
1763 Print( p_vout, 0, 0, LEFT_RALIGN, TOP_RALIGN, psz_buffer );
1767 * Print picture information in lower right corner
1769 sprintf( psz_buffer, "%s picture %dx%d (%dx%d%+d%+d %s) -> %dx%d+%d+%d",
1770 (p_pic->i_type == YUV_420_PICTURE) ? "4:2:0" :
1771 ((p_pic->i_type == YUV_422_PICTURE) ? "4:2:2" :
1772 ((p_pic->i_type == YUV_444_PICTURE) ? "4:4:4" : "ukn-type")),
1773 p_pic->i_width, p_pic->i_height,
1774 p_pic->i_display_width, p_pic->i_display_height,
1775 p_pic->i_display_horizontal_offset, p_pic->i_display_vertical_offset,
1776 (p_pic->i_aspect_ratio == AR_SQUARE_PICTURE) ? "sq" :
1777 ((p_pic->i_aspect_ratio == AR_3_4_PICTURE) ? "4:3" :
1778 ((p_pic->i_aspect_ratio == AR_16_9_PICTURE) ? "16:9" :
1779 ((p_pic->i_aspect_ratio == AR_221_1_PICTURE) ? "2.21:1" : "ukn-ar" ))),
1780 p_vout->p_buffer[ p_vout->i_buffer_index ].i_pic_width,
1781 p_vout->p_buffer[ p_vout->i_buffer_index ].i_pic_height,
1782 p_vout->p_buffer[ p_vout->i_buffer_index ].i_pic_x,
1783 p_vout->p_buffer[ p_vout->i_buffer_index ].i_pic_y );
1784 Print( p_vout, 0, 0, RIGHT_RALIGN, BOTTOM_RALIGN, psz_buffer );
1788 /*****************************************************************************
1789 * RenderSplash: render splash picture
1790 *****************************************************************************
1791 * This function will print something on the screen. It will return 0 if
1792 * nothing has been rendered, or 1 if something has been changed on the screen.
1793 * Note that if you absolutely want something to be printed, you will have
1794 * to force it by setting the last idle date to 0.
1795 * Unlike other rendering functions, this one calls the SetBufferPicture
1796 * function when needed.
1797 *****************************************************************************/
1798 int RenderSplash( vout_thread_t *p_vout )
1800 int i_x = 0, i_y = 0; /* text position */
1801 int i_width, i_height; /* text size */
1802 char *psz_text = "VideoLAN Client (" VERSION ")"; /* text to display */
1804 memset( p_vout->p_buffer[ p_vout->i_buffer_index ].p_data,
1805 p_vout->i_bytes_per_line * p_vout->i_height, 12);
1807 // SetBufferPicture( p_vout, NULL );
1808 vout_TextSize( p_vout->p_large_font, WIDE_TEXT | OUTLINED_TEXT, psz_text,
1809 &i_width, &i_height );
1810 if( !Align( p_vout, &i_x, &i_y, i_width, i_height, CENTER_RALIGN, CENTER_RALIGN ) )
1812 vout_Print( p_vout->p_large_font,
1813 p_vout->p_buffer[ p_vout->i_buffer_index ].p_data +
1814 i_x * p_vout->i_bytes_per_pixel + (i_y - 16 ) * p_vout->i_bytes_per_line,
1815 p_vout->i_bytes_per_pixel, p_vout->i_bytes_per_line,
1816 p_vout->i_white_pixel, p_vout->i_gray_pixel, 0,
1817 WIDE_TEXT | OUTLINED_TEXT, psz_text, 100);
1818 SetBufferArea( p_vout, i_x, i_y, i_width, i_height);
1824 /*****************************************************************************
1825 * RenderIdle: render idle picture
1826 *****************************************************************************
1827 * This function will print something on the screen. It will return 0 if
1828 * nothing has been rendered, or 1 if something has been changed on the screen.
1829 * Note that if you absolutely want something to be printed, you will have
1830 * to force it by setting the last idle date to 0.
1831 * Unlike other rendering functions, this one calls the SetBufferPicture
1832 * function when needed.
1833 *****************************************************************************/
1834 int RenderIdle( vout_thread_t *p_vout )
1837 int i_x = 0, i_y = 0; /* text position */
1838 int i_width, i_height; /* text size */
1839 int i_amount = 0; /* amount to draw */
1840 char *psz_text = "Waiting for stream"; /* text to display */
1841 char *psz_wtext = "[................]";
1843 mtime_t current_date; /* current date */
1846 memset( p_vout->p_buffer[ p_vout->i_buffer_index ].p_data,
1847 p_vout->i_bytes_per_line * p_vout->i_height, 12);
1850 current_date = mdate();
1851 if( (current_date - p_vout->last_display_date) > VOUT_IDLE_DELAY
1852 // && (current_date - p_vout->last_idle_date) > VOUT_IDLE_DELAY
1855 /* FIXME: idle screen disabled */
1857 SetBufferPicture( p_vout, NULL );
1858 vout_TextSize( p_vout->p_large_font, WIDE_TEXT | OUTLINED_TEXT, psz_text,
1859 &i_width, &i_height );
1860 if( !Align( p_vout, &i_x, &i_y, i_width, i_height * 2, CENTER_RALIGN, CENTER_RALIGN ) )
1862 i_amount = (int) ((current_date - p_vout->last_display_date ) / 5000LL);
1863 vout_Print( p_vout->p_large_font,
1864 p_vout->p_buffer[ p_vout->i_buffer_index ].p_data +
1865 i_x * p_vout->i_bytes_per_pixel + i_y * p_vout->i_bytes_per_line,
1866 p_vout->i_bytes_per_pixel, p_vout->i_bytes_per_line,
1867 p_vout->i_white_pixel, p_vout->i_gray_pixel, 0,
1868 WIDE_TEXT | OUTLINED_TEXT, psz_text, (i_amount / 3 ) %110);
1870 vout_Print( p_vout->p_large_font,
1871 p_vout->p_buffer[ p_vout->i_buffer_index ].p_data +
1872 i_x * p_vout->i_bytes_per_pixel + (i_y + 16) * p_vout->i_bytes_per_line,
1873 p_vout->i_bytes_per_pixel, p_vout->i_bytes_per_line,
1874 p_vout->i_white_pixel, p_vout->i_gray_pixel, 0,
1875 WIDE_TEXT | OUTLINED_TEXT, psz_wtext, (i_amount/5)%110 );
1878 SetBufferArea( p_vout, i_x, i_y, i_width, i_height * 2 );
1886 /*****************************************************************************
1887 * RenderInfo: render additionnal information
1888 *****************************************************************************
1889 * This function renders information which do not depend on the current
1891 *****************************************************************************/
1892 static void RenderInfo( vout_thread_t *p_vout )
1895 char psz_buffer[256]; /* string buffer */
1896 int i_ready_pic = 0; /* ready pictures */
1897 int i_reserved_pic = 0; /* reserved pictures */
1898 int i_picture; /* picture index */
1903 * Print thread state in lower left corner
1905 for( i_picture = 0; i_picture < VOUT_MAX_PICTURES; i_picture++ )
1907 switch( p_vout->p_picture[i_picture].i_status )
1909 case RESERVED_PICTURE:
1910 case RESERVED_DATED_PICTURE:
1911 case RESERVED_DISP_PICTURE:
1919 sprintf( psz_buffer, "pic: %d (%d/%d)/%d",
1920 p_vout->i_pictures, i_reserved_pic, i_ready_pic, VOUT_MAX_PICTURES );
1921 Print( p_vout, 0, 0, LEFT_RALIGN, BOTTOM_RALIGN, psz_buffer );
1925 /*****************************************************************************
1926 * RenderSubPicture: render a subpicture
1927 *****************************************************************************
1928 * This function renders a sub picture unit.
1929 *****************************************************************************/
1930 static void RenderSubPicture( vout_thread_t *p_vout, subpicture_t *p_subpic )
1932 p_vout_font_t p_font; /* text font */
1933 int i_width, i_height; /* subpicture dimensions */
1935 while( p_subpic != NULL )
1937 switch( p_subpic->i_type )
1939 case DVD_SUBPICTURE: /* DVD subpicture unit */
1940 /* test if the picture really has to be displayed */
1941 if( mdate() < p_subpic->begin_date )
1943 /* not yet, see you later */
1946 if( mdate() > p_subpic->end_date )
1948 /* too late, destroying the subpic */
1949 vout_DestroySubPicture( p_vout, p_subpic );
1952 vout_RenderSPU( &p_vout->p_buffer[ p_vout->i_buffer_index ],
1953 p_subpic, p_vout->i_bytes_per_pixel,
1954 p_vout->i_bytes_per_line );
1956 case TEXT_SUBPICTURE: /* single line text */
1957 /* Select default font if not specified */
1958 p_font = p_subpic->type.text.p_font;
1959 if( p_font == NULL )
1961 p_font = p_vout->p_default_font;
1964 /* Compute text size (width and height fields are ignored)
1966 vout_TextSize( p_font, p_subpic->type.text.i_style,
1967 p_subpic->p_data, &i_width, &i_height );
1968 if( !Align( p_vout, &p_subpic->i_x, &p_subpic->i_y,
1969 i_width, i_height, p_subpic->i_horizontal_align,
1970 p_subpic->i_vertical_align ) )
1973 p_vout->p_buffer[ p_vout->i_buffer_index ].p_data +
1974 p_subpic->i_x * p_vout->i_bytes_per_pixel +
1975 p_subpic->i_y * p_vout->i_bytes_per_line,
1976 p_vout->i_bytes_per_pixel, p_vout->i_bytes_per_line,
1977 p_subpic->type.text.i_char_color,
1978 p_subpic->type.text.i_border_color,
1979 p_subpic->type.text.i_bg_color,
1980 p_subpic->type.text.i_style, p_subpic->p_data, 100 );
1981 SetBufferArea( p_vout, p_subpic->i_x, p_subpic->i_y,
1982 i_width, i_height );
1988 intf_DbgMsg( "error: unknown subpicture %p type %d",
1989 p_subpic, p_subpic->i_type );
1993 p_subpic = p_subpic->p_next;
1997 /*****************************************************************************
1998 * RenderInterface: render the interface
1999 *****************************************************************************
2000 * This function renders the interface, if any.
2001 *****************************************************************************/
2002 static void RenderInterface( vout_thread_t *p_vout )
2004 int i_height, i_text_height; /* total and text height */
2005 int i_width_1, i_width_2; /* text width */
2006 int i_byte; /* byte index */
2007 const char *psz_text_1 = "[1-9] Channel [i]nfo [c]olor [g/G]amma";
2008 const char *psz_text_2 = "[+/-] Volume [m]ute [s]caling [Q]uit";
2011 vout_TextSize( p_vout->p_large_font, OUTLINED_TEXT, psz_text_1, &i_width_1, &i_height );
2012 vout_TextSize( p_vout->p_large_font, OUTLINED_TEXT, psz_text_2, &i_width_2, &i_text_height );
2013 i_height += i_text_height;
2015 /* Render background */
2016 for( i_byte = (p_vout->i_height - i_height) * p_vout->i_bytes_per_line;
2017 i_byte < p_vout->i_height * p_vout->i_bytes_per_line;
2021 p_vout->p_buffer[ p_vout->i_buffer_index ].p_data[ i_byte ] = p_vout->i_blue_pixel;
2024 /* Render text, if not larger than screen */
2025 if( i_width_1 < p_vout->i_width )
2027 vout_Print( p_vout->p_large_font, p_vout->p_buffer[ p_vout->i_buffer_index ].p_data +
2028 (p_vout->i_height - i_height) * p_vout->i_bytes_per_line,
2029 p_vout->i_bytes_per_pixel, p_vout->i_bytes_per_line,
2030 p_vout->i_white_pixel, p_vout->i_black_pixel, 0,
2031 OUTLINED_TEXT, psz_text_1, 100 );
2033 if( i_width_2 < p_vout->i_width )
2035 vout_Print( p_vout->p_large_font, p_vout->p_buffer[ p_vout->i_buffer_index ].p_data +
2036 (p_vout->i_height - i_height + i_text_height) * p_vout->i_bytes_per_line,
2037 p_vout->i_bytes_per_pixel, p_vout->i_bytes_per_line,
2038 p_vout->i_white_pixel, p_vout->i_black_pixel, 0,
2039 OUTLINED_TEXT, psz_text_2, 100 );
2042 /* Activate modified area */
2043 SetBufferArea( p_vout, 0, p_vout->i_height - i_height, p_vout->i_width, i_height );
2046 /*****************************************************************************
2047 * Manage: manage thread
2048 *****************************************************************************
2049 * This function will handle changes in thread configuration.
2050 *****************************************************************************/
2051 static int Manage( vout_thread_t *p_vout )
2054 if( p_vout->i_changes )
2056 intf_DbgMsg("changes: 0x%x (no display: 0x%x)", p_vout->i_changes,
2057 0 /* p_vout->i_changes & VOUT_NODISPLAY_CHANGE */ );
2061 /* On gamma or grayscale change, rebuild tables */
2062 if( p_vout->i_changes & (VOUT_GAMMA_CHANGE | VOUT_GRAYSCALE_CHANGE |
2065 if( vout_ResetYUV( p_vout ) )
2067 intf_ErrMsg( "vout error: can't rebuild conversion tables" );
2072 /* Clear changes flags which does not need management or have been
2074 p_vout->i_changes &= ~(VOUT_GAMMA_CHANGE | VOUT_GRAYSCALE_CHANGE |
2075 VOUT_YUV_CHANGE | VOUT_INFO_CHANGE |
2076 VOUT_INTF_CHANGE | VOUT_SCALE_CHANGE |
2077 VOUT_CURSOR_CHANGE | VOUT_FULLSCREEN_CHANGE );
2079 /* Detect unauthorized changes */
2080 if( p_vout->i_changes )
2082 /* Some changes were not acknowledged by p_vout->pf_manage or this
2083 * function, it means they should not be authorized */
2084 intf_ErrMsg( "vout error: unauthorized changes in the vout thread" );
2091 /*****************************************************************************
2092 * Align: align a subpicture in the screen
2093 *****************************************************************************
2094 * This function is used for rendering text or subpictures. It returns non 0
2095 * it the final aera is not fully included in display area. Return coordinates
2097 *****************************************************************************/
2098 static int Align( vout_thread_t *p_vout, int *pi_x, int *pi_y,
2099 int i_width, int i_height, int i_h_align, int i_v_align )
2101 /* Align horizontally */
2105 *pi_x -= i_width / 2;
2108 *pi_x += (p_vout->i_width - i_width) / 2;
2114 *pi_x += p_vout->i_width - i_width;
2118 /* Align vertically */
2122 *pi_y -= i_height / 2;
2125 *pi_y += (p_vout->i_height - i_height) / 2;
2131 *pi_y += p_vout->i_height - i_height;
2133 case SUBTITLE_RALIGN:
2134 *pi_y += (p_vout->i_height + p_vout->p_buffer[ p_vout->i_buffer_index ].i_pic_y +
2135 p_vout->p_buffer[ p_vout->i_buffer_index ].i_pic_height - i_height) / 2;
2139 /* Return non 0 if clipping failed */
2140 return( (*pi_x < 0) || (*pi_y < 0) ||
2141 (*pi_x + i_width > p_vout->i_width) || (*pi_y + i_height > p_vout->i_height) );
2144 /*****************************************************************************
2145 * SetPalette: sets an 8 bpp palette
2146 *****************************************************************************
2147 * This function is just a prototype that does nothing. Architectures that
2148 * support palette allocation should override it.
2149 *****************************************************************************/
2150 static void SetPalette ( p_vout_thread_t p_vout, u16 *red,
2151 u16 *green, u16 *blue, u16 *transp )
2153 intf_ErrMsg( "vout error: method does not support palette changing" );