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.197 2002/11/13 20:51:05 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 <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 /* Zero the output heap */
146 I_OUTPUTPICTURES = 0;
147 p_vout->output.i_width = 0;
148 p_vout->output.i_height = 0;
149 p_vout->output.i_chroma = 0;
150 p_vout->output.i_aspect = 0;
152 p_vout->output.i_rmask = 0;
153 p_vout->output.i_gmask = 0;
154 p_vout->output.i_bmask = 0;
156 /* Initialize misc stuff */
157 p_vout->i_changes = 0;
159 p_vout->b_grayscale = 0;
161 p_vout->b_interface = 0;
163 p_vout->b_fullscreen = 0;
164 p_vout->render_time = 10;
165 p_vout->c_fps_samples= 0;
167 /* Mouse coordinates */
168 var_Create( p_vout, "mouse-x", VLC_VAR_INTEGER );
169 var_Create( p_vout, "mouse-y", VLC_VAR_INTEGER );
170 var_Create( p_vout, "mouse-moved", VLC_VAR_BOOL );
171 var_Create( p_vout, "mouse-clicked", VLC_VAR_INTEGER );
173 /* user requested fullscreen? */
174 if( config_GetInt( p_vout, "fullscreen" ) )
176 p_vout->i_changes |= VOUT_FULLSCREEN_CHANGE;
179 /* Initialize the dimensions of the video window */
180 InitWindowSize( p_vout, &p_vout->i_window_width,
181 &p_vout->i_window_height );
184 p_vout->p_module = module_Need( p_vout,
185 ( p_vout->psz_filter_chain ) ?
186 "video filter" : "video output",
189 if( psz_plugin ) free( psz_plugin );
190 if( p_vout->p_module == NULL )
192 msg_Err( p_vout, "no suitable vout module" );
193 vlc_object_destroy( p_vout );
197 /* Create thread and set locks */
198 vlc_mutex_init( p_vout, &p_vout->picture_lock );
199 vlc_mutex_init( p_vout, &p_vout->subpicture_lock );
200 vlc_mutex_init( p_vout, &p_vout->change_lock );
202 vlc_object_attach( p_vout, p_parent );
204 if( vlc_thread_create( p_vout, "video output", RunThread,
205 VLC_THREAD_PRIORITY_OUTPUT, VLC_FALSE ) )
207 msg_Err( p_vout, "out of memory" );
208 module_Unneed( p_vout, p_vout->p_module );
209 vlc_object_destroy( p_vout );
216 /*****************************************************************************
217 * vout_DestroyThread: destroys a previously created thread
218 *****************************************************************************
219 * Destroy a terminated thread.
220 * The function will request a destruction of the specified thread. If pi_error
221 * is NULL, it will return once the thread is destroyed. Else, it will be
222 * update using one of the THREAD_* constants.
223 *****************************************************************************/
224 void vout_DestroyThread( vout_thread_t *p_vout )
226 /* Request thread destruction */
228 vlc_thread_join( p_vout );
231 vlc_object_destroy( p_vout );
234 /*****************************************************************************
235 * InitThread: initialize video output thread
236 *****************************************************************************
237 * This function is called from RunThread and performs the second step of the
238 * initialization. It returns 0 on success. Note that the thread's flag are not
239 * modified inside this function.
240 *****************************************************************************/
241 static int InitThread( vout_thread_t *p_vout )
245 vlc_mutex_lock( &p_vout->change_lock );
251 /* Initialize output method, it allocates direct buffers for us */
252 if( p_vout->pf_init( p_vout ) )
254 vlc_mutex_unlock( &p_vout->change_lock );
258 if( !I_OUTPUTPICTURES )
260 msg_Err( p_vout, "plugin was unable to allocate at least "
261 "one direct buffer" );
262 p_vout->pf_end( p_vout );
263 vlc_mutex_unlock( &p_vout->change_lock );
267 msg_Dbg( p_vout, "got %i direct buffer(s)", I_OUTPUTPICTURES );
269 i_pgcd = ReduceHeight( p_vout->render.i_aspect );
271 "picture in %ix%i, chroma 0x%.8x (%4.4s), aspect ratio %i:%i",
272 p_vout->render.i_width, p_vout->render.i_height,
273 p_vout->render.i_chroma, (char*)&p_vout->render.i_chroma,
274 p_vout->render.i_aspect / i_pgcd, VOUT_ASPECT_FACTOR / i_pgcd );
276 i_pgcd = ReduceHeight( p_vout->output.i_aspect );
278 "picture out %ix%i, chroma 0x%.8x (%4.4s), aspect ratio %i:%i",
279 p_vout->output.i_width, p_vout->output.i_height,
280 p_vout->output.i_chroma, (char*)&p_vout->output.i_chroma,
281 p_vout->output.i_aspect / i_pgcd, VOUT_ASPECT_FACTOR / i_pgcd );
283 /* Calculate shifts from system-updated masks */
284 MaskToShift( &p_vout->output.i_lrshift, &p_vout->output.i_rrshift,
285 p_vout->output.i_rmask );
286 MaskToShift( &p_vout->output.i_lgshift, &p_vout->output.i_rgshift,
287 p_vout->output.i_gmask );
288 MaskToShift( &p_vout->output.i_lbshift, &p_vout->output.i_rbshift,
289 p_vout->output.i_bmask );
291 /* Check whether we managed to create direct buffers similar to
292 * the render buffers, ie same size, chroma and aspect ratio */
293 if( ( p_vout->output.i_width == p_vout->render.i_width )
294 && ( p_vout->output.i_height == p_vout->render.i_height )
295 && ( vout_ChromaCmp( p_vout->output.i_chroma, p_vout->render.i_chroma ) )
296 && ( p_vout->output.i_aspect == p_vout->render.i_aspect ) )
298 /* Cool ! We have direct buffers, we can ask the decoder to
299 * directly decode into them ! Map the first render buffers to
300 * the first direct buffers, but keep the first direct buffer
301 * for memcpy operations */
302 p_vout->b_direct = 1;
304 msg_Dbg( p_vout, "direct render, mapping "
305 "render pictures 0-%i to system pictures 1-%i",
306 VOUT_MAX_PICTURES - 2, VOUT_MAX_PICTURES - 1 );
308 for( i = 1; i < VOUT_MAX_PICTURES; i++ )
310 PP_RENDERPICTURE[ I_RENDERPICTURES ] = &p_vout->p_picture[ i ];
316 /* Rats... Something is wrong here, we could not find an output
317 * plugin able to directly render what we decode. See if we can
318 * find a chroma plugin to do the conversion */
319 p_vout->b_direct = 0;
321 /* Choose the best module */
322 p_vout->chroma.p_module = module_Need( p_vout, "chroma", NULL );
324 if( p_vout->chroma.p_module == NULL )
326 msg_Err( p_vout, "no chroma module for %4.4s to %4.4s",
327 &p_vout->render.i_chroma, &p_vout->output.i_chroma );
328 p_vout->pf_end( p_vout );
329 vlc_mutex_unlock( &p_vout->change_lock );
333 if( I_OUTPUTPICTURES < 2 * VOUT_MAX_PICTURES )
335 msg_Dbg( p_vout, "indirect render, mapping "
336 "render pictures %i-%i to system pictures %i-%i",
337 I_OUTPUTPICTURES - 1, 2 * VOUT_MAX_PICTURES - 2,
338 I_OUTPUTPICTURES, 2 * VOUT_MAX_PICTURES - 1 );
342 /* FIXME: if this happens, we don't have any render pictures left */
343 msg_Dbg( p_vout, "indirect render, no system pictures needed,"
344 " we have %i directbuffers", I_OUTPUTPICTURES );
345 msg_Err( p_vout, "this is a bug!" );
348 /* Append render buffers after the direct buffers */
349 for( i = I_OUTPUTPICTURES; i < 2 * VOUT_MAX_PICTURES; i++ )
351 PP_RENDERPICTURE[ I_RENDERPICTURES ] = &p_vout->p_picture[ i ];
356 /* Link pictures back to their heap */
357 for( i = 0 ; i < I_RENDERPICTURES ; i++ )
359 PP_RENDERPICTURE[ i ]->p_heap = &p_vout->render;
362 for( i = 0 ; i < I_OUTPUTPICTURES ; i++ )
364 PP_OUTPUTPICTURE[ i ]->p_heap = &p_vout->output;
367 /* XXX XXX mark thread ready */
371 /*****************************************************************************
372 * RunThread: video output thread
373 *****************************************************************************
374 * Video output thread. This function does only returns when the thread is
375 * terminated. It handles the pictures arriving in the video heap and the
376 * display device events.
377 *****************************************************************************/
378 static void RunThread( vout_thread_t *p_vout)
380 int i_index; /* index in heap */
381 int i_idle_loops = 0; /* loops without displaying a picture */
382 mtime_t current_date; /* current date */
383 mtime_t display_date; /* display date */
385 picture_t * p_picture; /* picture pointer */
386 picture_t * p_last_picture = NULL; /* last picture */
387 picture_t * p_directbuffer; /* direct buffer to display */
389 subpicture_t * p_subpic; /* subpicture pointer */
394 p_vout->b_error = InitThread( p_vout );
395 if( p_vout->b_error )
397 /* Destroy thread structures allocated by Create and InitThread */
398 DestroyThread( p_vout );
403 * Main loop - it is not executed if an error occured during
406 while( (!p_vout->b_die) && (!p_vout->b_error) )
408 /* Initialize loop variables */
411 current_date = mdate();
415 if( !(p_vout->c_loops % VOUT_STATS_NB_LOOPS) )
417 msg_Dbg( p_vout, "picture heap: %d/%d",
418 I_RENDERPICTURES, p_vout->i_heap_size );
423 * Find the picture to display (the one with the earliest date).
424 * This operation does not need lock, since only READY_PICTUREs
426 for( i_index = 0; i_index < I_RENDERPICTURES; i_index++ )
428 if( (PP_RENDERPICTURE[i_index]->i_status == READY_PICTURE)
429 && ( (p_picture == NULL) ||
430 (PP_RENDERPICTURE[i_index]->date < display_date) ) )
432 p_picture = PP_RENDERPICTURE[i_index];
433 display_date = p_picture->date;
439 /* If we met the last picture, parse again to see whether there is
440 * a more appropriate one. */
441 if( p_picture == p_last_picture )
443 for( i_index = 0; i_index < I_RENDERPICTURES; i_index++ )
445 if( (PP_RENDERPICTURE[i_index]->i_status == READY_PICTURE)
446 && (PP_RENDERPICTURE[i_index] != p_last_picture)
447 && ((p_picture == p_last_picture) ||
448 (PP_RENDERPICTURE[i_index]->date < display_date)) )
450 p_picture = PP_RENDERPICTURE[i_index];
451 display_date = p_picture->date;
456 /* If we found better than the last picture, destroy it */
457 if( p_last_picture && p_picture != p_last_picture )
459 vlc_mutex_lock( &p_vout->picture_lock );
460 if( p_last_picture->i_refcount )
462 p_last_picture->i_status = DISPLAYED_PICTURE;
466 p_last_picture->i_status = DESTROYED_PICTURE;
467 p_vout->i_heap_size--;
469 vlc_mutex_unlock( &p_vout->picture_lock );
470 p_last_picture = NULL;
473 /* Compute FPS rate */
474 p_vout->p_fps_sample[ p_vout->c_fps_samples++ % VOUT_FPS_SAMPLES ]
477 if( !p_picture->b_force &&
478 p_picture != p_last_picture &&
479 display_date < current_date + p_vout->render_time )
481 /* Picture is late: it will be destroyed and the thread
482 * will directly choose the next picture */
483 vlc_mutex_lock( &p_vout->picture_lock );
484 if( p_picture->i_refcount )
486 /* Pretend we displayed the picture, but don't destroy
487 * it since the decoder might still need it. */
488 p_picture->i_status = DISPLAYED_PICTURE;
492 /* Destroy the picture without displaying it */
493 p_picture->i_status = DESTROYED_PICTURE;
494 p_vout->i_heap_size--;
496 msg_Warn( p_vout, "late picture skipped ("I64Fd")",
497 current_date - display_date );
498 vlc_mutex_unlock( &p_vout->picture_lock );
503 /* Removed because it causes problems for some people --Meuuh */
504 if( display_date > current_date + VOUT_BOGUS_DELAY )
506 /* Picture is waaay too early: it will be destroyed */
507 vlc_mutex_lock( &p_vout->picture_lock );
508 if( p_picture->i_refcount )
510 /* Pretend we displayed the picture, but don't destroy
511 * it since the decoder might still need it. */
512 p_picture->i_status = DISPLAYED_PICTURE;
516 /* Destroy the picture without displaying it */
517 p_picture->i_status = DESTROYED_PICTURE;
518 p_vout->i_heap_size--;
520 intf_WarnMsg( 1, "vout warning: early picture skipped "
521 "("I64Fd")", display_date - current_date );
522 vlc_mutex_unlock( &p_vout->picture_lock );
527 if( display_date > current_date + VOUT_DISPLAY_DELAY )
529 /* A picture is ready to be rendered, but its rendering date
530 * is far from the current one so the thread will perform an
531 * empty loop as if no picture were found. The picture state
536 else if( p_picture == p_last_picture )
538 /* We are asked to repeat the previous picture, but we first
539 * wait for a couple of idle loops */
540 if( i_idle_loops < 4 )
547 /* We set the display date to something high, otherwise
548 * we'll have lots of problems with late pictures */
549 display_date = current_date + p_vout->render_time;
554 if( p_picture == NULL )
560 * Check for subpictures to display
562 p_subpic = vout_SortSubPictures( p_vout, display_date );
567 p_directbuffer = vout_RenderPicture( p_vout, p_picture, p_subpic );
570 * Call the plugin-specific rendering method if there is one
572 if( p_picture != NULL && p_vout->pf_render )
574 /* Render the direct buffer returned by vout_RenderPicture */
575 p_vout->pf_render( p_vout, p_directbuffer );
581 if( display_date != 0 )
583 /* Store render time using a sliding mean */
584 p_vout->render_time += mdate() - current_date;
585 p_vout->render_time >>= 1;
588 /* Give back change lock */
589 vlc_mutex_unlock( &p_vout->change_lock );
591 /* Sleep a while or until a given date */
592 if( display_date != 0 )
594 mwait( display_date - VOUT_MWAIT_TOLERANCE );
598 msleep( VOUT_IDLE_SLEEP );
601 /* On awakening, take back lock and send immediately picture
603 vlc_mutex_lock( &p_vout->change_lock );
606 * Display the previously rendered picture
608 if( p_picture != NULL )
610 /* Display the direct buffer returned by vout_RenderPicture */
611 if( p_vout->pf_display )
613 p_vout->pf_display( p_vout, p_directbuffer );
616 /* Reinitialize idle loop count */
619 /* Tell the vout this was the last picture and that it does not
620 * need to be forced anymore. */
621 p_last_picture = p_picture;
622 p_last_picture->b_force = 0;
626 * Check events and manage thread
628 if( p_vout->pf_manage && p_vout->pf_manage( p_vout ) )
630 /* A fatal error occured, and the thread must terminate
631 * immediately, without displaying anything - setting b_error to 1
632 * causes the immediate end of the main while() loop. */
636 if( p_vout->i_changes & VOUT_SIZE_CHANGE )
638 /* this must only happen when the vout plugin is incapable of
639 * rescaling the picture itself. In this case we need to destroy
640 * the current picture buffers and recreate new ones with the right
644 p_vout->i_changes &= ~VOUT_SIZE_CHANGE;
646 p_vout->pf_end( p_vout );
647 for( i = 0; i < I_OUTPUTPICTURES; i++ )
648 p_vout->p_picture[ i ].i_status = FREE_PICTURE;
650 I_OUTPUTPICTURES = 0;
651 if( p_vout->pf_init( p_vout ) )
653 msg_Err( p_vout, "cannot resize display" );
654 /* FIXME: pf_end will be called again in EndThread() */
658 /* Need to reinitialise the chroma plugin */
659 p_vout->chroma.p_module->pf_deactivate( VLC_OBJECT(p_vout) );
660 p_vout->chroma.p_module->pf_activate( VLC_OBJECT(p_vout) );
665 * Error loop - wait until the thread destruction is requested
667 if( p_vout->b_error )
669 ErrorThread( p_vout );
675 /* Destroy thread structures allocated by CreateThread */
676 DestroyThread( p_vout );
679 /*****************************************************************************
680 * ErrorThread: RunThread() error loop
681 *****************************************************************************
682 * This function is called when an error occured during thread main's loop. The
683 * thread can still receive feed, but must be ready to terminate as soon as
685 *****************************************************************************/
686 static void ErrorThread( vout_thread_t *p_vout )
688 /* Wait until a `die' order */
689 while( !p_vout->b_die )
692 msleep( VOUT_IDLE_SLEEP );
696 /*****************************************************************************
697 * EndThread: thread destruction
698 *****************************************************************************
699 * This function is called when the thread ends after a sucessful
700 * initialization. It frees all ressources allocated by InitThread.
701 *****************************************************************************/
702 static void EndThread( vout_thread_t *p_vout )
704 int i_index; /* index in heap */
708 struct tms cpu_usage;
711 msg_Dbg( p_vout, "cpu usage (user: %d, system: %d)",
712 cpu_usage.tms_utime, cpu_usage.tms_stime );
716 if( !p_vout->b_direct )
718 module_Unneed( p_vout, p_vout->chroma.p_module );
721 /* Destroy all remaining pictures */
722 for( i_index = 0; i_index < 2 * VOUT_MAX_PICTURES; i_index++ )
724 if ( p_vout->p_picture[i_index].i_type == MEMORY_PICTURE )
726 free( p_vout->p_picture[i_index].p_data_orig );
730 /* Destroy all remaining subpictures */
731 for( i_index = 0; i_index < VOUT_MAX_SUBPICTURES; i_index++ )
733 if( p_vout->p_subpicture[i_index].i_status != FREE_SUBPICTURE )
735 free( p_vout->p_subpicture[i_index].p_sys );
739 /* Destroy translation tables */
740 p_vout->pf_end( p_vout );
742 /* Release the change lock */
743 vlc_mutex_unlock( &p_vout->change_lock );
746 /*****************************************************************************
747 * DestroyThread: thread destruction
748 *****************************************************************************
749 * This function is called when the thread ends. It frees all ressources
750 * allocated by CreateThread. Status is available at this stage.
751 *****************************************************************************/
752 static void DestroyThread( vout_thread_t *p_vout )
754 /* Destroy the locks */
755 vlc_mutex_destroy( &p_vout->picture_lock );
756 vlc_mutex_destroy( &p_vout->subpicture_lock );
757 vlc_mutex_destroy( &p_vout->change_lock );
759 /* Release the module */
760 module_Unneed( p_vout, p_vout->p_module );
763 /* following functions are local */
765 static int ReduceHeight( int i_ratio )
767 int i_dummy = VOUT_ASPECT_FACTOR;
775 /* VOUT_ASPECT_FACTOR is (2^7 * 3^3 * 5^3), we just check for 2, 3 and 5 */
776 while( !(i_ratio & 1) && !(i_dummy & 1) )
783 while( !(i_ratio % 3) && !(i_dummy % 3) )
790 while( !(i_ratio % 5) && !(i_dummy % 5) )
800 /*****************************************************************************
801 * BinaryLog: computes the base 2 log of a binary value
802 *****************************************************************************
803 * This functions is used by MaskToShift, to get a bit index from a binary
805 *****************************************************************************/
806 static int BinaryLog( uint32_t i )
810 if( i == 0 ) return -31337;
812 if( i & 0xffff0000 ) i_log += 16;
813 if( i & 0xff00ff00 ) i_log += 8;
814 if( i & 0xf0f0f0f0 ) i_log += 4;
815 if( i & 0xcccccccc ) i_log += 2;
816 if( i & 0xaaaaaaaa ) i_log += 1;
821 /*****************************************************************************
822 * MaskToShift: transform a color mask into right and left shifts
823 *****************************************************************************
824 * This function is used for obtaining color shifts from masks.
825 *****************************************************************************/
826 static void MaskToShift( int *pi_left, int *pi_right, uint32_t i_mask )
828 uint32_t i_low, i_high; /* lower hand higher bits of the mask */
832 *pi_left = *pi_right = 0;
837 i_low = i_mask & (- (int32_t)i_mask); /* lower bit of the mask */
838 i_high = i_mask + i_low; /* higher bit of the mask */
840 /* Transform bits into an index */
841 i_low = BinaryLog (i_low);
842 i_high = BinaryLog (i_high);
844 /* Update pointers and return */
846 *pi_right = (8 - i_high + i_low);
849 /*****************************************************************************
850 * InitWindowSize: find the initial dimensions the video window should have.
851 *****************************************************************************
852 * This function will check the "width", "height" and "zoom" config options and
853 * will calculate the size that the video window should have.
854 *****************************************************************************/
855 static void InitWindowSize( vout_thread_t *p_vout, int *pi_width,
858 int i_width, i_height;
861 #define FP_FACTOR 1000 /* our fixed point factor */
863 i_width = config_GetInt( p_vout, "width" );
864 i_height = config_GetInt( p_vout, "height" );
865 ll_zoom = (uint64_t)( FP_FACTOR * config_GetFloat( p_vout, "zoom" ) );
867 if( (i_width >= 0) && (i_height >= 0))
869 *pi_width = (int)( i_width * ll_zoom / FP_FACTOR );
870 *pi_height = (int)( i_height * ll_zoom / FP_FACTOR );
873 else if( i_width >= 0 )
875 *pi_width = (int)( i_width * ll_zoom / FP_FACTOR );
876 *pi_height = (int)( i_width * ll_zoom * VOUT_ASPECT_FACTOR /
877 p_vout->render.i_aspect / FP_FACTOR );
880 else if( i_height >= 0 )
882 *pi_height = (int)( i_height * ll_zoom / FP_FACTOR );
883 *pi_width = (int)( i_height * ll_zoom * p_vout->render.i_aspect /
884 VOUT_ASPECT_FACTOR / FP_FACTOR );
888 if( p_vout->render.i_height * p_vout->render.i_aspect
889 >= p_vout->render.i_width * VOUT_ASPECT_FACTOR )
891 *pi_width = (int)( p_vout->render.i_height * ll_zoom
892 * p_vout->render.i_aspect / VOUT_ASPECT_FACTOR / FP_FACTOR );
893 *pi_height = (int)( p_vout->render.i_height * ll_zoom / FP_FACTOR );
897 *pi_width = (int)( p_vout->render.i_width * ll_zoom / FP_FACTOR );
898 *pi_height = (int)( p_vout->render.i_width * ll_zoom
899 * VOUT_ASPECT_FACTOR / p_vout->render.i_aspect / FP_FACTOR );