/*****************************************************************************
* Includes
*****************************************************************************/
+#ifdef HAVE_CONFIG_H
+# include "config.h"
+#endif
+
#include <vlc/vlc.h>
#include <assert.h>
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;
}
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++)
{
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++)
{
{
/* 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);
}
}
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 );
}
/**********************************************************************
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;
}
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;
}