1 /*****************************************************************************
2 * video_output.c : video output thread
3 * This module describes the programming interface for video output threads.
4 * It includes functions allowing to open a new thread, send pictures to a
5 * thread, and destroy a previously oppened video output thread.
6 *****************************************************************************
7 * Copyright (C) 2000 VideoLAN
8 * $Id: video_output.c,v 1.126 2001/05/07 04:42:42 sam Exp $
10 * Authors: Vincent Seguin <seguin@via.ecp.fr>
12 * This program is free software; you can redistribute it and/or modify
13 * it under the terms of the GNU General Public License as published by
14 * the Free Software Foundation; either version 2 of the License, or
15 * (at your option) any later version.
17 * This program is distributed in the hope that it will be useful,
18 * but WITHOUT ANY WARRANTY; without even the implied warranty of
19 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 * GNU General Public License for more details.
22 * You should have received a copy of the GNU General Public License
23 * along with this program; if not, write to the Free Software
24 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111, USA.
25 *****************************************************************************/
27 /*****************************************************************************
29 *****************************************************************************/
32 #include <errno.h> /* ENOMEM */
33 #include <stdlib.h> /* free() */
34 #include <stdio.h> /* sprintf() */
35 #include <string.h> /* strerror() */
38 # include <sys/times.h>
48 #include "video_output.h"
49 #include "video_text.h"
50 #include "video_spu.h"
51 #include "video_yuv.h"
57 /*****************************************************************************
59 *****************************************************************************/
60 static int BinaryLog ( u32 i );
61 static void MaskToShift ( int *pi_left, int *pi_right, u32 i_mask );
62 static int InitThread ( vout_thread_t *p_vout );
63 static void RunThread ( vout_thread_t *p_vout );
64 static void ErrorThread ( vout_thread_t *p_vout );
65 static void EndThread ( vout_thread_t *p_vout );
66 static void DestroyThread ( vout_thread_t *p_vout, int i_status );
67 static void Print ( vout_thread_t *p_vout, int i_x, int i_y,
68 int i_h_align, int i_v_align,
69 unsigned char *psz_text );
70 static void SetBufferArea ( vout_thread_t *p_vout, int i_x, int i_y,
72 static void SetBufferPicture ( vout_thread_t *p_vout, picture_t *p_pic );
73 static void RenderPicture ( vout_thread_t *p_vout, picture_t *p_pic );
74 static void RenderPictureInfo ( vout_thread_t *p_vout, picture_t *p_pic );
75 static void RenderSubPicture ( vout_thread_t *p_vout,
76 subpicture_t *p_subpic );
77 static void RenderInterface ( vout_thread_t *p_vout );
78 static int RenderIdle ( vout_thread_t *p_vout );
79 static int RenderSplash ( vout_thread_t *p_vout );
80 static void RenderInfo ( vout_thread_t *p_vout );
81 static int Manage ( vout_thread_t *p_vout );
82 static int Align ( vout_thread_t *p_vout, int *pi_x,
83 int *pi_y, int i_width, int i_height,
84 int i_h_align, int i_v_align );
85 static void SetPalette ( p_vout_thread_t p_vout, u16 *red,
86 u16 *green, u16 *blue, u16 *transp );
88 /*****************************************************************************
89 * vout_InitBank: initialize the video output bank.
90 *****************************************************************************/
91 void vout_InitBank ( void )
93 p_vout_bank->i_count = 0;
95 vlc_mutex_init( &p_vout_bank->lock );
98 /*****************************************************************************
99 * vout_EndBank: empty the video output bank.
100 *****************************************************************************
101 * This function ends all unused video outputs and empties the bank in
103 *****************************************************************************/
104 void vout_EndBank ( void )
106 /* Ask all remaining video outputs to die */
107 while( p_vout_bank->i_count )
110 p_vout_bank->pp_vout[ --p_vout_bank->i_count ], NULL );
113 vlc_mutex_destroy( &p_vout_bank->lock );
116 /*****************************************************************************
117 * vout_CreateThread: creates a new video output thread
118 *****************************************************************************
119 * This function creates a new video output thread, and returns a pointer
120 * to its description. On error, it returns NULL.
121 * If pi_status is NULL, then the function will block until the thread is ready.
122 * If not, it will be updated using one of the THREAD_* constants.
123 *****************************************************************************/
124 vout_thread_t * vout_CreateThread ( int *pi_status )
126 vout_thread_t * p_vout; /* thread descriptor */
127 int i_status; /* thread status */
128 int i_index; /* index for array initialization */
130 /* Allocate descriptor */
131 p_vout = (vout_thread_t *) malloc( sizeof(vout_thread_t) );
134 intf_ErrMsg( "vout error: vout thread creation returned %s",
139 /* Choose the best module */
140 p_vout->p_module = module_Need( MODULE_CAPABILITY_VOUT, NULL );
142 if( p_vout->p_module == NULL )
144 intf_ErrMsg( "vout error: no suitable vout module" );
149 #define f p_vout->p_module->p_functions->vout.functions.vout
150 p_vout->pf_create = f.pf_create;
151 p_vout->pf_init = f.pf_init;
152 p_vout->pf_end = f.pf_end;
153 p_vout->pf_destroy = f.pf_destroy;
154 p_vout->pf_manage = f.pf_manage;
155 p_vout->pf_display = f.pf_display;
156 p_vout->pf_setpalette = f.pf_setpalette;
159 if( p_vout->pf_setpalette == NULL )
161 p_vout->pf_setpalette = SetPalette;
164 /* Initialize thread properties - thread id and locks will be initialized
168 p_vout->b_active = 0;
169 p_vout->pi_status = (pi_status != NULL) ? pi_status : &i_status;
170 *p_vout->pi_status = THREAD_CREATE;
172 /* Initialize some fields used by the system-dependant method - these
173 * fields will probably be modified by the method, and are only
175 p_vout->i_changes = 0;
176 p_vout->i_width = main_GetIntVariable( VOUT_WIDTH_VAR,
177 VOUT_WIDTH_DEFAULT );
178 p_vout->i_height = main_GetIntVariable( VOUT_HEIGHT_VAR,
179 VOUT_HEIGHT_DEFAULT );
180 p_vout->i_bytes_per_line = p_vout->i_width * 2;
181 p_vout->i_screen_depth = main_GetIntVariable( VOUT_DEPTH_VAR,
182 VOUT_DEPTH_DEFAULT );
183 p_vout->i_bytes_per_pixel = 2;
184 p_vout->f_gamma = VOUT_GAMMA_DEFAULT; // FIXME: replace with
186 p_vout->b_need_render = 1;
189 p_vout->b_grayscale = main_GetIntVariable( VOUT_GRAYSCALE_VAR,
190 VOUT_GRAYSCALE_DEFAULT );
192 p_vout->b_interface = 0;
194 p_vout->b_fullscreen = main_GetIntVariable( VOUT_FULLSCREEN_VAR,
195 VOUT_FULLSCREEN_DEFAULT );
197 intf_WarnMsg( 3, "wished configuration: %dx%d, %d/%d bpp (%d Bpl)",
198 p_vout->i_width, p_vout->i_height, p_vout->i_screen_depth,
199 p_vout->i_bytes_per_pixel * 8, p_vout->i_bytes_per_line );
201 /* Initialize idle screen */
202 p_vout->last_display_date = 0;
203 p_vout->last_idle_date = 0;
204 p_vout->init_display_date = mdate();
205 p_vout->render_time = 10000;
207 /* Initialize statistics fields */
208 p_vout->c_fps_samples = 0;
210 /* Initialize buffer index */
211 p_vout->i_buffer_index = 0;
213 /* Initialize pictures and subpictures - translation tables and functions
214 * will be initialized later in InitThread */
215 for( i_index = 0; i_index < VOUT_MAX_PICTURES; i_index++)
217 p_vout->p_picture[i_index].i_type = EMPTY_PICTURE;
218 p_vout->p_picture[i_index].i_status = FREE_PICTURE;
221 for( i_index = 0; i_index < VOUT_MAX_SUBPICTURES; i_index++)
223 p_vout->p_subpicture[i_index].i_type = EMPTY_SUBPICTURE;
224 p_vout->p_subpicture[i_index].i_status = FREE_SUBPICTURE;
227 p_vout->i_pictures = 0;
229 /* Create and initialize system-dependant method - this function issues its
230 * own error messages */
231 if( p_vout->pf_create( p_vout ) )
233 module_Unneed( p_vout->p_module );
238 intf_WarnMsg( 3, "actual configuration: %dx%d, %d/%d bpp (%d Bpl), "
239 "masks: 0x%x/0x%x/0x%x",
240 p_vout->i_width, p_vout->i_height, p_vout->i_screen_depth,
241 p_vout->i_bytes_per_pixel * 8, p_vout->i_bytes_per_line,
242 p_vout->i_red_mask, p_vout->i_green_mask,
243 p_vout->i_blue_mask );
245 /* Calculate shifts from system-updated masks */
246 MaskToShift( &p_vout->i_red_lshift, &p_vout->i_red_rshift,
247 p_vout->i_red_mask );
248 MaskToShift( &p_vout->i_green_lshift, &p_vout->i_green_rshift,
249 p_vout->i_green_mask );
250 MaskToShift( &p_vout->i_blue_lshift, &p_vout->i_blue_rshift,
251 p_vout->i_blue_mask );
253 /* Set some useful colors */
254 p_vout->i_white_pixel = RGB2PIXEL( p_vout, 255, 255, 255 );
255 p_vout->i_black_pixel = RGB2PIXEL( p_vout, 0, 0, 0 );
256 p_vout->i_gray_pixel = RGB2PIXEL( p_vout, 128, 128, 128 );
257 p_vout->i_blue_pixel = RGB2PIXEL( p_vout, 0, 0, 50 );
259 /* Load fonts - fonts must be initialized after the system method since
260 * they may be dependant on screen depth and other thread properties */
261 p_vout->p_default_font = vout_LoadFont( VOUT_DEFAULT_FONT );
262 if( p_vout->p_default_font == NULL )
264 intf_ErrMsg( "vout error: could not load default font" );
267 p_vout->p_large_font = vout_LoadFont( VOUT_LARGE_FONT );
268 if( p_vout->p_large_font == NULL )
270 intf_ErrMsg( "vout error: could not load large font" );
273 /* Create thread and set locks */
274 vlc_mutex_init( &p_vout->picture_lock );
275 vlc_mutex_init( &p_vout->subpicture_lock );
276 vlc_mutex_init( &p_vout->change_lock );
278 if( vlc_thread_create( &p_vout->thread_id, "video output",
279 (void *) RunThread, (void *) p_vout) )
281 intf_ErrMsg("vout error: %s", strerror(ENOMEM));
282 vout_UnloadFont( p_vout->p_default_font );
283 vout_UnloadFont( p_vout->p_large_font );
284 p_vout->pf_destroy( p_vout );
289 intf_WarnMsg( 1, "vout: video display initialized (%dx%d, %d/%d bpp)",
290 p_vout->i_width, p_vout->i_height, p_vout->i_screen_depth,
291 p_vout->i_bytes_per_pixel * 8 );
293 /* If status is NULL, wait until the thread is created */
294 if( pi_status == NULL )
298 msleep( THREAD_SLEEP );
299 }while( (i_status != THREAD_READY) && (i_status != THREAD_ERROR)
300 && (i_status != THREAD_FATAL) );
301 if( i_status != THREAD_READY )
309 /*****************************************************************************
310 * vout_DestroyThread: destroys a previously created thread
311 *****************************************************************************
312 * Destroy a terminated thread.
313 * The function will request a destruction of the specified thread. If pi_error
314 * is NULL, it will return once the thread is destroyed. Else, it will be
315 * update using one of the THREAD_* constants.
316 *****************************************************************************/
317 void vout_DestroyThread( vout_thread_t *p_vout, int *pi_status )
319 int i_status; /* thread status */
323 p_vout->pi_status = (pi_status != NULL) ? pi_status : &i_status;
324 *p_vout->pi_status = THREAD_DESTROY;
326 /* Request thread destruction */
329 /* If status is NULL, wait until thread has been destroyed */
330 if( pi_status == NULL )
334 msleep( THREAD_SLEEP );
335 }while( (i_status != THREAD_OVER) && (i_status != THREAD_ERROR)
336 && (i_status != THREAD_FATAL) );
340 /*****************************************************************************
341 * vout_DisplaySubPicture: display a subpicture unit
342 *****************************************************************************
343 * Remove the reservation flag of a subpicture, which will cause it to be ready
344 * for display. The picture does not need to be locked, since it is ignored by
345 * the output thread if is reserved.
346 *****************************************************************************/
347 void vout_DisplaySubPicture( vout_thread_t *p_vout, subpicture_t *p_subpic )
350 char psz_start[ MSTRTIME_MAX_SIZE ]; /* buffer for date string */
351 char psz_stop[ MSTRTIME_MAX_SIZE ]; /* buffer for date string */
355 /* Check if status is valid */
356 if( p_subpic->i_status != RESERVED_SUBPICTURE )
358 intf_ErrMsg("error: subpicture %p has invalid status %d", p_subpic,
359 p_subpic->i_status );
363 /* Remove reservation flag */
364 p_subpic->i_status = READY_SUBPICTURE;
367 /* Send subpicture information */
368 intf_DbgMsg("subpicture %p: type=%d, begin date=%s, end date=%s",
369 p_subpic, p_subpic->i_type,
370 mstrtime( psz_start, p_subpic->i_start ),
371 mstrtime( psz_stop, p_subpic->i_stop ) );
375 /*****************************************************************************
376 * vout_CreateSubPicture: allocate a subpicture in the video output heap.
377 *****************************************************************************
378 * This function create a reserved subpicture in the video output heap.
379 * A null pointer is returned if the function fails. This method provides an
380 * already allocated zone of memory in the spu data fields. It needs locking
381 * since several pictures can be created by several producers threads.
382 *****************************************************************************/
383 subpicture_t *vout_CreateSubPicture( vout_thread_t *p_vout, int i_type,
386 int i_subpic; /* subpicture index */
387 subpicture_t * p_free_subpic = NULL; /* first free subpicture */
388 subpicture_t * p_destroyed_subpic = NULL; /* first destroyed subpic */
391 vlc_mutex_lock( &p_vout->subpicture_lock );
394 * Look for an empty place
396 for( i_subpic = 0; i_subpic < VOUT_MAX_SUBPICTURES; i_subpic++ )
398 if( p_vout->p_subpicture[i_subpic].i_status == DESTROYED_SUBPICTURE )
400 /* Subpicture is marked for destruction, but is still allocated */
401 if( (p_vout->p_subpicture[i_subpic].i_type == i_type) &&
402 (p_vout->p_subpicture[i_subpic].i_size >= i_size) )
404 /* Memory size do match or is smaller : memory will not be
405 * reallocated, and function can end immediately - this is
406 * the best possible case, since no memory allocation needs
408 p_vout->p_subpicture[i_subpic].i_status = RESERVED_SUBPICTURE;
410 intf_DbgMsg("subpicture %p (in destroyed subpicture slot)",
411 &p_vout->p_subpicture[i_subpic] );
413 vlc_mutex_unlock( &p_vout->subpicture_lock );
414 return( &p_vout->p_subpicture[i_subpic] );
416 else if( p_destroyed_subpic == NULL )
418 /* Memory size do not match, but subpicture index will be kept in
419 * case no other place are left */
420 p_destroyed_subpic = &p_vout->p_subpicture[i_subpic];
423 else if( (p_free_subpic == NULL) &&
424 (p_vout->p_subpicture[i_subpic].i_status == FREE_SUBPICTURE ))
426 /* Subpicture is empty and ready for allocation */
427 p_free_subpic = &p_vout->p_subpicture[i_subpic];
431 /* If no free subpictures are available, use a destroyed subpicture */
432 if( (p_free_subpic == NULL) && (p_destroyed_subpic != NULL ) )
434 /* No free subpicture or matching destroyed subpictures have been
435 * found, but a destroyed subpicture is still avalaible */
436 free( p_destroyed_subpic->p_data );
437 p_free_subpic = p_destroyed_subpic;
443 if( p_free_subpic != NULL )
445 /* Allocate memory */
448 case TEXT_SUBPICTURE: /* text subpicture */
449 p_free_subpic->p_data = malloc( i_size + 1 );
451 case DVD_SUBPICTURE: /* DVD subpicture unit */
452 p_free_subpic->p_data = malloc( i_size );
456 intf_ErrMsg("error: unknown subpicture type %d", i_type );
457 p_free_subpic->p_data = NULL;
462 if( p_free_subpic->p_data != NULL )
464 /* Copy subpicture information, set some default values */
465 p_free_subpic->i_type = i_type;
466 p_free_subpic->i_status = RESERVED_SUBPICTURE;
467 p_free_subpic->i_size = i_size;
468 p_free_subpic->i_x = 0;
469 p_free_subpic->i_y = 0;
470 p_free_subpic->i_width = 0;
471 p_free_subpic->i_height = 0;
472 p_free_subpic->i_horizontal_align = CENTER_RALIGN;
473 p_free_subpic->i_vertical_align = CENTER_RALIGN;
477 /* Memory allocation failed : set subpicture as empty */
478 p_free_subpic->i_type = EMPTY_SUBPICTURE;
479 p_free_subpic->i_status = FREE_SUBPICTURE;
480 p_free_subpic = NULL;
481 intf_ErrMsg( "vout error: spu allocation returned %s",
482 strerror( ENOMEM ) );
486 intf_DbgMsg("subpicture %p (in free subpicture slot)", p_free_subpic );
488 vlc_mutex_unlock( &p_vout->subpicture_lock );
489 return( p_free_subpic );
492 /* No free or destroyed subpicture could be found */
493 intf_DbgMsg( "warning: subpicture heap is full" );
494 vlc_mutex_unlock( &p_vout->subpicture_lock );
498 /*****************************************************************************
499 * vout_DestroySubPicture: remove a subpicture from the heap
500 *****************************************************************************
501 * This function frees a previously reserved subpicture.
502 * It is meant to be used when the construction of a picture aborted.
503 * This function does not need locking since reserved subpictures are ignored
504 * by the output thread.
505 *****************************************************************************/
506 void vout_DestroySubPicture( vout_thread_t *p_vout, subpicture_t *p_subpic )
509 /* Check if status is valid */
510 if( p_subpic->i_status != RESERVED_SUBPICTURE )
512 intf_ErrMsg("error: subpicture %p has invalid status %d",
513 p_subpic, p_subpic->i_status );
517 p_subpic->i_status = DESTROYED_SUBPICTURE;
520 intf_DbgMsg("subpicture %p", p_subpic);
524 /*****************************************************************************
525 * vout_DisplayPicture: display a picture
526 *****************************************************************************
527 * Remove the reservation flag of a picture, which will cause it to be ready for
528 * display. The picture won't be displayed until vout_DatePicture has been
530 *****************************************************************************/
531 void vout_DisplayPicture( vout_thread_t *p_vout, picture_t *p_pic )
533 vlc_mutex_lock( &p_vout->picture_lock );
534 switch( p_pic->i_status )
536 case RESERVED_PICTURE:
537 p_pic->i_status = RESERVED_DISP_PICTURE;
539 case RESERVED_DATED_PICTURE:
540 p_pic->i_status = READY_PICTURE;
544 intf_ErrMsg("error: picture %p has invalid status %d", p_pic, p_pic->i_status );
550 intf_DbgMsg("picture %p", p_pic);
552 vlc_mutex_unlock( &p_vout->picture_lock );
555 /*****************************************************************************
556 * vout_DatePicture: date a picture
557 *****************************************************************************
558 * Remove the reservation flag of a picture, which will cause it to be ready for
559 * display. The picture won't be displayed until vout_DisplayPicture has been
561 *****************************************************************************/
562 void vout_DatePicture( vout_thread_t *p_vout, picture_t *p_pic, mtime_t date )
565 char psz_date[MSTRTIME_MAX_SIZE]; /* date */
568 vlc_mutex_lock( &p_vout->picture_lock );
570 switch( p_pic->i_status )
572 case RESERVED_PICTURE:
573 p_pic->i_status = RESERVED_DATED_PICTURE;
575 case RESERVED_DISP_PICTURE:
576 p_pic->i_status = READY_PICTURE;
580 intf_ErrMsg("error: picture %p has invalid status %d", p_pic, p_pic->i_status );
586 intf_DbgMsg("picture %p, display date: %s", p_pic, mstrtime( psz_date, p_pic->date) );
588 vlc_mutex_unlock( &p_vout->picture_lock );
591 /*****************************************************************************
592 * vout_CreatePicture: allocate a picture in the video output heap.
593 *****************************************************************************
594 * This function create a reserved image in the video output heap.
595 * A null pointer is returned if the function fails. This method provides an
596 * already allocated zone of memory in the picture data fields. It needs locking
597 * since several pictures can be created by several producers threads.
598 *****************************************************************************/
599 picture_t *vout_CreatePicture( vout_thread_t *p_vout, int i_type,
600 int i_width, int i_height )
602 int i_picture; /* picture index */
603 int i_chroma_width = 0; /* chroma width */
604 picture_t * p_free_picture = NULL; /* first free picture */
605 picture_t * p_destroyed_picture = NULL; /* first destroyed picture */
608 vlc_mutex_lock( &p_vout->picture_lock );
611 * Look for an empty place
613 for( i_picture = 0; i_picture < VOUT_MAX_PICTURES; i_picture++ )
615 if( p_vout->p_picture[i_picture].i_status == DESTROYED_PICTURE )
617 /* Picture is marked for destruction, but is still allocated - note
618 * that if width and type are the same for two pictures, chroma_width
619 * should also be the same */
620 if( (p_vout->p_picture[i_picture].i_type == i_type) &&
621 (p_vout->p_picture[i_picture].i_height == i_height) &&
622 (p_vout->p_picture[i_picture].i_width == i_width) )
624 /* Memory size do match : memory will not be reallocated, and function
625 * can end immediately - this is the best possible case, since no
626 * memory allocation needs to be done */
627 p_vout->p_picture[i_picture].i_status = RESERVED_PICTURE;
628 p_vout->i_pictures++;
630 intf_DbgMsg("picture %p (in destroyed picture slot)",
631 &p_vout->p_picture[i_picture] );
633 vlc_mutex_unlock( &p_vout->picture_lock );
634 return( &p_vout->p_picture[i_picture] );
636 else if( p_destroyed_picture == NULL )
638 /* Memory size do not match, but picture index will be kept in
639 * case no other place are left */
640 p_destroyed_picture = &p_vout->p_picture[i_picture];
643 else if( (p_free_picture == NULL) &&
644 (p_vout->p_picture[i_picture].i_status == FREE_PICTURE ))
646 /* Picture is empty and ready for allocation */
647 p_free_picture = &p_vout->p_picture[i_picture];
651 /* If no free picture is available, use a destroyed picture */
652 if( (p_free_picture == NULL) && (p_destroyed_picture != NULL ) )
654 /* No free picture or matching destroyed picture has been found, but
655 * a destroyed picture is still avalaible */
656 free( p_destroyed_picture->p_data );
657 p_free_picture = p_destroyed_picture;
663 if( p_free_picture != NULL )
665 /* Allocate memory */
668 case YUV_420_PICTURE: /* YUV 420: 1,1/4,1/4 samples per pixel */
669 i_chroma_width = i_width / 2;
670 p_free_picture->p_data = malloc( i_height * i_chroma_width * 3 * sizeof( yuv_data_t ) );
671 p_free_picture->p_y = (yuv_data_t *)p_free_picture->p_data;
672 p_free_picture->p_u = (yuv_data_t *)p_free_picture->p_data +i_height*i_chroma_width*4/2;
673 p_free_picture->p_v = (yuv_data_t *)p_free_picture->p_data +i_height*i_chroma_width*5/2;
675 case YUV_422_PICTURE: /* YUV 422: 1,1/2,1/2 samples per pixel */
676 i_chroma_width = i_width / 2;
677 p_free_picture->p_data = malloc( i_height * i_chroma_width * 4 * sizeof( yuv_data_t ) );
678 p_free_picture->p_y = (yuv_data_t *)p_free_picture->p_data;
679 p_free_picture->p_u = (yuv_data_t *)p_free_picture->p_data +i_height*i_chroma_width*2;
680 p_free_picture->p_v = (yuv_data_t *)p_free_picture->p_data +i_height*i_chroma_width*3;
682 case YUV_444_PICTURE: /* YUV 444: 1,1,1 samples per pixel */
683 i_chroma_width = i_width;
684 p_free_picture->p_data = malloc( i_height * i_chroma_width * 3 * sizeof( yuv_data_t ) );
685 p_free_picture->p_y = (yuv_data_t *)p_free_picture->p_data;
686 p_free_picture->p_u = (yuv_data_t *)p_free_picture->p_data +i_height*i_chroma_width;
687 p_free_picture->p_v = (yuv_data_t *)p_free_picture->p_data +i_height*i_chroma_width*2;
691 intf_ErrMsg("error: unknown picture type %d", i_type );
692 p_free_picture->p_data = NULL;
697 if( p_free_picture->p_data != NULL )
699 /* Copy picture information, set some default values */
700 p_free_picture->i_type = i_type;
701 p_free_picture->i_status = RESERVED_PICTURE;
702 p_free_picture->i_matrix_coefficients = 1;
703 p_free_picture->i_width = i_width;
704 p_free_picture->i_height = i_height;
705 p_free_picture->i_chroma_width = i_chroma_width;
706 p_free_picture->i_size = i_width * i_height;
707 p_free_picture->i_chroma_size = i_chroma_width
709 p_free_picture->i_display_horizontal_offset = 0;
710 p_free_picture->i_display_vertical_offset = 0;
711 p_free_picture->i_display_width = i_width;
712 p_free_picture->i_display_height = i_height;
713 p_free_picture->i_aspect_ratio = AR_SQUARE_PICTURE;
714 p_free_picture->i_refcount = 0;
715 p_vout->i_pictures++;
719 /* Memory allocation failed : set picture as empty */
720 p_free_picture->i_type = EMPTY_PICTURE;
721 p_free_picture->i_status = FREE_PICTURE;
722 p_free_picture = NULL;
723 intf_ErrMsg( "vout error: picture allocation returned %s",
724 strerror( ENOMEM ) );
728 intf_DbgMsg("picture %p (in free picture slot)", p_free_picture );
730 vlc_mutex_unlock( &p_vout->picture_lock );
732 /* Initialize mutex */
733 vlc_mutex_init( &(p_free_picture->lock_deccount) );
735 return( p_free_picture );
738 /* No free or destroyed picture could be found */
739 intf_DbgMsg( "warning: picture heap is full" );
740 vlc_mutex_unlock( &p_vout->picture_lock );
744 /*****************************************************************************
745 * vout_DestroyPicture: remove a permanent or reserved picture from the heap
746 *****************************************************************************
747 * This function frees a previously reserved picture or a permanent
748 * picture. It is meant to be used when the construction of a picture aborted.
749 * Note that the picture will be destroyed even if it is linked !
750 *****************************************************************************/
751 void vout_DestroyPicture( vout_thread_t *p_vout, picture_t *p_pic )
753 vlc_mutex_lock( &p_vout->picture_lock );
756 /* Check if picture status is valid */
757 if( (p_pic->i_status != RESERVED_PICTURE) &&
758 (p_pic->i_status != RESERVED_DATED_PICTURE) &&
759 (p_pic->i_status != RESERVED_DISP_PICTURE) )
761 intf_ErrMsg("error: picture %p has invalid status %d", p_pic, p_pic->i_status );
765 p_pic->i_status = DESTROYED_PICTURE;
766 p_vout->i_pictures--;
769 intf_DbgMsg("picture %p", p_pic);
772 /* destroy the lock that had been initialized in CreatePicture */
773 vlc_mutex_destroy( &(p_pic->lock_deccount) );
775 vlc_mutex_unlock( &p_vout->picture_lock );
778 /*****************************************************************************
779 * vout_LinkPicture: increment reference counter of a picture
780 *****************************************************************************
781 * This function increment the reference counter of a picture in the video
782 * heap. It needs a lock since several producer threads can access the picture.
783 *****************************************************************************/
784 void vout_LinkPicture( vout_thread_t *p_vout, picture_t *p_pic )
786 vlc_mutex_lock( &p_vout->picture_lock );
790 intf_DbgMsg("picture %p refcount=%d", p_pic, p_pic->i_refcount );
793 vlc_mutex_unlock( &p_vout->picture_lock );
796 /*****************************************************************************
797 * vout_UnlinkPicture: decrement reference counter of a picture
798 *****************************************************************************
799 * This function decrement the reference counter of a picture in the video heap.
800 *****************************************************************************/
801 void vout_UnlinkPicture( vout_thread_t *p_vout, picture_t *p_pic )
803 vlc_mutex_lock( &p_vout->picture_lock );
807 if( p_pic->i_refcount < 0 )
809 intf_DbgMsg("error: refcount < 0");
810 p_pic->i_refcount = 0;
814 if( (p_pic->i_refcount == 0) && (p_pic->i_status == DISPLAYED_PICTURE) )
816 p_pic->i_status = DESTROYED_PICTURE;
817 p_vout->i_pictures--;
821 intf_DbgMsg("picture %p refcount=%d", p_pic, p_pic->i_refcount );
824 vlc_mutex_unlock( &p_vout->picture_lock );
827 /*****************************************************************************
828 * vout_SetBuffers: set buffers adresses
829 *****************************************************************************
830 * This function is called by system drivers to set buffers video memory
832 *****************************************************************************/
833 void vout_SetBuffers( vout_thread_t *p_vout, void *p_buf1, void *p_buf2 )
835 /* No picture previously */
836 p_vout->p_buffer[0].i_pic_x = 0;
837 p_vout->p_buffer[0].i_pic_y = 0;
838 p_vout->p_buffer[0].i_pic_width = 0;
839 p_vout->p_buffer[0].i_pic_height = 0;
840 p_vout->p_buffer[1].i_pic_x = 0;
841 p_vout->p_buffer[1].i_pic_y = 0;
842 p_vout->p_buffer[1].i_pic_width = 0;
843 p_vout->p_buffer[1].i_pic_height = 0;
845 /* The first area covers all the screen */
846 p_vout->p_buffer[0].i_areas = 1;
847 p_vout->p_buffer[0].pi_area_begin[0] = 0;
848 p_vout->p_buffer[0].pi_area_end[0] = p_vout->i_height - 1;
849 p_vout->p_buffer[1].i_areas = 1;
850 p_vout->p_buffer[1].pi_area_begin[0] = 0;
851 p_vout->p_buffer[1].pi_area_end[0] = p_vout->i_height - 1;
854 p_vout->p_buffer[0].p_data = p_buf1;
855 p_vout->p_buffer[1].p_data = p_buf2;
858 /*****************************************************************************
859 * vout_Pixel2RGB: return red, green and blue from pixel value
860 *****************************************************************************
861 * Return color values, in 0-255 range, of the decomposition of a pixel. This
862 * is a slow routine and should only be used for initialization phase.
863 *****************************************************************************/
864 void vout_Pixel2RGB( vout_thread_t *p_vout, u32 i_pixel, int *pi_red, int *pi_green, int *pi_blue )
866 *pi_red = i_pixel & p_vout->i_red_mask;
867 *pi_green = i_pixel & p_vout->i_green_mask;
868 *pi_blue = i_pixel & p_vout->i_blue_mask;
871 /* following functions are local */
873 /*****************************************************************************
874 * BinaryLog: computes the base 2 log of a binary value
875 *****************************************************************************
876 * This functions is used by MaskToShift, to get a bit index from a binary
878 *****************************************************************************/
879 static int BinaryLog(u32 i)
904 if (i != ((u32)1 << i_log))
906 intf_DbgMsg("internal error: binary log overflow");
912 /*****************************************************************************
913 * MaskToShift: transform a color mask into right and left shifts
914 *****************************************************************************
915 * This function is used for obtaining color shifts from masks.
916 *****************************************************************************/
917 static void MaskToShift( int *pi_left, int *pi_right, u32 i_mask )
919 u32 i_low, i_high; /* lower hand higher bits of the mask */
922 i_low = i_mask & (- i_mask); /* lower bit of the mask */
923 i_high = i_mask + i_low; /* higher bit of the mask */
925 /* Transform bits into an index */
926 i_low = BinaryLog (i_low);
927 i_high = BinaryLog (i_high);
929 /* Update pointers and return */
931 *pi_right = (8 - i_high + i_low);
934 /*****************************************************************************
935 * InitThread: initialize video output thread
936 *****************************************************************************
937 * This function is called from RunThread and performs the second step of the
938 * initialization. It returns 0 on success. Note that the thread's flag are not
939 * modified inside this function.
940 *****************************************************************************/
941 static int InitThread( vout_thread_t *p_vout )
944 *p_vout->pi_status = THREAD_START;
946 vlc_mutex_lock( &p_vout->change_lock );
952 /* Initialize output method - this function issues its own error messages */
953 if( p_vout->pf_init( p_vout ) )
958 /* Initialize convertion tables and functions */
959 if( vout_InitYUV( p_vout ) )
961 intf_ErrMsg("vout error: can't allocate YUV translation tables");
965 /* Mark thread as running and return */
966 p_vout->b_active = 1;
967 *p_vout->pi_status = THREAD_READY;
970 intf_DbgMsg("thread ready");
974 /*****************************************************************************
975 * RunThread: video output thread
976 *****************************************************************************
977 * Video output thread. This function does only returns when the thread is
978 * terminated. It handles the pictures arriving in the video heap and the
979 * display device events.
980 *****************************************************************************/
981 static void RunThread( vout_thread_t *p_vout)
983 int i_index; /* index in heap */
984 mtime_t current_date; /* current date */
985 mtime_t display_date; /* display date */
986 boolean_t b_display; /* display flag */
987 picture_t * p_pic; /* picture pointer */
988 subpicture_t * p_subpic; /* subpicture pointer */
993 p_vout->b_error = InitThread( p_vout );
994 if( p_vout->b_error )
996 DestroyThread( p_vout, THREAD_ERROR );
1001 * Main loop - it is not executed if an error occured during
1004 while( (!p_vout->b_die) && (!p_vout->b_error) )
1006 /* Initialize loop variables */
1010 current_date = mdate();
1013 if( !(p_vout->c_loops % VOUT_STATS_NB_LOOPS) )
1015 intf_Msg("vout stats: picture heap: %d/%d",
1016 p_vout->i_pictures, VOUT_MAX_PICTURES);
1021 * Find the picture to display - this operation does not need lock,
1022 * since only READY_PICTUREs are handled
1024 for( i_index = 0; i_index < VOUT_MAX_PICTURES; i_index++ )
1026 if( (p_vout->p_picture[i_index].i_status == READY_PICTURE) &&
1027 ( (p_pic == NULL) ||
1028 (p_vout->p_picture[i_index].date < display_date) ) )
1030 p_pic = &p_vout->p_picture[i_index];
1031 display_date = p_pic->date;
1037 /* Computes FPS rate */
1038 p_vout->p_fps_sample[ p_vout->c_fps_samples++ % VOUT_FPS_SAMPLES ] = display_date;
1040 if( display_date < current_date - p_vout->render_time )
1042 /* Picture is late: it will be destroyed and the thread
1043 * will sleep and go to next picture */
1045 vlc_mutex_lock( &p_vout->picture_lock );
1046 if( p_pic->i_refcount )
1048 p_pic->i_status = DISPLAYED_PICTURE;
1052 p_pic->i_status = DESTROYED_PICTURE;
1053 p_vout->i_pictures--;
1056 "warning: late picture skipped (%p)", p_pic );
1057 vlc_mutex_unlock( &p_vout->picture_lock );
1061 else if( display_date > current_date + VOUT_DISPLAY_DELAY )
1063 /* A picture is ready to be rendered, but its rendering date
1064 * is far from the current one so the thread will perform an
1065 * empty loop as if no picture were found. The picture state
1073 * Find the subpictures to display - this operation does not need
1074 * lock, since only READY_SUBPICTURE are handled. If no picture
1075 * has been selected, display_date will depend on the subpicture.
1076 * We get an easily parsable chained list of subpictures which
1077 * ends with NULL since p_subpic was initialized to NULL.
1079 for( i_index = 0; i_index < VOUT_MAX_SUBPICTURES; i_index++ )
1081 if( p_vout->p_subpicture[i_index].i_status == READY_SUBPICTURE )
1083 p_vout->p_subpicture[i_index].p_next = p_subpic;
1084 p_subpic = &p_vout->p_subpicture[i_index];
1089 * Perform rendering, sleep and display rendered picture
1091 if( p_pic ) /* picture and perhaps subpicture */
1093 b_display = p_vout->b_active;
1094 p_vout->last_display_date = display_date;
1095 p_vout->p_rendered_pic = p_pic;
1097 /* Set picture dimensions and clear buffer */
1098 SetBufferPicture( p_vout, p_pic );
1100 /* FIXME: if b_need_render == 0 we need to do something with
1101 * the subpictures one day. */
1103 if( p_vout->b_need_render && b_display )
1105 /* Render picture and information */
1106 RenderPicture( p_vout, p_pic );
1107 if( p_vout->b_info )
1109 RenderPictureInfo( p_vout, p_pic );
1110 RenderInfo( p_vout );
1114 RenderSubPicture( p_vout, p_subpic );
1118 /* Render interface and subpicture */
1119 if( b_display && p_vout->b_interface && p_vout->b_need_render )
1121 RenderInterface( p_vout );
1125 else if( p_vout->b_active && p_vout->b_need_render
1126 && p_vout->init_display_date == 0)
1128 /* Idle or interface screen alone */
1130 if( p_vout->b_interface && 0 /* && XXX?? intf_change */ )
1132 /* Interface has changed, so a new rendering is required - force
1133 * it by setting last idle date to 0 */
1134 p_vout->last_idle_date = 0;
1137 /* Render idle screen and update idle date, then render interface if
1139 b_display = RenderIdle( p_vout );
1142 p_vout->last_idle_date = current_date;
1143 if( p_vout->b_interface )
1145 RenderInterface( p_vout );
1157 * Check for the current time and
1158 * display splash screen if everything is on time
1160 if( p_vout->init_display_date > 0 && p_vout->b_need_render )
1162 if( p_vout->b_active &&
1163 mdate()-p_vout->init_display_date < 5000000)
1165 /* there is something to display ! */
1167 RenderSplash( p_vout );
1170 /* no splash screen ! */
1171 p_vout->init_display_date=0;
1177 * Sleep, wake up and display rendered picture
1180 if( display_date != 0 )
1182 /* Store render time using Bresenham algorithm */
1183 p_vout->render_time += mdate() - current_date;
1184 p_vout->render_time >>= 1;
1187 /* Give back change lock */
1188 vlc_mutex_unlock( &p_vout->change_lock );
1190 /* Sleep a while or until a given date */
1191 if( display_date != 0 )
1193 mwait( display_date - VOUT_MWAIT_TOLERANCE );
1197 msleep( VOUT_IDLE_SLEEP );
1200 /* On awakening, take back lock and send immediately picture to display,
1201 * then swap buffers */
1202 vlc_mutex_lock( &p_vout->change_lock );
1204 intf_DbgMsg( "picture %p, subpicture %p in buffer %d, display=%d", p_pic, p_subpic,
1205 p_vout->i_buffer_index, b_display /* && !(p_vout->i_changes & VOUT_NODISPLAY_CHANGE) */ );
1207 if( b_display /* && !(p_vout->i_changes & VOUT_NODISPLAY_CHANGE) */ )
1209 p_vout->pf_display( p_vout );
1211 p_vout->i_buffer_index = ++p_vout->i_buffer_index & 1;
1217 /* Remove picture from heap */
1218 vlc_mutex_lock( &p_vout->picture_lock );
1219 if( p_pic->i_refcount )
1221 p_pic->i_status = DISPLAYED_PICTURE;
1225 p_pic->i_status = DESTROYED_PICTURE;
1226 p_vout->i_pictures--;
1228 vlc_mutex_unlock( &p_vout->picture_lock );
1233 * Check events and manage thread
1235 if( p_vout->pf_manage( p_vout ) | Manage( p_vout ) )
1237 /* A fatal error occured, and the thread must terminate immediately,
1238 * without displaying anything - setting b_error to 1 cause the
1239 * immediate end of the main while() loop. */
1240 p_vout->b_error = 1;
1245 * Error loop - wait until the thread destruction is requested
1247 if( p_vout->b_error )
1249 ErrorThread( p_vout );
1253 EndThread( p_vout );
1254 DestroyThread( p_vout, THREAD_OVER );
1255 intf_DbgMsg( "thread end" );
1258 /*****************************************************************************
1259 * ErrorThread: RunThread() error loop
1260 *****************************************************************************
1261 * This function is called when an error occured during thread main's loop. The
1262 * thread can still receive feed, but must be ready to terminate as soon as
1264 *****************************************************************************/
1265 static void ErrorThread( vout_thread_t *p_vout )
1267 /* Wait until a `die' order */
1268 while( !p_vout->b_die )
1271 msleep( VOUT_IDLE_SLEEP );
1275 /*****************************************************************************
1276 * EndThread: thread destruction
1277 *****************************************************************************
1278 * This function is called when the thread ends after a sucessful
1279 * initialization. It frees all ressources allocated by InitThread.
1280 *****************************************************************************/
1281 static void EndThread( vout_thread_t *p_vout )
1283 int i_index; /* index in heap */
1286 *p_vout->pi_status = THREAD_END;
1290 struct tms cpu_usage;
1291 times( &cpu_usage );
1293 intf_Msg( "vout stats: cpu usage (user: %d, system: %d)",
1294 cpu_usage.tms_utime, cpu_usage.tms_stime );
1298 /* Destroy all remaining pictures and subpictures */
1299 for( i_index = 0; i_index < VOUT_MAX_PICTURES; i_index++ )
1301 if( p_vout->p_picture[i_index].i_status != FREE_PICTURE )
1303 free( p_vout->p_picture[i_index].p_data );
1307 for( i_index = 0; i_index < VOUT_MAX_SUBPICTURES; i_index++ )
1309 if( p_vout->p_subpicture[i_index].i_status != FREE_SUBPICTURE )
1311 free( p_vout->p_subpicture[i_index].p_data );
1315 /* Destroy translation tables */
1316 vout_EndYUV( p_vout );
1317 p_vout->pf_end( p_vout );
1319 /* Release the change lock */
1320 vlc_mutex_unlock( &p_vout->change_lock );
1323 /*****************************************************************************
1324 * DestroyThread: thread destruction
1325 *****************************************************************************
1326 * This function is called when the thread ends. It frees all ressources
1327 * allocated by CreateThread. Status is available at this stage.
1328 *****************************************************************************/
1329 static void DestroyThread( vout_thread_t *p_vout, int i_status )
1331 int *pi_status; /* status adress */
1333 /* Store status adress */
1334 pi_status = p_vout->pi_status;
1336 /* Destroy thread structures allocated by Create and InitThread */
1337 vout_UnloadFont( p_vout->p_default_font );
1338 vout_UnloadFont( p_vout->p_large_font );
1339 p_vout->pf_destroy( p_vout );
1341 /* Destroy the locks */
1342 vlc_mutex_destroy( &p_vout->picture_lock );
1343 vlc_mutex_destroy( &p_vout->subpicture_lock );
1344 vlc_mutex_destroy( &p_vout->change_lock );
1346 /* Release the module */
1347 module_Unneed( p_vout->p_module );
1349 /* Free structure */
1351 *pi_status = i_status;
1354 /*****************************************************************************
1355 * Print: print simple text on a picture
1356 *****************************************************************************
1357 * This function will print a simple text on the picture. It is designed to
1358 * print debugging or general information.
1359 *****************************************************************************/
1360 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 )
1362 int i_text_height; /* total text height */
1363 int i_text_width; /* total text width */
1365 /* Update upper left coordinates according to alignment */
1366 vout_TextSize( p_vout->p_default_font, 0, psz_text, &i_text_width, &i_text_height );
1367 if( !Align( p_vout, &i_x, &i_y, i_text_width, i_text_height, i_h_align, i_v_align ) )
1369 /* Set area and print text */
1370 SetBufferArea( p_vout, i_x, i_y, i_text_width, i_text_height );
1371 vout_Print( p_vout->p_default_font, p_vout->p_buffer[ p_vout->i_buffer_index ].p_data +
1372 i_y * p_vout->i_bytes_per_line + i_x * p_vout->i_bytes_per_pixel,
1373 p_vout->i_bytes_per_pixel, p_vout->i_bytes_per_line,
1374 p_vout->i_white_pixel, 0, 0,
1379 /*****************************************************************************
1380 * SetBufferArea: activate an area in current buffer
1381 *****************************************************************************
1382 * This function is called when something is rendered on the current buffer.
1383 * It set the area as active and prepare it to be cleared on next rendering.
1384 * Pay attention to the fact that in this functions, i_h is in fact the end y
1385 * coordinate of the new area.
1386 *****************************************************************************/
1387 static void SetBufferArea( vout_thread_t *p_vout, int i_x, int i_y, int i_w, int i_h )
1389 vout_buffer_t * p_buffer; /* current buffer */
1390 int i_area_begin, i_area_end; /* area vertical extension */
1391 int i_area, i_area_copy; /* area index */
1392 int i_area_shift; /* shift distance for areas */
1394 /* Choose buffer and modify h to end of area position */
1395 p_buffer = &p_vout->p_buffer[ p_vout->i_buffer_index ];
1399 * Remove part of the area which is inside the picture - this is done
1400 * by calling again SetBufferArea with the correct areas dimensions.
1402 if( (i_x >= p_buffer->i_pic_x) && (i_x + i_w <= p_buffer->i_pic_x + p_buffer->i_pic_width) )
1404 i_area_begin = p_buffer->i_pic_y;
1405 i_area_end = i_area_begin + p_buffer->i_pic_height - 1;
1407 if( ((i_y >= i_area_begin) && (i_y <= i_area_end)) ||
1408 ((i_h >= i_area_begin) && (i_h <= i_area_end)) ||
1409 ((i_y < i_area_begin) && (i_h > i_area_end)) )
1411 /* Keep the stripe above the picture, if any */
1412 if( i_y < i_area_begin )
1414 SetBufferArea( p_vout, i_x, i_y, i_w, i_area_begin - i_y );
1416 /* Keep the stripe below the picture, if any */
1417 if( i_h > i_area_end )
1419 SetBufferArea( p_vout, i_x, i_area_end, i_w, i_h - i_area_end );
1425 /* Skip some extensions until interesting areas */
1427 (i_area < p_buffer->i_areas) &&
1428 (p_buffer->pi_area_end[i_area] + 1 <= i_y);
1434 if( i_area == p_buffer->i_areas )
1436 /* New area is below all existing ones: just add it at the end of the
1437 * array, if possible - otherwise, append it to the last one */
1438 if( i_area < VOUT_MAX_AREAS )
1440 p_buffer->pi_area_begin[i_area] = i_y;
1441 p_buffer->pi_area_end[i_area] = i_h;
1442 p_buffer->i_areas++;
1447 intf_DbgMsg("area overflow");
1449 p_buffer->pi_area_end[VOUT_MAX_AREAS - 1] = i_h;
1454 i_area_begin = p_buffer->pi_area_begin[i_area];
1455 i_area_end = p_buffer->pi_area_end[i_area];
1457 if( i_y < i_area_begin )
1459 if( i_h >= i_area_begin - 1 )
1461 /* Extend area above */
1462 p_buffer->pi_area_begin[i_area] = i_y;
1466 /* Create a new area above : merge last area if overflow, then
1467 * move all old areas down */
1468 if( p_buffer->i_areas == VOUT_MAX_AREAS )
1471 intf_DbgMsg("areas overflow");
1473 p_buffer->pi_area_end[VOUT_MAX_AREAS - 2] = p_buffer->pi_area_end[VOUT_MAX_AREAS - 1];
1477 p_buffer->i_areas++;
1479 for( i_area_copy = p_buffer->i_areas - 1; i_area_copy > i_area; i_area_copy-- )
1481 p_buffer->pi_area_begin[i_area_copy] = p_buffer->pi_area_begin[i_area_copy - 1];
1482 p_buffer->pi_area_end[i_area_copy] = p_buffer->pi_area_end[i_area_copy - 1];
1484 p_buffer->pi_area_begin[i_area] = i_y;
1485 p_buffer->pi_area_end[i_area] = i_h;
1489 if( i_h > i_area_end )
1491 /* Find further areas which can be merged with the new one */
1492 for( i_area_copy = i_area + 1;
1493 (i_area_copy < p_buffer->i_areas) &&
1494 (p_buffer->pi_area_begin[i_area] <= i_h);
1501 if( i_area_copy != i_area )
1503 /* Merge with last possible areas */
1504 //p_buffer->pi_area_end[i_area] = MAX( i_h, p_buffer->pi_area_end[i_area_copy] );
1506 /* Shift lower areas upward */
1507 i_area_shift = i_area_copy - i_area;
1508 p_buffer->i_areas -= i_area_shift;
1509 for( i_area_copy = i_area + 1; i_area_copy < p_buffer->i_areas; i_area_copy++ )
1511 p_buffer->pi_area_begin[i_area_copy] = p_buffer->pi_area_begin[i_area_copy + i_area_shift];
1512 p_buffer->pi_area_end[i_area_copy] = p_buffer->pi_area_end[i_area_copy + i_area_shift];
1517 /* Extend area below */
1518 p_buffer->pi_area_end[i_area] = i_h;
1524 /*****************************************************************************
1525 * SetBufferPicture: clear buffer and set picture area
1526 *****************************************************************************
1527 * This function is called before any rendering. It clears the current
1528 * rendering buffer and set the new picture area. If the picture pointer is
1529 * NULL, then no picture area is defined. Floating operations are avoided since
1530 * some MMX calculations may follow.
1531 *****************************************************************************/
1532 static void SetBufferPicture( vout_thread_t *p_vout, picture_t *p_pic )
1534 vout_buffer_t * p_buffer; /* current buffer */
1535 int i_pic_x, i_pic_y; /* picture position */
1536 int i_pic_width, i_pic_height; /* picture dimensions */
1537 int i_old_pic_y, i_old_pic_height; /* old picture area */
1538 int i_vout_width, i_vout_height; /* display dimensions */
1539 int i_area; /* area index */
1540 int i_data_index; /* area data index */
1541 int i_data_size; /* area data size, in 256 bytes blocs */
1542 u64 * p_data; /* area data, for clearing */
1543 byte_t * p_data8; /* area data, for clearing (slow) */
1545 /* Choose buffer and set display dimensions */
1546 p_buffer = &p_vout->p_buffer[ p_vout->i_buffer_index ];
1547 i_vout_width = p_vout->i_width;
1548 i_vout_height = p_vout->i_height;
1551 * Computes new picture size
1555 /* Try horizontal scaling first - width must be a mutiple of 16 */
1556 i_pic_width = (( p_vout->b_scale || (p_pic->i_width > i_vout_width)) ?
1557 i_vout_width : p_pic->i_width) & ~0xf;
1558 switch( p_pic->i_aspect_ratio )
1560 case AR_3_4_PICTURE:
1561 i_pic_height = i_pic_width * 3 / 4;
1563 case AR_16_9_PICTURE:
1564 i_pic_height = i_pic_width * 9 / 16;
1566 case AR_221_1_PICTURE:
1567 i_pic_height = i_pic_width * 100 / 221;
1569 case AR_SQUARE_PICTURE:
1571 i_pic_height = p_pic->i_height * i_pic_width / p_pic->i_width;
1575 /* If picture dimensions using horizontal scaling are too large, use
1576 * vertical scaling. Since width must be a multiple of 16, height is
1577 * adjusted again after. */
1578 if( i_pic_height > i_vout_height )
1580 i_pic_height = ( p_vout->b_scale || (p_pic->i_height > i_vout_height)) ?
1581 i_vout_height : p_pic->i_height;
1582 switch( p_pic->i_aspect_ratio )
1584 case AR_3_4_PICTURE:
1585 i_pic_width = (i_pic_height * 4 / 3) & ~0xf;
1586 i_pic_height = i_pic_width * 3 / 4;
1588 case AR_16_9_PICTURE:
1589 i_pic_width = (i_pic_height * 16 / 9) & ~0xf;
1590 i_pic_height = i_pic_width * 9 / 16;
1592 case AR_221_1_PICTURE:
1593 i_pic_width = (i_pic_height * 221 / 100) & ~0xf;
1594 i_pic_height = i_pic_width * 100 / 221;
1596 case AR_SQUARE_PICTURE:
1598 i_pic_width = (p_pic->i_width * i_pic_height / p_pic->i_height) & ~0xf;
1599 i_pic_height = p_pic->i_height * i_pic_width / p_pic->i_width;
1604 /* Set picture position */
1605 i_pic_x = (p_vout->i_width - i_pic_width) / 2;
1606 i_pic_y = (p_vout->i_height - i_pic_height) / 2;
1611 /* No picture: size is 0 */
1619 * Set new picture size - if it is smaller than the previous one, clear
1620 * around it. Since picture are centered, only their size is tested.
1622 if( (p_buffer->i_pic_width > i_pic_width) || (p_buffer->i_pic_height > i_pic_height) )
1624 i_old_pic_y = p_buffer->i_pic_y;
1625 i_old_pic_height = p_buffer->i_pic_height;
1626 p_buffer->i_pic_x = i_pic_x;
1627 p_buffer->i_pic_y = i_pic_y;
1628 p_buffer->i_pic_width = i_pic_width;
1629 p_buffer->i_pic_height = i_pic_height;
1630 SetBufferArea( p_vout, 0, i_old_pic_y, p_vout->i_width, i_old_pic_height );
1634 p_buffer->i_pic_x = i_pic_x;
1635 p_buffer->i_pic_y = i_pic_y;
1636 p_buffer->i_pic_width = i_pic_width;
1637 p_buffer->i_pic_height = i_pic_height;
1643 for( i_area = 0; i_area < p_buffer->i_areas; i_area++ )
1646 intf_DbgMsg("clearing picture %p area in buffer %d: %d-%d", p_pic,
1647 p_vout->i_buffer_index, p_buffer->pi_area_begin[i_area], p_buffer->pi_area_end[i_area] );
1649 i_data_size = (p_buffer->pi_area_end[i_area] - p_buffer->pi_area_begin[i_area] + 1) * p_vout->i_bytes_per_line;
1650 p_data = (u64*) (p_buffer->p_data + p_vout->i_bytes_per_line * p_buffer->pi_area_begin[i_area]);
1652 for( i_data_index = i_data_size / 256; i_data_index-- ; )
1654 /* Clear 256 bytes block */
1655 *p_data++ = 0; *p_data++ = 0; *p_data++ = 0; *p_data++ = 0;
1656 *p_data++ = 0; *p_data++ = 0; *p_data++ = 0; *p_data++ = 0;
1657 *p_data++ = 0; *p_data++ = 0; *p_data++ = 0; *p_data++ = 0;
1658 *p_data++ = 0; *p_data++ = 0; *p_data++ = 0; *p_data++ = 0;
1659 *p_data++ = 0; *p_data++ = 0; *p_data++ = 0; *p_data++ = 0;
1660 *p_data++ = 0; *p_data++ = 0; *p_data++ = 0; *p_data++ = 0;
1661 *p_data++ = 0; *p_data++ = 0; *p_data++ = 0; *p_data++ = 0;
1662 *p_data++ = 0; *p_data++ = 0; *p_data++ = 0; *p_data++ = 0;
1664 for( i_data_index = (i_data_size % 256) / 16; i_data_index--; )
1666 /* Clear remaining 16 bytes blocks */
1667 *p_data++ = 0; *p_data++ = 0;
1669 p_data8 = (byte_t *)p_data;
1670 for( i_data_index = i_data_size % 16; i_data_index--; )
1672 /* Clear remaining bytes */
1680 p_buffer->i_areas = 0;
1683 /*****************************************************************************
1684 * RenderPicture: render a picture
1685 *****************************************************************************
1686 * This function converts a picture from a video heap to a pixel-encoded image
1687 * and copies it to the current rendering buffer. No lock is required, since
1688 * the * rendered picture has been determined as existant, and will only be
1689 * destroyed by the vout thread later.
1690 *****************************************************************************/
1691 static void RenderPicture( vout_thread_t *p_vout, picture_t *p_pic )
1694 char psz_date[MSTRTIME_MAX_SIZE]; /* picture date */
1695 mtime_t render_time; /* picture rendering time */
1697 vout_buffer_t * p_buffer; /* rendering buffer */
1698 byte_t * p_pic_data; /* convertion destination */
1700 /* Get and set rendering information */
1701 p_buffer = &p_vout->p_buffer[ p_vout->i_buffer_index ];
1702 p_pic_data = p_buffer->p_data +
1703 p_buffer->i_pic_x * p_vout->i_bytes_per_pixel +
1704 p_buffer->i_pic_y * p_vout->i_bytes_per_line;
1706 render_time = mdate();
1712 * Choose appropriate rendering function and render picture
1714 switch( p_pic->i_type )
1716 case YUV_420_PICTURE:
1717 p_vout->yuv.pf_yuv420( p_vout, p_pic_data,
1718 p_pic->p_y, p_pic->p_u, p_pic->p_v,
1719 p_pic->i_width, p_pic->i_height,
1720 p_buffer->i_pic_width, p_buffer->i_pic_height,
1721 p_vout->i_bytes_per_line / p_vout->i_bytes_per_pixel,
1722 p_pic->i_matrix_coefficients );
1724 case YUV_422_PICTURE:
1725 p_vout->yuv.pf_yuv422( p_vout, p_pic_data,
1726 p_pic->p_y, p_pic->p_u, p_pic->p_v,
1727 p_pic->i_width, p_pic->i_height,
1728 p_buffer->i_pic_width, p_buffer->i_pic_height,
1729 p_vout->i_bytes_per_line / p_vout->i_bytes_per_pixel,
1730 p_pic->i_matrix_coefficients );
1732 case YUV_444_PICTURE:
1733 p_vout->yuv.pf_yuv444( p_vout, p_pic_data,
1734 p_pic->p_y, p_pic->p_u, p_pic->p_v,
1735 p_pic->i_width, p_pic->i_height,
1736 p_buffer->i_pic_width, p_buffer->i_pic_height,
1737 p_vout->i_bytes_per_line / p_vout->i_bytes_per_pixel,
1738 p_pic->i_matrix_coefficients );
1742 intf_ErrMsg("error: unknown picture type %d", p_pic->i_type );
1748 /* Print picture date and rendering time */
1749 intf_DbgMsg("picture %p rendered in buffer %d (%ld us), display date: %s", p_pic,
1750 p_vout->i_buffer_index, (long) (mdate() - render_time),
1751 mstrtime( psz_date, p_pic->date ));
1755 /*****************************************************************************
1756 * RenderPictureInfo: print additionnal information on a picture
1757 *****************************************************************************
1758 * This function will print information such as fps and other picture
1759 * dependant information.
1760 *****************************************************************************/
1761 static void RenderPictureInfo( vout_thread_t *p_vout, picture_t *p_pic )
1763 char psz_buffer[256]; /* string buffer */
1766 * Print FPS rate in upper right corner
1768 if( p_vout->c_fps_samples > VOUT_FPS_SAMPLES )
1770 long i_fps = VOUT_FPS_SAMPLES * 1000000 * 10 /
1771 ( p_vout->p_fps_sample[ (p_vout->c_fps_samples - 1)
1772 % VOUT_FPS_SAMPLES ] -
1773 p_vout->p_fps_sample[ p_vout->c_fps_samples
1774 % VOUT_FPS_SAMPLES ] );
1775 sprintf( psz_buffer, "%li.%i fps", i_fps / 10, (int)i_fps % 10 );
1776 Print( p_vout, 0, 0, RIGHT_RALIGN, TOP_RALIGN, psz_buffer );
1780 * Print frames count and loop time in upper left corner
1782 sprintf( psz_buffer, "%ld frames, render: %ldus",
1783 (long) p_vout->c_fps_samples, (long) p_vout->render_time );
1784 Print( p_vout, 0, 0, LEFT_RALIGN, TOP_RALIGN, psz_buffer );
1788 * Print picture information in lower right corner
1790 sprintf( psz_buffer, "%s picture %dx%d (%dx%d%+d%+d %s) -> %dx%d+%d+%d",
1791 (p_pic->i_type == YUV_420_PICTURE) ? "4:2:0" :
1792 ((p_pic->i_type == YUV_422_PICTURE) ? "4:2:2" :
1793 ((p_pic->i_type == YUV_444_PICTURE) ? "4:4:4" : "ukn-type")),
1794 p_pic->i_width, p_pic->i_height,
1795 p_pic->i_display_width, p_pic->i_display_height,
1796 p_pic->i_display_horizontal_offset, p_pic->i_display_vertical_offset,
1797 (p_pic->i_aspect_ratio == AR_SQUARE_PICTURE) ? "sq" :
1798 ((p_pic->i_aspect_ratio == AR_3_4_PICTURE) ? "4:3" :
1799 ((p_pic->i_aspect_ratio == AR_16_9_PICTURE) ? "16:9" :
1800 ((p_pic->i_aspect_ratio == AR_221_1_PICTURE) ? "2.21:1" : "ukn-ar" ))),
1801 p_vout->p_buffer[ p_vout->i_buffer_index ].i_pic_width,
1802 p_vout->p_buffer[ p_vout->i_buffer_index ].i_pic_height,
1803 p_vout->p_buffer[ p_vout->i_buffer_index ].i_pic_x,
1804 p_vout->p_buffer[ p_vout->i_buffer_index ].i_pic_y );
1805 Print( p_vout, 0, 0, RIGHT_RALIGN, BOTTOM_RALIGN, psz_buffer );
1809 /*****************************************************************************
1810 * RenderSplash: render splash picture
1811 *****************************************************************************
1812 * This function will print something on the screen. It will return 0 if
1813 * nothing has been rendered, or 1 if something has been changed on the screen.
1814 * Note that if you absolutely want something to be printed, you will have
1815 * to force it by setting the last idle date to 0.
1816 * Unlike other rendering functions, this one calls the SetBufferPicture
1817 * function when needed.
1818 *****************************************************************************/
1819 int RenderSplash( vout_thread_t *p_vout )
1821 int i_x = 0, i_y = 0; /* text position */
1822 int i_width, i_height; /* text size */
1823 char *psz_text = "VideoLAN Client (" VERSION ")"; /* text to display */
1825 memset( p_vout->p_buffer[ p_vout->i_buffer_index ].p_data,
1826 p_vout->i_bytes_per_line * p_vout->i_height, 12);
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, CENTER_RALIGN, CENTER_RALIGN ) )
1833 vout_Print( p_vout->p_large_font,
1834 p_vout->p_buffer[ p_vout->i_buffer_index ].p_data +
1835 i_x * p_vout->i_bytes_per_pixel + (i_y - 16 ) * p_vout->i_bytes_per_line,
1836 p_vout->i_bytes_per_pixel, p_vout->i_bytes_per_line,
1837 p_vout->i_white_pixel, p_vout->i_gray_pixel, 0,
1838 WIDE_TEXT | OUTLINED_TEXT, psz_text, 100);
1839 SetBufferArea( p_vout, i_x, i_y, i_width, i_height);
1845 /*****************************************************************************
1846 * RenderIdle: render idle picture
1847 *****************************************************************************
1848 * This function will print something on the screen. It will return 0 if
1849 * nothing has been rendered, or 1 if something has been changed on the screen.
1850 * Note that if you absolutely want something to be printed, you will have
1851 * to force it by setting the last idle date to 0.
1852 * Unlike other rendering functions, this one calls the SetBufferPicture
1853 * function when needed.
1854 *****************************************************************************/
1855 int RenderIdle( vout_thread_t *p_vout )
1858 int i_x = 0, i_y = 0; /* text position */
1859 int i_width, i_height; /* text size */
1860 int i_amount = 0; /* amount to draw */
1861 char *psz_text = "Waiting for stream"; /* text to display */
1862 char *psz_wtext = "[................]";
1864 mtime_t current_date; /* current date */
1867 memset( p_vout->p_buffer[ p_vout->i_buffer_index ].p_data,
1868 p_vout->i_bytes_per_line * p_vout->i_height, 12);
1871 current_date = mdate();
1872 if( (current_date - p_vout->last_display_date) > VOUT_IDLE_DELAY
1873 // && (current_date - p_vout->last_idle_date) > VOUT_IDLE_DELAY
1876 /* FIXME: idle screen disabled */
1878 SetBufferPicture( p_vout, NULL );
1879 vout_TextSize( p_vout->p_large_font, WIDE_TEXT | OUTLINED_TEXT, psz_text,
1880 &i_width, &i_height );
1881 if( !Align( p_vout, &i_x, &i_y, i_width, i_height * 2, CENTER_RALIGN, CENTER_RALIGN ) )
1883 i_amount = (int) ((current_date - p_vout->last_display_date ) / 5000LL);
1884 vout_Print( p_vout->p_large_font,
1885 p_vout->p_buffer[ p_vout->i_buffer_index ].p_data +
1886 i_x * p_vout->i_bytes_per_pixel + i_y * p_vout->i_bytes_per_line,
1887 p_vout->i_bytes_per_pixel, p_vout->i_bytes_per_line,
1888 p_vout->i_white_pixel, p_vout->i_gray_pixel, 0,
1889 WIDE_TEXT | OUTLINED_TEXT, psz_text, (i_amount / 3 ) %110);
1891 vout_Print( p_vout->p_large_font,
1892 p_vout->p_buffer[ p_vout->i_buffer_index ].p_data +
1893 i_x * p_vout->i_bytes_per_pixel + (i_y + 16) * p_vout->i_bytes_per_line,
1894 p_vout->i_bytes_per_pixel, p_vout->i_bytes_per_line,
1895 p_vout->i_white_pixel, p_vout->i_gray_pixel, 0,
1896 WIDE_TEXT | OUTLINED_TEXT, psz_wtext, (i_amount/5)%110 );
1899 SetBufferArea( p_vout, i_x, i_y, i_width, i_height * 2 );
1907 /*****************************************************************************
1908 * RenderInfo: render additionnal information
1909 *****************************************************************************
1910 * This function renders information which do not depend on the current
1912 *****************************************************************************/
1913 static void RenderInfo( vout_thread_t *p_vout )
1916 char psz_buffer[256]; /* string buffer */
1917 int i_ready_pic = 0; /* ready pictures */
1918 int i_reserved_pic = 0; /* reserved pictures */
1919 int i_picture; /* picture index */
1924 * Print thread state in lower left corner
1926 for( i_picture = 0; i_picture < VOUT_MAX_PICTURES; i_picture++ )
1928 switch( p_vout->p_picture[i_picture].i_status )
1930 case RESERVED_PICTURE:
1931 case RESERVED_DATED_PICTURE:
1932 case RESERVED_DISP_PICTURE:
1940 sprintf( psz_buffer, "pic: %d (%d/%d)/%d",
1941 p_vout->i_pictures, i_reserved_pic, i_ready_pic, VOUT_MAX_PICTURES );
1942 Print( p_vout, 0, 0, LEFT_RALIGN, BOTTOM_RALIGN, psz_buffer );
1946 /*****************************************************************************
1947 * RenderSubPicture: render a subpicture
1948 *****************************************************************************
1949 * This function renders a sub picture unit.
1950 *****************************************************************************/
1951 static void RenderSubPicture( vout_thread_t *p_vout, subpicture_t *p_subpic )
1953 p_vout_font_t p_font; /* text font */
1954 int i_width, i_height; /* subpicture dimensions */
1955 mtime_t i_date = mdate();
1957 subpicture_t *p_ephemer = NULL;
1958 subpicture_t *p_tmp = p_subpic;
1960 /* Look for the youngest ephemer */
1961 while( p_tmp != NULL )
1963 if( p_tmp->i_type == DVD_SUBPICTURE && p_tmp->b_ephemer
1964 && i_date >= p_tmp->i_start && i_date <= p_tmp->i_stop )
1966 if( p_ephemer == NULL || p_tmp->i_start < p_ephemer->i_start )
1972 p_tmp = p_tmp->p_next;
1975 /* If we found an ephemer, kill it if we find a more recent one */
1976 if( p_ephemer != NULL )
1980 while( p_tmp != NULL )
1982 if( p_tmp->i_type == DVD_SUBPICTURE
1983 && i_date >= p_tmp->i_start && i_date >= p_tmp->i_start
1984 && p_tmp != p_ephemer && p_tmp->i_start > p_ephemer->i_start )
1986 p_ephemer->i_stop = 0;
1989 p_tmp = p_tmp->p_next;
1993 while( p_subpic != NULL )
1995 switch( p_subpic->i_type )
1997 case DVD_SUBPICTURE: /* DVD subpicture unit */
1998 /* test if the picture really has to be displayed */
1999 if( i_date < p_subpic->i_start )
2001 /* not yet, see you later */
2004 if( i_date > p_subpic->i_stop )
2006 /* too late, destroying the subpic */
2007 vout_DestroySubPicture( p_vout, p_subpic );
2010 vout_RenderSPU( &p_vout->p_buffer[ p_vout->i_buffer_index ],
2011 p_subpic, p_vout->i_bytes_per_pixel,
2012 p_vout->i_bytes_per_line );
2015 case TEXT_SUBPICTURE: /* single line text */
2016 /* Select default font if not specified */
2017 p_font = p_subpic->type.text.p_font;
2018 if( p_font == NULL )
2020 p_font = p_vout->p_default_font;
2023 /* Compute text size (width and height fields are ignored)
2025 vout_TextSize( p_font, p_subpic->type.text.i_style,
2026 p_subpic->p_data, &i_width, &i_height );
2027 if( !Align( p_vout, &p_subpic->i_x, &p_subpic->i_y,
2028 i_width, i_height, p_subpic->i_horizontal_align,
2029 p_subpic->i_vertical_align ) )
2032 p_vout->p_buffer[ p_vout->i_buffer_index ].p_data +
2033 p_subpic->i_x * p_vout->i_bytes_per_pixel +
2034 p_subpic->i_y * p_vout->i_bytes_per_line,
2035 p_vout->i_bytes_per_pixel, p_vout->i_bytes_per_line,
2036 p_subpic->type.text.i_char_color,
2037 p_subpic->type.text.i_border_color,
2038 p_subpic->type.text.i_bg_color,
2039 p_subpic->type.text.i_style, p_subpic->p_data, 100 );
2040 SetBufferArea( p_vout, p_subpic->i_x, p_subpic->i_y,
2041 i_width, i_height );
2047 intf_ErrMsg( "error: unknown subpicture %p type %d",
2048 p_subpic, p_subpic->i_type );
2053 p_subpic = p_subpic->p_next;
2057 /*****************************************************************************
2058 * RenderInterface: render the interface
2059 *****************************************************************************
2060 * This function renders the interface, if any.
2061 *****************************************************************************/
2062 static void RenderInterface( vout_thread_t *p_vout )
2064 int i_height, i_text_height; /* total and text height */
2065 int i_width_1, i_width_2; /* text width */
2066 int i_byte; /* byte index */
2067 const char *psz_text_1 = "[1-9] Channel [i]nfo [c]olor [g/G]amma";
2068 const char *psz_text_2 = "[+/-] Volume [m]ute [s]caling [Q]uit";
2071 vout_TextSize( p_vout->p_large_font, OUTLINED_TEXT, psz_text_1, &i_width_1, &i_height );
2072 vout_TextSize( p_vout->p_large_font, OUTLINED_TEXT, psz_text_2, &i_width_2, &i_text_height );
2073 i_height += i_text_height;
2075 /* Render background */
2076 for( i_byte = (p_vout->i_height - i_height) * p_vout->i_bytes_per_line;
2077 i_byte < p_vout->i_height * p_vout->i_bytes_per_line;
2081 p_vout->p_buffer[ p_vout->i_buffer_index ].p_data[ i_byte ] = p_vout->i_blue_pixel;
2084 /* Render text, if not larger than screen */
2085 if( i_width_1 < p_vout->i_width )
2087 vout_Print( p_vout->p_large_font, p_vout->p_buffer[ p_vout->i_buffer_index ].p_data +
2088 (p_vout->i_height - i_height) * p_vout->i_bytes_per_line,
2089 p_vout->i_bytes_per_pixel, p_vout->i_bytes_per_line,
2090 p_vout->i_white_pixel, p_vout->i_black_pixel, 0,
2091 OUTLINED_TEXT, psz_text_1, 100 );
2093 if( i_width_2 < p_vout->i_width )
2095 vout_Print( p_vout->p_large_font, p_vout->p_buffer[ p_vout->i_buffer_index ].p_data +
2096 (p_vout->i_height - i_height + i_text_height) * p_vout->i_bytes_per_line,
2097 p_vout->i_bytes_per_pixel, p_vout->i_bytes_per_line,
2098 p_vout->i_white_pixel, p_vout->i_black_pixel, 0,
2099 OUTLINED_TEXT, psz_text_2, 100 );
2102 /* Activate modified area */
2103 SetBufferArea( p_vout, 0, p_vout->i_height - i_height, p_vout->i_width, i_height );
2106 /*****************************************************************************
2107 * Manage: manage thread
2108 *****************************************************************************
2109 * This function will handle changes in thread configuration.
2110 *****************************************************************************/
2111 static int Manage( vout_thread_t *p_vout )
2114 if( p_vout->i_changes )
2116 intf_DbgMsg("changes: 0x%x (no display: 0x%x)", p_vout->i_changes,
2117 0 /* p_vout->i_changes & VOUT_NODISPLAY_CHANGE */ );
2121 /* On gamma or grayscale change, rebuild tables */
2122 if( p_vout->i_changes & (VOUT_GAMMA_CHANGE | VOUT_GRAYSCALE_CHANGE |
2125 if( vout_ResetYUV( p_vout ) )
2127 intf_ErrMsg( "vout error: can't rebuild conversion tables" );
2132 /* Clear changes flags which does not need management or have been
2134 p_vout->i_changes &= ~(VOUT_GAMMA_CHANGE | VOUT_GRAYSCALE_CHANGE |
2135 VOUT_YUV_CHANGE | VOUT_INFO_CHANGE |
2136 VOUT_INTF_CHANGE | VOUT_SCALE_CHANGE |
2137 VOUT_CURSOR_CHANGE | VOUT_FULLSCREEN_CHANGE );
2139 /* Detect unauthorized changes */
2140 if( p_vout->i_changes )
2142 /* Some changes were not acknowledged by p_vout->pf_manage or this
2143 * function, it means they should not be authorized */
2144 intf_ErrMsg( "vout error: unauthorized changes in the vout thread" );
2151 /*****************************************************************************
2152 * Align: align a subpicture in the screen
2153 *****************************************************************************
2154 * This function is used for rendering text or subpictures. It returns non 0
2155 * it the final aera is not fully included in display area. Return coordinates
2157 *****************************************************************************/
2158 static int Align( vout_thread_t *p_vout, int *pi_x, int *pi_y,
2159 int i_width, int i_height, int i_h_align, int i_v_align )
2161 /* Align horizontally */
2165 *pi_x -= i_width / 2;
2168 *pi_x += (p_vout->i_width - i_width) / 2;
2174 *pi_x += p_vout->i_width - i_width;
2178 /* Align vertically */
2182 *pi_y -= i_height / 2;
2185 *pi_y += (p_vout->i_height - i_height) / 2;
2191 *pi_y += p_vout->i_height - i_height;
2193 case SUBTITLE_RALIGN:
2194 *pi_y += (p_vout->i_height + p_vout->p_buffer[ p_vout->i_buffer_index ].i_pic_y +
2195 p_vout->p_buffer[ p_vout->i_buffer_index ].i_pic_height - i_height) / 2;
2199 /* Return non 0 if clipping failed */
2200 return( (*pi_x < 0) || (*pi_y < 0) ||
2201 (*pi_x + i_width > p_vout->i_width) || (*pi_y + i_height > p_vout->i_height) );
2204 /*****************************************************************************
2205 * SetPalette: sets an 8 bpp palette
2206 *****************************************************************************
2207 * This function is just a prototype that does nothing. Architectures that
2208 * support palette allocation should override it.
2209 *****************************************************************************/
2210 static void SetPalette ( p_vout_thread_t p_vout, u16 *red,
2211 u16 *green, u16 *blue, u16 *transp )
2213 intf_ErrMsg( "vout error: method does not support palette changing" );