diff mbox series

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

Message ID HE1PR0301MB21546AAE917CCCCE202830968F5E9@HE1PR0301MB2154.eurprd03.prod.outlook.com
State Accepted
Commit b66ca3b8d41e6488c7e650d034f242086d432f24
Headers show
Series [FFmpeg-devel,01/46] avcodec/a64multienc: Avoid intermediate buffer
Related show

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
When the packet size is known in advance like here, one can avoid
an intermediate buffer for the packet data by using
ff_get_encode_buffer() and also set AV_CODEC_CAP_DR1 at the same time.

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

Patch

diff --git a/libavcodec/xfaceenc.c b/libavcodec/xfaceenc.c
index 21c7d8f31c..aa9e905965 100644
--- a/libavcodec/xfaceenc.c
+++ b/libavcodec/xfaceenc.c
@@ -26,6 +26,7 @@ 
 
 #include "xface.h"
 #include "avcodec.h"
+#include "encode.h"
 #include "internal.h"
 #include "libavutil/avassert.h"
 
@@ -195,7 +196,7 @@  static int xface_encode_frame(AVCodecContext *avctx, AVPacket *pkt,
         intbuf[i++] = r + XFACE_FIRST_PRINT;
     }
 
-    if ((ret = ff_alloc_packet2(avctx, pkt, i+2, 0)) < 0)
+    if ((ret = ff_get_encode_buffer(avctx, pkt, i + 2, 0)) < 0)
         return ret;
 
     /* revert the number, and close the buffer */
@@ -216,6 +217,7 @@  const AVCodec ff_xface_encoder = {
     .long_name      = NULL_IF_CONFIG_SMALL("X-face image"),
     .type           = AVMEDIA_TYPE_VIDEO,
     .id             = AV_CODEC_ID_XFACE,
+    .capabilities   = AV_CODEC_CAP_DR1,
     .priv_data_size = sizeof(XFaceContext),
     .encode2        = xface_encode_frame,
     .pix_fmts       = (const enum AVPixelFormat[]) { AV_PIX_FMT_MONOWHITE, AV_PIX_FMT_NONE },