FFmpeg
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
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  AVRational framerate; /* target framerate */
62  int use_frc; /* use framerate conversion */
63  int deinterlace; /* deinterlace mode : 0=off, 1=bob, 2=advanced */
64  int denoise; /* Enable Denoise algorithm. Value [0, 100] */
65  int detail; /* Enable Detail Enhancement algorithm. */
66  /* Level is the optional, value [0, 100] */
67  int use_crop; /* 1 = use crop; 0=none */
68  int crop_w;
69  int crop_h;
70  int crop_x;
71  int crop_y;
72 
73  /* param for the procamp */
74  int procamp; /* enable procamp */
75  float hue;
76  float saturation;
77  float contrast;
78  float brightness;
79 
80  char *cx, *cy, *cw, *ch;
81  char *ow, *oh;
82 } VPPContext;
83 
84 static const AVOption options[] = {
85  { "deinterlace", "deinterlace mode: 0=off, 1=bob, 2=advanced", OFFSET(deinterlace), AV_OPT_TYPE_INT, { .i64 = 0 }, 0, MFX_DEINTERLACING_ADVANCED, .flags = FLAGS, "deinterlace" },
86  { "bob", "Bob deinterlace mode.", 0, AV_OPT_TYPE_CONST, { .i64 = MFX_DEINTERLACING_BOB }, .flags = FLAGS, "deinterlace" },
87  { "advanced", "Advanced deinterlace mode. ", 0, AV_OPT_TYPE_CONST, { .i64 = MFX_DEINTERLACING_ADVANCED }, .flags = FLAGS, "deinterlace" },
88 
89  { "denoise", "denoise level [0, 100]", OFFSET(denoise), AV_OPT_TYPE_INT, { .i64 = 0 }, 0, 100, .flags = FLAGS },
90  { "detail", "enhancement level [0, 100]", OFFSET(detail), AV_OPT_TYPE_INT, { .i64 = 0 }, 0, 100, .flags = FLAGS },
91  { "framerate", "output framerate", OFFSET(framerate), AV_OPT_TYPE_RATIONAL, { .dbl = 0.0 },0, DBL_MAX, .flags = FLAGS },
92  { "procamp", "Enable ProcAmp", OFFSET(procamp), AV_OPT_TYPE_INT, { .i64 = 0 }, 0, 1, .flags = FLAGS},
93  { "hue", "ProcAmp hue", OFFSET(hue), AV_OPT_TYPE_FLOAT, { .dbl = 0.0 }, -180.0, 180.0, .flags = FLAGS},
94  { "saturation", "ProcAmp saturation", OFFSET(saturation), AV_OPT_TYPE_FLOAT, { .dbl = 1.0 }, 0.0, 10.0, .flags = FLAGS},
95  { "contrast", "ProcAmp contrast", OFFSET(contrast), AV_OPT_TYPE_FLOAT, { .dbl = 1.0 }, 0.0, 10.0, .flags = FLAGS},
96  { "brightness", "ProcAmp brightness", OFFSET(brightness), AV_OPT_TYPE_FLOAT, { .dbl = 0.0 }, -100.0, 100.0, .flags = FLAGS},
97 
98  { "cw", "set the width crop area expression", OFFSET(cw), AV_OPT_TYPE_STRING, { .str = "iw" }, CHAR_MIN, CHAR_MAX, FLAGS },
99  { "ch", "set the height crop area expression", OFFSET(ch), AV_OPT_TYPE_STRING, { .str = "ih" }, CHAR_MIN, CHAR_MAX, FLAGS },
100  { "cx", "set the x crop area expression", OFFSET(cx), AV_OPT_TYPE_STRING, { .str = "(in_w-out_w)/2" }, CHAR_MIN, CHAR_MAX, FLAGS },
101  { "cy", "set the y crop area expression", OFFSET(cy), AV_OPT_TYPE_STRING, { .str = "(in_h-out_h)/2" }, CHAR_MIN, CHAR_MAX, FLAGS },
102 
103  { "w", "Output video width", OFFSET(ow), AV_OPT_TYPE_STRING, { .str="cw" }, 0, 255, .flags = FLAGS },
104  { "width", "Output video width", OFFSET(ow), AV_OPT_TYPE_STRING, { .str="cw" }, 0, 255, .flags = FLAGS },
105  { "h", "Output video height", OFFSET(oh), AV_OPT_TYPE_STRING, { .str="w*ch/cw" }, 0, 255, .flags = FLAGS },
106  { "height", "Output video height", OFFSET(oh), AV_OPT_TYPE_STRING, { .str="w*ch/cw" }, 0, 255, .flags = FLAGS },
107  { NULL }
108 };
109 
110 static const char *const var_names[] = {
111  "iw", "in_w",
112  "ih", "in_h",
113  "ow", "out_w", "w",
114  "oh", "out_h", "h",
115  "cw",
116  "ch",
117  "cx",
118  "cy",
119  NULL
120 };
121 
122 enum var_name {
127  CW,
128  CH,
129  CX,
130  CY,
132 };
133 
135 {
136 #define PASS_EXPR(e, s) {\
137  ret = av_expr_parse(&e, s, var_names, NULL, NULL, NULL, NULL, 0, ctx); \
138  if (ret < 0) {\
139  av_log(ctx, AV_LOG_ERROR, "Error when passing '%s'.\n", s);\
140  goto release;\
141  }\
142 }
143 #define CALC_EXPR(e, v, i) {\
144  i = v = av_expr_eval(e, var_values, NULL); \
145 }
146  VPPContext *vpp = ctx->priv;
147  double var_values[VAR_VARS_NB] = { NAN };
148  AVExpr *w_expr = NULL, *h_expr = NULL;
149  AVExpr *cw_expr = NULL, *ch_expr = NULL;
150  AVExpr *cx_expr = NULL, *cy_expr = NULL;
151  int ret = 0;
152 
153  PASS_EXPR(cw_expr, vpp->cw);
154  PASS_EXPR(ch_expr, vpp->ch);
155 
156  PASS_EXPR(w_expr, vpp->ow);
157  PASS_EXPR(h_expr, vpp->oh);
158 
159  PASS_EXPR(cx_expr, vpp->cx);
160  PASS_EXPR(cy_expr, vpp->cy);
161 
162  var_values[VAR_iW] =
163  var_values[VAR_IN_W] = ctx->inputs[0]->w;
164 
165  var_values[VAR_iH] =
166  var_values[VAR_IN_H] = ctx->inputs[0]->h;
167 
168  /* crop params */
169  CALC_EXPR(cw_expr, var_values[CW], vpp->crop_w);
170  CALC_EXPR(ch_expr, var_values[CH], vpp->crop_h);
171 
172  /* calc again in case cw is relative to ch */
173  CALC_EXPR(cw_expr, var_values[CW], vpp->crop_w);
174 
175  CALC_EXPR(w_expr,
176  var_values[VAR_OUT_W] = var_values[VAR_oW] = var_values[VAR_W],
177  vpp->out_width);
178  CALC_EXPR(h_expr,
179  var_values[VAR_OUT_H] = var_values[VAR_oH] = var_values[VAR_H],
180  vpp->out_height);
181 
182  /* calc again in case ow is relative to oh */
183  CALC_EXPR(w_expr,
184  var_values[VAR_OUT_W] = var_values[VAR_oW] = var_values[VAR_W],
185  vpp->out_width);
186 
187 
188  CALC_EXPR(cx_expr, var_values[CX], vpp->crop_x);
189  CALC_EXPR(cy_expr, var_values[CY], vpp->crop_y);
190 
191  /* calc again in case cx is relative to cy */
192  CALC_EXPR(cx_expr, var_values[CX], vpp->crop_x);
193 
194  if ((vpp->crop_w != var_values[VAR_iW]) || (vpp->crop_h != var_values[VAR_iH]))
195  vpp->use_crop = 1;
196 
197 release:
198  av_expr_free(w_expr);
199  av_expr_free(h_expr);
200  av_expr_free(cw_expr);
201  av_expr_free(ch_expr);
202  av_expr_free(cx_expr);
203  av_expr_free(cy_expr);
204 #undef PASS_EXPR
205 #undef CALC_EXPR
206 
207  return ret;
208 }
209 
210 static int config_input(AVFilterLink *inlink)
211 {
212  AVFilterContext *ctx = inlink->dst;
213  VPPContext *vpp = ctx->priv;
214  int ret;
215 
216  if (vpp->framerate.den == 0 || vpp->framerate.num == 0)
217  vpp->framerate = inlink->frame_rate;
218 
219  if (av_cmp_q(vpp->framerate, inlink->frame_rate))
220  vpp->use_frc = 1;
221 
222  ret = eval_expr(ctx);
223  if (ret != 0) {
224  av_log(ctx, AV_LOG_ERROR, "Fail to eval expr.\n");
225  return ret;
226  }
227 
228  if (vpp->out_height == 0 || vpp->out_width == 0) {
229  vpp->out_width = inlink->w;
230  vpp->out_height = inlink->h;
231  }
232 
233  if (vpp->use_crop) {
234  vpp->crop_x = FFMAX(vpp->crop_x, 0);
235  vpp->crop_y = FFMAX(vpp->crop_y, 0);
236 
237  if(vpp->crop_w + vpp->crop_x > inlink->w)
238  vpp->crop_x = inlink->w - vpp->crop_w;
239  if(vpp->crop_h + vpp->crop_y > inlink->h)
240  vpp->crop_y = inlink->h - vpp->crop_h;
241  }
242 
243  return 0;
244 }
245 
246 static int config_output(AVFilterLink *outlink)
247 {
248  AVFilterContext *ctx = outlink->src;
249  VPPContext *vpp = ctx->priv;
250  QSVVPPParam param = { NULL };
251  QSVVPPCrop crop = { 0 };
252  mfxExtBuffer *ext_buf[ENH_FILTERS_COUNT];
253  AVFilterLink *inlink = ctx->inputs[0];
254 
255  outlink->w = vpp->out_width;
256  outlink->h = vpp->out_height;
257  outlink->frame_rate = vpp->framerate;
258  outlink->time_base = av_inv_q(vpp->framerate);
259 
260  param.filter_frame = NULL;
262  param.num_ext_buf = 0;
263  param.ext_buf = ext_buf;
264 
265  if (vpp->use_crop) {
266  crop.in_idx = 0;
267  crop.x = vpp->crop_x;
268  crop.y = vpp->crop_y;
269  crop.w = vpp->crop_w;
270  crop.h = vpp->crop_h;
271 
272  param.num_crop = 1;
273  param.crop = &crop;
274  }
275 
276  if (vpp->deinterlace) {
277  memset(&vpp->deinterlace_conf, 0, sizeof(mfxExtVPPDeinterlacing));
278  vpp->deinterlace_conf.Header.BufferId = MFX_EXTBUFF_VPP_DEINTERLACING;
279  vpp->deinterlace_conf.Header.BufferSz = sizeof(mfxExtVPPDeinterlacing);
280  vpp->deinterlace_conf.Mode = vpp->deinterlace == 1 ?
281  MFX_DEINTERLACING_BOB : MFX_DEINTERLACING_ADVANCED;
282 
283  param.ext_buf[param.num_ext_buf++] = (mfxExtBuffer*)&vpp->deinterlace_conf;
284  }
285 
286  if (vpp->use_frc) {
287  memset(&vpp->frc_conf, 0, sizeof(mfxExtVPPFrameRateConversion));
288  vpp->frc_conf.Header.BufferId = MFX_EXTBUFF_VPP_FRAME_RATE_CONVERSION;
289  vpp->frc_conf.Header.BufferSz = sizeof(mfxExtVPPFrameRateConversion);
290  vpp->frc_conf.Algorithm = MFX_FRCALGM_DISTRIBUTED_TIMESTAMP;
291 
292  param.ext_buf[param.num_ext_buf++] = (mfxExtBuffer*)&vpp->frc_conf;
293  }
294 
295  if (vpp->denoise) {
296  memset(&vpp->denoise_conf, 0, sizeof(mfxExtVPPDenoise));
297  vpp->denoise_conf.Header.BufferId = MFX_EXTBUFF_VPP_DENOISE;
298  vpp->denoise_conf.Header.BufferSz = sizeof(mfxExtVPPDenoise);
299  vpp->denoise_conf.DenoiseFactor = vpp->denoise;
300 
301  param.ext_buf[param.num_ext_buf++] = (mfxExtBuffer*)&vpp->denoise_conf;
302  }
303 
304  if (vpp->detail) {
305  memset(&vpp->detail_conf, 0, sizeof(mfxExtVPPDetail));
306  vpp->detail_conf.Header.BufferId = MFX_EXTBUFF_VPP_DETAIL;
307  vpp->detail_conf.Header.BufferSz = sizeof(mfxExtVPPDetail);
308  vpp->detail_conf.DetailFactor = vpp->detail;
309 
310  param.ext_buf[param.num_ext_buf++] = (mfxExtBuffer*)&vpp->detail_conf;
311  }
312 
313  if (vpp->procamp) {
314  memset(&vpp->procamp_conf, 0, sizeof(mfxExtVPPProcAmp));
315  vpp->procamp_conf.Header.BufferId = MFX_EXTBUFF_VPP_PROCAMP;
316  vpp->procamp_conf.Header.BufferSz = sizeof(mfxExtVPPProcAmp);
317  vpp->procamp_conf.Hue = vpp->hue;
318  vpp->procamp_conf.Saturation = vpp->saturation;
319  vpp->procamp_conf.Contrast = vpp->contrast;
320  vpp->procamp_conf.Brightness = vpp->brightness;
321 
322  param.ext_buf[param.num_ext_buf++] = (mfxExtBuffer*)&vpp->procamp_conf;
323  }
324 
325  if (vpp->use_frc || vpp->use_crop || vpp->deinterlace || vpp->denoise ||
326  vpp->detail || vpp->procamp || inlink->w != outlink->w || inlink->h != outlink->h)
327  return ff_qsvvpp_create(ctx, &vpp->qsv, &param);
328  else {
329  av_log(ctx, AV_LOG_VERBOSE, "qsv vpp pass through mode.\n");
330  if (inlink->hw_frames_ctx)
331  outlink->hw_frames_ctx = av_buffer_ref(inlink->hw_frames_ctx);
332  }
333 
334  return 0;
335 }
336 
337 static int filter_frame(AVFilterLink *inlink, AVFrame *picref)
338 {
339  int ret = 0;
340  AVFilterContext *ctx = inlink->dst;
341  VPPContext *vpp = inlink->dst->priv;
342  AVFilterLink *outlink = ctx->outputs[0];
343 
344  if (vpp->qsv) {
345  ret = ff_qsvvpp_filter_frame(vpp->qsv, inlink, picref);
346  av_frame_free(&picref);
347  } else {
348  if (picref->pts != AV_NOPTS_VALUE)
349  picref->pts = av_rescale_q(picref->pts, inlink->time_base, outlink->time_base);
350  ret = ff_filter_frame(outlink, picref);
351  }
352 
353  return ret;
354 }
355 
357 {
358  int ret;
359  AVFilterFormats *in_fmts, *out_fmts;
360  static const enum AVPixelFormat in_pix_fmts[] = {
367  };
368  static const enum AVPixelFormat out_pix_fmts[] = {
372  };
373 
374  in_fmts = ff_make_format_list(in_pix_fmts);
375  out_fmts = ff_make_format_list(out_pix_fmts);
376  ret = ff_formats_ref(in_fmts, &ctx->inputs[0]->out_formats);
377  if (ret < 0)
378  return ret;
379  ret = ff_formats_ref(out_fmts, &ctx->outputs[0]->in_formats);
380  if (ret < 0)
381  return ret;
382 
383  return 0;
384 }
385 
387 {
388  VPPContext *vpp = ctx->priv;
389 
390  ff_qsvvpp_free(&vpp->qsv);
391 }
392 
393 static const AVClass vpp_class = {
394  .class_name = "vpp_qsv",
395  .item_name = av_default_item_name,
396  .option = options,
397  .version = LIBAVUTIL_VERSION_INT,
398 };
399 
400 static const AVFilterPad vpp_inputs[] = {
401  {
402  .name = "default",
403  .type = AVMEDIA_TYPE_VIDEO,
404  .config_props = config_input,
405  .filter_frame = filter_frame,
406  },
407  { NULL }
408 };
409 
410 static const AVFilterPad vpp_outputs[] = {
411  {
412  .name = "default",
413  .type = AVMEDIA_TYPE_VIDEO,
414  .config_props = config_output,
415  },
416  { NULL }
417 };
418 
420  .name = "vpp_qsv",
421  .description = NULL_IF_CONFIG_SMALL("Quick Sync Video VPP."),
422  .priv_size = sizeof(VPPContext),
424  .uninit = vpp_uninit,
425  .inputs = vpp_inputs,
426  .outputs = vpp_outputs,
427  .priv_class = &vpp_class,
428  .flags_internal = FF_FILTER_FLAG_HWFRAME_AWARE,
429 };
#define ENH_FILTERS_COUNT
Definition: vf_vpp_qsv.c:44
#define NULL
Definition: coverity.c:32
#define FF_FILTER_FLAG_HWFRAME_AWARE
The filter is aware of hardware frames, and any hardware frame context should not be automatically pr...
Definition: internal.h:385
int use_frc
Definition: vf_vpp_qsv.c:62
This structure describes decoded (raw) audio or video data.
Definition: frame.h:226
float brightness
Definition: vf_vpp_qsv.c:78
int crop_w
Definition: vf_vpp_qsv.c:68
static int config_output(AVFilterLink *outlink)
Definition: vf_vpp_qsv.c:246
AVOption.
Definition: opt.h:246
#define LIBAVUTIL_VERSION_INT
Definition: version.h:85
Main libavfilter public API header.
int num
Numerator.
Definition: rational.h:59
char * ch
Definition: vf_vpp_qsv.c:80
static int config_input(AVFilterLink *inlink)
Definition: vf_vpp_qsv.c:210
const char * av_default_item_name(void *ptr)
Return the context name.
Definition: log.c:191
static int filter_frame(AVFilterLink *inlink, AVFrame *picref)
Definition: vf_vpp_qsv.c:337
AVFilterFormats * ff_make_format_list(const int *fmts)
Create a list of supported formats.
Definition: formats.c:283
const char * name
Pad name.
Definition: internal.h:60
const char * class_name
The name of the class; usually it is the same name as the context structure type to which the AVClass...
Definition: log.h:72
AVFilterLink ** inputs
array of pointers to input links
Definition: avfilter.h:346
#define OFFSET(x)
Definition: vf_vpp_qsv.c:40
int ff_filter_frame(AVFilterLink *link, AVFrame *frame)
Send a frame of data to the next filter.
Definition: avfilter.c:1080
mfxExtVPPProcAmp procamp_conf
Definition: vf_vpp_qsv.c:56
int crop_y
Definition: vf_vpp_qsv.c:71
AVRational framerate
Definition: vf_vpp_qsv.c:61
#define CALC_EXPR(e, v, i)
int ff_qsvvpp_create(AVFilterContext *avctx, QSVVPPContext **vpp, QSVVPPParam *param)
Definition: qsvvpp.c:559
AVFilter ff_vf_vpp_qsv
Definition: vf_vpp_qsv.c:419
#define av_cold
Definition: attributes.h:82
char * cw
Definition: vf_vpp_qsv.c:80
static av_cold int uninit(AVCodecContext *avctx)
Definition: crystalhd.c:279
AVOptions.
static int eval_expr(AVFilterContext *ctx)
Definition: vf_vpp_qsv.c:134
int64_t pts
Presentation timestamp in time_base units (time when frame should be shown to user).
Definition: frame.h:319
Definition: eval.c:157
float saturation
Definition: vf_vpp_qsv.c:76
int crop_h
Definition: vf_vpp_qsv.c:69
int detail
Definition: vf_vpp_qsv.c:65
int use_crop
Definition: vf_vpp_qsv.c:67
int w
Definition: qsvvpp.h:46
#define AV_LOG_VERBOSE
Detailed information.
Definition: log.h:192
#define av_log(a,...)
mfxExtVPPDetail detail_conf
Definition: vf_vpp_qsv.c:55
int num_ext_buf
Definition: qsvvpp.h:54
char * cy
Definition: vf_vpp_qsv.c:80
A filter pad used for either input or output.
Definition: internal.h:54
float contrast
Definition: vf_vpp_qsv.c:77
int64_t av_rescale_q(int64_t a, AVRational bq, AVRational cq)
Rescale a 64-bit integer by 2 rational numbers.
Definition: mathematics.c:142
int procamp
Definition: vf_vpp_qsv.c:74
mfxExtVPPDeinterlacing deinterlace_conf
Definition: vf_vpp_qsv.c:52
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
Definition: log.h:176
int deinterlace
Definition: vf_vpp_qsv.c:63
int out_width
Definition: vf_vpp_qsv.c:58
int crop_x
Definition: vf_vpp_qsv.c:70
static int query_formats(AVFilterContext *ctx)
Definition: vf_vpp_qsv.c:356
char * cx
Definition: vf_vpp_qsv.c:80
void av_frame_free(AVFrame **frame)
Free the frame and any dynamically allocated objects in it, e.g.
Definition: frame.c:202
#define NULL_IF_CONFIG_SMALL(x)
Return NULL if CONFIG_SMALL is true, otherwise the argument without modification. ...
Definition: internal.h:186
void * priv
private data for use by the filter
Definition: avfilter.h:353
Definition: vf_vpp_qsv.c:128
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
simple assert() macros that are a bit more flexible than ISO C assert().
static const char *const var_names[]
Definition: vf_vpp_qsv.c:110
static enum AVPixelFormat in_pix_fmts[]
Definition: vf_ciescope.c:121
#define FFMAX(a, b)
Definition: common.h:94
QSVVPPContext * qsv
Definition: vf_vpp_qsv.c:49
static const AVFilterPad vpp_outputs[]
Definition: vf_vpp_qsv.c:410
int(* filter_frame)(AVFilterLink *outlink, AVFrame *frame)
Definition: qsvvpp.h:51
float hue
Definition: vf_vpp_qsv.c:75
var_name
Definition: aeval.c:46
char * oh
Definition: vf_vpp_qsv.c:81
int x
Definition: qsvvpp.h:46
#define NAN
Definition: mathematics.h:64
Definition: vf_vpp_qsv.c:129
int ff_formats_ref(AVFilterFormats *f, AVFilterFormats **ref)
Add *ref as a new reference to formats.
Definition: formats.c:440
AVFormatContext * ctx
Definition: movenc.c:48
int num_crop
Definition: qsvvpp.h:61
char * ow
Definition: vf_vpp_qsv.c:81
#define FLAGS
Definition: vf_vpp_qsv.c:41
static const AVFilterPad inputs[]
Definition: af_acontrast.c:193
static const AVFilterPad outputs[]
Definition: af_acontrast.c:203
Libavcodec external API header.
void av_expr_free(AVExpr *e)
Free a parsed expression previously created with av_expr_parse().
Definition: eval.c:334
int y
Definition: qsvvpp.h:46
int ff_qsvvpp_filter_frame(QSVVPPContext *s, AVFilterLink *inlink, AVFrame *picref)
Definition: qsvvpp.c:686
#define AV_PIX_FMT_RGB32
Definition: pixfmt.h:352
static const AVFilterPad vpp_inputs[]
Definition: vf_vpp_qsv.c:400
packed YUV 4:2:2, 16bpp, Y0 Cb Y1 Cr
Definition: pixfmt.h:67
static const AVClass vpp_class
Definition: vf_vpp_qsv.c:393
Describe the class of an AVClass context structure.
Definition: log.h:67
int ff_qsvvpp_free(QSVVPPContext **vpp)
Definition: qsvvpp.c:662
Filter definition.
Definition: avfilter.h:144
Rational number (pair of numerator and denominator).
Definition: rational.h:58
int out_height
Definition: vf_vpp_qsv.c:59
HW acceleration through QSV, data[3] contains a pointer to the mfxFrameSurface1 structure.
Definition: pixfmt.h:222
const char * name
Filter name.
Definition: avfilter.h:148
#define PASS_EXPR(e, s)
AVFilterLink ** outputs
array of pointers to output links
Definition: avfilter.h:350
Definition: vf_vpp_qsv.c:127
mfxExtBuffer ** ext_buf
Definition: qsvvpp.h:55
mfxExtVPPFrameRateConversion frc_conf
Definition: vf_vpp_qsv.c:53
static av_always_inline AVRational av_inv_q(AVRational q)
Invert a rational.
Definition: rational.h:159
static int av_cmp_q(AVRational a, AVRational b)
Compare two rationals.
Definition: rational.h:89
Main libavformat public API header.
planar YUV 4:2:0, 12bpp, (1 Cr & Cb sample per 2x2 Y samples)
Definition: pixfmt.h:66
int h
Crop rectangle.
Definition: qsvvpp.h:46
mfxExtVPPDenoise denoise_conf
Definition: vf_vpp_qsv.c:54
AVBufferRef * av_buffer_ref(AVBufferRef *buf)
Create a new reference to an AVBuffer.
Definition: buffer.c:93
static enum AVPixelFormat out_pix_fmts[]
Definition: vf_ciescope.c:130
int den
Denominator.
Definition: rational.h:60
static const AVOption options[]
Definition: vf_vpp_qsv.c:84
int in_idx
Input index.
Definition: qsvvpp.h:45
static av_cold void vpp_uninit(AVFilterContext *ctx)
Definition: vf_vpp_qsv.c:386
A list of supported formats for one end of a filter link.
Definition: formats.h:64
int denoise
Definition: vf_vpp_qsv.c:64
An instance of a filter.
Definition: avfilter.h:338
QSVVPPCrop * crop
Definition: qsvvpp.h:62
enum AVPixelFormat out_sw_format
Definition: qsvvpp.h:58
Intel Quick Sync Video VPP base function.
#define denoise(...)
Definition: vf_hqdn3d.c:156
Definition: vf_vpp_qsv.c:130
internal API functions
AVPixelFormat
Pixel format.
Definition: pixfmt.h:64
#define AV_NOPTS_VALUE
Undefined timestamp value.
Definition: avutil.h:248
uint8_t pi<< 24) CONV_FUNC(AV_SAMPLE_FMT_S64, int64_t, AV_SAMPLE_FMT_U8,(uint64_t)((*(constuint8_t *) pi-0x80U))<< 56) CONV_FUNC(AV_SAMPLE_FMT_FLT, float, AV_SAMPLE_FMT_U8,(*(constuint8_t *) pi-0x80)*(1.0f/(1<< 7))) CONV_FUNC(AV_SAMPLE_FMT_DBL, double, AV_SAMPLE_FMT_U8,(*(constuint8_t *) pi-0x80)*(1.0/(1<< 7))) CONV_FUNC(AV_SAMPLE_FMT_U8, uint8_t, AV_SAMPLE_FMT_S16,(*(constint16_t *) pi >>8)+0x80) CONV_FUNC(AV_SAMPLE_FMT_S64, int64_t, AV_SAMPLE_FMT_S16,(uint64_t)(*(constint16_t *) pi)<< 48) CONV_FUNC(AV_SAMPLE_FMT_FLT, float, AV_SAMPLE_FMT_S16,*(constint16_t *) pi *(1.0f/(1<< 15))) CONV_FUNC(AV_SAMPLE_FMT_DBL, double, AV_SAMPLE_FMT_S16,*(constint16_t *) pi *(1.0/(1<< 15))) CONV_FUNC(AV_SAMPLE_FMT_U8, uint8_t, AV_SAMPLE_FMT_S32,(*(constint32_t *) pi >>24)+0x80) CONV_FUNC(AV_SAMPLE_FMT_S64, int64_t, AV_SAMPLE_FMT_S32,(uint64_t)(*(constint32_t *) pi)<< 32) CONV_FUNC(AV_SAMPLE_FMT_FLT, float, AV_SAMPLE_FMT_S32,*(constint32_t *) pi *(1.0f/(1U<< 31))) CONV_FUNC(AV_SAMPLE_FMT_DBL, double, AV_SAMPLE_FMT_S32,*(constint32_t *) pi *(1.0/(1U<< 31))) CONV_FUNC(AV_SAMPLE_FMT_U8, uint8_t, AV_SAMPLE_FMT_S64,(*(constint64_t *) pi >>56)+0x80) CONV_FUNC(AV_SAMPLE_FMT_FLT, float, AV_SAMPLE_FMT_S64,*(constint64_t *) pi *(1.0f/(INT64_C(1)<< 63))) CONV_FUNC(AV_SAMPLE_FMT_DBL, double, AV_SAMPLE_FMT_S64,*(constint64_t *) pi *(1.0/(INT64_C(1)<< 63))) CONV_FUNC(AV_SAMPLE_FMT_U8, uint8_t, AV_SAMPLE_FMT_FLT, av_clip_uint8(lrintf(*(constfloat *) pi *(1<< 7))+0x80)) CONV_FUNC(AV_SAMPLE_FMT_S16, int16_t, AV_SAMPLE_FMT_FLT, av_clip_int16(lrintf(*(constfloat *) pi *(1<< 15)))) CONV_FUNC(AV_SAMPLE_FMT_S32, int32_t, AV_SAMPLE_FMT_FLT, av_clipl_int32(llrintf(*(constfloat *) pi *(1U<< 31)))) CONV_FUNC(AV_SAMPLE_FMT_S64, int64_t, AV_SAMPLE_FMT_FLT, llrintf(*(constfloat *) pi *(INT64_C(1)<< 63))) CONV_FUNC(AV_SAMPLE_FMT_U8, uint8_t, AV_SAMPLE_FMT_DBL, av_clip_uint8(lrint(*(constdouble *) pi *(1<< 7))+0x80)) CONV_FUNC(AV_SAMPLE_FMT_S16, int16_t, AV_SAMPLE_FMT_DBL, av_clip_int16(lrint(*(constdouble *) pi *(1<< 15)))) CONV_FUNC(AV_SAMPLE_FMT_S32, int32_t, AV_SAMPLE_FMT_DBL, av_clipl_int32(llrint(*(constdouble *) pi *(1U<< 31)))) CONV_FUNC(AV_SAMPLE_FMT_S64, int64_t, AV_SAMPLE_FMT_DBL, llrint(*(constdouble *) pi *(INT64_C(1)<< 63)))#defineFMT_PAIR_FUNC(out, in) staticconv_func_type *constfmt_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),};staticvoidcpy1(uint8_t **dst, constuint8_t **src, intlen){memcpy(*dst,*src, len);}staticvoidcpy2(uint8_t **dst, constuint8_t **src, intlen){memcpy(*dst,*src, 2 *len);}staticvoidcpy4(uint8_t **dst, constuint8_t **src, intlen){memcpy(*dst,*src, 4 *len);}staticvoidcpy8(uint8_t **dst, constuint8_t **src, intlen){memcpy(*dst,*src, 8 *len);}AudioConvert *swri_audio_convert_alloc(enumAVSampleFormatout_fmt, enumAVSampleFormatin_fmt, intchannels, constint *ch_map, intflags){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) returnNULL;ctx=av_mallocz(sizeof(*ctx));if(!ctx) returnNULL;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)){case1:ctx->simd_f=cpy1;break;case2:ctx->simd_f=cpy2;break;case4:ctx->simd_f=cpy4;break;case8: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);returnctx;}voidswri_audio_convert_free(AudioConvert **ctx){av_freep(ctx);}intswri_audio_convert(AudioConvert *ctx, AudioData *out, AudioData *in, intlen){intch;intoff=0;constintos=(out->planar?1:out->ch_count)*out->bps;unsignedmisaligned=0;av_assert0(ctx->channels==out->ch_count);if(ctx->in_simd_align_mask){intplanes=in->planar?in->ch_count:1;unsignedm=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){intplanes=out->planar?out->ch_count:1;unsignedm=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){intplanes=out->planar?out->ch_count:1;for(ch=0;ch< planes;ch++){ctx->simd_f(out-> ch ch
Definition: audioconvert.c:56
simple arithmetic expression evaluator