Commit bfdd6304 authored by Paul B Mahol's avatar Paul B Mahol

avfilter/af_crystalizer: add slice threading support

parent af1f1e86
...@@ -29,8 +29,7 @@ typedef struct CrystalizerContext { ...@@ -29,8 +29,7 @@ typedef struct CrystalizerContext {
float mult; float mult;
int clip; int clip;
AVFrame *prev; AVFrame *prev;
void (*filter)(void **dst, void **prv, const void **src, int (*filter)(AVFilterContext *ctx, void *arg, int jobnr, int nb_jobs);
int nb_samples, int channels, float mult, int clip);
} CrystalizerContext; } CrystalizerContext;
#define OFFSET(x) offsetof(CrystalizerContext, x) #define OFFSET(x) offsetof(CrystalizerContext, x)
...@@ -74,42 +73,71 @@ static int query_formats(AVFilterContext *ctx) ...@@ -74,42 +73,71 @@ static int query_formats(AVFilterContext *ctx)
return ff_set_common_samplerates(ctx, formats); return ff_set_common_samplerates(ctx, formats);
} }
static void filter_flt(void **d, void **p, const void **s, typedef struct ThreadData {
int nb_samples, int channels, void **d;
float mult, int clip) void **p;
const void **s;
int nb_samples;
int channels;
float mult;
int clip;
} ThreadData;
static int filter_flt(AVFilterContext *ctx, void *arg, int jobnr, int nb_jobs)
{ {
const float *src = s[0]; ThreadData *td = arg;
float *dst = d[0]; void **d = td->d;
void **p = td->p;
const void **s = td->s;
const int nb_samples = td->nb_samples;
const int channels = td->channels;
float mult = td->mult;
const int clip = td->clip;
const int start = (channels * jobnr) / nb_jobs;
const int end = (channels * (jobnr+1)) / nb_jobs;
float *prv = p[0]; float *prv = p[0];
int n, c; int n, c;
for (n = 0; n < nb_samples; n++) { for (c = start; c < end; c++) {
for (c = 0; c < channels; c++) { const float *src = s[0];
float current = src[c]; float *dst = d[0];
for (n = 0; n < nb_samples; n++) {
float current = src[c];
dst[c] = current + (current - prv[c]) * mult; dst[c] = current + (current - prv[c]) * mult;
prv[c] = current; prv[c] = current;
if (clip) { if (clip) {
dst[c] = av_clipf(dst[c], -1, 1); dst[c] = av_clipf(dst[c], -1, 1);
} }
}
dst += c; dst += channels;
src += c; src += channels;
}
} }
return 0;
} }
static void filter_dbl(void **d, void **p, const void **s, static int filter_dbl(AVFilterContext *ctx, void *arg, int jobnr, int nb_jobs)
int nb_samples, int channels,
float mult, int clip)
{ {
const double *src = s[0]; ThreadData *td = arg;
double *dst = d[0]; void **d = td->d;
void **p = td->p;
const void **s = td->s;
const int nb_samples = td->nb_samples;
const int channels = td->channels;
float mult = td->mult;
const int clip = td->clip;
const int start = (channels * jobnr) / nb_jobs;
const int end = (channels * (jobnr+1)) / nb_jobs;
double *prv = p[0]; double *prv = p[0];
int n, c; int n, c;
for (n = 0; n < nb_samples; n++) { for (c = start; c < end; c++) {
for (c = 0; c < channels; c++) { const double *src = s[0];
double *dst = d[0];
for (n = 0; n < nb_samples; n++) {
double current = src[c]; double current = src[c];
dst[c] = current + (current - prv[c]) * mult; dst[c] = current + (current - prv[c]) * mult;
...@@ -117,20 +145,30 @@ static void filter_dbl(void **d, void **p, const void **s, ...@@ -117,20 +145,30 @@ static void filter_dbl(void **d, void **p, const void **s,
if (clip) { if (clip) {
dst[c] = av_clipd(dst[c], -1, 1); dst[c] = av_clipd(dst[c], -1, 1);
} }
}
dst += c; dst += channels;
src += c; src += channels;
}
} }
return 0;
} }
static void filter_fltp(void **d, void **p, const void **s, static int filter_fltp(AVFilterContext *ctx, void *arg, int jobnr, int nb_jobs)
int nb_samples, int channels,
float mult, int clip)
{ {
ThreadData *td = arg;
void **d = td->d;
void **p = td->p;
const void **s = td->s;
const int nb_samples = td->nb_samples;
const int channels = td->channels;
float mult = td->mult;
const int clip = td->clip;
const int start = (channels * jobnr) / nb_jobs;
const int end = (channels * (jobnr+1)) / nb_jobs;
int n, c; int n, c;
for (c = 0; c < channels; c++) { for (c = start; c < end; c++) {
const float *src = s[c]; const float *src = s[c];
float *dst = d[c]; float *dst = d[c];
float *prv = p[c]; float *prv = p[c];
...@@ -145,15 +183,25 @@ static void filter_fltp(void **d, void **p, const void **s, ...@@ -145,15 +183,25 @@ static void filter_fltp(void **d, void **p, const void **s,
} }
} }
} }
return 0;
} }
static void filter_dblp(void **d, void **p, const void **s, static int filter_dblp(AVFilterContext *ctx, void *arg, int jobnr, int nb_jobs)
int nb_samples, int channels,
float mult, int clip)
{ {
ThreadData *td = arg;
void **d = td->d;
void **p = td->p;
const void **s = td->s;
const int nb_samples = td->nb_samples;
const int channels = td->channels;
float mult = td->mult;
const int clip = td->clip;
const int start = (channels * jobnr) / nb_jobs;
const int end = (channels * (jobnr+1)) / nb_jobs;
int n, c; int n, c;
for (c = 0; c < channels; c++) { for (c = start; c < end; c++) {
const double *src = s[c]; const double *src = s[c];
double *dst = d[c]; double *dst = d[c];
double *prv = p[c]; double *prv = p[c];
...@@ -168,6 +216,8 @@ static void filter_dblp(void **d, void **p, const void **s, ...@@ -168,6 +216,8 @@ static void filter_dblp(void **d, void **p, const void **s,
} }
} }
} }
return 0;
} }
static int config_input(AVFilterLink *inlink) static int config_input(AVFilterLink *inlink)
...@@ -191,6 +241,7 @@ static int filter_frame(AVFilterLink *inlink, AVFrame *in) ...@@ -191,6 +241,7 @@ static int filter_frame(AVFilterLink *inlink, AVFrame *in)
AVFilterLink *outlink = ctx->outputs[0]; AVFilterLink *outlink = ctx->outputs[0];
CrystalizerContext *s = ctx->priv; CrystalizerContext *s = ctx->priv;
AVFrame *out; AVFrame *out;
ThreadData td;
if (!s->prev) { if (!s->prev) {
s->prev = ff_get_audio_buffer(inlink, 1); s->prev = ff_get_audio_buffer(inlink, 1);
...@@ -211,8 +262,15 @@ static int filter_frame(AVFilterLink *inlink, AVFrame *in) ...@@ -211,8 +262,15 @@ static int filter_frame(AVFilterLink *inlink, AVFrame *in)
av_frame_copy_props(out, in); av_frame_copy_props(out, in);
} }
s->filter((void **)out->extended_data, (void **)s->prev->extended_data, (const void **)in->extended_data, td.d = (void **)out->extended_data;
in->nb_samples, in->channels, ctx->is_disabled ? 0.f : s->mult, s->clip); td.s = (const void **)in->extended_data;
td.p = (void **)s->prev->extended_data;
td.nb_samples = in->nb_samples;
td.channels = in->channels;
td.mult = ctx->is_disabled ? 0.f : s->mult;
td.clip = s->clip;
ctx->internal->execute(ctx, s->filter, &td, NULL, FFMIN(inlink->channels,
ff_filter_get_nb_threads(ctx)));
if (out != in) if (out != in)
av_frame_free(&in); av_frame_free(&in);
...@@ -254,6 +312,7 @@ AVFilter ff_af_crystalizer = { ...@@ -254,6 +312,7 @@ AVFilter ff_af_crystalizer = {
.uninit = uninit, .uninit = uninit,
.inputs = inputs, .inputs = inputs,
.outputs = outputs, .outputs = outputs,
.flags = AVFILTER_FLAG_SUPPORT_TIMELINE_INTERNAL,
.process_command = ff_filter_process_command, .process_command = ff_filter_process_command,
.flags = AVFILTER_FLAG_SUPPORT_TIMELINE_INTERNAL |
AVFILTER_FLAG_SLICE_THREADS,
}; };
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment