Go to the documentation of this file.
44 #include <AMF/core/Surface.h>
45 #include <AMF/core/Trace.h>
51 #define FFMPEG_AMF_WRITER_ID L"ffmpeg_amf"
70 const wchar_t *scope,
const wchar_t *
message)
89 writer->
avctx = avctx;
139 return AMF_SURFACE_UNKNOWN;
180 const void *hwconfig,
278 AMFSurface *surface = (AMFSurface*)(
data);
279 surface->pVtbl->Release(surface);
286 AMFSurface* surface = (AMFSurface*)
dst->data[0];
288 uint8_t *dst_data[4];
296 if (
dst->hw_frames_ctx->data != (uint8_t *)
ctx ||
src->format !=
ctx->sw_format)
303 res = amf_device_ctx->
context->pVtbl->AllocSurface(amf_device_ctx->
context, AMF_MEMORY_HOST,
format,
dst->width,
dst->height, &surface);
305 dst->data[0] = (uint8_t *)surface;
313 planes = (int)surface->pVtbl->GetPlanesCount(surface);
317 plane = surface->pVtbl->GetPlaneAt(surface,
i);
318 dst_data[
i] = plane->pVtbl->GetNative(plane);
319 dst_linesize[
i] = plane->pVtbl->GetHPitch(plane);
331 AMFSurface* surface = (AMFSurface*)
src->data[0];
333 uint8_t *src_data[4];
341 if (
src->hw_frames_ctx->data != (uint8_t *)
ctx ||
dst->format !=
ctx->sw_format)
344 ret = surface->pVtbl->Convert(surface, AMF_MEMORY_HOST);
347 planes = (int)surface->pVtbl->GetPlanesCount(surface);
351 plane = surface->pVtbl->GetPlaneAt(surface,
i);
352 src_data[
i] = plane->pVtbl->GetNative(plane);
353 src_linesize[
i] = plane->pVtbl->GetHPitch(plane);
356 src_data, src_linesize,
dst->format,
366 AMF_RESULT res = AMF_NOT_INITIALIZED;
376 res = amf_ctx->
factory->pVtbl->GetTrace(amf_ctx->
factory, &trace);
403 AMFContext1 *context1 =
NULL;
406 if (!amf_ctx->
lock) {
418 if (res == AMF_OK || res == AMF_ALREADY_INITIALIZED) {
426 AMFGuid guid = IID_AMFContext1();
427 res = amf_ctx->
context->pVtbl->QueryInterface(amf_ctx->
context, &guid, (
void**)&context1);
430 res = context1->pVtbl->InitVulkan(context1,
NULL);
431 context1->pVtbl->Release(context1);
432 if (res != AMF_OK && res != AMF_ALREADY_INITIALIZED) {
433 if (res == AMF_NOT_SUPPORTED)
451 AMFQueryVersion_Fn version_fun;
454 amf_ctx->
library = dlopen(AMF_DLL_NAMEA, RTLD_NOW | RTLD_LOCAL);
458 init_fun = (AMFInit_Fn)dlsym(amf_ctx->
library, AMF_INIT_FUNCTION_NAME);
461 version_fun = (AMFQueryVersion_Fn)dlsym(amf_ctx->
library, AMF_QUERY_VERSION_FUNCTION_NAME);
464 res = version_fun(&amf_ctx->
version);
466 res = init_fun(AMF_FULL_VERSION, &amf_ctx->
factory);
479 ret =
ctx->factory->pVtbl->GetTrace(
ctx->factory, &trace);
482 int level_amf = AMF_TRACE_TRACE;
483 amf_bool enable_log =
true;
487 level_amf = AMF_TRACE_ERROR;
493 level_amf = AMF_TRACE_ERROR;
497 level_amf = AMF_TRACE_WARNING;
500 level_amf = AMF_TRACE_INFO;
503 level_amf = AMF_TRACE_DEBUG;
506 level_amf = AMF_TRACE_TRACE;
509 if(
ctx->version == AMF_MAKE_FULL_VERSION(1, 4, 35, 0)){
510 level_amf = AMF_TRACE_WARNING;
513 trace->pVtbl->EnableWriter(trace, AMF_TRACE_WRITER_CONSOLE, 0);
514 trace->pVtbl->SetGlobalLevel(trace, level_amf);
521 trace->pVtbl->SetWriterLevel(trace, AMF_TRACE_WRITER_DEBUG_OUTPUT, level_amf);
522 trace->pVtbl->EnableWriter(trace, AMF_TRACE_WRITER_DEBUG_OUTPUT, enable_log);
526 ret =
ctx->factory->pVtbl->CreateContext(
ctx->factory, &
ctx->context);
528 AMF_ASSIGN_PROPERTY_INT64(
ret,
ctx->context,
L"DeviceSurfaceCacheSize", 50 );
541 IDirect3DDevice9 *device;
542 HANDLE device_handle;
547 hr = IDirect3DDeviceManager9_OpenDeviceHandle(hwctx->
devmgr, &device_handle);
549 av_log(child_device_ctx,
AV_LOG_ERROR,
"Failed to open device handle for Direct3D9 device: %lx.\n", (
unsigned long)hr);
553 hr = IDirect3DDeviceManager9_LockDevice(hwctx->
devmgr, device_handle, &device, FALSE);
555 IDirect3DDeviceManager9_UnlockDevice(hwctx->
devmgr, device_handle, FALSE);
558 av_log(child_device_ctx,
AV_LOG_ERROR,
"Failed to lock device handle for Direct3D9 device: %lx.\n", (
unsigned long)hr);
563 IDirect3DDeviceManager9_CloseDeviceHandle(hwctx->
devmgr, device_handle);
570 IDirect3DDevice9_Release(device);
572 if (res != AMF_OK && res != AMF_ALREADY_INITIALIZED) {
573 if (res == AMF_NOT_SUPPORTED)
574 av_log(child_device_ctx,
AV_LOG_ERROR,
"AMF via D3D9 is not supported on the given device.\n");
576 av_log(child_device_ctx,
AV_LOG_ERROR,
"AMF failed to initialise on given D3D9 device: %d.\n", res);
590 if (res != AMF_OK && res != AMF_ALREADY_INITIALIZED) {
591 if (res == AMF_NOT_SUPPORTED)
592 av_log(child_device_ctx,
AV_LOG_ERROR,
"AMF via D3D11 is not supported on the given device.\n");
594 av_log(child_device_ctx,
AV_LOG_ERROR,
"AMF failed to initialise on the given D3D11 device: %d.\n", res);
607 AMFContext2 *context2 =
NULL;
608 AMFGuid guid = IID_AMFContext2();
609 res = amf_ctx->
context->pVtbl->QueryInterface(amf_ctx->
context, &guid, (
void**)&context2);
611 res = context2->pVtbl->InitDX12(context2, hwctx->
device, AMF_DX12);
612 context2->pVtbl->Release(context2);
613 if (res != AMF_OK && res != AMF_ALREADY_INITIALIZED) {
614 if (res == AMF_NOT_SUPPORTED)
615 av_log(child_device_ctx,
AV_LOG_ERROR,
"AMF via D3D12 is not supported on the given device.\n");
617 av_log(child_device_ctx,
AV_LOG_ERROR,
"AMF failed to initialise on the given D3D12 device: %d.\n", res);
630 #if CONFIG_DXVA2 || CONFIG_D3D11VA
639 switch (child_device_ctx->
type) {
643 return amf_init_from_dxva2_device(amf_ctx, child_device_ctx);
650 return amf_init_from_d3d11_device(amf_ctx, child_device_ctx);
656 return amf_init_from_d3d12_device(amf_ctx, child_device_ctx);
661 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
#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 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.
@ 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...
static int ff_mutex_unlock(AVMutex *mutex)
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.
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
This struct is allocated as AVHWDeviceContext.hwctx.
static void amf_lock_default(void *opaque)
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.
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...
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 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.
static void AMF_CDECL_CALL AMFTraceWriter_Flush(AMFTraceWriter *pThis)
#define AV_PIX_FMT_RGBAF16
static const struct @544 planes[]
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.