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  }
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;
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) {
192  handle_type = handle_types[i];
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) {
317  ff_qsvvpp_print_warning(ctx, err,
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 
332  qsvdeint_uninit(ctx);
333 
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 
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) {
353  qsvdeint_uninit(ctx);
354  return AVERROR(ENOMEM);
355  }
356 
357  ret = init_out_session(ctx);
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 
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 
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 
607  .inputs = qsvdeint_inputs,
608  .outputs = qsvdeint_outputs,
609 
610  .flags_internal = FF_FILTER_FLAG_HWFRAME_AWARE,
611 };
#define NULL
Definition: coverity.c:32
static av_cold void qsvdeint_uninit(AVFilterContext *ctx)
#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
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
mfxExtVPPDeinterlacing deint_conf
This structure describes decoded (raw) audio or video data.
Definition: frame.h:318
AVOption.
Definition: opt.h:248
static int get_free_frame(QSVDeintContext *s, QSVFrame **f)
static const AVClass qsvdeint_class
static const AVFilterPad qsvdeint_inputs[]
#define LIBAVUTIL_VERSION_INT
Definition: version.h:85
Main libavfilter public API header.
mfxHandleType handle_type
Definition: hwcontext_qsv.c:89
This struct is allocated as AVHWFramesContext.hwctx.
Definition: hwcontext_qsv.h:42
int num
Numerator.
Definition: rational.h:59
int repeat_pict
When decoding, this signals how much the picture must be delayed.
Definition: frame.h:460
const char * av_default_item_name(void *ptr)
Return the context name.
Definition: log.c:235
#define FLAGS
#define QSV_RUNTIME_VERSION_ATLEAST(MFX_VERSION, MAJOR, MINOR)
Definition: qsv_internal.h:59
#define FF_ARRAY_ELEMS(a)
void * av_mallocz(size_t size)
Allocate a memory block with alignment suitable for all memory accesses (including vectors if availab...
Definition: mem.c:237
int av_usleep(unsigned usec)
Sleep for a period of time.
Definition: time.c:84
AVFrame * ff_get_video_buffer(AVFilterLink *link, int w, int h)
Request a picture buffer with a specific set of permissions.
Definition: video.c:99
static int qsvdeint_request_frame(AVFilterLink *outlink)
AVFilterFormats * ff_make_format_list(const int *fmts)
Create a list of supported formats.
Definition: formats.c:287
static int qsvdeint_query_formats(AVFilterContext *ctx)
const char * name
Pad name.
Definition: internal.h:60
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:72
AVFilterLink ** inputs
array of pointers to input links
Definition: avfilter.h:349
int ff_filter_frame(AVFilterLink *link, AVFrame *frame)
Send a frame of data to the next filter.
Definition: avfilter.c:1094
#define OFFSET(x)
#define av_cold
Definition: attributes.h:88
AVOptions.
#define f(width, name)
Definition: cbs_vp9.c:255
static int process_frame(AVFilterContext *ctx, const AVFrame *in, mfxFrameSurface1 *surf_in)
int64_t pts
Presentation timestamp in time_base units (time when frame should be shown to user).
Definition: frame.h:411
static int qsvdeint_config_props(AVFilterLink *outlink)
void * hwctx
The format-specific data, allocated and freed by libavutil along with this context.
Definition: hwcontext.h:92
int queued
Definition: qsv_internal.h:79
static int qsvdeint_filter_frame(AVFilterLink *link, AVFrame *in)
int interlaced_frame
The content of the picture is interlaced.
Definition: frame.h:465
static mfxStatus frame_lock(mfxHDL pthis, mfxMemId mid, mfxFrameData *ptr)
int ff_qsvvpp_print_warning(void *log_ctx, mfxStatus err, const char *warning_string)
Definition: qsvvpp.c:142
#define av_log(a,...)
This struct is allocated as AVHWDeviceContext.hwctx.
Definition: hwcontext_qsv.h:35
A filter pad used for either input or output.
Definition: internal.h:54
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
int width
Definition: frame.h:376
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
Definition: log.h:194
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:588
void av_frame_free(AVFrame **frame)
Free the frame and any dynamically allocated objects in it, e.g.
Definition: frame.c:204
static mfxStatus frame_unlock(mfxHDL pthis, mfxMemId mid, mfxFrameData *ptr)
#define NULL_IF_CONFIG_SMALL(x)
Return NULL if CONFIG_SMALL is true, otherwise the argument without modification. ...
Definition: internal.h:117
void * priv
private data for use by the filter
Definition: avfilter.h:356
int ff_qsvvpp_print_iopattern(void *log_ctx, int mfx_iopattern, const char *extra_string)
Definition: qsvvpp.c:60
AVFilter ff_vf_deinterlace_qsv
static mfxStatus frame_free(mfxHDL pthis, mfxFrameAllocResponse *resp)
static mfxStatus frame_get_hdl(mfxHDL pthis, mfxMemId mid, mfxHDL *hdl)
#define fail()
Definition: checkasm.h:133
common internal API header
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
AVHWDeviceContext * device_ctx
The parent AVHWDeviceContext.
Definition: hwcontext.h:149
AVFormatContext * ctx
Definition: movenc.c:48
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
#define s(width, name)
Definition: cbs_vp9.c:257
AVBufferRef * hw_frames_ctx
mfxFrameSurface1 surface
Definition: qsv_internal.h:74
static const AVFilterPad outputs[]
Definition: af_acontrast.c:203
static const mfxHandleType handle_types[]
if(ret)
static void clear_unused_frames(QSVDeintContext *s)
static const AVOption options[]
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
uint8_t * data
The data buffer.
Definition: buffer.h:92
struct QSVFrame * next
Definition: qsv_internal.h:82
static mfxStatus frame_alloc(mfxHDL pthis, mfxFrameAllocRequest *req, mfxFrameAllocResponse *resp)
void * hwctx
The format-specific data, allocated and freed automatically along with this context.
Definition: hwcontext.h:162
static int submit_frame(AVFilterContext *ctx, AVFrame *frame, mfxFrameSurface1 **surface)
uint8_t pi<< 24) CONV_FUNC_GROUP(AV_SAMPLE_FMT_FLT, float, AV_SAMPLE_FMT_U8, uint8_t,(*(const uint8_t *) pi-0x80)*(1.0f/(1<< 7))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_DBL, double, AV_SAMPLE_FMT_U8, uint8_t,(*(const uint8_t *) pi-0x80)*(1.0/(1<< 7))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_U8, uint8_t, AV_SAMPLE_FMT_S16, int16_t,(*(const int16_t *) pi >> 8)+0x80) CONV_FUNC_GROUP(AV_SAMPLE_FMT_FLT, float, AV_SAMPLE_FMT_S16, int16_t,*(const int16_t *) pi *(1.0f/(1<< 15))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_DBL, double, AV_SAMPLE_FMT_S16, int16_t,*(const int16_t *) pi *(1.0/(1<< 15))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_U8, uint8_t, AV_SAMPLE_FMT_S32, int32_t,(*(const int32_t *) pi >> 24)+0x80) CONV_FUNC_GROUP(AV_SAMPLE_FMT_FLT, float, AV_SAMPLE_FMT_S32, int32_t,*(const int32_t *) pi *(1.0f/(1U<< 31))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_DBL, double, AV_SAMPLE_FMT_S32, int32_t,*(const int32_t *) pi *(1.0/(1U<< 31))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_U8, uint8_t, AV_SAMPLE_FMT_FLT, float, av_clip_uint8(lrintf(*(const float *) pi *(1<< 7))+0x80)) CONV_FUNC_GROUP(AV_SAMPLE_FMT_S16, int16_t, AV_SAMPLE_FMT_FLT, float, av_clip_int16(lrintf(*(const float *) pi *(1<< 15)))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_S32, int32_t, AV_SAMPLE_FMT_FLT, float, av_clipl_int32(llrintf(*(const float *) pi *(1U<< 31)))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_U8, uint8_t, AV_SAMPLE_FMT_DBL, double, av_clip_uint8(lrint(*(const double *) pi *(1<< 7))+0x80)) CONV_FUNC_GROUP(AV_SAMPLE_FMT_S16, int16_t, AV_SAMPLE_FMT_DBL, double, av_clip_int16(lrint(*(const double *) pi *(1<< 15)))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_S32, int32_t, AV_SAMPLE_FMT_DBL, double, av_clipl_int32(llrint(*(const double *) pi *(1U<< 31))))#define SET_CONV_FUNC_GROUP(ofmt, ifmt) static void set_generic_function(AudioConvert *ac){}void ff_audio_convert_free(AudioConvert **ac){if(!*ac) return;ff_dither_free(&(*ac) ->dc);av_freep(ac);}AudioConvert *ff_audio_convert_alloc(AVAudioResampleContext *avr, enum AVSampleFormat out_fmt, enum AVSampleFormat in_fmt, int channels, int sample_rate, int apply_map){AudioConvert *ac;int in_planar, out_planar;ac=av_mallocz(sizeof(*ac));if(!ac) return NULL;ac->avr=avr;ac->out_fmt=out_fmt;ac->in_fmt=in_fmt;ac->channels=channels;ac->apply_map=apply_map;if(avr->dither_method!=AV_RESAMPLE_DITHER_NONE &&av_get_packed_sample_fmt(out_fmt)==AV_SAMPLE_FMT_S16 &&av_get_bytes_per_sample(in_fmt) > 2){ac->dc=ff_dither_alloc(avr, out_fmt, in_fmt, channels, sample_rate, apply_map);if(!ac->dc){av_free(ac);return NULL;}return ac;}in_planar=ff_sample_fmt_is_planar(in_fmt, channels);out_planar=ff_sample_fmt_is_planar(out_fmt, channels);if(in_planar==out_planar){ac->func_type=CONV_FUNC_TYPE_FLAT;ac->planes=in_planar?ac->channels:1;}else if(in_planar) ac->func_type=CONV_FUNC_TYPE_INTERLEAVE;else ac->func_type=CONV_FUNC_TYPE_DEINTERLEAVE;set_generic_function(ac);if(ARCH_AARCH64) ff_audio_convert_init_aarch64(ac);if(ARCH_ARM) ff_audio_convert_init_arm(ac);if(ARCH_X86) ff_audio_convert_init_x86(ac);return ac;}int ff_audio_convert(AudioConvert *ac, AudioData *out, AudioData *in){int use_generic=1;int len=in->nb_samples;int p;if(ac->dc){av_log(ac->avr, AV_LOG_TRACE,"%d samples - audio_convert: %s to %s (dithered)\n", len, av_get_sample_fmt_name(ac->in_fmt), av_get_sample_fmt_name(ac->out_fmt));return ff_convert_dither(ac-> in
Describe the class of an AVClass context structure.
Definition: log.h:67
Filter definition.
Definition: avfilter.h:145
Rational number (pair of numerator and denominator).
Definition: rational.h:58
This struct describes a set or pool of "hardware" frames (i.e.
Definition: hwcontext.h:124
static const AVFilterPad qsvdeint_outputs[]
HW acceleration through QSV, data[3] contains a pointer to the mfxFrameSurface1 structure.
Definition: pixfmt.h:222
const char * name
Filter name.
Definition: avfilter.h:149
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
AVFilterLink ** outputs
array of pointers to output links
Definition: avfilter.h:353
static enum AVPixelFormat pix_fmts[]
Definition: libkvazaar.c:303
uint8_t * data[AV_NUM_DATA_POINTERS]
pointer to the picture/channel planes.
Definition: frame.h:332
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
mfxFrameSurface1 ** surface_ptrs
QSVFrame * work_frames
A reference to a data buffer.
Definition: buffer.h:84
common internal and external API header
int ff_qsvvpp_print_error(void *log_ctx, mfxStatus err, const char *error_string)
Definition: qsvvpp.c:132
AVBufferRef * av_buffer_ref(AVBufferRef *buf)
Create a new reference to an AVBuffer.
Definition: buffer.c:93
int den
Denominator.
Definition: rational.h:60
#define AVERROR_UNKNOWN
Unknown error, typically from an external library.
Definition: error.h:71
int top_field_first
If the content is interlaced, is top field displayed first.
Definition: frame.h:470
mfxExtOpaqueSurfaceAlloc opaque_alloc
mfxExtBuffer * ext_buffers[2]
A list of supported formats for one end of a filter link.
Definition: formats.h:65
An instance of a filter.
Definition: avfilter.h:341
AVRational av_mul_q(AVRational b, AVRational c)
Multiply two rationals.
Definition: rational.c:80
Intel Quick Sync Video VPP base function.
int height
Definition: frame.h:376
FILE * out
Definition: movenc.c:54
#define av_freep(p)
An API-specific header for AV_HWDEVICE_TYPE_QSV.
AVFrame * frame
Definition: qsv_internal.h:73
int ff_request_frame(AVFilterLink *link)
Request an input frame from the filter at the other end of the link.
Definition: avfilter.c:408
internal API functions
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
AVPixelFormat
Pixel format.
Definition: pixfmt.h:64
static int init_out_session(AVFilterContext *ctx)
mode
Use these values in ebur128_init (or&#39;ed).
Definition: ebur128.h:83
int av_frame_copy_props(AVFrame *dst, const AVFrame *src)
Copy only "metadata" fields from src to dst.
Definition: frame.c:659
int i
Definition: input.c:407
#define AV_NOPTS_VALUE
Undefined timestamp value.
Definition: avutil.h:248
void * av_mallocz_array(size_t nmemb, size_t size)
Definition: mem.c:190