From: Clément Stenac Date: Tue, 18 Jul 2006 17:19:10 +0000 (+0000) Subject: Better packetizer helpers X-Git-Tag: 0.9.0-test0~10834 X-Git-Url: https://git.sesse.net/?a=commitdiff_plain;h=f6ef9859ac452f74c2303ac999eddc7be33bf60b;p=vlc Better packetizer helpers --- diff --git a/include/vlc_demux.h b/include/vlc_demux.h index d4e6e0fd4f..085f08e6ed 100644 --- a/include/vlc_demux.h +++ b/include/vlc_demux.h @@ -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; \ diff --git a/modules/demux/a52.c b/modules/demux/a52.c index afbd66931b..fe1d013295 100644 --- a/modules/demux/a52.c +++ b/modules/demux/a52.c @@ -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 ); diff --git a/modules/demux/dts.c b/modules/demux/dts.c index 3954b700eb..8e6fb8045f 100644 --- a/modules/demux/dts.c +++ b/modules/demux/dts.c @@ -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 ); diff --git a/modules/demux/flac.c b/modules/demux/flac.c index 64f302f9c5..ef8907475e 100644 --- a/modules/demux/flac.c +++ b/modules/demux/flac.c @@ -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; diff --git a/modules/demux/mpeg/m4a.c b/modules/demux/mpeg/m4a.c index 8f0426f6ba..00ad088817 100644 --- a/modules/demux/mpeg/m4a.c +++ b/modules/demux/mpeg/m4a.c @@ -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; } diff --git a/modules/demux/mpeg/mpgv.c b/modules/demux/mpeg/mpgv.c index 809bd9fde9..7a3c4ca348 100644 --- a/modules/demux/mpeg/mpgv.c +++ b/modules/demux/mpeg/mpgv.c @@ -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 );