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.198 2002/11/19 20:45:08 gbazin 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 <stdlib.h> /* free() */
34 #ifdef HAVE_SYS_TIMES_H
35 # include <sys/times.h>
39 #include "video_output.h"
41 #if defined( SYS_DARWIN )
42 #include "darwin_specific.h"
45 /*****************************************************************************
47 *****************************************************************************/
48 static int InitThread ( vout_thread_t * );
49 static void RunThread ( vout_thread_t * );
50 static void ErrorThread ( vout_thread_t * );
51 static void EndThread ( vout_thread_t * );
52 static void DestroyThread ( vout_thread_t * );
54 static int ReduceHeight ( int );
55 static int BinaryLog ( uint32_t );
56 static void MaskToShift ( int *, int *, uint32_t );
57 static void InitWindowSize ( vout_thread_t *, int *, int * );
59 /*****************************************************************************
60 * vout_CreateThread: creates a new video output thread
61 *****************************************************************************
62 * This function creates a new video output thread, and returns a pointer
63 * to its description. On error, it returns NULL.
64 *****************************************************************************/
65 vout_thread_t * __vout_CreateThread ( vlc_object_t *p_parent,
66 int i_width, int i_height,
67 vlc_fourcc_t i_chroma, int i_aspect )
69 vout_thread_t * p_vout; /* thread descriptor */
70 int i_index; /* loop variable */
73 /* Allocate descriptor */
74 p_vout = vlc_object_create( p_parent, VLC_OBJECT_VOUT );
77 msg_Err( p_parent, "out of memory" );
81 /* If the parent is not a VOUT object, that means we are at the start of
82 * the video output pipe */
83 if( p_parent->i_object_type != VLC_OBJECT_VOUT )
85 /* look for the default filter configuration */
86 p_vout->psz_filter_chain = config_GetPsz( p_parent, "filter" );
90 /* continue the parent's filter chain */
93 psz_end = strchr( ((vout_thread_t *)p_parent)->psz_filter_chain, ':' );
94 if( psz_end && *(psz_end+1) )
95 p_vout->psz_filter_chain = strdup( psz_end+1 );
96 else p_vout->psz_filter_chain = NULL;
99 /* Choose the video output module */
100 if( !p_vout->psz_filter_chain )
102 psz_plugin = config_GetPsz( p_parent, "vout" );
106 /* the filter chain is a string list of filters separated by double
110 psz_end = strchr( p_vout->psz_filter_chain, ':' );
112 psz_plugin = strndup( p_vout->psz_filter_chain,
113 psz_end - p_vout->psz_filter_chain );
114 else psz_plugin = strdup( p_vout->psz_filter_chain );
117 /* Initialize pictures and subpictures - translation tables and functions
118 * will be initialized later in InitThread */
119 for( i_index = 0; i_index < 2 * VOUT_MAX_PICTURES; i_index++)
121 p_vout->p_picture[i_index].i_status = FREE_PICTURE;
122 p_vout->p_picture[i_index].i_type = EMPTY_PICTURE;
125 for( i_index = 0; i_index < VOUT_MAX_SUBPICTURES; i_index++)
127 p_vout->p_subpicture[i_index].i_status = FREE_SUBPICTURE;
128 p_vout->p_subpicture[i_index].i_type = EMPTY_SUBPICTURE;
131 /* No images in the heap */
132 p_vout->i_heap_size = 0;
134 /* Initialize the rendering heap */
135 I_RENDERPICTURES = 0;
136 p_vout->render.i_width = i_width;
137 p_vout->render.i_height = i_height;
138 p_vout->render.i_chroma = i_chroma;
139 p_vout->render.i_aspect = i_aspect;
141 p_vout->render.i_rmask = 0;
142 p_vout->render.i_gmask = 0;
143 p_vout->render.i_bmask = 0;
145 p_vout->render.i_last_used_pic = 0;
146 p_vout->render.b_allow_modify_pics = 1;
148 /* Zero the output heap */
149 I_OUTPUTPICTURES = 0;
150 p_vout->output.i_width = 0;
151 p_vout->output.i_height = 0;
152 p_vout->output.i_chroma = 0;
153 p_vout->output.i_aspect = 0;
155 p_vout->output.i_rmask = 0;
156 p_vout->output.i_gmask = 0;
157 p_vout->output.i_bmask = 0;
159 /* Initialize misc stuff */
160 p_vout->i_changes = 0;
162 p_vout->b_grayscale = 0;
164 p_vout->b_interface = 0;
166 p_vout->b_fullscreen = 0;
167 p_vout->render_time = 10;
168 p_vout->c_fps_samples= 0;
170 /* Mouse coordinates */
171 var_Create( p_vout, "mouse-x", VLC_VAR_INTEGER );
172 var_Create( p_vout, "mouse-y", VLC_VAR_INTEGER );
173 var_Create( p_vout, "mouse-moved", VLC_VAR_BOOL );
174 var_Create( p_vout, "mouse-clicked", VLC_VAR_INTEGER );
176 /* user requested fullscreen? */
177 if( config_GetInt( p_vout, "fullscreen" ) )
179 p_vout->i_changes |= VOUT_FULLSCREEN_CHANGE;
182 /* Initialize the dimensions of the video window */
183 InitWindowSize( p_vout, &p_vout->i_window_width,
184 &p_vout->i_window_height );
187 p_vout->p_module = module_Need( p_vout,
188 ( p_vout->psz_filter_chain ) ?
189 "video filter" : "video output",
192 if( psz_plugin ) free( psz_plugin );
193 if( p_vout->p_module == NULL )
195 msg_Err( p_vout, "no suitable vout module" );
196 vlc_object_destroy( p_vout );
200 /* Create thread and set locks */
201 vlc_mutex_init( p_vout, &p_vout->picture_lock );
202 vlc_mutex_init( p_vout, &p_vout->subpicture_lock );
203 vlc_mutex_init( p_vout, &p_vout->change_lock );
205 vlc_object_attach( p_vout, p_parent );
207 if( vlc_thread_create( p_vout, "video output", RunThread,
208 VLC_THREAD_PRIORITY_OUTPUT, VLC_FALSE ) )
210 msg_Err( p_vout, "out of memory" );
211 module_Unneed( p_vout, p_vout->p_module );
212 vlc_object_destroy( p_vout );
219 /*****************************************************************************
220 * vout_DestroyThread: destroys a previously created thread
221 *****************************************************************************
222 * Destroy a terminated thread.
223 * The function will request a destruction of the specified thread. If pi_error
224 * is NULL, it will return once the thread is destroyed. Else, it will be
225 * update using one of the THREAD_* constants.
226 *****************************************************************************/
227 void vout_DestroyThread( vout_thread_t *p_vout )
229 /* Request thread destruction */
231 vlc_thread_join( p_vout );
234 vlc_object_destroy( p_vout );
237 /*****************************************************************************
238 * InitThread: initialize video output thread
239 *****************************************************************************
240 * This function is called from RunThread and performs the second step of the
241 * initialization. It returns 0 on success. Note that the thread's flag are not
242 * modified inside this function.
243 *****************************************************************************/
244 static int InitThread( vout_thread_t *p_vout )
248 vlc_mutex_lock( &p_vout->change_lock );
254 /* Initialize output method, it allocates direct buffers for us */
255 if( p_vout->pf_init( p_vout ) )
257 vlc_mutex_unlock( &p_vout->change_lock );
261 if( !I_OUTPUTPICTURES )
263 msg_Err( p_vout, "plugin was unable to allocate at least "
264 "one direct buffer" );
265 p_vout->pf_end( p_vout );
266 vlc_mutex_unlock( &p_vout->change_lock );
270 msg_Dbg( p_vout, "got %i direct buffer(s)", I_OUTPUTPICTURES );
272 i_pgcd = ReduceHeight( p_vout->render.i_aspect );
274 "picture in %ix%i, chroma 0x%.8x (%4.4s), aspect ratio %i:%i",
275 p_vout->render.i_width, p_vout->render.i_height,
276 p_vout->render.i_chroma, (char*)&p_vout->render.i_chroma,
277 p_vout->render.i_aspect / i_pgcd, VOUT_ASPECT_FACTOR / i_pgcd );
279 i_pgcd = ReduceHeight( p_vout->output.i_aspect );
281 "picture out %ix%i, chroma 0x%.8x (%4.4s), aspect ratio %i:%i",
282 p_vout->output.i_width, p_vout->output.i_height,
283 p_vout->output.i_chroma, (char*)&p_vout->output.i_chroma,
284 p_vout->output.i_aspect / i_pgcd, VOUT_ASPECT_FACTOR / i_pgcd );
286 /* Calculate shifts from system-updated masks */
287 MaskToShift( &p_vout->output.i_lrshift, &p_vout->output.i_rrshift,
288 p_vout->output.i_rmask );
289 MaskToShift( &p_vout->output.i_lgshift, &p_vout->output.i_rgshift,
290 p_vout->output.i_gmask );
291 MaskToShift( &p_vout->output.i_lbshift, &p_vout->output.i_rbshift,
292 p_vout->output.i_bmask );
294 /* Check whether we managed to create direct buffers similar to
295 * the render buffers, ie same size, chroma and aspect ratio */
296 if( ( p_vout->output.i_width == p_vout->render.i_width )
297 && ( p_vout->output.i_height == p_vout->render.i_height )
298 && ( vout_ChromaCmp( p_vout->output.i_chroma, p_vout->render.i_chroma ) )
299 && ( p_vout->output.i_aspect == p_vout->render.i_aspect ) )
301 /* Cool ! We have direct buffers, we can ask the decoder to
302 * directly decode into them ! Map the first render buffers to
303 * the first direct buffers, but keep the first direct buffer
304 * for memcpy operations */
305 p_vout->b_direct = 1;
307 for( i = 1; i < VOUT_MAX_PICTURES; i++ )
309 if( p_vout->p_picture[ i ].i_type != DIRECT_PICTURE &&
310 I_RENDERPICTURES >= VOUT_MIN_DIRECT_PICTURES - 1 &&
311 p_vout->p_picture[ i - 1 ].i_type == DIRECT_PICTURE )
313 /* We have enough direct buffers so there's no need to
314 * try to use system memory buffers. */
317 PP_RENDERPICTURE[ I_RENDERPICTURES ] = &p_vout->p_picture[ i ];
321 msg_Dbg( p_vout, "direct render, mapping "
322 "render pictures 0-%i to system pictures 1-%i",
323 VOUT_MAX_PICTURES - 2, VOUT_MAX_PICTURES - 1 );
327 /* Rats... Something is wrong here, we could not find an output
328 * plugin able to directly render what we decode. See if we can
329 * find a chroma plugin to do the conversion */
330 p_vout->b_direct = 0;
332 /* Choose the best module */
333 p_vout->chroma.p_module = module_Need( p_vout, "chroma", NULL );
335 if( p_vout->chroma.p_module == NULL )
337 msg_Err( p_vout, "no chroma module for %4.4s to %4.4s",
338 &p_vout->render.i_chroma, &p_vout->output.i_chroma );
339 p_vout->pf_end( p_vout );
340 vlc_mutex_unlock( &p_vout->change_lock );
344 if( I_OUTPUTPICTURES < 2 * VOUT_MAX_PICTURES )
346 msg_Dbg( p_vout, "indirect render, mapping "
347 "render pictures %i-%i to system pictures %i-%i",
348 I_OUTPUTPICTURES - 1, 2 * VOUT_MAX_PICTURES - 2,
349 I_OUTPUTPICTURES, 2 * VOUT_MAX_PICTURES - 1 );
353 /* FIXME: if this happens, we don't have any render pictures left */
354 msg_Dbg( p_vout, "indirect render, no system pictures needed,"
355 " we have %i directbuffers", I_OUTPUTPICTURES );
356 msg_Err( p_vout, "this is a bug!" );
359 /* Append render buffers after the direct buffers */
360 for( i = I_OUTPUTPICTURES; i < 2 * VOUT_MAX_PICTURES; i++ )
362 PP_RENDERPICTURE[ I_RENDERPICTURES ] = &p_vout->p_picture[ i ];
367 /* Link pictures back to their heap */
368 for( i = 0 ; i < I_RENDERPICTURES ; i++ )
370 PP_RENDERPICTURE[ i ]->p_heap = &p_vout->render;
373 for( i = 0 ; i < I_OUTPUTPICTURES ; i++ )
375 PP_OUTPUTPICTURE[ i ]->p_heap = &p_vout->output;
378 /* XXX XXX mark thread ready */
382 /*****************************************************************************
383 * RunThread: video output thread
384 *****************************************************************************
385 * Video output thread. This function does only returns when the thread is
386 * terminated. It handles the pictures arriving in the video heap and the
387 * display device events.
388 *****************************************************************************/
389 static void RunThread( vout_thread_t *p_vout)
391 int i_index; /* index in heap */
392 int i_idle_loops = 0; /* loops without displaying a picture */
393 mtime_t current_date; /* current date */
394 mtime_t display_date; /* display date */
396 picture_t * p_picture; /* picture pointer */
397 picture_t * p_last_picture = NULL; /* last picture */
398 picture_t * p_directbuffer; /* direct buffer to display */
400 subpicture_t * p_subpic; /* subpicture pointer */
405 p_vout->b_error = InitThread( p_vout );
406 if( p_vout->b_error )
408 /* Destroy thread structures allocated by Create and InitThread */
409 DestroyThread( p_vout );
414 * Main loop - it is not executed if an error occured during
417 while( (!p_vout->b_die) && (!p_vout->b_error) )
419 /* Initialize loop variables */
422 current_date = mdate();
426 if( !(p_vout->c_loops % VOUT_STATS_NB_LOOPS) )
428 msg_Dbg( p_vout, "picture heap: %d/%d",
429 I_RENDERPICTURES, p_vout->i_heap_size );
434 * Find the picture to display (the one with the earliest date).
435 * This operation does not need lock, since only READY_PICTUREs
437 for( i_index = 0; i_index < I_RENDERPICTURES; i_index++ )
439 if( (PP_RENDERPICTURE[i_index]->i_status == READY_PICTURE)
440 && ( (p_picture == NULL) ||
441 (PP_RENDERPICTURE[i_index]->date < display_date) ) )
443 p_picture = PP_RENDERPICTURE[i_index];
444 display_date = p_picture->date;
450 /* If we met the last picture, parse again to see whether there is
451 * a more appropriate one. */
452 if( p_picture == p_last_picture )
454 for( i_index = 0; i_index < I_RENDERPICTURES; i_index++ )
456 if( (PP_RENDERPICTURE[i_index]->i_status == READY_PICTURE)
457 && (PP_RENDERPICTURE[i_index] != p_last_picture)
458 && ((p_picture == p_last_picture) ||
459 (PP_RENDERPICTURE[i_index]->date < display_date)) )
461 p_picture = PP_RENDERPICTURE[i_index];
462 display_date = p_picture->date;
467 /* If we found better than the last picture, destroy it */
468 if( p_last_picture && p_picture != p_last_picture )
470 vlc_mutex_lock( &p_vout->picture_lock );
471 if( p_last_picture->i_refcount )
473 p_last_picture->i_status = DISPLAYED_PICTURE;
477 p_last_picture->i_status = DESTROYED_PICTURE;
478 p_vout->i_heap_size--;
480 vlc_mutex_unlock( &p_vout->picture_lock );
481 p_last_picture = NULL;
484 /* Compute FPS rate */
485 p_vout->p_fps_sample[ p_vout->c_fps_samples++ % VOUT_FPS_SAMPLES ]
488 if( !p_picture->b_force &&
489 p_picture != p_last_picture &&
490 display_date < current_date + p_vout->render_time )
492 /* Picture is late: it will be destroyed and the thread
493 * will directly choose the next picture */
494 vlc_mutex_lock( &p_vout->picture_lock );
495 if( p_picture->i_refcount )
497 /* Pretend we displayed the picture, but don't destroy
498 * it since the decoder might still need it. */
499 p_picture->i_status = DISPLAYED_PICTURE;
503 /* Destroy the picture without displaying it */
504 p_picture->i_status = DESTROYED_PICTURE;
505 p_vout->i_heap_size--;
507 msg_Warn( p_vout, "late picture skipped ("I64Fd")",
508 current_date - display_date );
509 vlc_mutex_unlock( &p_vout->picture_lock );
514 /* Removed because it causes problems for some people --Meuuh */
515 if( display_date > current_date + VOUT_BOGUS_DELAY )
517 /* Picture is waaay too early: it will be destroyed */
518 vlc_mutex_lock( &p_vout->picture_lock );
519 if( p_picture->i_refcount )
521 /* Pretend we displayed the picture, but don't destroy
522 * it since the decoder might still need it. */
523 p_picture->i_status = DISPLAYED_PICTURE;
527 /* Destroy the picture without displaying it */
528 p_picture->i_status = DESTROYED_PICTURE;
529 p_vout->i_heap_size--;
531 intf_WarnMsg( 1, "vout warning: early picture skipped "
532 "("I64Fd")", display_date - current_date );
533 vlc_mutex_unlock( &p_vout->picture_lock );
538 if( display_date > current_date + VOUT_DISPLAY_DELAY )
540 /* A picture is ready to be rendered, but its rendering date
541 * is far from the current one so the thread will perform an
542 * empty loop as if no picture were found. The picture state
547 else if( p_picture == p_last_picture )
549 /* We are asked to repeat the previous picture, but we first
550 * wait for a couple of idle loops */
551 if( i_idle_loops < 4 )
558 /* We set the display date to something high, otherwise
559 * we'll have lots of problems with late pictures */
560 display_date = current_date + p_vout->render_time;
565 if( p_picture == NULL )
571 * Check for subpictures to display
573 p_subpic = vout_SortSubPictures( p_vout, display_date );
578 p_directbuffer = vout_RenderPicture( p_vout, p_picture, p_subpic );
581 * Call the plugin-specific rendering method if there is one
583 if( p_picture != NULL && p_vout->pf_render )
585 /* Render the direct buffer returned by vout_RenderPicture */
586 p_vout->pf_render( p_vout, p_directbuffer );
592 if( display_date != 0 )
594 /* Store render time using a sliding mean */
595 p_vout->render_time += mdate() - current_date;
596 p_vout->render_time >>= 1;
599 /* Give back change lock */
600 vlc_mutex_unlock( &p_vout->change_lock );
602 /* Sleep a while or until a given date */
603 if( display_date != 0 )
605 mwait( display_date - VOUT_MWAIT_TOLERANCE );
609 msleep( VOUT_IDLE_SLEEP );
612 /* On awakening, take back lock and send immediately picture
614 vlc_mutex_lock( &p_vout->change_lock );
617 * Display the previously rendered picture
619 if( p_picture != NULL )
621 /* Display the direct buffer returned by vout_RenderPicture */
622 if( p_vout->pf_display )
624 p_vout->pf_display( p_vout, p_directbuffer );
627 /* Reinitialize idle loop count */
630 /* Tell the vout this was the last picture and that it does not
631 * need to be forced anymore. */
632 p_last_picture = p_picture;
633 p_last_picture->b_force = 0;
637 * Check events and manage thread
639 if( p_vout->pf_manage && p_vout->pf_manage( p_vout ) )
641 /* A fatal error occured, and the thread must terminate
642 * immediately, without displaying anything - setting b_error to 1
643 * causes the immediate end of the main while() loop. */
647 if( p_vout->i_changes & VOUT_SIZE_CHANGE )
649 /* this must only happen when the vout plugin is incapable of
650 * rescaling the picture itself. In this case we need to destroy
651 * the current picture buffers and recreate new ones with the right
655 p_vout->i_changes &= ~VOUT_SIZE_CHANGE;
657 p_vout->pf_end( p_vout );
658 for( i = 0; i < I_OUTPUTPICTURES; i++ )
659 p_vout->p_picture[ i ].i_status = FREE_PICTURE;
661 I_OUTPUTPICTURES = 0;
662 if( p_vout->pf_init( p_vout ) )
664 msg_Err( p_vout, "cannot resize display" );
665 /* FIXME: pf_end will be called again in EndThread() */
669 /* Need to reinitialise the chroma plugin */
670 p_vout->chroma.p_module->pf_deactivate( VLC_OBJECT(p_vout) );
671 p_vout->chroma.p_module->pf_activate( VLC_OBJECT(p_vout) );
676 * Error loop - wait until the thread destruction is requested
678 if( p_vout->b_error )
680 ErrorThread( p_vout );
686 /* Destroy thread structures allocated by CreateThread */
687 DestroyThread( p_vout );
690 /*****************************************************************************
691 * ErrorThread: RunThread() error loop
692 *****************************************************************************
693 * This function is called when an error occured during thread main's loop. The
694 * thread can still receive feed, but must be ready to terminate as soon as
696 *****************************************************************************/
697 static void ErrorThread( vout_thread_t *p_vout )
699 /* Wait until a `die' order */
700 while( !p_vout->b_die )
703 msleep( VOUT_IDLE_SLEEP );
707 /*****************************************************************************
708 * EndThread: thread destruction
709 *****************************************************************************
710 * This function is called when the thread ends after a sucessful
711 * initialization. It frees all ressources allocated by InitThread.
712 *****************************************************************************/
713 static void EndThread( vout_thread_t *p_vout )
715 int i_index; /* index in heap */
719 struct tms cpu_usage;
722 msg_Dbg( p_vout, "cpu usage (user: %d, system: %d)",
723 cpu_usage.tms_utime, cpu_usage.tms_stime );
727 if( !p_vout->b_direct )
729 module_Unneed( p_vout, p_vout->chroma.p_module );
732 /* Destroy all remaining pictures */
733 for( i_index = 0; i_index < 2 * VOUT_MAX_PICTURES; i_index++ )
735 if ( p_vout->p_picture[i_index].i_type == MEMORY_PICTURE )
737 free( p_vout->p_picture[i_index].p_data_orig );
741 /* Destroy all remaining subpictures */
742 for( i_index = 0; i_index < VOUT_MAX_SUBPICTURES; i_index++ )
744 if( p_vout->p_subpicture[i_index].i_status != FREE_SUBPICTURE )
746 free( p_vout->p_subpicture[i_index].p_sys );
750 /* Destroy translation tables */
751 p_vout->pf_end( p_vout );
753 /* Release the change lock */
754 vlc_mutex_unlock( &p_vout->change_lock );
757 /*****************************************************************************
758 * DestroyThread: thread destruction
759 *****************************************************************************
760 * This function is called when the thread ends. It frees all ressources
761 * allocated by CreateThread. Status is available at this stage.
762 *****************************************************************************/
763 static void DestroyThread( vout_thread_t *p_vout )
765 /* Destroy the locks */
766 vlc_mutex_destroy( &p_vout->picture_lock );
767 vlc_mutex_destroy( &p_vout->subpicture_lock );
768 vlc_mutex_destroy( &p_vout->change_lock );
770 /* Release the module */
771 module_Unneed( p_vout, p_vout->p_module );
774 /* following functions are local */
776 static int ReduceHeight( int i_ratio )
778 int i_dummy = VOUT_ASPECT_FACTOR;
786 /* VOUT_ASPECT_FACTOR is (2^7 * 3^3 * 5^3), we just check for 2, 3 and 5 */
787 while( !(i_ratio & 1) && !(i_dummy & 1) )
794 while( !(i_ratio % 3) && !(i_dummy % 3) )
801 while( !(i_ratio % 5) && !(i_dummy % 5) )
811 /*****************************************************************************
812 * BinaryLog: computes the base 2 log of a binary value
813 *****************************************************************************
814 * This functions is used by MaskToShift, to get a bit index from a binary
816 *****************************************************************************/
817 static int BinaryLog( uint32_t i )
821 if( i == 0 ) return -31337;
823 if( i & 0xffff0000 ) i_log += 16;
824 if( i & 0xff00ff00 ) i_log += 8;
825 if( i & 0xf0f0f0f0 ) i_log += 4;
826 if( i & 0xcccccccc ) i_log += 2;
827 if( i & 0xaaaaaaaa ) i_log += 1;
832 /*****************************************************************************
833 * MaskToShift: transform a color mask into right and left shifts
834 *****************************************************************************
835 * This function is used for obtaining color shifts from masks.
836 *****************************************************************************/
837 static void MaskToShift( int *pi_left, int *pi_right, uint32_t i_mask )
839 uint32_t i_low, i_high; /* lower hand higher bits of the mask */
843 *pi_left = *pi_right = 0;
848 i_low = i_mask & (- (int32_t)i_mask); /* lower bit of the mask */
849 i_high = i_mask + i_low; /* higher bit of the mask */
851 /* Transform bits into an index */
852 i_low = BinaryLog (i_low);
853 i_high = BinaryLog (i_high);
855 /* Update pointers and return */
857 *pi_right = (8 - i_high + i_low);
860 /*****************************************************************************
861 * InitWindowSize: find the initial dimensions the video window should have.
862 *****************************************************************************
863 * This function will check the "width", "height" and "zoom" config options and
864 * will calculate the size that the video window should have.
865 *****************************************************************************/
866 static void InitWindowSize( vout_thread_t *p_vout, int *pi_width,
869 int i_width, i_height;
872 #define FP_FACTOR 1000 /* our fixed point factor */
874 i_width = config_GetInt( p_vout, "width" );
875 i_height = config_GetInt( p_vout, "height" );
876 ll_zoom = (uint64_t)( FP_FACTOR * config_GetFloat( p_vout, "zoom" ) );
878 if( (i_width >= 0) && (i_height >= 0))
880 *pi_width = (int)( i_width * ll_zoom / FP_FACTOR );
881 *pi_height = (int)( i_height * ll_zoom / FP_FACTOR );
884 else if( i_width >= 0 )
886 *pi_width = (int)( i_width * ll_zoom / FP_FACTOR );
887 *pi_height = (int)( i_width * ll_zoom * VOUT_ASPECT_FACTOR /
888 p_vout->render.i_aspect / FP_FACTOR );
891 else if( i_height >= 0 )
893 *pi_height = (int)( i_height * ll_zoom / FP_FACTOR );
894 *pi_width = (int)( i_height * ll_zoom * p_vout->render.i_aspect /
895 VOUT_ASPECT_FACTOR / FP_FACTOR );
899 if( p_vout->render.i_height * p_vout->render.i_aspect
900 >= p_vout->render.i_width * VOUT_ASPECT_FACTOR )
902 *pi_width = (int)( p_vout->render.i_height * ll_zoom
903 * p_vout->render.i_aspect / VOUT_ASPECT_FACTOR / FP_FACTOR );
904 *pi_height = (int)( p_vout->render.i_height * ll_zoom / FP_FACTOR );
908 *pi_width = (int)( p_vout->render.i_width * ll_zoom / FP_FACTOR );
909 *pi_height = (int)( p_vout->render.i_width * ll_zoom
910 * VOUT_ASPECT_FACTOR / p_vout->render.i_aspect / FP_FACTOR );