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)
132 if (
s->hwctx &&
s->cu_module) {
133 CudaFunctions *cu =
s->hwctx->internal->cuda_dl;
136 CHECK_CU(cu->cuCtxPushCurrent(
s->hwctx->cuda_ctx));
137 CHECK_CU(cu->cuModuleUnload(
s->cu_module));
176 s->frames_ctx = out_ref;
199 s->in_fmt = in_format;
200 s->out_fmt = out_format;
211 for (
i = 0;
i <
s->in_desc->nb_components;
i++) {
212 d = (
s->in_desc->comp[
i].depth + 7) / 8;
213 p =
s->in_desc->comp[
i].plane;
214 s->in_plane_channels[p] =
FFMAX(
s->in_plane_channels[p],
s->in_desc->comp[
i].step / d);
216 s->in_plane_depths[p] =
s->in_desc->comp[
i].depth;
221 int out_width,
int out_height)
255 if (
s->passthrough && in_width == out_width && in_height == out_height && in_format == out_format) {
266 if (in_width == out_width && in_height == out_height &&
281 CUcontext
dummy, cuda_ctx =
s->hwctx->cuda_ctx;
282 CudaFunctions *cu =
s->hwctx->internal->cuda_dl;
289 const char *function_infix =
"";
291 extern const unsigned char ff_vf_scale_cuda_ptx_data[];
292 extern const unsigned int ff_vf_scale_cuda_ptx_len;
294 switch(
s->interp_algo) {
296 function_infix =
"Nearest";
297 s->interp_use_linear = 0;
298 s->interp_as_integer = 1;
301 function_infix =
"Bilinear";
302 s->interp_use_linear = 1;
303 s->interp_as_integer = 1;
307 function_infix =
"Bicubic";
308 s->interp_use_linear = 0;
309 s->interp_as_integer = 0;
312 function_infix =
"Lanczos";
313 s->interp_use_linear = 0;
314 s->interp_as_integer = 0;
326 ff_vf_scale_cuda_ptx_data, ff_vf_scale_cuda_ptx_len);
330 snprintf(buf,
sizeof(buf),
"Subsample_%s_%s_%s", function_infix, in_fmt_name, out_fmt_name);
331 ret =
CHECK_CU(cu->cuModuleGetFunction(&
s->cu_func,
s->cu_module, buf));
338 snprintf(buf,
sizeof(buf),
"Subsample_%s_%s_%s_uv", function_infix, in_fmt_name, out_fmt_name);
339 ret =
CHECK_CU(cu->cuModuleGetFunction(&
s->cu_func_uv,
s->cu_module, buf));
361 s->w_expr,
s->h_expr,
367 s->force_original_aspect_ratio,
s->force_divisible_by);
383 s->hwctx = device_hwctx;
384 s->cu_stream =
s->hwctx->stream;
386 if (
inlink->sample_aspect_ratio.num) {
389 inlink->sample_aspect_ratio);
397 s->passthrough ?
" (passthrough)" :
"");
410 CUtexObject src_tex[4],
int src_left,
int src_top,
int src_width,
int src_height,
411 AVFrame *out_frame,
int dst_width,
int dst_height,
int dst_pitch)
414 CudaFunctions *cu =
s->hwctx->internal->cuda_dl;
416 CUdeviceptr dst_devptr[4] = {
417 (CUdeviceptr)out_frame->
data[0], (CUdeviceptr)out_frame->
data[1],
418 (CUdeviceptr)out_frame->
data[2], (CUdeviceptr)out_frame->
data[3]
421 void *args_uchar[] = {
422 &src_tex[0], &src_tex[1], &src_tex[2], &src_tex[3],
423 &dst_devptr[0], &dst_devptr[1], &dst_devptr[2], &dst_devptr[3],
424 &dst_width, &dst_height, &dst_pitch,
425 &src_left, &src_top, &src_width, &src_height, &
s->param
437 CudaFunctions *cu =
s->hwctx->internal->cuda_dl;
438 CUcontext
dummy, cuda_ctx =
s->hwctx->cuda_ctx;
441 CUtexObject tex[4] = { 0, 0, 0, 0 };
450 for (
i = 0;
i <
s->in_planes;
i++) {
451 CUDA_TEXTURE_DESC tex_desc = {
452 .filterMode =
s->interp_use_linear ?
453 CU_TR_FILTER_MODE_LINEAR :
454 CU_TR_FILTER_MODE_POINT,
455 .flags =
s->interp_as_integer ? CU_TRSF_READ_AS_INTEGER : 0,
458 CUDA_RESOURCE_DESC res_desc = {
459 .resType = CU_RESOURCE_TYPE_PITCH2D,
460 .res.pitch2D.format =
s->in_plane_depths[
i] <= 8 ?
461 CU_AD_FORMAT_UNSIGNED_INT8 :
462 CU_AD_FORMAT_UNSIGNED_INT16,
463 .res.pitch2D.numChannels =
s->in_plane_channels[
i],
464 .res.pitch2D.pitchInBytes = in->
linesize[
i],
465 .res.pitch2D.devPtr = (CUdeviceptr)in->
data[
i],
468 if (
i == 1 ||
i == 2) {
472 res_desc.res.pitch2D.width = in->
width;
473 res_desc.res.pitch2D.height = in->
height;
488 if (
s->out_planes > 1) {
504 for (
i = 0;
i <
s->in_planes;
i++)
506 CHECK_CU(cu->cuTexObjectDestroy(tex[
i]));
532 s->frame->width = outlink->
w;
533 s->frame->height = outlink->
h;
547 CudaFunctions *cu =
s->hwctx->internal->cuda_dl;
562 ret =
CHECK_CU(cu->cuCtxPushCurrent(
s->hwctx->cuda_ctx));
572 av_reduce(&
out->sample_aspect_ratio.num, &
out->sample_aspect_ratio.den,
589 return s->passthrough ?
594 #define OFFSET(x) offsetof(CUDAScaleContext, x)
595 #define FLAGS (AV_OPT_FLAG_FILTERING_PARAM|AV_OPT_FLAG_VIDEO_PARAM)
605 {
"passthrough",
"Do not process frames at all if parameters match",
OFFSET(passthrough),
AV_OPT_TYPE_BOOL, { .i64 = 1 }, 0, 1,
FLAGS },
607 {
"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" },
611 {
"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 },
640 .
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)
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
@ 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
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.
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
@ 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[]
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_)
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.