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.
22 #include "gupnp-dlna-profile.h"
23 #include <gst/gstminiobject.h>
26 * SECTION:gupnp-dlna-profile
27 * @short_description: Object representing a DLNA profile
29 * The #GUPnPDLNADiscoverer object provides a few APIs that return
30 * #GUPnPDLNAProfile objects. These represent a single DLNA profile. Each
31 * #GUPnPDLNAProfile has a name (the name of the DLNA profile), the
32 * corresponding MIME type, and a #GstEncodingProfile which represents the
33 * various audio/video/container restrictions specified for that DLNA profile.
35 G_DEFINE_TYPE (GUPnPDLNAProfile, gupnp_dlna_profile, G_TYPE_OBJECT)
37 #define GET_PRIVATE(o) \
38 (G_TYPE_INSTANCE_GET_PRIVATE ((o), \
39 GUPNP_TYPE_DLNA_PROFILE, \
40 GUPnPDLNAProfilePrivate))
42 typedef struct _GUPnPDLNAProfilePrivate GUPnPDLNAProfilePrivate;
44 struct _GUPnPDLNAProfilePrivate {
47 GstCaps *container_caps;
51 GstEncodingProfile *enc_profile;
58 PROP_ENCODING_PROFILE,
63 gupnp_dlna_profile_get_property (GObject *object,
68 GUPnPDLNAProfile *self = GUPNP_DLNA_PROFILE (object);
69 GUPnPDLNAProfilePrivate *priv = GET_PRIVATE (self);
71 switch (property_id) {
73 g_value_set_string (value, priv->name);
77 g_value_set_string (value, priv->mime);
80 case PROP_ENCODING_PROFILE:
81 gst_value_set_mini_object (value,
82 GST_MINI_OBJECT (priv->enc_profile));
85 case PROP_DLNA_EXTENDED:
86 g_value_set_boolean (value, priv->extended);
90 G_OBJECT_WARN_INVALID_PROPERTY_ID (object,
98 gupnp_dlna_profile_set_property (GObject *object,
103 GUPnPDLNAProfile *self = GUPNP_DLNA_PROFILE (object);
104 GUPnPDLNAProfilePrivate *priv = GET_PRIVATE (self);
106 switch (property_id) {
109 priv->name = g_value_dup_string (value);
114 priv->mime = g_value_dup_string (value);
117 case PROP_DLNA_EXTENDED:
118 priv->extended = g_value_get_boolean (value);
122 G_OBJECT_WARN_INVALID_PROPERTY_ID
123 (object, property_id, pspec);
129 gupnp_dlna_profile_finalize (GObject *object)
131 GUPnPDLNAProfile *self = GUPNP_DLNA_PROFILE (object);
132 GUPnPDLNAProfilePrivate *priv = GET_PRIVATE (self);
137 if (priv->container_caps)
138 gst_caps_unref (priv->container_caps);
139 if (priv->audio_caps)
140 gst_caps_unref (priv->audio_caps);
141 if (priv->video_caps)
142 gst_caps_unref (priv->video_caps);
144 if (priv->enc_profile)
145 gst_encoding_profile_unref (priv->enc_profile);
147 G_OBJECT_CLASS (gupnp_dlna_profile_parent_class)->finalize (object);
151 gupnp_dlna_profile_class_init (GUPnPDLNAProfileClass *klass)
153 GObjectClass *object_class = G_OBJECT_CLASS (klass);
156 g_type_class_add_private (klass, sizeof (GUPnPDLNAProfilePrivate));
158 object_class->get_property = gupnp_dlna_profile_get_property;
159 object_class->set_property = gupnp_dlna_profile_set_property;
160 object_class->finalize = gupnp_dlna_profile_finalize;
162 pspec = g_param_spec_string ("name",
164 "The name of the DLNA profile ",
167 G_PARAM_CONSTRUCT_ONLY);
168 g_object_class_install_property (object_class, PROP_DLNA_NAME, pspec);
170 pspec = g_param_spec_string ("mime",
171 "DLNA profile MIME type",
172 "The MIME type of the DLNA profile",
175 G_PARAM_CONSTRUCT_ONLY);
176 g_object_class_install_property (object_class, PROP_DLNA_MIME, pspec);
178 pspec = gst_param_spec_mini_object ("encoding-profile",
179 "Encoding Profile for the "
181 "GstEncodingProfile object"
182 "corresponding to the DLNA profile",
183 GST_TYPE_ENCODING_PROFILE,
185 g_object_class_install_property (object_class,
186 PROP_ENCODING_PROFILE,
189 pspec = g_param_spec_boolean ("extended",
190 "Extended mode property",
191 "Indicates that this profile is not "
192 "part of the DLNA specification",
195 G_PARAM_CONSTRUCT_ONLY);
196 g_object_class_install_property (object_class,
203 gupnp_dlna_profile_init (GUPnPDLNAProfile *self)
208 gupnp_dlna_profile_get_container_caps (GUPnPDLNAProfile *self)
210 GUPnPDLNAProfilePrivate *priv = GET_PRIVATE (self);
211 return priv->container_caps;
215 gupnp_dlna_profile_get_video_caps (GUPnPDLNAProfile *self)
217 GUPnPDLNAProfilePrivate *priv = GET_PRIVATE (self);
218 return priv->video_caps;
222 gupnp_dlna_profile_get_audio_caps (GUPnPDLNAProfile *self)
224 GUPnPDLNAProfilePrivate *priv = GET_PRIVATE (self);
225 return priv->audio_caps;
229 gupnp_dlna_profile_set_container_caps (GUPnPDLNAProfile *self, GstCaps *caps)
231 GUPnPDLNAProfilePrivate *priv = GET_PRIVATE (self);
233 if (priv->container_caps)
234 gst_caps_unref (priv->container_caps);
235 priv->container_caps = gst_caps_copy (caps);
239 gupnp_dlna_profile_set_video_caps (GUPnPDLNAProfile *self, GstCaps *caps)
241 GUPnPDLNAProfilePrivate *priv = GET_PRIVATE (self);
243 if (priv->video_caps)
244 gst_caps_unref (priv->video_caps);
245 priv->video_caps = gst_caps_copy (caps);
249 gupnp_dlna_profile_set_audio_caps (GUPnPDLNAProfile *self, GstCaps *caps)
251 GUPnPDLNAProfilePrivate *priv = GET_PRIVATE (self);
253 if (priv->audio_caps)
254 gst_caps_unref (priv->audio_caps);
255 priv->audio_caps = gst_caps_copy (caps);
259 gupnp_dlna_profile_new (gchar *name,
261 GstCaps *container_caps,
266 GUPnPDLNAProfile *prof;
268 prof = g_object_new (GUPNP_TYPE_DLNA_PROFILE,
271 "extended", extended,
274 gupnp_dlna_profile_set_container_caps (prof, container_caps);
275 gupnp_dlna_profile_set_video_caps (prof, video_caps);
276 gupnp_dlna_profile_set_audio_caps (prof, audio_caps);
282 * gupnp_dlna_profile_get_name:
283 * @self: The #GUPnPDLNAProfile object
285 * Returns: the name of the DLNA profile represented by @self
288 gupnp_dlna_profile_get_name (GUPnPDLNAProfile *self)
290 GUPnPDLNAProfilePrivate *priv = GET_PRIVATE (self);
295 * gupnp_dlna_profile_get_mime:
296 * @self: The #GUPnPDLNAProfile object
298 * Returns: the DLNA MIME type of the DLNA profile represented by @self
301 gupnp_dlna_profile_get_mime (GUPnPDLNAProfile *self)
303 GUPnPDLNAProfilePrivate *priv = GET_PRIVATE (self);
308 * gupnp_dlna_profile_get_encoding_profile:
309 * @self: The #GUPnPDLNAProfile object
311 * Returns: a #GstEncodingProfile object that, in a future version, can be used
312 * to transcode a given stream to match the DLNA profile represented
314 * The receiver must unref the returned #GstEncodingProfile when done
318 gupnp_dlna_profile_get_encoding_profile (GUPnPDLNAProfile *self)
320 GUPnPDLNAProfilePrivate *priv = GET_PRIVATE (self);
322 /* create an encoding-profile if we don't have one */
323 if (!priv->enc_profile) {
324 GstEncodingContainerProfile *container = NULL;
325 GstEncodingAudioProfile *audio_profile = NULL;
326 GstEncodingVideoProfile *video_profile = NULL;
328 if (GST_IS_CAPS (priv->video_caps) &&
329 !gst_caps_is_empty (priv->video_caps))
330 video_profile = gst_encoding_video_profile_new
331 (priv->video_caps,NULL, NULL, 0);
333 if (GST_IS_CAPS (priv->audio_caps) &&
334 !gst_caps_is_empty (priv->audio_caps))
335 audio_profile = gst_encoding_audio_profile_new
336 (priv->audio_caps,NULL, NULL, 0);
338 if (GST_IS_CAPS (priv->container_caps)) {
339 container = gst_encoding_container_profile_new
342 priv->container_caps,
346 gst_encoding_container_profile_add_profile
348 (GstEncodingProfile *)video_profile);
351 gst_encoding_container_profile_add_profile
353 (GstEncodingProfile *) audio_profile);
355 priv->enc_profile = (GstEncodingProfile *)container;
358 /* Container-less audio */
360 (GstEncodingProfile *)audio_profile;
363 /* Container-less video isn't a possibility
365 g_assert_not_reached ();
369 gst_encoding_profile_ref (priv->enc_profile);
371 return priv->enc_profile;
375 * gupnp_dlna_profile_get_extended:
376 * @self: The #GUPnPDLNAProfile object
378 * Returns: true if application is using extended mode and false otherwise
381 gupnp_dlna_profile_get_extended (GUPnPDLNAProfile *self)
383 GUPnPDLNAProfilePrivate *priv = GET_PRIVATE (self);
384 return priv->extended;