Commit b8ef158d authored by Rémi Denis-Courmont's avatar Rémi Denis-Courmont

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

parent 2ed6e6a6
...@@ -722,9 +722,9 @@ out: ...@@ -722,9 +722,9 @@ out:
* SDPGenerate * SDPGenerate
*****************************************************************************/ *****************************************************************************/
/*static*/ /*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; char *psz_sdp;
struct sockaddr_storage dst; struct sockaddr_storage dst;
socklen_t dstlen; socklen_t dstlen;
...@@ -746,11 +746,15 @@ char *SDPGenerate( const sout_stream_t *p_stream, const char *rtsp_url ) ...@@ -746,11 +746,15 @@ char *SDPGenerate( const sout_stream_t *p_stream, const char *rtsp_url )
*/ */
int inclport; 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 ) if( p_sys->psz_destination != NULL )
{ {
inclport = 1; inclport = 1;
/* Oh boy, this is really ugly! (+ race condition on lock_es) */ /* Oh boy, this is really ugly! */
dstlen = sizeof( dst ); dstlen = sizeof( dst );
if( p_sys->es[0]->listen.fd != NULL ) if( p_sys->es[0]->listen.fd != NULL )
getsockname( p_sys->es[0]->listen.fd[0], getsockname( p_sys->es[0]->listen.fd[0],
...@@ -780,7 +784,7 @@ char *SDPGenerate( const sout_stream_t *p_stream, const char *rtsp_url ) ...@@ -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, psz_sdp = vlc_sdp_Start( VLC_OBJECT( p_stream ), SOUT_CFG_PREFIX,
NULL, 0, (struct sockaddr *)&dst, dstlen ); NULL, 0, (struct sockaddr *)&dst, dstlen );
if( psz_sdp == NULL ) if( psz_sdp == NULL )
return NULL; goto out;
/* TODO: a=source-filter */ /* TODO: a=source-filter */
if( p_sys->rtcp_mux ) if( p_sys->rtcp_mux )
...@@ -807,7 +811,6 @@ char *SDPGenerate( const sout_stream_t *p_stream, const char *rtsp_url ) ...@@ -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++ ) for( i = 0; i < p_sys->i_es; i++ )
{ {
sout_stream_id_t *id = p_sys->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 ) ...@@ -854,7 +857,8 @@ char *SDPGenerate( const sout_stream_t *p_stream, const char *rtsp_url )
"SC:RTP%c", toupper( mime_major[0] ) ); "SC:RTP%c", toupper( mime_major[0] ) );
} }
} }
out:
vlc_mutex_unlock( &p_sys->lock_es );
return psz_sdp; return psz_sdp;
} }
......
...@@ -36,7 +36,7 @@ void RtspDelId( rtsp_stream_t *rtsp, rtsp_stream_id_t * ); ...@@ -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 *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 ); 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 ); int rtp_add_sink( sout_stream_id_t *id, int fd, bool rtcp_mux, uint16_t *seq );
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment