diff options
author | Justin Ruggles <justin.ruggles@gmail.com> | 2011-10-27 20:16:45 -0400 |
---|---|---|
committer | Justin Ruggles <justin.ruggles@gmail.com> | 2011-11-01 21:23:03 -0400 |
commit | 6ac34eed54f8e0298acb16636d0104c297e3d09f (patch) | |
tree | 17be20d43737bf1ab5b36aadfef860e7c3e09aae /libavcodec/g726.c | |
parent | d405237baea7ad3b6cb0bf9d91d63dd8a69e75ea (diff) | |
download | ffmpeg-6ac34eed54f8e0298acb16636d0104c297e3d09f.tar.gz |
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 'libavcodec/g726.c')
-rw-r--r-- | libavcodec/g726.c | 40 |
1 files changed, 19 insertions, 21 deletions
diff --git a/libavcodec/g726.c b/libavcodec/g726.c index b150f587f7..339281110c 100644 --- a/libavcodec/g726.c +++ b/libavcodec/g726.c @@ -301,29 +301,29 @@ static int16_t g726_encode(G726Context* c, int16_t sig) static av_cold int g726_encode_init(AVCodecContext *avctx) { G726Context* c = avctx->priv_data; - unsigned int index; if (avctx->sample_rate <= 0) { av_log(avctx, AV_LOG_ERROR, "Samplerate is invalid\n"); return -1; } - index = (avctx->bit_rate + avctx->sample_rate/2) / avctx->sample_rate - 2; - - if (avctx->bit_rate % avctx->sample_rate) { - av_log(avctx, AV_LOG_ERROR, "Bitrate - Samplerate combination is invalid\n"); - return -1; - } if(avctx->channels != 1){ av_log(avctx, AV_LOG_ERROR, "Only mono is supported\n"); return -1; } - if(index>3){ - av_log(avctx, AV_LOG_ERROR, "Unsupported number of bits %d\n", index+2); - return -1; + + if (avctx->bit_rate % avctx->sample_rate) { + av_log(avctx, AV_LOG_ERROR, "Bitrate - Samplerate combination is invalid\n"); + return AVERROR(EINVAL); + } + c->code_size = (avctx->bit_rate + avctx->sample_rate/2) / avctx->sample_rate; + if (c->code_size < 2 || c->code_size > 5) { + av_log(avctx, AV_LOG_ERROR, "Invalid number of bits %d\n", c->code_size); + return AVERROR(EINVAL); } - g726_reset(c, index); - c->code_size = index+2; + avctx->bits_per_coded_sample = c->code_size; + + g726_reset(c, c->code_size - 2); avctx->coded_frame = avcodec_alloc_frame(); if (!avctx->coded_frame) @@ -332,7 +332,7 @@ static av_cold int g726_encode_init(AVCodecContext *avctx) /* select a frame size that will end on a byte boundary and have a size of approximately 1024 bytes */ - avctx->frame_size = ((int[]){ 4096, 2736, 2048, 1640 })[index]; + avctx->frame_size = ((int[]){ 4096, 2736, 2048, 1640 })[c->code_size - 2]; return 0; } @@ -365,25 +365,23 @@ static int g726_encode_frame(AVCodecContext *avctx, static av_cold int g726_decode_init(AVCodecContext *avctx) { G726Context* c = avctx->priv_data; - unsigned int index; if (avctx->sample_rate <= 0) { av_log(avctx, AV_LOG_ERROR, "Samplerate is invalid\n"); return -1; } - index = (avctx->bit_rate + avctx->sample_rate/2) / avctx->sample_rate - 2; - if(avctx->channels != 1){ av_log(avctx, AV_LOG_ERROR, "Only mono is supported\n"); return -1; } - if(index>3){ - av_log(avctx, AV_LOG_ERROR, "Unsupported number of bits %d\n", index+2); - return -1; + + c->code_size = avctx->bits_per_coded_sample; + if (c->code_size < 2 || c->code_size > 5) { + av_log(avctx, AV_LOG_ERROR, "Invalid number of bits %d\n", c->code_size); + return AVERROR(EINVAL); } - g726_reset(c, index); - c->code_size = index+2; + g726_reset(c, c->code_size - 2); avctx->sample_fmt = AV_SAMPLE_FMT_S16; |