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