[vlc-commits] microdns: refactor
Thomas Guillem
git at videolan.org
Fri Mar 25 09:06:44 CET 2016
vlc | branch: master | Thomas Guillem <thomas at gllm.fr> | Wed Feb 10 15:00:37 2016 +0100| [8b31b1fc7be1fb9497af7562ead65db3981f3dc0] | committer: Jean-Baptiste Kempf
microdns: refactor
> http://git.videolan.org/gitweb.cgi/vlc.git/?a=commit;h=8b31b1fc7be1fb9497af7562ead65db3981f3dc0
---
modules/services_discovery/microdns.c | 40 +++++++++++++++++++--------------
1 file changed, 23 insertions(+), 17 deletions(-)
diff --git a/modules/services_discovery/microdns.c b/modules/services_discovery/microdns.c
index 8e86636..5a9a9eb 100644
--- a/modules/services_discovery/microdns.c
+++ b/modules/services_discovery/microdns.c
@@ -126,26 +126,43 @@ strrcmp(const char *s1, const char *s2)
}
static int
-items_add( services_discovery_t *p_sd, char *psz_uri,
- input_item_t *p_input_item )
+items_add_input( services_discovery_t *p_sd, char *psz_uri,
+ const char *psz_name )
{
services_discovery_sys_t *p_sys = p_sd->p_sys;
struct item *p_item = malloc( sizeof(struct item) );
if( p_item == NULL )
+ {
+ free( psz_uri );
+ return VLC_ENOMEM;
+ }
+
+ input_item_t *p_input_item =
+ input_item_NewWithTypeExt( psz_uri, psz_name, 0, NULL, 0, -1,
+ ITEM_TYPE_NODE, true );
+ if( p_input_item == NULL )
+ {
+ free( psz_uri );
+ free( p_item );
return VLC_ENOMEM;
+ }
+
p_item->psz_uri = psz_uri;
p_item->p_input_item = p_input_item;
p_item->i_last_seen = mdate();
vlc_array_append( &p_sys->items, p_item );
services_discovery_AddItem( p_sd, p_input_item, NULL );
+
return VLC_SUCCESS;
}
static void
-items_release( struct item *p_item )
+items_release( services_discovery_t *p_sd, struct item *p_item, bool b_notify )
{
input_item_Release( p_item->p_input_item );
+ if( b_notify )
+ services_discovery_RemoveItem( p_sd, p_item->p_input_item );
free( p_item->psz_uri );
free( p_item );
}
@@ -179,8 +196,7 @@ items_timeout( services_discovery_t *p_sd )
struct item *p_item = vlc_array_item_at_index( &p_sys->items, i );
if( i_now - p_item->i_last_seen > TIMEOUT )
{
- services_discovery_RemoveItem( p_sd, p_item->p_input_item );
- items_release( p_item );
+ items_release( p_sd, p_item, true );
vlc_array_remove( &p_sys->items, i-- );
}
}
@@ -194,7 +210,7 @@ items_clear( services_discovery_t *p_sd )
for( int i = 0; i < vlc_array_count( &p_sys->items ); ++i )
{
struct item *p_item = vlc_array_item_at_index( &p_sys->items, i );
- items_release( p_item );
+ items_release( p_sd, p_item, false );
}
vlc_array_clear( &p_sys->items );
}
@@ -283,17 +299,7 @@ new_entries_cb( void *p_this, int i_status,
free( psz_uri );
continue;
}
- input_item_t *p_input_item =
- input_item_NewWithTypeExt( psz_uri, p_srv->psz_device_name,
- 0, NULL, 0, -1, ITEM_TYPE_NODE, true );
-
- if( p_input_item != NULL
- && items_add( p_sd, psz_uri, p_input_item ) != VLC_SUCCESS )
- {
- if( p_input_item != NULL )
- input_item_Release( p_input_item );
- free( psz_uri );
- }
+ items_add_input( p_sd, psz_uri, p_srv->psz_device_name );
}
for( i_srv_idx = 0; i_srv_idx < i_nb_srv; ++i_srv_idx )
More information about the vlc-commits
mailing list