[FFmpeg-soc] [soc]: r4616 - in concat/libavformat: Makefile.diff datanode.c datanode.h

gkovacs subversion at mplayerhq.hu
Sun Jul 5 20:47:23 CEST 2009


Author: gkovacs
Date: Sun Jul  5 20:47:22 2009
New Revision: 4616

Log:
added datanode for ini (pls) file parsing

Modified:
   concat/libavformat/Makefile.diff
   concat/libavformat/datanode.c
   concat/libavformat/datanode.h

Modified: concat/libavformat/Makefile.diff
==============================================================================
--- concat/libavformat/Makefile.diff	Sun Jul  5 20:46:17 2009	(r4615)
+++ concat/libavformat/Makefile.diff	Sun Jul  5 20:47:22 2009	(r4616)
@@ -1,12 +1,12 @@
 diff --git a/libavformat/Makefile b/libavformat/Makefile
-index 8e8a869..adb8d8e 100644
+index 8e8a869..23074a7 100644
 --- a/libavformat/Makefile
 +++ b/libavformat/Makefile
 @@ -175,6 +175,7 @@ OBJS-$(CONFIG_PCM_U32LE_DEMUXER)         += raw.o
  OBJS-$(CONFIG_PCM_U32LE_MUXER)           += raw.o
  OBJS-$(CONFIG_PCM_U8_DEMUXER)            += raw.o
  OBJS-$(CONFIG_PCM_U8_MUXER)              += raw.o
-+OBJS-$(CONFIG_CONCAT_DEMUXER)            += m3u.o playlist.o concat.o concatgen.o
++OBJS-$(CONFIG_CONCAT_DEMUXER)            += m3u.o playlist.o concat.o concatgen.o datanode.o
  OBJS-$(CONFIG_PSP_MUXER)                 += movenc.o riff.o isom.o avc.o
  OBJS-$(CONFIG_PVA_DEMUXER)               += pva.o
  OBJS-$(CONFIG_QCP_DEMUXER)               += qcp.o

