Commit 59059fde31 for ffmpeg
commit 59059fde31ef21a5b544b00c969d59730a9fa581
Author: Patrick Domack <patrickdk@patrickdk.com>
Date: Sun Nov 1 04:56:50 2026 -0500
avcodec/dss_sp: reset the decoder state on flush
The decoder had no flush callback, so after a seek it kept everything
from before the seek: the excitation history, the filter and error
buffers, the decimator tail, the noise state, the pulse decoding mode
and the format 1 noise seed. The first frames after a seek then
differed from a decode that starts at that point. Add a reset that
returns the context to what a newly opened decoder starts with, and
call it from init and as the flush callback.
A test program decodes part of a file, seeks with av_seek_frame(), calls
avcodec_flush_buffers() and decodes to the end. It does so at two
points, forward and backward, in each of an Olympus-encoded SP clip, an
SP format 1 clip, DS230002.DSS and a 591 s recording. In all eight the
output after the seek is bit-identical to a fresh decoder fed the same
file's packets from the landing frame. Five of them land on a block that
starts with an unswapped frame, and there the output is also
bit-identical to a fresh decode of the file cut at that block. Without
the flush the same check fails, by up to 8802. Decoding without a seek
does not change on 33 DSS and DS2 files.
[Guillain d'Erceville: split from the DS2 work, so this goes in before
it; figures for DS2 files were measured with the whole series]
Signed-off-by: Patrick Domack <patrickdk@patrickdk.com>
Signed-off-by: Guillain d'Erceville <guillain@poulpe.us>
diff --git a/libavcodec/dss_sp.c b/libavcodec/dss_sp.c
index 7387f3ce88..7549a03455 100644
--- a/libavcodec/dss_sp.c
+++ b/libavcodec/dss_sp.c
@@ -303,9 +303,19 @@ static const int32_t dss_sp_sinc[67] = {
139, 269, 336, 356, 348, 323, 293, 262,
};
-static av_cold int dss_sp_decode_init(AVCodecContext *avctx)
+/* Bring the context back to what a newly opened decoder starts with. */
+static void dss_sp_reset(AVCodecContext *avctx)
{
DssSpContext *p = avctx->priv_data;
+
+ memset(p, 0, sizeof(*p));
+ p->pulse_dec_mode = 1;
+ p->avctx = avctx;
+ p->variable_rate = avctx->extradata_size >= 1 && avctx->extradata[0] == DSS_ACODEC_DSS_SP_VR;
+}
+
+static av_cold int dss_sp_decode_init(AVCodecContext *avctx)
+{
avctx->sample_fmt = AV_SAMPLE_FMT_S16;
/* The codec synthesises at 12000 Hz and dss_sp_update_state resamples by
* 11/12 -- 288 samples in, 264 out -- so a frame is exactly 24 ms and the
@@ -317,9 +327,7 @@ static av_cold int dss_sp_decode_init(AVCodecContext *avctx)
av_channel_layout_uninit(&avctx->ch_layout);
avctx->ch_layout = (AVChannelLayout)AV_CHANNEL_LAYOUT_MONO;
- p->pulse_dec_mode = 1;
- p->avctx = avctx;
- p->variable_rate = avctx->extradata_size >= 1 && avctx->extradata[0] == DSS_ACODEC_DSS_SP_VR;
+ dss_sp_reset(avctx);
return 0;
}
@@ -830,5 +838,6 @@ const FFCodec ff_dss_sp_decoder = {
.priv_data_size = sizeof(DssSpContext),
.init = dss_sp_decode_init,
FF_CODEC_DECODE_CB(dss_sp_decode_frame),
+ .flush = dss_sp_reset,
.p.capabilities = AV_CODEC_CAP_DR1 | AV_CODEC_CAP_CHANNEL_CONF,
};