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 227 unsigned char out_digit_packet[4];
263 char last_sent_id[13];
273 #define MAX_DTLS_MTU 4096 357 srtp_ctx_t *send_ctx[2];
358 srtp_ctx_t *recv_ctx[2];
360 srtp_policy_t send_policy[2];
361 srtp_policy_t recv_policy[2];
363 uint32_t srtp_errs[2];
364 uint32_t srctp_errs[2];
541 static void do_2833(switch_rtp_t *rtp_session);
544 #define rtp_type(rtp_session) rtp_session->flags[SWITCH_RTP_FLAG_TEXT] ? "text" : (rtp_session->flags[SWITCH_RTP_FLAG_VIDEO] ? "video" : "audio") 549 int is_rtcp = ice == &rtp_session->
rtcp_ice;
550 const char *err =
"";
552 uint8_t ice_cand_found_idx = 0;
556 ice_cand_found_idx = i;
560 if (!ice_cand_found_idx) {
626 unsigned char *packet = (
unsigned char *)
RTP_BODY(rtp_session);
630 uint16_t in_digit_seq;
635 if (!(packet[0] || packet[1] || packet[2] || packet[3]) && len >= 8) {
640 if (!(packet[0] || packet[1] || packet[2] || packet[3]) && rtp_session->
dtmf_data.
in_digit_ts) {
649 end = packet[1] & 0x80 ? 1 : 0;
650 duration = (packet[2] << 8) + packet[3];
652 in_digit_seq = ntohs((uint16_t) rtp_session->
last_rtp_hdr.seq);
666 if (in_digit_seq < rtp_session->dtmf_data.in_digit_seq) {
672 if (!(packet[0] || packet[1] || packet[2] || packet[3]) && len >= 8) {
817 static int rtp_write_ready(switch_rtp_t *rtp_session, uint32_t bytes,
int line);
823 #define MEDIA_TOO_LONG 2000 824 #define STUN_TOO_LONG 20000 825 #define ADJ_TOO_LONG 1000 840 if (!ref_point) ref_point = now;
842 rtp_session->
elapsed_stun = (
unsigned int) ((now - ref_point) / 1000);
859 uint8_t
buf[256] = { 0 };
861 unsigned int elapsed;
895 if (elapsed > 30000) {
949 if (strchr(them,
':')) {
962 unsigned char buf[1500] = { 0 };
966 uint32_t *pri = NULL;
967 int is_rtcp = ice == &rtp_session->
rtcp_ice;
971 const char *from_host = NULL;
973 char faddr_buf[80] =
"";
999 if (cpylen >
sizeof(buf)) {
1000 cpylen =
sizeof(
buf);
1005 memcpy(buf, data, cpylen);
1030 switch (attr->
type) {
1045 uint32_t code = (err->
code * 100) + err->
number;
1091 uint32_t priority = 0;
1092 pri = (uint32_t *) attr->
value;
1093 priority = ntohl(*pri);
1105 }
while (xlen <= packet->header.length);
1108 ok = !strcmp(ice->
user_ice, username);
1155 if (!
zstr(username)) {
1156 if (!
icecmp(username, ice)) {
1175 const char *old_host, *err = NULL;
1191 for (j = 0; j < 2; j++) {
1192 if (!icep[j] || !icep[j]->ice_params) {
1196 if (icep[j]->ice_params && icep[j]->ice_params->cands[i][icep[j]->
proto].priority == *pri) {
1217 if (!host || !port) {
1223 "%s ICE Auto Changing port from %s:%u to %s:%u\n",
rtp_type(rtp_session), old_host, old, host, port);
1273 const char *host2 = NULL;
1278 uint8_t stunbuf[512];
1280 const char *remote_ip;
1287 int cur_idx = -1, is_relay = 0, is_responsive = 0, use_candidate = 0;
1297 memset(stunbuf, 0,
sizeof(stunbuf));
1336 "%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",
1337 is_relay, is_responsive, use_candidate, ice->
ready, ice->
rready);
1368 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,
1383 }
else if (!do_adj) {
1384 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));
1441 "Auto Changing %s stun/%s/dtls port from %s:%u to %s:%u idx:%d\n",
rtp_type(rtp_session), is_rtcp ?
"rtcp" :
"rtp",
1443 from_host, from_port, cur_idx);
1471 msg.
from = __FILE__;
1477 "STUN/ICE binding error received on %s channel\n",
rtp_type(rtp_session));
1493 SWITCH_DECLARE(
void) switch_srtp_err_to_txt(srtp_err_status_t stat,
char **msg)
1495 if (stat == srtp_err_status_replay_fail) *msg=
"replay check failed";
1496 else if (stat == srtp_err_status_auth_fail) *msg=
"auth check failed";
1497 else if (stat == srtp_err_status_fail) *msg=
"unspecified failure";
1498 else if (stat == srtp_err_status_bad_param) *msg=
"unsupported parameter";
1499 else if (stat == srtp_err_status_alloc_fail) *msg=
"couldn't allocate memory";
1500 else if (stat == srtp_err_status_dealloc_fail) *msg=
"couldn't deallocate properly";
1501 else if (stat == srtp_err_status_init_fail) *msg=
"couldn't initialize";
1502 else if (stat == srtp_err_status_terminus) *msg=
"can't process as much data as requested";
1503 else if (stat == srtp_err_status_cipher_fail) *msg=
"cipher failure";
1504 else if (stat == srtp_err_status_replay_old) *msg=
"replay check failed";
1505 else if (stat == srtp_err_status_algo_fail) *msg=
"algorithm failed test routine";
1506 else if (stat == srtp_err_status_no_such_op) *msg=
"unsupported operation";
1507 else if (stat == srtp_err_status_no_ctx) *msg=
"no appropriate context found";
1508 else if (stat == srtp_err_status_cant_check) *msg=
"auth check failed";
1509 else if (stat == srtp_err_status_key_expired) *msg=
"can't use key any more";
1510 else if (stat == srtp_err_status_socket_err) *msg=
"error in use of socket";
1511 else if (stat == srtp_err_status_signal_err) *msg=
"error in use POSIX signals";
1512 else if (stat == srtp_err_status_nonce_bad) *msg=
"nonce check failed";
1513 else if (stat == srtp_err_status_read_fail) *msg=
"couldn't read data";
1514 else if (stat == srtp_err_status_write_fail) *msg=
"couldn't write data";
1515 else if (stat == srtp_err_status_parse_err) *msg=
"error parsing data";
1516 else if (stat == srtp_err_status_encode_err) *msg=
"error encoding data";
1517 else if (stat == srtp_err_status_semaphore_err) *msg=
"error while using semaphores";
1518 else if (stat == srtp_err_status_pfkey_err) *msg=
"error while using pfkey ";
1519 else if (stat == srtp_err_status_bad_mki) *msg=
"error MKI present in packet is invalid";
1520 else if (stat == srtp_err_status_pkt_idx_old) *msg=
"packet index is too old to consider";
1521 else if (stat == srtp_err_status_pkt_idx_adv) *msg=
"packet index advanced, reset needed";
1534 srtp_err_status_t stat = srtp_init();
1535 if (stat == srtp_err_status_ok) {
1549 uint8_t m = 0, changed = 0;
1553 rtp_session->
ts = (uint32_t) timestamp;
1575 static void do_mos(switch_rtp_t *rtp_session) {
1606 if (R < 0 || R > 100) R = 100;
1609 rtp_session->
stats.
inbound.
mos = 1 + (0.035) * R + (.000007) * R * (R-60) * (100-R);
1632 lost += i * loss[i];
1635 if (received > 0 && bursts > 0) {
1636 *burstr = (double)((
double)lost / (double)bursts) / (double)(1.0 / ( 1.0 - (
double)lost / (double)received ));
1638 *burstr = - *burstr;
1644 *lossr = (double)((
double)lost / (double)received);
1662 int64_t diff_time = 0, cur_diff = 0;
1678 seq = (int)(uint16_t) ntohs((uint16_t) rtp_session->
last_rtp_hdr.seq);
1751 if ( diff_time < 0 ) {
1752 diff_time = -diff_time;
1802 uint32_t sec, ntp_sec, ntp_usec;
1805 sec = (uint32_t)(now/1000000);
1808 ntp_usec = (uint32_t)(now - (sec*1000000));
1809 sr->
ntp_lsw = htonl((u_long)(ntp_usec*(
double)(((uint64_t)1)<<32)*1.0e-6));
1818 (ntohl(sr->
ntp_lsw)&0xffff0000)>>16 | (ntohl(sr->
ntp_msw)&0x0000ffff)<<16,
1826 uint32_t ntp_sec, ntp_usec, lsr_now, sec;
1828 sec = (uint32_t)(now/1000000);
1832 lsr_now = (uint32_t)(ntp_usec*0.065536) | (ntp_sec&0x0000ffff)<<16;
1840 int16_t extra_expected)
1846 uint32_t expected_pkt,
dlsr = 0;
1857 if (pkt_lost < 0) pkt_lost = 0;
1860 if (expected_pkt > 0 && pkt_lost > 0) {
1861 rtcp_report_block->
fraction = (pkt_lost == expected_pkt ? 255 : (uint8_t) (pkt_lost * 256 / expected_pkt));
1865 #if SWITCH_BYTE_ORDER == __BIG_ENDIAN 1894 rtcp_report_block->
dlsr = htonl(dlsr);
1910 stats->
ssrc = ntohl(hdr->ssrc);
1919 stats->
base_seq = ntohs((uint16_t)hdr->seq);
1961 uint32_t packet_spacing_diff = 0, pkt_tsdiff, pkt_extended_seq;
1962 uint16_t pkt_seq, seq_diff, max_seq;
1963 const int MAX_DROPOUT = 3000;
1964 const int MAX_MISORDER = 100;
1965 const int RTP_SEQ_MOD = (1<<16);
1970 pkt_seq = (uint16_t) ntohs((uint16_t) rtp_session->
last_rtp_hdr.seq);
1974 seq_diff = pkt_seq - max_seq;
1976 if (seq_diff < MAX_DROPOUT) {
1977 if (pkt_seq < max_seq) {
1982 pkt_extended_seq = stats->
cycle << 16 | pkt_seq;
1987 else if (seq_diff <= (RTP_SEQ_MOD - MAX_MISORDER)) {
1988 if (pkt_seq == stats->
bad_seq) {
1991 stats->
bad_seq = (pkt_seq + 1) & (RTP_SEQ_MOD-1);
1999 if (ntohl(hdr->ssrc) != stats->
ssrc || !stats->
init) {
2010 pkt_tsdiff = abs((int32_t)(rtp_session->
timer.
samplecount - ntohl(hdr->ts)));
2015 packet_spacing_diff = abs((int32_t)(pkt_tsdiff - stats->
last_pkt_tsdiff));
2030 uint32_t mantissa_max, i = 0;
2032 uint32_t mantissa = 0;
2033 uint16_t overhead = 60;
2037 mantissa_max = (1 << bits) - 1;
2039 for (i = 0; i < 32; ++i) {
2040 if (bps <= (mantissa_max << i)) {
2046 mantissa = (bps >> exp);
2048 tmmbx->
parts[0] = (uint8_t) ((exp << 2) + ((mantissa >> 15) & 0x03));
2049 tmmbx->
parts[1] = (uint8_t) (mantissa >> 7);
2050 tmmbx->
parts[2] = (uint8_t) ((mantissa >> 1) + ((overhead >> 8) & 0x01));
2051 tmmbx->
parts[3] = (uint8_t) (overhead);
2065 if (sr && rtcp_report_block) {
2077 snprintf(value,
sizeof(value),
"%.8x", rtp_session->
stats.
rtcp.
ssrc);
2086 snprintf(value,
sizeof(value),
"%u", ntohl(sr->
sender_info.
ts));
2089 snprintf(value,
sizeof(value),
"%u", ntohl(sr->
sender_info.
pc));
2092 snprintf(value,
sizeof(value),
"%u", ntohl(sr->
sender_info.
oc));
2095 snprintf(value,
sizeof(value),
"%u", ntohl(sr->
sender_info.
ts));
2102 snprintf(header,
sizeof(header),
"Source-SSRC");
2105 snprintf(header,
sizeof(header),
"Source-Fraction");
2106 snprintf(value,
sizeof(value),
"%u", (uint8_t)rtcp_report_block->
fraction);
2108 snprintf(header,
sizeof(header),
"Source-Lost");
2109 #if SWITCH_BYTE_ORDER == __BIG_ENDIAN 2110 tmpLost = rtcp_report_block->
lost;
2112 tmpLost = ntohl(rtcp_report_block->
lost)>>8;
2113 tmpLost = tmpLost | ((tmpLost & 0x00800000) ? 0xff000000 : 0x00000000);
2115 snprintf(value,
sizeof(value),
"%u", tmpLost);
2117 snprintf(header,
sizeof(header),
"Source-Highest-Sequence-Number-Received");
2120 snprintf(header,
sizeof(header),
"Source-Jitter");
2121 snprintf(value,
sizeof(value),
"%u", ntohl(rtcp_report_block->
jitter));
2123 snprintf(header,
sizeof(header),
"Source-LSR");
2124 snprintf(value,
sizeof(value),
"%u", ntohl(rtcp_report_block->
lsr));
2126 snprintf(header,
sizeof(header),
"Source-DLSR");
2127 snprintf(value,
sizeof(value),
"%u", ntohl(rtcp_report_block->
dlsr));
2140 int rtcp_ok = 0, rtcp_cyclic = 0, rtcp_fb = 0, force_send_rr = 0;
2142 int rate = 0, nack_ttl = 0, nack_dup = 0;
2143 uint32_t cur_nack[
MAX_NACK] = { 0 };
2151 uint8_t data[10] = { 0 };
2175 seq = ntohs(nack & 0xFFFF);
2180 cur_nack[nack_ttl++] = nack;
2214 if (rtcp_ok &&
using_ice(rtp_session)) {
2247 rtp_session->
vb && rtcp_cyclic) {
2257 is_only_receiver =
TRUE;
2262 rr->
ssrc = htonl(rtp_session->
ssrc);
2272 sr->
ssrc = htonl(rtp_session->
ssrc);
2276 if (!rtcp_cyclic && rtcp_fb) {
2322 for (n = 0; n < nack_ttl; n++) {
2334 ext_hdr->
length = htons(3);
2336 nack = (uint32_t *) p;
2337 *nack = cur_nack[n];
2378 fir->
r1 = fir->
r2 = fir->
r3 = 0;
2394 while (rtp_session->
tmmbr || rtp_session->
tmmbn) {
2410 if (rtp_session->
tmmbr) {
2413 bps = rtp_session->
tmmbr;
2414 rtp_session->
tmmbr = 0;
2418 bps = rtp_session->
tmmbn;
2419 rtp_session->
tmmbn = 0;
2434 sdes = &sdes_ssrc->
header;
2439 sdes_ssrc->
ssrc = htonl(rtp_session->
ssrc);
2440 sdes_bytes +=
sizeof(uint32_t);
2443 p = (uint8_t *) (sdes) + sdes_bytes;
2446 snprintf((
char *)unit->
value, 80,
"%x", rtp_session->
ssrc);
2454 snprintf((
char *)unit->
value, 80,
"FreeSWITCH.org -- Come to ClueCon.com");
2460 sdes_bytes += 4 - (sdes_bytes % 4);
2462 sdes->length = htons((uint16_t)(sdes_bytes / 4) - 1);
2463 rtcp_bytes += sdes_bytes;
2479 int sbytes = (int) rtcp_bytes;
2492 rtcp_bytes = sbytes;
2501 const char *old_host;
2548 RAND_bytes(buf, len);
2580 srtp_crypto_kernel_shutdown();
2657 rtp_session->
pmaps = pmap;
2670 rtp_session->
seq = 0;
2684 *err =
"RTCP Remote Address Error!";
2708 *err =
"RTCP Socket Error!";
2713 *err =
"RTCP NOT ACTIVE!";
2730 *err =
"RTCP Local Address Error!";
2735 *err =
"RTCP Socket Error!";
2740 *err =
"RTCP Socket Error!";
2745 *err =
"RTCP Bind Error!";
2751 *err =
"RTCP From Address Error!";
2757 rtcp_new_sock = NULL;
2769 if (rtcp_new_sock) {
2773 if (rtcp_old_sock) {
2789 char o[5] =
"TEST", i[5] =
"";
2794 if (rtp_session->
ready != 1) {
2810 if (
zstr(host) || !port) {
2811 *err =
"Address Error";
2821 *err =
"Local Address Error!";
2831 *err =
"Socket Error!";
2836 *err =
"Socket Error!";
2855 if ((j = atoi(host)) && j > 223 && j < 240) {
2857 *err =
"Multicast Socket interface Error";
2862 *err =
"Multicast Error";
2871 int ttl = atoi(var);
2873 if (ttl > 0 && ttl < 256) {
2875 *err =
"Mutlicast TTL set failed";
2946 if (rtp_session->
ready != 1) {
2975 "new max missed packets(%d->%d) greater than current missed packets(%d). RTP will timeout.\n",
2985 if (rtp_session->
jb) {
2994 if (rtp_session->
vb) {
2998 if (rtp_session->
vbw) {
3049 uint32_t o = UINT_MAX;
3136 *err =
"Remote Address Error!";
3145 if (change_adv_addr) {
3163 *err =
"Socket Error!";
3167 if (rtp_session->
dtls) {
3209 return dtls_state_names_t[s];
3212 #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 3214 #define cr_keylen 16 3215 #define cr_saltlen 14 3224 uint8_t raw_key_data[
cr_kslen * 2];
3225 unsigned char local_key_buf[
cr_kslen];
3226 unsigned char remote_key_buf[
cr_kslen];
3228 memset(&ssec, 0,
sizeof(ssec));
3235 }
else if ((cert = SSL_get_peer_certificate(dtls->
ssl))) {
3246 unsigned char *local_key, *remote_key, *local_salt, *remote_salt;
3250 #ifdef HAVE_OPENSSL_DTLS_SRTP 3251 if (!SSL_export_keying_material(dtls->
ssl, raw_key_data,
sizeof(raw_key_data),
"EXTRACTOR-dtls_srtp", 19, NULL, 0, 0)) {
3261 local_key = raw_key_data;
3267 remote_key = raw_key_data;
3327 if ((ret = SSL_do_handshake(dtls->
ssl)) != 1){
3328 switch((ret = SSL_get_error(dtls->
ssl, ret))){
3329 case SSL_ERROR_WANT_READ:
3330 case SSL_ERROR_WANT_WRITE:
3331 case SSL_ERROR_NONE:
3340 if (SSL_is_init_finished(dtls->
ssl)) {
3359 SSL_free(dtls->
ssl);
3369 int r = 0, ret = 0, len;
3372 uint8_t is_ice = rtp_session->
ice.
ice_user ? 1 : 0;
3380 if (!dtls->
bytes && !ready) {
3391 char tmp_buf1[80] =
"";
3392 char tmp_buf2[80] =
"";
3404 ret = SSL_get_error(dtls->
ssl, ret);
3406 }
else if (ret != (
int)dtls->
bytes) {
3411 if (dtls_states[dtls->
state]) {
3412 r = dtls_states[dtls->
state](rtp_session, dtls);
3415 while ((pending = BIO_ctrl_pending(dtls->
filter_bio)) > 0) {
3418 len = BIO_read(dtls->
write_bio, buf, pending);
3425 }
else if (bytes != len) {
3429 ret = SSL_get_error(dtls->
ssl, len);
3438 static int cb_verify_peer(
int preverify_ok, X509_STORE_CTX *ctx)
3445 ssl = X509_STORE_CTX_get_app_data(ctx);
3448 if (!(ssl && dtls)) {
3452 if ((cert = SSL_get_peer_certificate(dtls->
ssl))) {
3469 #if OPENSSL_VERSION_NUMBER < 0x10100000L 3476 #if OPENSSL_VERSION_NUMBER < 0x10100000L 3477 return(&dtls_bio_filter_methods);
3479 return(dtls_bio_filter_methods);
3513 #if OPENSSL_VERSION_NUMBER < 0x10100000L 3518 BIO_set_init(bio, 1);
3519 BIO_set_data(bio, filter);
3520 BIO_clear_flags(bio, ~0);
3534 #if OPENSSL_VERSION_NUMBER < 0x10100000L 3540 if (filter != NULL) {
3547 #if OPENSSL_VERSION_NUMBER < 0x10100000L 3552 BIO_set_init(bio, 0);
3553 BIO_set_data(bio, NULL);
3554 BIO_clear_flags(bio, ~0);
3565 #if OPENSSL_VERSION_NUMBER < 0x10100000L 3566 ret = BIO_write(bio->next_bio, in, inl);
3568 ret = BIO_write(BIO_next(bio), in, inl);
3574 #if OPENSSL_VERSION_NUMBER < 0x10100000L 3580 if (filter != NULL) {
3600 filter->
tail = node;
3609 #if OPENSSL_VERSION_NUMBER < 0x10100000L 3616 case BIO_CTRL_DGRAM_GET_FALLBACK_MTU:
3618 case BIO_CTRL_DGRAM_SET_MTU:
3622 case BIO_CTRL_FLUSH:
3624 case BIO_CTRL_DGRAM_QUERY_MTU:
3627 case BIO_CTRL_WPENDING:
3629 case BIO_CTRL_PENDING: {
3633 if (filter == NULL) {
3638 if ((top = filter->
packets)) {
3642 filter->
tail = NULL;
3645 pending = top->
size;
3660 #if OPENSSL_VERSION_NUMBER < 0x10100000L 3661 static BIO_METHOD dtls_bio_filter_methods = {
3674 static BIO_METHOD *dtls_bio_filter_methods = NULL;
3678 #if OPENSSL_VERSION_NUMBER >= 0x10100000L 3679 dtls_bio_filter_methods = BIO_meth_new(BIO_TYPE_FILTER | BIO_get_new_index(),
"DTLS filter");
3688 #if OPENSSL_VERSION_NUMBER >= 0x10100000L 3689 if (dtls_bio_filter_methods) {
3690 BIO_meth_free(dtls_bio_filter_methods);
3691 dtls_bio_filter_methods = NULL;
3701 #ifdef HAVE_OPENSSL_DTLS_SRTP 3758 if (rtp_session->
dtls) {
3762 if (rtp_session->
jb) {
3766 if (rtp_session->
vb) {
3770 if (rtp_session->
vbw) {
3787 for(x = 0; x < 2; x++) {
3789 srtp_dealloc(rtp_session->
send_ctx[x]);
3800 for (x = 0; x < 2; x++) {
3802 srtp_dealloc(rtp_session->
recv_ctx[x]);
3821 const char *kind =
"";
3822 unsigned long ssl_method_error = 0;
3823 unsigned long ssl_ctx_error = 0;
3826 #if OPENSSL_VERSION_NUMBER < 0x30000000 3831 #ifndef OPENSSL_NO_EC 3832 #if OPENSSL_VERSION_NUMBER < 0x10002000L 3837 #ifndef HAVE_OPENSSL_DTLS_SRTP 3853 if ((type & DTLS_TYPE_RTP) && (type & DTLS_TYPE_RTCP)) {
3855 }
else if ((type & DTLS_TYPE_RTP)) {
3862 "Activate %s %s DTLS %s\n", kind,
rtp_type(rtp_session), (type & DTLS_TYPE_SERVER) ?
"server" :
"client");
3864 if (((type & DTLS_TYPE_RTP) && rtp_session->
dtls) || ((type & DTLS_TYPE_RTCP) && rtp_session->
rtcp_dtls)) {
3882 #if OPENSSL_VERSION_NUMBER >= 0x10100000 3883 ssl_method = (type &
DTLS_TYPE_SERVER) ? DTLS_server_method() : DTLS_client_method();
3885 #ifdef HAVE_OPENSSL_DTLSv1_2_method 3886 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());
3888 ssl_method = (type &
DTLS_TYPE_SERVER) ? DTLSv1_server_method() : DTLSv1_client_method();
3889 #endif // HAVE_OPENSSL_DTLSv1_2_method 3893 ssl_method_error = ERR_peek_error();
3897 dtls->
ssl_ctx = ssl_ctx = SSL_CTX_new(ssl_method);
3900 ssl_ctx_error = ERR_peek_error();
3908 #if OPENSSL_VERSION_NUMBER < 0x30000000 3909 bio = BIO_new_file(dtls->
pem,
"r");
3910 dh = PEM_read_bio_DHparams(bio, NULL, NULL, NULL);
3913 SSL_CTX_set_tmp_dh(dtls->
ssl_ctx, dh);
3917 if(!SSL_CTX_set_dh_auto(dtls->
ssl_ctx, 1)) {
3921 SSL_CTX_set_mode(dtls->
ssl_ctx, SSL_MODE_AUTO_RETRY);
3924 SSL_CTX_set_verify(dtls->
ssl_ctx, SSL_VERIFY_NONE, NULL);
3928 SSL_CTX_set_cipher_list(dtls->
ssl_ctx,
"ALL:!ADH:!LOW:!EXP:!MD5:@STRENGTH");
3930 SSL_CTX_set_read_ahead(dtls->
ssl_ctx, 1);
3931 #ifdef HAVE_OPENSSL_DTLS_SRTP 3933 SSL_CTX_set_tlsext_use_srtp(dtls->
ssl_ctx,
"SRTP_AES128_CM_SHA1_80");
3937 dtls->
read_bio = BIO_new(BIO_s_mem());
3943 BIO_set_mem_eof_return(dtls->
read_bio, -1);
3944 BIO_set_mem_eof_return(dtls->
write_bio, -1);
3946 if ((ret=SSL_CTX_use_certificate_file(dtls->
ssl_ctx, dtls->
rsa, SSL_FILETYPE_PEM)) != 1) {
3951 if ((ret=SSL_CTX_use_PrivateKey_file(dtls->
ssl_ctx, dtls->
pvt, SSL_FILETYPE_PEM)) != 1) {
3956 if (SSL_CTX_check_private_key(dtls->
ssl_ctx) == 0) {
3962 && (ret = SSL_CTX_load_verify_locations(dtls->
ssl_ctx, dtls->
ca, NULL)) != 1) {
3965 SSL_get_error(dtls->
ssl, ret));
3971 #if OPENSSL_VERSION_NUMBER < 0x10100000L 3975 dtls->
filter_bio = BIO_new(dtls_bio_filter_methods);
3984 SSL_set_mode(dtls->
ssl, SSL_MODE_AUTO_RETRY);
3985 SSL_set_read_ahead(dtls->
ssl, 1);
3990 #ifndef OPENSSL_NO_EC 3991 #if OPENSSL_VERSION_NUMBER < 0x10002000L 3992 ecdh = EC_KEY_new_by_curve_name(NID_X9_62_prime256v1);
3996 SSL_set_options(dtls->
ssl, SSL_OP_SINGLE_ECDH_USE);
3997 SSL_set_tmp_ecdh(dtls->
ssl, ecdh);
3999 #elif OPENSSL_VERSION_NUMBER < 0x10100000L 4000 SSL_set_ecdh_auto(dtls->
ssl, 1);
4001 SSL_set_options(dtls->
ssl, SSL_OP_SINGLE_ECDH_USE);
4005 SSL_set_verify(dtls->
ssl, SSL_VERIFY_NONE, NULL);
4006 SSL_set_app_data(dtls->
ssl, dtls);
4016 int mtu = atoi(var);
4025 BIO_ctrl(dtls->
filter_bio, BIO_CTRL_DGRAM_SET_MTU, dtls->
mtu, NULL);
4029 if ((type & DTLS_TYPE_RTP)) {
4030 rtp_session->
dtls = dtls;
4035 if ((type & DTLS_TYPE_RTCP)) {
4037 if (!(type & DTLS_TYPE_RTP)) {
4043 if ((type & DTLS_TYPE_SERVER)) {
4044 SSL_set_accept_state(dtls->
ssl);
4046 SSL_set_connect_state(dtls->
ssl);
4070 srtp_policy_t *policy;
4071 srtp_err_status_t stat;
4078 unsigned char b64_key[512] =
"";
4080 unsigned char *keysalt = NULL;
4084 unsigned long *key_material_n = NULL;
4085 srtp_master_key_t **mkis = NULL;
4086 srtp_master_key_t *mki = NULL;
4159 memcpy(crypto_key->
keysalt, keysalt, keysalt_len);
4163 memset(policy, 0,
sizeof(*policy));
4173 switch (crypto_key->
type) {
4175 srtp_crypto_policy_set_aes_cm_128_hmac_sha1_80(&policy->rtp);
4176 srtp_crypto_policy_set_aes_cm_128_hmac_sha1_80(&policy->rtcp);
4183 srtp_crypto_policy_set_aes_cm_128_hmac_sha1_32(&policy->rtp);
4184 srtp_crypto_policy_set_aes_cm_128_hmac_sha1_32(&policy->rtcp);
4193 srtp_crypto_policy_set_aes_gcm_256_8_auth(&policy->rtp);
4194 srtp_crypto_policy_set_aes_gcm_256_8_auth(&policy->rtcp);
4202 srtp_crypto_policy_set_aes_gcm_256_16_auth(&policy->rtp);
4203 srtp_crypto_policy_set_aes_gcm_256_16_auth(&policy->rtcp);
4211 srtp_crypto_policy_set_aes_gcm_128_8_auth(&policy->rtp);
4212 srtp_crypto_policy_set_aes_gcm_128_8_auth(&policy->rtcp);
4220 srtp_crypto_policy_set_aes_gcm_128_16_auth(&policy->rtp);
4221 srtp_crypto_policy_set_aes_gcm_128_16_auth(&policy->rtcp);
4229 srtp_crypto_policy_set_aes_cm_256_hmac_sha1_80(&policy->rtp);
4230 srtp_crypto_policy_set_aes_cm_256_hmac_sha1_80(&policy->rtcp);
4236 srtp_crypto_policy_set_aes_cm_256_hmac_sha1_32(&policy->rtp);
4237 srtp_crypto_policy_set_aes_cm_256_hmac_sha1_32(&policy->rtcp);
4243 srtp_crypto_policy_set_aes_cm_192_hmac_sha1_80(&policy->rtp);
4244 srtp_crypto_policy_set_aes_cm_192_hmac_sha1_80(&policy->rtcp);
4250 srtp_crypto_policy_set_aes_cm_192_hmac_sha1_32(&policy->rtp);
4251 srtp_crypto_policy_set_aes_cm_192_hmac_sha1_32(&policy->rtcp);
4257 srtp_crypto_policy_set_aes_cm_128_null_auth(&policy->rtp);
4258 srtp_crypto_policy_set_aes_cm_128_null_auth(&policy->rtcp);
4270 if (key_material && (*key_material_n > 0)) {
4290 while (key_material && (mki_idx < *key_material_n)) {
4313 memcpy(mki->mki_id, &key_material->
mki_id, key_material->
mki_size);
4314 mki->mki_size = key_material->
mki_size;
4315 memcpy(mki->key, key_material->
raw_key, keysalt_len);
4317 mkis[mki_idx] = mki;
4319 key_material = key_material->
next;
4324 policy->keys = mkis;
4325 policy->num_master_keys = mki_idx;
4328 policy->key = (uint8_t *) crypto_key->
keysalt;
4331 policy->next = NULL;
4333 policy->window_size = 1024;
4334 policy->allow_repeat_tx = 1;
4339 switch (direction) {
4341 policy->ssrc.type = ssrc_any_inbound;
4346 if ((stat = srtp_create(&rtp_session->
recv_ctx[idx], policy)) || !rtp_session->
recv_ctx[idx]) {
4361 policy->ssrc.type = ssrc_any_outbound;
4368 if ((stat = srtp_create(&rtp_session->
send_ctx[idx], policy)) || !rtp_session->
send_ctx[idx]) {
4389 if (rtp_session->
dtls) {
4420 int change_timer = 0;
4428 if (change_timer && rtp_session->
timer_name) {
4441 rtp_session->
timer_name, ms_per_packet / 1000,
4445 "RE-Starting timer [%s] %d bytes per %dms\n", rtp_session->
timer_name, samples_per_interval, ms_per_packet / 1000);
4451 "Problem RE-Starting timer [%s] %d bytes per %dms\n", rtp_session->
timer_name, samples_per_interval, ms_per_packet / 1000);
4478 uint32_t samples_per_interval,
4479 uint32_t ms_per_packet,
4482 switch_rtp_t *rtp_session = NULL;
4488 *new_rtp_session = NULL;
4491 *err =
"Packet Size Too Large!";
4496 *err =
"Memory Error!";
4504 rtp_session->
session = session;
4526 #ifdef DEBUG_TS_ROLLOVER 4550 rtp_session->
payload = payload;
4557 timer_name =
"soft";
4560 if (!
zstr(timer_name) && !strcasecmp(timer_name,
"none")) {
4564 if (!
zstr(timer_name)) {
4571 "Starting timer [%s] %d bytes per %dms\n", timer_name, samples_per_interval, ms_per_packet / 1000);
4573 #ifdef DEBUG_TS_ROLLOVER 4574 rtp_session->
timer.
tick = TS_ROLLOVER_START / samples_per_interval;
4579 "Error Starting timer [%s] %d bytes per %dms, async RTP disabled\n", timer_name, samples_per_interval, ms_per_packet / 1000);
4620 rtp_session->
ready = 1;
4621 *new_rtp_session = rtp_session;
4628 const char *tx_host,
4631 uint32_t samples_per_interval,
4632 uint32_t ms_per_packet,
4637 switch_rtp_t *rtp_session = NULL;
4639 if (
zstr(rx_host)) {
4640 *err =
"Missing local host";
4645 *err =
"Missing local port";
4649 if (
zstr(tx_host)) {
4650 *err =
"Missing remote host";
4655 *err =
"Missing remote port";
4681 rtp_session->
ready = 2;
4683 rtp_session->
rx_port = rx_port;
4696 rtp_session->
te = te;
4711 rtp_session->
cng_pt = pt;
4722 return &rtp_session->
timer;
4735 return rtp_session->
jb ? rtp_session->
jb : rtp_session->
vb;
4742 if (rtp_session->
pause_jb && !pause) {
4743 if (rtp_session->
jb) {
4747 if (rtp_session->
vb) {
4752 new_val = pause ? 1 : -1;
4754 if (rtp_session->
pause_jb + new_val > -1) {
4759 "Jitterbuffer %s is %s\n",
rtp_type(rtp_session), rtp_session->
pause_jb ?
"paused" :
"enabled");
4779 if (rtp_session->
vb) {
4780 return switch_jb_get_frames(rtp_session->
vb, min_frame_len, max_frame_len, cur_frame_len, highest_frame_len);
4796 if (!max_frames || frames >= max_frames) {
4797 max_frames = frames * 10;
4802 if (!rtp_session->
vb) {
4825 if (name) x = atoi(name);
4828 if (rtp_session->
jb) {
4830 }
else if (rtp_session->
vb) {
4838 uint32_t queue_frames,
4839 uint32_t max_queue_frames,
4840 uint32_t samples_per_packet,
4841 uint32_t samples_per_second)
4849 if (queue_frames < 1) {
4853 if (max_queue_frames < queue_frames) {
4854 max_queue_frames = queue_frames * 3;
4859 if (rtp_session->
jb) {
4880 const char *err = NULL;
4897 if (send_rate == -1) {
4934 const char *password,
const char *rpassword,
ice_proto_t proto,
4949 ice = &rtp_session->
ice;
5011 proto ==
IPR_RTP ?
"RTP" :
"RTCP",
rtp_type(rtp_session), ice_user, host, port);
5043 rtp_session->
tmmbr = bps;
5054 rtp_session->
tmmbn = bps;
5095 }
else if (rtp_session->
session) {
5160 && rtp_session->
ready == 2) ? 1 : 0;
5197 if (!rtp_session || !*rtp_session || !(*rtp_session)->
ready) {
5201 if ((*rtp_session)->vb) {
5205 "NACK: Added to JB: [%u]\n", nack_jb_ok);
5213 (*rtp_session)->ready = 0;
5234 if ((*rtp_session)->jb) {
5238 if ((*rtp_session)->vb) {
5242 if ((*rtp_session)->vbw) {
5246 if ((*rtp_session)->dtls && (*rtp_session)->dtls == (*rtp_session)->rtcp_dtls) {
5247 (*rtp_session)->rtcp_dtls = NULL;
5250 if ((*rtp_session)->dtls) {
5254 if ((*rtp_session)->rtcp_dtls) {
5258 if ((*rtp_session)->rtcp_sock_input == (*rtp_session)->sock_input) {
5259 (*rtp_session)->rtcp_sock_input = NULL;
5262 if ((*rtp_session)->rtcp_sock_output == (*rtp_session)->sock_output) {
5263 (*rtp_session)->rtcp_sock_output = NULL;
5266 sock = (*rtp_session)->sock_input;
5267 (*rtp_session)->sock_input = NULL;
5270 if ((*rtp_session)->sock_output != sock) {
5271 sock = (*rtp_session)->sock_output;
5272 (*rtp_session)->sock_output = NULL;
5276 if ((sock = (*rtp_session)->rtcp_sock_input)) {
5277 (*rtp_session)->rtcp_sock_input = NULL;
5281 if ((*rtp_session)->rtcp_sock_output && (*rtp_session)->rtcp_sock_output != sock) {
5282 sock = (*rtp_session)->rtcp_sock_output;
5283 (*rtp_session)->rtcp_sock_output = NULL;
5289 for(x = 0; x < 2; x++) {
5290 if ((*rtp_session)->send_ctx[x]) {
5291 srtp_dealloc((*rtp_session)->send_ctx[x]);
5292 (*rtp_session)->send_ctx[x] = NULL;
5299 for (x = 0; x < 2; x++) {
5300 if ((*rtp_session)->recv_ctx[x]) {
5301 srtp_dealloc((*rtp_session)->recv_ctx[x]);
5302 (*rtp_session)->recv_ctx[x] = NULL;
5309 if ((*rtp_session)->timer.timer_interface) {
5313 if ((*rtp_session)->write_timer.timer_interface) {
5340 rtp_session->
payload = payload;
5377 int old_flag = rtp_session->
flags[flag];
5380 rtp_session->
flags[flag] = 1;
5409 if (xn > 0 && xn <= 65535) {
5420 if (rtp_session->
jb) {
5431 return (uint32_t) rtp_session->
flags[flags];
5436 int old_flag = rtp_session->
flags[flag];
5439 rtp_session->
flags[flag] = 0;
5457 int upsamp, max_upsamp;
5460 if (!max_ms) max_ms = ms;
5510 for (x = 0; x < loops; x++) {
5590 if (rdigit->
digit ==
'w') {
5596 if (rdigit->
digit ==
'W') {
5683 int was_blocking = 0;
5709 bytes_out = bytes_in;
5713 if (rtp_session->
vbw) {
5717 if (rtp_session->
vb) {
5719 bytes_out = bytes_in;
5773 }
while (bytes > 0);
5831 if (rtp_session->
pmaps && *rtp_session->
pmaps) {
5848 #define return_cng_frame() do_cng = 1; goto timer_check 5860 const char *tx_host;
5861 const char *old_host;
5862 const char *my_host;
5864 char bufa[50], bufb[50], bufc[50];
5872 "R %s b=%4ld %s:%u %s:%u %s:%u pt=%d ts=%u seq=%u m=%d\n",
5887 int sbytes = (int) *bytes;
5888 srtp_err_status_t stat = 0;
5934 switch_srtp_err_to_txt(stat, &msg);
5938 "SRTP %s unprotect failed with code %d (%s) %ld bytes %d errors\n",
5939 rtp_type(rtp_session), stat, msg, (
long)*bytes, errs);
5941 "Ending call due to SRTP error\n");
5945 "SRTP %s unprotect failed with code %d (%s) %ld bytes %d errors\n",
5946 rtp_type(rtp_session), stat, msg, (
long)*bytes, errs);
5960 if (!
jb_valid(rtp_bundle_session)) {
5964 if (rtp_bundle_session->
jb && !rtp_bundle_session->
pause_jb &&
jb_valid(rtp_bundle_session)) {
5978 unsigned char *
b = NULL;
5984 uint8_t audio_pt = 0;
5996 rtp_session->
punts++;
5997 rtp_session->
clean = 0;
6033 if (rtp_session->
dtls) {
6046 b = (
unsigned char *) &rtp_session->
recv_msg;
6055 if ((*b >= 20) && (*b <= 64)) {
6056 if (rtp_session->
dtls) {
6063 }
else if (*b == 0 || *b == 1) {
6108 int accept_packet = 1;
6143 if (!accept_packet) {
6145 "Invalid Packet SEQ: %d TS: %d PT:%d ignored\n",
6163 if (!rtp_session->
vb && (!rtp_session->
jb || rtp_session->
pause_jb || !
jb_valid(rtp_session))) {
6165 xcheck_jitter = *bytes;
6201 if (rtp_session->
dtls) {
6227 int sbytes = (int) *bytes;
6228 srtp_err_status_t stat = 0;
6262 const char *tx_host;
6263 const char *old_host;
6264 const char *my_host;
6266 char bufa[50], bufb[50], bufc[50];
6274 "R %s b=%4ld %s:%u %s:%u %s:%u pt=%d ts=%u seq=%u m=%d\n",
6285 #ifdef RTP_READ_PLOSS 6287 int r = (rand() % 10000) + 1;
6290 "Simulate dropped packet ......... ts: %u seq: %u\n", ntohl(rtp_session->
last_rtp_hdr.ts), ntohs(rtp_session->
last_rtp_hdr.seq));
6305 uint16_t seq = ntohs((uint16_t) rtp_session->
last_rtp_hdr.seq);
6308 #ifdef DEBUG_MISSED_SEQ 6314 if (num_missed == 1) {
6316 rtp_session->
last_seq+1, (flushed_packets_diff == 1) ?
" (flushed by FS)" :
" (missed)",
6319 if (flushed_packets_diff == 0) {
6321 "Missed %ld RTP frames from sequence [%d] to [%d] (missed). Time since last read [%ld]\n",
6322 num_missed, rtp_session->
last_seq+1, seq-1,
6324 }
else if (flushed_packets_diff == num_missed) {
6326 "Missed %ld RTP frames from sequence [%d] to [%d] (flushed by FS). Time since last read [%ld]\n",
6327 num_missed, rtp_session->
last_seq+1, seq-1,
6329 }
else if (num_missed > flushed_packets_diff) {
6331 "Missed %ld RTP frames from sequence [%d] to [%d] (%ld packets flushed by FS, %ld packets missed)." 6332 " Time since last read [%ld]\n",
6333 num_missed, rtp_session->
last_seq+1, seq-1,
6334 flushed_packets_diff, num_missed-flushed_packets_diff,
6338 "Missed %ld RTP frames from sequence [%d] to [%d] (%ld packets flushed by FS). Time since last read [%ld]\n",
6339 num_missed, rtp_session->
last_seq+1, seq-1,
6382 int sbytes = (int) *bytes;
6383 srtp_err_status_t stat = 0;
6429 switch_srtp_err_to_txt(stat, &msg);
6433 "SRTP %s unprotect failed with code %d (%s) %ld bytes %d errors\n",
6434 rtp_type(rtp_session), stat, msg, (
long)*bytes, errs);
6436 "Ending call due to SRTP error\n");
6440 "SRTP %s unprotect failed with code %d (%s) %ld bytes %d errors\n",
6441 rtp_type(rtp_session), stat, msg, (
long)*bytes, errs);
6471 if (*bytes > (length * 4 + 4)) {
6472 *bytes -= (length * 4 + 4);
6485 "VIDEO: seq: %d ts: %u len: %ld %02x %02x %02x %02x %02x %02x %02x %02x %02x %02x %02x mark: %d\n",
6487 *((uint8_t *)
RTP_BODY(rtp_session)), *((uint8_t *)
RTP_BODY(rtp_session) + 1),
6488 *((uint8_t *)
RTP_BODY(rtp_session) + 2), *((uint8_t *)
RTP_BODY(rtp_session) + 3),
6489 *((uint8_t *)
RTP_BODY(rtp_session) + 4), *((uint8_t *)
RTP_BODY(rtp_session) + 5),
6490 *((uint8_t *)
RTP_BODY(rtp_session) + 6), *((uint8_t *)
RTP_BODY(rtp_session) + 7),
6491 *((uint8_t *)
RTP_BODY(rtp_session) + 8), *((uint8_t *)
RTP_BODY(rtp_session) + 9),
6534 if (rtp_session->
jb) {
6538 if (rtp_session->
vb) {
6542 if (rtp_session->
vbw) {
6548 if (rtp_session->
has_rtp && *bytes) {
6549 uint32_t read_ssrc = ntohl(rtp_session->
last_rtp_hdr.ssrc);
6565 if (!return_jb_packet) {
6570 if (rtp_session->
jb &&
jb_valid(rtp_session)) {
6589 if (!return_jb_packet) {
6603 if (!*bytes || rtp_session->
has_rtp) {
6612 if (rtp_session->
punts < 4) {
6640 if (++rtp_session->
clean > 200) {
6641 rtp_session->
punts = 0;
6643 if (!xcheck_jitter) {
6682 if (!xcheck_jitter) {
6696 uint16_t seq = (uint16_t) (nack & 0xFFFF);
6697 uint16_t blp = (uint16_t) (nack >> 16);
6699 const char *tx_host = NULL;
6700 const char *old_host = NULL;
6701 const char *my_host = NULL;
6702 char bufa[50], bufb[50], bufc[50];
6721 "X %s b=%4ld %s:%u %s:%u %s:%u pt=%d ts=%u seq=%u m=%d\n",
6737 for (i = 0; i < 16; i++) {
6738 if (blp & (1 << i)) {
6746 "X %s b=%4ld %s:%u %s:%u %s:%u pt=%d ts=%u seq=%u m=%d\n",
6807 uint32_t *nack = (uint32_t *) extp->
body;
6831 uint32_t packet_ssrc;
6833 uint8_t rtt_valid = 0;
6834 int rtt_increase = 0, packet_loss_increase=0;
6847 packet_ssrc = sr->
ssrc;
6853 "length in words = %d, " \
6857 "RTP timestamp = %u, " \
6858 "Sender Packet Count = %u, " \
6859 "Sender Octet Count = %u\n",
6881 packet_ssrc = rr->
ssrc;
6886 "length in words = %d, " \
6897 uint8_t percent_fraction = (uint8_t)((uint16_t)(uint8_t)report->
fraction * 100 / 255);
6902 ((float)percent_fraction * .3));
6929 "Receiving an RTCP packet\n[%04d-%02d-%02d %02d:%02d:%02d.%d] SSRC[0x%x]\n" 6930 "RTT[%f] = A[%u] - DLSR[%u] - LSR[%u]\n",
6946 "Receiving RTCP packet\n[%04d-%02d-%02d %02d:%02d:%02d.%d] SSRC[0x%x]\n" 6947 "Ignoring erroneous RTT[%f] = A[%u] - DLSR[%u] - LSR[%u]\n",
6964 #ifdef DEBUG_ESTIMATORS_ 6974 #ifdef DEBUG_ESTIMATORS_ 6985 #ifdef DEBUG_ESTIMATORS_ 6988 packet_loss_increase = 1;
6990 #ifdef DEBUG_ESTIMATORS_ 7000 #ifdef DEBUG_ESTIMATORS_ 7014 #ifdef DEBUG_ESTIMATORS_ 7024 #ifdef DEBUG_ESTIMATORS_ 7033 #ifdef DEBUG_ESTIMATORS_ 7063 #ifdef DEBUG_ESTIMATORS_ 7148 unsigned char *p = (
unsigned char *) msg;
7155 }
while (remain >= 4);
7181 if (*b == 0 || *b == 1) {
7188 if (*bytes && (*b >= 20) && (*b <= 64)) {
7207 int sbytes = (int) *bytes;
7208 srtp_err_status_t stat = 0;
7238 const char *tx_host;
7239 const char *old_host;
7240 char bufa[50], bufb[50];
7246 "Auto Changing %s RTCP port from %s:%u to %s:%u\n",
rtp_type(rtp_session), old_host, old, tx_host,
7286 uint32_t elapsed = 0;
7289 elapsed = (now - rtp_session->
last_media) / 1000;
7315 int sleep_mss = 1000;
7343 int read_pretriggered = 0;
7345 int got_rtp_poll = 0;
7365 *flags &= ~SFF_RTCP;
7367 read_pretriggered = 0;
7372 read_pretriggered = 1;
7386 *flags &= ~SFF_RTCP;
7388 read_pretriggered = 0;
7394 read_pretriggered = 1;
7419 }
else if (hot_socket && (rtp_session->
hot_hits % 10) != 0) {
7422 }
else if (hot_socket) {
7432 "%s Auto-Flush catching up %d packets (%d)ms.\n",
7474 if (!read_pretriggered) {
7485 int pt = poll_sec * 1000000;
7498 if (rtp_session->
vb && !rtp_session->
pause_jb) {
7537 if (read_pretriggered) {
7538 read_pretriggered = 0;
7542 status =
read_rtp_packet(rtp_session, &bytes, flags, pmapP, poll_status, got_jb);
7585 *flags &= ~SFF_RTCP;
7668 switch_rtp_t *other_rtp_session = NULL;
7681 int sbytes = (int) rtcp_bytes;
7692 rtcp_bytes = sbytes;
7725 if (!bytes && (io_flags & SWITCH_IO_FLAG_NOBLOCK)) {
7743 (bytes && bytes < 5) || (!bytes && poll_loop)) {
7750 if (bytes && bytes < 5) {
7754 if (!bytes && poll_loop) {
7790 const char *tx_host;
7791 const char *old_host;
7792 char bufa[50], bufb[50];
7799 "Auto Changing %s port from %s:%u to %s:%u\n",
rtp_type(rtp_session), old_host, old, tx_host,
7803 char varname[80] =
"";
7873 "Ignoring udptl packet of size of %ld bytes that looks strikingly like a RTP packet.\n", (
long)bytes);
7899 if (check || bytes) {
7904 uint8_t *data = (uint8_t *)
RTP_BODY(rtp_session);
7940 goto result_continue;
7951 uint8_t *data = (uint8_t *)
RTP_BODY(rtp_session);
8103 if ((rdigit = malloc(
sizeof(*rdigit))) != 0) {
8128 if ((rdigit = malloc(
sizeof(*rdigit))) != 0) {
8154 bytes =
rtp_common_read(rtp_session, payload_type, NULL, flags, io_flags);
8159 }
else if (bytes == 0) {
8170 memcpy(data,
RTP_BODY(rtp_session), bytes);
8217 frame->
source = __FILE__;
8225 frame->
seq = (uint16_t) ntohs((uint16_t) rtp_session->
last_rtp_hdr.seq);
8257 bytes =
rtp_common_read(rtp_session, payload_type, NULL, flags, io_flags);
8275 if (!rtp_session)
return 0;
8279 rtp_type(rtp_session), (
long)bytes, line);
8285 rtp_type(rtp_session), (
long)bytes, line);
8298 uint32_t this_ts = 0;
8302 switch_rtp_t *rtp_bundle_session = NULL;
8303 switch_rtp_t *tmp_session = NULL;
8314 if (!rtp_bundle_session && !
rtp_write_ready(rtp_session, datalen, __LINE__)) {
8327 m = (uint8_t) send_msg->
header.m;
8328 rtp_session->
ts = ntohl(send_msg->
header.ts);
8335 send_msg->
header.pt = rtp_session->
te;
8337 data = send_msg->
body;
8347 payload = rtp_session->
te;
8351 send_msg->
header.pt = payload;
8357 memcpy(send_msg->
body, data, datalen);
8388 if (rtp_session->
cn && payload != rtp_session->
cng_pt) {
8389 rtp_session->
cn = 0;
8401 rtp_session->
ts = 0;
8451 if (delta < 0 || delta > 90000) {
8454 "Timestamp shift detected last: %d this: %d delta: %d stick with prev delta: %d\n",
8469 send_msg->
header.ssrc = htonl(rtp_session->
ssrc);
8480 uint32_t codec_flags = 0;
8481 uint32_t len =
sizeof(decoded);
8497 uint32_t energy = 0;
8498 uint32_t x, y = 0, z = len /
sizeof(int16_t);
8507 for (x = 0; x < z; x++) {
8508 energy += abs(decoded[y]);
8515 score = (energy / (z / divisor));
8592 this_ts = ntohl(send_msg->
header.ts);
8594 ts_delta = abs((int32_t)(this_ts - rtp_session->
last_write_ts));
8599 #ifdef DEBUG_TS_ROLLOVER 8617 int32_t y = ntohs(send_msg->
header.seq);
8622 if (x > UINT16_MAX / 2 && y < UINT16_MAX / 2) {
8623 x -= (int32_t)UINT16_MAX+1;
8636 rtp_session->
seq += delta;
8638 send_msg->
header.seq = htons(rtp_session->
seq);
8644 if (rtp_bundle_session) {
8645 tmp_session = rtp_session;
8646 rtp_session = rtp_bundle_session;
8652 int sbytes = (int) bytes;
8653 srtp_err_status_t stat;
8664 "Error! RE-Activating %s Secure RTP SEND\n",
rtp_type(rtp_session));
8671 "RE-Activating %s Secure RTP SEND\n",
rtp_type(rtp_session));
8683 "Error: %s SRTP protection failed with code %d\n",
rtp_type(rtp_session), stat);
8692 #ifdef RTP_DEBUG_WRITE_DELTA 8694 int delta = (int) (now - rtp_session->
send_time) / 1000;
8701 const char *tx_host;
8702 const char *old_host;
8703 const char *my_host;
8705 char bufa[50], bufb[50], bufc[50];
8713 "W %s b=%4ld %s:%u %s:%u %s:%u pt=%d ts=%u seq=%u m=%d\n",
8726 if (!rtp_session->
vbw) {
8727 int nack_size = 100;
8731 int tmp = atoi(var);
8733 if (tmp > 0 && tmp < 500) {
8740 if (rtp_session->
vbw) {
8748 #ifdef RTP_WRITE_PLOSS 8750 int r = (rand() % 10000) + 1;
8754 "Simulate dropping packet ......... ts: %u seq: %u\n", ntohl(send_msg->
header.ts), ntohs(send_msg->
header.seq));
8771 rtp_session->
seq -= delta;
8777 if (rtp_bundle_session) rtp_session = tmp_session;
8794 if (send_msg->header.pt == rtp_session->
cng_pt) {
8894 uint32_t len, ts = 0;
8897 srtp_hdr_t local_header;
8929 send_msg = frame->
packet;
8937 send_msg->
header.ssrc = htonl(rtp_session->
ssrc);
8938 send_msg->
header.seq = htons(++rtp_session->
seq);
8942 const char *tx_host;
8943 const char *old_host;
8944 const char *my_host;
8946 char bufa[50], bufb[50], bufc[50];
8954 "W %s b=%4ld %s:%u %s:%u %s:%u pt=%d ts=%u seq=%u m=%d\n",
8995 payload = rtp_session->
cng_pt;
9000 payload = rtp_session->
payload;
9002 if (rtp_session->
pmaps && *rtp_session->
pmaps) {
9004 for (pmap = *rtp_session->
pmaps; pmap; pmap = pmap->
next) {
9032 for (pmap = *rtp_session->
pmaps; pmap; pmap = pmap->
next) {
9042 send_msg = frame->
packet;
9043 local_header = send_msg->
header;
9047 send_msg->
header.pt = payload;
9050 send_msg->
header.version = 2;
9051 send_msg->
header.m = frame->
m;
9057 send_msg->
header.ssrc = htonl(rtp_session->
ssrc);
9076 send_msg->
header = local_header;
9094 *s = rtp_session->
stats;
9096 s = &rtp_session->
stats;
9099 if (rtp_session->
jb) {
9177 if (process_encryption) {
9182 int sbytes = (int) *bytes;
9183 srtp_err_status_t stat;
9217 #if defined(ENABLE_SRTP) 9228 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