]> git.sesse.net Git - ffmpeg/blob - libavfilter/vf_scale_npp.c
Merge commit '33f6690eb4e21acc4b581688eecfc4cc5ea9515e'
[ffmpeg] / libavfilter / vf_scale_npp.c
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/eval.h"
31 #include "libavutil/hwcontext.h"
32 #include "libavutil/hwcontext_cuda_internal.h"
33 #include "libavutil/internal.h"
34 #include "libavutil/mathematics.h"
35 #include "libavutil/opt.h"
36 #include "libavutil/pixdesc.h"
37
38 #include "avfilter.h"
39 #include "formats.h"
40 #include "internal.h"
41 #include "video.h"
42
43 static const enum AVPixelFormat supported_formats[] = {
44     AV_PIX_FMT_YUV420P,
45     AV_PIX_FMT_NV12,
46     AV_PIX_FMT_YUV444P,
47 };
48
49 static const enum AVPixelFormat deinterleaved_formats[][2] = {
50     { AV_PIX_FMT_NV12, AV_PIX_FMT_YUV420P },
51 };
52
53 static const char *const var_names[] = {
54     "PI",
55     "PHI",
56     "E",
57     "in_w",   "iw",
58     "in_h",   "ih",
59     "out_w",  "ow",
60     "out_h",  "oh",
61     "a", "dar",
62     "sar",
63     NULL
64 };
65
66 enum var_name {
67     VAR_PI,
68     VAR_PHI,
69     VAR_E,
70     VAR_IN_W,   VAR_IW,
71     VAR_IN_H,   VAR_IH,
72     VAR_OUT_W,  VAR_OW,
73     VAR_OUT_H,  VAR_OH,
74     VAR_A, VAR_DAR,
75     VAR_SAR,
76     VARS_NB
77 };
78
79 enum ScaleStage {
80     STAGE_DEINTERLEAVE,
81     STAGE_RESIZE,
82     STAGE_INTERLEAVE,
83     STAGE_NB,
84 };
85
86 typedef struct NPPScaleStageContext {
87     int stage_needed;
88     enum AVPixelFormat in_fmt;
89     enum AVPixelFormat out_fmt;
90
91     struct {
92         int width;
93         int height;
94     } planes_in[3], planes_out[3];
95
96     AVBufferRef *frames_ctx;
97     AVFrame     *frame;
98 } NPPScaleStageContext;
99
100 typedef struct NPPScaleContext {
101     const AVClass *class;
102
103     NPPScaleStageContext stages[STAGE_NB];
104     AVFrame *tmp_frame;
105     int passthrough;
106
107     int shift_width, shift_height;
108
109     /**
110      * New dimensions. Special values are:
111      *   0 = original width/height
112      *  -1 = keep original aspect
113      */
114     int w, h;
115
116     /**
117      * Output sw format. AV_PIX_FMT_NONE for no conversion.
118      */
119     enum AVPixelFormat format;
120
121     char *w_expr;               ///< width  expression string
122     char *h_expr;               ///< height expression string
123     char *format_str;
124
125     int interp_algo;
126 } NPPScaleContext;
127
128 static int nppscale_init(AVFilterContext *ctx)
129 {
130     NPPScaleContext *s = ctx->priv;
131     int i;
132
133     if (!strcmp(s->format_str, "same")) {
134         s->format = AV_PIX_FMT_NONE;
135     } else {
136         s->format = av_get_pix_fmt(s->format_str);
137         if (s->format == AV_PIX_FMT_NONE) {
138             av_log(ctx, AV_LOG_ERROR, "Unrecognized pixel format: %s\n", s->format_str);
139             return AVERROR(EINVAL);
140         }
141     }
142
143     for (i = 0; i < FF_ARRAY_ELEMS(s->stages); i++) {
144         s->stages[i].frame = av_frame_alloc();
145         if (!s->stages[i].frame)
146             return AVERROR(ENOMEM);
147     }
148     s->tmp_frame = av_frame_alloc();
149     if (!s->tmp_frame)
150         return AVERROR(ENOMEM);
151
152     return 0;
153 }
154
155 static void nppscale_uninit(AVFilterContext *ctx)
156 {
157     NPPScaleContext *s = ctx->priv;
158     int i;
159
160     for (i = 0; i < FF_ARRAY_ELEMS(s->stages); i++) {
161         av_frame_free(&s->stages[i].frame);
162         av_buffer_unref(&s->stages[i].frames_ctx);
163     }
164     av_frame_free(&s->tmp_frame);
165 }
166
167 static int nppscale_query_formats(AVFilterContext *ctx)
168 {
169     static const enum AVPixelFormat pixel_formats[] = {
170         AV_PIX_FMT_CUDA, AV_PIX_FMT_NONE,
171     };
172     AVFilterFormats *pix_fmts = ff_make_format_list(pixel_formats);
173
174     return ff_set_common_formats(ctx, pix_fmts);
175 }
176
177 static int init_stage(NPPScaleStageContext *stage, AVBufferRef *device_ctx)
178 {
179     AVBufferRef *out_ref = NULL;
180     AVHWFramesContext *out_ctx;
181     int in_sw, in_sh, out_sw, out_sh;
182     int ret, i;
183
184     av_pix_fmt_get_chroma_sub_sample(stage->in_fmt,  &in_sw,  &in_sh);
185     av_pix_fmt_get_chroma_sub_sample(stage->out_fmt, &out_sw, &out_sh);
186     if (!stage->planes_out[0].width) {
187         stage->planes_out[0].width  = stage->planes_in[0].width;
188         stage->planes_out[0].height = stage->planes_in[0].height;
189     }
190
191     for (i = 1; i < FF_ARRAY_ELEMS(stage->planes_in); i++) {
192         stage->planes_in[i].width   = stage->planes_in[0].width   >> in_sw;
193         stage->planes_in[i].height  = stage->planes_in[0].height  >> in_sh;
194         stage->planes_out[i].width  = stage->planes_out[0].width  >> out_sw;
195         stage->planes_out[i].height = stage->planes_out[0].height >> out_sh;
196     }
197
198     out_ref = av_hwframe_ctx_alloc(device_ctx);
199     if (!out_ref)
200         return AVERROR(ENOMEM);
201     out_ctx = (AVHWFramesContext*)out_ref->data;
202
203     out_ctx->format    = AV_PIX_FMT_CUDA;
204     out_ctx->sw_format = stage->out_fmt;
205     out_ctx->width     = FFALIGN(stage->planes_out[0].width,  32);
206     out_ctx->height    = FFALIGN(stage->planes_out[0].height, 32);
207
208     ret = av_hwframe_ctx_init(out_ref);
209     if (ret < 0)
210         goto fail;
211
212     av_frame_unref(stage->frame);
213     ret = av_hwframe_get_buffer(out_ref, stage->frame, 0);
214     if (ret < 0)
215         goto fail;
216
217     stage->frame->width  = stage->planes_out[0].width;
218     stage->frame->height = stage->planes_out[0].height;
219
220     av_buffer_unref(&stage->frames_ctx);
221     stage->frames_ctx = out_ref;
222
223     return 0;
224 fail:
225     av_buffer_unref(&out_ref);
226     return ret;
227 }
228
229 static int format_is_supported(enum AVPixelFormat fmt)
230 {
231     int i;
232
233     for (i = 0; i < FF_ARRAY_ELEMS(supported_formats); i++)
234         if (supported_formats[i] == fmt)
235             return 1;
236     return 0;
237 }
238
239 static enum AVPixelFormat get_deinterleaved_format(enum AVPixelFormat fmt)
240 {
241     const AVPixFmtDescriptor *desc = av_pix_fmt_desc_get(fmt);
242     int i, planes;
243
244     planes = av_pix_fmt_count_planes(fmt);
245     if (planes == desc->nb_components)
246         return fmt;
247     for (i = 0; i < FF_ARRAY_ELEMS(deinterleaved_formats); i++)
248         if (deinterleaved_formats[i][0] == fmt)
249             return deinterleaved_formats[i][1];
250     return AV_PIX_FMT_NONE;
251 }
252
253 static int init_processing_chain(AVFilterContext *ctx, int in_width, int in_height,
254                                  int out_width, int out_height)
255 {
256     NPPScaleContext *s = ctx->priv;
257
258     AVHWFramesContext *in_frames_ctx;
259
260     enum AVPixelFormat in_format;
261     enum AVPixelFormat out_format;
262     enum AVPixelFormat in_deinterleaved_format;
263     enum AVPixelFormat out_deinterleaved_format;
264
265     int i, ret, last_stage = -1;
266
267     /* check that we have a hw context */
268     if (!ctx->inputs[0]->hw_frames_ctx) {
269         av_log(ctx, AV_LOG_ERROR, "No hw context provided on input\n");
270         return AVERROR(EINVAL);
271     }
272     in_frames_ctx = (AVHWFramesContext*)ctx->inputs[0]->hw_frames_ctx->data;
273     in_format     = in_frames_ctx->sw_format;
274     out_format    = (s->format == AV_PIX_FMT_NONE) ? in_format : s->format;
275
276     if (!format_is_supported(in_format)) {
277         av_log(ctx, AV_LOG_ERROR, "Unsupported input format: %s\n",
278                av_get_pix_fmt_name(in_format));
279         return AVERROR(ENOSYS);
280     }
281     if (!format_is_supported(out_format)) {
282         av_log(ctx, AV_LOG_ERROR, "Unsupported output format: %s\n",
283                av_get_pix_fmt_name(out_format));
284         return AVERROR(ENOSYS);
285     }
286
287     in_deinterleaved_format  = get_deinterleaved_format(in_format);
288     out_deinterleaved_format = get_deinterleaved_format(out_format);
289     if (in_deinterleaved_format  == AV_PIX_FMT_NONE ||
290         out_deinterleaved_format == AV_PIX_FMT_NONE)
291         return AVERROR_BUG;
292
293     /* figure out which stages need to be done */
294     if (in_width != out_width || in_height != out_height ||
295         in_deinterleaved_format != out_deinterleaved_format) {
296         s->stages[STAGE_RESIZE].stage_needed = 1;
297
298         if (s->interp_algo == NPPI_INTER_SUPER &&
299             (out_width > in_width && out_height > in_height)) {
300             s->interp_algo = NPPI_INTER_LANCZOS;
301             av_log(ctx, AV_LOG_WARNING, "super-sampling not supported for output dimensions, using lanczos instead.\n");
302         }
303         if (s->interp_algo == NPPI_INTER_SUPER &&
304             !(out_width < in_width && out_height < in_height)) {
305             s->interp_algo = NPPI_INTER_CUBIC;
306             av_log(ctx, AV_LOG_WARNING, "super-sampling not supported for output dimensions, using cubic instead.\n");
307         }
308     }
309
310     if (!s->stages[STAGE_RESIZE].stage_needed && in_format == out_format)
311         s->passthrough = 1;
312
313     if (!s->passthrough) {
314         if (in_format != in_deinterleaved_format)
315             s->stages[STAGE_DEINTERLEAVE].stage_needed = 1;
316         if (out_format != out_deinterleaved_format)
317             s->stages[STAGE_INTERLEAVE].stage_needed = 1;
318     }
319
320     s->stages[STAGE_DEINTERLEAVE].in_fmt              = in_format;
321     s->stages[STAGE_DEINTERLEAVE].out_fmt             = in_deinterleaved_format;
322     s->stages[STAGE_DEINTERLEAVE].planes_in[0].width  = in_width;
323     s->stages[STAGE_DEINTERLEAVE].planes_in[0].height = in_height;
324
325     s->stages[STAGE_RESIZE].in_fmt               = in_deinterleaved_format;
326     s->stages[STAGE_RESIZE].out_fmt              = out_deinterleaved_format;
327     s->stages[STAGE_RESIZE].planes_in[0].width   = in_width;
328     s->stages[STAGE_RESIZE].planes_in[0].height  = in_height;
329     s->stages[STAGE_RESIZE].planes_out[0].width  = out_width;
330     s->stages[STAGE_RESIZE].planes_out[0].height = out_height;
331
332     s->stages[STAGE_INTERLEAVE].in_fmt              = out_deinterleaved_format;
333     s->stages[STAGE_INTERLEAVE].out_fmt             = out_format;
334     s->stages[STAGE_INTERLEAVE].planes_in[0].width  = out_width;
335     s->stages[STAGE_INTERLEAVE].planes_in[0].height = out_height;
336
337     /* init the hardware contexts */
338     for (i = 0; i < FF_ARRAY_ELEMS(s->stages); i++) {
339         if (!s->stages[i].stage_needed)
340             continue;
341
342         ret = init_stage(&s->stages[i], in_frames_ctx->device_ref);
343         if (ret < 0)
344             return ret;
345
346         last_stage = i;
347     }
348
349     if (last_stage < 0)
350         return 0;
351     ctx->outputs[0]->hw_frames_ctx = av_buffer_ref(s->stages[last_stage].frames_ctx);
352     if (!ctx->outputs[0]->hw_frames_ctx)
353         return AVERROR(ENOMEM);
354
355     return 0;
356 }
357
358 static int nppscale_config_props(AVFilterLink *outlink)
359 {
360     AVFilterContext *ctx = outlink->src;
361     AVFilterLink *inlink = outlink->src->inputs[0];
362     NPPScaleContext  *s = ctx->priv;
363     int64_t w, h;
364     double var_values[VARS_NB], res;
365     char *expr;
366     int ret;
367
368     var_values[VAR_PI]    = M_PI;
369     var_values[VAR_PHI]   = M_PHI;
370     var_values[VAR_E]     = M_E;
371     var_values[VAR_IN_W]  = var_values[VAR_IW] = inlink->w;
372     var_values[VAR_IN_H]  = var_values[VAR_IH] = inlink->h;
373     var_values[VAR_OUT_W] = var_values[VAR_OW] = NAN;
374     var_values[VAR_OUT_H] = var_values[VAR_OH] = NAN;
375     var_values[VAR_A]     = (double) inlink->w / inlink->h;
376     var_values[VAR_SAR]   = inlink->sample_aspect_ratio.num ?
377         (double) inlink->sample_aspect_ratio.num / inlink->sample_aspect_ratio.den : 1;
378     var_values[VAR_DAR]   = var_values[VAR_A] * var_values[VAR_SAR];
379
380     /* evaluate width and height */
381     av_expr_parse_and_eval(&res, (expr = s->w_expr),
382                            var_names, var_values,
383                            NULL, NULL, NULL, NULL, NULL, 0, ctx);
384     s->w = var_values[VAR_OUT_W] = var_values[VAR_OW] = res;
385     if ((ret = av_expr_parse_and_eval(&res, (expr = s->h_expr),
386                                       var_names, var_values,
387                                       NULL, NULL, NULL, NULL, NULL, 0, ctx)) < 0)
388         goto fail;
389     s->h = var_values[VAR_OUT_H] = var_values[VAR_OH] = res;
390     /* evaluate again the width, as it may depend on the output height */
391     if ((ret = av_expr_parse_and_eval(&res, (expr = s->w_expr),
392                                       var_names, var_values,
393                                       NULL, NULL, NULL, NULL, NULL, 0, ctx)) < 0)
394         goto fail;
395     s->w = res;
396
397     w = s->w;
398     h = s->h;
399
400     /* sanity check params */
401     if (w <  -1 || h <  -1) {
402         av_log(ctx, AV_LOG_ERROR, "Size values less than -1 are not acceptable.\n");
403         return AVERROR(EINVAL);
404     }
405     if (w == -1 && h == -1)
406         s->w = s->h = 0;
407
408     if (!(w = s->w))
409         w = inlink->w;
410     if (!(h = s->h))
411         h = inlink->h;
412     if (w == -1)
413         w = av_rescale(h, inlink->w, inlink->h);
414     if (h == -1)
415         h = av_rescale(w, inlink->h, inlink->w);
416
417     if (w > INT_MAX || h > INT_MAX ||
418         (h * inlink->w) > INT_MAX  ||
419         (w * inlink->h) > INT_MAX)
420         av_log(ctx, AV_LOG_ERROR, "Rescaled value for width or height is too big.\n");
421
422     outlink->w = w;
423     outlink->h = h;
424
425     ret = init_processing_chain(ctx, inlink->w, inlink->h, w, h);
426     if (ret < 0)
427         return ret;
428
429     av_log(ctx, AV_LOG_VERBOSE, "w:%d h:%d -> w:%d h:%d\n",
430            inlink->w, inlink->h, outlink->w, outlink->h);
431
432     if (inlink->sample_aspect_ratio.num)
433         outlink->sample_aspect_ratio = av_mul_q((AVRational){outlink->h*inlink->w,
434                                                              outlink->w*inlink->h},
435                                                 inlink->sample_aspect_ratio);
436     else
437         outlink->sample_aspect_ratio = inlink->sample_aspect_ratio;
438
439     return 0;
440
441 fail:
442     av_log(NULL, AV_LOG_ERROR,
443            "Error when evaluating the expression '%s'\n", expr);
444     return ret;
445 }
446
447 static int nppscale_deinterleave(AVFilterContext *ctx, NPPScaleStageContext *stage,
448                                  AVFrame *out, AVFrame *in)
449 {
450     AVHWFramesContext *in_frames_ctx = (AVHWFramesContext*)in->hw_frames_ctx->data;
451     NppStatus err;
452
453     switch (in_frames_ctx->sw_format) {
454     case AV_PIX_FMT_NV12:
455         err = nppiYCbCr420_8u_P2P3R(in->data[0], in->linesize[0],
456                                     in->data[1], in->linesize[1],
457                                     out->data, out->linesize,
458                                     (NppiSize){ in->width, in->height });
459         break;
460     default:
461         return AVERROR_BUG;
462     }
463     if (err != NPP_SUCCESS) {
464         av_log(ctx, AV_LOG_ERROR, "NPP deinterleave error: %d\n", err);
465         return AVERROR_UNKNOWN;
466     }
467
468     return 0;
469 }
470
471 static int nppscale_resize(AVFilterContext *ctx, NPPScaleStageContext *stage,
472                            AVFrame *out, AVFrame *in)
473 {
474     NPPScaleContext *s = ctx->priv;
475     NppStatus err;
476     int i;
477
478     for (i = 0; i < FF_ARRAY_ELEMS(in->data) && in->data[i]; i++) {
479         int iw = stage->planes_in[i].width;
480         int ih = stage->planes_in[i].height;
481         int ow = stage->planes_out[i].width;
482         int oh = stage->planes_out[i].height;
483
484         err = nppiResizeSqrPixel_8u_C1R(in->data[i], (NppiSize){ iw, ih },
485                                         in->linesize[i], (NppiRect){ 0, 0, iw, ih },
486                                         out->data[i], out->linesize[i],
487                                         (NppiRect){ 0, 0, ow, oh },
488                                         (double)ow / iw, (double)oh / ih,
489                                         0.0, 0.0, s->interp_algo);
490         if (err != NPP_SUCCESS) {
491             av_log(ctx, AV_LOG_ERROR, "NPP resize error: %d\n", err);
492             return AVERROR_UNKNOWN;
493         }
494     }
495
496     return 0;
497 }
498
499 static int nppscale_interleave(AVFilterContext *ctx, NPPScaleStageContext *stage,
500                                AVFrame *out, AVFrame *in)
501 {
502     AVHWFramesContext *out_frames_ctx = (AVHWFramesContext*)out->hw_frames_ctx->data;
503     NppStatus err;
504
505     switch (out_frames_ctx->sw_format) {
506     case AV_PIX_FMT_NV12:
507         err = nppiYCbCr420_8u_P3P2R((const uint8_t**)in->data,
508                                     in->linesize,
509                                     out->data[0], out->linesize[0],
510                                     out->data[1], out->linesize[1],
511                                     (NppiSize){ in->width, in->height });
512         break;
513     default:
514         return AVERROR_BUG;
515     }
516     if (err != NPP_SUCCESS) {
517         av_log(ctx, AV_LOG_ERROR, "NPP deinterleave error: %d\n", err);
518         return AVERROR_UNKNOWN;
519     }
520
521     return 0;
522 }
523
524 static int (*const nppscale_process[])(AVFilterContext *ctx, NPPScaleStageContext *stage,
525                                        AVFrame *out, AVFrame *in) = {
526     [STAGE_DEINTERLEAVE] = nppscale_deinterleave,
527     [STAGE_RESIZE]       = nppscale_resize,
528     [STAGE_INTERLEAVE]   = nppscale_interleave,
529 };
530
531 static int nppscale_scale(AVFilterContext *ctx, AVFrame *out, AVFrame *in)
532 {
533     NPPScaleContext *s = ctx->priv;
534     AVFrame *src = in;
535     int i, ret, last_stage = -1;
536
537     for (i = 0; i < FF_ARRAY_ELEMS(s->stages); i++) {
538         if (!s->stages[i].stage_needed)
539             continue;
540
541         ret = nppscale_process[i](ctx, &s->stages[i], s->stages[i].frame, src);
542         if (ret < 0)
543             return ret;
544
545         src        = s->stages[i].frame;
546         last_stage = i;
547     }
548
549     if (last_stage < 0)
550         return AVERROR_BUG;
551     ret = av_hwframe_get_buffer(src->hw_frames_ctx, s->tmp_frame, 0);
552     if (ret < 0)
553         return ret;
554
555     av_frame_move_ref(out, src);
556     av_frame_move_ref(src, s->tmp_frame);
557
558     ret = av_frame_copy_props(out, in);
559     if (ret < 0)
560         return ret;
561
562     return 0;
563 }
564
565 static int nppscale_filter_frame(AVFilterLink *link, AVFrame *in)
566 {
567     AVFilterContext              *ctx = link->dst;
568     NPPScaleContext                *s = ctx->priv;
569     AVFilterLink             *outlink = ctx->outputs[0];
570     AVHWFramesContext     *frames_ctx = (AVHWFramesContext*)outlink->hw_frames_ctx->data;
571     AVCUDADeviceContext *device_hwctx = frames_ctx->device_ctx->hwctx;
572
573     AVFrame *out = NULL;
574     CUresult err;
575     CUcontext dummy;
576     int ret = 0;
577
578     if (s->passthrough)
579         return ff_filter_frame(outlink, in);
580
581     out = av_frame_alloc();
582     if (!out) {
583         ret = AVERROR(ENOMEM);
584         goto fail;
585     }
586
587     err = device_hwctx->internal->cuda_dl->cuCtxPushCurrent(device_hwctx->cuda_ctx);
588     if (err != CUDA_SUCCESS) {
589         ret = AVERROR_UNKNOWN;
590         goto fail;
591     }
592
593     ret = nppscale_scale(ctx, out, in);
594
595     device_hwctx->internal->cuda_dl->cuCtxPopCurrent(&dummy);
596     if (ret < 0)
597         goto fail;
598
599     av_reduce(&out->sample_aspect_ratio.num, &out->sample_aspect_ratio.den,
600               (int64_t)in->sample_aspect_ratio.num * outlink->h * link->w,
601               (int64_t)in->sample_aspect_ratio.den * outlink->w * link->h,
602               INT_MAX);
603
604     av_frame_free(&in);
605     return ff_filter_frame(outlink, out);
606 fail:
607     av_frame_free(&in);
608     av_frame_free(&out);
609     return ret;
610 }
611
612 #define OFFSET(x) offsetof(NPPScaleContext, x)
613 #define FLAGS (AV_OPT_FLAG_FILTERING_PARAM|AV_OPT_FLAG_VIDEO_PARAM)
614 static const AVOption options[] = {
615     { "w",      "Output video width",  OFFSET(w_expr),     AV_OPT_TYPE_STRING, { .str = "iw"   }, .flags = FLAGS },
616     { "h",      "Output video height", OFFSET(h_expr),     AV_OPT_TYPE_STRING, { .str = "ih"   }, .flags = FLAGS },
617     { "format", "Output pixel format", OFFSET(format_str), AV_OPT_TYPE_STRING, { .str = "same" }, .flags = FLAGS },
618
619     { "interp_algo", "Interpolation algorithm used for resizing", OFFSET(interp_algo), AV_OPT_TYPE_INT, { .i64 = NPPI_INTER_CUBIC }, 0, INT_MAX, FLAGS, "interp_algo" },
620         { "nn",                 "nearest neighbour",                 0, AV_OPT_TYPE_CONST, { .i64 = NPPI_INTER_NN                 }, 0, 0, FLAGS, "interp_algo" },
621         { "linear",             "linear",                            0, AV_OPT_TYPE_CONST, { .i64 = NPPI_INTER_LINEAR             }, 0, 0, FLAGS, "interp_algo" },
622         { "cubic",              "cubic",                             0, AV_OPT_TYPE_CONST, { .i64 = NPPI_INTER_CUBIC              }, 0, 0, FLAGS, "interp_algo" },
623         { "cubic2p_bspline",    "2-parameter cubic (B=1, C=0)",      0, AV_OPT_TYPE_CONST, { .i64 = NPPI_INTER_CUBIC2P_BSPLINE    }, 0, 0, FLAGS, "interp_algo" },
624         { "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" },
625         { "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" },
626         { "super",              "supersampling",                     0, AV_OPT_TYPE_CONST, { .i64 = NPPI_INTER_SUPER              }, 0, 0, FLAGS, "interp_algo" },
627         { "lanczos",            "Lanczos",                           0, AV_OPT_TYPE_CONST, { .i64 = NPPI_INTER_LANCZOS            }, 0, 0, FLAGS, "interp_algo" },
628     { NULL },
629 };
630
631 static const AVClass nppscale_class = {
632     .class_name = "nppscale",
633     .item_name  = av_default_item_name,
634     .option     = options,
635     .version    = LIBAVUTIL_VERSION_INT,
636 };
637
638 static const AVFilterPad nppscale_inputs[] = {
639     {
640         .name        = "default",
641         .type        = AVMEDIA_TYPE_VIDEO,
642         .filter_frame = nppscale_filter_frame,
643     },
644     { NULL }
645 };
646
647 static const AVFilterPad nppscale_outputs[] = {
648     {
649         .name         = "default",
650         .type         = AVMEDIA_TYPE_VIDEO,
651         .config_props = nppscale_config_props,
652     },
653     { NULL }
654 };
655
656 AVFilter ff_vf_scale_npp = {
657     .name      = "scale_npp",
658     .description = NULL_IF_CONFIG_SMALL("NVIDIA Performance Primitives video "
659                                         "scaling and format conversion"),
660
661     .init          = nppscale_init,
662     .uninit        = nppscale_uninit,
663     .query_formats = nppscale_query_formats,
664
665     .priv_size = sizeof(NPPScaleContext),
666     .priv_class = &nppscale_class,
667
668     .inputs    = nppscale_inputs,
669     .outputs   = nppscale_outputs,
670 };