/*****************************************************************************
* sap.c : SAP announce handler
*****************************************************************************
- * Copyright (C) 2002-2007 the VideoLAN team
+ * Copyright (C) 2002-2008 the VideoLAN team
* $Id$
*
* Authors: Clément Stenac <zorglub@videolan.org>
/* A SAP session descriptor, enqueued in the SAP handler queue */
struct sap_session_t {
uint8_t *psz_data;
- unsigned i_length;
+ size_t i_length;
sap_address_t *p_address;
session_descriptor_t *p_sd;
/* Last and next send */
- mtime_t i_last;
mtime_t i_next;
};
static void * RunThread( vlc_object_t *p_this);
static int ComputeRate( sap_address_t *p_address );
-static int announce_SendSAPAnnounce( sap_handler_t *p_sap,
- sap_session_t *p_session );
+static void announce_SendSAPAnnounce( sap_handler_t *p_sap,
+ sap_session_t *p_session );
static int announce_SAPAnnounceAdd( sap_handler_t *p_sap,
{
sap_handler_t *p_sap = (sap_handler_t*)p_this;
sap_session_t *p_session;
+ /* TODO: Use poll() instead of msleep()). */
- while( !p_sap->b_die )
+ for (;;)
{
int i;
+ msleep( SAP_IDLE );
+
/* If needed, get the rate info */
if( p_sap->b_control == true )
{
else
{
vlc_object_unlock( p_sap );
- msleep( SAP_IDLE );
continue;
}
p_session = p_sap->pp_sessions[p_sap->i_current_session];
- vlc_object_unlock( p_sap );
/* And announce it */
if( p_session->p_address->b_enabled == true &&
p_session->p_address->b_ready == true )
{
+ int canc = vlc_savecancel ();
announce_SendSAPAnnounce( p_sap, p_session );
+ vlc_restorecancel (canc);
}
-
- msleep( SAP_IDLE );
+ vlc_object_unlock( p_sap );
}
return NULL;
}
/* If needed, build the SDP */
assert( p_session->psz_sdp != NULL );
- p_sap_session->i_last = 0;
+ p_sap_session->i_next = 0;
p_sap_session->i_length = headsize + strlen (p_session->psz_sdp);
p_sap_session->psz_data = malloc (p_sap_session->i_length + 1);
if (p_sap_session->psz_data == NULL)
return VLC_SUCCESS;
}
-static int announce_SendSAPAnnounce( sap_handler_t *p_sap,
- sap_session_t *p_session )
+static void announce_SendSAPAnnounce( sap_handler_t *p_sap,
+ sap_session_t *p_session )
{
- int i_ret;
+ mtime_t now = mdate();
- /* This announce has never been sent yet */
- if( p_session->i_last == 0 )
- {
- p_session->i_next = mdate()+ p_session->p_address->i_interval*1000000;
- p_session->i_last = 1;
- return VLC_SUCCESS;
- }
+ if( p_session->i_next >= now )
+ return;
- if( p_session->i_next < mdate() )
+ ssize_t i_ret = send( p_session->p_address->i_wfd, p_session->psz_data,
+ p_session->i_length, 0 );
+ if( i_ret != (ssize_t)p_session->i_length )
{
-#ifdef EXTRA_DEBUG
- msg_Dbg( p_sap, "sending announce");
-#endif
- i_ret = net_Write( p_sap, p_session->p_address->i_wfd, NULL,
- p_session->psz_data,
- p_session->i_length );
- if( i_ret != (int)p_session->i_length )
- {
- msg_Warn( p_sap, "SAP send failed on address %s (%i %i)",
- p_session->p_address->psz_address,
- i_ret, p_session->i_length );
- }
- p_session->i_last = p_session->i_next;
- p_session->i_next = p_session->i_last
- + p_session->p_address->i_interval*1000000;
+ msg_Warn( p_sap, "SAP send failed on address %s (%zd/%zu)",
+ p_session->p_address->psz_address,
+ i_ret, p_session->i_length );
}
- return VLC_SUCCESS;
+ p_session->i_next = now + p_session->p_address->i_interval*CLOCK_FREQ;
}
static int ComputeRate( sap_address_t *p_address )