History

avfilter/vf_scroll: add support for slice threading

Paul B Mahol committed 6 years ago

Commit f89ebf81 parent 9bd4df11 file · +50 −27Browse files

Unified · Split

libavfilter/vf_scroll.c+50−27
@@ -32,6 +32,8 @@ typedef struct ScrollContext { · 31 unmodified lines
3232 float h_pos, v_pos;
3333 float h_ipos, v_ipos;
3434
35+ int pos_h[4], pos_v[4];
36+
3537 const AVPixFmtDescriptor *desc;
3638 int nb_planes;
3739 int bytes;
@@ -70,10 +72,47 @@ static int query_formats(AVFilterContext *ctx) · 32 unmodified lines
7072 return ff_set_common_formats(ctx, fmts_list);
7173 }
7274
73−static void scroll(ScrollContext *s, AVFrame *in, AVFrame *out)
75+typedef struct ThreadData {
76+ AVFrame *in, *out;
77+} ThreadData;
78+
79+static int scroll_slice(AVFilterContext *ctx, void *arg, int jobnr,
80+ int nb_jobs)
7481 {
82+ ScrollContext *s = ctx->priv;
83+ ThreadData *td = arg;
84+ AVFrame *in = td->in;
85+ AVFrame *out = td->out;
86+
87+ for (int p = 0; p < s->nb_planes; p++) {
88+ const uint8_t *src = in->data[p];
89+ const int h = s->planeheight[p];
90+ const int w = s->planewidth[p] * s->bytes;
91+ const int slice_start = (h * jobnr) / nb_jobs;
92+ const int slice_end = (h * (jobnr+1)) / nb_jobs;
93+ uint8_t *dst = out->data[p] + slice_start * out->linesize[p];
94+
95+ for (int y = slice_start; y < slice_end; y++) {
96+ int yy = (y + s->pos_v[p]) % h;
97+ const uint8_t *ssrc = src + yy * in->linesize[p];
98+
99+ if (s->pos_h[p] < w)
100+ memcpy(dst, ssrc + s->pos_h[p], w - s->pos_h[p]);
101+ if (s->pos_h[p] > 0)
102+ memcpy(dst + w - s->pos_h[p], ssrc, s->pos_h[p]);
103+
104+ dst += out->linesize[p];
105+ }
106+ }
107+
108+ return 0;
109+}
110+
111+static void scroll(AVFilterContext *ctx, AVFrame *in, AVFrame *out)
112+{
113+ ScrollContext *s = ctx->priv;
114+ ThreadData td;
75115 int h_pos, v_pos;
76− int pos_h[4], pos_v[4];
77116
78117 s->h_pos = fmodf(s->h_pos, in->width);
79118 s->v_pos = fmodf(s->v_pos, in->height);
@@ -86,29 +125,14 @@ static void scroll(ScrollContext *s, AVFrame *in, AVFrame *out) · 6 unmodified lines
86125 if (v_pos < 0)
87126 v_pos += in->height;
88127
89− pos_v[1] = pos_v[2] = AV_CEIL_RSHIFT(v_pos, s->desc->log2_chroma_h);
90− pos_v[0] = pos_v[3] = v_pos;
91− pos_h[1] = pos_h[2] = AV_CEIL_RSHIFT(h_pos, s->desc->log2_chroma_w) * s->bytes;
92− pos_h[0] = pos_h[3] = h_pos * s->bytes;
128+ s->pos_v[1] = s->pos_v[2] = AV_CEIL_RSHIFT(v_pos, s->desc->log2_chroma_h);
129+ s->pos_v[0] = s->pos_v[3] = v_pos;
130+ s->pos_h[1] = s->pos_h[2] = AV_CEIL_RSHIFT(h_pos, s->desc->log2_chroma_w) * s->bytes;
131+ s->pos_h[0] = s->pos_h[3] = h_pos * s->bytes;
93132
94− for (int p = 0; p < s->nb_planes; p++) {
95− const uint8_t *src = in->data[p];
96− uint8_t *dst = out->data[p];
97− const int h = s->planeheight[p];
98− const int w = s->planewidth[p] * s->bytes;
99−
100− for (int y = 0; y < h; y++) {
101− int yy = (y + pos_v[p]) % h;
102− const uint8_t *ssrc = src + yy * in->linesize[p];
103−
104− if (pos_h[p] < w)
105− memcpy(dst, ssrc + pos_h[p], w - pos_h[p]);
106− if (pos_h[p] > 0)
107− memcpy(dst + w - pos_h[p], ssrc, pos_h[p]);
108−
109− dst += out->linesize[p];
110− }
111− }
133+ td.in = in; td.out = out;
134+ ctx->internal->execute(ctx, scroll_slice, &td, NULL,
135+ FFMIN(out->height, ff_filter_get_nb_threads(ctx)));
112136
113137 s->h_pos += s->h_speed * in->width;
114138 s->v_pos += s->v_speed * in->height;
@@ -117,7 +141,6 @@ static void scroll(ScrollContext *s, AVFrame *in, AVFrame *out) · 2 unmodified lines
117141 static int filter_frame(AVFilterLink *inlink, AVFrame *in)
118142 {
119143 AVFilterContext *ctx = inlink->dst;
120− ScrollContext *s = ctx->priv;
121144 AVFilterLink *outlink = ctx->outputs[0];
122145 AVFrame *out;
123146
@@ -128,7 +151,7 @@ static int filter_frame(AVFilterLink *inlink, AVFrame *in) · 4 unmodified lines
128151 }
129152 av_frame_copy_props(out, in);
130153
131− scroll(s, in, out);
154+ scroll(ctx, in, out);
132155
133156 av_frame_free(&in);
134157 return ff_filter_frame(outlink, out);
@@ -196,6 +219,6 @@ AVFilter ff_vf_scroll = { · 61 unmodified lines
196219 .query_formats = query_formats,
197220 .inputs = scroll_inputs,
198221 .outputs = scroll_outputs,
199− .flags = AVFILTER_FLAG_SUPPORT_TIMELINE_GENERIC,
222+ .flags = AVFILTER_FLAG_SUPPORT_TIMELINE_GENERIC | AVFILTER_FLAG_SLICE_THREADS,
200223 .process_command = ff_filter_process_command,
201224 };

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t