Commit 03b02bd6 authored by Laurent Aimar's avatar Laurent Aimar

Privatized input_clock_t to clock.c

parent 476ce3ee
...@@ -77,6 +77,30 @@ ...@@ -77,6 +77,30 @@
* my dice --Meuuh */ * my dice --Meuuh */
#define CR_MEAN_PTS_GAP 300000 #define CR_MEAN_PTS_GAP 300000
/*****************************************************************************
* Structures
*****************************************************************************/
struct input_clock_t
{
/* Synchronization information */
mtime_t delta_cr;
mtime_t cr_ref, sysdate_ref;
mtime_t last_sysdate;
mtime_t last_cr; /* reference to detect unexpected stream
* discontinuities */
mtime_t last_pts;
mtime_t last_update;
bool b_has_reference;
bool b_master;
int i_rate;
/* Config */
int i_cr_average;
int i_delta_cr_residue;
};
/***************************************************************************** /*****************************************************************************
* ClockToSysdate: converts a movie clock to system date * ClockToSysdate: converts a movie clock to system date
*****************************************************************************/ *****************************************************************************/
...@@ -113,11 +137,14 @@ static void ClockNewRef( input_clock_t *cl, ...@@ -113,11 +137,14 @@ static void ClockNewRef( input_clock_t *cl,
} }
/***************************************************************************** /*****************************************************************************
* input_ClockInit: reinitializes the clock reference after a stream * input_ClockNew: create a new clock
* discontinuity
*****************************************************************************/ *****************************************************************************/
void input_ClockInit( input_clock_t *cl, bool b_master, int i_cr_average, int i_rate ) input_clock_t *input_ClockNew( bool b_master, int i_cr_average, int i_rate )
{ {
input_clock_t *cl = malloc( sizeof(*cl) );
if( !cl )
return NULL;
cl->b_has_reference = false; cl->b_has_reference = false;
cl->last_cr = 0; cl->last_cr = 0;
...@@ -132,6 +159,16 @@ void input_ClockInit( input_clock_t *cl, bool b_master, int i_cr_average, int i_ ...@@ -132,6 +159,16 @@ void input_ClockInit( input_clock_t *cl, bool b_master, int i_cr_average, int i_
cl->i_cr_average = i_cr_average; cl->i_cr_average = i_cr_average;
cl->b_master = b_master; cl->b_master = b_master;
return cl;
}
/*****************************************************************************
* input_ClockDelete: destroy a new clock
*****************************************************************************/
void input_ClockDelete( input_clock_t *cl )
{
free( cl );
} }
/***************************************************************************** /*****************************************************************************
...@@ -232,6 +269,14 @@ void input_ClockSetRate( input_clock_t *cl, int i_rate ) ...@@ -232,6 +269,14 @@ void input_ClockSetRate( input_clock_t *cl, int i_rate )
cl->i_rate = i_rate; cl->i_rate = i_rate;
} }
/*****************************************************************************
* input_ClockSetMaster:
*****************************************************************************/
void input_ClockSetMaster( input_clock_t *cl, bool b_master )
{
cl->b_master = b_master;
}
/***************************************************************************** /*****************************************************************************
* input_ClockGetWakeup * input_ClockGetWakeup
*****************************************************************************/ *****************************************************************************/
......
...@@ -60,7 +60,7 @@ typedef struct ...@@ -60,7 +60,7 @@ typedef struct
bool b_selected; bool b_selected;
/* Clock for this program */ /* Clock for this program */
input_clock_t clock; input_clock_t *p_clock;
char *psz_name; char *psz_name;
char *psz_now_playing; char *psz_now_playing;
...@@ -317,6 +317,7 @@ void input_EsOutDelete( es_out_t *out ) ...@@ -317,6 +317,7 @@ void input_EsOutDelete( es_out_t *out )
for( i = 0; i < p_sys->i_pgrm; i++ ) for( i = 0; i < p_sys->i_pgrm; i++ )
{ {
es_out_pgrm_t *p_pgrm = p_sys->pgrm[i]; es_out_pgrm_t *p_pgrm = p_sys->pgrm[i];
input_ClockDelete( p_pgrm->p_clock );
free( p_pgrm->psz_now_playing ); free( p_pgrm->psz_now_playing );
free( p_pgrm->psz_publisher ); free( p_pgrm->psz_publisher );
free( p_pgrm->psz_name ); free( p_pgrm->psz_name );
...@@ -354,7 +355,7 @@ mtime_t input_EsOutGetWakeup( es_out_t *out ) ...@@ -354,7 +355,7 @@ mtime_t input_EsOutGetWakeup( es_out_t *out )
if( !p_sys->p_pgrm ) if( !p_sys->p_pgrm )
return 0; return 0;
return input_ClockGetWakeup( p_sys->p_input, &p_sys->p_pgrm->clock ); return input_ClockGetWakeup( p_sys->p_input, p_sys->p_pgrm->p_clock );
} }
static void EsOutDiscontinuity( es_out_t *out, bool b_flush, bool b_audio ) static void EsOutDiscontinuity( es_out_t *out, bool b_flush, bool b_audio )
...@@ -385,7 +386,7 @@ void input_EsOutChangeRate( es_out_t *out, int i_rate ) ...@@ -385,7 +386,7 @@ void input_EsOutChangeRate( es_out_t *out, int i_rate )
EsOutDiscontinuity( out, false, false ); EsOutDiscontinuity( out, false, false );
for( i = 0; i < p_sys->i_pgrm; i++ ) for( i = 0; i < p_sys->i_pgrm; i++ )
input_ClockSetRate( &p_sys->pgrm[i]->clock, i_rate ); input_ClockSetRate( p_sys->pgrm[i]->p_clock, i_rate );
} }
int input_EsOutSetRecord( es_out_t *out, bool b_record ) int input_EsOutSetRecord( es_out_t *out, bool b_record )
...@@ -638,11 +639,9 @@ static void EsOutProgramSelect( es_out_t *out, es_out_pgrm_t *p_pgrm ) ...@@ -638,11 +639,9 @@ static void EsOutProgramSelect( es_out_t *out, es_out_pgrm_t *p_pgrm )
p_pgrm->b_selected = true; p_pgrm->b_selected = true;
/* Switch master stream */ /* Switch master stream */
if( p_sys->p_pgrm && p_sys->p_pgrm->clock.b_master ) if( p_sys->p_pgrm )
{ input_ClockSetMaster( p_sys->p_pgrm->p_clock, false );
p_sys->p_pgrm->clock.b_master = false; input_ClockSetMaster( p_pgrm->p_clock, true );
}
p_pgrm->clock.b_master = true;
p_sys->p_pgrm = p_pgrm; p_sys->p_pgrm = p_pgrm;
/* Update "program" */ /* Update "program" */
...@@ -680,7 +679,8 @@ static es_out_pgrm_t *EsOutProgramAdd( es_out_t *out, int i_group ) ...@@ -680,7 +679,8 @@ static es_out_pgrm_t *EsOutProgramAdd( es_out_t *out, int i_group )
vlc_value_t val; vlc_value_t val;
es_out_pgrm_t *p_pgrm = malloc( sizeof( es_out_pgrm_t ) ); es_out_pgrm_t *p_pgrm = malloc( sizeof( es_out_pgrm_t ) );
if( !p_pgrm ) return NULL; if( !p_pgrm )
return NULL;
/* Init */ /* Init */
p_pgrm->i_id = i_group; p_pgrm->i_id = i_group;
...@@ -690,7 +690,12 @@ static es_out_pgrm_t *EsOutProgramAdd( es_out_t *out, int i_group ) ...@@ -690,7 +690,12 @@ static es_out_pgrm_t *EsOutProgramAdd( es_out_t *out, int i_group )
p_pgrm->psz_now_playing = NULL; p_pgrm->psz_now_playing = NULL;
p_pgrm->psz_publisher = NULL; p_pgrm->psz_publisher = NULL;
p_pgrm->p_epg = NULL; p_pgrm->p_epg = NULL;
input_ClockInit( &p_pgrm->clock, false, p_input->p->input.i_cr_average, p_sys->i_rate ); p_pgrm->p_clock = input_ClockNew( false, p_input->p->input.i_cr_average, p_sys->i_rate );
if( !p_pgrm->p_clock )
{
free( p_pgrm );
return NULL;
}
/* Append it */ /* Append it */
TAB_APPEND( p_sys->i_pgrm, p_sys->pgrm, p_pgrm ); TAB_APPEND( p_sys->i_pgrm, p_sys->pgrm, p_pgrm );
...@@ -743,7 +748,10 @@ static int EsOutProgramDel( es_out_t *out, int i_group ) ...@@ -743,7 +748,10 @@ static int EsOutProgramDel( es_out_t *out, int i_group )
TAB_REMOVE( p_sys->i_pgrm, p_sys->pgrm, p_pgrm ); TAB_REMOVE( p_sys->i_pgrm, p_sys->pgrm, p_pgrm );
/* If program is selected we need to unselect it */ /* If program is selected we need to unselect it */
if( p_sys->p_pgrm == p_pgrm ) p_sys->p_pgrm = NULL; if( p_sys->p_pgrm == p_pgrm )
p_sys->p_pgrm = NULL;
input_ClockDelete( p_pgrm->p_clock );
free( p_pgrm->psz_name ); free( p_pgrm->psz_name );
free( p_pgrm->psz_now_playing ); free( p_pgrm->psz_now_playing );
...@@ -1153,7 +1161,7 @@ static void EsCreateDecoder( es_out_t *out, es_out_id_t *p_es ) ...@@ -1153,7 +1161,7 @@ static void EsCreateDecoder( es_out_t *out, es_out_id_t *p_es )
} }
static void EsDestroyDecoder( es_out_t *out, es_out_id_t *p_es ) static void EsDestroyDecoder( es_out_t *out, es_out_id_t *p_es )
{ {
es_out_sys_t *p_sys = out->p_sys; VLC_UNUSED(out);
if( !p_es->p_dec ) if( !p_es->p_dec )
return; return;
...@@ -1538,7 +1546,7 @@ static int EsOutSend( es_out_t *out, es_out_id_t *es, block_t *p_block ) ...@@ -1538,7 +1546,7 @@ static int EsOutSend( es_out_t *out, es_out_id_t *es, block_t *p_block )
else if( p_block->i_dts > 0 ) else if( p_block->i_dts > 0 )
{ {
p_block->i_dts = p_block->i_dts =
input_ClockGetTS( p_input, &p_pgrm->clock, p_block->i_dts ) + i_delay; input_ClockGetTS( p_input, p_pgrm->p_clock, p_block->i_dts ) + i_delay;
} }
if( p_block->i_pts > 0 && (p_block->i_flags&BLOCK_FLAG_PREROLL) ) if( p_block->i_pts > 0 && (p_block->i_flags&BLOCK_FLAG_PREROLL) )
{ {
...@@ -1547,7 +1555,7 @@ static int EsOutSend( es_out_t *out, es_out_id_t *es, block_t *p_block ) ...@@ -1547,7 +1555,7 @@ static int EsOutSend( es_out_t *out, es_out_id_t *es, block_t *p_block )
else if( p_block->i_pts > 0 ) else if( p_block->i_pts > 0 )
{ {
p_block->i_pts = p_block->i_pts =
input_ClockGetTS( p_input, &p_pgrm->clock, p_block->i_pts ) + i_delay; input_ClockGetTS( p_input, p_pgrm->p_clock, p_block->i_pts ) + i_delay;
} }
if ( p_block->i_rate == INPUT_RATE_DEFAULT && if ( p_block->i_rate == INPUT_RATE_DEFAULT &&
es->fmt.i_codec == VLC_FOURCC( 't', 'e', 'l', 'x' ) ) es->fmt.i_codec == VLC_FOURCC( 't', 'e', 'l', 'x' ) )
...@@ -1902,13 +1910,13 @@ static int EsOutControl( es_out_t *out, int i_query, va_list args ) ...@@ -1902,13 +1910,13 @@ static int EsOutControl( es_out_t *out, int i_query, va_list args )
i_pcr = (int64_t)va_arg( args, int64_t ); i_pcr = (int64_t)va_arg( args, int64_t );
/* search program /* search program
* TODO do not use mdate() but proper stream acquisition date */ * TODO do not use mdate() but proper stream acquisition date */
input_ClockSetPCR( p_sys->p_input, &p_pgrm->clock, i_pcr, mdate() ); input_ClockSetPCR( p_sys->p_input, p_pgrm->p_clock, i_pcr, mdate() );
return VLC_SUCCESS; return VLC_SUCCESS;
} }
case ES_OUT_RESET_PCR: case ES_OUT_RESET_PCR:
for( i = 0; i < p_sys->i_pgrm; i++ ) for( i = 0; i < p_sys->i_pgrm; i++ )
input_ClockResetPCR( &p_sys->pgrm[i]->clock ); input_ClockResetPCR( p_sys->pgrm[i]->p_clock );
return VLC_SUCCESS; return VLC_SUCCESS;
case ES_OUT_GET_TS: case ES_OUT_GET_TS:
...@@ -1917,7 +1925,7 @@ static int EsOutControl( es_out_t *out, int i_query, va_list args ) ...@@ -1917,7 +1925,7 @@ static int EsOutControl( es_out_t *out, int i_query, va_list args )
int64_t i_ts = (int64_t)va_arg( args, int64_t ); int64_t i_ts = (int64_t)va_arg( args, int64_t );
int64_t *pi_ts = (int64_t *)va_arg( args, int64_t * ); int64_t *pi_ts = (int64_t *)va_arg( args, int64_t * );
*pi_ts = input_ClockGetTS( p_sys->p_input, *pi_ts = input_ClockGetTS( p_sys->p_input,
&p_sys->p_pgrm->clock, i_ts ); p_sys->p_pgrm->p_clock, i_ts );
return VLC_SUCCESS; return VLC_SUCCESS;
} }
return VLC_EGENERIC; return VLC_EGENERIC;
......
...@@ -355,32 +355,17 @@ void input_EsOutChangeState( es_out_t * ); ...@@ -355,32 +355,17 @@ void input_EsOutChangeState( es_out_t * );
void input_EsOutChangePosition( es_out_t * ); void input_EsOutChangePosition( es_out_t * );
bool input_EsOutDecodersEmpty( es_out_t * ); bool input_EsOutDecodersEmpty( es_out_t * );
typedef struct /* clock.c */
{ typedef struct input_clock_t input_clock_t;
/* Synchronization information */
mtime_t delta_cr; input_clock_t *input_ClockNew( bool b_master, int i_cr_average, int i_rate );
mtime_t cr_ref, sysdate_ref; void input_ClockDelete( input_clock_t * );
mtime_t last_sysdate;
mtime_t last_cr; /* reference to detect unexpected stream
* discontinuities */
mtime_t last_pts;
mtime_t last_update;
bool b_has_reference;
bool b_master;
int i_rate;
/* Config */
int i_cr_average;
int i_delta_cr_residue;
} input_clock_t;
void input_ClockInit( input_clock_t *, bool b_master, int i_cr_average, int i_rate );
void input_ClockSetPCR( input_thread_t *, input_clock_t *, mtime_t i_clock, mtime_t i_system ); void input_ClockSetPCR( input_thread_t *, input_clock_t *, mtime_t i_clock, mtime_t i_system );
void input_ClockResetPCR( input_clock_t * ); void input_ClockResetPCR( input_clock_t * );
mtime_t input_ClockGetTS( input_thread_t *, input_clock_t *, mtime_t ); mtime_t input_ClockGetTS( input_thread_t *, input_clock_t *, mtime_t );
void input_ClockSetRate( input_clock_t *cl, int i_rate ); void input_ClockSetRate( input_clock_t *cl, int i_rate );
void input_ClockSetMaster( input_clock_t *cl, bool b_master );
mtime_t input_ClockGetWakeup( input_thread_t *, input_clock_t *cl ); mtime_t input_ClockGetWakeup( input_thread_t *, input_clock_t *cl );
/* Subtitles */ /* Subtitles */
......
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