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

RTP output: accept COMEDIA connections in a separate thread

parent 7c1fed03
...@@ -233,6 +233,7 @@ static int MuxSend( sout_stream_t *, sout_stream_id_t *, ...@@ -233,6 +233,7 @@ static int MuxSend( sout_stream_t *, sout_stream_id_t *,
static sout_access_out_t *GrabberCreate( sout_stream_t *p_sout ); static sout_access_out_t *GrabberCreate( sout_stream_t *p_sout );
static void* ThreadSend( vlc_object_t *p_this ); static void* ThreadSend( vlc_object_t *p_this );
static void *rtp_listen_thread( void * );
static void SDPHandleUrl( sout_stream_t *, const char * ); static void SDPHandleUrl( sout_stream_t *, const char * );
...@@ -319,7 +320,10 @@ struct sout_stream_id_t ...@@ -319,7 +320,10 @@ struct sout_stream_id_t
int sinkc; int sinkc;
rtp_sink_t *sinkv; rtp_sink_t *sinkv;
rtsp_stream_id_t *rtsp_id; rtsp_stream_id_t *rtsp_id;
int *listen_fd; struct {
int *fd;
vlc_thread_t thread;
} listen;
block_fifo_t *p_fifo; block_fifo_t *p_fifo;
int64_t i_caching; int64_t i_caching;
...@@ -713,8 +717,8 @@ char *SDPGenerate( const sout_stream_t *p_stream, const char *rtsp_url ) ...@@ -713,8 +717,8 @@ char *SDPGenerate( const sout_stream_t *p_stream, const char *rtsp_url )
/* Oh boy, this is really ugly! (+ race condition on lock_es) */ /* Oh boy, this is really ugly! (+ race condition on lock_es) */
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],
(struct sockaddr *)&dst, &dstlen ); (struct sockaddr *)&dst, &dstlen );
else else
getpeername( p_sys->es[0]->sinkv[0].rtp_fd, getpeername( p_sys->es[0]->sinkv[0].rtp_fd,
...@@ -802,7 +806,7 @@ char *SDPGenerate( const sout_stream_t *p_stream, const char *rtsp_url ) ...@@ -802,7 +806,7 @@ char *SDPGenerate( const sout_stream_t *p_stream, const char *rtsp_url )
} }
else else
{ {
if( id->listen_fd != NULL ) if( id->listen.fd != NULL )
sdp_AddAttribute( &psz_sdp, "setup", "passive" ); sdp_AddAttribute( &psz_sdp, "setup", "passive" );
if( p_sys->proto == IPPROTO_DCCP ) if( p_sys->proto == IPPROTO_DCCP )
sdp_AddAttribute( &psz_sdp, "dccp-service-code", sdp_AddAttribute( &psz_sdp, "dccp-service-code",
...@@ -965,7 +969,7 @@ static sout_stream_id_t *Add( sout_stream_t *p_stream, es_format_t *p_fmt ) ...@@ -965,7 +969,7 @@ static sout_stream_id_t *Add( sout_stream_t *p_stream, es_format_t *p_fmt )
id->sinkv = NULL; id->sinkv = NULL;
id->rtsp_id = NULL; id->rtsp_id = NULL;
id->p_fifo = NULL; id->p_fifo = NULL;
id->listen_fd = NULL; id->listen.fd = NULL;
id->i_caching = id->i_caching =
(int64_t)1000 * var_GetInteger( p_stream, SOUT_CFG_PREFIX "caching"); (int64_t)1000 * var_GetInteger( p_stream, SOUT_CFG_PREFIX "caching");
...@@ -986,14 +990,21 @@ static sout_stream_id_t *Add( sout_stream_t *p_stream, es_format_t *p_fmt ) ...@@ -986,14 +990,21 @@ static sout_stream_id_t *Add( sout_stream_t *p_stream, es_format_t *p_fmt )
var_SetString (p_stream, "dccp-service", code); var_SetString (p_stream, "dccp-service", code);
} /* fall through */ } /* fall through */
case IPPROTO_TCP: case IPPROTO_TCP:
id->listen_fd = net_Listen( VLC_OBJECT(p_stream), id->listen.fd = net_Listen( VLC_OBJECT(p_stream),
p_sys->psz_destination, i_port, p_sys->psz_destination, i_port,
p_sys->proto ); p_sys->proto );
if( id->listen_fd == NULL ) if( id->listen.fd == NULL )
{ {
msg_Err( p_stream, "passive COMEDIA RTP socket failed" ); msg_Err( p_stream, "passive COMEDIA RTP socket failed" );
goto error; goto error;
} }
if( vlc_clone( &id->listen.thread, rtp_listen_thread, id,
VLC_THREAD_PRIORITY_LOW ) )
{
net_ListenClose( id->listen.fd );
id->listen.fd = NULL;
goto error;
}
break; break;
default: default:
...@@ -1325,8 +1336,12 @@ static int Del( sout_stream_t *p_stream, sout_stream_id_t *id ) ...@@ -1325,8 +1336,12 @@ static int Del( sout_stream_t *p_stream, sout_stream_id_t *id )
RtspDelId( p_sys->rtsp, id->rtsp_id ); RtspDelId( p_sys->rtsp, id->rtsp_id );
if( id->sinkc > 0 ) if( id->sinkc > 0 )
rtp_del_sink( id, id->sinkv[0].rtp_fd ); /* sink for explicit dst= */ rtp_del_sink( id, id->sinkv[0].rtp_fd ); /* sink for explicit dst= */
if( id->listen_fd != NULL ) if( id->listen.fd != NULL )
net_ListenClose( id->listen_fd ); {
vlc_cancel( id->listen.thread );
vlc_join( id->listen.thread, NULL );
net_ListenClose( id->listen.fd );
}
if( id->srtp != NULL ) if( id->srtp != NULL )
srtp_destroy( id->srtp ); srtp_destroy( id->srtp );
...@@ -1560,21 +1575,33 @@ static void* ThreadSend( vlc_object_t *p_this ) ...@@ -1560,21 +1575,33 @@ static void* ThreadSend( vlc_object_t *p_this )
msg_Dbg( id, "removing socket %d", deadv[i] ); msg_Dbg( id, "removing socket %d", deadv[i] );
rtp_del_sink( id, deadv[i] ); rtp_del_sink( id, deadv[i] );
} }
vlc_restorecancel (canc);
}
return NULL;
}
/* Hopefully we won't overflow the SO_MAXCONN accept queue */ /* This thread dequeues incoming connections (DCCP streaming) */
while( id->listen_fd != NULL ) static void *rtp_listen_thread( void *data )
{
sout_stream_id_t *id = data;
assert( id->listen.fd != NULL );
for( ;; )
{ {
int fd = net_Accept( id, id->listen_fd, 0 ); int fd = net_Accept( id, id->listen.fd, -1 );
if( fd == -1 ) if( fd == -1 )
break; continue;
msg_Dbg( id, "adding socket %d", fd ); int canc = vlc_savecancel( );
rtp_add_sink( id, fd, true ); rtp_add_sink( id, fd, true );
vlc_restorecancel( canc );
} }
vlc_restorecancel (canc);
} assert( 0 );
return NULL;
} }
int rtp_add_sink( sout_stream_id_t *id, int fd, bool rtcp_mux ) int rtp_add_sink( sout_stream_id_t *id, int fd, bool rtcp_mux )
{ {
rtp_sink_t sink = { fd, NULL }; rtp_sink_t sink = { fd, NULL };
......
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