Commit 920692ff authored by Pierre d'Herbemont's avatar Pierre d'Herbemont

input: Split Init() into multiple subfunctions to try to isolate the different...

input: Split Init() into multiple subfunctions to try to isolate the different part of the function.
parent f94a2f9c
...@@ -91,6 +91,7 @@ static sout_instance_t *SoutFind( vlc_object_t *p_parent, input_item_t *p_item, ...@@ -91,6 +91,7 @@ static sout_instance_t *SoutFind( vlc_object_t *p_parent, input_item_t *p_item,
static void SoutKeep( sout_instance_t * ); static void SoutKeep( sout_instance_t * );
static void DemuxMeta( input_thread_t *p_input, vlc_meta_t *p_meta, demux_t *p_demux ); static void DemuxMeta( input_thread_t *p_input, vlc_meta_t *p_meta, demux_t *p_demux );
static void AccessMeta( input_thread_t * p_input, vlc_meta_t *p_meta );
static void AppendAttachment( int *pi_attachment, input_attachment_t ***ppp_attachment, static void AppendAttachment( int *pi_attachment, input_attachment_t ***ppp_attachment,
int i_new, input_attachment_t **pp_new ); int i_new, input_attachment_t **pp_new );
...@@ -768,32 +769,10 @@ static void MainLoop( input_thread_t *p_input ) ...@@ -768,32 +769,10 @@ static void MainLoop( input_thread_t *p_input )
} }
} }
static int Init( input_thread_t * p_input ) static void InitStatistics( input_thread_t * p_input )
{ {
char *psz; if( p_input->b_preparsing ) return;
char *psz_subtitle;
vlc_value_t val;
double f_fps;
vlc_meta_t *p_meta;
int i_es_out_mode;
int i, i_delay;
for( i = 0; i < p_input->p->input.p_item->i_options; i++ )
{
if( !strncmp( p_input->p->input.p_item->ppsz_options[i], "meta-file", 9 ) )
{
msg_Dbg( p_input, "Input is a meta file: disabling unneeded options" );
var_SetString( p_input, "sout", "" );
var_SetBool( p_input, "sout-all", false );
var_SetString( p_input, "input-slave", "" );
var_SetInteger( p_input, "input-repeat", 0 );
var_SetString( p_input, "sub-file", "" );
var_SetBool( p_input, "sub-autodetect-file", false );
}
}
if( !p_input->b_preparsing )
{
/* Prepare statistics */ /* Prepare statistics */
#define INIT_COUNTER( c, type, compute ) p_input->p->counters.p_##c = \ #define INIT_COUNTER( c, type, compute ) p_input->p->counters.p_##c = \
stats_CounterCreate( p_input, VLC_VAR_##type, STATS_##compute); stats_CounterCreate( p_input, VLC_VAR_##type, STATS_##compute);
...@@ -819,6 +798,13 @@ static int Init( input_thread_t * p_input ) ...@@ -819,6 +798,13 @@ static int Init( input_thread_t * p_input )
if( p_input->p->counters.p_input_bitrate ) if( p_input->p->counters.p_input_bitrate )
p_input->p->counters.p_input_bitrate->update_interval = 1000000; p_input->p->counters.p_input_bitrate->update_interval = 1000000;
} }
}
static int InitSout( input_thread_t * p_input )
{
char *psz;
if( p_input->b_preparsing ) return VLC_SUCCESS;
/* Find a usable sout and attach it to p_input */ /* Find a usable sout and attach it to p_input */
psz = var_GetNonEmptyString( p_input, "sout" ); psz = var_GetNonEmptyString( p_input, "sout" );
...@@ -857,7 +843,6 @@ static int Init( input_thread_t * p_input ) ...@@ -857,7 +843,6 @@ static int Init( input_thread_t * p_input )
return VLC_EGENERIC; return VLC_EGENERIC;
} }
} }
if( p_input->p_libvlc->b_stats ) if( p_input->p_libvlc->b_stats )
{ {
INIT_COUNTER( sout_sent_packets, INTEGER, COUNTER ); INIT_COUNTER( sout_sent_packets, INTEGER, COUNTER );
...@@ -876,25 +861,17 @@ static int Init( input_thread_t * p_input ) ...@@ -876,25 +861,17 @@ static int Init( input_thread_t * p_input )
p_input->p->p_sout = NULL; p_input->p->p_sout = NULL;
} }
free( psz ); free( psz );
}
/* Create es out */ return VLC_SUCCESS;
p_input->p->p_es_out = input_EsOutNew( p_input, p_input->p->i_rate ); }
es_out_Control( p_input->p->p_es_out, ES_OUT_SET_ACTIVE, false );
es_out_Control( p_input->p->p_es_out, ES_OUT_SET_MODE, ES_OUT_MODE_NONE );
var_Create( p_input, "bit-rate", VLC_VAR_INTEGER ); static void InitTitle( input_thread_t * p_input )
var_Create( p_input, "sample-rate", VLC_VAR_INTEGER ); {
vlc_value_t val;
if( InputSourceInit( p_input, &p_input->p->input, if( p_input->b_preparsing ) return;
p_input->p->input.p_item->psz_uri, NULL ) )
{
goto error;
}
/* Create global title (from master) */ /* Create global title (from master) */
if( !p_input->b_preparsing )
{
p_input->p->i_title = p_input->p->input.i_title; p_input->p->i_title = p_input->p->input.i_title;
p_input->p->title = p_input->p->input.title; p_input->p->title = p_input->p->input.title;
p_input->p->i_title_offset = p_input->p->input.i_title_offset; p_input->p->i_title_offset = p_input->p->input.i_title_offset;
...@@ -924,29 +901,24 @@ static int Init( input_thread_t * p_input ) ...@@ -924,29 +901,24 @@ static int Init( input_thread_t * p_input )
p_input->p->input.i_cr_average *= (10 * p_input->i_pts_delay / 200000); p_input->p->input.i_cr_average *= (10 * p_input->i_pts_delay / 200000);
p_input->p->input.i_cr_average /= 10; p_input->p->input.i_cr_average /= 10;
if( p_input->p->input.i_cr_average < 10 ) p_input->p->input.i_cr_average = 10; if( p_input->p->input.i_cr_average < 10 ) p_input->p->input.i_cr_average = 10;
} }
/* Load master infos */ static void StartTitle( input_thread_t * p_input )
/* Init length */ {
if( !demux_Control( p_input->p->input.p_demux, DEMUX_GET_LENGTH, double f_fps;
&val.i_time ) && val.i_time > 0 ) vlc_value_t val;
{ int i, i_delay;
var_Change( p_input, "length", VLC_VAR_SETVALUE, &val, NULL ); char *psz;
UpdateItemLength( p_input, val.i_time ); char *psz_subtitle;
}
else
{
val.i_time = input_item_GetDuration( p_input->p->input.p_item );
if( val.i_time > 0 )
{ /* fallback: gets length from metadata */
var_Change( p_input, "length", VLC_VAR_SETVALUE, &val, NULL );
UpdateItemLength( p_input, val.i_time );
}
}
/* Start title/chapter */ /* Start title/chapter */
if( !p_input->b_preparsing )
if( p_input->b_preparsing )
{ {
p_input->p->i_start = 0;
return;
}
val.i_int = p_input->p->input.i_title_start - val.i_int = p_input->p->input.i_title_start -
p_input->p->input.i_title_offset; p_input->p->input.i_title_offset;
if( val.i_int > 0 && val.i_int < p_input->p->input.i_title ) if( val.i_int > 0 && val.i_int < p_input->p->input.i_title )
...@@ -1094,16 +1066,16 @@ static int Init( input_thread_t * p_input ) ...@@ -1094,16 +1066,16 @@ static int Init( input_thread_t * p_input )
} }
free( psz ); free( psz );
} }
} }
else
{ static void InitPrograms( input_thread_t * p_input )
p_input->p->i_start = 0; {
p_input->p->i_start = 0; int i_es_out_mode;
} vlc_value_t val;
if( p_input->b_preparsing ) return;
/* Set up es_out */ /* Set up es_out */
if( !p_input->b_preparsing )
{
es_out_Control( p_input->p->p_es_out, ES_OUT_SET_ACTIVE, true ); es_out_Control( p_input->p->p_es_out, ES_OUT_SET_ACTIVE, true );
i_es_out_mode = ES_OUT_MODE_AUTO; i_es_out_mode = ES_OUT_MODE_AUTO;
val.p_list = NULL; val.p_list = NULL;
...@@ -1145,17 +1117,75 @@ static int Init( input_thread_t * p_input ) ...@@ -1145,17 +1117,75 @@ static int Init( input_thread_t * p_input )
demux_Control( p_input->p->input.p_demux, DEMUX_SET_GROUP, demux_Control( p_input->p->input.p_demux, DEMUX_SET_GROUP,
(int) var_GetInteger( p_input, "program" ), NULL ); (int) var_GetInteger( p_input, "program" ), NULL );
} }
}
if( p_input->p->p_sout ) static int Init( input_thread_t * p_input )
{
vlc_meta_t *p_meta;
vlc_value_t val;
int i, ret;
for( i = 0; i < p_input->p->input.p_item->i_options; i++ )
{ {
if( p_input->p->p_sout->i_out_pace_nocontrol > 0 ) if( !strncmp( p_input->p->input.p_item->ppsz_options[i], "meta-file", 9 ) )
{ {
p_input->p->b_out_pace_control = false; msg_Dbg( p_input, "Input is a meta file: disabling unneeded options" );
var_SetString( p_input, "sout", "" );
var_SetBool( p_input, "sout-all", false );
var_SetString( p_input, "input-slave", "" );
var_SetInteger( p_input, "input-repeat", 0 );
var_SetString( p_input, "sub-file", "" );
var_SetBool( p_input, "sub-autodetect-file", false );
}
}
InitStatistics( p_input );
ret = InitSout( p_input );
if( ret != VLC_SUCCESS )
return ret; /* FIXME: goto error; should be better here */
/* Create es out */
p_input->p->p_es_out = input_EsOutNew( p_input, p_input->p->i_rate );
es_out_Control( p_input->p->p_es_out, ES_OUT_SET_ACTIVE, false );
es_out_Control( p_input->p->p_es_out, ES_OUT_SET_MODE, ES_OUT_MODE_NONE );
var_Create( p_input, "bit-rate", VLC_VAR_INTEGER );
var_Create( p_input, "sample-rate", VLC_VAR_INTEGER );
if( InputSourceInit( p_input, &p_input->p->input,
p_input->p->input.p_item->psz_uri, NULL ) )
{
goto error;
}
InitTitle( p_input );
/* Load master infos */
/* Init length */
if( !demux_Control( p_input->p->input.p_demux, DEMUX_GET_LENGTH,
&val.i_time ) && val.i_time > 0 )
{
var_Change( p_input, "length", VLC_VAR_SETVALUE, &val, NULL );
UpdateItemLength( p_input, val.i_time );
} }
else else
{ {
p_input->p->b_out_pace_control = true; val.i_time = input_item_GetDuration( p_input->p->input.p_item );
if( val.i_time > 0 )
{ /* fallback: gets length from metadata */
var_Change( p_input, "length", VLC_VAR_SETVALUE, &val, NULL );
UpdateItemLength( p_input, val.i_time );
} }
}
StartTitle( p_input );
InitPrograms( p_input );
if( !p_input->b_preparsing && p_input->p->p_sout )
{
p_input->p->b_out_pace_control = (p_input->p->p_sout->i_out_pace_nocontrol > 0);
if( p_input->b_can_pace_control && p_input->p->b_out_pace_control ) if( p_input->b_can_pace_control && p_input->p->b_out_pace_control )
{ {
...@@ -1167,9 +1197,9 @@ static int Init( input_thread_t * p_input ) ...@@ -1167,9 +1197,9 @@ static int Init( input_thread_t * p_input )
msg_Dbg( p_input, "starting in %s mode", msg_Dbg( p_input, "starting in %s mode",
p_input->p->b_out_pace_control ? "async" : "sync" ); p_input->p->b_out_pace_control ? "async" : "sync" );
} }
}
p_meta = vlc_meta_New(); p_meta = vlc_meta_New();
/* Get meta data from users */ /* Get meta data from users */
InputMetaUser( p_input, p_meta ); InputMetaUser( p_input, p_meta );
...@@ -1177,25 +1207,7 @@ static int Init( input_thread_t * p_input ) ...@@ -1177,25 +1207,7 @@ static int Init( input_thread_t * p_input )
DemuxMeta( p_input, p_meta, p_input->p->input.p_demux ); DemuxMeta( p_input, p_meta, p_input->p->input.p_demux );
/* Access_file does not give any meta, and there are no slave */ /* Access_file does not give any meta, and there are no slave */
if( !p_input->b_preparsing ) AccessMeta( p_input, p_meta );
{
if( p_input->p->input.p_access )
access_Control( p_input->p->input.p_access, ACCESS_GET_META,
p_meta );
/* Get meta data from slave input */
for( i = 0; i < p_input->p->i_slave; i++ )
{
DemuxMeta( p_input, p_meta, p_input->p->slave[i]->p_demux );
if( p_input->p->slave[i]->p_access )
{
access_Control( p_input->p->slave[i]->p_access,
ACCESS_GET_META, p_meta );
}
}
}
InputUpdateMeta( p_input, p_meta );
if( !p_input->b_preparsing ) if( !p_input->b_preparsing )
{ {
...@@ -2716,6 +2728,29 @@ static void AppendAttachment( int *pi_attachment, input_attachment_t ***ppp_atta ...@@ -2716,6 +2728,29 @@ static void AppendAttachment( int *pi_attachment, input_attachment_t ***ppp_atta
*ppp_attachment = attachment; *ppp_attachment = attachment;
} }
static void AccessMeta( input_thread_t * p_input, vlc_meta_t *p_meta )
{
int i;
if( p_input->b_preparsing )
return;
if( p_input->p->input.p_access )
access_Control( p_input->p->input.p_access, ACCESS_GET_META,
p_meta );
/* Get meta data from slave input */
for( i = 0; i < p_input->p->i_slave; i++ )
{
DemuxMeta( p_input, p_meta, p_input->p->slave[i]->p_demux );
if( p_input->p->slave[i]->p_access )
{
access_Control( p_input->p->slave[i]->p_access,
ACCESS_GET_META, p_meta );
}
}
}
static void DemuxMeta( input_thread_t *p_input, vlc_meta_t *p_meta, demux_t *p_demux ) static void DemuxMeta( input_thread_t *p_input, vlc_meta_t *p_meta, demux_t *p_demux )
{ {
bool b_bool; bool b_bool;
......
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