This will make merging with the audio part easier.
Unified · Split
| @@ -133,11 +133,33 @@ static int check_format_change(AVFilterContext *buffer_filter, · 132 unmodified lines | ||
| 133 | 133 | } |
| 134 | 134 | } |
| 135 | 135 | |
| 136 | +static AVFilterBufferRef *copy_buffer_ref(AVFilterContext *ctx, | |
| 137 | + AVFilterBufferRef *ref) | |
| 138 | +{ | |
| 139 | + AVFilterLink *outlink = ctx->outputs[0]; | |
| 140 | + AVFilterBufferRef *buf; | |
| 141 | + | |
| 142 | + switch (outlink->type) { | |
| 143 | + | |
| 144 | + case AVMEDIA_TYPE_VIDEO: | |
| 145 | + buf = avfilter_get_video_buffer(outlink, AV_PERM_WRITE, | |
| 146 | + ref->video->w, ref->video->h); | |
| 147 | + av_image_copy(buf->data, buf->linesize, | |
| 148 | + (void*)ref->data, ref->linesize, | |
| 149 | + ref->format, ref->video->w, ref->video->h); | |
| 150 | + break; | |
| 151 | + | |
| 152 | + default: | |
| 153 | + return NULL; | |
| 154 | + } | |
| 155 | + avfilter_copy_buffer_ref_props(buf, ref); | |
| 156 | + return buf; | |
| 157 | +} | |
| 158 | + | |
| 136 | 159 | int av_buffersrc_add_ref(AVFilterContext *buffer_filter, |
| 137 | 160 | AVFilterBufferRef *picref, int flags) |
| 138 | 161 | { |
| 139 | 162 | BufferSourceContext *c = buffer_filter->priv; |
| 140 | − AVFilterLink *outlink = buffer_filter->outputs[0]; | |
| 141 | 163 | AVFilterBufferRef *buf; |
| 142 | 164 | int ret; |
| 143 | 165 | |
| @@ -157,17 +179,10 @@ int av_buffersrc_add_ref(AVFilterContext *buffer_filter, · 13 unmodified lines | ||
| 157 | 179 | if (ret < 0) |
| 158 | 180 | return ret; |
| 159 | 181 | } |
| 160 | − if (flags & AV_BUFFERSRC_FLAG_NO_COPY) { | |
| 182 | + if (flags & AV_BUFFERSRC_FLAG_NO_COPY) | |
| 161 | 183 | buf = picref; |
| 162 | − } else { | |
| 163 | − buf = avfilter_get_video_buffer(outlink, AV_PERM_WRITE, | |
| 164 | − picref->video->w, picref->video->h); | |
| 165 | − av_image_copy(buf->data, buf->linesize, | |
| 166 | − (void*)picref->data, picref->linesize, | |
| 167 | − picref->format, picref->video->w, picref->video->h); | |
| 168 | − avfilter_copy_buffer_ref_props(buf, picref); | |
| 169 | − | |
| 170 | − } | |
| 184 | + else | |
| 185 | + buf = copy_buffer_ref(buffer_filter, picref); | |
| 171 | 186 | |
| 172 | 187 | if ((ret = av_fifo_generic_write(c->fifo, &buf, sizeof(buf), NULL)) < 0) { |
| 173 | 188 | if (buf != picref) |