[FFmpeg-devel] [PATCH 4/4] avcodec/librav1e: use lavu image helpers where adequate

James Almer jamrial at gmail.com
Wed Oct 12 16:08:29 EEST 2022


Signed-off-by: James Almer <jamrial at gmail.com>
---
 libavcodec/librav1e.c | 20 +++++++++++++++-----
 1 file changed, 15 insertions(+), 5 deletions(-)

diff --git a/libavcodec/librav1e.c b/libavcodec/librav1e.c
index 130417622a..284af34ec4 100644
--- a/libavcodec/librav1e.c
+++ b/libavcodec/librav1e.c
@@ -437,6 +437,8 @@ static int librav1e_receive_packet(AVCodecContext *avctx, AVPacket *pkt)
 
         if (frame->buf[0]) {
             const AVPixFmtDescriptor *desc = av_pix_fmt_desc_get(frame->format);
+            ptrdiff_t linesizes[4];
+            size_t sizes[4];
 
             int64_t *pts = av_malloc(sizeof(int64_t));
             if (!pts) {
@@ -453,12 +455,20 @@ static int librav1e_receive_packet(AVCodecContext *avctx, AVPacket *pkt)
                 return AVERROR(ENOMEM);
             }
 
+            for (int i = 0; i < 4; i++)
+                linesizes[i] = frame->linesize[i];
+
+            ret = av_image_fill_plane_sizes(sizes, frame->format, frame->height, linesizes);
+            if (ret < 0) {
+                rav1e_frame_unref(rframe);
+                av_frame_unref(frame);
+                av_freep(&pts);
+                return ret;
+            }
+
             for (int i = 0; i < desc->nb_components; i++) {
-                int shift = i ? desc->log2_chroma_h : 0;
-                int bytes = desc->comp[0].depth == 8 ? 1 : 2;
-                rav1e_frame_fill_plane(rframe, i, frame->data[i],
-                                       (frame->height >> shift) * frame->linesize[i],
-                                       frame->linesize[i], bytes);
+                rav1e_frame_fill_plane(rframe, i, frame->data[i], sizes[i],
+                                       linesizes[i], desc->comp[i].step);
             }
             av_frame_unref(frame);
             rav1e_frame_set_opaque(rframe, pts, av_free);
-- 
2.37.3



More information about the ffmpeg-devel mailing list