[FFmpeg-devel] [PATCH 4/3][RFC] avcodec/qtrle: call ff_reget_buffer() only when the picture data is going to change

James Almer jamrial at gmail.com
Mon Aug 26 20:36:56 EEST 2019


ff_reget_buffer() will attempt to create a writable copy of the frame,
which is not needed when the decoder intends to return a reference to
the same buffer as the previous frame.

Should reduce data copy, hopefully achieving a similar speed up as
a9dacdeea6168787a142209bd19fdd74aefc9dd6 without dropping frames.

Signed-off-by: James Almer <jamrial at gmail.com>
---
And this hopefully works around the other side of the issue.

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

diff --git a/libavcodec/qtrle.c b/libavcodec/qtrle.c
index bf3daf26e1..3255c64063 100644
--- a/libavcodec/qtrle.c
+++ b/libavcodec/qtrle.c
@@ -456,8 +456,6 @@ static int qtrle_decode_frame(AVCodecContext *avctx,
     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) {
@@ -492,6 +490,9 @@ static int qtrle_decode_frame(AVCodecContext *avctx,
         start_line = 0;
         height     = s->avctx->height;
     }
+    if ((ret = ff_reget_buffer(avctx, s->frame)) < 0)
+        return ret;
+
     row_ptr = s->frame->linesize[0] * start_line;
 
     switch (avctx->bits_per_coded_sample) {
@@ -553,6 +554,13 @@ static int qtrle_decode_frame(AVCodecContext *avctx,
     }
 
 done:
+    if (drop) {
+        // ff_reget_buffer() isn't needed when frames don't change, so just update
+        // frame props.
+        ret = ff_decode_frame_props(avctx, s->frame);
+        if (ret < 0)
+            return ret;
+    }
     if ((ret = av_frame_ref(data, s->frame)) < 0)
         return ret;
     if (drop)
-- 
2.22.0



More information about the ffmpeg-devel mailing list