X-Git-Url: https://git.sesse.net/?a=blobdiff_plain;f=modules%2Faccess_output%2Fudp.c;h=94d98b570fd9573086d14f463f4040fc6c4b65a3;hb=7e784b4dbac0381217f11a58519346a043a582d1;hp=660e7bbf9538f0b392a759595aa02dcf78359595;hpb=cdf34ed9ffedd4cd2e0c0f529a08b9bcca94c34d;p=vlc diff --git a/modules/access_output/udp.c b/modules/access_output/udp.c index 660e7bbf95..94d98b570f 100644 --- a/modules/access_output/udp.c +++ b/modules/access_output/udp.c @@ -102,9 +102,15 @@ static void Close( vlc_object_t * ); "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") ); @@ -115,15 +121,18 @@ vlc_module_begin(); 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(); @@ -136,6 +145,9 @@ static const char *ppsz_sout_options[] = { "caching", "group", "raw", + "rtcp", + "lite", + "cscov", NULL }; @@ -183,7 +195,7 @@ struct sout_access_out_sys_t { 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; @@ -197,21 +209,20 @@ struct sout_access_out_sys_t #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; @@ -223,10 +234,18 @@ static int Open( vlc_object_t *p_this ) 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; @@ -234,18 +253,16 @@ static int Open( vlc_object_t *p_this ) { 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) @@ -266,15 +283,13 @@ static int Open( vlc_object_t *p_this ) } } - 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 ) ); @@ -323,13 +338,33 @@ static int Open( vlc_object_t *p_this ) } } 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; @@ -344,7 +379,7 @@ static int Open( vlc_object_t *p_this ) 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); @@ -564,7 +599,7 @@ static block_t *NewUDPPacket( sout_access_out_t *p_access, mtime_t i_dts) /* 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++; @@ -667,12 +702,12 @@ static void ThreadWrite( vlc_object_t *p_this ) } #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; } } @@ -729,27 +764,24 @@ static const char *MakeRandMulticast (int family, char *buf, size_t buflen) * - 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; @@ -799,9 +831,20 @@ static int OpenRTCP (sout_access_out_t *obj) 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)