diff mbox series

[FFmpeg-devel,11/39] avcodec/libvpxenc: Avoid copying data, allow user-supplied buffers

Message ID HE1PR0301MB2154423E2A4BA96424BF52828F299@HE1PR0301MB2154.eurprd03.prod.outlook.com
State Accepted
Commit 3280c6f938c8b16254bfb68af54089af467274c5
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 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@outlook.com>
---
 libavcodec/libvpxenc.c | 9 ++++++---
 1 file changed, 6 insertions(+), 3 deletions(-)

Comments

James Zern May 21, 2021, 7:28 p.m. UTC | #1
On Fri, May 21, 2021 at 2:19 AM Andreas Rheinhardt
<andreas.rheinhardt@outlook.com> wrote:
>
> 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@outlook.com>
> ---
>  libavcodec/libvpxenc.c | 9 ++++++---
>  1 file changed, 6 insertions(+), 3 deletions(-)
>

lgtm
diff mbox series

Patch

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,