FFmpeg
qsvdec.c
Go to the documentation of this file.
1 /*
2  * Intel MediaSDK QSV codec-independent code
3  *
4  * copyright (c) 2013 Luca Barbato
5  * copyright (c) 2015 Anton Khirnov <anton@khirnov.net>
6  *
7  * This file is part of FFmpeg.
8  *
9  * FFmpeg is free software; you can redistribute it and/or
10  * modify it under the terms of the GNU Lesser General Public
11  * License as published by the Free Software Foundation; either
12  * version 2.1 of the License, or (at your option) any later version.
13  *
14  * FFmpeg is distributed in the hope that it will be useful,
15  * but WITHOUT ANY WARRANTY; without even the implied warranty of
16  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17  * Lesser General Public License for more details.
18  *
19  * You should have received a copy of the GNU Lesser General Public
20  * License along with FFmpeg; if not, write to the Free Software
21  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
22  */
23 
24 #include "config_components.h"
25 
26 #include <stdint.h>
27 #include <string.h>
28 #include <sys/types.h>
29 
30 #include <mfxvideo.h>
31 
32 #include "libavutil/common.h"
33 #include "libavutil/fifo.h"
34 #include "libavutil/frame.h"
35 #include "libavutil/hwcontext.h"
37 #include "libavutil/mem.h"
38 #include "libavutil/log.h"
39 #include "libavutil/opt.h"
40 #include "libavutil/pixfmt.h"
41 #include "libavutil/time.h"
42 #include "libavutil/imgutils.h"
45 #include "libavutil/avassert.h"
46 
47 #include "avcodec.h"
48 #include "codec_internal.h"
49 #include "internal.h"
50 #include "decode.h"
51 #include "hwconfig.h"
52 #include "qsv.h"
53 #include "qsv_internal.h"
54 #include "refstruct.h"
55 
56 #if QSV_ONEVPL
57 #include <mfxdispatcher.h>
58 #else
59 #define MFXUnload(a) do { } while(0)
60 #endif
61 
62 static const AVRational mfx_tb = { 1, 90000 };
63 
64 #define PTS_TO_MFX_PTS(pts, pts_tb) ((pts) == AV_NOPTS_VALUE ? \
65  MFX_TIMESTAMP_UNKNOWN : pts_tb.num ? \
66  av_rescale_q(pts, pts_tb, mfx_tb) : pts)
67 
68 #define MFX_PTS_TO_PTS(mfx_pts, pts_tb) ((mfx_pts) == MFX_TIMESTAMP_UNKNOWN ? \
69  AV_NOPTS_VALUE : pts_tb.num ? \
70  av_rescale_q(mfx_pts, mfx_tb, pts_tb) : mfx_pts)
71 
72 #define MFX_IMPL_VIA_MASK(impl) (0x0f00 & (impl))
73 
74 typedef struct QSVAsyncFrame {
75  mfxSyncPoint *sync;
78 
79 typedef struct QSVContext {
80  // the session used for decoding
81  mfxSession session;
82  mfxVersion ver;
83  mfxHandleType handle_type;
84 
85  // the session we allocated internally, in case the caller did not provide
86  // one
88 
90 
91  /**
92  * a linked list of frames currently being used by QSV
93  */
95 
99 
101  uint32_t fourcc;
102  mfxFrameInfo frame_info;
106 
107  // options set by the caller
110  int gpu_copy;
111 
113 
114  mfxExtBuffer **ext_buffers;
116 } QSVContext;
117 
118 static const AVCodecHWConfigInternal *const qsv_hw_configs[] = {
119  &(const AVCodecHWConfigInternal) {
120  .public = {
124  .device_type = AV_HWDEVICE_TYPE_QSV,
125  },
126  .hwaccel = NULL,
127  },
128  NULL
129 };
130 
132  AVBufferPool *pool)
133 {
134  int ret = 0;
135 
136  ret = ff_decode_frame_props(avctx, frame);
137  if (ret < 0)
138  return ret;
139 
140  frame->width = avctx->coded_width;
141  frame->height = avctx->coded_height;
142 
143  switch (avctx->pix_fmt) {
144  case AV_PIX_FMT_NV12:
145  frame->linesize[0] = FFALIGN(avctx->coded_width, 128);
146  break;
147  case AV_PIX_FMT_P010:
148  case AV_PIX_FMT_P012:
149  case AV_PIX_FMT_YUYV422:
150  frame->linesize[0] = 2 * FFALIGN(avctx->coded_width, 128);
151  break;
152  case AV_PIX_FMT_Y210:
153  case AV_PIX_FMT_VUYX:
154  case AV_PIX_FMT_XV30:
155  case AV_PIX_FMT_Y212:
156  frame->linesize[0] = 4 * FFALIGN(avctx->coded_width, 128);
157  break;
158  case AV_PIX_FMT_XV36:
159  frame->linesize[0] = 8 * FFALIGN(avctx->coded_width, 128);
160  break;
161  default:
162  av_log(avctx, AV_LOG_ERROR, "Unsupported pixel format.\n");
163  return AVERROR(EINVAL);
164  }
165 
166  frame->buf[0] = av_buffer_pool_get(pool);
167  if (!frame->buf[0])
168  return AVERROR(ENOMEM);
169 
170  frame->data[0] = frame->buf[0]->data;
171  if (avctx->pix_fmt == AV_PIX_FMT_NV12 ||
172  avctx->pix_fmt == AV_PIX_FMT_P010 ||
173  avctx->pix_fmt == AV_PIX_FMT_P012) {
174  frame->linesize[1] = frame->linesize[0];
175  frame->data[1] = frame->data[0] +
176  frame->linesize[0] * FFALIGN(avctx->coded_height, 64);
177  }
178 
180  if (ret < 0)
181  return ret;
182 
183  return 0;
184 }
185 
186 static int qsv_init_session(AVCodecContext *avctx, QSVContext *q, mfxSession session,
187  AVBufferRef *hw_frames_ref, AVBufferRef *hw_device_ref)
188 {
189  int ret;
190  mfxIMPL impl;
191 
192  if (q->gpu_copy == MFX_GPUCOPY_ON &&
193  !(q->iopattern & MFX_IOPATTERN_OUT_SYSTEM_MEMORY)) {
194  av_log(avctx, AV_LOG_WARNING, "GPU-accelerated memory copy "
195  "only works in system memory mode.\n");
196  q->gpu_copy = MFX_GPUCOPY_OFF;
197  }
198  if (session) {
199  q->session = session;
200  } else if (hw_frames_ref) {
201  if (q->internal_qs.session) {
202  MFXClose(q->internal_qs.session);
203  q->internal_qs.session = NULL;
204  }
206 
207  q->frames_ctx.hw_frames_ctx = av_buffer_ref(hw_frames_ref);
208  if (!q->frames_ctx.hw_frames_ctx)
209  return AVERROR(ENOMEM);
210 
212  &q->frames_ctx, q->load_plugins,
213 #if QSV_HAVE_OPAQUE
214  q->iopattern == MFX_IOPATTERN_OUT_OPAQUE_MEMORY,
215 #else
216  0,
217 #endif
218  q->gpu_copy);
219  if (ret < 0) {
221  return ret;
222  }
223 
224  q->session = q->internal_qs.session;
225  } else if (hw_device_ref) {
226  if (q->internal_qs.session) {
227  MFXClose(q->internal_qs.session);
228  q->internal_qs.session = NULL;
229  }
230 
232  hw_device_ref, q->load_plugins, q->gpu_copy);
233  if (ret < 0)
234  return ret;
235 
236  q->session = q->internal_qs.session;
237  } else {
238  if (!q->internal_qs.session) {
240  q->load_plugins, q->gpu_copy);
241  if (ret < 0)
242  return ret;
243  }
244 
245  q->session = q->internal_qs.session;
246  }
247 
248  if (MFXQueryIMPL(q->session, &impl) == MFX_ERR_NONE) {
249  switch (MFX_IMPL_VIA_MASK(impl)) {
250  case MFX_IMPL_VIA_VAAPI:
251  q->handle_type = MFX_HANDLE_VA_DISPLAY;
252  break;
253 
254  case MFX_IMPL_VIA_D3D11:
255  q->handle_type = MFX_HANDLE_D3D11_DEVICE;
256  break;
257 
258  case MFX_IMPL_VIA_D3D9:
259  q->handle_type = MFX_HANDLE_D3D9_DEVICE_MANAGER;
260  break;
261 
262  default:
263  av_assert0(!"should not reach here");
264  }
265  } else {
266  av_log(avctx, AV_LOG_ERROR, "Error querying the implementation. \n");
267  goto fail;
268  }
269 
270  if (MFXQueryVersion(q->session, &q->ver) != MFX_ERR_NONE) {
271  av_log(avctx, AV_LOG_ERROR, "Error querying the session version. \n");
272  goto fail;
273  }
274 
275  /* make sure the decoder is uninitialized */
276  MFXVideoDECODE_Close(q->session);
277 
278  return 0;
279 
280 fail:
281  q->session = NULL;
282 
283  if (q->internal_qs.session) {
284  MFXClose(q->internal_qs.session);
285  q->internal_qs.session = NULL;
286  }
287 
288  if (q->internal_qs.loader) {
290  q->internal_qs.loader = NULL;
291  }
292 
293  return AVERROR_EXTERNAL;
294 }
295 
296 static int qsv_decode_preinit(AVCodecContext *avctx, QSVContext *q, enum AVPixelFormat pix_fmt, mfxVideoParam *param)
297 {
298  mfxSession session = NULL;
299  int iopattern = 0;
300  int ret;
301  enum AVPixelFormat pix_fmts[3] = {
302  AV_PIX_FMT_QSV, /* opaque format in case of video memory output */
303  pix_fmt, /* system memory format obtained from bitstream parser */
304  AV_PIX_FMT_NONE };
305 
306  ret = ff_get_format(avctx, pix_fmts);
307  if (ret < 0) {
308  q->orig_pix_fmt = avctx->pix_fmt = AV_PIX_FMT_NONE;
309  return ret;
310  }
311 
312  if (!q->async_fifo) {
313  q->async_fifo = av_fifo_alloc2(q->async_depth, sizeof(QSVAsyncFrame), 0);
314  if (!q->async_fifo)
315  return AVERROR(ENOMEM);
316  }
317 
318  if (avctx->pix_fmt == AV_PIX_FMT_QSV && avctx->hwaccel_context) {
319  AVQSVContext *user_ctx = avctx->hwaccel_context;
320  session = user_ctx->session;
321  iopattern = user_ctx->iopattern;
322  q->ext_buffers = user_ctx->ext_buffers;
323  q->nb_ext_buffers = user_ctx->nb_ext_buffers;
324  }
325 
326  if (avctx->hw_device_ctx && !avctx->hw_frames_ctx && ret == AV_PIX_FMT_QSV) {
327  AVHWFramesContext *hwframes_ctx;
328  AVQSVFramesContext *frames_hwctx;
329 
331 
332  if (!avctx->hw_frames_ctx) {
333  av_log(avctx, AV_LOG_ERROR, "av_hwframe_ctx_alloc failed\n");
334  return AVERROR(ENOMEM);
335  }
336 
337  hwframes_ctx = (AVHWFramesContext*)avctx->hw_frames_ctx->data;
338  frames_hwctx = hwframes_ctx->hwctx;
339  hwframes_ctx->width = FFALIGN(avctx->coded_width, 32);
340  hwframes_ctx->height = FFALIGN(avctx->coded_height, 32);
341  hwframes_ctx->format = AV_PIX_FMT_QSV;
342  hwframes_ctx->sw_format = avctx->sw_pix_fmt;
343  if (QSV_RUNTIME_VERSION_ATLEAST(q->ver, 2, 9) && q->handle_type != MFX_HANDLE_D3D9_DEVICE_MANAGER)
344  hwframes_ctx->initial_pool_size = 0;
345  else
346  hwframes_ctx->initial_pool_size = q->suggest_pool_size + 16 + avctx->extra_hw_frames;
347  frames_hwctx->frame_type = MFX_MEMTYPE_VIDEO_MEMORY_DECODER_TARGET;
348 
350 
351  if (ret < 0) {
352  av_log(NULL, AV_LOG_ERROR, "Error initializing a QSV frame pool\n");
354  return ret;
355  }
356  }
357 
358  if (avctx->hw_frames_ctx) {
359  AVHWFramesContext *frames_ctx = (AVHWFramesContext*)avctx->hw_frames_ctx->data;
360  AVQSVFramesContext *frames_hwctx = frames_ctx->hwctx;
361 
362  if (!iopattern) {
363 #if QSV_HAVE_OPAQUE
364  if (frames_hwctx->frame_type & MFX_MEMTYPE_OPAQUE_FRAME)
365  iopattern = MFX_IOPATTERN_OUT_OPAQUE_MEMORY;
366  else if (frames_hwctx->frame_type & MFX_MEMTYPE_VIDEO_MEMORY_DECODER_TARGET)
367  iopattern = MFX_IOPATTERN_OUT_VIDEO_MEMORY;
368 #else
369  if (frames_hwctx->frame_type & MFX_MEMTYPE_VIDEO_MEMORY_DECODER_TARGET)
370  iopattern = MFX_IOPATTERN_OUT_VIDEO_MEMORY;
371 #endif
372  }
373  }
374 
375  if (!iopattern)
376  iopattern = MFX_IOPATTERN_OUT_SYSTEM_MEMORY;
377  q->iopattern = iopattern;
378 
379  ff_qsv_print_iopattern(avctx, q->iopattern, "Decoder");
380 
381  ret = qsv_init_session(avctx, q, session, avctx->hw_frames_ctx, avctx->hw_device_ctx);
382  if (ret < 0) {
383  av_log(avctx, AV_LOG_ERROR, "Error initializing an MFX session\n");
384  return ret;
385  }
386 
387  param->IOPattern = q->iopattern;
388  param->AsyncDepth = q->async_depth;
389  param->ExtParam = q->ext_buffers;
390  param->NumExtParam = q->nb_ext_buffers;
391 
392  return 0;
393  }
394 
395 static int qsv_decode_init_context(AVCodecContext *avctx, QSVContext *q, mfxVideoParam *param)
396 {
397  int ret;
398 
399  avctx->width = param->mfx.FrameInfo.CropW;
400  avctx->height = param->mfx.FrameInfo.CropH;
401  avctx->coded_width = param->mfx.FrameInfo.Width;
402  avctx->coded_height = param->mfx.FrameInfo.Height;
403  avctx->level = param->mfx.CodecLevel;
404  avctx->profile = param->mfx.CodecProfile;
405  avctx->field_order = ff_qsv_map_picstruct(param->mfx.FrameInfo.PicStruct);
406  avctx->pix_fmt = ff_qsv_map_fourcc(param->mfx.FrameInfo.FourCC);
407 
408  ret = MFXVideoDECODE_Init(q->session, param);
409  if (ret < 0)
410  return ff_qsv_print_error(avctx, ret,
411  "Error initializing the MFX video decoder");
412 
413  q->frame_info = param->mfx.FrameInfo;
414 
415  if (!avctx->hw_frames_ctx) {
416  ret = av_image_get_buffer_size(avctx->pix_fmt, FFALIGN(avctx->coded_width, 128), FFALIGN(avctx->coded_height, 64), 1);
417  if (ret < 0)
418  return ret;
420  }
421  return 0;
422 }
423 
425  const AVPacket *avpkt, enum AVPixelFormat pix_fmt,
426  mfxVideoParam *param)
427 {
428  int ret;
429  mfxExtVideoSignalInfo video_signal_info = { 0 };
430  mfxExtBuffer *header_ext_params[1] = { (mfxExtBuffer *)&video_signal_info };
431  mfxBitstream bs = { 0 };
432 
433  if (avpkt->size) {
434  bs.Data = avpkt->data;
435  bs.DataLength = avpkt->size;
436  bs.MaxLength = bs.DataLength;
437  bs.TimeStamp = PTS_TO_MFX_PTS(avpkt->pts, avctx->pkt_timebase);
438  if (avctx->field_order == AV_FIELD_PROGRESSIVE)
439  bs.DataFlag |= MFX_BITSTREAM_COMPLETE_FRAME;
440  } else
441  return AVERROR_INVALIDDATA;
442 
443 
444  if(!q->session) {
445  ret = qsv_decode_preinit(avctx, q, pix_fmt, param);
446  if (ret < 0)
447  return ret;
448  }
449 
451  if (ret < 0)
452  return ret;
453 
454  param->mfx.CodecId = ret;
455  video_signal_info.Header.BufferId = MFX_EXTBUFF_VIDEO_SIGNAL_INFO;
456  video_signal_info.Header.BufferSz = sizeof(video_signal_info);
457  // The SDK doesn't support other ext buffers when calling MFXVideoDECODE_DecodeHeader,
458  // so do not append this buffer to the existent buffer array
459  param->ExtParam = header_ext_params;
460  param->NumExtParam = 1;
461  ret = MFXVideoDECODE_DecodeHeader(q->session, &bs, param);
462  if (MFX_ERR_MORE_DATA == ret) {
463  return AVERROR(EAGAIN);
464  }
465  if (ret < 0)
466  return ff_qsv_print_error(avctx, ret,
467  "Error decoding stream header");
468 
469  avctx->color_range = video_signal_info.VideoFullRange ? AVCOL_RANGE_JPEG : AVCOL_RANGE_MPEG;
470 
471  if (video_signal_info.ColourDescriptionPresent) {
472  avctx->color_primaries = video_signal_info.ColourPrimaries;
473  avctx->color_trc = video_signal_info.TransferCharacteristics;
474  avctx->colorspace = video_signal_info.MatrixCoefficients;
475  }
476 
477  param->ExtParam = q->ext_buffers;
478  param->NumExtParam = q->nb_ext_buffers;
479 
480  if (param->mfx.FrameInfo.FrameRateExtN == 0 || param->mfx.FrameInfo.FrameRateExtD == 0) {
481  param->mfx.FrameInfo.FrameRateExtN = 25;
482  param->mfx.FrameInfo.FrameRateExtD = 1;
483  }
484 
485 #if QSV_VERSION_ATLEAST(1, 34)
486  if (QSV_RUNTIME_VERSION_ATLEAST(q->ver, 1, 34) && avctx->codec_id == AV_CODEC_ID_AV1)
487  param->mfx.FilmGrain = (avctx->export_side_data & AV_CODEC_EXPORT_DATA_FILM_GRAIN) ? 0 : param->mfx.FilmGrain;
488 #endif
489 
490  return 0;
491 }
492 
494 {
495  int ret;
496 
497  if (q->pool)
498  ret = qsv_get_continuous_buffer(avctx, frame->frame, q->pool);
499  else
500  ret = ff_get_buffer(avctx, frame->frame, AV_GET_BUFFER_FLAG_REF);
501 
502  if (ret < 0)
503  return ret;
504 
505  if (frame->frame->format == AV_PIX_FMT_QSV) {
506  frame->surface = *(mfxFrameSurface1*)frame->frame->data[3];
507  } else {
508  ret = ff_qsv_map_frame_to_surface(frame->frame, &frame->surface);
509  if (ret < 0) {
510  av_log(avctx, AV_LOG_ERROR, "map frame to surface failed.\n");
511  return ret;
512  }
513  }
514 
515  frame->surface.Info = q->frame_info;
516 
517  if (q->frames_ctx.mids) {
519  if (ret < 0)
520  return ret;
521 
522  frame->surface.Data.MemId = &q->frames_ctx.mids[ret];
523  }
524 
525  frame->surface.Data.ExtParam = frame->ext_param;
526  frame->surface.Data.NumExtParam = 0;
527  frame->num_ext_params = 0;
528  frame->dec_info.Header.BufferId = MFX_EXTBUFF_DECODED_FRAME_INFO;
529  frame->dec_info.Header.BufferSz = sizeof(frame->dec_info);
530  ff_qsv_frame_add_ext_param(avctx, frame, (mfxExtBuffer *)&frame->dec_info);
531 #if QSV_VERSION_ATLEAST(1, 34)
532  if (QSV_RUNTIME_VERSION_ATLEAST(q->ver, 1, 34) && avctx->codec_id == AV_CODEC_ID_AV1) {
533  frame->av1_film_grain_param.Header.BufferId = MFX_EXTBUFF_AV1_FILM_GRAIN_PARAM;
534  frame->av1_film_grain_param.Header.BufferSz = sizeof(frame->av1_film_grain_param);
535  frame->av1_film_grain_param.FilmGrainFlags = 0;
536  ff_qsv_frame_add_ext_param(avctx, frame, (mfxExtBuffer *)&frame->av1_film_grain_param);
537  }
538 #endif
539 
540 #if QSV_VERSION_ATLEAST(1, 35)
541  if ((QSV_RUNTIME_VERSION_ATLEAST(q->ver, 1, 35) && avctx->codec_id == AV_CODEC_ID_HEVC) ||
542  (QSV_RUNTIME_VERSION_ATLEAST(q->ver, 2, 9) && avctx->codec_id == AV_CODEC_ID_AV1)) {
543  frame->mdcv.Header.BufferId = MFX_EXTBUFF_MASTERING_DISPLAY_COLOUR_VOLUME;
544  frame->mdcv.Header.BufferSz = sizeof(frame->mdcv);
545  // The data in mdcv is valid when this flag is 1
546  frame->mdcv.InsertPayloadToggle = 0;
547  ff_qsv_frame_add_ext_param(avctx, frame, (mfxExtBuffer *)&frame->mdcv);
548 
549  frame->clli.Header.BufferId = MFX_EXTBUFF_CONTENT_LIGHT_LEVEL_INFO;
550  frame->clli.Header.BufferSz = sizeof(frame->clli);
551  // The data in clli is valid when this flag is 1
552  frame->clli.InsertPayloadToggle = 0;
553  ff_qsv_frame_add_ext_param(avctx, frame, (mfxExtBuffer *)&frame->clli);
554  }
555 #endif
556 
557  frame->used = 1;
558 
559  return 0;
560 }
561 
563 {
564  QSVFrame *cur = q->work_frames;
565  while (cur) {
566  if (cur->used && !cur->surface.Data.Locked && !cur->queued) {
567  cur->used = 0;
568  av_frame_unref(cur->frame);
569  }
570  cur = cur->next;
571  }
572 }
573 
574 static int get_surface(AVCodecContext *avctx, QSVContext *q, mfxFrameSurface1 **surf)
575 {
576  QSVFrame *frame, **last;
577  int ret;
578 
580 
581  frame = q->work_frames;
582  last = &q->work_frames;
583  while (frame) {
584  if (!frame->used) {
585  ret = alloc_frame(avctx, q, frame);
586  if (ret < 0)
587  return ret;
588  *surf = &frame->surface;
589  return 0;
590  }
591 
592  last = &frame->next;
593  frame = frame->next;
594  }
595 
596  frame = av_mallocz(sizeof(*frame));
597  if (!frame)
598  return AVERROR(ENOMEM);
599  frame->frame = av_frame_alloc();
600  if (!frame->frame) {
601  av_freep(&frame);
602  return AVERROR(ENOMEM);
603  }
604  *last = frame;
605 
606  ret = alloc_frame(avctx, q, frame);
607  if (ret < 0)
608  return ret;
609 
610  *surf = &frame->surface;
611 
612  return 0;
613 }
614 
615 static QSVFrame *find_frame(QSVContext *q, mfxFrameSurface1 *surf)
616 {
617  QSVFrame *cur = q->work_frames;
618  while (cur) {
619  if (surf == &cur->surface)
620  return cur;
621  cur = cur->next;
622  }
623  return NULL;
624 }
625 
626 #if QSV_VERSION_ATLEAST(1, 34)
627 static int qsv_export_film_grain(AVCodecContext *avctx, mfxExtAV1FilmGrainParam *ext_param, AVFrame *frame)
628 {
629  AVFilmGrainParams *fgp;
631  int i;
632 
633  if (!(ext_param->FilmGrainFlags & MFX_FILM_GRAIN_APPLY))
634  return 0;
635 
637 
638  if (!fgp)
639  return AVERROR(ENOMEM);
640 
642  fgp->seed = ext_param->GrainSeed;
643  aom = &fgp->codec.aom;
644 
645  aom->chroma_scaling_from_luma = !!(ext_param->FilmGrainFlags & MFX_FILM_GRAIN_CHROMA_SCALING_FROM_LUMA);
646  aom->scaling_shift = ext_param->GrainScalingMinus8 + 8;
647  aom->ar_coeff_lag = ext_param->ArCoeffLag;
648  aom->ar_coeff_shift = ext_param->ArCoeffShiftMinus6 + 6;
649  aom->grain_scale_shift = ext_param->GrainScaleShift;
650  aom->overlap_flag = !!(ext_param->FilmGrainFlags & MFX_FILM_GRAIN_OVERLAP);
651  aom->limit_output_range = !!(ext_param->FilmGrainFlags & MFX_FILM_GRAIN_CLIP_TO_RESTRICTED_RANGE);
652 
653  aom->num_y_points = ext_param->NumYPoints;
654 
655  for (i = 0; i < aom->num_y_points; i++) {
656  aom->y_points[i][0] = ext_param->PointY[i].Value;
657  aom->y_points[i][1] = ext_param->PointY[i].Scaling;
658  }
659 
660  aom->num_uv_points[0] = ext_param->NumCbPoints;
661 
662  for (i = 0; i < aom->num_uv_points[0]; i++) {
663  aom->uv_points[0][i][0] = ext_param->PointCb[i].Value;
664  aom->uv_points[0][i][1] = ext_param->PointCb[i].Scaling;
665  }
666 
667  aom->num_uv_points[1] = ext_param->NumCrPoints;
668 
669  for (i = 0; i < aom->num_uv_points[1]; i++) {
670  aom->uv_points[1][i][0] = ext_param->PointCr[i].Value;
671  aom->uv_points[1][i][1] = ext_param->PointCr[i].Scaling;
672  }
673 
674  for (i = 0; i < 24; i++)
675  aom->ar_coeffs_y[i] = ext_param->ArCoeffsYPlus128[i] - 128;
676 
677  for (i = 0; i < 25; i++) {
678  aom->ar_coeffs_uv[0][i] = ext_param->ArCoeffsCbPlus128[i] - 128;
679  aom->ar_coeffs_uv[1][i] = ext_param->ArCoeffsCrPlus128[i] - 128;
680  }
681 
682  aom->uv_mult[0] = ext_param->CbMult;
683  aom->uv_mult[1] = ext_param->CrMult;
684  aom->uv_mult_luma[0] = ext_param->CbLumaMult;
685  aom->uv_mult_luma[1] = ext_param->CrLumaMult;
686  aom->uv_offset[0] = ext_param->CbOffset;
687  aom->uv_offset[1] = ext_param->CrOffset;
688 
689  return 0;
690 }
691 #endif
692 
693 #if QSV_VERSION_ATLEAST(1, 35)
694 static int qsv_export_hdr_side_data(AVCodecContext *avctx, mfxExtMasteringDisplayColourVolume *mdcv,
695  mfxExtContentLightLevelInfo *clli, AVFrame *frame)
696 {
697  int ret;
698 
699  // The SDK re-uses this flag for HDR SEI parsing
700  if (mdcv->InsertPayloadToggle) {
701  AVMasteringDisplayMetadata *mastering;
702  const int mapping[3] = {2, 0, 1};
703  const int chroma_den = 50000;
704  const int luma_den = 10000;
705  int i;
706 
707  ret = ff_decode_mastering_display_new(avctx, frame, &mastering);
708  if (ret < 0)
709  return ret;
710 
711  if (mastering) {
712  for (i = 0; i < 3; i++) {
713  const int j = mapping[i];
714  mastering->display_primaries[i][0] = av_make_q(mdcv->DisplayPrimariesX[j], chroma_den);
715  mastering->display_primaries[i][1] = av_make_q(mdcv->DisplayPrimariesY[j], chroma_den);
716  }
717 
718  mastering->white_point[0] = av_make_q(mdcv->WhitePointX, chroma_den);
719  mastering->white_point[1] = av_make_q(mdcv->WhitePointY, chroma_den);
720 
721  mastering->max_luminance = av_make_q(mdcv->MaxDisplayMasteringLuminance, luma_den);
722  mastering->min_luminance = av_make_q(mdcv->MinDisplayMasteringLuminance, luma_den);
723 
724  mastering->has_luminance = 1;
725  mastering->has_primaries = 1;
726  }
727  }
728 
729  // The SDK re-uses this flag for HDR SEI parsing
730  if (clli->InsertPayloadToggle) {
731  AVContentLightMetadata *light;
732 
733  ret = ff_decode_content_light_new(avctx, frame, &light);
734  if (ret < 0)
735  return ret;
736 
737  if (light) {
738  light->MaxCLL = clli->MaxContentLightLevel;
739  light->MaxFALL = clli->MaxPicAverageLightLevel;
740  }
741  }
742 
743  return 0;
744 }
745 
746 static int qsv_export_hdr_side_data_av1(AVCodecContext *avctx, mfxExtMasteringDisplayColourVolume *mdcv,
747  mfxExtContentLightLevelInfo *clli, AVFrame *frame)
748 {
749  if (mdcv->InsertPayloadToggle) {
751  const int chroma_den = 1 << 16;
752  const int max_luma_den = 1 << 8;
753  const int min_luma_den = 1 << 14;
754 
755  if (!mastering)
756  return AVERROR(ENOMEM);
757 
758  for (int i = 0; i < 3; i++) {
759  mastering->display_primaries[i][0] = av_make_q(mdcv->DisplayPrimariesX[i], chroma_den);
760  mastering->display_primaries[i][1] = av_make_q(mdcv->DisplayPrimariesY[i], chroma_den);
761  }
762 
763  mastering->white_point[0] = av_make_q(mdcv->WhitePointX, chroma_den);
764  mastering->white_point[1] = av_make_q(mdcv->WhitePointY, chroma_den);
765 
766  mastering->max_luminance = av_make_q(mdcv->MaxDisplayMasteringLuminance, max_luma_den);
767  mastering->min_luminance = av_make_q(mdcv->MinDisplayMasteringLuminance, min_luma_den);
768 
769  mastering->has_luminance = 1;
770  mastering->has_primaries = 1;
771  }
772 
773  if (clli->InsertPayloadToggle) {
775  if (!light)
776  return AVERROR(ENOMEM);
777 
778  light->MaxCLL = clli->MaxContentLightLevel;
779  light->MaxFALL = clli->MaxPicAverageLightLevel;
780  }
781 
782  return 0;
783 }
784 
785 #endif
786 
787 static int qsv_decode(AVCodecContext *avctx, QSVContext *q,
788  AVFrame *frame, int *got_frame,
789  const AVPacket *avpkt)
790 {
791  mfxFrameSurface1 *insurf;
792  mfxFrameSurface1 *outsurf;
793  mfxSyncPoint *sync;
794  mfxBitstream bs = { { { 0 } } };
795  int ret;
796 
797  if (avpkt->size) {
798  bs.Data = avpkt->data;
799  bs.DataLength = avpkt->size;
800  bs.MaxLength = bs.DataLength;
801  bs.TimeStamp = PTS_TO_MFX_PTS(avpkt->pts, avctx->pkt_timebase);
802  if (avctx->field_order == AV_FIELD_PROGRESSIVE)
803  bs.DataFlag |= MFX_BITSTREAM_COMPLETE_FRAME;
804  }
805 
806  sync = av_mallocz(sizeof(*sync));
807  if (!sync) {
808  av_freep(&sync);
809  return AVERROR(ENOMEM);
810  }
811 
812  do {
813  ret = get_surface(avctx, q, &insurf);
814  if (ret < 0) {
815  av_freep(&sync);
816  return ret;
817  }
818 
819  ret = MFXVideoDECODE_DecodeFrameAsync(q->session, avpkt->size ? &bs : NULL,
820  insurf, &outsurf, sync);
821  if (ret == MFX_WRN_DEVICE_BUSY)
822  av_usleep(500);
823 
824  } while (ret == MFX_WRN_DEVICE_BUSY || ret == MFX_ERR_MORE_SURFACE);
825 
826  if (ret == MFX_ERR_INCOMPATIBLE_VIDEO_PARAM) {
827  q->reinit_flag = 1;
828  av_log(avctx, AV_LOG_DEBUG, "Video parameter change\n");
829  av_freep(&sync);
830  return 0;
831  }
832 
833  if (ret != MFX_ERR_NONE &&
834  ret != MFX_ERR_MORE_DATA &&
835  ret != MFX_WRN_VIDEO_PARAM_CHANGED &&
836  ret != MFX_ERR_MORE_SURFACE) {
837  av_freep(&sync);
838  return ff_qsv_print_error(avctx, ret,
839  "Error during QSV decoding.");
840  }
841 
842  /* make sure we do not enter an infinite loop if the SDK
843  * did not consume any data and did not return anything */
844  if (!*sync && !bs.DataOffset) {
845  bs.DataOffset = avpkt->size;
846  ++q->zero_consume_run;
847  if (q->zero_consume_run > 1 &&
848  (avpkt->size ||
849  ret != MFX_ERR_MORE_DATA))
850  ff_qsv_print_warning(avctx, ret, "A decode call did not consume any data");
851  } else {
852  q->zero_consume_run = 0;
853  }
854 
855  if (*sync) {
856  QSVAsyncFrame aframe;
857  QSVFrame *out_frame = find_frame(q, outsurf);
858 
859  if (!out_frame) {
860  av_log(avctx, AV_LOG_ERROR,
861  "The returned surface does not correspond to any frame\n");
862  av_freep(&sync);
863  return AVERROR_BUG;
864  }
865 
866  out_frame->queued += 1;
867 
868  aframe = (QSVAsyncFrame){ sync, out_frame };
869  av_fifo_write(q->async_fifo, &aframe, 1);
870  } else {
871  av_freep(&sync);
872  }
873 
874  if ((av_fifo_can_read(q->async_fifo) >= q->async_depth) ||
875  (!avpkt->size && av_fifo_can_read(q->async_fifo))) {
876  QSVAsyncFrame aframe;
877  AVFrame *src_frame;
878 
879  av_fifo_read(q->async_fifo, &aframe, 1);
880  aframe.frame->queued -= 1;
881 
882  if (avctx->pix_fmt != AV_PIX_FMT_QSV) {
883  do {
884  ret = MFXVideoCORE_SyncOperation(q->session, *aframe.sync, 1000);
885  } while (ret == MFX_WRN_IN_EXECUTION);
886  }
887 
888  av_freep(&aframe.sync);
889 
890  src_frame = aframe.frame->frame;
891 
892  ret = av_frame_ref(frame, src_frame);
893  if (ret < 0)
894  return ret;
895 
896  outsurf = &aframe.frame->surface;
897 
898  frame->pts = MFX_PTS_TO_PTS(outsurf->Data.TimeStamp, avctx->pkt_timebase);
899 #if QSV_VERSION_ATLEAST(1, 34)
901  QSV_RUNTIME_VERSION_ATLEAST(q->ver, 1, 34) &&
902  avctx->codec_id == AV_CODEC_ID_AV1) {
903  ret = qsv_export_film_grain(avctx, &aframe.frame->av1_film_grain_param, frame);
904 
905  if (ret < 0)
906  return ret;
907  }
908 #endif
909 
910 #if QSV_VERSION_ATLEAST(1, 35)
911  if (QSV_RUNTIME_VERSION_ATLEAST(q->ver, 1, 35) && avctx->codec_id == AV_CODEC_ID_HEVC) {
912  ret = qsv_export_hdr_side_data(avctx, &aframe.frame->mdcv, &aframe.frame->clli, frame);
913 
914  if (ret < 0)
915  return ret;
916  }
917 
918  if (QSV_RUNTIME_VERSION_ATLEAST(q->ver, 2, 9) && avctx->codec_id == AV_CODEC_ID_AV1) {
919  ret = qsv_export_hdr_side_data_av1(avctx, &aframe.frame->mdcv, &aframe.frame->clli, frame);
920  if (ret < 0)
921  return ret;
922  }
923 #endif
924 
925  frame->repeat_pict =
926  outsurf->Info.PicStruct & MFX_PICSTRUCT_FRAME_TRIPLING ? 4 :
927  outsurf->Info.PicStruct & MFX_PICSTRUCT_FRAME_DOUBLING ? 2 :
928  outsurf->Info.PicStruct & MFX_PICSTRUCT_FIELD_REPEATED ? 1 : 0;
930  !!(outsurf->Info.PicStruct & MFX_PICSTRUCT_FIELD_TFF);
931  frame->flags |= AV_FRAME_FLAG_INTERLACED *
932  !(outsurf->Info.PicStruct & MFX_PICSTRUCT_PROGRESSIVE);
933  frame->pict_type = ff_qsv_map_pictype(aframe.frame->dec_info.FrameType);
934 
935  if (avctx->codec_id == AV_CODEC_ID_H264 ||
936  avctx->codec_id == AV_CODEC_ID_HEVC) {
937  if (aframe.frame->dec_info.FrameType & MFX_FRAMETYPE_IDR)
938  frame->flags |= AV_FRAME_FLAG_KEY;
939  else
940  frame->flags &= ~AV_FRAME_FLAG_KEY;
941  } else {
942  if (aframe.frame->dec_info.FrameType & MFX_FRAMETYPE_I)
943  frame->flags |= AV_FRAME_FLAG_KEY;
944  else
945  frame->flags &= ~AV_FRAME_FLAG_KEY;
946  }
947  frame->crop_left = outsurf->Info.CropX;
948  frame->crop_top = outsurf->Info.CropY;
949  frame->crop_right = outsurf->Info.Width - (outsurf->Info.CropX + outsurf->Info.CropW);
950  frame->crop_bottom = outsurf->Info.Height - (outsurf->Info.CropY + outsurf->Info.CropH);
951 
952  /* update the surface properties */
953  if (avctx->pix_fmt == AV_PIX_FMT_QSV)
954  ((mfxFrameSurface1*)frame->data[3])->Info = outsurf->Info;
955 
956  *got_frame = 1;
957  }
958 
959  return bs.DataOffset;
960 }
961 
963 {
964  QSVFrame *cur = q->work_frames;
965 
966  if (q->session)
967  MFXVideoDECODE_Close(q->session);
968 
969  if (q->async_fifo) {
970  QSVAsyncFrame aframe;
971  while (av_fifo_read(q->async_fifo, &aframe, 1) >= 0)
972  av_freep(&aframe.sync);
974  }
975 
976  while (cur) {
977  q->work_frames = cur->next;
978  av_frame_free(&cur->frame);
979  av_freep(&cur);
980  cur = q->work_frames;
981  }
982 
984 
988 }
989 
991  AVFrame *frame, int *got_frame, const AVPacket *pkt)
992 {
993  int ret;
994  mfxVideoParam param = { 0 };
996 
997  if (!pkt->size)
998  return qsv_decode(avctx, q, frame, got_frame, pkt);
999 
1000  /* TODO: flush delayed frames on reinit */
1001 
1002  // sw_pix_fmt, coded_width/height should be set for ff_get_format(),
1003  // assume sw_pix_fmt is NV12 and coded_width/height to be 1280x720,
1004  // the assumption may be not corret but will be updated after header decoded if not true.
1005  if (q->orig_pix_fmt != AV_PIX_FMT_NONE)
1006  pix_fmt = q->orig_pix_fmt;
1007  if (!avctx->coded_width)
1008  avctx->coded_width = 1280;
1009  if (!avctx->coded_height)
1010  avctx->coded_height = 720;
1011 
1012  /* decode zero-size pkt to flush the buffered pkt before reinit */
1013  if (q->reinit_flag) {
1014  AVPacket zero_pkt = {0};
1015  ret = qsv_decode(avctx, q, frame, got_frame, &zero_pkt);
1016  if (ret < 0 || *got_frame)
1017  return ret;
1018  }
1019 
1020  if (q->reinit_flag || !q->session || !q->initialized) {
1021  mfxFrameAllocRequest request;
1022  memset(&request, 0, sizeof(request));
1023 
1024  q->reinit_flag = 0;
1025  ret = qsv_decode_header(avctx, q, pkt, pix_fmt, &param);
1026  if (ret < 0) {
1027  if (ret == AVERROR(EAGAIN))
1028  av_log(avctx, AV_LOG_VERBOSE, "More data is required to decode header\n");
1029  else
1030  av_log(avctx, AV_LOG_ERROR, "Error decoding header\n");
1031  goto reinit_fail;
1032  }
1033  param.IOPattern = q->iopattern;
1034 
1035  q->orig_pix_fmt = avctx->pix_fmt = pix_fmt = ff_qsv_map_fourcc(param.mfx.FrameInfo.FourCC);
1036 
1037  avctx->coded_width = param.mfx.FrameInfo.Width;
1038  avctx->coded_height = param.mfx.FrameInfo.Height;
1039 
1040  ret = MFXVideoDECODE_QueryIOSurf(q->session, &param, &request);
1041  if (ret < 0)
1042  return ff_qsv_print_error(avctx, ret, "Error querying IO surface");
1043 
1044  q->suggest_pool_size = request.NumFrameSuggested;
1045 
1046  ret = qsv_decode_preinit(avctx, q, pix_fmt, &param);
1047  if (ret < 0)
1048  goto reinit_fail;
1049  q->initialized = 0;
1050  }
1051 
1052  if (!q->initialized) {
1053  ret = qsv_decode_init_context(avctx, q, &param);
1054  if (ret < 0)
1055  goto reinit_fail;
1056  q->initialized = 1;
1057  }
1058 
1059  return qsv_decode(avctx, q, frame, got_frame, pkt);
1060 
1061 reinit_fail:
1062  q->orig_pix_fmt = avctx->pix_fmt = AV_PIX_FMT_NONE;
1063  return ret;
1064 }
1065 
1070 };
1071 
1072 typedef struct QSVDecContext {
1073  AVClass *class;
1075 
1077 
1079 
1081 } QSVDecContext;
1082 
1084 {
1085  AVPacket pkt;
1086  while (av_fifo_read(s->packet_fifo, &pkt, 1) >= 0)
1087  av_packet_unref(&pkt);
1088 
1089  av_packet_unref(&s->buffer_pkt);
1090 }
1091 
1093 {
1094  QSVDecContext *s = avctx->priv_data;
1095 
1097 
1099 
1100  av_fifo_freep2(&s->packet_fifo);
1101 
1102  return 0;
1103 }
1104 
1106 {
1107  QSVDecContext *s = avctx->priv_data;
1108  int ret;
1109  const char *uid = NULL;
1110 
1111  if (avctx->codec_id == AV_CODEC_ID_VP8) {
1112  uid = "f622394d8d87452f878c51f2fc9b4131";
1113  } else if (avctx->codec_id == AV_CODEC_ID_VP9) {
1114  uid = "a922394d8d87452f878c51f2fc9b4131";
1115  }
1116  else if (avctx->codec_id == AV_CODEC_ID_HEVC && s->load_plugin != LOAD_PLUGIN_NONE) {
1117  static const char * const uid_hevcdec_sw = "15dd936825ad475ea34e35f3f54217a6";
1118  static const char * const uid_hevcdec_hw = "33a61c0b4c27454ca8d85dde757c6f8e";
1119 
1120  if (s->qsv.load_plugins[0]) {
1121  av_log(avctx, AV_LOG_WARNING,
1122  "load_plugins is not empty, but load_plugin is not set to 'none'."
1123  "The load_plugin value will be ignored.\n");
1124  } else {
1125  if (s->load_plugin == LOAD_PLUGIN_HEVC_SW)
1126  uid = uid_hevcdec_sw;
1127  else
1128  uid = uid_hevcdec_hw;
1129  }
1130  }
1131  if (uid) {
1132  av_freep(&s->qsv.load_plugins);
1133  s->qsv.load_plugins = av_strdup(uid);
1134  if (!s->qsv.load_plugins)
1135  return AVERROR(ENOMEM);
1136  }
1137 
1138  s->qsv.orig_pix_fmt = AV_PIX_FMT_NV12;
1139  s->packet_fifo = av_fifo_alloc2(1, sizeof(AVPacket),
1141  if (!s->packet_fifo) {
1142  ret = AVERROR(ENOMEM);
1143  goto fail;
1144  }
1145 
1146  if (!avctx->pkt_timebase.num)
1147  av_log(avctx, AV_LOG_WARNING, "Invalid pkt_timebase, passing timestamps as-is.\n");
1148 
1149  return 0;
1150 fail:
1151  qsv_decode_close(avctx);
1152  return ret;
1153 }
1154 
1156  int *got_frame, AVPacket *avpkt)
1157 {
1158  QSVDecContext *s = avctx->priv_data;
1159  int ret;
1160 
1161  /* buffer the input packet */
1162  if (avpkt->size) {
1163  AVPacket input_ref;
1164 
1165  ret = av_packet_ref(&input_ref, avpkt);
1166  if (ret < 0)
1167  return ret;
1168  av_fifo_write(s->packet_fifo, &input_ref, 1);
1169  }
1170 
1171  /* process buffered data */
1172  while (!*got_frame) {
1173  /* prepare the input data */
1174  if (s->buffer_pkt.size <= 0) {
1175  /* no more data */
1176  if (!av_fifo_can_read(s->packet_fifo))
1177  return avpkt->size ? avpkt->size : qsv_process_data(avctx, &s->qsv, frame, got_frame, avpkt);
1178  /* in progress of reinit, no read from fifo and keep the buffer_pkt */
1179  if (!s->qsv.reinit_flag) {
1180  av_packet_unref(&s->buffer_pkt);
1181  av_fifo_read(s->packet_fifo, &s->buffer_pkt, 1);
1182  }
1183  }
1184 
1185  ret = qsv_process_data(avctx, &s->qsv, frame, got_frame, &s->buffer_pkt);
1186  if (ret < 0){
1187  if (ret == AVERROR(EAGAIN))
1188  ret = 0;
1189 
1190  /* Drop buffer_pkt when failed to decode the packet. Otherwise,
1191  the decoder will keep decoding the failure packet. */
1192  av_packet_unref(&s->buffer_pkt);
1193  return ret;
1194  }
1195  if (s->qsv.reinit_flag)
1196  continue;
1197 
1198  s->buffer_pkt.size -= ret;
1199  s->buffer_pkt.data += ret;
1200  }
1201 
1202  return avpkt->size;
1203 }
1204 
1206 {
1207  QSVDecContext *s = avctx->priv_data;
1208 
1210 
1211  s->qsv.orig_pix_fmt = AV_PIX_FMT_NONE;
1212  s->qsv.initialized = 0;
1213 }
1214 
1215 #define OFFSET(x) offsetof(QSVDecContext, x)
1216 #define VD AV_OPT_FLAG_VIDEO_PARAM | AV_OPT_FLAG_DECODING_PARAM
1217 
1218 #define DEFINE_QSV_DECODER_WITH_OPTION(x, X, bsf_name, opt) \
1219 static const AVClass x##_qsv_class = { \
1220  .class_name = #x "_qsv", \
1221  .item_name = av_default_item_name, \
1222  .option = opt, \
1223  .version = LIBAVUTIL_VERSION_INT, \
1224 }; \
1225 const FFCodec ff_##x##_qsv_decoder = { \
1226  .p.name = #x "_qsv", \
1227  CODEC_LONG_NAME(#X " video (Intel Quick Sync Video acceleration)"), \
1228  .priv_data_size = sizeof(QSVDecContext), \
1229  .p.type = AVMEDIA_TYPE_VIDEO, \
1230  .p.id = AV_CODEC_ID_##X, \
1231  .init = qsv_decode_init, \
1232  FF_CODEC_DECODE_CB(qsv_decode_frame), \
1233  .flush = qsv_decode_flush, \
1234  .close = qsv_decode_close, \
1235  .bsfs = bsf_name, \
1236  .p.capabilities = AV_CODEC_CAP_DELAY | AV_CODEC_CAP_DR1 | AV_CODEC_CAP_AVOID_PROBING | AV_CODEC_CAP_HYBRID, \
1237  .p.priv_class = &x##_qsv_class, \
1238  .hw_configs = qsv_hw_configs, \
1239  .p.wrapper_name = "qsv", \
1240  .caps_internal = FF_CODEC_CAP_NOT_INIT_THREADSAFE | FF_CODEC_CAP_EXPORTS_CROPPING, \
1241 }; \
1242 
1243 #define DEFINE_QSV_DECODER(x, X, bsf_name) DEFINE_QSV_DECODER_WITH_OPTION(x, X, bsf_name, options)
1244 
1245 #if CONFIG_HEVC_QSV_DECODER
1246 static const AVOption hevc_options[] = {
1247  { "async_depth", "Internal parallelization depth, the higher the value the higher the latency.", OFFSET(qsv.async_depth), AV_OPT_TYPE_INT, { .i64 = ASYNC_DEPTH_DEFAULT }, 1, INT_MAX, VD },
1248 
1249  { "load_plugin", "A user plugin to load in an internal session", OFFSET(load_plugin), AV_OPT_TYPE_INT, { .i64 = LOAD_PLUGIN_HEVC_HW }, LOAD_PLUGIN_NONE, LOAD_PLUGIN_HEVC_HW, VD, .unit = "load_plugin" },
1250  { "none", NULL, 0, AV_OPT_TYPE_CONST, { .i64 = LOAD_PLUGIN_NONE }, 0, 0, VD, .unit = "load_plugin" },
1251  { "hevc_sw", NULL, 0, AV_OPT_TYPE_CONST, { .i64 = LOAD_PLUGIN_HEVC_SW }, 0, 0, VD, .unit = "load_plugin" },
1252  { "hevc_hw", NULL, 0, AV_OPT_TYPE_CONST, { .i64 = LOAD_PLUGIN_HEVC_HW }, 0, 0, VD, .unit = "load_plugin" },
1253 
1254  { "load_plugins", "A :-separate list of hexadecimal plugin UIDs to load in an internal session",
1255  OFFSET(qsv.load_plugins), AV_OPT_TYPE_STRING, { .str = "" }, 0, 0, VD },
1256 
1257  { "gpu_copy", "A GPU-accelerated copy between video and system memory", OFFSET(qsv.gpu_copy), AV_OPT_TYPE_INT, { .i64 = MFX_GPUCOPY_DEFAULT }, MFX_GPUCOPY_DEFAULT, MFX_GPUCOPY_OFF, VD, .unit = "gpu_copy"},
1258  { "default", NULL, 0, AV_OPT_TYPE_CONST, { .i64 = MFX_GPUCOPY_DEFAULT }, 0, 0, VD, .unit = "gpu_copy"},
1259  { "on", NULL, 0, AV_OPT_TYPE_CONST, { .i64 = MFX_GPUCOPY_ON }, 0, 0, VD, .unit = "gpu_copy"},
1260  { "off", NULL, 0, AV_OPT_TYPE_CONST, { .i64 = MFX_GPUCOPY_OFF }, 0, 0, VD, .unit = "gpu_copy"},
1261  { NULL },
1262 };
1263 DEFINE_QSV_DECODER_WITH_OPTION(hevc, HEVC, "hevc_mp4toannexb", hevc_options)
1264 #endif
1265 
1266 static const AVOption options[] = {
1267  { "async_depth", "Internal parallelization depth, the higher the value the higher the latency.", OFFSET(qsv.async_depth), AV_OPT_TYPE_INT, { .i64 = ASYNC_DEPTH_DEFAULT }, 1, INT_MAX, VD },
1268 
1269  { "gpu_copy", "A GPU-accelerated copy between video and system memory", OFFSET(qsv.gpu_copy), AV_OPT_TYPE_INT, { .i64 = MFX_GPUCOPY_DEFAULT }, MFX_GPUCOPY_DEFAULT, MFX_GPUCOPY_OFF, VD, .unit = "gpu_copy"},
1270  { "default", NULL, 0, AV_OPT_TYPE_CONST, { .i64 = MFX_GPUCOPY_DEFAULT }, 0, 0, VD, .unit = "gpu_copy"},
1271  { "on", NULL, 0, AV_OPT_TYPE_CONST, { .i64 = MFX_GPUCOPY_ON }, 0, 0, VD, .unit = "gpu_copy"},
1272  { "off", NULL, 0, AV_OPT_TYPE_CONST, { .i64 = MFX_GPUCOPY_OFF }, 0, 0, VD, .unit = "gpu_copy"},
1273  { NULL },
1274 };
1275 
1276 #if CONFIG_H264_QSV_DECODER
1277 DEFINE_QSV_DECODER(h264, H264, "h264_mp4toannexb")
1278 #endif
1279 
1280 #if CONFIG_MPEG2_QSV_DECODER
1281 DEFINE_QSV_DECODER(mpeg2, MPEG2VIDEO, NULL)
1282 #endif
1283 
1284 #if CONFIG_VC1_QSV_DECODER
1285 DEFINE_QSV_DECODER(vc1, VC1, NULL)
1286 #endif
1287 
1288 #if CONFIG_MJPEG_QSV_DECODER
1289 DEFINE_QSV_DECODER(mjpeg, MJPEG, NULL)
1290 #endif
1291 
1292 #if CONFIG_VP8_QSV_DECODER
1293 DEFINE_QSV_DECODER(vp8, VP8, NULL)
1294 #endif
1295 
1296 #if CONFIG_VP9_QSV_DECODER
1297 DEFINE_QSV_DECODER(vp9, VP9, NULL)
1298 #endif
1299 
1300 #if CONFIG_AV1_QSV_DECODER
1301 DEFINE_QSV_DECODER(av1, AV1, NULL)
1302 #endif
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:427
AVQSVFramesContext::frame_type
int frame_type
A combination of MFX_MEMTYPE_* describing the frame pool.
Definition: hwcontext_qsv.h:75
AVCodecContext::hwaccel_context
void * hwaccel_context
Legacy hardware accelerator context.
Definition: avcodec.h:1451
av_buffer_pool_init
AVBufferPool * av_buffer_pool_init(size_t size, AVBufferRef *(*alloc)(size_t size))
Allocate and initialize a buffer pool.
Definition: buffer.c:280
AV_LOG_WARNING
#define AV_LOG_WARNING
Something somehow does not look correct.
Definition: log.h:186
AVMasteringDisplayMetadata::max_luminance
AVRational max_luminance
Max luminance of mastering display (cd/m^2).
Definition: mastering_display_metadata.h:57
LOAD_PLUGIN_HEVC_HW
@ LOAD_PLUGIN_HEVC_HW
Definition: qsvdec.c:1069
AVPixelFormat
AVPixelFormat
Pixel format.
Definition: pixfmt.h:71
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
uid
UID uid
Definition: mxfenc.c:2422
opt.h
AVCodecContext::colorspace
enum AVColorSpace colorspace
YUV colorspace type.
Definition: avcodec.h:685
ff_get_format
int ff_get_format(AVCodecContext *avctx, const enum AVPixelFormat *fmt)
Select the (possibly hardware accelerated) pixel format.
Definition: decode.c:1241
QSVFramesContext::hw_frames_ctx
AVBufferRef * hw_frames_ctx
Definition: qsv_internal.h:115
AVBufferPool
The buffer pool.
Definition: buffer_internal.h:88
AVBufferRef::data
uint8_t * data
The data buffer.
Definition: buffer.h:90
AV_FIELD_PROGRESSIVE
@ AV_FIELD_PROGRESSIVE
Definition: defs.h:201
options
static const AVOption options[]
Definition: qsvdec.c:1266
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:197
AVMasteringDisplayMetadata::has_luminance
int has_luminance
Flag indicating whether the luminance (min_ and max_) have been set.
Definition: mastering_display_metadata.h:67
LOAD_PLUGIN_NONE
@ LOAD_PLUGIN_NONE
Definition: qsvdec.c:1067
AVFilmGrainAOMParams::uv_points
uint8_t uv_points[2][10][2]
Definition: film_grain_params.h:63
OFFSET
#define OFFSET(x)
Definition: qsvdec.c:1215
av_frame_free
void av_frame_free(AVFrame **frame)
Free the frame and any dynamically allocated objects in it, e.g.
Definition: frame.c:160
AVContentLightMetadata::MaxCLL
unsigned MaxCLL
Max content light level (cd/m^2).
Definition: mastering_display_metadata.h:111
AVFilmGrainParams::aom
AVFilmGrainAOMParams aom
Definition: film_grain_params.h:260
av_hwframe_ctx_init
int av_hwframe_ctx_init(AVBufferRef *ref)
Finalize the context before use.
Definition: hwcontext.c:322
ff_qsv_close_internal_session
int ff_qsv_close_internal_session(QSVSession *qs)
Definition: qsv.c:1155
AVFrame
This structure describes decoded (raw) audio or video data.
Definition: frame.h:374
ff_qsv_map_pictype
enum AVPictureType ff_qsv_map_pictype(int mfx_pic_type)
Definition: qsv.c:375
AVCodecContext::color_trc
enum AVColorTransferCharacteristic color_trc
Color Transfer Characteristic.
Definition: avcodec.h:678
AVCOL_RANGE_JPEG
@ AVCOL_RANGE_JPEG
Full range content.
Definition: pixfmt.h:686
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:248
internal.h
AVPacket::data
uint8_t * data
Definition: packet.h:520
AVCodecContext::field_order
enum AVFieldOrder field_order
Field order.
Definition: avcodec.h:708
AVOption
AVOption.
Definition: opt.h:357
qsv_decode_close_qsvcontext
static void qsv_decode_close_qsvcontext(QSVContext *q)
Definition: qsvdec.c:962
ff_qsv_find_surface_idx
int ff_qsv_find_surface_idx(QSVFramesContext *ctx, QSVFrame *frame)
Definition: qsv.c:344
AV_PIX_FMT_XV30
#define AV_PIX_FMT_XV30
Definition: pixfmt.h:534
AV_LOG_VERBOSE
#define AV_LOG_VERBOSE
Detailed information.
Definition: log.h:196
QSVContext::work_frames
QSVFrame * work_frames
a linked list of frames currently being used by QSV
Definition: qsvdec.c:94
av_buffer_ref
AVBufferRef * av_buffer_ref(const AVBufferRef *buf)
Create a new reference to an AVBuffer.
Definition: buffer.c:103
AVHWFramesContext::width
int width
The allocated dimensions of the frames in this pool.
Definition: hwcontext.h:217
LOAD_PLUGIN_HEVC_SW
@ LOAD_PLUGIN_HEVC_SW
Definition: qsvdec.c:1068
qsv_decode_init_context
static int qsv_decode_init_context(AVCodecContext *avctx, QSVContext *q, mfxVideoParam *param)
Definition: qsvdec.c:395
QSVFrame::frame
AVFrame * frame
Definition: qsv_internal.h:80
AVQSVContext::iopattern
int iopattern
The IO pattern to use.
Definition: qsv.h:46
QSVFrame::used
int used
Definition: qsv_internal.h:100
AVFilmGrainParams::seed
uint64_t seed
Seed to use for the synthesis process, if the codec allows for it.
Definition: film_grain_params.h:250
ff_qsv_init_session_device
int ff_qsv_init_session_device(AVCodecContext *avctx, mfxSession *psession, AVBufferRef *device_ref, const char *load_plugins, int gpu_copy)
Definition: qsv.c:1028
AV_FRAME_FLAG_TOP_FIELD_FIRST
#define AV_FRAME_FLAG_TOP_FIELD_FIRST
A flag to mark frames where the top field is displayed first if the content is interlaced.
Definition: frame.h:638
AVContentLightMetadata
Content light level needed by to transmit HDR over HDMI (CTA-861.3).
Definition: mastering_display_metadata.h:107
ff_qsv_map_frame_to_surface
int ff_qsv_map_frame_to_surface(const AVFrame *frame, mfxFrameSurface1 *surface)
Definition: qsv.c:283
fifo.h
qsv_decode_flush
static void qsv_decode_flush(AVCodecContext *avctx)
Definition: qsvdec.c:1205
QSVContext::suggest_pool_size
int suggest_pool_size
Definition: qsvdec.c:104
fail
#define fail()
Definition: checkasm.h:185
qsv_decode
static int qsv_decode(AVCodecContext *avctx, QSVContext *q, AVFrame *frame, int *got_frame, const AVPacket *avpkt)
Definition: qsvdec.c:787
av_fifo_write
int av_fifo_write(AVFifo *f, const void *buf, size_t nb_elems)
Write data into a FIFO.
Definition: fifo.c:188
AVFilmGrainAOMParams::grain_scale_shift
int grain_scale_shift
Signals the down shift applied to the generated gaussian numbers during synthesis.
Definition: film_grain_params.h:99
QSVDecContext::qsv
QSVContext qsv
Definition: qsvdec.c:1074
AVCodecContext::coded_height
int coded_height
Definition: avcodec.h:633
AVFilmGrainAOMParams::limit_output_range
int limit_output_range
Signals to clip to limited color levels after film grain application.
Definition: film_grain_params.h:122
AVFilmGrainParams::codec
union AVFilmGrainParams::@407 codec
Additional fields may be added both here and in any structure included.
AVFilmGrainAOMParams::num_y_points
int num_y_points
Number of points, and the scale and value for each point of the piecewise linear scaling function for...
Definition: film_grain_params.h:49
AVRational::num
int num
Numerator.
Definition: rational.h:59
QSVDecContext::packet_fifo
AVFifo * packet_fifo
Definition: qsvdec.c:1078
QSVContext::async_fifo
AVFifo * async_fifo
Definition: qsvdec.c:96
refstruct.h
QSVContext
Definition: qsvdec.c:79
qsv_internal.h
AVFilmGrainAOMParams
This structure describes how to handle film grain synthesis for AOM codecs.
Definition: film_grain_params.h:44
av_frame_alloc
AVFrame * av_frame_alloc(void)
Allocate an AVFrame and set its fields to default values.
Definition: frame.c:148
get_surface
static int get_surface(AVCodecContext *avctx, QSVContext *q, mfxFrameSurface1 **surf)
Definition: qsvdec.c:574
AV_PIX_FMT_Y210
#define AV_PIX_FMT_Y210
Definition: pixfmt.h:532
avassert.h
AVCodecContext::color_primaries
enum AVColorPrimaries color_primaries
Chromaticity coordinates of the source primaries.
Definition: avcodec.h:671
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:180
ff_qsv_print_warning
int ff_qsv_print_warning(void *log_ctx, mfxStatus err, const char *warning_string)
Definition: qsv.c:194
ASYNC_DEPTH_DEFAULT
#define ASYNC_DEPTH_DEFAULT
Definition: qsv_internal.h:50
film_grain_params.h
av_cold
#define av_cold
Definition: attributes.h:90
av_fifo_read
int av_fifo_read(AVFifo *f, void *buf, size_t nb_elems)
Read data from a FIFO.
Definition: fifo.c:240
AVHWFramesContext::height
int height
Definition: hwcontext.h:217
AV_FRAME_FLAG_KEY
#define AV_FRAME_FLAG_KEY
A flag to mark frames that are keyframes.
Definition: frame.h:625
QSVDecContext
Definition: qsvdec.c:1072
QSVContext::iopattern
int iopattern
Definition: qsvdec.c:109
av_buffer_pool_get
AVBufferRef * av_buffer_pool_get(AVBufferPool *pool)
Allocate a new AVBuffer, reusing an old buffer from the pool when available.
Definition: buffer.c:384
AVMasteringDisplayMetadata::white_point
AVRational white_point[2]
CIE 1931 xy chromaticity coords of white point.
Definition: mastering_display_metadata.h:47
s
#define s(width, name)
Definition: cbs_vp9.c:198
hevc_options
static const AVOption hevc_options[]
Definition: videotoolboxenc.c:2932
QSVContext::reinit_flag
int reinit_flag
Definition: qsvdec.c:98
QSVContext::frames_ctx
QSVFramesContext frames_ctx
Definition: qsvdec.c:89
QSVContext::internal_qs
QSVSession internal_qs
Definition: qsvdec.c:87
AV_GET_BUFFER_FLAG_REF
#define AV_GET_BUFFER_FLAG_REF
The decoder will keep a reference to the frame and may reuse it later.
Definition: avcodec.h:425
pix_fmt
static enum AVPixelFormat pix_fmt
Definition: demux_decode.c:41
mfx_tb
static const AVRational mfx_tb
Definition: qsvdec.c:62
AV_CODEC_ID_VP9
@ AV_CODEC_ID_VP9
Definition: codec_id.h:220
QSVContext::ver
mfxVersion ver
Definition: qsvdec.c:82
qsv_process_data
static int qsv_process_data(AVCodecContext *avctx, QSVContext *q, AVFrame *frame, int *got_frame, const AVPacket *pkt)
Definition: qsvdec.c:990
QSV_RUNTIME_VERSION_ATLEAST
#define QSV_RUNTIME_VERSION_ATLEAST(MFX_VERSION, MAJOR, MINOR)
Definition: qsv_internal.h:63
av_film_grain_params_create_side_data
AVFilmGrainParams * av_film_grain_params_create_side_data(AVFrame *frame)
Allocate a complete AVFilmGrainParams and add it to the frame.
Definition: film_grain_params.c:33
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:315
MFX_PTS_TO_PTS
#define MFX_PTS_TO_PTS(mfx_pts, pts_tb)
Definition: qsvdec.c:68
av_assert0
#define av_assert0(cond)
assert() equivalent, that is always enabled.
Definition: avassert.h:40
pix_fmts
static enum AVPixelFormat pix_fmts[]
Definition: libkvazaar.c:304
AV_LOG_DEBUG
#define AV_LOG_DEBUG
Stuff which is only useful for libav* developers.
Definition: log.h:201
decode.h
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:343
av_usleep
int av_usleep(unsigned usec)
Sleep for a period of time.
Definition: time.c:84
AV_CODEC_ID_H264
@ AV_CODEC_ID_H264
Definition: codec_id.h:79
AVQSVContext::nb_ext_buffers
int nb_ext_buffers
Definition: qsv.h:52
ff_decode_mastering_display_new
int ff_decode_mastering_display_new(const AVCodecContext *avctx, AVFrame *frame, AVMasteringDisplayMetadata **mdm)
Wrapper around av_mastering_display_metadata_create_side_data(), which rejects side data overridden b...
Definition: decode.c:2038
AVCodecContext::codec_id
enum AVCodecID codec_id
Definition: avcodec.h:455
if
if(ret)
Definition: filter_design.txt:179
ff_qsv_init_session_frames
int ff_qsv_init_session_frames(AVCodecContext *avctx, mfxSession *psession, QSVFramesContext *qsv_frames_ctx, const char *load_plugins, int opaque, int gpu_copy)
Definition: qsv.c:1105
QSVFrame
Definition: qsv_internal.h:79
AVFilmGrainAOMParams::uv_mult_luma
int uv_mult_luma[2]
Definition: film_grain_params.h:106
AVClass
Describe the class of an AVClass context structure.
Definition: log.h:66
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:210
AVCodecContext::color_range
enum AVColorRange color_range
MPEG vs JPEG YUV range.
Definition: avcodec.h:695
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:280
qsv.h
AV_PIX_FMT_YUYV422
@ AV_PIX_FMT_YUYV422
packed YUV 4:2:2, 16bpp, Y0 Cb Y1 Cr
Definition: pixfmt.h:74
QSV_HAVE_OPAQUE
#define QSV_HAVE_OPAQUE
Definition: qsv_internal.h:68
AVRational
Rational number (pair of numerator and denominator).
Definition: rational.h:58
qsv_decode_preinit
static int qsv_decode_preinit(AVCodecContext *avctx, QSVContext *q, enum AVPixelFormat pix_fmt, mfxVideoParam *param)
Definition: qsvdec.c:296
ff_qsv_print_iopattern
int ff_qsv_print_iopattern(void *log_ctx, int mfx_iopattern, const char *extra_string)
Definition: qsv.c:100
av_buffer_pool_uninit
void av_buffer_pool_uninit(AVBufferPool **ppool)
Mark the pool as being available for freeing.
Definition: buffer.c:322
av_fifo_can_read
size_t av_fifo_can_read(const AVFifo *f)
Definition: fifo.c:87
qsv_get_continuous_buffer
static int qsv_get_continuous_buffer(AVCodecContext *avctx, AVFrame *frame, AVBufferPool *pool)
Definition: qsvdec.c:131
QSVContext::nb_ext_buffers
int nb_ext_buffers
Definition: qsvdec.c:115
QSVFrame::surface
mfxFrameSurface1 surface
Definition: qsv_internal.h:81
time.h
alloc_frame
static int alloc_frame(AVCodecContext *avctx, QSVContext *q, QSVFrame *frame)
Definition: qsvdec.c:493
AV_PIX_FMT_QSV
@ AV_PIX_FMT_QSV
HW acceleration through QSV, data[3] contains a pointer to the mfxFrameSurface1 structure.
Definition: pixfmt.h:247
av_packet_ref
int av_packet_ref(AVPacket *dst, const AVPacket *src)
Setup a new reference to the data described by a given packet.
Definition: packet.c:435
QSVContext::load_plugins
char * load_plugins
Definition: qsvdec.c:112
AVCodecContext::level
int level
Encoding level descriptor.
Definition: avcodec.h:1784
QSVContext::initialized
int initialized
Definition: qsvdec.c:105
QSVContext::fourcc
uint32_t fourcc
Definition: qsvdec.c:101
QSVContext::ext_buffers
mfxExtBuffer ** ext_buffers
Definition: qsvdec.c:114
AVFilmGrainAOMParams::num_uv_points
int num_uv_points[2]
If chroma_scaling_from_luma is set to 0, signals the chroma scaling function parameters.
Definition: film_grain_params.h:62
QSVContext::frame_info
mfxFrameInfo frame_info
Definition: qsvdec.c:102
ff_get_buffer
int ff_get_buffer(AVCodecContext *avctx, AVFrame *frame, int flags)
Get a buffer for a frame.
Definition: decode.c:1575
AVPacket::size
int size
Definition: packet.h:521
AVFifo
Definition: fifo.c:35
av_frame_ref
int av_frame_ref(AVFrame *dst, const AVFrame *src)
Set up a new reference to the data described by the source frame.
Definition: frame.c:384
AVCodecContext::extra_hw_frames
int extra_hw_frames
Video decoding only.
Definition: avcodec.h:1520
DEFINE_QSV_DECODER_WITH_OPTION
#define DEFINE_QSV_DECODER_WITH_OPTION(x, X, bsf_name, opt)
Definition: qsvdec.c:1218
codec_internal.h
AV_PIX_FMT_P012
#define AV_PIX_FMT_P012
Definition: pixfmt.h:529
for
for(k=2;k<=8;++k)
Definition: h264pred_template.c:425
QSVContext::handle_type
mfxHandleType handle_type
Definition: qsvdec.c:83
AVQSVContext::session
mfxSession session
If non-NULL, the session to use for encoding or decoding.
Definition: qsv.h:41
qsv_init_session
static int qsv_init_session(AVCodecContext *avctx, QSVContext *q, mfxSession session, AVBufferRef *hw_frames_ref, AVBufferRef *hw_device_ref)
Definition: qsvdec.c:186
AVCodecContext::pkt_timebase
AVRational pkt_timebase
Timebase in which pkt_dts/pts and AVPacket.dts/pts are expressed.
Definition: avcodec.h:551
av_make_q
static AVRational av_make_q(int num, int den)
Create an AVRational.
Definition: rational.h:71
qsv_decode_close
static av_cold int qsv_decode_close(AVCodecContext *avctx)
Definition: qsvdec.c:1092
AVFilmGrainParams
This structure describes how to handle film grain synthesis in video for specific codecs.
Definition: film_grain_params.h:238
qsv_clear_unused_frames
static void qsv_clear_unused_frames(QSVContext *q)
Definition: qsvdec.c:562
AVCodecHWConfigInternal
Definition: hwconfig.h:25
frame.h
AV_PIX_FMT_Y212
#define AV_PIX_FMT_Y212
Definition: pixfmt.h:533
AVQSVContext::ext_buffers
mfxExtBuffer ** ext_buffers
Extra buffers to pass to encoder or decoder initialization.
Definition: qsv.h:51
av_image_get_buffer_size
int av_image_get_buffer_size(enum AVPixelFormat pix_fmt, int width, int height, int align)
Return the size in bytes of the amount of data required to store an image with the given parameters.
Definition: imgutils.c:466
AVERROR_EXTERNAL
#define AVERROR_EXTERNAL
Generic error in an external library.
Definition: error.h:59
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:68
AVFilmGrainAOMParams::ar_coeffs_y
int8_t ar_coeffs_y[24]
Luma auto-regression coefficients.
Definition: film_grain_params.h:80
QSVFramesContext::mids
QSVMid * mids
The memory ids for the external frames.
Definition: qsv_internal.h:124
QSVAsyncFrame::frame
QSVFrame * frame
Definition: qsvdec.c:76
hwcontext_qsv.h
MFXUnload
#define MFXUnload(a)
Definition: qsvdec.c:59
qsv_decode_header
static int qsv_decode_header(AVCodecContext *avctx, QSVContext *q, const AVPacket *avpkt, enum AVPixelFormat pix_fmt, mfxVideoParam *param)
Definition: qsvdec.c:424
QSVContext::pool
AVBufferPool * pool
Definition: qsvdec.c:103
log.h
ff_qsv_map_picstruct
enum AVFieldOrder ff_qsv_map_picstruct(int mfx_pic_struct)
Definition: qsv.c:357
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:513
qsv_hw_configs
static const AVCodecHWConfigInternal *const qsv_hw_configs[]
Definition: qsvdec.c:118
QSVDecContext::buffer_pkt
AVPacket buffer_pkt
Definition: qsvdec.c:1080
common.h
QSVContext::session
mfxSession session
Definition: qsvdec.c:81
AV_CODEC_ID_HEVC
@ AV_CODEC_ID_HEVC
Definition: codec_id.h:226
av_frame_unref
void av_frame_unref(AVFrame *frame)
Unreference all the buffers referenced by frame and reset the frame fields.
Definition: frame.c:606
av_mallocz
void * av_mallocz(size_t size)
Allocate a memory block with alignment suitable for all memory accesses (including vectors if availab...
Definition: mem.c:256
AVFilmGrainAOMParams::scaling_shift
int scaling_shift
Specifies the shift applied to the chroma components.
Definition: film_grain_params.h:69
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:1497
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:618
AVCodecContext::pix_fmt
enum AVPixelFormat pix_fmt
Pixel format, see AV_PIX_FMT_xxx.
Definition: avcodec.h:657
AV_FRAME_FLAG_INTERLACED
#define AV_FRAME_FLAG_INTERLACED
A flag to mark frames whose content is interlaced.
Definition: frame.h:633
AVCOL_RANGE_MPEG
@ AVCOL_RANGE_MPEG
Narrow or limited range content.
Definition: pixfmt.h:669
QSVDecContext::load_plugin
int load_plugin
Definition: qsvdec.c:1076
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:1475
avcodec.h
AVHWFramesContext
This struct describes a set or pool of "hardware" frames (i.e.
Definition: hwcontext.h:115
find_frame
static QSVFrame * find_frame(QSVContext *q, mfxFrameSurface1 *surf)
Definition: qsvdec.c:615
av_buffer_allocz
AVBufferRef * av_buffer_allocz(size_t size)
Same as av_buffer_alloc(), except the returned buffer will be initialized to zero.
Definition: buffer.c:93
ret
ret
Definition: filter_design.txt:187
pixfmt.h
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
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
QSVFrame::queued
int queued
Definition: qsv_internal.h:99
QSVContext::async_depth
int async_depth
Definition: qsvdec.c:108
QSVSession
Definition: qsv_internal.h:105
AVHWFramesContext::hwctx
void * hwctx
The format-specific data, allocated and freed automatically along with this context.
Definition: hwcontext.h:150
ff_qsv_codec_id_to_mfx
int ff_qsv_codec_id_to_mfx(enum AVCodecID codec_id)
Definition: qsv.c:54
LoadPlugin
LoadPlugin
Definition: qsvdec.c:1066
ff_decode_content_light_new
int ff_decode_content_light_new(const AVCodecContext *avctx, AVFrame *frame, AVContentLightMetadata **clm)
Wrapper around av_content_light_metadata_create_side_data(), which rejects side data overridden by th...
Definition: decode.c:2083
QSVContext::zero_consume_run
int zero_consume_run
Definition: qsvdec.c:97
av_fifo_alloc2
AVFifo * av_fifo_alloc2(size_t nb_elems, size_t elem_size, unsigned int flags)
Allocate and initialize an AVFifo with a given element size.
Definition: fifo.c:47
AV_HWDEVICE_TYPE_QSV
@ AV_HWDEVICE_TYPE_QSV
Definition: hwcontext.h:33
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:1467
AVCodecContext
main external API structure.
Definition: avcodec.h:445
AVFilmGrainAOMParams::ar_coeff_lag
int ar_coeff_lag
Specifies the auto-regression lag.
Definition: film_grain_params.h:74
QSVContext::orig_pix_fmt
enum AVPixelFormat orig_pix_fmt
Definition: qsvdec.c:100
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:45
AVFilmGrainAOMParams::y_points
uint8_t y_points[14][2]
Definition: film_grain_params.h:50
AVFilmGrainAOMParams::uv_offset
int uv_offset[2]
Offset used for component scaling function.
Definition: film_grain_params.h:112
AV_PIX_FMT_NONE
@ AV_PIX_FMT_NONE
Definition: pixfmt.h:72
AV_OPT_TYPE_INT
@ AV_OPT_TYPE_INT
Definition: opt.h:245
AVCodecContext::profile
int profile
profile
Definition: avcodec.h:1640
AVQSVContext
This struct is used for communicating QSV parameters between libavcodec and the caller.
Definition: qsv.h:36
QSVSession::session
mfxSession session
Definition: qsv_internal.h:106
ff_qsv_map_fourcc
enum AVPixelFormat ff_qsv_map_fourcc(uint32_t fourcc)
Definition: qsv.c:203
AVFilmGrainAOMParams::uv_mult
int uv_mult[2]
Specifies the luma/chroma multipliers for the index to the component scaling function.
Definition: film_grain_params.h:105
AVCodecContext::export_side_data
int export_side_data
Bit set of AV_CODEC_EXPORT_DATA_* flags, which affects the kind of metadata exported in frame,...
Definition: avcodec.h:1927
qsv_decode_frame
static int qsv_decode_frame(AVCodecContext *avctx, AVFrame *frame, int *got_frame, AVPacket *avpkt)
Definition: qsvdec.c:1155
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:528
AVFilmGrainAOMParams::overlap_flag
int overlap_flag
Signals whether to overlap film grain blocks.
Definition: film_grain_params.h:117
AVQSVFramesContext
This struct is allocated as AVHWFramesContext.hwctx.
Definition: hwcontext_qsv.h:53
AVCodecContext::coded_width
int coded_width
Bitstream width / height, may be different from width/height e.g.
Definition: avcodec.h:633
AVHWFramesContext::initial_pool_size
int initial_pool_size
Initial size of the frame pool.
Definition: hwcontext.h:187
av_strdup
char * av_strdup(const char *s)
Duplicate a string.
Definition: mem.c:272
mem.h
AVBufferRef
A reference to a data buffer.
Definition: buffer.h:82
qsv_decode_init
static av_cold int qsv_decode_init(AVCodecContext *avctx)
Definition: qsvdec.c:1105
QSVFrame::dec_info
mfxExtDecodedFrameInfo dec_info
Definition: qsv_internal.h:83
mastering_display_metadata.h
ff_attach_decode_data
int ff_attach_decode_data(AVFrame *frame)
Definition: decode.c:1551
qsv_clear_buffers
static void qsv_clear_buffers(QSVDecContext *s)
Definition: qsvdec.c:1083
DEFINE_QSV_DECODER
#define DEFINE_QSV_DECODER(x, X, bsf_name)
Definition: qsvdec.c:1243
FFALIGN
#define FFALIGN(x, a)
Definition: macros.h:78
QSVAsyncFrame::sync
mfxSyncPoint * sync
Definition: qsvdec.c:75
QSVFramesContext
Definition: qsv_internal.h:114
AVCodecContext::priv_data
void * priv_data
Definition: avcodec.h:472
AVContentLightMetadata::MaxFALL
unsigned MaxFALL
Max average light level per frame (cd/m^2).
Definition: mastering_display_metadata.h:116
AVPacket
This structure stores compressed data.
Definition: packet.h:497
av_freep
#define av_freep(p)
Definition: tableprint_vlc.h:34
AVCodecContext::width
int width
picture width / height.
Definition: avcodec.h:618
imgutils.h
PTS_TO_MFX_PTS
#define PTS_TO_MFX_PTS(pts, pts_tb)
Definition: qsvdec.c:64
AV_PIX_FMT_XV36
#define AV_PIX_FMT_XV36
Definition: pixfmt.h:535
AV_CODEC_ID_VP8
@ AV_CODEC_ID_VP8
Definition: codec_id.h:192
hwcontext.h
AVERROR_BUG
#define AVERROR_BUG
Internal bug, also see AVERROR_BUG2.
Definition: error.h:52
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:302
av_log
#define av_log(a,...)
Definition: tableprint_vlc.h:27
VD
#define VD
Definition: qsvdec.c:1216
av_fifo_freep2
void av_fifo_freep2(AVFifo **f)
Free an AVFifo and reset pointer to NULL.
Definition: fifo.c:286
AVERROR_INVALIDDATA
#define AVERROR_INVALIDDATA
Invalid data found when processing input.
Definition: error.h:61
QSVContext::gpu_copy
int gpu_copy
Definition: qsvdec.c:110
AVCodecContext::sw_pix_fmt
enum AVPixelFormat sw_pix_fmt
Nominal unaccelerated pixel format, see AV_PIX_FMT_xxx.
Definition: avcodec.h:664
QSVAsyncFrame
Definition: qsvdec.c:74
AV_OPT_TYPE_STRING
@ AV_OPT_TYPE_STRING
Definition: opt.h:249
AVFilmGrainAOMParams::chroma_scaling_from_luma
int chroma_scaling_from_luma
Signals whether to derive the chroma scaling function from the luma.
Definition: film_grain_params.h:56
AV_PIX_FMT_VUYX
@ AV_PIX_FMT_VUYX
packed VUYX 4:4:4, 32bpp, Variant of VUYA where alpha channel is left undefined
Definition: pixfmt.h:406
QSVSession::loader
void * loader
Definition: qsv_internal.h:111
ff_qsv_frame_add_ext_param
void ff_qsv_frame_add_ext_param(AVCodecContext *avctx, QSVFrame *frame, mfxExtBuffer *param)
Definition: qsv.c:1173
AVCodecHWConfigInternal::public
AVCodecHWConfig public
This is the structure which will be returned to the user by avcodec_get_hw_config().
Definition: hwconfig.h:30
AV_FILM_GRAIN_PARAMS_AV1
@ AV_FILM_GRAIN_PARAMS_AV1
The union is valid when interpreted as AVFilmGrainAOMParams (codec.aom)
Definition: film_grain_params.h:30
QSVFrame::next
struct QSVFrame * next
Definition: qsv_internal.h:102
ff_qsv_print_error
int ff_qsv_print_error(void *log_ctx, mfxStatus err, const char *error_string)
Definition: qsv.c:185
AVFilmGrainParams::type
enum AVFilmGrainParamsType type
Specifies the codec for which this structure is valid.
Definition: film_grain_params.h:242
AV_OPT_TYPE_CONST
@ AV_OPT_TYPE_CONST
Definition: opt.h:254
ff_qsv_init_internal_session
int ff_qsv_init_internal_session(AVCodecContext *avctx, QSVSession *qs, const char *load_plugins, int gpu_copy)
Definition: qsv.c:677
MFX_IMPL_VIA_MASK
#define MFX_IMPL_VIA_MASK(impl)
Definition: qsvdec.c:72
ff_refstruct_unref
void ff_refstruct_unref(void *objp)
Decrement the reference count of the underlying object and automatically free the object if there are...
Definition: refstruct.c:120
AV_CODEC_EXPORT_DATA_FILM_GRAIN
#define AV_CODEC_EXPORT_DATA_FILM_GRAIN
Decoding only.
Definition: avcodec.h:420
AV_FIFO_FLAG_AUTO_GROW
#define AV_FIFO_FLAG_AUTO_GROW
Automatically resize the FIFO on writes, so that the data fits.
Definition: fifo.h:63
AVFilmGrainAOMParams::ar_coeff_shift
int ar_coeff_shift
Specifies the range of the auto-regressive coefficients.
Definition: film_grain_params.h:93
AVFilmGrainAOMParams::ar_coeffs_uv
int8_t ar_coeffs_uv[2][25]
Chroma auto-regression coefficients.
Definition: film_grain_params.h:86