clock: Fixed rounding error in clock smoothing algorithm.

Also removed a long unused member from the clock struct.
parent 01c9ca88
...@@ -136,7 +136,7 @@ void input_ClockInit( input_clock_t *cl, vlc_bool_t b_master, int i_cr_average ) ...@@ -136,7 +136,7 @@ void input_ClockInit( input_clock_t *cl, vlc_bool_t b_master, int i_cr_average )
cl->cr_ref = 0; cl->cr_ref = 0;
cl->sysdate_ref = 0; cl->sysdate_ref = 0;
cl->delta_cr = 0; cl->delta_cr = 0;
cl->c_average_count = 0; cl->i_delta_cr_residue = 0;
cl->i_cr_average = i_cr_average; cl->i_cr_average = i_cr_average;
...@@ -265,7 +265,7 @@ void input_ClockSetPCR( input_thread_t *p_input, ...@@ -265,7 +265,7 @@ void input_ClockSetPCR( input_thread_t *p_input,
{ {
cl->last_cr = 0; cl->last_cr = 0;
cl->delta_cr = 0; cl->delta_cr = 0;
cl->c_average_count = 0; cl->i_delta_cr_residue = 0;
} }
} }
else else
...@@ -312,11 +312,18 @@ void input_ClockSetPCR( input_thread_t *p_input, ...@@ -312,11 +312,18 @@ void input_ClockSetPCR( input_thread_t *p_input,
{ {
/* Smooth clock reference variations. */ /* Smooth clock reference variations. */
mtime_t i_extrapoled_clock = ClockCurrent( p_input, cl ); mtime_t i_extrapoled_clock = ClockCurrent( p_input, cl );
mtime_t delta_cr;
/* Bresenham algorithm to smooth variations. */ /* Bresenham algorithm to smooth variations. */
cl->delta_cr = ( cl->delta_cr * (cl->i_cr_average - 1) delta_cr = ( cl->delta_cr * (cl->i_cr_average - 1)
+ ( i_extrapoled_clock - i_clock ) ) + ( i_extrapoled_clock - i_clock )
+ cl->i_delta_cr_residue )
/ cl->i_cr_average; / cl->i_cr_average;
cl->i_delta_cr_residue = ( cl->delta_cr * (cl->i_cr_average - 1)
+ ( i_extrapoled_clock - i_clock )
+ cl->i_delta_cr_residue )
% cl->i_cr_average;
cl->delta_cr = delta_cr;
} }
} }
} }
......
...@@ -136,14 +136,13 @@ typedef struct ...@@ -136,14 +136,13 @@ typedef struct
mtime_t last_cr; /* reference to detect unexpected stream mtime_t last_cr; /* reference to detect unexpected stream
* discontinuities */ * discontinuities */
mtime_t last_pts; mtime_t last_pts;
count_t c_average_count;
/* counter used to compute dynamic average values */
int i_synchro_state; int i_synchro_state;
vlc_bool_t b_master; vlc_bool_t b_master;
/* Config */ /* Config */
int i_cr_average; int i_cr_average;
int i_delta_cr_residue;
} input_clock_t; } input_clock_t;
void input_ClockInit( input_clock_t *, vlc_bool_t b_master, int i_cr_average ); void input_ClockInit( input_clock_t *, vlc_bool_t b_master, int i_cr_average );
......
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