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:
parent
090d9956fd
commit
8c0350f57e
|
@ -100,7 +100,7 @@ static void vp9_tile_data_free(VP9TileData *td)
|
||||||
static void vp9_frame_unref(VP9Frame *f)
|
static void vp9_frame_unref(VP9Frame *f)
|
||||||
{
|
{
|
||||||
ff_thread_release_ext_buffer(&f->tf);
|
ff_thread_release_ext_buffer(&f->tf);
|
||||||
av_buffer_unref(&f->extradata);
|
ff_refstruct_unref(&f->extradata);
|
||||||
ff_refstruct_unref(&f->hwaccel_picture_private);
|
ff_refstruct_unref(&f->hwaccel_picture_private);
|
||||||
f->segmentation_map = NULL;
|
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;
|
sz = 64 * s->sb_cols * s->sb_rows;
|
||||||
if (sz != s->frame_extradata_pool_size) {
|
if (sz != s->frame_extradata_pool_size) {
|
||||||
av_buffer_pool_uninit(&s->frame_extradata_pool);
|
ff_refstruct_pool_uninit(&s->frame_extradata_pool);
|
||||||
s->frame_extradata_pool = av_buffer_pool_init(sz * (1 + sizeof(VP9mvrefPair)), NULL);
|
s->frame_extradata_pool = ff_refstruct_pool_alloc(sz * (1 + sizeof(VP9mvrefPair)),
|
||||||
|
FF_REFSTRUCT_POOL_FLAG_ZERO_EVERY_TIME);
|
||||||
if (!s->frame_extradata_pool) {
|
if (!s->frame_extradata_pool) {
|
||||||
s->frame_extradata_pool_size = 0;
|
s->frame_extradata_pool_size = 0;
|
||||||
ret = AVERROR(ENOMEM);
|
ret = AVERROR(ENOMEM);
|
||||||
|
@ -125,15 +126,14 @@ static int vp9_frame_alloc(AVCodecContext *avctx, VP9Frame *f)
|
||||||
}
|
}
|
||||||
s->frame_extradata_pool_size = sz;
|
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) {
|
if (!f->extradata) {
|
||||||
ret = AVERROR(ENOMEM);
|
ret = AVERROR(ENOMEM);
|
||||||
goto fail;
|
goto fail;
|
||||||
}
|
}
|
||||||
memset(f->extradata->data, 0, f->extradata->size);
|
|
||||||
|
|
||||||
f->segmentation_map = f->extradata->data;
|
f->segmentation_map = f->extradata;
|
||||||
f->mv = (VP9mvrefPair *) (f->extradata->data + sz);
|
f->mv = (VP9mvrefPair *) ((char*)f->extradata + sz);
|
||||||
|
|
||||||
ret = ff_hwaccel_frame_priv_alloc(avctx, &f->hwaccel_picture_private);
|
ret = ff_hwaccel_frame_priv_alloc(avctx, &f->hwaccel_picture_private);
|
||||||
if (ret < 0)
|
if (ret < 0)
|
||||||
|
@ -154,9 +154,7 @@ static int vp9_frame_ref(VP9Frame *dst, VP9Frame *src)
|
||||||
if (ret < 0)
|
if (ret < 0)
|
||||||
return ret;
|
return ret;
|
||||||
|
|
||||||
dst->extradata = av_buffer_ref(src->extradata);
|
dst->extradata = ff_refstruct_ref(src->extradata);
|
||||||
if (!dst->extradata)
|
|
||||||
goto fail;
|
|
||||||
|
|
||||||
dst->segmentation_map = src->segmentation_map;
|
dst->segmentation_map = src->segmentation_map;
|
||||||
dst->mv = src->mv;
|
dst->mv = src->mv;
|
||||||
|
@ -166,10 +164,6 @@ static int vp9_frame_ref(VP9Frame *dst, VP9Frame *src)
|
||||||
src->hwaccel_picture_private);
|
src->hwaccel_picture_private);
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
fail:
|
|
||||||
vp9_frame_unref(dst);
|
|
||||||
return AVERROR(ENOMEM);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static int update_size(AVCodecContext *avctx, int w, int h)
|
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]);
|
vp9_frame_unref(&s->s.frames[i]);
|
||||||
av_frame_free(&s->s.frames[i].tf.f);
|
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++) {
|
for (i = 0; i < 8; i++) {
|
||||||
ff_thread_release_ext_buffer(&s->s.refs[i]);
|
ff_thread_release_ext_buffer(&s->s.refs[i]);
|
||||||
av_frame_free(&s->s.refs[i].f);
|
av_frame_free(&s->s.refs[i].f);
|
||||||
|
|
|
@ -28,7 +28,6 @@
|
||||||
#include <stdint.h>
|
#include <stdint.h>
|
||||||
#include <stdatomic.h>
|
#include <stdatomic.h>
|
||||||
|
|
||||||
#include "libavutil/buffer.h"
|
|
||||||
#include "libavutil/mem_internal.h"
|
#include "libavutil/mem_internal.h"
|
||||||
#include "libavutil/thread.h"
|
#include "libavutil/thread.h"
|
||||||
#include "libavutil/internal.h"
|
#include "libavutil/internal.h"
|
||||||
|
@ -161,7 +160,7 @@ typedef struct VP9Context {
|
||||||
uint8_t mvstep[3][2];
|
uint8_t mvstep[3][2];
|
||||||
|
|
||||||
// frame specific buffer pools
|
// frame specific buffer pools
|
||||||
AVBufferPool *frame_extradata_pool;
|
struct FFRefStructPool *frame_extradata_pool;
|
||||||
int frame_extradata_pool_size;
|
int frame_extradata_pool_size;
|
||||||
} VP9Context;
|
} VP9Context;
|
||||||
|
|
||||||
|
|
|
@ -64,7 +64,7 @@ typedef struct VP9mvrefPair {
|
||||||
|
|
||||||
typedef struct VP9Frame {
|
typedef struct VP9Frame {
|
||||||
ThreadFrame tf;
|
ThreadFrame tf;
|
||||||
AVBufferRef *extradata;
|
void *extradata; ///< RefStruct reference
|
||||||
uint8_t *segmentation_map;
|
uint8_t *segmentation_map;
|
||||||
VP9mvrefPair *mv;
|
VP9mvrefPair *mv;
|
||||||
int uses_2pass;
|
int uses_2pass;
|
||||||
|
|
Loading…
Reference in New Issue