#include <vlc_httpd.h>
#include <vlc_url.h>
#include <vlc_network.h>
-#include <vlc_charset.h>
+#include <vlc_fs.h>
#include <vlc_strings.h>
#include <vlc_rand.h>
#ifdef HAVE_SRTP
block_t* );
static sout_access_out_t *GrabberCreate( sout_stream_t *p_sout );
-static void* ThreadSend( vlc_object_t *p_this );
+static void* ThreadSend( void * );
static void *rtp_listen_thread( void * );
static void SDPHandleUrl( sout_stream_t *, const char * );
struct sout_stream_id_t
{
- VLC_COMMON_MEMBERS
-
sout_stream_t *p_stream;
/* rtp field */
uint16_t i_sequence;
pf_rtp_packetizer_t pf_packetize;
/* Packets sinks */
+ vlc_thread_t thread;
vlc_mutex_t lock_sink;
int sinkc;
rtp_sink_t *sinkv;
msg_Err( p_stream, "you can use sdp=file:// only once" );
goto out;
}
- psz_url = &psz_url[5];
- if( psz_url[0] == '/' && psz_url[1] == '/' )
- psz_url += 2;
- p_sys->psz_sdp_file = strdup( psz_url );
+ p_sys->psz_sdp_file = make_path( psz_url );
if( p_sys->psz_sdp_file == NULL )
goto out;
- decode_URI( p_sys->psz_sdp_file ); /* FIXME? */
FileSetup( p_stream );
}
else
* 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;
- char *psz_sdp;
+ sout_stream_sys_t *p_sys = p_stream->p_sys;
+ char *psz_sdp = NULL;
struct sockaddr_storage dst;
socklen_t dstlen;
int i;
*/
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],
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 )
}
}
- /* FIXME: locking?! */
for( i = 0; i < p_sys->i_es; i++ )
{
sout_stream_id_t *id = p_sys->es[i];
"SC:RTP%c", toupper( mime_major[0] ) );
}
}
-
+out:
+ vlc_mutex_unlock( &p_sys->lock_es );
return psz_sdp;
}
/* NOTE: As a special case, if we use a non-RTP
* mux (TS/PS), then p_fmt is NULL. */
sout_stream_sys_t *p_sys = p_stream->p_sys;
- sout_stream_id_t *id;
char *psz_sdp;
if (0 == p_sys->payload_bitmap)
i_port = 0;
}
- id = vlc_object_create( p_stream, sizeof( sout_stream_id_t ) );
- if( id == NULL )
+ sout_stream_id_t *id = malloc( sizeof( *id ) );
+ if( unlikely(id == NULL) )
return NULL;
- vlc_object_attach( id, p_stream );
-
id->p_stream = p_stream;
/* Look for free dymanic payload type */
#ifdef HAVE_SRTP
id->srtp = NULL;
+#endif
+ vlc_mutex_init( &id->lock_sink );
+ id->sinkc = 0;
+ id->sinkv = NULL;
+ id->rtsp_id = NULL;
+ id->p_fifo = NULL;
+ id->listen.fd = NULL;
+ id->i_caching =
+ (int64_t)1000 * var_GetInteger( p_stream, SOUT_CFG_PREFIX "caching");
+
+#ifdef HAVE_SRTP
char *key = var_CreateGetNonEmptyString (p_stream, SOUT_CFG_PREFIX"key");
if (key)
{
}
#endif
- vlc_mutex_init( &id->lock_sink );
- id->sinkc = 0;
- id->sinkv = NULL;
- id->rtsp_id = NULL;
- id->p_fifo = NULL;
- id->listen.fd = NULL;
-
- id->i_caching =
- (int64_t)1000 * var_GetInteger( p_stream, SOUT_CFG_PREFIX "caching");
-
if( p_sys->psz_destination != NULL )
switch( p_sys->proto )
{
p_sys->i_ttl, id->i_port, id->i_port + 1 );
id->p_fifo = block_FifoNew();
- if( vlc_thread_create( id, "RTP send thread", ThreadSend,
- VLC_THREAD_PRIORITY_HIGHEST ) )
+ if( unlikely(id->p_fifo == NULL) )
+ goto error;
+ if( vlc_clone( &id->thread, ThreadSend, id, VLC_THREAD_PRIORITY_HIGHEST ) )
+ {
+ block_FifoRelease( id->p_fifo );
+ id->p_fifo = NULL;
goto error;
+ }
/* Update p_sys context */
vlc_mutex_lock( &p_sys->lock_es );
{
sout_stream_sys_t *p_sys = p_stream->p_sys;
- if( id->p_fifo != NULL )
- {
- vlc_object_kill( id );
- vlc_thread_join( id );
- block_FifoRelease( id->p_fifo );
- }
-
vlc_mutex_lock( &p_sys->lock_es );
TAB_REMOVE( p_sys->i_es, p_sys->es, id );
vlc_mutex_unlock( &p_sys->lock_es );
+ if( likely(id->p_fifo != NULL) )
+ {
+ vlc_cancel( id->thread );
+ vlc_join( id->thread, NULL );
+ block_FifoRelease( id->p_fifo );
+ }
+
/* Release dynamic payload type */
if (id->i_payload_type >= 96)
p_sys->payload_bitmap |= 1 << (127 - id->i_payload_type);
if( p_sys->b_export_sap && !p_sys->p_mux ) SapSetup( p_stream );
if( p_sys->psz_sdp_file != NULL ) FileSetup( p_stream );
- vlc_object_release( id );
+ free( id );
return VLC_SUCCESS;
}
if( p_sys->psz_sdp == NULL )
return VLC_EGENERIC; /* too early */
- if( ( f = utf8_fopen( p_sys->psz_sdp_file, "wt" ) ) == NULL )
+ if( ( f = vlc_fopen( p_sys->psz_sdp_file, "wt" ) ) == NULL )
{
msg_Err( p_stream, "cannot open file '%s' (%m)",
p_sys->psz_sdp_file );
/****************************************************************************
* RTP send
****************************************************************************/
-static void* ThreadSend( vlc_object_t *p_this )
+static void* ThreadSend( void *data )
{
#ifdef WIN32
# define ECONNREFUSED WSAECONNREFUSED
# define EAGAIN WSAEWOULDBLOCK
# define EWOULDBLOCK WSAEWOULDBLOCK
#endif
- sout_stream_id_t *id = (sout_stream_id_t *)p_this;
+ sout_stream_id_t *id = data;
unsigned i_caching = id->i_caching;
for (;;)
if( val )
{
errno = val;
- msg_Dbg( id, "SRTP sending error: %m" );
+ msg_Dbg( id->p_stream, "SRTP sending error: %m" );
block_Release( out );
out = NULL;
}
for( unsigned i = 0; i < deadc; i++ )
{
- msg_Dbg( id, "removing socket %d", deadv[i] );
+ msg_Dbg( id->p_stream, "removing socket %d", deadv[i] );
rtp_del_sink( id, deadv[i] );
}
vlc_restorecancel (canc);
for( ;; )
{
- int fd = net_Accept( id, id->listen.fd );
+ int fd = net_Accept( id->p_stream, id->listen.fd );
if( fd == -1 )
continue;
int canc = vlc_savecancel( );
sink.rtcp = OpenRTCP( VLC_OBJECT( id->p_stream ), fd, IPPROTO_UDP,
rtcp_mux );
if( sink.rtcp == NULL )
- msg_Err( id, "RTCP failed!" );
+ msg_Err( id->p_stream, "RTCP failed!" );
vlc_mutex_lock( &id->lock_sink );
INSERT_ELEM( id->sinkv, id->sinkc, id->sinkc, sink );