[vlc-commits] UPNP: set input item duration if available in UPNP response.

Konstantin Pavlov git at videolan.org
Wed Apr 20 15:57:35 CEST 2011


vlc | branch: master | Konstantin Pavlov <thresh at videolan.org> | Wed Apr 20 16:21:51 2011 +0400| [b6f472bae9e01ad875858e4d89a3e2d3e1a810f6] | committer: Konstantin Pavlov

UPNP: set input item duration if available in UPNP response.

> http://git.videolan.org/gitweb.cgi/vlc.git/?a=commit;h=b6f472bae9e01ad875858e4d89a3e2d3e1a810f6
---

 modules/services_discovery/upnp.cpp |   62 ++++++++++++++++++++++++++++++++---
 modules/services_discovery/upnp.hpp |    5 ++-
 2 files changed, 61 insertions(+), 6 deletions(-)

diff --git a/modules/services_discovery/upnp.cpp b/modules/services_discovery/upnp.cpp
index 151bcb7..7c8cc10 100644
--- a/modules/services_discovery/upnp.cpp
+++ b/modules/services_discovery/upnp.cpp
@@ -25,6 +25,8 @@
  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
  *****************************************************************************/
 
+#define __STDC_CONSTANT_MACROS 1
+
 #undef PACKAGE_NAME
 #ifdef HAVE_CONFIG_H
 # include "config.h"
@@ -75,6 +77,10 @@ static int Callback( Upnp_EventType event_type, void* p_event, void* p_user_data
 const char* xml_getChildElementValue( IXML_Element* p_parent,
                                       const char*   psz_tag_name );
 
+const char* xml_getChildElementAttributeValue( IXML_Element* p_parent,
+                                        const char* psz_tag_name_,
+                                        const char* psz_attribute_ );
+
 IXML_Document* parseBrowseResult( IXML_Document* p_doc );
 
 
@@ -166,6 +172,24 @@ const char* xml_getChildElementValue( IXML_Element* p_parent,
     return ixmlNode_getNodeValue( p_text_node );
 }
 
+const char* xml_getChildElementAttributeValue( IXML_Element* p_parent,
+                                        const char* psz_tag_name_,
+                                        const char* psz_attribute_ )
+{
+    if ( !p_parent ) return NULL;
+    if ( !psz_tag_name_ ) return NULL;
+    if ( !psz_attribute_ ) return NULL;
+
+    IXML_NodeList* p_node_list = ixmlElement_getElementsByTagName( p_parent, psz_tag_name_ );
+    if ( !p_node_list ) return NULL;
+
+    IXML_Node* p_element = ixmlNodeList_item( p_node_list, 0 );
+    ixmlNodeList_free( p_node_list );
+    if ( !p_element ) return NULL;
+
+    return ixmlElement_getAttribute( (IXML_Element*) p_element, psz_attribute_ );
+}
+
 // Extracts the result document from a SOAP response
 IXML_Document* parseBrowseResult( IXML_Document* p_doc )
 {
@@ -740,7 +764,7 @@ bool MediaServer::_fetchContents( Container* p_parent )
 
             if ( resource && childCount < 1 )
             {
-                Item* item = new Item( p_parent, objectID, title, resource );
+                Item* item = new Item( p_parent, objectID, title, resource, -1 );
                 p_parent->addItem( item );
             }
 
@@ -783,7 +807,24 @@ bool MediaServer::_fetchContents( Container* p_parent )
             if ( !resource )
                 continue;
 
-            Item* item = new Item( p_parent, objectID, title, resource );
+            const char* psz_duration = xml_getChildElementAttributeValue( itemElement,
+                                                                    "res",
+                                                                    "duration" );
+
+            mtime_t i_duration = -1;
+            int i_hours, i_minutes, i_seconds, i_decis;
+
+            if ( psz_duration )
+            {
+                if( sscanf( psz_duration, "%02d:%02d:%02d.%d",
+                        &i_hours, &i_minutes, &i_seconds, &i_decis ))
+                    i_duration = INT64_C(1000000) * ( i_hours*3600 +
+                                                      i_minutes*60 +
+                                                      i_seconds ) +
+                                 INT64_C(100000) * i_decis;
+            }
+
+            Item* item = new Item( p_parent, objectID, title, resource, i_duration );
             p_parent->addItem( item );
         }
         ixmlNodeList_free( itemNodeList );
@@ -849,9 +890,14 @@ void MediaServer::_buildPlaylist( Container* p_parent, input_item_node_t *p_inpu
     {
         Item* p_item = p_parent->getItem( i );
 
-        input_item_t* p_input_item = input_item_New( _p_sd,
+        input_item_t* p_input_item = input_item_NewExt( _p_sd,
                                                p_item->getResource(),
-                                               p_item->getTitle() );
+                                               p_item->getTitle(),
+                                               0,
+                                               NULL,
+                                               0,
+                                               p_item->getDuration() );
+
         assert( p_input_item );
         input_item_node_AppendItem( p_input_node, p_input_item );
         p_item->setInputItem( p_input_item );
@@ -974,13 +1020,14 @@ void MediaServerList::removeServer( const char* psz_udn )
 // Item...
 
 Item::Item( Container* p_parent, const char* psz_object_id, const char* psz_title,
-           const char* psz_resource )
+           const char* psz_resource, mtime_t i_duration )
 {
     _parent = p_parent;
 
     _objectID = psz_object_id;
     _title = psz_title;
     _resource = psz_resource;
+    _duration = i_duration;
 
     _p_input_item = NULL;
 }
@@ -1006,6 +1053,11 @@ const char* Item::getResource() const
     return _resource.c_str();
 }
 
+const mtime_t Item::getDuration() const
+{
+    return _duration;
+}
+
 void Item::setInputItem( input_item_t* p_input_item )
 {
     if( _p_input_item == p_input_item )
diff --git a/modules/services_discovery/upnp.hpp b/modules/services_discovery/upnp.hpp
index b3a3f47..9469c02 100644
--- a/modules/services_discovery/upnp.hpp
+++ b/modules/services_discovery/upnp.hpp
@@ -119,12 +119,14 @@ public:
     Item( Container*  parent,
           const char* objectID,
           const char* title,
-          const char* resource );
+          const char* resource,
+          mtime_t duration );
     ~Item();
 
     const char* getObjectID() const;
     const char* getTitle() const;
     const char* getResource() const;
+    const mtime_t getDuration() const;
 
     void setInputItem( input_item_t* p_input_item );
 
@@ -136,6 +138,7 @@ private:
     std::string _objectID;
     std::string _title;
     std::string _resource;
+    mtime_t _duration;
 };
 
 



More information about the vlc-commits mailing list