Add a bunch of helper functions/macros and start using them:
authorClément Stenac <zorglub@videolan.org>
Tue, 18 Jul 2006 17:08:18 +0000 (17:08 +0000)
committerClément Stenac <zorglub@videolan.org>
Tue, 18 Jul 2006 17:08:18 +0000 (17:08 +0000)
* malloc with NULL check
* file extension check
* check if a demux was forced
* try peeking, and check what we poke
* init standard demuxer fields
* create packetizers

20 files changed:
include/vlc_common.h
include/vlc_demux.h
modules/demux/a52.c
modules/demux/aiff.c
modules/demux/au.c
modules/demux/dts.c
modules/demux/playlist/asx.c
modules/demux/playlist/b4s.c
modules/demux/playlist/dvb.c
modules/demux/playlist/gvp.c
modules/demux/playlist/m3u.c
modules/demux/playlist/old.c
modules/demux/playlist/pls.c
modules/demux/playlist/podcast.c
modules/demux/playlist/qtl.c
modules/demux/playlist/sgimb.c
modules/demux/playlist/shoutcast.c
modules/demux/playlist/xspf.c
modules/demux/playlist/xspf.h
src/playlist/item.c

index f2da04a..7d0090a 100644 (file)
@@ -596,6 +596,20 @@ static int64_t GCD( int64_t a, int64_t b )
     else return a;
 }
 
+/* Malloc with automatic error */
+#define MALLOC_VOID( var, type ) { var = (type*)malloc( sizeof( type) ); \
+                                   if( !var ) return; }
+#define MALLOC_NULL( var, type ) { var = (type*)malloc( sizeof( type) ); \
+                                   if( !var ) return NULL; }
+#define MALLOC_ERR( var, type ) { var = (type*)malloc( sizeof( type) ); \
+                                   if( !var ) return VLC_ENOMEM; }
+#define MALLOC_GOTOERR( var, type ) { var = (type*)malloc( sizeof( type) ); \
+                                      if( !var ) goto error; }
+#define DECMALLOC_VOID( var, type ) type* var = (type*)malloc( sizeof(type) );\
+                                    if( !var ) return;
+#define DECMALLOC_NULL( var, type ) type* var = (type*)malloc( sizeof(type) );\
+                                    if( !var ) return NULL;
+
 /* Dynamic array handling: realloc array, move data, increment position */
 #if defined( _MSC_VER ) && _MSC_VER < 1300 && !defined( UNDER_CE )
 #   define VLCCVP (void**) /* Work-around for broken compiler */
index 52bfcca..d4e6e0f 100644 (file)
@@ -132,6 +132,97 @@ static inline int demux2_Control( demux_t *p_demux, int i_query, ... )
     va_end( args );
     return i_result;
 }
