From 9e0f68a30db55e542ac294e742d176d11aa5d4ab Mon Sep 17 00:00:00 2001 From: Laurent Aimar Date: Fri, 21 Nov 2008 19:54:23 +0100 Subject: [PATCH] Removed unneeded macros. --- include/vlc_demux.h | 38 ---------------------- modules/demux/aiff.c | 15 ++++++--- modules/demux/au.c | 5 ++- modules/demux/mpc.c | 52 ++++++++++++++++--------------- modules/demux/playlist/playlist.h | 25 +++++++++++++++ modules/demux/tta.c | 5 +-- 6 files changed, 67 insertions(+), 73 deletions(-) diff --git a/include/vlc_demux.h b/include/vlc_demux.h index cd70b4bf85..bc6caff60f 100644 --- a/include/vlc_demux.h +++ b/include/vlc_demux.h @@ -196,44 +196,6 @@ VLC_EXPORT( void, demux_PacketizerDestroy, ( decoder_t *p_packetizer ) ); if( !p_demux->p_sys ) return VLC_ENOMEM;\ memset( p_demux->p_sys, 0, sizeof( demux_sys_t ) ); } while(0) -#define STANDARD_DEMUX_INIT_MSG( msg ) do { \ - DEMUX_INIT_COMMON(); \ - msg_Dbg( p_demux, "%s", msg ); } while(0) - -#define DEMUX_BY_EXTENSION( ext ) \ - demux_t *p_demux = (demux_t *)p_this; \ - if( !demux_IsPathExtension( p_demux, ext ) ) \ - return VLC_EGENERIC; \ - DEMUX_INIT_COMMON(); - -#define DEMUX_BY_EXTENSION_MSG( ext, msg ) \ - demux_t *p_demux = (demux_t *)p_this; \ - if( !demux_IsPathExtension( 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( !demux_IsPathExtension( p_demux, ext ) && !demux_IsForced( p_demux, module ) ) \ - return VLC_EGENERIC; \ - DEMUX_INIT_COMMON(); - -#define DEMUX_BY_EXTENSION_OR_FORCED_MSG( ext, module, msg ) \ - demux_t *p_demux = (demux_t *)p_this; \ - if( !demux_IsPathExtension( p_demux, ext ) && !demux_IsForced( 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 POKE( peek, stuff, size ) (strncasecmp( (const char *)peek, stuff, size )==0) - /** * @} */ diff --git a/modules/demux/aiff.c b/modules/demux/aiff.c index 186606713b..cfc4b1659c 100644 --- a/modules/demux/aiff.c +++ b/modules/demux/aiff.c @@ -109,8 +109,7 @@ static int Open( vlc_object_t *p_this ) if( stream_Peek( p_demux->s, &p_peek, 12 ) < 12 ) return VLC_EGENERIC; - if( memcmp( p_peek, "FORM", 4 ) - || memcmp( &p_peek[8], "AIFF", 4 ) ) + if( memcmp( p_peek, "FORM", 4 ) || memcmp( &p_peek[8], "AIFF", 4 ) ) return VLC_EGENERIC; /* skip aiff header */ @@ -126,14 +125,18 @@ static int Open( vlc_object_t *p_this ) { uint32_t i_size; - CHECK_PEEK_GOTO( p_peek, 8 ); + if( stream_Peek( p_demux->s, &p_peek, 8 ) < 8 ) + goto error; + i_size = GetDWBE( &p_peek[4] ); msg_Dbg( p_demux, "chunk fcc=%4.4s size=%d", p_peek, i_size ); if( !memcmp( p_peek, "COMM", 4 ) ) { - CHECK_PEEK_GOTO( p_peek, 18+8 ); + if( stream_Peek( p_demux->s, &p_peek, 18+8 ) < 18+8 ) + goto error; + 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] ); @@ -144,7 +147,9 @@ static int Open( vlc_object_t *p_this ) } else if( !memcmp( p_peek, "SSND", 4 ) ) { - CHECK_PEEK_GOTO( p_peek, 8+8 ); + if( stream_Peek( p_demux->s, &p_peek, 8+8 ) < 8+8 ) + goto error; + 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] ); diff --git a/modules/demux/au.c b/modules/demux/au.c index 87fb9e4237..08f7e98641 100644 --- a/modules/demux/au.c +++ b/modules/demux/au.c @@ -109,12 +109,11 @@ static int Open( vlc_object_t *p_this ) int i_cat; int i_samples, i_modulo; - CHECK_PEEK( p_peek, 4 ); + if( stream_Peek( p_demux->s , &p_peek, 4 ) < 4 ) + return VLC_EGENERIC; if( memcmp( p_peek, ".snd", 4 ) ) - { return VLC_EGENERIC; - } /* skip signature */ stream_Read( p_demux->s, NULL, 4 ); /* cannot fail */ diff --git a/modules/demux/mpc.c b/modules/demux/mpc.c index d0a9d931f9..b02e4cdf51 100644 --- a/modules/demux/mpc.c +++ b/modules/demux/mpc.c @@ -71,7 +71,7 @@ static int Control( demux_t *, int, va_list ); struct demux_sys_t { /* */ - es_out_id_t *p_es; + es_out_id_t *p_es; /* */ mpc_decoder decoder; @@ -82,11 +82,11 @@ struct demux_sys_t int64_t i_position; }; -mpc_int32_t ReaderRead( void *p_private, void *dst, mpc_int32_t i_size ); -mpc_bool_t ReaderSeek( void *p_private, mpc_int32_t i_offset ); -mpc_int32_t ReaderTell( void *p_private); -mpc_int32_t ReaderGetSize( void *p_private ); -mpc_bool_t ReaderCanSeek( void *p_private ); +static mpc_int32_t ReaderRead( void *p_private, void *dst, mpc_int32_t i_size ); +static mpc_bool_t ReaderSeek( void *p_private, mpc_int32_t i_offset ); +static mpc_int32_t ReaderTell( void *p_private); +static mpc_int32_t ReaderGetSize( void *p_private ); +static mpc_bool_t ReaderCanSeek( void *p_private ); /***************************************************************************** * Open: initializes ES structures @@ -120,8 +120,9 @@ static int Open( vlc_object_t * p_this ) } /* */ - p_sys = malloc( sizeof( demux_sys_t ) ); - memset( p_sys, 0, sizeof(demux_sys_t) ); + p_sys = calloc( 1, sizeof( *p_sys ) ); + if( !p_sys ) + return VLC_ENOMEM; p_sys->i_position = 0; @@ -135,20 +136,12 @@ static int Open( vlc_object_t * p_this ) /* Load info */ mpc_streaminfo_init( &p_sys->info ); if( mpc_streaminfo_read( &p_sys->info, &p_sys->reader ) != ERROR_CODE_OK ) - { - /* invalid file */ - free( p_sys ); - return VLC_EGENERIC; - } + goto error; /* */ mpc_decoder_setup( &p_sys->decoder, &p_sys->reader ); if( !mpc_decoder_initialize( &p_sys->decoder, &p_sys->info ) ) - { - /* */ - free( p_sys ); - return VLC_EGENERIC; - } + goto error; /* Fill p_demux fields */ p_demux->pf_demux = Demux; @@ -187,8 +180,14 @@ static int Open( vlc_object_t * p_this ) } p_sys->p_es = es_out_Add( p_demux->out, &fmt ); + if( !p_sys->p_es ) + goto error; return VLC_SUCCESS; + +error: + free( p_sys ); + return VLC_EGENERIC; } /***************************************************************************** @@ -215,9 +214,12 @@ static int Demux( demux_t *p_demux ) p_data = block_New( p_demux, MPC_DECODER_BUFFER_LENGTH*sizeof(MPC_SAMPLE_FORMAT) ); + if( !p_data ) + return -1; + i_ret = mpc_decoder_decode( &p_sys->decoder, - (MPC_SAMPLE_FORMAT*)p_data->p_buffer, - NULL, NULL ); + (MPC_SAMPLE_FORMAT*)p_data->p_buffer, + NULL, NULL ); if( i_ret <= 0 ) { block_Release( p_data ); @@ -301,31 +303,31 @@ static int Control( demux_t *p_demux, int i_query, va_list args ) } } -mpc_int32_t ReaderRead( void *p_private, void *dst, mpc_int32_t i_size ) +static mpc_int32_t ReaderRead( void *p_private, void *dst, mpc_int32_t i_size ) { demux_t *p_demux = (demux_t*)p_private; return stream_Read( p_demux->s, dst, i_size ); } -mpc_bool_t ReaderSeek( void *p_private, mpc_int32_t i_offset ) +static mpc_bool_t ReaderSeek( void *p_private, mpc_int32_t i_offset ) { demux_t *p_demux = (demux_t*)p_private; return !stream_Seek( p_demux->s, i_offset ); } -mpc_int32_t ReaderTell( void *p_private) +static mpc_int32_t ReaderTell( void *p_private) { demux_t *p_demux = (demux_t*)p_private; return stream_Tell( p_demux->s ); } -mpc_int32_t ReaderGetSize( void *p_private ) +static mpc_int32_t ReaderGetSize( void *p_private ) { demux_t *p_demux = (demux_t*)p_private; return stream_Size( p_demux->s ); } -mpc_bool_t ReaderCanSeek( void *p_private ) +static mpc_bool_t ReaderCanSeek( void *p_private ) { demux_t *p_demux = (demux_t*)p_private; bool b_canseek; diff --git a/modules/demux/playlist/playlist.h b/modules/demux/playlist/playlist.h index ee27e2720b..bfa0666db7 100644 --- a/modules/demux/playlist/playlist.h +++ b/modules/demux/playlist/playlist.h @@ -79,3 +79,28 @@ void Close_iTML ( vlc_object_t * ); #define HANDLE_PLAY_AND_RELEASE \ vlc_object_release( p_input_thread ); + + +#define STANDARD_DEMUX_INIT_MSG( msg ) do { \ + DEMUX_INIT_COMMON(); \ + msg_Dbg( p_demux, "%s", msg ); } while(0) + +#define DEMUX_BY_EXTENSION_MSG( ext, msg ) \ + demux_t *p_demux = (demux_t *)p_this; \ + if( !demux_IsPathExtension( p_demux, ext ) ) \ + return VLC_EGENERIC; \ + STANDARD_DEMUX_INIT_MSG( msg ); + +#define DEMUX_BY_EXTENSION_OR_FORCED_MSG( ext, module, msg ) \ + demux_t *p_demux = (demux_t *)p_this; \ + if( !demux_IsPathExtension( p_demux, ext ) && !demux_IsForced( p_demux, module ) ) \ + return VLC_EGENERIC; \ + STANDARD_DEMUX_INIT_MSG( msg ); + + +#define CHECK_PEEK( zepeek, size ) do { \ + if( stream_Peek( p_demux->s , &zepeek, size ) < size ){ \ + msg_Dbg( p_demux, "not enough data" ); return VLC_EGENERIC; } } while(0) + +#define POKE( peek, stuff, size ) (strncasecmp( (const char *)peek, stuff, size )==0) + diff --git a/modules/demux/tta.c b/modules/demux/tta.c index 3f295c92ea..0922f38953 100644 --- a/modules/demux/tta.c +++ b/modules/demux/tta.c @@ -94,9 +94,10 @@ static int Open( vlc_object_t * p_this ) if( stream_Peek( p_demux->s, &p_peek, 4 ) < 4 ) return VLC_EGENERIC; - if( !POKE( p_peek, "TTA1", 4 ) ) + if( memcmp( p_peek, "TTA1", 4 ) ) { - if( !p_demux->b_force ) return VLC_EGENERIC; + if( !p_demux->b_force ) + return VLC_EGENERIC; /* User forced */ msg_Err( p_demux, "this doesn't look like a true-audio stream, " -- 2.39.2