"directly, without trying to fill the MTU (ie, " \
"without trying to make the biggest possible packets " \
"in order to improve streaming)." )
+#define RTCP_TEXT N_("RTCP destination port number")
+#define RTCP_LONGTEXT N_("Sends RTCP packets to this port (0 = auto)")
#define AUTO_MCAST_TEXT N_("Automatic multicast streaming")
#define AUTO_MCAST_LONGTEXT N_("Allocates an outbound multicast address " \
"automatically.")
+#define UDPLITE_TEXT N_("UDP-Lite")
+#define UDPLITE_LONGTEXT N_("Use UDP-Lite/IP instead of normal UDP/IP")
+#define CSCOV_TEXT N_("Checksum coverage")
+#define CSCOV_LONGTEXT N_("Payload bytes covered by layer-4 checksum")
vlc_module_begin();
set_description( _("UDP stream output") );
add_integer( SOUT_CFG_PREFIX "group", 1, NULL, GROUP_TEXT, GROUP_LONGTEXT,
VLC_TRUE );
add_suppressed_integer( SOUT_CFG_PREFIX "late" );
- add_bool( SOUT_CFG_PREFIX "raw", 0, NULL, RAW_TEXT, RAW_LONGTEXT,
+ add_bool( SOUT_CFG_PREFIX "raw", VLC_FALSE, NULL, RAW_TEXT, RAW_LONGTEXT,
VLC_TRUE );
- add_bool( SOUT_CFG_PREFIX "auto-mcast", 0, NULL, AUTO_MCAST_TEXT,
+ add_integer( SOUT_CFG_PREFIX "rtcp", 0, NULL, RTCP_TEXT, RTCP_LONGTEXT,
+ VLC_TRUE );
+ add_bool( SOUT_CFG_PREFIX "auto-mcast", VLC_FALSE, NULL, AUTO_MCAST_TEXT,
AUTO_MCAST_LONGTEXT, VLC_TRUE );
+ add_bool( SOUT_CFG_PREFIX "udplite", VLC_FALSE, NULL, UDPLITE_TEXT, UDPLITE_LONGTEXT, VLC_TRUE );
+ add_integer( SOUT_CFG_PREFIX "cscov", 12, NULL, CSCOV_TEXT, CSCOV_LONGTEXT, VLC_TRUE );
set_capability( "sout access", 100 );
add_shortcut( "udp" );
add_shortcut( "rtp" ); // Will work only with ts muxer
- add_shortcut( "udplite" );
set_callbacks( Open, Close );
vlc_module_end();
"caching",
"group",
"raw",
+ "rtcp",
+ "lite",
+ "cscov",
NULL
};
{
int i_mtu;
- vlc_bool_t b_rtpts; // 1 if add rtp/ts header
+ vlc_bool_t b_rtpts; // true for RTP/MP2 encapsulation
vlc_bool_t b_mtu_warning;
uint16_t i_sequence_number;
uint32_t i_ssrc;
#define DEFAULT_PORT 1234
#define RTP_HEADER_LENGTH 12
-static int OpenRTCP (sout_access_out_t *obj);
+static int OpenRTCP (sout_access_out_t *obj, int proto, uint16_t dport);
static void SendRTCP (sout_access_thread_t *obj, uint32_t timestamp);
static void CloseRTCP (sout_access_thread_t *obj);
/*****************************************************************************
* Open: open the file
*****************************************************************************/
-/* FIXME: lots of leaks in error handling here! */
static int Open( vlc_object_t *p_this )
{
sout_access_out_t *p_access = (sout_access_out_t*)p_this;
sout_access_out_sys_t *p_sys;
char *psz_dst_addr = NULL;
- int i_dst_port, proto = IPPROTO_UDP, cscov = 8;
+ int i_dst_port, i_rtcp_port = 0, proto = IPPROTO_UDP;
const char *protoname = "UDP";
int i_handle;
config_ChainParse( p_access, "",
ppsz_core_options, p_access->p_cfg );
+ if (var_Create (p_access, "dst-port", VLC_VAR_INTEGER)
+ || var_Create (p_access, "src-port", VLC_VAR_INTEGER)
+ || var_Create (p_access, "dst-addr", VLC_VAR_STRING)
+ || var_Create (p_access, "src-addr", VLC_VAR_STRING))
+ {
+ return VLC_ENOMEM;
+ }
+
if( !( p_sys = calloc ( 1, sizeof( sout_access_out_sys_t ) ) ) )
{
msg_Err( p_access, "not enough memory" );
- return VLC_EGENERIC;
+ return VLC_ENOMEM;
}
p_access->p_sys = p_sys;
{
if (strcmp (p_access->psz_access, "rtp") == 0)
p_sys->b_rtpts = VLC_TRUE;
- if (strcmp (p_access->psz_access, "udplite") == 0)
- {
- protoname = "UDP-Lite";
- proto = IPPROTO_UDPLITE;
- p_sys->b_rtpts = VLC_TRUE;
- }
}
- if (p_sys->b_rtpts)
- cscov += RTP_HEADER_LENGTH;
+
+ if (var_GetBool (p_access, SOUT_CFG_PREFIX"lite"))
+ {
+ protoname = "UDP-Lite";
+ proto = IPPROTO_UDPLITE;
+ }
i_dst_port = DEFAULT_PORT;
- if (var_CreateGetBool (p_access, SOUT_CFG_PREFIX"auto-mcast"))
+ if (var_GetBool (p_access, SOUT_CFG_PREFIX"auto-mcast"))
{
char buf[INET6_ADDRSTRLEN];
if (MakeRandMulticast (AF_INET, buf, sizeof (buf)) != NULL)
}
}
- if (var_Create (p_access, "dst-port", VLC_VAR_INTEGER)
- || var_Create (p_access, "src-port", VLC_VAR_INTEGER)
- || var_Create (p_access, "dst-addr", VLC_VAR_STRING)
- || var_Create (p_access, "src-addr", VLC_VAR_STRING))
- {
- free (p_sys);
- free (psz_dst_addr);
- return VLC_ENOMEM;
- }
+ /* This option is really only meant for the RTP streaming output
+ * plugin. Doing RTCP for raw UDP will yield weird results. */
+ i_rtcp_port = var_GetInteger (p_access, SOUT_CFG_PREFIX"rtcp");
+ /* If RTCP port is not specified, use the default, if we do RTP/MP2 encap,
+ * or do not use RTCP at all otherwise. */
+ if ((i_rtcp_port == 0) && (p_sys->b_rtpts))
+ i_rtcp_port = i_dst_port + 1;
p_sys->p_thread =
vlc_object_create( p_access, sizeof( sout_access_thread_t ) );
}
}
p_sys->p_thread->i_handle = i_handle;
- net_StopRecv( i_handle );
+ shutdown( i_handle, SHUT_RD );
+ int cscov = var_GetInteger (p_access, SOUT_CFG_PREFIX"cscov");
+ if (cscov)
+ {
+ switch (proto)
+ {
#ifdef UDPLITE_SEND_CSCOV
- if (proto == IPPROTO_UDPLITE)
- setsockopt (i_handle, SOL_UDPLITE, UDPLITE_SEND_CSCOV,
- &cscov, sizeof (cscov));
+ case IPPROTO_UDPLITE:
+ cscov += 8;
+ setsockopt (i_handle, SOL_UDPLITE, UDPLITE_SEND_CSCOV,
+ &(int){ cscov }, sizeof (cscov));
+ break;
#endif
+#ifdef DCCP_SOCKOPT_RECV_CSCOV
+ /* FIXME: ^^is this the right name ? */
+ /* FIXME: is this inherited by accept() ? */
+ case IPPROTO_DCCP:
+ cscov = ((cscov + 3) >> 2) + 1;
+ if (cscov > 15)
+ break; /* out of DCCP cscov range */
+ setsockopt (i_handle, SOL_DCCP, DCCP_SOCKOPT_RECV_CSCOV,
+ &(int){ cscov }, sizeof (cscov));
+ break;
+#endif
+ }
+ }
var_Get( p_access, SOUT_CFG_PREFIX "caching", &val );
p_sys->p_thread->i_caching = (int64_t)val.i_int * 1000;
p_sys->i_sequence_number = rand()&0xffff;
p_sys->i_ssrc = rand()&0xffffffff;
- if (p_sys->b_rtpts && OpenRTCP (p_access))
+ if (i_rtcp_port && OpenRTCP (p_access, proto, i_rtcp_port))
{
msg_Err (p_access, "cannot initialize RTCP sender");
net_Close (i_handle);
/* add rtp/ts header */
p_buffer->p_buffer[0] = 0x80;
- p_buffer->p_buffer[1] = 0x21; // mpeg2-ts
+ p_buffer->p_buffer[1] = 33; // mpeg2-ts
SetWBE( p_buffer->p_buffer + 2, p_sys->i_sequence_number );
p_sys->i_sequence_number++;
}
#endif
- if (p_thread->rtcp_handle != -1)
+ if ((p_thread->rtcp_handle != -1) && (p_pk->i_buffer >= 8))
{
/* FIXME: this is a very incorrect simplistic RTCP timer */
if ((rtcp_counter / 80) >= p_thread->rtcp_size)
{
- SendRTCP (p_thread, p_pk->i_dts * 9 / 100);
+ SendRTCP (p_thread, GetDWBE (p_pk->p_buffer + 4));
rtcp_counter = 0;
}
}
* - it is assumed we_sent = true (could be wrong), since we are THE sender,
* - we always send SR + SDES, while running,
* - FIXME: we do not implement separate rate limiting for SDES,
- * - FIXME: we should send BYE when stopping,
* - we do not implement any profile-specific extensions for the time being.
*/
-static int OpenRTCP (sout_access_out_t *obj)
+static int OpenRTCP (sout_access_out_t *obj, int proto, uint16_t dport)
{
sout_access_out_sys_t *p_sys = obj->p_sys;
uint8_t *ptr;
int fd;
char src[NI_MAXNUMERICHOST], dst[NI_MAXNUMERICHOST];
- int sport, dport;
+ int sport;
fd = obj->p_sys->p_thread->i_handle;
if (net_GetSockAddress (fd, src, &sport)
- || net_GetPeerAddress (fd, dst, &dport))
+ || net_GetPeerAddress (fd, dst, NULL))
return VLC_EGENERIC;
sport++;
- dport++;
- /* FIXME: should we use UDP for non-UDP protos? */
- fd = net_OpenDgram (obj, src, sport, dst, dport, AF_UNSPEC, IPPROTO_UDP);
+ fd = net_OpenDgram (obj, src, sport, dst, dport, AF_UNSPEC, proto);
if (fd == -1)
return VLC_EGENERIC;
static void CloseRTCP (sout_access_thread_t *obj)
{
- /* TODO: send RTCP BYE */
- if (obj->rtcp_handle != -1)
- net_Close (obj->rtcp_handle);
+ if (obj->rtcp_handle == -1)
+ return;
+
+ uint8_t *ptr = obj->rtcp_data;
+ /* Bye */
+ ptr[0] = (2 << 6) | 1; /* V = 2, P = 0, SC = 1 */
+ ptr[1] = 203; /* payload type: Bye */
+ SetWBE (ptr + 2, 1);
+ /* SSRC is already there :) */
+
+ /* We are THE sender, so we are more important than anybody else, so
+ * we can afford not to check bandwidth constraints here. */
+ send (obj->rtcp_handle, obj->rtcp_data, 8, 0);
+ net_Close (obj->rtcp_handle);
}
static void SendRTCP (sout_access_thread_t *obj, uint32_t timestamp)