summaryrefslogtreecommitdiff
path: root/libavformat/riff.c
diff options
context:
space:
mode:
authorJustin Ruggles <justin.ruggles@gmail.com>2011-10-27 20:16:45 -0400
committerJustin Ruggles <justin.ruggles@gmail.com>2011-11-01 21:23:03 -0400
commit6ac34eed54f8e0298acb16636d0104c297e3d09f (patch)
tree17be20d43737bf1ab5b36aadfef860e7c3e09aae /libavformat/riff.c
parentd405237baea7ad3b6cb0bf9d91d63dd8a69e75ea (diff)
g726: use bits_per_coded_sample instead of bitrate to determine mode
This requires some workarounds in the WAV muxer and demuxer. We need to write the correct bits_per_coded_sample and block_align in the muxer. In the demuxer, we cannot rely on the bits_per_coded_sample value, so we use the bit rate and sample rate to determine the value. This avoids having the decoder rely on AVCodecContext.bit_rate, which is not required to be set by the user for decoding according to our API.
Diffstat (limited to 'libavformat/riff.c')
-rw-r--r--libavformat/riff.c17
1 files changed, 10 insertions, 7 deletions
diff --git a/libavformat/riff.c b/libavformat/riff.c
index 0f4c079b35..8eed7ce28e 100644
--- a/libavformat/riff.c
+++ b/libavformat/riff.c
@@ -385,11 +385,13 @@ int ff_put_wav_header(AVIOContext *pb, AVCodecContext *enc)
avio_wl32(pb, enc->sample_rate);
if (enc->codec_id == CODEC_ID_MP2 || enc->codec_id == CODEC_ID_MP3 || enc->codec_id == CODEC_ID_GSM_MS) {
bps = 0;
- } else if (enc->codec_id == CODEC_ID_ADPCM_G726) {
- bps = 4;
} else {
- if (!(bps = av_get_bits_per_sample(enc->codec_id)))
- bps = 16; // default to 16
+ if (!(bps = av_get_bits_per_sample(enc->codec_id))) {
+ if (enc->bits_per_coded_sample)
+ bps = enc->bits_per_coded_sample;
+ else
+ bps = 16; // default to 16
+ }
}
if(bps != enc->bits_per_coded_sample && enc->bits_per_coded_sample){
av_log(enc, AV_LOG_WARNING, "requested bits_per_coded_sample (%d) and actually stored (%d) differ\n", enc->bits_per_coded_sample, bps);
@@ -400,12 +402,10 @@ int ff_put_wav_header(AVIOContext *pb, AVCodecContext *enc)
//blkalign = 144 * enc->bit_rate/enc->sample_rate;
} else if (enc->codec_id == CODEC_ID_AC3) {
blkalign = 3840; //maximum bytes per frame
- } else if (enc->codec_id == CODEC_ID_ADPCM_G726) { //
- blkalign = 1;
} else if (enc->block_align != 0) { /* specified by the codec */
blkalign = enc->block_align;
} else
- blkalign = enc->channels*bps >> 3;
+ blkalign = bps * enc->channels / av_gcd(8, bps);
if (enc->codec_id == CODEC_ID_PCM_U8 ||
enc->codec_id == CODEC_ID_PCM_S24LE ||
enc->codec_id == CODEC_ID_PCM_S32LE ||
@@ -545,6 +545,9 @@ int ff_get_wav_header(AVIOContext *pb, AVCodecContext *codec, int size)
codec->channels = 0;
codec->sample_rate = 0;
}
+ /* override bits_per_coded_sample for G.726 */
+ if (codec->codec_id == CODEC_ID_ADPCM_G726)
+ codec->bits_per_coded_sample = codec->bit_rate / codec->sample_rate;
return 0;
}