]> git.sesse.net Git - vlc/blobdiff - src/stream_output/announce.c
A bit of headers cleanup
[vlc] / src / stream_output / announce.c
index 211c0d4f64d8779ab92a7ac1b5a1af5a1625c958..ca1007896a2cda83bcb897bf23f6539bd363117f 100644 (file)
@@ -1,10 +1,10 @@
 /*****************************************************************************
  * announce.c : announce handler
  *****************************************************************************
- * Copyright (C) 2002-2004 VideoLAN (Centrale Réseaux) and its contributors
+ * Copyright (C) 2002-2004 the VideoLAN team
  * $Id$
  *
- * Authors: Clément Stenac <zorglub@videolan.org>
+ * Authors: Clément Stenac <zorglub@videolan.org>
  *
  * This program is free software; you can redistribute it and/or modify
  * it under the terms of the GNU General Public License as published by
@@ -18,7 +18,7 @@
  *
  * You should have received a copy of the GNU General Public License
  * along with this program; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111, USA.
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
  *****************************************************************************/
 
 /*****************************************************************************
 #include <string.h>                                            /* strerror() */
 
 #include <vlc/vlc.h>
-#include <vlc/sout.h>
-
-/*****************************************************************************
- * Local prototypes
- *****************************************************************************/
-#define FREE( p ) if( p ) { free( p ); (p) = NULL; }
-
+#include <vlc_sout.h>
+#include "stream_output.h"
 
 /****************************************************************************
  * Sout-side functions
@@ -69,7 +64,7 @@ int sout_AnnounceRegister( sout_instance_t *p_sout,
             return VLC_ENOMEM;
         }
         vlc_object_yield( p_announce );
-        msg_Dbg( p_sout,"Creation done" );
+        msg_Dbg( p_sout, "creation done" );
     }
 
     i_ret = announce_Register( p_announce, p_session, p_method );
@@ -83,11 +78,13 @@ int sout_AnnounceRegister( sout_instance_t *p_sout,
  *
  * \param p_sout a sout instance structure
  * \param psz_sdp the SDP to register
+ * \param psz_uri session URI (needed for SAP address auto detection
  * \param p_method an announce method descriptor
  * \return the new session descriptor structure
  */
 session_descriptor_t *sout_AnnounceRegisterSDP( sout_instance_t *p_sout,
-                          char *psz_sdp, announce_method_t *p_method )
+                          const char *psz_sdp, const char *psz_uri,
+                          announce_method_t *p_method )
 {
     session_descriptor_t *p_session;
     announce_handler_t *p_announce = (announce_handler_t*)
@@ -108,11 +105,12 @@ session_descriptor_t *sout_AnnounceRegisterSDP( sout_instance_t *p_sout,
 
     if( p_method->i_type != METHOD_TYPE_SAP )
     {
-        msg_Warn( p_sout,"forcing SAP announcement");
+        msg_Warn( p_sout, "forcing SAP announcement");
     }
 
     p_session = sout_AnnounceSessionCreate();
     p_session->psz_sdp = strdup( psz_sdp );
+    p_session->psz_uri = strdup( psz_uri );
     announce_Register( p_announce, p_session, p_method );
 
     vlc_object_release( p_announce );
@@ -136,7 +134,7 @@ int sout_AnnounceUnRegister( sout_instance_t *p_sout,
                                               FIND_ANYWHERE );
     if( !p_announce )
     {
-        msg_Dbg( p_sout, "Unable to remove announce: no announce handler" );
+        msg_Dbg( p_sout, "unable to remove announce: no announce handler" );
         return VLC_ENOOBJ;
     }
     i_ret  = announce_UnRegister( p_announce, p_session );
@@ -156,17 +154,10 @@ session_descriptor_t * sout_AnnounceSessionCreate(void)
     session_descriptor_t *p_session;
 
     p_session = (session_descriptor_t *)malloc( sizeof(session_descriptor_t));
+    if (p_session == NULL)
+        return NULL;
 
-    if( p_session)
-    {
-        p_session->p_sap = NULL;
-        p_session->psz_sdp = NULL;
-        p_session->psz_name = NULL;
-        p_session->psz_uri = NULL;
-        p_session->i_port = 0;
-        p_session->psz_group = NULL;
-    }
-
+    memset (p_session, 0, sizeof (*p_session));
     return p_session;
 }
 
@@ -180,10 +171,10 @@ void sout_AnnounceSessionDestroy( session_descriptor_t *p_session )
 {
     if( p_session )
     {
-        FREE( p_session->psz_name );
-        FREE( p_session->psz_group );
-        FREE( p_session->psz_uri );
-        FREE( p_session->psz_sdp );
+        FREENULL( p_session->psz_name );
+        FREENULL( p_session->psz_group );
+        FREENULL( p_session->psz_uri );
+        FREENULL( p_session->psz_sdp );
         free( p_session );
     }
 }
@@ -191,7 +182,7 @@ void sout_AnnounceSessionDestroy( session_descriptor_t *p_session )
 /**
  * Create and initialize an announcement method structure
  *
- * \param i_type METHOD_TYPE_SAP or METHOD_TYPE_SLP
+ * \param i_type METHOD_TYPE_SAP
  * \return a new announce_method structure
  */
 announce_method_t * sout_AnnounceMethodCreate( int i_type )
@@ -199,14 +190,10 @@ announce_method_t * sout_AnnounceMethodCreate( int i_type )
     announce_method_t *p_method;
 
     p_method = (announce_method_t *)malloc( sizeof(announce_method_t) );
+    if( p_method == NULL )
+        return NULL;
 
-    if( p_method )
-    {
-        p_method->i_type = i_type;
-        if( i_type == METHOD_TYPE_SAP )
-            /* Default value */
-            p_method->psz_address = NULL;
-    }
+    p_method->i_type = i_type;
     return p_method;
 }
 
@@ -233,9 +220,7 @@ announce_handler_t *__announce_HandlerCreate( vlc_object_t *p_this )
     }
 
     p_announce->p_sap = NULL;
-
-    vlc_object_attach( p_announce, p_this->p_vlc);
-
+    vlc_object_attach( p_announce, p_this->p_libvlc);
 
     return p_announce;
 }
@@ -286,16 +271,11 @@ int announce_Register( announce_handler_t *p_announce,
         }
         /* this will set p_session->p_sap for later deletion */
         msg_Dbg( p_announce, "adding SAP session");
-        p_announce->p_sap->pf_add( p_announce->p_sap, p_session, p_method );
-    }
-    else if( p_method->i_type == METHOD_TYPE_SLP )
-    {
-        msg_Dbg( p_announce, "SLP unsupported at the moment" );
-        return VLC_EGENERIC;
+        p_announce->p_sap->pf_add( p_announce->p_sap, p_session );
     }
     else
     {
-        msg_Dbg( p_announce, "Announce type unsupported" );
+        msg_Dbg( p_announce, "announce type unsupported" );
         return VLC_EGENERIC;
     }
     return VLC_SUCCESS;;