44 #include <apr_network_io.h>
47 #undef PACKAGE_TARNAME
48 #undef PACKAGE_VERSION
49 #undef PACKAGE_BUGREPORT
53 #include <datatypes.h>
55 #include <srtp_priv.h>
59 #define JITTER_LEAD_FRAMES 10
60 #define READ_INC(rtp_session) switch_mutex_lock(rtp_session->read_mutex); rtp_session->reading++
61 #define READ_DEC(rtp_session) switch_mutex_unlock(rtp_session->read_mutex); rtp_session->reading--
62 #define WRITE_INC(rtp_session) switch_mutex_lock(rtp_session->write_mutex); rtp_session->writing++
63 #define WRITE_DEC(rtp_session) switch_mutex_unlock(rtp_session->write_mutex); rtp_session->writing--
65 #define RTP_STUN_FREQ 1000000
66 #define rtp_header_len 12
67 #define RTP_START_PORT 16384
68 #define RTP_END_PORT 32768
69 #define MASTER_KEY_LEN 30
70 #define RTP_MAGIC_NUMBER 42
71 #define WARN_SRTP_ERRS 10
72 #define MAX_SRTP_ERRS 100
73 #define NTP_TIME_OFFSET 2208988800UL
74 #define ZRTP_MAGIC_COOKIE 0x5a525450
77 #define DTMF_SANITY (rtp_session->one_second * 30)
79 #define rtp_session_name(_rtp_session) _rtp_session->session ? switch_core_session_get_name(_rtp_session->session) : "-"
90 static zrtp_global_t *zrtp_global;
92 static zrtp_zid_t zid = {
"FreeSWITCH01" };
94 static zrtp_zid_t zid = {
"FreeSWITCH0" };
96 static int zrtp_on = 0;
97 #define ZRTP_MITM_TRIES 100
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)
254 char last_sent_id[13];
456 zrtp_session_t *zrtp_session;
457 zrtp_profile_t *zrtp_profile;
458 zrtp_stream_t *zrtp_stream;
510 static void do_2833(switch_rtp_t *rtp_session);
513 #define rtp_type(rtp_session) rtp_session->flags[SWITCH_RTP_FLAG_VIDEO] ? "video" : "audio"
518 int is_rtcp = ice == &rtp_session->
rtcp_ice;
519 const char *err =
"";
576 unsigned char *packet = (
unsigned char *)
RTP_BODY(rtp_session);
580 uint16_t in_digit_seq;
585 if (!(packet[0] || packet[1] || packet[2] || packet[3]) && len >= 8) {
591 if (!(packet[0] || packet[1] || packet[2] || packet[3]) && rtp_session->
dtmf_data.
in_digit_ts) {
600 end = packet[1] & 0x80 ? 1 : 0;
601 duration = (packet[2] << 8) + packet[3];
603 in_digit_seq = ntohs((uint16_t) rtp_session->
last_rtp_hdr.seq);
617 if (in_digit_seq < rtp_session->dtmf_data.in_digit_seq) {
765 static int rtp_write_ready(switch_rtp_t *rtp_session, uint32_t bytes,
int line);
773 uint8_t
buf[256] = { 0 };
775 unsigned int elapsed;
804 if (elapsed > 30000) {
858 if (strchr(them,
':')) {
870 char username[34] = { 0 };
871 unsigned char buf[512] = { 0 };
875 uint32_t *pri = NULL;
876 int is_rtcp = ice == &rtp_session->
rtcp_ice;
897 if (cpylen >
sizeof(buf)) {
898 cpylen =
sizeof(
buf);
902 memcpy(buf, data, cpylen);
934 switch (attr->
type) {
943 uint32_t code = (err->
code * 100) + err->
number;
990 uint32_t priority = 0;
991 pri = (uint32_t *) attr->
value;
992 priority = ntohl(*pri);
1004 }
while (xlen <= packet->header.length);
1007 ok = !strcmp(ice->
user_ice, username);
1015 char foo1[13] =
"", foo2[13] =
"";
1034 memcpy(foo1, packet->
header.
id, 12);
1043 if (!
zstr(username)) {
1044 if (!
icecmp(username, ice)) {
1059 if (elapsed > 20000 && pri) {
1063 const char *old_host, *err = NULL;
1079 for (j = 0; j < 2; j++) {
1080 if (!icep[j] || !icep[j]->ice_params) {
1084 if (icep[j]->ice_params && icep[j]->ice_params->cands[i][icep[j]->
proto].priority == *pri) {
1105 if (!host || !port) {
1111 "%s ICE Auto Changing port from %s:%u to %s:%u\n",
rtp_type(rtp_session), old_host, old, host, port);
1160 const char *host = NULL, *host2 = NULL;
1166 uint8_t stunbuf[512];
1168 const char *remote_ip;
1186 memset(stunbuf, 0,
sizeof(stunbuf));
1211 "STUN from %s:%d %s\n", host, port, cmp ?
"EXPECTED" :
"IGNORED");
1222 }
else if (rtp_session->
wrong_addrs > 10 || elapsed >= 10000) {
1242 if (elapsed < 1000) {
1244 "Skiping RELAY stun/%s/dtls port change from %s:%u to %s:%u\n", is_rtcp ?
"rtcp" :
"rtp",
1257 "Auto Changing %s stun/%s/dtls port from %s:%u to %s:%u\n",
rtp_type(rtp_session), is_rtcp ?
"rtcp" :
"rtp",
1273 msg.
from = __FILE__;
1296 zrtp_status_t status = zrtp_status_ok;
1298 status = zrtp_def_cache_store(zrtp_global);
1303 static int zrtp_send_rtp_callback(
const zrtp_stream_t *stream,
char *rtp_packet,
unsigned int rtp_packet_length)
1305 switch_rtp_t *rtp_session = zrtp_stream_get_userdata(stream);
1307 zrtp_status_t status = zrtp_status_ok;
1313 static void zrtp_event_callback(zrtp_stream_t *stream,
unsigned event)
1315 switch_rtp_t *rtp_session = zrtp_stream_get_userdata(stream);
1316 zrtp_session_info_t zrtp_session_info;
1325 case ZRTP_EVENT_IS_SECURE:
1333 if (zrtp_status_ok == zrtp_session_get(stream->session, &zrtp_session_info)) {
1334 if (zrtp_session_info.sas_is_ready) {
1339 zrtp_verified_set(zrtp_global, &stream->session->zid, &stream->session->peer_zid, (uint8_t)1);
1350 if (!video_rtp_session) {
1354 if (video_rtp_session) {
1355 if (zrtp_status_ok != zrtp_stream_attach(stream->session, &video_rtp_session->zrtp_stream)) {
1358 zrtp_stream_set_userdata(video_rtp_session->zrtp_stream, video_rtp_session);
1360 zrtp_stream_registration_start(video_rtp_session->zrtp_stream, video_rtp_session->
ssrc);
1362 zrtp_stream_start(video_rtp_session->zrtp_stream, video_rtp_session->
ssrc);
1371 stream->session->sas2.buffer);
1378 case ZRTP_EVENT_NO_ZRTP_QUICK:
1380 if (stream != NULL) {
1381 zrtp_stream_stop(stream);
1386 case ZRTP_EVENT_IS_CLIENT_ENROLLMENT:
1393 case ZRTP_EVENT_USER_ALREADY_ENROLLED:
1400 case ZRTP_EVENT_NEW_USER_ENROLLED:
1407 case ZRTP_EVENT_USER_UNENROLLED:
1414 case ZRTP_EVENT_IS_PENDINGCLEAR:
1421 rtp_session->zrtp_mitm_tries = 0;
1425 case ZRTP_EVENT_NO_ZRTP:
1436 static void zrtp_logger(
int level,
const char *data,
int len,
int offset)
1447 zrtp_config_t zrtp_config;
1448 char zrtp_cache_path[256] =
"";
1449 zrtp_on = zrtp_enabled ?
switch_true(zrtp_enabled) : 0;
1458 zrtp_config_defaults(&zrtp_config);
1459 strcpy(zrtp_config.client_id,
"FreeSWITCH");
1460 zrtp_config.is_mitm = 1;
1461 zrtp_config.lic_mode = ZRTP_LICENSE_MODE_ACTIVE;
1463 cache_len=(uint32_t)strlen(zrtp_cache_path);
1464 ZSTR_SET_EMPTY(zrtp_config.def_cache_path);
1465 zrtp_config.def_cache_path.length = cache_len > zrtp_config.def_cache_path.max_length ? zrtp_config.def_cache_path.max_length : (uint16_t)cache_len;
1466 strncpy(zrtp_config.def_cache_path.buffer, zrtp_cache_path, zrtp_config.def_cache_path.max_length);
1467 zrtp_config.cb.event_cb.on_zrtp_protocol_event = (void (*)(zrtp_stream_t*,zrtp_protocol_event_t))zrtp_event_callback;
1468 zrtp_config.cb.misc_cb.on_send_packet = zrtp_send_rtp_callback;
1469 zrtp_config.cb.event_cb.on_zrtp_security_event = (void (*)(zrtp_stream_t*,zrtp_security_event_t))zrtp_event_callback;
1470 zrtp_log_set_log_engine((zrtp_log_engine *) zrtp_logger);
1471 zrtp_log_set_level(4);
1472 if (zrtp_status_ok == zrtp_init(&zrtp_config, &zrtp_global)) {
1473 memcpy(zid, zid_string, 12);
1499 }
else if (timestamp) {
1500 rtp_session->
ts = (uint32_t) timestamp;
1521 static void do_mos(switch_rtp_t *rtp_session,
int force) {
1536 if (diff < 1) diff = 1;
1549 if (R < 0 || R > 100) R = 100;
1552 rtp_session->
stats.
inbound.
mos = 1 + (0.035) * R + (.000007) * R * (R-60) * (100-R);
1577 lost += i * loss[i];
1580 if (received > 0 && bursts > 0) {
1581 *burstr = (double)((
double)lost / (double)bursts) / (double)(1.0 / ( 1.0 - (
double)lost / (double)received ));
1583 *burstr = - *burstr;
1589 *lossr = (double)((
double)lost / (double)received);
1607 int64_t diff_time = 0, cur_diff = 0;
1623 seq = (int)(uint16_t) ntohs((uint16_t) rtp_session->
last_rtp_hdr.seq);
1687 if ( diff_time < 0 ) {
1688 diff_time = -diff_time;
1734 uint32_t sec, ntp_sec, ntp_usec;
1737 sec = (uint32_t)(now/1000000);
1740 ntp_usec = (uint32_t)(now - (sec*1000000));
1741 sr->
ntp_lsw = htonl((u_long)(ntp_usec*(
double)(((uint64_t)1)<<32)*1.0e-6));
1750 (ntohl(sr->
ntp_lsw)&0xffff0000)>>16 | (ntohl(sr->
ntp_msw)&0x0000ffff)<<16,
1762 uint32_t expected_pkt, dlsr;
1764 uint32_t ntp_sec, ntp_usec, lsr_now, sec;
1766 sec = (uint32_t)(now/1000000);
1768 ntp_usec = (uint32_t)(now - (sec*1000000));
1779 if (expected_pkt > 0 && pkt_lost > 0) {
1780 rtcp_report_block->
fraction = (uint8_t) (pkt_lost * 256 / expected_pkt);
1784 #if SWITCH_BYTE_ORDER != __BIG_ENDIAN
1803 lsr_now = (uint32_t)(ntp_usec*0.065536) | (ntp_sec&0x0000ffff)<<16;
1811 rtcp_report_block->
dlsr = htonl(dlsr);
1821 stats->
ssrc = ntohl(hdr->ssrc);
1830 stats->
base_seq = ntohs((uint16_t)hdr->seq);
1854 uint32_t packet_spacing_diff = 0, pkt_tsdiff, pkt_extended_seq;
1855 uint16_t pkt_seq, seq_diff, max_seq;
1856 const int MAX_DROPOUT = 3000;
1857 const int MAX_MISORDER = 100;
1858 const int RTP_SEQ_MOD = (1<<16);
1863 pkt_seq = (uint16_t) ntohs((uint16_t) rtp_session->
last_rtp_hdr.seq);
1867 seq_diff = pkt_seq - max_seq;
1869 if (seq_diff < MAX_DROPOUT) {
1870 if (pkt_seq < max_seq) {
1875 pkt_extended_seq = stats->
cycle << 16 | pkt_seq;
1880 else if (seq_diff <= (RTP_SEQ_MOD - MAX_MISORDER)) {
1881 if (pkt_seq == stats->
bad_seq) {
1884 stats->
bad_seq = (pkt_seq + 1) & (RTP_SEQ_MOD-1);
1892 if (ntohl(hdr->ssrc) != stats->
ssrc || !stats->
init) {
1903 pkt_tsdiff = abs((
int)rtp_session->
timer.
samplecount - (
int)ntohl(hdr->ts));
1907 packet_spacing_diff = abs((
int)pkt_tsdiff - (
int)stats->
last_pkt_tsdiff);
1922 uint32_t mantissa_max, i = 0;
1924 uint32_t mantissa = 0;
1925 uint16_t overhead = 60;
1929 mantissa_max = (1 << bits) - 1;
1931 for (i = 0; i < 32; ++i) {
1932 if (bps <= (mantissa_max << i)) {
1938 mantissa = (bps >> exp);
1940 tmmbx->
parts[0] = (uint8_t) ((exp << 2) + ((mantissa >> 15) & 0x03));
1941 tmmbx->
parts[1] = (uint8_t) (mantissa >> 7);
1942 tmmbx->
parts[2] = (uint8_t) ((mantissa >> 1) + ((overhead >> 8) & 0x01));
1943 tmmbx->
parts[3] = (uint8_t) (overhead);
1959 int rtcp_ok = 0, rtcp_fb = 0;
1961 int rate = 0, nack_ttl = 0;
1962 uint32_t cur_nack[
MAX_NACK] = { 0 };
1969 uint8_t data[10] = { 0 };
1993 cur_nack[nack_ttl++] = nack;
2016 if (rtcp_ok &&
using_ice(rtp_session)) {
2055 rr->
ssrc = htonl(rtp_session->
ssrc);
2062 sr->
ssrc = htonl(rtp_session->
ssrc);
2106 for (n = 0; n < nack_ttl; n++) {
2118 ext_hdr->
length = htons(3);
2120 nack = (uint32_t *) p;
2121 *nack = cur_nack[n];
2124 ntohs(*nack & 0xFFFF));
2153 fir->
r1 = fir->
r2 = fir->
r3 = 0;
2168 while (rtp_session->
tmmbr || rtp_session->
tmmbn) {
2184 if (rtp_session->
tmmbr) {
2187 bps = rtp_session->
tmmbr;
2188 rtp_session->
tmmbr = 0;
2192 bps = rtp_session->
tmmbn;
2193 rtp_session->
tmmbn = 0;
2212 p = (uint8_t *) (sdes) + sdes_bytes;
2213 ssrc = (uint32_t *) p;
2214 *ssrc = htonl(rtp_session->
ssrc);
2215 sdes_bytes +=
sizeof(uint32_t);
2218 p = (uint8_t *) (sdes) + sdes_bytes;
2221 snprintf((
char *)unit->
value, 80,
"%x", rtp_session->
ssrc);
2229 snprintf((
char *)unit->
value, 80,
"FreeSWITCH.org -- Come to ClueCon.com");
2235 sdes_bytes += 4 - (sdes_bytes % 4);
2237 sdes->length = htons((uint16_t)(sdes_bytes / 4) - 1);
2238 rtcp_bytes += sdes_bytes;
2252 int sbytes = (int) rtcp_bytes;
2259 rtcp_bytes = sbytes;
2268 unsigned int sbytes = (int) rtcp_bytes;
2269 zrtp_status_t stat = zrtp_status_fail;
2271 stat = zrtp_process_rtcp(rtp_session->zrtp_stream, (
void *) &rtp_session->
rtcp_send_msg, &sbytes);
2274 case zrtp_status_ok:
2276 case zrtp_status_drop:
2278 ret = (int)rtcp_bytes;
2281 case zrtp_status_fail:
2288 rtcp_bytes = sbytes;
2294 const char *old_host;
2341 crypto_get_random(buf, len);
2374 zrtp_status_t status = zrtp_status_ok;
2376 status = zrtp_def_cache_store(zrtp_global);
2378 zrtp_down(zrtp_global);
2382 crypto_kernel_shutdown();
2459 rtp_session->pmaps = pmap;
2469 rtp_session->rtp_bugs = bugs;
2472 rtp_session->seq = 0;
2486 *err =
"RTCP Remote Address Error!";
2510 *err =
"RTCP Socket Error!";
2515 *err =
"RTCP NOT ACTIVE!";
2532 *err =
"RTCP Local Address Error!";
2537 *err =
"RTCP Socket Error!";
2542 *err =
"RTCP Socket Error!";
2547 *err =
"RTCP Bind Error!";
2553 *err =
"RTCP From Address Error!";
2559 rtcp_new_sock = NULL;
2571 if (rtcp_new_sock) {
2575 if (rtcp_old_sock) {
2591 char o[5] =
"TEST", i[5] =
"";
2596 if (rtp_session->ready != 1) {
2612 if (
zstr(host) || !port) {
2613 *err =
"Address Error";
2619 rtp_session->local_port = port;
2623 *err =
"Local Address Error!";
2628 if (rtp_session->sock_input) {
2633 *err =
"Socket Error!";
2638 *err =
"Socket Error!";
2654 if ((j = atoi(host)) && j > 223 && j < 240) {
2656 *err =
"Multicast Socket interface Error";
2661 *err =
"Multicast Error";
2665 if (rtp_session->session) {
2670 int ttl = atoi(var);
2672 if (ttl > 0 && ttl < 256) {
2674 *err =
"Mutlicast TTL set failed";
2712 old_sock = rtp_session->sock_input;
2713 rtp_session->sock_input = new_sock;
2745 if (rtp_session->ready != 1) {
2759 if (rtp_session->missed_count >= max) {
2762 "new max missed packets(%d->%d) greater than current missed packets(%d). RTP will timeout.\n",
2763 rtp_session->missed_count, max, rtp_session->missed_count);
2766 rtp_session->max_missed_packets = max;
2772 if (rtp_session->jb) {
2780 if (rtp_session->vb) {
2784 if (rtp_session->vbw) {
2795 rtp_session->seq = (uint16_t) rand();
2796 rtp_session->ts = 0;
2797 memset(&rtp_session->ts_norm, 0,
sizeof(rtp_session->ts_norm));
2799 rtp_session->last_stun = rtp_session->first_stun = 0;
2800 rtp_session->wrong_addrs = 0;
2801 rtp_session->rtcp_sent_packets = 0;
2802 rtp_session->rtcp_last_sent = 0;
2803 rtp_session->ice_adj = 0;
2810 if (rtp_session->ice.ready) {
2812 rtp_session->ice.ready = rtp_session->ice.rready = 0;
2819 rtp_session->missed_count = 0;
2824 return zstr(rtp_session->remote_host_str) ?
"0.0.0.0" : rtp_session->remote_host_str;
2829 return rtp_session->remote_port;
2834 uint32_t o = UINT_MAX;
2860 memset(&rtp_session->timer, 0,
sizeof(rtp_session->timer));
2864 rtp_session->missed_count = 0;
2865 rtp_session->max_missed_packets = 0;
2869 if (rtp_session->rtcp_sock_input) {
2874 if (rtp_session->rtcp_sock_output && rtp_session->rtcp_sock_output != rtp_session->rtcp_sock_input) {
2879 rtp_session->rtcp_sock_input = NULL;
2880 rtp_session->rtcp_sock_output = NULL;
2882 if ((sock = rtp_session->rtcp_sock_input)) {
2883 rtp_session->rtcp_sock_input = NULL;
2886 if (rtp_session->rtcp_sock_output && rtp_session->rtcp_sock_output != sock) {
2887 if ((sock = rtp_session->rtcp_sock_output)) {
2888 rtp_session->rtcp_sock_output = NULL;
2921 *err =
"Remote Address Error!";
2928 rtp_session->remote_addr = remote_addr;
2929 switch_cp_addr(rtp_session->rtp_from_addr, rtp_session->remote_addr);
2931 if (change_adv_addr) {
2933 rtp_session->remote_port = port;
2937 rtp_session->eff_remote_port = port;
2940 rtp_session->sock_output = rtp_session->sock_input;
2942 if (rtp_session->sock_output && rtp_session->sock_output != rtp_session->sock_input) {
2949 *err =
"Socket Error!";
2953 if (rtp_session->dtls) {
2954 rtp_session->dtls->sock_output = rtp_session->sock_output;
2964 rtp_session->rtcp_remote_addr = rtp_session->remote_addr;
2965 rtp_session->rtcp_sock_output = rtp_session->sock_output;
2967 if (remote_rtcp_port) {
2968 rtp_session->remote_rtcp_port = remote_rtcp_port;
2970 rtp_session->remote_rtcp_port = rtp_session->eff_remote_port + 1;
2974 if (rtp_session->rtcp_dtls) {
2976 rtp_session->rtcp_dtls->remote_addr = rtp_session->rtcp_remote_addr;
2977 rtp_session->rtcp_dtls->sock_output = rtp_session->rtcp_sock_output;
2995 return dtls_state_names_t[s];
2999 #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
3001 #define cr_keylen 16
3002 #define cr_saltlen 14
3012 }
else if ((cert = SSL_get_peer_certificate(dtls->
ssl))) {
3023 uint8_t raw_key_data[
cr_kslen*2] = { 0 };
3024 unsigned char *local_key, *remote_key, *local_salt, *remote_salt;
3025 unsigned char local_key_buf[
cr_kslen] = {0}, remote_key_buf[
cr_kslen] = {0};
3029 #ifdef HAVE_OPENSSL_DTLS_SRTP
3030 if (!SSL_export_keying_material(dtls->
ssl, raw_key_data,
sizeof(raw_key_data),
"EXTRACTOR-dtls_srtp", 19, NULL, 0, 0)) {
3040 local_key = raw_key_data;
3046 remote_key = raw_key_data;
3052 memcpy(local_key_buf, local_key,
cr_keylen);
3055 memcpy(remote_key_buf, remote_key,
cr_keylen);
3104 if ((ret = SSL_do_handshake(dtls->
ssl)) != 1){
3105 switch((ret = SSL_get_error(dtls->
ssl, ret))){
3106 case SSL_ERROR_WANT_READ:
3107 case SSL_ERROR_WANT_WRITE:
3108 case SSL_ERROR_NONE:
3117 if (SSL_is_init_finished(dtls->
ssl)) {
3136 SSL_free(dtls->
ssl);
3146 int r = 0, ret = 0, len;
3148 unsigned char buf[4096] =
"";
3152 if (!dtls->
bytes && !ready) {
3157 ret = SSL_get_error(dtls->
ssl, ret);
3161 if (dtls_states[dtls->
state]) {
3162 r = dtls_states[dtls->
state](rtp_session, dtls);
3165 if ((len = BIO_read(dtls->
write_bio, buf,
sizeof(buf))) > 0) {
3179 static int cb_verify_peer(
int preverify_ok, X509_STORE_CTX *ctx)
3186 ssl = X509_STORE_CTX_get_app_data(ctx);
3189 if (!(ssl && dtls)) {
3193 if ((cert = SSL_get_peer_certificate(dtls->
ssl))) {
3208 #ifdef HAVE_OPENSSL_DTLS_SRTP
3217 if (!rtp_session || (!rtp_session->dtls && !rtp_session->rtcp_dtls)) {
3222 return rtp_session->dtls->state;
3226 return rtp_session->rtcp_dtls->state;
3235 if (!rtp_session || (!rtp_session->dtls && !rtp_session->rtcp_dtls)) {
3240 if (rtp_session->dtls && rtp_session->dtls == rtp_session->rtcp_dtls) {
3241 rtp_session->rtcp_dtls = NULL;
3244 if (rtp_session->dtls) {
3248 if (rtp_session->jb) {
3252 if (rtp_session->vb) {
3256 if (rtp_session->vbw) {
3270 for(x = 0; x < 2; x++) {
3271 if (rtp_session->send_ctx[x]) {
3272 srtp_dealloc(rtp_session->send_ctx[x]);
3273 rtp_session->send_ctx[x] = NULL;
3281 for (x = 0; x < 2; x++) {
3282 if (rtp_session->recv_ctx[x]) {
3283 srtp_dealloc(rtp_session->recv_ctx[x]);
3284 rtp_session->recv_ctx[x] = NULL;
3298 const char *kind =
"";
3301 #ifndef OPENSSL_NO_EC
3305 #ifndef HAVE_OPENSSL_DTLS_SRTP
3319 if ((type & DTLS_TYPE_RTP) && (type & DTLS_TYPE_RTCP)) {
3321 }
else if ((type & DTLS_TYPE_RTP)) {
3328 "Activate %s %s DTLS %s\n", kind,
rtp_type(rtp_session), (type & DTLS_TYPE_SERVER) ?
"server" :
"client");
3330 if (((type & DTLS_TYPE_RTP) && rtp_session->dtls) || ((type & DTLS_TYPE_RTCP) && rtp_session->rtcp_dtls)) {
3348 dtls->
ssl_ctx = SSL_CTX_new((type & DTLS_TYPE_SERVER) ? DTLSv1_server_method() : DTLSv1_client_method());
3351 bio = BIO_new_file(dtls->
pem,
"r");
3352 dh = PEM_read_bio_DHparams(bio, NULL, NULL, NULL);
3355 SSL_CTX_set_tmp_dh(dtls->
ssl_ctx, dh);
3359 SSL_CTX_set_mode(dtls->
ssl_ctx, SSL_MODE_AUTO_RETRY);
3362 SSL_CTX_set_verify(dtls->
ssl_ctx, SSL_VERIFY_NONE, NULL);
3364 SSL_CTX_set_cipher_list(dtls->
ssl_ctx,
"ALL");
3366 #ifdef HAVE_OPENSSL_DTLS_SRTP
3368 SSL_CTX_set_tlsext_use_srtp(dtls->
ssl_ctx,
"SRTP_AES128_CM_SHA1_80");
3372 dtls->
read_bio = BIO_new(BIO_s_mem());
3378 BIO_set_mem_eof_return(dtls->
read_bio, -1);
3379 BIO_set_mem_eof_return(dtls->
write_bio, -1);
3381 if ((ret=SSL_CTX_use_certificate_file(dtls->
ssl_ctx, dtls->
rsa, SSL_FILETYPE_PEM)) != 1) {
3386 if ((ret=SSL_CTX_use_PrivateKey_file(dtls->
ssl_ctx, dtls->
pvt, SSL_FILETYPE_PEM)) != 1) {
3391 if (SSL_CTX_check_private_key(dtls->
ssl_ctx) == 0) {
3397 && (ret = SSL_CTX_load_verify_locations(dtls->
ssl_ctx, dtls->
ca, NULL)) != 1) {
3400 SSL_get_error(dtls->
ssl, ret));
3407 SSL_set_mode(dtls->
ssl, SSL_MODE_AUTO_RETRY);
3408 SSL_set_read_ahead(dtls->
ssl, 1);
3411 #ifndef OPENSSL_NO_EC
3412 ecdh = EC_KEY_new_by_curve_name(NID_X9_62_prime256v1);
3416 SSL_set_options(dtls->
ssl, SSL_OP_SINGLE_ECDH_USE);
3417 SSL_set_tmp_ecdh(dtls->
ssl, ecdh);
3421 SSL_set_verify(dtls->
ssl, SSL_VERIFY_NONE, NULL);
3422 SSL_set_app_data(dtls->
ssl, dtls);
3424 BIO_ctrl(dtls->
read_bio, BIO_CTRL_DGRAM_SET_MTU, 1400, NULL);
3425 BIO_ctrl(dtls->
write_bio, BIO_CTRL_DGRAM_SET_MTU, 1400, NULL);
3426 SSL_set_mtu(dtls->
ssl, 1400);
3427 BIO_ctrl(dtls->
write_bio, BIO_C_SET_BUFF_SIZE, 1400, NULL);
3428 BIO_ctrl(dtls->
read_bio, BIO_C_SET_BUFF_SIZE, 1400, NULL);
3438 if ((type & DTLS_TYPE_RTP)) {
3439 rtp_session->dtls = dtls;
3444 if ((type & DTLS_TYPE_RTCP)) {
3445 rtp_session->rtcp_dtls = dtls;
3446 if (!(type & DTLS_TYPE_RTP)) {
3447 dtls->
sock_output = rtp_session->rtcp_sock_output;
3448 dtls->
remote_addr = rtp_session->rtcp_remote_addr;
3452 if ((type & DTLS_TYPE_SERVER)) {
3453 SSL_set_accept_state(dtls->
ssl);
3455 SSL_set_connect_state(dtls->
ssl);
3477 srtp_policy_t *policy;
3485 unsigned char b64_key[512] =
"";
3516 rtp_session->srtp_idx_rtcp = idx = 1;
3519 rtp_session->srtp_idx_rtcp = idx = 1;
3523 policy = &rtp_session->recv_policy[idx];
3525 policy = &rtp_session->send_policy[idx];
3528 crypto_key->
type = type;
3529 crypto_key->
index = index;
3530 memcpy(crypto_key->
key, key, keylen);
3531 crypto_key->
next = rtp_session->crypto_keys[direction];
3532 rtp_session->crypto_keys[direction] = crypto_key;
3534 memset(policy, 0,
sizeof(*policy));
3544 switch (crypto_key->
type) {
3546 crypto_policy_set_aes_cm_128_hmac_sha1_80(&policy->rtp);
3547 crypto_policy_set_aes_cm_128_hmac_sha1_80(&policy->rtcp);
3554 crypto_policy_set_aes_cm_128_hmac_sha1_32(&policy->rtp);
3555 crypto_policy_set_aes_cm_128_hmac_sha1_80(&policy->rtcp);
3564 crypto_policy_set_aes_gcm_256_8_auth(&policy->rtp);
3565 crypto_policy_set_aes_gcm_256_8_auth(&policy->rtcp);
3573 crypto_policy_set_aes_gcm_128_8_auth(&policy->rtp);
3574 crypto_policy_set_aes_gcm_128_8_auth(&policy->rtcp);
3582 crypto_policy_set_aes_cm_256_hmac_sha1_80(&policy->rtp);
3583 crypto_policy_set_aes_cm_256_hmac_sha1_80(&policy->rtcp);
3589 crypto_policy_set_aes_cm_128_null_auth(&policy->rtp);
3590 crypto_policy_set_aes_cm_128_null_auth(&policy->rtcp);
3600 policy->key = (uint8_t *) crypto_key->
key;
3601 policy->next = NULL;
3603 policy->window_size = 1024;
3604 policy->allow_repeat_tx = 1;
3609 switch (direction) {
3611 policy->ssrc.type = ssrc_any_inbound;
3616 if ((stat = srtp_create(&rtp_session->recv_ctx[idx], policy)) || !rtp_session->recv_ctx[idx]) {
3631 policy->ssrc.type = ssrc_any_outbound;
3638 if ((stat = srtp_create(&rtp_session->send_ctx[idx], policy)) || !rtp_session->send_ctx[idx]) {
3659 if (rtp_session->dtls) {
3676 rtp_session->ms_per_packet = ms_per_packet;
3677 rtp_session->samples_per_interval = rtp_session->conf_samples_per_interval = samples_per_interval;
3678 rtp_session->missed_count = 0;
3679 rtp_session->samples_per_second =
3680 (uint32_t) ((
double) (1000.0f / (double) (rtp_session->ms_per_packet / 1000)) * (
double) rtp_session->samples_per_interval);
3682 rtp_session->one_second = (rtp_session->samples_per_second / rtp_session->samples_per_interval);
3690 int change_timer = 0;
3692 if (rtp_session->ms_per_packet && rtp_session->ms_per_packet != ms_per_packet) {
3698 if (change_timer && rtp_session->timer_name) {
3702 if (rtp_session->timer.timer_interface) {
3706 rtp_session->timer_name, ms_per_packet / 1000,
3710 "RE-Starting timer [%s] %d bytes per %dms\n", rtp_session->timer_name, samples_per_interval, ms_per_packet / 1000);
3713 memset(&rtp_session->timer, 0,
sizeof(rtp_session->timer));
3715 "Problem RE-Starting timer [%s] %d bytes per %dms\n", rtp_session->timer_name, samples_per_interval, ms_per_packet / 1000);
3727 rtp_session->ssrc = ssrc;
3728 rtp_session->send_msg.header.ssrc = htonl(rtp_session->ssrc);
3735 rtp_session->remote_ssrc = ssrc;
3742 uint32_t samples_per_interval,
3743 uint32_t ms_per_packet,
3746 switch_rtp_t *rtp_session = NULL;
3752 *new_rtp_session = NULL;
3755 *err =
"Packet Size Too Large!";
3760 *err =
"Memory Error!";
3768 rtp_session->
session = session;
3787 rtp_session->
seq = (uint16_t) rand();
3811 rtp_session->
payload = payload;
3818 timer_name =
"soft";
3821 if (!
zstr(timer_name) && !strcasecmp(timer_name,
"none")) {
3825 if (!
zstr(timer_name)) {
3832 "Starting timer [%s] %d bytes per %dms\n", timer_name, samples_per_interval, ms_per_packet / 1000);
3836 "Error Starting timer [%s] %d bytes per %dms, async RTP disabled\n", timer_name, samples_per_interval, ms_per_packet / 1000);
3863 switch_rtp_t *master_rtp_session = NULL;
3871 "You can not have ZRTP and SRTP enabled simultaneously, ZRTP will be disabled for this call!\n");
3873 zrtp_enabled = NULL;
3883 master_rtp_session = rtp_session;
3891 if (rtp_session == master_rtp_session) {
3892 rtp_session->zrtp_profile =
switch_core_alloc(rtp_session->
pool,
sizeof(*rtp_session->zrtp_profile));
3893 zrtp_profile_defaults(rtp_session->zrtp_profile, zrtp_global);
3895 rtp_session->zrtp_profile->allowclear = 0;
3896 rtp_session->zrtp_profile->disclose_bit = 0;
3897 rtp_session->zrtp_profile->cache_ttl = (uint32_t) -1;
3899 if (zrtp_status_ok != zrtp_session_init(zrtp_global, rtp_session->zrtp_profile, zid, initiator, &rtp_session->zrtp_session)) {
3901 zrtp_session_down(rtp_session->zrtp_session);
3902 rtp_session->zrtp_session = NULL;
3906 zrtp_session_set_userdata(rtp_session->zrtp_session, session);
3909 if (zrtp_status_ok != zrtp_stream_attach(master_rtp_session->zrtp_session, &rtp_session->zrtp_stream)) {
3913 zrtp_stream_set_userdata(rtp_session->zrtp_stream, rtp_session);
3916 zrtp_stream_registration_start(rtp_session->zrtp_stream, rtp_session->
ssrc);
3918 zrtp_stream_start(rtp_session->zrtp_stream, rtp_session->
ssrc);
3944 rtp_session->
ready = 1;
3945 *new_rtp_session = rtp_session;
3952 const
char *tx_host,
3955 uint32_t samples_per_interval,
3956 uint32_t ms_per_packet,
3959 switch_rtp_t *rtp_session = NULL;
3961 if (
zstr(rx_host)) {
3962 *err =
"Missing local host";
3967 *err =
"Missing local port";
3971 if (
zstr(tx_host)) {
3972 *err =
"Missing remote host";
3977 *err =
"Missing remote port";
4003 rtp_session->
ready = 2;
4005 rtp_session->
rx_port = rx_port;
4017 rtp_session->te = te;
4025 rtp_session->recv_te = te;
4032 rtp_session->cng_pt = pt;
4039 if (rtp_session && rtp_session->timer.timer_interface) {
4043 return &rtp_session->timer;
4056 return rtp_session->jb;
4066 if (!!pause == !!rtp_session->pause_jb) {
4070 if (rtp_session->pause_jb && !pause) {
4074 rtp_session->pause_jb = pause ? 1 : 0;
4094 if (rtp_session->vb) {
4095 return switch_jb_get_frames(rtp_session->vb, min_frame_len, max_frame_len, cur_frame_len, highest_frame_len);
4111 if (!rtp_session->vb) {
4134 if (name) x = atoi(name);
4137 if (rtp_session->jb) {
4139 }
else if (rtp_session->vb) {
4147 uint32_t queue_frames,
4148 uint32_t max_queue_frames,
4149 uint32_t samples_per_packet,
4150 uint32_t samples_per_second)
4158 if (queue_frames < 1) {
4162 if (max_queue_frames < queue_frames) {
4163 max_queue_frames = queue_frames * 3;
4168 if (rtp_session->jb) {
4188 const char *err = NULL;
4190 if (!rtp_session->ms_per_packet) {
4196 if (!(rtp_session->remote_rtcp_port = remote_port)) {
4197 rtp_session->remote_rtcp_port = rtp_session->remote_port + 1;
4205 if (send_rate == -1) {
4212 rtp_session->rtcp_interval = send_rate;
4218 rtp_session->remote_rtcp_port, 0, rtp_session->pool) !=
SWITCH_STATUS_SUCCESS || !rtp_session->rtcp_remote_addr) {
4223 rtp_session->rtcp_local_addr = rtp_session->local_addr;
4224 rtp_session->rtcp_from_addr = rtp_session->from_addr;
4225 rtp_session->rtcp_sock_input = rtp_session->sock_input;
4226 rtp_session->rtcp_sock_output = rtp_session->sock_output;
4228 rtp_session->rtcp_recv_msg_p = (
rtcp_msg_t *) &rtp_session->recv_msg;
4234 rtp_session->rtcp_recv_msg_p = (
rtcp_msg_t *) &rtp_session->rtcp_recv_msg;
4242 const
char *password, const
char *rpassword,
ice_proto_t proto,
4257 ice = &rtp_session->ice;
4261 ice = &rtp_session->rtcp_ice;
4304 ice->
addr = rtp_session->remote_addr;
4306 ice->
addr = rtp_session->rtcp_remote_addr;
4314 proto ==
IPR_RTP ?
"RTP" :
"RTCP",
rtp_type(rtp_session), ice_user, host, port);
4342 if (!
rtp_write_ready(rtp_session, 0, __LINE__) || rtp_session->tmmbr) {
4346 rtp_session->tmmbr = bps;
4353 if (!
rtp_write_ready(rtp_session, 0, __LINE__) || rtp_session->tmmbn) {
4357 rtp_session->tmmbn = bps;
4370 rtp_session->fir_count = 1;
4381 rtp_session->pli_count = 1;
4397 }
else if (rtp_session->session) {
4418 if (rtp_session->sock_input) {
4431 if (rtp_session->sock_input) {
4435 if (rtp_session->sock_output && rtp_session->sock_output != rtp_session->sock_input) {
4440 if (rtp_session->rtcp_sock_input) {
4444 if (rtp_session->rtcp_sock_output && rtp_session->rtcp_sock_output != rtp_session->rtcp_sock_input) {
4461 ret = (rtp_session->flags[
SWITCH_RTP_FLAG_IO] && rtp_session->sock_input && rtp_session->sock_output && rtp_session->remote_addr
4462 && rtp_session->ready == 2) ? 1 : 0;
4483 if (rtp_session->stats.inbound.error_log && !rtp_session->stats.inbound.error_log->stop) {
4499 if (!rtp_session || !*rtp_session || !(*rtp_session)->ready) {
4508 (*rtp_session)->ready = 0;
4529 if ((*rtp_session)->jb) {
4533 if ((*rtp_session)->vb) {
4537 if ((*rtp_session)->vbw) {
4541 if ((*rtp_session)->dtls && (*rtp_session)->dtls == (*rtp_session)->rtcp_dtls) {
4542 (*rtp_session)->rtcp_dtls = NULL;
4545 if ((*rtp_session)->dtls) {
4549 if ((*rtp_session)->rtcp_dtls) {
4554 sock = (*rtp_session)->sock_input;
4555 (*rtp_session)->sock_input = NULL;
4558 if ((*rtp_session)->sock_output != sock) {
4559 sock = (*rtp_session)->sock_output;
4560 (*rtp_session)->sock_output = NULL;
4564 if ((sock = (*rtp_session)->rtcp_sock_input)) {
4565 (*rtp_session)->rtcp_sock_input = NULL;
4568 if ((*rtp_session)->rtcp_sock_output && (*rtp_session)->rtcp_sock_output != sock) {
4569 if ((sock = (*rtp_session)->rtcp_sock_output)) {
4570 (*rtp_session)->rtcp_sock_output = NULL;
4578 for(x = 0; x < 2; x++) {
4579 if ((*rtp_session)->send_ctx[x]) {
4580 srtp_dealloc((*rtp_session)->send_ctx[x]);
4581 (*rtp_session)->send_ctx[x] = NULL;
4588 for (x = 0; x < 2; x++) {
4589 if ((*rtp_session)->recv_ctx[x]) {
4590 srtp_dealloc((*rtp_session)->recv_ctx[x]);
4591 (*rtp_session)->recv_ctx[x] = NULL;
4602 if ((*rtp_session)->zrtp_stream != NULL) {
4603 zrtp_stream_stop((*rtp_session)->zrtp_stream);
4614 if ((*rtp_session)->zrtp_session) {
4615 zrtp_session_down((*rtp_session)->zrtp_session);
4616 (*rtp_session)->zrtp_session = NULL;
4620 if ((*rtp_session)->timer.timer_interface) {
4632 rtp_session->interdigit_delay = delay;
4637 return rtp_session->sock_input;
4642 return rtp_session->samples_per_interval;
4647 rtp_session->payload = payload;
4652 return rtp_session->payload;
4657 rtp_session->invalid_handler = on_invalid;
4666 rtp_session->flags[i] = flags[i];
4669 rtp_session->autoadj_window = 20;
4670 rtp_session->autoadj_threshold = 10;
4671 rtp_session->autoadj_tally = 0;
4672 if (rtp_session->session) {
4677 if (xn > 0 && xn <= 65535) {
4678 rtp_session->autoadj_window = xn*2;
4679 rtp_session->autoadj_threshold = xn;
4697 rtp_session->flags[i] = 0;
4706 rtp_session->flags[flag] = 1;
4710 rtp_session->stats.inbound.last_processed_seq = 0;
4714 rtp_session->autoadj_window = 20;
4715 rtp_session->autoadj_threshold = 10;
4716 rtp_session->autoadj_tally = 0;
4717 if (rtp_session->session) {
4722 if (xn > 0 && xn <= 65535) {
4723 rtp_session->autoadj_window = xn*2;
4724 rtp_session->autoadj_threshold = xn;
4733 if (rtp_session->jb) {
4744 return (uint32_t) rtp_session->flags[flags];
4751 rtp_session->flags[flag] = 0;
4755 rtp_session->stats.inbound.last_processed_seq = 0;
4765 int upsamp, max_upsamp;
4768 if (!max_ms) max_ms = ms;
4812 for (x = 0; x < loops; x++) {
4890 if (rdigit->
digit ==
'w') {
4896 if (rdigit->
digit ==
'W') {
4985 int was_blocking = 0;
4987 uint32_t flushed = 0;
5011 bytes_out = bytes_in;
5015 if (rtp_session->
vbw) {
5019 if (rtp_session->
vb) {
5021 bytes_out = bytes_in;
5063 }
while (bytes > 0);
5089 if (rtp_session->
pmaps && *rtp_session->
pmaps) {
5114 if (rtp_session->
pmaps && *rtp_session->
pmaps) {
5131 #define return_cng_frame() do_cng = 1; goto timer_check
5138 unsigned char *b = NULL;
5154 rtp_session->
punts++;
5155 rtp_session->
clean = 0;
5187 if (rtp_session->
dtls) {
5200 b = (
unsigned char *) &rtp_session->
recv_msg;
5205 if ((*b >= 20) && (*b <= 64)) {
5206 if (rtp_session->
dtls) {
5213 }
else if (*b == 0 || *b == 1) {
5252 if (!rtp_session->
vb && (!rtp_session->
jb || rtp_session->
pause_jb || !
jb_valid(rtp_session))) {
5254 xcheck_jitter = *bytes;
5288 if (rtp_session->
dtls) {
5312 int sbytes = (int) *bytes;
5313 err_status_t stat = 0;
5341 const char *tx_host;
5342 const char *old_host;
5343 const char *my_host;
5345 char bufa[50], bufb[50], bufc[50];
5353 "R %s b=%4ld %s:%u %s:%u %s:%u pt=%d ts=%u seq=%u m=%d\n",
5364 #ifdef RTP_READ_PLOSS
5366 int r = (rand() % 10000) + 1;
5369 "Simulate dropped packet ......... ts: %u seq: %u\n", ntohl(rtp_session->
last_rtp_hdr.ts), ntohs(rtp_session->
last_rtp_hdr.seq));
5384 uint16_t seq = ntohs((uint16_t) rtp_session->
last_rtp_hdr.seq);
5387 #ifdef DEBUG_MISSED_SEQ
5393 if (num_missed == 1) {
5395 rtp_session->
last_seq+1, (flushed_packets_diff == 1) ?
" (flushed by FS)" :
" (missed)",
5398 if (flushed_packets_diff == 0) {
5400 "Missed %ld RTP frames from sequence [%d] to [%d] (missed). Time since last read [%ld]\n",
5401 num_missed, rtp_session->
last_seq+1, seq-1,
5403 }
else if (flushed_packets_diff == num_missed) {
5405 "Missed %ld RTP frames from sequence [%d] to [%d] (flushed by FS). Time since last read [%ld]\n",
5406 num_missed, rtp_session->
last_seq+1, seq-1,
5408 }
else if (num_missed > flushed_packets_diff) {
5410 "Missed %ld RTP frames from sequence [%d] to [%d] (%ld packets flushed by FS, %ld packets missed)."
5411 " Time since last read [%ld]\n",
5412 num_missed, rtp_session->
last_seq+1, seq-1,
5413 flushed_packets_diff, num_missed-flushed_packets_diff,
5417 "Missed %ld RTP frames from sequence [%d] to [%d] (%ld packets flushed by FS). Time since last read [%ld]\n",
5418 num_missed, rtp_session->
last_seq+1, seq-1,
5452 unsigned int sbytes = (int) *bytes;
5453 zrtp_status_t stat = 0;
5455 stat = zrtp_process_srtp(rtp_session->zrtp_stream, (
void *) &rtp_session->
recv_msg, &sbytes);
5458 case zrtp_status_ok:
5461 case zrtp_status_drop:
5465 case zrtp_status_fail:
5480 int sbytes = (int) *bytes;
5481 err_status_t stat = 0;
5517 if (stat == err_status_replay_fail) msg=
"replay check failed";
5518 else if (stat == err_status_auth_fail) msg=
"auth check failed";
5523 "SRTP %s unprotect failed with code %d (%s) %ld bytes %d errors\n",
5524 rtp_type(rtp_session), stat, msg, (
long)*bytes, errs);
5526 "Ending call due to SRTP error\n");
5530 "SRTP %s unprotect failed with code %d (%s) %ld bytes %d errors\n",
5531 rtp_type(rtp_session), stat, msg, (
long)*bytes, errs);
5560 if (*bytes > (length * 4 + 4)) {
5561 *bytes -= (length * 4 + 4);
5574 "VIDEO: seq: %d ts: %u len: %ld %02x %02x %02x %02x %02x %02x %02x %02x %02x %02x %02x mark: %d\n",
5576 *((uint8_t *)
RTP_BODY(rtp_session)), *((uint8_t *)
RTP_BODY(rtp_session) + 1),
5577 *((uint8_t *)
RTP_BODY(rtp_session) + 2), *((uint8_t *)
RTP_BODY(rtp_session) + 3),
5578 *((uint8_t *)
RTP_BODY(rtp_session) + 4), *((uint8_t *)
RTP_BODY(rtp_session) + 5),
5579 *((uint8_t *)
RTP_BODY(rtp_session) + 6), *((uint8_t *)
RTP_BODY(rtp_session) + 7),
5580 *((uint8_t *)
RTP_BODY(rtp_session) + 8), *((uint8_t *)
RTP_BODY(rtp_session) + 9),
5609 (*bytes < rtp_header_len && *bytes > 0) ||
5625 if (rtp_session->
jb) {
5629 if (rtp_session->
vb) {
5634 if (rtp_session->
has_rtp && *bytes) {
5635 uint32_t read_ssrc = ntohl(rtp_session->
last_rtp_hdr.ssrc);
5637 if (rtp_session->
vb &&
jb_valid(rtp_session)) {
5647 if (!return_jb_packet) {
5674 if (!return_jb_packet) {
5687 if (!*bytes || rtp_session->
has_rtp) {
5696 if (rtp_session->
punts < 4) {
5720 if (++rtp_session->
clean > 200) {
5721 rtp_session->
punts = 0;
5723 if (!xcheck_jitter) {
5725 xcheck_jitter = *bytes;
5732 if (rtp_session->
vb &&
jb_valid(rtp_session)) {
5752 if (!xcheck_jitter) {
5754 xcheck_jitter = *bytes;
5767 uint16_t seq = (uint16_t) (nack & 0xFFFF);
5768 uint16_t blp = (uint16_t) (nack >> 16);
5770 const char *tx_host = NULL;
5771 const char *old_host = NULL;
5772 const char *my_host = NULL;
5773 char bufa[50], bufb[50], bufc[50];
5791 "X %s b=%4ld %s:%u %s:%u %s:%u pt=%d ts=%u seq=%u m=%d\n",
5807 for (i = 0; i < 16; i++) {
5808 if (blp & (1 << i)) {
5815 "X %s b=%4ld %s:%u %s:%u %s:%u pt=%d ts=%u seq=%u m=%d\n",
5850 if (rtp_session->
vbw) {
5856 uint32_t *nack = (uint32_t *) extp->
body;
5875 uint32_t sec, ntp_sec, ntp_usec, lsr_now;
5877 uint32_t packet_ssrc;
5880 sec = (uint32_t)(now/1000000);
5882 ntp_usec = (uint32_t)(now - (sec*1000000));
5883 lsr_now = (uint32_t)(ntp_usec*0.065536) | (ntp_sec&0x0000ffff)<<16;
5890 packet_ssrc = sr->
ssrc;
5896 "length in words = %d, " \
5900 "RTP timestamp = %u, " \
5901 "Sender Packet Count = %u, " \
5902 "Sender Octet Count = %u\n",
5924 uint8_t percent_fraction = (uint8_t)report->
fraction * 100 / 256 ;
5929 ((float)(uint8_t)percent_fraction * .3));
5949 "Receiving an RTCP packet\n[%04d-%02d-%02d %02d:%02d:%02d.%d] SSRC[0x%x]\n"
5950 "RTT[%f] = A[%u] - DLSR[%u] - LSR[%u]\n",
5967 packet_ssrc = rr->
ssrc;
6027 unsigned char *p = (
unsigned char *) msg;
6034 }
while (remain >= 4);
6059 if (*b == 0 || *b == 1) {
6066 if (*bytes && (*b >= 20) && (*b <= 64)) {
6087 int sbytes = (int) *bytes;
6088 err_status_t stat = 0;
6108 unsigned int sbytes = (int) *bytes;
6109 zrtp_status_t stat = 0;
6111 stat = zrtp_process_srtcp(rtp_session->zrtp_stream, (
void *) rtp_session->
rtcp_recv_msg_p, &sbytes);
6114 case zrtp_status_ok:
6117 case zrtp_status_drop:
6121 case zrtp_status_fail:
6151 int sleep_mss = 1000;
6178 int read_pretriggered = 0;
6180 int got_rtp_poll = 0;
6200 *flags &= ~SFF_RTCP;
6202 read_pretriggered = 0;
6207 read_pretriggered = 1;
6221 *flags &= ~SFF_RTCP;
6223 read_pretriggered = 0;
6229 read_pretriggered = 1;
6252 if (hot_socket && (rtp_session->
hot_hits % 10) != 0) {
6255 }
else if (hot_socket) {
6265 "%s Auto-Flush catching up %d packets (%d)ms.\n",
6298 if (!read_pretriggered) {
6309 int pt = poll_sec * 1000000;
6322 if (rtp_session->
vb) {
6357 if (read_pretriggered) {
6358 read_pretriggered = 0;
6398 *flags &= ~SFF_RTCP;
6479 switch_rtp_t *other_rtp_session = NULL;
6490 int sbytes = (int) rtcp_bytes;
6495 rtcp_bytes = sbytes;
6503 unsigned int sbytes = (
unsigned int) bytes;
6504 zrtp_status_t stat = zrtp_status_fail;
6506 stat = zrtp_process_rtcp(other_rtp_session->zrtp_stream, (
void *) &other_rtp_session->
rtcp_send_msg, &sbytes);
6509 case zrtp_status_ok:
6511 case zrtp_status_drop:
6516 case zrtp_status_fail:
6559 if (bytes && rtp_session->
has_rtp &&
6564 int accept_packet = 1;
6567 if (rtp_session->
pmaps && *rtp_session->
pmaps) {
6589 if (!accept_packet &&
6597 if (!bytes && (io_flags & SWITCH_IO_FLAG_NOBLOCK)) {
6615 (bytes && bytes < 5) || (!bytes && poll_loop)) {
6622 if (bytes && bytes < 5) {
6626 if (!bytes && poll_loop) {
6660 const char *tx_host;
6661 const char *old_host;
6662 char bufa[50], bufb[50];
6669 "Auto Changing %s port from %s:%u to %s:%u\n",
rtp_type(rtp_session), old_host, old, tx_host,
6673 char varname[80] =
"";
6727 "Ignoring udptl packet of size of %ld bytes that looks strikingly like a RTP packet.\n", (
long)bytes);
6753 if (check || bytes) {
6758 uint8_t *data = (uint8_t *)
RTP_BODY(rtp_session);
6794 goto result_continue;
6805 uint8_t *data = (uint8_t *)
RTP_BODY(rtp_session);
6895 return rtp_session->auto_adj_used;
6944 if ((rdigit = malloc(
sizeof(*rdigit))) != 0) {
6969 if ((rdigit = malloc(
sizeof(*rdigit))) != 0) {
6995 bytes =
rtp_common_read(rtp_session, payload_type, NULL, flags, io_flags);
7000 }
else if (bytes == 0) {
7011 memcpy(data,
RTP_BODY(rtp_session), bytes);
7024 if (rtp_session->rtcp_fresh_frame) {
7026 rtp_session->rtcp_fresh_frame = 0;
7028 *frame = rtp_session->rtcp_frame;
7044 bytes =
rtp_common_read(rtp_session, &frame->payload, &frame->pmap, &frame->flags, io_flags);
7046 frame->data =
RTP_BODY(rtp_session);
7049 frame->packet = NULL;
7050 frame->timestamp = 0;
7056 frame->packet = &rtp_session->recv_msg;
7057 frame->packetlen = bytes;
7058 frame->source = __FILE__;
7061 if (frame->payload == rtp_session->recv_te) {
7064 frame->timestamp = ntohl(rtp_session->last_rtp_hdr.ts);
7065 frame->seq = (uint16_t) ntohs((uint16_t) rtp_session->last_rtp_hdr.seq);
7066 frame->ssrc = ntohl(rtp_session->last_rtp_hdr.ssrc);
7072 zrtp_session_info_t zrtp_session_info;
7074 if (rtp_session->zrtp_session && (zrtp_status_ok == zrtp_session_get(rtp_session->zrtp_session, &zrtp_session_info))) {
7075 if (zrtp_session_info.sas_is_ready) {
7087 if (other_rtp_session) {
7090 if (zrtp_status_ok == zrtp_session_get(other_rtp_session->zrtp_session, &zrtp_session_info)) {
7091 if (rtp_session->zrtp_mitm_tries > ZRTP_MITM_TRIES) {
7096 }
else if (zrtp_status_ok == zrtp_resolve_mitm_call(other_rtp_session->zrtp_stream, rtp_session->zrtp_stream)) {
7101 rtp_session->zrtp_mitm_tries++;
7131 frame->datalen = bytes;
7145 bytes =
rtp_common_read(rtp_session, payload_type, NULL, flags, io_flags);
7163 if (!rtp_session)
return 0;
7167 rtp_type(rtp_session), (
long)bytes, line);
7173 rtp_type(rtp_session), (
long)bytes, line);
7188 uint32_t this_ts = 0;
7206 m = (uint8_t) send_msg->
header.m;
7207 rtp_session->
ts = ntohl(send_msg->
header.ts);
7214 send_msg->
header.pt = rtp_session->
te;
7216 data = send_msg->
body;
7226 payload = rtp_session->
te;
7230 send_msg->
header.pt = payload;
7236 memcpy(send_msg->
body, data, datalen);
7261 if (rtp_session->
cn && payload != rtp_session->
cng_pt) {
7262 rtp_session->
cn = 0;
7274 rtp_session->
ts = 0;
7296 rtp_session->
ts_norm.
ts = (uint32_t) rand() % 1000000 + 1;
7338 send_msg->
header.ssrc = htonl(rtp_session->
ssrc);
7349 uint32_t codec_flags = 0;
7350 uint32_t len =
sizeof(decoded);
7366 uint32_t energy = 0;
7367 uint32_t x, y = 0, z = len /
sizeof(int16_t);
7376 for (x = 0; x < z; x++) {
7377 energy += abs(decoded[y]);
7384 score = (energy / (z / divisor));
7459 this_ts = ntohl(send_msg->
header.ts);
7476 send_msg->
header.seq = htons(++rtp_session->
seq);
7484 int sbytes = (int) bytes;
7496 "Error! RE-Activating %s Secure RTP SEND\n",
rtp_type(rtp_session));
7502 "RE-Activating %s Secure RTP SEND\n",
rtp_type(rtp_session));
7511 "Error: %s SRTP protection failed with code %d\n",
rtp_type(rtp_session), stat);
7520 unsigned int sbytes = (int) bytes;
7521 zrtp_status_t stat = zrtp_status_fail;
7524 stat = zrtp_process_rtp(rtp_session->zrtp_stream, (
void *) send_msg, &sbytes);
7527 case zrtp_status_ok:
7529 case zrtp_status_drop:
7534 case zrtp_status_fail:
7546 #ifdef RTP_DEBUG_WRITE_DELTA
7548 int delta = (int) (now - rtp_session->
send_time) / 1000;
7555 const char *tx_host;
7556 const char *old_host;
7557 const char *my_host;
7559 char bufa[50], bufb[50], bufc[50];
7567 "W %s b=%4ld %s:%u %s:%u %s:%u pt=%d ts=%u seq=%u m=%d\n",
7578 if (!rtp_session->
vbw) {
7580 if (rtp_session->
vbw) {
7588 #ifdef RTP_WRITE_PLOSS
7590 int r = (rand() % 10000) + 1;
7594 "Simulate dropping packet ......... ts: %u seq: %u\n", ntohl(send_msg->
header.ts), ntohs(send_msg->
header.seq));
7680 memset(&rtp_session->vad_data, 0,
sizeof(rtp_session->vad_data));
7692 codec->implementation->iananame,
7693 codec->implementation->modname,
7695 codec->implementation->samples_per_second,
7696 codec->implementation->microseconds_per_packet / 1000,
7697 codec->implementation->number_of_channels,
7703 codec->implementation->microseconds_per_packet / 1000);
7704 rtp_session->vad_data.diff_level = 400;
7705 rtp_session->vad_data.hangunder = 15;
7706 rtp_session->vad_data.hangover = 40;
7707 rtp_session->vad_data.bg_len = 5;
7708 rtp_session->vad_data.bg_count = 5;
7709 rtp_session->vad_data.bg_level = 300;
7710 rtp_session->vad_data.read_codec = codec;
7711 rtp_session->vad_data.session = session;
7712 rtp_session->vad_data.flags = flags;
7713 rtp_session->vad_data.cng_freq = 50;
7714 rtp_session->vad_data.ts = 1;
7715 rtp_session->vad_data.start = 0;
7717 rtp_session->vad_data.scan_freq = 0;
7730 uint32_t len, ts = 0;
7733 srtp_hdr_t local_header;
7761 bytes = frame->packetlen;
7764 send_msg = frame->packet;
7769 send_msg->
header.pt = rtp_session->payload;
7772 send_msg->
header.ssrc = htonl(rtp_session->ssrc);
7773 send_msg->
header.seq = htons(++rtp_session->seq);
7781 rtp_session->stats.outbound.raw_bytes += bytes;
7782 rtp_session->stats.outbound.media_bytes += bytes;
7783 rtp_session->stats.outbound.media_packet_count++;
7784 rtp_session->stats.outbound.packet_count++;
7789 zrtp_session_info_t zrtp_session_info;
7791 if (zrtp_status_ok == zrtp_session_get(rtp_session->zrtp_session, &zrtp_session_info)) {
7792 if (zrtp_session_info.sas_is_ready) {
7805 if (other_rtp_session) {
7806 if (zrtp_status_ok == zrtp_session_get(other_rtp_session->zrtp_session, &zrtp_session_info)) {
7807 if (rtp_session->zrtp_mitm_tries > ZRTP_MITM_TRIES) {
7812 }
else if (zrtp_status_ok == zrtp_resolve_mitm_call(other_rtp_session->zrtp_stream, rtp_session->zrtp_stream)) {
7817 rtp_session->zrtp_mitm_tries++;
7819 rtp_session->zrtp_mitm_tries++;
7834 if (!fwd && !rtp_session->sending_dtmf && !rtp_session->queue_delay &&
7846 payload = rtp_session->cng_pt;
7848 return (
int) frame->packetlen;
7851 payload = rtp_session->payload;
7853 if (rtp_session->pmaps && *rtp_session->pmaps) {
7855 for (pmap = *rtp_session->pmaps; pmap; pmap = pmap->
next) {
7866 frame->m, frame->payload, (uint32_t) (frame->timestamp), &frame->flags);
7868 rtp_session->stats.outbound.raw_bytes += wrote;
7869 rtp_session->stats.outbound.media_bytes += wrote;
7870 rtp_session->stats.outbound.media_packet_count++;
7871 rtp_session->stats.outbound.packet_count++;
7874 if (frame->pmap && rtp_session->pmaps && *rtp_session->pmaps) {
7878 for (pmap = *rtp_session->pmaps; pmap; pmap = pmap->
next) {
7888 send_msg = frame->packet;
7889 local_header = send_msg->
header;
7890 len = frame->packetlen;
7893 send_msg->
header.pt = payload;
7896 send_msg->
header.version = 2;
7897 send_msg->
header.m = frame->m;
7898 send_msg->
header.ts = htonl(frame->timestamp);
7900 send_msg->
header.ssrc = htonl(frame->ssrc);
7902 send_msg->
header.ssrc = htonl(rtp_session->ssrc);
7908 len = frame->datalen;
7918 r =
rtp_common_write(rtp_session, send_msg, data, len, payload, ts, &frame->flags);
7921 send_msg->
header = local_header;
7939 *s = rtp_session->stats;
7941 s = &rtp_session->stats;
7944 if (rtp_session->jb) {
7975 rtp_session->write_msg = rtp_session->send_msg;
7976 rtp_session->write_msg.header.seq = htons(++rtp_session->seq);
7977 rtp_session->write_msg.header.ts = htonl(ts);
7978 rtp_session->write_msg.header.pt = payload;
7979 rtp_session->write_msg.header.m = m;
7980 memcpy(rtp_session->write_msg.body, data, datalen);
7991 rtp_session->last_write_ts = ts;
8022 if (process_encryption) {
8027 int sbytes = (int) *bytes;
8032 srtp_dealloc(rtp_session->send_ctx[rtp_session->srtp_idx_rtp]);
8033 rtp_session->send_ctx[rtp_session->srtp_idx_rtp] = NULL;
8034 if ((stat = srtp_create(&rtp_session->send_ctx[rtp_session->srtp_idx_rtp],
8035 &rtp_session->send_policy[rtp_session->srtp_idx_rtp])) || !rtp_session->send_ctx[rtp_session->srtp_idx_rtp]) {
8045 stat = srtp_protect(rtp_session->send_ctx[rtp_session->srtp_idx_rtp], &rtp_session->write_msg.header, &sbytes);
8055 unsigned int sbytes = (int) *bytes;
8056 zrtp_status_t stat = zrtp_status_fail;
8058 stat = zrtp_process_rtp(rtp_session->zrtp_stream, (
void *) &rtp_session->write_msg, &sbytes);
8061 case zrtp_status_ok:
8063 case zrtp_status_drop:
8068 case zrtp_status_fail:
8080 status =
switch_socket_sendto(rtp_session->sock_output, rtp_session->remote_addr, 0, data, bytes);
8091 return rtp_session->ssrc;
8096 rtp_session->private_data = private_data;
8101 return rtp_session->private_data;
struct apr_queue_t switch_queue_t
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)
#define ZRTP_MAGIC_COOKIE
switch_time_t rtcp_last_sent
char body[SWITCH_RTP_MAX_BUF_LEN]
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_time_t total_talk_time
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_add_crypto_key(switch_rtp_t *rtp_session, switch_rtp_crypto_direction_t direction, uint32_t index, switch_rtp_crypto_key_type_t type, unsigned char *key, switch_size_t keylen)
static void rtcp_generate_report_block(switch_rtp_t *rtp_session, struct switch_rtcp_report_block *rtcp_report_block)
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)
switch_size_t period_packet_count
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)
#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)
switch_rtp_crypto_key_type_t
switch_status_t switch_channel_set_variable_name_printf(switch_channel_t *channel, const char *val, const char *fmt,...)
switch_status_t switch_core_hash_destroy(_Inout_ switch_hash_t **hash)
Destroy an existing hash table.
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.
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
char * switch_core_get_variable_pdup(_In_z_ const char *varname, switch_memory_pool_t *pool)
switch_sockaddr_t * rtcp_local_addr
switch_port_t remote_rtcp_port
switch_mutex_t * flag_mutex
#define SWITCH_RECOMMENDED_BUFFER_SIZE
struct switch_rtcp_report_block report_block
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.
#define WRITE_INC(rtp_session)
switch_status_t switch_poll(switch_pollfd_t *aprset, int32_t numsock, int32_t *nsds, switch_interval_time_t timeout)
#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_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_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_set_variable(_In_z_ const char *varname, _In_opt_z_ const char *value)
Add a global variable to the core.
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
switch_socket_t * rtcp_sock_input
#define SWITCH_RTP_MAX_BUF_LEN
switch_status_t switch_queue_trypop(switch_queue_t *queue, void **data)
void * switch_channel_get_private_partner(switch_channel_t *channel, const char *key)
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]
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
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)
switch_status_t switch_jb_put_packet(switch_jb_t *jb, switch_rtp_packet_t *packet, switch_size_t len)
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.
Abstract handler to a timer module.
int(* dtls_state_handler_t)(switch_rtp_t *, switch_dtls_t *)
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
static int switch_true(const char *expr)
Evaluate the truthfullness of a string expression.
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)
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.
uint32_t switch_scheduler_add_task(time_t task_runtime, switch_scheduler_func_t func, const char *desc, const char *group, uint32_t cmd_id, void *cmd_arg, switch_scheduler_flag_t flags)
Schedule a task in the future.
#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.
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)
switch_status_t switch_rtp_udptl_mode(switch_rtp_t *rtp_session)
int switch_cmp_addr(switch_sockaddr_t *sa1, switch_sockaddr_t *sa2)
#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 switch_status_t ice_out(switch_rtp_t *rtp_session, switch_rtp_ice_t *ice)
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.
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)
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.
#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)
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
if((uint32_t)(unpack->cur-unpack->buf) > unpack->buflen)
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
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)
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)
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
struct apr_sockaddr_t switch_sockaddr_t
static switch_mutex_t * port_lock
#define SWITCH_RTP_MAX_CRYPTO_LEN
int switch_rtp_has_dtls(void)
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]
switch_mutex_t * dtmf_mutex
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)
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
void switch_core_port_allocator_destroy(_Inout_ switch_core_port_allocator_t **alloc)
destroythe port allocator
static switch_hash_t * alloc_hash
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
static switch_status_t read_rtp_packet(switch_rtp_t *rtp_session, switch_size_t *bytes, switch_frame_flag_t *flags, switch_status_t poll_status, switch_bool_t return_jb_packet)
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)
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)
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_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
void * switch_rtp_get_private(switch_rtp_t *rtp_session)
Retrieve the private data from a given RTP session.
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
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)
#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
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
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)
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)
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_core_session_request_video_refresh(switch_core_session_t *session)
switch_status_t switch_socket_create(switch_socket_t **new_sock, int family, int type, int protocol, switch_memory_pool_t *pool)
switch_rtp_hdr_ext_t * ext
uint8_t number_of_channels
struct apr_thread_mutex_t switch_mutex_t
static void handle_nack(switch_rtp_t *rtp_session, uint32_t nack)
char * switch_rtp_get_remote_host(switch_rtp_t *rtp_session)
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.
uint32_t switch_rtp_get_ssrc(switch_rtp_t *rtp_session)
Retrieve the SSRC from a given RTP session.
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)
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_size_t last_flush_packet_count
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.
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
unsigned char key[SWITCH_RTP_MAX_CRYPTO_LEN]
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)
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)
#define SWITCH_STANDARD_SCHED_FUNC(name)
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)
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])
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
switch_status_t switch_queue_trypush(switch_queue_t *queue, void *data)
static void ping_socket(switch_rtp_t *rtp_session)
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_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
icand_t cands[MAX_CAND][2]
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_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)
struct apr_pool_t switch_memory_pool_t
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]
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)
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)
#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)
void switch_rtp_kill_socket(switch_rtp_t *rtp_session)
Kill the socket on an existing RTP session.
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
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 ...
struct apr_socket_t switch_socket_t
#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
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)
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)
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)
switch_core_session_t * session
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.
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)
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
#define SWITCH_SIZE_T_FMT
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
uint8_t switch_stun_packet_attribute_add_integrity(switch_stun_packet_t *packet, const char *pass)
static void do_mos(switch_rtp_t *rtp_session, int force)
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
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.