[vlc-devel] commit: RTP out: fix race condition in SDP generation from RTSP DESCRIBE ( Rémi Denis-Courmont )

git version control git at videolan.org
Wed Feb 17 17:39:29 CET 2010


vlc | branch: master | Rémi Denis-Courmont <remi at remlab.net> | Wed Feb 17 18:38:33 2010 +0200| [b8ef158dad5705cd3aa74c5b703c8d6c2a128bc3] | committer: Rémi Denis-Courmont 

RTP out: fix race condition in SDP generation from RTSP DESCRIBE

> http://git.videolan.org/gitweb.cgi/vlc.git/?a=commit;h=b8ef158dad5705cd3aa74c5b703c8d6c2a128bc3
---

 modules/stream_out/rtp.c |   16 ++++++++++------
 modules/stream_out/rtp.h |    2 +-
 2 files changed, 11 insertions(+), 7 deletions(-)

diff --git a/modules/stream_out/rtp.c b/modules/stream_out/rtp.c
index f9ae123..266bab2 100644
--- a/modules/stream_out/rtp.c
+++ b/modules/stream_out/rtp.c
@@ -722,9 +722,9 @@ out:
  * SDPGenerate
  *****************************************************************************/
 /*static*/
-char *SDPGenerate( const sout_stream_t *p_stream, const char *rtsp_url )
+char *SDPGenerate( sout_stream_t *p_stream, const char *rtsp_url )
 {
-    const sout_stream_sys_t *p_sys = p_stream->p_sys;
+    sout_stream_sys_t *p_sys = p_stream->p_sys;
     char *psz_sdp;
     struct sockaddr_storage dst;
     socklen_t dstlen;
@@ -746,11 +746,15 @@ char *SDPGenerate( const sout_stream_t *p_stream, const char *rtsp_url )
      */
     int inclport;
 
+    vlc_mutex_lock( &p_sys->lock_es );
+    if( unlikely(p_sys->i_es == 0) )
+        goto out; /* hmm... */
+
     if( p_sys->psz_destination != NULL )
     {
         inclport = 1;
 
-        /* Oh boy, this is really ugly! (+ race condition on lock_es) */
+        /* Oh boy, this is really ugly! */
         dstlen = sizeof( dst );
         if( p_sys->es[0]->listen.fd != NULL )
             getsockname( p_sys->es[0]->listen.fd[0],
@@ -780,7 +784,7 @@ char *SDPGenerate( const sout_stream_t *p_stream, const char *rtsp_url )
     psz_sdp = vlc_sdp_Start( VLC_OBJECT( p_stream ), SOUT_CFG_PREFIX,
                              NULL, 0, (struct sockaddr *)&dst, dstlen );
     if( psz_sdp == NULL )
-        return NULL;
+        goto out;
 
     /* TODO: a=source-filter */
     if( p_sys->rtcp_mux )
@@ -807,7 +811,6 @@ char *SDPGenerate( const sout_stream_t *p_stream, const char *rtsp_url )
         }
     }
 
-    /* FIXME: locking?! */
     for( i = 0; i < p_sys->i_es; i++ )
     {
         sout_stream_id_t *id = p_sys->es[i];
@@ -854,7 +857,8 @@ char *SDPGenerate( const sout_stream_t *p_stream, const char *rtsp_url )
                                   "SC:RTP%c", toupper( mime_major[0] ) );
         }
     }
-
+out:
+    vlc_mutex_unlock( &p_sys->lock_es );
     return psz_sdp;
 }
 
diff --git a/modules/stream_out/rtp.h b/modules/stream_out/rtp.h
index 94b8a79..01e7288 100644
--- a/modules/stream_out/rtp.h
+++ b/modules/stream_out/rtp.h
@@ -36,7 +36,7 @@ void RtspDelId( rtsp_stream_t *rtsp, rtsp_stream_id_t * );
 
 char *RtspAppendTrackPath( rtsp_stream_id_t *id, const char *base );
 
-char *SDPGenerate( const sout_stream_t *p_stream, const char *rtsp_url );
+char *SDPGenerate( sout_stream_t *p_stream, const char *rtsp_url );
 
 uint32_t rtp_compute_ts( const sout_stream_id_t *id, int64_t i_pts );
 int rtp_add_sink( sout_stream_id_t *id, int fd, bool rtcp_mux, uint16_t *seq );




More information about the vlc-devel mailing list