FFmpeg
vf_scale_npp.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  * scale video filter
22  */
23 
24 #include <nppi.h>
25 #include <stdio.h>
26 #include <string.h>
27 
28 #include "libavutil/avstring.h"
29 #include "libavutil/common.h"
30 #include "libavutil/hwcontext.h"
32 #include "libavutil/cuda_check.h"
33 #include "libavutil/internal.h"
34 #include "libavutil/opt.h"
35 #include "libavutil/pixdesc.h"
36 
37 #include "avfilter.h"
38 #include "formats.h"
39 #include "internal.h"
40 #include "scale.h"
41 #include "video.h"
42 
43 #define CHECK_CU(x) FF_CUDA_CHECK_DL(ctx, device_hwctx->internal->cuda_dl, x)
44 
45 static const enum AVPixelFormat supported_formats[] = {
49 };
50 
51 static const enum AVPixelFormat deinterleaved_formats[][2] = {
53 };
54 
55 enum ScaleStage {
60 };
61 
62 typedef struct NPPScaleStageContext {
66 
67  struct {
68  int width;
69  int height;
70  } planes_in[3], planes_out[3];
71 
75 
76 typedef struct NPPScaleContext {
77  const AVClass *class;
78 
82 
84 
85  /**
86  * New dimensions. Special values are:
87  * 0 = original width/height
88  * -1 = keep original aspect
89  */
90  int w, h;
91 
92  /**
93  * Output sw format. AV_PIX_FMT_NONE for no conversion.
94  */
96 
97  char *w_expr; ///< width expression string
98  char *h_expr; ///< height expression string
99  char *format_str;
100 
103 
105 {
106  NPPScaleContext *s = ctx->priv;
107  int i;
108 
109  if (!strcmp(s->format_str, "same")) {
110  s->format = AV_PIX_FMT_NONE;
111  } else {
112  s->format = av_get_pix_fmt(s->format_str);
113  if (s->format == AV_PIX_FMT_NONE) {
114  av_log(ctx, AV_LOG_ERROR, "Unrecognized pixel format: %s\n", s->format_str);
115  return AVERROR(EINVAL);
116  }
117  }
118 
119  for (i = 0; i < FF_ARRAY_ELEMS(s->stages); i++) {
120  s->stages[i].frame = av_frame_alloc();
121  if (!s->stages[i].frame)
122  return AVERROR(ENOMEM);
123  }
124  s->tmp_frame = av_frame_alloc();
125  if (!s->tmp_frame)
126  return AVERROR(ENOMEM);
127 
128  return 0;
129 }
130 
132 {
133  NPPScaleContext *s = ctx->priv;
134  int i;
135 
136  for (i = 0; i < FF_ARRAY_ELEMS(s->stages); i++) {
137  av_frame_free(&s->stages[i].frame);
138  av_buffer_unref(&s->stages[i].frames_ctx);
139  }
140  av_frame_free(&s->tmp_frame);
141 }
142 
144 {
145  static const enum AVPixelFormat pixel_formats[] = {
147  };
148  AVFilterFormats *pix_fmts = ff_make_format_list(pixel_formats);
149 
151 }
152 
153 static int init_stage(NPPScaleStageContext *stage, AVBufferRef *device_ctx)
154 {
155  AVBufferRef *out_ref = NULL;
156  AVHWFramesContext *out_ctx;
157  int in_sw, in_sh, out_sw, out_sh;
158  int ret, i;
159 
160  av_pix_fmt_get_chroma_sub_sample(stage->in_fmt, &in_sw, &in_sh);
161  av_pix_fmt_get_chroma_sub_sample(stage->out_fmt, &out_sw, &out_sh);
162  if (!stage->planes_out[0].width) {
163  stage->planes_out[0].width = stage->planes_in[0].width;
164  stage->planes_out[0].height = stage->planes_in[0].height;
165  }
166 
167  for (i = 1; i < FF_ARRAY_ELEMS(stage->planes_in); i++) {
168  stage->planes_in[i].width = stage->planes_in[0].width >> in_sw;
169  stage->planes_in[i].height = stage->planes_in[0].height >> in_sh;
170  stage->planes_out[i].width = stage->planes_out[0].width >> out_sw;
171  stage->planes_out[i].height = stage->planes_out[0].height >> out_sh;
172  }
173 
174  out_ref = av_hwframe_ctx_alloc(device_ctx);
175  if (!out_ref)
176  return AVERROR(ENOMEM);
177  out_ctx = (AVHWFramesContext*)out_ref->data;
178 
179  out_ctx->format = AV_PIX_FMT_CUDA;
180  out_ctx->sw_format = stage->out_fmt;
181  out_ctx->width = FFALIGN(stage->planes_out[0].width, 32);
182  out_ctx->height = FFALIGN(stage->planes_out[0].height, 32);
183 
184  ret = av_hwframe_ctx_init(out_ref);
185  if (ret < 0)
186  goto fail;
187 
188  av_frame_unref(stage->frame);
189  ret = av_hwframe_get_buffer(out_ref, stage->frame, 0);
190  if (ret < 0)
191  goto fail;
192 
193  stage->frame->width = stage->planes_out[0].width;
194  stage->frame->height = stage->planes_out[0].height;
195 
196  av_buffer_unref(&stage->frames_ctx);
197  stage->frames_ctx = out_ref;
198 
199  return 0;
200 fail:
201  av_buffer_unref(&out_ref);
202  return ret;
203 }
204 
206 {
207  int i;
208 
209  for (i = 0; i < FF_ARRAY_ELEMS(supported_formats); i++)
210  if (supported_formats[i] == fmt)
211  return 1;
212  return 0;
213 }
214 
216 {
218  int i, planes;
219 
221  if (planes == desc->nb_components)
222  return fmt;
223  for (i = 0; i < FF_ARRAY_ELEMS(deinterleaved_formats); i++)
224  if (deinterleaved_formats[i][0] == fmt)
225  return deinterleaved_formats[i][1];
226  return AV_PIX_FMT_NONE;
227 }
228 
229 static int init_processing_chain(AVFilterContext *ctx, int in_width, int in_height,
230  int out_width, int out_height)
231 {
232  NPPScaleContext *s = ctx->priv;
233 
234  AVHWFramesContext *in_frames_ctx;
235 
236  enum AVPixelFormat in_format;
237  enum AVPixelFormat out_format;
238  enum AVPixelFormat in_deinterleaved_format;
239  enum AVPixelFormat out_deinterleaved_format;
240 
241  int i, ret, last_stage = -1;
242 
243  /* check that we have a hw context */
244  if (!ctx->inputs[0]->hw_frames_ctx) {
245  av_log(ctx, AV_LOG_ERROR, "No hw context provided on input\n");
246  return AVERROR(EINVAL);
247  }
248  in_frames_ctx = (AVHWFramesContext*)ctx->inputs[0]->hw_frames_ctx->data;
249  in_format = in_frames_ctx->sw_format;
250  out_format = (s->format == AV_PIX_FMT_NONE) ? in_format : s->format;
251 
252  if (!format_is_supported(in_format)) {
253  av_log(ctx, AV_LOG_ERROR, "Unsupported input format: %s\n",
254  av_get_pix_fmt_name(in_format));
255  return AVERROR(ENOSYS);
256  }
257  if (!format_is_supported(out_format)) {
258  av_log(ctx, AV_LOG_ERROR, "Unsupported output format: %s\n",
259  av_get_pix_fmt_name(out_format));
260  return AVERROR(ENOSYS);
261  }
262 
263  in_deinterleaved_format = get_deinterleaved_format(in_format);
264  out_deinterleaved_format = get_deinterleaved_format(out_format);
265  if (in_deinterleaved_format == AV_PIX_FMT_NONE ||
266  out_deinterleaved_format == AV_PIX_FMT_NONE)
267  return AVERROR_BUG;
268 
269  /* figure out which stages need to be done */
270  if (in_width != out_width || in_height != out_height ||
271  in_deinterleaved_format != out_deinterleaved_format) {
272  s->stages[STAGE_RESIZE].stage_needed = 1;
273 
274  if (s->interp_algo == NPPI_INTER_SUPER &&
275  (out_width > in_width && out_height > in_height)) {
276  s->interp_algo = NPPI_INTER_LANCZOS;
277  av_log(ctx, AV_LOG_WARNING, "super-sampling not supported for output dimensions, using lanczos instead.\n");
278  }
279  if (s->interp_algo == NPPI_INTER_SUPER &&
280  !(out_width < in_width && out_height < in_height)) {
281  s->interp_algo = NPPI_INTER_CUBIC;
282  av_log(ctx, AV_LOG_WARNING, "super-sampling not supported for output dimensions, using cubic instead.\n");
283  }
284  }
285 
286  if (!s->stages[STAGE_RESIZE].stage_needed && in_format == out_format)
287  s->passthrough = 1;
288 
289  if (!s->passthrough) {
290  if (in_format != in_deinterleaved_format)
291  s->stages[STAGE_DEINTERLEAVE].stage_needed = 1;
292  if (out_format != out_deinterleaved_format)
293  s->stages[STAGE_INTERLEAVE].stage_needed = 1;
294  }
295 
296  s->stages[STAGE_DEINTERLEAVE].in_fmt = in_format;
297  s->stages[STAGE_DEINTERLEAVE].out_fmt = in_deinterleaved_format;
298  s->stages[STAGE_DEINTERLEAVE].planes_in[0].width = in_width;
299  s->stages[STAGE_DEINTERLEAVE].planes_in[0].height = in_height;
300 
301  s->stages[STAGE_RESIZE].in_fmt = in_deinterleaved_format;
302  s->stages[STAGE_RESIZE].out_fmt = out_deinterleaved_format;
303  s->stages[STAGE_RESIZE].planes_in[0].width = in_width;
304  s->stages[STAGE_RESIZE].planes_in[0].height = in_height;
305  s->stages[STAGE_RESIZE].planes_out[0].width = out_width;
306  s->stages[STAGE_RESIZE].planes_out[0].height = out_height;
307 
308  s->stages[STAGE_INTERLEAVE].in_fmt = out_deinterleaved_format;
309  s->stages[STAGE_INTERLEAVE].out_fmt = out_format;
310  s->stages[STAGE_INTERLEAVE].planes_in[0].width = out_width;
311  s->stages[STAGE_INTERLEAVE].planes_in[0].height = out_height;
312 
313  /* init the hardware contexts */
314  for (i = 0; i < FF_ARRAY_ELEMS(s->stages); i++) {
315  if (!s->stages[i].stage_needed)
316  continue;
317 
318  ret = init_stage(&s->stages[i], in_frames_ctx->device_ref);
319  if (ret < 0)
320  return ret;
321 
322  last_stage = i;
323  }
324 
325  if (last_stage >= 0)
326  ctx->outputs[0]->hw_frames_ctx = av_buffer_ref(s->stages[last_stage].frames_ctx);
327  else
328  ctx->outputs[0]->hw_frames_ctx = av_buffer_ref(ctx->inputs[0]->hw_frames_ctx);
329 
330  if (!ctx->outputs[0]->hw_frames_ctx)
331  return AVERROR(ENOMEM);
332 
333  return 0;
334 }
335 
337 {
338  AVFilterContext *ctx = outlink->src;
339  AVFilterLink *inlink = outlink->src->inputs[0];
340  NPPScaleContext *s = ctx->priv;
341  int w, h;
342  int ret;
343 
345  s->w_expr, s->h_expr,
346  inlink, outlink,
347  &w, &h)) < 0)
348  goto fail;
349 
350  if (((int64_t)h * inlink->w) > INT_MAX ||
351  ((int64_t)w * inlink->h) > INT_MAX)
352  av_log(ctx, AV_LOG_ERROR, "Rescaled value for width or height is too big.\n");
353 
354  outlink->w = w;
355  outlink->h = h;
356 
358  if (ret < 0)
359  return ret;
360 
361  av_log(ctx, AV_LOG_VERBOSE, "w:%d h:%d -> w:%d h:%d\n",
362  inlink->w, inlink->h, outlink->w, outlink->h);
363 
364  if (inlink->sample_aspect_ratio.num)
365  outlink->sample_aspect_ratio = av_mul_q((AVRational){outlink->h*inlink->w,
366  outlink->w*inlink->h},
367  inlink->sample_aspect_ratio);
368  else
369  outlink->sample_aspect_ratio = inlink->sample_aspect_ratio;
370 
371  return 0;
372 
373 fail:
374  return ret;
375 }
376 
378  AVFrame *out, AVFrame *in)
379 {
380  AVHWFramesContext *in_frames_ctx = (AVHWFramesContext*)in->hw_frames_ctx->data;
381  NppStatus err;
382 
383  switch (in_frames_ctx->sw_format) {
384  case AV_PIX_FMT_NV12:
385  err = nppiYCbCr420_8u_P2P3R(in->data[0], in->linesize[0],
386  in->data[1], in->linesize[1],
387  out->data, out->linesize,
388  (NppiSize){ in->width, in->height });
389  break;
390  default:
391  return AVERROR_BUG;
392  }
393  if (err != NPP_SUCCESS) {
394  av_log(ctx, AV_LOG_ERROR, "NPP deinterleave error: %d\n", err);
395  return AVERROR_UNKNOWN;
396  }
397 
398  return 0;
399 }
400 
402  AVFrame *out, AVFrame *in)
403 {
404  NPPScaleContext *s = ctx->priv;
405  NppStatus err;
406  int i;
407 
408  for (i = 0; i < FF_ARRAY_ELEMS(stage->planes_in) && i < FF_ARRAY_ELEMS(in->data) && in->data[i]; i++) {
409  int iw = stage->planes_in[i].width;
410  int ih = stage->planes_in[i].height;
411  int ow = stage->planes_out[i].width;
412  int oh = stage->planes_out[i].height;
413 
414  err = nppiResizeSqrPixel_8u_C1R(in->data[i], (NppiSize){ iw, ih },
415  in->linesize[i], (NppiRect){ 0, 0, iw, ih },
416  out->data[i], out->linesize[i],
417  (NppiRect){ 0, 0, ow, oh },
418  (double)ow / iw, (double)oh / ih,
419  0.0, 0.0, s->interp_algo);
420  if (err != NPP_SUCCESS) {
421  av_log(ctx, AV_LOG_ERROR, "NPP resize error: %d\n", err);
422  return AVERROR_UNKNOWN;
423  }
424  }
425 
426  return 0;
427 }
428 
430  AVFrame *out, AVFrame *in)
431 {
432  AVHWFramesContext *out_frames_ctx = (AVHWFramesContext*)out->hw_frames_ctx->data;
433  NppStatus err;
434 
435  switch (out_frames_ctx->sw_format) {
436  case AV_PIX_FMT_NV12:
437  err = nppiYCbCr420_8u_P3P2R((const uint8_t**)in->data,
438  in->linesize,
439  out->data[0], out->linesize[0],
440  out->data[1], out->linesize[1],
441  (NppiSize){ in->width, in->height });
442  break;
443  default:
444  return AVERROR_BUG;
445  }
446  if (err != NPP_SUCCESS) {
447  av_log(ctx, AV_LOG_ERROR, "NPP deinterleave error: %d\n", err);
448  return AVERROR_UNKNOWN;
449  }
450 
451  return 0;
452 }
453 
455  AVFrame *out, AVFrame *in) = {
459 };
460 
462 {
463  NPPScaleContext *s = ctx->priv;
464  AVFrame *src = in;
465  int i, ret, last_stage = -1;
466 
467  for (i = 0; i < FF_ARRAY_ELEMS(s->stages); i++) {
468  if (!s->stages[i].stage_needed)
469  continue;
470 
471  ret = nppscale_process[i](ctx, &s->stages[i], s->stages[i].frame, src);
472  if (ret < 0)
473  return ret;
474 
475  src = s->stages[i].frame;
476  last_stage = i;
477  }
478  if (last_stage < 0)
479  return AVERROR_BUG;
480 
481  ret = av_hwframe_get_buffer(src->hw_frames_ctx, s->tmp_frame, 0);
482  if (ret < 0)
483  return ret;
484 
485  s->tmp_frame->width = src->width;
486  s->tmp_frame->height = src->height;
487 
489  av_frame_move_ref(src, s->tmp_frame);
490 
492  if (ret < 0)
493  return ret;
494 
495  return 0;
496 }
497 
499 {
500  AVFilterContext *ctx = link->dst;
501  NPPScaleContext *s = ctx->priv;
502  AVFilterLink *outlink = ctx->outputs[0];
503  AVHWFramesContext *frames_ctx = (AVHWFramesContext*)outlink->hw_frames_ctx->data;
504  AVCUDADeviceContext *device_hwctx = frames_ctx->device_ctx->hwctx;
505 
506  AVFrame *out = NULL;
507  CUcontext dummy;
508  int ret = 0;
509 
510  if (s->passthrough)
511  return ff_filter_frame(outlink, in);
512 
513  out = av_frame_alloc();
514  if (!out) {
515  ret = AVERROR(ENOMEM);
516  goto fail;
517  }
518 
519  ret = CHECK_CU(device_hwctx->internal->cuda_dl->cuCtxPushCurrent(device_hwctx->cuda_ctx));
520  if (ret < 0)
521  goto fail;
522 
523  ret = nppscale_scale(ctx, out, in);
524 
525  CHECK_CU(device_hwctx->internal->cuda_dl->cuCtxPopCurrent(&dummy));
526  if (ret < 0)
527  goto fail;
528 
529  av_reduce(&out->sample_aspect_ratio.num, &out->sample_aspect_ratio.den,
530  (int64_t)in->sample_aspect_ratio.num * outlink->h * link->w,
531  (int64_t)in->sample_aspect_ratio.den * outlink->w * link->h,
532  INT_MAX);
533 
534  av_frame_free(&in);
535  return ff_filter_frame(outlink, out);
536 fail:
537  av_frame_free(&in);
538  av_frame_free(&out);
539  return ret;
540 }
541 
542 #define OFFSET(x) offsetof(NPPScaleContext, x)
543 #define FLAGS (AV_OPT_FLAG_FILTERING_PARAM|AV_OPT_FLAG_VIDEO_PARAM)
544 static const AVOption options[] = {
545  { "w", "Output video width", OFFSET(w_expr), AV_OPT_TYPE_STRING, { .str = "iw" }, .flags = FLAGS },
546  { "h", "Output video height", OFFSET(h_expr), AV_OPT_TYPE_STRING, { .str = "ih" }, .flags = FLAGS },
547  { "format", "Output pixel format", OFFSET(format_str), AV_OPT_TYPE_STRING, { .str = "same" }, .flags = FLAGS },
548 
549  { "interp_algo", "Interpolation algorithm used for resizing", OFFSET(interp_algo), AV_OPT_TYPE_INT, { .i64 = NPPI_INTER_CUBIC }, 0, INT_MAX, FLAGS, "interp_algo" },
550  { "nn", "nearest neighbour", 0, AV_OPT_TYPE_CONST, { .i64 = NPPI_INTER_NN }, 0, 0, FLAGS, "interp_algo" },
551  { "linear", "linear", 0, AV_OPT_TYPE_CONST, { .i64 = NPPI_INTER_LINEAR }, 0, 0, FLAGS, "interp_algo" },
552  { "cubic", "cubic", 0, AV_OPT_TYPE_CONST, { .i64 = NPPI_INTER_CUBIC }, 0, 0, FLAGS, "interp_algo" },
553  { "cubic2p_bspline", "2-parameter cubic (B=1, C=0)", 0, AV_OPT_TYPE_CONST, { .i64 = NPPI_INTER_CUBIC2P_BSPLINE }, 0, 0, FLAGS, "interp_algo" },
554  { "cubic2p_catmullrom", "2-parameter cubic (B=0, C=1/2)", 0, AV_OPT_TYPE_CONST, { .i64 = NPPI_INTER_CUBIC2P_CATMULLROM }, 0, 0, FLAGS, "interp_algo" },
555  { "cubic2p_b05c03", "2-parameter cubic (B=1/2, C=3/10)", 0, AV_OPT_TYPE_CONST, { .i64 = NPPI_INTER_CUBIC2P_B05C03 }, 0, 0, FLAGS, "interp_algo" },
556  { "super", "supersampling", 0, AV_OPT_TYPE_CONST, { .i64 = NPPI_INTER_SUPER }, 0, 0, FLAGS, "interp_algo" },
557  { "lanczos", "Lanczos", 0, AV_OPT_TYPE_CONST, { .i64 = NPPI_INTER_LANCZOS }, 0, 0, FLAGS, "interp_algo" },
558  { NULL },
559 };
560 
561 static const AVClass nppscale_class = {
562  .class_name = "nppscale",
563  .item_name = av_default_item_name,
564  .option = options,
565  .version = LIBAVUTIL_VERSION_INT,
566 };
567 
568 static const AVFilterPad nppscale_inputs[] = {
569  {
570  .name = "default",
571  .type = AVMEDIA_TYPE_VIDEO,
572  .filter_frame = nppscale_filter_frame,
573  },
574  { NULL }
575 };
576 
577 static const AVFilterPad nppscale_outputs[] = {
578  {
579  .name = "default",
580  .type = AVMEDIA_TYPE_VIDEO,
581  .config_props = nppscale_config_props,
582  },
583  { NULL }
584 };
585 
587  .name = "scale_npp",
588  .description = NULL_IF_CONFIG_SMALL("NVIDIA Performance Primitives video "
589  "scaling and format conversion"),
590 
591  .init = nppscale_init,
592  .uninit = nppscale_uninit,
593  .query_formats = nppscale_query_formats,
594 
595  .priv_size = sizeof(NPPScaleContext),
596  .priv_class = &nppscale_class,
597 
600 
601  .flags_internal = FF_FILTER_FLAG_HWFRAME_AWARE,
602 };
format_is_supported
static int format_is_supported(enum AVPixelFormat fmt)
Definition: vf_scale_npp.c:205
AVHWDeviceContext::hwctx
void * hwctx
The format-specific data, allocated and freed by libavutil along with this context.
Definition: hwcontext.h:91
NPPScaleContext::passthrough
int passthrough
Definition: vf_scale_npp.c:81
AV_LOG_WARNING
#define AV_LOG_WARNING
Something somehow does not look correct.
Definition: log.h:182
AV_PIX_FMT_CUDA
@ AV_PIX_FMT_CUDA
HW acceleration through CUDA.
Definition: pixfmt.h:235
AVPixelFormat
AVPixelFormat
Pixel format.
Definition: pixfmt.h:64
nppscale_inputs
static const AVFilterPad nppscale_inputs[]
Definition: vf_scale_npp.c:568
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
hwcontext_cuda_internal.h
out
FILE * out
Definition: movenc.c:54
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
ff_filter_frame
int ff_filter_frame(AVFilterLink *link, AVFrame *frame)
Send a frame of data to the next filter.
Definition: avfilter.c:1080
av_pix_fmt_desc_get
const AVPixFmtDescriptor * av_pix_fmt_desc_get(enum AVPixelFormat pix_fmt)
Definition: pixdesc.c:2522
AVBufferRef::data
uint8_t * data
The data buffer.
Definition: buffer.h:89
CHECK_CU
#define CHECK_CU(x)
Definition: vf_scale_npp.c:43
AVHWFramesContext::format
enum AVPixelFormat format
The pixel format identifying the underlying HW surface type.
Definition: hwcontext.h:208
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
ScaleStage
ScaleStage
Definition: vf_scale_npp.c:55
nppscale_class
static const AVClass nppscale_class
Definition: vf_scale_npp.c:561
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
av_hwframe_ctx_init
int av_hwframe_ctx_init(AVBufferRef *ref)
Finalize the context before use.
Definition: hwcontext.c:329
AVFrame
This structure describes decoded (raw) audio or video data.
Definition: frame.h:295
pixdesc.h
AVFrame::width
int width
Definition: frame.h:353
w
uint8_t w
Definition: llviddspenc.c:38
av_hwframe_ctx_alloc
AVBufferRef * av_hwframe_ctx_alloc(AVBufferRef *device_ref_in)
Allocate an AVHWFramesContext tied to a given device context.
Definition: hwcontext.c:243
NPPScaleStageContext::stage_needed
int stage_needed
Definition: vf_scale_npp.c:63
AVOption
AVOption.
Definition: opt.h:246
supported_formats
static enum AVPixelFormat supported_formats[]
Definition: vf_scale_npp.c:45
AV_LOG_VERBOSE
#define AV_LOG_VERBOSE
Detailed information.
Definition: log.h:192
STAGE_NB
@ STAGE_NB
Definition: vf_scale_npp.c:59
AVFilter::name
const char * name
Filter name.
Definition: avfilter.h:148
AVERROR_UNKNOWN
#define AVERROR_UNKNOWN
Unknown error, typically from an external library.
Definition: error.h:71
AVHWFramesContext::width
int width
The allocated dimensions of the frames in this pool.
Definition: hwcontext.h:228
video.h
NPPScaleStageContext::frame
AVFrame * frame
Definition: vf_scale_npp.c:73
AVFilterFormats
A list of supported formats for one end of a filter link.
Definition: formats.h:64
formats.h
av_pix_fmt_count_planes
int av_pix_fmt_count_planes(enum AVPixelFormat pix_fmt)
Definition: pixdesc.c:2562
fmt
const char * fmt
Definition: avisynth_c.h:861
fail
#define fail()
Definition: checkasm.h:120
get_deinterleaved_format
static enum AVPixelFormat get_deinterleaved_format(enum AVPixelFormat fmt)
Definition: vf_scale_npp.c:215
STAGE_RESIZE
@ STAGE_RESIZE
Definition: vf_scale_npp.c:57
NPPScaleContext::tmp_frame
AVFrame * tmp_frame
Definition: vf_scale_npp.c:80
av_pix_fmt_get_chroma_sub_sample
int av_pix_fmt_get_chroma_sub_sample(enum AVPixelFormat pix_fmt, int *h_shift, int *v_shift)
Utility function to access log2_chroma_w log2_chroma_h from the pixel format AVPixFmtDescriptor.
Definition: pixdesc.c:2550
av_reduce
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
NPPScaleContext::shift_width
int shift_width
Definition: vf_scale_npp.c:83
src
#define src
Definition: vp8dsp.c:254
AVFilterPad
A filter pad used for either input or output.
Definition: internal.h:54
av_frame_alloc
AVFrame * av_frame_alloc(void)
Allocate an AVFrame and set its fields to default values.
Definition: frame.c:189
AV_LOG_ERROR
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
Definition: log.h:176
ff_set_common_formats
int ff_set_common_formats(AVFilterContext *ctx, AVFilterFormats *formats)
A helper for query_formats() which sets all links to the same list of formats.
Definition: formats.c:568
AVHWFramesContext::height
int height
Definition: hwcontext.h:228
s
#define s(width, name)
Definition: cbs_vp9.c:257
nppscale_uninit
static void nppscale_uninit(AVFilterContext *ctx)
Definition: vf_scale_npp.c:131
NPPScaleContext::stages
NPPScaleStageContext stages[STAGE_NB]
Definition: vf_scale_npp.c:79
nppscale_query_formats
static int nppscale_query_formats(AVFilterContext *ctx)
Definition: vf_scale_npp.c:143
outputs
static const AVFilterPad outputs[]
Definition: af_acontrast.c:203
pix_fmts
static enum AVPixelFormat pix_fmts[]
Definition: libkvazaar.c:275
ctx
AVFormatContext * ctx
Definition: movenc.c:48
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
link
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 link
Definition: filter_design.txt:23
NPPScaleContext
Definition: vf_scale_npp.c:76
if
if(ret)
Definition: filter_design.txt:179
FLAGS
#define FLAGS
Definition: vf_scale_npp.c:543
init_stage
static int init_stage(NPPScaleStageContext *stage, AVBufferRef *device_ctx)
Definition: vf_scale_npp.c:153
scale.h
LIBAVUTIL_VERSION_INT
#define LIBAVUTIL_VERSION_INT
Definition: version.h:85
AVClass
Describe the class of an AVClass context structure.
Definition: log.h:67
nppscale_interleave
static int nppscale_interleave(AVFilterContext *ctx, NPPScaleStageContext *stage, AVFrame *out, AVFrame *in)
Definition: vf_scale_npp.c:429
NULL
#define NULL
Definition: coverity.c:32
AVHWFramesContext::sw_format
enum AVPixelFormat sw_format
The pixel format identifying the actual data layout of the hardware frames.
Definition: hwcontext.h:221
av_frame_copy_props
int av_frame_copy_props(AVFrame *dst, const AVFrame *src)
Copy only "metadata" fields from src to dst.
Definition: frame.c:654
av_buffer_unref
void av_buffer_unref(AVBufferRef **buf)
Free a given reference and automatically free the buffer if there are no more references to it.
Definition: buffer.c:125
AVRational
Rational number (pair of numerator and denominator).
Definition: rational.h:58
AVHWFramesContext::device_ref
AVBufferRef * device_ref
A reference to the parent AVHWDeviceContext.
Definition: hwcontext.h:140
AVFilterContext::inputs
AVFilterLink ** inputs
array of pointers to input links
Definition: avfilter.h:346
av_default_item_name
const char * av_default_item_name(void *ptr)
Return the context name.
Definition: log.c:191
NPPScaleContext::h_expr
char * h_expr
height expression string
Definition: vf_scale_npp.c:98
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
nppscale_init
static int nppscale_init(AVFilterContext *ctx)
Definition: vf_scale_npp.c:104
NPPScaleContext::shift_height
int shift_height
Definition: vf_scale_npp.c:83
NPPScaleStageContext::height
int height
Definition: vf_scale_npp.c:69
desc
const char * desc
Definition: nvenc.c:68
planes
static const struct @314 planes[]
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
NPPScaleStageContext::out_fmt
enum AVPixelFormat out_fmt
Definition: vf_scale_npp.c:65
OFFSET
#define OFFSET(x)
Definition: vf_scale_npp.c:542
NPPScaleStageContext::frames_ctx
AVBufferRef * frames_ctx
Definition: vf_scale_npp.c:72
ff_vf_scale_npp
AVFilter ff_vf_scale_npp
Definition: vf_scale_npp.c:586
nppscale_filter_frame
static int nppscale_filter_frame(AVFilterLink *link, AVFrame *in)
Definition: vf_scale_npp.c:498
nppscale_config_props
static int nppscale_config_props(AVFilterLink *outlink)
Definition: vf_scale_npp.c:336
init_processing_chain
static int init_processing_chain(AVFilterContext *ctx, int in_width, int in_height, int out_width, int out_height)
Definition: vf_scale_npp.c:229
nppscale_resize
static int nppscale_resize(AVFilterContext *ctx, NPPScaleStageContext *stage, AVFrame *out, AVFrame *in)
Definition: vf_scale_npp.c:401
internal.h
ff_scale_eval_dimensions
int ff_scale_eval_dimensions(void *log_ctx, const char *w_expr, const char *h_expr, AVFilterLink *inlink, AVFilterLink *outlink, int *ret_w, int *ret_h)
Definition: scale.c:106
in
uint8_t pi<< 24) CONV_FUNC_GROUP(AV_SAMPLE_FMT_FLT, float, AV_SAMPLE_FMT_U8, uint8_t,(*(const uint8_t *) pi - 0x80) *(1.0f/(1<< 7))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_DBL, double, AV_SAMPLE_FMT_U8, uint8_t,(*(const uint8_t *) pi - 0x80) *(1.0/(1<< 7))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_U8, uint8_t, AV_SAMPLE_FMT_S16, int16_t,(*(const int16_t *) pi >> 8)+0x80) CONV_FUNC_GROUP(AV_SAMPLE_FMT_FLT, float, AV_SAMPLE_FMT_S16, int16_t, *(const int16_t *) pi *(1.0f/(1<< 15))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_DBL, double, AV_SAMPLE_FMT_S16, int16_t, *(const int16_t *) pi *(1.0/(1<< 15))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_U8, uint8_t, AV_SAMPLE_FMT_S32, int32_t,(*(const int32_t *) pi >> 24)+0x80) CONV_FUNC_GROUP(AV_SAMPLE_FMT_FLT, float, AV_SAMPLE_FMT_S32, int32_t, *(const int32_t *) pi *(1.0f/(1U<< 31))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_DBL, double, AV_SAMPLE_FMT_S32, int32_t, *(const int32_t *) pi *(1.0/(1U<< 31))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_U8, uint8_t, AV_SAMPLE_FMT_FLT, float, av_clip_uint8(lrintf(*(const float *) pi *(1<< 7))+0x80)) CONV_FUNC_GROUP(AV_SAMPLE_FMT_S16, int16_t, AV_SAMPLE_FMT_FLT, float, av_clip_int16(lrintf(*(const float *) pi *(1<< 15)))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_S32, int32_t, AV_SAMPLE_FMT_FLT, float, av_clipl_int32(llrintf(*(const float *) pi *(1U<< 31)))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_U8, uint8_t, AV_SAMPLE_FMT_DBL, double, av_clip_uint8(lrint(*(const double *) pi *(1<< 7))+0x80)) CONV_FUNC_GROUP(AV_SAMPLE_FMT_S16, int16_t, AV_SAMPLE_FMT_DBL, double, av_clip_int16(lrint(*(const double *) pi *(1<< 15)))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_S32, int32_t, AV_SAMPLE_FMT_DBL, double, av_clipl_int32(llrint(*(const double *) pi *(1U<< 31)))) #define SET_CONV_FUNC_GROUP(ofmt, ifmt) static void set_generic_function(AudioConvert *ac) { } void ff_audio_convert_free(AudioConvert **ac) { if(! *ac) return;ff_dither_free(&(*ac) ->dc);av_freep(ac);} AudioConvert *ff_audio_convert_alloc(AVAudioResampleContext *avr, enum AVSampleFormat out_fmt, enum AVSampleFormat in_fmt, int channels, int sample_rate, int apply_map) { AudioConvert *ac;int in_planar, out_planar;ac=av_mallocz(sizeof(*ac));if(!ac) return NULL;ac->avr=avr;ac->out_fmt=out_fmt;ac->in_fmt=in_fmt;ac->channels=channels;ac->apply_map=apply_map;if(avr->dither_method !=AV_RESAMPLE_DITHER_NONE &&av_get_packed_sample_fmt(out_fmt)==AV_SAMPLE_FMT_S16 &&av_get_bytes_per_sample(in_fmt) > 2) { ac->dc=ff_dither_alloc(avr, out_fmt, in_fmt, channels, sample_rate, apply_map);if(!ac->dc) { av_free(ac);return NULL;} return ac;} in_planar=ff_sample_fmt_is_planar(in_fmt, channels);out_planar=ff_sample_fmt_is_planar(out_fmt, channels);if(in_planar==out_planar) { ac->func_type=CONV_FUNC_TYPE_FLAT;ac->planes=in_planar ? ac->channels :1;} else if(in_planar) ac->func_type=CONV_FUNC_TYPE_INTERLEAVE;else ac->func_type=CONV_FUNC_TYPE_DEINTERLEAVE;set_generic_function(ac);if(ARCH_AARCH64) ff_audio_convert_init_aarch64(ac);if(ARCH_ARM) ff_audio_convert_init_arm(ac);if(ARCH_X86) ff_audio_convert_init_x86(ac);return ac;} int ff_audio_convert(AudioConvert *ac, AudioData *out, AudioData *in) { int use_generic=1;int len=in->nb_samples;int p;if(ac->dc) { av_log(ac->avr, AV_LOG_TRACE, "%d samples - audio_convert: %s to %s (dithered)\n", len, av_get_sample_fmt_name(ac->in_fmt), av_get_sample_fmt_name(ac->out_fmt));return ff_convert_dither(ac-> in
Definition: audio_convert.c:326
NPPScaleContext::h
int h
Definition: vf_scale_npp.c:90
i
#define i(width, name, range_min, range_max)
Definition: cbs_h2645.c:259
internal.h
common.h
av_frame_move_ref
void av_frame_move_ref(AVFrame *dst, AVFrame *src)
Move everything contained in src to dst and reset src.
Definition: frame.c:582
uint8_t
uint8_t
Definition: audio_convert.c:194
av_frame_unref
void av_frame_unref(AVFrame *frame)
Unreference all the buffers referenced by frame and reset the frame fields.
Definition: frame.c:553
AVFilterPad::name
const char * name
Pad name.
Definition: internal.h:60
NPPScaleContext::w
int w
New dimensions.
Definition: vf_scale_npp.c:90
AVFilter
Filter definition.
Definition: avfilter.h:144
AVHWFramesContext
This struct describes a set or pool of "hardware" frames (i.e.
Definition: hwcontext.h:123
AVCUDADeviceContext
This struct is allocated as AVHWDeviceContext.hwctx.
Definition: hwcontext_cuda.h:42
ret
ret
Definition: filter_design.txt:187
NPPScaleContext::format
enum AVPixelFormat format
Output sw format.
Definition: vf_scale_npp.c:95
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
AVHWFramesContext::device_ctx
AVHWDeviceContext * device_ctx
The parent AVHWDeviceContext.
Definition: hwcontext.h:148
cuda_check.h
NPPScaleContext::interp_algo
int interp_algo
Definition: vf_scale_npp.c:101
NPPScaleContext::w_expr
char * w_expr
width expression string
Definition: vf_scale_npp.c:97
FF_ARRAY_ELEMS
#define FF_ARRAY_ELEMS(a)
Definition: sinewin_tablegen_template.c:38
av_get_pix_fmt
enum AVPixelFormat av_get_pix_fmt(const char *name)
Return the pixel format corresponding to name.
Definition: pixdesc.c:2450
NPPScaleStageContext::in_fmt
enum AVPixelFormat in_fmt
Definition: vf_scale_npp.c:64
AVFrame::height
int height
Definition: frame.h:353
NPPScaleStageContext::planes_in
struct NPPScaleStageContext::@241 planes_in[3]
NPPScaleContext::format_str
char * format_str
Definition: vf_scale_npp.c:99
STAGE_INTERLEAVE
@ STAGE_INTERLEAVE
Definition: vf_scale_npp.c:58
AV_PIX_FMT_NONE
@ AV_PIX_FMT_NONE
Definition: pixfmt.h:65
dummy
int dummy
Definition: motion.c:64
AV_OPT_TYPE_INT
@ AV_OPT_TYPE_INT
Definition: opt.h:223
avfilter.h
nppscale_process
static int(*const nppscale_process[])(AVFilterContext *ctx, NPPScaleStageContext *stage, AVFrame *out, AVFrame *in)
Definition: vf_scale_npp.c:454
nppscale_outputs
static const AVFilterPad nppscale_outputs[]
Definition: vf_scale_npp.c:577
av_mul_q
AVRational av_mul_q(AVRational b, AVRational c)
Multiply two rationals.
Definition: rational.c:80
av_buffer_ref
AVBufferRef * av_buffer_ref(AVBufferRef *buf)
Create a new reference to an AVBuffer.
Definition: buffer.c:93
NPPScaleStageContext::width
int width
Definition: vf_scale_npp.c:68
AV_PIX_FMT_YUV444P
@ AV_PIX_FMT_YUV444P
planar YUV 4:4:4, 24bpp, (1 Cr & Cb sample per 1x1 Y samples)
Definition: pixfmt.h:71
NPPScaleStageContext
Definition: vf_scale_npp.c:62
AVFilterContext
An instance of a filter.
Definition: avfilter.h:338
STAGE_DEINTERLEAVE
@ STAGE_DEINTERLEAVE
Definition: vf_scale_npp.c:56
AVMEDIA_TYPE_VIDEO
@ AVMEDIA_TYPE_VIDEO
Definition: avutil.h:201
AVBufferRef
A reference to a data buffer.
Definition: buffer.h:81
options
static const AVOption options[]
Definition: vf_scale_npp.c:544
nppscale_deinterleave
static int nppscale_deinterleave(AVFilterContext *ctx, NPPScaleStageContext *stage, AVFrame *out, AVFrame *in)
Definition: vf_scale_npp.c:377
AVPixFmtDescriptor
Descriptor that unambiguously describes how the bits of a pixel are stored in the up to 4 data planes...
Definition: pixdesc.h:81
FFALIGN
#define FFALIGN(x, a)
Definition: macros.h:48
deinterleaved_formats
static enum AVPixelFormat deinterleaved_formats[][2]
Definition: vf_scale_npp.c:51
NPPScaleStageContext::planes_out
struct NPPScaleStageContext::@241 planes_out[3]
hwcontext.h
AVERROR_BUG
#define AVERROR_BUG
Internal bug, also see AVERROR_BUG2.
Definition: error.h:50
av_log
#define av_log(a,...)
Definition: tableprint_vlc.h:28
h
h
Definition: vp9dsp_template.c:2038
avstring.h
AV_OPT_TYPE_STRING
@ AV_OPT_TYPE_STRING
Definition: opt.h:227
int
int
Definition: ffmpeg_filter.c:191
av_hwframe_get_buffer
int av_hwframe_get_buffer(AVBufferRef *hwframe_ref, AVFrame *frame, int flags)
Allocate a new frame attached to the given AVHWFramesContext.
Definition: hwcontext.c:465
AV_OPT_TYPE_CONST
@ AV_OPT_TYPE_CONST
Definition: opt.h:232
av_get_pix_fmt_name
const char * av_get_pix_fmt_name(enum AVPixelFormat pix_fmt)
Return the short name for a pixel format, NULL in case pix_fmt is unknown.
Definition: pixdesc.c:2438
nppscale_scale
static int nppscale_scale(AVFilterContext *ctx, AVFrame *out, AVFrame *in)
Definition: vf_scale_npp.c:461