X-Git-Url: https://git.sesse.net/?a=blobdiff_plain;f=modules%2Fdemux%2Ftta.c;h=b0c53bb8393555445878d163ac1e155da526eaff;hb=1ce4f166a9653d8ee369862ee3111cce91af815d;hp=e9c686637506651fd5a0f3d23776ff28283a6761;hpb=f64ef866545064f3e5901e9b5a3b3f97a2516dd9;p=vlc diff --git a/modules/demux/tta.c b/modules/demux/tta.c index e9c6866375..b0c53bb839 100644 --- a/modules/demux/tta.c +++ b/modules/demux/tta.c @@ -24,7 +24,12 @@ /***************************************************************************** * Preamble *****************************************************************************/ -#include +#ifdef HAVE_CONFIG_H +# include "config.h" +#endif + +#include +#include #include #include #include @@ -35,16 +40,16 @@ static int Open ( vlc_object_t * ); static void Close ( vlc_object_t * ); -vlc_module_begin(); - set_shortname( "TTA" ); - set_description( _("TTA demuxer") ); - set_category( CAT_INPUT ); - set_subcategory( SUBCAT_INPUT_DEMUX ); - set_capability( "demux2", 145 ); +vlc_module_begin () + set_shortname( "TTA" ) + set_description( N_("TTA demuxer") ) + set_category( CAT_INPUT ) + set_subcategory( SUBCAT_INPUT_DEMUX ) + set_capability( "demux", 145 ) - set_callbacks( Open, Close ); - add_shortcut( "tta" ); -vlc_module_end(); + set_callbacks( Open, Close ) + add_shortcut( "tta" ) +vlc_module_end () #define TTA_FRAMETIME 1.04489795918367346939 @@ -60,10 +65,10 @@ struct demux_sys_t es_out_id_t *p_es; /* */ - int i_totalframes; - int i_currentframe; + uint32_t i_totalframes; + uint32_t i_currentframe; uint32_t *pi_seektable; - int i_datalength; + uint32_t i_datalength; int i_framelength; /* */ @@ -79,22 +84,23 @@ static int Open( vlc_object_t * p_this ) demux_t *p_demux = (demux_t*)p_this; demux_sys_t *p_sys; es_format_t fmt; - uint8_t *p_peek; + const uint8_t *p_peek; uint8_t p_header[22]; - uint8_t *p_seektable; - int i_seektable_size = 0, i; + uint8_t *p_fullheader; + int i_seektable_size = 0; //char psz_info[4096]; //module_t *p_id3; 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 flac stream, " + msg_Err( p_demux, "this doesn't look like a true-audio stream, " "continuing anyway" ); } @@ -105,53 +111,66 @@ static int Open( vlc_object_t * p_this ) p_demux->pf_demux = Demux; p_demux->pf_control = Control; p_demux->p_sys = p_sys = malloc( sizeof( demux_sys_t ) ); - + if( !p_sys ) + return VLC_ENOMEM; + + p_sys->pi_seektable = NULL; + /* Read the metadata */ - es_format_Init( &fmt, AUDIO_ES, VLC_FOURCC( 'T', 'T', 'A', '1' ) ); + es_format_Init( &fmt, AUDIO_ES, VLC_CODEC_TTA ); fmt.audio.i_channels = GetWLE( &p_header[6] ); fmt.audio.i_bitspersample = GetWLE( &p_header[8] ); fmt.audio.i_rate = GetDWLE( &p_header[10] ); + if( fmt.audio.i_rate == 0 || /* Avoid divide by 0 */ + fmt.audio.i_rate > ( 1 << 20 ) /* Avoid i_framelength overflow */ ) + { + msg_Warn( p_demux, "Wrong sample rate" ); + goto error; + } p_sys->i_datalength = GetDWLE( &p_header[14] ); p_sys->i_framelength = TTA_FRAMETIME * fmt.audio.i_rate; - p_sys->i_totalframes = p_sys->i_datalength / p_sys->i_framelength + - ((p_sys->i_datalength % p_sys->i_framelength) ? 1 : 0); + p_sys->i_totalframes = p_sys->i_datalength / p_sys->i_framelength + + ((p_sys->i_datalength % p_sys->i_framelength) != 0); p_sys->i_currentframe = 0; + if( p_sys->i_totalframes > (1 << 29)) + goto error; i_seektable_size = sizeof(uint32_t)*p_sys->i_totalframes; - p_seektable = (uint8_t *)malloc( i_seektable_size ); - stream_Read( p_demux->s, p_seektable, i_seektable_size ); - p_sys->pi_seektable = (uint32_t *)malloc(i_seektable_size); - - for( i = 0; i < p_sys->i_totalframes; i++ ) - p_sys->pi_seektable[i] = GetDWLE( &p_seektable[i*4] ); - - stream_Read( p_demux->s, NULL, 4 ); /* CRC */ /* Store the header and Seektable for avcodec */ - fmt.i_extra = 22 + (p_sys->i_totalframes * 4) + 4; - fmt.p_extra = malloc( fmt.i_extra ); - memcpy( (uint8_t*)fmt.p_extra, p_header, 22 ); - memcpy( (uint8_t*)fmt.p_extra+22, p_seektable, fmt.i_extra -22 ); - - p_sys->p_es = es_out_Add( p_demux->out, &fmt ); - free( p_seektable ); - p_sys->i_start = stream_Tell( p_demux->s ); - -#if 0 - /* Parse possible id3 header */ - if( ( p_id3 = module_Need( p_demux, "meta reader", NULL, 0 ) ) ) + fmt.i_extra = 22 + i_seektable_size + 4; + fmt.p_extra = p_fullheader = malloc( fmt.i_extra ); + if( !p_fullheader ) + goto error; + + memcpy( p_fullheader, p_header, 22 ); + p_fullheader += 22; + if( stream_Read( p_demux->s, p_fullheader, i_seektable_size ) + != i_seektable_size ) + goto error; + + p_sys->pi_seektable = calloc( p_sys->i_totalframes, sizeof(uint32_t) ); + if( !p_sys->pi_seektable ) + goto error; + for( uint32_t i = 0; i < p_sys->i_totalframes; i++ ) { - p_sys->p_meta = (vlc_meta_t *)p_demux->p_private; - p_demux->p_private = NULL; - module_Unneed( p_demux, p_id3 ); + p_sys->pi_seektable[i] = GetDWLE( p_fullheader ); + p_fullheader += 4; } - if( !p_sys->p_meta ) - p_sys->p_meta = vlc_meta_New(); -#endif + stream_Read( p_demux->s, p_fullheader, 4 ); /* CRC */ + p_fullheader += 4; + + p_sys->p_es = es_out_Add( p_demux->out, &fmt ); + p_sys->i_start = p_fullheader - (uint8_t *)fmt.p_extra; + return VLC_SUCCESS; +error: + es_format_Clean( &fmt ); + Close( p_this ); + return VLC_EGENERIC; } /***************************************************************************** @@ -162,6 +181,7 @@ static void Close( vlc_object_t * p_this ) demux_t *p_demux = (demux_t*)p_this; demux_sys_t *p_sys = p_demux->p_sys; + free( p_sys->pi_seektable ); free( p_sys ); } @@ -180,7 +200,7 @@ static int Demux( demux_t *p_demux ) p_data = stream_Block( p_demux->s, p_sys->pi_seektable[p_sys->i_currentframe] ); if( p_data == NULL ) return 0; - p_data->i_dts = p_data->i_pts = (int64_t)(1 + I64C(1000000) * p_sys->i_currentframe) * TTA_FRAMETIME; + p_data->i_dts = p_data->i_pts = VLC_TS_0 + (int64_t)(INT64_C(1000000) * p_sys->i_currentframe) * TTA_FRAMETIME; p_sys->i_currentframe++; @@ -217,11 +237,10 @@ static int Control( demux_t *p_demux, int i_query, va_list args ) case DEMUX_SET_POSITION: f = (double)va_arg( args, double ); i64 = (int64_t)(f * (stream_Size( p_demux->s ) - p_sys->i_start)); - es_out_Control( p_demux->out, ES_OUT_RESET_PCR ); if( i64 > 0 ) { int64_t tmp = 0; - int i; + uint32_t i; for( i=0; i < p_sys->i_totalframes && tmp+p_sys->pi_seektable[i] < i64; i++) { tmp += p_sys->pi_seektable[i]; @@ -231,17 +250,17 @@ static int Control( demux_t *p_demux, int i_query, va_list args ) return VLC_SUCCESS; } return VLC_EGENERIC; - + case DEMUX_GET_LENGTH: pi64 = (int64_t*)va_arg( args, int64_t * ); - *pi64 = I64C(1000000) * p_sys->i_totalframes * TTA_FRAMETIME; + *pi64 = INT64_C(1000000) * p_sys->i_totalframes * TTA_FRAMETIME; return VLC_SUCCESS; case DEMUX_GET_TIME: pi64 = (int64_t*)va_arg( args, int64_t * ); - *pi64 = I64C(1000000) * p_sys->i_currentframe * TTA_FRAMETIME; + *pi64 = INT64_C(1000000) * p_sys->i_currentframe * TTA_FRAMETIME; return VLC_SUCCESS; - + default: return VLC_EGENERIC; }