Commit 856338c8ac for ffmpeg
commit 856338c8ac9bdee3b86fd212b8a1c56cc751753a
Author: Patrick Domack <patrickdk@patrickdk.com>
Date: Sun Nov 1 04:56:37 2026 -0500
avcodec/g723_1dec: add a flush callback
The decoder had no flush callback, so after a seek it kept the LSP,
excitation, filter, postfilter and comfort noise state from before the
seek. Move the state setup from init into a reset. It first clears the
channel contexts, which returns them to the state a new decoder starts
with. Call it from init and as the flush callback.
No FATE reference changes.
Signed-off-by: Patrick Domack <patrickdk@patrickdk.com>
diff --git a/libavcodec/g723_1dec.c b/libavcodec/g723_1dec.c
index 67a5df55ff..8406655e44 100644
--- a/libavcodec/g723_1dec.c
+++ b/libavcodec/g723_1dec.c
@@ -112,16 +112,11 @@ static const int cng_filt[4] = { 273, 998, 499, 333 };
static const int cng_bseg[3] = { 2048, 18432, 231233 };
-static av_cold int g723_1_decode_init(AVCodecContext *avctx)
+static void g723_1_reset(AVCodecContext *avctx)
{
G723_1_Context *s = avctx->priv_data;
- avctx->sample_fmt = AV_SAMPLE_FMT_S16P;
- if (avctx->ch_layout.nb_channels < 1 || avctx->ch_layout.nb_channels > 2) {
- av_log(avctx, AV_LOG_ERROR, "Only mono and stereo are supported (requested channels: %d).\n",
- avctx->ch_layout.nb_channels);
- return AVERROR(EINVAL);
- }
+ memset(s->ch, 0, sizeof(s->ch));
for (int ch = 0; ch < avctx->ch_layout.nb_channels; ch++) {
G723_1_ChannelContext *p = &s->ch[ch];
@@ -133,6 +128,18 @@ static av_cold int g723_1_decode_init(AVCodecContext *avctx)
p->cng_random_seed = CNG_RANDOM_SEED;
p->past_frame_type = SID_FRAME;
}
+}
+
+static av_cold int g723_1_decode_init(AVCodecContext *avctx)
+{
+ avctx->sample_fmt = AV_SAMPLE_FMT_S16P;
+ if (avctx->ch_layout.nb_channels < 1 || avctx->ch_layout.nb_channels > 2) {
+ av_log(avctx, AV_LOG_ERROR, "Only mono and stereo are supported (requested channels: %d).\n",
+ avctx->ch_layout.nb_channels);
+ return AVERROR(EINVAL);
+ }
+
+ g723_1_reset(avctx);
return 0;
}
@@ -1118,6 +1125,7 @@ const FFCodec ff_g723_1_decoder = {
.priv_data_size = sizeof(G723_1_Context),
.init = g723_1_decode_init,
FF_CODEC_DECODE_CB(g723_1_decode_frame),
+ .flush = g723_1_reset,
.p.capabilities = AV_CODEC_CAP_DR1,
.p.priv_class = &g723_1dec_class,
};