1 /******************************************************************************
2 * video_output.c : video output thread
4 ******************************************************************************
5 * This module describes the programming interface for video output threads.
6 * It includes functions allowing to open a new thread, send pictures to a
7 * thread, and destroy a previously oppenned video output thread.
8 ******************************************************************************/
10 /******************************************************************************
12 ******************************************************************************/
21 #include "vlc_thread.h"
23 #include "video_output.h"
24 #include "video_text.h"
25 #include "video_sys.h"
26 #include "video_yuv.h"
30 /******************************************************************************
32 ******************************************************************************/
33 static int InitThread ( vout_thread_t *p_vout );
34 static void RunThread ( vout_thread_t *p_vout );
35 static void ErrorThread ( vout_thread_t *p_vout );
36 static void EndThread ( vout_thread_t *p_vout );
37 static void DestroyThread ( vout_thread_t *p_vout, int i_status );
38 static void Print ( vout_thread_t *p_vout, int i_x, int i_y,
39 int i_h_align, int i_v_align, unsigned char *psz_text );
40 static void SetBufferArea ( vout_thread_t *p_vout, int i_x, int i_y, int i_w, int i_h );
41 static void SetBufferPicture ( vout_thread_t *p_vout, picture_t *p_pic );
42 static void RenderPicture ( vout_thread_t *p_vout, picture_t *p_pic );
43 static void RenderPictureInfo ( vout_thread_t *p_vout, picture_t *p_pic );
44 static void RenderSubPicture ( vout_thread_t *p_vout, subpicture_t *p_subpic );
45 static void RenderInterface ( vout_thread_t *p_vout );
46 static int RenderIdle ( vout_thread_t *p_vout );
47 static void RenderInfo ( vout_thread_t *p_vout );
48 static int Manage ( vout_thread_t *p_vout );
49 static int Align ( vout_thread_t *p_vout, int *pi_x, int *pi_y,
50 int i_width, int i_height, int i_h_align, int i_v_align );
52 /******************************************************************************
53 * vout_CreateThread: creates a new video output thread
54 ******************************************************************************
55 * This function creates a new video output thread, and returns a pointer
56 * to its description. On error, it returns NULL.
57 * If pi_status is NULL, then the function will block until the thread is ready.
58 * If not, it will be updated using one of the THREAD_* constants.
59 ******************************************************************************/
60 vout_thread_t * vout_CreateThread ( char *psz_display, int i_root_window,
61 int i_width, int i_height, int *pi_status )
63 vout_thread_t * p_vout; /* thread descriptor */
64 int i_status; /* thread status */
65 int i_index; /* index for array initialization */
67 /* Allocate descriptor */
69 p_vout = (vout_thread_t *) malloc( sizeof(vout_thread_t) );
72 intf_ErrMsg("error: %s\n", strerror(ENOMEM));
76 /* Initialize thread properties - thread id and locks will be initialized
81 p_vout->pi_status = (pi_status != NULL) ? pi_status : &i_status;
82 *p_vout->pi_status = THREAD_CREATE;
84 /* Initialize some fields used by the system-dependant method - these fields will
85 * probably be modified by the method, and are only preferences */
86 p_vout->i_changes = 0;
87 p_vout->i_width = i_width;
88 p_vout->i_height = i_height;
89 p_vout->i_bytes_per_line = i_width * 2;
90 p_vout->i_screen_depth = 15;
91 p_vout->i_bytes_per_pixel = 2;
92 p_vout->f_gamma = VOUT_GAMMA;
94 p_vout->b_grayscale = main_GetIntVariable( VOUT_GRAYSCALE_VAR,
95 VOUT_GRAYSCALE_DEFAULT );
97 p_vout->b_interface = 0;
100 intf_DbgMsg("wished configuration: %dx%d,%d (%d bytes/pixel, %d bytes/line)\n",
101 p_vout->i_width, p_vout->i_height, p_vout->i_screen_depth,
102 p_vout->i_bytes_per_pixel, p_vout->i_bytes_per_line );
104 /* Initialize idle screen */
105 p_vout->last_display_date = mdate();
106 p_vout->last_idle_date = 0;
109 /* Initialize statistics fields */
110 p_vout->render_time = 0;
111 p_vout->c_fps_samples = 0;
114 /* Initialize buffer index */
115 p_vout->i_buffer_index = 0;
117 /* Initialize pictures and subpictures - translation tables and functions
118 * will be initialized later in InitThread */
119 for( i_index = 0; i_index < VOUT_MAX_PICTURES; i_index++)
121 p_vout->p_picture[i_index].i_type = EMPTY_PICTURE;
122 p_vout->p_picture[i_index].i_status = FREE_PICTURE;
123 p_vout->p_subpicture[i_index].i_type = EMPTY_SUBPICTURE;
124 p_vout->p_subpicture[i_index].i_status= FREE_SUBPICTURE;
127 /* Create and initialize system-dependant method - this function issues its
128 * own error messages */
129 if( vout_SysCreate( p_vout, psz_display, i_root_window ) )
134 intf_DbgMsg("actual configuration: %dx%d,%d (%d bytes/pixel, %d bytes/line)\n",
135 p_vout->i_width, p_vout->i_height, p_vout->i_screen_depth,
136 p_vout->i_bytes_per_pixel, p_vout->i_bytes_per_line );
138 /* Load fonts - fonts must be initialized after the systme method since
139 * they may be dependant of screen depth and other thread properties */
140 p_vout->p_default_font = vout_LoadFont( VOUT_DEFAULT_FONT );
141 if( p_vout->p_default_font == NULL )
143 vout_SysDestroy( p_vout );
147 p_vout->p_large_font = vout_LoadFont( VOUT_LARGE_FONT );
148 if( p_vout->p_large_font == NULL )
150 vout_UnloadFont( p_vout->p_default_font );
151 vout_SysDestroy( p_vout );
156 /* Create thread and set locks */
157 vlc_mutex_init( &p_vout->picture_lock );
158 vlc_mutex_init( &p_vout->subpicture_lock );
159 vlc_mutex_init( &p_vout->change_lock );
160 vlc_mutex_lock( &p_vout->change_lock );
161 if( vlc_thread_create( &p_vout->thread_id, "video output", (void *) RunThread, (void *) p_vout) )
163 intf_ErrMsg("error: %s\n", strerror(ENOMEM));
164 vout_UnloadFont( p_vout->p_default_font );
165 vout_UnloadFont( p_vout->p_large_font );
166 vout_SysDestroy( p_vout );
171 intf_Msg("Video display initialized (%dx%d, %d bpp)\n",
172 p_vout->i_width, p_vout->i_height, p_vout->i_screen_depth );
174 /* If status is NULL, wait until the thread is created */
175 if( pi_status == NULL )
179 msleep( THREAD_SLEEP );
180 }while( (i_status != THREAD_READY) && (i_status != THREAD_ERROR)
181 && (i_status != THREAD_FATAL) );
182 if( i_status != THREAD_READY )
190 /******************************************************************************
191 * vout_DestroyThread: destroys a previously created thread
192 ******************************************************************************
193 * Destroy a terminated thread.
194 * The function will request a destruction of the specified thread. If pi_error
195 * is NULL, it will return once the thread is destroyed. Else, it will be
196 * update using one of the THREAD_* constants.
197 ******************************************************************************/
198 void vout_DestroyThread( vout_thread_t *p_vout, int *pi_status )
200 int i_status; /* thread status */
204 p_vout->pi_status = (pi_status != NULL) ? pi_status : &i_status;
205 *p_vout->pi_status = THREAD_DESTROY;
207 /* Request thread destruction */
210 /* If status is NULL, wait until thread has been destroyed */
211 if( pi_status == NULL )
215 msleep( THREAD_SLEEP );
216 }while( (i_status != THREAD_OVER) && (i_status != THREAD_ERROR)
217 && (i_status != THREAD_FATAL) );
221 /******************************************************************************
222 * vout_DisplaySubPicture: display a subpicture unit
223 ******************************************************************************
224 * Remove the reservation flag of an subpicture, which will cause it to be ready
225 * for display. The picture does not need to be locked, since it is ignored by
226 * the output thread if is reserved.
227 ******************************************************************************/
228 void vout_DisplaySubPicture( vout_thread_t *p_vout, subpicture_t *p_subpic )
231 char psz_begin_date[MSTRTIME_MAX_SIZE]; /* buffer for date string */
232 char psz_end_date[MSTRTIME_MAX_SIZE]; /* buffer for date string */
236 /* Check if status is valid */
237 if( p_subpic->i_status != RESERVED_SUBPICTURE )
239 intf_DbgMsg("error: subpicture %p has invalid status %d\n", p_subpic,
240 p_subpic->i_status );
244 /* Remove reservation flag */
245 p_subpic->i_status = READY_SUBPICTURE;
248 /* Send subpicture informations */
249 intf_DbgMsg("subpicture %p: type=%d, begin date=%s, end date=%s\n",
250 p_subpic, p_subpic->i_type,
251 mstrtime( psz_begin_date, p_subpic->begin_date ),
252 mstrtime( psz_end_date, p_subpic->end_date ) );
256 /******************************************************************************
257 * vout_CreateSubPicture: allocate an subpicture in the video output heap.
258 ******************************************************************************
259 * This function create a reserved subpicture in the video output heap.
260 * A null pointer is returned if the function fails. This method provides an
261 * already allocated zone of memory in the spu data fields. It needs locking
262 * since several pictures can be created by several producers threads.
263 ******************************************************************************/
264 subpicture_t *vout_CreateSubPicture( vout_thread_t *p_vout, int i_type,
270 /******************************************************************************
271 * vout_DestroySubPicture: remove a subpicture from the heap
272 ******************************************************************************
273 * This function frees a previously reserved subpicture.
274 * It is meant to be used when the construction of a picture aborted.
275 * This function does not need locking since reserved subpictures are ignored
276 * by the output thread.
277 ******************************************************************************/
278 void vout_DestroySubPicture( vout_thread_t *p_vout, subpicture_t *p_subpic )
281 /* Check if status is valid */
282 if( p_subpic->i_status != RESERVED_SUBPICTURE )
284 intf_DbgMsg("error: subpicture %p has invalid status %d\n",
285 p_subpic, p_subpic->i_status );
289 p_subpic->i_status = DESTROYED_SUBPICTURE;
292 intf_DbgMsg("subpicture %p\n", p_subpic);
296 /******************************************************************************
297 * vout_DisplayPicture: display a picture
298 ******************************************************************************
299 * Remove the reservation flag of a picture, which will cause it to be ready for
300 * display. The picture won't be displayed until vout_DatePicture has been
302 ******************************************************************************/
303 void vout_DisplayPicture( vout_thread_t *p_vout, picture_t *p_pic )
305 vlc_mutex_lock( &p_vout->picture_lock );
306 switch( p_pic->i_status )
308 case RESERVED_PICTURE:
309 p_pic->i_status = RESERVED_DISP_PICTURE;
311 case RESERVED_DATED_PICTURE:
312 p_pic->i_status = READY_PICTURE;
316 intf_DbgMsg("error: picture %p has invalid status %d\n", p_pic, p_pic->i_status );
322 intf_DbgMsg("picture %p\n", p_pic );
325 vlc_mutex_unlock( &p_vout->picture_lock );
328 /******************************************************************************
329 * vout_DatePicture: date a picture
330 ******************************************************************************
331 * Remove the reservation flag of a picture, which will cause it to be ready for
332 * display. The picture won't be displayed until vout_DisplayPicture has been
334 ******************************************************************************/
335 void vout_DatePicture( vout_thread_t *p_vout, picture_t *p_pic, mtime_t date )
337 vlc_mutex_lock( &p_vout->picture_lock );
339 switch( p_pic->i_status )
341 case RESERVED_PICTURE:
342 p_pic->i_status = RESERVED_DATED_PICTURE;
344 case RESERVED_DISP_PICTURE:
345 p_pic->i_status = READY_PICTURE;
349 intf_DbgMsg("error: picture %p has invalid status %d\n", p_pic, p_pic->i_status );
355 intf_DbgMsg("picture %p\n", p_pic);
358 vlc_mutex_unlock( &p_vout->picture_lock );
361 /******************************************************************************
362 * vout_CreatePicture: allocate a picture in the video output heap.
363 ******************************************************************************
364 * This function create a reserved image in the video output heap.
365 * A null pointer is returned if the function fails. This method provides an
366 * already allocated zone of memory in the picture data fields. It needs locking
367 * since several pictures can be created by several producers threads.
368 ******************************************************************************/
369 picture_t *vout_CreatePicture( vout_thread_t *p_vout, int i_type,
370 int i_width, int i_height )
372 int i_picture; /* picture index */
373 int i_chroma_width = 0; /* chroma width */
374 picture_t * p_free_picture = NULL; /* first free picture */
375 picture_t * p_destroyed_picture = NULL; /* first destroyed picture */
378 vlc_mutex_lock( &p_vout->picture_lock );
381 * Look for an empty place
384 i_picture < VOUT_MAX_PICTURES;
387 if( p_vout->p_picture[i_picture].i_status == DESTROYED_PICTURE )
389 /* Picture is marked for destruction, but is still allocated - note
390 * that if width and type are the same for two pictures, chroma_width
391 * should also be the same */
392 if( (p_vout->p_picture[i_picture].i_type == i_type) &&
393 (p_vout->p_picture[i_picture].i_height == i_height) &&
394 (p_vout->p_picture[i_picture].i_width == i_width) )
396 /* Memory size do match : memory will not be reallocated, and function
397 * can end immediately - this is the best possible case, since no
398 * memory allocation needs to be done */
399 p_vout->p_picture[i_picture].i_status = RESERVED_PICTURE;
401 intf_DbgMsg("picture %p (in destroyed picture slot)\n",
402 &p_vout->p_picture[i_picture] );
404 vlc_mutex_unlock( &p_vout->picture_lock );
405 return( &p_vout->p_picture[i_picture] );
407 else if( p_destroyed_picture == NULL )
409 /* Memory size do not match, but picture index will be kept in
410 * case no other place are left */
411 p_destroyed_picture = &p_vout->p_picture[i_picture];
414 else if( (p_free_picture == NULL) &&
415 (p_vout->p_picture[i_picture].i_status == FREE_PICTURE ))
417 /* Picture is empty and ready for allocation */
418 p_free_picture = &p_vout->p_picture[i_picture];
422 /* If no free picture is available, use a destroyed picture */
423 if( (p_free_picture == NULL) && (p_destroyed_picture != NULL ) )
425 /* No free picture or matching destroyed picture has been found, but
426 * a destroyed picture is still avalaible */
427 free( p_destroyed_picture->p_data );
428 p_free_picture = p_destroyed_picture;
434 if( p_free_picture != NULL )
436 /* Allocate memory */
439 case YUV_420_PICTURE: /* YUV 420: 1,1/4,1/4 samples per pixel */
440 i_chroma_width = i_width / 2;
441 p_free_picture->p_data = malloc( i_height * i_chroma_width * 3 * sizeof( yuv_data_t ) );
442 p_free_picture->p_y = (yuv_data_t *)p_free_picture->p_data;
443 p_free_picture->p_u = (yuv_data_t *)p_free_picture->p_data +i_height*i_chroma_width*4/2;
444 p_free_picture->p_v = (yuv_data_t *)p_free_picture->p_data +i_height*i_chroma_width*5/2;
446 case YUV_422_PICTURE: /* YUV 422: 1,1/2,1/2 samples per pixel */
447 i_chroma_width = i_width / 2;
448 p_free_picture->p_data = malloc( i_height * i_chroma_width * 4 * sizeof( yuv_data_t ) );
449 p_free_picture->p_y = (yuv_data_t *)p_free_picture->p_data;
450 p_free_picture->p_u = (yuv_data_t *)p_free_picture->p_data +i_height*i_chroma_width*2;
451 p_free_picture->p_v = (yuv_data_t *)p_free_picture->p_data +i_height*i_chroma_width*3;
453 case YUV_444_PICTURE: /* YUV 444: 1,1,1 samples per pixel */
454 i_chroma_width = i_width;
455 p_free_picture->p_data = malloc( i_height * i_chroma_width * 3 * sizeof( yuv_data_t ) );
456 p_free_picture->p_y = (yuv_data_t *)p_free_picture->p_data;
457 p_free_picture->p_u = (yuv_data_t *)p_free_picture->p_data +i_height*i_chroma_width;
458 p_free_picture->p_v = (yuv_data_t *)p_free_picture->p_data +i_height*i_chroma_width*2;
462 intf_DbgMsg("error: unknown picture type %d\n", i_type );
463 p_free_picture->p_data = NULL;
468 if( p_free_picture->p_data != NULL )
470 /* Copy picture informations, set some default values */
471 p_free_picture->i_type = i_type;
472 p_free_picture->i_status = RESERVED_PICTURE;
473 p_free_picture->i_matrix_coefficients = 1;
474 p_free_picture->i_width = i_width;
475 p_free_picture->i_height = i_height;
476 p_free_picture->i_chroma_width = i_chroma_width;
477 p_free_picture->i_display_horizontal_offset = 0;
478 p_free_picture->i_display_vertical_offset = 0;
479 p_free_picture->i_display_width = i_width;
480 p_free_picture->i_display_height = i_height;
481 p_free_picture->i_aspect_ratio = AR_SQUARE_PICTURE;
482 p_free_picture->i_refcount = 0;
486 /* Memory allocation failed : set picture as empty */
487 p_free_picture->i_type = EMPTY_PICTURE;
488 p_free_picture->i_status = FREE_PICTURE;
489 p_free_picture = NULL;
490 intf_ErrMsg("warning: %s\n", strerror( ENOMEM ) );
494 intf_DbgMsg("picture %p (in free picture slot)\n", p_free_picture );
496 vlc_mutex_unlock( &p_vout->picture_lock );
497 return( p_free_picture );
500 // No free or destroyed picture could be found
501 intf_DbgMsg( "warning: heap is full\n" );
502 vlc_mutex_unlock( &p_vout->picture_lock );
506 /******************************************************************************
507 * vout_DestroyPicture: remove a permanent or reserved picture from the heap
508 ******************************************************************************
509 * This function frees a previously reserved picture or a permanent
510 * picture. It is meant to be used when the construction of a picture aborted.
511 * Note that the picture will be destroyed even if it is linked !
512 * This function does not need locking since reserved pictures are ignored by
514 ******************************************************************************/
515 void vout_DestroyPicture( vout_thread_t *p_vout, picture_t *p_pic )
518 /* Check if picture status is valid */
519 if( (p_pic->i_status != RESERVED_PICTURE) &&
520 (p_pic->i_status != RESERVED_DATED_PICTURE) &&
521 (p_pic->i_status != RESERVED_DISP_PICTURE) )
523 intf_DbgMsg("error: picture %p has invalid status %d\n", p_pic, p_pic->i_status );
527 p_pic->i_status = DESTROYED_PICTURE;
530 intf_DbgMsg("picture %p\n", p_pic);
534 /******************************************************************************
535 * vout_LinkPicture: increment reference counter of a picture
536 ******************************************************************************
537 * This function increment the reference counter of a picture in the video
538 * heap. It needs a lock since several producer threads can access the picture.
539 ******************************************************************************/
540 void vout_LinkPicture( vout_thread_t *p_vout, picture_t *p_pic )
542 vlc_mutex_lock( &p_vout->picture_lock );
546 intf_DbgMsg("picture %p refcount=%d\n", p_pic, p_pic->i_refcount );
549 vlc_mutex_unlock( &p_vout->picture_lock );
552 /******************************************************************************
553 * vout_UnlinkPicture: decrement reference counter of a picture
554 ******************************************************************************
555 * This function decrement the reference counter of a picture in the video heap.
556 ******************************************************************************/
557 void vout_UnlinkPicture( vout_thread_t *p_vout, picture_t *p_pic )
559 vlc_mutex_lock( &p_vout->picture_lock );
563 if( p_pic->i_refcount < 0 )
565 intf_DbgMsg("error: refcount < 0\n");
566 p_pic->i_refcount = 0;
570 if( (p_pic->i_refcount == 0) && (p_pic->i_status == DISPLAYED_PICTURE) )
572 p_pic->i_status = DESTROYED_PICTURE;
576 intf_DbgMsg("picture %p refcount=%d\n", p_pic, p_pic->i_refcount );
579 vlc_mutex_unlock( &p_vout->picture_lock );
582 /******************************************************************************
583 * vout_SetBuffers: set buffers adresses
584 ******************************************************************************
585 * This function is called by system drivers to set buffers video memory
587 ******************************************************************************/
588 void vout_SetBuffers( vout_thread_t *p_vout, void *p_buf1, void *p_buf2 )
590 /* No picture previously */
591 p_vout->p_buffer[0].i_pic_x = 0;
592 p_vout->p_buffer[0].i_pic_y = 0;
593 p_vout->p_buffer[0].i_pic_width = 0;
594 p_vout->p_buffer[0].i_pic_height = 0;
595 p_vout->p_buffer[1].i_pic_x = 0;
596 p_vout->p_buffer[1].i_pic_y = 0;
597 p_vout->p_buffer[1].i_pic_width = 0;
598 p_vout->p_buffer[1].i_pic_height = 0;
600 /* The first area covers all the screen */
601 p_vout->p_buffer[0].i_areas = 1;
602 p_vout->p_buffer[0].pi_area_begin[0] = 0;
603 p_vout->p_buffer[0].pi_area_end[0] = p_vout->i_height - 1;
604 p_vout->p_buffer[1].i_areas = 1;
605 p_vout->p_buffer[1].pi_area_begin[0] = 0;
606 p_vout->p_buffer[1].pi_area_end[0] = p_vout->i_height - 1;
609 p_vout->p_buffer[0].p_data = p_buf1;
610 p_vout->p_buffer[1].p_data = p_buf2;
613 /* following functions are local */
615 /******************************************************************************
616 * InitThread: initialize video output thread
617 ******************************************************************************
618 * This function is called from RunThread and performs the second step of the
619 * initialization. It returns 0 on success. Note that the thread's flag are not
620 * modified inside this function.
621 ******************************************************************************/
622 static int InitThread( vout_thread_t *p_vout )
626 *p_vout->pi_status = THREAD_START;
628 /* Initialize output method - this function issues its own error messages */
629 if( vout_SysInit( p_vout ) )
634 /* Initialize convertion tables and functions */
635 if( vout_InitYUV( p_vout ) )
637 intf_ErrMsg("error: can't allocate YUV translation tables\n");
641 /* Mark thread as running and return */
642 p_vout->b_active = 1;
643 *p_vout->pi_status = THREAD_READY;
644 intf_DbgMsg("thread ready\n");
648 /******************************************************************************
649 * RunThread: video output thread
650 ******************************************************************************
651 * Video output thread. This function does only returns when the thread is
652 * terminated. It handles the pictures arriving in the video heap and the
653 * display device events.
654 ******************************************************************************/
655 static void RunThread( vout_thread_t *p_vout)
657 int i_index; /* index in heap */
658 mtime_t current_date; /* current date */
659 mtime_t display_date; /* display date */
660 boolean_t b_display; /* display flag */
661 picture_t * p_pic; /* picture pointer */
662 subpicture_t * p_subpic; /* subpicture pointer */
667 p_vout->b_error = InitThread( p_vout );
668 if( p_vout->b_error )
670 DestroyThread( p_vout, THREAD_ERROR );
676 * Main loop - it is not executed if an error occured during
679 while( (!p_vout->b_die) && (!p_vout->b_error) )
681 /* Initialize loop variables */
685 current_date = mdate();
688 * Find the picture to display - this operation does not need lock,
689 * since only READY_PICTUREs are handled
691 for( i_index = 0; i_index < VOUT_MAX_PICTURES; i_index++ )
693 if( (p_vout->p_picture[i_index].i_status == READY_PICTURE) &&
695 (p_vout->p_picture[i_index].date < display_date) ) )
697 p_pic = &p_vout->p_picture[i_index];
698 display_date = p_pic->date;
705 /* Computes FPS rate */
706 p_vout->p_fps_sample[ p_vout->c_fps_samples++ % VOUT_FPS_SAMPLES ] = display_date;
708 if( display_date < current_date )
710 /* Picture is late: it will be destroyed and the thread will sleep and
711 * go to next picture */
712 vlc_mutex_lock( &p_vout->picture_lock );
713 p_pic->i_status = p_pic->i_refcount ? DISPLAYED_PICTURE : DESTROYED_PICTURE;
714 intf_DbgMsg( "warning: late picture %p skipped refcount=%d\n", p_pic, p_pic->i_refcount );
715 vlc_mutex_unlock( &p_vout->picture_lock );
719 else if( display_date > current_date + VOUT_DISPLAY_DELAY )
721 /* A picture is ready to be rendered, but its rendering date is
722 * far from the current one so the thread will perform an empty loop
723 * as if no picture were found. The picture state is unchanged */
730 * Find the subpicture to display - this operation does not need lock, since
731 * only READY_SUBPICTURES are handled. If no picture has been selected,
732 * display_date will depend on the subpicture
737 * Perform rendering, sleep and display rendered picture
739 if( p_pic ) /* picture and perhaps subpicture */
741 b_display = p_vout->b_active;
742 p_vout->last_display_date = display_date;
746 /* Set picture dimensions and clear buffer */
747 SetBufferPicture( p_vout, p_pic );
749 /* Render picture and informations */
750 RenderPicture( p_vout, p_pic );
753 RenderPictureInfo( p_vout, p_pic );
754 RenderInfo( p_vout );
758 /* Remove picture from heap */
759 vlc_mutex_lock( &p_vout->picture_lock );
760 p_pic->i_status = p_pic->i_refcount ? DISPLAYED_PICTURE : DESTROYED_PICTURE;
761 vlc_mutex_unlock( &p_vout->picture_lock );
763 /* Render interface and subpicture */
764 if( b_display && p_vout->b_interface )
766 RenderInterface( p_vout );
772 RenderSubPicture( p_vout, p_subpic );
775 /* Remove subpicture from heap */
776 vlc_mutex_lock( &p_vout->subpicture_lock );
777 p_subpic->i_status = DESTROYED_SUBPICTURE;
778 vlc_mutex_unlock( &p_vout->subpicture_lock );
782 else if( p_subpic ) /* subpicture alone */
784 b_display = p_vout->b_active;
785 p_vout->last_display_date = display_date;
790 SetBufferPicture( p_vout, NULL );
792 /* Render informations, interface and subpicture */
795 RenderInfo( p_vout );
797 if( p_vout->b_interface )
799 RenderInterface( p_vout );
801 RenderSubPicture( p_vout, p_subpic );
804 /* Remove subpicture from heap */
805 vlc_mutex_lock( &p_vout->subpicture_lock );
806 p_subpic->i_status = DESTROYED_SUBPICTURE;
807 vlc_mutex_unlock( &p_vout->subpicture_lock );
809 else if( p_vout->b_active ) /* idle or interface screen alone */
811 if( p_vout->b_interface && 0 /* && ?? intf_change */ )
813 /* Interface has changed, so a new rendering is required - force
814 * it by setting last idle date to 0 */
815 p_vout->last_idle_date = 0;
818 /* Render idle screen and update idle date, then render interface if
820 b_display = RenderIdle( p_vout );
823 p_vout->last_idle_date = current_date;
824 if( p_vout->b_interface )
826 RenderInterface( p_vout );
837 * Sleep, wake up and display rendered picture
841 /* Store render time */
842 p_vout->render_time = mdate() - current_date;
845 /* Give back change lock */
846 vlc_mutex_unlock( &p_vout->change_lock );
848 /* Sleep a while or until a given date */
849 if( display_date != 0 )
851 mwait( display_date );
855 msleep( VOUT_IDLE_SLEEP );
858 /* On awakening, take back lock and send immediately picture to display,
859 * then swap buffers */
860 vlc_mutex_lock( &p_vout->change_lock );
862 intf_DbgMsg( "picture %p, subpicture %p\n", p_pic, p_subpic );
864 if( b_display && !(p_vout->i_changes & VOUT_NODISPLAY_CHANGE) )
866 vout_SysDisplay( p_vout );
867 p_vout->i_buffer_index = ++p_vout->i_buffer_index & 1;
871 * Check events and manage thread
873 if( vout_SysManage( p_vout ) | Manage( p_vout ) )
875 /* A fatal error occured, and the thread must terminate immediately,
876 * without displaying anything - setting b_error to 1 cause the
877 * immediate end of the main while() loop. */
883 * Error loop - wait until the thread destruction is requested
885 if( p_vout->b_error )
887 ErrorThread( p_vout );
892 DestroyThread( p_vout, THREAD_OVER );
893 intf_DbgMsg( "thread end\n" );
896 /******************************************************************************
897 * ErrorThread: RunThread() error loop
898 ******************************************************************************
899 * This function is called when an error occured during thread main's loop. The
900 * thread can still receive feed, but must be ready to terminate as soon as
902 ******************************************************************************/
903 static void ErrorThread( vout_thread_t *p_vout )
905 /* Wait until a `die' order */
907 while( !p_vout->b_die )
910 msleep( VOUT_IDLE_SLEEP );
914 /*******************************************************************************
915 * EndThread: thread destruction
916 *******************************************************************************
917 * This function is called when the thread ends after a sucessfull
918 * initialization. It frees all ressources allocated by InitThread.
919 *******************************************************************************/
920 static void EndThread( vout_thread_t *p_vout )
922 int i_index; /* index in heap */
926 *p_vout->pi_status = THREAD_END;
928 /* Destroy all remaining pictures and subpictures */
929 for( i_index = 0; i_index < VOUT_MAX_PICTURES; i_index++ )
931 if( p_vout->p_picture[i_index].i_status != FREE_PICTURE )
933 free( p_vout->p_picture[i_index].p_data );
935 if( p_vout->p_subpicture[i_index].i_status != FREE_SUBPICTURE )
937 free( p_vout->p_subpicture[i_index].p_data );
941 /* Destroy translation tables */
942 vout_EndYUV( p_vout );
943 vout_SysEnd( p_vout );
946 /*******************************************************************************
947 * DestroyThread: thread destruction
948 *******************************************************************************
949 * This function is called when the thread ends. It frees all ressources
950 * allocated by CreateThread. Status is available at this stage.
951 *******************************************************************************/
952 static void DestroyThread( vout_thread_t *p_vout, int i_status )
954 int *pi_status; /* status adress */
956 /* Store status adress */
958 pi_status = p_vout->pi_status;
960 /* Destroy thread structures allocated by Create and InitThread */
961 vout_UnloadFont( p_vout->p_default_font );
962 vout_UnloadFont( p_vout->p_large_font );
963 vout_SysDestroy( p_vout );
965 *pi_status = i_status;
968 /*******************************************************************************
969 * Print: print simple text on a picture
970 *******************************************************************************
971 * This function will print a simple text on the picture. It is designed to
972 * print debugging or general informations.
973 *******************************************************************************/
974 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 )
976 int i_text_height; /* total text height */
977 int i_text_width; /* total text width */
979 /* Update upper left coordinates according to alignment */
980 vout_TextSize( p_vout->p_default_font, 0, psz_text, &i_text_width, &i_text_height );
981 if( !Align( p_vout, &i_x, &i_y, i_text_width, i_text_height, i_h_align, i_v_align ) )
983 /* Set area and print text */
984 SetBufferArea( p_vout, i_x, i_y, i_text_width, i_text_height );
985 vout_Print( p_vout->p_default_font, p_vout->p_buffer[ p_vout->i_buffer_index ].p_data +
986 i_y * p_vout->i_bytes_per_line + i_x * p_vout->i_bytes_per_pixel,
987 p_vout->i_bytes_per_pixel, p_vout->i_bytes_per_line,
988 0xffffffff, 0x00000000, 0x00000000, 0, psz_text );
992 /*******************************************************************************
993 * SetBufferArea: activate an area in current buffer
994 *******************************************************************************
995 * This function is called when something is rendered on the current buffer.
996 * It set the area as active and prepare it to be cleared on next rendering.
997 * Pay attention to the fact that in this functions, i_h is in fact the end y
998 * coordinate of the new area.
999 *******************************************************************************/
1000 static void SetBufferArea( vout_thread_t *p_vout, int i_x, int i_y, int i_w, int i_h )
1002 vout_buffer_t * p_buffer; /* current buffer */
1003 int i_area_begin, i_area_end; /* area vertical extension */
1004 int i_area, i_area_copy; /* area index */
1005 int i_area_shift; /* shift distance for areas */
1007 /* Choose buffer and modify h to end of area position */
1008 p_buffer = &p_vout->p_buffer[ p_vout->i_buffer_index ];
1012 * Remove part of the area which is inside the picture - this is done
1013 * by calling again SetBufferArea with the correct areas dimensions.
1015 if( (i_x >= p_buffer->i_pic_x) && (i_x + i_w <= p_buffer->i_pic_x + p_buffer->i_pic_width) )
1017 i_area_begin = p_buffer->i_pic_y;
1018 i_area_end = i_area_begin + p_buffer->i_pic_height - 1;
1020 if( ((i_y >= i_area_begin) && (i_y <= i_area_end)) ||
1021 ((i_h >= i_area_begin) && (i_h <= i_area_end)) ||
1022 ((i_y < i_area_begin) && (i_h > i_area_end)) )
1024 /* Keep the stripe above the picture, if any */
1025 if( i_y < i_area_begin )
1027 SetBufferArea( p_vout, i_x, i_y, i_w, i_area_begin - i_y );
1029 /* Keep the stripe below the picture, if any */
1030 if( i_h > i_area_end )
1032 SetBufferArea( p_vout, i_x, i_area_end, i_w, i_h - i_area_end );
1038 /* Skip some extensions until interesting areas */
1040 (i_area < p_buffer->i_areas) &&
1041 (p_buffer->pi_area_end[i_area] + 1 <= i_y);
1047 if( i_area == p_buffer->i_areas )
1049 /* New area is below all existing ones: just add it at the end of the
1050 * array, if possible - else, append it to the last one */
1051 if( i_area < VOUT_MAX_AREAS )
1053 p_buffer->pi_area_begin[i_area] = i_y;
1054 p_buffer->pi_area_end[i_area] = i_h;
1055 p_buffer->i_areas++;
1060 intf_DbgMsg("areas overflow\n");
1062 p_buffer->pi_area_end[VOUT_MAX_AREAS - 1] = i_h;
1067 i_area_begin = p_buffer->pi_area_begin[i_area];
1068 i_area_end = p_buffer->pi_area_end[i_area];
1070 if( i_y < i_area_begin )
1072 if( i_h >= i_area_begin - 1 )
1074 /* Extend area above */
1075 p_buffer->pi_area_begin[i_area] = i_y;
1079 /* Create a new area above : merge last area if overflow, then
1080 * move all old areas down */
1081 if( p_buffer->i_areas == VOUT_MAX_AREAS )
1084 intf_DbgMsg("areas overflow\n");
1086 p_buffer->pi_area_end[VOUT_MAX_AREAS - 2] = p_buffer->pi_area_end[VOUT_MAX_AREAS - 1];
1090 p_buffer->i_areas++;
1092 for( i_area_copy = p_buffer->i_areas - 1; i_area_copy > i_area; i_area_copy-- )
1094 p_buffer->pi_area_begin[i_area_copy] = p_buffer->pi_area_begin[i_area_copy - 1];
1095 p_buffer->pi_area_end[i_area_copy] = p_buffer->pi_area_end[i_area_copy - 1];
1097 p_buffer->pi_area_begin[i_area] = i_y;
1098 p_buffer->pi_area_end[i_area] = i_h;
1102 if( i_h > i_area_end )
1104 /* Find further areas which can be merged with the new one */
1105 for( i_area_copy = i_area + 1;
1106 (i_area_copy < p_buffer->i_areas) &&
1107 (p_buffer->pi_area_begin[i_area] <= i_h);
1114 if( i_area_copy != i_area )
1116 /* Merge with last possible areas */
1117 p_buffer->pi_area_end[i_area] = MAX( i_h, p_buffer->pi_area_end[i_area_copy] );
1119 /* Shift lower areas upward */
1120 i_area_shift = i_area_copy - i_area;
1121 p_buffer->i_areas -= i_area_shift;
1122 for( i_area_copy = i_area + 1; i_area_copy < p_buffer->i_areas; i_area_copy++ )
1124 p_buffer->pi_area_begin[i_area_copy] = p_buffer->pi_area_begin[i_area_copy + i_area_shift];
1125 p_buffer->pi_area_end[i_area_copy] = p_buffer->pi_area_end[i_area_copy + i_area_shift];
1130 /* Extend area below */
1131 p_buffer->pi_area_end[i_area] = i_h;
1137 /*******************************************************************************
1138 * SetBufferPicture: clear buffer and set picture area
1139 *******************************************************************************
1140 * This function is called before any rendering. It clears the current
1141 * rendering buffer and set the new picture area. If the picture pointer is
1142 * NULL, then no picture area is defined. Floating operations are avoided since
1143 * some MMX calculations may follow.
1144 *******************************************************************************/
1145 static void SetBufferPicture( vout_thread_t *p_vout, picture_t *p_pic )
1147 vout_buffer_t * p_buffer; /* current buffer */
1148 int i_pic_x, i_pic_y; /* picture position */
1149 int i_pic_width, i_pic_height; /* picture dimensions */
1150 int i_old_pic_y, i_old_pic_height; /* old picture area */
1151 int i_vout_width, i_vout_height; /* display dimensions */
1152 int i_area; /* area index */
1153 int i_data_index; /* area data index */
1154 int i_data_size; /* area data size, in 256 bytes blocs */
1155 u64 * p_data; /* area data */
1157 /* Choose buffer and set display dimensions */
1158 p_buffer = &p_vout->p_buffer[ p_vout->i_buffer_index ];
1159 i_vout_width = p_vout->i_width;
1160 i_vout_height = p_vout->i_height;
1163 * Computes new picture size
1167 /* Try horizontal scaling first */
1168 i_pic_width = ( p_vout->b_scale || (p_pic->i_width > i_vout_width)) ?
1169 i_vout_width : p_pic->i_width;
1170 i_pic_width = i_pic_width / 16 * 16; //?? currently, width must be multiple of 16
1171 switch( p_pic->i_aspect_ratio )
1173 case AR_3_4_PICTURE:
1174 i_pic_height = i_pic_width * 3 / 4;
1176 case AR_16_9_PICTURE:
1177 i_pic_height = i_pic_width * 9 / 16;
1179 case AR_221_1_PICTURE:
1180 i_pic_height = i_pic_width * 100 / 221;
1182 case AR_SQUARE_PICTURE:
1184 i_pic_height = p_pic->i_height * i_pic_width / p_pic->i_width;
1188 /* If picture dimensions using horizontal scaling are too large, use
1189 * vertical scaling */
1190 if( i_pic_height > i_vout_height )
1192 i_pic_height = ( p_vout->b_scale || (p_pic->i_height > i_vout_height)) ?
1193 i_vout_height : p_pic->i_height;
1194 switch( p_pic->i_aspect_ratio )
1196 case AR_3_4_PICTURE:
1197 i_pic_width = i_pic_height * 4 / 3;
1199 case AR_16_9_PICTURE:
1200 i_pic_width = i_pic_height * 16 / 9;
1202 case AR_221_1_PICTURE:
1203 i_pic_width = i_pic_height * 221 / 100;
1205 case AR_SQUARE_PICTURE:
1207 i_pic_width = p_pic->i_width * i_pic_height / p_pic->i_height;
1210 i_pic_width = i_pic_width / 16 * 16; //?? currently, width must be multiple of 16
1213 /* Set picture position */
1214 i_pic_x = (p_vout->i_width - i_pic_width) / 2;
1215 i_pic_y = (p_vout->i_height - i_pic_height) / 2;
1219 /* No picture: size is 0 */
1227 * Set new picture size - if is is smaller than the previous one, clear
1228 * around it. Since picture are centered, only their size is tested.
1230 if( (p_buffer->i_pic_width > i_pic_width) || (p_buffer->i_pic_height > i_pic_height) )
1232 i_old_pic_y = p_buffer->i_pic_y;
1233 i_old_pic_height = p_buffer->i_pic_height;
1234 p_buffer->i_pic_x = i_pic_x;
1235 p_buffer->i_pic_y = i_pic_y;
1236 p_buffer->i_pic_width = i_pic_width;
1237 p_buffer->i_pic_height = i_pic_height;
1238 SetBufferArea( p_vout, 0, i_old_pic_y, p_vout->i_width, i_old_pic_height );
1242 p_buffer->i_pic_x = i_pic_x;
1243 p_buffer->i_pic_y = i_pic_y;
1244 p_buffer->i_pic_width = i_pic_width;
1245 p_buffer->i_pic_height = i_pic_height;
1251 for( i_area = 0; i_area < p_buffer->i_areas; i_area++ )
1254 intf_DbgMsg("clearing picture %p area: %d-%d\n", p_pic,
1255 p_buffer->pi_area_begin[i_area], p_buffer->pi_area_end[i_area]);
1257 p_data = (u64*) (p_buffer->p_data + p_vout->i_bytes_per_line * p_buffer->pi_area_begin[i_area]);
1258 i_data_size = (p_buffer->pi_area_end[i_area] - p_buffer->pi_area_begin[i_area] + 1) *
1259 p_vout->i_bytes_per_line / 256;
1260 for( i_data_index = 0; i_data_index < i_data_size; i_data_index++ )
1262 /* Clear 256 bytes block */
1263 *p_data++ = 0; *p_data++ = 0; *p_data++ = 0; *p_data++ = 0;
1264 *p_data++ = 0; *p_data++ = 0; *p_data++ = 0; *p_data++ = 0;
1265 *p_data++ = 0; *p_data++ = 0; *p_data++ = 0; *p_data++ = 0;
1266 *p_data++ = 0; *p_data++ = 0; *p_data++ = 0; *p_data++ = 0;
1267 *p_data++ = 0; *p_data++ = 0; *p_data++ = 0; *p_data++ = 0;
1268 *p_data++ = 0; *p_data++ = 0; *p_data++ = 0; *p_data++ = 0;
1269 *p_data++ = 0; *p_data++ = 0; *p_data++ = 0; *p_data++ = 0;
1270 *p_data++ = 0; *p_data++ = 0; *p_data++ = 0; *p_data++ = 0;
1272 i_data_size = (p_buffer->pi_area_end[i_area] - p_buffer->pi_area_begin[i_area] + 1) *
1273 p_vout->i_bytes_per_line % 256 / 4;
1274 for( i_data_index = 0; i_data_index < i_data_size; i_data_index++ )
1276 /* Clear remaining 4 bytes blocks */
1284 p_buffer->i_areas = 0;
1287 /******************************************************************************
1288 * RenderPicture: render a picture
1289 ******************************************************************************
1290 * This function convert a picture from a video heap to a pixel-encoded image
1291 * and copy it to the current rendering buffer. No lock is required, since the
1292 * rendered picture has been determined as existant, and will only be destroyed
1293 * by the vout thread later.
1294 ******************************************************************************/
1295 static void RenderPicture( vout_thread_t *p_vout, picture_t *p_pic )
1297 vout_buffer_t * p_buffer; /* rendering buffer */
1298 byte_t * p_pic_data; /* convertion destination */
1300 /* Get and set rendering informations */
1301 p_buffer = &p_vout->p_buffer[ p_vout->i_buffer_index ];
1302 p_pic_data = p_buffer->p_data +
1303 p_buffer->i_pic_x * p_vout->i_bytes_per_pixel +
1304 p_buffer->i_pic_y * p_vout->i_bytes_per_line;
1307 * Choose appropriate rendering function and render picture
1309 switch( p_pic->i_type )
1311 case YUV_420_PICTURE:
1312 p_vout->yuv.p_Convert420( p_vout, p_pic_data,
1313 p_pic->p_y, p_pic->p_u, p_pic->p_v,
1314 p_pic->i_width, p_pic->i_height, 0,
1315 p_buffer->i_pic_width, p_buffer->i_pic_height,
1316 p_vout->i_bytes_per_line / p_vout->i_bytes_per_pixel - p_buffer->i_pic_width,
1317 p_pic->i_matrix_coefficients );
1319 case YUV_422_PICTURE:
1320 p_vout->yuv.p_Convert422( p_vout, p_pic_data,
1321 p_pic->p_y, p_pic->p_u, p_pic->p_v,
1322 p_pic->i_width, p_pic->i_height, 0,
1323 p_buffer->i_pic_width, p_buffer->i_pic_height,
1324 p_vout->i_bytes_per_line / p_vout->i_bytes_per_pixel - p_buffer->i_pic_width,
1325 p_pic->i_matrix_coefficients );
1327 case YUV_444_PICTURE:
1328 p_vout->yuv.p_Convert444( p_vout, p_pic_data,
1329 p_pic->p_y, p_pic->p_u, p_pic->p_v,
1330 p_pic->i_width, p_pic->i_height, 0,
1331 p_buffer->i_pic_width, p_buffer->i_pic_height,
1332 p_vout->i_bytes_per_line / p_vout->i_bytes_per_pixel - p_buffer->i_pic_width,
1333 p_pic->i_matrix_coefficients );
1337 intf_DbgMsg("error: unknown picture type %d\n", p_pic->i_type );
1343 /******************************************************************************
1344 * RenderPictureInfo: print additionnal informations on a picture
1345 ******************************************************************************
1346 * This function will print informations such as fps and other picture
1347 * dependant informations.
1348 ******************************************************************************/
1349 static void RenderPictureInfo( vout_thread_t *p_vout, picture_t *p_pic )
1351 #if defined(STATS) || defined(DEBUG)
1352 char psz_buffer[256]; /* string buffer */
1357 * Print FPS rate in upper right corner
1359 if( p_vout->c_fps_samples > VOUT_FPS_SAMPLES )
1361 sprintf( psz_buffer, "%.2f fps", (double) VOUT_FPS_SAMPLES * 1000000 /
1362 ( p_vout->p_fps_sample[ (p_vout->c_fps_samples - 1) % VOUT_FPS_SAMPLES ] -
1363 p_vout->p_fps_sample[ p_vout->c_fps_samples % VOUT_FPS_SAMPLES ] ) );
1364 Print( p_vout, 0, 0, RIGHT_RALIGN, TOP_RALIGN, psz_buffer );
1368 * Print frames count and loop time in upper left corner
1370 sprintf( psz_buffer, "%ld frames rendering: %ld us",
1371 (long) p_vout->c_fps_samples, (long) p_vout->render_time );
1372 Print( p_vout, 0, 0, LEFT_RALIGN, TOP_RALIGN, psz_buffer );
1377 * Print picture information in lower right corner
1379 sprintf( psz_buffer, "%s picture %dx%d (%dx%d%+d%+d %s) -> %dx%d+%d+%d",
1380 (p_pic->i_type == YUV_420_PICTURE) ? "4:2:0" :
1381 ((p_pic->i_type == YUV_422_PICTURE) ? "4:2:2" :
1382 ((p_pic->i_type == YUV_444_PICTURE) ? "4:4:4" : "ukn-type")),
1383 p_pic->i_width, p_pic->i_height,
1384 p_pic->i_display_width, p_pic->i_display_height,
1385 p_pic->i_display_horizontal_offset, p_pic->i_display_vertical_offset,
1386 (p_pic->i_aspect_ratio == AR_SQUARE_PICTURE) ? "sq" :
1387 ((p_pic->i_aspect_ratio == AR_3_4_PICTURE) ? "4:3" :
1388 ((p_pic->i_aspect_ratio == AR_16_9_PICTURE) ? "16:9" :
1389 ((p_pic->i_aspect_ratio == AR_221_1_PICTURE) ? "2.21:1" : "ukn-ar" ))),
1390 p_vout->p_buffer[ p_vout->i_buffer_index ].i_pic_width,
1391 p_vout->p_buffer[ p_vout->i_buffer_index ].i_pic_height,
1392 p_vout->p_buffer[ p_vout->i_buffer_index ].i_pic_x,
1393 p_vout->p_buffer[ p_vout->i_buffer_index ].i_pic_y );
1394 Print( p_vout, 0, 0, RIGHT_RALIGN, BOTTOM_RALIGN, psz_buffer );
1398 /******************************************************************************
1399 * RenderIdle: render idle picture
1400 ******************************************************************************
1401 * This function will print something on the screen. It will return 0 if
1402 * nothing has been rendered, or 1 if something has been changed on the screen.
1403 * Note that if you absolutely want something to be printed, you will have
1404 * to force it by setting the last idle date to 0.
1405 * Unlike other rendering functions, this one calls the SetBufferPicture
1406 * function when needed.
1407 ******************************************************************************/
1408 static int RenderIdle( vout_thread_t *p_vout )
1410 int i_x = 0, i_y = 0; /* text position */
1411 int i_width, i_height; /* text size */
1412 mtime_t current_date; /* current date */
1413 const char *psz_text = "no stream"; /* text to display */
1416 current_date = mdate();
1417 if( (current_date - p_vout->last_display_date) > VOUT_IDLE_DELAY &&
1418 (current_date - p_vout->last_idle_date) > VOUT_IDLE_DELAY )
1420 SetBufferPicture( p_vout, NULL );
1421 vout_TextSize( p_vout->p_large_font, WIDE_TEXT | OUTLINED_TEXT, psz_text,
1422 &i_width, &i_height );
1423 if( !Align( p_vout, &i_x, &i_y, i_width, i_height, CENTER_RALIGN, CENTER_RALIGN ) )
1425 vout_Print( p_vout->p_large_font,
1426 p_vout->p_buffer[ p_vout->i_buffer_index ].p_data +
1427 i_x * p_vout->i_bytes_per_pixel + i_y * p_vout->i_bytes_per_line,
1428 p_vout->i_bytes_per_pixel, p_vout->i_bytes_per_line,
1429 0xffffffff, 0x33333333, 0,
1430 WIDE_TEXT | OUTLINED_TEXT, psz_text );
1431 SetBufferArea( p_vout, i_x, i_y, i_width, i_height );
1438 /******************************************************************************
1439 * RenderInfo: render additionnal informations
1440 ******************************************************************************
1441 * This function render informations which do not depend of the current picture
1443 ******************************************************************************/
1444 static void RenderInfo( vout_thread_t *p_vout )
1447 char psz_buffer[256]; /* string buffer */
1448 int i_ready_pic = 0; /* ready pictures */
1449 int i_reserved_pic = 0; /* reserved pictures */
1450 int i_picture; /* picture index */
1455 * Print thread state in lower left corner
1457 for( i_picture = 0; i_picture < VOUT_MAX_PICTURES; i_picture++ )
1459 switch( p_vout->p_picture[i_picture].i_status )
1461 case RESERVED_PICTURE:
1462 case RESERVED_DATED_PICTURE:
1463 case RESERVED_DISP_PICTURE:
1471 sprintf( psz_buffer, "pic: %d/%d/%d",
1472 i_reserved_pic, i_ready_pic, VOUT_MAX_PICTURES );
1473 Print( p_vout, 0, 0, LEFT_RALIGN, BOTTOM_RALIGN, psz_buffer );
1477 /*******************************************************************************
1478 * RenderSubPicture: render a subpicture
1479 *******************************************************************************
1480 * This function render a sub picture unit.
1481 *******************************************************************************/
1482 static void RenderSubPicture( vout_thread_t *p_vout, subpicture_t *p_subpic )
1487 /*******************************************************************************
1488 * RenderInterface: render the interface
1489 *******************************************************************************
1490 * This function render the interface, if any.
1491 *******************************************************************************/
1492 static void RenderInterface( vout_thread_t *p_vout )
1494 int i_height, i_text_height; /* total and text height */
1495 int i_width_1, i_width_2; /* text width */
1496 int i_byte; /* byte index */
1497 const char *psz_text_1 = "[1-9] Channel [i]nfo [c]olor [g/G]amma";
1498 const char *psz_text_2 = "[+/-] Volume [m]ute [s]caling [Q]uit";
1501 vout_TextSize( p_vout->p_large_font, OUTLINED_TEXT, psz_text_1, &i_width_1, &i_height );
1502 vout_TextSize( p_vout->p_large_font, OUTLINED_TEXT, psz_text_2, &i_width_2, &i_text_height );
1503 i_height += i_text_height;
1505 /* Render background - effective background color will depend of the screen
1507 for( i_byte = (p_vout->i_height - i_height) * p_vout->i_bytes_per_line;
1508 i_byte < p_vout->i_height * p_vout->i_bytes_per_line;
1511 p_vout->p_buffer[ p_vout->i_buffer_index ].p_data[ i_byte ] = 0x33;
1514 /* Render text, if not larger than screen */
1515 if( i_width_1 < p_vout->i_width )
1517 vout_Print( p_vout->p_large_font, p_vout->p_buffer[ p_vout->i_buffer_index ].p_data +
1518 (p_vout->i_height - i_height) * p_vout->i_bytes_per_line,
1519 p_vout->i_bytes_per_pixel, p_vout->i_bytes_per_line,
1520 0xffffffff, 0x00000000, 0x00000000,
1521 OUTLINED_TEXT, psz_text_1 );
1523 if( i_width_2 < p_vout->i_width )
1525 vout_Print( p_vout->p_large_font, p_vout->p_buffer[ p_vout->i_buffer_index ].p_data +
1526 (p_vout->i_height - i_height + i_text_height) * p_vout->i_bytes_per_line,
1527 p_vout->i_bytes_per_pixel, p_vout->i_bytes_per_line,
1528 0xffffffff, 0x00000000, 0x00000000,
1529 OUTLINED_TEXT, psz_text_2 );
1532 /* Activate modified area */
1533 SetBufferArea( p_vout, 0, p_vout->i_height - i_height, p_vout->i_width, i_height );
1536 /******************************************************************************
1537 * Manage: manage thread
1538 ******************************************************************************
1539 * This function will handle changes in thread configuration.
1540 ******************************************************************************/
1541 static int Manage( vout_thread_t *p_vout )
1544 if( p_vout->i_changes )
1546 intf_DbgMsg("changes: 0x%x (no display: 0x%x)\n", p_vout->i_changes,
1547 p_vout->i_changes & VOUT_NODISPLAY_CHANGE );
1551 /* On gamma or grayscale change, rebuild tables */
1552 if( p_vout->i_changes & (VOUT_GAMMA_CHANGE | VOUT_GRAYSCALE_CHANGE |
1555 if( vout_ResetYUV( p_vout ) )
1557 intf_ErrMsg("error: can't rebuild convertion tables\n");
1562 /* Clear changes flags which does not need management or have been
1564 p_vout->i_changes &= ~(VOUT_GAMMA_CHANGE | VOUT_GRAYSCALE_CHANGE |
1565 VOUT_YUV_CHANGE | VOUT_INFO_CHANGE |
1566 VOUT_INTF_CHANGE | VOUT_SCALE_CHANGE );
1568 /* Detect unauthorized changes */
1569 if( p_vout->i_changes )
1571 /* Some changes were not acknowledged by vout_SysManage or this function,
1572 * it means they should not be authorized */
1573 intf_ErrMsg( "error: unauthorized changes in the video output thread\n" );
1580 /******************************************************************************
1581 * Align: align a subpicture in the screen
1582 ******************************************************************************
1583 * This function is used for rendering text or subpictures. It returns non 0
1584 * it the final aera is not fully included in display area. Return coordinates
1586 ******************************************************************************/
1587 static int Align( vout_thread_t *p_vout, int *pi_x, int *pi_y,
1588 int i_width, int i_height, int i_h_align, int i_v_align )
1590 /* Align horizontally */
1594 *pi_x -= i_width / 2;
1597 *pi_x += (p_vout->i_width - i_width) / 2;
1603 *pi_x += p_vout->i_width - i_width;
1607 /* Align vertically */
1611 *pi_y -= i_height / 2;
1614 *pi_y += (p_vout->i_height - i_height) / 2;
1620 *pi_y += p_vout->i_height - i_height;
1622 case SUBTITLE_RALIGN:
1623 *pi_y += (p_vout->i_height + p_vout->p_buffer[ p_vout->i_buffer_index ].i_pic_y +
1624 p_vout->p_buffer[ p_vout->i_buffer_index ].i_pic_height - i_height) / 2;
1628 /* Return non 0 if clipping failed */
1629 return( (*pi_x < 0) || (*pi_y < 0) ||
1630 (*pi_x + i_width > p_vout->i_width) || (*pi_y + i_height > p_vout->i_height) );