Signed-off-by: James Almer <jamr...@gmail.com>
---
Maybe we could also add an AV_CODEC_CAP_DISPOSABLE_FRAMES capability
to lavc and use it on relevant decoders like this one, to let the user
know to expect frames with this flag?
Although if lavc generic code doesn't do anything different for decoders
setting it, then i guess it's superfluous.

 libavcodec/qtrle.c | 15 ++++++++++++---
 1 file changed, 12 insertions(+), 3 deletions(-)

diff --git a/libavcodec/qtrle.c b/libavcodec/qtrle.c
index 7367f8688d..bf3daf26e1 100644
--- a/libavcodec/qtrle.c
+++ b/libavcodec/qtrle.c
@@ -453,14 +453,17 @@ static int qtrle_decode_frame(AVCodecContext *avctx,
     int height, row_ptr;
     int has_palette = 0;
     int ret, size;
+    int drop = 0;
 
     bytestream2_init(&s->g, avpkt->data, avpkt->size);
     if ((ret = ff_reget_buffer(avctx, s->frame)) < 0)
         return ret;
 
     /* check if this frame is even supposed to change */
-    if (avpkt->size < 8)
+    if (avpkt->size < 8) {
+        drop = 1;
         goto done;
+    }
 
     /* start after the chunk size */
     size = bytestream2_get_be32(&s->g) & 0x3FFFFFFF;
@@ -473,14 +476,18 @@ static int qtrle_decode_frame(AVCodecContext *avctx,
 
     /* if a header is present, fetch additional decoding parameters */
     if (header & 0x0008) {
-        if (avpkt->size < 14)
+        if (avpkt->size < 14) {
+            drop = 1;
             goto done;
+        }
         start_line = bytestream2_get_be16(&s->g);
         bytestream2_skip(&s->g, 2);
         height     = bytestream2_get_be16(&s->g);
         bytestream2_skip(&s->g, 2);
-        if (height > s->avctx->height - start_line)
+        if (height > s->avctx->height - start_line) {
+            drop = 1;
             goto done;
+        }
     } else {
         start_line = 0;
         height     = s->avctx->height;
@@ -548,6 +555,8 @@ static int qtrle_decode_frame(AVCodecContext *avctx,
 done:
     if ((ret = av_frame_ref(data, s->frame)) < 0)
         return ret;
+    if (drop)
+        ((AVFrame *)data)->flags |= AV_FRAME_FLAG_DISPOSABLE;
     *got_frame      = 1;
 
     /* always report that the buffer was completely consumed */
-- 
2.22.0

_______________________________________________
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or email
ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".

Reply via email to