2 * Copyright (C) 2010 Nokia Corporation.
4 * Authors: Arun Raghavan <arun.raghavan@collabora.co.uk>
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2 of the License, or (at your option) any later version.
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with this library; if not, write to the
18 * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
19 * Boston, MA 02111-1307, USA.
23 #include <libgupnp-dlna/gupnp-dlna-load.h>
24 #include <libgupnp-dlna/gupnp-dlna-profile.h>
25 #include <gst/pbutils/pbutils.h>
26 #include <libxml/xmlmemory.h>
29 static void usage (void)
31 g_print ("Usage: dlna-profile-parser file1 file2 ... dir1 dir2 ...\n");
34 static void print_caps (const GstCaps *caps)
38 for (i = 0; i < gst_caps_get_size (caps); i++) {
39 GstStructure *structure = gst_caps_get_structure (caps, i);
40 gchar *tmp = gst_structure_to_string (structure);
42 g_print ("%s`- %s\n", i ? " " : "", tmp);
48 static void print_profile (GUPnPDLNAProfile *profile, gpointer unused)
50 GstEncodingProfile *enc_profile;
54 enc_profile = gupnp_dlna_profile_get_encoding_profile (profile);
55 tmp = gst_encoding_container_profile_get_profiles (GST_ENCODING_CONTAINER_PROFILE (enc_profile));
56 caps_str = gst_caps_to_string ((GstCaps *)gst_encoding_profile_get_format (enc_profile));
58 g_print ("Loaded DLNA Profile: %s, %s - format %s\n",
59 gupnp_dlna_profile_get_name (profile),
60 gupnp_dlna_profile_get_mime (profile),
64 print_caps (gst_encoding_profile_get_format
65 (GST_ENCODING_PROFILE(tmp->data)));
71 gst_encoding_profile_unref (enc_profile);
75 free_restrictions_struct (gpointer data, gpointer user_data)
77 GUPnPDLNARestrictionsPriv *priv = (GUPnPDLNARestrictionsPriv *)data;
80 gst_caps_unref (priv->caps);
87 main (int argc, char **argv)
89 GList *profiles = NULL;
90 GUPnPDLNALoadState *data;
91 gboolean relaxed_mode = FALSE;
92 gboolean extended_mode = FALSE;
96 GOptionEntry options[] = {
97 {"relaxed mode", 'r', 0, G_OPTION_ARG_NONE, &relaxed_mode,
98 "Enable Relaxed mode", NULL},
99 {"extended mode", 'e', 0, G_OPTION_ARG_NONE, &extended_mode,
100 "Enable extended mode", NULL},
106 if (!g_thread_supported ())
107 g_thread_init (NULL);
109 ctx = g_option_context_new (" - test to parse dlna profiles");
110 g_option_context_add_main_entries (ctx, options, NULL);
111 g_option_context_add_group (ctx, gst_init_get_option_group ());
113 if (!g_option_context_parse (ctx, &argc, &argv, &err)) {
115 g_print ("Error initializing: %s\n", err->message);
119 g_option_context_free (ctx);
121 gst_init (&argc, &argv);
128 data = g_new (GUPnPDLNALoadState, 1);
130 data->restrictions = g_hash_table_new_full (g_str_hash,
132 (GDestroyNotify) xmlFree,
134 free_restrictions_struct);
135 data->profile_ids = g_hash_table_new_full (g_str_hash,
137 (GDestroyNotify) xmlFree,
140 data->files_hash = g_hash_table_new_full (g_str_hash,
145 data->relaxed_mode = relaxed_mode;
146 data->extended_mode = extended_mode;
148 for (i = 1; i < argc; i++) {
151 if (g_file_test (argv[i], G_FILE_TEST_IS_DIR))
152 tmp = gupnp_dlna_load_profiles_from_dir (argv[i],
155 tmp = gupnp_dlna_load_profiles_from_file (argv[i],
158 profiles = g_list_concat (profiles, tmp);
161 g_list_foreach (profiles, (GFunc)print_profile, NULL);
162 g_list_foreach (profiles, (GFunc)g_object_unref, NULL);
164 g_hash_table_unref (data->restrictions);
165 g_hash_table_unref (data->profile_ids);
166 g_hash_table_unref (data->files_hash);