98#define max(a, b) (((a) > (b))? (a): (b))
99#define min(a, b) (((a) < (b))? (a): (b))
102#define IPPORT_DYNAMIC ((1U<<15U) + (1U<<14U))
103#define IPPORT_MAX ((1U<<16U) - 1U)
104#define MOD_NAME "[rtp] "
109#define MAX_ENCRYPTION_PAD 16
113 unsigned int size,
unsigned char *initVec);
115 unsigned int size,
unsigned char *initVec);
117static bool des_initialize(
struct rtp *session,
const u_char *hash,
int hash_len);
119 unsigned int size,
unsigned char *initVec);
121 unsigned int size,
unsigned char *initVec);
123 uint8_t *buffer,
rtp_packet *packet,
int buflen);
125#define MAX_DROPOUT 3000
126#define MAX_MISORDER 100
127#define MIN_SEQUENTIAL 2
133#define RTP_SEQ_MOD 0x10000
134#define RTP_MAX_SDES_LEN 256
136#define RTP_LOWER_LAYER_OVERHEAD 28
146#ifdef WORDS_BIGENDIAN
147 unsigned short version:2;
149 unsigned short count:5;
247#define RTP_DB_SIZE 11
266 unsigned int size,
unsigned char *initvec);
268 unsigned int size,
unsigned char *initvec);
347 for (
int chain = 0; chain <
RTP_DB_SIZE; chain++) {
350 for (
source *s = session->
db[chain]; s != NULL; s = s->
next) {
351 if (!s->should_advertise_sdes)
401 while (cur !=
start) {
428 debug_msg(
"Created new rr entry for 0x%08" PRIx32
" from source 0x%08" PRIx32
"\n",
429 rr->
ssrc, reporter_ssrc);
443 while (cur !=
start) {
460 while (cur !=
start) {
461 if (cur->
rr->
ssrc == ssrc) {
486 while (cur !=
start) {
487 if (curr_ts - cur->
ts >
494 event.data = cur->
rr;
513 uint32_t reportee_ssrc)
520 while (cur !=
start) {
522 cur->
rr->
ssrc == reportee_ssrc) {
534 assert(s->
magic == 0xc001feed);
545#if defined DEBUG && ! defined SUPPRESS_BUGS
550 assert(session != NULL);
551 assert(session->
magic == 0xfeedface);
570 for (s = session->
db[chain]; s != NULL; s = s->
next) {
573 if (s->
prev == NULL) {
574 assert(s == session->
db[chain]);
578 if (s->
next != NULL) {
602 if (s->
ssrc == ssrc) {
611 int probation,
source * s)
623 memset(s, 0,
sizeof(
source));
624 s->
magic = 0xc001feed;
637 if (session->
db[h] != NULL) {
644 debug_msg(
"Created database entry 0x%08x (%d sources)\n", ssrc,
646 if (ssrc != session->
my_ssrc) {
685 if (session->
db[h] == s) {
688 if (s->
next != NULL) {
692 assert(s->
prev != NULL);
694 if (s->
next != NULL) {
840 double const RTCP_MIN_TIME = 5.0;
847 double const RTCP_SENDER_BW_FRACTION = 0.25;
848 double const RTCP_RCVR_BW_FRACTION = (1 - RTCP_SENDER_BW_FRACTION);
851 double const COMPENSATION = 2.71828 - 1.5;
854 double rtcp_min_time = RTCP_MIN_TIME;
856 double rtcp_bw = session->
rtcp_bw;
876 && session->
sender_count < n * RTCP_SENDER_BW_FRACTION) {
878 rtcp_bw *= RTCP_SENDER_BW_FRACTION;
881 rtcp_bw *= RTCP_RCVR_BW_FRACTION;
894 if (t < rtcp_min_time) {
902 return (t * (
ug_drand() + 0.5)) / COMPENSATION;
905#define MAXCNAMELEN 255
914 struct passwd *pwent;
927 GetUserName(NULL, &namelen);
929 name = (
char *)malloc(namelen + 1);
930 GetUserName(
name, &namelen);
932 uname = getenv(
"USER");
934 name = strdup(uname);
944 pwent = getpwuid(getuid());
946 uname = pwent->pw_name;
959 hname = strdup(
"127.0.0.1");
961 strncpy(cname + strlen(cname), hname,
MAXCNAMELEN - strlen(cname));
1000 uint16_t rx_port, uint16_t tx_port,
1003 int force_ip_version,
bool multithreaded)
1035 uint16_t rx_port, uint16_t tx_port,
1038 int force_ip_version,
bool multithreaded)
1040 struct rtp *session;
1046 if (multithreaded) {
1047 log_msg(
LOG_LEVEL_WARNING,
"Multithreaded RTP is not recommended for MSW due to internal locking within Winsock implementation.\n");
1051 if (force_ip_version != 0 && force_ip_version != 4 && force_ip_version != 6) {
1055 if (ttl < -1 || ttl > 255) {
1066 session = (
struct rtp *)malloc(
sizeof(
struct rtp));
1067 memset(session, 0,
sizeof(
struct rtp));
1069 session->
magic = 0xfeedface;
1072 session->
mt_recv = multithreaded;
1091 verbose_msg(
"Found empty UDP port pair %d/%d\n", rx_port, rx_port + 1);
1094 MSG(VERBOSE,
"Bound to ports %d/%d\n", rx_port, rx_port + 1);
1099 session->
rtp_socket =
udp_init_if(addr, iface, rx_port, tx_port, ttl, force_ip_version, multithreaded);
1102 udp_init_if(addr, iface, (uint16_t) (rx_port + (rx_port ? 1 : 0)),
1103 (uint16_t) (tx_port + (tx_port ? 1 : 0)), ttl, force_ip_version,
false);
1108 printf(
"Unable to open network\n");
1135 session->
mhdr = NULL;
1150 session->
db[i] = NULL;
1157 session->
rr[i][j].
next = &session->
rr[i][j];
1158 session->
rr[i][j].
prev = &session->
rr[i][j];
1177 struct rtp *session;
1184 session = (
struct rtp *)malloc(
sizeof(
struct rtp));
1185 memset(session, 0,
sizeof(
struct rtp));
1187 session->
magic = 0xfeedface;
1200 printf(
"Unable to open network\n");
1221 session->
rtcp_bw = 5 * 1024 * 1024;
1227 session->
mhdr = NULL;
1242 session->
db[i] = NULL;
1249 session->
rr[i][j].
next = &session->
rr[i][j];
1250 session->
rr[i][j].
prev = &session->
rr[i][j];
1289 session->
db[h] = NULL;
1334 (
"Ignoring unknown option (%d) in call to rtp_set_option().\n",
1370 (
"Ignoring unknown option (%d) in call to rtp_get_option().\n",
1411 if (packet->pt >= 72 && packet->pt <= 76) {
1412 debug_msg(
"rtp_header_validation: payload-type invalid");
1414 debug_msg(
" (RTCP packet on RTP port?)");
1420 if (
len < (vlen + (4 * packet->cc))) {
1422 (
"rtp_header_validation: packet length is smaller than the header\n");
1428 int payload_len =
len - vlen - (packet->cc * 4);
1431 payload_len -= 4 * (1 + packet->extn_len);
1433 if (packet->data[packet->data_len - 1] > payload_len) {
1435 (
"rtp_header_validation: padding greater than payload length\n");
1438 if (packet->data[packet->data_len - 1] < 1) {
1439 debug_msg(
"rtp_header_validation: padding zero\n");
1454 if (packet->v != 2) {
1455 debug_msg(
"rtp_header_validation: v != 2\n");
1480 if (packet->cc > 0) {
1481 for (i = 0; i < packet->cc; i++) {
1494 transit = curr_rtp_ts - packet->ts;
1504 event.ssrc = packet->ssrc;
1508 event.data = (
void *)packet;
1509 session->
callback(session, &event);
1527 uint8_t *buffer = NULL;
1537 struct sockaddr_storage *sin = NULL;
1538 socklen_t addrlen = 0;
1541 addrlen =
sizeof(
struct sockaddr_storage);
1546 (
struct sockaddr *) sin, sin ? &addrlen : 0);
1560 uint8_t *buffer,
rtp_packet *packet,
int buflen)
1568 uint8_t initVec[8] = { 0, 0, 0, 0, 0, 0, 0, 0 };
1575 struct sockaddr *sa = (
struct sockaddr *)(
void *)((
char *) packet +
RTP_MAX_PACKET_LEN);
1577 udp_set_receiver(session->
rtp_socket, sa, sa->sa_family == AF_INET ?
sizeof(
struct sockaddr_in) :
sizeof(
struct sockaddr_in6));
1585 packet->send_ts = ntohl(packet->send_ts);
1587 if (packet->pt & 64) {
1590 packet->rtt = ntohl(packet->rtt);
1594 uint8_t *buffer_vlen = buffer + vlen;
1597 packet->seq = ntohs(packet->seq);
1598 packet->ts = ntohl(packet->ts);
1599 packet->ssrc = ntohl(packet->ssrc);
1603 packet->csrc = (uint32_t *)(
void *) (buffer_vlen);
1604 for (i = 0; i < packet->cc; i++) {
1605 packet->csrc[i] = ntohl(packet->csrc[i]);
1608 packet->csrc = NULL;
1611 packet->extn = buffer_vlen + (packet->cc * 4);
1613 (packet->extn[2] << 8) | packet->extn[3];
1615 (packet->extn[0] << 8) | packet->extn[1];
1617 packet->extn = NULL;
1618 packet->extn_len = 0;
1619 packet->extn_type = 0;
1621 packet->data = (
char *)(buffer_vlen + (packet->cc * 4));
1622 packet->data_len = buflen - (packet->cc * 4) - vlen;
1623 if (packet->extn != NULL) {
1624 packet->data += ((packet->extn_len + 1) * 4);
1625 packet->data_len -= ((packet->extn_len + 1) * 4);
1656 debug_msg(
"RTP packet from probationary source ignored...\n");
1662 debug_msg(
"Invalid RTP packet discarded\n");
1695 debug_msg(
"Bogus RTCP packet: not a compound packet\n");
1702 (
"Bogus RTCP packet: length exceeds length of container UDP packet\n");
1710 (
"Bogus RTCP packet: version number != 2 in the first sub-packet\n");
1715 (
"Bogus RTCP packet: padding bit is set on first packet in compound\n");
1721 (
"Bogus RTCP packet: compound packet starts with SDES not SR or RR\n");
1724 (
"Bogus RTCP packet: compound packet starts with APP not SR or RR\n");
1727 (
"Bogus RTCP packet: compound packet starts with BYE not SR or RR\n");
1730 (
"Bogus RTCP packet: compound packet starts with packet type %d not SR or RR\n",
1742 (
"Bogus RTCP packet: padding bit set in sub-packet %d which is not final sub-packet\n",
1751 (
"Bogus RTCP packet: version number != 2 in sub-packet %d\n",
1760 (
"Bogus RTCP packet: SR packet is too short (length=%d)\n",
1768 (
"Bogus RTCP packet: RR packet is too short (length=%d)\n",
1775 struct rtcp_sdes_t *sd = &pkt->
r.
sdes;
1782 while (--
count >= 0) {
1784 if ((
char *)rsp > (
char *)end) {
1786 (
"Bogus RTCP packet: SDES longer than UDP packet: no terminating null item?\n");
1790 if (rsp >= sdes_end) {
1792 (
"Bogus RTCP packet: too many SDES items for packet length\n");
1796 for (; rsp->
type; rsp = rspn) {
1801 if (rspn == sdes_end) {
1805 sd = (
struct rtcp_sdes_t *)((uint32_t *) sd +
1812 (
"Bogus RTCP packet: malformed SDES packet\n");
1820 r = (
rtcp_t *) (((uint32_t *) r) + ntohs(r->common.length) + 1);
1828 (
"Bogus RTCP packet: RTCP packet length does not match UDP packet length (%d != %d)\n",
1834 (
"Bogus RTCP packet: RTCP packet length does not match UDP packet length (%p != %p)\n",
1860 session->
callback(session, &event);
1863 for (i = 0; i < packet->
common.
count; i++, rrp++) {
1870 rr->
lsr = ntohl(rrp->
lsr);
1875 rx->
ts = ntohl(rrx->
ts);
1878 rx->
p = ntohl(rrx->
p);
1888 event.data = (
void *)rr;
1889 session->
callback(session, &event);
1905 ssrc = ntohl(packet->
r.
sr.sr.
ssrc);
1908 debug_msg(
"Source 0x%08x invalid, skipping...\n", ssrc);
1921 sr->ntp_sec = ntohl(packet->
r.
sr.sr.
ntp_sec);
1923 sr->rtp_ts = ntohl(packet->
r.
sr.sr.
rtp_ts);
1928 sr = atomic_exchange(&s->
sr, sr);
1936 event.data = (
void *)s->
sr;
1937 session->
callback(session, &event);
1944 debug_msg(
"Profile specific SR extension ignored\n");
1953 ssrc = ntohl(packet->
r.
rr.
ssrc);
1956 debug_msg(
"Source 0x%08x invalid, skipping...\n", ssrc);
1963 debug_msg(
"Profile specific RR extension ignored\n");
1972 ssrc = ntohl(packet->
r.
rx.ssrc);
1975 debug_msg(
"Source 0x%08x invalid, skipping...\n", ssrc);
1983 debug_msg(
"Profile specific RR/RX extension ignored\n");
1990 struct rtcp_sdes_t *sd = &packet->
r.
sdes;
1999 while (--
count >= 0) {
2004 sd->ssrc = ntohl(sd->ssrc);
2008 (
"Can't get valid source entry for 0x%08x, skipping...\n",
2011 for (; rsp->
type; rsp = rspn) {
2020 (session, sd->ssrc, rsp->
type, rsp->
data,
2023 event.ssrc = sd->ssrc;
2025 event.data = (
void *)rsp;
2031 (
"Invalid sdes item for source 0x%08x, skipping...\n",
2036 sd = (
struct rtcp_sdes_t *)((uint32_t *) sd +
2037 (((
char *)rsp - (
char *)sd) >> 2) +
2041 debug_msg(
"Invalid RTCP SDES packet, some items ignored.\n");
2053 ssrc = ntohl(packet->
r.
bye.
ssrc[i]);
2063 session->
callback(session, &event);
2088 debug_msg(
"Source 0x%08x invalid, skipping...\n", ssrc);
2105 data_len = (
app->length - 2) * 4;
2112 event.data = (
void *)
app;
2113 session->
callback(session, &event);
2132 uint8_t initVec[8] = { 0, 0, 0, 0, 0, 0, 0, 0 };
2146 packet = (
rtcp_t *)(
void *) buffer;
2147 while (packet < (
rtcp_t *)(
void *) (buffer + buflen)) {
2157 event.data = &buflen;
2158 packet_ssrc =
event.ssrc;
2172 event.data = &buflen;
2173 packet_ssrc =
event.ssrc;
2185 ntohl(packet->
r.
rx.ssrc);
2187 event.data = &buflen;
2188 packet_ssrc =
event.ssrc;
2196 (
"RTCP_RX received without congestion control?");
2205 ntohl(packet->
r.
sdes.ssrc);
2207 event.data = &buflen;
2208 packet_ssrc =
event.ssrc;
2221 ntohl(packet->
r.
bye.
2224 event.data = &buflen;
2225 packet_ssrc =
event.ssrc;
2239 event.data = &buflen;
2247 (
"RTCP packet with unknown type (%d) ignored.\n",
2252 (
rtcp_t *)(
void *) ((
char *)packet +
2273 event.ssrc = packet_ssrc;
2276 session->
callback(session, &event);
2279 debug_msg(
"Invalid RTCP packet discarded\n");
2297bool rtp_recv(
struct rtp *session,
struct timeval *timeout, uint32_t curr_rtp_ts)
2338bool rtp_recv_r(
struct rtp *session,
struct timeval *timeout, uint32_t curr_rtp_ts)
2351 struct timeval no_wait_tv = { .tv_sec = 0, .tv_usec = 0 };
2436 struct rtp **current;
2441 for(current = sessions; *current != NULL; ++current) {
2447 int received_bytes = 0;
2448 for(current = sessions; *current != NULL; ++current) {
2456 udp_recv((*current)->rtcp_socket, (
char *)buffer,
2462 return received_bytes;
2488 debug_msg(
"Created source 0x%08x as CSRC\n", csrc);
2494 debug_msg(
"Added CSRC 0x%08" PRIx32
" as CSRC %d\n", csrc,
2517 debug_msg(
"Invalid source 0x%08x\n", csrc);
2547 const char *value,
int length)
2556 debug_msg(
"Invalid source 0x%08x\n", ssrc);
2561 v = (
char *)malloc(length + 1);
2562 memset(v,
'\0', length + 1);
2563 memcpy(v, value, length);
2607 debug_msg(
"Unknown SDES item (type=%d, value=%s)\n",
type, v);
2640 debug_msg(
"Invalid source 0x%08x\n", ssrc);
2711 return get_rr(session, reporter, reportee);
2743 int cc,
const uint32_t *csrc,
2744 char *data,
int data_len,
2745 char *extn, uint16_t extn_len, uint16_t extn_type)
2748 data, data_len, extn, extn_len, extn_type);
2753 uint32_t rtp_ts,
char pt,
int m,
2754 int cc,
const uint32_t *csrc,
2755 char *phdr,
int phdr_len,
2756 char *data,
int data_len,
2757 char *extn, uint16_t extn_len, uint16_t extn_type)
2759 int vlen, buffer_len, i, rc, pad, pad_len
__attribute__((unused));
2760 uint8_t *buffer = NULL;
2762 uint8_t initVec[8] = { 0, 0, 0, 0, 0, 0, 0, 0 };
2764 WSABUF *send_vector = NULL;
2766 struct iovec send_vector[3];
2768 int send_vector_len;
2774 assert((data == NULL && data_len == 0)
2775 || (data != NULL && data_len > 0));
2783 buffer_len = vlen + (4 * cc);
2786 buffer_len += (extn_len + 1) * 4;
2802 buffer_len += pad_len;
2818 buffer = (uint8_t *) d + 3 *
sizeof(WSABUF);
2826 send_vector[0].len = buffer_len;
2829 send_vector[0].iov_len = buffer_len;
2831 send_vector_len = 1;
2841 packet->data += (extn_len + 1) * 4;
2847 packet->x = (extn != NULL);
2851 packet->seq = htons(session->
rtp_seq++);
2852 packet->ts = htonl(rtp_ts);
2853 packet->ssrc = htonl(session->
my_ssrc);
2859 packet->rtt = htonl(session->
cmp_rtt);
2861 packet->pt = packet->pt | 64;
2863 packet->pt = packet->pt & 63;
2867 for (i = 0; i < cc; i++) {
2868 packet->csrc[i] = htonl(csrc[i]);
2873 uint16_t *base = (uint16_t *)(
void *) packet->extn;
2874 base[0] = htons(extn_type);
2875 base[1] = htons(extn_len);
2876 memcpy(packet->extn + 4, extn, extn_len * 4);
2881 send_vector[send_vector_len].buf = phdr;
2882 send_vector[send_vector_len].len = phdr_len;
2884 send_vector[send_vector_len].iov_base = phdr;
2885 send_vector[send_vector_len].iov_len = phdr_len;
2892 send_vector[send_vector_len].buf = (
void *) data;
2893 send_vector[send_vector_len].len = data_len;
2895 send_vector[send_vector_len].iov_base = (
void *) data;
2896 send_vector[send_vector_len].iov_len = data_len;
2903 for (i = 0; i < pad_len; i++) {
2916 buffer_len, initVec);
2936 struct rtp *session)
2945 for (s = session->
db[h]; s != NULL; s = s->
next) {
2947 if ((nblocks == 31) || (remaining_length < 24)) {
2953 int expected = extended_max - s->
base_seq + 1;
2955 int expected_interval =
2957 int received_interval =
2960 expected_interval - received_interval;
2968 if (expected_interval == 0
2969 || lost_interval <= 0) {
2973 (lost_interval << 8) /
2977 if (s->
sr == NULL) {
2994 rrp->
last_seq = htonl(extended_max);
2996 rrp->
lsr = htonl(lsr);
2997 rrp->
dlsr = htonl(dlsr);
2999 remaining_length -= 24;
3013 struct rtp *session, uint32_t rtp_ts)
3018 int remaining_length;
3019 uint32_t ntp_sec, ntp_frac;
3021 assert(buflen >= 28);
3040 remaining_length = buflen - 28;
3044 htons((uint16_t) (6 + (packet->
common.
count * 6)));
3049 struct rtp *session)
3054 int remaining_length;
3056 assert(buflen >= 8);
3067 remaining_length = buflen - 8;
3071 htons((uint16_t) (1 + (packet->
common.
count * 6)));
3083 debug_msg(
"Cannot format SDES item. type=%d val=%p\n",
type,
3088 namelen = strlen(
val);
3090 strncpy(shdr->
data,
val, buflen - 2);
3095 struct rtp *session)
3107 uint8_t *packet = buffer;
3110 size_t remaining_len;
3122 *((uint32_t *)(
void *) packet) = htonl(ssrc);
3125 remaining_len = buflen - (packet - buffer);
3127 if ((
item != NULL) && ((strlen(
item) + (
size_t) 2) <= remaining_len)) {
3132 remaining_len = buflen - (packet - buffer);
3134 if ((
item != NULL) && ((strlen(
item) + (
size_t) 2) <= remaining_len)) {
3139 remaining_len = buflen - (packet - buffer);
3151 && ((strlen(
item) + (
size_t) 2) <=
3164 && ((strlen(
item) + (
size_t) 2) <=
3178 && ((strlen(
item) + (
size_t) 2) <=
3191 && ((strlen(
item) + (
size_t) 2) <=
3203 && ((strlen(
item) + (
size_t) 2) <=
3224 pad = 4 - ((packet - buffer) & 0x3);
3229 common->
length = htons((uint16_t) (((
int)(packet - buffer) / 4) - 1));
3239 int pkt_octets = (
app->length + 1) * 4;
3240 int data_octets = pkt_octets - 12;
3242 assert(data_octets >= 0);
3243 assert(buflen >= pkt_octets);
3251 packet->
ssrc = htonl(ssrc);
3252 memcpy(packet->
name,
app->name, 4);
3253 memcpy(packet->
data,
app->data, data_octets);
3256 return buffer + pkt_octets;
3277 "sending RTCP packet: %s\n",
3291 uint8_t *ptr = buffer;
3295 uint8_t initVec[8] = { 0, 0, 0, 0, 0, 0, 0, 0 };
3300 *((uint32_t *)(
void *) ptr) =
ug_rand();
3348 (*appcallback) (session, rtp_ts,
3355 assert(ptr > old_ptr);
3372 for (i = 0; i < padlen - 1; i++) {
3375 *(ptr++) = (uint8_t) padlen;
3381 ((
rtcp_t *)(
void *) lpt)->common.length =
3382 htons((int16_t) (((ptr - lpt) / 4) - 1));
3384 (session->
encrypt_func) (session, buffer, ptr - buffer,
3420 double new_interval =
3423 if (curr_time > new_send_time) {
3424 send_rtcp(session, rtp_ts, appcallback);
3433 for (s = session->
db[h]; s != NULL; s = s->
next) {
3477 for (s = session->
db[h]; s != NULL; s = n) {
3493 (
"Deleting source 0x%08" PRIx32
" due to reception of BYE %f seconds ago...\n",
3513 (
"Deleting source 0x%08" PRIx32
" due to timeout...\n",
3531 uint8_t *ptr = buffer;
3533 uint8_t initVec[8] = { 0, 0, 0, 0, 0, 0, 0, 0 };
3538 *((uint32_t *)(
void *) ptr) =
ug_rand();
3549 common->
length = htons(1);
3552 *((uint32_t *)(
void *) ptr) = htonl(session->
my_ssrc);
3565 for (i = 0; i < padlen - 1; i++) {
3568 *(ptr++) = (uint8_t) padlen;
3573 (((ptr - (uint8_t *) common) / 4) - 1));
3576 (session->
encrypt_func) (session, buffer, ptr - buffer,
3602 double new_interval;
3629 debug_msg(
"Preparing to send BYE...\n");
3636 struct timeval timeout = { .tv_sec = d.quot, .tv_usec = d.rem };
3653 if (curr_time > new_send_time) {
3660 debug_msg(
"Reconsidered sending BYE... delay = %f\n",
3744 char *canonical_passphrase;
3755 if (passphrase == NULL) {
3762 debug_msg(
"Enabling RTP/RTCP encryption\n");
3769 slash = strchr(passphrase,
'/');
3773 int l = slash - passphrase;
3777 passphrase = slash + 1;
3780 debug_msg(
"Initializing encryption, algorithm is '%s'\n",
3794 canonical_passphrase = strdup(passphrase);
3798 MD5Update(&context, (u_char *) canonical_passphrase,
3799 strlen(canonical_passphrase));
3800 MD5Final((u_char *) hash, &context);
3801 free(canonical_passphrase);
3810 debug_msg(
"Encryption algorithm \"%s\" not found\n",
3832 key[1] = hash[0] << 7 | hash[1] >> 1;
3833 key[2] = hash[1] << 6 | hash[2] >> 2;
3834 key[3] = hash[2] << 5 | hash[3] >> 3;
3835 key[4] = hash[3] << 4 | hash[4] >> 4;
3836 key[5] = hash[4] << 3 | hash[5] >> 5;
3837 key[6] = hash[5] << 2 | hash[6] >> 6;
3838 key[7] = hash[6] << 1;
3841 for (
int i = 0; i < 8; ++i) {
3842 int k =
key[i] & 0xfe;
3856 unsigned int size,
unsigned char *initVec)
3859 data, size, initVec);
3864 unsigned int size,
unsigned char *initVec)
3867 data, size, initVec);
3894 debug_msg(
"cipherInst failed: %d\n", rc);
3901 unsigned int size,
unsigned char *initVec)
3913 data, size * 8, data);
3918 unsigned int size,
unsigned char *initVec)
3929 data, size * 8, data);
3980 for (s = session->
db[h]; s != NULL; s = s->
next) {
3982 if (s->
ssrc == ssrc) {
3985 int expected = extended_max - s->
base_seq + 1;
3987 int expected_interval =
3989 int received_interval =
3992 expected_interval - received_interval;
4000 if (expected_interval == 0
4001 || lost_interval <= 0) {
4005 (lost_interval << 8) /
int blockEncrypt(cipherInstance *cipher, keyInstance *key, BYTE *input, int inputLen, BYTE *outBuffer)
int blockDecrypt(cipherInstance *cipher, keyInstance *key, BYTE *input, int inputLen, BYTE *outBuffer)
int makeKey(keyInstance *key, BYTE direction, int keyLen, const char *keyMaterial)
int cipherInit(cipherInstance *cipher, BYTE mode, char *IV)
#define qfDES_CBC_e(_key, _data, _size, _initVec)
#define qfDES_CBC_d(_key, _data, _size, _initVec)
void debug_dump(const void *lp, int len)
void log_msg(int level, const char *format,...)
#define LOG_LEVEL_NOTICE
information that may be interesting
#define LOG_LEVEL_ERROR
general errors
#define debug_msg(...)
#define debug_msg(...) log_msg(LOG_LEVEL_DEBUG, "[pid/%d +%d %s] ", getpid(), LINE,...
#define LOG_LEVEL_WARNING
less severe errors
void MD5Update(MD5CTX *context, const unsigned char *input, unsigned int inputLen)
void MD5Final(unsigned char digest[16], MD5CTX *context)
void MD5Init(MD5CTX *context)
const char * ug_strerror(int errnum)
const char * get_sockaddr_str(struct sockaddr *sa)
bool is_host_loopback(const char *hostname)
#define IN6_BLACKHOLE_SERVER_MODE_STR
void udp_set_receiver(socket_udp *s, struct sockaddr *sa, socklen_t len)
void udp_exit(socket_udp *s)
int udp_recvfrom(socket_udp *s, char *buffer, int buflen, struct sockaddr *src_addr, socklen_t *addrlen)
int udp_recv(socket_udp *s, char *buffer, int buflen)
int udp_select_r(struct timeval *timeout, struct udp_fd_r *fd_struct)
int udp_get_udp_rx_port(socket_udp *s)
struct socket_udp_local * udp_get_local(socket_udp *s)
int udp_recv_data(socket_udp *s, char **buffer)
void udp_async_start(socket_udp *s, int nr_packets)
void udp_async_wait(socket_udp *s)
char * udp_host_addr(socket_udp *s)
int udp_sendto(socket_udp *s, char *buffer, int buflen, struct sockaddr *dst_addr, socklen_t addrlen)
int udp_sendv(socket_udp *s, struct iovec *vector, int count, void *d)
socket_udp * udp_init_with_local(struct socket_udp_local *l, struct sockaddr *sa, socklen_t len)
bool udp_set_recv_buf(socket_udp *s, int size)
bool udp_not_empty(socket_udp *s, struct timeval *timeout)
Checks whether there are data ready to read in socket.
void udp_fd_zero_r(struct udp_fd_r *fd_struct)
int udp_send(socket_udp *s, char *buffer, int buflen)
void udp_fd_set(socket_udp *s)
int udp_fd_isset(socket_udp *s)
bool udp_set_send_buf(socket_udp *s, int size)
int udp_port_pair_is_free(int force_ip_version, int even_port)
int udp_get_recv_buf(socket_udp *s)
void udp_fd_set_r(socket_udp *s, struct udp_fd_r *fd_struct)
bool udp_is_ipv6(socket_udp *s)
void udp_flush_recv_buf(socket_udp *s)
socket_udp * udp_init_if(const char *addr, const char *iface, uint16_t rx_port, uint16_t tx_port, int ttl, int force_ip_version, bool multithreaded)
bool udp_is_server_mode_blackhole(socket_udp *s)
int udp_select(struct timeval *timeout)
int udp_fd_isset_r(socket_udp *s, struct udp_fd_r *fd_struct)
void ntp64_time(uint32_t *ntp_sec, uint32_t *ntp_frac)
#define ntp64_to_ntp32(ntp_sec, ntp_frac)
static void rtp_process_ctrl(struct rtp *session, uint8_t *buffer, int buflen)
bool rtp_add_csrc(struct rtp *session, uint32_t csrc)
static void check_database(struct rtp *session)
static int validate_rtcp(uint8_t *packet, int len)
static void process_rtcp_app(struct rtp *session, rtcp_t *packet)
bool rtp_set_send_buf(struct rtp *session, int bufsize)
static void insert_rr(struct rtp *session, uint32_t reporter_ssrc, rtcp_rr *rr, rtcp_rx *rx)
struct _rtcp_rr_wrapper rtcp_rr_wrapper
static source * create_source(struct rtp *session, uint32_t ssrc, int probation)
static int ssrc_hash(uint32_t ssrc)
static void process_rtp(struct rtp *session, uint32_t curr_rtp_ts, rtp_packet *packet, source *s)
static bool rijndael_decrypt(struct rtp *session, unsigned char *data, unsigned int size, unsigned char *initVec)
static void process_rtcp_sdes(struct rtp *session, rtcp_t *packet)
static void check_source(source *s)
static void remove_rr(struct rtp *session, uint32_t ssrc)
static int update_seq(source *s, uint16_t seq)
void rtp_flush_recv_buf(struct rtp *session)
#define RTP_LOWER_LAYER_OVERHEAD
bool rtp_set_recv_buf(struct rtp *session, int bufsize)
static int des_encrypt(struct rtp *session, unsigned char *data, unsigned int size, unsigned char *initVec)
static void process_rtcp_sr(struct rtp *session, rtcp_t *packet)
bool rtp_set_option(struct rtp *session, rtp_option optname, int optval)
const rtcp_rr * rtp_get_rr(struct rtp *session, uint32_t reporter, uint32_t reportee)
int rtp_compute_fract_lost(struct rtp *session, uint32_t ssrc)
static uint8_t * format_rtcp_rr(uint8_t *buffer, int buflen, struct rtp *session)
const rtcp_sr * rtp_get_sr(struct rtp *session, uint32_t ssrc)
rtp_t rtp_init_with_udp_socket(struct socket_udp_local *l, struct sockaddr *sa, socklen_t len, rtp_callback callback)
#define MAX_ENCRYPTION_PAD
static void process_rtcp_bye(struct rtp *session, rtcp_t *packet)
int rtp_send_raw_rtp_data(struct rtp *session, char *buffer, int buffer_len)
void rtp_update(struct rtp *session, time_ns_t curr_time)
static uint8_t * format_rtcp_sr(uint8_t *buffer, int buflen, struct rtp *session, uint32_t rtp_ts)
struct rtp * rtp_init_if(const char *addr, const char *iface, uint16_t rx_port, uint16_t tx_port, int ttl, double rtcp_bw, int tfrc_on, rtp_callback callback, uint8_t *userdata, int force_ip_version, bool multithreaded)
int(* rtp_encrypt_func)(struct rtp *, unsigned char *data, unsigned int size, unsigned char *initvec)
static double rtcp_interval(struct rtp *session)
int rtp_send_data_hdr(struct rtp *session, uint32_t rtp_ts, char pt, int m, int cc, const uint32_t *csrc, char *phdr, int phdr_len, char *data, int data_len, char *extn, uint16_t extn_len, uint16_t extn_type)
bool(* rtp_decrypt_func)(struct rtp *, unsigned char *data, unsigned int size, unsigned char *initvec)
static void compute_loss_intervals(struct rtp *session, rtp_packet *packet)
bool rtp_get_option(struct rtp *session, rtp_option optname, int *optval)
static void rtp_process_data(struct rtp *session, uint32_t curr_rtp_ts, uint8_t *buffer, rtp_packet *packet, int buflen)
static char * get_cname(socket_udp *s)
static int format_report_blocks(rtcp_rr *rrp, int remaining_length, struct rtp *session)
static void process_report_blocks(struct rtp *session, rtcp_t *packet, uint32_t ssrc, rtcp_rr *rrp, rtcp_rx *rrx)
static source * get_source(struct rtp *session, uint32_t ssrc)
static void init_seq(source *s, uint16_t seq)
uint32_t rtp_my_ssrc(struct rtp *session)
void rtp_send_ctrl(struct rtp *session, uint32_t rtp_ts, rtcp_app_callback appcallback, time_ns_t curr_time)
bool rtp_set_sdes(struct rtp *session, uint32_t ssrc, rtcp_sdes_type type, const char *value, int length)
bool rtp_has_receiver(struct rtp *session)
uint8_t * rtp_get_userdata(struct rtp *session)
static int add_sdes_item(uint8_t *buf, int buflen, int type, const char *val)
int rtp_get_recv_buf(struct rtp *session)
static void rtp_send_bye_now(struct rtp *session)
struct rtp * rtp_init(const char *addr, uint16_t rx_port, uint16_t tx_port, int ttl, double rtcp_bw, int tfrc_on, rtp_callback callback, uint8_t *userdata, int force_ip_version, bool multithreaded)
int rtp_get_udp_rx_port(struct rtp *session)
static void rtcp_udp_send(struct rtp *session, int len, char *buffer)
static int rijndael_encrypt(struct rtp *session, unsigned char *data, unsigned int size, unsigned char *initVec)
static uint32_t compute_rtt(struct rtp *session, rtcp_rx *rrx)
static void timeout_rr(struct rtp *session, time_ns_t curr_ts)
static bool validate_rtp2(rtp_packet *packet, int len, int vlen)
static source * really_create_source(struct rtp *session, uint32_t ssrc, int probation, source *s)
bool rtp_recv_r(struct rtp *session, struct timeval *timeout, uint32_t curr_rtp_ts)
Receive RTP packets and dispatch them.
static const rtcp_rr * get_rr(struct rtp *session, uint32_t reporter_ssrc, uint32_t reportee_ssrc)
static void delete_source(struct rtp *session, uint32_t ssrc)
int rtp_recv_poll_r(struct rtp **sessions, struct timeval *timeout, uint32_t curr_rtp_ts)
void rtp_set_recv_iov(struct rtp *session, struct msghdr *m)
static void send_rtcp(struct rtp *session, uint32_t rtp_ts, rtcp_app_callback appcallback)
uint64_t rtp_get_bytes_sent(struct rtp *session)
bool rtp_is_ipv6(struct rtp *session)
static int rtp_recv_data(struct rtp *session, uint32_t curr_rtp_ts)
bool rtp_del_csrc(struct rtp *session, uint32_t csrc)
bool rtp_set_encryption_key(struct rtp *session, const char *passphrase)
bool rtp_recv(struct rtp *session, struct timeval *timeout, uint32_t curr_rtp_ts)
struct socket_udp_local * rtp_get_udp_local_socket(struct rtp *session)
static bool des_initialize(struct rtp *session, const u_char *hash, int hash_len)
static bool validate_rtp(struct rtp *session, rtp_packet *packet, int len, int vlen)
int rtp_send_data(struct rtp *session, uint32_t rtp_ts, char pt, int m, int cc, const uint32_t *csrc, char *data, int data_len, char *extn, uint16_t extn_len, uint16_t extn_type)
void rtp_async_wait(struct rtp *session)
bool rtcp_recv_r(struct rtp *session, struct timeval *timeout, uint32_t curr_rtp_ts)
void rtp_async_start(struct rtp *session, int nr_packets)
static uint32_t next_csrc(struct rtp *session)
static void process_rtcp_rx(struct rtp *session, rtcp_t *packet)
bool rtp_set_my_ssrc(struct rtp *session, uint32_t ssrc)
const char * rtp_get_sdes(struct rtp *session, uint32_t ssrc, rtcp_sdes_type type)
static void process_rtcp_rr(struct rtp *session, rtcp_t *packet)
static uint8_t * format_rtcp_app(uint8_t *buffer, int buflen, uint32_t ssrc, rtcp_app *app)
void rtp_send_bye(struct rtp *session)
static bool des_decrypt(struct rtp *session, unsigned char *data, unsigned int size, unsigned char *initVec)
void rtp_done(struct rtp *session)
static int filter_event(struct rtp *session, uint32_t ssrc)
static uint8_t * format_rtcp_sdes(uint8_t *buffer, int buflen, uint32_t ssrc, struct rtp *session)
static void init_opt(struct rtp *session)
static bool rijndael_initialize(struct rtp *session, const u_char *hash, int hash_len)
@ RTP_OPT_REUSE_PACKET_BUFS
@ RTP_OPT_FILTER_MY_PACKETS
@ RTP_OPT_WEAK_VALIDATION
void(* rtp_callback)(struct rtp *session, rtp_event *e)
struct __attribute__((packed))
#define RTP_PACKET_HEADER_SIZE
#define RTP_MAX_PACKET_LEN
rtcp_app *(* rtcp_app_callback)(struct rtp *session, uint32_t rtp_ts, int max_size)
Option::Callback::fcn_type callback
struct _rtcp_rr_wrapper * next
struct _rtcp_rr_wrapper * prev
int should_advertise_sdes
struct rtcp_t::@32::@37 app
struct rtcp_t::@32::@36 bye
struct rtcp_t::@32::rtcp_sdes_t sdes
rtp_encrypt_func encrypt_func
keyInstance keyInstDecrypt
time_ns_t last_rtp_send_time
keyInstance keyInstEncrypt
int encryption_pad_length
rtcp_rr_wrapper rr[RTP_DB_SIZE][RTP_DB_SIZE]
char * encryption_algorithm
union rtp::@38 crypto_state
struct rtp::@38::@39 rijndael
time_ns_t last_rtcp_send_time
struct sockaddr_storage rtcp_dest
cipherInstance cipherInst
rtp_decrypt_func decrypt_func
time_ns_t next_rtcp_send_time
uint32_t get_local_mediatime(void)
static time_ns_t get_time_in_ns()