[FFmpeg-soc] [soc]: r1644 - in libavfilter: Makefile avfiltergraphdesc.c avfiltergraphfile.c

koorogi subversion at mplayerhq.hu
Sat Dec 22 18:25:22 CET 2007


Author: koorogi
Date: Sat Dec 22 18:25:22 2007
New Revision: 1644

Log:
Move file loading code to a separate file so that it can be easily disabled.


Added:
   libavfilter/avfiltergraphfile.c
      - copied, changed from r1643, /libavfilter/avfiltergraphdesc.c
Modified:
   libavfilter/Makefile
   libavfilter/avfiltergraphdesc.c

Modified: libavfilter/Makefile
==============================================================================
--- libavfilter/Makefile	(original)
+++ libavfilter/Makefile	Sat Dec 22 18:25:22 2007
@@ -20,6 +20,7 @@ OBJS-yes = vf_crop.o \
            vf_slicify.o \
            vf_split.o \
            vf_vflip.o \
+           avfiltergraphfile.o \
 
 HEADERS = avfilter.h
 

Modified: libavfilter/avfiltergraphdesc.c
==============================================================================
--- libavfilter/avfiltergraphdesc.c	(original)
+++ libavfilter/avfiltergraphdesc.c	Sat Dec 22 18:25:22 2007
@@ -1,5 +1,5 @@
 /*
- * Filter graph descriptions for file serialization
+ * Filter graph descriptions
  * copyright (c) 2007 Bobby Bingham
  *
  * This file is part of FFmpeg.
@@ -19,7 +19,6 @@
  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  */
 
-#include <stdio.h>
 #include <ctype.h>
 #include <string.h>
 
@@ -188,35 +187,6 @@ int avfilter_graph_parse_desc(AVFilterGr
     return 0;
 }
 
