Skip to content

Commit

Permalink
lavc: fix av_get_audio_frame_duration functions
Browse files Browse the repository at this point in the history
Signed-off-by: James Almer <jamrial@gmail.com>
  • Loading branch information
jamrial committed Mar 5, 2016
1 parent a9770af commit 7a3ef8c
Showing 1 changed file with 10 additions and 7 deletions.
17 changes: 10 additions & 7 deletions libavcodec/utils.c
Expand Up @@ -3146,7 +3146,8 @@ int av_get_bits_per_sample(enum AVCodecID codec_id)
}

static int get_audio_frame_duration(enum AVCodecID id, int sr, int ch, int ba,
uint32_t tag, int bits_per_coded_sample, int frame_bytes)
uint32_t tag, int bits_per_coded_sample, int64_t bitrate
uint8_t * extradata, int frame_size, int frame_bytes)
{
int bps = av_get_exact_bits_per_sample(id);

Expand Down Expand Up @@ -3239,7 +3240,7 @@ static int get_audio_frame_duration(enum AVCodecID id, int sr, int ch, int ba,
return (frame_bytes - 8) * 2 / ch;
case AV_CODEC_ID_ADPCM_THP:
case AV_CODEC_ID_ADPCM_THP_LE:
if (avctx->extradata)
if (extradata)
return frame_bytes * 14 / (8 * ch);
break;
case AV_CODEC_ID_ADPCM_XA:
Expand Down Expand Up @@ -3309,14 +3310,14 @@ static int get_audio_frame_duration(enum AVCodecID id, int sr, int ch, int ba,
}

/* Fall back on using frame_size */
if (avctx->frame_size > 1 && frame_bytes)
return avctx->frame_size;
if (frame_size > 1 && frame_bytes)
return frame_size;

//For WMA we currently have no other means to calculate duration thus we
//do it here by assuming CBR, which is true for all known cases.
if (avctx->bit_rate>0 && frame_bytes>0 && avctx->sample_rate>0 && avctx->block_align>1) {
if (avctx->codec_id == AV_CODEC_ID_WMAV1 || avctx->codec_id == AV_CODEC_ID_WMAV2)
return (frame_bytes * 8LL * avctx->sample_rate) / avctx->bit_rate;
if (bitrate > 0 && frame_bytes > 0 && sr > 0 && ba > 1) {
if (id == AV_CODEC_ID_WMAV1 || id == AV_CODEC_ID_WMAV2)
return (frame_bytes * 8LL * sr) / bitrate;
}

return 0;
Expand All @@ -3327,6 +3328,7 @@ int av_get_audio_frame_duration(AVCodecContext *avctx, int frame_bytes)
return get_audio_frame_duration(avctx->codec_id, avctx->sample_rate,
avctx->channels, avctx->block_align,
avctx->codec_tag, avctx->bits_per_coded_sample,
avctx->bit_rate, avctx->extradata, avctx->frame_size,
frame_bytes);
}

Expand All @@ -3335,6 +3337,7 @@ int av_get_audio_frame_duration2(AVCodecParameters *par, int frame_bytes)
return get_audio_frame_duration(par->codec_id, par->sample_rate,
par->channels, par->block_align,
par->codec_tag, par->bits_per_coded_sample,
par->bit_rate, par->extradata, par->frame_size,
frame_bytes);
}

Expand Down

0 comments on commit 7a3ef8c

Please sign in to comment.