build: Get rid of gst-convenience warning
[gupnp:gupnp-dlna.git] / tests / dlna-profile-parser.c
1 /*
2  * Copyright (C) 2010 Nokia Corporation.
3  *
4  * Authors: Arun Raghavan <arun.raghavan@collabora.co.uk>
5  *
6  * This library is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU Library 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.
10  *
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  * Library General Public License for more details.
15  *
16  * You should have received a copy of the GNU Library 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.
20  */
21
22 #include <libgupnp-dlna/gupnp-dlna-load.h>
23 #include <libgupnp-dlna/gupnp-dlna-profile.h>
24 #include <gst/profile/gstprofile.h>
25 #include <stdlib.h>
26
27 static void usage (void)
28 {
29         g_print ("Usage: dlna-profile-parser file1 file2 ... dir1 dir2 ...\n");
30 }
31
32 static void print_caps (GstCaps *caps)
33 {
34         int i;
35
36         for (i = 0; i < gst_caps_get_size (caps); i++) {
37                 GstStructure *structure = gst_caps_get_structure (caps, i);
38                 gchar *tmp = gst_structure_to_string (structure);
39
40                 g_print ("%s`- %s\n", i ? "    " : "", tmp);
41
42                 g_free (tmp);
43         }
44 }
45
46 static void print_profile (GUPnPDLNAProfile *profile, gpointer unused)
47 {
48         GList *tmp = profile->enc_profile->encodingprofiles;
49         gchar *caps_str = gst_caps_to_string (profile->enc_profile->format);
50
51         g_print ("Loaded DLNA Profile: %s, %s - format %s\n",
52                  profile->name,
53                  profile->mime,
54                  caps_str);
55
56         while (tmp) {
57                 print_caps (((GstStreamEncodingProfile *) tmp->data)->format);
58                 tmp = tmp->next;
59         }
60
61         g_print ("\n");
62         g_free (caps_str);
63 }
64
65 int
66 main (int argc, char **argv)
67 {
68         GList *profiles = NULL;
69         GHashTable *restrictions, *profile_ids;
70         gint i;
71
72         g_thread_init (NULL);
73         gst_init (&argc, &argv);
74
75         if (argc < 2) {
76                 usage ();
77                 return EXIT_FAILURE;
78         }
79
80         restrictions = g_hash_table_new_full (g_str_hash,
81                                               g_str_equal,
82                                               (GDestroyNotify) xmlFree,
83                                               (GDestroyNotify)
84                                               gst_stream_encoding_profile_free);
85         profile_ids = g_hash_table_new_full (g_str_hash,
86                                               g_str_equal,
87                                               (GDestroyNotify) xmlFree,
88                                               (GDestroyNotify)
89                                               gst_encoding_profile_free);
90
91
92         for (i = 1; i < argc; i++) {
93                 GList *tmp;
94
95                 if (g_file_test (argv[i], G_FILE_TEST_IS_DIR))
96                         tmp = gupnp_dlna_load_profiles_from_dir (argv[i]);
97                 else
98                         tmp = gupnp_dlna_load_profiles_from_file (argv[i],
99                                                                   restrictions,
100                                                                   profile_ids);
101
102                 profiles = g_list_concat (profiles, tmp);
103         }
104
105         g_list_foreach (profiles, (GFunc)print_profile, NULL);
106         g_list_foreach (profiles, (GFunc)g_object_unref, NULL);
107
108         g_hash_table_unref (restrictions);
109         g_hash_table_unref (profile_ids);
110         return EXIT_SUCCESS;
111 }