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.192 2002/10/17 08:24:12 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() */
35 #ifdef HAVE_SYS_TIMES_H
36 # include <sys/times.h>
40 #include "video_output.h"
42 #if defined( SYS_DARWIN )
43 #include "darwin_specific.h"
46 /*****************************************************************************
48 *****************************************************************************/
49 static int InitThread ( vout_thread_t * );
50 static void RunThread ( vout_thread_t * );
51 static void ErrorThread ( vout_thread_t * );
52 static void EndThread ( vout_thread_t * );
53 static void DestroyThread ( vout_thread_t * );
55 static int ReduceHeight ( int );
56 static int BinaryLog ( u32 );
57 static void MaskToShift ( int *, int *, u32 );
58 static void InitWindowSize ( vout_thread_t *, int *, int * );
60 /*****************************************************************************
61 * vout_CreateThread: creates a new video output thread
62 *****************************************************************************
63 * This function creates a new video output thread, and returns a pointer
64 * to its description. On error, it returns NULL.
65 *****************************************************************************/
66 vout_thread_t * __vout_CreateThread ( vlc_object_t *p_parent,
67 int i_width, int i_height,
68 vlc_fourcc_t i_chroma, int i_aspect )
70 vout_thread_t * p_vout; /* thread descriptor */
71 int i_index; /* loop variable */
74 /* Allocate descriptor */
75 p_vout = vlc_object_create( p_parent, VLC_OBJECT_VOUT );
78 msg_Err( p_parent, "out of memory" );
82 /* If the parent is not a VOUT object, that means we are at the start of
83 * the video output pipe */
84 if( p_parent->i_object_type != VLC_OBJECT_VOUT )
86 /* look for the default filter configuration */
87 p_vout->psz_filter_chain = config_GetPsz( p_parent, "filter" );
91 /* continue the parent's filter chain */
94 psz_end = strchr( ((vout_thread_t *)p_parent)->psz_filter_chain, ':' );
95 if( psz_end && *(psz_end+1) )
96 p_vout->psz_filter_chain = strdup( psz_end+1 );
97 else p_vout->psz_filter_chain = NULL;
100 /* Choose the video output module */
101 if( !p_vout->psz_filter_chain )
103 psz_plugin = config_GetPsz( p_parent, "vout" );
107 /* the filter chain is a string list of filters separated by double
111 psz_end = strchr( p_vout->psz_filter_chain, ':' );
113 psz_plugin = strndup( p_vout->psz_filter_chain,
114 psz_end - p_vout->psz_filter_chain );
115 else psz_plugin = strdup( p_vout->psz_filter_chain );
118 /* Initialize pictures and subpictures - translation tables and functions
119 * will be initialized later in InitThread */
120 for( i_index = 0; i_index < 2 * VOUT_MAX_PICTURES; i_index++)
122 p_vout->p_picture[i_index].i_status = FREE_PICTURE;
123 p_vout->p_picture[i_index].i_type = EMPTY_PICTURE;
126 for( i_index = 0; i_index < VOUT_MAX_SUBPICTURES; i_index++)
128 p_vout->p_subpicture[i_index].i_status = FREE_SUBPICTURE;
129 p_vout->p_subpicture[i_index].i_type = EMPTY_SUBPICTURE;
132 /* No images in the heap */
133 p_vout->i_heap_size = 0;
135 /* Initialize the rendering heap */
136 I_RENDERPICTURES = 0;
137 p_vout->render.i_width = i_width;
138 p_vout->render.i_height = i_height;
139 p_vout->render.i_chroma = i_chroma;
140 p_vout->render.i_aspect = i_aspect;
142 p_vout->render.i_rmask = 0;
143 p_vout->render.i_gmask = 0;
144 p_vout->render.i_bmask = 0;
146 /* Zero the output heap */
147 I_OUTPUTPICTURES = 0;
148 p_vout->output.i_width = 0;
149 p_vout->output.i_height = 0;
150 p_vout->output.i_chroma = 0;
151 p_vout->output.i_aspect = 0;
153 p_vout->output.i_rmask = 0;
154 p_vout->output.i_gmask = 0;
155 p_vout->output.i_bmask = 0;
157 /* Initialize misc stuff */
158 p_vout->i_changes = 0;
160 p_vout->b_grayscale = 0;
162 p_vout->b_interface = 0;
164 p_vout->b_fullscreen = 0;
165 p_vout->render_time = 10;
166 p_vout->c_fps_samples= 0;
168 p_vout->i_mouse_x = 0;
169 p_vout->i_mouse_y = 0;
170 p_vout->i_mouse_button = 0;
172 /* user requested fullscreen? */
173 if( config_GetInt( p_vout, "fullscreen" ) )
175 p_vout->i_changes |= VOUT_FULLSCREEN_CHANGE;
178 /* Initialize the dimensions of the video window */
179 InitWindowSize( p_vout, &p_vout->i_window_width,
180 &p_vout->i_window_height );
183 p_vout->p_module = module_Need( p_vout,
184 ( p_vout->psz_filter_chain ) ?
185 "video filter" : "video output",
188 if( psz_plugin ) free( psz_plugin );
189 if( p_vout->p_module == NULL )
191 msg_Err( p_vout, "no suitable vout module" );
192 vlc_object_destroy( p_vout );
196 /* Create thread and set locks */
197 vlc_mutex_init( p_vout, &p_vout->picture_lock );
198 vlc_mutex_init( p_vout, &p_vout->subpicture_lock );
199 vlc_mutex_init( p_vout, &p_vout->change_lock );
201 vlc_object_attach( p_vout, p_parent );
203 if( vlc_thread_create( p_vout, "video output", RunThread,
204 VLC_THREAD_PRIORITY_OUTPUT, VLC_FALSE ) )
206 msg_Err( p_vout, "out of memory" );
207 module_Unneed( p_vout, p_vout->p_module );
208 vlc_object_destroy( p_vout );
215 /*****************************************************************************
216 * vout_DestroyThread: destroys a previously created thread
217 *****************************************************************************
218 * Destroy a terminated thread.
219 * The function will request a destruction of the specified thread. If pi_error
220 * is NULL, it will return once the thread is destroyed. Else, it will be
221 * update using one of the THREAD_* constants.
222 *****************************************************************************/
223 void vout_DestroyThread( vout_thread_t *p_vout )
225 /* Request thread destruction */
227 vlc_thread_join( p_vout );
230 vlc_object_destroy( p_vout );
233 /*****************************************************************************
234 * InitThread: initialize video output thread
235 *****************************************************************************
236 * This function is called from RunThread and performs the second step of the
237 * initialization. It returns 0 on success. Note that the thread's flag are not
238 * modified inside this function.
239 *****************************************************************************/
240 static int InitThread( vout_thread_t *p_vout )
244 vlc_mutex_lock( &p_vout->change_lock );
250 /* Initialize output method, it allocates direct buffers for us */
251 if( p_vout->pf_init( p_vout ) )
253 vlc_mutex_unlock( &p_vout->change_lock );
257 if( !I_OUTPUTPICTURES )
259 msg_Err( p_vout, "plugin was unable to allocate at least "
260 "one direct buffer" );
261 p_vout->pf_end( p_vout );
262 vlc_mutex_unlock( &p_vout->change_lock );
266 msg_Dbg( p_vout, "got %i direct buffer(s)", I_OUTPUTPICTURES );
268 i_pgcd = ReduceHeight( p_vout->render.i_aspect );
270 "picture in %ix%i, chroma 0x%.8x (%4.4s), aspect ratio %i:%i",
271 p_vout->render.i_width, p_vout->render.i_height,
272 p_vout->render.i_chroma, (char*)&p_vout->render.i_chroma,
273 p_vout->render.i_aspect / i_pgcd, VOUT_ASPECT_FACTOR / i_pgcd );
275 i_pgcd = ReduceHeight( p_vout->output.i_aspect );
277 "picture out %ix%i, chroma 0x%.8x (%4.4s), aspect ratio %i:%i",
278 p_vout->output.i_width, p_vout->output.i_height,
279 p_vout->output.i_chroma, (char*)&p_vout->output.i_chroma,
280 p_vout->output.i_aspect / i_pgcd, VOUT_ASPECT_FACTOR / i_pgcd );
282 /* Calculate shifts from system-updated masks */
283 MaskToShift( &p_vout->output.i_lrshift, &p_vout->output.i_rrshift,
284 p_vout->output.i_rmask );
285 MaskToShift( &p_vout->output.i_lgshift, &p_vout->output.i_rgshift,
286 p_vout->output.i_gmask );
287 MaskToShift( &p_vout->output.i_lbshift, &p_vout->output.i_rbshift,
288 p_vout->output.i_bmask );
290 /* Check whether we managed to create direct buffers similar to
291 * the render buffers, ie same size, chroma and aspect ratio */
292 if( ( p_vout->output.i_width == p_vout->render.i_width )
293 && ( p_vout->output.i_height == p_vout->render.i_height )
294 && ( vout_ChromaCmp( p_vout->output.i_chroma, p_vout->render.i_chroma ) )
295 && ( p_vout->output.i_aspect == p_vout->render.i_aspect ) )
297 /* Cool ! We have direct buffers, we can ask the decoder to
298 * directly decode into them ! Map the first render buffers to
299 * the first direct buffers, but keep the first direct buffer
300 * for memcpy operations */
301 p_vout->b_direct = 1;
303 msg_Dbg( p_vout, "direct render, mapping "
304 "render pictures 0-%i to system pictures 1-%i",
305 VOUT_MAX_PICTURES - 2, VOUT_MAX_PICTURES - 1 );
307 for( i = 1; i < VOUT_MAX_PICTURES; i++ )
309 PP_RENDERPICTURE[ I_RENDERPICTURES ] = &p_vout->p_picture[ i ];
315 /* Rats... Something is wrong here, we could not find an output
316 * plugin able to directly render what we decode. See if we can
317 * find a chroma plugin to do the conversion */
318 p_vout->b_direct = 0;
320 /* Choose the best module */
321 p_vout->chroma.p_module = module_Need( p_vout, "chroma", NULL );
323 if( p_vout->chroma.p_module == NULL )
325 msg_Err( p_vout, "no chroma module for %4.4s to %4.4s",
326 &p_vout->render.i_chroma, &p_vout->output.i_chroma );
327 p_vout->pf_end( p_vout );
328 vlc_mutex_unlock( &p_vout->change_lock );
332 if( I_OUTPUTPICTURES < 2 * VOUT_MAX_PICTURES )
334 msg_Dbg( p_vout, "indirect render, mapping "
335 "render pictures %i-%i to system pictures %i-%i",
336 I_OUTPUTPICTURES - 1, 2 * VOUT_MAX_PICTURES - 2,
337 I_OUTPUTPICTURES, 2 * VOUT_MAX_PICTURES - 1 );
341 /* FIXME: if this happens, we don't have any render pictures left */
342 msg_Dbg( p_vout, "indirect render, no system pictures needed,"
343 " we have %i directbuffers", I_OUTPUTPICTURES );
344 msg_Err( p_vout, "this is a bug!" );
347 /* Append render buffers after the direct buffers */
348 for( i = I_OUTPUTPICTURES; i < 2 * VOUT_MAX_PICTURES; i++ )
350 PP_RENDERPICTURE[ I_RENDERPICTURES ] = &p_vout->p_picture[ i ];
355 /* Link pictures back to their heap */
356 for( i = 0 ; i < I_RENDERPICTURES ; i++ )
358 PP_RENDERPICTURE[ i ]->p_heap = &p_vout->render;
361 for( i = 0 ; i < I_OUTPUTPICTURES ; i++ )
363 PP_OUTPUTPICTURE[ i ]->p_heap = &p_vout->output;
366 /* XXX XXX mark thread ready */
370 /*****************************************************************************
371 * RunThread: video output thread
372 *****************************************************************************
373 * Video output thread. This function does only returns when the thread is
374 * terminated. It handles the pictures arriving in the video heap and the
375 * display device events.
376 *****************************************************************************/
377 static void RunThread( vout_thread_t *p_vout)
379 int i_index; /* index in heap */
380 int i_idle_loops = 0; /* loops without displaying a picture */
381 mtime_t current_date; /* current date */
382 mtime_t display_date; /* display date */
384 picture_t * p_picture; /* picture pointer */
385 picture_t * p_last_picture = NULL; /* last picture */
386 picture_t * p_directbuffer; /* direct buffer to display */
388 subpicture_t * p_subpic; /* subpicture pointer */
393 p_vout->b_error = InitThread( p_vout );
394 if( p_vout->b_error )
396 /* Destroy thread structures allocated by Create and InitThread */
397 DestroyThread( p_vout );
402 * Main loop - it is not executed if an error occured during
405 while( (!p_vout->b_die) && (!p_vout->b_error) )
407 /* Initialize loop variables */
410 current_date = mdate();
414 if( !(p_vout->c_loops % VOUT_STATS_NB_LOOPS) )
416 msg_Dbg( p_vout, "picture heap: %d/%d",
417 I_RENDERPICTURES, p_vout->i_heap_size );
422 * Find the picture to display (the one with the earliest date).
423 * This operation does not need lock, since only READY_PICTUREs
425 for( i_index = 0; i_index < I_RENDERPICTURES; i_index++ )
427 if( (PP_RENDERPICTURE[i_index]->i_status == READY_PICTURE)
428 && ( (p_picture == NULL) ||
429 (PP_RENDERPICTURE[i_index]->date < display_date) ) )
431 p_picture = PP_RENDERPICTURE[i_index];
432 display_date = p_picture->date;
438 /* If we met the last picture, parse again to see whether there is
439 * a more appropriate one. */
440 if( p_picture == p_last_picture )
442 for( i_index = 0; i_index < I_RENDERPICTURES; i_index++ )
444 if( (PP_RENDERPICTURE[i_index]->i_status == READY_PICTURE)
445 && (PP_RENDERPICTURE[i_index] != p_last_picture)
446 && ((p_picture == p_last_picture) ||
447 (PP_RENDERPICTURE[i_index]->date < display_date)) )
449 p_picture = PP_RENDERPICTURE[i_index];
450 display_date = p_picture->date;
455 /* If we found better than the last picture, destroy it */
456 if( p_last_picture && p_picture != p_last_picture )
458 vlc_mutex_lock( &p_vout->picture_lock );
459 if( p_last_picture->i_refcount )
461 p_last_picture->i_status = DISPLAYED_PICTURE;
465 p_last_picture->i_status = DESTROYED_PICTURE;
466 p_vout->i_heap_size--;
468 vlc_mutex_unlock( &p_vout->picture_lock );
469 p_last_picture = NULL;
472 /* Compute FPS rate */
473 p_vout->p_fps_sample[ p_vout->c_fps_samples++ % VOUT_FPS_SAMPLES ]
476 if( !p_picture->b_force &&
477 p_picture != p_last_picture &&
478 display_date < current_date + p_vout->render_time )
480 /* Picture is late: it will be destroyed and the thread
481 * will directly choose the next picture */
482 vlc_mutex_lock( &p_vout->picture_lock );
483 if( p_picture->i_refcount )
485 /* Pretend we displayed the picture, but don't destroy
486 * it since the decoder might still need it. */
487 p_picture->i_status = DISPLAYED_PICTURE;
491 /* Destroy the picture without displaying it */
492 p_picture->i_status = DESTROYED_PICTURE;
493 p_vout->i_heap_size--;
495 msg_Warn( p_vout, "late picture skipped (%lld)",
496 current_date - display_date );
497 vlc_mutex_unlock( &p_vout->picture_lock );
502 /* Removed because it causes problems for some people --Meuuh */
503 if( display_date > current_date + VOUT_BOGUS_DELAY )
505 /* Picture is waaay too early: it will be destroyed */
506 vlc_mutex_lock( &p_vout->picture_lock );
507 if( p_picture->i_refcount )
509 /* Pretend we displayed the picture, but don't destroy
510 * it since the decoder might still need it. */
511 p_picture->i_status = DISPLAYED_PICTURE;
515 /* Destroy the picture without displaying it */
516 p_picture->i_status = DESTROYED_PICTURE;
517 p_vout->i_heap_size--;
519 intf_WarnMsg( 1, "vout warning: early picture skipped (%lld)",
520 display_date - current_date );
521 vlc_mutex_unlock( &p_vout->picture_lock );
526 if( display_date > current_date + VOUT_DISPLAY_DELAY )
528 /* A picture is ready to be rendered, but its rendering date
529 * is far from the current one so the thread will perform an
530 * empty loop as if no picture were found. The picture state
535 else if( p_picture == p_last_picture )
537 /* We are asked to repeat the previous picture, but we first
538 * wait for a couple of idle loops */
539 if( i_idle_loops < 4 )
546 /* We set the display date to something high, otherwise
547 * we'll have lots of problems with late pictures */
548 display_date = current_date + p_vout->render_time;
553 if( p_picture == NULL )
559 * Check for subpictures to display
561 p_subpic = vout_SortSubPictures( p_vout, display_date );
566 p_directbuffer = vout_RenderPicture( p_vout, p_picture, p_subpic );
569 * Call the plugin-specific rendering method if there is one
571 if( p_picture != NULL && p_vout->pf_render )
573 /* Render the direct buffer returned by vout_RenderPicture */
574 p_vout->pf_render( p_vout, p_directbuffer );
580 if( display_date != 0 )
582 /* Store render time using a sliding mean */
583 p_vout->render_time += mdate() - current_date;
584 p_vout->render_time >>= 1;
587 /* Give back change lock */
588 vlc_mutex_unlock( &p_vout->change_lock );
590 /* Sleep a while or until a given date */
591 if( display_date != 0 )
593 mwait( display_date - VOUT_MWAIT_TOLERANCE );
597 msleep( VOUT_IDLE_SLEEP );
600 /* On awakening, take back lock and send immediately picture
602 vlc_mutex_lock( &p_vout->change_lock );
605 * Display the previously rendered picture
607 if( p_picture != NULL )
609 /* Display the direct buffer returned by vout_RenderPicture */
610 if( p_vout->pf_display )
612 p_vout->pf_display( p_vout, p_directbuffer );
615 /* Reinitialize idle loop count */
618 /* Tell the vout this was the last picture and that it does not
619 * need to be forced anymore. */
620 p_last_picture = p_picture;
621 p_last_picture->b_force = 0;
625 * Check events and manage thread
627 if( p_vout->pf_manage && p_vout->pf_manage( p_vout ) )
629 /* A fatal error occured, and the thread must terminate
630 * immediately, without displaying anything - setting b_error to 1
631 * causes the immediate end of the main while() loop. */
635 if( p_vout->i_changes & VOUT_SIZE_CHANGE )
637 /* this must only happen when the vout plugin is incapable of
638 * rescaling the picture itself. In this case we need to destroy
639 * the current picture buffers and recreate new ones with the right
643 p_vout->i_changes &= ~VOUT_SIZE_CHANGE;
645 p_vout->pf_end( p_vout );
646 for( i = 0; i < I_OUTPUTPICTURES; i++ )
647 p_vout->p_picture[ i ].i_status = FREE_PICTURE;
649 I_OUTPUTPICTURES = 0;
650 if( p_vout->pf_init( p_vout ) )
652 msg_Err( p_vout, "cannot resize display" );
653 /* FIXME: pf_end will be called again in EndThread() */
657 /* Need to reinitialise the chroma plugin */
658 p_vout->chroma.p_module->pf_deactivate( VLC_OBJECT(p_vout) );
659 p_vout->chroma.p_module->pf_activate( VLC_OBJECT(p_vout) );
664 * Error loop - wait until the thread destruction is requested
666 if( p_vout->b_error )
668 ErrorThread( p_vout );
674 /* Destroy thread structures allocated by CreateThread */
675 DestroyThread( p_vout );
678 /*****************************************************************************
679 * ErrorThread: RunThread() error loop
680 *****************************************************************************
681 * This function is called when an error occured during thread main's loop. The
682 * thread can still receive feed, but must be ready to terminate as soon as
684 *****************************************************************************/
685 static void ErrorThread( vout_thread_t *p_vout )
687 /* Wait until a `die' order */
688 while( !p_vout->b_die )
691 msleep( VOUT_IDLE_SLEEP );
695 /*****************************************************************************
696 * EndThread: thread destruction
697 *****************************************************************************
698 * This function is called when the thread ends after a sucessful
699 * initialization. It frees all ressources allocated by InitThread.
700 *****************************************************************************/
701 static void EndThread( vout_thread_t *p_vout )
703 int i_index; /* index in heap */
707 struct tms cpu_usage;
710 msg_Dbg( p_vout, "cpu usage (user: %d, system: %d)",
711 cpu_usage.tms_utime, cpu_usage.tms_stime );
715 if( !p_vout->b_direct )
717 module_Unneed( p_vout, p_vout->chroma.p_module );
720 /* Destroy all remaining pictures */
721 for( i_index = 0; i_index < 2 * VOUT_MAX_PICTURES; i_index++ )
723 if ( p_vout->p_picture[i_index].i_type == MEMORY_PICTURE )
725 free( p_vout->p_picture[i_index].p_data_orig );
729 /* Destroy all remaining subpictures */
730 for( i_index = 0; i_index < VOUT_MAX_SUBPICTURES; i_index++ )
732 if( p_vout->p_subpicture[i_index].i_status != FREE_SUBPICTURE )
734 free( p_vout->p_subpicture[i_index].p_sys );
738 /* Destroy translation tables */
739 p_vout->pf_end( p_vout );
741 /* Release the change lock */
742 vlc_mutex_unlock( &p_vout->change_lock );
745 /*****************************************************************************
746 * DestroyThread: thread destruction
747 *****************************************************************************
748 * This function is called when the thread ends. It frees all ressources
749 * allocated by CreateThread. Status is available at this stage.
750 *****************************************************************************/
751 static void DestroyThread( vout_thread_t *p_vout )
753 /* Destroy the locks */
754 vlc_mutex_destroy( &p_vout->picture_lock );
755 vlc_mutex_destroy( &p_vout->subpicture_lock );
756 vlc_mutex_destroy( &p_vout->change_lock );
758 /* Release the module */
759 module_Unneed( p_vout, p_vout->p_module );
762 /* following functions are local */
764 static int ReduceHeight( int i_ratio )
766 int i_dummy = VOUT_ASPECT_FACTOR;
774 /* VOUT_ASPECT_FACTOR is (2^7 * 3^3 * 5^3), we just check for 2, 3 and 5 */
775 while( !(i_ratio & 1) && !(i_dummy & 1) )
782 while( !(i_ratio % 3) && !(i_dummy % 3) )
789 while( !(i_ratio % 5) && !(i_dummy % 5) )
799 /*****************************************************************************
800 * BinaryLog: computes the base 2 log of a binary value
801 *****************************************************************************
802 * This functions is used by MaskToShift, to get a bit index from a binary
804 *****************************************************************************/
805 static int BinaryLog(u32 i)
809 if( i == 0 ) return -31337;
811 if( i & 0xffff0000 ) i_log += 16;
812 if( i & 0xff00ff00 ) i_log += 8;
813 if( i & 0xf0f0f0f0 ) i_log += 4;
814 if( i & 0xcccccccc ) i_log += 2;
815 if( i & 0xaaaaaaaa ) i_log += 1;
820 /*****************************************************************************
821 * MaskToShift: transform a color mask into right and left shifts
822 *****************************************************************************
823 * This function is used for obtaining color shifts from masks.
824 *****************************************************************************/
825 static void MaskToShift( int *pi_left, int *pi_right, u32 i_mask )
827 u32 i_low, i_high; /* lower hand higher bits of the mask */
831 *pi_left = *pi_right = 0;
836 i_low = i_mask & (- i_mask); /* lower bit of the mask */
837 i_high = i_mask + i_low; /* higher bit of the mask */
839 /* Transform bits into an index */
840 i_low = BinaryLog (i_low);
841 i_high = BinaryLog (i_high);
843 /* Update pointers and return */
845 *pi_right = (8 - i_high + i_low);
848 /*****************************************************************************
849 * InitWindowSize: find the initial dimensions the video window should have.
850 *****************************************************************************
851 * This function will check the "width", "height" and "zoom" config options and
852 * will calculate the size that the video window should have.
853 *****************************************************************************/
854 static void InitWindowSize( vout_thread_t *p_vout, int *pi_width,
857 int i_width, i_height;
860 i_width = config_GetInt( p_vout, "width" );
861 i_height = config_GetInt( p_vout, "height" );
862 f_zoom = config_GetFloat( p_vout, "zoom" );
864 if( (i_width >= 0) && (i_height >= 0))
866 *pi_width = i_width * f_zoom;
867 *pi_height = i_height * f_zoom;
870 else if( i_width >= 0 )
872 *pi_width = i_width * f_zoom;
873 *pi_height = i_width * f_zoom * VOUT_ASPECT_FACTOR /
874 p_vout->render.i_aspect;
877 else if( i_height >= 0 )
879 *pi_height = i_height * f_zoom;
880 *pi_width = i_height * f_zoom * p_vout->render.i_aspect /
885 if( p_vout->render.i_height * p_vout->render.i_aspect
886 >= p_vout->render.i_width * VOUT_ASPECT_FACTOR )
888 *pi_width = p_vout->render.i_height * f_zoom
889 * p_vout->render.i_aspect / VOUT_ASPECT_FACTOR;
890 *pi_height = p_vout->render.i_height * f_zoom;
894 *pi_width = p_vout->render.i_width * f_zoom;
895 *pi_height = p_vout->render.i_width * f_zoom
896 * VOUT_ASPECT_FACTOR / p_vout->render.i_aspect;