Go to the documentation of this file.
40 #include <AMF/core/Surface.h>
41 #include <AMF/core/Trace.h>
47 #define FFMPEG_AMF_WRITER_ID L"ffmpeg_amf"
57 const wchar_t *scope,
const wchar_t *
message)
76 writer->
avctx = avctx;
124 return AMF_SURFACE_UNKNOWN;
135 return AMF_SURFACE_UNKNOWN;
162 const void *hwconfig,
260 AMFSurface *surface = (AMFSurface*)(
data);
261 surface->pVtbl->Release(surface);
268 AMFSurface* surface = (AMFSurface*)
dst->data[0];
270 uint8_t *dst_data[4];
282 res = amf_device_ctx->
context->pVtbl->AllocSurface(amf_device_ctx->
context, AMF_MEMORY_HOST,
format,
dst->width,
dst->height, &surface);
284 dst->data[0] = (uint8_t *)surface;
292 planes = (int)surface->pVtbl->GetPlanesCount(surface);
296 plane = surface->pVtbl->GetPlaneAt(surface,
i);
297 dst_data[
i] = plane->pVtbl->GetNative(plane);
298 dst_linesize[
i] = plane->pVtbl->GetHPitch(plane);
310 AMFSurface* surface = (AMFSurface*)
src->data[0];
312 uint8_t *src_data[4];
320 ret = surface->pVtbl->Convert(surface, AMF_MEMORY_HOST);
323 planes = (int)surface->pVtbl->GetPlanesCount(surface);
327 plane = surface->pVtbl->GetPlaneAt(surface,
i);
328 src_data[
i] = plane->pVtbl->GetNative(plane);
329 src_linesize[
i] = plane->pVtbl->GetHPitch(plane);
332 src_data, src_linesize,
dst->format,
351 res = amf_ctx->
factory->pVtbl->GetTrace(amf_ctx->
factory, &trace);
370 AMFContext1 *context1 =
NULL;
375 if (res == AMF_OK || res == AMF_ALREADY_INITIALIZED) {
383 AMFGuid guid = IID_AMFContext1();
384 res = amf_ctx->
context->pVtbl->QueryInterface(amf_ctx->
context, &guid, (
void**)&context1);
387 res = context1->pVtbl->InitVulkan(context1,
NULL);
388 context1->pVtbl->Release(context1);
389 if (res != AMF_OK && res != AMF_ALREADY_INITIALIZED) {
390 if (res == AMF_NOT_SUPPORTED)
407 AMFQueryVersion_Fn version_fun;
410 amf_ctx->
library = dlopen(AMF_DLL_NAMEA, RTLD_NOW | RTLD_LOCAL);
414 init_fun = (AMFInit_Fn)dlsym(amf_ctx->
library, AMF_INIT_FUNCTION_NAME);
417 version_fun = (AMFQueryVersion_Fn)dlsym(amf_ctx->
library, AMF_QUERY_VERSION_FUNCTION_NAME);
420 res = version_fun(&amf_ctx->
version);
422 res = init_fun(AMF_FULL_VERSION, &amf_ctx->
factory);
435 ret =
ctx->factory->pVtbl->GetTrace(
ctx->factory, &trace);
438 int level_amf = AMF_TRACE_TRACE;
439 amf_bool enable_log =
true;
443 level_amf = AMF_TRACE_ERROR;
449 level_amf = AMF_TRACE_ERROR;
453 level_amf = AMF_TRACE_WARNING;
456 level_amf = AMF_TRACE_INFO;
459 level_amf = AMF_TRACE_DEBUG;
462 level_amf = AMF_TRACE_TRACE;
465 if(
ctx->version == AMF_MAKE_FULL_VERSION(1, 4, 35, 0)){
466 level_amf = AMF_TRACE_WARNING;
469 trace->pVtbl->EnableWriter(trace, AMF_TRACE_WRITER_CONSOLE, 0);
470 trace->pVtbl->SetGlobalLevel(trace, level_amf);
477 trace->pVtbl->SetWriterLevel(trace, AMF_TRACE_WRITER_DEBUG_OUTPUT, level_amf);
478 trace->pVtbl->EnableWriter(trace, AMF_TRACE_WRITER_DEBUG_OUTPUT, enable_log);
482 ret =
ctx->factory->pVtbl->CreateContext(
ctx->factory, &
ctx->context);
494 IDirect3DDevice9 *device;
495 HANDLE device_handle;
500 hr = IDirect3DDeviceManager9_OpenDeviceHandle(hwctx->
devmgr, &device_handle);
502 av_log(hwctx,
AV_LOG_ERROR,
"Failed to open device handle for Direct3D9 device: %lx.\n", (
unsigned long)hr);
506 hr = IDirect3DDeviceManager9_LockDevice(hwctx->
devmgr, device_handle, &device, FALSE);
508 IDirect3DDeviceManager9_UnlockDevice(hwctx->
devmgr, device_handle, FALSE);
511 av_log(hwctx,
AV_LOG_ERROR,
"Failed to lock device handle for Direct3D9 device: %lx.\n", (
unsigned long)hr);
516 IDirect3DDeviceManager9_CloseDeviceHandle(hwctx->
devmgr, device_handle);
523 IDirect3DDevice9_Release(device);
525 if (res != AMF_OK && res != AMF_ALREADY_INITIALIZED) {
526 if (res == AMF_NOT_SUPPORTED)
529 av_log(hwctx,
AV_LOG_ERROR,
"AMF failed to initialise on given D3D9 device: %d.\n", res);
541 if (res != AMF_OK && res != AMF_ALREADY_INITIALIZED) {
542 if (res == AMF_NOT_SUPPORTED)
545 av_log(hwctx,
AV_LOG_ERROR,
"AMF failed to initialise on the given D3D11 device: %d.\n", res);
556 #if CONFIG_DXVA2 || CONFIG_D3D11VA
565 switch (child_device_ctx->
type) {
570 return amf_init_from_dxva2_device(amf_ctx, child_device_hwctx);
578 return amf_init_from_d3d11_device(amf_ctx, child_device_hwctx);
583 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
#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 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.
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 format(the sample packing is implied by the sample format) and sample rate. The lists are not just lists
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)
@ 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_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 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...
#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 const struct @473 planes[]
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 flags(name, subs,...)
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.