This allows for outputting the final frame. Otherwise the decoding will stop
after the first channel of the last frame when flushing the decoder with
empty packets.
FATE reference updated accordingly.
---
libavcodec/shorten.c | 28 ++++++++++++++++------------
tests/ref/fate/lossless-shortenaudio | 2 +-
2 files changed, 17 insertions(+), 13 deletions(-)
diff --git a/libavcodec/shorten.c b/libavcodec/shorten.c
index 96cf209..8725274 100644
--- a/libavcodec/shorten.c
+++ b/libavcodec/shorten.c
@@ -455,18 +455,22 @@ static int shorten_decode_frame(AVCodecContext *avctx,
return avpkt->size;
}
- {
+ s->cur_chan = 0;
+ while (s->cur_chan < s->channels) {
int cmd;
int len;
+
+ if (get_bits_left(&s->gb) < FNSIZE) {
+ *data_size = 0;
+ break;
+ }
+
cmd = get_ur_golomb_shorten(&s->gb, FNSIZE);
if (cmd > FN_VERBATIM) {
av_log(avctx, AV_LOG_ERROR, "unknown shorten function %d\n", cmd);
- if (s->bitstream_size > 0) {
- s->bitstream_index++;
- s->bitstream_size--;
- }
- return -1;
+ *data_size = 0;
+ break;
}
if (!is_audio_command[cmd]) {
@@ -499,7 +503,10 @@ static int shorten_decode_frame(AVCodecContext *avctx,
s->got_quit_command = 1;
break;
}
- *data_size = 0;
+ if (s->got_quit_command) {
+ *data_size = 0;
+ break;
+ }
} else {
/* process audio command */
int residual_size = 0;
@@ -559,8 +566,7 @@ static int shorten_decode_frame(AVCodecContext *avctx,
fix_bitshift(s, s->decoded[channel]);
/* if this is the last channel in the block, output the samples */
- s->cur_chan++;
- if (s->cur_chan == s->channels) {
+ if (s->cur_chan == s->channels - 1) {
int out_size = s->blocksize * s->channels *
av_get_bytes_per_sample(avctx->sample_fmt);
if (*data_size < out_size) {
@@ -568,11 +574,9 @@ static int shorten_decode_frame(AVCodecContext *avctx,
return AVERROR(EINVAL);
}
samples = interleave_buffer(samples, s->channels,
s->blocksize, s->decoded);
- s->cur_chan = 0;
*data_size = out_size;
- } else {
- *data_size = 0;
}
+ s->cur_chan++;
}
}
diff --git a/tests/ref/fate/lossless-shortenaudio
b/tests/ref/fate/lossless-shortenaudio
index 4a6c867..9cdb369 100644
--- a/tests/ref/fate/lossless-shortenaudio
+++ b/tests/ref/fate/lossless-shortenaudio
@@ -1 +1 @@
-8ec1a5426b9be1c93742d6e67d32b2df
+da93c50961443b88fce416ae61c8ca8a
--
1.7.1
_______________________________________________
libav-devel mailing list
[email protected]
https://lists.libav.org/mailman/listinfo/libav-devel