36 #include <switch_private.h> 39 #include <fspr_network_io.h> 42 #undef PACKAGE_TARNAME 43 #undef PACKAGE_VERSION 44 #undef PACKAGE_BUGREPORT 49 #include <srtp_priv.h> 54 #ifdef DEBUG_TS_ROLLOVER 55 #define TS_ROLLOVER_START 4294951295 63 #define DEBUG_ESTIMATORS_ 66 #define JITTER_LEAD_FRAMES 10 67 #define READ_INC(rtp_session) switch_mutex_lock(rtp_session->read_mutex); rtp_session->reading++ 68 #define READ_DEC(rtp_session) rtp_session->reading--; switch_mutex_unlock(rtp_session->read_mutex) 69 #define WRITE_INC(rtp_session) switch_mutex_lock(rtp_session->write_mutex); rtp_session->writing++ 70 #define WRITE_DEC(rtp_session) rtp_session->writing--; switch_mutex_unlock(rtp_session->write_mutex) 72 #define RTP_STUN_FREQ 1000000 73 #define rtp_header_len 12 74 #define RTP_START_PORT 16384 75 #define RTP_END_PORT 32768 76 #define MASTER_KEY_LEN 30 77 #define RTP_MAGIC_NUMBER 42 78 #define WARN_SRTP_ERRS 10 79 #define MAX_SRTP_ERRS 100 80 #define NTP_TIME_OFFSET 2208988800UL 83 #define DTMF_SANITY (rtp_session->one_second * 30) 85 #define rtp_session_name(_rtp_session) _rtp_session->session ? switch_core_session_get_name(_rtp_session->session) : "-" 87 #define STUN_USERNAME_MAX_SIZE 513 88 #define SDP_UFRAG_MAX_SIZE 256 118 #define RTP_BODY(_s) (char *) (_s->recv_msg.ebody ? _s->recv_msg.ebody : _s->recv_msg.body) 129 #pragma pack(push, r1, 1) 143 #if SWITCH_BYTE_ORDER == __BIG_ENDIAN 170 #pragma pack(pop, r1) 173 #define KALMAN_SYSTEM_MODELS 3 223 unsigned char out_digit_packet[4];
259 char last_sent_id[13];
269 #define MAX_DTLS_MTU 4096 353 srtp_ctx_t *send_ctx[2];
354 srtp_ctx_t *recv_ctx[2];
356 srtp_policy_t send_policy[2];
357 srtp_policy_t recv_policy[2];
359 uint32_t srtp_errs[2];
360 uint32_t srctp_errs[2];
537 static void do_2833(switch_rtp_t *rtp_session);
540 #define rtp_type(rtp_session) rtp_session->flags[SWITCH_RTP_FLAG_TEXT] ? "text" : (rtp_session->flags[SWITCH_RTP_FLAG_VIDEO] ? "video" : "audio") 545 int is_rtcp = ice == &rtp_session->
rtcp_ice;
546 const char *err =
"";
548 uint8_t ice_cand_found_idx = 0;
552 ice_cand_found_idx = i;
556 if (!ice_cand_found_idx) {
622 unsigned char *packet = (
unsigned char *)
RTP_BODY(rtp_session);
626 uint16_t in_digit_seq;
631 if (!(packet[0] || packet[1] || packet[2] || packet[3]) && len >= 8) {
636 if (!(packet[0] || packet[1] || packet[2] || packet[3]) && rtp_session->
dtmf_data.
in_digit_ts) {
645 end = packet[1] & 0x80 ? 1 : 0;
646 duration = (packet[2] << 8) + packet[3];
648 in_digit_seq = ntohs((uint16_t) rtp_session->
last_rtp_hdr.seq);
662 if (in_digit_seq < rtp_session->dtmf_data.in_digit_seq) {
668 if (!(packet[0] || packet[1] || packet[2] || packet[3]) && len >= 8) {
813 static int rtp_write_ready(switch_rtp_t *rtp_session, uint32_t bytes,
int line);
819 #define MEDIA_TOO_LONG 2000 820 #define STUN_TOO_LONG 20000 821 #define ADJ_TOO_LONG 1000 836 if (!ref_point) ref_point = now;
838 rtp_session->
elapsed_stun = (
unsigned int) ((now - ref_point) / 1000);
855 uint8_t
buf[256] = { 0 };
857 unsigned int elapsed;
891 if (elapsed > 30000) {
945 if (strchr(them,
':')) {
958 unsigned char buf[1500] = { 0 };
962 uint32_t *pri = NULL;
963 int is_rtcp = ice == &rtp_session->
rtcp_ice;
967 const char *from_host = NULL;
969 char faddr_buf[80] =
"";
995 if (cpylen >
sizeof(buf)) {
996 cpylen =
sizeof(
buf);
1001 memcpy(buf, data, cpylen);
1026 switch (attr->
type) {
1041 uint32_t code = (err->
code * 100) + err->
number;
1087 uint32_t priority = 0;
1088 pri = (uint32_t *) attr->
value;
1089 priority = ntohl(*pri);
1101 }
while (xlen <= packet->header.length);
1104 ok = !strcmp(ice->
user_ice, username);
1151 if (!
zstr(username)) {
1152 if (!
icecmp(username, ice)) {
1171 const char *old_host, *err = NULL;
1187 for (j = 0; j < 2; j++) {
1188 if (!icep[j] || !icep[j]->ice_params) {
1192 if (icep[j]->ice_params && icep[j]->ice_params->cands[i][icep[j]->
proto].priority == *pri) {
1213 if (!host || !port) {
1219 "%s ICE Auto Changing port from %s:%u to %s:%u\n",
rtp_type(rtp_session), old_host, old, host, port);
1269 const char *host2 = NULL;
1274 uint8_t stunbuf[512];
1276 const char *remote_ip;
1283 int cur_idx = -1, is_relay = 0, is_responsive = 0, use_candidate = 0;
1293 memset(stunbuf, 0,
sizeof(stunbuf));
1332 "%s %s STUN from %s:%d %s is_relay: %d is_responsive: %d use_candidate: %d ready: %d, rready: %d\n",
switch_channel_get_name(channel),
rtp_type(rtp_session), from_host, from_port, cmp ?
"EXPECTED" :
"IGNORED",
1333 is_relay, is_responsive, use_candidate, ice->
ready, ice->
rready);
1364 switch_channel_get_name(channel),
rtp_type(rtp_session), is_rtcp ?
"rtcp" :
"rtp",ice->
initializing,
switch_cmp_addr(from_addr, ice->
addr,
SWITCH_TRUE), from_host, from_port, is_relay, is_responsive, use_candidate,
1379 }
else if (!do_adj) {
1380 switch_log_printf(
SWITCH_CHANNEL_SESSION_LOG(rtp_session->
session),
SWITCH_LOG_DEBUG5,
"ICE %d/%d dt:%d i:%d i2:%d cmp:%d\n", rtp_session->
elapsed_stun, rtp_session->
elapsed_media, (rtp_session->
dtls && rtp_session->
dtls->
state !=
DS_READY), !ice->
ready, !ice->
rready,
switch_cmp_addr(from_addr, ice->
addr,
SWITCH_TRUE));
1437 "Auto Changing %s stun/%s/dtls port from %s:%u to %s:%u idx:%d\n",
rtp_type(rtp_session), is_rtcp ?
"rtcp" :
"rtp",
1439 from_host, from_port, cur_idx);
1467 msg.
from = __FILE__;
1473 "STUN/ICE binding error received on %s channel\n",
rtp_type(rtp_session));
1489 SWITCH_DECLARE(
void) switch_srtp_err_to_txt(srtp_err_status_t stat,
char **msg)
1491 if (stat == srtp_err_status_replay_fail) *msg=
"replay check failed";
1492 else if (stat == srtp_err_status_auth_fail) *msg=
"auth check failed";
1493 else if (stat == srtp_err_status_fail) *msg=
"unspecified failure";
1494 else if (stat == srtp_err_status_bad_param) *msg=
"unsupported parameter";
1495 else if (stat == srtp_err_status_alloc_fail) *msg=
"couldn't allocate memory";
1496 else if (stat == srtp_err_status_dealloc_fail) *msg=
"couldn't deallocate properly";
1497 else if (stat == srtp_err_status_init_fail) *msg=
"couldn't initialize";
1498 else if (stat == srtp_err_status_terminus) *msg=
"can't process as much data as requested";
1499 else if (stat == srtp_err_status_cipher_fail) *msg=
"cipher failure";
1500 else if (stat == srtp_err_status_replay_old) *msg=
"replay check failed";
1501 else if (stat == srtp_err_status_algo_fail) *msg=
"algorithm failed test routine";
1502 else if (stat == srtp_err_status_no_such_op) *msg=
"unsupported operation";
1503 else if (stat == srtp_err_status_no_ctx) *msg=
"no appropriate context found";
1504 else if (stat == srtp_err_status_cant_check) *msg=
"auth check failed";
1505 else if (stat == srtp_err_status_key_expired) *msg=
"can't use key any more";
1506 else if (stat == srtp_err_status_socket_err) *msg=
"error in use of socket";
1507 else if (stat == srtp_err_status_signal_err) *msg=
"error in use POSIX signals";
1508 else if (stat == srtp_err_status_nonce_bad) *msg=
"nonce check failed";
1509 else if (stat == srtp_err_status_read_fail) *msg=
"couldn't read data";
1510 else if (stat == srtp_err_status_write_fail) *msg=
"couldn't write data";
1511 else if (stat == srtp_err_status_parse_err) *msg=
"error parsing data";
1512 else if (stat == srtp_err_status_encode_err) *msg=
"error encoding data";
1513 else if (stat == srtp_err_status_semaphore_err) *msg=
"error while using semaphores";
1514 else if (stat == srtp_err_status_pfkey_err) *msg=
"error while using pfkey ";
1515 else if (stat == srtp_err_status_bad_mki) *msg=
"error MKI present in packet is invalid";
1516 else if (stat == srtp_err_status_pkt_idx_old) *msg=
"packet index is too old to consider";
1517 else if (stat == srtp_err_status_pkt_idx_adv) *msg=
"packet index advanced, reset needed";
1530 srtp_err_status_t stat = srtp_init();
1531 if (stat == srtp_err_status_ok) {
1545 uint8_t m = 0, changed = 0;
1549 rtp_session->
ts = (uint32_t) timestamp;
1571 static void do_mos(switch_rtp_t *rtp_session) {
1602 if (R < 0 || R > 100) R = 100;
1605 rtp_session->
stats.
inbound.
mos = 1 + (0.035) * R + (.000007) * R * (R-60) * (100-R);
1628 lost += i * loss[i];
1631 if (received > 0 && bursts > 0) {
1632 *burstr = (double)((
double)lost / (double)bursts) / (double)(1.0 / ( 1.0 - (
double)lost / (double)received ));
1634 *burstr = - *burstr;
1640 *lossr = (double)((
double)lost / (double)received);
1658 int64_t diff_time = 0, cur_diff = 0;
1674 seq = (int)(uint16_t) ntohs((uint16_t) rtp_session->
last_rtp_hdr.seq);
1747 if ( diff_time < 0 ) {
1748 diff_time = -diff_time;
1798 uint32_t sec, ntp_sec, ntp_usec;
1801 sec = (uint32_t)(now/1000000);
1804 ntp_usec = (uint32_t)(now - (sec*1000000));
1805 sr->
ntp_lsw = htonl((u_long)(ntp_usec*(
double)(((uint64_t)1)<<32)*1.0e-6));
1814 (ntohl(sr->
ntp_lsw)&0xffff0000)>>16 | (ntohl(sr->
ntp_msw)&0x0000ffff)<<16,
1822 uint32_t ntp_sec, ntp_usec, lsr_now, sec;
1824 sec = (uint32_t)(now/1000000);
1828 lsr_now = (uint32_t)(ntp_usec*0.065536) | (ntp_sec&0x0000ffff)<<16;
1836 int16_t extra_expected)
1842 uint32_t expected_pkt,
dlsr = 0;
1853 if (pkt_lost < 0) pkt_lost = 0;
1856 if (expected_pkt > 0 && pkt_lost > 0) {
1857 rtcp_report_block->
fraction = (pkt_lost == expected_pkt ? 255 : (uint8_t) (pkt_lost * 256 / expected_pkt));
1861 #if SWITCH_BYTE_ORDER == __BIG_ENDIAN 1890 rtcp_report_block->
dlsr = htonl(dlsr);
1906 stats->
ssrc = ntohl(hdr->ssrc);
1915 stats->
base_seq = ntohs((uint16_t)hdr->seq);
1957 uint32_t packet_spacing_diff = 0, pkt_tsdiff, pkt_extended_seq;
1958 uint16_t pkt_seq, seq_diff, max_seq;
1959 const int MAX_DROPOUT = 3000;
1960 const int MAX_MISORDER = 100;
1961 const int RTP_SEQ_MOD = (1<<16);
1966 pkt_seq = (uint16_t) ntohs((uint16_t) rtp_session->
last_rtp_hdr.seq);
1970 seq_diff = pkt_seq - max_seq;
1972 if (seq_diff < MAX_DROPOUT) {
1973 if (pkt_seq < max_seq) {
1978 pkt_extended_seq = stats->
cycle << 16 | pkt_seq;
1983 else if (seq_diff <= (RTP_SEQ_MOD - MAX_MISORDER)) {
1984 if (pkt_seq == stats->
bad_seq) {
1987 stats->
bad_seq = (pkt_seq + 1) & (RTP_SEQ_MOD-1);
1995 if (ntohl(hdr->ssrc) != stats->
ssrc || !stats->
init) {
2006 pkt_tsdiff = abs((int32_t)(rtp_session->
timer.
samplecount - ntohl(hdr->ts)));
2011 packet_spacing_diff = abs((int32_t)(pkt_tsdiff - stats->
last_pkt_tsdiff));
2026 uint32_t mantissa_max, i = 0;
2028 uint32_t mantissa = 0;
2029 uint16_t overhead = 60;
2033 mantissa_max = (1 << bits) - 1;
2035 for (i = 0; i < 32; ++i) {
2036 if (bps <= (mantissa_max << i)) {
2042 mantissa = (bps >> exp);
2044 tmmbx->
parts[0] = (uint8_t) ((exp << 2) + ((mantissa >> 15) & 0x03));
2045 tmmbx->
parts[1] = (uint8_t) (mantissa >> 7);
2046 tmmbx->
parts[2] = (uint8_t) ((mantissa >> 1) + ((overhead >> 8) & 0x01));
2047 tmmbx->
parts[3] = (uint8_t) (overhead);
2061 if (sr && rtcp_report_block) {
2073 snprintf(value,
sizeof(value),
"%.8x", rtp_session->
stats.
rtcp.
ssrc);
2082 snprintf(value,
sizeof(value),
"%u", ntohl(sr->
sender_info.
ts));
2085 snprintf(value,
sizeof(value),
"%u", ntohl(sr->
sender_info.
pc));
2088 snprintf(value,
sizeof(value),
"%u", ntohl(sr->
sender_info.
oc));
2091 snprintf(value,
sizeof(value),
"%u", ntohl(sr->
sender_info.
ts));
2098 snprintf(header,
sizeof(header),
"Source-SSRC");
2101 snprintf(header,
sizeof(header),
"Source-Fraction");
2102 snprintf(value,
sizeof(value),
"%u", (uint8_t)rtcp_report_block->
fraction);
2104 snprintf(header,
sizeof(header),
"Source-Lost");
2105 #if SWITCH_BYTE_ORDER == __BIG_ENDIAN 2106 tmpLost = rtcp_report_block->
lost;
2108 tmpLost = ntohl(rtcp_report_block->
lost)>>8;
2109 tmpLost = tmpLost | ((tmpLost & 0x00800000) ? 0xff000000 : 0x00000000);
2111 snprintf(value,
sizeof(value),
"%u", tmpLost);
2113 snprintf(header,
sizeof(header),
"Source-Highest-Sequence-Number-Received");
2116 snprintf(header,
sizeof(header),
"Source-Jitter");
2117 snprintf(value,
sizeof(value),
"%u", ntohl(rtcp_report_block->
jitter));
2119 snprintf(header,
sizeof(header),
"Source-LSR");
2120 snprintf(value,
sizeof(value),
"%u", ntohl(rtcp_report_block->
lsr));
2122 snprintf(header,
sizeof(header),
"Source-DLSR");
2123 snprintf(value,
sizeof(value),
"%u", ntohl(rtcp_report_block->
dlsr));
2136 int rtcp_ok = 0, rtcp_cyclic = 0, rtcp_fb = 0, force_send_rr = 0;
2138 int rate = 0, nack_ttl = 0, nack_dup = 0;
2139 uint32_t cur_nack[
MAX_NACK] = { 0 };
2147 uint8_t data[10] = { 0 };
2171 seq = ntohs(nack & 0xFFFF);
2176 cur_nack[nack_ttl++] = nack;
2210 if (rtcp_ok &&
using_ice(rtp_session)) {
2243 rtp_session->
vb && rtcp_cyclic) {
2253 is_only_receiver =
TRUE;
2258 rr->
ssrc = htonl(rtp_session->
ssrc);
2268 sr->
ssrc = htonl(rtp_session->
ssrc);
2272 if (!rtcp_cyclic && rtcp_fb) {
2318 for (n = 0; n < nack_ttl; n++) {
2330 ext_hdr->
length = htons(3);
2332 nack = (uint32_t *) p;
2333 *nack = cur_nack[n];
2374 fir->
r1 = fir->
r2 = fir->
r3 = 0;
2390 while (rtp_session->
tmmbr || rtp_session->
tmmbn) {
2406 if (rtp_session->
tmmbr) {
2409 bps = rtp_session->
tmmbr;
2410 rtp_session->
tmmbr = 0;
2414 bps = rtp_session->
tmmbn;
2415 rtp_session->
tmmbn = 0;
2434 p = (uint8_t *) (sdes) + sdes_bytes;
2435 ssrc = (uint32_t *) p;
2436 *ssrc = htonl(rtp_session->
ssrc);
2437 sdes_bytes +=
sizeof(uint32_t);
2440 p = (uint8_t *) (sdes) + sdes_bytes;
2443 snprintf((
char *)unit->
value, 80,
"%x", rtp_session->
ssrc);
2451 snprintf((
char *)unit->
value, 80,
"FreeSWITCH.org -- Come to ClueCon.com");
2457 sdes_bytes += 4 - (sdes_bytes % 4);
2459 sdes->length = htons((uint16_t)(sdes_bytes / 4) - 1);
2460 rtcp_bytes += sdes_bytes;
2476 int sbytes = (int) rtcp_bytes;
2489 rtcp_bytes = sbytes;
2498 const char *old_host;
2545 RAND_bytes(buf, len);
2577 srtp_crypto_kernel_shutdown();
2654 rtp_session->
pmaps = pmap;
2667 rtp_session->
seq = 0;
2681 *err =
"RTCP Remote Address Error!";
2705 *err =
"RTCP Socket Error!";
2710 *err =
"RTCP NOT ACTIVE!";
2727 *err =
"RTCP Local Address Error!";
2732 *err =
"RTCP Socket Error!";
2737 *err =
"RTCP Socket Error!";
2742 *err =
"RTCP Bind Error!";
2748 *err =
"RTCP From Address Error!";
2754 rtcp_new_sock = NULL;
2766 if (rtcp_new_sock) {
2770 if (rtcp_old_sock) {
2786 char o[5] =
"TEST", i[5] =
"";
2791 if (rtp_session->
ready != 1) {
2807 if (
zstr(host) || !port) {
2808 *err =
"Address Error";
2818 *err =
"Local Address Error!";
2828 *err =
"Socket Error!";
2833 *err =
"Socket Error!";
2852 if ((j = atoi(host)) && j > 223 && j < 240) {
2854 *err =
"Multicast Socket interface Error";
2859 *err =
"Multicast Error";
2868 int ttl = atoi(var);
2870 if (ttl > 0 && ttl < 256) {
2872 *err =
"Mutlicast TTL set failed";
2943 if (rtp_session->
ready != 1) {
2972 "new max missed packets(%d->%d) greater than current missed packets(%d). RTP will timeout.\n",
2982 if (rtp_session->
jb) {
2991 if (rtp_session->
vb) {
2995 if (rtp_session->
vbw) {
3046 uint32_t o = UINT_MAX;
3133 *err =
"Remote Address Error!";
3142 if (change_adv_addr) {
3160 *err =
"Socket Error!";
3164 if (rtp_session->
dtls) {
3206 return dtls_state_names_t[s];
3209 #define dtls_set_state(_dtls, _state) switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(rtp_session->session), SWITCH_LOG_INFO, "Changing %s DTLS state from %s to %s\n", rtp_type(rtp_session), dtls_state_names(_dtls->state), dtls_state_names(_state)); _dtls->new_state = 1; _dtls->last_state = _dtls->state; _dtls->state = _state 3211 #define cr_keylen 16 3212 #define cr_saltlen 14 3221 uint8_t raw_key_data[
cr_kslen * 2];
3222 unsigned char local_key_buf[
cr_kslen];
3223 unsigned char remote_key_buf[
cr_kslen];
3225 memset(&ssec, 0,
sizeof(ssec));
3232 }
else if ((cert = SSL_get_peer_certificate(dtls->
ssl))) {
3243 unsigned char *local_key, *remote_key, *local_salt, *remote_salt;
3247 #ifdef HAVE_OPENSSL_DTLS_SRTP 3248 if (!SSL_export_keying_material(dtls->
ssl, raw_key_data,
sizeof(raw_key_data),
"EXTRACTOR-dtls_srtp", 19, NULL, 0, 0)) {
3258 local_key = raw_key_data;
3264 remote_key = raw_key_data;
3324 if ((ret = SSL_do_handshake(dtls->
ssl)) != 1){
3325 switch((ret = SSL_get_error(dtls->
ssl, ret))){
3326 case SSL_ERROR_WANT_READ:
3327 case SSL_ERROR_WANT_WRITE:
3328 case SSL_ERROR_NONE:
3337 if (SSL_is_init_finished(dtls->
ssl)) {
3356 SSL_free(dtls->
ssl);
3366 int r = 0, ret = 0, len;
3369 uint8_t is_ice = rtp_session->
ice.
ice_user ? 1 : 0;
3377 if (!dtls->
bytes && !ready) {
3388 char tmp_buf1[80] =
"";
3389 char tmp_buf2[80] =
"";
3401 ret = SSL_get_error(dtls->
ssl, ret);
3403 }
else if (ret != (
int)dtls->
bytes) {
3408 if (dtls_states[dtls->
state]) {
3409 r = dtls_states[dtls->
state](rtp_session, dtls);
3412 while ((pending = BIO_ctrl_pending(dtls->
filter_bio)) > 0) {
3415 len = BIO_read(dtls->
write_bio, buf, pending);
3422 }
else if (bytes != len) {
3426 ret = SSL_get_error(dtls->
ssl, len);
3435 static int cb_verify_peer(
int preverify_ok, X509_STORE_CTX *ctx)
3442 ssl = X509_STORE_CTX_get_app_data(ctx);
3445 if (!(ssl && dtls)) {
3449 if ((cert = SSL_get_peer_certificate(dtls->
ssl))) {
3466 #if OPENSSL_VERSION_NUMBER < 0x10100000L 3473 #if OPENSSL_VERSION_NUMBER < 0x10100000L 3474 return(&dtls_bio_filter_methods);
3476 return(dtls_bio_filter_methods);
3510 #if OPENSSL_VERSION_NUMBER < 0x10100000L 3515 BIO_set_init(bio, 1);
3516 BIO_set_data(bio, filter);
3517 BIO_clear_flags(bio, ~0);
3531 #if OPENSSL_VERSION_NUMBER < 0x10100000L 3537 if (filter != NULL) {
3544 #if OPENSSL_VERSION_NUMBER < 0x10100000L 3549 BIO_set_init(bio, 0);
3550 BIO_set_data(bio, NULL);
3551 BIO_clear_flags(bio, ~0);
3562 #if OPENSSL_VERSION_NUMBER < 0x10100000L 3563 ret = BIO_write(bio->next_bio, in, inl);
3565 ret = BIO_write(BIO_next(bio), in, inl);
3571 #if OPENSSL_VERSION_NUMBER < 0x10100000L 3577 if (filter != NULL) {
3597 filter->
tail = node;
3606 #if OPENSSL_VERSION_NUMBER < 0x10100000L 3613 case BIO_CTRL_DGRAM_GET_FALLBACK_MTU:
3615 case BIO_CTRL_DGRAM_SET_MTU:
3619 case BIO_CTRL_FLUSH:
3621 case BIO_CTRL_DGRAM_QUERY_MTU:
3624 case BIO_CTRL_WPENDING:
3626 case BIO_CTRL_PENDING: {
3630 if (filter == NULL) {
3635 if ((top = filter->
packets)) {
3639 filter->
tail = NULL;
3642 pending = top->
size;
3657 #if OPENSSL_VERSION_NUMBER < 0x10100000L 3658 static BIO_METHOD dtls_bio_filter_methods = {
3671 static BIO_METHOD *dtls_bio_filter_methods = NULL;
3675 #if OPENSSL_VERSION_NUMBER >= 0x10100000L 3676 dtls_bio_filter_methods = BIO_meth_new(BIO_TYPE_FILTER | BIO_get_new_index(),
"DTLS filter");
3685 #if OPENSSL_VERSION_NUMBER >= 0x10100000L 3686 if (dtls_bio_filter_methods) {
3687 BIO_meth_free(dtls_bio_filter_methods);
3688 dtls_bio_filter_methods = NULL;
3698 #ifdef HAVE_OPENSSL_DTLS_SRTP 3755 if (rtp_session->
dtls) {
3759 if (rtp_session->
jb) {
3763 if (rtp_session->
vb) {
3767 if (rtp_session->
vbw) {
3784 for(x = 0; x < 2; x++) {
3786 srtp_dealloc(rtp_session->
send_ctx[x]);
3797 for (x = 0; x < 2; x++) {
3799 srtp_dealloc(rtp_session->
recv_ctx[x]);
3818 const char *kind =
"";
3819 unsigned long ssl_method_error = 0;
3820 unsigned long ssl_ctx_error = 0;
3823 #if OPENSSL_VERSION_NUMBER < 0x30000000 3828 #ifndef OPENSSL_NO_EC 3829 #if OPENSSL_VERSION_NUMBER < 0x10002000L 3834 #ifndef HAVE_OPENSSL_DTLS_SRTP 3850 if ((type & DTLS_TYPE_RTP) && (type & DTLS_TYPE_RTCP)) {
3852 }
else if ((type & DTLS_TYPE_RTP)) {
3859 "Activate %s %s DTLS %s\n", kind,
rtp_type(rtp_session), (type & DTLS_TYPE_SERVER) ?
"server" :
"client");
3861 if (((type & DTLS_TYPE_RTP) && rtp_session->
dtls) || ((type & DTLS_TYPE_RTCP) && rtp_session->
rtcp_dtls)) {
3879 #if OPENSSL_VERSION_NUMBER >= 0x10100000 3880 ssl_method = (type &
DTLS_TYPE_SERVER) ? DTLS_server_method() : DTLS_client_method();
3882 #ifdef HAVE_OPENSSL_DTLSv1_2_method 3883 ssl_method = (type &
DTLS_TYPE_SERVER) ? (want_DTLSv1_2 ? DTLSv1_2_server_method() : DTLSv1_server_method()) : (want_DTLSv1_2 ? DTLSv1_2_client_method() : DTLSv1_client_method());
3885 ssl_method = (type &
DTLS_TYPE_SERVER) ? DTLSv1_server_method() : DTLSv1_client_method();
3886 #endif // HAVE_OPENSSL_DTLSv1_2_method 3890 ssl_method_error = ERR_peek_error();
3894 dtls->
ssl_ctx = ssl_ctx = SSL_CTX_new(ssl_method);
3897 ssl_ctx_error = ERR_peek_error();
3905 #if OPENSSL_VERSION_NUMBER < 0x30000000 3906 bio = BIO_new_file(dtls->
pem,
"r");
3907 dh = PEM_read_bio_DHparams(bio, NULL, NULL, NULL);
3910 SSL_CTX_set_tmp_dh(dtls->
ssl_ctx, dh);
3914 if(!SSL_CTX_set_dh_auto(dtls->
ssl_ctx, 1)) {
3918 SSL_CTX_set_mode(dtls->
ssl_ctx, SSL_MODE_AUTO_RETRY);
3921 SSL_CTX_set_verify(dtls->
ssl_ctx, SSL_VERIFY_NONE, NULL);
3925 SSL_CTX_set_cipher_list(dtls->
ssl_ctx,
"ALL:!ADH:!LOW:!EXP:!MD5:@STRENGTH");
3927 SSL_CTX_set_read_ahead(dtls->
ssl_ctx, 1);
3928 #ifdef HAVE_OPENSSL_DTLS_SRTP 3930 SSL_CTX_set_tlsext_use_srtp(dtls->
ssl_ctx,
"SRTP_AES128_CM_SHA1_80");
3934 dtls->
read_bio = BIO_new(BIO_s_mem());
3940 BIO_set_mem_eof_return(dtls->
read_bio, -1);
3941 BIO_set_mem_eof_return(dtls->
write_bio, -1);
3943 if ((ret=SSL_CTX_use_certificate_file(dtls->
ssl_ctx, dtls->
rsa, SSL_FILETYPE_PEM)) != 1) {
3948 if ((ret=SSL_CTX_use_PrivateKey_file(dtls->
ssl_ctx, dtls->
pvt, SSL_FILETYPE_PEM)) != 1) {
3953 if (SSL_CTX_check_private_key(dtls->
ssl_ctx) == 0) {
3959 && (ret = SSL_CTX_load_verify_locations(dtls->
ssl_ctx, dtls->
ca, NULL)) != 1) {
3962 SSL_get_error(dtls->
ssl, ret));
3968 #if OPENSSL_VERSION_NUMBER < 0x10100000L 3972 dtls->
filter_bio = BIO_new(dtls_bio_filter_methods);
3981 SSL_set_mode(dtls->
ssl, SSL_MODE_AUTO_RETRY);
3982 SSL_set_read_ahead(dtls->
ssl, 1);
3987 #ifndef OPENSSL_NO_EC 3988 #if OPENSSL_VERSION_NUMBER < 0x10002000L 3989 ecdh = EC_KEY_new_by_curve_name(NID_X9_62_prime256v1);
3993 SSL_set_options(dtls->
ssl, SSL_OP_SINGLE_ECDH_USE);
3994 SSL_set_tmp_ecdh(dtls->
ssl, ecdh);
3996 #elif OPENSSL_VERSION_NUMBER < 0x10100000L 3997 SSL_set_ecdh_auto(dtls->
ssl, 1);
3998 SSL_set_options(dtls->
ssl, SSL_OP_SINGLE_ECDH_USE);
4002 SSL_set_verify(dtls->
ssl, SSL_VERIFY_NONE, NULL);
4003 SSL_set_app_data(dtls->
ssl, dtls);
4013 int mtu = atoi(var);
4022 BIO_ctrl(dtls->
filter_bio, BIO_CTRL_DGRAM_SET_MTU, dtls->
mtu, NULL);
4026 if ((type & DTLS_TYPE_RTP)) {
4027 rtp_session->
dtls = dtls;
4032 if ((type & DTLS_TYPE_RTCP)) {
4034 if (!(type & DTLS_TYPE_RTP)) {
4040 if ((type & DTLS_TYPE_SERVER)) {
4041 SSL_set_accept_state(dtls->
ssl);
4043 SSL_set_connect_state(dtls->
ssl);
4067 srtp_policy_t *policy;
4068 srtp_err_status_t stat;
4075 unsigned char b64_key[512] =
"";
4077 unsigned char *keysalt = NULL;
4081 unsigned long *key_material_n = NULL;
4082 srtp_master_key_t **mkis = NULL;
4083 srtp_master_key_t *mki = NULL;
4156 memcpy(crypto_key->
keysalt, keysalt, keysalt_len);
4160 memset(policy, 0,
sizeof(*policy));
4170 switch (crypto_key->
type) {
4172 srtp_crypto_policy_set_aes_cm_128_hmac_sha1_80(&policy->rtp);
4173 srtp_crypto_policy_set_aes_cm_128_hmac_sha1_80(&policy->rtcp);
4180 srtp_crypto_policy_set_aes_cm_128_hmac_sha1_32(&policy->rtp);
4181 srtp_crypto_policy_set_aes_cm_128_hmac_sha1_32(&policy->rtcp);
4190 srtp_crypto_policy_set_aes_gcm_256_8_auth(&policy->rtp);
4191 srtp_crypto_policy_set_aes_gcm_256_8_auth(&policy->rtcp);
4199 srtp_crypto_policy_set_aes_gcm_256_16_auth(&policy->rtp);
4200 srtp_crypto_policy_set_aes_gcm_256_16_auth(&policy->rtcp);
4208 srtp_crypto_policy_set_aes_gcm_128_8_auth(&policy->rtp);
4209 srtp_crypto_policy_set_aes_gcm_128_8_auth(&policy->rtcp);
4217 srtp_crypto_policy_set_aes_gcm_128_16_auth(&policy->rtp);
4218 srtp_crypto_policy_set_aes_gcm_128_16_auth(&policy->rtcp);
4226 srtp_crypto_policy_set_aes_cm_256_hmac_sha1_80(&policy->rtp);
4227 srtp_crypto_policy_set_aes_cm_256_hmac_sha1_80(&policy->rtcp);
4233 srtp_crypto_policy_set_aes_cm_256_hmac_sha1_32(&policy->rtp);
4234 srtp_crypto_policy_set_aes_cm_256_hmac_sha1_32(&policy->rtcp);
4240 srtp_crypto_policy_set_aes_cm_192_hmac_sha1_80(&policy->rtp);
4241 srtp_crypto_policy_set_aes_cm_192_hmac_sha1_80(&policy->rtcp);
4247 srtp_crypto_policy_set_aes_cm_192_hmac_sha1_32(&policy->rtp);
4248 srtp_crypto_policy_set_aes_cm_192_hmac_sha1_32(&policy->rtcp);
4254 srtp_crypto_policy_set_aes_cm_128_null_auth(&policy->rtp);
4255 srtp_crypto_policy_set_aes_cm_128_null_auth(&policy->rtcp);
4267 if (key_material && (*key_material_n > 0)) {
4287 while (key_material && (mki_idx < *key_material_n)) {
4310 memcpy(mki->mki_id, &key_material->
mki_id, key_material->
mki_size);
4311 mki->mki_size = key_material->
mki_size;
4312 memcpy(mki->key, key_material->
raw_key, keysalt_len);
4314 mkis[mki_idx] = mki;
4316 key_material = key_material->
next;
4321 policy->keys = mkis;
4322 policy->num_master_keys = mki_idx;
4325 policy->key = (uint8_t *) crypto_key->
keysalt;
4328 policy->next = NULL;
4330 policy->window_size = 1024;
4331 policy->allow_repeat_tx = 1;
4336 switch (direction) {
4338 policy->ssrc.type = ssrc_any_inbound;
4343 if ((stat = srtp_create(&rtp_session->
recv_ctx[idx], policy)) || !rtp_session->
recv_ctx[idx]) {
4358 policy->ssrc.type = ssrc_any_outbound;
4365 if ((stat = srtp_create(&rtp_session->
send_ctx[idx], policy)) || !rtp_session->
send_ctx[idx]) {
4386 if (rtp_session->
dtls) {
4417 int change_timer = 0;
4425 if (change_timer && rtp_session->
timer_name) {
4438 rtp_session->
timer_name, ms_per_packet / 1000,
4442 "RE-Starting timer [%s] %d bytes per %dms\n", rtp_session->
timer_name, samples_per_interval, ms_per_packet / 1000);
4448 "Problem RE-Starting timer [%s] %d bytes per %dms\n", rtp_session->
timer_name, samples_per_interval, ms_per_packet / 1000);
4475 uint32_t samples_per_interval,
4476 uint32_t ms_per_packet,
4479 switch_rtp_t *rtp_session = NULL;
4485 *new_rtp_session = NULL;
4488 *err =
"Packet Size Too Large!";
4493 *err =
"Memory Error!";
4501 rtp_session->
session = session;
4521 rtp_session->
seq = (uint16_t) rand();
4523 #ifdef DEBUG_TS_ROLLOVER 4547 rtp_session->
payload = payload;
4554 timer_name =
"soft";
4557 if (!
zstr(timer_name) && !strcasecmp(timer_name,
"none")) {
4561 if (!
zstr(timer_name)) {
4568 "Starting timer [%s] %d bytes per %dms\n", timer_name, samples_per_interval, ms_per_packet / 1000);
4570 #ifdef DEBUG_TS_ROLLOVER 4571 rtp_session->
timer.
tick = TS_ROLLOVER_START / samples_per_interval;
4576 "Error Starting timer [%s] %d bytes per %dms, async RTP disabled\n", timer_name, samples_per_interval, ms_per_packet / 1000);
4617 rtp_session->
ready = 1;
4618 *new_rtp_session = rtp_session;
4625 const char *tx_host,
4628 uint32_t samples_per_interval,
4629 uint32_t ms_per_packet,
4634 switch_rtp_t *rtp_session = NULL;
4636 if (
zstr(rx_host)) {
4637 *err =
"Missing local host";
4642 *err =
"Missing local port";
4646 if (
zstr(tx_host)) {
4647 *err =
"Missing remote host";
4652 *err =
"Missing remote port";
4678 rtp_session->
ready = 2;
4680 rtp_session->
rx_port = rx_port;
4693 rtp_session->
te = te;
4708 rtp_session->
cng_pt = pt;
4719 return &rtp_session->
timer;
4732 return rtp_session->
jb ? rtp_session->
jb : rtp_session->
vb;
4739 if (rtp_session->
pause_jb && !pause) {
4740 if (rtp_session->
jb) {
4744 if (rtp_session->
vb) {
4749 new_val = pause ? 1 : -1;
4751 if (rtp_session->
pause_jb + new_val > -1) {
4756 "Jitterbuffer %s is %s\n",
rtp_type(rtp_session), rtp_session->
pause_jb ?
"paused" :
"enabled");
4776 if (rtp_session->
vb) {
4777 return switch_jb_get_frames(rtp_session->
vb, min_frame_len, max_frame_len, cur_frame_len, highest_frame_len);
4793 if (!max_frames || frames >= max_frames) {
4794 max_frames = frames * 10;
4799 if (!rtp_session->
vb) {
4822 if (name) x = atoi(name);
4825 if (rtp_session->
jb) {
4827 }
else if (rtp_session->
vb) {
4835 uint32_t queue_frames,
4836 uint32_t max_queue_frames,
4837 uint32_t samples_per_packet,
4838 uint32_t samples_per_second)
4846 if (queue_frames < 1) {
4850 if (max_queue_frames < queue_frames) {
4851 max_queue_frames = queue_frames * 3;
4856 if (rtp_session->
jb) {
4877 const char *err = NULL;
4894 if (send_rate == -1) {
4931 const char *password,
const char *rpassword,
ice_proto_t proto,
4946 ice = &rtp_session->
ice;
5008 proto ==
IPR_RTP ?
"RTP" :
"RTCP",
rtp_type(rtp_session), ice_user, host, port);
5040 rtp_session->
tmmbr = bps;
5051 rtp_session->
tmmbn = bps;
5092 }
else if (rtp_session->
session) {
5157 && rtp_session->
ready == 2) ? 1 : 0;
5194 if (!rtp_session || !*rtp_session || !(*rtp_session)->
ready) {
5198 if ((*rtp_session)->vb) {
5202 "NACK: Added to JB: [%u]\n", nack_jb_ok);
5210 (*rtp_session)->ready = 0;
5231 if ((*rtp_session)->jb) {
5235 if ((*rtp_session)->vb) {
5239 if ((*rtp_session)->vbw) {
5243 if ((*rtp_session)->dtls && (*rtp_session)->dtls == (*rtp_session)->rtcp_dtls) {
5244 (*rtp_session)->rtcp_dtls = NULL;
5247 if ((*rtp_session)->dtls) {
5251 if ((*rtp_session)->rtcp_dtls) {
5255 if ((*rtp_session)->rtcp_sock_input == (*rtp_session)->sock_input) {
5256 (*rtp_session)->rtcp_sock_input = NULL;
5259 if ((*rtp_session)->rtcp_sock_output == (*rtp_session)->sock_output) {
5260 (*rtp_session)->rtcp_sock_output = NULL;
5263 sock = (*rtp_session)->sock_input;
5264 (*rtp_session)->sock_input = NULL;
5267 if ((*rtp_session)->sock_output != sock) {
5268 sock = (*rtp_session)->sock_output;
5269 (*rtp_session)->sock_output = NULL;
5273 if ((sock = (*rtp_session)->rtcp_sock_input)) {
5274 (*rtp_session)->rtcp_sock_input = NULL;
5278 if ((*rtp_session)->rtcp_sock_output && (*rtp_session)->rtcp_sock_output != sock) {
5279 sock = (*rtp_session)->rtcp_sock_output;
5280 (*rtp_session)->rtcp_sock_output = NULL;
5286 for(x = 0; x < 2; x++) {
5287 if ((*rtp_session)->send_ctx[x]) {
5288 srtp_dealloc((*rtp_session)->send_ctx[x]);
5289 (*rtp_session)->send_ctx[x] = NULL;
5296 for (x = 0; x < 2; x++) {
5297 if ((*rtp_session)->recv_ctx[x]) {
5298 srtp_dealloc((*rtp_session)->recv_ctx[x]);
5299 (*rtp_session)->recv_ctx[x] = NULL;
5306 if ((*rtp_session)->timer.timer_interface) {
5310 if ((*rtp_session)->write_timer.timer_interface) {
5337 rtp_session->
payload = payload;
5374 int old_flag = rtp_session->
flags[flag];
5377 rtp_session->
flags[flag] = 1;
5406 if (xn > 0 && xn <= 65535) {
5417 if (rtp_session->
jb) {
5428 return (uint32_t) rtp_session->
flags[flags];
5433 int old_flag = rtp_session->
flags[flag];
5436 rtp_session->
flags[flag] = 0;
5454 int upsamp, max_upsamp;
5457 if (!max_ms) max_ms = ms;
5507 for (x = 0; x < loops; x++) {
5587 if (rdigit->
digit ==
'w') {
5593 if (rdigit->
digit ==
'W') {
5680 int was_blocking = 0;
5706 bytes_out = bytes_in;
5710 if (rtp_session->
vbw) {
5714 if (rtp_session->
vb) {
5716 bytes_out = bytes_in;
5770 }
while (bytes > 0);
5828 if (rtp_session->
pmaps && *rtp_session->
pmaps) {
5845 #define return_cng_frame() do_cng = 1; goto timer_check 5857 const char *tx_host;
5858 const char *old_host;
5859 const char *my_host;
5861 char bufa[50], bufb[50], bufc[50];
5869 "R %s b=%4ld %s:%u %s:%u %s:%u pt=%d ts=%u seq=%u m=%d\n",
5884 int sbytes = (int) *bytes;
5885 srtp_err_status_t stat = 0;
5931 switch_srtp_err_to_txt(stat, &msg);
5935 "SRTP %s unprotect failed with code %d (%s) %ld bytes %d errors\n",
5936 rtp_type(rtp_session), stat, msg, (
long)*bytes, errs);
5938 "Ending call due to SRTP error\n");
5942 "SRTP %s unprotect failed with code %d (%s) %ld bytes %d errors\n",
5943 rtp_type(rtp_session), stat, msg, (
long)*bytes, errs);
5957 if (!
jb_valid(rtp_bundle_session)) {
5961 if (rtp_bundle_session->
jb && !rtp_bundle_session->
pause_jb &&
jb_valid(rtp_bundle_session)) {
5975 unsigned char *
b = NULL;
5981 uint8_t audio_pt = 0;
5993 rtp_session->
punts++;
5994 rtp_session->
clean = 0;
6030 if (rtp_session->
dtls) {
6043 b = (
unsigned char *) &rtp_session->
recv_msg;
6052 if ((*b >= 20) && (*b <= 64)) {
6053 if (rtp_session->
dtls) {
6060 }
else if (*b == 0 || *b == 1) {
6105 int accept_packet = 1;
6140 if (!accept_packet) {
6142 "Invalid Packet SEQ: %d TS: %d PT:%d ignored\n",
6160 if (!rtp_session->
vb && (!rtp_session->
jb || rtp_session->
pause_jb || !
jb_valid(rtp_session))) {
6162 xcheck_jitter = *bytes;
6198 if (rtp_session->
dtls) {
6224 int sbytes = (int) *bytes;
6225 srtp_err_status_t stat = 0;
6259 const char *tx_host;
6260 const char *old_host;
6261 const char *my_host;
6263 char bufa[50], bufb[50], bufc[50];
6271 "R %s b=%4ld %s:%u %s:%u %s:%u pt=%d ts=%u seq=%u m=%d\n",
6282 #ifdef RTP_READ_PLOSS 6284 int r = (rand() % 10000) + 1;
6287 "Simulate dropped packet ......... ts: %u seq: %u\n", ntohl(rtp_session->
last_rtp_hdr.ts), ntohs(rtp_session->
last_rtp_hdr.seq));
6302 uint16_t seq = ntohs((uint16_t) rtp_session->
last_rtp_hdr.seq);
6305 #ifdef DEBUG_MISSED_SEQ 6311 if (num_missed == 1) {
6313 rtp_session->
last_seq+1, (flushed_packets_diff == 1) ?
" (flushed by FS)" :
" (missed)",
6316 if (flushed_packets_diff == 0) {
6318 "Missed %ld RTP frames from sequence [%d] to [%d] (missed). Time since last read [%ld]\n",
6319 num_missed, rtp_session->
last_seq+1, seq-1,
6321 }
else if (flushed_packets_diff == num_missed) {
6323 "Missed %ld RTP frames from sequence [%d] to [%d] (flushed by FS). Time since last read [%ld]\n",
6324 num_missed, rtp_session->
last_seq+1, seq-1,
6326 }
else if (num_missed > flushed_packets_diff) {
6328 "Missed %ld RTP frames from sequence [%d] to [%d] (%ld packets flushed by FS, %ld packets missed)." 6329 " Time since last read [%ld]\n",
6330 num_missed, rtp_session->
last_seq+1, seq-1,
6331 flushed_packets_diff, num_missed-flushed_packets_diff,
6335 "Missed %ld RTP frames from sequence [%d] to [%d] (%ld packets flushed by FS). Time since last read [%ld]\n",
6336 num_missed, rtp_session->
last_seq+1, seq-1,
6379 int sbytes = (int) *bytes;
6380 srtp_err_status_t stat = 0;
6426 switch_srtp_err_to_txt(stat, &msg);
6430 "SRTP %s unprotect failed with code %d (%s) %ld bytes %d errors\n",
6431 rtp_type(rtp_session), stat, msg, (
long)*bytes, errs);
6433 "Ending call due to SRTP error\n");
6437 "SRTP %s unprotect failed with code %d (%s) %ld bytes %d errors\n",
6438 rtp_type(rtp_session), stat, msg, (
long)*bytes, errs);
6468 if (*bytes > (length * 4 + 4)) {
6469 *bytes -= (length * 4 + 4);
6482 "VIDEO: seq: %d ts: %u len: %ld %02x %02x %02x %02x %02x %02x %02x %02x %02x %02x %02x mark: %d\n",
6484 *((uint8_t *)
RTP_BODY(rtp_session)), *((uint8_t *)
RTP_BODY(rtp_session) + 1),
6485 *((uint8_t *)
RTP_BODY(rtp_session) + 2), *((uint8_t *)
RTP_BODY(rtp_session) + 3),
6486 *((uint8_t *)
RTP_BODY(rtp_session) + 4), *((uint8_t *)
RTP_BODY(rtp_session) + 5),
6487 *((uint8_t *)
RTP_BODY(rtp_session) + 6), *((uint8_t *)
RTP_BODY(rtp_session) + 7),
6488 *((uint8_t *)
RTP_BODY(rtp_session) + 8), *((uint8_t *)
RTP_BODY(rtp_session) + 9),
6531 if (rtp_session->
jb) {
6535 if (rtp_session->
vb) {
6539 if (rtp_session->
vbw) {
6545 if (rtp_session->
has_rtp && *bytes) {
6546 uint32_t read_ssrc = ntohl(rtp_session->
last_rtp_hdr.ssrc);
6562 if (!return_jb_packet) {
6567 if (rtp_session->
jb &&
jb_valid(rtp_session)) {
6586 if (!return_jb_packet) {
6600 if (!*bytes || rtp_session->
has_rtp) {
6609 if (rtp_session->
punts < 4) {
6637 if (++rtp_session->
clean > 200) {
6638 rtp_session->
punts = 0;
6640 if (!xcheck_jitter) {
6679 if (!xcheck_jitter) {
6693 uint16_t seq = (uint16_t) (nack & 0xFFFF);
6694 uint16_t blp = (uint16_t) (nack >> 16);
6696 const char *tx_host = NULL;
6697 const char *old_host = NULL;
6698 const char *my_host = NULL;
6699 char bufa[50], bufb[50], bufc[50];
6718 "X %s b=%4ld %s:%u %s:%u %s:%u pt=%d ts=%u seq=%u m=%d\n",
6734 for (i = 0; i < 16; i++) {
6735 if (blp & (1 << i)) {
6743 "X %s b=%4ld %s:%u %s:%u %s:%u pt=%d ts=%u seq=%u m=%d\n",
6804 uint32_t *nack = (uint32_t *) extp->
body;
6828 uint32_t packet_ssrc;
6830 uint8_t rtt_valid = 0;
6831 int rtt_increase = 0, packet_loss_increase=0;
6844 packet_ssrc = sr->
ssrc;
6850 "length in words = %d, " \
6854 "RTP timestamp = %u, " \
6855 "Sender Packet Count = %u, " \
6856 "Sender Octet Count = %u\n",
6878 packet_ssrc = rr->
ssrc;
6883 "length in words = %d, " \
6894 uint8_t percent_fraction = (uint8_t)((uint16_t)(uint8_t)report->
fraction * 100 / 255);
6899 ((float)percent_fraction * .3));
6926 "Receiving an RTCP packet\n[%04d-%02d-%02d %02d:%02d:%02d.%d] SSRC[0x%x]\n" 6927 "RTT[%f] = A[%u] - DLSR[%u] - LSR[%u]\n",
6943 "Receiving RTCP packet\n[%04d-%02d-%02d %02d:%02d:%02d.%d] SSRC[0x%x]\n" 6944 "Ignoring erroneous RTT[%f] = A[%u] - DLSR[%u] - LSR[%u]\n",
6961 #ifdef DEBUG_ESTIMATORS_ 6971 #ifdef DEBUG_ESTIMATORS_ 6982 #ifdef DEBUG_ESTIMATORS_ 6985 packet_loss_increase = 1;
6987 #ifdef DEBUG_ESTIMATORS_ 6997 #ifdef DEBUG_ESTIMATORS_ 7011 #ifdef DEBUG_ESTIMATORS_ 7021 #ifdef DEBUG_ESTIMATORS_ 7030 #ifdef DEBUG_ESTIMATORS_ 7060 #ifdef DEBUG_ESTIMATORS_ 7145 unsigned char *p = (
unsigned char *) msg;
7152 }
while (remain >= 4);
7178 if (*b == 0 || *b == 1) {
7185 if (*bytes && (*b >= 20) && (*b <= 64)) {
7204 int sbytes = (int) *bytes;
7205 srtp_err_status_t stat = 0;
7235 const char *tx_host;
7236 const char *old_host;
7237 char bufa[50], bufb[50];
7243 "Auto Changing %s RTCP port from %s:%u to %s:%u\n",
rtp_type(rtp_session), old_host, old, tx_host,
7283 uint32_t elapsed = 0;
7286 elapsed = (now - rtp_session->
last_media) / 1000;
7312 int sleep_mss = 1000;
7340 int read_pretriggered = 0;
7342 int got_rtp_poll = 0;
7362 *flags &= ~SFF_RTCP;
7364 read_pretriggered = 0;
7369 read_pretriggered = 1;
7383 *flags &= ~SFF_RTCP;
7385 read_pretriggered = 0;
7391 read_pretriggered = 1;
7416 }
else if (hot_socket && (rtp_session->
hot_hits % 10) != 0) {
7419 }
else if (hot_socket) {
7429 "%s Auto-Flush catching up %d packets (%d)ms.\n",
7471 if (!read_pretriggered) {
7482 int pt = poll_sec * 1000000;
7495 if (rtp_session->
vb && !rtp_session->
pause_jb) {
7534 if (read_pretriggered) {
7535 read_pretriggered = 0;
7539 status =
read_rtp_packet(rtp_session, &bytes, flags, pmapP, poll_status, got_jb);
7582 *flags &= ~SFF_RTCP;
7665 switch_rtp_t *other_rtp_session = NULL;
7678 int sbytes = (int) rtcp_bytes;
7689 rtcp_bytes = sbytes;
7722 if (!bytes && (io_flags & SWITCH_IO_FLAG_NOBLOCK)) {
7740 (bytes && bytes < 5) || (!bytes && poll_loop)) {
7747 if (bytes && bytes < 5) {
7751 if (!bytes && poll_loop) {
7787 const char *tx_host;
7788 const char *old_host;
7789 char bufa[50], bufb[50];
7796 "Auto Changing %s port from %s:%u to %s:%u\n",
rtp_type(rtp_session), old_host, old, tx_host,
7800 char varname[80] =
"";
7870 "Ignoring udptl packet of size of %ld bytes that looks strikingly like a RTP packet.\n", (
long)bytes);
7896 if (check || bytes) {
7901 uint8_t *data = (uint8_t *)
RTP_BODY(rtp_session);
7937 goto result_continue;
7948 uint8_t *data = (uint8_t *)
RTP_BODY(rtp_session);
8100 if ((rdigit = malloc(
sizeof(*rdigit))) != 0) {
8125 if ((rdigit = malloc(
sizeof(*rdigit))) != 0) {
8151 bytes =
rtp_common_read(rtp_session, payload_type, NULL, flags, io_flags);
8156 }
else if (bytes == 0) {
8167 memcpy(data,
RTP_BODY(rtp_session), bytes);
8214 frame->
source = __FILE__;
8222 frame->
seq = (uint16_t) ntohs((uint16_t) rtp_session->
last_rtp_hdr.seq);
8254 bytes =
rtp_common_read(rtp_session, payload_type, NULL, flags, io_flags);
8272 if (!rtp_session)
return 0;
8276 rtp_type(rtp_session), (
long)bytes, line);
8282 rtp_type(rtp_session), (
long)bytes, line);
8295 uint32_t this_ts = 0;
8299 switch_rtp_t *rtp_bundle_session = NULL;
8300 switch_rtp_t *tmp_session = NULL;
8311 if (!rtp_bundle_session && !
rtp_write_ready(rtp_session, datalen, __LINE__)) {
8324 m = (uint8_t) send_msg->
header.m;
8325 rtp_session->
ts = ntohl(send_msg->
header.ts);
8332 send_msg->
header.pt = rtp_session->
te;
8334 data = send_msg->
body;
8344 payload = rtp_session->
te;
8348 send_msg->
header.pt = payload;
8354 memcpy(send_msg->
body, data, datalen);
8385 if (rtp_session->
cn && payload != rtp_session->
cng_pt) {
8386 rtp_session->
cn = 0;
8398 rtp_session->
ts = 0;
8419 rtp_session->
ts_norm.
ts = (uint32_t) rand() % 1000000 + 1;
8448 if (delta < 0 || delta > 90000) {
8451 "Timestamp shift detected last: %d this: %d delta: %d stick with prev delta: %d\n",
8466 send_msg->
header.ssrc = htonl(rtp_session->
ssrc);
8477 uint32_t codec_flags = 0;
8478 uint32_t len =
sizeof(decoded);
8494 uint32_t energy = 0;
8495 uint32_t x, y = 0, z = len /
sizeof(int16_t);
8504 for (x = 0; x < z; x++) {
8505 energy += abs(decoded[y]);
8512 score = (energy / (z / divisor));
8589 this_ts = ntohl(send_msg->
header.ts);
8591 ts_delta = abs((int32_t)(this_ts - rtp_session->
last_write_ts));
8596 #ifdef DEBUG_TS_ROLLOVER 8614 int32_t y = ntohs(send_msg->
header.seq);
8619 if (x > UINT16_MAX / 2 && y < UINT16_MAX / 2) {
8620 x -= (int32_t)UINT16_MAX+1;
8633 rtp_session->
seq += delta;
8635 send_msg->
header.seq = htons(rtp_session->
seq);
8641 if (rtp_bundle_session) {
8642 tmp_session = rtp_session;
8643 rtp_session = rtp_bundle_session;
8649 int sbytes = (int) bytes;
8650 srtp_err_status_t stat;
8661 "Error! RE-Activating %s Secure RTP SEND\n",
rtp_type(rtp_session));
8668 "RE-Activating %s Secure RTP SEND\n",
rtp_type(rtp_session));
8680 "Error: %s SRTP protection failed with code %d\n",
rtp_type(rtp_session), stat);
8689 #ifdef RTP_DEBUG_WRITE_DELTA 8691 int delta = (int) (now - rtp_session->
send_time) / 1000;
8698 const char *tx_host;
8699 const char *old_host;
8700 const char *my_host;
8702 char bufa[50], bufb[50], bufc[50];
8710 "W %s b=%4ld %s:%u %s:%u %s:%u pt=%d ts=%u seq=%u m=%d\n",
8723 if (!rtp_session->
vbw) {
8724 int nack_size = 100;
8728 int tmp = atoi(var);
8730 if (tmp > 0 && tmp < 500) {
8737 if (rtp_session->
vbw) {
8745 #ifdef RTP_WRITE_PLOSS 8747 int r = (rand() % 10000) + 1;
8751 "Simulate dropping packet ......... ts: %u seq: %u\n", ntohl(send_msg->
header.ts), ntohs(send_msg->
header.seq));
8768 rtp_session->
seq -= delta;
8774 if (rtp_bundle_session) rtp_session = tmp_session;
8791 if (send_msg->header.pt == rtp_session->
cng_pt) {
8891 uint32_t len, ts = 0;
8894 srtp_hdr_t local_header;
8926 send_msg = frame->
packet;
8934 send_msg->
header.ssrc = htonl(rtp_session->
ssrc);
8935 send_msg->
header.seq = htons(++rtp_session->
seq);
8939 const char *tx_host;
8940 const char *old_host;
8941 const char *my_host;
8943 char bufa[50], bufb[50], bufc[50];
8951 "W %s b=%4ld %s:%u %s:%u %s:%u pt=%d ts=%u seq=%u m=%d\n",
8992 payload = rtp_session->
cng_pt;
8997 payload = rtp_session->
payload;
8999 if (rtp_session->
pmaps && *rtp_session->
pmaps) {
9001 for (pmap = *rtp_session->
pmaps; pmap; pmap = pmap->
next) {
9029 for (pmap = *rtp_session->
pmaps; pmap; pmap = pmap->
next) {
9039 send_msg = frame->
packet;
9040 local_header = send_msg->
header;
9044 send_msg->
header.pt = payload;
9047 send_msg->
header.version = 2;
9048 send_msg->
header.m = frame->
m;
9054 send_msg->
header.ssrc = htonl(rtp_session->
ssrc);
9073 send_msg->
header = local_header;
9091 *s = rtp_session->
stats;
9093 s = &rtp_session->
stats;
9096 if (rtp_session->
jb) {
9174 if (process_encryption) {
9179 int sbytes = (int) *bytes;
9180 srtp_err_status_t stat;
9214 #if defined(ENABLE_SRTP) 9225 return rtp_session->
ssrc;
uint8_t switch_stun_packet_attribute_add_software(switch_stun_packet_t *packet, char *software, uint16_t ulen)
switch_status_t switch_channel_set_variable_printf(switch_channel_t *channel, const char *varname, const char *fmt,...)
switch_status_t switch_jb_get_packet_by_seq(switch_jb_t *jb, uint16_t seq, switch_rtp_packet_t *packet, switch_size_t *len)
switch_time_t rtcp_last_sent
switch_time_t switch_micro_time_now(void)
Get the current epoch time in microseconds.
switch_pollfd_t * read_pollfd
#define switch_event_fire(event)
Fire an event filling in most of the arguements with obvious values.
switch_status_t switch_jb_get_packet(switch_jb_t *jb, switch_rtp_packet_t *packet, switch_size_t *len)
#define switch_channel_hangup(channel, hangup_cause)
Hangup a channel flagging it's state machine to end.
dtls_fingerprint_t * remote_fp
unsigned int switch_queue_size(switch_queue_t *queue)
switch_status_t switch_channel_execute_on(switch_channel_t *channel, const char *variable_prefix)
switch_time_t total_talk_time
#define KALMAN_SYSTEM_MODELS
#define switch_core_new_memory_pool(p)
Create a new sub memory pool from the core's master pool.
static switch_status_t read_rtcp_packet(switch_rtp_t *rtp_session, switch_size_t *bytes, switch_frame_flag_t *flags)
static switch_size_t do_flush(switch_rtp_t *rtp_session, int force, switch_size_t bytes_in)
switch_status_t switch_rtp_activate_rtcp(switch_rtp_t *rtp_session, int send_rate, switch_port_t remote_port, switch_bool_t mux)
Activate sending RTCP Sender Reports (SR's)
unsigned char remote_raw_key[SWITCH_RTP_MAX_CRYPTO_LEN]
#define SWITCH_SENSITIVE_DTMF_VARIABLE
BIO_METHOD * BIO_dtls_filter(void)
switch_size_t period_packet_count
static switch_bool_t switch_true(const char *expr)
Evaluate the truthfullness of a string expression.
int loss[LOST_BURST_CAPTURE]
switch_rtp_invalid_handler_t invalid_handler
#define SWITCH_CHANNEL_SESSION_LOG(x)
uint16_t switch_sockaddr_get_port(switch_sockaddr_t *sa)
void switch_rtp_set_media_timeout(switch_rtp_t *rtp_session, uint32_t ms)
#define switch_set_flag(obj, flag)
Set a flag on an arbitrary object.
switch_rtp_numbers_t inbound
switch_status_t switch_core_port_allocator_free_port(_In_ switch_core_port_allocator_t *alloc, _In_ switch_port_t port)
Return unused port to the port allocator.
uint8_t switch_rtp_ready(switch_rtp_t *rtp_session)
Test if an RTP session is ready.
uint8_t switch_stun_packet_attribute_add_priority(switch_stun_packet_t *packet, uint32_t priority)
uint32_t max_missed_packets
switch_sockaddr_t * rtcp_from_addr
switch_status_t switch_core_timer_init(switch_timer_t *timer, const char *timer_name, int interval, int samples, switch_memory_pool_t *pool)
Request a timer handle using given time module.
static const char * dtls_state_names_t[]
switch_core_session_message_types_t message_id
#define SWITCH_CHANNEL_LOG
switch_status_t switch_rtp_del_dtls(switch_rtp_t *rtp_session, dtls_type_t type)
struct packet_list_s packet_list_t
switch_status_t switch_core_hash_destroy(_Inout_ switch_hash_t **hash)
Destroy an existing hash table.
unsigned char keysalt[SWITCH_RTP_MAX_CRYPTO_LEN]
static void rtcp_generate_report_block(switch_rtp_t *rtp_session, struct switch_rtcp_report_block *rtcp_report_block, int16_t extra_expected)
unsigned char out_digit_packet[4]
static int dtls_state_ready(switch_rtp_t *rtp_session, switch_dtls_t *dtls)
uint32_t high_ext_seq_recv
void * switch_core_hash_find(_In_ switch_hash_t *hash, _In_z_ const char *key)
Retrieve data from a given hash.
void(* switch_rtp_invalid_handler_t)(switch_rtp_t *rtp_session, switch_socket_t *sock, void *data, switch_size_t datalen, switch_sockaddr_t *from_addr)
switch_status_t switch_time_exp_gmt(switch_time_exp_t *result, switch_time_t input)
switch_socket_t * switch_rtp_get_rtp_socket(switch_rtp_t *rtp_session)
Retrieve the socket from an existing RTP session.
uint32_t rsamples_per_interval
switch_sockaddr_t * remote_addr
uint8_t switch_stun_packet_attribute_add_fingerprint(switch_stun_packet_t *packet)
switch_status_t switch_socket_bind(switch_socket_t *sock, switch_sockaddr_t *sa)
const char * switch_channel_get_partner_uuid(switch_channel_t *channel)
#define SWITCH_STATUS_IS_BREAK(x)
#define switch_core_hash_init(_hash)
switch_status_t switch_channel_set_private(switch_channel_t *channel, const char *key, const void *private_info)
Set private data on channel.
void switch_rtp_reset(switch_rtp_t *rtp_session)
uint8_t switch_stun_packet_attribute_add_controlling(switch_stun_packet_t *packet)
static void rtcp_generate_sender_info(switch_rtp_t *rtp_session, struct switch_rtcp_sender_info *sr)
uint32_t switch_io_flag_t
static void free_dtls(switch_dtls_t **dtlsp)
switch_status_t switch_rtp_ack_bitrate(switch_rtp_t *rtp_session, uint32_t bps)
switch_status_t switch_mcast_hops(switch_socket_t *sock, uint8_t ttl)
switch_mutex_t * write_mutex
switch_pollfd_t * jb_pollfd
switch_sockaddr_t * remote_addr
uint32_t rtcp_autoadj_tally
#define SDP_UFRAG_MAX_SIZE
switch_rtp_t * switch_rtp_new(const char *rx_host, switch_port_t rx_port, const char *tx_host, switch_port_t tx_port, switch_payload_t payload, uint32_t samples_per_interval, uint32_t ms_per_packet, switch_rtp_flag_t flags[SWITCH_RTP_FLAG_INVALID], char *timer_name, const char **err, switch_memory_pool_t *pool, switch_port_t bundle_internal_port, switch_port_t bundle_external_port)
prepare a new RTP session handle and fully initilize it
switch_sockaddr_t * rtcp_local_addr
switch_port_t remote_rtcp_port
struct packet_list_s * next
switch_mutex_t * flag_mutex
#define SWITCH_RECOMMENDED_BUFFER_SIZE
struct switch_rtcp_report_block report_block
switch_core_session_t * switch_rtp_get_core_session(switch_rtp_t *rtp_session)
void switch_channel_event_set_data(_In_ switch_channel_t *channel, _In_ switch_event_t *event)
Add information about a given channel to an event object.
static void check_timeout(switch_rtp_t *rtp_session)
#define WRITE_INC(rtp_session)
#define switch_core_strdup(_pool, _todup)
Copy a string using memory allocation from a given pool.
switch_socket_t * sock_input
void switch_rtp_reset_vb(switch_rtp_t *rtp_session)
switch_bool_t switch_kalman_is_slow_link(kalman_estimator_t *est_loss, kalman_estimator_t *est_rtt)
switch_size_t largest_jb_size
struct error_period * next
static int dtls_state_fail(switch_rtp_t *rtp_session, switch_dtls_t *dtls)
switch_port_t remote_port
uint32_t consecutive_flaws
switch_status_t switch_rtp_add_crypto_key(switch_rtp_t *rtp_session, switch_rtp_crypto_direction_t direction, uint32_t index, switch_secure_settings_t *ssec)
#define switch_core_destroy_memory_pool(p)
Returns a subpool back to the main pool.
switch_memory_pool_t * pool
uint32_t last_jb_read_ssrc
switch_size_t switch_jb_get_last_read_len(switch_jb_t *jb)
switch_status_t switch_event_add_header(switch_event_t *event, switch_stack_t stack, const char *header_name, const char *fmt,...) PRINTF_FUNCTION(4
Add a header to an event.
Representation of an event.
srtp_policy_t send_policy[2]
void * switch_core_memory_pool_get_data(switch_memory_pool_t *pool, const char *key)
struct switch_rtcp_report_block_frame reports[MAX_REPORT_BLOCKS]
struct switch_rtp_vad_data vad_data
const char *const const char *const const cJSON *const value
switch_socket_t * rtcp_sock_input
#define SWITCH_RTP_MAX_BUF_LEN
switch_status_t switch_queue_trypop(switch_queue_t *queue, void **data)
#define SWITCH_CRYPTO_MKI_INDEX
switch_rtp_crypto_direction_t
int32_t switch_sockaddr_get_family(switch_sockaddr_t *sa)
switch_status_t switch_rtp_pause_jitter_buffer(switch_rtp_t *rtp_session, switch_bool_t pause)
static void set_dtmf_delay(switch_rtp_t *rtp_session, uint32_t ms, uint32_t max_ms)
switch_rtp_crypto_key_t * crypto_keys[SWITCH_RTP_CRYPTO_MAX]
uint32_t prev_nacks_inflight
dtls_state_t switch_rtp_dtls_state(switch_rtp_t *rtp_session, dtls_type_t type)
switch_bool_t rtcp_fresh_frame
switch_status_t switch_rtp_set_payload_map(switch_rtp_t *rtp_session, payload_map_t **pmap)
#define rtp_session_name(_rtp_session)
switch_status_t switch_core_codec_decode(switch_codec_t *codec, switch_codec_t *other_codec, void *encoded_data, uint32_t encoded_data_len, uint32_t encoded_rate, void *decoded_data, uint32_t *decoded_data_len, uint32_t *decoded_rate, unsigned int *flag)
Decode data using a codec handle.
uint32_t last_rpt_ext_seq
static int dtls_bio_filter_free(BIO *bio)
void switch_rtp_intentional_bugs(switch_rtp_t *rtp_session, switch_rtp_bug_flag_t bugs)
switch_status_t switch_core_codec_destroy(switch_codec_t *codec)
Destroy an initalized codec handle.
const char * switch_channel_get_variable_dup(switch_channel_t *channel, const char *varname, switch_bool_t dup, int idx)
Retrieve a variable from a given channel.
static void rtcp_stats_init(switch_rtp_t *rtp_session)
#define switch_core_session_get_name(_s)
switch_status_t switch_jb_put_packet(switch_jb_t *jb, switch_rtp_packet_t *packet, switch_size_t len)
uint32_t last_max_vb_frames
switch_status_t switch_jb_destroy(switch_jb_t **jbp)
switch_size_t media_bytes
void switch_rtp_set_telephony_recv_event(switch_rtp_t *rtp_session, switch_payload_t te)
void switch_rtp_set_private(switch_rtp_t *rtp_session, void *private_data)
Associate an arbitrary data pointer with and RTP session.
struct switch_crypto_key_material_s * local_key_material_next
icand_t cands[MAX_CAND][MAX_CAND_IDX_COUNT]
Abstract handler to a timer module.
switch_size_t dtmf_packet_count
int switch_snprintf(_Out_z_cap_(len) char *buf, _In_ switch_size_t len, _In_z_ _Printf_format_string_ const char *format,...)
void switch_jb_set_session(switch_jb_t *jb, switch_core_session_t *session)
switch_rtcp_ext_hdr_t header
switch_port_t switch_rtp_set_start_port(switch_port_t port)
Set/Get RTP start port.
int switch_core_cert_verify(dtls_fingerprint_t *fp)
uint32_t switch_channel_test_flag(switch_channel_t *channel, switch_channel_flag_t flag)
Test for presence of given flag on a given channel.
switch_status_t switch_socket_recvfrom(switch_sockaddr_t *from, switch_socket_t *sock, int32_t flags, char *buf, size_t *len)
struct switch_crypto_key_material_s * next
switch_status_t switch_rtp_zerocopy_read(switch_rtp_t *rtp_session, void **data, uint32_t *datalen, switch_payload_t *payload_type, switch_frame_flag_t *flags, switch_io_flag_t io_flags)
Read data from a given RTP session without copying.
#define READ_DEC(rtp_session)
switch_core_session_t * session
static int do_dtls(switch_rtp_t *rtp_session, switch_dtls_t *dtls)
switch_stun_packet_t * switch_stun_packet_build_header(switch_stun_message_t type, char *id, uint8_t *buf)
Prepare a new outbound packet of a certian type and id.
uint32_t rtcp_autoadj_threshold
A message object designed to allow unlike technologies to exchange data.
static int dtls_state_handshake(switch_rtp_t *rtp_session, switch_dtls_t *dtls)
uint32_t max_next_write_samplecount
struct switch_rtp_rfc2833_data dtmf_data
void switch_rtp_set_max_missed_packets(switch_rtp_t *rtp_session, uint32_t max)
switch_port_t switch_rtp_get_remote_port(switch_rtp_t *rtp_session)
struct payload_map_s * next
uint32_t highest_sequence_number_received
void rtp_flush_read_buffer(switch_rtp_t *rtp_session, switch_rtp_flush_t flush)
struct dtls_bio_filter dtls_bio_filter
switch_status_t switch_rtp_udptl_mode(switch_rtp_t *rtp_session)
#define rtp_type(rtp_session)
void switch_rtp_reset_media_timer(switch_rtp_t *rtp_session)
void switch_rtp_set_telephony_event(switch_rtp_t *rtp_session, switch_payload_t te)
Set the payload type to consider RFC2833 DTMF.
static long dtls_bio_filter_ctrl(BIO *bio, int cmd, long num, void *ptr)
switch_status_t switch_mutex_unlock(switch_mutex_t *lock)
uint8_t switch_stun_packet_attribute_add_use_candidate(switch_stun_packet_t *packet)
#define LOST_BURST_CAPTURE
void switch_rtp_init(switch_memory_pool_t *pool)
Initilize the RTP System.
_Ret_ switch_channel_t * switch_core_session_get_channel(_In_ switch_core_session_t *session)
Retrieve a pointer to the channel object associated with a given session.
void switch_rtp_destroy(switch_rtp_t **rtp_session)
Destroy an RTP session.
uint8_t switch_stun_packet_attribute_add_username(switch_stun_packet_t *packet, char *username, uint16_t ulen)
Add a username packet attribute.
char body[SWITCH_RTCP_MAX_BUF_LEN]
switch_socket_t * sock_output
#define switch_clear_flag(obj, flag)
Clear a flag on an arbitrary object while locked.
unsigned char local_raw_key[SWITCH_RTP_MAX_CRYPTO_LEN]
#define SWITCH_MUTEX_NESTED
uint32_t switch_core_min_dtmf_duration(uint32_t duration)
uint32_t switch_vad_flag_t
switch_status_t switch_rtp_deactivate_jitter_buffer(switch_rtp_t *rtp_session)
static void switch_rtp_dtls_destroy(void)
switch_jb_t * switch_rtp_get_jitter_buffer(switch_rtp_t *rtp_session)
switch_status_t switch_rtp_zerocopy_read_frame(switch_rtp_t *rtp_session, switch_frame_t *frame, switch_io_flag_t io_flags)
Read data from a given RTP session without copying.
#define SWITCH_PATH_SEPARATOR
static int rtp_common_write(switch_rtp_t *rtp_session, rtp_msg_t *send_msg, void *data, uint32_t datalen, switch_payload_t payload, uint32_t timestamp, switch_frame_flag_t *flags)
const switch_codec_implementation_t * implementation
switch_core_media_ice_type_t type
switch_rtcp_numbers_t rtcp
switch_byte_t switch_byte_t * buf
payload_map_t * pmap_tail
#define WRITE_DEC(rtp_session)
switch_queue_t * dtmf_inqueue
if((uint32_t)(unpack->cur - unpack->buf) > unpack->buflen)
static void switch_send_rtcp_event(switch_rtp_t *rtp_session, struct switch_rtcp_sender_report *sr, struct switch_rtcp_report_block *rtcp_report_block)
struct ts_normalize_s ts_normalize_t
#define switch_yield(ms)
Wait a desired number of microseconds and yield the CPU.
static int get_recv_payload(switch_rtp_t *rtp_session)
int icecmp(const char *them, switch_rtp_ice_t *ice)
static void calc_elapsed(switch_rtp_t *rtp_session, switch_rtp_ice_t *ice)
struct switch_rtcp_sender_info sender_info
SWITCH_BEGIN_EXTERN_C switch_status_t switch_jb_create(switch_jb_t **jbp, switch_jb_type_t type, uint32_t min_frame_len, uint32_t max_frame_len, switch_memory_pool_t *pool)
switch_port_t eff_remote_port
uint32_t highest_sequence_number_received
void switch_stun_random_string(char *buf, uint16_t len, char *set)
Writes random characters into a buffer.
static int rtcp_stats(switch_rtp_t *rtp_session)
switch_timer_interface_t * timer_interface
struct switch_rtcp_sdes_unit_s switch_rtcp_sdes_unit_t
switch_status_t switch_core_port_allocator_request_port(_In_ switch_core_port_allocator_t *alloc, _Out_ switch_port_t *port_ptr)
Get a port from the port allocator.
switch_status_t switch_rtp_activate_jitter_buffer(switch_rtp_t *rtp_session, uint32_t queue_frames, uint32_t max_queue_frames, uint32_t samples_per_packet, uint32_t samples_per_second)
Acvite a jitter buffer on an RTP session.
switch_status_t switch_socket_sendto(switch_socket_t *sock, switch_sockaddr_t *where, int32_t flags, const char *buf, switch_size_t *len)
switch_time_t last_read_time
uint32_t rtcp_autoadj_window
static switch_mutex_t * port_lock
int switch_rtp_has_dtls(void)
int switch_cmp_addr(switch_sockaddr_t *sa1, switch_sockaddr_t *sa2, switch_bool_t ip_only)
uint32_t switch_jb_get_nack_success(switch_jb_t *jb)
switch_frame_flag_t flags
switch_status_t switch_mutex_lock(switch_mutex_t *lock)
switch_status_t switch_b64_encode(unsigned char *in, switch_size_t ilen, unsigned char *out, switch_size_t olen)
#define JITTER_LEAD_FRAMES
switch_status_t switch_rtp_get_video_buffer_size(switch_rtp_t *rtp_session, uint32_t *min_frame_len, uint32_t *max_frame_len, uint32_t *cur_frame_len, uint32_t *highest_frame_len)
uint32_t flags[SWITCH_RTP_FLAG_INVALID]
#define switch_core_session_request_video_refresh(_s)
switch_mutex_t * dtmf_mutex
unsigned long local_key_material_n
switch_status_t switch_sockaddr_create(switch_sockaddr_t **sa, switch_memory_pool_t *pool)
#define switch_core_alloc(_pool, _mem)
Allocate memory directly from a memory pool.
uint32_t actual_samples_per_second
#define switch_stun_packet_first_attribute(packet, attribute)
set a switch_stun_packet_attribute_t pointer to point at the first attribute in a packet ...
switch_status_t switch_rtp_activate_ice(switch_rtp_t *rtp_session, char *login, char *rlogin, const char *password, const char *rpassword, ice_proto_t proto, switch_core_media_ice_type_t type, ice_t *ice_params)
Acvite ICE on an RTP session.
switch_status_t switch_jb_get_frames(switch_jb_t *jb, uint32_t *min_frame_len, uint32_t *max_frame_len, uint32_t *cur_frame_len, uint32_t *highest_frame_len)
#define switch_channel_get_variable(_c, _v)
static switch_status_t read_rtp_packet(switch_rtp_t *rtp_session, switch_size_t *bytes, switch_frame_flag_t *flags, payload_map_t **pmapP, switch_status_t poll_status, switch_bool_t return_jb_packet)
void switch_rtp_set_flags(switch_rtp_t *rtp_session, switch_rtp_flag_t flags[SWITCH_RTP_FLAG_INVALID])
switch_status_t switch_event_add_header_string(switch_event_t *event, switch_stack_t stack, const char *header_name, const char *data)
Add a string header to an event.
switch_sockaddr_t * rtp_from_addr
switch_status_t switch_socket_create_pollset(switch_pollfd_t **poll, switch_socket_t *sock, int16_t flags, switch_memory_pool_t *pool)
Create a set of file descriptors to poll from a socket.
void switch_core_port_allocator_destroy(_Inout_ switch_core_port_allocator_t **alloc)
destroythe port allocator
static switch_hash_t * alloc_hash
#define SWITCH_RTP_MAX_CRYPTO_LEN
switch_byte_t rtcp_auto_adj_used
switch_port_t switch_rtp_set_end_port(switch_port_t port)
Set/Get RTP end port.
#define switch_stun_attribute_padded_length(attribute)
Obtain the padded length of an attribute's value.
switch_status_t switch_rtp_disable_vad(switch_rtp_t *rtp_session)
Disable VAD on an RTP Session.
#define switch_safe_free(it)
Free a pointer and set it to NULL unless it already is NULL.
switch_rtp_numbers_t outbound
void switch_rtp_video_loss(switch_rtp_t *rtp_session)
#define READ_INC(rtp_session)
uint32_t autoadj_threshold
uint32_t samples_per_second
switch_byte_t auto_adj_used
switch_status_t switch_mutex_init(switch_mutex_t **lock, unsigned int flags, switch_memory_pool_t *pool)
static BIO_METHOD dtls_bio_filter_methods
static switch_status_t read_bundle_rtp_packet(switch_rtp_t *rtp_session, switch_size_t *bytes, switch_frame_flag_t *flags)
switch_status_t switch_rtp_set_remote_ssrc(switch_rtp_t *rtp_session, uint32_t ssrc)
#define switch_stun_packet_length(packet)
Obtain the correct length in bytes of a stun packet.
int switch_jb_poll(switch_jb_t *jb)
char body[SWITCH_RTP_MAX_BUF_LEN+4+sizeof(char *)]
switch_status_t switch_socket_opt_set(switch_socket_t *sock, int32_t opt, int32_t on)
switch_status_t switch_rtp_set_ssrc(switch_rtp_t *rtp_session, uint32_t ssrc)
void switch_jb_set_flag(switch_jb_t *jb, switch_jb_flag_t flag)
dtls_state_handler_t dtls_states[DS_INVALID]
void switch_core_hash_this(_In_ switch_hash_index_t *hi, _Out_opt_ptrdiff_cap_(klen) const void **key, _Out_opt_ switch_ssize_t *klen, _Out_ void **val)
Gets the key and value of the current hash element.
switch_rtp_crypto_key_type_t type
char * switch_strerror_r(int errnum, char *buf, switch_size_t buflen)
switch_byte_t switch_rtp_check_auto_adj(switch_rtp_t *rtp_session)
An abstraction of a data frame.
uint32_t switch_rtp_get_default_payload(switch_rtp_t *rtp_session)
Get the default payload number for a given RTP session.
static int rtp_write_ready(switch_rtp_t *rtp_session, uint32_t bytes, int line)
switch_status_t switch_rtp_add_dtls(switch_rtp_t *rtp_session, dtls_fingerprint_t *local_fp, dtls_fingerprint_t *remote_fp, dtls_type_t type, uint8_t want_DTLSv1_2)
switch_sockaddr_t * local_addr
switch_hash_index_t * switch_core_hash_next(_In_ switch_hash_index_t **hi)
Gets the next element of a hashtable.
struct switch_rtp * rtp_session
int switch_core_cert_expand_fingerprint(dtls_fingerprint_t *fp, const char *str)
void switch_swap_linear(int16_t *buf, int len)
Perform a byteswap on a buffer of 16 bit samples.
switch_size_t switch_rtp_has_dtmf(switch_rtp_t *rtp_session)
Test for presence of DTMF on a given RTP session.
switch_time_t start_talking
#define switch_core_codec_init(_codec, _codec_name, _modname, _fmtp, _rate, _ms, _channels, _flags, _codec_settings, _pool)
Initialize a codec handle.
uint32_t recovering_stream
switch_status_t switch_mcast_interface(switch_socket_t *sock, switch_sockaddr_t *iface)
switch_status_t switch_jb_set_frames(switch_jb_t *jb, uint32_t min_frame_len, uint32_t max_frame_len)
char switch_rfc2833_to_char(int event)
Return the RFC2833 character based on an event id.
void switch_cond_next(void)
#define switch_core_session_get_partner(_session, _partner)
switch_rtp_ice_t rtcp_ice
static switch_port_t START_PORT
kalman_estimator_t * estimators[KALMAN_SYSTEM_MODELS]
uint32_t consecutive_flaws
void * switch_rtp_get_private(switch_rtp_t *rtp_session)
Retrieve the private data from a given RTP session.
int microseconds_per_packet
char * switch_core_get_variable(_In_z_ const char *varname)
Retrieve a global variable from the core.
#define dtls_set_state(_dtls, _state)
uint32_t last_in_digit_ts
switch_size_t packet_count
switch_status_t switch_rtp_set_remote_address(switch_rtp_t *rtp_session, const char *host, switch_port_t port, switch_port_t remote_rtcp_port, switch_bool_t change_adv_addr, const char **err)
Assign a remote address to the RTP session.
uint32_t switch_frame_flag_t
unsigned long remote_key_material_n
char * switch_channel_get_uuid(switch_channel_t *channel)
Retrieve the given channel's unique id.
switch_status_t switch_core_timer_destroy(switch_timer_t *timer)
Destroy an allocated timer.
int switch_core_cert_extract_fingerprint(X509 *x509, dtls_fingerprint_t *fp)
int cand_idx[MAX_CAND_IDX_COUNT]
#define switch_core_session_receive_message(_session, _message)
void switch_core_session_rwunlock(_In_ switch_core_session_t *session)
Unlock a read or write lock on as given session.
switch_directories SWITCH_GLOBAL_dirs
char * switch_core_session_get_uuid(_In_ switch_core_session_t *session)
Retrieve the unique identifier from a session.
switch_status_t switch_poll(switch_pollfd_t *aprset, int32_t numsock, int32_t *nsds, switch_interval_time_t timeout)
switch_size_t jb_packet_count
#define SWITCH_RTCP_MAX_BUF_LEN
unsigned char switch_char_to_rfc2833(char key)
Return the RFC2833 event based on an key character.
switch_memory_pool_t * pool
switch_size_t skip_packet_count
struct fspr_sockaddr_t switch_sockaddr_t
void switch_rtp_set_cng_pt(switch_rtp_t *rtp_session, switch_payload_t pt)
Set the payload type for comfort noise.
switch_status_t switch_rtp_write_raw(switch_rtp_t *rtp_session, void *data, switch_size_t *bytes, switch_bool_t process_encryption)
void switch_rtp_shutdown(void)
static switch_status_t timer_check(switch_timer_t *timer, switch_bool_t step)
uint32_t switch_rtp_get_default_samples_per_interval(switch_rtp_t *rtp_session)
Get the default samples per interval for a given RTP session.
void switch_jb_debug_level(switch_jb_t *jb, uint8_t level)
struct fspr_thread_mutex_t switch_mutex_t
switch_status_t switch_core_timer_next(switch_timer_t *timer)
Wait for one cycle on an existing timer.
#define SWITCH_CHANNEL_SESSION_LOG_CLEAN(x)
static int switch_channel_var_true(switch_channel_t *channel, const char *variable)
switch_socket_t * rtcp_sock_output
static switch_port_t END_PORT
switch_status_t switch_file_exists(const char *filename, switch_memory_pool_t *pool)
void switch_rtp_clear_flag(switch_rtp_t *rtp_session, switch_rtp_flag_t flag)
Clear an RTP Flag.
switch_stun_packet_header_t header
#define switch_stun_packet_next_attribute(attribute, end)
Increment an attribute pointer to the next attribute in it's packet.
switch_rtcp_frame_t rtcp_frame
switch_time_t stop_talking
switch_port_t switch_rtp_request_port(const char *ip)
Request a new port to be used for media.
static void handle_ice(switch_rtp_t *rtp_session, switch_rtp_ice_t *ice, void *data, switch_size_t len)
void switch_rtp_set_flag(switch_rtp_t *rtp_session, switch_rtp_flag_t flag)
Set an RTP Flag.
switch_status_t switch_socket_create(switch_socket_t **new_sock, int family, int type, int protocol, switch_memory_pool_t *pool)
switch_status_t switch_rtp_create(switch_rtp_t **new_rtp_session, switch_payload_t payload, uint32_t samples_per_interval, uint32_t ms_per_packet, switch_rtp_flag_t flags[SWITCH_RTP_FLAG_INVALID], char *timer_name, const char **err, switch_memory_pool_t *pool)
create a new RTP session handle
switch_rtp_hdr_ext_t * ext
uint8_t number_of_channels
uint32_t samples_per_second
static void handle_nack(switch_rtp_t *rtp_session, uint32_t nack)
char * switch_rtp_get_remote_host(switch_rtp_t *rtp_session)
#define STUN_USERNAME_MAX_SIZE
char * switch_stun_packet_attribute_get_username(switch_stun_packet_attribute_t *attribute, char *username, uint16_t len)
Extract a username from a packet attribute.
switch_status_t
Common return values.
switch_timer_t * switch_rtp_get_media_timer(switch_rtp_t *rtp_session)
switch_mutex_t * read_mutex
void * switch_channel_get_private(switch_channel_t *channel, const char *key)
Retrieve private from a given channel.
#define switch_goto_status(_status, _label)
static int dtls_bio_filter_new(BIO *bio)
uint32_t switch_rtp_get_ssrc(switch_rtp_t *rtp_session)
Retrieve the SSRC from a given RTP session.
struct error_period * error_log
void switch_rtp_ping(switch_rtp_t *rtp_session)
switch_size_t switch_rtp_dequeue_dtmf(switch_rtp_t *rtp_session, switch_dtmf_t *dtmf)
Retrieve DTMF digits from a given RTP session.
static switch_status_t enable_remote_rtcp_socket(switch_rtp_t *rtp_session, const char **err)
void switch_rtp_flush(switch_rtp_t *rtp_session)
static int using_ice(switch_rtp_t *rtp_session)
uint32_t samples_per_interval
#define SWITCH_SO_NONBLOCK
uint32_t interdigit_delay
switch_rtcp_video_counters_t video_in
switch_size_t last_flush_packet_count
switch_status_t switch_socket_close(switch_socket_t *sock)
void switch_rtp_break(switch_rtp_t *rtp_session)
#define MAX_REPORT_BLOCKS
uint32_t last_recv_lsr_local
void switch_rtp_reset_jb(switch_rtp_t *rtp_session)
An abstraction of a rtcp frame.
srtp_policy_t recv_policy[2]
switch_payload_t ianacode
#define switch_core_hash_insert(_h, _k, _d)
switch_status_t switch_socket_shutdown(switch_socket_t *sock, switch_shutdown_how_e how)
#define switch_core_session_locate(uuid_str)
Locate a session based on it's uuid.
uint8_t switch_stun_packet_attribute_get_xor_mapped_address(switch_stun_packet_attribute_t *attribute, switch_stun_packet_header_t *header, char *ipstr, switch_size_t iplen, uint16_t *port)
uint16_t period_pkt_count
switch_rtp_flag_t
RTP Related Flags.
switch_mutex_t * ice_mutex
switch_time_t next_stat_check_time
static void reset_jitter_seq(switch_rtp_t *rtp_session)
switch_status_t switch_rtp_set_interval(switch_rtp_t *rtp_session, uint32_t ms_per_packet, uint32_t samples_per_interval)
void switch_rtp_get_random(void *buf, uint32_t len)
switch_status_t switch_rtp_queue_rfc2833(switch_rtp_t *rtp_session, const switch_dtmf_t *dtmf)
Queue RFC2833 DTMF data into an RTP Session.
switch_core_session_t * session
#define SWITCH_RTP_MAX_BUF_LEN_WORDS
void switch_rtp_set_default_payload(switch_rtp_t *rtp_session, switch_payload_t payload)
Set the default payload number for a given RTP session.
#define switch_event_create(event, id)
Create a new event assuming it will not be custom event and therefore hiding the unused parameters...
switch_stun_packet_t * switch_stun_packet_parse(uint8_t *buf, uint32_t len)
Prepare a raw packet for parsing.
switch_size_t flush_packet_count
static int check_rtcp_and_ice(switch_rtp_t *rtp_session)
int(* dtls_state_handler_t)(switch_rtp_t *, switch_dtls_t *)
switch_timer_t write_timer
uint32_t switch_jb_pop_nack(switch_jb_t *jb)
void switch_jb_reset(switch_jb_t *jb)
static int rtp_common_read(switch_rtp_t *rtp_session, switch_payload_t *payload_type, payload_map_t **pmapP, switch_frame_flag_t *flags, switch_io_flag_t io_flags)
#define switch_channel_set_flag(_c, _f)
switch_time_t last_write_timestamp
switch_dtls_t * rtcp_dtls
void burstr_calculate(int loss[], int received, double *burstr, double *lossr)
void switch_rtp_clear_flags(switch_rtp_t *rtp_session, switch_rtp_flag_t flags[SWITCH_RTP_FLAG_INVALID])
const SSL_METHOD * ssl_method
int switch_rtp_write_frame(switch_rtp_t *rtp_session, switch_frame_t *frame)
Write data to a given RTP session.
unsigned int out_digit_sofar
switch_size_t media_packet_count
switch_rtp_stats_t * switch_rtp_get_stats(switch_rtp_t *rtp_session, switch_memory_pool_t *pool)
switch_call_direction_t switch_channel_direction(switch_channel_t *channel)
switch_rtp_bug_flag_t rtp_bugs
void switch_kalman_init(kalman_estimator_t *est, float Q, float R)
switch_status_t switch_queue_trypush(switch_queue_t *queue, void *data)
static void ping_socket(switch_rtp_t *rtp_session)
static void switch_rtp_dtls_init(void)
switch_status_t switch_rtp_set_video_buffer_size(switch_rtp_t *rtp_session, uint32_t frames, uint32_t max_frames)
struct switch_rtcp_report_block report_block
#define SWITCH_SO_REUSEADDR
static void do_2833(switch_rtp_t *rtp_session)
switch_rtcp_video_stats_t rtcp_vstats
switch_status_t switch_rtp_change_interval(switch_rtp_t *rtp_session, uint32_t ms_per_packet, uint32_t samples_per_interval)
switch_status_t switch_rtp_debug_jitter_buffer(switch_rtp_t *rtp_session, const char *name)
static int jb_valid(switch_rtp_t *rtp_session)
dtls_fingerprint_t * local_fp
static uint32_t calc_local_lsr_now(void)
switch_bool_t switch_kalman_cusum_init(cusum_kalman_detector_t *detect_change, float epsilon, float h)
static const char * dtls_state_names(dtls_state_t s)
time_t switch_epoch_time_now(time_t *t)
Get the current epoch time.
switch_bool_t switch_kalman_cusum_detect_change(cusum_kalman_detector_t *detector, float measurement, float rtt_avg)
switch_status_t switch_mcast_join(switch_socket_t *sock, switch_sockaddr_t *join, switch_sockaddr_t *iface, switch_sockaddr_t *source)
switch_status_t switch_rtp_set_local_address(switch_rtp_t *rtp_session, const char *host, switch_port_t port, const char **err)
Assign a local address to the RTP session.
#define switch_core_session_alloc(_session, _memory)
Allocate memory from a session's pool.
switch_queue_t * dtmf_queue
uint8_t switch_stun_packet_attribute_add_controlled(switch_stun_packet_t *packet)
switch_status_t switch_rtp_enable_vad(switch_rtp_t *rtp_session, switch_core_session_t *session, switch_codec_t *codec, switch_vad_flag_t flags)
Enable VAD on an RTP Session.
void switch_rtp_release_port(const char *ip, switch_port_t port)
#define switch_test_flag(obj, flag)
Test for the existance of a flag on an arbitary object.
uint32_t next_write_samplecount
void switch_log_printf(_In_ switch_text_channel_t channel, _In_z_ const char *file, _In_z_ const char *func, _In_ int line, _In_opt_z_ const char *userdata, _In_ switch_log_level_t level, _In_z_ _Printf_format_string_ const char *fmt,...) PRINTF_FUNCTION(7
Write log data to the logging engine.
unsigned int out_digit_dur
uint32_t switch_rtp_test_flag(switch_rtp_t *rtp_session, switch_rtp_flag_t flags)
Test an RTP Flag.
char body[SWITCH_RTCP_MAX_BUF_LEN]
unsigned char raw_key[SWITCH_RTP_MAX_CRYPTO_LEN]
switch_pollfd_t * rtcp_read_pollfd
uint32_t conf_samples_per_interval
static void check_jitter(switch_rtp_t *rtp_session)
void switch_rtp_set_invalid_handler(switch_rtp_t *rtp_session, switch_rtp_invalid_handler_t on_invalid)
Set a callback function to execute when an invalid RTP packet is encountered.
uint8_t switch_stun_packet_attribute_add_xor_binded_address(switch_stun_packet_t *packet, char *ipstr, uint16_t port, int family)
struct fspr_pool_t switch_memory_pool_t
uint32_t last_write_samplecount
static handle_rfc2833_result_t handle_rfc2833(switch_rtp_t *rtp_session, switch_size_t bytes, int *do_cng)
const char * switch_get_addr(char *buf, switch_size_t len, switch_sockaddr_t *in)
const char * switch_stun_value_to_name(int32_t type, uint32_t value)
Obtain a printable string form of a given value.
switch_status_t switch_queue_create(switch_queue_t **queue, unsigned int queue_capacity, switch_memory_pool_t *pool)
int chosen[MAX_CAND_IDX_COUNT]
#define SWITCH_RTP_CNG_PAYLOAD
#define return_cng_frame()
switch_status_t switch_rtp_queue_rfc2833_in(switch_rtp_t *rtp_session, const switch_dtmf_t *dtmf)
Queue RFC2833 DTMF data into an RTP Session.
static switch_status_t process_rtcp_packet(switch_rtp_t *rtp_session, switch_size_t *bytes)
struct fspr_socket_t switch_socket_t
void switch_rtp_kill_socket(switch_rtp_t *rtp_session)
Kill the socket on an existing RTP session.
void switch_jb_set_jitter_estimator(switch_jb_t *jb, double *jitter, uint32_t samples_per_frame, uint32_t samples_per_second)
const char * switch_version_revision_human(void)
switch_sockaddr_t * from_addr
static const switch_payload_t INVALID_PT
void switch_channel_clear_flag(switch_channel_t *channel, switch_channel_flag_t flag)
Clear given flag(s) from a channel.
switch_core_media_ice_type_t
switch_bool_t switch_kalman_estimate(kalman_estimator_t *est, float measurement, int system_model)
char * switch_core_sprintf(_In_ switch_memory_pool_t *pool, _In_z_ _Printf_format_string_ const char *fmt,...)
printf-style style printing routine. The data is output to a string allocated from the pool ...
#define switch_channel_set_variable(_channel, _var, _val)
void switch_rtp_video_refresh(switch_rtp_t *rtp_session)
switch_time_t switch_time_now(void)
switch_sockaddr_t * rtcp_remote_addr
unsigned int out_digit_sub_sofar
static switch_status_t ice_out(switch_rtp_t *rtp_session, switch_rtp_ice_t *ice, switch_bool_t force)
static void do_mos(switch_rtp_t *rtp_session)
switch_status_t switch_sockaddr_info_get(switch_sockaddr_t **sa, const char *hostname, int32_t family, switch_port_t port, int32_t flags, switch_memory_pool_t *pool)
static int dtls_state_setup(switch_rtp_t *rtp_session, switch_dtls_t *dtls)
switch_rtp_crypto_key_type_t crypto_type
static void calc_bw_exp(uint32_t bps, uint8_t bits, rtcp_tmmbx_t *tmmbx)
struct switch_rtp_crypto_key * next
char * switch_channel_get_name(switch_channel_t *channel)
Retrieve the name of a given channel.
switch_status_t switch_rtp_req_bitrate(switch_rtp_t *rtp_session, uint32_t bps)
static int check_recv_payload(switch_rtp_t *rtp_session)
static void switch_rtp_change_ice_dest(switch_rtp_t *rtp_session, switch_rtp_ice_t *ice, const char *host, switch_port_t port)
#define switch_core_hash_first(_h)
char * eff_remote_host_str
uint8_t switch_stun_packet_attribute_get_mapped_address(switch_stun_packet_attribute_t *attribute, char *ipstr, switch_size_t iplen, uint16_t *port)
Extract a mapped address (IP:PORT) from a packet attribute.
static int dtls_bio_filter_write(BIO *bio, const char *in, int inl)
switch_status_t switch_rtcp_zerocopy_read_frame(switch_rtp_t *rtp_session, switch_rtcp_frame_t *frame)
Read RTCP data from a given RTP session without copying.
switch_status_t switch_rtp_read(switch_rtp_t *rtp_session, void *data, uint32_t *datalen, switch_payload_t *payload_type, switch_frame_flag_t *flags, switch_io_flag_t io_flags)
Read data from a given RTP session.
void switch_rtp_set_interdigit_delay(switch_rtp_t *rtp_session, uint32_t delay)
cusum_kalman_detector_t * detectors[KALMAN_SYSTEM_MODELS]
struct switch_dtls_s switch_dtls_t
switch_status_t switch_rtp_sync_stats(switch_rtp_t *rtp_session)
switch_codec_t * read_codec
void switch_jb_ts_mode(switch_jb_t *jb, uint32_t samples_per_frame, uint32_t samples_per_second)
static switch_status_t enable_local_rtcp_socket(switch_rtp_t *rtp_session, const char **err)
static uint8_t get_next_write_ts(switch_rtp_t *rtp_session, uint32_t timestamp)
uint32_t last_recv_lsr_peer
rtcp_msg_t * rtcp_recv_msg_p
int switch_cp_addr(switch_sockaddr_t *sa1, switch_sockaddr_t *sa2)
#define LOST_BURST_ANALYZE
switch_socket_t * sock_output
switch_memory_pool_t * pool
uint8_t switch_stun_packet_attribute_add_integrity(switch_stun_packet_t *packet, const char *pass)
switch_status_t switch_core_port_allocator_new(_In_ const char *ip, _In_ switch_port_t start, _In_ switch_port_t end, _In_ switch_port_flag_t flags, _Out_ switch_core_port_allocator_t **new_allocator)
Initilize the port allocator.
static switch_status_t process_rtcp_report(switch_rtp_t *rtp_session, rtcp_msg_t *msg, switch_size_t bytes)
switch_status_t switch_core_timer_sync(switch_timer_t *timer)
switch_size_t cng_packet_count
switch_status_t switch_ivr_parse_all_messages(switch_core_session_t *session)
int switch_rtp_write_manual(switch_rtp_t *rtp_session, void *data, uint32_t datalen, uint8_t m, switch_payload_t payload, uint32_t ts, switch_frame_flag_t *flags)
Write data with a specified payload and sequence number to a given RTP session.
struct switch_crypto_key_material_s * remote_key_material_next