FFmpeg
vf_bilateral_cuda.c
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2022 Mohamed Khaled <Mohamed_Khaled_Kamal@outlook.com>
3  *
4  * This file is part of FFmpeg.
5  *
6  * FFmpeg is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU Lesser General Public
8  * License as published by the Free Software Foundation; either
9  * version 2.1 of the License, or (at your option) any later version.
10  *
11  * FFmpeg is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14  * Lesser General Public License for more details.
15  *
16  * You should have received a copy of the GNU Lesser General Public
17  * License along with FFmpeg; if not, write to the Free Software
18  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
19  */
20 
21 #include <float.h>
22 #include <stdio.h>
23 
24 #include "libavutil/common.h"
25 #include "libavutil/hwcontext.h"
27 #include "libavutil/cuda_check.h"
28 #include "libavutil/internal.h"
29 #include "libavutil/opt.h"
30 #include "libavutil/pixdesc.h"
31 
32 #include "avfilter.h"
33 #include "filters.h"
34 
35 #include "cuda/load_helper.h"
36 
37 static const enum AVPixelFormat supported_formats[] = {
41 };
42 
43 #define DIV_UP(a, b) ( ((a) + (b) - 1) / (b) )
44 #define BLOCKX 32
45 #define BLOCKY 16
46 
47 #define CHECK_CU(x) FF_CUDA_CHECK_DL(ctx, s->hwctx->internal->cuda_dl, x)
48 
49 
50 typedef struct CUDABilateralContext {
51  const AVClass *class;
53 
54  enum AVPixelFormat in_fmt, out_fmt;
59 
61  float sigmaS;
62  float sigmaR;
63 
67 
68  CUcontext cu_ctx;
69  CUmodule cu_module;
70  CUfunction cu_func;
71  CUfunction cu_func_uv;
72  CUstream cu_stream;
74 
76 {
77  CUDABilateralContext *s = ctx->priv;
78 
79  s->frame = av_frame_alloc();
80  if (!s->frame)
81  return AVERROR(ENOMEM);
82 
83  s->tmp_frame = av_frame_alloc();
84  if (!s->tmp_frame)
85  return AVERROR(ENOMEM);
86 
87  return 0;
88 }
89 
91 {
92  CUDABilateralContext *s = ctx->priv;
93 
94  if (s->hwctx && s->cu_module) {
95  CudaFunctions *cu = s->hwctx->internal->cuda_dl;
96  CUcontext bilateral;
97 
98  CHECK_CU(cu->cuCtxPushCurrent(s->hwctx->cuda_ctx));
99  CHECK_CU(cu->cuModuleUnload(s->cu_module));
100  s->cu_module = NULL;
101  CHECK_CU(cu->cuCtxPopCurrent(&bilateral));
102  }
103 
104  av_frame_free(&s->frame);
105  av_buffer_unref(&s->frames_ctx);
106  av_frame_free(&s->tmp_frame);
107 }
108 
110 {
111  AVBufferRef *out_ref = NULL;
112  AVHWFramesContext *out_ctx;
113  int ret;
114 
115  out_ref = av_hwframe_ctx_alloc(device_ctx);
116  if (!out_ref)
117  return AVERROR(ENOMEM);
118  out_ctx = (AVHWFramesContext*)out_ref->data;
119 
120  out_ctx->format = AV_PIX_FMT_CUDA;
121  out_ctx->sw_format = s->out_fmt;
122  out_ctx->width = width;
123  out_ctx->height = height;
124 
125  ret = av_hwframe_ctx_init(out_ref);
126  if (ret < 0)
127  goto fail;
128 
129  av_frame_unref(s->frame);
130  ret = av_hwframe_get_buffer(out_ref, s->frame, 0);
131  if (ret < 0)
132  goto fail;
133 
134  av_buffer_unref(&s->frames_ctx);
135  s->frames_ctx = out_ref;
136 
137  return 0;
138 fail:
139  av_buffer_unref(&out_ref);
140  return ret;
141 }
142 
143 static int format_is_supported(enum AVPixelFormat fmt)
144 {
145  int i;
146 
147  for (i = 0; i < FF_ARRAY_ELEMS(supported_formats); i++)
148  if (supported_formats[i] == fmt)
149  return 1;
150  return 0;
151 }
152 
153 static av_cold void set_format_info(AVFilterContext *ctx, enum AVPixelFormat in_format, enum AVPixelFormat out_format)
154 {
155  CUDABilateralContext *s = ctx->priv;
156  int i, p, d;
157 
158  s->in_fmt = in_format;
159  s->out_fmt = out_format;
160 
161  s->in_desc = av_pix_fmt_desc_get(s->in_fmt);
162  s->out_desc = av_pix_fmt_desc_get(s->out_fmt);
163  s->in_planes = av_pix_fmt_count_planes(s->in_fmt);
164  s->out_planes = av_pix_fmt_count_planes(s->out_fmt);
165 
166  // find maximum step of each component of each plane
167  // For our subset of formats, this should accurately tell us how many channels CUDA needs
168  // i.e. 1 for Y plane, 2 for UV plane of NV12, 4 for single plane of RGB0 formats
169 
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);
174 
175  s->in_plane_depths[p] = s->in_desc->comp[i].depth;
176  }
177 }
178 
180 {
181  FilterLink *inl = ff_filter_link(ctx->inputs[0]);
182  FilterLink *outl = ff_filter_link(ctx->outputs[0]);
183  CUDABilateralContext *s = ctx->priv;
184  AVHWFramesContext *in_frames_ctx;
185  int ret;
186 
187  /* check that we have a hw context */
188  if (!inl->hw_frames_ctx) {
189  av_log(ctx, AV_LOG_ERROR, "No hw context provided on input\n");
190  return AVERROR(EINVAL);
191  }
192  in_frames_ctx = (AVHWFramesContext*)inl->hw_frames_ctx->data;
193 
194  if (!format_is_supported(in_frames_ctx->sw_format)) {
195  av_log(ctx, AV_LOG_ERROR, "Unsupported format: %s\n", av_get_pix_fmt_name(in_frames_ctx->sw_format));
196  return AVERROR(ENOSYS);
197  }
198 
199  set_format_info(ctx, in_frames_ctx->sw_format, in_frames_ctx->sw_format);
200 
201  ret = init_hwframe_ctx(s, in_frames_ctx->device_ref, width, height);
202  if (ret < 0)
203  return ret;
204 
205  outl->hw_frames_ctx = av_buffer_ref(s->frames_ctx);
206  if (!outl->hw_frames_ctx)
207  return AVERROR(ENOMEM);
208 
209  return 0;
210 }
211 
213 {
214  CUDABilateralContext *s = ctx->priv;
215  CUcontext bilateral, cuda_ctx = s->hwctx->cuda_ctx;
216  CudaFunctions *cu = s->hwctx->internal->cuda_dl;
217  int ret;
218 
219  extern const unsigned char ff_vf_bilateral_cuda_ptx_data[];
220  extern const unsigned int ff_vf_bilateral_cuda_ptx_len;
221 
222  ret = CHECK_CU(cu->cuCtxPushCurrent(cuda_ctx));
223  if (ret < 0)
224  return ret;
225 
226  ret = ff_cuda_load_module(ctx, s->hwctx, &s->cu_module,
227  ff_vf_bilateral_cuda_ptx_data, ff_vf_bilateral_cuda_ptx_len);
228  if (ret < 0)
229  goto fail;
230 
231  ret = CHECK_CU(cu->cuModuleGetFunction(&s->cu_func, s->cu_module, "Process_uchar"));
232  if (ret < 0) {
233  av_log(ctx, AV_LOG_FATAL, "Failed loading Process_uchar\n");
234  goto fail;
235  }
236 
237  ret = CHECK_CU(cu->cuModuleGetFunction(&s->cu_func_uv, s->cu_module, "Process_uchar2"));
238  if (ret < 0) {
239  av_log(ctx, AV_LOG_FATAL, "Failed loading Process_uchar2\n");
240  goto fail;
241  }
242 
243 fail:
244  CHECK_CU(cu->cuCtxPopCurrent(&bilateral));
245 
246  return ret;
247 }
248 
250 {
251  AVFilterContext *ctx = outlink->src;
252  AVFilterLink *inlink = outlink->src->inputs[0];
254  CUDABilateralContext *s = ctx->priv;
255  AVHWFramesContext *frames_ctx;
256  AVCUDADeviceContext *device_hwctx;
257  int ret;
258 
260  if (ret < 0)
261  return ret;
262 
263  frames_ctx = (AVHWFramesContext*)inl->hw_frames_ctx->data;
264  device_hwctx = frames_ctx->device_ctx->hwctx;
265 
266  s->hwctx = device_hwctx;
267  s->cu_stream = s->hwctx->stream;
268 
269  outlink->sample_aspect_ratio = inlink->sample_aspect_ratio;
270 
271  // the window_size makes more sense when it is odd, so add 1 if even
272  s->window_size= (s->window_size%2) ? s->window_size : s->window_size+1;
273 
275  if (ret < 0)
276  return ret;
277 
278  return 0;
279 }
280 
281 static int call_cuda_kernel(AVFilterContext *ctx, CUfunction func,
282  CUtexObject src_tex[3], AVFrame *out_frame,
283  int width, int height, int pitch,
284  int width_uv, int height_uv, int pitch_uv,
285  int window_size, float sigmaS, float sigmaR)
286 {
287  CUDABilateralContext *s = ctx->priv;
288  CudaFunctions *cu = s->hwctx->internal->cuda_dl;
289  int ret;
290 
291  CUdeviceptr dst_devptr[3] = {
292  (CUdeviceptr)out_frame->data[0], (CUdeviceptr)out_frame->data[1], (CUdeviceptr)out_frame->data[2]
293  };
294 
295  void *args_uchar[] = {
296  &src_tex[0], &src_tex[1], &src_tex[2],
297  &dst_devptr[0], &dst_devptr[1], &dst_devptr[2],
298  &width, &height, &pitch,
299  &width_uv, &height_uv, &pitch_uv,
300  &window_size, &sigmaS, &sigmaR
301  };
302 
303  ret = CHECK_CU(cu->cuLaunchKernel(func,
305  BLOCKX, BLOCKY, 1, 0, s->cu_stream, args_uchar, NULL));
306  if (ret < 0)
307  return ret;
308 
309  return ret;
310 }
311 
313  AVFrame *out, AVFrame *in)
314 {
315  CUDABilateralContext *s = ctx->priv;
316  CudaFunctions *cu = s->hwctx->internal->cuda_dl;
317  CUcontext bilateral, cuda_ctx = s->hwctx->cuda_ctx;
318  int i, ret;
319 
320  CUtexObject tex[3] = { 0, 0, 0 };
321 
322  ret = CHECK_CU(cu->cuCtxPushCurrent(cuda_ctx));
323  if (ret < 0)
324  return ret;
325 
326  for (i = 0; i < s->in_planes; i++) {
327  CUDA_TEXTURE_DESC tex_desc = {
328  .filterMode = CU_TR_FILTER_MODE_LINEAR,
329  .flags = 0, // CU_TRSF_READ_AS_INTEGER to get raw ints instead of normalized floats from tex2D
330  };
331 
332  CUDA_RESOURCE_DESC res_desc = {
333  .resType = CU_RESOURCE_TYPE_PITCH2D,
334  .res.pitch2D.format = CU_AD_FORMAT_UNSIGNED_INT8,
335  .res.pitch2D.numChannels = s->in_plane_channels[i],
336  .res.pitch2D.pitchInBytes = in->linesize[i],
337  .res.pitch2D.devPtr = (CUdeviceptr)in->data[i],
338  };
339 
340  if (i == 1 || i == 2) {
341  res_desc.res.pitch2D.width = AV_CEIL_RSHIFT(in->width, s->in_desc->log2_chroma_w);
342  res_desc.res.pitch2D.height = AV_CEIL_RSHIFT(in->height, s->in_desc->log2_chroma_h);
343  } else {
344  res_desc.res.pitch2D.width = in->width;
345  res_desc.res.pitch2D.height = in->height;
346  }
347 
348  ret = CHECK_CU(cu->cuTexObjectCreate(&tex[i], &res_desc, &tex_desc, NULL));
349  if (ret < 0)
350  goto exit;
351  }
352 
353  ret = call_cuda_kernel(ctx, (s->in_plane_channels[1] > 1) ? s->cu_func_uv : s->cu_func,
354  tex, out,
355  out->width, out->height, out->linesize[0],
356  AV_CEIL_RSHIFT(out->width, s->out_desc->log2_chroma_w),
357  AV_CEIL_RSHIFT(out->height, s->out_desc->log2_chroma_h),
358  out->linesize[1] >> ((s->in_plane_channels[1] > 1) ? 1 : 0),
359  s->window_size, s->sigmaS, s->sigmaR);
360  if (ret < 0)
361  goto exit;
362 
363 exit:
364  for (i = 0; i < s->in_planes; i++)
365  if (tex[i])
366  CHECK_CU(cu->cuTexObjectDestroy(tex[i]));
367 
368  CHECK_CU(cu->cuCtxPopCurrent(&bilateral));
369 
370  return ret;
371 }
372 
374 {
375  CUDABilateralContext *s = ctx->priv;
376  AVFrame *src = in;
377  int ret;
378 
380  if (ret < 0)
381  return ret;
382 
383  src = s->frame;
384  ret = av_hwframe_get_buffer(src->hw_frames_ctx, s->tmp_frame, 0);
385  if (ret < 0)
386  return ret;
387 
388  av_frame_move_ref(out, s->frame);
389  av_frame_move_ref(s->frame, s->tmp_frame);
390 
391  ret = av_frame_copy_props(out, in);
392  if (ret < 0)
393  return ret;
394 
395  return 0;
396 }
397 
399 {
400  AVFilterContext *ctx = link->dst;
401  CUDABilateralContext *s = ctx->priv;
402  AVFilterLink *outlink = ctx->outputs[0];
403  CudaFunctions *cu = s->hwctx->internal->cuda_dl;
404 
405  AVFrame *out = NULL;
406  CUcontext bilateral;
407  int ret = 0;
408 
409  out = av_frame_alloc();
410  if (!out) {
411  ret = AVERROR(ENOMEM);
412  goto fail;
413  }
414 
415  ret = CHECK_CU(cu->cuCtxPushCurrent(s->hwctx->cuda_ctx));
416  if (ret < 0)
417  goto fail;
418 
420 
421  CHECK_CU(cu->cuCtxPopCurrent(&bilateral));
422  if (ret < 0)
423  goto fail;
424 
425  av_frame_free(&in);
426  return ff_filter_frame(outlink, out);
427 fail:
428  av_frame_free(&in);
429  av_frame_free(&out);
430  return ret;
431 }
432 
433 #define OFFSET(x) offsetof(CUDABilateralContext, x)
434 #define FLAGS (AV_OPT_FLAG_FILTERING_PARAM|AV_OPT_FLAG_VIDEO_PARAM)
435 static const AVOption options[] = {
436  { "sigmaS", "set spatial sigma", OFFSET(sigmaS), AV_OPT_TYPE_FLOAT, {.dbl=0.1}, 0.1, 512, FLAGS },
437  { "sigmaR", "set range sigma", OFFSET(sigmaR), AV_OPT_TYPE_FLOAT, {.dbl=0.1}, 0.1, 512, FLAGS },
438  { "window_size", "set neighbours window_size", OFFSET(window_size), AV_OPT_TYPE_INT, {.i64=1}, 1, 255, FLAGS },
439  { NULL }
440 };
441 
443  .class_name = "cudabilateral",
444  .item_name = av_default_item_name,
445  .option = options,
446  .version = LIBAVUTIL_VERSION_INT,
447 };
448 
450  {
451  .name = "default",
452  .type = AVMEDIA_TYPE_VIDEO,
453  .filter_frame = cuda_bilateral_filter_frame,
454  },
455 };
456 
458  {
459  .name = "default",
460  .type = AVMEDIA_TYPE_VIDEO,
461  .config_props = cuda_bilateral_config_props,
462  },
463 };
464 
466  .name = "bilateral_cuda",
467  .description = NULL_IF_CONFIG_SMALL("GPU accelerated bilateral filter"),
468 
469  .init = cudabilateral_init,
470  .uninit = cudabilateral_uninit,
471 
472  .priv_size = sizeof(CUDABilateralContext),
473  .priv_class = &cuda_bilateral_class,
474 
477 
479 
480  .flags_internal = FF_FILTER_FLAG_HWFRAME_AWARE,
481 };
cuda_bilateral_process
static int cuda_bilateral_process(AVFilterContext *ctx, AVFrame *out, AVFrame *in)
Definition: vf_bilateral_cuda.c:373
func
int(* func)(AVBPrint *dst, const char *in, const char *arg)
Definition: jacosubdec.c:68
AVHWDeviceContext::hwctx
void * hwctx
The format-specific data, allocated and freed by libavutil along with this context.
Definition: hwcontext.h:85
CUDABilateralContext::in_desc
const AVPixFmtDescriptor * in_desc
Definition: vf_bilateral_cuda.c:55
AV_PIX_FMT_CUDA
@ AV_PIX_FMT_CUDA
HW acceleration through CUDA.
Definition: pixfmt.h:260
AVPixelFormat
AVPixelFormat
Pixel format.
Definition: pixfmt.h:71
AVERROR
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
CUDABilateralContext::frames_ctx
AVBufferRef * frames_ctx
Definition: vf_bilateral_cuda.c:64
opt.h
hwcontext_cuda_internal.h
out
FILE * out
Definition: movenc.c:55
options
static const AVOption options[]
Definition: vf_bilateral_cuda.c:435
ff_filter_frame
int ff_filter_frame(AVFilterLink *link, AVFrame *frame)
Send a frame of data to the next filter.
Definition: avfilter.c:1061
CUDABilateralContext::hwctx
AVCUDADeviceContext * hwctx
Definition: vf_bilateral_cuda.c:52
av_pix_fmt_desc_get
const AVPixFmtDescriptor * av_pix_fmt_desc_get(enum AVPixelFormat pix_fmt)
Definition: pixdesc.c:3170
AVBufferRef::data
uint8_t * data
The data buffer.
Definition: buffer.h:90
AVHWFramesContext::format
enum AVPixelFormat format
The pixel format identifying the underlying HW surface type.
Definition: hwcontext.h:197
call_cuda_kernel
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)
Definition: vf_bilateral_cuda.c:281
ff_cuda_load_module
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.
Definition: load_helper.c:35
inlink
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
Definition: filter_design.txt:212
CUDABilateralContext::cu_stream
CUstream cu_stream
Definition: vf_bilateral_cuda.c:72
av_frame_free
void av_frame_free(AVFrame **frame)
Free the frame and any dynamically allocated objects in it, e.g.
Definition: frame.c:162
av_hwframe_ctx_init
int av_hwframe_ctx_init(AVBufferRef *ref)
Finalize the context before use.
Definition: hwcontext.c:322
FILTER_INPUTS
#define FILTER_INPUTS(array)
Definition: filters.h:262
AVFrame
This structure describes decoded (raw) audio or video data.
Definition: frame.h:389
pixdesc.h
AVFrame::width
int width
Definition: frame.h:461
av_hwframe_ctx_alloc
AVBufferRef * av_hwframe_ctx_alloc(AVBufferRef *device_ref_in)
Allocate an AVHWFramesContext tied to a given device context.
Definition: hwcontext.c:248
BLOCKY
#define BLOCKY
Definition: vf_bilateral_cuda.c:45
AVOption
AVOption.
Definition: opt.h:429
cuda_bilateral_filter_frame
static int cuda_bilateral_filter_frame(AVFilterLink *link, AVFrame *in)
Definition: vf_bilateral_cuda.c:398
float.h
init_processing_chain
static av_cold int init_processing_chain(AVFilterContext *ctx, int width, int height)
Definition: vf_bilateral_cuda.c:179
CUDABilateralContext::in_plane_depths
int in_plane_depths[4]
Definition: vf_bilateral_cuda.c:57
FFMAX
#define FFMAX(a, b)
Definition: macros.h:47
av_buffer_ref
AVBufferRef * av_buffer_ref(const AVBufferRef *buf)
Create a new reference to an AVBuffer.
Definition: buffer.c:103
AVFilter::name
const char * name
Filter name.
Definition: avfilter.h:205
CUDABilateralContext::out_planes
int out_planes
Definition: vf_bilateral_cuda.c:56
AVHWFramesContext::width
int width
The allocated dimensions of the frames in this pool.
Definition: hwcontext.h:217
DIV_UP
#define DIV_UP(a, b)
Definition: vf_bilateral_cuda.c:43
cuda_bilateral_load_functions
static av_cold int cuda_bilateral_load_functions(AVFilterContext *ctx)
Definition: vf_bilateral_cuda.c:212
AVFrame::data
uint8_t * data[AV_NUM_DATA_POINTERS]
pointer to the picture/channel planes.
Definition: frame.h:410
av_pix_fmt_count_planes
int av_pix_fmt_count_planes(enum AVPixelFormat pix_fmt)
Definition: pixdesc.c:3210
fail
#define fail()
Definition: checkasm.h:200
CUDABilateralContext::frame
AVFrame * frame
Definition: vf_bilateral_cuda.c:65
cuda_bilateral_inputs
static const AVFilterPad cuda_bilateral_inputs[]
Definition: vf_bilateral_cuda.c:449
CUDABilateralContext::tmp_frame
AVFrame * tmp_frame
Definition: vf_bilateral_cuda.c:66
AVFilterPad
A filter pad used for either input or output.
Definition: filters.h:38
av_frame_alloc
AVFrame * av_frame_alloc(void)
Allocate an AVFrame and set its fields to default values.
Definition: frame.c:150
CUDABilateralContext::out_fmt
enum AVPixelFormat in_fmt out_fmt
Definition: vf_bilateral_cuda.c:54
AV_LOG_ERROR
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
Definition: log.h:209
FF_ARRAY_ELEMS
#define FF_ARRAY_ELEMS(a)
Definition: sinewin_tablegen.c:29
av_cold
#define av_cold
Definition: attributes.h:90
CUDABilateralContext::cu_ctx
CUcontext cu_ctx
Definition: vf_bilateral_cuda.c:68
AVHWFramesContext::height
int height
Definition: hwcontext.h:217
CUDABilateralContext
Definition: vf_bilateral_cuda.c:50
s
#define s(width, name)
Definition: cbs_vp9.c:198
AV_CEIL_RSHIFT
#define AV_CEIL_RSHIFT(a, b)
Definition: common.h:60
filters.h
ctx
AVFormatContext * ctx
Definition: movenc.c:49
format_is_supported
static int format_is_supported(enum AVPixelFormat fmt)
Definition: vf_bilateral_cuda.c:143
load_helper.h
AV_PIX_FMT_YUV420P
@ AV_PIX_FMT_YUV420P
planar YUV 4:2:0, 12bpp, (1 Cr & Cb sample per 2x2 Y samples)
Definition: pixfmt.h:73
FILTER_OUTPUTS
#define FILTER_OUTPUTS(array)
Definition: filters.h:263
link
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
Definition: filter_design.txt:23
CUDABilateralContext::in_plane_channels
int in_plane_channels[4]
Definition: vf_bilateral_cuda.c:58
if
if(ret)
Definition: filter_design.txt:179
LIBAVUTIL_VERSION_INT
#define LIBAVUTIL_VERSION_INT
Definition: version.h:85
set_format_info
static av_cold void set_format_info(AVFilterContext *ctx, enum AVPixelFormat in_format, enum AVPixelFormat out_format)
Definition: vf_bilateral_cuda.c:153
AVClass
Describe the class of an AVClass context structure.
Definition: log.h:75
NULL
#define NULL
Definition: coverity.c:32
AVHWFramesContext::sw_format
enum AVPixelFormat sw_format
The pixel format identifying the actual data layout of the hardware frames.
Definition: hwcontext.h:210
av_frame_copy_props
int av_frame_copy_props(AVFrame *dst, const AVFrame *src)
Copy only "metadata" fields from src to dst.
Definition: frame.c:725
av_buffer_unref
void av_buffer_unref(AVBufferRef **buf)
Free a given reference and automatically free the buffer if there are no more references to it.
Definition: buffer.c:139
FLAGS
#define FLAGS
Definition: vf_bilateral_cuda.c:434
AVHWFramesContext::device_ref
AVBufferRef * device_ref
A reference to the parent AVHWDeviceContext.
Definition: hwcontext.h:126
AVFilterContext::inputs
AVFilterLink ** inputs
array of pointers to input links
Definition: avfilter.h:465
av_default_item_name
const char * av_default_item_name(void *ptr)
Return the context name.
Definition: log.c:237
ff_vf_bilateral_cuda
const AVFilter ff_vf_bilateral_cuda
Definition: vf_bilateral_cuda.c:465
options
Definition: swscale.c:42
CUDABilateralContext::cu_func_uv
CUfunction cu_func_uv
Definition: vf_bilateral_cuda.c:71
cuda_bilateral_process_internal
static int cuda_bilateral_process_internal(AVFilterContext *ctx, AVFrame *out, AVFrame *in)
Definition: vf_bilateral_cuda.c:312
CUDABilateralContext::window_size
int window_size
Definition: vf_bilateral_cuda.c:60
ff_filter_link
static FilterLink * ff_filter_link(AVFilterLink *link)
Definition: filters.h:197
FF_FILTER_FLAG_HWFRAME_AWARE
#define FF_FILTER_FLAG_HWFRAME_AWARE
The filter is aware of hardware frames, and any hardware frame context should not be automatically pr...
Definition: filters.h:206
cudabilateral_init
static av_cold int cudabilateral_init(AVFilterContext *ctx)
Definition: vf_bilateral_cuda.c:75
NULL_IF_CONFIG_SMALL
#define NULL_IF_CONFIG_SMALL(x)
Return NULL if CONFIG_SMALL is true, otherwise the argument without modification.
Definition: internal.h:94
CUDABilateralContext::cu_module
CUmodule cu_module
Definition: vf_bilateral_cuda.c:69
height
#define height
Definition: dsp.h:85
cuda_bilateral_outputs
static const AVFilterPad cuda_bilateral_outputs[]
Definition: vf_bilateral_cuda.c:457
cudabilateral_uninit
static av_cold void cudabilateral_uninit(AVFilterContext *ctx)
Definition: vf_bilateral_cuda.c:90
init_hwframe_ctx
static av_cold int init_hwframe_ctx(CUDABilateralContext *s, AVBufferRef *device_ctx, int width, int height)
Definition: vf_bilateral_cuda.c:109
supported_formats
static enum AVPixelFormat supported_formats[]
Definition: vf_bilateral_cuda.c:37
cuda_bilateral_config_props
static av_cold int cuda_bilateral_config_props(AVFilterLink *outlink)
Definition: vf_bilateral_cuda.c:249
AV_OPT_TYPE_FLOAT
@ AV_OPT_TYPE_FLOAT
Underlying C type is float.
Definition: opt.h:271
i
#define i(width, name, range_min, range_max)
Definition: cbs_h2645.c:256
CUDABilateralContext::sigmaS
float sigmaS
Definition: vf_bilateral_cuda.c:61
internal.h
common.h
av_frame_move_ref
void av_frame_move_ref(AVFrame *dst, AVFrame *src)
Move everything contained in src to dst and reset src.
Definition: frame.c:649
av_frame_unref
void av_frame_unref(AVFrame *frame)
Unreference all the buffers referenced by frame and reset the frame fields.
Definition: frame.c:622
CUDABilateralContext::sigmaR
float sigmaR
Definition: vf_bilateral_cuda.c:62
AVFilterPad::name
const char * name
Pad name.
Definition: filters.h:44
BLOCKX
#define BLOCKX
Definition: vf_bilateral_cuda.c:44
AVFilter
Filter definition.
Definition: avfilter.h:201
AVHWFramesContext
This struct describes a set or pool of "hardware" frames (i.e.
Definition: hwcontext.h:115
AVCUDADeviceContext
This struct is allocated as AVHWDeviceContext.hwctx.
Definition: hwcontext_cuda.h:42
ret
ret
Definition: filter_design.txt:187
AV_LOG_FATAL
#define AV_LOG_FATAL
Something went wrong and recovery is not possible.
Definition: log.h:203
AV_PIX_FMT_NV12
@ 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...
Definition: pixfmt.h:96
AVClass::class_name
const char * class_name
The name of the class; usually it is the same name as the context structure type to which the AVClass...
Definition: log.h:80
AVHWFramesContext::device_ctx
AVHWDeviceContext * device_ctx
The parent AVHWDeviceContext.
Definition: hwcontext.h:134
cuda_check.h
cuda_bilateral_class
static const AVClass cuda_bilateral_class
Definition: vf_bilateral_cuda.c:442
AVFrame::height
int height
Definition: frame.h:461
AV_OPT_TYPE_INT
@ AV_OPT_TYPE_INT
Underlying C type is int.
Definition: opt.h:259
avfilter.h
AV_PIX_FMT_YUV444P
@ AV_PIX_FMT_YUV444P
planar YUV 4:4:4, 24bpp, (1 Cr & Cb sample per 1x1 Y samples)
Definition: pixfmt.h:78
AVFilterContext
An instance of a filter.
Definition: avfilter.h:457
AVMEDIA_TYPE_VIDEO
@ AVMEDIA_TYPE_VIDEO
Definition: avutil.h:201
OFFSET
#define OFFSET(x)
Definition: vf_bilateral_cuda.c:433
AVBufferRef
A reference to a data buffer.
Definition: buffer.h:82
AVPixFmtDescriptor
Descriptor that unambiguously describes how the bits of a pixel are stored in the up to 4 data planes...
Definition: pixdesc.h:69
CUDABilateralContext::out_desc
const AVPixFmtDescriptor * out_desc
Definition: vf_bilateral_cuda.c:55
CUDABilateralContext::cu_func
CUfunction cu_func
Definition: vf_bilateral_cuda.c:70
hwcontext.h
AVFrame::linesize
int linesize[AV_NUM_DATA_POINTERS]
For video, a positive or negative value, which is typically indicating the size in bytes of each pict...
Definition: frame.h:434
av_log
#define av_log(a,...)
Definition: tableprint_vlc.h:27
width
#define width
Definition: dsp.h:85
CHECK_CU
#define CHECK_CU(x)
Definition: vf_bilateral_cuda.c:47
CUDABilateralContext::in_planes
int in_planes
Definition: vf_bilateral_cuda.c:56
av_hwframe_get_buffer
int av_hwframe_get_buffer(AVBufferRef *hwframe_ref, AVFrame *frame, int flags)
Allocate a new frame attached to the given AVHWFramesContext.
Definition: hwcontext.c:491
FILTER_SINGLE_PIXFMT
#define FILTER_SINGLE_PIXFMT(pix_fmt_)
Definition: filters.h:252
src
#define src
Definition: vp8dsp.c:248
av_get_pix_fmt_name
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.
Definition: pixdesc.c:3090