| 147 | } |
| 148 | |
| 149 | int avfilter_link(AVFilterContext *src, unsigned srcpad, |
| 150 | AVFilterContext *dst, unsigned dstpad) |
| 151 | { |
| 152 | FilterLinkInternal *li; |
| 153 | AVFilterLink *link; |
| 154 | |
| 155 | av_assert0(src->graph); |
| 156 | av_assert0(dst->graph); |
| 157 | av_assert0(src->graph == dst->graph); |
| 158 | |
| 159 | if (src->nb_outputs <= srcpad || dst->nb_inputs <= dstpad || |
| 160 | src->outputs[srcpad] || dst->inputs[dstpad]) |
| 161 | return AVERROR(EINVAL); |
| 162 | |
| 163 | if (!(fffilterctx(src)->state_flags & AV_CLASS_STATE_INITIALIZED) || |
| 164 | !(fffilterctx(dst)->state_flags & AV_CLASS_STATE_INITIALIZED)) { |
| 165 | av_log(src, AV_LOG_ERROR, "Filters must be initialized before linking.\n"); |
| 166 | return AVERROR(EINVAL); |
| 167 | } |
| 168 | |
| 169 | if (src->output_pads[srcpad].type != dst->input_pads[dstpad].type) { |
| 170 | av_log(src, AV_LOG_ERROR, |
| 171 | "Media type mismatch between the '%s' filter output pad %d (%s) and the '%s' filter input pad %d (%s)\n", |
| 172 | src->name, srcpad, (char *)av_x_if_null(av_get_media_type_string(src->output_pads[srcpad].type), "?"), |
| 173 | dst->name, dstpad, (char *)av_x_if_null(av_get_media_type_string(dst-> input_pads[dstpad].type), "?")); |
| 174 | return AVERROR(EINVAL); |
| 175 | } |
| 176 | |
| 177 | li = av_mallocz(sizeof(*li)); |
| 178 | if (!li) |
| 179 | return AVERROR(ENOMEM); |
| 180 | link = &li->l.pub; |
| 181 | |
| 182 | src->outputs[srcpad] = dst->inputs[dstpad] = link; |
| 183 | |
| 184 | link->src = src; |
| 185 | link->dst = dst; |
| 186 | link->srcpad = &src->output_pads[srcpad]; |
| 187 | link->dstpad = &dst->input_pads[dstpad]; |
| 188 | link->type = src->output_pads[srcpad].type; |
| 189 | li->l.graph = src->graph; |
| 190 | av_assert0(AV_PIX_FMT_NONE == -1 && AV_SAMPLE_FMT_NONE == -1); |
| 191 | link->format = -1; |
| 192 | link->colorspace = AVCOL_SPC_UNSPECIFIED; |
| 193 | ff_framequeue_init(&li->fifo, &fffiltergraph(src->graph)->frame_queues); |
| 194 | |
| 195 | return 0; |
| 196 | } |
| 197 | |
| 198 | static void link_free(AVFilterLink **link) |
| 199 | { |
no test coverage detected