lavfi: add error handling to end_frame().

This commit is contained in:
Anton Khirnov 2012-07-14 09:25:33 +02:00
parent e9b992d035
commit d4f89906e3
26 changed files with 126 additions and 76 deletions

View File

@ -287,8 +287,10 @@ struct AVFilterPad {
* in the link structure during start_frame().
*
* Input video pads only.
*
* @return >= 0 on success, a negative AVERROR on error.
*/
void (*end_frame)(AVFilterLink *link);
int (*end_frame)(AVFilterLink *link);
/**
* Slice drawing callback. This is where a filter receives video data

View File

@ -98,7 +98,10 @@ static void queue_pop(FifoContext *s)
s->root.next = tmp;
}
static void end_frame(AVFilterLink *inlink) { }
static int end_frame(AVFilterLink *inlink)
{
return 0;
}
static int draw_slice(AVFilterLink *inlink, int y, int h, int slice_dir)
{

View File

@ -98,8 +98,10 @@ struct AVFilterPad {
* in the link structure during start_frame().
*
* Input video pads only.
*
* @return >= 0 on success, a negative AVERROR on error.
*/
void (*end_frame)(AVFilterLink *link);
int (*end_frame)(AVFilterLink *link);
/**
* Slice drawing callback. This is where a filter receives video data

View File

@ -90,13 +90,17 @@ static int draw_slice(AVFilterLink *inlink, int y, int h, int slice_dir)
return ret;
}
static void end_frame(AVFilterLink *inlink)
static int end_frame(AVFilterLink *inlink)
{
AVFilterContext *ctx = inlink->dst;
int i;
int i, ret = 0;
for (i = 0; i < ctx->nb_outputs; i++)
ff_end_frame(ctx->outputs[i]);
for (i = 0; i < ctx->nb_outputs; i++) {
ret = ff_end_frame(ctx->outputs[i]);
if (ret < 0)
break;
}
return ret;
}
AVFilter avfilter_vf_split = {

View File

@ -91,7 +91,7 @@ static int draw_slice(AVFilterLink *inlink, int y, int h, int slice_dir)
return ff_draw_slice(ctx->outputs[0], y, h, slice_dir);
}
static void end_frame(AVFilterLink *inlink)
static int end_frame(AVFilterLink *inlink)
{
AVFilterContext *ctx = inlink->dst;
BlackFrameContext *blackframe = ctx->priv;
@ -106,7 +106,7 @@ static void end_frame(AVFilterLink *inlink)
blackframe->frame++;
blackframe->nblack = 0;
ff_end_frame(inlink->dst->outputs[0]);
return ff_end_frame(inlink->dst->outputs[0]);
}
AVFilter avfilter_vf_blackframe = {

View File

@ -315,12 +315,12 @@ static int draw_slice(AVFilterLink *link, int y, int h, int slice_dir)
return ff_draw_slice(ctx->outputs[0], y - crop->y, h, slice_dir);
}
static void end_frame(AVFilterLink *link)
static int end_frame(AVFilterLink *link)
{
CropContext *crop = link->dst->priv;
crop->var_values[VAR_N] += 1.0;
ff_end_frame(link->dst->outputs[0]);
return ff_end_frame(link->dst->outputs[0]);
}
AVFilter avfilter_vf_crop = {

View File

@ -114,7 +114,7 @@ static int config_input(AVFilterLink *inlink)
return 0;
}
static void end_frame(AVFilterLink *inlink)
static int end_frame(AVFilterLink *inlink)
{
AVFilterContext *ctx = inlink->dst;
CropDetectContext *cd = ctx->priv;
@ -191,7 +191,7 @@ static void end_frame(AVFilterLink *inlink)
w, h, x, y);
}
ff_end_frame(inlink->dst->outputs[0]);
return ff_end_frame(inlink->dst->outputs[0]);
}
AVFilter avfilter_vf_cropdetect = {

View File

@ -250,7 +250,7 @@ static int null_draw_slice(AVFilterLink *link, int y, int h, int slice_dir)
return 0;
}
static void end_frame(AVFilterLink *inlink)
static int end_frame(AVFilterLink *inlink)
{
DelogoContext *delogo = inlink->dst->priv;
AVFilterLink *outlink = inlink->dst->outputs[0];
@ -260,6 +260,7 @@ static void end_frame(AVFilterLink *inlink)
int hsub0 = av_pix_fmt_descriptors[inlink->format].log2_chroma_w;
int vsub0 = av_pix_fmt_descriptors[inlink->format].log2_chroma_h;
int plane;
int ret;
for (plane = 0; plane < 4 && inpicref->data[plane]; plane++) {
int hsub = plane == 1 || plane == 2 ? hsub0 : 0;
@ -274,8 +275,10 @@ static void end_frame(AVFilterLink *inlink)
delogo->show, direct);
}
ff_draw_slice(outlink, 0, inlink->h, 1);
ff_end_frame(outlink);
if ((ret = ff_draw_slice(outlink, 0, inlink->h, 1)) < 0 ||
(ret = ff_end_frame(outlink)) < 0)
return ret;
return 0;
}
AVFilter avfilter_vf_delogo = {

View File

@ -860,19 +860,22 @@ static int start_frame(AVFilterLink *inlink, AVFilterBufferRef *inpicref)
return ff_start_frame(inlink->dst->outputs[0], buf_out);
}
static void end_frame(AVFilterLink *inlink)
static int end_frame(AVFilterLink *inlink)
{
AVFilterLink *outlink = inlink->dst->outputs[0];
AVFilterBufferRef *picref = inlink->cur_buf;
DrawTextContext *dtext = inlink->dst->priv;
int ret;
if (dtext->draw)
draw_text(inlink->dst, picref, picref->video->w, picref->video->h);
dtext->var_values[VAR_N] += 1.0;
ff_draw_slice(outlink, 0, picref->video->h, 1);
ff_end_frame(outlink);
if ((ret = ff_draw_slice(outlink, 0, picref->video->h, 1)) < 0 ||
(ret = ff_end_frame(outlink)) < 0)
return ret;
return 0;
}
AVFilter avfilter_vf_drawtext = {

View File

@ -137,17 +137,20 @@ static int draw_slice(AVFilterLink *inlink, int y, int h, int slice_dir)
return ff_draw_slice(inlink->dst->outputs[0], y, h, slice_dir);
}
static void end_frame(AVFilterLink *inlink)
static int end_frame(AVFilterLink *inlink)
{
FadeContext *fade = inlink->dst->priv;
int ret;
ff_end_frame(inlink->dst->outputs[0]);
ret = ff_end_frame(inlink->dst->outputs[0]);
if (fade->frame_index >= fade->start_frame &&
fade->frame_index <= fade->stop_frame)
fade->factor += fade->fade_per_frame;
fade->factor = av_clip_uint16(fade->factor);
fade->frame_index++;
return ret;
}
AVFilter avfilter_vf_fade = {

View File

@ -163,7 +163,7 @@ static int draw_slice(AVFilterLink *inlink, int y, int h, int slice_dir)
return 0;
}
static void end_frame(AVFilterLink *inlink)
static int end_frame(AVFilterLink *inlink)
{
AVFilterContext *ctx = inlink->dst;
FieldOrderContext *fieldorder = ctx->priv;
@ -227,7 +227,7 @@ static void end_frame(AVFilterLink *inlink)
"not interlaced or field order already correct\n");
}
ff_end_frame(outlink);
return ff_end_frame(outlink);
}
AVFilter avfilter_vf_fieldorder = {

View File

@ -166,14 +166,14 @@ static int write_to_fifo(AVFifoBuffer *fifo, AVFilterBufferRef *buf)
return 0;
}
static void end_frame(AVFilterLink *inlink)
static int end_frame(AVFilterLink *inlink)
{
AVFilterContext *ctx = inlink->dst;
FPSContext *s = ctx->priv;
AVFilterLink *outlink = ctx->outputs[0];
AVFilterBufferRef *buf = inlink->cur_buf;
int64_t delta;
int i;
int i, ret;
inlink->cur_buf = NULL;
s->frames_in++;
@ -188,13 +188,12 @@ static void end_frame(AVFilterLink *inlink)
avfilter_unref_buffer(buf);
s->drop++;
}
return;
return 0;
}
/* now wait for the next timestamp */
if (buf->pts == AV_NOPTS_VALUE) {
write_to_fifo(s->fifo, buf);
return;
return write_to_fifo(s->fifo, buf);
}
/* number of output frames */
@ -211,10 +210,10 @@ static void end_frame(AVFilterLink *inlink)
av_fifo_generic_read(s->fifo, &tmp, sizeof(tmp), NULL);
flush_fifo(s->fifo);
write_to_fifo(s->fifo, tmp);
ret = write_to_fifo(s->fifo, tmp);
avfilter_unref_buffer(buf);
return;
return ret;
}
/* can output >= 1 frames */
@ -239,8 +238,10 @@ static void end_frame(AVFilterLink *inlink)
}
flush_fifo(s->fifo);
write_to_fifo(s->fifo, buf);
ret = write_to_fifo(s->fifo, buf);
s->pts = s->first_pts + av_rescale_q(s->frames_out, outlink->time_base, inlink->time_base);
return ret;
}
static int null_start_frame(AVFilterLink *link, AVFilterBufferRef *buf)

