Merge branch 'master' into 0.11
[platform/upstream/gstreamer.git] / gst / gstpluginloader.c
index e748e69..6ac9b60 100644 (file)
@@ -61,12 +61,14 @@ static gboolean plugin_loader_free (GstPluginLoader * loader);
 static gboolean plugin_loader_load (GstPluginLoader * loader,
     const gchar * filename, off_t file_size, time_t file_mtime);
 
+/* functions used in GstRegistry scanning */
 const GstPluginLoaderFuncs _priv_gst_plugin_loader_funcs = {
   plugin_loader_new, plugin_loader_free, plugin_loader_load
 };
 
 typedef struct _PendingPluginEntry
 {
+  /* sequence number */
   guint32 tag;
   gchar *filename;
   off_t file_size;
@@ -92,6 +94,7 @@ struct _GstPluginLoader
   guint tx_buf_write;
   guint tx_buf_read;
 
+  /* next sequence number (for PendingPluginEntry) */
   guint32 next_tag;
 
   guint8 *rx_buf;
@@ -135,7 +138,7 @@ static gboolean plugin_loader_sync_with_child (GstPluginLoader * l);
 static GstPluginLoader *
 plugin_loader_new (GstRegistry * registry)
 {
-  GstPluginLoader *l = g_new0 (GstPluginLoader, 1);
+  GstPluginLoader *l = g_slice_new0 (GstPluginLoader);
 
   if (registry)
     l->registry = gst_object_ref (registry);
@@ -196,12 +199,12 @@ plugin_loader_free (GstPluginLoader * loader)
   while (cur) {
     PendingPluginEntry *entry = (PendingPluginEntry *) (cur->data);
     g_free (entry->filename);
-    g_free (entry);
+    g_slice_free (PendingPluginEntry, entry);
 
     cur = g_list_delete_link (cur, cur);
   }
 
-  g_free (loader);
+  g_slice_free (GstPluginLoader, loader);
 
   return got_plugin_details;
 }
@@ -220,7 +223,7 @@ plugin_loader_load (GstPluginLoader * loader, const gchar * filename,
   GST_LOG_OBJECT (loader->registry,
       "Sending file %s to child. tag %u", filename, loader->next_tag);
 
-  entry = g_new (PendingPluginEntry, 1);
+  entry = g_slice_new (PendingPluginEntry);
   entry->tag = loader->next_tag++;
   entry->filename = g_strdup (filename);
   entry->file_size = file_size;
@@ -267,6 +270,8 @@ restart:
       l->got_plugin_details = TRUE;
       /* Now remove this crashy plugin from the head of the list */
       l->pending_plugins = g_list_delete_link (cur, cur);
+      g_free (entry->filename);
+      g_slice_free (PendingPluginEntry, entry);
       if (l->pending_plugins == NULL)
         l->pending_plugins_tail = NULL;
       if (!gst_plugin_loader_spawn (l))
@@ -334,9 +339,9 @@ plugin_loader_create_blacklist_plugin (GstPluginLoader * l,
 
   plugin->basename = g_path_get_basename (plugin->filename);
   plugin->desc.name = g_intern_string (plugin->basename);
-  plugin->desc.description = g_strdup_printf ("Plugin for blacklisted file");
-  plugin->desc.version = g_intern_string ("0.0.0");
-  plugin->desc.license = g_intern_string ("BLACKLIST");
+  plugin->desc.description = "Plugin for blacklisted file";
+  plugin->desc.version = "0.0.0";
+  plugin->desc.license = "BLACKLIST";
   plugin->desc.source = plugin->desc.license;
   plugin->desc.package = plugin->desc.license;
   plugin->desc.origin = plugin->desc.license;
@@ -348,9 +353,36 @@ plugin_loader_create_blacklist_plugin (GstPluginLoader * l,
 static gboolean
 gst_plugin_loader_try_helper (GstPluginLoader * loader, gchar * location)
 {
+#ifdef __APPLE__
+#if defined(__x86_64__)
+  char *argv[] = { (char *) "/usr/bin/arch", (char *) "-x86_64",
+    location, (char *) "-l", NULL
+  };
+#elif defined(__i386__)
+  char *argv[] = { (char *) "/usr/bin/arch", (char *) "-i386",
+    location, (char *) "-l", NULL
+  };
+#elif defined(__ppc__)
+  char *argv[] = { (char *) "/usr/bin/arch", (char *) "-ppc",
+    location, (char *) "-l", NULL
+  };
+#elif defined(__ppc64__)
+  char *argv[] = { (char *) "/usr/bin/arch", (char *) "-ppc64",
+    location, (char *) "-l", NULL
+  };
+#endif
+#else /* ! __APPLE__ */
   char *argv[] = { location, (char *) "-l", NULL };
+#endif
 
+
+#ifdef __APPLE__
+  GST_LOG ("Trying to spawn gst-plugin-scanner helper at %s with arch %s",
+      location, argv[1]);
+#else
   GST_LOG ("Trying to spawn gst-plugin-scanner helper at %s", location);
+#endif
+
   if (!g_spawn_async_with_pipes (NULL, argv, NULL,
           G_SPAWN_DO_NOT_REAP_CHILD /* | G_SPAWN_STDERR_TO_DEV_NULL */ ,
           NULL, NULL, &loader->child_pid, &loader->fd_w.fd, &loader->fd_r.fd,
@@ -644,9 +676,7 @@ do_plugin_load (GstPluginLoader * l, const gchar * filename, guint tag)
         GstRegistryChunk *cur = walk->data;
         put_chunk (l, cur, &offset);
 
-        if (!(cur->flags & GST_REGISTRY_CHUNK_FLAG_CONST))
-          g_free (cur->data);
-        g_free (cur);
+        _priv_gst_registry_chunk_free (cur);
       }
 
       g_list_free (chunks);
@@ -677,9 +707,7 @@ fail:
     for (walk = chunks; walk; walk = g_list_next (walk)) {
       GstRegistryChunk *cur = walk->data;
 
-      if (!(cur->flags & GST_REGISTRY_CHUNK_FLAG_CONST))
-        g_free (cur->data);
-      g_free (cur);
+      _priv_gst_registry_chunk_free (cur);
     }
 
     g_list_free (chunks);
@@ -724,11 +752,10 @@ handle_rx_packet (GstPluginLoader * l,
     case PACKET_EXIT:
       gst_poll_fd_ctl_read (l->fdset, &l->fd_r, FALSE);
       if (l->is_child) {
-        /* Respond, then we keep looping until the parent closes the fd */
+        /* Respond */
         put_packet (l, PACKET_EXIT, 0, NULL, 0);
-      } else {
-        l->rx_done = TRUE;      /* All done reading from child */
       }
+      l->rx_done = TRUE;
       return TRUE;
     case PACKET_LOAD_PLUGIN:{
       if (!l->is_child)
@@ -764,7 +791,7 @@ handle_rx_packet (GstPluginLoader * l,
         } else {
           cur = g_list_delete_link (cur, cur);
           g_free (e->filename);
-          g_free (e);
+          g_slice_free (PendingPluginEntry, e);
         }
       }
 
@@ -798,7 +825,7 @@ handle_rx_packet (GstPluginLoader * l,
 
       if (entry != NULL) {
         g_free (entry->filename);
-        g_free (entry);
+        g_slice_free (PendingPluginEntry, entry);
       }
 
       /* Remove the plugin entry we just loaded */