Initial Submission of GUPnP-DLNA to Tizen IVI
[profile/ivi/GUPnP-DLNA.git] / libgupnp-dlna / gupnp-dlna-information.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 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.
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  * Lesser General Public License for more details.
15  *
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.
20  */
21
22 #include "gupnp-dlna-information.h"
23 #include <gst/gstminiobject.h>
24
25 /**
26  * SECTION:gupnp-dlna-information
27  * @short_description: Object containing metadata information returned by the
28  * #GUPnPDLNADiscoverer API
29  *
30  * The GUPnPDLNAInformation object holds metadata information discovered by the
31  * GUPnPDiscoverer API. The DLNA profile name and MIME type have their own
32  * fields, and other metadata is held in a GstDiscovererInfo structure.
33  * All fields are read-only.
34  */
35
36 G_DEFINE_TYPE (GUPnPDLNAInformation, gupnp_dlna_information, G_TYPE_OBJECT)
37
38 #define GET_PRIVATE(o)                                                  \
39         (G_TYPE_INSTANCE_GET_PRIVATE ((o),                              \
40                                       GUPNP_TYPE_DLNA_INFORMATION,      \
41                                       GUPnPDLNAInformationPrivate))
42
43 typedef struct _GUPnPDLNAInformationPrivate GUPnPDLNAInformationPrivate;
44
45 struct _GUPnPDLNAInformationPrivate {
46         GstDiscovererInfo *info;
47         gchar             *name;
48         gchar             *mime;
49 };
50
51 enum {
52         PROP_0,
53         PROP_DLNA_NAME,
54         PROP_DLNA_MIME,
55         PROP_DISCOVERER_INFO,
56 };
57
58 static void
59 gupnp_dlna_information_get_property (GObject    *object,
60                                      guint       property_id,
61                                      GValue     *value,
62                                      GParamSpec *pspec)
63 {
64         GUPnPDLNAInformation *self = GUPNP_DLNA_INFORMATION (object);
65         GUPnPDLNAInformationPrivate *priv = GET_PRIVATE (self);
66
67         switch (property_id) {
68                 case PROP_DLNA_NAME:
69                         g_value_set_string (value, priv->name);
70
71                         break;
72
73                 case PROP_DLNA_MIME:
74                         g_value_set_string (value, priv->mime);
75
76                         break;
77
78                 case PROP_DISCOVERER_INFO:
79                         gst_value_set_mini_object (value,
80                                                    GST_MINI_OBJECT(priv->info));
81
82                         break;
83
84                 default:
85                         G_OBJECT_WARN_INVALID_PROPERTY_ID (object,
86                                                            property_id,
87                                                            pspec);
88
89                         break;
90         }
91 }
92
93 static void
94 gupnp_dlna_information_set_property (GObject      *object,
95                                      guint         property_id,
96                                      const GValue *value,
97                                      GParamSpec   *pspec)
98 {
99         GUPnPDLNAInformation *self = GUPNP_DLNA_INFORMATION (object);
100         GUPnPDLNAInformationPrivate *priv = GET_PRIVATE (self);
101
102         switch (property_id) {
103                 case PROP_DLNA_NAME:
104                         g_free (priv->name);
105                         priv->name = g_value_dup_string (value);
106
107                         break;
108
109                 case PROP_DLNA_MIME:
110                         g_free (priv->mime);
111                         priv->mime = g_value_dup_string (value);
112
113                         break;
114
115                 case PROP_DISCOVERER_INFO:
116                         if (priv->info)
117                                 gst_discoverer_info_unref (priv->info);
118                         priv->info = GST_DISCOVERER_INFO
119                                 (gst_value_dup_mini_object (value));
120
121                         break;
122
123                 default:
124                         G_OBJECT_WARN_INVALID_PROPERTY_ID (object,
125                                                            property_id,
126                                                            pspec);
127
128                         break;
129         }
130 }
131
132
133 static void
134 gupnp_dlna_information_finalize (GObject *object)
135 {
136         GUPnPDLNAInformation *self = GUPNP_DLNA_INFORMATION (object);
137         GUPnPDLNAInformationPrivate *priv = GET_PRIVATE (self);
138
139         g_free (priv->name);
140         g_free (priv->mime);
141         if (priv->info)
142                 gst_discoverer_info_unref (priv->info);
143
144         G_OBJECT_CLASS (gupnp_dlna_information_parent_class)->finalize (object);
145 }
146
147 static void
148 gupnp_dlna_information_class_init (GUPnPDLNAInformationClass *klass)
149 {
150         GObjectClass *object_class = G_OBJECT_CLASS (klass);
151         GParamSpec *pspec;
152
153         g_type_class_add_private (klass, sizeof (GUPnPDLNAInformationPrivate));
154
155         object_class->get_property = gupnp_dlna_information_get_property;
156         object_class->set_property = gupnp_dlna_information_set_property;
157         object_class->finalize = gupnp_dlna_information_finalize;
158
159         pspec = g_param_spec_string ("name",
160                                      "DLNA profile name",
161                                      "The name of the DLNA profile "
162                                      "corresponding to the strream",
163                                      NULL,
164                                      G_PARAM_READWRITE |
165                                      G_PARAM_CONSTRUCT_ONLY);
166         g_object_class_install_property (object_class, PROP_DLNA_NAME, pspec);
167
168         pspec = g_param_spec_string ("mime",
169                                      "DLNA profile MIME type corresponding "
170                                      "to the stream",
171                                      "The DLNA MIME type of the stream",
172                                      NULL,
173                                      G_PARAM_READWRITE |
174                                      G_PARAM_CONSTRUCT_ONLY);
175         g_object_class_install_property (object_class, PROP_DLNA_MIME, pspec);
176
177         pspec = gst_param_spec_mini_object ("info",
178                                             "Stream metadata",
179                                             "Metadata of the stream in a "
180                                             "GstDiscovererInfo structure",
181                                             GST_TYPE_DISCOVERER_INFO,
182                                             G_PARAM_READWRITE |
183                                             G_PARAM_CONSTRUCT_ONLY);
184         g_object_class_install_property (object_class,
185                                          PROP_DISCOVERER_INFO,
186                                          pspec);
187 }
188
189 static void
190 gupnp_dlna_information_init (GUPnPDLNAInformation *self)
191 {
192         GUPnPDLNAInformationPrivate *priv = GET_PRIVATE (self);
193
194         priv->name = NULL;
195         priv->mime = NULL;
196         priv->info = NULL;
197 }
198
199 /**
200  * gupnp_dlna_information_new:
201  * @name: DLNA media profile name corresponding to the media
202  * @mime: DLNA MIME type for the media
203  * @info: #GstDiscovererInfo type with additional metadata about the
204  *        stream
205  *
206  * Creates a new #GUPnPDLNAInformation object with the given properties.
207  *
208  * Returns: A newly created #GUPnPDLNAInformation object.
209  */
210 GUPnPDLNAInformation*
211 gupnp_dlna_information_new (gchar             *name,
212                             gchar             *mime,
213                             GstDiscovererInfo *info)
214 {
215         return g_object_new (GUPNP_TYPE_DLNA_INFORMATION,
216                              "name", name,
217                              "mime", mime,
218                              "info", info,
219                              NULL);
220 }
221
222 /**
223  * gupnp_dlna_information_get_name:
224  * @self: The #GUPnPDLNAInformation object
225  *
226  * Returns: the DLNA profile name of the stream represented by @self. Do not
227  *          free this string.
228  */
229 const gchar *
230 gupnp_dlna_information_get_name (GUPnPDLNAInformation *self)
231 {
232         GUPnPDLNAInformationPrivate *priv = GET_PRIVATE (self);
233
234         return priv->name;
235 }
236
237 /**
238  * gupnp_dlna_information_get_mime:
239  * @self: The #GUPnPDLNAInformation object
240  *
241  * Returns: the DLNA MIME type of the stream represented by @self. Do not
242  *          free this string.
243  */
244 const gchar *
245 gupnp_dlna_information_get_mime (GUPnPDLNAInformation *self)
246 {
247         GUPnPDLNAInformationPrivate *priv = GET_PRIVATE (self);
248
249         return priv->mime;
250 }
251
252 /**finalize
253  * gupnp_dlna_information_get_info:
254  * @self: The #GUPnPDLNAInformation object
255  *
256  * Returns: additional stream metadata for @self in the form of a
257  *          #GstDiscovererInfo structure. Do not free this structure.
258  */
259 const GstDiscovererInfo *
260 gupnp_dlna_information_get_info (GUPnPDLNAInformation *self)
261 {
262         GUPnPDLNAInformationPrivate *priv = GET_PRIVATE (self);
263
264         return priv->info;
265 }