diff mbox series

[FFmpeg-devel,4/4] avformat/vapoursynth: stop hardcoding sizeof(AVFrame)

Message ID 20220212001301.4090-4-jamrial@gmail.com
State New
Headers show
Series [FFmpeg-devel,RFC,1/4] avutil/frame: add an internal field to store the size of AVFrame | expand

Checks

Context Check Description
andriy/make_x86 success Make finished
andriy/make_fate_x86 success Make fate finished
yinshiyou/make_loongarch64 success Make finished
yinshiyou/make_fate_loongarch64 success Make fate finished
andriy/make_ppc success Make finished
andriy/make_fate_ppc success Make fate finished
andriy/make_aarch64_jetson success Make finished
andriy/make_fate_aarch64_jetson success Make fate finished
andriy/make_armv7_RPi4 success Make finished
andriy/make_fate_armv7_RPi4 success Make fate finished

Commit Message

James Almer Feb. 12, 2022, 12:13 a.m. UTC
Use instead the new internal avpriv_avframe_size constant. This will
ensure the actual size of AVFrame from the libavutil loaded at runtime
is used instead.

Also add the missing padding bytes required by the AVPacket API while
at it.

Signed-off-by: James Almer <jamrial@gmail.com>
---
 libavformat/vapoursynth.c | 12 ++++++++----
 1 file changed, 8 insertions(+), 4 deletions(-)
diff mbox series

Patch

diff --git a/libavformat/vapoursynth.c b/libavformat/vapoursynth.c
index 1578a6ac77..5c57f3a71c 100644
--- a/libavformat/vapoursynth.c
+++ b/libavformat/vapoursynth.c
@@ -31,6 +31,7 @@ 
 #include "libavutil/avassert.h"
 #include "libavutil/avstring.h"
 #include "libavutil/eval.h"
+#include "libavutil/frame_internal.h"
 #include "libavutil/imgutils.h"
 #include "libavutil/opt.h"
 #include "libavutil/pixdesc.h"
@@ -344,6 +345,7 @@  static int read_packet_vs(AVFormatContext *s, AVPacket *pkt)
     const AVPixFmtDescriptor *desc;
     AVBufferRef *vsframe_ref = NULL;
     struct vsframe_ref_data *ref_data;
+    const size_t size = avpriv_avframe_size;
     int err = 0;
     int i;
 
@@ -382,11 +384,13 @@  static int read_packet_vs(AVFormatContext *s, AVPacket *pkt)
 
     props = vs->vsapi->getFramePropsRO(vsframe);
 
-    frame = av_frame_alloc();
+    frame = (AVFrame *)av_mallocz(size + AV_INPUT_BUFFER_PADDING_SIZE);
     if (!frame) {
         err = AVERROR(ENOMEM);
         goto end;
     }
+    // Set frame defaults
+    av_frame_unref(frame);
 
     frame->format       = st->codecpar->format;
     frame->width        = st->codecpar->width;
@@ -432,8 +436,8 @@  static int read_packet_vs(AVFormatContext *s, AVPacket *pkt)
         frame->buf[i]->size = frame->linesize[i] * plane_h;
     }
 
-    pkt->buf = av_buffer_create((uint8_t*)frame, sizeof(*frame),
-                                free_frame, NULL, 0);
+    pkt->buf = av_buffer_create((uint8_t*)frame, size + AV_INPUT_BUFFER_PADDING_SIZE,
+                                free_frame, NULL, AV_BUFFER_FLAG_READONLY);
     if (!pkt->buf) {
         err = AVERROR(ENOMEM);
         goto end;
@@ -442,7 +446,7 @@  static int read_packet_vs(AVFormatContext *s, AVPacket *pkt)
     frame = NULL; // pkt owns it now
 
     pkt->data   = pkt->buf->data;
-    pkt->size   = pkt->buf->size;
+    pkt->size   = size;
     pkt->flags |= AV_PKT_FLAG_TRUSTED;
 
     if (vs->is_cfr)