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 <stdint.h>
25 #include <string.h>
26 #include <sys/types.h>
27 
28 #include <mfx/mfxvideo.h>
29 
30 #include "libavutil/common.h"
31 #include "libavutil/fifo.h"
32 #include "libavutil/frame.h"
33 #include "libavutil/hwcontext.h"
35 #include "libavutil/mem.h"
36 #include "libavutil/log.h"
37 #include "libavutil/opt.h"
38 #include "libavutil/pixfmt.h"
39 #include "libavutil/time.h"
40 #include "libavutil/imgutils.h"
41 
42 #include "avcodec.h"
43 #include "internal.h"
44 #include "decode.h"
45 #include "hwconfig.h"
46 #include "qsv.h"
47 #include "qsv_internal.h"
48 
49 static const AVRational mfx_tb = { 1, 90000 };
50 
51 #define PTS_TO_MFX_PTS(pts, pts_tb) ((pts) == AV_NOPTS_VALUE ? \
52  MFX_TIMESTAMP_UNKNOWN : pts_tb.num ? \
53  av_rescale_q(pts, pts_tb, mfx_tb) : pts)
54 
55 #define MFX_PTS_TO_PTS(mfx_pts, pts_tb) ((mfx_pts) == MFX_TIMESTAMP_UNKNOWN ? \
56  AV_NOPTS_VALUE : pts_tb.num ? \
57  av_rescale_q(mfx_pts, mfx_tb, pts_tb) : mfx_pts)
58 
59 typedef struct QSVContext {
60  // the session used for decoding
61  mfxSession session;
62 
63  // the session we allocated internally, in case the caller did not provide
64  // one
66 
68 
69  /**
70  * a linked list of frames currently being used by QSV
71  */
73 
78 
80  uint32_t fourcc;
81  mfxFrameInfo frame_info;
83 
85 
86  // options set by the caller
88  int iopattern;
89  int gpu_copy;
90 
91  char *load_plugins;
92 
93  mfxExtBuffer **ext_buffers;
95 } QSVContext;
96 
97 static const AVCodecHWConfigInternal *const qsv_hw_configs[] = {
98  &(const AVCodecHWConfigInternal) {
99  .public = {
103  .device_type = AV_HWDEVICE_TYPE_QSV,
104  },
105  .hwaccel = NULL,
106  },
107  NULL
108 };
109 
111  AVBufferPool *pool)
112 {
113  int ret = 0;
114 
116 
117  frame->width = avctx->width;
118  frame->height = avctx->height;
119 
120  switch (avctx->pix_fmt) {
121  case AV_PIX_FMT_NV12:
122  frame->linesize[0] = FFALIGN(avctx->width, 128);
123  break;
124  case AV_PIX_FMT_P010:
125  frame->linesize[0] = 2 * FFALIGN(avctx->width, 128);
126  break;
127  default:
128  av_log(avctx, AV_LOG_ERROR, "Unsupported pixel format.\n");
129  return AVERROR(EINVAL);
130  }
131 
132  frame->linesize[1] = frame->linesize[0];
133  frame->buf[0] = av_buffer_pool_get(pool);
134  if (!frame->buf[0])
135  return AVERROR(ENOMEM);
136 
137  frame->data[0] = frame->buf[0]->data;
138  frame->data[1] = frame->data[0] +
139  frame->linesize[0] * FFALIGN(avctx->height, 64);
140 
142  if (ret < 0)
143  return ret;
144 
145  return 0;
146 }
147 
148 static int qsv_init_session(AVCodecContext *avctx, QSVContext *q, mfxSession session,
149  AVBufferRef *hw_frames_ref, AVBufferRef *hw_device_ref)
150 {
151  int ret;
152 
153  if (q->gpu_copy == MFX_GPUCOPY_ON &&
154  !(q->iopattern & MFX_IOPATTERN_OUT_SYSTEM_MEMORY)) {
155  av_log(avctx, AV_LOG_WARNING, "GPU-accelerated memory copy "
156  "only works in system memory mode.\n");
157  q->gpu_copy = MFX_GPUCOPY_OFF;
158  }
159  if (session) {
160  q->session = session;
161  } else if (hw_frames_ref) {
162  if (q->internal_qs.session) {
163  MFXClose(q->internal_qs.session);
164  q->internal_qs.session = NULL;
165  }
167 
168  q->frames_ctx.hw_frames_ctx = av_buffer_ref(hw_frames_ref);
169  if (!q->frames_ctx.hw_frames_ctx)
170  return AVERROR(ENOMEM);
171 
173  &q->frames_ctx, q->load_plugins,
174  q->iopattern == MFX_IOPATTERN_OUT_OPAQUE_MEMORY,
175  q->gpu_copy);
176  if (ret < 0) {
178  return ret;
179  }
180 
181  q->session = q->internal_qs.session;
182  } else if (hw_device_ref) {
183  if (q->internal_qs.session) {
184  MFXClose(q->internal_qs.session);
185  q->internal_qs.session = NULL;
186  }
187 
189  hw_device_ref, q->load_plugins, q->gpu_copy);
190  if (ret < 0)
191  return ret;
192 
193  q->session = q->internal_qs.session;
194  } else {
195  if (!q->internal_qs.session) {
197  q->load_plugins, q->gpu_copy);
198  if (ret < 0)
199  return ret;
200  }
201 
202  q->session = q->internal_qs.session;
203  }
204 
205  /* make sure the decoder is uninitialized */
206  MFXVideoDECODE_Close(q->session);
207 
208  return 0;
209 }
210 
211 static inline unsigned int qsv_fifo_item_size(void)
212 {
213  return sizeof(mfxSyncPoint*) + sizeof(QSVFrame*);
214 }
215 
216 static inline unsigned int qsv_fifo_size(const AVFifoBuffer* fifo)
217 {
218  return av_fifo_size(fifo) / qsv_fifo_item_size();
219 }
220 
221 static int qsv_decode_preinit(AVCodecContext *avctx, QSVContext *q, enum AVPixelFormat pix_fmt, mfxVideoParam *param)
222 {
223  mfxSession session = NULL;
224  int iopattern = 0;
225  int ret;
226  enum AVPixelFormat pix_fmts[3] = {
227  AV_PIX_FMT_QSV, /* opaque format in case of video memory output */
228  pix_fmt, /* system memory format obtained from bitstream parser */
229  AV_PIX_FMT_NONE };
230 
231  ret = ff_get_format(avctx, pix_fmts);
232  if (ret < 0) {
233  q->orig_pix_fmt = avctx->pix_fmt = AV_PIX_FMT_NONE;
234  return ret;
235  }
236 
237  if (!q->async_fifo) {
239  if (!q->async_fifo)
240  return AVERROR(ENOMEM);
241  }
242 
243  if (avctx->pix_fmt == AV_PIX_FMT_QSV && avctx->hwaccel_context) {
244  AVQSVContext *user_ctx = avctx->hwaccel_context;
245  session = user_ctx->session;
246  iopattern = user_ctx->iopattern;
247  q->ext_buffers = user_ctx->ext_buffers;
248  q->nb_ext_buffers = user_ctx->nb_ext_buffers;
249  }
250 
251  if (avctx->hw_frames_ctx) {
252  AVHWFramesContext *frames_ctx = (AVHWFramesContext*)avctx->hw_frames_ctx->data;
253  AVQSVFramesContext *frames_hwctx = frames_ctx->hwctx;
254 
255  if (!iopattern) {
256  if (frames_hwctx->frame_type & MFX_MEMTYPE_OPAQUE_FRAME)
257  iopattern = MFX_IOPATTERN_OUT_OPAQUE_MEMORY;
258  else if (frames_hwctx->frame_type & MFX_MEMTYPE_VIDEO_MEMORY_DECODER_TARGET)
259  iopattern = MFX_IOPATTERN_OUT_VIDEO_MEMORY;
260  }
261  }
262 
263  if (!iopattern)
264  iopattern = MFX_IOPATTERN_OUT_SYSTEM_MEMORY;
265  q->iopattern = iopattern;
266 
267  ff_qsv_print_iopattern(avctx, q->iopattern, "Decoder");
268 
269  ret = qsv_init_session(avctx, q, session, avctx->hw_frames_ctx, avctx->hw_device_ctx);
270  if (ret < 0) {
271  av_log(avctx, AV_LOG_ERROR, "Error initializing an MFX session\n");
272  return ret;
273  }
274 
275  param->IOPattern = q->iopattern;
276  param->AsyncDepth = q->async_depth;
277  param->ExtParam = q->ext_buffers;
278  param->NumExtParam = q->nb_ext_buffers;
279 
280  return 0;
281  }
282 
283 static int qsv_decode_init_context(AVCodecContext *avctx, QSVContext *q, mfxVideoParam *param)
284 {
285  int ret;
286 
287  avctx->width = param->mfx.FrameInfo.CropW;
288  avctx->height = param->mfx.FrameInfo.CropH;
289  avctx->coded_width = param->mfx.FrameInfo.Width;
290  avctx->coded_height = param->mfx.FrameInfo.Height;
291  avctx->level = param->mfx.CodecLevel;
292  avctx->profile = param->mfx.CodecProfile;
293  avctx->field_order = ff_qsv_map_picstruct(param->mfx.FrameInfo.PicStruct);
294  avctx->pix_fmt = ff_qsv_map_fourcc(param->mfx.FrameInfo.FourCC);
295 
296  ret = MFXVideoDECODE_Init(q->session, param);
297  if (ret < 0)
298  return ff_qsv_print_error(avctx, ret,
299  "Error initializing the MFX video decoder");
300 
301  q->frame_info = param->mfx.FrameInfo;
302 
303  if (!avctx->hw_frames_ctx)
305  FFALIGN(avctx->width, 128), FFALIGN(avctx->height, 64), 1), av_buffer_allocz);
306  return 0;
307 }
308 
310  const AVPacket *avpkt, enum AVPixelFormat pix_fmt,
311  mfxVideoParam *param)
312 {
313  int ret;
314 
315  mfxBitstream bs = { 0 };
316 
317  if (avpkt->size) {
318  bs.Data = avpkt->data;
319  bs.DataLength = avpkt->size;
320  bs.MaxLength = bs.DataLength;
321  bs.TimeStamp = PTS_TO_MFX_PTS(avpkt->pts, avctx->pkt_timebase);
322  if (avctx->field_order == AV_FIELD_PROGRESSIVE)
323  bs.DataFlag |= MFX_BITSTREAM_COMPLETE_FRAME;
324  } else
325  return AVERROR_INVALIDDATA;
326 
327 
328  if(!q->session) {
329  ret = qsv_decode_preinit(avctx, q, pix_fmt, param);
330  if (ret < 0)
331  return ret;
332  }
333 
335  if (ret < 0)
336  return ret;
337 
338  param->mfx.CodecId = ret;
339  ret = MFXVideoDECODE_DecodeHeader(q->session, &bs, param);
340  if (MFX_ERR_MORE_DATA == ret) {
341  return AVERROR(EAGAIN);
342  }
343  if (ret < 0)
344  return ff_qsv_print_error(avctx, ret,
345  "Error decoding stream header");
346 
347  return 0;
348 }
349 
351 {
352  int ret;
353 
354  if (q->pool)
355  ret = qsv_get_continuous_buffer(avctx, frame->frame, q->pool);
356  else
357  ret = ff_get_buffer(avctx, frame->frame, AV_GET_BUFFER_FLAG_REF);
358 
359  if (ret < 0)
360  return ret;
361 
362  if (frame->frame->format == AV_PIX_FMT_QSV) {
363  frame->surface = *(mfxFrameSurface1*)frame->frame->data[3];
364  } else {
365  frame->surface.Info = q->frame_info;
366 
367  frame->surface.Data.PitchLow = frame->frame->linesize[0];
368  frame->surface.Data.Y = frame->frame->data[0];
369  frame->surface.Data.UV = frame->frame->data[1];
370  }
371 
372  if (q->frames_ctx.mids) {
374  if (ret < 0)
375  return ret;
376 
377  frame->surface.Data.MemId = &q->frames_ctx.mids[ret];
378  }
379  frame->surface.Data.ExtParam = &frame->ext_param;
380  frame->surface.Data.NumExtParam = 1;
381  frame->ext_param = (mfxExtBuffer*)&frame->dec_info;
382  frame->dec_info.Header.BufferId = MFX_EXTBUFF_DECODED_FRAME_INFO;
383  frame->dec_info.Header.BufferSz = sizeof(frame->dec_info);
384 
385  frame->used = 1;
386 
387  return 0;
388 }
389 
391 {
392  QSVFrame *cur = q->work_frames;
393  while (cur) {
394  if (cur->used && !cur->surface.Data.Locked && !cur->queued) {
395  cur->used = 0;
396  av_frame_unref(cur->frame);
397  }
398  cur = cur->next;
399  }
400 }
401 
402 static int get_surface(AVCodecContext *avctx, QSVContext *q, mfxFrameSurface1 **surf)
403 {
404  QSVFrame *frame, **last;
405  int ret;
406 
408 
409  frame = q->work_frames;
410  last = &q->work_frames;
411  while (frame) {
412  if (!frame->used) {
413  ret = alloc_frame(avctx, q, frame);
414  if (ret < 0)
415  return ret;
416  *surf = &frame->surface;
417  return 0;
418  }
419 
420  last = &frame->next;
421  frame = frame->next;
422  }
423 
424  frame = av_mallocz(sizeof(*frame));
425  if (!frame)
426  return AVERROR(ENOMEM);
427  frame->frame = av_frame_alloc();
428  if (!frame->frame) {
429  av_freep(&frame);
430  return AVERROR(ENOMEM);
431  }
432  *last = frame;
433 
434  ret = alloc_frame(avctx, q, frame);
435  if (ret < 0)
436  return ret;
437 
438  *surf = &frame->surface;
439 
440  return 0;
441 }
442 
443 static QSVFrame *find_frame(QSVContext *q, mfxFrameSurface1 *surf)
444 {
445  QSVFrame *cur = q->work_frames;
446  while (cur) {
447  if (surf == &cur->surface)
448  return cur;
449  cur = cur->next;
450  }
451  return NULL;
452 }
453 
454 static int qsv_decode(AVCodecContext *avctx, QSVContext *q,
455  AVFrame *frame, int *got_frame,
456  const AVPacket *avpkt)
457 {
458  QSVFrame *out_frame;
459  mfxFrameSurface1 *insurf;
460  mfxFrameSurface1 *outsurf;
461  mfxSyncPoint *sync;
462  mfxBitstream bs = { { { 0 } } };
463  int ret;
464 
465  if (avpkt->size) {
466  bs.Data = avpkt->data;
467  bs.DataLength = avpkt->size;
468  bs.MaxLength = bs.DataLength;
469  bs.TimeStamp = PTS_TO_MFX_PTS(avpkt->pts, avctx->pkt_timebase);
470  if (avctx->field_order == AV_FIELD_PROGRESSIVE)
471  bs.DataFlag |= MFX_BITSTREAM_COMPLETE_FRAME;
472  }
473 
474  sync = av_mallocz(sizeof(*sync));
475  if (!sync) {
476  av_freep(&sync);
477  return AVERROR(ENOMEM);
478  }
479 
480  do {
481  ret = get_surface(avctx, q, &insurf);
482  if (ret < 0) {
483  av_freep(&sync);
484  return ret;
485  }
486 
487  ret = MFXVideoDECODE_DecodeFrameAsync(q->session, avpkt->size ? &bs : NULL,
488  insurf, &outsurf, sync);
489  if (ret == MFX_WRN_DEVICE_BUSY)
490  av_usleep(500);
491 
492  } while (ret == MFX_WRN_DEVICE_BUSY || ret == MFX_ERR_MORE_SURFACE);
493 
494  if (ret != MFX_ERR_NONE &&
495  ret != MFX_ERR_MORE_DATA &&
496  ret != MFX_WRN_VIDEO_PARAM_CHANGED &&
497  ret != MFX_ERR_MORE_SURFACE) {
498  av_freep(&sync);
499  return ff_qsv_print_error(avctx, ret,
500  "Error during QSV decoding.");
501  }
502 
503  /* make sure we do not enter an infinite loop if the SDK
504  * did not consume any data and did not return anything */
505  if (!*sync && !bs.DataOffset) {
506  bs.DataOffset = avpkt->size;
507  ++q->zero_consume_run;
508  if (q->zero_consume_run > 1)
509  ff_qsv_print_warning(avctx, ret, "A decode call did not consume any data");
510  } else if (!*sync && bs.DataOffset) {
511  ++q->buffered_count;
512  } else {
513  q->zero_consume_run = 0;
514  }
515 
516  if (*sync) {
517  QSVFrame *out_frame = find_frame(q, outsurf);
518 
519  if (!out_frame) {
520  av_log(avctx, AV_LOG_ERROR,
521  "The returned surface does not correspond to any frame\n");
522  av_freep(&sync);
523  return AVERROR_BUG;
524  }
525 
526  out_frame->queued = 1;
527  av_fifo_generic_write(q->async_fifo, &out_frame, sizeof(out_frame), NULL);
528  av_fifo_generic_write(q->async_fifo, &sync, sizeof(sync), NULL);
529  } else {
530  av_freep(&sync);
531  }
532 
533  if ((qsv_fifo_size(q->async_fifo) >= q->async_depth) ||
534  (!avpkt->size && av_fifo_size(q->async_fifo))) {
535  AVFrame *src_frame;
536 
537  av_fifo_generic_read(q->async_fifo, &out_frame, sizeof(out_frame), NULL);
538  av_fifo_generic_read(q->async_fifo, &sync, sizeof(sync), NULL);
539  out_frame->queued = 0;
540 
541  if (avctx->pix_fmt != AV_PIX_FMT_QSV) {
542  do {
543  ret = MFXVideoCORE_SyncOperation(q->session, *sync, 1000);
544  } while (ret == MFX_WRN_IN_EXECUTION);
545  }
546 
547  av_freep(&sync);
548 
549  src_frame = out_frame->frame;
550 
551  ret = av_frame_ref(frame, src_frame);
552  if (ret < 0)
553  return ret;
554 
555  outsurf = &out_frame->surface;
556 
557  frame->pts = MFX_PTS_TO_PTS(outsurf->Data.TimeStamp, avctx->pkt_timebase);
558 
559  frame->repeat_pict =
560  outsurf->Info.PicStruct & MFX_PICSTRUCT_FRAME_TRIPLING ? 4 :
561  outsurf->Info.PicStruct & MFX_PICSTRUCT_FRAME_DOUBLING ? 2 :
562  outsurf->Info.PicStruct & MFX_PICSTRUCT_FIELD_REPEATED ? 1 : 0;
563  frame->top_field_first =
564  outsurf->Info.PicStruct & MFX_PICSTRUCT_FIELD_TFF;
565  frame->interlaced_frame =
566  !(outsurf->Info.PicStruct & MFX_PICSTRUCT_PROGRESSIVE);
567  frame->pict_type = ff_qsv_map_pictype(out_frame->dec_info.FrameType);
568  //Key frame is IDR frame is only suitable for H264. For HEVC, IRAPs are key frames.
569  if (avctx->codec_id == AV_CODEC_ID_H264)
570  frame->key_frame = !!(out_frame->dec_info.FrameType & MFX_FRAMETYPE_IDR);
571 
572  /* update the surface properties */
573  if (avctx->pix_fmt == AV_PIX_FMT_QSV)
574  ((mfxFrameSurface1*)frame->data[3])->Info = outsurf->Info;
575 
576  *got_frame = 1;
577  }
578 
579  return bs.DataOffset;
580 }
581 
583 {
584  QSVFrame *cur = q->work_frames;
585 
586  if (q->session)
587  MFXVideoDECODE_Close(q->session);
588 
589  while (q->async_fifo && av_fifo_size(q->async_fifo)) {
590  QSVFrame *out_frame;
591  mfxSyncPoint *sync;
592 
593  av_fifo_generic_read(q->async_fifo, &out_frame, sizeof(out_frame), NULL);
594  av_fifo_generic_read(q->async_fifo, &sync, sizeof(sync), NULL);
595 
596  av_freep(&sync);
597  }
598 
599  while (cur) {
600  q->work_frames = cur->next;
601  av_frame_free(&cur->frame);
602  av_freep(&cur);
603  cur = q->work_frames;
604  }
605 
607  q->async_fifo = NULL;
608 
610 
614 }
615 
617  AVFrame *frame, int *got_frame, const AVPacket *pkt)
618 {
619  int ret;
620  mfxVideoParam param = { 0 };
622 
623  if (!pkt->size)
624  return qsv_decode(avctx, q, frame, got_frame, pkt);
625 
626  /* TODO: flush delayed frames on reinit */
627 
628  // sw_pix_fmt, coded_width/height should be set for ff_get_format(),
629  // assume sw_pix_fmt is NV12 and coded_width/height to be 1280x720,
630  // the assumption may be not corret but will be updated after header decoded if not true.
631  if (q->orig_pix_fmt != AV_PIX_FMT_NONE)
632  pix_fmt = q->orig_pix_fmt;
633  if (!avctx->coded_width)
634  avctx->coded_width = 1280;
635  if (!avctx->coded_height)
636  avctx->coded_height = 720;
637 
638  ret = qsv_decode_header(avctx, q, pkt, pix_fmt, &param);
639 
640  if (ret >= 0 && (q->orig_pix_fmt != ff_qsv_map_fourcc(param.mfx.FrameInfo.FourCC) ||
641  avctx->coded_width != param.mfx.FrameInfo.Width ||
642  avctx->coded_height != param.mfx.FrameInfo.Height)) {
643  AVPacket zero_pkt = {0};
644 
645  if (q->buffered_count) {
646  q->reinit_flag = 1;
647  /* decode zero-size pkt to flush the buffered pkt before reinit */
648  q->buffered_count--;
649  return qsv_decode(avctx, q, frame, got_frame, &zero_pkt);
650  }
651  q->reinit_flag = 0;
652 
653  q->orig_pix_fmt = avctx->pix_fmt = pix_fmt = ff_qsv_map_fourcc(param.mfx.FrameInfo.FourCC);
654 
655  avctx->coded_width = param.mfx.FrameInfo.Width;
656  avctx->coded_height = param.mfx.FrameInfo.Height;
657 
658  ret = qsv_decode_preinit(avctx, q, pix_fmt, &param);
659  if (ret < 0)
660  goto reinit_fail;
661  q->initialized = 0;
662  }
663 
664  if (!q->initialized) {
665  ret = qsv_decode_init_context(avctx, q, &param);
666  if (ret < 0)
667  goto reinit_fail;
668  q->initialized = 1;
669  }
670 
671  return qsv_decode(avctx, q, frame, got_frame, pkt);
672 
673 reinit_fail:
674  q->orig_pix_fmt = avctx->pix_fmt = AV_PIX_FMT_NONE;
675  return ret;
676 }
677 
682 };
683 
684 typedef struct QSVDecContext {
685  AVClass *class;
687 
689 
691 
693 } QSVDecContext;
694 
696 {
697  AVPacket pkt;
698  while (av_fifo_size(s->packet_fifo) >= sizeof(pkt)) {
699  av_fifo_generic_read(s->packet_fifo, &pkt, sizeof(pkt), NULL);
701  }
702 
703  av_packet_unref(&s->buffer_pkt);
704 }
705 
707 {
708  QSVDecContext *s = avctx->priv_data;
709 
710  av_freep(&s->qsv.load_plugins);
711 
713 
715 
716  av_fifo_free(s->packet_fifo);
717 
718  return 0;
719 }
720 
722 {
723  QSVDecContext *s = avctx->priv_data;
724  int ret;
725  const char *uid = NULL;
726 
727  if (avctx->codec_id == AV_CODEC_ID_VP8) {
728  uid = "f622394d8d87452f878c51f2fc9b4131";
729  } else if (avctx->codec_id == AV_CODEC_ID_VP9) {
730  uid = "a922394d8d87452f878c51f2fc9b4131";
731  }
732  else if (avctx->codec_id == AV_CODEC_ID_HEVC && s->load_plugin != LOAD_PLUGIN_NONE) {
733  static const char * const uid_hevcdec_sw = "15dd936825ad475ea34e35f3f54217a6";
734  static const char * const uid_hevcdec_hw = "33a61c0b4c27454ca8d85dde757c6f8e";
735 
736  if (s->qsv.load_plugins[0]) {
737  av_log(avctx, AV_LOG_WARNING,
738  "load_plugins is not empty, but load_plugin is not set to 'none'."
739  "The load_plugin value will be ignored.\n");
740  } else {
741  if (s->load_plugin == LOAD_PLUGIN_HEVC_SW)
742  uid = uid_hevcdec_sw;
743  else
744  uid = uid_hevcdec_hw;
745  }
746  }
747  if (uid) {
748  av_freep(&s->qsv.load_plugins);
749  s->qsv.load_plugins = av_strdup(uid);
750  if (!s->qsv.load_plugins)
751  return AVERROR(ENOMEM);
752  }
753 
754  s->qsv.orig_pix_fmt = AV_PIX_FMT_NV12;
755  s->packet_fifo = av_fifo_alloc(sizeof(AVPacket));
756  if (!s->packet_fifo) {
757  ret = AVERROR(ENOMEM);
758  goto fail;
759  }
760 
761  if (!avctx->pkt_timebase.num)
762  av_log(avctx, AV_LOG_WARNING, "Invalid pkt_timebase, passing timestamps as-is.\n");
763 
764  return 0;
765 fail:
766  qsv_decode_close(avctx);
767  return ret;
768 }
769 
770 static int qsv_decode_frame(AVCodecContext *avctx, void *data,
771  int *got_frame, AVPacket *avpkt)
772 {
773  QSVDecContext *s = avctx->priv_data;
774  AVFrame *frame = data;
775  int ret;
776 
777  /* buffer the input packet */
778  if (avpkt->size) {
779  AVPacket input_ref;
780 
781  if (av_fifo_space(s->packet_fifo) < sizeof(input_ref)) {
782  ret = av_fifo_realloc2(s->packet_fifo,
783  av_fifo_size(s->packet_fifo) + sizeof(input_ref));
784  if (ret < 0)
785  return ret;
786  }
787 
788  ret = av_packet_ref(&input_ref, avpkt);
789  if (ret < 0)
790  return ret;
791  av_fifo_generic_write(s->packet_fifo, &input_ref, sizeof(input_ref), NULL);
792  }
793 
794  /* process buffered data */
795  while (!*got_frame) {
796  /* prepare the input data */
797  if (s->buffer_pkt.size <= 0) {
798  /* no more data */
799  if (av_fifo_size(s->packet_fifo) < sizeof(AVPacket))
800  return avpkt->size ? avpkt->size : qsv_process_data(avctx, &s->qsv, frame, got_frame, avpkt);
801  /* in progress of reinit, no read from fifo and keep the buffer_pkt */
802  if (!s->qsv.reinit_flag) {
803  av_packet_unref(&s->buffer_pkt);
804  av_fifo_generic_read(s->packet_fifo, &s->buffer_pkt, sizeof(s->buffer_pkt), NULL);
805  }
806  }
807 
808  ret = qsv_process_data(avctx, &s->qsv, frame, got_frame, &s->buffer_pkt);
809  if (ret < 0){
810  /* Drop buffer_pkt when failed to decode the packet. Otherwise,
811  the decoder will keep decoding the failure packet. */
812  av_packet_unref(&s->buffer_pkt);
813  return ret;
814  }
815  if (s->qsv.reinit_flag)
816  continue;
817 
818  s->buffer_pkt.size -= ret;
819  s->buffer_pkt.data += ret;
820  }
821 
822  return avpkt->size;
823 }
824 
825 static void qsv_decode_flush(AVCodecContext *avctx)
826 {
827  QSVDecContext *s = avctx->priv_data;
828 
830 
831  s->qsv.orig_pix_fmt = AV_PIX_FMT_NONE;
832  s->qsv.initialized = 0;
833 }
834 
835 #define OFFSET(x) offsetof(QSVDecContext, x)
836 #define VD AV_OPT_FLAG_VIDEO_PARAM | AV_OPT_FLAG_DECODING_PARAM
837 
838 #define DEFINE_QSV_DECODER_WITH_OPTION(x, X, bsf_name, opt) \
839 static const AVClass x##_qsv_class = { \
840  .class_name = #x "_qsv", \
841  .item_name = av_default_item_name, \
842  .option = opt, \
843  .version = LIBAVUTIL_VERSION_INT, \
844 }; \
845 const AVCodec ff_##x##_qsv_decoder = { \
846  .name = #x "_qsv", \
847  .long_name = NULL_IF_CONFIG_SMALL(#X " video (Intel Quick Sync Video acceleration)"), \
848  .priv_data_size = sizeof(QSVDecContext), \
849  .type = AVMEDIA_TYPE_VIDEO, \
850  .id = AV_CODEC_ID_##X, \
851  .init = qsv_decode_init, \
852  .decode = qsv_decode_frame, \
853  .flush = qsv_decode_flush, \
854  .close = qsv_decode_close, \
855  .bsfs = bsf_name, \
856  .capabilities = AV_CODEC_CAP_DELAY | AV_CODEC_CAP_DR1 | AV_CODEC_CAP_AVOID_PROBING | AV_CODEC_CAP_HYBRID, \
857  .priv_class = &x##_qsv_class, \
858  .pix_fmts = (const enum AVPixelFormat[]){ AV_PIX_FMT_NV12, \
859  AV_PIX_FMT_P010, \
860  AV_PIX_FMT_QSV, \
861  AV_PIX_FMT_NONE }, \
862  .hw_configs = qsv_hw_configs, \
863  .wrapper_name = "qsv", \
864 }; \
865 
866 #define DEFINE_QSV_DECODER(x, X, bsf_name) DEFINE_QSV_DECODER_WITH_OPTION(x, X, bsf_name, options)
867 
868 #if CONFIG_HEVC_QSV_DECODER
869 static const AVOption hevc_options[] = {
870  { "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 },
871 
872  { "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, "load_plugin" },
873  { "none", NULL, 0, AV_OPT_TYPE_CONST, { .i64 = LOAD_PLUGIN_NONE }, 0, 0, VD, "load_plugin" },
874  { "hevc_sw", NULL, 0, AV_OPT_TYPE_CONST, { .i64 = LOAD_PLUGIN_HEVC_SW }, 0, 0, VD, "load_plugin" },
875  { "hevc_hw", NULL, 0, AV_OPT_TYPE_CONST, { .i64 = LOAD_PLUGIN_HEVC_HW }, 0, 0, VD, "load_plugin" },
876 
877  { "load_plugins", "A :-separate list of hexadecimal plugin UIDs to load in an internal session",
878  OFFSET(qsv.load_plugins), AV_OPT_TYPE_STRING, { .str = "" }, 0, 0, VD },
879 
880  { "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, "gpu_copy"},
881  { "default", NULL, 0, AV_OPT_TYPE_CONST, { .i64 = MFX_GPUCOPY_DEFAULT }, 0, 0, VD, "gpu_copy"},
882  { "on", NULL, 0, AV_OPT_TYPE_CONST, { .i64 = MFX_GPUCOPY_ON }, 0, 0, VD, "gpu_copy"},
883  { "off", NULL, 0, AV_OPT_TYPE_CONST, { .i64 = MFX_GPUCOPY_OFF }, 0, 0, VD, "gpu_copy"},
884  { NULL },
885 };
886 DEFINE_QSV_DECODER_WITH_OPTION(hevc, HEVC, "hevc_mp4toannexb", hevc_options)
887 #endif
888 
889 static const AVOption options[] = {
890  { "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 },
891 
892  { "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, "gpu_copy"},
893  { "default", NULL, 0, AV_OPT_TYPE_CONST, { .i64 = MFX_GPUCOPY_DEFAULT }, 0, 0, VD, "gpu_copy"},
894  { "on", NULL, 0, AV_OPT_TYPE_CONST, { .i64 = MFX_GPUCOPY_ON }, 0, 0, VD, "gpu_copy"},
895  { "off", NULL, 0, AV_OPT_TYPE_CONST, { .i64 = MFX_GPUCOPY_OFF }, 0, 0, VD, "gpu_copy"},
896  { NULL },
897 };
898 
899 #if CONFIG_H264_QSV_DECODER
900 DEFINE_QSV_DECODER(h264, H264, "h264_mp4toannexb")
901 #endif
902 
903 #if CONFIG_MPEG2_QSV_DECODER
904 DEFINE_QSV_DECODER(mpeg2, MPEG2VIDEO, NULL)
905 #endif
906 
907 #if CONFIG_VC1_QSV_DECODER
908 DEFINE_QSV_DECODER(vc1, VC1, NULL)
909 #endif
910 
911 #if CONFIG_MJPEG_QSV_DECODER
912 DEFINE_QSV_DECODER(mjpeg, MJPEG, NULL)
913 #endif
914 
915 #if CONFIG_VP8_QSV_DECODER
916 DEFINE_QSV_DECODER(vp8, VP8, NULL)
917 #endif
918 
919 #if CONFIG_VP9_QSV_DECODER
920 DEFINE_QSV_DECODER(vp9, VP9, NULL)
921 #endif
922 
923 #if CONFIG_AV1_QSV_DECODER
924 DEFINE_QSV_DECODER(av1, AV1, NULL)
925 #endif
hwconfig.h
av_packet_unref
void av_packet_unref(AVPacket *pkt)
Wipe the packet.
Definition: avpacket.c:417
AVCodecContext::hwaccel_context
void * hwaccel_context
Hardware accelerator context.
Definition: avcodec.h:1366
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:266
AV_LOG_WARNING
#define AV_LOG_WARNING
Something somehow does not look correct.
Definition: log.h:186
AVPixelFormat
AVPixelFormat
Pixel format.
Definition: pixfmt.h:64
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:2205
opt.h
qsv_process_data
static int qsv_process_data(AVCodecContext *avctx, QSVContext *q, AVFrame *frame, int *got_frame, const AVPacket *pkt)
Definition: qsvdec.c:616
av_fifo_generic_write
int av_fifo_generic_write(AVFifoBuffer *f, void *src, int size, int(*func)(void *, void *, int))
Feed data from a user-supplied callback to an AVFifoBuffer.
Definition: fifo.c:122
ff_get_format
int ff_get_format(AVCodecContext *avctx, const enum AVPixelFormat *fmt)
Select the (possibly hardware accelerated) pixel format.
Definition: decode.c:1083
QSVFramesContext::hw_frames_ctx
AVBufferRef * hw_frames_ctx
Definition: qsv_internal.h:94
AVBufferPool
The buffer pool.
Definition: buffer_internal.h:78
AVBufferRef::data
uint8_t * data
The data buffer.
Definition: buffer.h:90
av_fifo_free
void av_fifo_free(AVFifoBuffer *f)
Free an AVFifoBuffer.
Definition: fifo.c:55
qsv_fifo_size
static unsigned int qsv_fifo_size(const AVFifoBuffer *fifo)
Definition: qsvdec.c:216
av_frame_free
void av_frame_free(AVFrame **frame)
Free the frame and any dynamically allocated objects in it, e.g.
Definition: frame.c:112
ff_qsv_close_internal_session
int ff_qsv_close_internal_session(QSVSession *qs)
Definition: qsv.c:813
AVFrame
This structure describes decoded (raw) audio or video data.
Definition: frame.h:303
ff_qsv_map_pictype
enum AVPictureType ff_qsv_map_pictype(int mfx_pic_type)
Definition: qsv.c:270
internal.h
AVPacket::data
uint8_t * data
Definition: packet.h:373
AVCodecContext::field_order
enum AVFieldOrder field_order
Field order.
Definition: avcodec.h:985
AVOption
AVOption.
Definition: opt.h:247
ff_qsv_find_surface_idx
int ff_qsv_find_surface_idx(QSVFramesContext *ctx, QSVFrame *frame)
Definition: qsv.c:241
LOAD_PLUGIN_NONE
@ LOAD_PLUGIN_NONE
Definition: qsvdec.c:679
data
const char data[16]
Definition: mxf.c:143
QSVContext::work_frames
QSVFrame * work_frames
a linked list of frames currently being used by QSV
Definition: qsvdec.c:72
LOAD_PLUGIN_HEVC_HW
@ LOAD_PLUGIN_HEVC_HW
Definition: qsvdec.c:681
av_fifo_generic_read
int av_fifo_generic_read(AVFifoBuffer *f, void *dest, int buf_size, void(*func)(void *, void *, int))
Feed data from an AVFifoBuffer to a user-supplied callback.
Definition: fifo.c:213
QSVFrame::frame
AVFrame * frame
Definition: qsv_internal.h:73
AVQSVContext::iopattern
int iopattern
The IO pattern to use.
Definition: qsv.h:46
QSVFrame::used
int used
Definition: qsv_internal.h:80
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:689
AVFifoBuffer
Definition: fifo.h:31
QSVDecContext::packet_fifo
AVFifoBuffer * packet_fifo
Definition: qsvdec.c:690
fifo.h
DEFINE_QSV_DECODER
#define DEFINE_QSV_DECODER(x, X, bsf_name)
Definition: qsvdec.c:866
fail
#define fail()
Definition: checkasm.h:136
QSVDecContext::qsv
QSVContext qsv
Definition: qsvdec.c:686
AVCodecContext::coded_height
int coded_height
Definition: avcodec.h:567
LOAD_PLUGIN_HEVC_SW
@ LOAD_PLUGIN_HEVC_SW
Definition: qsvdec.c:680
options
static const AVOption options[]
Definition: qsvdec.c:889
DEFINE_QSV_DECODER_WITH_OPTION
#define DEFINE_QSV_DECODER_WITH_OPTION(x, X, bsf_name, opt)
Definition: qsvdec.c:838
mfx_tb
static const AVRational mfx_tb
Definition: qsvdec.c:49
AVRational::num
int num
Numerator.
Definition: rational.h:59
QSVContext
Definition: qsvdec.c:59
qsv_internal.h
av_frame_alloc
AVFrame * av_frame_alloc(void)
Allocate an AVFrame and set its fields to default values.
Definition: frame.c:99
find_frame
static QSVFrame * find_frame(QSVContext *q, mfxFrameSurface1 *surf)
Definition: qsvdec.c:443
qsv_decode_header
static int qsv_decode_header(AVCodecContext *avctx, QSVContext *q, const AVPacket *avpkt, enum AVPixelFormat pix_fmt, mfxVideoParam *param)
Definition: qsvdec.c:309
pkt
AVPacket * pkt
Definition: movenc.c:59
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:186
av_fifo_space
int av_fifo_space(const AVFifoBuffer *f)
Return the amount of space in bytes in the AVFifoBuffer, that is the amount of data you can write int...
Definition: fifo.c:82
ASYNC_DEPTH_DEFAULT
#define ASYNC_DEPTH_DEFAULT
Definition: qsv_internal.h:51
av_cold
#define av_cold
Definition: attributes.h:90
QSVDecContext
Definition: qsvdec.c:684
QSVContext::iopattern
int iopattern
Definition: qsvdec.c:88
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:435
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:373
qsv_decode_init
static av_cold int qsv_decode_init(AVCodecContext *avctx)
Definition: qsvdec.c:721
s
#define s(width, name)
Definition: cbs_vp9.c:257
hevc_options
static const AVOption hevc_options[]
Definition: videotoolboxenc.c:2686
QSVContext::reinit_flag
int reinit_flag
Definition: qsvdec.c:77
qsv_fifo_item_size
static unsigned int qsv_fifo_item_size(void)
Definition: qsvdec.c:211
QSVContext::frames_ctx
QSVFramesContext frames_ctx
Definition: qsvdec.c:67
QSVContext::internal_qs
QSVSession internal_qs
Definition: qsvdec.c:65
qsv_decode_frame
static int qsv_decode_frame(AVCodecContext *avctx, void *data, int *got_frame, AVPacket *avpkt)
Definition: qsvdec.c:770
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:357
AV_CODEC_ID_VP9
@ AV_CODEC_ID_VP9
Definition: codec_id.h:218
pix_fmts
static enum AVPixelFormat pix_fmts[]
Definition: libkvazaar.c:290
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:463
pix_fmt
static enum AVPixelFormat pix_fmt
Definition: demuxing_decoding.c:41
av_usleep
int av_usleep(unsigned usec)
Sleep for a period of time.
Definition: time.c:84
av_fifo_realloc2
int av_fifo_realloc2(AVFifoBuffer *f, unsigned int new_size)
Resize an AVFifoBuffer.
Definition: fifo.c:87
AV_CODEC_ID_H264
@ AV_CODEC_ID_H264
Definition: codec_id.h:77
AVQSVContext::nb_ext_buffers
int nb_ext_buffers
Definition: qsv.h:52
AVCodecContext::codec_id
enum AVCodecID codec_id
Definition: avcodec.h:389
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:766
QSVFrame
Definition: qsv_internal.h:72
AVClass
Describe the class of an AVClass context structure.
Definition: log.h:66
NULL
#define NULL
Definition: coverity.c:32
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:125
qsv.h
AVRational
Rational number (pair of numerator and denominator).
Definition: rational.h:58
ff_qsv_print_iopattern
int ff_qsv_print_iopattern(void *log_ctx, int mfx_iopattern, const char *extra_string)
Definition: qsv.c:104
av_buffer_pool_uninit
void av_buffer_pool_uninit(AVBufferPool **ppool)
Mark the pool as being available for freeing.
Definition: buffer.c:308
QSVContext::nb_ext_buffers
int nb_ext_buffers
Definition: qsvdec.c:94
QSVFrame::surface
mfxFrameSurface1 surface
Definition: qsv_internal.h:74
time.h
QSVFramesContext::mids_buf
AVBufferRef * mids_buf
Definition: qsv_internal.h:101
QSVContext::async_fifo
AVFifoBuffer * async_fifo
Definition: qsvdec.c:74
AV_PIX_FMT_QSV
@ AV_PIX_FMT_QSV
HW acceleration through QSV, data[3] contains a pointer to the mfxFrameSurface1 structure.
Definition: pixfmt.h:212
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: avpacket.c:425
QSVContext::load_plugins
char * load_plugins
Definition: qsvdec.c:91
AVCodecContext::level
int level
level
Definition: avcodec.h:1647
QSVContext::initialized
int initialized
Definition: qsvdec.c:84
qsv_clear_buffers
static void qsv_clear_buffers(QSVDecContext *s)
Definition: qsvdec.c:695
QSVContext::fourcc
uint32_t fourcc
Definition: qsvdec.c:80
QSVContext::ext_buffers
mfxExtBuffer ** ext_buffers
Definition: qsvdec.c:93
PTS_TO_MFX_PTS
#define PTS_TO_MFX_PTS(pts, pts_tb)
Definition: qsvdec.c:51
qsv_decode_close_qsvcontext
static void qsv_decode_close_qsvcontext(QSVContext *q)
Definition: qsvdec.c:582
QSVContext::frame_info
mfxFrameInfo frame_info
Definition: qsvdec.c:81
ff_get_buffer
int ff_get_buffer(AVCodecContext *avctx, AVFrame *frame, int flags)
Get a buffer for a frame.
Definition: decode.c:1648
AVPacket::size
int size
Definition: packet.h:374
QSVContext::buffered_count
int buffered_count
Definition: qsvdec.c:76
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:327
AVQSVContext::session
mfxSession session
If non-NULL, the session to use for encoding or decoding.
Definition: qsv.h:41
LoadPlugin
LoadPlugin
Definition: qsvdec.c:678
AVCodecContext::pkt_timebase
AVRational pkt_timebase
Timebase in which pkt_dts/pts and AVPacket.dts/pts are.
Definition: avcodec.h:1720
alloc_frame
static int alloc_frame(AVCodecContext *avctx, QSVContext *q, QSVFrame *frame)
Definition: qsvdec.c:350
qsv_decode
static int qsv_decode(AVCodecContext *avctx, QSVContext *q, AVFrame *frame, int *got_frame, const AVPacket *avpkt)
Definition: qsvdec.c:454
AVCodecHWConfigInternal
Definition: hwconfig.h:29
qsv_decode_close
static av_cold int qsv_decode_close(AVCodecContext *avctx)
Definition: qsvdec.c:706
frame.h
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
get_surface
static int get_surface(AVCodecContext *avctx, QSVContext *q, mfxFrameSurface1 **surf)
Definition: qsvdec.c:402
QSVFramesContext::mids
QSVMid * mids
Definition: qsv_internal.h:102
hwcontext_qsv.h
QSVContext::pool
AVBufferPool * pool
Definition: qsvdec.c:82
log.h
ff_qsv_map_picstruct
enum AVFieldOrder ff_qsv_map_picstruct(int mfx_pic_struct)
Definition: qsv.c:252
AVPacket::pts
int64_t pts
Presentation timestamp in AVStream->time_base units; the time at which the decompressed packet will b...
Definition: packet.h:366
AV_CODEC_HW_CONFIG_METHOD_AD_HOC
@ AV_CODEC_HW_CONFIG_METHOD_AD_HOC
The codec supports this format by some ad-hoc method.
Definition: codec.h:451
QSVDecContext::buffer_pkt
AVPacket buffer_pkt
Definition: qsvdec.c:692
common.h
QSVContext::session
mfxSession session
Definition: qsvdec.c:61
qsv_decode_preinit
static int qsv_decode_preinit(AVCodecContext *avctx, QSVContext *q, enum AVPixelFormat pix_fmt, mfxVideoParam *param)
Definition: qsvdec.c:221
AV_CODEC_ID_HEVC
@ AV_CODEC_ID_HEVC
Definition: codec_id.h:224
av_frame_unref
void av_frame_unref(AVFrame *frame)
Unreference all the buffers referenced by frame and reset the frame fields.
Definition: frame.c:437
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:243
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:1902
AVCodecContext::height
int height
Definition: avcodec.h:552
AVCodecContext::pix_fmt
enum AVPixelFormat pix_fmt
Pixel format, see AV_PIX_FMT_xxx.
Definition: avcodec.h:589
QSVDecContext::load_plugin
int load_plugin
Definition: qsvdec.c:688
OFFSET
#define OFFSET(x)
Definition: qsvdec.c:835
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:1853
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:148
avcodec.h
AVHWFramesContext
This struct describes a set or pool of "hardware" frames (i.e.
Definition: hwcontext.h:124
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:83
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:89
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:79
QSVContext::async_depth
int async_depth
Definition: qsvdec.c:87
MFX_PTS_TO_PTS
#define MFX_PTS_TO_PTS(mfx_pts, pts_tb)
Definition: qsvdec.c:55
QSVSession
Definition: qsv_internal.h:85
AVHWFramesContext::hwctx
void * hwctx
The format-specific data, allocated and freed automatically along with this context.
Definition: hwcontext.h:162
ff_qsv_codec_id_to_mfx
int ff_qsv_codec_id_to_mfx(enum AVCodecID codec_id)
Definition: qsv.c:43
QSVContext::zero_consume_run
int zero_consume_run
Definition: qsvdec.c:75
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:1485
AVCodecContext
main external API structure.
Definition: avcodec.h:379
QSVContext::orig_pix_fmt
enum AVPixelFormat orig_pix_fmt
Definition: qsvdec.c:79
qsv_decode_init_context
static int qsv_decode_init_context(AVCodecContext *avctx, QSVContext *q, mfxVideoParam *param)
Definition: qsvdec.c:283
AV_PIX_FMT_NONE
@ AV_PIX_FMT_NONE
Definition: pixfmt.h:65
AV_OPT_TYPE_INT
@ AV_OPT_TYPE_INT
Definition: opt.h:224
AVCodecContext::profile
int profile
profile
Definition: avcodec.h:1521
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:86
ff_qsv_map_fourcc
enum AVPixelFormat ff_qsv_map_fourcc(uint32_t fourcc)
Definition: qsv.c:196
av_buffer_ref
AVBufferRef * av_buffer_ref(AVBufferRef *buf)
Create a new reference to an AVBuffer.
Definition: buffer.c:93
AV_PIX_FMT_P010
#define AV_PIX_FMT_P010
Definition: pixfmt.h:438
qsv_get_continuous_buffer
static int qsv_get_continuous_buffer(AVCodecContext *avctx, AVFrame *frame, AVBufferPool *pool)
Definition: qsvdec.c:110
VD
#define VD
Definition: qsvdec.c:836
AVQSVFramesContext
This struct is allocated as AVHWFramesContext.hwctx.
Definition: hwcontext_qsv.h:42
AVCodecContext::coded_width
int coded_width
Bitstream width / height, may be different from width/height e.g.
Definition: avcodec.h:567
av_strdup
char * av_strdup(const char *s)
Duplicate a string.
Definition: mem.c:259
mem.h
AVBufferRef
A reference to a data buffer.
Definition: buffer.h:82
QSVFrame::dec_info
mfxExtDecodedFrameInfo dec_info
Definition: qsv_internal.h:76
ff_attach_decode_data
int ff_attach_decode_data(AVFrame *frame)
Definition: decode.c:1624
av_fifo_size
int av_fifo_size(const AVFifoBuffer *f)
Return the amount of data in bytes in the AVFifoBuffer, that is the amount of data you can read from ...
Definition: fifo.c:77
AV_FIELD_PROGRESSIVE
@ AV_FIELD_PROGRESSIVE
Definition: codec_par.h:38
FFALIGN
#define FFALIGN(x, a)
Definition: macros.h:78
QSVFramesContext
Definition: qsv_internal.h:93
AVCodecContext::priv_data
void * priv_data
Definition: avcodec.h:406
AVPacket
This structure stores compressed data.
Definition: packet.h:350
av_freep
#define av_freep(p)
Definition: tableprint_vlc.h:35
qsv_clear_unused_frames
static void qsv_clear_unused_frames(QSVContext *q)
Definition: qsvdec.c:390
AVCodecContext::width
int width
picture width / height.
Definition: avcodec.h:552
av_fifo_alloc
AVFifoBuffer * av_fifo_alloc(unsigned int size)
Initialize an AVFifoBuffer.
Definition: fifo.c:43
imgutils.h
AV_CODEC_ID_VP8
@ AV_CODEC_ID_VP8
Definition: codec_id.h:190
hwcontext.h
AVERROR_BUG
#define AVERROR_BUG
Internal bug, also see AVERROR_BUG2.
Definition: error.h:52
av_log
#define av_log(a,...)
Definition: tableprint_vlc.h:28
AVERROR_INVALIDDATA
#define AVERROR_INVALIDDATA
Invalid data found when processing input.
Definition: error.h:61
QSVContext::gpu_copy
int gpu_copy
Definition: qsvdec.c:89
AV_OPT_TYPE_STRING
@ AV_OPT_TYPE_STRING
Definition: opt.h:228
AVCodecHWConfigInternal::public
AVCodecHWConfig public
This is the structure which will be returned to the user by avcodec_get_hw_config().
Definition: hwconfig.h:34
QSVFrame::next
struct QSVFrame * next
Definition: qsv_internal.h:82
ff_qsv_print_error
int ff_qsv_print_error(void *log_ctx, mfxStatus err, const char *error_string)
Definition: qsv.c:176
AV_OPT_TYPE_CONST
@ AV_OPT_TYPE_CONST
Definition: opt.h:233
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:383
qsv_decode_flush
static void qsv_decode_flush(AVCodecContext *avctx)
Definition: qsvdec.c:825
qsv_hw_configs
static const AVCodecHWConfigInternal *const qsv_hw_configs[]
Definition: qsvdec.c:97