1 /*****************************************************************************
2 * Upnp.cpp : UPnP discovery module (libupnp)
3 *****************************************************************************
4 * Copyright (C) 2004-2008 the VideoLAN team
7 * Authors: RĂ©mi Denis-Courmont <rem # videolan.org> (original plugin)
8 * Christian Henz <henz # c-lab.de>
9 * Mirsal Ennaime <mirsal dot ennaime at gmail dot com>
11 * UPnP Plugin using the Intel SDK (libupnp) instead of CyberLink
13 * This program is free software; you can redistribute it and/or modify
14 * it under the terms of the GNU General Public License as published by
15 * the Free Software Foundation; either version 2 of the License, or
16 * (at your option) any later version.
18 * This program is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU General Public License for more details.
23 * You should have received a copy of the GNU General Public License
24 * along with this program; if not, write to the Free Software
25 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
26 *****************************************************************************/
29 \TODO: Debug messages: "__FILE__, __LINE__" ok ???, Wrn/Err ???
38 #include <vlc_plugin.h>
39 #include <vlc_services_discovery.h>
44 const char* MEDIA_SERVER_DEVICE_TYPE = "urn:schemas-upnp-org:device:MediaServer:1";
45 const char* CONTENT_DIRECTORY_SERVICE_TYPE = "urn:schemas-upnp-org:service:ContentDirectory:1";
48 struct services_discovery_sys_t
50 UpnpClient_Handle client_handle;
51 MediaServerList* p_server_list;
52 vlc_mutex_t callback_lock;
55 // VLC callback prototypes
56 static int Open( vlc_object_t* );
57 static void Close( vlc_object_t* );
58 VLC_SD_PROBE_HELPER("upnp", "Universal Plug'n'Play", SD_CAT_LAN)
63 set_shortname( "UPnP" );
64 set_description( N_( "Universal Plug'n'Play" ) );
65 set_category( CAT_PLAYLIST );
66 set_subcategory( SUBCAT_PLAYLIST_SD );
67 set_capability( "services_discovery", 0 );
68 set_callbacks( Open, Close );
70 VLC_SD_PROBE_SUBMODULE
76 static int Callback( Upnp_EventType event_type, void* p_event, void* p_user_data );
78 const char* xml_getChildElementValue( IXML_Element* p_parent,
79 const char* psz_tag_name );
81 IXML_Document* parseBrowseResult( IXML_Document* p_doc );
86 static int Open( vlc_object_t *p_this )
89 services_discovery_t *p_sd = ( services_discovery_t* )p_this;
90 services_discovery_sys_t *p_sys = ( services_discovery_sys_t * )
91 calloc( 1, sizeof( services_discovery_sys_t ) );
93 if(!(p_sd->p_sys = p_sys))
96 i_res = UpnpInit( 0, 0 );
97 if( i_res != UPNP_E_SUCCESS )
99 msg_Err( p_sd, "%s", UpnpGetErrorMessage( i_res ) );
104 p_sys->p_server_list = new MediaServerList( p_sd );
105 vlc_mutex_init( &p_sys->callback_lock );
107 i_res = UpnpRegisterClient( Callback, p_sd, &p_sys->client_handle );
108 if( i_res != UPNP_E_SUCCESS )
110 msg_Err( p_sd, "%s", UpnpGetErrorMessage( i_res ) );
111 Close( (vlc_object_t*) p_sd );
115 i_res = UpnpSearchAsync( p_sys->client_handle, 5,
116 MEDIA_SERVER_DEVICE_TYPE, p_sd );
117 if( i_res != UPNP_E_SUCCESS )
119 msg_Err( p_sd, "Search failed: %s", UpnpGetErrorMessage( i_res ) );
120 Close( (vlc_object_t*) p_sd );
124 i_res = UpnpSetMaxContentLength( 262144 );
125 if( i_res != UPNP_E_SUCCESS )
127 msg_Err( p_sd, "Failed to set maximum content length: %s", UpnpGetErrorMessage( i_res ) );
128 Close( (vlc_object_t*) p_sd );
135 static void Close( vlc_object_t *p_this )
137 services_discovery_t *p_sd = ( services_discovery_t* )p_this;
139 UpnpUnRegisterClient( p_sd->p_sys->client_handle );
142 delete p_sd->p_sys->p_server_list;
143 vlc_mutex_destroy( &p_sd->p_sys->callback_lock );
148 // XML utility functions:
150 // Returns the value of a child element, or 0 on error
151 const char* xml_getChildElementValue( IXML_Element* p_parent,
152 const char* psz_tag_name_ )
154 if ( !p_parent ) return 0;
155 if ( !psz_tag_name_ ) return 0;
157 char* psz_tag_name = strdup( psz_tag_name_ );
158 IXML_NodeList* p_node_list = ixmlElement_getElementsByTagName( p_parent, psz_tag_name );
159 free( psz_tag_name );
160 if ( !p_node_list ) return 0;
162 IXML_Node* p_element = ixmlNodeList_item( p_node_list, 0 );
163 ixmlNodeList_free( p_node_list );
164 if ( !p_element ) return 0;
166 IXML_Node* p_text_node = ixmlNode_getFirstChild( p_element );
167 if ( !p_text_node ) return 0;
169 return ixmlNode_getNodeValue( p_text_node );
172 // Extracts the result document from a SOAP response
173 IXML_Document* parseBrowseResult( IXML_Document* p_doc )
177 if ( !p_doc ) return 0;
179 IXML_NodeList* p_result_list = ixmlDocument_getElementsByTagName( p_doc,
182 if ( !p_result_list ) return 0;
184 IXML_Node* p_result_node = ixmlNodeList_item( p_result_list, 0 );
186 ixmlNodeList_free( p_result_list );
188 if ( !p_result_node ) return 0;
190 IXML_Node* p_text_node = ixmlNode_getFirstChild( p_result_node );
191 if ( !p_text_node ) return 0;
193 const char* psz_result_string = ixmlNode_getNodeValue( p_text_node );
194 char* psz_result_xml = strdup( psz_result_string );
196 IXML_Document* p_browse_doc = ixmlParseBuffer( psz_result_xml );
198 free( psz_result_xml );
204 // Handles all UPnP events
205 static int Callback( Upnp_EventType event_type, void* p_event, void* p_user_data )
207 services_discovery_t* p_sd = ( services_discovery_t* ) p_user_data;
208 services_discovery_sys_t* p_sys = p_sd->p_sys;
209 vlc_mutex_locker locker( &p_sys->callback_lock );
213 case UPNP_DISCOVERY_ADVERTISEMENT_ALIVE:
214 case UPNP_DISCOVERY_SEARCH_RESULT:
216 struct Upnp_Discovery* p_discovery = ( struct Upnp_Discovery* )p_event;
218 IXML_Document *p_description_doc = 0;
221 i_res = UpnpDownloadXmlDoc( p_discovery->Location, &p_description_doc );
222 if ( i_res != UPNP_E_SUCCESS )
225 "%s:%d: Could not download device description!",
226 __FILE__, __LINE__ );
227 msg_Dbg( p_sd, "Fetching data from %s failed: %s",
228 p_discovery->Location, UpnpGetErrorMessage( i_res ) );
232 MediaServer::parseDeviceDescription( p_description_doc,
233 p_discovery->Location, p_sd );
235 ixmlDocument_free( p_description_doc );
239 case UPNP_DISCOVERY_ADVERTISEMENT_BYEBYE:
241 struct Upnp_Discovery* p_discovery = ( struct Upnp_Discovery* )p_event;
243 p_sys->p_server_list->removeServer( p_discovery->DeviceId );
247 case UPNP_EVENT_RECEIVED:
249 Upnp_Event* p_e = ( Upnp_Event* )p_event;
251 MediaServer* p_server = p_sys->p_server_list->getServerBySID( p_e->Sid );
252 if ( p_server ) p_server->fetchContents();
256 case UPNP_EVENT_AUTORENEWAL_FAILED:
257 case UPNP_EVENT_SUBSCRIPTION_EXPIRED:
261 Upnp_Event_Subscribe* p_s = ( Upnp_Event_Subscribe* )p_event;
263 MediaServer* p_server = p_sys->p_server_list->getServerBySID( p_s->Sid );
264 if ( p_server ) p_server->subscribeToContentDirectory();
268 case UPNP_EVENT_SUBSCRIBE_COMPLETE:
269 msg_Warn( p_sd, "subscription complete" );
272 case UPNP_DISCOVERY_SEARCH_TIMEOUT:
273 msg_Warn( p_sd, "search timeout" );
278 "%s:%d: DEBUG: UNHANDLED EVENT ( TYPE=%d )",
279 __FILE__, __LINE__, event_type );
283 return UPNP_E_SUCCESS;
287 // Class implementations...
291 void MediaServer::parseDeviceDescription( IXML_Document* p_doc,
292 const char* p_location,
293 services_discovery_t* p_sd )
297 msg_Dbg( p_sd, "%s:%d: NULL", __FILE__, __LINE__ );
303 msg_Dbg( p_sd, "%s:%d: NULL", __FILE__, __LINE__ );
307 const char* psz_base_url = p_location;
309 // Try to extract baseURL
311 IXML_NodeList* p_url_list = ixmlDocument_getElementsByTagName( p_doc, "baseURL" );
315 if ( IXML_Node* p_url_node = ixmlNodeList_item( p_url_list, 0 ) )
317 IXML_Node* p_text_node = ixmlNode_getFirstChild( p_url_node );
318 if ( p_text_node ) psz_base_url = ixmlNode_getNodeValue( p_text_node );
321 ixmlNodeList_free( p_url_list );
325 IXML_NodeList* p_device_list =
326 ixmlDocument_getElementsByTagName( p_doc, "device" );
330 for ( unsigned int i = 0; i < ixmlNodeList_length( p_device_list ); i++ )
332 IXML_Element* p_device_element =
333 ( IXML_Element* ) ixmlNodeList_item( p_device_list, i );
335 const char* psz_device_type = xml_getChildElementValue( p_device_element,
337 if ( !psz_device_type )
340 "%s:%d: no deviceType!",
341 __FILE__, __LINE__ );
345 if ( strcmp( MEDIA_SERVER_DEVICE_TYPE, psz_device_type ) != 0 )
348 const char* psz_udn = xml_getChildElementValue( p_device_element, "UDN" );
351 msg_Dbg( p_sd, "%s:%d: no UDN!",
352 __FILE__, __LINE__ );
356 // Check if server is already added
357 if ( p_sd->p_sys->p_server_list->getServer( psz_udn ) != 0 )
359 msg_Dbg( p_sd, "%s:%d: server with uuid '%s' already exists.",
360 __FILE__, __LINE__, psz_udn );
364 const char* psz_friendly_name =
365 xml_getChildElementValue( p_device_element,
368 if ( !psz_friendly_name )
370 msg_Dbg( p_sd, "%s:%d: no friendlyName!", __FILE__, __LINE__ );
374 MediaServer* p_server = new MediaServer( psz_udn, psz_friendly_name, p_sd );
376 if ( !p_sd->p_sys->p_server_list->addServer( p_server ) )
383 // Check for ContentDirectory service...
384 IXML_NodeList* p_service_list =
385 ixmlElement_getElementsByTagName( p_device_element,
387 if ( p_service_list )
389 for ( unsigned int j = 0;
390 j < ixmlNodeList_length( p_service_list ); j++ )
392 IXML_Element* p_service_element =
393 ( IXML_Element* ) ixmlNodeList_item( p_service_list, j );
395 const char* psz_service_type =
396 xml_getChildElementValue( p_service_element,
398 if ( !psz_service_type )
401 if ( strcmp( CONTENT_DIRECTORY_SERVICE_TYPE,
402 psz_service_type ) != 0 )
405 const char* psz_event_sub_url =
406 xml_getChildElementValue( p_service_element,
408 if ( !psz_event_sub_url )
411 const char* psz_control_url =
412 xml_getChildElementValue( p_service_element,
414 if ( !psz_control_url )
417 // Try to subscribe to ContentDirectory service
419 char* psz_url = ( char* ) malloc( strlen( psz_base_url ) +
420 strlen( psz_event_sub_url ) + 1 );
423 char* psz_s1 = strdup( psz_base_url );
424 char* psz_s2 = strdup( psz_event_sub_url );
426 if ( UpnpResolveURL( psz_s1, psz_s2, psz_url ) ==
429 p_server->setContentDirectoryEventURL( psz_url );
430 p_server->subscribeToContentDirectory();
438 // Try to browse content directory...
440 psz_url = ( char* ) malloc( strlen( psz_base_url ) +
441 strlen( psz_control_url ) + 1 );
444 char* psz_s1 = strdup( psz_base_url );
445 char* psz_s2 = strdup( psz_control_url );
447 if ( UpnpResolveURL( psz_s1, psz_s2, psz_url ) ==
450 p_server->setContentDirectoryControlURL( psz_url );
451 p_server->fetchContents();
459 ixmlNodeList_free( p_service_list );
462 ixmlNodeList_free( p_device_list );
466 MediaServer::MediaServer( const char* psz_udn,
467 const char* psz_friendly_name,
468 services_discovery_t* p_sd )
473 _friendly_name = psz_friendly_name;
476 _p_input_item = NULL;
479 MediaServer::~MediaServer()
484 const char* MediaServer::getUDN() const
489 const char* MediaServer::getFriendlyName() const
491 return _friendly_name.c_str();
494 void MediaServer::setContentDirectoryEventURL( const char* psz_url )
496 _content_directory_event_url = psz_url;
499 const char* MediaServer::getContentDirectoryEventURL() const
501 return _content_directory_event_url.c_str();
504 void MediaServer::setContentDirectoryControlURL( const char* psz_url )
506 _content_directory_control_url = psz_url;
509 const char* MediaServer::getContentDirectoryControlURL() const
511 return _content_directory_control_url.c_str();
514 void MediaServer::subscribeToContentDirectory()
516 const char* psz_url = getContentDirectoryEventURL();
519 msg_Dbg( _p_sd, "No subscription url set!" );
523 int i_timeout = 1810;
526 int i_res = UpnpSubscribe( _p_sd->p_sys->client_handle, psz_url, &i_timeout, sid );
528 if ( i_res == UPNP_E_SUCCESS )
530 _i_subscription_timeout = i_timeout;
531 memcpy( _subscription_id, sid, sizeof( Upnp_SID ) );
536 "%s:%d: WARNING: '%s': %s", __FILE__, __LINE__,
537 getFriendlyName(), UpnpGetErrorMessage( i_res ) );
541 IXML_Document* MediaServer::_browseAction( const char* psz_object_id_,
542 const char* psz_browser_flag_,
543 const char* psz_filter_,
544 const char* psz_starting_index_,
545 const char* psz_requested_count_,
546 const char* psz_sort_criteria_ )
548 IXML_Document* p_action = 0;
549 IXML_Document* p_response = 0;
550 const char* psz_url = getContentDirectoryControlURL();
554 msg_Dbg( _p_sd, "No subscription url set!" );
558 char* psz_object_id = strdup( psz_object_id_ );
559 char* psz_browse_flag = strdup( psz_browser_flag_ );
560 char* psz_filter = strdup( psz_filter_ );
561 char* psz_starting_index = strdup( psz_starting_index_ );
562 char* psz_requested_count = strdup( psz_requested_count_ );
563 char* psz_sort_criteria = strdup( psz_sort_criteria_ );
564 char* psz_service_type = strdup( CONTENT_DIRECTORY_SERVICE_TYPE );
568 i_res = UpnpAddToAction( &p_action, "Browse",
569 psz_service_type, "ObjectID", psz_object_id );
571 if ( i_res != UPNP_E_SUCCESS )
574 "%s:%d: ERROR: %s", __FILE__, __LINE__,
575 UpnpGetErrorMessage( i_res ) );
576 goto browseActionCleanup;
579 i_res = UpnpAddToAction( &p_action, "Browse",
580 psz_service_type, "BrowseFlag", psz_browse_flag );
582 if ( i_res != UPNP_E_SUCCESS )
585 "%s:%d: ERROR: %s", __FILE__, __LINE__,
586 UpnpGetErrorMessage( i_res ) );
587 goto browseActionCleanup;
590 i_res = UpnpAddToAction( &p_action, "Browse",
591 psz_service_type, "Filter", psz_filter );
593 if ( i_res != UPNP_E_SUCCESS )
596 "%s:%d: ERROR: %s", __FILE__, __LINE__,
597 UpnpGetErrorMessage( i_res ) );
598 goto browseActionCleanup;
601 i_res = UpnpAddToAction( &p_action, "Browse",
602 psz_service_type, "StartingIndex", psz_starting_index );
604 if ( i_res != UPNP_E_SUCCESS )
607 "%s:%d: ERROR: %s", __FILE__, __LINE__,
608 UpnpGetErrorMessage( i_res ) );
609 goto browseActionCleanup;
612 i_res = UpnpAddToAction( &p_action, "Browse",
613 psz_service_type, "RequestedCount", psz_requested_count );
615 if ( i_res != UPNP_E_SUCCESS )
618 "%s:%d: ERROR: %s", __FILE__, __LINE__,
619 UpnpGetErrorMessage( i_res ) ); goto browseActionCleanup; }
621 i_res = UpnpAddToAction( &p_action, "Browse",
622 psz_service_type, "SortCriteria", psz_sort_criteria );
624 if ( i_res != UPNP_E_SUCCESS )
627 "%s:%d: ERROR: %s", __FILE__, __LINE__,
628 UpnpGetErrorMessage( i_res ) );
629 goto browseActionCleanup;
632 i_res = UpnpSendAction( _p_sd->p_sys->client_handle,
634 CONTENT_DIRECTORY_SERVICE_TYPE,
639 if ( i_res != UPNP_E_SUCCESS )
642 "%s:%d: ERROR: %s when trying the send() action with URL: %s",
644 UpnpGetErrorMessage( i_res ), psz_url );
646 ixmlDocument_free( p_response );
652 free( psz_object_id );
653 free( psz_browse_flag );
655 free( psz_starting_index );
656 free( psz_requested_count );
657 free( psz_sort_criteria );
659 free( psz_service_type );
661 ixmlDocument_free( p_action );
665 void MediaServer::fetchContents()
667 // Delete previous contents to prevent duplicate entries
671 services_discovery_RemoveItem( _p_sd, _p_input_item );
672 services_discovery_AddItem( _p_sd, _p_input_item, NULL );
675 Container* root = new Container( 0, "0", getFriendlyName() );
677 _fetchContents( root );
680 _p_contents->setInputItem( _p_input_item );
682 _buildPlaylist( _p_contents, NULL );
685 bool MediaServer::_fetchContents( Container* p_parent )
690 "%s:%d: parent==NULL", __FILE__, __LINE__ );
694 IXML_Document* p_response = _browseAction( p_parent->getObjectID(),
695 "BrowseDirectChildren",
700 "%s:%d: ERROR! No response from browse() action",
701 __FILE__, __LINE__ );
705 IXML_Document* p_result = parseBrowseResult( p_response );
706 ixmlDocument_free( p_response );
710 msg_Dbg( _p_sd, "%s:%d: ERROR! browse() response parsing failed",
711 __FILE__, __LINE__ );
715 IXML_NodeList* containerNodeList =
716 ixmlDocument_getElementsByTagName( p_result, "container" );
718 if ( containerNodeList )
720 for ( unsigned int i = 0;
721 i < ixmlNodeList_length( containerNodeList ); i++ )
723 IXML_Element* containerElement =
724 ( IXML_Element* )ixmlNodeList_item( containerNodeList, i );
726 const char* objectID = ixmlElement_getAttribute( containerElement,
731 const char* childCountStr =
732 ixmlElement_getAttribute( containerElement, "childCount" );
734 if ( !childCountStr )
737 int childCount = atoi( childCountStr );
738 const char* title = xml_getChildElementValue( containerElement,
744 const char* resource = xml_getChildElementValue( containerElement,
747 if ( resource && childCount < 1 )
749 Item* item = new Item( p_parent, objectID, title, resource );
750 p_parent->addItem( item );
755 Container* container = new Container( p_parent, objectID, title );
756 p_parent->addContainer( container );
758 if ( childCount > 0 )
759 _fetchContents( container );
762 ixmlNodeList_free( containerNodeList );
765 IXML_NodeList* itemNodeList = ixmlDocument_getElementsByTagName( p_result,
769 for ( unsigned int i = 0; i < ixmlNodeList_length( itemNodeList ); i++ )
771 IXML_Element* itemElement =
772 ( IXML_Element* )ixmlNodeList_item( itemNodeList, i );
774 const char* objectID =
775 ixmlElement_getAttribute( itemElement, "id" );
781 xml_getChildElementValue( itemElement, "dc:title" );
786 const char* resource =
787 xml_getChildElementValue( itemElement, "res" );
792 Item* item = new Item( p_parent, objectID, title, resource );
793 p_parent->addItem( item );
795 ixmlNodeList_free( itemNodeList );
798 ixmlDocument_free( p_result );
802 void MediaServer::_buildPlaylist( Container* p_parent, input_item_node_t *p_input_node )
804 bool b_send = p_input_node == NULL;
806 p_input_node = input_item_node_Create( p_parent->getInputItem() );
808 for ( unsigned int i = 0; i < p_parent->getNumContainers(); i++ )
810 Container* p_container = p_parent->getContainer( i );
812 input_item_t* p_input_item = input_item_New( _p_sd, "vlc://nop",
813 p_container->getTitle() );
814 input_item_node_t *p_new_node =
815 input_item_node_AppendItem( p_input_node, p_input_item );
817 p_container->setInputItem( p_input_item );
818 _buildPlaylist( p_container, p_new_node );
821 for ( unsigned int i = 0; i < p_parent->getNumItems(); i++ )
823 Item* p_item = p_parent->getItem( i );
825 input_item_t* p_input_item = input_item_New( _p_sd,
826 p_item->getResource(),
827 p_item->getTitle() );
828 assert( p_input_item );
829 input_item_node_AppendItem( p_input_node, p_input_item );
830 p_item->setInputItem( p_input_item );
834 input_item_node_PostAndDelete( p_input_node );
837 void MediaServer::setInputItem( input_item_t* p_input_item )
839 if(_p_input_item == p_input_item)
843 vlc_gc_decref( _p_input_item );
845 vlc_gc_incref( p_input_item );
846 _p_input_item = p_input_item;
849 bool MediaServer::compareSID( const char* psz_sid )
851 return ( strncmp( _subscription_id, psz_sid, sizeof( Upnp_SID ) ) == 0 );
855 // MediaServerList...
857 MediaServerList::MediaServerList( services_discovery_t* p_sd )
862 MediaServerList::~MediaServerList()
864 for ( unsigned int i = 0; i < _list.size(); i++ )
870 bool MediaServerList::addServer( MediaServer* p_server )
872 input_item_t* p_input_item = NULL;
873 if ( getServer( p_server->getUDN() ) != 0 ) return false;
875 msg_Dbg( _p_sd, "Adding server '%s' with uuid '%s'", p_server->getFriendlyName(), p_server->getUDN() );
877 p_input_item = input_item_New( _p_sd, "vlc://nop",
878 p_server->getFriendlyName() );
879 p_server->setInputItem( p_input_item );
881 services_discovery_AddItem( _p_sd, p_input_item, NULL );
883 _list.push_back( p_server );
888 MediaServer* MediaServerList::getServer( const char* psz_udn )
890 MediaServer* p_result = 0;
892 for ( unsigned int i = 0; i < _list.size(); i++ )
894 if( strcmp( psz_udn, _list[i]->getUDN() ) == 0 )
904 MediaServer* MediaServerList::getServerBySID( const char* psz_sid )
906 MediaServer* p_server = 0;
908 for ( unsigned int i = 0; i < _list.size(); i++ )
910 if ( _list[i]->compareSID( psz_sid ) )
920 void MediaServerList::removeServer( const char* psz_udn )
922 MediaServer* p_server = getServer( psz_udn );
923 if ( !p_server ) return;
926 "Removing server '%s'", p_server->getFriendlyName() );
928 std::vector<MediaServer*>::iterator it;
929 for ( it = _list.begin(); it != _list.end(); ++it )
931 if ( *it == p_server )
943 Item::Item( Container* p_parent, const char* psz_object_id, const char* psz_title,
944 const char* psz_resource )
948 _objectID = psz_object_id;
950 _resource = psz_resource;
952 _p_input_item = NULL;
958 vlc_gc_decref( _p_input_item );
961 const char* Item::getObjectID() const
963 return _objectID.c_str();
966 const char* Item::getTitle() const
968 return _title.c_str();
971 const char* Item::getResource() const
973 return _resource.c_str();
976 void Item::setInputItem( input_item_t* p_input_item )
978 if(_p_input_item == p_input_item)
982 vlc_gc_decref( _p_input_item );
984 vlc_gc_incref( p_input_item );
985 _p_input_item = p_input_item;
988 input_item_t* Item::getInputItem() const
990 return _p_input_item;
996 Container::Container( Container* p_parent,
997 const char* psz_object_id,
998 const char* psz_title )
1002 _objectID = psz_object_id;
1005 _p_input_item = NULL;
1008 Container::~Container()
1010 for ( unsigned int i = 0; i < _containers.size(); i++ )
1012 delete _containers[i];
1015 for ( unsigned int i = 0; i < _items.size(); i++ )
1021 vlc_gc_decref( _p_input_item );
1024 void Container::addItem( Item* item )
1026 _items.push_back( item );
1029 void Container::addContainer( Container* p_container )
1031 _containers.push_back( p_container );
1034 const char* Container::getObjectID() const
1036 return _objectID.c_str();
1039 const char* Container::getTitle() const
1041 return _title.c_str();
1044 unsigned int Container::getNumItems() const
1046 return _items.size();
1049 unsigned int Container::getNumContainers() const
1051 return _containers.size();
1054 Item* Container::getItem( unsigned int i_index ) const
1056 if ( i_index < _items.size() ) return _items[i_index];
1060 Container* Container::getContainer( unsigned int i_index ) const
1062 if ( i_index < _containers.size() ) return _containers[i_index];
1066 Container* Container::getParent()
1071 void Container::setInputItem( input_item_t* p_input_item )
1073 if(_p_input_item == p_input_item)
1077 vlc_gc_decref( _p_input_item );
1079 vlc_gc_incref( p_input_item );
1080 _p_input_item = p_input_item;
1083 input_item_t* Container::getInputItem() const
1085 return _p_input_item;