[FFmpeg-cvslog] avcodec/r210enc: Avoid copying packet data, allow user-supplied buffers

Andreas Rheinhardt git at videolan.org
Wed May 5 15:38:18 EEST 2021


ffmpeg | branch: master | Andreas Rheinhardt <andreas.rheinhardt at outlook.com> | Sun Apr 25 01:43:26 2021 +0200| [5cb64caadfdf6ecb3d63489a27d5b1d2e2992b8d] | committer: Andreas Rheinhardt

avcodec/r210enc: Avoid copying packet data, allow user-supplied buffers

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 at outlook.com>

> http://git.videolan.org/gitweb.cgi/ffmpeg.git/?a=commit;h=5cb64caadfdf6ecb3d63489a27d5b1d2e2992b8d
---

 libavcodec/r210enc.c | 7 ++++++-
 1 file changed, 6 insertions(+), 1 deletion(-)

diff --git a/libavcodec/r210enc.c b/libavcodec/r210enc.c
index 851b99c128..5e781ed20b 100644
--- a/libavcodec/r210enc.c
+++ b/libavcodec/r210enc.c
@@ -21,6 +21,7 @@
  */
 
 #include "avcodec.h"
+#include "encode.h"
 #include "internal.h"
 #include "bytestream.h"
 
@@ -46,7 +47,8 @@ static int encode_frame(AVCodecContext *avctx, AVPacket *pkt,
     uint8_t *srcr_line, *srcg_line, *srcb_line;
     uint8_t *dst;
 
-    if ((ret = ff_alloc_packet2(avctx, pkt, 4 * aligned_width * avctx->height, 0)) < 0)
+    ret = ff_get_encode_buffer(avctx, pkt, 4 * aligned_width * avctx->height, 0);
+    if (ret < 0)
         return ret;
 
     srcg_line = pic->data[0];
@@ -91,6 +93,7 @@ const AVCodec ff_r210_encoder = {
     .long_name      = NULL_IF_CONFIG_SMALL("Uncompressed RGB 10-bit"),
     .type           = AVMEDIA_TYPE_VIDEO,
     .id             = AV_CODEC_ID_R210,
+    .capabilities   = AV_CODEC_CAP_DR1,
     .init           = encode_init,
     .encode2        = encode_frame,
     .pix_fmts       = (const enum AVPixelFormat[]) { AV_PIX_FMT_GBRP10, AV_PIX_FMT_NONE },
@@ -103,6 +106,7 @@ const AVCodec ff_r10k_encoder = {
     .long_name      = NULL_IF_CONFIG_SMALL("AJA Kona 10-bit RGB Codec"),
     .type           = AVMEDIA_TYPE_VIDEO,
     .id             = AV_CODEC_ID_R10K,
+    .capabilities   = AV_CODEC_CAP_DR1,
     .init           = encode_init,
     .encode2        = encode_frame,
     .pix_fmts       = (const enum AVPixelFormat[]) { AV_PIX_FMT_GBRP10, AV_PIX_FMT_NONE },
@@ -115,6 +119,7 @@ const AVCodec ff_avrp_encoder = {
     .long_name      = NULL_IF_CONFIG_SMALL("Avid 1:1 10-bit RGB Packer"),
     .type           = AVMEDIA_TYPE_VIDEO,
     .id             = AV_CODEC_ID_AVRP,
+    .capabilities   = AV_CODEC_CAP_DR1,
     .init           = encode_init,
     .encode2        = encode_frame,
     .pix_fmts       = (const enum AVPixelFormat[]) { AV_PIX_FMT_GBRP10, AV_PIX_FMT_NONE },



More information about the ffmpeg-cvslog mailing list