aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorTong Wu <tong1.wu@intel.com>2024-04-17 14:27:30 +0800
committerLynne <dev@lynne.ee>2024-07-02 14:15:12 +0200
commitff06343d7e9500bf5070be169f749c1010860850 (patch)
treee5065e63a8d2dcc4906d4bb3835c1e413d370b3d
parentab944e06bcacb518a17a19a518975eb27ce5c43c (diff)
downloadffmpeg-ff06343d7e9500bf5070be169f749c1010860850.tar.gz
avcodec/vaapi_encode: add async_depth to common options
Signed-off-by: Tong Wu <tong1.wu@intel.com>
-rw-r--r--libavcodec/hw_base_encode.h10
-rw-r--r--libavcodec/vaapi_encode.c13
-rw-r--r--libavcodec/vaapi_encode.h7
-rw-r--r--libavcodec/vaapi_encode_av1.c1
-rw-r--r--libavcodec/vaapi_encode_h264.c1
-rw-r--r--libavcodec/vaapi_encode_h265.c1
-rw-r--r--libavcodec/vaapi_encode_mjpeg.c1
-rw-r--r--libavcodec/vaapi_encode_mpeg2.c1
-rw-r--r--libavcodec/vaapi_encode_vp8.c1
-rw-r--r--libavcodec/vaapi_encode_vp9.c1
10 files changed, 24 insertions, 13 deletions
diff --git a/libavcodec/hw_base_encode.h b/libavcodec/hw_base_encode.h
index f3c9f32977..c14c174102 100644
--- a/libavcodec/hw_base_encode.h
+++ b/libavcodec/hw_base_encode.h
@@ -50,7 +50,15 @@ enum {
typedef struct FFHWBaseEncodeContext {
const AVClass *class;
+
+ // Max number of frame buffered in encoder.
+ int async_depth;
} FFHWBaseEncodeContext;
-#endif /* AVCODEC_HW_BASE_ENCODE_H */
+#define HW_BASE_ENCODE_COMMON_OPTIONS \
+ { "async_depth", "Maximum processing parallelism. " \
+ "Increase this to improve single channel performance.", \
+ OFFSET(common.base.async_depth), AV_OPT_TYPE_INT, \
+ { .i64 = 2 }, 1, MAX_ASYNC_DEPTH, FLAGS }
+#endif /* AVCODEC_HW_BASE_ENCODE_H */
diff --git a/libavcodec/vaapi_encode.c b/libavcodec/vaapi_encode.c
index 3c3d6a37c7..77f539dc6d 100644
--- a/libavcodec/vaapi_encode.c
+++ b/libavcodec/vaapi_encode.c
@@ -669,7 +669,8 @@ static int vaapi_encode_set_output_property(AVCodecContext *avctx,
VAAPIEncodePicture *pic,
AVPacket *pkt)
{
- VAAPIEncodeContext *ctx = avctx->priv_data;
+ FFHWBaseEncodeContext *base_ctx = avctx->priv_data;
+ VAAPIEncodeContext *ctx = avctx->priv_data;
if (pic->type == FF_HW_PICTURE_TYPE_IDR)
pkt->flags |= AV_PKT_FLAG_KEY;
@@ -699,7 +700,7 @@ static int vaapi_encode_set_output_property(AVCodecContext *avctx,
pkt->dts = ctx->ts_ring[pic->encode_order] - ctx->dts_pts_diff;
} else {
pkt->dts = ctx->ts_ring[(pic->encode_order - ctx->decode_delay) %
- (3 * ctx->output_delay + ctx->async_depth)];
+ (3 * ctx->output_delay + base_ctx->async_depth)];
}
return 0;
@@ -1320,6 +1321,7 @@ static int vaapi_encode_check_frame(AVCodecContext *avctx,
static int vaapi_encode_send_frame(AVCodecContext *avctx, AVFrame *frame)
{
+ FFHWBaseEncodeContext *base_ctx = avctx->priv_data;
VAAPIEncodeContext *ctx = avctx->priv_data;
VAAPIEncodePicture *pic;
int err;
@@ -1365,7 +1367,7 @@ static int vaapi_encode_send_frame(AVCodecContext *avctx, AVFrame *frame)
ctx->dts_pts_diff = pic->pts - ctx->first_pts;
if (ctx->output_delay > 0)
ctx->ts_ring[ctx->input_order %
- (3 * ctx->output_delay + ctx->async_depth)] = pic->pts;
+ (3 * ctx->output_delay + base_ctx->async_depth)] = pic->pts;
pic->display_order = ctx->input_order;
++ctx->input_order;
@@ -2773,7 +2775,8 @@ static av_cold int vaapi_encode_create_recon_frames(AVCodecContext *avctx)
av_cold int ff_vaapi_encode_init(AVCodecContext *avctx)
{
- VAAPIEncodeContext *ctx = avctx->priv_data;
+ FFHWBaseEncodeContext *base_ctx = avctx->priv_data;
+ VAAPIEncodeContext *ctx = avctx->priv_data;
AVVAAPIFramesContext *recon_hwctx = NULL;
VAStatus vas;
int err;
@@ -2966,7 +2969,7 @@ av_cold int ff_vaapi_encode_init(AVCodecContext *avctx)
vas = vaSyncBuffer(ctx->hwctx->display, VA_INVALID_ID, 0);
if (vas != VA_STATUS_ERROR_UNIMPLEMENTED) {
ctx->has_sync_buffer_func = 1;
- ctx->encode_fifo = av_fifo_alloc2(ctx->async_depth,
+ ctx->encode_fifo = av_fifo_alloc2(base_ctx->async_depth,
sizeof(VAAPIEncodePicture *),
0);
if (!ctx->encode_fifo)
diff --git a/libavcodec/vaapi_encode.h b/libavcodec/vaapi_encode.h
index cae7af8725..9fdb945b18 100644
--- a/libavcodec/vaapi_encode.h
+++ b/libavcodec/vaapi_encode.h
@@ -374,8 +374,6 @@ typedef struct VAAPIEncodeContext {
int has_sync_buffer_func;
// Store buffered pic
AVFifo *encode_fifo;
- // Max number of frame buffered in encoder.
- int async_depth;
/** Head data for current output pkt, used only for AV1. */
//void *header_data;
@@ -491,11 +489,6 @@ int ff_vaapi_encode_close(AVCodecContext *avctx);
"Maximum B-frame reference depth", \
OFFSET(common.desired_b_depth), AV_OPT_TYPE_INT, \
{ .i64 = 1 }, 1, INT_MAX, FLAGS }, \
- { "async_depth", "Maximum processing parallelism. " \
- "Increase this to improve single channel performance. This option " \
- "doesn't work if driver doesn't implement vaSyncBuffer function.", \
- OFFSET(common.async_depth), AV_OPT_TYPE_INT, \
- { .i64 = 2 }, 1, MAX_ASYNC_DEPTH, FLAGS }, \
{ "max_frame_size", \
"Maximum frame size (in bytes)",\
OFFSET(common.max_frame_size), AV_OPT_TYPE_INT, \
diff --git a/libavcodec/vaapi_encode_av1.c b/libavcodec/vaapi_encode_av1.c
index 7740942f2c..5bd12f9f92 100644
--- a/libavcodec/vaapi_encode_av1.c
+++ b/libavcodec/vaapi_encode_av1.c
@@ -965,6 +965,7 @@ static av_cold int vaapi_encode_av1_close(AVCodecContext *avctx)
#define FLAGS (AV_OPT_FLAG_VIDEO_PARAM | AV_OPT_FLAG_ENCODING_PARAM)
static const AVOption vaapi_encode_av1_options[] = {
+ HW_BASE_ENCODE_COMMON_OPTIONS,
VAAPI_ENCODE_COMMON_OPTIONS,
VAAPI_ENCODE_RC_OPTIONS,
{ "profile", "Set profile (seq_profile)",
diff --git a/libavcodec/vaapi_encode_h264.c b/libavcodec/vaapi_encode_h264.c
index df116d6610..aa5b499d9f 100644
--- a/libavcodec/vaapi_encode_h264.c
+++ b/libavcodec/vaapi_encode_h264.c
@@ -1276,6 +1276,7 @@ static av_cold int vaapi_encode_h264_close(AVCodecContext *avctx)
#define OFFSET(x) offsetof(VAAPIEncodeH264Context, x)
#define FLAGS (AV_OPT_FLAG_VIDEO_PARAM | AV_OPT_FLAG_ENCODING_PARAM)
static const AVOption vaapi_encode_h264_options[] = {
+ HW_BASE_ENCODE_COMMON_OPTIONS,
VAAPI_ENCODE_COMMON_OPTIONS,
VAAPI_ENCODE_RC_OPTIONS,
diff --git a/libavcodec/vaapi_encode_h265.c b/libavcodec/vaapi_encode_h265.c
index edeffa9749..9222010ec0 100644
--- a/libavcodec/vaapi_encode_h265.c
+++ b/libavcodec/vaapi_encode_h265.c
@@ -1395,6 +1395,7 @@ static av_cold int vaapi_encode_h265_close(AVCodecContext *avctx)
#define OFFSET(x) offsetof(VAAPIEncodeH265Context, x)
#define FLAGS (AV_OPT_FLAG_VIDEO_PARAM | AV_OPT_FLAG_ENCODING_PARAM)
static const AVOption vaapi_encode_h265_options[] = {
+ HW_BASE_ENCODE_COMMON_OPTIONS,
VAAPI_ENCODE_COMMON_OPTIONS,
VAAPI_ENCODE_RC_OPTIONS,
diff --git a/libavcodec/vaapi_encode_mjpeg.c b/libavcodec/vaapi_encode_mjpeg.c
index 0e74a3eb6f..9e533e9fbe 100644
--- a/libavcodec/vaapi_encode_mjpeg.c
+++ b/libavcodec/vaapi_encode_mjpeg.c
@@ -540,6 +540,7 @@ static av_cold int vaapi_encode_mjpeg_close(AVCodecContext *avctx)
#define OFFSET(x) offsetof(VAAPIEncodeMJPEGContext, x)
#define FLAGS (AV_OPT_FLAG_VIDEO_PARAM | AV_OPT_FLAG_ENCODING_PARAM)
static const AVOption vaapi_encode_mjpeg_options[] = {
+ HW_BASE_ENCODE_COMMON_OPTIONS,
VAAPI_ENCODE_COMMON_OPTIONS,
{ "jfif", "Include JFIF header",
diff --git a/libavcodec/vaapi_encode_mpeg2.c b/libavcodec/vaapi_encode_mpeg2.c
index 92bf6e443e..69784f9ba6 100644
--- a/libavcodec/vaapi_encode_mpeg2.c
+++ b/libavcodec/vaapi_encode_mpeg2.c
@@ -639,6 +639,7 @@ static av_cold int vaapi_encode_mpeg2_close(AVCodecContext *avctx)
#define OFFSET(x) offsetof(VAAPIEncodeMPEG2Context, x)
#define FLAGS (AV_OPT_FLAG_VIDEO_PARAM | AV_OPT_FLAG_ENCODING_PARAM)
static const AVOption vaapi_encode_mpeg2_options[] = {
+ HW_BASE_ENCODE_COMMON_OPTIONS,
VAAPI_ENCODE_COMMON_OPTIONS,
VAAPI_ENCODE_RC_OPTIONS,
diff --git a/libavcodec/vaapi_encode_vp8.c b/libavcodec/vaapi_encode_vp8.c
index 7dcd3d84af..1f2de050d2 100644
--- a/libavcodec/vaapi_encode_vp8.c
+++ b/libavcodec/vaapi_encode_vp8.c
@@ -216,6 +216,7 @@ static av_cold int vaapi_encode_vp8_init(AVCodecContext *avctx)
#define OFFSET(x) offsetof(VAAPIEncodeVP8Context, x)
#define FLAGS (AV_OPT_FLAG_VIDEO_PARAM | AV_OPT_FLAG_ENCODING_PARAM)
static const AVOption vaapi_encode_vp8_options[] = {
+ HW_BASE_ENCODE_COMMON_OPTIONS,
VAAPI_ENCODE_COMMON_OPTIONS,
VAAPI_ENCODE_RC_OPTIONS,
diff --git a/libavcodec/vaapi_encode_vp9.c b/libavcodec/vaapi_encode_vp9.c
index 4eec0fd445..690e4a6bd1 100644
--- a/libavcodec/vaapi_encode_vp9.c
+++ b/libavcodec/vaapi_encode_vp9.c
@@ -273,6 +273,7 @@ static av_cold int vaapi_encode_vp9_init(AVCodecContext *avctx)
#define OFFSET(x) offsetof(VAAPIEncodeVP9Context, x)
#define FLAGS (AV_OPT_FLAG_VIDEO_PARAM | AV_OPT_FLAG_ENCODING_PARAM)
static const AVOption vaapi_encode_vp9_options[] = {
+ HW_BASE_ENCODE_COMMON_OPTIONS,
VAAPI_ENCODE_COMMON_OPTIONS,
VAAPI_ENCODE_RC_OPTIONS,