Go to the documentation of this file.
   43 #include <AMF/core/Surface.h> 
   44 #include <AMF/core/Trace.h> 
   50 #define FFMPEG_AMF_WRITER_ID L"ffmpeg_amf" 
   60     const wchar_t *scope, 
const wchar_t *
message)
 
   79     writer->
avctx = avctx;
 
  129     return AMF_SURFACE_UNKNOWN;
 
  140     return AMF_SURFACE_UNKNOWN;
 
  170                                        const void *hwconfig,
 
  268         AMFSurface *surface = (AMFSurface*)(
data);
 
  269         surface->pVtbl->Release(surface);
 
  276     AMFSurface* surface = (AMFSurface*)
dst->data[0];
 
  278     uint8_t  *dst_data[4];
 
  286     if (
dst->hw_frames_ctx->data != (uint8_t *)
ctx || 
src->format != 
ctx->sw_format)
 
  293         res = amf_device_ctx->
context->pVtbl->AllocSurface(amf_device_ctx->
context, AMF_MEMORY_HOST, 
format, 
dst->width, 
dst->height, &surface);
 
  295         dst->data[0] = (uint8_t *)surface;
 
  303     planes = (int)surface->pVtbl->GetPlanesCount(surface);
 
  307         plane = surface->pVtbl->GetPlaneAt(surface, 
i);
 
  308         dst_data[
i] = plane->pVtbl->GetNative(plane);
 
  309         dst_linesize[
i] = plane->pVtbl->GetHPitch(plane);
 
  321     AMFSurface* surface = (AMFSurface*)
src->data[0];
 
  323     uint8_t  *src_data[4];
 
  331     if (
src->hw_frames_ctx->data != (uint8_t *)
ctx || 
dst->format != 
ctx->sw_format)
 
  334     ret = surface->pVtbl->Convert(surface, AMF_MEMORY_HOST);
 
  337     planes = (int)surface->pVtbl->GetPlanesCount(surface);
 
  341         plane = surface->pVtbl->GetPlaneAt(surface, 
i);
 
  342         src_data[
i] = plane->pVtbl->GetNative(plane);
 
  343         src_linesize[
i] = plane->pVtbl->GetHPitch(plane);
 
  346                    src_data, src_linesize, 
dst->format,
 
  356     AMF_RESULT          res = AMF_NOT_INITIALIZED;
 
  366         res = amf_ctx->
factory->pVtbl->GetTrace(amf_ctx->
factory, &trace);
 
  386     AMFContext1 *context1 = 
