Libav
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 Libav.
8  *
9  * Libav 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  * Libav 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 Libav; if not, write to the Free Software
21  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
22  */
23 
24 #include <string.h>
25 #include <sys/types.h>
26 
27 #include <mfx/mfxvideo.h>
28 
29 #include "libavutil/common.h"
30 #include "libavutil/hwcontext.h"
32 #include "libavutil/mem.h"
33 #include "libavutil/log.h"
34 #include "libavutil/pixdesc.h"
35 #include "libavutil/pixfmt.h"
36 #include "libavutil/time.h"
37 
38 #include "avcodec.h"
39 #include "internal.h"
40 #include "qsv.h"
41 #include "qsv_internal.h"
42 #include "qsvdec.h"
43 
44 static int qsv_init_session(AVCodecContext *avctx, QSVContext *q, mfxSession session,
45  AVBufferRef *hw_frames_ref)
46 {
47  int ret;
48 
49  if (session) {
50  q->session = session;
51  } else if (hw_frames_ref) {
52  if (q->internal_session) {
53  MFXClose(q->internal_session);
55  }
57 
58  q->frames_ctx.hw_frames_ctx = av_buffer_ref(hw_frames_ref);
59  if (!q->frames_ctx.hw_frames_ctx)
60  return AVERROR(ENOMEM);
61 
63  &q->frames_ctx, q->load_plugins,
64  q->iopattern == MFX_IOPATTERN_OUT_OPAQUE_MEMORY);
65  if (ret < 0) {
67  return ret;
68  }
69 
70  q->session = q->internal_session;
71  } else {
72  if (!q->internal_session) {
74  q->load_plugins);
75  if (ret < 0)
76  return ret;
77  }
78 
79  q->session = q->internal_session;
80  }
81 
82  /* make sure the decoder is uninitialized */
83  MFXVideoDECODE_Close(q->session);
84 
85  return 0;
86 }
87 
89 {
90  const AVPixFmtDescriptor *desc;
91  mfxSession session = NULL;
92  int iopattern = 0;
93  mfxVideoParam param = { { 0 } };
94  int frame_width = avctx->coded_width;
95  int frame_height = avctx->coded_height;
96  int ret;
97 
98  desc = av_pix_fmt_desc_get(avctx->sw_pix_fmt);
99  if (!desc)
100  return AVERROR_BUG;
101 
102  if (!q->async_fifo) {
103  q->async_fifo = av_fifo_alloc((1 + q->async_depth) *
104  (sizeof(mfxSyncPoint*) + sizeof(QSVFrame*)));
105  if (!q->async_fifo)
106  return AVERROR(ENOMEM);
107  }
108 
109  if (avctx->pix_fmt == AV_PIX_FMT_QSV && avctx->hwaccel_context) {
110  AVQSVContext *user_ctx = avctx->hwaccel_context;
111  session = user_ctx->session;
112  iopattern = user_ctx->iopattern;
113  q->ext_buffers = user_ctx->ext_buffers;
114  q->nb_ext_buffers = user_ctx->nb_ext_buffers;
115  }
116 
117  if (avctx->hw_frames_ctx) {
118  AVHWFramesContext *frames_ctx = (AVHWFramesContext*)avctx->hw_frames_ctx->data;
119  AVQSVFramesContext *frames_hwctx = frames_ctx->hwctx;
120 
121  if (!iopattern) {
122  if (frames_hwctx->frame_type & MFX_MEMTYPE_OPAQUE_FRAME)
123  iopattern = MFX_IOPATTERN_OUT_OPAQUE_MEMORY;
124  else if (frames_hwctx->frame_type & MFX_MEMTYPE_VIDEO_MEMORY_DECODER_TARGET)
125  iopattern = MFX_IOPATTERN_OUT_VIDEO_MEMORY;
126  }
127 
128  frame_width = frames_hwctx->surfaces[0].Info.Width;
129  frame_height = frames_hwctx->surfaces[0].Info.Height;
130  }
131 
132  if (!iopattern)
133  iopattern = MFX_IOPATTERN_OUT_SYSTEM_MEMORY;
134  q->iopattern = iopattern;
135 
136  ret = qsv_init_session(avctx, q, session, avctx->hw_frames_ctx);
137  if (ret < 0) {
138  av_log(avctx, AV_LOG_ERROR, "Error initializing an MFX session\n");
139  return ret;
140  }
141 
142  ret = ff_qsv_codec_id_to_mfx(avctx->codec_id);
143  if (ret < 0)
144  return ret;
145 
146  param.mfx.CodecId = ret;
147  param.mfx.CodecProfile = avctx->profile;
148  param.mfx.CodecLevel = avctx->level;
149 
150  param.mfx.FrameInfo.BitDepthLuma = desc->comp[0].depth;
151  param.mfx.FrameInfo.BitDepthChroma = desc->comp[0].depth;
152  param.mfx.FrameInfo.Shift = desc->comp[0].depth > 8;
153  param.mfx.FrameInfo.FourCC = q->fourcc;
154  param.mfx.FrameInfo.Width = frame_width;
155  param.mfx.FrameInfo.Height = frame_height;
156  param.mfx.FrameInfo.ChromaFormat = MFX_CHROMAFORMAT_YUV420;
157 
158  param.IOPattern = q->iopattern;
159  param.AsyncDepth = q->async_depth;
160  param.ExtParam = q->ext_buffers;
161  param.NumExtParam = q->nb_ext_buffers;
162 
163  ret = MFXVideoDECODE_Init(q->session, &param);
164  if (ret < 0)
165  return ff_qsv_print_error(avctx, ret,
166  "Error initializing the MFX video decoder");
167 
168  q->frame_info = param.mfx.FrameInfo;
169 
170  return 0;
171 }
172 
173 static int alloc_frame(AVCodecContext *avctx, QSVContext *q, QSVFrame *frame)
174 {
175  int ret;
176 
177  ret = ff_get_buffer(avctx, frame->frame, AV_GET_BUFFER_FLAG_REF);
178  if (ret < 0)
179  return ret;
180 
181  if (frame->frame->format == AV_PIX_FMT_QSV) {
182  frame->surface = (mfxFrameSurface1*)frame->frame->data[3];
183  } else {
184  frame->surface_internal.Info = q->frame_info;
185 
186  frame->surface_internal.Data.PitchLow = frame->frame->linesize[0];
187  frame->surface_internal.Data.Y = frame->frame->data[0];
188  frame->surface_internal.Data.UV = frame->frame->data[1];
189 
190  frame->surface = &frame->surface_internal;
191  }
192 
193  return 0;
194 }
195 
197 {
198  QSVFrame *cur = q->work_frames;
199  while (cur) {
200  if (cur->surface && !cur->surface->Data.Locked && !cur->queued) {
201  cur->surface = NULL;
202  av_frame_unref(cur->frame);
203  }
204  cur = cur->next;
205  }
206 }
207 
208 static int get_surface(AVCodecContext *avctx, QSVContext *q, mfxFrameSurface1 **surf)
209 {
210  QSVFrame *frame, **last;
211  int ret;
212 
214 
215  frame = q->work_frames;
216  last = &q->work_frames;
217  while (frame) {
218  if (!frame->surface) {
219  ret = alloc_frame(avctx, q, frame);
220  if (ret < 0)
221  return ret;
222  *surf = frame->surface;
223  return 0;
224  }
225 
226  last = &frame->next;
227  frame = frame->next;
228  }
229 
230  frame = av_mallocz(sizeof(*frame));
231  if (!frame)
232  return AVERROR(ENOMEM);
233  frame->frame = av_frame_alloc();
234  if (!frame->frame) {
235  av_freep(&frame);
236  return AVERROR(ENOMEM);
237  }
238  *last = frame;
239 
240  ret = alloc_frame(avctx, q, frame);
241  if (ret < 0)
242  return ret;
243 
244  *surf = frame->surface;
245 
246  return 0;
247 }
248 
249 static QSVFrame *find_frame(QSVContext *q, mfxFrameSurface1 *surf)
250 {
251  QSVFrame *cur = q->work_frames;
252  while (cur) {
253  if (surf == cur->surface)
254  return cur;
255  cur = cur->next;
256  }
257  return NULL;
258 }
259 
260 static int qsv_decode(AVCodecContext *avctx, QSVContext *q,
261  AVFrame *frame, int *got_frame,
262  AVPacket *avpkt)
263 {
264  QSVFrame *out_frame;
265  mfxFrameSurface1 *insurf;
266  mfxFrameSurface1 *outsurf;
267  mfxSyncPoint *sync;
268  mfxBitstream bs = { { { 0 } } };
269  int ret;
270 
271  if (avpkt->size) {
272  bs.Data = avpkt->data;
273  bs.DataLength = avpkt->size;
274  bs.MaxLength = bs.DataLength;
275  bs.TimeStamp = avpkt->pts;
276  }
277 
278  sync = av_mallocz(sizeof(*sync));
279  if (!sync) {
280  av_freep(&sync);
281  return AVERROR(ENOMEM);
282  }
283 
284  do {
285  ret = get_surface(avctx, q, &insurf);
286  if (ret < 0)
287  return ret;
288 
289  ret = MFXVideoDECODE_DecodeFrameAsync(q->session, avpkt->size ? &bs : NULL,
290  insurf, &outsurf, sync);
291  if (ret == MFX_WRN_DEVICE_BUSY)
292  av_usleep(1);
293 
294  } while (ret == MFX_WRN_DEVICE_BUSY || ret == MFX_ERR_MORE_SURFACE);
295 
296  if (ret != MFX_ERR_NONE &&
297  ret != MFX_ERR_MORE_DATA &&
298  ret != MFX_WRN_VIDEO_PARAM_CHANGED &&
299  ret != MFX_ERR_MORE_SURFACE) {
300  av_freep(&sync);
301  return ff_qsv_print_error(avctx, ret,
302  "Error during QSV decoding.");
303  }
304 
305  /* make sure we do not enter an infinite loop if the SDK
306  * did not consume any data and did not return anything */
307  if (!*sync && !bs.DataOffset) {
308  av_log(avctx, AV_LOG_WARNING, "A decode call did not consume any data\n");
309  bs.DataOffset = avpkt->size;
310  }
311 
312  if (*sync) {
313  QSVFrame *out_frame = find_frame(q, outsurf);
314 
315  if (!out_frame) {
316  av_log(avctx, AV_LOG_ERROR,
317  "The returned surface does not correspond to any frame\n");
318  av_freep(&sync);
319  return AVERROR_BUG;
320  }
321 
322  out_frame->queued = 1;
323  av_fifo_generic_write(q->async_fifo, &out_frame, sizeof(out_frame), NULL);
324  av_fifo_generic_write(q->async_fifo, &sync, sizeof(sync), NULL);
325  } else {
326  av_freep(&sync);
327  }
328 
329  if (!av_fifo_space(q->async_fifo) ||
330  (!avpkt->size && av_fifo_size(q->async_fifo))) {
331  AVFrame *src_frame;
332 
333  av_fifo_generic_read(q->async_fifo, &out_frame, sizeof(out_frame), NULL);
334  av_fifo_generic_read(q->async_fifo, &sync, sizeof(sync), NULL);
335  out_frame->queued = 0;
336 
337  do {
338  ret = MFXVideoCORE_SyncOperation(q->session, *sync, 1000);
339  } while (ret == MFX_WRN_IN_EXECUTION);
340 
341  av_freep(&sync);
342 
343  src_frame = out_frame->frame;
344 
345  ret = av_frame_ref(frame, src_frame);
346  if (ret < 0)
347  return ret;
348 
349  outsurf = out_frame->surface;
350 
351 #if FF_API_PKT_PTS
353  frame->pkt_pts = outsurf->Data.TimeStamp;
355 #endif
356  frame->pts = outsurf->Data.TimeStamp;
357 
358  frame->repeat_pict =
359  outsurf->Info.PicStruct & MFX_PICSTRUCT_FRAME_TRIPLING ? 4 :
360  outsurf->Info.PicStruct & MFX_PICSTRUCT_FRAME_DOUBLING ? 2 :
361  outsurf->Info.PicStruct & MFX_PICSTRUCT_FIELD_REPEATED ? 1 : 0;
362  frame->top_field_first =
363  outsurf->Info.PicStruct & MFX_PICSTRUCT_FIELD_TFF;
364  frame->interlaced_frame =
365  !(outsurf->Info.PicStruct & MFX_PICSTRUCT_PROGRESSIVE);
366 
367  *got_frame = 1;
368  }
369 
370  return bs.DataOffset;
371 }
372 
374 {
375  QSVFrame *cur = q->work_frames;
376 
377  if (q->session)
378  MFXVideoDECODE_Close(q->session);
379 
380  while (q->async_fifo && av_fifo_size(q->async_fifo)) {
381  QSVFrame *out_frame;
382  mfxSyncPoint *sync;
383 
384  av_fifo_generic_read(q->async_fifo, &out_frame, sizeof(out_frame), NULL);
385  av_fifo_generic_read(q->async_fifo, &sync, sizeof(sync), NULL);
386 
387  av_freep(&sync);
388  }
389 
390  while (cur) {
391  q->work_frames = cur->next;
392  av_frame_free(&cur->frame);
393  av_freep(&cur);
394  cur = q->work_frames;
395  }
396 
398  q->async_fifo = NULL;
399 
402 
403  if (q->internal_session)
404  MFXClose(q->internal_session);
405 
407  av_freep(&q->frames_ctx.mids);
408  q->frames_ctx.nb_mids = 0;
409 
410  return 0;
411 }
412 
414  AVFrame *frame, int *got_frame, AVPacket *pkt)
415 {
416  uint8_t *dummy_data;
417  int dummy_size;
418  int ret;
419 
420  if (!q->avctx_internal) {
422  if (!q->avctx_internal)
423  return AVERROR(ENOMEM);
424 
425  if (avctx->extradata) {
427  if (!q->avctx_internal->extradata)
428  return AVERROR(ENOMEM);
429 
430  memcpy(q->avctx_internal->extradata, avctx->extradata,
431  avctx->extradata_size);
433  }
434 
435  q->parser = av_parser_init(avctx->codec_id);
436  if (!q->parser)
437  return AVERROR(ENOMEM);
438 
441  }
442 
443  if (!pkt->size)
444  return qsv_decode(avctx, q, frame, got_frame, pkt);
445 
446  /* we assume the packets are already split properly and want
447  * just the codec parameters here */
449  &dummy_data, &dummy_size,
450  pkt->data, pkt->size, pkt->pts, pkt->dts,
451  pkt->pos);
452 
453  /* TODO: flush delayed frames on reinit */
454  if (q->parser->format != q->orig_pix_fmt ||
455  q->parser->coded_width != avctx->coded_width ||
456  q->parser->coded_height != avctx->coded_height) {
459  AV_PIX_FMT_NONE };
460  enum AVPixelFormat qsv_format;
461 
462  qsv_format = ff_qsv_map_pixfmt(q->parser->format, &q->fourcc);
463  if (qsv_format < 0) {
464  av_log(avctx, AV_LOG_ERROR,
465  "Decoding pixel format '%s' is not supported\n",
467  ret = AVERROR(ENOSYS);
468  goto reinit_fail;
469  }
470 
471  q->orig_pix_fmt = q->parser->format;
472  avctx->pix_fmt = pix_fmts[1] = qsv_format;
473  avctx->width = q->parser->width;
474  avctx->height = q->parser->height;
475  avctx->coded_width = q->parser->coded_width;
476  avctx->coded_height = q->parser->coded_height;
477  avctx->level = q->avctx_internal->level;
478  avctx->profile = q->avctx_internal->profile;
479 
480  ret = ff_get_format(avctx, pix_fmts);
481  if (ret < 0)
482  goto reinit_fail;
483 
484  avctx->pix_fmt = ret;
485 
486  ret = qsv_decode_init(avctx, q);
487  if (ret < 0)
488  goto reinit_fail;
489  }
490 
491  return qsv_decode(avctx, q, frame, got_frame, pkt);
492 
493 reinit_fail:
494  q->orig_pix_fmt = q->parser->format = avctx->pix_fmt = AV_PIX_FMT_NONE;
495  return ret;
496 }
497 
499 {
501 }
static int qsv_decode_init(AVCodecContext *avctx, QSVContext *q)
Definition: qsvdec.c:88
int iopattern
Definition: qsvdec.h:64
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:106
const AVPixFmtDescriptor * av_pix_fmt_desc_get(enum AVPixelFormat pix_fmt)
Definition: pixdesc.c:1768
This structure describes decoded (raw) audio or video data.
Definition: frame.h:140
int coded_width
Bitstream width / height, may be different from width/height e.g.
Definition: avcodec.h:1595
#define AV_LOG_WARNING
Something somehow does not look correct.
Definition: log.h:130
memory handling functions
int64_t pos
byte position in stream, -1 if unknown
Definition: avcodec.h:1366
This struct is allocated as AVHWFramesContext.hwctx.
Definition: hwcontext_qsv.h:42
const char * desc
Definition: nvenc.c:101
int width
Dimensions of the decoded video intended for presentation.
Definition: avcodec.h:4508
int repeat_pict
When decoding, this signals how much the picture must be delayed.
Definition: frame.h:258
int size
Definition: avcodec.h:1347
av_log(ac->avr, AV_LOG_TRACE, "%d samples - audio_convert: %s to %s (%s)\, len, av_get_sample_fmt_name(ac->in_fmt), av_get_sample_fmt_name(ac->out_fmt), use_generic ? ac->func_descr_generic :ac->func_descr)
static int sync(AVFormatContext *s, uint8_t *header)
Read input until we find the next ident.
Definition: lxfdec.c:86
int coded_width
Dimensions of the coded video.
Definition: avcodec.h:4514
enum AVPixelFormat pix_fmt
Pixel format, see AV_PIX_FMT_xxx.
Definition: avcodec.h:1621
mfxExtBuffer ** ext_buffers
Definition: qsvdec.h:68
mfxFrameSurface1 * surface
Definition: qsv_internal.h:41
int av_usleep(unsigned usec)
Sleep for a period of time.
Definition: time.c:68
int ff_qsv_init_session_hwcontext(AVCodecContext *avctx, mfxSession *psession, QSVFramesContext *qsv_frames_ctx, const char *load_plugins, int opaque)
Definition: qsv.c:290
static int qsv_decode(AVCodecContext *avctx, QSVContext *q, AVFrame *frame, int *got_frame, AVPacket *avpkt)
Definition: qsvdec.c:260
int profile
profile
Definition: avcodec.h:2880
AVBufferRef * hw_frames_ctx
Definition: qsv_internal.h:51
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:84
int ff_qsv_print_error(void *log_ctx, mfxStatus err, const char *error_string)
Definition: qsv.c:112
void av_freep(void *arg)
Free a memory block which has been allocated with av_malloc(z)() or av_realloc() and set the pointer ...
Definition: mem.c:202
AVComponentDescriptor comp[4]
Parameters that describe how pixels are packed.
Definition: pixdesc.h:119
uint8_t
AVFrame * av_frame_alloc(void)
Allocate an AVFrame and set its fields to default values.
Definition: frame.c:68
void * hwaccel_context
Hardware accelerator context.
Definition: avcodec.h:2708
int ff_qsv_decode_close(QSVContext *q)
Definition: qsvdec.c:373
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:199
int64_t pts
Presentation timestamp in time_base units (time when frame should be shown to user).
Definition: frame.h:211
uint8_t * extradata
some codecs need / can use extradata like Huffman tables.
Definition: avcodec.h:1523
int queued
Definition: qsv_internal.h:45
uint8_t * data
Definition: avcodec.h:1346
void av_fifo_free(AVFifoBuffer *f)
Free an AVFifoBuffer.
Definition: fifo.c:38
int interlaced_frame
The content of the picture is interlaced.
Definition: frame.h:263
static QSVFrame * find_frame(QSVContext *q, mfxFrameSurface1 *surf)
Definition: qsvdec.c:249
AVCodecParserContext * parser
Definition: qsvdec.h:56
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
Definition: log.h:124
#define AVERROR(e)
Definition: error.h:43
void av_frame_free(AVFrame **frame)
Free the frame and any dynamically allocated objects in it, e.g.
Definition: frame.c:80
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:107
int iopattern
The IO pattern to use.
Definition: qsv.h:46
int nb_ext_buffers
Definition: qsv.h:52
void ff_qsv_decode_flush(AVCodecContext *avctx, QSVContext *q)
Definition: qsvdec.c:498
int ff_qsv_map_pixfmt(enum AVPixelFormat format, uint32_t *fourcc)
Definition: qsv.c:132
AVCodecContext * avcodec_alloc_context3(const AVCodec *codec)
Allocate an AVCodecContext and set its fields to default values.
Definition: options.c:136
int av_parser_parse2(AVCodecParserContext *s, AVCodecContext *avctx, uint8_t **poutbuf, int *poutbuf_size, const uint8_t *buf, int buf_size, int64_t pts, int64_t dts, int64_t pos)
Parse a packet.
Definition: parser.c:128
int width
picture width / height.
Definition: avcodec.h:1580
AVBufferRef * hw_frames_ctx
A reference to the AVHWFramesContext describing the input (for encoding) or output (decoding) frames...
Definition: avcodec.h:3102
int ff_qsv_codec_id_to_mfx(enum AVCodecID codec_id)
Definition: qsv.c:36
void av_parser_close(AVCodecParserContext *s)
Definition: parser.c:217
int level
level
Definition: avcodec.h:2970
mfxFrameSurface1 surface_internal
Definition: qsv_internal.h:43
if(ac->has_optimized_func)
int ff_get_format(AVCodecContext *avctx, const enum AVPixelFormat *fmt)
Select the (possibly hardware accelerated) pixel format.
Definition: utils.c:785
int format
format of the frame, -1 if unknown or unset Values correspond to enum AVPixelFormat for video frames...
Definition: frame.h:191
NULL
Definition: eval.c:55
int av_fifo_space(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:57
enum AVPixelFormat orig_pix_fmt
Definition: qsvdec.h:58
AVCodecParserContext * av_parser_init(int codec_id)
Definition: parser.c:48
Libavcodec external API header.
void avcodec_free_context(AVCodecContext **avctx)
Free the codec context and everything associated with it and write NULL to the provided pointer...
Definition: options.c:151
enum AVCodecID codec_id
Definition: avcodec.h:1426
mfxSession internal_session
Definition: qsvdec.h:44
mfxExtBuffer ** ext_buffers
Extra buffers to pass to encoder or decoder initialization.
Definition: qsv.h:51
int linesize[AV_NUM_DATA_POINTERS]
For video, size in bytes of each picture line.
Definition: frame.h:158
Descriptor that unambiguously describes how the bits of a pixel are stored in the up to 4 data planes...
Definition: pixdesc.h:80
static int alloc_frame(AVCodecContext *avctx, QSVContext *q, QSVFrame *frame)
Definition: qsvdec.c:173
main external API structure.
Definition: avcodec.h:1409
uint8_t * data
The data buffer.
Definition: buffer.h:89
struct QSVFrame * next
Definition: qsv_internal.h:47
int ff_get_buffer(AVCodecContext *avctx, AVFrame *frame, int flags)
Get a buffer for a frame.
Definition: utils.c:589
void * hwctx
The format-specific data, allocated and freed automatically along with this context.
Definition: hwcontext.h:155
int extradata_size
Definition: avcodec.h:1524
static int get_surface(AVCodecContext *avctx, QSVContext *q, mfxFrameSurface1 **surf)
Definition: qsvdec.c:208
#define AVERROR_BUG
Bug detected, please report the issue.
Definition: error.h:60
int coded_height
Definition: avcodec.h:1595
This struct describes a set or pool of "hardware" frames (i.e.
Definition: hwcontext.h:117
HW acceleration through QSV, data[3] contains a pointer to the mfxFrameSurface1 structure.
Definition: pixfmt.h:215
char * load_plugins
Definition: qsvdec.h:66
mfxMemId * mids
Definition: qsv_internal.h:53
This struct is used for communicating QSV parameters between libavcodec and the caller.
Definition: qsv.h:36
static void qsv_clear_unused_frames(QSVContext *q)
Definition: qsvdec.c:196
static enum AVPixelFormat pix_fmts[]
Definition: libkvazaar.c:257
void av_frame_unref(AVFrame *frame)
Unreference all the buffers referenced by frame and reset the frame fields.
Definition: frame.c:302
uint8_t * data[AV_NUM_DATA_POINTERS]
pointer to the picture/channel planes.
Definition: frame.h:146
attribute_deprecated int64_t pkt_pts
PTS copied from the AVPacket that was decoded to produce this frame.
Definition: frame.h:219
A reference to a data buffer.
Definition: buffer.h:81
int av_fifo_size(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:52
#define FF_DISABLE_DEPRECATION_WARNINGS
Definition: internal.h:77
common internal api header.
common internal and external API header
AVBufferRef * av_buffer_ref(AVBufferRef *buf)
Create a new reference to an AVBuffer.
Definition: buffer.c:92
int ff_qsv_init_internal_session(AVCodecContext *avctx, mfxSession *session, const char *load_plugins)
Definition: qsv.c:200
#define PARSER_FLAG_COMPLETE_FRAMES
Definition: avcodec.h:4396
mfxFrameInfo frame_info
Definition: qsvdec.h:60
#define AV_INPUT_BUFFER_PADDING_SIZE
Required number of additionally allocated bytes at the end of the input bitstream for decoding...
Definition: avcodec.h:638
pixel format definitions
static int qsv_init_session(AVCodecContext *avctx, QSVContext *q, mfxSession session, AVBufferRef *hw_frames_ref)
Definition: qsvdec.c:44
AVCodecContext * avctx_internal
Definition: qsvdec.h:57
#define FF_ENABLE_DEPRECATION_WARNINGS
Definition: internal.h:78
AVFifoBuffer * av_fifo_alloc(unsigned int size)
Initialize an AVFifoBuffer.
Definition: fifo.c:25
int top_field_first
If the content is interlaced, is top field displayed first.
Definition: frame.h:268
QSVFramesContext frames_ctx
Definition: qsvdec.h:46
int format
The format of the coded data, corresponds to enum AVPixelFormat for video and for enum AVSampleFormat...
Definition: avcodec.h:4525
mfxSession session
Definition: qsvdec.h:40
AVFifoBuffer * async_fifo
Definition: qsvdec.h:53
uint32_t fourcc
Definition: qsvdec.h:59
int64_t dts
Decompression timestamp in AVStream->time_base units; the time at which the packet is decompressed...
Definition: avcodec.h:1345
An API-specific header for AV_HWDEVICE_TYPE_QSV.
AVFrame * frame
Definition: qsv_internal.h:40
const char * av_get_pix_fmt_name(enum AVPixelFormat pix_fmt)
Return the short name for a pixel format, NULL in case pix_fmt is unknown.
Definition: pixdesc.c:1704
int async_depth
Definition: qsvdec.h:63
int depth
Number of bits in the component.
Definition: pixdesc.h:57
int ff_qsv_process_data(AVCodecContext *avctx, QSVContext *q, AVFrame *frame, int *got_frame, AVPacket *pkt)
Definition: qsvdec.c:413
QSVFrame * work_frames
a linked list of frames currently being used by QSV
Definition: qsvdec.h:51
AVPixelFormat
Pixel format.
Definition: pixfmt.h:57
This structure stores compressed data.
Definition: avcodec.h:1323
#define AV_GET_BUFFER_FLAG_REF
The decoder will keep a reference to the frame and may reuse it later.
Definition: avcodec.h:1183
mfxSession session
If non-NULL, the session to use for encoding or decoding.
Definition: qsv.h:41
void * av_mallocz(size_t size)
Allocate a block of size bytes with alignment suitable for all memory accesses (including vectors if ...
Definition: mem.c:211
int64_t pts
Presentation timestamp in AVStream->time_base units; the time at which the decompressed packet will b...
Definition: avcodec.h:1339
enum AVPixelFormat sw_pix_fmt
Nominal unaccelerated pixel format, see AV_PIX_FMT_xxx.
Definition: avcodec.h:3070
int nb_ext_buffers
Definition: qsvdec.h:69