]> git.sesse.net Git - vlc/blob - src/video_output/video_output.c
* ./Makefile: fixed OS X vlc.app compilation dependencies.
[vlc] / src / video_output / video_output.c
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.166 2002/03/15 04:41:54 sam Exp $
9  *
10  * Authors: Vincent Seguin <seguin@via.ecp.fr>
11  *
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.
16  *
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.
21  *
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  *****************************************************************************/
26
27 /*****************************************************************************
28  * Preamble
29  *****************************************************************************/
30 #include <errno.h>                                                 /* ENOMEM */
31 #include <stdlib.h>                                                /* free() */
32 #include <stdio.h>                                              /* sprintf() */
33 #include <string.h>                                            /* strerror() */
34
35 #include <videolan/vlc.h>
36
37 #ifdef HAVE_SYS_TIMES_H
38 #   include <sys/times.h>
39 #endif
40
41 #include "video.h"
42 #include "video_output.h"
43
44 /*****************************************************************************
45  * Local prototypes
46  *****************************************************************************/
47 static int      InitThread        ( vout_thread_t *p_vout );
48 static void     RunThread         ( vout_thread_t *p_vout );
49 static void     ErrorThread       ( vout_thread_t *p_vout );
50 static void     EndThread         ( vout_thread_t *p_vout );
51 static void     DestroyThread     ( vout_thread_t *p_vout, int i_status );
52 static int      ReduceHeight      ( int );
53
54 /*****************************************************************************
55  * vout_InitBank: initialize the video output bank.
56  *****************************************************************************/
57 void vout_InitBank ( void )
58 {
59     p_vout_bank->i_count = 0;
60
61     vlc_mutex_init( &p_vout_bank->lock );
62 }
63
64 /*****************************************************************************
65  * vout_EndBank: empty the video output bank.
66  *****************************************************************************
67  * This function ends all unused video outputs and empties the bank in
68  * case of success.
69  *****************************************************************************/
70 void vout_EndBank ( void )
71 {
72     /* Ask all remaining video outputs to die */
73     while( p_vout_bank->i_count )
74     {
75         vout_DestroyThread(
76                 p_vout_bank->pp_vout[ --p_vout_bank->i_count ], NULL );
77     }
78
79     vlc_mutex_destroy( &p_vout_bank->lock );
80 }
81
82 /*****************************************************************************
83  * vout_CreateThread: creates a new video output thread
84  *****************************************************************************
85  * This function creates a new video output thread, and returns a pointer
86  * to its description. On error, it returns NULL.
87  * If pi_status is NULL, then the function will block until the thread is ready.
88  * If not, it will be updated using one of the THREAD_* constants.
89  *****************************************************************************/
90 vout_thread_t * vout_CreateThread   ( int *pi_status,
91                                       int i_width, int i_height,
92                                       u32 i_chroma, int i_aspect )
93 {
94     vout_thread_t * p_vout;                             /* thread descriptor */
95     int             i_status;                               /* thread status */
96     int             i_index;                                /* loop variable */
97     char          * psz_plugin;
98
99     /* Allocate descriptor */
100     p_vout = (vout_thread_t *) malloc( sizeof(vout_thread_t) );
101     if( p_vout == NULL )
102     {
103         intf_ErrMsg( "vout error: vout thread creation returned %s",
104                      strerror(ENOMEM) );
105         return( NULL );
106     }
107
108     /* Choose the best module */
109     if( !(psz_plugin = config_GetPszVariable( "filter" )) )
110     {
111         psz_plugin = config_GetPszVariable( "vout" );
112     }
113
114     /* Initialize thread properties - thread id and locks will be initialized
115      * later */
116     p_vout->b_die               = 0;
117     p_vout->b_error             = 0;
118     p_vout->b_active            = 0;
119     p_vout->pi_status           = (pi_status != NULL) ? pi_status : &i_status;
120     *p_vout->pi_status          = THREAD_CREATE;
121
122     /* Initialize pictures and subpictures - translation tables and functions
123      * will be initialized later in InitThread */
124     for( i_index = 0; i_index < VOUT_MAX_PICTURES; i_index++)
125     {
126         p_vout->p_picture[i_index].i_status = FREE_PICTURE;
127         p_vout->p_picture[i_index].i_type   = EMPTY_PICTURE;
128     }
129
130     for( i_index = 0; i_index < VOUT_MAX_SUBPICTURES; i_index++)
131     {
132         p_vout->p_subpicture[i_index].i_status = FREE_SUBPICTURE;
133         p_vout->p_subpicture[i_index].i_type   = EMPTY_SUBPICTURE;
134     }
135
136     /* Initialize the rendering heap */
137     p_vout->i_heap_size = 0;
138
139     I_RENDERPICTURES = 0;
140     p_vout->render.i_width    = i_width;
141     p_vout->render.i_height   = i_height;
142     p_vout->render.i_chroma   = i_chroma;
143     p_vout->render.i_aspect   = i_aspect;
144
145     /* Initialize misc stuff */
146     p_vout->i_changes    = 0;
147     p_vout->f_gamma      = 0;
148     p_vout->b_grayscale  = 0;
149     p_vout->b_info       = 0;
150     p_vout->b_interface  = 0;
151     p_vout->b_scale      = 1;
152     p_vout->b_fullscreen = 0;
153     p_vout->render_time  = 10;
154     p_vout->c_fps_samples= 0;
155
156     /* user requested fullscreen? */
157     if( config_GetIntVariable( "fullscreen" ) )
158         p_vout->i_changes |= VOUT_FULLSCREEN_CHANGE;
159
160     p_vout->p_module
161         = module_Need( MODULE_CAPABILITY_VOUT, psz_plugin, (void *)p_vout );
162
163     if( psz_plugin ) free( psz_plugin );
164     if( p_vout->p_module == NULL )
165     {
166         intf_ErrMsg( "vout error: no suitable vout module" );
167         free( p_vout );
168         return( NULL );
169     }
170
171 #define f p_vout->p_module->p_functions->vout.functions.vout
172     p_vout->pf_create     = f.pf_create;
173     p_vout->pf_init       = f.pf_init;
174     p_vout->pf_end        = f.pf_end;
175     p_vout->pf_destroy    = f.pf_destroy;
176     p_vout->pf_manage     = f.pf_manage;
177     p_vout->pf_render     = f.pf_render;
178     p_vout->pf_display    = f.pf_display;
179 #undef f
180
181     /* Create thread and set locks */
182     vlc_mutex_init( &p_vout->picture_lock );
183     vlc_mutex_init( &p_vout->subpicture_lock );
184     vlc_mutex_init( &p_vout->change_lock );
185
186     if( vlc_thread_create( &p_vout->thread_id, "video output",
187                            (void *) RunThread, (void *) p_vout) )
188     {
189         intf_ErrMsg("vout error: %s", strerror(ENOMEM));
190         p_vout->pf_destroy( p_vout );
191         module_Unneed( p_vout->p_module );
192         free( p_vout );
193         return( NULL );
194     }
195
196     /* If status is NULL, wait until the thread is created */
197     if( pi_status == NULL )
198     {
199         do
200         {
201             msleep( THREAD_SLEEP );
202         }while( (i_status != THREAD_READY) && (i_status != THREAD_ERROR)
203                 && (i_status != THREAD_FATAL) );
204         if( i_status != THREAD_READY )
205         {
206             return( NULL );
207         }
208     }
209
210     return( p_vout );
211 }
212
213 /*****************************************************************************
214  * vout_DestroyThread: destroys a previously created thread
215  *****************************************************************************
216  * Destroy a terminated thread.
217  * The function will request a destruction of the specified thread. If pi_error
218  * is NULL, it will return once the thread is destroyed. Else, it will be
219  * update using one of the THREAD_* constants.
220  *****************************************************************************/
221 void vout_DestroyThread( vout_thread_t *p_vout, int *pi_status )
222 {
223     int     i_status;                                       /* thread status */
224
225     /* Set status */
226     p_vout->pi_status = (pi_status != NULL) ? pi_status : &i_status;
227     *p_vout->pi_status = THREAD_DESTROY;
228
229     /* Request thread destruction */
230     p_vout->b_die = 1;
231
232     /* If status is NULL, wait until thread has been destroyed */
233     if( pi_status == NULL )
234     {
235         do
236         {
237             msleep( THREAD_SLEEP );
238         } while( (i_status != THREAD_OVER) && (i_status != THREAD_ERROR)
239                  && (i_status != THREAD_FATAL) );
240     }
241 }
242
243 /*****************************************************************************
244  * InitThread: initialize video output thread
245  *****************************************************************************
246  * This function is called from RunThread and performs the second step of the
247  * initialization. It returns 0 on success. Note that the thread's flag are not
248  * modified inside this function.
249  *****************************************************************************/
250 static int InitThread( vout_thread_t *p_vout )
251 {
252     int i, i_pgcd;
253
254     /* Update status */
255     *p_vout->pi_status = THREAD_START;
256
257     vlc_mutex_lock( &p_vout->change_lock );
258
259 #ifdef STATS
260     p_vout->c_loops = 0;
261 #endif
262
263     /* Initialize output method, it issues its own error messages */
264     if( p_vout->pf_init( p_vout ) )
265     {
266         vlc_mutex_unlock( &p_vout->change_lock );
267         return( 1 );
268     }
269
270     if( !I_OUTPUTPICTURES )
271     {
272         intf_ErrMsg( "vout error: plugin was unable to allocate at least "
273                      "one direct buffer" );
274         p_vout->pf_end( p_vout );
275         vlc_mutex_unlock( &p_vout->change_lock );
276         return( 1 );
277     }
278
279     intf_WarnMsg( 1, "vout info: got %i direct buffer(s)", I_OUTPUTPICTURES );
280
281     i_pgcd = ReduceHeight( p_vout->render.i_aspect );
282     intf_WarnMsg( 1, "vout info: picture in %ix%i, chroma 0x%.8x (%4.4s), "
283                      "aspect ratio %i:%i",
284                   p_vout->render.i_width, p_vout->render.i_height,
285                   p_vout->render.i_chroma, (char*)&p_vout->render.i_chroma,
286                   p_vout->render.i_aspect / i_pgcd,
287                   VOUT_ASPECT_FACTOR / i_pgcd );
288
289     i_pgcd = ReduceHeight( p_vout->output.i_aspect );
290     intf_WarnMsg( 1, "vout info: picture out %ix%i, chroma 0x%.8x (%4.4s), "
291                      "aspect ratio %i:%i",
292                   p_vout->output.i_width, p_vout->output.i_height,
293                   p_vout->output.i_chroma, (char*)&p_vout->output.i_chroma,
294                   p_vout->output.i_aspect / i_pgcd,
295                   VOUT_ASPECT_FACTOR / i_pgcd );
296
297     /* Check whether we managed to create direct buffers similar to
298      * the render buffers, ie same size, chroma and aspect ratio */
299     if( ( p_vout->output.i_width == p_vout->render.i_width )
300      && ( p_vout->output.i_height == p_vout->render.i_height )
301      && ( vout_ChromaCmp( p_vout->output.i_chroma, p_vout->render.i_chroma ) )
302      && ( p_vout->output.i_aspect == p_vout->render.i_aspect ) )
303     {
304         /* Cool ! We have direct buffers, we can ask the decoder to
305          * directly decode into them ! Map the first render buffers to
306          * the first direct buffers, but keep the first direct buffer
307          * for memcpy operations */
308         p_vout->b_direct = 1;
309
310         intf_WarnMsg( 2, "vout info: direct render, mapping "
311                          "render pictures 0-%i to system pictures 1-%i",
312                          VOUT_MAX_PICTURES - 2, VOUT_MAX_PICTURES - 1 );
313
314         for( i = 1; i < VOUT_MAX_PICTURES; i++ )
315         {
316             PP_RENDERPICTURE[ I_RENDERPICTURES ] = &p_vout->p_picture[ i ];
317             I_RENDERPICTURES++;
318         }
319
320     }
321     else
322     {
323         /* Rats... Something is wrong here, we could not find an output
324          * plugin able to directly render what we decode. See if we can
325          * find a chroma plugin to do the conversion */
326         p_vout->b_direct = 0;
327
328         /* Choose the best module */
329         p_vout->chroma.p_module
330             = module_Need( MODULE_CAPABILITY_CHROMA, NULL, (void *)p_vout );
331
332         if( p_vout->chroma.p_module == NULL )
333         {
334             intf_ErrMsg( "vout error: no chroma module for %4.4s to %4.4s",
335                          &p_vout->render.i_chroma, &p_vout->output.i_chroma );
336             p_vout->pf_end( p_vout );
337             vlc_mutex_unlock( &p_vout->change_lock );
338             return( 1 );
339         }
340
341 #define f p_vout->chroma.p_module->p_functions->chroma.functions.chroma
342         p_vout->chroma.pf_init       = f.pf_init;
343         p_vout->chroma.pf_end        = f.pf_end;
344 #undef f
345
346         if( p_vout->chroma.pf_init( p_vout ) )
347         {
348             intf_ErrMsg( "vout error: could not initialize chroma module" );
349             module_Unneed( p_vout->chroma.p_module );
350             p_vout->pf_end( p_vout );
351             vlc_mutex_unlock( &p_vout->change_lock );
352             return( 1 );
353         }
354
355         if( I_OUTPUTPICTURES < VOUT_MAX_PICTURES )
356         {
357             intf_WarnMsg( 2, "vout info: indirect render, mapping "
358                              "render pictures %i-%i to system pictures %i-%i",
359                              I_OUTPUTPICTURES - 1, VOUT_MAX_PICTURES - 2,
360                              I_OUTPUTPICTURES, VOUT_MAX_PICTURES - 1 );
361         }
362         else
363         {
364             intf_WarnMsg( 2, "vout info: indirect render, no system "
365                              "pictures needed, we have %i directbuffers",
366                              I_OUTPUTPICTURES );
367         }
368
369         /* Append render buffers after the direct buffers */
370         for( i = I_OUTPUTPICTURES; i < VOUT_MAX_PICTURES; i++ )
371         {
372             PP_RENDERPICTURE[ I_RENDERPICTURES ] = &p_vout->p_picture[ i ];
373             I_RENDERPICTURES++;
374         }
375     }
376
377     /* Mark thread as running and return */
378     p_vout->b_active = 1;
379     *p_vout->pi_status = THREAD_READY;
380
381     return( 0 );
382 }
383
384 /*****************************************************************************
385  * RunThread: video output thread
386  *****************************************************************************
387  * Video output thread. This function does only returns when the thread is
388  * terminated. It handles the pictures arriving in the video heap and the
389  * display device events.
390  *****************************************************************************/
391 static void RunThread( vout_thread_t *p_vout)
392 {
393     int             i_index;                                /* index in heap */
394     mtime_t         current_date;                            /* current date */
395     mtime_t         display_date;                            /* display date */
396
397     picture_t *     p_picture;                            /* picture pointer */
398     picture_t *     p_directbuffer;              /* direct buffer to display */
399
400     subpicture_t *  p_subpic;                          /* subpicture pointer */
401
402     /*
403      * Initialize thread
404      */
405     p_vout->b_error = InitThread( p_vout );
406     if( p_vout->b_error )
407     {
408         /* Destroy thread structures allocated by Create and InitThread */
409         p_vout->pf_destroy( p_vout );
410
411         DestroyThread( p_vout, THREAD_ERROR );
412         return;
413     }
414
415     /*
416      * Main loop - it is not executed if an error occured during
417      * initialization
418      */
419     while( (!p_vout->b_die) && (!p_vout->b_error) )
420     {
421         /* Initialize loop variables */
422         display_date = 0;
423         current_date = mdate();
424
425 #ifdef STATS
426         p_vout->c_loops++;
427         if( !(p_vout->c_loops % VOUT_STATS_NB_LOOPS) )
428         {
429             intf_Msg( "vout stats: picture heap: %d/%d",
430                       I_RENDERPICTURES, p_vout->i_heap_size );
431         }
432 #endif
433
434         /*
435          * Find the picture to display - this operation does not need lock,
436          * since only READY_PICTUREs are handled
437          */
438         p_picture = NULL;
439
440         for( i_index = 0;
441              i_index < I_RENDERPICTURES;
442              i_index++ )
443         {
444             if( (PP_RENDERPICTURE[i_index]->i_status == READY_PICTURE)
445                 && ( (p_picture == NULL) ||
446                      (PP_RENDERPICTURE[i_index]->date < display_date) ) )
447             {
448                 p_picture = PP_RENDERPICTURE[i_index];
449                 display_date = p_picture->date;
450             }
451         }
452
453         if( p_picture != NULL )
454         {
455             /* Compute FPS rate */
456             p_vout->p_fps_sample[ p_vout->c_fps_samples++ % VOUT_FPS_SAMPLES ]
457                 = display_date;
458
459             if( display_date < current_date + p_vout->render_time )
460             {
461                 /* Picture is late: it will be destroyed and the thread
462                  * will directly choose the next picture */
463                 vlc_mutex_lock( &p_vout->picture_lock );
464                 if( p_picture->i_refcount )
465                 {
466                     /* Pretend we displayed the picture, but don't destroy
467                      * it since the decoder might still need it. */
468                     p_picture->i_status = DISPLAYED_PICTURE;
469                 }
470                 else
471                 {
472                     /* Destroy the picture without displaying it */
473                     p_picture->i_status = DESTROYED_PICTURE;
474                     p_vout->i_heap_size--;
475                 }
476                 intf_WarnMsg( 1, "vout warning: late picture skipped (%p)",
477                               p_picture );
478                 vlc_mutex_unlock( &p_vout->picture_lock );
479
480                 continue;
481             }
482             else if( display_date > current_date + VOUT_DISPLAY_DELAY )
483             {
484                 /* A picture is ready to be rendered, but its rendering date
485                  * is far from the current one so the thread will perform an
486                  * empty loop as if no picture were found. The picture state
487                  * is unchanged */
488                 p_picture    = NULL;
489                 display_date = 0;
490             }
491         }
492
493         /*
494          * Check for subpictures to display
495          */
496         p_subpic = vout_SortSubPictures( p_vout, display_date );
497
498         /*
499          * Perform rendering
500          */
501         p_directbuffer = vout_RenderPicture( p_vout, p_picture, p_subpic );
502
503         /*
504          * Call the plugin-specific rendering method
505          */
506         if( p_picture != NULL )
507         {
508             /* Render the direct buffer returned by vout_RenderPicture */
509             p_vout->pf_render( p_vout, p_directbuffer );
510         }
511
512         /*
513          * Sleep, wake up
514          */
515         if( display_date != 0 )
516         {
517             /* Store render time using Bresenham algorithm */
518             p_vout->render_time += mdate() - current_date;
519             p_vout->render_time >>= 1;
520         }
521
522         /* Give back change lock */
523         vlc_mutex_unlock( &p_vout->change_lock );
524
525         /* Sleep a while or until a given date */
526         if( display_date != 0 )
527         {
528             mwait( display_date - VOUT_MWAIT_TOLERANCE );
529         }
530         else
531         {
532             msleep( VOUT_IDLE_SLEEP );
533         }
534
535         /* On awakening, take back lock and send immediately picture
536          * to display. */
537         vlc_mutex_lock( &p_vout->change_lock );
538
539         /*
540          * Display the previously rendered picture
541          */
542         if( p_picture != NULL )
543         {
544             /* Display the direct buffer returned by vout_RenderPicture */
545             p_vout->pf_display( p_vout, p_directbuffer );
546
547             /* Remove picture from heap */
548             vlc_mutex_lock( &p_vout->picture_lock );
549             if( p_picture->i_refcount )
550             {
551                 p_picture->i_status = DISPLAYED_PICTURE;
552             }
553             else
554             {
555                 p_picture->i_status = DESTROYED_PICTURE;
556                 p_vout->i_heap_size--;
557             }
558             vlc_mutex_unlock( &p_vout->picture_lock );
559         }
560
561         /*
562          * Check events and manage thread
563          */
564         if( p_vout->pf_manage( p_vout ) )
565         {
566             /* A fatal error occured, and the thread must terminate immediately,
567              * without displaying anything - setting b_error to 1 causes the
568              * immediate end of the main while() loop. */
569             p_vout->b_error = 1;
570         }
571     }
572
573     /*
574      * Error loop - wait until the thread destruction is requested
575      */
576     if( p_vout->b_error )
577     {
578         ErrorThread( p_vout );
579     }
580
581     /* End of thread */
582     EndThread( p_vout );
583
584     /* Destroy method-dependant resources */
585     p_vout->pf_destroy( p_vout );
586
587     /* Destroy thread structures allocated by CreateThread */
588     DestroyThread( p_vout, THREAD_OVER );
589 }
590
591 /*****************************************************************************
592  * ErrorThread: RunThread() error loop
593  *****************************************************************************
594  * This function is called when an error occured during thread main's loop. The
595  * thread can still receive feed, but must be ready to terminate as soon as
596  * possible.
597  *****************************************************************************/
598 static void ErrorThread( vout_thread_t *p_vout )
599 {
600     /* Wait until a `die' order */
601     while( !p_vout->b_die )
602     {
603         /* Sleep a while */
604         msleep( VOUT_IDLE_SLEEP );
605     }
606 }
607
608 /*****************************************************************************
609  * EndThread: thread destruction
610  *****************************************************************************
611  * This function is called when the thread ends after a sucessful
612  * initialization. It frees all ressources allocated by InitThread.
613  *****************************************************************************/
614 static void EndThread( vout_thread_t *p_vout )
615 {
616     int     i_index;                                        /* index in heap */
617
618     /* Store status */
619     *p_vout->pi_status = THREAD_END;
620
621 #ifdef STATS
622     {
623         struct tms cpu_usage;
624         times( &cpu_usage );
625
626         intf_Msg( "vout stats: cpu usage (user: %d, system: %d)",
627                   cpu_usage.tms_utime, cpu_usage.tms_stime );
628     }
629 #endif
630
631     if( !p_vout->b_direct )
632     {
633         p_vout->chroma.pf_end( p_vout );
634         module_Unneed( p_vout->chroma.p_module );
635     }
636
637     /* Destroy all remaining pictures */
638     for( i_index = 0; i_index < VOUT_MAX_PICTURES; i_index++ )
639     {
640         if ( p_vout->p_picture[i_index].i_type == MEMORY_PICTURE )
641         {
642             free( p_vout->p_picture[i_index].p_data );
643         }
644     }
645
646     /* Destroy all remaining subpictures */
647     for( i_index = 0; i_index < VOUT_MAX_SUBPICTURES; i_index++ )
648     {
649         if( p_vout->p_subpicture[i_index].i_status != FREE_SUBPICTURE )
650         {
651             free( p_vout->p_subpicture[i_index].p_sys );
652         }
653     }
654
655     /* Destroy translation tables */
656     p_vout->pf_end( p_vout );
657
658     /* Release the change lock */
659     vlc_mutex_unlock( &p_vout->change_lock );
660 }
661
662 /*****************************************************************************
663  * DestroyThread: thread destruction
664  *****************************************************************************
665  * This function is called when the thread ends. It frees all ressources
666  * allocated by CreateThread. Status is available at this stage.
667  *****************************************************************************/
668 static void DestroyThread( vout_thread_t *p_vout, int i_status )
669 {
670     int *pi_status;                                         /* status adress */
671
672     /* Store status adress */
673     pi_status = p_vout->pi_status;
674
675     /* Destroy the locks */
676     vlc_mutex_destroy( &p_vout->picture_lock );
677     vlc_mutex_destroy( &p_vout->subpicture_lock );
678     vlc_mutex_destroy( &p_vout->change_lock );
679
680     /* Release the module */
681     module_Unneed( p_vout->p_module );
682
683     /* Free structure */
684     free( p_vout );
685     *pi_status = i_status;
686 }
687
688 static int ReduceHeight( int i_ratio )
689 {
690     int i_dummy = VOUT_ASPECT_FACTOR;
691     int i_pgcd  = 1;
692  
693     if( !i_ratio )
694     {
695         return i_pgcd;
696     }
697
698     /* VOUT_ASPECT_FACTOR is (2^7 * 3^3 * 5^3), we just check for 2, 3 and 5 */
699     while( !(i_ratio & 1) && !(i_dummy & 1) )
700     {
701         i_ratio >>= 1;
702         i_dummy >>= 1;
703         i_pgcd  <<= 1;
704     }
705
706     while( !(i_ratio % 3) && !(i_dummy % 3) )
707     {
708         i_ratio /= 3;
709         i_dummy /= 3;
710         i_pgcd  *= 3;
711     }
712
713     while( !(i_ratio % 5) && !(i_dummy % 5) )
714     {
715         i_ratio /= 5;
716         i_dummy /= 5;
717         i_pgcd  *= 5;
718     }
719
720     return i_pgcd;
721 }
722