FFmpeg
vf_deinterlace_qsv.c
Go to the documentation of this file.
1 /*
2  * This file is part of FFmpeg.
3  *
4  * FFmpeg is free software; you can redistribute it and/or
5  * modify it under the terms of the GNU Lesser General Public
6  * License as published by the Free Software Foundation; either
7  * version 2.1 of the License, or (at your option) any later version.
8  *
9  * FFmpeg is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12  * Lesser General Public License for more details.
13  *
14  * You should have received a copy of the GNU Lesser General Public
15  * License along with FFmpeg; if not, write to the Free Software
16  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
17  */
18 
19 /**
20  * @file
21  * deinterlace video filter - QSV
22  */
23 
24 #include <mfx/mfxvideo.h>
25 
26 #include <stdio.h>
27 #include <string.h>
28 
29 #include "libavutil/avstring.h"
30 #include "libavutil/common.h"
31 #include "libavutil/hwcontext.h"
33 #include "libavutil/internal.h"
34 #include "libavutil/mathematics.h"
35 #include "libavutil/opt.h"
36 #include "libavutil/pixdesc.h"
37 #include "libavutil/time.h"
38 #include "libavfilter/qsvvpp.h"
39 
40 #include "avfilter.h"
41 #include "formats.h"
42 #include "internal.h"
43 #include "video.h"
44 
45 enum {
48 };
49 
50 typedef struct QSVDeintContext {
51  const AVClass *class;
52 
54  /* a clone of the main session, used internally for deinterlacing */
55  mfxSession session;
56 
57  mfxMemId *mem_ids;
59 
60  mfxFrameSurface1 **surface_ptrs;
62 
63  mfxExtOpaqueSurfaceAlloc opaque_alloc;
64  mfxExtVPPDeinterlacing deint_conf;
65  mfxExtBuffer *ext_buffers[2];
67 
69 
70  int64_t last_pts;
71 
72  int eof;
73 
74  /* option for Deinterlacing algorithm to be used */
75  int mode;
77 
79 {
80  QSVDeintContext *s = ctx->priv;
81  QSVFrame *cur;
82 
83  if (s->session) {
84  MFXClose(s->session);
85  s->session = NULL;
86  }
87  av_buffer_unref(&s->hw_frames_ctx);
88 
89  cur = s->work_frames;
90  while (cur) {
91  s->work_frames = cur->next;
92  av_frame_free(&cur->frame);
93  av_freep(&cur);
94  cur = s->work_frames;
95  }
96 
97  av_freep(&s->mem_ids);
98  s->nb_mem_ids = 0;
99 
100  av_freep(&s->surface_ptrs);
101  s->nb_surface_ptrs = 0;
102 }
103 
105 {
106  static const enum AVPixelFormat pixel_formats[] = {
108  };
109  AVFilterFormats *pix_fmts = ff_make_format_list(pixel_formats);
110  int ret;
111 
112  if ((ret = ff_set_common_formats(ctx, pix_fmts)) < 0)
113  return ret;
114 
115  return 0;
116 }
117 
118 static mfxStatus frame_alloc(mfxHDL pthis, mfxFrameAllocRequest *req,
119  mfxFrameAllocResponse *resp)
120 {
121  AVFilterContext *ctx = pthis;
122  QSVDeintContext *s = ctx->priv;
123 
124  if (!(req->Type & MFX_MEMTYPE_VIDEO_MEMORY_PROCESSOR_TARGET) ||
125  !(req->Type & (MFX_MEMTYPE_FROM_VPPIN | MFX_MEMTYPE_FROM_VPPOUT)) ||
126  !(req->Type & MFX_MEMTYPE_EXTERNAL_FRAME))
127  return MFX_ERR_UNSUPPORTED;
128 
129  resp->mids = s->mem_ids;
130  resp->NumFrameActual = s->nb_mem_ids;
131 
132  return MFX_ERR_NONE;
133 }
134 
135 static mfxStatus frame_free(mfxHDL pthis, mfxFrameAllocResponse *resp)
136 {
137  return MFX_ERR_NONE;
138 }
139 
140 static mfxStatus frame_lock(mfxHDL pthis, mfxMemId mid, mfxFrameData *ptr)
141 {
142  return MFX_ERR_UNSUPPORTED;
143 }
144 
145 static mfxStatus frame_unlock(mfxHDL pthis, mfxMemId mid, mfxFrameData *ptr)
146 {
147  return MFX_ERR_UNSUPPORTED;
148 }
149 
150 static mfxStatus frame_get_hdl(mfxHDL pthis, mfxMemId mid, mfxHDL *hdl)
151 {
152  *hdl = mid;
153  return MFX_ERR_NONE;
154 }
155 
156 static const mfxHandleType handle_types[] = {
157  MFX_HANDLE_VA_DISPLAY,
158  MFX_HANDLE_D3D9_DEVICE_MANAGER,
159  MFX_HANDLE_D3D11_DEVICE,
160 };
161 
163 {
164 
165  QSVDeintContext *s = ctx->priv;
166  AVHWFramesContext *hw_frames_ctx = (AVHWFramesContext*)s->hw_frames_ctx->data;
167  AVQSVFramesContext *hw_frames_hwctx = hw_frames_ctx->hwctx;
168  AVQSVDeviceContext *device_hwctx = hw_frames_ctx->device_ctx->hwctx;
169 
170  int opaque = !!(hw_frames_hwctx->frame_type & MFX_MEMTYPE_OPAQUE_FRAME);
171 
172  mfxHDL handle = NULL;
173  mfxHandleType handle_type;
174  mfxVersion ver;
175  mfxIMPL impl;
176  mfxVideoParam par;
177  mfxStatus err;
178  int i;
179 
180  /* extract the properties of the "master" session given to us */
181  err = MFXQueryIMPL(device_hwctx->session, &impl);
182  if (err == MFX_ERR_NONE)
183  err = MFXQueryVersion(device_hwctx->session, &ver);
184  if (err != MFX_ERR_NONE) {
185  av_log(ctx, AV_LOG_ERROR, "Error querying the session attributes\n");
186  return AVERROR_UNKNOWN;
187  }
188 
189  for (i = 0; i < FF_ARRAY_ELEMS(handle_types); i++) {
190  err = MFXVideoCORE_GetHandle(device_hwctx->session, handle_types[i], &handle);
191  if (err == MFX_ERR_NONE) {
193  break;
194  }
195  }
196 
197  if (err < 0)
198  return ff_qsvvpp_print_error(ctx, err, "Error getting the session handle");
199  else if (err > 0) {
200  ff_qsvvpp_print_warning(ctx, err, "Warning in getting the session handle");
201  return AVERROR_UNKNOWN;
202  }
203 
204  /* create a "slave" session with those same properties, to be used for
205  * actual deinterlacing */
206  err = MFXInit(impl, &ver, &s->session);
207  if (err < 0)
208  return ff_qsvvpp_print_error(ctx, err, "Error initializing a session for deinterlacing");
209  else if (err > 0) {
210  ff_qsvvpp_print_warning(ctx, err, "Warning in session initialization");
211  return AVERROR_UNKNOWN;
212  }
213 
214  if (handle) {
215  err = MFXVideoCORE_SetHandle(s->session, handle_type, handle);
216  if (err != MFX_ERR_NONE)
217  return AVERROR_UNKNOWN;
218  }
219 
220  if (QSV_RUNTIME_VERSION_ATLEAST(ver, 1, 25)) {
221  err = MFXJoinSession(device_hwctx->session, s->session);
222  if (err != MFX_ERR_NONE)
223  return AVERROR_UNKNOWN;
224  }
225 
226  memset(&par, 0, sizeof(par));
227 
228  s->deint_conf.Header.BufferId = MFX_EXTBUFF_VPP_DEINTERLACING;
229  s->deint_conf.Header.BufferSz = sizeof(s->deint_conf);
230  s->deint_conf.Mode = s->mode;
231 
232  s->ext_buffers[s->num_ext_buffers++] = (mfxExtBuffer *)&s->deint_conf;
233 
234  if (opaque) {
235  s->surface_ptrs = av_mallocz_array(hw_frames_hwctx->nb_surfaces,
236  sizeof(*s->surface_ptrs));
237  if (!s->surface_ptrs)
238  return AVERROR(ENOMEM);
239  for (i = 0; i < hw_frames_hwctx->nb_surfaces; i++)
240  s->surface_ptrs[i] = hw_frames_hwctx->surfaces + i;
241  s->nb_surface_ptrs = hw_frames_hwctx->nb_surfaces;
242 
243  s->opaque_alloc.In.Surfaces = s->surface_ptrs;
244  s->opaque_alloc.In.NumSurface = s->nb_surface_ptrs;
245  s->opaque_alloc.In.Type = hw_frames_hwctx->frame_type;
246 
247  s->opaque_alloc.Out = s->opaque_alloc.In;
248 
249  s->opaque_alloc.Header.BufferId = MFX_EXTBUFF_OPAQUE_SURFACE_ALLOCATION;
250  s->opaque_alloc.Header.BufferSz = sizeof(s->opaque_alloc);
251 
252  s->ext_buffers[s->num_ext_buffers++] = (mfxExtBuffer *)&s->opaque_alloc;
253 
254  par.IOPattern = MFX_IOPATTERN_IN_OPAQUE_MEMORY | MFX_IOPATTERN_OUT_OPAQUE_MEMORY;
255  } else {
256  mfxFrameAllocator frame_allocator = {
257  .pthis = ctx,
258  .Alloc = frame_alloc,
259  .Lock = frame_lock,
260  .Unlock = frame_unlock,
261  .GetHDL = frame_get_hdl,
262  .Free = frame_free,
263  };
264 
265  s->mem_ids = av_mallocz_array(hw_frames_hwctx->nb_surfaces,
266  sizeof(*s->mem_ids));
267  if (!s->mem_ids)
268  return AVERROR(ENOMEM);
269  for (i = 0; i < hw_frames_hwctx->nb_surfaces; i++)
270  s->mem_ids[i] = hw_frames_hwctx->surfaces[i].Data.MemId;
271  s->nb_mem_ids = hw_frames_hwctx->nb_surfaces;
272 
273  err = MFXVideoCORE_SetFrameAllocator(s->session, &frame_allocator);
274  if (err != MFX_ERR_NONE)
275  return AVERROR_UNKNOWN;
276 
277  par.IOPattern = MFX_IOPATTERN_IN_VIDEO_MEMORY | MFX_IOPATTERN_OUT_VIDEO_MEMORY;
278  }
279 
280  par.ExtParam = s->ext_buffers;
281  par.NumExtParam = s->num_ext_buffers;
282 
283  par.AsyncDepth = 1; // TODO async
284 
285  par.vpp.In = hw_frames_hwctx->surfaces[0].Info;
286 
287  par.vpp.In.CropW = ctx->inputs[0]->w;
288  par.vpp.In.CropH = ctx->inputs[0]->h;
289 
290  if (ctx->inputs[0]->frame_rate.num) {
291  par.vpp.In.FrameRateExtN = ctx->inputs[0]->frame_rate.num;
292  par.vpp.In.FrameRateExtD = ctx->inputs[0]->frame_rate.den;
293  } else {
294  par.vpp.In.FrameRateExtN = ctx->inputs[0]->time_base.num;
295  par.vpp.In.FrameRateExtD = ctx->inputs[0]->time_base.den;
296  }
297 
298  par.vpp.Out = par.vpp.In;
299 
300  if (ctx->outputs[0]->frame_rate.num) {
301  par.vpp.Out.FrameRateExtN = ctx->outputs[0]->frame_rate.num;
302  par.vpp.Out.FrameRateExtD = ctx->outputs[0]->frame_rate.den;
303  } else {
304  par.vpp.Out.FrameRateExtN = ctx->outputs[0]->time_base.num;
305  par.vpp.Out.FrameRateExtD = ctx->outputs[0]->time_base.den;
306  }
307 
308  /* Print input memory mode */
309  ff_qsvvpp_print_iopattern(ctx, par.IOPattern & 0x0F, "VPP");
310  /* Print output memory mode */
311  ff_qsvvpp_print_iopattern(ctx, par.IOPattern & 0xF0, "VPP");
312  err = MFXVideoVPP_Init(s->session, &par);
313  if (err < 0)
314  return ff_qsvvpp_print_error(ctx, err,
315  "Error opening the VPP for deinterlacing");
316  else if (err > 0) {
318  "Warning in VPP initialization");
319  return AVERROR_UNKNOWN;
320  }
321 
322  return 0;
323 }
324 
326 {
327  AVFilterContext *ctx = outlink->src;
328  AVFilterLink *inlink = ctx->inputs[0];
329  QSVDeintContext *s = ctx->priv;
330  int ret;
331 
333 
334  s->last_pts = AV_NOPTS_VALUE;
335  outlink->frame_rate = av_mul_q(inlink->frame_rate,
336  (AVRational){ 2, 1 });
337  outlink->time_base = av_mul_q(inlink->time_base,
338  (AVRational){ 1, 2 });
339 
340  /* check that we have a hw context */
341  if (!inlink->hw_frames_ctx) {
342  av_log(ctx, AV_LOG_ERROR, "No hw context provided on input\n");
343  return AVERROR(EINVAL);
344  }
345 
346  s->hw_frames_ctx = av_buffer_ref(inlink->hw_frames_ctx);
347  if (!s->hw_frames_ctx)
348  return AVERROR(ENOMEM);
349 
350  av_buffer_unref(&outlink->hw_frames_ctx);
351  outlink->hw_frames_ctx = av_buffer_ref(inlink->hw_frames_ctx);
352  if (!outlink->hw_frames_ctx) {
354  return AVERROR(ENOMEM);
355  }
356 
358  if (ret < 0)
359  return ret;
360 
361 
362  return 0;
363 }
364 
366 {
367  QSVFrame *cur = s->work_frames;
368  while (cur) {
369  if (!cur->surface.Data.Locked) {
370  av_frame_free(&cur->frame);
371  cur->queued = 0;
372  }
373  cur = cur->next;
374  }
375 }
376 
378 {
379  QSVFrame *frame, **last;
380 
382 
383  frame = s->work_frames;
384  last = &s->work_frames;
385  while (frame) {
386  if (!frame->queued) {
387  *f = frame;
388  return 0;
389  }
390 
391  last = &frame->next;
392  frame = frame->next;
393  }
394 
395  frame = av_mallocz(sizeof(*frame));
396  if (!frame)
397  return AVERROR(ENOMEM);
398  *last = frame;
399  *f = frame;
400 
401  return 0;
402 }
403 
405  mfxFrameSurface1 **surface)
406 {
407  QSVDeintContext *s = ctx->priv;
408  QSVFrame *qf;
409  int ret;
410 
411  ret = get_free_frame(s, &qf);
412  if (ret < 0)
413  return ret;
414 
415  qf->frame = frame;
416 
417  qf->surface = *(mfxFrameSurface1*)qf->frame->data[3];
418 
419  qf->surface.Data.Locked = 0;
420  qf->surface.Info.CropW = qf->frame->width;
421  qf->surface.Info.CropH = qf->frame->height;
422 
423  qf->surface.Info.PicStruct = !qf->frame->interlaced_frame ? MFX_PICSTRUCT_PROGRESSIVE :
424  (qf->frame->top_field_first ? MFX_PICSTRUCT_FIELD_TFF :
425  MFX_PICSTRUCT_FIELD_BFF);
426  if (qf->frame->repeat_pict == 1) {
427  qf->surface.Info.PicStruct |= MFX_PICSTRUCT_FIELD_REPEATED;
428  qf->surface.Info.PicStruct |= qf->frame->top_field_first ? MFX_PICSTRUCT_FIELD_TFF :
429  MFX_PICSTRUCT_FIELD_BFF;
430  } else if (qf->frame->repeat_pict == 2)
431  qf->surface.Info.PicStruct |= MFX_PICSTRUCT_FRAME_DOUBLING;
432  else if (qf->frame->repeat_pict == 4)
433  qf->surface.Info.PicStruct |= MFX_PICSTRUCT_FRAME_TRIPLING;
434 
435  if (ctx->inputs[0]->frame_rate.num) {
436  qf->surface.Info.FrameRateExtN = ctx->inputs[0]->frame_rate.num;
437  qf->surface.Info.FrameRateExtD = ctx->inputs[0]->frame_rate.den;
438  } else {
439  qf->surface.Info.FrameRateExtN = ctx->inputs[0]->time_base.num;
440  qf->surface.Info.FrameRateExtD = ctx->inputs[0]->time_base.den;
441  }
442 
443  qf->surface.Data.TimeStamp = av_rescale_q(qf->frame->pts,
444  ctx->inputs[0]->time_base,
445  (AVRational){1, 90000});
446 
447  *surface = &qf->surface;
448  qf->queued = 1;
449 
450  return 0;
451 }
452 
453 static int process_frame(AVFilterContext *ctx, const AVFrame *in,
454  mfxFrameSurface1 *surf_in)
455 {
456  QSVDeintContext *s = ctx->priv;
457  AVFilterLink *inlink = ctx->inputs[0];
458  AVFilterLink *outlink = ctx->outputs[0];
459 
460  AVFrame *out;
461  mfxFrameSurface1 *surf_out;
462  mfxSyncPoint sync = NULL;
463  mfxStatus err;
464  int ret, again = 0;
465 
466  out = ff_get_video_buffer(outlink, outlink->w, outlink->h);
467  if (!out) {
468  ret = AVERROR(ENOMEM);
469  goto fail;
470  }
471 
472  surf_out = (mfxFrameSurface1*)out->data[3];
473  surf_out->Info.CropW = outlink->w;
474  surf_out->Info.CropH = outlink->h;
475  surf_out->Info.PicStruct = MFX_PICSTRUCT_PROGRESSIVE;
476 
477  do {
478  err = MFXVideoVPP_RunFrameVPPAsync(s->session, surf_in, surf_out,
479  NULL, &sync);
480  if (err == MFX_WRN_DEVICE_BUSY)
481  av_usleep(1);
482  } while (err == MFX_WRN_DEVICE_BUSY);
483 
484  if (err == MFX_ERR_MORE_DATA) {
485  av_frame_free(&out);
486  return QSVDEINT_MORE_INPUT;
487  }
488 
489  if (err < 0 && err != MFX_ERR_MORE_SURFACE) {
490  ret = ff_qsvvpp_print_error(ctx, err, "Error during deinterlacing");
491  goto fail;
492  }
493 
494  if (!sync) {
495  av_log(ctx, AV_LOG_ERROR, "No sync during deinterlacing\n");
497  goto fail;
498  }
499  if (err == MFX_ERR_MORE_SURFACE)
500  again = 1;
501 
502  do {
503  err = MFXVideoCORE_SyncOperation(s->session, sync, 1000);
504  } while (err == MFX_WRN_IN_EXECUTION);
505  if (err < 0) {
506  ret = ff_qsvvpp_print_error(ctx, err, "Error synchronizing the operation");
507  goto fail;
508  }
509 
510  ret = av_frame_copy_props(out, in);
511  if (ret < 0)
512  goto fail;
513 
514  out->width = outlink->w;
515  out->height = outlink->h;
516  out->interlaced_frame = 0;
517 
518  out->pts = av_rescale_q(out->pts, inlink->time_base, outlink->time_base);
519  if (out->pts == s->last_pts)
520  out->pts++;
521  s->last_pts = out->pts;
522 
523  ret = ff_filter_frame(outlink, out);
524  if (ret < 0)
525  return ret;
526 
527  return again ? QSVDEINT_MORE_OUTPUT : 0;
528 fail:
529  av_frame_free(&out);
530  return ret;
531 }
532 
534 {
535  AVFilterContext *ctx = link->dst;
536 
537  mfxFrameSurface1 *surf_in;
538  int ret;
539 
540  ret = submit_frame(ctx, in, &surf_in);
541  if (ret < 0) {
542  av_frame_free(&in);
543  return ret;
544  }
545 
546  do {
547  ret = process_frame(ctx, in, surf_in);
548  if (ret < 0)
549  return ret;
550  } while (ret == QSVDEINT_MORE_OUTPUT);
551 
552  return 0;
553 }
554 
556 {
557  AVFilterContext *ctx = outlink->src;
558 
559  return ff_request_frame(ctx->inputs[0]);
560 }
561 
562 #define OFFSET(x) offsetof(QSVDeintContext, x)
563 #define FLAGS AV_OPT_FLAG_VIDEO_PARAM|AV_OPT_FLAG_FILTERING_PARAM
564 static const AVOption options[] = {
565  { "mode", "set deinterlace mode", OFFSET(mode), AV_OPT_TYPE_INT, {.i64 = MFX_DEINTERLACING_ADVANCED}, MFX_DEINTERLACING_BOB, MFX_DEINTERLACING_ADVANCED, FLAGS, "mode"},
566  { "bob", "bob algorithm", 0, AV_OPT_TYPE_CONST, {.i64 = MFX_DEINTERLACING_BOB}, MFX_DEINTERLACING_BOB, MFX_DEINTERLACING_ADVANCED, FLAGS, "mode"},
567  { "advanced", "Motion adaptive algorithm", 0, AV_OPT_TYPE_CONST, {.i64 = MFX_DEINTERLACING_ADVANCED}, MFX_DEINTERLACING_BOB, MFX_DEINTERLACING_ADVANCED, FLAGS, "mode"},
568  { NULL },
569 };
570 
571 static const AVClass qsvdeint_class = {
572  .class_name = "deinterlace_qsv",
573  .item_name = av_default_item_name,
574  .option = options,
575  .version = LIBAVUTIL_VERSION_INT,
576 };
577 
578 static const AVFilterPad qsvdeint_inputs[] = {
579  {
580  .name = "default",
581  .type = AVMEDIA_TYPE_VIDEO,
582  .filter_frame = qsvdeint_filter_frame,
583  },
584  { NULL }
585 };
586 
587 static const AVFilterPad qsvdeint_outputs[] = {
588  {
589  .name = "default",
590  .type = AVMEDIA_TYPE_VIDEO,
591  .config_props = qsvdeint_config_props,
592  .request_frame = qsvdeint_request_frame,
593  },
594  { NULL }
595 };
596 
598  .name = "deinterlace_qsv",
599  .description = NULL_IF_CONFIG_SMALL("QuickSync video deinterlacing"),
600 
601  .uninit = qsvdeint_uninit,
602  .query_formats = qsvdeint_query_formats,
603 
604  .priv_size = sizeof(QSVDeintContext),
605  .priv_class = &qsvdeint_class,
606 
609 
610  .flags_internal = FF_FILTER_FLAG_HWFRAME_AWARE,
611 };
qsvdeint_request_frame
static int qsvdeint_request_frame(AVFilterLink *outlink)
Definition: vf_deinterlace_qsv.c:555
ff_get_video_buffer
AVFrame * ff_get_video_buffer(AVFilterLink *link, int w, int h)
Request a picture buffer with a specific set of permissions.
Definition: video.c:97
AVHWDeviceContext::hwctx
void * hwctx
The format-specific data, allocated and freed by libavutil along with this context.
Definition: hwcontext.h:92
AVPixelFormat
AVPixelFormat
Pixel format.
Definition: pixfmt.h:64
AVERROR
Filter the word “frame” indicates either a video frame or a group of audio as stored in an AVFrame structure Format for each input and each output the list of supported formats For video that means pixel format For audio that means channel sample they are references to shared objects When the negotiation mechanism computes the intersection of the formats supported at each end of a all references to both lists are replaced with a reference to the intersection And when a single format is eventually chosen for a link amongst the remaining all references to the list are updated That means that if a filter requires that its input and output have the same format amongst a supported all it has to do is use a reference to the same list of formats query_formats can leave some formats unset and return AVERROR(EAGAIN) to cause the negotiation mechanism toagain later. That can be used by filters with complex requirements to use the format negotiated on one link to set the formats supported on another. Frame references ownership and permissions
opt.h
ff_make_format_list
AVFilterFormats * ff_make_format_list(const int *fmts)
Create a list of supported formats.
Definition: formats.c:286
out
FILE * out
Definition: movenc.c:54
FF_FILTER_FLAG_HWFRAME_AWARE
#define FF_FILTER_FLAG_HWFRAME_AWARE
The filter is aware of hardware frames, and any hardware frame context should not be automatically pr...
Definition: internal.h:339
ff_filter_frame
int ff_filter_frame(AVFilterLink *link, AVFrame *frame)
Send a frame of data to the next filter.
Definition: avfilter.c:978
inlink
The exact code depends on how similar the blocks are and how related they are to the and needs to apply these operations to the correct inlink or outlink if there are several Macros are available to factor that when no extra processing is inlink
Definition: filter_design.txt:212
av_frame_free
void av_frame_free(AVFrame **frame)
Free the frame and any dynamically allocated objects in it, e.g.
Definition: frame.c:112
QSVDeintContext::mode
int mode
Definition: vf_deinterlace_qsv.c:75
AVFrame
This structure describes decoded (raw) audio or video data.
Definition: frame.h:303
pixdesc.h
AVFrame::pts
int64_t pts
Presentation timestamp in time_base units (time when frame should be shown to user).
Definition: frame.h:396
AVFrame::width
int width
Definition: frame.h:361
AVQSVDeviceContext
This struct is allocated as AVHWDeviceContext.hwctx.
Definition: hwcontext_qsv.h:35
ff_vf_deinterlace_qsv
const AVFilter ff_vf_deinterlace_qsv
Definition: vf_deinterlace_qsv.c:597
AVFrame::top_field_first
int top_field_first
If the content is interlaced, is top field displayed first.
Definition: frame.h:438
AVOption
AVOption.
Definition: opt.h:247
ff_request_frame
int ff_request_frame(AVFilterLink *link)
Request an input frame from the filter at the other end of the link.
Definition: avfilter.c:395
av_mallocz_array
void * av_mallocz_array(size_t nmemb, size_t size)
Definition: mem.c:196
mathematics.h
AVFilter::name
const char * name
Filter name.
Definition: avfilter.h:149
AVERROR_UNKNOWN
#define AVERROR_UNKNOWN
Unknown error, typically from an external library.
Definition: error.h:73
video.h
QSVFrame::frame
AVFrame * frame
Definition: qsv_internal.h:73
AVFrame::data
uint8_t * data[AV_NUM_DATA_POINTERS]
pointer to the picture/channel planes.
Definition: frame.h:317
AVFilterFormats
A list of supported formats for one end of a filter link.
Definition: formats.h:64
formats.h
QSVDeintContext::hw_frames_ctx
AVBufferRef * hw_frames_ctx
Definition: vf_deinterlace_qsv.c:53
QSVDeintContext::last_pts
int64_t last_pts
Definition: vf_deinterlace_qsv.c:70
qsvvpp.h
fail
#define fail()
Definition: checkasm.h:136
QSVDeintContext::ext_buffers
mfxExtBuffer * ext_buffers[2]
Definition: vf_deinterlace_qsv.c:65
qsvdeint_filter_frame
static int qsvdeint_filter_frame(AVFilterLink *link, AVFrame *in)
Definition: vf_deinterlace_qsv.c:533
QSVDeintContext
Definition: vf_deinterlace_qsv.c:50
handle_type
mfxHandleType handle_type
Definition: hwcontext_qsv.c:89
AVFilterPad
A filter pad used for either input or output.
Definition: internal.h:54
ff_qsvvpp_print_iopattern
int ff_qsvvpp_print_iopattern(void *log_ctx, int mfx_iopattern, const char *extra_string)
Definition: qsvvpp.c:60
AV_LOG_ERROR
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
Definition: log.h:180
FF_ARRAY_ELEMS
#define FF_ARRAY_ELEMS(a)
Definition: sinewin_tablegen.c:29
av_cold
#define av_cold
Definition: attributes.h:90
inputs
these buffered frames must be flushed immediately if a new input produces new the filter must not call request_frame to get more It must just process the frame or queue it The task of requesting more frames is left to the filter s request_frame method or the application If a filter has several inputs
Definition: filter_design.txt:243
ff_set_common_formats
int ff_set_common_formats(AVFilterContext *ctx, AVFilterFormats *formats)
A helper for query_formats() which sets all links to the same list of formats.
Definition: formats.c:580
QSVDeintContext::opaque_alloc
mfxExtOpaqueSurfaceAlloc opaque_alloc
Definition: vf_deinterlace_qsv.c:63
qsvdeint_uninit
static av_cold void qsvdeint_uninit(AVFilterContext *ctx)
Definition: vf_deinterlace_qsv.c:78
QSVDeintContext::surface_ptrs
mfxFrameSurface1 ** surface_ptrs
Definition: vf_deinterlace_qsv.c:60
s
#define s(width, name)
Definition: cbs_vp9.c:257
QSV_RUNTIME_VERSION_ATLEAST
#define QSV_RUNTIME_VERSION_ATLEAST(MFX_VERSION, MAJOR, MINOR)
Definition: qsv_internal.h:59
outputs
static const AVFilterPad outputs[]
Definition: af_acontrast.c:203
pix_fmts
static enum AVPixelFormat pix_fmts[]
Definition: libkvazaar.c:290
ctx
AVFormatContext * ctx
Definition: movenc.c:48
av_rescale_q
int64_t av_rescale_q(int64_t a, AVRational bq, AVRational cq)
Rescale a 64-bit integer by 2 rational numbers.
Definition: mathematics.c:141
av_usleep
int av_usleep(unsigned usec)
Sleep for a period of time.
Definition: time.c:84
f
#define f(width, name)
Definition: cbs_vp9.c:255
link
Filter the word “frame” indicates either a video frame or a group of audio as stored in an AVFrame structure Format for each input and each output the list of supported formats For video that means pixel format For audio that means channel sample they are references to shared objects When the negotiation mechanism computes the intersection of the formats supported at each end of a link
Definition: filter_design.txt:23
if
if(ret)
Definition: filter_design.txt:179
QSVDeintContext::work_frames
QSVFrame * work_frames
Definition: vf_deinterlace_qsv.c:68
QSVFrame
Definition: qsv_internal.h:72
LIBAVUTIL_VERSION_INT
#define LIBAVUTIL_VERSION_INT
Definition: version.h:85
AVClass
Describe the class of an AVClass context structure.
Definition: log.h:66
NULL
#define NULL
Definition: coverity.c:32
av_frame_copy_props
int av_frame_copy_props(AVFrame *dst, const AVFrame *src)
Copy only "metadata" fields from src to dst.
Definition: frame.c:537
av_buffer_unref
void av_buffer_unref(AVBufferRef **buf)
Free a given reference and automatically free the buffer if there are no more references to it.
Definition: buffer.c:125
AVRational
Rational number (pair of numerator and denominator).
Definition: rational.h:58
QSVDeintContext::num_ext_buffers
int num_ext_buffers
Definition: vf_deinterlace_qsv.c:66
ff_qsvvpp_print_error
int ff_qsvvpp_print_error(void *log_ctx, mfxStatus err, const char *error_string)
Definition: qsvvpp.c:132
av_default_item_name
const char * av_default_item_name(void *ptr)
Return the context name.
Definition: log.c:235
QSVFrame::surface
mfxFrameSurface1 surface
Definition: qsv_internal.h:74
OFFSET
#define OFFSET(x)
Definition: vf_deinterlace_qsv.c:562
time.h
QSVDeintContext::deint_conf
mfxExtVPPDeinterlacing deint_conf
Definition: vf_deinterlace_qsv.c:64
AV_PIX_FMT_QSV
@ AV_PIX_FMT_QSV
HW acceleration through QSV, data[3] contains a pointer to the mfxFrameSurface1 structure.
Definition: pixfmt.h:212
qsvdeint_class
static const AVClass qsvdeint_class
Definition: vf_deinterlace_qsv.c:571
handle_types
static const mfxHandleType handle_types[]
Definition: vf_deinterlace_qsv.c:156
NULL_IF_CONFIG_SMALL
#define NULL_IF_CONFIG_SMALL(x)
Return NULL if CONFIG_SMALL is true, otherwise the argument without modification.
Definition: internal.h:116
qsvdeint_query_formats
static int qsvdeint_query_formats(AVFilterContext *ctx)
Definition: vf_deinterlace_qsv.c:104
AV_NOPTS_VALUE
#define AV_NOPTS_VALUE
Undefined timestamp value.
Definition: avutil.h:248
frame_free
static mfxStatus frame_free(mfxHDL pthis, mfxFrameAllocResponse *resp)
Definition: vf_deinterlace_qsv.c:135
internal.h
QSVDeintContext::mem_ids
mfxMemId * mem_ids
Definition: vf_deinterlace_qsv.c:57
AVFrame::interlaced_frame
int interlaced_frame
The content of the picture is interlaced.
Definition: frame.h:433
hwcontext_qsv.h
i
int i
Definition: input.c:406
internal.h
common.h
frame_alloc
static mfxStatus frame_alloc(mfxHDL pthis, mfxFrameAllocRequest *req, mfxFrameAllocResponse *resp)
Definition: vf_deinterlace_qsv.c:118
clear_unused_frames
static void clear_unused_frames(QSVDeintContext *s)
Definition: vf_deinterlace_qsv.c:365
av_mallocz
void * av_mallocz(size_t size)
Allocate a memory block with alignment suitable for all memory accesses (including vectors if availab...
Definition: mem.c:243
QSVDeintContext::session
mfxSession session
Definition: vf_deinterlace_qsv.c:55
AVFilterPad::name
const char * name
Pad name.
Definition: internal.h:60
QSVDeintContext::nb_mem_ids
int nb_mem_ids
Definition: vf_deinterlace_qsv.c:58
AVFilter
Filter definition.
Definition: avfilter.h:145
AVHWFramesContext
This struct describes a set or pool of "hardware" frames (i.e.
Definition: hwcontext.h:124
QSVDEINT_MORE_INPUT
@ QSVDEINT_MORE_INPUT
Definition: vf_deinterlace_qsv.c:47
ret
ret
Definition: filter_design.txt:187
AVClass::class_name
const char * class_name
The name of the class; usually it is the same name as the context structure type to which the AVClass...
Definition: log.h:71
frame
these buffered frames must be flushed immediately if a new input produces new the filter must not call request_frame to get more It must just process the frame or queue it The task of requesting more frames is left to the filter s request_frame method or the application If a filter has several the filter must be ready for frames arriving randomly on any input any filter with several inputs will most likely require some kind of queuing mechanism It is perfectly acceptable to have a limited queue and to drop frames when the inputs are too unbalanced request_frame For filters that do not use the this method is called when a frame is wanted on an output For a it should directly call filter_frame on the corresponding output For a if there are queued frames already one of these frames should be pushed If the filter should request a frame on one of its repeatedly until at least one frame has been pushed Return or at least make progress towards producing a frame
Definition: filter_design.txt:264
QSVFrame::queued
int queued
Definition: qsv_internal.h:79
AVHWFramesContext::device_ctx
AVHWDeviceContext * device_ctx
The parent AVHWDeviceContext.
Definition: hwcontext.h:149
AVHWFramesContext::hwctx
void * hwctx
The format-specific data, allocated and freed automatically along with this context.
Definition: hwcontext.h:162
process_frame
static int process_frame(AVFilterContext *ctx, const AVFrame *in, mfxFrameSurface1 *surf_in)
Definition: vf_deinterlace_qsv.c:453
AVFrame::height
int height
Definition: frame.h:361
again
Filter the word “frame” indicates either a video frame or a group of audio as stored in an AVFrame structure Format for each input and each output the list of supported formats For video that means pixel format For audio that means channel sample they are references to shared objects When the negotiation mechanism computes the intersection of the formats supported at each end of a all references to both lists are replaced with a reference to the intersection And when a single format is eventually chosen for a link amongst the remaining again
Definition: filter_design.txt:25
options
static const AVOption options[]
Definition: vf_deinterlace_qsv.c:564
init_out_session
static int init_out_session(AVFilterContext *ctx)
Definition: vf_deinterlace_qsv.c:162
qsvdeint_config_props
static int qsvdeint_config_props(AVFilterLink *outlink)
Definition: vf_deinterlace_qsv.c:325
mode
mode
Definition: ebur128.h:83
AV_PIX_FMT_NONE
@ AV_PIX_FMT_NONE
Definition: pixfmt.h:65
qsvdeint_outputs
static const AVFilterPad qsvdeint_outputs[]
Definition: vf_deinterlace_qsv.c:587
AV_OPT_TYPE_INT
@ AV_OPT_TYPE_INT
Definition: opt.h:224
avfilter.h
av_mul_q
AVRational av_mul_q(AVRational b, AVRational c)
Multiply two rationals.
Definition: rational.c:80
QSVDEINT_MORE_OUTPUT
@ QSVDEINT_MORE_OUTPUT
Definition: vf_deinterlace_qsv.c:46
av_buffer_ref
AVBufferRef * av_buffer_ref(AVBufferRef *buf)
Create a new reference to an AVBuffer.
Definition: buffer.c:93
QSVDeintContext::eof
int eof
Definition: vf_deinterlace_qsv.c:72
AVFilterContext
An instance of a filter.
Definition: avfilter.h:333
frame_lock
static mfxStatus frame_lock(mfxHDL pthis, mfxMemId mid, mfxFrameData *ptr)
Definition: vf_deinterlace_qsv.c:140
qsvdeint_inputs
static const AVFilterPad qsvdeint_inputs[]
Definition: vf_deinterlace_qsv.c:578
AVQSVFramesContext
This struct is allocated as AVHWFramesContext.hwctx.
Definition: hwcontext_qsv.h:42
AVMEDIA_TYPE_VIDEO
@ AVMEDIA_TYPE_VIDEO
Definition: avutil.h:201
AVBufferRef
A reference to a data buffer.
Definition: buffer.h:82
submit_frame
static int submit_frame(AVFilterContext *ctx, AVFrame *frame, mfxFrameSurface1 **surface)
Definition: vf_deinterlace_qsv.c:404
frame_unlock
static mfxStatus frame_unlock(mfxHDL pthis, mfxMemId mid, mfxFrameData *ptr)
Definition: vf_deinterlace_qsv.c:145
av_freep
#define av_freep(p)
Definition: tableprint_vlc.h:35
get_free_frame
static int get_free_frame(QSVDeintContext *s, QSVFrame **f)
Definition: vf_deinterlace_qsv.c:377
hwcontext.h
av_log
#define av_log(a,...)
Definition: tableprint_vlc.h:28
frame_get_hdl
static mfxStatus frame_get_hdl(mfxHDL pthis, mfxMemId mid, mfxHDL *hdl)
Definition: vf_deinterlace_qsv.c:150
avstring.h
QSVFrame::next
struct QSVFrame * next
Definition: qsv_internal.h:82
AV_OPT_TYPE_CONST
@ AV_OPT_TYPE_CONST
Definition: opt.h:233
ff_qsvvpp_print_warning
int ff_qsvvpp_print_warning(void *log_ctx, mfxStatus err, const char *warning_string)
Definition: qsvvpp.c:142
AVFrame::repeat_pict
int repeat_pict
When decoding, this signals how much the picture must be delayed.
Definition: frame.h:428
QSVDeintContext::nb_surface_ptrs
int nb_surface_ptrs
Definition: vf_deinterlace_qsv.c:61
FLAGS
#define FLAGS
Definition: vf_deinterlace_qsv.c:563