[FFmpeg-devel] [PATCH 3/4] avcodec/wrapped_avframe: stop hardcoding sizeof(AVFrame)
James Almer
jamrial at gmail.com
Sat Feb 12 02:13:00 EET 2022
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.
Signed-off-by: James Almer <jamrial at gmail.com>
---
libavcodec/wrapped_avframe.c | 10 ++++++----
1 file changed, 6 insertions(+), 4 deletions(-)
diff --git a/libavcodec/wrapped_avframe.c b/libavcodec/wrapped_avframe.c
index 004bd5e0e7..543d9f85eb 100644
--- a/libavcodec/wrapped_avframe.c
+++ b/libavcodec/wrapped_avframe.c
@@ -30,6 +30,7 @@
#include "libavutil/internal.h"
#include "libavutil/frame.h"
+#include "libavutil/frame_internal.h"
#include "libavutil/buffer.h"
#include "libavutil/pixdesc.h"
@@ -44,7 +45,8 @@ static int wrapped_avframe_encode(AVCodecContext *avctx, AVPacket *pkt,
const AVFrame *frame, int *got_packet)
{
uint8_t *data;
- int ret, size = sizeof(*frame) + AV_INPUT_BUFFER_PADDING_SIZE;
+ const size_t size = avpriv_avframe_size;
+ int ret;
data = av_mallocz(size);
if (!data) {
@@ -53,7 +55,7 @@ static int wrapped_avframe_encode(AVCodecContext *avctx, AVPacket *pkt,
// Set frame defaults
av_frame_unref((AVFrame *)data);
- pkt->buf = av_buffer_create(data, size,
+ pkt->buf = av_buffer_create(data, size + AV_INPUT_BUFFER_PADDING_SIZE,
wrapped_avframe_release_buffer, NULL,
AV_BUFFER_FLAG_READONLY);
if (!pkt->buf) {
@@ -68,7 +70,7 @@ static int wrapped_avframe_encode(AVCodecContext *avctx, AVPacket *pkt,
}
pkt->data = data;
- pkt->size = sizeof(*frame);
+ pkt->size = size;
pkt->flags |= AV_PKT_FLAG_KEY;
*got_packet = 1;
@@ -86,7 +88,7 @@ static int wrapped_avframe_decode(AVCodecContext *avctx, void *data,
return AVERROR(EPERM);
}
- if (pkt->size < sizeof(AVFrame))
+ if (pkt->size < avpriv_avframe_size)
return AVERROR(EINVAL);
in = (AVFrame*)pkt->data;
--
2.35.1
More information about the ffmpeg-devel
mailing list