]> git.sesse.net Git - vlc/blobdiff - modules/services_discovery/upnp_intel.cpp
Use pl_Locked and pl_Unlocked
[vlc] / modules / services_discovery / upnp_intel.cpp
index 40a0febc041027517d706dc6c62fd18dfbf7972b..a65036a014da9ff07d314e40972d44435ba307b2 100644 (file)
@@ -27,9 +27,9 @@
 /*
   \TODO: Debug messages: "__FILE__, __LINE__" ok ???, Wrn/Err ???
   \TODO: Change names to VLC standard ???
+  \TODO: Rewrite this using the new service discovery API (see sap.c, shout.c).
 */
 
-#include <stdlib.h>
 
 #include <vector>
 #include <string>
 #include <upnp/upnptools.h>
 
 #undef PACKAGE_NAME
-#include <vlc/vlc.h>
+#ifdef HAVE_CONFIG_H
+# include "config.h"
+#endif
+
+#include <vlc_common.h>
+#include <vlc_plugin.h>
 #include <vlc_playlist.h>
-#include "vlc_strings.h"
 
 
 // VLC handle
 
 struct services_discovery_sys_t
 {
+    playlist_t *p_playlist;
     playlist_item_t *p_node_cat;
     playlist_item_t *p_node_one;
 };
@@ -83,7 +88,7 @@ public:
 
     Lockable( Cookie* c )
     {
-    vlc_mutex_init( c->serviceDiscovery, &_mutex );
+    vlc_mutex_init( &_mutex );
     }
 
     ~Lockable()
@@ -251,12 +256,16 @@ private:
 static int Open( vlc_object_t* );
 static void Close( vlc_object_t* );
 static void Run( services_discovery_t *p_sd );
+static playlist_t *pl_Get( services_discovery_t *p_sd )
+{
+    return p_sd->p_sys->p_playlist;
+}
 
 // Module descriptor
 
 vlc_module_begin();
 set_shortname( "UPnP" );
-set_description( _( "Universal Plug'n'Play discovery ( Intel SDK )" ) );
+set_description( N_( "Universal Plug'n'Play discovery ( Intel SDK )" ) );
 set_category( CAT_PLAYLIST );
 set_subcategory( SUBCAT_PLAYLIST_SD );
 set_capability( "services_discovery", 0 );
@@ -283,11 +292,12 @@ static int Open( vlc_object_t *p_this )
 
     p_sd->pf_run = Run;
     p_sd->p_sys = p_sys;
+    p_sys->p_playlist = pl_Yield( p_sd );
 
     /* Create our playlist node */
     playlist_NodesPairCreate( pl_Get( p_sd ), _("Devices"),
                               &p_sys->p_node_cat, &p_sys->p_node_one,
-                              VLC_TRUE );
+                              true );
 
     return VLC_SUCCESS;
 }
@@ -297,11 +307,11 @@ 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_NodeDelete( pl_Get( p_sd ), p_sys->p_node_one, VLC_TRUE,
-                         VLC_TRUE );
-    playlist_NodeDelete( pl_Get( p_sd ), p_sys->p_node_cat, VLC_TRUE,
-                         VLC_TRUE );
-
+    playlist_NodeDelete( pl_Get( p_sd ), p_sys->p_node_one, true,
+                         true );
+    playlist_NodeDelete( pl_Get( p_sd ), p_sys->p_node_cat, true,
+                         true );
+    pl_Release( p_sd );
     free( p_sys );
 }
 
@@ -337,7 +347,7 @@ static void Run( services_discovery_t* p_sd )
     }
 
     msg_Dbg( p_sd, "UPnP discovery started" );
-    while( !p_sd->b_die )
+    while( vlc_object_alive (p_sd) )
     {
         msleep( 500 );
     }
@@ -394,8 +404,6 @@ IXML_Document* parseBrowseResult( IXML_Document* doc )
     const char* resultString = ixmlNode_getNodeValue( textNode );
     char* resultXML = strdup( resultString );
 
-    resolve_xml_special_chars( resultXML );
-
     IXML_Document* browseDoc = ixmlParseBuffer( resultXML );
 
     free( resultXML );
@@ -466,11 +474,11 @@ static int Callback( Upnp_EventType eventType, void* event, void* pCookie )
     case UPNP_EVENT_SUBSCRIBE_COMPLETE:
         msg_Warn( cookie->serviceDiscovery, "subscription complete" );
         break;
-        
     case UPNP_DISCOVERY_SEARCH_TIMEOUT:
         msg_Warn( cookie->serviceDiscovery, "search timeout" );
         break;
-        
     default:
     msg_Dbg( cookie->serviceDiscovery, "%s:%d: DEBUG: UNHANDLED EVENT ( TYPE=%d )", __FILE__, __LINE__, eventType );
     break;
@@ -620,7 +628,7 @@ MediaServer::~MediaServer()
     if ( _contents )
     {
         playlist_NodeDelete( pl_Get( _cookie->serviceDiscovery ) ,
-                             _playlistNode, VLC_TRUE, VLC_TRUE );
+                             _playlistNode, true, true );
     }
 
     delete _contents;
@@ -759,7 +767,7 @@ void MediaServer::fetchContents()
     if ( _contents )
     {
         PL_LOCK;
-        playlist_NodeEmpty( p_playlist, _playlistNode, VLC_TRUE );
+        playlist_NodeEmpty( p_playlist, _playlistNode, true );
         PL_UNLOCK;
         delete _contents;
     }
@@ -854,7 +862,7 @@ void MediaServer::_buildPlaylist( Container* parent )
         playlist_item_t* parentNode = parent->getPlaylistNode();
 
         char* title = strdup( container->getTitle() );
-        playlist_item_t* node = playlist_NodeCreate( p_playlist, title, parentNode, 0 );
+        playlist_item_t* node = playlist_NodeCreate( p_playlist, title, parentNode, 0, NULL );
         free( title );
 
         container->setPlaylistNode( node );
@@ -870,10 +878,13 @@ void MediaServer::_buildPlaylist( Container* parent )
                                                item->getResource(),
                                                item->getTitle() );
         int i_cat;
+        /* FIXME: playlist_AddInput() can fail */
         playlist_BothAddInput( p_playlist, p_input, parentNode,
-                               PLAYLIST_APPEND, PLAYLIST_END, &i_cat, NULL );
+                               PLAYLIST_APPEND, PLAYLIST_END, &i_cat, NULL,
+                               pl_Unlocked );
+        vlc_gc_decref( p_input );
         /* TODO: do this better by storing ids */
-        playlist_item_t *p_node = playlist_ItemGetById( p_playlist, i_cat, VLC_FALSE );
+        playlist_item_t *p_node = playlist_ItemGetById( p_playlist, i_cat, false );
         assert( p_node );
         item->setPlaylistNode( p_node );
     }
@@ -916,7 +927,7 @@ bool MediaServerList::addServer( MediaServer* s )
     char* name = strdup( s->getFriendlyName() );
     playlist_item_t* node = playlist_NodeCreate( pl_Get( _cookie->serviceDiscovery ),
                                                  name,
-                                          _cookie->serviceDiscovery->p_sys->p_node_cat, 0 );
+                                          _cookie->serviceDiscovery->p_sys->p_node_cat, 0, NULL );
     free( name );
     s->setPlaylistNode( node );