History

Merge remote-tracking branch 'qatar/master'

* qatar/master: vf_fade: support slice threading vf_yadif: support slice threading Conflicts: libavfilter/vf_fade.c libavfilter/vf_yadif.c

Michael Niedermayer committed 13 years ago

Commit 558ce3e2 parents 2516b39 8a994b72 files · +116 −52Browse files

Unified · Split

2 files
  1. libavfilter/vf_fade.c +60 −21
  2. libavfilter/vf_yadif.c +56 −31
libavfilter/vf_fade.c+60−21
@@ -158,11 +158,61 @@ static void fade_plane(int y, int h, int w, · 157 unmodified lines
158 }158 }
159}159}
160 160
161static int filter_frame(AVFilterLink *inlink, AVFrame *frame)161static int filter_slice_luma(AVFilterContext *ctx, void *arg, int jobnr,
162 int nb_jobs)
162{163{
163 FadeContext *s = inlink->dst->priv;164 FadeContext *s = ctx->priv;
164 uint8_t *p;165 AVFrame *frame = arg;
166 int slice_h = frame->height / nb_jobs;
167 int slice_start = jobnr * slice_h;
168 int slice_end = (jobnr == nb_jobs - 1) ? frame->height : (jobnr + 1) * slice_h;
169 int i, j;
170
171 for (i = slice_start; i < slice_end; i++) {
172 uint8_t *p = frame->data[0] + i * frame->linesize[0];
173 for (j = 0; j < frame->width * s->bpp; j++) {
174 /* s->factor is using 16 lower-order bits for decimal
175 * places. 32768 = 1 << 15, it is an integer representation
176 * of 0.5 and is for rounding. */
177 *p = ((*p - s->black_level) * s->factor + s->black_level_scaled) >> 16;
178 p++;
179 }
180 }
181
182 return 0;
183}
184
185static int filter_slice_chroma(AVFilterContext *ctx, void *arg, int jobnr,
186 int nb_jobs)
187{
188 FadeContext *s = ctx->priv;
189 AVFrame *frame = arg;
190 int slice_h = FFALIGN(frame->height / nb_jobs, 1 << s->vsub);
191 int slice_start = jobnr * slice_h;
192 int slice_end = (jobnr == nb_jobs - 1) ? frame->height : (jobnr + 1) * slice_h;
165 int i, j, plane;193 int i, j, plane;
194 const int width = FF_CEIL_RSHIFT(frame->width, s->hsub);
195
196 for (plane = 1; plane < 3; plane++) {
197 for (i = slice_start; i < slice_end; i++) {
198 uint8_t *p = frame->data[plane] + (i >> s->vsub) * frame->linesize[plane];
199 for (j = 0; j < width; j++) {
200 /* 8421367 = ((128 << 1) + 1) << 15. It is an integer
201 * representation of 128.5. The .5 is for rounding
202 * purposes. */
203 *p = ((*p - 128) * s->factor + 8421367) >> 16;
204 p++;
205 }
206 }
207 }
208
209 return 0;
210}
211
212static int filter_frame(AVFilterLink *inlink, AVFrame *frame)
213{
214 AVFilterContext *ctx = inlink->dst;
215 FadeContext *s = ctx->priv;
166 double frame_timestamp = frame->pts == AV_NOPTS_VALUE ? -1 : frame->pts * av_q2d(inlink->time_base);216 double frame_timestamp = frame->pts == AV_NOPTS_VALUE ? -1 : frame->pts * av_q2d(inlink->time_base);
167 217
168 // Calculate Fade assuming this is a Fade In218 // Calculate Fade assuming this is a Fade In
@@ -216,7 +266,7 @@ static int filter_frame(AVFilterLink *inlink, AVFrame *frame) · 47 unmodified lines
216 if (s->factor < UINT16_MAX) {266 if (s->factor < UINT16_MAX) {
217 if (s->alpha) {267 if (s->alpha) {
218 // alpha only268 // alpha only
219 plane = s->is_packed_rgb ? 0 : A; // alpha is on plane 0 for packed formats269 int plane = s->is_packed_rgb ? 0 : A; // alpha is on plane 0 for packed formats
220 // or plane 3 for planar formats270 // or plane 3 for planar formats
221 fade_plane(0, frame->height, inlink->w,271 fade_plane(0, frame->height, inlink->w,
222 s->factor, s->black_level, s->black_level_scaled,272 s->factor, s->black_level, s->black_level_scaled,
@@ -225,25 +275,13 @@ static int filter_frame(AVFilterLink *inlink, AVFrame *frame) · 2 unmodified lines
225 1, frame->data[plane], frame->linesize[plane]);275 1, frame->data[plane], frame->linesize[plane]);
226 } else {276 } else {
227 /* luma or rgb plane */277 /* luma or rgb plane */
228 fade_plane(0, frame->height, inlink->w,278 ctx->internal->execute(ctx, filter_slice_luma, frame, NULL,
229 s->factor, s->black_level, s->black_level_scaled,279 FFMIN(frame->height, ctx->graph->nb_threads));
230 0, 1, // offset & pixstep for Y plane or RGB packed format280
231 s->bpp, frame->data[0], frame->linesize[0]);
232 if (frame->data[1] && frame->data[2]) {281 if (frame->data[1] && frame->data[2]) {
233 /* chroma planes */282 /* chroma planes */
234 for (plane = 1; plane < 3; plane++) {283 ctx->internal->execute(ctx, filter_slice_chroma, frame, NULL,
235 for (i = 0; i < frame->height; i++) {284 FFMIN(frame->height, ctx->graph->nb_threads));
236 const int width = FF_CEIL_RSHIFT(inlink->w, s->hsub);
237 p = frame->data[plane] + (i >> s->vsub) * frame->linesize[plane];
238 for (j = 0; j < width; j++) {
239 /* 8421367 = ((128 << 1) + 1) << 15. It is an integer
240 * representation of 128.5. The .5 is for rounding
241 * purposes. */
242 *p = ((*p - 128) * s->factor + 8421367) >> 16;
243 p++;
244 }
245 }
246 }
247 }285 }
248 }286 }
249 }287 }
@@ -314,4 +352,5 @@ AVFilter avfilter_vf_fade = { · 64 unmodified lines
314 352
315 .inputs = avfilter_vf_fade_inputs,353 .inputs = avfilter_vf_fade_inputs,
316 .outputs = avfilter_vf_fade_outputs,354 .outputs = avfilter_vf_fade_outputs,
355 .flags = AVFILTER_FLAG_SLICE_THREADS,
317};356};
libavfilter/vf_yadif.c+56−31
@@ -31,6 +31,14 @@ · 30 unmodified lines
31#undef NDEBUG31#undef NDEBUG
32#include <assert.h>32#include <assert.h>
33 33
34typedef struct ThreadData {
35 AVFrame *frame;
36 int plane;
37 int w, h;
38 int parity;
39 int tff;
40} ThreadData;
41
34#define CHECK(j)\42#define CHECK(j)\
35 { int score = FFABS(cur[mrefs - 1 + (j)] - cur[prefs - 1 - (j)])\43 { int score = FFABS(cur[mrefs - 1 + (j)] - cur[prefs - 1 - (j)])\
36 + FFABS(cur[mrefs +(j)] - cur[prefs -(j)])\44 + FFABS(cur[mrefs +(j)] - cur[prefs -(j)])\
@@ -172,50 +180,67 @@ static void filter_edges_16bit(void *dst1, void *prev1, void *cur1, void *next1, · 135 unmodified lines
172 FILTER(w - 3, w, 0)180 FILTER(w - 3, w, 0)
173}181}
174 182
183static int filter_slice(AVFilterContext *ctx, void *arg, int jobnr, int nb_jobs)
184{
185 YADIFContext *s = ctx->priv;
186 ThreadData *td = arg;
187 int refs = s->cur->linesize[td->plane];
188 int df = (s->csp->comp[td->plane].depth_minus1 + 8) / 8;
189 int pix_3 = 3 * df;
190 int slice_h = td->h / nb_jobs;
191 int slice_start = jobnr * slice_h;
192 int slice_end = (jobnr == nb_jobs - 1) ? td->h : (jobnr + 1) * slice_h;
193 int y;
194
195 /* filtering reads 3 pixels to the left/right; to avoid invalid reads,
196 * we need to call the c variant which avoids this for border pixels
197 */
198 for (y = slice_start; y < slice_end; y++) {
199 if ((y ^ td->parity) & 1) {
200 uint8_t *prev = &s->prev->data[td->plane][y * refs];
201 uint8_t *cur = &s->cur ->data[td->plane][y * refs];
202 uint8_t *next = &s->next->data[td->plane][y * refs];
203 uint8_t *dst = &td->frame->data[td->plane][y * td->frame->linesize[td->plane]];
204 int mode = y == 1 || y + 2 == td->h ? 2 : s->mode;
205 s->filter_line(dst + pix_3, prev + pix_3, cur + pix_3,
206 next + pix_3, td->w - 6,
207 y + 1 < td->h ? refs : -refs,
208 y ? -refs : refs,
209 td->parity ^ td->tff, mode);
210 s->filter_edges(dst, prev, cur, next, td->w,
211 y + 1 < td->h ? refs : -refs,
212 y ? -refs : refs,
213 td->parity ^ td->tff, mode);
214 } else {
215 memcpy(&td->frame->data[td->plane][y * td->frame->linesize[td->plane]],
216 &s->cur->data[td->plane][y * refs], td->w * df);
217 }
218 }
219 return 0;
220}
221
175static void filter(AVFilterContext *ctx, AVFrame *dstpic,222static void filter(AVFilterContext *ctx, AVFrame *dstpic,
176 int parity, int tff)223 int parity, int tff)
177{224{
178 YADIFContext *yadif = ctx->priv;225 YADIFContext *yadif = ctx->priv;
179 int y, i;226 ThreadData td = { .frame = dstpic, .parity = parity, .tff = tff };
227 int i;
180 228
181 for (i = 0; i < yadif->csp->nb_components; i++) {229 for (i = 0; i < yadif->csp->nb_components; i++) {
182 int w = dstpic->width;230 int w = dstpic->width;
183 int h = dstpic->height;231 int h = dstpic->height;
184 int refs = yadif->cur->linesize[i];
185 int df = (yadif->csp->comp[i].depth_minus1 + 8) / 8;
186 int pix_3 = 3 * df;
187 232
188 if (i == 1 || i == 2) {233 if (i == 1 || i == 2) {
189 /* Why is this not part of the per-plane description thing? */
190 w = FF_CEIL_RSHIFT(w, yadif->csp->log2_chroma_w);234 w = FF_CEIL_RSHIFT(w, yadif->csp->log2_chroma_w);
191 h = FF_CEIL_RSHIFT(h, yadif->csp->log2_chroma_h);235 h = FF_CEIL_RSHIFT(h, yadif->csp->log2_chroma_h);
192 }236 }
193 237
194 /* filtering reads 3 pixels to the left/right; to avoid invalid reads,238
195 * we need to call the c variant which avoids this for border pixels239 td.w = w;
196 */240 td.h = h;
197 241 td.plane = i;
198 for (y = 0; y < h; y++) {242
199 if ((y ^ parity) & 1) {243 ctx->internal->execute(ctx, filter_slice, &td, NULL, FFMIN(h, ctx->graph->nb_threads));
200 uint8_t *prev = &yadif->prev->data[i][y * refs];
201 uint8_t *cur = &yadif->cur ->data[i][y * refs];
202 uint8_t *next = &yadif->next->data[i][y * refs];
203 uint8_t *dst = &dstpic->data[i][y * dstpic->linesize[i]];
204 int mode = y == 1 || y + 2 == h ? 2 : yadif->mode;
205 yadif->filter_line(dst + pix_3, prev + pix_3, cur + pix_3,
206 next + pix_3, w - 6,
207 y + 1 < h ? refs : -refs,
208 y ? -refs : refs,
209 parity ^ tff, mode);
210 yadif->filter_edges(dst, prev, cur, next, w,
211 y + 1 < h ? refs : -refs,
212 y ? -refs : refs,
213 parity ^ tff, mode);
214 } else {
215 memcpy(&dstpic->data[i][y * dstpic->linesize[i]],
216 &yadif->cur->data[i][y * refs], w * df);
217 }
218 }
219 }244 }
220 245
221 emms_c();246 emms_c();
@@ -484,5 +509,5 @@ AVFilter avfilter_vf_yadif = { · 262 unmodified lines
484 509
485 .inputs = avfilter_vf_yadif_inputs,510 .inputs = avfilter_vf_yadif_inputs,
486 .outputs = avfilter_vf_yadif_outputs,511 .outputs = avfilter_vf_yadif_outputs,
487 .flags = AVFILTER_FLAG_SUPPORT_TIMELINE_INTERNAL,512 .flags = AVFILTER_FLAG_SUPPORT_TIMELINE_INTERNAL | AVFILTER_FLAG_SLICE_THREADS,
488};513};

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