FFmpeg
Loading...
Searching...
No Matches
amfdec.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
21#include "libavutil/pixdesc.h"
22#include "amfdec.h"
23#include "codec_internal.h"
24#include "hwconfig.h"
25#include "libavutil/time.h"
26#include "decode.h"
27#include "decode_bsf.h"
28
29#if CONFIG_D3D11VA
31#endif
32#if CONFIG_DXVA2
33#define COBJMACROS
35#endif
36
37#ifdef _WIN32
38#include "compat/w32dlfcn.h"
39#else
40#include <dlfcn.h>
41#endif
42//will be in public headers soon
43#define AMF_VIDEO_DECODER_OUTPUT_FORMAT L"OutputDecodeFormat"
44
45static const AVCodecHWConfigInternal *const amf_hw_configs[] = {
47 .public = {
48 .pix_fmt = AV_PIX_FMT_AMF_SURFACE,
51 .device_type = AV_HWDEVICE_TYPE_AMF,
52 },
53 .hwaccel = NULL,
54 },
55 NULL
56};
57
58static void amf_free_amfsurface(void *opaque, uint8_t *data)
59{
60 AMFSurface *surface = (AMFSurface*)(data);
61 surface->pVtbl->Release(surface);
62}
63
65{
66 if( AMF_GET_MAJOR_VERSION(amf_device_ctx->version) <= 1 &&
67 AMF_GET_MINOR_VERSION(amf_device_ctx->version) <= 4 &&
68 AMF_GET_SUBMINOR_VERSION(amf_device_ctx->version) < 36)
69 return 1;
70 return 0;
71}
72
74{
76 AVHWDeviceContext *hw_device_ctx = (AVHWDeviceContext*)ctx->device_ctx_ref->data;
77 AVAMFDeviceContext *amf_device_ctx = (AVAMFDeviceContext*)hw_device_ctx->hwctx;
78 const wchar_t *codec_id = NULL;
79 AMF_RESULT res;
80 AMFBuffer *buffer;
81 amf_int64 color_profile;
82 int pool_size = 36;
83 // way-around for older drivers that don't support dynamic bitness detection -
84 // define HEVC and VP9 10-bit based on container info
85 int no_bitness_detect = amf_legacy_driver_no_bitness_detect(amf_device_ctx);
86
87 ctx->drain = 0;
88 ctx->resolution_changed = 0;
89
90 switch (avctx->codec->id) {
92 codec_id = AMFVideoDecoderUVD_H264_AVC;
93 break;
94 case AV_CODEC_ID_HEVC: {
95 codec_id = AMFVideoDecoderHW_H265_HEVC;
96 if(no_bitness_detect){
97 if(avctx->pix_fmt == AV_PIX_FMT_YUV420P10)
98 codec_id = AMFVideoDecoderHW_H265_MAIN10;
99 }
100 } break;
101 case AV_CODEC_ID_VP9: {
102 codec_id = AMFVideoDecoderHW_VP9;
103 if(no_bitness_detect){
104 if(avctx->pix_fmt == AV_PIX_FMT_YUV420P10)
105 codec_id = AMFVideoDecoderHW_VP9_10BIT;
106 }
107 } break;
108 case AV_CODEC_ID_AV1:
109 codec_id = AMFVideoDecoderHW_AV1;
110 break;
111 default:
112 break;
113 }
114 AMF_RETURN_IF_FALSE(ctx, codec_id != NULL, AVERROR(EINVAL), "Codec %d is not supported\n", avctx->codec->id);
115
116 res = amf_device_ctx->factory->pVtbl->CreateComponent(amf_device_ctx->factory, amf_device_ctx->context, codec_id, &ctx->decoder);
117 AMF_RETURN_IF_FALSE(ctx, res == AMF_OK, AVERROR_ENCODER_NOT_FOUND, "CreateComponent(%ls) failed with error %d\n", codec_id, res);
118
119 // Color Metadata
120 /// Color Range (Support for older Drivers)
121 if (avctx->color_range == AVCOL_RANGE_JPEG) {
122 AMF_ASSIGN_PROPERTY_BOOL(res, ctx->decoder, AMF_VIDEO_DECODER_FULL_RANGE_COLOR, 1);
123 } else if (avctx->color_range != AVCOL_RANGE_UNSPECIFIED) {
124 AMF_ASSIGN_PROPERTY_BOOL(res, ctx->decoder, AMF_VIDEO_DECODER_FULL_RANGE_COLOR, 0);
125 }
126 color_profile = av_amf_get_color_profile(avctx->color_range, avctx->colorspace);
127 if (color_profile != AMF_VIDEO_CONVERTER_COLOR_PROFILE_UNKNOWN)
128 AMF_ASSIGN_PROPERTY_INT64(res, ctx->decoder, AMF_VIDEO_DECODER_COLOR_PROFILE, color_profile);
129 if (avctx->color_trc != AVCOL_TRC_UNSPECIFIED)
130 AMF_ASSIGN_PROPERTY_INT64(res, ctx->decoder, AMF_VIDEO_DECODER_COLOR_TRANSFER_CHARACTERISTIC, (amf_int64)avctx->color_trc);
131
133 AMF_ASSIGN_PROPERTY_INT64(res, ctx->decoder, AMF_VIDEO_DECODER_COLOR_PRIMARIES, (amf_int64)avctx->color_primaries);
134
135 if (ctx->timestamp_mode != -1)
136 AMF_ASSIGN_PROPERTY_INT64(res, ctx->decoder, AMF_TIMESTAMP_MODE, ctx->timestamp_mode);
137 if (ctx->decoder_mode != -1)
138 AMF_ASSIGN_PROPERTY_INT64(res, ctx->decoder, AMF_VIDEO_DECODER_REORDER_MODE, ctx->decoder_mode);
139 if (ctx->dpb_size != -1)
140 AMF_ASSIGN_PROPERTY_INT64(res, ctx->decoder, AMF_VIDEO_DECODER_DPB_SIZE, ctx->dpb_size);
141 if (ctx->lowlatency != -1)
142 AMF_ASSIGN_PROPERTY_INT64(res, ctx->decoder, AMF_VIDEO_DECODER_LOW_LATENCY, ctx->lowlatency);
143 if (ctx->smart_access_video != -1) {
144 AMF_ASSIGN_PROPERTY_INT64(res, ctx->decoder, AMF_VIDEO_DECODER_ENABLE_SMART_ACCESS_VIDEO, ctx->smart_access_video != 0);
145 if (res != AMF_OK) {
146 av_log(avctx, AV_LOG_ERROR, "The Smart Access Video is not supported by AMF decoder.\n");
147 return AVERROR(EINVAL);
148 } else {
149 av_log(avctx, AV_LOG_INFO, "The Smart Access Video (%d) is set.\n", ctx->smart_access_video);
150 // Set low latency mode if Smart Access Video is enabled
151 if (ctx->smart_access_video != 0) {
152 AMF_ASSIGN_PROPERTY_INT64(res, ctx->decoder, AMF_VIDEO_DECODER_LOW_LATENCY, true);
153 av_log(avctx, AV_LOG_INFO, "The Smart Access Video set low latency mode for decoder.\n");
154 }
155 }
156 }
157 if (ctx->skip_transfer_sav != -1)
158 AMF_ASSIGN_PROPERTY_INT64(res, ctx->decoder, AMF_VIDEO_DECODER_SKIP_TRANSFER_SMART_ACCESS_VIDEO, ctx->skip_transfer_sav);
159
160 if (ctx->copy_output != -1)
161 AMF_ASSIGN_PROPERTY_INT64(res, ctx->decoder, AMF_VIDEO_DECODER_SURFACE_COPY, ctx->copy_output);
162
163 if (avctx->extradata_size) {
164 const uint8_t *extradata;
165 int extradata_size;
166 ff_decode_get_extradata(avctx, &extradata, &extradata_size);
167 res = amf_device_ctx->context->pVtbl->AllocBuffer(amf_device_ctx->context, AMF_MEMORY_HOST, extradata_size, &buffer);
168 if (res == AMF_OK) {
169 memcpy(buffer->pVtbl->GetNative(buffer), extradata, extradata_size);
170 AMF_ASSIGN_PROPERTY_INTERFACE(res,ctx->decoder, AMF_VIDEO_DECODER_EXTRADATA, buffer);
171 buffer->pVtbl->Release(buffer);
172 buffer = NULL;
173 }
174 }
175 if (ctx->surface_pool_size == -1) {
176 ctx->surface_pool_size = pool_size;
177 if (avctx->extra_hw_frames > 0)
178 ctx->surface_pool_size += avctx->extra_hw_frames;
180 ctx->surface_pool_size += avctx->thread_count;
181 }
182
183 //at the moment, there is such a restriction in AMF.
184 //when it is possible, I will remove this code
185 if (ctx->surface_pool_size > 100)
186 ctx->surface_pool_size = 100;
187
188 AMF_ASSIGN_PROPERTY_INT64(res, ctx->decoder, AMF_VIDEO_DECODER_SURFACE_POOL_SIZE, ctx->surface_pool_size);
189 res = ctx->decoder->pVtbl->Init(ctx->decoder, AMF_SURFACE_UNKNOWN, avctx->width, avctx->height);
190 if (res != AMF_OK) {
191 av_log(avctx, AV_LOG_ERROR, "Decoder initialization failed with error %d\n", res);
192 return AVERROR(EINVAL);
193 }
194 return 0;
195}
196
198{
200
201 if (ctx->decoder) {
202 ctx->decoder->pVtbl->Terminate(ctx->decoder);
203 ctx->decoder->pVtbl->Release(ctx->decoder);
204 ctx->decoder = NULL;
205 }
206
207 av_buffer_unref(&ctx->device_ctx_ref);
208 av_packet_free(&ctx->in_pkt);
209
210 return 0;
211}
212
213static int amf_init_frames_context(AVCodecContext *avctx, int sw_format, int new_width, int new_height)
214{
215 int ret;
216 AVHWDeviceContext *hwdev_ctx;
217 AVHWFramesContext *hwframes_ctx;
219 if (!avctx->hw_frames_ctx || !avctx->hw_device_ctx)
220 return 0;
221 hwdev_ctx = (AVHWDeviceContext*)avctx->hw_device_ctx->data;
222 hwframes_ctx = (AVHWFramesContext*)avctx->hw_frames_ctx->data;
223 ctx = avctx->priv_data;
224
225 if (hwdev_ctx->type != AV_HWDEVICE_TYPE_AMF)
226 return 0;
227
228 hwframes_ctx->width = new_width;
229 hwframes_ctx->height = new_height;
230 hwframes_ctx->format = AV_PIX_FMT_AMF_SURFACE;
231 hwframes_ctx->sw_format = sw_format;
232 hwframes_ctx->initial_pool_size = ctx->surface_pool_size + 8;
233
235 if (ret < 0) {
236 av_log(avctx, AV_LOG_ERROR, "Error initializing a AMF frame pool\n");
238 return ret;
239 }
240 return 0;
241}
242
243static int amf_reinit_frames_context(AVCodecContext *avctx, int sw_format,
244 int new_width, int new_height)
245{
246 if (!avctx->hw_device_ctx)
247 return 0;
248
251 if (!avctx->hw_frames_ctx)
252 return AVERROR(ENOMEM);
253
254 return amf_init_frames_context(avctx, sw_format, new_width, new_height);
255}
256
258{
260 ctx->dimensions_initialized = 0;
261 int ret;
262 ctx->in_pkt = av_packet_alloc();
263 if (!ctx->in_pkt)
264 return AVERROR(ENOMEM);
265
266 if (avctx->hw_device_ctx) {
267 AVHWDeviceContext *hwdev_ctx;
268 hwdev_ctx = (AVHWDeviceContext*)avctx->hw_device_ctx->data;
269 if (hwdev_ctx->type == AV_HWDEVICE_TYPE_AMF)
270 {
271 ctx->device_ctx_ref = av_buffer_ref(avctx->hw_device_ctx);
272 if (!avctx->hw_frames_ctx) {
274 AMF_GOTO_FAIL_IF_FALSE(avctx, !!avctx->hw_frames_ctx, AVERROR(ENOMEM), "av_hwframe_ctx_alloc failed\n");
275 }
276 } else {
278 AMF_GOTO_FAIL_IF_FALSE(avctx, ret == 0, ret, "Failed to create derived AMF device context: %s\n", av_err2str(ret));
279 }
280 } else {
282 AMF_GOTO_FAIL_IF_FALSE(avctx, ret == 0, ret, "Failed to create hardware device context (AMF) : %s\n", av_err2str(ret));
283 }
284 if ((ret = amf_init_decoder(avctx)) == 0) {
285 AVHWDeviceContext *hw_device_ctx = (AVHWDeviceContext*)ctx->device_ctx_ref->data;
286 AVAMFDeviceContext *amf_device_ctx = (AVAMFDeviceContext*)hw_device_ctx->hwctx;
287 enum AVPixelFormat surf_pix_fmt = AV_PIX_FMT_NONE;
288
289 if (amf_legacy_driver_no_bitness_detect(amf_device_ctx)) {
290 // if bitness detection is not supported in legacy driver use format from container
291 switch (avctx->pix_fmt) {
294 surf_pix_fmt = AV_PIX_FMT_NV12; break;
296 surf_pix_fmt = AV_PIX_FMT_P010; break;
297 }
298 } else {
299 AMFVariantStruct format_var = {0};
300
301 ret = ctx->decoder->pVtbl->GetProperty(ctx->decoder, AMF_VIDEO_DECODER_OUTPUT_FORMAT, &format_var);
302 AMF_GOTO_FAIL_IF_FALSE(avctx, ret == AMF_OK, AVERROR(EINVAL), "Failed to get output format (AMF) : %d\n", ret);
303
304 surf_pix_fmt = av_amf_to_av_format(format_var.int64Value);
305 }
306 if (avctx->hw_frames_ctx)
307 {
308 // this values should be set for avcodec_open2
309 // will be updated after header decoded if not true.
310 if (surf_pix_fmt == AV_PIX_FMT_NONE)
311 surf_pix_fmt = AV_PIX_FMT_NV12; // for older drivers
312 int frames_w = 0;
313 int frames_h = 0;
314
315 if (avctx->coded_width > 0 && avctx->coded_height > 0) {
316 frames_w = avctx->coded_width;
317 frames_h = avctx->coded_height;
318 } else if (avctx->width > 0 && avctx->height > 0) {
319 frames_w = avctx->width;
320 frames_h = avctx->height;
321 } else {
322 frames_w = 1280;
323 frames_h = 720;
324 }
325 ret = amf_init_frames_context(avctx, surf_pix_fmt, frames_w, frames_h);
326 AMF_GOTO_FAIL_IF_FALSE(avctx, ret == 0, ret, "Failed to init frames context (AMF) : %s\n", av_err2str(ret));
327 }
328 else
329 avctx->pix_fmt = surf_pix_fmt;
330
331 return 0;
332 }
333fail:
334 amf_decode_close(avctx);
335 return ret;
336}
337
339{
340 return pri != AVCOL_PRI_UNSPECIFIED && pri != AVCOL_PRI_RESERVED0 &&
342}
343
345{
346 return trc != AVCOL_TRC_UNSPECIFIED && trc != AVCOL_TRC_RESERVED0 &&
348}
349
350static enum AVColorPrimaries amf_to_av_primaries(enum AMF_COLOR_PRIMARIES_ENUM pri)
351{
352 enum AVColorPrimaries avpri = (enum AVColorPrimaries)pri;
353
354 switch (pri) {
355 case AMF_COLOR_PRIMARIES_UNDEFINED:
356 case AMF_COLOR_PRIMARIES_UNSPECIFIED:
357 case AMF_COLOR_PRIMARIES_RESERVED:
359 default:
360 if (amf_color_primaries_valid(avpri))
361 return avpri;
363 }
364}
365
366static enum AVColorTransferCharacteristic amf_to_av_trc(enum AMF_COLOR_TRANSFER_CHARACTERISTIC_ENUM trc)
367{
369
370 switch (trc) {
371 case AMF_COLOR_TRANSFER_CHARACTERISTIC_UNDEFINED:
372 case AMF_COLOR_TRANSFER_CHARACTERISTIC_UNSPECIFIED:
373 case AMF_COLOR_TRANSFER_CHARACTERISTIC_RESERVED:
375 default:
376 if (amf_color_trc_valid(avtrc))
377 return avtrc;
379 }
380}
381
382static enum AVColorRange amf_to_av_range(enum AMF_COLOR_RANGE_ENUM range)
383{
384 switch (range) {
385 case AMF_COLOR_RANGE_FULL:
386 return AVCOL_RANGE_JPEG;
387 case AMF_COLOR_RANGE_STUDIO:
388 return AVCOL_RANGE_MPEG;
389 default:
391 }
392}
393
394static enum AVColorSpace amf_to_av_colorspace(enum AMF_VIDEO_CONVERTER_COLOR_PROFILE_ENUM profile)
395{
396 switch (profile) {
397 case AMF_VIDEO_CONVERTER_COLOR_PROFILE_601:
398 case AMF_VIDEO_CONVERTER_COLOR_PROFILE_FULL_601:
399 return AVCOL_SPC_SMPTE170M;
400 case AMF_VIDEO_CONVERTER_COLOR_PROFILE_709:
401 case AMF_VIDEO_CONVERTER_COLOR_PROFILE_FULL_709:
402 return AVCOL_SPC_BT709;
403 case AMF_VIDEO_CONVERTER_COLOR_PROFILE_2020:
404 case AMF_VIDEO_CONVERTER_COLOR_PROFILE_FULL_2020:
406 default:
408 }
409}
410
411static void amf_read_surface_color(AVCodecContext *avctx, AMFSurface *surface,
412 AVFrame *frame)
413{
414 AMFVariantStruct var = {0};
415 AMF_RESULT res;
418 enum AVColorSpace colorspace = avctx->colorspace;
419 enum AVColorRange range = avctx->color_range;
420
421 res = surface->pVtbl->GetProperty(surface, AMF_VIDEO_DECODER_COLOR_PRIMARIES, &var);
422 if (res == AMF_OK)
423 primaries = amf_to_av_primaries((enum AMF_COLOR_PRIMARIES_ENUM)var.int64Value);
424 AMFVariantClear(&var);
425
426 res = surface->pVtbl->GetProperty(surface, AMF_VIDEO_DECODER_COLOR_TRANSFER_CHARACTERISTIC, &var);
427 if (res == AMF_OK)
428 trc = amf_to_av_trc((enum AMF_COLOR_TRANSFER_CHARACTERISTIC_ENUM)var.int64Value);
429 AMFVariantClear(&var);
430
431 res = surface->pVtbl->GetProperty(surface, AMF_VIDEO_DECODER_COLOR_PROFILE, &var);
432 if (res == AMF_OK)
433 colorspace = amf_to_av_colorspace((enum AMF_VIDEO_CONVERTER_COLOR_PROFILE_ENUM)var.int64Value);
434 AMFVariantClear(&var);
435
437 colorspace != AVCOL_SPC_UNSPECIFIED) {
438 res = surface->pVtbl->GetProperty(surface, AMF_VIDEO_DECODER_COLOR_RANGE, &var);
439 if (res == AMF_OK)
440 range = amf_to_av_range((enum AMF_COLOR_RANGE_ENUM)var.int64Value);
441 AMFVariantClear(&var);
442 }
443 avctx->color_primaries = primaries;
444 avctx->color_trc = trc;
445 avctx->colorspace = colorspace;
446 avctx->color_range = range;
447
448 frame->color_primaries = primaries;
449 frame->color_trc = trc;
450 frame->colorspace = colorspace;
451 frame->color_range = range;
452}
453
454static AMF_RESULT amf_get_property_buffer(AMFData *object, const wchar_t *name, AMFBuffer **val)
455{
456 AMF_RESULT res;
457 AMFVariantStruct var;
458 res = AMFVariantInit(&var);
459 if (res == AMF_OK) {
460 res = object->pVtbl->GetProperty(object, name, &var);
461 if (res == AMF_OK) {
462 if (var.type == AMF_VARIANT_INTERFACE) {
463 AMFGuid guid_AMFBuffer = IID_AMFBuffer();
464 AMFInterface *amf_interface = AMFVariantInterface(&var);
465 res = amf_interface->pVtbl->QueryInterface(amf_interface, &guid_AMFBuffer, (void**)val);
466 } else {
467 res = AMF_INVALID_DATA_TYPE;
468 }
469 }
470 AMFVariantClear(&var);
471 }
472 return res;
473}
474
475static int amf_attach_hdr_metadata(AVCodecContext *avctx, AMFSurface *surface, AVFrame *frame)
476{
477 AMFBuffer *hdrmeta_buffer = NULL;
478 AMFHDRMetadata *hdrmeta;
479 AMF_RESULT res;
480 int ret;
481
482 if (frame->color_trc != AVCOL_TRC_SMPTE2084)
483 return 0;
484
485 res = amf_get_property_buffer((AMFData *)surface, AMF_VIDEO_DECODER_HDR_METADATA,
486 &hdrmeta_buffer);
487 if (!hdrmeta_buffer)
488 return 0;
489
490 if (res != AMF_OK) {
491 hdrmeta_buffer->pVtbl->Release(hdrmeta_buffer);
492 return AVERROR(EINVAL);
493 }
494
495 hdrmeta = (AMFHDRMetadata *)hdrmeta_buffer->pVtbl->GetNative(hdrmeta_buffer);
496 if (!hdrmeta) {
497 hdrmeta_buffer->pVtbl->Release(hdrmeta_buffer);
498 return AVERROR(EINVAL);
499 }
500
502 hdrmeta_buffer->pVtbl->Release(hdrmeta_buffer);
503 return ret;
504}
505
507{
509 AMFVariantStruct size_var = {0};
510 AMF_RESULT res = AMF_OK;
511
512 res = ctx->decoder->pVtbl->GetProperty(ctx->decoder, AMF_VIDEO_DECODER_CURRENT_SIZE, &size_var);
513 if (res == AMF_OK && size_var.sizeValue.width > 0 && size_var.sizeValue.height > 0) {
514 avctx->width = size_var.sizeValue.width;
515 avctx->height = size_var.sizeValue.height;
516 avctx->coded_width = size_var.sizeValue.width;
517 avctx->coded_height = size_var.sizeValue.height;
518
519 ctx->dimensions_initialized = 1;
520
521 av_log(avctx, AV_LOG_DEBUG, "AMF: detected initial decoder size %dx%d\n", avctx->width, avctx->height);
522 }
523}
524
525static int amf_amfsurface_to_avframe(AVCodecContext *avctx, AMFSurface* surface, AVFrame *frame)
526{
527 AMFVariantStruct var = {0};
528 AMFPlane *plane;
529 int i;
530 int ret;
531 int format_amf;
532
533 if (!((AMFDecoderContext *)avctx->priv_data)->dimensions_initialized)
534 amf_init_dimensions(avctx);
535
536 if (avctx->hw_device_ctx && ((AVHWDeviceContext*)avctx->hw_device_ctx->data)->type == AV_HWDEVICE_TYPE_AMF) {
537 AVHWFramesContext *frames_ctx;
538 enum AVPixelFormat sw_format;
539 int width, height;
540
541 frames_ctx = avctx->hw_frames_ctx ?
543 sw_format = av_amf_to_av_format(surface->pVtbl->GetFormat(surface));
544 plane = surface->pVtbl->GetPlaneAt(surface, 0);
545 if (!plane || plane->pVtbl->GetWidth(plane) <= 0 || plane->pVtbl->GetHeight(plane) <= 0)
546 return AVERROR_EXTERNAL;
547 width = FFMAX(plane->pVtbl->GetWidth(plane), avctx->width);
548 height = FFMAX(plane->pVtbl->GetHeight(plane), avctx->height);
549 if (!frames_ctx || sw_format != frames_ctx->sw_format ||
550 width > frames_ctx->width || height > frames_ctx->height) {
551 ret = amf_reinit_frames_context(avctx, sw_format, width, height);
552 if (ret < 0)
553 return ret;
554 }
555
556 // prepare frame similar to ff_get_buffer(avctx, frame, AV_GET_BUFFER_FLAG_REF);
557
559 if (ret < 0)
560 return ret;
561
562 avctx->sw_pix_fmt = avctx->pix_fmt;
563
565 if (ret < 0)
566 return ret;
567 frame->width = avctx->width;
568 frame->height = avctx->height;
569
570 ////
571 frame->buf[0] = av_buffer_create((uint8_t *)surface, sizeof(surface),
572 amf_free_amfsurface, (void*)avctx,
574 AMF_RETURN_IF_FALSE(avctx, !!frame->buf[0], AVERROR(ENOMEM), "av_buffer_create for amf surface failed.");
575
576 frame->data[0] = (uint8_t *)surface;
578 format_amf = surface->pVtbl->GetFormat(surface);
579 avctx->sw_pix_fmt = av_amf_to_av_format(format_amf);
580 frame->hw_frames_ctx = av_buffer_ref(avctx->hw_frames_ctx);
581 } else {
582 ret = surface->pVtbl->Convert(surface, AMF_MEMORY_HOST);
583 AMF_RETURN_IF_FALSE(avctx, ret == AMF_OK, AVERROR_UNKNOWN, "Convert(amf::AMF_MEMORY_HOST) failed with error %d\n", ret);
584
585 for (i = 0; i < surface->pVtbl->GetPlanesCount(surface); i++) {
586 plane = surface->pVtbl->GetPlaneAt(surface, i);
587 frame->data[i] = plane->pVtbl->GetNative(plane);
588 frame->linesize[i] = plane->pVtbl->GetHPitch(plane);
589 }
590
591 frame->buf[0] = av_buffer_create((uint8_t *)surface, sizeof(surface),
592 amf_free_amfsurface, (void*)avctx,
594 AMF_RETURN_IF_FALSE(avctx, !!frame->buf[0], AVERROR(ENOMEM), "av_buffer_create for amf surface failed.");
595
596 format_amf = surface->pVtbl->GetFormat(surface);
597 frame->format = av_amf_to_av_format(format_amf);
598 }
599
600 frame->width = avctx->width;
601 frame->height = avctx->height;
602
603 frame->pts = surface->pVtbl->GetPts(surface);
604
605 surface->pVtbl->GetProperty(surface, L"FFMPEG:dts", &var);
606 frame->pkt_dts = var.int64Value;
607
608 frame->duration = surface->pVtbl->GetDuration(surface);
609 if (frame->duration < 0)
610 frame->duration = 0;
611
612 amf_read_surface_color(avctx, surface, frame);
613
614 ret = amf_attach_hdr_metadata(avctx, surface, frame);
615 if (ret < 0)
616 return ret;
617
618 return 0;
619}
620
622{
624 AMF_RESULT ret = AMF_OK;
625 AMFSurface *surface = NULL;
626 AMFData *data_out = NULL;
627
628 ret = ctx->decoder->pVtbl->QueryOutput(ctx->decoder, &data_out);
629 if (ret != AMF_OK && ret != AMF_REPEAT) {
630 return ret;
631 }
632 if (data_out == NULL) {
633 return AMF_REPEAT;
634 }
635
636 if (data_out) {
637 AMFGuid guid = IID_AMFSurface();
638 data_out->pVtbl->QueryInterface(data_out, &guid, (void**)&surface); // query for buffer interface
639 data_out->pVtbl->Release(data_out);
640 data_out = NULL;
641 }
642
643 ret = amf_amfsurface_to_avframe(avctx, surface, frame);
644 AMF_GOTO_FAIL_IF_FALSE(avctx, ret >= 0, AMF_FAIL, "Failed to convert AMFSurface to AVFrame = %d\n", ret);
645 return AMF_OK;
646fail:
647
648 if (surface) {
649 surface->pVtbl->Release(surface);
650 surface = NULL;
651 }
652 return ret;
653}
654
655static AMF_RESULT amf_update_buffer_properties(AVCodecContext *avctx, AMFBuffer* buffer, const AVPacket* pkt)
656{
657 AMF_RESULT res;
658
659 AMF_RETURN_IF_FALSE(avctx, buffer != NULL, AMF_INVALID_ARG, "update_buffer_properties() - buffer not passed in");
660 AMF_RETURN_IF_FALSE(avctx, pkt != NULL, AMF_INVALID_ARG, "update_buffer_properties() - packet not passed in");
661 buffer->pVtbl->SetPts(buffer, pkt->pts);
662 buffer->pVtbl->SetDuration(buffer, pkt->duration);
663 AMF_ASSIGN_PROPERTY_INT64(res, buffer, L"FFMPEG:dts", pkt->dts);
664 if (res != AMF_OK)
665 av_log(avctx, AV_LOG_VERBOSE, "Failed to assign dts value.");
666 return AMF_OK;
667}
668
669static AMF_RESULT amf_buffer_from_packet(AVCodecContext *avctx, const AVPacket* pkt, AMFBuffer** buffer)
670{
672 AVHWDeviceContext *hw_device_ctx = (AVHWDeviceContext*)ctx->device_ctx_ref->data;
673 AVAMFDeviceContext *amf_device_ctx = (AVAMFDeviceContext *)hw_device_ctx->hwctx;
674 AMFContext *ctxt = amf_device_ctx->context;
675 void *mem;
676 AMF_RESULT err;
677 AMFBuffer *buf = NULL;
678
679 AMF_RETURN_IF_FALSE(ctxt, pkt != NULL, AMF_INVALID_ARG, "amf_buffer_from_packet() - packet not passed in");
680 AMF_RETURN_IF_FALSE(ctxt, buffer != NULL, AMF_INVALID_ARG, "amf_buffer_from_packet() - buffer pointer not passed in");
681
682 err = ctxt->pVtbl->AllocBuffer(ctxt, AMF_MEMORY_HOST, pkt->size + AV_INPUT_BUFFER_PADDING_SIZE, buffer);
683 AMF_RETURN_IF_FALSE(ctxt, err == AMF_OK, err, "amf_buffer_from_packet() - failed");
684 buf = *buffer;
685 err = buf->pVtbl->SetSize(buf, pkt->size);
686 AMF_RETURN_IF_FALSE(ctxt, err == AMF_OK, err, "amf_buffer_from_packet() - SetSize failed");
687 // get the memory location and check the buffer was indeed allocated
688 mem = buf->pVtbl->GetNative(buf);
689 AMF_RETURN_IF_FALSE(ctxt, mem != NULL, AMF_INVALID_POINTER, "amf_buffer_from_packet() - GetNative failed");
690
691 // copy the packet memory and clear data padding
692 memcpy(mem, pkt->data, pkt->size);
693 memset((amf_int8*)(mem)+pkt->size, 0, AV_INPUT_BUFFER_PADDING_SIZE);
694
695 return amf_update_buffer_properties(avctx, buf, pkt);
696}
697
698static int amf_decode_frame(AVCodecContext *avctx, struct AVFrame *frame)
699{
701 AMFBuffer *buf;
702 AMF_RESULT res;
703 int got_frame = 0;
704 AVPacket *avpkt = ctx->in_pkt;
705
706 if (!ctx->decoder)
707 return AVERROR(EINVAL);
708
709 // get packet if needed
710 if(!ctx->drain){
711 if(ctx->resolution_changed)
712 ctx->resolution_changed = 0;
713 else{
714 int ret;
715 av_packet_unref(avpkt);
716 ret = ff_decode_get_packet(avctx, avpkt);
717 if (ret < 0 && ret != AVERROR_EOF)
718 return ret;
719 if (ret == AVERROR_EOF) {
720 //nothing to consume, start external drain
721 ctx->decoder->pVtbl->Drain(ctx->decoder);
722 ctx->drain = 1;
723 }
724 }
725 }
726
727 if(!ctx->drain){
728 // submit frame
729 res = amf_buffer_from_packet(avctx, avpkt, &buf);
730 AMF_RETURN_IF_FALSE(avctx, res == AMF_OK, 0, "Cannot convert AVPacket to AMFbuffer");
731 do{
732 res = ctx->decoder->pVtbl->SubmitInput(ctx->decoder, (AMFData*) buf);
733 if(res == AMF_DECODER_NO_FREE_SURFACES)
734 {
735 av_usleep(100);
736 }
737 } while (res == AMF_DECODER_NO_FREE_SURFACES);
738
739 buf->pVtbl->Release(buf);
740
741 if(res == AMF_DECODER_NO_FREE_SURFACES) {
742 // input is not consumed, need to QueryOutput and submit again
743 av_log(avctx, AV_LOG_VERBOSE, "SubmitInput() returned NO_FREE_SURFACES and came out of loop - should never happen\n");
744 res = AMF_OK;
745 } else if (res == AMF_RESOLUTION_CHANGED) {
746 //input is not consumed, start internal drain
747 ctx->decoder->pVtbl->Drain(ctx->decoder);
748 ctx->drain = 1;
749 // process resolution_changed when internal drain is complete
750 ctx->resolution_changed = 1;
751 res = AMF_OK;
752 } else if (res != AMF_OK && res != AMF_NEED_MORE_INPUT && res != AMF_REPEAT) {
753 av_log(avctx, AV_LOG_ERROR, "SubmitInput() returned error %d\n", res);
754 return AVERROR(EINVAL);
755 }
756 }
757
758 res = amf_receive_frame(avctx, frame);
759 if (res == AMF_OK)
760 got_frame = 1;
761 else if (res == AMF_REPEAT)
762 // decoder has no output yet
763 res = AMF_OK;
764 else if (res == AMF_EOF) {
765 // drain is complete
766 ctx->drain = 0;
767 if(ctx->resolution_changed){
768 // re-initialze decoder
769 AMFVariantStruct size_var = {0};
770 AMFVariantStruct format_var = {0};
771 res = ctx->decoder->pVtbl->GetProperty(ctx->decoder, AMF_VIDEO_DECODER_CURRENT_SIZE, &size_var);
772 if (res != AMF_OK) {
773 return AVERROR(EINVAL);
774 }
775
776 avctx->width = size_var.sizeValue.width;
777 avctx->height = size_var.sizeValue.height;
778 avctx->coded_width = size_var.sizeValue.width;
779 avctx->coded_height = size_var.sizeValue.height;
780 res = ctx->decoder->pVtbl->ReInit(ctx->decoder, avctx->width, avctx->height);
781 if (res != AMF_OK) {
782 av_log(avctx, AV_LOG_ERROR, "ReInit() returned %d\n", res);
783 return AVERROR(EINVAL);
784 }
785 res = ctx->decoder->pVtbl->GetProperty(ctx->decoder, AMF_VIDEO_DECODER_OUTPUT_FORMAT, &format_var);
786 if (res != AMF_OK) {
787 return AVERROR(EINVAL);
788 }
789 int ret = amf_reinit_frames_context(avctx, av_amf_to_av_format(format_var.int64Value), avctx->coded_width, avctx->coded_height);
790 if (ret < 0)
791 return ret;
792 } else
793 return AVERROR_EOF;
794 } else {
795 av_log(avctx, AV_LOG_ERROR, "Unknown result from QueryOutput %d\n", res);
796 }
797 return got_frame ? 0 : AVERROR(EAGAIN);
798}
799
801{
803 ctx->decoder->pVtbl->Flush(ctx->decoder);
804}
805
806#define OFFSET(x) offsetof(AMFDecoderContext, x)
807#define VD AV_OPT_FLAG_VIDEO_PARAM | AV_OPT_FLAG_DECODING_PARAM
808
809static const AVOption options[] = {
810 // Decoder mode
811 { "decoder_mode", "Decoder mode", OFFSET(decoder_mode), AV_OPT_TYPE_INT, { .i64 = -1 }, -1, AMF_VIDEO_DECODER_MODE_LOW_LATENCY, VD, "decoder_mode" },
812 { "regular", "DPB delay is based on number of reference frames + 1", 0, AV_OPT_TYPE_CONST, { .i64 = AMF_VIDEO_DECODER_MODE_REGULAR }, 0, 0, VD, "decoder_mode" },
813 { "compliant", "DPB delay is based on profile - up to 16", 0, AV_OPT_TYPE_CONST, { .i64 = AMF_VIDEO_DECODER_MODE_COMPLIANT }, 0, 0, VD, "decoder_mode" },
814 { "low_latency", "DPB delay is 0", 0, AV_OPT_TYPE_CONST, { .i64 = AMF_VIDEO_DECODER_MODE_LOW_LATENCY }, 0, 0, VD, "decoder_mode" },
815
816 // Timestamp mode
817 { "timestamp_mode", "Timestamp mode", OFFSET(timestamp_mode), AV_OPT_TYPE_INT, { .i64 = AMF_TS_SORT }, -1, AMF_TS_DECODE, VD, "timestamp_mode" },
818 { "presentation", "Preserve timestamps from input to output", 0, AV_OPT_TYPE_CONST, { .i64 = AMF_TS_PRESENTATION }, 0, 0, VD, "timestamp_mode" },
819 { "sort", "Resort PTS list", 0, AV_OPT_TYPE_CONST, { .i64 = AMF_TS_SORT }, 0, 0, VD, "timestamp_mode" },
820 { "decode", "Decode order", 0, AV_OPT_TYPE_CONST, { .i64 = AMF_TS_DECODE }, 0, 0, VD, "timestamp_mode" },
821
822 // Reference frame management
823 { "surface_pool_size", "Number of surfaces in the decode pool", OFFSET(surface_pool_size), AV_OPT_TYPE_INT, { .i64 = -1 }, -1, INT_MAX, VD, NULL },
824 { "dpb_size", "Minimum number of surfaces for reordering", OFFSET(dpb_size), AV_OPT_TYPE_INT, { .i64 = -1 }, -1, 32, VD, NULL },
825
826 { "lowlatency", "Low latency", OFFSET(lowlatency), AV_OPT_TYPE_INT, { .i64 = -1 }, -1, 1, VD, NULL },
827 { "smart_access_video", "Smart Access Video", OFFSET(smart_access_video), AV_OPT_TYPE_INT, { .i64 = -1 }, -1, 1, VD, NULL },
828 { "skip_transfer_sav", "Skip transfer on another GPU when SAV enabled", OFFSET(skip_transfer_sav), AV_OPT_TYPE_INT, { .i64 = -1 }, -1, 1, VD, NULL },
829 { "copy_output", "Copy Output", OFFSET(copy_output), AV_OPT_TYPE_INT, { .i64 = -1 }, -1, 1, VD, NULL },
830
831 { NULL }
832};
833
834static const AVClass amf_decode_class = {
835 .class_name = "amf",
836 .item_name = av_default_item_name,
837 .option = options,
838 .version = LIBAVUTIL_VERSION_INT,
839};
840
841#define DEFINE_AMF_DECODER(x, X, bsf_name) \
842const FFCodec ff_##x##_amf_decoder = { \
843 .p.name = #x "_amf", \
844 CODEC_LONG_NAME(#X " AMD AMF video decoder"), \
845 .priv_data_size = sizeof(AMFDecoderContext), \
846 .p.type = AVMEDIA_TYPE_VIDEO, \
847 .p.id = AV_CODEC_ID_##X, \
848 .init = amf_decode_init, \
849 FF_CODEC_RECEIVE_FRAME_CB(amf_decode_frame), \
850 .flush = amf_decode_flush, \
851 .close = amf_decode_close, \
852 .bsfs = bsf_name, \
853 .p.capabilities = AV_CODEC_CAP_HARDWARE | AV_CODEC_CAP_DELAY | AV_CODEC_CAP_AVOID_PROBING, \
854 .p.priv_class = &amf_decode_class, \
855 .hw_configs = amf_hw_configs, \
856 .p.wrapper_name = "amf", \
857 .caps_internal = FF_CODEC_CAP_NOT_INIT_THREADSAFE, \
858}; \
859
860DEFINE_AMF_DECODER(h264, H264, "h264_mp4toannexb")
861DEFINE_AMF_DECODER(hevc, HEVC, NULL)
862DEFINE_AMF_DECODER(vp9, VP9, NULL)
863DEFINE_AMF_DECODER(av1, AV1, NULL)
static double val(void *priv, double ch)
Definition aeval.c:77
static int amf_legacy_driver_no_bitness_detect(AVAMFDeviceContext *amf_device_ctx)
Definition amfdec.c:64
static enum AVColorTransferCharacteristic amf_to_av_trc(enum AMF_COLOR_TRANSFER_CHARACTERISTIC_ENUM trc)
Definition amfdec.c:366
static AMF_RESULT amf_update_buffer_properties(AVCodecContext *avctx, AMFBuffer *buffer, const AVPacket *pkt)
Definition amfdec.c:655
#define AMF_VIDEO_DECODER_OUTPUT_FORMAT
Definition amfdec.c:43
static int amf_amfsurface_to_avframe(AVCodecContext *avctx, AMFSurface *surface, AVFrame *frame)
Definition amfdec.c:525
static void amf_init_dimensions(AVCodecContext *avctx)
Definition amfdec.c:506
static int amf_init_frames_context(AVCodecContext *avctx, int sw_format, int new_width, int new_height)
Definition amfdec.c:213
static int amf_init_decoder(AVCodecContext *avctx)
Definition amfdec.c:73
static int amf_color_trc_valid(enum AVColorTransferCharacteristic trc)
Definition amfdec.c:344
static int amf_attach_hdr_metadata(AVCodecContext *avctx, AMFSurface *surface, AVFrame *frame)
Definition amfdec.c:475
static void amf_read_surface_color(AVCodecContext *avctx, AMFSurface *surface, AVFrame *frame)
Definition amfdec.c:411
static enum AVColorPrimaries amf_to_av_primaries(enum AMF_COLOR_PRIMARIES_ENUM pri)
Definition amfdec.c:350
static int amf_decode_frame(AVCodecContext *avctx, struct AVFrame *frame)
Definition amfdec.c:698
static AMF_RESULT amf_receive_frame(AVCodecContext *avctx, AVFrame *frame)
Definition amfdec.c:621
#define DEFINE_AMF_DECODER(x, X, bsf_name)
Definition amfdec.c:841
static void amf_decode_flush(AVCodecContext *avctx)
Definition amfdec.c:800
static enum AVColorSpace amf_to_av_colorspace(enum AMF_VIDEO_CONVERTER_COLOR_PROFILE_ENUM profile)
Definition amfdec.c:394
static AMF_RESULT amf_buffer_from_packet(AVCodecContext *avctx, const AVPacket *pkt, AMFBuffer **buffer)
Definition amfdec.c:669
static int amf_decode_close(AVCodecContext *avctx)
Definition amfdec.c:197
static void amf_free_amfsurface(void *opaque, uint8_t *data)
Definition amfdec.c:58
static const AVCodecHWConfigInternal *const amf_hw_configs[]
Definition amfdec.c:45
#define VD
Definition amfdec.c:807
static const AVClass amf_decode_class
Definition amfdec.c:834
static int amf_color_primaries_valid(enum AVColorPrimaries pri)
Definition amfdec.c:338
#define OFFSET(x)
Definition amfdec.c:806
static enum AVColorRange amf_to_av_range(enum AMF_COLOR_RANGE_ENUM range)
Definition amfdec.c:382
static int amf_reinit_frames_context(AVCodecContext *avctx, int sw_format, int new_width, int new_height)
Definition amfdec.c:243
static AMF_RESULT amf_get_property_buffer(AMFData *object, const wchar_t *name, AMFBuffer **val)
Definition amfdec.c:454
static int amf_decode_init(AVCodecContext *avctx)
Definition amfdec.c:257
#define AMF_RETURN_IF_FALSE(avctx, exp, ret_value,...)
Error handling helper.
Definition amfenc.h:195
static AVFormatContext * ctx
#define L(x)
Definition vpx_arith.h:36
#define FF_THREAD_FRAME
Decode more than one frame at once.
Definition avcodec.h:1600
#define i(width, name, range_min, range_max)
Definition cbs_h264.c:63
#define NULL
Definition coverity.c:32
int ff_decode_frame_props(AVCodecContext *avctx, AVFrame *frame)
Set various frame properties from the codec context / packet data.
Definition decode.c:1656
int ff_attach_decode_data(AVCodecContext *avctx, AVFrame *frame)
Definition decode.c:1753
int ff_decode_get_packet(AVCodecContext *avctx, AVPacket *pkt)
Called by decoders to get the next packet for decoding.
Definition decode.c:255
static void ff_decode_get_extradata(const AVCodecContext *avctx, const uint8_t **extradata, int *extradata_size)
Helper function for decoders that may use a BSF that changes extradata.
Definition decode_bsf.h:32
static AVPacket * pkt
static AVFrame * frame
int ret
Definition ffplay.c:391
#define fail
Definition test.h:479
@ AV_OPT_TYPE_CONST
Special option type for declaring named constants.
Definition opt.h:298
@ AV_OPT_TYPE_INT
Underlying C type is int.
Definition opt.h:258
@ AV_CODEC_HW_CONFIG_METHOD_HW_FRAMES_CTX
The codec supports this format via the hw_frames_ctx interface.
Definition codec.h:295
@ AV_CODEC_HW_CONFIG_METHOD_HW_DEVICE_CTX
The codec supports this format via the hw_device_ctx interface.
Definition codec.h:282
@ AV_CODEC_ID_H264
Definition codec_id.h:77
@ AV_CODEC_ID_AV1
Definition codec_id.h:275
@ AV_CODEC_ID_HEVC
Definition codec_id.h:223
@ AV_CODEC_ID_VP9
Definition codec_id.h:217
#define AV_INPUT_BUFFER_PADDING_SIZE
Required number of additionally allocated bytes at the end of the input bitstream for decoding.
Definition defs.h:40
void av_packet_free(AVPacket **pkt)
Free the packet, if the packet is reference counted, it will be unreferenced first.
Definition packet.c:74
void av_packet_unref(AVPacket *pkt)
Wipe the packet.
Definition packet.c:435
AVPacket * av_packet_alloc(void)
Allocate an AVPacket and set its fields to default values.
Definition packet.c:63
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:140
AVBufferRef * av_buffer_ref(const AVBufferRef *buf)
Create a new reference to an AVBuffer.
Definition buffer.c:104
#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:56
#define AVERROR_ENCODER_NOT_FOUND
Encoder not found.
Definition error.h:56
#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_EOF
End of file.
Definition error.h:57
#define av_err2str(errnum)
Convenience macro, the return value should be used only directly in function arguments but never stan...
Definition error.h:122
#define AVERROR(e)
Definition error.h:45
#define AV_LOG_DEBUG
Stuff which is only useful for libav* developers.
Definition log.h:231
#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
const char * av_default_item_name(void *ptr)
Return the context name.
Definition log.c:247
#define LIBAVUTIL_VERSION_INT
Definition version.h:85
static AVBufferRef * hw_device_ctx
Definition hw_decode.c:45
int av_hwdevice_ctx_create(AVBufferRef **pdevice_ref, enum AVHWDeviceType type, const char *device, AVDictionary *opts, int flags)
Open a device of the specified type and create an AVHWDeviceContext for it.
Definition hwcontext.c:673
int av_hwdevice_ctx_create_derived(AVBufferRef **dst_ref_ptr, enum AVHWDeviceType type, AVBufferRef *src_ref, int flags)
Create a new device of the specified type from an existing device.
Definition hwcontext.c:776
int av_hwframe_ctx_init(AVBufferRef *ref)
Finalize the context before use.
Definition hwcontext.c:347
AVBufferRef * av_hwframe_ctx_alloc(AVBufferRef *device_ref_in)
Allocate an AVHWFramesContext tied to a given device context.
Definition hwcontext.c:267
@ AV_HWDEVICE_TYPE_AMF
Definition hwcontext.h:41
int av_amf_attach_hdr_metadata(AVFrame *frame, const AMFHDRMetadata *hdrmeta)
enum AVPixelFormat av_amf_to_av_format(enum AMF_SURFACE_FORMAT fmt)
enum AMF_VIDEO_CONVERTER_COLOR_PROFILE_ENUM av_amf_get_color_profile(enum AVColorRange color_range, enum AVColorSpace color_space)
#define AMF_GOTO_FAIL_IF_FALSE(avctx, exp, ret_value,...)
An API-specific header for AV_HWDEVICE_TYPE_D3D11VA.
An API-specific header for AV_HWDEVICE_TYPE_DXVA2.
#define FFMAX(a, b)
Definition macros.h:47
enum AVColorPrimaries primaries
enum AVColorRange range
const char data[16]
Definition mxf.c:149
int profile
Definition mxfenc.c:2304
const char * av_color_transfer_name(enum AVColorTransferCharacteristic transfer)
Definition pixdesc.c:3851
const char * av_color_primaries_name(enum AVColorPrimaries primaries)
Definition pixdesc.c:3818
#define AV_PIX_FMT_YUV420P10
Definition pixfmt.h:548
AVColorRange
Visual content value range.
Definition pixfmt.h:757
@ AVCOL_RANGE_MPEG
Narrow or limited range content.
Definition pixfmt.h:775
@ AVCOL_RANGE_UNSPECIFIED
Definition pixfmt.h:758
@ AVCOL_RANGE_JPEG
Full range content.
Definition pixfmt.h:792
#define AV_PIX_FMT_P010
Definition pixfmt.h:613
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_YUVJ420P
planar YUV 4:2:0, 12bpp, full scale (JPEG), deprecated in favor of AV_PIX_FMT_YUV420P and setting col...
Definition pixfmt.h:85
@ AV_PIX_FMT_AMF_SURFACE
HW acceleration through AMF.
Definition pixfmt.h:477
AVColorPrimaries
Chromaticity coordinates of the source primaries.
Definition pixfmt.h:647
@ AVCOL_PRI_RESERVED
Definition pixfmt.h:651
@ AVCOL_PRI_UNSPECIFIED
Definition pixfmt.h:650
@ AVCOL_PRI_RESERVED0
Definition pixfmt.h:648
AVColorTransferCharacteristic
Color Transfer Characteristic.
Definition pixfmt.h:677
@ AVCOL_TRC_SMPTE2084
SMPTE ST 2084 for 10-, 12-, 14- and 16-bit systems.
Definition pixfmt.h:694
@ AVCOL_TRC_RESERVED
Definition pixfmt.h:681
@ AVCOL_TRC_UNSPECIFIED
Definition pixfmt.h:680
@ AVCOL_TRC_RESERVED0
Definition pixfmt.h:678
AVColorSpace
YUV colorspace type.
Definition pixfmt.h:711
@ AVCOL_SPC_BT709
also ITU-R BT1361 / IEC 61966-2-4 xvYCC709 / derived in SMPTE RP 177 Annex B
Definition pixfmt.h:713
@ AVCOL_SPC_BT2020_NCL
ITU-R BT2020 non-constant luminance system.
Definition pixfmt.h:722
@ AVCOL_SPC_UNSPECIFIED
Definition pixfmt.h:714
@ AVCOL_SPC_SMPTE170M
also ITU-R BT601-6 525 / ITU-R BT1358 525 / ITU-R BT1700 NTSC / functionally identical to above
Definition pixfmt.h:718
const char * name
Definition qsvenc.c:142
static int copy_output(SANMVideoContext *ctx, int sanm)
Definition sanm.c:2683
AMF decoder context.
Definition amfdec.h:39
This struct is allocated as AVHWDeviceContext.hwctx.
AMFContext * context
AMFFactory * factory
int64_t version
version of AMF runtime
uint8_t * data
The data buffer.
Definition buffer.h:90
Describe the class of an AVClass context structure.
Definition log.h:76
main external API structure.
Definition avcodec.h:443
enum AVPixelFormat pix_fmt
Pixel format, see AV_PIX_FMT_xxx.
Definition avcodec.h:644
int width
picture width / height.
Definition avcodec.h:605
enum AVPixelFormat sw_pix_fmt
Nominal unaccelerated pixel format, see AV_PIX_FMT_xxx.
Definition avcodec.h:651
enum AVColorRange color_range
MPEG vs JPEG YUV range.
Definition avcodec.h:685
enum AVColorPrimaries color_primaries
Chromaticity coordinates of the source primaries.
Definition avcodec.h:658
AVBufferRef * hw_frames_ctx
A reference to the AVHWFramesContext describing the input (for encoding) or output (decoding) frames.
Definition avcodec.h:1477
int active_thread_type
Which multithreading methods are in use by the codec.
Definition avcodec.h:1608
const struct AVCodec * codec
Definition avcodec.h:452
enum AVColorSpace colorspace
YUV colorspace type.
Definition avcodec.h:672
int thread_count
thread count is used to decide how many independent tasks should be passed to execute()
Definition avcodec.h:1589
enum AVColorTransferCharacteristic color_trc
Color Transfer Characteristic.
Definition avcodec.h:665
AVBufferRef * hw_device_ctx
A reference to the AVHWDeviceContext describing the device which will be used by a hardware encoder/d...
Definition avcodec.h:1499
int extra_hw_frames
Video decoding only.
Definition avcodec.h:1522
int extradata_size
Definition avcodec.h:527
int coded_width
Bitstream width / height, may be different from width/height e.g.
Definition avcodec.h:620
void * priv_data
Definition avcodec.h:470
enum AVCodecID id
Definition codec.h:189
This structure describes decoded (raw) audio or video data.
Definition frame.h:479
This struct aggregates all the (hardware/vendor-specific) "high-level" state, i.e.
Definition hwcontext.h:63
enum AVHWDeviceType type
This field identifies the underlying API used for hardware access.
Definition hwcontext.h:75
This struct describes a set or pool of "hardware" frames (i.e.
Definition hwcontext.h:118
enum AVPixelFormat format
The pixel format identifying the underlying HW surface type.
Definition hwcontext.h:200
enum AVPixelFormat sw_format
The pixel format identifying the actual data layout of the hardware frames.
Definition hwcontext.h:213
int initial_pool_size
Initial size of the frame pool.
Definition hwcontext.h:190
int width
The allocated dimensions of the frames in this pool.
Definition hwcontext.h:220
AVOption.
Definition opt.h:428
This structure stores compressed data.
Definition packet.h:587
#define av_log(a,...)
int dpb_size
static char buffer[20]
Definition seek.c:33
#define height
Definition dsp.h:99
#define width
Definition dsp.h:99
int av_usleep(unsigned usec)
Sleep for a period of time.
Definition time.c:93
enum AVCodecID codec_id