FFmpeg
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
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 QSVFrame {
51  AVFrame *frame;
52  mfxFrameSurface1 surface;
53  int used;
54 
55  struct QSVFrame *next;
56 } QSVFrame;
57 
58 typedef struct QSVDeintContext {
59  const AVClass *class;
60 
62  /* a clone of the main session, used internally for deinterlacing */
63  mfxSession session;
64 
65  mfxMemId *mem_ids;
67 
68  mfxFrameSurface1 **surface_ptrs;
70 
71  mfxExtOpaqueSurfaceAlloc opaque_alloc;
72  mfxExtVPPDeinterlacing deint_conf;
73  mfxExtBuffer *ext_buffers[2];
75 
77 
78  int64_t last_pts;
79 
80  int eof;
81 
82  /* option for Deinterlacing algorithm to be used */
83  int mode;
85 
87 {
88  QSVDeintContext *s = ctx->priv;
89  QSVFrame *cur;
90 
91  if (s->session) {
92  MFXClose(s->session);
93  s->session = NULL;
94  }
96 
97  cur = s->work_frames;
98  while (cur) {
99  s->work_frames = cur->next;
100  av_frame_free(&cur->frame);
101  av_freep(&cur);
102  cur = s->work_frames;
103  }
104 
105  av_freep(&s->mem_ids);
106  s->nb_mem_ids = 0;
107 
108  av_freep(&s->surface_ptrs);
109  s->nb_surface_ptrs = 0;
110 }
111 
113 {
114  static const enum AVPixelFormat pixel_formats[] = {
116  };
117  AVFilterFormats *pix_fmts = ff_make_format_list(pixel_formats);
118  int ret;
119 
120  if ((ret = ff_set_common_formats(ctx, pix_fmts)) < 0)
121  return ret;
122 
123  return 0;
124 }
125 
126 static mfxStatus frame_alloc(mfxHDL pthis, mfxFrameAllocRequest *req,
127  mfxFrameAllocResponse *resp)
128 {
129  AVFilterContext *ctx = pthis;
130  QSVDeintContext *s = ctx->priv;
131 
132  if (!(req->Type & MFX_MEMTYPE_VIDEO_MEMORY_PROCESSOR_TARGET) ||
133  !(req->Type & (MFX_MEMTYPE_FROM_VPPIN | MFX_MEMTYPE_FROM_VPPOUT)) ||
134  !(req->Type & MFX_MEMTYPE_EXTERNAL_FRAME))
135  return MFX_ERR_UNSUPPORTED;
136 
137  resp->mids = s->mem_ids;
138  resp->NumFrameActual = s->nb_mem_ids;
139 
140  return MFX_ERR_NONE;
141 }
142 
143 static mfxStatus frame_free(mfxHDL pthis, mfxFrameAllocResponse *resp)
144 {
145  return MFX_ERR_NONE;
146 }
147 
148 static mfxStatus frame_lock(mfxHDL pthis, mfxMemId mid, mfxFrameData *ptr)
149 {
150  return MFX_ERR_UNSUPPORTED;
151 }
152 
153 static mfxStatus frame_unlock(mfxHDL pthis, mfxMemId mid, mfxFrameData *ptr)
154 {
155  return MFX_ERR_UNSUPPORTED;
156 }
157 
158 static mfxStatus frame_get_hdl(mfxHDL pthis, mfxMemId mid, mfxHDL *hdl)
159 {
160  *hdl = mid;
161  return MFX_ERR_NONE;
162 }
163 
164 static const mfxHandleType handle_types[] = {
165  MFX_HANDLE_VA_DISPLAY,
166  MFX_HANDLE_D3D9_DEVICE_MANAGER,
167  MFX_HANDLE_D3D11_DEVICE,
168 };
169 
171 {
172 
173  QSVDeintContext *s = ctx->priv;
174  AVHWFramesContext *hw_frames_ctx = (AVHWFramesContext*)s->hw_frames_ctx->data;
175  AVQSVFramesContext *hw_frames_hwctx = hw_frames_ctx->hwctx;
176  AVQSVDeviceContext *device_hwctx = hw_frames_ctx->device_ctx->hwctx;
177 
178  int opaque = !!(hw_frames_hwctx->frame_type & MFX_MEMTYPE_OPAQUE_FRAME);
179 
180  mfxHDL handle = NULL;
181  mfxHandleType handle_type;
182  mfxVersion ver;
183  mfxIMPL impl;
184  mfxVideoParam par;
185  mfxStatus err;
186  int i;
187 
188  /* extract the properties of the "master" session given to us */
189  err = MFXQueryIMPL(device_hwctx->session, &impl);
190  if (err == MFX_ERR_NONE)
191  err = MFXQueryVersion(device_hwctx->session, &ver);
192  if (err != MFX_ERR_NONE) {
193  av_log(ctx, AV_LOG_ERROR, "Error querying the session attributes\n");
194  return AVERROR_UNKNOWN;
195  }
196 
197  for (i = 0; i < FF_ARRAY_ELEMS(handle_types); i++) {
198  err = MFXVideoCORE_GetHandle(device_hwctx->session, handle_types[i], &handle);
199  if (err == MFX_ERR_NONE) {
200  handle_type = handle_types[i];
201  break;
202  }
203  }
204 
205  /* create a "slave" session with those same properties, to be used for
206  * actual deinterlacing */
207  err = MFXInit(impl, &ver, &s->session);
208  if (err != MFX_ERR_NONE) {
209  av_log(ctx, AV_LOG_ERROR, "Error initializing a session for deinterlacing\n");
210  return AVERROR_UNKNOWN;
211  }
212 
213  if (handle) {
214  err = MFXVideoCORE_SetHandle(s->session, handle_type, handle);
215  if (err != MFX_ERR_NONE)
216  return AVERROR_UNKNOWN;
217  }
218 
219  if (QSV_RUNTIME_VERSION_ATLEAST(ver, 1, 25)) {
220  err = MFXJoinSession(device_hwctx->session, s->session);
221  if (err != MFX_ERR_NONE)
222  return AVERROR_UNKNOWN;
223  }
224 
225  memset(&par, 0, sizeof(par));
226 
227  s->deint_conf.Header.BufferId = MFX_EXTBUFF_VPP_DEINTERLACING;
228  s->deint_conf.Header.BufferSz = sizeof(s->deint_conf);
229  s->deint_conf.Mode = s->mode;
230 
231  s->ext_buffers[s->num_ext_buffers++] = (mfxExtBuffer *)&s->deint_conf;
232 
233  if (opaque) {
234  s->surface_ptrs = av_mallocz_array(hw_frames_hwctx->nb_surfaces,
235  sizeof(*s->surface_ptrs));
236  if (!s->surface_ptrs)
237  return AVERROR(ENOMEM);
238  for (i = 0; i < hw_frames_hwctx->nb_surfaces; i++)
239  s->surface_ptrs[i] = hw_frames_hwctx->surfaces + i;
240  s->nb_surface_ptrs = hw_frames_hwctx->nb_surfaces;
241 
242  s->opaque_alloc.In.Surfaces = s->surface_ptrs;
243  s->opaque_alloc.In.NumSurface = s->nb_surface_ptrs;
244  s->opaque_alloc.In.Type = hw_frames_hwctx->frame_type;
245 
246  s->opaque_alloc.Out = s->opaque_alloc.In;
247 
248  s->opaque_alloc.Header.BufferId = MFX_EXTBUFF_OPAQUE_SURFACE_ALLOCATION;
249  s->opaque_alloc.Header.BufferSz = sizeof(s->opaque_alloc);
250 
251  s->ext_buffers[s->num_ext_buffers++] = (mfxExtBuffer *)&s->opaque_alloc;
252 
253  par.IOPattern = MFX_IOPATTERN_IN_OPAQUE_MEMORY | MFX_IOPATTERN_OUT_OPAQUE_MEMORY;
254  } else {
255  mfxFrameAllocator frame_allocator = {
256  .pthis = ctx,
257  .Alloc = frame_alloc,
258  .Lock = frame_lock,
259  .Unlock = frame_unlock,
260  .GetHDL = frame_get_hdl,
261  .Free = frame_free,
262  };
263 
264  s->mem_ids = av_mallocz_array(hw_frames_hwctx->nb_surfaces,
265  sizeof(*s->mem_ids));
266  if (!s->mem_ids)
267  return AVERROR(ENOMEM);
268  for (i = 0; i < hw_frames_hwctx->nb_surfaces; i++)
269  s->mem_ids[i] = hw_frames_hwctx->surfaces[i].Data.MemId;
270  s->nb_mem_ids = hw_frames_hwctx->nb_surfaces;
271 
272  err = MFXVideoCORE_SetFrameAllocator(s->session, &frame_allocator);
273  if (err != MFX_ERR_NONE)
274  return AVERROR_UNKNOWN;
275 
276  par.IOPattern = MFX_IOPATTERN_IN_VIDEO_MEMORY | MFX_IOPATTERN_OUT_VIDEO_MEMORY;
277  }
278 
279  par.ExtParam = s->ext_buffers;
280  par.NumExtParam = s->num_ext_buffers;
281 
282  par.AsyncDepth = 1; // TODO async
283 
284  par.vpp.In = hw_frames_hwctx->surfaces[0].Info;
285 
286  par.vpp.In.CropW = ctx->inputs[0]->w;
287  par.vpp.In.CropH = ctx->inputs[0]->h;
288 
289  if (ctx->inputs[0]->frame_rate.num) {
290  par.vpp.In.FrameRateExtN = ctx->inputs[0]->frame_rate.num;
291  par.vpp.In.FrameRateExtD = ctx->inputs[0]->frame_rate.den;
292  } else {
293  par.vpp.In.FrameRateExtN = ctx->inputs[0]->time_base.num;
294  par.vpp.In.FrameRateExtD = ctx->inputs[0]->time_base.den;
295  }
296 
297  par.vpp.Out = par.vpp.In;
298 
299  if (ctx->outputs[0]->frame_rate.num) {
300  par.vpp.Out.FrameRateExtN = ctx->outputs[0]->frame_rate.num;
301  par.vpp.Out.FrameRateExtD = ctx->outputs[0]->frame_rate.den;
302  } else {
303  par.vpp.Out.FrameRateExtN = ctx->outputs[0]->time_base.num;
304  par.vpp.Out.FrameRateExtD = ctx->outputs[0]->time_base.den;
305  }
306 
307  err = MFXVideoVPP_Init(s->session, &par);
308  if (err != MFX_ERR_NONE) {
309  av_log(ctx, AV_LOG_ERROR, "Error opening the VPP for deinterlacing: %d\n", err);
310  return AVERROR_UNKNOWN;
311  }
312 
313  return 0;
314 }
315 
317 {
318  AVFilterContext *ctx = outlink->src;
319  AVFilterLink *inlink = ctx->inputs[0];
320  QSVDeintContext *s = ctx->priv;
321  int ret;
322 
323  qsvdeint_uninit(ctx);
324 
326  outlink->frame_rate = av_mul_q(inlink->frame_rate,
327  (AVRational){ 2, 1 });
328  outlink->time_base = av_mul_q(inlink->time_base,
329  (AVRational){ 1, 2 });
330 
331  /* check that we have a hw context */
332  if (!inlink->hw_frames_ctx) {
333  av_log(ctx, AV_LOG_ERROR, "No hw context provided on input\n");
334  return AVERROR(EINVAL);
335  }
336 
337  s->hw_frames_ctx = av_buffer_ref(inlink->hw_frames_ctx);
338  if (!s->hw_frames_ctx)
339  return AVERROR(ENOMEM);
340 
341  av_buffer_unref(&outlink->hw_frames_ctx);
342  outlink->hw_frames_ctx = av_buffer_ref(inlink->hw_frames_ctx);
343  if (!outlink->hw_frames_ctx) {
345  return AVERROR(ENOMEM);
346  }
347 
348  ret = init_out_session(ctx);
349  if (ret < 0)
350  return ret;
351 
352 
353  return 0;
354 }
355 
357 {
358  QSVFrame *cur = s->work_frames;
359  while (cur) {
360  if (!cur->surface.Data.Locked) {
361  av_frame_free(&cur->frame);
362  cur->used = 0;
363  }
364  cur = cur->next;
365  }
366 }
367 
369 {
370  QSVFrame *frame, **last;
371 
373 
374  frame = s->work_frames;
375  last = &s->work_frames;
376  while (frame) {
377  if (!frame->used) {
378  *f = frame;
379  return 0;
380  }
381 
382  last = &frame->next;
383  frame = frame->next;
384  }
385 
386  frame = av_mallocz(sizeof(*frame));
387  if (!frame)
388  return AVERROR(ENOMEM);
389  *last = frame;
390  *f = frame;
391 
392  return 0;
393 }
394 
396  mfxFrameSurface1 **surface)
397 {
398  QSVDeintContext *s = ctx->priv;
399  QSVFrame *qf;
400  int ret;
401 
402  ret = get_free_frame(s, &qf);
403  if (ret < 0)
404  return ret;
405 
406  qf->frame = frame;
407 
408  qf->surface = *(mfxFrameSurface1*)qf->frame->data[3];
409 
410  qf->surface.Data.Locked = 0;
411  qf->surface.Info.CropW = qf->frame->width;
412  qf->surface.Info.CropH = qf->frame->height;
413 
414  qf->surface.Info.PicStruct = !qf->frame->interlaced_frame ? MFX_PICSTRUCT_PROGRESSIVE :
415  (qf->frame->top_field_first ? MFX_PICSTRUCT_FIELD_TFF :
416  MFX_PICSTRUCT_FIELD_BFF);
417  if (qf->frame->repeat_pict == 1)
418  qf->surface.Info.PicStruct |= MFX_PICSTRUCT_FIELD_REPEATED;
419  else if (qf->frame->repeat_pict == 2)
420  qf->surface.Info.PicStruct |= MFX_PICSTRUCT_FRAME_DOUBLING;
421  else if (qf->frame->repeat_pict == 4)
422  qf->surface.Info.PicStruct |= MFX_PICSTRUCT_FRAME_TRIPLING;
423 
424  if (ctx->inputs[0]->frame_rate.num) {
425  qf->surface.Info.FrameRateExtN = ctx->inputs[0]->frame_rate.num;
426  qf->surface.Info.FrameRateExtD = ctx->inputs[0]->frame_rate.den;
427  } else {
428  qf->surface.Info.FrameRateExtN = ctx->inputs[0]->time_base.num;
429  qf->surface.Info.FrameRateExtD = ctx->inputs[0]->time_base.den;
430  }
431 
432  qf->surface.Data.TimeStamp = av_rescale_q(qf->frame->pts,
433  ctx->inputs[0]->time_base,
434  (AVRational){1, 90000});
435 
436  *surface = &qf->surface;
437  qf->used = 1;
438 
439  return 0;
440 }
441 
443  mfxFrameSurface1 *surf_in)
444 {
445  QSVDeintContext *s = ctx->priv;
446  AVFilterLink *inlink = ctx->inputs[0];
447  AVFilterLink *outlink = ctx->outputs[0];
448 
449  AVFrame *out;
450  mfxFrameSurface1 *surf_out;
451  mfxSyncPoint sync = NULL;
452  mfxStatus err;
453  int ret, again = 0;
454 
455  out = ff_get_video_buffer(outlink, outlink->w, outlink->h);
456  if (!out) {
457  ret = AVERROR(ENOMEM);
458  goto fail;
459  }
460 
461  surf_out = (mfxFrameSurface1*)out->data[3];
462  surf_out->Info.CropW = outlink->w;
463  surf_out->Info.CropH = outlink->h;
464  surf_out->Info.PicStruct = MFX_PICSTRUCT_PROGRESSIVE;
465 
466  do {
467  err = MFXVideoVPP_RunFrameVPPAsync(s->session, surf_in, surf_out,
468  NULL, &sync);
469  if (err == MFX_WRN_DEVICE_BUSY)
470  av_usleep(1);
471  } while (err == MFX_WRN_DEVICE_BUSY);
472 
473  if (err == MFX_ERR_MORE_DATA) {
474  av_frame_free(&out);
475  return QSVDEINT_MORE_INPUT;
476  }
477 
478  if ((err < 0 && err != MFX_ERR_MORE_SURFACE) || !sync) {
479  av_log(ctx, AV_LOG_ERROR, "Error during deinterlacing: %d\n", err);
480  ret = AVERROR_UNKNOWN;
481  goto fail;
482  }
483  if (err == MFX_ERR_MORE_SURFACE)
484  again = 1;
485 
486  do {
487  err = MFXVideoCORE_SyncOperation(s->session, sync, 1000);
488  } while (err == MFX_WRN_IN_EXECUTION);
489  if (err < 0) {
490  av_log(ctx, AV_LOG_ERROR, "Error synchronizing the operation: %d\n", err);
491  ret = AVERROR_UNKNOWN;
492  goto fail;
493  }
494 
495  ret = av_frame_copy_props(out, in);
496  if (ret < 0)
497  goto fail;
498 
499  out->width = outlink->w;
500  out->height = outlink->h;
501  out->interlaced_frame = 0;
502 
503  out->pts = av_rescale_q(out->pts, inlink->time_base, outlink->time_base);
504  if (out->pts == s->last_pts)
505  out->pts++;
506  s->last_pts = out->pts;
507 
508  ret = ff_filter_frame(outlink, out);
509  if (ret < 0)
510  return ret;
511 
512  return again ? QSVDEINT_MORE_OUTPUT : 0;
513 fail:
514  av_frame_free(&out);
515  return ret;
516 }
517 
519 {
520  AVFilterContext *ctx = link->dst;
521 
522  mfxFrameSurface1 *surf_in;
523  int ret;
524 
525  ret = submit_frame(ctx, in, &surf_in);
526  if (ret < 0) {
527  av_frame_free(&in);
528  return ret;
529  }
530 
531  do {
532  ret = process_frame(ctx, in, surf_in);
533  if (ret < 0)
534  return ret;
535  } while (ret == QSVDEINT_MORE_OUTPUT);
536 
537  return 0;
538 }
539 
541 {
542  AVFilterContext *ctx = outlink->src;
543 
544  return ff_request_frame(ctx->inputs[0]);
545 }
546 
547 #define OFFSET(x) offsetof(QSVDeintContext, x)
548 #define FLAGS AV_OPT_FLAG_VIDEO_PARAM|AV_OPT_FLAG_FILTERING_PARAM
549 static const AVOption options[] = {
550  { "mode", "set deinterlace mode", OFFSET(mode), AV_OPT_TYPE_INT, {.i64 = MFX_DEINTERLACING_ADVANCED}, MFX_DEINTERLACING_BOB, MFX_DEINTERLACING_ADVANCED, FLAGS, "mode"},
551  { "bob", "bob algorithm", 0, AV_OPT_TYPE_CONST, {.i64 = MFX_DEINTERLACING_BOB}, MFX_DEINTERLACING_BOB, MFX_DEINTERLACING_ADVANCED, FLAGS, "mode"},
552  { "advanced", "Motion adaptive algorithm", 0, AV_OPT_TYPE_CONST, {.i64 = MFX_DEINTERLACING_ADVANCED}, MFX_DEINTERLACING_BOB, MFX_DEINTERLACING_ADVANCED, FLAGS, "mode"},
553  { NULL },
554 };
555 
556 static const AVClass qsvdeint_class = {
557  .class_name = "deinterlace_qsv",
558  .item_name = av_default_item_name,
559  .option = options,
560  .version = LIBAVUTIL_VERSION_INT,
561 };
562 
563 static const AVFilterPad qsvdeint_inputs[] = {
564  {
565  .name = "default",
566  .type = AVMEDIA_TYPE_VIDEO,
567  .filter_frame = qsvdeint_filter_frame,
568  },
569  { NULL }
570 };
571 
572 static const AVFilterPad qsvdeint_outputs[] = {
573  {
574  .name = "default",
575  .type = AVMEDIA_TYPE_VIDEO,
576  .config_props = qsvdeint_config_props,
577  .request_frame = qsvdeint_request_frame,
578  },
579  { NULL }
580 };
581 
583  .name = "deinterlace_qsv",
584  .description = NULL_IF_CONFIG_SMALL("QuickSync video deinterlacing"),
585 
586  .uninit = qsvdeint_uninit,
587  .query_formats = qsvdeint_query_formats,
588 
589  .priv_size = sizeof(QSVDeintContext),
590  .priv_class = &qsvdeint_class,
591 
592  .inputs = qsvdeint_inputs,
593  .outputs = qsvdeint_outputs,
594 
595  .flags_internal = FF_FILTER_FLAG_HWFRAME_AWARE,
596 };
#define NULL
Definition: coverity.c:32
#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:385
const char * s
Definition: avisynth_c.h:768
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:218
AVOption.
Definition: opt.h:246
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:75
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:360
const char * av_default_item_name(void *ptr)
Return the context name.
Definition: log.c:191
#define FLAGS
#define QSV_RUNTIME_VERSION_ATLEAST(MFX_VERSION, MAJOR, MINOR)
Definition: qsv_internal.h:41
void * av_mallocz(size_t size)
Allocate a memory block with alignment suitable for all memory accesses (including vectors if availab...
Definition: mem.c:236
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:283
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:346
int ff_filter_frame(AVFilterLink *link, AVFrame *frame)
Send a frame of data to the next filter.
Definition: avfilter.c:1080
#define OFFSET(x)
AVOptions.
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:311
static void qsvdeint_uninit(AVFilterContext *ctx)
static int qsvdeint_config_props(AVFilterLink *outlink)
static AVFrame * frame
void * hwctx
The format-specific data, allocated and freed by libavutil along with this context.
Definition: hwcontext.h:91
static int qsvdeint_filter_frame(AVFilterLink *link, AVFrame *in)
int interlaced_frame
The content of the picture is interlaced.
Definition: frame.h:365
static mfxStatus frame_lock(mfxHDL pthis, mfxMemId mid, mfxFrameData *ptr)
#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:276
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
Definition: log.h:176
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:568
#define AVERROR(e)
Definition: error.h:43
void av_frame_free(AVFrame **frame)
Free the frame and any dynamically allocated objects in it, e.g.
Definition: frame.c:202
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:186
void * priv
private data for use by the filter
Definition: avfilter.h:353
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:116
common internal API header
AVHWDeviceContext * device_ctx
The parent AVHWDeviceContext.
Definition: hwcontext.h:148
AVFormatContext * ctx
Definition: movenc.c:48
AVBufferRef * hw_frames_ctx
mfxFrameSurface1 surface
Definition: qsv_internal.h:56
static const AVFilterPad inputs[]
Definition: af_acontrast.c:193
static const AVFilterPad outputs[]
Definition: af_acontrast.c:203
#define FF_ARRAY_ELEMS(a)
static const mfxHandleType handle_types[]
static void clear_unused_frames(QSVDeintContext *s)
static const AVOption options[]
uint8_t * data
The data buffer.
Definition: buffer.h:89
struct QSVFrame * next
Definition: qsv_internal.h:64
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:161
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,(*(constuint8_t *) pi-0x80)*(1.0f/(1<< 7))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_DBL, double, AV_SAMPLE_FMT_U8, uint8_t,(*(constuint8_t *) pi-0x80)*(1.0/(1<< 7))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_U8, uint8_t, AV_SAMPLE_FMT_S16, int16_t,(*(constint16_t *) pi >>8)+0x80) CONV_FUNC_GROUP(AV_SAMPLE_FMT_FLT, float, AV_SAMPLE_FMT_S16, int16_t,*(constint16_t *) pi *(1.0f/(1<< 15))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_DBL, double, AV_SAMPLE_FMT_S16, int16_t,*(constint16_t *) pi *(1.0/(1<< 15))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_U8, uint8_t, AV_SAMPLE_FMT_S32, int32_t,(*(constint32_t *) pi >>24)+0x80) CONV_FUNC_GROUP(AV_SAMPLE_FMT_FLT, float, AV_SAMPLE_FMT_S32, int32_t,*(constint32_t *) pi *(1.0f/(1U<< 31))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_DBL, double, AV_SAMPLE_FMT_S32, int32_t,*(constint32_t *) pi *(1.0/(1U<< 31))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_U8, uint8_t, AV_SAMPLE_FMT_FLT, float, av_clip_uint8(lrintf(*(constfloat *) pi *(1<< 7))+0x80)) CONV_FUNC_GROUP(AV_SAMPLE_FMT_S16, int16_t, AV_SAMPLE_FMT_FLT, float, av_clip_int16(lrintf(*(constfloat *) pi *(1<< 15)))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_S32, int32_t, AV_SAMPLE_FMT_FLT, float, av_clipl_int32(llrintf(*(constfloat *) pi *(1U<< 31)))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_U8, uint8_t, AV_SAMPLE_FMT_DBL, double, av_clip_uint8(lrint(*(constdouble *) pi *(1<< 7))+0x80)) CONV_FUNC_GROUP(AV_SAMPLE_FMT_S16, int16_t, AV_SAMPLE_FMT_DBL, double, av_clip_int16(lrint(*(constdouble *) pi *(1<< 15)))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_S32, int32_t, AV_SAMPLE_FMT_DBL, double, av_clipl_int32(llrint(*(constdouble *) pi *(1U<< 31))))#defineSET_CONV_FUNC_GROUP(ofmt, ifmt) staticvoidset_generic_function(AudioConvert *ac){}voidff_audio_convert_free(AudioConvert **ac){if(!*ac) return;ff_dither_free(&(*ac) ->dc);av_freep(ac);}AudioConvert *ff_audio_convert_alloc(AVAudioResampleContext *avr, enumAVSampleFormatout_fmt, enumAVSampleFormatin_fmt, intchannels, intsample_rate, intapply_map){AudioConvert *ac;intin_planar, out_planar;ac=av_mallocz(sizeof(*ac));if(!ac) returnNULL;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);returnNULL;}returnac;}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;}elseif(in_planar) ac->func_type=CONV_FUNC_TYPE_INTERLEAVE;elseac->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);returnac;}intff_audio_convert(AudioConvert *ac, AudioData *out, AudioData *in){intuse_generic=1;intlen=in->nb_samples;intp;if(ac->dc){av_log(ac->avr, AV_LOG_TRACE,"%dsamples-audio_convert:%sto%s(dithered)\n", len, av_get_sample_fmt_name(ac->in_fmt), av_get_sample_fmt_name(ac->out_fmt));returnff_convert_dither(ac-> in
Describe the class of an AVClass context structure.
Definition: log.h:67
Filter definition.
Definition: avfilter.h:144
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:123
static const AVFilterPad qsvdeint_outputs[]
HW acceleration through QSV, data[3] contains a pointer to the mfxFrameSurface1 structure.
Definition: pixfmt.h:218
const char * name
Filter name.
Definition: avfilter.h:148
AVFilterLink ** outputs
array of pointers to output links
Definition: avfilter.h:350
static enum AVPixelFormat pix_fmts[]
Definition: libkvazaar.c:266
uint8_t * data[AV_NUM_DATA_POINTERS]
pointer to the picture/channel planes.
Definition: frame.h:232
mfxFrameSurface1 ** surface_ptrs
QSVFrame * work_frames
A reference to a data buffer.
Definition: buffer.h:81
common internal and external API header
if(ret< 0)
Definition: vf_mcdeint.c:279
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:370
mfxExtOpaqueSurfaceAlloc opaque_alloc
mfxExtBuffer * ext_buffers[2]
A list of supported formats for one end of a filter link.
Definition: formats.h:64
An instance of a filter.
Definition: avfilter.h:338
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:276
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:55
int ff_request_frame(AVFilterLink *link)
Request an input frame from the filter at the other end of the link.
Definition: avfilter.c:407
internal API functions
AVPixelFormat
Pixel format.
Definition: pixfmt.h:60
static int init_out_session(AVFilterContext *ctx)
mode
Use these values in ebur128_init (or'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:652
#define AV_NOPTS_VALUE
Undefined timestamp value.
Definition: avutil.h:248
void * av_mallocz_array(size_t nmemb, size_t size)
Definition: mem.c:191