[FFmpeg-cvslog] avcodec/libxavs2: Allow user-supplied buffers

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


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

avcodec/libxavs2: Allow user-supplied buffers

Here the packet size is known before allocating the packet,
so that supporting user-supplied buffers is trivial.

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=3abdf0efac7d588efb757837e962afd9334b3bf6
---

 libavcodec/libxavs2.c | 10 +++++-----
 1 file changed, 5 insertions(+), 5 deletions(-)

diff --git a/libavcodec/libxavs2.c b/libavcodec/libxavs2.c
index 99fe0e3286..9c5a576e90 100644
--- a/libavcodec/libxavs2.c
+++ b/libavcodec/libxavs2.c
@@ -23,6 +23,7 @@
  */
 
 #include "xavs2.h"
+#include "encode.h"
 #include "mpeg12.h"
 #include "libavutil/avstring.h"
 
@@ -214,10 +215,9 @@ static int xavs2_encode_frame(AVCodecContext *avctx, AVPacket *pkt,
     }
 
     if ((cae->packet.len) && (cae->packet.state != XAVS2_STATE_FLUSH_END)) {
-        if (av_new_packet(pkt, cae->packet.len) < 0) {
-            av_log(avctx, AV_LOG_ERROR, "Failed to alloc xavs2 packet.\n");
+        if ((ret = ff_get_encode_buffer(avctx, pkt, cae->packet.len, 0)) < 0) {
             cae->api->encoder_packet_unref(cae->encoder, &cae->packet);
-            return AVERROR(ENOMEM);
+            return ret;
         }
 
         pkt->pts = cae->packet.pts;
@@ -230,7 +230,6 @@ static int xavs2_encode_frame(AVCodecContext *avctx, AVPacket *pkt,
         }
 
         memcpy(pkt->data, cae->packet.stream, cae->packet.len);
-        pkt->size = cae->packet.len;
 
         cae->api->encoder_packet_unref(cae->encoder, &cae->packet);
 
@@ -290,11 +289,12 @@ const AVCodec ff_libxavs2_encoder = {
     .long_name      = NULL_IF_CONFIG_SMALL("libxavs2 AVS2-P2/IEEE1857.4"),
     .type           = AVMEDIA_TYPE_VIDEO,
     .id             = AV_CODEC_ID_AVS2,
+    .capabilities   = AV_CODEC_CAP_DR1 | AV_CODEC_CAP_DELAY |
+                      AV_CODEC_CAP_OTHER_THREADS,
     .priv_data_size = sizeof(XAVS2EContext),
     .init           = xavs2_init,
     .encode2        = xavs2_encode_frame,
     .close          = xavs2_close,
-    .capabilities   = AV_CODEC_CAP_DELAY | AV_CODEC_CAP_OTHER_THREADS,
     .caps_internal  = FF_CODEC_CAP_AUTO_THREADS,
     .pix_fmts       = (const enum AVPixelFormat[]) { AV_PIX_FMT_YUV420P,
                                                      AV_PIX_FMT_NONE },



More information about the ffmpeg-cvslog mailing list