34 #define MAX_THREADS 16 63 #define OFFSET(x) offsetof(ConvolveContext, x) 64 #define FLAGS AV_OPT_FLAG_FILTERING_PARAM|AV_OPT_FLAG_VIDEO_PARAM 69 {
"first",
"process only first impulse, ignore rest", 0,
AV_OPT_TYPE_CONST, {.i64=0}, 0, 0,
FLAGS,
"impulse" },
123 for (fft_bits = 1; 1 << fft_bits <
n; fft_bits++);
173 int start = (n * jobnr) / nb_jobs;
174 int end = (n * (jobnr+1)) / nb_jobs;
177 for (y = start; y <
end; y++) {
188 const int iw = (n -
w) / 2, ih = (n - h) / 2;
192 for (y = 0; y <
h; y++) {
195 for (x = 0; x <
w; x++) {
196 fft_hdata[(y + ih) * n + iw + x].
re = src[x] * scale;
197 fft_hdata[(y + ih) * n + iw + x].
im = 0;
200 for (x = 0; x < iw; x++) {
201 fft_hdata[(y + ih) * n + x].
re = fft_hdata[(y + ih) * n + iw].
re;
202 fft_hdata[(y + ih) * n + x].
im = 0;
205 for (x = n - iw; x <
n; x++) {
206 fft_hdata[(y + ih) * n + x].
re = fft_hdata[(y + ih) * n + n - iw - 1].
re;
207 fft_hdata[(y + ih) * n + x].
im = 0;
211 for (y = 0; y < ih; y++) {
212 for (x = 0; x <
n; x++) {
213 fft_hdata[y * n + x].
re = fft_hdata[ih * n + x].
re;
214 fft_hdata[y * n + x].
im = 0;
218 for (y = n - ih; y <
n; y++) {
219 for (x = 0; x <
n; x++) {
220 fft_hdata[y * n + x].
re = fft_hdata[(n - ih - 1) * n + x].
re;
221 fft_hdata[y * n + x].
im = 0;
225 for (y = 0; y <
h; y++) {
226 const uint16_t *
src = (
const uint16_t *)(in->
data[plane] + in->
linesize[plane] * y);
228 for (x = 0; x <
w; x++) {
229 fft_hdata[(y + ih) * n + iw + x].
re = src[x] * scale;
230 fft_hdata[(y + ih) * n + iw + x].
im = 0;
233 for (x = 0; x < iw; x++) {
234 fft_hdata[(y + ih) * n + x].
re = fft_hdata[(y + ih) * n + iw].
re;
235 fft_hdata[(y + ih) * n + x].
im = 0;
238 for (x = n - iw; x <
n; x++) {
239 fft_hdata[(y + ih) * n + x].
re = fft_hdata[(y + ih) * n + n - iw - 1].
re;
240 fft_hdata[(y + ih) * n + x].
im = 0;
244 for (y = 0; y < ih; y++) {
245 for (x = 0; x <
n; x++) {
246 fft_hdata[y * n + x].
re = fft_hdata[ih * n + x].
re;
247 fft_hdata[y * n + x].
im = 0;
251 for (y = n - ih; y <
n; y++) {
252 for (x = 0; x <
n; x++) {
253 fft_hdata[y * n + x].
re = fft_hdata[(n - ih - 1) * n + x].
re;
254 fft_hdata[y * n + x].
im = 0;
268 int start = (n * jobnr) / nb_jobs;
269 int end = (n * (jobnr+1)) / nb_jobs;
272 for (y = start; y <
end; y++) {
273 for (x = 0; x <
n; x++) {
274 vdata[y * n + x].
re = hdata[x * n + y].
re;
275 vdata[y * n + x].
im = hdata[x * n + y].
im;
293 int start = (n * jobnr) / nb_jobs;
294 int end = (n * (jobnr+1)) / nb_jobs;
297 for (y = start; y <
end; y++) {
301 for (x = 0; x <
n; x++) {
302 hdata[x * n + y].
re = vdata[y * n + x].
re;
303 hdata[x * n + y].
im = vdata[y * n + x].
im;
317 int start = (n * jobnr) / nb_jobs;
318 int end = (n * (jobnr+1)) / nb_jobs;
321 for (y = start; y <
end; y++) {
330 int w,
int h,
int n,
int plane,
float scale)
332 const int max = (1 << s->
depth) - 1;
333 const int hh = h / 2;
334 const int hw = w / 2;
338 for (y = 0; y < hh; y++) {
340 for (x = 0; x < hw; x++)
341 dst[x] = av_clip_uint8(input[y * n + x].
re * scale);
343 for (y = 0; y < hh; y++) {
345 for (x = 0; x < hw; x++)
346 dst[x] = av_clip_uint8(input[y * n + n - hw + x].
re * scale);
348 for (y = 0; y < hh; y++) {
350 for (x = 0; x < hw; x++)
351 dst[x] = av_clip_uint8(input[(n - hh + y) * n + x].
re * scale);
353 for (y = 0; y < hh; y++) {
355 for (x = 0; x < hw; x++)
356 dst[x] = av_clip_uint8(input[(n - hh + y) * n + n - hw + x].
re * scale);
359 for (y = 0; y < hh; y++) {
360 uint16_t *dst = (uint16_t *)(out->
data[plane] + (y + hh) * out->
linesize[
plane] + hw * 2);
361 for (x = 0; x < hw; x++)
362 dst[x] = av_clip(input[y * n + x].
re * scale, 0, max);
364 for (y = 0; y < hh; y++) {
365 uint16_t *dst = (uint16_t *)(out->
data[plane] + (y + hh) * out->
linesize[
plane]);
366 for (x = 0; x < hw; x++)
367 dst[x] = av_clip(input[y * n + n - hw + x].
re * scale, 0, max);
369 for (y = 0; y < hh; y++) {
370 uint16_t *dst = (uint16_t *)(out->
data[plane] + y * out->
linesize[plane] + hw * 2);
371 for (x = 0; x < hw; x++)
372 dst[x] = av_clip(input[(n - hh + y) * n + x].
re * scale, 0, max);
374 for (y = 0; y < hh; y++) {
375 uint16_t *dst = (uint16_t *)(out->
data[plane] + y * out->
linesize[plane]);
376 for (x = 0; x < hw; x++)
377 dst[x] = av_clip(input[(n - hh + y) * n + n - hw + x].
re * scale, 0, max);
390 int start = (n * jobnr) / nb_jobs;
391 int end = (n * (jobnr+1)) / nb_jobs;
394 for (y = start; y <
end; y++) {
397 for (x = 0; x <
n; x++) {
400 re = input[yn + x].
re;
401 im = input[yn + x].
im;
402 ire = filter[yn + x].
re +
noise;
403 iim = filter[yn + x].
im;
405 input[yn + x].
re = ire * re - iim *
im;
406 input[yn + x].
im = iim * re + ire *
im;
421 int start = (n * jobnr) / nb_jobs;
422 int end = (n * (jobnr+1)) / nb_jobs;
425 for (y = start; y <
end; y++) {
428 for (x = 0; x <
n; x++) {
431 re = input[yn + x].
re;
432 im = input[yn + x].
im;
433 ire = filter[yn + x].
re;
434 iim = filter[yn + x].
im;
435 div = ire * ire + iim * iim +
noise;
437 input[yn + x].
re = (ire * re + iim *
im) / div;
438 input[yn + x].
im = (ire * im - iim *
re) / div;
451 int ret, y, x,
plane;
459 for (plane = 0; plane < s->
nb_planes; plane++) {
468 if (!(s->
planes & (1 << plane))) {
483 for (y = 0; y <
h; y++) {
484 const uint8_t *
src = (
const uint8_t *)(impulsepic->data[plane] + y * impulsepic->linesize[plane]) ;
485 for (x = 0; x <
w; x++) {
490 for (y = 0; y <
h; y++) {
491 const uint16_t *
src = (
const uint16_t *)(impulsepic->data[plane] + y * impulsepic->linesize[plane]) ;
492 for (x = 0; x <
w; x++) {
497 total =
FFMAX(1, total);
538 outlink->
w = mainlink->
w;
539 outlink->
h = mainlink->
h;
551 if (!s->
fft[i][j] || !s->
ifft[i][j])
571 }
else if (!strcmp(ctx->
filter->
name,
"deconvolve")) {
585 for (i = 0; i < 4; i++) {
622 #if CONFIG_CONVOLVE_FILTER 629 .preinit = convolve_framesync_preinit,
635 .priv_class = &convolve_class,
636 .
inputs = convolve_inputs,
643 #if CONFIG_DECONVOLVE_FILTER 645 static const AVOption deconvolve_options[] = {
648 {
"first",
"process only first impulse, ignore rest", 0,
AV_OPT_TYPE_CONST, {.i64=0}, 0, 0,
FLAGS,
"impulse" },
657 .
name =
"deconvolve",
659 .preinit = deconvolve_framesync_preinit,
665 .priv_class = &deconvolve_class,
666 .
inputs = convolve_inputs,
#define FRAMESYNC_DEFINE_CLASS(name, context, field)
#define AV_PIX_FMT_YUVA422P16
static int fft_vertical(AVFilterContext *ctx, void *arg, int jobnr, int nb_jobs)
#define AV_PIX_FMT_YUVA422P9
const AVPixFmtDescriptor * av_pix_fmt_desc_get(enum AVPixelFormat pix_fmt)
This structure describes decoded (raw) audio or video data.
static const AVFilterPad convolve_outputs[]
#define AV_PIX_FMT_YUVA420P10
#define AV_PIX_FMT_YUV444P14
av_cold void av_fft_end(FFTContext *s)
static int complex_multiply(AVFilterContext *ctx, void *arg, int jobnr, int nb_jobs)
#define AV_PIX_FMT_GBRAP10
#define AV_PIX_FMT_YUVA422P10
planar YUV 4:4:4, 24bpp, (1 Cr & Cb sample per 1x1 Y samples)
static int fft_horizontal(AVFilterContext *ctx, void *arg, int jobnr, int nb_jobs)
Main libavfilter public API header.
int h
agreed upon image height
static int ifft_vertical(AVFilterContext *ctx, void *arg, int jobnr, int nb_jobs)
#define AV_PIX_FMT_GBRP10
int(* filter)(AVFilterContext *ctx, void *arg, int jobnr, int nb_jobs)
#define AV_PIX_FMT_YUV420P12
static int activate(AVFilterContext *ctx)
int ff_framesync_configure(FFFrameSync *fs)
Configure a frame sync structure.
void av_fft_permute(FFTContext *s, FFTComplex *z)
Do the permutation needed BEFORE calling ff_fft_calc().
static int config_input_main(AVFilterLink *inlink)
uint8_t log2_chroma_w
Amount to shift the luma width right to find the chroma width.
static av_cold void uninit(AVFilterContext *ctx)
void * av_calloc(size_t nmemb, size_t size)
Non-inlined equivalent of av_mallocz_array().
#define AV_PIX_FMT_GRAY10
const char * name
Pad name.
AVFilterContext * parent
Parent filter context.
#define AV_PIX_FMT_GRAY12
AVFilterLink ** inputs
array of pointers to input links
int ff_filter_frame(AVFilterLink *link, AVFrame *frame)
Send a frame of data to the next filter.
planar YUV 4:2:0, 20bpp, (1 Cr & Cb sample per 2x2 Y & A samples)
AVComponentDescriptor comp[4]
Parameters that describe how pixels are packed.
int ff_framesync_init_dualinput(FFFrameSync *fs, AVFilterContext *parent)
Initialize a frame sync structure for dualinput.
static av_cold int end(AVCodecContext *avctx)
int ff_framesync_dualinput_get(FFFrameSync *fs, AVFrame **f0, AVFrame **f1)
#define AV_PIX_FMT_YUVA420P9
planar YUV 4:4:0 full scale (JPEG), deprecated in favor of AV_PIX_FMT_YUV440P and setting color_range...
planar YUV 4:2:2, 16bpp, full scale (JPEG), deprecated in favor of AV_PIX_FMT_YUV422P and setting col...
#define AV_PIX_FMT_YUV444P16
#define AV_PIX_FMT_YUV422P12
static int do_convolve(FFFrameSync *fs)
#define AV_PIX_FMT_YUVA420P16
static int config_output(AVFilterLink *outlink)
A filter pad used for either input or output.
A link between two filters.
FFTComplex * fft_hdata[4]
planar YUV 4:2:2 24bpp, (1 Cr & Cb sample per 2x1 Y & A samples)
static av_cold int init(AVFilterContext *ctx)
static const AVOption convolve_options[]
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
uint8_t log2_chroma_h
Amount to shift the luma height right to find the chroma height.
FFTContext * ifft[4][MAX_THREADS]
void ff_framesync_uninit(FFFrameSync *fs)
Free all memory currently allocated.
AVRational frame_rate
Frame rate of the stream on the link, or 1/0 if unknown or variable; if left to 0/0, will be automatically copied from the first input of the source filter if it exists.
FFTComplex * fft_vdata_impulse[4]
#define NULL_IF_CONFIG_SMALL(x)
Return NULL if CONFIG_SMALL is true, otherwise the argument without modification. ...
void * priv
private data for use by the filter
#define AVFILTER_FLAG_SLICE_THREADS
The filter supports multithreading by splitting frames into multiple parts and processing them concur...
#define AV_PIX_FMT_YUVA444P16
AVRational time_base
Define the time base used by the PTS of the frames/samples which will pass through this link...
#define AV_PIX_FMT_GBRAP12
FFTContext * av_fft_init(int nbits, int inverse)
Set up a complex FFT.
int ff_framesync_activate(FFFrameSync *fs)
Examine the frames in the filter's input and try to produce output.
#define AV_PIX_FMT_YUV444P10
int(* on_event)(struct FFFrameSync *fs)
Callback called when a frame event is ready.
static void convolve(float *tgt, const float *src, int len, int n)
#define AV_PIX_FMT_GBRAP16
planar YUV 4:2:2, 16bpp, (1 Cr & Cb sample per 2x1 Y samples)
int w
agreed upon image width
FFTContext * fft[4][MAX_THREADS]
#define AV_PIX_FMT_YUV422P9
uint8_t nb_components
The number of components each pixel has, (1-4)
FFTComplex * fft_vdata[4]
#define AV_PIX_FMT_GBRP16
int ff_filter_get_nb_threads(AVFilterContext *ctx)
Get number of threads for current filter instance.
#define AV_PIX_FMT_GRAY16
planar YUV 4:2:0, 12bpp, full scale (JPEG), deprecated in favor of AV_PIX_FMT_YUV420P and setting col...
static void get_input(ConvolveContext *s, FFTComplex *fft_hdata, AVFrame *in, int w, int h, int n, int plane, float scale)
AVFilterContext * src
source filter
#define AV_PIX_FMT_YUVA444P10
static const AVFilterPad inputs[]
#define AV_PIX_FMT_YUV444P9
#define AV_PIX_FMT_GBRP14
static const AVFilterPad outputs[]
int format
agreed upon media format
#define AV_PIX_FMT_YUV420P16
static int query_formats(AVFilterContext *ctx)
static int complex_divide(AVFilterContext *ctx, void *arg, int jobnr, int nb_jobs)
#define AV_PIX_FMT_YUV420P14
int linesize[AV_NUM_DATA_POINTERS]
For video, size in bytes of each picture line.
planar YUV 4:4:4 32bpp, (1 Cr & Cb sample per 1x1 Y & A samples)
Descriptor that unambiguously describes how the bits of a pixel are stored in the up to 4 data planes...
#define AVERROR_BUG
Internal bug, also see AVERROR_BUG2.
uint8_t pi<< 24) CONV_FUNC_GROUP(AV_SAMPLE_FMT_FLT, float, AV_SAMPLE_FMT_U8, uint8_t,(*(const uint8_t *) pi - 0x80) *(1.0f/(1<< 7))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_DBL, double, AV_SAMPLE_FMT_U8, uint8_t,(*(const uint8_t *) pi - 0x80) *(1.0/(1<< 7))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_U8, uint8_t, AV_SAMPLE_FMT_S16, int16_t,(*(const int16_t *) pi >> 8)+0x80) CONV_FUNC_GROUP(AV_SAMPLE_FMT_FLT, float, AV_SAMPLE_FMT_S16, int16_t, *(const int16_t *) pi *(1.0f/(1<< 15))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_DBL, double, AV_SAMPLE_FMT_S16, int16_t, *(const int16_t *) pi *(1.0/(1<< 15))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_U8, uint8_t, AV_SAMPLE_FMT_S32, int32_t,(*(const int32_t *) pi >> 24)+0x80) CONV_FUNC_GROUP(AV_SAMPLE_FMT_FLT, float, AV_SAMPLE_FMT_S32, int32_t, *(const int32_t *) pi *(1.0f/(1U<< 31))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_DBL, double, AV_SAMPLE_FMT_S32, int32_t, *(const int32_t *) pi *(1.0/(1U<< 31))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_U8, uint8_t, AV_SAMPLE_FMT_FLT, float, av_clip_uint8(lrintf(*(const float *) pi *(1<< 7))+0x80)) CONV_FUNC_GROUP(AV_SAMPLE_FMT_S16, int16_t, AV_SAMPLE_FMT_FLT, float, av_clip_int16(lrintf(*(const float *) pi *(1<< 15)))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_S32, int32_t, AV_SAMPLE_FMT_FLT, float, av_clipl_int32(llrintf(*(const float *) pi *(1U<< 31)))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_U8, uint8_t, AV_SAMPLE_FMT_DBL, double, av_clip_uint8(lrint(*(const double *) pi *(1<< 7))+0x80)) CONV_FUNC_GROUP(AV_SAMPLE_FMT_S16, int16_t, AV_SAMPLE_FMT_DBL, double, av_clip_int16(lrint(*(const double *) pi *(1<< 15)))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_S32, int32_t, AV_SAMPLE_FMT_DBL, double, av_clipl_int32(llrint(*(const double *) pi *(1U<< 31)))) #define SET_CONV_FUNC_GROUP(ofmt, ifmt) static void set_generic_function(AudioConvert *ac) { } void ff_audio_convert_free(AudioConvert **ac) { if(! *ac) return;ff_dither_free(&(*ac) ->dc);av_freep(ac);} AudioConvert *ff_audio_convert_alloc(AVAudioResampleContext *avr, enum AVSampleFormat out_fmt, enum AVSampleFormat in_fmt, int channels, int sample_rate, int apply_map) { AudioConvert *ac;int in_planar, out_planar;ac=av_mallocz(sizeof(*ac));if(!ac) return NULL;ac->avr=avr;ac->out_fmt=out_fmt;ac->in_fmt=in_fmt;ac->channels=channels;ac->apply_map=apply_map;if(avr->dither_method !=AV_RESAMPLE_DITHER_NONE &&av_get_packed_sample_fmt(out_fmt)==AV_SAMPLE_FMT_S16 &&av_get_bytes_per_sample(in_fmt) > 2) { ac->dc=ff_dither_alloc(avr, out_fmt, in_fmt, channels, sample_rate, apply_map);if(!ac->dc) { av_free(ac);return NULL;} return ac;} in_planar=ff_sample_fmt_is_planar(in_fmt, channels);out_planar=ff_sample_fmt_is_planar(out_fmt, channels);if(in_planar==out_planar) { ac->func_type=CONV_FUNC_TYPE_FLAT;ac->planes=in_planar ? ac->channels :1;} else if(in_planar) ac->func_type=CONV_FUNC_TYPE_INTERLEAVE;else ac->func_type=CONV_FUNC_TYPE_DEINTERLEAVE;set_generic_function(ac);if(ARCH_AARCH64) ff_audio_convert_init_aarch64(ac);if(ARCH_ARM) ff_audio_convert_init_arm(ac);if(ARCH_X86) ff_audio_convert_init_x86(ac);return ac;} int ff_audio_convert(AudioConvert *ac, AudioData *out, AudioData *in) { int use_generic=1;int len=in->nb_samples;int p;if(ac->dc) { av_log(ac->avr, AV_LOG_TRACE, "%d samples - audio_convert: %s to %s (dithered)\", len, av_get_sample_fmt_name(ac->in_fmt), av_get_sample_fmt_name(ac->out_fmt));return ff_convert_dither(ac-> in
#define AV_PIX_FMT_YUV420P10
planar YUV 4:1:0, 9bpp, (1 Cr & Cb sample per 4x4 Y samples)
Describe the class of an AVClass context structure.
const char * name
Filter name.
#define AV_PIX_FMT_YUV440P12
#define AV_PIX_FMT_YUV420P9
AVRational sample_aspect_ratio
agreed upon sample aspect ratio
#define AVFILTER_FLAG_SUPPORT_TIMELINE_INTERNAL
Same as AVFILTER_FLAG_SUPPORT_TIMELINE_GENERIC, except that the filter will have its filter_frame() c...
AVFilterLink ** outputs
array of pointers to output links
AVFilter ff_vf_deconvolve
#define AV_PIX_FMT_YUV422P14
#define AV_PIX_FMT_GBRP12
AVFilterInternal * internal
An opaque struct for libavfilter internal use.
#define AV_PIX_FMT_YUV422P10
#define AV_PIX_FMT_YUV444P12
uint8_t * data[AV_NUM_DATA_POINTERS]
pointer to the picture/channel planes.
planar YUV 4:2:0, 12bpp, (1 Cr & Cb sample per 2x2 Y samples)
static void get_output(ConvolveContext *s, FFTComplex *input, AVFrame *out, int w, int h, int n, int plane, float scale)
planar GBRA 4:4:4:4 32bpp
#define AV_PIX_FMT_YUVA444P9
planar YUV 4:4:4, 24bpp, full scale (JPEG), deprecated in favor of AV_PIX_FMT_YUV444P and setting col...
planar YUV 4:1:1, 12bpp, (1 Cr & Cb sample per 4x1 Y samples)
avfilter_execute_func * execute
static int ifft_horizontal(AVFilterContext *ctx, void *arg, int jobnr, int nb_jobs)
AVFilterContext * dst
dest filter
planar YUV 4:1:1, 12bpp, (1 Cr & Cb sample per 4x1 Y samples) full scale (JPEG), deprecated in favor ...
planar YUV 4:4:0 (1 Cr & Cb sample per 1x2 Y samples)
static int config_input_impulse(AVFilterLink *inlink)
static const AVFilterPad convolve_inputs[]
FFTComplex * fft_hdata_impulse[4]
int depth
Number of bits in the component.
void av_fft_calc(FFTContext *s, FFTComplex *z)
Do a complex FFT with the parameters defined in av_fft_init().
AVPixelFormat
Pixel format.
const AVFilter * filter
the AVFilter of which this is an instance
#define AV_PIX_FMT_YUV422P16
#define AV_CEIL_RSHIFT(a, b)