37#include "AMF/components/HQScaler.h"
38#include "AMF/components/VideoConverter.h"
39#include "AMF/components/ColorSpace.h"
58 return algorithm == AMF_HQ_SCALER_ALGORITHM_VIDEOSR1_1 ||
59 algorithm == AMF_HQ_SCALER_ALGORITHM_POINT;
104 input_pix_fmts = pix_fmts_packed_rgb;
106 input_pix_fmts = input_pix_fmts_default;
110 if (input_pix_fmts[
i] ==
ctx->format_opt) {
111 pix_fmts_requested[0] =
ctx->format_opt;
112 input_pix_fmts = pix_fmts_requested;
130 enum AMF_MEMORY_TYPE mem_type = AMF_MEMORY_UNKNOWN;
132 int needs_conversion;
135 ctx->format =
ctx->format_opt;
140 ctx->format = in_sw_format;
144 av_log(avctx,
AV_LOG_ERROR,
"This algorithm only outputs packed RGB, format=%s is not supported.\n",
148 needs_conversion =
ctx->format != in_sw_format;
150 av_log(avctx,
AV_LOG_ERROR,
"The HQ scaler does not convert formats, format must be same or %s.\n",
154 ctx->format = in_sw_format;
155 needs_conversion = 0;
162 if (needs_conversion) {
163 AMFSize in_size = { inlink->
w, inlink->
h };
165 res =
ctx->amf_device_ctx->factory->pVtbl->CreateComponent(
ctx->amf_device_ctx->factory,
ctx->amf_device_ctx->context, AMFVideoConverter, &
ctx->pre_converter);
168 AMF_ASSIGN_PROPERTY_INT64(res,
ctx->pre_converter, AMF_VIDEO_CONVERTER_OUTPUT_FORMAT, (amf_int32)
av_av_to_amf_format(
ctx->format));
170 AMF_ASSIGN_PROPERTY_SIZE(res,
ctx->pre_converter, AMF_VIDEO_CONVERTER_OUTPUT_SIZE, in_size);
172 AMF_ASSIGN_PROPERTY_INT64(res,
ctx->pre_converter, AMF_VIDEO_CONVERTER_OUTPUT_COLOR_RANGE, AMF_COLOR_RANGE_FULL);
177 "AMFConverter-Init() failed with error %d, %s to %s is not supported by this device%s\n",
181 in_format =
ctx->format;
185 if (inlink->
w > outlink->
w || inlink->
h > outlink->
h) {
190 res =
ctx->amf_device_ctx->factory->pVtbl->CreateComponent(
ctx->amf_device_ctx->factory,
ctx->amf_device_ctx->context, AMFHQScaler, &
ctx->component);
194 if (mem_type != AMF_MEMORY_UNKNOWN)
195 AMF_ASSIGN_PROPERTY_INT64(res,
ctx->component, AMF_HQ_SCALER_ENGINE_TYPE, mem_type);
199 AMF_ASSIGN_PROPERTY_SIZE(res,
ctx->component, AMF_HQ_SCALER_OUTPUT_SIZE,
out_size);
202 if (
ctx->algorithm != -1) {
203 AMF_ASSIGN_PROPERTY_INT64(res,
ctx->component, AMF_HQ_SCALER_ALGORITHM,
ctx->algorithm);
205 if (
ctx->sharpness != -1) {
206 AMF_ASSIGN_PROPERTY_DOUBLE(res,
ctx->component, AMF_HQ_SCALER_SHARPNESS,
ctx->sharpness);
208 AMF_ASSIGN_PROPERTY_BOOL(res,
ctx->component, AMF_HQ_SCALER_FILL,
ctx->fill);
209 AMF_ASSIGN_PROPERTY_BOOL(res,
ctx->component, AMF_HQ_SCALER_KEEP_ASPECT_RATIO,
ctx->keep_ratio);
211 ctx->in_color_range = AMF_COLOR_RANGE_UNDEFINED;
212 ctx->in_primaries = AMF_COLOR_PRIMARIES_UNDEFINED;
213 ctx->in_trc = AMF_COLOR_TRANSFER_CHARACTERISTIC_UNDEFINED;
214 ctx->color_profile = AMF_VIDEO_CONVERTER_COLOR_PROFILE_UNKNOWN;
215 ctx->out_color_range = needs_conversion ? AMF_COLOR_RANGE_FULL : AMF_COLOR_RANGE_UNDEFINED;
216 ctx->out_primaries = AMF_COLOR_PRIMARIES_UNDEFINED;
217 ctx->out_trc = AMF_COLOR_TRANSFER_CHARACTERISTIC_UNDEFINED;
225#define OFFSET(x) offsetof(AMFFilterContext, x)
226#define FLAGS AV_OPT_FLAG_VIDEO_PARAM|AV_OPT_FLAG_FILTERING_PARAM
236 {
"algorithm",
"Scaling algorithm",
OFFSET(algorithm),
AV_OPT_TYPE_INT, { .i64 = -1 }, -1, AMF_HQ_SCALER_ALGORITHM_VIDEOSR1_1,
FLAGS,
"algorithm" },
237 {
"bilinear",
"Bilinear", 0,
AV_OPT_TYPE_CONST, { .i64 = AMF_HQ_SCALER_ALGORITHM_BILINEAR }, 0, 0,
FLAGS,
"algorithm" },
238 {
"bicubic",
"Bicubic", 0,
AV_OPT_TYPE_CONST, { .i64 = AMF_HQ_SCALER_ALGORITHM_BICUBIC }, 0, 0,
FLAGS,
"algorithm" },
239 {
"sr1-0",
"Video SR1.0", 0,
AV_OPT_TYPE_CONST, { .i64 = AMF_HQ_SCALER_ALGORITHM_VIDEOSR1_0 }, 0, 0,
FLAGS,
"algorithm" },
240 {
"point",
"Point", 0,
AV_OPT_TYPE_CONST, { .i64 = AMF_HQ_SCALER_ALGORITHM_POINT }, 0, 0,
FLAGS,
"algorithm" },
241 {
"sr1-1",
"Video SR1.1", 0,
AV_OPT_TYPE_CONST, { .i64 = AMF_HQ_SCALER_ALGORITHM_VIDEOSR1_1 }, 0, 0,
FLAGS,
"algorithm" },
267 .p.priv_class = &sr_amf_class,
static const char *const format[]
const FFFilter ff_vf_sr_amf
#define AMF_RETURN_IF_FALSE(avctx, exp, ret_value,...)
Error handling helper.
static AVFormatContext * ctx
simple assert() macros that are a bit more flexible than ISO C assert().
Main libavfilter public API header.
#define i(width, name, range_min, range_max)
int(* init)(AVBSFContext *ctx)
@ AV_OPT_TYPE_CONST
Special option type for declaring named constants.
@ AV_OPT_TYPE_INT
Underlying C type is int.
@ AV_OPT_TYPE_FLOAT
Underlying C type is float.
@ AV_OPT_TYPE_BOOL
Underlying C type is int.
@ AV_OPT_TYPE_STRING
Underlying C type is a uint8_t* that is either NULL or points to a C string allocated with the av_mal...
#define AVFILTER_FLAG_HWDEVICE
The filter can create hardware frames using AVFilterContext.hw_device_ctx.
#define AVERROR_FILTER_NOT_FOUND
Filter not found.
#define AVERROR_UNKNOWN
Unknown error, typically from an external library.
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
enum AMF_MEMORY_TYPE av_amf_get_memory_type(AVAMFDeviceContext *amf_ctx)
enum AMF_SURFACE_FORMAT av_av_to_amf_format(enum AVPixelFormat fmt)
static av_cold void uninit(AVBitStreamFilterContext *ctx)
static int activate(AVBitStreamFilterContext *ctx)
#define FILTER_INPUTS(array)
#define FILTER_OUTPUTS(array)
#define FF_FILTER_FLAG_HWFRAME_AWARE
The filter is aware of hardware frames, and any hardware frame context should not be automatically pr...
#define FILTER_QUERY_FUNC(func)
#define AVFILTER_DEFINE_CLASS(fname)
#define NULL_IF_CONFIG_SMALL(x)
Return NULL if CONFIG_SMALL is true, otherwise the argument without modification.
const char * av_get_pix_fmt_name(enum AVPixelFormat pix_fmt)
Return the short name for a pixel format, NULL in case pix_fmt is unknown.
#define AV_PIX_FMT_RGBAF16
AVPixelFormat
Pixel format.
@ AV_PIX_FMT_NV12
planar YUV 4:2:0, 12bpp, 1 plane for Y and 1 plane for the UV components, which are interleaved (firs...
@ AV_PIX_FMT_DXVA2_VLD
HW decoding through DXVA2, Picture.data[3] contains a LPDIRECT3DSURFACE9 pointer.
@ AV_PIX_FMT_BGRA
packed BGRA 8:8:8:8, 32bpp, BGRABGRA...
@ AV_PIX_FMT_RGBA
packed RGBA 8:8:8:8, 32bpp, RGBARGBA...
@ AV_PIX_FMT_D3D11
Hardware surfaces for Direct3D11.
@ AV_PIX_FMT_AMF_SURFACE
HW acceleration through AMF.
#define AV_PIX_FMT_X2BGR10
AVFilterLink ** inputs
array of pointers to input links
void * priv
private data for use by the filter
A link between two filters.
int w
agreed upon image width
int h
agreed upon image height
AVFilterContext * src
source filter
A filter pad used for either input or output.
int amf_setup_input_output_formats(AVFilterContext *avctx, const enum AVPixelFormat *input_pix_fmts)
int amf_filter_activate(AVFilterContext *avctx)
int amf_filter_init(AVFilterContext *avctx)
int amf_init_filter_config(AVFilterLink *outlink, enum AVPixelFormat *in_format)
enum AVPixelFormat amf_inlink_sw_format(AVFilterLink *inlink)
void amf_filter_uninit(AVFilterContext *avctx)
static const AVFilterPad amf_filter_inputs[]
static int amf_filter_query_formats(AVFilterContext *avctx)
static const AVFilterPad amf_filter_outputs[]
static int amf_hq_scaler_needs_packed_rgb(int algorithm)
static int amf_is_packed_rgb(enum AVPixelFormat format)
static int amf_filter_config_output(AVFilterLink *outlink)
static int amf_filter_query_formats(AVFilterContext *avctx)
static const AVOption sr_amf_options[]