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 
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"
29 
30 #if CONFIG_D3D11VA
32 #endif
33 #if CONFIG_DXVA2
34 #define COBJMACROS
36 #endif
37 
38 #ifdef _WIN32
39 #include "compat/w32dlfcn.h"
40 #else
41 #include <dlfcn.h>
42 #endif
43 //will be in public headers soon
44 #define AMF_VIDEO_DECODER_OUTPUT_FORMAT L"OutputDecodeFormat"
45 
52 };
53 
54 static const AVCodecHWConfigInternal *const amf_hw_configs[] = {
55  &(const AVCodecHWConfigInternal) {
56  .public = {
60  .device_type = AV_HWDEVICE_TYPE_AMF,
61  },
62  .hwaccel = NULL,
63  },
64  NULL
65 };
66 
67 static void amf_free_amfsurface(void *opaque, uint8_t *data)
68 {
69  AMFSurface *surface = (AMFSurface*)(data);
70  surface->pVtbl->Release(surface);
71 }
72 
74 {
75  if( AMF_GET_MAJOR_VERSION(amf_device_ctx->version) <= 1 &&
76  AMF_GET_MINOR_VERSION(amf_device_ctx->version) <= 4 &&
77  AMF_GET_SUBMINOR_VERSION(amf_device_ctx->version) < 36)
78  return 1;
79  return 0;
80 }
81 
82 static int amf_init_decoder(AVCodecContext *avctx)
83 {
85  AVHWDeviceContext *hw_device_ctx = (AVHWDeviceContext*)ctx->device_ctx_ref->data;
86  AVAMFDeviceContext *amf_device_ctx = (AVAMFDeviceContext*)hw_device_ctx->hwctx;
87  const wchar_t *codec_id = NULL;
88  AMF_RESULT res;
89  AMFBuffer *buffer;
90  amf_int64 color_profile;
91  int pool_size = 36;
92 
93  ctx->drain = 0;
94  ctx->resolution_changed = 0;
95 
96  switch (avctx->codec->id) {
97  case AV_CODEC_ID_H264:
98  codec_id = AMFVideoDecoderUVD_H264_AVC;
99  break;
100  case AV_CODEC_ID_HEVC: {
101  codec_id = AMFVideoDecoderHW_H265_HEVC;
102  // way-around for older drivers that don't support dynamic butness detection -
103  // define HEVC 10-bit based on container info
104  if(amf_legacy_driver_no_bitness_detect(amf_device_ctx)){
105  if(avctx->pix_fmt == AV_PIX_FMT_YUV420P10)
106  codec_id = AMFVideoDecoderHW_H265_MAIN10;
107  }
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;
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 
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  res = amf_device_ctx->context->pVtbl->AllocBuffer(amf_device_ctx->context, AMF_MEMORY_HOST, avctx->extradata_size, &buffer);
191  if (res == AMF_OK) {
192  memcpy(buffer->pVtbl->GetNative(buffer), avctx->extradata, avctx->extradata_size);
193  AMF_ASSIGN_PROPERTY_INTERFACE(res,ctx->decoder, AMF_VIDEO_DECODER_EXTRADATA, buffer);
194  buffer->pVtbl->Release(buffer);
195  buffer = NULL;
196  }
197  }
198  if (ctx->surface_pool_size == -1) {
199  ctx->surface_pool_size = pool_size;
200  if (avctx->extra_hw_frames > 0)
201  ctx->surface_pool_size += avctx->extra_hw_frames;
202  if (avctx->active_thread_type & FF_THREAD_FRAME)
203  ctx->surface_pool_size += avctx->thread_count;
204  }
205 
206  //at the moment, there is such a restriction in AMF.
207  //when it is possible, I will remove this code
208  if (ctx->surface_pool_size > 100)
209  ctx->surface_pool_size = 100;
210 
211  AMF_ASSIGN_PROPERTY_INT64(res, ctx->decoder, AMF_VIDEO_DECODER_SURFACE_POOL_SIZE, ctx->surface_pool_size);
212  res = ctx->decoder->pVtbl->Init(ctx->decoder, AMF_SURFACE_UNKNOWN, avctx->width, avctx->height);
213  if (res != AMF_OK) {
214  av_log(avctx, AV_LOG_ERROR, "Decoder initialization failed with error %d\n", res);
215  return AVERROR(EINVAL);
216  }
217  return 0;
218 }
219 
221 {
222  AMFDecoderContext *ctx = avctx->priv_data;
223 
224  if (ctx->decoder) {
225  ctx->decoder->pVtbl->Terminate(ctx->decoder);
226  ctx->decoder->pVtbl->Release(ctx->decoder);
227  ctx->decoder = NULL;
228  }
229 
230  av_buffer_unref(&ctx->device_ctx_ref);
231  av_packet_free(&ctx->in_pkt);
232 
233  return 0;
234 }
235 
236 static int amf_init_frames_context(AVCodecContext *avctx, int sw_format, int new_width, int new_height)
237 {
238  int ret;
239  AVHWDeviceContext *hwdev_ctx;
240  AVHWFramesContext *hwframes_ctx;
242  if (!avctx->hw_frames_ctx || !avctx->hw_device_ctx)
243  return 0;
244  hwdev_ctx = (AVHWDeviceContext*)avctx->hw_device_ctx->data;
245  hwframes_ctx = (AVHWFramesContext*)avctx->hw_frames_ctx->data;
246  ctx = avctx->priv_data;
247 
248  if (hwdev_ctx->type != AV_HWDEVICE_TYPE_AMF)
249  return 0;
250 
251  hwframes_ctx->width = new_width;
252  hwframes_ctx->height = new_height;
253  hwframes_ctx->format = AV_PIX_FMT_AMF_SURFACE;
254  hwframes_ctx->sw_format = sw_format;
255  hwframes_ctx->initial_pool_size = ctx->surface_pool_size + 8;
256 
258  if (ret < 0) {
259  av_log(NULL, AV_LOG_ERROR, "Error initializing a AMF frame pool\n");
261  return ret;
262  }
263  return 0;
264 }
265 
266 static int amf_decode_init(AVCodecContext *avctx)
267 {
268  AMFDecoderContext *ctx = avctx->priv_data;
269  int ret;
270  ctx->in_pkt = av_packet_alloc();
271  if (!ctx->in_pkt)
272  return AVERROR(ENOMEM);
273 
274  if (avctx->hw_device_ctx && !avctx->hw_frames_ctx) {
275  AVHWDeviceContext *hwdev_ctx;
276  hwdev_ctx = (AVHWDeviceContext*)avctx->hw_device_ctx->data;
277  if (hwdev_ctx->type == AV_HWDEVICE_TYPE_AMF)
278  {
279  ctx->device_ctx_ref = av_buffer_ref(avctx->hw_device_ctx);
281 
282  AMF_GOTO_FAIL_IF_FALSE(avctx, !!avctx->hw_frames_ctx, AVERROR(ENOMEM), "av_hwframe_ctx_alloc failed\n");
283  } else {
285  AMF_GOTO_FAIL_IF_FALSE(avctx, ret == 0, ret, "Failed to create derived AMF device context: %s\n", av_err2str(ret));
286  }
287  } else {
288  ret = av_hwdevice_ctx_create(&ctx->device_ctx_ref, AV_HWDEVICE_TYPE_AMF, NULL, NULL, 0);
289  AMF_GOTO_FAIL_IF_FALSE(avctx, ret == 0, ret, "Failed to create hardware device context (AMF) : %s\n", av_err2str(ret));
290  }
291  if ((ret = amf_init_decoder(avctx)) == 0) {
292  AVHWDeviceContext *hw_device_ctx = (AVHWDeviceContext*)ctx->device_ctx_ref->data;
293  AVAMFDeviceContext *amf_device_ctx = (AVAMFDeviceContext*)hw_device_ctx->hwctx;
294  enum AVPixelFormat surf_pix_fmt = AV_PIX_FMT_NONE;
295 
296  if(amf_legacy_driver_no_bitness_detect(amf_device_ctx)){
297  // if bitness detection is not supported in legacy driver use format from container
298  switch (avctx->pix_fmt) {
299  case AV_PIX_FMT_YUV420P:
300  case AV_PIX_FMT_YUVJ420P:
301  surf_pix_fmt = AV_PIX_FMT_NV12; break;
303  surf_pix_fmt = AV_PIX_FMT_P010; break;
304  }
305  }else{
306  AMFVariantStruct format_var = {0};
307 
308  ret = ctx->decoder->pVtbl->GetProperty(ctx->decoder, AMF_VIDEO_DECODER_OUTPUT_FORMAT, &format_var);
309  AMF_GOTO_FAIL_IF_FALSE(avctx, ret == AMF_OK, AVERROR(EINVAL), "Failed to get output format (AMF) : %d\n", ret);
310 
311  surf_pix_fmt = av_amf_to_av_format(format_var.int64Value);
312  }
313  if(avctx->hw_frames_ctx)
314  {
315  // this values should be set for avcodec_open2
316  // will be updated after header decoded if not true.
317  if(surf_pix_fmt == AV_PIX_FMT_NONE)
318  surf_pix_fmt = AV_PIX_FMT_NV12; // for older drivers
319  if (!avctx->coded_width)
320  avctx->coded_width = 1280;
321  if (!avctx->coded_height)
322  avctx->coded_height = 720;
323  ret = amf_init_frames_context(avctx, surf_pix_fmt, avctx->coded_width, avctx->coded_height);
324  AMF_GOTO_FAIL_IF_FALSE(avctx, ret == 0, ret, "Failed to init frames context (AMF) : %s\n", av_err2str(ret));
325  }
326  else
327  avctx->pix_fmt = surf_pix_fmt;
328 
329  return 0;
330  }
331 fail:
332  amf_decode_close(avctx);
333  return ret;
334 }
335 
336 static AMF_RESULT amf_get_property_buffer(AMFData *object, const wchar_t *name, AMFBuffer **val)
337 {
338  AMF_RESULT res;
339  AMFVariantStruct var;
340  res = AMFVariantInit(&var);
341  if (res == AMF_OK) {
342  res = object->pVtbl->GetProperty(object, name, &var);
343  if (res == AMF_OK) {
344  if (var.type == AMF_VARIANT_INTERFACE) {
345  AMFGuid guid_AMFBuffer = IID_AMFBuffer();
346  AMFInterface *amf_interface = AMFVariantInterface(&var);
347  res = amf_interface->pVtbl->QueryInterface(amf_interface, &guid_AMFBuffer, (void**)val);
348  } else {
349  res = AMF_INVALID_DATA_TYPE;
350  }
351  }
352  AMFVariantClear(&var);
353  }
354  return res;
355 }
356 
357 static int amf_amfsurface_to_avframe(AVCodecContext *avctx, AMFSurface* surface, AVFrame *frame)
358 {
359  AMFVariantStruct var = {0};
360  AMFPlane *plane;
361  int i;
362  int ret;
363  int format_amf;
364 
365  if (avctx->hw_device_ctx && ((AVHWDeviceContext*)avctx->hw_device_ctx->data)->type == AV_HWDEVICE_TYPE_AMF) {
366  // prepare frame similar to ff_get_buffer(avctx, frame, AV_GET_BUFFER_FLAG_REF);
367 
368  ret = ff_decode_frame_props(avctx, frame);
369  if (ret < 0)
370  return ret;
371 
372  avctx->sw_pix_fmt = avctx->pix_fmt;
373 
375  if (ret < 0)
376  return ret;
377  frame->width = avctx->width;
378  frame->height = avctx->height;
379 
380  ////
381  frame->buf[0] = av_buffer_create((uint8_t *)surface, sizeof(surface),
382  amf_free_amfsurface, (void*)avctx,
384  AMF_RETURN_IF_FALSE(avctx, !!frame->buf[0], AVERROR(ENOMEM), "av_buffer_create for amf surface failed.");
385 
386  frame->data[0] = (uint8_t *)surface;
387  frame->format = AV_PIX_FMT_AMF_SURFACE;
388  format_amf = surface->pVtbl->GetFormat(surface);
389  avctx->sw_pix_fmt = av_amf_to_av_format(format_amf);
390  frame->hw_frames_ctx = av_buffer_ref(avctx->hw_frames_ctx);
391  } else {
392  ret = surface->pVtbl->Convert(surface, AMF_MEMORY_HOST);
393  AMF_RETURN_IF_FALSE(avctx, ret == AMF_OK, AVERROR_UNKNOWN, "Convert(amf::AMF_MEMORY_HOST) failed with error %d\n", ret);
394 
395  for (i = 0; i < surface->pVtbl->GetPlanesCount(surface); i++) {
396  plane = surface->pVtbl->GetPlaneAt(surface, i);
397  frame->data[i] = plane->pVtbl->GetNative(plane);
398  frame->linesize[i] = plane->pVtbl->GetHPitch(plane);
399  }
400 
401  frame->buf[0] = av_buffer_create((uint8_t *)surface, sizeof(surface),
402  amf_free_amfsurface, (void*)avctx,
404  AMF_RETURN_IF_FALSE(avctx, !!frame->buf[0], AVERROR(ENOMEM), "av_buffer_create for amf surface failed.");
405 
406  format_amf = surface->pVtbl->GetFormat(surface);
407  frame->format = av_amf_to_av_format(format_amf);
408  }
409 
410  frame->width = avctx->width;
411  frame->height = avctx->height;
412 
413  frame->pts = surface->pVtbl->GetPts(surface);
414 
415  surface->pVtbl->GetProperty(surface, L"FFMPEG:dts", &var);
416  frame->pkt_dts = var.int64Value;
417 
418  frame->duration = surface->pVtbl->GetDuration(surface);
419  if (frame->duration < 0)
420  frame->duration = 0;
421 
422  frame->color_range = avctx->color_range;
423  frame->colorspace = avctx->colorspace;
424  frame->color_trc = avctx->color_trc;
425  frame->color_primaries = avctx->color_primaries;
426 
427  if (frame->color_trc == AVCOL_TRC_SMPTE2084) {
428  AMFBuffer * hdrmeta_buffer = NULL;
429  ret = amf_get_property_buffer((AMFData *)surface, AMF_VIDEO_DECODER_HDR_METADATA, &hdrmeta_buffer);
430  if (hdrmeta_buffer != NULL) {
431  AMFHDRMetadata * hdrmeta = (AMFHDRMetadata*)hdrmeta_buffer->pVtbl->GetNative(hdrmeta_buffer);
432  if (ret != AMF_OK)
433  return ret;
434  if (hdrmeta != NULL) {
436  const int chroma_den = 50000;
437  const int luma_den = 10000;
438 
439  if (!mastering)
440  return AVERROR(ENOMEM);
441 
442  mastering->display_primaries[0][0] = av_make_q(hdrmeta->redPrimary[0], chroma_den);
443  mastering->display_primaries[0][1] = av_make_q(hdrmeta->redPrimary[1], chroma_den);
444 
445  mastering->display_primaries[1][0] = av_make_q(hdrmeta->greenPrimary[0], chroma_den);
446  mastering->display_primaries[1][1] = av_make_q(hdrmeta->greenPrimary[1], chroma_den);
447 
448  mastering->display_primaries[2][0] = av_make_q(hdrmeta->bluePrimary[0], chroma_den);
449  mastering->display_primaries[2][1] = av_make_q(hdrmeta->bluePrimary[1], chroma_den);
450 
451  mastering->white_point[0] = av_make_q(hdrmeta->whitePoint[0], chroma_den);
452  mastering->white_point[1] = av_make_q(hdrmeta->whitePoint[1], chroma_den);
453 
454  mastering->max_luminance = av_make_q(hdrmeta->maxMasteringLuminance, luma_den);
455  mastering->min_luminance = av_make_q(hdrmeta->maxMasteringLuminance, luma_den);
456 
457  mastering->has_luminance = 1;
458  mastering->has_primaries = 1;
459  if (hdrmeta->maxContentLightLevel) {
461 
462  if (!light)
463  return AVERROR(ENOMEM);
464 
465  light->MaxCLL = hdrmeta->maxContentLightLevel;
466  light->MaxFALL = hdrmeta->maxFrameAverageLightLevel;
467  }
468  }
469  }
470  }
471  return 0;
472 }
473 
474 static AMF_RESULT amf_receive_frame(AVCodecContext *avctx, AVFrame *frame)
475 {
476  AMFDecoderContext *ctx = avctx->priv_data;
477  AMF_RESULT ret = AMF_OK;
478  AMFSurface *surface = NULL;
479  AMFData *data_out = NULL;
480 
481  ret = ctx->decoder->pVtbl->QueryOutput(ctx->decoder, &data_out);
482  if (ret != AMF_OK && ret != AMF_REPEAT) {
483  return ret;
484  }
485  if (data_out == NULL) {
486  return AMF_REPEAT;
487  }
488 
489  if (data_out) {
490  AMFGuid guid = IID_AMFSurface();
491  data_out->pVtbl->QueryInterface(data_out, &guid, (void**)&surface); // query for buffer interface
492  data_out->pVtbl->Release(data_out);
493  data_out = NULL;
494  }
495 
496  ret = amf_amfsurface_to_avframe(avctx, surface, frame);
497  AMF_GOTO_FAIL_IF_FALSE(avctx, ret >= 0, AMF_FAIL, "Failed to convert AMFSurface to AVFrame = %d\n", ret);
498  return AMF_OK;
499 fail:
500 
501  if (surface) {
502  surface->pVtbl->Release(surface);
503  surface = NULL;
504  }
505  return ret;
506 }
507 
508 static AMF_RESULT amf_update_buffer_properties(AVCodecContext *avctx, AMFBuffer* buffer, const AVPacket* pkt)
509 {
510  AMF_RESULT res;
511 
512  AMF_RETURN_IF_FALSE(avctx, buffer != NULL, AMF_INVALID_ARG, "update_buffer_properties() - buffer not passed in");
513  AMF_RETURN_IF_FALSE(avctx, pkt != NULL, AMF_INVALID_ARG, "update_buffer_properties() - packet not passed in");
514  buffer->pVtbl->SetPts(buffer, pkt->pts);
515  buffer->pVtbl->SetDuration(buffer, pkt->duration);
516  AMF_ASSIGN_PROPERTY_INT64(res, buffer, L"FFMPEG:dts", pkt->dts);
517  if (res != AMF_OK)
518  av_log(avctx, AV_LOG_VERBOSE, "Failed to assign dts value.");
519  return AMF_OK;
520 }
521 
522 static AMF_RESULT amf_buffer_from_packet(AVCodecContext *avctx, const AVPacket* pkt, AMFBuffer** buffer)
523 {
524  AMFDecoderContext *ctx = avctx->priv_data;
525  AVHWDeviceContext *hw_device_ctx = (AVHWDeviceContext*)ctx->device_ctx_ref->data;
526  AVAMFDeviceContext *amf_device_ctx = (AVAMFDeviceContext *)hw_device_ctx->hwctx;
527  AMFContext *ctxt = amf_device_ctx->context;
528  void *mem;
529  AMF_RESULT err;
530  AMFBuffer *buf = NULL;
531 
532  AMF_RETURN_IF_FALSE(ctxt, pkt != NULL, AMF_INVALID_ARG, "amf_buffer_from_packet() - packet not passed in");
533  AMF_RETURN_IF_FALSE(ctxt, buffer != NULL, AMF_INVALID_ARG, "amf_buffer_from_packet() - buffer pointer not passed in");
534 
535  err = ctxt->pVtbl->AllocBuffer(ctxt, AMF_MEMORY_HOST, pkt->size + AV_INPUT_BUFFER_PADDING_SIZE, buffer);
536  AMF_RETURN_IF_FALSE(ctxt, err == AMF_OK, err, "amf_buffer_from_packet() - failed");
537  buf = *buffer;
538  err = buf->pVtbl->SetSize(buf, pkt->size);
539  AMF_RETURN_IF_FALSE(ctxt, err == AMF_OK, err, "amf_buffer_from_packet() - SetSize failed");
540  // get the memory location and check the buffer was indeed allocated
541  mem = buf->pVtbl->GetNative(buf);
542  AMF_RETURN_IF_FALSE(ctxt, mem != NULL, AMF_INVALID_POINTER, "amf_buffer_from_packet() - GetNative failed");
543 
544  // copy the packet memory and clear data padding
545  memcpy(mem, pkt->data, pkt->size);
546  memset((amf_int8*)(mem)+pkt->size, 0, AV_INPUT_BUFFER_PADDING_SIZE);
547 
548  return amf_update_buffer_properties(avctx, buf, pkt);
549 }
550 
551 static int amf_decode_frame(AVCodecContext *avctx, struct AVFrame *frame)
552 {
553  AMFDecoderContext *ctx = avctx->priv_data;
554  AMFBuffer *buf;
555  AMF_RESULT res;
556  int got_frame = 0;
557  AVPacket *avpkt = ctx->in_pkt;
558 
559  if (!ctx->decoder)
560  return AVERROR(EINVAL);
561 
562  // get packet if needed
563  if(!ctx->drain){
564  if(ctx->resolution_changed)
565  ctx->resolution_changed = 0;
566  else{
567  int ret;
568  av_packet_unref(avpkt);
569  ret = ff_decode_get_packet(avctx, avpkt);
570  if (ret < 0 && ret != AVERROR_EOF)
571  return ret;
572  if (ret == AVERROR_EOF) {
573  //nothing to consume, start external drain
574  ctx->decoder->pVtbl->Drain(ctx->decoder);
575  ctx->drain = 1;
576  }
577  }
578  }
579 
580  if(!ctx->drain){
581  // submit frame
582  res = amf_buffer_from_packet(avctx, avpkt, &buf);
583  AMF_RETURN_IF_FALSE(avctx, res == AMF_OK, 0, "Cannot convert AVPacket to AMFbuffer");
584  do{
585  res = ctx->decoder->pVtbl->SubmitInput(ctx->decoder, (AMFData*) buf);
586  if(res == AMF_DECODER_NO_FREE_SURFACES)
587  {
588  av_usleep(100);
589  }
590  } while (res == AMF_DECODER_NO_FREE_SURFACES);
591 
592  buf->pVtbl->Release(buf);
593 
594  if(res == AMF_DECODER_NO_FREE_SURFACES) {
595  // input is not consumed, need to QueryOutput and submit again
596  av_log(avctx, AV_LOG_VERBOSE, "SubmitInput() returned NO_FREE_SURFACES and came out of loop - should never happen\n");
597  res = AMF_OK;
598  } else if (res == AMF_RESOLUTION_CHANGED) {
599  //input is not consumed, start internal drain
600  ctx->decoder->pVtbl->Drain(ctx->decoder);
601  ctx->drain = 1;
602  // process resolution_changed when internal drain is complete
603  ctx->resolution_changed = 1;
604  res = AMF_OK;
605  } else if (res != AMF_OK && res != AMF_NEED_MORE_INPUT && res != AMF_REPEAT) {
606  av_log(avctx, AV_LOG_ERROR, "SubmitInput() returned error %d\n", res);
607  return AVERROR(EINVAL);
608  }
609  }
610 
611  res = amf_receive_frame(avctx, frame);
612  if (res == AMF_OK)
613  got_frame = 1;
614  else if (res == AMF_REPEAT)
615  // decoder has no output yet
616  res = AMF_OK;
617  else if (res == AMF_EOF) {
618  // drain is complete
619  ctx->drain = 0;
620  if(ctx->resolution_changed){
621  // re-initialze decoder
622  AMFVariantStruct size_var = {0};
623  AMFVariantStruct format_var = {0};
624  res = ctx->decoder->pVtbl->GetProperty(ctx->decoder, AMF_VIDEO_DECODER_CURRENT_SIZE, &size_var);
625  if (res != AMF_OK) {
626  return AVERROR(EINVAL);
627  }
628 
629  avctx->width = size_var.sizeValue.width;
630  avctx->height = size_var.sizeValue.height;
631  avctx->coded_width = size_var.sizeValue.width;
632  avctx->coded_height = size_var.sizeValue.height;
633  res = ctx->decoder->pVtbl->ReInit(ctx->decoder, avctx->width, avctx->height);
634  if (res != AMF_OK) {
635  av_log(avctx, AV_LOG_ERROR, "ReInit() returned %d\n", res);
636  return AVERROR(EINVAL);
637  }
638  res = ctx->decoder->pVtbl->GetProperty(ctx->decoder, AMF_VIDEO_DECODER_OUTPUT_FORMAT, &format_var);
639  if (res == AMF_OK) {
640  res = amf_init_frames_context(avctx, av_amf_to_av_format(format_var.int64Value), avctx->coded_width, avctx->coded_height);
641  }
642 
643  if (res < 0)
644  return AVERROR(EINVAL);
645  }else
646  return AVERROR_EOF;
647  } else {
648  av_log(avctx, AV_LOG_ERROR, "Unkown result from QueryOutput %d\n", res);
649  }
650  return got_frame ? 0 : AVERROR(EAGAIN);
651 }
652 
653 static void amf_decode_flush(AVCodecContext *avctx)
654 {
655  AMFDecoderContext *ctx = avctx->priv_data;
656  ctx->decoder->pVtbl->Flush(ctx->decoder);
657 }
658 
659 #define OFFSET(x) offsetof(AMFDecoderContext, x)
660 #define VD AV_OPT_FLAG_VIDEO_PARAM | AV_OPT_FLAG_DECODING_PARAM
661 
662 static const AVOption options[] = {
663  // Decoder mode
664  { "decoder_mode", "Decoder mode", OFFSET(decoder_mode), AV_OPT_TYPE_INT, { .i64 = -1 }, -1, AMF_VIDEO_DECODER_MODE_LOW_LATENCY, VD, "decoder_mode" },
665  { "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" },
666  { "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" },
667  { "low_latency", "DPB delay is 0", 0, AV_OPT_TYPE_CONST, { .i64 = AMF_VIDEO_DECODER_MODE_LOW_LATENCY }, 0, 0, VD, "decoder_mode" },
668 
669  // Timestamp mode
670  { "timestamp_mode", "Timestamp mode", OFFSET(timestamp_mode), AV_OPT_TYPE_INT, { .i64 = AMF_TS_SORT }, -1, AMF_TS_DECODE, VD, "timestamp_mode" },
671  { "presentation", "Preserve timestamps from input to output", 0, AV_OPT_TYPE_CONST, { .i64 = AMF_TS_PRESENTATION }, 0, 0, VD, "timestamp_mode" },
672  { "sort", "Resort PTS list", 0, AV_OPT_TYPE_CONST, { .i64 = AMF_TS_SORT }, 0, 0, VD, "timestamp_mode" },
673  { "decode", "Decode order", 0, AV_OPT_TYPE_CONST, { .i64 = AMF_TS_DECODE }, 0, 0, VD, "timestamp_mode" },
674 
675  // Reference frame management
676  { "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 },
677  { "dpb_size", "Minimum number of surfaces for reordering", OFFSET(dpb_size), AV_OPT_TYPE_INT, { .i64 = -1 }, -1, 32, VD, NULL },
678 
679  { "lowlatency", "Low latency", OFFSET(lowlatency), AV_OPT_TYPE_INT, { .i64 = -1 }, -1, 1, VD, NULL },
680  { "smart_access_video", "Smart Access Video", OFFSET(smart_access_video), AV_OPT_TYPE_INT, { .i64 = -1 }, -1, 1, VD, NULL },
681  { "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 },
682  { "copy_output", "Copy Output", OFFSET(copy_output), AV_OPT_TYPE_INT, { .i64 = -1 }, -1, 1, VD, NULL },
683 
684  { NULL }
685 };
686 
687 static const AVClass amf_decode_class = {
688  .class_name = "amf",
689  .item_name = av_default_item_name,
690  .option = options,
691  .version = LIBAVUTIL_VERSION_INT,
692 };
693 
694 #define DEFINE_AMF_DECODER(x, X, bsf_name) \
695 const FFCodec ff_##x##_amf_decoder = { \
696  .p.name = #x "_amf", \
697  CODEC_LONG_NAME(#X " AMD AMF video decoder"), \
698  .priv_data_size = sizeof(AMFDecoderContext), \
699  .p.type = AVMEDIA_TYPE_VIDEO, \
700  .p.id = AV_CODEC_ID_##X, \
701  .init = amf_decode_init, \
702  FF_CODEC_RECEIVE_FRAME_CB(amf_decode_frame), \
703  .flush = amf_decode_flush, \
704  .close = amf_decode_close, \
705  .bsfs = bsf_name, \
706  .p.capabilities = AV_CODEC_CAP_HARDWARE | AV_CODEC_CAP_DELAY | AV_CODEC_CAP_AVOID_PROBING, \
707  .p.priv_class = &amf_decode_class, \
708  .p.pix_fmts = amf_dec_pix_fmts, \
709  .hw_configs = amf_hw_configs, \
710  .p.wrapper_name = "amf", \
711  .caps_internal = FF_CODEC_CAP_NOT_INIT_THREADSAFE, \
712 }; \
713 
714 DEFINE_AMF_DECODER(h264, H264, "h264_mp4toannexb")
715 DEFINE_AMF_DECODER(hevc, HEVC, NULL)
716 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:430
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:248
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:699
amf_amfsurface_to_avframe
static int amf_amfsurface_to_avframe(AVCodecContext *avctx, AMFSurface *surface, AVFrame *frame)
Definition: amfdec.c:357
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:551
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:198
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:266
AMF_VIDEO_DECODER_OUTPUT_FORMAT
#define AMF_VIDEO_DECODER_OUTPUT_FORMAT
Definition: amfdec.c:44
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:326
AVFrame
This structure describes decoded (raw) audio or video data.
Definition: frame.h:410
AVCodecContext::color_trc
enum AVColorTransferCharacteristic color_trc
Color Transfer Characteristic.
Definition: avcodec.h:692
AVCOL_RANGE_JPEG
@ AVCOL_RANGE_JPEG
Full range content.
Definition: pixfmt.h:733
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:252
AVPacket::data
uint8_t * data
Definition: packet.h:539
AVOption
AVOption.
Definition: opt.h:429
AVCOL_TRC_UNSPECIFIED
@ AVCOL_TRC_UNSPECIFIED
Definition: pixfmt.h:630
data
const char data[16]
Definition: mxf.c:149
AV_PIX_FMT_YUV420P10
#define AV_PIX_FMT_YUV420P10
Definition: pixfmt.h:515
AV_LOG_VERBOSE
#define AV_LOG_VERBOSE
Detailed information.
Definition: log.h:225
AVPacket::duration
int64_t duration
Duration of this packet in AVStream->time_base units, 0 if unknown.
Definition: packet.h:557
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:162
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:218
AVCOL_SPC_BT2020_CL
@ AVCOL_SPC_BT2020_CL
ITU-R BT2020 constant luminance system.
Definition: pixfmt.h:668
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:75
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:460
fail
#define fail()
Definition: checkasm.h:193
AVCodecContext::thread_count
int thread_count
thread count is used to decide how many independent tasks should be passed to execute()
Definition: avcodec.h:1601
av_amf_to_av_format
enum AVPixelFormat av_amf_to_av_format(enum AMF_SURFACE_FORMAT fmt)
Definition: hwcontext_amf.c:127
val
static double val(void *priv, double ch)
Definition: aeval.c:77
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:326
AVCodecContext::coded_height
int coded_height
Definition: avcodec.h:647
AVHWDeviceContext
This struct aggregates all the (hardware/vendor-specific) "high-level" state, i.e.
Definition: hwcontext.h:61
AVCodecContext::color_primaries
enum AVColorPrimaries color_primaries
Chromaticity coordinates of the source primaries.
Definition: avcodec.h:685
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:209
AVHWFramesContext::height
int height
Definition: hwcontext.h:218
AVCodecContext::extradata_size
int extradata_size
Definition: avcodec.h:538
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:663
amf_update_buffer_properties
static AMF_RESULT amf_update_buffer_properties(AVCodecContext *avctx, AMFBuffer *buffer, const AVPacket *pkt)
Definition: amfdec.c:508
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:354
hwcontext_amf.h
AVAMFDeviceContext::version
int64_t version
version of AMF runtime
Definition: hwcontext_amf.h:38
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:605
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:694
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:75
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:211
AVCodecContext::color_range
enum AVColorRange color_range
MPEG vs JPEG YUV range.
Definition: avcodec.h:709
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:522
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:237
OFFSET
#define OFFSET(x)
Definition: amfdec.c:659
options
Definition: swscale.c:42
time.h
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:313
AVCOL_RANGE_UNSPECIFIED
@ AVCOL_RANGE_UNSPECIFIED
Definition: pixfmt.h:699
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:644
hwcontext_dxva2.h
AVPacket::size
int size
Definition: packet.h:540
AVCodecContext::extra_hw_frames
int extra_hw_frames
Video decoding only.
Definition: avcodec.h:1538
codec_internal.h
AV_PIX_FMT_P012
#define AV_PIX_FMT_P012
Definition: pixfmt.h:569
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:33
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:538
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:82
av_packet_alloc
AVPacket * av_packet_alloc(void)
Allocate an AVPacket and set its fields to default values.
Definition: packet.c:64
AV_LOG_INFO
#define AV_LOG_INFO
Standard information.
Definition: log.h:220
FF_THREAD_FRAME
#define FF_THREAD_FRAME
Decode more than one frame at once.
Definition: avcodec.h:1612
AVCodec::id
enum AVCodecID id
Definition: codec.h:201
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:707
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:532
AVCOL_SPC_BT2020_NCL
@ AVCOL_SPC_BT2020_NCL
ITU-R BT2020 non-constant luminance system.
Definition: pixfmt.h:667
AVCodecContext::extradata
uint8_t * extradata
Out-of-band global headers that may be used by some codecs.
Definition: avcodec.h:537
amf_init_frames_context
static int amf_init_frames_context(AVCodecContext *avctx, int sw_format, int new_width, int new_height)
Definition: amfdec.c:236
amf_dec_pix_fmts
enum AVPixelFormat amf_dec_pix_fmts[]
Definition: amfdec.c:46
hw_device_ctx
static AVBufferRef * hw_device_ctx
Definition: hw_decode.c:45
VD
#define VD
Definition: amfdec.c:660
amf_legacy_driver_no_bitness_detect
static int amf_legacy_driver_no_bitness_detect(AVAMFDeviceContext *amf_device_ctx)
Definition: amfdec.c:73
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:1515
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:632
AVCodecContext::pix_fmt
enum AVPixelFormat pix_fmt
Pixel format, see AV_PIX_FMT_xxx.
Definition: avcodec.h:671
amf_decode_flush
static void amf_decode_flush(AVCodecContext *avctx)
Definition: amfdec.c:653
amf_hw_configs
static const AVCodecHWConfigInternal *const amf_hw_configs[]
Definition: amfdec.c:54
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:1493
AVHWFramesContext
This struct describes a set or pool of "hardware" frames (i.e.
Definition: hwcontext.h:116
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:73
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:80
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:264
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:604
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:687
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:1564
AVCodecContext
main external API structure.
Definition: avcodec.h:451
AVCodecContext::active_thread_type
int active_thread_type
Which multithreading methods are in use by the codec.
Definition: avcodec.h:1620
hwcontext_amf_internal.h
copy_output
static int copy_output(SANMVideoContext *ctx, SANMFrameHeader *hdr)
Definition: sanm.c:1696
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:220
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:474
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:568
AVCodecContext::coded_width
int coded_width
Bitstream width / height, may be different from width/height e.g.
Definition: avcodec.h:647
AVHWFramesContext::initial_pool_size
int initial_pool_size
Initial size of the frame pool.
Definition: hwcontext.h:188
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:336
mem.h
mastering_display_metadata.h
ff_attach_decode_data
int ff_attach_decode_data(AVFrame *frame)
Definition: decode.c:1639
AVPacket
This structure stores compressed data.
Definition: packet.h:516
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:478
AVCodecContext::width
int width
picture width / height.
Definition: avcodec.h:632
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:678
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:658
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:67
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:662
w32dlfcn.h