aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAndreas Rheinhardt <andreas.rheinhardt@outlook.com>2021-04-25 01:43:26 +0200
committerAndreas Rheinhardt <andreas.rheinhardt@outlook.com>2021-05-23 14:50:46 +0200
commit3280c6f938c8b16254bfb68af54089af467274c5 (patch)
treee90ee0f0e0b188be31f5471b23bf157e4530f1d6
parentd8e66ec1d7233541fd84205cb10e8e6ff87167de (diff)
downloadffmpeg-3280c6f938c8b16254bfb68af54089af467274c5.tar.gz
avcodec/libvpxenc: Avoid copying data, allow user-supplied buffers
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. Reviewed-by: James Almer <jamrial@gmail.com> Reviewed-by: James Zern <jzern@google.com> Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
-rw-r--r--libavcodec/libvpxenc.c9
1 files 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,