]> git.sesse.net Git - vlc/commitdiff
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 f2da04aa0a577de982be9a343bad05702531bab6..7d0090af458a2a45e1ecbeed040db6eff6d9c56e 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 52bfccacc2974a5d6cf9ea532b4517e8476afd9a..d4e6e0fd4f17216a28ff113058065317305737e8 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 710d74216198c0945a45497f12ab6e34fa1e95b5..afbd66931b7f94f85a2c94c83bce6a4677d2d1a8 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 c7fe525e375ea7ca01be31b7c7548cce7956f3d9..724e21b732f1c6e8ab8be5397e691023e0fa461d 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 cc40dcc88328cedb89225f63698f8c3d94df5301..a275c2e7da20737997ef39ea483177e70cf8249c 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 01206f5b251d5561d4480d8d27ebcb897b46987f..3954b700eb83e555b859388fb164113a1c1430c2 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 675fa32ae564b1029b94ac797e15d6b463ebb08a..4e73551efb2120938b68cd5b23aca6c1c5f9890b 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 30fc35bf3db324abb490d04a60e0faf37e6ac98a..e975bb04f8f61d6d07e27c442c24ecbb1ba1d31a 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 0be77b3016d86e97a99dea9cb693df5664da3428..cc4d90511bf225c2a2d77bb30cee31d0c347c6c4 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 dda6b4bd16ae735f43faeaf0ef3d6ffea9831756..348edcb1e0cc5b087c5285235739868455170630 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 d963b7d3b9569e3f73d8db135fa6014e41d6699b..237eb8a2febd1f645aa50e1913bd7c64f6b2906b 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 62da1368b52a71082c558f3e2ae4649d7eb9d143..2a76a9fcaa7a15b18f923ac8ab794b292c6bb854 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 fecc7048129c951505b5cf0c98d7dc7e169005ea..799e824356226b243a5865a2be0d9b9c7cc05a1b 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 06816437513eeaa4afcc8ae521587d57c0effc0d..5afa5bc52c1bed8f5f59e957adfbeade64862be0 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 e76b7e1e067365304afefaeb2e504a508c48aace..f92a62b2b21238866d38d87d762eef35581319b7 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 7d2d8146542569ea8b53fd26f9d70a3ccb070005..d8c3211e7e9b04a6295267ea14a2431b84891c34 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 56d85961f277ff55724a53f0cf54587beb85c6a1..da6385bc231cd9710fe9b95558e1f0f744d95abc 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 172d2c5ae5e25f29f79b37b389f9a3d9d8983b49..196f50fe53a9c5b2fa940a8c47003a00b5c4ab24 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 a311fd89a8435176758c5f59a90ea718b9c813b3..04dbbbc5359bc33e8a1b4ef64215eb795e72492d 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 591123984e63023e30f11986b2b32a7af39bd18f..61a61e439c96c97ee687c681a9ee6ed924c5f398 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 );