@ -61,7 +61,6 @@ typedef struct TTAChannel {
typedef struct TTAContext {
AVClass * class ;
AVCodecContext * avctx ;
AVFrame frame ;
GetBitContext gb ;
const AVCRC * crc_table ;
@ -312,15 +311,13 @@ static av_cold int tta_decode_init(AVCodecContext * avctx)
return AVERROR_INVALIDDATA ;
}
avcodec_get_frame_defaults ( & s - > frame ) ;
avctx - > coded_frame = & s - > frame ;
return 0 ;
}
static int tta_decode_frame ( AVCodecContext * avctx , void * data ,
int * got_frame_ptr , AVPacket * avpkt )
{
AVFrame * frame = data ;
const uint8_t * buf = avpkt - > data ;
int buf_size = avpkt - > size ;
TTAContext * s = avctx - > priv_data ;
@ -336,15 +333,15 @@ static int tta_decode_frame(AVCodecContext *avctx, void *data,
init_get_bits ( & s - > gb , buf , buf_size * 8 ) ;
/* get output buffer */
s - > frame . nb_samples = framelen ;
if ( ( ret = ff_get_buffer ( avctx , & s - > frame ) ) < 0 ) {
frame - > nb_samples = framelen ;
if ( ( ret = ff_get_buffer ( avctx , frame ) ) < 0 ) {
av_log ( avctx , AV_LOG_ERROR , " get_buffer() failed \n " ) ;
return ret ;
}
// decode directly to output buffer for 24-bit sample format
if ( s - > bps = = 3 )
s - > decode_buffer = ( int32_t * ) s - > frame . data [ 0 ] ;
s - > decode_buffer = ( int32_t * ) frame - > data [ 0 ] ;
// init per channel states
for ( i = 0 ; i < s - > channels ; i + + ) {
@ -433,7 +430,7 @@ static int tta_decode_frame(AVCodecContext *avctx, void *data,
i + + ;
// check for last frame
if ( i = = s - > last_frame_length & & get_bits_left ( & s - > gb ) / 8 = = 4 ) {
s - > frame . nb_samples = framelen = s - > last_frame_length ;
frame - > nb_samples = framelen = s - > last_frame_length ;
break ;
}
}
@ -449,20 +446,20 @@ static int tta_decode_frame(AVCodecContext *avctx, void *data,
// convert to output buffer
switch ( s - > bps ) {
case 1 : {
uint8_t * samples = ( uint8_t * ) s - > frame . data [ 0 ] ;
uint8_t * samples = ( uint8_t * ) frame - > data [ 0 ] ;
for ( p = s - > decode_buffer ; p < s - > decode_buffer + ( framelen * s - > channels ) ; p + + )
* samples + + = * p + 0x80 ;
break ;
}
case 2 : {
int16_t * samples = ( int16_t * ) s - > frame . data [ 0 ] ;
int16_t * samples = ( int16_t * ) frame - > data [ 0 ] ;
for ( p = s - > decode_buffer ; p < s - > decode_buffer + ( framelen * s - > channels ) ; p + + )
* samples + + = * p ;
break ;
}
case 3 : {
// shift samples for 24-bit sample format
int32_t * samples = ( int32_t * ) s - > frame . data [ 0 ] ;
int32_t * samples = ( int32_t * ) frame - > data [ 0 ] ;
for ( p = s - > decode_buffer ; p < s - > decode_buffer + ( framelen * s - > channels ) ; p + + )
* samples + + < < = 8 ;
// reset decode buffer
@ -471,8 +468,7 @@ static int tta_decode_frame(AVCodecContext *avctx, void *data,
}
}
* got_frame_ptr = 1 ;
* ( AVFrame * ) data = s - > frame ;
* got_frame_ptr = 1 ;
return buf_size ;
error :