[farsight2/master] Make the codec cache into its own separate module

Olivier Crête olivier.crete at collabora.co.uk
Tue Dec 23 15:19:44 PST 2008


---
 gst/fsrtpconference/fs-rtp-codec-cache.c     |   42 ++++++++++++++++----------
 gst/fsrtpconference/fs-rtp-codec-cache.h     |    4 +-
 gst/fsrtpconference/fs-rtp-discover-codecs.c |    8 ++---
 gst/fsrtpconference/fs-rtp-discover-codecs.h |    2 +
 4 files changed, 33 insertions(+), 23 deletions(-)

diff --git a/gst/fsrtpconference/fs-rtp-codec-cache.c b/gst/fsrtpconference/fs-rtp-codec-cache.c
index 1a2a338..abf53b5 100644
--- a/gst/fsrtpconference/fs-rtp-codec-cache.c
+++ b/gst/fsrtpconference/fs-rtp-codec-cache.c
@@ -145,9 +145,9 @@ read_codec_blueprint_string (gchar **in, gsize *size, gchar **str) {
 }
 
 
-#define READ_CHECK(x) if(!x) return FALSE;
+#define READ_CHECK(x) if(!x) goto error;
 
-static gboolean
+static CodecBlueprint *
 load_codec_blueprint (FsMediaType media_type, gchar **in, gsize *size) {
   CodecBlueprint *codec_blueprint = g_new0 (CodecBlueprint, 1);
   gchar *tmp;
@@ -213,15 +213,17 @@ load_codec_blueprint (FsMediaType media_type, gchar **in, gsize *size) {
   READ_CHECK (read_codec_blueprint_int
       (in, size, &(codec_blueprint->receive_has_unique)));
 
-  /* insert new information into tables */
-  list_codec_blueprints[media_type] = g_list_append (
-      list_codec_blueprints[media_type], codec_blueprint);
   g_debug ("adding codec %s with pt %d, send_pipeline %p, receive_pipeline %p",
       codec_blueprint->codec->encoding_name, codec_blueprint->codec->id,
       codec_blueprint->send_pipeline_factory,
       codec_blueprint->receive_pipeline_factory);
 
-  return TRUE;
+  return codec_blueprint;
+
+ error:
+  codec_blueprint_destroy (codec_blueprint);
+
+  return NULL;
 }
 
 
@@ -234,7 +236,7 @@ load_codec_blueprint (FsMediaType media_type, gchar **in, gsize *size) {
  * Returns : TRUE if successful, FALSE if error, or cache outdated
  *
  */
-gboolean
+GList *
 load_codecs_cache (FsMediaType media_type)
 {
   GMappedFile *mapped = NULL;
@@ -242,7 +244,7 @@ load_codecs_cache (FsMediaType media_type)
   gchar *in = NULL;
   gsize size;
   GError *err = NULL;
-  gboolean ret = FALSE;
+  GList *blueprints = NULL;
 
   gchar magic[8] = {0};
   gchar magic_media = '?';
@@ -324,13 +326,21 @@ load_codecs_cache (FsMediaType media_type)
   size -= sizeof(gint);
 
   for (i = 0; i < num_blueprints; i++) {
-    if (!load_codec_blueprint (media_type, &in, &size)) {
+    CodecBlueprint *blueprint = load_codec_blueprint (media_type, &in, &size);
+    if (!blueprint) {
       g_warning ("Problem reading codecs cache. File corrupt");
+
+      if (blueprints) {
+        g_list_foreach (blueprints, (GFunc) codec_blueprint_destroy, NULL);
+        g_list_free (blueprints);
+        blueprints = NULL;
+      }
+
       goto error;
     }
+    blueprints = g_list_prepend (blueprints, blueprint);
   }
 
-  ret = TRUE;
  error:
   if (mapped) {
     g_mapped_file_free (mapped);
@@ -338,8 +348,7 @@ load_codecs_cache (FsMediaType media_type)
     g_free (contents);
   }
   g_free (cache_path);
-  return ret;
-
+  return blueprints;
 }
 
 #define WRITE_CHECK(x) if(!x) return FALSE;
@@ -427,8 +436,8 @@ save_codec_blueprint (int fd, CodecBlueprint *codec_blueprint) {
 }
 
 
-static gboolean
-save_codecs_cache(FsMediaType media_type)
+gboolean
+save_codecs_cache(FsMediaType media_type, GList *blueprints)
 {
   gchar *cache_path;
   GList *item;
@@ -487,12 +496,13 @@ save_codecs_cache(FsMediaType media_type)
     return FALSE;
 
 
-  size = g_list_length (list_codec_blueprints[media_type]);
+  size = g_list_length (blueprints);
   if (write (fd, &size, sizeof(gint)) != sizeof(gint))
     return FALSE;
 
 
-  for (item = list_codec_blueprints[media_type]; item;
+  for (item = g_list_first (blueprints);
+       item;
        item = g_list_next (item)) {
     CodecBlueprint *codec_blueprint = item->data;
     if (!save_codec_blueprint (fd, codec_blueprint)) {
diff --git a/gst/fsrtpconference/fs-rtp-codec-cache.h b/gst/fsrtpconference/fs-rtp-codec-cache.h
index 2dd501c..0aa582e 100644
--- a/gst/fsrtpconference/fs-rtp-codec-cache.h
+++ b/gst/fsrtpconference/fs-rtp-codec-cache.h
@@ -31,8 +31,8 @@
 
 G_BEGIN_DECLS
 
-gboolean load_codecs_cache(FsMediaType media_type);
-void save_codecs_cache(FsMediaType media_type);
+GList *load_codecs_cache(FsMediaType media_type);
+gboolean save_codecs_cache(FsMediaType media_type, GList *codec_blueprints);
 
 
 G_END_DECLS
diff --git a/gst/fsrtpconference/fs-rtp-discover-codecs.c b/gst/fsrtpconference/fs-rtp-discover-codecs.c
index 1dfe096..9f13680 100644
--- a/gst/fsrtpconference/fs-rtp-discover-codecs.c
+++ b/gst/fsrtpconference/fs-rtp-discover-codecs.c
@@ -77,7 +77,6 @@ static GList *list_codec_blueprints[FS_MEDIA_TYPE_LAST+1] = { NULL };
 static gint codecs_lists_ref[FS_MEDIA_TYPE_LAST+1] = { 0 };
 
 
-
 static void
 debug_pipeline (GList *pipeline)
 {
@@ -271,7 +270,7 @@ load_codecs (FsMediaType media_type)
     codec_cap_list_free (send_list);
 
   /* Save the codecs blueprint cache */
-  save_codecs_cache(media_type);
+  save_codecs_cache(media_type, list_codec_blueprints[media_type]);
 
   return ret;
 }
@@ -876,10 +875,9 @@ codec_cap_list_intersect (GList *list1, GList *list2)
 }
 
 
-static void
-codec_blueprint_destroy (gpointer data)
+void
+codec_blueprint_destroy (CodecBlueprint *codec_blueprint)
 {
-  CodecBlueprint *codec_blueprint = data;
   GList *walk;
 
   if (codec_blueprint->codec)
diff --git a/gst/fsrtpconference/fs-rtp-discover-codecs.h b/gst/fsrtpconference/fs-rtp-discover-codecs.h
index a6a3b5c..e8ac978 100644
--- a/gst/fsrtpconference/fs-rtp-discover-codecs.h
+++ b/gst/fsrtpconference/fs-rtp-discover-codecs.h
@@ -50,6 +50,8 @@ typedef struct _CodecBlueprint
 gboolean load_codecs (FsMediaType media_type);
 void unload_codecs (FsMediaType media_type);
 
+void codec_blueprint_destroy (CodecBlueprint *codec_blueprint);
+
 
 
 G_END_DECLS
-- 
1.5.6.5




More information about the farsight-commits mailing list