[vlc-devel] [PATCH 6/7] upnp: no need to store the MediaServerList in services_discovery_sys_t
Steve Lhomme
robux4 at videolabs.io
Wed Jun 1 16:38:09 CEST 2016
Let UpnpInstanceWrapper manage it completely
---
modules/services_discovery/upnp.cpp | 31 ++++++++++++++++---------------
modules/services_discovery/upnp.hpp | 2 +-
2 files changed, 17 insertions(+), 16 deletions(-)
diff --git a/modules/services_discovery/upnp.cpp b/modules/services_discovery/upnp.cpp
index 73f335a..99eb9ef 100644
--- a/modules/services_discovery/upnp.cpp
+++ b/modules/services_discovery/upnp.cpp
@@ -62,7 +62,6 @@ static const char *const ppsz_readible_satip_satellites[] = {
struct services_discovery_sys_t
{
UpnpInstanceWrapper* p_upnp;
- SD::MediaServerList* p_server_list;
vlc_thread_t thread;
};
@@ -232,17 +231,9 @@ static int Open( vlc_object_t *p_this )
if( !( p_sd->p_sys = p_sys ) )
return VLC_ENOMEM;
- p_sys->p_server_list = new(std::nothrow) SD::MediaServerList( p_sd );
- if ( unlikely( p_sys->p_server_list == NULL ) )
- {
- free(p_sys);
- return VLC_ENOMEM;
- }
-
- p_sys->p_upnp = UpnpInstanceWrapper::get( p_this, p_sys->p_server_list );
+ p_sys->p_upnp = UpnpInstanceWrapper::get( p_this, p_sd );
if ( !p_sys->p_upnp )
{
- delete p_sys->p_server_list;
free(p_sys);
return VLC_EGENERIC;
}
@@ -254,7 +245,6 @@ static int Open( vlc_object_t *p_this )
VLC_THREAD_PRIORITY_LOW ) )
{
p_sys->p_upnp->release( true );
- delete p_sys->p_server_list;
free(p_sys);
return VLC_EGENERIC;
}
@@ -272,7 +262,6 @@ static void Close( vlc_object_t *p_this )
vlc_join( p_sys->thread, NULL );
p_sys->p_upnp->release( true );
- delete p_sys->p_server_list;
free( p_sys );
}
@@ -1141,8 +1130,19 @@ UpnpInstanceWrapper::~UpnpInstanceWrapper()
vlc_mutex_destroy( &m_callback_lock );
}
-UpnpInstanceWrapper *UpnpInstanceWrapper::get(vlc_object_t *p_obj, SD::MediaServerList *opaque)
+UpnpInstanceWrapper *UpnpInstanceWrapper::get(vlc_object_t *p_obj, services_discovery_t *p_sd)
{
+ SD::MediaServerList *p_server_list = NULL;
+ if (p_sd)
+ {
+ p_server_list = new(std::nothrow) SD::MediaServerList( p_sd );
+ if ( unlikely( p_server_list == NULL ) )
+ {
+ msg_Err( p_sd, "Failed to create a MediaServerList");
+ return NULL;
+ }
+ }
+
vlc_mutex_locker lock( &s_lock );
if ( s_instance == NULL )
{
@@ -1191,11 +1191,11 @@ UpnpInstanceWrapper *UpnpInstanceWrapper::get(vlc_object_t *p_obj, SD::MediaServ
}
s_instance->m_refcount++;
// This assumes a single UPNP SD instance
- if (opaque)
+ if (p_server_list != NULL)
{
vlc_mutex_locker lock( &s_instance->m_callback_lock );
assert(!s_instance->m_opaque);
- s_instance->m_opaque = opaque;
+ s_instance->m_opaque = p_server_list;
}
return s_instance;
}
@@ -1206,6 +1206,7 @@ void UpnpInstanceWrapper::release(bool isSd)
if ( isSd )
{
vlc_mutex_locker lock( &m_callback_lock );
+ delete m_opaque;
m_opaque = NULL;
}
if (--s_instance->m_refcount == 0)
diff --git a/modules/services_discovery/upnp.hpp b/modules/services_discovery/upnp.hpp
index 65f1072..215673b 100644
--- a/modules/services_discovery/upnp.hpp
+++ b/modules/services_discovery/upnp.hpp
@@ -58,7 +58,7 @@ class UpnpInstanceWrapper
{
public:
// This increases the refcount before returning the instance
- static UpnpInstanceWrapper* get(vlc_object_t* p_obj, SD::MediaServerList *opaque);
+ static UpnpInstanceWrapper* get(vlc_object_t* p_obj, services_discovery_t *p_sd);
void release(bool isSd);
UpnpClient_Handle handle() const;
--
2.8.1
More information about the vlc-devel
mailing list