FFmpeg
Data Structures | Macros | Enumerations | Functions | Variables
vf_scale_cuda.c File Reference
#include <float.h>
#include <stdio.h>
#include "libavutil/common.h"
#include "libavutil/hwcontext.h"
#include "libavutil/hwcontext_cuda_internal.h"
#include "libavutil/cuda_check.h"
#include "libavutil/internal.h"
#include "libavutil/opt.h"
#include "libavutil/pixdesc.h"
#include "avfilter.h"
#include "filters.h"
#include "scale_eval.h"
#include "video.h"
#include "cuda/load_helper.h"
#include "vf_scale_cuda.h"

Go to the source code of this file.

Data Structures

struct  CUDAScaleContext
 

Macros

#define DIV_UP(a, b)   ( ((a) + (b) - 1) / (b) )
 
#define BLOCKX   32
 
#define BLOCKY   16
 
#define CHECK_CU(x)   FF_CUDA_CHECK_DL(ctx, s->hwctx->internal->cuda_dl, x)
 
#define OFFSET(x)   offsetof(CUDAScaleContext, x)
 
#define FLAGS   (AV_OPT_FLAG_FILTERING_PARAM|AV_OPT_FLAG_VIDEO_PARAM)
 

Enumerations

enum  {
  INTERP_ALGO_DEFAULT, INTERP_ALGO_NEAREST, INTERP_ALGO_BILINEAR, INTERP_ALGO_BICUBIC,
  INTERP_ALGO_LANCZOS, INTERP_ALGO_COUNT
}
 

Functions

static av_cold int cudascale_init (AVFilterContext *ctx)
 
static av_cold void cudascale_uninit (AVFilterContext *ctx)
 
static av_cold int init_hwframe_ctx (CUDAScaleContext *s, AVBufferRef *device_ctx, int width, int height)
 
static int format_is_supported (enum AVPixelFormat fmt)
 
static av_cold void set_format_info (AVFilterContext *ctx, enum AVPixelFormat in_format, enum AVPixelFormat out_format)
 
static av_cold int init_processing_chain (AVFilterContext *ctx, int in_width, int in_height, int out_width, int out_height)
 
static av_cold int cudascale_load_functions (AVFilterContext *ctx)
 
static av_cold int cudascale_config_props (AVFilterLink *outlink)
 
static int call_resize_kernel (AVFilterContext *ctx, CUfunction func, CUtexObject src_tex[4], int src_left, int src_top, int src_width, int src_height, AVFrame *out_frame, int dst_width, int dst_height, int dst_pitch)
 
static int scalecuda_resize (AVFilterContext *ctx, AVFrame *out, AVFrame *in)
 
static int cudascale_scale (AVFilterContext *ctx, AVFrame *out, AVFrame *in)
 
static int cudascale_filter_frame (AVFilterLink *link, AVFrame *in)
 
static AVFramecudascale_get_video_buffer (AVFilterLink *inlink, int w, int h)
 

Variables

static enum AVPixelFormat supported_formats []
 
static const AVOption options []
 
static const AVClass cudascale_class
 
static const AVFilterPad cudascale_inputs []
 
static const AVFilterPad cudascale_outputs []
 
const AVFilter ff_vf_scale_cuda
 

Macro Definition Documentation

◆ DIV_UP

#define DIV_UP (   a,
  b 
)    ( ((a) + (b) - 1) / (b) )

Definition at line 55 of file vf_scale_cuda.c.

◆ BLOCKX

#define BLOCKX   32

Definition at line 56 of file vf_scale_cuda.c.

◆ BLOCKY

#define BLOCKY   16

Definition at line 57 of file vf_scale_cuda.c.

◆ CHECK_CU

#define CHECK_CU (   x)    FF_CUDA_CHECK_DL(ctx, s->hwctx->internal->cuda_dl, x)

Definition at line 59 of file vf_scale_cuda.c.

◆ OFFSET

#define OFFSET (   x)    offsetof(CUDAScaleContext, x)

Definition at line 599 of file vf_scale_cuda.c.

◆ FLAGS

Definition at line 600 of file vf_scale_cuda.c.

Enumeration Type Documentation

◆ anonymous enum

anonymous enum
Enumerator
INTERP_ALGO_DEFAULT 
INTERP_ALGO_NEAREST 
INTERP_ALGO_BILINEAR 
INTERP_ALGO_BICUBIC 
INTERP_ALGO_LANCZOS 
INTERP_ALGO_COUNT 

