You've already forked FFmpeg
mirror of
https://github.com/FFmpeg/FFmpeg.git
synced 2025-08-04 22:03:09 +02:00
avcodec/amfenc: redesign to use hwcontext_amf.
Co-authored-by: Evgeny Pavlov <lucenticus@gmail.com> v3: cleanup code
This commit is contained in:
File diff suppressed because it is too large
Load Diff
@ -33,57 +33,34 @@
|
|||||||
|
|
||||||
#define MAX_LOOKAHEAD_DEPTH 41
|
#define MAX_LOOKAHEAD_DEPTH 41
|
||||||
|
|
||||||
/**
|
|
||||||
* AMF trace writer callback class
|
|
||||||
* Used to capture all AMF logging
|
|
||||||
*/
|
|
||||||
|
|
||||||
typedef struct AmfTraceWriter {
|
|
||||||
AMFTraceWriterVtbl *vtbl;
|
|
||||||
AVCodecContext *avctx;
|
|
||||||
} AmfTraceWriter;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* AMF encoder context
|
* AMF encoder context
|
||||||
*/
|
*/
|
||||||
|
|
||||||
typedef struct AmfContext {
|
typedef struct AMFEncoderContext {
|
||||||
AVClass *avclass;
|
AVClass *avclass;
|
||||||
// access to AMF runtime
|
// access to AMF runtime
|
||||||
amf_handle library; ///< handle to DLL library
|
AVBufferRef *device_ctx_ref;
|
||||||
AMFFactory *factory; ///< pointer to AMF factory
|
|
||||||
AMFDebug *debug; ///< pointer to AMF debug interface
|
|
||||||
AMFTrace *trace; ///< pointer to AMF trace interface
|
|
||||||
|
|
||||||
amf_uint64 version; ///< version of AMF runtime
|
|
||||||
AmfTraceWriter tracer; ///< AMF writer registered with AMF
|
|
||||||
AMFContext *context; ///< AMF context
|
|
||||||
//encoder
|
//encoder
|
||||||
AMFComponent *encoder; ///< AMF encoder object
|
AMFComponent *encoder; ///< AMF encoder object
|
||||||
amf_bool eof; ///< flag indicating EOF happened
|
amf_bool eof; ///< flag indicating EOF happened
|
||||||
AMF_SURFACE_FORMAT format; ///< AMF surface format
|
AMF_SURFACE_FORMAT format; ///< AMF surface format
|
||||||
|
|
||||||
AVBufferRef *hw_device_ctx; ///< pointer to HW accelerator (decoder)
|
|
||||||
AVBufferRef *hw_frames_ctx; ///< pointer to HW accelerator (frame allocator)
|
|
||||||
|
|
||||||
int hwsurfaces_in_queue;
|
int hwsurfaces_in_queue;
|
||||||
int hwsurfaces_in_queue_max;
|
int hwsurfaces_in_queue_max;
|
||||||
int query_timeout_supported;
|
int query_timeout_supported;
|
||||||
|
|
||||||
// helpers to handle async calls
|
// helpers to handle async calls
|
||||||
int delayed_drain;
|
int delayed_drain;
|
||||||
AMFSurface *delayed_surface;
|
|
||||||
AVFrame *delayed_frame;
|
|
||||||
|
|
||||||
// shift dts back by max_b_frames in timing
|
// shift dts back by max_b_frames in timing
|
||||||
AVFifo *timestamp_list;
|
AVFifo *timestamp_list;
|
||||||
int64_t dts_delay;
|
int64_t dts_delay;
|
||||||
int submitted_frame;
|
int64_t submitted_frame;
|
||||||
amf_bool use_b_frame;
|
int64_t encoded_frame;
|
||||||
|
|
||||||
// common encoder option options
|
// common encoder options
|
||||||
|
|
||||||
int log_to_dbg;
|
|
||||||
|
|
||||||
// Static options, have to be set before Init() call
|
// Static options, have to be set before Init() call
|
||||||
int usage;
|
int usage;
|
||||||
@ -154,7 +131,7 @@ typedef struct AmfContext {
|
|||||||
int pa_adaptive_mini_gop;
|
int pa_adaptive_mini_gop;
|
||||||
|
|
||||||
|
|
||||||
} AmfContext;
|
} AMFEncoderContext;
|
||||||
|
|
||||||
extern const AVCodecHWConfigInternal *const ff_amfenc_hw_configs[];
|
extern const AVCodecHWConfigInternal *const ff_amfenc_hw_configs[];
|
||||||
|
|
||||||
|
@ -26,7 +26,7 @@
|
|||||||
#define AMF_VIDEO_ENCODER_AV1_CAP_WIDTH_ALIGNMENT_FACTOR_LOCAL L"Av1WidthAlignmentFactor" // amf_int64; default = 1
|
#define AMF_VIDEO_ENCODER_AV1_CAP_WIDTH_ALIGNMENT_FACTOR_LOCAL L"Av1WidthAlignmentFactor" // amf_int64; default = 1
|
||||||
#define AMF_VIDEO_ENCODER_AV1_CAP_HEIGHT_ALIGNMENT_FACTOR_LOCAL L"Av1HeightAlignmentFactor" // amf_int64; default = 1
|
#define AMF_VIDEO_ENCODER_AV1_CAP_HEIGHT_ALIGNMENT_FACTOR_LOCAL L"Av1HeightAlignmentFactor" // amf_int64; default = 1
|
||||||
|
|
||||||
#define OFFSET(x) offsetof(AmfContext, x)
|
#define OFFSET(x) offsetof(AMFEncoderContext, x)
|
||||||
#define VE AV_OPT_FLAG_VIDEO_PARAM | AV_OPT_FLAG_ENCODING_PARAM
|
#define VE AV_OPT_FLAG_VIDEO_PARAM | AV_OPT_FLAG_ENCODING_PARAM
|
||||||
static const AVOption options[] = {
|
static const AVOption options[] = {
|
||||||
|
|
||||||
@ -129,8 +129,6 @@ static const AVOption options[] = {
|
|||||||
{ "1080p", "", 0, AV_OPT_TYPE_CONST, {.i64 = AMF_VIDEO_ENCODER_AV1_ALIGNMENT_MODE_64X16_1080P_CODED_1082 }, 0, 0, VE, .unit = "align" },
|
{ "1080p", "", 0, AV_OPT_TYPE_CONST, {.i64 = AMF_VIDEO_ENCODER_AV1_ALIGNMENT_MODE_64X16_1080P_CODED_1082 }, 0, 0, VE, .unit = "align" },
|
||||||
{ "none", "", 0, AV_OPT_TYPE_CONST, {.i64 = AMF_VIDEO_ENCODER_AV1_ALIGNMENT_MODE_NO_RESTRICTIONS }, 0, 0, VE, .unit = "align" },
|
{ "none", "", 0, AV_OPT_TYPE_CONST, {.i64 = AMF_VIDEO_ENCODER_AV1_ALIGNMENT_MODE_NO_RESTRICTIONS }, 0, 0, VE, .unit = "align" },
|
||||||
|
|
||||||
{ "log_to_dbg", "Enable AMF logging to debug output", OFFSET(log_to_dbg), AV_OPT_TYPE_BOOL,{.i64 = 0 }, 0, 1, VE },
|
|
||||||
|
|
||||||
//Pre Analysis options
|
//Pre Analysis options
|
||||||
{ "preanalysis", "Enable preanalysis", OFFSET(preanalysis), AV_OPT_TYPE_BOOL, {.i64 = -1 }, -1, 1, VE },
|
{ "preanalysis", "Enable preanalysis", OFFSET(preanalysis), AV_OPT_TYPE_BOOL, {.i64 = -1 }, -1, 1, VE },
|
||||||
|
|
||||||
@ -187,11 +185,11 @@ static av_cold int amf_encode_init_av1(AVCodecContext* avctx)
|
|||||||
{
|
{
|
||||||
int ret = 0;
|
int ret = 0;
|
||||||
AMF_RESULT res = AMF_OK;
|
AMF_RESULT res = AMF_OK;
|
||||||
AmfContext* ctx = avctx->priv_data;
|
AMFEncoderContext *ctx = avctx->priv_data;
|
||||||
AMFVariantStruct var = { 0 };
|
AMFVariantStruct var = { 0 };
|
||||||
amf_int64 profile = 0;
|
amf_int64 profile = 0;
|
||||||
amf_int64 profile_level = 0;
|
amf_int64 profile_level = 0;
|
||||||
AMFBuffer* buffer;
|
AMFBuffer *buffer;
|
||||||
AMFGuid guid;
|
AMFGuid guid;
|
||||||
AMFRate framerate;
|
AMFRate framerate;
|
||||||
AMFSize framesize = AMFConstructSize(avctx->width, avctx->height);
|
AMFSize framesize = AMFConstructSize(avctx->width, avctx->height);
|
||||||
@ -693,7 +691,7 @@ const FFCodec ff_av1_amf_encoder = {
|
|||||||
.init = amf_encode_init_av1,
|
.init = amf_encode_init_av1,
|
||||||
FF_CODEC_RECEIVE_PACKET_CB(ff_amf_receive_packet),
|
FF_CODEC_RECEIVE_PACKET_CB(ff_amf_receive_packet),
|
||||||
.close = ff_amf_encode_close,
|
.close = ff_amf_encode_close,
|
||||||
.priv_data_size = sizeof(AmfContext),
|
.priv_data_size = sizeof(AMFEncoderContext),
|
||||||
.p.priv_class = &av1_amf_class,
|
.p.priv_class = &av1_amf_class,
|
||||||
.defaults = defaults,
|
.defaults = defaults,
|
||||||
.p.capabilities = AV_CODEC_CAP_DELAY | AV_CODEC_CAP_HARDWARE |
|
.p.capabilities = AV_CODEC_CAP_DELAY | AV_CODEC_CAP_HARDWARE |
|
||||||
|
@ -24,7 +24,7 @@
|
|||||||
#include "codec_internal.h"
|
#include "codec_internal.h"
|
||||||
#include <AMF/components/PreAnalysis.h>
|
#include <AMF/components/PreAnalysis.h>
|
||||||
|
|
||||||
#define OFFSET(x) offsetof(AmfContext, x)
|
#define OFFSET(x) offsetof(AMFEncoderContext, x)
|
||||||
#define VE AV_OPT_FLAG_VIDEO_PARAM | AV_OPT_FLAG_ENCODING_PARAM
|
#define VE AV_OPT_FLAG_VIDEO_PARAM | AV_OPT_FLAG_ENCODING_PARAM
|
||||||
|
|
||||||
static const AVOption options[] = {
|
static const AVOption options[] = {
|
||||||
@ -139,9 +139,6 @@ static const AVOption options[] = {
|
|||||||
{ "forced_idr", "Force I frames to be IDR frames", OFFSET(forced_idr) , AV_OPT_TYPE_BOOL, { .i64 = 0 }, 0, 1, VE },
|
{ "forced_idr", "Force I frames to be IDR frames", OFFSET(forced_idr) , AV_OPT_TYPE_BOOL, { .i64 = 0 }, 0, 1, VE },
|
||||||
{ "aud", "Inserts AU Delimiter NAL unit", OFFSET(aud) , AV_OPT_TYPE_BOOL, { .i64 = -1 }, -1, 1, VE },
|
{ "aud", "Inserts AU Delimiter NAL unit", OFFSET(aud) , AV_OPT_TYPE_BOOL, { .i64 = -1 }, -1, 1, VE },
|
||||||
|
|
||||||
|
|
||||||
{ "log_to_dbg", "Enable AMF logging to debug output", OFFSET(log_to_dbg) , AV_OPT_TYPE_BOOL, { .i64 = 0 }, 0, 1, VE },
|
|
||||||
|
|
||||||
//Pre Analysis options
|
//Pre Analysis options
|
||||||
{ "preanalysis", "Enable preanalysis", OFFSET(preanalysis), AV_OPT_TYPE_BOOL, {.i64 = -1 }, -1, 1, VE },
|
{ "preanalysis", "Enable preanalysis", OFFSET(preanalysis), AV_OPT_TYPE_BOOL, {.i64 = -1 }, -1, 1, VE },
|
||||||
|
|
||||||
@ -196,7 +193,7 @@ static av_cold int amf_encode_init_h264(AVCodecContext *avctx)
|
|||||||
{
|
{
|
||||||
int ret = 0;
|
int ret = 0;
|
||||||
AMF_RESULT res = AMF_OK;
|
AMF_RESULT res = AMF_OK;
|
||||||
AmfContext *ctx = avctx->priv_data;
|
AMFEncoderContext *ctx = avctx->priv_data;
|
||||||
AMFVariantStruct var = { 0 };
|
AMFVariantStruct var = { 0 };
|
||||||
amf_int64 profile = 0;
|
amf_int64 profile = 0;
|
||||||
amf_int64 profile_level = 0;
|
amf_int64 profile_level = 0;
|
||||||
@ -605,7 +602,7 @@ const FFCodec ff_h264_amf_encoder = {
|
|||||||
.init = amf_encode_init_h264,
|
.init = amf_encode_init_h264,
|
||||||
FF_CODEC_RECEIVE_PACKET_CB(ff_amf_receive_packet),
|
FF_CODEC_RECEIVE_PACKET_CB(ff_amf_receive_packet),
|
||||||
.close = ff_amf_encode_close,
|
.close = ff_amf_encode_close,
|
||||||
.priv_data_size = sizeof(AmfContext),
|
.priv_data_size = sizeof(AMFEncoderContext),
|
||||||
.p.priv_class = &h264_amf_class,
|
.p.priv_class = &h264_amf_class,
|
||||||
.defaults = defaults,
|
.defaults = defaults,
|
||||||
.p.capabilities = AV_CODEC_CAP_DELAY | AV_CODEC_CAP_HARDWARE |
|
.p.capabilities = AV_CODEC_CAP_DELAY | AV_CODEC_CAP_HARDWARE |
|
||||||
|
@ -23,7 +23,7 @@
|
|||||||
#include "codec_internal.h"
|
#include "codec_internal.h"
|
||||||
#include <AMF/components/PreAnalysis.h>
|
#include <AMF/components/PreAnalysis.h>
|
||||||
|
|
||||||
#define OFFSET(x) offsetof(AmfContext, x)
|
#define OFFSET(x) offsetof(AMFEncoderContext, x)
|
||||||
#define VE AV_OPT_FLAG_VIDEO_PARAM | AV_OPT_FLAG_ENCODING_PARAM
|
#define VE AV_OPT_FLAG_VIDEO_PARAM | AV_OPT_FLAG_ENCODING_PARAM
|
||||||
|
|
||||||
static const AVOption options[] = {
|
static const AVOption options[] = {
|
||||||
@ -105,9 +105,6 @@ static const AVOption options[] = {
|
|||||||
{ "forced_idr", "Force I frames to be IDR frames", OFFSET(forced_idr) ,AV_OPT_TYPE_BOOL,{ .i64 = 0 }, 0, 1, VE },
|
{ "forced_idr", "Force I frames to be IDR frames", OFFSET(forced_idr) ,AV_OPT_TYPE_BOOL,{ .i64 = 0 }, 0, 1, VE },
|
||||||
{ "aud", "Inserts AU Delimiter NAL unit", OFFSET(aud) ,AV_OPT_TYPE_BOOL,{ .i64 = -1 }, -1, 1, VE },
|
{ "aud", "Inserts AU Delimiter NAL unit", OFFSET(aud) ,AV_OPT_TYPE_BOOL,{ .i64 = -1 }, -1, 1, VE },
|
||||||
|
|
||||||
|
|
||||||
{ "log_to_dbg", "Enable AMF logging to debug output", OFFSET(log_to_dbg), AV_OPT_TYPE_BOOL,{ .i64 = 0 }, 0, 1, VE },
|
|
||||||
|
|
||||||
//Pre Analysis options
|
//Pre Analysis options
|
||||||
{ "preanalysis", "Enable preanalysis", OFFSET(preanalysis), AV_OPT_TYPE_BOOL, {.i64 = -1 }, -1, 1, VE },
|
{ "preanalysis", "Enable preanalysis", OFFSET(preanalysis), AV_OPT_TYPE_BOOL, {.i64 = -1 }, -1, 1, VE },
|
||||||
|
|
||||||
@ -160,7 +157,7 @@ static av_cold int amf_encode_init_hevc(AVCodecContext *avctx)
|
|||||||
{
|
{
|
||||||
int ret = 0;
|
int ret = 0;
|
||||||
AMF_RESULT res = AMF_OK;
|
AMF_RESULT res = AMF_OK;
|
||||||
AmfContext *ctx = avctx->priv_data;
|
AMFEncoderContext *ctx = avctx->priv_data;
|
||||||
AMFVariantStruct var = {0};
|
AMFVariantStruct var = {0};
|
||||||
amf_int64 profile = 0;
|
amf_int64 profile = 0;
|
||||||
amf_int64 profile_level = 0;
|
amf_int64 profile_level = 0;
|
||||||
@ -534,7 +531,7 @@ const FFCodec ff_hevc_amf_encoder = {
|
|||||||
.init = amf_encode_init_hevc,
|
.init = amf_encode_init_hevc,
|
||||||
FF_CODEC_RECEIVE_PACKET_CB(ff_amf_receive_packet),
|
FF_CODEC_RECEIVE_PACKET_CB(ff_amf_receive_packet),
|
||||||
.close = ff_amf_encode_close,
|
.close = ff_amf_encode_close,
|
||||||
.priv_data_size = sizeof(AmfContext),
|
.priv_data_size = sizeof(AMFEncoderContext),
|
||||||
.p.priv_class = &hevc_amf_class,
|
.p.priv_class = &hevc_amf_class,
|
||||||
.defaults = defaults,
|
.defaults = defaults,
|
||||||
.p.capabilities = AV_CODEC_CAP_DELAY | AV_CODEC_CAP_HARDWARE |
|
.p.capabilities = AV_CODEC_CAP_DELAY | AV_CODEC_CAP_HARDWARE |
|
||||||
|
Reference in New Issue
Block a user