doc: Update NEWS for 0.4.0
[gupnp:gupnp-dlna.git] / tools / gupnp-dlna-ls-profiles.c
1 /* GUPnPDLNA
2  * gupnp-dlna-ls-profiles.c
3  *
4  * Copyright (C) 2010 Nokia Corporation
5  * Copyright (C) 2010 Collabora Multimedia
6  *
7  * Authors: Parthasarathi Susarla <partha.susarla@collabora.co.uk>
8  *
9  * This library is free software; you can redistribute it and/or
10  * modify it under the terms of the GNU Lesser General Public
11  * License as published by the Free Software Foundation; either
12  * version 2 of the License, or (at your option) any later version.
13  *
14  * This library is distributed in the hope that it will be useful,
15  * but WITHOUT ANY WARRANTY; without even the implied warranty of
16  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
17  * Lesser General Public License for more details.
18  *
19  * You should have received a copy of the GNU Lesser General Public
20  * License along with this library; if not, write to the
21  * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
22  * Boston, MA 02111-1307, USA.
23  */
24 #ifdef HAVE_CONFIG_H
25 #include "config.h"
26 #endif
27
28 #include <stdlib.h>
29 #include <string.h>
30
31 #include <glib.h>
32 #include <glib-object.h>
33 #include <gio/gio.h>
34
35 #include <libgupnp-dlna/gupnp-dlna-profile.h>
36 #include <libgupnp-dlna/gupnp-dlna-discoverer.h>
37
38 #include <gst/profile/gstprofile.h>
39
40 static gboolean verbose = FALSE, relaxed = FALSE;
41
42 static void print_caps (GstCaps *caps)
43 {
44         int i;
45
46         for (i = 0; i < gst_caps_get_size (caps); i++) {
47                 GstStructure *structure = gst_caps_get_structure (caps, i);
48                 gchar *tmp = gst_structure_to_string (structure);
49
50                 g_print ("%s`- %s\n", i ? "    " : "", tmp);
51
52                 g_free (tmp);
53         }
54 }
55
56 static void
57 print_profile (GUPnPDLNAProfile *profile, gpointer unused)
58 {
59         const GstEncodingProfile *enc_profile;
60         GList *tmp;
61         gchar *caps_str;
62
63         enc_profile = gupnp_dlna_profile_get_encoding_profile (profile);
64         tmp = enc_profile->encodingprofiles;
65
66         g_print ("%s %-30s%-35s",
67                  gupnp_dlna_profile_get_extended (profile) ? "*" : " ",
68                  gupnp_dlna_profile_get_name (profile),
69                  gupnp_dlna_profile_get_mime (profile));
70
71         if (verbose) {
72                 caps_str = gst_caps_to_string (enc_profile->format);
73                 g_print ("\n`- container: %s\n", caps_str);
74                 g_free (caps_str);
75
76                 while (tmp) {
77                         print_caps (((GstStreamEncodingProfile *) tmp->data)->format);
78                         tmp = tmp->next;
79                 }
80         }
81
82         g_print ("\n");
83 }
84
85 int
86 main (int argc, char **argv)
87 {
88         GError *err = NULL;
89         GList *profiles = NULL;
90         GUPnPDLNADiscoverer *discover;
91
92         GOptionEntry options[] = {
93                 {"verbose", 'v', 0, G_OPTION_ARG_NONE, &verbose,
94                  "Print (very) verbose output", NULL},
95                 {"relaxed", 'r', 0, G_OPTION_ARG_NONE, &relaxed,
96                  "Read profiles in relaxed mode (only useful with -v)", NULL},
97                 {NULL}
98         };
99
100         GOptionContext *ctx;
101
102         g_thread_init(NULL);
103
104         ctx = g_option_context_new (" - program to list all the DLNA profiles supported by gupnp-dlna");
105         g_option_context_add_main_entries (ctx, options, NULL);
106         g_option_context_add_group (ctx, gst_init_get_option_group ());
107
108         if (!g_option_context_parse (ctx, &argc, &argv, &err)) {
109
110                 g_print ("Error initializing: %s\n", err->message);
111                 exit (1);
112         }
113
114         g_option_context_free (ctx);
115
116         gst_init (&argc, &argv);
117
118         discover = gupnp_dlna_discoverer_new ((GstClockTime) GST_SECOND,
119                                               relaxed,
120                                               TRUE);
121
122         profiles = (GList *) gupnp_dlna_discoverer_list_profiles (discover);
123
124         if (!verbose) {
125                 g_print ("  %-30s%s\n", "Name", "MIME type");
126                 g_print ("---------------------------------------------------"
127                          "---------------------\n");
128         }
129         g_list_foreach (profiles, (GFunc) print_profile, NULL);
130         g_print ("\nProfiles with a '*' against their name are extended "
131                  "(non-standard) profiles.\n\n");
132
133         g_object_unref (discover);
134
135         return 0;
136 }