1 /*****************************************************************************
2 * video_output.c : video output thread
3 * This module describes the programming interface for video output threads.
4 * It includes functions allowing to open a new thread, send pictures to a
5 * thread, and destroy a previously oppened video output thread.
6 *****************************************************************************
7 * Copyright (C) 2000 VideoLAN
11 * This program is free software; you can redistribute it and/or modify
12 * it under the terms of the GNU General Public License as published by
13 * the Free Software Foundation; either version 2 of the License, or
14 * (at your option) any later version.
16 * This program is distributed in the hope that it will be useful,
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 * GNU General Public License for more details.
21 * You should have received a copy of the GNU General Public License
22 * along with this program; if not, write to the Free Software
23 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111, USA.
24 *****************************************************************************/
26 /*****************************************************************************
28 *****************************************************************************/
31 #include <errno.h> /* ENOMEM */
32 #include <stdlib.h> /* free() */
33 #include <stdio.h> /* sprintf() */
34 #include <string.h> /* strerror() */
37 # include <sys/times.h>
46 #include "video_output.h"
47 #include "video_text.h"
48 #include "video_spu.h"
49 #include "video_yuv.h"
54 /*****************************************************************************
56 *****************************************************************************/
57 static int BinaryLog ( u32 i );
58 static void MaskToShift ( int *pi_left, int *pi_right, u32 i_mask );
59 static int InitThread ( vout_thread_t *p_vout );
60 static void RunThread ( vout_thread_t *p_vout );
61 static void ErrorThread ( vout_thread_t *p_vout );
62 static void EndThread ( vout_thread_t *p_vout );
63 static void DestroyThread ( vout_thread_t *p_vout, int i_status );
64 static void Print ( vout_thread_t *p_vout, int i_x, int i_y,
65 int i_h_align, int i_v_align,
66 unsigned char *psz_text );
67 static void SetBufferArea ( vout_thread_t *p_vout, int i_x, int i_y,
69 static void SetBufferPicture ( vout_thread_t *p_vout, picture_t *p_pic );
70 static void RenderPicture ( vout_thread_t *p_vout, picture_t *p_pic );
71 static void RenderPictureInfo ( vout_thread_t *p_vout, picture_t *p_pic );
72 static void RenderSubPicture ( vout_thread_t *p_vout,
73 subpicture_t *p_subpic );
74 static void RenderInterface ( vout_thread_t *p_vout );
75 static int RenderIdle ( vout_thread_t *p_vout );
76 static int RenderSplash ( vout_thread_t *p_vout );
77 static void RenderInfo ( vout_thread_t *p_vout );
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 */
104 p_vout = (vout_thread_t *) malloc( sizeof(vout_thread_t) );
107 intf_ErrMsg( "vout error: %s", strerror(ENOMEM) );
111 p_vout->p_set_palette = SetPalette;
113 /* Get a suitable video plugin */
114 for( i_index = 0 ; i_index < p_main->p_bank->i_plugin_count ; i_index++ )
116 /* If there's a plugin in p_info ... */
117 if( p_main->p_bank->p_info[ i_index ] != NULL )
119 /* ... and if this plugin provides the functions we want ... */
120 if( p_main->p_bank->p_info[ i_index ]->vout_GetPlugin != NULL )
122 /* ... and if this plugin has a good score ... */
123 if( p_main->p_bank->p_info[ i_index ]->i_score > i_best_score )
125 /* ... then take it */
126 i_best_score = p_main->p_bank->p_info[ i_index ]->i_score;
127 i_best_index = i_index;
133 if( i_best_score == 0 )
139 /* Get the plugin functions */
140 ( (vout_getplugin_t *)
141 p_main->p_bank->p_info[ i_best_index ]->vout_GetPlugin )( p_vout );
143 /* Initialize thread properties - thread id and locks will be initialized
147 p_vout->b_active = 0;
148 p_vout->pi_status = (pi_status != NULL) ? pi_status : &i_status;
149 *p_vout->pi_status = THREAD_CREATE;
151 /* Initialize some fields used by the system-dependant method - these
152 * fields will probably be modified by the method, and are only
154 p_vout->i_changes = 0;
155 p_vout->i_width = i_width;
156 p_vout->i_height = i_height;
157 p_vout->i_bytes_per_line = i_width * 2;
158 p_vout->i_screen_depth = 15;
159 p_vout->i_bytes_per_pixel = 2;
160 p_vout->f_gamma = VOUT_GAMMA;
161 p_vout->b_need_render = 1;
163 p_vout->b_grayscale = main_GetIntVariable( VOUT_GRAYSCALE_VAR,
164 VOUT_GRAYSCALE_DEFAULT );
166 p_vout->b_interface = 0;
169 intf_DbgMsg( "wished configuration: %dx%d, %d/%d bpp (%d Bpl)",
170 p_vout->i_width, p_vout->i_height, p_vout->i_screen_depth,
171 p_vout->i_bytes_per_pixel * 8, p_vout->i_bytes_per_line );
173 /* Initialize idle screen */
174 p_vout->last_display_date = 0;
175 p_vout->last_idle_date = 0;
176 p_vout->init_display_date = mdate();
177 p_vout->render_time = 10000;
179 /* Initialize statistics fields */
180 p_vout->c_fps_samples = 0;
182 /* Initialize buffer index */
183 p_vout->i_buffer_index = 0;
185 /* Initialize pictures and subpictures - translation tables and functions
186 * will be initialized later in InitThread */
187 for( i_index = 0; i_index < VOUT_MAX_PICTURES; i_index++)
189 p_vout->p_picture[i_index].i_type = EMPTY_PICTURE;
190 p_vout->p_picture[i_index].i_status = FREE_PICTURE;
192 for( i_index = 0; i_index < VOUT_MAX_SUBPICTURES; i_index++)
194 p_vout->p_subpicture[i_index].i_type = EMPTY_SUBPICTURE;
195 p_vout->p_subpicture[i_index].i_status= FREE_SUBPICTURE;
197 p_vout->i_pictures = 0;
199 /* Create and initialize system-dependant method - this function issues its
200 * own error messages */
201 if( p_vout->p_sys_create( p_vout, psz_display, i_root_window, p_data ) )
206 intf_DbgMsg( "actual configuration: %dx%d, %d/%d bpp (%d Bpl), "
207 "masks: 0x%x/0x%x/0x%x",
208 p_vout->i_width, p_vout->i_height, p_vout->i_screen_depth,
209 p_vout->i_bytes_per_pixel * 8, p_vout->i_bytes_per_line,
210 p_vout->i_red_mask, p_vout->i_green_mask,
211 p_vout->i_blue_mask );
213 /* Calculate shifts from system-updated masks */
214 MaskToShift( &p_vout->i_red_lshift, &p_vout->i_red_rshift,
215 p_vout->i_red_mask );
216 MaskToShift( &p_vout->i_green_lshift, &p_vout->i_green_rshift,
217 p_vout->i_green_mask );
218 MaskToShift( &p_vout->i_blue_lshift, &p_vout->i_blue_rshift,
219 p_vout->i_blue_mask );
221 /* Set some useful colors */
222 p_vout->i_white_pixel = RGB2PIXEL( p_vout, 255, 255, 255 );
223 p_vout->i_black_pixel = RGB2PIXEL( p_vout, 0, 0, 0 );
224 p_vout->i_gray_pixel = RGB2PIXEL( p_vout, 128, 128, 128 );
225 p_vout->i_blue_pixel = RGB2PIXEL( p_vout, 0, 0, 50 );
227 /* Load fonts - fonts must be initialized after the system method since
228 * they may be dependant on screen depth and other thread properties */
229 p_vout->p_default_font = vout_LoadFont( DATA_PATH "/" VOUT_DEFAULT_FONT );
230 if( p_vout->p_default_font == NULL )
232 p_vout->p_default_font = vout_LoadFont( "share/" VOUT_DEFAULT_FONT );
234 if( p_vout->p_default_font == NULL )
236 intf_ErrMsg( "vout error: could not load default font" );
237 p_vout->p_sys_destroy( p_vout );
241 p_vout->p_large_font = vout_LoadFont( DATA_PATH "/" VOUT_LARGE_FONT );
242 if( p_vout->p_large_font == NULL )
244 p_vout->p_large_font = vout_LoadFont( "share/" VOUT_LARGE_FONT );
246 if( p_vout->p_large_font == NULL )
248 intf_ErrMsg( "vout error: could not load large font" );
249 vout_UnloadFont( p_vout->p_default_font );
250 p_vout->p_sys_destroy( p_vout );
255 /* Create thread and set locks */
256 vlc_mutex_init( &p_vout->picture_lock );
257 vlc_mutex_init( &p_vout->subpicture_lock );
258 vlc_mutex_init( &p_vout->change_lock );
259 vlc_mutex_lock( &p_vout->change_lock );
260 if( vlc_thread_create( &p_vout->thread_id, "video output",
261 (void *) RunThread, (void *) p_vout) )
263 intf_ErrMsg("vout error: %s", strerror(ENOMEM));
264 vout_UnloadFont( p_vout->p_default_font );
265 vout_UnloadFont( p_vout->p_large_font );
266 p_vout->p_sys_destroy( p_vout );
271 intf_Msg( "Video display initialized (%dx%d, %d/%d bpp)", p_vout->i_width,
272 p_vout->i_height, p_vout->i_screen_depth,
273 p_vout->i_bytes_per_pixel * 8 );
275 /* If status is NULL, wait until the thread is created */
276 if( pi_status == NULL )
280 msleep( THREAD_SLEEP );
281 }while( (i_status != THREAD_READY) && (i_status != THREAD_ERROR)
282 && (i_status != THREAD_FATAL) );
283 if( i_status != THREAD_READY )
291 /*****************************************************************************
292 * vout_DestroyThread: destroys a previously created thread
293 *****************************************************************************
294 * Destroy a terminated thread.
295 * The function will request a destruction of the specified thread. If pi_error
296 * is NULL, it will return once the thread is destroyed. Else, it will be
297 * update using one of the THREAD_* constants.
298 *****************************************************************************/
299 void vout_DestroyThread( vout_thread_t *p_vout, int *pi_status )
301 int i_status; /* thread status */
305 p_vout->pi_status = (pi_status != NULL) ? pi_status : &i_status;
306 *p_vout->pi_status = THREAD_DESTROY;
308 /* Request thread destruction */
311 /* If status is NULL, wait until thread has been destroyed */
312 if( pi_status == NULL )
316 msleep( THREAD_SLEEP );
317 }while( (i_status != THREAD_OVER) && (i_status != THREAD_ERROR)
318 && (i_status != THREAD_FATAL) );
322 /*****************************************************************************
323 * vout_DisplaySubPicture: display a subpicture unit
324 *****************************************************************************
325 * Remove the reservation flag of an subpicture, which will cause it to be ready
326 * for display. The picture does not need to be locked, since it is ignored by
327 * the output thread if is reserved.
328 *****************************************************************************/
329 void vout_DisplaySubPicture( vout_thread_t *p_vout, subpicture_t *p_subpic )
332 char psz_begin_date[MSTRTIME_MAX_SIZE]; /* buffer for date string */
333 char psz_end_date[MSTRTIME_MAX_SIZE]; /* buffer for date string */
337 /* Check if status is valid */
338 if( p_subpic->i_status != RESERVED_SUBPICTURE )
340 intf_DbgMsg("error: subpicture %p has invalid status %d", p_subpic,
341 p_subpic->i_status );
345 /* Remove reservation flag */
346 p_subpic->i_status = READY_SUBPICTURE;
349 /* Send subpicture information */
350 intf_DbgMsg("subpicture %p: type=%d, begin date=%s, end date=%s",
351 p_subpic, p_subpic->i_type,
352 mstrtime( psz_begin_date, p_subpic->begin_date ),
353 mstrtime( psz_end_date, p_subpic->end_date ) );
357 /*****************************************************************************
358 * vout_CreateSubPicture: allocate a subpicture in the video output heap.
359 *****************************************************************************
360 * This function create a reserved subpicture in the video output heap.
361 * A null pointer is returned if the function fails. This method provides an
362 * already allocated zone of memory in the spu data fields. It needs locking
363 * since several pictures can be created by several producers threads.
364 *****************************************************************************/
365 subpicture_t *vout_CreateSubPicture( vout_thread_t *p_vout, int i_type,
368 int i_subpic; /* subpicture index */
369 subpicture_t * p_free_subpic = NULL; /* first free subpicture */
370 subpicture_t * p_destroyed_subpic = NULL; /* first destroyed subpic */
373 vlc_mutex_lock( &p_vout->subpicture_lock );
376 * Look for an empty place
378 for( i_subpic = 0; i_subpic < VOUT_MAX_SUBPICTURES; i_subpic++ )
380 if( p_vout->p_subpicture[i_subpic].i_status == DESTROYED_SUBPICTURE )
382 /* Subpicture is marked for destruction, but is still allocated */
383 if( (p_vout->p_subpicture[i_subpic].i_type == i_type) &&
384 (p_vout->p_subpicture[i_subpic].i_size >= i_size) )
386 /* Memory size do match or is smaller : memory will not be
387 * reallocated, and function can end immediately - this is
388 * the best possible case, since no memory allocation needs
390 p_vout->p_subpicture[i_subpic].i_status = RESERVED_SUBPICTURE;
392 intf_DbgMsg("subpicture %p (in destroyed subpicture slot)",
393 &p_vout->p_subpicture[i_subpic] );
395 vlc_mutex_unlock( &p_vout->subpicture_lock );
396 return( &p_vout->p_subpicture[i_subpic] );
398 else if( p_destroyed_subpic == NULL )
400 /* Memory size do not match, but subpicture index will be kept in
401 * case no other place are left */
402 p_destroyed_subpic = &p_vout->p_subpicture[i_subpic];
405 else if( (p_free_subpic == NULL) &&
406 (p_vout->p_subpicture[i_subpic].i_status == FREE_SUBPICTURE ))
408 /* Subpicture is empty and ready for allocation */
409 p_free_subpic = &p_vout->p_subpicture[i_subpic];
413 /* If no free subpictures are available, use a destroyed subpicture */
414 if( (p_free_subpic == NULL) && (p_destroyed_subpic != NULL ) )
416 /* No free subpicture or matching destroyed subpictures have been
417 * found, but a destroyed subpicture is still avalaible */
418 free( p_destroyed_subpic->p_data );
419 p_free_subpic = p_destroyed_subpic;
425 if( p_free_subpic != NULL )
427 /* Allocate memory */
430 case TEXT_SUBPICTURE: /* text subpicture */
431 p_free_subpic->p_data = malloc( i_size + 1 );
433 case DVD_SUBPICTURE: /* DVD subpicture unit */
434 p_free_subpic->p_data = malloc( i_size );
438 intf_DbgMsg("error: unknown subpicture type %d", i_type );
439 p_free_subpic->p_data = NULL;
444 if( p_free_subpic->p_data != NULL )
446 /* Copy subpicture information, set some default values */
447 p_free_subpic->i_type = i_type;
448 p_free_subpic->i_status = RESERVED_SUBPICTURE;
449 p_free_subpic->i_size = i_size;
450 p_free_subpic->i_x = 0;
451 p_free_subpic->i_y = 0;
452 p_free_subpic->i_width = 0;
453 p_free_subpic->i_height = 0;
454 p_free_subpic->i_horizontal_align = CENTER_RALIGN;
455 p_free_subpic->i_vertical_align = CENTER_RALIGN;
459 /* Memory allocation failed : set subpicture as empty */
460 p_free_subpic->i_type = EMPTY_SUBPICTURE;
461 p_free_subpic->i_status = FREE_SUBPICTURE;
462 p_free_subpic = NULL;
463 intf_ErrMsg("spu warning: %s", strerror( ENOMEM ) );
467 intf_DbgMsg("subpicture %p (in free subpicture slot)", p_free_subpic );
469 vlc_mutex_unlock( &p_vout->subpicture_lock );
470 return( p_free_subpic );
473 /* No free or destroyed subpicture could be found */
474 intf_DbgMsg( "warning: subpicture heap is full" );
475 vlc_mutex_unlock( &p_vout->subpicture_lock );
479 /*****************************************************************************
480 * vout_DestroySubPicture: remove a subpicture from the heap
481 *****************************************************************************
482 * This function frees a previously reserved subpicture.
483 * It is meant to be used when the construction of a picture aborted.
484 * This function does not need locking since reserved subpictures are ignored
485 * by the output thread.
486 *****************************************************************************/
487 void vout_DestroySubPicture( vout_thread_t *p_vout, subpicture_t *p_subpic )
490 /* Check if status is valid */
491 if( p_subpic->i_status != RESERVED_SUBPICTURE )
493 intf_DbgMsg("error: subpicture %p has invalid status %d",
494 p_subpic, p_subpic->i_status );
498 p_subpic->i_status = DESTROYED_SUBPICTURE;
501 intf_DbgMsg("subpicture %p", p_subpic);
505 /*****************************************************************************
506 * vout_DisplayPicture: display a picture
507 *****************************************************************************
508 * Remove the reservation flag of a picture, which will cause it to be ready for
509 * display. The picture won't be displayed until vout_DatePicture has been
511 *****************************************************************************/
512 void vout_DisplayPicture( vout_thread_t *p_vout, picture_t *p_pic )
514 vlc_mutex_lock( &p_vout->picture_lock );
515 switch( p_pic->i_status )
517 case RESERVED_PICTURE:
518 p_pic->i_status = RESERVED_DISP_PICTURE;
520 case RESERVED_DATED_PICTURE:
521 p_pic->i_status = READY_PICTURE;
525 intf_DbgMsg("error: picture %p has invalid status %d", p_pic, p_pic->i_status );
531 intf_DbgMsg("picture %p", p_pic);
533 vlc_mutex_unlock( &p_vout->picture_lock );
536 /*****************************************************************************
537 * vout_DatePicture: date a picture
538 *****************************************************************************
539 * Remove the reservation flag of a picture, which will cause it to be ready for
540 * display. The picture won't be displayed until vout_DisplayPicture has been
542 *****************************************************************************/
543 void vout_DatePicture( vout_thread_t *p_vout, picture_t *p_pic, mtime_t date )
546 char psz_date[MSTRTIME_MAX_SIZE]; /* date */
549 vlc_mutex_lock( &p_vout->picture_lock );
551 switch( p_pic->i_status )
553 case RESERVED_PICTURE:
554 p_pic->i_status = RESERVED_DATED_PICTURE;
556 case RESERVED_DISP_PICTURE:
557 p_pic->i_status = READY_PICTURE;
561 intf_DbgMsg("error: picture %p has invalid status %d", p_pic, p_pic->i_status );
567 intf_DbgMsg("picture %p, display date: %s", p_pic, mstrtime( psz_date, p_pic->date) );
569 vlc_mutex_unlock( &p_vout->picture_lock );
572 /*****************************************************************************
573 * vout_CreatePicture: allocate a picture in the video output heap.
574 *****************************************************************************
575 * This function create a reserved image in the video output heap.
576 * A null pointer is returned if the function fails. This method provides an
577 * already allocated zone of memory in the picture data fields. It needs locking
578 * since several pictures can be created by several producers threads.
579 *****************************************************************************/
580 picture_t *vout_CreatePicture( vout_thread_t *p_vout, int i_type,
581 int i_width, int i_height )
583 int i_picture; /* picture index */
584 int i_chroma_width = 0; /* chroma width */
585 picture_t * p_free_picture = NULL; /* first free picture */
586 picture_t * p_destroyed_picture = NULL; /* first destroyed picture */
589 vlc_mutex_lock( &p_vout->picture_lock );
592 * Look for an empty place
594 for( i_picture = 0; i_picture < VOUT_MAX_PICTURES; i_picture++ )
596 if( p_vout->p_picture[i_picture].i_status == DESTROYED_PICTURE )
598 /* Picture is marked for destruction, but is still allocated - note
599 * that if width and type are the same for two pictures, chroma_width
600 * should also be the same */
601 if( (p_vout->p_picture[i_picture].i_type == i_type) &&
602 (p_vout->p_picture[i_picture].i_height == i_height) &&
603 (p_vout->p_picture[i_picture].i_width == i_width) )
605 /* Memory size do match : memory will not be reallocated, and function
606 * can end immediately - this is the best possible case, since no
607 * memory allocation needs to be done */
608 p_vout->p_picture[i_picture].i_status = RESERVED_PICTURE;
609 p_vout->i_pictures++;
611 intf_DbgMsg("picture %p (in destroyed picture slot)",
612 &p_vout->p_picture[i_picture] );
614 vlc_mutex_unlock( &p_vout->picture_lock );
615 return( &p_vout->p_picture[i_picture] );
617 else if( p_destroyed_picture == NULL )
619 /* Memory size do not match, but picture index will be kept in
620 * case no other place are left */
621 p_destroyed_picture = &p_vout->p_picture[i_picture];
624 else if( (p_free_picture == NULL) &&
625 (p_vout->p_picture[i_picture].i_status == FREE_PICTURE ))
627 /* Picture is empty and ready for allocation */
628 p_free_picture = &p_vout->p_picture[i_picture];
632 /* If no free picture is available, use a destroyed picture */
633 if( (p_free_picture == NULL) && (p_destroyed_picture != NULL ) )
635 /* No free picture or matching destroyed picture has been found, but
636 * a destroyed picture is still avalaible */
637 free( p_destroyed_picture->p_data );
638 p_free_picture = p_destroyed_picture;
644 if( p_free_picture != NULL )
646 /* Allocate memory */
649 case YUV_420_PICTURE: /* YUV 420: 1,1/4,1/4 samples per pixel */
650 i_chroma_width = i_width / 2;
651 p_free_picture->p_data = malloc( i_height * i_chroma_width * 3 * sizeof( yuv_data_t ) );
652 p_free_picture->p_y = (yuv_data_t *)p_free_picture->p_data;
653 p_free_picture->p_u = (yuv_data_t *)p_free_picture->p_data +i_height*i_chroma_width*4/2;
654 p_free_picture->p_v = (yuv_data_t *)p_free_picture->p_data +i_height*i_chroma_width*5/2;
656 case YUV_422_PICTURE: /* YUV 422: 1,1/2,1/2 samples per pixel */
657 i_chroma_width = i_width / 2;
658 p_free_picture->p_data = malloc( i_height * i_chroma_width * 4 * sizeof( yuv_data_t ) );
659 p_free_picture->p_y = (yuv_data_t *)p_free_picture->p_data;
660 p_free_picture->p_u = (yuv_data_t *)p_free_picture->p_data +i_height*i_chroma_width*2;
661 p_free_picture->p_v = (yuv_data_t *)p_free_picture->p_data +i_height*i_chroma_width*3;
663 case YUV_444_PICTURE: /* YUV 444: 1,1,1 samples per pixel */
664 i_chroma_width = i_width;
665 p_free_picture->p_data = malloc( i_height * i_chroma_width * 3 * sizeof( yuv_data_t ) );
666 p_free_picture->p_y = (yuv_data_t *)p_free_picture->p_data;
667 p_free_picture->p_u = (yuv_data_t *)p_free_picture->p_data +i_height*i_chroma_width;
668 p_free_picture->p_v = (yuv_data_t *)p_free_picture->p_data +i_height*i_chroma_width*2;
672 intf_DbgMsg("error: unknown picture type %d", i_type );
673 p_free_picture->p_data = NULL;
678 if( p_free_picture->p_data != NULL )
680 /* Copy picture information, set some default values */
681 p_free_picture->i_type = i_type;
682 p_free_picture->i_status = RESERVED_PICTURE;
683 p_free_picture->i_matrix_coefficients = 1;
684 p_free_picture->i_width = i_width;
685 p_free_picture->i_height = i_height;
686 p_free_picture->i_chroma_width = i_chroma_width;
687 p_free_picture->i_display_horizontal_offset = 0;
688 p_free_picture->i_display_vertical_offset = 0;
689 p_free_picture->i_display_width = i_width;
690 p_free_picture->i_display_height = i_height;
691 p_free_picture->i_aspect_ratio = AR_SQUARE_PICTURE;
692 p_free_picture->i_refcount = 0;
693 p_vout->i_pictures++;
697 /* Memory allocation failed : set picture as empty */
698 p_free_picture->i_type = EMPTY_PICTURE;
699 p_free_picture->i_status = FREE_PICTURE;
700 p_free_picture = NULL;
701 intf_ErrMsg( "vout warning: %s", strerror( ENOMEM ) );
705 intf_DbgMsg("picture %p (in free picture slot)", p_free_picture );
707 vlc_mutex_unlock( &p_vout->picture_lock );
708 return( p_free_picture );
711 /* No free or destroyed picture could be found */
712 intf_DbgMsg( "warning: picture heap is full" );
713 vlc_mutex_unlock( &p_vout->picture_lock );
717 /*****************************************************************************
718 * vout_DestroyPicture: remove a permanent or reserved picture from the heap
719 *****************************************************************************
720 * This function frees a previously reserved picture or a permanent
721 * picture. It is meant to be used when the construction of a picture aborted.
722 * Note that the picture will be destroyed even if it is linked !
723 *****************************************************************************/
724 void vout_DestroyPicture( vout_thread_t *p_vout, picture_t *p_pic )
726 vlc_mutex_lock( &p_vout->picture_lock );
729 /* Check if picture status is valid */
730 if( (p_pic->i_status != RESERVED_PICTURE) &&
731 (p_pic->i_status != RESERVED_DATED_PICTURE) &&
732 (p_pic->i_status != RESERVED_DISP_PICTURE) )
734 intf_DbgMsg("error: picture %p has invalid status %d", p_pic, p_pic->i_status );
738 p_pic->i_status = DESTROYED_PICTURE;
739 p_vout->i_pictures--;
742 intf_DbgMsg("picture %p", p_pic);
744 vlc_mutex_unlock( &p_vout->picture_lock );
747 /*****************************************************************************
748 * vout_LinkPicture: increment reference counter of a picture
749 *****************************************************************************
750 * This function increment the reference counter of a picture in the video
751 * heap. It needs a lock since several producer threads can access the picture.
752 *****************************************************************************/
753 void vout_LinkPicture( vout_thread_t *p_vout, picture_t *p_pic )
755 vlc_mutex_lock( &p_vout->picture_lock );
759 intf_DbgMsg("picture %p refcount=%d", p_pic, p_pic->i_refcount );
762 vlc_mutex_unlock( &p_vout->picture_lock );
765 /*****************************************************************************
766 * vout_UnlinkPicture: decrement reference counter of a picture
767 *****************************************************************************
768 * This function decrement the reference counter of a picture in the video heap.
769 *****************************************************************************/
770 void vout_UnlinkPicture( vout_thread_t *p_vout, picture_t *p_pic )
772 vlc_mutex_lock( &p_vout->picture_lock );
776 if( p_pic->i_refcount < 0 )
778 intf_DbgMsg("error: refcount < 0");
779 p_pic->i_refcount = 0;
783 if( (p_pic->i_refcount == 0) && (p_pic->i_status == DISPLAYED_PICTURE) )
785 p_pic->i_status = DESTROYED_PICTURE;
786 p_vout->i_pictures--;
790 intf_DbgMsg("picture %p refcount=%d", p_pic, p_pic->i_refcount );
793 vlc_mutex_unlock( &p_vout->picture_lock );
796 /*****************************************************************************
797 * vout_SetBuffers: set buffers adresses
798 *****************************************************************************
799 * This function is called by system drivers to set buffers video memory
801 *****************************************************************************/
802 void vout_SetBuffers( vout_thread_t *p_vout, void *p_buf1, void *p_buf2 )
804 /* No picture previously */
805 p_vout->p_buffer[0].i_pic_x = 0;
806 p_vout->p_buffer[0].i_pic_y = 0;
807 p_vout->p_buffer[0].i_pic_width = 0;
808 p_vout->p_buffer[0].i_pic_height = 0;
809 p_vout->p_buffer[1].i_pic_x = 0;
810 p_vout->p_buffer[1].i_pic_y = 0;
811 p_vout->p_buffer[1].i_pic_width = 0;
812 p_vout->p_buffer[1].i_pic_height = 0;
814 /* The first area covers all the screen */
815 p_vout->p_buffer[0].i_areas = 1;
816 p_vout->p_buffer[0].pi_area_begin[0] = 0;
817 p_vout->p_buffer[0].pi_area_end[0] = p_vout->i_height - 1;
818 p_vout->p_buffer[1].i_areas = 1;
819 p_vout->p_buffer[1].pi_area_begin[0] = 0;
820 p_vout->p_buffer[1].pi_area_end[0] = p_vout->i_height - 1;
823 p_vout->p_buffer[0].p_data = p_buf1;
824 p_vout->p_buffer[1].p_data = p_buf2;
827 /*****************************************************************************
828 * vout_Pixel2RGB: return red, green and blue from pixel value
829 *****************************************************************************
830 * Return color values, in 0-255 range, of the decomposition of a pixel. This
831 * is a slow routine and should only be used for initialization phase.
832 *****************************************************************************/
833 void vout_Pixel2RGB( vout_thread_t *p_vout, u32 i_pixel, int *pi_red, int *pi_green, int *pi_blue )
835 *pi_red = i_pixel & p_vout->i_red_mask;
836 *pi_green = i_pixel & p_vout->i_green_mask;
837 *pi_blue = i_pixel & p_vout->i_blue_mask;
840 /* following functions are local */
842 /*****************************************************************************
843 * BinaryLog: computes the base 2 log of a binary value
844 *****************************************************************************
845 * This functions is used by MaskToShift, to get a bit index from a binary
847 *****************************************************************************/
848 static int BinaryLog(u32 i)
873 if (i != ((u32)1 << i_log))
875 intf_DbgMsg("internal error: binary log overflow");
881 /*****************************************************************************
882 * MaskToShift: transform a color mask into right and left shifts
883 *****************************************************************************
884 * This function is used for obtaining color shifts from masks.
885 *****************************************************************************/
886 static void MaskToShift( int *pi_left, int *pi_right, u32 i_mask )
888 u32 i_low, i_high; /* lower hand higher bits of the mask */
891 i_low = i_mask & (- i_mask); /* lower bit of the mask */
892 i_high = i_mask + i_low; /* higher bit of the mask */
894 /* Transform bits into an index */
895 i_low = BinaryLog (i_low);
896 i_high = BinaryLog (i_high);
898 /* Update pointers and return */
900 *pi_right = (8 - i_high + i_low);
903 /*****************************************************************************
904 * InitThread: initialize video output thread
905 *****************************************************************************
906 * This function is called from RunThread and performs the second step of the
907 * initialization. It returns 0 on success. Note that the thread's flag are not
908 * modified inside this function.
909 *****************************************************************************/
910 static int InitThread( vout_thread_t *p_vout )
913 *p_vout->pi_status = THREAD_START;
919 /* Initialize output method - this function issues its own error messages */
920 if( p_vout->p_sys_init( p_vout ) )
925 if( p_vout->b_need_render )
927 /* Initialize convertion tables and functions */
928 if( vout_InitYUV( p_vout ) )
930 intf_ErrMsg("error: can't allocate YUV translation tables");
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");
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 int i_index; /* index in heap */
954 mtime_t current_date; /* current date */
955 mtime_t display_date; /* display date */
956 boolean_t b_display; /* display flag */
957 picture_t * p_pic; /* picture pointer */
958 subpicture_t * p_subpic; /* subpicture pointer */
963 p_vout->b_error = InitThread( p_vout );
964 if( p_vout->b_error )
966 DestroyThread( p_vout, THREAD_ERROR );
971 * Main loop - it is not executed if an error occured during
974 while( (!p_vout->b_die) && (!p_vout->b_error) )
976 /* Initialize loop variables */
980 current_date = mdate();
983 if( !(p_vout->c_loops % VOUT_STATS_NB_LOOPS) )
985 intf_Msg("vout stats: picture heap: %d/%d",
986 p_vout->i_pictures, VOUT_MAX_PICTURES);
991 * Find the picture to display - this operation does not need lock,
992 * since only READY_PICTUREs are handled
994 for( i_index = 0; i_index < VOUT_MAX_PICTURES; i_index++ )
996 if( (p_vout->p_picture[i_index].i_status == READY_PICTURE) &&
998 (p_vout->p_picture[i_index].date < display_date) ) )
1000 p_pic = &p_vout->p_picture[i_index];
1001 display_date = p_pic->date;
1007 /* Computes FPS rate */
1008 p_vout->p_fps_sample[ p_vout->c_fps_samples++ % VOUT_FPS_SAMPLES ] = display_date;
1010 if( display_date < current_date - p_vout->render_time )
1012 /* Picture is late: it will be destroyed and the thread
1013 * will sleep and go to next picture */
1015 vlc_mutex_lock( &p_vout->picture_lock );
1016 if( p_pic->i_refcount )
1018 p_pic->i_status = DISPLAYED_PICTURE;
1022 p_pic->i_status = DESTROYED_PICTURE;
1023 p_vout->i_pictures--;
1026 "warning: late picture skipped (%p)", p_pic );
1027 vlc_mutex_unlock( &p_vout->picture_lock );
1031 else if( display_date > current_date + VOUT_DISPLAY_DELAY )
1033 /* A picture is ready to be rendered, but its rendering date
1034 * is far from the current one so the thread will perform an
1035 * empty loop as if no picture were found. The picture state
1042 * Find the subpictures to display - this operation does not need
1043 * lock, since only READY_SUBPICTURE are handled. If no picture
1044 * has been selected, display_date will depend on the subpicture.
1045 * We get an easily parsable chained list of subpictures which
1046 * ends with NULL since p_subpic was initialized to NULL.
1048 for( i_index = 0; i_index < VOUT_MAX_SUBPICTURES; i_index++ )
1050 if( p_vout->p_subpicture[i_index].i_status == READY_SUBPICTURE )
1052 p_vout->p_subpicture[i_index].p_next = p_subpic;
1053 p_subpic = &p_vout->p_subpicture[i_index];
1058 * Perform rendering, sleep and display rendered picture
1060 if( p_pic ) /* picture and perhaps subpicture */
1062 b_display = p_vout->b_active;
1063 p_vout->last_display_date = display_date;
1064 p_vout->p_rendered_pic = p_pic;
1069 /* FIXME: if b_need_render == 0 we need to do something with
1070 * the subpictures one day. */
1071 if( p_vout->b_need_render && b_display )
1073 /* Set picture dimensions and clear buffer */
1074 SetBufferPicture( p_vout, p_pic );
1076 /* Render picture and information */
1077 RenderPicture( p_vout, p_pic );
1078 if( p_vout->b_info )
1080 RenderPictureInfo( p_vout, p_pic );
1081 RenderInfo( p_vout );
1085 RenderSubPicture( p_vout, p_subpic );
1089 /* Render interface and subpicture */
1090 if( b_display && p_vout->b_interface && p_vout->b_need_render )
1092 RenderInterface( p_vout );
1096 else if( p_vout->b_active && p_vout->b_need_render
1097 && p_vout->init_display_date == 0)
1099 /* Idle or interface screen alone */
1101 if( p_vout->b_interface && 0 /* && XXX?? intf_change */ )
1103 /* Interface has changed, so a new rendering is required - force
1104 * it by setting last idle date to 0 */
1105 p_vout->last_idle_date = 0;
1108 /* Render idle screen and update idle date, then render interface if
1110 b_display = RenderIdle( p_vout );
1113 p_vout->last_idle_date = current_date;
1114 if( p_vout->b_interface )
1116 RenderInterface( p_vout );
1128 * Check for the current time and
1129 * display splash screen if everything is on time
1131 if( p_vout->init_display_date > 0 && p_vout->b_need_render )
1133 if( p_vout->b_active &&
1134 mdate()-p_vout->init_display_date < 5000000)
1136 /* there is something to display ! */
1138 RenderSplash( p_vout );
1141 /* no splash screen ! */
1142 intf_ErrMsgImm("End of splash screen");
1143 p_vout->init_display_date=0;
1149 * Sleep, wake up and display rendered picture
1152 if( display_date != 0 )
1154 /* Store render time using Bresenham algorithm */
1155 p_vout->render_time += mdate() - current_date;
1156 p_vout->render_time >>= 1;
1159 /* Give back change lock */
1160 vlc_mutex_unlock( &p_vout->change_lock );
1162 /* Sleep a while or until a given date */
1163 if( display_date != 0 )
1165 mwait( display_date - VOUT_MWAIT_TOLERANCE );
1169 msleep( VOUT_IDLE_SLEEP );
1172 /* On awakening, take back lock and send immediately picture to display,
1173 * then swap buffers */
1174 vlc_mutex_lock( &p_vout->change_lock );
1176 intf_DbgMsg( "picture %p, subpicture %p in buffer %d, display=%d", p_pic, p_subpic,
1177 p_vout->i_buffer_index, b_display /* && !(p_vout->i_changes & VOUT_NODISPLAY_CHANGE) */ );
1179 if( b_display /* && !(p_vout->i_changes & VOUT_NODISPLAY_CHANGE) */ )
1181 p_vout->p_sys_display( p_vout );
1183 p_vout->i_buffer_index = ++p_vout->i_buffer_index & 1;
1189 /* Remove picture from heap */
1190 vlc_mutex_lock( &p_vout->picture_lock );
1191 if( p_pic->i_refcount )
1193 p_pic->i_status = DISPLAYED_PICTURE;
1197 p_pic->i_status = DESTROYED_PICTURE;
1198 p_vout->i_pictures--;
1200 vlc_mutex_unlock( &p_vout->picture_lock );
1205 * Check events and manage thread
1207 if( p_vout->p_sys_manage( p_vout ) | Manage( p_vout ) )
1209 /* A fatal error occured, and the thread must terminate immediately,
1210 * without displaying anything - setting b_error to 1 cause the
1211 * immediate end of the main while() loop. */
1212 p_vout->b_error = 1;
1217 * Error loop - wait until the thread destruction is requested
1219 if( p_vout->b_error )
1221 ErrorThread( p_vout );
1225 EndThread( p_vout );
1226 DestroyThread( p_vout, THREAD_OVER );
1227 intf_DbgMsg( "thread end" );
1230 /*****************************************************************************
1231 * ErrorThread: RunThread() error loop
1232 *****************************************************************************
1233 * This function is called when an error occured during thread main's loop. The
1234 * thread can still receive feed, but must be ready to terminate as soon as
1236 *****************************************************************************/
1237 static void ErrorThread( vout_thread_t *p_vout )
1239 /* Wait until a `die' order */
1240 while( !p_vout->b_die )
1243 msleep( VOUT_IDLE_SLEEP );
1247 /*****************************************************************************
1248 * EndThread: thread destruction
1249 *****************************************************************************
1250 * This function is called when the thread ends after a sucessful
1251 * initialization. It frees all ressources allocated by InitThread.
1252 *****************************************************************************/
1253 static void EndThread( vout_thread_t *p_vout )
1255 int i_index; /* index in heap */
1258 *p_vout->pi_status = THREAD_END;
1262 struct tms cpu_usage;
1263 times( &cpu_usage );
1265 intf_Msg("vout stats: cpu usage (user: %d, system: %d)",
1266 cpu_usage.tms_utime, cpu_usage.tms_stime);
1270 /* Destroy all remaining pictures and subpictures */
1271 for( i_index = 0; i_index < VOUT_MAX_PICTURES; i_index++ )
1273 if( p_vout->p_picture[i_index].i_status != FREE_PICTURE )
1275 free( p_vout->p_picture[i_index].p_data );
1278 for( i_index = 0; i_index < VOUT_MAX_SUBPICTURES; i_index++ )
1280 if( p_vout->p_subpicture[i_index].i_status != FREE_SUBPICTURE )
1282 free( p_vout->p_subpicture[i_index].p_data );
1286 /* Destroy translation tables */
1287 vout_EndYUV( p_vout );
1288 p_vout->p_sys_end( p_vout );
1291 /*****************************************************************************
1292 * DestroyThread: thread destruction
1293 *****************************************************************************
1294 * This function is called when the thread ends. It frees all ressources
1295 * allocated by CreateThread. Status is available at this stage.
1296 *****************************************************************************/
1297 static void DestroyThread( vout_thread_t *p_vout, int i_status )
1299 int *pi_status; /* status adress */
1301 /* Store status adress */
1302 pi_status = p_vout->pi_status;
1304 /* Destroy thread structures allocated by Create and InitThread */
1305 vout_UnloadFont( p_vout->p_default_font );
1306 vout_UnloadFont( p_vout->p_large_font );
1307 p_vout->p_sys_destroy( p_vout );
1309 /* Free structure */
1311 *pi_status = i_status;
1314 /*****************************************************************************
1315 * Print: print simple text on a picture
1316 *****************************************************************************
1317 * This function will print a simple text on the picture. It is designed to
1318 * print debugging or general information.
1319 *****************************************************************************/
1320 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 )
1322 int i_text_height; /* total text height */
1323 int i_text_width; /* total text width */
1325 /* Update upper left coordinates according to alignment */
1326 vout_TextSize( p_vout->p_default_font, 0, psz_text, &i_text_width, &i_text_height );
1327 if( !Align( p_vout, &i_x, &i_y, i_text_width, i_text_height, i_h_align, i_v_align ) )
1329 /* Set area and print text */
1330 SetBufferArea( p_vout, i_x, i_y, i_text_width, i_text_height );
1331 vout_Print( p_vout->p_default_font, p_vout->p_buffer[ p_vout->i_buffer_index ].p_data +
1332 i_y * p_vout->i_bytes_per_line + i_x * p_vout->i_bytes_per_pixel,
1333 p_vout->i_bytes_per_pixel, p_vout->i_bytes_per_line,
1334 p_vout->i_white_pixel, 0, 0,
1339 /*****************************************************************************
1340 * SetBufferArea: activate an area in current buffer
1341 *****************************************************************************
1342 * This function is called when something is rendered on the current buffer.
1343 * It set the area as active and prepare it to be cleared on next rendering.
1344 * Pay attention to the fact that in this functions, i_h is in fact the end y
1345 * coordinate of the new area.
1346 *****************************************************************************/
1347 static void SetBufferArea( vout_thread_t *p_vout, int i_x, int i_y, int i_w, int i_h )
1349 vout_buffer_t * p_buffer; /* current buffer */
1350 int i_area_begin, i_area_end; /* area vertical extension */
1351 int i_area, i_area_copy; /* area index */
1352 int i_area_shift; /* shift distance for areas */
1354 /* Choose buffer and modify h to end of area position */
1355 p_buffer = &p_vout->p_buffer[ p_vout->i_buffer_index ];
1359 * Remove part of the area which is inside the picture - this is done
1360 * by calling again SetBufferArea with the correct areas dimensions.
1362 if( (i_x >= p_buffer->i_pic_x) && (i_x + i_w <= p_buffer->i_pic_x + p_buffer->i_pic_width) )
1364 i_area_begin = p_buffer->i_pic_y;
1365 i_area_end = i_area_begin + p_buffer->i_pic_height - 1;
1367 if( ((i_y >= i_area_begin) && (i_y <= i_area_end)) ||
1368 ((i_h >= i_area_begin) && (i_h <= i_area_end)) ||
1369 ((i_y < i_area_begin) && (i_h > i_area_end)) )
1371 /* Keep the stripe above the picture, if any */
1372 if( i_y < i_area_begin )
1374 SetBufferArea( p_vout, i_x, i_y, i_w, i_area_begin - i_y );
1376 /* Keep the stripe below the picture, if any */
1377 if( i_h > i_area_end )
1379 SetBufferArea( p_vout, i_x, i_area_end, i_w, i_h - i_area_end );
1385 /* Skip some extensions until interesting areas */
1387 (i_area < p_buffer->i_areas) &&
1388 (p_buffer->pi_area_end[i_area] + 1 <= i_y);
1394 if( i_area == p_buffer->i_areas )
1396 /* New area is below all existing ones: just add it at the end of the
1397 * array, if possible - otherwise, append it to the last one */
1398 if( i_area < VOUT_MAX_AREAS )
1400 p_buffer->pi_area_begin[i_area] = i_y;
1401 p_buffer->pi_area_end[i_area] = i_h;
1402 p_buffer->i_areas++;
1407 intf_DbgMsg("area overflow");
1409 p_buffer->pi_area_end[VOUT_MAX_AREAS - 1] = i_h;
1414 i_area_begin = p_buffer->pi_area_begin[i_area];
1415 i_area_end = p_buffer->pi_area_end[i_area];
1417 if( i_y < i_area_begin )
1419 if( i_h >= i_area_begin - 1 )
1421 /* Extend area above */
1422 p_buffer->pi_area_begin[i_area] = i_y;
1426 /* Create a new area above : merge last area if overflow, then
1427 * move all old areas down */
1428 if( p_buffer->i_areas == VOUT_MAX_AREAS )
1431 intf_DbgMsg("areas overflow");
1433 p_buffer->pi_area_end[VOUT_MAX_AREAS - 2] = p_buffer->pi_area_end[VOUT_MAX_AREAS - 1];
1437 p_buffer->i_areas++;
1439 for( i_area_copy = p_buffer->i_areas - 1; i_area_copy > i_area; i_area_copy-- )
1441 p_buffer->pi_area_begin[i_area_copy] = p_buffer->pi_area_begin[i_area_copy - 1];
1442 p_buffer->pi_area_end[i_area_copy] = p_buffer->pi_area_end[i_area_copy - 1];
1444 p_buffer->pi_area_begin[i_area] = i_y;
1445 p_buffer->pi_area_end[i_area] = i_h;
1449 if( i_h > i_area_end )
1451 /* Find further areas which can be merged with the new one */
1452 for( i_area_copy = i_area + 1;
1453 (i_area_copy < p_buffer->i_areas) &&
1454 (p_buffer->pi_area_begin[i_area] <= i_h);
1461 if( i_area_copy != i_area )
1463 /* Merge with last possible areas */
1464 p_buffer->pi_area_end[i_area] = MAX( i_h, p_buffer->pi_area_end[i_area_copy] );
1466 /* Shift lower areas upward */
1467 i_area_shift = i_area_copy - i_area;
1468 p_buffer->i_areas -= i_area_shift;
1469 for( i_area_copy = i_area + 1; i_area_copy < p_buffer->i_areas; i_area_copy++ )
1471 p_buffer->pi_area_begin[i_area_copy] = p_buffer->pi_area_begin[i_area_copy + i_area_shift];
1472 p_buffer->pi_area_end[i_area_copy] = p_buffer->pi_area_end[i_area_copy + i_area_shift];
1477 /* Extend area below */
1478 p_buffer->pi_area_end[i_area] = i_h;
1484 /*****************************************************************************
1485 * SetBufferPicture: clear buffer and set picture area
1486 *****************************************************************************
1487 * This function is called before any rendering. It clears the current
1488 * rendering buffer and set the new picture area. If the picture pointer is
1489 * NULL, then no picture area is defined. Floating operations are avoided since
1490 * some MMX calculations may follow.
1491 *****************************************************************************/
1492 static void SetBufferPicture( vout_thread_t *p_vout, picture_t *p_pic )
1494 vout_buffer_t * p_buffer; /* current buffer */
1495 int i_pic_x, i_pic_y; /* picture position */
1496 int i_pic_width, i_pic_height; /* picture dimensions */
1497 int i_old_pic_y, i_old_pic_height; /* old picture area */
1498 int i_vout_width, i_vout_height; /* display dimensions */
1499 int i_area; /* area index */
1500 int i_data_index; /* area data index */
1501 int i_data_size; /* area data size, in 256 bytes blocs */
1502 u64 * p_data; /* area data, for clearing */
1503 byte_t * p_data8; /* area data, for clearing (slow) */
1505 /* Choose buffer and set display dimensions */
1506 p_buffer = &p_vout->p_buffer[ p_vout->i_buffer_index ];
1507 i_vout_width = p_vout->i_width;
1508 i_vout_height = p_vout->i_height;
1511 * Computes new picture size
1515 /* Try horizontal scaling first - width must be a mutiple of 16 */
1516 i_pic_width = (( p_vout->b_scale || (p_pic->i_width > i_vout_width)) ?
1517 i_vout_width : p_pic->i_width) & ~0xf;
1518 switch( p_pic->i_aspect_ratio )
1520 case AR_3_4_PICTURE:
1521 i_pic_height = i_pic_width * 3 / 4;
1523 case AR_16_9_PICTURE:
1524 i_pic_height = i_pic_width * 9 / 16;
1526 case AR_221_1_PICTURE:
1527 i_pic_height = i_pic_width * 100 / 221;
1529 case AR_SQUARE_PICTURE:
1531 i_pic_height = p_pic->i_height * i_pic_width / p_pic->i_width;
1535 /* If picture dimensions using horizontal scaling are too large, use
1536 * vertical scaling. Since width must be a multiple of 16, height is
1537 * adjusted again after. */
1538 if( i_pic_height > i_vout_height )
1540 i_pic_height = ( p_vout->b_scale || (p_pic->i_height > i_vout_height)) ?
1541 i_vout_height : p_pic->i_height;
1542 switch( p_pic->i_aspect_ratio )
1544 case AR_3_4_PICTURE:
1545 i_pic_width = (i_pic_height * 4 / 3) & ~0xf;
1546 i_pic_height = i_pic_width * 3 / 4;
1548 case AR_16_9_PICTURE:
1549 i_pic_width = (i_pic_height * 16 / 9) & ~0xf;
1550 i_pic_height = i_pic_width * 9 / 16;
1552 case AR_221_1_PICTURE:
1553 i_pic_width = (i_pic_height * 221 / 100) & ~0xf;
1554 i_pic_height = i_pic_width * 100 / 221;
1556 case AR_SQUARE_PICTURE:
1558 i_pic_width = (p_pic->i_width * i_pic_height / p_pic->i_height) & ~0xf;
1559 i_pic_height = p_pic->i_height * i_pic_width / p_pic->i_width;
1564 /* Set picture position */
1565 i_pic_x = (p_vout->i_width - i_pic_width) / 2;
1566 i_pic_y = (p_vout->i_height - i_pic_height) / 2;
1571 /* No picture: size is 0 */
1579 * Set new picture size - if it is smaller than the previous one, clear
1580 * around it. Since picture are centered, only their size is tested.
1582 if( (p_buffer->i_pic_width > i_pic_width) || (p_buffer->i_pic_height > i_pic_height) )
1584 i_old_pic_y = p_buffer->i_pic_y;
1585 i_old_pic_height = p_buffer->i_pic_height;
1586 p_buffer->i_pic_x = i_pic_x;
1587 p_buffer->i_pic_y = i_pic_y;
1588 p_buffer->i_pic_width = i_pic_width;
1589 p_buffer->i_pic_height = i_pic_height;
1590 SetBufferArea( p_vout, 0, i_old_pic_y, p_vout->i_width, i_old_pic_height );
1594 p_buffer->i_pic_x = i_pic_x;
1595 p_buffer->i_pic_y = i_pic_y;
1596 p_buffer->i_pic_width = i_pic_width;
1597 p_buffer->i_pic_height = i_pic_height;
1603 for( i_area = 0; i_area < p_buffer->i_areas; i_area++ )
1606 intf_DbgMsg("clearing picture %p area in buffer %d: %d-%d", p_pic,
1607 p_vout->i_buffer_index, p_buffer->pi_area_begin[i_area], p_buffer->pi_area_end[i_area] );
1609 i_data_size = (p_buffer->pi_area_end[i_area] - p_buffer->pi_area_begin[i_area] + 1) * p_vout->i_bytes_per_line;
1610 p_data = (u64*) (p_buffer->p_data + p_vout->i_bytes_per_line * p_buffer->pi_area_begin[i_area]);
1611 for( i_data_index = i_data_size / 256; i_data_index-- ; )
1613 /* Clear 256 bytes block */
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;
1619 *p_data++ = 0; *p_data++ = 0; *p_data++ = 0; *p_data++ = 0;
1620 *p_data++ = 0; *p_data++ = 0; *p_data++ = 0; *p_data++ = 0;
1621 *p_data++ = 0; *p_data++ = 0; *p_data++ = 0; *p_data++ = 0;
1623 for( i_data_index = (i_data_size % 256) / 16; i_data_index--; )
1625 /* Clear remaining 16 bytes blocks */
1626 *p_data++ = 0; *p_data++ = 0;
1628 p_data8 = (byte_t *)p_data;
1629 for( i_data_index = i_data_size % 16; i_data_index--; )
1631 /* Clear remaining bytes */
1639 p_buffer->i_areas = 0;
1642 /*****************************************************************************
1643 * RenderPicture: render a picture
1644 *****************************************************************************
1645 * This function converts a picture from a video heap to a pixel-encoded image
1646 * and copies it to the current rendering buffer. No lock is required, since
1647 * the * rendered picture has been determined as existant, and will only be
1648 * destroyed by the vout thread later.
1649 *****************************************************************************/
1650 static void RenderPicture( vout_thread_t *p_vout, picture_t *p_pic )
1653 char psz_date[MSTRTIME_MAX_SIZE]; /* picture date */
1654 mtime_t render_time; /* picture rendering time */
1656 vout_buffer_t * p_buffer; /* rendering buffer */
1657 byte_t * p_pic_data; /* convertion destination */
1659 /* Get and set rendering information */
1660 p_buffer = &p_vout->p_buffer[ p_vout->i_buffer_index ];
1661 p_pic_data = p_buffer->p_data +
1662 p_buffer->i_pic_x * p_vout->i_bytes_per_pixel +
1663 p_buffer->i_pic_y * p_vout->i_bytes_per_line;
1665 render_time = mdate();
1671 * Choose appropriate rendering function and render picture
1673 switch( p_pic->i_type )
1675 case YUV_420_PICTURE:
1676 p_vout->yuv.p_Convert420( p_vout, p_pic_data,
1677 p_pic->p_y, p_pic->p_u, p_pic->p_v,
1678 p_pic->i_width, p_pic->i_height,
1679 p_buffer->i_pic_width, p_buffer->i_pic_height,
1680 p_vout->i_bytes_per_line / p_vout->i_bytes_per_pixel,
1681 p_pic->i_matrix_coefficients );
1683 case YUV_422_PICTURE:
1684 p_vout->yuv.p_Convert422( p_vout, p_pic_data,
1685 p_pic->p_y, p_pic->p_u, p_pic->p_v,
1686 p_pic->i_width, p_pic->i_height,
1687 p_buffer->i_pic_width, p_buffer->i_pic_height,
1688 p_vout->i_bytes_per_line / p_vout->i_bytes_per_pixel,
1689 p_pic->i_matrix_coefficients );
1691 case YUV_444_PICTURE:
1692 p_vout->yuv.p_Convert444( p_vout, p_pic_data,
1693 p_pic->p_y, p_pic->p_u, p_pic->p_v,
1694 p_pic->i_width, p_pic->i_height,
1695 p_buffer->i_pic_width, p_buffer->i_pic_height,
1696 p_vout->i_bytes_per_line / p_vout->i_bytes_per_pixel,
1697 p_pic->i_matrix_coefficients );
1701 intf_DbgMsg("error: unknown picture type %d", p_pic->i_type );
1707 /* Print picture date and rendering time */
1708 intf_DbgMsg("picture %p rendered in buffer %d (%ld us), display date: %s", p_pic,
1709 p_vout->i_buffer_index, (long) (mdate() - render_time),
1710 mstrtime( psz_date, p_pic->date ));
1714 /*****************************************************************************
1715 * RenderPictureInfo: print additionnal information on a picture
1716 *****************************************************************************
1717 * This function will print information such as fps and other picture
1718 * dependant information.
1719 *****************************************************************************/
1720 static void RenderPictureInfo( vout_thread_t *p_vout, picture_t *p_pic )
1722 char psz_buffer[256]; /* string buffer */
1725 * Print FPS rate in upper right corner
1727 if( p_vout->c_fps_samples > VOUT_FPS_SAMPLES )
1729 long i_fps = VOUT_FPS_SAMPLES * 1000000 * 10 /
1730 ( p_vout->p_fps_sample[ (p_vout->c_fps_samples - 1)
1731 % VOUT_FPS_SAMPLES ] -
1732 p_vout->p_fps_sample[ p_vout->c_fps_samples
1733 % VOUT_FPS_SAMPLES ] );
1734 sprintf( psz_buffer, "%li.%i fps", i_fps / 10, (int)i_fps % 10 );
1735 Print( p_vout, 0, 0, RIGHT_RALIGN, TOP_RALIGN, psz_buffer );
1739 * Print frames count and loop time in upper left corner
1741 sprintf( psz_buffer, "%ld frames, render: %ldus",
1742 (long) p_vout->c_fps_samples, (long) p_vout->render_time );
1743 Print( p_vout, 0, 0, LEFT_RALIGN, TOP_RALIGN, psz_buffer );
1747 * Print picture information in lower right corner
1749 sprintf( psz_buffer, "%s picture %dx%d (%dx%d%+d%+d %s) -> %dx%d+%d+%d",
1750 (p_pic->i_type == YUV_420_PICTURE) ? "4:2:0" :
1751 ((p_pic->i_type == YUV_422_PICTURE) ? "4:2:2" :
1752 ((p_pic->i_type == YUV_444_PICTURE) ? "4:4:4" : "ukn-type")),
1753 p_pic->i_width, p_pic->i_height,
1754 p_pic->i_display_width, p_pic->i_display_height,
1755 p_pic->i_display_horizontal_offset, p_pic->i_display_vertical_offset,
1756 (p_pic->i_aspect_ratio == AR_SQUARE_PICTURE) ? "sq" :
1757 ((p_pic->i_aspect_ratio == AR_3_4_PICTURE) ? "4:3" :
1758 ((p_pic->i_aspect_ratio == AR_16_9_PICTURE) ? "16:9" :
1759 ((p_pic->i_aspect_ratio == AR_221_1_PICTURE) ? "2.21:1" : "ukn-ar" ))),
1760 p_vout->p_buffer[ p_vout->i_buffer_index ].i_pic_width,
1761 p_vout->p_buffer[ p_vout->i_buffer_index ].i_pic_height,
1762 p_vout->p_buffer[ p_vout->i_buffer_index ].i_pic_x,
1763 p_vout->p_buffer[ p_vout->i_buffer_index ].i_pic_y );
1764 Print( p_vout, 0, 0, RIGHT_RALIGN, BOTTOM_RALIGN, psz_buffer );
1768 /*****************************************************************************
1769 * RenderSplash: render splash picture
1770 *****************************************************************************
1771 * This function will print something on the screen. It will return 0 if
1772 * nothing has been rendered, or 1 if something has been changed on the screen.
1773 * Note that if you absolutely want something to be printed, you will have
1774 * to force it by setting the last idle date to 0.
1775 * Unlike other rendering functions, this one calls the SetBufferPicture
1776 * function when needed.
1777 *****************************************************************************/
1778 int RenderSplash( vout_thread_t *p_vout )
1780 int i_x = 0, i_y = 0; /* text position */
1781 int i_width, i_height; /* text size */
1782 char *psz_text = "VideoLAN Client (" VERSION ")"; /* text to display */
1784 memset( p_vout->p_buffer[ p_vout->i_buffer_index ].p_data,
1785 p_vout->i_bytes_per_line * p_vout->i_height, 12);
1787 // SetBufferPicture( p_vout, NULL );
1788 vout_TextSize( p_vout->p_large_font, WIDE_TEXT | OUTLINED_TEXT, psz_text,
1789 &i_width, &i_height );
1790 if( !Align( p_vout, &i_x, &i_y, i_width, i_height, CENTER_RALIGN, CENTER_RALIGN ) )
1792 vout_Print( p_vout->p_large_font,
1793 p_vout->p_buffer[ p_vout->i_buffer_index ].p_data +
1794 i_x * p_vout->i_bytes_per_pixel + (i_y - 16 ) * p_vout->i_bytes_per_line,
1795 p_vout->i_bytes_per_pixel, p_vout->i_bytes_per_line,
1796 p_vout->i_white_pixel, p_vout->i_gray_pixel, 0,
1797 WIDE_TEXT | OUTLINED_TEXT, psz_text, 100);
1798 SetBufferArea( p_vout, i_x, i_y, i_width, i_height);
1804 /*****************************************************************************
1805 * RenderIdle: render idle picture
1806 *****************************************************************************
1807 * This function will print something on the screen. It will return 0 if
1808 * nothing has been rendered, or 1 if something has been changed on the screen.
1809 * Note that if you absolutely want something to be printed, you will have
1810 * to force it by setting the last idle date to 0.
1811 * Unlike other rendering functions, this one calls the SetBufferPicture
1812 * function when needed.
1813 *****************************************************************************/
1814 int RenderIdle( vout_thread_t *p_vout )
1816 int i_x = 0, i_y = 0; /* text position */
1817 int i_width, i_height; /* text size */
1818 mtime_t current_date; /* current date */
1819 int i_amount = 0; /* amount to draw */
1820 char *psz_text = "Waiting for stream"; /* text to display */
1821 char *psz_wtext = "[................]";
1824 memset( p_vout->p_buffer[ p_vout->i_buffer_index ].p_data,
1825 p_vout->i_bytes_per_line * p_vout->i_height, 12);
1828 current_date = mdate();
1829 if( (current_date - p_vout->last_display_date) > VOUT_IDLE_DELAY
1830 // && (current_date - p_vout->last_idle_date) > VOUT_IDLE_DELAY
1833 SetBufferPicture( p_vout, NULL );
1834 vout_TextSize( p_vout->p_large_font, WIDE_TEXT | OUTLINED_TEXT, psz_text,
1835 &i_width, &i_height );
1836 if( !Align( p_vout, &i_x, &i_y, i_width, i_height * 2, CENTER_RALIGN, CENTER_RALIGN ) )
1838 i_amount = (int) ((current_date - p_vout->last_display_date ) / 5000LL);
1839 vout_Print( p_vout->p_large_font,
1840 p_vout->p_buffer[ p_vout->i_buffer_index ].p_data +
1841 i_x * p_vout->i_bytes_per_pixel + i_y * p_vout->i_bytes_per_line,
1842 p_vout->i_bytes_per_pixel, p_vout->i_bytes_per_line,
1843 p_vout->i_white_pixel, p_vout->i_gray_pixel, 0,
1844 WIDE_TEXT | OUTLINED_TEXT, psz_text, (i_amount / 3 ) %110);
1846 vout_Print( p_vout->p_large_font,
1847 p_vout->p_buffer[ p_vout->i_buffer_index ].p_data +
1848 i_x * p_vout->i_bytes_per_pixel + (i_y + 16) * p_vout->i_bytes_per_line,
1849 p_vout->i_bytes_per_pixel, p_vout->i_bytes_per_line,
1850 p_vout->i_white_pixel, p_vout->i_gray_pixel, 0,
1851 WIDE_TEXT | OUTLINED_TEXT, psz_wtext, (i_amount/5)%110 );
1854 SetBufferArea( p_vout, i_x, i_y, i_width, i_height * 2 );
1861 /*****************************************************************************
1862 * RenderInfo: render additionnal information
1863 *****************************************************************************
1864 * This function renders information which do not depend on the current
1866 *****************************************************************************/
1867 static void RenderInfo( vout_thread_t *p_vout )
1870 char psz_buffer[256]; /* string buffer */
1871 int i_ready_pic = 0; /* ready pictures */
1872 int i_reserved_pic = 0; /* reserved pictures */
1873 int i_picture; /* picture index */
1878 * Print thread state in lower left corner
1880 for( i_picture = 0; i_picture < VOUT_MAX_PICTURES; i_picture++ )
1882 switch( p_vout->p_picture[i_picture].i_status )
1884 case RESERVED_PICTURE:
1885 case RESERVED_DATED_PICTURE:
1886 case RESERVED_DISP_PICTURE:
1894 sprintf( psz_buffer, "pic: %d (%d/%d)/%d",
1895 p_vout->i_pictures, i_reserved_pic, i_ready_pic, VOUT_MAX_PICTURES );
1896 Print( p_vout, 0, 0, LEFT_RALIGN, BOTTOM_RALIGN, psz_buffer );
1900 /*****************************************************************************
1901 * RenderSubPicture: render a subpicture
1902 *****************************************************************************
1903 * This function renders a sub picture unit.
1904 *****************************************************************************/
1905 static void RenderSubPicture( vout_thread_t *p_vout, subpicture_t *p_subpic )
1907 p_vout_font_t p_font; /* text font */
1908 int i_width, i_height; /* subpicture dimensions */
1910 while( p_subpic != NULL )
1912 switch( p_subpic->i_type )
1914 case DVD_SUBPICTURE: /* DVD subpicture unit */
1915 /* test if the picture really has to be displayed */
1916 if( mdate() < p_subpic->begin_date )
1918 /* not yet, see you later */
1921 if( mdate() > p_subpic->end_date )
1923 /* too late, destroying the subpic */
1924 vout_DestroySubPicture( p_vout, p_subpic );
1927 vout_RenderSPU( &p_vout->p_buffer[ p_vout->i_buffer_index ],
1928 p_subpic, p_vout->i_bytes_per_pixel,
1929 p_vout->i_bytes_per_line );
1931 case TEXT_SUBPICTURE: /* single line text */
1932 /* Select default font if not specified */
1933 p_font = p_subpic->type.text.p_font;
1934 if( p_font == NULL )
1936 p_font = p_vout->p_default_font;
1939 /* Compute text size (width and height fields are ignored)
1941 vout_TextSize( p_font, p_subpic->type.text.i_style,
1942 p_subpic->p_data, &i_width, &i_height );
1943 if( !Align( p_vout, &p_subpic->i_x, &p_subpic->i_y,
1944 i_width, i_height, p_subpic->i_horizontal_align,
1945 p_subpic->i_vertical_align ) )
1948 p_vout->p_buffer[ p_vout->i_buffer_index ].p_data +
1949 p_subpic->i_x * p_vout->i_bytes_per_pixel +
1950 p_subpic->i_y * p_vout->i_bytes_per_line,
1951 p_vout->i_bytes_per_pixel, p_vout->i_bytes_per_line,
1952 p_subpic->type.text.i_char_color,
1953 p_subpic->type.text.i_border_color,
1954 p_subpic->type.text.i_bg_color,
1955 p_subpic->type.text.i_style, p_subpic->p_data, 100 );
1956 SetBufferArea( p_vout, p_subpic->i_x, p_subpic->i_y,
1957 i_width, i_height );
1963 intf_DbgMsg( "error: unknown subpicture %p type %d",
1964 p_subpic, p_subpic->i_type );
1968 p_subpic = p_subpic->p_next;
1972 /*****************************************************************************
1973 * RenderInterface: render the interface
1974 *****************************************************************************
1975 * This function renders the interface, if any.
1976 *****************************************************************************/
1977 static void RenderInterface( vout_thread_t *p_vout )
1979 int i_height, i_text_height; /* total and text height */
1980 int i_width_1, i_width_2; /* text width */
1981 int i_byte; /* byte index */
1982 const char *psz_text_1 = "[1-9] Channel [i]nfo [c]olor [g/G]amma";
1983 const char *psz_text_2 = "[+/-] Volume [m]ute [s]caling [Q]uit";
1986 vout_TextSize( p_vout->p_large_font, OUTLINED_TEXT, psz_text_1, &i_width_1, &i_height );
1987 vout_TextSize( p_vout->p_large_font, OUTLINED_TEXT, psz_text_2, &i_width_2, &i_text_height );
1988 i_height += i_text_height;
1990 /* Render background */
1991 for( i_byte = (p_vout->i_height - i_height) * p_vout->i_bytes_per_line;
1992 i_byte < p_vout->i_height * p_vout->i_bytes_per_line;
1996 p_vout->p_buffer[ p_vout->i_buffer_index ].p_data[ i_byte ] = p_vout->i_blue_pixel;
1999 /* Render text, if not larger than screen */
2000 if( i_width_1 < p_vout->i_width )
2002 vout_Print( p_vout->p_large_font, p_vout->p_buffer[ p_vout->i_buffer_index ].p_data +
2003 (p_vout->i_height - i_height) * p_vout->i_bytes_per_line,
2004 p_vout->i_bytes_per_pixel, p_vout->i_bytes_per_line,
2005 p_vout->i_white_pixel, p_vout->i_black_pixel, 0,
2006 OUTLINED_TEXT, psz_text_1, 100 );
2008 if( i_width_2 < p_vout->i_width )
2010 vout_Print( p_vout->p_large_font, p_vout->p_buffer[ p_vout->i_buffer_index ].p_data +
2011 (p_vout->i_height - i_height + i_text_height) * p_vout->i_bytes_per_line,
2012 p_vout->i_bytes_per_pixel, p_vout->i_bytes_per_line,
2013 p_vout->i_white_pixel, p_vout->i_black_pixel, 0,
2014 OUTLINED_TEXT, psz_text_2, 100 );
2017 /* Activate modified area */
2018 SetBufferArea( p_vout, 0, p_vout->i_height - i_height, p_vout->i_width, i_height );
2021 /*****************************************************************************
2022 * Manage: manage thread
2023 *****************************************************************************
2024 * This function will handle changes in thread configuration.
2025 *****************************************************************************/
2026 static int Manage( vout_thread_t *p_vout )
2029 if( p_vout->i_changes )
2031 intf_DbgMsg("changes: 0x%x (no display: 0x%x)", p_vout->i_changes,
2032 0 /* p_vout->i_changes & VOUT_NODISPLAY_CHANGE */ );
2036 /* On gamma or grayscale change, rebuild tables */
2037 if( p_vout->i_changes & (VOUT_GAMMA_CHANGE | VOUT_GRAYSCALE_CHANGE |
2040 if( vout_ResetYUV( p_vout ) )
2042 intf_ErrMsg("error: can't rebuild convertion tables");
2047 /* Clear changes flags which does not need management or have been
2049 p_vout->i_changes &= ~(VOUT_GAMMA_CHANGE | VOUT_GRAYSCALE_CHANGE |
2050 VOUT_YUV_CHANGE | VOUT_INFO_CHANGE |
2051 VOUT_INTF_CHANGE | VOUT_SCALE_CHANGE );
2053 /* Detect unauthorized changes */
2054 if( p_vout->i_changes )
2056 /* Some changes were not acknowledged by p_vout->p_sys_manage or this
2057 * function, it means they should not be authorized */
2058 intf_ErrMsg( "error: unauthorized changes in the video output thread" );
2065 /*****************************************************************************
2066 * Align: align a subpicture in the screen
2067 *****************************************************************************
2068 * This function is used for rendering text or subpictures. It returns non 0
2069 * it the final aera is not fully included in display area. Return coordinates
2071 *****************************************************************************/
2072 static int Align( vout_thread_t *p_vout, int *pi_x, int *pi_y,
2073 int i_width, int i_height, int i_h_align, int i_v_align )
2075 /* Align horizontally */
2079 *pi_x -= i_width / 2;
2082 *pi_x += (p_vout->i_width - i_width) / 2;
2088 *pi_x += p_vout->i_width - i_width;
2092 /* Align vertically */
2096 *pi_y -= i_height / 2;
2099 *pi_y += (p_vout->i_height - i_height) / 2;
2105 *pi_y += p_vout->i_height - i_height;
2107 case SUBTITLE_RALIGN:
2108 *pi_y += (p_vout->i_height + p_vout->p_buffer[ p_vout->i_buffer_index ].i_pic_y +
2109 p_vout->p_buffer[ p_vout->i_buffer_index ].i_pic_height - i_height) / 2;
2113 /* Return non 0 if clipping failed */
2114 return( (*pi_x < 0) || (*pi_y < 0) ||
2115 (*pi_x + i_width > p_vout->i_width) || (*pi_y + i_height > p_vout->i_height) );
2118 /*****************************************************************************
2119 * SetPalette: sets an 8 bpp palette
2120 *****************************************************************************
2121 * This function is just a prototype that does nothing. Architectures that
2122 * support palette allocation should override it.
2123 *****************************************************************************/
2124 static void SetPalette ( p_vout_thread_t p_vout, u16 *red,
2125 u16 *green, u16 *blue, u16 *transp )
2127 intf_ErrMsg( "SetPalette: method does not support palette changing" );