Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/FFmpeg/FFmpeg.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPaul B Mahol <onemda@gmail.com>2018-05-01 16:05:43 +0300
committerPaul B Mahol <onemda@gmail.com>2018-05-01 16:05:43 +0300
commit5bfc433a6ed9ff55ad0a6b0d7745ea74bb0f1d99 (patch)
treeb850f3a834442cd28b6dcd8867a986c2efc4b615 /libavfilter/vf_neighbor.c
parentddf844d17c40fd6053f06d67d8973c302e01b61c (diff)
avfilter/vf_neighbor: add slice threading
Signed-off-by: Paul B Mahol <onemda@gmail.com>
Diffstat (limited to 'libavfilter/vf_neighbor.c')
-rw-r--r--libavfilter/vf_neighbor.c54
1 files changed, 38 insertions, 16 deletions
diff --git a/libavfilter/vf_neighbor.c b/libavfilter/vf_neighbor.c
index 1eb89c208d..12fe4b7ab7 100644
--- a/libavfilter/vf_neighbor.c
+++ b/libavfilter/vf_neighbor.c
@@ -27,6 +27,10 @@
#include "internal.h"
#include "video.h"
+typedef struct ThreadData {
+ AVFrame *in, *out;
+} ThreadData;
+
typedef struct NContext {
const AVClass *class;
int planeheight[4];
@@ -148,36 +152,31 @@ static int config_input(AVFilterLink *inlink)
return 0;
}
-static int filter_frame(AVFilterLink *inlink, AVFrame *in)
+static int filter_slice(AVFilterContext *ctx, void *arg, int jobnr, int nb_jobs)
{
- AVFilterContext *ctx = inlink->dst;
- AVFilterLink *outlink = ctx->outputs[0];
NContext *s = ctx->priv;
- AVFrame *out;
+ ThreadData *td = arg;
+ AVFrame *out = td->out;
+ AVFrame *in = td->in;
int plane, y;
- 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);
-
for (plane = 0; plane < s->nb_planes; plane++) {
const int threshold = s->threshold[plane];
const int stride = in->linesize[plane];
const int dstride = out->linesize[plane];
- const uint8_t *src = in->data[plane];
- uint8_t *dst = out->data[plane];
const int height = s->planeheight[plane];
const int width = s->planewidth[plane];
+ const int slice_start = (height * jobnr) / nb_jobs;
+ const int slice_end = (height * (jobnr+1)) / nb_jobs;
+ const uint8_t *src = (const uint8_t *)in->data[plane] + slice_start * stride;
+ uint8_t *dst = out->data[plane] + slice_start * dstride;
if (!threshold) {
- av_image_copy_plane(dst, dstride, src, stride, width, height);
+ av_image_copy_plane(dst, dstride, src, stride, width, slice_end - slice_start);
continue;
}
- for (y = 0; y < height; y++) {
+ for (y = slice_start; y < slice_end; y++) {
const int nh = y > 0;
const int ph = y < height - 1;
const uint8_t *coordinates[] = { src - nh * stride, src + 1 - nh * stride, src + 2 - nh * stride,
@@ -201,6 +200,28 @@ static int filter_frame(AVFilterLink *inlink, AVFrame *in)
}
}
+ return 0;
+}
+
+static int filter_frame(AVFilterLink *inlink, AVFrame *in)
+{
+ AVFilterContext *ctx = inlink->dst;
+ AVFilterLink *outlink = ctx->outputs[0];
+ NContext *s = ctx->priv;
+ ThreadData td;
+ AVFrame *out;
+
+ 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);
+
+ td.in = in;
+ td.out = out;
+ ctx->internal->execute(ctx, filter_slice, &td, NULL, FFMIN(s->planeheight[1], ff_filter_get_nb_threads(ctx)));
+
av_frame_free(&in);
return ff_filter_frame(outlink, out);
}
@@ -237,7 +258,8 @@ AVFilter ff_vf_##name_ = { \
.query_formats = query_formats, \
.inputs = neighbor_inputs, \
.outputs = neighbor_outputs, \
- .flags = AVFILTER_FLAG_SUPPORT_TIMELINE_GENERIC, \
+ .flags = AVFILTER_FLAG_SUPPORT_TIMELINE_GENERIC| \
+ AVFILTER_FLAG_SLICE_THREADS, \
}
#if CONFIG_EROSION_FILTER