RTS API Documentation  1.10.11
Typedefs | Functions
RTP (RealTime Transport Protocol)
+ Collaboration diagram for RTP (RealTime Transport Protocol):

Typedefs

typedef 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)
 

Functions

void switch_rtp_get_random (void *buf, uint32_t len)
 
void switch_rtp_init (switch_memory_pool_t *pool)
 Initilize the RTP System. More...
 
void switch_rtp_shutdown (void)
 
switch_port_t switch_rtp_set_start_port (switch_port_t port)
 Set/Get RTP start port. More...
 
switch_status_t switch_rtp_set_ssrc (switch_rtp_t *rtp_session, uint32_t ssrc)
 
switch_status_t switch_rtp_set_remote_ssrc (switch_rtp_t *rtp_session, uint32_t ssrc)
 
switch_port_t switch_rtp_set_end_port (switch_port_t port)
 Set/Get RTP end port. More...
 
switch_port_t switch_rtp_request_port (const char *ip)
 Request a new port to be used for media. More...
 
void switch_rtp_release_port (const char *ip, switch_port_t port)
 
switch_status_t switch_rtp_set_interval (switch_rtp_t *rtp_session, uint32_t ms_per_packet, uint32_t samples_per_interval)
 
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_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 More...
 
switch_rtp_tswitch_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_ports, switch_port_t bundle_external_port)
 prepare a new RTP session handle and fully initilize it More...
 
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. More...
 
void switch_rtp_reset_jb (switch_rtp_t *rtp_session)
 
char * switch_rtp_get_remote_host (switch_rtp_t *rtp_session)
 
switch_port_t switch_rtp_get_remote_port (switch_rtp_t *rtp_session)
 
void switch_rtp_reset_media_timer (switch_rtp_t *rtp_session)
 
void switch_rtp_set_max_missed_packets (switch_rtp_t *rtp_session, uint32_t max)
 
void switch_rtp_set_media_timeout (switch_rtp_t *rtp_session, uint32_t ms)
 
switch_status_t switch_rtp_udptl_mode (switch_rtp_t *rtp_session)
 
void switch_rtp_reset (switch_rtp_t *rtp_session)
 
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. More...
 
void switch_rtp_kill_socket (switch_rtp_t *rtp_session)
 Kill the socket on an existing RTP session. More...
 
void switch_rtp_break (switch_rtp_t *rtp_session)
 
void switch_rtp_flush (switch_rtp_t *rtp_session)
 
uint8_t switch_rtp_ready (switch_rtp_t *rtp_session)
 Test if an RTP session is ready. More...
 
void switch_rtp_destroy (switch_rtp_t **rtp_session)
 Destroy an RTP session. More...
 
switch_status_t switch_rtp_sync_stats (switch_rtp_t *rtp_session)
 
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. More...
 
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) More...
 
switch_timer_tswitch_rtp_get_media_timer (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)
 
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)
 
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. More...
 
switch_status_t switch_rtp_debug_jitter_buffer (switch_rtp_t *rtp_session, const char *name)
 
switch_status_t switch_rtp_deactivate_jitter_buffer (switch_rtp_t *rtp_session)
 
switch_status_t switch_rtp_pause_jitter_buffer (switch_rtp_t *rtp_session, switch_bool_t pause)
 
switch_jb_tswitch_rtp_get_jitter_buffer (switch_rtp_t *rtp_session)
 
void switch_rtp_set_flag (switch_rtp_t *rtp_session, switch_rtp_flag_t flag)
 Set an RTP Flag. More...
 
void switch_rtp_set_flags (switch_rtp_t *rtp_session, switch_rtp_flag_t flags[SWITCH_RTP_FLAG_INVALID])
 
void switch_rtp_clear_flags (switch_rtp_t *rtp_session, switch_rtp_flag_t flags[SWITCH_RTP_FLAG_INVALID])
 
uint32_t switch_rtp_test_flag (switch_rtp_t *rtp_session, switch_rtp_flag_t flags)
 Test an RTP Flag. More...
 
void switch_rtp_clear_flag (switch_rtp_t *rtp_session, switch_rtp_flag_t flag)
 Clear an RTP Flag. More...
 
switch_socket_tswitch_rtp_get_rtp_socket (switch_rtp_t *rtp_session)
 Retrieve the socket from an existing RTP session. More...
 
void switch_rtp_ping (switch_rtp_t *rtp_session)
 
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. More...
 
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. More...
 
uint32_t switch_rtp_get_default_payload (switch_rtp_t *rtp_session)
 Get the default payload number for a given RTP session. More...
 
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. More...
 
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. More...
 
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. More...
 
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. More...
 
switch_size_t switch_rtp_has_dtmf (switch_rtp_t *rtp_session)
 Test for presence of DTMF on a given RTP session. More...
 
switch_size_t switch_rtp_dequeue_dtmf (switch_rtp_t *rtp_session, switch_dtmf_t *dtmf)
 Retrieve DTMF digits from a given RTP session. More...
 
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. More...
 
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. More...
 
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. More...
 
void rtp_flush_read_buffer (switch_rtp_t *rtp_session, switch_rtp_flush_t flush)
 
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. More...
 
switch_status_t switch_rtp_disable_vad (switch_rtp_t *rtp_session)
 Disable VAD on an RTP Session. More...
 
int switch_rtp_write_frame (switch_rtp_t *rtp_session, switch_frame_t *frame)
 Write data to a given RTP session. More...
 
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. More...
 
switch_status_t switch_rtp_write_raw (switch_rtp_t *rtp_session, void *data, switch_size_t *bytes, switch_bool_t process_encryption)
 
uint32_t switch_rtp_get_ssrc (switch_rtp_t *rtp_session)
 Retrieve the SSRC from a given RTP session. More...
 
void switch_rtp_set_private (switch_rtp_t *rtp_session, void *private_data)
 Associate an arbitrary data pointer with and RTP session. More...
 
void switch_rtp_set_telephony_event (switch_rtp_t *rtp_session, switch_payload_t te)
 Set the payload type to consider RFC2833 DTMF. More...
 
void switch_rtp_set_telephony_recv_event (switch_rtp_t *rtp_session, switch_payload_t te)
 
void switch_rtp_set_cng_pt (switch_rtp_t *rtp_session, switch_payload_t pt)
 Set the payload type for comfort noise. More...
 
void * switch_rtp_get_private (switch_rtp_t *rtp_session)
 Retrieve the private data from a given RTP session. More...
 
switch_status_t switch_rtp_set_payload_map (switch_rtp_t *rtp_session, payload_map_t **pmap)
 
void switch_rtp_intentional_bugs (switch_rtp_t *rtp_session, switch_rtp_bug_flag_t bugs)
 
switch_rtp_stats_tswitch_rtp_get_stats (switch_rtp_t *rtp_session, switch_memory_pool_t *pool)
 
switch_byte_t switch_rtp_check_auto_adj (switch_rtp_t *rtp_session)
 
void switch_rtp_set_interdigit_delay (switch_rtp_t *rtp_session, uint32_t delay)
 
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_status_t switch_rtp_del_dtls (switch_rtp_t *rtp_session, dtls_type_t type)
 
dtls_state_t switch_rtp_dtls_state (switch_rtp_t *rtp_session, dtls_type_t type)
 
int switch_rtp_has_dtls (void)
 
switch_status_t switch_rtp_req_bitrate (switch_rtp_t *rtp_session, uint32_t bps)
 
switch_status_t switch_rtp_ack_bitrate (switch_rtp_t *rtp_session, uint32_t bps)
 
void switch_rtp_video_refresh (switch_rtp_t *rtp_session)
 
void switch_rtp_video_loss (switch_rtp_t *rtp_session)
 
switch_core_session_tswitch_rtp_get_core_session (switch_rtp_t *rtp_session)
 

Detailed Description

Typedef Documentation

◆ switch_rtp_invalid_handler_t

typedef 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)

Definition at line 185 of file switch_rtp.h.

Function Documentation

◆ rtp_flush_read_buffer()

void rtp_flush_read_buffer ( switch_rtp_t rtp_session,
switch_rtp_flush_t  flush 
)

Definition at line 5635 of file switch_rtp.c.

References switch_rtp::flags, reset_jitter_seq(), switch_rtp_clear_flag(), SWITCH_RTP_FLAG_FLUSH, SWITCH_RTP_FLAG_PROXY_MEDIA, SWITCH_RTP_FLAG_RESET, SWITCH_RTP_FLAG_STICKY_FLUSH, SWITCH_RTP_FLAG_UDPTL, SWITCH_RTP_FLUSH_STICK, SWITCH_RTP_FLUSH_UNSTICK, switch_rtp_ready(), and switch_rtp_set_flag().

Referenced by rtp_common_read(), switch_core_media_receive_message(), and switch_rtp_set_flag().

5636 {
5637 
5638  if (rtp_session->flags[SWITCH_RTP_FLAG_PROXY_MEDIA] ||
5639  rtp_session->flags[SWITCH_RTP_FLAG_UDPTL]) {
5640  return;
5641  }
5642 
5643 
5644  if (switch_rtp_ready(rtp_session)) {
5645  rtp_session->flags[SWITCH_RTP_FLAG_RESET] = 1;
5646  rtp_session->flags[SWITCH_RTP_FLAG_FLUSH] = 1;
5647  reset_jitter_seq(rtp_session);
5648 
5649  switch (flush) {
5652  break;
5655  break;
5656  default:
5657  break;
5658  }
5659  }
5660 }
uint8_t switch_rtp_ready(switch_rtp_t *rtp_session)
Test if an RTP session is ready.
Definition: switch_rtp.c:5147
uint32_t flags[SWITCH_RTP_FLAG_INVALID]
Definition: switch_rtp.c:392
void switch_rtp_clear_flag(switch_rtp_t *rtp_session, switch_rtp_flag_t flag)
Clear an RTP Flag.
Definition: switch_rtp.c:5431
void switch_rtp_set_flag(switch_rtp_t *rtp_session, switch_rtp_flag_t flag)
Set an RTP Flag.
Definition: switch_rtp.c:5372
static void reset_jitter_seq(switch_rtp_t *rtp_session)
Definition: switch_rtp.c:1646

◆ switch_rtcp_zerocopy_read_frame()

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.

Parameters
rtp_sessionthe RTP session to read from
framean RTCP frame to populate with information
Returns
the number of bytes read

Definition at line 8172 of file switch_rtp.c.

References switch_rtp::flags, switch_rtp::rtcp_frame, switch_rtp::rtcp_fresh_frame, SWITCH_RTP_FLAG_ENABLE_RTCP, SWITCH_STATUS_FALSE, SWITCH_STATUS_SUCCESS, and SWITCH_STATUS_TIMEOUT.

Referenced by switch_core_media_read_frame().

8173 {
8174 
8175  if (!rtp_session->flags[SWITCH_RTP_FLAG_ENABLE_RTCP]) {
8176  return SWITCH_STATUS_FALSE;
8177  }
8178 
8179  /* A fresh frame has been found! */
8180  if (rtp_session->rtcp_fresh_frame) {
8181  /* turn the flag off! */
8182  rtp_session->rtcp_fresh_frame = 0;
8183 
8184  *frame = rtp_session->rtcp_frame;
8185 
8186  return SWITCH_STATUS_SUCCESS;
8187  }
8188 
8189  return SWITCH_STATUS_TIMEOUT;
8190 }
switch_bool_t rtcp_fresh_frame
Definition: switch_rtp.c:460
uint32_t flags[SWITCH_RTP_FLAG_INVALID]
Definition: switch_rtp.c:392
switch_rtcp_frame_t rtcp_frame
Definition: switch_rtp.c:329

◆ switch_rtp_ack_bitrate()

switch_status_t switch_rtp_ack_bitrate ( switch_rtp_t rtp_session,
uint32_t  bps 
)

Definition at line 5045 of file switch_rtp.c.

References rtp_write_ready(), SWITCH_STATUS_FALSE, SWITCH_STATUS_SUCCESS, and switch_rtp::tmmbn.

Referenced by switch_core_media_receive_message().

5046 {
5047  if (!rtp_write_ready(rtp_session, 0, __LINE__) || rtp_session->tmmbn) {
5048  return SWITCH_STATUS_FALSE;
5049  }
5050 
5051  rtp_session->tmmbn = bps;
5052 
5053  return SWITCH_STATUS_SUCCESS;
5054 }
uint32_t tmmbn
Definition: switch_rtp.c:337
static int rtp_write_ready(switch_rtp_t *rtp_session, uint32_t bytes, int line)
Definition: switch_rtp.c:8270

◆ switch_rtp_activate_ice()

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.

Returns
SWITCH_STATUS_SUCCESS

Definition at line 4930 of file switch_rtp.c.

References switch_rtp_ice_t::addr, switch_rtp_ice_t::cand_responsive, ice_s::cands, ice_s::chosen, icand_s::con_addr, icand_s::con_port, switch_rtp::flags, switch_rtp::ice, switch_rtp::ice_mutex, switch_rtp_ice_t::ice_params, switch_rtp_ice_t::ice_user, ICE_VANILLA, switch_rtp_ice_t::initializing, IPR_RTP, switch_rtp_ice_t::luser_ice, switch_rtp_ice_t::next_run, switch_rtp_ice_t::pass, switch_rtp::pool, switch_rtp_ice_t::proto, switch_rtp_ice_t::ready, switch_rtp::remote_addr, switch_rtp_ice_t::rpass, switch_rtp_ice_t::rready, switch_rtp::rtcp_ice, switch_rtp::rtcp_remote_addr, RTP_BUG_ACCEPT_ANY_PACKETS, switch_rtp::rtp_bugs, rtp_type, SDP_UFRAG_MAX_SIZE, switch_rtp::session, STUN_USERNAME_MAX_SIZE, SWITCH_CHANNEL_SESSION_LOG, switch_core_strdup, switch_get_addr(), SWITCH_LOG_ERROR, SWITCH_LOG_NOTICE, switch_log_printf(), switch_micro_time_now(), switch_mutex_lock(), switch_mutex_unlock(), switch_rtp_break(), SWITCH_RTP_FLAG_MUTE, SWITCH_RTP_FLAG_PAUSE, SWITCH_RTP_FLAG_VIDEO, SWITCH_RTP_FLAG_VIDEO_BREAK, switch_snprintf(), switch_sockaddr_get_port(), switch_sockaddr_info_get(), SWITCH_STATUS_FALSE, SWITCH_STATUS_SUCCESS, SWITCH_UNSPEC, switch_rtp_ice_t::type, and switch_rtp_ice_t::user_ice.

Referenced by check_ice(), and switch_core_media_activate_rtp().

4933 {
4934  char ice_user[STUN_USERNAME_MAX_SIZE];
4935  char user_ice[STUN_USERNAME_MAX_SIZE];
4936  char luser_ice[SDP_UFRAG_MAX_SIZE];
4937  switch_rtp_ice_t *ice;
4938  char *host = NULL;
4939  switch_port_t port = 0;
4940  char bufc[50];
4941 
4942 
4943  switch_mutex_lock(rtp_session->ice_mutex);
4944 
4945  if (proto == IPR_RTP) {
4946  ice = &rtp_session->ice;
4947  rtp_session->flags[SWITCH_RTP_FLAG_PAUSE] = 0;
4948  rtp_session->flags[SWITCH_RTP_FLAG_MUTE] = 0;
4949  } else {
4950  ice = &rtp_session->rtcp_ice;
4951  }
4952 
4953  ice->proto = proto;
4954 
4955  if ((type & ICE_VANILLA)) {
4956  switch_snprintf(ice_user, sizeof(ice_user), "%s:%s", login, rlogin);
4957  switch_snprintf(user_ice, sizeof(user_ice), "%s:%s", rlogin, login);
4958  switch_snprintf(luser_ice, sizeof(luser_ice), "%s%s", rlogin, login);
4959  ice->ready = ice->rready = 0;
4960  ice->cand_responsive = 0;
4961  } else {
4962  switch_snprintf(ice_user, sizeof(ice_user), "%s%s", login, rlogin);
4963  switch_snprintf(user_ice, sizeof(user_ice), "%s%s", rlogin, login);
4964  switch_snprintf(luser_ice, sizeof(luser_ice), "");
4965  ice->ready = ice->rready = 1;
4966  ice->cand_responsive = 0;
4967  }
4968 
4969  ice->ice_user = switch_core_strdup(rtp_session->pool, ice_user);
4970  ice->user_ice = switch_core_strdup(rtp_session->pool, user_ice);
4971  ice->luser_ice = switch_core_strdup(rtp_session->pool, luser_ice);
4972  ice->type = type;
4973  ice->ice_params = ice_params;
4974  ice->pass = "";
4975  ice->rpass = "";
4977  ice->initializing = 1;
4978 
4979  if (password) {
4980  ice->pass = switch_core_strdup(rtp_session->pool, password);
4981  }
4982 
4983  if (rpassword) {
4984  ice->rpass = switch_core_strdup(rtp_session->pool, rpassword);
4985  }
4986 
4987  if ((ice->type & ICE_VANILLA) && ice->ice_params) {
4988  host = ice->ice_params->cands[ice->ice_params->chosen[ice->proto]][ice->proto].con_addr;
4989  port = ice->ice_params->cands[ice->ice_params->chosen[ice->proto]][ice->proto].con_port;
4990 
4991  if (!host || !port || switch_sockaddr_info_get(&ice->addr, host, SWITCH_UNSPEC, port, 0, rtp_session->pool) != SWITCH_STATUS_SUCCESS || !ice->addr) {
4992  switch_mutex_unlock(rtp_session->ice_mutex);
4993  switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(rtp_session->session), SWITCH_LOG_ERROR, "Error setting remote host!\n");
4994  return SWITCH_STATUS_FALSE;
4995  }
4996  } else {
4997  if (proto == IPR_RTP) {
4998  ice->addr = rtp_session->remote_addr;
4999  } else {
5000  ice->addr = rtp_session->rtcp_remote_addr;
5001  }
5002 
5003  host = (char *)switch_get_addr(bufc, sizeof(bufc), ice->addr);
5004  port = switch_sockaddr_get_port(ice->addr);
5005  }
5006 
5007  switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(rtp_session->session), SWITCH_LOG_NOTICE, "Activating %s %s ICE: %s %s:%d\n",
5008  proto == IPR_RTP ? "RTP" : "RTCP", rtp_type(rtp_session), ice_user, host, port);
5009 
5010 
5011  rtp_session->rtp_bugs |= RTP_BUG_ACCEPT_ANY_PACKETS;
5012 
5013 
5014  if (rtp_session->flags[SWITCH_RTP_FLAG_VIDEO]) {
5015  rtp_session->flags[SWITCH_RTP_FLAG_VIDEO_BREAK] = 1;
5016  switch_rtp_break(rtp_session);
5017  }
5018 
5019  switch_mutex_unlock(rtp_session->ice_mutex);
5020 
5021  return SWITCH_STATUS_SUCCESS;
5022 }
switch_time_t switch_micro_time_now(void)
Get the current epoch time in microseconds.
Definition: switch_time.c:311
#define SWITCH_CHANNEL_SESSION_LOG(x)
uint16_t switch_sockaddr_get_port(switch_sockaddr_t *sa)
Definition: switch_apr.c:1001
switch_sockaddr_t * remote_addr
Definition: switch_rtp.c:340
#define SDP_UFRAG_MAX_SIZE
Definition: switch_rtp.c:88
switch_sockaddr_t * addr
Definition: switch_rtp.c:248
#define switch_core_strdup(_pool, _todup)
Copy a string using memory allocation from a given pool.
Definition: switch_core.h:733
ice_t * ice_params
Definition: switch_rtp.c:252
uint8_t initializing
Definition: switch_rtp.c:257
icand_t cands[MAX_CAND][MAX_CAND_IDX_COUNT]
Definition: switch_rtp.h:114
int switch_snprintf(_Out_z_cap_(len) char *buf, _In_ switch_size_t len, _In_z_ _Printf_format_string_ const char *format,...)
switch_time_t next_run
Definition: switch_rtp.c:250
#define rtp_type(rtp_session)
Definition: switch_rtp.c:540
switch_status_t switch_mutex_unlock(switch_mutex_t *lock)
Definition: switch_apr.c:313
switch_core_media_ice_type_t type
Definition: switch_rtp.c:251
switch_status_t switch_mutex_lock(switch_mutex_t *lock)
Definition: switch_apr.c:308
uint32_t flags[SWITCH_RTP_FLAG_INVALID]
Definition: switch_rtp.c:392
uint8_t cand_responsive
Definition: switch_rtp.c:261
char * con_addr
Definition: switch_rtp.h:99
uint16_t switch_port_t
switch_rtp_ice_t rtcp_ice
Definition: switch_rtp.c:398
switch_memory_pool_t * pool
Definition: switch_rtp.c:393
#define STUN_USERNAME_MAX_SIZE
Definition: switch_rtp.c:87
ice_proto_t proto
Definition: switch_rtp.c:253
void switch_rtp_break(switch_rtp_t *rtp_session)
Definition: switch_rtp.c:5080
#define SWITCH_UNSPEC
Definition: switch_apr.h:1022
switch_mutex_t * ice_mutex
Definition: switch_rtp.c:429
switch_core_session_t * session
Definition: switch_rtp.c:472
switch_rtp_ice_t ice
Definition: switch_rtp.c:397
switch_rtp_bug_flag_t rtp_bugs
Definition: switch_rtp.c:449
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.
const char * switch_get_addr(char *buf, switch_size_t len, switch_sockaddr_t *in)
Definition: switch_apr.c:979
int chosen[MAX_CAND_IDX_COUNT]
Definition: switch_rtp.h:116
switch_sockaddr_t * rtcp_remote_addr
Definition: switch_rtp.c:340
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)
Definition: switch_apr.c:839
switch_port_t con_port
Definition: switch_rtp.h:100

◆ switch_rtp_activate_jitter_buffer()

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.

Parameters
rtp_sessionthe rtp session
queue_framesthe number of frames to delay
Returns
SWITCH_STATUS_SUCCESS

Definition at line 4834 of file switch_rtp.c.

References switch_rtcp_numbers_t::inter_jitter, switch_rtp::jb, switch_rtp::pool, READ_DEC, READ_INC, switch_rtp_stats_t::rtcp, switch_rtp::session, SJB_AUDIO, switch_rtp::stats, switch_channel_get_variable_dup(), switch_core_session_get_channel(), SWITCH_FALSE, switch_jb_create(), switch_jb_set_frames(), switch_jb_set_jitter_estimator(), switch_jb_set_session(), switch_jb_ts_mode(), switch_rtp_ready(), SWITCH_STATUS_FALSE, and switch_true().

Referenced by check_jb().

4839 {
4841 
4842  if (!switch_rtp_ready(rtp_session)) {
4843  return SWITCH_STATUS_FALSE;
4844  }
4845 
4846  if (queue_frames < 1) {
4847  queue_frames = 3;
4848  }
4849 
4850  if (max_queue_frames < queue_frames) {
4851  max_queue_frames = queue_frames * 3;
4852  }
4853 
4854 
4855 
4856  if (rtp_session->jb) {
4857  status = switch_jb_set_frames(rtp_session->jb, queue_frames, max_queue_frames);
4858  } else {
4859  READ_INC(rtp_session);
4860  status = switch_jb_create(&rtp_session->jb, SJB_AUDIO, queue_frames, max_queue_frames, rtp_session->pool);
4861  switch_jb_set_session(rtp_session->jb, rtp_session->session);
4862  switch_jb_set_jitter_estimator(rtp_session->jb, &rtp_session->stats.rtcp.inter_jitter, samples_per_packet, samples_per_second);
4864  switch_jb_ts_mode(rtp_session->jb, samples_per_packet, samples_per_second);
4865  }
4866  //switch_jb_debug_level(rtp_session->jb, 10);
4867  READ_DEC(rtp_session);
4868  }
4869 
4870 
4871 
4872  return status;
4873 }
static switch_bool_t switch_true(const char *expr)
Evaluate the truthfullness of a string expression.
Definition: switch_utils.h:519
uint8_t switch_rtp_ready(switch_rtp_t *rtp_session)
Test if an RTP session is ready.
Definition: switch_rtp.c:5147
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.
void switch_jb_set_session(switch_jb_t *jb, switch_core_session_t *session)
#define READ_DEC(rtp_session)
Definition: switch_rtp.c:68
_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.
switch_rtcp_numbers_t rtcp
Definition: switch_types.h:762
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)
#define READ_INC(rtp_session)
Definition: switch_rtp.c:67
switch_status_t switch_jb_set_frames(switch_jb_t *jb, uint32_t min_frame_len, uint32_t max_frame_len)
switch_rtp_stats_t stats
Definition: switch_rtp.c:450
switch_memory_pool_t * pool
Definition: switch_rtp.c:393
switch_jb_t * jb
Definition: switch_rtp.c:434
switch_status_t
Common return values.
switch_core_session_t * session
Definition: switch_rtp.c:472
void switch_jb_set_jitter_estimator(switch_jb_t *jb, double *jitter, uint32_t samples_per_frame, uint32_t samples_per_second)
void switch_jb_ts_mode(switch_jb_t *jb, uint32_t samples_per_frame, uint32_t samples_per_second)

◆ switch_rtp_activate_rtcp()

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)

Parameters
send_rateinterval in milliseconds to send at
Returns
SWITCH_STATUS_SUCCESS

Definition at line 4875 of file switch_rtp.c.

References switch_rtp::eff_remote_host_str, enable_local_rtcp_socket(), enable_remote_rtcp_socket(), switch_rtp::flags, switch_rtp::from_addr, switch_rtp::local_addr, switch_rtp::ms_per_packet, switch_rtp::pool, switch_rtp::recv_msg, switch_rtp::remote_port, switch_rtp::remote_rtcp_port, switch_rtp::rtcp_from_addr, switch_rtp::rtcp_interval, switch_rtp::rtcp_local_addr, switch_rtp::rtcp_recv_msg, switch_rtp::rtcp_recv_msg_p, switch_rtp::rtcp_remote_addr, switch_rtp::rtcp_sock_input, switch_rtp::rtcp_sock_output, switch_rtp::session, switch_rtp::sock_input, switch_rtp::sock_output, SWITCH_CHANNEL_SESSION_LOG, SWITCH_LOG_DEBUG, SWITCH_LOG_ERROR, switch_log_printf(), SWITCH_RTP_FLAG_ENABLE_RTCP, SWITCH_RTP_FLAG_RTCP_MUX, SWITCH_RTP_FLAG_RTCP_PASSTHRU, switch_sockaddr_info_get(), SWITCH_STATUS_FALSE, SWITCH_STATUS_SUCCESS, and SWITCH_UNSPEC.

Referenced by check_ice(), and switch_core_media_activate_rtp().

4876 {
4877  const char *err = NULL;
4878 
4879  if (!rtp_session->ms_per_packet) {
4880  return SWITCH_STATUS_FALSE;
4881  }
4882 
4883  rtp_session->flags[SWITCH_RTP_FLAG_ENABLE_RTCP] = 1;
4884 
4885  if (!(rtp_session->remote_rtcp_port = remote_port)) {
4886  rtp_session->remote_rtcp_port = rtp_session->remote_port + 1;
4887  }
4888 
4889  if (mux) {
4890  rtp_session->flags[SWITCH_RTP_FLAG_RTCP_MUX]++;
4891  }
4892 
4893 
4894  if (send_rate == -1) {
4895 
4896  rtp_session->flags[SWITCH_RTP_FLAG_RTCP_PASSTHRU] = 1;
4897  switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(rtp_session->session), SWITCH_LOG_DEBUG, "RTCP passthru enabled. Remote Port: %d\n", rtp_session->remote_rtcp_port);
4898  } else {
4899  switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(rtp_session->session), SWITCH_LOG_DEBUG, "RTCP send rate is: %d and packet rate is: %d Remote Port: %d\n", send_rate, rtp_session->ms_per_packet, rtp_session->remote_rtcp_port);
4900 
4901  rtp_session->rtcp_interval = send_rate;
4902  }
4903 
4904  if (rtp_session->flags[SWITCH_RTP_FLAG_RTCP_MUX]) {
4905 
4907  rtp_session->remote_rtcp_port, 0, rtp_session->pool) != SWITCH_STATUS_SUCCESS || !rtp_session->rtcp_remote_addr) {
4908  switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(rtp_session->session), SWITCH_LOG_ERROR, "RTCP MUX Remote Address Error!");
4909  return SWITCH_STATUS_FALSE;
4910  }
4911 
4912  rtp_session->rtcp_local_addr = rtp_session->local_addr;
4913  rtp_session->rtcp_from_addr = rtp_session->from_addr;
4914  rtp_session->rtcp_sock_input = rtp_session->sock_input;
4915  rtp_session->rtcp_sock_output = rtp_session->sock_output;
4916 
4917  rtp_session->rtcp_recv_msg_p = (rtcp_msg_t *) &rtp_session->recv_msg;
4918 
4919  return SWITCH_STATUS_SUCCESS;
4920 
4921  //return enable_remote_rtcp_socket(rtp_session, &err);
4922  } else {
4923  rtp_session->rtcp_recv_msg_p = (rtcp_msg_t *) &rtp_session->rtcp_recv_msg;
4924  }
4925 
4926  return enable_local_rtcp_socket(rtp_session, &err) || enable_remote_rtcp_socket(rtp_session, &err);
4927 
4928 }
#define SWITCH_CHANNEL_SESSION_LOG(x)
switch_sockaddr_t * rtcp_from_addr
Definition: switch_rtp.c:394
switch_sockaddr_t * rtcp_local_addr
Definition: switch_rtp.c:326
switch_port_t remote_rtcp_port
Definition: switch_rtp.c:419
switch_socket_t * sock_input
Definition: switch_rtp.c:322
switch_port_t remote_port
Definition: switch_rtp.c:417
switch_socket_t * rtcp_sock_input
Definition: switch_rtp.c:322
rtcp_msg_t rtcp_recv_msg
Definition: switch_rtp.c:342
uint32_t flags[SWITCH_RTP_FLAG_INVALID]
Definition: switch_rtp.c:392
switch_sockaddr_t * local_addr
Definition: switch_rtp.c:326
switch_memory_pool_t * pool
Definition: switch_rtp.c:393
switch_socket_t * rtcp_sock_output
Definition: switch_rtp.c:322
int rtcp_interval
Definition: switch_rtp.c:458
static switch_status_t enable_remote_rtcp_socket(switch_rtp_t *rtp_session, const char **err)
Definition: switch_rtp.c:2673
rtp_msg_t recv_msg
Definition: switch_rtp.c:341
#define SWITCH_UNSPEC
Definition: switch_apr.h:1022
switch_core_session_t * session
Definition: switch_rtp.c:472
uint32_t ms_per_packet
Definition: switch_rtp.c:410
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.
switch_sockaddr_t * from_addr
Definition: switch_rtp.c:394
switch_sockaddr_t * rtcp_remote_addr
Definition: switch_rtp.c:340
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)
Definition: switch_apr.c:839
char * eff_remote_host_str
Definition: switch_rtp.c:402
static switch_status_t enable_local_rtcp_socket(switch_rtp_t *rtp_session, const char **err)
Definition: switch_rtp.c:2717
rtcp_msg_t * rtcp_recv_msg_p
Definition: switch_rtp.c:343
switch_socket_t * sock_output
Definition: switch_rtp.c:322

◆ switch_rtp_add_dtls()

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 
)

Definition at line 3813 of file switch_rtp.c.

References BIO_dtls_filter(), switch_dtls_s::ca, switch_directories::certs_dir, DS_HANDSHAKE, switch_rtp::dtls, dtls_set_state, DTLS_SRTP_FNAME, DTLS_TYPE_CLIENT, DTLS_TYPE_RTCP, DTLS_TYPE_RTP, DTLS_TYPE_SERVER, switch_dtls_s::filter_bio, switch_rtp::flags, switch_rtp::ice_mutex, switch_dtls_s::local_fp, MAX_DTLS_MTU, switch_dtls_s::mtu, switch_dtls_s::pem, switch_rtp::pool, switch_dtls_s::pvt, switch_dtls_s::read_bio, switch_dtls_s::remote_addr, switch_rtp::remote_addr, switch_dtls_s::remote_fp, switch_dtls_s::rsa, switch_rtp::rtcp_dtls, switch_rtp::rtcp_remote_addr, switch_rtp::rtcp_sock_output, switch_dtls_s::rtp_session, rtp_type, switch_rtp::session, switch_dtls_s::sock_output, switch_rtp::sock_output, switch_dtls_s::ssl, ssl_ctx, switch_dtls_s::ssl_ctx, ssl_method, dtls_fp_s::str, switch_assert, SWITCH_CAUSE_NORMAL_TEMPORARY_FAILURE, switch_channel_get_variable, switch_channel_hangup, SWITCH_CHANNEL_SESSION_LOG, switch_core_alloc, switch_core_cert_expand_fingerprint(), switch_core_session_get_channel(), switch_core_sprintf(), switch_file_exists(), SWITCH_GLOBAL_dirs, switch_goto_status, SWITCH_LOG_CRIT, SWITCH_LOG_ERROR, SWITCH_LOG_INFO, switch_log_printf(), SWITCH_LOG_WARNING, switch_mutex_lock(), switch_mutex_unlock(), SWITCH_PATH_SEPARATOR, switch_rtp_break(), switch_rtp_del_dtls(), SWITCH_RTP_FLAG_VIDEO_BREAK, switch_rtp_ready(), SWITCH_STATUS_FALSE, SWITCH_STATUS_SUCCESS, switch_dtls_s::type, switch_dtls_s::write_bio, and zstr.

Referenced by check_dtls_reinvite(), and switch_core_media_activate_rtp().

3814 {
3815  switch_dtls_t *dtls;
3816  const char *var;
3817  int ret;
3818  const char *kind = "";
3819  unsigned long ssl_method_error = 0;
3820  unsigned long ssl_ctx_error = 0;
3821  const SSL_METHOD *ssl_method;
3822  SSL_CTX *ssl_ctx;
3823 #if OPENSSL_VERSION_NUMBER < 0x30000000
3824  BIO *bio;
3825  DH *dh;
3826 #endif
3828 #ifndef OPENSSL_NO_EC
3829 #if OPENSSL_VERSION_NUMBER < 0x10002000L
3830  EC_KEY* ecdh;
3831 #endif
3832 #endif
3833 
3834 #ifndef HAVE_OPENSSL_DTLS_SRTP
3835  return SWITCH_STATUS_FALSE;
3836 #endif
3837 
3838  if (!switch_rtp_ready(rtp_session)) {
3839  return SWITCH_STATUS_FALSE;
3840  }
3841 
3842  switch_mutex_lock(rtp_session->ice_mutex);
3843 
3844  if (!((type & DTLS_TYPE_RTP) || (type & DTLS_TYPE_RTCP)) || !((type & DTLS_TYPE_CLIENT) || (type & DTLS_TYPE_SERVER))) {
3845  switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(rtp_session->session), SWITCH_LOG_CRIT, "INVALID TYPE!\n");
3846  }
3847 
3848  switch_rtp_del_dtls(rtp_session, type);
3849 
3850  if ((type & DTLS_TYPE_RTP) && (type & DTLS_TYPE_RTCP)) {
3851  kind = "RTP/RTCP";
3852  } else if ((type & DTLS_TYPE_RTP)) {
3853  kind = "RTP";
3854  } else {
3855  kind = "RTCP";
3856  }
3857 
3859  "Activate %s %s DTLS %s\n", kind, rtp_type(rtp_session), (type & DTLS_TYPE_SERVER) ? "server" : "client");
3860 
3861  if (((type & DTLS_TYPE_RTP) && rtp_session->dtls) || ((type & DTLS_TYPE_RTCP) && rtp_session->rtcp_dtls)) {
3862  switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(rtp_session->session), SWITCH_LOG_WARNING, "DTLS ALREADY INIT\n");
3864  }
3865 
3866  dtls = switch_core_alloc(rtp_session->pool, sizeof(*dtls));
3867 
3869 
3870  if (switch_file_exists(dtls->pem, rtp_session->pool) == SWITCH_STATUS_SUCCESS) {
3871  dtls->pvt = dtls->rsa = dtls->pem;
3872  } else {
3875  }
3876 
3877  dtls->ca = switch_core_sprintf(rtp_session->pool, "%s%sca-bundle.crt", SWITCH_GLOBAL_dirs.certs_dir, SWITCH_PATH_SEPARATOR);
3878 
3879 #if OPENSSL_VERSION_NUMBER >= 0x10100000
3880  ssl_method = (type & DTLS_TYPE_SERVER) ? DTLS_server_method() : DTLS_client_method();
3881 #else
3882  #ifdef HAVE_OPENSSL_DTLSv1_2_method
3883  ssl_method = (type & DTLS_TYPE_SERVER) ? (want_DTLSv1_2 ? DTLSv1_2_server_method() : DTLSv1_server_method()) : (want_DTLSv1_2 ? DTLSv1_2_client_method() : DTLSv1_client_method());
3884  #else
3885  ssl_method = (type & DTLS_TYPE_SERVER) ? DTLSv1_server_method() : DTLSv1_client_method();
3886  #endif // HAVE_OPENSSL_DTLSv1_2_method
3887 #endif
3888 
3889  if (!ssl_method) {
3890  ssl_method_error = ERR_peek_error();
3891  switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(rtp_session->session), SWITCH_LOG_ERROR, "%s ssl_method is NULL [%lu]\n", rtp_type(rtp_session), ssl_method_error);
3892  }
3893 
3894  dtls->ssl_ctx = ssl_ctx = SSL_CTX_new(ssl_method);
3895 
3896  if (!ssl_ctx) {
3897  ssl_ctx_error = ERR_peek_error();
3898  switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(rtp_session->session), SWITCH_LOG_ERROR, "%s SSL_CTX_new failed [%lu]\n", rtp_type(rtp_session), ssl_ctx_error);
3901  }
3902 
3903  switch_assert(dtls->ssl_ctx);
3904 
3905 #if OPENSSL_VERSION_NUMBER < 0x30000000
3906  bio = BIO_new_file(dtls->pem, "r");
3907  dh = PEM_read_bio_DHparams(bio, NULL, NULL, NULL);
3908  BIO_free(bio);
3909  if (dh) {
3910  SSL_CTX_set_tmp_dh(dtls->ssl_ctx, dh);
3911  DH_free(dh);
3912  }
3913 #else
3914  if(!SSL_CTX_set_dh_auto(dtls->ssl_ctx, 1)) {
3915  switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(rtp_session->session), SWITCH_LOG_ERROR, "Failed enable auto DH!\n");
3916  }
3917 #endif
3918  SSL_CTX_set_mode(dtls->ssl_ctx, SSL_MODE_AUTO_RETRY);
3919 
3920  //SSL_CTX_set_verify(dtls->ssl_ctx, SSL_VERIFY_PEER | SSL_VERIFY_FAIL_IF_NO_PEER_CERT, NULL);
3921  SSL_CTX_set_verify(dtls->ssl_ctx, SSL_VERIFY_NONE, NULL);
3922 
3923  //SSL_CTX_set_cipher_list(dtls->ssl_ctx, "ECDH:!RC4:!SSLv3:RSA_WITH_AES_128_CBC_SHA");
3924  //SSL_CTX_set_cipher_list(dtls->ssl_ctx, "ECDHE-RSA-AES256-GCM-SHA384");
3925  SSL_CTX_set_cipher_list(dtls->ssl_ctx, "ALL:!ADH:!LOW:!EXP:!MD5:@STRENGTH");
3926  //SSL_CTX_set_cipher_list(dtls->ssl_ctx, "SUITEB128");
3927  SSL_CTX_set_read_ahead(dtls->ssl_ctx, 1);
3928 #ifdef HAVE_OPENSSL_DTLS_SRTP
3929  //SSL_CTX_set_tlsext_use_srtp(dtls->ssl_ctx, "SRTP_AES128_CM_SHA1_80:SRTP_AES128_CM_SHA1_32");
3930  SSL_CTX_set_tlsext_use_srtp(dtls->ssl_ctx, "SRTP_AES128_CM_SHA1_80");
3931 #endif
3932 
3933  dtls->type = type;
3934  dtls->read_bio = BIO_new(BIO_s_mem());
3935  switch_assert(dtls->read_bio);
3936 
3937  dtls->write_bio = BIO_new(BIO_s_mem());
3938  switch_assert(dtls->write_bio);
3939 
3940  BIO_set_mem_eof_return(dtls->read_bio, -1);
3941  BIO_set_mem_eof_return(dtls->write_bio, -1);
3942 
3943  if ((ret=SSL_CTX_use_certificate_file(dtls->ssl_ctx, dtls->rsa, SSL_FILETYPE_PEM)) != 1) {
3944  switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(rtp_session->session), SWITCH_LOG_ERROR, "%s DTLS cert err [%d]\n", rtp_type(rtp_session), SSL_get_error(dtls->ssl, ret));
3946  }
3947 
3948  if ((ret=SSL_CTX_use_PrivateKey_file(dtls->ssl_ctx, dtls->pvt, SSL_FILETYPE_PEM)) != 1) {
3949  switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(rtp_session->session), SWITCH_LOG_ERROR, "%s DTLS key err [%d]\n", rtp_type(rtp_session), SSL_get_error(dtls->ssl, ret));
3951  }
3952 
3953  if (SSL_CTX_check_private_key(dtls->ssl_ctx) == 0) {
3954  switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(rtp_session->session), SWITCH_LOG_ERROR, "%s DTLS check key failed\n", rtp_type(rtp_session));
3956  }
3957 
3958  if (!zstr(dtls->ca) && switch_file_exists(dtls->ca, rtp_session->pool) == SWITCH_STATUS_SUCCESS
3959  && (ret = SSL_CTX_load_verify_locations(dtls->ssl_ctx, dtls->ca, NULL)) != 1) {
3960  switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(rtp_session->session), SWITCH_LOG_ERROR, "%s DTLS check chain cert failed [%d]\n",
3961  rtp_type(rtp_session) ,
3962  SSL_get_error(dtls->ssl, ret));
3964  }
3965 
3966  dtls->ssl = SSL_new(dtls->ssl_ctx);
3967 
3968 #if OPENSSL_VERSION_NUMBER < 0x10100000L
3969  dtls->filter_bio = BIO_new(BIO_dtls_filter());
3970 #else
3972  dtls->filter_bio = BIO_new(dtls_bio_filter_methods);
3973 #endif
3974 
3975  switch_assert(dtls->filter_bio);
3976 
3977  BIO_push(dtls->filter_bio, dtls->write_bio);
3978 
3979  SSL_set_bio(dtls->ssl, dtls->read_bio, dtls->filter_bio);
3980 
3981  SSL_set_mode(dtls->ssl, SSL_MODE_AUTO_RETRY);
3982  SSL_set_read_ahead(dtls->ssl, 1);
3983 
3984 
3985  //SSL_set_verify(dtls->ssl, (SSL_VERIFY_PEER | SSL_VERIFY_FAIL_IF_NO_PEER_CERT), cb_verify_peer);
3986 
3987 #ifndef OPENSSL_NO_EC
3988 #if OPENSSL_VERSION_NUMBER < 0x10002000L
3989  ecdh = EC_KEY_new_by_curve_name(NID_X9_62_prime256v1);
3990  if (!ecdh) {
3992  }
3993  SSL_set_options(dtls->ssl, SSL_OP_SINGLE_ECDH_USE);
3994  SSL_set_tmp_ecdh(dtls->ssl, ecdh);
3995  EC_KEY_free(ecdh);
3996 #elif OPENSSL_VERSION_NUMBER < 0x10100000L
3997  SSL_set_ecdh_auto(dtls->ssl, 1);
3998  SSL_set_options(dtls->ssl, SSL_OP_SINGLE_ECDH_USE);
3999 #endif
4000 #endif
4001 
4002  SSL_set_verify(dtls->ssl, SSL_VERIFY_NONE, NULL);
4003  SSL_set_app_data(dtls->ssl, dtls);
4004 
4005  dtls->local_fp = local_fp;
4006  dtls->remote_fp = remote_fp;
4007  dtls->rtp_session = rtp_session;
4008  dtls->mtu = 1200;
4009 
4010  if (rtp_session->session) {
4011  switch_channel_t *channel = switch_core_session_get_channel(rtp_session->session);
4012  if ((var = switch_channel_get_variable(channel, "rtp_dtls_mtu"))) {
4013  int mtu = atoi(var);
4014 
4015  if (mtu > 0 && mtu < MAX_DTLS_MTU) {
4016  dtls->mtu = mtu;
4017  }
4018 
4019  }
4020  }
4021 
4022  BIO_ctrl(dtls->filter_bio, BIO_CTRL_DGRAM_SET_MTU, dtls->mtu, NULL);
4023 
4024  switch_core_cert_expand_fingerprint(remote_fp, remote_fp->str);
4025 
4026  if ((type & DTLS_TYPE_RTP)) {
4027  rtp_session->dtls = dtls;
4028  dtls->sock_output = rtp_session->sock_output;
4029  dtls->remote_addr = rtp_session->remote_addr;
4030  }
4031 
4032  if ((type & DTLS_TYPE_RTCP)) {
4033  rtp_session->rtcp_dtls = dtls;
4034  if (!(type & DTLS_TYPE_RTP)) {
4035  dtls->sock_output = rtp_session->rtcp_sock_output;
4036  dtls->remote_addr = rtp_session->rtcp_remote_addr;
4037  }
4038  }
4039 
4040  if ((type & DTLS_TYPE_SERVER)) {
4041  SSL_set_accept_state(dtls->ssl);
4042  } else {
4043  SSL_set_connect_state(dtls->ssl);
4044  }
4045 
4047 
4048  rtp_session->flags[SWITCH_RTP_FLAG_VIDEO_BREAK] = 1;
4049  switch_rtp_break(rtp_session);
4050 
4051  done:
4052 
4053  switch_mutex_unlock(rtp_session->ice_mutex);
4054 
4055  return status;
4056 
4057 }
SSL_CTX * ssl_ctx
Definition: switch_rtp.c:273
#define switch_channel_hangup(channel, hangup_cause)
Hangup a channel flagging it&#39;s state machine to end.
dtls_fingerprint_t * remote_fp
Definition: switch_rtp.c:279
BIO_METHOD * BIO_dtls_filter(void)
Definition: switch_rtp.c:3472
#define SWITCH_CHANNEL_SESSION_LOG(x)
uint8_t switch_rtp_ready(switch_rtp_t *rtp_session)
Test if an RTP session is ready.
Definition: switch_rtp.c:5147
BIO * write_bio
Definition: switch_rtp.c:276
switch_status_t switch_rtp_del_dtls(switch_rtp_t *rtp_session, dtls_type_t type)
Definition: switch_rtp.c:3736
switch_sockaddr_t * remote_addr
Definition: switch_rtp.c:287
switch_sockaddr_t * remote_addr
Definition: switch_rtp.c:340
BIO * filter_bio
Definition: switch_rtp.c:277
BIO * read_bio
Definition: switch_rtp.c:275
char str[MAX_FPSTRLEN]
Definition: switch_core.h:156
#define zstr(x)
Definition: switch_utils.h:314
#define rtp_type(rtp_session)
Definition: switch_rtp.c:540
switch_status_t switch_mutex_unlock(switch_mutex_t *lock)
Definition: switch_apr.c:313
_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.
switch_socket_t * sock_output
Definition: switch_rtp.c:286
#define SWITCH_PATH_SEPARATOR
Definition: switch_types.h:124
switch_status_t switch_mutex_lock(switch_mutex_t *lock)
Definition: switch_apr.c:308
SSL_CTX * ssl_ctx
Definition: switch_msrp.c:66
uint32_t flags[SWITCH_RTP_FLAG_INVALID]
Definition: switch_rtp.c:392
#define switch_core_alloc(_pool, _mem)
Allocate memory directly from a memory pool.
Definition: switch_core.h:684
#define switch_channel_get_variable(_c, _v)
static BIO_METHOD dtls_bio_filter_methods
Definition: switch_rtp.c:3467
struct switch_rtp * rtp_session
Definition: switch_rtp.c:292
int switch_core_cert_expand_fingerprint(dtls_fingerprint_t *fp, const char *str)
switch_dtls_t * dtls
Definition: switch_rtp.c:366
#define dtls_set_state(_dtls, _state)
Definition: switch_rtp.c:3209
#define DTLS_SRTP_FNAME
Definition: switch_core.h:148
switch_directories SWITCH_GLOBAL_dirs
Definition: switch_core.c:82
switch_memory_pool_t * pool
Definition: switch_rtp.c:393
switch_socket_t * rtcp_sock_output
Definition: switch_rtp.c:322
switch_status_t switch_file_exists(const char *filename, switch_memory_pool_t *pool)
Definition: switch_apr.c:519
switch_status_t
Common return values.
#define switch_goto_status(_status, _label)
Definition: switch_utils.h:287
void switch_rtp_break(switch_rtp_t *rtp_session)
Definition: switch_rtp.c:5080
switch_mutex_t * ice_mutex
Definition: switch_rtp.c:429
switch_core_session_t * session
Definition: switch_rtp.c:472
switch_dtls_t * rtcp_dtls
Definition: switch_rtp.c:367
const SSL_METHOD * ssl_method
Definition: switch_msrp.c:65
dtls_type_t type
Definition: switch_rtp.c:283
dtls_fingerprint_t * local_fp
Definition: switch_rtp.c:278
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.
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_assert(expr)
switch_sockaddr_t * rtcp_remote_addr
Definition: switch_rtp.c:340
switch_socket_t * sock_output
Definition: switch_rtp.c:322
#define MAX_DTLS_MTU
Definition: switch_rtp.c:269

◆ switch_rtp_break()

void switch_rtp_break ( switch_rtp_t rtp_session)

Definition at line 5080 of file switch_rtp.c.

References CF_VIDEO_BREAK, switch_rtp::flag_mutex, switch_rtp::flags, ping_socket(), switch_rtp::session, switch_rtp::sock_input, switch_channel_clear_flag(), switch_channel_test_flag(), switch_core_session_get_channel(), switch_mutex_lock(), switch_mutex_unlock(), SWITCH_RTP_FLAG_BREAK, SWITCH_RTP_FLAG_NOBLOCK, SWITCH_RTP_FLAG_VIDEO, SWITCH_RTP_FLAG_VIDEO_BREAK, switch_rtp_ready(), and switch_rtp_video_refresh().

Referenced by switch_core_media_break(), switch_rtp_activate_ice(), switch_rtp_add_dtls(), and switch_rtp_udptl_mode().

5081 {
5082  if (!switch_rtp_ready(rtp_session)) {
5083  return;
5084  }
5085 
5086  if (rtp_session->flags[SWITCH_RTP_FLAG_VIDEO]) {
5087  int ret = 1;
5088 
5089  if (rtp_session->flags[SWITCH_RTP_FLAG_VIDEO_BREAK]) {
5090  rtp_session->flags[SWITCH_RTP_FLAG_VIDEO_BREAK] = 0;
5091  ret = 0;
5092  } else if (rtp_session->session) {
5093  switch_channel_t *channel = switch_core_session_get_channel(rtp_session->session);
5094  if (switch_channel_test_flag(channel, CF_VIDEO_BREAK)) {
5096  ret = 0;
5097  }
5098  }
5099 
5100  if (ret) return;
5101 
5102  switch_rtp_video_refresh(rtp_session);
5103  }
5104 
5105  switch_mutex_lock(rtp_session->flag_mutex);
5106  rtp_session->flags[SWITCH_RTP_FLAG_BREAK] = 1;
5107 
5108  if (rtp_session->flags[SWITCH_RTP_FLAG_NOBLOCK]) {
5109  switch_mutex_unlock(rtp_session->flag_mutex);
5110  return;
5111  }
5112 
5113  if (rtp_session->sock_input) {
5114  ping_socket(rtp_session);
5115  }
5116 
5117  switch_mutex_unlock(rtp_session->flag_mutex);
5118 }
uint8_t switch_rtp_ready(switch_rtp_t *rtp_session)
Test if an RTP session is ready.
Definition: switch_rtp.c:5147
switch_mutex_t * flag_mutex
Definition: switch_rtp.c:426
switch_socket_t * sock_input
Definition: switch_rtp.c:322
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_mutex_unlock(switch_mutex_t *lock)
Definition: switch_apr.c:313
_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.
switch_status_t switch_mutex_lock(switch_mutex_t *lock)
Definition: switch_apr.c:308
uint32_t flags[SWITCH_RTP_FLAG_INVALID]
Definition: switch_rtp.c:392
switch_core_session_t * session
Definition: switch_rtp.c:472
static void ping_socket(switch_rtp_t *rtp_session)
Definition: switch_rtp.c:3044
void switch_channel_clear_flag(switch_channel_t *channel, switch_channel_flag_t flag)
Clear given flag(s) from a channel.
void switch_rtp_video_refresh(switch_rtp_t *rtp_session)
Definition: switch_rtp.c:5056

◆ switch_rtp_change_interval()

switch_status_t switch_rtp_change_interval ( switch_rtp_t rtp_session,
uint32_t  ms_per_packet,
uint32_t  samples_per_interval 
)

Definition at line 4414 of file switch_rtp.c.

References memset(), switch_rtp::ms_per_packet, switch_rtp::pool, READ_DEC, READ_INC, switch_rtp::samples_per_interval, switch_rtp::session, SWITCH_CHANNEL_SESSION_LOG, switch_core_timer_destroy(), switch_core_timer_init(), SWITCH_LOG_DEBUG, SWITCH_LOG_ERROR, switch_log_printf(), switch_rtp_set_interval(), SWITCH_STATUS_SUCCESS, switch_rtp::timer, switch_timer::timer_interface, switch_rtp::timer_name, WRITE_DEC, WRITE_INC, and switch_rtp::write_timer.

Referenced by switch_core_media_set_codec().

4415 {
4417  int change_timer = 0;
4418 
4419  if (rtp_session->ms_per_packet != ms_per_packet || rtp_session->samples_per_interval != samples_per_interval) {
4420  change_timer = 1;
4421  }
4422 
4423  switch_rtp_set_interval(rtp_session, ms_per_packet, samples_per_interval);
4424 
4425  if (change_timer && rtp_session->timer_name) {
4426  READ_INC(rtp_session);
4427  WRITE_INC(rtp_session);
4428 
4429  if (rtp_session->timer.timer_interface) {
4430  switch_core_timer_destroy(&rtp_session->timer);
4431  }
4432 
4433  if (rtp_session->write_timer.timer_interface) {
4434  switch_core_timer_destroy(&rtp_session->write_timer);
4435  }
4436 
4437  if ((status = switch_core_timer_init(&rtp_session->timer,
4438  rtp_session->timer_name, ms_per_packet / 1000,
4439  samples_per_interval, rtp_session->pool)) == SWITCH_STATUS_SUCCESS) {
4440 
4442  "RE-Starting timer [%s] %d bytes per %dms\n", rtp_session->timer_name, samples_per_interval, ms_per_packet / 1000);
4443  switch_core_timer_init(&rtp_session->write_timer, rtp_session->timer_name, (ms_per_packet / 1000), samples_per_interval, rtp_session->pool);
4444  } else {
4445 
4446  memset(&rtp_session->timer, 0, sizeof(rtp_session->timer));
4448  "Problem RE-Starting timer [%s] %d bytes per %dms\n", rtp_session->timer_name, samples_per_interval, ms_per_packet / 1000);
4449  }
4450 
4451  WRITE_DEC(rtp_session);
4452  READ_DEC(rtp_session);
4453  }
4454 
4455  return status;
4456 }
#define SWITCH_CHANNEL_SESSION_LOG(x)
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.
#define WRITE_INC(rtp_session)
Definition: switch_rtp.c:69
#define READ_DEC(rtp_session)
Definition: switch_rtp.c:68
#define WRITE_DEC(rtp_session)
Definition: switch_rtp.c:70
switch_timer_interface_t * timer_interface
#define READ_INC(rtp_session)
Definition: switch_rtp.c:67
char * timer_name
Definition: switch_rtp.c:399
switch_status_t switch_core_timer_destroy(switch_timer_t *timer)
Destroy an allocated timer.
switch_memory_pool_t * pool
Definition: switch_rtp.c:393
switch_status_t
Common return values.
uint32_t samples_per_interval
Definition: switch_rtp.c:405
switch_timer_t timer
Definition: switch_rtp.c:430
switch_status_t switch_rtp_set_interval(switch_rtp_t *rtp_session, uint32_t ms_per_packet, uint32_t samples_per_interval)
Definition: switch_rtp.c:4401
switch_core_session_t * session
Definition: switch_rtp.c:472
switch_timer_t write_timer
Definition: switch_rtp.c:431
uint32_t ms_per_packet
Definition: switch_rtp.c:410
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.
memset(buf, 0, buflen)

◆ switch_rtp_check_auto_adj()

switch_byte_t switch_rtp_check_auto_adj ( switch_rtp_t rtp_session)

Definition at line 8046 of file switch_rtp.c.

References switch_rtp::auto_adj_used.

8047 {
8048  return rtp_session->auto_adj_used;
8049 }
switch_byte_t auto_adj_used
Definition: switch_rtp.c:463

◆ switch_rtp_clear_flag()

void switch_rtp_clear_flag ( switch_rtp_t rtp_session,
switch_rtp_flag_t  flag 
)

Clear an RTP Flag.

Parameters
rtp_sessionthe RTP session
flagsthe flags to clear

Definition at line 5431 of file switch_rtp.c.

References FALSE, switch_rtp::flag_mutex, switch_rtp::flags, switch_rtp_stats_t::inbound, switch_rtp_numbers_t::last_processed_seq, reset_jitter_seq(), switch_rtp::sock_input, switch_rtp::stats, SWITCH_FALSE, switch_mutex_lock(), switch_mutex_unlock(), SWITCH_RTP_FLAG_DTMF_ON, SWITCH_RTP_FLAG_NOBLOCK, SWITCH_RTP_FLAG_PASSTHRU, SWITCH_RTP_FLAG_PAUSE, switch_rtp_pause_jitter_buffer(), SWITCH_SO_NONBLOCK, and switch_socket_opt_set().

Referenced by do_flush(), handle_ice(), read_bundle_rtp_packet(), read_rtcp_packet(), read_rtp_packet(), rtp_common_read(), rtp_common_write(), rtp_flush_read_buffer(), switch_core_media_clear_rtp_flag(), switch_core_media_negotiate_sdp(), switch_core_media_receive_message(), switch_core_media_resume(), switch_core_media_toggle_hold(), switch_core_session_passthru(), switch_rtp_clear_flags(), switch_rtp_create(), switch_rtp_disable_vad(), switch_rtp_udptl_mode(), and switch_rtp_write_raw().

5432 {
5433  int old_flag = rtp_session->flags[flag];
5434 
5435  switch_mutex_lock(rtp_session->flag_mutex);
5436  rtp_session->flags[flag] = 0;
5437  switch_mutex_unlock(rtp_session->flag_mutex);
5438 
5439  if (flag == SWITCH_RTP_FLAG_PASSTHRU) {
5440  if (old_flag) {
5442  }
5443  } else if (flag == SWITCH_RTP_FLAG_DTMF_ON) {
5444  rtp_session->stats.inbound.last_processed_seq = 0;
5445  } else if (flag == SWITCH_RTP_FLAG_PAUSE) {
5446  reset_jitter_seq(rtp_session);
5447  } else if (flag == SWITCH_RTP_FLAG_NOBLOCK && rtp_session->sock_input) {
5449  }
5450 }
switch_rtp_numbers_t inbound
Definition: switch_types.h:760
switch_mutex_t * flag_mutex
Definition: switch_rtp.c:426
switch_socket_t * sock_input
Definition: switch_rtp.c:322
switch_status_t switch_rtp_pause_jitter_buffer(switch_rtp_t *rtp_session, switch_bool_t pause)
Definition: switch_rtp.c:4735
switch_status_t switch_mutex_unlock(switch_mutex_t *lock)
Definition: switch_apr.c:313
switch_status_t switch_mutex_lock(switch_mutex_t *lock)
Definition: switch_apr.c:308
uint32_t flags[SWITCH_RTP_FLAG_INVALID]
Definition: switch_rtp.c:392
switch_status_t switch_socket_opt_set(switch_socket_t *sock, int32_t opt, int32_t on)
Definition: switch_apr.c:907
switch_rtp_stats_t stats
Definition: switch_rtp.c:450
#define SWITCH_SO_NONBLOCK
Definition: switch_apr.h:994
#define FALSE
static void reset_jitter_seq(switch_rtp_t *rtp_session)
Definition: switch_rtp.c:1646

◆ switch_rtp_clear_flags()

void switch_rtp_clear_flags ( switch_rtp_t rtp_session,
switch_rtp_flag_t  flags[SWITCH_RTP_FLAG_INVALID] 
)

Definition at line 5361 of file switch_rtp.c.

References switch_rtp_clear_flag(), and SWITCH_RTP_FLAG_INVALID.

Referenced by switch_core_media_receive_message().

5362 {
5363  int i;
5364 
5365  for(i = 0; i < SWITCH_RTP_FLAG_INVALID; i++) {
5366  if (flags[i]) {
5367  switch_rtp_clear_flag(rtp_session, i);
5368  }
5369  }
5370 }
void switch_rtp_clear_flag(switch_rtp_t *rtp_session, switch_rtp_flag_t flag)
Clear an RTP Flag.
Definition: switch_rtp.c:5431

◆ switch_rtp_create()

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

Parameters
new_rtp_sessiona poiter to aim at the new session
payloadthe IANA payload number
samples_per_intervalthe default samples_per_interval
ms_per_packettime in microseconds per packet
flagsflags to control behaviour
timer_nametimer interface to use
erra pointer to resolve error messages
poola memory pool to use for the session
Returns
the new RTP session or NULL on failure

Definition at line 4473 of file switch_rtp.c.

References switch_rtp_numbers_t::burstrate, switch_rtp::cng_pt, switch_rtp::conf_samples_per_interval, switch_rtp::dtmf_data, switch_rtp_rfc2833_data::dtmf_inqueue, switch_rtp_rfc2833_data::dtmf_mutex, switch_rtp_rfc2833_data::dtmf_queue, switch_rtp::flag_mutex, switch_rtp::flags, switch_rtp::from_addr, rtp_msg_t::header, switch_rtp::ice_mutex, switch_rtp_stats_t::inbound, INVALID_PT, switch_rtp_numbers_t::jitter_add, switch_rtp_numbers_t::jitter_addsq, switch_rtp_numbers_t::jitter_n, switch_rtp_numbers_t::last_loss, switch_rtp_numbers_t::last_proc_time, switch_rtp_numbers_t::last_processed_seq, switch_rtp::last_write_ts, switch_rtp_numbers_t::loss, switch_rtp_numbers_t::lossrate, switch_rtp_numbers_t::max_variance, memset(), switch_rtp_numbers_t::min_variance, switch_rtp_numbers_t::mos, switch_rtp::payload, pool, switch_rtp::pool, switch_rtp_numbers_t::R, switch_rtp::read_mutex, switch_rtp::ready, switch_rtp::recv_msg, switch_rtp::recv_te, switch_rtp::rtcp_from_addr, switch_rtp::rtcp_last_sent, switch_rtp::rtp_from_addr, switch_rtp::send_msg, switch_rtp::seq, switch_rtp::session, switch_rtp::ssrc, switch_rtp::stats, SWITCH_CHANNEL_SESSION_LOG, switch_channel_set_private(), switch_core_alloc, switch_core_memory_pool_get_data(), switch_core_session_get_channel(), switch_core_strdup, switch_core_timer_init(), switch_epoch_time_now(), SWITCH_LOG_DEBUG, SWITCH_LOG_ERROR, switch_log_printf(), switch_micro_time_now(), switch_mutex_init(), SWITCH_MUTEX_NESTED, switch_queue_create(), switch_rtp_clear_flag(), SWITCH_RTP_FLAG_ENABLE_RTCP, SWITCH_RTP_FLAG_NOBLOCK, SWITCH_RTP_FLAG_USE_TIMER, SWITCH_RTP_FLAG_VIDEO, SWITCH_RTP_MAX_BUF_LEN, switch_rtp_set_flag(), switch_rtp_set_flags(), switch_rtp_set_interval(), switch_sockaddr_create(), SWITCH_STATUS_FALSE, SWITCH_STATUS_MEMERR, SWITCH_STATUS_SUCCESS, switch_rtp::te, switch_timer::tick, switch_rtp::timer, switch_rtp::timer_name, switch_rtp::write_mutex, switch_rtp::write_timer, and zstr.

Referenced by switch_rtp_new().

4478 {
4479  switch_rtp_t *rtp_session = NULL;
4481  switch_channel_t *channel = NULL;
4482 
4483  if (session) channel = switch_core_session_get_channel(session);
4484 
4485  *new_rtp_session = NULL;
4486 
4487  if (samples_per_interval > SWITCH_RTP_MAX_BUF_LEN) {
4488  *err = "Packet Size Too Large!";
4489  return SWITCH_STATUS_FALSE;
4490  }
4491 
4492  if (!(rtp_session = switch_core_alloc(pool, sizeof(*rtp_session)))) {
4493  *err = "Memory Error!";
4494  return SWITCH_STATUS_MEMERR;
4495  }
4496 
4497  rtp_session->pool = pool;
4498  rtp_session->te = INVALID_PT;
4499  rtp_session->recv_te = INVALID_PT;
4500  rtp_session->cng_pt = INVALID_PT;
4501  rtp_session->session = session;
4502 
4508  switch_queue_create(&rtp_session->dtmf_data.dtmf_queue, 100, rtp_session->pool);
4509  switch_queue_create(&rtp_session->dtmf_data.dtmf_inqueue, 100, rtp_session->pool);
4510 
4511  switch_rtp_set_flags(rtp_session, flags);
4512 
4513  /* for from address on recvfrom calls */
4514  switch_sockaddr_create(&rtp_session->from_addr, pool);
4515  switch_sockaddr_create(&rtp_session->rtp_from_addr, pool);
4516 
4517  if (rtp_session->flags[SWITCH_RTP_FLAG_ENABLE_RTCP]) {
4518  switch_sockaddr_create(&rtp_session->rtcp_from_addr, pool);
4519  }
4520 
4521  rtp_session->seq = (uint16_t) rand();
4522  rtp_session->ssrc = (uint32_t) ((intptr_t) rtp_session + (switch_time_t) switch_epoch_time_now(NULL));
4523 #ifdef DEBUG_TS_ROLLOVER
4524  rtp_session->last_write_ts = TS_ROLLOVER_START;
4525 #endif
4526  rtp_session->stats.inbound.R = 100.0;
4527  rtp_session->stats.inbound.mos = 4.5;
4528  rtp_session->send_msg.header.ssrc = htonl(rtp_session->ssrc);
4529  rtp_session->send_msg.header.ts = 0;
4530  rtp_session->send_msg.header.m = 0;
4531  rtp_session->send_msg.header.pt = (switch_payload_t) htonl(payload);
4532  rtp_session->send_msg.header.version = 2;
4533  rtp_session->send_msg.header.p = 0;
4534  rtp_session->send_msg.header.x = 0;
4535  rtp_session->send_msg.header.cc = 0;
4536 
4537  rtp_session->recv_msg.header.ssrc = 0;
4538  rtp_session->recv_msg.header.ts = 0;
4539  rtp_session->recv_msg.header.seq = 0;
4540  rtp_session->recv_msg.header.m = 0;
4541  rtp_session->recv_msg.header.pt = (switch_payload_t) htonl(payload);
4542  rtp_session->recv_msg.header.version = 2;
4543  rtp_session->recv_msg.header.p = 0;
4544  rtp_session->recv_msg.header.x = 0;
4545  rtp_session->recv_msg.header.cc = 0;
4546 
4547  rtp_session->payload = payload;
4548  rtp_session->rtcp_last_sent = switch_micro_time_now();
4549 
4550  switch_rtp_set_interval(rtp_session, ms_per_packet, samples_per_interval);
4551  rtp_session->conf_samples_per_interval = samples_per_interval;
4552 
4553  if (rtp_session->flags[SWITCH_RTP_FLAG_USE_TIMER] && zstr(timer_name)) {
4554  timer_name = "soft";
4555  }
4556 
4557  if (!zstr(timer_name) && !strcasecmp(timer_name, "none")) {
4558  timer_name = NULL;
4559  }
4560 
4561  if (!zstr(timer_name)) {
4562  rtp_session->timer_name = switch_core_strdup(pool, timer_name);
4565 
4566  if (switch_core_timer_init(&rtp_session->timer, timer_name, ms_per_packet / 1000, samples_per_interval, pool) == SWITCH_STATUS_SUCCESS) {
4568  "Starting timer [%s] %d bytes per %dms\n", timer_name, samples_per_interval, ms_per_packet / 1000);
4569  switch_core_timer_init(&rtp_session->write_timer, timer_name, (ms_per_packet / 1000), samples_per_interval, pool);
4570 #ifdef DEBUG_TS_ROLLOVER
4571  rtp_session->timer.tick = TS_ROLLOVER_START / samples_per_interval;
4572 #endif
4573  } else {
4574  memset(&rtp_session->timer, 0, sizeof(rtp_session->timer));
4576  "Error Starting timer [%s] %d bytes per %dms, async RTP disabled\n", timer_name, samples_per_interval, ms_per_packet / 1000);
4578  }
4579  } else {
4580  if (rtp_session->flags[SWITCH_RTP_FLAG_VIDEO]) {
4581  if (switch_core_timer_init(&rtp_session->timer, "soft", 1, 90, pool) == SWITCH_STATUS_SUCCESS) {
4582  switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(rtp_session->session), SWITCH_LOG_DEBUG, "Starting video timer.\n");
4583  }
4584 
4585  //switch_jb_create(&rtp_session->vb, 3, 10, rtp_session->pool);
4586  //switch_jb_debug_level(rtp_session->vb, 10);
4587 
4588  } else {
4589  switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(rtp_session->session), SWITCH_LOG_DEBUG, "Not using a timer\n");
4590  }
4591 
4594  }
4595 
4596 
4597  if (channel) {
4598  switch_channel_set_private(channel, "__rtcp_audio_rtp_session", rtp_session);
4599  }
4600 
4601 
4602  /* Jitter */
4603  rtp_session->stats.inbound.last_proc_time = switch_micro_time_now() / 1000;
4604  rtp_session->stats.inbound.jitter_n = 0;
4605  rtp_session->stats.inbound.jitter_add = 0;
4606  rtp_session->stats.inbound.jitter_addsq = 0;
4607  rtp_session->stats.inbound.min_variance = 0;
4608  rtp_session->stats.inbound.max_variance = 0;
4609 
4610  /* Burst and Packet Loss */
4611  rtp_session->stats.inbound.lossrate = 0;
4612  rtp_session->stats.inbound.burstrate = 0;
4613  memset(rtp_session->stats.inbound.loss, 0, sizeof(rtp_session->stats.inbound.loss));
4614  rtp_session->stats.inbound.last_loss = 0;
4615  rtp_session->stats.inbound.last_processed_seq = -1;
4616 
4617  rtp_session->ready = 1;
4618  *new_rtp_session = rtp_session;
4619 
4620  return SWITCH_STATUS_SUCCESS;
4621 }
switch_time_t rtcp_last_sent
Definition: switch_rtp.c:408
switch_time_t switch_micro_time_now(void)
Get the current epoch time in microseconds.
Definition: switch_time.c:311
int loss[LOST_BURST_CAPTURE]
Definition: switch_types.h:708
#define SWITCH_CHANNEL_SESSION_LOG(x)
switch_rtp_numbers_t inbound
Definition: switch_types.h:760
switch_sockaddr_t * rtcp_from_addr
Definition: switch_rtp.c:394
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.
switch_core_session_t * session
switch_status_t switch_channel_set_private(switch_channel_t *channel, const char *key, const void *private_info)
Set private data on channel.
switch_mutex_t * write_mutex
Definition: switch_rtp.c:428
switch_mutex_t * flag_mutex
Definition: switch_rtp.c:426
#define switch_core_strdup(_pool, _todup)
Copy a string using memory allocation from a given pool.
Definition: switch_core.h:733
switch_memory_pool_t * pool
void * switch_core_memory_pool_get_data(switch_memory_pool_t *pool, const char *key)
#define SWITCH_RTP_MAX_BUF_LEN
Definition: switch_rtp.h:45
struct switch_rtp_rfc2833_data dtmf_data
Definition: switch_rtp.c:422
#define zstr(x)
Definition: switch_utils.h:314
switch_payload_t cng_pt
Definition: switch_rtp.c:425
_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.
#define SWITCH_MUTEX_NESTED
Definition: switch_apr.h:318
int64_t switch_time_t
Definition: switch_apr.h:188
switch_queue_t * dtmf_inqueue
Definition: switch_rtp.c:237
uint8_t ready
Definition: switch_rtp.c:432
uint32_t flags[SWITCH_RTP_FLAG_INVALID]
Definition: switch_rtp.c:392
switch_mutex_t * dtmf_mutex
Definition: switch_rtp.c:238
switch_status_t switch_sockaddr_create(switch_sockaddr_t **sa, switch_memory_pool_t *pool)
Definition: switch_apr.c:818
#define switch_core_alloc(_pool, _mem)
Allocate memory directly from a memory pool.
Definition: switch_core.h:684
void switch_rtp_set_flags(switch_rtp_t *rtp_session, switch_rtp_flag_t flags[SWITCH_RTP_FLAG_INVALID])
Definition: switch_rtp.c:5350
switch_sockaddr_t * rtp_from_addr
Definition: switch_rtp.c:394
switch_status_t switch_mutex_init(switch_mutex_t **lock, unsigned int flags, switch_memory_pool_t *pool)
Definition: switch_apr.c:293
uint16_t seq
Definition: switch_rtp.c:371
char * timer_name
Definition: switch_rtp.c:399
switch_rtp_stats_t stats
Definition: switch_rtp.c:450
switch_memory_pool_t * pool
Definition: switch_rtp.c:393
void switch_rtp_clear_flag(switch_rtp_t *rtp_session, switch_rtp_flag_t flag)
Clear an RTP Flag.
Definition: switch_rtp.c:5431
void switch_rtp_set_flag(switch_rtp_t *rtp_session, switch_rtp_flag_t flag)
Set an RTP Flag.
Definition: switch_rtp.c:5372
switch_mutex_t * read_mutex
Definition: switch_rtp.c:427
srtp_hdr_t header
Definition: switch_rtp.c:112
switch_timer_t timer
Definition: switch_rtp.c:430
rtp_msg_t recv_msg
Definition: switch_rtp.c:341
uint32_t last_write_ts
Definition: switch_rtp.c:382
switch_mutex_t * ice_mutex
Definition: switch_rtp.c:429
switch_status_t switch_rtp_set_interval(switch_rtp_t *rtp_session, uint32_t ms_per_packet, uint32_t samples_per_interval)
Definition: switch_rtp.c:4401
switch_core_session_t * session
Definition: switch_rtp.c:472
switch_timer_t write_timer
Definition: switch_rtp.c:431
time_t switch_epoch_time_now(time_t *t)
Get the current epoch time.
Definition: switch_time.c:322
switch_payload_t te
Definition: switch_rtp.c:423
switch_payload_t recv_te
Definition: switch_rtp.c:424
switch_queue_t * dtmf_queue
Definition: switch_rtp.c:221
uint32_t ssrc
Definition: switch_rtp.c:372
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.
uint32_t conf_samples_per_interval
Definition: switch_rtp.c:407
switch_status_t switch_queue_create(switch_queue_t **queue, unsigned int queue_capacity, switch_memory_pool_t *pool)
Definition: switch_apr.c:1233
rtp_msg_t send_msg
Definition: switch_rtp.c:327
switch_sockaddr_t * from_addr
Definition: switch_rtp.c:394
static const switch_payload_t INVALID_PT
Definition: switch_rtp.c:81
switch_payload_t payload
Definition: switch_rtp.c:377
memset(buf, 0, buflen)
uint8_t switch_payload_t

◆ switch_rtp_deactivate_jitter_buffer()

switch_status_t switch_rtp_deactivate_jitter_buffer ( switch_rtp_t rtp_session)

Definition at line 4761 of file switch_rtp.c.

References switch_rtp::flags, SWITCH_RTP_FLAG_KILL_JB, switch_rtp_ready(), SWITCH_STATUS_FALSE, and SWITCH_STATUS_SUCCESS.

Referenced by check_jb().

4762 {
4763 
4764  if (!switch_rtp_ready(rtp_session)) {
4765  return SWITCH_STATUS_FALSE;
4766  }
4767 
4768  rtp_session->flags[SWITCH_RTP_FLAG_KILL_JB]++;
4769 
4770  return SWITCH_STATUS_SUCCESS;
4771 }
uint8_t switch_rtp_ready(switch_rtp_t *rtp_session)
Test if an RTP session is ready.
Definition: switch_rtp.c:5147
uint32_t flags[SWITCH_RTP_FLAG_INVALID]
Definition: switch_rtp.c:392

◆ switch_rtp_debug_jitter_buffer()

switch_status_t switch_rtp_debug_jitter_buffer ( switch_rtp_t rtp_session,
const char *  name 
)

Definition at line 4814 of file switch_rtp.c.

References switch_rtp::jb, switch_jb_debug_level(), switch_rtp_ready(), SWITCH_STATUS_FALSE, SWITCH_STATUS_SUCCESS, and switch_rtp::vb.

Referenced by check_jb().

4815 {
4816  int x = 0;
4817 
4818  if (!switch_rtp_ready(rtp_session)) {
4819  return SWITCH_STATUS_FALSE;
4820  }
4821 
4822  if (name) x = atoi(name);
4823  if (x < 0) x = 0;
4824 
4825  if (rtp_session->jb) {
4826  switch_jb_debug_level(rtp_session->jb, x);
4827  } else if (rtp_session->vb) {
4828  switch_jb_debug_level(rtp_session->vb, x);
4829  }
4830 
4831  return SWITCH_STATUS_SUCCESS;
4832 }
uint8_t switch_rtp_ready(switch_rtp_t *rtp_session)
Test if an RTP session is ready.
Definition: switch_rtp.c:5147
switch_jb_t * vb
Definition: switch_rtp.c:435
void switch_jb_debug_level(switch_jb_t *jb, uint8_t level)
switch_jb_t * jb
Definition: switch_rtp.c:434
const char *const name
Definition: switch_cJSON.h:250

◆ switch_rtp_del_dtls()

switch_status_t switch_rtp_del_dtls ( switch_rtp_t rtp_session,
dtls_type_t  type 
)

Definition at line 3736 of file switch_rtp.c.

References switch_rtp::dtls, DTLS_TYPE_RTCP, DTLS_TYPE_RTP, switch_rtp::flags, free_dtls(), switch_rtp::ice_mutex, switch_rtp::jb, switch_rtp::recv_ctx, switch_rtp::rtcp_dtls, switch_rtp::send_ctx, switch_goto_status, switch_jb_reset(), switch_mutex_lock(), switch_mutex_unlock(), SWITCH_RTP_FLAG_SECURE_RECV, SWITCH_RTP_FLAG_SECURE_SEND, SWITCH_STATUS_FALSE, SWITCH_STATUS_SUCCESS, switch_rtp::vb, and switch_rtp::vbw.

Referenced by switch_rtp_add_dtls().

3737 {
3739 
3740  if (!rtp_session) {
3741  return SWITCH_STATUS_FALSE;
3742  }
3743 
3744  switch_mutex_lock(rtp_session->ice_mutex);
3745 
3746  if (!rtp_session->dtls && !rtp_session->rtcp_dtls) {
3748  }
3749 
3750  if ((type & DTLS_TYPE_RTP)) {
3751  if (rtp_session->dtls && rtp_session->dtls == rtp_session->rtcp_dtls) {
3752  rtp_session->rtcp_dtls = NULL;
3753  }
3754 
3755  if (rtp_session->dtls) {
3756  free_dtls(&rtp_session->dtls);
3757  }
3758 
3759  if (rtp_session->jb) {
3760  switch_jb_reset(rtp_session->jb);
3761  }
3762 
3763  if (rtp_session->vb) {
3764  switch_jb_reset(rtp_session->vb);
3765  }
3766 
3767  if (rtp_session->vbw) {
3768  switch_jb_reset(rtp_session->vbw);
3769  }
3770 
3771  }
3772 
3773  if ((type & DTLS_TYPE_RTCP) && rtp_session->rtcp_dtls) {
3774  free_dtls(&rtp_session->rtcp_dtls);
3775  }
3776 
3777 
3778 #ifdef ENABLE_SRTP
3779  if (rtp_session->flags[SWITCH_RTP_FLAG_SECURE_SEND]) {
3780  int x;
3781 
3782  rtp_session->flags[SWITCH_RTP_FLAG_SECURE_SEND] = 0;
3783 
3784  for(x = 0; x < 2; x++) {
3785  if (rtp_session->send_ctx[x]) {
3786  srtp_dealloc(rtp_session->send_ctx[x]);
3787  rtp_session->send_ctx[x] = NULL;
3788  }
3789  }
3790  }
3791 
3792  if (rtp_session->flags[SWITCH_RTP_FLAG_SECURE_RECV]) {
3793  int x;
3794 
3795  rtp_session->flags[SWITCH_RTP_FLAG_SECURE_RECV] = 0;
3796 
3797  for (x = 0; x < 2; x++) {
3798  if (rtp_session->recv_ctx[x]) {
3799  srtp_dealloc(rtp_session->recv_ctx[x]);
3800  rtp_session->recv_ctx[x] = NULL;
3801  }
3802  }
3803  }
3804 #endif
3805 
3806  done:
3807 
3808  switch_mutex_unlock(rtp_session->ice_mutex);
3809 
3810  return status;
3811 }
static void free_dtls(switch_dtls_t **dtlsp)
Definition: switch_rtp.c:3344
switch_jb_t * vbw
Definition: switch_rtp.c:436
switch_status_t switch_mutex_unlock(switch_mutex_t *lock)
Definition: switch_apr.c:313
srtp_ctx_t * send_ctx[2]
Definition: switch_rtp.c:353
switch_status_t switch_mutex_lock(switch_mutex_t *lock)
Definition: switch_apr.c:308
uint32_t flags[SWITCH_RTP_FLAG_INVALID]
Definition: switch_rtp.c:392
srtp_ctx_t * recv_ctx[2]
Definition: switch_rtp.c:354
switch_dtls_t * dtls
Definition: switch_rtp.c:366
switch_jb_t * vb
Definition: switch_rtp.c:435
switch_jb_t * jb
Definition: switch_rtp.c:434
switch_status_t
Common return values.
#define switch_goto_status(_status, _label)
Definition: switch_utils.h:287
switch_mutex_t * ice_mutex
Definition: switch_rtp.c:429
void switch_jb_reset(switch_jb_t *jb)
switch_dtls_t * rtcp_dtls
Definition: switch_rtp.c:367

◆ switch_rtp_dequeue_dtmf()

switch_size_t switch_rtp_dequeue_dtmf ( switch_rtp_t rtp_session,
switch_dtmf_t dtmf 
)

Retrieve DTMF digits from a given RTP session.

Parameters
rtp_sessionRTP session to retrieve digits from
dtmfthe dtmf
Returns
number of bytes read into the buffer

Definition at line 8064 of file switch_rtp.c.

References switch_dtmf_t::digit, switch_rtp::dtmf_data, switch_rtp_rfc2833_data::dtmf_inqueue, switch_rtp_rfc2833_data::dtmf_mutex, switch_dtmf_t::duration, switch_rtp::session, SWITCH_CHANNEL_SESSION_LOG, switch_channel_var_true(), switch_core_session_get_channel(), SWITCH_LOG_DEBUG, switch_log_printf(), switch_mutex_lock(), switch_mutex_unlock(), switch_queue_trypop(), switch_rtp_ready(), SWITCH_SENSITIVE_DTMF_VARIABLE, and SWITCH_STATUS_SUCCESS.

Referenced by switch_core_media_read_frame().

8065 {
8066  switch_size_t bytes = 0;
8067  switch_dtmf_t *_dtmf = NULL;
8068  void *pop;
8069 
8070  if (!switch_rtp_ready(rtp_session)) {
8071  return bytes;
8072  }
8073 
8074  switch_mutex_lock(rtp_session->dtmf_data.dtmf_mutex);
8075  if (switch_queue_trypop(rtp_session->dtmf_data.dtmf_inqueue, &pop) == SWITCH_STATUS_SUCCESS) {
8076 
8077  _dtmf = (switch_dtmf_t *)pop;
8078  *dtmf = *_dtmf;
8079  /* Only log DTMF buffer if sensitive_dtmf channel variable not set to true */
8081  switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(rtp_session->session), SWITCH_LOG_DEBUG,"RTP RECV DTMF %c:%d\n", dtmf->digit, dtmf->duration);
8082  }
8083  bytes++;
8084  free(pop);
8085  }
8087 
8088  return bytes;
8089 }
#define SWITCH_SENSITIVE_DTMF_VARIABLE
Definition: switch_types.h:146
#define SWITCH_CHANNEL_SESSION_LOG(x)
uint8_t switch_rtp_ready(switch_rtp_t *rtp_session)
Test if an RTP session is ready.
Definition: switch_rtp.c:5147
switch_status_t switch_queue_trypop(switch_queue_t *queue, void **data)
Definition: switch_apr.c:1264
uint32_t duration
Definition: switch_types.h:298
struct switch_rtp_rfc2833_data dtmf_data
Definition: switch_rtp.c:422
switch_status_t switch_mutex_unlock(switch_mutex_t *lock)
Definition: switch_apr.c:313
_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.
switch_queue_t * dtmf_inqueue
Definition: switch_rtp.c:237
switch_status_t switch_mutex_lock(switch_mutex_t *lock)
Definition: switch_apr.c:308
switch_mutex_t * dtmf_mutex
Definition: switch_rtp.c:238
uintptr_t switch_size_t
static int switch_channel_var_true(switch_channel_t *channel, const char *variable)
switch_core_session_t * session
Definition: switch_rtp.c:472
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.

◆ switch_rtp_destroy()

void switch_rtp_destroy ( switch_rtp_t **  rtp_session)

Destroy an RTP session.

Parameters
rtp_sessionan RTP session to destroy

Definition at line 5186 of file switch_rtp.c.

References free_dtls(), READ_DEC, READ_INC, switch_rtp::ready, SWITCH_CHANNEL_SESSION_LOG, switch_core_timer_destroy(), switch_jb_destroy(), switch_jb_get_nack_success(), SWITCH_LOG_DEBUG, switch_log_printf(), switch_mutex_lock(), switch_mutex_unlock(), switch_queue_trypop(), switch_rtp_disable_vad(), SWITCH_RTP_FLAG_SECURE_RECV, SWITCH_RTP_FLAG_SECURE_SEND, SWITCH_RTP_FLAG_SHUTDOWN, SWITCH_RTP_FLAG_VAD, switch_rtp_kill_socket(), switch_rtp_release_port(), switch_safe_free, switch_socket_close(), SWITCH_STATUS_SUCCESS, WRITE_DEC, and WRITE_INC.

Referenced by switch_core_media_deactivate_rtp().

5187 {
5188  void *pop;
5189  switch_socket_t *sock;
5190 #ifdef ENABLE_SRTP
5191  int x;
5192 #endif
5193 
5194  if (!rtp_session || !*rtp_session || !(*rtp_session)->ready) {
5195  return;
5196  }
5197 
5198  if ((*rtp_session)->vb) {
5199  /* retrieve counter for ALL received NACKed packets */
5200  uint32_t nack_jb_ok = switch_jb_get_nack_success((*rtp_session)->vb);
5202  "NACK: Added to JB: [%u]\n", nack_jb_ok);
5203  }
5204 
5205  (*rtp_session)->flags[SWITCH_RTP_FLAG_SHUTDOWN] = 1;
5206 
5207  READ_INC((*rtp_session));
5208  WRITE_INC((*rtp_session));
5209 
5210  (*rtp_session)->ready = 0;
5211 
5212  WRITE_DEC((*rtp_session));
5213  READ_DEC((*rtp_session));
5214 
5215  if ((*rtp_session)->flags[SWITCH_RTP_FLAG_VAD]) {
5216  switch_rtp_disable_vad(*rtp_session);
5217  }
5218 
5219  switch_mutex_lock((*rtp_session)->flag_mutex);
5220 
5221  switch_rtp_kill_socket(*rtp_session);
5222 
5223  while (switch_queue_trypop((*rtp_session)->dtmf_data.dtmf_inqueue, &pop) == SWITCH_STATUS_SUCCESS) {
5224  switch_safe_free(pop);
5225  }
5226 
5227  while (switch_queue_trypop((*rtp_session)->dtmf_data.dtmf_queue, &pop) == SWITCH_STATUS_SUCCESS) {
5228  switch_safe_free(pop);
5229  }
5230 
5231  if ((*rtp_session)->jb) {
5232  switch_jb_destroy(&(*rtp_session)->jb);
5233  }
5234 
5235  if ((*rtp_session)->vb) {
5236  switch_jb_destroy(&(*rtp_session)->vb);
5237  }
5238 
5239  if ((*rtp_session)->vbw) {
5240  switch_jb_destroy(&(*rtp_session)->vbw);
5241  }
5242 
5243  if ((*rtp_session)->dtls && (*rtp_session)->dtls == (*rtp_session)->rtcp_dtls) {
5244  (*rtp_session)->rtcp_dtls = NULL;
5245  }
5246 
5247  if ((*rtp_session)->dtls) {
5248  free_dtls(&(*rtp_session)->dtls);
5249  }
5250 
5251  if ((*rtp_session)->rtcp_dtls) {
5252  free_dtls(&(*rtp_session)->rtcp_dtls);
5253  }
5254 
5255  if ((*rtp_session)->rtcp_sock_input == (*rtp_session)->sock_input) {
5256  (*rtp_session)->rtcp_sock_input = NULL;
5257  }
5258 
5259  if ((*rtp_session)->rtcp_sock_output == (*rtp_session)->sock_output) {
5260  (*rtp_session)->rtcp_sock_output = NULL;
5261  }
5262 
5263  sock = (*rtp_session)->sock_input;
5264  (*rtp_session)->sock_input = NULL;
5265  switch_socket_close(sock);
5266 
5267  if ((*rtp_session)->sock_output != sock) {
5268  sock = (*rtp_session)->sock_output;
5269  (*rtp_session)->sock_output = NULL;
5270  switch_socket_close(sock);
5271  }
5272 
5273  if ((sock = (*rtp_session)->rtcp_sock_input)) {
5274  (*rtp_session)->rtcp_sock_input = NULL;
5275  switch_socket_close(sock);
5276  }
5277 
5278  if ((*rtp_session)->rtcp_sock_output && (*rtp_session)->rtcp_sock_output != sock) {
5279  sock = (*rtp_session)->rtcp_sock_output;
5280  (*rtp_session)->rtcp_sock_output = NULL;
5281  switch_socket_close(sock);
5282  }
5283 
5284 #ifdef ENABLE_SRTP
5285  if ((*rtp_session)->flags[SWITCH_RTP_FLAG_SECURE_SEND]) {
5286  for(x = 0; x < 2; x++) {
5287  if ((*rtp_session)->send_ctx[x]) {
5288  srtp_dealloc((*rtp_session)->send_ctx[x]);
5289  (*rtp_session)->send_ctx[x] = NULL;
5290  }
5291  }
5292  (*rtp_session)->flags[SWITCH_RTP_FLAG_SECURE_SEND] = 0;
5293  }
5294 
5295  if ((*rtp_session)->flags[SWITCH_RTP_FLAG_SECURE_RECV]) {
5296  for (x = 0; x < 2; x++) {
5297  if ((*rtp_session)->recv_ctx[x]) {
5298  srtp_dealloc((*rtp_session)->recv_ctx[x]);
5299  (*rtp_session)->recv_ctx[x] = NULL;
5300  }
5301  }
5302  (*rtp_session)->flags[SWITCH_RTP_FLAG_SECURE_RECV] = 0;
5303  }
5304 #endif
5305 
5306  if ((*rtp_session)->timer.timer_interface) {
5307  switch_core_timer_destroy(&(*rtp_session)->timer);
5308  }
5309 
5310  if ((*rtp_session)->write_timer.timer_interface) {
5311  switch_core_timer_destroy(&(*rtp_session)->write_timer);
5312  }
5313 
5314  switch_rtp_release_port((*rtp_session)->rx_host, (*rtp_session)->rx_port);
5315  switch_mutex_unlock((*rtp_session)->flag_mutex);
5316 
5317  return;
5318 }
#define SWITCH_CHANNEL_SESSION_LOG(x)
static void free_dtls(switch_dtls_t **dtlsp)
Definition: switch_rtp.c:3344
#define WRITE_INC(rtp_session)
Definition: switch_rtp.c:69
switch_status_t switch_queue_trypop(switch_queue_t *queue, void **data)
Definition: switch_apr.c:1264
switch_status_t switch_jb_destroy(switch_jb_t **jbp)
#define READ_DEC(rtp_session)
Definition: switch_rtp.c:68
switch_status_t switch_mutex_unlock(switch_mutex_t *lock)
Definition: switch_apr.c:313
#define WRITE_DEC(rtp_session)
Definition: switch_rtp.c:70
uint8_t ready
Definition: switch_rtp.c:432
uint32_t switch_jb_get_nack_success(switch_jb_t *jb)
switch_status_t switch_mutex_lock(switch_mutex_t *lock)
Definition: switch_apr.c:308
switch_status_t switch_rtp_disable_vad(switch_rtp_t *rtp_session)
Disable VAD on an RTP Session.
Definition: switch_rtp.c:8815
#define switch_safe_free(it)
Free a pointer and set it to NULL unless it already is NULL.
Definition: switch_utils.h:885
#define READ_INC(rtp_session)
Definition: switch_rtp.c:67
switch_status_t switch_core_timer_destroy(switch_timer_t *timer)
Destroy an allocated timer.
switch_status_t switch_socket_close(switch_socket_t *sock)
Definition: switch_apr.c:737
void switch_rtp_release_port(const char *ip, switch_port_t port)
Definition: switch_rtp.c:2610
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.
struct fspr_socket_t switch_socket_t
Definition: switch_apr.h:1026
void switch_rtp_kill_socket(switch_rtp_t *rtp_session)
Kill the socket on an existing RTP session.
Definition: switch_rtp.c:5120

◆ switch_rtp_disable_vad()

switch_status_t switch_rtp_disable_vad ( switch_rtp_t rtp_session)

Disable VAD on an RTP Session.

Parameters
rtp_sessionthe RTP session
Returns
SWITCH_STAUTS_SUCCESS on success

Definition at line 8815 of file switch_rtp.c.

References switch_rtp::flags, switch_core_codec_destroy(), switch_rtp_clear_flag(), SWITCH_RTP_FLAG_VAD, SWITCH_STATUS_FALSE, SWITCH_STATUS_GENERR, SWITCH_STATUS_SUCCESS, switch_rtp_vad_data::vad_codec, and switch_rtp::vad_data.

Referenced by switch_rtp_destroy().

8816 {
8817 
8818  if (!rtp_session) {
8819  return SWITCH_STATUS_FALSE;
8820  }
8821 
8822  if (!rtp_session->flags[SWITCH_RTP_FLAG_VAD]) {
8823  return SWITCH_STATUS_GENERR;
8824  }
8827  return SWITCH_STATUS_SUCCESS;
8828 }
struct switch_rtp_vad_data vad_data
Definition: switch_rtp.c:421
switch_status_t switch_core_codec_destroy(switch_codec_t *codec)
Destroy an initalized codec handle.
switch_codec_t vad_codec
Definition: switch_rtp.c:196
uint32_t flags[SWITCH_RTP_FLAG_INVALID]
Definition: switch_rtp.c:392
void switch_rtp_clear_flag(switch_rtp_t *rtp_session, switch_rtp_flag_t flag)
Clear an RTP Flag.
Definition: switch_rtp.c:5431

◆ switch_rtp_dtls_state()

dtls_state_t switch_rtp_dtls_state ( switch_rtp_t rtp_session,
dtls_type_t  type 
)

Definition at line 3705 of file switch_rtp.c.

References DS_OFF, switch_rtp::dtls, DTLS_TYPE_RTCP, DTLS_TYPE_RTP, switch_rtp::ice_mutex, switch_rtp::rtcp_dtls, switch_dtls_s::state, switch_mutex_lock(), and switch_mutex_unlock().

Referenced by check_engine().

3706 {
3707  dtls_state_t s = DS_OFF;
3708 
3709  if (!rtp_session) {
3710  return s;
3711  }
3712 
3713  switch_mutex_lock(rtp_session->ice_mutex);
3714 
3715  if (!rtp_session->dtls && !rtp_session->rtcp_dtls) {
3716  s = DS_OFF;
3717  goto done;
3718  }
3719 
3720  if ((type == DTLS_TYPE_RTP) && rtp_session->dtls) {
3721  s = rtp_session->dtls->state;
3722  goto done;
3723  }
3724 
3725  if ((type == DTLS_TYPE_RTCP) && rtp_session->rtcp_dtls) {
3726  s = rtp_session->rtcp_dtls->state;
3727  }
3728 
3729  done:
3730 
3731  switch_mutex_unlock(rtp_session->ice_mutex);
3732 
3733  return s;
3734 }
dtls_state_t state
Definition: switch_rtp.c:280
switch_status_t switch_mutex_unlock(switch_mutex_t *lock)
Definition: switch_apr.c:313
switch_status_t switch_mutex_lock(switch_mutex_t *lock)
Definition: switch_apr.c:308
switch_dtls_t * dtls
Definition: switch_rtp.c:366
dtls_state_t
Definition: switch_core.h:166
switch_mutex_t * ice_mutex
Definition: switch_rtp.c:429
switch_dtls_t * rtcp_dtls
Definition: switch_rtp.c:367

◆ switch_rtp_enable_vad()

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.

Parameters
rtp_sessionthe RTP session
sessionthe core session associated with the RTP session
codecthe codec the channel is currenty using
flagsflags for control
Returns
SWITCH_STAUTS_SUCCESS on success

Definition at line 8830 of file switch_rtp.c.

References switch_rtp_vad_data::bg_count, switch_rtp_vad_data::bg_len, switch_rtp_vad_data::bg_level, switch_rtp_vad_data::cng_freq, switch_rtp_vad_data::diff_level, switch_rtp_vad_data::fire_events, switch_rtp_vad_data::flags, switch_rtp::flags, switch_rtp_vad_data::hangover, switch_rtp_vad_data::hangunder, switch_codec_implementation::iananame, switch_codec::implementation, memset(), switch_codec_implementation::microseconds_per_packet, switch_codec_implementation::modname, switch_rtp_vad_data::next_scan, switch_codec_implementation::number_of_channels, switch_rtp::pool, switch_rtp_vad_data::read_codec, switch_codec_implementation::samples_per_second, switch_rtp_vad_data::scan_freq, switch_rtp_vad_data::session, switch_rtp::session, switch_rtp_vad_data::start, switch_rtp_vad_data::start_talking, switch_channel_get_variable, SWITCH_CHANNEL_SESSION_LOG, SWITCH_CODEC_FLAG_DECODE, SWITCH_CODEC_FLAG_ENCODE, switch_core_codec_init, switch_core_session_get_channel(), switch_epoch_time_now(), SWITCH_LOG_DEBUG, SWITCH_LOG_ERROR, switch_log_printf(), switch_micro_time_now(), SWITCH_RTP_FLAG_VAD, switch_rtp_ready(), switch_rtp_set_flag(), switch_set_flag, SWITCH_STATUS_FALSE, SWITCH_STATUS_GENERR, SWITCH_STATUS_SUCCESS, switch_test_flag, switch_true(), SWITCH_VAD_FLAG_CNG, SWITCH_VAD_FLAG_TALKING, switch_rtp_vad_data::ts, switch_rtp_vad_data::vad_codec, switch_rtp::vad_data, VAD_FIRE_NOT_TALK, and VAD_FIRE_TALK.

Referenced by switch_core_media_activate_rtp().

8832 {
8833  if (!switch_rtp_ready(rtp_session)) {
8834  return SWITCH_STATUS_FALSE;
8835  }
8836 
8837  if (rtp_session->flags[SWITCH_RTP_FLAG_VAD]) {
8838  return SWITCH_STATUS_GENERR;
8839  }
8840 
8841  memset(&rtp_session->vad_data, 0, sizeof(rtp_session->vad_data));
8842 
8843  if (switch_true(switch_channel_get_variable(switch_core_session_get_channel(rtp_session->session), "fire_talk_events"))) {
8844  rtp_session->vad_data.fire_events |= VAD_FIRE_TALK;
8845  }
8846 
8847  if (switch_true(switch_channel_get_variable(switch_core_session_get_channel(rtp_session->session), "fire_not_talk_events"))) {
8848  rtp_session->vad_data.fire_events |= VAD_FIRE_NOT_TALK;
8849  }
8850 
8851 
8852  if (switch_core_codec_init(&rtp_session->vad_data.vad_codec,
8853  codec->implementation->iananame,
8854  codec->implementation->modname,
8855  NULL,
8857  codec->implementation->microseconds_per_packet / 1000,
8860  switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(rtp_session->session), SWITCH_LOG_ERROR, "Can't load codec?\n");
8861  return SWITCH_STATUS_FALSE;
8862  }
8863  switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(rtp_session->session), SWITCH_LOG_DEBUG, "Activate VAD codec %s %dms\n", codec->implementation->iananame,
8864  codec->implementation->microseconds_per_packet / 1000);
8865  rtp_session->vad_data.diff_level = 400;
8866  rtp_session->vad_data.hangunder = 15;
8867  rtp_session->vad_data.hangover = 40;
8868  rtp_session->vad_data.bg_len = 5;
8869  rtp_session->vad_data.bg_count = 5;
8870  rtp_session->vad_data.bg_level = 300;
8871  rtp_session->vad_data.read_codec = codec;
8872  rtp_session->vad_data.session = session;
8873  rtp_session->vad_data.flags = flags;
8874  rtp_session->vad_data.cng_freq = 50;
8875  rtp_session->vad_data.ts = 1;
8876  rtp_session->vad_data.start = 0;
8877  rtp_session->vad_data.next_scan = switch_epoch_time_now(NULL);
8878  rtp_session->vad_data.scan_freq = 0;
8879  if (switch_test_flag(&rtp_session->vad_data, SWITCH_VAD_FLAG_TALKING)) {
8880  rtp_session->vad_data.start_talking = switch_micro_time_now();
8881  }
8884  return SWITCH_STATUS_SUCCESS;
8885 }
switch_time_t switch_micro_time_now(void)
Get the current epoch time in microseconds.
Definition: switch_time.c:311
static switch_bool_t switch_true(const char *expr)
Evaluate the truthfullness of a string expression.
Definition: switch_utils.h:519
#define SWITCH_CHANNEL_SESSION_LOG(x)
#define switch_set_flag(obj, flag)
Set a flag on an arbitrary object.
Definition: switch_utils.h:700
uint8_t switch_rtp_ready(switch_rtp_t *rtp_session)
Test if an RTP session is ready.
Definition: switch_rtp.c:5147
switch_core_session_t * session
struct switch_rtp_vad_data vad_data
Definition: switch_rtp.c:421
switch_vad_flag_t flags
Definition: switch_rtp.c:208
switch_codec_t vad_codec
Definition: switch_rtp.c:196
switch_core_session_t * session
Definition: switch_rtp.c:195
_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.
const switch_codec_implementation_t * implementation
uint32_t flags[SWITCH_RTP_FLAG_INVALID]
Definition: switch_rtp.c:392
#define switch_channel_get_variable(_c, _v)
switch_time_t start_talking
Definition: switch_rtp.c:214
#define switch_core_codec_init(_codec, _codec_name, _modname, _fmtp, _rate, _ms, _channels, _flags, _codec_settings, _pool)
Initialize a codec handle.
Definition: switch_core.h:1693
switch_memory_pool_t * pool
Definition: switch_rtp.c:393
void switch_rtp_set_flag(switch_rtp_t *rtp_session, switch_rtp_flag_t flag)
Set an RTP Flag.
Definition: switch_rtp.c:5372
switch_core_session_t * session
Definition: switch_rtp.c:472
time_t switch_epoch_time_now(time_t *t)
Get the current epoch time.
Definition: switch_time.c:322
#define switch_test_flag(obj, flag)
Test for the existance of a flag on an arbitary object.
Definition: switch_utils.h:693
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.
memset(buf, 0, buflen)
switch_codec_t * read_codec
Definition: switch_rtp.c:197

◆ switch_rtp_flush()

void switch_rtp_flush ( switch_rtp_t rtp_session)

Definition at line 5025 of file switch_rtp.c.

References SWITCH_RTP_FLAG_FLUSH, switch_rtp_ready(), and switch_rtp_set_flag().

Referenced by switch_core_media_receive_message().

5026 {
5027  if (!switch_rtp_ready(rtp_session)) {
5028  return;
5029  }
5030 
5032 }
uint8_t switch_rtp_ready(switch_rtp_t *rtp_session)
Test if an RTP session is ready.
Definition: switch_rtp.c:5147
void switch_rtp_set_flag(switch_rtp_t *rtp_session, switch_rtp_flag_t flag)
Set an RTP Flag.
Definition: switch_rtp.c:5372

◆ switch_rtp_get_core_session()

switch_core_session_t* switch_rtp_get_core_session ( switch_rtp_t rtp_session)

Definition at line 9238 of file switch_rtp.c.

References switch_rtp::session.

9239 {
9240  return rtp_session->session;
9241 }
switch_core_session_t * session
Definition: switch_rtp.c:472

◆ switch_rtp_get_default_payload()

uint32_t switch_rtp_get_default_payload ( switch_rtp_t rtp_session)

Get the default payload number for a given RTP session.

Parameters
rtp_sessionthe RTP session to get the payload number from
Returns
the default payload of the RTP session

Definition at line 5340 of file switch_rtp.c.

References switch_rtp::payload.

5341 {
5342  return rtp_session->payload;
5343 }
switch_payload_t payload
Definition: switch_rtp.c:377

◆ switch_rtp_get_default_samples_per_interval()

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.

Parameters
rtp_sessionthe RTP session to get the samples per interval from
Returns
the default samples per interval of the RTP session

Definition at line 5330 of file switch_rtp.c.

References switch_rtp::samples_per_interval.

5331 {
5332  return rtp_session->samples_per_interval;
5333 }
uint32_t samples_per_interval
Definition: switch_rtp.c:405

◆ switch_rtp_get_jitter_buffer()

switch_jb_t* switch_rtp_get_jitter_buffer ( switch_rtp_t rtp_session)

Definition at line 4726 of file switch_rtp.c.

References switch_rtp::jb, switch_rtp_ready(), and switch_rtp::vb.

Referenced by switch_core_media_get_jb(), switch_core_media_read_frame(), and switch_core_media_receive_message().

4727 {
4728  if (!switch_rtp_ready(rtp_session)) {
4729  return NULL;
4730  }
4731 
4732  return rtp_session->jb ? rtp_session->jb : rtp_session->vb;
4733 }
uint8_t switch_rtp_ready(switch_rtp_t *rtp_session)
Test if an RTP session is ready.
Definition: switch_rtp.c:5147
switch_jb_t * vb
Definition: switch_rtp.c:435
switch_jb_t * jb
Definition: switch_rtp.c:434

◆ switch_rtp_get_media_timer()

switch_timer_t* switch_rtp_get_media_timer ( switch_rtp_t rtp_session)

Definition at line 4712 of file switch_rtp.c.

References switch_rtp::flags, switch_core_timer_sync(), SWITCH_RTP_FLAG_VIDEO, switch_rtp::timer, and switch_timer::timer_interface.

Referenced by switch_core_media_get_timer().

4713 {
4714 
4715  if (rtp_session && rtp_session->timer.timer_interface) {
4716  if (rtp_session->flags[SWITCH_RTP_FLAG_VIDEO]) {
4717  switch_core_timer_sync(&rtp_session->timer);
4718  }
4719  return &rtp_session->timer;
4720  }
4721 
4722  return NULL;
4723 }
switch_timer_interface_t * timer_interface
uint32_t flags[SWITCH_RTP_FLAG_INVALID]
Definition: switch_rtp.c:392
switch_timer_t timer
Definition: switch_rtp.c:430
switch_status_t switch_core_timer_sync(switch_timer_t *timer)

◆ switch_rtp_get_private()

void* switch_rtp_get_private ( switch_rtp_t rtp_session)

Retrieve the private data from a given RTP session.

Parameters
rtp_sessionthe RTP session to retrieve the data from
Returns
the pointer to the private data

Definition at line 9233 of file switch_rtp.c.

References switch_rtp::private_data.

9234 {
9235  return rtp_session->private_data;
9236 }
void * private_data
Definition: switch_rtp.c:379

◆ switch_rtp_get_random()

void switch_rtp_get_random ( void *  buf,
uint32_t  len 
)

Definition at line 2542 of file switch_rtp.c.

References switch_stun_random_string().

Referenced by switch_core_media_build_crypto().

2543 {
2544 #ifdef HAVE_OPENSSL
2545  RAND_bytes(buf, len);
2546 #else
2547  switch_stun_random_string(buf, len, NULL);
2548 #endif
2549 }
switch_byte_t switch_byte_t * buf
void switch_stun_random_string(char *buf, uint16_t len, char *set)
Writes random characters into a buffer.
Definition: switch_stun.c:125

◆ switch_rtp_get_remote_host()

char* switch_rtp_get_remote_host ( switch_rtp_t rtp_session)

Definition at line 3034 of file switch_rtp.c.

References switch_rtp::remote_host_str, and zstr.

Referenced by switch_core_media_activate_rtp(), switch_core_media_negotiate_sdp(), switch_core_media_process_t38_passthru(), switch_core_media_proxy_remote_addr(), and switch_core_media_start_udptl().

3035 {
3036  return zstr(rtp_session->remote_host_str) ? "0.0.0.0" : rtp_session->remote_host_str;
3037 }
char * remote_host_str
Definition: switch_rtp.c:401
#define zstr(x)
Definition: switch_utils.h:314

◆ switch_rtp_get_remote_port()

switch_port_t switch_rtp_get_remote_port ( switch_rtp_t rtp_session)

◆ switch_rtp_get_rtp_socket()

switch_socket_t* switch_rtp_get_rtp_socket ( switch_rtp_t rtp_session)

Retrieve the socket from an existing RTP session.

Parameters
rtp_sessionthe RTP session to retrieve the socket from
Returns
the socket from the RTP session

Definition at line 5325 of file switch_rtp.c.

References switch_rtp::sock_input.

5326 {
5327  return rtp_session->sock_input;
5328 }
switch_socket_t * sock_input
Definition: switch_rtp.c:322

◆ switch_rtp_get_ssrc()

uint32_t switch_rtp_get_ssrc ( switch_rtp_t rtp_session)

Retrieve the SSRC from a given RTP session.

Parameters
rtp_sessionthe RTP session to retrieve from
Returns
the SSRC

Definition at line 9223 of file switch_rtp.c.

References switch_rtp::ssrc.

Referenced by switch_core_media_activate_rtp().

9224 {
9225  return rtp_session->ssrc;
9226 }
uint32_t ssrc
Definition: switch_rtp.c:372

◆ switch_rtp_get_stats()

switch_rtp_stats_t* switch_rtp_get_stats ( switch_rtp_t rtp_session,
switch_memory_pool_t pool 
)

Definition at line 9080 of file switch_rtp.c.

References do_mos(), switch_rtp::flag_mutex, switch_rtp_stats_t::inbound, switch_rtp::jb, switch_rtp_numbers_t::largest_jb_size, switch_rtp::stats, switch_core_alloc, switch_jb_get_frames(), switch_mutex_lock(), and switch_mutex_unlock().

Referenced by switch_core_media_get_stats().

9081 {
9082  switch_rtp_stats_t *s;
9083 
9084  if (!rtp_session) {
9085  return NULL;
9086  }
9087 
9088  switch_mutex_lock(rtp_session->flag_mutex);
9089  if (pool) {
9090  s = switch_core_alloc(pool, sizeof(*s));
9091  *s = rtp_session->stats;
9092  } else {
9093  s = &rtp_session->stats;
9094  }
9095 
9096  if (rtp_session->jb) {
9097  switch_jb_get_frames(rtp_session->jb, NULL, NULL, NULL, (uint32_t *)&s->inbound.largest_jb_size);
9098  }
9099 
9100  do_mos(rtp_session);
9101 
9102  switch_mutex_unlock(rtp_session->flag_mutex);
9103 
9104  return s;
9105 }
switch_rtp_numbers_t inbound
Definition: switch_types.h:760
switch_mutex_t * flag_mutex
Definition: switch_rtp.c:426
switch_size_t largest_jb_size
Definition: switch_types.h:692
switch_memory_pool_t * pool
switch_status_t switch_mutex_unlock(switch_mutex_t *lock)
Definition: switch_apr.c:313
switch_status_t switch_mutex_lock(switch_mutex_t *lock)
Definition: switch_apr.c:308
#define switch_core_alloc(_pool, _mem)
Allocate memory directly from a memory pool.
Definition: switch_core.h:684
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)
switch_rtp_stats_t stats
Definition: switch_rtp.c:450
switch_jb_t * jb
Definition: switch_rtp.c:434
static void do_mos(switch_rtp_t *rtp_session)
Definition: switch_rtp.c:1571

◆ switch_rtp_get_video_buffer_size()

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 
)

Definition at line 4773 of file switch_rtp.c.

References switch_jb_get_frames(), SWITCH_STATUS_FALSE, and switch_rtp::vb.

Referenced by check_jb_sync().

4774 {
4775 
4776  if (rtp_session->vb) {
4777  return switch_jb_get_frames(rtp_session->vb, min_frame_len, max_frame_len, cur_frame_len, highest_frame_len);
4778  }
4779 
4780  return SWITCH_STATUS_FALSE;
4781 }
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)
switch_jb_t * vb
Definition: switch_rtp.c:435

◆ switch_rtp_has_dtls()

int switch_rtp_has_dtls ( void  )

Definition at line 3697 of file switch_rtp.c.

Referenced by check_dtls_reinvite(), check_ice(), switch_core_media_activate_rtp(), switch_core_media_gen_local_sdp(), switch_core_media_negotiate_sdp(), and switch_ice_direction().

3697  {
3698 #ifdef HAVE_OPENSSL_DTLS_SRTP
3699  return 1;
3700 #else
3701  return 0;
3702 #endif
3703 }

◆ switch_rtp_has_dtmf()

switch_size_t switch_rtp_has_dtmf ( switch_rtp_t rtp_session)

Test for presence of DTMF on a given RTP session.

Parameters
rtp_sessionsession to test
Returns
number of digits in the queue

Definition at line 8051 of file switch_rtp.c.

References switch_rtp::dtmf_data, switch_rtp_rfc2833_data::dtmf_inqueue, switch_rtp_rfc2833_data::dtmf_mutex, switch_mutex_lock(), switch_mutex_unlock(), switch_queue_size(), and switch_rtp_ready().

Referenced by switch_core_media_read_frame().

8052 {
8053  switch_size_t has = 0;
8054 
8055  if (switch_rtp_ready(rtp_session)) {
8056  switch_mutex_lock(rtp_session->dtmf_data.dtmf_mutex);
8057  has = switch_queue_size(rtp_session->dtmf_data.dtmf_inqueue);
8059  }
8060 
8061  return has;
8062 }
unsigned int switch_queue_size(switch_queue_t *queue)
Definition: switch_apr.c:1238
uint8_t switch_rtp_ready(switch_rtp_t *rtp_session)
Test if an RTP session is ready.
Definition: switch_rtp.c:5147
struct switch_rtp_rfc2833_data dtmf_data
Definition: switch_rtp.c:422
switch_status_t switch_mutex_unlock(switch_mutex_t *lock)
Definition: switch_apr.c:313
switch_queue_t * dtmf_inqueue
Definition: switch_rtp.c:237
switch_status_t switch_mutex_lock(switch_mutex_t *lock)
Definition: switch_apr.c:308
switch_mutex_t * dtmf_mutex
Definition: switch_rtp.c:238
uintptr_t switch_size_t

◆ switch_rtp_init()

void switch_rtp_init ( switch_memory_pool_t pool)

Initilize the RTP System.

Parameters
poolthe memory pool to use for long term allocations
Note
Generally called by the core_init

Definition at line 1522 of file switch_rtp.c.

References port_lock, SWITCH_CHANNEL_LOG, switch_core_hash_init, SWITCH_LOG_DEBUG, SWITCH_LOG_ERROR, switch_log_printf(), switch_mutex_init(), SWITCH_MUTEX_NESTED, and switch_rtp_dtls_init().

Referenced by switch_core_init().

1523 {
1524  if (global_init) {
1525  return;
1526  }
1528 #ifdef ENABLE_SRTP
1529  {
1530  srtp_err_status_t stat = srtp_init();
1531  if (stat == srtp_err_status_ok) {
1532  switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "SRTP (%s) initialized.\n", srtp_get_version_string());
1533  } else {
1534  switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Error initializing SRTP (%d).\n", stat);
1535  }
1536  }
1537 #endif
1540  global_init = 1;
1541 }
#define SWITCH_CHANNEL_LOG
#define switch_core_hash_init(_hash)
Definition: switch_core.h:1431
switch_memory_pool_t * pool
static int global_init
Definition: switch_rtp.c:814
#define SWITCH_MUTEX_NESTED
Definition: switch_apr.h:318
static switch_mutex_t * port_lock
Definition: switch_rtp.c:94
static switch_hash_t * alloc_hash
Definition: switch_rtp.c:109
switch_status_t switch_mutex_init(switch_mutex_t **lock, unsigned int flags, switch_memory_pool_t *pool)
Definition: switch_apr.c:293
static void switch_rtp_dtls_init(void)
Definition: switch_rtp.c:3674
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.

