Showing the changes to libavfilter (1 of 1 file). Show all
Unified · Split
| @@ -94,7 +94,7 @@ int attribute_align_arg av_buffersrc_add_frame(AVFilterContext *ctx, · 93 unmodified lines | ||
| 94 | 94 | { |
| 95 | 95 | BufferSourceContext *s = ctx->priv; |
| 96 | 96 | AVFrame *copy; |
| 97 | − int ret; | |
| 97 | + int refcounted, ret; | |
| 98 | 98 | |
| 99 | 99 | if (!frame) { |
| 100 | 100 | s->eof = 1; |
| @@ -102,6 +102,8 @@ int attribute_align_arg av_buffersrc_add_frame(AVFilterContext *ctx, · 1 unmodified line | ||
| 102 | 102 | } else if (s->eof) |
| 103 | 103 | return AVERROR(EINVAL); |
| 104 | 104 | |
| 105 | + refcounted = !!frame->buf[0]; | |
| 106 | + | |
| 105 | 107 | switch (ctx->outputs[0]->type) { |
| 106 | 108 | case AVMEDIA_TYPE_VIDEO: |
| 107 | 109 | CHECK_VIDEO_PARAM_CHANGE(ctx, s, frame->width, frame->height, |
| @@ -122,10 +124,20 @@ int attribute_align_arg av_buffersrc_add_frame(AVFilterContext *ctx, · 14 unmodified lines | ||
| 122 | 124 | |
| 123 | 125 | if (!(copy = av_frame_alloc())) |
| 124 | 126 | return AVERROR(ENOMEM); |
| 125 | − av_frame_move_ref(copy, frame); | |
| 127 | + | |
| 128 | + if (refcounted) { | |
| 129 | + av_frame_move_ref(copy, frame); | |
| 130 | + } else { | |
| 131 | + ret = av_frame_ref(copy, frame); | |
| 132 | + if (ret < 0) { | |
| 133 | + av_frame_free(©); | |
| 134 | + return ret; | |
| 135 | + } | |
| 136 | + } | |
| 126 | 137 | |
| 127 | 138 | if ((ret = av_fifo_generic_write(s->fifo, ©, sizeof(copy), NULL)) < 0) { |
| 128 | − av_frame_move_ref(frame, copy); | |
| 139 | + if (refcounted) | |
| 140 | + av_frame_move_ref(frame, copy); | |
| 129 | 141 | av_frame_free(©); |
| 130 | 142 | return ret; |
| 131 | 143 | } |