The input main loop will now handles space control at the right place.
* new_average = (old_average * c_average + new_sample_value) / (c_average +1)
*/
+enum /* Synchro states */
+{
+ SYNCHRO_OK = 0,
+ SYNCHRO_START = 1,
+ SYNCHRO_REINIT = 2,
+};
static void ClockNewRef( input_clock_t * p_pgrm,
mtime_t i_clock, mtime_t i_sysdate );
cl->last_cr = i_clock;
cl->last_sysdate = i_mdate;
- if( b_synchronize )
- {
- /* 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->p->b_out_pace_control )
- {
- mtime_t i_wakeup = ClockToSysdate( cl, i_clock );
- while( (i_wakeup - mdate()) / CLOCK_FREQ > 1 )
- {
- msleep( CLOCK_FREQ );
- if( p_input->b_die ) i_wakeup = mdate();
- }
- mwait( i_wakeup );
- }
- }
- else if ( i_mdate - cl->last_update > 200000 )
+ if( !b_synchronize && i_mdate - cl->last_update > 200000 )
{
/* Smooth clock reference variations. */
const mtime_t i_extrapoled_clock = ClockCurrent( cl );
cl->i_rate = i_rate;
}
+/*****************************************************************************
+ * input_ClockGetWakeup
+ *****************************************************************************/
+mtime_t input_ClockGetWakeup( input_thread_t *p_input, input_clock_t *cl )
+{
+ /* Not synchronized, we cannot wait */
+ if( cl->i_synchro_state != SYNCHRO_OK )
+ return 0;
+
+ /* We must not wait if not pace controled, or we are not the
+ * master clock */
+ if( !p_input->b_can_pace_control || !cl->b_master ||
+ p_input->p->b_out_pace_control )
+ return 0;
+
+ /* */
+ return ClockToSysdate( cl, cl->last_cr );
+}
+
return NULL;
}
+mtime_t input_EsOutGetWakeup( es_out_t *out )
+{
+ es_out_sys_t *p_sys = out->p_sys;
+
+ if( !p_sys->p_pgrm )
+ return 0;
+ return input_ClockGetWakeup( p_sys->p_input, &p_sys->p_pgrm->clock );
+}
+
static void EsOutDiscontinuity( es_out_t *out, bool b_flush, bool b_audio )
{
es_out_sys_t *p_sys = out->p_sys;
vlc_value_t val;
mtime_t i_current;
mtime_t i_deadline;
+ mtime_t i_wakeup;
/* Demux data */
b_force_update = false;
+ i_wakeup = 0;
if( p_input->i_state != PAUSE_S )
+ {
MainLoopDemux( p_input, &b_force_update, &i_start_mdate );
+ i_wakeup = input_EsOutGetWakeup( p_input->p->p_es_out );
+ }
/* */
- i_deadline = 0;
- if( p_input->i_state == PAUSE_S )
- i_deadline = __MIN( i_intf_update, i_statistic_update );
-
- /* Handle control */
- vlc_mutex_lock( &p_input->p->lock_control );
- ControlReduce( p_input );
- while( !ControlPopNoLock( p_input, &i_type, &val, i_deadline ) )
- {
- msg_Dbg( p_input, "control type=%d", i_type );
- if( Control( p_input, i_type, val ) )
- b_force_update = true;
- }
- vlc_mutex_unlock( &p_input->p->lock_control );
+ do {
+ i_deadline = i_wakeup;
+ if( p_input->i_state == PAUSE_S )
+ i_deadline = __MIN( i_intf_update, i_statistic_update );
+
+ /* Handle control */
+ vlc_mutex_lock( &p_input->p->lock_control );
+ ControlReduce( p_input );
+ while( !ControlPopNoLock( p_input, &i_type, &val, i_deadline ) )
+ {
+ msg_Dbg( p_input, "control type=%d", i_type );
+ if( Control( p_input, i_type, val ) )
+ b_force_update = true;
+ }
+ vlc_mutex_unlock( &p_input->p->lock_control );
- /* Update interface and statistics */
- i_current = mdate();
- if( i_intf_update < i_current || b_force_update )
- {
- MainLoopInterface( p_input );
- i_intf_update = i_current + INT64_C(250000);
- }
- if( i_statistic_update < i_current )
- {
- MainLoopStatistic( p_input );
- i_statistic_update = i_current + INT64_C(1000000);
- }
+ /* Update interface and statistics */
+ i_current = mdate();
+ if( i_intf_update < i_current || b_force_update )
+ {
+ MainLoopInterface( p_input );
+ i_intf_update = i_current + INT64_C(250000);
+ b_force_update = false;
+ }
+ if( i_statistic_update < i_current )
+ {
+ MainLoopStatistic( p_input );
+ i_statistic_update = i_current + INT64_C(1000000);
+ }
+ } while( i_current < i_wakeup );
}
if( !p_input->b_eof && !p_input->b_error && p_input->p->input.b_eof )
es_out_t *input_EsOutNew( input_thread_t *, int i_rate );
void input_EsOutDelete( es_out_t * );
es_out_id_t *input_EsOutGetFromID( es_out_t *, int i_id );
+mtime_t input_EsOutGetWakeup( es_out_t * );
void input_EsOutSetDelay( es_out_t *, int i_cat, int64_t );
-int input_EsOutSetRecord( es_out_t *, bool b_record );
+int input_EsOutSetRecord( es_out_t *, bool b_record );
void input_EsOutChangeRate( es_out_t *, int );
void input_EsOutChangeState( es_out_t * );
void input_EsOutChangePosition( es_out_t * );
bool input_EsOutDecodersEmpty( es_out_t * );
-/* clock.c */
-enum /* Synchro states */
-{
- SYNCHRO_OK = 0,
- SYNCHRO_START = 1,
- SYNCHRO_REINIT = 2,
-};
-
typedef struct
{
/* Synchronization information */
void input_ClockResetPCR( input_clock_t * );
mtime_t input_ClockGetTS( input_thread_t *, input_clock_t *, mtime_t );
void input_ClockSetRate( input_clock_t *cl, int i_rate );
+mtime_t input_ClockGetWakeup( input_thread_t *, input_clock_t *cl );
/* Subtitles */
char **subtitles_Detect( input_thread_t *, char* path, const char *fname );