[vlc-commits] input: factor if and add error handling to demux_New()
Rémi Denis-Courmont
git at videolan.org
Mon Mar 10 21:29:36 CET 2014
vlc | branch: master | Rémi Denis-Courmont <remi at remlab.net> | Mon Mar 10 22:00:40 2014 +0200| [6dc876028c457902f0b8ca2f3ca56186fe811f9f] | committer: Rémi Denis-Courmont
input: factor if and add error handling to demux_New()
> http://git.videolan.org/gitweb.cgi/vlc.git/?a=commit;h=6dc876028c457902f0b8ca2f3ca56186fe811f9f
---
src/input/demux.c | 170 +++++++++++++++++++++++++--------------------------
src/libvlc-module.c | 2 +-
2 files changed, 83 insertions(+), 89 deletions(-)
diff --git a/src/input/demux.c b/src/input/demux.c
index 56301af..622f568 100644
--- a/src/input/demux.c
+++ b/src/input/demux.c
@@ -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 );
- p_demux->psz_demux = strdup( psz_demux );
+
+ 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,83 +99,79 @@ 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, '.' )) )
+ /* 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
+ */
+ static const struct { char ext[5]; char demux[9]; } exttodemux[] =
{
- /* XXX: add only file without any problem here and with strong detection.
- * - no .mp3, .a52, ...
- * - wav can't be added 'cause of a52 and dts in them as raw audio
- */
- static const struct { char ext[5]; char demux[9]; } exttodemux[] =
- {
- { "aiff", "aiff" },
- { "asf", "asf" }, { "wmv", "asf" }, { "wma", "asf" },
- { "avi", "avi" },
- { "au", "au" },
- { "flac", "flac" },
- { "dv", "dv" },
- { "drc", "dirac" },
- { "m3u", "m3u" },
- { "m3u8", "m3u8" },
- { "mkv", "mkv" }, { "mka", "mkv" }, { "mks", "mkv" },
- { "mp4", "mp4" }, { "m4a", "mp4" }, { "mov", "mp4" }, { "moov", "mp4" },
- { "nsv", "nsv" },
- { "ogg", "ogg" }, { "ogm", "ogg" }, /* legacy Ogg */
- { "oga", "ogg" }, { "spx", "ogg" }, { "ogv", "ogg" },
- { "ogx", "ogg" }, /*RFC5334*/
- { "opus", "ogg" }, /*draft-terriberry-oggopus-01*/
- { "pva", "pva" },
- { "rm", "avformat" },
- { "m4v", "m4v" },
- { "h264", "h264" },
- { "voc", "voc" },
- { "mid", "smf" }, { "rmi", "smf" }, { "kar", "smf" },
- { "", "" },
- };
- /* Here, we don't mind if it does not work, it must be quick */
- static const struct { char ext[4]; char demux[5]; } exttodemux_quick[] =
- {
- { "mp3", "mpga" },
- { "ogg", "ogg" },
- { "wma", "asf" },
- { "", "" }
- };
+ { "aiff", "aiff" },
+ { "asf", "asf" }, { "wmv", "asf" }, { "wma", "asf" },
+ { "avi", "avi" },
+ { "au", "au" },
+ { "flac", "flac" },
+ { "dv", "dv" },
+ { "drc", "dirac" },
+ { "m3u", "m3u" },
+ { "m3u8", "m3u8" },
+ { "mkv", "mkv" }, { "mka", "mkv" }, { "mks", "mkv" },
+ { "mp4", "mp4" }, { "m4a", "mp4" }, { "mov", "mp4" }, { "moov", "mp4" },
+ { "nsv", "nsv" },
+ { "ogg", "ogg" }, { "ogm", "ogg" }, /* legacy Ogg */
+ { "oga", "ogg" }, { "spx", "ogg" }, { "ogv", "ogg" },
+ { "ogx", "ogg" }, /*RFC5334*/
+ { "opus", "ogg" }, /*draft-terriberry-oggopus-01*/
+ { "pva", "pva" },
+ { "rm", "avformat" },
+ { "m4v", "m4v" },
+ { "h264", "h264" },
+ { "voc", "voc" },
+ { "mid", "smf" }, { "rmi", "smf" }, { "kar", "smf" },
+ { "", "" },
+ };
+ /* Here, we don't mind if it does not work, it must be quick */
+ static const struct { char ext[4]; char demux[5]; } exttodemux_quick[] =
+ {
+ { "mp3", "mpga" },
+ { "ogg", "ogg" },
+ { "wma", "asf" },
+ { "", "" }
+ };
- psz_ext++; // skip '.'
+ if( s != NULL )
+ {
+ const char *psz_ext;
+ const char *psz_module = p_demux->psz_demux;
- if( !b_quick )
+ if( *psz_module && p_demux->psz_file != NULL
+ && (psz_ext = strrchr( p_demux->psz_file, '.' )) != NULL )
{
- for( unsigned i = 0; exttodemux[i].ext[0]; i++ )
+ psz_ext++; // skip '.'
+
+ if( !b_quick )
{
- if( !strcasecmp( psz_ext, exttodemux[i].ext ) )
+ for( unsigned i = 0; exttodemux[i].ext[0]; i++ )
{
- psz_module = exttodemux[i].demux;
- break;
+ if( !strcasecmp( psz_ext, exttodemux[i].ext ) )
+ {
+ psz_module = exttodemux[i].demux;
+ break;
+ }
}
}
- }
- else
- {
- for( unsigned i = 0; exttodemux_quick[i].ext[0]; i++ )
+ else
{
- if( !strcasecmp( psz_ext, exttodemux_quick[i].ext ) )
+ for( unsigned i = 0; exttodemux_quick[i].ext[0]; i++ )
{
- psz_module = exttodemux_quick[i].demux;
- break;
+ if( !strcasecmp( psz_ext, exttodemux_quick[i].ext ) )
+ {
+ psz_module = exttodemux_quick[i].demux;
+ 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 )
- {
- 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;
- }
+ 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;
}
/*****************************************************************************
diff --git a/src/libvlc-module.c b/src/libvlc-module.c
index 11fd1cb..85637bd 100644
--- a/src/libvlc-module.c
+++ b/src/libvlc-module.c
@@ -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 )
More information about the vlc-commits
mailing list