Commit 12ee3312 authored by Rémi Denis-Courmont's avatar Rémi Denis-Courmont

input: merge InputSourceNew() and InputSourceInit()

Also merge InputSourceClean() and free().
parent 786cd054
...@@ -75,11 +75,10 @@ static void UpdateTitleListfromDemux( input_thread_t * ); ...@@ -75,11 +75,10 @@ static void UpdateTitleListfromDemux( input_thread_t * );
static void MRLSections( const char *, int *, int *, int *, int *); static void MRLSections( const char *, int *, int *, int *, int *);
static input_source_t *InputSourceNew( input_thread_t *); static input_source_t *InputSourceNew( input_thread_t *, const char *,
static int InputSourceInit( input_thread_t *, input_source_t *, const char *psz_forced_demux,
const char *, const char *psz_forced_demux,
bool b_in_can_fail ); bool b_in_can_fail );
static void InputSourceClean( input_source_t * ); static void InputSourceDestroy( input_source_t * );
static void InputSourceMeta( input_thread_t *, input_source_t *, vlc_meta_t * ); static void InputSourceMeta( input_thread_t *, input_source_t *, vlc_meta_t * );
/* TODO */ /* TODO */
...@@ -257,8 +256,6 @@ static void input_Destructor( vlc_object_t *obj ) ...@@ -257,8 +256,6 @@ static void input_Destructor( vlc_object_t *obj )
free( psz_name ); free( psz_name );
#endif #endif
free( p_input->p->master );
if( p_input->p->p_es_out_display ) if( p_input->p->p_es_out_display )
es_out_Delete( p_input->p->p_es_out_display ); es_out_Delete( p_input->p->p_es_out_display );
...@@ -359,17 +356,7 @@ static input_thread_t *Create( vlc_object_t *p_parent, input_item_t *p_item, ...@@ -359,17 +356,7 @@ static input_thread_t *Create( vlc_object_t *p_parent, input_item_t *p_item,
p_input->p->p_item = p_item; p_input->p->p_item = p_item;
/* Init Input fields */ /* Init Input fields */
p_input->p->master = InputSourceNew( p_input ); p_input->p->master = NULL;
if( unlikely(p_input->p->master == NULL) )
{
free( p_input->psz_header );
free( p_input->p );
vlc_object_release( p_input );
return NULL;
}
p_input->p->master->b_can_pace_control = true;
p_input->p->master->b_can_rate_control = true;
p_input->p->master->b_rescale_ts = true;
vlc_mutex_lock( &p_item->lock ); vlc_mutex_lock( &p_item->lock );
if( !p_item->p_stats ) if( !p_item->p_stats )
...@@ -1043,11 +1030,9 @@ static void LoadSlaves( input_thread_t *p_input ) ...@@ -1043,11 +1030,9 @@ static void LoadSlaves( input_thread_t *p_input )
continue; continue;
msg_Dbg( p_input, "adding slave input '%s'", uri ); msg_Dbg( p_input, "adding slave input '%s'", uri );
input_source_t *p_slave = InputSourceNew( p_input ); input_source_t *p_slave = InputSourceNew( p_input, uri, NULL, false );
if( p_slave && !InputSourceInit( p_input, p_slave, uri, NULL, false ) ) if( p_slave )
TAB_APPEND( p_input->p->i_slave, p_input->p->slave, p_slave ); TAB_APPEND( p_input->p->i_slave, p_input->p->slave, p_slave );
else
free( p_slave );
free( uri ); free( uri );
} }
free( psz_org ); free( psz_org );
...@@ -1141,6 +1126,8 @@ static void InitPrograms( input_thread_t * p_input ) ...@@ -1141,6 +1126,8 @@ static void InitPrograms( input_thread_t * p_input )
static int Init( input_thread_t * p_input ) static int Init( input_thread_t * p_input )
{ {
input_source_t *master;
for( int i = 0; i < p_input->p->p_item->i_options; i++ ) for( int i = 0; i < p_input->p->p_item->i_options; i++ )
{ {
if( !strncmp( p_input->p->p_item->ppsz_options[i], "meta-file", 9 ) ) if( !strncmp( p_input->p->p_item->ppsz_options[i], "meta-file", 9 ) )
...@@ -1169,19 +1156,18 @@ static int Init( input_thread_t * p_input ) ...@@ -1169,19 +1156,18 @@ static int Init( input_thread_t * p_input )
input_SendEventCache( p_input, 0.0 ); input_SendEventCache( p_input, 0.0 );
/* */ /* */
if( InputSourceInit( p_input, p_input->p->master, master = InputSourceNew( p_input, p_input->p->p_item->psz_uri, NULL,
p_input->p->p_item->psz_uri, NULL, false ) ) false );
{ if( master == NULL )
goto error; goto error;
} p_input->p->master = master;
InitTitle( p_input ); InitTitle( p_input );
/* Load master infos */ /* Load master infos */
/* Init length */ /* Init length */
mtime_t i_length; mtime_t i_length;
if( demux_Control( p_input->p->master->p_demux, DEMUX_GET_LENGTH, if( demux_Control( master->p_demux, DEMUX_GET_LENGTH, &i_length ) )
&i_length ) )
i_length = 0; i_length = 0;
if( i_length <= 0 ) if( i_length <= 0 )
i_length = input_item_GetDuration( p_input->p->p_item ); i_length = input_item_GetDuration( p_input->p->p_item );
...@@ -1226,7 +1212,7 @@ static int Init( input_thread_t * p_input ) ...@@ -1226,7 +1212,7 @@ static int Init( input_thread_t * p_input )
InputMetaUser( p_input, p_meta ); InputMetaUser( p_input, p_meta );
/* Get meta data from master input */ /* Get meta data from master input */
InputSourceMeta( p_input, p_input->p->master, p_meta ); InputSourceMeta( p_input, master, p_meta );
/* And from slave */ /* And from slave */
for( int i = 0; i < p_input->p->i_slave; i++ ) for( int i = 0; i < p_input->p->i_slave; i++ )
...@@ -1290,7 +1276,6 @@ error: ...@@ -1290,7 +1276,6 @@ error:
} }
/* Mark them deleted */ /* Mark them deleted */
p_input->p->master->p_demux = NULL;
p_input->p->p_es_out = NULL; p_input->p->p_es_out = NULL;
p_input->p->p_sout = NULL; p_input->p->p_sout = NULL;
...@@ -1302,8 +1287,6 @@ error: ...@@ -1302,8 +1287,6 @@ error:
*****************************************************************************/ *****************************************************************************/
static void End( input_thread_t * p_input ) static void End( input_thread_t * p_input )
{ {
int i;
/* We are at the end */ /* We are at the end */
input_ChangeState( p_input, END_S ); input_ChangeState( p_input, END_S );
...@@ -1313,17 +1296,14 @@ static void End( input_thread_t * p_input ) ...@@ -1313,17 +1296,14 @@ static void End( input_thread_t * p_input )
/* Stop es out activity */ /* Stop es out activity */
es_out_SetMode( p_input->p->p_es_out, ES_OUT_MODE_NONE ); es_out_SetMode( p_input->p->p_es_out, ES_OUT_MODE_NONE );
/* Clean up master */
InputSourceClean( p_input->p->master );
/* Delete slave */ /* Delete slave */
for( i = 0; i < p_input->p->i_slave; i++ ) for( int i = 0; i < p_input->p->i_slave; i++ )
{ InputSourceDestroy( p_input->p->slave[i] );
InputSourceClean( p_input->p->slave[i] );
free( p_input->p->slave[i] );
}
free( p_input->p->slave ); free( p_input->p->slave );
/* Clean up master */
InputSourceDestroy( p_input->p->master );
/* Unload all modules */ /* Unload all modules */
if( p_input->p->p_es_out ) if( p_input->p->p_es_out )
es_out_Delete( p_input->p->p_es_out ); es_out_Delete( p_input->p->p_es_out );
...@@ -1365,7 +1345,7 @@ static void End( input_thread_t * p_input ) ...@@ -1365,7 +1345,7 @@ static void End( input_thread_t * p_input )
vlc_mutex_lock( &p_input->p->p_item->lock ); vlc_mutex_lock( &p_input->p->p_item->lock );
if( p_input->p->i_attachment > 0 ) if( p_input->p->i_attachment > 0 )
{ {
for( i = 0; i < p_input->p->i_attachment; i++ ) for( int i = 0; i < p_input->p->i_attachment; i++ )
vlc_input_attachment_Delete( p_input->p->attachment[i] ); vlc_input_attachment_Delete( p_input->p->attachment[i] );
TAB_CLEAN( p_input->p->i_attachment, p_input->p->attachment ); TAB_CLEAN( p_input->p->i_attachment, p_input->p->attachment );
free( p_input->p->attachment_demux); free( p_input->p->attachment_demux);
...@@ -1886,10 +1866,14 @@ static bool Control( input_thread_t *p_input, ...@@ -1886,10 +1866,14 @@ static bool Control( input_thread_t *p_input,
if( val.psz_string ) if( val.psz_string )
{ {
const char *uri = val.psz_string; const char *uri = val.psz_string;
input_source_t *slave = InputSourceNew( p_input ); input_source_t *slave = InputSourceNew( p_input, uri, NULL,
false );
if( slave && !InputSourceInit( p_input, slave, uri, NULL, false ) ) if( slave == NULL )
{ {
msg_Warn( p_input, "failed to add %s as slave", uri );
break;
}
int64_t i_time; int64_t i_time;
/* Add the slave */ /* Add the slave */
...@@ -1900,16 +1884,15 @@ static bool Control( input_thread_t *p_input, ...@@ -1900,16 +1884,15 @@ static bool Control( input_thread_t *p_input,
DEMUX_GET_TIME, &i_time ) ) DEMUX_GET_TIME, &i_time ) )
{ {
msg_Err( p_input, "demux doesn't like DEMUX_GET_TIME" ); msg_Err( p_input, "demux doesn't like DEMUX_GET_TIME" );
InputSourceClean( slave ); InputSourceDestroy( slave );
free( slave );
break; break;
} }
if( demux_Control( slave->p_demux, if( demux_Control( slave->p_demux,
DEMUX_SET_TIME, i_time, true ) ) DEMUX_SET_TIME, i_time, true ) )
{ {
msg_Err( p_input, "seek failed for new slave" ); msg_Err( p_input, "seek failed for new slave" );
InputSourceClean( slave ); InputSourceDestroy( slave );
free( slave );
break; break;
} }
...@@ -1918,12 +1901,6 @@ static bool Control( input_thread_t *p_input, ...@@ -1918,12 +1901,6 @@ static bool Control( input_thread_t *p_input,
TAB_APPEND( p_input->p->i_slave, p_input->p->slave, slave ); TAB_APPEND( p_input->p->i_slave, p_input->p->slave, slave );
} }
else
{
free( slave );
msg_Warn( p_input, "failed to add %s as slave", uri );
}
}
break; break;
case INPUT_CONTROL_SET_RECORD_STATE: case INPUT_CONTROL_SET_RECORD_STATE:
...@@ -2107,20 +2084,15 @@ static void UpdateTitleListfromDemux( input_thread_t *p_input ) ...@@ -2107,20 +2084,15 @@ static void UpdateTitleListfromDemux( input_thread_t *p_input )
/***************************************************************************** /*****************************************************************************
* InputSourceNew: * InputSourceNew:
*****************************************************************************/ *****************************************************************************/
static input_source_t *InputSourceNew( input_thread_t *p_input ) static input_source_t *InputSourceNew( input_thread_t *p_input,
const char *psz_mrl,
const char *psz_forced_demux,
bool b_in_can_fail )
{ {
VLC_UNUSED(p_input); input_source_t *in = calloc( 1, sizeof( *in ) );
if( unlikely(in == NULL) )
return calloc( 1, sizeof( input_source_t ) ); return NULL;
}
/*****************************************************************************
* InputSourceInit:
*****************************************************************************/
static int InputSourceInit( input_thread_t *p_input,
input_source_t *in, const char *psz_mrl,
const char *psz_forced_demux, bool b_in_can_fail )
{
const char *psz_access, *psz_demux, *psz_path, *psz_anchor = NULL; const char *psz_access, *psz_demux, *psz_path, *psz_anchor = NULL;
double f_fps; double f_fps;
...@@ -2128,7 +2100,10 @@ static int InputSourceInit( input_thread_t *p_input, ...@@ -2128,7 +2100,10 @@ static int InputSourceInit( input_thread_t *p_input,
char *psz_dup = strdup( psz_mrl ); char *psz_dup = strdup( psz_mrl );
if( psz_dup == NULL ) if( psz_dup == NULL )
return VLC_ENOMEM; {
free( in );
return NULL;
}
/* Split uri */ /* Split uri */
input_SplitMRL( &psz_access, &psz_demux, &psz_path, &psz_anchor, psz_dup ); input_SplitMRL( &psz_access, &psz_demux, &psz_path, &psz_anchor, psz_dup );
...@@ -2143,7 +2118,7 @@ static int InputSourceInit( input_thread_t *p_input, ...@@ -2143,7 +2118,7 @@ static int InputSourceInit( input_thread_t *p_input,
MRLSections( psz_anchor, &in->i_title_start, &in->i_title_end, MRLSections( psz_anchor, &in->i_title_start, &in->i_title_end,
&in->i_seekpoint_start, &in->i_seekpoint_end ); &in->i_seekpoint_start, &in->i_seekpoint_end );
if( p_input->p->master == in ) if( p_input->p->master == NULL /* XXX ugly */)
{ /* On master stream only, use input-list */ { /* On master stream only, use input-list */
char *str = var_InheritString( p_input, "input-list" ); char *str = var_InheritString( p_input, "input-list" );
if( str != NULL ) if( str != NULL )
...@@ -2207,7 +2182,8 @@ static int InputSourceInit( input_thread_t *p_input, ...@@ -2207,7 +2182,8 @@ static int InputSourceInit( input_thread_t *p_input,
dialog_Fatal( p_input, _("Your input can't be opened"), dialog_Fatal( p_input, _("Your input can't be opened"),
_("VLC is unable to open the MRL '%s'." _("VLC is unable to open the MRL '%s'."
" Check the log for details."), psz_mrl ); " Check the log for details."), psz_mrl );
return VLC_EGENERIC; free( in );
return NULL;
} }
/* Get infos from (access_)demux */ /* Get infos from (access_)demux */
...@@ -2305,13 +2281,13 @@ static int InputSourceInit( input_thread_t *p_input, ...@@ -2305,13 +2281,13 @@ static int InputSourceInit( input_thread_t *p_input,
if( var_GetInteger( p_input, "clock-synchro" ) != -1 ) if( var_GetInteger( p_input, "clock-synchro" ) != -1 )
in->b_can_pace_control = !var_GetInteger( p_input, "clock-synchro" ); in->b_can_pace_control = !var_GetInteger( p_input, "clock-synchro" );
return VLC_SUCCESS; return in;
} }
/***************************************************************************** /*****************************************************************************
* InputSourceClean: * InputSourceDestroy:
*****************************************************************************/ *****************************************************************************/
static void InputSourceClean( input_source_t *in ) static void InputSourceDestroy( input_source_t *in )
{ {
int i; int i;
...@@ -2324,6 +2300,8 @@ static void InputSourceClean( input_source_t *in ) ...@@ -2324,6 +2300,8 @@ static void InputSourceClean( input_source_t *in )
vlc_input_title_Delete( in->title[i] ); vlc_input_title_Delete( in->title[i] );
TAB_CLEAN( in->i_title, in->title ); TAB_CLEAN( in->i_title, in->title );
} }
free( in );
} }
/***************************************************************************** /*****************************************************************************
...@@ -2794,20 +2772,15 @@ static void MRLSections( const char *p, ...@@ -2794,20 +2772,15 @@ static void MRLSections( const char *p,
static void input_SubtitleAdd( input_thread_t *p_input, static void input_SubtitleAdd( input_thread_t *p_input,
const char *url, unsigned i_flags ) const char *url, unsigned i_flags )
{ {
input_source_t *sub = InputSourceNew( p_input );
if( sub == NULL )
return;
vlc_value_t count; vlc_value_t count;
var_Change( p_input, "spu-es", VLC_VAR_CHOICESCOUNT, &count, NULL ); var_Change( p_input, "spu-es", VLC_VAR_CHOICESCOUNT, &count, NULL );
if( InputSourceInit( p_input, sub, url, "subtitle", input_source_t *sub = InputSourceNew( p_input, url, "subtitle",
(i_flags & SUB_CANFAIL) ) ) (i_flags & SUB_CANFAIL) );
{ if( sub == NULL )
free( sub );
return; return;
}
TAB_APPEND( p_input->p->i_slave, p_input->p->slave, sub ); TAB_APPEND( p_input->p->i_slave, p_input->p->slave, sub );
if( !(i_flags & SUB_FORCED) ) if( !(i_flags & SUB_FORCED) )
......
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