+
+/*************************************************************************
+ * Miscellaneous helpers for demuxers
+ *************************************************************************/
+
+static inline vlc_bool_t isExtension( demux_t *p_demux, char *psz_requested )
+{
+    char    *psz_ext;
+    psz_ext = strrchr ( p_demux->psz_path, '.' );
+    if( !psz_ext || strcmp( psz_ext, psz_requested ) )
+        return VLC_FALSE;
+    return VLC_TRUE;
+}
+static inline vlc_bool_t isDemux( demux_t *p_demux, char *psz_requested )
+{
+   if( !p_demux->psz_demux || strcmp( p_demux->psz_demux, psz_requested ) )
+        return VLC_FALSE;
+    return VLC_TRUE;
+}
+
+#define STANDARD_DEMUX_INIT \
+    p_demux->pf_control = Control; \
+    p_demux->pf_demux = Demux; \
+    MALLOC_ERR( p_demux->p_sys, demux_sys_t );
+
+#define STANDARD_DEMUX_INIT_MSG( msg ) \
+    p_demux->pf_control = Control; \
+    p_demux->pf_demux = Demux; \
+    MALLOC_ERR( p_demux->p_sys, demux_sys_t ); \
+    msg_Dbg( p_demux, msg ); \
+
+#define DEMUX_BY_EXTENSION( ext ) \
+    demux_t *p_demux = (demux_t *)p_this; \
+    if( !isExtension( p_demux, ext ) ) \
+        return VLC_EGENERIC; \
+    STANDARD_DEMUX_INIT;
+
+#define DEMUX_BY_EXTENSION_MSG( ext, msg ) \
+    demux_t *p_demux = (demux_t *)p_this; \
+    if( !isExtension( p_demux, ext ) ) \
+        return VLC_EGENERIC; \
+    STANDARD_DEMUX_INIT_MSG( msg );
+
+#define DEMUX_BY_EXTENSION_OR_FORCED( ext, module ) \
+    demux_t *p_demux = (demux_t *)p_this; \
+    if( !isExtension( p_demux, ext ) && !isDemux( p_demux, module ) ) \
+        return VLC_EGENERIC; \
+    STANDARD_DEMUX_INIT;
+
+#define DEMUX_BY_EXTENSION_OR_FORCED_MSG( ext, module, msg ) \
+    demux_t *p_demux = (demux_t *)p_this; \
+    if( !isExtension( p_demux, ext ) && !isDemux( p_demux, module ) ) \
+        return VLC_EGENERIC; \
+    STANDARD_DEMUX_INIT_MSG( msg );
+
+#define CHECK_PEEK( zepeek, size ) \
+    if( stream_Peek( p_demux->s , &zepeek, size ) < size ){ \
+        msg_Dbg( p_demux, "not enough data" ); return VLC_EGENERIC; }
+
+#define CHECK_PEEK_GOTO( zepeek, size ) \
+    if( stream_Peek( p_demux->s , &zepeek, size ) < size ) { \
+        msg_Dbg( p_demux, "not enough data" ); goto error; }
+
+#define CHECK_DISCARD_PEEK( size ) { uint8_t *p_peek; \
+    if( stream_Peek( p_demux->s , &p_peek, size ) < size ) return VLC_EGENERIC;}
+
+#define POKE( peek, stuff, size ) (strncasecmp( (char *)peek, stuff, size )==0)
+    
+
+#define CREATE_PACKETIZER( a,b,c,d ) \
+    p_sys->p_packetizer = vlc_object_create( p_demux, VLC_OBJECT_DECODER ); \
+    p_sys->p_packetizer->pf_decode_audio = 0; \
+    p_sys->p_packetizer->pf_decode_video = 0; \
+    p_sys->p_packetizer->pf_decode_sub = 0; \
+    p_sys->p_packetizer->pf_packetize = 0; \
+    es_format_Init( &p_sys->p_packetizer->fmt_in, AUDIO_ES, \
+                    VLC_FOURCC( a, b, c, d ) );
+
+/* BEWARE ! This can lead to memory leaks ! */
+#define LOAD_PACKETIZER_OR_FAIL( msg ) \
+    p_sys->p_packetizer->p_module = \
+        module_Need( p_sys->p_packetizer, "packetizer", NULL, 0 ); \
+    \
+    if( p_sys->p_packetizer->p_module == NULL ) \
+    { \
+        vlc_object_destroy( p_sys->p_packetizer ); \
+        msg_Err( p_demux, "cannot find packetizer for " # msg ); \
+        free( p_sys ); \
+        return VLC_EGENERIC; \
+    }
+
 /**
  * @}
  */
index 710d742..afbd669 100644 (file)
@@ -125,13 +125,7 @@ static int Open( vlc_object_t * p_this )
     }
 
     /* Have a peep at the show. */
-    if( stream_Peek( p_demux->s, &p_peek, i_peek + A52_MAX_HEADER_SIZE * 2 ) <
-        i_peek + A52_MAX_HEADER_SIZE * 2 )
-    {
-        /* Stream too short */
-        msg_Warn( p_demux, "cannot peek()" );
-        return VLC_EGENERIC;
-    }
+    CHECK_PEEK( p_peek, i_peek + A52_MAX_HEADER_SIZE * 2 );
 
     if( CheckSync( p_peek + i_peek, &b_big_endian ) != VLC_SUCCESS )
     {
@@ -146,16 +140,12 @@ static int Open( vlc_object_t * p_this )
     }
 
     /* Fill p_demux fields */
-    p_demux->pf_demux = Demux;
-    p_demux->pf_control = Control;
-    p_demux->p_sys = p_sys = malloc( sizeof( demux_sys_t ) );
+    STANDARD_DEMUX_INIT; p_sys = p_demux->p_sys;
     p_sys->b_start = VLC_TRUE;
     p_sys->i_mux_rate = 0;
     p_sys->b_big_endian = b_big_endian;
 
-    /*
-     * Load the A52 packetizer
-     */
+    /* Load the A52 packetizer */
     p_sys->p_packetizer = vlc_object_create( p_demux, VLC_OBJECT_DECODER );
     p_sys->p_packetizer->pf_decode_audio = 0;
     p_sys->p_packetizer->pf_decode_video = 0;
index c7fe525..724e21b 100644 (file)
@@ -113,10 +113,7 @@ static int Open( vlc_object_t *p_this )
     stream_Read( p_demux->s, NULL, 12 );
 
     /* Fill p_demux field */
-    p_demux->pf_demux = Demux;
-    p_demux->pf_control = Control;
-    p_demux->p_sys = p_sys = malloc( sizeof( demux_sys_t ) );
-
+    STANDARD_DEMUX_INIT; p_sys = p_demux->p_sys;
     es_format_Init( &p_sys->fmt, UNKNOWN_ES, 0 );
     p_sys->i_time = 1;
     p_sys->i_ssnd_pos = -1;
@@ -125,22 +122,14 @@ static int Open( vlc_object_t *p_this )
     {
         uint32_t i_size;
 
-        if( stream_Peek( p_demux->s, &p_peek, 8 ) < 8 )
-        {
-            msg_Dbg( p_demux, "cannot peek()" );
-            goto error;
-        }
+        CHECK_PEEK_GOTO( p_peek, 8 );
         i_size = GetDWBE( &p_peek[4] );
 
         msg_Dbg( p_demux, "chunk fcc=%4.4s size=%d", p_peek, i_size );
 
         if( !strncmp( (char *)&p_peek[0], "COMM", 4 ) )
         {
-            if( stream_Peek( p_demux->s, &p_peek, 18 + 8 ) < 18 + 8 )
-            {
-                msg_Dbg( p_demux, "cannot peek()" );
-                goto error;
-            }
+            CHECK_PEEK_GOTO( p_peek, 18+8 );
             es_format_Init( &p_sys->fmt, AUDIO_ES, VLC_FOURCC( 't', 'w', 'o', 's' ) );
             p_sys->fmt.audio.i_channels = GetWBE( &p_peek[8] );
             p_sys->fmt.audio.i_bitspersample = GetWBE( &p_peek[14] );
@@ -151,12 +140,7 @@ static int Open( vlc_object_t *p_this )
         }
         else if( !strncmp( (char *)&p_peek[0], "SSND", 4 ) )
         {
-            if( stream_Peek( p_demux->s, &p_peek, 8 + 8 ) < 8 + 8 )
-            {
-                msg_Dbg( p_demux, "cannot peek()" );
-                goto error;
-            }
-
+            CHECK_PEEK_GOTO( p_peek, 8+8 );
             p_sys->i_ssnd_pos = stream_Tell( p_demux->s );
             p_sys->i_ssnd_size = i_size;
             p_sys->i_ssnd_offset = GetDWBE( &p_peek[8] );
index cc40dcc..a275c2e 100644 (file)
@@ -89,7 +89,7 @@ struct demux_sys_t
     int             i_header_size;
 };
 
-static int DemuxPCM( demux_t * );
+static int Demux( demux_t * );
 static int Control ( demux_t *, int i_query, va_list args );
 
 /*****************************************************************************
@@ -105,7 +105,7 @@ static int Open( vlc_object_t *p_this )
     int          i_cat;
     int          i_samples, i_modulo;
 
-    if( stream_Peek( p_demux->s, &p_peek, 4 ) < 4 ) return VLC_EGENERIC;
+    CHECK_PEEK( p_peek, 4 );
 
     if( memcmp( p_peek, ".snd", 4 ) )
     {
@@ -128,7 +128,7 @@ static int Open( vlc_object_t *p_this )
         return VLC_EGENERIC;
     }
 
-    p_sys = p_demux->p_sys = malloc( sizeof( demux_sys_t ) );
+    STANDARD_DEMUX_INIT; p_sys = p_demux->p_sys;
     p_sys->i_time = 1;
     p_sys->i_header_size = GetDWBE( &hdr[0] );
 
@@ -276,19 +276,15 @@ static int Open( vlc_object_t *p_this )
                             (mtime_t)i_samples /
                             (mtime_t)p_sys->fmt.audio.i_rate;
 
-    /* finish to set up p_demux */
-    p_demux->pf_demux   = DemuxPCM;
-    p_demux->pf_control = Control;
-
     return VLC_SUCCESS;
 }
 
 /*****************************************************************************
- * DemuxPCM: read packet and send them to decoders
+ * Demux: read packet and send them to decoders
  *****************************************************************************
  * Returns -1 in case of error, 0 in case of EOF, 1 otherwise
  *****************************************************************************/
-static int DemuxPCM( demux_t *p_demux )
+static int Demux( demux_t *p_demux )
 {
     demux_sys_t *p_sys = p_demux->p_sys;
     block_t     *p_block;
index 01206f5..3954b70 100644 (file)
@@ -136,13 +136,7 @@ static int Open( vlc_object_t * p_this )
     }
 
     /* Have a peep at the show. */
-    if( stream_Peek( p_demux->s, &p_peek, i_peek + DTS_MAX_HEADER_SIZE * 2 ) <
-        i_peek + DTS_MAX_HEADER_SIZE * 2 )
-    {
-        /* Stream too short */
-        msg_Warn( p_demux, "cannot peek()" );
-        return VLC_EGENERIC;
-    }
+    CHECK_PEEK( p_peek, i_peek + DTS_MAX_HEADER_SIZE * 2  );
 
     if( CheckSync( p_peek + i_peek ) != VLC_SUCCESS )
     {
@@ -155,32 +149,10 @@ static int Open( vlc_object_t * p_this )
                  "continuing anyway" );
     }
 
-    p_demux->pf_demux = Demux;
-    p_demux->pf_control = Control;
-    p_demux->p_sys = p_sys = malloc( sizeof( demux_sys_t ) );
-    p_sys->b_start = VLC_TRUE;
-    p_sys->i_mux_rate = 0;
-
-    /*
-     * Load the DTS packetizer
-     */
-    p_sys->p_packetizer = vlc_object_create( p_demux, VLC_OBJECT_DECODER );
-    p_sys->p_packetizer->pf_decode_audio = 0;
-    p_sys->p_packetizer->pf_decode_video = 0;
-    p_sys->p_packetizer->pf_decode_sub = 0;
-    p_sys->p_packetizer->pf_packetize = 0;
-
-    /* Initialization of decoder structure */
-    es_format_Init( &p_sys->p_packetizer->fmt_in, AUDIO_ES,
-                    VLC_FOURCC( 'd', 't', 's', ' ' ) );
-
-    p_sys->p_packetizer->p_module =
-        module_Need( p_sys->p_packetizer, "packetizer", NULL, 0 );
-    if( !p_sys->p_packetizer->p_module )
-    {
-        msg_Err( p_demux, "cannot find DTS packetizer" );
-        return VLC_EGENERIC;
-    }
+    STANDARD_DEMUX_INIT; p_sys = p_demux->p_sys;
+   
+    INIT_PACKETIZER( 'd','t','s',' ' );
+    LOAD_PACKETIZER_OR_FAIL( "DTS" );
 
     p_sys->p_es = es_out_Add( p_demux->out, &p_sys->p_packetizer->fmt_in );
 
index 675fa32..4e73551 100644 (file)
@@ -86,7 +86,6 @@ static int StoreString( demux_t *p_demux, char **ppsz_string, char *psz_source_s
 int E_(Import_ASX)( vlc_object_t *p_this )
 {
     demux_t *p_demux = (demux_t *)p_this;
-    demux_sys_t *p_sys;
 
     char    *psz_ext;
 
@@ -95,7 +94,7 @@ int E_(Import_ASX)( vlc_object_t *p_this )
     if( ( psz_ext && !strcasecmp( psz_ext, ".asx") ) ||
         ( psz_ext && !strcasecmp( psz_ext, ".wax") ) ||
         ( psz_ext && !strcasecmp( psz_ext, ".wvx") ) ||
-        ( p_demux->psz_demux && !strcmp(p_demux->psz_demux, "asx-open") ) )
+        isDemux( p_demux, "asx-open" ) )
     {
         ;
     }
@@ -103,20 +102,11 @@ int E_(Import_ASX)( vlc_object_t *p_this )
     {
         return VLC_EGENERIC;
     }
-    msg_Dbg( p_demux, "using asx playlist import");
-
-    p_demux->pf_control = Control;
-    p_demux->pf_demux = Demux;
-    p_demux->p_sys = p_sys = malloc( sizeof(demux_sys_t) );
-    if( p_sys == NULL )
-    {
-        msg_Err( p_demux, "out of memory" );
-        return VLC_ENOMEM;
-    }
-    p_sys->psz_prefix = E_(FindPrefix)( p_demux );
-    p_sys->psz_data = NULL;
-    p_sys->i_data_len = -1;
-    p_sys->b_utf8 = VLC_FALSE;
+    STANDARD_DEMUX_INIT_MSG( "using ASX playlist reader" );
+    p_demux->p_sys->psz_prefix = E_(FindPrefix)( p_demux );
+    p_demux->p_sys->psz_data = NULL;
+    p_demux->p_sys->i_data_len = -1;
+    p_demux->p_sys->b_utf8 = VLC_FALSE;
     
     return VLC_SUCCESS;
 }
@@ -494,4 +484,4 @@ static int Demux( demux_t *p_demux )
 static int Control( demux_t *p_demux, int i_query, va_list args )
 {
     return VLC_EGENERIC;
-}
\ No newline at end of file
+}
index 30fc35b..e975bb0 100644 (file)
 /*****************************************************************************
  * Preamble
  *****************************************************************************/
-#include <stdlib.h>                                      /* malloc(), free() */
 #include <ctype.h>                                              /* isspace() */
 
 #include <vlc/vlc.h>
 #include <vlc/input.h>
 #include <vlc/intf.h>
 
-#include <errno.h>                                                 /* ENOMEM */
 #include "playlist.h"
 #include "vlc_xml.h"
 
@@ -55,36 +53,11 @@ static int IsWhitespace( char *psz_string );
  *****************************************************************************/
 int E_(Import_B4S)( vlc_object_t *p_this )
 {
-    demux_t *p_demux = (demux_t *)p_this;
-    demux_sys_t *p_sys;
-
-    char    *psz_ext;
-
-    psz_ext = strrchr ( p_demux->psz_path, '.' );
-
-    if( ( psz_ext && !strcasecmp( psz_ext, ".b4s") ) ||
-        ( p_demux->psz_demux && !strcmp(p_demux->psz_demux, "b4s-open") ) )
-    {
-        ;
-    }
-    else
-    {
-        return VLC_EGENERIC;
-    }
-    msg_Dbg( p_demux, "using b4s playlist import");
-
-    p_demux->pf_control = Control;
-    p_demux->pf_demux = Demux;
-    p_demux->p_sys = p_sys = malloc( sizeof(demux_sys_t) );
-    if( p_sys == NULL )
-    {
-        msg_Err( p_demux, "out of memory" );
-        return VLC_ENOMEM;
-    }
-    p_sys->psz_prefix = E_(FindPrefix)( p_demux );
-    p_sys->p_xml = NULL;
-    p_sys->p_xml_reader = NULL;
-
+    DEMUX_BY_EXTENSION_OR_FORCED_MSG( ".b4s", "b4s-open", 
+                                      "using B4S playlist reader" );
+    p_demux->p_sys->psz_prefix = E_(FindPrefix)( p_demux );
+    p_demux->p_sys->p_xml = NULL;
+    p_demux->p_sys->p_xml_reader = NULL;
     return VLC_SUCCESS;
 }
 
index 0be77b3..cc4d905 100644 (file)
@@ -24,8 +24,6 @@
 /*****************************************************************************
  * Preamble
  *****************************************************************************/
-#include <stdlib.h>                                      /* malloc(), free() */
-
 #include <vlc/vlc.h>
 #include <vlc/input.h>
 #include <vlc/intf.h>
@@ -54,13 +52,10 @@ int E_(Import_DVB)( vlc_object_t *p_this )
     demux_t *p_demux = (demux_t *)p_this;
     uint8_t *p_peek;
     int     i_peek;
-    char    *psz_ext;
     vlc_bool_t b_valid = VLC_FALSE;
 
-    psz_ext = strrchr ( p_demux->psz_path, '.' );
-
-    if( !( psz_ext && !strncasecmp( psz_ext, ".conf", 5 ) ) &&
-        !p_demux->b_force ) return VLC_EGENERIC;
+    if( !isExtension( p_demux, ".conf" ) && !p_demux->b_force )
+        return VLC_EGENERIC;
 
     /* Check if this really is a channels file */
     if( (i_peek = stream_Peek( p_demux->s, &p_peek, 1024 )) > 0 )
@@ -81,7 +76,6 @@ int E_(Import_DVB)( vlc_object_t *p_this )
     if( !b_valid ) return VLC_EGENERIC;
 
     msg_Dbg( p_demux, "found valid DVB conf playlist file");
-
     p_demux->pf_control = Control;
     p_demux->pf_demux = Demux;
 
index dda6b4b..348edcb 100644 (file)
@@ -37,8 +37,6 @@
 /*****************************************************************************
  * Preamble
  *****************************************************************************/
-#include <stdlib.h>                                      /* malloc(), free() */
-
 #include <vlc/vlc.h>
 #include <vlc/input.h>
 #include <vlc/intf.h>
@@ -68,7 +66,6 @@ static int Control( demux_t *p_demux, int i_query, va_list args );
 int E_(Import_GVP)( vlc_object_t *p_this )
 {
     demux_t *p_demux = (demux_t *)p_this;
-    demux_sys_t *p_sys;
 
     int i_size;
     byte_t *p_peek;
@@ -79,18 +76,11 @@ int E_(Import_GVP)( vlc_object_t *p_this )
         return VLC_EGENERIC;
     }
 
-    msg_Dbg( p_demux, "using Google Video Playlist (gvp) import");
-
+    STANDARD_DEMUX_INIT_MSG(  "using Google Video Playlist (gvp) import" )
     p_demux->pf_control = Control;
     p_demux->pf_demux = Demux;
-    p_demux->p_sys = p_sys = malloc( sizeof(demux_sys_t) );
-    if( p_sys == NULL )
-    {
-        msg_Err( p_demux, "out of memory" );
-        return VLC_ENOMEM;
-    }
-
-    p_sys->p_playlist = NULL;
+    MALLOC_ERR( p_demux->p_sys, demux_sys_t );
+    p_demux->p_sys->p_playlist = NULL;
 
     return VLC_SUCCESS;
 }
index d963b7d..237eb8a 100644 (file)
@@ -72,7 +72,7 @@ int E_(Import_M3U)( vlc_object_t *p_this )
              ( psz_ext && !strcasecmp( psz_ext, ".rm") ) ||
              ( psz_ext && !strcasecmp( psz_ext, ".vlc") ) ||
              /* A .ram file can contain a single rtsp link */
-             ( p_demux->psz_demux && !strcmp(p_demux->psz_demux, "m3u") ) )
+             isDemux( p_demux,  "m3u" ) )
     {
         ;
     }
@@ -80,16 +80,7 @@ int E_(Import_M3U)( vlc_object_t *p_this )
     {
         return VLC_EGENERIC;
     }
-    msg_Dbg( p_demux, "found valid M3U playlist file");
-
-    p_demux->pf_control = Control;
-    p_demux->pf_demux = Demux;
-    p_demux->p_sys = malloc( sizeof(demux_sys_t) );
-    if( p_demux->p_sys == NULL )
-    {
-        msg_Err( p_demux, "Out of memory" );
-        return VLC_ENOMEM;
-    }
+    STANDARD_DEMUX_INIT_MSG( "found valid M3U playlist" );
     p_demux->p_sys->psz_prefix = E_(FindPrefix)( p_demux );
 
     return VLC_SUCCESS;
index 62da136..2a76a9f 100644 (file)
 /*****************************************************************************
  * Preamble
  *****************************************************************************/
-#include <stdlib.h>                                      /* malloc(), free() */
-
 #include <vlc/vlc.h>
 #include <vlc/input.h>
 #include <vlc/intf.h>
 #include "charset.h"
 
-#include <errno.h>                                                 /* ENOMEM */
-
 #define PLAYLIST_FILE_HEADER "# vlc playlist file version 0.5"
 
 /*****************************************************************************
@@ -54,7 +50,6 @@ int E_(Import_Old)( vlc_object_t *p_this )
     if( strncmp( (char *)p_peek, PLAYLIST_FILE_HEADER , 31 ) ) return VLC_EGENERIC;
 
     msg_Dbg( p_demux, "found valid old playlist file");
-
     p_demux->pf_control = Control;
     p_demux->pf_demux = Demux;
 
index fecc704..799e824 100644 (file)
 /*****************************************************************************
  * Preamble
  *****************************************************************************/
-#include <stdlib.h>                                      /* malloc(), free() */
-
 #include <vlc/vlc.h>
 #include <vlc/input.h>
 #include <vlc/intf.h>
 
-#include <errno.h>                                                 /* ENOMEM */
 #include "playlist.h"
 
 struct demux_sys_t
@@ -51,34 +48,17 @@ static int Control( demux_t *p_demux, int i_query, va_list args );
 int E_(Import_PLS)( vlc_object_t *p_this )
 {
     demux_t *p_demux = (demux_t *)p_this;
-
     uint8_t *p_peek;
-    char    *psz_ext;
-
-    if( stream_Peek( p_demux->s , &p_peek, 7 ) < 7 ) return VLC_EGENERIC;
-    psz_ext = strrchr ( p_demux->psz_path, '.' );
+    CHECK_PEEK( p_peek, 7 );
 
-    if( !strncasecmp( (char *)p_peek, "[playlist]", 10 ) )
-    {
-        ;
-    }
-    else if( ( psz_ext && !strcasecmp( psz_ext, ".pls") ) ||
-             ( p_demux->psz_demux && !strcmp(p_demux->psz_demux, "pls") ) )
+    if( POKE( p_peek, "[playlist]", 10 ) ||
+        isExtension( p_demux, ".pls" )   || isDemux( p_demux, "pls" ) )
     {
         ;
     }
     else return VLC_EGENERIC;
 
-    msg_Dbg( p_demux, "found valid PLS playlist file");
-
-    p_demux->pf_control = Control;
-    p_demux->pf_demux = Demux;
-    p_demux->p_sys = malloc( sizeof(demux_sys_t) );
-    if( p_demux->p_sys == NULL )
-    {
-        msg_Err( p_demux, "out of memory" );
-        return VLC_ENOMEM;
-    }
+    STANDARD_DEMUX_INIT_MSG(  "found valid PLS playlist file");
     p_demux->p_sys->psz_prefix = E_(FindPrefix)( p_demux );
 
     return VLC_SUCCESS;
index 0681643..5afa5bc 100644 (file)
 /*****************************************************************************
  * Preamble
  *****************************************************************************/
-#include <stdlib.h>                                      /* malloc(), free() */
 #include <ctype.h>                                              /* isspace() */
 
 #include <vlc/vlc.h>
 #include <vlc/input.h>
 #include <vlc/intf.h>
 
-#include <errno.h>                                                 /* ENOMEM */
 #include "playlist.h"
 #include "vlc_xml.h"
 
@@ -55,34 +53,15 @@ static int Control( demux_t *p_demux, int i_query, va_list args );
 int E_(Import_podcast)( vlc_object_t *p_this )
 {
     demux_t *p_demux = (demux_t *)p_this;
-    demux_sys_t *p_sys;
 
-    char    *psz_ext;
-
-    psz_ext = strrchr ( p_demux->psz_path, '.' );
-
-    if( p_demux->psz_demux && !strcmp(p_demux->psz_demux, "podcast") )
-    {
-        ;
-    }
-    else
-    {
+    if( !isDemux( p_demux, "podcast" ) )
         return VLC_EGENERIC;
-    }
-    msg_Dbg( p_demux, "using podcast playlist import");
-
-    p_demux->pf_control = Control;
-    p_demux->pf_demux = Demux;
-    p_demux->p_sys = p_sys = malloc( sizeof(demux_sys_t) );
-    if( p_sys == NULL )
-    {
-        msg_Err( p_demux, "out of memory" );
-        return VLC_ENOMEM;
-    }
-    p_sys->psz_prefix = E_(FindPrefix)( p_demux );
-    p_sys->p_playlist = NULL;
-    p_sys->p_xml = NULL;
-    p_sys->p_xml_reader = NULL;
+    
+    STANDARD_DEMUX_INIT_MSG( "using podcast reader" );
+    p_demux->p_sys->psz_prefix = E_(FindPrefix)( p_demux );
+    p_demux->p_sys->p_playlist = NULL;
+    p_demux->p_sys->p_xml = NULL;
+    p_demux->p_sys->p_xml_reader = NULL;
 
     return VLC_SUCCESS;
 }
index e76b7e1..f92a62b 100644 (file)
@@ -47,14 +47,12 @@ volume - 0 (mute) - 100 (max)
 /*****************************************************************************
  * Preamble
  *****************************************************************************/
-#include <stdlib.h>                                      /* malloc(), free() */
 #include <ctype.h>                                              /* isspace() */
 
 #include <vlc/vlc.h>
 #include <vlc/input.h>
 #include <vlc/intf.h>
 
-#include <errno.h>                                                 /* ENOMEM */
 #include "playlist.h"
 #include "vlc_xml.h"
 
@@ -91,32 +89,10 @@ static int Control( demux_t *p_demux, int i_query, va_list args );
  *****************************************************************************/
 int E_(Import_QTL)( vlc_object_t *p_this )
 {
-    demux_t *p_demux = (demux_t *)p_this;
-    demux_sys_t *p_sys;
-
-    char    *psz_ext;
-
-    psz_ext = strrchr ( p_demux->psz_path, '.' );
-
-    if( strcmp( psz_ext, ".qtl" ) )
-    {
-        return VLC_EGENERIC;
-    }
-    msg_Dbg( p_demux, "using QuickTime Media Link playlist import");
-
-    p_demux->pf_control = Control;
-    p_demux->pf_demux = Demux;
-    p_demux->p_sys = p_sys = malloc( sizeof(demux_sys_t) );
-    if( p_sys == NULL )
-    {
-        msg_Err( p_demux, "out of memory" );
-        return VLC_ENOMEM;
-    }
-
-    p_sys->p_playlist = NULL;
-    p_sys->p_xml = NULL;
-    p_sys->p_xml_reader = NULL;
-
+    DEMUX_BY_EXTENSION_MSG( ".qtl", "using QuickTime Media Link reader" );
+    p_demux->p_sys->p_playlist = NULL;
+    p_demux->p_sys->p_xml = NULL;
+    p_demux->p_sys->p_xml_reader = NULL;
     return VLC_SUCCESS;
 }
 
index 7d2d814..d8c3211 100644 (file)
@@ -135,7 +135,6 @@ static int Control( demux_t *p_demux, int i_query, va_list args );
 int E_(Import_SGIMB)( vlc_object_t * p_this )
 {
     demux_t *p_demux = (demux_t *)p_this;
-    demux_sys_t *p_sys;
     byte_t *p_peek;
     int i_size;
 
@@ -152,27 +151,22 @@ int E_(Import_SGIMB)( vlc_object_t * p_this )
         }
         if ( !strncasecmp( (char *)p_peek, "sgiNameServerHost=", i_len ) )
         {
-            p_demux->pf_demux = Demux;
-            p_demux->pf_control = Control;
-
-            p_demux->p_sys = p_sys = malloc( sizeof( demux_sys_t ) );
-            p_sys->psz_uri = NULL;
-            p_sys->psz_server = NULL;
-            p_sys->psz_location = NULL;
-            p_sys->psz_name = NULL;
-            p_sys->psz_user = NULL;
-            p_sys->psz_password = NULL;
-            p_sys->psz_mcast_ip = NULL;
-            p_sys->i_mcast_port = 0;
-            p_sys->i_packet_size = 0;
-            p_sys->i_duration = 0;
-            p_sys->i_port = 0;
-            p_sys->i_sid = 0;
-            p_sys->b_rtsp_kasenna = VLC_FALSE;
-            p_sys->b_concert = VLC_FALSE;
+            STANDARD_DEMUX_INIT_MSG( "using SGIMB playlist reader" );
+            p_demux->p_sys->psz_uri = NULL;
+            p_demux->p_sys->psz_server = NULL;
+            p_demux->p_sys->psz_location = NULL;
+            p_demux->p_sys->psz_name = NULL;
+            p_demux->p_sys->psz_user = NULL;
+            p_demux->p_sys->psz_password = NULL;
+            p_demux->p_sys->psz_mcast_ip = NULL;
+            p_demux->p_sys->i_mcast_port = 0;
+            p_demux->p_sys->i_packet_size = 0;
+            p_demux->p_sys->i_duration = 0;
+            p_demux->p_sys->i_port = 0;
+            p_demux->p_sys->i_sid = 0;
+            p_demux->p_sys->b_rtsp_kasenna = VLC_FALSE;
+            p_demux->p_sys->b_concert = VLC_FALSE;
             
-            msg_Dbg( p_demux, "using sgimb playlist import");
-
             return VLC_SUCCESS;
         }
     }
index 56d8596..da6385b 100644 (file)
@@ -25,7 +25,6 @@
 /*****************************************************************************
  * Preamble
  *****************************************************************************/
-#include <stdlib.h>                                      /* malloc(), free() */
 #include <ctype.h>                                              /* isspace() */
 
 #include <vlc/vlc.h>
@@ -69,35 +68,19 @@ static int DemuxStation( demux_t *p_demux );
 int E_(Import_Shoutcast)( vlc_object_t *p_this )
 {
     demux_t *p_demux = (demux_t *)p_this;
-    demux_sys_t *p_sys;
 
-    char    *psz_ext;
-
-    psz_ext = strrchr ( p_demux->psz_path, '.' );
-
-    if( !p_demux->psz_demux || strcmp(p_demux->psz_demux, "shout-winamp") )
-    {
+    if( !isDemux( p_demux, "shout-winamp" ) )
         return VLC_EGENERIC;
-    }
-    msg_Dbg( p_demux, "using shoutcast playlist import");
-
-    p_demux->pf_control = Control;
-    p_demux->pf_demux = Demux;
-    p_demux->p_sys = p_sys = malloc( sizeof(demux_sys_t) );
-    if( p_sys == NULL )
-    {
-        msg_Err( p_demux, "out of memory" );
-        return VLC_ENOMEM;
-    }
-
-    p_sys->p_playlist = NULL;
-    p_sys->p_xml = NULL;
-    p_sys->p_xml_reader = NULL;
+    
+    STANDARD_DEMUX_INIT_MSG( "using shoutcast playlist reader" );
+    p_demux->p_sys->p_playlist = NULL;
+    p_demux->p_sys->p_xml = NULL;
+    p_demux->p_sys->p_xml_reader = NULL;
 
     /* Do we want to list adult content ? */
     var_Create( p_demux, "shoutcast-show-adult",
                 VLC_VAR_BOOL | VLC_VAR_DOINHERIT );
-    p_sys->b_adult = var_GetBool( p_demux, "shoutcast-show-adult" );
+    p_demux->p_sys->b_adult = var_GetBool( p_demux, "shoutcast-show-adult" );
 
     return VLC_SUCCESS;
 }
index 172d2c5..196f50f 100644 (file)
@@ -44,39 +44,23 @@ struct demux_sys_t
     int i_identifier;
 };
 
+static int Control( demux_t *, int, va_list );
+static int Demux( demux_t * );
+
 /**
  * \brief XSPF submodule initialization function
  */
 int E_(xspf_import_Activate)( vlc_object_t *p_this )
 {
-    demux_t *p_demux = (demux_t *)p_this;
-    char    *psz_ext;
-
-    psz_ext = strrchr( p_demux->psz_path, '.' );
-
-    if( ( psz_ext && !strcasecmp( psz_ext, ".xspf") ) ||
-        ( p_demux->psz_demux && !strcmp(p_demux->psz_demux, "xspf-open") ) )
-    {
-        ;
-    }
-    else
-    {
-        return VLC_EGENERIC;
-    }
-    msg_Dbg( p_demux, "using xspf playlist import");
-
-    p_demux->p_sys = (demux_sys_t*)malloc(sizeof(demux_sys_t ) );
-
-    p_demux->pf_control = xspf_import_Control;
-    p_demux->pf_demux = xspf_import_Demux;
-
+    DEMUX_BY_EXTENSION_OR_FORCED_MSG( ".xspf", "xspf-open", 
+                                      "using XSPF playlist reader" );
     return VLC_SUCCESS;
 }
 
 /**
  * \brief demuxer function for XSPF parsing
  */
-int xspf_import_Demux( demux_t *p_demux )
+int Demux( demux_t *p_demux )
 {
     int i_ret = VLC_SUCCESS;
     xml_t *p_xml = NULL;
@@ -138,7 +122,7 @@ int xspf_import_Demux( demux_t *p_demux )
 }
 
 /** \brief dummy function for demux callback interface */
-int xspf_import_Control( demux_t *p_demux, int i_query, va_list args )
+static int Control( demux_t *p_demux, int i_query, va_list args )
 {
     return VLC_EGENERIC;
 }
index a311fd8..04dbbbc 100644 (file)
@@ -41,9 +41,6 @@
                            const char      *psz_element)
 
 /* prototypes */
-int xspf_import_Demux( demux_t *);
-int xspf_import_Control( demux_t *, int, va_list );
-
 static vlc_bool_t parse_playlist_node COMPLEX_INTERFACE;
 static vlc_bool_t parse_tracklist_node COMPLEX_INTERFACE;
 static vlc_bool_t parse_track_node COMPLEX_INTERFACE;
index 5911239..61a61e4 100644 (file)
@@ -76,9 +76,7 @@ playlist_item_t *__playlist_ItemNewFromInput( vlc_object_t *p_obj,
 {
     /** FIXME !!!!! don't find playlist each time */
     playlist_t *p_playlist = (playlist_t *)vlc_object_find( p_obj, VLC_OBJECT_PLAYLIST, FIND_ANYWHERE );
-    playlist_item_t * p_item;
-    p_item = malloc( sizeof( playlist_item_t ) );
-    if( p_item == NULL ) return NULL;
+    DECMALLOC_NULL( p_item, playlist_item_t );
 
     p_item->p_input = p_input;
     vlc_gc_incref( p_item->p_input );