]> git.sesse.net Git - vlc/blobdiff - modules/access_output/bonjour.c
direct3d11: give enough room for the \0 in the string
[vlc] / modules / access_output / bonjour.c
index 125f5f5dc218c9397fbfc0b38719c36a8e7252c8..d4dc8f6abda9af944c025f2c964a3bd07754a96f 100644 (file)
  * Preamble
  *****************************************************************************/
 
-#include <vlc/vlc.h>
+#ifdef HAVE_CONFIG_H
+# include "config.h"
+#endif
+
+#include <vlc_common.h>
+#include "bonjour.h"
 
 #ifdef HAVE_AVAHI_CLIENT
 #include <vlc_sout.h>
 
 #include <avahi-client/client.h>
-#ifdef HAVE_AVAHI_06
-# include <avahi-client/publish.h>
-# include <avahi-client/lookup.h>
-#endif
+#include <avahi-client/publish.h>
+#include <avahi-client/lookup.h>
 #include <avahi-common/alternative.h>
 #include <avahi-common/simple-watch.h>
 #include <avahi-common/malloc.h>
 /*****************************************************************************
  * Structures
  *****************************************************************************/
-typedef struct poll_thread_t
-{
-    VLC_COMMON_MEMBERS
-
-    AvahiSimplePoll     *simple_poll;
-} poll_thread_t;
-
 typedef struct bonjour_t
 {
     vlc_object_t        *p_log;
 
-    poll_thread_t       *poll_thread;
+    vlc_thread_t        thread;
     AvahiSimplePoll     *simple_poll;
     AvahiEntryGroup     *group;
     AvahiClient         *client;
@@ -76,6 +72,7 @@ static void entry_group_callback( AvahiEntryGroup *g,
                                   AvahiEntryGroupState state,
                                   void *userdata )
 {
+    (void)g;
     bonjour_t *p_sys = (bonjour_t *)userdata;
 
     if( state == AVAHI_ENTRY_GROUP_ESTABLISHED )
@@ -116,11 +113,7 @@ static int create_service( bonjour_t *p_sys )
     }
 
     error = avahi_entry_group_add_service( p_sys->group, AVAHI_IF_UNSPEC,
-#ifdef HAVE_AVAHI_06
                                            AVAHI_PROTO_UNSPEC, 0, p_sys->psz_name,
-#else
-                                           AVAHI_PROTO_UNSPEC, p_sys->psz_name,
-#endif
                                            p_sys->psz_stype, NULL, NULL,
                                            p_sys->i_port,
                                            p_sys->psz_txt, NULL );
@@ -161,12 +154,8 @@ static void client_callback( AvahiClient *c,
         if( p_sys->group != NULL )
             avahi_entry_group_reset( p_sys->group );
     }
-#ifdef HAVE_AVAHI_06
     else if( state == AVAHI_CLIENT_FAILURE &&
               (avahi_client_errno(c) == AVAHI_ERR_DISCONNECTED) )
-#else
-    else if( state == AVAHI_CLIENT_DISCONNECTED )
-#endif
     {
         msg_Err( p_sys->p_log, "avahi client disconnected" );
         avahi_simple_poll_quit( p_sys->simple_poll );
@@ -176,52 +165,46 @@ static void client_callback( AvahiClient *c,
 /*****************************************************************************
  * poll_iterate_thread
  *****************************************************************************/
-static void poll_iterate_thread( poll_thread_t *p_pt )
+static void *poll_iterate_thread( void *data )
 {
-    vlc_thread_ready( p_pt );
+    AvahiSimplePoll *simple_poll = data;
 
-    while( !p_pt->b_die )
-        if( avahi_simple_poll_iterate( p_pt->simple_poll, 100 ) != 0 )
+    for( ;; )
+    {
+        vlc_testcancel();
+        int canc = vlc_savecancel();
+        int ret = avahi_simple_poll_iterate( p_pt->simple_poll, 100 );
+        vlc_restorecancel( canc );
+        if (ret)
             break;
+    }
+    return NULL;
 }
 
 /*****************************************************************************
  * bonjour_start_service
  *****************************************************************************/
-void *bonjour_start_service( vlc_object_t *p_log, char *psz_stype,
-                            char *psz_name, int i_port, char *psz_txt )
+void *bonjour_start_service( vlc_object_t *p_log, const char *psz_stype,
+                             const char *psz_name, int i_port, char *psz_txt )
 {
     int err;
-    bonjour_t *p_sys;
 
-    p_sys = (bonjour_t *)malloc( sizeof(*p_sys) );
+    bonjour_t* p_sys = calloc( 1, sizeof(*p_sys) );
     if( p_sys == NULL )
-    {
-        msg_Err( p_log, "out of memory" );
         return NULL;
-    }
-
-    memset( p_sys, 0, sizeof(*p_sys) );
 
     p_sys->p_log = p_log;
-
     p_sys->i_port = i_port;
     p_sys->psz_name = avahi_strdup( psz_name );
     p_sys->psz_stype = avahi_strdup( psz_stype );
     if( p_sys->psz_name == NULL || p_sys->psz_stype == NULL )
-    {
-        msg_Err( p_sys->p_log, "out of memory" );
         goto error;
-    }
 
     if( psz_txt != NULL )
     {
         p_sys->psz_txt = avahi_strdup( psz_txt );
         if( p_sys->psz_txt == NULL )
-        {
-            msg_Err( p_sys->p_log, "out of memory" );
             goto error;
-        }
     }
 
     p_sys->simple_poll = avahi_simple_poll_new();
@@ -232,9 +215,7 @@ void *bonjour_start_service( vlc_object_t *p_log, char *psz_stype,
     }
 
     p_sys->client = avahi_client_new( avahi_simple_poll_get(p_sys->simple_poll),
-#ifdef HAVE_AVAHI_06
                                       0,
-#endif
                                       client_callback, p_sys, &err );
     if( p_sys->client == NULL )
     {
@@ -243,18 +224,9 @@ void *bonjour_start_service( vlc_object_t *p_log, char *psz_stype,
         goto error;
     }
 
-    p_sys->poll_thread = vlc_object_create( p_sys->p_log,
-                                            sizeof(poll_thread_t) );
-    if( p_sys->poll_thread == NULL )
-    {
-        msg_Err( p_sys->p_log, "out of memory" );
-        goto error;
-    }
-    p_sys->poll_thread->simple_poll = p_sys->simple_poll;
-
-    if( vlc_thread_create( p_sys->poll_thread, "Avahi Poll Iterate Thread",
-                           poll_iterate_thread,
-                           VLC_THREAD_PRIORITY_HIGHEST, VLC_FALSE ) )
+    if( vlc_clone( &p_sys->thread,
+                   poll_iterate_thread, p_sys->simple_poll,
+                   VLC_THREAD_PRIORITY_HIGHEST ) )
     {
         msg_Err( p_sys->p_log, "failed to create poll iterate thread" );
         goto error;
@@ -263,8 +235,6 @@ void *bonjour_start_service( vlc_object_t *p_log, char *psz_stype,
     return (void *)p_sys;
 
 error:
-    if( p_sys->poll_thread != NULL )
-        vlc_object_destroy( p_sys->poll_thread );
     if( p_sys->client != NULL )
         avahi_client_free( p_sys->client );
     if( p_sys->simple_poll != NULL )
@@ -276,7 +246,7 @@ error:
     if( p_sys->psz_txt != NULL )
         avahi_free( p_sys->psz_txt );
 
-    free( (void *)p_sys );
+    free( p_sys );
 
     return NULL;
 }
@@ -288,9 +258,8 @@ void bonjour_stop_service( void *_p_sys )
 {
     bonjour_t *p_sys = (bonjour_t *)_p_sys;
 
-    vlc_object_kill( p_sys->poll_thread );
-    vlc_thread_join( p_sys->poll_thread );
-    vlc_object_destroy( p_sys->poll_thread );
+    vlc_cancel( p_sys->thread );
+    vlc_join( p_sys->thread, NULL );
 
     if( p_sys->group != NULL )
         avahi_entry_group_free( p_sys->group );