float candidate_deviation;
float optimal_deviation;
float predict;
+ mtime_t i_current_pts;
+ decoder_fifo_t * decoder_fifo;
+ /* interpolate the current PTS */
+ decoder_fifo = p_vpar->bit_stream.p_decoder_fifo;
+ /* see if the current image has a pts - if not, interpolate */
+ if( i_current_pts = decoder_fifo->buffer[decoder_fifo->i_start]->i_pts )
+ {
+ p_vpar->synchro.i_images_since_pts = 1;
+ }
+ else
+ {
+ i_current_pts = p_vpar->synchro.i_last_pts
+ + (1000000 / p_vpar->synchro.theorical_fps);
+ p_vpar->synchro.i_images_since_pts++;
+ }
+ p_vpar->synchro.fifo[p_vpar->synchro.i_fifo_stop].i_pts = i_current_pts;
+ p_vpar->synchro.i_last_pts = i_current_pts;
+
+
+ /* update structures */
switch(i_coding_type)
{
case P_CODING_TYPE:
+
p_vpar->synchro.current_p_count++;
break;
+
case B_CODING_TYPE:
p_vpar->synchro.current_b_count++;
break;
+
case I_CODING_TYPE:
+ /* update information about images we can decode */
+ if ( p_vpar->synchro.i_last_i_pts )
+ {
+ p_vpar->synchro.theorical_fps = 1000000 * (1 + p_vpar->synchro.current_b_count + p_vpar->synchro.current_p_count) / (i_current_pts - p_vpar->synchro.i_last_i_pts);
+ }
+ p_vpar->synchro.i_last_i_pts = i_current_pts;
+
+
/* update all the structures for P images */
/* period == 1 */
p_vpar->synchro.b_count_predict = predict;
p_vpar->synchro.current_b_count = 0;
-
-
+
break;
}
p_vpar->synchro.modulo++;
+
}
/*****************************************************************************
boolean_t vpar_SynchroChoose( vpar_thread_t * p_vpar, int i_coding_type,
int i_structure )
{
- static int meuh = 1;
- static int truc = 0;
-// return( 1 );
- if( i_coding_type == 1 )
- meuh = 1;
- if( i_coding_type == 2 )
- meuh++;
- truc++;
- if( truc == 3 )
+
+ if( p_vpar->synchro.fifo[p_vpar->synchro.i_fifo_start].i_decode_date + ((p_vpar->synchro.i_fifo_stop - p_vpar->synchro.i_fifo_start) & 0xf) * p_vpar->synchro.i_mean_decode_time > mdate() )
{
- // while(1);
+ //fprintf( stderr, "chooser : we are à la bourre !\n");
+ return( i_coding_type == I_CODING_TYPE );
}
- return( i_coding_type == I_CODING_TYPE || (i_coding_type == P_CODING_TYPE) && (meuh == 2));
- intf_DbgMsg("vpar debug: synchro image %i - modulo is %i\n", i_coding_type, p_vpar->synchro.modulo);
- intf_DbgMsg("vpar debug: synchro predict P %e - predict B %e\n", p_vpar->synchro.p_count_predict, p_vpar->synchro.b_count_predict);
- return(0);
- return( i_coding_type == I_CODING_TYPE );
+ return( i_coding_type == I_CODING_TYPE || (i_coding_type == P_CODING_TYPE));
+
}
/*****************************************************************************
void vpar_SynchroTrash( vpar_thread_t * p_vpar, int i_coding_type,
int i_structure )
{
- //fprintf ( stderr, "trashing type %i\n", p_vpar->picture.i_coding_type );
-
vpar_SynchroUpdateStructures (p_vpar, i_coding_type);
}
void vpar_SynchroDecode( vpar_thread_t * p_vpar, int i_coding_type,
int i_structure )
{
- //fprintf ( stderr, "decoding type %i\n", p_vpar->picture.i_coding_type );
-
vpar_SynchroUpdateStructures (p_vpar, i_coding_type);
- p_vpar->synchro.fifo[p_vpar->synchro.i_fifo_stop].decode_date = mdate();
+ p_vpar->synchro.fifo[p_vpar->synchro.i_fifo_stop].i_decode_date = mdate();
p_vpar->synchro.fifo[p_vpar->synchro.i_fifo_stop].i_image_type
= i_coding_type;
p_vpar->synchro.i_fifo_stop = (p_vpar->synchro.i_fifo_stop + 1) & 0xf;
- fprintf ( stderr, "%i images in synchro fifo\n", ( p_vpar->synchro.i_fifo_stop - p_vpar->synchro.i_fifo_start ) & 0xf );
}
/*****************************************************************************
*****************************************************************************/
void vpar_SynchroEnd( vpar_thread_t * p_vpar )
{
- mtime_t * p_decode_time;
+ mtime_t i_decode_time;
- fprintf ( stderr, "type %i decoding time was %lli\n",
- p_vpar->synchro.fifo[p_vpar->synchro.i_fifo_start].i_image_type,
- ( mdate()
- - p_vpar->synchro.fifo[p_vpar->synchro.i_fifo_start].decode_date )
- / (( p_vpar->synchro.i_fifo_stop - p_vpar->synchro.i_fifo_start ) & 0xf ));
+ i_decode_time = (mdate() -
+ p_vpar->synchro.fifo[p_vpar->synchro.i_fifo_start].i_decode_date)
+ / (p_vpar->synchro.i_fifo_stop - p_vpar->synchro.i_fifo_start & 0x0f);
- p_vpar->synchro.decode_time =
- ( (p_vpar->synchro.decode_time * 3) + (mdate()
- - p_vpar->synchro.fifo[p_vpar->synchro.i_fifo_start].decode_date)
- / (( p_vpar->synchro.i_fifo_stop - p_vpar->synchro.i_fifo_start)
- & 0xf) ) >> 2;
+ p_vpar->synchro.i_mean_decode_time =
+ ( 3 * p_vpar->synchro.i_mean_decode_time + i_decode_time ) / 4;
p_vpar->synchro.i_fifo_start = (p_vpar->synchro.i_fifo_start + 1) & 0xf;
}
mtime_t vpar_SynchroDate( vpar_thread_t * p_vpar )
{
decoder_fifo_t * fifo;
- mtime_t displaydate;
-
- fifo = p_vpar->bit_stream.p_decoder_fifo;
- displaydate = fifo->buffer[fifo->i_start]->i_pts;
+ mtime_t i_displaydate;
+ mtime_t i_delay;
+
+ i_displaydate =
+ p_vpar->synchro.fifo[p_vpar->synchro.i_fifo_start].i_decode_date;
+ /* this value should be removed */
+ i_displaydate += 500000;
+ i_delay = i_displaydate - mdate();
+
+ //fprintf(stderr, "displaying type %i with delay %lli)\n", p_vpar->synchro.fifo[p_vpar->synchro.i_fifo_start].i_image_type, i_delay);
- if (displaydate) fprintf(stderr, "displaying type %i at %lli, (time %lli, delta %lli)\n", p_vpar->synchro.fifo[p_vpar->synchro.i_fifo_start].i_image_type, displaydate, mdate() + 1000000, displaydate - mdate() - 1000000);
- return displaydate;
+ return i_displaydate;
}