diff mbox series

[FFmpeg-devel,05/46] avcodec/[e]ac3enc: Allow user-supplied buffers

Message ID HE1PR0301MB2154190EACA55E4BF42D7F748F5F9@HE1PR0301MB2154.eurprd03.prod.outlook.com
State Accepted
Commit 39bb36d7231b4dd5eec8105903cd8e323b2c0474
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:56 p.m. UTC
The size of the output buffer is always known in advance and
the code has no alignment requirement (it uses mostly the PutBits API),
so allowing user-supplied buffers is trivial.

Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
---
 libavcodec/ac3enc.c       | 3 ++-
 libavcodec/ac3enc_fixed.c | 1 +
 libavcodec/ac3enc_float.c | 1 +
 libavcodec/eac3enc.c      | 1 +
 4 files changed, 5 insertions(+), 1 deletion(-)
diff mbox series

Patch

diff --git a/libavcodec/ac3enc.c b/libavcodec/ac3enc.c
index 8d9de8e108..0036f7d8bc 100644
--- a/libavcodec/ac3enc.c
+++ b/libavcodec/ac3enc.c
@@ -38,6 +38,7 @@ 
 #include "libavutil/opt.h"
 #include "libavutil/thread.h"
 #include "avcodec.h"
+#include "encode.h"
 #include "internal.h"
 #include "me_cmp.h"
 #include "put_bits.h"
@@ -1760,7 +1761,7 @@  int ff_ac3_encode_frame_common_end(AVCodecContext *avctx, AVPacket *avpkt,
 
     ac3_quantize_mantissas(s);
 
-    ret = ff_alloc_packet2(avctx, avpkt, s->frame_size, s->frame_size);
+    ret = ff_get_encode_buffer(avctx, avpkt, s->frame_size, 0);
     if (ret < 0)
         return ret;
     ac3_output_frame(s, avpkt->data);
diff --git a/libavcodec/ac3enc_fixed.c b/libavcodec/ac3enc_fixed.c
index fe8607988b..58decc594e 100644
--- a/libavcodec/ac3enc_fixed.c
+++ b/libavcodec/ac3enc_fixed.c
@@ -132,6 +132,7 @@  const AVCodec ff_ac3_fixed_encoder = {
     .long_name       = NULL_IF_CONFIG_SMALL("ATSC A/52A (AC-3)"),
     .type            = AVMEDIA_TYPE_AUDIO,
     .id              = AV_CODEC_ID_AC3,
+    .capabilities    = AV_CODEC_CAP_DR1,
     .priv_data_size  = sizeof(AC3EncodeContext),
     .init            = ac3_fixed_encode_init,
     .encode2         = ff_ac3_fixed_encode_frame,
diff --git a/libavcodec/ac3enc_float.c b/libavcodec/ac3enc_float.c
index e5c2cbd42c..f9759bd2cf 100644
--- a/libavcodec/ac3enc_float.c
+++ b/libavcodec/ac3enc_float.c
@@ -136,6 +136,7 @@  const AVCodec ff_ac3_encoder = {
     .long_name       = NULL_IF_CONFIG_SMALL("ATSC A/52A (AC-3)"),
     .type            = AVMEDIA_TYPE_AUDIO,
     .id              = AV_CODEC_ID_AC3,
+    .capabilities    = AV_CODEC_CAP_DR1,
     .priv_data_size  = sizeof(AC3EncodeContext),
     .init            = ff_ac3_float_encode_init,
     .encode2         = ff_ac3_float_encode_frame,
diff --git a/libavcodec/eac3enc.c b/libavcodec/eac3enc.c
index 38ca31a219..96ef00ea4f 100644
--- a/libavcodec/eac3enc.c
+++ b/libavcodec/eac3enc.c
@@ -253,6 +253,7 @@  const AVCodec ff_eac3_encoder = {
     .long_name       = NULL_IF_CONFIG_SMALL("ATSC A/52 E-AC-3"),
     .type            = AVMEDIA_TYPE_AUDIO,
     .id              = AV_CODEC_ID_EAC3,
+    .capabilities    = AV_CODEC_CAP_DR1,
     .priv_data_size  = sizeof(AC3EncodeContext),
     .init            = ff_ac3_float_encode_init,
     .encode2         = ff_ac3_float_encode_frame,