[FFmpeg-cvslog] frame: Simplify the video allocation

Luca Barbato git at videolan.org
Tue Sep 11 19:09:46 EEST 2018


ffmpeg | branch: master | Luca Barbato <lu_zero at gentoo.org> | Fri Jul 27 08:34:08 2018 +0200| [f89ec87afaf0d1abb6d450253b0b348fd554533b] | committer: Luca Barbato

frame: Simplify the video allocation

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

 libavutil/frame.c | 29 +++++++++--------------------
 1 file changed, 9 insertions(+), 20 deletions(-)

diff --git a/libavutil/frame.c b/libavutil/frame.c
index db3897c299..fa6245914e 100644
--- a/libavutil/frame.c
+++ b/libavutil/frame.c
@@ -89,12 +89,8 @@ void av_frame_free(AVFrame **frame)
 
 static int get_video_buffer(AVFrame *frame, int align)
 {
-    const AVPixFmtDescriptor *desc = av_pix_fmt_desc_get(frame->format);
     int ret, i;
 
-    if (!desc)
-        return AVERROR(EINVAL);
-
     if ((ret = av_image_check_size(frame->width, frame->height, 0, NULL)) < 0)
         return ret;
 
@@ -111,24 +107,17 @@ static int get_video_buffer(AVFrame *frame, int align)
             frame->linesize[i] = FFALIGN(frame->linesize[i], align);
     }
 
-    for (i = 0; i < 4 && frame->linesize[i]; i++) {
-        int h = frame->height;
-        if (i == 1 || i == 2)
-            h = AV_CEIL_RSHIFT(h, desc->log2_chroma_h);
+    if ((ret = av_image_fill_pointers(frame->data, frame->format, frame->height,
+                                      NULL, frame->linesize)) < 0)
+        return ret;
 
-        frame->buf[i] = av_buffer_alloc(frame->linesize[i] * h);
-        if (!frame->buf[i])
-            goto fail;
+    frame->buf[0] = av_buffer_alloc(ret);
+    if (!frame->buf[0])
+        goto fail;
 
-        frame->data[i] = frame->buf[i]->data;
-    }
-    if (desc->flags & AV_PIX_FMT_FLAG_PAL || desc->flags & AV_PIX_FMT_FLAG_PSEUDOPAL) {
-        av_buffer_unref(&frame->buf[1]);
-        frame->buf[1] = av_buffer_alloc(1024);
-        if (!frame->buf[1])
-            goto fail;
-        frame->data[1] = frame->buf[1]->data;
-    }
+    if (av_image_fill_pointers(frame->data, frame->format, frame->height,
+                               frame->buf[0]->data, frame->linesize) < 0)
+        goto fail;
 
     frame->extended_data = frame->data;
 



More information about the ffmpeg-cvslog mailing list