NULL;
 
  391     if (res == AMF_OK || res == AMF_ALREADY_INITIALIZED) {
 
  399             AMFGuid guid = IID_AMFContext1();
 
  400             res = amf_ctx->
context->pVtbl->QueryInterface(amf_ctx->
context, &guid, (
void**)&context1);
 
  403             res = context1->pVtbl->InitVulkan(context1, 
NULL);
 
  404             context1->pVtbl->Release(context1);
 
  405             if (res != AMF_OK && res != AMF_ALREADY_INITIALIZED) {
 
  406                 if (res == AMF_NOT_SUPPORTED)
 
  423     AMFQueryVersion_Fn version_fun;
 
  426     amf_ctx->
library = dlopen(AMF_DLL_NAMEA, RTLD_NOW | RTLD_LOCAL);
 
  430     init_fun = (AMFInit_Fn)dlsym(amf_ctx->
library, AMF_INIT_FUNCTION_NAME);
 
  433     version_fun = (AMFQueryVersion_Fn)dlsym(amf_ctx->
library, AMF_QUERY_VERSION_FUNCTION_NAME);
 
  436     res = version_fun(&amf_ctx->
version);
 
  438     res = init_fun(AMF_FULL_VERSION, &amf_ctx->
factory);
 
  451         ret = 
ctx->factory->pVtbl->GetTrace(
ctx->factory, &trace);
 
  454             int level_amf = AMF_TRACE_TRACE;
 
  455             amf_bool enable_log = 
true;
 
  459                 level_amf = AMF_TRACE_ERROR;
 
  465                 level_amf = AMF_TRACE_ERROR;
 
  469                 level_amf = AMF_TRACE_WARNING;
 
  472                 level_amf = AMF_TRACE_INFO;
 
  475                 level_amf = AMF_TRACE_DEBUG;
 
  478                 level_amf = AMF_TRACE_TRACE;
 
  481             if(
ctx->version == AMF_MAKE_FULL_VERSION(1, 4, 35, 0)){
 
  482                 level_amf = AMF_TRACE_WARNING;
 
  485             trace->pVtbl->EnableWriter(trace, AMF_TRACE_WRITER_CONSOLE, 0);
 
  486             trace->pVtbl->SetGlobalLevel(trace, level_amf);
 
  493             trace->pVtbl->SetWriterLevel(trace, AMF_TRACE_WRITER_DEBUG_OUTPUT, level_amf);
 
  494             trace->pVtbl->EnableWriter(trace, AMF_TRACE_WRITER_DEBUG_OUTPUT, enable_log);
 
  498         ret = 
ctx->factory->pVtbl->CreateContext(
ctx->factory, &
ctx->context);
 
  500             AMF_ASSIGN_PROPERTY_INT64(
ret, 
ctx->context, 
L"DeviceSurfaceCacheSize", 50 );
 
  513     IDirect3DDevice9    *device;
 
  514     HANDLE              device_handle;
 
  519     hr = IDirect3DDeviceManager9_OpenDeviceHandle(hwctx->
devmgr, &device_handle);
 
  521         av_log(child_device_ctx, 
AV_LOG_ERROR, 
"Failed to open device handle for Direct3D9 device: %lx.\n", (
unsigned long)hr);
 
  525     hr = IDirect3DDeviceManager9_LockDevice(hwctx->
devmgr, device_handle, &device, FALSE);
 
  527         IDirect3DDeviceManager9_UnlockDevice(hwctx->
devmgr, device_handle, FALSE);
 
  530         av_log(child_device_ctx, 
AV_LOG_ERROR, 
"Failed to lock device handle for Direct3D9 device: %lx.\n", (
unsigned long)hr);
 
  535     IDirect3DDeviceManager9_CloseDeviceHandle(hwctx->
devmgr, device_handle);
 
  542     IDirect3DDevice9_Release(device);
 
  544     if (res != AMF_OK && res != AMF_ALREADY_INITIALIZED) {
 
  545         if (res == AMF_NOT_SUPPORTED)
 
  546             av_log(child_device_ctx, 
AV_LOG_ERROR, 
"AMF via D3D9 is not supported on the given device.\n");
 
  548             av_log(child_device_ctx, 
AV_LOG_ERROR, 
"AMF failed to initialise on given D3D9 device: %d.\n", res);
 
  562     if (res != AMF_OK && res != AMF_ALREADY_INITIALIZED) {
 
  563         if (res == AMF_NOT_SUPPORTED)
 
  564             av_log(child_device_ctx, 
AV_LOG_ERROR, 
"AMF via D3D11 is not supported on the given device.\n");
 
  566             av_log(child_device_ctx, 
AV_LOG_ERROR, 
"AMF failed to initialise on the given D3D11 device: %d.\n", res);
 
  579     AMFContext2 *context2 = 
NULL;
 
  580     AMFGuid guid = IID_AMFContext2();
 
  581     res = amf_ctx->
context->pVtbl->QueryInterface(amf_ctx->
context, &guid, (
void**)&context2);
 
  583     res = context2->pVtbl->InitDX12(context2, hwctx->
device, AMF_DX12);
 
  584     context2->pVtbl->Release(context2);
 
  585     if (res != AMF_OK && res != AMF_ALREADY_INITIALIZED) {
 
  586         if (res == AMF_NOT_SUPPORTED)
 
  587             av_log(child_device_ctx, 
AV_LOG_ERROR, 
"AMF via D3D12 is not supported on the given device.\n");
 
  589             av_log(child_device_ctx, 
AV_LOG_ERROR, 
"AMF failed to initialise on the given D3D12 device: %d.\n", res);
 
  602 #if CONFIG_DXVA2 || CONFIG_D3D11VA 
  611     switch (child_device_ctx->
type) {
 
  615             return amf_init_from_dxva2_device(amf_ctx, child_device_ctx);
 
  622             return amf_init_from_d3d11_device(amf_ctx, child_device_ctx);
 
  628             return amf_init_from_d3d12_device(amf_ctx, child_device_ctx);
 
  633             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.
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
#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)
This structure describes decoded (raw) audio or video data.
static const struct @540 planes[]
static void amf_dummy_free(void *opaque, uint8_t *data)
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.
@ AV_PIX_FMT_AMF_SURFACE
HW acceleration through AMF.
This struct describes the constraints on hardware frames attached to a given device with a hardware-s...
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 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.
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)
#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 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_PIX_FMT_BGR0
packed BGR 8:8:8, 32bpp, BGRXBGRX... X=unused/undefined
@ AV_PIX_FMT_D3D12
Hardware surfaces for Direct3D 12.
@ 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.
#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
This struct is allocated as AVHWDeviceContext.hwctx.
const HWContextType ff_hwcontext_type_amf
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.
@ 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...
This struct is allocated as AVHWDeviceContext.hwctx.
#define i(width, name, range_min, range_max)
This struct is allocated as AVHWDeviceContext.hwctx.
#define av_malloc_array(a, b)
This struct is allocated as AVHWDeviceContext.hwctx.
static int amf_transfer_data_from(AVHWFramesContext *ctx, AVFrame *dst, const AVFrame *src)
void * av_mallocz(size_t size)
Allocate a memory block with alignment suitable for all memory accesses (including vectors if availab...
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 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.
static void AMF_CDECL_CALL AMFTraceWriter_Flush(AMFTraceWriter *pThis)
#define AV_PIX_FMT_RGBAF16
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.