X-Git-Url: https://git.sesse.net/?a=blobdiff_plain;f=modules%2Fservices_discovery%2Fupnp_cc.cpp;h=aed508ba66a720f2d593176f5c4f7f392346c89a;hb=c2752f8142a31b728b797ba915b59fc671744181;hp=925fb5e177c6d65ddcc2ddd5df2491de7ddc25bb;hpb=0900f11014557ea895a290d2c1518d739f97a8b6;p=vlc diff --git a/modules/services_discovery/upnp_cc.cpp b/modules/services_discovery/upnp_cc.cpp index 925fb5e177..aed508ba66 100644 --- a/modules/services_discovery/upnp_cc.cpp +++ b/modules/services_discovery/upnp_cc.cpp @@ -6,7 +6,7 @@ * * 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,69 +58,16 @@ 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_begin () + set_shortname( "UPnP") + set_description( N_("Universal Plug'n'Play discovery") ) + set_category( CAT_PLAYLIST ) + set_subcategory( SUBCAT_PLAYLIST_SD ) -vlc_module_end(); + set_capability( "services_discovery", 0 ) + set_callbacks( Open, Close ) - -/***************************************************************************** - * Local structures - *****************************************************************************/ - -struct services_discovery_sys_t -{ - playlist_item_t *p_node_one; - playlist_item_t *p_node_cat; -}; - -/***************************************************************************** - * Local prototypes - *****************************************************************************/ - -/* Main functions */ - static void Run ( services_discovery_t *p_sd ); - -/***************************************************************************** - * 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 ) ); - - p_sd->pf_run = Run; - p_sd->p_sys = p_sys; - - playlist_NodesPairCreate( pl_Get( p_sd ), _("Devices"), - &p_sys->p_node_cat, &p_sys->p_node_one, - VLC_TRUE ); - return VLC_SUCCESS; -} - - -/***************************************************************************** - * 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; - playlist_t *p_playlist = pl_Yield( p_sd ); - playlist_NodeDelete( p_playlist, p_sys->p_node_one, VLC_TRUE, - VLC_TRUE ); - playlist_NodeDelete( p_playlist, p_sys->p_node_cat, VLC_TRUE, - VLC_TRUE ); - pl_Release(); - free( p_sys ); -} +vlc_module_end () /***************************************************************************** * Run: main UPnP thread @@ -127,7 +79,6 @@ class UPnPHandler : public MediaPlayer, public DeviceChangeListener, { private: services_discovery_t *p_sd; - services_discovery_sys_t *p_sys; Device *GetDeviceFromUSN( const string& usn ) { @@ -136,7 +87,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 ) @@ -160,30 +111,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" ); } @@ -206,7 +166,7 @@ playlist_item_t *UPnPHandler::AddDevice( Device *dev ) */ char *str = strdup( dev->getFriendlyName( ) ); - p_item = playlist_NodeCreate( p_sys->p_playlist, str, p_sys->p_node_cat ); + 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 ); @@ -238,16 +198,19 @@ void UPnPHandler::AddContent( playlist_item_t *p_parent, ContentNode *node ) if ( node->isItemNode() ) { ItemNode *iNode = (ItemNode *)node; - input_item_t *p_input = input_ItemNew( p_sd, iNode->getResource(), title ); - playlist_BothAddInput( p_sys->p_playlist, p_input, p_parent, - PLAYLIST_APPEND, PLAYLIST_END, NULL, NULL ); + input_item_t *p_input = input_item_New( p_sd, iNode->getResource(), title ); + /* FIXME: playlist_AddInput() can fail */ + playlist_BothAddInput( p_playlist, p_input, p_parent, + PLAYLIST_APPEND, PLAYLIST_END, NULL, NULL, + 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, - p_name, p_parent ); + playlist_item_t* p_node = playlist_NodeCreate( p_playlist, p_name, + p_parent, 0, NULL ); free(p_name); unsigned nContentNodes = conNode->getNContentNodes(); @@ -263,7 +226,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 ); }