2 * Copyright (C) 2009 Nokia Corporation.
3 * Copyright (C) 2007, 2008 OpenedHand Ltd.
4 * Copyright (C) 2012 Intel Corporation
6 * Authors: Zeeshan Ali (Khattak) <zeeshan.ali@nokia.com>
7 * <zeeshanak@gnome.org>
8 * Jorn Baayen <jorn@openedhand.com>
9 * Krzesimir Nowak <krnowak@openismus.com>
11 * This library is free software; you can redistribute it and/or
12 * modify it under the terms of the GNU Library General Public
13 * License as published by the Free Software Foundation; either
14 * version 2 of the License, or (at your option) any later version.
16 * This library is distributed in the hope that it will be useful,
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
19 * Library General Public License for more details.
21 * You should have received a copy of the GNU Library General Public
22 * License along with this library; if not, write to the
23 * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
24 * Boston, MA 02110-1301, USA.
28 * SECTION:gupnp-didl-lite-resource
29 * @short_description: DIDL-Lite Resource
31 * #GUPnPDIDLLiteResource respresent a DIDL-Lite resource (res) element.
36 #include "gupnp-didl-lite-resource.h"
38 #include "time-utils.h"
40 G_DEFINE_TYPE (GUPnPDIDLLiteResource,
41 gupnp_didl_lite_resource,
44 struct _GUPnPDIDLLiteResourcePrivate {
48 GUPnPProtocolInfo *protocol_info;
79 get_resolution_info (GUPnPDIDLLiteResource *resource,
83 const char *resolution;
86 resolution = xml_util_get_attribute_content (resource->priv->xml_node,
88 if (resolution == NULL)
91 tokens = g_strsplit (resolution, "x", -1);
92 if (tokens == NULL || tokens[0] == NULL || tokens[1] == NULL) {
93 g_warning ("Failed to resolution string '%s'\n", resolution);
99 *width = atoi (tokens[0]);
101 *height = atoi (tokens[1]);
108 on_protocol_info_changed (GUPnPProtocolInfo *info,
112 GUPnPDIDLLiteResource *resource = GUPNP_DIDL_LITE_RESOURCE (user_data);
114 gupnp_didl_lite_resource_set_protocol_info (resource, info);
118 gupnp_didl_lite_resource_init (GUPnPDIDLLiteResource *resource)
120 resource->priv = G_TYPE_INSTANCE_GET_PRIVATE
122 GUPNP_TYPE_DIDL_LITE_RESOURCE,
123 GUPnPDIDLLiteResourcePrivate);
127 gupnp_didl_lite_resource_set_property (GObject *object,
132 GUPnPDIDLLiteResource *resource;
134 resource = GUPNP_DIDL_LITE_RESOURCE (object);
136 switch (property_id) {
138 resource->priv->xml_node = g_value_get_pointer (value);
141 resource->priv->xml_doc = g_value_dup_object (value);
144 gupnp_didl_lite_resource_set_uri (resource,
145 g_value_get_string (value));
147 case PROP_IMPORT_URI:
148 gupnp_didl_lite_resource_set_import_uri
150 g_value_get_string (value));
152 case PROP_PROTOCOL_INFO:
153 gupnp_didl_lite_resource_set_protocol_info
155 g_value_get_object (value));
158 gupnp_didl_lite_resource_set_size (resource,
159 g_value_get_long (value));
162 gupnp_didl_lite_resource_set_size64 (resource,
163 g_value_get_int64 (value));
166 gupnp_didl_lite_resource_set_duration
168 g_value_get_long (value));
171 gupnp_didl_lite_resource_set_bitrate (resource,
172 g_value_get_int (value));
174 case PROP_SAMPLE_FREQ:
175 gupnp_didl_lite_resource_set_sample_freq
177 g_value_get_int (value));
179 case PROP_BITS_PER_SAMPLE:
180 gupnp_didl_lite_resource_set_bits_per_sample
182 g_value_get_int (value));
184 case PROP_PROTECTION:
185 gupnp_didl_lite_resource_set_protection
187 g_value_get_string (value));
189 case PROP_AUDIO_CHANNELS:
190 gupnp_didl_lite_resource_set_audio_channels
192 g_value_get_int (value));
195 gupnp_didl_lite_resource_set_width (resource,
196 g_value_get_int (value));
199 gupnp_didl_lite_resource_set_height (resource,
200 g_value_get_int (value));
202 case PROP_COLOR_DEPTH:
203 gupnp_didl_lite_resource_set_color_depth
205 g_value_get_int (value));
207 case PROP_UPDATE_COUNT:
208 gupnp_didl_lite_resource_set_update_count
210 g_value_get_uint (value));
213 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
219 gupnp_didl_lite_resource_get_property (GObject *object,
224 GUPnPDIDLLiteResource *resource;
226 resource = GUPNP_DIDL_LITE_RESOURCE (object);
228 switch (property_id) {
232 gupnp_didl_lite_resource_get_xml_node (resource));
237 gupnp_didl_lite_resource_get_uri (resource));
239 case PROP_IMPORT_URI:
242 gupnp_didl_lite_resource_get_import_uri (resource));
244 case PROP_PROTOCOL_INFO:
247 gupnp_didl_lite_resource_get_protocol_info (resource));
250 g_value_set_long (value,
251 gupnp_didl_lite_resource_get_size (resource));
254 g_value_set_int64 (value,
255 gupnp_didl_lite_resource_get_size64 (resource));
260 gupnp_didl_lite_resource_get_duration (resource));
265 gupnp_didl_lite_resource_get_bitrate (resource));
267 case PROP_BITS_PER_SAMPLE:
270 gupnp_didl_lite_resource_get_bits_per_sample
273 case PROP_SAMPLE_FREQ:
276 gupnp_didl_lite_resource_get_sample_freq (resource));
278 case PROP_PROTECTION:
281 gupnp_didl_lite_resource_get_protection (resource));
283 case PROP_AUDIO_CHANNELS:
286 gupnp_didl_lite_resource_get_audio_channels
290 g_value_set_int (value,
291 gupnp_didl_lite_resource_get_width (resource));
296 gupnp_didl_lite_resource_get_height (resource));
298 case PROP_COLOR_DEPTH:
301 gupnp_didl_lite_resource_get_color_depth (resource));
303 case PROP_UPDATE_COUNT:
306 gupnp_didl_lite_resource_get_update_count (resource));
309 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
315 gupnp_didl_lite_resource_dispose (GObject *object)
317 GObjectClass *object_class;
318 GUPnPDIDLLiteResourcePrivate *priv;
320 priv = GUPNP_DIDL_LITE_RESOURCE (object)->priv;
323 g_object_unref (priv->xml_doc);
324 priv->xml_doc = NULL;
327 if (priv->protocol_info != NULL) {
328 g_object_unref (priv->protocol_info);
329 priv->protocol_info = NULL;
332 object_class = G_OBJECT_CLASS (gupnp_didl_lite_resource_parent_class);
333 object_class->dispose (object);
337 gupnp_didl_lite_resource_class_init (GUPnPDIDLLiteResourceClass *klass)
339 GObjectClass *object_class;
341 object_class = G_OBJECT_CLASS (klass);
343 object_class->set_property = gupnp_didl_lite_resource_set_property;
344 object_class->get_property = gupnp_didl_lite_resource_get_property;
345 object_class->dispose = gupnp_didl_lite_resource_dispose;
347 g_type_class_add_private (klass, sizeof (GUPnPDIDLLiteResourcePrivate));
350 * GUPnPDIDLLiteResource:xml-node:
352 * The pointer to res node in XML document.
354 g_object_class_install_property
357 g_param_spec_pointer ("xml-node",
359 "The pointer to res node in XML"
362 G_PARAM_CONSTRUCT_ONLY |
363 G_PARAM_STATIC_NAME |
364 G_PARAM_STATIC_NICK |
365 G_PARAM_STATIC_BLURB));
368 * GUPnPDIDLLiteResource:xml-doc:
370 * The reference to XML document containing this object.
376 g_object_class_install_property
379 g_param_spec_object ("xml-doc",
381 "The reference to XML document"
382 " containing this object.",
385 G_PARAM_CONSTRUCT_ONLY |
386 G_PARAM_STATIC_NAME |
387 G_PARAM_STATIC_NICK |
388 G_PARAM_STATIC_BLURB));
391 * GUPnPDIDLLiteResource:uri:
393 * The URI associated with this resource.
395 g_object_class_install_property
398 g_param_spec_string ("uri",
400 "The URI associated with this resource",
403 G_PARAM_STATIC_NAME |
404 G_PARAM_STATIC_NICK |
405 G_PARAM_STATIC_BLURB));
408 * GUPnPDIDLLiteResource:import-uri:
410 * The Import URI associated with this resource.
412 g_object_class_install_property
415 g_param_spec_string ("import-uri",
417 "The import URI associated with this"
421 G_PARAM_STATIC_NAME |
422 G_PARAM_STATIC_NICK |
423 G_PARAM_STATIC_BLURB));
426 * GUPnPDIDLLiteResource:protocol-info:
428 * The protocol info associated with this resource.
430 g_object_class_install_property
433 g_param_spec_object ("protocol-info",
435 "The protocol info associated with this"
437 GUPNP_TYPE_PROTOCOL_INFO,
439 G_PARAM_STATIC_NAME |
440 G_PARAM_STATIC_NICK |
441 G_PARAM_STATIC_BLURB));
444 * GUPnPDIDLLiteResource:size:
446 * The size (in bytes) of this resource.
448 g_object_class_install_property
451 g_param_spec_long ("size",
453 "The size (in bytes) of this resource.",
458 G_PARAM_STATIC_NAME |
459 G_PARAM_STATIC_NICK |
460 G_PARAM_STATIC_BLURB));
463 * GUPnPDIDLLiteResource:size64:
465 * The size (in bytes) of this resource.
467 g_object_class_install_property
470 g_param_spec_int64 ("size64",
472 "The size (in bytes) of this resource.",
477 G_PARAM_STATIC_NAME |
478 G_PARAM_STATIC_NICK |
479 G_PARAM_STATIC_BLURB));
482 * GUPnPDIDLLiteResource:duration:
484 * The duration (in seconds) of this resource.
486 g_object_class_install_property
489 g_param_spec_long ("duration",
491 "The duration (in seconds) of this"
497 G_PARAM_STATIC_NAME |
498 G_PARAM_STATIC_NICK |
499 G_PARAM_STATIC_BLURB));
502 * GUPnPDIDLLiteResource:bitrate:
504 * The bitrate of this resource.
506 g_object_class_install_property
509 g_param_spec_int ("bitrate",
511 "The bitrate of this resource.",
516 G_PARAM_STATIC_NAME |
517 G_PARAM_STATIC_NICK |
518 G_PARAM_STATIC_BLURB));
521 * GUPnPDIDLLiteResource:sample-freq:
523 * The sample frequency of this resource.
525 g_object_class_install_property
528 g_param_spec_int ("sample-freq",
530 "The sample frequency of this resource.",
535 G_PARAM_STATIC_NAME |
536 G_PARAM_STATIC_NICK |
537 G_PARAM_STATIC_BLURB));
540 * GUPnPDIDLLiteResource:bits-per-sample:
542 * The sample size of this resource.
544 g_object_class_install_property
546 PROP_BITS_PER_SAMPLE,
547 g_param_spec_int ("bits-per-sample",
549 "The sample size of this resource.",
554 G_PARAM_STATIC_NAME |
555 G_PARAM_STATIC_NICK |
556 G_PARAM_STATIC_BLURB));
559 * GUPnPDIDLLiteResource:protection:
561 * The protection system used for this resource.
563 g_object_class_install_property
566 g_param_spec_string ("protection",
568 "The protection system used by this"
572 G_PARAM_STATIC_NAME |
573 G_PARAM_STATIC_NICK |
574 G_PARAM_STATIC_BLURB));
577 * GUPnPDIDLLiteResource:audio-channels:
579 * The number of audio channels in this resource.
581 g_object_class_install_property
584 g_param_spec_int ("audio-channels",
586 "The number of audio channels in this"
592 G_PARAM_STATIC_NAME |
593 G_PARAM_STATIC_NICK |
594 G_PARAM_STATIC_BLURB));
597 * GUPnPDIDLLiteResource:width:
599 * The width of this image/video resource.
601 g_object_class_install_property
604 g_param_spec_int ("width",
606 "The width of this image/video resource.",
611 G_PARAM_STATIC_NAME |
612 G_PARAM_STATIC_NICK |
613 G_PARAM_STATIC_BLURB));
616 * GUPnPDIDLLiteResource:height:
618 * The height of this image/video resource.
620 g_object_class_install_property
623 g_param_spec_int ("height",
625 "The height of this image/video resource.",
630 G_PARAM_STATIC_NAME |
631 G_PARAM_STATIC_NICK |
632 G_PARAM_STATIC_BLURB));
635 * GUPnPDIDLLiteResource:color-depth:
637 * The color-depth of this image/video resource.
639 g_object_class_install_property
642 g_param_spec_int ("color-depth",
644 "The color-depth of this image/video"
650 G_PARAM_STATIC_NAME |
651 G_PARAM_STATIC_NICK |
652 G_PARAM_STATIC_BLURB));
655 * GUPnPDIDLLiteResource:update_count:
657 * The update count of this resource.
659 g_object_class_install_property
662 g_param_spec_uint ("update-count",
664 "The update count of this resource.",
669 G_PARAM_STATIC_NAME |
670 G_PARAM_STATIC_NICK |
671 G_PARAM_STATIC_BLURB));
675 * gupnp_didl_lite_resource_new_from_xml:
676 * @xml_node: The pointer to 'res' node in XML document
677 * @xml_doc: The reference to XML document containing this resource
679 * Creates a new #GUPnPDIDLLiteResource for the @xml_node.
681 * Return value: A new #GUPnPDIDLLiteResource object. Unref after usage.
683 GUPnPDIDLLiteResource *
684 gupnp_didl_lite_resource_new_from_xml (xmlNode *xml_node,
685 GUPnPXMLDoc *xml_doc)
687 GUPnPDIDLLiteResource *resource;
689 return g_object_new (GUPNP_TYPE_DIDL_LITE_RESOURCE,
690 "xml-node", xml_node,
698 * gupnp_didl_lite_resource_get_xml_node:
699 * @resource: The #GUPnPDIDLLiteResource
701 * Get the pointer to res node in XML document.
703 * Returns: (transfer none): The pointer to res node in XML document.
706 gupnp_didl_lite_resource_get_xml_node (GUPnPDIDLLiteResource *resource)
708 g_return_val_if_fail (GUPNP_IS_DIDL_LITE_RESOURCE (resource), NULL);
710 return resource->priv->xml_node;
714 * gupnp_didl_lite_resource_get_uri:
715 * @resource: A #GUPnPDIDLLiteResource
717 * Get the URI associated with the @resource.
719 * Return value: The of URI the @resource or %NULL.
722 gupnp_didl_lite_resource_get_uri (GUPnPDIDLLiteResource *resource)
724 g_return_val_if_fail (GUPNP_IS_DIDL_LITE_RESOURCE (resource), NULL);
726 if (G_UNLIKELY (resource->priv->xml_node->children == NULL))
729 return (const char *) resource->priv->xml_node->children->content;
733 * gupnp_didl_lite_resource_get_import_uri:
734 * @resource: A #GUPnPDIDLLiteResource
736 * Get the import URI associated with the @resource.
738 * Return value: The import URI or %NULL.
741 gupnp_didl_lite_resource_get_import_uri (GUPnPDIDLLiteResource *resource)
743 g_return_val_if_fail (GUPNP_IS_DIDL_LITE_RESOURCE (resource), NULL);
745 return xml_util_get_attribute_content (resource->priv->xml_node,
750 * gupnp_didl_lite_resource_get_protocol_info:
751 * @resource: A #GUPnPDIDLLiteResource
753 * Get the protocol info associated with the @resource.
755 * Returns: (transfer none): The protocol info associated with the @resource or %NULL. The
756 * returned object must not be unrefed.
759 gupnp_didl_lite_resource_get_protocol_info (GUPnPDIDLLiteResource *resource)
761 GUPnPProtocolInfo *info;
762 const char *protocol_info;
765 g_return_val_if_fail (GUPNP_IS_DIDL_LITE_RESOURCE (resource), NULL);
767 if (resource->priv->protocol_info != NULL)
768 return resource->priv->protocol_info;
770 protocol_info = xml_util_get_attribute_content
771 (resource->priv->xml_node,
773 g_return_val_if_fail (protocol_info != NULL, NULL);
776 info = gupnp_protocol_info_new_from_string (protocol_info, &error);
778 g_warning ("Error parsing protocolInfo '%s': %s",
782 g_error_free (error);
785 resource->priv->protocol_info = info;
791 * gupnp_didl_lite_resource_get_size:
792 * @resource: A #GUPnPDIDLLiteResource
794 * Get the size (in bytes) of the @resource.
796 * Return value: The size (in bytes) of the @resource or -1.
799 gupnp_didl_lite_resource_get_size (GUPnPDIDLLiteResource *resource)
801 return (glong) gupnp_didl_lite_resource_get_size64 (resource);
805 * gupnp_didl_lite_resource_get_size64:
806 * @resource: A #GUPnPDIDLLiteResource
808 * Get the size (in bytes) of the @resource.
810 * Return value: The size (in bytes) of the @resource or -1.
813 gupnp_didl_lite_resource_get_size64 (GUPnPDIDLLiteResource *resource)
815 g_return_val_if_fail (GUPNP_IS_DIDL_LITE_RESOURCE (resource), -1);
817 return xml_util_get_int64_attribute (resource->priv->xml_node,
824 * gupnp_didl_lite_resource_get_duration:
825 * @resource: A #GUPnPDIDLLiteResource
827 * Get the duration (in seconds) of the @resource.
829 * Return value: The duration (in seconds) of the @resource or -1.
832 gupnp_didl_lite_resource_get_duration (GUPnPDIDLLiteResource *resource)
834 const char *duration_str;
837 g_return_val_if_fail (GUPNP_IS_DIDL_LITE_RESOURCE (resource), -1);
839 duration_str = xml_util_get_attribute_content (resource->priv->xml_node,
841 duration = seconds_from_time (duration_str);
847 * gupnp_didl_lite_resource_get_bitrate:
848 * @resource: A #GUPnPDIDLLiteResource
850 * Get the bitrate (in bytes per second) of the @resource.
852 * Return value: The bitrate (in bytes per second) of the @resource or -1.
855 gupnp_didl_lite_resource_get_bitrate (GUPnPDIDLLiteResource *resource)
857 g_return_val_if_fail (GUPNP_IS_DIDL_LITE_RESOURCE (resource), -1);
859 return xml_util_get_long_attribute (resource->priv->xml_node,
865 * gupnp_didl_lite_resource_get_sample_freq:
866 * @resource: A #GUPnPDIDLLiteResource
868 * Get the sample frequency of the @resource.
870 * Return value: The sample frequency of the @resource or -1.
873 gupnp_didl_lite_resource_get_sample_freq (GUPnPDIDLLiteResource *resource)
875 g_return_val_if_fail (GUPNP_IS_DIDL_LITE_RESOURCE (resource), -1);
877 return xml_util_get_long_attribute (resource->priv->xml_node,
883 * gupnp_didl_lite_resource_get_bits_per_sample:
884 * @resource: A #GUPnPDIDLLiteResource
886 * Get the sample size of the @resource.
888 * Return value: The number of bits per sample of the @resource or -1.
891 gupnp_didl_lite_resource_get_bits_per_sample (GUPnPDIDLLiteResource *resource)
893 g_return_val_if_fail (GUPNP_IS_DIDL_LITE_RESOURCE (resource), -1);
895 return xml_util_get_long_attribute (resource->priv->xml_node,
901 * gupnp_didl_lite_resource_get_protection:
902 * @resource: A #GUPnPDIDLLiteResource
904 * Get the protection system used by the @resource.
906 * Return value: The protection system in use by the @resource or %NULL.
909 gupnp_didl_lite_resource_get_protection (GUPnPDIDLLiteResource *resource)
911 g_return_val_if_fail (GUPNP_IS_DIDL_LITE_RESOURCE (resource), NULL);
913 return xml_util_get_attribute_content (resource->priv->xml_node,
918 * gupnp_didl_lite_resource_get_audio_channels:
919 * @resource: A #GUPnPDIDLLiteResource
921 * Get the number of audio channels in the @resource.
923 * Return value: The number of audio channels in the @resource or -1.
926 gupnp_didl_lite_resource_get_audio_channels (GUPnPDIDLLiteResource *resource)
928 g_return_val_if_fail (GUPNP_IS_DIDL_LITE_RESOURCE (resource), -1);
930 return xml_util_get_long_attribute (resource->priv->xml_node,
936 * gupnp_didl_lite_resource_get_width:
937 * @resource: A #GUPnPDIDLLiteResource
939 * Get the width of this image/video resource.
941 * Return value: The width of this image/video resource or -1.
944 gupnp_didl_lite_resource_get_width (GUPnPDIDLLiteResource *resource)
948 g_return_val_if_fail (GUPNP_IS_DIDL_LITE_RESOURCE (resource), -1);
950 get_resolution_info (resource, &width, NULL);
956 * gupnp_didl_lite_resource_get_height:
957 * @resource: A #GUPnPDIDLLiteResource
959 * Get the height of this image/video resource.
961 * Return value: The height of the @resource or -1.
964 gupnp_didl_lite_resource_get_height (GUPnPDIDLLiteResource *resource)
968 g_return_val_if_fail (GUPNP_IS_DIDL_LITE_RESOURCE (resource), -1);
970 get_resolution_info (resource, NULL, &height);
976 * gupnp_didl_lite_resource_get_color_depth:
977 * @resource: A #GUPnPDIDLLiteResource
979 * Get the color-depth of this image/video resource.
981 * Return value: The color depth of the @resource or -1.
984 gupnp_didl_lite_resource_get_color_depth (GUPnPDIDLLiteResource *resource)
986 g_return_val_if_fail (GUPNP_IS_DIDL_LITE_RESOURCE (resource), -1);
988 return xml_util_get_long_attribute (resource->priv->xml_node,
994 * gupnp_didl_lite_resource_get_update_count:
995 * @resource: A #GUPnPDIDLLiteResource
997 * Get the update count of this resource.
999 * Return value: The update count of the @resource.
1002 gupnp_didl_lite_resource_get_update_count (GUPnPDIDLLiteResource *resource)
1004 g_return_val_if_fail (GUPNP_IS_DIDL_LITE_RESOURCE (resource), 0);
1006 return xml_util_get_uint_attribute (resource->priv->xml_node,
1012 * gupnp_didl_lite_resource_update_count_is_set:
1013 * @resource: A #GUPnPDIDLLiteResource
1015 * Check whether the update count property of this resource is set.
1017 * Return value: %TRUE if set, otherwise %FALSE.
1020 gupnp_didl_lite_resource_update_count_is_set (GUPnPDIDLLiteResource *resource)
1022 const char *content;
1024 g_return_val_if_fail (GUPNP_IS_DIDL_LITE_RESOURCE (resource), FALSE);
1026 content = xml_util_get_attribute_content (resource->priv->xml_node,
1028 return content != NULL;
1032 * gupnp_didl_lite_resource_set_uri:
1033 * @resource: A #GUPnPDIDLLiteResource
1034 * @uri: The URI as string
1036 * Set the URI associated with the @resource.
1038 * Return value: None.
1041 gupnp_didl_lite_resource_set_uri (GUPnPDIDLLiteResource *resource,
1046 g_return_if_fail (GUPNP_IS_DIDL_LITE_RESOURCE (resource));
1047 g_return_if_fail (uri != NULL);
1049 escaped = xmlEncodeSpecialChars (resource->priv->xml_doc->doc,
1050 (const unsigned char *) uri);
1051 xmlNodeSetContent (resource->priv->xml_node, escaped);
1054 g_object_notify (G_OBJECT (resource), "uri");
1058 * gupnp_didl_lite_resource_set_import_uri:
1059 * @resource: A #GUPnPDIDLLiteResource
1060 * @import_uri: The URI as string
1062 * Set the import URI associated with the @resource.
1064 * Return value: None.
1067 gupnp_didl_lite_resource_set_import_uri (GUPnPDIDLLiteResource *resource,
1068 const char *import_uri)
1070 g_return_if_fail (GUPNP_IS_DIDL_LITE_RESOURCE (resource));
1072 xmlSetProp (resource->priv->xml_node,
1073 (unsigned char *) "importUri",
1074 (unsigned char *) import_uri);
1076 g_object_notify (G_OBJECT (resource), "import-uri");
1080 * gupnp_didl_lite_resource_set_protocol_info:
1081 * @resource: A #GUPnPDIDLLiteResource
1082 * @info: The protocol string
1084 * Set the protocol info associated with the @resource.
1086 * Return value: None.
1089 gupnp_didl_lite_resource_set_protocol_info (GUPnPDIDLLiteResource *resource,
1090 GUPnPProtocolInfo *info)
1094 g_return_if_fail (GUPNP_IS_DIDL_LITE_RESOURCE (resource));
1095 g_return_if_fail (GUPNP_IS_PROTOCOL_INFO (info));
1097 str = gupnp_protocol_info_to_string (info);
1098 xmlSetProp (resource->priv->xml_node,
1099 (unsigned char *) "protocolInfo",
1100 (unsigned char *) str);
1103 /* Get a ref first in case it's the same object that we already have */
1104 g_object_ref (info);
1105 if (resource->priv->protocol_info != NULL)
1106 g_object_unref (resource->priv->protocol_info);
1107 resource->priv->protocol_info = info;
1109 /* We need to listen to changes to properties so we update the
1110 * corresponding xml property.
1112 g_signal_handlers_disconnect_by_func (info,
1113 on_protocol_info_changed,
1115 g_signal_connect (info,
1117 G_CALLBACK (on_protocol_info_changed),
1120 g_object_notify (G_OBJECT (resource), "protocol-info");
1124 * gupnp_didl_lite_resource_set_size:
1125 * @resource: A #GUPnPDIDLLiteResource
1126 * @size: The size (in bytes)
1128 * Set the size (in bytes) of the @resource. Passing a negative number will
1129 * unset this property.
1131 * Return value: None.
1134 gupnp_didl_lite_resource_set_size (GUPnPDIDLLiteResource *resource,
1137 gupnp_didl_lite_resource_set_size64 (resource, size);
1141 * gupnp_didl_lite_resource_set_size64:
1142 * @resource: A #GUPnPDIDLLiteResource
1143 * @size: The size (in bytes)
1145 * Set the size (in bytes) of the @resource. Passing a negative number will
1146 * unset this property.
1148 * Return value: None.
1151 gupnp_didl_lite_resource_set_size64 (GUPnPDIDLLiteResource *resource,
1154 g_return_if_fail (GUPNP_IS_DIDL_LITE_RESOURCE (resource));
1157 xmlUnsetProp (resource->priv->xml_node,
1158 (unsigned char *) "size");
1162 str = g_strdup_printf ("%" G_GINT64_FORMAT, size);
1163 xmlSetProp (resource->priv->xml_node,
1164 (unsigned char *) "size",
1165 (unsigned char *) str);
1169 g_object_notify (G_OBJECT (resource), "size64");
1170 g_object_notify (G_OBJECT (resource), "size");
1175 * gupnp_didl_lite_resource_set_duration:
1176 * @resource: A #GUPnPDIDLLiteResource
1177 * @duration: The duration (in seconds)
1179 * Set the duration (in seconds) of the @resource. Passing a negative number
1180 * will unset this property.
1182 * Return value: None.
1185 gupnp_didl_lite_resource_set_duration (GUPnPDIDLLiteResource *resource,
1188 g_return_if_fail (GUPNP_IS_DIDL_LITE_RESOURCE (resource));
1191 xmlUnsetProp (resource->priv->xml_node,
1192 (unsigned char *) "duration");
1196 str = seconds_to_time (duration);
1197 xmlSetProp (resource->priv->xml_node,
1198 (unsigned char *) "duration",
1199 (unsigned char *) str);
1203 g_object_notify (G_OBJECT (resource), "duration");
1207 * gupnp_didl_lite_resource_set_bitrate:
1208 * @resource: A #GUPnPDIDLLiteResource
1209 * @bitrate: The bitrate
1211 * Set the bitrate (in bytes per second) of the @resource. Passing a negative
1212 * number will unset this property.
1214 * Return value: None.
1217 gupnp_didl_lite_resource_set_bitrate (GUPnPDIDLLiteResource *resource,
1220 g_return_if_fail (GUPNP_IS_DIDL_LITE_RESOURCE (resource));
1223 xmlUnsetProp (resource->priv->xml_node,
1224 (unsigned char *) "bitrate");
1228 str = g_strdup_printf ("%d", bitrate);
1229 xmlSetProp (resource->priv->xml_node,
1230 (unsigned char *) "bitrate",
1231 (unsigned char *) str);
1235 g_object_notify (G_OBJECT (resource), "bitrate");
1239 * gupnp_didl_lite_resource_set_sample_freq:
1240 * @resource: A #GUPnPDIDLLiteResource
1241 * @sample_freq: The sample frequency
1243 * Set the sample frequency of the @resource. Passing a negative number will
1244 * unset this property.
1246 * Return value: None.
1249 gupnp_didl_lite_resource_set_sample_freq (GUPnPDIDLLiteResource *resource,
1252 g_return_if_fail (GUPNP_IS_DIDL_LITE_RESOURCE (resource));
1254 if (sample_freq < 0)
1255 xmlUnsetProp (resource->priv->xml_node,
1256 (unsigned char *) "sampleFrequency");
1260 str = g_strdup_printf ("%d", sample_freq);
1261 xmlSetProp (resource->priv->xml_node,
1262 (unsigned char *) "sampleFrequency",
1263 (unsigned char *) str);
1267 g_object_notify (G_OBJECT (resource), "sample-freq");
1271 * gupnp_didl_lite_resource_set_bits_per_sample:
1272 * @resource: A #GUPnPDIDLLiteResource
1273 * @sample_size: The number of bits per sample
1275 * Set the sample size of the @resource. Passing a negative number will unset
1278 * Return value: None.
1281 gupnp_didl_lite_resource_set_bits_per_sample
1282 (GUPnPDIDLLiteResource *resource,
1285 g_return_if_fail (GUPNP_IS_DIDL_LITE_RESOURCE (resource));
1287 if (sample_size < 0)
1288 xmlUnsetProp (resource->priv->xml_node,
1289 (unsigned char *) "bitsPerSample");
1293 str = g_strdup_printf ("%d", sample_size);
1294 xmlSetProp (resource->priv->xml_node,
1295 (unsigned char *) "bitsPerSample",
1296 (unsigned char *) str);
1300 g_object_notify (G_OBJECT (resource), "bits-per-sample");
1304 * gupnp_didl_lite_resource_set_protection:
1305 * @resource: A #GUPnPDIDLLiteResource
1306 * @protection: The protection system identifier as string
1308 * Set the protection system used by the @resource. Passing a negative number
1309 * will unset this property.
1311 * Return value: None.
1314 gupnp_didl_lite_resource_set_protection (GUPnPDIDLLiteResource *resource,
1315 const char *protection)
1317 g_return_if_fail (GUPNP_IS_DIDL_LITE_RESOURCE (resource));
1319 xmlSetProp (resource->priv->xml_node,
1320 (unsigned char *) "protection",
1321 (unsigned char *) protection);
1323 g_object_notify (G_OBJECT (resource), "protection");
1327 * gupnp_didl_lite_resource_set_audio_channels:
1328 * @resource: A #GUPnPDIDLLiteResource
1329 * @n_channels: The number of channels
1331 * Set the number of audio channels in the @resource. Passing a negative number
1332 * will unset this property.
1334 * Return value: The number of audio channels in the @resource or -1.
1337 gupnp_didl_lite_resource_set_audio_channels (GUPnPDIDLLiteResource *resource,
1340 g_return_if_fail (GUPNP_IS_DIDL_LITE_RESOURCE (resource));
1343 xmlUnsetProp (resource->priv->xml_node,
1344 (unsigned char *) "nrAudioChannels");
1348 str = g_strdup_printf ("%d", n_channels);
1349 xmlSetProp (resource->priv->xml_node,
1350 (unsigned char *) "nrAudioChannels",
1351 (unsigned char *) str);
1355 g_object_notify (G_OBJECT (resource), "audio-channels");
1359 * gupnp_didl_lite_resource_set_width:
1360 * @resource: A #GUPnPDIDLLiteResource
1363 * Set the width of this image/video resource. Setting both width and height to
1364 * a negative number will unset the resolution property.
1366 * Return value: None.
1369 gupnp_didl_lite_resource_set_width (GUPnPDIDLLiteResource *resource,
1375 g_return_if_fail (GUPNP_IS_DIDL_LITE_RESOURCE (resource));
1377 get_resolution_info (resource, NULL, &height);
1379 if (width < 0 && height < 0)
1380 xmlUnsetProp (resource->priv->xml_node,
1381 (unsigned char *) "resolution");
1383 resolution = g_strdup_printf ("%dx%d", width, height);
1384 xmlSetProp (resource->priv->xml_node,
1385 (unsigned char *) "resolution",
1386 (unsigned char *) resolution);
1387 g_free (resolution);
1390 g_object_notify (G_OBJECT (resource), "width");
1394 * gupnp_didl_lite_resource_set_height:
1395 * @resource: A #GUPnPDIDLLiteResource
1396 * @height: The height
1398 * Set the height of this image/video resource. Setting both width and height to
1399 * a negative number will unset the resolution property.
1401 * Return value: None.
1404 gupnp_didl_lite_resource_set_height (GUPnPDIDLLiteResource *resource,
1409 g_return_if_fail (GUPNP_IS_DIDL_LITE_RESOURCE (resource));
1411 get_resolution_info (resource, &width, NULL);
1413 if (width < 0 && height < 0)
1414 xmlUnsetProp (resource->priv->xml_node,
1415 (unsigned char *) "resolution");
1419 resolution = g_strdup_printf ("%dx%d", width, height);
1420 xmlSetProp (resource->priv->xml_node,
1421 (unsigned char *) "resolution",
1422 (unsigned char *) resolution);
1423 g_free (resolution);
1426 g_object_notify (G_OBJECT (resource), "height");
1430 * gupnp_didl_lite_resource_set_color_depth:
1431 * @resource: A #GUPnPDIDLLiteResource
1432 * @color_depth: The color-depth
1434 * Set the color-depth of this image/video resource. Passing a negative number
1435 * will unset this property.
1437 * Return value: None.
1440 gupnp_didl_lite_resource_set_color_depth (GUPnPDIDLLiteResource *resource,
1443 g_return_if_fail (GUPNP_IS_DIDL_LITE_RESOURCE (resource));
1445 if (color_depth < 0)
1446 xmlUnsetProp (resource->priv->xml_node,
1447 (unsigned char *) "colorDepth");
1451 str = g_strdup_printf ("%d", color_depth);
1452 xmlSetProp (resource->priv->xml_node,
1453 (unsigned char *) "colorDepth",
1454 (unsigned char *) str);
1458 g_object_notify (G_OBJECT (resource), "color-depth");
1462 * gupnp_didl_lite_resource_set_update_count:
1463 * @resource: A #GUPnPDIDLLiteResource
1464 * @update_count: The update_count
1466 * Set the update count of this resource.
1468 * Return value: None.
1471 gupnp_didl_lite_resource_set_update_count (GUPnPDIDLLiteResource *resource,
1476 g_return_if_fail (GUPNP_IS_DIDL_LITE_RESOURCE (resource));
1478 str = g_strdup_printf ("%u", update_count);
1479 xmlSetProp (resource->priv->xml_node,
1480 (unsigned char *) "updateCount",
1481 (unsigned char *) str);
1484 g_object_notify (G_OBJECT (resource), "update-count");
1488 * gupnp_didl_lite_resource_unset_update_count:
1489 * @resource: A #GUPnPDIDLLiteResource
1491 * Unset the update count of this resource.
1493 * Return value: None.
1496 gupnp_didl_lite_resource_unset_update_count (GUPnPDIDLLiteResource *resource)
1498 g_return_if_fail (GUPNP_IS_DIDL_LITE_RESOURCE (resource));
1500 xmlUnsetProp (resource->priv->xml_node,
1501 (unsigned char *) "updateCount");
1503 g_object_notify (G_OBJECT (resource), "update-count");