*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111, USA.
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
*****************************************************************************/
/*****************************************************************************
#include <stdlib.h>
#include <vlc/vlc.h>
-#include <vlc/input.h>
#include "input_internal.h"
/*
* in all the FIFOs, but it may be not enough.
*/
-/* p_input->i_cr_average : Maximum number of samples used to compute the
+/* p_input->p->i_cr_average : Maximum number of samples used to compute the
* dynamic average value.
* We use the following formula :
* new_average = (old_average * c_average + new_sample_value) / (c_average +1)
if( cl->i_synchro_state == SYNCHRO_OK )
{
i_sysdate = (mtime_t)(i_clock - cl->cr_ref)
- * (mtime_t)p_input->i_rate
+ * (mtime_t)p_input->p->i_rate
* (mtime_t)300;
i_sysdate /= 27;
- i_sysdate /= 1000;
+ i_sysdate /= INPUT_RATE_DEFAULT;
i_sysdate += (mtime_t)cl->sysdate_ref;
}
input_clock_t *cl )
{
return( (mdate() - cl->sysdate_ref) * 27 * INPUT_RATE_DEFAULT
- / p_input->i_rate / 300
+ / p_input->p->i_rate / 300
+ cl->cr_ref );
}
cl->last_cr = 0;
cl->last_pts = 0;
+ cl->last_sysdate = 0;
cl->cr_ref = 0;
cl->sysdate_ref = 0;
cl->delta_cr = 0;
- cl->c_average_count = 0;
+ cl->i_delta_cr_residue = 0;
cl->i_cr_average = i_cr_average;
cl->b_master = b_master;
}
-#if 0
-/*****************************************************************************
- * input_ClockManageControl: handles the messages from the interface
- *****************************************************************************
- * Returns UNDEF_S if nothing happened, PAUSE_S if the stream was paused
- *****************************************************************************/
-int input_ClockManageControl( input_thread_t * p_input,
- input_clock_t *cl, mtime_t i_clock )
-{
-#if 0
- vlc_value_t val;
- int i_return_value = UNDEF_S;
-
- vlc_mutex_lock( &p_input->stream.stream_lock );
-
- if( p_input->stream.i_new_status == PAUSE_S )
- {
- int i_old_status;
-
- vlc_mutex_lock( &p_input->stream.control.control_lock );
- i_old_status = p_input->stream.control.i_status;
- p_input->stream.control.i_status = PAUSE_S;
- vlc_mutex_unlock( &p_input->stream.control.control_lock );
-
- vlc_cond_wait( &p_input->stream.stream_wait,
- &p_input->stream.stream_lock );
- ClockNewRef( p_pgrm, i_clock, p_pgrm->last_pts > mdate() ?
- p_pgrm->last_pts : mdate() );
-
- if( p_input->stream.i_new_status == PAUSE_S )
- {
- /* PAUSE_S undoes the pause state: Return to old state. */
- vlc_mutex_lock( &p_input->stream.control.control_lock );
- p_input->stream.control.i_status = i_old_status;
- vlc_mutex_unlock( &p_input->stream.control.control_lock );
-
- p_input->stream.i_new_status = UNDEF_S;
- p_input->stream.i_new_rate = UNDEF_S;
- }
-
- /* We handle i_new_status != PAUSE_S below... */
-
- i_return_value = PAUSE_S;
- }
-
- if( p_input->stream.i_new_status != UNDEF_S )
- {
- vlc_mutex_lock( &p_input->stream.control.control_lock );
-
- p_input->stream.control.i_status = p_input->stream.i_new_status;
-
- ClockNewRef( p_pgrm, i_clock,
- ClockToSysdate( p_input, p_pgrm, i_clock ) );
-
- if( p_input->stream.control.i_status == PLAYING_S )
- {
- p_input->stream.control.i_rate = DEFAULT_RATE;
- p_input->stream.control.b_mute = 0;
- }
- else
- {
- p_input->stream.control.i_rate = p_input->stream.i_new_rate;
- p_input->stream.control.b_mute = 1;
-
- /* Feed the audio decoders with a NULL packet to avoid
- * discontinuities. */
- input_EscapeAudioDiscontinuity( p_input );
- }
-
- val.i_int = p_input->stream.control.i_rate;
- var_Change( p_input, "rate", VLC_VAR_SETVALUE, &val, NULL );
-
- val.i_int = p_input->stream.control.i_status;
- var_Change( p_input, "state", VLC_VAR_SETVALUE, &val, NULL );
-
- p_input->stream.i_new_status = UNDEF_S;
- p_input->stream.i_new_rate = UNDEF_S;
-
- vlc_mutex_unlock( &p_input->stream.control.control_lock );
- }
-
- vlc_mutex_unlock( &p_input->stream.stream_lock );
-
- return( i_return_value );
-#endif
- return UNDEF_S;
-}
-#endif
-
/*****************************************************************************
* input_ClockSetPCR: manages a clock reference
*****************************************************************************/
if( p_input->b_can_pace_control && cl->b_master )
{
cl->last_cr = i_clock;
- if( !p_input->b_out_pace_control )
+ if( !p_input->p->b_out_pace_control )
{
mtime_t i_wakeup = ClockToSysdate( p_input, cl, i_clock );
while( (i_wakeup - mdate()) / CLOCK_FREQ > 1 )
else
{
cl->last_cr = 0;
+ cl->last_sysdate = 0;
cl->delta_cr = 0;
- cl->c_average_count = 0;
+ cl->i_delta_cr_residue = 0;
}
}
else
* stream ?). */
msg_Warn( p_input, "clock gap, unexpected stream discontinuity" );
input_ClockInit( cl, cl->b_master, cl->i_cr_average );
- /* FIXME needed ? */
-#if 0
- input_EscapeDiscontinuity( p_input );
-#endif
}
cl->last_cr = i_clock;
/* Wait a while before delivering the packets to the decoder.
* In case of multiple programs, we arbitrarily follow the
* clock of the selected program. */
- if( !p_input->b_out_pace_control )
+ if( !p_input->p->b_out_pace_control )
{
mtime_t i_wakeup = ClockToSysdate( p_input, cl, i_clock );
while( (i_wakeup - mdate()) / CLOCK_FREQ > 1 )
}
mwait( i_wakeup );
}
- /* FIXME Not needed anymore ? */
-#if 0
- /* Now take into account interface changes. */
- input_ClockManageControl( p_input, cl, i_clock );
-#endif
}
- else
+ else if ( mdate() - cl->last_sysdate > 200000 )
{
/* Smooth clock reference variations. */
mtime_t i_extrapoled_clock = ClockCurrent( p_input, cl );
+ mtime_t delta_cr;
/* Bresenham algorithm to smooth variations. */
- cl->delta_cr = ( cl->delta_cr * (cl->i_cr_average - 1)
- + ( i_extrapoled_clock - i_clock ) )
+ delta_cr = ( cl->delta_cr * (cl->i_cr_average - 1)
+ + ( i_extrapoled_clock - i_clock )
+ + cl->i_delta_cr_residue )
/ 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;
+ cl->last_sysdate = mdate();
}
}
}