X-Git-Url: https://git.sesse.net/?a=blobdiff_plain;f=modules%2Fservices_discovery%2Fupnp_intel.cpp;h=53558b7edc182a793cc5a13758698040c67529d5;hb=c6a97a1b0bba035c8c1bb06dcc12ec6c67c2e109;hp=1e1b4f8af997544326d5559abec4669980dec8cd;hpb=5858f0fccb1f97087d630712c9526d553599adb7;p=vlc diff --git a/modules/services_discovery/upnp_intel.cpp b/modules/services_discovery/upnp_intel.cpp index 1e1b4f8af9..53558b7edc 100644 --- a/modules/services_discovery/upnp_intel.cpp +++ b/modules/services_discovery/upnp_intel.cpp @@ -29,242 +29,42 @@ \TODO: Debug messages: "__FILE__, __LINE__" ok ???, Wrn/Err ??? \TODO: Change names to VLC standard ??? */ - - -#include -#include - -#include -#include - #undef PACKAGE_NAME #ifdef HAVE_CONFIG_H # include "config.h" #endif -#include +#include "upnp_intel.hpp" + #include #include -// Constants +// Constants const char* MEDIA_SERVER_DEVICE_TYPE = "urn:schemas-upnp-org:device:MediaServer:1"; const char* CONTENT_DIRECTORY_SERVICE_TYPE = "urn:schemas-upnp-org:service:ContentDirectory:1"; -// Classes - -class MediaServer; -class MediaServerList; -class Item; -class Container; -class Lockable; - // VLC handle - struct services_discovery_sys_t { UpnpClient_Handle clientHandle; MediaServerList* serverList; - Lockable* callbackLock; -}; - -// Class definitions... - -class Lockable -{ -public: - - Lockable() - { - vlc_mutex_init( &_mutex ); - } - - ~Lockable() - { - vlc_mutex_destroy( &_mutex ); - } - - void lock() { vlc_mutex_lock( &_mutex ); } - void unlock() { vlc_mutex_unlock( &_mutex ); } - -private: - - vlc_mutex_t _mutex; -}; - - -class Locker -{ -public: - Locker( Lockable* l ) - { - _lockable = l; - _lockable->lock(); - } - - ~Locker() - { - _lockable->unlock(); - } - -private: - Lockable* _lockable; -}; - - -class MediaServer -{ -public: - - static void parseDeviceDescription( IXML_Document* doc, - const char* location, - services_discovery_t* p_sd ); - - MediaServer( const char* UDN, - const char* friendlyName, - services_discovery_t* p_sd ); - - ~MediaServer(); - - const char* getUDN() const; - const char* getFriendlyName() const; - - void setContentDirectoryEventURL( const char* url ); - const char* getContentDirectoryEventURL() const; - - void setContentDirectoryControlURL( const char* url ); - const char* getContentDirectoryControlURL() const; - - void subscribeToContentDirectory(); - void fetchContents(); - - void setInputItem( input_item_t* p_input_item ); - - bool compareSID( const char* sid ); - -private: - - bool _fetchContents( Container* parent ); - void _buildPlaylist( Container* container ); - - IXML_Document* _browseAction( const char*, const char*, - const char*, const char*, const char*, const char* ); - - services_discovery_t* _p_sd; - - Container* _contents; - input_item_t* _inputItem; - - std::string _UDN; - std::string _friendlyName; - - std::string _contentDirectoryEventURL; - std::string _contentDirectoryControlURL; - - int _subscriptionTimeOut; - Upnp_SID _subscriptionID; -}; - - -class MediaServerList -{ -public: - - MediaServerList( services_discovery_t* p_sd ); - ~MediaServerList(); - - bool addServer( MediaServer* s ); - void removeServer( const char* UDN ); - - MediaServer* getServer( const char* UDN ); - MediaServer* getServerBySID( const char* ); - -private: - - services_discovery_t* _p_sd; - - std::vector _list; -}; - - -class Item -{ -public: - - Item( Container* parent, - const char* objectID, - const char* title, - const char* resource ); - ~Item(); - - const char* getObjectID() const; - const char* getTitle() const; - const char* getResource() const; - - void setInputItem( input_item_t* p_input_item ); - input_item_t* getInputItem() const ; - -private: - - input_item_t* _inputItem; - - Container* _parent; - std::string _objectID; - std::string _title; - std::string _resource; -}; - - -class Container -{ -public: - - Container( Container* parent, const char* objectID, const char* title ); - ~Container(); - - void addItem( Item* item ); - void addContainer( Container* container ); - - const char* getObjectID() const; - const char* getTitle() const; - - unsigned int getNumItems() const; - unsigned int getNumContainers() const; - - Item* getItem( unsigned int i ) const; - Container* getContainer( unsigned int i ) const; - Container* getParent(); - - void setInputItem( input_item_t* p_input_item ); - input_item_t* getInputItem() const; - -private: - - input_item_t* _inputItem; - - Container* _parent; - - std::string _objectID; - std::string _title; - std::vector _items; - std::vector _containers; + vlc_mutex_t callbackLock; }; // VLC callback prototypes - static int Open( vlc_object_t* ); static void Close( vlc_object_t* ); -static void Run( services_discovery_t *p_sd ); // Module descriptor vlc_module_begin(); -set_shortname( "UPnP" ); -set_description( N_( "Universal Plug'n'Play discovery ( Intel SDK )" ) ); -set_category( CAT_PLAYLIST ); -set_subcategory( SUBCAT_PLAYLIST_SD ); -set_capability( "services_discovery", 0 ); -set_callbacks( Open, Close ); + set_shortname( "UPnP" ); + set_description( N_( "Universal Plug'n'Play discovery" ) ); + set_category( CAT_PLAYLIST ); + set_subcategory( SUBCAT_PLAYLIST_SD ); + set_capability( "services_discovery", 0 ); + set_callbacks( Open, Close ); vlc_module_end(); @@ -290,17 +90,16 @@ static int Open( vlc_object_t *p_this ) if(!(p_sd->p_sys = p_sys)) return VLC_ENOMEM; - services_discovery_SetLocalizedName( p_sd, _("UPnP devices") ); - res = UpnpInit( 0, 0 ); if( res != UPNP_E_SUCCESS ) { msg_Err( p_sd, "%s", UpnpGetErrorMessage( res ) ); + free( p_sys ); return VLC_EGENERIC; } p_sys->serverList = new MediaServerList( p_sd ); - p_sys->callbackLock = new Lockable(); + vlc_mutex_init( &p_sys->callbackLock ); res = UpnpRegisterClient( Callback, p_sd, &p_sys->clientHandle ); if( res != UPNP_E_SUCCESS ) @@ -312,7 +111,7 @@ static int Open( vlc_object_t *p_this ) res = UpnpSearchAsync( p_sys->clientHandle, 5, MEDIA_SERVER_DEVICE_TYPE, p_sd ); - + if( res != UPNP_E_SUCCESS ) { msg_Err( p_sd, "%s", UpnpGetErrorMessage( res ) ); @@ -329,25 +128,11 @@ static void Close( vlc_object_t *p_this ) UpnpFinish(); delete p_sd->p_sys->serverList; - delete p_sd->p_sys->callbackLock; + vlc_mutex_destroy( &p_sd->p_sys->callbackLock ); free( p_sd->p_sys ); } -static void Run( services_discovery_t* p_sd ) -{ - - msg_Dbg( p_sd, "UPnP discovery started" ); - while( vlc_object_alive (p_sd) ) - { - msleep( 500 ); - } - - msg_Dbg( p_sd, "UPnP discovery stopped" ); - -} - - // XML utility functions: // Returns the value of a child element, or 0 on error @@ -409,7 +194,7 @@ static int Callback( Upnp_EventType eventType, void* event, void* user_data ) { services_discovery_t *p_sd = ( services_discovery_t* ) user_data; services_discovery_sys_t* p_sys = p_sd->p_sys; - Locker locker( p_sys->callbackLock ); + vlc_mutex_locker locker( &p_sys->callbackLock ); switch( eventType ) { @@ -868,14 +653,6 @@ void MediaServer::fetchContents() Container* root = new Container( 0, "0", getFriendlyName() ); _fetchContents( root ); - // if ( _contents ) - // { - // PL_LOCK; - // playlist_NodeEmpty( p_playlist, _playlistNode, true ); - // PL_UNLOCK; - // delete _contents; - // } - _contents = root; _contents->setInputItem( _inputItem );