]> git.sesse.net Git - vlc/blobdiff - src/stream_output/sap.c
sout_AccessOutNew: allow any VLC object type, not just sout instance
[vlc] / src / stream_output / sap.c
index 0c4e3f9dc30bda7418b61d22ef343e7f0cca135d..61243c6021b3c60829a2f853ed042e3ee6dd0fb2 100644 (file)
@@ -1,7 +1,7 @@
 /*****************************************************************************
  * 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>
@@ -82,12 +82,11 @@ struct sap_address_t
 /* 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;
 };
 
@@ -97,8 +96,8 @@ struct sap_session_t {
 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,
@@ -192,13 +191,9 @@ static void * RunThread( vlc_object_t *p_this)
 {
     sap_handler_t *p_sap = (sap_handler_t*)p_this;
     sap_session_t *p_session;
-    int canc = vlc_savecancel ();
-    /* TODO: Once net_Write() is cancel-safe, so will this whole thread.
-     * However, there is a more serious issues here: msleep(SAP_IDLE).
-     * This thread should really use poll().
-     */
+    /* TODO: Use poll() instead of msleep()). */
 
-    while( !p_sap->b_die )
+    for (;;)
     {
         int i;
 
@@ -237,11 +232,12 @@ static void * RunThread( vlc_object_t *p_this)
         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);
         }
         vlc_object_unlock( p_sap );
     }
-    vlc_restorecancel (canc);
     return NULL;
 }
 
@@ -446,7 +442,7 @@ static int announce_SAPAnnounceAdd( sap_handler_t *p_sap,
     /* 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)
@@ -548,38 +544,23 @@ static int announce_SAPAnnounceDel( sap_handler_t *p_sap,
     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 )