-AVFilterGraphDesc *avfilter_graph_load_desc(const char *filename)
-{
-    AVFilterGraphDesc       *ret    = NULL;
-    AVFilterGraphDescParser *parser = NULL;
-
-    char line[LINESIZE];
-    FILE *in = NULL;
-
-    /* TODO: maybe allow searching in a predefined set of directories to
-     * allow users to build up libraries of useful graphs? */
-    if(!(in = fopen(filename, "r")))
-        goto fail;
-
-    while(fgets(line, LINESIZE, in))
-        if(avfilter_graph_parse_desc(&ret, &parser, line) < 0)
-            goto fail;
-
-    fclose(in);
-    av_free(parser);
-    return ret;
-
-fail:
-    av_free(ret);
-    av_free(parser);
-    if(in) fclose(in);
-
-    return NULL;
-}
-
 void avfilter_graph_free_desc(AVFilterGraphDesc *desc)
 {
     void *next;

Copied: libavfilter/avfiltergraphfile.c (from r1643, /libavfilter/avfiltergraphdesc.c)
==============================================================================
--- /libavfilter/avfiltergraphdesc.c	(original)
+++ libavfilter/avfiltergraphfile.c	Sat Dec 22 18:25:22 2007
@@ -1,5 +1,5 @@
 /*
- * Filter graph descriptions for file serialization
+ * Loading filter graph descriptions from files
  * copyright (c) 2007 Bobby Bingham
  *
  * This file is part of FFmpeg.
@@ -20,174 +20,12 @@
  */
 
 #include <stdio.h>
-#include <ctype.h>
-#include <string.h>
 
 #include "avfilter.h"
 #include "avfiltergraph.h"
 
 #define LINESIZE    240             ///< maximum length of an input line
 
-/** a comment is a line which is empty, or starts with whitespace, ';' or '#' */
-static inline int is_line_comment(char *line)
-{
-    return line[0] == 0     ||
-           isspace(line[0]) ||
-           line[0] == ';'   ||
-           line[0] == '#';
-}
-
-static AVFilterGraphDescSection parse_section_name(char *line)
-{
-    struct {
-        char *str;
-        int section;
-    } *sec, sections[] = { { "[filters]", SEC_FILTERS },
-                           { "[links]",   SEC_LINKS   },
-                           { "[inputs]",  SEC_INPUTS  },
-                           { "[outputs]", SEC_OUTPUTS },
-                           { NULL, 0 } };
-
-    for(sec = sections; sec->str; sec ++)
-        if(!strncmp(line, sec->str, strlen(sec->str)))
-            return sec->section;
-
-    av_log(NULL, AV_LOG_ERROR, "unknown section name in graph description\n");
-    return SEC_NONE;
-}
-
-static AVFilterGraphDescFilter *parse_filter(char *line)
-{
-    AVFilterGraphDescFilter *ret = av_mallocz(sizeof(AVFilterGraphDescFilter));
-    char *tok;
-
-    if(!(tok = strchr(line, '='))) {
-        av_log(NULL, AV_LOG_ERROR, "filter line missing type of filter");
-        goto fail;
-    }
-    *tok = '\0';
-    ret->name = av_strdup(line);
-    line = tok+1;
-
-    if((tok = strchr(line, '='))) {
-        *tok ++ = '\0';
-        ret->args = av_strdup(tok);
-    }
-    ret->filter = av_strdup(line);
-
-    return ret;
-
-fail:
-    av_free(ret->name);
-    av_free(ret->filter);
-    av_free(ret->args);
-    av_free(ret);
-    return NULL;
-}
-
-/* TODO: allow referencing pad names, not just indices */
-static AVFilterGraphDescLink *parse_link(char *line)
-{
-    AVFilterGraphDescLink *ret = av_mallocz(sizeof(AVFilterGraphDescLink));
-    ret->src = av_malloc(32);
-    ret->dst = av_malloc(32);
-
-    if(sscanf(line, "%31[a-zA-Z0-9]:%u=%31[a-zA-Z0-9]:%u",
-              ret->src, &ret->srcpad, ret->dst, &ret->dstpad) < 4) {
-        av_free(ret->src);
-        av_free(ret->dst);
-        av_free(ret);
-        return NULL;
-    }
-
-    return ret;
-}
-
-/* TODO: allow referencing pad names, not just indices */
-static AVFilterGraphDescExport *parse_export(char *line)
-{
-    AVFilterGraphDescExport *ret = av_mallocz(sizeof(AVFilterGraphDescLink));
-    ret->name   = av_malloc(32);
-    ret->filter = av_malloc(32);
-
-    if(sscanf(line, "%31[a-zA-Z0-9]=%31[a-zA-Z0-9]:%u",
-              ret->name, ret->filter, &ret->pad) < 3) {
-        av_free(ret->name);
-        av_free(ret->filter);
-        av_free(ret);
-        return NULL;
-    }
-
-    return ret;
-}
-
-int avfilter_graph_parse_desc(AVFilterGraphDesc **desc,
-                              AVFilterGraphDescParser **parser,
-                              char *line)
-{
-    void *next;
-    int len;
-
-    if(!*desc)
-        if(!(*desc = av_mallocz(sizeof(AVFilterGraphDesc))))
-            return AVERROR_NOMEM;
-
-    if(!*parser) {
-        if(!(*parser = av_mallocz(sizeof(AVFilterGraphDescParser))))
-            return AVERROR_NOMEM;
-
-        (*parser)->filterp = &(*desc)->filters;
-        (*parser)->linkp   = &(*desc)->links;
-        (*parser)->inputp  = &(*desc)->inputs;
-        (*parser)->outputp = &(*desc)->outputs;
-    }
-
-    /* ignore comments */
-    if(is_line_comment(line)) return 0;
-
-    /* check if a new section is starting */
-    if(line[0] == '[') {
-        if(((*parser)->section = parse_section_name(line)) == SEC_NONE)
-            return AVERROR_INVALIDDATA;
-        return 0;
-    }
-
-    /* remove any trailing newline characters */
-    for(len = strlen(line); len && (line[len-1]=='\n'||line[len-1]=='\r');)
-        line[--len] = '\0';
-
-    switch((*parser)->section) {
-    case SEC_FILTERS:
-        if(!(next = parse_filter(line)))
-            return AVERROR_INVALIDDATA;
-        *(*parser)->filterp = next;
-        (*parser)->filterp  = &(*(*parser)->filterp)->next;
-        break;
-    case SEC_LINKS:
-        if(!(next = parse_link(line)))
-            return AVERROR_INVALIDDATA;
-        *(*parser)->linkp = next;
-        (*parser)->linkp  = &(*(*parser)->linkp)->next;
-        break;
-    case SEC_INPUTS:
-        if(!(next = parse_export(line)))
-            return AVERROR_INVALIDDATA;
-        *(*parser)->inputp = next;
-        (*parser)->inputp  = &(*(*parser)->inputp)->next;
-        break;
-    case SEC_OUTPUTS:
-        if(!(next = parse_export(line)))
-            return AVERROR_INVALIDDATA;
-        *(*parser)->outputp = next;
-        (*parser)->outputp  = &(*(*parser)->outputp)->next;
-        break;
-    default:
-        return AVERROR_INVALIDDATA;
-    }
-
-    return 0;
-}
-
 AVFilterGraphDesc *avfilter_graph_load_desc(const char *filename)
 {
     AVFilterGraphDesc       *ret    = NULL;
@@ -217,39 +55,3 @@ fail:
     return NULL;
 }
 
-void avfilter_graph_free_desc(AVFilterGraphDesc *desc)
-{
-    void *next;
-
-    while(desc->filters) {
-        next = desc->filters->next;
-        av_free(desc->filters->name);
-        av_free(desc->filters->filter);
-        av_free(desc->filters->args);
-        av_free(desc->filters);
-        desc->filters = next;
-    }
-
-    while(desc->links) {
-        next = desc->links->next;
-        av_free(desc->links->src);
-        av_free(desc->links->dst);
-        av_free(desc->links);
-        desc->links = next;
-    }
-
-    while(desc->inputs) {
-        next = desc->inputs->next;
-        av_free(desc->inputs->filter);
-        av_free(desc->inputs);
-        desc->inputs = next;
-    }
-
-    while(desc->outputs) {
-        next = desc->outputs->next;
-        av_free(desc->outputs->filter);
-        av_free(desc->outputs);
-        desc->outputs = next;
-    }
-}
-



More information about the FFmpeg-soc mailing list