[vlc-commits] rd: remove reference counting
Rémi Denis-Courmont
git at videolan.org
Mon May 15 21:31:56 CEST 2017
vlc | branch: master | Rémi Denis-Courmont <remi at remlab.net> | Sun May 14 23:42:56 2017 +0300| [0303cb6b285aa56aee0032bd83eab44d7b7da6df] | committer: Rémi Denis-Courmont
rd: remove reference counting
Like SD, and in fact most VLC object types, RD is not meant for objects
shared by multiple threads (input, vout, aout...). Using a custom
release makes no sense here.
> http://git.videolan.org/gitweb.cgi/vlc.git/?a=commit;h=0303cb6b285aa56aee0032bd83eab44d7b7da6df
---
include/vlc_renderer_discovery.h | 8 +-----
lib/renderer_discoverer.c | 8 +++---
modules/gui/macosx/VLCRendererDiscovery.m | 45 +++++++++++++++----------------
modules/gui/qt/actions_manager.cpp | 23 +++++++---------
modules/gui/qt/actions_manager.hpp | 1 -
src/libvlccore.sym | 2 +-
src/misc/renderer_discovery.c | 17 ++++--------
7 files changed, 41 insertions(+), 63 deletions(-)
diff --git a/include/vlc_renderer_discovery.h b/include/vlc_renderer_discovery.h
index 30019ee270..3ed26b56ea 100644
--- a/include/vlc_renderer_discovery.h
+++ b/include/vlc_renderer_discovery.h
@@ -143,7 +143,7 @@ vlc_rd_get_names(vlc_object_t *p_obj, char ***pppsz_names,
VLC_API vlc_renderer_discovery_t *
vlc_rd_new(vlc_object_t *p_obj, const char *psz_name) VLC_USED;
-#define vlc_rd_release(p_rd) vlc_object_release(p_rd)
+VLC_API void vlc_rd_release(vlc_renderer_discovery_t *p_rd);
/**
* Get the event manager of the renderer discovery module
@@ -164,12 +164,6 @@ VLC_API int
vlc_rd_start(vlc_renderer_discovery_t *p_rd);
/**
- * Stop the renderer discovery module
- */
-VLC_API void
-vlc_rd_stop(vlc_renderer_discovery_t *p_rd);
-
-/**
* @}
* @defgroup vlc_renderer_discovery_module VLC renderer module
* @{
diff --git a/lib/renderer_discoverer.c b/lib/renderer_discoverer.c
index bb67dae888..b9d49822b6 100644
--- a/lib/renderer_discoverer.c
+++ b/lib/renderer_discoverer.c
@@ -157,10 +157,9 @@ error:
void
libvlc_renderer_discoverer_release( libvlc_renderer_discoverer_t *p_lrd )
{
- if( p_lrd->p_rd != NULL )
- vlc_rd_release( p_lrd->p_rd );
+ libvlc_renderer_discoverer_stop( p_lrd );
- if( p_lrd->p_event_manager != NULL )
+ if( p_lrd->p_event_manager == NULL )
libvlc_event_manager_release( p_lrd->p_event_manager );
free( p_lrd );
@@ -175,7 +174,8 @@ libvlc_renderer_discoverer_start( libvlc_renderer_discoverer_t *p_lrd )
void
libvlc_renderer_discoverer_stop( libvlc_renderer_discoverer_t *p_lrd )
{
- vlc_rd_stop( p_lrd->p_rd );
+ if( p_lrd->p_rd != NULL )
+ vlc_rd_release( p_lrd->p_rd );
for( int i = 0; i < p_lrd->i_items; ++i )
vlc_renderer_item_release( p_lrd->pp_items[i] );
diff --git a/modules/gui/macosx/VLCRendererDiscovery.m b/modules/gui/macosx/VLCRendererDiscovery.m
index 00b98b33fc..c6f0ad5faa 100644
--- a/modules/gui/macosx/VLCRendererDiscovery.m
+++ b/modules/gui/macosx/VLCRendererDiscovery.m
@@ -54,52 +54,49 @@ static void renderer_event_received(const vlc_event_t *p_event, void *user_data)
if (!name)
[NSException raise:NSInvalidArgumentException
format:@"name must not be nil"];
-
- // Create renderer object
- p_intf = getIntf();
- p_rd = vlc_rd_new(VLC_OBJECT(p_intf), name);
-
- if (p_rd) {
- _name = [NSString stringWithUTF8String:name];
- _longName = (!longname) ? nil : [NSString stringWithUTF8String:longname];
- _discoveryStarted = false;
- } else {
- msg_Err(p_intf, "Could not create '%s' renderer discovery service", name);
- self = nil;
- }
+ _name = [NSString stringWithUTF8String:name];
+ _longName = (!longname) ? nil : [NSString stringWithUTF8String:longname];
}
return self;
}
- (void)dealloc
{
- if (_discoveryStarted)
- [self stopDiscovery];
- if (p_rd != NULL)
- vlc_rd_release(p_rd);
+ [self stopDiscovery];
}
- (bool)startDiscovery
{
+ p_intf = getIntf();
+
msg_Dbg(p_intf, "Starting renderer discovery service %s", _name.UTF8String);
+ // Create renderer object
+ p_rd = vlc_rd_new(VLC_OBJECT(p_intf), _name.UTF8String);
+
+ if (p_rd) {
+ } else {
+ msg_Err(p_intf, "Could not create '%s' renderer discovery service", _name.UTF8String);
+ return false;
+ }
+
[self attachEventHandlers];
int ret = vlc_rd_start(p_rd);
- if (ret == VLC_SUCCESS) {
- _discoveryStarted = true;
- return true;
- } else {
+ if (ret != VLC_SUCCESS) {
msg_Err(p_intf, "Could not start '%s' renderer discovery", _name.UTF8String);
[self detachEventHandler];
+ vlc_rd_release(p_rd);
+ p_rd = NULL;
return false;
}
+ return true;
}
- (void)stopDiscovery
{
- if (_discoveryStarted) {
+ if (p_rd != NULL) {
[self detachEventHandler];
- vlc_rd_stop(p_rd);
- _discoveryStarted = false;
+ vlc_rd_release(p_rd);
+ p_rd = NULL;
}
}
diff --git a/modules/gui/qt/actions_manager.cpp b/modules/gui/qt/actions_manager.cpp
index 14e2d483f2..bc59217d0a 100644
--- a/modules/gui/qt/actions_manager.cpp
+++ b/modules/gui/qt/actions_manager.cpp
@@ -41,21 +41,15 @@
ActionsManager::ActionsManager( intf_thread_t * _p_i )
: p_intf( _p_i )
, p_rd( NULL )
- , b_rd_started( false )
{ }
ActionsManager::~ActionsManager()
{
if ( p_rd != NULL )
{
- if (b_rd_started)
- {
- vlc_event_manager_t *em = vlc_rd_event_manager( p_rd );
- vlc_event_detach( em, vlc_RendererDiscoveryItemAdded, renderer_event_received, p_intf);
- vlc_event_detach( em, vlc_RendererDiscoveryItemRemoved, renderer_event_received, p_intf);
-
- vlc_rd_stop( p_rd );
- }
+ vlc_event_manager_t *em = vlc_rd_event_manager( p_rd );
+ vlc_event_detach( em, vlc_RendererDiscoveryItemAdded, renderer_event_received, p_intf);
+ vlc_event_detach( em, vlc_RendererDiscoveryItemRemoved, renderer_event_received, p_intf);
vlc_rd_release( p_rd );
}
}
@@ -292,7 +286,7 @@ void ActionsManager::renderer_event_received( const vlc_event_t * p_event, void
void ActionsManager::ScanRendererAction(bool checked)
{
- if (checked == b_rd_started)
+ if (checked == (p_rd != NULL))
return; /* nothing changed */
if (checked)
@@ -348,11 +342,12 @@ void ActionsManager::ScanRendererAction(bool checked)
vlc_event_attach( em, vlc_RendererDiscoveryItemAdded, renderer_event_received, p_intf);
vlc_event_attach( em, vlc_RendererDiscoveryItemRemoved, renderer_event_received, p_intf);
- b_rd_started = vlc_rd_start( p_rd ) == VLC_SUCCESS;
- if ( !b_rd_started )
+ if( vlc_rd_start( p_rd ) != VLC_SUCCESS )
{
vlc_event_detach( em, vlc_RendererDiscoveryItemAdded, renderer_event_received, p_intf);
vlc_event_detach( em, vlc_RendererDiscoveryItemRemoved, renderer_event_received, p_intf);
+ vlc_rd_release( p_rd );
+ p_rd = NULL;
}
}
}
@@ -364,9 +359,9 @@ void ActionsManager::ScanRendererAction(bool checked)
vlc_event_detach( em, vlc_RendererDiscoveryItemAdded, renderer_event_received, p_intf);
vlc_event_detach( em, vlc_RendererDiscoveryItemRemoved, renderer_event_received, p_intf);
- vlc_rd_stop( p_rd );
+ vlc_rd_release( p_rd );
+ p_rd = NULL;
}
- b_rd_started = false;
}
}
diff --git a/modules/gui/qt/actions_manager.hpp b/modules/gui/qt/actions_manager.hpp
index 92b80afcbb..9acdf34dab 100644
--- a/modules/gui/qt/actions_manager.hpp
+++ b/modules/gui/qt/actions_manager.hpp
@@ -76,7 +76,6 @@ private:
intf_thread_t* const p_intf;
vlc_renderer_discovery_t *p_rd;
- bool b_rd_started;
static void renderer_event_received( const vlc_event_t * p_event, void * user_data );
static bool isItemSout( QVariant & m_obj, const char *psz_sout, bool as_output );
diff --git a/src/libvlccore.sym b/src/libvlccore.sym
index 4cb7a22503..5a1b571467 100644
--- a/src/libvlccore.sym
+++ b/src/libvlccore.sym
@@ -764,9 +764,9 @@ vlc_renderer_item_demux_filter
vlc_renderer_item_flags
vlc_rd_get_names
vlc_rd_new
+vlc_rd_release
vlc_rd_event_manager
vlc_rd_start
-vlc_rd_stop
vlc_rd_add_item
vlc_rd_remove_item
vlc_rd_probe_add
diff --git a/src/misc/renderer_discovery.c b/src/misc/renderer_discovery.c
index 1ceb0de2d5..45c776d0eb 100644
--- a/src/misc/renderer_discovery.c
+++ b/src/misc/renderer_discovery.c
@@ -233,15 +233,15 @@ vlc_rd_get_names(vlc_object_t *p_obj, char ***pppsz_names,
return VLC_SUCCESS;
}
-static void
-rd_destructor(vlc_object_t *p_obj)
+void vlc_rd_release(vlc_renderer_discovery_t *p_rd)
{
- vlc_renderer_discovery_t * p_rd =(vlc_renderer_discovery_t *)p_obj;
- assert(!p_rd->p_module); /* Forgot to call Stop */
+ if (p_rd->p_module != NULL)
+ module_unneed(p_rd, p_rd->p_module);
config_ChainDestroy(p_rd->p_cfg);
free(p_rd->psz_name);
vlc_event_manager_fini(&p_rd->event_manager);
+ vlc_object_release(p_rd);
}
vlc_renderer_discovery_t *
@@ -259,7 +259,7 @@ vlc_rd_new(vlc_object_t *p_obj, const char *psz_name)
vlc_event_manager_register_event_type(p_em, vlc_RendererDiscoveryItemAdded);
vlc_event_manager_register_event_type(p_em, vlc_RendererDiscoveryItemRemoved);
- vlc_object_set_destructor(p_rd, rd_destructor);
+ p_rd->p_module = NULL;
return p_rd;
}
@@ -286,13 +286,6 @@ vlc_rd_start(vlc_renderer_discovery_t *p_rd)
}
void
-vlc_rd_stop(vlc_renderer_discovery_t * p_rd)
-{
- module_unneed(p_rd, p_rd->p_module);
- p_rd->p_module = NULL;
-}
-
-void
vlc_rd_add_item(vlc_renderer_discovery_t * p_rd, vlc_renderer_item_t * p_item)
{
vlc_event_t event;
More information about the vlc-commits
mailing list