Commit ba8d1d4c authored by Sam Hocevar's avatar Sam Hocevar

. nouvelle synchro. �a devrait d�j� fonctionner correctement en monothread

parent 82c00619
...@@ -43,15 +43,12 @@ typedef struct video_synchro_s ...@@ -43,15 +43,12 @@ typedef struct video_synchro_s
/* mean decoding time */ /* mean decoding time */
mtime_t i_mean_decode_time; mtime_t i_mean_decode_time;
/* tells whether we accumulated delay */
mtime_t i_delay;
/* dates */ /* dates */
mtime_t i_last_display_pts; mtime_t i_last_display_pts; /* pts of the last displayed image */
mtime_t i_last_decode_pts; mtime_t i_last_decode_pts; /* pts of the last decoded image */
mtime_t i_last_i_pts; mtime_t i_last_i_pts; /* pts of the last I image */
mtime_t i_last_nondropped_i_pts; /* pts of last non-dropped I image */
unsigned int i_images_since_pts; unsigned int i_images_since_pts;
/* last pts of non-dropped I image */
mtime_t i_last_nondropped_i_pts;
/* il manquait un compteur */ /* il manquait un compteur */
unsigned int modulo; unsigned int modulo;
...@@ -65,6 +62,13 @@ typedef struct video_synchro_s ...@@ -65,6 +62,13 @@ typedef struct video_synchro_s
unsigned int nondropped_b_count; unsigned int nondropped_b_count;
double b_count_predict; double b_count_predict;
/* can we display pictures ? */
unsigned int can_display_i;
unsigned int can_display_p;
double displayable_p;
unsigned int can_display_b;
double displayable_b;
/* 1 for linear count, 2 for binary count, 3 for ternary count */ /* 1 for linear count, 2 for binary count, 3 for ternary count */
video_synchro_tab_t tab_p[6]; video_synchro_tab_t tab_p[6];
video_synchro_tab_t tab_b[6]; video_synchro_tab_t tab_b[6];
......
...@@ -242,6 +242,7 @@ static int InitThread( vpar_thread_t *p_vpar ) ...@@ -242,6 +242,7 @@ static int InitThread( vpar_thread_t *p_vpar )
vpar_InitCodedPattern( p_vpar ); vpar_InitCodedPattern( p_vpar );
vpar_InitDCTTables( p_vpar ); vpar_InitDCTTables( p_vpar );
/* /*
* Initialize the synchro properties * Initialize the synchro properties
*/ */
...@@ -260,8 +261,12 @@ static int InitThread( vpar_thread_t *p_vpar ) ...@@ -260,8 +261,12 @@ static int InitThread( vpar_thread_t *p_vpar )
p_vpar->synchro.modulo = 0; p_vpar->synchro.modulo = 0;
/* mean decoding time - at least 200 ms for a slow machine */ /* mean decoding time - at least 200 ms for a slow machine */
p_vpar->synchro.i_mean_decode_time = 200000; p_vpar->synchro.i_mean_decode_time = 200000;
/* suppose we have no delay */ /* assume we can display all Is and 2 Ps */
p_vpar->synchro.i_delay = 0; p_vpar->synchro.can_display_i = 1;
p_vpar->synchro.can_display_p = 0;
p_vpar->synchro.displayable_p = 2;
p_vpar->synchro.can_display_b = 0;
p_vpar->synchro.displayable_b = 0;
/* assume there were about 3 P and 6 B images between I's */ /* assume there were about 3 P and 6 B images between I's */
p_vpar->synchro.current_p_count = 1; p_vpar->synchro.current_p_count = 1;
p_vpar->synchro.nondropped_p_count = 1; p_vpar->synchro.nondropped_p_count = 1;
...@@ -273,7 +278,6 @@ static int InitThread( vpar_thread_t *p_vpar ) ...@@ -273,7 +278,6 @@ static int InitThread( vpar_thread_t *p_vpar )
{ {
p_vpar->synchro.tab_p[i_dummy].mean = 3; p_vpar->synchro.tab_p[i_dummy].mean = 3;
p_vpar->synchro.tab_p[i_dummy].deviation = .5; p_vpar->synchro.tab_p[i_dummy].deviation = .5;
p_vpar->synchro.tab_b[i_dummy].mean = 6; p_vpar->synchro.tab_b[i_dummy].mean = 6;
p_vpar->synchro.tab_b[i_dummy].deviation = .5; p_vpar->synchro.tab_b[i_dummy].deviation = .5;
} }
......
...@@ -66,6 +66,7 @@ void vpar_SynchroUpdateStructures( vpar_thread_t * p_vpar, ...@@ -66,6 +66,7 @@ void vpar_SynchroUpdateStructures( vpar_thread_t * p_vpar,
float optimal_deviation; float optimal_deviation;
float predict; float predict;
mtime_t i_current_pts; mtime_t i_current_pts;
mtime_t i_delay;
mtime_t i_displaydate; mtime_t i_displaydate;
decoder_fifo_t * decoder_fifo = p_vpar->bit_stream.p_decoder_fifo; decoder_fifo_t * decoder_fifo = p_vpar->bit_stream.p_decoder_fifo;
...@@ -93,10 +94,11 @@ void vpar_SynchroUpdateStructures( vpar_thread_t * p_vpar, ...@@ -93,10 +94,11 @@ void vpar_SynchroUpdateStructures( vpar_thread_t * p_vpar,
+ 1000000.0 / (p_vpar->synchro.theorical_fps); + 1000000.0 / (p_vpar->synchro.theorical_fps);
//fprintf (stderr, " "); //fprintf (stderr, " ");
} }
//else fprintf (stderr, "R ");
//if (dropped) fprintf (stderr, " "); else fprintf (stderr, "* "); /* else fprintf (stderr, "R ");
//fprintf (stderr, "%i ", i_coding_type); if (dropped) fprintf (stderr, " "); else fprintf (stderr, "* ");
//fprintf (stderr, "pts %lli delta %lli\n", i_displaydate, i_displaydate - p_vpar->synchro.i_last_display_pts); fprintf (stderr, "%i ", i_coding_type);
fprintf (stderr, "pts %lli delta %lli\n", i_displaydate, i_displaydate - p_vpar->synchro.i_last_display_pts); */
p_vpar->synchro.i_images_since_pts--; p_vpar->synchro.i_images_since_pts--;
p_vpar->synchro.i_last_display_pts = i_displaydate; p_vpar->synchro.i_last_display_pts = i_displaydate;
...@@ -136,9 +138,6 @@ void vpar_SynchroUpdateStructures( vpar_thread_t * p_vpar, ...@@ -136,9 +138,6 @@ void vpar_SynchroUpdateStructures( vpar_thread_t * p_vpar,
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; 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;
} }
p_vpar->synchro.i_last_nondropped_i_pts = i_current_pts;
p_vpar->synchro.nondropped_p_count = 0;
p_vpar->synchro.nondropped_b_count = 0;
} }
...@@ -205,7 +204,61 @@ void vpar_SynchroUpdateStructures( vpar_thread_t * p_vpar, ...@@ -205,7 +204,61 @@ void vpar_SynchroUpdateStructures( vpar_thread_t * p_vpar,
p_vpar->synchro.b_count_predict = predict; p_vpar->synchro.b_count_predict = predict;
p_vpar->synchro.current_b_count = 0; p_vpar->synchro.current_b_count = 0;
/* now we calculated all statistics, it's time to
* decide what we have the time to display
*/
i_delay = i_current_pts - p_vpar->synchro.i_last_nondropped_i_pts;
p_vpar->synchro.can_display_i
= ( p_vpar->synchro.i_mean_decode_time < i_delay );
p_vpar->synchro.can_display_p
= ( p_vpar->synchro.i_mean_decode_time
* (1 + p_vpar->synchro.p_count_predict) < i_delay );
if( !p_vpar->synchro.can_display_p )
{
p_vpar->synchro.displayable_p
= -1 + i_delay / p_vpar->synchro.i_mean_decode_time;
if( p_vpar->synchro.displayable_p < 0 )
p_vpar->synchro.displayable_p = 0;
}
else
p_vpar->synchro.displayable_p = 0;
if( p_vpar->synchro.can_display_p
&& !(p_vpar->synchro.can_display_b
= ( p_vpar->synchro.i_mean_decode_time
* (1 + p_vpar->synchro.b_count_predict
+ p_vpar->synchro.p_count_predict)) < i_delay) )
{
p_vpar->synchro.displayable_b
= -2.0 + i_delay / p_vpar->synchro.i_mean_decode_time
- p_vpar->synchro.can_display_p;
}
else
p_vpar->synchro.displayable_b = 0;
#if 0
fprintf( stderr,
"I %i P %i (%f) B %i (%f)\n",
p_vpar->synchro.can_display_i,
p_vpar->synchro.can_display_p,
p_vpar->synchro.displayable_p,
p_vpar->synchro.can_display_b,
p_vpar->synchro.displayable_b );
#endif
/* update some values */
if( !dropped )
{
p_vpar->synchro.i_last_nondropped_i_pts = i_current_pts;
p_vpar->synchro.nondropped_p_count = 0;
p_vpar->synchro.nondropped_b_count = 0;
}
break; break;
} }
p_vpar->synchro.modulo++; p_vpar->synchro.modulo++;
...@@ -218,41 +271,50 @@ void vpar_SynchroUpdateStructures( vpar_thread_t * p_vpar, ...@@ -218,41 +271,50 @@ void vpar_SynchroUpdateStructures( vpar_thread_t * p_vpar,
boolean_t vpar_SynchroChoose( vpar_thread_t * p_vpar, int i_coding_type, boolean_t vpar_SynchroChoose( vpar_thread_t * p_vpar, int i_coding_type,
int i_structure ) int i_structure )
{ {
mtime_t i_delay; mtime_t i_delay = p_vpar->synchro.i_last_decode_pts - mdate();
int keep;
switch( i_coding_type )
{
case I_CODING_TYPE:
i_delay = p_vpar->synchro.i_last_decode_pts - mdate(); return( p_vpar->synchro.can_display_i );
//fprintf( stderr, "delay is %lli - ", i_delay); case P_CODING_TYPE:
#if 1 if( p_vpar->synchro.can_display_p )
/*if ( i_coding_type == B_CODING_TYPE ) return( 1 );
return (0);*/
//return( i_coding_type == I_CODING_TYPE || i_coding_type == P_CODING_TYPE ); if( p_vpar->synchro.displayable_p * i_delay
if( i_delay > 120000 ) < p_vpar->synchro.i_mean_decode_time )
{
keep = 1;
}
else if( i_delay > 100000 )
{ {
keep = ( i_coding_type == I_CODING_TYPE //fprintf( stderr, "trashed a P\n");
|| i_coding_type == P_CODING_TYPE ); return( 0 );
} }
else if( i_delay > 50000 )
{ p_vpar->synchro.displayable_p--;
keep = ( i_coding_type == I_CODING_TYPE ); return( 1 );
}
else case B_CODING_TYPE:
if( p_vpar->synchro.can_display_b )
return( 1 );
/* modulo & 0x3 is here to add some randomness */
if( i_delay < (1 + (p_vpar->synchro.modulo & 0x3))
* p_vpar->synchro.i_mean_decode_time )
{ {
keep = 0; //fprintf( stderr, "trashed a B\n");
return( 0 );
} }
#endif
//if (!keep) fprintf( stderr, "trashing a type %i with delay %lli\n", i_coding_type, i_delay); if( p_vpar->synchro.displayable_b <= 0 )
// else fprintf( stderr, "chooser : ok - displaying a %i \n", i_coding_type); return( 0 );
return (keep); p_vpar->synchro.displayable_b--;
return( 1 );
}
return( 0 );
} }
...@@ -296,7 +358,9 @@ void vpar_SynchroEnd( vpar_thread_t * p_vpar ) ...@@ -296,7 +358,9 @@ void vpar_SynchroEnd( vpar_thread_t * p_vpar )
p_vpar->synchro.i_mean_decode_time = p_vpar->synchro.i_mean_decode_time =
( 7 * p_vpar->synchro.i_mean_decode_time + i_decode_time ) / 8; ( 7 * p_vpar->synchro.i_mean_decode_time + i_decode_time ) / 8;
//fprintf (stderr, "decoding time is %lli\n", p_vpar->synchro.i_mean_decode_time); /* fprintf (stderr,
"decoding time was %lli\n",
p_vpar->synchro.i_mean_decode_time); */
p_vpar->synchro.i_fifo_start = (p_vpar->synchro.i_fifo_start + 1) & 0xf; p_vpar->synchro.i_fifo_start = (p_vpar->synchro.i_fifo_start + 1) & 0xf;
...@@ -308,12 +372,23 @@ void vpar_SynchroEnd( vpar_thread_t * p_vpar ) ...@@ -308,12 +372,23 @@ void vpar_SynchroEnd( vpar_thread_t * p_vpar )
mtime_t vpar_SynchroDate( vpar_thread_t * p_vpar ) mtime_t vpar_SynchroDate( vpar_thread_t * p_vpar )
{ {
mtime_t i_displaydate = p_vpar->synchro.i_last_display_pts; mtime_t i_displaydate = p_vpar->synchro.i_last_display_pts;
#if 0
static mtime_t i_delta = 0; static mtime_t i_delta = 0;
//fprintf(stderr, "displaying type %i with delay %lli and delta %lli\n", p_vpar->synchro.fifo[p_vpar->synchro.i_fifo_start].i_image_type, i_displaydate - mdate(), i_displaydate - i_delta); fprintf( stderr,
//fprintf (stderr, "theorical fps: %f - actual fps: %f \n", p_vpar->synchro.theorical_fps, p_vpar->synchro.actual_fps); "displaying type %i with delay %lli and delta %lli\n",
p_vpar->synchro.fifo[p_vpar->synchro.i_fifo_start].i_image_type,
i_displaydate - mdate(),
i_displaydate - i_delta );
fprintf (stderr,
"theorical fps: %f - actual fps: %f \n",
p_vpar->synchro.theorical_fps, p_vpar->synchro.actual_fps );
i_delta = i_displaydate; i_delta = i_displaydate;
#endif
return i_displaydate; return i_displaydate;
} }
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment