]> git.sesse.net Git - vlc/commitdiff
Better packetizer helpers
authorClément Stenac <zorglub@videolan.org>
Tue, 18 Jul 2006 17:19:10 +0000 (17:19 +0000)
committerClément Stenac <zorglub@videolan.org>
Tue, 18 Jul 2006 17:19:10 +0000 (17:19 +0000)
include/vlc_demux.h
modules/demux/a52.c
modules/demux/dts.c
modules/demux/flac.c
modules/demux/mpeg/m4a.c
modules/demux/mpeg/mpgv.c

index d4e6e0fd4f17216a28ff113058065317305737e8..085f08e6ed2064457b9cb60e145db789e9bddc58 100644 (file)
@@ -199,25 +199,31 @@ static inline vlc_bool_t isDemux( demux_t *p_demux, char *psz_requested )
     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, \
+
+#define COMMON_INIT_PACKETIZER( location ) \
+    location = vlc_object_create( p_demux, VLC_OBJECT_DECODER ); \
+    location->pf_decode_audio = 0; \
+    location->pf_decode_video = 0; \
+    location->pf_decode_sub = 0; \
+    location->pf_packetize = 0; \
+
+#define INIT_APACKETIZER( location, a,b,c,d ) \
+    COMMON_INIT_PACKETIZER(location ); \
+    es_format_Init( &location->fmt_in, AUDIO_ES, \
+                    VLC_FOURCC( a, b, c, d ) );
+
+#define INIT_VPACKETIZER( location, a,b,c,d ) \
+    COMMON_INIT_PACKETIZER(location ); \
+    es_format_Init( &location->fmt_in, VIDEO_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 ) \
+#define LOAD_PACKETIZER_OR_FAIL( location, msg ) \
+    location->p_module = \
+        module_Need( location, "packetizer", NULL, 0 ); \
+    if( location->p_module == NULL ) \
     { \
-        vlc_object_destroy( p_sys->p_packetizer ); \
+        vlc_object_destroy( location ); \
         msg_Err( p_demux, "cannot find packetizer for " # msg ); \
         free( p_sys ); \
         return VLC_EGENERIC; \
index afbd66931b7f94f85a2c94c83bce6a4677d2d1a8..fe1d013295b11b6a1e95d7f1f21bbaa005f5b8d0 100644 (file)
@@ -146,23 +146,8 @@ static int Open( vlc_object_t * p_this )
     p_sys->b_big_endian = b_big_endian;
 
     /* 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;
-    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( 'a', '5', '2', ' ' ) );
-
-    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 A52 packetizer" );
-        return VLC_EGENERIC;
-    }
+    INIT_APACKETIZER( p_sys->p_packetizer, 'a', '5', '2', ' ' );
+    LOAD_PACKETIZER_OR_FAIL( p_sys->p_packetizer, "A52" );
 
     /* Create one program */
     p_sys->p_es = es_out_Add( p_demux->out, &p_sys->p_packetizer->fmt_in );
index 3954b700eb83e555b859388fb164113a1c1430c2..8e6fb8045f69360502439b336c708035a53be3f1 100644 (file)
@@ -151,8 +151,8 @@ static int Open( vlc_object_t * p_this )
 
     STANDARD_DEMUX_INIT; p_sys = p_demux->p_sys;
    
-    INIT_PACKETIZER( 'd','t','s',' ' );
-    LOAD_PACKETIZER_OR_FAIL( "DTS" );
+    INIT_APACKETIZER( p_sys->p_packetizer, 'd','t','s',' ' );
+    LOAD_PACKETIZER_OR_FAIL( p_sys->p_packetizer, "DTS" );
 
     p_sys->p_es = es_out_Add( p_demux->out, &p_sys->p_packetizer->fmt_in );
 
index 64f302f9c57c8402ecf71cc6669b7068cdb4e7e9..ef8907475e00df08e692439e4de0860002bb667e 100644 (file)
@@ -107,18 +107,8 @@ static int Open( vlc_object_t * p_this )
         return VLC_EGENERIC;
     }
 
-    /*
-     * Load the FLAC 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( 'f', 'l', 'a', 'c' ) );
+    /* Load the FLAC packetizer */
+    INIT_APACKETIZER( p_sys->p_packetizer, 'f', 'l', 'a', 'c' );
 
     /* Store STREAMINFO for the decoder and packetizer */
     p_sys->p_packetizer->fmt_in.i_extra = fmt.i_extra = STREAMINFO_SIZE + 4;
index 8f0426f6babeacf1263e3324203769093c400eaf..00ad088817665b36c384f1718ba711da90767acc 100644 (file)
@@ -106,27 +106,10 @@ static int Open( vlc_object_t * p_this )
     p_sys->p_es        = NULL;
     p_sys->b_start     = VLC_TRUE;
 
-    /*
-     * Load the mpeg 4 audio packetizer
-     */
-    p_sys->p_packetizer = vlc_object_create( p_demux, VLC_OBJECT_PACKETIZER );
-    p_sys->p_packetizer->pf_decode_audio = NULL;
-    p_sys->p_packetizer->pf_decode_video = NULL;
-    p_sys->p_packetizer->pf_decode_sub = NULL;
-    p_sys->p_packetizer->pf_packetize = NULL;
-    es_format_Init( &p_sys->p_packetizer->fmt_in, AUDIO_ES,
-                    VLC_FOURCC( 'm', 'p', '4', 'a' ) );
+    /* Load the mpeg 4 audio packetizer */
+    INIT_APACKETIZER( p_sys->p_packetizer,  'm', 'p', '4', 'a'  );
     es_format_Init( &p_sys->p_packetizer->fmt_out, UNKNOWN_ES, 0 );
-    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 mp4a packetizer" );
-        free( p_sys );
-        return VLC_EGENERIC;
-    }
+    LOAD_PACKETIZER_OR_FAIL( p_sys->p_packetizer, "mp4 audio" );
 
     return VLC_SUCCESS;
 }
index 809bd9fde9e0da42071a3816d623febfe2065c0e..7a3c4ca3489a930f39a25ecbbbdda01facd27da5 100644 (file)
@@ -105,31 +105,12 @@ static int Open( vlc_object_t * p_this )
     p_sys->b_start     = VLC_TRUE;
     p_sys->p_es        = NULL;
 
-    /*
-     * Load the mpegvideo packetizer
-     */
-    p_sys->p_packetizer = vlc_object_create( p_demux, VLC_OBJECT_PACKETIZER );
-    p_sys->p_packetizer->pf_decode_audio = NULL;
-    p_sys->p_packetizer->pf_decode_video = NULL;
-    p_sys->p_packetizer->pf_decode_sub = NULL;
-    p_sys->p_packetizer->pf_packetize = NULL;
-    es_format_Init( &p_sys->p_packetizer->fmt_in, VIDEO_ES,
-                    VLC_FOURCC( 'm', 'p', 'g', 'v' ) );
+    /* Load the mpegvideo packetizer */
+    INIT_VPACKETIZER( p_sys->p_packetizer,  'm', 'p', 'g', 'v' );
     es_format_Init( &p_sys->p_packetizer->fmt_out, UNKNOWN_ES, 0 );
-    p_sys->p_packetizer->p_module =
-        module_Need( p_sys->p_packetizer, "packetizer", NULL, 0 );
+    LOAD_PACKETIZER_OR_FAIL( p_sys->p_packetizer, "MPEG Video" );
 
-    if( p_sys->p_packetizer->p_module == NULL)
-    {
-        vlc_object_destroy( p_sys->p_packetizer );
-        msg_Err( p_demux, "cannot find mpgv packetizer" );
-        free( p_sys );
-        return VLC_EGENERIC;
-    }
-
-    /*
-     * create the output
-     */
+    /* create the output */
     es_format_Init( &fmt, VIDEO_ES, VLC_FOURCC( 'm', 'p', 'g', 'v' ) );
     p_sys->p_es = es_out_Add( p_demux->out, &fmt );