[vlc-devel] [PATCH 3/4] avahi: Prepare code for support of renderer discovery
Stefan Brüns
stefan.bruens at rwth-aachen.de
Wed Dec 26 03:21:42 CET 2018
Instead of passing the services_discovery_t as userdata for the callbacks,
use a struct (discovery_sys_t) which can be used regardless of the service
type (input or renderer).
---
modules/services_discovery/avahi.c | 83 ++++++++++++++++++------------
1 file changed, 50 insertions(+), 33 deletions(-)
diff --git a/modules/services_discovery/avahi.c b/modules/services_discovery/
avahi.c
index aa58c7f673..1ea60ab152 100644
--- a/modules/services_discovery/avahi.c
+++ b/modules/services_discovery/avahi.c
@@ -46,8 +46,8 @@
*****************************************************************************/
/* Callbacks */
-static int Open ( vlc_object_t * );
-static void Close( vlc_object_t * );
+static int OpenSD ( vlc_object_t * );
+static void CloseSD( vlc_object_t * );
VLC_SD_PROBE_HELPER("avahi", N_("Zeroconf network services"), SD_CAT_LAN)
@@ -57,7 +57,7 @@ vlc_module_begin ()
set_category( CAT_PLAYLIST )
set_subcategory( SUBCAT_PLAYLIST_SD )
set_capability( "services_discovery", 0 )
- set_callbacks( Open, Close )
+ set_callbacks( OpenSD, CloseSD )
add_shortcut( "mdns", "avahi" )
VLC_SD_PROBE_SUBMODULE
@@ -72,7 +72,14 @@ typedef struct
AvahiThreadedPoll *poll;
AvahiClient *client;
vlc_dictionary_t services_name_to_input_item;
-} services_discovery_sys_t;
+ vlc_object_t *parent;
+ bool renderer;
+} discovery_sys_t;
+
+struct services_discovery_sys_t
+{
+ discovery_sys_t s;
+};
static const struct
{
@@ -93,13 +100,12 @@ static const struct
static void client_callback( AvahiClient *c, AvahiClientState state,
void * userdata )
{
- services_discovery_t *p_sd = ( services_discovery_t* )userdata;
- services_discovery_sys_t *p_sys = p_sd->p_sys;
+ discovery_sys_t *p_sys = userdata;
if( state == AVAHI_CLIENT_FAILURE &&
(avahi_client_errno(c) == AVAHI_ERR_DISCONNECTED) )
{
- msg_Err( p_sd, "avahi client disconnected" );
+ msg_Err( p_sys->parent, "avahi client disconnected" );
avahi_threaded_poll_quit( p_sys->poll );
}
}
@@ -122,15 +128,14 @@ static void resolve_callback(
AvahiLookupResultFlags flags,
void* userdata )
{
- services_discovery_t *p_sd = ( services_discovery_t* )userdata;
- services_discovery_sys_t *p_sys = p_sd->p_sys;
+ discovery_sys_t *p_sys = userdata;
VLC_UNUSED(interface); VLC_UNUSED(host_name);
VLC_UNUSED(flags);
if( event == AVAHI_RESOLVER_FAILURE )
{
- msg_Err( p_sd,
+ msg_Err( p_sys->parent,
"failed to resolve service '%s' of type '%s' in domain
'%s'",
name, type, domain );
}
@@ -142,7 +147,7 @@ static void resolve_callback(
AvahiStringList *asl = NULL;
input_item_t *p_input = NULL;
- msg_Info( p_sd, "service '%s' of type '%s' in domain '%s' port %i",
+ msg_Info( p_sys->parent, "service '%s' of type '%s' in domain '%s'
port %i",
name, type, domain, port );
avahi_address_snprint(a, (sizeof(a)/sizeof(a[0]))-1, address);
@@ -212,6 +217,7 @@ static void resolve_callback(
}
if( p_input != NULL )
{
+ services_discovery_t *p_sd = ( services_discovery_t* )(p_sys-
>parent);
vlc_dictionary_insert( &p_sys->services_name_to_input_item,
name, p_input );
services_discovery_AddItem( p_sd, p_input );
@@ -238,8 +244,7 @@ static void browse_callback(
{
VLC_UNUSED(b);
VLC_UNUSED(flags);
- services_discovery_t *p_sd = ( services_discovery_t* )userdata;
- services_discovery_sys_t *p_sys = p_sd->p_sys;
+ discovery_sys_t *p_sys = userdata;
if( event == AVAHI_BROWSER_NEW )
{
if( avahi_service_resolver_new( p_sys->client, interface, protocol,
@@ -247,21 +252,22 @@ static void browse_callback(
0,
resolve_callback, userdata ) == NULL
)
{
- msg_Err( p_sd, "failed to resolve service '%s': %s", name,
+ msg_Err( p_sys->parent, "failed to resolve service '%s': %s",
name,
avahi_strerror( avahi_client_errno( p_sys->client ) ) );
}
}
else if( event == AVAHI_BROWSER_REMOVE && name )
{
/** \todo Store the input id and search it, rather than searching the
items */
- input_item_t *p_item;
+ void *p_item;
p_item = vlc_dictionary_value_for_key(
&p_sys->services_name_to_input_item,
name );
if( !p_item )
- msg_Err( p_sd, "failed to find service '%s' in playlist", name );
+ msg_Err( p_sys->parent, "failed to find service '%s' in
playlist", name );
else
{
+ services_discovery_t *p_sd = ( services_discovery_t* )(p_sys-
>parent);
services_discovery_RemoveItem( p_sd, p_item );
vlc_dictionary_remove_value_for_key(
&p_sys->services_name_to_input_item,
@@ -273,32 +279,24 @@ static void browse_callback(
/
*****************************************************************************
* Open: initialize and create stuff
*****************************************************************************/
-static int Open( vlc_object_t *p_this )
+static int OpenCommon( discovery_sys_t *p_sys )
{
- services_discovery_t *p_sd = ( services_discovery_t* )p_this;
- services_discovery_sys_t *p_sys;
int err;
- p_sd->p_sys = p_sys = calloc( 1, sizeof( services_discovery_sys_t ) );
- if( !p_sys )
- return VLC_ENOMEM;
-
- p_sd->description = _("Zeroconf network services");
-
vlc_dictionary_init( &p_sys->services_name_to_input_item, 1 );
p_sys->poll = avahi_threaded_poll_new();
if( p_sys->poll == NULL )
{
- msg_Err( p_sd, "failed to create Avahi threaded poll" );
+ msg_Err( p_sys->parent, "failed to create Avahi threaded poll" );
goto error;
}
p_sys->client = avahi_client_new( avahi_threaded_poll_get(p_sys->poll),
- 0, client_callback, p_sd, &err );
+ 0, client_callback, p_sys, &err );
if( p_sys->client == NULL )
{
- msg_Err( p_sd, "failed to create avahi client: %s",
+ msg_Err( p_sys->parent, "failed to create avahi client: %s",
avahi_strerror( err ) );
goto error;
}
@@ -309,10 +307,10 @@ static int Open( vlc_object_t *p_this )
sb = avahi_service_browser_new( p_sys->client, AVAHI_IF_UNSPEC,
AVAHI_PROTO_UNSPEC,
protocols[i].psz_service_name, NULL,
- 0, browse_callback, p_sd );
+ 0, browse_callback, p_sys );
if( sb == NULL )
{
- msg_Err( p_sd, "failed to create avahi service browser %s",
avahi_strerror( avahi_client_errno(p_sys->client) ) );
+ msg_Err( p_sys->parent, "failed to create avahi service browser
%s", avahi_strerror( avahi_client_errno(p_sys->client) ) );
goto error;
}
}
@@ -333,13 +331,25 @@ error:
return VLC_EGENERIC;
}
+static int OpenSD( vlc_object_t *p_this )
+{
+ services_discovery_t *p_sd = ( services_discovery_t* )p_this;
+ p_sd->description = _("Zeroconf network services");
+
+ p_sd->p_sys = calloc( 1, sizeof( services_discovery_sys_t ) );
+ if( !p_sd->p_sys )
+ return VLC_ENOMEM;
+ p_sd->p_sys->s.parent = p_this;
+ p_sd->p_sys->s.renderer = false;
+
+ return OpenCommon( &p_sd->p_sys->s );
+}
+
/
*****************************************************************************
* Close: cleanup
*****************************************************************************/
-static void Close( vlc_object_t *p_this )
+static void CloseCommon( discovery_sys_t *p_sys )
{
- services_discovery_t *p_sd = ( services_discovery_t* )p_this;
- services_discovery_sys_t *p_sys = p_sd->p_sys;
avahi_threaded_poll_stop( p_sys->poll );
avahi_client_free( p_sys->client );
@@ -348,3 +358,10 @@ static void Close( vlc_object_t *p_this )
vlc_dictionary_clear( &p_sys->services_name_to_input_item, NULL, NULL );
free( p_sys );
}
+
+static void CloseSD( vlc_object_t *p_this )
+{
+ services_discovery_t *p_sd = ( services_discovery_t* )p_this;
+ services_discovery_sys_t *p_sys = p_sd->p_sys;
+ CloseCommon( &p_sys->s );
+}
--
2.20.1
--
Stefan Brüns / Bergstraße 21 / 52062 Aachen
home: +49 241 53809034 mobile: +49 151 50412019
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 195 bytes
Desc: This is a digitally signed message part.
URL: <http://mailman.videolan.org/pipermail/vlc-devel/attachments/20181226/aa0bbc9b/attachment.sig>
More information about the vlc-devel
mailing list