Commit 0cff5611 authored by Hugo Beauzée-Luyssen's avatar Hugo Beauzée-Luyssen

upnp: Fetch the server icon

parent 1bed74fe
...@@ -277,10 +277,12 @@ static void Close( vlc_object_t *p_this ) ...@@ -277,10 +277,12 @@ static void Close( vlc_object_t *p_this )
free( p_sys ); free( p_sys );
} }
MediaServerDesc::MediaServerDesc(const std::string& udn, const std::string& fName, const std::string& loc) MediaServerDesc::MediaServerDesc( const std::string& udn, const std::string& fName,
const std::string& loc, const std::string& iconUrl )
: UDN( udn ) : UDN( udn )
, friendlyName( fName ) , friendlyName( fName )
, location( loc ) , location( loc )
, iconUrl( iconUrl )
, inputItem( NULL ) , inputItem( NULL )
, isSatIp( false ) , isSatIp( false )
{ {
...@@ -332,6 +334,8 @@ bool MediaServerList::addServer( MediaServerDesc* desc ) ...@@ -332,6 +334,8 @@ bool MediaServerList::addServer( MediaServerDesc* desc )
if ( !p_input_item ) if ( !p_input_item )
return false; return false;
if ( desc->iconUrl.empty() == false )
input_item_SetArtworkURL( p_input_item, desc->iconUrl.c_str() );
desc->inputItem = p_input_item; desc->inputItem = p_input_item;
input_item_SetDescription( p_input_item, desc->UDN.c_str() ); input_item_SetDescription( p_input_item, desc->UDN.c_str() );
services_discovery_AddItem( p_sd_, p_input_item, NULL ); services_discovery_AddItem( p_sd_, p_input_item, NULL );
...@@ -435,6 +439,8 @@ void MediaServerList::parseNewServer( IXML_Document *doc, const std::string &loc ...@@ -435,6 +439,8 @@ void MediaServerList::parseNewServer( IXML_Document *doc, const std::string &loc
continue; continue;
} }
std::string iconUrl = getIconURL( p_device_element, psz_base_url );
// We now have basic info, we need to get the content browsing url // We now have basic info, we need to get the content browsing url
// so the access module can browse without fetching the manifest again // so the access module can browse without fetching the manifest again
...@@ -451,11 +457,11 @@ void MediaServerList::parseNewServer( IXML_Document *doc, const std::string &loc ...@@ -451,11 +457,11 @@ void MediaServerList::parseNewServer( IXML_Document *doc, const std::string &loc
char* psz_url = NULL; char* psz_url = NULL;
if ( UpnpResolveURL2( psz_base_url, psz_m3u_url, &psz_url ) == UPNP_E_SUCCESS ) if ( UpnpResolveURL2( psz_base_url, psz_m3u_url, &psz_url ) == UPNP_E_SUCCESS )
{ {
p_server = new(std::nothrow) SD::MediaServerDesc( psz_udn, psz_friendly_name, psz_url ); p_server = new(std::nothrow) SD::MediaServerDesc( psz_udn, psz_friendly_name, psz_url, iconUrl );
free(psz_url); free(psz_url);
} }
} else } else
p_server = new(std::nothrow) SD::MediaServerDesc( psz_udn, psz_friendly_name, psz_m3u_url ); p_server = new(std::nothrow) SD::MediaServerDesc( psz_udn, psz_friendly_name, psz_m3u_url, iconUrl );
if ( unlikely( !p_server ) ) if ( unlikely( !p_server ) )
break; break;
...@@ -485,7 +491,7 @@ void MediaServerList::parseNewServer( IXML_Document *doc, const std::string &loc ...@@ -485,7 +491,7 @@ void MediaServerList::parseNewServer( IXML_Document *doc, const std::string &loc
vlc_UrlClean( &url ); vlc_UrlClean( &url );
p_server = new(std::nothrow) SD::MediaServerDesc( psz_udn, p_server = new(std::nothrow) SD::MediaServerDesc( psz_udn,
psz_friendly_name, psz_url ); psz_friendly_name, psz_url, iconUrl );
p_server->isSatIp = true; p_server->isSatIp = true;
if( !addServer( p_server ) ) { if( !addServer( p_server ) ) {
...@@ -532,7 +538,7 @@ void MediaServerList::parseNewServer( IXML_Document *doc, const std::string &loc ...@@ -532,7 +538,7 @@ void MediaServerList::parseNewServer( IXML_Document *doc, const std::string &loc
if ( UpnpResolveURL( psz_base_url, psz_control_url, psz_url ) == UPNP_E_SUCCESS ) if ( UpnpResolveURL( psz_base_url, psz_control_url, psz_url ) == UPNP_E_SUCCESS )
{ {
SD::MediaServerDesc* p_server = new(std::nothrow) SD::MediaServerDesc( psz_udn, SD::MediaServerDesc* p_server = new(std::nothrow) SD::MediaServerDesc( psz_udn,
psz_friendly_name, psz_url ); psz_friendly_name, psz_url, iconUrl );
free( psz_url ); free( psz_url );
if ( unlikely( !p_server ) ) if ( unlikely( !p_server ) )
break; break;
...@@ -552,6 +558,60 @@ void MediaServerList::parseNewServer( IXML_Document *doc, const std::string &loc ...@@ -552,6 +558,60 @@ void MediaServerList::parseNewServer( IXML_Document *doc, const std::string &loc
ixmlNodeList_free( p_device_list ); ixmlNodeList_free( p_device_list );
} }
std::string MediaServerList::getIconURL( IXML_Element* p_device_elem, const char* psz_base_url )
{
std::string res;
IXML_NodeList* p_icon_lists = ixmlElement_getElementsByTagName( p_device_elem, "iconList" );
if ( p_icon_lists == NULL )
return res;
IXML_Element* p_icon_list = (IXML_Element*)ixmlNodeList_item( p_icon_lists, 0 );
if ( p_icon_list != NULL )
{
IXML_NodeList* p_icons = ixmlElement_getElementsByTagName( p_icon_list, "icon" );
if ( p_icons != NULL )
{
unsigned int maxWidth = 0;
unsigned int maxHeight = 0;
for ( unsigned int i = 0; i < ixmlNodeList_length( p_icons ); ++i )
{
IXML_Element* p_icon = (IXML_Element*)ixmlNodeList_item( p_icons, i );
const char* widthStr = xml_getChildElementValue( p_icon, "width" );
const char* heightStr = xml_getChildElementValue( p_icon, "height" );
if ( widthStr == NULL || heightStr == NULL )
continue;
unsigned int width = atoi( widthStr );
unsigned int height = atoi( heightStr );
if ( width <= maxWidth || height <= maxHeight )
continue;
const char* iconUrl = xml_getChildElementValue( p_icon, "url" );
if ( iconUrl == NULL )
continue;
maxWidth = width;
maxHeight = height;
res = iconUrl;
}
ixmlNodeList_free( p_icons );
}
}
ixmlNodeList_free( p_icon_lists );
if ( res.empty() == false )
{
vlc_url_t url;
vlc_UrlParse( &url, psz_base_url );
char* psz_url;
if ( asprintf( &psz_url, "%s://%s:%u%s", url.psz_protocol, url.psz_host, url.i_port, res.c_str() ) < 0 )
res.clear();
else
{
res = psz_url;
free( psz_url );
}
vlc_UrlClean( &url );
}
return res;
}
void MediaServerList::removeServer( const std::string& udn ) void MediaServerList::removeServer( const std::string& udn )
{ {
vlc_mutex_locker lock( &lock_ ); vlc_mutex_locker lock( &lock_ );
......
...@@ -83,11 +83,13 @@ namespace SD ...@@ -83,11 +83,13 @@ namespace SD
struct MediaServerDesc struct MediaServerDesc
{ {
MediaServerDesc(const std::string& udn, const std::string& fName, const std::string& loc); MediaServerDesc( const std::string& udn, const std::string& fName,
const std::string& loc, const std::string& iconUrl );
~MediaServerDesc(); ~MediaServerDesc();
std::string UDN; std::string UDN;
std::string friendlyName; std::string friendlyName;
std::string location; std::string location;
std::string iconUrl;
input_item_t* inputItem; input_item_t* inputItem;
bool isSatIp; bool isSatIp;
}; };
...@@ -107,6 +109,7 @@ public: ...@@ -107,6 +109,7 @@ public:
private: private:
void parseNewServer( IXML_Document* doc, const std::string& location ); void parseNewServer( IXML_Document* doc, const std::string& location );
std::string getIconURL( IXML_Element* p_device_elem , const char* psz_base_url );
private: private:
services_discovery_t* p_sd_; services_discovery_t* p_sd_;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment