discoverer: Add APIs to simply get installer details for missing plugins
[platform/upstream/gstreamer.git] / tools / gst-discoverer.c
index 4ad26d7..db351b3 100644 (file)
  *
  * You should have received a copy of the GNU Library General Public
  * License along with this library; if not, write to the
- * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
- * Boston, MA 02111-1307, USA.
+ * Free Software Foundation, Inc., 51 Franklin St, Fifth Floor,
+ * Boston, MA 02110-1301, USA.
  */
 
 #ifdef HAVE_CONFIG_H
 #include "config.h"
 #endif
 
+#include <locale.h>
+
 #include <stdlib.h>
 #include <glib.h>
 #include <gst/gst.h>
 #include <gst/pbutils/pbutils.h>
 
+/* *INDENT-OFF* */
+static void my_g_string_append_printf (GString * str, int depth, const gchar * format, ...) G_GNUC_PRINTF (3, 4);
+/* *INDENT-ON* */
+
 static gboolean async = FALSE;
 static gboolean show_toc = FALSE;
 static gboolean verbose = FALSE;
@@ -51,21 +57,13 @@ my_g_string_append_printf (GString * str, int depth, const gchar * format, ...)
   va_end (args);
 }
 
-static gchar *
-gst_stream_audio_information_to_string (GstDiscovererStreamInfo * info,
+static void
+gst_stream_information_to_string (GstDiscovererStreamInfo * info, GString * s,
     gint depth)
 {
-  GstDiscovererAudioInfo *audio_info;
-  GString *s;
   gchar *tmp;
-  const gchar *ctmp;
-  int len = 400;
-  const GstTagList *tags;
   GstCaps *caps;
-
-  g_return_val_if_fail (info != NULL, NULL);
-
-  s = g_string_sized_new (len);
+  const GstStructure *misc;
 
   my_g_string_append_printf (s, depth, "Codec:\n");
   caps = gst_discoverer_stream_info_get_caps (info);
@@ -75,14 +73,35 @@ gst_stream_audio_information_to_string (GstDiscovererStreamInfo * info,
   g_free (tmp);
 
   my_g_string_append_printf (s, depth, "Additional info:\n");
-  if (gst_discoverer_stream_info_get_misc (info)) {
-    tmp = gst_structure_to_string (gst_discoverer_stream_info_get_misc (info));
+  if ((misc = gst_discoverer_stream_info_get_misc (info))) {
+    tmp = gst_structure_to_string (misc);
     my_g_string_append_printf (s, depth, "  %s\n", tmp);
     g_free (tmp);
   } else {
     my_g_string_append_printf (s, depth, "  None\n");
   }
 
+  my_g_string_append_printf (s, depth, "Stream ID: %s\n",
+      gst_discoverer_stream_info_get_stream_id (info));
+}
+
+static gchar *
+gst_stream_audio_information_to_string (GstDiscovererStreamInfo * info,
+    gint depth)
+{
+  GstDiscovererAudioInfo *audio_info;
+  GString *s;
+  gchar *tmp;
+  const gchar *ctmp;
+  int len = 400;
+  const GstTagList *tags;
+
+  g_return_val_if_fail (info != NULL, NULL);
+
+  s = g_string_sized_new (len);
+
+  gst_stream_information_to_string (info, s, depth);
+
   audio_info = (GstDiscovererAudioInfo *) info;
   ctmp = gst_discoverer_audio_info_get_language (audio_info);
   my_g_string_append_printf (s, depth, "Language: %s\n",
@@ -122,30 +141,13 @@ gst_stream_video_information_to_string (GstDiscovererStreamInfo * info,
   GString *s;
   gchar *tmp;
   int len = 500;
-  const GstStructure *misc;
   const GstTagList *tags;
-  GstCaps *caps;
 
   g_return_val_if_fail (info != NULL, NULL);
 
   s = g_string_sized_new (len);
 
-  my_g_string_append_printf (s, depth, "Codec:\n");
-  caps = gst_discoverer_stream_info_get_caps (info);
-  tmp = gst_caps_to_string (caps);
-  gst_caps_unref (caps);
-  my_g_string_append_printf (s, depth, "  %s\n", tmp);
-  g_free (tmp);
-
-  my_g_string_append_printf (s, depth, "Additional info:\n");
-  misc = gst_discoverer_stream_info_get_misc (info);
-  if (misc) {
-    tmp = gst_structure_to_string (misc);
-    my_g_string_append_printf (s, depth, "  %s\n", tmp);
-    g_free (tmp);
-  } else {
-    my_g_string_append_printf (s, depth, "  None\n");
-  }
+  gst_stream_information_to_string (info, s, depth);
 
   video_info = (GstDiscovererVideoInfo *) info;
   my_g_string_append_printf (s, depth, "Width: %u\n",
@@ -196,27 +198,12 @@ gst_stream_subtitle_information_to_string (GstDiscovererStreamInfo * info,
   const gchar *ctmp;
   int len = 400;
   const GstTagList *tags;
-  GstCaps *caps;
 
   g_return_val_if_fail (info != NULL, NULL);
 
   s = g_string_sized_new (len);
 
-  my_g_string_append_printf (s, depth, "Codec:\n");
-  caps = gst_discoverer_stream_info_get_caps (info);
-  tmp = gst_caps_to_string (caps);
-  gst_caps_unref (caps);
-  my_g_string_append_printf (s, depth, "  %s\n", tmp);
-  g_free (tmp);
-
-  my_g_string_append_printf (s, depth, "Additional info:\n");
-  if (gst_discoverer_stream_info_get_misc (info)) {
-    tmp = gst_structure_to_string (gst_discoverer_stream_info_get_misc (info));
-    my_g_string_append_printf (s, depth, "  %s\n", tmp);
-    g_free (tmp);
-  } else {
-    my_g_string_append_printf (s, depth, "  None\n");
-  }
+  gst_stream_information_to_string (info, s, depth);
 
   subtitle_info = (GstDiscovererSubtitleInfo *) info;
   ctmp = gst_discoverer_subtitle_info_get_language (subtitle_info);
@@ -422,10 +409,15 @@ print_info (GstDiscovererInfo * info, GError * err)
     {
       g_print ("Missing plugins\n");
       if (verbose) {
-        gchar *tmp =
-            gst_structure_to_string (gst_discoverer_info_get_misc (info));
-        g_print (" (%s)\n", tmp);
-        g_free (tmp);
+        gint i = 0;
+        const gchar **installer_details =
+            gst_discoverer_info_get_missing_elements_installer_details (info);
+
+        while (installer_details[i]) {
+          g_print (" (%s)\n", installer_details[i]);
+
+          i++;
+        }
       }
       break;
     }
@@ -547,6 +539,8 @@ main (int argc, char **argv)
   };
   GOptionContext *ctx;
 
+  setlocale (LC_ALL, "");
+
   ctx =
       g_option_context_new
       ("- discover files synchronously with GstDiscoverer");