Revision cf4f7d38 libavfilter/graphparser.c

View differences:

libavfilter/graphparser.c
199 199
}
200 200

  
201 201
/**
202
 * Process a link. This funcion looks for a matching label in the *inout
203
 * linked list. If none is found, it adds this link to the list.
204
 */
205
static int handle_link(char *name, AVFilterInOut **inout, int pad,
206
                       enum LinkType type, AVFilterContext *filter,
207
                       AVClass *log_ctx)
208
{
209
    AVFilterInOut *p = *inout;
210

  
211
    for (; p && strcmp(p->name, name); p = p->next);
212

  
213
    if(!p) {
214
        // First label apearence, add it to the linked list
215
        AVFilterInOut *inoutn = av_malloc(sizeof(AVFilterInOut));
216

  
217
        inoutn->name    = name;
218
        inoutn->type    = type;
219
        inoutn->filter  = filter;
220
        inoutn->pad_idx = pad;
221
        inoutn->next    = *inout;
222
        *inout = inoutn;
223
         return 0;
224
    }
225

  
226
    if(p->type == LinkTypeIn && type == LinkTypeOut) {
227
        if(link_filter(filter, pad, p->filter, p->pad_idx, log_ctx) < 0)
228
            return -1;
229
    } else if(p->type == LinkTypeOut && type == LinkTypeIn) {
230
        if(link_filter(p->filter, p->pad_idx, filter, pad, log_ctx) < 0)
231
            return -1;
232
    } else {
233
        av_log(log_ctx, AV_LOG_ERROR,
234
               "Two links named '%s' are either both input or both output\n",
235
               name);
236
        return -1;
237
    }
238

  
239
    p->filter = NULL;
240

  
241
    return 0;
242
}
243

  
244

  
245
/**
246 202
 * Parse "[a1][link2] ... [etc]"
247 203
 */
248 204
static int parse_inouts(const char **buf, AVFilterInOut **inout, int pad,
......
251 207
{
252 208
    while (**buf == '[') {
253 209
        char *name;
210
        AVFilterInOut *p = *inout;
254 211

  
255 212
        parse_link_name(buf, &name, log_ctx);
256 213

  
257 214
        if(!name)
258 215
            return -1;
259 216

  
260
        if(handle_link(name, inout, pad++, type, filter, log_ctx) < 0)
261
            return -1;
217
        for (; p && strcmp(p->name, name); p = p->next);
218

  
219
        if(!p) {
220
            // First label apearence, add it to the linked list
221
            AVFilterInOut *inoutn = av_malloc(sizeof(AVFilterInOut));
222

  
223
            inoutn->name    = name;
224
            inoutn->type    = type;
225
            inoutn->filter  = filter;
226
            inoutn->pad_idx = pad;
227
            inoutn->next    = *inout;
228
            *inout = inoutn;
229
        } else {
262 230

  
231
            if(p->type == LinkTypeIn && type == LinkTypeOut) {
232
                if(link_filter(filter, pad, p->filter, p->pad_idx, log_ctx) < 0)
233
                    return -1;
234
            } else if(p->type == LinkTypeOut && type == LinkTypeIn) {
235
                if(link_filter(p->filter, p->pad_idx, filter, pad, log_ctx) < 0)
236
                    return -1;
237
            } else {
238
                av_log(log_ctx, AV_LOG_ERROR,
239
                       "Two links named '%s' are either both input or both output\n",
240
                       name);
241
                return -1;
242
            }
243

  
244
            p->filter = NULL;
245
        }
246

  
247
        pad++;
263 248
        consume_whitespace(buf);
264 249
    }
250

  
265 251
    return pad;
266 252
}
267 253

  

Also available in: Unified diff