History

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

Anton Khirnov committed 12 years ago

Commit 104a97b1 parent 5ef11b81 file · +15 −3Browse files

Showing the changes to libavfilter (1 of 1 file). Show all

Unified · Split

libavfilter/buffersrc.c+15−3
@@ -94,7 +94,7 @@ int attribute_align_arg av_buffersrc_add_frame(AVFilterContext *ctx, · 93 unmodified lines
9494 {
9595 BufferSourceContext *s = ctx->priv;
9696 AVFrame *copy;
97− int ret;
97+ int refcounted, ret;
9898
9999 if (!frame) {
100100 s->eof = 1;
@@ -102,6 +102,8 @@ int attribute_align_arg av_buffersrc_add_frame(AVFilterContext *ctx, · 1 unmodified line
102102 } else if (s->eof)
103103 return AVERROR(EINVAL);
104104
105+ refcounted = !!frame->buf[0];
106+
105107 switch (ctx->outputs[0]->type) {
106108 case AVMEDIA_TYPE_VIDEO:
107109 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
122124
123125 if (!(copy = av_frame_alloc()))
124126 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(&copy);
134+ return ret;
135+ }
136+ }
126137
127138 if ((ret = av_fifo_generic_write(s->fifo, &copy, sizeof(copy), NULL)) < 0) {
128− av_frame_move_ref(frame, copy);
139+ if (refcounted)
140+ av_frame_move_ref(frame, copy);
129141 av_frame_free(&copy);
130142 return ret;
131143 }

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t