[FFmpeg-cvslog] avcodec/libgsmenc: Avoid copying packet data, allow user-supplied buffers

Andreas Rheinhardt git at videolan.org
Sun May 23 16:42:00 EEST 2021


ffmpeg | branch: master | Andreas Rheinhardt <andreas.rheinhardt at outlook.com> | Sun Apr 25 01:43:26 2021 +0200| [91567c28fc178d8f3c226b66dd40572f4eadd35c] | committer: Andreas Rheinhardt

avcodec/libgsmenc: Avoid copying packet data, allow user-supplied buffers

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.

Reviewed-by: James Almer <jamrial at gmail.com>
Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt at outlook.com>

> http://git.videolan.org/gitweb.cgi/ffmpeg.git/?a=commit;h=91567c28fc178d8f3c226b66dd40572f4eadd35c
---

 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,



More information about the ffmpeg-cvslog mailing list