diff mbox series

[FFmpeg-devel,23/39] avcodec/pngenc: Avoid copying APNG data, allow user-supplied buffer

Message ID HE1PR0301MB2154FCF2664CC096B9B2BFD48F299@HE1PR0301MB2154.eurprd03.prod.outlook.com
State Accepted
Commit 250d8661abdbe2929bfef17e699adfab10a9c67c
Headers show
Series [FFmpeg-devel,01/39] avcodec/audiotoolboxenc: Remove AV_CODEC_CAP_DR1 | 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 May 21, 2021, 9:17 a.m. UTC
The APNG encoder already uses internal buffers, so that the packet size
is already known before allocating the packet; therefore one can avoid
another (implicit) intermediate buffer by switching to
ff_get_encode_buffer(), thereby also supporting user-supplied buffers.

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

Patch

diff --git a/libavcodec/pngenc.c b/libavcodec/pngenc.c
index 5a376765cf..894b44197e 100644
--- a/libavcodec/pngenc.c
+++ b/libavcodec/pngenc.c
@@ -20,6 +20,7 @@ 
  */
 
 #include "avcodec.h"
+#include "encode.h"
 #include "internal.h"
 #include "bytestream.h"
 #include "lossless_videoencdsp.h"
@@ -887,12 +888,11 @@  static int encode_apng(AVCodecContext *avctx, AVPacket *pkt,
         if (!s->last_frame_packet)
             return AVERROR(ENOMEM);
     } else if (s->last_frame) {
-        ret = ff_alloc_packet2(avctx, pkt, max_packet_size, 0);
+        ret = ff_get_encode_buffer(avctx, pkt, s->last_frame_packet_size, 0);
         if (ret < 0)
             return ret;
 
         memcpy(pkt->data, s->last_frame_packet, s->last_frame_packet_size);
-        pkt->size = s->last_frame_packet_size;
         pkt->pts = pkt->dts = s->last_frame->pts;
     }
 
@@ -1148,11 +1148,11 @@  const AVCodec ff_apng_encoder = {
     .long_name      = NULL_IF_CONFIG_SMALL("APNG (Animated Portable Network Graphics) image"),
     .type           = AVMEDIA_TYPE_VIDEO,
     .id             = AV_CODEC_ID_APNG,
+    .capabilities   = AV_CODEC_CAP_DR1 | AV_CODEC_CAP_DELAY,
     .priv_data_size = sizeof(PNGEncContext),
     .init           = png_enc_init,
     .close          = png_enc_close,
     .encode2        = encode_apng,
-    .capabilities   = AV_CODEC_CAP_DELAY,
     .pix_fmts       = (const enum AVPixelFormat[]) {
         AV_PIX_FMT_RGB24, AV_PIX_FMT_RGBA,
         AV_PIX_FMT_RGB48BE, AV_PIX_FMT_RGBA64BE,