This function merges the features of av_vsrc_buffer_add_video_buffer_ref() and av_buffersrc_buffer().
Showing the changes to libavfilter/src_buffer.c (1 of 2 files). Show all
Unified · Split
| @@ -69,8 +69,8 @@ typedef struct { · 68 unmodified lines | ||
| 69 | 69 | return AVERROR(EINVAL);\ |
| 70 | 70 | } |
| 71 | 71 | |
| 72 | −int av_vsrc_buffer_add_video_buffer_ref(AVFilterContext *buffer_filter, | |
| 73 | − AVFilterBufferRef *picref, int flags) | |
| 72 | +int av_buffersrc_add_ref(AVFilterContext *buffer_filter, | |
| 73 | + AVFilterBufferRef *picref, int flags) | |
| 74 | 74 | { |
| 75 | 75 | BufferSourceContext *c = buffer_filter->priv; |
| 76 | 76 | AVFilterLink *outlink = buffer_filter->outputs[0]; |
| @@ -88,6 +88,8 @@ int av_vsrc_buffer_add_video_buffer_ref(AVFilterContext *buffer_filter, · 11 unmodified lines | ||
| 88 | 88 | sizeof(buf))) < 0) |
| 89 | 89 | return ret; |
| 90 | 90 | |
| 91 | + if (!(flags & AV_BUFFERSRC_FLAG_NO_CHECK_FORMAT)) { | |
| 92 | + /* TODO reindent */ | |
| 91 | 93 | if (picref->video->w != c->w || picref->video->h != c->h || picref->format != c->pix_fmt) { |
| 92 | 94 | AVFilterContext *scale = buffer_filter->outputs[0]->dst; |
| 93 | 95 | AVFilterLink *link; |
| @@ -132,7 +134,11 @@ int av_vsrc_buffer_add_video_buffer_ref(AVFilterContext *buffer_filter, · 38 unmodified lines | ||
| 132 | 134 | if ((ret = link->srcpad->config_props(link)) < 0) |
| 133 | 135 | return ret; |
| 134 | 136 | } |
| 137 | + } | |
| 135 | 138 | |
| 139 | + if (flags & AV_BUFFERSRC_FLAG_NO_COPY) { | |
| 140 | + buf = picref; | |
| 141 | + } else { | |
| 136 | 142 | buf = avfilter_get_video_buffer(outlink, AV_PERM_WRITE, |
| 137 | 143 | picref->video->w, picref->video->h); |
| 138 | 144 | av_image_copy(buf->data, buf->linesize, |
| @@ -140,8 +146,11 @@ int av_vsrc_buffer_add_video_buffer_ref(AVFilterContext *buffer_filter, · 1 unmodified line | ||
| 140 | 146 | picref->format, picref->video->w, picref->video->h); |
| 141 | 147 | avfilter_copy_buffer_ref_props(buf, picref); |
| 142 | 148 | |
| 149 | + } | |
| 150 | + | |
| 143 | 151 | if ((ret = av_fifo_generic_write(c->fifo, &buf, sizeof(buf), NULL)) < 0) { |
| 144 | − avfilter_unref_buffer(buf); | |
| 152 | + if (buf != picref) | |
| 153 | + avfilter_unref_buffer(buf); | |
| 145 | 154 | return ret; |
| 146 | 155 | } |
| 147 | 156 | c->nb_failed_requests = 0; |
| @@ -149,29 +158,16 @@ int av_vsrc_buffer_add_video_buffer_ref(AVFilterContext *buffer_filter, · 1 unmodified line | ||
| 149 | 158 | return 0; |
| 150 | 159 | } |
| 151 | 160 | |
| 152 | −int av_buffersrc_buffer(AVFilterContext *s, AVFilterBufferRef *buf) | |
| 161 | +int av_vsrc_buffer_add_video_buffer_ref(AVFilterContext *buffer_filter, | |
| 162 | + AVFilterBufferRef *picref, int flags) | |
| 153 | 163 | { |
| 154 | − BufferSourceContext *c = s->priv; | |
| 155 | − int ret; | |
| 156 | − | |
| 157 | − if (!buf) { | |
| 158 | − c->eof = 1; | |
| 159 | − return 0; | |
| 160 | − } else if (c->eof) | |
| 161 | − return AVERROR(EINVAL); | |
| 162 | − | |
| 163 | − if (!av_fifo_space(c->fifo) && | |
| 164 | − (ret = av_fifo_realloc2(c->fifo, av_fifo_size(c->fifo) + | |
| 165 | − sizeof(buf))) < 0) | |
| 166 | − return ret; | |
| 167 | − | |
| 168 | −// CHECK_PARAM_CHANGE(s, c, buf->video->w, buf->video->h, buf->format); | |
| 169 | − | |
| 170 | − if ((ret = av_fifo_generic_write(c->fifo, &buf, sizeof(buf), NULL)) < 0) | |
| 171 | − return ret; | |
| 172 | − c->nb_failed_requests = 0; | |
| 164 | + return av_buffersrc_add_ref(buffer_filter, picref, 0); | |
| 165 | +} | |
| 173 | 166 | |
| 174 | − return 0; | |
| 167 | +int av_buffersrc_buffer(AVFilterContext *s, AVFilterBufferRef *buf) | |
| 168 | +{ | |
| 169 | + return av_buffersrc_add_ref(s, buf, AV_BUFFERSRC_FLAG_NO_CHECK_FORMAT | | |
| 170 | + AV_BUFFERSRC_FLAG_NO_COPY); | |
| 175 | 171 | } |
| 176 | 172 | |
| 177 | 173 | #if CONFIG_AVCODEC |