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 <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 #define MFX_IMPL_VIA_MASK(impl) (0x0f00 & (impl))
46 
47 enum {
50 };
51 
52 typedef struct QSVDeintContext {
53  const AVClass *class;
54 
56  /* a clone of the main session, used internally for deinterlacing */
57  mfxSession session;
58 
59  mfxMemId *mem_ids;
61 
62  mfxFrameSurface1 **surface_ptrs;
64 
65 #if QSV_HAVE_OPAQUE
66  mfxExtOpaqueSurfaceAlloc opaque_alloc;
67 #endif
68  mfxExtVPPDeinterlacing deint_conf;
69  mfxExtBuffer *ext_buffers[2];
71 
73 
74  int64_t last_pts;
75 
76  int eof;
77 
78  /* option for Deinterlacing algorithm to be used */
79  int mode;
81 
83 {
84  QSVDeintContext *s = ctx->priv;
85  QSVFrame *cur;
86 
87  if (s->session) {
88  MFXClose(s->session);
89  s->session = NULL;
90  }
91  av_buffer_unref(&s->hw_frames_ctx);
92 
93  cur = s->work_frames;
94  while (cur) {
95  s->work_frames = cur->next;
96  av_frame_free(&cur->frame);
97  av_freep(&cur);
98  cur = s->work_frames;
99  }
100 
101  av_freep(&s->mem_ids);
102  s->nb_mem_ids = 0;
103 
104  av_freep(&s->surface_ptrs);
105  s->nb_surface_ptrs = 0;
106 }
107 
108 static mfxStatus frame_alloc(mfxHDL pthis, mfxFrameAllocRequest *req,
109  mfxFrameAllocResponse *resp)
110 {
111  AVFilterContext *ctx = pthis;
112  QSVDeintContext *s = ctx->priv;
113 
114  if (!(req->Type & MFX_MEMTYPE_VIDEO_MEMORY_PROCESSOR_TARGET) ||
115  !(req->Type & (MFX_MEMTYPE_FROM_VPPIN | MFX_MEMTYPE_FROM_VPPOUT)) ||
116  !(req->Type & MFX_MEMTYPE_EXTERNAL_FRAME))
117  return MFX_ERR_UNSUPPORTED;
118 
119  resp->mids = s->mem_ids;
120  resp->NumFrameActual = s->nb_mem_ids;
121 
122  return MFX_ERR_NONE;
123 }
124 
125 static mfxStatus frame_free(mfxHDL pthis, mfxFrameAllocResponse *resp)
126 {
127  return MFX_ERR_NONE;
128 }
129 
130 static mfxStatus frame_lock(mfxHDL pthis, mfxMemId mid, mfxFrameData *ptr)
131 {
132  return MFX_ERR_UNSUPPORTED;
133 }
134 
135 static mfxStatus frame_unlock(mfxHDL pthis, mfxMemId mid, mfxFrameData *ptr)
136 {
137  return MFX_ERR_UNSUPPORTED;
138 }
139 
140 static mfxStatus frame_get_hdl(mfxHDL pthis, mfxMemId mid, mfxHDL *hdl)
141 {
142  mfxHDLPair *pair_dst = (mfxHDLPair*)hdl;
143  mfxHDLPair *pair_src = (mfxHDLPair*)mid;
144 
145  pair_dst->first = pair_src->first;
146 
147  if (pair_src->second != (mfxMemId)MFX_INFINITE)
148  pair_dst->second = pair_src->second;
149  return MFX_ERR_NONE;
150 }
151 
153 {
154 
155  QSVDeintContext *s = ctx->priv;
156  AVHWFramesContext *hw_frames_ctx = (AVHWFramesContext*)s->hw_frames_ctx->data;
157  AVQSVFramesContext *hw_frames_hwctx = hw_frames_ctx->hwctx;
158  AVQSVDeviceContext *device_hwctx = hw_frames_ctx->device_ctx->hwctx;
159  int opaque = 0;
160  mfxHDL handle = NULL;
161  mfxHandleType handle_type;
162  mfxVersion ver;
163  mfxIMPL impl;
164  mfxVideoParam par;
165  mfxStatus err;
166  int i, ret;
167 
168 #if QSV_HAVE_OPAQUE
169  opaque = !!(hw_frames_hwctx->frame_type & MFX_MEMTYPE_OPAQUE_FRAME);
170 #endif
171  /* extract the properties of the "master" session given to us */
172  err = MFXQueryIMPL(device_hwctx->session, &impl);
173  if (err == MFX_ERR_NONE)
174  err = MFXQueryVersion(device_hwctx->session, &ver);
175  if (err != MFX_ERR_NONE) {
176  av_log(ctx, AV_LOG_ERROR, "Error querying the session attributes\n");
177  return AVERROR_UNKNOWN;
178  }
179 
180  if (MFX_IMPL_VIA_VAAPI == MFX_IMPL_VIA_MASK(impl)) {
181  handle_type = MFX_HANDLE_VA_DISPLAY;
182  } else if (MFX_IMPL_VIA_D3D11 == MFX_IMPL_VIA_MASK(impl)) {
183  handle_type = MFX_HANDLE_D3D11_DEVICE;
184  } else if (MFX_IMPL_VIA_D3D9 == MFX_IMPL_VIA_MASK(impl)) {
185  handle_type = MFX_HANDLE_D3D9_DEVICE_MANAGER;
186  } else {
187  av_log(ctx, AV_LOG_ERROR, "Error unsupported handle type\n");
188  return AVERROR_UNKNOWN;
189  }
190 
191  err = MFXVideoCORE_GetHandle(device_hwctx->session, handle_type, &handle);
192  if (err < 0)
193  return ff_qsvvpp_print_error(ctx, err, "Error getting the session handle");
194  else if (err > 0) {
195  ff_qsvvpp_print_warning(ctx, err, "Warning in getting the session handle");
196  return AVERROR_UNKNOWN;
197  }
198 
199  /* create a "slave" session with those same properties, to be used for
200  * actual deinterlacing */
201  ret = ff_qsvvpp_create_mfx_session(ctx, device_hwctx->loader, impl, &ver,
202  &s->session);
203  if (ret)
204  return ret;
205 
206  if (handle) {
207  err = MFXVideoCORE_SetHandle(s->session, handle_type, handle);
208  if (err != MFX_ERR_NONE)
209  return AVERROR_UNKNOWN;
210  }
211 
212  if (QSV_RUNTIME_VERSION_ATLEAST(ver, 1, 25)) {
213  err = MFXJoinSession(device_hwctx->session, s->session);
214  if (err != MFX_ERR_NONE)
215  return AVERROR_UNKNOWN;
216  }
217 
218  memset(&par, 0, sizeof(par));
219 
220  s->deint_conf.Header.BufferId = MFX_EXTBUFF_VPP_DEINTERLACING;
221  s->deint_conf.Header.BufferSz = sizeof(s->deint_conf);
222  s->deint_conf.Mode = s->mode;
223 
224  s->ext_buffers[s->num_ext_buffers++] = (mfxExtBuffer *)&s->deint_conf;
225 
226  if (!opaque) {
227  mfxFrameAllocator frame_allocator = {
228  .pthis = ctx,
229  .Alloc = frame_alloc,
230  .Lock = frame_lock,
231  .Unlock = frame_unlock,
232  .GetHDL = frame_get_hdl,
233  .Free = frame_free,
234  };
235 
236  s->mem_ids = av_calloc(hw_frames_hwctx->nb_surfaces,
237  sizeof(*s->mem_ids));
238  if (!s->mem_ids)
239  return AVERROR(ENOMEM);
240  for (i = 0; i < hw_frames_hwctx->nb_surfaces; i++)
241  s->mem_ids[i] = hw_frames_hwctx->surfaces[i].Data.MemId;
242  s->nb_mem_ids = hw_frames_hwctx->nb_surfaces;
243 
244  err = MFXVideoCORE_SetFrameAllocator(s->session, &frame_allocator);
245  if (err != MFX_ERR_NONE)
246  return AVERROR_UNKNOWN;
247 
248  par.IOPattern = MFX_IOPATTERN_IN_VIDEO_MEMORY | MFX_IOPATTERN_OUT_VIDEO_MEMORY;
249  }
250 #if QSV_HAVE_OPAQUE
251  else {
252  s->surface_ptrs = av_calloc(hw_frames_hwctx->nb_surfaces,
253  sizeof(*s->surface_ptrs));
254 
255  if (!s->surface_ptrs)
256  return AVERROR(ENOMEM);
257  for (i = 0; i < hw_frames_hwctx->nb_surfaces; i++)
258  s->surface_ptrs[i] = hw_frames_hwctx->surfaces + i;
259  s->nb_surface_ptrs = hw_frames_hwctx->nb_surfaces;
260 
261  s->opaque_alloc.In.Surfaces = s->surface_ptrs;
262  s->opaque_alloc.In.NumSurface = s->nb_surface_ptrs;
263  s->opaque_alloc.In.Type = hw_frames_hwctx->frame_type;
264 
265  s->opaque_alloc.Out = s->opaque_alloc.In;
266 
267  s->opaque_alloc.Header.BufferId = MFX_EXTBUFF_OPAQUE_SURFACE_ALLOCATION;
268  s->opaque_alloc.Header.BufferSz = sizeof(s->opaque_alloc);
269 
270  s->ext_buffers[s->num_ext_buffers++] = (mfxExtBuffer *)&s->opaque_alloc;
271 
272  par.IOPattern = MFX_IOPATTERN_IN_OPAQUE_MEMORY | MFX_IOPATTERN_OUT_OPAQUE_MEMORY;
273  }
274 #endif
275 
276  par.ExtParam = s->ext_buffers;
277  par.NumExtParam = s->num_ext_buffers;
278 
279  par.AsyncDepth = 1; // TODO async
280 
281  par.vpp.In = hw_frames_hwctx->surfaces[0].Info;
282 
283  par.vpp.In.CropW = ctx->inputs[0]->w;
284  par.vpp.In.CropH = ctx->inputs[0]->h;
285 
286  if (ctx->inputs[0]->frame_rate.num) {
287  par.vpp.In.FrameRateExtN = ctx->inputs[0]->frame_rate.num;
288  par.vpp.In.FrameRateExtD = ctx->inputs[0]->frame_rate.den;
289  } else {
290  par.vpp.In.FrameRateExtN = ctx->inputs[0]->time_base.num;
291  par.vpp.In.FrameRateExtD = ctx->inputs[0]->time_base.den;
292  }
293 
294  par.vpp.Out = par.vpp.In;
295 
296  if (ctx->outputs[0]->frame_rate.num) {
297  par.vpp.Out.FrameRateExtN = ctx->outputs[0]->frame_rate.num;
298  par.vpp.Out.FrameRateExtD = ctx->outputs[0]->frame_rate.den;
299  } else {
300  par.vpp.Out.FrameRateExtN = ctx->outputs[0]->time_base.num;
301  par.vpp.Out.FrameRateExtD = ctx->outputs[0]->time_base.den;
302  }
303 
304  /* Print input memory mode */
305  ff_qsvvpp_print_iopattern(ctx, par.IOPattern & 0x0F, "VPP");
306  /* Print output memory mode */
307  ff_qsvvpp_print_iopattern(ctx, par.IOPattern & 0xF0, "VPP");
308  err = MFXVideoVPP_Init(s->session, &par);
309  if (err < 0)
310  return ff_qsvvpp_print_error(ctx, err,
311  "Error opening the VPP for deinterlacing");
312  else if (err > 0) {
314  "Warning in VPP initialization");
315  return AVERROR_UNKNOWN;
316  }
317 
318  return 0;
319 }
320 
322 {
323  AVFilterContext *ctx = outlink->src;
324  AVFilterLink *inlink = ctx->inputs[0];
325  QSVDeintContext *s = ctx->priv;
326  int ret;
327 
329 
330  s->last_pts = AV_NOPTS_VALUE;
331  outlink->frame_rate = av_mul_q(inlink->frame_rate,
332  (AVRational){ 2, 1 });
333  outlink->time_base = av_mul_q(inlink->time_base,
334  (AVRational){ 1, 2 });
335 
336  /* check that we have a hw context */
337  if (!inlink->hw_frames_ctx) {
338  av_log(ctx, AV_LOG_ERROR, "No hw context provided on input\n");
339  return AVERROR(EINVAL);
340  }
341 
342  s->hw_frames_ctx = av_buffer_ref(inlink->hw_frames_ctx);
343  if (!s->hw_frames_ctx)
344  return AVERROR(ENOMEM);
345 
346  av_buffer_unref(&outlink->hw_frames_ctx);
347  outlink->hw_frames_ctx = av_buffer_ref(inlink->hw_frames_ctx);
348  if (!outlink->hw_frames_ctx) {
350  return AVERROR(ENOMEM);
351  }
352 
354  if (ret < 0)
355  return ret;
356 
357 
358  return 0;
359 }
360 
362 {
363  QSVFrame *cur = s->work_frames;
364  while (cur) {
365  if (!cur->surface.Data.Locked) {
366  av_frame_free(&cur->frame);
367  cur->queued = 0;
368  }
369  cur = cur->next;
370  }
371 }
372 
374 {
375  QSVFrame *frame, **last;
376 
378 
379  frame = s->work_frames;
380  last = &s->work_frames;
381  while (frame) {
382  if (!frame->queued) {
383  *f = frame;
384  return 0;
385  }
386 
387  last = &frame->next;
388  frame = frame->next;
389  }
390 
391  frame = av_mallocz(sizeof(*frame));
392  if (!frame)
393  return AVERROR(ENOMEM);
394  *last = frame;
395  *f = frame;
396 
397  return 0;
398 }
399 
401  mfxFrameSurface1 **surface)
402 {
403  QSVDeintContext *s = ctx->priv;
404  QSVFrame *qf;
405  int ret;
406 
407  ret = get_free_frame(s, &qf);
408  if (ret < 0)
409  return ret;
410 
411  qf->frame = frame;
412 
413  qf->surface = *(mfxFrameSurface1*)qf->frame->data[3];
414 
415  qf->surface.Data.Locked = 0;
416  qf->surface.Info.CropW = qf->frame->width;
417  qf->surface.Info.CropH = qf->frame->height;
418 
419  qf->surface.Info.PicStruct = !qf->frame->interlaced_frame ? MFX_PICSTRUCT_PROGRESSIVE :
420  (qf->frame->top_field_first ? MFX_PICSTRUCT_FIELD_TFF :
421  MFX_PICSTRUCT_FIELD_BFF);
422  if (qf->frame->repeat_pict == 1) {
423  qf->surface.Info.PicStruct |= MFX_PICSTRUCT_FIELD_REPEATED;
424  qf->surface.Info.PicStruct |= qf->frame->top_field_first ? MFX_PICSTRUCT_FIELD_TFF :
425  MFX_PICSTRUCT_FIELD_BFF;
426  } else if (qf->frame->repeat_pict == 2)
427  qf->surface.Info.PicStruct |= MFX_PICSTRUCT_FRAME_DOUBLING;
428  else if (qf->frame->repeat_pict == 4)
429  qf->surface.Info.PicStruct |= MFX_PICSTRUCT_FRAME_TRIPLING;
430 
431  if (ctx->inputs[0]->frame_rate.num) {
432  qf->surface.Info.FrameRateExtN = ctx->inputs[0]->frame_rate.num;
433  qf->surface.Info.FrameRateExtD = ctx->inputs[0]->frame_rate.den;
434  } else {
435  qf->surface.Info.FrameRateExtN = ctx->inputs[0]->time_base.num;
436  qf->surface.Info.FrameRateExtD = ctx->inputs[0]->time_base.den;
437  }
438 
439  qf->surface.Data.TimeStamp = av_rescale_q(qf->frame->pts,
440  ctx->inputs[0]->time_base,
441  (AVRational){1, 90000});
442 
443  *surface = &qf->surface;
444  qf->queued = 1;
445 
446  return 0;
447 }
448 
449 static int process_frame(AVFilterContext *ctx, const AVFrame *in,
450  mfxFrameSurface1 *surf_in)
451 {
452  QSVDeintContext *s = ctx->priv;
453  AVFilterLink *inlink = ctx->inputs[0];
454  AVFilterLink *outlink = ctx->outputs[0];
455 
456  AVFrame *out;
457  mfxFrameSurface1 *surf_out;
458  mfxSyncPoint sync = NULL;
459  mfxStatus err;
460  int ret, again = 0;
461 
462  out = ff_get_video_buffer(outlink, outlink->w, outlink->h);
463  if (!out) {
464  ret = AVERROR(ENOMEM);
465  goto fail;
466  }
467 
468  surf_out = (mfxFrameSurface1*)out->data[3];
469  surf_out->Info.CropW = outlink->w;
470  surf_out->Info.CropH = outlink->h;
471  surf_out->Info.PicStruct = MFX_PICSTRUCT_PROGRESSIVE;
472 
473  do {
474  err = MFXVideoVPP_RunFrameVPPAsync(s->session, surf_in, surf_out,
475  NULL, &sync);
476  if (err == MFX_WRN_DEVICE_BUSY)
477  av_usleep(1);
478  } while (err == MFX_WRN_DEVICE_BUSY);
479 
480  if (err == MFX_ERR_MORE_DATA) {
481  av_frame_free(&out);
482  return QSVDEINT_MORE_INPUT;
483  }
484 
485  if (err < 0 && err != MFX_ERR_MORE_SURFACE) {
486  ret = ff_qsvvpp_print_error(ctx, err, "Error during deinterlacing");
487  goto fail;
488  }
489 
490  if (!sync) {
491  av_log(ctx, AV_LOG_ERROR, "No sync during deinterlacing\n");
493  goto fail;
494  }
495  if (err == MFX_ERR_MORE_SURFACE)
496  again = 1;
497 
498  do {
499  err = MFXVideoCORE_SyncOperation(s->session, sync, 1000);
500  } while (err == MFX_WRN_IN_EXECUTION);
501  if (err < 0) {
502  ret = ff_qsvvpp_print_error(ctx, err, "Error synchronizing the operation");
503  goto fail;
504  }
505 
506  ret = av_frame_copy_props(out, in);
507  if (ret < 0)
508  goto fail;
509 
510  out->width = outlink->w;
511  out->height = outlink->h;
512  out->interlaced_frame = 0;
513 
514  out->pts = av_rescale_q(out->pts, inlink->time_base, outlink->time_base);
515  if (out->pts == s->last_pts)
516  out->pts++;
517  s->last_pts = out->pts;
518 
519  if (outlink->frame_rate.num && outlink->frame_rate.den)
520  out->duration = av_rescale_q(1, av_inv_q(outlink->frame_rate), outlink->time_base);
521  else
522  out->duration = 0;
523 
524  ret = ff_filter_frame(outlink, out);
525  if (ret < 0)
526  return ret;
527 
528  return again ? QSVDEINT_MORE_OUTPUT : 0;
529 fail:
530  av_frame_free(&out);
531  return ret;
532 }
533 
535 {
536  AVFilterContext *ctx = link->dst;
537 
538  mfxFrameSurface1 *surf_in;
539  int ret;
540 
541  ret = submit_frame(ctx, in, &surf_in);
542  if (ret < 0) {
543  av_frame_free(&in);
544  return ret;
545  }
546 
547  do {
548  ret = process_frame(ctx, in, surf_in);
549  if (ret < 0)
550  return ret;
551  } while (ret == QSVDEINT_MORE_OUTPUT);
552 
553  return 0;
554 }
555 
557 {
558  AVFilterContext *ctx = outlink->src;
559 
560  return ff_request_frame(ctx->inputs[0]);
561 }
562 
563 #define OFFSET(x) offsetof(QSVDeintContext, x)
564 #define FLAGS AV_OPT_FLAG_VIDEO_PARAM|AV_OPT_FLAG_FILTERING_PARAM
565 static const AVOption options[] = {
566  { "mode", "set deinterlace mode", OFFSET(mode), AV_OPT_TYPE_INT, {.i64 = MFX_DEINTERLACING_ADVANCED}, MFX_DEINTERLACING_BOB, MFX_DEINTERLACING_ADVANCED, FLAGS, "mode"},
567  { "bob", "bob algorithm", 0, AV_OPT_TYPE_CONST, {.i64 = MFX_DEINTERLACING_BOB}, MFX_DEINTERLACING_BOB, MFX_DEINTERLACING_ADVANCED, FLAGS, "mode"},
568  { "advanced", "Motion adaptive algorithm", 0, AV_OPT_TYPE_CONST, {.i64 = MFX_DEINTERLACING_ADVANCED}, MFX_DEINTERLACING_BOB, MFX_DEINTERLACING_ADVANCED, FLAGS, "mode"},
569  { NULL },
570 };
571 
572 static const AVClass qsvdeint_class = {
573  .class_name = "deinterlace_qsv",
574  .item_name = av_default_item_name,
575  .option = options,
576  .version = LIBAVUTIL_VERSION_INT,
577 };
578 
579 static const AVFilterPad qsvdeint_inputs[] = {
580  {
581  .name = "default",
582  .type = AVMEDIA_TYPE_VIDEO,
583  .filter_frame = qsvdeint_filter_frame,
584  .get_buffer.video = ff_qsvvpp_get_video_buffer,
585  },
586 };
587 
588 static const AVFilterPad qsvdeint_outputs[] = {
589  {
590  .name = "default",
591  .type = AVMEDIA_TYPE_VIDEO,
592  .config_props = qsvdeint_config_props,
593  .request_frame = qsvdeint_request_frame,
594  },
595 };
596 
598  .name = "deinterlace_qsv",
599  .description = NULL_IF_CONFIG_SMALL("QuickSync video deinterlacing"),
600 
601  .uninit = qsvdeint_uninit,
602 
603  .priv_size = sizeof(QSVDeintContext),
604  .priv_class = &qsvdeint_class,
605 
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:556
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:101
AVHWDeviceContext::hwctx
void * hwctx
The format-specific data, allocated and freed by libavutil along with this context.
Definition: hwcontext.h:92
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
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:370
ff_filter_frame
int ff_filter_frame(AVFilterLink *link, AVFrame *frame)
Send a frame of data to the next filter.
Definition: avfilter.c:978
ff_qsvvpp_get_video_buffer
AVFrame * ff_qsvvpp_get_video_buffer(AVFilterLink *inlink, int w, int h)
Definition: qsvvpp.c:1017
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:116
QSVDeintContext::mode
int mode
Definition: vf_deinterlace_qsv.c:79
AVFrame
This structure describes decoded (raw) audio or video data.
Definition: frame.h:330
pixdesc.h
AVFrame::pts
int64_t pts
Presentation timestamp in time_base units (time when frame should be shown to user).
Definition: frame.h:437
AVFrame::width
int width
Definition: frame.h:402
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:487
AVOption
AVOption.
Definition: opt.h:251
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:410
mathematics.h
av_buffer_ref
AVBufferRef * av_buffer_ref(const AVBufferRef *buf)
Create a new reference to an AVBuffer.
Definition: buffer.c:103
AVFilter::name
const char * name
Filter name.
Definition: avfilter.h:175
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:81
AVFrame::data
uint8_t * data[AV_NUM_DATA_POINTERS]
pointer to the picture/channel planes.
Definition: frame.h:351
formats.h
QSVDeintContext::hw_frames_ctx
AVBufferRef * hw_frames_ctx
Definition: vf_deinterlace_qsv.c:55
QSVDeintContext::last_pts
int64_t last_pts
Definition: vf_deinterlace_qsv.c:74
qsvvpp.h
fail
#define fail()
Definition: checkasm.h:134
QSVDeintContext::ext_buffers
mfxExtBuffer * ext_buffers[2]
Definition: vf_deinterlace_qsv.c:69
qsvdeint_filter_frame
static int qsvdeint_filter_frame(AVFilterLink *link, AVFrame *in)
Definition: vf_deinterlace_qsv.c:534
QSVDEINT_MORE_INPUT
@ QSVDEINT_MORE_INPUT
Definition: vf_deinterlace_qsv.c:49
QSVDeintContext
Definition: vf_deinterlace_qsv.c:52
AVFilterPad
A filter pad used for either input or output.
Definition: internal.h:49
ff_qsvvpp_print_iopattern
int ff_qsvvpp_print_iopattern(void *log_ctx, int mfx_iopattern, const char *extra_string)
Definition: qsvvpp.c:72
AV_LOG_ERROR
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
Definition: log.h:180
av_cold
#define av_cold
Definition: attributes.h:90
qsvdeint_uninit
static av_cold void qsvdeint_uninit(AVFilterContext *ctx)
Definition: vf_deinterlace_qsv.c:82
QSVDeintContext::surface_ptrs
mfxFrameSurface1 ** surface_ptrs
Definition: vf_deinterlace_qsv.c:62
s
#define s(width, name)
Definition: cbs_vp9.c:256
QSV_RUNTIME_VERSION_ATLEAST
#define QSV_RUNTIME_VERSION_ATLEAST(MFX_VERSION, MAJOR, MINOR)
Definition: qsv_internal.h:64
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:142
av_usleep
int av_usleep(unsigned usec)
Sleep for a period of time.
Definition: time.c:84
FILTER_INPUTS
#define FILTER_INPUTS(array)
Definition: internal.h:190
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:72
QSVFrame
Definition: qsv_internal.h:80
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:603
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:139
QSV_HAVE_OPAQUE
#define QSV_HAVE_OPAQUE
Definition: qsv_internal.h:69
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:70
ff_qsvvpp_print_error
int ff_qsvvpp_print_error(void *log_ctx, mfxStatus err, const char *error_string)
Definition: qsvvpp.c:154
av_default_item_name
const char * av_default_item_name(void *ptr)
Return the context name.
Definition: log.c:237
QSVFrame::surface
mfxFrameSurface1 surface
Definition: qsv_internal.h:82
OFFSET
#define OFFSET(x)
Definition: vf_deinterlace_qsv.c:563
time.h
QSVDeintContext::deint_conf
mfxExtVPPDeinterlacing deint_conf
Definition: vf_deinterlace_qsv.c:68
AV_PIX_FMT_QSV
@ AV_PIX_FMT_QSV
HW acceleration through QSV, data[3] contains a pointer to the mfxFrameSurface1 structure.
Definition: pixfmt.h:240
qsvdeint_class
static const AVClass qsvdeint_class
Definition: vf_deinterlace_qsv.c:572
QSVDEINT_MORE_OUTPUT
@ QSVDEINT_MORE_OUTPUT
Definition: vf_deinterlace_qsv.c:48
f
f
Definition: af_crystalizer.c:122
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:115
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:125
internal.h
QSVDeintContext::mem_ids
mfxMemId * mem_ids
Definition: vf_deinterlace_qsv.c:59
FILTER_SINGLE_PIXFMT
#define FILTER_SINGLE_PIXFMT(pix_fmt_)
Definition: internal.h:180
AVFrame::interlaced_frame
int interlaced_frame
The content of the picture is interlaced.
Definition: frame.h:482
hwcontext_qsv.h
i
#define i(width, name, range_min, range_max)
Definition: cbs_h2645.c:269
internal.h
common.h
frame_alloc
static mfxStatus frame_alloc(mfxHDL pthis, mfxFrameAllocRequest *req, mfxFrameAllocResponse *resp)
Definition: vf_deinterlace_qsv.c:108
clear_unused_frames
static void clear_unused_frames(QSVDeintContext *s)
Definition: vf_deinterlace_qsv.c:361
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:264
av_inv_q
static av_always_inline AVRational av_inv_q(AVRational q)
Invert a rational.
Definition: rational.h:159
QSVDeintContext::session
mfxSession session
Definition: vf_deinterlace_qsv.c:57
AVFilterPad::name
const char * name
Pad name.
Definition: internal.h:55
QSVDeintContext::nb_mem_ids
int nb_mem_ids
Definition: vf_deinterlace_qsv.c:60
av_calloc
void * av_calloc(size_t nmemb, size_t size)
Definition: mem.c:272
AVFilter
Filter definition.
Definition: avfilter.h:171
AVHWFramesContext
This struct describes a set or pool of "hardware" frames (i.e.
Definition: hwcontext.h:124
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:100
AVHWFramesContext::device_ctx
AVHWDeviceContext * device_ctx
The parent AVHWDeviceContext.
Definition: hwcontext.h:149
MFX_IMPL_VIA_MASK
#define MFX_IMPL_VIA_MASK(impl)
Definition: vf_deinterlace_qsv.c:45
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:449
AVFrame::height
int height
Definition: frame.h:402
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:565
init_out_session
static int init_out_session(AVFilterContext *ctx)
Definition: vf_deinterlace_qsv.c:152
qsvdeint_config_props
static int qsvdeint_config_props(AVFilterLink *outlink)
Definition: vf_deinterlace_qsv.c:321
mode
mode
Definition: ebur128.h:83
qsvdeint_outputs
static const AVFilterPad qsvdeint_outputs[]
Definition: vf_deinterlace_qsv.c:588
AV_OPT_TYPE_INT
@ AV_OPT_TYPE_INT
Definition: opt.h:225
avfilter.h
av_mul_q
AVRational av_mul_q(AVRational b, AVRational c)
Multiply two rationals.
Definition: rational.c:80
QSVDeintContext::eof
int eof
Definition: vf_deinterlace_qsv.c:76
AVFilterContext
An instance of a filter.
Definition: avfilter.h:402
frame_lock
static mfxStatus frame_lock(mfxHDL pthis, mfxMemId mid, mfxFrameData *ptr)
Definition: vf_deinterlace_qsv.c:130
qsvdeint_inputs
static const AVFilterPad qsvdeint_inputs[]
Definition: vf_deinterlace_qsv.c:579
AVQSVFramesContext
This struct is allocated as AVHWFramesContext.hwctx.
Definition: hwcontext_qsv.h:53
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:400
frame_unlock
static mfxStatus frame_unlock(mfxHDL pthis, mfxMemId mid, mfxFrameData *ptr)
Definition: vf_deinterlace_qsv.c:135
FILTER_OUTPUTS
#define FILTER_OUTPUTS(array)
Definition: internal.h:191
av_freep
#define av_freep(p)
Definition: tableprint_vlc.h:34
get_free_frame
static int get_free_frame(QSVDeintContext *s, QSVFrame **f)
Definition: vf_deinterlace_qsv.c:373
hwcontext.h
av_log
#define av_log(a,...)
Definition: tableprint_vlc.h:27
frame_get_hdl
static mfxStatus frame_get_hdl(mfxHDL pthis, mfxMemId mid, mfxHDL *hdl)
Definition: vf_deinterlace_qsv.c:140
avstring.h
ff_qsvvpp_create_mfx_session
int ff_qsvvpp_create_mfx_session(void *ctx, void *loader, mfxIMPL implementation, mfxVersion *pver, mfxSession *psession)
Definition: qsvvpp.c:986
QSVFrame::next
struct QSVFrame * next
Definition: qsv_internal.h:103
AV_OPT_TYPE_CONST
@ AV_OPT_TYPE_CONST
Definition: opt.h:234
ff_qsvvpp_print_warning
int ff_qsvvpp_print_warning(void *log_ctx, mfxStatus err, const char *warning_string)
Definition: qsvvpp.c:164
AVFrame::repeat_pict
int repeat_pict
When decoding, this signals how much the picture must be delayed.
Definition: frame.h:477
QSVDeintContext::nb_surface_ptrs
int nb_surface_ptrs
Definition: vf_deinterlace_qsv.c:63
FLAGS
#define FLAGS
Definition: vf_deinterlace_qsv.c:564