Commit 4d269a64 authored by Pierre Ynard's avatar Pierre Ynard

rtp sout: safer numbering of RTSP tracks

parent ea9810b5
...@@ -683,7 +683,7 @@ static void SDPHandleUrl( sout_stream_t *p_stream, const char *psz_url ) ...@@ -683,7 +683,7 @@ static void SDPHandleUrl( sout_stream_t *p_stream, const char *psz_url )
if( p_sys->p_mux != NULL ) if( p_sys->p_mux != NULL )
{ {
sout_stream_id_t *id = p_sys->es[0]; sout_stream_id_t *id = p_sys->es[0];
id->rtsp_id = RtspAddId( p_sys->rtsp, id, 0, GetDWBE( id->ssrc ), id->rtsp_id = RtspAddId( p_sys->rtsp, id, GetDWBE( id->ssrc ),
p_sys->psz_destination, p_sys->i_ttl, p_sys->psz_destination, p_sys->i_ttl,
id->i_port, id->i_port + 1 ); id->i_port, id->i_port + 1 );
} }
...@@ -1339,7 +1339,7 @@ static sout_stream_id_t *Add( sout_stream_t *p_stream, es_format_t *p_fmt ) ...@@ -1339,7 +1339,7 @@ static sout_stream_id_t *Add( sout_stream_t *p_stream, es_format_t *p_fmt )
id->i_ts_offset = rtp_compute_ts( id, p_sys->i_pts_offset ); id->i_ts_offset = rtp_compute_ts( id, p_sys->i_pts_offset );
if( p_sys->rtsp != NULL ) if( p_sys->rtsp != NULL )
id->rtsp_id = RtspAddId( p_sys->rtsp, id, p_sys->i_es, id->rtsp_id = RtspAddId( p_sys->rtsp, id,
GetDWBE( id->ssrc ), GetDWBE( id->ssrc ),
p_sys->psz_destination, p_sys->psz_destination,
p_sys->i_ttl, id->i_port, id->i_port + 1 ); p_sys->i_ttl, id->i_port, id->i_port + 1 );
...@@ -1740,25 +1740,6 @@ int64_t rtp_get_ts( const sout_stream_t *p_stream ) ...@@ -1740,25 +1740,6 @@ int64_t rtp_get_ts( const sout_stream_t *p_stream )
return p_sys->i_pts_zero + (now - i_npt_zero); return p_sys->i_pts_zero + (now - i_npt_zero);
} }
/* FIXME: this is pretty bad - if we remove and then insert an ES
* the number will get unsynched from inside RTSP */
unsigned rtp_get_num( const sout_stream_id_t *id )
{
sout_stream_sys_t *p_sys = id->p_stream->p_sys;
int i;
vlc_mutex_lock( &p_sys->lock_es );
for( i = 0; i < p_sys->i_es; i++ )
{
if( id == p_sys->es[i] )
break;
}
vlc_mutex_unlock( &p_sys->lock_es );
return i;
}
void rtp_packetize_common( sout_stream_id_t *id, block_t *out, void rtp_packetize_common( sout_stream_id_t *id, block_t *out,
int b_marker, int64_t i_pts ) int b_marker, int64_t i_pts )
{ {
......
...@@ -29,7 +29,7 @@ rtsp_stream_t *RtspSetup( sout_stream_t *p_stream, const vlc_url_t *url ); ...@@ -29,7 +29,7 @@ rtsp_stream_t *RtspSetup( sout_stream_t *p_stream, const vlc_url_t *url );
void RtspUnsetup( rtsp_stream_t *rtsp ); void RtspUnsetup( rtsp_stream_t *rtsp );
rtsp_stream_id_t *RtspAddId( rtsp_stream_t *rtsp, sout_stream_id_t *sid, rtsp_stream_id_t *RtspAddId( rtsp_stream_t *rtsp, sout_stream_id_t *sid,
unsigned i, uint32_t ssrc, uint32_t ssrc,
const char *dst, int ttl, const char *dst, int ttl,
unsigned loport, unsigned hiport ); unsigned loport, unsigned hiport );
void RtspDelId( rtsp_stream_t *rtsp, rtsp_stream_id_t * ); void RtspDelId( rtsp_stream_t *rtsp, rtsp_stream_id_t * );
...@@ -41,7 +41,6 @@ int rtp_add_sink( sout_stream_id_t *id, int fd, bool rtcp_mux, uint16_t *seq ); ...@@ -41,7 +41,6 @@ int rtp_add_sink( sout_stream_id_t *id, int fd, bool rtcp_mux, uint16_t *seq );
void rtp_del_sink( sout_stream_id_t *id, int fd ); void rtp_del_sink( sout_stream_id_t *id, int fd );
uint16_t rtp_get_seq( sout_stream_id_t *id ); uint16_t rtp_get_seq( sout_stream_id_t *id );
int64_t rtp_get_ts( const sout_stream_t *p_stream ); int64_t rtp_get_ts( const sout_stream_t *p_stream );
unsigned rtp_get_num( const sout_stream_id_t *id );
/* RTP packetization */ /* RTP packetization */
void rtp_packetize_common (sout_stream_id_t *id, block_t *out, void rtp_packetize_common (sout_stream_id_t *id, block_t *out,
......
...@@ -53,6 +53,7 @@ struct rtsp_stream_t ...@@ -53,6 +53,7 @@ struct rtsp_stream_t
httpd_url_t *url; httpd_url_t *url;
char *psz_path; char *psz_path;
const char *track_fmt; const char *track_fmt;
unsigned track_id;
unsigned port; unsigned port;
int sessionc; int sessionc;
...@@ -84,6 +85,7 @@ rtsp_stream_t *RtspSetup( sout_stream_t *p_stream, const vlc_url_t *url ) ...@@ -84,6 +85,7 @@ rtsp_stream_t *RtspSetup( sout_stream_t *p_stream, const vlc_url_t *url )
rtsp->host = NULL; rtsp->host = NULL;
rtsp->url = NULL; rtsp->url = NULL;
rtsp->psz_path = NULL; rtsp->psz_path = NULL;
rtsp->track_id = 0;
vlc_mutex_init( &rtsp->lock ); vlc_mutex_init( &rtsp->lock );
rtsp->port = (url->i_port > 0) ? url->i_port : 554; rtsp->port = (url->i_port > 0) ? url->i_port : 554;
...@@ -150,6 +152,7 @@ struct rtsp_stream_id_t ...@@ -150,6 +152,7 @@ struct rtsp_stream_id_t
httpd_url_t *url; httpd_url_t *url;
const char *dst; const char *dst;
int ttl; int ttl;
unsigned track_id;
uint32_t ssrc; uint32_t ssrc;
uint16_t loport, hiport; uint16_t loport, hiport;
}; };
...@@ -172,14 +175,14 @@ struct rtsp_session_t ...@@ -172,14 +175,14 @@ struct rtsp_session_t
/* Unicast session track */ /* Unicast session track */
struct rtsp_strack_t struct rtsp_strack_t
{ {
sout_stream_id_t *id; rtsp_stream_id_t *id;
int fd; int fd;
bool playing; bool playing;
}; };
rtsp_stream_id_t *RtspAddId( rtsp_stream_t *rtsp, sout_stream_id_t *sid, rtsp_stream_id_t *RtspAddId( rtsp_stream_t *rtsp, sout_stream_id_t *sid,
unsigned num, uint32_t ssrc, uint32_t ssrc,
/* Multicast stuff - TODO: cleanup */ /* Multicast stuff - TODO: cleanup */
const char *dst, int ttl, const char *dst, int ttl,
unsigned loport, unsigned hiport ) unsigned loport, unsigned hiport )
...@@ -193,6 +196,7 @@ rtsp_stream_id_t *RtspAddId( rtsp_stream_t *rtsp, sout_stream_id_t *sid, ...@@ -193,6 +196,7 @@ rtsp_stream_id_t *RtspAddId( rtsp_stream_t *rtsp, sout_stream_id_t *sid,
id->stream = rtsp; id->stream = rtsp;
id->sout_id = sid; id->sout_id = sid;
id->track_id = rtsp->track_id;
id->ssrc = ssrc; id->ssrc = ssrc;
/* TODO: can we assume that this need not be strdup'd? */ /* TODO: can we assume that this need not be strdup'd? */
id->dst = dst; id->dst = dst;
...@@ -203,9 +207,8 @@ rtsp_stream_id_t *RtspAddId( rtsp_stream_t *rtsp, sout_stream_id_t *sid, ...@@ -203,9 +207,8 @@ rtsp_stream_id_t *RtspAddId( rtsp_stream_t *rtsp, sout_stream_id_t *sid,
id->hiport = hiport; id->hiport = hiport;
} }
/* FIXME: num screws up if any ES has been removed and re-added */
snprintf( urlbuf, sizeof( urlbuf ), rtsp->track_fmt, rtsp->psz_path, snprintf( urlbuf, sizeof( urlbuf ), rtsp->track_fmt, rtsp->psz_path,
num ); id->track_id );
msg_Dbg( rtsp->owner, "RTSP: adding %s", urlbuf ); msg_Dbg( rtsp->owner, "RTSP: adding %s", urlbuf );
url = id->url = httpd_UrlNewUnique( rtsp->host, urlbuf, NULL, NULL, NULL ); url = id->url = httpd_UrlNewUnique( rtsp->host, urlbuf, NULL, NULL, NULL );
...@@ -222,6 +225,8 @@ rtsp_stream_id_t *RtspAddId( rtsp_stream_t *rtsp, sout_stream_id_t *sid, ...@@ -222,6 +225,8 @@ rtsp_stream_id_t *RtspAddId( rtsp_stream_t *rtsp, sout_stream_id_t *sid,
httpd_UrlCatch( url, HTTPD_MSG_GETPARAMETER, RtspCallbackId, (void *)id ); httpd_UrlCatch( url, HTTPD_MSG_GETPARAMETER, RtspCallbackId, (void *)id );
httpd_UrlCatch( url, HTTPD_MSG_TEARDOWN, RtspCallbackId, (void *)id ); httpd_UrlCatch( url, HTTPD_MSG_TEARDOWN, RtspCallbackId, (void *)id );
rtsp->track_id++;
return id; return id;
} }
...@@ -235,7 +240,7 @@ void RtspDelId( rtsp_stream_t *rtsp, rtsp_stream_id_t *id ) ...@@ -235,7 +240,7 @@ void RtspDelId( rtsp_stream_t *rtsp, rtsp_stream_id_t *id )
for( int j = 0; j < ses->trackc; j++ ) for( int j = 0; j < ses->trackc; j++ )
{ {
if( ses->trackv[j].id == id->sout_id ) if( ses->trackv[j].id == id )
{ {
rtsp_strack_t *tr = ses->trackv + j; rtsp_strack_t *tr = ses->trackv + j;
net_Close( tr->fd ); net_Close( tr->fd );
...@@ -303,7 +308,7 @@ void RtspClientDel( rtsp_stream_t *rtsp, rtsp_session_t *session ) ...@@ -303,7 +308,7 @@ void RtspClientDel( rtsp_stream_t *rtsp, rtsp_session_t *session )
TAB_REMOVE( rtsp->sessionc, rtsp->sessionv, session ); TAB_REMOVE( rtsp->sessionc, rtsp->sessionv, session );
for( i = 0; i < session->trackc; i++ ) for( i = 0; i < session->trackc; i++ )
rtp_del_sink( session->trackv[i].id, session->trackv[i].fd ); rtp_del_sink( session->trackv[i].id->sout_id, session->trackv[i].fd );
free( session->trackv ); free( session->trackv );
free( session ); free( session );
...@@ -537,7 +542,7 @@ static int RtspHandler( rtsp_stream_t *rtsp, rtsp_stream_id_t *id, ...@@ -537,7 +542,7 @@ static int RtspHandler( rtsp_stream_t *rtsp, rtsp_stream_id_t *id,
{ {
char ip[NI_MAXNUMERICHOST], src[NI_MAXNUMERICHOST]; char ip[NI_MAXNUMERICHOST], src[NI_MAXNUMERICHOST];
rtsp_session_t *ses = NULL; rtsp_session_t *ses = NULL;
rtsp_strack_t track = { id->sout_id, -1, false }; rtsp_strack_t track = { id, -1, false };
int sport; int sport;
if( httpd_ClientIP( cl, ip ) == NULL ) if( httpd_ClientIP( cl, ip ) == NULL )
...@@ -646,22 +651,21 @@ static int RtspHandler( rtsp_stream_t *rtsp, rtsp_stream_id_t *id, ...@@ -646,22 +651,21 @@ static int RtspHandler( rtsp_stream_t *rtsp, rtsp_stream_id_t *id,
for( int i = 0; i < ses->trackc; i++ ) for( int i = 0; i < ses->trackc; i++ )
{ {
rtsp_strack_t *tr = ses->trackv + i; rtsp_strack_t *tr = ses->trackv + i;
if( ( id == NULL ) || ( tr->id == id->sout_id ) ) if( ( id == NULL ) || ( tr->id == id ) )
{ {
uint16_t seq; uint16_t seq;
if( !tr->playing ) if( !tr->playing )
{ {
tr->playing = true; tr->playing = true;
rtp_add_sink( tr->id, tr->fd, false, &seq ); rtp_add_sink( tr->id->sout_id, tr->fd, false,
&seq );
} }
else else
seq = rtp_get_seq( tr->id ); seq = rtp_get_seq( tr->id->sout_id );
infolen += sprintf( info + infolen, infolen += sprintf( info + infolen,
"url=%s/trackID=%u;seq=%u;rtptime=%u, ", "url=%s/trackID=%u;seq=%u;rtptime=%u, ",
control, control, tr->id->track_id, seq,
rtp_get_num( tr->id ), rtp_compute_ts( tr->id->sout_id, ts ) );
seq,
rtp_compute_ts( tr->id, ts ) );
} }
} }
if( infolen > 0 ) if( infolen > 0 )
...@@ -712,7 +716,7 @@ static int RtspHandler( rtsp_stream_t *rtsp, rtsp_stream_id_t *id, ...@@ -712,7 +716,7 @@ static int RtspHandler( rtsp_stream_t *rtsp, rtsp_stream_id_t *id,
else /* Delete one track from the session */ else /* Delete one track from the session */
for( int i = 0; i < ses->trackc; i++ ) for( int i = 0; i < ses->trackc; i++ )
{ {
if( ses->trackv[i].id == id->sout_id ) if( ses->trackv[i].id == id )
{ {
rtp_del_sink( id->sout_id, ses->trackv[i].fd ); rtp_del_sink( id->sout_id, ses->trackv[i].fd );
REMOVE_ELEM( ses->trackv, ses->trackc, i ); REMOVE_ELEM( ses->trackv, ses->trackc, i );
......
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