Also need to stop decoding when the FN_QUIT command is found so that a
trailing seek table isn't decoded as a normal frame.

Updated FATE reference. More valid audio is now decoded.
---
 libavcodec/shorten.c                 |   17 ++++++++++++++---
 tests/ref/fate/lossless-shortenaudio |    2 +-
 2 files changed, 15 insertions(+), 4 deletions(-)

diff --git a/libavcodec/shorten.c b/libavcodec/shorten.c
index 357512f..96cf209 100644
--- a/libavcodec/shorten.c
+++ b/libavcodec/shorten.c
@@ -103,6 +103,7 @@ typedef struct ShortenContext {
     int bitindex;
     int32_t lpcqoffset;
     int got_header;
+    int got_quit_command;
 } ShortenContext;
 
 static av_cold int shorten_decode_init(AVCodecContext * avctx)
@@ -425,13 +426,15 @@ static int shorten_decode_frame(AVCodecContext *avctx,
             memmove(s->bitstream, &s->bitstream[s->bitstream_index], 
s->bitstream_size);
             s->bitstream_index=0;
         }
-        memcpy(&s->bitstream[s->bitstream_index + s->bitstream_size], buf, 
buf_size);
+        if (buf)
+            memcpy(&s->bitstream[s->bitstream_index + s->bitstream_size], buf, 
buf_size);
         buf= &s->bitstream[s->bitstream_index];
         buf_size += s->bitstream_size;
         s->bitstream_size= buf_size;
 
-        /* do not decode until buffer has at least max_framesize bytes */
-        if(buf_size < s->max_framesize){
+        /* do not decode until buffer has at least max_framesize bytes or
+           the end of the file has been reached */
+        if (buf_size < s->max_framesize && avpkt->data) {
             *data_size = 0;
             return input_buf_size;
         }
@@ -446,6 +449,12 @@ static int shorten_decode_frame(AVCodecContext *avctx,
             return ret;
     }
 
+    /* if quit command was read previously, don't decode anything */
+    if (s->got_quit_command) {
+        *data_size = 0;
+        return avpkt->size;
+    }
+
     {
         int cmd;
         int len;
@@ -487,6 +496,7 @@ static int shorten_decode_frame(AVCodecContext *avctx,
                     break;
                 }
                 case FN_QUIT:
+                    s->got_quit_command = 1;
                     break;
             }
             *data_size = 0;
@@ -605,5 +615,6 @@ AVCodec ff_shorten_decoder = {
     .init           = shorten_decode_init,
     .close          = shorten_decode_close,
     .decode         = shorten_decode_frame,
+    .capabilities   = CODEC_CAP_DELAY,
     .long_name= NULL_IF_CONFIG_SMALL("Shorten"),
 };
diff --git a/tests/ref/fate/lossless-shortenaudio 
b/tests/ref/fate/lossless-shortenaudio
index 9448052..4a6c867 100644
--- a/tests/ref/fate/lossless-shortenaudio
+++ b/tests/ref/fate/lossless-shortenaudio
@@ -1 +1 @@
-9949141c405524f37ef1058b1ef4114b
+8ec1a5426b9be1c93742d6e67d32b2df
-- 
1.7.1

_______________________________________________
libav-devel mailing list
[email protected]
https://lists.libav.org/mailman/listinfo/libav-devel

Reply via email to