]> git.sesse.net Git - vlc/blob - src/video_parser/vpar_synchro.c
caac6b16b67314a8656d04affc06fc6ebec22cfa
[vlc] / src / video_parser / vpar_synchro.c
1 /*****************************************************************************
2  * vpar_synchro.c : frame dropping routines
3  *****************************************************************************
4  * Copyright (C) 1999, 2000 VideoLAN
5  * $Id: vpar_synchro.c,v 1.88 2001/04/27 19:29:11 massiot Exp $
6  *
7  * Authors: Christophe Massiot <massiot@via.ecp.fr>
8  *          Samuel Hocevar <sam@via.ecp.fr>
9  *          Jean-Marc Dressler <polux@via.ecp.fr>
10  *
11  * This program is free software; you can redistribute it and/or modify
12  * it under the terms of the GNU General Public License as published by
13  * the Free Software Foundation; either version 2 of the License, or
14  * (at your option) any later version.
15  * 
16  * This program is distributed in the hope that it will be useful,
17  * but WITHOUT ANY WARRANTY; without even the implied warranty of
18  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
19  * GNU General Public License for more details.
20  *
21  * You should have received a copy of the GNU General Public License
22  * along with this program; if not, write to the Free Software
23  * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111, USA.
24  *****************************************************************************/
25
26 /*
27  * DISCUSSION : How to Write an efficient Frame-Dropping Algorithm
28  * ==========
29  *
30  * This implementation is based on mathematical and statistical
31  * developments. Older implementations used an enslavement, considering
32  * that if we're late when reading an I picture, we will decode one frame
33  * less. It had a tendancy to derive, and wasn't responsive enough, which
34  * would have caused trouble with the stream control stuff.
35  *
36  * 1. Structure of a picture stream
37  *    =============================
38  * Between 2 I's, we have for instance :
39  *    I   B   P   B   P   B   P   B   P   B   P   B   I
40  *    t0  t1  t2  t3  t4  t5  t6  t7  t8  t9  t10 t11 t12
41  * Please bear in mind that B's and IP's will be inverted when displaying
42  * (decoding order != presentation order). Thus, t1 < t0.
43  *
44  * 2. Definitions
45  *    ===========
46  * t[0..12]     : Presentation timestamps of pictures 0..12.
47  * t            : Current timestamp, at the moment of the decoding.
48  * T            : Picture period, T = 1/frame_rate.
49  * tau[I,P,B]   : Mean time to decode an [I,P,B] picture.
50  * tauYUV       : Mean time to render a picture (given by the video_output).
51  * tau´[I,P,B] = 2 * tau[I,P,B] + tauYUV
52  *              : Mean time + typical difference (estimated to tau/2, that
53  *                needs to be confirmed) + render time.
54  * DELTA        : A given error margin.
55  *
56  * 3. General considerations
57  *    ======================
58  * We define three types of machines :
59  *      14T > tauI : machines capable of decoding all I pictures
60  *      2T > tauP  : machines capable of decoding all P pictures
61  *      T > tauB   : machines capable of decoding all B pictures
62  *
63  * 4. Decoding of an I picture
64  *    ========================
65  * On fast machines, we decode all I's.
66  * Otherwise :
67  * We can decode an I picture if we simply have enough time to decode it 
68  * before displaying :
69  *      t0 - t > tau´I + DELTA
70  *
71  * 5. Decoding of a P picture
72  *    =======================
73  * On fast machines, we decode all P's.
74  * Otherwise :
75  * First criterion : have time to decode it.
76  *      t2 - t > tau´P + DELTA
77  *
78  * Second criterion : it shouldn't prevent us from displaying the forthcoming
79  * I picture, which is more important.
80  *      t12 - t > tau´P + tau´I + DELTA
81  *
82  * 6. Decoding of a B picture
83  *    =======================
84  * On fast machines, we decode all B's. Otherwise :
85  *      t1 - t > tau´B + DELTA
86  * Since the next displayed I or P is already decoded, we don't have to
87  * worry about it.
88  *
89  * I hope you will have a pleasant flight and do not forget your life
90  * jacket.
91  *                                                  --Meuuh (2000-12-29)
92  */
93
94 /*****************************************************************************
95  * Preamble
96  *****************************************************************************/
97 #include "defs.h"
98
99 #include <string.h>                                    /* memcpy(), memset() */
100
101 #include "config.h"
102 #include "common.h"
103 #include "threads.h"
104 #include "mtime.h"
105
106 #include "intf_msg.h"
107
108 #include "stream_control.h"
109 #include "input_ext-dec.h"
110
111 #include "video.h"
112 #include "video_output.h"
113
114 #include "video_decoder.h"
115 #include "vdec_motion.h"
116 #include "../video_decoder/vdec_idct.h"
117
118 #include "vpar_blocks.h"
119 #include "../video_decoder/vpar_headers.h"
120 #include "../video_decoder/vpar_synchro.h"
121 #include "../video_decoder/video_parser.h"
122
123 #include "main.h"
124
125 /*
126  * Local prototypes
127  */
128 static int  SynchroType( void );
129
130 /* Error margins */
131 #define DELTA                   (int)(0.040*CLOCK_FREQ)
132
133 #define DEFAULT_NB_P            5
134 #define DEFAULT_NB_B            1
135
136 /*****************************************************************************
137  * vpar_SynchroInit : You know what ?
138  *****************************************************************************/
139 void vpar_SynchroInit( vpar_thread_t * p_vpar )
140 {
141     p_vpar->synchro.i_type = SynchroType();
142     p_vpar->synchro.i_start = p_vpar->synchro.i_end = 0;
143     vlc_mutex_init( &p_vpar->synchro.fifo_lock );
144
145     /* We use a fake stream pattern, which is often right. */
146     p_vpar->synchro.i_n_p = p_vpar->synchro.i_eta_p = DEFAULT_NB_P;
147     p_vpar->synchro.i_n_b = p_vpar->synchro.i_eta_b = DEFAULT_NB_B;
148     memset( p_vpar->synchro.p_tau, 0, 4 * sizeof(mtime_t) );
149     memset( p_vpar->synchro.pi_meaningful, 0, 4 * sizeof(unsigned int) );
150     p_vpar->synchro.b_dropped_last = 0;
151     p_vpar->synchro.current_pts = mdate() + DEFAULT_PTS_DELAY;
152     p_vpar->synchro.backward_pts = 0;
153     p_vpar->synchro.i_current_period = p_vpar->synchro.i_backward_period = 0;
154 #ifdef STATS
155     p_vpar->synchro.i_trashed_pic = p_vpar->synchro.i_not_chosen_pic = 
156         p_vpar->synchro.i_pic = 0;
157 #endif
158 }
159
160 /*****************************************************************************
161  * vpar_SynchroChoose : Decide whether we will decode a picture or not
162  *****************************************************************************/
163 boolean_t vpar_SynchroChoose( vpar_thread_t * p_vpar, int i_coding_type,
164                               int i_structure )
165 {
166     /* For clarity reasons, we separated the special synchros code from the
167      * mathematical synchro */
168
169     if( p_vpar->synchro.i_type != VPAR_SYNCHRO_DEFAULT )
170     {
171         switch( i_coding_type )
172         {
173         case I_CODING_TYPE:
174             /* I, IP, IP+, IPB */
175             if( p_vpar->synchro.i_type == VPAR_SYNCHRO_Iplus )
176             {
177                 p_vpar->synchro.b_dropped_last = 1;
178             }
179             return( 1 );
180
181         case P_CODING_TYPE:
182             if( p_vpar->synchro.i_type == VPAR_SYNCHRO_I ) /* I */
183             {
184                 return( 0 );
185             }
186
187             if( p_vpar->synchro.i_type == VPAR_SYNCHRO_Iplus ) /* I+ */
188             {
189                 if( p_vpar->synchro.b_dropped_last )
190                 {
191                     p_vpar->synchro.b_dropped_last = 0;
192                     return( 1 );
193                 }
194                 else
195                 {
196                     return( 0 );
197                 }
198             }
199
200             return( 1 ); /* IP, IP+, IPB */
201
202         case B_CODING_TYPE:
203             if( p_vpar->synchro.i_type <= VPAR_SYNCHRO_IP ) /* I, IP */
204             {
205                 return( 0 );
206             }
207             else if( p_vpar->synchro.i_type == VPAR_SYNCHRO_IPB ) /* IPB */
208             {
209                 return( 1 );
210             }
211
212             p_vpar->synchro.b_dropped_last ^= 1; /* IP+ */
213             return( !p_vpar->synchro.b_dropped_last );
214         }
215         return( 0 ); /* never reached but gcc yells at me */
216     }
217     else
218     {
219 #define TAU_PRIME( coding_type )    (p_vpar->synchro.p_tau[(coding_type)] \
220                                  + (p_vpar->synchro.p_tau[(coding_type)] >> 1) \
221                                             + tau_yuv)
222 #define S                           p_vpar->synchro
223         /* VPAR_SYNCHRO_DEFAULT */
224         mtime_t         now, period, tau_yuv;
225         mtime_t         pts = 0;
226         boolean_t       b_decode = 0;
227 #ifdef TRACE_VPAR
228         char            p_date[MSTRTIME_MAX_SIZE];
229 #endif
230
231         now = mdate();
232         period = 1000000 * 1001 / p_vpar->sequence.i_frame_rate
233                     * p_vpar->sequence.i_current_rate / DEFAULT_RATE;
234
235         vlc_mutex_lock( &p_vpar->p_vout->change_lock );
236         tau_yuv = p_vpar->p_vout->render_time;
237         vlc_mutex_unlock( &p_vpar->p_vout->change_lock );
238 #ifdef VDEC_SMP
239         vlc_mutex_lock( &p_vpar->synchro.fifo_lock );
240 #endif
241
242         switch( i_coding_type )
243         {
244         case I_CODING_TYPE:
245             if( S.backward_pts )
246             {
247                 pts = S.backward_pts;
248             }
249             else
250             {
251                 /* displaying order : B B P B B I
252                  *                      ^       ^
253                  *                      |       +- current picture
254                  *                      +- current PTS
255                  */
256                 pts = S.current_pts + period * (S.i_n_b + 2);
257             }
258
259             if( (1 + S.i_n_p * (S.i_n_b + 1)) * period >
260                     S.p_tau[I_CODING_TYPE] )
261             {
262                 b_decode = 1;
263             }
264             else
265             {
266                 b_decode = (pts - now) > (TAU_PRIME(I_CODING_TYPE) + DELTA);
267             }
268             if( !b_decode )
269                 intf_WarnMsg( 3, "vpar synchro warning: trashing I (%lld)",
270                              pts - now);
271             break;
272
273         case P_CODING_TYPE:
274             if( S.backward_pts )
275             {
276                 pts = S.backward_pts;
277             }
278             else
279             {
280                 pts = S.current_pts + period * (S.i_n_b + 1);
281             }
282
283             if( (1 + S.i_n_p * (S.i_n_b + 1)) * period >
284                     S.p_tau[I_CODING_TYPE] )
285             {
286                 if( (S.i_n_b + 1) * period > S.p_tau[P_CODING_TYPE] )
287                 {
288                     /* Security in case we're _really_ late */
289                     b_decode = (pts - now > 0);
290                 }
291                 else
292                 {
293                     b_decode = (pts - now) > (TAU_PRIME(P_CODING_TYPE) + DELTA);
294                     /* next I */
295                     b_decode &= (pts - now
296                                   + period
297                               * ( (S.i_n_p - S.i_eta_p) * (1 + S.i_n_b) - 1 ))
298                                 > (TAU_PRIME(P_CODING_TYPE)
299                                     + TAU_PRIME(I_CODING_TYPE) + DELTA);
300                 }
301             }
302             else
303             {
304                 b_decode = 0;
305             }
306             break;
307
308         case B_CODING_TYPE:
309             pts = S.current_pts;
310
311             if( (S.i_n_b + 1) * period > S.p_tau[P_CODING_TYPE] )
312             {
313                 b_decode = (pts - now) > (TAU_PRIME(B_CODING_TYPE) + DELTA);
314             }
315             else
316             {
317                 b_decode = 0;
318             }
319         }
320
321 #ifdef VDEC_SMP
322         vlc_mutex_unlock( &p_vpar->synchro.fifo_lock );
323 #endif
324 #ifdef TRACE_VPAR
325         intf_DbgMsg("vpar synchro debug: %s picture scheduled for %s, %s (%lld)",
326                     i_coding_type == B_CODING_TYPE ? "B" :
327                     (i_coding_type == P_CODING_TYPE ? "P" : "I"),
328                     mstrtime(p_date, pts), b_decode ? "decoding" : "trashed",
329                     S.p_tau[i_coding_type]);
330 #endif
331 #ifdef STATS
332         if( !b_decode )
333         {
334             S.i_not_chosen_pic++;
335         }
336 #endif
337         return( b_decode );
338 #undef S
339 #undef TAU_PRIME
340     }
341 }
342
343 /*****************************************************************************
344  * vpar_SynchroTrash : Update counters when we trash a picture
345  *****************************************************************************/
346 void vpar_SynchroTrash( vpar_thread_t * p_vpar, int i_coding_type,
347                         int i_structure )
348 {
349 #ifdef STATS
350     p_vpar->synchro.i_trashed_pic++;
351 #endif
352 }
353
354 /*****************************************************************************
355  * vpar_SynchroDecode : Update timers when we decide to decode a picture
356  *****************************************************************************/
357 void vpar_SynchroDecode( vpar_thread_t * p_vpar, int i_coding_type,
358                          int i_structure )
359 {
360 #ifdef VDEC_SMP
361     vlc_mutex_lock( &p_vpar->synchro.fifo_lock );
362 #endif
363
364     if( ((p_vpar->synchro.i_end + 1 - p_vpar->synchro.i_start)
365             % MAX_DECODING_PIC) )
366     {
367         p_vpar->synchro.p_date_fifo[p_vpar->synchro.i_end] = mdate();
368         p_vpar->synchro.pi_coding_types[p_vpar->synchro.i_end] = i_coding_type;
369
370         FIFO_INCREMENT( i_end );
371     }
372     else
373     {
374         /* FIFO full, panic() */
375         intf_ErrMsg("vpar error: synchro fifo full, estimations will be biased (%d:%d)",
376                     p_vpar->synchro.i_start, p_vpar->synchro.i_end);
377     }
378 #ifdef VDEC_SMP
379     vlc_mutex_unlock( &p_vpar->synchro.fifo_lock );
380 #endif
381 }
382
383 /*****************************************************************************
384  * vpar_SynchroEnd : Called when the image is totally decoded
385  *****************************************************************************/
386 void vpar_SynchroEnd( vpar_thread_t * p_vpar, int i_garbage )
387 {
388     mtime_t     tau;
389     int         i_coding_type;
390
391 #ifdef VDEC_SMP
392     vlc_mutex_lock( &p_vpar->synchro.fifo_lock );
393 #endif
394
395     i_coding_type = p_vpar->synchro.pi_coding_types[p_vpar->synchro.i_start];
396
397     if( !i_garbage )
398     {
399         tau = mdate() - p_vpar->synchro.p_date_fifo[p_vpar->synchro.i_start];
400
401         /* If duration too high, something happened (pause ?), so don't
402          * take it into account. */
403         if( tau < 3 * p_vpar->synchro.p_tau[i_coding_type]
404              || !p_vpar->synchro.pi_meaningful[i_coding_type] )
405         {
406             /* Mean with average tau, to ensure stability. */
407             p_vpar->synchro.p_tau[i_coding_type] =
408                 (p_vpar->synchro.pi_meaningful[i_coding_type]
409                  * p_vpar->synchro.p_tau[i_coding_type] + tau)
410                 / (p_vpar->synchro.pi_meaningful[i_coding_type] + 1);
411             if( p_vpar->synchro.pi_meaningful[i_coding_type] < MAX_PIC_AVERAGE )
412             {
413                 p_vpar->synchro.pi_meaningful[i_coding_type]++;
414             }
415         }
416
417 #ifdef TRACE_VPAR
418         intf_DbgMsg("vpar synchro debug: finished decoding %s (%lld)",
419                     i_coding_type == B_CODING_TYPE ? "B" :
420                     (i_coding_type == P_CODING_TYPE ? "P" : "I"), tau);
421 #endif
422     }
423     else
424     {
425         intf_DbgMsg("vpar synchro debug: aborting %s",
426                     i_coding_type == B_CODING_TYPE ? "B" :
427                     (i_coding_type == P_CODING_TYPE ? "P" : "I"));
428     }
429
430     FIFO_INCREMENT( i_start );
431
432 #ifdef VDEC_SMP
433     vlc_mutex_unlock( &p_vpar->synchro.fifo_lock );
434 #endif
435 }
436
437 /*****************************************************************************
438  * vpar_SynchroDate : When an image has been decoded, ask for its date
439  *****************************************************************************/
440 mtime_t vpar_SynchroDate( vpar_thread_t * p_vpar )
441 {
442     /* No need to lock, since PTS are only used by the video parser. */
443     return( p_vpar->synchro.current_pts );
444 }
445
446 /*****************************************************************************
447  * vpar_SynchroNewPicture: Update stream structure and PTS
448  *****************************************************************************/
449 void vpar_SynchroNewPicture( vpar_thread_t * p_vpar, int i_coding_type,
450                              int i_repeat_field )
451 {
452     mtime_t         period = 1000000 * 1001 / p_vpar->sequence.i_frame_rate
453                               * p_vpar->sequence.i_current_rate / DEFAULT_RATE;
454 #if 0
455     mtime_t         now = mdate(); 
456 #endif
457
458     switch( i_coding_type )
459     {
460     case I_CODING_TYPE:
461         if( p_vpar->synchro.i_eta_p
462                 && p_vpar->synchro.i_eta_p != p_vpar->synchro.i_n_p )
463         {
464             intf_WarnMsg( 1, "Stream periodicity changed from P[%d] to P[%d]",
465                           p_vpar->synchro.i_n_p, p_vpar->synchro.i_eta_p );
466             p_vpar->synchro.i_n_p = p_vpar->synchro.i_eta_p;
467         }
468         p_vpar->synchro.i_eta_p = p_vpar->synchro.i_eta_b = 0;
469 #ifdef STATS
470         if( p_vpar->synchro.i_type == VPAR_SYNCHRO_DEFAULT )
471         {
472             intf_Msg( "vpar synchro stats: I(%lld) P(%lld)[%d] B(%lld)[%d] YUV(%lld) : trashed %d:%d/%d",
473                   p_vpar->synchro.p_tau[I_CODING_TYPE],
474                   p_vpar->synchro.p_tau[P_CODING_TYPE],
475                   p_vpar->synchro.i_n_p,
476                   p_vpar->synchro.p_tau[B_CODING_TYPE],
477                   p_vpar->synchro.i_n_b,
478                   p_vpar->p_vout->render_time,
479                   p_vpar->synchro.i_not_chosen_pic,
480                   p_vpar->synchro.i_trashed_pic -
481                   p_vpar->synchro.i_not_chosen_pic,
482                   p_vpar->synchro.i_pic );
483             p_vpar->synchro.i_trashed_pic = p_vpar->synchro.i_not_chosen_pic
484                 = p_vpar->synchro.i_pic = 0;
485         }
486 #endif
487         break;
488     case P_CODING_TYPE:
489         p_vpar->synchro.i_eta_p++;
490         if( p_vpar->synchro.i_eta_b
491                 && p_vpar->synchro.i_eta_b != p_vpar->synchro.i_n_b )
492         {
493             intf_WarnMsg( 1, "Stream periodicity changed from B[%d] to B[%d]",
494                           p_vpar->synchro.i_n_b, p_vpar->synchro.i_eta_b );
495             p_vpar->synchro.i_n_b = p_vpar->synchro.i_eta_b;
496         }
497         p_vpar->synchro.i_eta_b = 0;
498         break;
499     case B_CODING_TYPE:
500         p_vpar->synchro.i_eta_b++;
501         break;
502     }
503
504     p_vpar->synchro.current_pts += p_vpar->synchro.i_current_period
505                                         * (period >> 1);
506  
507 #define PTS_THRESHOLD   (period >> 2)
508     if( i_coding_type == B_CODING_TYPE )
509     {
510         /* A video frame can be displayed 1, 2 or 3 times, according to
511          * repeat_first_field, top_field_first, progressive_sequence and
512          * progressive_frame. */
513         p_vpar->synchro.i_current_period = i_repeat_field;
514
515         if( p_vpar->sequence.next_pts )
516         {
517             if( p_vpar->sequence.next_pts - p_vpar->synchro.current_pts
518                     > PTS_THRESHOLD
519                  || p_vpar->synchro.current_pts - p_vpar->sequence.next_pts
520                     > PTS_THRESHOLD )
521             {
522                 intf_WarnMsg( 2,
523                         "vpar synchro warning: pts != current_date (%lld)",
524                         p_vpar->synchro.current_pts
525                             - p_vpar->sequence.next_pts );
526             }
527             p_vpar->synchro.current_pts = p_vpar->sequence.next_pts;
528             p_vpar->sequence.next_pts = 0;
529         }
530     }
531     else
532     {
533         p_vpar->synchro.i_current_period = p_vpar->synchro.i_backward_period;
534         p_vpar->synchro.i_backward_period = i_repeat_field;
535
536         if( p_vpar->synchro.backward_pts )
537         {
538             if( p_vpar->sequence.next_dts && 
539                 (p_vpar->sequence.next_dts - p_vpar->synchro.backward_pts
540                     > PTS_THRESHOLD
541               || p_vpar->synchro.backward_pts - p_vpar->sequence.next_dts
542                     > PTS_THRESHOLD) )
543             {
544                 intf_WarnMsg( 2,
545                         "vpar synchro warning: backward_pts != dts (%lld)",
546                         p_vpar->sequence.next_dts
547                             - p_vpar->synchro.backward_pts );
548             }
549             if( p_vpar->synchro.backward_pts - p_vpar->synchro.current_pts
550                     > PTS_THRESHOLD
551                  || p_vpar->synchro.current_pts - p_vpar->synchro.backward_pts
552                     > PTS_THRESHOLD )
553             {
554                 intf_WarnMsg( 2,
555                    "vpar synchro warning: backward_pts != current_pts (%lld)",
556                    p_vpar->synchro.current_pts - p_vpar->synchro.backward_pts );
557             }
558             p_vpar->synchro.current_pts = p_vpar->synchro.backward_pts;
559             p_vpar->synchro.backward_pts = 0;
560         }
561         else if( p_vpar->sequence.next_dts )
562         {
563             if( p_vpar->sequence.next_dts - p_vpar->synchro.current_pts
564                     > PTS_THRESHOLD
565                  || p_vpar->synchro.current_pts - p_vpar->sequence.next_dts
566                     > PTS_THRESHOLD )
567             {
568                 intf_WarnMsg( 2,
569                         "vpar synchro warning: dts != current_pts (%lld)",
570                         p_vpar->synchro.current_pts
571                             - p_vpar->sequence.next_dts );
572             }
573             /* By definition of a DTS. */
574             p_vpar->synchro.current_pts = p_vpar->sequence.next_dts;
575             p_vpar->sequence.next_dts = 0;
576         }
577
578         if( p_vpar->sequence.next_pts )
579         {
580             /* Store the PTS for the next time we have to date an I picture. */
581             p_vpar->synchro.backward_pts = p_vpar->sequence.next_pts;
582             p_vpar->sequence.next_pts = 0;
583         }
584     }
585 #undef PTS_THRESHOLD
586
587 #if 0
588     /* Removed for incompatibility with slow motion */
589     if( p_vpar->synchro.current_pts + DEFAULT_PTS_DELAY < now )
590     {
591         /* We cannot be _that_ late, something must have happened, reinit
592          * the dates. */
593         intf_WarnMsg( 2, "PTS << now (%lld), resetting",
594                       now - p_vpar->synchro.current_pts - DEFAULT_PTS_DELAY );
595         p_vpar->synchro.current_pts = now + DEFAULT_PTS_DELAY;
596     }
597     if( p_vpar->synchro.backward_pts
598          && p_vpar->synchro.backward_pts + DEFAULT_PTS_DELAY < now )
599     {
600         /* The same. */
601         p_vpar->synchro.backward_pts = 0;
602     }
603 #endif
604
605 #ifdef STATS
606     p_vpar->synchro.i_pic++;
607 #endif
608 }
609
610 /*****************************************************************************
611  * SynchroType: Get the user's synchro type
612  *****************************************************************************
613  * This function is called at initialization.
614  *****************************************************************************/
615 static int SynchroType( void )
616 {
617     char * psz_synchro = main_GetPszVariable( VPAR_SYNCHRO_VAR, NULL );
618
619     if( psz_synchro == NULL )
620     {
621         return VPAR_SYNCHRO_DEFAULT;
622     }
623
624     switch( *psz_synchro++ )
625     {
626       case 'i':
627       case 'I':
628         switch( *psz_synchro++ )
629         {
630           case '\0':
631             return VPAR_SYNCHRO_I;
632
633           case '+':
634             if( *psz_synchro ) return 0;
635             return VPAR_SYNCHRO_Iplus;
636
637           case 'p':
638           case 'P':
639             switch( *psz_synchro++ )
640             {
641               case '\0':
642                 return VPAR_SYNCHRO_IP;
643
644               case '+':
645                 if( *psz_synchro ) return 0;
646                 return VPAR_SYNCHRO_IPplus;
647
648               case 'b':
649               case 'B':
650                 if( *psz_synchro ) return 0;
651                 return VPAR_SYNCHRO_IPB;
652
653               default:
654                 return VPAR_SYNCHRO_DEFAULT;
655                 
656             }
657
658           default:
659             return VPAR_SYNCHRO_DEFAULT;
660         }
661     }
662
663     return VPAR_SYNCHRO_DEFAULT;
664 }
665