FFmpeg  4.4.5
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 
106 
107  frame->width = avctx->width;
108  frame->height = avctx->height;
109 
110  switch (avctx->pix_fmt) {
111  case AV_PIX_FMT_NV12:
112  frame->linesize[0] = FFALIGN(avctx->width, 128);
113  break;
114  case AV_PIX_FMT_P010:
115  frame->linesize[0] = 2 * FFALIGN(avctx->width, 128);
116  break;
117  default:
118  av_log(avctx, AV_LOG_ERROR, "Unsupported pixel format.\n");
119  return AVERROR(EINVAL);
120  }
121 
122  frame->linesize[1] = frame->linesize[0];
123  frame->buf[0] = av_buffer_pool_get(pool);
124  if (!frame->buf[0])
125  return AVERROR(ENOMEM);
126 
127  frame->data[0] = frame->buf[0]->data;
128  frame->data[1] = frame->data[0] +
129  frame->linesize[0] * FFALIGN(avctx->height, 64);
130 
132  if (ret < 0)
133  return ret;
134 
135  return 0;
136 }
137 
138 static int qsv_init_session(AVCodecContext *avctx, QSVContext *q, mfxSession session,
139  AVBufferRef *hw_frames_ref, AVBufferRef *hw_device_ref)
140 {
141  int ret;
142 
143  if (q->gpu_copy == MFX_GPUCOPY_ON &&
144  !(q->iopattern & MFX_IOPATTERN_OUT_SYSTEM_MEMORY)) {
145  av_log(avctx, AV_LOG_WARNING, "GPU-accelerated memory copy "
146  "only works in system memory mode.\n");
147  q->gpu_copy = MFX_GPUCOPY_OFF;
148  }
149  if (session) {
150  q->session = session;
151  } else if (hw_frames_ref) {
152  if (q->internal_qs.session) {
153  MFXClose(q->internal_qs.session);
154  q->internal_qs.session = NULL;
155  }
157 
158  q->frames_ctx.hw_frames_ctx = av_buffer_ref(hw_frames_ref);
159  if (!q->frames_ctx.hw_frames_ctx)
160  return AVERROR(ENOMEM);
161 
163  &q->frames_ctx, q->load_plugins,
164  q->iopattern == MFX_IOPATTERN_OUT_OPAQUE_MEMORY,
165  q->gpu_copy);
166  if (ret < 0) {
168  return ret;
169  }
170 
171  q->session = q->internal_qs.session;
172  } else if (hw_device_ref) {
173  if (q->internal_qs.session) {
174  MFXClose(q->internal_qs.session);
175  q->internal_qs.session = NULL;
176  }
177 
179  hw_device_ref, q->load_plugins, q->gpu_copy);
180  if (ret < 0)
181  return ret;
182 
183  q->session = q->internal_qs.session;
184  } else {
185  if (!q->internal_qs.session) {
186  ret = ff_qsv_init_internal_session(avctx, &q->internal_qs,
187  q->load_plugins, q->gpu_copy);
188  if (ret < 0)
189  return ret;
190  }
191 
192  q->session = q->internal_qs.session;
193  }
194 
195  /* make sure the decoder is uninitialized */
196  MFXVideoDECODE_Close(q->session);
197 
198  return 0;
199 }
200 
201 static inline unsigned int qsv_fifo_item_size(void)
202 {
203  return sizeof(mfxSyncPoint*) + sizeof(QSVFrame*);
204 }
205 
206 static inline unsigned int qsv_fifo_size(const AVFifoBuffer* fifo)
207 {
208  return av_fifo_size(fifo) / qsv_fifo_item_size();
209 }
210 
211 static int qsv_decode_preinit(AVCodecContext *avctx, QSVContext *q, enum AVPixelFormat pix_fmt, mfxVideoParam *param)
212 {
213  mfxSession session = NULL;
214  int iopattern = 0;
215  int ret;
216  enum AVPixelFormat pix_fmts[3] = {
217  AV_PIX_FMT_QSV, /* opaque format in case of video memory output */
218  pix_fmt, /* system memory format obtained from bitstream parser */
219  AV_PIX_FMT_NONE };
220 
221  ret = ff_get_format(avctx, pix_fmts);
222  if (ret < 0) {
223  q->orig_pix_fmt = avctx->pix_fmt = AV_PIX_FMT_NONE;
224  return ret;
225  }
226 
227  if (!q->async_fifo) {
229  if (!q->async_fifo)
230  return AVERROR(ENOMEM);
231  }
232 
233  if (avctx->pix_fmt == AV_PIX_FMT_QSV && avctx->hwaccel_context) {
234  AVQSVContext *user_ctx = avctx->hwaccel_context;
235  session = user_ctx->session;
236  iopattern = user_ctx->iopattern;
237  q->ext_buffers = user_ctx->ext_buffers;
238  q->nb_ext_buffers = user_ctx->nb_ext_buffers;
239  }
240 
241  if (avctx->hw_frames_ctx) {
242  AVHWFramesContext *frames_ctx = (AVHWFramesContext*)avctx->hw_frames_ctx->data;
243  AVQSVFramesContext *frames_hwctx = frames_ctx->hwctx;
244 
245  if (!iopattern) {
246  if (frames_hwctx->frame_type & MFX_MEMTYPE_OPAQUE_FRAME)
247  iopattern = MFX_IOPATTERN_OUT_OPAQUE_MEMORY;
248  else if (frames_hwctx->frame_type & MFX_MEMTYPE_VIDEO_MEMORY_DECODER_TARGET)
249  iopattern = MFX_IOPATTERN_OUT_VIDEO_MEMORY;
250  }
251  }
252 
253  if (!iopattern)
254  iopattern = MFX_IOPATTERN_OUT_SYSTEM_MEMORY;
255  q->iopattern = iopattern;
256 
257  ff_qsv_print_iopattern(avctx, q->iopattern, "Decoder");
258 
259  ret = qsv_init_session(avctx, q, session, avctx->hw_frames_ctx, avctx->hw_device_ctx);
260  if (ret < 0) {
261  av_log(avctx, AV_LOG_ERROR, "Error initializing an MFX session\n");
262  return ret;
263  }
264 
265  param->IOPattern = q->iopattern;
266  param->AsyncDepth = q->async_depth;
267  param->ExtParam = q->ext_buffers;
268  param->NumExtParam = q->nb_ext_buffers;
269 
270  return 0;
271  }
272 
273 static int qsv_decode_init_context(AVCodecContext *avctx, QSVContext *q, mfxVideoParam *param)
274 {
275  int ret;
276 
277  avctx->width = param->mfx.FrameInfo.CropW;
278  avctx->height = param->mfx.FrameInfo.CropH;
279  avctx->coded_width = param->mfx.FrameInfo.Width;
280  avctx->coded_height = param->mfx.FrameInfo.Height;
281  avctx->level = param->mfx.CodecLevel;
282  avctx->profile = param->mfx.CodecProfile;
283  avctx->field_order = ff_qsv_map_picstruct(param->mfx.FrameInfo.PicStruct);
284  avctx->pix_fmt = ff_qsv_map_fourcc(param->mfx.FrameInfo.FourCC);
285 
286  ret = MFXVideoDECODE_Init(q->session, param);
287  if (ret < 0)
288  return ff_qsv_print_error(avctx, ret,
289  "Error initializing the MFX video decoder");
290 
291  q->frame_info = param->mfx.FrameInfo;
292 
293  if (!avctx->hw_frames_ctx) {
294  ret = av_image_get_buffer_size(avctx->pix_fmt, FFALIGN(avctx->width, 128), FFALIGN(avctx->height, 64), 1);
295  if (ret < 0)
296  return ret;
298  }
299  return 0;
300 }
301 
303  const AVPacket *avpkt, enum AVPixelFormat pix_fmt,
304  mfxVideoParam *param)
305 {
306  int ret;
307 
308  mfxBitstream bs = { 0 };
309 
310  if (avpkt->size) {
311  bs.Data = avpkt->data;
312  bs.DataLength = avpkt->size;
313  bs.MaxLength = bs.DataLength;
314  bs.TimeStamp = avpkt->pts;
315  if (avctx->field_order == AV_FIELD_PROGRESSIVE)
316  bs.DataFlag |= MFX_BITSTREAM_COMPLETE_FRAME;
317  } else
318  return AVERROR_INVALIDDATA;
319 
320 
321  if(!q->session) {
322  ret = qsv_decode_preinit(avctx, q, pix_fmt, param);
323  if (ret < 0)
324  return ret;
325  }
326 
327  ret = ff_qsv_codec_id_to_mfx(avctx->codec_id);
328  if (ret < 0)
329  return ret;
330 
331  param->mfx.CodecId = ret;
332  ret = MFXVideoDECODE_DecodeHeader(q->session, &bs, param);
333  if (MFX_ERR_MORE_DATA == ret) {
334  return AVERROR(EAGAIN);
335  }
336  if (ret < 0)
337  return ff_qsv_print_error(avctx, ret,
338  "Error decoding stream header");
339 
340  return 0;
341 }
342 
344 {
345  int ret;
346 
347  if (q->pool)
348  ret = qsv_get_continuous_buffer(avctx, frame->frame, q->pool);
349  else
350  ret = ff_get_buffer(avctx, frame->frame, AV_GET_BUFFER_FLAG_REF);
351 
352  if (ret < 0)
353  return ret;
354 
355  if (frame->frame->format == AV_PIX_FMT_QSV) {
356  frame->surface = *(mfxFrameSurface1*)frame->frame->data[3];
357  } else {
358  frame->surface.Info = q->frame_info;
359 
360  frame->surface.Data.PitchLow = frame->frame->linesize[0];
361  frame->surface.Data.Y = frame->frame->data[0];
362  frame->surface.Data.UV = frame->frame->data[1];
363  }
364 
365  if (q->frames_ctx.mids) {
367  if (ret < 0)
368  return ret;
369 
370  frame->surface.Data.MemId = &q->frames_ctx.mids[ret];
371  }
372  frame->surface.Data.ExtParam = &frame->ext_param;
373  frame->surface.Data.NumExtParam = 1;
374  frame->ext_param = (mfxExtBuffer*)&frame->dec_info;
375  frame->dec_info.Header.BufferId = MFX_EXTBUFF_DECODED_FRAME_INFO;
376  frame->dec_info.Header.BufferSz = sizeof(frame->dec_info);
377 
378  frame->used = 1;
379 
380  return 0;
381 }
382 
384 {
385  QSVFrame *cur = q->work_frames;
386  while (cur) {
387  if (cur->used && !cur->surface.Data.Locked && !cur->queued) {
388  cur->used = 0;
389  av_frame_unref(cur->frame);
390  }
391  cur = cur->next;
392  }
393 }
394 
395 static int get_surface(AVCodecContext *avctx, QSVContext *q, mfxFrameSurface1 **surf)
396 {
397  QSVFrame *frame, **last;
398  int ret;
399 
401 
402  frame = q->work_frames;
403  last = &q->work_frames;
404  while (frame) {
405  if (!frame->used) {
406  ret = alloc_frame(avctx, q, frame);
407  if (ret < 0)
408  return ret;
409  *surf = &frame->surface;
410  return 0;
411  }
412 
413  last = &frame->next;
414  frame = frame->next;
415  }
416 
417  frame = av_mallocz(sizeof(*frame));
418  if (!frame)
419  return AVERROR(ENOMEM);
420  frame->frame = av_frame_alloc();
421  if (!frame->frame) {
422  av_freep(&frame);
423  return AVERROR(ENOMEM);
424  }
425  *last = frame;
426 
427  ret = alloc_frame(avctx, q, frame);
428  if (ret < 0)
429  return ret;
430 
431  *surf = &frame->surface;
432 
433  return 0;
434 }
435 
436 static QSVFrame *find_frame(QSVContext *q, mfxFrameSurface1 *surf)
437 {
438  QSVFrame *cur = q->work_frames;
439  while (cur) {
440  if (surf == &cur->surface)
441  return cur;
442  cur = cur->next;
443  }
444  return NULL;
445 }
446 
447 static int qsv_decode(AVCodecContext *avctx, QSVContext *q,
448  AVFrame *frame, int *got_frame,
449  const AVPacket *avpkt)
450 {
451  QSVFrame *out_frame;
452  mfxFrameSurface1 *insurf;
453  mfxFrameSurface1 *outsurf;
454  mfxSyncPoint *sync;
455  mfxBitstream bs = { { { 0 } } };
456  int ret;
457 
458  if (avpkt->size) {
459  bs.Data = avpkt->data;
460  bs.DataLength = avpkt->size;
461  bs.MaxLength = bs.DataLength;
462  bs.TimeStamp = avpkt->pts;
463  if (avctx->field_order == AV_FIELD_PROGRESSIVE)
464  bs.DataFlag |= MFX_BITSTREAM_COMPLETE_FRAME;
465  }
466 
467  sync = av_mallocz(sizeof(*sync));
468  if (!sync) {
469  av_freep(&sync);
470  return AVERROR(ENOMEM);
471  }
472 
473  do {
474  ret = get_surface(avctx, q, &insurf);
475  if (ret < 0) {
476  av_freep(&sync);
477  return ret;
478  }
479 
480  ret = MFXVideoDECODE_DecodeFrameAsync(q->session, avpkt->size ? &bs : NULL,
481  insurf, &outsurf, sync);
482  if (ret == MFX_WRN_DEVICE_BUSY)
483  av_usleep(500);
484 
485  } while (ret == MFX_WRN_DEVICE_BUSY || ret == MFX_ERR_MORE_SURFACE);
486 
487  if (ret != MFX_ERR_NONE &&
488  ret != MFX_ERR_MORE_DATA &&
489  ret != MFX_WRN_VIDEO_PARAM_CHANGED &&
490  ret != MFX_ERR_MORE_SURFACE) {
491  av_freep(&sync);
492  return ff_qsv_print_error(avctx, ret,
493  "Error during QSV decoding.");
494  }
495 
496  /* make sure we do not enter an infinite loop if the SDK
497  * did not consume any data and did not return anything */
498  if (!*sync && !bs.DataOffset) {
499  bs.DataOffset = avpkt->size;
500  ++q->zero_consume_run;
501  if (q->zero_consume_run > 1)
502  ff_qsv_print_warning(avctx, ret, "A decode call did not consume any data");
503  } else if (!*sync && bs.DataOffset) {
504  ++q->buffered_count;
505  } else {
506  q->zero_consume_run = 0;
507  }
508 
509  if (*sync) {
510  QSVFrame *out_frame = find_frame(q, outsurf);
511 
512  if (!out_frame) {
513  av_log(avctx, AV_LOG_ERROR,
514  "The returned surface does not correspond to any frame\n");
515  av_freep(&sync);
516  return AVERROR_BUG;
517  }
518 
519  out_frame->queued = 1;
520  av_fifo_generic_write(q->async_fifo, &out_frame, sizeof(out_frame), NULL);
521  av_fifo_generic_write(q->async_fifo, &sync, sizeof(sync), NULL);
522  } else {
523  av_freep(&sync);
524  }
525 
526  if ((qsv_fifo_size(q->async_fifo) >= q->async_depth) ||
527  (!avpkt->size && av_fifo_size(q->async_fifo))) {
528  AVFrame *src_frame;
529 
530  av_fifo_generic_read(q->async_fifo, &out_frame, sizeof(out_frame), NULL);
531  av_fifo_generic_read(q->async_fifo, &sync, sizeof(sync), NULL);
532  out_frame->queued = 0;
533 
534  if (avctx->pix_fmt != AV_PIX_FMT_QSV) {
535  do {
536  ret = MFXVideoCORE_SyncOperation(q->session, *sync, 1000);
537  } while (ret == MFX_WRN_IN_EXECUTION);
538  }
539 
540  av_freep(&sync);
541 
542  src_frame = out_frame->frame;
543 
544  ret = av_frame_ref(frame, src_frame);
545  if (ret < 0)
546  return ret;
547 
548  outsurf = &out_frame->surface;
549 
550 #if FF_API_PKT_PTS
552  frame->pkt_pts = outsurf->Data.TimeStamp;
554 #endif
555  frame->pts = outsurf->Data.TimeStamp;
556 
557  frame->repeat_pict =
558  outsurf->Info.PicStruct & MFX_PICSTRUCT_FRAME_TRIPLING ? 4 :
559  outsurf->Info.PicStruct & MFX_PICSTRUCT_FRAME_DOUBLING ? 2 :
560  outsurf->Info.PicStruct & MFX_PICSTRUCT_FIELD_REPEATED ? 1 : 0;
562  outsurf->Info.PicStruct & MFX_PICSTRUCT_FIELD_TFF;
564  !(outsurf->Info.PicStruct & MFX_PICSTRUCT_PROGRESSIVE);
565  frame->pict_type = ff_qsv_map_pictype(out_frame->dec_info.FrameType);
566  //Key frame is IDR frame is only suitable for H264. For HEVC, IRAPs are key frames.
567  if (avctx->codec_id == AV_CODEC_ID_H264)
568  frame->key_frame = !!(out_frame->dec_info.FrameType & MFX_FRAMETYPE_IDR);
569 
570  /* update the surface properties */
571  if (avctx->pix_fmt == AV_PIX_FMT_QSV)
572  ((mfxFrameSurface1*)frame->data[3])->Info = outsurf->Info;
573 
574  *got_frame = 1;
575  }
576 
577  return bs.DataOffset;
578 }
579 
581 {
582  QSVFrame *cur = q->work_frames;
583 
584  if (q->session)
585  MFXVideoDECODE_Close(q->session);
586 
587  while (q->async_fifo && av_fifo_size(q->async_fifo)) {
588  QSVFrame *out_frame;
589  mfxSyncPoint *sync;
590 
591  av_fifo_generic_read(q->async_fifo, &out_frame, sizeof(out_frame), NULL);
592  av_fifo_generic_read(q->async_fifo, &sync, sizeof(sync), NULL);
593 
594  av_freep(&sync);
595  }
596 
597  while (cur) {
598  q->work_frames = cur->next;
599  av_frame_free(&cur->frame);
600  av_freep(&cur);
601  cur = q->work_frames;
602  }
603 
605  q->async_fifo = NULL;
606 
608 
612 }
613 
615  AVFrame *frame, int *got_frame, const AVPacket *pkt)
616 {
617  int ret;
618  mfxVideoParam param = { 0 };
620 
621  if (!pkt->size)
622  return qsv_decode(avctx, q, frame, got_frame, pkt);
623 
624  /* TODO: flush delayed frames on reinit */
625 
626  // sw_pix_fmt, coded_width/height should be set for ff_get_format(),
627  // assume sw_pix_fmt is NV12 and coded_width/height to be 1280x720,
628  // the assumption may be not corret but will be updated after header decoded if not true.
629  if (q->orig_pix_fmt != AV_PIX_FMT_NONE)
630  pix_fmt = q->orig_pix_fmt;
631  if (!avctx->coded_width)
632  avctx->coded_width = 1280;
633  if (!avctx->coded_height)
634  avctx->coded_height = 720;
635 
636  ret = qsv_decode_header(avctx, q, pkt, pix_fmt, &param);
637 
638  if (ret >= 0 && (q->orig_pix_fmt != ff_qsv_map_fourcc(param.mfx.FrameInfo.FourCC) ||
639  avctx->coded_width != param.mfx.FrameInfo.Width ||
640  avctx->coded_height != param.mfx.FrameInfo.Height)) {
641  AVPacket zero_pkt = {0};
642 
643  if (q->buffered_count) {
644  q->reinit_flag = 1;
645  /* decode zero-size pkt to flush the buffered pkt before reinit */
646  q->buffered_count--;
647  return qsv_decode(avctx, q, frame, got_frame, &zero_pkt);
648  }
649  q->reinit_flag = 0;
650 
651  q->orig_pix_fmt = avctx->pix_fmt = pix_fmt = ff_qsv_map_fourcc(param.mfx.FrameInfo.FourCC);
652 
653  avctx->coded_width = param.mfx.FrameInfo.Width;
654  avctx->coded_height = param.mfx.FrameInfo.Height;
655 
656  ret = qsv_decode_preinit(avctx, q, pix_fmt, &param);
657  if (ret < 0)
658  goto reinit_fail;
659  q->initialized = 0;
660  }
661 
662  if (!q->initialized) {
663  ret = qsv_decode_init_context(avctx, q, &param);
664  if (ret < 0)
665  goto reinit_fail;
666  q->initialized = 1;
667  }
668 
669  return qsv_decode(avctx, q, frame, got_frame, pkt);
670 
671 reinit_fail:
672  q->orig_pix_fmt = avctx->pix_fmt = AV_PIX_FMT_NONE;
673  return ret;
674 }
675 
680 };
681 
682 typedef struct QSVDecContext {
683  AVClass *class;
685 
687 
689 
691 } QSVDecContext;
692 
694 {
695  AVPacket pkt;
696  while (av_fifo_size(s->packet_fifo) >= sizeof(pkt)) {
697  av_fifo_generic_read(s->packet_fifo, &pkt, sizeof(pkt), NULL);
699  }
700 
701  av_packet_unref(&s->buffer_pkt);
702 }
703 
705 {
706  QSVDecContext *s = avctx->priv_data;
707 
708  av_freep(&s->qsv.load_plugins);
709 
711 
713 
714  av_fifo_free(s->packet_fifo);
715 
716  return 0;
717 }
718 
720 {
721  QSVDecContext *s = avctx->priv_data;
722  int ret;
723  const char *uid = NULL;
724 
725  if (avctx->codec_id == AV_CODEC_ID_VP8) {
726  uid = "f622394d8d87452f878c51f2fc9b4131";
727  } else if (avctx->codec_id == AV_CODEC_ID_VP9) {
728  uid = "a922394d8d87452f878c51f2fc9b4131";
729  }
730  else if (avctx->codec_id == AV_CODEC_ID_HEVC && s->load_plugin != LOAD_PLUGIN_NONE) {
731  static const char * const uid_hevcdec_sw = "15dd936825ad475ea34e35f3f54217a6";
732  static const char * const uid_hevcdec_hw = "33a61c0b4c27454ca8d85dde757c6f8e";
733 
734  if (s->qsv.load_plugins[0]) {
735  av_log(avctx, AV_LOG_WARNING,
736  "load_plugins is not empty, but load_plugin is not set to 'none'."
737  "The load_plugin value will be ignored.\n");
738  } else {
739  if (s->load_plugin == LOAD_PLUGIN_HEVC_SW)
740  uid = uid_hevcdec_sw;
741  else
742  uid = uid_hevcdec_hw;
743  }
744  }
745  if (uid) {
746  av_freep(&s->qsv.load_plugins);
747  s->qsv.load_plugins = av_strdup(uid);
748  if (!s->qsv.load_plugins)
749  return AVERROR(ENOMEM);
750  }
751 
752  s->qsv.orig_pix_fmt = AV_PIX_FMT_NV12;
753  s->packet_fifo = av_fifo_alloc(sizeof(AVPacket));
754  if (!s->packet_fifo) {
755  ret = AVERROR(ENOMEM);
756  goto fail;
757  }
758 
759  return 0;
760 fail:
761  qsv_decode_close(avctx);
762  return ret;
763 }
764 
765 static int qsv_decode_frame(AVCodecContext *avctx, void *data,
766  int *got_frame, AVPacket *avpkt)
767 {
768  QSVDecContext *s = avctx->priv_data;
769  AVFrame *frame = data;
770  int ret;
771 
772  /* buffer the input packet */
773  if (avpkt->size) {
774  AVPacket input_ref;
775 
776  if (av_fifo_space(s->packet_fifo) < sizeof(input_ref)) {
777  ret = av_fifo_realloc2(s->packet_fifo,
778  av_fifo_size(s->packet_fifo) + sizeof(input_ref));
779  if (ret < 0)
780  return ret;
781  }
782 
783  ret = av_packet_ref(&input_ref, avpkt);
784  if (ret < 0)
785  return ret;
786  av_fifo_generic_write(s->packet_fifo, &input_ref, sizeof(input_ref), NULL);
787  }
788 
789  /* process buffered data */
790  while (!*got_frame) {
791  /* prepare the input data */
792  if (s->buffer_pkt.size <= 0) {
793  /* no more data */
794  if (av_fifo_size(s->packet_fifo) < sizeof(AVPacket))
795  return avpkt->size ? avpkt->size : qsv_process_data(avctx, &s->qsv, frame, got_frame, avpkt);
796  /* in progress of reinit, no read from fifo and keep the buffer_pkt */
797  if (!s->qsv.reinit_flag) {
798  av_packet_unref(&s->buffer_pkt);
799  av_fifo_generic_read(s->packet_fifo, &s->buffer_pkt, sizeof(s->buffer_pkt), NULL);
800  }
801  }
802 
803  ret = qsv_process_data(avctx, &s->qsv, frame, got_frame, &s->buffer_pkt);
804  if (ret < 0){
805  /* Drop buffer_pkt when failed to decode the packet. Otherwise,
806  the decoder will keep decoding the failure packet. */
807  av_packet_unref(&s->buffer_pkt);
808  return ret;
809  }
810  if (s->qsv.reinit_flag)
811  continue;
812 
813  s->buffer_pkt.size -= ret;
814  s->buffer_pkt.data += ret;
815  }
816 
817  return avpkt->size;
818 }
819 
820 static void qsv_decode_flush(AVCodecContext *avctx)
821 {
822  QSVDecContext *s = avctx->priv_data;
823 
825 
826  s->qsv.orig_pix_fmt = AV_PIX_FMT_NONE;
827  s->qsv.initialized = 0;
828 }
829 
830 #define OFFSET(x) offsetof(QSVDecContext, x)
831 #define VD AV_OPT_FLAG_VIDEO_PARAM | AV_OPT_FLAG_DECODING_PARAM
832 
833 #define DEFINE_QSV_DECODER_WITH_OPTION(x, X, bsf_name, opt) \
834 static const AVClass x##_qsv_class = { \
835  .class_name = #x "_qsv", \
836  .item_name = av_default_item_name, \
837  .option = opt, \
838  .version = LIBAVUTIL_VERSION_INT, \
839 }; \
840 AVCodec ff_##x##_qsv_decoder = { \
841  .name = #x "_qsv", \
842  .long_name = NULL_IF_CONFIG_SMALL(#X " video (Intel Quick Sync Video acceleration)"), \
843  .priv_data_size = sizeof(QSVDecContext), \
844  .type = AVMEDIA_TYPE_VIDEO, \
845  .id = AV_CODEC_ID_##X, \
846  .init = qsv_decode_init, \
847  .decode = qsv_decode_frame, \
848  .flush = qsv_decode_flush, \
849  .close = qsv_decode_close, \
850  .bsfs = bsf_name, \
851  .capabilities = AV_CODEC_CAP_DELAY | AV_CODEC_CAP_DR1 | AV_CODEC_CAP_AVOID_PROBING | AV_CODEC_CAP_HYBRID, \
852  .priv_class = &x##_qsv_class, \
853  .pix_fmts = (const enum AVPixelFormat[]){ AV_PIX_FMT_NV12, \
854  AV_PIX_FMT_P010, \
855  AV_PIX_FMT_QSV, \
856  AV_PIX_FMT_NONE }, \
857  .hw_configs = qsv_hw_configs, \
858  .wrapper_name = "qsv", \
859 }; \
860 
861 #define DEFINE_QSV_DECODER(x, X, bsf_name) DEFINE_QSV_DECODER_WITH_OPTION(x, X, bsf_name, options)
862 
863 #if CONFIG_HEVC_QSV_DECODER
864 static const AVOption hevc_options[] = {
865  { "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 },
866 
867  { "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" },
868  { "none", NULL, 0, AV_OPT_TYPE_CONST, { .i64 = LOAD_PLUGIN_NONE }, 0, 0, VD, "load_plugin" },
869  { "hevc_sw", NULL, 0, AV_OPT_TYPE_CONST, { .i64 = LOAD_PLUGIN_HEVC_SW }, 0, 0, VD, "load_plugin" },
870  { "hevc_hw", NULL, 0, AV_OPT_TYPE_CONST, { .i64 = LOAD_PLUGIN_HEVC_HW }, 0, 0, VD, "load_plugin" },
871 
872  { "load_plugins", "A :-separate list of hexadecimal plugin UIDs to load in an internal session",
873  OFFSET(qsv.load_plugins), AV_OPT_TYPE_STRING, { .str = "" }, 0, 0, VD },
874 
875  { "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"},
876  { "default", NULL, 0, AV_OPT_TYPE_CONST, { .i64 = MFX_GPUCOPY_DEFAULT }, 0, 0, VD, "gpu_copy"},
877  { "on", NULL, 0, AV_OPT_TYPE_CONST, { .i64 = MFX_GPUCOPY_ON }, 0, 0, VD, "gpu_copy"},
878  { "off", NULL, 0, AV_OPT_TYPE_CONST, { .i64 = MFX_GPUCOPY_OFF }, 0, 0, VD, "gpu_copy"},
879  { NULL },
880 };
881 DEFINE_QSV_DECODER_WITH_OPTION(hevc, HEVC, "hevc_mp4toannexb", hevc_options)
882 #endif
883 
884 static const AVOption options[] = {
885  { "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 },
886 
887  { "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"},
888  { "default", NULL, 0, AV_OPT_TYPE_CONST, { .i64 = MFX_GPUCOPY_DEFAULT }, 0, 0, VD, "gpu_copy"},
889  { "on", NULL, 0, AV_OPT_TYPE_CONST, { .i64 = MFX_GPUCOPY_ON }, 0, 0, VD, "gpu_copy"},
890  { "off", NULL, 0, AV_OPT_TYPE_CONST, { .i64 = MFX_GPUCOPY_OFF }, 0, 0, VD, "gpu_copy"},
891  { NULL },
892 };
893 
894 #if CONFIG_H264_QSV_DECODER
895 DEFINE_QSV_DECODER(h264, H264, "h264_mp4toannexb")
896 #endif
897 
898 #if CONFIG_MPEG2_QSV_DECODER
899 DEFINE_QSV_DECODER(mpeg2, MPEG2VIDEO, NULL)
900 #endif
901 
902 #if CONFIG_VC1_QSV_DECODER
903 DEFINE_QSV_DECODER(vc1, VC1, NULL)
904 #endif
905 
906 #if CONFIG_MJPEG_QSV_DECODER
907 DEFINE_QSV_DECODER(mjpeg, MJPEG, NULL)
908 #endif
909 
910 #if CONFIG_VP8_QSV_DECODER
911 DEFINE_QSV_DECODER(vp8, VP8, NULL)
912 #endif
913 
914 #if CONFIG_VP9_QSV_DECODER
915 DEFINE_QSV_DECODER(vp9, VP9, NULL)
916 #endif
917 
918 #if CONFIG_AV1_QSV_DECODER
919 DEFINE_QSV_DECODER(av1, AV1, NULL)
920 #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:1900
int ff_decode_frame_props(AVCodecContext *avctx, AVFrame *frame)
Set various frame properties from the codec context / packet data.
Definition: decode.c:1731
int ff_attach_decode_data(AVFrame *frame)
Definition: decode.c:1876
int ff_get_format(AVCodecContext *avctx, const enum AVPixelFormat *fmt)
Select the (possibly hardware accelerated) pixel format.
Definition: decode.c:1326
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:466
@ 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:614
static int qsv_decode(AVCodecContext *avctx, QSVContext *q, AVFrame *frame, int *got_frame, const AVPacket *avpkt)
Definition: qsvdec.c:447
static void qsv_clear_unused_frames(QSVContext *q)
Definition: qsvdec.c:383
static const AVOption options[]
Definition: qsvdec.c:884
#define DEFINE_QSV_DECODER_WITH_OPTION(x, X, bsf_name, opt)
Definition: qsvdec.c:833
static int qsv_decode_header(AVCodecContext *avctx, QSVContext *q, const AVPacket *avpkt, enum AVPixelFormat pix_fmt, mfxVideoParam *param)
Definition: qsvdec.c:302
static int qsv_decode_preinit(AVCodecContext *avctx, QSVContext *q, enum AVPixelFormat pix_fmt, mfxVideoParam *param)
Definition: qsvdec.c:211
static int qsv_decode_init_context(AVCodecContext *avctx, QSVContext *q, mfxVideoParam *param)
Definition: qsvdec.c:273
static int get_surface(AVCodecContext *avctx, QSVContext *q, mfxFrameSurface1 **surf)
Definition: qsvdec.c:395
static int qsv_decode_frame(AVCodecContext *avctx, void *data, int *got_frame, AVPacket *avpkt)
Definition: qsvdec.c:765
static void qsv_decode_flush(AVCodecContext *avctx)
Definition: qsvdec.c:820
static QSVFrame * find_frame(QSVContext *q, mfxFrameSurface1 *surf)
Definition: qsvdec.c:436
#define DEFINE_QSV_DECODER(x, X, bsf_name)
Definition: qsvdec.c:861
static void qsv_decode_close_qsvcontext(QSVContext *q)
Definition: qsvdec.c:580
static const AVCodecHWConfigInternal *const qsv_hw_configs[]
Definition: qsvdec.c:87
static void qsv_clear_buffers(QSVDecContext *s)
Definition: qsvdec.c:693
#define VD
Definition: qsvdec.c:831
static av_cold int qsv_decode_init(AVCodecContext *avctx)
Definition: qsvdec.c:719
static av_cold int qsv_decode_close(AVCodecContext *avctx)
Definition: qsvdec.c:704
LoadPlugin
Definition: qsvdec.c:676
@ LOAD_PLUGIN_NONE
Definition: qsvdec.c:677
@ LOAD_PLUGIN_HEVC_HW
Definition: qsvdec.c:679
@ LOAD_PLUGIN_HEVC_SW
Definition: qsvdec.c:678
static int alloc_frame(AVCodecContext *avctx, QSVContext *q, QSVFrame *frame)
Definition: qsvdec.c:343
#define OFFSET(x)
Definition: qsvdec.c:830
static unsigned int qsv_fifo_item_size(void)
Definition: qsvdec.c:201
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:138
static unsigned int qsv_fifo_size(const AVFifoBuffer *fifo)
Definition: qsvdec.c:206
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:2218
enum AVFieldOrder field_order
Field order.
Definition: avcodec.h:1193
int level
level
Definition: avcodec.h:1984
int profile
profile
Definition: avcodec.h:1858
void * hwaccel_context
Hardware accelerator context.
Definition: avcodec.h:1692
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:2270
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:690
QSVContext qsv
Definition: qsvdec.c:684
int load_plugin
Definition: qsvdec.c:686
AVFifoBuffer * packet_fifo
Definition: qsvdec.c:688
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[]