[FFmpeg-cvslog] avcodec/svq3: Avoid overhead of AVBuffer API

Andreas Rheinhardt git at videolan.org
Thu Sep 17 01:10:51 EEST 2020


ffmpeg | branch: master | Andreas Rheinhardt <andreas.rheinhardt at gmail.com> | Sun Sep 13 03:15:29 2020 +0200| [ef6c52f3c56ffdefb6c1f108b583b60657ff0bfc] | committer: Andreas Rheinhardt

avcodec/svq3: Avoid overhead of AVBuffer API

Up until now, the SVQ3 decoder allocated several refcounted buffers,
despite no sharing/refcounting happening at all: Their refcount never
exceeds one and they are treated like ordinary buffers (with the
exception that the pointer used to access them is in the middle of the
allocated buffer, but this does not warrant using the AVBuffer API at
all). Given that using the AVBuffer API incurs overhead, it is no longer
used at all.

Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt at gmail.com>

> http://git.videolan.org/gitweb.cgi/ffmpeg.git/?a=commit;h=ef6c52f3c56ffdefb6c1f108b583b60657ff0bfc
---

 libavcodec/svq3.c | 17 ++++++++---------
 1 file changed, 8 insertions(+), 9 deletions(-)

diff --git a/libavcodec/svq3.c b/libavcodec/svq3.c
index 0ac81364bd..fb7b992496 100644
--- a/libavcodec/svq3.c
+++ b/libavcodec/svq3.c
@@ -70,11 +70,10 @@
 typedef struct SVQ3Frame {
     AVFrame *f;
 
-    AVBufferRef *motion_val_buf[2];
+    int16_t (*motion_val_buf[2])[2];
     int16_t (*motion_val[2])[2];
 
-    AVBufferRef *mb_type_buf;
-    uint32_t *mb_type;
+    uint32_t *mb_type_buf, *mb_type;
 } SVQ3Frame;
 
 typedef struct SVQ3Context {
@@ -1325,9 +1324,9 @@ static void free_picture(AVCodecContext *avctx, SVQ3Frame *pic)
 {
     int i;
     for (i = 0; i < 2; i++) {
-        av_buffer_unref(&pic->motion_val_buf[i]);
+        av_freep(&pic->motion_val_buf[i]);
     }
-    av_buffer_unref(&pic->mb_type_buf);
+    av_freep(&pic->mb_type_buf);
 
     av_frame_unref(pic->f);
 }
@@ -1343,19 +1342,19 @@ static int get_buffer(AVCodecContext *avctx, SVQ3Frame *pic)
     if (!pic->motion_val_buf[0]) {
         int i;
 
-        pic->mb_type_buf = av_buffer_allocz((big_mb_num + s->mb_stride) * sizeof(uint32_t));
+        pic->mb_type_buf = av_calloc(big_mb_num + s->mb_stride, sizeof(uint32_t));
         if (!pic->mb_type_buf)
             return AVERROR(ENOMEM);
-        pic->mb_type = (uint32_t*)pic->mb_type_buf->data + 2 * s->mb_stride + 1;
+        pic->mb_type = pic->mb_type_buf + 2 * s->mb_stride + 1;
 
         for (i = 0; i < 2; i++) {
-            pic->motion_val_buf[i] = av_buffer_allocz(2 * (b4_array_size + 4) * sizeof(int16_t));
+            pic->motion_val_buf[i] = av_calloc(b4_array_size + 4, 2 * sizeof(int16_t));
             if (!pic->motion_val_buf[i]) {
                 ret = AVERROR(ENOMEM);
                 goto fail;
             }
 
-            pic->motion_val[i] = (int16_t (*)[2])pic->motion_val_buf[i]->data + 4;
+            pic->motion_val[i] = pic->motion_val_buf[i] + 4;
         }
     }
 



More information about the ffmpeg-cvslog mailing list