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 "internal.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  CUDABilateralContext *s = ctx->priv;
182  AVHWFramesContext *in_frames_ctx;
183  int ret;
184 
185  /* check that we have a hw context */
186  if (!ctx->inputs[0]->hw_frames_ctx) {
187  av_log(ctx, AV_LOG_ERROR, "No hw context provided on input\n");
188  return AVERROR(EINVAL);
189  }
190  in_frames_ctx = (AVHWFramesContext*)ctx->inputs[0]->hw_frames_ctx->data;
191 
192  if (!format_is_supported(in_frames_ctx->sw_format)) {
193  av_log(ctx, AV_LOG_ERROR, "Unsupported format: %s\n", av_get_pix_fmt_name(in_frames_ctx->sw_format));
194  return AVERROR(ENOSYS);
195  }
196 
197  set_format_info(ctx, in_frames_ctx->sw_format, in_frames_ctx->sw_format);
198 
199  ret = init_hwframe_ctx(s, in_frames_ctx->device_ref, width, height);
200  if (ret < 0)
201  return ret;
202 
203  ctx->outputs[0]->hw_frames_ctx = av_buffer_ref(s->frames_ctx);
204  if (!ctx->outputs[0]->hw_frames_ctx)
205  return AVERROR(ENOMEM);
206 
207  return 0;
208 }
209 
211 {
212  CUDABilateralContext *s = ctx->priv;
213  CUcontext bilateral, cuda_ctx = s->hwctx->cuda_ctx;
214  CudaFunctions *cu = s->hwctx->internal->cuda_dl;
215  int ret;
216 
217  extern const unsigned char ff_vf_bilateral_cuda_ptx_data[];
218  extern const unsigned int ff_vf_bilateral_cuda_ptx_len;
219 
220  ret = CHECK_CU(cu->cuCtxPushCurrent(cuda_ctx));
221  if (ret < 0)
222  return ret;
223 
224  ret = ff_cuda_load_module(ctx, s->hwctx, &s->cu_module,
225  ff_vf_bilateral_cuda_ptx_data, ff_vf_bilateral_cuda_ptx_len);
226  if (ret < 0)
227  goto fail;
228 
229  ret = CHECK_CU(cu->cuModuleGetFunction(&s->cu_func, s->cu_module, "Process_uchar"));
230  if (ret < 0) {
231  av_log(ctx, AV_LOG_FATAL, "Failed loading Process_uchar\n");
232  goto fail;
233  }
234 
235  ret = CHECK_CU(cu->cuModuleGetFunction(&s->cu_func_uv, s->cu_module, "Process_uchar2"));
236  if (ret < 0) {
237  av_log(ctx, AV_LOG_FATAL, "Failed loading Process_uchar2\n");
238  goto fail;
239  }
240 
241 fail:
242  CHECK_CU(cu->cuCtxPopCurrent(&bilateral));
243 
244  return ret;
245 }
246 
248 {
249  AVFilterContext *ctx = outlink->src;
250  AVFilterLink *inlink = outlink->src->inputs[0];
251  CUDABilateralContext *s = ctx->priv;
252  AVHWFramesContext *frames_ctx = (AVHWFramesContext*)inlink->hw_frames_ctx->data;
253  AVCUDADeviceContext *device_hwctx = frames_ctx->device_ctx->hwctx;
254  int ret;
255 
256  s->hwctx = device_hwctx;
257  s->cu_stream = s->hwctx->stream;
258 
260  if (ret < 0)
261  return ret;
262 
263  outlink->sample_aspect_ratio = inlink->sample_aspect_ratio;
264 
265  // the window_size makes more sense when it is odd, so add 1 if even
266  s->window_size= (s->window_size%2) ? s->window_size : s->window_size+1;
267 
269  if (ret < 0)
270  return ret;
271 
272  return 0;
273 }
274 
275 static int call_cuda_kernel(AVFilterContext *ctx, CUfunction func,
276  CUtexObject src_tex[3], AVFrame *out_frame,
277  int width, int height, int pitch,
278  int width_uv, int height_uv, int pitch_uv,
279  int window_size, float sigmaS, float sigmaR)
280 {
281  CUDABilateralContext *s = ctx->priv;
282  CudaFunctions *cu = s->hwctx->internal->cuda_dl;
283  int ret;
284 
285  CUdeviceptr dst_devptr[3] = {
286  (CUdeviceptr)out_frame->data[0], (CUdeviceptr)out_frame->data[1], (CUdeviceptr)out_frame->data[2]
287  };
288 
289  void *args_uchar[] = {
290  &src_tex[0], &src_tex[1], &src_tex[2],
291  &dst_devptr[0], &dst_devptr[1], &dst_devptr[2],
292  &width, &height, &pitch,
293  &width_uv, &height_uv, &pitch_uv,
294  &window_size, &sigmaS, &sigmaR
295  };
296 
297  ret = CHECK_CU(cu->cuLaunchKernel(func,
299  BLOCKX, BLOCKY, 1, 0, s->cu_stream, args_uchar, NULL));
300  if (ret < 0)
301  return ret;
302 
303  return ret;
304 }
305 
307  AVFrame *out, AVFrame *in)
308 {
309  CUDABilateralContext *s = ctx->priv;
310  CudaFunctions *cu = s->hwctx->internal->cuda_dl;
311  CUcontext bilateral, cuda_ctx = s->hwctx->cuda_ctx;
312  int i, ret;
313 
314  CUtexObject tex[3] = { 0, 0, 0 };
315 
316  ret = CHECK_CU(cu->cuCtxPushCurrent(cuda_ctx));
317  if (ret < 0)
318  return ret;
319 
320  for (i = 0; i < s->in_planes; i++) {
321  CUDA_TEXTURE_DESC tex_desc = {
322  .filterMode = CU_TR_FILTER_MODE_LINEAR,
323  .flags = 0, // CU_TRSF_READ_AS_INTEGER to get raw ints instead of normalized floats from tex2D
324  };
325 
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],
332  };
333 
334  if (i == 1 || i == 2) {
335  res_desc.res.pitch2D.width = AV_CEIL_RSHIFT(in->width, s->in_desc->log2_chroma_w);
336  res_desc.res.pitch2D.height = AV_CEIL_RSHIFT(in->height, s->in_desc->log2_chroma_h);
337  } else {
338  res_desc.res.pitch2D.width = in->width;
339  res_desc.res.pitch2D.height = in->height;
340  }
341 
342  ret = CHECK_CU(cu->cuTexObjectCreate(&tex[i], &res_desc, &tex_desc, NULL));
343  if (ret < 0)
344  goto exit;
345  }
346 
347  ret = call_cuda_kernel(ctx, (s->in_plane_channels[1] > 1) ? s->cu_func_uv : s->cu_func,
348  tex, out,
349  out->width, out->height, out->linesize[0],
350  AV_CEIL_RSHIFT(out->width, s->out_desc->log2_chroma_w),
351  AV_CEIL_RSHIFT(out->height, s->out_desc->log2_chroma_h),
352  out->linesize[1] >> ((s->in_plane_channels[1] > 1) ? 1 : 0),
353  s->window_size, s->sigmaS, s->sigmaR);
354  if (ret < 0)
355  goto exit;
356 
357 exit:
358  for (i = 0; i < s->in_planes; i++)
359  if (tex[i])
360  CHECK_CU(cu->cuTexObjectDestroy(tex[i]));
361 
362  CHECK_CU(cu->cuCtxPopCurrent(&bilateral));
363 
364  return ret;
365 }
366 
368 {
369  CUDABilateralContext *s = ctx->priv;
370  AVFrame *src = in;
371  int ret;
372 
374  if (ret < 0)
375  return ret;
376 
377  src = s->frame;
378  ret = av_hwframe_get_buffer(src->hw_frames_ctx, s->tmp_frame, 0);
379  if (ret < 0)
380  return ret;
381 
382  av_frame_move_ref(out, s->frame);
383  av_frame_move_ref(s->frame, s->tmp_frame);
384 
385  ret = av_frame_copy_props(out, in);
386  if (ret < 0)
387  return ret;
388 
389  return 0;
390 }
391 
393 {
394  AVFilterContext *ctx = link->dst;
395  CUDABilateralContext *s = ctx->priv;
396  AVFilterLink *outlink = ctx->outputs[0];
397  CudaFunctions *cu = s->hwctx->internal->cuda_dl;
398 
399  AVFrame *out = NULL;
400  CUcontext bilateral;
401  int ret = 0;
402 
403  out = av_frame_alloc();
404  if (!out) {
405  ret = AVERROR(ENOMEM);
406  goto fail;
407  }
408 
409  ret = CHECK_CU(cu->cuCtxPushCurrent(s->hwctx->cuda_ctx));
410  if (ret < 0)
411  goto fail;
412 
414 
415  CHECK_CU(cu->cuCtxPopCurrent(&bilateral));
416  if (ret < 0)
417  goto fail;
418 
419  av_frame_free(&in);
420  return ff_filter_frame(outlink, out);
421 fail:
422  av_frame_free(&in);
423  av_frame_free(&out);
424  return ret;
425 }
426 
427 #define OFFSET(x) offsetof(CUDABilateralContext, x)
428 #define FLAGS (AV_OPT_FLAG_FILTERING_PARAM|AV_OPT_FLAG_VIDEO_PARAM)
429 static const AVOption options[] = {
430  { "sigmaS", "set spatial sigma", OFFSET(sigmaS), AV_OPT_TYPE_FLOAT, {.dbl=0.1}, 0.1, 512, FLAGS },
431  { "sigmaR", "set range sigma", OFFSET(sigmaR), AV_OPT_TYPE_FLOAT, {.dbl=0.1}, 0.1, 512, FLAGS },
432  { "window_size", "set neighbours window_size", OFFSET(window_size), AV_OPT_TYPE_INT, {.i64=1}, 1, 255, FLAGS },
433  { NULL }
434 };
435 
437  .class_name = "cudabilateral",
438  .item_name = av_default_item_name,
439  .option = options,
440  .version = LIBAVUTIL_VERSION_INT,
441 };
442 
444  {
445  .name = "default",
446  .type = AVMEDIA_TYPE_VIDEO,
447  .filter_frame = cuda_bilateral_filter_frame,
448  },
449 };
450 
452  {
453  .name = "default",
454  .type = AVMEDIA_TYPE_VIDEO,
455  .config_props = cuda_bilateral_config_props,
456  },
457 };
458 
460  .name = "bilateral_cuda",
461  .description = NULL_IF_CONFIG_SMALL("GPU accelerated bilateral filter"),
462 
463  .init = cudabilateral_init,
464  .uninit = cudabilateral_uninit,
465 
466  .priv_size = sizeof(CUDABilateralContext),
467  .priv_class = &cuda_bilateral_class,
468 
471 
473 
474  .flags_internal = FF_FILTER_FLAG_HWFRAME_AWARE,
475 };
cuda_bilateral_process
static int cuda_bilateral_process(AVFilterContext *ctx, AVFrame *out, AVFrame *in)
Definition: vf_bilateral_cuda.c:367
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:92
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:253
AVPixelFormat
AVPixelFormat
Pixel format.
Definition: pixfmt.h:64
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:54
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: internal.h:364
options
static const AVOption options[]
Definition: vf_bilateral_cuda.c:429
ff_filter_frame
int ff_filter_frame(AVFilterLink *link, AVFrame *frame)
Send a frame of data to the next filter.
Definition: avfilter.c:978
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:2964
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:209
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:275
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 neccesary.
Definition: load_helper.c:34
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:100
av_hwframe_ctx_init
int av_hwframe_ctx_init(AVBufferRef *ref)
Finalize the context before use.
Definition: hwcontext.c:334
AVFrame
This structure describes decoded (raw) audio or video data.
Definition: frame.h:340
pixdesc.h
AVFrame::width
int width
Definition: frame.h:412
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:251
cuda_bilateral_filter_frame
static int cuda_bilateral_filter_frame(AVFilterLink *link, AVFrame *in)
Definition: vf_bilateral_cuda.c:392
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:170
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:229
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:210
AVFrame::data
uint8_t * data[AV_NUM_DATA_POINTERS]
pointer to the picture/channel planes.
Definition: frame.h:361
av_pix_fmt_count_planes
int av_pix_fmt_count_planes(enum AVPixelFormat pix_fmt)
Definition: pixdesc.c:3004
fail
#define fail()
Definition: checkasm.h:138
CUDABilateralContext::frame
AVFrame * frame
Definition: vf_bilateral_cuda.c:65
cuda_bilateral_inputs
static const AVFilterPad cuda_bilateral_inputs[]
Definition: vf_bilateral_cuda.c:443
CUDABilateralContext::tmp_frame
AVFrame * tmp_frame
Definition: vf_bilateral_cuda.c:66
AVFilterPad
A filter pad used for either input or output.
Definition: internal.h:47
av_frame_alloc
AVFrame * av_frame_alloc(void)
Allocate an AVFrame and set its fields to default values.
Definition: frame.c:88
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:180
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:229
CUDABilateralContext
Definition: vf_bilateral_cuda.c:50
width
#define width
s
#define s(width, name)
Definition: cbs_vp9.c:198
AV_CEIL_RSHIFT
#define AV_CEIL_RSHIFT(a, b)
Definition: common.h:51
ctx
AVFormatContext * ctx
Definition: movenc.c:48
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:66
FILTER_INPUTS
#define FILTER_INPUTS(array)
Definition: internal.h:192
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:66
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:222
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:736
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:428
AVHWFramesContext::device_ref
AVBufferRef * device_ref
A reference to the parent AVHWDeviceContext.
Definition: hwcontext.h:141
AVFilterContext::inputs
AVFilterLink ** inputs
array of pointers to input links
Definition: avfilter.h:405
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:459
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:306
CUDABilateralContext::window_size
int window_size
Definition: vf_bilateral_cuda.c:60
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:106
CUDABilateralContext::cu_module
CUmodule cu_module
Definition: vf_bilateral_cuda.c:69
cuda_bilateral_outputs
static const AVFilterPad cuda_bilateral_outputs[]
Definition: vf_bilateral_cuda.c:451
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
height
#define height
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:247
internal.h
AV_OPT_TYPE_FLOAT
@ AV_OPT_TYPE_FLOAT
Definition: opt.h:228
FILTER_SINGLE_PIXFMT
#define FILTER_SINGLE_PIXFMT(pix_fmt_)
Definition: internal.h:182
i
#define i(width, name, range_min, range_max)
Definition: cbs_h2645.c:255
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: internal.h:53
BLOCKX
#define BLOCKX
Definition: vf_bilateral_cuda.c:44
AVFilter
Filter definition.
Definition: avfilter.h:166
AVHWFramesContext
This struct describes a set or pool of "hardware" frames (i.e.
Definition: hwcontext.h:124
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:174
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:89
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:71
AVHWFramesContext::device_ctx
AVHWDeviceContext * device_ctx
The parent AVHWDeviceContext.
Definition: hwcontext.h:149
cuda_check.h
cuda_bilateral_class
static const AVClass cuda_bilateral_class
Definition: vf_bilateral_cuda.c:436
AVFrame::height
int height
Definition: frame.h:412
AV_OPT_TYPE_INT
@ AV_OPT_TYPE_INT
Definition: opt.h:225
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:71
AVFilterContext
An instance of a filter.
Definition: avfilter.h:397
AVMEDIA_TYPE_VIDEO
@ AVMEDIA_TYPE_VIDEO
Definition: avutil.h:201
OFFSET
#define OFFSET(x)
Definition: vf_bilateral_cuda.c:427
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
FILTER_OUTPUTS
#define FILTER_OUTPUTS(array)
Definition: internal.h:193
src
INIT_CLIP pixel * src
Definition: h264pred_template.c:418
CUDABilateralContext::out_desc
const AVPixFmtDescriptor * out_desc
Definition: vf_bilateral_cuda.c:55
d
d
Definition: ffmpeg_filter.c:368
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:385
av_log
#define av_log(a,...)
Definition: tableprint_vlc.h:27
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:507
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:2884