[gnac/devel] Fixed the support for missing plugin installation



commit 30001729ae3c35b0403d06023c8223a5e45bf630
Author: Benoît Dupasquier <bdupasqu src gnome org>
Date:   Wed May 19 18:12:57 2010 +0100

    Fixed the support for missing plugin installation

 libgnac/libgnac-converter.c  |   14 ++++++++---
 libgnac/libgnac-gst-utils.c  |    2 +-
 libgnac/libgnac-gst.c        |   53 +++++++++++++++++++++++++++++++++++++----
 libgnac/libgnac-media-item.c |   40 +++++++++++++++++++++++--------
 4 files changed, 87 insertions(+), 22 deletions(-)
---
diff --git a/libgnac/libgnac-converter.c b/libgnac/libgnac-converter.c
index c0812de..18c374f 100644
--- a/libgnac/libgnac-converter.c
+++ b/libgnac/libgnac-converter.c
@@ -1110,11 +1110,17 @@ libgnac_converter_missing_plugin_result_cb(GstInstallPluginsReturn result,
 
   item = converter->priv->current;
 
-  if (result == GST_INSTALL_PLUGINS_SUCCESS)
+  if (result == GST_INSTALL_PLUGINS_SUCCESS ||
+      result == GST_INSTALL_PLUGINS_PARTIAL_SUCCESS)
   {
-    if (libgnac_converter_restart_current(converter))
-    {
-      return;
+    /* update the plugin registry */
+    if (gst_update_registry()) {
+      /* restart the conversion */
+      if (libgnac_converter_restart_current(converter)) {
+        return;
+      }
+    } else {
+      libgnac_debug("Failed to update GStreamer registry");
     }
   } else {
     uri = g_file_get_uri(item->source);
diff --git a/libgnac/libgnac-gst-utils.c b/libgnac/libgnac-gst-utils.c
index 5b615d7..4802ce9 100644
--- a/libgnac/libgnac-gst-utils.c
+++ b/libgnac/libgnac-gst-utils.c
@@ -48,7 +48,7 @@ libgnac_gstu_make_pipeline_element(GstElement   *bin,
     g_set_error(error,
         LIBGNAC_ERROR,
         LIBGNAC_ERROR_MISSING_PLUGIN,
-        _("Failed to create %s element"),
+        "%s",
         element);
     return NULL;
   }
diff --git a/libgnac/libgnac-gst.c b/libgnac/libgnac-gst.c
index f97513c..9ac6c11 100644
--- a/libgnac/libgnac-gst.c
+++ b/libgnac/libgnac-gst.c
@@ -70,11 +70,39 @@ libgnac_gst_stop(LibgnacMediaItem  *item,
 }
 
 
+static void
+libgnac_gst_parse_error_missing_elem(GstParseContext  *ctx,
+                                     gchar            *descr,
+                                     GError          **error)
+{
+  g_return_if_fail(error);
+
+  if (g_error_matches(*error, GST_PARSE_ERROR,
+      GST_PARSE_ERROR_NO_SUCH_ELEMENT))
+  {
+    gchar **missing;
+    /* clean up the "old" error */
+    g_error_free(*error);
+    *error = NULL;
+    /* get the name of the missing elements */
+    missing = gst_parse_context_get_missing_elements(ctx);
+    libgnac_debug("Failed to parse description: %s", descr);
+    /* set the "new" error */
+    g_set_error(error,
+        LIBGNAC_ERROR,
+        LIBGNAC_ERROR_MISSING_PLUGIN,
+        "%s", missing[0]);
+    /* clean up */
+    g_strfreev(missing);
+    gst_parse_context_free(ctx);
+  }
+}
+
 
 static GstElement *
 libgnac_gst_get_audio_bin(LibgnacMediaItem  *item,
                           LibgnacProfile    *profile,
-                          GError               **error)
+                          GError           **error)
 {
   GstElement *bin;
   GstElement *conv;
@@ -82,6 +110,7 @@ libgnac_gst_get_audio_bin(LibgnacMediaItem  *item,
   GstElement *rate;
   GstElement *resample;
   GstPad     *pad;
+  GstParseContext *ctx;
 
   bin = gst_bin_new("audio_bin");
 
@@ -95,8 +124,14 @@ libgnac_gst_get_audio_bin(LibgnacMediaItem  *item,
   rate = libgnac_gstu_make_pipeline_element(bin, "audiorate", NULL, error);
   g_return_val_if_fail(rate, NULL);
 
-  enc = gst_parse_bin_from_description(profile->audio_desc, TRUE, error);
-  g_return_val_if_fail(enc && gst_bin_add(GST_BIN(bin), enc), NULL);
+  ctx = gst_parse_context_new();
+  enc = gst_parse_bin_from_description_full(profile->audio_desc, TRUE, ctx,
+      GST_PARSE_FLAG_NONE, error);
+  if (!enc) {
+    libgnac_gst_parse_error_missing_elem(ctx, profile->audio_desc, error);
+    return NULL;
+  }
+  g_return_val_if_fail(gst_bin_add(GST_BIN(bin), enc), NULL);
 
   g_return_val_if_fail(
       gst_element_link_many(conv, resample, rate, enc, NULL),
@@ -125,10 +160,10 @@ libgnac_gst_get_video_bin(LibgnacMediaItem  *item,
   GstElement *enc;
   GstElement *rate;
   GstPad     *pad;
+  GstParseContext *ctx;
 
   bin = gst_bin_new("video_bin");
 
-
   conv = libgnac_gstu_make_pipeline_element(bin, "ffmpegcolorspace",
       NULL, error);
   g_return_val_if_fail(conv, NULL);
@@ -136,8 +171,14 @@ libgnac_gst_get_video_bin(LibgnacMediaItem  *item,
   rate = libgnac_gstu_make_pipeline_element(bin, "videorate", NULL, error);
   g_return_val_if_fail(rate, NULL);
 
-  enc = gst_parse_bin_from_description(profile->video_desc, TRUE, error);
-  g_return_val_if_fail(enc && gst_bin_add(GST_BIN(bin), enc), NULL);
+  ctx = gst_parse_context_new();
+  enc = gst_parse_bin_from_description_full(profile->video_desc, TRUE, ctx,
+      GST_PARSE_FLAG_NONE, error);
+  if (!enc) {
+    libgnac_gst_parse_error_missing_elem(ctx, profile->video_desc, error);
+    return NULL;
+  }
+  g_return_val_if_fail(gst_bin_add(GST_BIN(bin), enc), NULL);
 
   g_return_val_if_fail(
       gst_element_link_many(conv, rate, enc, NULL),
diff --git a/libgnac/libgnac-media-item.c b/libgnac/libgnac-media-item.c
index 5c5eb91..c6250e2 100644
--- a/libgnac/libgnac-media-item.c
+++ b/libgnac/libgnac-media-item.c
@@ -100,10 +100,30 @@ libgnac_item_build(LibgnacMediaItem  *item,
 
   libgnac_gst_build_pipeline(item, item->profile, has_video, &err);
   if (err) {
-    libgnac_warning("Unable to build pipeline");
-    libgnac_gst_clean_pipeline(item);
-    g_propagate_error(error, err);
-    return;
+    if (g_error_matches(err, LIBGNAC_ERROR, LIBGNAC_ERROR_MISSING_PLUGIN))
+    {
+      gchar *details;
+      GstMessage *msg;
+      msg = gst_missing_element_message_new(item->pipeline, err->message);
+      g_return_if_fail(msg);
+      details = gst_missing_plugin_message_get_installer_detail(msg);
+      gst_message_unref(msg);
+      if (details) {
+        GstInstallPluginsReturn ret;
+        ret = gst_install_plugins_async(&details, NULL,
+            libgnac_converter_missing_plugin_result_cb, item->parent);
+        g_free(details);
+        if (ret != GST_INSTALL_PLUGINS_STARTED_OK) {
+          libgnac_warning("Could not launch installer for required plugins");
+        }
+      }
+      return;
+    } else {
+      libgnac_warning("Unable to build pipeline");
+      libgnac_gst_clean_pipeline(item);
+      g_propagate_error(error, err);
+      return;
+    }
   }
 
   /* Connect item callbacks*/
@@ -129,13 +149,11 @@ libgnac_item_run(LibgnacMediaItem  *item,
   g_return_if_fail(error == NULL || *error == NULL);
 
   /* Build pipeline if doesn't exist */
-  if (!item->pipeline) {
-    libgnac_item_build(item, &err);
-    if(err)
-    {
-      g_propagate_error(error, err);
-      return;
-    }
+  libgnac_item_build(item, &err);
+  if(err)
+  {
+    g_propagate_error(error, err);
+    return;
   }
 
   libgnac_item_init_event_src(item);



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]