1
0
mirror of https://github.com/FFmpeg/FFmpeg.git synced 2024-12-23 12:43:46 +02:00

avfilter/vf_rotate: support slice threading

Signed-off-by: Paul B Mahol <onemda@gmail.com>
This commit is contained in:
Paul B Mahol 2013-09-29 19:04:01 +00:00
parent 54197c7aae
commit 862773907a

View File

@ -77,6 +77,16 @@ typedef struct {
FFDrawColor color;
} RotContext;
typedef struct ThreadData {
AVFrame *in, *out;
int inw, inh;
int outw, outh;
int plane;
int xi, yi;
int xprime, yprime;
int c, s;
} ThreadData;
#define OFFSET(x) offsetof(RotContext, x)
#define FLAGS AV_OPT_FLAG_FILTERING_PARAM|AV_OPT_FLAG_VIDEO_PARAM
@ -299,53 +309,24 @@ static uint8_t *interpolate_bilinear(uint8_t *dst_color,
#define TS2T(ts, tb) ((ts) == AV_NOPTS_VALUE ? NAN : (double)(ts)*av_q2d(tb))
static int filter_frame(AVFilterLink *inlink, AVFrame *in)
static int filter_slice(AVFilterContext *ctx, void *arg, int job, int nb_jobs)
{
AVFilterContext *ctx = inlink->dst;
AVFilterLink *outlink = ctx->outputs[0];
AVFrame *out;
ThreadData *td = arg;
AVFrame *in = td->in;
AVFrame *out = td->out;
RotContext *rot = ctx->priv;
int angle_int, s, c, plane;
double res;
out = ff_get_video_buffer(outlink, outlink->w, outlink->h);
if (!out) {
av_frame_free(&in);
return AVERROR(ENOMEM);
}
av_frame_copy_props(out, in);
rot->var_values[VAR_N] = inlink->frame_count;
rot->var_values[VAR_T] = TS2T(in->pts, inlink->time_base);
rot->angle = res = av_expr_eval(rot->angle_expr, rot->var_values, rot);
av_log(ctx, AV_LOG_DEBUG, "n:%f time:%f angle:%f/PI\n",
rot->var_values[VAR_N], rot->var_values[VAR_T], rot->angle/M_PI);
angle_int = res * FIXP;
s = int_sin(angle_int);
c = int_sin(angle_int + INT_PI/2);
/* fill background */
if (rot->fillcolor_enable)
ff_fill_rectangle(&rot->draw, &rot->color, out->data, out->linesize,
0, 0, outlink->w, outlink->h);
for (plane = 0; plane < rot->nb_planes; plane++) {
int hsub = plane == 1 || plane == 2 ? rot->hsub : 0;
int vsub = plane == 1 || plane == 2 ? rot->vsub : 0;
int inw = FF_CEIL_RSHIFT(inlink->w, hsub);
int inh = FF_CEIL_RSHIFT(inlink->h, vsub);
int outw = FF_CEIL_RSHIFT(outlink->w, hsub);
int outh = FF_CEIL_RSHIFT(outlink->h, vsub);
const int xi = -outw/2 * c;
const int yi = outw/2 * s;
int xprime = -outh/2 * s;
int yprime = -outh/2 * c;
const int outw = td->outw, outh = td->outh;
const int inw = td->inw, inh = td->inh;
const int plane = td->plane;
const int xi = td->xi, yi = td->yi;
const int c = td->c, s = td->s;
const int start = (outh * job ) / nb_jobs;
const int end = (outh * (job+1)) / nb_jobs;
int xprime = td->xprime + start * s;
int yprime = td->yprime + start * c;
int i, j, x, y;
for (j = 0; j < outh; j++) {
for (j = start; j < end; j++) {
x = xprime + xi + FIXP*inw/2;
y = yprime + yi + FIXP*inh/2;
@ -394,6 +375,58 @@ static int filter_frame(AVFilterLink *inlink, AVFrame *in)
xprime += s;
yprime += c;
}
return 0;
}
static int filter_frame(AVFilterLink *inlink, AVFrame *in)
{
AVFilterContext *ctx = inlink->dst;
AVFilterLink *outlink = ctx->outputs[0];
AVFrame *out;
RotContext *rot = ctx->priv;
int angle_int, s, c, plane;
double res;
out = ff_get_video_buffer(outlink, outlink->w, outlink->h);
if (!out) {
av_frame_free(&in);
return AVERROR(ENOMEM);
}
av_frame_copy_props(out, in);
rot->var_values[VAR_N] = inlink->frame_count;
rot->var_values[VAR_T] = TS2T(in->pts, inlink->time_base);
rot->angle = res = av_expr_eval(rot->angle_expr, rot->var_values, rot);
av_log(ctx, AV_LOG_DEBUG, "n:%f time:%f angle:%f/PI\n",
rot->var_values[VAR_N], rot->var_values[VAR_T], rot->angle/M_PI);
angle_int = res * FIXP;
s = int_sin(angle_int);
c = int_sin(angle_int + INT_PI/2);
/* fill background */
if (rot->fillcolor_enable)
ff_fill_rectangle(&rot->draw, &rot->color, out->data, out->linesize,
0, 0, outlink->w, outlink->h);
for (plane = 0; plane < rot->nb_planes; plane++) {
int hsub = plane == 1 || plane == 2 ? rot->hsub : 0;
int vsub = plane == 1 || plane == 2 ? rot->vsub : 0;
const int outw = FF_CEIL_RSHIFT(outlink->w, hsub);
const int outh = FF_CEIL_RSHIFT(outlink->h, vsub);
ThreadData td = { .in = in, .out = out,
.inw = FF_CEIL_RSHIFT(inlink->w, hsub),
.inh = FF_CEIL_RSHIFT(inlink->h, vsub),
.outh = outh, .outw = outw,
.xi = -outw/2 * c, .yi = outw/2 * s,
.xprime = -outh/2 * s,
.yprime = -outh/2 * c,
.plane = plane, .c = c, .s = s };
ctx->internal->execute(ctx, filter_slice, &td, NULL, FFMIN(outh, ctx->graph->nb_threads));
}
av_frame_free(&in);
@ -452,5 +485,5 @@ AVFilter avfilter_vf_rotate = {
.inputs = rotate_inputs,
.outputs = rotate_outputs,
.priv_class = &rotate_class,
.flags = AVFILTER_FLAG_SUPPORT_TIMELINE_GENERIC,
.flags = AVFILTER_FLAG_SUPPORT_TIMELINE_GENERIC | AVFILTER_FLAG_SLICE_THREADS,
};