* $Id$
*
* Authors: RĂ©mi Denis-Courmont <rem # videolan.org>
- *
- * 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 <skonno@cybergarage.org>
*
/*****************************************************************************
* Includes
*****************************************************************************/
-#include <stdlib.h> /* malloc(), free() */
#include <cybergarage/upnp/media/player/MediaPlayer.h>
#undef PACKAGE_NAME
-#include <vlc/vlc.h>
-#include <vlc/intf.h>
+#ifdef HAVE_CONFIG_H
+# include "config.h"
+#endif
+
+#include <vlc_common.h>
+#include <vlc_plugin.h>
+#include <vlc_playlist.h>
+#include <vlc_services_discovery.h>
/* FIXME: thread-safety ?? */
/* FIXME: playlist locking */
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 );
+VLC_SD_PROBE_HELPER("upnp", "Universal Plug'n'Play", SD_CAT_LAN)
- set_capability( "services_discovery", 0 );
- set_callbacks( Open, Close );
+vlc_module_begin ()
+ set_shortname( "UPnP")
+ set_description( N_("Universal Plug'n'Play") )
+ set_category( CAT_PLAYLIST )
+ set_subcategory( SUBCAT_PLAYLIST_SD )
-vlc_module_end();
+ set_capability( "services_discovery", 0 )
+ set_callbacks( Open, Close )
+ VLC_SD_PROBE_SUBMODULE
-/*****************************************************************************
- * Local structures
- *****************************************************************************/
-
-struct services_discovery_sys_t
-{
- /* playlist node */
- playlist_item_t *p_node;
- playlist_item_t *p_node_cat;
- playlist_t *p_playlist;
-};
-
-/*****************************************************************************
- * 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;
-
- /* 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;
- }
-
- playlist_NodesPairCreate( p_sys->p_playlist, _("Devices"),
- &p_sys->p_node_cat, &p_sys->p_node,
- 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;
-
- if( p_sys->p_playlist )
- {
- playlist_NodeDelete( p_sys->p_playlist, p_sys->p_node, VLC_TRUE,
- VLC_TRUE );
- playlist_NodeDelete( p_sys->p_playlist, p_sys->p_node_cat, VLC_TRUE,
- VLC_TRUE );
- vlc_object_release( p_sys->p_playlist );
- }
-
- free( p_sys );
-}
+vlc_module_end ()
/*****************************************************************************
* Run: main UPnP thread
{
private:
services_discovery_t *p_sd;
- services_discovery_sys_t *p_sys;
Device *GetDeviceFromUSN( const string& usn )
{
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 )
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 stopped" );
}
*/
char *str = strdup( dev->getFriendlyName( ) );
- p_item = playlist_NodeCreate( p_sys->p_playlist, str, p_sys->p_node );
+ p_item = playlist_NodeCreate( p_playlist, str, p_sd->p_cat, PLAYLIST_END, 0, NULL );
p_item->i_flags &= ~PLAYLIST_SKIP_FLAG;
msg_Dbg( p_sd, "device %s added", str );
free( str );
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,
- 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,
- 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, PLAYLIST_END, 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 ) );
}
}
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 );
}