Definition at line 61 of file vf_scale_cuda.c.

Function Documentation

◆ cudascale_init()

static av_cold int cudascale_init ( AVFilterContext ctx)
static

Definition at line 113 of file vf_scale_cuda.c.

◆ cudascale_uninit()

static av_cold void cudascale_uninit ( AVFilterContext ctx)
static

Definition at line 128 of file vf_scale_cuda.c.

◆ init_hwframe_ctx()

static av_cold int init_hwframe_ctx ( CUDAScaleContext s,
AVBufferRef device_ctx,
int  width,
int  height 
)
static

Definition at line 147 of file vf_scale_cuda.c.

Referenced by init_processing_chain().

◆ format_is_supported()

static int format_is_supported ( enum AVPixelFormat  fmt)
static

Definition at line 184 of file vf_scale_cuda.c.

Referenced by init_processing_chain().

◆ set_format_info()

static av_cold void set_format_info ( AVFilterContext ctx,
enum AVPixelFormat  in_format,
enum AVPixelFormat  out_format 
)
static

Definition at line 194 of file vf_scale_cuda.c.

Referenced by init_processing_chain().

◆ init_processing_chain()

static av_cold int init_processing_chain ( AVFilterContext ctx,
int  in_width,
int  in_height,
int  out_width,
int  out_height 
)
static

Definition at line 220 of file vf_scale_cuda.c.

Referenced by cudascale_config_props().

◆ cudascale_load_functions()

static av_cold int cudascale_load_functions ( AVFilterContext ctx)
static

Definition at line 278 of file vf_scale_cuda.c.

Referenced by cudascale_config_props().

◆ cudascale_config_props()

static av_cold int cudascale_config_props ( AVFilterLink outlink)
static

Definition at line 349 of file vf_scale_cuda.c.

◆ call_resize_kernel()

static int call_resize_kernel ( AVFilterContext ctx,
CUfunction  func,
CUtexObject  src_tex[4],
int  src_left,
int  src_top,
int  src_width,
int  src_height,
AVFrame out_frame,
int  dst_width,
int  dst_height,
int  dst_pitch 
)
static

Definition at line 409 of file vf_scale_cuda.c.

Referenced by scalecuda_resize().

◆ scalecuda_resize()

static int scalecuda_resize ( AVFilterContext ctx,
AVFrame out,
AVFrame in 
)
static

Definition at line 433 of file vf_scale_cuda.c.

Referenced by cudascale_scale().

◆ cudascale_scale()

static int cudascale_scale ( AVFilterContext ctx,
AVFrame out,
AVFrame in 
)
static

Definition at line 513 of file vf_scale_cuda.c.

Referenced by cudascale_filter_frame().

◆ cudascale_filter_frame()

static int cudascale_filter_frame ( AVFilterLink link,
AVFrame in 
)
static

Definition at line 547 of file vf_scale_cuda.c.

◆ cudascale_get_video_buffer()

static AVFrame* cudascale_get_video_buffer ( AVFilterLink inlink,
int  w,
int  h 
)
static

Definition at line 590 of file vf_scale_cuda.c.

Variable Documentation

◆ supported_formats

enum AVPixelFormat supported_formats[]
static

◆ options

