Go to the documentation of this file.
43 #define DIV_UP(a, b) ( ((a) + (b) - 1) / (b) )
47 #define CHECK_CU(x) FF_CUDA_CHECK_DL(ctx, s->hwctx->internal->cuda_dl, x)
94 if (
s->hwctx &&
s->cu_module) {
95 CudaFunctions *cu =
s->hwctx->internal->cuda_dl;
98 CHECK_CU(cu->cuCtxPushCurrent(
s->hwctx->cuda_ctx));
99 CHECK_CU(cu->cuModuleUnload(
s->cu_module));
101 CHECK_CU(cu->cuCtxPopCurrent(&bilateral));
135 s->frames_ctx = out_ref;
158 s->in_fmt = in_format;
159 s->out_fmt = out_format;
170 for (
i = 0;
i <
s->in_desc->nb_components;
i++) {
171 d = (
s->in_desc->comp[
i].depth + 7) / 8;
172 p =
s->in_desc->comp[
i].plane;
173 s->in_plane_channels[p] =
FFMAX(
s->in_plane_channels[p],
s->in_desc->comp[
i].step /
d);
175 s->in_plane_depths[p] =
s->in_desc->comp[
i].depth;
186 if (!
ctx->inputs[0]->hw_frames_ctx) {
204 if (!
ctx->outputs[0]->hw_frames_ctx)
213 CUcontext bilateral, cuda_ctx =
s->hwctx->cuda_ctx;
214 CudaFunctions *cu =
s->hwctx->internal->cuda_dl;
217 extern const unsigned char ff_vf_bilateral_cuda_ptx_data[];
218 extern const unsigned int ff_vf_bilateral_cuda_ptx_len;
225 ff_vf_bilateral_cuda_ptx_data, ff_vf_bilateral_cuda_ptx_len);
229 ret =
CHECK_CU(cu->cuModuleGetFunction(&
s->cu_func,
s->cu_module,
"Process_uchar"));
235 ret =
CHECK_CU(cu->cuModuleGetFunction(&
s->cu_func_uv,
s->cu_module,
"Process_uchar2"));
242 CHECK_CU(cu->cuCtxPopCurrent(&bilateral));
256 s->hwctx = device_hwctx;
257 s->cu_stream =
s->hwctx->stream;
266 s->window_size= (
s->window_size%2) ?
s->window_size :
s->window_size+1;
276 CUtexObject src_tex[3],
AVFrame *out_frame,
278 int width_uv,
int height_uv,
int pitch_uv,
279 int window_size,
float sigmaS,
float sigmaR)
282 CudaFunctions *cu =
s->hwctx->internal->cuda_dl;
285 CUdeviceptr dst_devptr[3] = {
286 (CUdeviceptr)out_frame->
data[0], (CUdeviceptr)out_frame->
data[1], (CUdeviceptr)out_frame->
data[2]
289 void *args_uchar[] = {
290 &src_tex[0], &src_tex[1], &src_tex[2],
291 &dst_devptr[0], &dst_devptr[1], &dst_devptr[2],
293 &width_uv, &height_uv, &pitch_uv,
294 &window_size, &sigmaS, &sigmaR
310 CudaFunctions *cu =
s->hwctx->internal->cuda_dl;
311 CUcontext bilateral, cuda_ctx =
s->hwctx->cuda_ctx;
314 CUtexObject tex[3] = { 0, 0, 0 };
320 for (
i = 0;
i <
s->in_planes;
i++) {
321 CUDA_TEXTURE_DESC tex_desc = {
322 .filterMode = CU_TR_FILTER_MODE_LINEAR,
326 CUDA_RESOURCE_DESC res_desc = {
327 .resType = CU_RESOURCE_TYPE_PITCH2D,
328 .res.pitch2D.format = CU_AD_FORMAT_UNSIGNED_INT8,
329 .res.pitch2D.numChannels =
s->in_plane_channels[
i],
330 .res.pitch2D.pitchInBytes = in->
linesize[
i],
331 .res.pitch2D.devPtr = (CUdeviceptr)in->
data[
i],
334 if (
i == 1 ||
i == 2) {
338 res_desc.res.pitch2D.width = in->
width;
339 res_desc.res.pitch2D.height = in->
height;
349 out->width,
out->height,
out->linesize[0],
352 out->linesize[1] >> ((
s->in_plane_channels[1] > 1) ? 1 : 0),
353 s->window_size,
s->sigmaS,
s->sigmaR);
358 for (
i = 0;
i <
s->in_planes;
i++)
360 CHECK_CU(cu->cuTexObjectDestroy(tex[
i]));
362 CHECK_CU(cu->cuCtxPopCurrent(&bilateral));
397 CudaFunctions *cu =
s->hwctx->internal->cuda_dl;
409 ret =
CHECK_CU(cu->cuCtxPushCurrent(
s->hwctx->cuda_ctx));
415 CHECK_CU(cu->cuCtxPopCurrent(&bilateral));
427 #define OFFSET(x) offsetof(CUDABilateralContext, x)
428 #define FLAGS (AV_OPT_FLAG_FILTERING_PARAM|AV_OPT_FLAG_VIDEO_PARAM)
460 .
name =
"bilateral_cuda",
static int cuda_bilateral_process(AVFilterContext *ctx, AVFrame *out, AVFrame *in)
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.
const AVPixFmtDescriptor * in_desc
@ 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
#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 AVOption options[]
int ff_filter_frame(AVFilterLink *link, AVFrame *frame)
Send a frame of data to the next filter.
AVCUDADeviceContext * hwctx
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.
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)
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
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.
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 int cuda_bilateral_filter_frame(AVFilterLink *link, AVFrame *in)
static av_cold int init_processing_chain(AVFilterContext *ctx, int width, int 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.
static av_cold int cuda_bilateral_load_functions(AVFilterContext *ctx)
uint8_t * data[AV_NUM_DATA_POINTERS]
pointer to the picture/channel planes.
int av_pix_fmt_count_planes(enum AVPixelFormat pix_fmt)
static const AVFilterPad cuda_bilateral_inputs[]
A filter pad used for either input or output.
AVFrame * av_frame_alloc(void)
Allocate an AVFrame and set its fields to default values.
enum AVPixelFormat in_fmt out_fmt
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
#define FF_ARRAY_ELEMS(a)
#define AV_CEIL_RSHIFT(a, b)
AVRational sample_aspect_ratio
agreed upon sample aspect ratio
static int format_is_supported(enum AVPixelFormat fmt)
@ AV_PIX_FMT_YUV420P
planar YUV 4:2:0, 12bpp, (1 Cr & Cb sample per 2x2 Y samples)
#define FILTER_INPUTS(array)
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
static av_cold void set_format_info(AVFilterContext *ctx, enum AVPixelFormat in_format, enum AVPixelFormat out_format)
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.
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.
const AVFilter ff_vf_bilateral_cuda
static int cuda_bilateral_process_internal(AVFilterContext *ctx, AVFrame *out, AVFrame *in)
static av_cold int cudabilateral_init(AVFilterContext *ctx)
#define NULL_IF_CONFIG_SMALL(x)
Return NULL if CONFIG_SMALL is true, otherwise the argument without modification.
static const AVFilterPad cuda_bilateral_outputs[]
static av_cold void cudabilateral_uninit(AVFilterContext *ctx)
AVFilterContext * src
source filter
static av_cold int init_hwframe_ctx(CUDABilateralContext *s, AVBufferRef *device_ctx, int width, int height)
static enum AVPixelFormat supported_formats[]
static av_cold int cuda_bilateral_config_props(AVFilterLink *outlink)
#define FILTER_SINGLE_PIXFMT(pix_fmt_)
#define i(width, name, range_min, range_max)
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.
#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...
AVHWDeviceContext * device_ctx
The parent AVHWDeviceContext.
static const AVClass cuda_bilateral_class
@ AV_PIX_FMT_YUV444P
planar YUV 4:4:4, 24bpp, (1 Cr & Cb sample per 1x1 Y samples)
A reference to a data buffer.
Descriptor that unambiguously describes how the bits of a pixel are stored in the up to 4 data planes...
#define FILTER_OUTPUTS(array)
const AVPixFmtDescriptor * out_desc
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 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.