diff mbox series

[FFmpeg-devel,28/34] avcodec/libmp3lame: Avoid copying packet data

Message ID HE1PR0301MB2154773B8FC0935F2030DF9B8F439@HE1PR0301MB2154.eurprd03.prod.outlook.com
State New
Headers show
Series [FFmpeg-devel,01/34] avcodec/adpcmenc: Avoid copying packet data
Related show

Checks

Context Check Description
andriy/x86_make success Make finished
andriy/x86_make_fate fail Make fate failed
andriy/PPC64_make success Make finished
andriy/PPC64_make_fate warning Make fate failed

Commit Message

Andreas Rheinhardt April 25, 2021, 10:34 p.m. UTC
The libmp3lame encoder already uses an internal buffer, so that the
packet size is already known before allocating the packet; therefore
one can avoid another (implicit) intermediate buffer by setting
the min_size parameter in ff_alloc_packet2().

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

Patch

diff --git a/libavcodec/libmp3lame.c b/libavcodec/libmp3lame.c
index 2beb28e569..bdb69424ee 100644
--- a/libavcodec/libmp3lame.c
+++ b/libavcodec/libmp3lame.c
@@ -264,7 +264,7 @@  static int mp3lame_encode_frame(AVCodecContext *avctx, AVPacket *avpkt,
     ff_dlog(avctx, "in:%d packet-len:%d index:%d\n", avctx->frame_size, len,
             s->buffer_index);
     if (len <= s->buffer_index) {
-        if ((ret = ff_alloc_packet2(avctx, avpkt, len, 0)) < 0)
+        if ((ret = ff_alloc_packet2(avctx, avpkt, len, len)) < 0)
             return ret;
         memcpy(avpkt->data, s->buffer, len);
         s->buffer_index -= len;
@@ -296,7 +296,6 @@  static int mp3lame_encode_frame(AVCodecContext *avctx, AVPacket *avpkt,
             AV_WL32(side_data + 4, discard_padding);
         }
 
-        avpkt->size = len;
         *got_packet_ptr = 1;
     }
     return 0;