44#define DIV_UP(a, b) ( ((a) + (b) - 1) / (b) )
48#define CHECK_CU(x) FF_CUDA_CHECK_DL(ctx, s->hwctx->internal->cuda_dl, x)
74 if (
s->hwctx &&
s->cu_module) {
75 CudaFunctions *cu =
s->hwctx->internal->cuda_dl;
78 CHECK_CU(cu->cuCtxPushCurrent(
s->hwctx->cuda_ctx));
79 CHECK_CU(cu->cuModuleUnload(
s->cu_module));
81 CHECK_CU(cu->cuCtxPopCurrent(&bilateral));
107 for (
i = 0;
i <
s->in_desc->nb_components;
i++) {
108 d = (
s->in_desc->comp[
i].depth + 7) / 8;
109 p =
s->in_desc->comp[
i].plane;
110 s->in_plane_channels[p] =
FFMAX(
s->in_plane_channels[p],
s->in_desc->comp[
i].step / d);
144 CUcontext bilateral, cuda_ctx =
s->hwctx->cuda_ctx;
145 CudaFunctions *cu =
s->hwctx->internal->cuda_dl;
148 extern const unsigned char ff_vf_bilateral_cuda_ptx_data[];
149 extern const unsigned int ff_vf_bilateral_cuda_ptx_len;
151 ret =
CHECK_CU(cu->cuCtxPushCurrent(cuda_ctx));
156 ff_vf_bilateral_cuda_ptx_data, ff_vf_bilateral_cuda_ptx_len);
160 ret =
CHECK_CU(cu->cuModuleGetFunction(&
s->cu_func,
s->cu_module,
"Process_uchar"));
166 ret =
CHECK_CU(cu->cuModuleGetFunction(&
s->cu_func_uv,
s->cu_module,
"Process_uchar2"));
173 CHECK_CU(cu->cuCtxPopCurrent(&bilateral));
195 s->hwctx = device_hwctx;
196 s->cu_stream =
s->hwctx->stream;
211 CUtexObject src_tex[3],
AVFrame *out_frame,
213 int width_uv,
int height_uv,
int pitch_uv,
214 int window_size,
float sigmaS,
float sigmaR)
217 CudaFunctions *cu =
s->hwctx->internal->cuda_dl;
220 CUdeviceptr dst_devptr[3] = {
221 (CUdeviceptr)out_frame->
data[0], (CUdeviceptr)out_frame->
data[1], (CUdeviceptr)out_frame->
data[2]
224 void *args_uchar[] = {
225 &src_tex[0], &src_tex[1], &src_tex[2],
226 &dst_devptr[0], &dst_devptr[1], &dst_devptr[2],
228 &width_uv, &height_uv, &pitch_uv,
229 &window_size, &sigmaS, &sigmaR
245 CudaFunctions *cu =
s->hwctx->internal->cuda_dl;
246 CUcontext bilateral, cuda_ctx =
s->hwctx->cuda_ctx;
249 CUtexObject tex[3] = { 0, 0, 0 };
251 ret =
CHECK_CU(cu->cuCtxPushCurrent(cuda_ctx));
255 for (
i = 0;
i <
s->in_planes;
i++) {
256 CUDA_TEXTURE_DESC tex_desc = {
257 .filterMode = CU_TR_FILTER_MODE_LINEAR,
261 CUDA_RESOURCE_DESC res_desc = {
262 .resType = CU_RESOURCE_TYPE_PITCH2D,
263 .res.pitch2D.format = CU_AD_FORMAT_UNSIGNED_INT8,
264 .res.pitch2D.numChannels =
s->in_plane_channels[
i],
265 .res.pitch2D.pitchInBytes = in->
linesize[
i],
266 .res.pitch2D.devPtr = (CUdeviceptr)in->
data[
i],
269 if (
i == 1 ||
i == 2) {
273 res_desc.res.pitch2D.width = in->
width;
274 res_desc.res.pitch2D.height = in->
height;
277 ret =
CHECK_CU(cu->cuTexObjectCreate(&tex[
i], &res_desc, &tex_desc,
NULL));
284 out->width,
out->height,
out->linesize[0],
287 out->linesize[1] >> ((
s->in_plane_channels[1] > 1) ? 1 : 0),
288 s->window_size,
s->sigmaS,
s->sigmaR);
291 for (
i = 0;
i <
s->in_planes;
i++)
293 CHECK_CU(cu->cuTexObjectDestroy(tex[
i]));
295 CHECK_CU(cu->cuCtxPopCurrent(&bilateral));
305 CudaFunctions *cu =
s->hwctx->internal->cuda_dl;
317 ret =
CHECK_CU(cu->cuCtxPushCurrent(
s->hwctx->cuda_ctx));
329 ret =
CHECK_CU(cu->cuCtxPopCurrent(&bilateral));
341#define OFFSET(x) offsetof(CUDABilateralContext, x)
342#define FLAGS (AV_OPT_FLAG_FILTERING_PARAM|AV_OPT_FLAG_VIDEO_PARAM)
351 .class_name =
"cudabilateral",
374 .p.name =
"bilateral_cuda",
static const char *const format[]
const FFFilter ff_vf_bilateral_cuda
int ff_filter_frame(AVFilterLink *link, AVFrame *frame)
Send a frame of data to the next filter.
Main libavfilter public API header.
#define i(width, name, range_min, range_max)
common internal and external API header
#define AV_CEIL_RSHIFT(a, b)
@ AV_OPT_TYPE_INT
Underlying C type is int.
@ AV_OPT_TYPE_FLOAT
Underlying C type is float.
AVBufferRef * av_buffer_ref(const AVBufferRef *buf)
Create a new reference to an AVBuffer.
void av_frame_free(AVFrame **frame)
Free the frame and any dynamically allocated objects in it, e.g.
int av_frame_copy_props(AVFrame *dst, const AVFrame *src)
Copy only "metadata" fields from src to dst.
#define AV_LOG_FATAL
Something went wrong and recovery is not possible.
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
const char * av_default_item_name(void *ptr)
Return the context name.
#define LIBAVUTIL_VERSION_INT
FFmpeg internal API for CUDA.
int(* func)(AVBPrint *dst, const char *in, const char *arg)
#define FILTER_INPUTS(array)
#define FILTER_OUTPUTS(array)
#define FF_FILTER_FLAG_HWFRAME_AWARE
The filter is aware of hardware frames, and any hardware frame context should not be automatically pr...
static FilterLink * ff_filter_link(AVFilterLink *link)
#define FILTER_SINGLE_PIXFMT(pix_fmt_)
common internal API header
#define NULL_IF_CONFIG_SMALL(x)
Return NULL if CONFIG_SMALL is true, otherwise the argument without modification.
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.
int av_pix_fmt_count_planes(enum AVPixelFormat pix_fmt)
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.
const AVPixFmtDescriptor * av_pix_fmt_desc_get(enum AVPixelFormat pix_fmt)
AVPixelFormat
Pixel format.
@ 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...
@ AV_PIX_FMT_YUV420P
planar YUV 4:2:0, 12bpp, (1 Cr & Cb sample per 2x2 Y samples)
@ AV_PIX_FMT_CUDA
HW acceleration through CUDA.
@ AV_PIX_FMT_YUV444P
planar YUV 4:4:4, 24bpp, (1 Cr & Cb sample per 1x1 Y samples)
#define FF_ARRAY_ELEMS(a)
uint8_t * data
The data buffer.
This struct is allocated as AVHWDeviceContext.hwctx.
Describe the class of an AVClass context structure.
AVFilterLink ** inputs
array of pointers to input links
A link between two filters.
int w
agreed upon image width
int h
agreed upon image height
AVFilterContext * src
source filter
AVRational sample_aspect_ratio
agreed upon sample aspect ratio
AVFilterContext * dst
dest filter
A filter pad used for either input or output.
This structure describes decoded (raw) audio or video data.
uint8_t * data[AV_NUM_DATA_POINTERS]
pointer to the picture/channel planes.
int linesize[AV_NUM_DATA_POINTERS]
For video, a positive or negative value, which is typically indicating the size in bytes of each pict...
void * hwctx
The format-specific data, allocated and freed by libavutil along with this context.
This struct describes a set or pool of "hardware" frames (i.e.
enum AVPixelFormat sw_format
The pixel format identifying the actual data layout of the hardware frames.
AVHWDeviceContext * device_ctx
The parent AVHWDeviceContext.
Descriptor that unambiguously describes how the bits of a pixel are stored in the up to 4 data planes...
AVCUDADeviceContext * hwctx
const AVPixFmtDescriptor * in_desc
Link properties exposed to filter code, but not external callers.
AVBufferRef * hw_frames_ctx
For hwaccel pixel formats, this should be a reference to the AVHWFramesContext describing the frames.
static AVFormatContext * ctx
static enum AVPixelFormat supported_formats[]
static av_cold int cuda_bilateral_load_functions(AVFilterContext *ctx)
static int call_cuda_kernel(AVFilterContext *ctx, CUfunction func, CUtexObject src_tex[3], AVFrame *out_frame, int width, int height, int pitch, int width_uv, int height_uv, int pitch_uv, int window_size, float sigmaS, float sigmaR)
static const AVFilterPad cuda_bilateral_outputs[]
static const AVClass cuda_bilateral_class
static int cuda_bilateral_filter_frame(AVFilterLink *link, AVFrame *in)
static av_cold void cudabilateral_uninit(AVFilterContext *ctx)
static const AVFilterPad cuda_bilateral_inputs[]
static av_cold void set_format_info(AVFilterContext *ctx, enum AVPixelFormat format)
static int format_is_supported(enum AVPixelFormat fmt)
static av_cold int cuda_bilateral_config_props(AVFilterLink *outlink)
static int cuda_bilateral_process_internal(AVFilterContext *ctx, AVFrame *out, AVFrame *in)
static av_cold int init_processing_chain(AVFilterContext *ctx, int width, int height)
AVFrame * ff_get_video_buffer(AVFilterLink *link, int w, int h)
Request a picture buffer with a specific set of permissions.