◆ switch_rtp_intentional_bugs()

void switch_rtp_intentional_bugs ( switch_rtp_t rtp_session,
switch_rtp_bug_flag_t  bugs 
)

Definition at line 2662 of file switch_rtp.c.

References RTP_BUG_START_SEQ_AT_ZERO, switch_rtp::rtp_bugs, and switch_rtp::seq.

Referenced by switch_core_media_activate_rtp().

2663 {
2664  rtp_session->rtp_bugs = bugs;
2665 
2666  if ((rtp_session->rtp_bugs & RTP_BUG_START_SEQ_AT_ZERO)) {
2667  rtp_session->seq = 0;
2668  }
2669 
2670 }
uint16_t seq
Definition: switch_rtp.c:371
switch_rtp_bug_flag_t rtp_bugs
Definition: switch_rtp.c:449

◆ switch_rtp_kill_socket()

void switch_rtp_kill_socket ( switch_rtp_t rtp_session)

Kill the socket on an existing RTP session.

Parameters
rtp_sessionan RTP session to kill the socket of

Definition at line 5120 of file switch_rtp.c.

References switch_rtp::flag_mutex, switch_rtp::flags, ping_socket(), switch_rtp::rtcp_sock_input, switch_rtp::rtcp_sock_output, switch_rtp::sock_input, switch_rtp::sock_output, switch_assert, switch_mutex_lock(), switch_mutex_unlock(), SWITCH_RTP_FLAG_ENABLE_RTCP, SWITCH_RTP_FLAG_IO, SWITCH_SHUTDOWN_READWRITE, and switch_socket_shutdown().

Referenced by switch_core_media_kill_socket(), switch_rtp_destroy(), and switch_rtp_set_local_address().

5121 {
5122  switch_assert(rtp_session != NULL);
5123  switch_mutex_lock(rtp_session->flag_mutex);
5124  if (rtp_session->flags[SWITCH_RTP_FLAG_IO]) {
5125  rtp_session->flags[SWITCH_RTP_FLAG_IO] = 0;
5126  if (rtp_session->sock_input) {
5127  ping_socket(rtp_session);
5129  }
5130  if (rtp_session->sock_output && rtp_session->sock_output != rtp_session->sock_input) {
5132  }
5133 
5134  if (rtp_session->flags[SWITCH_RTP_FLAG_ENABLE_RTCP]) {
5135  if (rtp_session->sock_input && rtp_session->rtcp_sock_input && rtp_session->rtcp_sock_input != rtp_session->sock_input) {
5136  ping_socket(rtp_session);
5138  }
5139  if (rtp_session->rtcp_sock_output && rtp_session->rtcp_sock_output != rtp_session->sock_output && rtp_session->rtcp_sock_output != rtp_session->rtcp_sock_input) {
5141  }
5142  }
5143  }
5144  switch_mutex_unlock(rtp_session->flag_mutex);
5145 }
switch_mutex_t * flag_mutex
Definition: switch_rtp.c:426
switch_socket_t * sock_input
Definition: switch_rtp.c:322
switch_socket_t * rtcp_sock_input
Definition: switch_rtp.c:322
switch_status_t switch_mutex_unlock(switch_mutex_t *lock)
Definition: switch_apr.c:313
switch_status_t switch_mutex_lock(switch_mutex_t *lock)
Definition: switch_apr.c:308
uint32_t flags[SWITCH_RTP_FLAG_INVALID]
Definition: switch_rtp.c:392
switch_socket_t * rtcp_sock_output
Definition: switch_rtp.c:322
switch_status_t switch_socket_shutdown(switch_socket_t *sock, switch_shutdown_how_e how)
Definition: switch_apr.c:732
static void ping_socket(switch_rtp_t *rtp_session)
Definition: switch_rtp.c:3044
#define switch_assert(expr)
switch_socket_t * sock_output
Definition: switch_rtp.c:322

◆ switch_rtp_new()

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_ports,
switch_port_t  bundle_external_port 
)

prepare a new RTP session handle and fully initilize it

Parameters
rx_hostthe local address
rx_portthe local port
tx_hostthe remote address
tx_portthe remote port
payloadthe IANA payload number
samples_per_intervalthe default samples_per_interval
ms_per_packettime in microseconds per packet
flagsflags to control behaviour
timer_nametimer interface to use
erra pointer to resolve error messages
poola memory pool to use for the session
bundle_portport used by bundled stream locally, for video thread this is the port where it will forward audio (internal bundle port on which audio is listening), and for audio this is the port where it will send RTP (external bundle port where video is listening)
Returns
the new RTP session or NULL on failure

Definition at line 4623 of file switch_rtp.c.

References switch_rtp::flag_mutex, switch_rtp::pool, switch_rtp::ready, switch_rtp::rx_host, switch_rtp::rx_port, switch_core_strdup, switch_mutex_lock(), switch_mutex_unlock(), switch_rtp_create(), SWITCH_RTP_FLAG_DETECT_SSRC, SWITCH_RTP_FLAG_FLUSH, switch_rtp_release_port(), switch_rtp_set_flag(), switch_rtp_set_local_address(), switch_rtp_set_remote_address(), SWITCH_STATUS_SUCCESS, SWITCH_TRUE, and zstr.

Referenced by switch_core_media_activate_rtp().

4633 {
4634  switch_rtp_t *rtp_session = NULL;
4635 
4636  if (zstr(rx_host)) {
4637  *err = "Missing local host";
4638  goto end;
4639  }
4640 
4641  if (!rx_port) {
4642  *err = "Missing local port";
4643  goto end;
4644  }
4645 
4646  if (zstr(tx_host)) {
4647  *err = "Missing remote host";
4648  goto end;
4649  }
4650 
4651  if (!tx_port) {
4652  *err = "Missing remote port";
4653  goto end;
4654  }
4655 
4656  if (switch_rtp_create(&rtp_session, payload, samples_per_interval, ms_per_packet, flags, timer_name, err, pool) != SWITCH_STATUS_SUCCESS) {
4657  goto end;
4658  }
4659 
4660  switch_mutex_lock(rtp_session->flag_mutex);
4661 
4662  if (switch_rtp_set_local_address(rtp_session, rx_host, rx_port, err) != SWITCH_STATUS_SUCCESS) {
4663  switch_mutex_unlock(rtp_session->flag_mutex);
4664  rtp_session = NULL;
4665  goto end;
4666  }
4667 
4668  if (switch_rtp_set_remote_address(rtp_session, tx_host, tx_port, 0, SWITCH_TRUE, err) != SWITCH_STATUS_SUCCESS) {
4669  switch_mutex_unlock(rtp_session->flag_mutex);
4670  rtp_session = NULL;
4671  goto end;
4672  }
4673 
4674  end:
4675 
4676  if (rtp_session) {
4677  switch_mutex_unlock(rtp_session->flag_mutex);
4678  rtp_session->ready = 2;
4679  rtp_session->rx_host = switch_core_strdup(rtp_session->pool, rx_host);
4680  rtp_session->rx_port = rx_port;
4683  } else {
4684  switch_rtp_release_port(rx_host, rx_port);
4685  }
4686 
4687  return rtp_session;
4688 }
switch_port_t rx_port
Definition: switch_rtp.c:396
switch_mutex_t * flag_mutex
Definition: switch_rtp.c:426
#define switch_core_strdup(_pool, _todup)
Copy a string using memory allocation from a given pool.
Definition: switch_core.h:733
switch_memory_pool_t * pool
#define zstr(x)
Definition: switch_utils.h:314
switch_status_t switch_mutex_unlock(switch_mutex_t *lock)
Definition: switch_apr.c:313
uint8_t ready
Definition: switch_rtp.c:432
switch_status_t switch_mutex_lock(switch_mutex_t *lock)
Definition: switch_apr.c:308
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.
Definition: switch_rtp.c:3125
switch_memory_pool_t * pool
Definition: switch_rtp.c:393
void switch_rtp_set_flag(switch_rtp_t *rtp_session, switch_rtp_flag_t flag)
Set an RTP Flag.
Definition: switch_rtp.c:5372
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
Definition: switch_rtp.c:4473
char * rx_host
Definition: switch_rtp.c:395
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.
Definition: switch_rtp.c:2780
void switch_rtp_release_port(const char *ip, switch_port_t port)
Definition: switch_rtp.c:2610

◆ switch_rtp_pause_jitter_buffer()

switch_status_t switch_rtp_pause_jitter_buffer ( switch_rtp_t rtp_session,
switch_bool_t  pause 
)

Definition at line 4735 of file switch_rtp.c.

References switch_rtp::jb, switch_rtp::pause_jb, rtp_type, switch_rtp::session, SWITCH_CHANNEL_SESSION_LOG, switch_jb_reset(), SWITCH_LOG_DEBUG1, switch_log_printf(), SWITCH_STATUS_SUCCESS, and switch_rtp::vb.

Referenced by check_jb(), switch_core_media_receive_message(), switch_rtp_clear_flag(), and switch_rtp_set_flag().

4736 {
4737  int new_val;
4738 
4739  if (rtp_session->pause_jb && !pause) {
4740  if (rtp_session->jb) {
4741  switch_jb_reset(rtp_session->jb);
4742  }
4743 
4744  if (rtp_session->vb) {
4745  switch_jb_reset(rtp_session->vb);
4746  }
4747  }
4748 
4749  new_val = pause ? 1 : -1;
4750 
4751  if (rtp_session->pause_jb + new_val > -1) {
4752  rtp_session->pause_jb += new_val;
4753  }
4754 
4756  "Jitterbuffer %s is %s\n", rtp_type(rtp_session), rtp_session->pause_jb ? "paused" : "enabled");
4757 
4758  return SWITCH_STATUS_SUCCESS;
4759 }
#define SWITCH_CHANNEL_SESSION_LOG(x)
#define rtp_type(rtp_session)
Definition: switch_rtp.c:540
switch_jb_t * vb
Definition: switch_rtp.c:435
switch_jb_t * jb
Definition: switch_rtp.c:434
switch_core_session_t * session
Definition: switch_rtp.c:472
void switch_jb_reset(switch_jb_t *jb)
uint8_t pause_jb
Definition: switch_rtp.c:465
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.

◆ switch_rtp_ping()

void switch_rtp_ping ( switch_rtp_t rtp_session)

Definition at line 2537 of file switch_rtp.c.

References check_rtcp_and_ice().

2538 {
2539  check_rtcp_and_ice(rtp_session);
2540 }
static int check_rtcp_and_ice(switch_rtp_t *rtp_session)
Definition: switch_rtp.c:2133

◆ switch_rtp_queue_rfc2833()

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.

Parameters
rtp_sessionthe rtp session to use
dtmfthe dtmf digits to queue
Returns
SWITCH_STATUS_SUCCESS on success

Definition at line 8091 of file switch_rtp.c.

References switch_rtp::dtmf_data, switch_rtp_rfc2833_data::dtmf_queue, switch_dtmf_t::duration, switch_core_min_dtmf_duration(), switch_queue_trypush(), switch_rtp_ready(), SWITCH_STATUS_FALSE, and SWITCH_STATUS_SUCCESS.

Referenced by switch_core_media_queue_rfc2833().

8092 {
8093 
8094  switch_dtmf_t *rdigit;
8095 
8096  if (!switch_rtp_ready(rtp_session)) {
8097  return SWITCH_STATUS_FALSE;
8098  }
8099 
8100  if ((rdigit = malloc(sizeof(*rdigit))) != 0) {
8101  *rdigit = *dtmf;
8102  if (rdigit->duration < switch_core_min_dtmf_duration(0)) {
8104  }
8105 
8106  if ((switch_queue_trypush(rtp_session->dtmf_data.dtmf_queue, rdigit)) != SWITCH_STATUS_SUCCESS) {
8107  free(rdigit);
8108  return SWITCH_STATUS_FALSE;
8109  }
8110  } else {
8111  abort();
8112  }
8113 
8114  return SWITCH_STATUS_SUCCESS;
8115 }
uint8_t switch_rtp_ready(switch_rtp_t *rtp_session)
Test if an RTP session is ready.
Definition: switch_rtp.c:5147
uint32_t duration
Definition: switch_types.h:298
struct switch_rtp_rfc2833_data dtmf_data
Definition: switch_rtp.c:422
uint32_t switch_core_min_dtmf_duration(uint32_t duration)
Definition: switch_core.c:1744
switch_status_t switch_queue_trypush(switch_queue_t *queue, void *data)
Definition: switch_apr.c:1279
switch_queue_t * dtmf_queue
Definition: switch_rtp.c:221

◆ switch_rtp_queue_rfc2833_in()

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.

Parameters
rtp_sessionthe rtp session to use
dtmfthe dtmf digits to queue
Returns
SWITCH_STATUS_SUCCESS on success

Definition at line 8117 of file switch_rtp.c.

References switch_rtp::dtmf_data, switch_rtp_rfc2833_data::dtmf_inqueue, switch_dtmf_t::duration, switch_core_min_dtmf_duration(), switch_queue_trypush(), switch_rtp_ready(), SWITCH_STATUS_FALSE, and SWITCH_STATUS_SUCCESS.

Referenced by handle_rfc2833(), and switch_core_media_queue_rfc2833_in().

8118 {
8119  switch_dtmf_t *rdigit;
8120 
8121  if (!switch_rtp_ready(rtp_session)) {
8122  return SWITCH_STATUS_FALSE;
8123  }
8124 
8125  if ((rdigit = malloc(sizeof(*rdigit))) != 0) {
8126  *rdigit = *dtmf;
8127  if (rdigit->duration < switch_core_min_dtmf_duration(0)) {
8129  }
8130 
8131  if ((switch_queue_trypush(rtp_session->dtmf_data.dtmf_inqueue, rdigit)) != SWITCH_STATUS_SUCCESS) {
8132  free(rdigit);
8133  return SWITCH_STATUS_FALSE;
8134  }
8135  } else {
8136  abort();
8137  }
8138 
8139  return SWITCH_STATUS_SUCCESS;
8140 }
uint8_t switch_rtp_ready(switch_rtp_t *rtp_session)
Test if an RTP session is ready.
Definition: switch_rtp.c:5147
uint32_t duration
Definition: switch_types.h:298
struct switch_rtp_rfc2833_data dtmf_data
Definition: switch_rtp.c:422
uint32_t switch_core_min_dtmf_duration(uint32_t duration)
Definition: switch_core.c:1744
switch_queue_t * dtmf_inqueue
Definition: switch_rtp.c:237
switch_status_t switch_queue_trypush(switch_queue_t *queue, void *data)
Definition: switch_apr.c:1279

◆ switch_rtp_read()

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.

Parameters
rtp_sessionthe RTP session to read from
datathe data to read
datalena pointer to the datalen
payload_typethe IANA payload of the packet
flagsflags
io_flagsi/o flags
Returns
the number of bytes read

Definition at line 8142 of file switch_rtp.c.

References RTP_BODY, rtp_common_read(), rtp_header_len, switch_rtp_ready(), SWITCH_STATUS_BREAK, SWITCH_STATUS_FALSE, SWITCH_STATUS_GENERR, SWITCH_STATUS_SUCCESS, and SWITCH_STATUS_TIMEOUT.

8144 {
8145  int bytes = 0;
8146 
8147  if (!switch_rtp_ready(rtp_session)) {
8148  return SWITCH_STATUS_FALSE;
8149  }
8150 
8151  bytes = rtp_common_read(rtp_session, payload_type, NULL, flags, io_flags);
8152 
8153  if (bytes < 0) {
8154  *datalen = 0;
8155  return bytes == -2 ? SWITCH_STATUS_TIMEOUT : SWITCH_STATUS_GENERR;
8156  } else if (bytes == 0) {
8157  *datalen = 0;
8158  return SWITCH_STATUS_BREAK;
8159  } else {
8160  if (bytes > rtp_header_len) {
8161  bytes -= rtp_header_len;
8162  }
8163  }
8164 
8165  *datalen = bytes;
8166 
8167  memcpy(data, RTP_BODY(rtp_session), bytes);
8168 
8169  return SWITCH_STATUS_SUCCESS;
8170 }
uint8_t switch_rtp_ready(switch_rtp_t *rtp_session)
Test if an RTP session is ready.
Definition: switch_rtp.c:5147
#define RTP_BODY(_s)
Definition: switch_rtp.c:118
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)
Definition: switch_rtp.c:7301
#define rtp_header_len
Definition: switch_rtp.c:73

◆ switch_rtp_ready()

uint8_t switch_rtp_ready ( switch_rtp_t rtp_session)

Test if an RTP session is ready.

Parameters
rtp_sessionan RTP session to test
Returns
a true value if it's ready

Definition at line 5147 of file switch_rtp.c.

References switch_rtp::flag_mutex, switch_rtp::flags, switch_rtp::ready, switch_rtp::remote_addr, switch_rtp::sock_input, switch_rtp::sock_output, switch_mutex_lock(), switch_mutex_unlock(), SWITCH_RTP_FLAG_IO, and SWITCH_RTP_FLAG_SHUTDOWN.

Referenced by check_ice(), check_media_timeout_params(), do_flush(), handle_ice(), handle_rfc2833(), rtp_common_read(), rtp_common_write(), rtp_flush_read_buffer(), switch_core_media_activate_rtp(), switch_core_media_break(), switch_core_media_check_udptl_mode(), switch_core_media_clear_rtp_flag(), switch_core_media_get_jb(), switch_core_media_kill_socket(), switch_core_media_negotiate_sdp(), switch_core_media_patch_sdp(), switch_core_media_proxy_remote_addr(), switch_core_media_queue_rfc2833(), switch_core_media_queue_rfc2833_in(), switch_core_media_read_frame(), switch_core_media_read_lock_unlock(), switch_core_media_ready(), switch_core_media_receive_message(), switch_core_media_reset_jb(), switch_core_media_set_codec(), switch_core_media_set_rtp_flag(), switch_core_media_set_telephony_event(), switch_core_media_set_telephony_recv_event(), switch_core_media_set_video_codec(), switch_core_media_start_udptl(), switch_core_media_udptl_mode(), switch_core_media_write_frame(), switch_core_session_check_incoming_crypto(), switch_core_session_passthru(), switch_rtp_activate_jitter_buffer(), switch_rtp_add_dtls(), switch_rtp_break(), switch_rtp_deactivate_jitter_buffer(), switch_rtp_debug_jitter_buffer(), switch_rtp_dequeue_dtmf(), switch_rtp_enable_vad(), switch_rtp_flush(), switch_rtp_get_jitter_buffer(), switch_rtp_has_dtmf(), switch_rtp_queue_rfc2833(), switch_rtp_queue_rfc2833_in(), switch_rtp_read(), switch_rtp_reset_jb(), switch_rtp_set_local_address(), switch_rtp_set_max_missed_packets(), switch_rtp_set_media_timeout(), switch_rtp_set_video_buffer_size(), switch_rtp_udptl_mode(), switch_rtp_write_frame(), switch_rtp_write_manual(), switch_rtp_write_raw(), switch_rtp_zerocopy_read(), and switch_rtp_zerocopy_read_frame().

5148 {
5149  uint8_t ret;
5150 
5151  if (!rtp_session || !rtp_session->flag_mutex || rtp_session->flags[SWITCH_RTP_FLAG_SHUTDOWN]) {
5152  return 0;
5153  }
5154 
5155  switch_mutex_lock(rtp_session->flag_mutex);
5156  ret = (rtp_session->flags[SWITCH_RTP_FLAG_IO] && rtp_session->sock_input && rtp_session->sock_output && rtp_session->remote_addr
5157  && rtp_session->ready == 2) ? 1 : 0;
5158  switch_mutex_unlock(rtp_session->flag_mutex);
5159 
5160  return ret;
5161 }
switch_sockaddr_t * remote_addr
Definition: switch_rtp.c:340
switch_mutex_t * flag_mutex
Definition: switch_rtp.c:426
switch_socket_t * sock_input
Definition: switch_rtp.c:322
switch_status_t switch_mutex_unlock(switch_mutex_t *lock)
Definition: switch_apr.c:313
uint8_t ready
Definition: switch_rtp.c:432
switch_status_t switch_mutex_lock(switch_mutex_t *lock)
Definition: switch_apr.c:308
uint32_t flags[SWITCH_RTP_FLAG_INVALID]
Definition: switch_rtp.c:392
switch_socket_t * sock_output
Definition: switch_rtp.c:322

◆ switch_rtp_release_port()

void switch_rtp_release_port ( const char *  ip,
switch_port_t  port 
)

Definition at line 2610 of file switch_rtp.c.

References port_lock, switch_core_hash_find(), switch_core_port_allocator_free_port(), switch_mutex_lock(), and switch_mutex_unlock().

Referenced by switch_core_media_choose_port(), switch_core_media_deactivate_rtp(), switch_rtp_destroy(), and switch_rtp_new().

2611 {
2612  switch_core_port_allocator_t *alloc = NULL;
2613 
2614  if (!ip || !port) {
2615  return;
2616  }
2617 
2619  if ((alloc = switch_core_hash_find(alloc_hash, ip))) {
2621  }
2623 
2624 }
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.
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_mutex_unlock(switch_mutex_t *lock)
Definition: switch_apr.c:313
static switch_mutex_t * port_lock
Definition: switch_rtp.c:94
switch_status_t switch_mutex_lock(switch_mutex_t *lock)
Definition: switch_apr.c:308
static switch_hash_t * alloc_hash
Definition: switch_rtp.c:109
char * ip
Definition: switch_msrp.c:60

◆ switch_rtp_req_bitrate()

switch_status_t switch_rtp_req_bitrate ( switch_rtp_t rtp_session,
uint32_t  bps 
)

Definition at line 5034 of file switch_rtp.c.

References rtp_write_ready(), SWITCH_STATUS_FALSE, SWITCH_STATUS_SUCCESS, and switch_rtp::tmmbr.

Referenced by switch_core_media_receive_message().

5035 {
5036  if (!rtp_write_ready(rtp_session, 0, __LINE__) || rtp_session->tmmbr) {
5037  return SWITCH_STATUS_FALSE;
5038  }
5039 
5040  rtp_session->tmmbr = bps;
5041 
5042  return SWITCH_STATUS_SUCCESS;
5043 }
static int rtp_write_ready(switch_rtp_t *rtp_session, uint32_t bytes, int line)
Definition: switch_rtp.c:8270
uint32_t tmmbr
Definition: switch_rtp.c:336

◆ switch_rtp_request_port()

switch_port_t switch_rtp_request_port ( const char *  ip)

Request a new port to be used for media.

Parameters
ipthe ip to request a port from
Returns
the new port to use

Definition at line 2626 of file switch_rtp.c.

References END_PORT, port_lock, SPF_EVEN, START_PORT, switch_core_hash_find(), switch_core_hash_insert, switch_core_port_allocator_new(), switch_core_port_allocator_request_port(), switch_mutex_lock(), switch_mutex_unlock(), and SWITCH_STATUS_SUCCESS.

Referenced by switch_core_media_choose_port().

2627 {
2628  switch_port_t port = 0;
2629  switch_core_port_allocator_t *alloc = NULL;
2630 
2633  if (!alloc) {
2635  abort();
2636  }
2637 
2639  }
2640 
2642  port = 0;
2643  }
2644 
2646  return port;
2647 }
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_mutex_unlock(switch_mutex_t *lock)
Definition: switch_apr.c:313
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.
static switch_mutex_t * port_lock
Definition: switch_rtp.c:94
switch_status_t switch_mutex_lock(switch_mutex_t *lock)
Definition: switch_apr.c:308
static switch_hash_t * alloc_hash
Definition: switch_rtp.c:109
uint16_t switch_port_t
static switch_port_t START_PORT
Definition: switch_rtp.c:92
static switch_port_t END_PORT
Definition: switch_rtp.c:93
char * ip
Definition: switch_msrp.c:60
#define switch_core_hash_insert(_h, _k, _d)
Definition: switch_core.h:1479
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.

◆ switch_rtp_reset()

void switch_rtp_reset ( switch_rtp_t rtp_session)

Definition at line 3000 of file switch_rtp.c.

References switch_rtp_ice_t::cand_responsive, switch_rtp::first_stun, switch_rtp::ice, switch_rtp::last_adj, switch_rtp::last_stun, memset(), switch_rtp_ice_t::ready, switch_rtp_ice_t::rready, switch_rtp::rtcp_last_sent, switch_rtp::rtcp_sent_packets, rtcp_stats_init(), SWITCH_RTP_FLAG_MUTE, SWITCH_RTP_FLAG_PAUSE, switch_rtp_reset_vb(), switch_rtp_set_flag(), and switch_rtp::ts_norm.

Referenced by clear_ice(), and switch_core_session_stop_media().

3001 {
3002  if (!rtp_session) {
3003  return;
3004  }
3005 
3006  //rtp_session->seq = (uint16_t) rand();
3007  //rtp_session->ts = 0;
3008  memset(&rtp_session->ts_norm, 0, sizeof(rtp_session->ts_norm));
3009 
3010  rtp_session->last_stun = rtp_session->first_stun = 0;
3011  rtp_session->rtcp_sent_packets = 0;
3012  rtp_session->rtcp_last_sent = 0;
3013  rtp_session->last_adj = 0;
3014 
3015  //switch_rtp_del_dtls(rtp_session, DTLS_TYPE_RTP|DTLS_TYPE_RTCP);
3018  rtcp_stats_init(rtp_session);
3019 
3020  if (rtp_session->ice.ready) {
3021  switch_rtp_reset_vb(rtp_session);
3022  rtp_session->ice.ready = rtp_session->ice.rready = 0;
3023  rtp_session->ice.cand_responsive = 0;
3024  }
3025 
3026 }
switch_time_t rtcp_last_sent
Definition: switch_rtp.c:408
void switch_rtp_reset_vb(switch_rtp_t *rtp_session)
Definition: switch_rtp.c:2988
static void rtcp_stats_init(switch_rtp_t *rtp_session)
Definition: switch_rtp.c:1901
uint8_t cand_responsive
Definition: switch_rtp.c:261
switch_time_t last_adj
Definition: switch_rtp.c:477
void switch_rtp_set_flag(switch_rtp_t *rtp_session, switch_rtp_flag_t flag)
Set an RTP Flag.
Definition: switch_rtp.c:5372
switch_rtp_ice_t ice
Definition: switch_rtp.c:397
switch_time_t last_stun
Definition: switch_rtp.c:404
switch_time_t first_stun
Definition: switch_rtp.c:403
memset(buf, 0, buflen)
int rtcp_sent_packets
Definition: switch_rtp.c:459
ts_normalize_t ts_norm
Definition: switch_rtp.c:339

◆ switch_rtp_reset_jb()

void switch_rtp_reset_jb ( switch_rtp_t rtp_session)

Definition at line 2979 of file switch_rtp.c.

References switch_rtp::jb, switch_jb_reset(), and switch_rtp_ready().

Referenced by switch_core_media_receive_message(), switch_core_media_reset_jb(), and switch_core_media_set_codec().

2980 {
2981  if (switch_rtp_ready(rtp_session)) {
2982  if (rtp_session->jb) {
2983  switch_jb_reset(rtp_session->jb);
2984  }
2985  }
2986 }
uint8_t switch_rtp_ready(switch_rtp_t *rtp_session)
Test if an RTP session is ready.
Definition: switch_rtp.c:5147
switch_jb_t * jb
Definition: switch_rtp.c:434
void switch_jb_reset(switch_jb_t *jb)

◆ switch_rtp_reset_media_timer()

void switch_rtp_reset_media_timer ( switch_rtp_t rtp_session)

Definition at line 3028 of file switch_rtp.c.

References switch_rtp::last_media, switch_rtp::missed_count, and switch_micro_time_now().

Referenced by rtp_common_read(), switch_core_media_activate_rtp(), switch_core_media_toggle_hold(), and switch_rtp_set_media_timeout().

3029 {
3030  rtp_session->missed_count = 0;
3031  rtp_session->last_media = switch_micro_time_now();
3032 }
switch_time_t switch_micro_time_now(void)
Get the current epoch time in microseconds.
Definition: switch_time.c:311
switch_time_t last_media
Definition: switch_rtp.c:439
uint32_t missed_count
Definition: switch_rtp.c:438

◆ switch_rtp_set_cng_pt()

void switch_rtp_set_cng_pt ( switch_rtp_t rtp_session,
switch_payload_t  pt 
)

Set the payload type for comfort noise.

Parameters
rtp_sessionthe RTP session to modify
ptthe payload type

Definition at line 4706 of file switch_rtp.c.

References switch_rtp::cng_pt, switch_rtp::flags, and SWITCH_RTP_FLAG_AUTO_CNG.

Referenced by switch_core_media_activate_rtp(), and switch_core_media_negotiate_sdp().

4707 {
4708  rtp_session->cng_pt = pt;
4709  rtp_session->flags[SWITCH_RTP_FLAG_AUTO_CNG] = 1;
4710 }
switch_payload_t cng_pt
Definition: switch_rtp.c:425
uint32_t flags[SWITCH_RTP_FLAG_INVALID]
Definition: switch_rtp.c:392

◆ switch_rtp_set_default_payload()

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.

Parameters
rtp_sessionthe RTP session to set the payload number on
payloadthe new default payload number

Definition at line 5335 of file switch_rtp.c.

References switch_rtp::payload.

Referenced by switch_core_media_activate_rtp(), switch_core_media_negotiate_sdp(), switch_core_media_set_codec(), switch_core_media_set_video_codec(), switch_core_session_start_text_thread(), and switch_core_session_start_video_thread().

5336 {
5337  rtp_session->payload = payload;
5338 }
switch_payload_t payload
Definition: switch_rtp.c:377

◆ switch_rtp_set_end_port()

