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() */
42 #include "video_output.h"
43 #include "video_text.h"
44 #include "video_spu.h"
45 #include "video_yuv.h"
50 /*****************************************************************************
52 *****************************************************************************/
53 static int BinaryLog ( u32 i );
54 static void MaskToShift ( int *pi_left, int *pi_right, u32 i_mask );
55 static int InitThread ( vout_thread_t *p_vout );
56 static void RunThread ( vout_thread_t *p_vout );
57 static void ErrorThread ( vout_thread_t *p_vout );
58 static void EndThread ( vout_thread_t *p_vout );
59 static void DestroyThread ( vout_thread_t *p_vout, int i_status );
60 static void Print ( vout_thread_t *p_vout, int i_x, int i_y,
61 int i_h_align, int i_v_align,
62 unsigned char *psz_text );
63 static void SetBufferArea ( vout_thread_t *p_vout, int i_x, int i_y,
65 static void SetBufferPicture ( vout_thread_t *p_vout, picture_t *p_pic );
66 static void RenderPicture ( vout_thread_t *p_vout, picture_t *p_pic );
67 static void RenderPictureInfo ( vout_thread_t *p_vout, picture_t *p_pic );
68 static void RenderSubPicture ( vout_thread_t *p_vout,
69 subpicture_t *p_subpic );
70 static void RenderInterface ( vout_thread_t *p_vout );
71 static int RenderIdle ( vout_thread_t *p_vout );
72 static int RenderSplash( vout_thread_t *p_vout );
73 static void RenderInfo ( vout_thread_t *p_vout );
74 static void Synchronize ( vout_thread_t *p_vout, s64 i_delay );
75 static int Manage ( vout_thread_t *p_vout );
76 static int Align ( vout_thread_t *p_vout, int *pi_x,
77 int *pi_y, int i_width, int i_height,
78 int i_h_align, int i_v_align );
79 static void SetPalette ( p_vout_thread_t p_vout, u16 *red,
80 u16 *green, u16 *blue, u16 *transp );
82 /*****************************************************************************
83 * vout_CreateThread: creates a new video output thread
84 *****************************************************************************
85 * This function creates a new video output thread, and returns a pointer
86 * to its description. On error, it returns NULL.
87 * If pi_status is NULL, then the function will block until the thread is ready.
88 * If not, it will be updated using one of the THREAD_* constants.
89 *****************************************************************************/
90 vout_thread_t * vout_CreateThread ( char *psz_display, int i_root_window,
91 int i_width, int i_height, int *pi_status,
92 int i_method, void *p_data )
94 vout_thread_t * p_vout; /* thread descriptor */
95 typedef void ( vout_getplugin_t ) ( vout_thread_t * p_vout );
96 int i_status; /* thread status */
97 int i_index; /* index for array initialization */
98 int i_best_index = 0, i_best_score = 0;
100 /* Allocate descriptor */
102 p_vout = (vout_thread_t *) malloc( sizeof(vout_thread_t) );
105 intf_ErrMsg( "error: %s\n", strerror(ENOMEM) );
109 p_vout->p_set_palette = SetPalette;
111 /* Get a suitable video plugin */
112 for( i_index = 0 ; i_index < p_main->p_bank->i_plugin_count ; i_index++ )
114 /* If there's a plugin in p_info ... */
115 if( p_main->p_bank->p_info[ i_index ] != NULL )
117 /* ... and if this plugin provides the functions we want ... */
118 if( p_main->p_bank->p_info[ i_index ]->vout_GetPlugin != NULL )
120 /* ... and if this plugin has a good score ... */
121 if( p_main->p_bank->p_info[ i_index ]->i_score > i_best_score )
123 /* ... then take it */
124 i_best_score = p_main->p_bank->p_info[ i_index ]->i_score;
125 i_best_index = i_index;
131 if( i_best_score == 0 )
137 /* Get the plugin functions */
138 ( (vout_getplugin_t *)
139 p_main->p_bank->p_info[ i_best_index ]->vout_GetPlugin )( p_vout );
141 /* Initialize thread properties - thread id and locks will be initialized
145 p_vout->b_active = 0;
146 p_vout->pi_status = (pi_status != NULL) ? pi_status : &i_status;
147 *p_vout->pi_status = THREAD_CREATE;
149 /* Initialize some fields used by the system-dependant method - these
150 * fields will probably be modified by the method, and are only
152 p_vout->i_changes = 0;
153 p_vout->i_width = i_width;
154 p_vout->i_height = i_height;
155 p_vout->i_bytes_per_line = i_width * 2;
156 p_vout->i_screen_depth = 15;
157 p_vout->i_bytes_per_pixel = 2;
158 p_vout->f_gamma = VOUT_GAMMA;
160 p_vout->b_grayscale = main_GetIntVariable( VOUT_GRAYSCALE_VAR,
161 VOUT_GRAYSCALE_DEFAULT );
163 p_vout->b_interface = 0;
166 intf_DbgMsg( "wished configuration: %dx%d, %d/%d bpp (%d Bpl)\n",
167 p_vout->i_width, p_vout->i_height, p_vout->i_screen_depth,
168 p_vout->i_bytes_per_pixel * 8, p_vout->i_bytes_per_line );
170 /* Initialize idle screen */
171 p_vout->last_display_date = 0;
172 p_vout->last_idle_date = 0;
173 p_vout->init_display_date = mdate();
176 /* Initialize statistics fields */
177 p_vout->render_time = 0;
178 p_vout->c_fps_samples = 0;
181 /* Initialize buffer index */
182 p_vout->i_buffer_index = 0;
184 /* Initialize pictures and subpictures - translation tables and functions
185 * will be initialized later in InitThread */
186 for( i_index = 0; i_index < VOUT_MAX_PICTURES; i_index++)
188 p_vout->p_picture[i_index].i_type = EMPTY_PICTURE;
189 p_vout->p_picture[i_index].i_status = FREE_PICTURE;
191 for( i_index = 0; i_index < VOUT_MAX_SUBPICTURES; i_index++)
193 p_vout->p_subpicture[i_index].i_type = EMPTY_SUBPICTURE;
194 p_vout->p_subpicture[i_index].i_status= FREE_SUBPICTURE;
196 p_vout->i_pictures = 0;
198 /* Initialize synchronization information */
199 p_vout->i_synchro_level = VOUT_SYNCHRO_LEVEL_START;
201 /* Create and initialize system-dependant method - this function issues its
202 * own error messages */
203 if( p_vout->p_sys_create( p_vout, psz_display, i_root_window, p_data ) )
208 intf_DbgMsg( "actual configuration: %dx%d, %d/%d bpp (%d Bpl), "
209 "masks: 0x%x/0x%x/0x%x\n",
210 p_vout->i_width, p_vout->i_height, p_vout->i_screen_depth,
211 p_vout->i_bytes_per_pixel * 8, p_vout->i_bytes_per_line,
212 p_vout->i_red_mask, p_vout->i_green_mask,
213 p_vout->i_blue_mask );
215 /* Calculate shifts from system-updated masks */
216 MaskToShift( &p_vout->i_red_lshift, &p_vout->i_red_rshift,
217 p_vout->i_red_mask );
218 MaskToShift( &p_vout->i_green_lshift, &p_vout->i_green_rshift,
219 p_vout->i_green_mask );
220 MaskToShift( &p_vout->i_blue_lshift, &p_vout->i_blue_rshift,
221 p_vout->i_blue_mask );
223 /* Set some useful colors */
224 p_vout->i_white_pixel = RGB2PIXEL( p_vout, 255, 255, 255 );
225 p_vout->i_black_pixel = RGB2PIXEL( p_vout, 0, 0, 0 );
226 p_vout->i_gray_pixel = RGB2PIXEL( p_vout, 128, 128, 128 );
227 p_vout->i_blue_pixel = RGB2PIXEL( p_vout, 0, 0, 50 );
229 /* Load fonts - fonts must be initialized after the system method since
230 * they may be dependant on screen depth and other thread properties */
231 p_vout->p_default_font = vout_LoadFont( DATA_PATH "/" VOUT_DEFAULT_FONT );
232 if( p_vout->p_default_font == NULL )
234 p_vout->p_default_font = vout_LoadFont( "share/" VOUT_DEFAULT_FONT );
236 if( p_vout->p_default_font == NULL )
238 intf_ErrMsg( "vout error: could not load default font\n" );
239 p_vout->p_sys_destroy( p_vout );
243 p_vout->p_large_font = vout_LoadFont( DATA_PATH "/" VOUT_LARGE_FONT );
244 if( p_vout->p_large_font == NULL )
246 p_vout->p_large_font = vout_LoadFont( "share/" VOUT_LARGE_FONT );
248 if( p_vout->p_large_font == NULL )
250 intf_ErrMsg( "vout error: could not load large font\n" );
251 vout_UnloadFont( p_vout->p_default_font );
252 p_vout->p_sys_destroy( p_vout );
257 /* Create thread and set locks */
258 vlc_mutex_init( &p_vout->picture_lock );
259 vlc_mutex_init( &p_vout->subpicture_lock );
260 vlc_mutex_init( &p_vout->change_lock );
261 vlc_mutex_lock( &p_vout->change_lock );
262 if( vlc_thread_create( &p_vout->thread_id, "video output",
263 (void *) RunThread, (void *) p_vout) )
265 intf_ErrMsg("error: %s\n", strerror(ENOMEM));
266 vout_UnloadFont( p_vout->p_default_font );
267 vout_UnloadFont( p_vout->p_large_font );
268 p_vout->p_sys_destroy( p_vout );
273 intf_Msg( "Video display initialized (%dx%d, %d/%d bpp)\n", p_vout->i_width,
274 p_vout->i_height, p_vout->i_screen_depth,
275 p_vout->i_bytes_per_pixel * 8 );
277 /* If status is NULL, wait until the thread is created */
278 if( pi_status == NULL )
282 msleep( THREAD_SLEEP );
283 }while( (i_status != THREAD_READY) && (i_status != THREAD_ERROR)
284 && (i_status != THREAD_FATAL) );
285 if( i_status != THREAD_READY )
293 /*****************************************************************************
294 * vout_DestroyThread: destroys a previously created thread
295 *****************************************************************************
296 * Destroy a terminated thread.
297 * The function will request a destruction of the specified thread. If pi_error
298 * is NULL, it will return once the thread is destroyed. Else, it will be
299 * update using one of the THREAD_* constants.
300 *****************************************************************************/
301 void vout_DestroyThread( vout_thread_t *p_vout, int *pi_status )
303 int i_status; /* thread status */
307 p_vout->pi_status = (pi_status != NULL) ? pi_status : &i_status;
308 *p_vout->pi_status = THREAD_DESTROY;
310 /* Request thread destruction */
313 /* If status is NULL, wait until thread has been destroyed */
314 if( pi_status == NULL )
318 msleep( THREAD_SLEEP );
319 }while( (i_status != THREAD_OVER) && (i_status != THREAD_ERROR)
320 && (i_status != THREAD_FATAL) );
324 /*****************************************************************************
325 * vout_DisplaySubPicture: display a subpicture unit
326 *****************************************************************************
327 * Remove the reservation flag of an subpicture, which will cause it to be ready
328 * for display. The picture does not need to be locked, since it is ignored by
329 * the output thread if is reserved.
330 *****************************************************************************/
331 void vout_DisplaySubPicture( vout_thread_t *p_vout, subpicture_t *p_subpic )
334 char psz_begin_date[MSTRTIME_MAX_SIZE]; /* buffer for date string */
335 char psz_end_date[MSTRTIME_MAX_SIZE]; /* buffer for date string */
339 /* Check if status is valid */
340 if( p_subpic->i_status != RESERVED_SUBPICTURE )
342 intf_DbgMsg("error: subpicture %p has invalid status %d\n", p_subpic,
343 p_subpic->i_status );
347 /* Remove reservation flag */
348 p_subpic->i_status = READY_SUBPICTURE;
351 /* Send subpicture information */
352 intf_DbgMsg("subpicture %p: type=%d, begin date=%s, end date=%s\n",
353 p_subpic, p_subpic->i_type,
354 mstrtime( psz_begin_date, p_subpic->begin_date ),
355 mstrtime( psz_end_date, p_subpic->end_date ) );
359 /*****************************************************************************
360 * vout_CreateSubPicture: allocate a subpicture in the video output heap.
361 *****************************************************************************
362 * This function create a reserved subpicture in the video output heap.
363 * A null pointer is returned if the function fails. This method provides an
364 * already allocated zone of memory in the spu data fields. It needs locking
365 * since several pictures can be created by several producers threads.
366 *****************************************************************************/
367 subpicture_t *vout_CreateSubPicture( vout_thread_t *p_vout, int i_type,
370 int i_subpic; /* subpicture index */
371 subpicture_t * p_free_subpic = NULL; /* first free subpicture */
372 subpicture_t * p_destroyed_subpic = NULL; /* first destroyed subpic */
375 vlc_mutex_lock( &p_vout->subpicture_lock );
378 * Look for an empty place
380 for( i_subpic = 0; i_subpic < VOUT_MAX_SUBPICTURES; i_subpic++ )
382 if( p_vout->p_subpicture[i_subpic].i_status == DESTROYED_SUBPICTURE )
384 /* Subpicture is marked for destruction, but is still allocated */
385 if( (p_vout->p_subpicture[i_subpic].i_type == i_type) &&
386 (p_vout->p_subpicture[i_subpic].i_size >= i_size) )
388 /* Memory size do match or is smaller : memory will not be
389 * reallocated, and function can end immediately - this is
390 * the best possible case, since no memory allocation needs
392 p_vout->p_subpicture[i_subpic].i_status = RESERVED_SUBPICTURE;
394 intf_DbgMsg("subpicture %p (in destroyed subpicture slot)\n",
395 &p_vout->p_subpicture[i_subpic] );
397 vlc_mutex_unlock( &p_vout->subpicture_lock );
398 return( &p_vout->p_subpicture[i_subpic] );
400 else if( p_destroyed_subpic == NULL )
402 /* Memory size do not match, but subpicture index will be kept in
403 * case no other place are left */
404 p_destroyed_subpic = &p_vout->p_subpicture[i_subpic];
407 else if( (p_free_subpic == NULL) &&
408 (p_vout->p_subpicture[i_subpic].i_status == FREE_SUBPICTURE ))
410 /* Subpicture is empty and ready for allocation */
411 p_free_subpic = &p_vout->p_subpicture[i_subpic];
415 /* If no free subpictures are available, use a destroyed subpicture */
416 if( (p_free_subpic == NULL) && (p_destroyed_subpic != NULL ) )
418 /* No free subpicture or matching destroyed subpictures have been
419 * found, but a destroyed subpicture is still avalaible */
420 free( p_destroyed_subpic->p_data );
421 p_free_subpic = p_destroyed_subpic;
427 if( p_free_subpic != NULL )
429 /* Allocate memory */
432 case TEXT_SUBPICTURE: /* text subpicture */
433 p_free_subpic->p_data = malloc( i_size + 1 );
435 case DVD_SUBPICTURE: /* DVD subpicture unit */
436 p_free_subpic->p_data = malloc( i_size );
440 intf_DbgMsg("error: unknown subpicture type %d\n", i_type );
441 p_free_subpic->p_data = NULL;
446 if( p_free_subpic->p_data != NULL )
448 /* Copy subpicture information, set some default values */
449 p_free_subpic->i_type = i_type;
450 p_free_subpic->i_status = RESERVED_SUBPICTURE;
451 p_free_subpic->i_size = i_size;
452 p_free_subpic->i_x = 0;
453 p_free_subpic->i_y = 0;
454 p_free_subpic->i_width = 0;
455 p_free_subpic->i_height = 0;
456 p_free_subpic->i_horizontal_align = CENTER_RALIGN;
457 p_free_subpic->i_vertical_align = CENTER_RALIGN;
461 /* Memory allocation failed : set subpicture as empty */
462 p_free_subpic->i_type = EMPTY_SUBPICTURE;
463 p_free_subpic->i_status = FREE_SUBPICTURE;
464 p_free_subpic = NULL;
465 intf_ErrMsg("spu warning: %s\n", strerror( ENOMEM ) );
469 intf_DbgMsg("subpicture %p (in free subpicture slot)\n", p_free_subpic );
471 vlc_mutex_unlock( &p_vout->subpicture_lock );
472 return( p_free_subpic );
475 /* No free or destroyed subpicture could be found */
476 intf_DbgMsg( "warning: subpicture heap is full\n" );
477 vlc_mutex_unlock( &p_vout->subpicture_lock );
481 /*****************************************************************************
482 * vout_DestroySubPicture: remove a subpicture from the heap
483 *****************************************************************************
484 * This function frees a previously reserved subpicture.
485 * It is meant to be used when the construction of a picture aborted.
486 * This function does not need locking since reserved subpictures are ignored
487 * by the output thread.
488 *****************************************************************************/
489 void vout_DestroySubPicture( vout_thread_t *p_vout, subpicture_t *p_subpic )
492 /* Check if status is valid */
493 if( p_subpic->i_status != RESERVED_SUBPICTURE )
495 intf_DbgMsg("error: subpicture %p has invalid status %d\n",
496 p_subpic, p_subpic->i_status );
500 p_subpic->i_status = DESTROYED_SUBPICTURE;
503 intf_DbgMsg("subpicture %p\n", p_subpic);
507 /*****************************************************************************
508 * vout_DisplayPicture: display a picture
509 *****************************************************************************
510 * Remove the reservation flag of a picture, which will cause it to be ready for
511 * display. The picture won't be displayed until vout_DatePicture has been
513 *****************************************************************************/
514 void vout_DisplayPicture( vout_thread_t *p_vout, picture_t *p_pic )
516 vlc_mutex_lock( &p_vout->picture_lock );
517 switch( p_pic->i_status )
519 case RESERVED_PICTURE:
520 p_pic->i_status = RESERVED_DISP_PICTURE;
522 case RESERVED_DATED_PICTURE:
523 p_pic->i_status = READY_PICTURE;
527 intf_DbgMsg("error: picture %p has invalid status %d\n", p_pic, p_pic->i_status );
533 intf_DbgMsg("picture %p\n", p_pic);
535 vlc_mutex_unlock( &p_vout->picture_lock );
538 /*****************************************************************************
539 * vout_DatePicture: date a picture
540 *****************************************************************************
541 * Remove the reservation flag of a picture, which will cause it to be ready for
542 * display. The picture won't be displayed until vout_DisplayPicture has been
544 *****************************************************************************/
545 void vout_DatePicture( vout_thread_t *p_vout, picture_t *p_pic, mtime_t date )
548 char psz_date[MSTRTIME_MAX_SIZE]; /* date */
551 vlc_mutex_lock( &p_vout->picture_lock );
553 switch( p_pic->i_status )
555 case RESERVED_PICTURE:
556 p_pic->i_status = RESERVED_DATED_PICTURE;
558 case RESERVED_DISP_PICTURE:
559 p_pic->i_status = READY_PICTURE;
563 intf_DbgMsg("error: picture %p has invalid status %d\n", p_pic, p_pic->i_status );
569 intf_DbgMsg("picture %p, display date: %s\n", p_pic, mstrtime( psz_date, p_pic->date) );
571 vlc_mutex_unlock( &p_vout->picture_lock );
574 /*****************************************************************************
575 * vout_CreatePicture: allocate a picture in the video output heap.
576 *****************************************************************************
577 * This function create a reserved image in the video output heap.
578 * A null pointer is returned if the function fails. This method provides an
579 * already allocated zone of memory in the picture data fields. It needs locking
580 * since several pictures can be created by several producers threads.
581 *****************************************************************************/
582 picture_t *vout_CreatePicture( vout_thread_t *p_vout, int i_type,
583 int i_width, int i_height )
585 int i_picture; /* picture index */
586 int i_chroma_width = 0; /* chroma width */
587 picture_t * p_free_picture = NULL; /* first free picture */
588 picture_t * p_destroyed_picture = NULL; /* first destroyed picture */
591 vlc_mutex_lock( &p_vout->picture_lock );
594 * Look for an empty place
596 for( i_picture = 0; i_picture < VOUT_MAX_PICTURES; i_picture++ )
598 if( p_vout->p_picture[i_picture].i_status == DESTROYED_PICTURE )
600 /* Picture is marked for destruction, but is still allocated - note
601 * that if width and type are the same for two pictures, chroma_width
602 * should also be the same */
603 if( (p_vout->p_picture[i_picture].i_type == i_type) &&
604 (p_vout->p_picture[i_picture].i_height == i_height) &&
605 (p_vout->p_picture[i_picture].i_width == i_width) )
607 /* Memory size do match : memory will not be reallocated, and function
608 * can end immediately - this is the best possible case, since no
609 * memory allocation needs to be done */
610 p_vout->p_picture[i_picture].i_status = RESERVED_PICTURE;
611 p_vout->i_pictures++;
613 intf_DbgMsg("picture %p (in destroyed picture slot)\n",
614 &p_vout->p_picture[i_picture] );
616 vlc_mutex_unlock( &p_vout->picture_lock );
617 return( &p_vout->p_picture[i_picture] );
619 else if( p_destroyed_picture == NULL )
621 /* Memory size do not match, but picture index will be kept in
622 * case no other place are left */
623 p_destroyed_picture = &p_vout->p_picture[i_picture];
626 else if( (p_free_picture == NULL) &&
627 (p_vout->p_picture[i_picture].i_status == FREE_PICTURE ))
629 /* Picture is empty and ready for allocation */
630 p_free_picture = &p_vout->p_picture[i_picture];
634 /* If no free picture is available, use a destroyed picture */
635 if( (p_free_picture == NULL) && (p_destroyed_picture != NULL ) )
637 /* No free picture or matching destroyed picture has been found, but
638 * a destroyed picture is still avalaible */
639 free( p_destroyed_picture->p_data );
640 p_free_picture = p_destroyed_picture;
646 if( p_free_picture != NULL )
648 /* Allocate memory */
651 case YUV_420_PICTURE: /* YUV 420: 1,1/4,1/4 samples per pixel */
652 i_chroma_width = i_width / 2;
653 p_free_picture->p_data = malloc( i_height * i_chroma_width * 3 * sizeof( yuv_data_t ) );
654 p_free_picture->p_y = (yuv_data_t *)p_free_picture->p_data;
655 p_free_picture->p_u = (yuv_data_t *)p_free_picture->p_data +i_height*i_chroma_width*4/2;
656 p_free_picture->p_v = (yuv_data_t *)p_free_picture->p_data +i_height*i_chroma_width*5/2;
658 case YUV_422_PICTURE: /* YUV 422: 1,1/2,1/2 samples per pixel */
659 i_chroma_width = i_width / 2;
660 p_free_picture->p_data = malloc( i_height * i_chroma_width * 4 * sizeof( yuv_data_t ) );
661 p_free_picture->p_y = (yuv_data_t *)p_free_picture->p_data;
662 p_free_picture->p_u = (yuv_data_t *)p_free_picture->p_data +i_height*i_chroma_width*2;
663 p_free_picture->p_v = (yuv_data_t *)p_free_picture->p_data +i_height*i_chroma_width*3;
665 case YUV_444_PICTURE: /* YUV 444: 1,1,1 samples per pixel */
666 i_chroma_width = i_width;
667 p_free_picture->p_data = malloc( i_height * i_chroma_width * 3 * sizeof( yuv_data_t ) );
668 p_free_picture->p_y = (yuv_data_t *)p_free_picture->p_data;
669 p_free_picture->p_u = (yuv_data_t *)p_free_picture->p_data +i_height*i_chroma_width;
670 p_free_picture->p_v = (yuv_data_t *)p_free_picture->p_data +i_height*i_chroma_width*2;
674 intf_DbgMsg("error: unknown picture type %d\n", i_type );
675 p_free_picture->p_data = NULL;
680 if( p_free_picture->p_data != NULL )
682 /* Copy picture information, set some default values */
683 p_free_picture->i_type = i_type;
684 p_free_picture->i_status = RESERVED_PICTURE;
685 p_free_picture->i_matrix_coefficients = 1;
686 p_free_picture->i_width = i_width;
687 p_free_picture->i_height = i_height;
688 p_free_picture->i_chroma_width = i_chroma_width;
689 p_free_picture->i_display_horizontal_offset = 0;
690 p_free_picture->i_display_vertical_offset = 0;
691 p_free_picture->i_display_width = i_width;
692 p_free_picture->i_display_height = i_height;
693 p_free_picture->i_aspect_ratio = AR_SQUARE_PICTURE;
694 p_free_picture->i_refcount = 0;
695 p_vout->i_pictures++;
699 /* Memory allocation failed : set picture as empty */
700 p_free_picture->i_type = EMPTY_PICTURE;
701 p_free_picture->i_status = FREE_PICTURE;
702 p_free_picture = NULL;
703 intf_ErrMsg("vout warning: %s\n", strerror( ENOMEM ) );
707 intf_DbgMsg("picture %p (in free picture slot)\n", p_free_picture );
709 vlc_mutex_unlock( &p_vout->picture_lock );
710 return( p_free_picture );
713 /* No free or destroyed picture could be found */
714 intf_DbgMsg( "warning: picture heap is full\n" );
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\n", p_pic, p_pic->i_status );
740 p_pic->i_status = DESTROYED_PICTURE;
741 p_vout->i_pictures--;
744 intf_DbgMsg("picture %p\n", p_pic);
746 vlc_mutex_unlock( &p_vout->picture_lock );
749 /*****************************************************************************
750 * vout_LinkPicture: increment reference counter of a picture
751 *****************************************************************************
752 * This function increment the reference counter of a picture in the video
753 * heap. It needs a lock since several producer threads can access the picture.
754 *****************************************************************************/
755 void vout_LinkPicture( vout_thread_t *p_vout, picture_t *p_pic )
757 vlc_mutex_lock( &p_vout->picture_lock );
761 intf_DbgMsg("picture %p refcount=%d\n", p_pic, p_pic->i_refcount );
764 vlc_mutex_unlock( &p_vout->picture_lock );
767 /*****************************************************************************
768 * vout_UnlinkPicture: decrement reference counter of a picture
769 *****************************************************************************
770 * This function decrement the reference counter of a picture in the video heap.
771 *****************************************************************************/
772 void vout_UnlinkPicture( vout_thread_t *p_vout, picture_t *p_pic )
774 vlc_mutex_lock( &p_vout->picture_lock );
778 if( p_pic->i_refcount < 0 )
780 intf_DbgMsg("error: refcount < 0\n");
781 p_pic->i_refcount = 0;
785 if( (p_pic->i_refcount == 0) && (p_pic->i_status == DISPLAYED_PICTURE) )
787 p_pic->i_status = DESTROYED_PICTURE;
788 p_vout->i_pictures--;
792 intf_DbgMsg("picture %p refcount=%d\n", p_pic, p_pic->i_refcount );
795 vlc_mutex_unlock( &p_vout->picture_lock );
798 /*****************************************************************************
799 * vout_SetBuffers: set buffers adresses
800 *****************************************************************************
801 * This function is called by system drivers to set buffers video memory
803 *****************************************************************************/
804 void vout_SetBuffers( vout_thread_t *p_vout, void *p_buf1, void *p_buf2 )
806 /* No picture previously */
807 p_vout->p_buffer[0].i_pic_x = 0;
808 p_vout->p_buffer[0].i_pic_y = 0;
809 p_vout->p_buffer[0].i_pic_width = 0;
810 p_vout->p_buffer[0].i_pic_height = 0;
811 p_vout->p_buffer[1].i_pic_x = 0;
812 p_vout->p_buffer[1].i_pic_y = 0;
813 p_vout->p_buffer[1].i_pic_width = 0;
814 p_vout->p_buffer[1].i_pic_height = 0;
816 /* The first area covers all the screen */
817 p_vout->p_buffer[0].i_areas = 1;
818 p_vout->p_buffer[0].pi_area_begin[0] = 0;
819 p_vout->p_buffer[0].pi_area_end[0] = p_vout->i_height - 1;
820 p_vout->p_buffer[1].i_areas = 1;
821 p_vout->p_buffer[1].pi_area_begin[0] = 0;
822 p_vout->p_buffer[1].pi_area_end[0] = p_vout->i_height - 1;
825 p_vout->p_buffer[0].p_data = p_buf1;
826 p_vout->p_buffer[1].p_data = p_buf2;
829 /*****************************************************************************
830 * vout_Pixel2RGB: return red, green and blue from pixel value
831 *****************************************************************************
832 * Return color values, in 0-255 range, of the decomposition of a pixel. This
833 * is a slow routine and should only be used for initialization phase.
834 *****************************************************************************/
835 void vout_Pixel2RGB( vout_thread_t *p_vout, u32 i_pixel, int *pi_red, int *pi_green, int *pi_blue )
837 *pi_red = i_pixel & p_vout->i_red_mask;
838 *pi_green = i_pixel & p_vout->i_green_mask;
839 *pi_blue = i_pixel & p_vout->i_blue_mask;
842 /* following functions are local */
844 /*****************************************************************************
845 * BinaryLog: computes the base 2 log of a binary value
846 *****************************************************************************
847 * This functions is used by MaskToShift, to get a bit index from a binary
849 *****************************************************************************/
850 static int BinaryLog(u32 i)
875 if (i != ((u32)1 << i_log))
877 intf_DbgMsg("internal error: binary log overflow\n");
883 /*****************************************************************************
884 * MaskToShift: transform a color mask into right and left shifts
885 *****************************************************************************
886 * This function is used for obtaining color shifts from masks.
887 *****************************************************************************/
888 static void MaskToShift( int *pi_left, int *pi_right, u32 i_mask )
890 u32 i_low, i_high; /* lower hand higher bits of the mask */
893 i_low = i_mask & (- i_mask); /* lower bit of the mask */
894 i_high = i_mask + i_low; /* higher bit of the mask */
896 /* Transform bits into an index */
897 i_low = BinaryLog (i_low);
898 i_high = BinaryLog (i_high);
900 /* Update pointers and return */
902 *pi_right = (8 - i_high + i_low);
905 /*****************************************************************************
906 * InitThread: initialize video output thread
907 *****************************************************************************
908 * This function is called from RunThread and performs the second step of the
909 * initialization. It returns 0 on success. Note that the thread's flag are not
910 * modified inside this function.
911 *****************************************************************************/
912 static int InitThread( vout_thread_t *p_vout )
916 *p_vout->pi_status = THREAD_START;
918 /* Initialize output method - this function issues its own error messages */
919 if( p_vout->p_sys_init( p_vout ) )
924 /* Initialize convertion tables and functions */
925 if( vout_InitYUV( p_vout ) )
927 intf_ErrMsg("error: can't allocate YUV translation tables\n");
931 /* Mark thread as running and return */
932 p_vout->b_active = 1;
933 *p_vout->pi_status = THREAD_READY;
936 intf_DbgMsg("thread ready\n");
940 /*****************************************************************************
941 * RunThread: video output thread
942 *****************************************************************************
943 * Video output thread. This function does only returns when the thread is
944 * terminated. It handles the pictures arriving in the video heap and the
945 * display device events.
946 *****************************************************************************/
947 static void RunThread( vout_thread_t *p_vout)
949 /* XXX?? welcome to gore land */
950 static int i_trash_count = 0;
951 static mtime_t last_display_date = 0;
953 int i_index; /* index in heap */
954 mtime_t current_date; /* current date */
955 mtime_t display_date; /* display date */
956 boolean_t b_display; /* display flag */
957 picture_t * p_pic; /* picture pointer */
958 subpicture_t * p_subpic; /* subpicture pointer */
963 p_vout->b_error = InitThread( p_vout );
964 if( p_vout->b_error )
966 DestroyThread( p_vout, THREAD_ERROR );
972 * Main loop - it is not executed if an error occured during
975 while( (!p_vout->b_die) && (!p_vout->b_error) )
977 /* Initialize loop variables */
981 current_date = mdate();
984 * Find the picture to display - this operation does not need lock,
985 * since only READY_PICTUREs are handled
987 for( i_index = 0; i_index < VOUT_MAX_PICTURES; i_index++ )
989 if( (p_vout->p_picture[i_index].i_status == READY_PICTURE) &&
991 (p_vout->p_picture[i_index].date < display_date) ) )
993 p_pic = &p_vout->p_picture[i_index];
994 display_date = p_pic->date;
1001 /* Computes FPS rate */
1002 p_vout->p_fps_sample[ p_vout->c_fps_samples++ % VOUT_FPS_SAMPLES ] = display_date;
1006 //fprintf( stderr, "gap : %Ld\n", display_date-last_display_date );
1007 last_display_date = display_date;
1009 if( display_date < current_date && i_trash_count > 4 )
1011 /* Picture is late: it will be destroyed and the thread
1012 * will sleep and go to next picture */
1014 vlc_mutex_lock( &p_vout->picture_lock );
1015 if( p_pic->i_refcount )
1017 p_pic->i_status = DISPLAYED_PICTURE;
1021 p_pic->i_status = DESTROYED_PICTURE;
1022 p_vout->i_pictures--;
1024 intf_DbgMsg( "warning: late picture %p skipped refcount=%d\n", p_pic, p_pic->i_refcount );
1025 vlc_mutex_unlock( &p_vout->picture_lock );
1027 /* Update synchronization information as if display delay
1029 Synchronize( p_vout, display_date - current_date );
1037 if( display_date > current_date + VOUT_DISPLAY_DELAY )
1039 /* A picture is ready to be rendered, but its rendering date
1040 * is far from the current one so the thread will perform an
1041 * empty loop as if no picture were found. The picture state
1048 /* Picture will be displayed, update synchronization
1050 Synchronize( p_vout, display_date - current_date );
1054 * Find the subpictures to display - this operation does not need
1055 * lock, since only READY_SUBPICTURE are handled. If no picture
1056 * has been selected, display_date will depend on the subpicture.
1057 * We get an easily parsable chained list of subpictures which
1058 * ends with NULL since p_subpic was initialized to NULL.
1060 for( i_index = 0; i_index < VOUT_MAX_SUBPICTURES; i_index++ )
1062 if( p_vout->p_subpicture[i_index].i_status == READY_SUBPICTURE )
1064 p_vout->p_subpicture[i_index].p_next = p_subpic;
1065 p_subpic = &p_vout->p_subpicture[i_index];
1071 * Perform rendering, sleep and display rendered picture
1074 if( p_pic ) /* picture and perhaps subpicture */
1076 b_display = p_vout->b_active;
1077 p_vout->last_display_date = display_date;
1081 /* Set picture dimensions and clear buffer */
1082 SetBufferPicture( p_vout, p_pic );
1084 /* Render picture and information */
1085 RenderPicture( p_vout, p_pic );
1086 if( p_vout->b_info )
1088 RenderPictureInfo( p_vout, p_pic );
1089 RenderInfo( p_vout );
1093 RenderSubPicture( p_vout, p_subpic );
1097 /* Remove picture from heap */
1098 vlc_mutex_lock( &p_vout->picture_lock );
1099 if( p_pic->i_refcount )
1101 p_pic->i_status = DISPLAYED_PICTURE;
1105 p_pic->i_status = DESTROYED_PICTURE;
1106 p_vout->i_pictures--;
1108 vlc_mutex_unlock( &p_vout->picture_lock );
1110 /* Render interface and subpicture */
1111 if( b_display && p_vout->b_interface )
1113 RenderInterface( p_vout );
1117 else if( p_vout->b_active && p_vout->init_display_date == 0) /* idle or interface screen alone */
1119 if( p_vout->b_interface && 0 /* && XXX?? intf_change */ )
1121 /* Interface has changed, so a new rendering is required - force
1122 * it by setting last idle date to 0 */
1123 p_vout->last_idle_date = 0;
1126 /* Render idle screen and update idle date, then render interface if
1128 b_display = RenderIdle( p_vout );
1131 p_vout->last_idle_date = current_date;
1132 if( p_vout->b_interface )
1134 RenderInterface( p_vout );
1146 * chech for the current time and
1147 * display splash screen if everything is on time
1149 if( p_vout->init_display_date > 0)
1151 if( p_vout->b_active &&
1152 mdate()-p_vout->init_display_date < 5000000)
1154 /* there is something to display ! */
1156 RenderSplash( p_vout );
1159 /* no splash screen ! */
1160 intf_ErrMsgImm("End of splash screen\n");
1161 p_vout->init_display_date=0;
1169 * Sleep, wake up and display rendered picture
1173 /* Store render time */
1174 p_vout->render_time = mdate() - current_date;
1177 /* Give back change lock */
1178 vlc_mutex_unlock( &p_vout->change_lock );
1180 /* Sleep a while or until a given date */
1181 if( display_date != 0 )
1183 mwait( display_date );
1187 msleep( VOUT_IDLE_SLEEP );
1190 /* On awakening, take back lock and send immediately picture to display,
1191 * then swap buffers */
1192 vlc_mutex_lock( &p_vout->change_lock );
1194 intf_DbgMsg( "picture %p, subpicture %p in buffer %d, display=%d\n", p_pic, p_subpic,
1195 p_vout->i_buffer_index, b_display && !(p_vout->i_changes & VOUT_NODISPLAY_CHANGE) );
1197 if( b_display && !(p_vout->i_changes & VOUT_NODISPLAY_CHANGE) )
1199 p_vout->p_sys_display( p_vout );
1201 p_vout->i_buffer_index = ++p_vout->i_buffer_index & 1;
1206 * Check events and manage thread
1208 if( p_vout->p_sys_manage( p_vout ) | Manage( p_vout ) )
1210 /* A fatal error occured, and the thread must terminate immediately,
1211 * without displaying anything - setting b_error to 1 cause the
1212 * immediate end of the main while() loop. */
1213 p_vout->b_error = 1;
1218 * Error loop - wait until the thread destruction is requested
1220 if( p_vout->b_error )
1222 ErrorThread( p_vout );
1226 EndThread( p_vout );
1227 DestroyThread( p_vout, THREAD_OVER );
1228 intf_DbgMsg( "thread end\n" );
1231 /*****************************************************************************
1232 * ErrorThread: RunThread() error loop
1233 *****************************************************************************
1234 * This function is called when an error occured during thread main's loop. The
1235 * thread can still receive feed, but must be ready to terminate as soon as
1237 *****************************************************************************/
1238 static void ErrorThread( vout_thread_t *p_vout )
1240 /* Wait until a `die' order */
1242 while( !p_vout->b_die )
1245 msleep( VOUT_IDLE_SLEEP );
1249 /*****************************************************************************
1250 * EndThread: thread destruction
1251 *****************************************************************************
1252 * This function is called when the thread ends after a sucessful
1253 * initialization. It frees all ressources allocated by InitThread.
1254 *****************************************************************************/
1255 static void EndThread( vout_thread_t *p_vout )
1257 int i_index; /* index in heap */
1261 *p_vout->pi_status = THREAD_END;
1263 /* Destroy all remaining pictures and subpictures */
1264 for( i_index = 0; i_index < VOUT_MAX_PICTURES; i_index++ )
1266 if( p_vout->p_picture[i_index].i_status != FREE_PICTURE )
1268 free( p_vout->p_picture[i_index].p_data );
1271 for( i_index = 0; i_index < VOUT_MAX_SUBPICTURES; i_index++ )
1273 if( p_vout->p_subpicture[i_index].i_status != FREE_SUBPICTURE )
1275 free( p_vout->p_subpicture[i_index].p_data );
1279 /* Destroy translation tables */
1280 vout_EndYUV( p_vout );
1281 p_vout->p_sys_end( p_vout );
1284 /*****************************************************************************
1285 * DestroyThread: thread destruction
1286 *****************************************************************************
1287 * This function is called when the thread ends. It frees all ressources
1288 * allocated by CreateThread. Status is available at this stage.
1289 *****************************************************************************/
1290 static void DestroyThread( vout_thread_t *p_vout, int i_status )
1292 int *pi_status; /* status adress */
1294 /* Store status adress */
1296 pi_status = p_vout->pi_status;
1298 /* Destroy thread structures allocated by Create and InitThread */
1299 vout_UnloadFont( p_vout->p_default_font );
1300 vout_UnloadFont( p_vout->p_large_font );
1301 p_vout->p_sys_destroy( p_vout );
1303 /* Free structure */
1305 *pi_status = i_status;
1308 /*****************************************************************************
1309 * Print: print simple text on a picture
1310 *****************************************************************************
1311 * This function will print a simple text on the picture. It is designed to
1312 * print debugging or general information.
1313 *****************************************************************************/
1314 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 )
1316 int i_text_height; /* total text height */
1317 int i_text_width; /* total text width */
1319 /* Update upper left coordinates according to alignment */
1320 vout_TextSize( p_vout->p_default_font, 0, psz_text, &i_text_width, &i_text_height );
1321 if( !Align( p_vout, &i_x, &i_y, i_text_width, i_text_height, i_h_align, i_v_align ) )
1323 /* Set area and print text */
1324 SetBufferArea( p_vout, i_x, i_y, i_text_width, i_text_height );
1325 vout_Print( p_vout->p_default_font, p_vout->p_buffer[ p_vout->i_buffer_index ].p_data +
1326 i_y * p_vout->i_bytes_per_line + i_x * p_vout->i_bytes_per_pixel,
1327 p_vout->i_bytes_per_pixel, p_vout->i_bytes_per_line,
1328 p_vout->i_white_pixel, 0, 0,
1333 /*****************************************************************************
1334 * SetBufferArea: activate an area in current buffer
1335 *****************************************************************************
1336 * This function is called when something is rendered on the current buffer.
1337 * It set the area as active and prepare it to be cleared on next rendering.
1338 * Pay attention to the fact that in this functions, i_h is in fact the end y
1339 * coordinate of the new area.
1340 *****************************************************************************/
1341 static void SetBufferArea( vout_thread_t *p_vout, int i_x, int i_y, int i_w, int i_h )
1343 vout_buffer_t * p_buffer; /* current buffer */
1344 int i_area_begin, i_area_end; /* area vertical extension */
1345 int i_area, i_area_copy; /* area index */
1346 int i_area_shift; /* shift distance for areas */
1348 /* Choose buffer and modify h to end of area position */
1349 p_buffer = &p_vout->p_buffer[ p_vout->i_buffer_index ];
1353 * Remove part of the area which is inside the picture - this is done
1354 * by calling again SetBufferArea with the correct areas dimensions.
1356 if( (i_x >= p_buffer->i_pic_x) && (i_x + i_w <= p_buffer->i_pic_x + p_buffer->i_pic_width) )
1358 i_area_begin = p_buffer->i_pic_y;
1359 i_area_end = i_area_begin + p_buffer->i_pic_height - 1;
1361 if( ((i_y >= i_area_begin) && (i_y <= i_area_end)) ||
1362 ((i_h >= i_area_begin) && (i_h <= i_area_end)) ||
1363 ((i_y < i_area_begin) && (i_h > i_area_end)) )
1365 /* Keep the stripe above the picture, if any */
1366 if( i_y < i_area_begin )
1368 SetBufferArea( p_vout, i_x, i_y, i_w, i_area_begin - i_y );
1370 /* Keep the stripe below the picture, if any */
1371 if( i_h > i_area_end )
1373 SetBufferArea( p_vout, i_x, i_area_end, i_w, i_h - i_area_end );
1379 /* Skip some extensions until interesting areas */
1381 (i_area < p_buffer->i_areas) &&
1382 (p_buffer->pi_area_end[i_area] + 1 <= i_y);
1388 if( i_area == p_buffer->i_areas )
1390 /* New area is below all existing ones: just add it at the end of the
1391 * array, if possible - otherwise, append it to the last one */
1392 if( i_area < VOUT_MAX_AREAS )
1394 p_buffer->pi_area_begin[i_area] = i_y;
1395 p_buffer->pi_area_end[i_area] = i_h;
1396 p_buffer->i_areas++;
1401 intf_DbgMsg("area overflow\n");
1403 p_buffer->pi_area_end[VOUT_MAX_AREAS - 1] = i_h;
1408 i_area_begin = p_buffer->pi_area_begin[i_area];
1409 i_area_end = p_buffer->pi_area_end[i_area];
1411 if( i_y < i_area_begin )
1413 if( i_h >= i_area_begin - 1 )
1415 /* Extend area above */
1416 p_buffer->pi_area_begin[i_area] = i_y;
1420 /* Create a new area above : merge last area if overflow, then
1421 * move all old areas down */
1422 if( p_buffer->i_areas == VOUT_MAX_AREAS )
1425 intf_DbgMsg("areas overflow\n");
1427 p_buffer->pi_area_end[VOUT_MAX_AREAS - 2] = p_buffer->pi_area_end[VOUT_MAX_AREAS - 1];
1431 p_buffer->i_areas++;
1433 for( i_area_copy = p_buffer->i_areas - 1; i_area_copy > i_area; i_area_copy-- )
1435 p_buffer->pi_area_begin[i_area_copy] = p_buffer->pi_area_begin[i_area_copy - 1];
1436 p_buffer->pi_area_end[i_area_copy] = p_buffer->pi_area_end[i_area_copy - 1];
1438 p_buffer->pi_area_begin[i_area] = i_y;
1439 p_buffer->pi_area_end[i_area] = i_h;
1443 if( i_h > i_area_end )
1445 /* Find further areas which can be merged with the new one */
1446 for( i_area_copy = i_area + 1;
1447 (i_area_copy < p_buffer->i_areas) &&
1448 (p_buffer->pi_area_begin[i_area] <= i_h);
1455 if( i_area_copy != i_area )
1457 /* Merge with last possible areas */
1458 p_buffer->pi_area_end[i_area] = MAX( i_h, p_buffer->pi_area_end[i_area_copy] );
1460 /* Shift lower areas upward */
1461 i_area_shift = i_area_copy - i_area;
1462 p_buffer->i_areas -= i_area_shift;
1463 for( i_area_copy = i_area + 1; i_area_copy < p_buffer->i_areas; i_area_copy++ )
1465 p_buffer->pi_area_begin[i_area_copy] = p_buffer->pi_area_begin[i_area_copy + i_area_shift];
1466 p_buffer->pi_area_end[i_area_copy] = p_buffer->pi_area_end[i_area_copy + i_area_shift];
1471 /* Extend area below */
1472 p_buffer->pi_area_end[i_area] = i_h;
1478 /*****************************************************************************
1479 * SetBufferPicture: clear buffer and set picture area
1480 *****************************************************************************
1481 * This function is called before any rendering. It clears the current
1482 * rendering buffer and set the new picture area. If the picture pointer is
1483 * NULL, then no picture area is defined. Floating operations are avoided since
1484 * some MMX calculations may follow.
1485 *****************************************************************************/
1486 static void SetBufferPicture( vout_thread_t *p_vout, picture_t *p_pic )
1488 vout_buffer_t * p_buffer; /* current buffer */
1489 int i_pic_x, i_pic_y; /* picture position */
1490 int i_pic_width, i_pic_height; /* picture dimensions */
1491 int i_old_pic_y, i_old_pic_height; /* old picture area */
1492 int i_vout_width, i_vout_height; /* display dimensions */
1493 int i_area; /* area index */
1494 int i_data_index; /* area data index */
1495 int i_data_size; /* area data size, in 256 bytes blocs */
1496 u64 * p_data; /* area data, for clearing */
1497 byte_t * p_data8; /* area data, for clearing (slow) */
1499 /* Choose buffer and set display dimensions */
1500 p_buffer = &p_vout->p_buffer[ p_vout->i_buffer_index ];
1501 i_vout_width = p_vout->i_width;
1502 i_vout_height = p_vout->i_height;
1505 * Computes new picture size
1509 /* Try horizontal scaling first - width must be a mutiple of 16 */
1510 i_pic_width = (( p_vout->b_scale || (p_pic->i_width > i_vout_width)) ?
1511 i_vout_width : p_pic->i_width) & ~0xf;
1512 switch( p_pic->i_aspect_ratio )
1514 case AR_3_4_PICTURE:
1515 i_pic_height = i_pic_width * 3 / 4;
1517 case AR_16_9_PICTURE:
1518 i_pic_height = i_pic_width * 9 / 16;
1520 case AR_221_1_PICTURE:
1521 i_pic_height = i_pic_width * 100 / 221;
1523 case AR_SQUARE_PICTURE:
1525 i_pic_height = p_pic->i_height * i_pic_width / p_pic->i_width;
1529 /* If picture dimensions using horizontal scaling are too large, use
1530 * vertical scaling. Since width must be a multiple of 16, height is
1531 * adjusted again after. */
1532 if( i_pic_height > i_vout_height )
1534 i_pic_height = ( p_vout->b_scale || (p_pic->i_height > i_vout_height)) ?
1535 i_vout_height : p_pic->i_height;
1536 switch( p_pic->i_aspect_ratio )
1538 case AR_3_4_PICTURE:
1539 i_pic_width = (i_pic_height * 4 / 3) & ~0xf;
1540 i_pic_height = i_pic_width * 3 / 4;
1542 case AR_16_9_PICTURE:
1543 i_pic_width = (i_pic_height * 16 / 9) & ~0xf;
1544 i_pic_height = i_pic_width * 9 / 16;
1546 case AR_221_1_PICTURE:
1547 i_pic_width = (i_pic_height * 221 / 100) & ~0xf;
1548 i_pic_height = i_pic_width * 100 / 221;
1550 case AR_SQUARE_PICTURE:
1552 i_pic_width = (p_pic->i_width * i_pic_height / p_pic->i_height) & ~0xf;
1553 i_pic_height = p_pic->i_height * i_pic_width / p_pic->i_width;
1558 /* Set picture position */
1559 i_pic_x = (p_vout->i_width - i_pic_width) / 2;
1560 i_pic_y = (p_vout->i_height - i_pic_height) / 2;
1564 /* No picture: size is 0 */
1572 * Set new picture size - if it is smaller than the previous one, clear
1573 * around it. Since picture are centered, only their size is tested.
1575 if( (p_buffer->i_pic_width > i_pic_width) || (p_buffer->i_pic_height > i_pic_height) )
1577 i_old_pic_y = p_buffer->i_pic_y;
1578 i_old_pic_height = p_buffer->i_pic_height;
1579 p_buffer->i_pic_x = i_pic_x;
1580 p_buffer->i_pic_y = i_pic_y;
1581 p_buffer->i_pic_width = i_pic_width;
1582 p_buffer->i_pic_height = i_pic_height;
1583 SetBufferArea( p_vout, 0, i_old_pic_y, p_vout->i_width, i_old_pic_height );
1587 p_buffer->i_pic_x = i_pic_x;
1588 p_buffer->i_pic_y = i_pic_y;
1589 p_buffer->i_pic_width = i_pic_width;
1590 p_buffer->i_pic_height = i_pic_height;
1596 for( i_area = 0; i_area < p_buffer->i_areas; i_area++ )
1599 intf_DbgMsg("clearing picture %p area in buffer %d: %d-%d\n", p_pic,
1600 p_vout->i_buffer_index, p_buffer->pi_area_begin[i_area], p_buffer->pi_area_end[i_area] );
1602 i_data_size = (p_buffer->pi_area_end[i_area] - p_buffer->pi_area_begin[i_area] + 1) * p_vout->i_bytes_per_line;
1603 p_data = (u64*) (p_buffer->p_data + p_vout->i_bytes_per_line * p_buffer->pi_area_begin[i_area]);
1604 for( i_data_index = i_data_size / 256; i_data_index-- ; )
1606 /* Clear 256 bytes block */
1607 *p_data++ = 0; *p_data++ = 0; *p_data++ = 0; *p_data++ = 0;
1608 *p_data++ = 0; *p_data++ = 0; *p_data++ = 0; *p_data++ = 0;
1609 *p_data++ = 0; *p_data++ = 0; *p_data++ = 0; *p_data++ = 0;
1610 *p_data++ = 0; *p_data++ = 0; *p_data++ = 0; *p_data++ = 0;
1611 *p_data++ = 0; *p_data++ = 0; *p_data++ = 0; *p_data++ = 0;
1612 *p_data++ = 0; *p_data++ = 0; *p_data++ = 0; *p_data++ = 0;
1613 *p_data++ = 0; *p_data++ = 0; *p_data++ = 0; *p_data++ = 0;
1614 *p_data++ = 0; *p_data++ = 0; *p_data++ = 0; *p_data++ = 0;
1616 for( i_data_index = (i_data_size % 256) / 16; i_data_index--; )
1618 /* Clear remaining 16 bytes blocks */
1619 *p_data++ = 0; *p_data++ = 0;
1621 p_data8 = (byte_t *)p_data;
1622 for( i_data_index = i_data_size % 16; i_data_index--; )
1624 /* Clear remaining bytes */
1632 p_buffer->i_areas = 0;
1635 /*****************************************************************************
1636 * RenderPicture: render a picture
1637 *****************************************************************************
1638 * This function converts a picture from a video heap to a pixel-encoded image
1639 * and copies it to the current rendering buffer. No lock is required, since
1640 * the * rendered picture has been determined as existant, and will only be
1641 * destroyed by the vout thread later.
1642 *****************************************************************************/
1643 static void RenderPicture( vout_thread_t *p_vout, picture_t *p_pic )
1646 char psz_date[MSTRTIME_MAX_SIZE]; /* picture date */
1647 mtime_t render_time; /* picture rendering time */
1649 vout_buffer_t * p_buffer; /* rendering buffer */
1650 byte_t * p_pic_data; /* convertion destination */
1652 /* Get and set rendering information */
1653 p_buffer = &p_vout->p_buffer[ p_vout->i_buffer_index ];
1654 p_pic_data = p_buffer->p_data +
1655 p_buffer->i_pic_x * p_vout->i_bytes_per_pixel +
1656 p_buffer->i_pic_y * p_vout->i_bytes_per_line;
1658 render_time = mdate();
1662 * Choose appropriate rendering function and render picture
1664 switch( p_pic->i_type )
1666 case YUV_420_PICTURE:
1667 p_vout->yuv.p_Convert420( p_vout, p_pic_data,
1668 p_pic->p_y, p_pic->p_u, p_pic->p_v,
1669 p_pic->i_width, p_pic->i_height,
1670 p_buffer->i_pic_width, p_buffer->i_pic_height,
1671 p_vout->i_bytes_per_line / p_vout->i_bytes_per_pixel,
1672 p_pic->i_matrix_coefficients );
1674 case YUV_422_PICTURE:
1675 p_vout->yuv.p_Convert422( p_vout, p_pic_data,
1676 p_pic->p_y, p_pic->p_u, p_pic->p_v,
1677 p_pic->i_width, p_pic->i_height,
1678 p_buffer->i_pic_width, p_buffer->i_pic_height,
1679 p_vout->i_bytes_per_line / p_vout->i_bytes_per_pixel,
1680 p_pic->i_matrix_coefficients );
1682 case YUV_444_PICTURE:
1683 p_vout->yuv.p_Convert444( p_vout, p_pic_data,
1684 p_pic->p_y, p_pic->p_u, p_pic->p_v,
1685 p_pic->i_width, p_pic->i_height,
1686 p_buffer->i_pic_width, p_buffer->i_pic_height,
1687 p_vout->i_bytes_per_line / p_vout->i_bytes_per_pixel,
1688 p_pic->i_matrix_coefficients );
1692 intf_DbgMsg("error: unknown picture type %d\n", p_pic->i_type );
1698 /* Print picture date and rendering time */
1699 intf_DbgMsg("picture %p rendered in buffer %d (%ld us), display date: %s\n", p_pic,
1700 p_vout->i_buffer_index, (long) (mdate() - render_time),
1701 mstrtime( psz_date, p_pic->date ));
1705 /*****************************************************************************
1706 * RenderPictureInfo: print additionnal information on a picture
1707 *****************************************************************************
1708 * This function will print information such as fps and other picture
1709 * dependant information.
1710 *****************************************************************************/
1711 static void RenderPictureInfo( vout_thread_t *p_vout, picture_t *p_pic )
1713 #if defined(STATS) || defined(DEBUG)
1714 char psz_buffer[256]; /* string buffer */
1719 * Print FPS rate in upper right corner
1721 if( p_vout->c_fps_samples > VOUT_FPS_SAMPLES )
1723 long i_fps = VOUT_FPS_SAMPLES * 1000000 * 10 /
1724 ( p_vout->p_fps_sample[ (p_vout->c_fps_samples - 1)
1725 % VOUT_FPS_SAMPLES ] -
1726 p_vout->p_fps_sample[ p_vout->c_fps_samples
1727 % VOUT_FPS_SAMPLES ] );
1728 sprintf( psz_buffer, "%li.%i fps", i_fps / 10, (int)i_fps % 10 );
1729 Print( p_vout, 0, 0, RIGHT_RALIGN, TOP_RALIGN, psz_buffer );
1733 * Print frames count and loop time in upper left corner
1735 sprintf( psz_buffer, "%ld frames, render: %ldus",
1736 (long) p_vout->c_fps_samples, (long) p_vout->render_time );
1737 Print( p_vout, 0, 0, LEFT_RALIGN, TOP_RALIGN, psz_buffer );
1742 * Print picture information in lower right corner
1744 sprintf( psz_buffer, "%s picture %dx%d (%dx%d%+d%+d %s) -> %dx%d+%d+%d",
1745 (p_pic->i_type == YUV_420_PICTURE) ? "4:2:0" :
1746 ((p_pic->i_type == YUV_422_PICTURE) ? "4:2:2" :
1747 ((p_pic->i_type == YUV_444_PICTURE) ? "4:4:4" : "ukn-type")),
1748 p_pic->i_width, p_pic->i_height,
1749 p_pic->i_display_width, p_pic->i_display_height,
1750 p_pic->i_display_horizontal_offset, p_pic->i_display_vertical_offset,
1751 (p_pic->i_aspect_ratio == AR_SQUARE_PICTURE) ? "sq" :
1752 ((p_pic->i_aspect_ratio == AR_3_4_PICTURE) ? "4:3" :
1753 ((p_pic->i_aspect_ratio == AR_16_9_PICTURE) ? "16:9" :
1754 ((p_pic->i_aspect_ratio == AR_221_1_PICTURE) ? "2.21:1" : "ukn-ar" ))),
1755 p_vout->p_buffer[ p_vout->i_buffer_index ].i_pic_width,
1756 p_vout->p_buffer[ p_vout->i_buffer_index ].i_pic_height,
1757 p_vout->p_buffer[ p_vout->i_buffer_index ].i_pic_x,
1758 p_vout->p_buffer[ p_vout->i_buffer_index ].i_pic_y );
1759 Print( p_vout, 0, 0, RIGHT_RALIGN, BOTTOM_RALIGN, psz_buffer );
1763 /*****************************************************************************
1764 * RenderSplash: render splash picture
1765 *****************************************************************************
1766 * This function will print something on the screen. It will return 0 if
1767 * nothing has been rendered, or 1 if something has been changed on the screen.
1768 * Note that if you absolutely want something to be printed, you will have
1769 * to force it by setting the last idle date to 0.
1770 * Unlike other rendering functions, this one calls the SetBufferPicture
1771 * function when needed.
1772 *****************************************************************************/
1773 int RenderSplash( vout_thread_t *p_vout )
1775 int i_x = 0, i_y = 0; /* text position */
1776 int i_width, i_height; /* text size */
1777 char *psz_text = "VideoLan Client (" VERSION ")"; /* text to display */
1779 memset( p_vout->p_buffer[ p_vout->i_buffer_index ].p_data,
1780 p_vout->i_bytes_per_line * p_vout->i_height, 12);
1782 // SetBufferPicture( p_vout, NULL );
1783 vout_TextSize( p_vout->p_large_font, WIDE_TEXT | OUTLINED_TEXT, psz_text,
1784 &i_width, &i_height );
1785 if( !Align( p_vout, &i_x, &i_y, i_width, i_height, CENTER_RALIGN, CENTER_RALIGN ) )
1787 vout_Print( p_vout->p_large_font,
1788 p_vout->p_buffer[ p_vout->i_buffer_index ].p_data +
1789 i_x * p_vout->i_bytes_per_pixel + (i_y - 16 ) * p_vout->i_bytes_per_line,
1790 p_vout->i_bytes_per_pixel, p_vout->i_bytes_per_line,
1791 p_vout->i_white_pixel, p_vout->i_gray_pixel, 0,
1792 WIDE_TEXT | OUTLINED_TEXT, psz_text, 100);
1793 SetBufferArea( p_vout, i_x, i_y, i_width, i_height);
1799 /*****************************************************************************
1800 * RenderIdle: render idle picture
1801 *****************************************************************************
1802 * This function will print something on the screen. It will return 0 if
1803 * nothing has been rendered, or 1 if something has been changed on the screen.
1804 * Note that if you absolutely want something to be printed, you will have
1805 * to force it by setting the last idle date to 0.
1806 * Unlike other rendering functions, this one calls the SetBufferPicture
1807 * function when needed.
1808 *****************************************************************************/
1809 int RenderIdle( vout_thread_t *p_vout )
1811 int i_x = 0, i_y = 0; /* text position */
1812 int i_width, i_height; /* text size */
1813 mtime_t current_date; /* current date */
1814 int i_amount = 0; /* amount to draw */
1815 char *psz_text = "Waiting for stream"; /* text to display */
1816 char *psz_wtext = "[................]";
1819 memset( p_vout->p_buffer[ p_vout->i_buffer_index ].p_data,
1820 p_vout->i_bytes_per_line * p_vout->i_height, 12);
1823 current_date = mdate();
1824 if( (current_date - p_vout->last_display_date) > VOUT_IDLE_DELAY
1825 // && (current_date - p_vout->last_idle_date) > VOUT_IDLE_DELAY
1828 SetBufferPicture( p_vout, NULL );
1829 vout_TextSize( p_vout->p_large_font, WIDE_TEXT | OUTLINED_TEXT, psz_text,
1830 &i_width, &i_height );
1831 if( !Align( p_vout, &i_x, &i_y, i_width, i_height * 2, CENTER_RALIGN, CENTER_RALIGN ) )
1833 i_amount = (int) ((current_date - p_vout->last_display_date ) / 5000LL);
1834 vout_Print( p_vout->p_large_font,
1835 p_vout->p_buffer[ p_vout->i_buffer_index ].p_data +
1836 i_x * p_vout->i_bytes_per_pixel + i_y * p_vout->i_bytes_per_line,
1837 p_vout->i_bytes_per_pixel, p_vout->i_bytes_per_line,
1838 p_vout->i_white_pixel, p_vout->i_gray_pixel, 0,
1839 WIDE_TEXT | OUTLINED_TEXT, psz_text, (i_amount / 3 ) %110);
1841 vout_Print( p_vout->p_large_font,
1842 p_vout->p_buffer[ p_vout->i_buffer_index ].p_data +
1843 i_x * p_vout->i_bytes_per_pixel + (i_y + 16) * p_vout->i_bytes_per_line,
1844 p_vout->i_bytes_per_pixel, p_vout->i_bytes_per_line,
1845 p_vout->i_white_pixel, p_vout->i_gray_pixel, 0,
1846 WIDE_TEXT | OUTLINED_TEXT, psz_wtext, (i_amount/5)%110 );
1849 SetBufferArea( p_vout, i_x, i_y, i_width, i_height * 2 );
1856 /*****************************************************************************
1857 * RenderInfo: render additionnal information
1858 *****************************************************************************
1859 * This function renders information which do not depend on the current
1861 *****************************************************************************/
1862 static void RenderInfo( vout_thread_t *p_vout )
1865 char psz_buffer[256]; /* string buffer */
1866 int i_ready_pic = 0; /* ready pictures */
1867 int i_reserved_pic = 0; /* reserved pictures */
1868 int i_picture; /* picture index */
1873 * Print thread state in lower left corner
1875 for( i_picture = 0; i_picture < VOUT_MAX_PICTURES; i_picture++ )
1877 switch( p_vout->p_picture[i_picture].i_status )
1879 case RESERVED_PICTURE:
1880 case RESERVED_DATED_PICTURE:
1881 case RESERVED_DISP_PICTURE:
1889 sprintf( psz_buffer, "pic: %d (%d/%d)/%d",
1890 p_vout->i_pictures, i_reserved_pic, i_ready_pic, VOUT_MAX_PICTURES );
1891 Print( p_vout, 0, 0, LEFT_RALIGN, BOTTOM_RALIGN, psz_buffer );
1895 /*****************************************************************************
1896 * RenderSubPicture: render a subpicture
1897 *****************************************************************************
1898 * This function renders a sub picture unit.
1899 *****************************************************************************/
1900 static void RenderSubPicture( vout_thread_t *p_vout, subpicture_t *p_subpic )
1902 p_vout_font_t p_font; /* text font */
1903 int i_width, i_height; /* subpicture dimensions */
1905 while( p_subpic != NULL )
1907 switch( p_subpic->i_type )
1909 case DVD_SUBPICTURE: /* DVD subpicture unit */
1910 /* test if the picture really has to be displayed */
1911 if( mdate() < p_subpic->begin_date )
1913 /* not yet, see you later */
1916 if( mdate() > p_subpic->end_date )
1918 /* too late, destroying the subpic */
1919 vout_DestroySubPicture( p_vout, p_subpic );
1922 vout_RenderSPU( &p_vout->p_buffer[ p_vout->i_buffer_index ],
1923 p_subpic, p_vout->i_bytes_per_pixel,
1924 p_vout->i_bytes_per_line );
1926 case TEXT_SUBPICTURE: /* single line text */
1927 /* Select default font if not specified */
1928 p_font = p_subpic->type.text.p_font;
1929 if( p_font == NULL )
1931 p_font = p_vout->p_default_font;
1934 /* Compute text size (width and height fields are ignored)
1936 vout_TextSize( p_font, p_subpic->type.text.i_style,
1937 p_subpic->p_data, &i_width, &i_height );
1938 if( !Align( p_vout, &p_subpic->i_x, &p_subpic->i_y,
1939 i_width, i_height, p_subpic->i_horizontal_align,
1940 p_subpic->i_vertical_align ) )
1943 p_vout->p_buffer[ p_vout->i_buffer_index ].p_data +
1944 p_subpic->i_x * p_vout->i_bytes_per_pixel +
1945 p_subpic->i_y * p_vout->i_bytes_per_line,
1946 p_vout->i_bytes_per_pixel, p_vout->i_bytes_per_line,
1947 p_subpic->type.text.i_char_color,
1948 p_subpic->type.text.i_border_color,
1949 p_subpic->type.text.i_bg_color,
1950 p_subpic->type.text.i_style, p_subpic->p_data, 100 );
1951 SetBufferArea( p_vout, p_subpic->i_x, p_subpic->i_y,
1952 i_width, i_height );
1958 intf_DbgMsg( "error: unknown subpicture %p type %d\n",
1959 p_subpic, p_subpic->i_type );
1963 p_subpic = p_subpic->p_next;
1967 /*****************************************************************************
1968 * RenderInterface: render the interface
1969 *****************************************************************************
1970 * This function renders the interface, if any.
1971 *****************************************************************************/
1972 static void RenderInterface( vout_thread_t *p_vout )
1974 int i_height, i_text_height; /* total and text height */
1975 int i_width_1, i_width_2; /* text width */
1976 int i_byte; /* byte index */
1977 const char *psz_text_1 = "[1-9] Channel [i]nfo [c]olor [g/G]amma";
1978 const char *psz_text_2 = "[+/-] Volume [m]ute [s]caling [Q]uit";
1981 vout_TextSize( p_vout->p_large_font, OUTLINED_TEXT, psz_text_1, &i_width_1, &i_height );
1982 vout_TextSize( p_vout->p_large_font, OUTLINED_TEXT, psz_text_2, &i_width_2, &i_text_height );
1983 i_height += i_text_height;
1985 /* Render background */
1986 for( i_byte = (p_vout->i_height - i_height) * p_vout->i_bytes_per_line;
1987 i_byte < p_vout->i_height * p_vout->i_bytes_per_line;
1991 p_vout->p_buffer[ p_vout->i_buffer_index ].p_data[ i_byte ] = p_vout->i_blue_pixel;
1994 /* Render text, if not larger than screen */
1995 if( i_width_1 < p_vout->i_width )
1997 vout_Print( p_vout->p_large_font, p_vout->p_buffer[ p_vout->i_buffer_index ].p_data +
1998 (p_vout->i_height - i_height) * p_vout->i_bytes_per_line,
1999 p_vout->i_bytes_per_pixel, p_vout->i_bytes_per_line,
2000 p_vout->i_white_pixel, p_vout->i_black_pixel, 0,
2001 OUTLINED_TEXT, psz_text_1, 100 );
2003 if( i_width_2 < p_vout->i_width )
2005 vout_Print( p_vout->p_large_font, p_vout->p_buffer[ p_vout->i_buffer_index ].p_data +
2006 (p_vout->i_height - i_height + i_text_height) * p_vout->i_bytes_per_line,
2007 p_vout->i_bytes_per_pixel, p_vout->i_bytes_per_line,
2008 p_vout->i_white_pixel, p_vout->i_black_pixel, 0,
2009 OUTLINED_TEXT, psz_text_2, 100 );
2012 /* Activate modified area */
2013 SetBufferArea( p_vout, 0, p_vout->i_height - i_height, p_vout->i_width, i_height );
2016 /*****************************************************************************
2017 * Synchronize: update synchro level depending of heap state
2018 *****************************************************************************
2019 * This function is called during the main vout loop.
2020 *****************************************************************************/
2021 static void Synchronize( vout_thread_t *p_vout, s64 i_delay )
2023 int i_synchro_inc = 0;
2024 /* XXX?? gore following */
2025 static int i_panic_count = 0;
2026 static int i_last_synchro_inc = 0;
2027 static int i_synchro_level = VOUT_SYNCHRO_LEVEL_START;
2028 static int i_truc = 10;
2032 //fprintf( stderr, "PANIC %d\n", i_panic_count );
2038 if( p_vout->i_pictures > VOUT_SYNCHRO_HEAP_IDEAL_SIZE+1 )
2041 i_synchro_inc += p_vout->i_pictures - VOUT_SYNCHRO_HEAP_IDEAL_SIZE - 1;
2046 if( p_vout->i_pictures < VOUT_SYNCHRO_HEAP_IDEAL_SIZE )
2049 i_synchro_inc += p_vout->i_pictures - VOUT_SYNCHRO_HEAP_IDEAL_SIZE;
2053 if( i_truc > VOUT_SYNCHRO_LEVEL_MAX >> 5 ||
2054 i_synchro_inc*i_last_synchro_inc < 0 )
2059 if( i_delay < 6000 )
2064 else if( i_delay < 70000 )
2066 i_truc = 24+(24*i_delay)/70000;
2069 i_synchro_inc -= 1+(5*(70000-i_delay))/70000;
2071 else if( i_delay > 100000 )
2073 i_synchro_level += 1 << 10;
2074 if( i_delay > 130000 )
2075 i_synchro_level += 1 << 10;
2078 i_synchro_level += ( i_synchro_inc << 10 ) / i_truc;
2079 p_vout->i_synchro_level = ( i_synchro_level + (1 << 9) );
2081 if( i_synchro_level > VOUT_SYNCHRO_LEVEL_MAX )
2083 i_synchro_level = VOUT_SYNCHRO_LEVEL_MAX;
2086 //fprintf( stderr, "synchro level : %d, heap : %d (%d, %d) (%d, %f) - %Ld\n", p_vout->i_synchro_level,
2087 // p_vout->i_pictures, i_last_synchro_inc, i_synchro_inc, i_truc, r_synchro_level, i_delay );
2088 i_last_synchro_inc = i_synchro_inc;
2091 /*****************************************************************************
2092 * Manage: manage thread
2093 *****************************************************************************
2094 * This function will handle changes in thread configuration.
2095 *****************************************************************************/
2096 static int Manage( vout_thread_t *p_vout )
2099 if( p_vout->i_changes )
2101 intf_DbgMsg("changes: 0x%x (no display: 0x%x)\n", p_vout->i_changes,
2102 p_vout->i_changes & VOUT_NODISPLAY_CHANGE );
2106 /* On gamma or grayscale change, rebuild tables */
2107 if( p_vout->i_changes & (VOUT_GAMMA_CHANGE | VOUT_GRAYSCALE_CHANGE |
2110 if( vout_ResetYUV( p_vout ) )
2112 intf_ErrMsg("error: can't rebuild convertion tables\n");
2117 /* Clear changes flags which does not need management or have been
2119 p_vout->i_changes &= ~(VOUT_GAMMA_CHANGE | VOUT_GRAYSCALE_CHANGE |
2120 VOUT_YUV_CHANGE | VOUT_INFO_CHANGE |
2121 VOUT_INTF_CHANGE | VOUT_SCALE_CHANGE );
2123 /* Detect unauthorized changes */
2124 if( p_vout->i_changes )
2126 /* Some changes were not acknowledged by p_vout->p_sys_manage or this
2127 * function, it means they should not be authorized */
2128 intf_ErrMsg( "error: unauthorized changes in the video output thread\n" );
2135 /*****************************************************************************
2136 * Align: align a subpicture in the screen
2137 *****************************************************************************
2138 * This function is used for rendering text or subpictures. It returns non 0
2139 * it the final aera is not fully included in display area. Return coordinates
2141 *****************************************************************************/
2142 static int Align( vout_thread_t *p_vout, int *pi_x, int *pi_y,
2143 int i_width, int i_height, int i_h_align, int i_v_align )
2145 /* Align horizontally */
2149 *pi_x -= i_width / 2;
2152 *pi_x += (p_vout->i_width - i_width) / 2;
2158 *pi_x += p_vout->i_width - i_width;
2162 /* Align vertically */
2166 *pi_y -= i_height / 2;
2169 *pi_y += (p_vout->i_height - i_height) / 2;
2175 *pi_y += p_vout->i_height - i_height;
2177 case SUBTITLE_RALIGN:
2178 *pi_y += (p_vout->i_height + p_vout->p_buffer[ p_vout->i_buffer_index ].i_pic_y +
2179 p_vout->p_buffer[ p_vout->i_buffer_index ].i_pic_height - i_height) / 2;
2183 /* Return non 0 if clipping failed */
2184 return( (*pi_x < 0) || (*pi_y < 0) ||
2185 (*pi_x + i_width > p_vout->i_width) || (*pi_y + i_height > p_vout->i_height) );
2188 /*****************************************************************************
2189 * SetPalette: sets an 8 bpp palette
2190 *****************************************************************************
2191 * This function is just a prototype that does nothing. Architectures that
2192 * support palette allocation should override it.
2193 *****************************************************************************/
2194 static void SetPalette ( p_vout_thread_t p_vout, u16 *red,
2195 u16 *green, u16 *blue, u16 *transp )
2197 intf_ErrMsg( "SetPalette: method does not support palette changing\n" );