X-Git-Url: https://git.sesse.net/?a=blobdiff_plain;f=modules%2Fdemux%2Faiff.c;h=8a7dd28b1828ae798395f79e167c7a09a56ef90b;hb=50f7a078c47c0118426d348f1011bb1c4e5defcc;hp=883d81142dad1d0ec8710099f1301d129eb453a0;hpb=57bbabb5e7c4b33141fdfbd811c78120e2401a9f;p=vlc diff --git a/modules/demux/aiff.c b/modules/demux/aiff.c index 883d81142d..8a7dd28b18 100644 --- a/modules/demux/aiff.c +++ b/modules/demux/aiff.c @@ -1,24 +1,24 @@ /***************************************************************************** * aiff.c: Audio Interchange File Format demuxer ***************************************************************************** - * Copyright (C) 2004-2007 the VideoLAN team + * Copyright (C) 2004-2007 VLC authors and VideoLAN * $Id$ * * Authors: Laurent Aimar * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or + * This program is free software; you can redistribute it and/or modify it + * under the terms of the GNU Lesser General Public License as published by + * the Free Software Foundation; either version 2.1 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License for more details. * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA. + * You should have received a copy of the GNU Lesser General Public License + * along with this program; if not, write to the Free Software Foundation, + * Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA. *****************************************************************************/ /***************************************************************************** @@ -29,7 +29,8 @@ # include "config.h" #endif -#include +#include +#include #include /* TODO: @@ -42,14 +43,14 @@ static int Open ( vlc_object_t * ); static void Close ( vlc_object_t * ); -vlc_module_begin(); - set_category( CAT_INPUT ); - set_subcategory( SUBCAT_INPUT_DEMUX ); - set_description( _("AIFF demuxer" ) ); - set_capability( "demux", 10 ); - set_callbacks( Open, Close ); - add_shortcut( "aiff" ); -vlc_module_end(); +vlc_module_begin () + set_category( CAT_INPUT ) + set_subcategory( SUBCAT_INPUT_DEMUX ) + set_description( N_("AIFF demuxer" ) ) + set_capability( "demux", 10 ) + set_callbacks( Open, Close ) + add_shortcut( "aiff" ) +vlc_module_end () /***************************************************************************** * Local prototypes @@ -84,7 +85,7 @@ static unsigned int GetF80BE( const uint8_t p[10] ) int i_exp = 30 - p[1]; unsigned int i_last = 0; - while( i_exp-- ) + while( i_exp-- > 0 ) { i_last = i_mantissa; i_mantissa >>= 1; @@ -108,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 */ @@ -118,32 +118,39 @@ static int Open( vlc_object_t *p_this ) /* Fill p_demux field */ DEMUX_INIT_COMMON(); p_sys = p_demux->p_sys; es_format_Init( &p_sys->fmt, UNKNOWN_ES, 0 ); - p_sys->i_time = 1; + p_sys->i_time = 0; p_sys->i_ssnd_pos = -1; for( ;; ) { 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] ); p_sys->fmt.audio.i_rate = GetF80BE( &p_peek[16] ); msg_Dbg( p_demux, "COMM: channels=%d samples_frames=%d bits=%d rate=%d", - GetWBE( &p_peek[8] ), GetDWBE( &p_peek[10] ), GetWBE( &p_peek[14] ), GetF80BE( &p_peek[16] ) ); + GetWBE( &p_peek[8] ), GetDWBE( &p_peek[10] ), GetWBE( &p_peek[14] ), + GetF80BE( &p_peek[16] ) ); } 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] ); @@ -175,7 +182,7 @@ static int Open( vlc_object_t *p_this ) p_sys->i_ssnd_fsize = p_sys->fmt.audio.i_channels * ((p_sys->fmt.audio.i_bitspersample + 7) / 8); - if( p_sys->i_ssnd_fsize <= 0 ) + if( p_sys->i_ssnd_fsize <= 0 || p_sys->fmt.audio.i_rate == 0 ) { msg_Err( p_demux, "invalid audio parameters" ); goto error; @@ -234,7 +241,7 @@ static int Demux( demux_t *p_demux ) } /* Set PCR */ - es_out_Control( p_demux->out, ES_OUT_SET_PCR, p_sys->i_time); + es_out_Control( p_demux->out, ES_OUT_SET_PCR, VLC_TS_0 + p_sys->i_time); /* we will read 100ms at once */ i_read = p_sys->i_ssnd_fsize * ( p_sys->fmt.audio.i_rate / 10 ); @@ -248,7 +255,7 @@ static int Demux( demux_t *p_demux ) } p_block->i_dts = - p_block->i_pts = p_sys->i_time; + p_block->i_pts = VLC_TS_0 + p_sys->i_time; p_sys->i_time += (int64_t)1000000 * p_block->i_buffer / @@ -303,7 +310,7 @@ static int Control( demux_t *p_demux, int i_query, va_list args ) { return VLC_EGENERIC; } - p_sys->i_time = 1 + (int64_t)1000000 * i_frame / p_sys->fmt.audio.i_rate; + p_sys->i_time = (int64_t)1000000 * i_frame / p_sys->fmt.audio.i_rate; return VLC_SUCCESS; } return VLC_EGENERIC;