* commit 'a8068346e48e123f8d3bdf4d64464d81e53e5fc7':
lavc: add a variant of av_get_audio_frame_duration working with AVCodecParameters
Fixes from jamrial incorporated.
Merged-by: Derek Buitenhuis <derek.buitenhuis@gmail.com>
... | ... |
@@ -17,6 +17,7 @@ API changes, most recent first: |
17 | 17 |
|
18 | 18 |
2016-xx-xx - lavc 57.33.0 - avcodec.h |
19 | 19 |
xxxxxxx - Add AVCodecParameters and its related API. |
20 |
+ xxxxxxx - Add av_get_audio_frame_duration2(). |
|
20 | 21 |
|
21 | 22 |
2016-03-11 - xxxxxxx - lavf/lavc 57.28.101 |
22 | 23 |
Add requirement to bitstream filtering API that returned packets with |
... | ... |
@@ -5342,6 +5342,12 @@ int av_get_exact_bits_per_sample(enum AVCodecID codec_id); |
5342 | 5342 |
*/ |
5343 | 5343 |
int av_get_audio_frame_duration(AVCodecContext *avctx, int frame_bytes); |
5344 | 5344 |
|
5345 |
+/** |
|
5346 |
+ * This function is the same as av_get_audio_frame_duration(), except it works |
|
5347 |
+ * with AVCodecParameters instead of an AVCodecContext. |
|
5348 |
+ */ |
|
5349 |
+int av_get_audio_frame_duration2(AVCodecParameters *par, int frame_bytes); |
|
5350 |
+ |
|
5345 | 5351 |
|
5346 | 5352 |
typedef struct AVBitStreamFilterContext { |
5347 | 5353 |
void *priv_data; |
... | ... |
@@ -3145,21 +3145,16 @@ int av_get_bits_per_sample(enum AVCodecID codec_id) |
3145 | 3145 |
} |
3146 | 3146 |
} |
3147 | 3147 |
|
3148 |
-int av_get_audio_frame_duration(AVCodecContext *avctx, int frame_bytes) |
|
3148 |
+static int get_audio_frame_duration(enum AVCodecID id, int sr, int ch, int ba, |
|
3149 |
+ uint32_t tag, int bits_per_coded_sample, int64_t bitrate, |
|
3150 |
+ uint8_t * extradata, int frame_size, int frame_bytes) |
|
3149 | 3151 |
{ |
3150 |
- int id, sr, ch, ba, tag, bps; |
|
3151 |
- |
|
3152 |
- id = avctx->codec_id; |
|
3153 |
- sr = avctx->sample_rate; |
|
3154 |
- ch = avctx->channels; |
|
3155 |
- ba = avctx->block_align; |
|
3156 |
- tag = avctx->codec_tag; |
|
3157 |
- bps = av_get_exact_bits_per_sample(avctx->codec_id); |
|
3152 |
+ int bps = av_get_exact_bits_per_sample(id); |
|
3158 | 3153 |
|
3159 | 3154 |
/* codecs with an exact constant bits per sample */ |
3160 | 3155 |
if (bps > 0 && ch > 0 && frame_bytes > 0 && ch < 32768 && bps < 32768) |
3161 | 3156 |
return (frame_bytes * 8LL) / (bps * ch); |
3162 |
- bps = avctx->bits_per_coded_sample; |
|
3157 |
+ bps = bits_per_coded_sample; |
|
3163 | 3158 |
|
3164 | 3159 |
/* codecs with a fixed packet duration */ |
3165 | 3160 |
switch (id) { |
... | ... |
@@ -3245,7 +3240,7 @@ int av_get_audio_frame_duration(AVCodecContext *avctx, int frame_bytes) |
3245 | 3245 |
return (frame_bytes - 8) * 2 / ch; |
3246 | 3246 |
case AV_CODEC_ID_ADPCM_THP: |
3247 | 3247 |
case AV_CODEC_ID_ADPCM_THP_LE: |
3248 |
- if (avctx->extradata) |
|
3248 |
+ if (extradata) |
|
3249 | 3249 |
return frame_bytes * 14 / (8 * ch); |
3250 | 3250 |
break; |
3251 | 3251 |
case AV_CODEC_ID_ADPCM_XA: |
... | ... |
@@ -3280,7 +3275,7 @@ int av_get_audio_frame_duration(AVCodecContext *avctx, int frame_bytes) |
3280 | 3280 |
if (ba > 0) { |
3281 | 3281 |
/* calc from frame_bytes, channels, and block_align */ |
3282 | 3282 |
int blocks = frame_bytes / ba; |
3283 |
- switch (avctx->codec_id) { |
|
3283 |
+ switch (id) { |
|
3284 | 3284 |
case AV_CODEC_ID_ADPCM_IMA_WAV: |
3285 | 3285 |
if (bps < 2 || bps > 5) |
3286 | 3286 |
return 0; |
... | ... |
@@ -3298,7 +3293,7 @@ int av_get_audio_frame_duration(AVCodecContext *avctx, int frame_bytes) |
3298 | 3298 |
|
3299 | 3299 |
if (bps > 0) { |
3300 | 3300 |
/* calc from frame_bytes, channels, and bits_per_coded_sample */ |
3301 |
- switch (avctx->codec_id) { |
|
3301 |
+ switch (id) { |
|
3302 | 3302 |
case AV_CODEC_ID_PCM_DVD: |
3303 | 3303 |
if(bps<4) |
3304 | 3304 |
return 0; |
... | ... |
@@ -3315,19 +3310,37 @@ int av_get_audio_frame_duration(AVCodecContext *avctx, int frame_bytes) |
3315 | 3315 |
} |
3316 | 3316 |
|
3317 | 3317 |
/* Fall back on using frame_size */ |
3318 |
- if (avctx->frame_size > 1 && frame_bytes) |
|
3319 |
- return avctx->frame_size; |
|
3318 |
+ if (frame_size > 1 && frame_bytes) |
|
3319 |
+ return frame_size; |
|
3320 | 3320 |
|
3321 | 3321 |
//For WMA we currently have no other means to calculate duration thus we |
3322 | 3322 |
//do it here by assuming CBR, which is true for all known cases. |
3323 |
- if (avctx->bit_rate>0 && frame_bytes>0 && avctx->sample_rate>0 && avctx->block_align>1) { |
|
3324 |
- if (avctx->codec_id == AV_CODEC_ID_WMAV1 || avctx->codec_id == AV_CODEC_ID_WMAV2) |
|
3325 |
- return (frame_bytes * 8LL * avctx->sample_rate) / avctx->bit_rate; |
|
3323 |
+ if (bitrate > 0 && frame_bytes > 0 && sr > 0 && ba > 1) { |
|
3324 |
+ if (id == AV_CODEC_ID_WMAV1 || id == AV_CODEC_ID_WMAV2) |
|
3325 |
+ return (frame_bytes * 8LL * sr) / bitrate; |
|
3326 | 3326 |
} |
3327 | 3327 |
|
3328 | 3328 |
return 0; |
3329 | 3329 |
} |
3330 | 3330 |
|
3331 |
+int av_get_audio_frame_duration(AVCodecContext *avctx, int frame_bytes) |
|
3332 |
+{ |
|
3333 |
+ return get_audio_frame_duration(avctx->codec_id, avctx->sample_rate, |
|
3334 |
+ avctx->channels, avctx->block_align, |
|
3335 |
+ avctx->codec_tag, avctx->bits_per_coded_sample, |
|
3336 |
+ avctx->bit_rate, avctx->extradata, avctx->frame_size, |
|
3337 |
+ frame_bytes); |
|
3338 |
+} |
|
3339 |
+ |
|
3340 |
+int av_get_audio_frame_duration2(AVCodecParameters *par, int frame_bytes) |
|
3341 |
+{ |
|
3342 |
+ return get_audio_frame_duration(par->codec_id, par->sample_rate, |
|
3343 |
+ par->channels, par->block_align, |
|
3344 |
+ par->codec_tag, par->bits_per_coded_sample, |
|
3345 |
+ par->bit_rate, par->extradata, par->frame_size, |
|
3346 |
+ frame_bytes); |
|
3347 |
+} |
|
3348 |
+ |
|
3331 | 3349 |
#if !HAVE_THREADS |
3332 | 3350 |
int ff_thread_init(AVCodecContext *s) |
3333 | 3351 |
{ |