Commit 6dc87602 authored by Rémi Denis-Courmont's avatar Rémi Denis-Courmont

input: factor if and add error handling to demux_New()

parent e1c3843f
......@@ -63,26 +63,25 @@ demux_t *demux_New( vlc_object_t *p_obj, input_thread_t *p_parent_input,
stream_t *s, es_out_t *out, bool b_quick )
{
demux_t *p_demux = vlc_custom_create( p_obj, sizeof( *p_demux ), "demux" );
const char *psz_module;
if( p_demux == NULL ) return NULL;
if( unlikely(p_demux == NULL) )
return NULL;
p_demux->p_input = p_parent_input;
/* Parse URL */
p_demux->psz_access = strdup( psz_access );
if( psz_demux[0] == '\0' )
/* Take into account "demux" to be able to do :demux=dump */
p_demux->psz_demux = var_InheritString( p_obj, "demux" );
else
p_demux->psz_demux = strdup( psz_demux );
p_demux->psz_location = strdup( psz_location );
p_demux->psz_file = get_path( psz_location );
p_demux->psz_file = get_path( psz_location ); /* parse URL */
/* Take into account "demux" to be able to do :demux=dump */
if( *p_demux->psz_demux == '\0' )
{
free( p_demux->psz_demux );
p_demux->psz_demux = var_GetNonEmptyString( p_obj, "demux" );
if( p_demux->psz_demux == NULL )
p_demux->psz_demux = strdup( "" );
}
if( unlikely(p_demux->psz_access == NULL
|| p_demux->psz_demux == NULL
|| p_demux->psz_location == NULL) )
goto error;
if( !b_quick )
msg_Dbg( p_obj, "creating demux: access='%s' demux='%s' "
......@@ -100,16 +99,7 @@ demux_t *demux_New( vlc_object_t *p_obj, input_thread_t *p_parent_input,
p_demux->info.i_title = 0;
p_demux->info.i_seekpoint = 0;
if( s ) psz_module = p_demux->psz_demux;
else psz_module = p_demux->psz_access;
const char *psz_ext;
if( s && *psz_module == '\0'
&& p_demux->psz_file != NULL
&& (psz_ext = strrchr( p_demux->psz_file, '.' )) )
{
/* XXX: add only file without any problem here and with strong detection.
/* NOTE: Add only file without any problems here and with strong detection:
* - no .mp3, .a52, ...
* - wav can't be added 'cause of a52 and dts in them as raw audio
*/
......@@ -148,6 +138,14 @@ demux_t *demux_New( vlc_object_t *p_obj, input_thread_t *p_parent_input,
{ "", "" }
};
if( s != NULL )
{
const char *psz_ext;
const char *psz_module = p_demux->psz_demux;
if( *psz_module && p_demux->psz_file != NULL
&& (psz_ext = strrchr( p_demux->psz_file, '.' )) != NULL )
{
psz_ext++; // skip '.'
if( !b_quick )
......@@ -171,12 +169,9 @@ demux_t *demux_New( vlc_object_t *p_obj, input_thread_t *p_parent_input,
break;
}
}
}
}
if( s )
{
/* ID3/APE tags will mess-up demuxer probing so we skip it here.
* ID3/APE parsers will called later on in the demuxer to access the
* skipped info. */
......@@ -191,21 +186,20 @@ demux_t *demux_New( vlc_object_t *p_obj, input_thread_t *p_parent_input,
else
{
p_demux->p_module =
module_need( p_demux, "access_demux", psz_module,
!strcmp( psz_module, p_demux->psz_access ) );
module_need( p_demux, "access_demux", p_demux->psz_access, true );
}
if( p_demux->p_module == NULL )
{
goto error;
return p_demux;
error:
free( p_demux->psz_file );
free( p_demux->psz_location );
free( p_demux->psz_demux );
free( p_demux->psz_access );
vlc_object_release( p_demux );
return NULL;
}
return p_demux;
}
/*****************************************************************************
......
......@@ -1884,7 +1884,7 @@ vlc_module_begin ()
add_module( "access", "access", NULL, ACCESS_TEXT, ACCESS_LONGTEXT, true )
set_subcategory( SUBCAT_INPUT_DEMUX )
add_module( "demux", "demux", NULL, DEMUX_TEXT, DEMUX_LONGTEXT, true )
add_module( "demux", "demux", "any", DEMUX_TEXT, DEMUX_LONGTEXT, true )
set_subcategory( SUBCAT_INPUT_VCODEC )
set_subcategory( SUBCAT_INPUT_ACODEC )
set_subcategory( SUBCAT_INPUT_SCODEC )
......
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