Commit 9bc4e21a authored by Kostya Shishkov's avatar Kostya Shishkov Committed by Anton Khirnov

wavpack: use context reset in appropriate places

This fixes improper flushing in the cases when the same frame is decoded in
several iterations (for being too large to fit into output buffer) and flush is
called mid-decoding and it also resets context in case of decoding errors.
Signed-off-by: 's avatarAnton Khirnov <anton@khirnov.net>
parent dc26318c
...@@ -470,6 +470,7 @@ static float wv_get_value_float(WavpackFrameContext *s, uint32_t *crc, int S) ...@@ -470,6 +470,7 @@ static float wv_get_value_float(WavpackFrameContext *s, uint32_t *crc, int S)
static void wv_reset_saved_context(WavpackFrameContext *s) static void wv_reset_saved_context(WavpackFrameContext *s)
{ {
s->pos = 0; s->pos = 0;
s->samples_left = 0;
s->sc.crc = s->extra_sc.crc = 0xFFFFFFFF; s->sc.crc = s->extra_sc.crc = 0xFFFFFFFF;
} }
...@@ -582,6 +583,7 @@ static inline int wv_unpack_stereo(WavpackFrameContext *s, GetBitContext *gb, vo ...@@ -582,6 +583,7 @@ static inline int wv_unpack_stereo(WavpackFrameContext *s, GetBitContext *gb, vo
s->samples_left -= count; s->samples_left -= count;
if(!s->samples_left){ if(!s->samples_left){
wv_reset_saved_context(s);
if(crc != s->CRC){ if(crc != s->CRC){
av_log(s->avctx, AV_LOG_ERROR, "CRC error\n"); av_log(s->avctx, AV_LOG_ERROR, "CRC error\n");
return -1; return -1;
...@@ -590,7 +592,6 @@ static inline int wv_unpack_stereo(WavpackFrameContext *s, GetBitContext *gb, vo ...@@ -590,7 +592,6 @@ static inline int wv_unpack_stereo(WavpackFrameContext *s, GetBitContext *gb, vo
av_log(s->avctx, AV_LOG_ERROR, "Extra bits CRC error\n"); av_log(s->avctx, AV_LOG_ERROR, "Extra bits CRC error\n");
return -1; return -1;
} }
wv_reset_saved_context(s);
}else{ }else{
s->pos = pos; s->pos = pos;
s->sc.crc = crc; s->sc.crc = crc;
...@@ -660,6 +661,7 @@ static inline int wv_unpack_mono(WavpackFrameContext *s, GetBitContext *gb, void ...@@ -660,6 +661,7 @@ static inline int wv_unpack_mono(WavpackFrameContext *s, GetBitContext *gb, void
s->samples_left -= count; s->samples_left -= count;
if(!s->samples_left){ if(!s->samples_left){
wv_reset_saved_context(s);
if(crc != s->CRC){ if(crc != s->CRC){
av_log(s->avctx, AV_LOG_ERROR, "CRC error\n"); av_log(s->avctx, AV_LOG_ERROR, "CRC error\n");
return -1; return -1;
...@@ -668,7 +670,6 @@ static inline int wv_unpack_mono(WavpackFrameContext *s, GetBitContext *gb, void ...@@ -668,7 +670,6 @@ static inline int wv_unpack_mono(WavpackFrameContext *s, GetBitContext *gb, void
av_log(s->avctx, AV_LOG_ERROR, "Extra bits CRC error\n"); av_log(s->avctx, AV_LOG_ERROR, "Extra bits CRC error\n");
return -1; return -1;
} }
wv_reset_saved_context(s);
}else{ }else{
s->pos = pos; s->pos = pos;
s->sc.crc = crc; s->sc.crc = crc;
...@@ -1195,7 +1196,7 @@ static void wavpack_decode_flush(AVCodecContext *avctx) ...@@ -1195,7 +1196,7 @@ static void wavpack_decode_flush(AVCodecContext *avctx)
int i; int i;
for (i = 0; i < s->fdec_num; i++) for (i = 0; i < s->fdec_num; i++)
s->fdec[i]->samples_left = 0; wv_reset_saved_context(s->fdec[i]);
} }
AVCodec ff_wavpack_decoder = { AVCodec ff_wavpack_decoder = {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment