+ i_delta = i_displaydate;
+
+ return i_displaydate;
+#else
+
+ return p_vpar->synchro.i_last_pts;
+
+#endif
+}
+
+#endif
+
+#ifdef MEUUH_SYNCHRO
+
+/* synchro a deux balles backportee du decodeur de reference. NE MARCHE PAS
+AVEC LES IMAGES MONOTRAMES */
+
+boolean_t vpar_SynchroChoose( vpar_thread_t * p_vpar, int i_coding_type,
+ int i_structure )
+{
+ switch (i_coding_type)
+ {
+ case B_CODING_TYPE:
+ if ((p_vpar->synchro.kludge_level <= p_vpar->synchro.kludge_nbp))
+ {
+ p_vpar->synchro.kludge_b++;
+ return( 0 );
+ }
+ if (p_vpar->synchro.kludge_b %
+ (p_vpar->synchro.kludge_nbb /
+ (p_vpar->synchro.kludge_level - p_vpar->synchro.kludge_nbp)))
+ {
+ p_vpar->synchro.kludge_b++;
+ return( 0 );
+ }
+ p_vpar->synchro.kludge_b++;
+ return( 1 );
+
+ case P_CODING_TYPE:
+ if (p_vpar->synchro.kludge_p++ >= p_vpar->synchro.kludge_level)
+ {
+ return( 0 );
+ }
+ return( 1 );
+
+ default:
+ return( 1 );
+ }
+}
+
+void vpar_SynchroTrash( vpar_thread_t * p_vpar, int i_coding_type,
+ int i_structure )
+{
+ if (DECODER_FIFO_START(p_vpar->fifo)->b_has_pts && i_coding_type == I_CODING_TYPE)
+ {
+ p_vpar->synchro.kludge_nbframes = 0;
+ p_vpar->synchro.kludge_date = DECODER_FIFO_START(p_vpar->fifo)->i_pts;
+ }
+ else
+ p_vpar->synchro.kludge_nbframes++;
+ DECODER_FIFO_START(p_vpar->fifo)->b_has_pts = 0;
+}
+
+void vpar_SynchroDecode( vpar_thread_t * p_vpar, int i_coding_type,
+ int i_structure )
+{
+ if (DECODER_FIFO_START(p_vpar->fifo)->b_has_pts && i_coding_type == I_CODING_TYPE)
+ {
+ p_vpar->synchro.kludge_nbframes = 0;
+ p_vpar->synchro.kludge_date = DECODER_FIFO_START(p_vpar->fifo)->i_pts;
+ DECODER_FIFO_START(p_vpar->fifo)->b_has_pts = 0;
+ }
+ else
+ p_vpar->synchro.kludge_nbframes++;
+}
+
+mtime_t vpar_SynchroDate( vpar_thread_t * p_vpar )
+{
+ return( p_vpar->synchro.kludge_date
+ + p_vpar->synchro.kludge_nbframes*1000000/(p_vpar->sequence.r_frame_rate ) );
+}
+
+void vpar_SynchroEnd( vpar_thread_t * p_vpar )
+{
+}
+
+void vpar_SynchroKludge( vpar_thread_t * p_vpar, mtime_t date )
+{
+ mtime_t show_date;
+ int temp = p_vpar->synchro.kludge_level;
+
+ p_vpar->synchro.kludge_nbp = p_vpar->synchro.kludge_p ? p_vpar->synchro.kludge_p : 5;
+ p_vpar->synchro.kludge_nbb = p_vpar->synchro.kludge_b ? p_vpar->synchro.kludge_b : 6;
+ show_date = date - mdate();
+ p_vpar->synchro.kludge_p = 0;
+ p_vpar->synchro.kludge_b = 0;
+
+ if (show_date < (SYNC_DELAY - SYNC_TOLERATE) && show_date <= p_vpar->synchro.kludge_prevdate)
+ {
+ p_vpar->synchro.kludge_level--;
+ if (p_vpar->synchro.kludge_level < 0)
+ p_vpar->synchro.kludge_level = 0;
+ else if (p_vpar->synchro.kludge_level >
+ p_vpar->synchro.kludge_nbp + p_vpar->synchro.kludge_nbb)
+ p_vpar->synchro.kludge_level = p_vpar->synchro.kludge_nbp + p_vpar->synchro.kludge_nbb;
+#ifdef DEBUG
+ if (temp != p_vpar->synchro.kludge_level)
+ intf_DbgMsg("vdec debug: Level changed from %d to %d (%Ld)\n",
+ temp, p_vpar->synchro.kludge_level, show_date );
+#endif
+ }
+ else if (show_date > (SYNC_DELAY + SYNC_TOLERATE) && show_date >= p_vpar->synchro.kludge_prevdate)
+ {
+ p_vpar->synchro.kludge_level++;
+ if (p_vpar->synchro.kludge_level > p_vpar->synchro.kludge_nbp + p_vpar->synchro.kludge_nbb)
+ p_vpar->synchro.kludge_level = p_vpar->synchro.kludge_nbp + p_vpar->synchro.kludge_nbb;
+#ifdef DEBUG
+ if (temp != p_vpar->synchro.kludge_level)
+ intf_DbgMsg("vdec debug: Level changed from %d to %d (%Ld)\n",
+ temp, p_vpar->synchro.kludge_level, show_date );
+#endif
+ }
+
+ p_vpar->synchro.kludge_prevdate = show_date;
+ if ((p_vpar->synchro.kludge_level - p_vpar->synchro.kludge_nbp) > p_vpar->synchro.kludge_nbb)
+ p_vpar->synchro.kludge_level = p_vpar->synchro.kludge_nbb + p_vpar->synchro.kludge_nbp;
+}
+
+#endif
+
+
+#ifdef POLUX_SYNCHRO
+
+void vpar_SynchroSetCurrentDate( vpar_thread_t * p_vpar, int i_coding_type )
+{
+ pes_packet_t * p_pes =
+ p_vpar->bit_stream.p_decoder_fifo->buffer[p_vpar->bit_stream.p_decoder_fifo->i_start];
+
+
+ switch( i_coding_type )
+ {
+ case B_CODING_TYPE:
+ if( p_pes->b_has_pts )
+ {
+ if( p_pes->i_pts < p_vpar->synchro.i_current_frame_date )
+ {
+ intf_ErrMsg( "vpar warning: pts_date < current_date\n" );
+ }
+ p_vpar->synchro.i_current_frame_date = p_pes->i_pts;
+ p_pes->b_has_pts = 0;
+ }
+ else
+ {
+ p_vpar->synchro.i_current_frame_date += 1000000/(p_vpar->sequence.r_frame_rate);
+ }
+ break;
+
+ default:
+
+ if( p_vpar->synchro.i_backward_frame_date == 0 )
+ {
+ p_vpar->synchro.i_current_frame_date += 1000000/(p_vpar->sequence.r_frame_rate);
+ }
+ else
+ {
+ if( p_vpar->synchro.i_backward_frame_date < p_vpar->synchro.i_current_frame_date )
+ {
+ intf_ErrMsg( "vpar warning: backward_date < current_date (%Ld)\n",
+ p_vpar->synchro.i_backward_frame_date - p_vpar->synchro.i_current_frame_date );
+ }
+ p_vpar->synchro.i_current_frame_date = p_vpar->synchro.i_backward_frame_date;
+ p_vpar->synchro.i_backward_frame_date = 0;
+ }
+
+ if( p_pes->b_has_pts )
+ {
+ p_vpar->synchro.i_backward_frame_date = p_pes->i_pts;
+ p_pes->b_has_pts = 0;
+ }
+ break;
+ }
+}
+
+boolean_t vpar_SynchroChoose( vpar_thread_t * p_vpar, int i_coding_type,
+ int i_structure )
+{
+ boolean_t b_result = 1;
+ int i_synchro_level = p_vpar->p_vout->i_synchro_level;
+
+ vpar_SynchroSetCurrentDate( p_vpar, i_coding_type );
+
+ /*
+ * The synchro level is updated by the video input (see SynchroLevelUpdate)
+ * so we just use the synchro_level to decide which frame to trash
+ */
+
+ switch( i_coding_type )
+ {
+ case I_CODING_TYPE:
+
+ p_vpar->synchro.r_p_average =
+ (p_vpar->synchro.r_p_average*(SYNC_AVERAGE_COUNT-1)+p_vpar->synchro.i_p_count)/SYNC_AVERAGE_COUNT;
+ p_vpar->synchro.r_b_average =
+ (p_vpar->synchro.r_b_average*(SYNC_AVERAGE_COUNT-1)+p_vpar->synchro.i_b_count)/SYNC_AVERAGE_COUNT;
+
+ p_vpar->synchro.i_p_nb = (int)(p_vpar->synchro.r_p_average+0.5);
+ p_vpar->synchro.i_b_nb = (int)(p_vpar->synchro.r_b_average+0.5);
+
+ p_vpar->synchro.i_p_count = p_vpar->synchro.i_b_count = 0;
+ p_vpar->synchro.i_b_trasher = p_vpar->synchro.i_b_nb / 2;
+ p_vpar->synchro.i_i_count++;
+ break;
+
+ case P_CODING_TYPE:
+ p_vpar->synchro.i_p_count++;
+ if( p_vpar->synchro.i_p_count > i_synchro_level )
+ {
+ b_result = 0;
+ }
+ break;
+
+ case B_CODING_TYPE:
+ p_vpar->synchro.i_b_count++;
+ if( p_vpar->synchro.i_p_nb >= i_synchro_level )
+ {
+ /* We must trash all the B */
+ b_result = 0;
+ }
+ else
+ {
+ /* We use the brensenham algorithm to decide which B to trash */
+ p_vpar->synchro.i_b_trasher +=
+ p_vpar->synchro.i_b_nb - (i_synchro_level-p_vpar->synchro.i_p_nb);
+ if( p_vpar->synchro.i_b_trasher >= p_vpar->synchro.i_b_nb )
+ {
+ b_result = 0;
+ p_vpar->synchro.i_b_trasher -= p_vpar->synchro.i_b_nb;
+ }
+ }
+ break;
+ }
+
+ return( b_result );
+}
+
+void vpar_SynchroTrash( vpar_thread_t * p_vpar, int i_coding_type,
+ int i_structure )
+{
+ vpar_SynchroChoose( p_vpar, i_coding_type, i_structure );
+}
+
+void vpar_SynchroUpdateLevel()
+{
+ //vlc_mutex_lock( &level_lock );
+ //vlc_mutex_unlock( &level_lock );
+}
+
+mtime_t vpar_SynchroDate( vpar_thread_t * p_vpar )
+{
+ return( p_vpar->synchro.i_current_frame_date );
+}
+
+/* functions with no use */
+
+void vpar_SynchroEnd( vpar_thread_t * p_vpar )
+{
+}
+
+void vpar_SynchroDecode( vpar_thread_t * p_vpar, int i_coding_type,
+ int i_structure )
+{
+}