Commit 0303cb6b authored by Rémi Denis-Courmont's avatar 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.
parent 5616dbd1
......@@ -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
......@@ -163,12 +163,6 @@ vlc_rd_event_manager(vlc_renderer_discovery_t *p_rd);
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
......
......@@ -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] );
......
......@@ -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;
}
}
......
......@@ -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;
}
}
......
......@@ -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 );
......
......@@ -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
......@@ -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;
}
......@@ -285,13 +285,6 @@ vlc_rd_start(vlc_renderer_discovery_t *p_rd)
return VLC_SUCCESS;
}
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)
{
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment