X-Git-Url: https://git.sesse.net/?a=blobdiff_plain;f=modules%2Fservices_discovery%2Fupnp_cc.cpp;h=7b72db632e3042299893578a31b781a7ed4e23eb;hb=6b22637020b2551eaaf0c835a2dfa2e90a3a1562;hp=9e5ebe304c42630f832a13453844ddb5911a6fe7;hpb=18f8461307c499afe662c52a990792b399d93d1e;p=vlc diff --git a/modules/services_discovery/upnp_cc.cpp b/modules/services_discovery/upnp_cc.cpp index 9e5ebe304c..7b72db632e 100644 --- a/modules/services_discovery/upnp_cc.cpp +++ b/modules/services_discovery/upnp_cc.cpp @@ -5,8 +5,8 @@ * $Id$ * * Authors: Rémi Denis-Courmont - * - * Based on original wxWindows patch for VLC, and dependant on CyberLink + * + * Based on original wxWindows patch for VLC, and dependent on CyberLink * UPnP library from : * Satoshi Konno * @@ -28,13 +28,18 @@ /***************************************************************************** * Includes *****************************************************************************/ -#include /* malloc(), free() */ #include #undef PACKAGE_NAME -#include -#include +#ifdef HAVE_CONFIG_H +# include "config.h" +#endif + +#include +#include +#include +#include /* FIXME: thread-safety ?? */ /* FIXME: playlist locking */ @@ -53,90 +58,20 @@ using namespace CyberLink; static int Open ( vlc_object_t * ); static void Close( vlc_object_t * ); -vlc_module_begin(); - set_shortname( "UPnP"); - set_description( _("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(); - - -/***************************************************************************** - * Local structures - *****************************************************************************/ - -struct services_discovery_sys_t -{ - /* playlist node */ - playlist_item_t *p_node; - playlist_t *p_playlist; -}; - -/***************************************************************************** - * Local prototypes - *****************************************************************************/ - -/* Main functions */ - static void Run ( services_discovery_t *p_sd ); +VLC_SD_PROBE_HELPER("upnp", N_("Universal Plug'n'Play")) -/***************************************************************************** - * Open: initialize and create stuff - *****************************************************************************/ -static int Open( vlc_object_t *p_this ) -{ - services_discovery_t *p_sd = ( services_discovery_t* )p_this; - services_discovery_sys_t *p_sys = (services_discovery_sys_t *) - malloc( sizeof( services_discovery_sys_t ) ); +vlc_module_begin () + set_shortname( "UPnP") + set_description( N_("Universal Plug'n'Play") ) + set_category( CAT_PLAYLIST ) + set_subcategory( SUBCAT_PLAYLIST_SD ) - playlist_view_t *p_view; - vlc_value_t val; + set_capability( "services_discovery", 0 ) + set_callbacks( Open, Close ) - p_sd->pf_run = Run; - p_sd->p_sys = p_sys; - - /* Create our playlist node */ - p_sys->p_playlist = (playlist_t *)vlc_object_find( p_sd, - VLC_OBJECT_PLAYLIST, - FIND_ANYWHERE ); - if( !p_sys->p_playlist ) - { - msg_Warn( p_sd, "unable to find playlist, cancelling UPnP listening"); - return VLC_EGENERIC; - } - - p_view = playlist_ViewFind( p_sys->p_playlist, VIEW_CATEGORY ); - p_sys->p_node = playlist_NodeCreate( p_sys->p_playlist, VIEW_CATEGORY, - "UPnP", p_view->p_root ); - p_sys->p_node->i_flags |= PLAYLIST_RO_FLAG; - p_sys->p_node->i_flags &= ~PLAYLIST_SKIP_FLAG; - val.b_bool = VLC_TRUE; - var_Set( p_sys->p_playlist, "intf-change", val ); - - return VLC_SUCCESS; -} + VLC_SD_PROBE_SUBMODULE - -/***************************************************************************** - * Close: - *****************************************************************************/ -static void Close( vlc_object_t *p_this ) -{ - services_discovery_t *p_sd = ( services_discovery_t* )p_this; - services_discovery_sys_t *p_sys = p_sd->p_sys; - - if( p_sys->p_playlist ) - { - playlist_NodeDelete( p_sys->p_playlist, p_sys->p_node, VLC_TRUE, - VLC_TRUE ); - vlc_object_release( p_sys->p_playlist ); - } - - free( p_sys ); -} +vlc_module_end () /***************************************************************************** * Run: main UPnP thread @@ -148,7 +83,6 @@ class UPnPHandler : public MediaPlayer, public DeviceChangeListener, { private: services_discovery_t *p_sd; - services_discovery_sys_t *p_sys; Device *GetDeviceFromUSN( const string& usn ) { @@ -157,7 +91,7 @@ class UPnPHandler : public MediaPlayer, public DeviceChangeListener, playlist_item_t *FindDeviceNode( Device *dev ) { - return playlist_ChildSearchName( p_sys->p_node, dev->getFriendlyName() ); + return playlist_ChildSearchName( p_sd->p_cat, dev->getFriendlyName() ); } playlist_item_t *FindDeviceNode( const string &usn ) @@ -181,30 +115,39 @@ class UPnPHandler : public MediaPlayer, public DeviceChangeListener, public: UPnPHandler( services_discovery_t *p_this ) - : p_sd( p_this ), p_sys( p_this->p_sys ) + : p_sd( p_this ) { addDeviceChangeListener( this ); addSearchResponseListener( this ); //addEventListener( this ); } - }; -static void Run( services_discovery_t *p_sd ) +/***************************************************************************** + * Open: initialize and create stuff + *****************************************************************************/ +static int Open( vlc_object_t *p_this ) { - UPnPHandler u( p_sd ); + services_discovery_t *p_sd = ( services_discovery_t* )p_this; - u.start(); + UPnPHandler *u = new UPnPHandler( p_sd ); + u->start( ); + msg_Dbg( p_sd, "upnp discovery started" ); + p_sd->p_private = u; - msg_Dbg( p_sd, "UPnP discovery started" ); - /* read SAP packets */ - while( !p_sd->b_die ) - { - msleep( 500 ); - } + return VLC_SUCCESS; +} + + +/***************************************************************************** + * Close: + *****************************************************************************/ +static void Close( vlc_object_t *p_this ) +{ + UPnPHandler *u = (UPnPHandler *)p_this->p_private; + u->stop( ); - u.stop(); - msg_Dbg( p_sd, "UPnP discovery stopped" ); + msg_Dbg( p_this, "upnp discovery started" ); } @@ -227,8 +170,7 @@ playlist_item_t *UPnPHandler::AddDevice( Device *dev ) */ char *str = strdup( dev->getFriendlyName( ) ); - p_item = playlist_NodeCreate( p_sys->p_playlist, VIEW_CATEGORY, - str, p_sys->p_node ); + p_item = playlist_NodeCreate( p_playlist, str, p_sd->p_cat, 0, NULL ); p_item->i_flags &= ~PLAYLIST_SKIP_FLAG; msg_Dbg( p_sd, "device %s added", str ); free( str ); @@ -257,29 +199,28 @@ void UPnPHandler::AddContent( playlist_item_t *p_parent, ContentNode *node ) msg_Dbg( p_sd, "title = %s", title ); - if ( node->isItemNode() ) + if ( node->isItemNode() ) { ItemNode *iNode = (ItemNode *)node; - - playlist_item_t *p_item; - p_item = playlist_ItemNew( p_sd, iNode->getResource(), title ); - - playlist_NodeAddItem( p_sys->p_playlist, p_item, VIEW_CATEGORY, - p_parent, PLAYLIST_APPEND, PLAYLIST_END ); - - } else if ( node->isContainerNode() ) + input_item_t *p_input = input_item_New( p_sd, iNode->getResource(), title ); + /* FIXME: playlist_AddInput() can fail */ + playlist_NodeAddInput( p_playlist, p_input, p_parent, + PLAYLIST_APPEND, PLAYLIST_END, + false ); + vlc_gc_decref( p_input ); + } else if ( node->isContainerNode() ) { ContainerNode *conNode = (ContainerNode *)node; - char* p_name = strdup(title); /* See other comment on strdup */ - playlist_item_t* p_node = playlist_NodeCreate( p_sys->p_playlist, VIEW_CATEGORY, - p_name, p_parent ); - free(p_name); + char* p_name = strdup(title); /* See other comment on strdup */ + playlist_item_t* p_node = playlist_NodeCreate( p_playlist, p_name, + p_parent, 0, NULL ); + free(p_name); - unsigned nContentNodes = conNode->getNContentNodes(); + unsigned nContentNodes = conNode->getNContentNodes(); - for( unsigned n = 0; n < nContentNodes; n++ ) - AddContent( p_node, conNode->getContentNode( n ) ); + for( unsigned n = 0; n < nContentNodes; n++ ) + AddContent( p_node, conNode->getContentNode( n ) ); } } @@ -289,7 +230,7 @@ void UPnPHandler::RemoveDevice( Device *dev ) playlist_item_t *p_item = FindDeviceNode( dev ); if( p_item != NULL ) - playlist_NodeDelete( p_sys->p_playlist, p_item, VLC_TRUE, VLC_TRUE ); + playlist_NodeDelete( p_playlist, p_item, true, true ); }