]> git.sesse.net Git - vlc/blob - src/video_parser/vpar_synchro.c
. disparition de la plupart des printf
[vlc] / src / video_parser / vpar_synchro.c
1 /*****************************************************************************
2  * vpar_motion.c : motion vectors parsing
3  *****************************************************************************
4  * Copyright (C) 1999, 2000 VideoLAN
5  *
6  * Authors:
7  *
8  * This program is free software; you can redistribute it and/or modify
9  * it under the terms of the GNU General Public License as published by
10  * the Free Software Foundation; either version 2 of the License, or
11  * (at your option) any later version.
12  * 
13  * This program is distributed in the hope that it will be useful,
14  * but WITHOUT ANY WARRANTY; without even the implied warranty of
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16  * GNU General Public License for more details.
17  *
18  * You should have received a copy of the GNU General Public License
19  * along with this program; if not, write to the Free Software
20  * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111, USA.
21  *****************************************************************************/
22
23 /*****************************************************************************
24  * Preamble
25  *****************************************************************************/
26 #include "defs.h"
27
28 #include <stdlib.h>                                                /* free() */
29 #include <sys/types.h>                        /* on BSD, uio.h needs types.h */
30 #include <sys/uio.h>                                            /* "input.h" */
31
32 #include "config.h"
33 #include "common.h"
34 #include "threads.h"
35 #include "mtime.h"
36 #include "plugins.h"
37
38 #include "intf_msg.h"
39
40 #include "input.h"
41 #include "decoder_fifo.h"
42 #include "video.h"
43 #include "video_output.h"
44
45 #include "vdec_idct.h"
46 #include "video_decoder.h"
47 #include "vdec_motion.h"
48
49 #include "vpar_blocks.h"
50 #include "vpar_headers.h"
51 #include "vpar_synchro.h"
52 #include "video_parser.h"
53
54 #define MAX_COUNT 3
55
56 /*
57  * Local prototypes
58  */
59
60 #ifdef SAM_SYNCHRO
61 /*****************************************************************************
62  * vpar_SynchroUpdateTab : Update a mean table in the synchro structure
63  *****************************************************************************/
64 float vpar_SynchroUpdateTab( video_synchro_tab_t * tab, int count )
65 {
66
67     tab->mean = ( tab->mean + MAX_COUNT * count ) / ( MAX_COUNT + 1 );
68     tab->deviation = ( tab->deviation + MAX_COUNT * abs (tab->mean - count) )
69                         / ( MAX_COUNT + 1 );
70
71     return tab->deviation;
72 }
73
74 /*****************************************************************************
75  * vpar_SynchroUpdateStructures : Update the synchro structures
76  *****************************************************************************/
77 void vpar_SynchroUpdateStructures( vpar_thread_t * p_vpar,
78                                    int i_coding_type, int dropped )
79 {
80     float candidate_deviation;
81     float optimal_deviation;
82     float predict;
83     mtime_t i_current_pts;
84     mtime_t i_delay;
85     mtime_t i_displaydate;
86     decoder_fifo_t * decoder_fifo = p_vpar->bit_stream.p_decoder_fifo;
87
88     /* interpolate the current _decode_ PTS */
89     i_current_pts = decoder_fifo->buffer[decoder_fifo->i_start]->b_has_pts ?
90                     decoder_fifo->buffer[decoder_fifo->i_start]->i_pts :
91                     0;
92     if( !i_current_pts )
93     {
94         i_current_pts = p_vpar->synchro.i_last_decode_pts
95                        + 1000000.0 / (1 + p_vpar->synchro.actual_fps);
96     }
97     p_vpar->synchro.i_last_decode_pts = i_current_pts;
98
99     /* see if the current image has a pts - if not, set to 0 */
100     p_vpar->synchro.fifo[p_vpar->synchro.i_fifo_stop].i_pts
101             = i_current_pts;
102
103     /* update display time */
104     i_displaydate = decoder_fifo->buffer[decoder_fifo->i_start]->b_has_pts ?
105                     decoder_fifo->buffer[decoder_fifo->i_start]->i_pts :
106                     0;
107     if( !i_displaydate || i_coding_type != I_CODING_TYPE )
108     {
109         if (!p_vpar->synchro.i_images_since_pts )
110             p_vpar->synchro.i_images_since_pts = 10;
111
112         i_displaydate = p_vpar->synchro.i_last_display_pts
113                        + 1000000.0 / (p_vpar->synchro.theorical_fps);
114     }
115
116     decoder_fifo->buffer[decoder_fifo->i_start]->b_has_pts = 0;
117
118     p_vpar->synchro.i_images_since_pts--;
119     p_vpar->synchro.i_last_display_pts = i_displaydate;
120
121
122
123     /* update structures */
124     switch(i_coding_type)
125     {
126         case P_CODING_TYPE:
127
128             p_vpar->synchro.current_p_count++;
129             if( !dropped ) p_vpar->synchro.nondropped_p_count++;
130             break;
131
132         case B_CODING_TYPE:
133             p_vpar->synchro.current_b_count++;
134             if( !dropped ) p_vpar->synchro.nondropped_b_count++;
135             break;
136
137         case I_CODING_TYPE:
138
139             /* update information about images we can decode */
140             if (i_current_pts != p_vpar->synchro.i_last_i_pts)
141             {
142                 if ( p_vpar->synchro.i_last_i_pts && i_current_pts != p_vpar->synchro.i_last_i_pts)
143                 {
144                     p_vpar->synchro.theorical_fps = (p_vpar->synchro.theorical_fps + 1000000.0 * (1 + p_vpar->synchro.current_b_count + p_vpar->synchro.current_p_count) / (i_current_pts - p_vpar->synchro.i_last_i_pts)) / 2;
145                 }
146                 p_vpar->synchro.i_last_i_pts = i_current_pts;
147             }
148
149             if( !dropped )
150             {
151                 if ( p_vpar->synchro.i_last_nondropped_i_pts && i_current_pts != p_vpar->synchro.i_last_nondropped_i_pts)
152                 {
153                     p_vpar->synchro.actual_fps = (p_vpar->synchro.actual_fps + 1000000.0 * (1 + p_vpar->synchro.nondropped_b_count + p_vpar->synchro.nondropped_p_count) / (i_current_pts - p_vpar->synchro.i_last_nondropped_i_pts)) / 2;
154                 }
155
156             }
157
158
159             /* update all the structures for P images */
160
161             /* period == 1 */
162             optimal_deviation = vpar_SynchroUpdateTab(
163                             &p_vpar->synchro.tab_p[0],
164                             p_vpar->synchro.current_p_count);
165             predict = p_vpar->synchro.tab_p[0].mean;
166
167             /* period == 2 */
168             candidate_deviation = vpar_SynchroUpdateTab(
169                             &p_vpar->synchro.tab_p[1 + (p_vpar->synchro.modulo & 0x1)],
170                             p_vpar->synchro.current_p_count);
171             if (candidate_deviation < optimal_deviation)
172             {
173                 optimal_deviation = candidate_deviation;
174                 predict = p_vpar->synchro.tab_p[1 + (p_vpar->synchro.modulo & 0x1)].mean;
175             }
176
177             /* period == 3 */
178             candidate_deviation = vpar_SynchroUpdateTab(
179                             &p_vpar->synchro.tab_p[3 + (p_vpar->synchro.modulo % 3)],
180                             p_vpar->synchro.current_p_count);
181             if (candidate_deviation < optimal_deviation)
182             {
183                 optimal_deviation = candidate_deviation;
184                 predict = p_vpar->synchro.tab_p[1 + (p_vpar->synchro.modulo % 3)].mean;
185             }
186
187             p_vpar->synchro.p_count_predict = predict;
188             p_vpar->synchro.current_p_count = 0;
189
190
191             /* update all the structures for B images */
192
193             /* period == 1 */
194             optimal_deviation = vpar_SynchroUpdateTab(
195                             &p_vpar->synchro.tab_b[0],
196                             p_vpar->synchro.current_b_count);
197             predict = p_vpar->synchro.tab_b[0].mean;
198
199             /* period == 2 */
200             candidate_deviation = vpar_SynchroUpdateTab(
201                             &p_vpar->synchro.tab_b[1 + (p_vpar->synchro.modulo & 0x1)],
202                             p_vpar->synchro.current_b_count);
203             if (candidate_deviation < optimal_deviation)
204             {
205                 optimal_deviation = candidate_deviation;
206                 predict = p_vpar->synchro.tab_b[1 + (p_vpar->synchro.modulo & 0x1)].mean;
207             }
208
209             /* period == 3 */
210             candidate_deviation = vpar_SynchroUpdateTab(
211                             &p_vpar->synchro.tab_b[3 + (p_vpar->synchro.modulo % 3)],
212                             p_vpar->synchro.current_b_count);
213             if (candidate_deviation < optimal_deviation)
214             {
215                 optimal_deviation = candidate_deviation;
216                 predict = p_vpar->synchro.tab_b[1 + (p_vpar->synchro.modulo % 3)].mean;
217             }
218
219             p_vpar->synchro.b_count_predict = predict;
220             p_vpar->synchro.current_b_count = 0;
221
222             /* now we calculated all statistics, it's time to
223              * decide what we have the time to display
224              */
225             i_delay = i_current_pts - p_vpar->synchro.i_last_nondropped_i_pts;
226
227             p_vpar->synchro.can_display_i
228                 = ( p_vpar->synchro.i_mean_decode_time < i_delay );
229
230             p_vpar->synchro.can_display_p
231                     = ( p_vpar->synchro.i_mean_decode_time
232                     * (1 + p_vpar->synchro.p_count_predict) < i_delay );
233
234             if( !p_vpar->synchro.can_display_p )
235             {
236                 p_vpar->synchro.displayable_p
237                     = -1 + i_delay / p_vpar->synchro.i_mean_decode_time;
238                 if( p_vpar->synchro.displayable_p < 0 )
239                     p_vpar->synchro.displayable_p = 0;
240             }
241             else
242                 p_vpar->synchro.displayable_p = 0;
243
244             if( p_vpar->synchro.can_display_p
245                 && !(p_vpar->synchro.can_display_b
246                     = ( p_vpar->synchro.i_mean_decode_time
247                     * (1 + p_vpar->synchro.b_count_predict
248                         + p_vpar->synchro.p_count_predict)) < i_delay) )
249             {
250                 p_vpar->synchro.displayable_b
251                     = -2.0 + i_delay / p_vpar->synchro.i_mean_decode_time
252                         - p_vpar->synchro.can_display_p;
253             }
254             else
255                 p_vpar->synchro.displayable_b = 0;
256
257 #if 0
258             intf_DbgMsg( "I %i  P %i (%f)  B %i (%f)\n",
259                 p_vpar->synchro.can_display_i,
260                 p_vpar->synchro.can_display_p,
261                 p_vpar->synchro.displayable_p,
262                 p_vpar->synchro.can_display_b,
263                 p_vpar->synchro.displayable_b );
264 #endif
265
266             /* update some values */
267             if( !dropped )
268             {
269                 p_vpar->synchro.i_last_nondropped_i_pts = i_current_pts;
270                 p_vpar->synchro.nondropped_p_count = 0;
271                 p_vpar->synchro.nondropped_b_count = 0;
272             }
273
274             break;
275
276     }
277
278     p_vpar->synchro.modulo++;
279
280 }
281
282 /*****************************************************************************
283  * vpar_SynchroChoose : Decide whether we will decode a picture or not
284  *****************************************************************************/
285 boolean_t vpar_SynchroChoose( vpar_thread_t * p_vpar, int i_coding_type,
286                               int i_structure )
287 {
288     mtime_t i_delay = p_vpar->synchro.i_last_decode_pts - mdate();
289
290     switch( i_coding_type )
291     {
292         case I_CODING_TYPE:
293
294             return( p_vpar->synchro.can_display_i );
295
296         case P_CODING_TYPE:
297
298             if( p_vpar->synchro.can_display_p )
299                 return( 1 );
300
301             if( p_vpar->synchro.displayable_p * i_delay
302                 < p_vpar->synchro.i_mean_decode_time )
303             {
304                 //intf_ErrMsg( "trashed a P\n" );
305                 return( 0 );
306             }
307
308             p_vpar->synchro.displayable_p--;
309             return( 1 );
310
311         case B_CODING_TYPE:
312
313             if( p_vpar->synchro.can_display_b )
314                 return( 1 );
315
316             /* modulo & 0x3 is here to add some randomness */
317             if( i_delay < (1 + (p_vpar->synchro.modulo & 0x3))
318                 * p_vpar->synchro.i_mean_decode_time )
319             {
320                 //intf_ErrMsg( "trashed a B\n" );
321                 return( 0 );
322             }
323
324             if( p_vpar->synchro.displayable_b <= 0 )
325                 return( 0 );
326
327             p_vpar->synchro.displayable_b--;
328             return( 1 );
329     }
330
331     return( 0 );
332
333 }
334
335 /*****************************************************************************
336  * vpar_SynchroTrash : Update timers when we trash a picture
337  *****************************************************************************/
338 void vpar_SynchroTrash( vpar_thread_t * p_vpar, int i_coding_type,
339                         int i_structure )
340 {
341     vpar_SynchroUpdateStructures (p_vpar, i_coding_type, 1);
342
343 }
344
345 /*****************************************************************************
346  * vpar_SynchroDecode : Update timers when we decide to decode a picture
347  *****************************************************************************/
348 void vpar_SynchroDecode( vpar_thread_t * p_vpar, int i_coding_type,
349                             int i_structure )
350 {
351     vpar_SynchroUpdateStructures (p_vpar, i_coding_type, 0);
352
353     p_vpar->synchro.fifo[p_vpar->synchro.i_fifo_stop].i_decode_date = mdate();
354     p_vpar->synchro.fifo[p_vpar->synchro.i_fifo_stop].i_image_type
355         = i_coding_type;
356
357     p_vpar->synchro.i_fifo_stop = (p_vpar->synchro.i_fifo_stop + 1) & 0xf;
358
359 }
360
361 /*****************************************************************************
362  * vpar_SynchroEnd : Called when the image is totally decoded
363  *****************************************************************************/
364 void vpar_SynchroEnd( vpar_thread_t * p_vpar )
365 {
366     mtime_t i_decode_time;
367
368     i_decode_time = (mdate() -
369             p_vpar->synchro.fifo[p_vpar->synchro.i_fifo_start].i_decode_date)
370         / ( (p_vpar->synchro.i_fifo_stop - p_vpar->synchro.i_fifo_start) & 0x0f);
371
372     p_vpar->synchro.i_mean_decode_time =
373         ( 7 * p_vpar->synchro.i_mean_decode_time + i_decode_time ) / 8;
374
375     /* intf_ErrMsg( "decoding time was %lli\n",
376         p_vpar->synchro.i_mean_decode_time ); */
377
378     p_vpar->synchro.i_fifo_start = (p_vpar->synchro.i_fifo_start + 1) & 0xf;
379
380 }
381
382 /*****************************************************************************
383  * vpar_SynchroDate : When an image has been decoded, ask for its date
384  *****************************************************************************/
385 mtime_t vpar_SynchroDate( vpar_thread_t * p_vpar )
386 {
387     mtime_t i_displaydate = p_vpar->synchro.i_last_display_pts;
388
389 #if 0
390     static mtime_t i_delta = 0;
391
392     intf_ErrMsg( "displaying type %i with delay %lli and delta %lli\n",
393         p_vpar->synchro.fifo[p_vpar->synchro.i_fifo_start].i_image_type,
394         i_displaydate - mdate(),
395         i_displaydate - i_delta );
396
397     intf_ErrMsg ( "theorical fps: %f - actual fps: %f \n",
398         p_vpar->synchro.theorical_fps, p_vpar->synchro.actual_fps );
399
400     i_delta = i_displaydate;
401 #endif
402
403     return i_displaydate;
404 }
405
406 #endif
407
408 #ifdef MEUUH_SYNCHRO
409
410 /* synchro a deux balles backportee du decodeur de reference. NE MARCHE PAS
411 AVEC LES IMAGES MONOTRAMES */
412
413 boolean_t vpar_SynchroChoose( vpar_thread_t * p_vpar, int i_coding_type,
414                               int i_structure )
415 {
416     switch (i_coding_type)
417     {
418     case B_CODING_TYPE:
419         if ((p_vpar->synchro.kludge_level <= p_vpar->synchro.kludge_nbp))
420         {
421             p_vpar->synchro.kludge_b++;
422             return( 0 );
423         }
424         if (p_vpar->synchro.kludge_b %
425              (p_vpar->synchro.kludge_nbb /
426                 (p_vpar->synchro.kludge_level - p_vpar->synchro.kludge_nbp)))
427         {
428             p_vpar->synchro.kludge_b++;
429             return( 0 );
430         }
431         p_vpar->synchro.kludge_b++;
432         return( 1 );
433
434     case P_CODING_TYPE:
435         if (p_vpar->synchro.kludge_p++ >= p_vpar->synchro.kludge_level)
436         {
437             return( 0 );
438         }
439         return( 1 );
440
441     default:
442         return( 1 );
443     }
444 }
445
446 void vpar_SynchroTrash( vpar_thread_t * p_vpar, int i_coding_type,
447                         int i_structure )
448 {
449     if (DECODER_FIFO_START(p_vpar->fifo)->b_has_pts && i_coding_type == I_CODING_TYPE)
450     {
451         p_vpar->synchro.kludge_nbframes = 0;
452         p_vpar->synchro.kludge_date = DECODER_FIFO_START(p_vpar->fifo)->i_pts;
453     }
454     else
455         p_vpar->synchro.kludge_nbframes++;
456     DECODER_FIFO_START(p_vpar->fifo)->b_has_pts = 0;
457 }
458
459 void vpar_SynchroDecode( vpar_thread_t * p_vpar, int i_coding_type,
460                             int i_structure )
461 {
462     if (DECODER_FIFO_START(p_vpar->fifo)->b_has_pts && i_coding_type == I_CODING_TYPE)
463     {
464         p_vpar->synchro.kludge_nbframes = 0;
465         p_vpar->synchro.kludge_date = DECODER_FIFO_START(p_vpar->fifo)->i_pts;
466         DECODER_FIFO_START(p_vpar->fifo)->b_has_pts = 0;
467     }
468     else
469         p_vpar->synchro.kludge_nbframes++;
470 }
471
472 mtime_t vpar_SynchroDate( vpar_thread_t * p_vpar )
473 {
474     return( p_vpar->synchro.kludge_date
475             + p_vpar->synchro.kludge_nbframes*1000000/(p_vpar->sequence.r_frame_rate ) );
476 }
477
478 void vpar_SynchroEnd( vpar_thread_t * p_vpar )
479 {
480 }
481
482 void vpar_SynchroKludge( vpar_thread_t * p_vpar, mtime_t date )
483 {
484     mtime_t     show_date;
485     int         temp = p_vpar->synchro.kludge_level;
486
487     p_vpar->synchro.kludge_nbp = p_vpar->synchro.kludge_p ? p_vpar->synchro.kludge_p : 5;
488     p_vpar->synchro.kludge_nbb = p_vpar->synchro.kludge_b ? p_vpar->synchro.kludge_b : 6;
489     show_date = date - mdate();
490     p_vpar->synchro.kludge_p = 0;
491     p_vpar->synchro.kludge_b = 0;
492
493     if (show_date < (SYNC_DELAY - SYNC_TOLERATE) && show_date <= p_vpar->synchro.kludge_prevdate)
494     {
495         p_vpar->synchro.kludge_level--;
496         if (p_vpar->synchro.kludge_level < 0)
497             p_vpar->synchro.kludge_level = 0;
498         else if (p_vpar->synchro.kludge_level >
499                      p_vpar->synchro.kludge_nbp + p_vpar->synchro.kludge_nbb)
500             p_vpar->synchro.kludge_level = p_vpar->synchro.kludge_nbp + p_vpar->synchro.kludge_nbb;
501 #ifdef DEBUG
502         if (temp != p_vpar->synchro.kludge_level)
503             intf_DbgMsg("vdec debug: Level changed from %d to %d (%Ld)\n",
504                         temp, p_vpar->synchro.kludge_level, show_date );
505 #endif
506     }
507     else if (show_date > (SYNC_DELAY + SYNC_TOLERATE) && show_date >= p_vpar->synchro.kludge_prevdate)
508     {
509         p_vpar->synchro.kludge_level++;
510         if (p_vpar->synchro.kludge_level > p_vpar->synchro.kludge_nbp + p_vpar->synchro.kludge_nbb)
511             p_vpar->synchro.kludge_level = p_vpar->synchro.kludge_nbp + p_vpar->synchro.kludge_nbb;
512 #ifdef DEBUG
513         if (temp != p_vpar->synchro.kludge_level)
514             intf_DbgMsg("vdec debug: Level changed from %d to %d (%Ld)\n",
515                         temp, p_vpar->synchro.kludge_level, show_date );
516 #endif
517     }
518
519     p_vpar->synchro.kludge_prevdate = show_date;
520     if ((p_vpar->synchro.kludge_level - p_vpar->synchro.kludge_nbp) > p_vpar->synchro.kludge_nbb)
521         p_vpar->synchro.kludge_level = p_vpar->synchro.kludge_nbb + p_vpar->synchro.kludge_nbp;
522 }
523
524 #endif
525
526
527 #ifdef POLUX_SYNCHRO
528
529 void vpar_SynchroSetCurrentDate( vpar_thread_t * p_vpar, int i_coding_type )
530 {
531     pes_packet_t * p_pes =
532         p_vpar->bit_stream.p_decoder_fifo->buffer[p_vpar->bit_stream.p_decoder_fifo->i_start];
533
534
535     switch( i_coding_type )
536     {
537     case B_CODING_TYPE:
538         if( p_pes->b_has_pts )
539         {
540             if( p_pes->i_pts < p_vpar->synchro.i_current_frame_date )
541             {
542                 intf_ErrMsg( "vpar warning: pts_date < current_date\n" );
543             }
544             p_vpar->synchro.i_current_frame_date = p_pes->i_pts;
545             p_pes->b_has_pts = 0;
546         }
547         else
548         {
549             p_vpar->synchro.i_current_frame_date += 1000000/(p_vpar->sequence.r_frame_rate);
550         }
551         break;
552
553     default:
554
555         if( p_vpar->synchro.i_backward_frame_date == 0 )
556         {
557             p_vpar->synchro.i_current_frame_date += 1000000/(p_vpar->sequence.r_frame_rate);
558         }
559         else
560         {
561             if( p_vpar->synchro.i_backward_frame_date < p_vpar->synchro.i_current_frame_date )
562             {
563                 intf_ErrMsg( "vpar warning: backward_date < current_date (%Ld)\n",
564                          p_vpar->synchro.i_backward_frame_date - p_vpar->synchro.i_current_frame_date );
565             }
566             p_vpar->synchro.i_current_frame_date = p_vpar->synchro.i_backward_frame_date;
567             p_vpar->synchro.i_backward_frame_date = 0;
568         }
569
570         if( p_pes->b_has_pts )
571         {
572             p_vpar->synchro.i_backward_frame_date = p_pes->i_pts;
573             p_pes->b_has_pts = 0;
574         }
575        break;
576     }
577 }
578
579 boolean_t vpar_SynchroChoose( vpar_thread_t * p_vpar, int i_coding_type,
580                               int i_structure )
581 {
582     boolean_t b_result = 1;
583     int i_synchro_level = p_vpar->p_vout->i_synchro_level;
584
585     vpar_SynchroSetCurrentDate( p_vpar, i_coding_type );
586
587     /*
588      * The synchro level is updated by the video input (see SynchroLevelUpdate)
589      * so we just use the synchro_level to decide which frame to trash
590      */
591
592     switch( i_coding_type )
593     {
594     case I_CODING_TYPE:
595
596         p_vpar->synchro.r_p_average =
597             (p_vpar->synchro.r_p_average*(SYNC_AVERAGE_COUNT-1)+p_vpar->synchro.i_p_count)/SYNC_AVERAGE_COUNT;
598         p_vpar->synchro.r_b_average =
599             (p_vpar->synchro.r_b_average*(SYNC_AVERAGE_COUNT-1)+p_vpar->synchro.i_b_count)/SYNC_AVERAGE_COUNT;
600
601         p_vpar->synchro.i_p_nb = (int)(p_vpar->synchro.r_p_average+0.5);
602         p_vpar->synchro.i_b_nb = (int)(p_vpar->synchro.r_b_average+0.5);
603
604         p_vpar->synchro.i_p_count = p_vpar->synchro.i_b_count = 0;
605         p_vpar->synchro.i_b_trasher = p_vpar->synchro.i_b_nb / 2;
606         p_vpar->synchro.i_i_count++;
607        break;
608
609     case P_CODING_TYPE:
610         p_vpar->synchro.i_p_count++;
611         if( p_vpar->synchro.i_p_count > i_synchro_level )
612         {
613             b_result = 0;
614         }
615         break;
616
617     case B_CODING_TYPE:
618         p_vpar->synchro.i_b_count++;
619         if( p_vpar->synchro.i_p_nb >= i_synchro_level )
620         {
621             /* We must trash all the B */
622             b_result = 0;
623         }
624         else
625         {
626             /* We use the brensenham algorithm to decide which B to trash */
627             p_vpar->synchro.i_b_trasher +=
628                 p_vpar->synchro.i_b_nb - (i_synchro_level-p_vpar->synchro.i_p_nb);
629             if( p_vpar->synchro.i_b_trasher >= p_vpar->synchro.i_b_nb )
630             {
631                 b_result = 0;
632                 p_vpar->synchro.i_b_trasher -= p_vpar->synchro.i_b_nb;
633             }
634         }
635         break;
636     }
637
638     return( b_result );
639 }
640
641 void vpar_SynchroTrash( vpar_thread_t * p_vpar, int i_coding_type,
642                         int i_structure )
643 {
644     vpar_SynchroChoose( p_vpar, i_coding_type, i_structure );
645 }
646
647 void vpar_SynchroUpdateLevel()
648 {
649     //vlc_mutex_lock( &level_lock );
650     //vlc_mutex_unlock( &level_lock );
651 }
652
653 mtime_t vpar_SynchroDate( vpar_thread_t * p_vpar )
654 {
655     return( p_vpar->synchro.i_current_frame_date );
656 }
657
658 /* functions with no use */
659
660 void vpar_SynchroEnd( vpar_thread_t * p_vpar )
661 {
662 }
663
664 void vpar_SynchroDecode( vpar_thread_t * p_vpar, int i_coding_type,
665                             int i_structure )
666 {
667 }
668
669 #endif