diff mbox series

[FFmpeg-devel,16/39] avcodec/libx265: Allow user-supplied buffers

Message ID HE1PR0301MB21545154B4B0081582ABB2D08F299@HE1PR0301MB2154.eurprd03.prod.outlook.com
State Accepted
Commit a4b334327895f17211b4bbbc19ebab41a7aa35dc
Headers show
Series [FFmpeg-devel,01/39] avcodec/audiotoolboxenc: Remove AV_CODEC_CAP_DR1 | expand

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 May 21, 2021, 9:17 a.m. UTC
Here the packet size is known before allocating the packet,
so that supporting user-supplied buffers is trivial.

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

Patch

diff --git a/libavcodec/libx265.c b/libavcodec/libx265.c
index a1bd205201..90658d3d9e 100644
--- a/libavcodec/libx265.c
+++ b/libavcodec/libx265.c
@@ -32,6 +32,7 @@ 
 #include "libavutil/opt.h"
 #include "libavutil/pixdesc.h"
 #include "avcodec.h"
+#include "encode.h"
 #include "internal.h"
 #include "packet_internal.h"
 
@@ -531,7 +532,7 @@  static int libx265_encode_frame(AVCodecContext *avctx, AVPacket *pkt,
     for (i = 0; i < nnal; i++)
         payload += nal[i].sizeBytes;
 
-    ret = ff_alloc_packet2(avctx, pkt, payload, payload);
+    ret = ff_get_encode_buffer(avctx, pkt, payload, 0);
     if (ret < 0) {
         av_log(avctx, AV_LOG_ERROR, "Error getting output packet.\n");
         return ret;
@@ -687,6 +688,9 @@  AVCodec ff_libx265_encoder = {
     .long_name        = NULL_IF_CONFIG_SMALL("libx265 H.265 / HEVC"),
     .type             = AVMEDIA_TYPE_VIDEO,
     .id               = AV_CODEC_ID_HEVC,
+    .capabilities     = AV_CODEC_CAP_DR1 | AV_CODEC_CAP_DELAY |
+                        AV_CODEC_CAP_OTHER_THREADS |
+                        AV_CODEC_CAP_ENCODER_REORDERED_OPAQUE,
     .init             = libx265_encode_init,
     .init_static_data = libx265_encode_init_csp,
     .encode2          = libx265_encode_frame,
@@ -694,8 +698,6 @@  AVCodec ff_libx265_encoder = {
     .priv_data_size   = sizeof(libx265Context),
     .priv_class       = &class,
     .defaults         = x265_defaults,
-    .capabilities     = AV_CODEC_CAP_DELAY | AV_CODEC_CAP_OTHER_THREADS |
-                        AV_CODEC_CAP_ENCODER_REORDERED_OPAQUE,
     .caps_internal    = FF_CODEC_CAP_AUTO_THREADS,
     .wrapper_name     = "libx265",
 };