[FFmpeg-devel] [PATCH 2/4] avcodec/wrapped_avframe: don't allocate an AVFrame twice
James Almer
jamrial at gmail.com
Sat Feb 12 02:12:59 EET 2022
Signed-off-by: James Almer <jamrial at gmail.com>
---
libavcodec/wrapped_avframe.c | 19 +++++++++----------
1 file changed, 9 insertions(+), 10 deletions(-)
diff --git a/libavcodec/wrapped_avframe.c b/libavcodec/wrapped_avframe.c
index a7834b86e8..004bd5e0e7 100644
--- a/libavcodec/wrapped_avframe.c
+++ b/libavcodec/wrapped_avframe.c
@@ -43,33 +43,32 @@ static void wrapped_avframe_release_buffer(void *unused, uint8_t *data)
static int wrapped_avframe_encode(AVCodecContext *avctx, AVPacket *pkt,
const AVFrame *frame, int *got_packet)
{
- AVFrame *wrapped = av_frame_clone(frame);
uint8_t *data;
- int size = sizeof(*wrapped) + AV_INPUT_BUFFER_PADDING_SIZE;
-
- if (!wrapped)
- return AVERROR(ENOMEM);
+ int ret, size = sizeof(*frame) + AV_INPUT_BUFFER_PADDING_SIZE;
data = av_mallocz(size);
if (!data) {
- av_frame_free(&wrapped);
return AVERROR(ENOMEM);
}
+ // Set frame defaults
+ av_frame_unref((AVFrame *)data);
pkt->buf = av_buffer_create(data, size,
wrapped_avframe_release_buffer, NULL,
AV_BUFFER_FLAG_READONLY);
if (!pkt->buf) {
- av_frame_free(&wrapped);
av_freep(&data);
return AVERROR(ENOMEM);
}
- av_frame_move_ref((AVFrame*)data, wrapped);
- av_frame_free(&wrapped);
+ ret = av_frame_ref((AVFrame*)data, frame);
+ if (ret < 0) {
+ av_buffer_unref(&pkt->buf);
+ return ret;
+ }
pkt->data = data;
- pkt->size = sizeof(*wrapped);
+ pkt->size = sizeof(*frame);
pkt->flags |= AV_PKT_FLAG_KEY;
*got_packet = 1;
--
2.35.1
More information about the ffmpeg-devel
mailing list