This will make merging the check with the audio part easier.
Showing the changes to libavfilter/src_buffer.c (1 of 1 file). Show all
Unified · Split
| @@ -69,27 +69,12 @@ typedef struct { · 68 unmodified lines | ||
| 69 | 69 | return AVERROR(EINVAL);\ |
| 70 | 70 | } |
| 71 | 71 | |
| 72 | −int av_buffersrc_add_ref(AVFilterContext *buffer_filter, | |
| 73 | − AVFilterBufferRef *picref, int flags) | |
| 72 | +static int check_format_change_video(AVFilterContext *buffer_filter, | |
| 73 | + AVFilterBufferRef *picref) | |
| 74 | 74 | { |
| 75 | 75 | BufferSourceContext *c = buffer_filter->priv; |
| 76 | − AVFilterLink *outlink = buffer_filter->outputs[0]; | |
| 77 | − AVFilterBufferRef *buf; | |
| 78 | 76 | int ret; |
| 79 | 77 | |
| 80 | − if (!picref) { | |
| 81 | − c->eof = 1; | |
| 82 | − return 0; | |
| 83 | − } else if (c->eof) | |
| 84 | − return AVERROR(EINVAL); | |
| 85 | − | |
| 86 | − if (!av_fifo_space(c->fifo) && | |
| 87 | − (ret = av_fifo_realloc2(c->fifo, av_fifo_size(c->fifo) + | |
| 88 | − sizeof(buf))) < 0) | |
| 89 | − return ret; | |
| 90 | − | |
| 91 | − if (!(flags & AV_BUFFERSRC_FLAG_NO_CHECK_FORMAT)) { | |
| 92 | − /* TODO reindent */ | |
| 93 | 78 | if (picref->video->w != c->w || picref->video->h != c->h || picref->format != c->pix_fmt) { |
| 94 | 79 | AVFilterContext *scale = buffer_filter->outputs[0]->dst; |
| 95 | 80 | AVFilterLink *link; |
| @@ -134,8 +119,44 @@ int av_buffersrc_add_ref(AVFilterContext *buffer_filter, · 38 unmodified lines | ||
| 134 | 119 | if ((ret = link->srcpad->config_props(link)) < 0) |
| 135 | 120 | return ret; |
| 136 | 121 | } |
| 122 | + return 0; | |
| 123 | +} | |
| 124 | + | |
| 125 | +static int check_format_change(AVFilterContext *buffer_filter, | |
| 126 | + AVFilterBufferRef *picref) | |
| 127 | +{ | |
| 128 | + switch (buffer_filter->outputs[0]->type) { | |
| 129 | + case AVMEDIA_TYPE_VIDEO: | |
| 130 | + return check_format_change_video(buffer_filter, picref); | |
| 131 | + default: | |
| 132 | + return AVERROR(ENOSYS); | |
| 137 | 133 | } |
| 134 | +} | |
| 135 | + | |
| 136 | +int av_buffersrc_add_ref(AVFilterContext *buffer_filter, | |
| 137 | + AVFilterBufferRef *picref, int flags) | |
| 138 | +{ | |
| 139 | + BufferSourceContext *c = buffer_filter->priv; | |
| 140 | + AVFilterLink *outlink = buffer_filter->outputs[0]; | |
| 141 | + AVFilterBufferRef *buf; | |
| 142 | + int ret; | |
| 138 | 143 | |
| 144 | + if (!picref) { | |
| 145 | + c->eof = 1; | |
| 146 | + return 0; | |
| 147 | + } else if (c->eof) | |
| 148 | + return AVERROR(EINVAL); | |
| 149 | + | |
| 150 | + if (!av_fifo_space(c->fifo) && | |
| 151 | + (ret = av_fifo_realloc2(c->fifo, av_fifo_size(c->fifo) + | |
| 152 | + sizeof(buf))) < 0) | |
| 153 | + return ret; | |
| 154 | + | |
| 155 | + if (!(flags & AV_BUFFERSRC_FLAG_NO_CHECK_FORMAT)) { | |
| 156 | + ret = check_format_change(buffer_filter, picref); | |
| 157 | + if (ret < 0) | |
| 158 | + return ret; | |
| 159 | + } | |
| 139 | 160 | if (flags & AV_BUFFERSRC_FLAG_NO_COPY) { |
| 140 | 161 | buf = picref; |
| 141 | 162 | } else { |