From e61a670b53f4578ab06c2a2d0452518384ac00e5 Mon Sep 17 00:00:00 2001 From: Justin Ruggles Date: Thu, 27 Oct 2011 14:31:42 -0400 Subject: g726: use int16_t instead of short --- libavcodec/g726.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'libavcodec/g726.c') diff --git a/libavcodec/g726.c b/libavcodec/g726.c index 0f8fe81fc3..6cd8c936ac 100644 --- a/libavcodec/g726.c +++ b/libavcodec/g726.c @@ -353,7 +353,7 @@ static int g726_encode_frame(AVCodecContext *avctx, uint8_t *dst, int buf_size, void *data) { G726Context *c = avctx->priv_data; - const short *samples = data; + const int16_t *samples = data; PutBitContext pb; int i; @@ -375,7 +375,7 @@ static int g726_decode_frame(AVCodecContext *avctx, const uint8_t *buf = avpkt->data; int buf_size = avpkt->size; G726Context *c = avctx->priv_data; - short *samples = data; + int16_t *samples = data; GetBitContext gb; init_get_bits(&gb, buf, buf_size * 8); -- cgit v1.2.1 From c8d36d254e298a51ea569b2557451d26499d0f88 Mon Sep 17 00:00:00 2001 From: Justin Ruggles Date: Thu, 27 Oct 2011 14:36:41 -0400 Subject: g726: pre-calculate the number of output samples. Allows for checking output buffer size and simplification of decoding loop. --- libavcodec/g726.c | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) (limited to 'libavcodec/g726.c') diff --git a/libavcodec/g726.c b/libavcodec/g726.c index 6cd8c936ac..6ff3288a67 100644 --- a/libavcodec/g726.c +++ b/libavcodec/g726.c @@ -377,16 +377,24 @@ static int g726_decode_frame(AVCodecContext *avctx, G726Context *c = avctx->priv_data; int16_t *samples = data; GetBitContext gb; + int out_samples, out_size; + + out_samples = buf_size * 8 / c->code_size; + out_size = out_samples * av_get_bytes_per_sample(avctx->sample_fmt); + if (*data_size < out_size) { + av_log(avctx, AV_LOG_ERROR, "Output buffer is too small\n"); + return AVERROR(EINVAL); + } init_get_bits(&gb, buf, buf_size * 8); - while (get_bits_count(&gb) + c->code_size <= buf_size*8) + while (out_samples--) *samples++ = g726_decode(c, get_bits(&gb, c->code_size)); - if(buf_size*8 != get_bits_count(&gb)) + if (get_bits_left(&gb) > 0) av_log(avctx, AV_LOG_ERROR, "Frame invalidly split, missing parser?\n"); - *data_size = (uint8_t*)samples - (uint8_t*)data; + *data_size = out_size; return buf_size; } -- cgit v1.2.1 From d405237baea7ad3b6cb0bf9d91d63dd8a69e75ea Mon Sep 17 00:00:00 2001 From: Justin Ruggles Date: Thu, 27 Oct 2011 18:13:47 -0400 Subject: g726: split the init function for the encoder and decoder This also allows for not having a decoder close function. --- libavcodec/g726.c | 49 +++++++++++++++++++++++++++++++++++-------------- 1 file changed, 35 insertions(+), 14 deletions(-) (limited to 'libavcodec/g726.c') diff --git a/libavcodec/g726.c b/libavcodec/g726.c index 6ff3288a67..b150f587f7 100644 --- a/libavcodec/g726.c +++ b/libavcodec/g726.c @@ -295,11 +295,10 @@ static int16_t g726_encode(G726Context* c, int16_t sig) g726_decode(c, i); return i; } -#endif /* Interfacing to the libavcodec */ -static av_cold int g726_init(AVCodecContext * avctx) +static av_cold int g726_encode_init(AVCodecContext *avctx) { G726Context* c = avctx->priv_data; unsigned int index; @@ -311,7 +310,7 @@ static av_cold int g726_init(AVCodecContext * avctx) index = (avctx->bit_rate + avctx->sample_rate/2) / avctx->sample_rate - 2; - if (avctx->bit_rate % avctx->sample_rate && avctx->codec->encode) { + if (avctx->bit_rate % avctx->sample_rate) { av_log(avctx, AV_LOG_ERROR, "Bitrate - Samplerate combination is invalid\n"); return -1; } @@ -331,24 +330,19 @@ static av_cold int g726_init(AVCodecContext * avctx) return AVERROR(ENOMEM); avctx->coded_frame->key_frame = 1; - if (avctx->codec->decode) - avctx->sample_fmt = AV_SAMPLE_FMT_S16; - /* select a frame size that will end on a byte boundary and have a size of approximately 1024 bytes */ - if (avctx->codec->encode) - avctx->frame_size = ((int[]){ 4096, 2736, 2048, 1640 })[index]; + avctx->frame_size = ((int[]){ 4096, 2736, 2048, 1640 })[index]; return 0; } -static av_cold int g726_close(AVCodecContext *avctx) +static av_cold int g726_encode_close(AVCodecContext *avctx) { av_freep(&avctx->coded_frame); return 0; } -#if CONFIG_ADPCM_G726_ENCODER static int g726_encode_frame(AVCodecContext *avctx, uint8_t *dst, int buf_size, void *data) { @@ -368,6 +362,34 @@ static int g726_encode_frame(AVCodecContext *avctx, } #endif +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; + } + g726_reset(c, index); + c->code_size = index+2; + + avctx->sample_fmt = AV_SAMPLE_FMT_S16; + + return 0; +} + static int g726_decode_frame(AVCodecContext *avctx, void *data, int *data_size, AVPacket *avpkt) @@ -404,9 +426,9 @@ AVCodec ff_adpcm_g726_encoder = { .type = AVMEDIA_TYPE_AUDIO, .id = CODEC_ID_ADPCM_G726, .priv_data_size = sizeof(G726Context), - .init = g726_init, + .init = g726_encode_init, .encode = g726_encode_frame, - .close = g726_close, + .close = g726_encode_close, .capabilities = CODEC_CAP_SMALL_LAST_FRAME, .sample_fmts = (const enum AVSampleFormat[]){AV_SAMPLE_FMT_S16,AV_SAMPLE_FMT_NONE}, .long_name = NULL_IF_CONFIG_SMALL("G.726 ADPCM"), @@ -418,8 +440,7 @@ AVCodec ff_adpcm_g726_decoder = { .type = AVMEDIA_TYPE_AUDIO, .id = CODEC_ID_ADPCM_G726, .priv_data_size = sizeof(G726Context), - .init = g726_init, - .close = g726_close, + .init = g726_decode_init, .decode = g726_decode_frame, .long_name = NULL_IF_CONFIG_SMALL("G.726 ADPCM"), }; -- cgit v1.2.1 From 6ac34eed54f8e0298acb16636d0104c297e3d09f Mon Sep 17 00:00:00 2001 From: Justin Ruggles Date: Thu, 27 Oct 2011 20:16:45 -0400 Subject: 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. --- libavcodec/g726.c | 40 +++++++++++++++++++--------------------- 1 file changed, 19 insertions(+), 21 deletions(-) (limited to 'libavcodec/g726.c') 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; -- cgit v1.2.1 From 6e8d4a7afbf40c0eb4bd70a6e7724d22ce7a6239 Mon Sep 17 00:00:00 2001 From: Justin Ruggles Date: Thu, 27 Oct 2011 20:22:14 -0400 Subject: g726dec: remove the sample_rate validation --- libavcodec/g726.c | 5 ----- 1 file changed, 5 deletions(-) (limited to 'libavcodec/g726.c') diff --git a/libavcodec/g726.c b/libavcodec/g726.c index 339281110c..b17d578d53 100644 --- a/libavcodec/g726.c +++ b/libavcodec/g726.c @@ -366,11 +366,6 @@ static av_cold int g726_decode_init(AVCodecContext *avctx) { G726Context* c = avctx->priv_data; - if (avctx->sample_rate <= 0) { - av_log(avctx, AV_LOG_ERROR, "Samplerate is invalid\n"); - return -1; - } - if(avctx->channels != 1){ av_log(avctx, AV_LOG_ERROR, "Only mono is supported\n"); return -1; -- cgit v1.2.1 From 9e78d8cfdf915bd8704f544df84402a4b36dfb72 Mon Sep 17 00:00:00 2001 From: Justin Ruggles Date: Thu, 27 Oct 2011 20:45:24 -0400 Subject: g726: treat sample rates other than 8kHz as unofficial. --- libavcodec/g726.c | 15 +++++++++++++++ 1 file changed, 15 insertions(+) (limited to 'libavcodec/g726.c') diff --git a/libavcodec/g726.c b/libavcodec/g726.c index b17d578d53..12a37e0ab5 100644 --- a/libavcodec/g726.c +++ b/libavcodec/g726.c @@ -302,6 +302,13 @@ static av_cold int g726_encode_init(AVCodecContext *avctx) { G726Context* c = avctx->priv_data; + if (avctx->strict_std_compliance > FF_COMPLIANCE_UNOFFICIAL && + avctx->sample_rate != 8000) { + av_log(avctx, AV_LOG_ERROR, "Sample rates other than 8kHz are not " + "allowed when the compliance level is higher than unofficial. " + "Resample or reduce the compliance level.\n"); + return AVERROR(EINVAL); + } if (avctx->sample_rate <= 0) { av_log(avctx, AV_LOG_ERROR, "Samplerate is invalid\n"); return -1; @@ -366,6 +373,14 @@ static av_cold int g726_decode_init(AVCodecContext *avctx) { G726Context* c = avctx->priv_data; + if (avctx->strict_std_compliance >= FF_COMPLIANCE_STRICT && + avctx->sample_rate != 8000) { + av_log(avctx, AV_LOG_ERROR, "Only 8kHz sample rate is allowed when " + "the compliance level is strict. Reduce the compliance level " + "if you wish to decode the stream anyway.\n"); + return AVERROR(EINVAL); + } + if(avctx->channels != 1){ av_log(avctx, AV_LOG_ERROR, "Only mono is supported\n"); return -1; -- cgit v1.2.1 From 50c466d609ec60a324a7a776dfdb57c8d38faa11 Mon Sep 17 00:00:00 2001 From: Justin Ruggles Date: Thu, 27 Oct 2011 20:47:08 -0400 Subject: g726enc: use av_assert0() for sample_rate validation This should never happen, but the check avoids a divide-by-zero. --- libavcodec/g726.c | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) (limited to 'libavcodec/g726.c') diff --git a/libavcodec/g726.c b/libavcodec/g726.c index 12a37e0ab5..ffddf95f20 100644 --- a/libavcodec/g726.c +++ b/libavcodec/g726.c @@ -22,6 +22,7 @@ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA */ #include +#include "libavutil/avassert.h" #include "avcodec.h" #include "get_bits.h" #include "put_bits.h" @@ -309,10 +310,7 @@ static av_cold int g726_encode_init(AVCodecContext *avctx) "Resample or reduce the compliance level.\n"); return AVERROR(EINVAL); } - if (avctx->sample_rate <= 0) { - av_log(avctx, AV_LOG_ERROR, "Samplerate is invalid\n"); - return -1; - } + av_assert0(avctx->sample_rate > 0); if(avctx->channels != 1){ av_log(avctx, AV_LOG_ERROR, "Only mono is supported\n"); -- cgit v1.2.1 From 50969c0f46ce60a32c292b8375b4a442cc908c64 Mon Sep 17 00:00:00 2001 From: Justin Ruggles Date: Thu, 27 Oct 2011 20:49:04 -0400 Subject: g726: return AVERROR(EINVAL) instead of -1 for invalid channel count --- libavcodec/g726.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'libavcodec/g726.c') diff --git a/libavcodec/g726.c b/libavcodec/g726.c index ffddf95f20..f58bc98dad 100644 --- a/libavcodec/g726.c +++ b/libavcodec/g726.c @@ -314,7 +314,7 @@ static av_cold int g726_encode_init(AVCodecContext *avctx) if(avctx->channels != 1){ av_log(avctx, AV_LOG_ERROR, "Only mono is supported\n"); - return -1; + return AVERROR(EINVAL); } if (avctx->bit_rate % avctx->sample_rate) { @@ -381,7 +381,7 @@ static av_cold int g726_decode_init(AVCodecContext *avctx) if(avctx->channels != 1){ av_log(avctx, AV_LOG_ERROR, "Only mono is supported\n"); - return -1; + return AVERROR(EINVAL); } c->code_size = avctx->bits_per_coded_sample; -- cgit v1.2.1 From 437c11ca16dde4ccf4719584c3683230e79bc5b9 Mon Sep 17 00:00:00 2001 From: Justin Ruggles Date: Thu, 27 Oct 2011 20:50:41 -0400 Subject: g726: group the g726_encoder AVCodec with the other encoding functions --- libavcodec/g726.c | 28 +++++++++++++--------------- 1 file changed, 13 insertions(+), 15 deletions(-) (limited to 'libavcodec/g726.c') diff --git a/libavcodec/g726.c b/libavcodec/g726.c index f58bc98dad..2a60a926cd 100644 --- a/libavcodec/g726.c +++ b/libavcodec/g726.c @@ -365,6 +365,19 @@ static int g726_encode_frame(AVCodecContext *avctx, return put_bits_count(&pb)>>3; } + +AVCodec ff_adpcm_g726_encoder = { + .name = "g726", + .type = AVMEDIA_TYPE_AUDIO, + .id = CODEC_ID_ADPCM_G726, + .priv_data_size = sizeof(G726Context), + .init = g726_encode_init, + .encode = g726_encode_frame, + .close = g726_encode_close, + .capabilities = CODEC_CAP_SMALL_LAST_FRAME, + .sample_fmts = (const enum AVSampleFormat[]){AV_SAMPLE_FMT_S16,AV_SAMPLE_FMT_NONE}, + .long_name = NULL_IF_CONFIG_SMALL("G.726 ADPCM"), +}; #endif static av_cold int g726_decode_init(AVCodecContext *avctx) @@ -426,21 +439,6 @@ static int g726_decode_frame(AVCodecContext *avctx, return buf_size; } -#if CONFIG_ADPCM_G726_ENCODER -AVCodec ff_adpcm_g726_encoder = { - .name = "g726", - .type = AVMEDIA_TYPE_AUDIO, - .id = CODEC_ID_ADPCM_G726, - .priv_data_size = sizeof(G726Context), - .init = g726_encode_init, - .encode = g726_encode_frame, - .close = g726_encode_close, - .capabilities = CODEC_CAP_SMALL_LAST_FRAME, - .sample_fmts = (const enum AVSampleFormat[]){AV_SAMPLE_FMT_S16,AV_SAMPLE_FMT_NONE}, - .long_name = NULL_IF_CONFIG_SMALL("G.726 ADPCM"), -}; -#endif - AVCodec ff_adpcm_g726_decoder = { .name = "g726", .type = AVMEDIA_TYPE_AUDIO, -- cgit v1.2.1 From 7abb73d4ba8aeeb18b8adbd0f19b8caa4ec51f39 Mon Sep 17 00:00:00 2001 From: Justin Ruggles Date: Thu, 27 Oct 2011 20:51:40 -0400 Subject: g726: wrap the decoder functions with a CONFIG_ADPCM_G726_DECODER check --- libavcodec/g726.c | 2 ++ 1 file changed, 2 insertions(+) (limited to 'libavcodec/g726.c') diff --git a/libavcodec/g726.c b/libavcodec/g726.c index 2a60a926cd..14ce545017 100644 --- a/libavcodec/g726.c +++ b/libavcodec/g726.c @@ -380,6 +380,7 @@ AVCodec ff_adpcm_g726_encoder = { }; #endif +#if CONFIG_ADPCM_G726_DECODER static av_cold int g726_decode_init(AVCodecContext *avctx) { G726Context* c = avctx->priv_data; @@ -448,3 +449,4 @@ AVCodec ff_adpcm_g726_decoder = { .decode = g726_decode_frame, .long_name = NULL_IF_CONFIG_SMALL("G.726 ADPCM"), }; +#endif -- cgit v1.2.1 From 615b2a2cf5e93bc8701944b136891973aab84579 Mon Sep 17 00:00:00 2001 From: Justin Ruggles Date: Thu, 27 Oct 2011 21:19:41 -0400 Subject: g726enc: add private option for setting code size directly. This is an easy alternative to setting bit_rate. This patch also selects the closest bit_rate to the requested one rather than requiring an exact value. --- libavcodec/g726.c | 38 +++++++++++++++++++++++++++++--------- 1 file changed, 29 insertions(+), 9 deletions(-) (limited to 'libavcodec/g726.c') diff --git a/libavcodec/g726.c b/libavcodec/g726.c index 14ce545017..4bba3b5f17 100644 --- a/libavcodec/g726.c +++ b/libavcodec/g726.c @@ -23,7 +23,9 @@ */ #include #include "libavutil/avassert.h" +#include "libavutil/opt.h" #include "avcodec.h" +#include "internal.h" #include "get_bits.h" #include "put_bits.h" @@ -72,6 +74,7 @@ typedef struct G726Tables { } G726Tables; typedef struct G726Context { + AVClass *class; G726Tables tbls; /**< static tables needed for computation */ Float11 sr[2]; /**< prev. reconstructed samples */ @@ -317,15 +320,11 @@ static av_cold int g726_encode_init(AVCodecContext *avctx) return AVERROR(EINVAL); } - 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); - } + if (avctx->bit_rate) + c->code_size = (avctx->bit_rate + avctx->sample_rate/2) / avctx->sample_rate; + + c->code_size = av_clip(c->code_size, 2, 5); + avctx->bit_rate = c->code_size * avctx->sample_rate; avctx->bits_per_coded_sample = c->code_size; g726_reset(c, c->code_size - 2); @@ -366,6 +365,25 @@ static int g726_encode_frame(AVCodecContext *avctx, return put_bits_count(&pb)>>3; } +#define OFFSET(x) offsetof(G726Context, x) +#define AE AV_OPT_FLAG_AUDIO_PARAM | AV_OPT_FLAG_ENCODING_PARAM +static const AVOption options[] = { + { "code_size", "Bits per code", OFFSET(code_size), AV_OPT_TYPE_INT, { 4 }, 2, 5, AE }, + { NULL }, +}; + +static const AVClass class = { + .class_name = "g726", + .item_name = av_default_item_name, + .option = options, + .version = LIBAVUTIL_VERSION_INT, +}; + +static const AVCodecDefault defaults[] = { + { "b", "0" }, + { NULL }, +}; + AVCodec ff_adpcm_g726_encoder = { .name = "g726", .type = AVMEDIA_TYPE_AUDIO, @@ -377,6 +395,8 @@ AVCodec ff_adpcm_g726_encoder = { .capabilities = CODEC_CAP_SMALL_LAST_FRAME, .sample_fmts = (const enum AVSampleFormat[]){AV_SAMPLE_FMT_S16,AV_SAMPLE_FMT_NONE}, .long_name = NULL_IF_CONFIG_SMALL("G.726 ADPCM"), + .priv_class = &class, + .defaults = defaults, }; #endif -- cgit v1.2.1 From 97f5dd1d84d2352450093a696869433b6c85db9a Mon Sep 17 00:00:00 2001 From: Justin Ruggles Date: Thu, 27 Oct 2011 21:31:24 -0400 Subject: g726: don't pass index to g726_reset() calculate it from c->code_size instead. --- libavcodec/g726.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'libavcodec/g726.c') diff --git a/libavcodec/g726.c b/libavcodec/g726.c index 4bba3b5f17..f14958a55d 100644 --- a/libavcodec/g726.c +++ b/libavcodec/g726.c @@ -270,11 +270,11 @@ static int16_t g726_decode(G726Context* c, int I) return av_clip(re_signal << 2, -0xffff, 0xffff); } -static av_cold int g726_reset(G726Context* c, int index) +static av_cold int g726_reset(G726Context *c) { int i; - c->tbls = G726Tables_pool[index]; + c->tbls = G726Tables_pool[c->code_size - 2]; for (i=0; i<2; i++) { c->sr[i].mant = 1<<5; c->pk[i] = 1; @@ -327,7 +327,7 @@ static av_cold int g726_encode_init(AVCodecContext *avctx) avctx->bit_rate = c->code_size * avctx->sample_rate; avctx->bits_per_coded_sample = c->code_size; - g726_reset(c, c->code_size - 2); + g726_reset(c); avctx->coded_frame = avcodec_alloc_frame(); if (!avctx->coded_frame) @@ -423,7 +423,7 @@ static av_cold int g726_decode_init(AVCodecContext *avctx) av_log(avctx, AV_LOG_ERROR, "Invalid number of bits %d\n", c->code_size); return AVERROR(EINVAL); } - g726_reset(c, c->code_size - 2); + g726_reset(c); avctx->sample_fmt = AV_SAMPLE_FMT_S16; -- cgit v1.2.1 From da249637251869fb93bdf58de44e50b74df2ec35 Mon Sep 17 00:00:00 2001 From: Justin Ruggles Date: Thu, 27 Oct 2011 21:33:18 -0400 Subject: g726dec: add flush() function to reset state when seeking --- libavcodec/g726.c | 7 +++++++ 1 file changed, 7 insertions(+) (limited to 'libavcodec/g726.c') diff --git a/libavcodec/g726.c b/libavcodec/g726.c index f14958a55d..37b0adf3b4 100644 --- a/libavcodec/g726.c +++ b/libavcodec/g726.c @@ -460,6 +460,12 @@ static int g726_decode_frame(AVCodecContext *avctx, return buf_size; } +static void g726_decode_flush(AVCodecContext *avctx) +{ + G726Context *c = avctx->priv_data; + g726_reset(c); +} + AVCodec ff_adpcm_g726_decoder = { .name = "g726", .type = AVMEDIA_TYPE_AUDIO, @@ -467,6 +473,7 @@ AVCodec ff_adpcm_g726_decoder = { .priv_data_size = sizeof(G726Context), .init = g726_decode_init, .decode = g726_decode_frame, + .flush = g726_decode_flush, .long_name = NULL_IF_CONFIG_SMALL("G.726 ADPCM"), }; #endif -- cgit v1.2.1