29#include "AMF/components/VideoDecoderUVD.h"
46 if (!strcmp(
ctx->format_str,
"same")) {
64 ctx->component->pVtbl->Terminate(
ctx->component);
65 ctx->component->pVtbl->Release(
ctx->component);
69 if (
ctx->master_display)
87 AMFSurface *surface_in;
88 AMFSurface *surface_out;
89 AMFData *data_out =
NULL;
103 res =
ctx->component->pVtbl->SubmitInput(
ctx->component, (AMFData*)surface_in);
104 surface_in->pVtbl->Release(surface_in);
106 res =
ctx->component->pVtbl->QueryOutput(
ctx->component, &data_out);
110 AMFGuid guid = IID_AMFSurface();
111 res = data_out->pVtbl->QueryInterface(data_out, &guid, (
void**)&surface_out);
112 data_out->pVtbl->Release(data_out);
125 if (
ctx->color_profile != AMF_VIDEO_CONVERTER_COLOR_PROFILE_UNKNOWN) {
126 switch(
ctx->color_profile) {
127 case AMF_VIDEO_CONVERTER_COLOR_PROFILE_601:
130 case AMF_VIDEO_CONVERTER_COLOR_PROFILE_709:
133 case AMF_VIDEO_CONVERTER_COLOR_PROFILE_2020:
136 case AMF_VIDEO_CONVERTER_COLOR_PROFILE_JPEG:
143 out->colorspace = out_colorspace;
147 if (
ctx->out_color_range == AMF_COLOR_RANGE_FULL)
149 else if (
ctx->out_color_range == AMF_COLOR_RANGE_STUDIO)
152 if (
ctx->out_color_range != AMF_COLOR_RANGE_UNDEFINED)
153 out->color_range = out_color_range;
155 if (
ctx->out_primaries != AMF_COLOR_PRIMARIES_UNDEFINED)
156 out->color_primaries =
ctx->out_primaries;
158 if (
ctx->out_trc != AMF_COLOR_TRANSFER_CHARACTERISTIC_UNDEFINED)
159 out->color_trc =
ctx->out_trc;
166 if (!
out->hw_frames_ctx) {
194 switch (device_ctx->
type) {
202 output_pix_fmts = output_pix_fmts_d3d11;
213 output_pix_fmts = output_pix_fmts_dxva2;
229 if (!input_formats) {
233 if (!output_formats) {
249 uint8_t *dst_data[4];
254 planes = (int)surface->pVtbl->GetPlanesCount(surface);
258 plane = surface->pVtbl->GetPlaneAt(surface,
i);
259 dst_data[
i] = plane->pVtbl->GetNative(plane);
260 dst_linesize[
i] = plane->pVtbl->GetHPitch(plane);
284 if (
ctx->w_expr &&
ctx->h_expr) {
288 &
ctx->width, &
ctx->height)) < 0)
291 ctx->width = inlink->
w;
292 ctx->height = inlink->
h;
299 ctx->force_original_aspect_ratio,
300 ctx->force_divisible_by, w_adj);
307 ctx->local_context = 0;
311 av_log(avctx,
AV_LOG_ERROR,
"Format of input frames context (%s) is not supported by AMF.\n",
321 if (!
ctx->hwframes_in_ref)
330 if (!
ctx->hwdevice_ref)
340 out_sw_format = in_sw_format;
342 out_sw_format = outlink->
format;
345 if (!
ctx->hwframes_out_ref)
351 ctx->amf_device_ctx = hwdev_ctx->
hwctx;
359 *in_format = in_sw_format;
360 outlink->
w =
ctx->width;
361 outlink->
h =
ctx->height;
370 hwframes_out->
width = outlink->
w;
371 hwframes_out->
height = outlink->
h;
386 AMFSurface *surface = (AMFSurface*)
data;
387 surface->pVtbl->Release(surface);
398 if (
ctx->hwframes_out_ref) {
406 frame->data[0] = (uint8_t *)pSurface;
417 switch (pSurface->pVtbl->GetMemoryType(pSurface))
420 case AMF_MEMORY_DX11:
422 AMFPlane *plane0 = pSurface->pVtbl->GetPlaneAt(pSurface, 0);
423 frame->data[0] = plane0->pVtbl->GetNative(plane0);
424 frame->data[1] = (uint8_t*)(intptr_t)0;
437 AMFPlane *plane0 = pSurface->pVtbl->GetPlaneAt(pSurface, 0);
438 frame->data[3] = plane0->pVtbl->GetNative(plane0);
450 av_log(avctx,
AV_LOG_ERROR,
"Unsupported memory type : %d\n", pSurface->pVtbl->GetMemoryType(pSurface));
465 AMFVariantStruct var = { 0 };
467 AMFBuffer *hdrmeta_buffer =
NULL;
472 switch (
frame->format) {
476 static const GUID AMFTextureArrayIndexGUID = { 0x28115527, 0xe7c3, 0x4b66, { 0x99, 0xd3, 0x4f, 0x2a, 0xe6, 0xb4, 0x7f, 0xaf } };
477 ID3D11Texture2D *texture = (ID3D11Texture2D*)
frame->data[0];
479 texture->lpVtbl->SetPrivateData(texture, &AMFTextureArrayIndexGUID,
sizeof(
index), &
index);
481 res =
ctx->amf_device_ctx->context->pVtbl->CreateSurfaceFromDX11Native(
ctx->amf_device_ctx->context, texture, &surface,
NULL);
489 surface = (AMFSurface*)
frame->data[0];
490 surface->pVtbl->Acquire(surface);
498 IDirect3DSurface9 *texture = (IDirect3DSurface9 *)
frame->data[3];
500 res =
ctx->amf_device_ctx->context->pVtbl->CreateSurfaceFromDX9Native(
ctx->amf_device_ctx->context, texture, &surface,
NULL);
509 res =
ctx->amf_device_ctx->context->pVtbl->AllocSurface(
ctx->amf_device_ctx->context, AMF_MEMORY_HOST, amf_fmt,
frame->width,
frame->height, &surface);
524 res = surface->pVtbl->GetProperty(surface, AMF_VIDEO_DECODER_COLOR_TRANSFER_CHARACTERISTIC, &var);
531 AMF_ASSIGN_PROPERTY_INT64(res, surface, AMF_VIDEO_DECODER_COLOR_TRANSFER_CHARACTERISTIC,
frame->color_trc);
533 res = surface->pVtbl->GetProperty(surface, AMF_VIDEO_DECODER_COLOR_PRIMARIES, &var);
535 AMF_ASSIGN_PROPERTY_INT64(res, surface, AMF_VIDEO_DECODER_COLOR_PRIMARIES,
frame->color_primaries);
537 res = surface->pVtbl->GetProperty(surface, AMF_VIDEO_DECODER_COLOR_RANGE, &var);
539 AMF_ASSIGN_PROPERTY_INT64(res, surface, AMF_VIDEO_DECODER_COLOR_RANGE,
frame->color_range);
543 AMF_ASSIGN_PROPERTY_BOOL(res, surface, AMF_VIDEO_DECODER_FULL_RANGE_COLOR, 1);
545 AMF_ASSIGN_PROPERTY_BOOL(res, surface, AMF_VIDEO_DECODER_FULL_RANGE_COLOR, 0);
548 res = surface->pVtbl->GetProperty(surface, AMF_VIDEO_DECODER_COLOR_PROFILE, &var);
552 if (color_profile != AMF_VIDEO_CONVERTER_COLOR_PROFILE_UNKNOWN)
553 AMF_ASSIGN_PROPERTY_INT64(res, surface, AMF_VIDEO_DECODER_COLOR_PROFILE, color_profile);
556 if (
ctx->in_trc == AMF_COLOR_TRANSFER_CHARACTERISTIC_SMPTE2084 && (
ctx->master_display ||
ctx->light_meta)) {
557 res =
ctx->amf_device_ctx->context->pVtbl->AllocBuffer(
ctx->amf_device_ctx->context, AMF_MEMORY_HOST,
sizeof(AMFHDRMetadata), &hdrmeta_buffer);
559 AMFHDRMetadata *hdrmeta = (AMFHDRMetadata*)hdrmeta_buffer->pVtbl->GetNative(hdrmeta_buffer);
563 AMF_ASSIGN_PROPERTY_INTERFACE(res, surface, AMF_VIDEO_DECODER_HDR_METADATA, hdrmeta_buffer);
566 res = surface->pVtbl->GetProperty(surface, AMF_VIDEO_DECODER_HDR_METADATA, &var);
567 if (res == AMF_NOT_FOUND) {
568 res =
ctx->amf_device_ctx->context->pVtbl->AllocBuffer(
ctx->amf_device_ctx->context, AMF_MEMORY_HOST,
sizeof(AMFHDRMetadata), &hdrmeta_buffer);
570 AMFHDRMetadata *hdrmeta = (AMFHDRMetadata*)hdrmeta_buffer->pVtbl->GetNative(hdrmeta_buffer);
573 AMF_ASSIGN_PROPERTY_INTERFACE(res, surface, AMF_VIDEO_DECODER_HDR_METADATA, hdrmeta_buffer);
578 if (hdrmeta_buffer) {
579 hdrmeta_buffer->pVtbl->Release(hdrmeta_buffer);
580 hdrmeta_buffer =
NULL;
584 size_t crop_x =
frame->crop_left;
585 size_t crop_y =
frame->crop_top;
587 size_t crop_h =
frame->height - (
frame->crop_top +
frame->crop_bottom);
589 if (crop_x || crop_y) {
590 if (crop_w == outlink->
w && crop_h == outlink->
h) {
591 AMFData *cropped_buffer =
NULL;
592 res = surface->pVtbl->Duplicate(surface, surface->pVtbl->GetMemoryType(surface), &cropped_buffer);
594 surface->pVtbl->Release(surface);
595 surface = (AMFSurface*)cropped_buffer;
598 surface->pVtbl->SetCrop(surface, (amf_int32)crop_x, (amf_int32)crop_y, (amf_int32)crop_w, (amf_int32)crop_h);
601 surface->pVtbl->SetCrop(surface, (amf_int32)crop_x, (amf_int32)crop_y, (amf_int32)crop_w, (amf_int32)crop_h);
603 else if (hw_surface) {
605 surface->pVtbl->SetCrop(surface, 0, 0,
frame->width,
frame->height);
608 surface->pVtbl->SetPts(surface,
frame->pts);
609 *ppSurface = surface;
static void amf_free_amfsurface(void *opaque, uint8_t *data)
#define AMF_RETURN_IF_FALSE(avctx, exp, ret_value,...)
Error handling helper.
simple assert() macros that are a bit more flexible than ISO C assert().
#define av_assert0(cond)
assert() equivalent, that is always enabled.
int ff_filter_frame(AVFilterLink *link, AVFrame *frame)
Send a frame of data to the next filter.
Main libavfilter public API header.
#define i(width, name, range_min, range_max)
void av_buffer_unref(AVBufferRef **buf)
Free a given reference and automatically free the buffer if there are no more references to it.
AVBufferRef * av_buffer_ref(const AVBufferRef *buf)
Create a new reference to an AVBuffer.
#define AV_BUFFER_FLAG_READONLY
Always treat the buffer as read-only, even when it has only one reference.
AVBufferRef * av_buffer_create(uint8_t *data, size_t size, void(*free)(void *opaque, uint8_t *data), void *opaque, int flags)
Create an AVBuffer from an existing array.
#define AVERROR_UNKNOWN
Unknown error, typically from an external library.
#define av_err2str(errnum)
Convenience macro, the return value should be used only directly in function arguments but never stan...
void av_frame_unref(AVFrame *frame)
Unreference all the buffers referenced by frame and reset the frame fields.
void av_frame_free(AVFrame **frame)
Free the frame and any dynamically allocated objects in it, e.g.
int av_frame_copy_props(AVFrame *dst, const AVFrame *src)
Copy only "metadata" fields from src to dst.
AVFrame * av_frame_alloc(void)
Allocate an AVFrame and set its fields to default values.
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
AVRational av_mul_q(AVRational b, AVRational c)
Multiply two rationals.
void av_image_copy(uint8_t *const dst_data[4], const int dst_linesizes[4], const uint8_t *const src_data[4], const int src_linesizes[4], enum AVPixelFormat pix_fmt, int width, int height)
Copy image in src_data to dst_data.
int av_hwdevice_ctx_create(AVBufferRef **pdevice_ref, enum AVHWDeviceType type, const char *device, AVDictionary *opts, int flags)
Open a device of the specified type and create an AVHWDeviceContext for it.
const char * av_hwdevice_get_type_name(enum AVHWDeviceType type)
Get the string name of an AVHWDeviceType.
int av_hwdevice_ctx_create_derived(AVBufferRef **dst_ref_ptr, enum AVHWDeviceType type, AVBufferRef *src_ref, int flags)
Create a new device of the specified type from an existing device.
int av_hwframe_ctx_init(AVBufferRef *ref)
Finalize the context before use.
AVBufferRef * av_hwframe_ctx_alloc(AVBufferRef *device_ref_in)
Allocate an AVHWFramesContext tied to a given device context.
int av_hwframe_get_buffer(AVBufferRef *hwframe_ref, AVFrame *frame, int flags)
Allocate a new frame attached to the given AVHWFramesContext.
@ AV_HWDEVICE_TYPE_D3D11VA
int av_amf_display_mastering_meta_to_hdrmeta(const AVMasteringDisplayMetadata *display_meta, AMFHDRMetadata *hdrmeta)
int av_amf_light_metadata_to_hdrmeta(const AVContentLightMetadata *light_meta, AMFHDRMetadata *hdrmeta)
enum AMF_SURFACE_FORMAT av_av_to_amf_format(enum AVPixelFormat fmt)
int av_amf_extract_hdr_metadata(const AVFrame *frame, AMFHDRMetadata *hdrmeta)
enum AMF_VIDEO_CONVERTER_COLOR_PROFILE_ENUM av_amf_get_color_profile(enum AVColorRange color_range, enum AVColorSpace color_space)
#define AMF_GOTO_FAIL_IF_FALSE(avctx, exp, ret_value,...)
static FilterLink * ff_filter_link(AVFilterLink *link)
static const struct @257111027162314367033347246032313251342043035002 planes[]
Memory handling functions.
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.
enum AVPixelFormat av_get_pix_fmt(const char *name)
Return the pixel format corresponding to name.
const AVPixFmtDescriptor * av_pix_fmt_desc_get(enum AVPixelFormat pix_fmt)
#define AV_PIX_FMT_FLAG_HWACCEL
Pixel format is an HW accelerated format.
AVColorRange
Visual content value range.
@ AVCOL_RANGE_MPEG
Narrow or limited range content.
@ AVCOL_RANGE_UNSPECIFIED
@ AVCOL_RANGE_JPEG
Full range content.
AVPixelFormat
Pixel format.
@ AV_PIX_FMT_DXVA2_VLD
HW decoding through DXVA2, Picture.data[3] contains a LPDIRECT3DSURFACE9 pointer.
@ AV_PIX_FMT_D3D11
Hardware surfaces for Direct3D11.
@ AV_PIX_FMT_AMF_SURFACE
HW acceleration through AMF.
@ AVCOL_TRC_SMPTE2084
SMPTE ST 2084 for 10-, 12-, 14- and 16-bit systems.
AVColorSpace
YUV colorspace type.
@ AVCOL_SPC_BT709
also ITU-R BT1361 / IEC 61966-2-4 xvYCC709 / derived in SMPTE RP 177 Annex B
@ AVCOL_SPC_RGB
order of coefficients is actually GBR, also IEC 61966-2-1 (sRGB), YZX and ST 428-1
@ AVCOL_SPC_BT2020_NCL
ITU-R BT2020 non-constant luminance system.
@ AVCOL_SPC_SMPTE170M
also ITU-R BT601-6 525 / ITU-R BT1358 525 / ITU-R BT1700 NTSC / functionally identical to above
int ff_scale_adjust_dimensions(AVFilterLink *inlink, int *ret_w, int *ret_h, int force_original_aspect_ratio, int force_divisible_by, double w_adj)
Transform evaluated width and height obtained from ff_scale_eval_dimensions into actual target width ...
int ff_scale_eval_dimensions(void *log_ctx, const char *w_expr, const char *h_expr, AVFilterLink *inlink, AVFilterLink *outlink, int *ret_w, int *ret_h)
Parse and evaluate string expressions for width and height.
#define FF_ARRAY_ELEMS(a)
uint8_t * data
The data buffer.
AVFilterLink ** inputs
array of pointers to input links
void * priv
private data for use by the filter
AVBufferRef * hw_device_ctx
For filters which will create hardware frames, sets the device the filter should create them in.
AVFilterLink ** outputs
array of pointers to output links
A link between two filters.
AVFilterFormatsConfig incfg
Lists of supported formats / etc.
int w
agreed upon image width
int h
agreed upon image height
AVFilterFormatsConfig outcfg
Lists of supported formats / etc.
AVFilterContext * src
source filter
AVRational sample_aspect_ratio
agreed upon sample aspect ratio
AVFilterContext * dst
dest filter
int format
agreed upon media format
This structure describes decoded (raw) audio or video data.
This struct aggregates all the (hardware/vendor-specific) "high-level" state, i.e.
void * hwctx
The format-specific data, allocated and freed by libavutil along with this context.
enum AVHWDeviceType type
This field identifies the underlying API used for hardware access.
This struct describes a set or pool of "hardware" frames (i.e.
enum AVPixelFormat format
The pixel format identifying the underlying HW surface type.
AVBufferRef * device_ref
A reference to the parent AVHWDeviceContext.
enum AVPixelFormat sw_format
The pixel format identifying the actual data layout of the hardware frames.
int width
The allocated dimensions of the frames in this pool.
Descriptor that unambiguously describes how the bits of a pixel are stored in the up to 4 data planes...
Rational number (pair of numerator and denominator).
Link properties exposed to filter code, but not external callers.
AVBufferRef * hw_frames_ctx
For hwaccel pixel formats, this should be a reference to the AVHWFramesContext describing the frames.
static AVFormatContext * ctx
void amf_free_amfsurface(void *opaque, uint8_t *data)
AVFrame * amf_amfsurface_to_avframe(AVFilterContext *avctx, AMFSurface *pSurface)
int amf_copy_surface(AVFilterContext *avctx, const AVFrame *frame, AMFSurface *surface)
int amf_avframe_to_amfsurface(AVFilterContext *avctx, const AVFrame *frame, AMFSurface **ppSurface)
int amf_filter_init(AVFilterContext *avctx)
int amf_init_filter_config(AVFilterLink *outlink, enum AVPixelFormat *in_format)
int amf_filter_filter_frame(AVFilterLink *inlink, AVFrame *in)
int amf_setup_input_output_formats(AVFilterContext *avctx, const enum AVPixelFormat *input_pix_fmts, const enum AVPixelFormat *output_pix_fmts)
void amf_filter_uninit(AVFilterContext *avctx)