FFmpeg
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
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 <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 = ff_qsv_profile_to_mfx(avctx->codec_id, avctx->profile);
148  param.mfx.CodecLevel = avctx->level == FF_LEVEL_UNKNOWN ? MFX_LEVEL_UNKNOWN : 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  switch (avctx->field_order) {
160  param.mfx.FrameInfo.PicStruct = MFX_PICSTRUCT_PROGRESSIVE;
161  break;
162  case AV_FIELD_TT:
163  param.mfx.FrameInfo.PicStruct = MFX_PICSTRUCT_FIELD_TFF;
164  break;
165  case AV_FIELD_BB:
166  param.mfx.FrameInfo.PicStruct = MFX_PICSTRUCT_FIELD_BFF;
167  break;
168  default:
169  param.mfx.FrameInfo.PicStruct = MFX_PICSTRUCT_UNKNOWN;
170  break;
171  }
172 
173  param.IOPattern = q->iopattern;
174  param.AsyncDepth = q->async_depth;
175  param.ExtParam = q->ext_buffers;
176  param.NumExtParam = q->nb_ext_buffers;
177 
178  ret = MFXVideoDECODE_Init(q->session, &param);
179  if (ret < 0)
180  return ff_qsv_print_error(avctx, ret,
181  "Error initializing the MFX video decoder");
182 
183  q->frame_info = param.mfx.FrameInfo;
184 
185  return 0;
186 }
187 
189 {
190  int ret;
191 
192  ret = ff_get_buffer(avctx, frame->frame, AV_GET_BUFFER_FLAG_REF);
193  if (ret < 0)
194  return ret;
195 
196  if (frame->frame->format == AV_PIX_FMT_QSV) {
197  frame->surface = *(mfxFrameSurface1*)frame->frame->data[3];
198  } else {
199  frame->surface.Info = q->frame_info;
200 
201  frame->surface.Data.PitchLow = frame->frame->linesize[0];
202  frame->surface.Data.Y = frame->frame->data[0];
203  frame->surface.Data.UV = frame->frame->data[1];
204  }
205 
206  if (q->frames_ctx.mids) {
207  ret = ff_qsv_find_surface_idx(&q->frames_ctx, frame);
208  if (ret < 0)
209  return ret;
210 
211  frame->surface.Data.MemId = &q->frames_ctx.mids[ret];
212  }
213 
214  frame->used = 1;
215 
216  return 0;
217 }
218 
220 {
221  QSVFrame *cur = q->work_frames;
222  while (cur) {
223  if (cur->used && !cur->surface.Data.Locked && !cur->queued) {
224  cur->used = 0;
225  av_frame_unref(cur->frame);
226  }
227  cur = cur->next;
228  }
229 }
230 
231 static int get_surface(AVCodecContext *avctx, QSVContext *q, mfxFrameSurface1 **surf)
232 {
233  QSVFrame *frame, **last;
234  int ret;
235 
237 
238  frame = q->work_frames;
239  last = &q->work_frames;
240  while (frame) {
241  if (!frame->used) {
242  ret = alloc_frame(avctx, q, frame);
243  if (ret < 0)
244  return ret;
245  *surf = &frame->surface;
246  return 0;
247  }
248 
249  last = &frame->next;
250  frame = frame->next;
251  }
252 
253  frame = av_mallocz(sizeof(*frame));
254  if (!frame)
255  return AVERROR(ENOMEM);
256  frame->frame = av_frame_alloc();
257  if (!frame->frame) {
258  av_freep(&frame);
259  return AVERROR(ENOMEM);
260  }
261  *last = frame;
262 
263  ret = alloc_frame(avctx, q, frame);
264  if (ret < 0)
265  return ret;
266 
267  *surf = &frame->surface;
268 
269  return 0;
270 }
271 
272 static QSVFrame *find_frame(QSVContext *q, mfxFrameSurface1 *surf)
273 {
274  QSVFrame *cur = q->work_frames;
275  while (cur) {
276  if (surf == &cur->surface)
277  return cur;
278  cur = cur->next;
279  }
280  return NULL;
281 }
282 
283 static int qsv_decode(AVCodecContext *avctx, QSVContext *q,
284  AVFrame *frame, int *got_frame,
285  AVPacket *avpkt)
286 {
287  QSVFrame *out_frame;
288  mfxFrameSurface1 *insurf;
289  mfxFrameSurface1 *outsurf;
290  mfxSyncPoint *sync;
291  mfxBitstream bs = { { { 0 } } };
292  int ret;
293 
294  if (avpkt->size) {
295  bs.Data = avpkt->data;
296  bs.DataLength = avpkt->size;
297  bs.MaxLength = bs.DataLength;
298  bs.TimeStamp = avpkt->pts;
299  }
300 
301  sync = av_mallocz(sizeof(*sync));
302  if (!sync) {
303  av_freep(&sync);
304  return AVERROR(ENOMEM);
305  }
306 
307  do {
308  ret = get_surface(avctx, q, &insurf);
309  if (ret < 0) {
310  av_freep(&sync);
311  return ret;
312  }
313 
314  ret = MFXVideoDECODE_DecodeFrameAsync(q->session, avpkt->size ? &bs : NULL,
315  insurf, &outsurf, sync);
316  if (ret == MFX_WRN_DEVICE_BUSY)
317  av_usleep(500);
318 
319  } while (ret == MFX_WRN_DEVICE_BUSY || ret == MFX_ERR_MORE_SURFACE);
320 
321  if (ret != MFX_ERR_NONE &&
322  ret != MFX_ERR_MORE_DATA &&
323  ret != MFX_WRN_VIDEO_PARAM_CHANGED &&
324  ret != MFX_ERR_MORE_SURFACE) {
325  av_freep(&sync);
326  return ff_qsv_print_error(avctx, ret,
327  "Error during QSV decoding.");
328  }
329 
330  /* make sure we do not enter an infinite loop if the SDK
331  * did not consume any data and did not return anything */
332  if (!*sync && !bs.DataOffset) {
333  bs.DataOffset = avpkt->size;
334  ++q->zero_consume_run;
335  if (q->zero_consume_run > 1)
336  ff_qsv_print_warning(avctx, ret, "A decode call did not consume any data");
337  } else {
338  q->zero_consume_run = 0;
339  }
340 
341  if (*sync) {
342  QSVFrame *out_frame = find_frame(q, outsurf);
343 
344  if (!out_frame) {
345  av_log(avctx, AV_LOG_ERROR,
346  "The returned surface does not correspond to any frame\n");
347  av_freep(&sync);
348  return AVERROR_BUG;
349  }
350 
351  out_frame->queued = 1;
352  av_fifo_generic_write(q->async_fifo, &out_frame, sizeof(out_frame), NULL);
353  av_fifo_generic_write(q->async_fifo, &sync, sizeof(sync), NULL);
354  } else {
355  av_freep(&sync);
356  }
357 
358  if (!av_fifo_space(q->async_fifo) ||
359  (!avpkt->size && av_fifo_size(q->async_fifo))) {
360  AVFrame *src_frame;
361 
362  av_fifo_generic_read(q->async_fifo, &out_frame, sizeof(out_frame), NULL);
363  av_fifo_generic_read(q->async_fifo, &sync, sizeof(sync), NULL);
364  out_frame->queued = 0;
365 
366  do {
367  ret = MFXVideoCORE_SyncOperation(q->session, *sync, 1000);
368  } while (ret == MFX_WRN_IN_EXECUTION);
369 
370  av_freep(&sync);
371 
372  src_frame = out_frame->frame;
373 
374  ret = av_frame_ref(frame, src_frame);
375  if (ret < 0)
376  return ret;
377 
378  outsurf = &out_frame->surface;
379 
380 #if FF_API_PKT_PTS
382  frame->pkt_pts = outsurf->Data.TimeStamp;
384 #endif
385  frame->pts = outsurf->Data.TimeStamp;
386 
387  frame->repeat_pict =
388  outsurf->Info.PicStruct & MFX_PICSTRUCT_FRAME_TRIPLING ? 4 :
389  outsurf->Info.PicStruct & MFX_PICSTRUCT_FRAME_DOUBLING ? 2 :
390  outsurf->Info.PicStruct & MFX_PICSTRUCT_FIELD_REPEATED ? 1 : 0;
391  frame->top_field_first =
392  outsurf->Info.PicStruct & MFX_PICSTRUCT_FIELD_TFF;
393  frame->interlaced_frame =
394  !(outsurf->Info.PicStruct & MFX_PICSTRUCT_PROGRESSIVE);
395 
396  /* update the surface properties */
397  if (avctx->pix_fmt == AV_PIX_FMT_QSV)
398  ((mfxFrameSurface1*)frame->data[3])->Info = outsurf->Info;
399 
400  *got_frame = 1;
401  }
402 
403  return bs.DataOffset;
404 }
405 
407 {
408  QSVFrame *cur = q->work_frames;
409 
410  if (q->session)
411  MFXVideoDECODE_Close(q->session);
412 
413  while (q->async_fifo && av_fifo_size(q->async_fifo)) {
414  QSVFrame *out_frame;
415  mfxSyncPoint *sync;
416 
417  av_fifo_generic_read(q->async_fifo, &out_frame, sizeof(out_frame), NULL);
418  av_fifo_generic_read(q->async_fifo, &sync, sizeof(sync), NULL);
419 
420  av_freep(&sync);
421  }
422 
423  while (cur) {
424  q->work_frames = cur->next;
425  av_frame_free(&cur->frame);
426  av_freep(&cur);
427  cur = q->work_frames;
428  }
429 
431  q->async_fifo = NULL;
432 
435 
436  if (q->internal_session)
437  MFXClose(q->internal_session);
438 
441 
442  return 0;
443 }
444 
446  AVFrame *frame, int *got_frame, AVPacket *pkt)
447 {
448  uint8_t *dummy_data;
449  int dummy_size;
450  int ret;
451 
452  if (!q->avctx_internal) {
454  if (!q->avctx_internal)
455  return AVERROR(ENOMEM);
456 
457  q->parser = av_parser_init(avctx->codec_id);
458  if (!q->parser)
459  return AVERROR(ENOMEM);
460 
463  }
464 
465  if (!pkt->size)
466  return qsv_decode(avctx, q, frame, got_frame, pkt);
467 
468  /* we assume the packets are already split properly and want
469  * just the codec parameters here */
471  &dummy_data, &dummy_size,
472  pkt->data, pkt->size, pkt->pts, pkt->dts,
473  pkt->pos);
474 
475  /* TODO: flush delayed frames on reinit */
476  if (q->parser->format != q->orig_pix_fmt ||
477  q->parser->coded_width != avctx->coded_width ||
478  q->parser->coded_height != avctx->coded_height) {
481  AV_PIX_FMT_NONE };
482  enum AVPixelFormat qsv_format;
483 
484  qsv_format = ff_qsv_map_pixfmt(q->parser->format, &q->fourcc);
485  if (qsv_format < 0) {
486  av_log(avctx, AV_LOG_ERROR,
487  "Decoding pixel format '%s' is not supported\n",
489  ret = AVERROR(ENOSYS);
490  goto reinit_fail;
491  }
492 
493  q->orig_pix_fmt = q->parser->format;
494  avctx->pix_fmt = pix_fmts[1] = qsv_format;
495  avctx->width = q->parser->width;
496  avctx->height = q->parser->height;
497  avctx->coded_width = q->parser->coded_width;
498  avctx->coded_height = q->parser->coded_height;
499  avctx->field_order = q->parser->field_order;
500  avctx->level = q->avctx_internal->level;
501  avctx->profile = q->avctx_internal->profile;
502 
503  ret = ff_get_format(avctx, pix_fmts);
504  if (ret < 0)
505  goto reinit_fail;
506 
507  avctx->pix_fmt = ret;
508 
509  ret = qsv_decode_init(avctx, q);
510  if (ret < 0)
511  goto reinit_fail;
512  }
513 
514  return qsv_decode(avctx, q, frame, got_frame, pkt);
515 
516 reinit_fail:
517  q->orig_pix_fmt = q->parser->format = avctx->pix_fmt = AV_PIX_FMT_NONE;
518  return ret;
519 }
520 
522 {
524 }
#define NULL
Definition: coverity.c:32
static int qsv_decode_init(AVCodecContext *avctx, QSVContext *q)
Definition: qsvdec.c:88
int iopattern
Definition: qsvdec.h:65
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
const AVPixFmtDescriptor * av_pix_fmt_desc_get(enum AVPixelFormat pix_fmt)
Definition: pixdesc.c:2333
This structure describes decoded (raw) audio or video data.
Definition: frame.h:187
int coded_width
Bitstream width / height, may be different from width/height e.g.
Definition: avcodec.h:1934
Memory handling functions.
int64_t pos
byte position in stream, -1 if unknown
Definition: avcodec.h:1677
This struct is allocated as AVHWFramesContext.hwctx.
Definition: hwcontext_qsv.h:42
const char * desc
Definition: nvenc.c:60
int width
Dimensions of the decoded video intended for presentation.
Definition: avcodec.h:5222
enum AVFieldOrder field_order
Definition: avcodec.h:5199
int repeat_pict
When decoding, this signals how much the picture must be delayed.
Definition: frame.h:320
int size
Definition: avcodec.h:1658
int coded_width
Dimensions of the coded video.
Definition: avcodec.h:5228
enum AVPixelFormat pix_fmt
Pixel format, see AV_PIX_FMT_xxx.
Definition: avcodec.h:1960
mfxExtBuffer ** ext_buffers
Definition: qsvdec.h:69
void * av_mallocz(size_t size)
Allocate a memory block with alignment suitable for all memory accesses (including vectors if availab...
Definition: mem.c:222
int av_usleep(unsigned usec)
Sleep for a period of time.
Definition: time.c:84
static AVPacket pkt
int ff_qsv_init_session_hwcontext(AVCodecContext *avctx, mfxSession *psession, QSVFramesContext *qsv_frames_ctx, const char *load_plugins, int opaque)
Definition: qsv.c:538
static int qsv_decode(AVCodecContext *avctx, QSVContext *q, AVFrame *frame, int *got_frame, AVPacket *avpkt)
Definition: qsvdec.c:283
int profile
profile
Definition: avcodec.h:3235
AVBufferRef * hw_frames_ctx
Definition: qsv_internal.h:62
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 ff_qsv_print_error(void *log_ctx, mfxStatus err, const char *error_string)
Definition: qsv.c:135
#define FF_LEVEL_UNKNOWN
Definition: avcodec.h:3334
AVComponentDescriptor comp[4]
Parameters that describe how pixels are packed.
Definition: pixdesc.h:117
uint8_t
AVFrame * av_frame_alloc(void)
Allocate an AVFrame and set its fields to default values.
Definition: frame.c:150
void * hwaccel_context
Hardware accelerator context.
Definition: avcodec.h:3064
AVBufferRef * mids_buf
Definition: qsv_internal.h:69
int ff_qsv_decode_close(QSVContext *q)
Definition: qsvdec.c:406
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:388
int64_t pts
Presentation timestamp in time_base units (time when frame should be shown to user).
Definition: frame.h:271
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
static AVFrame * frame
int queued
Definition: qsv_internal.h:55
uint8_t * data
Definition: avcodec.h:1657
void av_fifo_free(AVFifoBuffer *f)
Free an AVFifoBuffer.
Definition: fifo.c:55
int interlaced_frame
The content of the picture is interlaced.
Definition: frame.h:325
#define av_log(a,...)
static QSVFrame * find_frame(QSVContext *q, mfxFrameSurface1 *surf)
Definition: qsvdec.c:272
AVCodecParserContext * parser
Definition: qsvdec.h:57
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
Definition: log.h:176
int ff_qsv_find_surface_idx(QSVFramesContext *ctx, QSVFrame *frame)
Definition: qsv.c:182
#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:163
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 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:521
int ff_qsv_print_warning(void *log_ctx, mfxStatus err, const char *warning_string)
Definition: qsv.c:145
int ff_qsv_map_pixfmt(enum AVPixelFormat format, uint32_t *fourcc)
Definition: qsv.c:165
int ff_qsv_profile_to_mfx(enum AVCodecID codec_id, int profile)
Definition: qsv.c:66
int zero_consume_run
Definition: qsvdec.h:54
AVCodecContext * avcodec_alloc_context3(const AVCodec *codec)
Allocate an AVCodecContext and set its fields to default values.
Definition: options.c:157
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:136
int width
picture width / height.
Definition: avcodec.h:1919
AVBufferRef * hw_frames_ctx
A reference to the AVHWFramesContext describing the input (for encoding) or output (decoding) frames...
Definition: avcodec.h:3585
int ff_qsv_codec_id_to_mfx(enum AVCodecID codec_id)
Definition: qsv.c:41
void av_parser_close(AVCodecParserContext *s)
Definition: parser.c:240
int level
level
Definition: avcodec.h:3333
mfxFrameSurface1 surface
Definition: qsv_internal.h:52
int ff_get_format(AVCodecContext *avctx, const enum AVPixelFormat *fmt)
Select the (possibly hardware accelerated) pixel format.
Definition: utils.c:1112
int format
format of the frame, -1 if unknown or unset Values correspond to enum AVPixelFormat for video frames...
Definition: frame.h:251
enum AVPixelFormat orig_pix_fmt
Definition: qsvdec.h:59
AVCodecParserContext * av_parser_init(int codec_id)
Definition: parser.c:51
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:172
enum AVCodecID codec_id
Definition: avcodec.h:1749
mfxSession internal_session
Definition: qsvdec.h:44
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
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:218
Descriptor that unambiguously describes how the bits of a pixel are stored in the up to 4 data planes...
Definition: pixdesc.h:81
static int alloc_frame(AVCodecContext *avctx, QSVContext *q, QSVFrame *frame)
Definition: qsvdec.c:188
main external API structure.
Definition: avcodec.h:1732
uint8_t * data
The data buffer.
Definition: buffer.h:89
struct QSVFrame * next
Definition: qsv_internal.h:58
int ff_get_buffer(AVCodecContext *avctx, AVFrame *frame, int flags)
Get a buffer for a frame.
Definition: utils.c:953
void * hwctx
The format-specific data, allocated and freed automatically along with this context.
Definition: hwcontext.h:155
static int get_surface(AVCodecContext *avctx, QSVContext *q, mfxFrameSurface1 **surf)
Definition: qsvdec.c:231
#define AVERROR_BUG
Internal bug, also see AVERROR_BUG2.
Definition: error.h:50
int coded_height
Definition: avcodec.h:1934
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:236
char * load_plugins
Definition: qsvdec.h:67
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:219
static enum AVPixelFormat pix_fmts[]
Definition: libkvazaar.c:262
void av_frame_unref(AVFrame *frame)
Unreference all the buffers referenced by frame and reset the frame fields.
Definition: frame.c:498
uint8_t * data[AV_NUM_DATA_POINTERS]
pointer to the picture/channel planes.
Definition: frame.h:201
attribute_deprecated int64_t pkt_pts
PTS copied from the AVPacket that was decoded to produce this frame.
Definition: frame.h:279
A reference to a data buffer.
Definition: buffer.h:81
#define FF_DISABLE_DEPRECATION_WARNINGS
Definition: internal.h:83
common internal api header.
common internal and external API header
if(ret< 0)
Definition: vf_mcdeint.c:282
AVBufferRef * av_buffer_ref(AVBufferRef *buf)
Create a new reference to an AVBuffer.
Definition: buffer.c:93
int ff_qsv_init_internal_session(AVCodecContext *avctx, mfxSession *session, const char *load_plugins)
Definition: qsv.c:244
#define PARSER_FLAG_COMPLETE_FRAMES
Definition: avcodec.h:5109
mfxFrameInfo frame_info
Definition: qsvdec.h:61
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:58
#define FF_ENABLE_DEPRECATION_WARNINGS
Definition: internal.h:84
AVFifoBuffer * av_fifo_alloc(unsigned int size)
Initialize an AVFifoBuffer.
Definition: fifo.c:43
int top_field_first
If the content is interlaced, is top field displayed first.
Definition: frame.h:330
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:5239
mfxSession session
Definition: qsvdec.h:40
AVFifoBuffer * async_fifo
Definition: qsvdec.h:53
uint32_t fourcc
Definition: qsvdec.h:60
int64_t dts
Decompression timestamp in AVStream->time_base units; the time at which the packet is decompressed...
Definition: avcodec.h:1656
#define av_freep(p)
enum AVFieldOrder field_order
Field order.
Definition: avcodec.h:2491
An API-specific header for AV_HWDEVICE_TYPE_QSV.
AVFrame * frame
Definition: qsv_internal.h:51
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:2249
int async_depth
Definition: qsvdec.h:64
int depth
Number of bits in the component.
Definition: pixdesc.h:58
int ff_qsv_process_data(AVCodecContext *avctx, QSVContext *q, AVFrame *frame, int *got_frame, AVPacket *pkt)
Definition: qsvdec.c:445
QSVFrame * work_frames
a linked list of frames currently being used by QSV
Definition: qsvdec.h:51
AVPixelFormat
Pixel format.
Definition: pixfmt.h:60
This structure stores compressed data.
Definition: avcodec.h:1634
#define AV_GET_BUFFER_FLAG_REF
The decoder will keep a reference to the frame and may reuse it later.
Definition: avcodec.h:1389
mfxSession session
If non-NULL, the session to use for encoding or decoding.
Definition: qsv.h:41
int64_t pts
Presentation timestamp in AVStream->time_base units; the time at which the decompressed packet will b...
Definition: avcodec.h:1650
enum AVPixelFormat sw_pix_fmt
Nominal unaccelerated pixel format, see AV_PIX_FMT_xxx.
Definition: avcodec.h:3436
int nb_ext_buffers
Definition: qsvdec.h:70