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-2001 VideoLAN
8 * $Id: video_output.c,v 1.180 2002/05/29 18:39:14 sam Exp $
10 * Authors: Vincent Seguin <seguin@via.ecp.fr>
12 * This program is free software; you can redistribute it and/or modify
13 * it under the terms of the GNU General Public License as published by
14 * the Free Software Foundation; either version 2 of the License, or
15 * (at your option) any later version.
17 * This program is distributed in the hope that it will be useful,
18 * but WITHOUT ANY WARRANTY; without even the implied warranty of
19 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 * GNU General Public License for more details.
22 * You should have received a copy of the GNU General Public License
23 * along with this program; if not, write to the Free Software
24 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111, USA.
25 *****************************************************************************/
27 /*****************************************************************************
29 *****************************************************************************/
30 #include <errno.h> /* ENOMEM */
31 #include <stdlib.h> /* free() */
32 #include <stdio.h> /* sprintf() */
33 #include <string.h> /* strerror() */
35 #include <videolan/vlc.h>
37 #ifdef HAVE_SYS_TIMES_H
38 # include <sys/times.h>
42 #include "video_output.h"
44 /*****************************************************************************
46 *****************************************************************************/
47 static int InitThread ( vout_thread_t *p_vout );
48 static void RunThread ( vout_thread_t *p_vout );
49 static void ErrorThread ( vout_thread_t *p_vout );
50 static void EndThread ( vout_thread_t *p_vout );
51 static void DestroyThread ( vout_thread_t *p_vout, int i_status );
53 static int ReduceHeight ( int );
54 static int BinaryLog ( u32 );
55 static void MaskToShift ( int *, int *, u32 );
56 static void InitWindowSize ( vout_thread_t *, int *, int * );
58 /*****************************************************************************
59 * vout_InitBank: initialize the video output bank.
60 *****************************************************************************/
61 void vout_InitBank ( void )
63 p_vout_bank->i_count = 0;
65 vlc_mutex_init( &p_vout_bank->lock );
68 /*****************************************************************************
69 * vout_EndBank: empty the video output bank.
70 *****************************************************************************
71 * This function ends all unused video outputs and empties the bank in
73 *****************************************************************************/
74 void vout_EndBank ( void )
76 /* Ask all remaining video outputs to die */
77 while( p_vout_bank->i_count )
80 p_vout_bank->pp_vout[ --p_vout_bank->i_count ], NULL );
83 vlc_mutex_destroy( &p_vout_bank->lock );
86 /*****************************************************************************
87 * vout_CreateThread: creates a new video output thread
88 *****************************************************************************
89 * This function creates a new video output thread, and returns a pointer
90 * to its description. On error, it returns NULL.
91 * If pi_status is NULL, then the function will block until the thread is ready.
92 * If not, it will be updated using one of the THREAD_* constants.
93 *****************************************************************************/
94 vout_thread_t * vout_CreateThread ( int *pi_status,
95 int i_width, int i_height,
96 u32 i_chroma, int i_aspect )
98 vout_thread_t * p_vout; /* thread descriptor */
99 int i_status; /* thread status */
100 int i_index; /* loop variable */
103 /* Allocate descriptor */
104 p_vout = (vout_thread_t *) malloc( sizeof(vout_thread_t) );
107 intf_ErrMsg( "vout error: vout thread creation returned %s",
112 /* Choose the best module */
113 if( !(psz_plugin = config_GetPszVariable( "filter" )) )
115 psz_plugin = config_GetPszVariable( "vout" );
118 /* Initialize thread properties - thread id and locks will be initialized
122 p_vout->b_active = 0;
123 p_vout->pi_status = (pi_status != NULL) ? pi_status : &i_status;
124 *p_vout->pi_status = THREAD_CREATE;
126 /* Initialize pictures and subpictures - translation tables and functions
127 * will be initialized later in InitThread */
128 for( i_index = 0; i_index < 2 * VOUT_MAX_PICTURES; i_index++)
130 p_vout->p_picture[i_index].i_status = FREE_PICTURE;
131 p_vout->p_picture[i_index].i_type = EMPTY_PICTURE;
134 for( i_index = 0; i_index < VOUT_MAX_SUBPICTURES; i_index++)
136 p_vout->p_subpicture[i_index].i_status = FREE_SUBPICTURE;
137 p_vout->p_subpicture[i_index].i_type = EMPTY_SUBPICTURE;
140 /* No images in the heap */
141 p_vout->i_heap_size = 0;
143 /* Initialize the rendering heap */
144 I_RENDERPICTURES = 0;
145 p_vout->render.i_width = i_width;
146 p_vout->render.i_height = i_height;
147 p_vout->render.i_chroma = i_chroma;
148 p_vout->render.i_aspect = i_aspect;
150 p_vout->render.i_rmask = 0;
151 p_vout->render.i_gmask = 0;
152 p_vout->render.i_bmask = 0;
154 /* Zero the output heap */
155 I_OUTPUTPICTURES = 0;
156 p_vout->output.i_width = 0;
157 p_vout->output.i_height = 0;
158 p_vout->output.i_chroma = 0;
159 p_vout->output.i_aspect = 0;
161 p_vout->output.i_rmask = 0;
162 p_vout->output.i_gmask = 0;
163 p_vout->output.i_bmask = 0;
165 /* Initialize misc stuff */
166 p_vout->i_changes = 0;
168 p_vout->b_grayscale = 0;
170 p_vout->b_interface = 0;
172 p_vout->b_fullscreen = 0;
173 p_vout->render_time = 10;
174 p_vout->c_fps_samples= 0;
176 /* user requested fullscreen? */
177 if( config_GetIntVariable( "fullscreen" ) )
178 p_vout->i_changes |= VOUT_FULLSCREEN_CHANGE;
180 /* Initialize the dimensions of the video window */
181 InitWindowSize( p_vout, &p_vout->i_window_width,
182 &p_vout->i_window_height );
186 = module_Need( MODULE_CAPABILITY_VOUT, psz_plugin, (void *)p_vout );
188 if( psz_plugin ) free( psz_plugin );
189 if( p_vout->p_module == NULL )
191 intf_ErrMsg( "vout error: no suitable vout module" );
196 #define f p_vout->p_module->p_functions->vout.functions.vout
197 p_vout->pf_create = f.pf_create;
198 p_vout->pf_init = f.pf_init;
199 p_vout->pf_end = f.pf_end;
200 p_vout->pf_destroy = f.pf_destroy;
201 p_vout->pf_manage = f.pf_manage;
202 p_vout->pf_render = f.pf_render;
203 p_vout->pf_display = f.pf_display;
206 /* Create thread and set locks */
207 vlc_mutex_init( &p_vout->picture_lock );
208 vlc_mutex_init( &p_vout->subpicture_lock );
209 vlc_mutex_init( &p_vout->change_lock );
211 if( vlc_thread_create( &p_vout->thread_id, "video output",
212 (void *) RunThread, (void *) p_vout) )
214 intf_ErrMsg("vout error: %s", strerror(ENOMEM));
215 p_vout->pf_destroy( p_vout );
216 module_Unneed( p_vout->p_module );
221 /* If status is NULL, wait until the thread is created */
222 if( pi_status == NULL )
226 msleep( THREAD_SLEEP );
227 }while( (i_status != THREAD_READY) && (i_status != THREAD_ERROR)
228 && (i_status != THREAD_FATAL) );
229 if( i_status != THREAD_READY )
238 /*****************************************************************************
239 * vout_DestroyThread: destroys a previously created thread
240 *****************************************************************************
241 * Destroy a terminated thread.
242 * The function will request a destruction of the specified thread. If pi_error
243 * is NULL, it will return once the thread is destroyed. Else, it will be
244 * update using one of the THREAD_* constants.
245 *****************************************************************************/
246 void vout_DestroyThread( vout_thread_t *p_vout, int *pi_status )
248 int i_status; /* thread status */
251 p_vout->pi_status = (pi_status != NULL) ? pi_status : &i_status;
252 *p_vout->pi_status = THREAD_DESTROY;
254 /* Request thread destruction */
256 /* only if pi_status is NULL */
257 vlc_thread_join( p_vout->thread_id );
263 /*****************************************************************************
264 * vout_ChromaCmp: compare two chroma values
265 *****************************************************************************
266 * This function returns 1 if the two fourcc values given as argument are
267 * the same format (eg. UYVY / UYNV) or almost the same format (eg. I420/YV12)
268 *****************************************************************************/
269 int vout_ChromaCmp( u32 i_chroma, u32 i_amorhc )
271 /* If they are the same, they are the same ! */
272 if( i_chroma == i_amorhc )
277 /* Check for equivalence classes */
325 /*****************************************************************************
326 * InitThread: initialize video output thread
327 *****************************************************************************
328 * This function is called from RunThread and performs the second step of the
329 * initialization. It returns 0 on success. Note that the thread's flag are not
330 * modified inside this function.
331 *****************************************************************************/
332 static int InitThread( vout_thread_t *p_vout )
337 *p_vout->pi_status = THREAD_START;
339 vlc_mutex_lock( &p_vout->change_lock );
345 /* Initialize output method, it allocates direct buffers for us */
346 if( p_vout->pf_init( p_vout ) )
348 vlc_mutex_unlock( &p_vout->change_lock );
352 if( !I_OUTPUTPICTURES )
354 intf_ErrMsg( "vout error: plugin was unable to allocate at least "
355 "one direct buffer" );
356 p_vout->pf_end( p_vout );
357 vlc_mutex_unlock( &p_vout->change_lock );
361 intf_WarnMsg( 1, "vout info: got %i direct buffer(s)", I_OUTPUTPICTURES );
363 i_pgcd = ReduceHeight( p_vout->render.i_aspect );
364 intf_WarnMsg( 1, "vout info: picture in %ix%i, chroma 0x%.8x (%4.4s), "
365 "aspect ratio %i:%i",
366 p_vout->render.i_width, p_vout->render.i_height,
367 p_vout->render.i_chroma, (char*)&p_vout->render.i_chroma,
368 p_vout->render.i_aspect / i_pgcd,
369 VOUT_ASPECT_FACTOR / i_pgcd );
371 i_pgcd = ReduceHeight( p_vout->output.i_aspect );
372 intf_WarnMsg( 1, "vout info: picture out %ix%i, chroma 0x%.8x (%4.4s), "
373 "aspect ratio %i:%i",
374 p_vout->output.i_width, p_vout->output.i_height,
375 p_vout->output.i_chroma, (char*)&p_vout->output.i_chroma,
376 p_vout->output.i_aspect / i_pgcd,
377 VOUT_ASPECT_FACTOR / i_pgcd );
379 /* Calculate shifts from system-updated masks */
380 MaskToShift( &p_vout->output.i_lrshift, &p_vout->output.i_rrshift,
381 p_vout->output.i_rmask );
382 MaskToShift( &p_vout->output.i_lgshift, &p_vout->output.i_rgshift,
383 p_vout->output.i_gmask );
384 MaskToShift( &p_vout->output.i_lbshift, &p_vout->output.i_rbshift,
385 p_vout->output.i_bmask );
387 /* Check whether we managed to create direct buffers similar to
388 * the render buffers, ie same size, chroma and aspect ratio */
389 if( ( p_vout->output.i_width == p_vout->render.i_width )
390 && ( p_vout->output.i_height == p_vout->render.i_height )
391 && ( vout_ChromaCmp( p_vout->output.i_chroma, p_vout->render.i_chroma ) )
392 && ( p_vout->output.i_aspect == p_vout->render.i_aspect ) )
394 /* Cool ! We have direct buffers, we can ask the decoder to
395 * directly decode into them ! Map the first render buffers to
396 * the first direct buffers, but keep the first direct buffer
397 * for memcpy operations */
398 p_vout->b_direct = 1;
400 intf_WarnMsg( 2, "vout info: direct render, mapping "
401 "render pictures 0-%i to system pictures 1-%i",
402 VOUT_MAX_PICTURES - 2, VOUT_MAX_PICTURES - 1 );
404 for( i = 1; i < VOUT_MAX_PICTURES; i++ )
406 PP_RENDERPICTURE[ I_RENDERPICTURES ] = &p_vout->p_picture[ i ];
412 /* Rats... Something is wrong here, we could not find an output
413 * plugin able to directly render what we decode. See if we can
414 * find a chroma plugin to do the conversion */
415 p_vout->b_direct = 0;
417 /* Choose the best module */
418 p_vout->chroma.p_module
419 = module_Need( MODULE_CAPABILITY_CHROMA, NULL, (void *)p_vout );
421 if( p_vout->chroma.p_module == NULL )
423 intf_ErrMsg( "vout error: no chroma module for %4.4s to %4.4s",
424 &p_vout->render.i_chroma, &p_vout->output.i_chroma );
425 p_vout->pf_end( p_vout );
426 vlc_mutex_unlock( &p_vout->change_lock );
430 #define f p_vout->chroma.p_module->p_functions->chroma.functions.chroma
431 p_vout->chroma.pf_init = f.pf_init;
432 p_vout->chroma.pf_end = f.pf_end;
435 if( I_OUTPUTPICTURES < 2 * VOUT_MAX_PICTURES )
437 intf_WarnMsg( 2, "vout info: indirect render, mapping "
438 "render pictures %i-%i to system pictures %i-%i",
439 I_OUTPUTPICTURES - 1, 2 * VOUT_MAX_PICTURES - 2,
440 I_OUTPUTPICTURES, 2 * VOUT_MAX_PICTURES - 1 );
444 /* FIXME: if this happens, we don't have any render picture left */
445 intf_WarnMsg( 2, "vout info: indirect render, no system "
446 "pictures needed, we have %i directbuffers",
448 intf_ErrMsg( "vout: this is a bug!\n");
451 /* Append render buffers after the direct buffers */
452 for( i = I_OUTPUTPICTURES; i < 2 * VOUT_MAX_PICTURES; i++ )
454 PP_RENDERPICTURE[ I_RENDERPICTURES ] = &p_vout->p_picture[ i ];
459 /* Link pictures back to their heap */
460 for( i = 0 ; i < I_RENDERPICTURES ; i++ )
462 PP_RENDERPICTURE[ i ]->p_heap = &p_vout->render;
465 for( i = 0 ; i < I_OUTPUTPICTURES ; i++ )
467 PP_OUTPUTPICTURE[ i ]->p_heap = &p_vout->output;
470 /* Mark thread as running and return */
471 p_vout->b_active = 1;
472 *p_vout->pi_status = THREAD_READY;
477 /*****************************************************************************
478 * RunThread: video output thread
479 *****************************************************************************
480 * Video output thread. This function does only returns when the thread is
481 * terminated. It handles the pictures arriving in the video heap and the
482 * display device events.
483 *****************************************************************************/
484 static void RunThread( vout_thread_t *p_vout)
486 int i_index; /* index in heap */
487 int i_idle_loops = 0; /* loops without displaying a picture */
488 mtime_t current_date; /* current date */
489 mtime_t display_date; /* display date */
491 picture_t * p_picture; /* picture pointer */
492 picture_t * p_last_picture = NULL; /* last picture */
493 picture_t * p_directbuffer; /* direct buffer to display */
495 subpicture_t * p_subpic; /* subpicture pointer */
500 p_vout->b_error = InitThread( p_vout );
501 if( p_vout->b_error )
503 /* Destroy thread structures allocated by Create and InitThread */
504 p_vout->pf_destroy( p_vout );
506 DestroyThread( p_vout, THREAD_ERROR );
511 * Main loop - it is not executed if an error occured during
514 while( (!p_vout->b_die) && (!p_vout->b_error) )
516 /* Initialize loop variables */
518 current_date = mdate();
522 if( !(p_vout->c_loops % VOUT_STATS_NB_LOOPS) )
524 intf_Msg( "vout stats: picture heap: %d/%d",
525 I_RENDERPICTURES, p_vout->i_heap_size );
530 * Find the picture to display - this operation does not need lock,
531 * since only READY_PICTUREs are handled
535 for( i_index = 0; i_index < I_RENDERPICTURES; i_index++ )
537 if( (PP_RENDERPICTURE[i_index]->i_status == READY_PICTURE)
538 && ( (p_picture == NULL) ||
539 (PP_RENDERPICTURE[i_index]->date < display_date) ) )
541 p_picture = PP_RENDERPICTURE[i_index];
542 display_date = p_picture->date;
546 if( p_picture != NULL )
548 /* If we met the last picture, parse again to see whether there is
549 * a more appropriate one. */
550 if( p_picture == p_last_picture )
552 for( i_index = 0; i_index < I_RENDERPICTURES; i_index++ )
554 if( (PP_RENDERPICTURE[i_index]->i_status == READY_PICTURE)
555 && (PP_RENDERPICTURE[i_index] != p_last_picture)
556 && ((p_picture == p_last_picture) ||
557 (PP_RENDERPICTURE[i_index]->date < display_date)) )
559 p_picture = PP_RENDERPICTURE[i_index];
560 display_date = p_picture->date;
565 /* If we found better than the last picture, destroy it */
566 if( p_last_picture && p_picture != p_last_picture )
568 vlc_mutex_lock( &p_vout->picture_lock );
569 if( p_last_picture->i_refcount )
571 p_last_picture->i_status = DISPLAYED_PICTURE;
575 p_last_picture->i_status = DESTROYED_PICTURE;
576 p_vout->i_heap_size--;
578 vlc_mutex_unlock( &p_vout->picture_lock );
581 /* Compute FPS rate */
582 p_vout->p_fps_sample[ p_vout->c_fps_samples++ % VOUT_FPS_SAMPLES ]
585 if( !p_picture->b_force &&
586 p_picture != p_last_picture &&
587 display_date < current_date + p_vout->render_time )
589 /* Picture is late: it will be destroyed and the thread
590 * will directly choose the next picture */
591 vlc_mutex_lock( &p_vout->picture_lock );
592 if( p_picture->i_refcount )
594 /* Pretend we displayed the picture, but don't destroy
595 * it since the decoder might still need it. */
596 p_picture->i_status = DISPLAYED_PICTURE;
600 /* Destroy the picture without displaying it */
601 p_picture->i_status = DESTROYED_PICTURE;
602 p_vout->i_heap_size--;
604 intf_WarnMsg( 1, "vout warning: late picture skipped (%lld)",
605 current_date - display_date );
606 vlc_mutex_unlock( &p_vout->picture_lock );
611 /* Removed because it causes problems for some people --Meuuh */
612 if( display_date > current_date + VOUT_BOGUS_DELAY )
614 /* Picture is waaay too early: it will be destroyed */
615 vlc_mutex_lock( &p_vout->picture_lock );
616 if( p_picture->i_refcount )
618 /* Pretend we displayed the picture, but don't destroy
619 * it since the decoder might still need it. */
620 p_picture->i_status = DISPLAYED_PICTURE;
624 /* Destroy the picture without displaying it */
625 p_picture->i_status = DESTROYED_PICTURE;
626 p_vout->i_heap_size--;
628 intf_WarnMsg( 1, "vout warning: early picture skipped (%lld)",
629 display_date - current_date );
630 vlc_mutex_unlock( &p_vout->picture_lock );
635 if( display_date > current_date + VOUT_DISPLAY_DELAY )
637 /* A picture is ready to be rendered, but its rendering date
638 * is far from the current one so the thread will perform an
639 * empty loop as if no picture were found. The picture state
644 else if( p_picture == p_last_picture )
646 if( i_idle_loops < 4 )
648 /* We are asked to repeat the previous picture, but we first
649 * wait for a couple of idle loops */
655 //intf_WarnMsg( 6, "vout info: duplicating picture" );
660 if( p_picture == NULL )
666 * Check for subpictures to display
668 p_subpic = vout_SortSubPictures( p_vout, display_date );
673 p_directbuffer = vout_RenderPicture( p_vout, p_picture, p_subpic );
676 * Call the plugin-specific rendering method
678 if( p_picture != NULL )
680 /* Render the direct buffer returned by vout_RenderPicture */
681 p_vout->pf_render( p_vout, p_directbuffer );
687 if( display_date != 0 )
689 /* Store render time using Bresenham algorithm */
690 p_vout->render_time += mdate() - current_date;
691 p_vout->render_time >>= 1;
694 /* Give back change lock */
695 vlc_mutex_unlock( &p_vout->change_lock );
697 /* Sleep a while or until a given date */
698 if( display_date != 0 )
700 mwait( display_date - VOUT_MWAIT_TOLERANCE );
704 msleep( VOUT_IDLE_SLEEP );
707 /* On awakening, take back lock and send immediately picture
709 vlc_mutex_lock( &p_vout->change_lock );
712 * Display the previously rendered picture
714 if( p_picture != NULL )
716 /* Display the direct buffer returned by vout_RenderPicture */
717 p_vout->pf_display( p_vout, p_directbuffer );
719 /* Reinitialize idle loop count */
722 /* Tell the vout this was the last picture and that it does not
723 * need to be forced anymore. */
724 p_last_picture = p_picture;
725 p_last_picture->b_force = 0;
729 * Check events and manage thread
731 if( p_vout->pf_manage( p_vout ) )
733 /* A fatal error occured, and the thread must terminate
734 * immediately, without displaying anything - setting b_error to 1
735 * causes the immediate end of the main while() loop. */
739 if( p_vout->i_changes & VOUT_SIZE_CHANGE )
741 /* this must only happen when the vout plugin is incapable of
742 * rescaling the picture itself. In this case we need to destroy
743 * the current picture buffers and recreate new ones with the right
747 p_vout->i_changes &= ~VOUT_SIZE_CHANGE;
749 p_vout->pf_end( p_vout );
750 for( i = 0; i < I_OUTPUTPICTURES; i++ )
751 p_vout->p_picture[ i ].i_status = FREE_PICTURE;
753 I_OUTPUTPICTURES = 0;
754 if( p_vout->pf_init( p_vout ) )
756 intf_ErrMsg( "vout error: cannot resize display" );
757 /* FixMe: p_vout->pf_end will be called again in EndThread() */
761 /* Need to reinitialise the chroma plugin */
762 p_vout->chroma.pf_end( p_vout );
763 p_vout->chroma.pf_init( p_vout );
769 * Error loop - wait until the thread destruction is requested
771 if( p_vout->b_error )
773 ErrorThread( p_vout );
779 /* Destroy method-dependant resources */
780 p_vout->pf_destroy( p_vout );
782 /* Destroy thread structures allocated by CreateThread */
783 DestroyThread( p_vout, THREAD_OVER );
786 /*****************************************************************************
787 * ErrorThread: RunThread() error loop
788 *****************************************************************************
789 * This function is called when an error occured during thread main's loop. The
790 * thread can still receive feed, but must be ready to terminate as soon as
792 *****************************************************************************/
793 static void ErrorThread( vout_thread_t *p_vout )
795 /* Wait until a `die' order */
796 while( !p_vout->b_die )
799 msleep( VOUT_IDLE_SLEEP );
803 /*****************************************************************************
804 * EndThread: thread destruction
805 *****************************************************************************
806 * This function is called when the thread ends after a sucessful
807 * initialization. It frees all ressources allocated by InitThread.
808 *****************************************************************************/
809 static void EndThread( vout_thread_t *p_vout )
811 int i_index; /* index in heap */
814 *p_vout->pi_status = THREAD_END;
818 struct tms cpu_usage;
821 intf_Msg( "vout stats: cpu usage (user: %d, system: %d)",
822 cpu_usage.tms_utime, cpu_usage.tms_stime );
826 if( !p_vout->b_direct )
828 p_vout->chroma.pf_end( p_vout );
829 module_Unneed( p_vout->chroma.p_module );
832 /* Destroy all remaining pictures */
833 for( i_index = 0; i_index < 2 * VOUT_MAX_PICTURES; i_index++ )
835 if ( p_vout->p_picture[i_index].i_type == MEMORY_PICTURE )
837 free( p_vout->p_picture[i_index].p_data_orig );
841 /* Destroy all remaining subpictures */
842 for( i_index = 0; i_index < VOUT_MAX_SUBPICTURES; i_index++ )
844 if( p_vout->p_subpicture[i_index].i_status != FREE_SUBPICTURE )
846 free( p_vout->p_subpicture[i_index].p_sys );
850 /* Destroy translation tables */
851 p_vout->pf_end( p_vout );
853 /* Release the change lock */
854 vlc_mutex_unlock( &p_vout->change_lock );
857 /*****************************************************************************
858 * DestroyThread: thread destruction
859 *****************************************************************************
860 * This function is called when the thread ends. It frees all ressources
861 * allocated by CreateThread. Status is available at this stage.
862 *****************************************************************************/
863 static void DestroyThread( vout_thread_t *p_vout, int i_status )
865 int *pi_status; /* status adress */
867 /* Store status adress */
868 pi_status = p_vout->pi_status;
870 /* Destroy the locks */
871 vlc_mutex_destroy( &p_vout->picture_lock );
872 vlc_mutex_destroy( &p_vout->subpicture_lock );
873 vlc_mutex_destroy( &p_vout->change_lock );
875 /* Release the module */
876 module_Unneed( p_vout->p_module );
878 *pi_status = i_status;
881 /* following functions are local */
883 static int ReduceHeight( int i_ratio )
885 int i_dummy = VOUT_ASPECT_FACTOR;
893 /* VOUT_ASPECT_FACTOR is (2^7 * 3^3 * 5^3), we just check for 2, 3 and 5 */
894 while( !(i_ratio & 1) && !(i_dummy & 1) )
901 while( !(i_ratio % 3) && !(i_dummy % 3) )
908 while( !(i_ratio % 5) && !(i_dummy % 5) )
918 /*****************************************************************************
919 * BinaryLog: computes the base 2 log of a binary value
920 *****************************************************************************
921 * This functions is used by MaskToShift, to get a bit index from a binary
923 *****************************************************************************/
924 static int BinaryLog(u32 i)
928 if(i & 0xffff0000) i_log += 16;
929 if(i & 0xff00ff00) i_log += 8;
930 if(i & 0xf0f0f0f0) i_log += 4;
931 if(i & 0xcccccccc) i_log += 2;
932 if(i & 0xaaaaaaaa) i_log += 1;
934 if (i != ((u32)1 << i_log))
936 intf_ErrMsg( "vout error: binary log overflow for %i", i );
942 /*****************************************************************************
943 * MaskToShift: transform a color mask into right and left shifts
944 *****************************************************************************
945 * This function is used for obtaining color shifts from masks.
946 *****************************************************************************/
947 static void MaskToShift( int *pi_left, int *pi_right, u32 i_mask )
949 u32 i_low, i_high; /* lower hand higher bits of the mask */
953 *pi_left = *pi_right = 0;
958 i_low = i_mask & (- i_mask); /* lower bit of the mask */
959 i_high = i_mask + i_low; /* higher bit of the mask */
961 /* Transform bits into an index */
962 i_low = BinaryLog (i_low);
963 i_high = BinaryLog (i_high);
965 /* Update pointers and return */
967 *pi_right = (8 - i_high + i_low);
970 /*****************************************************************************
971 * InitWindowSize: find the initial dimensions the video window should have.
972 *****************************************************************************
973 * This function will check the "width", "height" and "zoom" config options and
974 * will calculate the size that the video window should have.
975 *****************************************************************************/
976 static void InitWindowSize( vout_thread_t *p_vout, int *pi_width,
979 int i_width, i_height;
982 i_width = config_GetIntVariable( "width" );
983 i_height = config_GetIntVariable( "height" );
984 f_zoom = config_GetFloatVariable( "zoom" );
986 if( (i_width >= 0) && (i_height >= 0))
988 *pi_width = i_width * f_zoom;
989 *pi_height = i_height * f_zoom;
992 else if( i_width >= 0 )
994 *pi_width = i_width * f_zoom;
995 *pi_height = i_width * f_zoom * VOUT_ASPECT_FACTOR /
996 p_vout->render.i_aspect;
999 else if( i_height >= 0 )
1001 *pi_height = i_height * f_zoom;
1002 *pi_width = i_height * f_zoom * p_vout->render.i_aspect /
1007 if( p_vout->render.i_height * p_vout->render.i_aspect
1008 >= p_vout->render.i_width * VOUT_ASPECT_FACTOR )
1010 *pi_width = p_vout->render.i_height * f_zoom
1011 * p_vout->render.i_aspect / VOUT_ASPECT_FACTOR;
1012 *pi_height = p_vout->render.i_height * f_zoom;
1016 *pi_width = p_vout->render.i_width * f_zoom;
1017 *pi_height = p_vout->render.i_width * f_zoom
1018 * VOUT_ASPECT_FACTOR / p_vout->render.i_aspect;