diff mbox series

[FFmpeg-devel,46/46] avcodec/zmbvenc: Avoid copying packet data, allow user-supplied buffers

Message ID HE1PR0301MB21547184BB3C14504681F67C8F5E9@HE1PR0301MB2154.eurprd03.prod.outlook.com
State Accepted
Commit 4fda451c9f2dda4ced8cff92cd7c5387550dad83
Headers show
Series [FFmpeg-devel,01/46] avcodec/a64multienc: Avoid intermediate buffer | expand

Checks

Context Check Description
andriy/x86_make success Make finished
andriy/x86_make_fate success Make fate finished
andriy/PPC64_make success Make finished
andriy/PPC64_make_fate success Make fate finished

Commit Message

Andreas Rheinhardt April 29, 2021, 11:57 p.m. UTC
Here the packet size is known before allocating the packet because
the encoder itself works with an internal buffer, so one can use
this information to avoid the implicit use of another intermediate
buffer for the packet data; one can also switch to
ff_get_encode_buffer() and directly use user-supplied buffers.

Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
---
 libavcodec/zmbvenc.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)
diff mbox series

Patch

diff --git a/libavcodec/zmbvenc.c b/libavcodec/zmbvenc.c
index 68618f77e9..531559e264 100644
--- a/libavcodec/zmbvenc.c
+++ b/libavcodec/zmbvenc.c
@@ -30,6 +30,7 @@ 
 #include "libavutil/common.h"
 #include "libavutil/intreadwrite.h"
 #include "avcodec.h"
+#include "encode.h"
 #include "internal.h"
 
 #include <zlib.h>
@@ -275,7 +276,7 @@  static int encode_frame(AVCodecContext *avctx, AVPacket *pkt,
     }
 
     pkt_size = c->zstream.total_out + 1 + 6*keyframe;
-    if ((ret = ff_alloc_packet2(avctx, pkt, pkt_size, 0)) < 0)
+    if ((ret = ff_get_encode_buffer(avctx, pkt, pkt_size, 0)) < 0)
         return ret;
     buf = pkt->data;
 
@@ -427,6 +428,7 @@  const AVCodec ff_zmbv_encoder = {
     .long_name      = NULL_IF_CONFIG_SMALL("Zip Motion Blocks Video"),
     .type           = AVMEDIA_TYPE_VIDEO,
     .id             = AV_CODEC_ID_ZMBV,
+    .capabilities   = AV_CODEC_CAP_DR1,
     .priv_data_size = sizeof(ZmbvEncContext),
     .init           = encode_init,
     .encode2        = encode_frame,