]> git.sesse.net Git - vlc/blobdiff - src/stream_output/sap.c
Remove msg_Err about memory allocation.
[vlc] / src / stream_output / sap.c
index 9529c5fe4310dd5125fdfe8b18ca2a3a461f3f01..49b1c9f9feb7ab484f038401365d2a4b0f240665 100644 (file)
@@ -30,7 +30,7 @@
 # include "config.h"
 #endif
 
-#include <vlc/vlc.h>
+#include <vlc_common.h>
 
 #include <stdlib.h>                                                /* free() */
 #include <stdio.h>                                              /* sprintf() */
@@ -43,6 +43,7 @@
 #include <vlc_charset.h>
 
 #include "stream_output.h"
+#include "libvlc.h"
 
 /* SAP is always on that port */
 #define SAP_PORT 9875
@@ -71,8 +72,8 @@ struct sap_address_t
 
     /* Used for flow control */
     mtime_t t1;
-    vlc_bool_t b_enabled;
-    vlc_bool_t b_ready;
+    bool b_enabled;
+    bool b_ready;
     int i_interval;
     int i_buff;
     int i_limit;
@@ -106,6 +107,8 @@ static int announce_SAPAnnounceAdd( sap_handler_t *p_sap,
 static int announce_SAPAnnounceDel( sap_handler_t *p_sap,
                              session_descriptor_t *p_session );
 
+static void announce_SAPHandlerDestructor( vlc_object_t *p_this );
+
 
 /**
  * Create the SAP handler
@@ -117,15 +120,12 @@ sap_handler_t *announce_SAPHandlerCreate( announce_handler_t *p_announce )
 {
     sap_handler_t *p_sap;
 
-    p_sap = vlc_object_create( p_announce, sizeof( sap_handler_t ) );
-
+    p_sap = vlc_custom_create( VLC_OBJECT(p_announce), sizeof( sap_handler_t ),
+                               VLC_OBJECT_ANNOUNCE, "announce" );
     if( !p_sap )
-    {
-        msg_Err( p_announce, "out of memory" );
         return NULL;
-    }
 
-    vlc_mutex_init( p_sap, &p_sap->object_lock );
+    p_sap->psz_object_name = strdup( "sap announcer" );
 
     p_sap->pf_add = announce_SAPAnnounceAdd;
     p_sap->pf_del = announce_SAPAnnounceDel;
@@ -137,27 +137,25 @@ sap_handler_t *announce_SAPHandlerCreate( announce_handler_t *p_announce )
     p_sap->b_control = config_GetInt( p_sap, "sap-flow-control");
 
     if( vlc_thread_create( p_sap, "sap handler", RunThread,
-                       VLC_THREAD_PRIORITY_LOW, VLC_FALSE ) )
+                       VLC_THREAD_PRIORITY_LOW, false ) )
     {
         msg_Dbg( p_announce, "unable to spawn SAP handler thread");
-        free( p_sap );
+        vlc_object_release( p_sap );
         return NULL;
-    };
+    }
+
+    vlc_object_set_destructor( p_sap, announce_SAPHandlerDestructor );
+
     msg_Dbg( p_announce, "thread created, %i sessions", p_sap->i_sessions);
+
     return p_sap;
 }
 
-/**
- *  Destroy the SAP handler
- *  \param p_this the SAP Handler to destroy
- *  \return nothing
- */
-void announce_SAPHandlerDestroy( sap_handler_t *p_sap )
+static void announce_SAPHandlerDestructor( vlc_object_t * p_this )
 {
+    sap_handler_t *p_sap = (sap_handler_t *)p_this;
     int i;
 
-    vlc_mutex_destroy( &p_sap->object_lock );
-
     /* Free the remaining sessions */
     for( i = 0 ; i< p_sap->i_sessions ; i++)
     {
@@ -183,9 +181,6 @@ void announce_SAPHandlerDestroy( sap_handler_t *p_sap )
         REMOVE_ELEM( p_sap->pp_addresses, p_sap->i_addresses, i );
         FREENULL( p_address );
     }
-
-    /* Free the structure */
-    vlc_object_destroy( p_sap );
 }
 
 /**
@@ -203,11 +198,11 @@ static void RunThread( vlc_object_t *p_this)
         int i;
 
         /* If needed, get the rate info */
-        if( p_sap->b_control == VLC_TRUE )
+        if( p_sap->b_control == true )
         {
             for( i = 0 ; i< p_sap->i_addresses ; i++)
             {
-                if( p_sap->pp_addresses[i]->b_enabled == VLC_TRUE )
+                if( p_sap->pp_addresses[i]->b_enabled == true )
                 {
                     ComputeRate( p_sap->pp_addresses[i] );
                 }
@@ -215,7 +210,7 @@ static void RunThread( vlc_object_t *p_this)
         }
 
         /* Find the session to announce */
-        vlc_mutex_lock( &p_sap->object_lock );
+        vlc_object_lock( p_sap );
         if( p_sap->i_sessions > p_sap->i_current_session + 1)
         {
             p_sap->i_current_session++;
@@ -226,16 +221,16 @@ static void RunThread( vlc_object_t *p_this)
         }
         else
         {
-            vlc_mutex_unlock( &p_sap->object_lock );
+            vlc_object_unlock( p_sap );
             msleep( SAP_IDLE );
             continue;
         }
         p_session = p_sap->pp_sessions[p_sap->i_current_session];
-        vlc_mutex_unlock( &p_sap->object_lock );
+        vlc_object_unlock( p_sap );
 
         /* And announce it */
-        if( p_session->p_address->b_enabled == VLC_TRUE &&
-            p_session->p_address->b_ready == VLC_TRUE )
+        if( p_session->p_address->b_enabled == true &&
+            p_session->p_address->b_ready == true )
         {
             announce_SendSAPAnnounce( p_sap, p_session );
         }
@@ -250,17 +245,17 @@ static int announce_SAPAnnounceAdd( sap_handler_t *p_sap,
 {
     int i;
     char psz_addr[NI_MAXNUMERICHOST];
-    vlc_bool_t b_ipv6 = VLC_FALSE, b_ssm = VLC_FALSE;
+    bool b_ipv6 = false, b_ssm = false;
     sap_session_t *p_sap_session;
     mtime_t i_hash;
     struct sockaddr_storage addr;
     socklen_t addrlen;
 
-    vlc_mutex_lock( &p_sap->object_lock );
+    vlc_object_lock( p_sap );
     addrlen = p_session->addrlen;
     if ((addrlen == 0) || (addrlen > sizeof (addr)))
     {
-        vlc_mutex_unlock( &p_sap->object_lock );
+        vlc_object_unlock( p_sap );
         msg_Err( p_sap, "No/invalid address specified for SAP announce" );
         return VLC_EGENERIC;
     }
@@ -290,7 +285,7 @@ static int announce_SAPAnnounceAdd( sap_handler_t *p_sap,
                 /* Unicast IPv6 - assume global scope */
                 memcpy( a6->s6_addr, "\xff\x0e", 2 );
 
-            b_ipv6 = VLC_TRUE;
+            b_ipv6 = true;
             break;
         }
 #endif
@@ -327,7 +322,7 @@ static int announce_SAPAnnounceAdd( sap_handler_t *p_sap,
             {
                 msg_Err( p_sap, "Out-of-scope multicast address "
                          "not supported by SAP" );
-                vlc_mutex_unlock( &p_sap->object_lock );
+                vlc_object_unlock( p_sap );
                 return VLC_EGENERIC;
             }
 
@@ -336,7 +331,7 @@ static int announce_SAPAnnounceAdd( sap_handler_t *p_sap,
         }
 
         default:
-            vlc_mutex_unlock( &p_sap->object_lock );
+            vlc_object_unlock( p_sap );
             msg_Err( p_sap, "Address family %d not supported by SAP",
                      addr.ss_family );
             return VLC_EGENERIC;
@@ -347,7 +342,7 @@ static int announce_SAPAnnounceAdd( sap_handler_t *p_sap,
 
     if( i )
     {
-        vlc_mutex_unlock( &p_sap->object_lock );
+        vlc_object_unlock( p_sap );
         msg_Err( p_sap, "%s", vlc_gai_strerror( i ) );
         return VLC_EGENERIC;
     }
@@ -375,7 +370,7 @@ static int announce_SAPAnnounceAdd( sap_handler_t *p_sap,
                                     malloc( sizeof(sap_address_t) );
         if( !p_address )
         {
-            vlc_mutex_unlock( &p_sap->object_lock );
+            vlc_object_unlock( p_sap );
             return VLC_ENOMEM;
         }
         p_address->psz_address = strdup( psz_addr );
@@ -388,21 +383,21 @@ static int announce_SAPAnnounceAdd( sap_handler_t *p_sap,
                          &p_address->origlen);
         }
 
-        if( p_sap->b_control == VLC_TRUE )
+        if( p_sap->b_control == true )
         {
             p_address->i_rfd = net_ListenUDP1( (vlc_object_t*)p_sap, psz_addr, SAP_PORT );
             if( p_address->i_rfd != -1 )
                 shutdown( p_address->i_rfd, SHUT_WR );
             p_address->i_buff = 0;
-            p_address->b_enabled = VLC_TRUE;
-            p_address->b_ready = VLC_FALSE;
+            p_address->b_enabled = true;
+            p_address->b_ready = false;
             p_address->i_limit = 10000; /* 10000 bps */
             p_address->t1 = 0;
         }
         else
         {
-            p_address->b_enabled = VLC_TRUE;
-            p_address->b_ready = VLC_TRUE;
+            p_address->b_enabled = true;
+            p_address->b_ready = true;
             p_address->i_interval = config_GetInt( p_sap,"sap-interval");
             p_address->i_rfd = -1;
         }
@@ -411,7 +406,7 @@ static int announce_SAPAnnounceAdd( sap_handler_t *p_sap,
                                         && p_sap->b_control ) )
         {
             msg_Warn( p_sap, "disabling address" );
-            p_address->b_enabled = VLC_FALSE;
+            p_address->b_enabled = false;
         }
 
         INSERT_ELEM( p_sap->pp_addresses,
@@ -438,7 +433,7 @@ static int announce_SAPAnnounceAdd( sap_handler_t *p_sap,
         default:
             msg_Err( p_sap, "Address family %d not supported by SAP",
                      addr.ss_family );
-            vlc_mutex_unlock( &p_sap->object_lock );
+            vlc_object_unlock( p_sap );
             return VLC_EGENERIC;
     }
 
@@ -451,7 +446,7 @@ static int announce_SAPAnnounceAdd( sap_handler_t *p_sap,
     if (p_sap_session->psz_data == NULL)
     {
         free (p_session->psz_sdp);
-        vlc_mutex_unlock( &p_sap->object_lock );
+        vlc_object_unlock( p_sap );
         return VLC_ENOMEM;
     }
 
@@ -505,7 +500,7 @@ static int announce_SAPAnnounceAdd( sap_handler_t *p_sap,
     msg_Dbg( p_sap,"%i addresses, %i sessions",
                    p_sap->i_addresses,p_sap->i_sessions);
 
-    vlc_mutex_unlock( &p_sap->object_lock );
+    vlc_object_unlock( p_sap );
 
     return VLC_SUCCESS;
 }
@@ -515,7 +510,7 @@ static int announce_SAPAnnounceDel( sap_handler_t *p_sap,
                              session_descriptor_t *p_session )
 {
     int i;
-    vlc_mutex_lock( &p_sap->object_lock );
+    vlc_object_lock( p_sap );
 
     msg_Dbg( p_sap, "removing session %p from SAP", p_session);
 
@@ -524,6 +519,7 @@ static int announce_SAPAnnounceDel( sap_handler_t *p_sap,
     {
         if( p_session == p_sap->pp_sessions[i]->p_sd )
         {
+            free( p_session->psz_sdp );
             sap_session_t *p_mysession = p_sap->pp_sessions[i];
             REMOVE_ELEM( p_sap->pp_sessions,
                          p_sap->i_sessions,
@@ -541,7 +537,7 @@ static int announce_SAPAnnounceDel( sap_handler_t *p_sap,
 
     msg_Dbg( p_sap,"%i announcements remaining", p_sap->i_sessions );
 
-    vlc_mutex_unlock( &p_sap->object_lock );
+    vlc_object_unlock( p_sap );
 
     return VLC_SUCCESS;
 }
@@ -628,7 +624,7 @@ static int ComputeRate( sap_address_t *p_address )
              p_address->psz_address,SAP_PORT, i_rate, p_address->i_interval );
 #endif
 
-    p_address->b_ready = VLC_TRUE;
+    p_address->b_ready = true;
 
     p_address->t1 = i_temp;
     p_address->i_buff = 0;