FFmpeg  4.4.5
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 
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  }
95  av_buffer_unref(&s->hw_frames_ctx);
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) {
201  break;
202  }
203  }
204 
205  if (err < 0)
206  return ff_qsvvpp_print_error(ctx, err, "Error getting the session handle");
207  else if (err > 0) {
208  ff_qsvvpp_print_warning(ctx, err, "Warning in getting the session handle");
209  return AVERROR_UNKNOWN;
210  }
211 
212  /* create a "slave" session with those same properties, to be used for
213  * actual deinterlacing */
214  err = MFXInit(impl, &ver, &s->session);
215  if (err < 0)
216  return ff_qsvvpp_print_error(ctx, err, "Error initializing a session for deinterlacing");
217  else if (err > 0) {
218  ff_qsvvpp_print_warning(ctx, err, "Warning in session initialization");
219  return AVERROR_UNKNOWN;
220  }
221 
222  if (handle) {
223  err = MFXVideoCORE_SetHandle(s->session, handle_type, handle);
224  if (err != MFX_ERR_NONE)
225  return AVERROR_UNKNOWN;
226  }
227 
228  if (QSV_RUNTIME_VERSION_ATLEAST(ver, 1, 25)) {
229  err = MFXJoinSession(device_hwctx->session, s->session);
230  if (err != MFX_ERR_NONE)
231  return AVERROR_UNKNOWN;
232  }
233 
234  memset(&par, 0, sizeof(par));
235 
236  s->deint_conf.Header.BufferId = MFX_EXTBUFF_VPP_DEINTERLACING;
237  s->deint_conf.Header.BufferSz = sizeof(s->deint_conf);
238  s->deint_conf.Mode = s->mode;
239 
240  s->ext_buffers[s->num_ext_buffers++] = (mfxExtBuffer *)&s->deint_conf;
241 
242  if (opaque) {
243  s->surface_ptrs = av_mallocz_array(hw_frames_hwctx->nb_surfaces,
244  sizeof(*s->surface_ptrs));
245  if (!s->surface_ptrs)
246  return AVERROR(ENOMEM);
247  for (i = 0; i < hw_frames_hwctx->nb_surfaces; i++)
248  s->surface_ptrs[i] = hw_frames_hwctx->surfaces + i;
249  s->nb_surface_ptrs = hw_frames_hwctx->nb_surfaces;
250 
251  s->opaque_alloc.In.Surfaces = s->surface_ptrs;
252  s->opaque_alloc.In.NumSurface = s->nb_surface_ptrs;
253  s->opaque_alloc.In.Type = hw_frames_hwctx->frame_type;
254 
255  s->opaque_alloc.Out = s->opaque_alloc.In;
256 
257  s->opaque_alloc.Header.BufferId = MFX_EXTBUFF_OPAQUE_SURFACE_ALLOCATION;
258  s->opaque_alloc.Header.BufferSz = sizeof(s->opaque_alloc);
259 
260  s->ext_buffers[s->num_ext_buffers++] = (mfxExtBuffer *)&s->opaque_alloc;
261 
262  par.IOPattern = MFX_IOPATTERN_IN_OPAQUE_MEMORY | MFX_IOPATTERN_OUT_OPAQUE_MEMORY;
263  } else {
264  mfxFrameAllocator frame_allocator = {
265  .pthis = ctx,
266  .Alloc = frame_alloc,
267  .Lock = frame_lock,
268  .Unlock = frame_unlock,
269  .GetHDL = frame_get_hdl,
270  .Free = frame_free,
271  };
272 
273  s->mem_ids = av_mallocz_array(hw_frames_hwctx->nb_surfaces,
274  sizeof(*s->mem_ids));
275  if (!s->mem_ids)
276  return AVERROR(ENOMEM);
277  for (i = 0; i < hw_frames_hwctx->nb_surfaces; i++)
278  s->mem_ids[i] = hw_frames_hwctx->surfaces[i].Data.MemId;
279  s->nb_mem_ids = hw_frames_hwctx->nb_surfaces;
280 
281  err = MFXVideoCORE_SetFrameAllocator(s->session, &frame_allocator);
282  if (err != MFX_ERR_NONE)
283  return AVERROR_UNKNOWN;
284 
285  par.IOPattern = MFX_IOPATTERN_IN_VIDEO_MEMORY | MFX_IOPATTERN_OUT_VIDEO_MEMORY;
286  }
287 
288  par.ExtParam = s->ext_buffers;
289  par.NumExtParam = s->num_ext_buffers;
290 
291  par.AsyncDepth = 1; // TODO async
292 
293  par.vpp.In = hw_frames_hwctx->surfaces[0].Info;
294 
295  par.vpp.In.CropW = ctx->inputs[0]->w;
296  par.vpp.In.CropH = ctx->inputs[0]->h;
297 
298  if (ctx->inputs[0]->frame_rate.num) {
299  par.vpp.In.FrameRateExtN = ctx->inputs[0]->frame_rate.num;
300  par.vpp.In.FrameRateExtD = ctx->inputs[0]->frame_rate.den;
301  } else {
302  par.vpp.In.FrameRateExtN = ctx->inputs[0]->time_base.num;
303  par.vpp.In.FrameRateExtD = ctx->inputs[0]->time_base.den;
304  }
305 
306  par.vpp.Out = par.vpp.In;
307 
308  if (ctx->outputs[0]->frame_rate.num) {
309  par.vpp.Out.FrameRateExtN = ctx->outputs[0]->frame_rate.num;
310  par.vpp.Out.FrameRateExtD = ctx->outputs[0]->frame_rate.den;
311  } else {
312  par.vpp.Out.FrameRateExtN = ctx->outputs[0]->time_base.num;
313  par.vpp.Out.FrameRateExtD = ctx->outputs[0]->time_base.den;
314  }
315 
316  /* Print input memory mode */
317  ff_qsvvpp_print_iopattern(ctx, par.IOPattern & 0x0F, "VPP");
318  /* Print output memory mode */
319  ff_qsvvpp_print_iopattern(ctx, par.IOPattern & 0xF0, "VPP");
320  err = MFXVideoVPP_Init(s->session, &par);
321  if (err < 0)
322  return ff_qsvvpp_print_error(ctx, err,
323  "Error opening the VPP for deinterlacing");
324  else if (err > 0) {
326  "Warning in VPP initialization");
327  return AVERROR_UNKNOWN;
328  }
329 
330  return 0;
331 }
332 
334 {
335  AVFilterContext *ctx = outlink->src;
336  AVFilterLink *inlink = ctx->inputs[0];
337  QSVDeintContext *s = ctx->priv;
338  int ret;
339 
341 
342  s->last_pts = AV_NOPTS_VALUE;
343  outlink->frame_rate = av_mul_q(inlink->frame_rate,
344  (AVRational){ 2, 1 });
345  outlink->time_base = av_mul_q(inlink->time_base,
346  (AVRational){ 1, 2 });
347 
348  /* check that we have a hw context */
349  if (!inlink->hw_frames_ctx) {
350  av_log(ctx, AV_LOG_ERROR, "No hw context provided on input\n");
351  return AVERROR(EINVAL);
352  }
353 
354  s->hw_frames_ctx = av_buffer_ref(inlink->hw_frames_ctx);
355  if (!s->hw_frames_ctx)
356  return AVERROR(ENOMEM);
357 
358  av_buffer_unref(&outlink->hw_frames_ctx);
359  outlink->hw_frames_ctx = av_buffer_ref(inlink->hw_frames_ctx);
360  if (!outlink->hw_frames_ctx) {
362  return AVERROR(ENOMEM);
363  }
364 
365  ret = init_out_session(ctx);
366  if (ret < 0)
367  return ret;
368 
369 
370  return 0;
371 }
372 
374 {
375  QSVFrame *cur = s->work_frames;
376  while (cur) {
377  if (!cur->surface.Data.Locked) {
378  av_frame_free(&cur->frame);
379  cur->used = 0;
380  }
381  cur = cur->next;
382  }
383 }
384 
386 {
387  QSVFrame *frame, **last;
388 
390 
391  frame = s->work_frames;
392  last = &s->work_frames;
393  while (frame) {
394  if (!frame->used) {
395  *f = frame;
396  return 0;
397  }
398 
399  last = &frame->next;
400  frame = frame->next;
401  }
402 
403  frame = av_mallocz(sizeof(*frame));
404  if (!frame)
405  return AVERROR(ENOMEM);
406  *last = frame;
407  *f = frame;
408 
409  return 0;
410 }
411 
413  mfxFrameSurface1 **surface)
414 {
415  QSVDeintContext *s = ctx->priv;
416  QSVFrame *qf;
417  int ret;
418 
419  ret = get_free_frame(s, &qf);
420  if (ret < 0)
421  return ret;
422 
423  qf->frame = frame;
424 
425  qf->surface = *(mfxFrameSurface1*)qf->frame->data[3];
426 
427  qf->surface.Data.Locked = 0;
428  qf->surface.Info.CropW = qf->frame->width;
429  qf->surface.Info.CropH = qf->frame->height;
430 
431  qf->surface.Info.PicStruct = !qf->frame->interlaced_frame ? MFX_PICSTRUCT_PROGRESSIVE :
432  (qf->frame->top_field_first ? MFX_PICSTRUCT_FIELD_TFF :
433  MFX_PICSTRUCT_FIELD_BFF);
434  if (qf->frame->repeat_pict == 1) {
435  qf->surface.Info.PicStruct |= MFX_PICSTRUCT_FIELD_REPEATED;
436  qf->surface.Info.PicStruct |= qf->frame->top_field_first ? MFX_PICSTRUCT_FIELD_TFF :
437  MFX_PICSTRUCT_FIELD_BFF;
438  } else if (qf->frame->repeat_pict == 2)
439  qf->surface.Info.PicStruct |= MFX_PICSTRUCT_FRAME_DOUBLING;
440  else if (qf->frame->repeat_pict == 4)
441  qf->surface.Info.PicStruct |= MFX_PICSTRUCT_FRAME_TRIPLING;
442 
443  if (ctx->inputs[0]->frame_rate.num) {
444  qf->surface.Info.FrameRateExtN = ctx->inputs[0]->frame_rate.num;
445  qf->surface.Info.FrameRateExtD = ctx->inputs[0]->frame_rate.den;
446  } else {
447  qf->surface.Info.FrameRateExtN = ctx->inputs[0]->time_base.num;
448  qf->surface.Info.FrameRateExtD = ctx->inputs[0]->time_base.den;
449  }
450 
451  qf->surface.Data.TimeStamp = av_rescale_q(qf->frame->pts,
452  ctx->inputs[0]->time_base,
453  (AVRational){1, 90000});
454 
455  *surface = &qf->surface;
456  qf->used = 1;
457 
458  return 0;
459 }
460 
462  mfxFrameSurface1 *surf_in)
463 {
464  QSVDeintContext *s = ctx->priv;
465  AVFilterLink *inlink = ctx->inputs[0];
466  AVFilterLink *outlink = ctx->outputs[0];
467 
468  AVFrame *out;
469  mfxFrameSurface1 *surf_out;
470  mfxSyncPoint sync = NULL;
471  mfxStatus err;
472  int ret, again = 0;
473 
474  out = ff_get_video_buffer(outlink, outlink->w, outlink->h);
475  if (!out) {
476  ret = AVERROR(ENOMEM);
477  goto fail;
478  }
479 
480  surf_out = (mfxFrameSurface1*)out->data[3];
481  surf_out->Info.CropW = outlink->w;
482  surf_out->Info.CropH = outlink->h;
483  surf_out->Info.PicStruct = MFX_PICSTRUCT_PROGRESSIVE;
484 
485  do {
486  err = MFXVideoVPP_RunFrameVPPAsync(s->session, surf_in, surf_out,
487  NULL, &sync);
488  if (err == MFX_WRN_DEVICE_BUSY)
489  av_usleep(1);
490  } while (err == MFX_WRN_DEVICE_BUSY);
491 
492  if (err == MFX_ERR_MORE_DATA) {
493  av_frame_free(&out);
494  return QSVDEINT_MORE_INPUT;
495  }
496 
497  if (err < 0 && err != MFX_ERR_MORE_SURFACE) {
498  ret = ff_qsvvpp_print_error(ctx, err, "Error during deinterlacing");
499  goto fail;
500  }
501 
502  if (!sync) {
503  av_log(ctx, AV_LOG_ERROR, "No sync during deinterlacing\n");
504  ret = AVERROR_UNKNOWN;
505  goto fail;
506  }
507  if (err == MFX_ERR_MORE_SURFACE)
508  again = 1;
509 
510  do {
511  err = MFXVideoCORE_SyncOperation(s->session, sync, 1000);
512  } while (err == MFX_WRN_IN_EXECUTION);
513  if (err < 0) {
514  ret = ff_qsvvpp_print_error(ctx, err, "Error synchronizing the operation");
515  goto fail;
516  }
517 
518  ret = av_frame_copy_props(out, in);
519  if (ret < 0)
520  goto fail;
521 
522  out->width = outlink->w;
523  out->height = outlink->h;
524  out->interlaced_frame = 0;
525 
526  out->pts = av_rescale_q(out->pts, inlink->time_base, outlink->time_base);
527  if (out->pts == s->last_pts)
528  out->pts++;
529  s->last_pts = out->pts;
530 
531  ret = ff_filter_frame(outlink, out);
532  if (ret < 0)
533  return ret;
534 
535  return again ? QSVDEINT_MORE_OUTPUT : 0;
536 fail:
537  av_frame_free(&out);
538  return ret;
539 }
540 
542 {
543  AVFilterContext *ctx = link->dst;
544 
545  mfxFrameSurface1 *surf_in;
546  int ret;
547 
548  ret = submit_frame(ctx, in, &surf_in);
549  if (ret < 0) {
550  av_frame_free(&in);
551  return ret;
552  }
553 
554  do {
555  ret = process_frame(ctx, in, surf_in);
556  if (ret < 0)
557  return ret;
558  } while (ret == QSVDEINT_MORE_OUTPUT);
559 
560  return 0;
561 }
562 
564 {
565  AVFilterContext *ctx = outlink->src;
566 
567  return ff_request_frame(ctx->inputs[0]);
568 }
569 
570 #define OFFSET(x) offsetof(QSVDeintContext, x)
571 #define FLAGS AV_OPT_FLAG_VIDEO_PARAM|AV_OPT_FLAG_FILTERING_PARAM
572 static const AVOption options[] = {
573  { "mode", "set deinterlace mode", OFFSET(mode), AV_OPT_TYPE_INT, {.i64 = MFX_DEINTERLACING_ADVANCED}, MFX_DEINTERLACING_BOB, MFX_DEINTERLACING_ADVANCED, FLAGS, "mode"},
574  { "bob", "bob algorithm", 0, AV_OPT_TYPE_CONST, {.i64 = MFX_DEINTERLACING_BOB}, MFX_DEINTERLACING_BOB, MFX_DEINTERLACING_ADVANCED, FLAGS, "mode"},
575  { "advanced", "Motion adaptive algorithm", 0, AV_OPT_TYPE_CONST, {.i64 = MFX_DEINTERLACING_ADVANCED}, MFX_DEINTERLACING_BOB, MFX_DEINTERLACING_ADVANCED, FLAGS, "mode"},
576  { NULL },
577 };
578 
579 static const AVClass qsvdeint_class = {
580  .class_name = "deinterlace_qsv",
581  .item_name = av_default_item_name,
582  .option = options,
583  .version = LIBAVUTIL_VERSION_INT,
584 };
585 
586 static const AVFilterPad qsvdeint_inputs[] = {
587  {
588  .name = "default",
589  .type = AVMEDIA_TYPE_VIDEO,
590  .filter_frame = qsvdeint_filter_frame,
591  },
592  { NULL }
593 };
594 
595 static const AVFilterPad qsvdeint_outputs[] = {
596  {
597  .name = "default",
598  .type = AVMEDIA_TYPE_VIDEO,
599  .config_props = qsvdeint_config_props,
600  .request_frame = qsvdeint_request_frame,
601  },
602  { NULL }
603 };
604 
606  .name = "deinterlace_qsv",
607  .description = NULL_IF_CONFIG_SMALL("QuickSync video deinterlacing"),
608 
609  .uninit = qsvdeint_uninit,
610  .query_formats = qsvdeint_query_formats,
611 
612  .priv_size = sizeof(QSVDeintContext),
613  .priv_class = &qsvdeint_class,
614 
617 
618  .flags_internal = FF_FILTER_FLAG_HWFRAME_AWARE,
619 };
static const AVFilterPad inputs[]
Definition: af_acontrast.c:193
static const AVFilterPad outputs[]
Definition: af_acontrast.c:203
#define av_cold
Definition: attributes.h:88
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
int ff_filter_frame(AVFilterLink *link, AVFrame *frame)
Send a frame of data to the next filter.
Definition: avfilter.c:1096
int ff_request_frame(AVFilterLink *link)
Request an input frame from the filter at the other end of the link.
Definition: avfilter.c:408
Main libavfilter public API header.
#define s(width, name)
Definition: cbs_vp9.c:257
#define f(width, name)
Definition: cbs_vp9.c:255
#define fail()
Definition: checkasm.h:133
common internal and external API header
#define NULL
Definition: coverity.c:32
long long int64_t
Definition: coverity.c:34
static AVFrame * frame
mode
Use these values in ebur128_init (or'ed).
Definition: ebur128.h:83
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:587
AVFilterFormats * ff_make_format_list(const int *fmts)
Create a list of supported formats.
Definition: formats.c:286
@ AV_OPT_TYPE_CONST
Definition: opt.h:234
@ AV_OPT_TYPE_INT
Definition: opt.h:225
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
AVBufferRef * av_buffer_ref(AVBufferRef *buf)
Create a new reference to an AVBuffer.
Definition: buffer.c:93
#define AVERROR_UNKNOWN
Unknown error, typically from an external library.
Definition: error.h:71
#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:203
int av_frame_copy_props(AVFrame *dst, const AVFrame *src)
Copy only "metadata" fields from src to dst.
Definition: frame.c:658
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
Definition: log.h:194
const char * av_default_item_name(void *ptr)
Return the context name.
Definition: log.c:235
AVRational av_mul_q(AVRational b, AVRational c)
Multiply two rationals.
Definition: rational.c:80
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
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
void * av_mallocz_array(size_t nmemb, size_t size)
Allocate a memory block for an array with av_mallocz().
Definition: mem.c:190
@ AVMEDIA_TYPE_VIDEO
Definition: avutil.h:201
#define AV_NOPTS_VALUE
Undefined timestamp value.
Definition: avutil.h:248
#define LIBAVUTIL_VERSION_INT
Definition: version.h:85
mfxHandleType handle_type
Definition: hwcontext_qsv.c:89
An API-specific header for AV_HWDEVICE_TYPE_QSV.
int i
Definition: input.c:407
#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
common internal API header
#define NULL_IF_CONFIG_SMALL(x)
Return NULL if CONFIG_SMALL is true, otherwise the argument without modification.
Definition: internal.h:117
static enum AVPixelFormat pix_fmts[]
Definition: libkvazaar.c:309
AVOptions.
AVPixelFormat
Pixel format.
Definition: pixfmt.h:64
@ AV_PIX_FMT_NONE
Definition: pixfmt.h:65
@ AV_PIX_FMT_QSV
HW acceleration through QSV, data[3] contains a pointer to the mfxFrameSurface1 structure.
Definition: pixfmt.h:222
#define QSV_RUNTIME_VERSION_ATLEAST(MFX_VERSION, MAJOR, MINOR)
Definition: qsv_internal.h:59
int ff_qsvvpp_print_iopattern(void *log_ctx, int mfx_iopattern, const char *extra_string)
Definition: qsvvpp.c:91
int ff_qsvvpp_print_error(void *log_ctx, mfxStatus err, const char *error_string)
Definition: qsvvpp.c:163
int ff_qsvvpp_print_warning(void *log_ctx, mfxStatus err, const char *warning_string)
Definition: qsvvpp.c:173
Intel Quick Sync Video VPP base function.
#define FF_ARRAY_ELEMS(a)
A reference to a data buffer.
Definition: buffer.h:84
Describe the class of an AVClass context structure.
Definition: log.h:67
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
An instance of a filter.
Definition: avfilter.h:341
A list of supported formats for one end of a filter link.
Definition: formats.h:65
A filter pad used for either input or output.
Definition: internal.h:54
const char * name
Pad name.
Definition: internal.h:60
Filter definition.
Definition: avfilter.h:145
const char * name
Filter name.
Definition: avfilter.h:149
This structure describes decoded (raw) audio or video data.
Definition: frame.h:318
int64_t pts
Presentation timestamp in time_base units (time when frame should be shown to user).
Definition: frame.h:411
uint8_t * data[AV_NUM_DATA_POINTERS]
pointer to the picture/channel planes.
Definition: frame.h:332
int width
Definition: frame.h:376
int height
Definition: frame.h:376
int top_field_first
If the content is interlaced, is top field displayed first.
Definition: frame.h:470
int interlaced_frame
The content of the picture is interlaced.
Definition: frame.h:465
int repeat_pict
When decoding, this signals how much the picture must be delayed.
Definition: frame.h:460
void * hwctx
The format-specific data, allocated and freed by libavutil along with this context.
Definition: hwcontext.h:92
This struct describes a set or pool of "hardware" frames (i.e.
Definition: hwcontext.h:124
void * hwctx
The format-specific data, allocated and freed automatically along with this context.
Definition: hwcontext.h:162
AVHWDeviceContext * device_ctx
The parent AVHWDeviceContext.
Definition: hwcontext.h:149
AVOption.
Definition: opt.h:248
This struct is allocated as AVHWDeviceContext.hwctx.
Definition: hwcontext_qsv.h:35
This struct is allocated as AVHWFramesContext.hwctx.
Definition: hwcontext_qsv.h:42
Rational number (pair of numerator and denominator).
Definition: rational.h:58
mfxFrameSurface1 ** surface_ptrs
mfxExtOpaqueSurfaceAlloc opaque_alloc
QSVFrame * work_frames
AVBufferRef * hw_frames_ctx
mfxExtBuffer * ext_buffers[2]
mfxExtVPPDeinterlacing deint_conf
AVFrame * frame
Definition: qsv_internal.h:73
struct QSVFrame * next
Definition: qsv_internal.h:82
mfxFrameSurface1 surface
Definition: qsv_internal.h:74
#define av_freep(p)
#define av_log(a,...)
FILE * out
Definition: movenc.c:54
AVFormatContext * ctx
Definition: movenc.c:48
int av_usleep(unsigned usec)
Sleep for a period of time.
Definition: time.c:84
static const AVClass qsvdeint_class
static int init_out_session(AVFilterContext *ctx)
static int qsvdeint_config_props(AVFilterLink *outlink)
static const AVFilterPad qsvdeint_outputs[]
static const AVFilterPad qsvdeint_inputs[]
static int qsvdeint_request_frame(AVFilterLink *outlink)
static const AVOption options[]
static int qsvdeint_query_formats(AVFilterContext *ctx)
static int qsvdeint_filter_frame(AVFilterLink *link, AVFrame *in)
static int process_frame(AVFilterContext *ctx, const AVFrame *in, mfxFrameSurface1 *surf_in)
static mfxStatus frame_alloc(mfxHDL pthis, mfxFrameAllocRequest *req, mfxFrameAllocResponse *resp)
static mfxStatus frame_get_hdl(mfxHDL pthis, mfxMemId mid, mfxHDL *hdl)
#define FLAGS
static mfxStatus frame_lock(mfxHDL pthis, mfxMemId mid, mfxFrameData *ptr)
static int get_free_frame(QSVDeintContext *s, QSVFrame **f)
static av_cold void qsvdeint_uninit(AVFilterContext *ctx)
AVFilter ff_vf_deinterlace_qsv
static const mfxHandleType handle_types[]
static int submit_frame(AVFilterContext *ctx, AVFrame *frame, mfxFrameSurface1 **surface)
static mfxStatus frame_free(mfxHDL pthis, mfxFrameAllocResponse *resp)
#define OFFSET(x)
static mfxStatus frame_unlock(mfxHDL pthis, mfxMemId mid, mfxFrameData *ptr)
static void clear_unused_frames(QSVDeintContext *s)
@ QSVDEINT_MORE_OUTPUT
@ QSVDEINT_MORE_INPUT
if(ret< 0)
Definition: vf_mcdeint.c:282
AVFrame * ff_get_video_buffer(AVFilterLink *link, int w, int h)
Request a picture buffer with a specific set of permissions.
Definition: video.c:104