avcodec/vp9: Use RefStruct-pool API for extradata

It avoids allocations and corresponding error checks.

Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
This commit is contained in:
Andreas Rheinhardt 2022-08-06 13:59:20 +02:00
parent 090d9956fd
commit 8c0350f57e
3 changed files with 11 additions and 18 deletions

View File

@ -100,7 +100,7 @@ static void vp9_tile_data_free(VP9TileData *td)
static void vp9_frame_unref(VP9Frame *f)
{
ff_thread_release_ext_buffer(&f->tf);
av_buffer_unref(&f->extradata);
ff_refstruct_unref(&f->extradata);
ff_refstruct_unref(&f->hwaccel_picture_private);
f->segmentation_map = NULL;
}
@ -116,8 +116,9 @@ static int vp9_frame_alloc(AVCodecContext *avctx, VP9Frame *f)
sz = 64 * s->sb_cols * s->sb_rows;
if (sz != s->frame_extradata_pool_size) {
av_buffer_pool_uninit(&s->frame_extradata_pool);
s->frame_extradata_pool = av_buffer_pool_init(sz * (1 + sizeof(VP9mvrefPair)), NULL);
ff_refstruct_pool_uninit(&s->frame_extradata_pool);
s->frame_extradata_pool = ff_refstruct_pool_alloc(sz * (1 + sizeof(VP9mvrefPair)),
FF_REFSTRUCT_POOL_FLAG_ZERO_EVERY_TIME);
if (!s->frame_extradata_pool) {
s->frame_extradata_pool_size = 0;
ret = AVERROR(ENOMEM);
@ -125,15 +126,14 @@ static int vp9_frame_alloc(AVCodecContext *avctx, VP9Frame *f)
}
s->frame_extradata_pool_size = sz;
}
f->extradata = av_buffer_pool_get(s->frame_extradata_pool);
f->extradata = ff_refstruct_pool_get(s->frame_extradata_pool);
if (!f->extradata) {
ret = AVERROR(ENOMEM);
goto fail;
}
memset(f->extradata->data, 0, f->extradata->size);
f->segmentation_map = f->extradata->data;
f->mv = (VP9mvrefPair *) (f->extradata->data + sz);
f->segmentation_map = f->extradata;
f->mv = (VP9mvrefPair *) ((char*)f->extradata + sz);
ret = ff_hwaccel_frame_priv_alloc(avctx, &f->hwaccel_picture_private);
if (ret < 0)
@ -154,9 +154,7 @@ static int vp9_frame_ref(VP9Frame *dst, VP9Frame *src)
if (ret < 0)
return ret;
dst->extradata = av_buffer_ref(src->extradata);
if (!dst->extradata)
goto fail;
dst->extradata = ff_refstruct_ref(src->extradata);
dst->segmentation_map = src->segmentation_map;
dst->mv = src->mv;
@ -166,10 +164,6 @@ static int vp9_frame_ref(VP9Frame *dst, VP9Frame *src)
src->hwaccel_picture_private);
return 0;
fail:
vp9_frame_unref(dst);
return AVERROR(ENOMEM);
}
static int update_size(AVCodecContext *avctx, int w, int h)
@ -1245,7 +1239,7 @@ static av_cold int vp9_decode_free(AVCodecContext *avctx)
vp9_frame_unref(&s->s.frames[i]);
av_frame_free(&s->s.frames[i].tf.f);
}
av_buffer_pool_uninit(&s->frame_extradata_pool);
ff_refstruct_pool_uninit(&s->frame_extradata_pool);
for (i = 0; i < 8; i++) {
ff_thread_release_ext_buffer(&s->s.refs[i]);
av_frame_free(&s->s.refs[i].f);

View File

@ -28,7 +28,6 @@
#include <stdint.h>
#include <stdatomic.h>
#include "libavutil/buffer.h"
#include "libavutil/mem_internal.h"
#include "libavutil/thread.h"
#include "libavutil/internal.h"
@ -161,7 +160,7 @@ typedef struct VP9Context {
uint8_t mvstep[3][2];
// frame specific buffer pools
AVBufferPool *frame_extradata_pool;
struct FFRefStructPool *frame_extradata_pool;
int frame_extradata_pool_size;
} VP9Context;

View File

@ -64,7 +64,7 @@ typedef struct VP9mvrefPair {
typedef struct VP9Frame {
ThreadFrame tf;
AVBufferRef *extradata;
void *extradata; ///< RefStruct reference
uint8_t *segmentation_map;
VP9mvrefPair *mv;
int uses_2pass;