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;
126 return AMF_SURFACE_UNKNOWN;
137 return AMF_SURFACE_UNKNOWN;
164 const void *hwconfig,
262 AMFSurface *surface = (AMFSurface*)(
data);
263 surface->pVtbl->Release(surface);
270 AMFSurface* surface = (AMFSurface*)
dst->data[0];
272 uint8_t *dst_data[4];
280 if (
dst->hw_frames_ctx->data != (uint8_t *)
ctx ||
src->format !=
ctx->sw_format)
287 res = amf_device_ctx->
context->pVtbl->AllocSurface(amf_device_ctx->
context, AMF_MEMORY_HOST,
format,
dst->width,
dst->height, &surface);
289 dst->data[0] = (uint8_t *)surface;
297 planes = (int)surface->pVtbl->GetPlanesCount(surface);
301 plane = surface->pVtbl->GetPlaneAt(surface,
i);
302 dst_data[
i] = plane->pVtbl->GetNative(plane);
303 dst_linesize[
i] = plane->pVtbl->GetHPitch(plane);
315 AMFSurface* surface = (AMFSurface*)
src->data[0];
317 uint8_t *src_data[4];
325 if (
src->hw_frames_ctx->data != (uint8_t *)
ctx ||
dst->format !=
ctx->sw_format)
328 ret = surface->pVtbl->Convert(surface, AMF_MEMORY_HOST);
331 planes = (int)surface->pVtbl->GetPlanesCount(surface);
335 plane = surface->pVtbl->GetPlaneAt(surface,
i);
336 src_data[
i] = plane->pVtbl->GetNative(plane);
337 src_linesize[
i] = plane->pVtbl->GetHPitch(plane);
340 src_data, src_linesize,
dst->format,
350 AMF_RESULT res = AMF_NOT_INITIALIZED;
360 res = amf_ctx->
factory->pVtbl->GetTrace(amf_ctx->
factory, &trace);
380 AMFContext1 *context1 =
NULL;
385 if (res == AMF_OK || res == AMF_ALREADY_INITIALIZED) {
393 AMFGuid guid = IID_AMFContext1();
394 res = amf_ctx->
context->pVtbl->QueryInterface(amf_ctx->
context, &guid, (
void**)&context1);
397 res = context1->pVtbl->InitVulkan(context1,
NULL);
398 context1->pVtbl->Release(context1);
399 if (res != AMF_OK && res != AMF_ALREADY_INITIALIZED) {
400 if (res == AMF_NOT_SUPPORTED)
417 AMFQueryVersion_Fn version_fun;
420 amf_ctx->
library = dlopen(AMF_DLL_NAMEA, RTLD_NOW | RTLD_LOCAL);
424 init_fun = (AMFInit_Fn)dlsym(amf_ctx->
library, AMF_INIT_FUNCTION_NAME);
427 version_fun = (AMFQueryVersion_Fn)dlsym(amf_ctx->
library, AMF_QUERY_VERSION_FUNCTION_NAME);
430 res = version_fun(&amf_ctx->
version);
432 res = init_fun(AMF_FULL_VERSION, &amf_ctx->
factory);
445 ret =
ctx->factory->pVtbl->GetTrace(
ctx->factory, &trace);
448 int level_amf = AMF_TRACE_TRACE;
449 amf_bool enable_log =
true;
453 level_amf = AMF_TRACE_ERROR;
459 level_amf = AMF_TRACE_ERROR;
463 level_amf = AMF_TRACE_WARNING;
466 level_amf = AMF_TRACE_INFO;
469 level_amf = AMF_TRACE_DEBUG;
472 level_amf = AMF_TRACE_TRACE;
475 if(
ctx->version == AMF_MAKE_FULL_VERSION(1, 4, 35, 0)){
476 level_amf = AMF_TRACE_WARNING;
479 trace->pVtbl->EnableWriter(trace, AMF_TRACE_WRITER_CONSOLE, 0);
480 trace->pVtbl->SetGlobalLevel(trace, level_amf);
487 trace->pVtbl->SetWriterLevel(trace, AMF_TRACE_WRITER_DEBUG_OUTPUT, level_amf);
488 trace->pVtbl->EnableWriter(trace, AMF_TRACE_WRITER_DEBUG_OUTPUT, enable_log);
492 ret =
ctx->factory->pVtbl->CreateContext(
ctx->factory, &
ctx->context);
504 IDirect3DDevice9 *device;
505 HANDLE device_handle;
510 hr = IDirect3DDeviceManager9_OpenDeviceHandle(hwctx->
devmgr, &device_handle);
512 av_log(hwctx,
AV_LOG_ERROR,
"Failed to open device handle for Direct3D9 device: %lx.\n", (
unsigned long)hr);
516 hr = IDirect3DDeviceManager9_LockDevice(hwctx->
devmgr, device_handle, &device, FALSE);
518 IDirect3DDeviceManager9_UnlockDevice(hwctx->
devmgr, device_handle, FALSE);
521 av_log(hwctx,
AV_LOG_ERROR,
"Failed to lock device handle for Direct3D9 device: %lx.\n", (
unsigned long)hr);
526 IDirect3DDeviceManager9_CloseDeviceHandle(hwctx->
devmgr, device_handle);
533 IDirect3DDevice9_Release(device);
535 if (res != AMF_OK && res != AMF_ALREADY_INITIALIZED) {
536 if (res == AMF_NOT_SUPPORTED)
539 av_log(hwctx,
AV_LOG_ERROR,
"AMF failed to initialise on given D3D9 device: %d.\n", res);
551 if (res != AMF_OK && res != AMF_ALREADY_INITIALIZED) {
552 if (res == AMF_NOT_SUPPORTED)
555 av_log(hwctx,
AV_LOG_ERROR,
"AMF failed to initialise on the given D3D11 device: %d.\n", res);
566 #if CONFIG_DXVA2 || CONFIG_D3D11VA
575 switch (child_device_ctx->
type) {
580 return amf_init_from_dxva2_device(amf_ctx, child_device_hwctx);
588 return amf_init_from_d3d11_device(amf_ctx, child_device_hwctx);
593 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.
static const struct @487 planes[]
@ 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.
#define AV_PIX_FMT_X2BGR10
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 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.