diff mbox series

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

Message ID HE1PR0301MB2154AB11DBFA45A6F6F58BF18F5E9@HE1PR0301MB2154.eurprd03.prod.outlook.com
State Accepted
Commit 765366bcba7ab8d6b3958a860f64147c9e1ceb2a
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/xwdenc.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)
diff mbox series

Patch

diff --git a/libavcodec/xwdenc.c b/libavcodec/xwdenc.c
index 8eec700e9d..d7d18f913c 100644
--- a/libavcodec/xwdenc.c
+++ b/libavcodec/xwdenc.c
@@ -24,6 +24,7 @@ 
 #include "libavutil/pixdesc.h"
 #include "avcodec.h"
 #include "bytestream.h"
+#include "encode.h"
 #include "internal.h"
 #include "xwd.h"
 
@@ -147,7 +148,7 @@  static int xwd_encode_frame(AVCodecContext *avctx, AVPacket *pkt,
     header_size = XWD_HEADER_SIZE + WINDOW_NAME_SIZE;
     out_size    = header_size + ncolors * XWD_CMAP_SIZE + avctx->height * lsize;
 
-    if ((ret = ff_alloc_packet2(avctx, pkt, out_size, 0)) < 0)
+    if ((ret = ff_get_encode_buffer(avctx, pkt, out_size, 0)) < 0)
         return ret;
     buf = pkt->data;
 
@@ -220,6 +221,7 @@  const AVCodec ff_xwd_encoder = {
     .long_name    = NULL_IF_CONFIG_SMALL("XWD (X Window Dump) image"),
     .type         = AVMEDIA_TYPE_VIDEO,
     .id           = AV_CODEC_ID_XWD,
+    .capabilities = AV_CODEC_CAP_DR1,
     .encode2      = xwd_encode_frame,
     .pix_fmts     = (const enum AVPixelFormat[]) { AV_PIX_FMT_BGRA,
                                                  AV_PIX_FMT_RGBA,