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)
232 if (!
ctx->inputs[0]->hw_frames_ctx) {
253 if (
s->passthrough && in_width == out_width && in_height == out_height && in_format == out_format) {
264 if (in_width == out_width && in_height == out_height &&
270 if (!
ctx->outputs[0]->hw_frames_ctx)
279 CUcontext
dummy, cuda_ctx =
s->hwctx->cuda_ctx;
280 CudaFunctions *cu =
s->hwctx->internal->cuda_dl;
287 const char *function_infix =
"";
289 extern const unsigned char ff_vf_scale_cuda_ptx_data[];
290 extern const unsigned int ff_vf_scale_cuda_ptx_len;
292 switch(
s->interp_algo) {
294 function_infix =
"Nearest";
295 s->interp_use_linear = 0;
296 s->interp_as_integer = 1;
299 function_infix =
"Bilinear";
300 s->interp_use_linear = 1;
301 s->interp_as_integer = 1;
305 function_infix =
"Bicubic";
306 s->interp_use_linear = 0;
307 s->interp_as_integer = 0;
310 function_infix =
"Lanczos";
311 s->interp_use_linear = 0;
312 s->interp_as_integer = 0;
324 ff_vf_scale_cuda_ptx_data, ff_vf_scale_cuda_ptx_len);
328 snprintf(buf,
sizeof(buf),
"Subsample_%s_%s_%s", function_infix, in_fmt_name, out_fmt_name);
329 ret =
CHECK_CU(cu->cuModuleGetFunction(&
s->cu_func,
s->cu_module, buf));
336 snprintf(buf,
sizeof(buf),
"Subsample_%s_%s_%s_uv", function_infix, in_fmt_name, out_fmt_name);
337 ret =
CHECK_CU(cu->cuModuleGetFunction(&
s->cu_func_uv,
s->cu_module, buf));
357 s->hwctx = device_hwctx;
358 s->cu_stream =
s->hwctx->stream;
361 s->w_expr,
s->h_expr,
367 s->force_original_aspect_ratio,
s->force_divisible_by);
380 if (
inlink->sample_aspect_ratio.num) {
383 inlink->sample_aspect_ratio);
391 s->passthrough ?
" (passthrough)" :
"");
404 CUtexObject src_tex[4],
int src_width,
int src_height,
405 AVFrame *out_frame,
int dst_width,
int dst_height,
int dst_pitch)
408 CudaFunctions *cu =
s->hwctx->internal->cuda_dl;
410 CUdeviceptr dst_devptr[4] = {
411 (CUdeviceptr)out_frame->
data[0], (CUdeviceptr)out_frame->
data[1],
412 (CUdeviceptr)out_frame->
data[2], (CUdeviceptr)out_frame->
data[3]
415 void *args_uchar[] = {
416 &src_tex[0], &src_tex[1], &src_tex[2], &src_tex[3],
417 &dst_devptr[0], &dst_devptr[1], &dst_devptr[2], &dst_devptr[3],
418 &dst_width, &dst_height, &dst_pitch,
419 &src_width, &src_height, &
s->param
431 CudaFunctions *cu =
s->hwctx->internal->cuda_dl;
432 CUcontext
dummy, cuda_ctx =
s->hwctx->cuda_ctx;
435 CUtexObject tex[4] = { 0, 0, 0, 0 };
441 for (
i = 0;
i <
s->in_planes;
i++) {
442 CUDA_TEXTURE_DESC tex_desc = {
443 .filterMode =
s->interp_use_linear ?
444 CU_TR_FILTER_MODE_LINEAR :
445 CU_TR_FILTER_MODE_POINT,
446 .flags =
s->interp_as_integer ? CU_TRSF_READ_AS_INTEGER : 0,
449 CUDA_RESOURCE_DESC res_desc = {
450 .resType = CU_RESOURCE_TYPE_PITCH2D,
451 .res.pitch2D.format =
s->in_plane_depths[
i] <= 8 ?
452 CU_AD_FORMAT_UNSIGNED_INT8 :
453 CU_AD_FORMAT_UNSIGNED_INT16,
454 .res.pitch2D.numChannels =
s->in_plane_channels[
i],
455 .res.pitch2D.pitchInBytes = in->
linesize[
i],
456 .res.pitch2D.devPtr = (CUdeviceptr)in->
data[
i],
459 if (
i == 1 ||
i == 2) {
463 res_desc.res.pitch2D.width = in->
width;
464 res_desc.res.pitch2D.height = in->
height;
479 if (
s->out_planes > 1) {
493 for (
i = 0;
i <
s->in_planes;
i++)
495 CHECK_CU(cu->cuTexObjectDestroy(tex[
i]));
521 s->frame->width = outlink->
w;
522 s->frame->height = outlink->
h;
536 CudaFunctions *cu =
s->hwctx->internal->cuda_dl;
551 ret =
CHECK_CU(cu->cuCtxPushCurrent(
s->hwctx->cuda_ctx));
561 av_reduce(&
out->sample_aspect_ratio.num, &
out->sample_aspect_ratio.den,
578 return s->passthrough ?
583 #define OFFSET(x) offsetof(CUDAScaleContext, x)
584 #define FLAGS (AV_OPT_FLAG_FILTERING_PARAM|AV_OPT_FLAG_VIDEO_PARAM)
594 {
"passthrough",
"Do not process frames at all if parameters match",
OFFSET(passthrough),
AV_OPT_TYPE_BOOL, { .i64 = 1 }, 0, 1,
FLAGS },
596 {
"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" },
600 {
"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 .
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 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.
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)
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_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.