#include "rtp.h"
-#ifdef HAVE_UNISTD_H
-# include <sys/types.h>
-# include <unistd.h>
-#endif
+#include <sys/types.h>
+#include <unistd.h>
#ifdef HAVE_ARPA_INET_H
# include <arpa/inet.h>
#endif
# define IPPROTO_UDPLITE 136
#endif
+#include <ctype.h>
#include <errno.h>
-
#include <assert.h>
/*****************************************************************************
add_string( SOUT_CFG_PREFIX "proto", "udp", PROTO_TEXT,
PROTO_LONGTEXT, false )
- change_string_list( ppsz_protos, ppsz_protocols, NULL )
+ change_string_list( ppsz_protos, ppsz_protocols )
add_integer( SOUT_CFG_PREFIX "port", 5004, PORT_TEXT,
PORT_LONGTEXT, true )
add_integer( SOUT_CFG_PREFIX "port-audio", 0, PORT_AUDIO_TEXT,
"mp4a-latm", NULL
};
-static sout_stream_id_t *Add ( sout_stream_t *, es_format_t * );
-static int Del ( sout_stream_t *, sout_stream_id_t * );
-static int Send( sout_stream_t *, sout_stream_id_t *,
+static sout_stream_id_sys_t *Add ( sout_stream_t *, es_format_t * );
+static int Del ( sout_stream_t *, sout_stream_id_sys_t * );
+static int Send( sout_stream_t *, sout_stream_id_sys_t *,
block_t* );
-static sout_stream_id_t *MuxAdd ( sout_stream_t *, es_format_t * );
-static int MuxDel ( sout_stream_t *, sout_stream_id_t * );
-static int MuxSend( sout_stream_t *, sout_stream_id_t *,
+static sout_stream_id_sys_t *MuxAdd ( sout_stream_t *, es_format_t * );
+static int MuxDel ( sout_stream_t *, sout_stream_id_sys_t * );
+static int MuxSend( sout_stream_t *, sout_stream_id_sys_t *,
block_t* );
static sout_access_out_t *GrabberCreate( sout_stream_t *p_sout );
/* */
vlc_mutex_t lock_es;
int i_es;
- sout_stream_id_t **es;
+ sout_stream_id_sys_t **es;
};
typedef struct rtp_sink_t
rtcp_sender_t *rtcp;
} rtp_sink_t;
-struct sout_stream_id_t
+struct sout_stream_id_sys_t
{
sout_stream_t *p_stream;
/* rtp field */
- uint16_t i_sequence;
+ /* For RFC 4175, seqnum is extended to 32-bits */
+ uint32_t i_sequence;
bool b_first_packet;
bool b_ts_init;
uint32_t i_ts_offset;
static int Open( vlc_object_t *p_this )
{
sout_stream_t *p_stream = (sout_stream_t*)p_this;
- sout_instance_t *p_sout = p_stream->p_sout;
sout_stream_sys_t *p_sys = NULL;
config_chain_t *p_cfg = NULL;
char *psz;
}
p_sys->p_grab = GrabberCreate( p_stream );
- p_sys->p_mux = sout_MuxNew( p_sout, psz, p_sys->p_grab );
+ p_sys->p_mux = sout_MuxNew( p_stream->p_sout, psz, p_sys->p_grab );
free( psz );
if( p_sys->p_mux == NULL )
p_stream->pf_del = Del;
p_stream->pf_send = Send;
}
+ p_stream->pace_nocontrol = true;
if( var_GetBool( p_stream, SOUT_CFG_PREFIX"sap" ) )
SDPHandleUrl( p_stream, "sap" );
free( psz );
}
- /* update p_sout->i_out_pace_nocontrol */
- p_stream->p_sout->i_out_pace_nocontrol++;
-
if( p_sys->p_mux != NULL )
{
- sout_stream_id_t *id = Add( p_stream, NULL );
+ sout_stream_id_sys_t *id = Add( p_stream, NULL );
if( id == NULL )
{
Close( p_this );
sout_stream_t *p_stream = (sout_stream_t*)p_this;
sout_stream_sys_t *p_sys = p_stream->p_sys;
- /* update p_sout->i_out_pace_nocontrol */
- p_stream->p_sout->i_out_pace_nocontrol--;
-
if( p_sys->p_mux )
{
assert( p_sys->i_es <= 1 );
if( p_sys->psz_sdp_file != NULL )
{
-#ifdef HAVE_UNISTD_H
unlink( p_sys->psz_sdp_file );
-#endif
free( p_sys->psz_sdp_file );
}
free( p_sys->psz_vod_session );
for( i = 0; i < p_sys->i_es; i++ )
{
- sout_stream_id_t *id = p_sys->es[i];
+ sout_stream_id_sys_t *id = p_sys->es[i];
rtp_format_t *rtp_fmt = &id->rtp_fmt;
const char *mime_major; /* major MIME type */
* Shrink the MTU down to a fixed packetization time (for audio).
*/
static void
-rtp_set_ptime (sout_stream_id_t *id, unsigned ptime_ms, size_t bytes)
+rtp_set_ptime (sout_stream_id_sys_t *id, unsigned ptime_ms, size_t bytes)
{
/* Samples per second */
size_t spl = (id->rtp_fmt.clock_rate - 1) * ptime_ms / 1000 + 1;
}
/** Add an ES as a new RTP stream */
-static sout_stream_id_t *Add( sout_stream_t *p_stream, es_format_t *p_fmt )
+static sout_stream_id_sys_t *Add( sout_stream_t *p_stream, es_format_t *p_fmt )
{
/* 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;
char *psz_sdp;
- sout_stream_id_t *id = malloc( sizeof( *id ) );
+ sout_stream_id_sys_t *id = malloc( sizeof( *id ) );
if( unlikely(id == NULL) )
return NULL;
id->p_stream = p_stream;
}
char *salt = var_GetNonEmptyString (p_stream, SOUT_CFG_PREFIX"salt");
- errno = srtp_setkeystring (id->srtp, key, salt ? salt : "");
+ int val = srtp_setkeystring (id->srtp, key, salt ? salt : "");
free (salt);
free (key);
- if (errno)
+ if (val)
{
- msg_Err (p_stream, "bad SRTP key/salt combination (%m)");
+ msg_Err (p_stream, "bad SRTP key/salt combination (%s)",
+ vlc_strerror_c(val));
goto error;
}
id->i_sequence = 0; /* FIXME: awful hack for libvlc_srtp */
case VLC_CODEC_S16L:
rtp_set_ptime (id, 20, 2);
break;
+ case VLC_CODEC_S24B:
+ rtp_set_ptime (id, 20, 3);
+ break;
default:
break;
}
return NULL;
}
-static int Del( sout_stream_t *p_stream, sout_stream_id_t *id )
+static int Del( sout_stream_t *p_stream, sout_stream_id_sys_t *id )
{
sout_stream_sys_t *p_sys = p_stream->p_sys;
return VLC_SUCCESS;
}
-static int Send( sout_stream_t *p_stream, sout_stream_id_t *id,
+static int Send( sout_stream_t *p_stream, sout_stream_id_sys_t *id,
block_t *p_buffer )
{
- block_t *p_next;
-
assert( p_stream->p_sys->p_mux == NULL );
(void)p_stream;
while( p_buffer != NULL )
{
- p_next = p_buffer->p_next;
+ block_t *p_next = p_buffer->p_next;
+ p_buffer->p_next = NULL;
/* Send a Vorbis/Theora Packed Configuration packet (RFC 5215 ยง3.1)
* as the first packet of the stream */
if( id->rtp_fmt.pf_packetize( id, p_buffer ) )
break;
- block_Release( p_buffer );
p_buffer = p_next;
}
return VLC_SUCCESS;
static int SapSetup( sout_stream_t *p_stream )
{
sout_stream_sys_t *p_sys = p_stream->p_sys;
- sout_instance_t *p_sout = p_stream->p_sout;
/* Remove the previous session */
if( p_sys->p_session != NULL)
{
- sout_AnnounceUnRegister( p_sout, p_sys->p_session);
+ sout_AnnounceUnRegister( p_stream, p_sys->p_session);
p_sys->p_session = NULL;
}
if( p_sys->i_es > 0 && p_sys->psz_sdp && *p_sys->psz_sdp )
- p_sys->p_session = sout_AnnounceRegisterSDP( p_sout,
+ p_sys->p_session = sout_AnnounceRegisterSDP( p_stream,
p_sys->psz_sdp,
p_sys->psz_destination );
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 );
+ msg_Err( p_stream, "cannot open file '%s' (%s)",
+ p_sys->psz_sdp_file, vlc_strerror_c(errno) );
return VLC_EGENERIC;
}
****************************************************************************/
static void* ThreadSend( void *data )
{
-#ifdef WIN32
-# define ECONNREFUSED WSAECONNREFUSED
-# define ENOPROTOOPT WSAENOPROTOOPT
-# define EHOSTUNREACH WSAEHOSTUNREACH
-# define ENETUNREACH WSAENETUNREACH
-# define ENETDOWN WSAENETDOWN
+#ifdef _WIN32
# define ENOBUFS WSAENOBUFS
# define EAGAIN WSAEWOULDBLOCK
# define EWOULDBLOCK WSAEWOULDBLOCK
#endif
- sout_stream_id_t *id = data;
+ sout_stream_id_sys_t *id = data;
unsigned i_caching = id->i_caching;
for (;;)
vlc_restorecancel (canc);
if( val )
{
- errno = val;
- msg_Dbg( id->p_stream, "SRTP sending error: %m" );
+ msg_Dbg( id->p_stream, "SRTP sending error: %s",
+ vlc_strerror_c(val) );
block_Release( out );
out = NULL;
}
/* This thread dequeues incoming connections (DCCP streaming) */
static void *rtp_listen_thread( void *data )
{
- sout_stream_id_t *id = data;
+ sout_stream_id_sys_t *id = data;
assert( id->listen.fd != NULL );
}
-int rtp_add_sink( sout_stream_id_t *id, int fd, bool rtcp_mux, uint16_t *seq )
+int rtp_add_sink( sout_stream_id_sys_t *id, int fd, bool rtcp_mux, uint16_t *seq )
{
rtp_sink_t sink = { fd, NULL };
sink.rtcp = OpenRTCP( VLC_OBJECT( id->p_stream ), fd, IPPROTO_UDP,
return VLC_SUCCESS;
}
-void rtp_del_sink( sout_stream_id_t *id, int fd )
+void rtp_del_sink( sout_stream_id_sys_t *id, int fd )
{
rtp_sink_t sink = { fd, NULL };
net_Close( sink.rtp_fd );
}
-uint16_t rtp_get_seq( sout_stream_id_t *id )
+uint16_t rtp_get_seq( sout_stream_id_sys_t *id )
{
/* This will return values for the next packet. */
uint16_t seq;
* Also return the NPT corresponding to this timestamp. If the stream
* output is not started, the initial timestamp that will be used with
* the first packets for NPT=0 is returned instead. */
-int64_t rtp_get_ts( const sout_stream_t *p_stream, const sout_stream_id_t *id,
+int64_t rtp_get_ts( const sout_stream_t *p_stream, const sout_stream_id_sys_t *id,
const vod_media_t *p_media, const char *psz_vod_session,
int64_t *p_npt )
{
return p_sys->i_pts_zero + npt;
}
-void rtp_packetize_common( sout_stream_id_t *id, block_t *out,
+void rtp_packetize_common( sout_stream_id_sys_t *id, block_t *out,
int b_marker, int64_t i_pts )
{
if( !id->b_ts_init )
memcpy( out->p_buffer + 8, id->ssrc, 4 );
- out->i_buffer = 12;
id->i_sequence++;
}
-void rtp_packetize_send( sout_stream_id_t *id, block_t *out )
+uint16_t rtp_get_extended_sequence( sout_stream_id_sys_t *id )
+{
+ return id->i_sequence >> 16;
+}
+
+void rtp_packetize_send( sout_stream_id_sys_t *id, block_t *out )
{
block_FifoPut( id->p_fifo, out );
}
* @return configured max RTP payload size (including payload type-specific
* headers, excluding RTP and transport headers)
*/
-size_t rtp_mtu (const sout_stream_id_t *id)
+size_t rtp_mtu (const sout_stream_id_sys_t *id)
{
return id->i_mtu - 12;
}
*****************************************************************************/
/** Add an ES to a non-RTP muxed stream */
-static sout_stream_id_t *MuxAdd( sout_stream_t *p_stream, es_format_t *p_fmt )
+static sout_stream_id_sys_t *MuxAdd( sout_stream_t *p_stream, es_format_t *p_fmt )
{
sout_input_t *p_input;
sout_mux_t *p_mux = p_stream->p_sys->p_mux;
return NULL;
}
- return (sout_stream_id_t *)p_input;
+ return (sout_stream_id_sys_t *)p_input;
}
-static int MuxSend( sout_stream_t *p_stream, sout_stream_id_t *id,
+static int MuxSend( sout_stream_t *p_stream, sout_stream_id_sys_t *id,
block_t *p_buffer )
{
sout_mux_t *p_mux = p_stream->p_sys->p_mux;
assert( p_mux != NULL );
- sout_MuxSendBuffer( p_mux, (sout_input_t *)id, p_buffer );
- return VLC_SUCCESS;
+ return sout_MuxSendBuffer( p_mux, (sout_input_t *)id, p_buffer );
}
/** Remove an ES from a non-RTP muxed stream */
-static int MuxDel( sout_stream_t *p_stream, sout_stream_id_t *id )
+static int MuxDel( sout_stream_t *p_stream, sout_stream_id_sys_t *id )
{
sout_mux_t *p_mux = p_stream->p_sys->p_mux;
assert( p_mux != NULL );
const block_t *p_buffer )
{
sout_stream_sys_t *p_sys = p_stream->p_sys;
- sout_stream_id_t *id = p_sys->es[0];
+ sout_stream_id_sys_t *id = p_sys->es[0];
int64_t i_dts = p_buffer->i_dts;
if( p_sys->packet == NULL )
{
/* allocate a new packet */
- p_sys->packet = block_New( p_stream, id->i_mtu );
+ p_sys->packet = block_Alloc( id->i_mtu );
rtp_packetize_common( id, p_sys->packet, 1, i_dts );
p_sys->packet->i_dts = i_dts;
p_sys->packet->i_length = p_buffer->i_length / i_packet;
p_grab->pf_write = AccessOutGrabberWrite;
return p_grab;
}
+
+void rtp_get_video_geometry( sout_stream_id_sys_t *id, int *width, int *height )
+{
+ int ret = sscanf( id->rtp_fmt.fmtp, "%*s width=%d; height=%d; ", width, height );
+ assert( ret == 2 );
+}