Changeset cd1ad0c30c82e11893b51a6493ff88e645844bae

Show
Ignore:
Timestamp:
09/08/07 12:08:33 (1 year ago)
Author:
Rémi Denis-Courmont <rem@videolan.org>
git-committer:
Rémi Denis-Courmont <rem@videolan.org> 1189246113 +0000
git-parent:

[eec78961e6d670e6c108aa3f45c8a7bba3764129]

git-author:
Rémi Denis-Courmont <rem@videolan.org> 1189246113 +0000
Message:

Remove dead RTCP code

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • modules/access_output/udp.c

    reec7896 rcd1ad0c  
    9696                          "helps reducing the scheduling load on " \ 
    9797                          "heavily-loaded systems." ) 
    98 #define RTCP_TEXT N_("RTCP Sender Report") 
    99 #define RTCP_LONGTEXT N_("Send RTCP Sender Report packets") 
    100 #define RTCP_PORT_TEXT N_("RTCP destination port number") 
    101 #define RTCP_PORT_LONGTEXT N_("Sends RTCP packets to this port (0 = auto)") 
    10298#define AUTO_MCAST_TEXT N_("Automatic multicast streaming") 
    10399#define AUTO_MCAST_LONGTEXT N_("Allocates an outbound multicast address " \ 
     
    118114    add_obsolete_integer( SOUT_CFG_PREFIX "late" ); 
    119115    add_obsolete_bool( SOUT_CFG_PREFIX "raw" ); 
    120     add_bool( SOUT_CFG_PREFIX "rtcp",  VLC_FALSE, NULL, RTCP_TEXT, RTCP_LONGTEXT, 
    121                                  VLC_TRUE ); 
    122     add_integer( SOUT_CFG_PREFIX "rtcp-port",  0, NULL, RTCP_PORT_TEXT, 
    123                  RTCP_PORT_LONGTEXT, VLC_TRUE ); 
    124116    add_bool( SOUT_CFG_PREFIX "auto-mcast", VLC_FALSE, NULL, AUTO_MCAST_TEXT, 
    125117              AUTO_MCAST_LONGTEXT, VLC_TRUE ); 
     
    140132    "caching", 
    141133    "group", 
    142     "rtcp", 
    143     "rtcp-port", 
    144134    "lite", 
    145135    "cscov", 
     
    163153static const char *MakeRandMulticast (int family, char *buf, size_t buflen); 
    164154 
    165 typedef struct rtcp_sender_t 
    166 { 
    167     size_t   length;  /* RTCP packet length */ 
    168     uint8_t  payload[28 + 8 + (2 * 257)]; 
    169     int      handle;  /* RTCP socket handler */ 
    170  
    171     uint32_t packets; /* RTP packets sent */ 
    172     uint32_t bytes;   /* RTP bytes sent */ 
    173     unsigned counter; /* RTP packets sent since last RTCP packet */ 
    174 } rtcp_sender_t; 
    175  
    176155typedef struct sout_access_thread_t 
    177156{ 
     
    188167 
    189168    block_fifo_t *p_empty_blocks; 
    190  
    191     rtcp_sender_t rtcp; 
    192169} sout_access_thread_t; 
    193170 
     
    206183#define RTP_HEADER_LENGTH 12 
    207184 
    208 static int OpenRTCP (vlc_object_t *obj, rtcp_sender_t *rtcp, int rtp_fd, 
    209                      int proto, uint16_t dport); 
    210 static void SendRTCP (rtcp_sender_t *obj, const block_t *rtp); 
    211 static void CloseRTCP (rtcp_sender_t *obj); 
    212  
    213185/***************************************************************************** 
    214186 * Open: open the file 
     
    220192 
    221193    char                *psz_dst_addr = NULL; 
    222     int                 i_dst_port, i_rtcp_port = 0, proto = IPPROTO_UDP; 
     194    int                 i_dst_port, proto = IPPROTO_UDP; 
    223195    const char          *protoname = "UDP"; 
    224196 
     
    271243            i_dst_port = atoi (psz_parser); 
    272244        } 
    273     } 
    274  
    275     if (var_GetBool (p_access, SOUT_CFG_PREFIX"rtcp")) 
    276     { 
    277         /* This is really only for the RTP sout plugin. 
    278          * Doing RTCP for non RTP packet is NOT a good idea. */ 
    279         i_rtcp_port = var_GetInteger (p_access, SOUT_CFG_PREFIX"rtcp-port"); 
    280         if (i_rtcp_port == 0) 
    281             i_rtcp_port = i_dst_port + 1; 
    282245    } 
    283246 
     
    365328    p_sys->p_buffer = NULL; 
    366329 
    367     if (i_rtcp_port && OpenRTCP (VLC_OBJECT (p_access), &p_sys->p_thread->rtcp, 
    368                                  i_handle, proto, i_rtcp_port)) 
    369     { 
    370         msg_Err (p_access, "cannot initialize RTCP sender"); 
    371         net_Close (i_handle); 
    372         vlc_object_destroy (p_sys->p_thread); 
    373         free (p_sys); 
    374         return VLC_EGENERIC; 
    375     } 
    376  
    377330    if( vlc_thread_create( p_sys->p_thread, "sout write thread", ThreadWrite, 
    378331                           VLC_THREAD_PRIORITY_HIGHEST, VLC_FALSE ) ) 
     
    421374 
    422375    net_Close( p_sys->p_thread->i_handle ); 
    423     CloseRTCP (&p_sys->p_thread->rtcp); 
    424376 
    425377    vlc_object_detach( p_sys->p_thread ); 
     
    640592#endif 
    641593 
    642         SendRTCP (&p_thread->rtcp, p_pk); 
    643  
    644594        block_FifoPut( p_thread->p_empty_blocks, p_pk ); 
    645595 
     
    682632 
    683633 
    684 /* 
    685  * NOTE on RTCP implementation: 
    686  * - there is a single sender (us), no conferencing here! => n = sender = 1, 
    687  * - as such we need not bother to include Receiver Reports, 
    688  * - in unicast case, there is a single receiver => members = 1 + 1 = 2, 
    689  *   and obviously n > 25% of members, 
    690  * - in multicast case, we do not want to maintain the number of receivers 
    691  *   and we assume it is big (i.e. than 3) because that's what broadcasting is 
    692  *   all about, 
    693  * - it is assumed we_sent = true (could be wrong), since we are THE sender, 
    694  * - we always send SR + SDES, while running, 
    695  * - FIXME: we do not implement separate rate limiting for SDES, 
    696  * - we do not implement any profile-specific extensions for the time being. 
    697  */ 
    698 static int OpenRTCP (vlc_object_t *obj, rtcp_sender_t *rtcp, int rtp_fd, 
    699                      int proto, uint16_t dport) 
    700 { 
    701     uint8_t *ptr; 
    702     int fd; 
    703  
    704     char src[NI_MAXNUMERICHOST], dst[NI_MAXNUMERICHOST]; 
    705     int sport; 
    706  
    707     rtcp->bytes = rtcp->packets = rtcp->counter = 0; 
    708  
    709     if (net_GetSockAddress (rtp_fd, src, &sport) 
    710      || net_GetPeerAddress (rtp_fd, dst, NULL)) 
    711         return VLC_EGENERIC; 
    712  
    713     sport++; 
    714     fd = net_OpenDgram (obj, src, sport, dst, dport, AF_UNSPEC, proto); 
    715     if (fd == -1) 
    716         return VLC_EGENERIC; 
    717  
    718     rtcp->handle = fd; 
    719  
    720     ptr = (uint8_t *)strchr (src, '%'); 
    721     if (ptr != NULL) 
    722         *ptr = '\0'; /* remove scope ID frop IPv6 addresses */ 
    723  
    724     ptr = rtcp->payload; 
    725  
    726     /* Sender report */ 
    727     ptr[0] = 2 << 6; /* V = 2, P = RC = 0 */ 
    728     ptr[1] = 200; /* payload type: Sender Report */ 
    729     SetWBE (ptr + 2, 6); /* length = 6 (7 double words) */ 
    730     memset (ptr + 4, 0, 4); /* SSRC unknown yet */ 
    731     SetQWBE (ptr + 8, NTPtime64 ()); 
    732     memset (ptr + 16, 0, 12); /* timestamp and counters */ 
    733     ptr += 28; 
    734  
    735     /* Source description */ 
    736     uint8_t *sdes = ptr; 
    737     ptr[0] = (2 << 6) | 1; /* V = 2, P = 0, SC = 1 */ 
    738     ptr[1] = 202; /* payload type: Source Description */ 
    739     uint8_t *lenptr = ptr + 2; 
    740     memset (ptr + 4, 0, 4); /* SSRC unknown yet */ 
    741     ptr += 8; 
    742  
    743     ptr[0] = 1; /* CNAME - mandatory */ 
    744     assert (NI_MAXNUMERICHOST <= 256); 
    745     ptr[1] = strlen (src); 
    746     memcpy (ptr + 2, src, ptr[1]); 
    747     ptr += ptr[1] + 2; 
    748  
    749     static const char tool[] = PACKAGE_STRING; 
    750     ptr[0] = 6; /* TOOL */ 
    751     ptr[1] = (sizeof (tool) > 256) ? 255 : (sizeof (tool) - 1); 
    752     memcpy (ptr + 2, tool, ptr[1]); 
    753     ptr += ptr[1] + 2; 
    754  
    755     while ((ptr - sdes) & 3) /* 32-bits padding */ 
    756         *ptr++ = 0; 
    757     SetWBE (lenptr, ptr - sdes); 
    758  
    759     rtcp->length = ptr - rtcp->payload; 
    760     return VLC_SUCCESS; 
    761 } 
    762  
    763 static void CloseRTCP (rtcp_sender_t *rtcp) 
    764 { 
    765     if (rtcp->handle == -1) 
    766         return; 
    767  
    768     uint8_t *ptr = rtcp->payload; 
    769     /* Bye */ 
    770     ptr[0] = (2 << 6) | 1; /* V = 2, P = 0, SC = 1 */ 
    771     ptr[1] = 203; /* payload type: Bye */ 
    772     SetWBE (ptr + 2, 1); 
    773     /* SSRC is already there :) */ 
    774  
    775     /* We are THE sender, so we are more important than anybody else, so 
    776      * we can afford not to check bandwidth constraints here. */ 
    777     send (rtcp->handle, rtcp->payload, 8, 0); 
    778     net_Close (rtcp->handle); 
    779 } 
    780  
    781 static void SendRTCP (rtcp_sender_t *rtcp, const block_t *rtp) 
    782 { 
    783     uint8_t *ptr = rtcp->payload; 
    784  
    785     if ((rtcp->handle == -1) /* RTCP sender off */ 
    786      || (rtp->i_buffer < 12)) /* too short RTP packet */ 
    787         return; 
    788  
    789     /* Updates statistics */ 
    790     rtcp->packets++; 
    791     rtcp->bytes += rtp->i_buffer; 
    792     rtcp->counter += rtp->i_buffer; 
    793  
    794     /* 1.25% rate limit */ 
    795     if ((rtcp->counter / 80) < rtcp->length) 
    796         return; 
    797  
    798     uint32_t last = GetDWBE (ptr + 8); // last RTCP SR send time 
    799     uint64_t now64 = NTPtime64 (); 
    800     if ((now64 >> 32) < (last + 5)) 
    801         return; // no more than one SR every 5 seconds 
    802  
    803     memcpy (ptr + 4, rtp->p_buffer + 8, 4); /* SR SSRC */ 
    804     SetQWBE (ptr + 8, now64); 
    805     memcpy (ptr + 16, rtp->p_buffer + 4, 4); /* RTP timestamp */ 
    806     SetDWBE (ptr + 20, rtcp->packets); 
    807     SetDWBE (ptr + 24, rtcp->bytes); 
    808     memcpy (ptr + 28 + 4, rtp->p_buffer + 8, 4); /* SDES SSRC */ 
    809  
    810     if (send (rtcp->handle, ptr, rtcp->length, 0) == (ssize_t)rtcp->length) 
    811         rtcp->counter = 0; 
    812 }