Go to the documentation of this file.
55 #define DIV_UP(a, b) ( ((a) + (b) - 1) / (b) )
59 #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)
256 if (
s->passthrough && in_width == out_width && in_height == out_height && in_format == out_format) {
267 if (in_width == out_width && in_height == out_height &&
282 CUcontext
dummy, cuda_ctx =
s->hwctx->cuda_ctx;
283 CudaFunctions *cu =
s->hwctx->internal->cuda_dl;
290 const char *function_infix =
"";
292 extern const unsigned char ff_vf_scale_cuda_ptx_data[];
293 extern const unsigned int ff_vf_scale_cuda_ptx_len;
295 switch(
s->interp_algo) {
297 function_infix =
"Nearest";
298 s->interp_use_linear = 0;
299 s->interp_as_integer = 1;
302 function_infix =
"Bilinear";
303 s->interp_use_linear = 1;
304 s->interp_as_integer = 1;
308 function_infix =
"Bicubic";
309 s->interp_use_linear = 0;
310 s->interp_as_integer = 0;
313 function_infix =
"Lanczos";
314 s->interp_use_linear = 0;
315 s->interp_as_integer = 0;
327 ff_vf_scale_cuda_ptx_data, ff_vf_scale_cuda_ptx_len);
331 snprintf(buf,
sizeof(buf),
"Subsample_%s_%s_%s", function_infix, in_fmt_name, out_fmt_name);
332 ret =
CHECK_CU(cu->cuModuleGetFunction(&
s->cu_func,
s->cu_module, buf));
339 snprintf(buf,
sizeof(buf),
"Subsample_%s_%s_%s_uv", function_infix, in_fmt_name, out_fmt_name);
340 ret =
CHECK_CU(cu->cuModuleGetFunction(&
s->cu_func_uv,
s->cu_module, buf));
363 s->w_expr,
s->h_expr,
369 w_adj =
inlink->sample_aspect_ratio.num ?
373 s->force_original_aspect_ratio,
s->force_divisible_by, w_adj);
389 s->hwctx = device_hwctx;
390 s->cu_stream =
s->hwctx->stream;
394 else if (
inlink->sample_aspect_ratio.num) {
397 inlink->sample_aspect_ratio);
405 s->passthrough ?
" (passthrough)" :
"");
418 CUtexObject src_tex[4],
int src_left,
int src_top,
int src_width,
int src_height,
419 AVFrame *out_frame,
int dst_width,
int dst_height,
int dst_pitch)
422 CudaFunctions *cu =
s->hwctx->internal->cuda_dl;
424 CUdeviceptr dst_devptr[4] = {
425 (CUdeviceptr)out_frame->
data[0], (CUdeviceptr)out_frame->
data[1],
426 (CUdeviceptr)out_frame->
data[2], (CUdeviceptr)out_frame->
data[3]
429 void *args_uchar[] = {
430 &src_tex[0], &src_tex[1], &src_tex[2], &src_tex[3],
431 &dst_devptr[0], &dst_devptr[1], &dst_devptr[2], &dst_devptr[3],
432 &dst_width, &dst_height, &dst_pitch,
433 &src_left, &src_top, &src_width, &src_height, &
s->param
445 CudaFunctions *cu =
s->hwctx->internal->cuda_dl;
446 CUcontext
dummy, cuda_ctx =
s->hwctx->cuda_ctx;
449 CUtexObject tex[4] = { 0, 0, 0, 0 };
458 for (
i = 0;
i <
s->in_planes;
i++) {
459 CUDA_TEXTURE_DESC tex_desc = {
460 .filterMode =
s->interp_use_linear ?
461 CU_TR_FILTER_MODE_LINEAR :
462 CU_TR_FILTER_MODE_POINT,
463 .flags =
s->interp_as_integer ? CU_TRSF_READ_AS_INTEGER : 0,
466 CUDA_RESOURCE_DESC res_desc = {
467 .resType = CU_RESOURCE_TYPE_PITCH2D,
468 .res.pitch2D.format =
s->in_plane_depths[
i] <= 8 ?
469 CU_AD_FORMAT_UNSIGNED_INT8 :
470 CU_AD_FORMAT_UNSIGNED_INT16,
471 .res.pitch2D.numChannels =
s->in_plane_channels[
i],
472 .res.pitch2D.pitchInBytes = in->
linesize[
i],
473 .res.pitch2D.devPtr = (CUdeviceptr)in->
data[
i],
476 if (
i == 1 ||
i == 2) {
480 res_desc.res.pitch2D.width = in->
width;
481 res_desc.res.pitch2D.height = in->
height;
496 if (
s->out_planes > 1) {
512 for (
i = 0;
i <
s->in_planes;
i++)
514 CHECK_CU(cu->cuTexObjectDestroy(tex[
i]));
540 s->frame->width = outlink->
w;
541 s->frame->height = outlink->
h;
560 CudaFunctions *cu =
s->hwctx->internal->cuda_dl;
575 ret =
CHECK_CU(cu->cuCtxPushCurrent(
s->hwctx->cuda_ctx));
588 av_reduce(&
out->sample_aspect_ratio.num, &
out->sample_aspect_ratio.den,
606 return s->passthrough ?
611 #define OFFSET(x) offsetof(CUDAScaleContext, x)
612 #define FLAGS (AV_OPT_FLAG_FILTERING_PARAM|AV_OPT_FLAG_VIDEO_PARAM)
622 {
"passthrough",
"Do not process frames at all if parameters match",
OFFSET(passthrough),
AV_OPT_TYPE_BOOL, { .i64 = 1 }, 0, 1,
FLAGS },
624 {
"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" },
628 {
"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 },
629 {
"reset_sar",
"reset SAR to 1 and scale to square pixels if scaling proportionally",
OFFSET(reset_sar),
AV_OPT_TYPE_BOOL, { .i64 = 0}, 0, 1,
FLAGS },
658 .
p.
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)
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 necessary.
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.
#define FILTER_INPUTS(array)
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)
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)
#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.
Link properties exposed to filter code, but not external callers.
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)
@ AV_SIDE_DATA_PROP_SIZE_DEPENDENT
Side data depends on the video dimensions.
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)
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
#define AV_PIX_FMT_0BGR32
AVRational sample_aspect_ratio
agreed upon sample aspect ratio
const FFFilter ff_vf_scale_cuda
@ AV_PIX_FMT_YUV420P
planar YUV 4:2:0, 12bpp, (1 Cr & Cb sample per 2x2 Y samples)
#define FILTER_OUTPUTS(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 FilterLink * ff_filter_link(AVFilterLink *link)
#define FF_FILTER_FLAG_HWFRAME_AWARE
The filter is aware of hardware frames, and any hardware frame context should not be automatically pr...
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
void av_frame_side_data_remove_by_props(AVFrameSideData ***sd, int *nb_sd, int props)
Remove and free all side data instances that match any of the given side data properties.
AVBufferRef * hw_frames_ctx
For hwaccel pixel formats, this should be a reference to the AVHWFramesContext describing the frames.
AVFrame * ff_null_get_video_buffer(AVFilterLink *link, int w, int h)
@ AV_OPT_TYPE_FLOAT
Underlying C type is float.
static enum AVPixelFormat supported_formats[]
#define i(width, name, range_min, range_max)
int w
agreed upon image width
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.
static AVFrame * cudascale_get_video_buffer(AVFilterLink *inlink, int w, int h)
int h
agreed upon image height
@ AV_OPT_TYPE_INT
Underlying C type is int.
@ AV_OPT_TYPE_PIXEL_FMT
Underlying C type is enum AVPixelFormat.
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[]
AVFilter p
The public AVFilter.
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.
@ AV_OPT_TYPE_BOOL
Underlying C type is int.
#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...
@ 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...
int av_hwframe_get_buffer(AVBufferRef *hwframe_ref, AVFrame *frame, int flags)
Allocate a new frame attached to the given AVHWFramesContext.
@ AV_OPT_TYPE_CONST
Special option type for declaring named constants.
#define FILTER_SINGLE_PIXFMT(pix_fmt_)
int ff_scale_adjust_dimensions(AVFilterLink *inlink, int *ret_w, int *ret_h, int force_original_aspect_ratio, int force_divisible_by, double w_adj)
Transform evaluated width and height obtained from ff_scale_eval_dimensions into actual target width ...
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.