Commit 1dc42050 authored by Anton Khirnov's avatar Anton Khirnov

lavfi: check all avfilter_ref_buffer() calls for errors.

parent 80e4ed27
......@@ -169,6 +169,9 @@ static int return_audio_frame(AVFilterContext *ctx)
queue_pop(s);
} else {
buf_out = avfilter_ref_buffer(head, AV_PERM_READ);
if (!buf_out)
return AVERROR(ENOMEM);
buf_out->audio->nb_samples = link->request_samples;
buffer_offset(link, head, link->request_samples);
}
......
......@@ -69,8 +69,11 @@ static int start_frame(AVFilterLink *inlink, AVFilterBufferRef *picref)
int i, ret = 0;
for (i = 0; i < ctx->nb_outputs; i++) {
ret = ff_start_frame(ctx->outputs[i],
avfilter_ref_buffer(picref, ~AV_PERM_WRITE));
AVFilterBufferRef *buf_out = avfilter_ref_buffer(picref, ~AV_PERM_WRITE);
if (!buf_out)
return AVERROR(ENOMEM);
ret = ff_start_frame(ctx->outputs[i], buf_out);
if (ret < 0)
break;
}
......@@ -126,8 +129,14 @@ static int filter_samples(AVFilterLink *inlink, AVFilterBufferRef *samplesref)
int i, ret = 0;
for (i = 0; i < ctx->nb_outputs; i++) {
ret = ff_filter_samples(inlink->dst->outputs[i],
avfilter_ref_buffer(samplesref, ~AV_PERM_WRITE));
AVFilterBufferRef *buf_out = avfilter_ref_buffer(samplesref,
~AV_PERM_WRITE);
if (!buf_out) {
ret = AVERROR(ENOMEM);
break;
}
ret = ff_filter_samples(inlink->dst->outputs[i], buf_out);
if (ret < 0)
break;
}
......
......@@ -217,7 +217,7 @@ static av_cold int init(AVFilterContext *ctx, const char *args)
static int start_frame(AVFilterLink *inlink, AVFilterBufferRef *inpicref)
{
AVFilterLink *outlink = inlink->dst->outputs[0];
AVFilterBufferRef *outpicref = NULL;
AVFilterBufferRef *outpicref = NULL, *for_next_filter;
int ret = 0;
if (inpicref->perms & AV_PERM_PRESERVE) {
......@@ -235,7 +235,12 @@ static int start_frame(AVFilterLink *inlink, AVFilterBufferRef *inpicref)
return AVERROR(ENOMEM);
}
ret = ff_start_frame(outlink, avfilter_ref_buffer(outpicref, ~0));
for_next_filter = avfilter_ref_buffer(outpicref, ~0);
if (for_next_filter)
ret = ff_start_frame(outlink, for_next_filter);
else
ret = AVERROR(ENOMEM);
if (ret < 0) {
avfilter_unref_bufferp(&outpicref);
return ret;
......
......@@ -438,13 +438,20 @@ static int source_request_frame(AVFilterLink *outlink)
{
Frei0rContext *frei0r = outlink->src->priv;
AVFilterBufferRef *picref = ff_get_video_buffer(outlink, AV_PERM_WRITE, outlink->w, outlink->h);
AVFilterBufferRef *buf_out;
int ret;
picref->video->pixel_aspect = (AVRational) {1, 1};
picref->pts = frei0r->pts++;
picref->pos = -1;
ret = ff_start_frame(outlink, avfilter_ref_buffer(picref, ~0));
buf_out = avfilter_ref_buffer(picref, ~0);
if (!buf_out) {
ret = AVERROR(ENOMEM);
goto fail;
}
ret = ff_start_frame(outlink, buf_out);
if (ret < 0)
goto fail;
......
......@@ -183,7 +183,7 @@ static int config_input(AVFilterLink *inlink)
static int start_frame(AVFilterLink *inlink, AVFilterBufferRef *inpicref)
{
AVFilterLink *outlink = inlink->dst->outputs[0];
AVFilterBufferRef *outpicref = NULL;
AVFilterBufferRef *outpicref = NULL, *for_next_filter;
int ret = 0;
if (inpicref->perms & AV_PERM_PRESERVE) {
......@@ -200,7 +200,12 @@ static int start_frame(AVFilterLink *inlink, AVFilterBufferRef *inpicref)
return AVERROR(ENOMEM);
}
ret = ff_start_frame(outlink, avfilter_ref_buffer(outpicref, ~0));
for_next_filter = avfilter_ref_buffer(outpicref, ~0);
if (for_next_filter)
ret = ff_start_frame(outlink, for_next_filter);
else
ret = AVERROR(ENOMEM);
if (ret < 0) {
avfilter_unref_bufferp(&outpicref);
return ret;
......
......@@ -213,6 +213,9 @@ static int start_frame(AVFilterLink *inlink, AVFilterBufferRef *inpicref)
AVFilterContext *ctx = inlink->dst;
OverlayContext *over = ctx->priv;
if (!outpicref)
return AVERROR(ENOMEM);
outpicref->pts = av_rescale_q(outpicref->pts, ctx->inputs[MAIN]->time_base,
ctx->outputs[0]->time_base);
......
......@@ -55,7 +55,7 @@ static int start_frame(AVFilterLink *inlink, AVFilterBufferRef *picref)
{
PixdescTestContext *priv = inlink->dst->priv;
AVFilterLink *outlink = inlink->dst->outputs[0];
AVFilterBufferRef *outpicref;
AVFilterBufferRef *outpicref, *for_next_filter;
int i, ret = 0;
outpicref = ff_get_video_buffer(outlink, AV_PERM_WRITE,
......@@ -80,7 +80,12 @@ static int start_frame(AVFilterLink *inlink, AVFilterBufferRef *picref)
priv->pix_desc->flags & PIX_FMT_PSEUDOPAL)
memcpy(outpicref->data[1], outpicref->data[1], 256*4);
ret = ff_start_frame(outlink, avfilter_ref_buffer(outpicref, ~0));
for_next_filter = avfilter_ref_buffer(outpicref, ~0);
if (for_next_filter)
ret = ff_start_frame(outlink, for_next_filter);
else
ret = AVERROR(ENOMEM);
if (ret < 0) {
avfilter_unref_bufferp(&outpicref);
return ret;
......
......@@ -256,11 +256,14 @@ static int start_frame(AVFilterLink *link, AVFilterBufferRef *picref)
{
ScaleContext *scale = link->dst->priv;
AVFilterLink *outlink = link->dst->outputs[0];
AVFilterBufferRef *outpicref;
AVFilterBufferRef *outpicref, *for_next_filter;
int ret = 0;
if (!scale->sws) {
return ff_start_frame(outlink, avfilter_ref_buffer(picref, ~0));
outpicref = avfilter_ref_buffer(picref, ~0);
if (!outpicref)
return AVERROR(ENOMEM);
return ff_start_frame(outlink, outpicref);
}
scale->hsub = av_pix_fmt_descriptors[link->format].log2_chroma_w;
......@@ -281,7 +284,12 @@ static int start_frame(AVFilterLink *link, AVFilterBufferRef *picref)
INT_MAX);
scale->slice_y = 0;
ret = ff_start_frame(outlink, avfilter_ref_buffer(outpicref, ~0));
for_next_filter = avfilter_ref_buffer(outpicref, ~0);
if (for_next_filter)
ret = ff_start_frame(outlink, for_next_filter);
else
ret = AVERROR(ENOMEM);
if (ret < 0) {
avfilter_unref_bufferp(&outpicref);
return ret;
......
......@@ -233,6 +233,7 @@ static int start_frame(AVFilterLink *inlink, AVFilterBufferRef *picref)
select->select = select_frame(inlink->dst, picref);
if (select->select) {
AVFilterBufferRef *buf_out;
/* frame was requested through poll_frame */
if (select->cache_frames) {
if (!av_fifo_space(select->pending_frames))
......@@ -243,7 +244,10 @@ static int start_frame(AVFilterLink *inlink, AVFilterBufferRef *picref)
sizeof(picref), NULL);
return 0;
}
return ff_start_frame(inlink->dst->outputs[0], avfilter_ref_buffer(picref, ~0));
buf_out = avfilter_ref_buffer(picref, ~0);
if (!buf_out)
return AVERROR(ENOMEM);
return ff_start_frame(inlink->dst->outputs[0], buf_out);
}
return 0;
......
......@@ -120,6 +120,7 @@ static int config_props_output(AVFilterLink *outlink)
static int start_frame(AVFilterLink *inlink, AVFilterBufferRef *picref)
{
AVFilterLink *outlink = inlink->dst->outputs[0];
AVFilterBufferRef *buf_out;
outlink->out_buf = ff_get_video_buffer(outlink, AV_PERM_WRITE,
outlink->w, outlink->h);
......@@ -135,7 +136,10 @@ static int start_frame(AVFilterLink *inlink, AVFilterBufferRef *picref)
outlink->out_buf->video->pixel_aspect.den = picref->video->pixel_aspect.num;
}
return ff_start_frame(outlink, avfilter_ref_buffer(outlink->out_buf, ~0));
buf_out = avfilter_ref_buffer(outlink->out_buf, ~0);
if (!buf_out)
return AVERROR(ENOMEM);
return ff_start_frame(outlink, buf_out);
}
static int end_frame(AVFilterLink *inlink)
......
......@@ -70,6 +70,9 @@ static int start_frame(AVFilterLink *link, AVFilterBufferRef *inpicref)
AVFilterBufferRef *outpicref = avfilter_ref_buffer(inpicref, ~0);
int i;
if (!outpicref)
return AVERROR(ENOMEM);
for (i = 0; i < 4; i ++) {
int vsub = i == 1 || i == 2 ? flip->vsub : 0;
......
......@@ -224,14 +224,18 @@ static int start_frame(AVFilterLink *link, AVFilterBufferRef *picref)
if (yadif->auto_enable && !yadif->cur->video->interlaced) {
yadif->out = avfilter_ref_buffer(yadif->cur, AV_PERM_READ);
if (!yadif->out)
return AVERROR(ENOMEM);
avfilter_unref_bufferp(&yadif->prev);
if (yadif->out->pts != AV_NOPTS_VALUE)
yadif->out->pts *= 2;
return ff_start_frame(ctx->outputs[0], yadif->out);
}
if (!yadif->prev)
yadif->prev = avfilter_ref_buffer(yadif->cur, AV_PERM_READ);
if (!yadif->prev &&
!(yadif->prev = avfilter_ref_buffer(yadif->cur, AV_PERM_READ)))
return AVERROR(ENOMEM);
yadif->out = ff_get_video_buffer(ctx->outputs[0], AV_PERM_WRITE | AV_PERM_PRESERVE |
AV_PERM_REUSE, link->w, link->h);
......@@ -282,6 +286,9 @@ static int request_frame(AVFilterLink *link)
if (ret == AVERROR_EOF && yadif->next) {
AVFilterBufferRef *next = avfilter_ref_buffer(yadif->next, AV_PERM_READ);
if (!next)
return AVERROR(ENOMEM);
next->pts = yadif->next->pts * 2 - yadif->cur->pts;
start_frame(link->src->inputs[0], next);
......
......@@ -176,12 +176,17 @@ static int default_start_frame(AVFilterLink *inlink, AVFilterBufferRef *picref)
outlink = inlink->dst->outputs[0];
if (outlink) {
AVFilterBufferRef *buf_out;
outlink->out_buf = ff_get_video_buffer(outlink, AV_PERM_WRITE, outlink->w, outlink->h);
if (!outlink->out_buf)
return AVERROR(ENOMEM);
avfilter_copy_buffer_ref_props(outlink->out_buf, picref);
return ff_start_frame(outlink, avfilter_ref_buffer(outlink->out_buf, ~0));
buf_out = avfilter_ref_buffer(outlink->out_buf, ~0);
if (!buf_out)
return AVERROR(ENOMEM);
return ff_start_frame(outlink, buf_out);
}
return 0;
}
......
......@@ -142,13 +142,20 @@ static int color_request_frame(AVFilterLink *link)
{
ColorContext *color = link->src->priv;
AVFilterBufferRef *picref = ff_get_video_buffer(link, AV_PERM_WRITE, color->w, color->h);
AVFilterBufferRef *buf_out;
int ret;
picref->video->pixel_aspect = (AVRational) {1, 1};
picref->pts = color->pts++;
picref->pos = -1;
ret = ff_start_frame(link, avfilter_ref_buffer(picref, ~0));
buf_out = avfilter_ref_buffer(picref, ~0);
if (!buf_out) {
ret = AVERROR(ENOMEM);
goto fail;
}
ret = ff_start_frame(link, buf_out);
if (ret < 0)
goto fail;
......
......@@ -289,6 +289,11 @@ static int request_frame(AVFilterLink *outlink)
return ret;
outpicref = avfilter_ref_buffer(movie->picref, ~0);
if (!outpicref) {
ret = AVERROR(ENOMEM);
goto fail;
}
ret = ff_start_frame(outlink, outpicref);
if (ret < 0)
goto fail;
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment