diff mbox series

[FFmpeg-devel,11/46] avcodec/cljrenc: Don't use too big buffers, don't copy them, set CAP_DR1

Message ID HE1PR0301MB2154FDBD7A3D307A0CCF13088F5F9@HE1PR0301MB2154.eurprd03.prod.outlook.com
State Accepted
Commit 5b8c18495c834253731cb55e4cda2e41ca40a2c4
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:56 p.m. UTC
Up until now, the cljr encoder used buffers that were too big by a
factor of eight (probably bit/byte confusion). This has been fixed.
And because the needed buffer size can be easily calculated in advance,
one can avoid the implicit use of an intermediate buffer and can even
allow user-supplied buffers.

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

Patch

diff --git a/libavcodec/cljrenc.c b/libavcodec/cljrenc.c
index 6f04c62cb0..15fe43e073 100644
--- a/libavcodec/cljrenc.c
+++ b/libavcodec/cljrenc.c
@@ -28,6 +28,7 @@ 
 #include "libavutil/opt.h"
 
 #include "avcodec.h"
+#include "encode.h"
 #include "internal.h"
 #include "put_bits.h"
 
@@ -56,7 +57,8 @@  static int encode_frame(AVCodecContext *avctx, AVPacket *pkt,
          return AVERROR_EXPERIMENTAL;
     }
 
-    if ((ret = ff_alloc_packet2(avctx, pkt, 32*avctx->height*avctx->width/4, 0)) < 0)
+    ret = ff_get_encode_buffer(avctx, pkt, 4 * avctx->height * ((avctx->width + 3) / 4), 0);
+    if (ret < 0)
         return ret;
 
     init_put_bits(&pb, pkt->data, pkt->size);
@@ -89,7 +91,6 @@  static int encode_frame(AVCodecContext *avctx, AVPacket *pkt,
 
     flush_put_bits(&pb);
 
-    pkt->size   = put_bytes_output(&pb);
     pkt->flags |= AV_PKT_FLAG_KEY;
     *got_packet = 1;
     return 0;
@@ -114,6 +115,7 @@  const AVCodec ff_cljr_encoder = {
     .long_name      = NULL_IF_CONFIG_SMALL("Cirrus Logic AccuPak"),
     .type           = AVMEDIA_TYPE_VIDEO,
     .id             = AV_CODEC_ID_CLJR,
+    .capabilities   = AV_CODEC_CAP_DR1,
     .priv_data_size = sizeof(CLJRContext),
     .encode2        = encode_frame,
     .pix_fmts       = (const enum AVPixelFormat[]) { AV_PIX_FMT_YUV411P,