]> git.sesse.net Git - vlc/blobdiff - modules/services_discovery/sap.c
ignore folder contents
[vlc] / modules / services_discovery / sap.c
index 171d756a706227af2e69c6236232dbd843cd986f..ebda11fcc9449e854c1977331982dde5a127c69f 100644 (file)
 /*****************************************************************************
  * Includes
  *****************************************************************************/
+#ifdef HAVE_CONFIG_H
+# include "config.h"
+#endif
+
 #include <vlc/vlc.h>
 #include <assert.h>
 
@@ -277,7 +281,7 @@ struct demux_sys_t
     static int Decompress( const unsigned char *psz_src, unsigned char **_dst, int i_len );
     static void FreeSDP( sdp_t *p_sdp );
 
-static inline int min( int a, int b )
+static inline int min_int( int a, int b )
 {
     return a > b ? b : a;
 }
@@ -542,11 +546,13 @@ static void Run( services_discovery_t *p_sd )
         return;
     }
 
+    vlc_object_lock( p_sd );
+
     /* read SAP packets */
     while( vlc_object_alive( p_sd ) )
     {
         unsigned n = p_sd->p_sys->i_fd;
-        struct pollfd ufd[n];
+        struct pollfd ufd[n+1];
 
         for (unsigned i = 0; i < n; i++)
         {
@@ -555,12 +561,23 @@ static void Run( services_discovery_t *p_sd )
             ufd[i].revents = 0;
         }
 
-        /* FIXME: remove this stupid evil hack when we have sorted out how to
-         * to cancel threads while doing network I/O */
-        if (timeout > 2000)
-            timeout = 2000;
+        /* Make sure we track vlc_object_signal() */
+        ufd[n].fd = vlc_object_waitpipe( p_sd );
+        ufd[n].events = POLLIN | POLLHUP;
+        ufd[n].revents = 0;
 
-        if (poll (ufd, n, timeout) > 0)
+        if( ufd[n].fd == -1 )
+        {
+            /* On windows, fd will be -1, as we can't select on a pipe()-ed
+             * fildes. Because we have no other solution to track that
+             * object is killed, we make sure the timeout won't be to long. */
+            if( timeout > 1000 || timeout == -1 )
+                timeout = 1000;
+        }
+
+        vlc_object_unlock( p_sd );
+
+        if (poll (ufd, n+1, timeout) > 0)
         {
             for (unsigned i = 0; i < n; i++)
             {
@@ -608,8 +625,8 @@ static void Run( services_discovery_t *p_sd )
             {
                 /* Compute next timeout */
                 if( p_announce->i_period_trust > 5 )
-                    timeout = min((3 * p_announce->i_period - i_last_period) / 1000, timeout);
-                timeout = min((i_timeout - i_last_period)/1000, timeout);
+                    timeout = min_int((3 * p_announce->i_period - i_last_period) / 1000, timeout);
+                timeout = min_int((i_timeout - i_last_period)/1000, timeout);
             }
         }
 
@@ -617,7 +634,10 @@ static void Run( services_discovery_t *p_sd )
             timeout = -1; /* We can safely poll indefinitly. */
         else if( timeout < 200 )
             timeout = 200; /* Don't wakeup too fast. */
+
+        vlc_object_lock( p_sd );
     }
+    vlc_object_unlock( p_sd );
 }
 
 /**********************************************************************
@@ -665,6 +685,7 @@ static int Demux( demux_t *p_demux )
 
 static int Control( demux_t *p_demux, int i_query, va_list args )
 {
+    VLC_UNUSED(p_demux); VLC_UNUSED(i_query); VLC_UNUSED(args);
     return VLC_EGENERIC;
 }
 
@@ -879,7 +900,7 @@ sap_announce_t *CreateAnnounce( services_discovery_t *p_sd, uint16_t i_hash,
     services_discovery_AddItem( p_sd, p_input, psz_value /* category name */ );
 
     TAB_APPEND( p_sys->i_announces, p_sys->pp_announces, p_sap );
-
+    vlc_gc_decref( p_input );
     return p_sap;
 }