Go to the documentation of this file.
32 #include <AMF/core/Surface.h>
33 #include <AMF/core/Trace.h>
53 #define FFMPEG_AMF_WRITER_ID L"ffmpeg_amf"
72 const wchar_t *scope,
const wchar_t *
message)
91 writer->
avctx = avctx;
141 return AMF_SURFACE_UNKNOWN;
157 switch (color_space) {
160 return AMF_VIDEO_CONVERTER_COLOR_PROFILE_FULL_601;
162 return AMF_VIDEO_CONVERTER_COLOR_PROFILE_601;
167 return AMF_VIDEO_CONVERTER_COLOR_PROFILE_FULL_709;
169 return AMF_VIDEO_CONVERTER_COLOR_PROFILE_709;
175 return AMF_VIDEO_CONVERTER_COLOR_PROFILE_FULL_2020;
177 return AMF_VIDEO_CONVERTER_COLOR_PROFILE_2020;
182 return AMF_VIDEO_CONVERTER_COLOR_PROFILE_UNKNOWN;
188 if (!display_meta || !hdrmeta)
192 const unsigned int luma_den = 10000;
193 hdrmeta->maxMasteringLuminance =
195 hdrmeta->minMasteringLuminance =
200 const unsigned int chroma_den = 50000;
201 hdrmeta->redPrimary[0] =
203 hdrmeta->redPrimary[1] =
205 hdrmeta->greenPrimary[0] =
207 hdrmeta->greenPrimary[1] =
209 hdrmeta->bluePrimary[0] =
211 hdrmeta->bluePrimary[1] =
213 hdrmeta->whitePoint[0] =
215 hdrmeta->whitePoint[1] =
224 if (!light_meta || !hdrmeta)
227 hdrmeta->maxContentLightLevel = (amf_uint16)light_meta->
MaxCLL;
228 hdrmeta->maxFrameAverageLightLevel = (amf_uint16)light_meta->
MaxFALL;
237 if (!
frame || !hdrmeta)
256 if (!hdrmeta || !
frame)
261 const int chroma_den = 50000;
262 const int luma_den = 10000;
268 av_make_q(hdrmeta->redPrimary[0], chroma_den);
270 av_make_q(hdrmeta->redPrimary[1], chroma_den);
273 av_make_q(hdrmeta->greenPrimary[0], chroma_den);
275 av_make_q(hdrmeta->greenPrimary[1], chroma_den);
278 av_make_q(hdrmeta->bluePrimary[0], chroma_den);
280 av_make_q(hdrmeta->bluePrimary[1], chroma_den);
286 av_make_q(hdrmeta->maxMasteringLuminance, luma_den);
288 av_make_q(hdrmeta->maxMasteringLuminance, luma_den);
292 if (hdrmeta->maxContentLightLevel) {
299 light->
MaxCLL = hdrmeta->maxContentLightLevel;
300 light->
MaxFALL = hdrmeta->maxFrameAverageLightLevel;
334 const void *hwconfig,
432 AMFSurface *surface = (AMFSurface*)(
data);
433 surface->pVtbl->Release(surface);
440 AMFSurface* surface = (AMFSurface*)
dst->data[0];
442 uint8_t *dst_data[4];
450 if (
dst->hw_frames_ctx->data != (uint8_t *)
ctx ||
src->format !=
ctx->sw_format)
457 res = amf_device_ctx->
context->pVtbl->AllocSurface(amf_device_ctx->
context, AMF_MEMORY_HOST,
format,
dst->width,
dst->height, &surface);
459 dst->data[0] = (uint8_t *)surface;
467 planes = (int)surface->pVtbl->GetPlanesCount(surface);
471 plane = surface->pVtbl->GetPlaneAt(surface,
i);
472 dst_data[
i] = plane->pVtbl->GetNative(plane);
473 dst_linesize[
i] = plane->pVtbl->GetHPitch(plane);
485 AMFSurface* surface = (AMFSurface*)
src->data[0];
487 uint8_t *src_data[4];
495 if (
src->hw_frames_ctx->data != (uint8_t *)
ctx ||
dst->format !=
ctx->sw_format)
498 ret = surface->pVtbl->Convert(surface, AMF_MEMORY_HOST);
501 planes = (int)surface->pVtbl->GetPlanesCount(surface);
505 plane = surface->pVtbl->GetPlaneAt(surface,
i);
506 src_data[
i] = plane->pVtbl->GetNative(plane);
507 src_linesize[
i] = plane->pVtbl->GetHPitch(plane);
510 src_data, src_linesize,
dst->format,
520 AMF_RESULT res = AMF_NOT_INITIALIZED;
530 res = amf_ctx->
factory->pVtbl->GetTrace(amf_ctx->
factory, &trace);
557 AMFContext1 *context1 =
NULL;
560 if (!amf_ctx->
lock) {
572 if (res == AMF_OK || res == AMF_ALREADY_INITIALIZED) {
580 AMFGuid guid = IID_AMFContext1();
581 res = amf_ctx->
context->pVtbl->QueryInterface(amf_ctx->
context, &guid, (
void**)&context1);
584 res = context1->pVtbl->InitVulkan(context1,
NULL);
585 context1->pVtbl->Release(context1);
586 if (res != AMF_OK && res != AMF_ALREADY_INITIALIZED) {
587 if (res == AMF_NOT_SUPPORTED)
605 AMFQueryVersion_Fn version_fun;
608 amf_ctx->
library = dlopen(AMF_DLL_NAMEA, RTLD_NOW | RTLD_LOCAL);
612 init_fun = (AMFInit_Fn)dlsym(amf_ctx->
library, AMF_INIT_FUNCTION_NAME);
615 version_fun = (AMFQueryVersion_Fn)dlsym(amf_ctx->
library, AMF_QUERY_VERSION_FUNCTION_NAME);
622 res = init_fun(AMF_FULL_VERSION, &amf_ctx->
factory);
635 ret =
ctx->factory->pVtbl->GetTrace(
ctx->factory, &trace);
638 int level_amf = AMF_TRACE_TRACE;
639 amf_bool enable_log =
true;
643 level_amf = AMF_TRACE_ERROR;
649 level_amf = AMF_TRACE_ERROR;
653 level_amf = AMF_TRACE_WARNING;
656 level_amf = AMF_TRACE_INFO;
659 level_amf = AMF_TRACE_DEBUG;
662 level_amf = AMF_TRACE_TRACE;
665 if(
ctx->version == AMF_MAKE_FULL_VERSION(1, 4, 35, 0)){
666 level_amf = AMF_TRACE_WARNING;
669 trace->pVtbl->EnableWriter(trace, AMF_TRACE_WRITER_CONSOLE, 0);
670 trace->pVtbl->SetGlobalLevel(trace, level_amf);
677 trace->pVtbl->SetWriterLevel(trace, AMF_TRACE_WRITER_DEBUG_OUTPUT, level_amf);
678 trace->pVtbl->EnableWriter(trace, AMF_TRACE_WRITER_DEBUG_OUTPUT, enable_log);
682 ret =
ctx->factory->pVtbl->CreateContext(
ctx->factory, &
ctx->context);
684 AMF_ASSIGN_PROPERTY_INT64(
ret,
ctx->context,
L"DeviceSurfaceCacheSize", 50 );
697 IDirect3DDevice9 *device;
698 HANDLE device_handle;
703 hr = IDirect3DDeviceManager9_OpenDeviceHandle(hwctx->
devmgr, &device_handle);
705 av_log(child_device_ctx,
AV_LOG_ERROR,
"Failed to open device handle for Direct3D9 device: %lx.\n", (
unsigned long)hr);
709 hr = IDirect3DDeviceManager9_LockDevice(hwctx->
devmgr, device_handle, &device, FALSE);
711 IDirect3DDeviceManager9_UnlockDevice(hwctx->
devmgr, device_handle, FALSE);
714 av_log(child_device_ctx,
AV_LOG_ERROR,
"Failed to lock device handle for Direct3D9 device: %lx.\n", (
unsigned long)hr);
719 IDirect3DDeviceManager9_CloseDeviceHandle(hwctx->
devmgr, device_handle);
726 IDirect3DDevice9_Release(device);
728 if (res != AMF_OK && res != AMF_ALREADY_INITIALIZED) {
729 if (res == AMF_NOT_SUPPORTED)
730 av_log(child_device_ctx,
AV_LOG_ERROR,
"AMF via D3D9 is not supported on the given device.\n");
732 av_log(child_device_ctx,
AV_LOG_ERROR,
"AMF failed to initialise on given D3D9 device: %d.\n", res);
746 if (res != AMF_OK && res != AMF_ALREADY_INITIALIZED) {
747 if (res == AMF_NOT_SUPPORTED)
748 av_log(child_device_ctx,
AV_LOG_ERROR,
"AMF via D3D11 is not supported on the given device.\n");
750 av_log(child_device_ctx,
AV_LOG_ERROR,
"AMF failed to initialise on the given D3D11 device: %d.\n", res);
763 AMFContext2 *context2 =
NULL;
764 AMFGuid guid = IID_AMFContext2();
765 res = amf_ctx->
context->pVtbl->QueryInterface(amf_ctx->
context, &guid, (
void**)&context2);
767 res = context2->pVtbl->InitDX12(context2, hwctx->
device, AMF_DX12);
768 context2->pVtbl->Release(context2);
769 if (res != AMF_OK && res != AMF_ALREADY_INITIALIZED) {
770 if (res == AMF_NOT_SUPPORTED)
771 av_log(child_device_ctx,
AV_LOG_ERROR,
"AMF via D3D12 is not supported on the given device.\n");
773 av_log(child_device_ctx,
AV_LOG_ERROR,
"AMF failed to initialise on the given D3D12 device: %d.\n", res);
786 #if CONFIG_DXVA2 || CONFIG_D3D11VA
795 switch (child_device_ctx->
type) {
798 return amf_init_from_dxva2_device(amf_ctx, child_device_ctx);
802 return amf_init_from_d3d11_device(amf_ctx, child_device_ctx);
806 return amf_init_from_d3d12_device(amf_ctx, child_device_ctx);
809 av_log(child_device_ctx,
AV_LOG_ERROR,
"AMF initialisation from a %s device is not supported.\n",
void * hwctx
The format-specific data, allocated and freed by libavutil along with this context.
AVBufferPool * pool_internal
ID3D12Device * device
Device used for objects creation and access.
#define AV_LOG_WARNING
Something somehow does not look correct.
AVPixelFormat
Pixel format.
static int ff_mutex_init(AVMutex *mutex, const void *attr)
Filter the word “frame” indicates either a video frame or a group of audio as stored in an AVFrame structure Format for each input and each output the list of supported formats For video that means pixel format For audio that means channel sample they are references to shared objects When the negotiation mechanism computes the intersection of the formats supported at each end of a all references to both lists are replaced with a reference to the intersection And when a single format is eventually chosen for a link amongst the remaining all references to the list are updated That means that if a filter requires that its input and output have the same format amongst a supported all it has to do is use a reference to the same list of formats query_formats can leave some formats unset and return AVERROR(EAGAIN) to cause the negotiation mechanism toagain later. That can be used by filters with complex requirements to use the format negotiated on one link to set the formats supported on another. Frame references ownership and permissions
AVFrameSideData * av_frame_get_side_data(const AVFrame *frame, enum AVFrameSideDataType type)
#define AV_LOG_QUIET
Print no output.
#define AV_LOG_PANIC
Something went really wrong and we will crash now.
static AmfTraceWriter * amf_writer_alloc(void *avctx)
int av_amf_attach_hdr_metadata(AVFrame *frame, const AMFHDRMetadata *hdrmeta)
unsigned MaxCLL
Max content light level (cd/m^2).
This structure describes decoded (raw) audio or video data.
@ AVCOL_RANGE_JPEG
Full range content.
static void amf_dummy_free(void *opaque, uint8_t *data)
void(* lock)(void *lock_ctx)
static int amf_device_create(AVHWDeviceContext *device_ctx, const char *device, AVDictionary *opts, int flags)
IDirect3DDeviceManager9 * devmgr
#define AV_LOG_VERBOSE
Detailed information.
static void AMF_CDECL_CALL AMFTraceWriter_Write(AMFTraceWriter *pThis, const wchar_t *scope, const wchar_t *message)
@ AV_PIX_FMT_BGRA
packed BGRA 8:8:8:8, 32bpp, BGRABGRA...
#define AMF_RETURN_IF_FALSE(avctx, exp, ret_value,...)
Error handling helper.
enum AVPixelFormat * valid_hw_formats
A list of possible values for format in the hw_frames_ctx, terminated by AV_PIX_FMT_NONE.
#define AVERROR_UNKNOWN
Unknown error, typically from an external library.
@ AVCOL_SPC_BT2020_CL
ITU-R BT2020 constant luminance system.
@ AV_PIX_FMT_AMF_SURFACE
HW acceleration through AMF.
int av_amf_display_mastering_meta_to_hdrmeta(const AVMasteringDisplayMetadata *display_meta, AMFHDRMetadata *hdrmeta)
This struct describes the constraints on hardware frames attached to a given device with a hardware-s...
static int ff_mutex_unlock(AVMutex *mutex)
Content light level needed by to transmit HDR over HDMI (CTA-861.3).
enum AVPixelFormat av_amf_to_av_format(enum AMF_SURFACE_FORMAT fmt)
@ AV_HWDEVICE_TYPE_D3D11VA
AVBufferPool * av_buffer_pool_init2(size_t size, void *opaque, AVBufferRef *(*alloc)(void *opaque, size_t size), void(*pool_free)(void *opaque))
Allocate and initialize a buffer pool with a more complex allocator.
enum AMF_SURFACE_FORMAT av_av_to_amf_format(enum AVPixelFormat fmt)
This struct aggregates all the (hardware/vendor-specific) "high-level" state, i.e.
static int amf_transfer_get_formats(AVHWFramesContext *ctx, enum AVHWFrameTransferDirection dir, enum AVPixelFormat **formats)
static FFHWFramesContext * ffhwframesctx(AVHWFramesContext *ctx)
#define AV_LOG_TRACE
Extremely verbose debugging, useful for libav* development.
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
#define FF_ARRAY_ELEMS(a)
enum AMF_VIDEO_CONVERTER_COLOR_PROFILE_ENUM av_amf_get_color_profile(enum AVColorRange color_range, enum AVColorSpace color_space)
enum AVPixelFormat * valid_sw_formats
A list of possible values for sw_format in the hw_frames_ctx, terminated by AV_PIX_FMT_NONE.
AVBufferRef * av_buffer_pool_get(AVBufferPool *pool)
Allocate a new AVBuffer, reusing an old buffer from the pool when available.
@ AV_PIX_FMT_DXVA2_VLD
HW decoding through DXVA2, Picture.data[3] contains a LPDIRECT3DSURFACE9 pointer.
static int amf_frames_get_constraints(AVHWDeviceContext *ctx, const void *hwconfig, AVHWFramesConstraints *constraints)
ID3D11Device * device
Device used for texture creation and access.
#define AV_BUFFER_FLAG_READONLY
Always treat the buffer as read-only, even when it has only one reference.
@ AVCOL_SPC_SMPTE170M
also ITU-R BT601-6 525 / ITU-R BT1358 525 / ITU-R BT1700 NTSC / functionally identical to above
static double av_q2d(AVRational a)
Convert an AVRational to a double.
AMFTraceWriterVtbl * vtblp
#define av_assert0(cond)
assert() equivalent, that is always enabled.
static int amf_device_init(AVHWDeviceContext *ctx)
#define AV_LOG_DEBUG
Stuff which is only useful for libav* developers.
static int amf_transfer_data_to(AVHWFramesContext *ctx, AVFrame *dst, const AVFrame *src)
static AVFormatContext * ctx
#define FFMPEG_AMF_WRITER_ID
int64_t version
version of AMF runtime
static void amf_writer_free(void *opaque)
const char * av_hwdevice_get_type_name(enum AVHWDeviceType type)
Get the string name of an AVHWDeviceType.
@ AV_PIX_FMT_YUV420P
planar YUV 4:2:0, 12bpp, (1 Cr & Cb sample per 2x2 Y samples)
@ AV_PIX_FMT_RGBA
packed RGBA 8:8:8:8, 32bpp, RGBARGBA...
int av_log_get_level(void)
Get the current log level.
static AVDictionary * opts
static AVBufferRef * amf_pool_alloc(void *opaque, size_t size)
New swscale design to change SwsGraph is what coordinates multiple passes These can include cascaded scaling error diffusion and so on Or we could have separate passes for the vertical and horizontal scaling In between each SwsPass lies a fully allocated image buffer Graph passes may have different levels of e g we can have a single threaded error diffusion pass following a multi threaded scaling pass SwsGraph is internally recreated whenever the image format
@ AV_PIX_FMT_YUYV422
packed YUV 4:2:2, 16bpp, Y0 Cb Y1 Cr
@ AV_FRAME_DATA_MASTERING_DISPLAY_METADATA
Mastering display metadata associated with a video frame.
@ AV_PIX_FMT_BGR0
packed BGR 8:8:8, 32bpp, BGRXBGRX... X=unused/undefined
@ AV_PIX_FMT_D3D12
Hardware surfaces for Direct3D 12.
static const struct @561 planes[]
@ AV_PIX_FMT_GRAY8
Y , 8bpp.
static int amf_get_buffer(AVHWFramesContext *ctx, AVFrame *frame)
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.
static int ff_mutex_destroy(AVMutex *mutex)
#define AV_PIX_FMT_X2BGR10
@ AV_HWDEVICE_TYPE_D3D12VA
static void amf_free_amfsurface(void *opaque, uint8_t *data)
uint8_t ptrdiff_t const uint8_t ptrdiff_t int intptr_t intptr_t int int16_t * dst
#define i(width, name, range_min, range_max)
int av_amf_extract_hdr_metadata(const AVFrame *frame, AMFHDRMetadata *hdrmeta)
This struct is allocated as AVHWDeviceContext.hwctx.
static void amf_lock_default(void *opaque)
const HWContextType ff_hwcontext_type_amf
static AVRational av_make_q(int num, int den)
Create an AVRational.
static void amf_device_uninit(AVHWDeviceContext *device_ctx)
We still need AVHWFramesContext to utilize our hardware memory otherwise, we will receive the error "...
#define AVERROR_EXTERNAL
Generic error in an external library.
static int ff_mutex_lock(AVMutex *mutex)
@ AV_PIX_FMT_RGB0
packed RGB 8:8:8, 32bpp, RGBXRGBX... X=unused/undefined
@ AV_PIX_FMT_D3D11
Hardware surfaces for Direct3D11.
static int amf_frames_init(AVHWFramesContext *ctx)
#define AV_LOG_INFO
Standard information.
@ AV_PIX_FMT_ARGB
packed ARGB 8:8:8:8, 32bpp, ARGBARGB...
@ AV_FRAME_DATA_CONTENT_LIGHT_LEVEL
Content light level (based on CTA-861.3).
This struct is allocated as AVHWDeviceContext.hwctx.
@ AVCOL_SPC_BT2020_NCL
ITU-R BT2020 non-constant luminance system.
This struct is allocated as AVHWDeviceContext.hwctx.
#define av_malloc_array(a, b)
AVColorSpace
YUV colorspace type.
This struct is allocated as AVHWDeviceContext.hwctx.
static int amf_transfer_data_from(AVHWFramesContext *ctx, AVFrame *dst, const AVFrame *src)
static int amf_device_derive(AVHWDeviceContext *device_ctx, AVHWDeviceContext *child_device_ctx, AVDictionary *opts, int flags)
AVHWFrameTransferDirection
This struct describes a set or pool of "hardware" frames (i.e.
#define AV_LOG_FATAL
Something went wrong and recovery is not possible.
enum AVHWDeviceType type
This field identifies the underlying API used for hardware access.
@ 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...
these buffered frames must be flushed immediately if a new input produces new the filter must not call request_frame to get more It must just process the frame or queue it The task of requesting more frames is left to the filter s request_frame method or the application If a filter has several the filter must be ready for frames arriving randomly on any input any filter with several inputs will most likely require some kind of queuing mechanism It is perfectly acceptable to have a limited queue and to drop frames when the inputs are too unbalanced request_frame For filters that do not use the this method is called when a frame is wanted on an output For a it should directly call filter_frame on the corresponding output For a if there are queued frames already one of these frames should be pushed If the filter should request a frame on one of its repeatedly until at least one frame has been pushed Return or at least make progress towards producing a frame
static enum AVPixelFormat supported_formats[]
static void amf_unlock_default(void *opaque)
void(* unlock)(void *lock_ctx)
static int amf_load_library(AVAMFDeviceContext *amf_ctx, void *avcl)
static void av_image_copy2(uint8_t *const dst_data[4], const int dst_linesizes[4], uint8_t *const src_data[4], const int src_linesizes[4], enum AVPixelFormat pix_fmt, int width, int height)
Wrapper around av_image_copy() to workaround the limitation that the conversion from uint8_t * const ...
const FormatMap format_map[]
A reference to a data buffer.
Structure to hold side data for an AVFrame.
static void AMF_CDECL_CALL AMFTraceWriter_Flush(AMFTraceWriter *pThis)
unsigned MaxFALL
Max average light level per frame (cd/m^2).
#define AV_PIX_FMT_RGBAF16
int av_amf_light_metadata_to_hdrmeta(const AVContentLightMetadata *light_meta, AMFHDRMetadata *hdrmeta)
@ AVCOL_SPC_BT709
also ITU-R BT1361 / IEC 61966-2-4 xvYCC709 / derived in SMPTE RP 177 Annex B
AVColorRange
Visual content value range.
static enum AVPixelFormat supported_transfer_formats[]
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.