FFmpeg  4.4.9
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 typedef struct QSVContext {
50  // the session used for decoding
51  mfxSession session;
52 
53  // the session we allocated internally, in case the caller did not provide
54  // one
56 
58 
59  /**
60  * a linked list of frames currently being used by QSV
61  */
63 
68 
70  uint32_t fourcc;
71  mfxFrameInfo frame_info;
73 
75 
76  // options set by the caller
78  int iopattern;
79  int gpu_copy;
80 
81  char *load_plugins;
82 
83  mfxExtBuffer **ext_buffers;
85 } QSVContext;
86 
87 static const AVCodecHWConfigInternal *const qsv_hw_configs[] = {
88  &(const AVCodecHWConfigInternal) {
89  .public = {
93  .device_type = AV_HWDEVICE_TYPE_QSV,
94  },
95  .hwaccel = NULL,
96  },
97  NULL
98 };
99 
101  AVBufferPool *pool)
102 {
103  int ret = 0;
104 
105  ret = ff_decode_frame_props(avctx, frame);
106  if (ret < 0)
107  return ret;
108 
109  frame->width = avctx->width;
110  frame->height = avctx->height;
111 
112  switch (avctx->pix_fmt) {
113  case AV_PIX_FMT_NV12:
114  frame->linesize[0] = FFALIGN(avctx->width, 128);
115  break;
116  case AV_PIX_FMT_P010:
117  frame->linesize[0] = 2 * FFALIGN(avctx->width, 128);
118  break;
119  default:
120  av_log(avctx, AV_LOG_ERROR, "Unsupported pixel format.\n");
121  return AVERROR(EINVAL);
122  }
123 
124  frame->linesize[1] = frame->linesize[0];
125  frame->buf[0] = av_buffer_pool_get(pool);
126  if (!frame->buf[0])
127  return AVERROR(ENOMEM);
128 
129  frame->data[0] = frame->buf[0]->data;
130  frame->data[1] = frame->data[0] +
131  frame->linesize[0] * FFALIGN(avctx->height, 64);
132 
134  if (ret < 0)
135  return ret;
136 
137  return 0;
138 }
139 
140 static int qsv_init_session(AVCodecContext *avctx, QSVContext *q, mfxSession session,
141  AVBufferRef *hw_frames_ref, AVBufferRef *hw_device_ref)
142 {
143  int ret;
144 
145  if (q->gpu_copy == MFX_GPUCOPY_ON &&
146  !(q->iopattern & MFX_IOPATTERN_OUT_SYSTEM_MEMORY)) {
147  av_log(avctx, AV_LOG_WARNING, "GPU-accelerated memory copy "
148  "only works in system memory mode.\n");
149  q->gpu_copy = MFX_GPUCOPY_OFF;
150  }
151  if (session) {
152  q->session = session;
153  } else if (hw_frames_ref) {
154  if (q->internal_qs.session) {
155  MFXClose(q->internal_qs.session);
156  q->internal_qs.session = NULL;
157  }
159 
160  q->frames_ctx.hw_frames_ctx = av_buffer_ref(hw_frames_ref);
161  if (!q->frames_ctx.hw_frames_ctx)
162  return AVERROR(ENOMEM);
163 
165  &q->frames_ctx, q->load_plugins,
166  q->iopattern == MFX_IOPATTERN_OUT_OPAQUE_MEMORY,
167  q->gpu_copy);
168  if (ret < 0) {
170  return ret;
171  }
172 
173  q->session = q->internal_qs.session;
174  } else if (hw_device_ref) {
175  if (q->internal_qs.session) {
176  MFXClose(q->internal_qs.session);
177  q->internal_qs.session = NULL;
178  }
179 
181  hw_device_ref, q->load_plugins, q->gpu_copy);
182  if (ret < 0)
183  return ret;
184 
185  q->session = q->internal_qs.session;
186  } else {
187  if (!q->internal_qs.session) {
188  ret = ff_qsv_init_internal_session(avctx, &q->internal_qs,
189  q->load_plugins, q->gpu_copy);
190  if (ret < 0)
191  return ret;
192  }
193 
194  q->session = q->internal_qs.session;
195  }
196 
197  /* make sure the decoder is uninitialized */
198  MFXVideoDECODE_Close(q->session);
199 
200  return 0;
201 }
202 
203 static inline unsigned int qsv_fifo_item_size(void)
204 {
205  return sizeof(mfxSyncPoint*) + sizeof(QSVFrame*);
206 }
207 
208 static inline unsigned int qsv_fifo_size(const AVFifoBuffer* fifo)
209 {
210  return av_fifo_size(fifo) / qsv_fifo_item_size();
211 }
212 
213 static int qsv_decode_preinit(AVCodecContext *avctx, QSVContext *q, enum AVPixelFormat pix_fmt, mfxVideoParam *param)
214 {
215  mfxSession session = NULL;
216  int iopattern = 0;
217  int ret;
218  enum AVPixelFormat pix_fmts[3] = {
219  AV_PIX_FMT_QSV, /* opaque format in case of video memory output */
220  pix_fmt, /* system memory format obtained from bitstream parser */
221  AV_PIX_FMT_NONE };
222 
223  ret = ff_get_format(avctx, pix_fmts);
224  if (ret < 0) {
225  q->orig_pix_fmt = avctx->pix_fmt = AV_PIX_FMT_NONE;
226  return ret;
227  }
228 
229  if (!q->async_fifo) {
231  if (!q->async_fifo)
232  return AVERROR(ENOMEM);
233  }
234 
235  if (avctx->pix_fmt == AV_PIX_FMT_QSV && avctx->hwaccel_context) {
236  AVQSVContext *user_ctx = avctx->hwaccel_context;
237  session = user_ctx->session;
238  iopattern = user_ctx->iopattern;
239  q->ext_buffers = user_ctx->ext_buffers;
240  q->nb_ext_buffers = user_ctx->nb_ext_buffers;
241  }
242 
243  if (avctx->hw_frames_ctx) {
244  AVHWFramesContext *frames_ctx = (AVHWFramesContext*)avctx->hw_frames_ctx->data;
245  AVQSVFramesContext *frames_hwctx = frames_ctx->hwctx;
246 
247  if (!iopattern) {
248  if (frames_hwctx->frame_type & MFX_MEMTYPE_OPAQUE_FRAME)
249  iopattern = MFX_IOPATTERN_OUT_OPAQUE_MEMORY;
250  else if (frames_hwctx->frame_type & MFX_MEMTYPE_VIDEO_MEMORY_DECODER_TARGET)
251  iopattern = MFX_IOPATTERN_OUT_VIDEO_MEMORY;
252  }
253  }
254 
255  if (!iopattern)
256  iopattern = MFX_IOPATTERN_OUT_SYSTEM_MEMORY;
257  q->iopattern = iopattern;
258 
259  ff_qsv_print_iopattern(avctx, q->iopattern, "Decoder");
260 
261  ret = qsv_init_session(avctx, q, session, avctx->hw_frames_ctx, avctx->hw_device_ctx);
262  if (ret < 0) {
263  av_log(avctx, AV_LOG_ERROR, "Error initializing an MFX session\n");
264  return ret;
265  }
266 
267  param->IOPattern = q->iopattern;
268  param->AsyncDepth = q->async_depth;
269  param->ExtParam = q->ext_buffers;
270  param->NumExtParam = q->nb_ext_buffers;
271 
272  return 0;
273  }
274 
275 static int qsv_decode_init_context(AVCodecContext *avctx, QSVContext *q, mfxVideoParam *param)
276 {
277  int ret;
278 
279  avctx->width = param->mfx.FrameInfo.CropW;
280  avctx->height = param->mfx.FrameInfo.CropH;
281  avctx->coded_width = param->mfx.FrameInfo.Width;
282  avctx->coded_height = param->mfx.FrameInfo.Height;
283  avctx->level = param->mfx.CodecLevel;
284  avctx->profile = param->mfx.CodecProfile;
285  avctx->field_order = ff_qsv_map_picstruct(param->mfx.FrameInfo.PicStruct);
286  avctx->pix_fmt = ff_qsv_map_fourcc(param->mfx.FrameInfo.FourCC);
287 
288  ret = MFXVideoDECODE_Init(q->session, param);
289  if (ret < 0)
290  return ff_qsv_print_error(avctx, ret,
291  "Error initializing the MFX video decoder");
292 
293  q->frame_info = param->mfx.FrameInfo;
294 
295  if (!avctx->hw_frames_ctx) {
296  ret = av_image_get_buffer_size(avctx->pix_fmt, FFALIGN(avctx->width, 128), FFALIGN(avctx->height, 64), 1);
297  if (ret < 0)
298  return ret;
300  }
301  return 0;
302 }
303 
305  const AVPacket *avpkt, enum AVPixelFormat pix_fmt,
306  mfxVideoParam *param)
307 {
308  int ret;
309 
310  mfxBitstream bs = { 0 };
311 
312  if (avpkt->size) {
313  bs.Data = avpkt->data;
314  bs.DataLength = avpkt->size;
315  bs.MaxLength = bs.DataLength;
316  bs.TimeStamp = avpkt->pts;
317  if (avctx->field_order == AV_FIELD_PROGRESSIVE)
318  bs.DataFlag |= MFX_BITSTREAM_COMPLETE_FRAME;
319  } else
320  return AVERROR_INVALIDDATA;
321 
322 
323  if(!q->session) {
324  ret = qsv_decode_preinit(avctx, q, pix_fmt, param);
325  if (ret < 0)
326  return ret;
327  }
328 
329  ret = ff_qsv_codec_id_to_mfx(avctx->codec_id);
330  if (ret < 0)
331  return ret;
332 
333  param->mfx.CodecId = ret;
334  ret = MFXVideoDECODE_DecodeHeader(q->session, &bs, param);
335  if (MFX_ERR_MORE_DATA == ret) {
336  return AVERROR(EAGAIN);
337  }
338  if (ret < 0)
339  return ff_qsv_print_error(avctx, ret,
340  "Error decoding stream header");
341 
342  return 0;
343 }
344 
346 {
347  int ret;
348 
349  if (q->pool)
350  ret = qsv_get_continuous_buffer(avctx, frame->frame, q->pool);
351  else
352  ret = ff_get_buffer(avctx, frame->frame, AV_GET_BUFFER_FLAG_REF);
353 
354  if (ret < 0)
355  return ret;
356 
357  if (frame->frame->format == AV_PIX_FMT_QSV) {
358  frame->surface = *(mfxFrameSurface1*)frame->frame->data[3];
359  } else {
360  frame->surface.Info = q->frame_info;
361 
362  frame->surface.Data.PitchLow = frame->frame->linesize[0];
363  frame->surface.Data.Y = frame->frame->data[0];
364  frame->surface.Data.UV = frame->frame->data[1];
365  }
366 
367  if (q->frames_ctx.mids) {
369  if (ret < 0)
370  return ret;
371 
372  frame->surface.Data.MemId = &q->frames_ctx.mids[ret];
373  }
374  frame->surface.Data.ExtParam = &frame->ext_param;
375  frame->surface.Data.NumExtParam = 1;
376  frame->ext_param = (mfxExtBuffer*)&frame->dec_info;
377  frame->dec_info.Header.BufferId = MFX_EXTBUFF_DECODED_FRAME_INFO;
378  frame->dec_info.Header.BufferSz = sizeof(frame->dec_info);
379 
380  frame->used = 1;
381 
382  return 0;
383 }
384 
386 {
387  QSVFrame *cur = q->work_frames;
388  while (cur) {
389  if (cur->used && !cur->surface.Data.Locked && !cur->queued) {
390  cur->used = 0;
391  av_frame_unref(cur->frame);
392  }
393  cur = cur->next;
394  }
395 }
396 
397 static int get_surface(AVCodecContext *avctx, QSVContext *q, mfxFrameSurface1 **surf)
398 {
399  QSVFrame *frame, **last;
400  int ret;
401 
403 
404  frame = q->work_frames;
405  last = &q->work_frames;
406  while (frame) {
407  if (!frame->used) {
408  ret = alloc_frame(avctx, q, frame);
409  if (ret < 0)
410  return ret;
411  *surf = &frame->surface;
412  return 0;
413  }
414 
415  last = &frame->next;
416  frame = frame->next;
417  }
418 
419  frame = av_mallocz(sizeof(*frame));
420  if (!frame)
421  return AVERROR(ENOMEM);
422  frame->frame = av_frame_alloc();
423  if (!frame->frame) {
424  av_freep(&frame);
425  return AVERROR(ENOMEM);
426  }
427  *last = frame;
428 
429  ret = alloc_frame(avctx, q, frame);
430  if (ret < 0)
431  return ret;
432 
433  *surf = &frame->surface;
434 
435  return 0;
436 }
437 
438 static QSVFrame *find_frame(QSVContext *q, mfxFrameSurface1 *surf)
439 {
440  QSVFrame *cur = q->work_frames;
441  while (cur) {
442  if (surf == &cur->surface)
443  return cur;
444  cur = cur->next;
445  }
446  return NULL;
447 }
448 
449 static int qsv_decode(AVCodecContext *avctx, QSVContext *q,
450  AVFrame *frame, int *got_frame,
451  const AVPacket *avpkt)
452 {
453  QSVFrame *out_frame;
454  mfxFrameSurface1 *insurf;
455  mfxFrameSurface1 *outsurf;
456  mfxSyncPoint *sync;
457  mfxBitstream bs = { { { 0 } } };
458  int ret;
459 
460  if (avpkt->size) {
461  bs.Data = avpkt->data;
462  bs.DataLength = avpkt->size;
463  bs.MaxLength = bs.DataLength;
464  bs.TimeStamp = avpkt->pts;
465  if (avctx->field_order == AV_FIELD_PROGRESSIVE)
466  bs.DataFlag |= MFX_BITSTREAM_COMPLETE_FRAME;
467  }
468 
469  sync = av_mallocz(sizeof(*sync));
470  if (!sync) {
471  av_freep(&sync);
472  return AVERROR(ENOMEM);
473  }
474 
475  do {
476  ret = get_surface(avctx, q, &insurf);
477  if (ret < 0) {
478  av_freep(&sync);
479  return ret;
480  }
481 
482  ret = MFXVideoDECODE_DecodeFrameAsync(q->session, avpkt->size ? &bs : NULL,
483  insurf, &outsurf, sync);
484  if (ret == MFX_WRN_DEVICE_BUSY)
485  av_usleep(500);
486 
487  } while (ret == MFX_WRN_DEVICE_BUSY || ret == MFX_ERR_MORE_SURFACE);
488 
489  if (ret != MFX_ERR_NONE &&
490  ret != MFX_ERR_MORE_DATA &&
491  ret != MFX_WRN_VIDEO_PARAM_CHANGED &&
492  ret != MFX_ERR_MORE_SURFACE) {
493  av_freep(&sync);
494  return ff_qsv_print_error(avctx, ret,
495  "Error during QSV decoding.");
496  }
497 
498  /* make sure we do not enter an infinite loop if the SDK
499  * did not consume any data and did not return anything */
500  if (!*sync && !bs.DataOffset) {
501  bs.DataOffset = avpkt->size;
502  ++q->zero_consume_run;
503  if (q->zero_consume_run > 1)
504  ff_qsv_print_warning(avctx, ret, "A decode call did not consume any data");
505  } else if (!*sync && bs.DataOffset) {
506  ++q->buffered_count;
507  } else {
508  q->zero_consume_run = 0;
509  }
510 
511  if (*sync) {
512  QSVFrame *out_frame = find_frame(q, outsurf);
513 
514  if (!out_frame) {
515  av_log(avctx, AV_LOG_ERROR,
516  "The returned surface does not correspond to any frame\n");
517  av_freep(&sync);
518  return AVERROR_BUG;
519  }
520 
521  out_frame->queued = 1;
522  av_fifo_generic_write(q->async_fifo, &out_frame, sizeof(out_frame), NULL);
523  av_fifo_generic_write(q->async_fifo, &sync, sizeof(sync), NULL);
524  } else {
525  av_freep(&sync);
526  }
527 
528  if ((qsv_fifo_size(q->async_fifo) >= q->async_depth) ||
529  (!avpkt->size && av_fifo_size(q->async_fifo))) {
530  AVFrame *src_frame;
531 
532  av_fifo_generic_read(q->async_fifo, &out_frame, sizeof(out_frame), NULL);
533  av_fifo_generic_read(q->async_fifo, &sync, sizeof(sync), NULL);
534  out_frame->queued = 0;
535 
536  if (avctx->pix_fmt != AV_PIX_FMT_QSV) {
537  do {
538  ret = MFXVideoCORE_SyncOperation(q->session, *sync, 1000);
539  } while (ret == MFX_WRN_IN_EXECUTION);
540  }
541 
542  av_freep(&sync);
543 
544  src_frame = out_frame->frame;
545 
546  ret = av_frame_ref(frame, src_frame);
547  if (ret < 0)
548  return ret;
549 
550  outsurf = &out_frame->surface;
551 
552 #if FF_API_PKT_PTS
554  frame->pkt_pts = outsurf->Data.TimeStamp;
556 #endif
557  frame->pts = outsurf->Data.TimeStamp;
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;
564  outsurf->Info.PicStruct & MFX_PICSTRUCT_FIELD_TFF;
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  return 0;
762 fail:
763  qsv_decode_close(avctx);
764  return ret;
765 }
766 
767 static int qsv_decode_frame(AVCodecContext *avctx, void *data,
768  int *got_frame, AVPacket *avpkt)
769 {
770  QSVDecContext *s = avctx->priv_data;
771  AVFrame *frame = data;
772  int ret;
773 
774  /* buffer the input packet */
775  if (avpkt->size) {
776  AVPacket input_ref;
777 
778  if (av_fifo_space(s->packet_fifo) < sizeof(input_ref)) {
779  ret = av_fifo_realloc2(s->packet_fifo,
780  av_fifo_size(s->packet_fifo) + sizeof(input_ref));
781  if (ret < 0)
782  return ret;
783  }
784 
785  ret = av_packet_ref(&input_ref, avpkt);
786  if (ret < 0)
787  return ret;
788  av_fifo_generic_write(s->packet_fifo, &input_ref, sizeof(input_ref), NULL);
789  }
790 
791  /* process buffered data */
792  while (!*got_frame) {
793  /* prepare the input data */
794  if (s->buffer_pkt.size <= 0) {
795  /* no more data */
796  if (av_fifo_size(s->packet_fifo) < sizeof(AVPacket))
797  return avpkt->size ? avpkt->size : qsv_process_data(avctx, &s->qsv, frame, got_frame, avpkt);
798  /* in progress of reinit, no read from fifo and keep the buffer_pkt */
799  if (!s->qsv.reinit_flag) {
800  av_packet_unref(&s->buffer_pkt);
801  av_fifo_generic_read(s->packet_fifo, &s->buffer_pkt, sizeof(s->buffer_pkt), NULL);
802  }
803  }
804 
805  ret = qsv_process_data(avctx, &s->qsv, frame, got_frame, &s->buffer_pkt);
806  if (ret < 0){
807  /* Drop buffer_pkt when failed to decode the packet. Otherwise,
808  the decoder will keep decoding the failure packet. */
809  av_packet_unref(&s->buffer_pkt);
810  return ret;
811  }
812  if (s->qsv.reinit_flag)
813  continue;
814 
815  s->buffer_pkt.size -= ret;
816  s->buffer_pkt.data += ret;
817  }
818 
819  return avpkt->size;
820 }
821 
822 static void qsv_decode_flush(AVCodecContext *avctx)
823 {
824  QSVDecContext *s = avctx->priv_data;
825 
827 
828  s->qsv.orig_pix_fmt = AV_PIX_FMT_NONE;
829  s->qsv.initialized = 0;
830 }
831 
832 #define OFFSET(x) offsetof(QSVDecContext, x)
833 #define VD AV_OPT_FLAG_VIDEO_PARAM | AV_OPT_FLAG_DECODING_PARAM
834 
835 #define DEFINE_QSV_DECODER_WITH_OPTION(x, X, bsf_name, opt) \
836 static const AVClass x##_qsv_class = { \
837  .class_name = #x "_qsv", \
838  .item_name = av_default_item_name, \
839  .option = opt, \
840  .version = LIBAVUTIL_VERSION_INT, \
841 }; \
842 AVCodec ff_##x##_qsv_decoder = { \
843  .name = #x "_qsv", \
844  .long_name = NULL_IF_CONFIG_SMALL(#X " video (Intel Quick Sync Video acceleration)"), \
845  .priv_data_size = sizeof(QSVDecContext), \
846  .type = AVMEDIA_TYPE_VIDEO, \
847  .id = AV_CODEC_ID_##X, \
848  .init = qsv_decode_init, \
849  .decode = qsv_decode_frame, \
850  .flush = qsv_decode_flush, \
851  .close = qsv_decode_close, \
852  .bsfs = bsf_name, \
853  .capabilities = AV_CODEC_CAP_DELAY | AV_CODEC_CAP_DR1 | AV_CODEC_CAP_AVOID_PROBING | AV_CODEC_CAP_HYBRID, \
854  .priv_class = &x##_qsv_class, \
855  .pix_fmts = (const enum AVPixelFormat[]){ AV_PIX_FMT_NV12, \
856  AV_PIX_FMT_P010, \
857  AV_PIX_FMT_QSV, \
858  AV_PIX_FMT_NONE }, \
859  .hw_configs = qsv_hw_configs, \
860  .wrapper_name = "qsv", \
861 }; \
862 
863 #define DEFINE_QSV_DECODER(x, X, bsf_name) DEFINE_QSV_DECODER_WITH_OPTION(x, X, bsf_name, options)
864 
865 #if CONFIG_HEVC_QSV_DECODER
866 static const AVOption hevc_options[] = {
867  { "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 },
868 
869  { "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" },
870  { "none", NULL, 0, AV_OPT_TYPE_CONST, { .i64 = LOAD_PLUGIN_NONE }, 0, 0, VD, "load_plugin" },
871  { "hevc_sw", NULL, 0, AV_OPT_TYPE_CONST, { .i64 = LOAD_PLUGIN_HEVC_SW }, 0, 0, VD, "load_plugin" },
872  { "hevc_hw", NULL, 0, AV_OPT_TYPE_CONST, { .i64 = LOAD_PLUGIN_HEVC_HW }, 0, 0, VD, "load_plugin" },
873 
874  { "load_plugins", "A :-separate list of hexadecimal plugin UIDs to load in an internal session",
875  OFFSET(qsv.load_plugins), AV_OPT_TYPE_STRING, { .str = "" }, 0, 0, VD },
876 
877  { "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"},
878  { "default", NULL, 0, AV_OPT_TYPE_CONST, { .i64 = MFX_GPUCOPY_DEFAULT }, 0, 0, VD, "gpu_copy"},
879  { "on", NULL, 0, AV_OPT_TYPE_CONST, { .i64 = MFX_GPUCOPY_ON }, 0, 0, VD, "gpu_copy"},
880  { "off", NULL, 0, AV_OPT_TYPE_CONST, { .i64 = MFX_GPUCOPY_OFF }, 0, 0, VD, "gpu_copy"},
881  { NULL },
882 };
883 DEFINE_QSV_DECODER_WITH_OPTION(hevc, HEVC, "hevc_mp4toannexb", hevc_options)
884 #endif
885 
886 static const AVOption options[] = {
887  { "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 },
888 
889  { "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"},
890  { "default", NULL, 0, AV_OPT_TYPE_CONST, { .i64 = MFX_GPUCOPY_DEFAULT }, 0, 0, VD, "gpu_copy"},
891  { "on", NULL, 0, AV_OPT_TYPE_CONST, { .i64 = MFX_GPUCOPY_ON }, 0, 0, VD, "gpu_copy"},
892  { "off", NULL, 0, AV_OPT_TYPE_CONST, { .i64 = MFX_GPUCOPY_OFF }, 0, 0, VD, "gpu_copy"},
893  { NULL },
894 };
895 
896 #if CONFIG_H264_QSV_DECODER
897 DEFINE_QSV_DECODER(h264, H264, "h264_mp4toannexb")
898 #endif
899 
900 #if CONFIG_MPEG2_QSV_DECODER
901 DEFINE_QSV_DECODER(mpeg2, MPEG2VIDEO, NULL)
902 #endif
903 
904 #if CONFIG_VC1_QSV_DECODER
905 DEFINE_QSV_DECODER(vc1, VC1, NULL)
906 #endif
907 
908 #if CONFIG_MJPEG_QSV_DECODER
909 DEFINE_QSV_DECODER(mjpeg, MJPEG, NULL)
910 #endif
911 
912 #if CONFIG_VP8_QSV_DECODER
913 DEFINE_QSV_DECODER(vp8, VP8, NULL)
914 #endif
915 
916 #if CONFIG_VP9_QSV_DECODER
917 DEFINE_QSV_DECODER(vp9, VP9, NULL)
918 #endif
919 
920 #if CONFIG_AV1_QSV_DECODER
921 DEFINE_QSV_DECODER(av1, AV1, NULL)
922 #endif
#define av_cold
Definition: attributes.h:88
Libavcodec external API header.
#define s(width, name)
Definition: cbs_vp9.c:257
#define fail()
Definition: checkasm.h:133
@ AV_FIELD_PROGRESSIVE
Definition: codec_par.h:38
common internal and external API header
#define NULL
Definition: coverity.c:32
int ff_get_buffer(AVCodecContext *avctx, AVFrame *frame, int flags)
Get a buffer for a frame.
Definition: decode.c:1911
int ff_decode_frame_props(AVCodecContext *avctx, AVFrame *frame)
Set various frame properties from the codec context / packet data.
Definition: decode.c:1742
int ff_attach_decode_data(AVFrame *frame)
Definition: decode.c:1887
int ff_get_format(AVCodecContext *avctx, const enum AVPixelFormat *fmt)
Select the (possibly hardware accelerated) pixel format.
Definition: decode.c:1337
static enum AVPixelFormat pix_fmt
static AVFrame * frame
a very simple circular buffer FIFO implementation
reference-counted frame API
@ AV_OPT_TYPE_CONST
Definition: opt.h:234
@ AV_OPT_TYPE_INT
Definition: opt.h:225
@ AV_OPT_TYPE_STRING
Definition: opt.h:229
#define AV_GET_BUFFER_FLAG_REF
The decoder will keep a reference to the frame and may reuse it later.
Definition: avcodec.h:514
@ AV_CODEC_HW_CONFIG_METHOD_AD_HOC
The codec supports this format by some ad-hoc method.
Definition: codec.h:440
@ AV_CODEC_HW_CONFIG_METHOD_HW_FRAMES_CTX
The codec supports this format via the hw_frames_ctx interface.
Definition: codec.h:424
@ AV_CODEC_ID_H264
Definition: codec_id.h:76
@ AV_CODEC_ID_VP8
Definition: codec_id.h:189
@ AV_CODEC_ID_HEVC
Definition: codec_id.h:223
@ AV_CODEC_ID_VP9
Definition: codec_id.h:217
void av_packet_unref(AVPacket *pkt)
Wipe the packet.
Definition: avpacket.c:634
int av_packet_ref(AVPacket *dst, const AVPacket *src)
Setup a new reference to the data described by a given packet.
Definition: avpacket.c:641
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
AVBufferRef * av_buffer_allocz(buffer_size_t size)
Same as av_buffer_alloc(), except the returned buffer will be initialized to zero.
Definition: buffer.c:83
AVBufferRef * av_buffer_ref(AVBufferRef *buf)
Create a new reference to an AVBuffer.
Definition: buffer.c:93
AVBufferPool * av_buffer_pool_init(buffer_size_t size, AVBufferRef *(*alloc)(buffer_size_t size))
Allocate and initialize a buffer pool.
Definition: buffer.c:269
AVBufferRef * av_buffer_pool_get(AVBufferPool *pool)
Allocate a new AVBuffer, reusing an old buffer from the pool when available.
Definition: buffer.c:379
void av_buffer_pool_uninit(AVBufferPool **ppool)
Mark the pool as being available for freeing.
Definition: buffer.c:314
#define AVERROR_BUG
Internal bug, also see AVERROR_BUG2.
Definition: error.h:50
#define AVERROR_INVALIDDATA
Invalid data found when processing input.
Definition: error.h:59
#define AVERROR(e)
Definition: error.h:43
void av_frame_unref(AVFrame *frame)
Unreference all the buffers referenced by frame and reset the frame fields.
Definition: frame.c:553
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:443
void av_frame_free(AVFrame **frame)
Free the frame and any dynamically allocated objects in it, e.g.
Definition: frame.c:203
AVFrame * av_frame_alloc(void)
Allocate an AVFrame and set its fields to default values.
Definition: frame.c:190
#define AV_LOG_WARNING
Something somehow does not look correct.
Definition: log.h:200
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
Definition: log.h:194
void * av_mallocz(size_t size)
Allocate a memory block with alignment suitable for all memory accesses (including vectors if availab...
Definition: mem.c:237
char * av_strdup(const char *s)
Duplicate a string.
Definition: mem.c:253
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:469
@ AV_HWDEVICE_TYPE_QSV
Definition: hwcontext.h:33
An API-specific header for AV_HWDEVICE_TYPE_QSV.
misc image utilities
static int qsv_process_data(AVCodecContext *avctx, QSVContext *q, AVFrame *frame, int *got_frame, const AVPacket *pkt)
Definition: qsvdec.c:616
static int qsv_decode(AVCodecContext *avctx, QSVContext *q, AVFrame *frame, int *got_frame, const AVPacket *avpkt)
Definition: qsvdec.c:449
static void qsv_clear_unused_frames(QSVContext *q)
Definition: qsvdec.c:385
static const AVOption options[]
Definition: qsvdec.c:886
#define DEFINE_QSV_DECODER_WITH_OPTION(x, X, bsf_name, opt)
Definition: qsvdec.c:835
static int qsv_decode_header(AVCodecContext *avctx, QSVContext *q, const AVPacket *avpkt, enum AVPixelFormat pix_fmt, mfxVideoParam *param)
Definition: qsvdec.c:304
static int qsv_decode_preinit(AVCodecContext *avctx, QSVContext *q, enum AVPixelFormat pix_fmt, mfxVideoParam *param)
Definition: qsvdec.c:213
static int qsv_decode_init_context(AVCodecContext *avctx, QSVContext *q, mfxVideoParam *param)
Definition: qsvdec.c:275
static int get_surface(AVCodecContext *avctx, QSVContext *q, mfxFrameSurface1 **surf)
Definition: qsvdec.c:397
static int qsv_decode_frame(AVCodecContext *avctx, void *data, int *got_frame, AVPacket *avpkt)
Definition: qsvdec.c:767
static void qsv_decode_flush(AVCodecContext *avctx)
Definition: qsvdec.c:822
static QSVFrame * find_frame(QSVContext *q, mfxFrameSurface1 *surf)
Definition: qsvdec.c:438
#define DEFINE_QSV_DECODER(x, X, bsf_name)
Definition: qsvdec.c:863
static void qsv_decode_close_qsvcontext(QSVContext *q)
Definition: qsvdec.c:582
static const AVCodecHWConfigInternal *const qsv_hw_configs[]
Definition: qsvdec.c:87
static void qsv_clear_buffers(QSVDecContext *s)
Definition: qsvdec.c:695
#define VD
Definition: qsvdec.c:833
static av_cold int qsv_decode_init(AVCodecContext *avctx)
Definition: qsvdec.c:721
static av_cold int qsv_decode_close(AVCodecContext *avctx)
Definition: qsvdec.c:706
LoadPlugin
Definition: qsvdec.c:678
@ LOAD_PLUGIN_NONE
Definition: qsvdec.c:679
@ LOAD_PLUGIN_HEVC_HW
Definition: qsvdec.c:681
@ LOAD_PLUGIN_HEVC_SW
Definition: qsvdec.c:680
static int alloc_frame(AVCodecContext *avctx, QSVContext *q, QSVFrame *frame)
Definition: qsvdec.c:345
#define OFFSET(x)
Definition: qsvdec.c:832
static unsigned int qsv_fifo_item_size(void)
Definition: qsvdec.c:203
static int qsv_get_continuous_buffer(AVCodecContext *avctx, AVFrame *frame, AVBufferPool *pool)
Definition: qsvdec.c:100
static int qsv_init_session(AVCodecContext *avctx, QSVContext *q, mfxSession session, AVBufferRef *hw_frames_ref, AVBufferRef *hw_device_ref)
Definition: qsvdec.c:140
static unsigned int qsv_fifo_size(const AVFifoBuffer *fifo)
Definition: qsvdec.c:208
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
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
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
void av_fifo_free(AVFifoBuffer *f)
Free an AVFifoBuffer.
Definition: fifo.c:55
AVFifoBuffer * av_fifo_alloc(unsigned int size)
Initialize an AVFifoBuffer.
Definition: fifo.c:43
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
int av_fifo_realloc2(AVFifoBuffer *f, unsigned int new_size)
Resize an AVFifoBuffer.
Definition: fifo.c:87
common internal API header
#define FF_DISABLE_DEPRECATION_WARNINGS
Definition: internal.h:83
#define FF_ENABLE_DEPRECATION_WARNINGS
Definition: internal.h:84
static enum AVPixelFormat pix_fmts[]
Definition: libkvazaar.c:309
#define FFALIGN(x, a)
Definition: macros.h:48
Memory handling functions.
const char data[16]
Definition: mxf.c:142
UID uid
Definition: mxfenc.c:2205
AVOptions.
pixel format definitions
#define AV_PIX_FMT_P010
Definition: pixfmt.h:448
AVPixelFormat
Pixel format.
Definition: pixfmt.h:64
@ 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
@ AV_PIX_FMT_NONE
Definition: pixfmt.h:65
@ AV_PIX_FMT_QSV
HW acceleration through QSV, data[3] contains a pointer to the mfxFrameSurface1 structure.
Definition: pixfmt.h:222
int ff_qsv_codec_id_to_mfx(enum AVCodecID codec_id)
Definition: qsv.c:43
enum AVFieldOrder ff_qsv_map_picstruct(int mfx_pic_struct)
Definition: qsv.c:252
int ff_qsv_init_internal_session(AVCodecContext *avctx, QSVSession *qs, const char *load_plugins, int gpu_copy)
Definition: qsv.c:383
int ff_qsv_print_error(void *log_ctx, mfxStatus err, const char *error_string)
Definition: qsv.c:176
int ff_qsv_close_internal_session(QSVSession *qs)
Definition: qsv.c:813
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
int ff_qsv_print_iopattern(void *log_ctx, int mfx_iopattern, const char *extra_string)
Definition: qsv.c:104
int ff_qsv_init_session_device(AVCodecContext *avctx, mfxSession *psession, AVBufferRef *device_ref, const char *load_plugins, int gpu_copy)
Definition: qsv.c:689
enum AVPictureType ff_qsv_map_pictype(int mfx_pic_type)
Definition: qsv.c:270
enum AVPixelFormat ff_qsv_map_fourcc(uint32_t fourcc)
Definition: qsv.c:196
int ff_qsv_find_surface_idx(QSVFramesContext *ctx, QSVFrame *frame)
Definition: qsv.c:241
int ff_qsv_print_warning(void *log_ctx, mfxStatus err, const char *warning_string)
Definition: qsv.c:186
#define ASYNC_DEPTH_DEFAULT
Definition: qsv_internal.h:51
The buffer pool.
A reference to a data buffer.
Definition: buffer.h:84
uint8_t * data
The data buffer.
Definition: buffer.h:92
Describe the class of an AVClass context structure.
Definition: log.h:67
main external API structure.
Definition: avcodec.h:536
enum AVPixelFormat pix_fmt
Pixel format, see AV_PIX_FMT_xxx.
Definition: avcodec.h:746
int width
picture width / height.
Definition: avcodec.h:709
AVBufferRef * hw_frames_ctx
A reference to the AVHWFramesContext describing the input (for encoding) or output (decoding) frames.
Definition: avcodec.h:2222
enum AVFieldOrder field_order
Field order.
Definition: avcodec.h:1193
int level
level
Definition: avcodec.h:1988
int profile
profile
Definition: avcodec.h:1862
void * hwaccel_context
Hardware accelerator context.
Definition: avcodec.h:1696
int coded_height
Definition: avcodec.h:724
AVBufferRef * hw_device_ctx
A reference to the AVHWDeviceContext describing the device which will be used by a hardware encoder/d...
Definition: avcodec.h:2274
enum AVCodecID codec_id
Definition: avcodec.h:546
int coded_width
Bitstream width / height, may be different from width/height e.g.
Definition: avcodec.h:724
void * priv_data
Definition: avcodec.h:563
AVCodecHWConfig public
This is the structure which will be returned to the user by avcodec_get_hw_config().
Definition: hwconfig.h:34
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:452
This structure describes decoded (raw) audio or video data.
Definition: frame.h:318
int64_t pts
Presentation timestamp in time_base units (time when frame should be shown to user).
Definition: frame.h:411
uint8_t * data[AV_NUM_DATA_POINTERS]
pointer to the picture/channel planes.
Definition: frame.h:332
int width
Definition: frame.h:376
attribute_deprecated int64_t pkt_pts
PTS copied from the AVPacket that was decoded to produce this frame.
Definition: frame.h:419
int key_frame
1 -> keyframe, 0-> not
Definition: frame.h:396
int height
Definition: frame.h:376
AVBufferRef * buf[AV_NUM_DATA_POINTERS]
AVBuffer references backing the data for this frame.
Definition: frame.h:509
int top_field_first
If the content is interlaced, is top field displayed first.
Definition: frame.h:470
int interlaced_frame
The content of the picture is interlaced.
Definition: frame.h:465
int linesize[AV_NUM_DATA_POINTERS]
For video, size in bytes of each picture line.
Definition: frame.h:349
int format
format of the frame, -1 if unknown or unset Values correspond to enum AVPixelFormat for video frames,...
Definition: frame.h:391
int repeat_pict
When decoding, this signals how much the picture must be delayed.
Definition: frame.h:460
enum AVPictureType pict_type
Picture type of the frame.
Definition: frame.h:401
This struct describes a set or pool of "hardware" frames (i.e.
Definition: hwcontext.h:124
void * hwctx
The format-specific data, allocated and freed automatically along with this context.
Definition: hwcontext.h:162
AVOption.
Definition: opt.h:248
This structure stores compressed data.
Definition: packet.h:346
int size
Definition: packet.h:370
int64_t pts
Presentation timestamp in AVStream->time_base units; the time at which the decompressed packet will b...
Definition: packet.h:362
uint8_t * data
Definition: packet.h:369
This struct is used for communicating QSV parameters between libavcodec and the caller.
Definition: qsv.h:36
int nb_ext_buffers
Definition: qsv.h:52
mfxExtBuffer ** ext_buffers
Extra buffers to pass to encoder or decoder initialization.
Definition: qsv.h:51
int iopattern
The IO pattern to use.
Definition: qsv.h:46
mfxSession session
If non-NULL, the session to use for encoding or decoding.
Definition: qsv.h:41
This struct is allocated as AVHWFramesContext.hwctx.
Definition: hwcontext_qsv.h:42
mfxExtBuffer ** ext_buffers
Definition: qsvdec.c:83
int iopattern
Definition: qsvdec.c:78
int zero_consume_run
Definition: qsvdec.c:65
mfxSession session
Definition: qsvdec.c:51
enum AVPixelFormat orig_pix_fmt
Definition: qsvdec.c:69
int async_depth
Definition: qsvdec.c:77
QSVFramesContext frames_ctx
Definition: qsvdec.c:57
int nb_ext_buffers
Definition: qsvdec.c:84
int gpu_copy
Definition: qsvdec.c:79
char * load_plugins
Definition: qsvdec.c:81
int reinit_flag
Definition: qsvdec.c:67
uint32_t fourcc
Definition: qsvdec.c:70
int buffered_count
Definition: qsvdec.c:66
QSVSession internal_qs
Definition: qsvdec.c:55
AVFifoBuffer * async_fifo
Definition: qsvdec.c:64
QSVFrame * work_frames
a linked list of frames currently being used by QSV
Definition: qsvdec.c:62
AVBufferPool * pool
Definition: qsvdec.c:72
mfxFrameInfo frame_info
Definition: qsvdec.c:71
int initialized
Definition: qsvdec.c:74
AVPacket buffer_pkt
Definition: qsvdec.c:692
QSVContext qsv
Definition: qsvdec.c:686
int load_plugin
Definition: qsvdec.c:688
AVFifoBuffer * packet_fifo
Definition: qsvdec.c:690
AVFrame * frame
Definition: qsv_internal.h:73
struct QSVFrame * next
Definition: qsv_internal.h:82
int queued
Definition: qsv_internal.h:79
mfxFrameSurface1 surface
Definition: qsv_internal.h:74
mfxExtDecodedFrameInfo dec_info
Definition: qsv_internal.h:76
AVBufferRef * hw_frames_ctx
Definition: qsv_internal.h:94
AVBufferRef * mids_buf
Definition: qsv_internal.h:101
mfxSession session
Definition: qsv_internal.h:86
#define av_freep(p)
#define av_log(a,...)
AVPacket * pkt
Definition: movenc.c:59
int av_usleep(unsigned usec)
Sleep for a period of time.
Definition: time.c:84
if(ret< 0)
Definition: vf_mcdeint.c:282
static const AVOption hevc_options[]