aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorLynne <dev@lynne.ee>2024-08-21 23:27:15 +0800
committerLynne <dev@lynne.ee>2024-09-09 07:05:24 +0200
commit9db68ed042a9043362d57c79945f6a8d936f9dba (patch)
tree887988d3bf3186cbf552be7a233880fd5c96840a
parentfdf8025eb64c99567eadbebfd488a8e04c028a10 (diff)
downloadffmpeg-9db68ed042a9043362d57c79945f6a8d936f9dba.tar.gz
hw_base_encode: refactor picture allocation/freeing
This commit cleans up and refactors the mess of private state upon private state that used to be. Now, FFHWBaseEncodePicture is fully initialized upon call-time, and, most importantly, this lets APIs which require initialization data for frames (VkImageViews) to initialize this for both the input image, and the reconstruction (DPB) image. Signed-off-by: Tong Wu <wutong1208@outlook.com>
-rw-r--r--libavcodec/d3d12va_encode.c68
-rw-r--r--libavcodec/d3d12va_encode.h4
-rw-r--r--libavcodec/d3d12va_encode_hevc.c12
-rw-r--r--libavcodec/hw_base_encode.c39
-rw-r--r--libavcodec/hw_base_encode.h22
-rw-r--r--libavcodec/vaapi_encode.c89
-rw-r--r--libavcodec/vaapi_encode.h12
-rw-r--r--libavcodec/vaapi_encode_av1.c26
-rw-r--r--libavcodec/vaapi_encode_h264.c67
-rw-r--r--libavcodec/vaapi_encode_h265.c24
-rw-r--r--libavcodec/vaapi_encode_mjpeg.c8
-rw-r--r--libavcodec/vaapi_encode_mpeg2.c15
-rw-r--r--libavcodec/vaapi_encode_vp8.c10
-rw-r--r--libavcodec/vaapi_encode_vp9.c16
14 files changed, 201 insertions, 211 deletions
diff --git a/libavcodec/d3d12va_encode.c b/libavcodec/d3d12va_encode.c
index 9ee9da41e3..d437750598 100644
--- a/libavcodec/d3d12va_encode.c
+++ b/libavcodec/d3d12va_encode.c
@@ -107,10 +107,10 @@ static int d3d12va_discard_command_allocator(AVCodecContext *avctx, ID3D12Comman
}
static int d3d12va_encode_wait(AVCodecContext *avctx,
- D3D12VAEncodePicture *pic)
+ FFHWBaseEncodePicture *base_pic)
{
- D3D12VAEncodeContext *ctx = avctx->priv_data;
- FFHWBaseEncodePicture *base_pic = &pic->base;
+ D3D12VAEncodeContext *ctx = avctx->priv_data;
+ D3D12VAEncodePicture *pic = base_pic->priv;
uint64_t completion;
av_assert0(base_pic->encode_issued);
@@ -186,12 +186,12 @@ static int d3d12va_encode_create_metadata_buffers(AVCodecContext *avctx,
}
static int d3d12va_encode_issue(AVCodecContext *avctx,
- const FFHWBaseEncodePicture *base_pic)
+ FFHWBaseEncodePicture *base_pic)
{
FFHWBaseEncodeContext *base_ctx = avctx->priv_data;
D3D12VAEncodeContext *ctx = avctx->priv_data;
+ D3D12VAEncodePicture *pic = base_pic->priv;
AVD3D12VAFramesContext *frames_hwctx = base_ctx->input_frames->hwctx;
- D3D12VAEncodePicture *pic = (D3D12VAEncodePicture *)base_pic;
int err, i, j;
HRESULT hr;
char data[MAX_PARAM_BUFFER_SIZE];
@@ -288,7 +288,7 @@ static int d3d12va_encode_issue(AVCodecContext *avctx,
goto fail;
if (ctx->codec->init_picture_params) {
- err = ctx->codec->init_picture_params(avctx, pic);
+ err = ctx->codec->init_picture_params(avctx, base_pic);
if (err < 0) {
av_log(avctx, AV_LOG_ERROR, "Failed to initialise picture "
"parameters: %d.\n", err);
@@ -333,9 +333,9 @@ static int d3d12va_encode_issue(AVCodecContext *avctx,
i = 0;
for (j = 0; j < base_pic->nb_refs[0]; j++)
- d3d12_refs.ppTexture2Ds[i++] = ((D3D12VAEncodePicture *)base_pic->refs[0][j])->recon_surface->texture;
+ d3d12_refs.ppTexture2Ds[i++] = ((D3D12VAEncodePicture *)base_pic->refs[0][j]->priv)->recon_surface->texture;
for (j = 0; j < base_pic->nb_refs[1]; j++)
- d3d12_refs.ppTexture2Ds[i++] = ((D3D12VAEncodePicture *)base_pic->refs[1][j])->recon_surface->texture;
+ d3d12_refs.ppTexture2Ds[i++] = ((D3D12VAEncodePicture *)base_pic->refs[1][j]->priv)->recon_surface->texture;
}
input_args.PictureControlDesc.IntraRefreshFrameIndex = 0;
@@ -515,10 +515,11 @@ fail:
}
static int d3d12va_encode_discard(AVCodecContext *avctx,
- D3D12VAEncodePicture *pic)
+ FFHWBaseEncodePicture *base_pic)
{
- FFHWBaseEncodePicture *base_pic = &pic->base;
- d3d12va_encode_wait(avctx, pic);
+ D3D12VAEncodePicture *pic = base_pic->priv;
+
+ d3d12va_encode_wait(avctx, base_pic);
if (pic->output_buffer_ref) {
av_log(avctx, AV_LOG_DEBUG, "Discard output for pic "
@@ -560,44 +561,33 @@ static int d3d12va_encode_free_rc_params(AVCodecContext *avctx)
return 0;
}
-static FFHWBaseEncodePicture *d3d12va_encode_alloc(AVCodecContext *avctx,
- const AVFrame *frame)
+static int d3d12va_encode_init(AVCodecContext *avctx, FFHWBaseEncodePicture *pic)
{
D3D12VAEncodeContext *ctx = avctx->priv_data;
- D3D12VAEncodePicture *pic;
-
- pic = av_mallocz(sizeof(*pic));
- if (!pic)
- return NULL;
+ D3D12VAEncodePicture *priv = pic->priv;
+ AVFrame *frame = pic->input_image;
if (ctx->codec->picture_priv_data_size > 0) {
- pic->base.priv_data = av_mallocz(ctx->codec->picture_priv_data_size);
- if (!pic->base.priv_data) {
- av_freep(&pic);
- return NULL;
- }
+ pic->codec_priv = av_mallocz(ctx->codec->picture_priv_data_size);
+ if (!pic->codec_priv)
+ return AVERROR(ENOMEM);
}
- pic->input_surface = (AVD3D12VAFrame *)frame->data[0];
+ priv->input_surface = (AVD3D12VAFrame *)frame->data[0];
- return &pic->base;
+ return 0;
}
-static int d3d12va_encode_free(AVCodecContext *avctx,
- FFHWBaseEncodePicture *base_pic)
+static int d3d12va_encode_free(AVCodecContext *avctx, FFHWBaseEncodePicture *pic)
{
D3D12VAEncodeContext *ctx = avctx->priv_data;
- D3D12VAEncodePicture *pic = (D3D12VAEncodePicture *)base_pic;
+ D3D12VAEncodePicture *priv = pic->priv;
- if (base_pic->encode_issued)
+ if (pic->encode_issued)
d3d12va_encode_discard(avctx, pic);
if (ctx->codec->free_picture_params)
- ctx->codec->free_picture_params(pic);
-
- ff_hw_base_encode_free(base_pic);
-
- av_free(pic);
+ ctx->codec->free_picture_params(priv);
return 0;
}
@@ -680,14 +670,14 @@ end:
}
static int d3d12va_encode_output(AVCodecContext *avctx,
- const FFHWBaseEncodePicture *base_pic, AVPacket *pkt)
+ FFHWBaseEncodePicture *base_pic, AVPacket *pkt)
{
FFHWBaseEncodeContext *base_ctx = avctx->priv_data;
- D3D12VAEncodePicture *pic = (D3D12VAEncodePicture *)base_pic;
+ D3D12VAEncodePicture *pic = base_pic->priv;
AVPacket *pkt_ptr = pkt;
int err;
- err = d3d12va_encode_wait(avctx, pic);
+ err = d3d12va_encode_wait(avctx, base_pic);
if (err < 0)
return err;
@@ -1389,7 +1379,9 @@ static int d3d12va_encode_create_recon_frames(AVCodecContext *avctx)
}
static const FFHWEncodePictureOperation d3d12va_type = {
- .alloc = &d3d12va_encode_alloc,
+ .priv_size = sizeof(D3D12VAEncodePicture),
+
+ .init = &d3d12va_encode_init,
.issue = &d3d12va_encode_issue,
diff --git a/libavcodec/d3d12va_encode.h b/libavcodec/d3d12va_encode.h
index 51440428e4..3b0b8153d5 100644
--- a/libavcodec/d3d12va_encode.h
+++ b/libavcodec/d3d12va_encode.h
@@ -40,8 +40,6 @@ extern const AVCodecHWConfigInternal *const ff_d3d12va_encode_hw_configs[];
#define D3D12VA_VIDEO_ENC_ASYNC_DEPTH 8
typedef struct D3D12VAEncodePicture {
- FFHWBaseEncodePicture base;
-
int header_size;
int aligned_header_size;
@@ -303,7 +301,7 @@ typedef struct D3D12VAEncodeType {
int (*init_sequence_params)(AVCodecContext *avctx);
int (*init_picture_params)(AVCodecContext *avctx,
- D3D12VAEncodePicture *pic);
+ FFHWBaseEncodePicture *base_pic);
void (*free_picture_params)(D3D12VAEncodePicture *pic);
diff --git a/libavcodec/d3d12va_encode_hevc.c b/libavcodec/d3d12va_encode_hevc.c
index 4a12ddd0dc..571ce57385 100644
--- a/libavcodec/d3d12va_encode_hevc.c
+++ b/libavcodec/d3d12va_encode_hevc.c
@@ -748,12 +748,12 @@ static void d3d12va_encode_hevc_free_picture_params(D3D12VAEncodePicture *pic)
}
static int d3d12va_encode_hevc_init_picture_params(AVCodecContext *avctx,
- D3D12VAEncodePicture *pic)
+ FFHWBaseEncodePicture *base_pic)
{
- FFHWBaseEncodePicture *base_pic = &pic->base;
- D3D12VAEncodeHEVCPicture *hpic = base_pic->priv_data;
+ D3D12VAEncodePicture *pic = base_pic->priv;
+ D3D12VAEncodeHEVCPicture *hpic = base_pic->codec_priv;
FFHWBaseEncodePicture *prev = base_pic->prev;
- D3D12VAEncodeHEVCPicture *hprev = prev ? prev->priv_data : NULL;
+ D3D12VAEncodeHEVCPicture *hprev = prev ? prev->codec_priv : NULL;
D3D12_VIDEO_ENCODER_REFERENCE_PICTURE_DESCRIPTOR_HEVC *pd = NULL;
UINT *ref_list0 = NULL, *ref_list1 = NULL;
int i, idx = 0;
@@ -807,7 +807,7 @@ static int d3d12va_encode_hevc_init_picture_params(AVCodecContext *avctx,
D3D12VAEncodeHEVCPicture *href;
av_assert0(ref && ref->encode_order < base_pic->encode_order);
- href = ref->priv_data;
+ href = ref->codec_priv;
ref_list0[i] = idx;
pd[idx].ReconstructedPictureResourceIndex = idx;
@@ -828,7 +828,7 @@ static int d3d12va_encode_hevc_init_picture_params(AVCodecContext *avctx,
D3D12VAEncodeHEVCPicture *href;
av_assert0(ref && ref->encode_order < base_pic->encode_order);
- href = ref->priv_data;
+ href = ref->codec_priv;
ref_list1[i] = idx;
pd[idx].ReconstructedPictureResourceIndex = idx;
diff --git a/libavcodec/hw_base_encode.c b/libavcodec/hw_base_encode.c
index c1346e866c..35dac6e596 100644
--- a/libavcodec/hw_base_encode.c
+++ b/libavcodec/hw_base_encode.c
@@ -27,6 +27,19 @@
#include "avcodec.h"
#include "hw_base_encode.h"
+static int base_encode_pic_free(FFHWBaseEncodePicture *pic)
+{
+ av_frame_free(&pic->input_image);
+ av_frame_free(&pic->recon_image);
+
+ av_buffer_unref(&pic->opaque_ref);
+ av_freep(&pic->codec_priv);
+ av_freep(&pic->priv);
+ av_free(pic);
+
+ return 0;
+}
+
static void hw_base_encode_add_ref(FFHWBaseEncodePicture *pic,
FFHWBaseEncodePicture *target,
int is_ref, int in_dpb, int prev)
@@ -370,6 +383,7 @@ static int hw_base_encode_clear_old(AVCodecContext *avctx, FFHWBaseEncodeContext
else
ctx->pic_start = next;
ctx->op->free(avctx, pic);
+ base_encode_pic_free(pic);
} else {
prev = pic;
}
@@ -416,7 +430,7 @@ static int hw_base_encode_send_frame(AVCodecContext *avctx, FFHWBaseEncodeContex
if (err < 0)
return err;
- pic = ctx->op->alloc(avctx, frame);
+ pic = av_mallocz(sizeof(*pic));
if (!pic)
return AVERROR(ENOMEM);
@@ -432,6 +446,12 @@ static int hw_base_encode_send_frame(AVCodecContext *avctx, FFHWBaseEncodeContex
goto fail;
}
+ pic->priv = av_mallocz(ctx->op->priv_size);
+ if (!pic->priv) {
+ err = AVERROR(ENOMEM);
+ goto fail;
+ }
+
if (ctx->input_order == 0 || frame->pict_type == AV_PICTURE_TYPE_I)
pic->force_idr = 1;
@@ -467,6 +487,9 @@ static int hw_base_encode_send_frame(AVCodecContext *avctx, FFHWBaseEncodeContex
ctx->pic_end = pic;
}
+ err = ctx->op->init(avctx, pic);
+ if (err < 0)
+ goto fail;
} else {
ctx->end_of_stream = 1;
@@ -480,6 +503,7 @@ static int hw_base_encode_send_frame(AVCodecContext *avctx, FFHWBaseEncodeContex
fail:
ctx->op->free(avctx, pic);
+ base_encode_pic_free(pic);
return err;
}
@@ -529,7 +553,7 @@ int ff_hw_base_encode_receive_packet(FFHWBaseEncodeContext *ctx,
AVFrame *frame = ctx->frame;
int err;
- av_assert0(ctx->op && ctx->op->alloc && ctx->op->issue &&
+ av_assert0(ctx->op && ctx->op->init && ctx->op->issue &&
ctx->op->output && ctx->op->free);
start:
@@ -737,17 +761,6 @@ fail:
return err;
}
-int ff_hw_base_encode_free(FFHWBaseEncodePicture *pic)
-{
- av_frame_free(&pic->input_image);
- av_frame_free(&pic->recon_image);
-
- av_buffer_unref(&pic->opaque_ref);
- av_freep(&pic->priv_data);
-
- return 0;
-}
-
int ff_hw_base_encode_init(AVCodecContext *avctx, FFHWBaseEncodeContext *ctx)
{
ctx->log_ctx = (void *)avctx;
diff --git a/libavcodec/hw_base_encode.h b/libavcodec/hw_base_encode.h
index ac0cc7b80c..e30b1e60ad 100644
--- a/libavcodec/hw_base_encode.h
+++ b/libavcodec/hw_base_encode.h
@@ -59,6 +59,11 @@ enum {
};
typedef struct FFHWBaseEncodePicture {
+ // API-specific private data
+ void *priv;
+ // Codec-specific private data
+ void *codec_priv;
+
struct FFHWBaseEncodePicture *next;
int64_t display_order;
@@ -78,8 +83,6 @@ typedef struct FFHWBaseEncodePicture {
AVFrame *input_image;
AVFrame *recon_image;
- void *priv_data;
-
// Whether this picture is a reference picture.
int is_reference;
@@ -104,15 +107,16 @@ typedef struct FFHWBaseEncodePicture {
} FFHWBaseEncodePicture;
typedef struct FFHWEncodePictureOperation {
- // Alloc memory for the picture structure and initialize the API-specific internals
- // based of the given frame.
- FFHWBaseEncodePicture * (*alloc)(AVCodecContext *avctx, const AVFrame *frame);
+ // Size of API-specific internal picture data
+ size_t priv_size;
+ // Initialize API-specific internals
+ int (*init)(AVCodecContext *avctx, FFHWBaseEncodePicture *pic);
// Issue the picture structure, which will send the frame surface to HW Encode API.
- int (*issue)(AVCodecContext *avctx, const FFHWBaseEncodePicture *base_pic);
+ int (*issue)(AVCodecContext *avctx, FFHWBaseEncodePicture *pic);
// Get the output AVPacket.
- int (*output)(AVCodecContext *avctx, const FFHWBaseEncodePicture *base_pic, AVPacket *pkt);
+ int (*output)(AVCodecContext *avctx, FFHWBaseEncodePicture *pic, AVPacket *pkt);
// Free the picture structure.
- int (*free)(AVCodecContext *avctx, FFHWBaseEncodePicture *base_pic);
+ int (*free)(AVCodecContext *avctx, FFHWBaseEncodePicture *pic);
} FFHWEncodePictureOperation;
typedef struct FFHWBaseEncodeContext {
@@ -228,8 +232,6 @@ int ff_hw_base_init_gop_structure(FFHWBaseEncodeContext *ctx, AVCodecContext *av
int ff_hw_base_get_recon_format(FFHWBaseEncodeContext *ctx, const void *hwconfig,
enum AVPixelFormat *fmt);
-int ff_hw_base_encode_free(FFHWBaseEncodePicture *pic);
-
int ff_hw_base_encode_init(AVCodecContext *avctx, FFHWBaseEncodeContext *ctx);
int ff_hw_base_encode_close(FFHWBaseEncodeContext *ctx);
diff --git a/libavcodec/vaapi_encode.c b/libavcodec/vaapi_encode.c
index afdf3fe3d8..b72e9035cb 100644
--- a/libavcodec/vaapi_encode.c
+++ b/libavcodec/vaapi_encode.c
@@ -135,14 +135,13 @@ static int vaapi_encode_make_misc_param_buffer(AVCodecContext *avctx,
buffer, buffer_size);
}
-static int vaapi_encode_wait(AVCodecContext *avctx,
- VAAPIEncodePicture *pic)
+static int vaapi_encode_wait(AVCodecContext *avctx, FFHWBaseEncodePicture *base_pic)
{
#if VA_CHECK_VERSION(1, 9, 0)
FFHWBaseEncodeContext *base_ctx = avctx->priv_data;
#endif
VAAPIEncodeContext *ctx = avctx->priv_data;
- FFHWBaseEncodePicture *base_pic = &pic->base;
+ VAAPIEncodePicture *pic = base_pic->priv;
VAStatus vas;
av_assert0(base_pic->encode_issued);
@@ -267,11 +266,11 @@ static int vaapi_encode_make_tile_slice(AVCodecContext *avctx,
}
static int vaapi_encode_issue(AVCodecContext *avctx,
- const FFHWBaseEncodePicture *base_pic)
+ FFHWBaseEncodePicture *base_pic)
{
FFHWBaseEncodeContext *base_ctx = avctx->priv_data;
VAAPIEncodeContext *ctx = avctx->priv_data;
- VAAPIEncodePicture *pic = (VAAPIEncodePicture*)base_pic;
+ VAAPIEncodePicture *pic = base_pic->priv;
VAAPIEncodeSlice *slice;
VAStatus vas;
int err, i;
@@ -364,7 +363,7 @@ static int vaapi_encode_issue(AVCodecContext *avctx,
}
if (ctx->codec->init_picture_params) {
- err = ctx->codec->init_picture_params(avctx, pic);
+ err = ctx->codec->init_picture_params(avctx, base_pic);
if (err < 0) {
av_log(avctx, AV_LOG_ERROR, "Failed to initialise picture "
"parameters: %d.\n", err);
@@ -410,7 +409,7 @@ static int vaapi_encode_issue(AVCodecContext *avctx,
if (ctx->va_packed_headers & VA_ENC_PACKED_HEADER_PICTURE &&
ctx->codec->write_picture_header) {
bit_len = 8 * sizeof(data);
- err = ctx->codec->write_picture_header(avctx, pic, data, &bit_len);
+ err = ctx->codec->write_picture_header(avctx, base_pic, data, &bit_len);
if (err < 0) {
av_log(avctx, AV_LOG_ERROR, "Failed to write per-picture "
"header: %d.\n", err);
@@ -427,7 +426,7 @@ static int vaapi_encode_issue(AVCodecContext *avctx,
for (i = 0;; i++) {
size_t len = sizeof(data);
int type;
- err = ctx->codec->write_extra_buffer(avctx, pic, i, &type,
+ err = ctx->codec->write_extra_buffer(avctx, base_pic, i, &type,
data, &len);
if (err == AVERROR_EOF)
break;
@@ -449,7 +448,7 @@ static int vaapi_encode_issue(AVCodecContext *avctx,
for (i = 0;; i++) {
int type;
bit_len = 8 * sizeof(data);
- err = ctx->codec->write_extra_header(avctx, pic, i, &type,
+ err = ctx->codec->write_extra_header(avctx, base_pic, i, &type,
data, &bit_len);
if (err == AVERROR_EOF)
break;
@@ -493,7 +492,7 @@ static int vaapi_encode_issue(AVCodecContext *avctx,
}
if (ctx->codec->init_slice_params) {
- err = ctx->codec->init_slice_params(avctx, pic, slice);
+ err = ctx->codec->init_slice_params(avctx, base_pic, slice);
if (err < 0) {
av_log(avctx, AV_LOG_ERROR, "Failed to initialise slice "
"parameters: %d.\n", err);
@@ -773,15 +772,15 @@ end:
}
static int vaapi_encode_output(AVCodecContext *avctx,
- const FFHWBaseEncodePicture *base_pic, AVPacket *pkt)
+ FFHWBaseEncodePicture *base_pic, AVPacket *pkt)
{
FFHWBaseEncodeContext *base_ctx = avctx->priv_data;
VAAPIEncodeContext *ctx = avctx->priv_data;
- VAAPIEncodePicture *pic = (VAAPIEncodePicture*)base_pic;
+ VAAPIEncodePicture *pic = base_pic->priv;
AVPacket *pkt_ptr = pkt;
int err;
- err = vaapi_encode_wait(avctx, pic);
+ err = vaapi_encode_wait(avctx, base_pic);
if (err < 0)
return err;
@@ -820,12 +819,11 @@ end:
return err;
}
-static int vaapi_encode_discard(AVCodecContext *avctx,
- VAAPIEncodePicture *pic)
+static int vaapi_encode_discard(AVCodecContext *avctx, FFHWBaseEncodePicture *base_pic)
{
- FFHWBaseEncodePicture *base_pic = &pic->base;
+ VAAPIEncodePicture *pic = base_pic->priv;
- vaapi_encode_wait(avctx, pic);
+ vaapi_encode_wait(avctx, base_pic);
if (pic->output_buffer_ref) {
av_log(avctx, AV_LOG_DEBUG, "Discard output for pic "
@@ -839,56 +837,45 @@ static int vaapi_encode_discard(AVCodecContext *avctx,
return 0;
}
-static FFHWBaseEncodePicture *vaapi_encode_alloc(AVCodecContext *avctx,
- const AVFrame *frame)
+static int vaapi_encode_init(AVCodecContext *avctx, FFHWBaseEncodePicture *pic)
{
VAAPIEncodeContext *ctx = avctx->priv_data;
- VAAPIEncodePicture *pic;
-
- pic = av_mallocz(sizeof(*pic));
- if (!pic)
- return NULL;
+ VAAPIEncodePicture *priv = pic->priv;
+ AVFrame *frame = pic->input_image;
if (ctx->codec->picture_priv_data_size > 0) {
- pic->base.priv_data = av_mallocz(ctx->codec->picture_priv_data_size);
- if (!pic->base.priv_data) {
- av_freep(&pic);
- return NULL;
- }
+ pic->codec_priv = av_mallocz(ctx->codec->picture_priv_data_size);
+ if (!pic->codec_priv)
+ return AVERROR(ENOMEM);
}
- pic->input_surface = (VASurfaceID)(uintptr_t)frame->data[3];
- pic->recon_surface = VA_INVALID_ID;
- pic->output_buffer = VA_INVALID_ID;
+ priv->input_surface = (VASurfaceID)(uintptr_t)frame->data[3];
+ priv->recon_surface = VA_INVALID_ID;
+ priv->output_buffer = VA_INVALID_ID;
- return &pic->base;
+ return 0;
}
-static int vaapi_encode_free(AVCodecContext *avctx,
- FFHWBaseEncodePicture *base_pic)
+static int vaapi_encode_free(AVCodecContext *avctx, FFHWBaseEncodePicture *pic)
{
- VAAPIEncodePicture *pic = (VAAPIEncodePicture*)base_pic;
+ VAAPIEncodePicture *priv = pic->priv;
int i;
- if (base_pic->encode_issued)
+ if (pic->encode_issued)
vaapi_encode_discard(avctx, pic);
- if (pic->slices) {
- for (i = 0; i < pic->nb_slices; i++)
- av_freep(&pic->slices[i].codec_slice_params);
+ if (priv->slices) {
+ for (i = 0; i < priv->nb_slices; i++)
+ av_freep(&priv->slices[i].codec_slice_params);
}
- ff_hw_base_encode_free(base_pic);
-
- av_freep(&pic->param_buffers);
- av_freep(&pic->slices);
+ av_freep(&priv->param_buffers);
+ av_freep(&priv->slices);
// Output buffer should already be destroyed.
- av_assert0(pic->output_buffer == VA_INVALID_ID);
+ av_assert0(priv->output_buffer == VA_INVALID_ID);
- av_freep(&pic->codec_picture_params);
- av_freep(&pic->roi);
-
- av_free(pic);
+ av_freep(&priv->codec_picture_params);
+ av_freep(&priv->roi);
return 0;
}
@@ -2090,7 +2077,9 @@ static av_cold int vaapi_encode_create_recon_frames(AVCodecContext *avctx)
}
static const FFHWEncodePictureOperation vaapi_op = {
- .alloc = &vaapi_encode_alloc,
+ .priv_size = sizeof(VAAPIEncodePicture),
+
+ .init = &vaapi_encode_init,
.issue = &vaapi_encode_issue,
diff --git a/libavcodec/vaapi_encode.h b/libavcodec/vaapi_encode.h
index d76cdb8662..c4f85397a2 100644
--- a/libavcodec/vaapi_encode.h
+++ b/libavcodec/vaapi_encode.h
@@ -63,8 +63,6 @@ typedef struct VAAPIEncodeSlice {
} VAAPIEncodeSlice;
typedef struct VAAPIEncodePicture {
- FFHWBaseEncodePicture base;
-
#if VA_CHECK_VERSION(1, 0, 0)
// ROI regions.
VAEncROI *roi;
@@ -301,9 +299,9 @@ typedef struct VAAPIEncodeType {
// Fill the parameter structures.
int (*init_sequence_params)(AVCodecContext *avctx);
int (*init_picture_params)(AVCodecContext *avctx,
- VAAPIEncodePicture *pic);
+ FFHWBaseEncodePicture *pic);
int (*init_slice_params)(AVCodecContext *avctx,
- VAAPIEncodePicture *pic,
+ FFHWBaseEncodePicture *pic,
VAAPIEncodeSlice *slice);
// The type used by the packed header: this should look like
@@ -318,7 +316,7 @@ typedef struct VAAPIEncodeType {
int (*write_sequence_header)(AVCodecContext *avctx,
char *data, size_t *data_len);
int (*write_picture_header)(AVCodecContext *avctx,
- VAAPIEncodePicture *pic,
+ FFHWBaseEncodePicture *pic,
char *data, size_t *data_len);
int (*write_slice_header)(AVCodecContext *avctx,
VAAPIEncodePicture *pic,
@@ -330,7 +328,7 @@ typedef struct VAAPIEncodeType {
// with increasing index argument until AVERROR_EOF is
// returned.
int (*write_extra_buffer)(AVCodecContext *avctx,
- VAAPIEncodePicture *pic,
+ FFHWBaseEncodePicture *pic,
int index, int *type,
char *data, size_t *data_len);
@@ -338,7 +336,7 @@ typedef struct VAAPIEncodeType {
// with increasing index argument until AVERROR_EOF is
// returned.
int (*write_extra_header)(AVCodecContext *avctx,
- VAAPIEncodePicture *pic,
+ FFHWBaseEncodePicture *pic,
int index, int *type,
char *data, size_t *data_len);
} VAAPIEncodeType;
diff --git a/libavcodec/vaapi_encode_av1.c b/libavcodec/vaapi_encode_av1.c
index dfdb424185..6d1be9fc07 100644
--- a/libavcodec/vaapi_encode_av1.c
+++ b/libavcodec/vaapi_encode_av1.c
@@ -466,12 +466,12 @@ end:
}
static int vaapi_encode_av1_init_picture_params(AVCodecContext *avctx,
- VAAPIEncodePicture *vaapi_pic)
+ FFHWBaseEncodePicture *pic)
{
VAAPIEncodeContext *ctx = avctx->priv_data;
VAAPIEncodeAV1Context *priv = avctx->priv_data;
- const FFHWBaseEncodePicture *pic = &vaapi_pic->base;
- VAAPIEncodeAV1Picture *hpic = pic->priv_data;
+ VAAPIEncodePicture *vaapi_pic = pic->priv;
+ VAAPIEncodeAV1Picture *hpic = pic->codec_priv;
AV1RawOBU *fh_obu = &priv->fh;
AV1RawFrameHeader *fh = &fh_obu->obu.frame.header;
VAEncPictureParameterBufferAV1 *vpic = vaapi_pic->codec_picture_params;
@@ -503,7 +503,7 @@ static int vaapi_encode_av1_init_picture_params(AVCodecContext *avctx,
fh->frame_type = AV1_FRAME_INTER;
fh->base_q_idx = priv->q_idx_p;
ref = pic->refs[0][pic->nb_refs[0] - 1];
- href = ref->priv_data;
+ href = ref->codec_priv;
hpic->slot = !href->slot;
hpic->last_idr_frame = href->last_idr_frame;
fh->refresh_frame_flags = 1 << hpic->slot;
@@ -519,7 +519,7 @@ static int vaapi_encode_av1_init_picture_params(AVCodecContext *avctx,
/** set the 2nd nearest frame in L0 as Golden frame. */
if (pic->nb_refs[0] > 1) {
ref = pic->refs[0][pic->nb_refs[0] - 2];
- href = ref->priv_data;
+ href = ref->codec_priv;
fh->ref_frame_idx[3] = href->slot;
fh->ref_order_hint[href->slot] = ref->display_order - href->last_idr_frame;
vpic->ref_frame_ctrl_l0.fields.search_idx1 = AV1_REF_FRAME_GOLDEN;
@@ -540,7 +540,7 @@ static int vaapi_encode_av1_init_picture_params(AVCodecContext *avctx,
vpic->ref_frame_ctrl_l1.fields.search_idx0 = AV1_REF_FRAME_BWDREF;
ref = pic->refs[0][pic->nb_refs[0] - 1];
- href = ref->priv_data;
+ href = ref->codec_priv;
hpic->last_idr_frame = href->last_idr_frame;
fh->primary_ref_frame = href->slot;
fh->ref_order_hint[href->slot] = ref->display_order - href->last_idr_frame;
@@ -549,7 +549,7 @@ static int vaapi_encode_av1_init_picture_params(AVCodecContext *avctx,
}
ref = pic->refs[1][pic->nb_refs[1] - 1];
- href = ref->priv_data;
+ href = ref->codec_priv;
fh->ref_order_hint[href->slot] = ref->display_order - href->last_idr_frame;
for (i = AV1_REF_FRAME_GOLDEN; i < AV1_REFS_PER_FRAME; i++) {
fh->ref_frame_idx[i] = href->slot;
@@ -634,7 +634,7 @@ static int vaapi_encode_av1_init_picture_params(AVCodecContext *avctx,
for (int j = 0; j < pic->nb_refs[i]; j++) {
FFHWBaseEncodePicture *ref_pic = pic->refs[i][j];
- slot = ((VAAPIEncodeAV1Picture*)ref_pic->priv_data)->slot;
+ slot = ((VAAPIEncodeAV1Picture*)ref_pic->codec_priv)->slot;
av_assert0(vpic->reference_frames[slot] == VA_INVALID_SURFACE);
vpic->reference_frames[slot] = ((VAAPIEncodePicture *)ref_pic)->recon_surface;
@@ -732,7 +732,7 @@ end:
}
static int vaapi_encode_av1_init_slice_params(AVCodecContext *avctx,
- VAAPIEncodePicture *pic,
+ FFHWBaseEncodePicture *base,
VAAPIEncodeSlice *slice)
{
VAAPIEncodeAV1Context *priv = avctx->priv_data;
@@ -754,7 +754,7 @@ static int vaapi_encode_av1_init_slice_params(AVCodecContext *avctx,
}
static int vaapi_encode_av1_write_picture_header(AVCodecContext *avctx,
- VAAPIEncodePicture *vaapi_pic,
+ FFHWBaseEncodePicture *pic,
char *data, size_t *data_len)
{
VAAPIEncodeAV1Context *priv = avctx->priv_data;
@@ -762,7 +762,7 @@ static int vaapi_encode_av1_write_picture_header(AVCodecContext *avctx,
CodedBitstreamAV1Context *cbctx = priv->cbc->priv_data;
AV1RawOBU *fh_obu = &priv->fh;
AV1RawFrameHeader *rep_fh = &fh_obu->obu.frame_header;
- const FFHWBaseEncodePicture *pic = &vaapi_pic->base;
+ VAAPIEncodePicture *vaapi_pic = pic->priv;
VAAPIEncodeAV1Picture *href;
int ret = 0;
@@ -770,7 +770,7 @@ static int vaapi_encode_av1_write_picture_header(AVCodecContext *avctx,
/** Pack repeat frame header. */
if (pic->display_order > pic->encode_order) {
memset(fh_obu, 0, sizeof(*fh_obu));
- href = pic->refs[0][pic->nb_refs[0] - 1]->priv_data;
+ href = pic->refs[0][pic->nb_refs[0] - 1]->codec_priv;
fh_obu->header.obu_type = AV1_OBU_FRAME_HEADER;
fh_obu->header.obu_has_size_field = 1;
@@ -804,7 +804,7 @@ end:
}
static int vaapi_encode_av1_write_extra_header(AVCodecContext *avctx,
- VAAPIEncodePicture *pic,
+ FFHWBaseEncodePicture *base_pic,
int index, int *type,
char *data, size_t *data_len)
{
diff --git a/libavcodec/vaapi_encode_h264.c b/libavcodec/vaapi_encode_h264.c
index 84f306b95f..7dc4779dde 100644
--- a/libavcodec/vaapi_encode_h264.c
+++ b/libavcodec/vaapi_encode_h264.c
@@ -209,7 +209,7 @@ fail:
}
static int vaapi_encode_h264_write_extra_header(AVCodecContext *avctx,
- VAAPIEncodePicture *pic,
+ FFHWBaseEncodePicture *base,
int index, int *type,
char *data, size_t *data_len)
{
@@ -233,7 +233,7 @@ static int vaapi_encode_h264_write_extra_header(AVCodecContext *avctx,
goto fail;
}
if (priv->sei_needed & SEI_TIMING) {
- if (pic->base.type == FF_HW_PICTURE_TYPE_IDR) {
+ if (base->type == FF_HW_PICTURE_TYPE_IDR) {
err = ff_cbs_sei_add_message(priv->cbc, au, 1,
SEI_TYPE_BUFFERING_PERIOD,
&priv->sei_buffering_period, NULL);
@@ -620,14 +620,14 @@ static int vaapi_encode_h264_init_sequence_params(AVCodecContext *avctx)
}
static int vaapi_encode_h264_init_picture_params(AVCodecContext *avctx,
- VAAPIEncodePicture *vaapi_pic)
+ FFHWBaseEncodePicture *pic)
{
FFHWBaseEncodeContext *base_ctx = avctx->priv_data;
VAAPIEncodeH264Context *priv = avctx->priv_data;
- const FFHWBaseEncodePicture *pic = &vaapi_pic->base;
- VAAPIEncodeH264Picture *hpic = pic->priv_data;
+ VAAPIEncodePicture *vaapi_pic = pic->priv;
+ VAAPIEncodeH264Picture *hpic = pic->codec_priv;
FFHWBaseEncodePicture *prev = pic->prev;
- VAAPIEncodeH264Picture *hprev = prev ? prev->priv_data : NULL;
+ VAAPIEncodeH264Picture *hprev = prev ? prev->codec_priv : NULL;
VAEncPictureParameterBufferH264 *vpic = vaapi_pic->codec_picture_params;
int i, j = 0;
@@ -736,10 +736,10 @@ static int vaapi_encode_h264_init_picture_params(AVCodecContext *avctx,
VAAPIEncodeH264Picture *href;
av_assert0(ref && ref->encode_order < pic->encode_order);
- href = ref->priv_data;
+ href = ref->codec_priv;
vpic->ReferenceFrames[j++] = (VAPictureH264) {
- .picture_id = ((VAAPIEncodePicture *)ref)->recon_surface,
+ .picture_id = ((VAAPIEncodePicture *)ref->priv)->recon_surface,
.frame_idx = href->frame_num,
.flags = VA_PICTURE_H264_SHORT_TERM_REFERENCE,
.TopFieldOrderCnt = href->pic_order_cnt,
@@ -766,37 +766,36 @@ static int vaapi_encode_h264_init_picture_params(AVCodecContext *avctx,
}
static void vaapi_encode_h264_default_ref_pic_list(AVCodecContext *avctx,
- VAAPIEncodePicture *vaapi_pic,
- VAAPIEncodePicture **rpl0,
- VAAPIEncodePicture **rpl1,
+ FFHWBaseEncodePicture *pic,
+ FFHWBaseEncodePicture **rpl0,
+ FFHWBaseEncodePicture **rpl1,
int *rpl_size)
{
- FFHWBaseEncodePicture *pic = &vaapi_pic->base;
FFHWBaseEncodePicture *prev;
VAAPIEncodeH264Picture *hp, *hn, *hc;
int i, j, n = 0;
prev = pic->prev;
av_assert0(prev);
- hp = pic->priv_data;
+ hp = pic->codec_priv;
for (i = 0; i < pic->prev->nb_dpb_pics; i++) {
- hn = prev->dpb[i]->priv_data;
+ hn = prev->dpb[i]->codec_priv;
av_assert0(hn->frame_num < hp->frame_num);
if (pic->type == FF_HW_PICTURE_TYPE_P) {
for (j = n; j > 0; j--) {
- hc = rpl0[j - 1]->base.priv_data;
+ hc = rpl0[j - 1]->codec_priv;
av_assert0(hc->frame_num != hn->frame_num);
if (hc->frame_num > hn->frame_num)
break;
rpl0[j] = rpl0[j - 1];
}
- rpl0[j] = (VAAPIEncodePicture *)prev->dpb[i];
+ rpl0[j] = prev->dpb[i];
} else if (pic->type == FF_HW_PICTURE_TYPE_B) {
for (j = n; j > 0; j--) {
- hc = rpl0[j - 1]->base.priv_data;
+ hc = rpl0[j - 1]->codec_priv;
av_assert0(hc->pic_order_cnt != hp->pic_order_cnt);
if (hc->pic_order_cnt < hp->pic_order_cnt) {
if (hn->pic_order_cnt > hp->pic_order_cnt ||
@@ -808,10 +807,10 @@ static void vaapi_encode_h264_default_ref_pic_list(AVCodecContext *avctx,
}
rpl0[j] = rpl0[j - 1];
}
- rpl0[j] = (VAAPIEncodePicture *)prev->dpb[i];
+ rpl0[j] = prev->dpb[i];
for (j = n; j > 0; j--) {
- hc = rpl1[j - 1]->base.priv_data;
+ hc = rpl1[j - 1]->codec_priv;
av_assert0(hc->pic_order_cnt != hp->pic_order_cnt);
if (hc->pic_order_cnt > hp->pic_order_cnt) {
if (hn->pic_order_cnt < hp->pic_order_cnt ||
@@ -823,7 +822,7 @@ static void vaapi_encode_h264_default_ref_pic_list(AVCodecContext *avctx,
}
rpl1[j] = rpl1[j - 1];
}
- rpl1[j] = (VAAPIEncodePicture *)prev->dpb[i];
+ rpl1[j] = prev->dpb[i];
}
++n;
@@ -835,7 +834,7 @@ static void vaapi_encode_h264_default_ref_pic_list(AVCodecContext *avctx,
break;
}
if (i == n)
- FFSWAP(VAAPIEncodePicture*, rpl1[0], rpl1[1]);
+ FFSWAP(FFHWBaseEncodePicture *, rpl1[0], rpl1[1]);
}
if (pic->type == FF_HW_PICTURE_TYPE_P ||
@@ -843,7 +842,7 @@ static void vaapi_encode_h264_default_ref_pic_list(AVCodecContext *avctx,
av_log(avctx, AV_LOG_DEBUG, "Default RefPicList0 for fn=%d/poc=%d:",
hp->frame_num, hp->pic_order_cnt);
for (i = 0; i < n; i++) {
- hn = rpl0[i]->base.priv_data;
+ hn = rpl0[i]->codec_priv;
av_log(avctx, AV_LOG_DEBUG, " fn=%d/poc=%d",
hn->frame_num, hn->pic_order_cnt);
}
@@ -853,7 +852,7 @@ static void vaapi_encode_h264_default_ref_pic_list(AVCodecContext *avctx,
av_log(avctx, AV_LOG_DEBUG, "Default RefPicList1 for fn=%d/poc=%d:",
hp->frame_num, hp->pic_order_cnt);
for (i = 0; i < n; i++) {
- hn = rpl1[i]->base.priv_data;
+ hn = rpl1[i]->codec_priv;
av_log(avctx, AV_LOG_DEBUG, " fn=%d/poc=%d",
hn->frame_num, hn->pic_order_cnt);
}
@@ -864,12 +863,12 @@ static void vaapi_encode_h264_default_ref_pic_list(AVCodecContext *avctx,
}
static int vaapi_encode_h264_init_slice_params(AVCodecContext *avctx,
- VAAPIEncodePicture *vaapi_pic,
+ FFHWBaseEncodePicture *pic,
VAAPIEncodeSlice *slice)
{
VAAPIEncodeH264Context *priv = avctx->priv_data;
- const FFHWBaseEncodePicture *pic = &vaapi_pic->base;
- VAAPIEncodeH264Picture *hpic = pic->priv_data;
+ VAAPIEncodePicture *vaapi_pic = pic->priv;
+ VAAPIEncodeH264Picture *hpic = pic->codec_priv;
FFHWBaseEncodePicture *prev = pic->prev;
H264RawSPS *sps = &priv->raw_sps;
H264RawPPS *pps = &priv->raw_pps;
@@ -931,7 +930,7 @@ static int vaapi_encode_h264_init_slice_params(AVCodecContext *avctx,
} else {
sh->adaptive_ref_pic_marking_mode_flag = 1;
for (i = 0; i < discard; i++) {
- VAAPIEncodeH264Picture *old = discard_list[i]->priv_data;
+ VAAPIEncodeH264Picture *old = discard_list[i]->codec_priv;
av_assert0(old->frame_num < hpic->frame_num);
sh->mmco[i].memory_management_control_operation = 1;
sh->mmco[i].difference_of_pic_nums_minus1 =
@@ -944,11 +943,11 @@ static int vaapi_encode_h264_init_slice_params(AVCodecContext *avctx,
// If the intended references are not the first entries of RefPicListN
// by default, use ref-pic-list-modification to move them there.
if (pic->type == FF_HW_PICTURE_TYPE_P || pic->type == FF_HW_PICTURE_TYPE_B) {
- VAAPIEncodePicture *def_l0[MAX_DPB_SIZE], *def_l1[MAX_DPB_SIZE];
+ FFHWBaseEncodePicture *def_l0[MAX_DPB_SIZE], *def_l1[MAX_DPB_SIZE];
VAAPIEncodeH264Picture *href;
int n;
- vaapi_encode_h264_default_ref_pic_list(avctx, vaapi_pic,
+ vaapi_encode_h264_default_ref_pic_list(avctx, pic,
def_l0, def_l1, &n);
if (pic->type == FF_HW_PICTURE_TYPE_P) {
@@ -963,7 +962,7 @@ static int vaapi_encode_h264_init_slice_params(AVCodecContext *avctx,
if (need_rplm) {
int pic_num = hpic->frame_num;
for (i = 0; i < pic->nb_refs[0]; i++) {
- href = pic->refs[0][i]->priv_data;
+ href = pic->refs[0][i]->codec_priv;
av_assert0(href->frame_num != pic_num);
if (href->frame_num < pic_num) {
sh->rplm_l0[i].modification_of_pic_nums_idc = 0;
@@ -984,7 +983,7 @@ static int vaapi_encode_h264_init_slice_params(AVCodecContext *avctx,
int n0 = 0, n1 = 0;
for (i = 0; i < pic->nb_refs[0]; i++) {
av_assert0(pic->refs[0][i]);
- href = pic->refs[0][i]->priv_data;
+ href = pic->refs[0][i]->codec_priv;
av_assert0(href->pic_order_cnt < hpic->pic_order_cnt);
if (pic->refs[0][i] != (FFHWBaseEncodePicture *)def_l0[n0])
need_rplm_l0 = 1;
@@ -993,7 +992,7 @@ static int vaapi_encode_h264_init_slice_params(AVCodecContext *avctx,
for (i = 0; i < pic->nb_refs[1]; i++) {
av_assert0(pic->refs[1][i]);
- href = pic->refs[1][i]->priv_data;
+ href = pic->refs[1][i]->codec_priv;
av_assert0(href->pic_order_cnt > hpic->pic_order_cnt);
if (pic->refs[1][i] != (FFHWBaseEncodePicture *)def_l1[n1])
need_rplm_l1 = 1;
@@ -1004,7 +1003,7 @@ static int vaapi_encode_h264_init_slice_params(AVCodecContext *avctx,
if (need_rplm_l0) {
int pic_num = hpic->frame_num;
for (i = j = 0; i < pic->nb_refs[0]; i++) {
- href = pic->refs[0][i]->priv_data;
+ href = pic->refs[0][i]->codec_priv;
av_assert0(href->frame_num != pic_num);
if (href->frame_num < pic_num) {
sh->rplm_l0[j].modification_of_pic_nums_idc = 0;
@@ -1026,7 +1025,7 @@ static int vaapi_encode_h264_init_slice_params(AVCodecContext *avctx,
if (need_rplm_l1) {
int pic_num = hpic->frame_num;
for (i = j = 0; i < pic->nb_refs[1]; i++) {
- href = pic->refs[1][i]->priv_data;
+ href = pic->refs[1][i]->codec_priv;
av_assert0(href->frame_num != pic_num);
if (href->frame_num < pic_num) {
sh->rplm_l1[j].modification_of_pic_nums_idc = 0;
diff --git a/libavcodec/vaapi_encode_h265.c b/libavcodec/vaapi_encode_h265.c
index 548029a645..6d59a98114 100644
--- a/libavcodec/vaapi_encode_h265.c
+++ b/libavcodec/vaapi_encode_h265.c
@@ -200,7 +200,7 @@ fail:
}
static int vaapi_encode_h265_write_extra_header(AVCodecContext *avctx,
- VAAPIEncodePicture *pic,
+ FFHWBaseEncodePicture *base,
int index, int *type,
char *data, size_t *data_len)
{
@@ -757,14 +757,14 @@ static int vaapi_encode_h265_init_sequence_params(AVCodecContext *avctx)
}
static int vaapi_encode_h265_init_picture_params(AVCodecContext *avctx,
- VAAPIEncodePicture *vaapi_pic)
+ FFHWBaseEncodePicture *pic)
{
FFHWBaseEncodeContext *base_ctx = avctx->priv_data;
VAAPIEncodeH265Context *priv = avctx->priv_data;
- FFHWBaseEncodePicture *pic = &vaapi_pic->base;
- VAAPIEncodeH265Picture *hpic = pic->priv_data;
+ VAAPIEncodePicture *vaapi_pic = pic->priv;
+ VAAPIEncodeH265Picture *hpic = pic->codec_priv;
FFHWBaseEncodePicture *prev = pic->prev;
- VAAPIEncodeH265Picture *hprev = prev ? prev->priv_data : NULL;
+ VAAPIEncodeH265Picture *hprev = prev ? prev->codec_priv : NULL;
VAEncPictureParameterBufferHEVC *vpic = vaapi_pic->codec_picture_params;
int i, j = 0;
@@ -923,10 +923,10 @@ static int vaapi_encode_h265_init_picture_params(AVCodecContext *avctx,
VAAPIEncodeH265Picture *href;
av_assert0(ref && ref->encode_order < pic->encode_order);
- href = ref->priv_data;
+ href = ref->codec_priv;
vpic->reference_frames[j++] = (VAPictureHEVC) {
- .picture_id = ((VAAPIEncodePicture *)ref)->recon_surface,
+ .picture_id = ((VAAPIEncodePicture *)ref->priv)->recon_surface,
.pic_order_cnt = href->pic_order_cnt,
.flags = (ref->display_order < pic->display_order ?
VA_PICTURE_HEVC_RPS_ST_CURR_BEFORE : 0) |
@@ -973,13 +973,13 @@ static int vaapi_encode_h265_init_picture_params(AVCodecContext *avctx,
}
static int vaapi_encode_h265_init_slice_params(AVCodecContext *avctx,
- VAAPIEncodePicture *vaapi_pic,
+ FFHWBaseEncodePicture *pic,
VAAPIEncodeSlice *slice)
{
FFHWBaseEncodeContext *base_ctx = avctx->priv_data;
VAAPIEncodeH265Context *priv = avctx->priv_data;
- const FFHWBaseEncodePicture *pic = &vaapi_pic->base;
- VAAPIEncodeH265Picture *hpic = pic->priv_data;
+ VAAPIEncodePicture *vaapi_pic = pic->priv;
+ VAAPIEncodeH265Picture *hpic = pic->codec_priv;
const H265RawSPS *sps = &priv->raw_sps;
const H265RawPPS *pps = &priv->raw_pps;
H265RawSliceHeader *sh = &priv->raw_slice.header;
@@ -1021,7 +1021,7 @@ static int vaapi_encode_h265_init_slice_params(AVCodecContext *avctx,
rps_pics = 0;
for (i = 0; i < MAX_REFERENCE_LIST_NUM; i++) {
for (j = 0; j < pic->nb_refs[i]; j++) {
- strp = pic->refs[i][j]->priv_data;
+ strp = pic->refs[i][j]->codec_priv;
rps_poc[rps_pics] = strp->pic_order_cnt;
rps_used[rps_pics] = 1;
++rps_pics;
@@ -1046,7 +1046,7 @@ static int vaapi_encode_h265_init_slice_params(AVCodecContext *avctx,
if (j < pic->nb_refs[1])
continue;
- strp = pic->dpb[i]->priv_data;
+ strp = pic->dpb[i]->codec_priv;
rps_poc[rps_pics] = strp->pic_order_cnt;
rps_used[rps_pics] = 0;
++rps_pics;
diff --git a/libavcodec/vaapi_encode_mjpeg.c b/libavcodec/vaapi_encode_mjpeg.c
index 7667845c3d..5f8266e98a 100644
--- a/libavcodec/vaapi_encode_mjpeg.c
+++ b/libavcodec/vaapi_encode_mjpeg.c
@@ -147,7 +147,7 @@ fail:
}
static int vaapi_encode_mjpeg_write_extra_buffer(AVCodecContext *avctx,
- VAAPIEncodePicture *pic,
+ FFHWBaseEncodePicture *base,
int index, int *type,
char *data, size_t *data_len)
{
@@ -220,11 +220,11 @@ static int vaapi_encode_mjpeg_write_extra_buffer(AVCodecContext *avctx,
}
static int vaapi_encode_mjpeg_init_picture_params(AVCodecContext *avctx,
- VAAPIEncodePicture *vaapi_pic)
+ FFHWBaseEncodePicture *pic)
{
FFHWBaseEncodeContext *base_ctx = avctx->priv_data;
VAAPIEncodeMJPEGContext *priv = avctx->priv_data;
- const FFHWBaseEncodePicture *pic = &vaapi_pic->base;
+ VAAPIEncodePicture *vaapi_pic = pic->priv;
JPEGRawFrameHeader *fh = &priv->frame_header;
JPEGRawScanHeader *sh = &priv->scan.header;
VAEncPictureParameterBufferJPEG *vpic = vaapi_pic->codec_picture_params;
@@ -414,7 +414,7 @@ static int vaapi_encode_mjpeg_init_picture_params(AVCodecContext *avctx,
}
static int vaapi_encode_mjpeg_init_slice_params(AVCodecContext *avctx,
- VAAPIEncodePicture *pic,
+ FFHWBaseEncodePicture *base,
VAAPIEncodeSlice *slice)
{
VAAPIEncodeMJPEGContext *priv = avctx->priv_data;
diff --git a/libavcodec/vaapi_encode_mpeg2.c b/libavcodec/vaapi_encode_mpeg2.c
index 30a333ecd4..5701e2e803 100644
--- a/libavcodec/vaapi_encode_mpeg2.c
+++ b/libavcodec/vaapi_encode_mpeg2.c
@@ -141,7 +141,7 @@ fail:
}
static int vaapi_encode_mpeg2_write_picture_header(AVCodecContext *avctx,
- VAAPIEncodePicture *pic,
+ FFHWBaseEncodePicture *pic,
char *data, size_t *data_len)
{
VAAPIEncodeMPEG2Context *priv = avctx->priv_data;
@@ -418,10 +418,10 @@ static int vaapi_encode_mpeg2_init_sequence_params(AVCodecContext *avctx)
}
static int vaapi_encode_mpeg2_init_picture_params(AVCodecContext *avctx,
- VAAPIEncodePicture *vaapi_pic)
+ FFHWBaseEncodePicture *pic)
{
VAAPIEncodeMPEG2Context *priv = avctx->priv_data;
- const FFHWBaseEncodePicture *pic = &vaapi_pic->base;
+ VAAPIEncodePicture *vaapi_pic = pic->priv;
MPEG2RawPictureHeader *ph = &priv->picture_header;
MPEG2RawPictureCodingExtension *pce = &priv->picture_coding_extension.data.picture_coding;
VAEncPictureParameterBufferMPEG2 *vpic = vaapi_pic->codec_picture_params;
@@ -460,12 +460,12 @@ static int vaapi_encode_mpeg2_init_picture_params(AVCodecContext *avctx,
break;
case FF_HW_PICTURE_TYPE_P:
vpic->picture_type = VAEncPictureTypePredictive;
- vpic->forward_reference_picture = ((VAAPIEncodePicture *)pic->refs[0][0])->recon_surface;
+ vpic->forward_reference_picture = ((VAAPIEncodePicture *)pic->refs[0][0]->priv)->recon_surface;
break;
case FF_HW_PICTURE_TYPE_B:
vpic->picture_type = VAEncPictureTypeBidirectional;
- vpic->forward_reference_picture = ((VAAPIEncodePicture *)pic->refs[0][0])->recon_surface;
- vpic->backward_reference_picture = ((VAAPIEncodePicture *)pic->refs[1][0])->recon_surface;
+ vpic->forward_reference_picture = ((VAAPIEncodePicture *)pic->refs[0][0]->priv)->recon_surface;
+ vpic->backward_reference_picture = ((VAAPIEncodePicture *)pic->refs[1][0]->priv)->recon_surface;
break;
default:
av_assert0(0 && "invalid picture type");
@@ -481,10 +481,9 @@ static int vaapi_encode_mpeg2_init_picture_params(AVCodecContext *avctx,
}
static int vaapi_encode_mpeg2_init_slice_params(AVCodecContext *avctx,
- VAAPIEncodePicture *vaapi_pic,
+ FFHWBaseEncodePicture *pic,
VAAPIEncodeSlice *slice)
{
- const FFHWBaseEncodePicture *pic = &vaapi_pic->base;
VAAPIEncodeMPEG2Context *priv = avctx->priv_data;
VAEncSliceParameterBufferMPEG2 *vslice = slice->codec_slice_params;
int qp;
diff --git a/libavcodec/vaapi_encode_vp8.c b/libavcodec/vaapi_encode_vp8.c
index b2576f4a45..ad88af63eb 100644
--- a/libavcodec/vaapi_encode_vp8.c
+++ b/libavcodec/vaapi_encode_vp8.c
@@ -74,9 +74,9 @@ static int vaapi_encode_vp8_init_sequence_params(AVCodecContext *avctx)
}
static int vaapi_encode_vp8_init_picture_params(AVCodecContext *avctx,
- VAAPIEncodePicture *vaapi_pic)
+ FFHWBaseEncodePicture *pic)
{
- const FFHWBaseEncodePicture *pic = &vaapi_pic->base;
+ VAAPIEncodePicture *vaapi_pic = pic->priv;
VAAPIEncodeVP8Context *priv = avctx->priv_data;
VAEncPictureParameterBufferVP8 *vpic = vaapi_pic->codec_picture_params;
int i;
@@ -103,7 +103,7 @@ static int vaapi_encode_vp8_init_picture_params(AVCodecContext *avctx,
vpic->ref_last_frame =
vpic->ref_gf_frame =
vpic->ref_arf_frame =
- ((VAAPIEncodePicture *)pic->refs[0][0])->recon_surface;
+ ((VAAPIEncodePicture *)pic->refs[0][0]->priv)->recon_surface;
break;
default:
av_assert0(0 && "invalid picture type");
@@ -129,7 +129,7 @@ static int vaapi_encode_vp8_init_picture_params(AVCodecContext *avctx,
}
static int vaapi_encode_vp8_write_quant_table(AVCodecContext *avctx,
- VAAPIEncodePicture *pic,
+ FFHWBaseEncodePicture *base_pic,
int index, int *type,
char *data, size_t *data_len)
{
@@ -147,7 +147,7 @@ static int vaapi_encode_vp8_write_quant_table(AVCodecContext *avctx,
memset(&quant, 0, sizeof(quant));
- if (pic->base.type == FF_HW_PICTURE_TYPE_P)
+ if (base_pic->type == FF_HW_PICTURE_TYPE_P)
q = priv->q_index_p;
else
q = priv->q_index_i;
diff --git a/libavcodec/vaapi_encode_vp9.c b/libavcodec/vaapi_encode_vp9.c
index 7ce24cb864..ab925e24b5 100644
--- a/libavcodec/vaapi_encode_vp9.c
+++ b/libavcodec/vaapi_encode_vp9.c
@@ -77,12 +77,12 @@ static int vaapi_encode_vp9_init_sequence_params(AVCodecContext *avctx)
}
static int vaapi_encode_vp9_init_picture_params(AVCodecContext *avctx,
- VAAPIEncodePicture *vaapi_pic)
+ FFHWBaseEncodePicture *pic)
{
FFHWBaseEncodeContext *base_ctx = avctx->priv_data;
VAAPIEncodeVP9Context *priv = avctx->priv_data;
- const FFHWBaseEncodePicture *pic = &vaapi_pic->base;
- VAAPIEncodeVP9Picture *hpic = pic->priv_data;
+ VAAPIEncodePicture *vaapi_pic = pic->priv;
+ VAAPIEncodeVP9Picture *hpic = pic->codec_priv;
VAEncPictureParameterBufferVP9 *vpic = vaapi_pic->codec_picture_params;
int i;
int num_tile_columns;
@@ -106,7 +106,7 @@ static int vaapi_encode_vp9_init_picture_params(AVCodecContext *avctx,
case FF_HW_PICTURE_TYPE_P:
av_assert0(!pic->nb_refs[1]);
{
- VAAPIEncodeVP9Picture *href = pic->refs[0][0]->priv_data;
+ VAAPIEncodeVP9Picture *href = pic->refs[0][0]->codec_priv;
av_assert0(href->slot == 0 || href->slot == 1);
if (base_ctx->max_b_depth > 0) {
@@ -124,8 +124,8 @@ static int vaapi_encode_vp9_init_picture_params(AVCodecContext *avctx,
case FF_HW_PICTURE_TYPE_B:
av_assert0(pic->nb_refs[0] && pic->nb_refs[1]);
{
- VAAPIEncodeVP9Picture *href0 = pic->refs[0][0]->priv_data,
- *href1 = pic->refs[1][0]->priv_data;
+ VAAPIEncodeVP9Picture *href0 = pic->refs[0][0]->codec_priv,
+ *href1 = pic->refs[1][0]->codec_priv;
av_assert0(href0->slot < pic->b_depth + 1 &&
href1->slot < pic->b_depth + 1);
@@ -163,9 +163,9 @@ static int vaapi_encode_vp9_init_picture_params(AVCodecContext *avctx,
for (int j = 0; j < pic->nb_refs[i]; j++) {
FFHWBaseEncodePicture *ref_pic = pic->refs[i][j];
int slot;
- slot = ((VAAPIEncodeVP9Picture*)ref_pic->priv_data)->slot;
+ slot = ((VAAPIEncodeVP9Picture*)ref_pic->codec_priv)->slot;
av_assert0(vpic->reference_frames[slot] == VA_INVALID_SURFACE);
- vpic->reference_frames[slot] = ((VAAPIEncodePicture *)ref_pic)->recon_surface;
+ vpic->reference_frames[slot] = ((VAAPIEncodePicture *)ref_pic->priv)->recon_surface;
}
}