View File

@ -345,18 +345,21 @@ static int null_draw_slice(AVFilterLink *inlink, int y, int h, int slice_dir)
return 0;
}
static void end_frame(AVFilterLink *inlink)
static int end_frame(AVFilterLink *inlink)
{
Frei0rContext *frei0r = inlink->dst->priv;
AVFilterLink *outlink = inlink->dst->outputs[0];
AVFilterBufferRef *inpicref = inlink->cur_buf;
AVFilterBufferRef *outpicref = outlink->out_buf;
int ret;
frei0r->update(frei0r->instance, inpicref->pts * av_q2d(inlink->time_base) * 1000,
(const uint32_t *)inpicref->data[0],
(uint32_t *)outpicref->data[0]);
ff_draw_slice(outlink, 0, outlink->h, 1);
ff_end_frame(outlink);
if ((ret = ff_draw_slice(outlink, 0, outlink->h, 1)) ||
(ret = ff_end_frame(outlink)) < 0)
return ret;
return 0;
}
AVFilter avfilter_vf_frei0r = {

View File

@ -215,13 +215,13 @@ static int null_draw_slice(AVFilterLink *link, int y, int h, int slice_dir)
return 0;
}
static void end_frame(AVFilterLink *inlink)
static int end_frame(AVFilterLink *inlink)
{
GradFunContext *gf = inlink->dst->priv;
AVFilterBufferRef *inpic = inlink->cur_buf;
AVFilterLink *outlink = inlink->dst->outputs[0];
AVFilterBufferRef *outpic = outlink->out_buf;
int p;
int p, ret;
for (p = 0; p < 4 && inpic->data[p]; p++) {
int w = inlink->w;
@ -239,8 +239,10 @@ static void end_frame(AVFilterLink *inlink)
av_image_copy_plane(outpic->data[p], outpic->linesize[p], inpic->data[p], inpic->linesize[p], w, h);
}
ff_draw_slice(outlink, 0, inlink->h, 1);
ff_end_frame(outlink);
if ((ret = ff_draw_slice(outlink, 0, inlink->h, 1)) < 0 ||
(ret = ff_end_frame(outlink)) < 0)
return ret;
return 0;
}
AVFilter avfilter_vf_gradfun = {

View File

@ -295,7 +295,7 @@ static int null_draw_slice(AVFilterLink *link, int y, int h, int slice_dir)
return 0;
}
static void end_frame(AVFilterLink *inlink)
static int end_frame(AVFilterLink *inlink)
{
HQDN3DContext *hqdn3d = inlink->dst->priv;
AVFilterLink *outlink = inlink->dst->outputs[0];
@ -303,6 +303,7 @@ static void end_frame(AVFilterLink *inlink)
AVFilterBufferRef *outpic = outlink->out_buf;
int cw = inpic->video->w >> hqdn3d->hsub;
int ch = inpic->video->h >> hqdn3d->vsub;
int ret;
deNoise(inpic->data[0], outpic->data[0],
hqdn3d->Line, &hqdn3d->Frame[0], inpic->video->w, inpic->video->h,
@ -323,8 +324,10 @@ static void end_frame(AVFilterLink *inlink)
hqdn3d->Coefs[2],
hqdn3d->Coefs[3]);
ff_draw_slice(outlink, 0, inpic->video->h, 1);
ff_end_frame(outlink);
if ((ret = ff_draw_slice(outlink, 0, inpic->video->h, 1)) < 0 ||
(ret = ff_end_frame(outlink)) < 0)
return ret;
return 0;
}
AVFilter avfilter_vf_hqdn3d = {

View File

@ -354,7 +354,7 @@ static av_cold void uninit(AVFilterContext *ctx)
memset(ocv, 0, sizeof(*ocv));
}
static void end_frame(AVFilterLink *inlink)
static int end_frame(AVFilterLink *inlink)
{
AVFilterContext *ctx = inlink->dst;
OCVContext *ocv = ctx->priv;
@ -362,14 +362,17 @@ static void end_frame(AVFilterLink *inlink)
AVFilterBufferRef *inpicref = inlink ->cur_buf;
AVFilterBufferRef *outpicref = outlink->out_buf;
IplImage inimg, outimg;
int ret;
fill_iplimage_from_picref(&inimg , inpicref , inlink->format);
fill_iplimage_from_picref(&outimg, outpicref, inlink->format);
ocv->end_frame_filter(ctx, &inimg, &outimg);
fill_picref_from_iplimage(outpicref, &outimg, inlink->format);
ff_draw_slice(outlink, 0, outlink->h, 1);
ff_end_frame(outlink);
if ((ret = ff_draw_slice(outlink, 0, outlink->h, 1)) < 0 ||
(ret = ff_end_frame(outlink)) < 0)
return ret;
return 0;
}
AVFilter avfilter_vf_ocv = {

View File

@ -337,9 +337,9 @@ static int draw_slice(AVFilterLink *inlink, int y, int h, int slice_dir)
return ff_draw_slice(outlink, y, h, slice_dir);
}
static void end_frame(AVFilterLink *inlink)
static int end_frame(AVFilterLink *inlink)
{
ff_end_frame(inlink->dst->outputs[0]);
return ff_end_frame(inlink->dst->outputs[0]);
}
static int null_draw_slice(AVFilterLink *inlink, int y, int h, int slice_dir)
@ -347,7 +347,10 @@ static int null_draw_slice(AVFilterLink *inlink, int y, int h, int slice_dir)
return 0;
}
static void null_end_frame(AVFilterLink *inlink) { }
static int null_end_frame(AVFilterLink *inlink)
{
return 0;
}
static int poll_frame(AVFilterLink *link)
{

View File

@ -362,9 +362,9 @@ fail:
return ret;
}
static void end_frame(AVFilterLink *link)
static int end_frame(AVFilterLink *link)
{
ff_end_frame(link->dst->outputs[0]);
return ff_end_frame(link->dst->outputs[0]);
}
static int draw_send_bar_slice(AVFilterLink *link, int y, int h, int slice_dir, int before_slice)

View File

@ -258,15 +258,16 @@ static int draw_slice(AVFilterLink *inlink, int y, int h, int slice_dir)
return 0;
}
static void end_frame(AVFilterLink *inlink)
static int end_frame(AVFilterLink *inlink)
{
SelectContext *select = inlink->dst->priv;
if (select->select) {
if (select->cache_frames)
return;
ff_end_frame(inlink->dst->outputs[0]);
return 0;
return ff_end_frame(inlink->dst->outputs[0]);
}
return 0;
}
static int request_frame(AVFilterLink *outlink)

View File

@ -40,7 +40,7 @@ static av_cold int init(AVFilterContext *ctx, const char *args)
return 0;
}
static void end_frame(AVFilterLink *inlink)
static int end_frame(AVFilterLink *inlink)
{
AVFilterContext *ctx = inlink->dst;
ShowInfoContext *showinfo = ctx->priv;
@ -76,7 +76,7 @@ static void end_frame(AVFilterLink *inlink)
checksum, plane_checksum[0], plane_checksum[1], plane_checksum[2], plane_checksum[3]);
showinfo->frame++;
ff_end_frame(inlink->dst->outputs[0]);
return ff_end_frame(inlink->dst->outputs[0]);
}
AVFilter avfilter_vf_showinfo = {

View File

@ -138,13 +138,13 @@ static int start_frame(AVFilterLink *inlink, AVFilterBufferRef *picref)
return ff_start_frame(outlink, avfilter_ref_buffer(outlink->out_buf, ~0));
}
static void end_frame(AVFilterLink *inlink)
static int end_frame(AVFilterLink *inlink)
{
TransContext *trans = inlink->dst->priv;
AVFilterBufferRef *inpic = inlink->cur_buf;
AVFilterBufferRef *outpic = inlink->dst->outputs[0]->out_buf;
AVFilterLink *outlink = inlink->dst->outputs[0];
int plane;
int plane, ret;
for (plane = 0; outpic->data[plane]; plane++) {
int hsub = plane == 1 || plane == 2 ? trans->hsub : 0;
@ -195,8 +195,10 @@ static void end_frame(AVFilterLink *inlink)
}
}
ff_draw_slice(outlink, 0, outpic->video->h, 1);
ff_end_frame(outlink);
if ((ret = ff_draw_slice(outlink, 0, outpic->video->h, 1)) < 0 ||
(ret = ff_end_frame(outlink)) < 0)
return ret;
return 0;
}
AVFilter avfilter_vf_transpose = {

View File

@ -213,20 +213,23 @@ static av_cold void uninit(AVFilterContext *ctx)
free_filter_param(&unsharp->chroma);
}
static void end_frame(AVFilterLink *link)
static int end_frame(AVFilterLink *link)
{
UnsharpContext *unsharp = link->dst->priv;
AVFilterBufferRef *in = link->cur_buf;
AVFilterBufferRef *out = link->dst->outputs[0]->out_buf;
int cw = SHIFTUP(link->w, unsharp->hsub);
int ch = SHIFTUP(link->h, unsharp->vsub);
int ret;
apply_unsharp(out->data[0], out->linesize[0], in->data[0], in->linesize[0], link->w, link->h, &unsharp->luma);
apply_unsharp(out->data[1], out->linesize[1], in->data[1], in->linesize[1], cw, ch, &unsharp->chroma);
apply_unsharp(out->data[2], out->linesize[2], in->data[2], in->linesize[2], cw, ch, &unsharp->chroma);
ff_draw_slice(link->dst->outputs[0], 0, link->h, 1);
ff_end_frame(link->dst->outputs[0]);
if ((ret = ff_draw_slice(link->dst->outputs[0], 0, link->h, 1)) < 0 ||
(ret = ff_end_frame(link->dst->outputs[0])) < 0)
return ret;
return 0;
}
static int draw_slice(AVFilterLink *link, int y, int h, int slice_dir)

View File

@ -240,21 +240,23 @@ static int start_frame(AVFilterLink *link, AVFilterBufferRef *picref)
return ff_start_frame(ctx->outputs[0], yadif->out);
}
static void end_frame(AVFilterLink *link)
static int end_frame(AVFilterLink *link)
{
AVFilterContext *ctx = link->dst;
YADIFContext *yadif = ctx->priv;
if (!yadif->out)
return;
return 0;
if (yadif->auto_enable && !yadif->cur->video->interlaced) {
ff_draw_slice(ctx->outputs[0], 0, link->h, 1);
ff_end_frame(ctx->outputs[0]);
return;
int ret = ff_draw_slice(ctx->outputs[0], 0, link->h, 1);
if (ret >= 0)
ret = ff_end_frame(ctx->outputs[0]);
return ret;
}
return_frame(ctx, 0);
return 0;
}
static int request_frame(AVFilterLink *link)

View File

@ -234,12 +234,12 @@ int ff_start_frame(AVFilterLink *link, AVFilterBufferRef *picref)
return ret;
}
void ff_null_end_frame(AVFilterLink *link)
int ff_null_end_frame(AVFilterLink *link)
{
ff_end_frame(link->dst->outputs[0]);
return ff_end_frame(link->dst->outputs[0]);
}
static void default_end_frame(AVFilterLink *inlink)
static int default_end_frame(AVFilterLink *inlink)
{
AVFilterLink *outlink = NULL;
@ -247,20 +247,24 @@ static void default_end_frame(AVFilterLink *inlink)
outlink = inlink->dst->outputs[0];
if (outlink) {
ff_end_frame(outlink);
return ff_end_frame(outlink);
}
return 0;
}
void ff_end_frame(AVFilterLink *link)
int ff_end_frame(AVFilterLink *link)
{
void (*end_frame)(AVFilterLink *);
int (*end_frame)(AVFilterLink *);
int ret;
if (!(end_frame = link->dstpad->end_frame))
end_frame = default_end_frame;
end_frame(link);
ret = end_frame(link);
clear_link(link);
return ret;
}
int ff_null_draw_slice(AVFilterLink *link, int y, int h, int slice_dir)

View File

@ -41,7 +41,7 @@ AVFilterBufferRef *ff_get_video_buffer(AVFilterLink *link, int perms,
int ff_null_start_frame(AVFilterLink *link, AVFilterBufferRef *picref);
int ff_null_draw_slice(AVFilterLink *link, int y, int h, int slice_dir);
void ff_null_end_frame(AVFilterLink *link);
int ff_null_end_frame(AVFilterLink *link);
/**
* Notify the next filter of the start of a frame.
@ -61,8 +61,10 @@ int ff_start_frame(AVFilterLink *link, AVFilterBufferRef *picref);
* Notify the next filter that the current frame has finished.
*
* @param link the output link the frame was sent over
*
* @return >= 0 on success, a negative AVERROR on error
*/
void ff_end_frame(AVFilterLink *link);
int ff_end_frame(AVFilterLink *link);
/**
* Send a slice to the next filter.

View File

@ -24,8 +24,9 @@ static int start_frame(AVFilterLink *link, AVFilterBufferRef *picref)
return 0;
}
static void end_frame(AVFilterLink *link)
static int end_frame(AVFilterLink *link)
{
return 0;
}
AVFilter avfilter_vsink_nullsink = {