summaryrefslogtreecommitdiff
path: root/tests/dlna-profile-parser.c
blob: 0f1e2701e09558706a84aa288a1322f16513432b (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
/*
 * Copyright (C) 2010 Nokia Corporation.
 *
 * Authors: Arun Raghavan <arun.raghavan@collabora.co.uk>
 *
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Library General Public
 * License as published by the Free Software Foundation; either
 * version 2 of the License, or (at your option) any later version.
 *
 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Library General Public License for more details.
 *
 * 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.
 */

#include <libgupnp-dlna/gupnp-dlna-load.h>
#include <libgupnp-dlna/gupnp-dlna-profile.h>
#include <gst/profile/gstprofile.h>
#include <stdlib.h>

static void usage (void)
{
        g_print ("Usage: dlna-profile-parser file1 file2 ... dir1 dir2 ...\n");
}

static void print_caps (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 void print_profile (GUPnPDLNAProfile *profile, gpointer unused)
{
        GList *tmp = profile->enc_profile->encodingprofiles;
        gchar *caps_str = gst_caps_to_string (profile->enc_profile->format);

        g_print ("Loaded DLNA Profile: %s, %s - format %s\n",
                 profile->name,
                 profile->mime,
                 caps_str);

        while (tmp) {
                print_caps (((GstStreamEncodingProfile *) tmp->data)->format);
                tmp = tmp->next;
        }

        g_print ("\n");
        g_free (caps_str);
}

int
main (int argc, char **argv)
{
        GList *profiles = NULL;
        GHashTable *restrictions, *profile_ids, *files_hash;
        gint i;

        g_thread_init (NULL);
        gst_init (&argc, &argv);

        if (argc < 2) {
                usage ();
                return EXIT_FAILURE;
        }

        restrictions = g_hash_table_new_full (g_str_hash,
                                              g_str_equal,
                                              (GDestroyNotify) xmlFree,
                                              (GDestroyNotify)
                                              gst_stream_encoding_profile_free);
        profile_ids = g_hash_table_new_full (g_str_hash,
                                              g_str_equal,
                                              (GDestroyNotify) xmlFree,
                                              (GDestroyNotify)
                                              gst_encoding_profile_free);
        files_hash = g_hash_table_new_full (g_str_hash,
                                            g_str_equal,
                                            g_free,
                                            NULL);


        for (i = 1; i < argc; i++) {
                GList *tmp;

                if (g_file_test (argv[i], G_FILE_TEST_IS_DIR))
                        tmp = gupnp_dlna_load_profiles_from_dir (argv[i],
                                                                 files_hash);
                else
                        tmp = gupnp_dlna_load_profiles_from_file (argv[i],
                                                                  restrictions,
                                                                  profile_ids,
                                                                  files_hash);

                profiles = g_list_concat (profiles, tmp);
        }

        g_list_foreach (profiles, (GFunc)print_profile, NULL);
        g_list_foreach (profiles, (GFunc)g_object_unref, NULL);

        g_hash_table_unref (restrictions);
        g_hash_table_unref (profile_ids);
        g_hash_table_unref (files_hash);
        return EXIT_SUCCESS;
}