mirror of
https://github.com/FFmpeg/FFmpeg.git
synced 2024-12-23 12:43:46 +02:00
avfilter: slice processing for geq
Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
This commit is contained in:
parent
206b25f9f4
commit
ac6b0bba79
@ -41,6 +41,9 @@ typedef struct GEQContext {
|
||||
AVExpr *e[4]; ///< expressions for each plane
|
||||
char *expr_str[4+3]; ///< expression strings for each plane
|
||||
AVFrame *picref; ///< current input buffer
|
||||
uint8_t *dst; ///< reference pointer to the 8bits output
|
||||
uint16_t *dst16; ///< reference pointer to the 16bits output
|
||||
double values[VAR_VARS_NB]; ///< expression values
|
||||
int hsub, vsub; ///< chroma subsampling
|
||||
int planes; ///< number of planes
|
||||
int is_rgb;
|
||||
@ -226,8 +229,62 @@ static int geq_config_props(AVFilterLink *inlink)
|
||||
|
||||
geq->hsub = desc->log2_chroma_w;
|
||||
geq->vsub = desc->log2_chroma_h;
|
||||
geq->bps = desc->comp[0].depth;
|
||||
geq->planes = desc->nb_components;
|
||||
geq->bps = desc->comp[0].depth;
|
||||
return 0;
|
||||
}
|
||||
|
||||
typedef struct ThreadData {
|
||||
int height;
|
||||
int width;
|
||||
int plane;
|
||||
int linesize;
|
||||
} ThreadData;
|
||||
|
||||
static int slice_geq_filter(AVFilterContext *ctx, void *arg, int jobnr, int nb_jobs)
|
||||
{
|
||||
GEQContext *geq = ctx->priv;
|
||||
ThreadData *td = arg;
|
||||
const int height = td->height;
|
||||
const int width = td->width;
|
||||
const int plane = td->plane;
|
||||
const int linesize = td->linesize;
|
||||
const int slice_start = (height * jobnr) / nb_jobs;
|
||||
const int slice_end = (height * (jobnr+1)) / nb_jobs;
|
||||
int x, y;
|
||||
uint8_t *ptr;
|
||||
uint16_t *ptr16;
|
||||
|
||||
double values[VAR_VARS_NB];
|
||||
values[VAR_W] = geq->values[VAR_W];
|
||||
values[VAR_H] = geq->values[VAR_H];
|
||||
values[VAR_N] = geq->values[VAR_N];
|
||||
values[VAR_SW] = geq->values[VAR_SW];
|
||||
values[VAR_SH] = geq->values[VAR_SH];
|
||||
values[VAR_T] = geq->values[VAR_T];
|
||||
|
||||
if (geq->bps == 8) {
|
||||
for (y = slice_start; y < slice_end; y++) {
|
||||
ptr = geq->dst + linesize * y;
|
||||
values[VAR_Y] = y;
|
||||
|
||||
for (x = 0; x < width; x++) {
|
||||
values[VAR_X] = x;
|
||||
ptr[x] = av_expr_eval(geq->e[plane], values, geq);
|
||||
}
|
||||
ptr += linesize;
|
||||
}
|
||||
}
|
||||
else {
|
||||
for (y = slice_start; y < slice_end; y++) {
|
||||
ptr16 = geq->dst16 + (linesize/2) * y;
|
||||
values[VAR_Y] = y;
|
||||
for (x = 0; x < width; x++) {
|
||||
values[VAR_X] = x;
|
||||
ptr16[x] = av_expr_eval(geq->e[plane], values, geq);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
@ -235,13 +292,14 @@ static int geq_config_props(AVFilterLink *inlink)
|
||||
static int geq_filter_frame(AVFilterLink *inlink, AVFrame *in)
|
||||
{
|
||||
int plane;
|
||||
GEQContext *geq = inlink->dst->priv;
|
||||
AVFilterContext *ctx = inlink->dst;
|
||||
const int nb_threads = ff_filter_get_nb_threads(ctx);
|
||||
GEQContext *geq = ctx->priv;
|
||||
AVFilterLink *outlink = inlink->dst->outputs[0];
|
||||
AVFrame *out;
|
||||
double values[VAR_VARS_NB] = {
|
||||
[VAR_N] = inlink->frame_count_out,
|
||||
[VAR_T] = in->pts == AV_NOPTS_VALUE ? NAN : in->pts * av_q2d(inlink->time_base),
|
||||
};
|
||||
|
||||
geq->values[VAR_N] = inlink->frame_count_out,
|
||||
geq->values[VAR_T] = in->pts == AV_NOPTS_VALUE ? NAN : in->pts * av_q2d(inlink->time_base),
|
||||
|
||||
geq->picref = in;
|
||||
out = ff_get_video_buffer(outlink, outlink->w, outlink->h);
|
||||
@ -252,34 +310,25 @@ static int geq_filter_frame(AVFilterLink *inlink, AVFrame *in)
|
||||
av_frame_copy_props(out, in);
|
||||
|
||||
for (plane = 0; plane < geq->planes && out->data[plane]; plane++) {
|
||||
int x, y;
|
||||
uint8_t *dst = out->data[plane];
|
||||
uint16_t *dst16 = (uint16_t*)out->data[plane];
|
||||
const int linesize = out->linesize[plane];
|
||||
const int w = (plane == 1 || plane == 2) ? AV_CEIL_RSHIFT(inlink->w, geq->hsub) : inlink->w;
|
||||
const int h = (plane == 1 || plane == 2) ? AV_CEIL_RSHIFT(inlink->h, geq->vsub) : inlink->h;
|
||||
const int linesize = out->linesize[plane];
|
||||
ThreadData td;
|
||||
|
||||
values[VAR_W] = w;
|
||||
values[VAR_H] = h;
|
||||
values[VAR_SW] = w / (double)inlink->w;
|
||||
values[VAR_SH] = h / (double)inlink->h;
|
||||
geq->dst = out->data[plane];
|
||||
geq->dst16 = (uint16_t*)out->data[plane];
|
||||
|
||||
for (y = 0; y < h; y++) {
|
||||
values[VAR_Y] = y;
|
||||
if (geq->bps > 8) {
|
||||
for (x = 0; x < w; x++) {
|
||||
values[VAR_X] = x;
|
||||
dst16[x] = av_expr_eval(geq->e[plane], values, geq);
|
||||
}
|
||||
dst16 += linesize / 2;
|
||||
} else {
|
||||
for (x = 0; x < w; x++) {
|
||||
values[VAR_X] = x;
|
||||
dst[x] = av_expr_eval(geq->e[plane], values, geq);
|
||||
}
|
||||
dst += linesize;
|
||||
}
|
||||
}
|
||||
geq->values[VAR_W] = w;
|
||||
geq->values[VAR_H] = h;
|
||||
geq->values[VAR_SW] = w / (double)inlink->w;
|
||||
geq->values[VAR_SH] = h / (double)inlink->h;
|
||||
|
||||
td.width = w;
|
||||
td.height = h;
|
||||
td.plane = plane;
|
||||
td.linesize = linesize;
|
||||
|
||||
ctx->internal->execute(ctx, slice_geq_filter, &td, NULL, FFMIN(h, nb_threads));
|
||||
}
|
||||
|
||||
av_frame_free(&geq->picref);
|
||||
@ -323,5 +372,5 @@ AVFilter ff_vf_geq = {
|
||||
.inputs = geq_inputs,
|
||||
.outputs = geq_outputs,
|
||||
.priv_class = &geq_class,
|
||||
.flags = AVFILTER_FLAG_SUPPORT_TIMELINE_GENERIC,
|
||||
.flags = AVFILTER_FLAG_SUPPORT_TIMELINE_GENERIC | AVFILTER_FLAG_SLICE_THREADS,
|
||||
};
|
||||
|
Loading…
Reference in New Issue
Block a user