[gupnp-dlna/wip/new-api: 7/15] Adapt tools to new API.



commit 78f71d792d14443b8ea686de3bad60616707e4e6
Author: Krzesimir Nowak <krnowak openismus com>
Date:   Thu Nov 15 15:29:28 2012 +0100

    Adapt tools to new API.

 tools/gupnp-dlna-info.c        |  462 +++++++++++-----------------------------
 tools/gupnp-dlna-ls-profiles.c |   85 ++------
 2 files changed, 142 insertions(+), 405 deletions(-)
---
diff --git a/tools/gupnp-dlna-info.c b/tools/gupnp-dlna-info.c
index 514dad0..e3d94e8 100644
--- a/tools/gupnp-dlna-info.c
+++ b/tools/gupnp-dlna-info.c
@@ -3,8 +3,10 @@
  *
  * Copyright (C) 2010 Nokia Corporation
  * Copyright (C) 2010 Collabora Multimedia
+ * Copyright (C) 2012 Intel Corporation
  *
  * Authors: Parthasarathi Susarla <partha susarla collabora co uk>
+ *          Krzesimir Nowak <krnowak openismus com>
  *
  * Based on 'gst-discoverer.c' by
  * Edward Hervey <edward hervey collabora co uk>
@@ -35,356 +37,127 @@
 
 #include <glib.h>
 #include <glib-object.h>
-#include <gio/gio.h>
 
-#include <gst/gst.h>
-#include <gst/pbutils/pbutils.h>
-
-#include <libgupnp-dlna/profile-loading.h>
 #include <libgupnp-dlna/gupnp-dlna-profile.h>
-#include <libgupnp-dlna/gupnp-dlna-discoverer.h>
-#include <libgupnp-dlna/gupnp-dlna-information.h>
+#include <libgupnp-dlna/gupnp-dlna-profile-guesser.h>
 
 
 static gboolean async = FALSE;
-static gboolean verbose = FALSE;
 static gint timeout = 10;
-
+static guint files_to_guess = 0;
 
 typedef struct
 {
-        GUPnPDLNADiscoverer *dc;
+        GUPnPDLNAProfileGuesser *guesser;
         int argc;
         char **argv;
 } PrivStruct;
 
