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_WarnMsg( 1, "wished configuration: %dx%d, %d/%d bpp (%d Bpl)",
165 p_vout->i_width, p_vout->i_height, p_vout->i_screen_depth,
166 p_vout->i_bytes_per_pixel * 8, p_vout->i_bytes_per_line );
168 /* Initialize idle screen */
169 p_vout->last_display_date = 0;
170 p_vout->last_idle_date = 0;
171 p_vout->init_display_date = mdate();
172 p_vout->render_time = 10000;
174 /* Initialize statistics fields */
175 p_vout->c_fps_samples = 0;
177 /* Initialize buffer index */
178 p_vout->i_buffer_index = 0;
180 /* Initialize pictures and subpictures - translation tables and functions
181 * will be initialized later in InitThread */
182 for( i_index = 0; i_index < VOUT_MAX_PICTURES; i_index++)
184 p_vout->p_picture[i_index].i_type = EMPTY_PICTURE;
185 p_vout->p_picture[i_index].i_status = FREE_PICTURE;
187 for( i_index = 0; i_index < VOUT_MAX_SUBPICTURES; i_index++)
189 p_vout->p_subpicture[i_index].i_type = EMPTY_SUBPICTURE;
190 p_vout->p_subpicture[i_index].i_status= FREE_SUBPICTURE;
192 p_vout->i_pictures = 0;
194 /* Create and initialize system-dependant method - this function issues its
195 * own error messages */
196 if( p_vout->pf_create( p_vout ) )
198 module_Unneed( p_main->p_bank, p_vout->p_module );
202 intf_WarnMsg( 1, "actual configuration: %dx%d, %d/%d bpp (%d Bpl), "
203 "masks: 0x%x/0x%x/0x%x",
204 p_vout->i_width, p_vout->i_height, p_vout->i_screen_depth,
205 p_vout->i_bytes_per_pixel * 8, p_vout->i_bytes_per_line,
206 p_vout->i_red_mask, p_vout->i_green_mask,
207 p_vout->i_blue_mask );
209 /* Calculate shifts from system-updated masks */
210 MaskToShift( &p_vout->i_red_lshift, &p_vout->i_red_rshift,
211 p_vout->i_red_mask );
212 MaskToShift( &p_vout->i_green_lshift, &p_vout->i_green_rshift,
213 p_vout->i_green_mask );
214 MaskToShift( &p_vout->i_blue_lshift, &p_vout->i_blue_rshift,
215 p_vout->i_blue_mask );
217 /* Set some useful colors */
218 p_vout->i_white_pixel = RGB2PIXEL( p_vout, 255, 255, 255 );
219 p_vout->i_black_pixel = RGB2PIXEL( p_vout, 0, 0, 0 );
220 p_vout->i_gray_pixel = RGB2PIXEL( p_vout, 128, 128, 128 );
221 p_vout->i_blue_pixel = RGB2PIXEL( p_vout, 0, 0, 50 );
223 /* Load fonts - fonts must be initialized after the system method since
224 * they may be dependant on screen depth and other thread properties */
225 p_vout->p_default_font = vout_LoadFont( 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 /* Initialize convertion tables and functions */
934 if( vout_InitYUV( p_vout ) )
936 intf_ErrMsg("vout error: can't allocate YUV translation tables");
940 /* Mark thread as running and return */
941 p_vout->b_active = 1;
942 *p_vout->pi_status = THREAD_READY;
945 intf_DbgMsg("thread ready");
949 /*****************************************************************************
950 * RunThread: video output thread
951 *****************************************************************************
952 * Video output thread. This function does only returns when the thread is
953 * terminated. It handles the pictures arriving in the video heap and the
954 * display device events.
955 *****************************************************************************/
956 static void RunThread( vout_thread_t *p_vout)
958 int i_index; /* index in heap */
959 mtime_t current_date; /* current date */
960 mtime_t display_date; /* display date */
961 boolean_t b_display; /* display flag */
962 picture_t * p_pic; /* picture pointer */
963 subpicture_t * p_subpic; /* subpicture pointer */
968 p_vout->b_error = InitThread( p_vout );
969 if( p_vout->b_error )
971 DestroyThread( p_vout, THREAD_ERROR );
976 * Main loop - it is not executed if an error occured during
979 while( (!p_vout->b_die) && (!p_vout->b_error) )
981 /* Initialize loop variables */
985 current_date = mdate();
988 if( !(p_vout->c_loops % VOUT_STATS_NB_LOOPS) )
990 intf_Msg("vout stats: picture heap: %d/%d",
991 p_vout->i_pictures, VOUT_MAX_PICTURES);
996 * Find the picture to display - this operation does not need lock,
997 * since only READY_PICTUREs are handled
999 for( i_index = 0; i_index < VOUT_MAX_PICTURES; i_index++ )
1001 if( (p_vout->p_picture[i_index].i_status == READY_PICTURE) &&
1002 ( (p_pic == NULL) ||
1003 (p_vout->p_picture[i_index].date < display_date) ) )
1005 p_pic = &p_vout->p_picture[i_index];
1006 display_date = p_pic->date;
1012 /* Computes FPS rate */
1013 p_vout->p_fps_sample[ p_vout->c_fps_samples++ % VOUT_FPS_SAMPLES ] = display_date;
1015 if( display_date < current_date - p_vout->render_time )
1017 /* Picture is late: it will be destroyed and the thread
1018 * will sleep and go to next picture */
1020 vlc_mutex_lock( &p_vout->picture_lock );
1021 if( p_pic->i_refcount )
1023 p_pic->i_status = DISPLAYED_PICTURE;
1027 p_pic->i_status = DESTROYED_PICTURE;
1028 p_vout->i_pictures--;
1031 "warning: late picture skipped (%p)", p_pic );
1032 vlc_mutex_unlock( &p_vout->picture_lock );
1036 else if( display_date > current_date + VOUT_DISPLAY_DELAY )
1038 /* A picture is ready to be rendered, but its rendering date
1039 * is far from the current one so the thread will perform an
1040 * empty loop as if no picture were found. The picture state
1047 * Find the subpictures to display - this operation does not need
1048 * lock, since only READY_SUBPICTURE are handled. If no picture
1049 * has been selected, display_date will depend on the subpicture.
1050 * We get an easily parsable chained list of subpictures which
1051 * ends with NULL since p_subpic was initialized to NULL.
1053 for( i_index = 0; i_index < VOUT_MAX_SUBPICTURES; i_index++ )
1055 if( p_vout->p_subpicture[i_index].i_status == READY_SUBPICTURE )
1057 p_vout->p_subpicture[i_index].p_next = p_subpic;
1058 p_subpic = &p_vout->p_subpicture[i_index];
1063 * Perform rendering, sleep and display rendered picture
1065 if( p_pic ) /* picture and perhaps subpicture */
1067 b_display = p_vout->b_active;
1068 p_vout->last_display_date = display_date;
1069 p_vout->p_rendered_pic = p_pic;
1074 /* Set picture dimensions and clear buffer */
1075 SetBufferPicture( p_vout, p_pic );
1077 /* FIXME: if b_need_render == 0 we need to do something with
1078 * the subpictures one day. */
1080 if( p_vout->b_need_render && b_display )
1082 /* Render picture and information */
1083 RenderPicture( p_vout, p_pic );
1084 if( p_vout->b_info )
1086 RenderPictureInfo( p_vout, p_pic );
1087 RenderInfo( p_vout );
1091 RenderSubPicture( p_vout, p_subpic );
1095 /* Render interface and subpicture */
1096 if( b_display && p_vout->b_interface && p_vout->b_need_render )
1098 RenderInterface( p_vout );
1102 else if( p_vout->b_active && p_vout->b_need_render
1103 && p_vout->init_display_date == 0)
1105 /* Idle or interface screen alone */
1107 if( p_vout->b_interface && 0 /* && XXX?? intf_change */ )
1109 /* Interface has changed, so a new rendering is required - force
1110 * it by setting last idle date to 0 */
1111 p_vout->last_idle_date = 0;
1114 /* Render idle screen and update idle date, then render interface if
1116 b_display = RenderIdle( p_vout );
1119 p_vout->last_idle_date = current_date;
1120 if( p_vout->b_interface )
1122 RenderInterface( p_vout );
1134 * Check for the current time and
1135 * display splash screen if everything is on time
1137 if( p_vout->init_display_date > 0 && p_vout->b_need_render )
1139 if( p_vout->b_active &&
1140 mdate()-p_vout->init_display_date < 5000000)
1142 /* there is something to display ! */
1144 RenderSplash( p_vout );
1147 /* no splash screen ! */
1148 p_vout->init_display_date=0;
1154 * Sleep, wake up and display rendered picture
1157 if( display_date != 0 )
1159 /* Store render time using Bresenham algorithm */
1160 p_vout->render_time += mdate() - current_date;
1161 p_vout->render_time >>= 1;
1164 /* Give back change lock */
1165 vlc_mutex_unlock( &p_vout->change_lock );
1167 /* Sleep a while or until a given date */
1168 if( display_date != 0 )
1170 mwait( display_date - VOUT_MWAIT_TOLERANCE );
1174 msleep( VOUT_IDLE_SLEEP );
1177 /* On awakening, take back lock and send immediately picture to display,
1178 * then swap buffers */
1179 vlc_mutex_lock( &p_vout->change_lock );
1181 intf_DbgMsg( "picture %p, subpicture %p in buffer %d, display=%d", p_pic, p_subpic,
1182 p_vout->i_buffer_index, b_display /* && !(p_vout->i_changes & VOUT_NODISPLAY_CHANGE) */ );
1184 if( b_display /* && !(p_vout->i_changes & VOUT_NODISPLAY_CHANGE) */ )
1186 p_vout->pf_display( p_vout );
1188 p_vout->i_buffer_index = ++p_vout->i_buffer_index & 1;
1194 /* Remove picture from heap */
1195 vlc_mutex_lock( &p_vout->picture_lock );
1196 if( p_pic->i_refcount )
1198 p_pic->i_status = DISPLAYED_PICTURE;
1202 p_pic->i_status = DESTROYED_PICTURE;
1203 p_vout->i_pictures--;
1205 vlc_mutex_unlock( &p_vout->picture_lock );
1210 * Check events and manage thread
1212 if( p_vout->pf_manage( p_vout ) | Manage( p_vout ) )
1214 /* A fatal error occured, and the thread must terminate immediately,
1215 * without displaying anything - setting b_error to 1 cause the
1216 * immediate end of the main while() loop. */
1217 p_vout->b_error = 1;
1222 * Error loop - wait until the thread destruction is requested
1224 if( p_vout->b_error )
1226 ErrorThread( p_vout );
1230 EndThread( p_vout );
1231 DestroyThread( p_vout, THREAD_OVER );
1232 intf_DbgMsg( "thread end" );
1235 /*****************************************************************************
1236 * ErrorThread: RunThread() error loop
1237 *****************************************************************************
1238 * This function is called when an error occured during thread main's loop. The
1239 * thread can still receive feed, but must be ready to terminate as soon as
1241 *****************************************************************************/
1242 static void ErrorThread( vout_thread_t *p_vout )
1244 /* Wait until a `die' order */
1245 while( !p_vout->b_die )
1248 msleep( VOUT_IDLE_SLEEP );
1252 /*****************************************************************************
1253 * EndThread: thread destruction
1254 *****************************************************************************
1255 * This function is called when the thread ends after a sucessful
1256 * initialization. It frees all ressources allocated by InitThread.
1257 *****************************************************************************/
1258 static void EndThread( vout_thread_t *p_vout )
1260 int i_index; /* index in heap */
1263 *p_vout->pi_status = THREAD_END;
1267 struct tms cpu_usage;
1268 times( &cpu_usage );
1270 intf_Msg( "vout stats: cpu usage (user: %d, system: %d)",
1271 cpu_usage.tms_utime, cpu_usage.tms_stime );
1275 /* Destroy all remaining pictures and subpictures */
1276 for( i_index = 0; i_index < VOUT_MAX_PICTURES; i_index++ )
1278 if( p_vout->p_picture[i_index].i_status != FREE_PICTURE )
1280 free( p_vout->p_picture[i_index].p_data );
1284 for( i_index = 0; i_index < VOUT_MAX_SUBPICTURES; i_index++ )
1286 if( p_vout->p_subpicture[i_index].i_status != FREE_SUBPICTURE )
1288 free( p_vout->p_subpicture[i_index].p_data );
1292 /* Destroy translation tables */
1293 vout_EndYUV( p_vout );
1294 p_vout->pf_end( p_vout );
1296 /* Release the change lock */
1297 vlc_mutex_unlock( &p_vout->change_lock );
1300 /*****************************************************************************
1301 * DestroyThread: thread destruction
1302 *****************************************************************************
1303 * This function is called when the thread ends. It frees all ressources
1304 * allocated by CreateThread. Status is available at this stage.
1305 *****************************************************************************/
1306 static void DestroyThread( vout_thread_t *p_vout, int i_status )
1308 int *pi_status; /* status adress */
1310 /* Store status adress */
1311 pi_status = p_vout->pi_status;
1313 /* Destroy thread structures allocated by Create and InitThread */
1314 vout_UnloadFont( p_vout->p_default_font );
1315 vout_UnloadFont( p_vout->p_large_font );
1316 p_vout->pf_destroy( p_vout );
1318 /* Destroy the locks */
1319 vlc_mutex_destroy( &p_vout->picture_lock );
1320 vlc_mutex_destroy( &p_vout->subpicture_lock );
1321 vlc_mutex_destroy( &p_vout->change_lock );
1323 /* Release the module */
1324 module_Unneed( p_main->p_bank, p_vout->p_module );
1326 /* Free structure */
1328 *pi_status = i_status;
1331 /*****************************************************************************
1332 * Print: print simple text on a picture
1333 *****************************************************************************
1334 * This function will print a simple text on the picture. It is designed to
1335 * print debugging or general information.
1336 *****************************************************************************/
1337 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 )
1339 int i_text_height; /* total text height */
1340 int i_text_width; /* total text width */
1342 /* Update upper left coordinates according to alignment */
1343 vout_TextSize( p_vout->p_default_font, 0, psz_text, &i_text_width, &i_text_height );
1344 if( !Align( p_vout, &i_x, &i_y, i_text_width, i_text_height, i_h_align, i_v_align ) )
1346 /* Set area and print text */
1347 SetBufferArea( p_vout, i_x, i_y, i_text_width, i_text_height );
1348 vout_Print( p_vout->p_default_font, p_vout->p_buffer[ p_vout->i_buffer_index ].p_data +
1349 i_y * p_vout->i_bytes_per_line + i_x * p_vout->i_bytes_per_pixel,
1350 p_vout->i_bytes_per_pixel, p_vout->i_bytes_per_line,
1351 p_vout->i_white_pixel, 0, 0,
1356 /*****************************************************************************
1357 * SetBufferArea: activate an area in current buffer
1358 *****************************************************************************
1359 * This function is called when something is rendered on the current buffer.
1360 * It set the area as active and prepare it to be cleared on next rendering.
1361 * Pay attention to the fact that in this functions, i_h is in fact the end y
1362 * coordinate of the new area.
1363 *****************************************************************************/
1364 static void SetBufferArea( vout_thread_t *p_vout, int i_x, int i_y, int i_w, int i_h )
1366 vout_buffer_t * p_buffer; /* current buffer */
1367 int i_area_begin, i_area_end; /* area vertical extension */
1368 int i_area, i_area_copy; /* area index */
1369 int i_area_shift; /* shift distance for areas */
1371 /* Choose buffer and modify h to end of area position */
1372 p_buffer = &p_vout->p_buffer[ p_vout->i_buffer_index ];
1376 * Remove part of the area which is inside the picture - this is done
1377 * by calling again SetBufferArea with the correct areas dimensions.
1379 if( (i_x >= p_buffer->i_pic_x) && (i_x + i_w <= p_buffer->i_pic_x + p_buffer->i_pic_width) )
1381 i_area_begin = p_buffer->i_pic_y;
1382 i_area_end = i_area_begin + p_buffer->i_pic_height - 1;
1384 if( ((i_y >= i_area_begin) && (i_y <= i_area_end)) ||
1385 ((i_h >= i_area_begin) && (i_h <= i_area_end)) ||
1386 ((i_y < i_area_begin) && (i_h > i_area_end)) )
1388 /* Keep the stripe above the picture, if any */
1389 if( i_y < i_area_begin )
1391 SetBufferArea( p_vout, i_x, i_y, i_w, i_area_begin - i_y );
1393 /* Keep the stripe below the picture, if any */
1394 if( i_h > i_area_end )
1396 SetBufferArea( p_vout, i_x, i_area_end, i_w, i_h - i_area_end );
1402 /* Skip some extensions until interesting areas */
1404 (i_area < p_buffer->i_areas) &&
1405 (p_buffer->pi_area_end[i_area] + 1 <= i_y);
1411 if( i_area == p_buffer->i_areas )
1413 /* New area is below all existing ones: just add it at the end of the
1414 * array, if possible - otherwise, append it to the last one */
1415 if( i_area < VOUT_MAX_AREAS )
1417 p_buffer->pi_area_begin[i_area] = i_y;
1418 p_buffer->pi_area_end[i_area] = i_h;
1419 p_buffer->i_areas++;
1424 intf_DbgMsg("area overflow");
1426 p_buffer->pi_area_end[VOUT_MAX_AREAS - 1] = i_h;
1431 i_area_begin = p_buffer->pi_area_begin[i_area];
1432 i_area_end = p_buffer->pi_area_end[i_area];
1434 if( i_y < i_area_begin )
1436 if( i_h >= i_area_begin - 1 )
1438 /* Extend area above */
1439 p_buffer->pi_area_begin[i_area] = i_y;
1443 /* Create a new area above : merge last area if overflow, then
1444 * move all old areas down */
1445 if( p_buffer->i_areas == VOUT_MAX_AREAS )
1448 intf_DbgMsg("areas overflow");
1450 p_buffer->pi_area_end[VOUT_MAX_AREAS - 2] = p_buffer->pi_area_end[VOUT_MAX_AREAS - 1];
1454 p_buffer->i_areas++;
1456 for( i_area_copy = p_buffer->i_areas - 1; i_area_copy > i_area; i_area_copy-- )
1458 p_buffer->pi_area_begin[i_area_copy] = p_buffer->pi_area_begin[i_area_copy - 1];
1459 p_buffer->pi_area_end[i_area_copy] = p_buffer->pi_area_end[i_area_copy - 1];
1461 p_buffer->pi_area_begin[i_area] = i_y;
1462 p_buffer->pi_area_end[i_area] = i_h;
1466 if( i_h > i_area_end )
1468 /* Find further areas which can be merged with the new one */
1469 for( i_area_copy = i_area + 1;
1470 (i_area_copy < p_buffer->i_areas) &&
1471 (p_buffer->pi_area_begin[i_area] <= i_h);
1478 if( i_area_copy != i_area )
1480 /* Merge with last possible areas */
1481 p_buffer->pi_area_end[i_area] = MAX( i_h, p_buffer->pi_area_end[i_area_copy] );
1483 /* Shift lower areas upward */
1484 i_area_shift = i_area_copy - i_area;
1485 p_buffer->i_areas -= i_area_shift;
1486 for( i_area_copy = i_area + 1; i_area_copy < p_buffer->i_areas; i_area_copy++ )
1488 p_buffer->pi_area_begin[i_area_copy] = p_buffer->pi_area_begin[i_area_copy + i_area_shift];
1489 p_buffer->pi_area_end[i_area_copy] = p_buffer->pi_area_end[i_area_copy + i_area_shift];
1494 /* Extend area below */
1495 p_buffer->pi_area_end[i_area] = i_h;
1501 /*****************************************************************************
1502 * SetBufferPicture: clear buffer and set picture area
1503 *****************************************************************************
1504 * This function is called before any rendering. It clears the current
1505 * rendering buffer and set the new picture area. If the picture pointer is
1506 * NULL, then no picture area is defined. Floating operations are avoided since
1507 * some MMX calculations may follow.
1508 *****************************************************************************/
1509 static void SetBufferPicture( vout_thread_t *p_vout, picture_t *p_pic )
1511 vout_buffer_t * p_buffer; /* current buffer */
1512 int i_pic_x, i_pic_y; /* picture position */
1513 int i_pic_width, i_pic_height; /* picture dimensions */
1514 int i_old_pic_y, i_old_pic_height; /* old picture area */
1515 int i_vout_width, i_vout_height; /* display dimensions */
1516 int i_area; /* area index */
1517 int i_data_index; /* area data index */
1518 int i_data_size; /* area data size, in 256 bytes blocs */
1519 u64 * p_data; /* area data, for clearing */
1520 byte_t * p_data8; /* area data, for clearing (slow) */
1522 /* Choose buffer and set display dimensions */
1523 p_buffer = &p_vout->p_buffer[ p_vout->i_buffer_index ];
1524 i_vout_width = p_vout->i_width;
1525 i_vout_height = p_vout->i_height;
1528 * Computes new picture size
1532 /* Try horizontal scaling first - width must be a mutiple of 16 */
1533 i_pic_width = (( p_vout->b_scale || (p_pic->i_width > i_vout_width)) ?
1534 i_vout_width : p_pic->i_width) & ~0xf;
1535 switch( p_pic->i_aspect_ratio )
1537 case AR_3_4_PICTURE:
1538 i_pic_height = i_pic_width * 3 / 4;
1540 case AR_16_9_PICTURE:
1541 i_pic_height = i_pic_width * 9 / 16;
1543 case AR_221_1_PICTURE:
1544 i_pic_height = i_pic_width * 100 / 221;
1546 case AR_SQUARE_PICTURE:
1548 i_pic_height = p_pic->i_height * i_pic_width / p_pic->i_width;
1552 /* If picture dimensions using horizontal scaling are too large, use
1553 * vertical scaling. Since width must be a multiple of 16, height is
1554 * adjusted again after. */
1555 if( i_pic_height > i_vout_height )
1557 i_pic_height = ( p_vout->b_scale || (p_pic->i_height > i_vout_height)) ?
1558 i_vout_height : p_pic->i_height;
1559 switch( p_pic->i_aspect_ratio )
1561 case AR_3_4_PICTURE:
1562 i_pic_width = (i_pic_height * 4 / 3) & ~0xf;
1563 i_pic_height = i_pic_width * 3 / 4;
1565 case AR_16_9_PICTURE:
1566 i_pic_width = (i_pic_height * 16 / 9) & ~0xf;
1567 i_pic_height = i_pic_width * 9 / 16;
1569 case AR_221_1_PICTURE:
1570 i_pic_width = (i_pic_height * 221 / 100) & ~0xf;
1571 i_pic_height = i_pic_width * 100 / 221;
1573 case AR_SQUARE_PICTURE:
1575 i_pic_width = (p_pic->i_width * i_pic_height / p_pic->i_height) & ~0xf;
1576 i_pic_height = p_pic->i_height * i_pic_width / p_pic->i_width;
1581 /* Set picture position */
1582 i_pic_x = (p_vout->i_width - i_pic_width) / 2;
1583 i_pic_y = (p_vout->i_height - i_pic_height) / 2;
1588 /* No picture: size is 0 */
1596 * Set new picture size - if it is smaller than the previous one, clear
1597 * around it. Since picture are centered, only their size is tested.
1599 if( (p_buffer->i_pic_width > i_pic_width) || (p_buffer->i_pic_height > i_pic_height) )
1601 i_old_pic_y = p_buffer->i_pic_y;
1602 i_old_pic_height = p_buffer->i_pic_height;
1603 p_buffer->i_pic_x = i_pic_x;
1604 p_buffer->i_pic_y = i_pic_y;
1605 p_buffer->i_pic_width = i_pic_width;
1606 p_buffer->i_pic_height = i_pic_height;
1607 SetBufferArea( p_vout, 0, i_old_pic_y, p_vout->i_width, i_old_pic_height );
1611 p_buffer->i_pic_x = i_pic_x;
1612 p_buffer->i_pic_y = i_pic_y;
1613 p_buffer->i_pic_width = i_pic_width;
1614 p_buffer->i_pic_height = i_pic_height;
1620 for( i_area = 0; i_area < p_buffer->i_areas; i_area++ )
1623 intf_DbgMsg("clearing picture %p area in buffer %d: %d-%d", p_pic,
1624 p_vout->i_buffer_index, p_buffer->pi_area_begin[i_area], p_buffer->pi_area_end[i_area] );
1626 i_data_size = (p_buffer->pi_area_end[i_area] - p_buffer->pi_area_begin[i_area] + 1) * p_vout->i_bytes_per_line;
1627 p_data = (u64*) (p_buffer->p_data + p_vout->i_bytes_per_line * p_buffer->pi_area_begin[i_area]);
1628 for( i_data_index = i_data_size / 256; i_data_index-- ; )
1630 /* Clear 256 bytes block */
1631 *p_data++ = 0; *p_data++ = 0; *p_data++ = 0; *p_data++ = 0;
1632 *p_data++ = 0; *p_data++ = 0; *p_data++ = 0; *p_data++ = 0;
1633 *p_data++ = 0; *p_data++ = 0; *p_data++ = 0; *p_data++ = 0;
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;
1640 for( i_data_index = (i_data_size % 256) / 16; i_data_index--; )
1642 /* Clear remaining 16 bytes blocks */
1643 *p_data++ = 0; *p_data++ = 0;
1645 p_data8 = (byte_t *)p_data;
1646 for( i_data_index = i_data_size % 16; i_data_index--; )
1648 /* Clear remaining bytes */
1656 p_buffer->i_areas = 0;
1659 /*****************************************************************************
1660 * RenderPicture: render a picture
1661 *****************************************************************************
1662 * This function converts a picture from a video heap to a pixel-encoded image
1663 * and copies it to the current rendering buffer. No lock is required, since
1664 * the * rendered picture has been determined as existant, and will only be
1665 * destroyed by the vout thread later.
1666 *****************************************************************************/
1667 static void RenderPicture( vout_thread_t *p_vout, picture_t *p_pic )
1670 char psz_date[MSTRTIME_MAX_SIZE]; /* picture date */
1671 mtime_t render_time; /* picture rendering time */
1673 vout_buffer_t * p_buffer; /* rendering buffer */
1674 byte_t * p_pic_data; /* convertion destination */
1676 /* Get and set rendering information */
1677 p_buffer = &p_vout->p_buffer[ p_vout->i_buffer_index ];
1678 p_pic_data = p_buffer->p_data +
1679 p_buffer->i_pic_x * p_vout->i_bytes_per_pixel +
1680 p_buffer->i_pic_y * p_vout->i_bytes_per_line;
1682 render_time = mdate();
1688 * Choose appropriate rendering function and render picture
1690 switch( p_pic->i_type )
1692 case YUV_420_PICTURE:
1693 p_vout->yuv.p_Convert420( p_vout, p_pic_data,
1694 p_pic->p_y, p_pic->p_u, p_pic->p_v,
1695 p_pic->i_width, p_pic->i_height,
1696 p_buffer->i_pic_width, p_buffer->i_pic_height,
1697 p_vout->i_bytes_per_line / p_vout->i_bytes_per_pixel,
1698 p_pic->i_matrix_coefficients );
1700 case YUV_422_PICTURE:
1701 p_vout->yuv.p_Convert422( p_vout, p_pic_data,
1702 p_pic->p_y, p_pic->p_u, p_pic->p_v,
1703 p_pic->i_width, p_pic->i_height,
1704 p_buffer->i_pic_width, p_buffer->i_pic_height,
1705 p_vout->i_bytes_per_line / p_vout->i_bytes_per_pixel,
1706 p_pic->i_matrix_coefficients );
1708 case YUV_444_PICTURE:
1709 p_vout->yuv.p_Convert444( p_vout, p_pic_data,
1710 p_pic->p_y, p_pic->p_u, p_pic->p_v,
1711 p_pic->i_width, p_pic->i_height,
1712 p_buffer->i_pic_width, p_buffer->i_pic_height,
1713 p_vout->i_bytes_per_line / p_vout->i_bytes_per_pixel,
1714 p_pic->i_matrix_coefficients );
1718 intf_DbgMsg("error: unknown picture type %d", p_pic->i_type );
1724 /* Print picture date and rendering time */
1725 intf_DbgMsg("picture %p rendered in buffer %d (%ld us), display date: %s", p_pic,
1726 p_vout->i_buffer_index, (long) (mdate() - render_time),
1727 mstrtime( psz_date, p_pic->date ));
1731 /*****************************************************************************
1732 * RenderPictureInfo: print additionnal information on a picture
1733 *****************************************************************************
1734 * This function will print information such as fps and other picture
1735 * dependant information.
1736 *****************************************************************************/
1737 static void RenderPictureInfo( vout_thread_t *p_vout, picture_t *p_pic )
1739 char psz_buffer[256]; /* string buffer */
1742 * Print FPS rate in upper right corner
1744 if( p_vout->c_fps_samples > VOUT_FPS_SAMPLES )
1746 long i_fps = VOUT_FPS_SAMPLES * 1000000 * 10 /
1747 ( p_vout->p_fps_sample[ (p_vout->c_fps_samples - 1)
1748 % VOUT_FPS_SAMPLES ] -
1749 p_vout->p_fps_sample[ p_vout->c_fps_samples
1750 % VOUT_FPS_SAMPLES ] );
1751 sprintf( psz_buffer, "%li.%i fps", i_fps / 10, (int)i_fps % 10 );
1752 Print( p_vout, 0, 0, RIGHT_RALIGN, TOP_RALIGN, psz_buffer );
1756 * Print frames count and loop time in upper left corner
1758 sprintf( psz_buffer, "%ld frames, render: %ldus",
1759 (long) p_vout->c_fps_samples, (long) p_vout->render_time );
1760 Print( p_vout, 0, 0, LEFT_RALIGN, TOP_RALIGN, psz_buffer );
1764 * Print picture information in lower right corner
1766 sprintf( psz_buffer, "%s picture %dx%d (%dx%d%+d%+d %s) -> %dx%d+%d+%d",
1767 (p_pic->i_type == YUV_420_PICTURE) ? "4:2:0" :
1768 ((p_pic->i_type == YUV_422_PICTURE) ? "4:2:2" :
1769 ((p_pic->i_type == YUV_444_PICTURE) ? "4:4:4" : "ukn-type")),
1770 p_pic->i_width, p_pic->i_height,
1771 p_pic->i_display_width, p_pic->i_display_height,
1772 p_pic->i_display_horizontal_offset, p_pic->i_display_vertical_offset,
1773 (p_pic->i_aspect_ratio == AR_SQUARE_PICTURE) ? "sq" :
1774 ((p_pic->i_aspect_ratio == AR_3_4_PICTURE) ? "4:3" :
1775 ((p_pic->i_aspect_ratio == AR_16_9_PICTURE) ? "16:9" :
1776 ((p_pic->i_aspect_ratio == AR_221_1_PICTURE) ? "2.21:1" : "ukn-ar" ))),
1777 p_vout->p_buffer[ p_vout->i_buffer_index ].i_pic_width,
1778 p_vout->p_buffer[ p_vout->i_buffer_index ].i_pic_height,
1779 p_vout->p_buffer[ p_vout->i_buffer_index ].i_pic_x,
1780 p_vout->p_buffer[ p_vout->i_buffer_index ].i_pic_y );
1781 Print( p_vout, 0, 0, RIGHT_RALIGN, BOTTOM_RALIGN, psz_buffer );
1785 /*****************************************************************************
1786 * RenderSplash: render splash picture
1787 *****************************************************************************
1788 * This function will print something on the screen. It will return 0 if
1789 * nothing has been rendered, or 1 if something has been changed on the screen.
1790 * Note that if you absolutely want something to be printed, you will have
1791 * to force it by setting the last idle date to 0.
1792 * Unlike other rendering functions, this one calls the SetBufferPicture
1793 * function when needed.
1794 *****************************************************************************/
1795 int RenderSplash( vout_thread_t *p_vout )
1797 int i_x = 0, i_y = 0; /* text position */
1798 int i_width, i_height; /* text size */
1799 char *psz_text = "VideoLAN Client (" VERSION ")"; /* text to display */
1801 memset( p_vout->p_buffer[ p_vout->i_buffer_index ].p_data,
1802 p_vout->i_bytes_per_line * p_vout->i_height, 12);
1804 // SetBufferPicture( p_vout, NULL );
1805 vout_TextSize( p_vout->p_large_font, WIDE_TEXT | OUTLINED_TEXT, psz_text,
1806 &i_width, &i_height );
1807 if( !Align( p_vout, &i_x, &i_y, i_width, i_height, CENTER_RALIGN, CENTER_RALIGN ) )
1809 vout_Print( p_vout->p_large_font,
1810 p_vout->p_buffer[ p_vout->i_buffer_index ].p_data +
1811 i_x * p_vout->i_bytes_per_pixel + (i_y - 16 ) * p_vout->i_bytes_per_line,
1812 p_vout->i_bytes_per_pixel, p_vout->i_bytes_per_line,
1813 p_vout->i_white_pixel, p_vout->i_gray_pixel, 0,
1814 WIDE_TEXT | OUTLINED_TEXT, psz_text, 100);
1815 SetBufferArea( p_vout, i_x, i_y, i_width, i_height);
1821 /*****************************************************************************
1822 * RenderIdle: render idle picture
1823 *****************************************************************************
1824 * This function will print something on the screen. It will return 0 if
1825 * nothing has been rendered, or 1 if something has been changed on the screen.
1826 * Note that if you absolutely want something to be printed, you will have
1827 * to force it by setting the last idle date to 0.
1828 * Unlike other rendering functions, this one calls the SetBufferPicture
1829 * function when needed.
1830 *****************************************************************************/
1831 int RenderIdle( vout_thread_t *p_vout )
1834 int i_x = 0, i_y = 0; /* text position */
1835 int i_width, i_height; /* text size */
1836 int i_amount = 0; /* amount to draw */
1837 char *psz_text = "Waiting for stream"; /* text to display */
1838 char *psz_wtext = "[................]";
1840 mtime_t current_date; /* current date */
1843 memset( p_vout->p_buffer[ p_vout->i_buffer_index ].p_data,
1844 p_vout->i_bytes_per_line * p_vout->i_height, 12);
1847 current_date = mdate();
1848 if( (current_date - p_vout->last_display_date) > VOUT_IDLE_DELAY
1849 // && (current_date - p_vout->last_idle_date) > VOUT_IDLE_DELAY
1852 /* FIXME: idle screen disabled */
1854 SetBufferPicture( p_vout, NULL );
1855 vout_TextSize( p_vout->p_large_font, WIDE_TEXT | OUTLINED_TEXT, psz_text,
1856 &i_width, &i_height );
1857 if( !Align( p_vout, &i_x, &i_y, i_width, i_height * 2, CENTER_RALIGN, CENTER_RALIGN ) )
1859 i_amount = (int) ((current_date - p_vout->last_display_date ) / 5000LL);
1860 vout_Print( p_vout->p_large_font,
1861 p_vout->p_buffer[ p_vout->i_buffer_index ].p_data +
1862 i_x * p_vout->i_bytes_per_pixel + i_y * p_vout->i_bytes_per_line,
1863 p_vout->i_bytes_per_pixel, p_vout->i_bytes_per_line,
1864 p_vout->i_white_pixel, p_vout->i_gray_pixel, 0,
1865 WIDE_TEXT | OUTLINED_TEXT, psz_text, (i_amount / 3 ) %110);
1867 vout_Print( p_vout->p_large_font,
1868 p_vout->p_buffer[ p_vout->i_buffer_index ].p_data +
1869 i_x * p_vout->i_bytes_per_pixel + (i_y + 16) * p_vout->i_bytes_per_line,
1870 p_vout->i_bytes_per_pixel, p_vout->i_bytes_per_line,
1871 p_vout->i_white_pixel, p_vout->i_gray_pixel, 0,
1872 WIDE_TEXT | OUTLINED_TEXT, psz_wtext, (i_amount/5)%110 );
1875 SetBufferArea( p_vout, i_x, i_y, i_width, i_height * 2 );
1883 /*****************************************************************************
1884 * RenderInfo: render additionnal information
1885 *****************************************************************************
1886 * This function renders information which do not depend on the current
1888 *****************************************************************************/
1889 static void RenderInfo( vout_thread_t *p_vout )
1892 char psz_buffer[256]; /* string buffer */
1893 int i_ready_pic = 0; /* ready pictures */
1894 int i_reserved_pic = 0; /* reserved pictures */
1895 int i_picture; /* picture index */
1900 * Print thread state in lower left corner
1902 for( i_picture = 0; i_picture < VOUT_MAX_PICTURES; i_picture++ )
1904 switch( p_vout->p_picture[i_picture].i_status )
1906 case RESERVED_PICTURE:
1907 case RESERVED_DATED_PICTURE:
1908 case RESERVED_DISP_PICTURE:
1916 sprintf( psz_buffer, "pic: %d (%d/%d)/%d",
1917 p_vout->i_pictures, i_reserved_pic, i_ready_pic, VOUT_MAX_PICTURES );
1918 Print( p_vout, 0, 0, LEFT_RALIGN, BOTTOM_RALIGN, psz_buffer );
1922 /*****************************************************************************
1923 * RenderSubPicture: render a subpicture
1924 *****************************************************************************
1925 * This function renders a sub picture unit.
1926 *****************************************************************************/
1927 static void RenderSubPicture( vout_thread_t *p_vout, subpicture_t *p_subpic )
1929 p_vout_font_t p_font; /* text font */
1930 int i_width, i_height; /* subpicture dimensions */
1932 while( p_subpic != NULL )
1934 switch( p_subpic->i_type )
1936 case DVD_SUBPICTURE: /* DVD subpicture unit */
1937 /* test if the picture really has to be displayed */
1938 if( mdate() < p_subpic->begin_date )
1940 /* not yet, see you later */
1943 if( mdate() > p_subpic->end_date )
1945 /* too late, destroying the subpic */
1946 vout_DestroySubPicture( p_vout, p_subpic );
1949 vout_RenderSPU( &p_vout->p_buffer[ p_vout->i_buffer_index ],
1950 p_subpic, p_vout->i_bytes_per_pixel,
1951 p_vout->i_bytes_per_line );
1953 case TEXT_SUBPICTURE: /* single line text */
1954 /* Select default font if not specified */
1955 p_font = p_subpic->type.text.p_font;
1956 if( p_font == NULL )
1958 p_font = p_vout->p_default_font;
1961 /* Compute text size (width and height fields are ignored)
1963 vout_TextSize( p_font, p_subpic->type.text.i_style,
1964 p_subpic->p_data, &i_width, &i_height );
1965 if( !Align( p_vout, &p_subpic->i_x, &p_subpic->i_y,
1966 i_width, i_height, p_subpic->i_horizontal_align,
1967 p_subpic->i_vertical_align ) )
1970 p_vout->p_buffer[ p_vout->i_buffer_index ].p_data +
1971 p_subpic->i_x * p_vout->i_bytes_per_pixel +
1972 p_subpic->i_y * p_vout->i_bytes_per_line,
1973 p_vout->i_bytes_per_pixel, p_vout->i_bytes_per_line,
1974 p_subpic->type.text.i_char_color,
1975 p_subpic->type.text.i_border_color,
1976 p_subpic->type.text.i_bg_color,
1977 p_subpic->type.text.i_style, p_subpic->p_data, 100 );
1978 SetBufferArea( p_vout, p_subpic->i_x, p_subpic->i_y,
1979 i_width, i_height );
1985 intf_DbgMsg( "error: unknown subpicture %p type %d",
1986 p_subpic, p_subpic->i_type );
1990 p_subpic = p_subpic->p_next;
1994 /*****************************************************************************
1995 * RenderInterface: render the interface
1996 *****************************************************************************
1997 * This function renders the interface, if any.
1998 *****************************************************************************/
1999 static void RenderInterface( vout_thread_t *p_vout )
2001 int i_height, i_text_height; /* total and text height */
2002 int i_width_1, i_width_2; /* text width */
2003 int i_byte; /* byte index */
2004 const char *psz_text_1 = "[1-9] Channel [i]nfo [c]olor [g/G]amma";
2005 const char *psz_text_2 = "[+/-] Volume [m]ute [s]caling [Q]uit";
2008 vout_TextSize( p_vout->p_large_font, OUTLINED_TEXT, psz_text_1, &i_width_1, &i_height );
2009 vout_TextSize( p_vout->p_large_font, OUTLINED_TEXT, psz_text_2, &i_width_2, &i_text_height );
2010 i_height += i_text_height;
2012 /* Render background */
2013 for( i_byte = (p_vout->i_height - i_height) * p_vout->i_bytes_per_line;
2014 i_byte < p_vout->i_height * p_vout->i_bytes_per_line;
2018 p_vout->p_buffer[ p_vout->i_buffer_index ].p_data[ i_byte ] = p_vout->i_blue_pixel;
2021 /* Render text, if not larger than screen */
2022 if( i_width_1 < p_vout->i_width )
2024 vout_Print( p_vout->p_large_font, p_vout->p_buffer[ p_vout->i_buffer_index ].p_data +
2025 (p_vout->i_height - i_height) * p_vout->i_bytes_per_line,
2026 p_vout->i_bytes_per_pixel, p_vout->i_bytes_per_line,
2027 p_vout->i_white_pixel, p_vout->i_black_pixel, 0,
2028 OUTLINED_TEXT, psz_text_1, 100 );
2030 if( i_width_2 < p_vout->i_width )
2032 vout_Print( p_vout->p_large_font, p_vout->p_buffer[ p_vout->i_buffer_index ].p_data +
2033 (p_vout->i_height - i_height + i_text_height) * p_vout->i_bytes_per_line,
2034 p_vout->i_bytes_per_pixel, p_vout->i_bytes_per_line,
2035 p_vout->i_white_pixel, p_vout->i_black_pixel, 0,
2036 OUTLINED_TEXT, psz_text_2, 100 );
2039 /* Activate modified area */
2040 SetBufferArea( p_vout, 0, p_vout->i_height - i_height, p_vout->i_width, i_height );
2043 /*****************************************************************************
2044 * Manage: manage thread
2045 *****************************************************************************
2046 * This function will handle changes in thread configuration.
2047 *****************************************************************************/
2048 static int Manage( vout_thread_t *p_vout )
2051 if( p_vout->i_changes )
2053 intf_DbgMsg("changes: 0x%x (no display: 0x%x)", p_vout->i_changes,
2054 0 /* p_vout->i_changes & VOUT_NODISPLAY_CHANGE */ );
2058 /* On gamma or grayscale change, rebuild tables */
2059 if( p_vout->i_changes & (VOUT_GAMMA_CHANGE | VOUT_GRAYSCALE_CHANGE |
2062 if( vout_ResetYUV( p_vout ) )
2064 intf_ErrMsg( "vout error: can't rebuild conversion tables" );
2069 /* Clear changes flags which does not need management or have been
2071 p_vout->i_changes &= ~(VOUT_GAMMA_CHANGE | VOUT_GRAYSCALE_CHANGE |
2072 VOUT_YUV_CHANGE | VOUT_INFO_CHANGE |
2073 VOUT_INTF_CHANGE | VOUT_SCALE_CHANGE |
2074 VOUT_CURSOR_CHANGE | VOUT_FULLSCREEN_CHANGE );
2076 /* Detect unauthorized changes */
2077 if( p_vout->i_changes )
2079 /* Some changes were not acknowledged by p_vout->pf_manage or this
2080 * function, it means they should not be authorized */
2081 intf_ErrMsg( "vout error: unauthorized changes in the vout thread" );
2088 /*****************************************************************************
2089 * Align: align a subpicture in the screen
2090 *****************************************************************************
2091 * This function is used for rendering text or subpictures. It returns non 0
2092 * it the final aera is not fully included in display area. Return coordinates
2094 *****************************************************************************/
2095 static int Align( vout_thread_t *p_vout, int *pi_x, int *pi_y,
2096 int i_width, int i_height, int i_h_align, int i_v_align )
2098 /* Align horizontally */
2102 *pi_x -= i_width / 2;
2105 *pi_x += (p_vout->i_width - i_width) / 2;
2111 *pi_x += p_vout->i_width - i_width;
2115 /* Align vertically */
2119 *pi_y -= i_height / 2;
2122 *pi_y += (p_vout->i_height - i_height) / 2;
2128 *pi_y += p_vout->i_height - i_height;
2130 case SUBTITLE_RALIGN:
2131 *pi_y += (p_vout->i_height + p_vout->p_buffer[ p_vout->i_buffer_index ].i_pic_y +
2132 p_vout->p_buffer[ p_vout->i_buffer_index ].i_pic_height - i_height) / 2;
2136 /* Return non 0 if clipping failed */
2137 return( (*pi_x < 0) || (*pi_y < 0) ||
2138 (*pi_x + i_width > p_vout->i_width) || (*pi_y + i_height > p_vout->i_height) );
2141 /*****************************************************************************
2142 * SetPalette: sets an 8 bpp palette
2143 *****************************************************************************
2144 * This function is just a prototype that does nothing. Architectures that
2145 * support palette allocation should override it.
2146 *****************************************************************************/
2147 static void SetPalette ( p_vout_thread_t p_vout, u16 *red,
2148 u16 *green, u16 *blue, u16 *transp )
2150 intf_ErrMsg( "vout error: method does not support palette changing" );