FFmpeg: libavcodec/amfdec.c Source File

FFmpeg
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 
19 #include "libavutil/hwcontext_amf.h"
20 #include "libavutil/hwcontext_amf_internal.h"
21 #include "amfdec.h"
22 #include "codec_internal.h"
23 #include "hwconfig.h"
24 #include "libavutil/imgutils.h"
25 #include "libavutil/mem.h"
26 #include "libavutil/time.h"
27 #include "decode.h"
28 #include "decode_bsf.h"
29 #include "libavutil/mastering_display_metadata.h"
30 
31 #if CONFIG_D3D11VA
32 #include "libavutil/hwcontext_d3d11va.h"
33 #endif
34 #if CONFIG_DXVA2
35 #define COBJMACROS
36 #include "libavutil/hwcontext_dxva2.h"
37 #endif
38 
39 #ifdef _WIN32
40 #include "compat/w32dlfcn.h"
41 #else
42 #include <dlfcn.h>
43 #endif
44 //will be in public headers soon
45  #define AMF_VIDEO_DECODER_OUTPUT_FORMAT L"OutputDecodeFormat"
46 
47  static const AVCodecHWConfigInternal *const amf_hw_configs[] = {
48  &(const AVCodecHWConfigInternal) {
49  .public = {
50  .pix_fmt = AV_PIX_FMT_AMF_SURFACE,
51  .methods = AV_CODEC_HW_CONFIG_METHOD_HW_FRAMES_CTX |
52  AV_CODEC_HW_CONFIG_METHOD_HW_DEVICE_CTX,
53  .device_type = AV_HWDEVICE_TYPE_AMF,
54  },
55  .hwaccel = NULL,
56  },
57  NULL
58 };
59 
60  static void amf_free_amfsurface(void *opaque, uint8_t *data)
61 {
62  AMFSurface *surface = (AMFSurface*)(data);
63  surface->pVtbl->Release(surface);
64 }
65 
66  static int amf_legacy_driver_no_bitness_detect(AVAMFDeviceContext *amf_device_ctx)
67 {
68  if( AMF_GET_MAJOR_VERSION(amf_device_ctx->version) <= 1 &&
69  AMF_GET_MINOR_VERSION(amf_device_ctx->version) <= 4 &&
70  AMF_GET_SUBMINOR_VERSION(amf_device_ctx->version) < 36)
71  return 1;
72  return 0;
73 }
74 
75  static int amf_init_decoder(AVCodecContext *avctx)
76 {
77  AMFDecoderContext *ctx = avctx->priv_data;
78  AVHWDeviceContext *hw_device_ctx = (AVHWDeviceContext*)ctx->device_ctx_ref->data;
79  AVAMFDeviceContext *amf_device_ctx = (AVAMFDeviceContext*)hw_device_ctx->hwctx;
80  const wchar_t *codec_id = NULL;
81  AMF_RESULT res;
82  AMFBuffer *buffer;
83  amf_int64 color_profile;
84  int pool_size = 36;
85  // way-around for older drivers that don't support dynamic bitness detection -
86  // define HEVC and VP9 10-bit based on container info
87  int no_bitness_detect = amf_legacy_driver_no_bitness_detect(amf_device_ctx);
88 
89  ctx->drain = 0;
90  ctx->resolution_changed = 0;
91 
92  switch (avctx->codec->id) {
93  case AV_CODEC_ID_H264:
94  codec_id = AMFVideoDecoderUVD_H264_AVC;
95  break;
96  case AV_CODEC_ID_HEVC: {
97  codec_id = AMFVideoDecoderHW_H265_HEVC;
98  if(no_bitness_detect){
99  if(avctx->pix_fmt == AV_PIX_FMT_YUV420P10)
100  codec_id = AMFVideoDecoderHW_H265_MAIN10;
101  }
102  } break;
103  case AV_CODEC_ID_VP9: {
104  codec_id = AMFVideoDecoderHW_VP9;
105  if(no_bitness_detect){
106  if(avctx->pix_fmt == AV_PIX_FMT_YUV420P10)
107  codec_id = AMFVideoDecoderHW_VP9_10BIT;
108  }
109  } break;
110  case AV_CODEC_ID_AV1:
111  codec_id = AMFVideoDecoderHW_AV1;
112  break;
113  default:
114  break;
115  }
116  AMF_RETURN_IF_FALSE(ctx, codec_id != NULL, AVERROR(EINVAL), "Codec %d is not supported\n", avctx->codec->id);
117 
118  res = amf_device_ctx->factory->pVtbl->CreateComponent(amf_device_ctx->factory, amf_device_ctx->context, codec_id, &ctx->decoder);
119  AMF_RETURN_IF_FALSE(ctx, res == AMF_OK, AVERROR_ENCODER_NOT_FOUND, "CreateComponent(%ls) failed with error %d\n", codec_id, res);
120 
121  // Color Metadata
122  /// Color Range (Support for older Drivers)
123  if (avctx->color_range == AVCOL_RANGE_JPEG) {
124  AMF_ASSIGN_PROPERTY_BOOL(res, ctx->decoder, AMF_VIDEO_DECODER_FULL_RANGE_COLOR, 1);
125  } else if (avctx->color_range != AVCOL_RANGE_UNSPECIFIED) {
126  AMF_ASSIGN_PROPERTY_BOOL(res, ctx->decoder, AMF_VIDEO_DECODER_FULL_RANGE_COLOR, 0);
127  }
128  color_profile = AMF_VIDEO_CONVERTER_COLOR_PROFILE_UNKNOWN;
129  switch (avctx->colorspace) {
130  case AVCOL_SPC_SMPTE170M:
131  if (avctx->color_range == AVCOL_RANGE_JPEG) {
132  color_profile = AMF_VIDEO_CONVERTER_COLOR_PROFILE_FULL_601;
133  } else {
134  color_profile = AMF_VIDEO_CONVERTER_COLOR_PROFILE_601;
135  }
136  break;
137  case AVCOL_SPC_BT709:
138  if (avctx->color_range == AVCOL_RANGE_JPEG) {
139  color_profile = AMF_VIDEO_CONVERTER_COLOR_PROFILE_FULL_709;
140  } else {
141  color_profile = AMF_VIDEO_CONVERTER_COLOR_PROFILE_709;
142  }
143  break;
144  case AVCOL_SPC_BT2020_NCL:
145  case AVCOL_SPC_BT2020_CL:
146  if (avctx->color_range == AVCOL_RANGE_JPEG) {
147  color_profile = AMF_VIDEO_CONVERTER_COLOR_PROFILE_FULL_2020;
148  } else {
149  color_profile = AMF_VIDEO_CONVERTER_COLOR_PROFILE_2020;
150  }
151  break;
152  }
153  if (color_profile != AMF_VIDEO_CONVERTER_COLOR_PROFILE_UNKNOWN)
154  AMF_ASSIGN_PROPERTY_INT64(res, ctx->decoder, AMF_VIDEO_DECODER_COLOR_PROFILE, color_profile);
155  if (avctx->color_trc != AVCOL_TRC_UNSPECIFIED)
156  AMF_ASSIGN_PROPERTY_INT64(res, ctx->decoder, AMF_VIDEO_DECODER_COLOR_TRANSFER_CHARACTERISTIC, (amf_int64)avctx->color_trc);
157 
158  if (avctx->color_primaries != AVCOL_PRI_UNSPECIFIED)
159  AMF_ASSIGN_PROPERTY_INT64(res, ctx->decoder, AMF_VIDEO_DECODER_COLOR_PRIMARIES, (amf_int64)avctx->color_primaries);
160 
161  if (ctx->timestamp_mode != -1)
162  AMF_ASSIGN_PROPERTY_INT64(res, ctx->decoder, AMF_TIMESTAMP_MODE, ctx->timestamp_mode);
163  if (ctx->decoder_mode != -1)
164  AMF_ASSIGN_PROPERTY_INT64(res, ctx->decoder, AMF_VIDEO_DECODER_REORDER_MODE, ctx->decoder_mode);
165  if (ctx->dpb_size != -1)
166  AMF_ASSIGN_PROPERTY_INT64(res, ctx->decoder, AMF_VIDEO_DECODER_DPB_SIZE, ctx->dpb_size);
167  if (ctx->lowlatency != -1)
168  AMF_ASSIGN_PROPERTY_INT64(res, ctx->decoder, AMF_VIDEO_DECODER_LOW_LATENCY, ctx->lowlatency);
169  if (ctx->smart_access_video != -1) {
170  AMF_ASSIGN_PROPERTY_INT64(res, ctx->decoder, AMF_VIDEO_DECODER_ENABLE_SMART_ACCESS_VIDEO, ctx->smart_access_video != 0);
171  if (res != AMF_OK) {
172  av_log(avctx, AV_LOG_ERROR, "The Smart Access Video is not supported by AMF decoder.\n");
173  return AVERROR(EINVAL);
174  } else {
175  av_log(avctx, AV_LOG_INFO, "The Smart Access Video (%d) is set.\n", ctx->smart_access_video);
176  // Set low latency mode if Smart Access Video is enabled
177  if (ctx->smart_access_video != 0) {
178  AMF_ASSIGN_PROPERTY_INT64(res, ctx->decoder, AMF_VIDEO_DECODER_LOW_LATENCY, true);
179  av_log(avctx, AV_LOG_INFO, "The Smart Access Video set low latency mode for decoder.\n");
180  }
181  }
182  }
183  if (ctx->skip_transfer_sav != -1)
184  AMF_ASSIGN_PROPERTY_INT64(res, ctx->decoder, AMF_VIDEO_DECODER_SKIP_TRANSFER_SMART_ACCESS_VIDEO, ctx->skip_transfer_sav);
185 
186  if (ctx->copy_output != -1)
187  AMF_ASSIGN_PROPERTY_INT64(res, ctx->decoder, AMF_VIDEO_DECODER_SURFACE_COPY, ctx->copy_output);
188 
189  if (avctx->extradata_size) {
190  const uint8_t *extradata;
191  int extradata_size;
192  ff_decode_get_extradata(avctx, &extradata, &extradata_size);
193  res = amf_device_ctx->context->pVtbl->AllocBuffer(amf_device_ctx->context, AMF_MEMORY_HOST, extradata_size, &buffer);
194  if (res == AMF_OK) {
195  memcpy(buffer->pVtbl->GetNative(buffer), extradata, extradata_size);
196  AMF_ASSIGN_PROPERTY_INTERFACE(res,ctx->decoder, AMF_VIDEO_DECODER_EXTRADATA, buffer);
197  buffer->pVtbl->Release(buffer);
198  buffer = NULL;
199  }
200  }
201  if (ctx->surface_pool_size == -1) {
202  ctx->surface_pool_size = pool_size;
203  if (avctx->extra_hw_frames > 0)
204  ctx->surface_pool_size += avctx->extra_hw_frames;
205  if (avctx->active_thread_type & FF_THREAD_FRAME)
206  ctx->surface_pool_size += avctx->thread_count;
207  }
208 
209  //at the moment, there is such a restriction in AMF.
210  //when it is possible, I will remove this code
211  if (ctx->surface_pool_size > 100)
212  ctx->surface_pool_size = 100;
213 
214  AMF_ASSIGN_PROPERTY_INT64(res, ctx->decoder, AMF_VIDEO_DECODER_SURFACE_POOL_SIZE, ctx->surface_pool_size);
215  res = ctx->decoder->pVtbl->Init(ctx->decoder, AMF_SURFACE_UNKNOWN, avctx->width, avctx->height);
216  if (res != AMF_OK) {
217  av_log(avctx, AV_LOG_ERROR, "Decoder initialization failed with error %d\n", res);
218  return AVERROR(EINVAL);
219  }
220  return 0;
221 }
222 
223  static int amf_decode_close(AVCodecContext *avctx)
224 {
225  AMFDecoderContext *ctx = avctx->priv_data;
226 
227  if (ctx->decoder) {
228  ctx->decoder->pVtbl->Terminate(ctx->decoder);
229  ctx->decoder->pVtbl->Release(ctx->decoder);
230  ctx->decoder = NULL;
231  }
232 
233  av_buffer_unref(&ctx->device_ctx_ref);
234  av_packet_free(&ctx->in_pkt);
235 
236  return 0;
237 }
238 
239  static int amf_init_frames_context(AVCodecContext *avctx, int sw_format, int new_width, int new_height)
240 {
241  int ret;
242  AVHWDeviceContext *hwdev_ctx;
243  AVHWFramesContext *hwframes_ctx;
244  AMFDecoderContext *ctx;
245  if (!avctx->hw_frames_ctx || !avctx->hw_device_ctx)
246  return 0;
247  hwdev_ctx = (AVHWDeviceContext*)avctx->hw_device_ctx->data;
248  hwframes_ctx = (AVHWFramesContext*)avctx->hw_frames_ctx->data;
249  ctx = avctx->priv_data;
250 
251  if (hwdev_ctx->type != AV_HWDEVICE_TYPE_AMF)
252  return 0;
253 
254  hwframes_ctx->width = new_width;
255  hwframes_ctx->height = new_height;
256  hwframes_ctx->format = AV_PIX_FMT_AMF_SURFACE;
257  hwframes_ctx->sw_format = sw_format;
258  hwframes_ctx->initial_pool_size = ctx->surface_pool_size + 8;
259 
260  ret = av_hwframe_ctx_init(avctx->hw_frames_ctx);
261  if (ret < 0) {
262  av_log(NULL, AV_LOG_ERROR, "Error initializing a AMF frame pool\n");
263  av_buffer_unref(&avctx->hw_frames_ctx);
264  return ret;
265  }
266  return 0;
267 }
268 
269  static int amf_decode_init(AVCodecContext *avctx)
270 {
271  AMFDecoderContext *ctx = avctx->priv_data;
272  int ret;
273  ctx->in_pkt = av_packet_alloc();
274  if (!ctx->in_pkt)
275  return AVERROR(ENOMEM);
276 
277  if (avctx->hw_device_ctx && !avctx->hw_frames_ctx) {
278  AVHWDeviceContext *hwdev_ctx;
279  hwdev_ctx = (AVHWDeviceContext*)avctx->hw_device_ctx->data;
280  if (hwdev_ctx->type == AV_HWDEVICE_TYPE_AMF)
281  {
282  ctx->device_ctx_ref = av_buffer_ref(avctx->hw_device_ctx);
283  avctx->hw_frames_ctx = av_hwframe_ctx_alloc(avctx->hw_device_ctx);
284 
285  AMF_GOTO_FAIL_IF_FALSE(avctx, !!avctx->hw_frames_ctx, AVERROR(ENOMEM), "av_hwframe_ctx_alloc failed\n");
286  } else {
287  ret = av_hwdevice_ctx_create_derived(&ctx->device_ctx_ref, AV_HWDEVICE_TYPE_AMF, avctx->hw_device_ctx, 0);
288  AMF_GOTO_FAIL_IF_FALSE(avctx, ret == 0, ret, "Failed to create derived AMF device context: %s\n", av_err2str(ret));
289  }
290  } else {
291  ret = av_hwdevice_ctx_create(&ctx->device_ctx_ref, AV_HWDEVICE_TYPE_AMF, NULL, NULL, 0);
292  AMF_GOTO_FAIL_IF_FALSE(avctx, ret == 0, ret, "Failed to create hardware device context (AMF) : %s\n", av_err2str(ret));
293  }
294  if ((ret = amf_init_decoder(avctx)) == 0) {
295  AVHWDeviceContext *hw_device_ctx = (AVHWDeviceContext*)ctx->device_ctx_ref->data;
296  AVAMFDeviceContext *amf_device_ctx = (AVAMFDeviceContext*)hw_device_ctx->hwctx;
297  enum AVPixelFormat surf_pix_fmt = AV_PIX_FMT_NONE;
298 
299  if(amf_legacy_driver_no_bitness_detect(amf_device_ctx)){
300  // if bitness detection is not supported in legacy driver use format from container
301  switch (avctx->pix_fmt) {
302  case AV_PIX_FMT_YUV420P:
303  case AV_PIX_FMT_YUVJ420P:
304  surf_pix_fmt = AV_PIX_FMT_NV12; break;
305  case AV_PIX_FMT_YUV420P10:
306  surf_pix_fmt = AV_PIX_FMT_P010; break;
307  }
308  }else{
309  AMFVariantStruct format_var = {0};
310 
311  ret = ctx->decoder->pVtbl->GetProperty(ctx->decoder, AMF_VIDEO_DECODER_OUTPUT_FORMAT, &format_var);
312  AMF_GOTO_FAIL_IF_FALSE(avctx, ret == AMF_OK, AVERROR(EINVAL), "Failed to get output format (AMF) : %d\n", ret);
313 
314  surf_pix_fmt = av_amf_to_av_format(format_var.int64Value);
315  }
316  if(avctx->hw_frames_ctx)
317  {
318  // this values should be set for avcodec_open2
319  // will be updated after header decoded if not true.
320  if(surf_pix_fmt == AV_PIX_FMT_NONE)
321  surf_pix_fmt = AV_PIX_FMT_NV12; // for older drivers
322  if (!avctx->coded_width)
323  avctx->coded_width = 1280;
324  if (!avctx->coded_height)
325  avctx->coded_height = 720;
326  ret = amf_init_frames_context(avctx, surf_pix_fmt, avctx->coded_width, avctx->coded_height);
327  AMF_GOTO_FAIL_IF_FALSE(avctx, ret == 0, ret, "Failed to init frames context (AMF) : %s\n", av_err2str(ret));
328  }
329  else
330  avctx->pix_fmt = surf_pix_fmt;
331 
332  return 0;
333  }
334 fail:
335  amf_decode_close(avctx);
336  return ret;
337 }
338 
339  static AMF_RESULT amf_get_property_buffer(AMFData *object, const wchar_t *name, AMFBuffer **val)
340 {
341  AMF_RESULT res;
342  AMFVariantStruct var;
343  res = AMFVariantInit(&var);
344  if (res == AMF_OK) {
345  res = object->pVtbl->GetProperty(object, name, &var);
346  if (res == AMF_OK) {
347  if (var.type == AMF_VARIANT_INTERFACE) {
348  AMFGuid guid_AMFBuffer = IID_AMFBuffer();
349  AMFInterface *amf_interface = AMFVariantInterface(&var);
350  res = amf_interface->pVtbl->QueryInterface(amf_interface, &guid_AMFBuffer, (void**)val);
351  } else {
352  res = AMF_INVALID_DATA_TYPE;
353  }
354  }
355  AMFVariantClear(&var);
356  }
357  return res;
358 }
359 
360  static int amf_amfsurface_to_avframe(AVCodecContext *avctx, AMFSurface* surface, AVFrame *frame)
361 {
362  AMFVariantStruct var = {0};
363  AMFPlane *plane;
364  int i;
365  int ret;
366  int format_amf;
367 
368  if (avctx->hw_device_ctx && ((AVHWDeviceContext*)avctx->hw_device_ctx->data)->type == AV_HWDEVICE_TYPE_AMF) {
369  // prepare frame similar to ff_get_buffer(avctx, frame, AV_GET_BUFFER_FLAG_REF);
370 
371  ret = ff_decode_frame_props(avctx, frame);
372  if (ret < 0)
373  return ret;
374 
375  avctx->sw_pix_fmt = avctx->pix_fmt;
376 
377  ret = ff_attach_decode_data(frame);
378  if (ret < 0)
379  return ret;
380  frame->width = avctx->width;
381  frame->height = avctx->height;
382 
383  ////
384  frame->buf[0] = av_buffer_create((uint8_t *)surface, sizeof(surface),
385  amf_free_amfsurface, (void*)avctx,
386  AV_BUFFER_FLAG_READONLY);
387  AMF_RETURN_IF_FALSE(avctx, !!frame->buf[0], AVERROR(ENOMEM), "av_buffer_create for amf surface failed.");
388 
389  frame->data[0] = (uint8_t *)surface;
390  frame->format = AV_PIX_FMT_AMF_SURFACE;
391  format_amf = surface->pVtbl->GetFormat(surface);
392  avctx->sw_pix_fmt = av_amf_to_av_format(format_amf);
393  frame->hw_frames_ctx = av_buffer_ref(avctx->hw_frames_ctx);
394  } else {
395  ret = surface->pVtbl->Convert(surface, AMF_MEMORY_HOST);
396  AMF_RETURN_IF_FALSE(avctx, ret == AMF_OK, AVERROR_UNKNOWN, "Convert(amf::AMF_MEMORY_HOST) failed with error %d\n", ret);
397 
398  for (i = 0; i < surface->pVtbl->GetPlanesCount(surface); i++) {
399  plane = surface->pVtbl->GetPlaneAt(surface, i);
400  frame->data[i] = plane->pVtbl->GetNative(plane);
401  frame->linesize[i] = plane->pVtbl->GetHPitch(plane);
402  }
403 
404  frame->buf[0] = av_buffer_create((uint8_t *)surface, sizeof(surface),
405  amf_free_amfsurface, (void*)avctx,
406  AV_BUFFER_FLAG_READONLY);
407  AMF_RETURN_IF_FALSE(avctx, !!frame->buf[0], AVERROR(ENOMEM), "av_buffer_create for amf surface failed.");
408 
409  format_amf = surface->pVtbl->GetFormat(surface);
410  frame->format = av_amf_to_av_format(format_amf);
411  }
412 
413  frame->width = avctx->width;
414  frame->height = avctx->height;
415 
416  frame->pts = surface->pVtbl->GetPts(surface);
417 
418  surface->pVtbl->GetProperty(surface, L "FFMPEG:dts", &var);
419  frame->pkt_dts = var.int64Value;
420 
421  frame->duration = surface->pVtbl->GetDuration(surface);
422  if (frame->duration < 0)
423  frame->duration = 0;
424 
425  frame->color_range = avctx->color_range;
426  frame->colorspace = avctx->colorspace;
427  frame->color_trc = avctx->color_trc;
428  frame->color_primaries = avctx->color_primaries;
429 
430  if (frame->color_trc == AVCOL_TRC_SMPTE2084) {
431  AMFBuffer * hdrmeta_buffer = NULL;
432  ret = amf_get_property_buffer((AMFData *)surface, AMF_VIDEO_DECODER_HDR_METADATA, &hdrmeta_buffer);
433  if (hdrmeta_buffer != NULL) {
434  AMFHDRMetadata * hdrmeta = (AMFHDRMetadata*)hdrmeta_buffer->pVtbl->GetNative(hdrmeta_buffer);
435  if (ret != AMF_OK)
436  return ret;
437  if (hdrmeta != NULL) {
438  AVMasteringDisplayMetadata *mastering = av_mastering_display_metadata_create_side_data(frame);
439  const int chroma_den = 50000;
440  const int luma_den = 10000;
441 
442  if (!mastering)
443  return AVERROR(ENOMEM);
444 
445  mastering->display_primaries[0][0] = av_make_q(hdrmeta->redPrimary[0], chroma_den);
446  mastering->display_primaries[0][1] = av_make_q(hdrmeta->redPrimary[1], chroma_den);
447 
448  mastering->display_primaries[1][0] = av_make_q(hdrmeta->greenPrimary[0], chroma_den);
449  mastering->display_primaries[1][1] = av_make_q(hdrmeta->greenPrimary[1], chroma_den);
450 
451  mastering->display_primaries[2][0] = av_make_q(hdrmeta->bluePrimary[0], chroma_den);
452  mastering->display_primaries[2][1] = av_make_q(hdrmeta->bluePrimary[1], chroma_den);
453 
454  mastering->white_point[0] = av_make_q(hdrmeta->whitePoint[0], chroma_den);
455  mastering->white_point[1] = av_make_q(hdrmeta->whitePoint[1], chroma_den);
456 
457  mastering->max_luminance = av_make_q(hdrmeta->maxMasteringLuminance, luma_den);
458  mastering->min_luminance = av_make_q(hdrmeta->maxMasteringLuminance, luma_den);
459 
460  mastering->has_luminance = 1;
461  mastering->has_primaries = 1;
462  if (hdrmeta->maxContentLightLevel) {
463  AVContentLightMetadata *light = av_content_light_metadata_create_side_data(frame);
464 
465  if (!light)
466  return AVERROR(ENOMEM);
467 
468  light->MaxCLL = hdrmeta->maxContentLightLevel;
469  light->MaxFALL = hdrmeta->maxFrameAverageLightLevel;
470  }
471  }
472  }
473  }
474  return 0;
475 }
476 
477  static AMF_RESULT amf_receive_frame(AVCodecContext *avctx, AVFrame *frame)
478 {
479  AMFDecoderContext *ctx = avctx->priv_data;
480  AMF_RESULT ret = AMF_OK;
481  AMFSurface *surface = NULL;
482  AMFData *data_out = NULL;
483 
484  ret = ctx->decoder->pVtbl->QueryOutput(ctx->decoder, &data_out);
485  if (ret != AMF_OK && ret != AMF_REPEAT) {
486  return ret;
487  }
488  if (data_out == NULL) {
489  return AMF_REPEAT;
490  }
491 
492  if (data_out) {
493  AMFGuid guid = IID_AMFSurface();
494  data_out->pVtbl->QueryInterface(data_out, &guid, (void**)&surface); // query for buffer interface
495  data_out->pVtbl->Release(data_out);
496  data_out = NULL;
497  }
498 
499  ret = amf_amfsurface_to_avframe(avctx, surface, frame);
500  AMF_GOTO_FAIL_IF_FALSE(avctx, ret >= 0, AMF_FAIL, "Failed to convert AMFSurface to AVFrame = %d\n", ret);
501  return AMF_OK;
502 fail:
503 
504  if (surface) {
505  surface->pVtbl->Release(surface);
506  surface = NULL;
507  }
508  return ret;
509 }
510 
511  static AMF_RESULT amf_update_buffer_properties(AVCodecContext *avctx, AMFBuffer* buffer, const AVPacket* pkt)
512 {
513  AMF_RESULT res;
514 
515  AMF_RETURN_IF_FALSE(avctx, buffer != NULL, AMF_INVALID_ARG, "update_buffer_properties() - buffer not passed in");
516  AMF_RETURN_IF_FALSE(avctx, pkt != NULL, AMF_INVALID_ARG, "update_buffer_properties() - packet not passed in");
517  buffer->pVtbl->SetPts(buffer, pkt->pts);
518  buffer->pVtbl->SetDuration(buffer, pkt->duration);
519  AMF_ASSIGN_PROPERTY_INT64(res, buffer, L "FFMPEG:dts", pkt->dts);
520  if (res != AMF_OK)
521  av_log(avctx, AV_LOG_VERBOSE, "Failed to assign dts value.");
522  return AMF_OK;
523 }
524 
525  static AMF_RESULT amf_buffer_from_packet(AVCodecContext *avctx, const AVPacket* pkt, AMFBuffer** buffer)
526 {
527  AMFDecoderContext *ctx = avctx->priv_data;
528  AVHWDeviceContext *hw_device_ctx = (AVHWDeviceContext*)ctx->device_ctx_ref->data;
529  AVAMFDeviceContext *amf_device_ctx = (AVAMFDeviceContext *)hw_device_ctx->hwctx;
530  AMFContext *ctxt = amf_device_ctx->context;
531  void *mem;
532  AMF_RESULT err;
533  AMFBuffer *buf = NULL;
534 
535  AMF_RETURN_IF_FALSE(ctxt, pkt != NULL, AMF_INVALID_ARG, "amf_buffer_from_packet() - packet not passed in");
536  AMF_RETURN_IF_FALSE(ctxt, buffer != NULL, AMF_INVALID_ARG, "amf_buffer_from_packet() - buffer pointer not passed in");
537 
538  err = ctxt->pVtbl->AllocBuffer(ctxt, AMF_MEMORY_HOST, pkt->size + AV_INPUT_BUFFER_PADDING_SIZE, buffer);
539  AMF_RETURN_IF_FALSE(ctxt, err == AMF_OK, err, "amf_buffer_from_packet() - failed");
540  buf = *buffer;
541  err = buf->pVtbl->SetSize(buf, pkt->size);
542  AMF_RETURN_IF_FALSE(ctxt, err == AMF_OK, err, "amf_buffer_from_packet() - SetSize failed");
543  // get the memory location and check the buffer was indeed allocated
544  mem = buf->pVtbl->GetNative(buf);
545  AMF_RETURN_IF_FALSE(ctxt, mem != NULL, AMF_INVALID_POINTER, "amf_buffer_from_packet() - GetNative failed");
546 
547  // copy the packet memory and clear data padding
548  memcpy(mem, pkt->data, pkt->size);
549  memset((amf_int8*)(mem)+pkt->size, 0, AV_INPUT_BUFFER_PADDING_SIZE);
550 
551  return amf_update_buffer_properties(avctx, buf, pkt);
552 }
553 
554  static int amf_decode_frame(AVCodecContext *avctx, struct AVFrame *frame)
555 {
556  AMFDecoderContext *ctx = avctx->priv_data;
557  AMFBuffer *buf;
558  AMF_RESULT res;
559  int got_frame = 0;
560  AVPacket *avpkt = ctx->in_pkt;
561 
562  if (!ctx->decoder)
563  return AVERROR(EINVAL);
564 
565  // get packet if needed
566  if(!ctx->drain){
567  if(ctx->resolution_changed)
568  ctx->resolution_changed = 0;
569  else{
570  int ret;
571  av_packet_unref(avpkt);
572  ret = ff_decode_get_packet(avctx, avpkt);
573  if (ret < 0 && ret != AVERROR_EOF)
574  return ret;
575  if (ret == AVERROR_EOF) {
576  //nothing to consume, start external drain
577  ctx->decoder->pVtbl->Drain(ctx->decoder);
578  ctx->drain = 1;
579  }
580  }
581  }
582 
583  if(!ctx->drain){
584  // submit frame
585  res = amf_buffer_from_packet(avctx, avpkt, &buf);
586  AMF_RETURN_IF_FALSE(avctx, res == AMF_OK, 0, "Cannot convert AVPacket to AMFbuffer");
587  do{
588  res = ctx->decoder->pVtbl->SubmitInput(ctx->decoder, (AMFData*) buf);
589  if(res == AMF_DECODER_NO_FREE_SURFACES)
590  {
591  av_usleep(100);
592  }
593  } while (res == AMF_DECODER_NO_FREE_SURFACES);
594 
595  buf->pVtbl->Release(buf);
596 
597  if(res == AMF_DECODER_NO_FREE_SURFACES) {
598  // input is not consumed, need to QueryOutput and submit again
599  av_log(avctx, AV_LOG_VERBOSE, "SubmitInput() returned NO_FREE_SURFACES and came out of loop - should never happen\n");
600  res = AMF_OK;
601  } else if (res == AMF_RESOLUTION_CHANGED) {
602  //input is not consumed, start internal drain
603  ctx->decoder->pVtbl->Drain(ctx->decoder);
604  ctx->drain = 1;
605  // process resolution_changed when internal drain is complete
606  ctx->resolution_changed = 1;
607  res = AMF_OK;
608  } else if (res != AMF_OK && res != AMF_NEED_MORE_INPUT && res != AMF_REPEAT) {
609  av_log(avctx, AV_LOG_ERROR, "SubmitInput() returned error %d\n", res);
610  return AVERROR(EINVAL);
611  }
612  }
613 
614  res = amf_receive_frame(avctx, frame);
615  if (res == AMF_OK)
616  got_frame = 1;
617  else if (res == AMF_REPEAT)
618  // decoder has no output yet
619  res = AMF_OK;
620  else if (res == AMF_EOF) {
621  // drain is complete
622  ctx->drain = 0;
623  if(ctx->resolution_changed){
624  // re-initialze decoder
625  AMFVariantStruct size_var = {0};
626  AMFVariantStruct format_var = {0};
627  res = ctx->decoder->pVtbl->GetProperty(ctx->decoder, AMF_VIDEO_DECODER_CURRENT_SIZE, &size_var);
628  if (res != AMF_OK) {
629  return AVERROR(EINVAL);
630  }
631 
632  avctx->width = size_var.sizeValue.width;
633  avctx->height = size_var.sizeValue.height;
634  avctx->coded_width = size_var.sizeValue.width;
635  avctx->coded_height = size_var.sizeValue.height;
636  res = ctx->decoder->pVtbl->ReInit(ctx->decoder, avctx->width, avctx->height);
637  if (res != AMF_OK) {
638  av_log(avctx, AV_LOG_ERROR, "ReInit() returned %d\n", res);
639  return AVERROR(EINVAL);
640  }
641  res = ctx->decoder->pVtbl->GetProperty(ctx->decoder, AMF_VIDEO_DECODER_OUTPUT_FORMAT, &format_var);
642  if (res == AMF_OK) {
643  res = amf_init_frames_context(avctx, av_amf_to_av_format(format_var.int64Value), avctx->coded_width, avctx->coded_height);
644  }
645 
646  if (res < 0)
647  return AVERROR(EINVAL);
648  }else
649  return AVERROR_EOF;
650  } else {
651  av_log(avctx, AV_LOG_ERROR, "Unknown result from QueryOutput %d\n", res);
652  }
653  return got_frame ? 0 : AVERROR(EAGAIN);
654 }
655 
656  static void amf_decode_flush(AVCodecContext *avctx)
657 {
658  AMFDecoderContext *ctx = avctx->priv_data;
659  ctx->decoder->pVtbl->Flush(ctx->decoder);
660 }
661 
662  #define OFFSET(x) offsetof(AMFDecoderContext, x)
663  #define VD AV_OPT_FLAG_VIDEO_PARAM | AV_OPT_FLAG_DECODING_PARAM
664 
665  static const AVOption options[] = {
666  // Decoder mode
667  { "decoder_mode", "Decoder mode", OFFSET(decoder_mode), AV_OPT_TYPE_INT, { .i64 = -1 }, -1, AMF_VIDEO_DECODER_MODE_LOW_LATENCY, VD, "decoder_mode" },
668  { "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" },
669  { "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" },
670  { "low_latency", "DPB delay is 0", 0, AV_OPT_TYPE_CONST, { .i64 = AMF_VIDEO_DECODER_MODE_LOW_LATENCY }, 0, 0, VD, "decoder_mode" },
671 
672  // Timestamp mode
673  { "timestamp_mode", "Timestamp mode", OFFSET(timestamp_mode), AV_OPT_TYPE_INT, { .i64 = AMF_TS_SORT }, -1, AMF_TS_DECODE, VD, "timestamp_mode" },
674  { "presentation", "Preserve timestamps from input to output", 0, AV_OPT_TYPE_CONST, { .i64 = AMF_TS_PRESENTATION }, 0, 0, VD, "timestamp_mode" },
675  { "sort", "Resort PTS list", 0, AV_OPT_TYPE_CONST, { .i64 = AMF_TS_SORT }, 0, 0, VD, "timestamp_mode" },
676  { "decode", "Decode order", 0, AV_OPT_TYPE_CONST, { .i64 = AMF_TS_DECODE }, 0, 0, VD, "timestamp_mode" },
677 
678  // Reference frame management
679  { "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 },
680  { "dpb_size", "Minimum number of surfaces for reordering", OFFSET(dpb_size), AV_OPT_TYPE_INT, { .i64 = -1 }, -1, 32, VD, NULL },
681 
682  { "lowlatency", "Low latency", OFFSET(lowlatency), AV_OPT_TYPE_INT, { .i64 = -1 }, -1, 1, VD, NULL },
683  { "smart_access_video", "Smart Access Video", OFFSET(smart_access_video), AV_OPT_TYPE_INT, { .i64 = -1 }, -1, 1, VD, NULL },
684  { "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 },
685  { "copy_output", "Copy Output", OFFSET(copy_output), AV_OPT_TYPE_INT, { .i64 = -1 }, -1, 1, VD, NULL },
686 
687  { NULL }
688 };
689 
690  static const AVClass amf_decode_class = {
691  .class_name = "amf",
692  .item_name = av_default_item_name,
693  .option = options,
694  .version = LIBAVUTIL_VERSION_INT,
695 };
696 
697  #define DEFINE_AMF_DECODER(x, X, bsf_name) \
698 const FFCodec ff_##x##_amf_decoder = { \
699  .p.name = #x "_amf", \
700  CODEC_LONG_NAME(#X " AMD AMF video decoder"), \
701  .priv_data_size = sizeof(AMFDecoderContext), \
702  .p.type = AVMEDIA_TYPE_VIDEO, \
703  .p.id = AV_CODEC_ID_##X, \
704  .init = amf_decode_init, \
705  FF_CODEC_RECEIVE_FRAME_CB(amf_decode_frame), \
706  .flush = amf_decode_flush, \
707  .close = amf_decode_close, \
708  .bsfs = bsf_name, \
709  .p.capabilities = AV_CODEC_CAP_HARDWARE | AV_CODEC_CAP_DELAY | AV_CODEC_CAP_AVOID_PROBING, \
710  .p.priv_class = &amf_decode_class, \
711  .hw_configs = amf_hw_configs, \
712  .p.wrapper_name = "amf", \
713  .caps_internal = FF_CODEC_CAP_NOT_INIT_THREADSAFE, \
714 }; \
715 
716 DEFINE_AMF_DECODER(h264, H264, "h264_mp4toannexb")
717 DEFINE_AMF_DECODER(hevc, HEVC, NULL)
718 DEFINE_AMF_DECODER(vp9, VP9, NULL)
719 DEFINE_AMF_DECODER(av1, AV1, NULL)
hwconfig.h
AVMasteringDisplayMetadata::has_primaries
int has_primaries
Flag indicating whether the display primaries (and white point) are set.
Definition: mastering_display_metadata.h:62
av_packet_unref
void av_packet_unref(AVPacket *pkt)
Wipe the packet.
Definition: packet.c:432
ff_decode_get_packet
int ff_decode_get_packet(AVCodecContext *avctx, AVPacket *pkt)
Called by decoders to get the next packet for decoding.
Definition: decode.c:249
AVMasteringDisplayMetadata::max_luminance
AVRational max_luminance
Max luminance of mastering display (cd/m^2).
Definition: mastering_display_metadata.h:57
AVPixelFormat
AVPixelFormat
Pixel format.
Definition: pixfmt.h:71
name
it s the only field you need to keep assuming you have a context There is some magic you don t need to care about around this just let it vf default minimum maximum flags name is the option name
Definition: writing_filters.txt:88
AVERROR
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
AVCodecContext::colorspace
enum AVColorSpace colorspace
YUV colorspace type.
Definition: avcodec.h:659
amf_amfsurface_to_avframe
static int amf_amfsurface_to_avframe(AVCodecContext *avctx, AMFSurface *surface, AVFrame *frame)
Definition: amfdec.c:360
AVERROR_EOF
#define AVERROR_EOF
End of file.
Definition: error.h:57
AVBufferRef::data
uint8_t * data
The data buffer.
Definition: buffer.h:90
amf_decode_frame
static int amf_decode_frame(AVCodecContext *avctx, struct AVFrame *frame)
Definition: amfdec.c:554
AVMasteringDisplayMetadata::display_primaries
AVRational display_primaries[3][2]
CIE 1931 xy chromaticity coords of color primaries (r, g, b order).
Definition: mastering_display_metadata.h:42
AVHWFramesContext::format
enum AVPixelFormat format
The pixel format identifying the underlying HW surface type.
Definition: hwcontext.h:200
AVMasteringDisplayMetadata::has_luminance
int has_luminance
Flag indicating whether the luminance (min_ and max_) have been set.
Definition: mastering_display_metadata.h:67
amf_decode_init
static int amf_decode_init(AVCodecContext *avctx)
Definition: amfdec.c:269
AMF_VIDEO_DECODER_OUTPUT_FORMAT
#define AMF_VIDEO_DECODER_OUTPUT_FORMAT
Definition: amfdec.c:45
AVContentLightMetadata::MaxCLL
unsigned MaxCLL
Max content light level (cd/m^2).
Definition: mastering_display_metadata.h:111
av_hwframe_ctx_init
int av_hwframe_ctx_init(AVBufferRef *ref)
Finalize the context before use.
Definition: hwcontext.c:337
AVFrame
This structure describes decoded (raw) audio or video data.
Definition: frame.h:427
AVCodecContext::color_trc
enum AVColorTransferCharacteristic color_trc
Color Transfer Characteristic.
Definition: avcodec.h:652
AVCOL_RANGE_JPEG
@ AVCOL_RANGE_JPEG
Full range content.
Definition: pixfmt.h:777
av_hwframe_ctx_alloc
AVBufferRef * av_hwframe_ctx_alloc(AVBufferRef *device_ref_in)
Allocate an AVHWFramesContext tied to a given device context.
Definition: hwcontext.c:263
AVPacket::data
uint8_t * data
Definition: packet.h:588
AVOption
AVOption.
Definition: opt.h:429
AVCOL_TRC_UNSPECIFIED
@ AVCOL_TRC_UNSPECIFIED
Definition: pixfmt.h:669
data
const char data[16]
Definition: mxf.c:149
AV_PIX_FMT_YUV420P10
#define AV_PIX_FMT_YUV420P10
Definition: pixfmt.h:539
AV_LOG_VERBOSE
#define AV_LOG_VERBOSE
Detailed information.
Definition: log.h:226
AVPacket::duration
int64_t duration
Duration of this packet in AVStream->time_base units, 0 if unknown.
Definition: packet.h:606
av_buffer_ref
AVBufferRef * av_buffer_ref(const AVBufferRef *buf)
Create a new reference to an AVBuffer.
Definition: buffer.c:103
AMF_RETURN_IF_FALSE
#define AMF_RETURN_IF_FALSE(avctx, exp, ret_value,...)
Error handling helper.
Definition: amfenc.h:169
AVERROR_UNKNOWN
#define AVERROR_UNKNOWN
Unknown error, typically from an external library.
Definition: error.h:73
AVHWFramesContext::width
int width
The allocated dimensions of the frames in this pool.
Definition: hwcontext.h:220
AVCOL_SPC_BT2020_CL
@ AVCOL_SPC_BT2020_CL
ITU-R BT2020 constant luminance system.
Definition: pixfmt.h:712
av_packet_free
void av_packet_free(AVPacket **pkt)
Free the packet, if the packet is reference counted, it will be unreferenced first.
Definition: packet.c:74
AV_PIX_FMT_AMF_SURFACE
@ AV_PIX_FMT_AMF_SURFACE
HW acceleration through AMF.
Definition: pixfmt.h:477
AVContentLightMetadata
Content light level needed by to transmit HDR over HDMI (CTA-861.3).
Definition: mastering_display_metadata.h:107
AVCodecContext::codec
const struct AVCodec * codec
Definition: avcodec.h:440
copy_output
static int copy_output(SANMVideoContext *ctx, int sanm)
Definition: sanm.c:2674
fail
#define fail()
Definition: checkasm.h:207
AVCodecContext::thread_count
int thread_count
thread count is used to decide how many independent tasks should be passed to execute()
Definition: avcodec.h:1561
av_amf_to_av_format
enum AVPixelFormat av_amf_to_av_format(enum AMF_SURFACE_FORMAT fmt)
Definition: hwcontext_amf.c:132
AV_CODEC_HW_CONFIG_METHOD_HW_FRAMES_CTX
@ AV_CODEC_HW_CONFIG_METHOD_HW_FRAMES_CTX
The codec supports this format via the hw_frames_ctx interface.
Definition: codec.h:311
val
static double val(void *priv, double ch)
Definition: aeval.c:77
AVCodecContext::coded_height
int coded_height
Definition: avcodec.h:607
AVHWDeviceContext
This struct aggregates all the (hardware/vendor-specific) "high-level" state, i.e.
Definition: hwcontext.h:63
decode_bsf.h
AVCodecContext::color_primaries
enum AVColorPrimaries color_primaries
Chromaticity coordinates of the source primaries.
Definition: avcodec.h:645
pkt
AVPacket * pkt
Definition: movenc.c:60
AV_LOG_ERROR
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
Definition: log.h:210
AVHWFramesContext::height
int height
Definition: hwcontext.h:220
AVCodecContext::extradata_size
int extradata_size
Definition: avcodec.h:515
AVMasteringDisplayMetadata::white_point
AVRational white_point[2]
CIE 1931 xy chromaticity coords of white point.
Definition: mastering_display_metadata.h:47
AV_BUFFER_FLAG_READONLY
#define AV_BUFFER_FLAG_READONLY
Always treat the buffer as read-only, even when it has only one reference.
Definition: buffer.h:114
AVCOL_SPC_SMPTE170M
@ AVCOL_SPC_SMPTE170M
also ITU-R BT601-6 525 / ITU-R BT1358 525 / ITU-R BT1700 NTSC / functionally identical to above
Definition: pixfmt.h:707
AV_CODEC_ID_VP9
@ AV_CODEC_ID_VP9
Definition: codec_id.h:222
amf_update_buffer_properties
static AMF_RESULT amf_update_buffer_properties(AVCodecContext *avctx, AMFBuffer *buffer, const AVPacket *pkt)
Definition: amfdec.c:511
AV_HWDEVICE_TYPE_AMF
@ AV_HWDEVICE_TYPE_AMF
Definition: hwcontext.h:41
ctx
AVFormatContext * ctx
Definition: movenc.c:49
decode.h
AMF_GOTO_FAIL_IF_FALSE
#define AMF_GOTO_FAIL_IF_FALSE(avctx, exp, ret_value,...)
Definition: hwcontext_amf_internal.h:34
AVCodecHWConfig::pix_fmt
enum AVPixelFormat pix_fmt
For decoders, a hardware pixel format which that decoder may be able to decode to if suitable hardwar...
Definition: codec.h:339
hwcontext_amf.h
AVAMFDeviceContext::version
int64_t version
version of AMF runtime
Definition: hwcontext_amf.h:39
codec_id
enum AVCodecID codec_id
Definition: vaapi_decode.c:410
AV_PIX_FMT_YUV420P
@ AV_PIX_FMT_YUV420P
planar YUV 4:2:0, 12bpp, (1 Cr & Cb sample per 2x2 Y samples)
Definition: pixfmt.h:73
av_usleep
int av_usleep(unsigned usec)
Sleep for a period of time.
Definition: time.c:84
AVCOL_PRI_UNSPECIFIED
@ AVCOL_PRI_UNSPECIFIED
Definition: pixfmt.h:639
AV_CODEC_ID_H264
@ AV_CODEC_ID_H264
Definition: codec_id.h:79
dpb_size
int dpb_size
Definition: h264_levels.c:111
if
if(ret)
Definition: filter_design.txt:179
DEFINE_AMF_DECODER
#define DEFINE_AMF_DECODER(x, X, bsf_name)
Definition: amfdec.c:697
AMFDecoderContext
AMF decoder context.
Definition: amfdec.h:39
LIBAVUTIL_VERSION_INT
#define LIBAVUTIL_VERSION_INT
Definition: version.h:85
AVClass
Describe the class of an AVClass context structure.
Definition: log.h:76
NULL
#define NULL
Definition: coverity.c:32
AVHWFramesContext::sw_format
enum AVPixelFormat sw_format
The pixel format identifying the actual data layout of the hardware frames.
Definition: hwcontext.h:213
AVCodecContext::color_range
enum AVColorRange color_range
MPEG vs JPEG YUV range.
Definition: avcodec.h:669
av_buffer_unref
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
AV_CODEC_ID_AV1
@ AV_CODEC_ID_AV1
Definition: codec_id.h:284
amf_buffer_from_packet
static AMF_RESULT amf_buffer_from_packet(AVCodecContext *avctx, const AVPacket *pkt, AMFBuffer **buffer)
Definition: amfdec.c:525
AV_PIX_FMT_YUVJ420P
@ 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_default_item_name
const char * av_default_item_name(void *ptr)
Return the context name.
Definition: log.c:241
OFFSET
#define OFFSET(x)
Definition: amfdec.c:662
options
Definition: swscale.c:43
time.h
ff_decode_get_extradata
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
AVCOL_RANGE_UNSPECIFIED
@ AVCOL_RANGE_UNSPECIFIED
Definition: pixfmt.h:743
av_buffer_create
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
AVCOL_TRC_SMPTE2084
@ AVCOL_TRC_SMPTE2084
SMPTE ST 2084 for 10-, 12-, 14- and 16-bit systems.
Definition: pixfmt.h:683
hwcontext_dxva2.h
AVPacket::size
int size
Definition: packet.h:589
AVCodecContext::extra_hw_frames
int extra_hw_frames
Video decoding only.
Definition: avcodec.h:1498
codec_internal.h
av_err2str
#define av_err2str(errnum)
Convenience macro, the return value should be used only directly in function arguments but never stan...
Definition: error.h:122
AVAMFDeviceContext
This struct is allocated as AVHWDeviceContext.hwctx.
Definition: hwcontext_amf.h:34
av_make_q
static AVRational av_make_q(int num, int den)
Create an AVRational.
Definition: rational.h:71
AVCodecHWConfigInternal
Definition: hwconfig.h:25
AVPacket::dts
int64_t dts
Decompression timestamp in AVStream->time_base units; the time at which the packet is decompressed.
Definition: packet.h:587
av_content_light_metadata_create_side_data
AVContentLightMetadata * av_content_light_metadata_create_side_data(AVFrame *frame)
Allocate a complete AVContentLightMetadata and add it to the frame.
Definition: mastering_display_metadata.c:82
amfdec.h
amf_init_decoder
static int amf_init_decoder(AVCodecContext *avctx)
Definition: amfdec.c:75
av_packet_alloc
AVPacket * av_packet_alloc(void)
Allocate an AVPacket and set its fields to default values.
Definition: packet.c:63
AV_LOG_INFO
#define AV_LOG_INFO
Standard information.
Definition: log.h:221
FF_THREAD_FRAME
#define FF_THREAD_FRAME
Decode more than one frame at once.
Definition: avcodec.h:1572
AVCodec::id
enum AVCodecID id
Definition: codec.h:186
av_hwdevice_ctx_create_derived
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:718
i
#define i(width, name, range_min, range_max)
Definition: cbs_h2645.c:256
AVPacket::pts
int64_t pts
Presentation timestamp in AVStream->time_base units; the time at which the decompressed packet will b...
Definition: packet.h:581
AVCOL_SPC_BT2020_NCL
@ AVCOL_SPC_BT2020_NCL
ITU-R BT2020 non-constant luminance system.
Definition: pixfmt.h:711
amf_init_frames_context
static int amf_init_frames_context(AVCodecContext *avctx, int sw_format, int new_width, int new_height)
Definition: amfdec.c:239
hw_device_ctx
static AVBufferRef * hw_device_ctx
Definition: hw_decode.c:45
VD
#define VD
Definition: amfdec.c:663
amf_legacy_driver_no_bitness_detect
static int amf_legacy_driver_no_bitness_detect(AVAMFDeviceContext *amf_device_ctx)
Definition: amfdec.c:66
AV_CODEC_ID_HEVC
@ AV_CODEC_ID_HEVC
Definition: codec_id.h:228
AVCodecContext::hw_device_ctx
AVBufferRef * hw_device_ctx
A reference to the AVHWDeviceContext describing the device which will be used by a hardware encoder/d...
Definition: avcodec.h:1475
AVMasteringDisplayMetadata
Mastering display metadata capable of representing the color volume of the display used to master the...
Definition: mastering_display_metadata.h:38
AVCodecContext::height
int height
Definition: avcodec.h:592
AVCodecContext::pix_fmt
enum AVPixelFormat pix_fmt
Pixel format, see AV_PIX_FMT_xxx.
Definition: avcodec.h:631
amf_decode_flush
static void amf_decode_flush(AVCodecContext *avctx)
Definition: amfdec.c:656
amf_hw_configs
static const AVCodecHWConfigInternal *const amf_hw_configs[]
Definition: amfdec.c:47
AVCodecContext::hw_frames_ctx
AVBufferRef * hw_frames_ctx
A reference to the AVHWFramesContext describing the input (for encoding) or output (decoding) frames.
Definition: avcodec.h:1453
AVHWFramesContext
This struct describes a set or pool of "hardware" frames (i.e.
Definition: hwcontext.h:118
ret
ret
Definition: filter_design.txt:187
AVHWDeviceContext::type
enum AVHWDeviceType type
This field identifies the underlying API used for hardware access.
Definition: hwcontext.h:75
AV_PIX_FMT_NV12
@ 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
AVClass::class_name
const char * class_name
The name of the class; usually it is the same name as the context structure type to which the AVClass...
Definition: log.h:81
frame
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
Definition: filter_design.txt:265
av_hwdevice_ctx_create
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:615
AV_INPUT_BUFFER_PADDING_SIZE
#define AV_INPUT_BUFFER_PADDING_SIZE
Definition: defs.h:40
amf_decode_class
static const AVClass amf_decode_class
Definition: amfdec.c:690
ff_decode_frame_props
int ff_decode_frame_props(AVCodecContext *avctx, AVFrame *frame)
Set various frame properties from the codec context / packet data.
Definition: decode.c:1570
AVCodecContext
main external API structure.
Definition: avcodec.h:431
AVCodecContext::active_thread_type
int active_thread_type
Which multithreading methods are in use by the codec.
Definition: avcodec.h:1580
hwcontext_amf_internal.h
av_mastering_display_metadata_create_side_data
AVMasteringDisplayMetadata * av_mastering_display_metadata_create_side_data(AVFrame *frame)
Allocate a complete AVMasteringDisplayMetadata and add it to the frame.
Definition: mastering_display_metadata.c:58
amf_decode_close
static int amf_decode_close(AVCodecContext *avctx)
Definition: amfdec.c:223
buffer
the frame and frame reference mechanism is intended to as much as expensive copies of that data while still allowing the filters to produce correct results The data is stored in buffers represented by AVFrame structures Several references can point to the same frame buffer
Definition: filter_design.txt:49
AV_PIX_FMT_NONE
@ AV_PIX_FMT_NONE
Definition: pixfmt.h:72
AV_OPT_TYPE_INT
@ AV_OPT_TYPE_INT
Underlying C type is int.
Definition: opt.h:259
amf_receive_frame
static AMF_RESULT amf_receive_frame(AVCodecContext *avctx, AVFrame *frame)
Definition: amfdec.c:477
L
#define L(x)
Definition: vpx_arith.h:36
AVMasteringDisplayMetadata::min_luminance
AVRational min_luminance
Min luminance of mastering display (cd/m^2).
Definition: mastering_display_metadata.h:52
AV_PIX_FMT_P010
#define AV_PIX_FMT_P010
Definition: pixfmt.h:602
AVCodecContext::coded_width
int coded_width
Bitstream width / height, may be different from width/height e.g.
Definition: avcodec.h:607
AVHWFramesContext::initial_pool_size
int initial_pool_size
Initial size of the frame pool.
Definition: hwcontext.h:190
AVERROR_ENCODER_NOT_FOUND
#define AVERROR_ENCODER_NOT_FOUND
Encoder not found.
Definition: error.h:56
amf_get_property_buffer
static AMF_RESULT amf_get_property_buffer(AMFData *object, const wchar_t *name, AMFBuffer **val)
Definition: amfdec.c:339
mem.h
mastering_display_metadata.h
ff_attach_decode_data
int ff_attach_decode_data(AVFrame *frame)
Definition: decode.c:1647
AV_CODEC_HW_CONFIG_METHOD_HW_DEVICE_CTX
@ AV_CODEC_HW_CONFIG_METHOD_HW_DEVICE_CTX
The codec supports this format via the hw_device_ctx interface.
Definition: codec.h:298
AVPacket
This structure stores compressed data.
Definition: packet.h:565
AVContentLightMetadata::MaxFALL
unsigned MaxFALL
Max average light level per frame (cd/m^2).
Definition: mastering_display_metadata.h:116
AVCodecContext::priv_data
void * priv_data
Definition: avcodec.h:458
AVCodecContext::width
int width
picture width / height.
Definition: avcodec.h:592
imgutils.h
av_log
#define av_log(a,...)
Definition: tableprint_vlc.h:27
AVCodecContext::sw_pix_fmt
enum AVPixelFormat sw_pix_fmt
Nominal unaccelerated pixel format, see AV_PIX_FMT_xxx.
Definition: avcodec.h:638
AVCOL_SPC_BT709
@ AVCOL_SPC_BT709
also ITU-R BT1361 / IEC 61966-2-4 xvYCC709 / derived in SMPTE RP 177 Annex B
Definition: pixfmt.h:702
AVCodecHWConfigInternal::public
AVCodecHWConfig public
This is the structure which will be returned to the user by avcodec_get_hw_config().
Definition: hwconfig.h:30
amf_free_amfsurface
static void amf_free_amfsurface(void *opaque, uint8_t *data)
Definition: amfdec.c:60
AV_OPT_TYPE_CONST
@ AV_OPT_TYPE_CONST
Special option type for declaring named constants.
Definition: opt.h:299
hwcontext_d3d11va.h
options
static const AVOption options[]
Definition: amfdec.c:665
w32dlfcn.h

Generated on Wed Nov 19 2025 19:21:46 for FFmpeg by   doxygen 1.8.17

AltStyle によって変換されたページ (->オリジナル) /