FFmpeg
vf_vpp_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  ** Hardware accelerated common filters based on Intel Quick Sync Video VPP
22  **/
23 
24 #include <float.h>
25 
26 #include "libavutil/opt.h"
27 #include "libavutil/eval.h"
28 #include "libavutil/avassert.h"
29 #include "libavutil/pixdesc.h"
30 #include "libavutil/mathematics.h"
31 
32 #include "formats.h"
33 #include "internal.h"
34 #include "avfilter.h"
35 #include "libavcodec/avcodec.h"
36 #include "libavformat/avformat.h"
37 
38 #include "qsvvpp.h"
39 
40 #define OFFSET(x) offsetof(VPPContext, x)
41 #define FLAGS (AV_OPT_FLAG_VIDEO_PARAM | AV_OPT_FLAG_FILTERING_PARAM)
42 
43 /* number of video enhancement filters */
44 #define ENH_FILTERS_COUNT (5)
45 
46 typedef struct VPPContext{
47  const AVClass *class;
48 
50 
51  /* Video Enhancement Algorithms */
52  mfxExtVPPDeinterlacing deinterlace_conf;
53  mfxExtVPPFrameRateConversion frc_conf;
54  mfxExtVPPDenoise denoise_conf;
55  mfxExtVPPDetail detail_conf;
56  mfxExtVPPProcAmp procamp_conf;
57 
58  int out_width;
60  /**
61  * Output sw format. AV_PIX_FMT_NONE for no conversion.
62  */
64 
65  AVRational framerate; /* target framerate */
66  int use_frc; /* use framerate conversion */
67  int deinterlace; /* deinterlace mode : 0=off, 1=bob, 2=advanced */
68  int denoise; /* Enable Denoise algorithm. Value [0, 100] */
69  int detail; /* Enable Detail Enhancement algorithm. */
70  /* Level is the optional, value [0, 100] */
71  int use_crop; /* 1 = use crop; 0=none */
72  int crop_w;
73  int crop_h;
74  int crop_x;
75  int crop_y;
76 
77  /* param for the procamp */
78  int procamp; /* enable procamp */
79  float hue;
80  float saturation;
81  float contrast;
82  float brightness;
83 
84  char *cx, *cy, *cw, *ch;
85  char *ow, *oh;
87 } VPPContext;
88 
89 static const AVOption options[] = {
90  { "deinterlace", "deinterlace mode: 0=off, 1=bob, 2=advanced", OFFSET(deinterlace), AV_OPT_TYPE_INT, { .i64 = 0 }, 0, MFX_DEINTERLACING_ADVANCED, .flags = FLAGS, "deinterlace" },
91  { "bob", "Bob deinterlace mode.", 0, AV_OPT_TYPE_CONST, { .i64 = MFX_DEINTERLACING_BOB }, .flags = FLAGS, "deinterlace" },
92  { "advanced", "Advanced deinterlace mode. ", 0, AV_OPT_TYPE_CONST, { .i64 = MFX_DEINTERLACING_ADVANCED }, .flags = FLAGS, "deinterlace" },
93 
94  { "denoise", "denoise level [0, 100]", OFFSET(denoise), AV_OPT_TYPE_INT, { .i64 = 0 }, 0, 100, .flags = FLAGS },
95  { "detail", "enhancement level [0, 100]", OFFSET(detail), AV_OPT_TYPE_INT, { .i64 = 0 }, 0, 100, .flags = FLAGS },
96  { "framerate", "output framerate", OFFSET(framerate), AV_OPT_TYPE_RATIONAL, { .dbl = 0.0 },0, DBL_MAX, .flags = FLAGS },
97  { "procamp", "Enable ProcAmp", OFFSET(procamp), AV_OPT_TYPE_INT, { .i64 = 0 }, 0, 1, .flags = FLAGS},
98  { "hue", "ProcAmp hue", OFFSET(hue), AV_OPT_TYPE_FLOAT, { .dbl = 0.0 }, -180.0, 180.0, .flags = FLAGS},
99  { "saturation", "ProcAmp saturation", OFFSET(saturation), AV_OPT_TYPE_FLOAT, { .dbl = 1.0 }, 0.0, 10.0, .flags = FLAGS},
100  { "contrast", "ProcAmp contrast", OFFSET(contrast), AV_OPT_TYPE_FLOAT, { .dbl = 1.0 }, 0.0, 10.0, .flags = FLAGS},
101  { "brightness", "ProcAmp brightness", OFFSET(brightness), AV_OPT_TYPE_FLOAT, { .dbl = 0.0 }, -100.0, 100.0, .flags = FLAGS},
102 
103  { "cw", "set the width crop area expression", OFFSET(cw), AV_OPT_TYPE_STRING, { .str = "iw" }, CHAR_MIN, CHAR_MAX, FLAGS },
104  { "ch", "set the height crop area expression", OFFSET(ch), AV_OPT_TYPE_STRING, { .str = "ih" }, CHAR_MIN, CHAR_MAX, FLAGS },
105  { "cx", "set the x crop area expression", OFFSET(cx), AV_OPT_TYPE_STRING, { .str = "(in_w-out_w)/2" }, CHAR_MIN, CHAR_MAX, FLAGS },
106  { "cy", "set the y crop area expression", OFFSET(cy), AV_OPT_TYPE_STRING, { .str = "(in_h-out_h)/2" }, CHAR_MIN, CHAR_MAX, FLAGS },
107 
108  { "w", "Output video width", OFFSET(ow), AV_OPT_TYPE_STRING, { .str="cw" }, 0, 255, .flags = FLAGS },
109  { "width", "Output video width", OFFSET(ow), AV_OPT_TYPE_STRING, { .str="cw" }, 0, 255, .flags = FLAGS },
110  { "h", "Output video height", OFFSET(oh), AV_OPT_TYPE_STRING, { .str="w*ch/cw" }, 0, 255, .flags = FLAGS },
111  { "height", "Output video height", OFFSET(oh), AV_OPT_TYPE_STRING, { .str="w*ch/cw" }, 0, 255, .flags = FLAGS },
112  { "format", "Output pixel format", OFFSET(output_format_str), AV_OPT_TYPE_STRING, { .str = "same" }, .flags = FLAGS },
113 
114  { NULL }
115 };
116 
117 static const char *const var_names[] = {
118  "iw", "in_w",
119  "ih", "in_h",
120  "ow", "out_w", "w",
121  "oh", "out_h", "h",
122  "cw",
123  "ch",
124  "cx",
125  "cy",
126  NULL
127 };
128 
129 enum var_name {
134  CW,
135  CH,
136  CX,
137  CY,
139 };
140 
142 {
143 #define PASS_EXPR(e, s) {\
144  ret = av_expr_parse(&e, s, var_names, NULL, NULL, NULL, NULL, 0, ctx); \
145  if (ret < 0) {\
146  av_log(ctx, AV_LOG_ERROR, "Error when passing '%s'.\n", s);\
147  goto release;\
148  }\
149 }
150 #define CALC_EXPR(e, v, i) {\
151  i = v = av_expr_eval(e, var_values, NULL); \
152 }
153  VPPContext *vpp = ctx->priv;
154  double var_values[VAR_VARS_NB] = { NAN };
155  AVExpr *w_expr = NULL, *h_expr = NULL;
156  AVExpr *cw_expr = NULL, *ch_expr = NULL;
157  AVExpr *cx_expr = NULL, *cy_expr = NULL;
158  int ret = 0;
159 
160  PASS_EXPR(cw_expr, vpp->cw);
161  PASS_EXPR(ch_expr, vpp->ch);
162 
163  PASS_EXPR(w_expr, vpp->ow);
164  PASS_EXPR(h_expr, vpp->oh);
165 
166  PASS_EXPR(cx_expr, vpp->cx);
167  PASS_EXPR(cy_expr, vpp->cy);
168 
169  var_values[VAR_iW] =
170  var_values[VAR_IN_W] = ctx->inputs[0]->w;
171 
172  var_values[VAR_iH] =
173  var_values[VAR_IN_H] = ctx->inputs[0]->h;
174 
175  /* crop params */
176  CALC_EXPR(cw_expr, var_values[CW], vpp->crop_w);
177  CALC_EXPR(ch_expr, var_values[CH], vpp->crop_h);
178 
179  /* calc again in case cw is relative to ch */
180  CALC_EXPR(cw_expr, var_values[CW], vpp->crop_w);
181 
182  CALC_EXPR(w_expr,
183  var_values[VAR_OUT_W] = var_values[VAR_oW] = var_values[VAR_W],
184  vpp->out_width);
185  CALC_EXPR(h_expr,
186  var_values[VAR_OUT_H] = var_values[VAR_oH] = var_values[VAR_H],
187  vpp->out_height);
188 
189  /* calc again in case ow is relative to oh */
190  CALC_EXPR(w_expr,
191  var_values[VAR_OUT_W] = var_values[VAR_oW] = var_values[VAR_W],
192  vpp->out_width);
193 
194 
195  CALC_EXPR(cx_expr, var_values[CX], vpp->crop_x);
196  CALC_EXPR(cy_expr, var_values[CY], vpp->crop_y);
197 
198  /* calc again in case cx is relative to cy */
199  CALC_EXPR(cx_expr, var_values[CX], vpp->crop_x);
200 
201  if ((vpp->crop_w != var_values[VAR_iW]) || (vpp->crop_h != var_values[VAR_iH]))
202  vpp->use_crop = 1;
203 
204 release:
205  av_expr_free(w_expr);
206  av_expr_free(h_expr);
207  av_expr_free(cw_expr);
208  av_expr_free(ch_expr);
209  av_expr_free(cx_expr);
210  av_expr_free(cy_expr);
211 #undef PASS_EXPR
212 #undef CALC_EXPR
213 
214  return ret;
215 }
216 
218 {
219  VPPContext *vpp = ctx->priv;
220 
221  if (!strcmp(vpp->output_format_str, "same")) {
223  } else {
225  if (vpp->out_format == AV_PIX_FMT_NONE) {
226  av_log(ctx, AV_LOG_ERROR, "Unrecognized output pixel format: %s\n", vpp->output_format_str);
227  return AVERROR(EINVAL);
228  }
229  }
230 
231  return 0;
232 }
233 
235 {
236  AVFilterContext *ctx = inlink->dst;
237  VPPContext *vpp = ctx->priv;
238  int ret;
239 
240  if (vpp->framerate.den == 0 || vpp->framerate.num == 0)
241  vpp->framerate = inlink->frame_rate;
242 
243  if (av_cmp_q(vpp->framerate, inlink->frame_rate))
244  vpp->use_frc = 1;
245 
246  ret = eval_expr(ctx);
247  if (ret != 0) {
248  av_log(ctx, AV_LOG_ERROR, "Fail to eval expr.\n");
249  return ret;
250  }
251 
252  if (vpp->out_height == 0 || vpp->out_width == 0) {
253  vpp->out_width = inlink->w;
254  vpp->out_height = inlink->h;
255  }
256 
257  if (vpp->use_crop) {
258  vpp->crop_x = FFMAX(vpp->crop_x, 0);
259  vpp->crop_y = FFMAX(vpp->crop_y, 0);
260 
261  if(vpp->crop_w + vpp->crop_x > inlink->w)
262  vpp->crop_x = inlink->w - vpp->crop_w;
263  if(vpp->crop_h + vpp->crop_y > inlink->h)
264  vpp->crop_y = inlink->h - vpp->crop_h;
265  }
266 
267  return 0;
268 }
269 
270 static int config_output(AVFilterLink *outlink)
271 {
272  AVFilterContext *ctx = outlink->src;
273  VPPContext *vpp = ctx->priv;
274  QSVVPPParam param = { NULL };
275  QSVVPPCrop crop = { 0 };
276  mfxExtBuffer *ext_buf[ENH_FILTERS_COUNT];
277  AVFilterLink *inlink = ctx->inputs[0];
278  enum AVPixelFormat in_format;
279 
280  outlink->w = vpp->out_width;
281  outlink->h = vpp->out_height;
282  outlink->frame_rate = vpp->framerate;
283  outlink->time_base = av_inv_q(vpp->framerate);
284 
285  param.filter_frame = NULL;
286  param.num_ext_buf = 0;
287  param.ext_buf = ext_buf;
288 
289  if (inlink->format == AV_PIX_FMT_QSV) {
290  if (!inlink->hw_frames_ctx || !inlink->hw_frames_ctx->data)
291  return AVERROR(EINVAL);
292  else
293  in_format = ((AVHWFramesContext*)inlink->hw_frames_ctx->data)->sw_format;
294  } else
295  in_format = inlink->format;
296 
297  param.out_sw_format = (vpp->out_format == AV_PIX_FMT_NONE) ? in_format : vpp->out_format;
298 
299  if (vpp->use_crop) {
300  crop.in_idx = 0;
301  crop.x = vpp->crop_x;
302  crop.y = vpp->crop_y;
303  crop.w = vpp->crop_w;
304  crop.h = vpp->crop_h;
305 
306  param.num_crop = 1;
307  param.crop = &crop;
308  }
309 
310  if (vpp->deinterlace) {
311  memset(&vpp->deinterlace_conf, 0, sizeof(mfxExtVPPDeinterlacing));
312  vpp->deinterlace_conf.Header.BufferId = MFX_EXTBUFF_VPP_DEINTERLACING;
313  vpp->deinterlace_conf.Header.BufferSz = sizeof(mfxExtVPPDeinterlacing);
314  vpp->deinterlace_conf.Mode = vpp->deinterlace == 1 ?
315  MFX_DEINTERLACING_BOB : MFX_DEINTERLACING_ADVANCED;
316 
317  param.ext_buf[param.num_ext_buf++] = (mfxExtBuffer*)&vpp->deinterlace_conf;
318  }
319 
320  if (vpp->use_frc) {
321  memset(&vpp->frc_conf, 0, sizeof(mfxExtVPPFrameRateConversion));
322  vpp->frc_conf.Header.BufferId = MFX_EXTBUFF_VPP_FRAME_RATE_CONVERSION;
323  vpp->frc_conf.Header.BufferSz = sizeof(mfxExtVPPFrameRateConversion);
324  vpp->frc_conf.Algorithm = MFX_FRCALGM_DISTRIBUTED_TIMESTAMP;
325 
326  param.ext_buf[param.num_ext_buf++] = (mfxExtBuffer*)&vpp->frc_conf;
327  }
328 
329  if (vpp->denoise) {
330  memset(&vpp->denoise_conf, 0, sizeof(mfxExtVPPDenoise));
331  vpp->denoise_conf.Header.BufferId = MFX_EXTBUFF_VPP_DENOISE;
332  vpp->denoise_conf.Header.BufferSz = sizeof(mfxExtVPPDenoise);
333  vpp->denoise_conf.DenoiseFactor = vpp->denoise;
334 
335  param.ext_buf[param.num_ext_buf++] = (mfxExtBuffer*)&vpp->denoise_conf;
336  }
337 
338  if (vpp->detail) {
339  memset(&vpp->detail_conf, 0, sizeof(mfxExtVPPDetail));
340  vpp->detail_conf.Header.BufferId = MFX_EXTBUFF_VPP_DETAIL;
341  vpp->detail_conf.Header.BufferSz = sizeof(mfxExtVPPDetail);
342  vpp->detail_conf.DetailFactor = vpp->detail;
343 
344  param.ext_buf[param.num_ext_buf++] = (mfxExtBuffer*)&vpp->detail_conf;
345  }
346 
347  if (vpp->procamp) {
348  memset(&vpp->procamp_conf, 0, sizeof(mfxExtVPPProcAmp));
349  vpp->procamp_conf.Header.BufferId = MFX_EXTBUFF_VPP_PROCAMP;
350  vpp->procamp_conf.Header.BufferSz = sizeof(mfxExtVPPProcAmp);
351  vpp->procamp_conf.Hue = vpp->hue;
352  vpp->procamp_conf.Saturation = vpp->saturation;
353  vpp->procamp_conf.Contrast = vpp->contrast;
354  vpp->procamp_conf.Brightness = vpp->brightness;
355 
356  param.ext_buf[param.num_ext_buf++] = (mfxExtBuffer*)&vpp->procamp_conf;
357  }
358 
359  if (vpp->use_frc || vpp->use_crop || vpp->deinterlace || vpp->denoise ||
360  vpp->detail || vpp->procamp || inlink->w != outlink->w || inlink->h != outlink->h)
361  return ff_qsvvpp_create(ctx, &vpp->qsv, &param);
362  else {
363  av_log(ctx, AV_LOG_VERBOSE, "qsv vpp pass through mode.\n");
364  if (inlink->hw_frames_ctx)
365  outlink->hw_frames_ctx = av_buffer_ref(inlink->hw_frames_ctx);
366  }
367 
368  return 0;
369 }
370 
372 {
373  int ret = 0;
374  AVFilterContext *ctx = inlink->dst;
375  VPPContext *vpp = inlink->dst->priv;
376  AVFilterLink *outlink = ctx->outputs[0];
377 
378  if (vpp->qsv) {
379  ret = ff_qsvvpp_filter_frame(vpp->qsv, inlink, picref);
380  av_frame_free(&picref);
381  } else {
382  if (picref->pts != AV_NOPTS_VALUE)
383  picref->pts = av_rescale_q(picref->pts, inlink->time_base, outlink->time_base);
384  ret = ff_filter_frame(outlink, picref);
385  }
386 
387  return ret;
388 }
389 
391 {
392  int ret;
393  AVFilterFormats *in_fmts, *out_fmts;
394  static const enum AVPixelFormat in_pix_fmts[] = {
401  };
402  static const enum AVPixelFormat out_pix_fmts[] = {
407  };
408 
409  in_fmts = ff_make_format_list(in_pix_fmts);
410  out_fmts = ff_make_format_list(out_pix_fmts);
411  ret = ff_formats_ref(in_fmts, &ctx->inputs[0]->out_formats);
412  if (ret < 0)
413  return ret;
414  ret = ff_formats_ref(out_fmts, &ctx->outputs[0]->in_formats);
415  if (ret < 0)
416  return ret;
417 
418  return 0;
419 }
420 
422 {
423  VPPContext *vpp = ctx->priv;
424 
425  ff_qsvvpp_free(&vpp->qsv);
426 }
427 
428 static const AVClass vpp_class = {
429  .class_name = "vpp_qsv",
430  .item_name = av_default_item_name,
431  .option = options,
432  .version = LIBAVUTIL_VERSION_INT,
433 };
434 
435 static const AVFilterPad vpp_inputs[] = {
436  {
437  .name = "default",
438  .type = AVMEDIA_TYPE_VIDEO,
439  .config_props = config_input,
440  .filter_frame = filter_frame,
441  },
442  { NULL }
443 };
444 
445 static const AVFilterPad vpp_outputs[] = {
446  {
447  .name = "default",
448  .type = AVMEDIA_TYPE_VIDEO,
449  .config_props = config_output,
450  },
451  { NULL }
452 };
453 
455  .name = "vpp_qsv",
456  .description = NULL_IF_CONFIG_SMALL("Quick Sync Video VPP."),
457  .priv_size = sizeof(VPPContext),
459  .init = vpp_init,
460  .uninit = vpp_uninit,
461  .inputs = vpp_inputs,
462  .outputs = vpp_outputs,
463  .priv_class = &vpp_class,
464  .flags_internal = FF_FILTER_FLAG_HWFRAME_AWARE,
465 };
VAR_oW
@ VAR_oW
Definition: vf_vpp_qsv.c:132
QSVVPPCrop::in_idx
int in_idx
Input index.
Definition: qsvvpp.h:45
AVPixelFormat
AVPixelFormat
Pixel format.
Definition: pixfmt.h:64
init
static av_cold int init(AVCodecContext *avctx)
Definition: avrndec.c:35
AVERROR
Filter the word “frame” indicates either a video frame or a group of audio as stored in an AVFrame structure Format for each input and each output the list of supported formats For video that means pixel format For audio that means channel sample they are references to shared objects When the negotiation mechanism computes the intersection of the formats supported at each end of a all references to both lists are replaced with a reference to the intersection And when a single format is eventually chosen for a link amongst the remaining all references to the list are updated That means that if a filter requires that its input and output have the same format amongst a supported all it has to do is use a reference to the same list of formats query_formats can leave some formats unset and return AVERROR(EAGAIN) to cause the negotiation mechanism toagain later. That can be used by filters with complex requirements to use the format negotiated on one link to set the formats supported on another. Frame references ownership and permissions
opt.h
ff_make_format_list
AVFilterFormats * ff_make_format_list(const int *fmts)
Create a list of supported formats.
Definition: formats.c:283
OFFSET
#define OFFSET(x)
Definition: vf_vpp_qsv.c:40
FF_FILTER_FLAG_HWFRAME_AWARE
#define FF_FILTER_FLAG_HWFRAME_AWARE
The filter is aware of hardware frames, and any hardware frame context should not be automatically pr...
Definition: internal.h:385
QSVVPPParam::crop
QSVVPPCrop * crop
Definition: qsvvpp.h:62
QSVVPPParam::out_sw_format
enum AVPixelFormat out_sw_format
Definition: qsvvpp.h:58
ff_filter_frame
int ff_filter_frame(AVFilterLink *link, AVFrame *frame)
Send a frame of data to the next filter.
Definition: avfilter.c:1080
VPPContext::cx
char * cx
Definition: vf_vpp_qsv.c:84
ch
uint8_t pi<< 24) CONV_FUNC(AV_SAMPLE_FMT_S64, int64_t, AV_SAMPLE_FMT_U8,(uint64_t)((*(const uint8_t *) pi - 0x80U))<< 56) CONV_FUNC(AV_SAMPLE_FMT_FLT, float, AV_SAMPLE_FMT_U8,(*(const uint8_t *) pi - 0x80) *(1.0f/(1<< 7))) CONV_FUNC(AV_SAMPLE_FMT_DBL, double, AV_SAMPLE_FMT_U8,(*(const uint8_t *) pi - 0x80) *(1.0/(1<< 7))) CONV_FUNC(AV_SAMPLE_FMT_U8, uint8_t, AV_SAMPLE_FMT_S16,(*(const int16_t *) pi >>8)+0x80) CONV_FUNC(AV_SAMPLE_FMT_S64, int64_t, AV_SAMPLE_FMT_S16,(uint64_t)(*(const int16_t *) pi)<< 48) CONV_FUNC(AV_SAMPLE_FMT_FLT, float, AV_SAMPLE_FMT_S16, *(const int16_t *) pi *(1.0f/(1<< 15))) CONV_FUNC(AV_SAMPLE_FMT_DBL, double, AV_SAMPLE_FMT_S16, *(const int16_t *) pi *(1.0/(1<< 15))) CONV_FUNC(AV_SAMPLE_FMT_U8, uint8_t, AV_SAMPLE_FMT_S32,(*(const int32_t *) pi >>24)+0x80) CONV_FUNC(AV_SAMPLE_FMT_S64, int64_t, AV_SAMPLE_FMT_S32,(uint64_t)(*(const int32_t *) pi)<< 32) CONV_FUNC(AV_SAMPLE_FMT_FLT, float, AV_SAMPLE_FMT_S32, *(const int32_t *) pi *(1.0f/(1U<< 31))) CONV_FUNC(AV_SAMPLE_FMT_DBL, double, AV_SAMPLE_FMT_S32, *(const int32_t *) pi *(1.0/(1U<< 31))) CONV_FUNC(AV_SAMPLE_FMT_U8, uint8_t, AV_SAMPLE_FMT_S64,(*(const int64_t *) pi >>56)+0x80) CONV_FUNC(AV_SAMPLE_FMT_FLT, float, AV_SAMPLE_FMT_S64, *(const int64_t *) pi *(1.0f/(INT64_C(1)<< 63))) CONV_FUNC(AV_SAMPLE_FMT_DBL, double, AV_SAMPLE_FMT_S64, *(const int64_t *) pi *(1.0/(INT64_C(1)<< 63))) CONV_FUNC(AV_SAMPLE_FMT_U8, uint8_t, AV_SAMPLE_FMT_FLT, av_clip_uint8(lrintf(*(const float *) pi *(1<< 7))+0x80)) CONV_FUNC(AV_SAMPLE_FMT_S16, int16_t, AV_SAMPLE_FMT_FLT, av_clip_int16(lrintf(*(const float *) pi *(1<< 15)))) CONV_FUNC(AV_SAMPLE_FMT_S32, int32_t, AV_SAMPLE_FMT_FLT, av_clipl_int32(llrintf(*(const float *) pi *(1U<< 31)))) CONV_FUNC(AV_SAMPLE_FMT_S64, int64_t, AV_SAMPLE_FMT_FLT, llrintf(*(const float *) pi *(INT64_C(1)<< 63))) CONV_FUNC(AV_SAMPLE_FMT_U8, uint8_t, AV_SAMPLE_FMT_DBL, av_clip_uint8(lrint(*(const double *) pi *(1<< 7))+0x80)) CONV_FUNC(AV_SAMPLE_FMT_S16, int16_t, AV_SAMPLE_FMT_DBL, av_clip_int16(lrint(*(const double *) pi *(1<< 15)))) CONV_FUNC(AV_SAMPLE_FMT_S32, int32_t, AV_SAMPLE_FMT_DBL, av_clipl_int32(llrint(*(const double *) pi *(1U<< 31)))) CONV_FUNC(AV_SAMPLE_FMT_S64, int64_t, AV_SAMPLE_FMT_DBL, llrint(*(const double *) pi *(INT64_C(1)<< 63))) #define FMT_PAIR_FUNC(out, in) static conv_func_type *const fmt_pair_to_conv_functions[AV_SAMPLE_FMT_NB *AV_SAMPLE_FMT_NB]={ FMT_PAIR_FUNC(AV_SAMPLE_FMT_U8, AV_SAMPLE_FMT_U8), FMT_PAIR_FUNC(AV_SAMPLE_FMT_S16, AV_SAMPLE_FMT_U8), FMT_PAIR_FUNC(AV_SAMPLE_FMT_S32, AV_SAMPLE_FMT_U8), FMT_PAIR_FUNC(AV_SAMPLE_FMT_FLT, AV_SAMPLE_FMT_U8), FMT_PAIR_FUNC(AV_SAMPLE_FMT_DBL, AV_SAMPLE_FMT_U8), FMT_PAIR_FUNC(AV_SAMPLE_FMT_S64, AV_SAMPLE_FMT_U8), FMT_PAIR_FUNC(AV_SAMPLE_FMT_U8, AV_SAMPLE_FMT_S16), FMT_PAIR_FUNC(AV_SAMPLE_FMT_S16, AV_SAMPLE_FMT_S16), FMT_PAIR_FUNC(AV_SAMPLE_FMT_S32, AV_SAMPLE_FMT_S16), FMT_PAIR_FUNC(AV_SAMPLE_FMT_FLT, AV_SAMPLE_FMT_S16), FMT_PAIR_FUNC(AV_SAMPLE_FMT_DBL, AV_SAMPLE_FMT_S16), FMT_PAIR_FUNC(AV_SAMPLE_FMT_S64, AV_SAMPLE_FMT_S16), FMT_PAIR_FUNC(AV_SAMPLE_FMT_U8, AV_SAMPLE_FMT_S32), FMT_PAIR_FUNC(AV_SAMPLE_FMT_S16, AV_SAMPLE_FMT_S32), FMT_PAIR_FUNC(AV_SAMPLE_FMT_S32, AV_SAMPLE_FMT_S32), FMT_PAIR_FUNC(AV_SAMPLE_FMT_FLT, AV_SAMPLE_FMT_S32), FMT_PAIR_FUNC(AV_SAMPLE_FMT_DBL, AV_SAMPLE_FMT_S32), FMT_PAIR_FUNC(AV_SAMPLE_FMT_S64, AV_SAMPLE_FMT_S32), FMT_PAIR_FUNC(AV_SAMPLE_FMT_U8, AV_SAMPLE_FMT_FLT), FMT_PAIR_FUNC(AV_SAMPLE_FMT_S16, AV_SAMPLE_FMT_FLT), FMT_PAIR_FUNC(AV_SAMPLE_FMT_S32, AV_SAMPLE_FMT_FLT), FMT_PAIR_FUNC(AV_SAMPLE_FMT_FLT, AV_SAMPLE_FMT_FLT), FMT_PAIR_FUNC(AV_SAMPLE_FMT_DBL, AV_SAMPLE_FMT_FLT), FMT_PAIR_FUNC(AV_SAMPLE_FMT_S64, AV_SAMPLE_FMT_FLT), FMT_PAIR_FUNC(AV_SAMPLE_FMT_U8, AV_SAMPLE_FMT_DBL), FMT_PAIR_FUNC(AV_SAMPLE_FMT_S16, AV_SAMPLE_FMT_DBL), FMT_PAIR_FUNC(AV_SAMPLE_FMT_S32, AV_SAMPLE_FMT_DBL), FMT_PAIR_FUNC(AV_SAMPLE_FMT_FLT, AV_SAMPLE_FMT_DBL), FMT_PAIR_FUNC(AV_SAMPLE_FMT_DBL, AV_SAMPLE_FMT_DBL), FMT_PAIR_FUNC(AV_SAMPLE_FMT_S64, AV_SAMPLE_FMT_DBL), FMT_PAIR_FUNC(AV_SAMPLE_FMT_U8, AV_SAMPLE_FMT_S64), FMT_PAIR_FUNC(AV_SAMPLE_FMT_S16, AV_SAMPLE_FMT_S64), FMT_PAIR_FUNC(AV_SAMPLE_FMT_S32, AV_SAMPLE_FMT_S64), FMT_PAIR_FUNC(AV_SAMPLE_FMT_FLT, AV_SAMPLE_FMT_S64), FMT_PAIR_FUNC(AV_SAMPLE_FMT_DBL, AV_SAMPLE_FMT_S64), FMT_PAIR_FUNC(AV_SAMPLE_FMT_S64, AV_SAMPLE_FMT_S64), };static void cpy1(uint8_t **dst, const uint8_t **src, int len){ memcpy(*dst, *src, len);} static void cpy2(uint8_t **dst, const uint8_t **src, int len){ memcpy(*dst, *src, 2 *len);} static void cpy4(uint8_t **dst, const uint8_t **src, int len){ memcpy(*dst, *src, 4 *len);} static void cpy8(uint8_t **dst, const uint8_t **src, int len){ memcpy(*dst, *src, 8 *len);} AudioConvert *swri_audio_convert_alloc(enum AVSampleFormat out_fmt, enum AVSampleFormat in_fmt, int channels, const int *ch_map, int flags) { AudioConvert *ctx;conv_func_type *f=fmt_pair_to_conv_functions[av_get_packed_sample_fmt(out_fmt)+AV_SAMPLE_FMT_NB *av_get_packed_sample_fmt(in_fmt)];if(!f) return NULL;ctx=av_mallocz(sizeof(*ctx));if(!ctx) return NULL;if(channels==1){ in_fmt=av_get_planar_sample_fmt(in_fmt);out_fmt=av_get_planar_sample_fmt(out_fmt);} ctx->channels=channels;ctx->conv_f=f;ctx->ch_map=ch_map;if(in_fmt==AV_SAMPLE_FMT_U8||in_fmt==AV_SAMPLE_FMT_U8P) memset(ctx->silence, 0x80, sizeof(ctx->silence));if(out_fmt==in_fmt &&!ch_map) { switch(av_get_bytes_per_sample(in_fmt)){ case 1:ctx->simd_f=cpy1;break;case 2:ctx->simd_f=cpy2;break;case 4:ctx->simd_f=cpy4;break;case 8:ctx->simd_f=cpy8;break;} } if(HAVE_X86ASM &&1) swri_audio_convert_init_x86(ctx, out_fmt, in_fmt, channels);if(ARCH_ARM) swri_audio_convert_init_arm(ctx, out_fmt, in_fmt, channels);if(ARCH_AARCH64) swri_audio_convert_init_aarch64(ctx, out_fmt, in_fmt, channels);return ctx;} void swri_audio_convert_free(AudioConvert **ctx) { av_freep(ctx);} int swri_audio_convert(AudioConvert *ctx, AudioData *out, AudioData *in, int len) { int ch;int off=0;const int os=(out->planar ? 1 :out->ch_count) *out->bps;unsigned misaligned=0;av_assert0(ctx->channels==out->ch_count);if(ctx->in_simd_align_mask) { int planes=in->planar ? in->ch_count :1;unsigned m=0;for(ch=0;ch< planes;ch++) m|=(intptr_t) in->ch[ch];misaligned|=m &ctx->in_simd_align_mask;} if(ctx->out_simd_align_mask) { int planes=out->planar ? out->ch_count :1;unsigned m=0;for(ch=0;ch< planes;ch++) m|=(intptr_t) out->ch[ch];misaligned|=m &ctx->out_simd_align_mask;} if(ctx->simd_f &&!ctx->ch_map &&!misaligned){ off=len &~15;av_assert1(off >=0);av_assert1(off<=len);av_assert2(ctx->channels==SWR_CH_MAX||!in->ch[ctx->channels]);if(off >0){ if(out->planar==in->planar){ int planes=out->planar ? out->ch_count :1;for(ch=0;ch< planes;ch++){ ctx->simd_f(out-> ch ch
Definition: audioconvert.c:56
inlink
The exact code depends on how similar the blocks are and how related they are to the and needs to apply these operations to the correct inlink or outlink if there are several Macros are available to factor that when no extra processing is inlink
Definition: filter_design.txt:212
VPPContext::crop_w
int crop_w
Definition: vf_vpp_qsv.c:72
VPPContext::crop_h
int crop_h
Definition: vf_vpp_qsv.c:73
VPPContext::detail
int detail
Definition: vf_vpp_qsv.c:69
av_frame_free
void av_frame_free(AVFrame **frame)
Free the frame and any dynamically allocated objects in it, e.g.
Definition: frame.c:202
AVFrame
This structure describes decoded (raw) audio or video data.
Definition: frame.h:295
pixdesc.h
AVFrame::pts
int64_t pts
Presentation timestamp in time_base units (time when frame should be shown to user).
Definition: frame.h:388
AVOption
AVOption.
Definition: opt.h:246
VPPContext::contrast
float contrast
Definition: vf_vpp_qsv.c:81
vpp_uninit
static av_cold void vpp_uninit(AVFilterContext *ctx)
Definition: vf_vpp_qsv.c:421
VPPContext::qsv
QSVVPPContext * qsv
Definition: vf_vpp_qsv.c:49
AV_LOG_VERBOSE
#define AV_LOG_VERBOSE
Detailed information.
Definition: log.h:192
float.h
VAR_OUT_H
@ VAR_OUT_H
Definition: vf_vpp_qsv.c:133
VPPContext::hue
float hue
Definition: vf_vpp_qsv.c:79
mathematics.h
CY
@ CY
Definition: vf_vpp_qsv.c:137
VAR_IN_H
@ VAR_IN_H
Definition: vf_vpp_qsv.c:131
AVFilter::name
const char * name
Filter name.
Definition: avfilter.h:148
AV_OPT_TYPE_RATIONAL
@ AV_OPT_TYPE_RATIONAL
Definition: opt.h:228
AVFilterFormats
A list of supported formats for one end of a filter link.
Definition: formats.h:64
formats.h
framerate
int framerate
Definition: h264_levels.c:65
VAR_oH
@ VAR_oH
Definition: vf_vpp_qsv.c:133
VPPContext::saturation
float saturation
Definition: vf_vpp_qsv.c:80
qsvvpp.h
VAR_IN_W
@ VAR_IN_W
Definition: vf_vpp_qsv.c:130
PASS_EXPR
#define PASS_EXPR(e, s)
VPPContext::out_format
enum AVPixelFormat out_format
Output sw format.
Definition: vf_vpp_qsv.c:63
av_expr_free
void av_expr_free(AVExpr *e)
Free a parsed expression previously created with av_expr_parse().
Definition: eval.c:334
AVRational::num
int num
Numerator.
Definition: rational.h:59
AVFilterPad
A filter pad used for either input or output.
Definition: internal.h:54
VPPContext::out_width
int out_width
Definition: vf_vpp_qsv.c:58
FLAGS
#define FLAGS
Definition: vf_vpp_qsv.c:41
in_pix_fmts
static enum AVPixelFormat in_pix_fmts[]
Definition: vf_ciescope.c:121
avassert.h
VPPContext::crop_x
int crop_x
Definition: vf_vpp_qsv.c:74
AV_LOG_ERROR
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
Definition: log.h:176
av_cold
#define av_cold
Definition: attributes.h:84
VPPContext::use_frc
int use_frc
Definition: vf_vpp_qsv.c:66
QSVVPPCrop::w
int w
Definition: qsvvpp.h:46
VPPContext::denoise_conf
mfxExtVPPDenoise denoise_conf
Definition: vf_vpp_qsv.c:54
ff_qsvvpp_create
int ff_qsvvpp_create(AVFilterContext *avctx, QSVVPPContext **vpp, QSVVPPParam *param)
Definition: qsvvpp.c:561
ff_formats_ref
int ff_formats_ref(AVFilterFormats *f, AVFilterFormats **ref)
Add *ref as a new reference to formats.
Definition: formats.c:440
outputs
static const AVFilterPad outputs[]
Definition: af_acontrast.c:203
ctx
AVFormatContext * ctx
Definition: movenc.c:48
av_rescale_q
int64_t av_rescale_q(int64_t a, AVRational bq, AVRational cq)
Rescale a 64-bit integer by 2 rational numbers.
Definition: mathematics.c:142
AVExpr
Definition: eval.c:157
VPPContext::detail_conf
mfxExtVPPDetail detail_conf
Definition: vf_vpp_qsv.c:55
AV_PIX_FMT_YUV420P
@ AV_PIX_FMT_YUV420P
planar YUV 4:2:0, 12bpp, (1 Cr & Cb sample per 2x2 Y samples)
Definition: pixfmt.h:66
NAN
#define NAN
Definition: mathematics.h:64
options
static const AVOption options[]
Definition: vf_vpp_qsv.c:89
if
if(ret)
Definition: filter_design.txt:179
VAR_iW
@ VAR_iW
Definition: vf_vpp_qsv.c:130
QSVVPPContext
Definition: qsvvpp.c:48
LIBAVUTIL_VERSION_INT
#define LIBAVUTIL_VERSION_INT
Definition: version.h:85
AVClass
Describe the class of an AVClass context structure.
Definition: log.h:67
NULL
#define NULL
Definition: coverity.c:32
ENH_FILTERS_COUNT
#define ENH_FILTERS_COUNT
Definition: vf_vpp_qsv.c:44
QSVVPPParam::num_crop
int num_crop
Definition: qsvvpp.h:61
QSVVPPParam
Definition: qsvvpp.h:49
QSVVPPCrop::x
int x
Definition: qsvvpp.h:46
VPPContext::cw
char * cw
Definition: vf_vpp_qsv.c:84
AV_PIX_FMT_YUYV422
@ AV_PIX_FMT_YUYV422
packed YUV 4:2:2, 16bpp, Y0 Cb Y1 Cr
Definition: pixfmt.h:67
AVRational
Rational number (pair of numerator and denominator).
Definition: rational.h:58
av_default_item_name
const char * av_default_item_name(void *ptr)
Return the context name.
Definition: log.c:191
VPPContext::deinterlace
int deinterlace
Definition: vf_vpp_qsv.c:67
CALC_EXPR
#define CALC_EXPR(e, v, i)
VAR_H
@ VAR_H
Definition: vf_vpp_qsv.c:133
VPPContext::deinterlace_conf
mfxExtVPPDeinterlacing deinterlace_conf
Definition: vf_vpp_qsv.c:52
VPPContext::frc_conf
mfxExtVPPFrameRateConversion frc_conf
Definition: vf_vpp_qsv.c:53
vpp_inputs
static const AVFilterPad vpp_inputs[]
Definition: vf_vpp_qsv.c:435
VPPContext::denoise
int denoise
Definition: vf_vpp_qsv.c:68
inputs
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
Definition: filter_design.txt:243
AV_PIX_FMT_QSV
@ AV_PIX_FMT_QSV
HW acceleration through QSV, data[3] contains a pointer to the mfxFrameSurface1 structure.
Definition: pixfmt.h:222
VPPContext
Definition: vf_vpp_qsv.c:46
ff_qsvvpp_free
int ff_qsvvpp_free(QSVVPPContext **vpp)
Definition: qsvvpp.c:664
VPPContext::ow
char * ow
Definition: vf_vpp_qsv.c:85
query_formats
static int query_formats(AVFilterContext *ctx)
Definition: vf_vpp_qsv.c:390
eval.h
NULL_IF_CONFIG_SMALL
#define NULL_IF_CONFIG_SMALL(x)
Return NULL if CONFIG_SMALL is true, otherwise the argument without modification.
Definition: internal.h:188
var_name
var_name
Definition: aeval.c:46
VAR_W
@ VAR_W
Definition: vf_vpp_qsv.c:132
config_input
static int config_input(AVFilterLink *inlink)
Definition: vf_vpp_qsv.c:234
FFMAX
#define FFMAX(a, b)
Definition: common.h:94
VAR_iH
@ VAR_iH
Definition: vf_vpp_qsv.c:131
AV_NOPTS_VALUE
#define AV_NOPTS_VALUE
Undefined timestamp value.
Definition: avutil.h:248
VAR_OUT_W
@ VAR_OUT_W
Definition: vf_vpp_qsv.c:132
VPPContext::output_format_str
char * output_format_str
Definition: vf_vpp_qsv.c:86
VAR_VARS_NB
@ VAR_VARS_NB
Definition: vf_vpp_qsv.c:138
VPPContext::ch
char * ch
Definition: vf_vpp_qsv.c:84
VPPContext::procamp_conf
mfxExtVPPProcAmp procamp_conf
Definition: vf_vpp_qsv.c:56
CH
@ CH
Definition: vf_vpp_qsv.c:135
AV_PIX_FMT_RGB32
#define AV_PIX_FMT_RGB32
Definition: pixfmt.h:360
internal.h
AV_OPT_TYPE_FLOAT
@ AV_OPT_TYPE_FLOAT
Definition: opt.h:226
denoise
#define denoise(...)
Definition: vf_hqdn3d.c:156
config_output
static int config_output(AVFilterLink *outlink)
Definition: vf_vpp_qsv.c:270
ff_vf_vpp_qsv
AVFilter ff_vf_vpp_qsv
Definition: vf_vpp_qsv.c:454
out_pix_fmts
static enum AVPixelFormat out_pix_fmts[]
Definition: vf_ciescope.c:130
QSVVPPParam::num_ext_buf
int num_ext_buf
Definition: qsvvpp.h:54
av_inv_q
static av_always_inline AVRational av_inv_q(AVRational q)
Invert a rational.
Definition: rational.h:159
QSVVPPParam::filter_frame
int(* filter_frame)(AVFilterLink *outlink, AVFrame *frame)
Definition: qsvvpp.h:51
VPPContext::crop_y
int crop_y
Definition: vf_vpp_qsv.c:75
VPPContext::framerate
AVRational framerate
Definition: vf_vpp_qsv.c:65
AVFilterPad::name
const char * name
Pad name.
Definition: internal.h:60
VPPContext::out_height
int out_height
Definition: vf_vpp_qsv.c:59
filter_frame
static int filter_frame(AVFilterLink *inlink, AVFrame *picref)
Definition: vf_vpp_qsv.c:371
vpp_init
static av_cold int vpp_init(AVFilterContext *ctx)
Definition: vf_vpp_qsv.c:217
avcodec.h
av_cmp_q
static int av_cmp_q(AVRational a, AVRational b)
Compare two rationals.
Definition: rational.h:89
AVFilter
Filter definition.
Definition: avfilter.h:144
AVHWFramesContext
This struct describes a set or pool of "hardware" frames (i.e.
Definition: hwcontext.h:123
ret
ret
Definition: filter_design.txt:187
AV_PIX_FMT_NV12
@ AV_PIX_FMT_NV12
planar YUV 4:2:0, 12bpp, 1 plane for Y and 1 plane for the UV components, which are interleaved (firs...
Definition: pixfmt.h:89
AVClass::class_name
const char * class_name
The name of the class; usually it is the same name as the context structure type to which the AVClass...
Definition: log.h:72
avformat.h
av_get_pix_fmt
enum AVPixelFormat av_get_pix_fmt(const char *name)
Return the pixel format corresponding to name.
Definition: pixdesc.c:2450
QSVVPPCrop::h
int h
Crop rectangle.
Definition: qsvvpp.h:46
QSVVPPCrop::y
int y
Definition: qsvvpp.h:46
VPPContext::oh
char * oh
Definition: vf_vpp_qsv.c:85
ff_qsvvpp_filter_frame
int ff_qsvvpp_filter_frame(QSVVPPContext *s, AVFilterLink *inlink, AVFrame *picref)
Definition: qsvvpp.c:688
eval_expr
static int eval_expr(AVFilterContext *ctx)
Definition: vf_vpp_qsv.c:141
AVRational::den
int den
Denominator.
Definition: rational.h:60
AV_PIX_FMT_NONE
@ AV_PIX_FMT_NONE
Definition: pixfmt.h:65
AV_OPT_TYPE_INT
@ AV_OPT_TYPE_INT
Definition: opt.h:223
avfilter.h
vpp_class
static const AVClass vpp_class
Definition: vf_vpp_qsv.c:428
VPPContext::use_crop
int use_crop
Definition: vf_vpp_qsv.c:71
VPPContext::cy
char * cy
Definition: vf_vpp_qsv.c:84
av_buffer_ref
AVBufferRef * av_buffer_ref(AVBufferRef *buf)
Create a new reference to an AVBuffer.
Definition: buffer.c:93
AVFilterContext
An instance of a filter.
Definition: avfilter.h:338
AV_PIX_FMT_P010
#define AV_PIX_FMT_P010
Definition: pixfmt.h:436
AVMEDIA_TYPE_VIDEO
@ AVMEDIA_TYPE_VIDEO
Definition: avutil.h:201
var_names
static const char *const var_names[]
Definition: vf_vpp_qsv.c:117
CW
@ CW
Definition: vf_vpp_qsv.c:134
CX
@ CX
Definition: vf_vpp_qsv.c:136
av_log
#define av_log(a,...)
Definition: tableprint_vlc.h:28
uninit
static av_cold int uninit(AVCodecContext *avctx)
Definition: crystalhd.c:279
QSVVPPCrop
Definition: qsvvpp.h:44
AV_OPT_TYPE_STRING
@ AV_OPT_TYPE_STRING
Definition: opt.h:227
AV_OPT_TYPE_CONST
@ AV_OPT_TYPE_CONST
Definition: opt.h:232
VPPContext::brightness
float brightness
Definition: vf_vpp_qsv.c:82
VPPContext::procamp
int procamp
Definition: vf_vpp_qsv.c:78
QSVVPPParam::ext_buf
mfxExtBuffer ** ext_buf
Definition: qsvvpp.h:55
vpp_outputs
static const AVFilterPad vpp_outputs[]
Definition: vf_vpp_qsv.c:445