Commit 3a71b317 authored by Thomas Guillem's avatar Thomas Guillem Committed by Jean-Baptiste Kempf

dsm/sd: discover in a separate thread

Signed-off-by: default avatarJean-Baptiste Kempf <jb@videolan.org>
parent 91b638cc
......@@ -30,11 +30,18 @@
# include "config.h"
#endif
#include <vlc_common.h>
#include <vlc_atomic.h>
#include <bdsm/bdsm.h>
#include "common.h"
struct services_discovery_sys_t
{
netbios_ns *ns;
netbios_ns *p_ns;
vlc_thread_t thread;
atomic_bool stop;
};
int bdsm_sd_probe_Open (vlc_object_t *p_this)
......@@ -47,26 +54,20 @@ int bdsm_sd_probe_Open (vlc_object_t *p_this)
return VLC_PROBE_CONTINUE;
}
int bdsm_SdOpen (vlc_object_t *p_this)
static void *Run( void *data )
{
services_discovery_t *p_sd = (services_discovery_t *)p_this;
services_discovery_sys_t *p_sys = malloc (sizeof (*p_sys));
services_discovery_t *p_sd = data;
services_discovery_sys_t *p_sys = p_sd->p_sys;
if( p_sys == NULL )
return VLC_ENOMEM;
p_sd->p_sys = p_sys;
if( !netbios_ns_discover( p_sys->p_ns ) )
return NULL;
/* Let's create a NETBIOS name service object */
p_sys->ns = netbios_ns_new();
if( p_sys->ns == NULL )
goto error;
if (atomic_load(&p_sys->stop))
return NULL;
if( !netbios_ns_discover( p_sys->ns ) )
goto error;
for( ssize_t i = 0; i < netbios_ns_entry_count( p_sys->ns ); i++ )
for( ssize_t i = 0; i < netbios_ns_entry_count( p_sys->p_ns ); i++ )
{
netbios_ns_entry *p_entry = netbios_ns_entry_at( p_sys->ns, i );
netbios_ns_entry *p_entry = netbios_ns_entry_at( p_sys->p_ns, i );
char type = netbios_ns_entry_type( p_entry );
if( type == 0x20 )
......@@ -76,7 +77,7 @@ int bdsm_SdOpen (vlc_object_t *p_this)
const char *name = netbios_ns_entry_name( p_entry );
if( asprintf(&psz_mrl, "smb://%s", name) < 0 )
goto error;
return NULL;
p_item = input_item_NewWithType( psz_mrl, name, 0, NULL,
0, -1, ITEM_TYPE_NODE );
......@@ -84,18 +85,37 @@ int bdsm_SdOpen (vlc_object_t *p_this)
services_discovery_AddItem( p_sd, p_item, NULL );
free( psz_mrl );
}
}
return NULL;
}
int bdsm_SdOpen (vlc_object_t *p_this)
{
services_discovery_t *p_sd = (services_discovery_t *)p_this;
services_discovery_sys_t *p_sys = calloc (1, sizeof (*p_sys));
if( p_sys == NULL )
return VLC_ENOMEM;
p_sd->p_sys = p_sys;
p_sys->p_ns = netbios_ns_new();
if( p_sys->p_ns == NULL )
goto error;
atomic_store(&p_sys->stop, false);
if( vlc_clone( &p_sys->thread, Run, p_sd, VLC_THREAD_PRIORITY_LOW ) )
{
p_sys->thread = 0;
goto error;
}
return VLC_SUCCESS;
error:
if( p_sys->ns != NULL )
netbios_ns_destroy( p_sys->ns );
free( p_sys );
p_sd->p_sys = NULL;
bdsm_SdClose( p_this );
return VLC_EGENERIC;
}
......@@ -107,7 +127,16 @@ void bdsm_SdClose (vlc_object_t *p_this)
if( p_sys == NULL )
return;
if( p_sys->ns != NULL )
netbios_ns_destroy( p_sys->ns );
if( p_sys->thread ) {
atomic_store(&p_sys->stop, true);
if( p_sys->p_ns )
netbios_ns_abort( p_sys->p_ns );
vlc_join( p_sys->thread, NULL );
}
if( p_sys->p_ns )
netbios_ns_destroy( p_sys->p_ns );
free( p_sys );
}
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