libavcodec/vaapi_encode: Add async_depth to vaapi_encoder to increase performance
Fix: #7706. After commit 5fdcf85bbf, vaapi encoder's performance
decrease. The reason is that vaRenderPicture() and vaSyncBuffer() are
called at the same time (vaRenderPicture() always followed by a
vaSyncBuffer()). Now I changed them to be called in a asynchronous way,
which will make better use of hardware.
Async_depth is added to increase encoder's performance. The frames that
are sent to hardware are stored in a fifo. Encoder will sync output
after async fifo is full.
Signed-off-by: Wenbin Chen <wenbin.chen@intel.com>
Signed-off-by: Haihao Xiang <haihao.xiang@intel.com>
This commit is contained in:
committed by
Haihao Xiang
parent
e0ff869930
commit
d165ce22a4
@@ -29,6 +29,7 @@
|
||||
|
||||
#include "libavutil/hwcontext.h"
|
||||
#include "libavutil/hwcontext_vaapi.h"
|
||||
#include "libavutil/fifo.h"
|
||||
|
||||
#include "avcodec.h"
|
||||
#include "hwconfig.h"
|
||||
@@ -47,6 +48,7 @@ enum {
|
||||
MAX_TILE_ROWS = 22,
|
||||
// A.4.1: table A.6 allows at most 20 tile columns for any level.
|
||||
MAX_TILE_COLS = 20,
|
||||
MAX_ASYNC_DEPTH = 64,
|
||||
};
|
||||
|
||||
extern const AVCodecHWConfigInternal *const ff_vaapi_encode_hw_configs[];
|
||||
@@ -297,7 +299,8 @@ typedef struct VAAPIEncodeContext {
|
||||
// Timestamp handling.
|
||||
int64_t first_pts;
|
||||
int64_t dts_pts_diff;
|
||||
int64_t ts_ring[MAX_REORDER_DELAY * 3];
|
||||
int64_t ts_ring[MAX_REORDER_DELAY * 3 +
|
||||
MAX_ASYNC_DEPTH];
|
||||
|
||||
// Slice structure.
|
||||
int slice_block_rows;
|
||||
@@ -348,6 +351,10 @@ typedef struct VAAPIEncodeContext {
|
||||
|
||||
// Whether the driver support vaSyncBuffer
|
||||
int has_sync_buffer_func;
|
||||
// Store buffered pic
|
||||
AVFifo *encode_fifo;
|
||||
// Max number of frame buffered in encoder.
|
||||
int async_depth;
|
||||
} VAAPIEncodeContext;
|
||||
|
||||
enum {
|
||||
@@ -458,7 +465,12 @@ int ff_vaapi_encode_close(AVCodecContext *avctx);
|
||||
{ "b_depth", \
|
||||
"Maximum B-frame reference depth", \
|
||||
OFFSET(common.desired_b_depth), AV_OPT_TYPE_INT, \
|
||||
{ .i64 = 1 }, 1, INT_MAX, FLAGS }
|
||||
{ .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 }
|
||||
|
||||
#define VAAPI_ENCODE_RC_MODE(name, desc) \
|
||||
{ #name, desc, 0, AV_OPT_TYPE_CONST, { .i64 = RC_MODE_ ## name }, \
|
||||
|
||||
Reference in New Issue
Block a user