diff mbox series

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

Message ID HE1PR0301MB2154FDBC260D9108F7E74F3B8F5E9@HE1PR0301MB2154.eurprd03.prod.outlook.com
State Accepted
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
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/v408enc.c | 6 ++++--
 libavcodec/v410enc.c | 6 ++++--
 2 files changed, 8 insertions(+), 4 deletions(-)
diff mbox series

Patch

diff --git a/libavcodec/v408enc.c b/libavcodec/v408enc.c
index a0cda6fb0c..af9fcfa9e2 100644
--- a/libavcodec/v408enc.c
+++ b/libavcodec/v408enc.c
@@ -75,6 +75,8 @@  static int v408_encode_frame(AVCodecContext *avctx, AVPacket *pkt,
     return 0;
 }
 
+static const enum AVPixelFormat pix_fmt[] = { AV_PIX_FMT_YUVA444P, AV_PIX_FMT_NONE };
+
 #if CONFIG_AYUV_ENCODER
 const AVCodec ff_ayuv_encoder = {
     .name         = "ayuv",
@@ -84,7 +86,7 @@  const AVCodec ff_ayuv_encoder = {
     .capabilities = AV_CODEC_CAP_DR1,
     .init         = v408_encode_init,
     .encode2      = v408_encode_frame,
-    .pix_fmts     = (const enum AVPixelFormat[]){ AV_PIX_FMT_YUVA444P, AV_PIX_FMT_NONE },
+    .pix_fmts     = pix_fmt,
 };
 #endif
 #if CONFIG_V408_ENCODER
@@ -96,6 +98,6 @@  const AVCodec ff_v408_encoder = {
     .capabilities = AV_CODEC_CAP_DR1,
     .init         = v408_encode_init,
     .encode2      = v408_encode_frame,
-    .pix_fmts     = (const enum AVPixelFormat[]){ AV_PIX_FMT_YUVA444P, AV_PIX_FMT_NONE },
+    .pix_fmts     = pix_fmt,
 };
 #endif
diff --git a/libavcodec/v410enc.c b/libavcodec/v410enc.c
index c31bf7f4d8..07d1565980 100644
--- a/libavcodec/v410enc.c
+++ b/libavcodec/v410enc.c
@@ -23,6 +23,7 @@ 
 #include "libavutil/common.h"
 #include "libavutil/intreadwrite.h"
 #include "avcodec.h"
+#include "encode.h"
 #include "internal.h"
 
 static av_cold int v410_encode_init(AVCodecContext *avctx)
@@ -46,8 +47,8 @@  static int v410_encode_frame(AVCodecContext *avctx, AVPacket *pkt,
     uint32_t val;
     int i, j, ret;
 
-    if ((ret = ff_alloc_packet2(avctx, pkt, avctx->width * avctx->height * 4,
-                                            avctx->width * avctx->height * 4)) < 0)
+    ret = ff_get_encode_buffer(avctx, pkt, avctx->width * avctx->height * 4, 0);
+    if (ret < 0)
         return ret;
     dst = pkt->data;
 
@@ -78,6 +79,7 @@  const AVCodec ff_v410_encoder = {
     .long_name    = NULL_IF_CONFIG_SMALL("Uncompressed 4:4:4 10-bit"),
     .type         = AVMEDIA_TYPE_VIDEO,
     .id           = AV_CODEC_ID_V410,
+    .capabilities = AV_CODEC_CAP_DR1,
     .init         = v410_encode_init,
     .encode2      = v410_encode_frame,
     .pix_fmts     = (const enum AVPixelFormat[]){ AV_PIX_FMT_YUV444P10, AV_PIX_FMT_NONE },