switch_port_t switch_rtp_set_end_port ( switch_port_t  port)

Set/Get RTP end port.

Parameters
portnew value (if > 0)
Returns
the current RTP end port

Definition at line 2596 of file switch_rtp.c.

References END_PORT, port_lock, switch_mutex_lock(), and switch_mutex_unlock().

Referenced by switch_core_get_rtp_port_range_end_port(), and switch_load_core_config().

2597 {
2598  if (port) {
2599  if (port_lock) {
2601  }
2602  END_PORT = port;
2603  if (port_lock) {
2605  }
2606  }
2607  return END_PORT;
2608 }
switch_status_t switch_mutex_unlock(switch_mutex_t *lock)
Definition: switch_apr.c:313
static switch_mutex_t * port_lock
Definition: switch_rtp.c:94
switch_status_t switch_mutex_lock(switch_mutex_t *lock)
Definition: switch_apr.c:308
static switch_port_t END_PORT
Definition: switch_rtp.c:93

◆ switch_rtp_set_flag()

void switch_rtp_set_flag ( switch_rtp_t rtp_session,
switch_rtp_flag_t  flag 
)

Set an RTP Flag.

Parameters
rtp_sessionthe RTP session
flagsthe flags to set

Definition at line 5372 of file switch_rtp.c.

References switch_rtp::autoadj_tally, switch_rtp::autoadj_threshold, switch_rtp::autoadj_window, switch_rtp::flag_mutex, switch_rtp::flags, switch_rtp_stats_t::inbound, switch_rtp::jb, switch_rtp_numbers_t::last_processed_seq, reset_jitter_seq(), switch_rtp::rtcp_autoadj_tally, switch_rtp::rtcp_autoadj_threshold, switch_rtp::rtcp_autoadj_window, rtp_flush_read_buffer(), switch_rtp::session, switch_rtp::sock_input, switch_rtp::stats, switch_channel_get_variable, switch_core_session_get_channel(), switch_jb_reset(), switch_mutex_lock(), switch_mutex_unlock(), SWITCH_RTP_FLAG_AUTOADJ, SWITCH_RTP_FLAG_DTMF_ON, SWITCH_RTP_FLAG_FLUSH, SWITCH_RTP_FLAG_NOBLOCK, SWITCH_RTP_FLAG_PASSTHRU, SWITCH_RTP_FLAG_RTCP_AUTOADJ, SWITCH_RTP_FLUSH_ONCE, switch_rtp_pause_jitter_buffer(), SWITCH_SO_NONBLOCK, switch_socket_opt_set(), SWITCH_TRUE, and TRUE.

Referenced by do_flush(), handle_ice(), process_rtcp_report(), read_rtcp_packet(), read_rtp_packet(), rtp_common_read(), rtp_flush_read_buffer(), switch_core_media_activate_rtp(), switch_core_media_check_autoadj(), switch_core_media_negotiate_sdp(), switch_core_media_pause(), switch_core_media_proxy_remote_addr(), switch_core_media_receive_message(), switch_core_media_set_rtp_flag(), switch_core_media_start_udptl(), switch_core_media_toggle_hold(), switch_core_session_passthru(), switch_rtp_create(), switch_rtp_enable_vad(), switch_rtp_flush(), switch_rtp_new(), switch_rtp_reset(), switch_rtp_set_flags(), switch_rtp_set_local_address(), and switch_rtp_udptl_mode().

5373 {
5374  int old_flag = rtp_session->flags[flag];
5375 
5376  switch_mutex_lock(rtp_session->flag_mutex);
5377  rtp_session->flags[flag] = 1;
5378  switch_mutex_unlock(rtp_session->flag_mutex);
5379 
5380  if (flag == SWITCH_RTP_FLAG_PASSTHRU) {
5381  if (!old_flag) {
5383  }
5384  } else if (flag == SWITCH_RTP_FLAG_DTMF_ON) {
5385  rtp_session->stats.inbound.last_processed_seq = 0;
5386  } else if (flag == SWITCH_RTP_FLAG_FLUSH) {
5387  reset_jitter_seq(rtp_session);
5388  } else if (flag == SWITCH_RTP_FLAG_AUTOADJ) {
5389  rtp_session->autoadj_window = 20;
5390  rtp_session->autoadj_threshold = 10;
5391  rtp_session->autoadj_tally = 0;
5392 
5393  switch_mutex_lock(rtp_session->flag_mutex);
5394  rtp_session->flags[SWITCH_RTP_FLAG_RTCP_AUTOADJ] = 1;
5395  switch_mutex_unlock(rtp_session->flag_mutex);
5396 
5397  rtp_session->rtcp_autoadj_window = 20;
5398  rtp_session->rtcp_autoadj_threshold = 1;
5399  rtp_session->rtcp_autoadj_tally = 0;
5400 
5401  if (rtp_session->session) {
5402  switch_channel_t *channel = switch_core_session_get_channel(rtp_session->session);
5403  const char *x = switch_channel_get_variable(channel, "rtp_auto_adjust_threshold");
5404  if (x && *x) {
5405  int xn = atoi(x);
5406  if (xn > 0 && xn <= 65535) {
5407  rtp_session->autoadj_window = xn*2;
5408  rtp_session->autoadj_threshold = xn;
5409  }
5410  }
5411  }
5412 
5413 
5415 
5416 
5417  if (rtp_session->jb) {
5418  switch_jb_reset(rtp_session->jb);
5419  }
5420  } else if (flag == SWITCH_RTP_FLAG_NOBLOCK && rtp_session->sock_input) {
5422  }
5423 
5424 }
switch_rtp_numbers_t inbound
Definition: switch_types.h:760
uint32_t rtcp_autoadj_tally
Definition: switch_rtp.c:351
switch_mutex_t * flag_mutex
Definition: switch_rtp.c:426
switch_socket_t * sock_input
Definition: switch_rtp.c:322
switch_status_t switch_rtp_pause_jitter_buffer(switch_rtp_t *rtp_session, switch_bool_t pause)
Definition: switch_rtp.c:4735
uint32_t rtcp_autoadj_threshold
Definition: switch_rtp.c:350
void rtp_flush_read_buffer(switch_rtp_t *rtp_session, switch_rtp_flush_t flush)
Definition: switch_rtp.c:5635
switch_status_t switch_mutex_unlock(switch_mutex_t *lock)
Definition: switch_apr.c:313
_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.
uint32_t rtcp_autoadj_window
Definition: switch_rtp.c:349
switch_status_t switch_mutex_lock(switch_mutex_t *lock)
Definition: switch_apr.c:308
uint32_t flags[SWITCH_RTP_FLAG_INVALID]
Definition: switch_rtp.c:392
#define switch_channel_get_variable(_c, _v)
uint32_t autoadj_threshold
Definition: switch_rtp.c:346
switch_status_t switch_socket_opt_set(switch_socket_t *sock, int32_t opt, int32_t on)
Definition: switch_apr.c:907
uint32_t autoadj_window
Definition: switch_rtp.c:345
switch_rtp_stats_t stats
Definition: switch_rtp.c:450
switch_jb_t * jb
Definition: switch_rtp.c:434
#define SWITCH_SO_NONBLOCK
Definition: switch_apr.h:994
static void reset_jitter_seq(switch_rtp_t *rtp_session)
Definition: switch_rtp.c:1646
switch_core_session_t * session
Definition: switch_rtp.c:472
void switch_jb_reset(switch_jb_t *jb)
#define TRUE
uint32_t autoadj_tally
Definition: switch_rtp.c:347

◆ switch_rtp_set_flags()

void switch_rtp_set_flags ( switch_rtp_t rtp_session,
switch_rtp_flag_t  flags[SWITCH_RTP_FLAG_INVALID] 
)

Definition at line 5350 of file switch_rtp.c.

References SWITCH_RTP_FLAG_INVALID, and switch_rtp_set_flag().

Referenced by switch_core_media_receive_message(), and switch_rtp_create().

5351 {
5352  int i;
5353 
5354  for(i = 0; i < SWITCH_RTP_FLAG_INVALID; i++) {
5355  if (flags[i]) {
5356  switch_rtp_set_flag(rtp_session, i);
5357  }
5358  }
5359 }
void switch_rtp_set_flag(switch_rtp_t *rtp_session, switch_rtp_flag_t flag)
Set an RTP Flag.
Definition: switch_rtp.c:5372

◆ switch_rtp_set_interdigit_delay()

void switch_rtp_set_interdigit_delay ( switch_rtp_t rtp_session,
uint32_t  delay 
)

Definition at line 5320 of file switch_rtp.c.

References switch_rtp::interdigit_delay.

Referenced by switch_core_media_activate_rtp().

5321 {
5322  rtp_session->interdigit_delay = delay;
5323 }
uint32_t interdigit_delay
Definition: switch_rtp.c:471

◆ switch_rtp_set_interval()

switch_status_t switch_rtp_set_interval ( switch_rtp_t rtp_session,
uint32_t  ms_per_packet,
uint32_t  samples_per_interval 
)

Definition at line 4401 of file switch_rtp.c.

References switch_rtp::conf_samples_per_interval, switch_rtp::missed_count, switch_rtp::ms_per_packet, switch_rtp::one_second, switch_rtp::samples_per_interval, switch_rtp::samples_per_second, and SWITCH_STATUS_SUCCESS.

Referenced by switch_rtp_change_interval(), and switch_rtp_create().

4402 {
4403  rtp_session->ms_per_packet = ms_per_packet;
4404  rtp_session->samples_per_interval = rtp_session->conf_samples_per_interval = samples_per_interval;
4405  rtp_session->missed_count = 0;
4406  rtp_session->samples_per_second =
4407  (uint32_t) ((double) (1000.0f / (double) (rtp_session->ms_per_packet / 1000)) * (double) rtp_session->samples_per_interval);
4408 
4409  rtp_session->one_second = (rtp_session->samples_per_second / rtp_session->samples_per_interval);
4410 
4411  return SWITCH_STATUS_SUCCESS;
4412 }
uint32_t samples_per_second
Definition: switch_rtp.c:406
uint32_t missed_count
Definition: switch_rtp.c:438
uint32_t samples_per_interval
Definition: switch_rtp.c:405
uint32_t ms_per_packet
Definition: switch_rtp.c:410
uint32_t conf_samples_per_interval
Definition: switch_rtp.c:407
uint32_t one_second
Definition: switch_rtp.c:411

◆ switch_rtp_set_invalid_handler()

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.

Parameters
rtp_sessionthe RTP session
on_invalidthe function to set
Returns

Definition at line 5345 of file switch_rtp.c.

References switch_rtp::invalid_handler.

5346 {
5347  rtp_session->invalid_handler = on_invalid;
5348 }
switch_rtp_invalid_handler_t invalid_handler
Definition: switch_rtp.c:378

◆ switch_rtp_set_local_address()

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.

Parameters
rtp_sessionan RTP session to assign the local address to
hostthe ip or fqhn of the local address
portthe local port
change_adv_addrchange the advertised address for doing compare
errpointer for error messages
Note
this call also binds the RTP session's socket to the new address

Definition at line 2780 of file switch_rtp.c.

References enable_local_rtcp_socket(), FALSE, switch_rtp::flags, switch_rtp::from_addr, switch_rtp::local_addr, switch_rtp::local_host_str, switch_rtp::local_port, switch_rtp::pool, READ_DEC, READ_INC, switch_rtp::read_pollfd, switch_rtp::ready, switch_rtp::session, switch_rtp::sock_input, switch_channel_get_variable, switch_cond_next(), switch_core_session_get_channel(), switch_core_sprintf(), switch_core_strdup, switch_mcast_hops(), switch_mcast_interface(), switch_mcast_join(), SWITCH_POLLERR, SWITCH_POLLIN, SWITCH_RTP_FLAG_ENABLE_RTCP, SWITCH_RTP_FLAG_IO, SWITCH_RTP_FLAG_NOBLOCK, SWITCH_RTP_FLAG_USE_TIMER, SWITCH_RTP_FLAG_VIDEO, switch_rtp_kill_socket(), switch_rtp_ready(), switch_rtp_set_flag(), SWITCH_SO_NONBLOCK, SWITCH_SO_RCVBUF, SWITCH_SO_REUSEADDR, SWITCH_SO_SNDBUF, switch_sockaddr_get_family(), switch_sockaddr_info_get(), switch_socket_bind(), switch_socket_close(), switch_socket_create(), switch_socket_create_pollset(), switch_socket_opt_set(), switch_socket_recvfrom(), switch_socket_sendto(), SWITCH_STATUS_BREAK, SWITCH_STATUS_FALSE, SWITCH_STATUS_SUCCESS, SWITCH_UNSPEC, TRUE, WRITE_DEC, WRITE_INC, and zstr.

Referenced by switch_rtp_new().

2781 {
2782  switch_socket_t *new_sock = NULL, *old_sock = NULL;
2784  int j = 0;
2785 #ifndef WIN32
2786  char o[5] = "TEST", i[5] = "";
2787  switch_size_t len, ilen = 0;
2788  int x;
2789 #endif
2790 
2791  if (rtp_session->ready != 1) {
2792  if (!switch_rtp_ready(rtp_session)) {
2793  return SWITCH_STATUS_FALSE;
2794  }
2795 
2796  READ_INC(rtp_session);
2797  WRITE_INC(rtp_session);
2798 
2799  if (!switch_rtp_ready(rtp_session)) {
2800  goto done;
2801  }
2802  }
2803 
2804 
2805  *err = NULL;
2806 
2807  if (zstr(host) || !port) {
2808  *err = "Address Error";
2809  goto done;
2810  }
2811 
2812 
2813  rtp_session->local_host_str = switch_core_strdup(rtp_session->pool, host);
2814  rtp_session->local_port = port;
2815 
2816 
2817  if (switch_sockaddr_info_get(&rtp_session->local_addr, host, SWITCH_UNSPEC, port, 0, rtp_session->pool) != SWITCH_STATUS_SUCCESS) {
2818  *err = "Local Address Error!";
2819  goto done;
2820  }
2821 
2822 
2823  if (rtp_session->sock_input) {
2824  switch_rtp_kill_socket(rtp_session);
2825  }
2826 
2827  if (switch_socket_create(&new_sock, switch_sockaddr_get_family(rtp_session->local_addr), SOCK_DGRAM, 0, rtp_session->pool) != SWITCH_STATUS_SUCCESS) {
2828  *err = "Socket Error!";
2829  goto done;
2830  }
2831 
2833  *err = "Socket Error!";
2834  goto done;
2835  }
2836 
2837  if (rtp_session->flags[SWITCH_RTP_FLAG_VIDEO]) {
2838  switch_socket_opt_set(new_sock, SWITCH_SO_RCVBUF, 1572864);
2839  switch_socket_opt_set(new_sock, SWITCH_SO_SNDBUF, 1572864);
2840  } else {
2841  switch_socket_opt_set(new_sock, SWITCH_SO_RCVBUF, 851968);
2842  switch_socket_opt_set(new_sock, SWITCH_SO_SNDBUF, 851968);
2843  }
2844 
2845  if (switch_socket_bind(new_sock, rtp_session->local_addr) != SWITCH_STATUS_SUCCESS) {
2846  char *em = switch_core_sprintf(rtp_session->pool, "Bind Error! %s:%d", host, port);
2847  *err = em;
2848  goto done;
2849  }
2850 
2851 
2852  if ((j = atoi(host)) && j > 223 && j < 240) { /* mcast */
2853  if (switch_mcast_interface(new_sock, rtp_session->local_addr) != SWITCH_STATUS_SUCCESS) {
2854  *err = "Multicast Socket interface Error";
2855  goto done;
2856  }
2857 
2858  if (switch_mcast_join(new_sock, rtp_session->local_addr, NULL, NULL) != SWITCH_STATUS_SUCCESS) {
2859  *err = "Multicast Error";
2860  goto done;
2861  }
2862 
2863  if (rtp_session->session) {
2864  switch_channel_t *channel = switch_core_session_get_channel(rtp_session->session);
2865  const char *var;
2866 
2867  if ((var = switch_channel_get_variable(channel, "multicast_ttl"))) {
2868  int ttl = atoi(var);
2869 
2870  if (ttl > 0 && ttl < 256) {
2871  if (switch_mcast_hops(new_sock, (uint8_t) ttl) != SWITCH_STATUS_SUCCESS) {
2872  *err = "Mutlicast TTL set failed";
2873  goto done;
2874  }
2875 
2876  }
2877  }
2878 
2879  }
2880 
2881  }
2882 
2883 
2884 
2885 #ifndef WIN32
2886  len = sizeof(i);
2888 
2889  switch_socket_sendto(new_sock, rtp_session->local_addr, 0, (void *) o, &len);
2890 
2891  x = 0;
2892  while (!ilen) {
2893  switch_status_t status;
2894  ilen = len;
2895  status = switch_socket_recvfrom(rtp_session->from_addr, new_sock, 0, (void *) i, &ilen);
2896 
2897  if (status != SWITCH_STATUS_SUCCESS && status != SWITCH_STATUS_BREAK) {
2898  break;
2899  }
2900 
2901  if (++x > 1000) {
2902  break;
2903  }
2904  switch_cond_next();
2905  }
2907 
2908 #endif
2909 
2910  old_sock = rtp_session->sock_input;
2911  rtp_session->sock_input = new_sock;
2912  new_sock = NULL;
2913 
2914  if (rtp_session->flags[SWITCH_RTP_FLAG_USE_TIMER] || rtp_session->flags[SWITCH_RTP_FLAG_NOBLOCK] || rtp_session->flags[SWITCH_RTP_FLAG_VIDEO]) {
2917  }
2918 
2919  switch_socket_create_pollset(&rtp_session->read_pollfd, rtp_session->sock_input, SWITCH_POLLIN | SWITCH_POLLERR, rtp_session->pool);
2920 
2921  if (rtp_session->flags[SWITCH_RTP_FLAG_ENABLE_RTCP]) {
2922  if ((status = enable_local_rtcp_socket(rtp_session, err)) == SWITCH_STATUS_SUCCESS) {
2923  *err = "Success";
2924  }
2925  } else {
2926  status = SWITCH_STATUS_SUCCESS;
2927  *err = "Success";
2928  }
2929 
2931 
2932  done:
2933 
2934  if (new_sock) {
2935  switch_socket_close(new_sock);
2936  }
2937 
2938  if (old_sock) {
2939  switch_socket_close(old_sock);
2940  }
2941 
2942 
2943  if (rtp_session->ready != 1) {
2944  WRITE_DEC(rtp_session);
2945  READ_DEC(rtp_session);
2946  }
2947 
2948  return status;
2949 }
switch_pollfd_t * read_pollfd
Definition: switch_rtp.c:323
uint8_t switch_rtp_ready(switch_rtp_t *rtp_session)
Test if an RTP session is ready.
Definition: switch_rtp.c:5147
switch_status_t switch_socket_bind(switch_socket_t *sock, switch_sockaddr_t *sa)
Definition: switch_apr.c:742
switch_status_t switch_mcast_hops(switch_socket_t *sock, uint8_t ttl)
Definition: switch_apr.c:961
#define WRITE_INC(rtp_session)
Definition: switch_rtp.c:69
#define switch_core_strdup(_pool, _todup)
Copy a string using memory allocation from a given pool.
Definition: switch_core.h:733
switch_socket_t * sock_input
Definition: switch_rtp.c:322
int32_t switch_sockaddr_get_family(switch_sockaddr_t *sa)
Definition: switch_apr.c:1006
switch_status_t switch_socket_recvfrom(switch_sockaddr_t *from, switch_socket_t *sock, int32_t flags, char *buf, size_t *len)
Definition: switch_apr.c:1021
#define READ_DEC(rtp_session)
Definition: switch_rtp.c:68
#define zstr(x)
Definition: switch_utils.h:314
_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.
#define WRITE_DEC(rtp_session)
Definition: switch_rtp.c:70
uint8_t ready
Definition: switch_rtp.c:432
switch_status_t switch_socket_sendto(switch_socket_t *sock, switch_sockaddr_t *where, int32_t flags, const char *buf, switch_size_t *len)
Definition: switch_apr.c:796
uint32_t flags[SWITCH_RTP_FLAG_INVALID]
Definition: switch_rtp.c:392
#define switch_channel_get_variable(_c, _v)
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.
Definition: switch_apr.c:1117
char * local_host_str
Definition: switch_rtp.c:400
#define READ_INC(rtp_session)
Definition: switch_rtp.c:67
switch_status_t switch_socket_opt_set(switch_socket_t *sock, int32_t opt, int32_t on)
Definition: switch_apr.c:907
#define SWITCH_POLLERR
Definition: switch_apr.h:1339
uintptr_t switch_size_t
switch_sockaddr_t * local_addr
Definition: switch_rtp.c:326
switch_status_t switch_mcast_interface(switch_socket_t *sock, switch_sockaddr_t *iface)
Definition: switch_apr.c:971
void switch_cond_next(void)
Definition: switch_time.c:658
#define SWITCH_POLLIN
Definition: switch_apr.h:1336
switch_memory_pool_t * pool
Definition: switch_rtp.c:393
void switch_rtp_set_flag(switch_rtp_t *rtp_session, switch_rtp_flag_t flag)
Set an RTP Flag.
Definition: switch_rtp.c:5372
switch_status_t switch_socket_create(switch_socket_t **new_sock, int family, int type, int protocol, switch_memory_pool_t *pool)
Definition: switch_apr.c:727
switch_status_t
Common return values.
#define SWITCH_SO_RCVBUF
Definition: switch_apr.h:997
#define SWITCH_SO_NONBLOCK
Definition: switch_apr.h:994
switch_status_t switch_socket_close(switch_socket_t *sock)
Definition: switch_apr.c:737
#define SWITCH_UNSPEC
Definition: switch_apr.h:1022
#define FALSE
switch_core_session_t * session
Definition: switch_rtp.c:472
#define SWITCH_SO_SNDBUF
Definition: switch_apr.h:996
#define SWITCH_SO_REUSEADDR
Definition: switch_apr.h:995
switch_status_t switch_mcast_join(switch_socket_t *sock, switch_sockaddr_t *join, switch_sockaddr_t *iface, switch_sockaddr_t *source)
Definition: switch_apr.c:956
#define TRUE
switch_port_t local_port
Definition: switch_rtp.c:416
struct fspr_socket_t switch_socket_t
Definition: switch_apr.h:1026
void switch_rtp_kill_socket(switch_rtp_t *rtp_session)
Kill the socket on an existing RTP session.
Definition: switch_rtp.c:5120
switch_sockaddr_t * from_addr
Definition: switch_rtp.c:394
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 ...
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)
Definition: switch_apr.c:839
static switch_status_t enable_local_rtcp_socket(switch_rtp_t *rtp_session, const char **err)
Definition: switch_rtp.c:2717

◆ switch_rtp_set_max_missed_packets()

void switch_rtp_set_max_missed_packets ( switch_rtp_t rtp_session,
uint32_t  max 
)

Definition at line 2963 of file switch_rtp.c.

References switch_rtp::flags, switch_rtp::max_missed_packets, switch_rtp::missed_count, switch_rtp::session, SWITCH_CHANNEL_SESSION_LOG, switch_log_printf(), SWITCH_LOG_WARNING, SWITCH_RTP_FLAG_UDPTL, and switch_rtp_ready().

Referenced by check_media_timeout_params(), switch_core_media_activate_rtp(), switch_core_media_negotiate_sdp(), switch_core_media_read_frame(), switch_core_media_receive_message(), and switch_core_media_toggle_hold().

2964 {
2965  if (!switch_rtp_ready(rtp_session) || rtp_session->flags[SWITCH_RTP_FLAG_UDPTL]) {
2966  return;
2967  }
2968 
2969  if (rtp_session->missed_count > max) {
2970 
2972  "new max missed packets(%d->%d) greater than current missed packets(%d). RTP will timeout.\n",
2973  rtp_session->max_missed_packets, max, rtp_session->missed_count);
2974  }
2975 
2976  rtp_session->max_missed_packets = max;
2977 }
#define SWITCH_CHANNEL_SESSION_LOG(x)
uint8_t switch_rtp_ready(switch_rtp_t *rtp_session)
Test if an RTP session is ready.
Definition: switch_rtp.c:5147
uint32_t max_missed_packets
Definition: switch_rtp.c:437
uint32_t flags[SWITCH_RTP_FLAG_INVALID]
Definition: switch_rtp.c:392
uint32_t missed_count
Definition: switch_rtp.c:438
switch_core_session_t * session
Definition: switch_rtp.c:472
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.

◆ switch_rtp_set_media_timeout()

void switch_rtp_set_media_timeout ( switch_rtp_t rtp_session,
uint32_t  ms 
)

Definition at line 2951 of file switch_rtp.c.

References switch_rtp::flags, switch_rtp::media_timeout, rtp_type, switch_rtp::session, SWITCH_CHANNEL_SESSION_LOG, switch_core_session_get_name, SWITCH_LOG_DEBUG1, switch_log_printf(), SWITCH_RTP_FLAG_UDPTL, switch_rtp_ready(), and switch_rtp_reset_media_timer().

Referenced by check_media_timeout_params(), switch_core_media_negotiate_sdp(), switch_core_media_receive_message(), and switch_core_media_toggle_hold().

2952 {
2953  if (!switch_rtp_ready(rtp_session) || rtp_session->flags[SWITCH_RTP_FLAG_UDPTL]) {
2954  return;
2955  }
2956 
2958  "%s MEDIA TIMEOUT %s set to %u\n", switch_core_session_get_name(rtp_session->session), rtp_type(rtp_session), ms);
2959  rtp_session->media_timeout = ms;
2960  switch_rtp_reset_media_timer(rtp_session);
2961 }
#define SWITCH_CHANNEL_SESSION_LOG(x)
uint8_t switch_rtp_ready(switch_rtp_t *rtp_session)
Test if an RTP session is ready.
Definition: switch_rtp.c:5147
uint32_t media_timeout
Definition: switch_rtp.c:440
#define switch_core_session_get_name(_s)
Definition: switch_core.h:265
#define rtp_type(rtp_session)
Definition: switch_rtp.c:540
void switch_rtp_reset_media_timer(switch_rtp_t *rtp_session)
Definition: switch_rtp.c:3028
uint32_t flags[SWITCH_RTP_FLAG_INVALID]
Definition: switch_rtp.c:392
switch_core_session_t * session
Definition: switch_rtp.c:472
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.

◆ switch_rtp_set_payload_map()

switch_status_t switch_rtp_set_payload_map ( switch_rtp_t rtp_session,
payload_map_t **  pmap 
)

Definition at line 2649 of file switch_rtp.c.

References switch_rtp::flag_mutex, switch_rtp::pmaps, switch_mutex_lock(), switch_mutex_unlock(), SWITCH_STATUS_FALSE, and SWITCH_STATUS_SUCCESS.

Referenced by switch_core_media_activate_rtp().

2650 {
2651 
2652  if (rtp_session) {
2653  switch_mutex_lock(rtp_session->flag_mutex);
2654  rtp_session->pmaps = pmap;
2655  switch_mutex_unlock(rtp_session->flag_mutex);
2656  return SWITCH_STATUS_SUCCESS;
2657  }
2658 
2659  return SWITCH_STATUS_FALSE;
2660 }
switch_mutex_t * flag_mutex
Definition: switch_rtp.c:426
switch_status_t switch_mutex_unlock(switch_mutex_t *lock)
Definition: switch_apr.c:313
switch_status_t switch_mutex_lock(switch_mutex_t *lock)
Definition: switch_apr.c:308
payload_map_t ** pmaps
Definition: switch_rtp.c:473

◆ switch_rtp_set_private()

void switch_rtp_set_private ( switch_rtp_t rtp_session,
void *  private_data 
)

Associate an arbitrary data pointer with and RTP session.

Parameters
rtp_sessionthe RTP session to assign the pointer to
private_datathe private data to assign

Definition at line 9228 of file switch_rtp.c.

References switch_rtp::private_data.

9229 {
9230  rtp_session->private_data = private_data;
9231 }
void * private_data
Definition: switch_rtp.c:379

◆ switch_rtp_set_remote_address()

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.

Parameters
rtp_sessionan RTP session to assign the remote address to
hostthe ip or fqhn of the remote address
portthe remote port
errpointer for error messages

Definition at line 3125 of file switch_rtp.c.

References switch_rtp::dtls, switch_rtp::eff_remote_host_str, switch_rtp::eff_remote_port, switch_rtp::flags, switch_rtp::local_addr, switch_rtp::pool, switch_dtls_s::remote_addr, switch_rtp::remote_addr, switch_rtp::remote_host_str, switch_rtp::remote_port, switch_rtp::rtcp_remote_addr, switch_rtp::rtcp_sock_output, switch_rtp::sock_input, switch_dtls_s::sock_output, switch_rtp::sock_output, switch_core_strdup, switch_mutex_lock(), switch_mutex_unlock(), SWITCH_RTP_FLAG_ENABLE_RTCP, SWITCH_RTP_FLAG_RTCP_MUX, switch_sockaddr_get_family(), switch_sockaddr_info_get(), switch_socket_close(), switch_socket_create(), SWITCH_STATUS_FALSE, SWITCH_STATUS_SUCCESS, SWITCH_UNSPEC, and switch_rtp::write_mutex.

Referenced by handle_ice(), rtp_common_read(), switch_core_media_activate_rtp(), switch_core_media_negotiate_sdp(), switch_core_media_process_t38_passthru(), switch_core_media_proxy_remote_addr(), switch_core_media_start_udptl(), switch_rtp_change_ice_dest(), and switch_rtp_new().

3127 {
3128  switch_sockaddr_t *remote_addr;
3130  *err = "Success";
3131 
3132  if (switch_sockaddr_info_get(&remote_addr, host, SWITCH_UNSPEC, port, 0, rtp_session->pool) != SWITCH_STATUS_SUCCESS || !remote_addr) {
3133  *err = "Remote Address Error!";
3134  return SWITCH_STATUS_FALSE;
3135  }
3136 
3137 
3138  switch_mutex_lock(rtp_session->write_mutex);
3139 
3140  rtp_session->remote_addr = remote_addr;
3141 
3142  if (change_adv_addr) {
3143  rtp_session->remote_host_str = switch_core_strdup(rtp_session->pool, host);
3144  rtp_session->remote_port = port;
3145  }
3146 
3147  rtp_session->eff_remote_host_str = switch_core_strdup(rtp_session->pool, host);
3148  rtp_session->eff_remote_port = port;
3149 
3150  if (rtp_session->sock_input && switch_sockaddr_get_family(rtp_session->remote_addr) == switch_sockaddr_get_family(rtp_session->local_addr)) {
3151  rtp_session->sock_output = rtp_session->sock_input;
3152  } else {
3153  if (rtp_session->sock_output && rtp_session->sock_output != rtp_session->sock_input) {
3154  switch_socket_close(rtp_session->sock_output);
3155  }
3156  if ((status = switch_socket_create(&rtp_session->sock_output,
3158  SOCK_DGRAM, 0, rtp_session->pool)) != SWITCH_STATUS_SUCCESS) {
3159 
3160  *err = "Socket Error!";
3161  }
3162  }
3163 
3164  if (rtp_session->dtls) {
3165  rtp_session->dtls->sock_output = rtp_session->sock_output;
3166 
3167  if (rtp_session->flags[SWITCH_RTP_FLAG_RTCP_MUX]) {
3168  status = switch_sockaddr_info_get(&rtp_session->dtls->remote_addr, host, SWITCH_UNSPEC, port, 0, rtp_session->pool);
3169  }
3170  }
3171 
3172 
3173  if (rtp_session->flags[SWITCH_RTP_FLAG_ENABLE_RTCP]) {
3174  if (rtp_session->flags[SWITCH_RTP_FLAG_RTCP_MUX]) {
3175  rtp_session->rtcp_remote_addr = rtp_session->remote_addr;
3176  rtp_session->rtcp_sock_output = rtp_session->sock_output;
3177  }/* else {
3178  if (remote_rtcp_port) {
3179  rtp_session->remote_rtcp_port = remote_rtcp_port;
3180  } else {
3181  rtp_session->remote_rtcp_port = rtp_session->eff_remote_port + 1;
3182  }
3183  status = enable_remote_rtcp_socket(rtp_session, err);
3184 
3185  if (rtp_session->rtcp_dtls) {
3186  //switch_sockaddr_info_get(&rtp_session->rtcp_dtls->remote_addr, host, SWITCH_UNSPEC, port, 0, rtp_session->pool);
3187  rtp_session->rtcp_dtls->remote_addr = rtp_session->rtcp_remote_addr;
3188  rtp_session->rtcp_dtls->sock_output = rtp_session->rtcp_sock_output;
3189  }
3190  }*/
3191  }
3192 
3193  switch_mutex_unlock(rtp_session->write_mutex);
3194 
3195  return status;
3196 }
switch_sockaddr_t * remote_addr
Definition: switch_rtp.c:287
switch_mutex_t * write_mutex
Definition: switch_rtp.c:428
switch_sockaddr_t * remote_addr
Definition: switch_rtp.c:340
#define switch_core_strdup(_pool, _todup)
Copy a string using memory allocation from a given pool.
Definition: switch_core.h:733
switch_socket_t * sock_input
Definition: switch_rtp.c:322
switch_port_t remote_port
Definition: switch_rtp.c:417
int32_t switch_sockaddr_get_family(switch_sockaddr_t *sa)
Definition: switch_apr.c:1006
char * remote_host_str
Definition: switch_rtp.c:401
switch_status_t switch_mutex_unlock(switch_mutex_t *lock)
Definition: switch_apr.c:313
switch_socket_t * sock_output
Definition: switch_rtp.c:286
switch_port_t eff_remote_port
Definition: switch_rtp.c:418
switch_status_t switch_mutex_lock(switch_mutex_t *lock)
Definition: switch_apr.c:308
uint32_t flags[SWITCH_RTP_FLAG_INVALID]
Definition: switch_rtp.c:392
switch_sockaddr_t * local_addr
Definition: switch_rtp.c:326
switch_dtls_t * dtls
Definition: switch_rtp.c:366
switch_memory_pool_t * pool
Definition: switch_rtp.c:393
struct fspr_sockaddr_t switch_sockaddr_t
Definition: switch_apr.h:1029
switch_socket_t * rtcp_sock_output
Definition: switch_rtp.c:322
switch_status_t switch_socket_create(switch_socket_t **new_sock, int family, int type, int protocol, switch_memory_pool_t *pool)
Definition: switch_apr.c:727
switch_status_t
Common return values.
switch_status_t switch_socket_close(switch_socket_t *sock)
Definition: switch_apr.c:737
#define SWITCH_UNSPEC
Definition: switch_apr.h:1022
switch_sockaddr_t * rtcp_remote_addr
Definition: switch_rtp.c:340
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)
Definition: switch_apr.c:839
char * eff_remote_host_str
Definition: switch_rtp.c:402
switch_socket_t * sock_output
Definition: switch_rtp.c:322

◆ switch_rtp_set_remote_ssrc()

switch_status_t switch_rtp_set_remote_ssrc ( switch_rtp_t rtp_session,
uint32_t  ssrc 
)

Definition at line 4466 of file switch_rtp.c.

References switch_rtp::flags, switch_rtp::remote_ssrc, switch_rtcp_report_block_frame::ssrc, SWITCH_RTP_FLAG_DETECT_SSRC, and SWITCH_STATUS_SUCCESS.

Referenced by check_ice(), and switch_core_media_activate_rtp().

4467 {
4468  rtp_session->remote_ssrc = ssrc;
4469  rtp_session->flags[SWITCH_RTP_FLAG_DETECT_SSRC] = 0;
4470  return SWITCH_STATUS_SUCCESS;
4471 }
uint32_t flags[SWITCH_RTP_FLAG_INVALID]
Definition: switch_rtp.c:392
uint32_t remote_ssrc
Definition: switch_rtp.c:373

◆ switch_rtp_set_ssrc()

switch_status_t switch_rtp_set_ssrc ( switch_rtp_t rtp_session,
uint32_t  ssrc 
)

Definition at line 4458 of file switch_rtp.c.

References rtp_msg_t::header, switch_rtp::send_msg, switch_rtcp_report_block_frame::ssrc, switch_rtp::ssrc, and SWITCH_STATUS_SUCCESS.

Referenced by rtp_common_write(), and switch_core_media_activate_rtp().

4459 {
4460  rtp_session->ssrc = ssrc;
4461  rtp_session->send_msg.header.ssrc = htonl(rtp_session->ssrc);
4462 
4463  return SWITCH_STATUS_SUCCESS;
4464 }
srtp_hdr_t header
Definition: switch_rtp.c:112
uint32_t ssrc
Definition: switch_rtp.c:372
rtp_msg_t send_msg
Definition: switch_rtp.c:327

◆ switch_rtp_set_start_port()

switch_port_t switch_rtp_set_start_port ( switch_port_t  port)

Set/Get RTP start port.

Parameters
portnew value (if > 0)
Returns
the current RTP start port

Definition at line 2582 of file switch_rtp.c.

References port_lock, START_PORT, switch_mutex_lock(), and switch_mutex_unlock().

Referenced by switch_core_get_rtp_port_range_start_port(), and switch_load_core_config().

2583 {
2584  if (port) {
2585  if (port_lock) {
2587  }
2588  START_PORT = port;
2589  if (port_lock) {
2591  }
2592  }
2593  return START_PORT;
2594 }
switch_status_t switch_mutex_unlock(switch_mutex_t *lock)
Definition: switch_apr.c:313
static switch_mutex_t * port_lock
Definition: switch_rtp.c:94
switch_status_t switch_mutex_lock(switch_mutex_t *lock)
Definition: switch_apr.c:308
static switch_port_t START_PORT
Definition: switch_rtp.c:92

◆ switch_rtp_set_telephony_event()

void switch_rtp_set_telephony_event ( switch_rtp_t rtp_session,
switch_payload_t  te 
)

Set the payload type to consider RFC2833 DTMF.

Parameters
rtp_sessionthe RTP session to modify
tethe payload type

Definition at line 4690 of file switch_rtp.c.

References switch_rtp::te.

Referenced by switch_core_media_activate_rtp(), switch_core_media_negotiate_sdp(), switch_core_media_recover_session(), and switch_core_media_set_telephony_event().

4691 {
4692  if (te > 95) {
4693  rtp_session->te = te;
4694  }
4695 }
switch_payload_t te
Definition: switch_rtp.c:423

◆ switch_rtp_set_telephony_recv_event()

void switch_rtp_set_telephony_recv_event ( switch_rtp_t rtp_session,
switch_payload_t  te 
)

Definition at line 4698 of file switch_rtp.c.

References switch_rtp::recv_te.

Referenced by switch_core_media_activate_rtp(), switch_core_media_negotiate_sdp(), switch_core_media_recover_session(), and switch_core_media_set_telephony_recv_event().

4699 {
4700  if (te > 95) {
4701  rtp_session->recv_te = te;
4702  }
4703 }
switch_payload_t recv_te
Definition: switch_rtp.c:424

◆ switch_rtp_set_video_buffer_size()

switch_status_t switch_rtp_set_video_buffer_size ( switch_rtp_t rtp_session,
uint32_t  frames,
uint32_t  max_frames 
)

Definition at line 4783 of file switch_rtp.c.

References switch_rtp::flags, switch_rtp::last_max_vb_frames, switch_rtp::pool, switch_rtp::session, SJB_TEXT, SJB_VIDEO, SWITCH_CHANNEL_SESSION_LOG, switch_core_session_request_video_refresh, switch_jb_create(), switch_jb_set_frames(), switch_jb_set_session(), SWITCH_LOG_DEBUG1, switch_log_printf(), SWITCH_RTP_FLAG_TEXT, switch_rtp_ready(), SWITCH_STATUS_FALSE, SWITCH_STATUS_SUCCESS, and switch_rtp::vb.

Referenced by check_jb(), and switch_core_media_activate_rtp().

4784 {
4785  if (!switch_rtp_ready(rtp_session)) {
4786  return SWITCH_STATUS_FALSE;
4787  }
4788 
4789  if (!max_frames) {
4790  max_frames = rtp_session->last_max_vb_frames;
4791  }
4792 
4793  if (!max_frames || frames >= max_frames) {
4794  max_frames = frames * 10;
4795  }
4796 
4797  rtp_session->last_max_vb_frames = max_frames;
4798 
4799  if (!rtp_session->vb) {
4800  switch_jb_create(&rtp_session->vb, rtp_session->flags[SWITCH_RTP_FLAG_TEXT] ? SJB_TEXT : SJB_VIDEO, frames, max_frames, rtp_session->pool);
4801  switch_jb_set_session(rtp_session->vb, rtp_session->session);
4802  } else {
4803  switch_jb_set_frames(rtp_session->vb, frames, max_frames);
4804  }
4805 
4806  //switch_rtp_flush(rtp_session);
4808 
4809  switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(rtp_session->session), SWITCH_LOG_DEBUG1, "Setting video buffer %u Frames.\n", frames);
4810 
4811  return SWITCH_STATUS_SUCCESS;
4812 }
#define SWITCH_CHANNEL_SESSION_LOG(x)
uint8_t switch_rtp_ready(switch_rtp_t *rtp_session)
Test if an RTP session is ready.
Definition: switch_rtp.c:5147
uint32_t last_max_vb_frames
Definition: switch_rtp.c:487
void switch_jb_set_session(switch_jb_t *jb, switch_core_session_t *session)
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)
uint32_t flags[SWITCH_RTP_FLAG_INVALID]
Definition: switch_rtp.c:392
#define switch_core_session_request_video_refresh(_s)
Definition: switch_core.h:2881
switch_status_t switch_jb_set_frames(switch_jb_t *jb, uint32_t min_frame_len, uint32_t max_frame_len)
switch_jb_t * vb
Definition: switch_rtp.c:435
switch_memory_pool_t * pool
Definition: switch_rtp.c:393
switch_core_session_t * session
Definition: switch_rtp.c:472
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.

◆ switch_rtp_shutdown()

void switch_rtp_shutdown ( void  )

Definition at line 2552 of file switch_rtp.c.

References port_lock, SWITCH_CHANNEL_LOG, switch_core_hash_destroy(), switch_core_hash_first, switch_core_hash_next(), switch_core_hash_this(), switch_core_port_allocator_destroy(), SWITCH_LOG_DEBUG, switch_log_printf(), switch_mutex_lock(), switch_mutex_unlock(), and switch_rtp_dtls_destroy().

Referenced by switch_core_destroy().

2553 {
2554  switch_core_port_allocator_t *alloc = NULL;
2555  switch_hash_index_t *hi;
2556  const void *var;
2557  void *val;
2558 
2559  if (!global_init) {
2560  return;
2561  }
2562 
2564 
2565  for (hi = switch_core_hash_first(alloc_hash); hi; hi = switch_core_hash_next(&hi)) {
2566  switch_core_hash_this(hi, &var, NULL, &val);
2567  if ((alloc = (switch_core_port_allocator_t *) val)) {
2568  switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "Destroy port allocator for %s\n", (char *) var);
2570  }
2571  }
2572 
2575 
2576 #ifdef ENABLE_SRTP
2577  srtp_crypto_kernel_shutdown();
2578 #endif
2580 }
#define SWITCH_CHANNEL_LOG
switch_status_t switch_core_hash_destroy(_Inout_ switch_hash_t **hash)
Destroy an existing hash table.
static int global_init
Definition: switch_rtp.c:814
switch_status_t switch_mutex_unlock(switch_mutex_t *lock)
Definition: switch_apr.c:313
static void switch_rtp_dtls_destroy(void)
Definition: switch_rtp.c:3684
static switch_mutex_t * port_lock
Definition: switch_rtp.c:94
switch_status_t switch_mutex_lock(switch_mutex_t *lock)
Definition: switch_apr.c:308
void switch_core_port_allocator_destroy(_Inout_ switch_core_port_allocator_t **alloc)
destroythe port allocator
static switch_hash_t * alloc_hash
Definition: switch_rtp.c:109
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_hash_index_t * switch_core_hash_next(_In_ switch_hash_index_t **hi)
Gets the next element of a hashtable.
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.
#define switch_core_hash_first(_h)
Definition: switch_core.h:1592

◆ switch_rtp_sync_stats()

switch_status_t switch_rtp_sync_stats ( switch_rtp_t rtp_session)

Definition at line 5163 of file switch_rtp.c.

References do_mos(), switch_rtp_numbers_t::error_log, switch_rtp::flags, switch_rtp_stats_t::inbound, switch_rtp_vad_data::session, switch_rtp::stats, error_period::stop, switch_channel_set_variable_printf(), switch_core_session_get_channel(), switch_micro_time_now(), SWITCH_RTP_FLAG_VAD, SWITCH_STATUS_FALSE, SWITCH_STATUS_SUCCESS, switch_rtp_vad_data::total_talk_time, and switch_rtp::vad_data.

Referenced by switch_core_media_sync_stats().

5164 {
5165  if (!rtp_session) {
5166  return SWITCH_STATUS_FALSE;
5167  }
5168 
5169  if (rtp_session->flags[SWITCH_RTP_FLAG_VAD]) {
5171 
5172  switch_channel_set_variable_printf(channel, "vad_total_talk_time_ms", "%u", (uint32_t)rtp_session->vad_data.total_talk_time / 1000);
5173  switch_channel_set_variable_printf(channel, "vad_total_talk_time_sec", "%u", (uint32_t)rtp_session->vad_data.total_talk_time / 1000000);
5174  }
5175 
5176  do_mos(rtp_session);
5177 
5178  if (rtp_session->stats.inbound.error_log && !rtp_session->stats.inbound.error_log->stop) {
5179  rtp_session->stats.inbound.error_log->stop = switch_micro_time_now();
5180  }
5181 
5182  return SWITCH_STATUS_SUCCESS;
5183 }
switch_status_t switch_channel_set_variable_printf(switch_channel_t *channel, const char *varname, const char *fmt,...)
switch_time_t switch_micro_time_now(void)
Get the current epoch time in microseconds.
Definition: switch_time.c:311
switch_time_t total_talk_time
Definition: switch_rtp.c:216
switch_rtp_numbers_t inbound
Definition: switch_types.h:760
struct switch_rtp_vad_data vad_data
Definition: switch_rtp.c:421
switch_core_session_t * session
Definition: switch_rtp.c:195
_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.
int64_t stop
Definition: switch_types.h:674
uint32_t flags[SWITCH_RTP_FLAG_INVALID]
Definition: switch_rtp.c:392
switch_rtp_stats_t stats
Definition: switch_rtp.c:450
struct error_period * error_log
Definition: switch_types.h:716
static void do_mos(switch_rtp_t *rtp_session)
Definition: switch_rtp.c:1571

◆ switch_rtp_test_flag()

uint32_t switch_rtp_test_flag ( switch_rtp_t rtp_session,
switch_rtp_flag_t  flags 
)

Test an RTP Flag.

Parameters
rtp_sessionthe RTP session
flagsthe flags to test
Returns
TRUE or FALSE

Definition at line 5426 of file switch_rtp.c.

References switch_rtp::flags.

Referenced by check_rtcp_and_ice(), get_next_write_ts(), process_rtcp_report(), rtp_common_read(), rtp_common_write(), switch_core_media_check_udptl_mode(), switch_core_media_receive_message(), and switch_rtp_udptl_mode().

5427 {
5428  return (uint32_t) rtp_session->flags[flags];
5429 }
uint32_t flags[SWITCH_RTP_FLAG_INVALID]
Definition: switch_rtp.c:392

◆ switch_rtp_udptl_mode()

switch_status_t switch_rtp_udptl_mode ( switch_rtp_t rtp_session)

Definition at line 3055 of file switch_rtp.c.

References FALSE, switch_rtp::flags, switch_rtp::max_missed_packets, memset(), switch_rtp::missed_count, ping_socket(), READ_DEC, READ_INC, switch_rtp::rtcp_sock_input, switch_rtp::rtcp_sock_output, switch_rtp::sock_input, switch_core_timer_destroy(), switch_rtp_break(), switch_rtp_clear_flag(), SWITCH_RTP_FLAG_ENABLE_RTCP, SWITCH_RTP_FLAG_FLUSH, SWITCH_RTP_FLAG_NOBLOCK, SWITCH_RTP_FLAG_PROXY_MEDIA, SWITCH_RTP_FLAG_RTCP_MUX, SWITCH_RTP_FLAG_STICKY_FLUSH, SWITCH_RTP_FLAG_UDPTL, SWITCH_RTP_FLAG_USE_TIMER, switch_rtp_ready(), switch_rtp_set_flag(), switch_rtp_test_flag(), SWITCH_SHUTDOWN_READWRITE, SWITCH_SO_NONBLOCK, switch_socket_close(), switch_socket_opt_set(), switch_socket_shutdown(), SWITCH_STATUS_FALSE, SWITCH_STATUS_SUCCESS, switch_rtp::timer, switch_timer::timer_interface, WRITE_DEC, and WRITE_INC.

Referenced by switch_core_media_start_udptl(), and switch_core_media_udptl_mode().

3056 {
3057  switch_socket_t *sock;
3058 
3059  if (!switch_rtp_ready(rtp_session)) {
3060  return SWITCH_STATUS_FALSE;
3061  }
3062 
3064  ping_socket(rtp_session);
3065  }
3066 
3067  READ_INC(rtp_session);
3068  WRITE_INC(rtp_session);
3069 
3070  if (rtp_session->flags[SWITCH_RTP_FLAG_USE_TIMER] || rtp_session->timer.timer_interface) {
3071  switch_core_timer_destroy(&rtp_session->timer);
3072  memset(&rtp_session->timer, 0, sizeof(rtp_session->timer));
3074  }
3075 
3076  rtp_session->missed_count = 0;
3077  rtp_session->max_missed_packets = 0;
3078 
3079  rtp_session->flags[SWITCH_RTP_FLAG_ENABLE_RTCP] = 0;
3080 
3081  if (rtp_session->flags[SWITCH_RTP_FLAG_RTCP_MUX]) {
3082  rtp_session->rtcp_sock_input = NULL;
3083  rtp_session->rtcp_sock_output = NULL;
3084  } else {
3085  if (rtp_session->rtcp_sock_input && rtp_session->rtcp_sock_input != rtp_session->sock_input) {
3086  ping_socket(rtp_session);
3088  }
3089 
3090  if (rtp_session->rtcp_sock_output && rtp_session->rtcp_sock_output != rtp_session->rtcp_sock_input &&
3091  rtp_session->rtcp_sock_output != rtp_session->sock_input) {
3093  }
3094 
3095  if ((sock = rtp_session->rtcp_sock_input)) {
3096  rtp_session->rtcp_sock_input = NULL;
3097  switch_socket_close(sock);
3098 
3099  if (rtp_session->rtcp_sock_output && rtp_session->rtcp_sock_output != sock) {
3100  sock = rtp_session->rtcp_sock_output;
3101  rtp_session->rtcp_sock_output = NULL;
3102  switch_socket_close(sock);
3103  }
3104  }
3105  }
3106 
3111 
3112  WRITE_DEC(rtp_session);
3113  READ_DEC(rtp_session);
3114 
3117 
3118  switch_rtp_break(rtp_session);
3119 
3120  return SWITCH_STATUS_SUCCESS;
3121 
3122 }
uint8_t switch_rtp_ready(switch_rtp_t *rtp_session)
Test if an RTP session is ready.
Definition: switch_rtp.c:5147
uint32_t max_missed_packets
Definition: switch_rtp.c:437
#define WRITE_INC(rtp_session)
Definition: switch_rtp.c:69
switch_socket_t * sock_input
Definition: switch_rtp.c:322
switch_socket_t * rtcp_sock_input
Definition: switch_rtp.c:322
#define READ_DEC(rtp_session)
Definition: switch_rtp.c:68
#define WRITE_DEC(rtp_session)
Definition: switch_rtp.c:70
switch_timer_interface_t * timer_interface
uint32_t flags[SWITCH_RTP_FLAG_INVALID]
Definition: switch_rtp.c:392
#define READ_INC(rtp_session)
Definition: switch_rtp.c:67
switch_status_t switch_socket_opt_set(switch_socket_t *sock, int32_t opt, int32_t on)
Definition: switch_apr.c:907
switch_status_t switch_core_timer_destroy(switch_timer_t *timer)
Destroy an allocated timer.
switch_socket_t * rtcp_sock_output
Definition: switch_rtp.c:322
void switch_rtp_clear_flag(switch_rtp_t *rtp_session, switch_rtp_flag_t flag)
Clear an RTP Flag.
Definition: switch_rtp.c:5431
void switch_rtp_set_flag(switch_rtp_t *rtp_session, switch_rtp_flag_t flag)
Set an RTP Flag.
Definition: switch_rtp.c:5372
uint32_t missed_count
Definition: switch_rtp.c:438
#define SWITCH_SO_NONBLOCK
Definition: switch_apr.h:994
switch_status_t switch_socket_close(switch_socket_t *sock)
Definition: switch_apr.c:737
switch_timer_t timer
Definition: switch_rtp.c:430
void switch_rtp_break(switch_rtp_t *rtp_session)
Definition: switch_rtp.c:5080
switch_status_t switch_socket_shutdown(switch_socket_t *sock, switch_shutdown_how_e how)
Definition: switch_apr.c:732
#define FALSE
static void ping_socket(switch_rtp_t *rtp_session)
Definition: switch_rtp.c:3044
uint32_t switch_rtp_test_flag(switch_rtp_t *rtp_session, switch_rtp_flag_t flags)
Test an RTP Flag.
Definition: switch_rtp.c:5426
struct fspr_socket_t switch_socket_t
Definition: switch_apr.h:1026
memset(buf, 0, buflen)

◆ switch_rtp_video_loss()

void switch_rtp_video_loss ( switch_rtp_t rtp_session)

Definition at line 5068 of file switch_rtp.c.

References switch_rtp::flags, switch_rtp::ice, switch_rtp_ice_t::ice_user, switch_rtp::pli_count, rtp_write_ready(), SWITCH_RTP_FLAG_PLI, and SWITCH_RTP_FLAG_VIDEO.

Referenced by switch_core_media_receive_message().

5069 {
5070 
5071  if (!rtp_write_ready(rtp_session, 0, __LINE__)) {
5072  return;
5073  }
5074 
5075  if (rtp_session->flags[SWITCH_RTP_FLAG_VIDEO] && (rtp_session->ice.ice_user || rtp_session->flags[SWITCH_RTP_FLAG_PLI])) {
5076  rtp_session->pli_count = 1;
5077  }
5078 }
uint16_t pli_count
Definition: switch_rtp.c:334
uint32_t flags[SWITCH_RTP_FLAG_INVALID]
Definition: switch_rtp.c:392
static int rtp_write_ready(switch_rtp_t *rtp_session, uint32_t bytes, int line)
Definition: switch_rtp.c:8270
switch_rtp_ice_t ice
Definition: switch_rtp.c:397

◆ switch_rtp_video_refresh()

void switch_rtp_video_refresh ( switch_rtp_t rtp_session)

Definition at line 5056 of file switch_rtp.c.

References switch_rtp::fir_count, switch_rtp::flags, switch_rtp::ice, switch_rtp_ice_t::ice_user, rtp_write_ready(), SWITCH_RTP_FLAG_FIR, SWITCH_RTP_FLAG_OLD_FIR, and SWITCH_RTP_FLAG_VIDEO.

Referenced by read_rtp_packet(), switch_core_media_receive_message(), and switch_rtp_break().

5057 {
5058 
5059  if (!rtp_write_ready(rtp_session, 0, __LINE__)) {
5060  return;
5061  }
5062 
5063  if (rtp_session->flags[SWITCH_RTP_FLAG_VIDEO] && (rtp_session->ice.ice_user || rtp_session->flags[SWITCH_RTP_FLAG_FIR] || rtp_session->flags[SWITCH_RTP_FLAG_OLD_FIR])) {
5064  rtp_session->fir_count = 1;
5065  }
5066 }
uint32_t flags[SWITCH_RTP_FLAG_INVALID]
Definition: switch_rtp.c:392
uint16_t fir_count
Definition: switch_rtp.c:333
static int rtp_write_ready(switch_rtp_t *rtp_session, uint32_t bytes, int line)
Definition: switch_rtp.c:8270
switch_rtp_ice_t ice
Definition: switch_rtp.c:397

◆ switch_rtp_write_frame()

int switch_rtp_write_frame ( switch_rtp_t rtp_session,
switch_frame_t frame 
)

Write data to a given RTP session.

Parameters
rtp_sessionthe RTP session to write to
framethe frame to write
Returns
the number of bytes written

Definition at line 8887 of file switch_rtp.c.

References CF_AUDIO_VIDEO_BUNDLE, switch_rtp::cng_pt, payload_map_s::current, switch_frame::data, switch_frame::datalen, switch_rtp::flag_mutex, switch_frame::flags, switch_rtp::flags, payload_map_s::hash, rtp_msg_t::header, INVALID_PT, switch_rtp::local_addr, switch_frame::m, switch_rtp_numbers_t::media_bytes, switch_rtp_numbers_t::media_packet_count, payload_map_s::negotiated, payload_map_s::next, switch_rtp_stats_t::outbound, switch_frame::packet, switch_rtp_numbers_t::packet_count, switch_frame::packetlen, switch_frame::payload, switch_rtp::payload, switch_frame::pmap, switch_rtp::pmaps, payload_map_s::pt, switch_rtp::queue_delay, switch_rtp_numbers_t::raw_bytes, payload_map_s::recv_pt, switch_rtp::remote_addr, switch_rtp::remote_port, RTP_BUG_GEN_ONE_GEN_ALL, switch_rtp::rtp_bugs, rtp_common_write(), switch_rtp::rtp_from_addr, rtp_write_ready(), switch_rtp::sending_dtmf, switch_rtp::seq, switch_rtp::session, SFF_CNG, SFF_PROXY_PACKET, SFF_RAW_RTP, SFF_RAW_RTP_PARSE_FRAME, SFF_RTP_HEADER, SFF_UDPTL_PACKET, switch_rtp::sock_output, switch_frame::ssrc, switch_rtp::ssrc, switch_rtp::stats, switch_assert, switch_channel_get_name(), SWITCH_CHANNEL_SESSION_LOG, SWITCH_CHANNEL_SESSION_LOG_CLEAN, switch_channel_test_flag(), switch_core_session_get_channel(), switch_get_addr(), SWITCH_LOG_CONSOLE, SWITCH_LOG_ERROR, switch_log_printf(), SWITCH_LOG_WARNING, switch_mutex_lock(), switch_mutex_unlock(), SWITCH_RTP_FLAG_DEBUG_RTP_WRITE, SWITCH_RTP_FLAG_PROXY_MEDIA, SWITCH_RTP_FLAG_RAW_WRITE, SWITCH_RTP_FLAG_RESET, SWITCH_RTP_FLAG_TEXT, SWITCH_RTP_FLAG_UDPTL, SWITCH_RTP_FLAG_VIDEO, switch_rtp_ready(), switch_rtp_write_manual(), SWITCH_SIZE_T_FMT, switch_sockaddr_get_port(), switch_socket_sendto(), SWITCH_STATUS_SUCCESS, switch_test_flag, and switch_frame::timestamp.

Referenced by switch_core_media_write_frame().

8888 {
8889  uint8_t fwd = 0;
8890  void *data = NULL;
8891  uint32_t len, ts = 0;
8892  switch_payload_t payload = 0;
8893  rtp_msg_t *send_msg = NULL;
8894  srtp_hdr_t local_header;
8895  int r = 0;
8896  switch_status_t status;
8897 
8898  if (!switch_rtp_ready(rtp_session) || !rtp_session->remote_addr) {
8899  return -1;
8900  }
8901 
8902  if (!rtp_write_ready(rtp_session, frame->datalen, __LINE__)) {
8904  }
8905 
8906  //if (rtp_session->flags[SWITCH_RTP_FLAG_VIDEO]) {
8907  // rtp_session->flags[SWITCH_RTP_FLAG_DEBUG_RTP_READ]++;
8908  // rtp_session->flags[SWITCH_RTP_FLAG_DEBUG_RTP_WRITE]++;
8909  //}
8910 
8911 
8913  rtp_session->flags[SWITCH_RTP_FLAG_PROXY_MEDIA] || rtp_session->flags[SWITCH_RTP_FLAG_UDPTL]) {
8914 
8915  //if (rtp_session->flags[SWITCH_RTP_FLAG_PROXY_MEDIA] || rtp_session->flags[SWITCH_RTP_FLAG_UDPTL]) {
8916  switch_size_t bytes;
8917  //char bufa[50];
8918 
8919  /* Fast PASS! */
8921  return 0;
8922  }
8923  bytes = frame->packetlen;
8924  //tx_host = switch_get_addr(bufa, sizeof(bufa), rtp_session->remote_addr);
8925 
8926  send_msg = frame->packet;
8927 
8928  if (!rtp_session->flags[SWITCH_RTP_FLAG_UDPTL] && !switch_test_flag(frame, SFF_UDPTL_PACKET)) {
8929 
8930  if (rtp_session->flags[SWITCH_RTP_FLAG_VIDEO] && rtp_session->payload > 0) {
8931  send_msg->header.pt = rtp_session->payload;
8932  }
8933 
8934  send_msg->header.ssrc = htonl(rtp_session->ssrc);
8935  send_msg->header.seq = htons(++rtp_session->seq);
8936  }
8937 
8938  if (rtp_session->flags[SWITCH_RTP_FLAG_DEBUG_RTP_WRITE]) {
8939  const char *tx_host;
8940  const char *old_host;
8941  const char *my_host;
8942 
8943  char bufa[50], bufb[50], bufc[50];
8944 
8945 
8946  tx_host = switch_get_addr(bufa, sizeof(bufa), rtp_session->rtp_from_addr);
8947  old_host = switch_get_addr(bufb, sizeof(bufb), rtp_session->remote_addr);
8948  my_host = switch_get_addr(bufc, sizeof(bufc), rtp_session->local_addr);
8949 
8951  "W %s b=%4ld %s:%u %s:%u %s:%u pt=%d ts=%u seq=%u m=%d\n",
8952  rtp_session->session ? switch_channel_get_name(switch_core_session_get_channel(rtp_session->session)) : "NoName",
8953  (long) bytes,
8954  my_host, switch_sockaddr_get_port(rtp_session->local_addr),
8955  old_host, rtp_session->remote_port,
8956  tx_host, switch_sockaddr_get_port(rtp_session->rtp_from_addr),
8957  send_msg->header.pt, ntohl(send_msg->header.ts), ntohs(send_msg->header.seq), send_msg->header.m);
8958 
8959  }
8960 
8961  if ((status = switch_socket_sendto(rtp_session->sock_output, rtp_session->remote_addr, 0, frame->packet, &bytes)) != SWITCH_STATUS_SUCCESS) {
8962  if (rtp_session->flags[SWITCH_RTP_FLAG_DEBUG_RTP_WRITE]) {
8963  switch_log_printf(SWITCH_CHANNEL_SESSION_LOG_CLEAN(rtp_session->session), SWITCH_LOG_ERROR, "bytes: %" SWITCH_SIZE_T_FMT ", status: %d", bytes, status);
8964  }
8965 
8966  return -1 * status;
8967  }
8968 
8969 
8970  rtp_session->stats.outbound.raw_bytes += bytes;
8971  rtp_session->stats.outbound.media_bytes += bytes;
8972  rtp_session->stats.outbound.media_packet_count++;
8973  rtp_session->stats.outbound.packet_count++;
8974  return (int) bytes;
8975  }
8976 
8977  fwd = (rtp_session->flags[SWITCH_RTP_FLAG_RAW_WRITE] &&
8979 
8980  if (!fwd && !rtp_session->sending_dtmf && !rtp_session->queue_delay && !rtp_session->flags[SWITCH_RTP_FLAG_VIDEO] &&
8981  rtp_session->flags[SWITCH_RTP_FLAG_RAW_WRITE] && (rtp_session->rtp_bugs & RTP_BUG_GEN_ONE_GEN_ALL)) {
8982 
8983  switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(rtp_session->session), SWITCH_LOG_WARNING, "Generating RTP locally but timestamp passthru is configured, disabling....\n");
8984  rtp_session->flags[SWITCH_RTP_FLAG_RAW_WRITE] = 0;
8985  rtp_session->flags[SWITCH_RTP_FLAG_RESET] = 1;
8986  }
8987 
8988  switch_assert(frame != NULL);
8989 
8990  if (switch_test_flag(frame, SFF_CNG)) {
8991  if (rtp_session->cng_pt != INVALID_PT) {
8992  payload = rtp_session->cng_pt;
8993  } else {
8994  return (int) frame->packetlen;
8995  }
8996  } else {
8997  payload = rtp_session->payload;
8998 #if 0
8999  if (rtp_session->pmaps && *rtp_session->pmaps) {
9000  payload_map_t *pmap;
9001  for (pmap = *rtp_session->pmaps; pmap; pmap = pmap->next) {
9002  if (pmap->current) {
9003  payload = pmap->pt;
9004  }
9005  }
9006  }
9007 #endif
9008  }
9009 
9010 
9011  if (switch_test_flag(frame, SFF_RTP_HEADER) || rtp_session->flags[SWITCH_RTP_FLAG_TEXT]) {
9012  switch_size_t wrote;
9013 
9014  wrote = switch_rtp_write_manual(rtp_session, frame->data, frame->datalen,
9015  frame->m, frame->payload, (uint32_t) (frame->timestamp), &frame->flags);
9016 
9017  rtp_session->stats.outbound.raw_bytes += wrote;
9018  rtp_session->stats.outbound.media_bytes += wrote;
9019  rtp_session->stats.outbound.media_packet_count++;
9020  rtp_session->stats.outbound.packet_count++;
9021 
9022  return wrote;
9023  }
9024 
9025  if (frame->pmap && rtp_session->pmaps && *rtp_session->pmaps) {
9026  payload_map_t *pmap;
9027 
9028  switch_mutex_lock(rtp_session->flag_mutex);
9029  for (pmap = *rtp_session->pmaps; pmap; pmap = pmap->next) {
9030  if (pmap->negotiated && pmap->hash == frame->pmap->hash) {
9031  payload = pmap->recv_pt;
9032  break;
9033  }
9034  }
9035  switch_mutex_unlock(rtp_session->flag_mutex);
9036  }
9037 
9038  if (fwd) {
9039  send_msg = frame->packet;
9040  local_header = send_msg->header;
9041  len = frame->packetlen;
9042  ts = 0;
9043 
9044  send_msg->header.pt = payload;
9045 
9047  send_msg->header.version = 2;
9048  send_msg->header.m = frame->m;
9049 
9050  send_msg->header.ts = htonl(frame->timestamp);
9051  if (frame->ssrc) {
9052  send_msg->header.ssrc = htonl(frame->ssrc);
9053  } else {
9054  send_msg->header.ssrc = htonl(rtp_session->ssrc);
9055  }
9056  }
9057 
9058  } else {
9059  data = frame->data;
9060  len = frame->datalen;
9061  ts = rtp_session->flags[SWITCH_RTP_FLAG_RAW_WRITE] ? (uint32_t) frame->timestamp : 0;
9062  }
9063 
9064  /*
9065  if (rtp_session->flags[SWITCH_RTP_FLAG_VIDEO]) {
9066  send_msg->header.pt = rtp_session->payload;
9067  }
9068  */
9069 
9070  r = rtp_common_write(rtp_session, send_msg, data, len, payload, ts, &frame->flags);
9071 
9072  if (send_msg) {
9073  send_msg->header = local_header;
9074  }
9075 
9076  return r;
9077 
9078 }
uint32_t queue_delay
Definition: switch_rtp.c:390
switch_bool_t m
Definition: switch_frame.h:83
#define SWITCH_CHANNEL_SESSION_LOG(x)
uint16_t switch_sockaddr_get_port(switch_sockaddr_t *sa)
Definition: switch_apr.c:1001
uint8_t switch_rtp_ready(switch_rtp_t *rtp_session)
Test if an RTP session is ready.
Definition: switch_rtp.c:5147
switch_sockaddr_t * remote_addr
Definition: switch_rtp.c:340
switch_mutex_t * flag_mutex
Definition: switch_rtp.c:426
uint32_t timestamp
Definition: switch_frame.h:80
unsigned long hash
switch_port_t remote_port
Definition: switch_rtp.c:417
switch_size_t media_bytes
Definition: switch_types.h:683
uint32_t ssrc
Definition: switch_frame.h:82
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.
struct payload_map_s * next
switch_payload_t cng_pt
Definition: switch_rtp.c:425
switch_status_t switch_mutex_unlock(switch_mutex_t *lock)
Definition: switch_apr.c:313
_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.
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)
Definition: switch_rtp.c:8290
switch_size_t raw_bytes
Definition: switch_types.h:682
uint32_t datalen
Definition: switch_frame.h:68
uint32_t packetlen
Definition: switch_frame.h:62
switch_status_t switch_socket_sendto(switch_socket_t *sock, switch_sockaddr_t *where, int32_t flags, const char *buf, switch_size_t *len)
Definition: switch_apr.c:796
switch_frame_flag_t flags
Definition: switch_frame.h:85
switch_status_t switch_mutex_lock(switch_mutex_t *lock)
Definition: switch_apr.c:308
payload_map_t * pmap
Definition: switch_frame.h:87
uint32_t flags[SWITCH_RTP_FLAG_INVALID]
Definition: switch_rtp.c:392
switch_sockaddr_t * rtp_from_addr
Definition: switch_rtp.c:394
switch_rtp_numbers_t outbound
Definition: switch_types.h:761
static int rtp_write_ready(switch_rtp_t *rtp_session, uint32_t bytes, int line)
Definition: switch_rtp.c:8270
uintptr_t switch_size_t
uint8_t negotiated
switch_sockaddr_t * local_addr
Definition: switch_rtp.c:326
uint16_t seq
Definition: switch_rtp.c:371
switch_payload_t pt
switch_size_t packet_count
Definition: switch_types.h:684
switch_rtp_stats_t stats
Definition: switch_rtp.c:450
#define SWITCH_CHANNEL_SESSION_LOG_CLEAN(x)
payload_map_t ** pmaps
Definition: switch_rtp.c:473
void * packet
Definition: switch_frame.h:60
#define SWITCH_SIZE_T_FMT
switch_status_t
Common return values.
srtp_hdr_t header
Definition: switch_rtp.c:112
switch_core_session_t * session
Definition: switch_rtp.c:472
int8_t sending_dtmf
Definition: switch_rtp.c:375
switch_size_t media_packet_count
Definition: switch_types.h:686
switch_rtp_bug_flag_t rtp_bugs
Definition: switch_rtp.c:449
uint32_t ssrc
Definition: switch_rtp.c:372
switch_payload_t payload
Definition: switch_frame.h:78
#define switch_test_flag(obj, flag)
Test for the existance of a flag on an arbitary object.
Definition: switch_utils.h:693
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.
switch_payload_t recv_pt
const char * switch_get_addr(char *buf, switch_size_t len, switch_sockaddr_t *in)
Definition: switch_apr.c:979
static const switch_payload_t INVALID_PT
Definition: switch_rtp.c:81
#define switch_assert(expr)
char * switch_channel_get_name(switch_channel_t *channel)
Retrieve the name of a given channel.
switch_payload_t payload
Definition: switch_rtp.c:377
switch_socket_t * sock_output
Definition: switch_rtp.c:322
uint8_t switch_payload_t
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.
Definition: switch_rtp.c:9107

◆ switch_rtp_write_manual()

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.

Parameters
rtp_sessionthe RTP session to write to
datadata to write
datalenthe size of the data
mset mark bit or not
payloadthe IANA payload number
tsthen number of bytes to increment the timestamp by
flagsframe flags
Returns
the number of bytes written

Definition at line 9107 of file switch_rtp.c.

References rtp_msg_t::body, switch_rtp::flags, rtp_msg_t::header, INVALID_PT, switch_rtp::last_write_ts, switch_rtp::remote_addr, rtp_header_len, rtp_write_ready(), switch_rtp::send_msg, switch_rtp::seq, SFF_RTP_HEADER, SWITCH_RTP_FLAG_RESET, SWITCH_RTP_MAX_BUF_LEN, switch_rtp_ready(), switch_rtp_write_raw(), SWITCH_STATUS_SUCCESS, SWITCH_TRUE, WRITE_DEC, WRITE_INC, and switch_rtp::write_msg.

Referenced by check_rtcp_and_ice(), do_2833(), and switch_rtp_write_frame().

9109 {
9110  switch_size_t bytes;
9111  int ret = -1;
9112 
9113  if (!switch_rtp_ready(rtp_session) || !rtp_session->remote_addr || datalen > SWITCH_RTP_MAX_BUF_LEN) {
9114  return -1;
9115  }
9116 
9117  if (!rtp_write_ready(rtp_session, datalen, __LINE__)) {
9118  return 0;
9119  }
9120 
9121  if (payload == INVALID_PT) {
9122  return 0;
9123  }
9124 
9125  WRITE_INC(rtp_session);
9126 
9127  rtp_session->write_msg = rtp_session->send_msg;
9128  rtp_session->write_msg.header.seq = htons(++rtp_session->seq);
9129  rtp_session->write_msg.header.ts = htonl(ts);
9130  rtp_session->write_msg.header.pt = payload;
9131  rtp_session->write_msg.header.m = m;
9132  memcpy(rtp_session->write_msg.body, data, datalen);
9133 
9134  bytes = rtp_header_len + datalen;
9135 
9136  if (switch_rtp_write_raw(rtp_session, (void *) &rtp_session->write_msg, &bytes, SWITCH_TRUE) != SWITCH_STATUS_SUCCESS) {
9137  rtp_session->seq--;
9138  ret = -1;
9139  goto end;
9140  }
9141 
9142  if (((*flags) & SFF_RTP_HEADER)) {
9143  rtp_session->last_write_ts = ts;
9144  rtp_session->flags[SWITCH_RTP_FLAG_RESET] = 0;
9145  }
9146 
9147  ret = (int) bytes;
9148 
9149  end:
9150 
9151  WRITE_DEC(rtp_session);
9152 
9153  return ret;
9154 }
uint8_t switch_rtp_ready(switch_rtp_t *rtp_session)
Test if an RTP session is ready.
Definition: switch_rtp.c:5147
switch_sockaddr_t * remote_addr
Definition: switch_rtp.c:340
#define WRITE_INC(rtp_session)
Definition: switch_rtp.c:69
#define SWITCH_RTP_MAX_BUF_LEN
Definition: switch_rtp.h:45
#define WRITE_DEC(rtp_session)
Definition: switch_rtp.c:70
uint32_t flags[SWITCH_RTP_FLAG_INVALID]
Definition: switch_rtp.c:392
char body[SWITCH_RTP_MAX_BUF_LEN+4+sizeof(char *)]
Definition: switch_rtp.c:113
static int rtp_write_ready(switch_rtp_t *rtp_session, uint32_t bytes, int line)
Definition: switch_rtp.c:8270
uintptr_t switch_size_t
uint16_t seq
Definition: switch_rtp.c:371
switch_status_t switch_rtp_write_raw(switch_rtp_t *rtp_session, void *data, switch_size_t *bytes, switch_bool_t process_encryption)
Definition: switch_rtp.c:9158
rtp_msg_t write_msg
Definition: switch_rtp.c:441
srtp_hdr_t header
Definition: switch_rtp.c:112
uint32_t last_write_ts
Definition: switch_rtp.c:382
rtp_msg_t send_msg
Definition: switch_rtp.c:327
static const switch_payload_t INVALID_PT
Definition: switch_rtp.c:81
#define rtp_header_len
Definition: switch_rtp.c:73

◆ switch_rtp_write_raw()

switch_status_t switch_rtp_write_raw ( switch_rtp_t rtp_session,
void *  data,
switch_size_t bytes,
switch_bool_t  process_encryption 
)

Definition at line 9158 of file switch_rtp.c.

References switch_rtp::flags, rtp_msg_t::header, switch_rtp::ice_mutex, switch_rtp::remote_addr, rtp_write_ready(), switch_rtp::send_ctx, switch_rtp::send_policy, switch_rtp::session, switch_rtp::sock_output, switch_rtp::srtp_idx_rtp, switch_assert, SWITCH_CHANNEL_SESSION_LOG, SWITCH_CRYPTO_MKI_INDEX, SWITCH_LOG_ERROR, SWITCH_LOG_INFO, switch_log_printf(), switch_mutex_lock(), switch_mutex_unlock(), switch_rtp_clear_flag(), SWITCH_RTP_FLAG_SECURE_SEND, SWITCH_RTP_FLAG_SECURE_SEND_MKI, SWITCH_RTP_FLAG_SECURE_SEND_RESET, SWITCH_RTP_MAX_BUF_LEN, switch_rtp_ready(), switch_socket_sendto(), SWITCH_STATUS_FALSE, SWITCH_STATUS_NOT_INITALIZED, WRITE_DEC, WRITE_INC, and switch_rtp::write_msg.

Referenced by handle_nack(), and switch_rtp_write_manual().

9159 {
9161 
9162  switch_assert(bytes);
9163 
9164  if (!switch_rtp_ready(rtp_session) || !rtp_session->remote_addr || *bytes > SWITCH_RTP_MAX_BUF_LEN) {
9165  return status;
9166  }
9167 
9168  if (!rtp_write_ready(rtp_session, *bytes, __LINE__)) {
9170  }
9171 
9172  WRITE_INC(rtp_session);
9173 
9174  if (process_encryption) {
9175 #ifdef ENABLE_SRTP
9176  switch_mutex_lock(rtp_session->ice_mutex);
9177  if (rtp_session->flags[SWITCH_RTP_FLAG_SECURE_SEND]) {
9178 
9179  int sbytes = (int) *bytes;
9180  srtp_err_status_t stat;
9181 
9182  if (rtp_session->flags[SWITCH_RTP_FLAG_SECURE_SEND_RESET]) {
9184  srtp_dealloc(rtp_session->send_ctx[rtp_session->srtp_idx_rtp]);
9185  rtp_session->send_ctx[rtp_session->srtp_idx_rtp] = NULL;
9186  if (srtp_create(&rtp_session->send_ctx[rtp_session->srtp_idx_rtp],
9187  &rtp_session->send_policy[rtp_session->srtp_idx_rtp]) || !rtp_session->send_ctx[rtp_session->srtp_idx_rtp]) {
9188  switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(rtp_session->session), SWITCH_LOG_ERROR, "Error! RE-Activating Secure RTP SEND\n");
9189  rtp_session->flags[SWITCH_RTP_FLAG_SECURE_SEND] = 0;
9190  status = SWITCH_STATUS_FALSE;
9191  switch_mutex_unlock(rtp_session->ice_mutex);
9192  goto end;
9193  } else {
9194  switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(rtp_session->session), SWITCH_LOG_INFO, "RE-Activating Secure RTP SEND\n");
9195  }
9196  }
9197 
9198  if (!rtp_session->flags[SWITCH_RTP_FLAG_SECURE_SEND_MKI]) {
9199  stat = srtp_protect(rtp_session->send_ctx[rtp_session->srtp_idx_rtp], &rtp_session->write_msg.header, &sbytes);
9200  } else {
9201  stat = srtp_protect_mki(rtp_session->send_ctx[rtp_session->srtp_idx_rtp], &rtp_session->write_msg.header, &sbytes, 1, SWITCH_CRYPTO_MKI_INDEX);
9202  }
9203 
9204  if (stat) {
9205  switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(rtp_session->session), SWITCH_LOG_ERROR, "Error: SRTP protection failed with code %d\n", stat);
9206  }
9207  *bytes = sbytes;
9208  }
9209  switch_mutex_unlock(rtp_session->ice_mutex);
9210 #endif
9211  }
9212 
9213  status = switch_socket_sendto(rtp_session->sock_output, rtp_session->remote_addr, 0, data, bytes);
9214 #if defined(ENABLE_SRTP)
9215  end:
9216 #endif
9217 
9218  WRITE_DEC(rtp_session);
9219 
9220  return status;
9221 }
#define SWITCH_CHANNEL_SESSION_LOG(x)
uint8_t switch_rtp_ready(switch_rtp_t *rtp_session)
Test if an RTP session is ready.
Definition: switch_rtp.c:5147
switch_sockaddr_t * remote_addr
Definition: switch_rtp.c:340
#define WRITE_INC(rtp_session)
Definition: switch_rtp.c:69
srtp_policy_t send_policy[2]
Definition: switch_rtp.c:356
#define SWITCH_RTP_MAX_BUF_LEN
Definition: switch_rtp.h:45
#define SWITCH_CRYPTO_MKI_INDEX
switch_status_t switch_mutex_unlock(switch_mutex_t *lock)
Definition: switch_apr.c:313
srtp_ctx_t * send_ctx[2]
Definition: switch_rtp.c:353
#define WRITE_DEC(rtp_session)
Definition: switch_rtp.c:70
switch_status_t switch_socket_sendto(switch_socket_t *sock, switch_sockaddr_t *where, int32_t flags, const char *buf, switch_size_t *len)
Definition: switch_apr.c:796
switch_status_t switch_mutex_lock(switch_mutex_t *lock)
Definition: switch_apr.c:308
uint32_t flags[SWITCH_RTP_FLAG_INVALID]
Definition: switch_rtp.c:392
static int rtp_write_ready(switch_rtp_t *rtp_session, uint32_t bytes, int line)
Definition: switch_rtp.c:8270
void switch_rtp_clear_flag(switch_rtp_t *rtp_session, switch_rtp_flag_t flag)
Clear an RTP Flag.
Definition: switch_rtp.c:5431
rtp_msg_t write_msg
Definition: switch_rtp.c:441
switch_status_t
Common return values.
srtp_hdr_t header
Definition: switch_rtp.c:112
switch_mutex_t * ice_mutex
Definition: switch_rtp.c:429
switch_core_session_t * session
Definition: switch_rtp.c:472
int srtp_idx_rtp
Definition: switch_rtp.c:363
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.
#define switch_assert(expr)
switch_socket_t * sock_output
Definition: switch_rtp.c:322

◆ switch_rtp_zerocopy_read()

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.

Parameters
rtp_sessionthe RTP session to read from
dataa pointer to point directly to the RTP read buffer
datalena pointer to the datalen
payload_typethe IANA payload of the packet
flagsflags
io_flagsi/o flags
Returns
the number of bytes read

Definition at line 8244 of file switch_rtp.c.

References RTP_BODY, rtp_common_read(), rtp_header_len, switch_rtp_ready(), SWITCH_STATUS_FALSE, SWITCH_STATUS_GENERR, and SWITCH_STATUS_SUCCESS.

8247 {
8248  int bytes = 0;
8249 
8250  if (!switch_rtp_ready(rtp_session)) {
8251  return SWITCH_STATUS_FALSE;
8252  }
8253 
8254  bytes = rtp_common_read(rtp_session, payload_type, NULL, flags, io_flags);
8255  *data = RTP_BODY(rtp_session);
8256 
8257  if (bytes < 0) {
8258  *datalen = 0;
8259  return SWITCH_STATUS_GENERR;
8260  } else {
8261  if (bytes > rtp_header_len) {
8262  bytes -= rtp_header_len;
8263  }
8264  }
8265 
8266  *datalen = bytes;
8267  return SWITCH_STATUS_SUCCESS;
8268 }
uint8_t switch_rtp_ready(switch_rtp_t *rtp_session)
Test if an RTP session is ready.
Definition: switch_rtp.c:5147
#define RTP_BODY(_s)
Definition: switch_rtp.c:118
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)
Definition: switch_rtp.c:7301
#define rtp_header_len
Definition: switch_rtp.c:73

◆ switch_rtp_zerocopy_read_frame()

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.

Parameters
rtp_sessionthe RTP session to read from
framea frame to populate with information
io_flagsi/o flags
Returns
the number of bytes read

Definition at line 8192 of file switch_rtp.c.

References switch_frame::data, switch_frame::datalen, switch_frame::flags, switch_rtp::flags, switch_rtp::last_rtp_hdr, switch_frame::m, switch_frame::packet, switch_frame::packetlen, switch_frame::payload, switch_frame::pmap, switch_rtp::recv_msg, switch_rtp::recv_te, RTP_BODY, rtp_common_read(), rtp_header_len, switch_frame::seq, SFF_CNG, SFF_EXTERNAL, SFF_RAW_RTP, SFF_RFC2833, switch_frame::source, switch_frame::ssrc, SWITCH_FALSE, SWITCH_RTP_FLAG_UDPTL, switch_rtp_ready(), switch_set_flag, SWITCH_STATUS_BREAK, SWITCH_STATUS_FALSE, SWITCH_STATUS_GENERR, SWITCH_STATUS_SUCCESS, SWITCH_STATUS_TIMEOUT, switch_test_flag, SWITCH_TRUE, and switch_frame::timestamp.

Referenced by check_engine(), and switch_core_media_read_frame().

8193 {
8194  int bytes = 0;
8195 
8196  if (!switch_rtp_ready(rtp_session)) {
8197  return SWITCH_STATUS_FALSE;
8198  }
8199 
8200  bytes = rtp_common_read(rtp_session, &frame->payload, &frame->pmap, &frame->flags, io_flags);
8201 
8202  frame->data = RTP_BODY(rtp_session);
8203 
8204  if (!rtp_session->flags[SWITCH_RTP_FLAG_UDPTL] && (bytes < rtp_header_len || switch_test_flag(frame, SFF_CNG))) {
8205  frame->packet = NULL;
8206  frame->timestamp = 0;
8207  frame->seq = 0;
8208  frame->ssrc = 0;
8209  frame->m = 0;
8210  } else {
8211 
8212  frame->packet = &rtp_session->recv_msg;
8213  frame->packetlen = bytes;
8214  frame->source = __FILE__;
8215 
8216  switch_set_flag(frame, SFF_RAW_RTP);
8217  switch_set_flag(frame, SFF_EXTERNAL);
8218  if (frame->payload == rtp_session->recv_te) {
8219  switch_set_flag(frame, SFF_RFC2833);
8220  }
8221  frame->timestamp = ntohl(rtp_session->last_rtp_hdr.ts);
8222  frame->seq = (uint16_t) ntohs((uint16_t) rtp_session->last_rtp_hdr.seq);
8223  frame->ssrc = ntohl(rtp_session->last_rtp_hdr.ssrc);
8224  frame->m = rtp_session->last_rtp_hdr.m ? SWITCH_TRUE : SWITCH_FALSE;
8225  }
8226 
8227 
8228  if (bytes < 0) {
8229  frame->datalen = 0;
8230  return bytes == -2 ? SWITCH_STATUS_TIMEOUT : SWITCH_STATUS_GENERR;
8231  } else if (!rtp_session->flags[SWITCH_RTP_FLAG_UDPTL]) {
8232  if (bytes < rtp_header_len) {
8233  frame->datalen = 0;
8234  return SWITCH_STATUS_BREAK;
8235  } else {
8236  bytes -= rtp_header_len;
8237  }
8238  }
8239 
8240  frame->datalen = bytes;
8241  return SWITCH_STATUS_SUCCESS;
8242 }
switch_bool_t m
Definition: switch_frame.h:83
#define switch_set_flag(obj, flag)
Set a flag on an arbitrary object.
Definition: switch_utils.h:700
uint8_t switch_rtp_ready(switch_rtp_t *rtp_session)
Test if an RTP session is ready.
Definition: switch_rtp.c:5147
uint32_t timestamp
Definition: switch_frame.h:80
const char * source
Definition: switch_frame.h:58
uint32_t ssrc
Definition: switch_frame.h:82
uint16_t seq
Definition: switch_frame.h:81
uint32_t datalen
Definition: switch_frame.h:68
uint32_t packetlen
Definition: switch_frame.h:62
switch_frame_flag_t flags
Definition: switch_frame.h:85
payload_map_t * pmap
Definition: switch_frame.h:87
uint32_t flags[SWITCH_RTP_FLAG_INVALID]
Definition: switch_rtp.c:392
#define RTP_BODY(_s)
Definition: switch_rtp.c:118
void * packet
Definition: switch_frame.h:60
rtp_msg_t recv_msg
Definition: switch_rtp.c:341
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)
Definition: switch_rtp.c:7301
switch_payload_t recv_te
Definition: switch_rtp.c:424
switch_payload_t payload
Definition: switch_frame.h:78
#define switch_test_flag(obj, flag)
Test for the existance of a flag on an arbitary object.
Definition: switch_utils.h:693
rtp_hdr_t last_rtp_hdr
Definition: switch_rtp.c:369
#define rtp_header_len
Definition: switch_rtp.c:73