gst/gstregistrybinary.*: use glib types, cleanup comments, impement interfaces and...
authorStefan Kost <ensonic@users.sourceforge.net>
Mon, 15 Jan 2007 12:18:46 +0000 (12:18 +0000)
committerStefan Kost <ensonic@users.sourceforge.net>
Mon, 15 Jan 2007 12:18:46 +0000 (12:18 +0000)
Original commit message from CVS:
* gst/gstregistrybinary.c: (gst_registry_binary_write),
(gst_registry_binary_initialize_magic),
(gst_registry_binary_save_string), (gst_registry_binary_make_data),
(gst_registry_binary_save_pad_template),
(gst_registry_binary_save_feature),
(gst_registry_binary_save_plugin),
(gst_registry_binary_write_cache),
(gst_registry_binary_check_magic),
(gst_registry_binary_load_pad_template),
(gst_registry_binary_load_feature),
(gst_registry_binary_load_plugin),
(gst_registry_binary_read_cache):
* gst/gstregistrybinary.h:
use glib types, cleanup comments, impement interfaces and uri-types

ChangeLog
gst/gstregistrybinary.c
gst/gstregistrybinary.h

index b616864..4d8dd91 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,20 @@
+2007-01-15  Stefan Kost  <ensonic@users.sf.net>
+
+       * gst/gstregistrybinary.c: (gst_registry_binary_write),
+       (gst_registry_binary_initialize_magic),
+       (gst_registry_binary_save_string), (gst_registry_binary_make_data),
+       (gst_registry_binary_save_pad_template),
+       (gst_registry_binary_save_feature),
+       (gst_registry_binary_save_plugin),
+       (gst_registry_binary_write_cache),
+       (gst_registry_binary_check_magic),
+       (gst_registry_binary_load_pad_template),
+       (gst_registry_binary_load_feature),
+       (gst_registry_binary_load_plugin),
+       (gst_registry_binary_read_cache):
+       * gst/gstregistrybinary.h:
+         use glib types, cleanup comments, impement interfaces and uri-types
+
 2007-01-13  Andy Wingo  <wingo@pobox.com>
 
        * gst/gstpad.c (gst_pad_get_range, gst_pad_pull_range): Allow
index 824f9a6..d8a9a71 100644 (file)
 
 /* FIXME:
  * - Add random key to libgstreamer during build and only accept registry,
- *   if key matches
+ *   if key matches (or is the version check enough)
  * - handle cases where we can't mmap
  * - keep registry binary blob and reference strings
  *   (need const flags in GstPlugin, etc.)
  * - why do we collect a list of binary chunks and not write immediately
+ *   - because we need to process subchunks, before we can set e.g. nr_of_items
+ *     in parnt chunk
  * - need more robustness
  *   - don't parse beyond mem-block size
  *   - include md5-sum ?
@@ -131,6 +133,26 @@ gst_registry_binary_save_string (GList ** list, gchar * str)
 }
 
 /*
+ * gst_registry_binary_save_data:
+ *
+ * Store some data in a binary chunk.
+ *
+ * Returns: the initialized chunk
+ */
+inline static GstBinaryChunk *
+gst_registry_binary_make_data (gpointer data, gulong size)
+{
+  GstBinaryChunk *chunk;
+
+  chunk = g_malloc (sizeof (GstBinaryChunk));
+  chunk->data = data;
+  chunk->size = size;
+  chunk->flags = GST_BINARY_REGISTRY_FLAG_NONE;
+  chunk->align = TRUE;
+  return chunk;
+}
+
+/*
  * gst_registry_binary_save_pad_template:
  *
  * Store pad_templates in binary chunks.
@@ -145,12 +167,7 @@ gst_registry_binary_save_pad_template (GList ** list,
   GstBinaryChunk *chk;
 
   pt = g_malloc (sizeof (GstBinaryPadTemplate));
-  chk = g_malloc (sizeof (GstBinaryChunk));
-
-  chk->data = pt;
-  chk->size = sizeof (GstBinaryPadTemplate);
-  chk->flags = GST_BINARY_REGISTRY_FLAG_NONE;
-  chk->align = TRUE;
+  chk = gst_registry_binary_make_data (pt, sizeof (GstBinaryPadTemplate));
 
   pt->presence = template->presence;
   pt->direction = template->direction;
@@ -186,19 +203,44 @@ gst_registry_binary_save_feature (GList ** list, GstPluginFeature * feature)
   }
 
   pf = g_malloc (sizeof (GstBinaryPluginFeature));
-  chk = g_malloc (sizeof (GstBinaryChunk));
-
-  chk->data = pf;
-  chk->size = sizeof (GstBinaryPluginFeature);
-  chk->flags = GST_BINARY_REGISTRY_FLAG_NONE;
-  chk->align = TRUE;
+  chk = gst_registry_binary_make_data (pf, sizeof (GstBinaryPluginFeature));
 
   pf->rank = feature->rank;
-  pf->npadtemplates = pf->ninterfaces = pf->nuritypes = 0;
+  pf->npadtemplates = pf->ninterfaces = pf->nuriprotocols = 0;
 
   if (GST_IS_ELEMENT_FACTORY (feature)) {
     GstElementFactory *factory = GST_ELEMENT_FACTORY (feature);
 
+    /* save interfaces */
+    for (walk = factory->interfaces; walk;
+        walk = g_list_next (walk), pf->ninterfaces++) {
+      gst_registry_binary_save_string (list, (gchar *) walk->data);
+    }
+    GST_DEBUG ("Saved %d Interfaces", pf->ninterfaces);
+    /* save uritypes */
+    if (GST_URI_TYPE_IS_VALID (factory->uri_type)) {
+      if (factory->uri_protocols) {
+        GstBinaryChunk *subchk;
+        gchar **protocol;
+
+        subchk =
+            gst_registry_binary_make_data (&factory->uri_type,
+            sizeof (factory->uri_type));
+        subchk->flags = GST_BINARY_REGISTRY_FLAG_CONST;
+
+        protocol = factory->uri_protocols;
+        while (*protocol) {
+          gst_registry_binary_save_string (list, *protocol++);
+          pf->nuriprotocols++;
+        }
+        *list = g_list_prepend (*list, subchk);
+        GST_DEBUG ("Saved %d UriTypes", pf->nuriprotocols);
+      } else {
+        g_warning ("GStreamer feature '%s' is URI handler but does not provide"
+            " any protocols it can handle", feature->name);
+      }
+    }
+
     /* save pad-templates */
     for (walk = factory->staticpadtemplates; walk;
         walk = g_list_next (walk), pf->npadtemplates++) {
@@ -215,15 +257,20 @@ gst_registry_binary_save_feature (GList ** list, GstPluginFeature * feature)
     gst_registry_binary_save_string (list, factory->details.description);
     gst_registry_binary_save_string (list, factory->details.klass);
     gst_registry_binary_save_string (list, factory->details.longname);
+  } else if (GST_IS_TYPE_FIND_FACTORY (feature)) {
+    /* FIXME: save typefind */
+  }
+#ifndef GST_DISABLE_INDEX
+  else if (GST_IS_INDEX_FACTORY (feature)) {
+    /* FIXME: save indexers */
   }
+#endif
 
   /* pack plugin feature strings */
   gst_registry_binary_save_string (list, feature->name);
   gst_registry_binary_save_string (list, (gchar *) type_name);
 
   *list = g_list_prepend (*list, chk);
-
-  /* FIXME: save interfaces and uritypes */
   return TRUE;
 
   /* Errors */
@@ -249,12 +296,7 @@ gst_registry_binary_save_plugin (GList ** list, GstRegistry * registry,
   GList *walk;
 
   pe = g_malloc (sizeof (GstBinaryPluginElement));
-  chk = g_malloc (sizeof (GstBinaryChunk));
-
-  chk->data = pe;
-  chk->size = sizeof (GstBinaryPluginElement);
-  chk->flags = GST_BINARY_REGISTRY_FLAG_NONE;
-  chk->align = TRUE;
+  chk = gst_registry_binary_make_data (pe, sizeof (GstBinaryPluginElement));
 
   pe->file_size = plugin->file_size;
   pe->file_mtime = plugin->file_mtime;
@@ -502,7 +544,7 @@ gst_registry_binary_load_feature (GstRegistry * registry, gchar ** in,
 {
   GstBinaryPluginFeature *pf;
   GstPluginFeature *feature;
-  gchar *type_name;
+  gchar *type_name = NULL, *str;
   GType type;
   guint i;
 
@@ -557,26 +599,47 @@ gst_registry_binary_load_feature (GstRegistry * registry, gchar ** in,
         goto fail;
       }
     }
-  }
 
-  gst_registry_add_feature (registry, feature);
-  GST_DEBUG ("Added feature %s", feature->name);
+    /* load uritypes */
+    if (pf->nuriprotocols) {
+      GST_DEBUG ("Reading %d UriTypes at address %p", pf->nuriprotocols, *in);
 
-  /* FIXME: handle interfaces and uritypes */
-#if 0
-  for (i = 0; i < pf->ninterfaces; i++) {
-    // read string
-    __gst_element_factory_add_interface (factory, s);
+      align32 (*in);
+      factory->uri_type = *((guint *) * in);
+      *in += sizeof (factory->uri_type);
+      //unpack_element(*in, &factory->uri_type, factory->uri_type);
+
+      factory->uri_protocols = g_new0 (gchar *, pf->nuriprotocols + 1);
+      for (i = 0; i < pf->nuriprotocols; i++) {
+        unpack_string (*in, str);
+        factory->uri_protocols[i] = str;
+      }
+    }
+    /* load interfaces */
+    GST_DEBUG ("Reading %d Interfaces at address %p", pf->ninterfaces, *in);
+    for (i = 0; i < pf->ninterfaces; i++) {
+      unpack_string (*in, str);
+      __gst_element_factory_add_interface (factory, str);
+      g_free (str);
+    }
+  } else if (GST_IS_TYPE_FIND_FACTORY (feature)) {
+    /* FIXME: load typefind */
   }
-  for (i = 0; i < pf->nuritypes; i++) {
-    // read string
-    add_to_char_array (&factory->uri_protocols, s);
+#ifndef GST_DISABLE_INDEX
+  else if (GST_IS_INDEX_FACTORY (feature)) {
+    /* FIXME: load indexers */
   }
 #endif
+
+  gst_registry_add_feature (registry, feature);
+  GST_DEBUG ("Added feature %s", feature->name);
+
+  g_free (type_name);
   return TRUE;
 
   /* Errors */
 fail:
+  g_free (type_name);
   if (GST_IS_OBJECT (feature))
     gst_object_unref (feature);
   else
@@ -718,7 +781,6 @@ gst_registry_binary_read_cache (GstRegistry * registry, const char *location)
     return TRUE;                /* empty file, this is not an error */
   }
 
-
   for (;
       ((size_t) in + sizeof (GstBinaryPluginElement)) <
       (size_t) contents + size;) {
index d71cc60..be9517a 100644 (file)
@@ -81,8 +81,8 @@
 
 typedef struct _GstBinaryRegistryMagic
 {
-  char magic[GST_MAGIC_BINARY_REGISTRY_LEN];
-  char version[GST_MAGIC_BINARY_VERSION_LEN];
+  gchar magic[GST_MAGIC_BINARY_REGISTRY_LEN];
+  gchar version[GST_MAGIC_BINARY_VERSION_LEN];
 } GstBinaryRegistryMagic;
 
 /*
@@ -94,76 +94,67 @@ enum {
   GST_BINARY_REGISTRY_FLAG_CONST = 1
 };
 
-/* GstBinaryChunk:
+/*
+ * GstBinaryChunk:
  *
  * Header for binary blobs
  */
 typedef struct _GstBinaryChunk
 {
-  void *data;
-  unsigned int size;
-  unsigned int flags;
+  gpointer data;
+  guint size;
+  guint flags;
   gboolean align;
 } GstBinaryChunk;
 
-/* A structure containing (staticely) every information needed for a plugin
-**
-** Notes :
-** "nfeatures" is used to say how many GstBinaryPluginFeature structures we will have 
-** right after the structure itself.
-*/
+/*
+ * GstBinaryPluginElement:
+ *
+ * @nfeatures: says how many GstBinaryPluginFeature structures we will have
+ * right after the structure itself.
+ *
+ * A structure containing (staticely) every information needed for a plugin
+ */
 
 typedef struct _GstBinaryPluginElement
 {
-  unsigned long file_size;
-  unsigned long file_mtime;
+  gulong file_size;
+  gulong file_mtime;
 
-  unsigned int nfeatures;
+  guint nfeatures;
 } GstBinaryPluginElement;
 
 
-/* A structure containing the plugin features
-**
-** Note :
-** "npadtemplates" is used to store the number of GstBinaryPadTemplate structures following the structure itself.
-** "ninterfaces" is used to store the number of GstBinaryInterface structures following the structure itself.
-** "nuritypes" is used to store the number of GstBinaryUriType structures following the structure itself.
-*/
+/*
+ * GstBinaryPluginFeature:
+ * @npadtemplates: stores the number of GstBinaryPadTemplate structures
+ * following the structure
+ * @ninterfaces: stores the number of interface names following the structure
+ * @nuriprotocols: stores the number of protocol strings following the structure
+ *
+ * A structure containing the plugin features
+ */
 typedef struct _GstBinaryPluginFeature
 {
-  unsigned long rank;
+  gulong rank;
 
-  unsigned int npadtemplates;
-  unsigned int ninterfaces;
-  unsigned int nuritypes;
+  guint npadtemplates;
+  guint ninterfaces;
+  guint nuriprotocols;
 } GstBinaryPluginFeature;
 
 
-/* 
-** A structure containing the static pad templates of a plugin feature 
-*/
+/*
+ * GstBinaryPadTemplate:
+ *
+ * A structure containing the static pad templates of a plugin feature 
+ */
 typedef struct _GstBinaryPadTemplate
 {
-  int direction;                      /* Either 0:"sink" or 1:"src" */
+  guint direction;                    /* Either 0:"sink" or 1:"src" */
   GstPadPresence presence;
 } GstBinaryPadTemplate;
 
-/*
-** A very simple structure defining the plugin feature interface string
-*/
-//#define GST_BINARY_REGISTRY_INTERFACE_INTERFACE_LEN (512)
-typedef struct _GstBinaryInterface
-{
-  //char interface[GST_BINARY_REGISTRY_INTERFACE_INTERFACE_LEN];
-  unsigned long size;
-} GstBinaryInterface;
-
-/* Uri Type */
-typedef struct _GstBinaryUriType
-{
-  GstURIType type;              /* GST_URI_SINK / GST_URI_SRC */
-  unsigned long nuriprotocols;
-} GstBinaryUriType;
 
 /* Function prototypes */
 gboolean gst_registry_binary_write_cache(GstRegistry *registry, const char *location);