vlc_mutex_t lock_sdp;
/* SDP to disk */
- bool b_export_sdp_file;
char *psz_sdp_file;
/* SDP via SAP */
p_sys->i_port_video = var_GetInteger( p_stream, SOUT_CFG_PREFIX "port-video" );
p_sys->rtcp_mux = var_GetBool( p_stream, SOUT_CFG_PREFIX "rtcp-mux" );
- p_sys->psz_sdp_file = NULL;
-
if( p_sys->i_port_audio && p_sys->i_port_video == p_sys->i_port_audio )
{
msg_Err( p_stream, "audio and video RTP port must be distinct" );
p_sys->psz_sdp = NULL;
p_sys->b_export_sap = false;
- p_sys->b_export_sdp_file = false;
p_sys->p_session = NULL;
+ p_sys->psz_sdp_file = NULL;
p_sys->p_httpd_host = NULL;
p_sys->p_httpd_file = NULL;
if( p_sys->p_mux )
{
assert( p_sys->i_es == 1 );
- Del( p_stream, p_sys->es[0] );
sout_MuxDelete( p_sys->p_mux );
+ Del( p_stream, p_sys->es[0] );
sout_AccessOutDelete( p_sys->p_grab );
+
if( p_sys->packet )
{
block_Release( p_sys->packet );
free( p_sys->psz_sdp );
- if( p_sys->b_export_sdp_file )
+ if( p_sys->psz_sdp_file != NULL )
{
#ifdef HAVE_UNISTD_H
unlink( p_sys->psz_sdp_file );
}
else if( url.psz_protocol && !strcasecmp( url.psz_protocol, "file" ) )
{
- if( p_sys->b_export_sdp_file )
+ if( p_sys->psz_sdp_file != NULL )
{
msg_Err( p_stream, "you can use sdp=file:// only once" );
goto out;
}
- p_sys->b_export_sdp_file = true;
psz_url = &psz_url[5];
if( psz_url[0] == '/' && psz_url[1] == '/' )
psz_url += 2;
p_sys->psz_sdp_file = strdup( psz_url );
+ if( p_sys->psz_sdp_file == NULL )
+ goto out;
+ decode_URI( p_sys->psz_sdp_file ); /* FIXME? */
+ FileSetup( p_stream );
}
else
{
* mux (TS/PS), then p_fmt is NULL. */
sout_stream_sys_t *p_sys = p_stream->p_sys;
sout_stream_id_t *id;
- int i_port, cscov = -1;
+ int cscov = -1;
char *psz_sdp;
- int i_port_audio_option = var_GetInteger( p_stream, "port-audio" );
- int i_port_video_option = var_GetInteger( p_stream, "port-video" );
if (0xffffffff == p_sys->payload_bitmap)
{
return NULL;
}
- id = vlc_object_create( p_stream, sizeof( sout_stream_id_t ) );
- if( id == NULL )
- return NULL;
- vlc_object_attach( id, p_stream );
-
/* Choose the port */
- i_port = 0;
+ uint16_t i_port = 0;
if( p_fmt == NULL )
;
else
if( p_fmt->i_cat == AUDIO_ES && p_sys->i_port_audio > 0 )
- {
i_port = p_sys->i_port_audio;
- p_sys->i_port_audio = 0;
- }
else
if( p_fmt->i_cat == VIDEO_ES && p_sys->i_port_video > 0 )
- {
i_port = p_sys->i_port_video;
- p_sys->i_port_video = 0;
- }
- while( i_port == 0 )
+ /* We do not need the ES lock (p_sys->lock_es) here, because this is the
+ * only one thread that can *modify* the ES table. The ES lock protects
+ * the other threads from our modifications (TAB_APPEND, TAB_REMOVE). */
+ for (int i = 0; i_port && (i < p_sys->i_es); i++)
+ if (i_port == p_sys->es[i]->i_port)
+ i_port = 0; /* Port already in use! */
+ for (uint16_t p = p_sys->i_port; i_port == 0; p += 2)
{
- if( p_sys->i_port != i_port_audio_option
- && p_sys->i_port != i_port_video_option )
+ if (p == 0)
{
- i_port = p_sys->i_port;
+ msg_Err (p_stream, "too many RTP elementary streams");
+ return NULL;
}
- p_sys->i_port += 2;
+ i_port = p;
+ for (int i = 0; i_port && (i < p_sys->i_es); i++)
+ if (p == p_sys->es[i]->i_port)
+ i_port = 0;
}
+ id = vlc_object_create( p_stream, sizeof( sout_stream_id_t ) );
+ if( id == NULL )
+ return NULL;
+ vlc_object_attach( id, p_stream );
+
id->p_stream = p_stream;
/* Look for free dymanic payload type */
id->psz_enc = "G726-40";
id->pf_packetize = rtp_packetize_g726_40;
break;
+ default:
+ msg_Err( p_stream, "cannot add this stream (unsupported "
+ "G.726 bit rate: %u)", p_fmt->i_bitrate );
+ goto error;
}
break;
case VLC_CODEC_A52:
default:
msg_Err( p_stream, "cannot add this stream (unsupported "
- "codec:%4.4s)", (char*)&p_fmt->i_codec );
+ "codec: %4.4s)", (char*)&p_fmt->i_codec );
goto error;
}
if (id->i_payload_type >= 96)
/* Update SDP (sap/file) */
if( p_sys->b_export_sap ) SapSetup( p_stream );
- if( p_sys->b_export_sdp_file ) FileSetup( p_stream );
+ if( p_sys->psz_sdp_file != NULL ) FileSetup( p_stream );
return id;
TAB_REMOVE( p_sys->i_es, p_sys->es, id );
vlc_mutex_unlock( &p_sys->lock_es );
- /* Release port */
- if( id->i_port == var_GetInteger( p_stream, "port-audio" ) )
- p_sys->i_port_audio = id->i_port;
- if( id->i_port == var_GetInteger( p_stream, "port-video" ) )
- p_sys->i_port_video = id->i_port;
/* Release dynamic payload type */
if (id->i_payload_type >= 96)
p_sys->payload_bitmap &= ~(1 << (id->i_payload_type - 96));
/* Update SDP (sap/file) */
if( p_sys->b_export_sap && !p_sys->p_mux ) SapSetup( p_stream );
- if( p_sys->b_export_sdp_file ) FileSetup( p_stream );
+ if( p_sys->psz_sdp_file != NULL ) FileSetup( p_stream );
vlc_object_detach( id );
vlc_object_release( id );
sout_stream_sys_t *p_sys = p_stream->p_sys;
FILE *f;
+ if( p_sys->psz_sdp == NULL )
+ return VLC_EGENERIC; /* too early */
+
if( ( f = utf8_fopen( p_sys->psz_sdp_file, "wt" ) ) == NULL )
{
msg_Err( p_stream, "cannot open file '%s' (%m)",
void rtp_packetize_common( sout_stream_id_t *id, block_t *out,
int b_marker, int64_t i_pts )
{
- uint32_t i_timestamp = i_pts * (int64_t)id->i_clock_rate / INT64_C(1000000);
+ uint32_t i_timestamp = i_pts * (int64_t)id->i_clock_rate / CLOCK_FREQ;
out->p_buffer[0] = 0x80;
out->p_buffer[1] = (b_marker?0x80:0x00)|id->i_payload_type;