Modified: concat/libavformat/datanode.c
==============================================================================
--- concat/libavformat/datanode.c	Sun Jul  5 20:46:17 2009	(r4615)
+++ concat/libavformat/datanode.c	Sun Jul  5 20:47:22 2009	(r4616)
@@ -1,2 +1,202 @@
+/*
+ * Library to parse and represent ini (and later xml) files
+ * Copyright (c) 2009 Geza Kovacs
+ *
+ * This file is part of FFmpeg.
+ *
+ * FFmpeg is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * FFmpeg is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with FFmpeg; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+
+#include "datanode.h"
+
+DataNode *ff_datanode_mkchild(DataNode *o)
+{
+    DataNode *d = av_malloc(sizeof(*d));
+    memset(d, 0, sizeof(*d));
+    o->child = d;
+    d->parent = o;
+    return d;
+}
+
+DataNode *ff_datanode_mknext(DataNode *o)
+{
+    DataNode *d = av_malloc(sizeof(*d));
+    memset(d, 0, sizeof(*d));
+    o->next = d;
+    d->prev = o;
+    d->parent = o->parent;
+    return d;
+}
+
+DataNode *ff_datanode_tree_from_ini(char *p)
+{
+    char c;
+    char *s;
+    char e;
+    int i, b;
+    DataNode *o;
+    DataNode *d;
+    d = av_malloc(sizeof(*d));
+    memset(d, 0, sizeof(*d));
+    o = d;
+    s = d->name;
+    e = 1;
+    i = b = 0;
+    for (; (c = *p++); ) {
+        if (c == '\n') {
+            d = ff_datanode_mknext(d);
+            i = b = 0;
+            s = d->name;
+            e = 1;
+            continue;
+        }
+        if (!e) {
+            continue;
+        }
+        if (c == '#') {
+            e = 0;
+            continue;
+        }
+        if (c == '[') {
+            if (d->parent) {
+                d = d->parent;
+            }
+            d = ff_datanode_mknext(d);
+            i = b = 0;
+            s = d->name;
+            continue;
+        }
+        if (c == ']') {
+            d = ff_datanode_mkchild(d);
+            i = b = 0;
+            s = d->name;
+            continue;
+        }
+        if (c == '=') {
+            i = b = 0;
+            s = d->value;
+            continue;
+        }
+        if (i >= b-1) {
+            b += DATANODE_STR_BUFSIZE;
+            if (s == d->name) {
+                s = av_realloc(s, b);
+                d->name = s;
+            }
+            else if (s == d->value) {
+                s = av_realloc(s, b);
+                d->value = s;
+            }
+        }
+        s[i++] = c;
+        s[i] = 0;
+    }
+    return o;
+}
+
+DataNode *ff_datanode_tree_from_ini(char *p)
+{
+    // TODO
+    return NULL;
+}
+
+DataNode *ff_datanode_getlognext(DataNode *d)
+{
+    if (d->child)
+        return d->child;
+    if (d->next)
+        return d->next;
+    while ((d = d->parent)) {
+        if (d->next)
+            return d->next;
+    }
+    return NULL;
+}
+
+void ff_datanode_filter_names_by_value(DataNode *d, StringList *l, char *v)
+{
+    if (!d)
+        return;
+    if (d->value && !strncmp(v, d->value, strlen(v)))
+        ff_stringlist_append(l, d->name);
+    ff_datanode_filter_names_by_value(ff_datanode_getlognext(d), l, v);
+}
+
+void ff_datanode_filter_values_by_name(DataNode *d, StringList *l, char *n)
+{
+    if (!d)
+        return;
+    if (d->value && !strncmp(n, d->name, strlen(n)))
+        ff_stringlist_append(l, d->value);
+    ff_datanode_filter_values_by_name(ff_datanode_getlognext(d), l, n);
+}
+
+int ff_datanode_getdepth(DataNode *d)
+{
+    int i = 0;
+    while ((d = d->parent))
+        ++i;
+    return i;
+}
+
+void ff_datanode_visualize(DataNode *d)
+{
+    int i, depth;
+    if (!d)
+        return;
+    depth = ff_datanode_getdepth(d);
+    for (i = 0; i < depth; ++i)
+        putchar('>');
+    printf("name: ");
+    if (d->name)
+        printf("%s", d->name);
+    putchar('\n');
+    for (i = 0; i < depth; ++i)
+        putchar('>');
+    printf("value: ");
+    if (d->value)
+        printf("%s", d->value);
+    putchar('\n');
+    ff_datanode_visualize(ff_datanode_getlognext(d));
+}
+
+StringList *ff_stringlist_alloc()
+{
+    StringList *l = av_malloc(sizeof(*l));
+    memset(l, 0, sizeof(*l));
+    return l;
+}
 
+void ff_stringlist_append(StringList *l, char *str)
+{
+    while (l->next)
+        l = l->next;
+    if (l->str) {
+        l->next = ff_stringlist_alloc();
+        l->next->str = str;
+    } else
+        l->str = str;
+}
 
+void ff_stringlist_print(StringList *l)
+{
+    if (!l)
+        return;
+    printf("str: ");
+    if (l->str)
+        printf("%s", l->str);
+    putchar('\n');
+    ff_stringlist_print(l->next);
+}

Modified: concat/libavformat/datanode.h
==============================================================================
--- concat/libavformat/datanode.h	Sun Jul  5 20:46:17 2009	(r4615)
+++ concat/libavformat/datanode.h	Sun Jul  5 20:47:22 2009	(r4616)
@@ -1,2 +1,65 @@
+/*
+ * Format to represent ini (and later xml) as doubly linked 2D data nodes
+ * Copyright (c) 2009 Geza Kovacs
+ *
+ * This file is part of FFmpeg.
+ *
+ * FFmpeg is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * FFmpeg is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with FFmpeg; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+
+#ifndef AVFORMAT_DATANODE_H
+#define AVFORMAT_DATANODE_H
+
+#include "avformat.h"
 
+#define DATANODE_STR_BUFSIZE 5
 
+typedef struct DataNode {
+    char *name;
+    char *value;
+    struct DataNode *child;
+    struct DataNode *parent;
+    struct DataNode *next;
+    struct DataNode *prev;
+} DataNode;
+
+typedef struct StringList {
+    char *str;
+    struct StringList *next;
+} StringList;
+
+DataNode *ff_datanode_mkchild(DataNode *o);
+
+DataNode *ff_datanode_mknext(DataNode *o);
+
+DataNode *ff_datanode_tree_from_ini(char *p);
+
+DataNode *ff_datanode_tree_from_xml(char *p);
+
+DataNode *ff_datanode_getlognext(DataNode *d);
+
+void ff_datanode_filter_values_by_name(DataNode *d, StringList *l, char *n);
+
+int ff_datanode_getdepth(DataNode *d);
+
+void ff_datanode_visualize(DataNode *d);
+
+StringList *ff_stringlist_alloc();
+
+void ff_stringlist_append(StringList *l, char *str);
+
+void ff_stringlist_print(StringList *l);
+
+#endif /* AVFORMAT_DATANODE_H */


More information about the FFmpeg-soc mailing list