vf_scale_npp.c 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599
  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. * @file
  20. * scale video filter
  21. */
  22. #include <nppi.h>
  23. #include <stdio.h>
  24. #include <string.h>
  25. #include "libavutil/avstring.h"
  26. #include "libavutil/common.h"
  27. #include "libavutil/hwcontext.h"
  28. #include "libavutil/hwcontext_cuda_internal.h"
  29. #include "libavutil/cuda_check.h"
  30. #include "libavutil/internal.h"
  31. #include "libavutil/opt.h"
  32. #include "libavutil/pixdesc.h"
  33. #include "avfilter.h"
  34. #include "formats.h"
  35. #include "internal.h"
  36. #include "scale.h"
  37. #include "video.h"
  38. #define CHECK_CU(x) FF_CUDA_CHECK_DL(ctx, device_hwctx->internal->cuda_dl, x)
  39. static const enum AVPixelFormat supported_formats[] = {
  40. AV_PIX_FMT_YUV420P,
  41. AV_PIX_FMT_NV12,
  42. AV_PIX_FMT_YUV444P,
  43. };
  44. static const enum AVPixelFormat deinterleaved_formats[][2] = {
  45. { AV_PIX_FMT_NV12, AV_PIX_FMT_YUV420P },
  46. };
  47. enum ScaleStage {
  48. STAGE_DEINTERLEAVE,
  49. STAGE_RESIZE,
  50. STAGE_INTERLEAVE,
  51. STAGE_NB,
  52. };
  53. typedef struct NPPScaleStageContext {
  54. int stage_needed;
  55. enum AVPixelFormat in_fmt;
  56. enum AVPixelFormat out_fmt;
  57. struct {
  58. int width;
  59. int height;
  60. } planes_in[3], planes_out[3];
  61. AVBufferRef *frames_ctx;
  62. AVFrame *frame;
  63. } NPPScaleStageContext;
  64. typedef struct NPPScaleContext {
  65. const AVClass *class;
  66. NPPScaleStageContext stages[STAGE_NB];
  67. AVFrame *tmp_frame;
  68. int passthrough;
  69. int shift_width, shift_height;
  70. /**
  71. * New dimensions. Special values are:
  72. * 0 = original width/height
  73. * -1 = keep original aspect
  74. */
  75. int w, h;
  76. /**
  77. * Output sw format. AV_PIX_FMT_NONE for no conversion.
  78. */
  79. enum AVPixelFormat format;
  80. char *w_expr; ///< width expression string
  81. char *h_expr; ///< height expression string
  82. char *format_str;
  83. int interp_algo;
  84. } NPPScaleContext;
  85. static int nppscale_init(AVFilterContext *ctx)
  86. {
  87. NPPScaleContext *s = ctx->priv;
  88. int i;
  89. if (!strcmp(s->format_str, "same")) {
  90. s->format = AV_PIX_FMT_NONE;
  91. } else {
  92. s->format = av_get_pix_fmt(s->format_str);
  93. if (s->format == AV_PIX_FMT_NONE) {
  94. av_log(ctx, AV_LOG_ERROR, "Unrecognized pixel format: %s\n", s->format_str);
  95. return AVERROR(EINVAL);
  96. }
  97. }
  98. for (i = 0; i < FF_ARRAY_ELEMS(s->stages); i++) {
  99. s->stages[i].frame = av_frame_alloc();
  100. if (!s->stages[i].frame)
  101. return AVERROR(ENOMEM);
  102. }
  103. s->tmp_frame = av_frame_alloc();
  104. if (!s->tmp_frame)
  105. return AVERROR(ENOMEM);
  106. return 0;
  107. }
  108. static void nppscale_uninit(AVFilterContext *ctx)
  109. {
  110. NPPScaleContext *s = ctx->priv;
  111. int i;
  112. for (i = 0; i < FF_ARRAY_ELEMS(s->stages); i++) {
  113. av_frame_free(&s->stages[i].frame);
  114. av_buffer_unref(&s->stages[i].frames_ctx);
  115. }
  116. av_frame_free(&s->tmp_frame);
  117. }
  118. static int nppscale_query_formats(AVFilterContext *ctx)
  119. {
  120. static const enum AVPixelFormat pixel_formats[] = {
  121. AV_PIX_FMT_CUDA, AV_PIX_FMT_NONE,
  122. };
  123. AVFilterFormats *pix_fmts = ff_make_format_list(pixel_formats);
  124. return ff_set_common_formats(ctx, pix_fmts);
  125. }
  126. static int init_stage(NPPScaleStageContext *stage, AVBufferRef *device_ctx)
  127. {
  128. AVBufferRef *out_ref = NULL;
  129. AVHWFramesContext *out_ctx;
  130. int in_sw, in_sh, out_sw, out_sh;
  131. int ret, i;
  132. av_pix_fmt_get_chroma_sub_sample(stage->in_fmt, &in_sw, &in_sh);
  133. av_pix_fmt_get_chroma_sub_sample(stage->out_fmt, &out_sw, &out_sh);
  134. if (!stage->planes_out[0].width) {
  135. stage->planes_out[0].width = stage->planes_in[0].width;
  136. stage->planes_out[0].height = stage->planes_in[0].height;
  137. }
  138. for (i = 1; i < FF_ARRAY_ELEMS(stage->planes_in); i++) {
  139. stage->planes_in[i].width = stage->planes_in[0].width >> in_sw;
  140. stage->planes_in[i].height = stage->planes_in[0].height >> in_sh;
  141. stage->planes_out[i].width = stage->planes_out[0].width >> out_sw;
  142. stage->planes_out[i].height = stage->planes_out[0].height >> out_sh;
  143. }
  144. out_ref = av_hwframe_ctx_alloc(device_ctx);
  145. if (!out_ref)
  146. return AVERROR(ENOMEM);
  147. out_ctx = (AVHWFramesContext*)out_ref->data;
  148. out_ctx->format = AV_PIX_FMT_CUDA;
  149. out_ctx->sw_format = stage->out_fmt;
  150. out_ctx->width = FFALIGN(stage->planes_out[0].width, 32);
  151. out_ctx->height = FFALIGN(stage->planes_out[0].height, 32);
  152. ret = av_hwframe_ctx_init(out_ref);
  153. if (ret < 0)
  154. goto fail;
  155. av_frame_unref(stage->frame);
  156. ret = av_hwframe_get_buffer(out_ref, stage->frame, 0);
  157. if (ret < 0)
  158. goto fail;
  159. stage->frame->width = stage->planes_out[0].width;
  160. stage->frame->height = stage->planes_out[0].height;
  161. av_buffer_unref(&stage->frames_ctx);
  162. stage->frames_ctx = out_ref;
  163. return 0;
  164. fail:
  165. av_buffer_unref(&out_ref);
  166. return ret;
  167. }
  168. static int format_is_supported(enum AVPixelFormat fmt)
  169. {
  170. int i;
  171. for (i = 0; i < FF_ARRAY_ELEMS(supported_formats); i++)
  172. if (supported_formats[i] == fmt)
  173. return 1;
  174. return 0;
  175. }
  176. static enum AVPixelFormat get_deinterleaved_format(enum AVPixelFormat fmt)
  177. {
  178. const AVPixFmtDescriptor *desc = av_pix_fmt_desc_get(fmt);
  179. int i, planes;
  180. planes = av_pix_fmt_count_planes(fmt);
  181. if (planes == desc->nb_components)
  182. return fmt;
  183. for (i = 0; i < FF_ARRAY_ELEMS(deinterleaved_formats); i++)
  184. if (deinterleaved_formats[i][0] == fmt)
  185. return deinterleaved_formats[i][1];
  186. return AV_PIX_FMT_NONE;
  187. }
  188. static int init_processing_chain(AVFilterContext *ctx, int in_width, int in_height,
  189. int out_width, int out_height)
  190. {
  191. NPPScaleContext *s = ctx->priv;
  192. AVHWFramesContext *in_frames_ctx;
  193. enum AVPixelFormat in_format;
  194. enum AVPixelFormat out_format;
  195. enum AVPixelFormat in_deinterleaved_format;
  196. enum AVPixelFormat out_deinterleaved_format;
  197. int i, ret, last_stage = -1;
  198. /* check that we have a hw context */
  199. if (!ctx->inputs[0]->hw_frames_ctx) {
  200. av_log(ctx, AV_LOG_ERROR, "No hw context provided on input\n");
  201. return AVERROR(EINVAL);
  202. }
  203. in_frames_ctx = (AVHWFramesContext*)ctx->inputs[0]->hw_frames_ctx->data;
  204. in_format = in_frames_ctx->sw_format;
  205. out_format = (s->format == AV_PIX_FMT_NONE) ? in_format : s->format;
  206. if (!format_is_supported(in_format)) {
  207. av_log(ctx, AV_LOG_ERROR, "Unsupported input format: %s\n",
  208. av_get_pix_fmt_name(in_format));
  209. return AVERROR(ENOSYS);
  210. }
  211. if (!format_is_supported(out_format)) {
  212. av_log(ctx, AV_LOG_ERROR, "Unsupported output format: %s\n",
  213. av_get_pix_fmt_name(out_format));
  214. return AVERROR(ENOSYS);
  215. }
  216. in_deinterleaved_format = get_deinterleaved_format(in_format);
  217. out_deinterleaved_format = get_deinterleaved_format(out_format);
  218. if (in_deinterleaved_format == AV_PIX_FMT_NONE ||
  219. out_deinterleaved_format == AV_PIX_FMT_NONE)
  220. return AVERROR_BUG;
  221. /* figure out which stages need to be done */
  222. if (in_width != out_width || in_height != out_height ||
  223. in_deinterleaved_format != out_deinterleaved_format) {
  224. s->stages[STAGE_RESIZE].stage_needed = 1;
  225. if (s->interp_algo == NPPI_INTER_SUPER &&
  226. (out_width > in_width && out_height > in_height)) {
  227. s->interp_algo = NPPI_INTER_LANCZOS;
  228. av_log(ctx, AV_LOG_WARNING, "super-sampling not supported for output dimensions, using lanczos instead.\n");
  229. }
  230. if (s->interp_algo == NPPI_INTER_SUPER &&
  231. !(out_width < in_width && out_height < in_height)) {
  232. s->interp_algo = NPPI_INTER_CUBIC;
  233. av_log(ctx, AV_LOG_WARNING, "super-sampling not supported for output dimensions, using cubic instead.\n");
  234. }
  235. }
  236. if (!s->stages[STAGE_RESIZE].stage_needed && in_format == out_format)
  237. s->passthrough = 1;
  238. if (!s->passthrough) {
  239. if (in_format != in_deinterleaved_format)
  240. s->stages[STAGE_DEINTERLEAVE].stage_needed = 1;
  241. if (out_format != out_deinterleaved_format)
  242. s->stages[STAGE_INTERLEAVE].stage_needed = 1;
  243. }
  244. s->stages[STAGE_DEINTERLEAVE].in_fmt = in_format;
  245. s->stages[STAGE_DEINTERLEAVE].out_fmt = in_deinterleaved_format;
  246. s->stages[STAGE_DEINTERLEAVE].planes_in[0].width = in_width;
  247. s->stages[STAGE_DEINTERLEAVE].planes_in[0].height = in_height;
  248. s->stages[STAGE_RESIZE].in_fmt = in_deinterleaved_format;
  249. s->stages[STAGE_RESIZE].out_fmt = out_deinterleaved_format;
  250. s->stages[STAGE_RESIZE].planes_in[0].width = in_width;
  251. s->stages[STAGE_RESIZE].planes_in[0].height = in_height;
  252. s->stages[STAGE_RESIZE].planes_out[0].width = out_width;
  253. s->stages[STAGE_RESIZE].planes_out[0].height = out_height;
  254. s->stages[STAGE_INTERLEAVE].in_fmt = out_deinterleaved_format;
  255. s->stages[STAGE_INTERLEAVE].out_fmt = out_format;
  256. s->stages[STAGE_INTERLEAVE].planes_in[0].width = out_width;
  257. s->stages[STAGE_INTERLEAVE].planes_in[0].height = out_height;
  258. /* init the hardware contexts */
  259. for (i = 0; i < FF_ARRAY_ELEMS(s->stages); i++) {
  260. if (!s->stages[i].stage_needed)
  261. continue;
  262. ret = init_stage(&s->stages[i], in_frames_ctx->device_ref);
  263. if (ret < 0)
  264. return ret;
  265. last_stage = i;
  266. }
  267. if (last_stage >= 0)
  268. ctx->outputs[0]->hw_frames_ctx = av_buffer_ref(s->stages[last_stage].frames_ctx);
  269. else
  270. ctx->outputs[0]->hw_frames_ctx = av_buffer_ref(ctx->inputs[0]->hw_frames_ctx);
  271. if (!ctx->outputs[0]->hw_frames_ctx)
  272. return AVERROR(ENOMEM);
  273. return 0;
  274. }
  275. static int nppscale_config_props(AVFilterLink *outlink)
  276. {
  277. AVFilterContext *ctx = outlink->src;
  278. AVFilterLink *inlink = outlink->src->inputs[0];
  279. NPPScaleContext *s = ctx->priv;
  280. int w, h;
  281. int ret;
  282. if ((ret = ff_scale_eval_dimensions(s,
  283. s->w_expr, s->h_expr,
  284. inlink, outlink,
  285. &w, &h)) < 0)
  286. goto fail;
  287. if (((int64_t)h * inlink->w) > INT_MAX ||
  288. ((int64_t)w * inlink->h) > INT_MAX)
  289. av_log(ctx, AV_LOG_ERROR, "Rescaled value for width or height is too big.\n");
  290. outlink->w = w;
  291. outlink->h = h;
  292. ret = init_processing_chain(ctx, inlink->w, inlink->h, w, h);
  293. if (ret < 0)
  294. return ret;
  295. av_log(ctx, AV_LOG_VERBOSE, "w:%d h:%d -> w:%d h:%d\n",
  296. inlink->w, inlink->h, outlink->w, outlink->h);
  297. if (inlink->sample_aspect_ratio.num)
  298. outlink->sample_aspect_ratio = av_mul_q((AVRational){outlink->h*inlink->w,
  299. outlink->w*inlink->h},
  300. inlink->sample_aspect_ratio);
  301. else
  302. outlink->sample_aspect_ratio = inlink->sample_aspect_ratio;
  303. return 0;
  304. fail:
  305. return ret;
  306. }
  307. static int nppscale_deinterleave(AVFilterContext *ctx, NPPScaleStageContext *stage,
  308. AVFrame *out, AVFrame *in)
  309. {
  310. AVHWFramesContext *in_frames_ctx = (AVHWFramesContext*)in->hw_frames_ctx->data;
  311. NppStatus err;
  312. switch (in_frames_ctx->sw_format) {
  313. case AV_PIX_FMT_NV12:
  314. err = nppiYCbCr420_8u_P2P3R(in->data[0], in->linesize[0],
  315. in->data[1], in->linesize[1],
  316. out->data, out->linesize,
  317. (NppiSize){ in->width, in->height });
  318. break;
  319. default:
  320. return AVERROR_BUG;
  321. }
  322. if (err != NPP_SUCCESS) {
  323. av_log(ctx, AV_LOG_ERROR, "NPP deinterleave error: %d\n", err);
  324. return AVERROR_UNKNOWN;
  325. }
  326. return 0;
  327. }
  328. static int nppscale_resize(AVFilterContext *ctx, NPPScaleStageContext *stage,
  329. AVFrame *out, AVFrame *in)
  330. {
  331. NPPScaleContext *s = ctx->priv;
  332. NppStatus err;
  333. int i;
  334. for (i = 0; i < FF_ARRAY_ELEMS(stage->planes_in) && i < FF_ARRAY_ELEMS(in->data) && in->data[i]; i++) {
  335. int iw = stage->planes_in[i].width;
  336. int ih = stage->planes_in[i].height;
  337. int ow = stage->planes_out[i].width;
  338. int oh = stage->planes_out[i].height;
  339. err = nppiResizeSqrPixel_8u_C1R(in->data[i], (NppiSize){ iw, ih },
  340. in->linesize[i], (NppiRect){ 0, 0, iw, ih },
  341. out->data[i], out->linesize[i],
  342. (NppiRect){ 0, 0, ow, oh },
  343. (double)ow / iw, (double)oh / ih,
  344. 0.0, 0.0, s->interp_algo);
  345. if (err != NPP_SUCCESS) {
  346. av_log(ctx, AV_LOG_ERROR, "NPP resize error: %d\n", err);
  347. return AVERROR_UNKNOWN;
  348. }
  349. }
  350. return 0;
  351. }
  352. static int nppscale_interleave(AVFilterContext *ctx, NPPScaleStageContext *stage,
  353. AVFrame *out, AVFrame *in)
  354. {
  355. AVHWFramesContext *out_frames_ctx = (AVHWFramesContext*)out->hw_frames_ctx->data;
  356. NppStatus err;
  357. switch (out_frames_ctx->sw_format) {
  358. case AV_PIX_FMT_NV12:
  359. err = nppiYCbCr420_8u_P3P2R((const uint8_t**)in->data,
  360. in->linesize,
  361. out->data[0], out->linesize[0],
  362. out->data[1], out->linesize[1],
  363. (NppiSize){ in->width, in->height });
  364. break;
  365. default:
  366. return AVERROR_BUG;
  367. }
  368. if (err != NPP_SUCCESS) {
  369. av_log(ctx, AV_LOG_ERROR, "NPP deinterleave error: %d\n", err);
  370. return AVERROR_UNKNOWN;
  371. }
  372. return 0;
  373. }
  374. static int (*const nppscale_process[])(AVFilterContext *ctx, NPPScaleStageContext *stage,
  375. AVFrame *out, AVFrame *in) = {
  376. [STAGE_DEINTERLEAVE] = nppscale_deinterleave,
  377. [STAGE_RESIZE] = nppscale_resize,
  378. [STAGE_INTERLEAVE] = nppscale_interleave,
  379. };
  380. static int nppscale_scale(AVFilterContext *ctx, AVFrame *out, AVFrame *in)
  381. {
  382. NPPScaleContext *s = ctx->priv;
  383. AVFrame *src = in;
  384. int i, ret, last_stage = -1;
  385. for (i = 0; i < FF_ARRAY_ELEMS(s->stages); i++) {
  386. if (!s->stages[i].stage_needed)
  387. continue;
  388. ret = nppscale_process[i](ctx, &s->stages[i], s->stages[i].frame, src);
  389. if (ret < 0)
  390. return ret;
  391. src = s->stages[i].frame;
  392. last_stage = i;
  393. }
  394. if (last_stage < 0)
  395. return AVERROR_BUG;
  396. ret = av_hwframe_get_buffer(src->hw_frames_ctx, s->tmp_frame, 0);
  397. if (ret < 0)
  398. return ret;
  399. av_frame_move_ref(out, src);
  400. av_frame_move_ref(src, s->tmp_frame);
  401. ret = av_frame_copy_props(out, in);
  402. if (ret < 0)
  403. return ret;
  404. return 0;
  405. }
  406. static int nppscale_filter_frame(AVFilterLink *link, AVFrame *in)
  407. {
  408. AVFilterContext *ctx = link->dst;
  409. NPPScaleContext *s = ctx->priv;
  410. AVFilterLink *outlink = ctx->outputs[0];
  411. AVHWFramesContext *frames_ctx = (AVHWFramesContext*)outlink->hw_frames_ctx->data;
  412. AVCUDADeviceContext *device_hwctx = frames_ctx->device_ctx->hwctx;
  413. AVFrame *out = NULL;
  414. CUcontext dummy;
  415. int ret = 0;
  416. if (s->passthrough)
  417. return ff_filter_frame(outlink, in);
  418. out = av_frame_alloc();
  419. if (!out) {
  420. ret = AVERROR(ENOMEM);
  421. goto fail;
  422. }
  423. ret = CHECK_CU(device_hwctx->internal->cuda_dl->cuCtxPushCurrent(device_hwctx->cuda_ctx));
  424. if (ret < 0)
  425. goto fail;
  426. ret = nppscale_scale(ctx, out, in);
  427. CHECK_CU(device_hwctx->internal->cuda_dl->cuCtxPopCurrent(&dummy));
  428. if (ret < 0)
  429. goto fail;
  430. av_reduce(&out->sample_aspect_ratio.num, &out->sample_aspect_ratio.den,
  431. (int64_t)in->sample_aspect_ratio.num * outlink->h * link->w,
  432. (int64_t)in->sample_aspect_ratio.den * outlink->w * link->h,
  433. INT_MAX);
  434. av_frame_free(&in);
  435. return ff_filter_frame(outlink, out);
  436. fail:
  437. av_frame_free(&in);
  438. av_frame_free(&out);
  439. return ret;
  440. }
  441. #define OFFSET(x) offsetof(NPPScaleContext, x)
  442. #define FLAGS (AV_OPT_FLAG_FILTERING_PARAM|AV_OPT_FLAG_VIDEO_PARAM)
  443. static const AVOption options[] = {
  444. { "w", "Output video width", OFFSET(w_expr), AV_OPT_TYPE_STRING, { .str = "iw" }, .flags = FLAGS },
  445. { "h", "Output video height", OFFSET(h_expr), AV_OPT_TYPE_STRING, { .str = "ih" }, .flags = FLAGS },
  446. { "format", "Output pixel format", OFFSET(format_str), AV_OPT_TYPE_STRING, { .str = "same" }, .flags = FLAGS },
  447. { "interp_algo", "Interpolation algorithm used for resizing", OFFSET(interp_algo), AV_OPT_TYPE_INT, { .i64 = NPPI_INTER_CUBIC }, 0, INT_MAX, FLAGS, "interp_algo" },
  448. { "nn", "nearest neighbour", 0, AV_OPT_TYPE_CONST, { .i64 = NPPI_INTER_NN }, 0, 0, FLAGS, "interp_algo" },
  449. { "linear", "linear", 0, AV_OPT_TYPE_CONST, { .i64 = NPPI_INTER_LINEAR }, 0, 0, FLAGS, "interp_algo" },
  450. { "cubic", "cubic", 0, AV_OPT_TYPE_CONST, { .i64 = NPPI_INTER_CUBIC }, 0, 0, FLAGS, "interp_algo" },
  451. { "cubic2p_bspline", "2-parameter cubic (B=1, C=0)", 0, AV_OPT_TYPE_CONST, { .i64 = NPPI_INTER_CUBIC2P_BSPLINE }, 0, 0, FLAGS, "interp_algo" },
  452. { "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" },
  453. { "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" },
  454. { "super", "supersampling", 0, AV_OPT_TYPE_CONST, { .i64 = NPPI_INTER_SUPER }, 0, 0, FLAGS, "interp_algo" },
  455. { "lanczos", "Lanczos", 0, AV_OPT_TYPE_CONST, { .i64 = NPPI_INTER_LANCZOS }, 0, 0, FLAGS, "interp_algo" },
  456. { NULL },
  457. };
  458. static const AVClass nppscale_class = {
  459. .class_name = "nppscale",
  460. .item_name = av_default_item_name,
  461. .option = options,
  462. .version = LIBAVUTIL_VERSION_INT,
  463. };
  464. static const AVFilterPad nppscale_inputs[] = {
  465. {
  466. .name = "default",
  467. .type = AVMEDIA_TYPE_VIDEO,
  468. .filter_frame = nppscale_filter_frame,
  469. },
  470. { NULL }
  471. };
  472. static const AVFilterPad nppscale_outputs[] = {
  473. {
  474. .name = "default",
  475. .type = AVMEDIA_TYPE_VIDEO,
  476. .config_props = nppscale_config_props,
  477. },
  478. { NULL }
  479. };
  480. AVFilter ff_vf_scale_npp = {
  481. .name = "scale_npp",
  482. .description = NULL_IF_CONFIG_SMALL("NVIDIA Performance Primitives video "
  483. "scaling and format conversion"),
  484. .init = nppscale_init,
  485. .uninit = nppscale_uninit,
  486. .query_formats = nppscale_query_formats,
  487. .priv_size = sizeof(NPPScaleContext),
  488. .priv_class = &nppscale_class,
  489. .inputs = nppscale_inputs,
  490. .outputs = nppscale_outputs,
  491. .flags_internal = FF_FILTER_FLAG_HWFRAME_AWARE,
  492. };