summaryrefslogtreecommitdiff
path: root/libavformat
diff options
context:
space:
mode:
authorJustin Ruggles <justin.ruggles@gmail.com>2012-02-27 15:54:41 -0500
committerJustin Ruggles <justin.ruggles@gmail.com>2012-03-05 13:08:18 -0500
commit6c65cf58fdeafc1bd7643305e66e0e073429c78d (patch)
treedc6b974ba1e1434733078f21b4ed93412cbe9421 /libavformat
parent11ac796f7ab2738eff19ea18847355363c8cc797 (diff)
lavf: Use av_get_audio_frame_duration() in get_audio_frame_size()
Also, do not give AVCodecContext.frame_size priority for muxing. Updated 2 FATE references: dxa-feeble - adds 1 audio frame that is still within 2 seconds as specified by -t 2 in the FATE test wmv8-drm-nodec - durations are not needed. previously they were estimated using the packet size and average bit rate.
Diffstat (limited to 'libavformat')
-rw-r--r--libavformat/utils.c33
1 files changed, 14 insertions, 19 deletions
diff --git a/libavformat/utils.c b/libavformat/utils.c
index 7e66962b9a..7fd7c32f80 100644
--- a/libavformat/utils.c
+++ b/libavformat/utils.c
@@ -697,27 +697,22 @@ int av_read_packet(AVFormatContext *s, AVPacket *pkt)
/**
* Get the number of samples of an audio frame. Return -1 on error.
*/
-static int get_audio_frame_size(AVCodecContext *enc, int size)
+static int get_audio_frame_size(AVCodecContext *enc, int size, int mux)
{
int frame_size;
- if (enc->frame_size <= 1) {
- int bits_per_sample = av_get_bits_per_sample(enc->codec_id);
+ /* give frame_size priority if demuxing */
+ if (!mux && enc->frame_size > 1)
+ return enc->frame_size;
- if (bits_per_sample) {
- if (enc->channels == 0)
- return -1;
- frame_size = (size << 3) / (bits_per_sample * enc->channels);
- } else {
- /* used for example by ADPCM codecs */
- if (enc->bit_rate == 0)
- return -1;
- frame_size = ((int64_t)size * 8 * enc->sample_rate) / enc->bit_rate;
- }
- } else {
- frame_size = enc->frame_size;
- }
- return frame_size;
+ if ((frame_size = av_get_audio_frame_duration(enc, size)) > 0)
+ return frame_size;
+
+ /* fallback to using frame_size if muxing */
+ if (enc->frame_size > 1)
+ return enc->frame_size;
+
+ return -1;
}
@@ -753,7 +748,7 @@ static void compute_frame_duration(int *pnum, int *pden, AVStream *st,
}
break;
case AVMEDIA_TYPE_AUDIO:
- frame_size = get_audio_frame_size(st->codec, pkt->size);
+ frame_size = get_audio_frame_size(st->codec, pkt->size, 0);
if (frame_size <= 0 || st->codec->sample_rate <= 0)
break;
*pnum = frame_size;
@@ -2955,7 +2950,7 @@ static int compute_pkt_fields2(AVFormatContext *s, AVStream *st, AVPacket *pkt){
/* update pts */
switch (st->codec->codec_type) {
case AVMEDIA_TYPE_AUDIO:
- frame_size = get_audio_frame_size(st->codec, pkt->size);
+ frame_size = get_audio_frame_size(st->codec, pkt->size, 1);
/* HACK/FIXME, we skip the initial 0 size packets as they are most
likely equal to the encoder delay, but it would be better if we