FFmpeg
Loading...
Searching...
No Matches
hwcontext_amf.c
Go to the documentation of this file.
1/*
2 * This file is part of FFmpeg.
3 *
4 * FFmpeg is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Lesser General Public
6 * License as published by the Free Software Foundation; either
7 * version 2.1 of the License, or (at your option) any later version.
8 *
9 * FFmpeg is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * Lesser General Public License for more details.
13 *
14 * You should have received a copy of the GNU Lesser General Public
15 * License along with FFmpeg; if not, write to the Free Software
16 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
17 */
18
19#include "mem.h"
20#include "buffer.h"
21#include "pixfmt.h"
22#include "pixdesc.h"
23#include "imgutils.h"
24#include "hwcontext.h"
25#include "hwcontext_amf.h"
26#include "hwcontext_internal.h"
28
29#include "libavutil/thread.h"
30#include "libavutil/avassert.h"
31
32#include <AMF/core/Surface.h>
33#include <AMF/core/Trace.h>
34
35#if CONFIG_VULKAN
36#include "hwcontext_vulkan.h"
37#endif
38#if CONFIG_D3D11VA
40#endif
41#if CONFIG_D3D12VA
43#endif
44#if CONFIG_DXVA2
45#define COBJMACROS
47#endif
48#ifdef _WIN32
49#include "compat/w32dlfcn.h"
50#else
51#include <dlfcn.h>
52#endif
53#define FFMPEG_AMF_WRITER_ID L"ffmpeg_amf"
54
55static void amf_lock_default(void *opaque)
56{
57 ff_mutex_lock((AVMutex*)opaque);
58}
59
60static void amf_unlock_default(void *opaque)
61{
62 ff_mutex_unlock((AVMutex*)opaque);
63}
64
65typedef struct AmfTraceWriter {
66 AMFTraceWriterVtbl *vtblp;
67 void *avctx;
68 AMFTraceWriterVtbl vtbl;
70
71static void AMF_CDECL_CALL AMFTraceWriter_Write(AMFTraceWriter *pThis,
72 const wchar_t *scope, const wchar_t *message)
73{
74 AmfTraceWriter *tracer = (AmfTraceWriter*)pThis;
75 av_log(tracer->avctx, AV_LOG_DEBUG, "%ls: %ls", scope, message); // \n is provided from AMF
76}
77
78static void AMF_CDECL_CALL AMFTraceWriter_Flush(AMFTraceWriter *pThis)
79{
80}
81
82static AmfTraceWriter * amf_writer_alloc(void *avctx)
83{
84 AmfTraceWriter * writer = av_mallocz(sizeof(AmfTraceWriter));
85 if (!writer)
86 return NULL;
87
88 writer->vtblp = &writer->vtbl;
89 writer->vtblp->Write = AMFTraceWriter_Write;
90 writer->vtblp->Flush = AMFTraceWriter_Flush;
91 writer->avctx = avctx;
92
93 return writer;
94}
95
96static void amf_writer_free(void *opaque)
97{
98 AmfTraceWriter *writer = (AmfTraceWriter *)opaque;
99 av_freep(&writer);
100}
101
102/**
103 * We still need AVHWFramesContext to utilize our hardware memory
104 * otherwise, we will receive the error "HW format requires hw_frames_ctx to be non-NULL".
105 * (libavfilter\buffersrc.c function query_formats)
106*/
107typedef struct {
108 void *dummy;
110
111typedef struct AVAMFFormatMap {
113 enum AMF_SURFACE_FORMAT amf_format;
114} FormatMap;
115
117{
118 { AV_PIX_FMT_NONE, AMF_SURFACE_UNKNOWN },
119 { AV_PIX_FMT_NV12, AMF_SURFACE_NV12 },
120 { AV_PIX_FMT_BGR0, AMF_SURFACE_BGRA },
121 { AV_PIX_FMT_RGB0, AMF_SURFACE_RGBA },
122 { AV_PIX_FMT_BGRA, AMF_SURFACE_BGRA },
123 { AV_PIX_FMT_ARGB, AMF_SURFACE_ARGB },
124 { AV_PIX_FMT_RGBA, AMF_SURFACE_RGBA },
125 { AV_PIX_FMT_GRAY8, AMF_SURFACE_GRAY8 },
126 { AV_PIX_FMT_YUV420P, AMF_SURFACE_YUV420P },
127 { AV_PIX_FMT_YUYV422, AMF_SURFACE_YUY2 },
128 { AV_PIX_FMT_P010, AMF_SURFACE_P010 },
129 { AV_PIX_FMT_X2BGR10, AMF_SURFACE_R10G10B10A2 },
130 { AV_PIX_FMT_RGBAF16, AMF_SURFACE_RGBA_F16},
131};
132
133enum AMF_SURFACE_FORMAT av_av_to_amf_format(enum AVPixelFormat fmt)
134{
135 int i;
136 for (i = 0; i < amf_countof(format_map); i++) {
137 if (format_map[i].av_format == fmt) {
138 return format_map[i].amf_format;
139 }
140 }
141 return AMF_SURFACE_UNKNOWN;
142}
143
144enum AVPixelFormat av_amf_to_av_format(enum AMF_SURFACE_FORMAT fmt)
145{
146 int i;
147 for (i = 0; i < amf_countof(format_map); i++) {
148 if (format_map[i].amf_format == fmt) {
149 return format_map[i].av_format;
150 }
151 }
152 return AV_PIX_FMT_NONE;
153}
154
155enum AMF_VIDEO_CONVERTER_COLOR_PROFILE_ENUM av_amf_get_color_profile(enum AVColorRange color_range, enum AVColorSpace color_space)
156{
157 switch (color_space) {
160 return AMF_VIDEO_CONVERTER_COLOR_PROFILE_FULL_601;
161 } else {
162 return AMF_VIDEO_CONVERTER_COLOR_PROFILE_601;
163 }
164 break;
165 case AVCOL_SPC_BT709:
167 return AMF_VIDEO_CONVERTER_COLOR_PROFILE_FULL_709;
168 } else {
169 return AMF_VIDEO_CONVERTER_COLOR_PROFILE_709;
170 }
171 break;
175 return AMF_VIDEO_CONVERTER_COLOR_PROFILE_FULL_2020;
176 } else {
177 return AMF_VIDEO_CONVERTER_COLOR_PROFILE_2020;
178 }
179 break;
180
181 default:
182 return AMF_VIDEO_CONVERTER_COLOR_PROFILE_UNKNOWN;
183 }
184}
185
186int av_amf_display_mastering_meta_to_hdrmeta(const AVMasteringDisplayMetadata *display_meta, AMFHDRMetadata *hdrmeta)
187{
188 if (!display_meta || !hdrmeta)
189 return AVERROR(EINVAL);
190
191 if (display_meta->has_luminance) {
192 const unsigned int luma_den = 10000;
193 hdrmeta->maxMasteringLuminance =
194 (amf_uint32)(luma_den * av_q2d(display_meta->max_luminance));
195 hdrmeta->minMasteringLuminance =
196 FFMIN((amf_uint32)(luma_den * av_q2d(display_meta->min_luminance)), hdrmeta->maxMasteringLuminance);
197 }
198
199 if (display_meta->has_primaries) {
200 const unsigned int chroma_den = 50000;
201 hdrmeta->redPrimary[0] =
202 FFMIN((amf_uint16)(chroma_den * av_q2d(display_meta->display_primaries[0][0])), chroma_den);
203 hdrmeta->redPrimary[1] =
204 FFMIN((amf_uint16)(chroma_den * av_q2d(display_meta->display_primaries[0][1])), chroma_den);
205 hdrmeta->greenPrimary[0] =
206 FFMIN((amf_uint16)(chroma_den * av_q2d(display_meta->display_primaries[1][0])), chroma_den);
207 hdrmeta->greenPrimary[1] =
208 FFMIN((amf_uint16)(chroma_den * av_q2d(display_meta->display_primaries[1][1])), chroma_den);
209 hdrmeta->bluePrimary[0] =
210 FFMIN((amf_uint16)(chroma_den * av_q2d(display_meta->display_primaries[2][0])), chroma_den);
211 hdrmeta->bluePrimary[1] =
212 FFMIN((amf_uint16)(chroma_den * av_q2d(display_meta->display_primaries[2][1])), chroma_den);
213 hdrmeta->whitePoint[0] =
214 FFMIN((amf_uint16)(chroma_den * av_q2d(display_meta->white_point[0])), chroma_den);
215 hdrmeta->whitePoint[1] =
216 FFMIN((amf_uint16)(chroma_den * av_q2d(display_meta->white_point[1])), chroma_den);
217 }
218
219 return 0;
220}
221
222int av_amf_light_metadata_to_hdrmeta(const AVContentLightMetadata *light_meta, AMFHDRMetadata *hdrmeta)
223{
224 if (!light_meta || !hdrmeta)
225 return AVERROR(EINVAL);
226
227 hdrmeta->maxContentLightLevel = (amf_uint16)light_meta->MaxCLL;
228 hdrmeta->maxFrameAverageLightLevel = (amf_uint16)light_meta->MaxFALL;
229
230 return 0;
231}
232
233int av_amf_extract_hdr_metadata(const AVFrame *frame, AMFHDRMetadata *hdrmeta)
234{
235 AVFrameSideData *sidedata;
236 AVContentLightMetadata *content_light = NULL;
237 AVMasteringDisplayMetadata *mastering_display = NULL;
238
239 if (!frame || !hdrmeta)
240 return AVERROR(EINVAL);
241
243 if (sidedata) {
244 mastering_display = (AVMasteringDisplayMetadata *)sidedata->data;
245 if (av_amf_display_mastering_meta_to_hdrmeta(mastering_display, hdrmeta) != 0)
246 mastering_display = NULL;
247 }
248
250 if (sidedata) {
251 content_light = (AVContentLightMetadata *)sidedata->data;
252 if (av_amf_light_metadata_to_hdrmeta(content_light, hdrmeta) != 0)
253 content_light = NULL;
254 }
255
256 if (!mastering_display && !content_light)
257 return AVERROR(ENODATA);
258
259 return 0;
260}
261
262int av_amf_attach_hdr_metadata(AVFrame *frame, const AMFHDRMetadata *hdrmeta) {
263 if (!hdrmeta || !frame)
264 return AVERROR(EINVAL);
265
266 AVMasteringDisplayMetadata *mastering =
268 const int chroma_den = 50000;
269 const int luma_den = 10000;
270
271 if (!mastering)
272 return AVERROR(ENOMEM);
273
274 mastering->display_primaries[0][0] =
275 av_make_q(hdrmeta->redPrimary[0], chroma_den);
276 mastering->display_primaries[0][1] =
277 av_make_q(hdrmeta->redPrimary[1], chroma_den);
278
279 mastering->display_primaries[1][0] =
280 av_make_q(hdrmeta->greenPrimary[0], chroma_den);
281 mastering->display_primaries[1][1] =
282 av_make_q(hdrmeta->greenPrimary[1], chroma_den);
283
284 mastering->display_primaries[2][0] =
285 av_make_q(hdrmeta->bluePrimary[0], chroma_den);
286 mastering->display_primaries[2][1] =
287 av_make_q(hdrmeta->bluePrimary[1], chroma_den);
288
289 mastering->white_point[0] = av_make_q(hdrmeta->whitePoint[0], chroma_den);
290 mastering->white_point[1] = av_make_q(hdrmeta->whitePoint[1], chroma_den);
291
292 mastering->max_luminance =
293 av_make_q(hdrmeta->maxMasteringLuminance, luma_den);
294 mastering->min_luminance =
295 av_make_q(hdrmeta->maxMasteringLuminance, luma_den);
296
297 mastering->has_luminance = 1;
298 mastering->has_primaries = 1;
299 if (hdrmeta->maxContentLightLevel) {
302
303 if (!light)
304 return AVERROR(ENOMEM);
305
306 light->MaxCLL = hdrmeta->maxContentLightLevel;
307 light->MaxFALL = hdrmeta->maxFrameAverageLightLevel;
308 }
309
310 return 0;
311}
312
313static const enum AVPixelFormat supported_formats[] = {
322#if CONFIG_D3D11VA
324#endif
325#if CONFIG_D3D12VA
327#endif
328#if CONFIG_DXVA2
330#endif
331};
332
343
345 const void *hwconfig,
346 AVHWFramesConstraints *constraints)
347{
348 int i;
349
351 sizeof(*constraints->valid_sw_formats));
352 if (!constraints->valid_sw_formats)
353 return AVERROR(ENOMEM);
354
355 for (i = 0; i < FF_ARRAY_ELEMS(supported_formats); i++)
356 constraints->valid_sw_formats[i] = supported_formats[i];
358
359 constraints->valid_hw_formats = av_malloc_array(2, sizeof(*constraints->valid_hw_formats));
360 if (!constraints->valid_hw_formats)
361 return AVERROR(ENOMEM);
362
364 constraints->valid_hw_formats[1] = AV_PIX_FMT_NONE;
365
366 return 0;
367}
368
369static void amf_dummy_free(void *opaque, uint8_t *data)
370{
371
372}
373
374static AVBufferRef *amf_pool_alloc(void *opaque, size_t size)
375{
376 AVHWFramesContext *hwfc = (AVHWFramesContext *)opaque;
377 AVBufferRef *buf;
378
380 if (!buf) {
381 av_log(hwfc, AV_LOG_ERROR, "Failed to create buffer for AMF context.\n");
382 return NULL;
383 }
384 return buf;
385}
386
388{
389 int i;
390
391 for (i = 0; i < FF_ARRAY_ELEMS(supported_formats); i++) {
392 if (ctx->sw_format == supported_formats[i])
393 break;
394 }
396 av_log(ctx, AV_LOG_ERROR, "Pixel format '%s' is not supported\n",
397 av_get_pix_fmt_name(ctx->sw_format));
398 return AVERROR(ENOSYS);
399 }
400
402 av_buffer_pool_init2(sizeof(AMFSurface), ctx,
404
405 return 0;
406}
407
408
410{
411 frame->buf[0] = av_buffer_pool_get(ctx->pool);
412 if (!frame->buf[0])
413 return AVERROR(ENOMEM);
414
415 frame->data[0] = frame->buf[0]->data;
417 frame->width = ctx->width;
418 frame->height = ctx->height;
419 return 0;
420}
421
424 enum AVPixelFormat **formats)
425{
426 enum AVPixelFormat *fmts;
427 int i;
428
430 if (!fmts)
431 return AVERROR(ENOMEM);
434
435 *formats = fmts;
436
437 return 0;
438}
439
440static void amf_free_amfsurface(void *opaque, uint8_t *data)
441{
442 if(!!data){
443 AMFSurface *surface = (AMFSurface*)(data);
444 surface->pVtbl->Release(surface);
445 }
446}
447
449 const AVFrame *src)
450{
451 AMFSurface* surface = (AMFSurface*)dst->data[0];
452 AMFPlane *plane;
453 uint8_t *dst_data[4];
454 int dst_linesize[4];
455 int planes;
456 int i;
457 int res;
458 int w = FFMIN(dst->width, src->width);
459 int h = FFMIN(dst->height, src->height);
460
461 if (dst->hw_frames_ctx->data != (uint8_t *)ctx || src->format != ctx->sw_format)
462 return AVERROR(EINVAL);
463
464 if (!surface) {
465 AVHWDeviceContext *hwdev_ctx = ctx->device_ctx;
466 AVAMFDeviceContext *amf_device_ctx = (AVAMFDeviceContext *)hwdev_ctx->hwctx;
467 AMF_SURFACE_FORMAT format = av_av_to_amf_format(ctx->sw_format);
468 res = amf_device_ctx->context->pVtbl->AllocSurface(amf_device_ctx->context, AMF_MEMORY_HOST, format, dst->width, dst->height, &surface);
469 AMF_RETURN_IF_FALSE(ctx, res == AMF_OK, AVERROR(ENOMEM), "AllocSurface() failed with error %d\n", res);
470 dst->data[0] = (uint8_t *)surface;
471 dst->buf[1] = av_buffer_create((uint8_t *)surface, sizeof(surface),
473 NULL,
475 AMF_RETURN_IF_FALSE(ctx, !!dst->buf[1], AVERROR(ENOMEM), "av_buffer_create for amf surface failed.");
476 }
477
478 planes = (int)surface->pVtbl->GetPlanesCount(surface);
479 av_assert0(planes < FF_ARRAY_ELEMS(dst_data));
480
481 for (i = 0; i < planes; i++) {
482 plane = surface->pVtbl->GetPlaneAt(surface, i);
483 dst_data[i] = plane->pVtbl->GetNative(plane);
484 dst_linesize[i] = plane->pVtbl->GetHPitch(plane);
485 }
486 av_image_copy2(dst_data, dst_linesize,
487 src->data, src->linesize, src->format,
488 w, h);
489
490 return 0;
491}
492
494 const AVFrame *src)
495{
496 AMFSurface* surface = (AMFSurface*)src->data[0];
497 AMFPlane *plane;
498 uint8_t *src_data[4];
499 int src_linesize[4];
500 int planes;
501 int i;
502 int w = FFMIN(dst->width, src->width);
503 int h = FFMIN(dst->height, src->height);
504 int ret;
505
506 if (src->hw_frames_ctx->data != (uint8_t *)ctx || dst->format != ctx->sw_format)
507 return AVERROR(EINVAL);
508
509 ret = surface->pVtbl->Convert(surface, AMF_MEMORY_HOST);
510 AMF_RETURN_IF_FALSE(ctx, ret == AMF_OK, AVERROR_UNKNOWN, "Convert(amf::AMF_MEMORY_HOST) failed with error %d\n", AVERROR_UNKNOWN);
511
512 planes = (int)surface->pVtbl->GetPlanesCount(surface);
513 av_assert0(planes < FF_ARRAY_ELEMS(src_data));
514
515 for (i = 0; i < planes; i++) {
516 plane = surface->pVtbl->GetPlaneAt(surface, i);
517 src_data[i] = plane->pVtbl->GetNative(plane);
518 src_linesize[i] = plane->pVtbl->GetHPitch(plane);
519 }
520 av_image_copy2(dst->data, dst->linesize,
521 src_data, src_linesize, dst->format,
522 w, h);
523 return 0;
524}
525
526
527
528static void amf_device_uninit(AVHWDeviceContext *device_ctx)
529{
530 AVAMFDeviceContext *amf_ctx = device_ctx->hwctx;
531 AMF_RESULT res = AMF_NOT_INITIALIZED;
532 AMFTrace *trace;
533
534 if (amf_ctx->context) {
535 amf_ctx->context->pVtbl->Terminate(amf_ctx->context);
536 amf_ctx->context->pVtbl->Release(amf_ctx->context);
537 amf_ctx->context = NULL;
538 }
539
540 if (amf_ctx->factory)
541 res = amf_ctx->factory->pVtbl->GetTrace(amf_ctx->factory, &trace);
542
543 if (res == AMF_OK) {
544 trace->pVtbl->UnregisterWriter(trace, FFMPEG_AMF_WRITER_ID);
545 }
546
547 if(amf_ctx->library) {
548 dlclose(amf_ctx->library);
549 amf_ctx->library = NULL;
550 }
551 if (amf_ctx->trace_writer) {
553 }
554
555 if (amf_ctx->lock_ctx == amf_lock_default) {
557 av_freep(&amf_ctx->lock_ctx);
558 amf_ctx->lock = NULL;
559 amf_ctx->unlock = NULL;
560 }
561
562 amf_ctx->version = 0;
563}
564
565enum AMF_MEMORY_TYPE av_amf_get_memory_type(AVAMFDeviceContext *amf_ctx)
566{
567 AMFContext *context = amf_ctx->context;
568 AMFContext1 *context1 = NULL;
569 AMFGuid guid1 = IID_AMFContext1();
570
571 if (!amf_ctx)
572 return AMF_MEMORY_UNKNOWN;
573
574#ifdef _WIN32
575 if (AMF_IFACE_CALL(context, GetDX11Device, AMF_DX11_1))
576 return AMF_MEMORY_DX11;
577
578 if (AMF_IFACE_CALL(context, GetDX9Device, AMF_DX9))
579 return AMF_MEMORY_DX9;
580#endif
581
582 if (AMF_IFACE_CALL(context, QueryInterface, &guid1, (void**)&context1) != AMF_OK)
583 return AMF_MEMORY_UNKNOWN;
584
585 if (AMF_IFACE_CALL(context1, GetVulkanDevice)) {
586 context1->pVtbl->Release(context1);
587 return AMF_MEMORY_VULKAN;
588 }
589
590 return AMF_MEMORY_UNKNOWN;
591}
592
594{
595 AVAMFDeviceContext *amf_ctx = ctx->hwctx;
596 AMFContext *context = amf_ctx->context;
597 AMFContext1 *context1 = NULL;
598 AMFGuid guid1 = IID_AMFContext1();
599 AMF_RESULT res;
600
601 if (!amf_ctx->lock) {
602 amf_ctx->lock_ctx = av_mallocz(sizeof(AVMutex));
603 if (!amf_ctx->lock_ctx) {
604 return AVERROR(ENOMEM);
605 }
606 ff_mutex_init((AVMutex*)amf_ctx->lock_ctx, NULL);
607 amf_ctx->lock = amf_lock_default;
608 amf_ctx->unlock = amf_unlock_default;
609 }
610
611 if (av_amf_get_memory_type(amf_ctx) != AMF_MEMORY_UNKNOWN) {
612 av_log(ctx, AV_LOG_VERBOSE, "AMF is already initialized, skipping init.\n");
613 return 0;
614 }
615
616#ifdef _WIN32
617 res = AMF_IFACE_CALL(context, InitDX11, NULL, AMF_DX11_1);
618 if (res == AMF_OK) {
619 av_log(ctx, AV_LOG_VERBOSE, "Successfully initialized AMF via D3D11.\n");
620 return 0;
621 }
622
623 res = AMF_IFACE_CALL(context, InitDX9, NULL);
624 if (res == AMF_OK) {
625 av_log(ctx, AV_LOG_VERBOSE, "Successfully initialized AMF via D3D9.\n");
626 return 0;
627 }
628
629 av_log(ctx, AV_LOG_WARNING, "AMF failed to initialize with any of supported versions of DirectX, trying Vulkan instead...\n");
630#endif
631
632 res = AMF_IFACE_CALL(context, QueryInterface, &guid1, (void**)&context1);
633 AMF_RETURN_IF_FALSE(ctx, res == AMF_OK, AVERROR_UNKNOWN, "CreateContext1() failed with error %d\n", res);
634
635 res = AMF_IFACE_CALL(context1, InitVulkan, NULL);
636 AMF_IFACE_CALL(context1, Release);
637
638 if (res == AMF_OK)
639 av_log(ctx, AV_LOG_VERBOSE, "Successfully initialized AMF via Vulkan.\n");
640 else {
641 if (res == AMF_NOT_SUPPORTED)
642 av_log(ctx, AV_LOG_ERROR, "AMF via Vulkan is not supported on the given device.\n");
643 else
644 av_log(ctx, AV_LOG_ERROR, "Failed to initialize AMF via Vulkan, error %d\n", res);
645
646 return AVERROR(ENOSYS);
647 }
648
649 return 0;
650}
651
652static int amf_load_library(AVAMFDeviceContext* amf_ctx, void* avcl)
653{
654 AMFInit_Fn init_fun;
655 AMFQueryVersion_Fn version_fun;
656 AMF_RESULT res;
657
658 amf_ctx->library = dlopen(AMF_DLL_NAMEA, RTLD_NOW | RTLD_LOCAL);
659 AMF_RETURN_IF_FALSE(avcl, amf_ctx->library != NULL,
660 AVERROR_UNKNOWN, "DLL %s failed to open\n", AMF_DLL_NAMEA);
661
662 init_fun = (AMFInit_Fn)dlsym(amf_ctx->library, AMF_INIT_FUNCTION_NAME);
663 AMF_RETURN_IF_FALSE(avcl, init_fun != NULL, AVERROR_UNKNOWN, "DLL %s failed to find function %s\n", AMF_DLL_NAMEA, AMF_INIT_FUNCTION_NAME);
664
665 version_fun = (AMFQueryVersion_Fn)dlsym(amf_ctx->library, AMF_QUERY_VERSION_FUNCTION_NAME);
666 AMF_RETURN_IF_FALSE(avcl, version_fun != NULL, AVERROR_UNKNOWN, "DLL %s failed to find function %s\n", AMF_DLL_NAMEA, AMF_QUERY_VERSION_FUNCTION_NAME);
667
668 amf_uint64 version;
669 res = version_fun(&version);
670 AMF_RETURN_IF_FALSE(avcl, res == AMF_OK, AVERROR_UNKNOWN, "%s failed with error %d\n", AMF_QUERY_VERSION_FUNCTION_NAME, res);
671 amf_ctx->version = version;
672 res = init_fun(AMF_FULL_VERSION, &amf_ctx->factory);
673 AMF_RETURN_IF_FALSE(avcl, res == AMF_OK, AVERROR_UNKNOWN, "%s failed with error %d\n", AMF_INIT_FUNCTION_NAME, res);
674 return 0;
675}
676
678 const char *device,
679 AVDictionary *opts, int flags)
680{
681 AVAMFDeviceContext *ctx = device_ctx->hwctx;
682 AMFTrace *trace;
683 int ret;
684 if ((ret = amf_load_library(ctx, device_ctx)) == 0) {
685 ret = ctx->factory->pVtbl->GetTrace(ctx->factory, &trace);
686 if (ret == AMF_OK) {
687 int level_ff = av_log_get_level();
688 int level_amf = AMF_TRACE_TRACE;
689 amf_bool enable_log = true;
690 switch(level_ff)
691 {
692 case AV_LOG_QUIET:
693 level_amf = AMF_TRACE_ERROR;
694 enable_log = false;
695 break;
696 case AV_LOG_PANIC:
697 case AV_LOG_FATAL:
698 case AV_LOG_ERROR:
699 level_amf = AMF_TRACE_ERROR;
700 break;
701 case AV_LOG_WARNING:
702 case AV_LOG_INFO:
703 level_amf = AMF_TRACE_WARNING;
704 break;
705 case AV_LOG_VERBOSE:
706 level_amf = AMF_TRACE_INFO;
707 break;
708 case AV_LOG_DEBUG:
709 level_amf = AMF_TRACE_DEBUG;
710 break;
711 case AV_LOG_TRACE:
712 level_amf = AMF_TRACE_TRACE;
713 break;
714 }
715 if(ctx->version == AMF_MAKE_FULL_VERSION(1, 4, 35, 0)){// get around a bug in trace in AMF runtime driver 24.20
716 level_amf = AMF_TRACE_WARNING;
717 }
718
719 trace->pVtbl->EnableWriter(trace, AMF_TRACE_WRITER_CONSOLE, 0);
720 trace->pVtbl->SetGlobalLevel(trace, level_amf);
721
722 // connect AMF logger to av_log
723 ctx->trace_writer = amf_writer_alloc(device_ctx);
724 trace->pVtbl->RegisterWriter(trace, FFMPEG_AMF_WRITER_ID, (AMFTraceWriter*)ctx->trace_writer, 1);
725 trace->pVtbl->SetWriterLevel(trace, FFMPEG_AMF_WRITER_ID, level_amf);
726 trace->pVtbl->EnableWriter(trace, FFMPEG_AMF_WRITER_ID, enable_log);
727 trace->pVtbl->SetWriterLevel(trace, AMF_TRACE_WRITER_DEBUG_OUTPUT, level_amf);
728 trace->pVtbl->EnableWriter(trace, AMF_TRACE_WRITER_DEBUG_OUTPUT, enable_log);
729 }
730
731
732 ret = ctx->factory->pVtbl->CreateContext(ctx->factory, &ctx->context);
733 if (ret == AMF_OK) {
734 AMF_ASSIGN_PROPERTY_INT64(ret, ctx->context, L"DeviceSurfaceCacheSize", 50 );
735 return 0;
736 }
737 av_log(device_ctx, AV_LOG_ERROR, "CreateContext() failed with error %d.\n", ret);
738 }
739 amf_device_uninit(device_ctx);
740 return ret;
741}
742
743#if CONFIG_DXVA2
744static int amf_init_from_dxva2_device(AVAMFDeviceContext * amf_ctx, AVHWDeviceContext *child_device_ctx)
745{
746 AVDXVA2DeviceContext *hwctx = child_device_ctx->hwctx;
747 IDirect3DDevice9 *device;
748 HANDLE device_handle;
749 HRESULT hr;
750 AMF_RESULT res;
751 int ret;
752
753 hr = IDirect3DDeviceManager9_OpenDeviceHandle(hwctx->devmgr, &device_handle);
754 if (FAILED(hr)) {
755 av_log(child_device_ctx, AV_LOG_ERROR, "Failed to open device handle for Direct3D9 device: %lx.\n", (unsigned long)hr);
756 return AVERROR_EXTERNAL;
757 }
758
759 hr = IDirect3DDeviceManager9_LockDevice(hwctx->devmgr, device_handle, &device, FALSE);
760 if (SUCCEEDED(hr)) {
761 IDirect3DDeviceManager9_UnlockDevice(hwctx->devmgr, device_handle, FALSE);
762 ret = 0;
763 } else {
764 av_log(child_device_ctx, AV_LOG_ERROR, "Failed to lock device handle for Direct3D9 device: %lx.\n", (unsigned long)hr);
765 ret = AVERROR_EXTERNAL;
766 }
767
768
769 IDirect3DDeviceManager9_CloseDeviceHandle(hwctx->devmgr, device_handle);
770
771 if (ret < 0)
772 return ret;
773
774 res = amf_ctx->context->pVtbl->InitDX9(amf_ctx->context, device);
775
776 IDirect3DDevice9_Release(device);
777
778 if (res != AMF_OK && res != AMF_ALREADY_INITIALIZED) {
779 if (res == AMF_NOT_SUPPORTED)
780 av_log(child_device_ctx, AV_LOG_ERROR, "AMF via D3D9 is not supported on the given device.\n");
781 else
782 av_log(child_device_ctx, AV_LOG_ERROR, "AMF failed to initialise on given D3D9 device: %d.\n", res);
783 return AVERROR(ENODEV);
784 }
785 av_log(child_device_ctx, AV_LOG_INFO, "AMF via DXVA2.\n");
786 return 0;
787}
788#endif
789
790#if CONFIG_D3D11VA
791static int amf_init_from_d3d11_device(AVAMFDeviceContext* amf_ctx, AVHWDeviceContext *child_device_ctx)
792{
793 AMF_RESULT res;
794 AVD3D11VADeviceContext *hwctx = child_device_ctx->hwctx;
795 res = amf_ctx->context->pVtbl->InitDX11(amf_ctx->context, hwctx->device, AMF_DX11_1);
796 if (res != AMF_OK && res != AMF_ALREADY_INITIALIZED) {
797 if (res == AMF_NOT_SUPPORTED)
798 av_log(child_device_ctx, AV_LOG_ERROR, "AMF via D3D11 is not supported on the given device.\n");
799 else
800 av_log(child_device_ctx, AV_LOG_ERROR, "AMF failed to initialise on the given D3D11 device: %d.\n", res);
801 return AVERROR(ENODEV);
802 }
803 av_log(child_device_ctx, AV_LOG_INFO, "AMF via D3D11.\n");
804 return 0;
805}
806#endif
807
808#if CONFIG_D3D12VA
809static int amf_init_from_d3d12_device(AVAMFDeviceContext* amf_ctx, AVHWDeviceContext *child_device_ctx)
810{
811 AVD3D12VADeviceContext *hwctx = child_device_ctx->hwctx;
812 AMF_RESULT res;
813 AMFContext2 *context2 = NULL;
814 AMFGuid guid = IID_AMFContext2();
815 res = amf_ctx->context->pVtbl->QueryInterface(amf_ctx->context, &guid, (void**)&context2);
816 AMF_RETURN_IF_FALSE(child_device_ctx, res == AMF_OK, AVERROR_UNKNOWN, "CreateContext2() failed with error %d\n", res);
817 res = context2->pVtbl->InitDX12(context2, hwctx->device, AMF_DX12);
818 context2->pVtbl->Release(context2);
819 if (res != AMF_OK && res != AMF_ALREADY_INITIALIZED) {
820 if (res == AMF_NOT_SUPPORTED)
821 av_log(child_device_ctx, AV_LOG_ERROR, "AMF via D3D12 is not supported on the given device.\n");
822 else
823 av_log(child_device_ctx, AV_LOG_ERROR, "AMF failed to initialise on the given D3D12 device: %d.\n", res);
824 return AVERROR(ENODEV);
825 }
826 av_log(child_device_ctx, AV_LOG_INFO, "AMF via D3D12.\n");
827 return 0;
828}
829#endif
830
831
833 AVHWDeviceContext *child_device_ctx, AVDictionary *opts,
834 int flags)
835{
836#if CONFIG_DXVA2 || CONFIG_D3D11VA
837 AVAMFDeviceContext *amf_ctx = device_ctx->hwctx;
838#endif
839 int ret;
840
841 ret = amf_device_create(device_ctx, "", opts, flags);
842 if(ret < 0)
843 return ret;
844
845 switch (child_device_ctx->type) {
846#if CONFIG_DXVA2
848 return amf_init_from_dxva2_device(amf_ctx, child_device_ctx);
849#endif
850#if CONFIG_D3D11VA
852 return amf_init_from_d3d11_device(amf_ctx, child_device_ctx);
853#endif
854#if CONFIG_D3D12VA
856 return amf_init_from_d3d12_device(amf_ctx, child_device_ctx);
857#endif
858 default:
859 av_log(child_device_ctx, AV_LOG_ERROR, "AMF initialisation from a %s device is not supported.\n",
860 av_hwdevice_get_type_name(child_device_ctx->type));
861 return AVERROR(ENOSYS);
862 }
863}
864
866{
867 AMFSurface1 *surface1 = hwmap->priv;
868 AMF_IFACE_CALL(surface1, Unmap);
869 AMF_IFACE_CALL(surface1, Release);
870}
871
872static int amf_map_frame(AVHWFramesContext *device_ctx, AVFrame *dst, const AVFrame *src, int flags)
873{
874 AMFSurface *surface = (AMFSurface *)src->data[0];
875 AMFSurface1 *surface1 = NULL;
876 size_t *linesizes = NULL;
877 uint8_t **map = NULL;
878 int amf_mem_flags = AMF_MEMORY_CPU_NONE;
879 const AMFGuid guid = IID_AMFSurface1();
880 AMF_RESULT res = AMF_FAIL;
881 size_t plane_count = 0;
882 int ret = -1;
883
884 AMF_RETURN_IF_FALSE(device_ctx, surface != NULL, AVERROR(EINVAL) , "Source surface is null");
885
886 res = AMF_IFACE_CALL(surface, QueryInterface, &guid, (void**)&surface1);
887 AMF_RETURN_IF_FALSE(device_ctx, res == AMF_OK, AVERROR_UNKNOWN, "QueryInterface(AMFSurface1) failed with error %d\n", res);
888
890 amf_mem_flags |= AMF_MEMORY_CPU_READ;
891
893 amf_mem_flags |= AMF_MEMORY_CPU_WRITE;
894
895 plane_count = AMF_IFACE_CALL(surface, GetPlanesCount);
896 linesizes = av_malloc_array(sizeof(size_t), plane_count);
897 AMF_GOTO_FAIL_IF_FALSE(device_ctx, linesizes, AVERROR(ENOMEM), "Unable to allocate line sizes array\n");
898
899 map = av_malloc_array(sizeof(uint8_t *), plane_count);
900 AMF_GOTO_FAIL_IF_FALSE(device_ctx, map, AVERROR(ENOMEM), "Unable to allocate mapping buffer\n");
901
902 dst->format = av_amf_to_av_format(AMF_IFACE_CALL(surface, GetFormat));
903
904 res = AMF_IFACE_CALL(surface1, Map, amf_mem_flags, plane_count, linesizes, (void**)map);
905 AMF_GOTO_FAIL_IF_FALSE(device_ctx, res == AMF_OK, AVERROR_UNKNOWN, "AMFSurface1->Map() failed with error %d\n", res);
906
907 ret = ff_hwframe_map_create(src->hw_frames_ctx, dst, src, &amf_unmap_frame, surface1);
908 AMF_GOTO_FAIL_IF_FALSE(device_ctx, ret >= 0, ret, "ff_hwframe_map_create failed with error %d\n", ret);
909
910 dst->width = src->width;
911 dst->height = src->height;
913
914 // The dst frame is no longer a hardware frame, from the perspective of any dst frame consumer.
915 av_buffer_unref(&dst->hw_frames_ctx);
916
917 for (int plane = 0; plane < plane_count; ++plane)
918 {
919 dst->data[plane] = map[plane];
920 dst->linesize[plane] = linesizes[plane];
921 }
922
923fail:
924 if (map)
925 av_free(map);
926
927 if (linesizes)
928 av_free(linesizes);
929
930 if (ret < 0 && surface1 != NULL)
931 AMF_IFACE_CALL(surface1, Release);
932
933 return ret;
934}
935
937 .type = AV_HWDEVICE_TYPE_AMF,
938 .name = "AMF",
939
940 .device_hwctx_size = sizeof(AVAMFDeviceContext),
941 .frames_hwctx_size = sizeof(AMFFramesContext),
942
943 .device_create = amf_device_create,
944 .device_derive = amf_device_derive,
945 .device_init = amf_device_init,
946 .device_uninit = amf_device_uninit,
947 .frames_get_constraints = amf_frames_get_constraints,
948 .frames_init = amf_frames_init,
949 .frames_get_buffer = amf_get_buffer,
950 .transfer_get_formats = amf_transfer_get_formats,
951 .transfer_data_to = amf_transfer_data_to,
952 .transfer_data_from = amf_transfer_data_from,
953 .map_from = amf_map_frame,
954
955 .pix_fmts = (const enum AVPixelFormat[]){ AV_PIX_FMT_AMF_SURFACE, AV_PIX_FMT_NONE },
956};
uint8_t ptrdiff_t const uint8_t ptrdiff_t int intptr_t intptr_t int int16_t * dst
Definition dsp.h:87
static const char *const format[]
Definition af_aiir.c:445
static void amf_free_amfsurface(void *opaque, uint8_t *data)
Definition amfdec.c:58
#define FFMPEG_AMF_WRITER_ID
Definition amfenc.c:52
#define AMF_RETURN_IF_FALSE(avctx, exp, ret_value,...)
Error handling helper.
Definition amfenc.h:169
static AVFormatContext * ctx
static AVDictionary * opts
#define L(x)
Definition vpx_arith.h:36
simple assert() macros that are a bit more flexible than ISO C assert().
#define av_assert0(cond)
assert() equivalent, that is always enabled.
Definition avassert.h:42
refcounted data buffer API
#define flags(name, subs,...)
Definition cbs_h264.c:74
#define i(width, name, range_min, range_max)
Definition cbs_h264.c:63
#define NULL
Definition coverity.c:32
static AVFrame * frame
#define fail
Definition test.h:479
void av_buffer_unref(AVBufferRef **buf)
Free a given reference and automatically free the buffer if there are no more references to it.
Definition buffer.c:139
#define AV_BUFFER_FLAG_READONLY
Always treat the buffer as read-only, even when it has only one reference.
Definition buffer.h:114
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.
Definition buffer.c:55
AVBufferRef * av_buffer_pool_get(AVBufferPool *pool)
Allocate a new AVBuffer, reusing an old buffer from the pool when available.
Definition buffer.c:390
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.
Definition buffer.c:259
#define AVERROR_UNKNOWN
Unknown error, typically from an external library.
Definition error.h:73
#define AVERROR_EXTERNAL
Generic error in an external library.
Definition error.h:59
#define AVERROR(e)
Definition error.h:45
AVFrameSideData * av_frame_get_side_data(const AVFrame *frame, enum AVFrameSideDataType type)
Definition frame.c:659
int av_frame_copy_props(AVFrame *dst, const AVFrame *src)
Copy only "metadata" fields from src to dst.
Definition frame.c:599
@ AV_FRAME_DATA_CONTENT_LIGHT_LEVEL
Content light level (based on CTA-861.3).
Definition frame.h:137
@ AV_FRAME_DATA_MASTERING_DISPLAY_METADATA
Mastering display metadata associated with a video frame.
Definition frame.h:120
#define AV_LOG_TRACE
Extremely verbose debugging, useful for libav* development.
Definition log.h:236
#define AV_LOG_PANIC
Something went really wrong and we will crash now.
Definition log.h:197
#define AV_LOG_QUIET
Print no output.
Definition log.h:192
#define AV_LOG_DEBUG
Stuff which is only useful for libav* developers.
Definition log.h:231
#define AV_LOG_WARNING
Something somehow does not look correct.
Definition log.h:216
#define AV_LOG_FATAL
Something went wrong and recovery is not possible.
Definition log.h:204
#define AV_LOG_VERBOSE
Detailed information.
Definition log.h:226
#define AV_LOG_INFO
Standard information.
Definition log.h:221
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
Definition log.h:210
int av_log_get_level(void)
Get the current log level.
Definition log.c:471
static AVRational av_make_q(int num, int den)
Create an AVRational.
Definition rational.h:71
static double av_q2d(AVRational a)
Convert an AVRational to a double.
Definition rational.h:104
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 ...
Definition imgutils.h:184
const char * av_hwdevice_get_type_name(enum AVHWDeviceType type)
Get the string name of an AVHWDeviceType.
Definition hwcontext.c:120
int ff_hwframe_map_create(AVBufferRef *hwframe_ref, AVFrame *dst, const AVFrame *src, void(*unmap)(AVHWFramesContext *ctx, HWMapDescriptor *hwmap), void *priv)
Definition hwcontext.c:741
@ AV_HWFRAME_MAP_READ
The mapping must be readable.
Definition hwcontext.h:515
@ AV_HWFRAME_MAP_WRITE
The mapping must be writeable.
Definition hwcontext.h:519
AVHWFrameTransferDirection
Definition hwcontext.h:406
@ AV_HWDEVICE_TYPE_D3D11VA
Definition hwcontext.h:35
@ AV_HWDEVICE_TYPE_AMF
Definition hwcontext.h:41
@ AV_HWDEVICE_TYPE_D3D12VA
Definition hwcontext.h:40
@ AV_HWDEVICE_TYPE_DXVA2
Definition hwcontext.h:32
int av_amf_display_mastering_meta_to_hdrmeta(const AVMasteringDisplayMetadata *display_meta, AMFHDRMetadata *hdrmeta)
static int amf_device_create(AVHWDeviceContext *device_ctx, const char *device, AVDictionary *opts, int flags)
static void amf_unmap_frame(av_unused AVHWFramesContext *unused, HWMapDescriptor *hwmap)
static int amf_device_init(AVHWDeviceContext *ctx)
static void amf_unlock_default(void *opaque)
static int amf_load_library(AVAMFDeviceContext *amf_ctx, void *avcl)
enum AMF_MEMORY_TYPE av_amf_get_memory_type(AVAMFDeviceContext *amf_ctx)
static int amf_map_frame(AVHWFramesContext *device_ctx, AVFrame *dst, const AVFrame *src, int flags)
int av_amf_attach_hdr_metadata(AVFrame *frame, const AMFHDRMetadata *hdrmeta)
static void AMF_CDECL_CALL AMFTraceWriter_Write(AMFTraceWriter *pThis, const wchar_t *scope, const wchar_t *message)
static int amf_transfer_data_from(AVHWFramesContext *ctx, AVFrame *dst, const AVFrame *src)
static int amf_transfer_data_to(AVHWFramesContext *ctx, AVFrame *dst, const AVFrame *src)
const FormatMap format_map[]
const HWContextType ff_hwcontext_type_amf
int av_amf_light_metadata_to_hdrmeta(const AVContentLightMetadata *light_meta, AMFHDRMetadata *hdrmeta)
static void amf_device_uninit(AVHWDeviceContext *device_ctx)
static int amf_frames_init(AVHWFramesContext *ctx)
enum AMF_SURFACE_FORMAT av_av_to_amf_format(enum AVPixelFormat fmt)
static void amf_writer_free(void *opaque)
static enum AVPixelFormat supported_transfer_formats[]
static AmfTraceWriter * amf_writer_alloc(void *avctx)
static int amf_device_derive(AVHWDeviceContext *device_ctx, AVHWDeviceContext *child_device_ctx, AVDictionary *opts, int flags)
static int amf_get_buffer(AVHWFramesContext *ctx, AVFrame *frame)
static void amf_free_amfsurface(void *opaque, uint8_t *data)
int av_amf_extract_hdr_metadata(const AVFrame *frame, AMFHDRMetadata *hdrmeta)
enum AVPixelFormat av_amf_to_av_format(enum AMF_SURFACE_FORMAT fmt)
static void amf_lock_default(void *opaque)
static int amf_transfer_get_formats(AVHWFramesContext *ctx, enum AVHWFrameTransferDirection dir, enum AVPixelFormat **formats)
static void amf_dummy_free(void *opaque, uint8_t *data)
enum AMF_VIDEO_CONVERTER_COLOR_PROFILE_ENUM av_amf_get_color_profile(enum AVColorRange color_range, enum AVColorSpace color_space)
static int amf_frames_get_constraints(AVHWDeviceContext *ctx, const void *hwconfig, AVHWFramesConstraints *constraints)
static AVBufferRef * amf_pool_alloc(void *opaque, size_t size)
static void AMF_CDECL_CALL AMFTraceWriter_Flush(AMFTraceWriter *pThis)
#define AMF_GOTO_FAIL_IF_FALSE(avctx, exp, ret_value,...)
#define AMF_IFACE_CALL(this, function,...)
An API-specific header for AV_HWDEVICE_TYPE_D3D11VA.
An API-specific header for AV_HWDEVICE_TYPE_D3D12VA.
An API-specific header for AV_HWDEVICE_TYPE_DXVA2.
static FFHWFramesContext * ffhwframesctx(AVHWFramesContext *ctx)
const VDPAUPixFmtMap * map
API-specific header for AV_HWDEVICE_TYPE_VULKAN.
misc image utilities
#define av_unused
Definition attributes.h:164
static int ff_mutex_unlock(AVMutex *mutex)
Definition thread.h:189
static int ff_mutex_lock(AVMutex *mutex)
Definition thread.h:188
static int ff_mutex_destroy(AVMutex *mutex)
Definition thread.h:190
#define AVMutex
Definition thread.h:184
static int ff_mutex_init(AVMutex *mutex, const void *attr)
Definition thread.h:187
version
Definition libkvazaar.c:313
static const struct @257111027162314367033347246032313251342043035002 planes[]
uint8_t w
Definition llvidencdsp.c:39
#define FFMIN(a, b)
Definition macros.h:49
AVContentLightMetadata * av_content_light_metadata_create_side_data(AVFrame *frame)
Allocate a complete AVContentLightMetadata and add it to the frame.
AVMasteringDisplayMetadata * av_mastering_display_metadata_create_side_data(AVFrame *frame)
Allocate a complete AVMasteringDisplayMetadata and add it to the frame.
Memory handling functions.
const char data[16]
Definition mxf.c:149
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.
Definition pixdesc.c:3380
pixel format definitions
#define AV_PIX_FMT_RGBAF16
Definition pixfmt.h:630
AVColorRange
Visual content value range.
Definition pixfmt.h:748
@ AVCOL_RANGE_JPEG
Full range content.
Definition pixfmt.h:783
#define AV_PIX_FMT_P010
Definition pixfmt.h:608
AVPixelFormat
Pixel format.
Definition pixfmt.h:71
@ 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...
Definition pixfmt.h:96
@ AV_PIX_FMT_NONE
Definition pixfmt.h:72
@ AV_PIX_FMT_YUV420P
planar YUV 4:2:0, 12bpp, (1 Cr & Cb sample per 2x2 Y samples)
Definition pixfmt.h:73
@ AV_PIX_FMT_BGR0
packed BGR 8:8:8, 32bpp, BGRXBGRX... X=unused/undefined
Definition pixfmt.h:265
@ AV_PIX_FMT_D3D12
Hardware surfaces for Direct3D 12.
Definition pixfmt.h:440
@ AV_PIX_FMT_DXVA2_VLD
HW decoding through DXVA2, Picture.data[3] contains a LPDIRECT3DSURFACE9 pointer.
Definition pixfmt.h:134
@ AV_PIX_FMT_ARGB
packed ARGB 8:8:8:8, 32bpp, ARGBARGB...
Definition pixfmt.h:99
@ AV_PIX_FMT_BGRA
packed BGRA 8:8:8:8, 32bpp, BGRABGRA...
Definition pixfmt.h:102
@ AV_PIX_FMT_GRAY8
Y , 8bpp.
Definition pixfmt.h:81
@ AV_PIX_FMT_RGBA
packed RGBA 8:8:8:8, 32bpp, RGBARGBA...
Definition pixfmt.h:100
@ AV_PIX_FMT_D3D11
Hardware surfaces for Direct3D11.
Definition pixfmt.h:336
@ AV_PIX_FMT_RGB0
packed RGB 8:8:8, 32bpp, RGBXRGBX... X=unused/undefined
Definition pixfmt.h:263
@ AV_PIX_FMT_YUYV422
packed YUV 4:2:2, 16bpp, Y0 Cb Y1 Cr
Definition pixfmt.h:74
@ AV_PIX_FMT_AMF_SURFACE
HW acceleration through AMF.
Definition pixfmt.h:477
#define AV_PIX_FMT_X2BGR10
Definition pixfmt.h:620
AVColorSpace
YUV colorspace type.
Definition pixfmt.h:706
@ AVCOL_SPC_BT709
also ITU-R BT1361 / IEC 61966-2-4 xvYCC709 / derived in SMPTE RP 177 Annex B
Definition pixfmt.h:708
@ AVCOL_SPC_BT2020_CL
ITU-R BT2020 constant luminance system.
Definition pixfmt.h:718
@ AVCOL_SPC_BT2020_NCL
ITU-R BT2020 non-constant luminance system.
Definition pixfmt.h:717
@ AVCOL_SPC_SMPTE170M
also ITU-R BT601-6 525 / ITU-R BT1358 525 / ITU-R BT1700 NTSC / functionally identical to above
Definition pixfmt.h:713
formats
Definition signature.h:47
#define FF_ARRAY_ELEMS(a)
We still need AVHWFramesContext to utilize our hardware memory otherwise, we will receive the error "...
This struct is allocated as AVHWDeviceContext.hwctx.
void(* lock)(void *lock_ctx)
AMFContext * context
void(* unlock)(void *lock_ctx)
AMFFactory * factory
int64_t version
version of AMF runtime
A reference to a data buffer.
Definition buffer.h:82
Content light level needed by to transmit HDR over HDMI (CTA-861.3).
unsigned MaxFALL
Max average light level per frame (cd/m^2).
unsigned MaxCLL
Max content light level (cd/m^2).
This struct is allocated as AVHWDeviceContext.hwctx.
ID3D11Device * device
Device used for texture creation and access.
This struct is allocated as AVHWDeviceContext.hwctx.
ID3D12Device * device
Device used for objects creation and access.
This struct is allocated as AVHWDeviceContext.hwctx.
IDirect3DDeviceManager9 * devmgr
Structure to hold side data for an AVFrame.
Definition frame.h:327
uint8_t * data
Definition frame.h:329
This structure describes decoded (raw) audio or video data.
Definition frame.h:472
This struct aggregates all the (hardware/vendor-specific) "high-level" state, i.e.
Definition hwcontext.h:63
void * hwctx
The format-specific data, allocated and freed by libavutil along with this context.
Definition hwcontext.h:88
enum AVHWDeviceType type
This field identifies the underlying API used for hardware access.
Definition hwcontext.h:75
This struct describes the constraints on hardware frames attached to a given device with a hardware-s...
Definition hwcontext.h:444
enum AVPixelFormat * valid_hw_formats
A list of possible values for format in the hw_frames_ctx, terminated by AV_PIX_FMT_NONE.
Definition hwcontext.h:449
enum AVPixelFormat * valid_sw_formats
A list of possible values for sw_format in the hw_frames_ctx, terminated by AV_PIX_FMT_NONE.
Definition hwcontext.h:456
This struct describes a set or pool of "hardware" frames (i.e.
Definition hwcontext.h:118
Mastering display metadata capable of representing the color volume of the display used to master the...
int has_primaries
Flag indicating whether the display primaries (and white point) are set.
AVRational max_luminance
Max luminance of mastering display (cd/m^2).
AVRational min_luminance
Min luminance of mastering display (cd/m^2).
AVRational display_primaries[3][2]
CIE 1931 xy chromaticity coords of color primaries (r, g, b order).
AVRational white_point[2]
CIE 1931 xy chromaticity coords of white point.
int has_luminance
Flag indicating whether the luminance (min_ and max_) have been set.
AMFTraceWriterVtbl vtbl
AMFTraceWriterVtbl * vtblp
AVBufferPool * pool_internal
enum AMF_SURFACE_FORMAT amf_format
enum AVPixelFormat av_format
void * priv
Hardware-specific private data associated with the mapping.
#define av_free(p)
#define av_malloc_array(a, b)
#define av_mallocz(s)
#define av_freep(p)
#define av_log(a,...)
#define src
Definition vp8dsp.c:248
int size
static enum AVPixelFormat supported_formats[]
color_range