Libav
vf_scale_qsv.c
Go to the documentation of this file.
1 /*
2  * This file is part of Libav.
3  *
4  * Libav 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  * Libav 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 Libav; if not, write to the Free Software
16  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
17  */
18 
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/eval.h"
32 #include "libavutil/hwcontext.h"
34 #include "libavutil/internal.h"
35 #include "libavutil/mathematics.h"
36 #include "libavutil/opt.h"
37 #include "libavutil/pixdesc.h"
38 #include "libavutil/time.h"
39 
40 #include "avfilter.h"
41 #include "formats.h"
42 #include "internal.h"
43 #include "video.h"
44 
45 static const char *const var_names[] = {
46  "PI",
47  "PHI",
48  "E",
49  "in_w", "iw",
50  "in_h", "ih",
51  "out_w", "ow",
52  "out_h", "oh",
53  "a", "dar",
54  "sar",
55  NULL
56 };
57 
58 enum var_name {
69 };
70 
71 typedef struct QSVScaleContext {
72  const AVClass *class;
73 
75  /* a clone of the main session, used internally for scaling */
76  mfxSession session;
77 
78  mfxMemId *mem_ids_in;
80 
81  mfxMemId *mem_ids_out;
83 
84  mfxFrameSurface1 **surface_ptrs_in;
86 
87  mfxFrameSurface1 **surface_ptrs_out;
89 
90  mfxExtOpaqueSurfaceAlloc opaque_alloc;
91  mfxExtBuffer *ext_buffers[1];
92 
94 
100  int w, h;
101 
106 
107  char *w_expr;
108  char *h_expr;
109  char *format_str;
111 
113 {
114  QSVScaleContext *s = ctx->priv;
115 
116  if (!strcmp(s->format_str, "same")) {
117  s->format = AV_PIX_FMT_NONE;
118  } else {
120  if (s->format == AV_PIX_FMT_NONE) {
121  av_log(ctx, AV_LOG_ERROR, "Unrecognized pixel format: %s\n", s->format_str);
122  return AVERROR(EINVAL);
123  }
124  }
125 
126  return 0;
127 }
128 
130 {
131  QSVScaleContext *s = ctx->priv;
132 
133  if (s->session) {
134  MFXClose(s->session);
135  s->session = NULL;
136  }
138 
139  av_freep(&s->mem_ids_in);
140  av_freep(&s->mem_ids_out);
141  s->nb_mem_ids_in = 0;
142  s->nb_mem_ids_out = 0;
143 
146  s->nb_surface_ptrs_in = 0;
147  s->nb_surface_ptrs_out = 0;
148 }
149 
151 {
152  static const enum AVPixelFormat pixel_formats[] = {
154  };
155  AVFilterFormats *pix_fmts = ff_make_format_list(pixel_formats);
156 
157  ff_set_common_formats(ctx, pix_fmts);
158 
159  return 0;
160 }
161 
163  int out_width, int out_height)
164 {
165  QSVScaleContext *s = ctx->priv;
166 
167  AVHWFramesContext *in_frames_ctx;
168  AVHWFramesContext *out_frames_ctx;
169  AVQSVFramesContext *in_frames_hwctx;
170  AVQSVFramesContext *out_frames_hwctx;
171  enum AVPixelFormat in_format;
172  enum AVPixelFormat out_format;
173  int i, ret;
174 
175  /* check that we have a hw context */
176  if (!ctx->inputs[0]->hw_frames_ctx) {
177  av_log(ctx, AV_LOG_ERROR, "No hw context provided on input\n");
178  return AVERROR(EINVAL);
179  }
180  in_frames_ctx = (AVHWFramesContext*)ctx->inputs[0]->hw_frames_ctx->data;
181  in_frames_hwctx = in_frames_ctx->hwctx;
182 
183  in_format = in_frames_ctx->sw_format;
184  out_format = (s->format == AV_PIX_FMT_NONE) ? in_format : s->format;
185 
186  s->out_frames_ref = av_hwframe_ctx_alloc(in_frames_ctx->device_ref);
187  if (!s->out_frames_ref)
188  return AVERROR(ENOMEM);
189  out_frames_ctx = (AVHWFramesContext*)s->out_frames_ref->data;
190  out_frames_hwctx = out_frames_ctx->hwctx;
191 
192  out_frames_ctx->format = AV_PIX_FMT_QSV;
193  out_frames_ctx->width = FFALIGN(out_width, 32);
194  out_frames_ctx->height = FFALIGN(out_height, 32);
195  out_frames_ctx->sw_format = out_format;
196  out_frames_ctx->initial_pool_size = 32;
197 
198  out_frames_hwctx->frame_type = in_frames_hwctx->frame_type;
199 
201  if (ret < 0)
202  return ret;
203 
204  for (i = 0; i < out_frames_hwctx->nb_surfaces; i++) {
205  mfxFrameInfo *info = &out_frames_hwctx->surfaces[i].Info;
206  info->CropW = out_width;
207  info->CropH = out_height;
208  }
209 
210  return 0;
211 }
212 
213 static mfxStatus frame_alloc(mfxHDL pthis, mfxFrameAllocRequest *req,
214  mfxFrameAllocResponse *resp)
215 {
216  AVFilterContext *ctx = pthis;
217  QSVScaleContext *s = ctx->priv;
218 
219  if (!(req->Type & MFX_MEMTYPE_VIDEO_MEMORY_PROCESSOR_TARGET) ||
220  !(req->Type & (MFX_MEMTYPE_FROM_VPPIN | MFX_MEMTYPE_FROM_VPPOUT)) ||
221  !(req->Type & MFX_MEMTYPE_EXTERNAL_FRAME))
222  return MFX_ERR_UNSUPPORTED;
223 
224  if (req->Type & MFX_MEMTYPE_FROM_VPPIN) {
225  resp->mids = s->mem_ids_in;
226  resp->NumFrameActual = s->nb_mem_ids_in;
227  } else {
228  resp->mids = s->mem_ids_out;
229  resp->NumFrameActual = s->nb_mem_ids_out;
230  }
231 
232  return MFX_ERR_NONE;
233 }
234 
235 static mfxStatus frame_free(mfxHDL pthis, mfxFrameAllocResponse *resp)
236 {
237  return MFX_ERR_NONE;
238 }
239 
240 static mfxStatus frame_lock(mfxHDL pthis, mfxMemId mid, mfxFrameData *ptr)
241 {
242  return MFX_ERR_UNSUPPORTED;
243 }
244 
245 static mfxStatus frame_unlock(mfxHDL pthis, mfxMemId mid, mfxFrameData *ptr)
246 {
247  return MFX_ERR_UNSUPPORTED;
248 }
249 
250 static mfxStatus frame_get_hdl(mfxHDL pthis, mfxMemId mid, mfxHDL *hdl)
251 {
252  *hdl = mid;
253  return MFX_ERR_NONE;
254 }
255 
256 static const mfxHandleType handle_types[] = {
257  MFX_HANDLE_VA_DISPLAY,
258  MFX_HANDLE_D3D9_DEVICE_MANAGER,
259  MFX_HANDLE_D3D11_DEVICE,
260 };
261 
263 {
264 
265  QSVScaleContext *s = ctx->priv;
266  AVHWFramesContext *in_frames_ctx = (AVHWFramesContext*)ctx->inputs[0]->hw_frames_ctx->data;
267  AVHWFramesContext *out_frames_ctx = (AVHWFramesContext*)s->out_frames_ref->data;
268  AVQSVFramesContext *in_frames_hwctx = in_frames_ctx->hwctx;
269  AVQSVFramesContext *out_frames_hwctx = out_frames_ctx->hwctx;
270  AVQSVDeviceContext *device_hwctx = in_frames_ctx->device_ctx->hwctx;
271 
272  int opaque = !!(in_frames_hwctx->frame_type & MFX_MEMTYPE_OPAQUE_FRAME);
273 
274  mfxHDL handle = NULL;
275  mfxHandleType handle_type;
276  mfxVersion ver;
277  mfxIMPL impl;
278  mfxVideoParam par;
279  mfxStatus err;
280  int i;
281 
282  /* extract the properties of the "master" session given to us */
283  err = MFXQueryIMPL(device_hwctx->session, &impl);
284  if (err == MFX_ERR_NONE)
285  err = MFXQueryVersion(device_hwctx->session, &ver);
286  if (err != MFX_ERR_NONE) {
287  av_log(ctx, AV_LOG_ERROR, "Error querying the session attributes\n");
288  return AVERROR_UNKNOWN;
289  }
290 
291  for (i = 0; i < FF_ARRAY_ELEMS(handle_types); i++) {
292  err = MFXVideoCORE_GetHandle(device_hwctx->session, handle_types[i], &handle);
293  if (err == MFX_ERR_NONE) {
294  handle_type = handle_types[i];
295  break;
296  }
297  }
298 
299  /* create a "slave" session with those same properties, to be used for
300  * actual scaling */
301  err = MFXInit(impl, &ver, &s->session);
302  if (err != MFX_ERR_NONE) {
303  av_log(ctx, AV_LOG_ERROR, "Error initializing a session for scaling\n");
304  return AVERROR_UNKNOWN;
305  }
306 
307  if (handle) {
308  err = MFXVideoCORE_SetHandle(s->session, handle_type, handle);
309  if (err != MFX_ERR_NONE)
310  return AVERROR_UNKNOWN;
311  }
312 
313  memset(&par, 0, sizeof(par));
314 
315  if (opaque) {
316  s->surface_ptrs_in = av_mallocz_array(in_frames_hwctx->nb_surfaces,
317  sizeof(*s->surface_ptrs_in));
318  if (!s->surface_ptrs_in)
319  return AVERROR(ENOMEM);
320  for (i = 0; i < in_frames_hwctx->nb_surfaces; i++)
321  s->surface_ptrs_in[i] = in_frames_hwctx->surfaces + i;
322  s->nb_surface_ptrs_in = in_frames_hwctx->nb_surfaces;
323 
324  s->surface_ptrs_out = av_mallocz_array(out_frames_hwctx->nb_surfaces,
325  sizeof(*s->surface_ptrs_out));
326  if (!s->surface_ptrs_out)
327  return AVERROR(ENOMEM);
328  for (i = 0; i < out_frames_hwctx->nb_surfaces; i++)
329  s->surface_ptrs_out[i] = out_frames_hwctx->surfaces + i;
330  s->nb_surface_ptrs_out = out_frames_hwctx->nb_surfaces;
331 
332  s->opaque_alloc.In.Surfaces = s->surface_ptrs_in;
333  s->opaque_alloc.In.NumSurface = s->nb_surface_ptrs_in;
334  s->opaque_alloc.In.Type = in_frames_hwctx->frame_type;
335 
336  s->opaque_alloc.Out.Surfaces = s->surface_ptrs_out;
337  s->opaque_alloc.Out.NumSurface = s->nb_surface_ptrs_out;
338  s->opaque_alloc.Out.Type = out_frames_hwctx->frame_type;
339 
340  s->opaque_alloc.Header.BufferId = MFX_EXTBUFF_OPAQUE_SURFACE_ALLOCATION;
341  s->opaque_alloc.Header.BufferSz = sizeof(s->opaque_alloc);
342 
343  s->ext_buffers[0] = (mfxExtBuffer*)&s->opaque_alloc;
344 
345  par.ExtParam = s->ext_buffers;
346  par.NumExtParam = FF_ARRAY_ELEMS(s->ext_buffers);
347 
348  par.IOPattern = MFX_IOPATTERN_IN_OPAQUE_MEMORY | MFX_IOPATTERN_OUT_OPAQUE_MEMORY;
349  } else {
350  mfxFrameAllocator frame_allocator = {
351  .pthis = ctx,
352  .Alloc = frame_alloc,
353  .Lock = frame_lock,
354  .Unlock = frame_unlock,
355  .GetHDL = frame_get_hdl,
356  .Free = frame_free,
357  };
358 
359  s->mem_ids_in = av_mallocz_array(in_frames_hwctx->nb_surfaces,
360  sizeof(*s->mem_ids_in));
361  if (!s->mem_ids_in)
362  return AVERROR(ENOMEM);
363  for (i = 0; i < in_frames_hwctx->nb_surfaces; i++)
364  s->mem_ids_in[i] = in_frames_hwctx->surfaces[i].Data.MemId;
365  s->nb_mem_ids_in = in_frames_hwctx->nb_surfaces;
366 
367  s->mem_ids_out = av_mallocz_array(out_frames_hwctx->nb_surfaces,
368  sizeof(*s->mem_ids_out));
369  if (!s->mem_ids_out)
370  return AVERROR(ENOMEM);
371  for (i = 0; i < out_frames_hwctx->nb_surfaces; i++)
372  s->mem_ids_out[i] = out_frames_hwctx->surfaces[i].Data.MemId;
373  s->nb_mem_ids_out = out_frames_hwctx->nb_surfaces;
374 
375  err = MFXVideoCORE_SetFrameAllocator(s->session, &frame_allocator);
376  if (err != MFX_ERR_NONE)
377  return AVERROR_UNKNOWN;
378 
379  par.IOPattern = MFX_IOPATTERN_IN_VIDEO_MEMORY | MFX_IOPATTERN_OUT_VIDEO_MEMORY;
380  }
381 
382  par.AsyncDepth = 1; // TODO async
383 
384  par.vpp.In = in_frames_hwctx->surfaces[0].Info;
385  par.vpp.Out = out_frames_hwctx->surfaces[0].Info;
386 
387  /* Apparently VPP requires the frame rate to be set to some value, otherwise
388  * init will fail (probably for the framerate conversion filter). Since we
389  * are only doing scaling here, we just invent an arbitrary
390  * value */
391  par.vpp.In.FrameRateExtN = 25;
392  par.vpp.In.FrameRateExtD = 1;
393  par.vpp.Out.FrameRateExtN = 25;
394  par.vpp.Out.FrameRateExtD = 1;
395 
396  err = MFXVideoVPP_Init(s->session, &par);
397  if (err != MFX_ERR_NONE) {
398  av_log(ctx, AV_LOG_ERROR, "Error opening the VPP for scaling\n");
399  return AVERROR_UNKNOWN;
400  }
401 
402  return 0;
403 }
404 
405 static int init_scale_session(AVFilterContext *ctx, int in_width, int in_height,
406  int out_width, int out_height)
407 {
408  QSVScaleContext *s = ctx->priv;
409 
410  int ret;
411 
412  qsvscale_uninit(ctx);
413 
414  ret = init_out_pool(ctx, out_width, out_height);
415  if (ret < 0)
416  return ret;
417 
418  ret = init_out_session(ctx);
419  if (ret < 0)
420  return ret;
421 
424  if (!ctx->outputs[0]->hw_frames_ctx)
425  return AVERROR(ENOMEM);
426 
427  return 0;
428 }
429 
431 {
432  AVFilterContext *ctx = outlink->src;
433  AVFilterLink *inlink = outlink->src->inputs[0];
434  QSVScaleContext *s = ctx->priv;
435  int64_t w, h;
436  double var_values[VARS_NB], res;
437  char *expr;
438  int ret;
439 
440  var_values[VAR_PI] = M_PI;
441  var_values[VAR_PHI] = M_PHI;
442  var_values[VAR_E] = M_E;
443  var_values[VAR_IN_W] = var_values[VAR_IW] = inlink->w;
444  var_values[VAR_IN_H] = var_values[VAR_IH] = inlink->h;
445  var_values[VAR_OUT_W] = var_values[VAR_OW] = NAN;
446  var_values[VAR_OUT_H] = var_values[VAR_OH] = NAN;
447  var_values[VAR_A] = (double) inlink->w / inlink->h;
448  var_values[VAR_SAR] = inlink->sample_aspect_ratio.num ?
449  (double) inlink->sample_aspect_ratio.num / inlink->sample_aspect_ratio.den : 1;
450  var_values[VAR_DAR] = var_values[VAR_A] * var_values[VAR_SAR];
451 
452  /* evaluate width and height */
453  av_expr_parse_and_eval(&res, (expr = s->w_expr),
454  var_names, var_values,
455  NULL, NULL, NULL, NULL, NULL, 0, ctx);
456  s->w = var_values[VAR_OUT_W] = var_values[VAR_OW] = res;
457  if ((ret = av_expr_parse_and_eval(&res, (expr = s->h_expr),
458  var_names, var_values,
459  NULL, NULL, NULL, NULL, NULL, 0, ctx)) < 0)
460  goto fail;
461  s->h = var_values[VAR_OUT_H] = var_values[VAR_OH] = res;
462  /* evaluate again the width, as it may depend on the output height */
463  if ((ret = av_expr_parse_and_eval(&res, (expr = s->w_expr),
464  var_names, var_values,
465  NULL, NULL, NULL, NULL, NULL, 0, ctx)) < 0)
466  goto fail;
467  s->w = res;
468 
469  w = s->w;
470  h = s->h;
471 
472  /* sanity check params */
473  if (w < -1 || h < -1) {
474  av_log(ctx, AV_LOG_ERROR, "Size values less than -1 are not acceptable.\n");
475  return AVERROR(EINVAL);
476  }
477  if (w == -1 && h == -1)
478  s->w = s->h = 0;
479 
480  if (!(w = s->w))
481  w = inlink->w;
482  if (!(h = s->h))
483  h = inlink->h;
484  if (w == -1)
485  w = av_rescale(h, inlink->w, inlink->h);
486  if (h == -1)
487  h = av_rescale(w, inlink->h, inlink->w);
488 
489  if (w > INT_MAX || h > INT_MAX ||
490  (h * inlink->w) > INT_MAX ||
491  (w * inlink->h) > INT_MAX)
492  av_log(ctx, AV_LOG_ERROR, "Rescaled value for width or height is too big.\n");
493 
494  outlink->w = w;
495  outlink->h = h;
496 
497  ret = init_scale_session(ctx, inlink->w, inlink->h, w, h);
498  if (ret < 0)
499  return ret;
500 
501  av_log(ctx, AV_LOG_VERBOSE, "w:%d h:%d -> w:%d h:%d\n",
502  inlink->w, inlink->h, outlink->w, outlink->h);
503 
504  if (inlink->sample_aspect_ratio.num)
505  outlink->sample_aspect_ratio = av_mul_q((AVRational){outlink->h*inlink->w,
506  outlink->w*inlink->h},
507  inlink->sample_aspect_ratio);
508  else
509  outlink->sample_aspect_ratio = inlink->sample_aspect_ratio;
510 
511  return 0;
512 
513 fail:
515  "Error when evaluating the expression '%s'\n", expr);
516  return ret;
517 }
518 
520 {
521  AVFilterContext *ctx = link->dst;
522  QSVScaleContext *s = ctx->priv;
523  AVFilterLink *outlink = ctx->outputs[0];
524 
525  mfxSyncPoint sync = NULL;
526  mfxStatus err;
527 
528  AVFrame *out = NULL;
529  int ret = 0;
530 
531  out = av_frame_alloc();
532  if (!out) {
533  ret = AVERROR(ENOMEM);
534  goto fail;
535  }
536 
537  ret = av_hwframe_get_buffer(s->out_frames_ref, out, 0);
538  if (ret < 0)
539  goto fail;
540 
541  do {
542  err = MFXVideoVPP_RunFrameVPPAsync(s->session,
543  (mfxFrameSurface1*)in->data[3],
544  (mfxFrameSurface1*)out->data[3],
545  NULL, &sync);
546  if (err == MFX_WRN_DEVICE_BUSY)
547  av_usleep(1);
548  } while (err == MFX_WRN_DEVICE_BUSY);
549 
550  if (err < 0 || !sync) {
551  av_log(ctx, AV_LOG_ERROR, "Error during scaling\n");
552  ret = AVERROR_UNKNOWN;
553  goto fail;
554  }
555 
556  do {
557  err = MFXVideoCORE_SyncOperation(s->session, sync, 1000);
558  } while (err == MFX_WRN_IN_EXECUTION);
559  if (err < 0) {
560  av_log(ctx, AV_LOG_ERROR, "Error synchronizing the operation: %d\n", err);
561  ret = AVERROR_UNKNOWN;
562  goto fail;
563  }
564 
565  ret = av_frame_copy_props(out, in);
566  if (ret < 0)
567  goto fail;
568 
569  out->width = outlink->w;
570  out->height = outlink->h;
571 
573  (int64_t)in->sample_aspect_ratio.num * outlink->h * link->w,
574  (int64_t)in->sample_aspect_ratio.den * outlink->w * link->h,
575  INT_MAX);
576 
577  av_frame_free(&in);
578  return ff_filter_frame(outlink, out);
579 fail:
580  av_frame_free(&in);
581  av_frame_free(&out);
582  return ret;
583 }
584 
585 #define OFFSET(x) offsetof(QSVScaleContext, x)
586 #define FLAGS AV_OPT_FLAG_VIDEO_PARAM
587 static const AVOption options[] = {
588  { "w", "Output video width", OFFSET(w_expr), AV_OPT_TYPE_STRING, { .str = "iw" }, .flags = FLAGS },
589  { "h", "Output video height", OFFSET(h_expr), AV_OPT_TYPE_STRING, { .str = "ih" }, .flags = FLAGS },
590  { "format", "Output pixel format", OFFSET(format_str), AV_OPT_TYPE_STRING, { .str = "same" }, .flags = FLAGS },
591 
592  { NULL },
593 };
594 
595 static const AVClass qsvscale_class = {
596  .class_name = "qsvscale",
597  .item_name = av_default_item_name,
598  .option = options,
599  .version = LIBAVUTIL_VERSION_INT,
600 };
601 
602 static const AVFilterPad qsvscale_inputs[] = {
603  {
604  .name = "default",
605  .type = AVMEDIA_TYPE_VIDEO,
606  .filter_frame = qsvscale_filter_frame,
607  },
608  { NULL }
609 };
610 
611 static const AVFilterPad qsvscale_outputs[] = {
612  {
613  .name = "default",
614  .type = AVMEDIA_TYPE_VIDEO,
615  .config_props = qsvscale_config_props,
616  },
617  { NULL }
618 };
619 
621  .name = "scale_qsv",
622  .description = NULL_IF_CONFIG_SMALL("QuickSync video scaling and format conversion"),
623 
624  .init = qsvscale_init,
625  .uninit = qsvscale_uninit,
626  .query_formats = qsvscale_query_formats,
627 
628  .priv_size = sizeof(QSVScaleContext),
629  .priv_class = &qsvscale_class,
630 
631  .inputs = qsvscale_inputs,
632  .outputs = qsvscale_outputs,
633 };
AVBufferRef * out_frames_ref
Definition: vf_scale_qsv.c:74
static const AVClass qsvscale_class
Definition: vf_scale_qsv.c:595
static mfxStatus frame_alloc(mfxHDL pthis, mfxFrameAllocRequest *req, mfxFrameAllocResponse *resp)
Definition: vf_scale_qsv.c:213
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:106
This structure describes decoded (raw) audio or video data.
Definition: frame.h:140
enum AVPixelFormat format
Output sw format.
Definition: vf_scale_qsv.c:105
AVOption.
Definition: opt.h:234
int frame_type
A combination of MFX_MEMTYPE_* describing the frame pool.
Definition: hwcontext_qsv.h:49
static const AVFilterPad outputs[]
Definition: af_ashowinfo.c:259
Main libavfilter public API header.
#define OFFSET(x)
Definition: vf_scale_qsv.c:585
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:44
av_log(ac->avr, AV_LOG_TRACE, "%d samples - audio_convert: %s to %s (%s)\, len, av_get_sample_fmt_name(ac->in_fmt), av_get_sample_fmt_name(ac->out_fmt), use_generic ? ac->func_descr_generic :ac->func_descr)
static int sync(AVFormatContext *s, uint8_t *header)
Read input until we find the next ident.
Definition: lxfdec.c:86
int width
The allocated dimensions of the frames in this pool.
Definition: hwcontext.h:222
enum AVPixelFormat format
The pixel format identifying the underlying HW surface type.
Definition: hwcontext.h:202
#define FF_ARRAY_ELEMS(a)
int av_usleep(unsigned usec)
Sleep for a period of time.
Definition: time.c:68
static int qsvscale_query_formats(AVFilterContext *ctx)
Definition: vf_scale_qsv.c:150
void av_freep(void *arg)
Free a memory block which has been allocated with av_malloc(z)() or av_realloc() and set the pointer ...
Definition: mem.c:202
AVFilterFormats * ff_make_format_list(const int *fmts)
Create a list of supported formats.
Definition: formats.c:165
const char * name
Pad name.
Definition: internal.h:41
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:39
AVFilterLink ** inputs
array of pointers to input links
Definition: avfilter.h:270
int ff_filter_frame(AVFilterLink *link, AVFrame *frame)
Send a frame of data to the next filter.
Definition: avfilter.c:747
AVFrame * av_frame_alloc(void)
Allocate an AVFrame and set its fields to default values.
Definition: frame.c:68
AVOptions.
void * hwctx
The format-specific data, allocated and freed by libavutil along with this context.
Definition: hwcontext.h:85
AVRational av_mul_q(AVRational b, AVRational c)
Multiply two rationals.
Definition: rational.c:79
#define AV_LOG_VERBOSE
Detailed information.
Definition: log.h:140
static mfxStatus frame_free(mfxHDL pthis, mfxFrameAllocResponse *resp)
Definition: vf_scale_qsv.c:235
void 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:389
static mfxStatus frame_unlock(mfxHDL pthis, mfxMemId mid, mfxFrameData *ptr)
Definition: vf_scale_qsv.c:245
static int qsvscale_config_props(AVFilterLink *outlink)
Definition: vf_scale_qsv.c:430
AVFilter ff_vf_scale_qsv
Definition: vf_scale_qsv.c:620
#define FFALIGN(x, a)
Definition: macros.h:48
static const AVFilterPad qsvscale_outputs[]
Definition: vf_scale_qsv.c:611
mfxExtOpaqueSurfaceAlloc opaque_alloc
Definition: vf_scale_qsv.c:90
This struct is allocated as AVHWDeviceContext.hwctx.
Definition: hwcontext_qsv.h:35
A filter pad used for either input or output.
Definition: internal.h:35
int av_expr_parse_and_eval(double *d, const char *s, const char *const *const_names, const double *const_values, const char *const *func1_names, double(*const *funcs1)(void *, double), const char *const *func2_names, double(*const *funcs2)(void *, double, double), void *opaque, int log_offset, void *log_ctx)
Parse and evaluate an expression.
Definition: eval.c:551
static const AVOption options[]
Definition: vf_scale_qsv.c:587
int width
width and height of the video frame
Definition: frame.h:179
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
Definition: log.h:124
mfxMemId * mem_ids_in
Definition: vf_scale_qsv.c:78
#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:80
#define NULL_IF_CONFIG_SMALL(x)
Return NULL if CONFIG_SMALL is true, otherwise the argument without modification. ...
Definition: internal.h:148
static int qsvscale_filter_frame(AVFilterLink *link, AVFrame *in)
Definition: vf_scale_qsv.c:519
void * priv
private data for use by the filter
Definition: avfilter.h:277
int av_hwframe_ctx_init(AVBufferRef *ref)
Finalize the context before use.
Definition: hwcontext.c:263
int av_hwframe_get_buffer(AVBufferRef *hwframe_ref, AVFrame *frame, int flags)
Allocate a new frame attached to the given AVHWFramesContext.
Definition: hwcontext.c:394
#define fail()
Definition: checkasm.h:80
int av_reduce(int *dst_num, int *dst_den, int64_t num, int64_t den, int64_t max)
Reduce a fraction.
Definition: rational.c:35
static int init_scale_session(AVFilterContext *ctx, int in_width, int in_height, int out_width, int out_height)
Definition: vf_scale_qsv.c:405
common internal API header
int initial_pool_size
Initial size of the frame pool.
Definition: hwcontext.h:192
int64_t av_rescale(int64_t a, int64_t b, int64_t c)
Rescale a 64-bit integer with rounding to nearest.
Definition: mathematics.c:86
AVHWDeviceContext * device_ctx
The parent AVHWDeviceContext.
Definition: hwcontext.h:142
static mfxStatus frame_get_hdl(mfxHDL pthis, mfxMemId mid, mfxHDL *hdl)
Definition: vf_scale_qsv.c:250
#define M_E
Definition: ratecontrol.c:42
static int init_out_session(AVFilterContext *ctx)
Definition: vf_scale_qsv.c:262
AVFormatContext * ctx
Definition: movenc.c:48
LIBAVUTIL_VERSION_INT
Definition: eval.c:55
int w
New dimensions.
Definition: vf_scale_qsv.c:100
mfxSession session
Definition: hwcontext_qsv.h:36
NULL
Definition: eval.c:55
mfxFrameSurface1 * surfaces
Definition: hwcontext_qsv.h:43
av_default_item_name
Definition: dnxhdenc.c:55
uint8_t * data
The data buffer.
Definition: buffer.h:89
AVRational sample_aspect_ratio
Sample aspect ratio for the video frame, 0/1 if unknown/unspecified.
Definition: frame.h:206
void * hwctx
The format-specific data, allocated and freed automatically along with this context.
Definition: hwcontext.h:155
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)\", 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:34
Filter definition.
Definition: avfilter.h:120
static const AVFilterPad inputs[]
Definition: af_ashowinfo.c:248
rational number numerator/denominator
Definition: rational.h:43
This struct describes a set or pool of "hardware" frames (i.e.
Definition: hwcontext.h:117
#define M_PHI
Definition: mathematics.h:34
HW acceleration through QSV, data[3] contains a pointer to the mfxFrameSurface1 structure.
Definition: pixfmt.h:215
const char * name
Filter name.
Definition: avfilter.h:124
static const AVFilterPad qsvscale_inputs[]
Definition: vf_scale_qsv.c:602
mfxFrameSurface1 ** surface_ptrs_in
Definition: vf_scale_qsv.c:84
AVFilterLink ** outputs
array of pointers to output links
Definition: avfilter.h:274
mfxSession session
Definition: vf_scale_qsv.c:76
static enum AVPixelFormat pix_fmts[]
Definition: libkvazaar.c:257
static int qsvscale_init(AVFilterContext *ctx)
Definition: vf_scale_qsv.c:112
mfxFrameSurface1 ** surface_ptrs_out
Definition: vf_scale_qsv.c:87
static void qsvscale_uninit(AVFilterContext *ctx)
Definition: vf_scale_qsv.c:129
uint8_t * data[AV_NUM_DATA_POINTERS]
pointer to the picture/channel planes.
Definition: frame.h:146
AVBufferRef * device_ref
A reference to the parent AVHWDeviceContext.
Definition: hwcontext.h:134
A reference to a data buffer.
Definition: buffer.h:81
common internal and external API header
AVBufferRef * av_hwframe_ctx_alloc(AVBufferRef *device_ref_in)
Allocate an AVHWFramesContext tied to a given device context.
Definition: hwcontext.c:177
mfxMemId * mem_ids_out
Definition: vf_scale_qsv.c:81
AVBufferRef * av_buffer_ref(AVBufferRef *buf)
Create a new reference to an AVBuffer.
Definition: buffer.c:92
int den
denominator
Definition: rational.h:45
#define AVERROR_UNKNOWN
Unknown error, typically from an external library.
Definition: error.h:61
static int init_out_pool(AVFilterContext *ctx, int out_width, int out_height)
Definition: vf_scale_qsv.c:162
static const mfxHandleType handle_types[]
Definition: vf_scale_qsv.c:256
#define NAN
Definition: math.h:28
mfxExtBuffer * ext_buffers[1]
Definition: vf_scale_qsv.c:91
char * h_expr
height expression string
Definition: vf_scale_qsv.c:108
A list of supported formats for one end of a filter link.
Definition: formats.h:64
static mfxStatus frame_lock(mfxHDL pthis, mfxMemId mid, mfxFrameData *ptr)
Definition: vf_scale_qsv.c:240
An instance of a filter.
Definition: avfilter.h:262
static void * av_mallocz_array(size_t nmemb, size_t size)
Definition: mem.h:205
int height
Definition: frame.h:179
FILE * out
Definition: movenc.c:54
static const char *const var_names[]
Definition: vf_scale_qsv.c:45
An API-specific header for AV_HWDEVICE_TYPE_QSV.
char * w_expr
width expression string
Definition: vf_scale_qsv.c:107
enum AVPixelFormat av_get_pix_fmt(const char *name)
Return the pixel format corresponding to name.
Definition: pixdesc.c:1716
internal API functions
#define FLAGS
Definition: vf_scale_qsv.c:586
enum AVPixelFormat sw_format
The pixel format identifying the actual data layout of the hardware frames.
Definition: hwcontext.h:215
AVPixelFormat
Pixel format.
Definition: pixfmt.h:57
int av_frame_copy_props(AVFrame *dst, const AVFrame *src)
Copy only "metadata" fields from src to dst.
Definition: frame.c:386
var_name
Definition: setpts.c:61
simple arithmetic expression evaluator