[FFmpeg-devel] [PATCH 15/15] lavc/adpcm: THP: don't use the ADPC/SEEK table when not seeking
Rodger Combs
rodger.combs at gmail.com
Sat Jun 20 12:01:27 CEST 2015
This is almost certainly closer to how the actual Nintendo players work,
and fixes some output pops in files with blank ADPC/SEEK tables (like
those from brawlcustommusic).
---
libavcodec/adpcm.c | 21 +++++++++++++++++----
1 file changed, 17 insertions(+), 4 deletions(-)
diff --git a/libavcodec/adpcm.c b/libavcodec/adpcm.c
index 94b4de1..c6ca880 100644
--- a/libavcodec/adpcm.c
+++ b/libavcodec/adpcm.c
@@ -86,6 +86,7 @@ static const int swf_index_tables[4][16] = {
typedef struct ADPCMDecodeContext {
ADPCMChannelStatus status[10];
int vqa_version; /**< VQA version. Used for ADPCM_IMA_WS */
+ int has_status;
} ADPCMDecodeContext;
static av_cold int adpcm_decode_init(AVCodecContext * avctx)
@@ -1455,10 +1456,15 @@ static int adpcm_decode_frame(AVCodecContext *avctx, void *data,
for (n = 0; n < 16; n++)
table[i][n] = THP_GET16(gb);
- /* Initialize the previous sample. */
- for (i = 0; i < avctx->channels; i++) {
- c->status[i].sample1 = THP_GET16(gb);
- c->status[i].sample2 = THP_GET16(gb);
+ if (!c->has_status) {
+ /* Initialize the previous sample. */
+ for (i = 0; i < avctx->channels; i++) {
+ c->status[i].sample1 = THP_GET16(gb);
+ c->status[i].sample2 = THP_GET16(gb);
+ }
+ c->has_status = 1;
+ } else {
+ bytestream2_skip(&gb, avctx->channels * 4);
}
}
@@ -1562,6 +1568,12 @@ static int adpcm_decode_frame(AVCodecContext *avctx, void *data,
return bytestream2_tell(&gb);
}
+static void adpcm_flush(AVCodecContext *avctx)
+{
+ ADPCMDecodeContext *c = avctx->priv_data;
+ c->has_status = 0;
+}
+
static const enum AVSampleFormat sample_fmts_s16[] = { AV_SAMPLE_FMT_S16,
AV_SAMPLE_FMT_NONE };
@@ -1580,6 +1592,7 @@ AVCodec ff_ ## name_ ## _decoder = { \
.priv_data_size = sizeof(ADPCMDecodeContext), \
.init = adpcm_decode_init, \
.decode = adpcm_decode_frame, \
+ .flush = adpcm_flush, \
.capabilities = CODEC_CAP_DR1, \
.sample_fmts = sample_fmts_, \
}
--
2.4.1
More information about the ffmpeg-devel
mailing list