Commit e9b992d0 authored by Anton Khirnov's avatar Anton Khirnov
Browse files

lavfi: add error handling to draw_slice().

parent ebc8d974
...@@ -295,8 +295,10 @@ struct AVFilterPad { ...@@ -295,8 +295,10 @@ struct AVFilterPad {
* and should do its processing. * and should do its processing.
* *
* Input video pads only. * Input video pads only.
*
* @return >= 0 on success, a negative AVERROR on error.
*/ */
void (*draw_slice)(AVFilterLink *link, int y, int height, int slice_dir); int (*draw_slice)(AVFilterLink *link, int y, int height, int slice_dir);
/** /**
* Samples filtering callback. This is where a filter receives audio data * Samples filtering callback. This is where a filter receives audio data
......
...@@ -100,7 +100,10 @@ static void queue_pop(FifoContext *s) ...@@ -100,7 +100,10 @@ static void queue_pop(FifoContext *s)
static void end_frame(AVFilterLink *inlink) { } static void end_frame(AVFilterLink *inlink) { }
static void draw_slice(AVFilterLink *inlink, int y, int h, int slice_dir) { } static int draw_slice(AVFilterLink *inlink, int y, int h, int slice_dir)
{
return 0;
}
/** /**
* Move data pointers and pts offset samples forward. * Move data pointers and pts offset samples forward.
......
...@@ -106,8 +106,10 @@ struct AVFilterPad { ...@@ -106,8 +106,10 @@ struct AVFilterPad {
* and should do its processing. * and should do its processing.
* *
* Input video pads only. * Input video pads only.
*
* @return >= 0 on success, a negative AVERROR on error.
*/ */
void (*draw_slice)(AVFilterLink *link, int y, int height, int slice_dir); int (*draw_slice)(AVFilterLink *link, int y, int height, int slice_dir);
/** /**
* Samples filtering callback. This is where a filter receives audio data * Samples filtering callback. This is where a filter receives audio data
......
...@@ -77,13 +77,17 @@ static int start_frame(AVFilterLink *inlink, AVFilterBufferRef *picref) ...@@ -77,13 +77,17 @@ static int start_frame(AVFilterLink *inlink, AVFilterBufferRef *picref)
return ret; return ret;
} }
static void draw_slice(AVFilterLink *inlink, int y, int h, int slice_dir) static int draw_slice(AVFilterLink *inlink, int y, int h, int slice_dir)
{ {
AVFilterContext *ctx = inlink->dst; AVFilterContext *ctx = inlink->dst;
int i; int i, ret = 0;
for (i = 0; i < ctx->nb_outputs; i++) for (i = 0; i < ctx->nb_outputs; i++) {
ff_draw_slice(ctx->outputs[i], y, h, slice_dir); ret = ff_draw_slice(ctx->outputs[i], y, h, slice_dir);
if (ret < 0)
break;
}
return ret;
} }
static void end_frame(AVFilterLink *inlink) static void end_frame(AVFilterLink *inlink)
......
...@@ -74,7 +74,7 @@ static av_cold int init(AVFilterContext *ctx, const char *args) ...@@ -74,7 +74,7 @@ static av_cold int init(AVFilterContext *ctx, const char *args)
return 0; return 0;
} }
static void draw_slice(AVFilterLink *inlink, int y, int h, int slice_dir) static int draw_slice(AVFilterLink *inlink, int y, int h, int slice_dir)
{ {
AVFilterContext *ctx = inlink->dst; AVFilterContext *ctx = inlink->dst;
BlackFrameContext *blackframe = ctx->priv; BlackFrameContext *blackframe = ctx->priv;
...@@ -88,7 +88,7 @@ static void draw_slice(AVFilterLink *inlink, int y, int h, int slice_dir) ...@@ -88,7 +88,7 @@ static void draw_slice(AVFilterLink *inlink, int y, int h, int slice_dir)
p += picref->linesize[0]; p += picref->linesize[0];
} }
ff_draw_slice(ctx->outputs[0], y, h, slice_dir); return ff_draw_slice(ctx->outputs[0], y, h, slice_dir);
} }
static void end_frame(AVFilterLink *inlink) static void end_frame(AVFilterLink *inlink)
......
...@@ -306,7 +306,7 @@ static void vblur(uint8_t *dst, int dst_linesize, const uint8_t *src, int src_li ...@@ -306,7 +306,7 @@ static void vblur(uint8_t *dst, int dst_linesize, const uint8_t *src, int src_li
h, radius, power, temp); h, radius, power, temp);
} }
static void draw_slice(AVFilterLink *inlink, int y0, int h0, int slice_dir) static int draw_slice(AVFilterLink *inlink, int y0, int h0, int slice_dir)
{ {
AVFilterContext *ctx = inlink->dst; AVFilterContext *ctx = inlink->dst;
BoxBlurContext *boxblur = ctx->priv; BoxBlurContext *boxblur = ctx->priv;
...@@ -330,7 +330,7 @@ static void draw_slice(AVFilterLink *inlink, int y0, int h0, int slice_dir) ...@@ -330,7 +330,7 @@ static void draw_slice(AVFilterLink *inlink, int y0, int h0, int slice_dir)
w[plane], h[plane], boxblur->radius[plane], boxblur->power[plane], w[plane], h[plane], boxblur->radius[plane], boxblur->power[plane],
boxblur->temp); boxblur->temp);
ff_draw_slice(outlink, y0, h0, slice_dir); return ff_draw_slice(outlink, y0, h0, slice_dir);
} }
AVFilter avfilter_vf_boxblur = { AVFilter avfilter_vf_boxblur = {
......
...@@ -297,13 +297,13 @@ static int start_frame(AVFilterLink *link, AVFilterBufferRef *picref) ...@@ -297,13 +297,13 @@ static int start_frame(AVFilterLink *link, AVFilterBufferRef *picref)
return ff_start_frame(link->dst->outputs[0], ref2); return ff_start_frame(link->dst->outputs[0], ref2);
} }
static void draw_slice(AVFilterLink *link, int y, int h, int slice_dir) static int draw_slice(AVFilterLink *link, int y, int h, int slice_dir)
{ {
AVFilterContext *ctx = link->dst; AVFilterContext *ctx = link->dst;
CropContext *crop = ctx->priv; CropContext *crop = ctx->priv;
if (y >= crop->y + crop->h || y + h <= crop->y) if (y >= crop->y + crop->h || y + h <= crop->y)
return; return 0;
if (y < crop->y) { if (y < crop->y) {
h -= crop->y - y; h -= crop->y - y;
...@@ -312,7 +312,7 @@ static void draw_slice(AVFilterLink *link, int y, int h, int slice_dir) ...@@ -312,7 +312,7 @@ static void draw_slice(AVFilterLink *link, int y, int h, int slice_dir)
if (y + h > crop->y + crop->h) if (y + h > crop->y + crop->h)
h = crop->y + crop->h - y; h = crop->y + crop->h - y;
ff_draw_slice(ctx->outputs[0], y - crop->y, h, slice_dir); return ff_draw_slice(ctx->outputs[0], y - crop->y, h, slice_dir);
} }
static void end_frame(AVFilterLink *link) static void end_frame(AVFilterLink *link)
......
...@@ -245,7 +245,10 @@ static int start_frame(AVFilterLink *inlink, AVFilterBufferRef *inpicref) ...@@ -245,7 +245,10 @@ static int start_frame(AVFilterLink *inlink, AVFilterBufferRef *inpicref)
return 0; return 0;
} }
static void null_draw_slice(AVFilterLink *link, int y, int h, int slice_dir) { } static int null_draw_slice(AVFilterLink *link, int y, int h, int slice_dir)
{
return 0;
}
static void end_frame(AVFilterLink *inlink) static void end_frame(AVFilterLink *inlink)
{ {
......
...@@ -94,7 +94,7 @@ static int config_input(AVFilterLink *inlink) ...@@ -94,7 +94,7 @@ static int config_input(AVFilterLink *inlink)
return 0; return 0;
} }
static void draw_slice(AVFilterLink *inlink, int y0, int h, int slice_dir) static int draw_slice(AVFilterLink *inlink, int y0, int h, int slice_dir)
{ {
DrawBoxContext *drawbox = inlink->dst->priv; DrawBoxContext *drawbox = inlink->dst->priv;
int plane, x, y, xb = drawbox->x, yb = drawbox->y; int plane, x, y, xb = drawbox->x, yb = drawbox->y;
...@@ -120,7 +120,7 @@ static void draw_slice(AVFilterLink *inlink, int y0, int h, int slice_dir) ...@@ -120,7 +120,7 @@ static void draw_slice(AVFilterLink *inlink, int y0, int h, int slice_dir)
} }
} }
ff_draw_slice(inlink->dst->outputs[0], y0, h, 1); return ff_draw_slice(inlink->dst->outputs[0], y0, h, 1);
} }
AVFilter avfilter_vf_drawbox = { AVFilter avfilter_vf_drawbox = {
......
...@@ -791,7 +791,10 @@ static int draw_text(AVFilterContext *ctx, AVFilterBufferRef *picref, ...@@ -791,7 +791,10 @@ static int draw_text(AVFilterContext *ctx, AVFilterBufferRef *picref,
return 0; return 0;
} }
static void null_draw_slice(AVFilterLink *link, int y, int h, int slice_dir) { } static int null_draw_slice(AVFilterLink *link, int y, int h, int slice_dir)
{
return 0;
}
static inline int normalize_double(int *n, double d) static inline int normalize_double(int *n, double d)
{ {
......
...@@ -97,7 +97,7 @@ static int config_props(AVFilterLink *inlink) ...@@ -97,7 +97,7 @@ static int config_props(AVFilterLink *inlink)
return 0; return 0;
} }
static void draw_slice(AVFilterLink *inlink, int y, int h, int slice_dir) static int draw_slice(AVFilterLink *inlink, int y, int h, int slice_dir)
{ {
FadeContext *fade = inlink->dst->priv; FadeContext *fade = inlink->dst->priv;
AVFilterBufferRef *outpic = inlink->cur_buf; AVFilterBufferRef *outpic = inlink->cur_buf;
...@@ -134,7 +134,7 @@ static void draw_slice(AVFilterLink *inlink, int y, int h, int slice_dir) ...@@ -134,7 +134,7 @@ static void draw_slice(AVFilterLink *inlink, int y, int h, int slice_dir)
} }
} }
ff_draw_slice(inlink->dst->outputs[0], y, h, slice_dir); return ff_draw_slice(inlink->dst->outputs[0], y, h, slice_dir);
} }
static void end_frame(AVFilterLink *inlink) static void end_frame(AVFilterLink *inlink)
......
...@@ -144,7 +144,7 @@ static int start_frame(AVFilterLink *inlink, AVFilterBufferRef *inpicref) ...@@ -144,7 +144,7 @@ static int start_frame(AVFilterLink *inlink, AVFilterBufferRef *inpicref)
return 0; return 0;
} }
static void draw_slice(AVFilterLink *inlink, int y, int h, int slice_dir) static int draw_slice(AVFilterLink *inlink, int y, int h, int slice_dir)
{ {
AVFilterContext *ctx = inlink->dst; AVFilterContext *ctx = inlink->dst;
FieldOrderContext *fieldorder = ctx->priv; FieldOrderContext *fieldorder = ctx->priv;
...@@ -158,8 +158,9 @@ static void draw_slice(AVFilterLink *inlink, int y, int h, int slice_dir) ...@@ -158,8 +158,9 @@ static void draw_slice(AVFilterLink *inlink, int y, int h, int slice_dir)
* and that complexity will be added later */ * and that complexity will be added later */
if ( !inpicref->video->interlaced if ( !inpicref->video->interlaced
|| inpicref->video->top_field_first == fieldorder->dst_tff) { || inpicref->video->top_field_first == fieldorder->dst_tff) {
ff_draw_slice(outlink, y, h, slice_dir); return ff_draw_slice(outlink, y, h, slice_dir);
} }
return 0;
} }
static void end_frame(AVFilterLink *inlink) static void end_frame(AVFilterLink *inlink)
......
...@@ -248,8 +248,9 @@ static int null_start_frame(AVFilterLink *link, AVFilterBufferRef *buf) ...@@ -248,8 +248,9 @@ static int null_start_frame(AVFilterLink *link, AVFilterBufferRef *buf)
return 0; return 0;
} }
static void null_draw_slice(AVFilterLink *link, int y, int h, int slice_dir) static int null_draw_slice(AVFilterLink *link, int y, int h, int slice_dir)
{ {
return 0;
} }
AVFilter avfilter_vf_fps = { AVFilter avfilter_vf_fps = {
......
...@@ -340,7 +340,10 @@ static int query_formats(AVFilterContext *ctx) ...@@ -340,7 +340,10 @@ static int query_formats(AVFilterContext *ctx)
return 0; return 0;
} }
static void null_draw_slice(AVFilterLink *inlink, int y, int h, int slice_dir) { } static int null_draw_slice(AVFilterLink *inlink, int y, int h, int slice_dir)
{
return 0;
}
static void end_frame(AVFilterLink *inlink) static void end_frame(AVFilterLink *inlink)
{ {
......
...@@ -210,7 +210,10 @@ static int start_frame(AVFilterLink *inlink, AVFilterBufferRef *inpicref) ...@@ -210,7 +210,10 @@ static int start_frame(AVFilterLink *inlink, AVFilterBufferRef *inpicref)
return 0; return 0;
} }
static void null_draw_slice(AVFilterLink *link, int y, int h, int slice_dir) { } static int null_draw_slice(AVFilterLink *link, int y, int h, int slice_dir)
{
return 0;
}
static void end_frame(AVFilterLink *inlink) static void end_frame(AVFilterLink *inlink)
{ {
......
...@@ -81,7 +81,7 @@ static int config_props(AVFilterLink *inlink) ...@@ -81,7 +81,7 @@ static int config_props(AVFilterLink *inlink)
return 0; return 0;
} }
static void draw_slice(AVFilterLink *inlink, int y, int h, int slice_dir) static int draw_slice(AVFilterLink *inlink, int y, int h, int slice_dir)
{ {
FlipContext *flip = inlink->dst->priv; FlipContext *flip = inlink->dst->priv;
AVFilterBufferRef *inpic = inlink->cur_buf; AVFilterBufferRef *inpic = inlink->cur_buf;
...@@ -142,7 +142,7 @@ static void draw_slice(AVFilterLink *inlink, int y, int h, int slice_dir) ...@@ -142,7 +142,7 @@ static void draw_slice(AVFilterLink *inlink, int y, int h, int slice_dir)
} }
} }
ff_draw_slice(inlink->dst->outputs[0], y, h, slice_dir); return ff_draw_slice(inlink->dst->outputs[0], y, h, slice_dir);
} }
AVFilter avfilter_vf_hflip = { AVFilter avfilter_vf_hflip = {
......
...@@ -290,7 +290,10 @@ static int config_input(AVFilterLink *inlink) ...@@ -290,7 +290,10 @@ static int config_input(AVFilterLink *inlink)
return 0; return 0;
} }
static void null_draw_slice(AVFilterLink *link, int y, int h, int slice_dir) { } static int null_draw_slice(AVFilterLink *link, int y, int h, int slice_dir)
{
return 0;
}
static void end_frame(AVFilterLink *inlink) static void end_frame(AVFilterLink *inlink)
{ {
......
...@@ -67,7 +67,10 @@ static int query_formats(AVFilterContext *ctx) ...@@ -67,7 +67,10 @@ static int query_formats(AVFilterContext *ctx)
return 0; return 0;
} }
static void null_draw_slice(AVFilterLink *link, int y, int h, int slice_dir) { } static int null_draw_slice(AVFilterLink *link, int y, int h, int slice_dir)
{
return 0;
}
typedef struct { typedef struct {
const char *name; const char *name;
......
...@@ -294,7 +294,7 @@ static int config_props(AVFilterLink *inlink) ...@@ -294,7 +294,7 @@ static int config_props(AVFilterLink *inlink)
return 0; return 0;
} }
static void draw_slice(AVFilterLink *inlink, int y, int h, int slice_dir) static int draw_slice(AVFilterLink *inlink, int y, int h, int slice_dir)
{ {
AVFilterContext *ctx = inlink->dst; AVFilterContext *ctx = inlink->dst;
LutContext *lut = ctx->priv; LutContext *lut = ctx->priv;
...@@ -339,7 +339,7 @@ static void draw_slice(AVFilterLink *inlink, int y, int h, int slice_dir) ...@@ -339,7 +339,7 @@ static void draw_slice(AVFilterLink *inlink, int y, int h, int slice_dir)
} }
} }
ff_draw_slice(outlink, y, h, slice_dir); return ff_draw_slice(outlink, y, h, slice_dir);
} }
static const AVFilterPad inputs[] = { static const AVFilterPad inputs[] = {
......
...@@ -320,7 +320,7 @@ static void blend_slice(AVFilterContext *ctx, ...@@ -320,7 +320,7 @@ static void blend_slice(AVFilterContext *ctx,
} }
} }
static void draw_slice(AVFilterLink *inlink, int y, int h, int slice_dir) static int draw_slice(AVFilterLink *inlink, int y, int h, int slice_dir)
{ {
AVFilterContext *ctx = inlink->dst; AVFilterContext *ctx = inlink->dst;
AVFilterLink *outlink = ctx->outputs[0]; AVFilterLink *outlink = ctx->outputs[0];
...@@ -334,7 +334,7 @@ static void draw_slice(AVFilterLink *inlink, int y, int h, int slice_dir) ...@@ -334,7 +334,7 @@ static void draw_slice(AVFilterLink *inlink, int y, int h, int slice_dir)
over->overpicref->video->w, over->overpicref->video->h, over->overpicref->video->w, over->overpicref->video->h,
y, outpicref->video->w, h); y, outpicref->video->w, h);
} }
ff_draw_slice(outlink, y, h, slice_dir); return ff_draw_slice(outlink, y, h, slice_dir);
} }
static void end_frame(AVFilterLink *inlink) static void end_frame(AVFilterLink *inlink)
...@@ -342,7 +342,10 @@ static void end_frame(AVFilterLink *inlink) ...@@ -342,7 +342,10 @@ static void end_frame(AVFilterLink *inlink)
ff_end_frame(inlink->dst->outputs[0]); ff_end_frame(inlink->dst->outputs[0]);
} }
static void null_draw_slice(AVFilterLink *inlink, int y, int h, int slice_dir) { } static int null_draw_slice(AVFilterLink *inlink, int y, int h, int slice_dir)
{
return 0;
}
static void null_end_frame(AVFilterLink *inlink) { } static void null_end_frame(AVFilterLink *inlink) { }
......
...@@ -367,10 +367,10 @@ static void end_frame(AVFilterLink *link) ...@@ -367,10 +367,10 @@ static void end_frame(AVFilterLink *link)
ff_end_frame(link->dst->outputs[0]); ff_end_frame(link->dst->outputs[0]);
} }
static void draw_send_bar_slice(AVFilterLink *link, int y, int h, int slice_dir, int before_slice) static int draw_send_bar_slice(AVFilterLink *link, int y, int h, int slice_dir, int before_slice)
{ {
PadContext *pad = link->dst->priv; PadContext *pad = link->dst->priv;
int bar_y, bar_h = 0; int bar_y, bar_h = 0, ret = 0;
if (slice_dir * before_slice == 1 && y == pad->y) { if (slice_dir * before_slice == 1 && y == pad->y) {
/* top bar */ /* top bar */
...@@ -387,15 +387,17 @@ static void draw_send_bar_slice(AVFilterLink *link, int y, int h, int slice_dir, ...@@ -387,15 +387,17 @@ static void draw_send_bar_slice(AVFilterLink *link, int y, int h, int slice_dir,
link->dst->outputs[0]->out_buf->linesize, link->dst->outputs[0]->out_buf->linesize,
pad->line, pad->line_step, pad->hsub, pad->vsub, pad->line, pad->line_step, pad->hsub, pad->vsub,
0, bar_y, pad->w, bar_h); 0, bar_y, pad->w, bar_h);
ff_draw_slice(link->dst->outputs[0], bar_y, bar_h, slice_dir); ret = ff_draw_slice(link->dst->outputs[0], bar_y, bar_h, slice_dir);
} }
return ret;
} }
static void draw_slice(AVFilterLink *link, int y, int h, int slice_dir) static int draw_slice(AVFilterLink *link, int y, int h, int slice_dir)
{ {
PadContext *pad = link->dst->priv; PadContext *pad = link->dst->priv;
AVFilterBufferRef *outpic = link->dst->outputs[0]->out_buf; AVFilterBufferRef *outpic = link->dst->outputs[0]->out_buf;
AVFilterBufferRef *inpic = link->cur_buf; AVFilterBufferRef *inpic = link->cur_buf;
int ret;
y += pad->y; y += pad->y;
...@@ -403,7 +405,7 @@ static void draw_slice(AVFilterLink *link, int y, int h, int slice_dir) ...@@ -403,7 +405,7 @@ static void draw_slice(AVFilterLink *link, int y, int h, int slice_dir)
h &= ~((1 << pad->vsub) - 1); h &= ~((1 << pad->vsub) - 1);
if (!h) if (!h)
return; return 0;
draw_send_bar_slice(link, y, h, slice_dir, 1); draw_send_bar_slice(link, y, h, slice_dir, 1);
/* left border */ /* left border */
...@@ -421,9 +423,11 @@ static void draw_slice(AVFilterLink *link, int y, int h, int slice_dir) ...@@ -421,9 +423,11 @@ static void draw_slice(AVFilterLink *link, int y, int h, int slice_dir)
ff_draw_rectangle(outpic->data, outpic->linesize, ff_draw_rectangle(outpic->data, outpic->linesize,
pad->line, pad->line_step, pad->hsub, pad->vsub, pad->line, pad->line_step, pad->hsub, pad->vsub,
pad->x + pad->in_w, y, pad->w - pad->x - pad->in_w, h); pad->x + pad->in_w, y, pad->w - pad->x - pad->in_w, h);
ff_draw_slice(link->dst->outputs[0], y, h, slice_dir); ret = ff_draw_slice(link->dst->outputs[0], y, h, slice_dir);
if (ret < 0)
return ret;
draw_send_bar_slice(link, y, h, slice_dir, -1); return draw_send_bar_slice(link, y, h, slice_dir, -1);
} }
AVFilter avfilter_vf_pad = { AVFilter avfilter_vf_pad = {
......
...@@ -90,7 +90,7 @@ static int start_frame(AVFilterLink *inlink, AVFilterBufferRef *picref) ...@@ -90,7 +90,7 @@ static int start_frame(AVFilterLink *inlink, AVFilterBufferRef *picref)
return 0; return 0;
} }
static void draw_slice(AVFilterLink *inlink, int y, int h, int slice_dir) static int draw_slice(AVFilterLink *inlink, int y, int h, int slice_dir)
{ {
PixdescTestContext *priv = inlink->dst->priv; PixdescTestContext *priv = inlink->dst->priv;
AVFilterBufferRef *inpic = inlink->cur_buf; AVFilterBufferRef *inpic = inlink->cur_buf;
...@@ -117,7 +117,7 @@ static void draw_slice(AVFilterLink *inlink, int y, int h, int slice_dir) ...@@ -117,7 +117,7 @@ static void draw_slice(AVFilterLink *inlink, int y, int h, int slice_dir)
} }
} }
ff_draw_slice(inlink->dst->outputs[0], y, h, slice_dir); return ff_draw_slice(inlink->dst->outputs[0], y, h, slice_dir);
} }
AVFilter avfilter_vf_pixdesctest = { AVFilter avfilter_vf_pixdesctest = {
......
...@@ -291,16 +291,15 @@ static int start_frame(AVFilterLink *link, AVFilterBufferRef *picref) ...@@ -291,16 +291,15 @@ static int start_frame(AVFilterLink *link, AVFilterBufferRef *picref)