[FFmpeg-devel] [PATCH 04/39] avcodec/libgsmenc: Avoid copying packet data, allow user-supplied buffers

Andreas Rheinhardt andreas.rheinhardt at outlook.com
Fri May 21 12:17:07 EEST 2021


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>
---
 libavcodec/libgsmenc.c | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)

diff --git a/libavcodec/libgsmenc.c b/libavcodec/libgsmenc.c
index 850963e8f6..97ba789046 100644
--- a/libavcodec/libgsmenc.c
+++ b/libavcodec/libgsmenc.c
@@ -37,6 +37,7 @@
 #include "libavutil/common.h"
 
 #include "avcodec.h"
+#include "encode.h"
 #include "internal.h"
 #include "gsm.h"
 
@@ -98,7 +99,7 @@ static int libgsm_encode_frame(AVCodecContext *avctx, AVPacket *avpkt,
     gsm_signal *samples = (gsm_signal *)frame->data[0];
     struct gsm_state *state = avctx->priv_data;
 
-    if ((ret = ff_alloc_packet2(avctx, avpkt, avctx->block_align, 0)) < 0)
+    if ((ret = ff_get_encode_buffer(avctx, avpkt, avctx->block_align, 0)) < 0)
         return ret;
 
     switch(avctx->codec_id) {
@@ -125,6 +126,7 @@ const AVCodec ff_libgsm_encoder = {
     .long_name      = NULL_IF_CONFIG_SMALL("libgsm GSM"),
     .type           = AVMEDIA_TYPE_AUDIO,
     .id             = AV_CODEC_ID_GSM,
+    .capabilities   = AV_CODEC_CAP_DR1,
     .init           = libgsm_encode_init,
     .encode2        = libgsm_encode_frame,
     .close          = libgsm_encode_close,
@@ -141,6 +143,7 @@ const AVCodec ff_libgsm_ms_encoder = {
     .long_name      = NULL_IF_CONFIG_SMALL("libgsm GSM Microsoft variant"),
     .type           = AVMEDIA_TYPE_AUDIO,
     .id             = AV_CODEC_ID_GSM_MS,
+    .capabilities   = AV_CODEC_CAP_DR1,
     .init           = libgsm_encode_init,
     .encode2        = libgsm_encode_frame,
     .close          = libgsm_encode_close,
-- 
2.27.0



More information about the ffmpeg-devel mailing list