Go to the documentation of this file.
31 #define WEIGHT_LUT_NBITS 20
32 #define WEIGHT_LUT_SIZE (1<<WEIGHT_LUT_NBITS)
65 #define OFFSET(x) offsetof(AudioNLMeansContext, x)
66 #define AFT AV_OPT_FLAG_AUDIO_PARAM|AV_OPT_FLAG_FILTERING_PARAM|AV_OPT_FLAG_RUNTIME_PARAM
87 static inline float sqrdiff(
float x,
float y)
89 const float diff = x - y;
98 for (
int k = -
K; k <=
K; k++)
105 ptrdiff_t
S, ptrdiff_t
K,
106 ptrdiff_t
i, ptrdiff_t jj)
110 for (
int j = jj; j < jj +
S; j++, v++)
128 int newK, newS, newH, newN;
134 newN = newH + (newK + newS) * 2;
138 if (!
s->cache ||
s->cache->nb_samples < newS * 2) {
145 s->cache = new_cache;
153 if (!
s->window ||
s->window->nb_samples < newN) {
160 s->window = new_window;
170 float w = -
i /
s->pdiff_lut_scale;
206 const int om =
s->om;
207 const float *
f = (
const float *)(
s->window->extended_data[ch]) +
K;
208 float *cache = (
float *)
s->cache->extended_data[ch];
209 const float sw = (65536.f / (4 *
K + 2)) /
sqrtf(
s->a);
210 float *
dst = (
float *)
out->extended_data[ch];
211 const float *
const weight_lut =
s->weight_lut;
212 const float pdiff_lut_scale =
s->pdiff_lut_scale;
215 float *
src = (
float *)
s->window->extended_data[ch];
219 memcpy(&
src[
offset], in->extended_data[ch], in->nb_samples *
sizeof(
float));
220 memset(&
src[
offset + in->nb_samples], 0, (
H - in->nb_samples) *
sizeof(
float));
222 for (
int i =
S;
i <
H +
S;
i++) {
223 float P = 0.f,
Q = 0.f;
227 for (
int j =
i -
S; j <=
i +
S; j++) {
230 cache[v++] =
s->dsp.compute_distance_ssd(
f +
i,
f + j,
K);
233 s->dsp.compute_cache(cache,
f,
S,
K,
i,
i -
S);
234 s->dsp.compute_cache(cache +
S,
f,
S,
K,
i,
i + 1);
237 for (
int j = 0; j < 2 *
S && !
ctx->is_disabled; j++) {
239 unsigned weight_lut_idx;
247 weight_lut_idx =
w * pdiff_lut_scale;
249 w = weight_lut[weight_lut_idx];
250 P +=
w *
f[
i -
S + j + (j >=
S)];
325 char *res,
int res_len,
int flags)
354 .description =
NULL_IF_CONFIG_SMALL(
"Reduce broadband noise from stream using Non-Local Means."),
356 .priv_class = &anlmdn_class,
int av_samples_copy(uint8_t *const *dst, uint8_t *const *src, int dst_offset, int src_offset, int nb_samples, int nb_channels, enum AVSampleFormat sample_fmt)
Copy samples from src to dst.
AVFrame * ff_get_audio_buffer(AVFilterLink *link, int nb_samples)
Request an audio samples buffer with a specific set of permissions.
@ AV_SAMPLE_FMT_FLTP
float, planar
void ff_anlmdn_init(AudioNLMDNDSPContext *dsp)
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 int filter_frame(AVFilterLink *inlink, AVFrame *in)
float(* compute_distance_ssd)(const float *f1, const float *f2, ptrdiff_t K)
int ff_filter_frame(AVFilterLink *link, AVFrame *frame)
Send a frame of data to the next filter.
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.
#define FILTER_INPUTS(array)
This structure describes decoded (raw) audio or video data.
int64_t pts
Presentation timestamp in time_base units (time when frame should be shown to user).
@ AV_OPT_TYPE_DURATION
Underlying C type is int64_t.
static int config_output(AVFilterLink *outlink)
const char * name
Filter name.
int nb_channels
Number of channels in this layout.
A link between two filters.
#define FF_FILTER_FORWARD_STATUS_BACK(outlink, inlink)
Forward the status on an output link to an input link.
static const AVFilterPad outputs[]
static int config_filter(AVFilterContext *ctx)
AVChannelLayout ch_layout
Channel layout of the audio data.
A filter pad used for either input or output.
static const AVOption anlmdn_options[]
static void ff_outlink_set_status(AVFilterLink *link, int status, int64_t pts)
Set the status field of a link from the source filter.
void ff_inlink_request_frame(AVFilterLink *link)
Mark that a frame is wanted on the link.
float fminf(float, float)
#define AV_LOG_DEBUG
Stuff which is only useful for libav* developers.
#define FILTER_OUTPUTS(array)
Describe the class of an AVClass context structure.
int ff_inlink_consume_samples(AVFilterLink *link, unsigned min, unsigned max, AVFrame **rframe)
Take samples from the link's FIFO and update the link's stats.
static int filter_channel(AVFilterContext *ctx, void *arg, int ch, int nb_jobs)
AVFILTER_DEFINE_CLASS(anlmdn)
const AVFilterPad ff_audio_default_filterpad[1]
An AVFilterPad array whose only entry has name "default" and is of type AVMEDIA_TYPE_AUDIO.
static __device__ float sqrtf(float a)
static float sqrdiff(float x, float y)
int ff_inlink_acknowledge_status(AVFilterLink *link, int *rstatus, int64_t *rpts)
Test and acknowledge the change of status on the link.
void ff_anlmdn_init_x86(AudioNLMDNDSPContext *s)
#define FILTER_SINGLE_SAMPLEFMT(sample_fmt_)
#define NULL_IF_CONFIG_SMALL(x)
Return NULL if CONFIG_SMALL is true, otherwise the argument without modification.
uint8_t ptrdiff_t const uint8_t ptrdiff_t int intptr_t intptr_t int int16_t * dst
static av_cold void uninit(AVFilterContext *ctx)
static float compute_distance_ssd_c(const float *f1, const float *f2, ptrdiff_t K)
void(* compute_cache)(float *cache, const float *f, ptrdiff_t S, ptrdiff_t K, ptrdiff_t i, ptrdiff_t jj)
int av_frame_is_writable(AVFrame *frame)
Check if the frame data is writable.
int format
format of the frame, -1 if unknown or unset Values correspond to enum AVPixelFormat for video frames,...
AVFilterContext * src
source filter
int ff_filter_process_command(AVFilterContext *ctx, const char *cmd, const char *arg, char *res, int res_len, int flags)
Generic processing of user supplied commands that are set in the same way as the filter options.
static av_always_inline int diff(const struct color_info *a, const struct color_info *b, const int trans_thresh)
The reader does not expect b to be semantically here and if the code is changed by maybe adding a a division or other the signedness will almost certainly be mistaken To avoid this confusion a new type was SUINT is the C unsigned type but it holds a signed int to use the same example SUINT a
it s the only field you need to keep assuming you have a context There is some magic you don t need to care about around this just let it vf offset
static int process_command(AVFilterContext *ctx, const char *cmd, const char *args, char *res, int res_len, int flags)
@ AV_OPT_TYPE_FLOAT
Underlying C type is float.
float weight_lut[WEIGHT_LUT_SIZE]
int sample_rate
samples per second
#define av_assert2(cond)
assert() equivalent, that does lie in speed critical code.
int nb_samples
number of audio samples (per channel) described by this frame
#define i(width, name, range_min, range_max)
#define AV_TIME_BASE
Internal time base represented as integer.
uint8_t ** extended_data
pointers to the data planes/channels.
static int activate(AVFilterContext *ctx)
const char * name
Pad name.
int ff_inlink_queued_samples(AVFilterLink *link)
int64_t av_rescale(int64_t a, int64_t b, int64_t c)
Rescale a 64-bit integer with rounding to nearest.
const AVFilter ff_af_anlmdn
int ff_filter_execute(AVFilterContext *ctx, avfilter_action_func *func, void *arg, int *ret, int nb_jobs)
@ AV_OPT_TYPE_INT
Underlying C type is int.
static void compute_cache_c(float *cache, const float *f, ptrdiff_t S, ptrdiff_t K, ptrdiff_t i, ptrdiff_t jj)
#define AVFILTER_FLAG_SLICE_THREADS
The filter supports multithreading by splitting frames into multiple parts and processing them concur...
static float smooth(DeshakeOpenCLContext *deshake_ctx, float *gauss_kernel, int length, float max_val, AVFifo *values)
static float distance(float x, float y, int band)
#define AVFILTER_FLAG_SUPPORT_TIMELINE_INTERNAL
Same as AVFILTER_FLAG_SUPPORT_TIMELINE_GENERIC, except that the filter will have its filter_frame() c...
#define flags(name, subs,...)
the definition of that something depends on the semantic of the filter The callback must examine the status of the filter s links and proceed accordingly The status of output links is stored in the status_in and status_out fields and tested by the ff_outlink_frame_wanted() function. If this function returns true
@ AV_OPT_TYPE_CONST
Special option type for declaring named constants.
void ff_filter_set_ready(AVFilterContext *filter, unsigned priority)
Mark a filter ready and schedule it for activation.