const AVOption options[]
static
Initial value:
= {
{ "w", "Output video width", OFFSET(w_expr), AV_OPT_TYPE_STRING, { .str = "iw" }, .flags = FLAGS },
{ "h", "Output video height", OFFSET(h_expr), AV_OPT_TYPE_STRING, { .str = "ih" }, .flags = FLAGS },
{ "interp_algo", "Interpolation algorithm used for resizing", OFFSET(interp_algo), AV_OPT_TYPE_INT, { .i64 = INTERP_ALGO_DEFAULT }, 0, INTERP_ALGO_COUNT - 1, FLAGS, .unit = "interp_algo" },
{ "nearest", "nearest neighbour", 0, AV_OPT_TYPE_CONST, { .i64 = INTERP_ALGO_NEAREST }, 0, 0, FLAGS, .unit = "interp_algo" },
{ "bilinear", "bilinear", 0, AV_OPT_TYPE_CONST, { .i64 = INTERP_ALGO_BILINEAR }, 0, 0, FLAGS, .unit = "interp_algo" },
{ "bicubic", "bicubic", 0, AV_OPT_TYPE_CONST, { .i64 = INTERP_ALGO_BICUBIC }, 0, 0, FLAGS, .unit = "interp_algo" },
{ "lanczos", "lanczos", 0, AV_OPT_TYPE_CONST, { .i64 = INTERP_ALGO_LANCZOS }, 0, 0, FLAGS, .unit = "interp_algo" },
{ "format", "Output video pixel format", OFFSET(format), AV_OPT_TYPE_PIXEL_FMT, { .i64 = AV_PIX_FMT_NONE }, INT_MIN, INT_MAX, .flags=FLAGS },
{ "passthrough", "Do not process frames at all if parameters match", OFFSET(passthrough), AV_OPT_TYPE_BOOL, { .i64 = 1 }, 0, 1, FLAGS },
{ "param", "Algorithm-Specific parameter", OFFSET(param), AV_OPT_TYPE_FLOAT, { .dbl = SCALE_CUDA_PARAM_DEFAULT }, -FLT_MAX, FLT_MAX, FLAGS },
{ "force_original_aspect_ratio", "decrease or increase w/h if necessary to keep the original AR", OFFSET(force_original_aspect_ratio), AV_OPT_TYPE_INT, { .i64 = 0 }, 0, 2, FLAGS, .unit = "force_oar" },
{ "disable", NULL, 0, AV_OPT_TYPE_CONST, {.i64 = 0 }, 0, 0, FLAGS, .unit = "force_oar" },
{ "decrease", NULL, 0, AV_OPT_TYPE_CONST, {.i64 = 1 }, 0, 0, FLAGS, .unit = "force_oar" },
{ "increase", NULL, 0, AV_OPT_TYPE_CONST, {.i64 = 2 }, 0, 0, FLAGS, .unit = "force_oar" },
{ "force_divisible_by", "enforce that the output resolution is divisible by a defined integer when force_original_aspect_ratio is used", OFFSET(force_divisible_by), AV_OPT_TYPE_INT, { .i64 = 1 }, 1, 256, FLAGS },
{ NULL },
}

Definition at line 601 of file vf_scale_cuda.c.

◆ cudascale_class

const AVClass cudascale_class
static
Initial value:
= {
.class_name = "cudascale",
.item_name = av_default_item_name,
.option = options,
}

Definition at line 620 of file vf_scale_cuda.c.

◆ cudascale_inputs

const AVFilterPad cudascale_inputs[]
static
Initial value:
= {
{
.name = "default",
.filter_frame = cudascale_filter_frame,
.get_buffer.video = cudascale_get_video_buffer,
},
}

Definition at line 627 of file vf_scale_cuda.c.

◆ cudascale_outputs

const AVFilterPad cudascale_outputs[]
static
Initial value:
= {
{
.name = "default",
.config_props = cudascale_config_props,
},
}

Definition at line 636 of file vf_scale_cuda.c.

◆ ff_vf_scale_cuda

const AVFilter ff_vf_scale_cuda
Initial value:
= {
.name = "scale_cuda",
.description = NULL_IF_CONFIG_SMALL("GPU accelerated video resizer"),
.init = cudascale_init,
.uninit = cudascale_uninit,
.priv_size = sizeof(CUDAScaleContext),
.priv_class = &cudascale_class,
.flags_internal = FF_FILTER_FLAG_HWFRAME_AWARE,
}

Definition at line 644 of file vf_scale_cuda.c.

