Browse Source

buffersrc: handle non-refcounted frames in av_buffersrc_add_frame() correctly

tags/n2.2-rc1
Anton Khirnov 12 years ago
parent
commit
104a97beaf
1 changed files with 15 additions and 3 deletions
  1. +15
    -3
      libavfilter/buffersrc.c

+ 15
- 3
libavfilter/buffersrc.c View File

@@ -94,7 +94,7 @@ int attribute_align_arg av_buffersrc_add_frame(AVFilterContext *ctx,
{
BufferSourceContext *s = ctx->priv;
AVFrame *copy;
int ret;
int refcounted, ret;

if (!frame) {
s->eof = 1;
@@ -102,6 +102,8 @@ int attribute_align_arg av_buffersrc_add_frame(AVFilterContext *ctx,
} else if (s->eof)
return AVERROR(EINVAL);

refcounted = !!frame->buf[0];

switch (ctx->outputs[0]->type) {
case AVMEDIA_TYPE_VIDEO:
CHECK_VIDEO_PARAM_CHANGE(ctx, s, frame->width, frame->height,
@@ -122,10 +124,20 @@ int attribute_align_arg av_buffersrc_add_frame(AVFilterContext *ctx,

if (!(copy = av_frame_alloc()))
return AVERROR(ENOMEM);
av_frame_move_ref(copy, frame);

if (refcounted) {
av_frame_move_ref(copy, frame);
} else {
ret = av_frame_ref(copy, frame);
if (ret < 0) {
av_frame_free(&copy);
return ret;
}
}

if ((ret = av_fifo_generic_write(s->fifo, &copy, sizeof(copy), NULL)) < 0) {
av_frame_move_ref(frame, copy);
if (refcounted)
av_frame_move_ref(frame, copy);
av_frame_free(&copy);
return ret;
}


Loading…
Cancel
Save