[FFmpeg-devel] [PATCH 11/39] avcodec/libvpxenc: Avoid copying data, allow user-supplied buffers
Andreas Rheinhardt
andreas.rheinhardt at outlook.com
Fri May 21 12:17:14 EEST 2021
Here the packet size is known before allocating the packet because
the encoder provides said information (and works with internal buffers
itself), so one can use this information to avoid the implicit use of
another intermediate buffer for the packet data; and by switching to
ff_get_encode_buffer() one can also allow user-supplied buffers.
Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt at outlook.com>
---
libavcodec/libvpxenc.c | 9 ++++++---
1 file changed, 6 insertions(+), 3 deletions(-)
diff --git a/libavcodec/libvpxenc.c b/libavcodec/libvpxenc.c
index 8173af5dce..2d9e56837b 100644
--- a/libavcodec/libvpxenc.c
+++ b/libavcodec/libvpxenc.c
@@ -29,6 +29,7 @@
#include <vpx/vp8cx.h>
#include "avcodec.h"
+#include "encode.h"
#include "internal.h"
#include "libavutil/avassert.h"
#include "libvpx.h"
@@ -1173,7 +1174,7 @@ static inline void cx_pktcpy(struct FrameListData *dst,
static int storeframe(AVCodecContext *avctx, struct FrameListData *cx_frame,
AVPacket *pkt)
{
- int ret = ff_alloc_packet2(avctx, pkt, cx_frame->sz, 0);
+ int ret = ff_get_encode_buffer(avctx, pkt, cx_frame->sz, 0);
uint8_t *side_data;
if (ret >= 0) {
int pict_type;
@@ -1830,11 +1831,12 @@ const AVCodec ff_libvpx_vp8_encoder = {
.long_name = NULL_IF_CONFIG_SMALL("libvpx VP8"),
.type = AVMEDIA_TYPE_VIDEO,
.id = AV_CODEC_ID_VP8,
+ .capabilities = AV_CODEC_CAP_DR1 | AV_CODEC_CAP_DELAY |
+ AV_CODEC_CAP_OTHER_THREADS,
.priv_data_size = sizeof(VPxContext),
.init = vp8_init,
.encode2 = vpx_encode,
.close = vpx_free,
- .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_YUVA420P, AV_PIX_FMT_NONE },
.priv_class = &class_vp8,
@@ -1861,11 +1863,12 @@ AVCodec ff_libvpx_vp9_encoder = {
.long_name = NULL_IF_CONFIG_SMALL("libvpx VP9"),
.type = AVMEDIA_TYPE_VIDEO,
.id = AV_CODEC_ID_VP9,
+ .capabilities = AV_CODEC_CAP_DR1 | AV_CODEC_CAP_DELAY |
+ AV_CODEC_CAP_OTHER_THREADS,
.priv_data_size = sizeof(VPxContext),
.init = vp9_init,
.encode2 = vpx_encode,
.close = vpx_free,
- .capabilities = AV_CODEC_CAP_DELAY | AV_CODEC_CAP_OTHER_THREADS,
.caps_internal = FF_CODEC_CAP_AUTO_THREADS,
.profiles = NULL_IF_CONFIG_SMALL(ff_vp9_profiles),
.priv_class = &class_vp9,
--
2.27.0
More information about the ffmpeg-devel
mailing list