options
static const AVOption options[]
Definition: vf_scale_cuda.c:601
AV_PIX_FMT_CUDA
@ AV_PIX_FMT_CUDA
HW acceleration through CUDA.
Definition: pixfmt.h:260
cudascale_init
static av_cold int cudascale_init(AVFilterContext *ctx)
Definition: vf_scale_cuda.c:113
AV_PIX_FMT_BGR32
#define AV_PIX_FMT_BGR32
Definition: pixfmt.h:477
cudascale_uninit
static av_cold void cudascale_uninit(AVFilterContext *ctx)
Definition: vf_scale_cuda.c:128
INTERP_ALGO_DEFAULT
@ INTERP_ALGO_DEFAULT
Definition: vf_scale_cuda.c:62
FILTER_INPUTS
#define FILTER_INPUTS(array)
Definition: filters.h:262
INTERP_ALGO_BILINEAR
@ INTERP_ALGO_BILINEAR
Definition: vf_scale_cuda.c:65
FLAGS
#define FLAGS
Definition: vf_scale_cuda.c:600
INTERP_ALGO_NEAREST
@ INTERP_ALGO_NEAREST
Definition: vf_scale_cuda.c:64
cudascale_class
static const AVClass cudascale_class
Definition: vf_scale_cuda.c:620
cudascale_config_props
static av_cold int cudascale_config_props(AVFilterLink *outlink)
Definition: vf_scale_cuda.c:349
AV_PIX_FMT_YUV444P16
#define AV_PIX_FMT_YUV444P16
Definition: pixfmt.h:515
format
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 format(the sample packing is implied by the sample format) and sample rate. The lists are not just lists
AV_PIX_FMT_0BGR32
#define AV_PIX_FMT_0BGR32
Definition: pixfmt.h:480
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:73
FILTER_OUTPUTS
#define FILTER_OUTPUTS(array)
Definition: filters.h:263
LIBAVUTIL_VERSION_INT
#define LIBAVUTIL_VERSION_INT
Definition: version.h:85
OFFSET
#define OFFSET(x)
Definition: vf_scale_cuda.c:599
NULL
#define NULL
Definition: coverity.c:32
av_default_item_name
const char * av_default_item_name(void *ptr)
Return the context name.
Definition: log.c:237
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: filters.h:206
cudascale_inputs
static const AVFilterPad cudascale_inputs[]
Definition: vf_scale_cuda.c:627
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:94
AV_PIX_FMT_RGB32
#define AV_PIX_FMT_RGB32
Definition: pixfmt.h:475
CUDAScaleContext
Definition: vf_scale_cuda.c:72
AV_OPT_TYPE_FLOAT
@ AV_OPT_TYPE_FLOAT
Underlying C type is float.
Definition: opt.h:271
AV_PIX_FMT_P016
#define AV_PIX_FMT_P016
Definition: pixfmt.h:554
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:96
AV_PIX_FMT_0RGB32
#define AV_PIX_FMT_0RGB32
Definition: pixfmt.h:479
cudascale_get_video_buffer
static AVFrame * cudascale_get_video_buffer(AVFilterLink *inlink, int w, int h)
Definition: vf_scale_cuda.c:590
AV_PIX_FMT_NONE
@ AV_PIX_FMT_NONE
Definition: pixfmt.h:72
AV_OPT_TYPE_INT
@ AV_OPT_TYPE_INT
Underlying C type is int.
Definition: opt.h:259
AV_OPT_TYPE_PIXEL_FMT
@ AV_OPT_TYPE_PIXEL_FMT
Underlying C type is enum AVPixelFormat.
Definition: opt.h:307
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:78
AV_PIX_FMT_P010
#define AV_PIX_FMT_P010
Definition: pixfmt.h:552
cudascale_outputs
static const AVFilterPad cudascale_outputs[]
Definition: vf_scale_cuda.c:636
AVMEDIA_TYPE_VIDEO
@ AVMEDIA_TYPE_VIDEO
Definition: avutil.h:201
INTERP_ALGO_COUNT
@ INTERP_ALGO_COUNT
Definition: vf_scale_cuda.c:69
cudascale_filter_frame
static int cudascale_filter_frame(AVFilterLink *link, AVFrame *in)
Definition: vf_scale_cuda.c:547
AV_OPT_TYPE_BOOL
@ AV_OPT_TYPE_BOOL
Underlying C type is int.
Definition: opt.h:327
SCALE_CUDA_PARAM_DEFAULT
#define SCALE_CUDA_PARAM_DEFAULT
Definition: vf_scale_cuda.h:26
INTERP_ALGO_LANCZOS
@ INTERP_ALGO_LANCZOS
Definition: vf_scale_cuda.c:67
AV_OPT_TYPE_STRING
@ AV_OPT_TYPE_STRING
Underlying C type is a uint8_t* that is either NULL or points to a C string allocated with the av_mal...
Definition: opt.h:276
AV_OPT_TYPE_CONST
@ AV_OPT_TYPE_CONST
Special option type for declaring named constants.
Definition: opt.h:299
FILTER_SINGLE_PIXFMT
#define FILTER_SINGLE_PIXFMT(pix_fmt_)
Definition: filters.h:252
INTERP_ALGO_BICUBIC
@ INTERP_ALGO_BICUBIC
Definition: vf_scale_cuda.c:66