Go to the documentation of this file.
56 #define DIV_UP(a, b) ( ((a) + (b) - 1) / (b) )
60 #define CHECK_CU(x) FF_CUDA_CHECK_DL(ctx, s->hwctx->internal->cuda_dl, x)
133 if (
s->hwctx &&
s->cu_module) {
134 CudaFunctions *cu =
s->hwctx->internal->cuda_dl;
137 CHECK_CU(cu->cuCtxPushCurrent(
s->hwctx->cuda_ctx));
138 CHECK_CU(cu->cuModuleUnload(
s->cu_module));
177 s->frames_ctx = out_ref;
200 s->in_fmt = in_format;
201 s->out_fmt = out_format;
212 for (
i = 0;
i <
s->in_desc->nb_components;
i++) {
213 d = (
s->in_desc->comp[
i].depth + 7) / 8;
214 p =
s->in_desc->comp[
i].plane;
215 s->in_plane_channels[p] =
FFMAX(
s->in_plane_channels[p],
s->in_desc->comp[
i].step /
d);
217 s->in_plane_depths[p] =
s->in_desc->comp[
i].depth;
222 int out_width,
int out_height)
233 if (!
ctx->inputs[0]->hw_frames_ctx) {
254 if (
s->passthrough && in_width == out_width && in_height == out_height && in_format == out_format) {
265 if (in_width == out_width && in_height == out_height &&
271 if (!
ctx->outputs[0]->hw_frames_ctx)
280 CUcontext
dummy, cuda_ctx =
s->hwctx->cuda_ctx;
281 CudaFunctions *cu =
s->hwctx->internal->cuda_dl;
288 const char *function_infix =
"";
290 extern const unsigned char ff_vf_scale_cuda_ptx_data[];
291 extern const unsigned int ff_vf_scale_cuda_ptx_len;
293 switch(
s->interp_algo) {
295 function_infix =
"Nearest";
296 s->interp_use_linear = 0;
297 s->interp_as_integer = 1;
300 function_infix =
"Bilinear";
301 s->interp_use_linear = 1;
302 s->interp_as_integer = 1;
306 function_infix =
"Bicubic";
307 s->interp_use_linear = 0;
308 s->interp_as_integer = 0;
311 function_infix =
"Lanczos";
312 s->interp_use_linear = 0;
313 s->interp_as_integer = 0;
325 ff_vf_scale_cuda_ptx_data, ff_vf_scale_cuda_ptx_len);
329 snprintf(buf,
sizeof(buf),
"Subsample_%s_%s_%s", function_infix, in_fmt_name, out_fmt_name);
330 ret =
CHECK_CU(cu->cuModuleGetFunction(&
s->cu_func,
s->cu_module, buf));
337 snprintf(buf,
sizeof(buf),
"Subsample_%s_%s_%s_uv", function_infix, in_fmt_name, out_fmt_name);
338 ret =
CHECK_CU(cu->cuModuleGetFunction(&
s->cu_func_uv,
s->cu_module, buf));
358 s->hwctx = device_hwctx;
359 s->cu_stream =
s->hwctx->stream;
362 s->w_expr,
s->h_expr,
368 s->force_original_aspect_ratio,
s->force_divisible_by);
370 if (((int64_t)
h *
inlink->w) > INT_MAX ||
371 ((int64_t)
w *
inlink->h) > INT_MAX)
381 if (
inlink->sample_aspect_ratio.num) {
384 inlink->sample_aspect_ratio);
392 s->passthrough ?
" (passthrough)" :
"");
405 CUtexObject src_tex[4],
int src_width,
int src_height,
406 AVFrame *out_frame,
int dst_width,
int dst_height,
int dst_pitch)
409 CudaFunctions *cu =
s->hwctx->internal->cuda_dl;
411 CUdeviceptr dst_devptr[4] = {
412 (CUdeviceptr)out_frame->
data[0], (CUdeviceptr)out_frame->
data[1],
413 (CUdeviceptr)out_frame->
data[2], (CUdeviceptr)out_frame->
data[3]
416 void *args_uchar[] = {
417 &src_tex[0], &src_tex[1], &src_tex[2], &src_tex[3],
418 &dst_devptr[0], &dst_devptr[1], &dst_devptr[2], &dst_devptr[3],
419 &dst_width, &dst_height, &dst_pitch,
420 &src_width, &src_height, &
s->param
432 CudaFunctions *cu =
s->hwctx->internal->cuda_dl;
433 CUcontext
dummy, cuda_ctx =
s->hwctx->cuda_ctx;
436 CUtexObject tex[4] = { 0, 0, 0, 0 };
442 for (
i = 0;
i <
s->in_planes;
i++) {
443 CUDA_TEXTURE_DESC tex_desc = {
444 .filterMode =
s->interp_use_linear ?
445 CU_TR_FILTER_MODE_LINEAR :
446 CU_TR_FILTER_MODE_POINT,
447 .flags =
s->interp_as_integer ? CU_TRSF_READ_AS_INTEGER : 0,
450 CUDA_RESOURCE_DESC res_desc = {
451 .resType = CU_RESOURCE_TYPE_PITCH2D,
452 .res.pitch2D.format =
s->in_plane_depths[
i] <= 8 ?
453 CU_AD_FORMAT_UNSIGNED_INT8 :
454 CU_AD_FORMAT_UNSIGNED_INT16,
455 .res.pitch2D.numChannels =
s->in_plane_channels[
i],
456 .res.pitch2D.pitchInBytes = in->
linesize[
i],
457 .res.pitch2D.devPtr = (CUdeviceptr)in->
data[
i],
460 if (
i == 1 ||
i == 2) {
464 res_desc.res.pitch2D.width = in->
width;
465 res_desc.res.pitch2D.height = in->
height;
480 if (
s->out_planes > 1) {
494 for (
i = 0;
i <
s->in_planes;
i++)
496 CHECK_CU(cu->cuTexObjectDestroy(tex[
i]));
522 s->frame->width = outlink->
w;
523 s->frame->height = outlink->
h;
537 CudaFunctions *cu =
s->hwctx->internal->cuda_dl;
552 ret =
CHECK_CU(cu->cuCtxPushCurrent(
s->hwctx->cuda_ctx));
562 av_reduce(&
out->sample_aspect_ratio.num, &
out->sample_aspect_ratio.den,
579 return s->passthrough ?
584 #define OFFSET(x) offsetof(CUDAScaleContext, x)
585 #define FLAGS (AV_OPT_FLAG_FILTERING_PARAM|AV_OPT_FLAG_VIDEO_PARAM)
595 {
"passthrough",
"Do not process frames at all if parameters match",
OFFSET(passthrough),
AV_OPT_TYPE_BOOL, { .i64 = 1 }, 0, 1,
FLAGS },
597 {
"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,
"force_oar" },
601 {
"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 },
630 .
name =
"scale_cuda",
static const AVOption options[]
int(* func)(AVBPrint *dst, const char *in, const char *arg)
void * hwctx
The format-specific data, allocated and freed by libavutil along with this context.
@ AV_PIX_FMT_CUDA
HW acceleration through CUDA.
AVPixelFormat
Pixel 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 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
static av_cold int cudascale_init(AVFilterContext *ctx)
#define FF_FILTER_FLAG_HWFRAME_AWARE
The filter is aware of hardware frames, and any hardware frame context should not be automatically pr...
int ff_filter_frame(AVFilterLink *link, AVFrame *frame)
Send a frame of data to the next filter.
const AVPixFmtDescriptor * av_pix_fmt_desc_get(enum AVPixelFormat pix_fmt)
uint8_t * data
The data buffer.
enum AVPixelFormat format
The pixel format identifying the underlying HW surface type.
int ff_cuda_load_module(void *avctx, AVCUDADeviceContext *hwctx, CUmodule *cu_module, const unsigned char *data, const unsigned int length)
Loads a CUDA module and applies any decompression, if neccesary.
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
static av_cold void cudascale_uninit(AVFilterContext *ctx)
void av_frame_free(AVFrame **frame)
Free the frame and any dynamically allocated objects in it, e.g.
int av_hwframe_ctx_init(AVBufferRef *ref)
Finalize the context before use.
char * w_expr
width expression string
This structure describes decoded (raw) audio or video data.
AVBufferRef * av_hwframe_ctx_alloc(AVBufferRef *device_ref_in)
Allocate an AVHWFramesContext tied to a given device context.
static av_cold int init_hwframe_ctx(CUDAScaleContext *s, AVBufferRef *device_ctx, int width, int height)
#define AV_LOG_VERBOSE
Detailed information.
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)
Parse and evaluate string expressions for width and height.
AVBufferRef * av_buffer_ref(const AVBufferRef *buf)
Create a new reference to an AVBuffer.
const char * name
Filter name.
int width
The allocated dimensions of the frames in this pool.
A link between two filters.
uint8_t * data[AV_NUM_DATA_POINTERS]
pointer to the picture/channel planes.
AVFrame * ff_default_get_video_buffer(AVFilterLink *link, int w, int h)
int av_pix_fmt_count_planes(enum AVPixelFormat pix_fmt)
static int scalecuda_resize(AVFilterContext *ctx, AVFrame *out, AVFrame *in)
int av_reduce(int *dst_num, int *dst_den, int64_t num, int64_t den, int64_t max)
Reduce a fraction.
static av_cold int cudascale_load_functions(AVFilterContext *ctx)
A filter pad used for either input or output.
AVFrame * av_frame_alloc(void)
Allocate an AVFrame and set its fields to default values.
static const AVClass cudascale_class
static av_cold int cudascale_config_props(AVFilterLink *outlink)
AVCUDADeviceContext * hwctx
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
static av_cold void set_format_info(AVFilterContext *ctx, enum AVPixelFormat in_format, enum AVPixelFormat out_format)
#define FF_ARRAY_ELEMS(a)
#define AV_PIX_FMT_YUV444P16
#define AV_CEIL_RSHIFT(a, b)
#define AV_PIX_FMT_0BGR32
AVRational sample_aspect_ratio
agreed upon sample aspect ratio
@ AV_PIX_FMT_YUV420P
planar YUV 4:2:0, 12bpp, (1 Cr & Cb sample per 2x2 Y samples)
#define FILTER_INPUTS(array)
static int format_is_supported(enum AVPixelFormat fmt)
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
#define LIBAVUTIL_VERSION_INT
Describe the class of an AVClass context structure.
enum AVPixelFormat sw_format
The pixel format identifying the actual data layout of the hardware frames.
int av_frame_copy_props(AVFrame *dst, const AVFrame *src)
Copy only "metadata" fields from src to dst.
void av_buffer_unref(AVBufferRef **buf)
Free a given reference and automatically free the buffer if there are no more references to it.
const AVPixFmtDescriptor * out_desc
char * h_expr
height expression string
Rational number (pair of numerator and denominator).
AVBufferRef * device_ref
A reference to the parent AVHWDeviceContext.
AVFilterLink ** inputs
array of pointers to input links
const char * av_default_item_name(void *ptr)
Return the context name.
static const AVFilterPad cudascale_inputs[]
#define NULL_IF_CONFIG_SMALL(x)
Return NULL if CONFIG_SMALL is true, otherwise the argument without modification.
AVFilterContext * src
source filter
AVFrame * ff_null_get_video_buffer(AVFilterLink *link, int w, int h)
#define FILTER_SINGLE_PIXFMT(pix_fmt_)
static enum AVPixelFormat supported_formats[]
#define i(width, name, range_min, range_max)
int w
agreed upon image width
static int call_resize_kernel(AVFilterContext *ctx, CUfunction func, CUtexObject src_tex[4], int src_width, int src_height, AVFrame *out_frame, int dst_width, int dst_height, int dst_pitch)
void av_frame_move_ref(AVFrame *dst, AVFrame *src)
Move everything contained in src to dst and reset src.
void av_frame_unref(AVFrame *frame)
Unreference all the buffers referenced by frame and reset the frame fields.
const char * name
Pad name.
This struct describes a set or pool of "hardware" frames (i.e.
This struct is allocated as AVHWDeviceContext.hwctx.
enum AVPixelFormat in_fmt out_fmt
#define AV_LOG_FATAL
Something went wrong and recovery is not possible.
@ 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...
const char * class_name
The name of the class; usually it is the same name as the context structure type to which the AVClass...
#define AV_PIX_FMT_0RGB32
AVHWDeviceContext * device_ctx
The parent AVHWDeviceContext.
AVRational sample_aspect_ratio
Sample aspect ratio for the video frame, 0/1 if unknown/unspecified.
int ff_scale_adjust_dimensions(AVFilterLink *inlink, int *ret_w, int *ret_h, int force_original_aspect_ratio, int force_divisible_by)
Transform evaluated width and height obtained from ff_scale_eval_dimensions into actual target width ...
static AVFrame * cudascale_get_video_buffer(AVFilterLink *inlink, int w, int h)
int h
agreed upon image height
AVRational av_mul_q(AVRational b, AVRational c)
Multiply two rationals.
@ AV_PIX_FMT_YUV444P
planar YUV 4:4:4, 24bpp, (1 Cr & Cb sample per 1x1 Y samples)
static const AVFilterPad cudascale_outputs[]
A reference to a data buffer.
static int cudascale_scale(AVFilterContext *ctx, AVFrame *out, AVFrame *in)
static int cudascale_filter_frame(AVFilterLink *link, AVFrame *in)
Descriptor that unambiguously describes how the bits of a pixel are stored in the up to 4 data planes...
int force_original_aspect_ratio
enum AVPixelFormat format
Output sw format.
#define FILTER_OUTPUTS(array)
#define SCALE_CUDA_PARAM_DEFAULT
const AVPixFmtDescriptor * in_desc
static av_cold int init_processing_chain(AVFilterContext *ctx, int in_width, int in_height, int out_width, int out_height)
#define AVERROR_BUG
Internal bug, also see AVERROR_BUG2.
int linesize[AV_NUM_DATA_POINTERS]
For video, a positive or negative value, which is typically indicating the size in bytes of each pict...
int av_hwframe_get_buffer(AVBufferRef *hwframe_ref, AVFrame *frame, int flags)
Allocate a new frame attached to the given AVHWFramesContext.
const AVFilter ff_vf_scale_cuda
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.