-/*
- * The following functions are from gst-discoverer.c (gst-convenience/tools)
- */
-#define my_g_string_append_printf(str, format, ...)			\
-        g_string_append_printf (str, "%*s" format, 2*depth, " ", ##__VA_ARGS__)
-
-static gchar *
-gst_stream_audio_information_to_string (GstDiscovererStreamInfo * info,
-					gint depth)
-{
-        GString *s;
-        gchar *tmp;
-        GstCaps *caps;
-        const GstStructure *misc;
-        const GstTagList *taglist;
-        const GstDiscovererAudioInfo *audio_info;
-        int len = 400;
-
-        g_return_val_if_fail (info != NULL, NULL);
-
-        audio_info = GST_DISCOVERER_AUDIO_INFO (info);
-        s = g_string_sized_new (len);
-
-        my_g_string_append_printf (s, "Codec:\n");
-        caps = gst_discoverer_stream_info_get_caps (info);
-        tmp = gst_caps_to_string (caps);
-        my_g_string_append_printf (s, "  %s\n", tmp);
-        gst_caps_unref (caps);
-        g_free (tmp);
-
-        my_g_string_append_printf (s, "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, "  %s\n", tmp);
-                g_free (tmp);
-        } else {
-                my_g_string_append_printf (s, "  None\n");
-        }
-
-        my_g_string_append_printf (s, "Channels: %u\n",
-                                   gst_discoverer_audio_info_get_channels (audio_info));
-        my_g_string_append_printf (s, "Sample rate: %u\n",
-                                   gst_discoverer_audio_info_get_sample_rate (audio_info));
-        my_g_string_append_printf (s, "Depth: %u\n",
-                                   gst_discoverer_audio_info_get_depth (audio_info));
-
-        my_g_string_append_printf (s, "Bitrate: %u\n",
-                                   gst_discoverer_audio_info_get_bitrate (audio_info));
-        my_g_string_append_printf (s, "Max bitrate: %u\n",
-                                   gst_discoverer_audio_info_get_max_bitrate (audio_info));
-
-        my_g_string_append_printf (s, "Tags:\n");
-        taglist = gst_discoverer_stream_info_get_tags (info);
-        if (taglist) {
-                tmp = gst_structure_to_string ((GstStructure *) taglist);
-                my_g_string_append_printf (s, "  %s\n", tmp);
-                g_free (tmp);
-        } else {
-                my_g_string_append_printf (s, "  None\n");
-        }
-
-        return g_string_free (s, FALSE);
-}
-
-static gchar *
-gst_stream_video_information_to_string (GstDiscovererStreamInfo * info,
-					gint depth)
+static void
+print_dlna_profile (GUPnPDLNAProfile *profile,
+                    const gchar *uri,
+                    GError *err)
 {
-        GString *s;
-        gchar *tmp;
-        const GstStructure *misc;
-        const GstTagList *taglist;
-        const GstDiscovererVideoInfo *video_info;
-        GstCaps *caps;
-        int len = 500;
-
-        g_return_val_if_fail (info != NULL, NULL);
-
-        video_info = GST_DISCOVERER_VIDEO_INFO (info);
-
-        s = g_string_sized_new (len);
-
-        my_g_string_append_printf (s, "Codec:\n");
-        caps = gst_discoverer_stream_info_get_caps (info);
-        tmp = gst_caps_to_string (caps);
-        my_g_string_append_printf (s, "  %s\n", tmp);
-        gst_caps_unref (caps);
-        g_free (tmp);
-
-        my_g_string_append_printf (s, "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, "  %s\n", tmp);
-                g_free (tmp);
-        } else {
-                my_g_string_append_printf (s, "  None\n");
-        }
-
-        my_g_string_append_printf (s, "Width: %u\n",
-                                   gst_discoverer_video_info_get_width (video_info));
-        my_g_string_append_printf (s, "Height: %u\n",
-                                   gst_discoverer_video_info_get_height (video_info));
-        my_g_string_append_printf (s, "Depth: %u\n",
-                                   gst_discoverer_video_info_get_depth (video_info));
-
-        my_g_string_append_printf (s, "Frame rate: %u/%u\n",
-                                   gst_discoverer_video_info_get_framerate_num (video_info),
-                                   gst_discoverer_video_info_get_framerate_denom (video_info));
-
-        my_g_string_append_printf (s, "Pixel aspect ratio: %u/%u\n",
-                                   gst_discoverer_video_info_get_par_num (video_info),
-                                   gst_discoverer_video_info_get_par_denom (video_info));
-
-        my_g_string_append_printf (s, "Interlaced: %s\n",
-                                   gst_discoverer_video_info_is_interlaced (video_info) ? "true" : "false");
-
-        my_g_string_append_printf (s, "Bitrate: %u\n",
-                                   gst_discoverer_video_info_get_bitrate (video_info));
-
-        my_g_string_append_printf (s, "Max bitrate: %u\n",
-                                   gst_discoverer_video_info_get_max_bitrate (video_info));
-
-        my_g_string_append_printf (s, "Tags:\n");
-        taglist = gst_discoverer_stream_info_get_tags (info);
-        if (taglist) {
-                tmp = gst_structure_to_string ((GstStructure *) taglist);
-                my_g_string_append_printf (s, "  %s\n", tmp);
-                g_free (tmp);
+        g_print ("\nURI: %s\n", uri);
+        if (err) {
+                g_print ("Failed to guess: %s\n", err->message);
+        } else if (profile == NULL) {
+                g_print ("No error reported, but no matching profile found.\n");
         } else {
-                my_g_string_append_printf (s, "  None\n");
+                g_print ("Profile Name: %s\n", gupnp_dlna_profile_get_name (profile));
+                g_print ("Profile MIME: %s\n", gupnp_dlna_profile_get_mime (profile));
         }
-
-
-        return g_string_free (s, FALSE);
+        return;
 }
 
 static void
-print_stream_info (GstDiscovererStreamInfo * info, void *depth)
+guesser_done (GUPnPDLNAProfileGuesser *guesser G_GNUC_UNUSED,
+              const gchar *uri,
+              GUPnPDLNAProfile *profile,
+              GError *err,
+              GMainLoop *ml)
 {
-        gchar *desc = NULL;
-        GstCaps *caps;
-
-        caps = gst_discoverer_stream_info_get_caps (info);
-        if (caps) {
-                desc = gst_caps_to_string (caps);
-        }
-
-        g_print ("%*s%s: %s\n", 2 * GPOINTER_TO_INT (depth), " ",
-                 gst_discoverer_stream_info_get_stream_type_nick (info),
-                 desc);
-
-        if (desc) {
-                g_free (desc);
-                desc = NULL;
-        }
-
-        if (GST_IS_DISCOVERER_AUDIO_INFO (info))
-                desc = gst_stream_audio_information_to_string (
-                                        info,
-                                        GPOINTER_TO_INT (depth) + 1);
-        else if (GST_IS_DISCOVERER_VIDEO_INFO (info))
-                desc = gst_stream_video_information_to_string (
-                                         info,
-                                         GPOINTER_TO_INT (depth) + 1);
-
-        if (desc) {
-                g_print ("%s", desc);
-                g_free (desc);
-        }
+        print_dlna_profile (profile, uri, err);
+        --files_to_guess;
+        if (!files_to_guess)
+                g_main_loop_quit (ml);
+        return;
 }
 
-static void
-print_topology (GstDiscovererStreamInfo * info, gint depth)
+static gboolean
+is_uri (const gchar *filename)
 {
-        GstDiscovererStreamInfo *next;
-        if (!info)
-                return;
-
-        print_stream_info (info, GINT_TO_POINTER (depth));
-
-        next = gst_discoverer_stream_info_get_next (info);
-        if (next) {
-                print_topology (next, depth + 1);
-                gst_discoverer_stream_info_unref (next);
-        } else if (GST_IS_DISCOVERER_CONTAINER_INFO (info)) {
-                GList *tmp, *streams;
-                GstDiscovererContainerInfo *container =
-                        GST_DISCOVERER_CONTAINER_INFO (info);
-
-                streams = gst_discoverer_container_info_get_streams (container);
-                for (tmp = streams; tmp; tmp = tmp->next) {
-                        GstDiscovererStreamInfo *tmpinf =
-                                GST_DISCOVERER_STREAM_INFO (tmp->data);
-                        print_topology (tmpinf, depth + 1);
-                }
-        }
-}
+        gchar *uri = g_uri_parse_scheme (filename);
+        gboolean result = (uri != NULL);
 
-static void
-print_duration (GstDiscovererInfo * info, gint tab)
-{
-        g_print ("%*s%" GST_TIME_FORMAT "\n", tab + 1, " ",
-                 GST_TIME_ARGS (gst_discoverer_info_get_duration (info)));
+        g_free (uri);
+
+        return result;
 }
 
 static void
-print_gst_info (GstDiscovererInfo *info, GError *err)
-{
-        GstDiscovererResult result = gst_discoverer_info_get_result (info);
-        GstDiscovererStreamInfo *sinfo;
-
-        switch (result) {
-        case GST_DISCOVERER_OK:
-                break;
-        case GST_DISCOVERER_URI_INVALID:
-                g_print ("URI is not valid\n");
-                break;
-        case GST_DISCOVERER_ERROR:
-                g_print ("An error was encountered while discovering the file\n");
-                g_print (" %s\n", err->message);
-                break;
-        case GST_DISCOVERER_TIMEOUT:
-                g_print ("Analyzing URI timed out\n");
-                break;
-        case GST_DISCOVERER_BUSY:
-                g_print ("Discoverer was busy\n");
-                break;
-        case GST_DISCOVERER_MISSING_PLUGINS:
-                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);
-                }
-                break;
-        }
-
-        if (verbose) {
-                if ((sinfo = gst_discoverer_info_get_stream_info (info))) {
-                        g_print ("\nTopology:\n");
-                        print_topology (sinfo, 1);
-                        g_print ("\nDuration:\n");
-                        print_duration (info, 1);
-                        gst_discoverer_stream_info_unref (sinfo);
-                }
-        }
-
-        g_print ("\n");
-}
+process_file (GUPnPDLNAProfileGuesser *guesser,
+              const gchar *filename);
 
 static void
-print_dlna_info (GUPnPDLNAInformation *dlna, GError *err)
+process_directory (GUPnPDLNAProfileGuesser *guesser,
+                   const gchar *directory)
 {
-        GstDiscovererInfo *info;
+        GError *err = NULL;
+        GDir *dir = g_dir_open (directory, 0, &err);
 
-        info = (GstDiscovererInfo *)gupnp_dlna_information_get_info (dlna);
+        if (dir) {
+                const gchar *entry;
 
-        g_print ("\nURI: %s\n", gst_discoverer_info_get_uri (info));
-        g_print ("Profile Name: %s\n", gupnp_dlna_information_get_name (dlna));
-        g_print ("Profile MIME: %s\n", gupnp_dlna_information_get_mime (dlna));
+                while ((entry = g_dir_read_name (dir))) {
+                        gchar *entry_path;
 
-        print_gst_info ((GstDiscovererInfo *)info, err);
+                        entry_path = g_build_filename (directory,
+                                                       entry,
+                                                       NULL);
+                        process_file (guesser, entry_path);
+                        g_free (entry_path);
+                }
 
-        g_print ("\n");
-        return;
+                g_dir_close (dir);
+        } else {
+                g_warning ("Couldn't open directory: %s.\n",
+                           err->message);
+                g_error_free (err);
+                err = NULL;
+        }
 }
 
 static void
-discoverer_done (GUPnPDLNADiscoverer *discover,
-                 GUPnPDLNAInformation *dlna,
-                 GError *err)
+process_file (GUPnPDLNAProfileGuesser *guesser,
+              const gchar *filename)
 {
-        print_dlna_info (dlna, err);
-        return;
-}
+        gchar *uri;
 
-static void
-discoverer_ready (GUPnPDLNADiscoverer *dc, GMainLoop *ml)
-{
-        g_main_loop_quit (ml);
-}
+        if(!is_uri (filename)) {
+                gchar *abs_path;
+                GError *err = NULL;
 
-static void
-process_file (GUPnPDLNADiscoverer *discover, const gchar *filename)
-{
-        GError *err = NULL;
-        GDir *dir;
-        gchar *uri, *path;
-        GUPnPDLNAInformation *dlna;
-
-        if(!gst_uri_is_valid (filename)) {
-                if((dir = g_dir_open (filename, 0, NULL))) {
-                        const gchar *entry;
-
-                        while ((entry = g_dir_read_name (dir))) {
-                                gchar *path;
-                                path = g_strconcat (filename,
-                                                    G_DIR_SEPARATOR_S,
-                                                    entry,
-                                                    NULL);
-                                process_file (discover, path);
-                                g_free(path);
-                        }
-
-                        g_dir_close (dir);
+                if (g_file_test (filename, G_FILE_TEST_IS_DIR)) {
+                        process_directory (guesser, filename);
                         return;
                 }
 
                 if (!g_path_is_absolute (filename)) {
-                        gchar *cur_dir;
+                        gchar *cur_dir = g_get_current_dir ();
 
-                        cur_dir = g_get_current_dir ();
-                        path = g_build_filename (cur_dir, filename, NULL);
+                        abs_path = g_build_filename (cur_dir, filename, NULL);
                         g_free (cur_dir);
                 } else {
-                        path = g_strdup (filename);
+                        abs_path = g_strdup (filename);
                 }
 
-                uri = g_filename_to_uri (path, NULL, &err);
-                g_free (path);
-                path = NULL;
+                uri = g_filename_to_uri (abs_path, NULL, &err);
+                g_free (abs_path);
 
                 if (err) {
-                        g_warning ("Couldn't convert filename to URI: %s\n",
+                        g_warning ("Couldn't convert filename (%s) to URI: %s\n",
+                                   filename,
                                    err->message);
                         g_error_free (err);
                         err = NULL;
@@ -394,34 +167,48 @@ process_file (GUPnPDLNADiscoverer *discover, const gchar *filename)
                 uri = g_strdup (filename);
         }
 
-        if (async == FALSE) {
-                dlna = gupnp_dlna_discoverer_discover_uri_sync (discover,
-                                                                uri,
-                                                                &err);
+        if (async) {
+                GError *err = NULL;
+
+                if (!gupnp_dlna_profile_guesser_guess_profile_async (guesser, uri, timeout, &err)) {
+                        const gchar *message;
+
+                        if (err) {
+                                message = err->message;
+                        } else {
+                                message = "Unknown error, probably programming mistake";
+                        }
+                        g_warning ("Unable to queue file for guessing: %s\n",
+                                   message);
+                        if (err) {
+                                g_error_free (err);
+                        }
+                } else {
+                        ++files_to_guess;
+                }
+        } else {
+                GError *err = NULL;
+                GUPnPDLNAProfile *profile = gupnp_dlna_profile_guesser_guess_profile_sync (guesser, uri, timeout, &err);
+
                 if (err) {
-                        /* Report error to user, and free error */
-                        fprintf (stderr,
-                                 "Unable to read file: %s\n",
-                                 err->message);
+                        g_warning ("Unable to read file: %s\n",
+                                   err->message);
                         g_error_free (err);
                         err = NULL;
                 } else {
-                        print_dlna_info (dlna, err);
+                        print_dlna_profile (profile, uri, err);
                 }
-        } else {
-                gupnp_dlna_discoverer_discover_uri (discover, uri);
         }
-
         g_free (uri);
 }
 
 static gboolean
-async_idle_loop (PrivStruct * ps)
+async_idle_loop (PrivStruct *ps)
 {
-        gint i;
+        gint iter;
 
-        for (i = 1; i < ps->argc; i++)
-                process_file (ps->dc, ps->argv[i]);
+        for (iter = 1; iter < ps->argc; iter++)
+                process_file (ps->guesser, ps->argv[iter]);
 
         return FALSE;
 }
@@ -430,8 +217,7 @@ async_idle_loop (PrivStruct * ps)
 int
 main (int argc, char **argv)
 {
-        gint i;
-        GUPnPDLNADiscoverer *discover;
+        GUPnPDLNAProfileGuesser *guesser;
         gboolean relaxed_mode = FALSE;
         gboolean extended_mode = FALSE;
         GError *err = NULL;
@@ -441,8 +227,6 @@ main (int argc, char **argv)
                  "Specify timeout (in seconds, defaults to 10)", "T"},
                 {"async", 'a', 0, G_OPTION_ARG_NONE, &async,
                  "Run asynchronously", NULL},
-                {"verbose", 'v', 0, G_OPTION_ARG_NONE, &verbose,
-                 "Print lot more information", NULL},
                 {"relaxed mode", 'r', 0, G_OPTION_ARG_NONE, &relaxed_mode,
                  "Enable Relaxed mode", NULL},
                 {"extended mode", 'e', 0, G_OPTION_ARG_NONE, &extended_mode,
@@ -452,15 +236,17 @@ main (int argc, char **argv)
 
         GOptionContext *ctx;
 
+#if !GLIB_CHECK_VERSION(2,35,0)
         g_type_init ();
+#endif
 
         ctx = g_option_context_new (" - program to extract DLNA and related metadata");
         g_option_context_add_main_entries (ctx, options, NULL);
-        g_option_context_add_group (ctx, gst_init_get_option_group ());
 
         if (!g_option_context_parse (ctx, &argc, &argv, &err)) {
 
                 g_print ("Error initializing: %s\n", err->message);
+                g_error_free (err);
                 exit (1);
         }
 
@@ -471,38 +257,36 @@ main (int argc, char **argv)
                 return -1;
         }
 
-        gst_init(&argc, &argv);
+        /* Option was passed in seconds, but guesser takes
+           miliseconds. */
+        timeout *= 1000;
 
-        discover = gupnp_dlna_discoverer_new ((GstClockTime)
-                                              (timeout * GST_SECOND),
-                                              relaxed_mode,
-                                              extended_mode);
+        guesser = gupnp_dlna_profile_guesser_new (relaxed_mode,
+                                                  extended_mode);
 
         if (async == FALSE) {
-                for ( i = 1 ; i < argc ; i++ )
-                        process_file (discover, argv[i]);
+                gint iter;
+
+                for (iter = 1; iter < argc; ++iter)
+                        process_file (guesser, argv[iter]);
         } else {
-                PrivStruct *ps = g_new0 (PrivStruct, 1);
+                PrivStruct *ps = g_slice_new0 (PrivStruct);
                 GMainLoop *ml = g_main_loop_new (NULL, FALSE);
 
-                ps->dc = discover;
+                ps->guesser = guesser;
                 ps->argc = argc;
                 ps->argv = argv;
 
                 g_idle_add ((GSourceFunc) async_idle_loop, ps);
 
-                g_signal_connect (discover, "done",
-                                  (GCallback) discoverer_done, 0);
-                g_signal_connect (discover, "finished",
-                                  (GCallback) discoverer_ready, ml);
-
-                gupnp_dlna_discoverer_start (discover);
+                g_signal_connect (guesser, "done",
+                                  G_CALLBACK (guesser_done), ml);
 
                 g_main_loop_run (ml);
-
-                gupnp_dlna_discoverer_stop (discover);
-
+                g_main_loop_unref (ml);
+                g_slice_free (PrivStruct, ps);
         }
-        g_object_unref (discover);
+        g_object_unref (guesser);
+        gupnp_dlna_profile_guesser_cleanup ();
         return 0;
 }
diff --git a/tools/gupnp-dlna-ls-profiles.c b/tools/gupnp-dlna-ls-profiles.c
index cb803fc..09f3a76 100644
--- a/tools/gupnp-dlna-ls-profiles.c
+++ b/tools/gupnp-dlna-ls-profiles.c
@@ -3,8 +3,10 @@
  *
  * Copyright (C) 2010 Nokia Corporation
  * Copyright (C) 2010 Collabora Multimedia
+ * Copyright (C) 2012 Intel Corporation
  *
  * Authors: Parthasarathi Susarla <partha susarla collabora co uk>
+ *          Krzesimir Nowak <krnowak openismus com>
  *
  * This library is free software; you can redistribute it and/or
  * modify it under the terms of the GNU Lesser General Public
@@ -26,115 +28,66 @@
 #endif
 
 #include <stdlib.h>
-#include <string.h>
 
 #include <glib.h>
 #include <glib-object.h>
-#include <gio/gio.h>
 
 #include <libgupnp-dlna/gupnp-dlna-profile.h>
-#include <libgupnp-dlna/gupnp-dlna-discoverer.h>
+#include <libgupnp-dlna/gupnp-dlna-profile-guesser.h>
 
-#include <gst/pbutils/pbutils.h>
-
-static gboolean verbose = FALSE, relaxed = FALSE;
-
-static void print_caps (const GstCaps *caps)
-{
-        int i;
-
-        for (i = 0; i < gst_caps_get_size (caps); i++) {
-                GstStructure *structure = gst_caps_get_structure (caps, i);
-                gchar *tmp = gst_structure_to_string (structure);
-
-                g_print ("%s`- %s\n", i ? "    " : "", tmp);
-
-                g_free (tmp);
-        }
-}
+static gboolean relaxed = FALSE;
 
 static void
-print_profile (GUPnPDLNAProfile *profile, gpointer unused)
+print_profile (GUPnPDLNAProfile *profile)
 {
-        GstEncodingProfile *enc_profile;
-        const GList *tmp;
-        gchar *caps_str;
-
-        enc_profile = gupnp_dlna_profile_get_encoding_profile (profile);
-        tmp = gst_encoding_container_profile_get_profiles
-                                        (GST_ENCODING_CONTAINER_PROFILE (enc_profile));
-
-        g_print ("%s %-30s%-35s",
+        g_print ("%s %-30s%-35s\n",
                  gupnp_dlna_profile_get_extended (profile) ? "*" : " ",
                  gupnp_dlna_profile_get_name (profile),
                  gupnp_dlna_profile_get_mime (profile));
-
-        if (verbose) {
-                caps_str = gst_caps_to_string
-                        (gst_encoding_profile_get_format (enc_profile));
-                g_print ("\n`- container: %s\n", caps_str);
-                g_free (caps_str);
-
-                while (tmp) {
-                        print_caps (gst_encoding_profile_get_format
-                                        (GST_ENCODING_PROFILE (tmp->data)));
-                        tmp = tmp->next;
-                }
-        }
-
-        g_print ("\n");
-        gst_encoding_profile_unref (enc_profile);
 }
 
 int
 main (int argc, char **argv)
 {
         GError *err = NULL;
-        GList *profiles = NULL;
-        GUPnPDLNADiscoverer *discover;
+        const GList *profiles = NULL;
+        GUPnPDLNAProfileGuesser *guesser;
 
         GOptionEntry options[] = {
-                {"verbose", 'v', 0, G_OPTION_ARG_NONE, &verbose,
-                 "Print (very) verbose output", NULL},
                 {"relaxed", 'r', 0, G_OPTION_ARG_NONE, &relaxed,
-                 "Read profiles in relaxed mode (only useful with -v)", NULL},
+                 "Read profiles in relaxed mode", NULL},
                 {NULL}
         };
 
         GOptionContext *ctx;
 
+#if !GLIB_CHECK_VERSION(2,35,0)
         g_type_init ();
+#endif
 
         ctx = g_option_context_new (" - program to list all the DLNA profiles supported by gupnp-dlna");
         g_option_context_add_main_entries (ctx, options, NULL);
-        g_option_context_add_group (ctx, gst_init_get_option_group ());
-
         if (!g_option_context_parse (ctx, &argc, &argv, &err)) {
 
                 g_print ("Error initializing: %s\n", err->message);
+                g_error_free (err);
                 exit (1);
         }
 
         g_option_context_free (ctx);
 
-        gst_init (&argc, &argv);
-
-        discover = gupnp_dlna_discoverer_new ((GstClockTime) GST_SECOND,
-                                              relaxed,
-                                              TRUE);
+        guesser = gupnp_dlna_profile_guesser_new (relaxed, TRUE);
+        profiles = gupnp_dlna_profile_guesser_list_profiles (guesser);
 
-        profiles = (GList *) gupnp_dlna_discoverer_list_profiles (discover);
-
-        if (!verbose) {
-                g_print ("  %-30s%s\n", "Name", "MIME type");
-                g_print ("---------------------------------------------------"
+        g_print ("  %-30s%s\n", "Name", "MIME type");
+        g_print ("---------------------------------------------------"
                          "---------------------\n");
-        }
-        g_list_foreach (profiles, (GFunc) print_profile, NULL);
+g_list_foreach ((GList *) profiles, (GFunc) print_profile, NULL);
         g_print ("\nProfiles with a '*' against their name are extended "
                  "(non-standard) profiles.\n\n");
 
-        g_object_unref (discover);
+        g_object_unref (guesser);
+        gupnp_dlna_profile_guesser_cleanup ();
 
         return 0;
 }



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