# 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)
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));
-
- if( p_sys == NULL )
- return VLC_ENOMEM;
- p_sd->p_sys = p_sys;
+ services_discovery_t *p_sd = data;
+ services_discovery_sys_t *p_sys = p_sd->p_sys;
- /* Let's create a NETBIOS name service object */
- p_sys->ns = netbios_ns_new();
- if( p_sys->ns == NULL )
- goto error;
+ if( !netbios_ns_discover( p_sys->p_ns ) )
+ return NULL;
- if( !netbios_ns_discover( p_sys->ns ) )
- goto error;
+ if (atomic_load(&p_sys->stop))
+ return NULL;
- 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 )
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 );
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;
}
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 );
}