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.182 2002/06/01 18:04:49 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() */
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 * );
48 static void RunThread ( vout_thread_t * );
49 static void ErrorThread ( vout_thread_t * );
50 static void EndThread ( vout_thread_t * );
51 static void DestroyThread ( vout_thread_t * );
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_CreateThread: creates a new video output thread
60 *****************************************************************************
61 * This function creates a new video output thread, and returns a pointer
62 * to its description. On error, it returns NULL.
63 *****************************************************************************/
64 vout_thread_t * __vout_CreateThread ( vlc_object_t *p_parent,
65 int i_width, int i_height,
66 u32 i_chroma, int i_aspect )
68 vout_thread_t * p_vout; /* thread descriptor */
69 int i_index; /* loop variable */
72 /* Allocate descriptor */
73 p_vout = vlc_object_create( p_parent, VLC_OBJECT_VOUT );
76 msg_Err( p_parent, "out of memory" );
80 /* Choose the best module */
81 if( !(psz_plugin = config_GetPsz( p_vout, "filter" )) )
83 psz_plugin = config_GetPsz( p_vout, "vout" );
86 /* Initialize pictures and subpictures - translation tables and functions
87 * will be initialized later in InitThread */
88 for( i_index = 0; i_index < 2 * VOUT_MAX_PICTURES; i_index++)
90 p_vout->p_picture[i_index].i_status = FREE_PICTURE;
91 p_vout->p_picture[i_index].i_type = EMPTY_PICTURE;
94 for( i_index = 0; i_index < VOUT_MAX_SUBPICTURES; i_index++)
96 p_vout->p_subpicture[i_index].i_status = FREE_SUBPICTURE;
97 p_vout->p_subpicture[i_index].i_type = EMPTY_SUBPICTURE;
100 /* No images in the heap */
101 p_vout->i_heap_size = 0;
103 /* Initialize the rendering heap */
104 I_RENDERPICTURES = 0;
105 p_vout->render.i_width = i_width;
106 p_vout->render.i_height = i_height;
107 p_vout->render.i_chroma = i_chroma;
108 p_vout->render.i_aspect = i_aspect;
110 p_vout->render.i_rmask = 0;
111 p_vout->render.i_gmask = 0;
112 p_vout->render.i_bmask = 0;
114 /* Zero the output heap */
115 I_OUTPUTPICTURES = 0;
116 p_vout->output.i_width = 0;
117 p_vout->output.i_height = 0;
118 p_vout->output.i_chroma = 0;
119 p_vout->output.i_aspect = 0;
121 p_vout->output.i_rmask = 0;
122 p_vout->output.i_gmask = 0;
123 p_vout->output.i_bmask = 0;
125 /* Initialize misc stuff */
126 p_vout->i_changes = 0;
128 p_vout->b_grayscale = 0;
130 p_vout->b_interface = 0;
132 p_vout->b_fullscreen = 0;
133 p_vout->render_time = 10;
134 p_vout->c_fps_samples= 0;
136 /* user requested fullscreen? */
137 if( config_GetInt( p_vout, "fullscreen" ) )
139 p_vout->i_changes |= VOUT_FULLSCREEN_CHANGE;
142 /* Initialize the dimensions of the video window */
143 InitWindowSize( p_vout, &p_vout->i_window_width,
144 &p_vout->i_window_height );
147 p_vout->p_module = module_Need( p_vout, MODULE_CAPABILITY_VOUT,
148 psz_plugin, (void *)p_vout );
150 if( psz_plugin ) free( psz_plugin );
151 if( p_vout->p_module == NULL )
153 msg_Err( p_vout, "no suitable vout module" );
154 vlc_object_destroy( p_vout );
158 #define f p_vout->p_module->p_functions->vout.functions.vout
159 p_vout->pf_create = f.pf_create;
160 p_vout->pf_init = f.pf_init;
161 p_vout->pf_end = f.pf_end;
162 p_vout->pf_destroy = f.pf_destroy;
163 p_vout->pf_manage = f.pf_manage;
164 p_vout->pf_render = f.pf_render;
165 p_vout->pf_display = f.pf_display;
168 /* Create thread and set locks */
169 vlc_mutex_init( p_vout, &p_vout->picture_lock );
170 vlc_mutex_init( p_vout, &p_vout->subpicture_lock );
171 vlc_mutex_init( p_vout, &p_vout->change_lock );
173 vlc_object_attach( p_vout, p_parent );
175 if( vlc_thread_create( p_vout, "video output", RunThread, 0 ) )
177 msg_Err( p_vout, "%s", strerror(ENOMEM) );
178 p_vout->pf_destroy( p_vout );
179 module_Unneed( p_vout->p_module );
180 vlc_object_destroy( p_vout );
187 /*****************************************************************************
188 * vout_DestroyThread: destroys a previously created thread
189 *****************************************************************************
190 * Destroy a terminated thread.
191 * The function will request a destruction of the specified thread. If pi_error
192 * is NULL, it will return once the thread is destroyed. Else, it will be
193 * update using one of the THREAD_* constants.
194 *****************************************************************************/
195 void vout_DestroyThread( vout_thread_t *p_vout )
198 vlc_object_unlink_all( p_vout );
200 /* Request thread destruction */
202 vlc_thread_join( p_vout );
205 vlc_object_destroy( p_vout );
208 /*****************************************************************************
209 * vout_ChromaCmp: compare two chroma values
210 *****************************************************************************
211 * This function returns 1 if the two fourcc values given as argument are
212 * the same format (eg. UYVY / UYNV) or almost the same format (eg. I420/YV12)
213 *****************************************************************************/
214 int vout_ChromaCmp( u32 i_chroma, u32 i_amorhc )
216 /* If they are the same, they are the same ! */
217 if( i_chroma == i_amorhc )
222 /* Check for equivalence classes */
270 /*****************************************************************************
271 * InitThread: initialize video output thread
272 *****************************************************************************
273 * This function is called from RunThread and performs the second step of the
274 * initialization. It returns 0 on success. Note that the thread's flag are not
275 * modified inside this function.
276 *****************************************************************************/
277 static int InitThread( vout_thread_t *p_vout )
281 vlc_mutex_lock( &p_vout->change_lock );
287 /* Initialize output method, it allocates direct buffers for us */
288 if( p_vout->pf_init( p_vout ) )
290 vlc_mutex_unlock( &p_vout->change_lock );
294 if( !I_OUTPUTPICTURES )
296 msg_Err( p_vout, "plugin was unable to allocate at least "
297 "one direct buffer" );
298 p_vout->pf_end( p_vout );
299 vlc_mutex_unlock( &p_vout->change_lock );
303 msg_Dbg( p_vout, "got %i direct buffer(s)", I_OUTPUTPICTURES );
305 i_pgcd = ReduceHeight( p_vout->render.i_aspect );
307 "picture in %ix%i, chroma 0x%.8x (%4.4s), aspect ratio %i:%i",
308 p_vout->render.i_width, p_vout->render.i_height,
309 p_vout->render.i_chroma, (char*)&p_vout->render.i_chroma,
310 p_vout->render.i_aspect / i_pgcd, VOUT_ASPECT_FACTOR / i_pgcd );
312 i_pgcd = ReduceHeight( p_vout->output.i_aspect );
314 "picture out %ix%i, chroma 0x%.8x (%4.4s), aspect ratio %i:%i",
315 p_vout->output.i_width, p_vout->output.i_height,
316 p_vout->output.i_chroma, (char*)&p_vout->output.i_chroma,
317 p_vout->output.i_aspect / i_pgcd, VOUT_ASPECT_FACTOR / i_pgcd );
319 /* Calculate shifts from system-updated masks */
320 MaskToShift( &p_vout->output.i_lrshift, &p_vout->output.i_rrshift,
321 p_vout->output.i_rmask );
322 MaskToShift( &p_vout->output.i_lgshift, &p_vout->output.i_rgshift,
323 p_vout->output.i_gmask );
324 MaskToShift( &p_vout->output.i_lbshift, &p_vout->output.i_rbshift,
325 p_vout->output.i_bmask );
327 /* Check whether we managed to create direct buffers similar to
328 * the render buffers, ie same size, chroma and aspect ratio */
329 if( ( p_vout->output.i_width == p_vout->render.i_width )
330 && ( p_vout->output.i_height == p_vout->render.i_height )
331 && ( vout_ChromaCmp( p_vout->output.i_chroma, p_vout->render.i_chroma ) )
332 && ( p_vout->output.i_aspect == p_vout->render.i_aspect ) )
334 /* Cool ! We have direct buffers, we can ask the decoder to
335 * directly decode into them ! Map the first render buffers to
336 * the first direct buffers, but keep the first direct buffer
337 * for memcpy operations */
338 p_vout->b_direct = 1;
340 msg_Dbg( p_vout, "direct render, mapping "
341 "render pictures 0-%i to system pictures 1-%i",
342 VOUT_MAX_PICTURES - 2, VOUT_MAX_PICTURES - 1 );
344 for( i = 1; i < VOUT_MAX_PICTURES; i++ )
346 PP_RENDERPICTURE[ I_RENDERPICTURES ] = &p_vout->p_picture[ i ];
352 /* Rats... Something is wrong here, we could not find an output
353 * plugin able to directly render what we decode. See if we can
354 * find a chroma plugin to do the conversion */
355 p_vout->b_direct = 0;
357 /* Choose the best module */
358 p_vout->chroma.p_module =
359 module_Need( p_vout, MODULE_CAPABILITY_CHROMA,
360 NULL, (void *)p_vout );
362 if( p_vout->chroma.p_module == NULL )
364 msg_Err( p_vout, "no chroma module for %4.4s to %4.4s",
365 &p_vout->render.i_chroma, &p_vout->output.i_chroma );
366 p_vout->pf_end( p_vout );
367 vlc_mutex_unlock( &p_vout->change_lock );
371 #define f p_vout->chroma.p_module->p_functions->chroma.functions.chroma
372 p_vout->chroma.pf_init = f.pf_init;
373 p_vout->chroma.pf_end = f.pf_end;
376 if( I_OUTPUTPICTURES < 2 * VOUT_MAX_PICTURES )
378 msg_Dbg( p_vout, "indirect render, mapping "
379 "render pictures %i-%i to system pictures %i-%i",
380 I_OUTPUTPICTURES - 1, 2 * VOUT_MAX_PICTURES - 2,
381 I_OUTPUTPICTURES, 2 * VOUT_MAX_PICTURES - 1 );
385 /* FIXME: if this happens, we don't have any render pictures left */
386 msg_Dbg( p_vout, "indirect render, no system pictures needed,"
387 " we have %i directbuffers", I_OUTPUTPICTURES );
388 msg_Err( p_vout, "this is a bug!" );
391 /* Append render buffers after the direct buffers */
392 for( i = I_OUTPUTPICTURES; i < 2 * VOUT_MAX_PICTURES; i++ )
394 PP_RENDERPICTURE[ I_RENDERPICTURES ] = &p_vout->p_picture[ i ];
399 /* Link pictures back to their heap */
400 for( i = 0 ; i < I_RENDERPICTURES ; i++ )
402 PP_RENDERPICTURE[ i ]->p_heap = &p_vout->render;
405 for( i = 0 ; i < I_OUTPUTPICTURES ; i++ )
407 PP_OUTPUTPICTURE[ i ]->p_heap = &p_vout->output;
410 /* XXX XXX mark thread ready */
414 /*****************************************************************************
415 * RunThread: video output thread
416 *****************************************************************************
417 * Video output thread. This function does only returns when the thread is
418 * terminated. It handles the pictures arriving in the video heap and the
419 * display device events.
420 *****************************************************************************/
421 static void RunThread( vout_thread_t *p_vout)
423 int i_index; /* index in heap */
424 int i_idle_loops = 0; /* loops without displaying a picture */
425 mtime_t current_date; /* current date */
426 mtime_t display_date; /* display date */
428 picture_t * p_picture; /* picture pointer */
429 picture_t * p_last_picture = NULL; /* last picture */
430 picture_t * p_directbuffer; /* direct buffer to display */
432 subpicture_t * p_subpic; /* subpicture pointer */
437 p_vout->b_error = InitThread( p_vout );
438 if( p_vout->b_error )
440 /* Destroy thread structures allocated by Create and InitThread */
441 p_vout->pf_destroy( p_vout );
443 DestroyThread( p_vout );
448 * Main loop - it is not executed if an error occured during
451 while( (!p_vout->b_die) && (!p_vout->b_error) )
453 /* Initialize loop variables */
455 current_date = mdate();
459 if( !(p_vout->c_loops % VOUT_STATS_NB_LOOPS) )
461 msg_Dbg( p_vout, "picture heap: %d/%d",
462 I_RENDERPICTURES, p_vout->i_heap_size );
467 * Find the picture to display - this operation does not need lock,
468 * since only READY_PICTUREs are handled
472 for( i_index = 0; i_index < I_RENDERPICTURES; i_index++ )
474 if( (PP_RENDERPICTURE[i_index]->i_status == READY_PICTURE)
475 && ( (p_picture == NULL) ||
476 (PP_RENDERPICTURE[i_index]->date < display_date) ) )
478 p_picture = PP_RENDERPICTURE[i_index];
479 display_date = p_picture->date;
483 if( p_picture != NULL )
485 /* If we met the last picture, parse again to see whether there is
486 * a more appropriate one. */
487 if( p_picture == p_last_picture )
489 for( i_index = 0; i_index < I_RENDERPICTURES; i_index++ )
491 if( (PP_RENDERPICTURE[i_index]->i_status == READY_PICTURE)
492 && (PP_RENDERPICTURE[i_index] != p_last_picture)
493 && ((p_picture == p_last_picture) ||
494 (PP_RENDERPICTURE[i_index]->date < display_date)) )
496 p_picture = PP_RENDERPICTURE[i_index];
497 display_date = p_picture->date;
502 /* If we found better than the last picture, destroy it */
503 if( p_last_picture && p_picture != p_last_picture )
505 vlc_mutex_lock( &p_vout->picture_lock );
506 if( p_last_picture->i_refcount )
508 p_last_picture->i_status = DISPLAYED_PICTURE;
512 p_last_picture->i_status = DESTROYED_PICTURE;
513 p_vout->i_heap_size--;
515 vlc_mutex_unlock( &p_vout->picture_lock );
518 /* Compute FPS rate */
519 p_vout->p_fps_sample[ p_vout->c_fps_samples++ % VOUT_FPS_SAMPLES ]
522 if( !p_picture->b_force &&
523 p_picture != p_last_picture &&
524 display_date < current_date + p_vout->render_time )
526 /* Picture is late: it will be destroyed and the thread
527 * will directly choose the next picture */
528 vlc_mutex_lock( &p_vout->picture_lock );
529 if( p_picture->i_refcount )
531 /* Pretend we displayed the picture, but don't destroy
532 * it since the decoder might still need it. */
533 p_picture->i_status = DISPLAYED_PICTURE;
537 /* Destroy the picture without displaying it */
538 p_picture->i_status = DESTROYED_PICTURE;
539 p_vout->i_heap_size--;
541 msg_Warn( p_vout, "late picture skipped (%lld)",
542 current_date - display_date );
543 vlc_mutex_unlock( &p_vout->picture_lock );
548 /* Removed because it causes problems for some people --Meuuh */
549 if( display_date > current_date + VOUT_BOGUS_DELAY )
551 /* Picture is waaay too early: it will be destroyed */
552 vlc_mutex_lock( &p_vout->picture_lock );
553 if( p_picture->i_refcount )
555 /* Pretend we displayed the picture, but don't destroy
556 * it since the decoder might still need it. */
557 p_picture->i_status = DISPLAYED_PICTURE;
561 /* Destroy the picture without displaying it */
562 p_picture->i_status = DESTROYED_PICTURE;
563 p_vout->i_heap_size--;
565 intf_WarnMsg( 1, "vout warning: early picture skipped (%lld)",
566 display_date - current_date );
567 vlc_mutex_unlock( &p_vout->picture_lock );
572 if( display_date > current_date + VOUT_DISPLAY_DELAY )
574 /* A picture is ready to be rendered, but its rendering date
575 * is far from the current one so the thread will perform an
576 * empty loop as if no picture were found. The picture state
581 else if( p_picture == p_last_picture )
583 /* We are asked to repeat the previous picture, but we first
584 * wait for a couple of idle loops */
585 if( i_idle_loops < 4 )
592 //intf_WarnMsg( 6, "vout info: duplicating picture" );
597 if( p_picture == NULL )
603 * Check for subpictures to display
605 p_subpic = vout_SortSubPictures( p_vout, display_date );
610 p_directbuffer = vout_RenderPicture( p_vout, p_picture, p_subpic );
613 * Call the plugin-specific rendering method
615 if( p_picture != NULL )
617 /* Render the direct buffer returned by vout_RenderPicture */
618 p_vout->pf_render( p_vout, p_directbuffer );
624 if( display_date != 0 )
626 /* Store render time using Bresenham algorithm */
627 p_vout->render_time += mdate() - current_date;
628 p_vout->render_time >>= 1;
631 /* Give back change lock */
632 vlc_mutex_unlock( &p_vout->change_lock );
634 /* Sleep a while or until a given date */
635 if( display_date != 0 )
637 mwait( display_date - VOUT_MWAIT_TOLERANCE );
641 msleep( VOUT_IDLE_SLEEP );
644 /* On awakening, take back lock and send immediately picture
646 vlc_mutex_lock( &p_vout->change_lock );
649 * Display the previously rendered picture
651 if( p_picture != NULL )
653 /* Display the direct buffer returned by vout_RenderPicture */
654 p_vout->pf_display( p_vout, p_directbuffer );
656 /* Reinitialize idle loop count */
659 /* Tell the vout this was the last picture and that it does not
660 * need to be forced anymore. */
661 p_last_picture = p_picture;
662 p_last_picture->b_force = 0;
666 * Check events and manage thread
668 if( p_vout->pf_manage( p_vout ) )
670 /* A fatal error occured, and the thread must terminate
671 * immediately, without displaying anything - setting b_error to 1
672 * causes the immediate end of the main while() loop. */
676 if( p_vout->i_changes & VOUT_SIZE_CHANGE )
678 /* this must only happen when the vout plugin is incapable of
679 * rescaling the picture itself. In this case we need to destroy
680 * the current picture buffers and recreate new ones with the right
684 p_vout->i_changes &= ~VOUT_SIZE_CHANGE;
686 p_vout->pf_end( p_vout );
687 for( i = 0; i < I_OUTPUTPICTURES; i++ )
688 p_vout->p_picture[ i ].i_status = FREE_PICTURE;
690 I_OUTPUTPICTURES = 0;
691 if( p_vout->pf_init( p_vout ) )
693 msg_Err( p_vout, "cannot resize display" );
694 /* FixMe: p_vout->pf_end will be called again in EndThread() */
698 /* Need to reinitialise the chroma plugin */
699 p_vout->chroma.pf_end( p_vout );
700 p_vout->chroma.pf_init( p_vout );
706 * Error loop - wait until the thread destruction is requested
708 if( p_vout->b_error )
710 ErrorThread( p_vout );
716 /* Destroy method-dependant resources */
717 p_vout->pf_destroy( p_vout );
719 /* Destroy thread structures allocated by CreateThread */
720 DestroyThread( p_vout );
723 /*****************************************************************************
724 * ErrorThread: RunThread() error loop
725 *****************************************************************************
726 * This function is called when an error occured during thread main's loop. The
727 * thread can still receive feed, but must be ready to terminate as soon as
729 *****************************************************************************/
730 static void ErrorThread( vout_thread_t *p_vout )
732 /* Wait until a `die' order */
733 while( !p_vout->b_die )
736 msleep( VOUT_IDLE_SLEEP );
740 /*****************************************************************************
741 * EndThread: thread destruction
742 *****************************************************************************
743 * This function is called when the thread ends after a sucessful
744 * initialization. It frees all ressources allocated by InitThread.
745 *****************************************************************************/
746 static void EndThread( vout_thread_t *p_vout )
748 int i_index; /* index in heap */
752 struct tms cpu_usage;
755 msg_Dbg( p_vout, "cpu usage (user: %d, system: %d)",
756 cpu_usage.tms_utime, cpu_usage.tms_stime );
760 if( !p_vout->b_direct )
762 p_vout->chroma.pf_end( p_vout );
763 module_Unneed( p_vout->chroma.p_module );
766 /* Destroy all remaining pictures */
767 for( i_index = 0; i_index < 2 * VOUT_MAX_PICTURES; i_index++ )
769 if ( p_vout->p_picture[i_index].i_type == MEMORY_PICTURE )
771 free( p_vout->p_picture[i_index].p_data_orig );
775 /* Destroy all remaining subpictures */
776 for( i_index = 0; i_index < VOUT_MAX_SUBPICTURES; i_index++ )
778 if( p_vout->p_subpicture[i_index].i_status != FREE_SUBPICTURE )
780 free( p_vout->p_subpicture[i_index].p_sys );
784 /* Destroy translation tables */
785 p_vout->pf_end( p_vout );
787 /* Release the change lock */
788 vlc_mutex_unlock( &p_vout->change_lock );
791 /*****************************************************************************
792 * DestroyThread: thread destruction
793 *****************************************************************************
794 * This function is called when the thread ends. It frees all ressources
795 * allocated by CreateThread. Status is available at this stage.
796 *****************************************************************************/
797 static void DestroyThread( vout_thread_t *p_vout )
799 /* Destroy the locks */
800 vlc_mutex_destroy( &p_vout->picture_lock );
801 vlc_mutex_destroy( &p_vout->subpicture_lock );
802 vlc_mutex_destroy( &p_vout->change_lock );
804 /* Release the module */
805 module_Unneed( p_vout->p_module );
808 /* following functions are local */
810 static int ReduceHeight( int i_ratio )
812 int i_dummy = VOUT_ASPECT_FACTOR;
820 /* VOUT_ASPECT_FACTOR is (2^7 * 3^3 * 5^3), we just check for 2, 3 and 5 */
821 while( !(i_ratio & 1) && !(i_dummy & 1) )
828 while( !(i_ratio % 3) && !(i_dummy % 3) )
835 while( !(i_ratio % 5) && !(i_dummy % 5) )
845 /*****************************************************************************
846 * BinaryLog: computes the base 2 log of a binary value
847 *****************************************************************************
848 * This functions is used by MaskToShift, to get a bit index from a binary
850 *****************************************************************************/
851 static int BinaryLog(u32 i)
855 if( i == 0 ) return -31337;
857 if( i & 0xffff0000 ) i_log += 16;
858 if( i & 0xff00ff00 ) i_log += 8;
859 if( i & 0xf0f0f0f0 ) i_log += 4;
860 if( i & 0xcccccccc ) i_log += 2;
861 if( i & 0xaaaaaaaa ) i_log += 1;
866 /*****************************************************************************
867 * MaskToShift: transform a color mask into right and left shifts
868 *****************************************************************************
869 * This function is used for obtaining color shifts from masks.
870 *****************************************************************************/
871 static void MaskToShift( int *pi_left, int *pi_right, u32 i_mask )
873 u32 i_low, i_high; /* lower hand higher bits of the mask */
877 *pi_left = *pi_right = 0;
882 i_low = i_mask & (- i_mask); /* lower bit of the mask */
883 i_high = i_mask + i_low; /* higher bit of the mask */
885 /* Transform bits into an index */
886 i_low = BinaryLog (i_low);
887 i_high = BinaryLog (i_high);
889 /* Update pointers and return */
891 *pi_right = (8 - i_high + i_low);
894 /*****************************************************************************
895 * InitWindowSize: find the initial dimensions the video window should have.
896 *****************************************************************************
897 * This function will check the "width", "height" and "zoom" config options and
898 * will calculate the size that the video window should have.
899 *****************************************************************************/
900 static void InitWindowSize( vout_thread_t *p_vout, int *pi_width,
903 int i_width, i_height;
906 i_width = config_GetInt( p_vout, "width" );
907 i_height = config_GetInt( p_vout, "height" );
908 f_zoom = config_GetFloat( p_vout, "zoom" );
910 if( (i_width >= 0) && (i_height >= 0))
912 *pi_width = i_width * f_zoom;
913 *pi_height = i_height * f_zoom;
916 else if( i_width >= 0 )
918 *pi_width = i_width * f_zoom;
919 *pi_height = i_width * f_zoom * VOUT_ASPECT_FACTOR /
920 p_vout->render.i_aspect;
923 else if( i_height >= 0 )
925 *pi_height = i_height * f_zoom;
926 *pi_width = i_height * f_zoom * p_vout->render.i_aspect /
931 if( p_vout->render.i_height * p_vout->render.i_aspect
932 >= p_vout->render.i_width * VOUT_ASPECT_FACTOR )
934 *pi_width = p_vout->render.i_height * f_zoom
935 * p_vout->render.i_aspect / VOUT_ASPECT_FACTOR;
936 *pi_height = p_vout->render.i_height * f_zoom;
940 *pi_width = p_vout->render.i_width * f_zoom;
941 *pi_height = p_vout->render.i_width * f_zoom
942 * VOUT_ASPECT_FACTOR / p_vout->render.i_aspect;