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 #include "vdec_idct.h"
51 #include "video_decoder.h"
53 /*****************************************************************************
55 *****************************************************************************/
56 static int BinaryLog ( u32 i );
57 static void MaskToShift ( int *pi_left, int *pi_right, u32 i_mask );
58 static int InitThread ( vout_thread_t *p_vout );
59 static void RunThread ( vout_thread_t *p_vout );
60 static void ErrorThread ( vout_thread_t *p_vout );
61 static void EndThread ( vout_thread_t *p_vout );
62 static void DestroyThread ( vout_thread_t *p_vout, int i_status );
63 static void Print ( vout_thread_t *p_vout, int i_x, int i_y,
64 int i_h_align, int i_v_align,
65 unsigned char *psz_text );
66 static void SetBufferArea ( vout_thread_t *p_vout, int i_x, int i_y,
68 static void SetBufferPicture ( vout_thread_t *p_vout, picture_t *p_pic );
69 static void RenderPicture ( vout_thread_t *p_vout, picture_t *p_pic );
70 static void RenderPictureInfo ( vout_thread_t *p_vout, picture_t *p_pic );
71 static void RenderSubPicture ( vout_thread_t *p_vout,
72 subpicture_t *p_subpic );
73 static void RenderInterface ( vout_thread_t *p_vout );
74 static int RenderIdle ( vout_thread_t *p_vout );
75 static int RenderSplash ( vout_thread_t *p_vout );
76 static void RenderInfo ( vout_thread_t *p_vout );
77 static void Synchronize ( vout_thread_t *p_vout, s64 i_delay );
78 static int Manage ( vout_thread_t *p_vout );
79 static int Align ( vout_thread_t *p_vout, int *pi_x,
80 int *pi_y, int i_width, int i_height,
81 int i_h_align, int i_v_align );
82 static void SetPalette ( p_vout_thread_t p_vout, u16 *red,
83 u16 *green, u16 *blue, u16 *transp );
85 /*****************************************************************************
86 * vout_CreateThread: creates a new video output thread
87 *****************************************************************************
88 * This function creates a new video output thread, and returns a pointer
89 * to its description. On error, it returns NULL.
90 * If pi_status is NULL, then the function will block until the thread is ready.
91 * If not, it will be updated using one of the THREAD_* constants.
92 *****************************************************************************/
93 vout_thread_t * vout_CreateThread ( char *psz_display, int i_root_window,
94 int i_width, int i_height, int *pi_status,
95 int i_method, void *p_data )
97 vout_thread_t * p_vout; /* thread descriptor */
98 typedef void ( vout_getplugin_t ) ( vout_thread_t * p_vout );
99 int i_status; /* thread status */
100 int i_index; /* index for array initialization */
101 int i_best_index = 0, i_best_score = 0;
103 /* Allocate descriptor */
105 p_vout = (vout_thread_t *) malloc( sizeof(vout_thread_t) );
108 intf_ErrMsg( "error: %s\n", strerror(ENOMEM) );
112 p_vout->p_set_palette = SetPalette;
114 /* Get a suitable video plugin */
115 for( i_index = 0 ; i_index < p_main->p_bank->i_plugin_count ; i_index++ )
117 /* If there's a plugin in p_info ... */
118 if( p_main->p_bank->p_info[ i_index ] != NULL )
120 /* ... and if this plugin provides the functions we want ... */
121 if( p_main->p_bank->p_info[ i_index ]->vout_GetPlugin != NULL )
123 /* ... and if this plugin has a good score ... */
124 if( p_main->p_bank->p_info[ i_index ]->i_score > i_best_score )
126 /* ... then take it */
127 i_best_score = p_main->p_bank->p_info[ i_index ]->i_score;
128 i_best_index = i_index;
134 if( i_best_score == 0 )
140 /* Get the plugin functions */
141 ( (vout_getplugin_t *)
142 p_main->p_bank->p_info[ i_best_index ]->vout_GetPlugin )( p_vout );
144 /* Initialize thread properties - thread id and locks will be initialized
148 p_vout->b_active = 0;
149 p_vout->pi_status = (pi_status != NULL) ? pi_status : &i_status;
150 *p_vout->pi_status = THREAD_CREATE;
152 /* Initialize some fields used by the system-dependant method - these
153 * fields will probably be modified by the method, and are only
155 p_vout->i_changes = 0;
156 p_vout->i_width = i_width;
157 p_vout->i_height = i_height;
158 p_vout->i_bytes_per_line = i_width * 2;
159 p_vout->i_screen_depth = 15;
160 p_vout->i_bytes_per_pixel = 2;
161 p_vout->f_gamma = VOUT_GAMMA;
163 p_vout->b_grayscale = main_GetIntVariable( VOUT_GRAYSCALE_VAR,
164 VOUT_GRAYSCALE_DEFAULT );
165 p_vout->vdec_DecodeMacroblock = vdec_DecodeMacroblockC;
167 p_vout->b_interface = 0;
170 intf_DbgMsg( "wished configuration: %dx%d, %d/%d bpp (%d Bpl)\n",
171 p_vout->i_width, p_vout->i_height, p_vout->i_screen_depth,
172 p_vout->i_bytes_per_pixel * 8, p_vout->i_bytes_per_line );
174 /* Initialize idle screen */
175 p_vout->last_display_date = 0;
176 p_vout->last_idle_date = 0;
177 p_vout->init_display_date = mdate();
180 /* Initialize statistics fields */
181 p_vout->render_time = 0;
182 p_vout->c_fps_samples = 0;
185 /* Initialize buffer index */
186 p_vout->i_buffer_index = 0;
188 /* Initialize pictures and subpictures - translation tables and functions
189 * will be initialized later in InitThread */
190 for( i_index = 0; i_index < VOUT_MAX_PICTURES; i_index++)
192 p_vout->p_picture[i_index].i_type = EMPTY_PICTURE;
193 p_vout->p_picture[i_index].i_status = FREE_PICTURE;
195 for( i_index = 0; i_index < VOUT_MAX_SUBPICTURES; i_index++)
197 p_vout->p_subpicture[i_index].i_type = EMPTY_SUBPICTURE;
198 p_vout->p_subpicture[i_index].i_status= FREE_SUBPICTURE;
200 p_vout->i_pictures = 0;
202 /* Initialize synchronization information */
203 p_vout->i_synchro_level = VOUT_SYNCHRO_LEVEL_START;
205 /* Create and initialize system-dependant method - this function issues its
206 * own error messages */
207 if( p_vout->p_sys_create( p_vout, psz_display, i_root_window, p_data ) )
212 intf_DbgMsg( "actual configuration: %dx%d, %d/%d bpp (%d Bpl), "
213 "masks: 0x%x/0x%x/0x%x\n",
214 p_vout->i_width, p_vout->i_height, p_vout->i_screen_depth,
215 p_vout->i_bytes_per_pixel * 8, p_vout->i_bytes_per_line,
216 p_vout->i_red_mask, p_vout->i_green_mask,
217 p_vout->i_blue_mask );
219 /* Calculate shifts from system-updated masks */
220 MaskToShift( &p_vout->i_red_lshift, &p_vout->i_red_rshift,
221 p_vout->i_red_mask );
222 MaskToShift( &p_vout->i_green_lshift, &p_vout->i_green_rshift,
223 p_vout->i_green_mask );
224 MaskToShift( &p_vout->i_blue_lshift, &p_vout->i_blue_rshift,
225 p_vout->i_blue_mask );
227 /* Set some useful colors */
228 p_vout->i_white_pixel = RGB2PIXEL( p_vout, 255, 255, 255 );
229 p_vout->i_black_pixel = RGB2PIXEL( p_vout, 0, 0, 0 );
230 p_vout->i_gray_pixel = RGB2PIXEL( p_vout, 128, 128, 128 );
231 p_vout->i_blue_pixel = RGB2PIXEL( p_vout, 0, 0, 50 );
233 /* Load fonts - fonts must be initialized after the system method since
234 * they may be dependant on screen depth and other thread properties */
235 p_vout->p_default_font = vout_LoadFont( DATA_PATH "/" VOUT_DEFAULT_FONT );
236 if( p_vout->p_default_font == NULL )
238 p_vout->p_default_font = vout_LoadFont( "share/" VOUT_DEFAULT_FONT );
240 if( p_vout->p_default_font == NULL )
242 intf_ErrMsg( "vout error: could not load default font\n" );
243 p_vout->p_sys_destroy( p_vout );
247 p_vout->p_large_font = vout_LoadFont( DATA_PATH "/" VOUT_LARGE_FONT );
248 if( p_vout->p_large_font == NULL )
250 p_vout->p_large_font = vout_LoadFont( "share/" VOUT_LARGE_FONT );
252 if( p_vout->p_large_font == NULL )
254 intf_ErrMsg( "vout error: could not load large font\n" );
255 vout_UnloadFont( p_vout->p_default_font );
256 p_vout->p_sys_destroy( p_vout );
261 /* Create thread and set locks */
262 vlc_mutex_init( &p_vout->picture_lock );
263 vlc_mutex_init( &p_vout->subpicture_lock );
264 vlc_mutex_init( &p_vout->change_lock );
265 vlc_mutex_lock( &p_vout->change_lock );
266 if( vlc_thread_create( &p_vout->thread_id, "video output",
267 (void *) RunThread, (void *) p_vout) )
269 intf_ErrMsg("error: %s\n", strerror(ENOMEM));
270 vout_UnloadFont( p_vout->p_default_font );
271 vout_UnloadFont( p_vout->p_large_font );
272 p_vout->p_sys_destroy( p_vout );
277 intf_Msg( "Video display initialized (%dx%d, %d/%d bpp)\n", p_vout->i_width,
278 p_vout->i_height, p_vout->i_screen_depth,
279 p_vout->i_bytes_per_pixel * 8 );
281 /* If status is NULL, wait until the thread is created */
282 if( pi_status == NULL )
286 msleep( THREAD_SLEEP );
287 }while( (i_status != THREAD_READY) && (i_status != THREAD_ERROR)
288 && (i_status != THREAD_FATAL) );
289 if( i_status != THREAD_READY )
297 /*****************************************************************************
298 * vout_DestroyThread: destroys a previously created thread
299 *****************************************************************************
300 * Destroy a terminated thread.
301 * The function will request a destruction of the specified thread. If pi_error
302 * is NULL, it will return once the thread is destroyed. Else, it will be
303 * update using one of the THREAD_* constants.
304 *****************************************************************************/
305 void vout_DestroyThread( vout_thread_t *p_vout, int *pi_status )
307 int i_status; /* thread status */
311 p_vout->pi_status = (pi_status != NULL) ? pi_status : &i_status;
312 *p_vout->pi_status = THREAD_DESTROY;
314 /* Request thread destruction */
317 /* If status is NULL, wait until thread has been destroyed */
318 if( pi_status == NULL )
322 msleep( THREAD_SLEEP );
323 }while( (i_status != THREAD_OVER) && (i_status != THREAD_ERROR)
324 && (i_status != THREAD_FATAL) );
328 /*****************************************************************************
329 * vout_DisplaySubPicture: display a subpicture unit
330 *****************************************************************************
331 * Remove the reservation flag of an subpicture, which will cause it to be ready
332 * for display. The picture does not need to be locked, since it is ignored by
333 * the output thread if is reserved.
334 *****************************************************************************/
335 void vout_DisplaySubPicture( vout_thread_t *p_vout, subpicture_t *p_subpic )
338 char psz_begin_date[MSTRTIME_MAX_SIZE]; /* buffer for date string */
339 char psz_end_date[MSTRTIME_MAX_SIZE]; /* buffer for date string */
343 /* Check if status is valid */
344 if( p_subpic->i_status != RESERVED_SUBPICTURE )
346 intf_DbgMsg("error: subpicture %p has invalid status %d\n", p_subpic,
347 p_subpic->i_status );
351 /* Remove reservation flag */
352 p_subpic->i_status = READY_SUBPICTURE;
355 /* Send subpicture information */
356 intf_DbgMsg("subpicture %p: type=%d, begin date=%s, end date=%s\n",
357 p_subpic, p_subpic->i_type,
358 mstrtime( psz_begin_date, p_subpic->begin_date ),
359 mstrtime( psz_end_date, p_subpic->end_date ) );
363 /*****************************************************************************
364 * vout_CreateSubPicture: allocate a subpicture in the video output heap.
365 *****************************************************************************
366 * This function create a reserved subpicture in the video output heap.
367 * A null pointer is returned if the function fails. This method provides an
368 * already allocated zone of memory in the spu data fields. It needs locking
369 * since several pictures can be created by several producers threads.
370 *****************************************************************************/
371 subpicture_t *vout_CreateSubPicture( vout_thread_t *p_vout, int i_type,
374 int i_subpic; /* subpicture index */
375 subpicture_t * p_free_subpic = NULL; /* first free subpicture */
376 subpicture_t * p_destroyed_subpic = NULL; /* first destroyed subpic */
379 vlc_mutex_lock( &p_vout->subpicture_lock );
382 * Look for an empty place
384 for( i_subpic = 0; i_subpic < VOUT_MAX_SUBPICTURES; i_subpic++ )
386 if( p_vout->p_subpicture[i_subpic].i_status == DESTROYED_SUBPICTURE )
388 /* Subpicture is marked for destruction, but is still allocated */
389 if( (p_vout->p_subpicture[i_subpic].i_type == i_type) &&
390 (p_vout->p_subpicture[i_subpic].i_size >= i_size) )
392 /* Memory size do match or is smaller : memory will not be
393 * reallocated, and function can end immediately - this is
394 * the best possible case, since no memory allocation needs
396 p_vout->p_subpicture[i_subpic].i_status = RESERVED_SUBPICTURE;
398 intf_DbgMsg("subpicture %p (in destroyed subpicture slot)\n",
399 &p_vout->p_subpicture[i_subpic] );
401 vlc_mutex_unlock( &p_vout->subpicture_lock );
402 return( &p_vout->p_subpicture[i_subpic] );
404 else if( p_destroyed_subpic == NULL )
406 /* Memory size do not match, but subpicture index will be kept in
407 * case no other place are left */
408 p_destroyed_subpic = &p_vout->p_subpicture[i_subpic];
411 else if( (p_free_subpic == NULL) &&
412 (p_vout->p_subpicture[i_subpic].i_status == FREE_SUBPICTURE ))
414 /* Subpicture is empty and ready for allocation */
415 p_free_subpic = &p_vout->p_subpicture[i_subpic];
419 /* If no free subpictures are available, use a destroyed subpicture */
420 if( (p_free_subpic == NULL) && (p_destroyed_subpic != NULL ) )
422 /* No free subpicture or matching destroyed subpictures have been
423 * found, but a destroyed subpicture is still avalaible */
424 free( p_destroyed_subpic->p_data );
425 p_free_subpic = p_destroyed_subpic;
431 if( p_free_subpic != NULL )
433 /* Allocate memory */
436 case TEXT_SUBPICTURE: /* text subpicture */
437 p_free_subpic->p_data = malloc( i_size + 1 );
439 case DVD_SUBPICTURE: /* DVD subpicture unit */
440 p_free_subpic->p_data = malloc( i_size );
444 intf_DbgMsg("error: unknown subpicture type %d\n", i_type );
445 p_free_subpic->p_data = NULL;
450 if( p_free_subpic->p_data != NULL )
452 /* Copy subpicture information, set some default values */
453 p_free_subpic->i_type = i_type;
454 p_free_subpic->i_status = RESERVED_SUBPICTURE;
455 p_free_subpic->i_size = i_size;
456 p_free_subpic->i_x = 0;
457 p_free_subpic->i_y = 0;
458 p_free_subpic->i_width = 0;
459 p_free_subpic->i_height = 0;
460 p_free_subpic->i_horizontal_align = CENTER_RALIGN;
461 p_free_subpic->i_vertical_align = CENTER_RALIGN;
465 /* Memory allocation failed : set subpicture as empty */
466 p_free_subpic->i_type = EMPTY_SUBPICTURE;
467 p_free_subpic->i_status = FREE_SUBPICTURE;
468 p_free_subpic = NULL;
469 intf_ErrMsg("spu warning: %s\n", strerror( ENOMEM ) );
473 intf_DbgMsg("subpicture %p (in free subpicture slot)\n", p_free_subpic );
475 vlc_mutex_unlock( &p_vout->subpicture_lock );
476 return( p_free_subpic );
479 /* No free or destroyed subpicture could be found */
480 intf_DbgMsg( "warning: subpicture heap is full\n" );
481 vlc_mutex_unlock( &p_vout->subpicture_lock );
485 /*****************************************************************************
486 * vout_DestroySubPicture: remove a subpicture from the heap
487 *****************************************************************************
488 * This function frees a previously reserved subpicture.
489 * It is meant to be used when the construction of a picture aborted.
490 * This function does not need locking since reserved subpictures are ignored
491 * by the output thread.
492 *****************************************************************************/
493 void vout_DestroySubPicture( vout_thread_t *p_vout, subpicture_t *p_subpic )
496 /* Check if status is valid */
497 if( p_subpic->i_status != RESERVED_SUBPICTURE )
499 intf_DbgMsg("error: subpicture %p has invalid status %d\n",
500 p_subpic, p_subpic->i_status );
504 p_subpic->i_status = DESTROYED_SUBPICTURE;
507 intf_DbgMsg("subpicture %p\n", p_subpic);
511 /*****************************************************************************
512 * vout_DisplayPicture: display a picture
513 *****************************************************************************
514 * Remove the reservation flag of a picture, which will cause it to be ready for
515 * display. The picture won't be displayed until vout_DatePicture has been
517 *****************************************************************************/
518 void vout_DisplayPicture( vout_thread_t *p_vout, picture_t *p_pic )
520 vlc_mutex_lock( &p_vout->picture_lock );
521 switch( p_pic->i_status )
523 case RESERVED_PICTURE:
524 p_pic->i_status = RESERVED_DISP_PICTURE;
526 case RESERVED_DATED_PICTURE:
527 p_pic->i_status = READY_PICTURE;
531 intf_DbgMsg("error: picture %p has invalid status %d\n", p_pic, p_pic->i_status );
537 intf_DbgMsg("picture %p\n", p_pic);
539 vlc_mutex_unlock( &p_vout->picture_lock );
542 /*****************************************************************************
543 * vout_DatePicture: date a picture
544 *****************************************************************************
545 * Remove the reservation flag of a picture, which will cause it to be ready for
546 * display. The picture won't be displayed until vout_DisplayPicture has been
548 *****************************************************************************/
549 void vout_DatePicture( vout_thread_t *p_vout, picture_t *p_pic, mtime_t date )
552 char psz_date[MSTRTIME_MAX_SIZE]; /* date */
555 vlc_mutex_lock( &p_vout->picture_lock );
557 switch( p_pic->i_status )
559 case RESERVED_PICTURE:
560 p_pic->i_status = RESERVED_DATED_PICTURE;
562 case RESERVED_DISP_PICTURE:
563 p_pic->i_status = READY_PICTURE;
567 intf_DbgMsg("error: picture %p has invalid status %d\n", p_pic, p_pic->i_status );
573 intf_DbgMsg("picture %p, display date: %s\n", p_pic, mstrtime( psz_date, p_pic->date) );
575 vlc_mutex_unlock( &p_vout->picture_lock );
578 /*****************************************************************************
579 * vout_CreatePicture: allocate a picture in the video output heap.
580 *****************************************************************************
581 * This function create a reserved image in the video output heap.
582 * A null pointer is returned if the function fails. This method provides an
583 * already allocated zone of memory in the picture data fields. It needs locking
584 * since several pictures can be created by several producers threads.
585 *****************************************************************************/
586 picture_t *vout_CreatePicture( vout_thread_t *p_vout, int i_type,
587 int i_width, int i_height )
589 int i_picture; /* picture index */
590 int i_chroma_width = 0; /* chroma width */
591 picture_t * p_free_picture = NULL; /* first free picture */
592 picture_t * p_destroyed_picture = NULL; /* first destroyed picture */
595 vlc_mutex_lock( &p_vout->picture_lock );
598 * Look for an empty place
600 for( i_picture = 0; i_picture < VOUT_MAX_PICTURES; i_picture++ )
602 if( p_vout->p_picture[i_picture].i_status == DESTROYED_PICTURE )
604 /* Picture is marked for destruction, but is still allocated - note
605 * that if width and type are the same for two pictures, chroma_width
606 * should also be the same */
607 if( (p_vout->p_picture[i_picture].i_type == i_type) &&
608 (p_vout->p_picture[i_picture].i_height == i_height) &&
609 (p_vout->p_picture[i_picture].i_width == i_width) )
611 /* Memory size do match : memory will not be reallocated, and function
612 * can end immediately - this is the best possible case, since no
613 * memory allocation needs to be done */
614 p_vout->p_picture[i_picture].i_status = RESERVED_PICTURE;
615 p_vout->i_pictures++;
617 intf_DbgMsg("picture %p (in destroyed picture slot)\n",
618 &p_vout->p_picture[i_picture] );
620 vlc_mutex_unlock( &p_vout->picture_lock );
621 return( &p_vout->p_picture[i_picture] );
623 else if( p_destroyed_picture == NULL )
625 /* Memory size do not match, but picture index will be kept in
626 * case no other place are left */
627 p_destroyed_picture = &p_vout->p_picture[i_picture];
630 else if( (p_free_picture == NULL) &&
631 (p_vout->p_picture[i_picture].i_status == FREE_PICTURE ))
633 /* Picture is empty and ready for allocation */
634 p_free_picture = &p_vout->p_picture[i_picture];
638 /* If no free picture is available, use a destroyed picture */
639 if( (p_free_picture == NULL) && (p_destroyed_picture != NULL ) )
641 /* No free picture or matching destroyed picture has been found, but
642 * a destroyed picture is still avalaible */
643 free( p_destroyed_picture->p_data );
644 p_free_picture = p_destroyed_picture;
650 if( p_free_picture != NULL )
652 /* Allocate memory */
655 case YUV_420_PICTURE: /* YUV 420: 1,1/4,1/4 samples per pixel */
656 i_chroma_width = i_width / 2;
657 p_free_picture->p_data = malloc( i_height * i_chroma_width * 3 * sizeof( yuv_data_t ) );
658 p_free_picture->p_y = (yuv_data_t *)p_free_picture->p_data;
659 p_free_picture->p_u = (yuv_data_t *)p_free_picture->p_data +i_height*i_chroma_width*4/2;
660 p_free_picture->p_v = (yuv_data_t *)p_free_picture->p_data +i_height*i_chroma_width*5/2;
662 case YUV_422_PICTURE: /* YUV 422: 1,1/2,1/2 samples per pixel */
663 i_chroma_width = i_width / 2;
664 p_free_picture->p_data = malloc( i_height * i_chroma_width * 4 * sizeof( yuv_data_t ) );
665 p_free_picture->p_y = (yuv_data_t *)p_free_picture->p_data;
666 p_free_picture->p_u = (yuv_data_t *)p_free_picture->p_data +i_height*i_chroma_width*2;
667 p_free_picture->p_v = (yuv_data_t *)p_free_picture->p_data +i_height*i_chroma_width*3;
669 case YUV_444_PICTURE: /* YUV 444: 1,1,1 samples per pixel */
670 i_chroma_width = i_width;
671 p_free_picture->p_data = malloc( i_height * i_chroma_width * 3 * sizeof( yuv_data_t ) );
672 p_free_picture->p_y = (yuv_data_t *)p_free_picture->p_data;
673 p_free_picture->p_u = (yuv_data_t *)p_free_picture->p_data +i_height*i_chroma_width;
674 p_free_picture->p_v = (yuv_data_t *)p_free_picture->p_data +i_height*i_chroma_width*2;
678 intf_DbgMsg("error: unknown picture type %d\n", i_type );
679 p_free_picture->p_data = NULL;
684 if( p_free_picture->p_data != NULL )
686 /* Copy picture information, set some default values */
687 p_free_picture->i_type = i_type;
688 p_free_picture->i_status = RESERVED_PICTURE;
689 p_free_picture->i_matrix_coefficients = 1;
690 p_free_picture->i_width = i_width;
691 p_free_picture->i_height = i_height;
692 p_free_picture->i_chroma_width = i_chroma_width;
693 p_free_picture->i_display_horizontal_offset = 0;
694 p_free_picture->i_display_vertical_offset = 0;
695 p_free_picture->i_display_width = i_width;
696 p_free_picture->i_display_height = i_height;
697 p_free_picture->i_aspect_ratio = AR_SQUARE_PICTURE;
698 p_free_picture->i_refcount = 0;
699 p_vout->i_pictures++;
703 /* Memory allocation failed : set picture as empty */
704 p_free_picture->i_type = EMPTY_PICTURE;
705 p_free_picture->i_status = FREE_PICTURE;
706 p_free_picture = NULL;
707 intf_ErrMsg("vout warning: %s\n", strerror( ENOMEM ) );
711 intf_DbgMsg("picture %p (in free picture slot)\n", p_free_picture );
713 vlc_mutex_unlock( &p_vout->picture_lock );
714 return( p_free_picture );
717 /* No free or destroyed picture could be found */
718 intf_DbgMsg( "warning: picture heap is full\n" );
719 vlc_mutex_unlock( &p_vout->picture_lock );
723 /*****************************************************************************
724 * vout_DestroyPicture: remove a permanent or reserved picture from the heap
725 *****************************************************************************
726 * This function frees a previously reserved picture or a permanent
727 * picture. It is meant to be used when the construction of a picture aborted.
728 * Note that the picture will be destroyed even if it is linked !
729 *****************************************************************************/
730 void vout_DestroyPicture( vout_thread_t *p_vout, picture_t *p_pic )
732 vlc_mutex_lock( &p_vout->picture_lock );
735 /* Check if picture status is valid */
736 if( (p_pic->i_status != RESERVED_PICTURE) &&
737 (p_pic->i_status != RESERVED_DATED_PICTURE) &&
738 (p_pic->i_status != RESERVED_DISP_PICTURE) )
740 intf_DbgMsg("error: picture %p has invalid status %d\n", p_pic, p_pic->i_status );
744 p_pic->i_status = DESTROYED_PICTURE;
745 p_vout->i_pictures--;
748 intf_DbgMsg("picture %p\n", p_pic);
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\n", 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\n");
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\n", 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\n");
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 )
920 *p_vout->pi_status = THREAD_START;
922 /* Initialize output method - this function issues its own error messages */
923 if( p_vout->p_sys_init( p_vout ) )
928 /* Initialize convertion tables and functions */
929 if( vout_InitYUV( p_vout ) )
931 intf_ErrMsg("error: can't allocate YUV translation tables\n");
935 /* Mark thread as running and return */
936 p_vout->b_active = 1;
937 *p_vout->pi_status = THREAD_READY;
940 intf_DbgMsg("thread ready\n");
944 /*****************************************************************************
945 * RunThread: video output thread
946 *****************************************************************************
947 * Video output thread. This function does only returns when the thread is
948 * terminated. It handles the pictures arriving in the video heap and the
949 * display device events.
950 *****************************************************************************/
951 static void RunThread( vout_thread_t *p_vout)
953 /* XXX?? welcome to gore land */
954 static int i_trash_count = 0;
955 static mtime_t last_display_date = 0;
957 int i_index; /* index in heap */
958 mtime_t current_date; /* current date */
959 mtime_t display_date; /* display date */
960 boolean_t b_display; /* display flag */
961 picture_t * p_pic; /* picture pointer */
962 subpicture_t * p_subpic; /* subpicture pointer */
967 p_vout->b_error = InitThread( p_vout );
968 if( p_vout->b_error )
970 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 * Find the picture to display - this operation does not need lock,
989 * since only READY_PICTUREs are handled
991 for( i_index = 0; i_index < VOUT_MAX_PICTURES; i_index++ )
993 if( (p_vout->p_picture[i_index].i_status == READY_PICTURE) &&
995 (p_vout->p_picture[i_index].date < display_date) ) )
997 p_pic = &p_vout->p_picture[i_index];
998 display_date = p_pic->date;
1005 /* Computes FPS rate */
1006 p_vout->p_fps_sample[ p_vout->c_fps_samples++ % VOUT_FPS_SAMPLES ] = display_date;
1010 //fprintf( stderr, "gap : %Ld\n", display_date-last_display_date );
1011 last_display_date = display_date;
1013 if( display_date < current_date && i_trash_count > 4 )
1015 /* Picture is late: it will be destroyed and the thread
1016 * will sleep and go to next picture */
1018 vlc_mutex_lock( &p_vout->picture_lock );
1019 if( p_pic->i_refcount )
1021 p_pic->i_status = DISPLAYED_PICTURE;
1025 p_pic->i_status = DESTROYED_PICTURE;
1026 p_vout->i_pictures--;
1028 intf_DbgMsg( "warning: late picture %p skipped refcount=%d\n", p_pic, p_pic->i_refcount );
1029 vlc_mutex_unlock( &p_vout->picture_lock );
1031 /* Update synchronization information as if display delay
1033 Synchronize( p_vout, display_date - current_date );
1041 if( display_date > current_date + VOUT_DISPLAY_DELAY )
1043 /* A picture is ready to be rendered, but its rendering date
1044 * is far from the current one so the thread will perform an
1045 * empty loop as if no picture were found. The picture state
1052 /* Picture will be displayed, update synchronization
1054 Synchronize( p_vout, display_date - current_date );
1058 * Find the subpictures to display - this operation does not need
1059 * lock, since only READY_SUBPICTURE are handled. If no picture
1060 * has been selected, display_date will depend on the subpicture.
1061 * We get an easily parsable chained list of subpictures which
1062 * ends with NULL since p_subpic was initialized to NULL.
1064 for( i_index = 0; i_index < VOUT_MAX_SUBPICTURES; i_index++ )
1066 if( p_vout->p_subpicture[i_index].i_status == READY_SUBPICTURE )
1068 p_vout->p_subpicture[i_index].p_next = p_subpic;
1069 p_subpic = &p_vout->p_subpicture[i_index];
1075 * Perform rendering, sleep and display rendered picture
1078 if( p_pic ) /* picture and perhaps subpicture */
1080 b_display = p_vout->b_active;
1081 p_vout->last_display_date = display_date;
1085 /* Set picture dimensions and clear buffer */
1086 SetBufferPicture( p_vout, p_pic );
1088 /* Render picture and information */
1089 RenderPicture( p_vout, p_pic );
1090 if( p_vout->b_info )
1092 RenderPictureInfo( p_vout, p_pic );
1093 RenderInfo( p_vout );
1097 RenderSubPicture( p_vout, p_subpic );
1101 /* Remove picture from heap */
1102 vlc_mutex_lock( &p_vout->picture_lock );
1103 if( p_pic->i_refcount )
1105 p_pic->i_status = DISPLAYED_PICTURE;
1109 p_pic->i_status = DESTROYED_PICTURE;
1110 p_vout->i_pictures--;
1112 vlc_mutex_unlock( &p_vout->picture_lock );
1114 /* Render interface and subpicture */
1115 if( b_display && p_vout->b_interface )
1117 RenderInterface( p_vout );
1121 else if( p_vout->b_active && p_vout->init_display_date == 0) /* idle or interface screen alone */
1123 if( p_vout->b_interface && 0 /* && XXX?? intf_change */ )
1125 /* Interface has changed, so a new rendering is required - force
1126 * it by setting last idle date to 0 */
1127 p_vout->last_idle_date = 0;
1130 /* Render idle screen and update idle date, then render interface if
1132 b_display = RenderIdle( p_vout );
1135 p_vout->last_idle_date = current_date;
1136 if( p_vout->b_interface )
1138 RenderInterface( p_vout );
1150 * chech for the current time and
1151 * display splash screen if everything is on time
1153 if( p_vout->init_display_date > 0)
1155 if( p_vout->b_active &&
1156 mdate()-p_vout->init_display_date < 5000000)
1158 /* there is something to display ! */
1160 RenderSplash( p_vout );
1163 /* no splash screen ! */
1164 intf_ErrMsgImm("End of splash screen\n");
1165 p_vout->init_display_date=0;
1173 * Sleep, wake up and display rendered picture
1177 /* Store render time */
1178 p_vout->render_time = mdate() - current_date;
1181 /* Give back change lock */
1182 vlc_mutex_unlock( &p_vout->change_lock );
1184 /* Sleep a while or until a given date */
1185 if( display_date != 0 )
1187 mwait( display_date );
1191 msleep( VOUT_IDLE_SLEEP );
1194 /* On awakening, take back lock and send immediately picture to display,
1195 * then swap buffers */
1196 vlc_mutex_lock( &p_vout->change_lock );
1198 intf_DbgMsg( "picture %p, subpicture %p in buffer %d, display=%d\n", p_pic, p_subpic,
1199 p_vout->i_buffer_index, b_display && !(p_vout->i_changes & VOUT_NODISPLAY_CHANGE) );
1201 if( b_display && !(p_vout->i_changes & VOUT_NODISPLAY_CHANGE) )
1203 p_vout->p_sys_display( p_vout );
1205 p_vout->i_buffer_index = ++p_vout->i_buffer_index & 1;
1210 * Check events and manage thread
1212 if( p_vout->p_sys_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\n" );
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 */
1246 while( !p_vout->b_die )
1249 msleep( VOUT_IDLE_SLEEP );
1253 /*****************************************************************************
1254 * EndThread: thread destruction
1255 *****************************************************************************
1256 * This function is called when the thread ends after a sucessful
1257 * initialization. It frees all ressources allocated by InitThread.
1258 *****************************************************************************/
1259 static void EndThread( vout_thread_t *p_vout )
1261 int i_index; /* index in heap */
1265 *p_vout->pi_status = THREAD_END;
1267 /* Destroy all remaining pictures and subpictures */
1268 for( i_index = 0; i_index < VOUT_MAX_PICTURES; i_index++ )
1270 if( p_vout->p_picture[i_index].i_status != FREE_PICTURE )
1272 free( p_vout->p_picture[i_index].p_data );
1275 for( i_index = 0; i_index < VOUT_MAX_SUBPICTURES; i_index++ )
1277 if( p_vout->p_subpicture[i_index].i_status != FREE_SUBPICTURE )
1279 free( p_vout->p_subpicture[i_index].p_data );
1283 /* Destroy translation tables */
1284 vout_EndYUV( p_vout );
1285 p_vout->p_sys_end( p_vout );
1288 /*****************************************************************************
1289 * DestroyThread: thread destruction
1290 *****************************************************************************
1291 * This function is called when the thread ends. It frees all ressources
1292 * allocated by CreateThread. Status is available at this stage.
1293 *****************************************************************************/
1294 static void DestroyThread( vout_thread_t *p_vout, int i_status )
1296 int *pi_status; /* status adress */
1298 /* Store status adress */
1300 pi_status = p_vout->pi_status;
1302 /* Destroy thread structures allocated by Create and InitThread */
1303 vout_UnloadFont( p_vout->p_default_font );
1304 vout_UnloadFont( p_vout->p_large_font );
1305 p_vout->p_sys_destroy( p_vout );
1307 /* Free structure */
1309 *pi_status = i_status;
1312 /*****************************************************************************
1313 * Print: print simple text on a picture
1314 *****************************************************************************
1315 * This function will print a simple text on the picture. It is designed to
1316 * print debugging or general information.
1317 *****************************************************************************/
1318 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 )
1320 int i_text_height; /* total text height */
1321 int i_text_width; /* total text width */
1323 /* Update upper left coordinates according to alignment */
1324 vout_TextSize( p_vout->p_default_font, 0, psz_text, &i_text_width, &i_text_height );
1325 if( !Align( p_vout, &i_x, &i_y, i_text_width, i_text_height, i_h_align, i_v_align ) )
1327 /* Set area and print text */
1328 SetBufferArea( p_vout, i_x, i_y, i_text_width, i_text_height );
1329 vout_Print( p_vout->p_default_font, p_vout->p_buffer[ p_vout->i_buffer_index ].p_data +
1330 i_y * p_vout->i_bytes_per_line + i_x * p_vout->i_bytes_per_pixel,
1331 p_vout->i_bytes_per_pixel, p_vout->i_bytes_per_line,
1332 p_vout->i_white_pixel, 0, 0,
1337 /*****************************************************************************
1338 * SetBufferArea: activate an area in current buffer
1339 *****************************************************************************
1340 * This function is called when something is rendered on the current buffer.
1341 * It set the area as active and prepare it to be cleared on next rendering.
1342 * Pay attention to the fact that in this functions, i_h is in fact the end y
1343 * coordinate of the new area.
1344 *****************************************************************************/
1345 static void SetBufferArea( vout_thread_t *p_vout, int i_x, int i_y, int i_w, int i_h )
1347 vout_buffer_t * p_buffer; /* current buffer */
1348 int i_area_begin, i_area_end; /* area vertical extension */
1349 int i_area, i_area_copy; /* area index */
1350 int i_area_shift; /* shift distance for areas */
1352 /* Choose buffer and modify h to end of area position */
1353 p_buffer = &p_vout->p_buffer[ p_vout->i_buffer_index ];
1357 * Remove part of the area which is inside the picture - this is done
1358 * by calling again SetBufferArea with the correct areas dimensions.
1360 if( (i_x >= p_buffer->i_pic_x) && (i_x + i_w <= p_buffer->i_pic_x + p_buffer->i_pic_width) )
1362 i_area_begin = p_buffer->i_pic_y;
1363 i_area_end = i_area_begin + p_buffer->i_pic_height - 1;
1365 if( ((i_y >= i_area_begin) && (i_y <= i_area_end)) ||
1366 ((i_h >= i_area_begin) && (i_h <= i_area_end)) ||
1367 ((i_y < i_area_begin) && (i_h > i_area_end)) )
1369 /* Keep the stripe above the picture, if any */
1370 if( i_y < i_area_begin )
1372 SetBufferArea( p_vout, i_x, i_y, i_w, i_area_begin - i_y );
1374 /* Keep the stripe below the picture, if any */
1375 if( i_h > i_area_end )
1377 SetBufferArea( p_vout, i_x, i_area_end, i_w, i_h - i_area_end );
1383 /* Skip some extensions until interesting areas */
1385 (i_area < p_buffer->i_areas) &&
1386 (p_buffer->pi_area_end[i_area] + 1 <= i_y);
1392 if( i_area == p_buffer->i_areas )
1394 /* New area is below all existing ones: just add it at the end of the
1395 * array, if possible - otherwise, append it to the last one */
1396 if( i_area < VOUT_MAX_AREAS )
1398 p_buffer->pi_area_begin[i_area] = i_y;
1399 p_buffer->pi_area_end[i_area] = i_h;
1400 p_buffer->i_areas++;
1405 intf_DbgMsg("area overflow\n");
1407 p_buffer->pi_area_end[VOUT_MAX_AREAS - 1] = i_h;
1412 i_area_begin = p_buffer->pi_area_begin[i_area];
1413 i_area_end = p_buffer->pi_area_end[i_area];
1415 if( i_y < i_area_begin )
1417 if( i_h >= i_area_begin - 1 )
1419 /* Extend area above */
1420 p_buffer->pi_area_begin[i_area] = i_y;
1424 /* Create a new area above : merge last area if overflow, then
1425 * move all old areas down */
1426 if( p_buffer->i_areas == VOUT_MAX_AREAS )
1429 intf_DbgMsg("areas overflow\n");
1431 p_buffer->pi_area_end[VOUT_MAX_AREAS - 2] = p_buffer->pi_area_end[VOUT_MAX_AREAS - 1];
1435 p_buffer->i_areas++;
1437 for( i_area_copy = p_buffer->i_areas - 1; i_area_copy > i_area; i_area_copy-- )
1439 p_buffer->pi_area_begin[i_area_copy] = p_buffer->pi_area_begin[i_area_copy - 1];
1440 p_buffer->pi_area_end[i_area_copy] = p_buffer->pi_area_end[i_area_copy - 1];
1442 p_buffer->pi_area_begin[i_area] = i_y;
1443 p_buffer->pi_area_end[i_area] = i_h;
1447 if( i_h > i_area_end )
1449 /* Find further areas which can be merged with the new one */
1450 for( i_area_copy = i_area + 1;
1451 (i_area_copy < p_buffer->i_areas) &&
1452 (p_buffer->pi_area_begin[i_area] <= i_h);
1459 if( i_area_copy != i_area )
1461 /* Merge with last possible areas */
1462 p_buffer->pi_area_end[i_area] = MAX( i_h, p_buffer->pi_area_end[i_area_copy] );
1464 /* Shift lower areas upward */
1465 i_area_shift = i_area_copy - i_area;
1466 p_buffer->i_areas -= i_area_shift;
1467 for( i_area_copy = i_area + 1; i_area_copy < p_buffer->i_areas; i_area_copy++ )
1469 p_buffer->pi_area_begin[i_area_copy] = p_buffer->pi_area_begin[i_area_copy + i_area_shift];
1470 p_buffer->pi_area_end[i_area_copy] = p_buffer->pi_area_end[i_area_copy + i_area_shift];
1475 /* Extend area below */
1476 p_buffer->pi_area_end[i_area] = i_h;
1482 /*****************************************************************************
1483 * SetBufferPicture: clear buffer and set picture area
1484 *****************************************************************************
1485 * This function is called before any rendering. It clears the current
1486 * rendering buffer and set the new picture area. If the picture pointer is
1487 * NULL, then no picture area is defined. Floating operations are avoided since
1488 * some MMX calculations may follow.
1489 *****************************************************************************/
1490 static void SetBufferPicture( vout_thread_t *p_vout, picture_t *p_pic )
1492 vout_buffer_t * p_buffer; /* current buffer */
1493 int i_pic_x, i_pic_y; /* picture position */
1494 int i_pic_width, i_pic_height; /* picture dimensions */
1495 int i_old_pic_y, i_old_pic_height; /* old picture area */
1496 int i_vout_width, i_vout_height; /* display dimensions */
1497 int i_area; /* area index */
1498 int i_data_index; /* area data index */
1499 int i_data_size; /* area data size, in 256 bytes blocs */
1500 u64 * p_data; /* area data, for clearing */
1501 byte_t * p_data8; /* area data, for clearing (slow) */
1503 /* Choose buffer and set display dimensions */
1504 p_buffer = &p_vout->p_buffer[ p_vout->i_buffer_index ];
1505 i_vout_width = p_vout->i_width;
1506 i_vout_height = p_vout->i_height;
1509 * Computes new picture size
1513 /* Try horizontal scaling first - width must be a mutiple of 16 */
1514 i_pic_width = (( p_vout->b_scale || (p_pic->i_width > i_vout_width)) ?
1515 i_vout_width : p_pic->i_width) & ~0xf;
1516 switch( p_pic->i_aspect_ratio )
1518 case AR_3_4_PICTURE:
1519 i_pic_height = i_pic_width * 3 / 4;
1521 case AR_16_9_PICTURE:
1522 i_pic_height = i_pic_width * 9 / 16;
1524 case AR_221_1_PICTURE:
1525 i_pic_height = i_pic_width * 100 / 221;
1527 case AR_SQUARE_PICTURE:
1529 i_pic_height = p_pic->i_height * i_pic_width / p_pic->i_width;
1533 /* If picture dimensions using horizontal scaling are too large, use
1534 * vertical scaling. Since width must be a multiple of 16, height is
1535 * adjusted again after. */
1536 if( i_pic_height > i_vout_height )
1538 i_pic_height = ( p_vout->b_scale || (p_pic->i_height > i_vout_height)) ?
1539 i_vout_height : p_pic->i_height;
1540 switch( p_pic->i_aspect_ratio )
1542 case AR_3_4_PICTURE:
1543 i_pic_width = (i_pic_height * 4 / 3) & ~0xf;
1544 i_pic_height = i_pic_width * 3 / 4;
1546 case AR_16_9_PICTURE:
1547 i_pic_width = (i_pic_height * 16 / 9) & ~0xf;
1548 i_pic_height = i_pic_width * 9 / 16;
1550 case AR_221_1_PICTURE:
1551 i_pic_width = (i_pic_height * 221 / 100) & ~0xf;
1552 i_pic_height = i_pic_width * 100 / 221;
1554 case AR_SQUARE_PICTURE:
1556 i_pic_width = (p_pic->i_width * i_pic_height / p_pic->i_height) & ~0xf;
1557 i_pic_height = p_pic->i_height * i_pic_width / p_pic->i_width;
1562 /* Set picture position */
1563 i_pic_x = (p_vout->i_width - i_pic_width) / 2;
1564 i_pic_y = (p_vout->i_height - i_pic_height) / 2;
1568 /* No picture: size is 0 */
1576 * Set new picture size - if it is smaller than the previous one, clear
1577 * around it. Since picture are centered, only their size is tested.
1579 if( (p_buffer->i_pic_width > i_pic_width) || (p_buffer->i_pic_height > i_pic_height) )
1581 i_old_pic_y = p_buffer->i_pic_y;
1582 i_old_pic_height = p_buffer->i_pic_height;
1583 p_buffer->i_pic_x = i_pic_x;
1584 p_buffer->i_pic_y = i_pic_y;
1585 p_buffer->i_pic_width = i_pic_width;
1586 p_buffer->i_pic_height = i_pic_height;
1587 SetBufferArea( p_vout, 0, i_old_pic_y, p_vout->i_width, i_old_pic_height );
1591 p_buffer->i_pic_x = i_pic_x;
1592 p_buffer->i_pic_y = i_pic_y;
1593 p_buffer->i_pic_width = i_pic_width;
1594 p_buffer->i_pic_height = i_pic_height;
1600 for( i_area = 0; i_area < p_buffer->i_areas; i_area++ )
1603 intf_DbgMsg("clearing picture %p area in buffer %d: %d-%d\n", p_pic,
1604 p_vout->i_buffer_index, p_buffer->pi_area_begin[i_area], p_buffer->pi_area_end[i_area] );
1606 i_data_size = (p_buffer->pi_area_end[i_area] - p_buffer->pi_area_begin[i_area] + 1) * p_vout->i_bytes_per_line;
1607 p_data = (u64*) (p_buffer->p_data + p_vout->i_bytes_per_line * p_buffer->pi_area_begin[i_area]);
1608 for( i_data_index = i_data_size / 256; i_data_index-- ; )
1610 /* Clear 256 bytes block */
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;
1615 *p_data++ = 0; *p_data++ = 0; *p_data++ = 0; *p_data++ = 0;
1616 *p_data++ = 0; *p_data++ = 0; *p_data++ = 0; *p_data++ = 0;
1617 *p_data++ = 0; *p_data++ = 0; *p_data++ = 0; *p_data++ = 0;
1618 *p_data++ = 0; *p_data++ = 0; *p_data++ = 0; *p_data++ = 0;
1620 for( i_data_index = (i_data_size % 256) / 16; i_data_index--; )
1622 /* Clear remaining 16 bytes blocks */
1623 *p_data++ = 0; *p_data++ = 0;
1625 p_data8 = (byte_t *)p_data;
1626 for( i_data_index = i_data_size % 16; i_data_index--; )
1628 /* Clear remaining bytes */
1636 p_buffer->i_areas = 0;
1639 /*****************************************************************************
1640 * RenderPicture: render a picture
1641 *****************************************************************************
1642 * This function converts a picture from a video heap to a pixel-encoded image
1643 * and copies it to the current rendering buffer. No lock is required, since
1644 * the * rendered picture has been determined as existant, and will only be
1645 * destroyed by the vout thread later.
1646 *****************************************************************************/
1647 static void RenderPicture( vout_thread_t *p_vout, picture_t *p_pic )
1650 char psz_date[MSTRTIME_MAX_SIZE]; /* picture date */
1651 mtime_t render_time; /* picture rendering time */
1653 vout_buffer_t * p_buffer; /* rendering buffer */
1654 byte_t * p_pic_data; /* convertion destination */
1656 /* Get and set rendering information */
1657 p_buffer = &p_vout->p_buffer[ p_vout->i_buffer_index ];
1658 p_pic_data = p_buffer->p_data +
1659 p_buffer->i_pic_x * p_vout->i_bytes_per_pixel +
1660 p_buffer->i_pic_y * p_vout->i_bytes_per_line;
1662 render_time = mdate();
1666 * Choose appropriate rendering function and render picture
1668 switch( p_pic->i_type )
1670 case YUV_420_PICTURE:
1671 p_vout->yuv.p_Convert420( p_vout, p_pic_data,
1672 p_pic->p_y, p_pic->p_u, p_pic->p_v,
1673 p_pic->i_width, p_pic->i_height,
1674 p_buffer->i_pic_width, p_buffer->i_pic_height,
1675 p_vout->i_bytes_per_line / p_vout->i_bytes_per_pixel,
1676 p_pic->i_matrix_coefficients );
1678 case YUV_422_PICTURE:
1679 p_vout->yuv.p_Convert422( p_vout, p_pic_data,
1680 p_pic->p_y, p_pic->p_u, p_pic->p_v,
1681 p_pic->i_width, p_pic->i_height,
1682 p_buffer->i_pic_width, p_buffer->i_pic_height,
1683 p_vout->i_bytes_per_line / p_vout->i_bytes_per_pixel,
1684 p_pic->i_matrix_coefficients );
1686 case YUV_444_PICTURE:
1687 p_vout->yuv.p_Convert444( p_vout, p_pic_data,
1688 p_pic->p_y, p_pic->p_u, p_pic->p_v,
1689 p_pic->i_width, p_pic->i_height,
1690 p_buffer->i_pic_width, p_buffer->i_pic_height,
1691 p_vout->i_bytes_per_line / p_vout->i_bytes_per_pixel,
1692 p_pic->i_matrix_coefficients );
1696 intf_DbgMsg("error: unknown picture type %d\n", p_pic->i_type );
1702 /* Print picture date and rendering time */
1703 intf_DbgMsg("picture %p rendered in buffer %d (%ld us), display date: %s\n", p_pic,
1704 p_vout->i_buffer_index, (long) (mdate() - render_time),
1705 mstrtime( psz_date, p_pic->date ));
1709 /*****************************************************************************
1710 * RenderPictureInfo: print additionnal information on a picture
1711 *****************************************************************************
1712 * This function will print information such as fps and other picture
1713 * dependant information.
1714 *****************************************************************************/
1715 static void RenderPictureInfo( vout_thread_t *p_vout, picture_t *p_pic )
1717 #if defined(STATS) || defined(DEBUG)
1718 char psz_buffer[256]; /* string buffer */
1723 * Print FPS rate in upper right corner
1725 if( p_vout->c_fps_samples > VOUT_FPS_SAMPLES )
1727 long i_fps = VOUT_FPS_SAMPLES * 1000000 * 10 /
1728 ( p_vout->p_fps_sample[ (p_vout->c_fps_samples - 1)
1729 % VOUT_FPS_SAMPLES ] -
1730 p_vout->p_fps_sample[ p_vout->c_fps_samples
1731 % VOUT_FPS_SAMPLES ] );
1732 sprintf( psz_buffer, "%li.%i fps", i_fps / 10, (int)i_fps % 10 );
1733 Print( p_vout, 0, 0, RIGHT_RALIGN, TOP_RALIGN, psz_buffer );
1737 * Print frames count and loop time in upper left corner
1739 sprintf( psz_buffer, "%ld frames, render: %ldus",
1740 (long) p_vout->c_fps_samples, (long) p_vout->render_time );
1741 Print( p_vout, 0, 0, LEFT_RALIGN, TOP_RALIGN, psz_buffer );
1746 * Print picture information in lower right corner
1748 sprintf( psz_buffer, "%s picture %dx%d (%dx%d%+d%+d %s) -> %dx%d+%d+%d",
1749 (p_pic->i_type == YUV_420_PICTURE) ? "4:2:0" :
1750 ((p_pic->i_type == YUV_422_PICTURE) ? "4:2:2" :
1751 ((p_pic->i_type == YUV_444_PICTURE) ? "4:4:4" : "ukn-type")),
1752 p_pic->i_width, p_pic->i_height,
1753 p_pic->i_display_width, p_pic->i_display_height,
1754 p_pic->i_display_horizontal_offset, p_pic->i_display_vertical_offset,
1755 (p_pic->i_aspect_ratio == AR_SQUARE_PICTURE) ? "sq" :
1756 ((p_pic->i_aspect_ratio == AR_3_4_PICTURE) ? "4:3" :
1757 ((p_pic->i_aspect_ratio == AR_16_9_PICTURE) ? "16:9" :
1758 ((p_pic->i_aspect_ratio == AR_221_1_PICTURE) ? "2.21:1" : "ukn-ar" ))),
1759 p_vout->p_buffer[ p_vout->i_buffer_index ].i_pic_width,
1760 p_vout->p_buffer[ p_vout->i_buffer_index ].i_pic_height,
1761 p_vout->p_buffer[ p_vout->i_buffer_index ].i_pic_x,
1762 p_vout->p_buffer[ p_vout->i_buffer_index ].i_pic_y );
1763 Print( p_vout, 0, 0, RIGHT_RALIGN, BOTTOM_RALIGN, psz_buffer );
1767 /*****************************************************************************
1768 * RenderSplash: render splash picture
1769 *****************************************************************************
1770 * This function will print something on the screen. It will return 0 if
1771 * nothing has been rendered, or 1 if something has been changed on the screen.
1772 * Note that if you absolutely want something to be printed, you will have
1773 * to force it by setting the last idle date to 0.
1774 * Unlike other rendering functions, this one calls the SetBufferPicture
1775 * function when needed.
1776 *****************************************************************************/
1777 int RenderSplash( vout_thread_t *p_vout )
1779 int i_x = 0, i_y = 0; /* text position */
1780 int i_width, i_height; /* text size */
1781 char *psz_text = "VideoLAN Client (" VERSION ")"; /* text to display */
1783 memset( p_vout->p_buffer[ p_vout->i_buffer_index ].p_data,
1784 p_vout->i_bytes_per_line * p_vout->i_height, 12);
1786 // SetBufferPicture( p_vout, NULL );
1787 vout_TextSize( p_vout->p_large_font, WIDE_TEXT | OUTLINED_TEXT, psz_text,
1788 &i_width, &i_height );
1789 if( !Align( p_vout, &i_x, &i_y, i_width, i_height, CENTER_RALIGN, CENTER_RALIGN ) )
1791 vout_Print( p_vout->p_large_font,
1792 p_vout->p_buffer[ p_vout->i_buffer_index ].p_data +
1793 i_x * p_vout->i_bytes_per_pixel + (i_y - 16 ) * p_vout->i_bytes_per_line,
1794 p_vout->i_bytes_per_pixel, p_vout->i_bytes_per_line,
1795 p_vout->i_white_pixel, p_vout->i_gray_pixel, 0,
1796 WIDE_TEXT | OUTLINED_TEXT, psz_text, 100);
1797 SetBufferArea( p_vout, i_x, i_y, i_width, i_height);
1803 /*****************************************************************************
1804 * RenderIdle: render idle picture
1805 *****************************************************************************
1806 * This function will print something on the screen. It will return 0 if
1807 * nothing has been rendered, or 1 if something has been changed on the screen.
1808 * Note that if you absolutely want something to be printed, you will have
1809 * to force it by setting the last idle date to 0.
1810 * Unlike other rendering functions, this one calls the SetBufferPicture
1811 * function when needed.
1812 *****************************************************************************/
1813 int RenderIdle( vout_thread_t *p_vout )
1815 int i_x = 0, i_y = 0; /* text position */
1816 int i_width, i_height; /* text size */
1817 mtime_t current_date; /* current date */
1818 int i_amount = 0; /* amount to draw */
1819 char *psz_text = "Waiting for stream"; /* text to display */
1820 char *psz_wtext = "[................]";
1823 memset( p_vout->p_buffer[ p_vout->i_buffer_index ].p_data,
1824 p_vout->i_bytes_per_line * p_vout->i_height, 12);
1827 current_date = mdate();
1828 if( (current_date - p_vout->last_display_date) > VOUT_IDLE_DELAY
1829 // && (current_date - p_vout->last_idle_date) > VOUT_IDLE_DELAY
1832 SetBufferPicture( p_vout, NULL );
1833 vout_TextSize( p_vout->p_large_font, WIDE_TEXT | OUTLINED_TEXT, psz_text,
1834 &i_width, &i_height );
1835 if( !Align( p_vout, &i_x, &i_y, i_width, i_height * 2, CENTER_RALIGN, CENTER_RALIGN ) )
1837 i_amount = (int) ((current_date - p_vout->last_display_date ) / 5000LL);
1838 vout_Print( p_vout->p_large_font,
1839 p_vout->p_buffer[ p_vout->i_buffer_index ].p_data +
1840 i_x * p_vout->i_bytes_per_pixel + i_y * p_vout->i_bytes_per_line,
1841 p_vout->i_bytes_per_pixel, p_vout->i_bytes_per_line,
1842 p_vout->i_white_pixel, p_vout->i_gray_pixel, 0,
1843 WIDE_TEXT | OUTLINED_TEXT, psz_text, (i_amount / 3 ) %110);
1845 vout_Print( p_vout->p_large_font,
1846 p_vout->p_buffer[ p_vout->i_buffer_index ].p_data +
1847 i_x * p_vout->i_bytes_per_pixel + (i_y + 16) * p_vout->i_bytes_per_line,
1848 p_vout->i_bytes_per_pixel, p_vout->i_bytes_per_line,
1849 p_vout->i_white_pixel, p_vout->i_gray_pixel, 0,
1850 WIDE_TEXT | OUTLINED_TEXT, psz_wtext, (i_amount/5)%110 );
1853 SetBufferArea( p_vout, i_x, i_y, i_width, i_height * 2 );
1860 /*****************************************************************************
1861 * RenderInfo: render additionnal information
1862 *****************************************************************************
1863 * This function renders information which do not depend on the current
1865 *****************************************************************************/
1866 static void RenderInfo( vout_thread_t *p_vout )
1869 char psz_buffer[256]; /* string buffer */
1870 int i_ready_pic = 0; /* ready pictures */
1871 int i_reserved_pic = 0; /* reserved pictures */
1872 int i_picture; /* picture index */
1877 * Print thread state in lower left corner
1879 for( i_picture = 0; i_picture < VOUT_MAX_PICTURES; i_picture++ )
1881 switch( p_vout->p_picture[i_picture].i_status )
1883 case RESERVED_PICTURE:
1884 case RESERVED_DATED_PICTURE:
1885 case RESERVED_DISP_PICTURE:
1893 sprintf( psz_buffer, "pic: %d (%d/%d)/%d",
1894 p_vout->i_pictures, i_reserved_pic, i_ready_pic, VOUT_MAX_PICTURES );
1895 Print( p_vout, 0, 0, LEFT_RALIGN, BOTTOM_RALIGN, psz_buffer );
1899 /*****************************************************************************
1900 * RenderSubPicture: render a subpicture
1901 *****************************************************************************
1902 * This function renders a sub picture unit.
1903 *****************************************************************************/
1904 static void RenderSubPicture( vout_thread_t *p_vout, subpicture_t *p_subpic )
1906 p_vout_font_t p_font; /* text font */
1907 int i_width, i_height; /* subpicture dimensions */
1909 while( p_subpic != NULL )
1911 switch( p_subpic->i_type )
1913 case DVD_SUBPICTURE: /* DVD subpicture unit */
1914 /* test if the picture really has to be displayed */
1915 if( mdate() < p_subpic->begin_date )
1917 /* not yet, see you later */
1920 if( mdate() > p_subpic->end_date )
1922 /* too late, destroying the subpic */
1923 vout_DestroySubPicture( p_vout, p_subpic );
1926 vout_RenderSPU( &p_vout->p_buffer[ p_vout->i_buffer_index ],
1927 p_subpic, p_vout->i_bytes_per_pixel,
1928 p_vout->i_bytes_per_line );
1930 case TEXT_SUBPICTURE: /* single line text */
1931 /* Select default font if not specified */
1932 p_font = p_subpic->type.text.p_font;
1933 if( p_font == NULL )
1935 p_font = p_vout->p_default_font;
1938 /* Compute text size (width and height fields are ignored)
1940 vout_TextSize( p_font, p_subpic->type.text.i_style,
1941 p_subpic->p_data, &i_width, &i_height );
1942 if( !Align( p_vout, &p_subpic->i_x, &p_subpic->i_y,
1943 i_width, i_height, p_subpic->i_horizontal_align,
1944 p_subpic->i_vertical_align ) )
1947 p_vout->p_buffer[ p_vout->i_buffer_index ].p_data +
1948 p_subpic->i_x * p_vout->i_bytes_per_pixel +
1949 p_subpic->i_y * p_vout->i_bytes_per_line,
1950 p_vout->i_bytes_per_pixel, p_vout->i_bytes_per_line,
1951 p_subpic->type.text.i_char_color,
1952 p_subpic->type.text.i_border_color,
1953 p_subpic->type.text.i_bg_color,
1954 p_subpic->type.text.i_style, p_subpic->p_data, 100 );
1955 SetBufferArea( p_vout, p_subpic->i_x, p_subpic->i_y,
1956 i_width, i_height );
1962 intf_DbgMsg( "error: unknown subpicture %p type %d\n",
1963 p_subpic, p_subpic->i_type );
1967 p_subpic = p_subpic->p_next;
1971 /*****************************************************************************
1972 * RenderInterface: render the interface
1973 *****************************************************************************
1974 * This function renders the interface, if any.
1975 *****************************************************************************/
1976 static void RenderInterface( vout_thread_t *p_vout )
1978 int i_height, i_text_height; /* total and text height */
1979 int i_width_1, i_width_2; /* text width */
1980 int i_byte; /* byte index */
1981 const char *psz_text_1 = "[1-9] Channel [i]nfo [c]olor [g/G]amma";
1982 const char *psz_text_2 = "[+/-] Volume [m]ute [s]caling [Q]uit";
1985 vout_TextSize( p_vout->p_large_font, OUTLINED_TEXT, psz_text_1, &i_width_1, &i_height );
1986 vout_TextSize( p_vout->p_large_font, OUTLINED_TEXT, psz_text_2, &i_width_2, &i_text_height );
1987 i_height += i_text_height;
1989 /* Render background */
1990 for( i_byte = (p_vout->i_height - i_height) * p_vout->i_bytes_per_line;
1991 i_byte < p_vout->i_height * p_vout->i_bytes_per_line;
1995 p_vout->p_buffer[ p_vout->i_buffer_index ].p_data[ i_byte ] = p_vout->i_blue_pixel;
1998 /* Render text, if not larger than screen */
1999 if( i_width_1 < p_vout->i_width )
2001 vout_Print( p_vout->p_large_font, p_vout->p_buffer[ p_vout->i_buffer_index ].p_data +
2002 (p_vout->i_height - i_height) * p_vout->i_bytes_per_line,
2003 p_vout->i_bytes_per_pixel, p_vout->i_bytes_per_line,
2004 p_vout->i_white_pixel, p_vout->i_black_pixel, 0,
2005 OUTLINED_TEXT, psz_text_1, 100 );
2007 if( i_width_2 < p_vout->i_width )
2009 vout_Print( p_vout->p_large_font, p_vout->p_buffer[ p_vout->i_buffer_index ].p_data +
2010 (p_vout->i_height - i_height + i_text_height) * p_vout->i_bytes_per_line,
2011 p_vout->i_bytes_per_pixel, p_vout->i_bytes_per_line,
2012 p_vout->i_white_pixel, p_vout->i_black_pixel, 0,
2013 OUTLINED_TEXT, psz_text_2, 100 );
2016 /* Activate modified area */
2017 SetBufferArea( p_vout, 0, p_vout->i_height - i_height, p_vout->i_width, i_height );
2020 /*****************************************************************************
2021 * Synchronize: update synchro level depending of heap state
2022 *****************************************************************************
2023 * This function is called during the main vout loop.
2024 *****************************************************************************/
2025 static void Synchronize( vout_thread_t *p_vout, s64 i_delay )
2027 int i_synchro_inc = 0;
2028 /* XXX?? gore following */
2029 static int i_panic_count = 0;
2030 static int i_last_synchro_inc = 0;
2031 static int i_synchro_level = VOUT_SYNCHRO_LEVEL_START;
2032 static int i_truc = 10;
2036 //fprintf( stderr, "PANIC %d\n", i_panic_count );
2042 if( p_vout->i_pictures > VOUT_SYNCHRO_HEAP_IDEAL_SIZE+1 )
2045 i_synchro_inc += p_vout->i_pictures - VOUT_SYNCHRO_HEAP_IDEAL_SIZE - 1;
2050 if( p_vout->i_pictures < VOUT_SYNCHRO_HEAP_IDEAL_SIZE )
2053 i_synchro_inc += p_vout->i_pictures - VOUT_SYNCHRO_HEAP_IDEAL_SIZE;
2057 if( i_truc > VOUT_SYNCHRO_LEVEL_MAX >> 5 ||
2058 i_synchro_inc*i_last_synchro_inc < 0 )
2063 if( i_delay < 6000 )
2068 else if( i_delay < 70000 )
2070 i_truc = 24+(24*i_delay)/70000;
2073 i_synchro_inc -= 1+(5*(70000-i_delay))/70000;
2075 else if( i_delay > 100000 )
2077 i_synchro_level += 1 << 10;
2078 if( i_delay > 130000 )
2079 i_synchro_level += 1 << 10;
2082 i_synchro_level += ( i_synchro_inc << 10 ) / i_truc;
2083 p_vout->i_synchro_level = ( i_synchro_level + (1 << 9) );
2085 if( i_synchro_level > VOUT_SYNCHRO_LEVEL_MAX )
2087 i_synchro_level = VOUT_SYNCHRO_LEVEL_MAX;
2090 //fprintf( stderr, "synchro level : %d, heap : %d (%d, %d) (%d, %f) - %Ld\n", p_vout->i_synchro_level,
2091 // p_vout->i_pictures, i_last_synchro_inc, i_synchro_inc, i_truc, r_synchro_level, i_delay );
2092 i_last_synchro_inc = i_synchro_inc;
2095 /*****************************************************************************
2096 * Manage: manage thread
2097 *****************************************************************************
2098 * This function will handle changes in thread configuration.
2099 *****************************************************************************/
2100 static int Manage( vout_thread_t *p_vout )
2103 if( p_vout->i_changes )
2105 intf_DbgMsg("changes: 0x%x (no display: 0x%x)\n", p_vout->i_changes,
2106 p_vout->i_changes & VOUT_NODISPLAY_CHANGE );
2110 /* On gamma or grayscale change, rebuild tables */
2111 if( p_vout->i_changes & (VOUT_GAMMA_CHANGE | VOUT_GRAYSCALE_CHANGE |
2114 /* Change vdec_DecodeMacroblock when switching between BW and C */
2115 if( !p_vout->b_grayscale )
2117 p_vout->vdec_DecodeMacroblock = vdec_DecodeMacroblockC;
2119 else if( p_vout->b_grayscale)
2121 p_vout->vdec_DecodeMacroblock = vdec_DecodeMacroblockBW;
2123 if( vout_ResetYUV( p_vout ) )
2125 intf_ErrMsg("error: can't rebuild convertion tables\n");
2130 /* Clear changes flags which does not need management or have been
2132 p_vout->i_changes &= ~(VOUT_GAMMA_CHANGE | VOUT_GRAYSCALE_CHANGE |
2133 VOUT_YUV_CHANGE | VOUT_INFO_CHANGE |
2134 VOUT_INTF_CHANGE | VOUT_SCALE_CHANGE );
2136 /* Detect unauthorized changes */
2137 if( p_vout->i_changes )
2139 /* Some changes were not acknowledged by p_vout->p_sys_manage or this
2140 * function, it means they should not be authorized */
2141 intf_ErrMsg( "error: unauthorized changes in the video output thread\n" );
2148 /*****************************************************************************
2149 * Align: align a subpicture in the screen
2150 *****************************************************************************
2151 * This function is used for rendering text or subpictures. It returns non 0
2152 * it the final aera is not fully included in display area. Return coordinates
2154 *****************************************************************************/
2155 static int Align( vout_thread_t *p_vout, int *pi_x, int *pi_y,
2156 int i_width, int i_height, int i_h_align, int i_v_align )
2158 /* Align horizontally */
2162 *pi_x -= i_width / 2;
2165 *pi_x += (p_vout->i_width - i_width) / 2;
2171 *pi_x += p_vout->i_width - i_width;
2175 /* Align vertically */
2179 *pi_y -= i_height / 2;
2182 *pi_y += (p_vout->i_height - i_height) / 2;
2188 *pi_y += p_vout->i_height - i_height;
2190 case SUBTITLE_RALIGN:
2191 *pi_y += (p_vout->i_height + p_vout->p_buffer[ p_vout->i_buffer_index ].i_pic_y +
2192 p_vout->p_buffer[ p_vout->i_buffer_index ].i_pic_height - i_height) / 2;
2196 /* Return non 0 if clipping failed */
2197 return( (*pi_x < 0) || (*pi_y < 0) ||
2198 (*pi_x + i_width > p_vout->i_width) || (*pi_y + i_height > p_vout->i_height) );
2201 /*****************************************************************************
2202 * SetPalette: sets an 8 bpp palette
2203 *****************************************************************************
2204 * This function is just a prototype that does nothing. Architectures that
2205 * support palette allocation should override it.
2206 *****************************************************************************/
2207 static void SetPalette ( p_vout_thread_t p_vout, u16 *red,
2208 u16 *green, u16 *blue, u16 *transp )
2210 intf_ErrMsg( "SetPalette: method does not support palette changing\n" );