xml: Relax AVC_MP4_MP_HD_1080i_AAC profile restrictions
[gupnp:gupnp-dlna.git] / libgupnp-dlna / gupnp-dlna-profile.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-profile.h"
23
24 /**
25  * SECTION:gupnp-dlna-profile
26  * @short_description: Object representing a DLNA profile
27  *
28  * The #GUPnPDLNADiscoverer object provides a few APIs that return
29  * #GUPnPDLNAProfile objects. These represent a single DLNA profile. Each
30  * #GUPnPDLNAProfile has a name (the name of the DLNA profile), the
31  * corresponding MIME type, and a #GstEncodingProfile which represents the
32  * various audio/video/container restrictions specified for that DLNA profile.
33  */
34 G_DEFINE_TYPE (GUPnPDLNAProfile, gupnp_dlna_profile, G_TYPE_OBJECT)
35
36 #define GET_PRIVATE(o) \
37   (G_TYPE_INSTANCE_GET_PRIVATE ((o), \
38                                 GUPNP_TYPE_DLNA_PROFILE, \
39                                 GUPnPDLNAProfilePrivate))
40
41 typedef struct _GUPnPDLNAProfilePrivate GUPnPDLNAProfilePrivate;
42
43 struct _GUPnPDLNAProfilePrivate {
44         gchar              *name;
45         gchar              *mime;
46         GstEncodingProfile *enc_profile;
47         gboolean           extended;
48 };
49
50 enum {
51         PROP_0,
52         PROP_DLNA_NAME,
53         PROP_DLNA_MIME,
54         PROP_ENCODING_PROFILE,
55         PROP_DLNA_EXTENDED,
56 };
57
58 static void
59 gupnp_dlna_profile_get_property (GObject    *object,
60                                  guint       property_id,
61                                  GValue     *value,
62                                  GParamSpec *pspec)
63 {
64         GUPnPDLNAProfile *self = GUPNP_DLNA_PROFILE (object);
65         GUPnPDLNAProfilePrivate *priv = GET_PRIVATE (self);
66
67         switch (property_id) {
68                 case PROP_DLNA_NAME:
69                         g_value_set_string (value, priv->name);
70                         break;
71
72                 case PROP_DLNA_MIME:
73                         g_value_set_string (value, priv->mime);
74                         break;
75
76                 case PROP_ENCODING_PROFILE:
77                         g_value_set_boxed (value, priv->enc_profile);
78                         break;
79
80                 case PROP_DLNA_EXTENDED:
81                         g_value_set_boolean (value, priv->extended);
82                         break;
83
84                 default:
85                         G_OBJECT_WARN_INVALID_PROPERTY_ID (object,
86                                                            property_id,
87                                                            pspec);
88                         break;
89         }
90 }
91
92 static void
93 gupnp_dlna_profile_set_property (GObject      *object,
94                                  guint         property_id,
95                                  const GValue *value,
96                                  GParamSpec   *pspec)
97 {
98         GUPnPDLNAProfile *self = GUPNP_DLNA_PROFILE (object);
99         GUPnPDLNAProfilePrivate *priv = GET_PRIVATE (self);
100
101         switch (property_id) {
102                 case PROP_DLNA_NAME:
103                         g_free (priv->name);
104                         priv->name = g_value_dup_string (value);
105                         break;
106
107                 case PROP_DLNA_MIME:
108                         g_free (priv->mime);
109                         priv->mime = g_value_dup_string (value);
110                         break;
111
112                 case PROP_ENCODING_PROFILE:
113                         if (priv->enc_profile)
114                                 gst_encoding_profile_free (priv->enc_profile);
115                         priv->enc_profile = g_value_dup_boxed (value);
116                         break;
117
118                 case PROP_DLNA_EXTENDED:
119                         priv->extended = g_value_get_boolean (value);
120                         break;
121
122                 default:
123                         G_OBJECT_WARN_INVALID_PROPERTY_ID (object,
124                                                            property_id,
125                                                            pspec);
126                         break;
127   }
128 }
129 static void
130 gupnp_dlna_profile_finalize (GObject *object)
131 {
132         GUPnPDLNAProfile *self = GUPNP_DLNA_PROFILE (object);
133         GUPnPDLNAProfilePrivate *priv = GET_PRIVATE (self);
134
135         g_free (priv->name);
136         g_free (priv->mime);
137         if (priv->enc_profile)
138                 gst_encoding_profile_free (priv->enc_profile);
139
140         G_OBJECT_CLASS (gupnp_dlna_profile_parent_class)->finalize (object);
141 }
142
143 static void
144 gupnp_dlna_profile_class_init (GUPnPDLNAProfileClass *klass)
145 {
146         GObjectClass *object_class = G_OBJECT_CLASS (klass);
147         GParamSpec *pspec;
148
149         g_type_class_add_private (klass, sizeof (GUPnPDLNAProfilePrivate));
150
151         object_class->get_property = gupnp_dlna_profile_get_property;
152         object_class->set_property = gupnp_dlna_profile_set_property;
153         object_class->finalize = gupnp_dlna_profile_finalize;
154
155         pspec = g_param_spec_string ("name",
156                                      "DLNA profile name",
157                                      "The name of the DLNA profile ",
158                                      NULL,
159                                      G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY);
160         g_object_class_install_property (object_class, PROP_DLNA_NAME, pspec);
161
162         pspec = g_param_spec_string ("mime",
163                                      "DLNA profile MIME type",
164                                      "The MIME type of the DLNA profile",
165                                      NULL,
166                                      G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY);
167         g_object_class_install_property (object_class, PROP_DLNA_MIME, pspec);
168
169         pspec = g_param_spec_boxed ("encoding-profile",
170                                     "Encoding profile for the DLNA profile",
171                                     "GstEncodingProfile object corresponding "
172                                     "to the DLNA profile",
173                                     GST_TYPE_ENCODING_PROFILE,
174                                     G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY);
175         g_object_class_install_property (object_class,
176                                          PROP_ENCODING_PROFILE,
177                                          pspec);
178
179         pspec = g_param_spec_boolean ("extended",
180                                       "Extended mode property",
181                                       "Indicates that this profile is not "
182                                       "part of the DLNA specification",
183                                       FALSE,
184                                       G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY);
185         g_object_class_install_property (object_class,
186                                          PROP_DLNA_EXTENDED,
187                                          pspec);
188
189 }
190
191 static void
192 gupnp_dlna_profile_init (GUPnPDLNAProfile *self)
193 {
194         GUPnPDLNAProfilePrivate *priv = GET_PRIVATE (self);
195
196         priv->name = NULL;
197         priv->mime = NULL;
198         priv->enc_profile = NULL;
199         priv->extended = FALSE;
200 }
201
202 /**
203  * gupnp_dlna_profile_new:
204  *
205  * Creates a new #GUPnPDLNAProfile object.
206  *
207  * Returns: A new #GUPnPDLNAProfile object.
208  */
209 GUPnPDLNAProfile*
210 gupnp_dlna_profile_new (gchar              *name,
211                         gchar              *mime,
212                         GstEncodingProfile *enc_profile,
213                         gboolean           extended)
214 {
215         return g_object_new (GUPNP_TYPE_DLNA_PROFILE,
216                              "name", name,
217                              "mime", mime,
218                              "encoding-profile", enc_profile,
219                              "extended", extended,
220                              NULL);
221 }
222
223 /**
224  * gupnp_dlna_profile_get_name:
225  * @self: The #GUPnPDLNAProfile object
226  *
227  * Returns: the name of the DLNA profile represented by @self
228  */
229 const gchar *
230 gupnp_dlna_profile_get_name (GUPnPDLNAProfile *self)
231 {
232         GUPnPDLNAProfilePrivate *priv = GET_PRIVATE (self);
233         return priv->name;
234 }
235
236 /**
237  * gupnp_dlna_profile_get_mime:
238  * @self: The #GUPnPDLNAProfile object
239  *
240  * Returns: the DLNA MIME type of the DLNA profile represented by @self
241  */
242 const gchar *
243 gupnp_dlna_profile_get_mime (GUPnPDLNAProfile *self)
244 {
245         GUPnPDLNAProfilePrivate *priv = GET_PRIVATE (self);
246         return priv->mime;
247 }
248
249 /**
250  * gupnp_dlna_profile_get_encoding_profile:
251  * @self: The #GUPnPDLNAProfile object
252  *
253  * Returns: a #GstEncodingProfile object that, in a future version, can be used
254  *          to transcode a given stream to match the DLNA profile represented
255  *          by @self.
256  */
257 const GstEncodingProfile *
258 gupnp_dlna_profile_get_encoding_profile (GUPnPDLNAProfile *self)
259 {
260         GUPnPDLNAProfilePrivate *priv = GET_PRIVATE (self);
261         return priv->enc_profile;
262 }
263
264 /**
265  * gupnp_dlna_profile_get_extended:
266  * @self: The #GUPnPDLNAProfile object
267  *
268  * Returns: true if application is using extended mode and false otherwise
269  */
270 gboolean
271 gupnp_dlna_profile_get_extended (GUPnPDLNAProfile *self)
272 {
273         GUPnPDLNAProfilePrivate *priv = GET_PRIVATE (self);
274         return priv->extended;
275 }