Revision 2b7defc7

View differences:

libavfilter/graphparser.c
214 214
}
215 215

  
216 216
/**
217
 * Process a link. This funcion looks for a matching label in the *inout
218
 * linked list. If none is found, it adds this link to the list.
219
 */
220
static int handle_link(char *name, AVFilterInOut **inout, int pad,
221
                       enum LinkType type, AVFilterContext *filter)
222
{
223
    AVFilterInOut *p = *inout;
224

  
225
    for (; p && strcmp(p->name, name); p = p->next);
226

  
227
    if(!p) {
228
        // First label apearence, add it to the linked list
229
        AVFilterInOut *inoutn = av_malloc(sizeof(AVFilterInOut));
230

  
231
        inoutn->name    = name;
232
        inoutn->type    = type;
233
        inoutn->filter  = filter;
234
        inoutn->pad_idx = pad;
235
        inoutn->next    = *inout;
236
        *inout = inoutn;
237
         return 0;
238
    }
239

  
240
    if(p->type == LinkTypeIn && type == LinkTypeOut) {
241
        if(link_filter(filter, pad, p->filter, p->pad_idx) < 0)
242
            goto fail;
243
    } else if(p->type == LinkTypeOut && type == LinkTypeIn) {
244
        if(link_filter(p->filter, p->pad_idx, filter, pad) < 0)
245
            goto fail;
246
    } else {
247
        av_log(&log_ctx, AV_LOG_ERROR,
248
               "Two links named '%s' are either both input or both output\n",
249
               name);
250
        goto fail;
251
    }
252

  
253
    p->filter = NULL;
254

  
255
    return 0;
256
 fail:
257
    return -1;
258
}
259

  
260

  
261
/**
217 262
 * Parse "[a1][link2] ... [etc]"
218 263
 */
219 264
static int parse_inouts(const char **buf, AVFilterInOut **inout, int pad,
220 265
                        enum LinkType type, AVFilterContext *filter)
221 266
{
222 267
    while (**buf == '[') {
223
        AVFilterInOut *inoutn = av_malloc(sizeof(AVFilterInOut));
224
        parse_link_name(buf, &inoutn->name);
268
        char *name;
225 269

  
226
        if (!inoutn->name) {
227
            av_free(inoutn);
270
        parse_link_name(buf, &name);
271

  
272
        if (!name)
228 273
            return -1;
229
        }
230 274

  
231
        inoutn->type    = type;
232
        inoutn->filter  = filter;
233
        inoutn->pad_idx = pad++;
234
        inoutn->next    = *inout;
235
        *inout = inoutn;
275
        handle_link(name, inout, pad++, type, filter);
236 276
        consume_whitespace(buf);
237 277
    }
238 278
    return pad;
......
307 347
    } while (chr == ',' || chr == ';');
308 348

  
309 349
    head = inout;
350
    // Process remaining labels. Only inputs and outputs should be left.
310 351
    for (; inout; inout = inout->next) {
311 352
        if(!inout->filter)
312 353
            continue; // Already processed
......
322 363
                goto fail;
323 364

  
324 365
        } else {
325
            AVFilterInOut *p, *src, *dst;
326
            for (p = inout->next;
327
                 p && strcmp(p->name,inout->name); p = p->next);
328

  
329
            if(!p) {
330
                av_log(&log_ctx, AV_LOG_ERROR, "Unmatched link: %s.\n",
331
                       inout->name);
366
            av_log(&log_ctx, AV_LOG_ERROR, "Unmatched link: %s.\n",
367
                   inout->name);
332 368
                goto fail;
333
            }
334

  
335
            if(p->type == LinkTypeIn && inout->type == LinkTypeOut) {
336
                src = inout;
337
                dst = p;
338
            } else if(p->type == LinkTypeOut && inout->type == LinkTypeIn) {
339
                src = p;
340
                dst = inout;
341
            } else {
342
                av_log(&log_ctx, AV_LOG_ERROR, "Two links named '%s' are either both input or both output\n",
343
                       inout->name);
344
                goto fail;
345
            }
346

  
347
            if(link_filter(src->filter, src->pad_idx, dst->filter, dst->pad_idx) < 0)
348
                goto fail;
349

  
350
            src->filter = NULL;
351
            dst->filter = NULL;
352 369
        }
353 370
    }
354 371

  

Also available in: Unified diff