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 5638 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().

5639 {
5640 
5641  if (rtp_session->flags[SWITCH_RTP_FLAG_PROXY_MEDIA] ||
5642  rtp_session->flags[SWITCH_RTP_FLAG_UDPTL]) {
5643  return;
5644  }
5645 
5646 
5647  if (switch_rtp_ready(rtp_session)) {
5648  rtp_session->flags[SWITCH_RTP_FLAG_RESET] = 1;
5649  rtp_session->flags[SWITCH_RTP_FLAG_FLUSH] = 1;
5650  reset_jitter_seq(rtp_session);
5651 
5652  switch (flush) {
5655  break;
5658  break;
5659  default:
5660  break;
5661  }
5662  }
5663 }
uint8_t switch_rtp_ready(switch_rtp_t *rtp_session)
Test if an RTP session is ready.
Definition: switch_rtp.c:5150
uint32_t flags[SWITCH_RTP_FLAG_INVALID]
Definition: switch_rtp.c:396
void switch_rtp_clear_flag(switch_rtp_t *rtp_session, switch_rtp_flag_t flag)
Clear an RTP Flag.
Definition: switch_rtp.c:5434
void switch_rtp_set_flag(switch_rtp_t *rtp_session, switch_rtp_flag_t flag)
Set an RTP Flag.
Definition: switch_rtp.c:5375
static void reset_jitter_seq(switch_rtp_t *rtp_session)
Definition: switch_rtp.c:1650

◆ 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 8175 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().

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

◆ switch_rtp_ack_bitrate()

switch_status_t switch_rtp_ack_bitrate ( switch_rtp_t rtp_session,
uint32_t  bps 
)

Definition at line 5048 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().

5049 {
5050  if (!rtp_write_ready(rtp_session, 0, __LINE__) || rtp_session->tmmbn) {
5051  return SWITCH_STATUS_FALSE;
5052  }
5053 
5054  rtp_session->tmmbn = bps;
5055 
5056  return SWITCH_STATUS_SUCCESS;
5057 }
uint32_t tmmbn
Definition: switch_rtp.c:341
static int rtp_write_ready(switch_rtp_t *rtp_session, uint32_t bytes, int line)
Definition: switch_rtp.c:8273

◆ 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 4933 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().

4936 {
4937  char ice_user[STUN_USERNAME_MAX_SIZE];
4938  char user_ice[STUN_USERNAME_MAX_SIZE];
4939  char luser_ice[SDP_UFRAG_MAX_SIZE];
4940  switch_rtp_ice_t *ice;
4941  char *host = NULL;
4942  switch_port_t port = 0;
4943  char bufc[50];
4944 
4945 
4946  switch_mutex_lock(rtp_session->ice_mutex);
4947 
4948  if (proto == IPR_RTP) {
4949  ice = &rtp_session->ice;
4950  rtp_session->flags[SWITCH_RTP_FLAG_PAUSE] = 0;
4951  rtp_session->flags[SWITCH_RTP_FLAG_MUTE] = 0;
4952  } else {
4953  ice = &rtp_session->rtcp_ice;
4954  }
4955 
4956  ice->proto = proto;
4957 
4958  if ((type & ICE_VANILLA)) {
4959  switch_snprintf(ice_user, sizeof(ice_user), "%s:%s", login, rlogin);
4960  switch_snprintf(user_ice, sizeof(user_ice), "%s:%s", rlogin, login);
4961  switch_snprintf(luser_ice, sizeof(luser_ice), "%s%s", rlogin, login);
4962  ice->ready = ice->rready = 0;
4963  ice->cand_responsive = 0;
4964  } else {
4965  switch_snprintf(ice_user, sizeof(ice_user), "%s%s", login, rlogin);
4966  switch_snprintf(user_ice, sizeof(user_ice), "%s%s", rlogin, login);
4967  switch_snprintf(luser_ice, sizeof(luser_ice), "");
4968  ice->ready = ice->rready = 1;
4969  ice->cand_responsive = 0;
4970  }
4971 
4972  ice->ice_user = switch_core_strdup(rtp_session->pool, ice_user);
4973  ice->user_ice = switch_core_strdup(rtp_session->pool, user_ice);
4974  ice->luser_ice = switch_core_strdup(rtp_session->pool, luser_ice);
4975  ice->type = type;
4976  ice->ice_params = ice_params;
4977  ice->pass = "";
4978  ice->rpass = "";
4980  ice->initializing = 1;
4981 
4982  if (password) {
4983  ice->pass = switch_core_strdup(rtp_session->pool, password);
4984  }
4985 
4986  if (rpassword) {
4987  ice->rpass = switch_core_strdup(rtp_session->pool, rpassword);
4988  }
4989 
4990  if ((ice->type & ICE_VANILLA) && ice->ice_params) {
4991  host = ice->ice_params->cands[ice->ice_params->chosen[ice->proto]][ice->proto].con_addr;
4992  port = ice->ice_params->cands[ice->ice_params->chosen[ice->proto]][ice->proto].con_port;
4993 
4994  if (!host || !port || switch_sockaddr_info_get(&ice->addr, host, SWITCH_UNSPEC, port, 0, rtp_session->pool) != SWITCH_STATUS_SUCCESS || !ice->addr) {
4995  switch_mutex_unlock(rtp_session->ice_mutex);
4996  switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(rtp_session->session), SWITCH_LOG_ERROR, "Error setting remote host!\n");
4997  return SWITCH_STATUS_FALSE;
4998  }
4999  } else {
5000  if (proto == IPR_RTP) {
5001  ice->addr = rtp_session->remote_addr;
5002  } else {
5003  ice->addr = rtp_session->rtcp_remote_addr;
5004  }
5005 
5006  host = (char *)switch_get_addr(bufc, sizeof(bufc), ice->addr);
5007  port = switch_sockaddr_get_port(ice->addr);
5008  }
5009 
5010  switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(rtp_session->session), SWITCH_LOG_NOTICE, "Activating %s %s ICE: %s %s:%d\n",
5011  proto == IPR_RTP ? "RTP" : "RTCP", rtp_type(rtp_session), ice_user, host, port);
5012 
5013 
5014  rtp_session->rtp_bugs |= RTP_BUG_ACCEPT_ANY_PACKETS;
5015 
5016 
5017  if (rtp_session->flags[SWITCH_RTP_FLAG_VIDEO]) {
5018  rtp_session->flags[SWITCH_RTP_FLAG_VIDEO_BREAK] = 1;
5019  switch_rtp_break(rtp_session);
5020  }
5021 
5022  switch_mutex_unlock(rtp_session->ice_mutex);
5023 
5024  return SWITCH_STATUS_SUCCESS;
5025 }
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:344
#define SDP_UFRAG_MAX_SIZE
Definition: switch_rtp.c:88
switch_sockaddr_t * addr
Definition: switch_rtp.c:252
#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:256
uint8_t initializing
Definition: switch_rtp.c:261
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:254
#define rtp_type(rtp_session)
Definition: switch_rtp.c:544
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:255
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:396
uint8_t cand_responsive
Definition: switch_rtp.c:265
char * con_addr
Definition: switch_rtp.h:99
uint16_t switch_port_t
switch_rtp_ice_t rtcp_ice
Definition: switch_rtp.c:402
switch_memory_pool_t * pool
Definition: switch_rtp.c:397
#define STUN_USERNAME_MAX_SIZE
Definition: switch_rtp.c:87
ice_proto_t proto
Definition: switch_rtp.c:257
void switch_rtp_break(switch_rtp_t *rtp_session)
Definition: switch_rtp.c:5083
#define SWITCH_UNSPEC
Definition: switch_apr.h:1022
switch_mutex_t * ice_mutex
Definition: switch_rtp.c:433
switch_core_session_t * session
Definition: switch_rtp.c:476
switch_rtp_ice_t ice
Definition: switch_rtp.c:401
switch_rtp_bug_flag_t rtp_bugs
Definition: switch_rtp.c:453
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:344
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 4837 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().

4842 {
4844 
4845  if (!switch_rtp_ready(rtp_session)) {
4846  return SWITCH_STATUS_FALSE;
4847  }
4848 
4849  if (queue_frames < 1) {
4850  queue_frames = 3;
4851  }
4852 
4853  if (max_queue_frames < queue_frames) {
4854  max_queue_frames = queue_frames * 3;
4855  }
4856 
4857 
4858 
4859  if (rtp_session->jb) {
4860  status = switch_jb_set_frames(rtp_session->jb, queue_frames, max_queue_frames);
4861  } else {
4862  READ_INC(rtp_session);
4863  status = switch_jb_create(&rtp_session->jb, SJB_AUDIO, queue_frames, max_queue_frames, rtp_session->pool);
4864  switch_jb_set_session(rtp_session->jb, rtp_session->session);
4865  switch_jb_set_jitter_estimator(rtp_session->jb, &rtp_session->stats.rtcp.inter_jitter, samples_per_packet, samples_per_second);
4867  switch_jb_ts_mode(rtp_session->jb, samples_per_packet, samples_per_second);
4868  }
4869  //switch_jb_debug_level(rtp_session->jb, 10);
4870  READ_DEC(rtp_session);
4871  }
4872 
4873 
4874 
4875  return status;
4876 }
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:5150
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:773
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:454
switch_memory_pool_t * pool
Definition: switch_rtp.c:397
switch_jb_t * jb
Definition: switch_rtp.c:438
switch_status_t
Common return values.
switch_core_session_t * session
Definition: switch_rtp.c:476
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 4878 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().

4879 {
4880  const char *err = NULL;
4881 
4882  if (!rtp_session->ms_per_packet) {
4883  return SWITCH_STATUS_FALSE;
4884  }
4885 
4886  rtp_session->flags[SWITCH_RTP_FLAG_ENABLE_RTCP] = 1;
4887 
4888  if (!(rtp_session->remote_rtcp_port = remote_port)) {
4889  rtp_session->remote_rtcp_port = rtp_session->remote_port + 1;
4890  }
4891 
4892  if (mux) {
4893  rtp_session->flags[SWITCH_RTP_FLAG_RTCP_MUX]++;
4894  }
4895 
4896 
4897  if (send_rate == -1) {
4898 
4899  rtp_session->flags[SWITCH_RTP_FLAG_RTCP_PASSTHRU] = 1;
4900  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);
4901  } else {
4902  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);
4903 
4904  rtp_session->rtcp_interval = send_rate;
4905  }
4906 
4907  if (rtp_session->flags[SWITCH_RTP_FLAG_RTCP_MUX]) {
4908 
4910  rtp_session->remote_rtcp_port, 0, rtp_session->pool) != SWITCH_STATUS_SUCCESS || !rtp_session->rtcp_remote_addr) {
4911  switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(rtp_session->session), SWITCH_LOG_ERROR, "RTCP MUX Remote Address Error!");
4912  return SWITCH_STATUS_FALSE;
4913  }
4914 
4915  rtp_session->rtcp_local_addr = rtp_session->local_addr;
4916  rtp_session->rtcp_from_addr = rtp_session->from_addr;
4917  rtp_session->rtcp_sock_input = rtp_session->sock_input;
4918  rtp_session->rtcp_sock_output = rtp_session->sock_output;
4919 
4920  rtp_session->rtcp_recv_msg_p = (rtcp_msg_t *) &rtp_session->recv_msg;
4921 
4922  return SWITCH_STATUS_SUCCESS;
4923 
4924  //return enable_remote_rtcp_socket(rtp_session, &err);
4925  } else {
4926  rtp_session->rtcp_recv_msg_p = (rtcp_msg_t *) &rtp_session->rtcp_recv_msg;
4927  }
4928 
4929  return enable_local_rtcp_socket(rtp_session, &err) || enable_remote_rtcp_socket(rtp_session, &err);
4930 
4931 }
#define SWITCH_CHANNEL_SESSION_LOG(x)
switch_sockaddr_t * rtcp_from_addr
Definition: switch_rtp.c:398
switch_sockaddr_t * rtcp_local_addr
Definition: switch_rtp.c:330
switch_port_t remote_rtcp_port
Definition: switch_rtp.c:423
switch_socket_t * sock_input
Definition: switch_rtp.c:326
switch_port_t remote_port
Definition: switch_rtp.c:421
switch_socket_t * rtcp_sock_input
Definition: switch_rtp.c:326
rtcp_msg_t rtcp_recv_msg
Definition: switch_rtp.c:346
uint32_t flags[SWITCH_RTP_FLAG_INVALID]
Definition: switch_rtp.c:396
switch_sockaddr_t * local_addr
Definition: switch_rtp.c:330
switch_memory_pool_t * pool
Definition: switch_rtp.c:397
switch_socket_t * rtcp_sock_output
Definition: switch_rtp.c:326
int rtcp_interval
Definition: switch_rtp.c:462
static switch_status_t enable_remote_rtcp_socket(switch_rtp_t *rtp_session, const char **err)
Definition: switch_rtp.c:2676
rtp_msg_t recv_msg
Definition: switch_rtp.c:345
#define SWITCH_UNSPEC
Definition: switch_apr.h:1022
switch_core_session_t * session
Definition: switch_rtp.c:476
uint32_t ms_per_packet
Definition: switch_rtp.c:414
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:398
switch_sockaddr_t * rtcp_remote_addr
Definition: switch_rtp.c:344
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:406
static switch_status_t enable_local_rtcp_socket(switch_rtp_t *rtp_session, const char **err)
Definition: switch_rtp.c:2720
rtcp_msg_t * rtcp_recv_msg_p
Definition: switch_rtp.c:347
switch_socket_t * sock_output
Definition: switch_rtp.c:326

◆ 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 3816 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().

3817 {
3818  switch_dtls_t *dtls;
3819  const char *var;
3820  int ret;
3821  const char *kind = "";
3822  unsigned long ssl_method_error = 0;
3823  unsigned long ssl_ctx_error = 0;
3824  const SSL_METHOD *ssl_method;
3825  SSL_CTX *ssl_ctx;
3826 #if OPENSSL_VERSION_NUMBER < 0x30000000
3827  BIO *bio;
3828  DH *dh;
3829 #endif
3831 #ifndef OPENSSL_NO_EC
3832 #if OPENSSL_VERSION_NUMBER < 0x10002000L
3833  EC_KEY* ecdh;
3834 #endif
3835 #endif
3836 
3837 #ifndef HAVE_OPENSSL_DTLS_SRTP
3838  return SWITCH_STATUS_FALSE;
3839 #endif
3840 
3841  if (!switch_rtp_ready(rtp_session)) {
3842  return SWITCH_STATUS_FALSE;
3843  }
3844 
3845  switch_mutex_lock(rtp_session->ice_mutex);
3846 
3847  if (!((type & DTLS_TYPE_RTP) || (type & DTLS_TYPE_RTCP)) || !((type & DTLS_TYPE_CLIENT) || (type & DTLS_TYPE_SERVER))) {
3848  switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(rtp_session->session), SWITCH_LOG_CRIT, "INVALID TYPE!\n");
3849  }
3850 
3851  switch_rtp_del_dtls(rtp_session, type);
3852 
3853  if ((type & DTLS_TYPE_RTP) && (type & DTLS_TYPE_RTCP)) {
3854  kind = "RTP/RTCP";
3855  } else if ((type & DTLS_TYPE_RTP)) {
3856  kind = "RTP";
3857  } else {
3858  kind = "RTCP";
3859  }
3860 
3862  "Activate %s %s DTLS %s\n", kind, rtp_type(rtp_session), (type & DTLS_TYPE_SERVER) ? "server" : "client");
3863 
3864  if (((type & DTLS_TYPE_RTP) && rtp_session->dtls) || ((type & DTLS_TYPE_RTCP) && rtp_session->rtcp_dtls)) {
3865  switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(rtp_session->session), SWITCH_LOG_WARNING, "DTLS ALREADY INIT\n");
3867  }
3868 
3869  dtls = switch_core_alloc(rtp_session->pool, sizeof(*dtls));
3870 
3872 
3873  if (switch_file_exists(dtls->pem, rtp_session->pool) == SWITCH_STATUS_SUCCESS) {
3874  dtls->pvt = dtls->rsa = dtls->pem;
3875  } else {
3878  }
3879 
3880  dtls->ca = switch_core_sprintf(rtp_session->pool, "%s%sca-bundle.crt", SWITCH_GLOBAL_dirs.certs_dir, SWITCH_PATH_SEPARATOR);
3881 
3882 #if OPENSSL_VERSION_NUMBER >= 0x10100000
3883  ssl_method = (type & DTLS_TYPE_SERVER) ? DTLS_server_method() : DTLS_client_method();
3884 #else
3885  #ifdef HAVE_OPENSSL_DTLSv1_2_method
3886  ssl_method = (type & DTLS_TYPE_SERVER) ? (want_DTLSv1_2 ? DTLSv1_2_server_method() : DTLSv1_server_method()) : (want_DTLSv1_2 ? DTLSv1_2_client_method() : DTLSv1_client_method());
3887  #else
3888  ssl_method = (type & DTLS_TYPE_SERVER) ? DTLSv1_server_method() : DTLSv1_client_method();
3889  #endif // HAVE_OPENSSL_DTLSv1_2_method
3890 #endif
3891 
3892  if (!ssl_method) {
3893  ssl_method_error = ERR_peek_error();
3894  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);
3895  }
3896 
3897  dtls->ssl_ctx = ssl_ctx = SSL_CTX_new(ssl_method);
3898 
3899  if (!ssl_ctx) {
3900  ssl_ctx_error = ERR_peek_error();
3901  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);
3904  }
3905 
3906  switch_assert(dtls->ssl_ctx);
3907 
3908 #if OPENSSL_VERSION_NUMBER < 0x30000000
3909  bio = BIO_new_file(dtls->pem, "r");
3910  dh = PEM_read_bio_DHparams(bio, NULL, NULL, NULL);
3911  BIO_free(bio);
3912  if (dh) {
3913  SSL_CTX_set_tmp_dh(dtls->ssl_ctx, dh);
3914  DH_free(dh);
3915  }
3916 #else
3917  if(!SSL_CTX_set_dh_auto(dtls->ssl_ctx, 1)) {
3918  switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(rtp_session->session), SWITCH_LOG_ERROR, "Failed enable auto DH!\n");
3919  }
3920 #endif
3921  SSL_CTX_set_mode(dtls->ssl_ctx, SSL_MODE_AUTO_RETRY);
3922 
3923  //SSL_CTX_set_verify(dtls->ssl_ctx, SSL_VERIFY_PEER | SSL_VERIFY_FAIL_IF_NO_PEER_CERT, NULL);
3924  SSL_CTX_set_verify(dtls->ssl_ctx, SSL_VERIFY_NONE, NULL);
3925 
3926  //SSL_CTX_set_cipher_list(dtls->ssl_ctx, "ECDH:!RC4:!SSLv3:RSA_WITH_AES_128_CBC_SHA");
3927  //SSL_CTX_set_cipher_list(dtls->ssl_ctx, "ECDHE-RSA-AES256-GCM-SHA384");
3928  SSL_CTX_set_cipher_list(dtls->ssl_ctx, "ALL:!ADH:!LOW:!EXP:!MD5:@STRENGTH");
3929  //SSL_CTX_set_cipher_list(dtls->ssl_ctx, "SUITEB128");
3930  SSL_CTX_set_read_ahead(dtls->ssl_ctx, 1);
3931 #ifdef HAVE_OPENSSL_DTLS_SRTP
3932  //SSL_CTX_set_tlsext_use_srtp(dtls->ssl_ctx, "SRTP_AES128_CM_SHA1_80:SRTP_AES128_CM_SHA1_32");
3933  SSL_CTX_set_tlsext_use_srtp(dtls->ssl_ctx, "SRTP_AES128_CM_SHA1_80");
3934 #endif
3935 
3936  dtls->type = type;
3937  dtls->read_bio = BIO_new(BIO_s_mem());
3938  switch_assert(dtls->read_bio);
3939 
3940  dtls->write_bio = BIO_new(BIO_s_mem());
3941  switch_assert(dtls->write_bio);
3942 
3943  BIO_set_mem_eof_return(dtls->read_bio, -1);
3944  BIO_set_mem_eof_return(dtls->write_bio, -1);
3945 
3946  if ((ret=SSL_CTX_use_certificate_file(dtls->ssl_ctx, dtls->rsa, SSL_FILETYPE_PEM)) != 1) {
3947  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));
3949  }
3950 
3951  if ((ret=SSL_CTX_use_PrivateKey_file(dtls->ssl_ctx, dtls->pvt, SSL_FILETYPE_PEM)) != 1) {
3952  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));
3954  }
3955 
3956  if (SSL_CTX_check_private_key(dtls->ssl_ctx) == 0) {
3957  switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(rtp_session->session), SWITCH_LOG_ERROR, "%s DTLS check key failed\n", rtp_type(rtp_session));
3959  }
3960 
3961  if (!zstr(dtls->ca) && switch_file_exists(dtls->ca, rtp_session->pool) == SWITCH_STATUS_SUCCESS
3962  && (ret = SSL_CTX_load_verify_locations(dtls->ssl_ctx, dtls->ca, NULL)) != 1) {
3963  switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(rtp_session->session), SWITCH_LOG_ERROR, "%s DTLS check chain cert failed [%d]\n",
3964  rtp_type(rtp_session) ,
3965  SSL_get_error(dtls->ssl, ret));
3967  }
3968 
3969  dtls->ssl = SSL_new(dtls->ssl_ctx);
3970 
3971 #if OPENSSL_VERSION_NUMBER < 0x10100000L
3972  dtls->filter_bio = BIO_new(BIO_dtls_filter());
3973 #else
3975  dtls->filter_bio = BIO_new(dtls_bio_filter_methods);
3976 #endif
3977 
3978  switch_assert(dtls->filter_bio);
3979 
3980  BIO_push(dtls->filter_bio, dtls->write_bio);
3981 
3982  SSL_set_bio(dtls->ssl, dtls->read_bio, dtls->filter_bio);
3983 
3984  SSL_set_mode(dtls->ssl, SSL_MODE_AUTO_RETRY);
3985  SSL_set_read_ahead(dtls->ssl, 1);
3986 
3987 
3988  //SSL_set_verify(dtls->ssl, (SSL_VERIFY_PEER | SSL_VERIFY_FAIL_IF_NO_PEER_CERT), cb_verify_peer);
3989 
3990 #ifndef OPENSSL_NO_EC
3991 #if OPENSSL_VERSION_NUMBER < 0x10002000L
3992  ecdh = EC_KEY_new_by_curve_name(NID_X9_62_prime256v1);
3993  if (!ecdh) {
3995  }
3996  SSL_set_options(dtls->ssl, SSL_OP_SINGLE_ECDH_USE);
3997  SSL_set_tmp_ecdh(dtls->ssl, ecdh);
3998  EC_KEY_free(ecdh);
3999 #elif OPENSSL_VERSION_NUMBER < 0x10100000L
4000  SSL_set_ecdh_auto(dtls->ssl, 1);
4001  SSL_set_options(dtls->ssl, SSL_OP_SINGLE_ECDH_USE);
4002 #endif
4003 #endif
4004 
4005  SSL_set_verify(dtls->ssl, SSL_VERIFY_NONE, NULL);
4006  SSL_set_app_data(dtls->ssl, dtls);
4007 
4008  dtls->local_fp = local_fp;
4009  dtls->remote_fp = remote_fp;
4010  dtls->rtp_session = rtp_session;
4011  dtls->mtu = 1200;
4012 
4013  if (rtp_session->session) {
4014  switch_channel_t *channel = switch_core_session_get_channel(rtp_session->session);
4015  if ((var = switch_channel_get_variable(channel, "rtp_dtls_mtu"))) {
4016  int mtu = atoi(var);
4017 
4018  if (mtu > 0 && mtu < MAX_DTLS_MTU) {
4019  dtls->mtu = mtu;
4020  }
4021 
4022  }
4023  }
4024 
4025  BIO_ctrl(dtls->filter_bio, BIO_CTRL_DGRAM_SET_MTU, dtls->mtu, NULL);
4026 
4027  switch_core_cert_expand_fingerprint(remote_fp, remote_fp->str);
4028 
4029  if ((type & DTLS_TYPE_RTP)) {
4030  rtp_session->dtls = dtls;
4031  dtls->sock_output = rtp_session->sock_output;
4032  dtls->remote_addr = rtp_session->remote_addr;
4033  }
4034 
4035  if ((type & DTLS_TYPE_RTCP)) {
4036  rtp_session->rtcp_dtls = dtls;
4037  if (!(type & DTLS_TYPE_RTP)) {
4038  dtls->sock_output = rtp_session->rtcp_sock_output;
4039  dtls->remote_addr = rtp_session->rtcp_remote_addr;
4040  }
4041  }
4042 
4043  if ((type & DTLS_TYPE_SERVER)) {
4044  SSL_set_accept_state(dtls->ssl);
4045  } else {
4046  SSL_set_connect_state(dtls->ssl);
4047  }
4048 
4050 
4051  rtp_session->flags[SWITCH_RTP_FLAG_VIDEO_BREAK] = 1;
4052  switch_rtp_break(rtp_session);
4053 
4054  done:
4055 
4056  switch_mutex_unlock(rtp_session->ice_mutex);
4057 
4058  return status;
4059 
4060 }
SSL_CTX * ssl_ctx
Definition: switch_rtp.c:277
#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:283
BIO_METHOD * BIO_dtls_filter(void)
Definition: switch_rtp.c:3475
#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:5150
BIO * write_bio
Definition: switch_rtp.c:280
switch_status_t switch_rtp_del_dtls(switch_rtp_t *rtp_session, dtls_type_t type)
Definition: switch_rtp.c:3739
switch_sockaddr_t * remote_addr
Definition: switch_rtp.c:291
switch_sockaddr_t * remote_addr
Definition: switch_rtp.c:344
BIO * filter_bio
Definition: switch_rtp.c:281
BIO * read_bio
Definition: switch_rtp.c:279
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:544
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:290
#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:396
#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:3470
struct switch_rtp * rtp_session
Definition: switch_rtp.c:296
int switch_core_cert_expand_fingerprint(dtls_fingerprint_t *fp, const char *str)
switch_dtls_t * dtls
Definition: switch_rtp.c:370
#define dtls_set_state(_dtls, _state)
Definition: switch_rtp.c:3212
#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:397
switch_socket_t * rtcp_sock_output
Definition: switch_rtp.c:326
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:5083
switch_mutex_t * ice_mutex
Definition: switch_rtp.c:433
switch_core_session_t * session
Definition: switch_rtp.c:476
switch_dtls_t * rtcp_dtls
Definition: switch_rtp.c:371
const SSL_METHOD * ssl_method
Definition: switch_msrp.c:65
dtls_type_t type
Definition: switch_rtp.c:287
dtls_fingerprint_t * local_fp
Definition: switch_rtp.c:282
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:344
switch_socket_t * sock_output
Definition: switch_rtp.c:326
#define MAX_DTLS_MTU
Definition: switch_rtp.c:273

◆ switch_rtp_break()

void switch_rtp_break ( switch_rtp_t rtp_session)

Definition at line 5083 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().

5084 {
5085  if (!switch_rtp_ready(rtp_session)) {
5086  return;
5087  }
5088 
5089  if (rtp_session->flags[SWITCH_RTP_FLAG_VIDEO]) {
5090  int ret = 1;
5091 
5092  if (rtp_session->flags[SWITCH_RTP_FLAG_VIDEO_BREAK]) {
5093  rtp_session->flags[SWITCH_RTP_FLAG_VIDEO_BREAK] = 0;
5094  ret = 0;
5095  } else if (rtp_session->session) {
5096  switch_channel_t *channel = switch_core_session_get_channel(rtp_session->session);
5097  if (switch_channel_test_flag(channel, CF_VIDEO_BREAK)) {
5099  ret = 0;
5100  }
5101  }
5102 
5103  if (ret) return;
5104 
5105  switch_rtp_video_refresh(rtp_session);
5106  }
5107 
5108  switch_mutex_lock(rtp_session->flag_mutex);
5109  rtp_session->flags[SWITCH_RTP_FLAG_BREAK] = 1;
5110 
5111  if (rtp_session->flags[SWITCH_RTP_FLAG_NOBLOCK]) {
5112  switch_mutex_unlock(rtp_session->flag_mutex);
5113  return;
5114  }
5115 
5116  if (rtp_session->sock_input) {
5117  ping_socket(rtp_session);
5118  }
5119 
5120  switch_mutex_unlock(rtp_session->flag_mutex);
5121 }
uint8_t switch_rtp_ready(switch_rtp_t *rtp_session)
Test if an RTP session is ready.
Definition: switch_rtp.c:5150
switch_mutex_t * flag_mutex
Definition: switch_rtp.c:430
switch_socket_t * sock_input
Definition: switch_rtp.c:326
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:396
switch_core_session_t * session
Definition: switch_rtp.c:476
static void ping_socket(switch_rtp_t *rtp_session)
Definition: switch_rtp.c:3047
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:5059

◆ 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 4417 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().

4418 {
4420  int change_timer = 0;
4421 
4422  if (rtp_session->ms_per_packet != ms_per_packet || rtp_session->samples_per_interval != samples_per_interval) {
4423  change_timer = 1;
4424  }
4425 
4426  switch_rtp_set_interval(rtp_session, ms_per_packet, samples_per_interval);
4427 
4428  if (change_timer && rtp_session->timer_name) {
4429  READ_INC(rtp_session);
4430  WRITE_INC(rtp_session);
4431 
4432  if (rtp_session->timer.timer_interface) {
4433  switch_core_timer_destroy(&rtp_session->timer);
4434  }
4435 
4436  if (rtp_session->write_timer.timer_interface) {
4437  switch_core_timer_destroy(&rtp_session->write_timer);
4438  }
4439 
4440  if ((status = switch_core_timer_init(&rtp_session->timer,
4441  rtp_session->timer_name, ms_per_packet / 1000,
4442  samples_per_interval, rtp_session->pool)) == SWITCH_STATUS_SUCCESS) {
4443 
4445  "RE-Starting timer [%s] %d bytes per %dms\n", rtp_session->timer_name, samples_per_interval, ms_per_packet / 1000);
4446  switch_core_timer_init(&rtp_session->write_timer, rtp_session->timer_name, (ms_per_packet / 1000), samples_per_interval, rtp_session->pool);
4447  } else {
4448 
4449  memset(&rtp_session->timer, 0, sizeof(rtp_session->timer));
4451  "Problem RE-Starting timer [%s] %d bytes per %dms\n", rtp_session->timer_name, samples_per_interval, ms_per_packet / 1000);
4452  }
4453 
4454  WRITE_DEC(rtp_session);
4455  READ_DEC(rtp_session);
4456  }
4457 
4458  return status;
4459 }
#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:403
switch_status_t switch_core_timer_destroy(switch_timer_t *timer)
Destroy an allocated timer.
switch_memory_pool_t * pool
Definition: switch_rtp.c:397
switch_status_t
Common return values.
uint32_t samples_per_interval
Definition: switch_rtp.c:409
switch_timer_t timer
Definition: switch_rtp.c:434
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:4404
switch_core_session_t * session
Definition: switch_rtp.c:476
switch_timer_t write_timer
Definition: switch_rtp.c:435
uint32_t ms_per_packet
Definition: switch_rtp.c:414
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 8049 of file switch_rtp.c.

References switch_rtp::auto_adj_used.

8050 {
8051  return rtp_session->auto_adj_used;
8052 }
switch_byte_t auto_adj_used
Definition: switch_rtp.c:467

◆ 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 5434 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().

5435 {
5436  int old_flag = rtp_session->flags[flag];
5437 
5438  switch_mutex_lock(rtp_session->flag_mutex);
5439  rtp_session->flags[flag] = 0;
5440  switch_mutex_unlock(rtp_session->flag_mutex);
5441 
5442  if (flag == SWITCH_RTP_FLAG_PASSTHRU) {
5443  if (old_flag) {
5445  }
5446  } else if (flag == SWITCH_RTP_FLAG_DTMF_ON) {
5447  rtp_session->stats.inbound.last_processed_seq = 0;
5448  } else if (flag == SWITCH_RTP_FLAG_PAUSE) {
5449  reset_jitter_seq(rtp_session);
5450  } else if (flag == SWITCH_RTP_FLAG_NOBLOCK && rtp_session->sock_input) {
5452  }
5453 }
switch_rtp_numbers_t inbound
Definition: switch_types.h:771
switch_mutex_t * flag_mutex
Definition: switch_rtp.c:430
switch_socket_t * sock_input
Definition: switch_rtp.c:326
switch_status_t switch_rtp_pause_jitter_buffer(switch_rtp_t *rtp_session, switch_bool_t pause)
Definition: switch_rtp.c:4738
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:396
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:454
#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:1650

◆ 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 5364 of file switch_rtp.c.

References switch_rtp_clear_flag(), and SWITCH_RTP_FLAG_INVALID.

Referenced by switch_core_media_receive_message().

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

◆ 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 4476 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_rand(), 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().

4481 {
4482  switch_rtp_t *rtp_session = NULL;
4484  switch_channel_t *channel = NULL;
4485 
4486  if (session) channel = switch_core_session_get_channel(session);
4487 
4488  *new_rtp_session = NULL;
4489 
4490  if (samples_per_interval > SWITCH_RTP_MAX_BUF_LEN) {
4491  *err = "Packet Size Too Large!";
4492  return SWITCH_STATUS_FALSE;
4493  }
4494 
4495  if (!(rtp_session = switch_core_alloc(pool, sizeof(*rtp_session)))) {
4496  *err = "Memory Error!";
4497  return SWITCH_STATUS_MEMERR;
4498  }
4499 
4500  rtp_session->pool = pool;
4501  rtp_session->te = INVALID_PT;
4502  rtp_session->recv_te = INVALID_PT;
4503  rtp_session->cng_pt = INVALID_PT;
4504  rtp_session->session = session;
4505 
4511  switch_queue_create(&rtp_session->dtmf_data.dtmf_queue, 100, rtp_session->pool);
4512  switch_queue_create(&rtp_session->dtmf_data.dtmf_inqueue, 100, rtp_session->pool);
4513 
4514  switch_rtp_set_flags(rtp_session, flags);
4515 
4516  /* for from address on recvfrom calls */
4517  switch_sockaddr_create(&rtp_session->from_addr, pool);
4518  switch_sockaddr_create(&rtp_session->rtp_from_addr, pool);
4519 
4520  if (rtp_session->flags[SWITCH_RTP_FLAG_ENABLE_RTCP]) {
4521  switch_sockaddr_create(&rtp_session->rtcp_from_addr, pool);
4522  }
4523 
4524  rtp_session->seq = (uint16_t) switch_rand();
4525  rtp_session->ssrc = (uint32_t) ((intptr_t) rtp_session + (switch_time_t) switch_epoch_time_now(NULL));
4526 #ifdef DEBUG_TS_ROLLOVER
4527  rtp_session->last_write_ts = TS_ROLLOVER_START;
4528 #endif
4529  rtp_session->stats.inbound.R = 100.0;
4530  rtp_session->stats.inbound.mos = 4.5;
4531  rtp_session->send_msg.header.ssrc = htonl(rtp_session->ssrc);
4532  rtp_session->send_msg.header.ts = 0;
4533  rtp_session->send_msg.header.m = 0;
4534  rtp_session->send_msg.header.pt = (switch_payload_t) htonl(payload);
4535  rtp_session->send_msg.header.version = 2;
4536  rtp_session->send_msg.header.p = 0;
4537  rtp_session->send_msg.header.x = 0;
4538  rtp_session->send_msg.header.cc = 0;
4539 
4540  rtp_session->recv_msg.header.ssrc = 0;
4541  rtp_session->recv_msg.header.ts = 0;
4542  rtp_session->recv_msg.header.seq = 0;
4543  rtp_session->recv_msg.header.m = 0;
4544  rtp_session->recv_msg.header.pt = (switch_payload_t) htonl(payload);
4545  rtp_session->recv_msg.header.version = 2;
4546  rtp_session->recv_msg.header.p = 0;
4547  rtp_session->recv_msg.header.x = 0;
4548  rtp_session->recv_msg.header.cc = 0;
4549 
4550  rtp_session->payload = payload;
4551  rtp_session->rtcp_last_sent = switch_micro_time_now();
4552 
4553  switch_rtp_set_interval(rtp_session, ms_per_packet, samples_per_interval);
4554  rtp_session->conf_samples_per_interval = samples_per_interval;
4555 
4556  if (rtp_session->flags[SWITCH_RTP_FLAG_USE_TIMER] && zstr(timer_name)) {
4557  timer_name = "soft";
4558  }
4559 
4560  if (!zstr(timer_name) && !strcasecmp(timer_name, "none")) {
4561  timer_name = NULL;
4562  }
4563 
4564  if (!zstr(timer_name)) {
4565  rtp_session->timer_name = switch_core_strdup(pool, timer_name);
4568 
4569  if (switch_core_timer_init(&rtp_session->timer, timer_name, ms_per_packet / 1000, samples_per_interval, pool) == SWITCH_STATUS_SUCCESS) {
4571  "Starting timer [%s] %d bytes per %dms\n", timer_name, samples_per_interval, ms_per_packet / 1000);
4572  switch_core_timer_init(&rtp_session->write_timer, timer_name, (ms_per_packet / 1000), samples_per_interval, pool);
4573 #ifdef DEBUG_TS_ROLLOVER
4574  rtp_session->timer.tick = TS_ROLLOVER_START / samples_per_interval;
4575 #endif
4576  } else {
4577  memset(&rtp_session->timer, 0, sizeof(rtp_session->timer));
4579  "Error Starting timer [%s] %d bytes per %dms, async RTP disabled\n", timer_name, samples_per_interval, ms_per_packet / 1000);
4581  }
4582  } else {
4583  if (rtp_session->flags[SWITCH_RTP_FLAG_VIDEO]) {
4584  if (switch_core_timer_init(&rtp_session->timer, "soft", 1, 90, pool) == SWITCH_STATUS_SUCCESS) {
4585  switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(rtp_session->session), SWITCH_LOG_DEBUG, "Starting video timer.\n");
4586  }
4587 
4588  //switch_jb_create(&rtp_session->vb, 3, 10, rtp_session->pool);
4589  //switch_jb_debug_level(rtp_session->vb, 10);
4590 
4591  } else {
4592  switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(rtp_session->session), SWITCH_LOG_DEBUG, "Not using a timer\n");
4593  }
4594 
4597  }
4598 
4599 
4600  if (channel) {
4601  switch_channel_set_private(channel, "__rtcp_audio_rtp_session", rtp_session);
4602  }
4603 
4604 
4605  /* Jitter */
4606  rtp_session->stats.inbound.last_proc_time = switch_micro_time_now() / 1000;
4607  rtp_session->stats.inbound.jitter_n = 0;
4608  rtp_session->stats.inbound.jitter_add = 0;
4609  rtp_session->stats.inbound.jitter_addsq = 0;
4610  rtp_session->stats.inbound.min_variance = 0;
4611  rtp_session->stats.inbound.max_variance = 0;
4612 
4613  /* Burst and Packet Loss */
4614  rtp_session->stats.inbound.lossrate = 0;
4615  rtp_session->stats.inbound.burstrate = 0;
4616  memset(rtp_session->stats.inbound.loss, 0, sizeof(rtp_session->stats.inbound.loss));
4617  rtp_session->stats.inbound.last_loss = 0;
4618  rtp_session->stats.inbound.last_processed_seq = -1;
4619 
4620  rtp_session->ready = 1;
4621  *new_rtp_session = rtp_session;
4622 
4623  return SWITCH_STATUS_SUCCESS;
4624 }
switch_time_t rtcp_last_sent
Definition: switch_rtp.c:412
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:719
#define SWITCH_CHANNEL_SESSION_LOG(x)
switch_rtp_numbers_t inbound
Definition: switch_types.h:771
switch_sockaddr_t * rtcp_from_addr
Definition: switch_rtp.c:398
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:432
switch_mutex_t * flag_mutex
Definition: switch_rtp.c:430
#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:426
#define zstr(x)
Definition: switch_utils.h:314
switch_payload_t cng_pt
Definition: switch_rtp.c:429
_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:241
uint8_t ready
Definition: switch_rtp.c:436
uint32_t flags[SWITCH_RTP_FLAG_INVALID]
Definition: switch_rtp.c:396
switch_mutex_t * dtmf_mutex
Definition: switch_rtp.c:242
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
int switch_rand(void)
void switch_rtp_set_flags(switch_rtp_t *rtp_session, switch_rtp_flag_t flags[SWITCH_RTP_FLAG_INVALID])
Definition: switch_rtp.c:5353
switch_sockaddr_t * rtp_from_addr
Definition: switch_rtp.c:398
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:375
char * timer_name
Definition: switch_rtp.c:403
switch_rtp_stats_t stats
Definition: switch_rtp.c:454
switch_memory_pool_t * pool
Definition: switch_rtp.c:397
void switch_rtp_clear_flag(switch_rtp_t *rtp_session, switch_rtp_flag_t flag)
Clear an RTP Flag.
Definition: switch_rtp.c:5434
void switch_rtp_set_flag(switch_rtp_t *rtp_session, switch_rtp_flag_t flag)
Set an RTP Flag.
Definition: switch_rtp.c:5375
switch_mutex_t * read_mutex
Definition: switch_rtp.c:431
srtp_hdr_t header
Definition: switch_rtp.c:112
switch_timer_t timer
Definition: switch_rtp.c:434
rtp_msg_t recv_msg
Definition: switch_rtp.c:345
uint32_t last_write_ts
Definition: switch_rtp.c:386
switch_mutex_t * ice_mutex
Definition: switch_rtp.c:433
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:4404
switch_core_session_t * session
Definition: switch_rtp.c:476
switch_timer_t write_timer
Definition: switch_rtp.c:435
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:427
switch_payload_t recv_te
Definition: switch_rtp.c:428
switch_queue_t * dtmf_queue
Definition: switch_rtp.c:225
uint32_t ssrc
Definition: switch_rtp.c:376
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:411
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:331
switch_sockaddr_t * from_addr
Definition: switch_rtp.c:398
static const switch_payload_t INVALID_PT
Definition: switch_rtp.c:81
switch_payload_t payload
Definition: switch_rtp.c:381
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 4764 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().

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

◆ switch_rtp_debug_jitter_buffer()

switch_status_t switch_rtp_debug_jitter_buffer ( switch_rtp_t rtp_session,
const char *  name 
)

Definition at line 4817 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().

4818 {
4819  int x = 0;
4820 
4821  if (!switch_rtp_ready(rtp_session)) {
4822  return SWITCH_STATUS_FALSE;
4823  }
4824 
4825  if (name) x = atoi(name);
4826  if (x < 0) x = 0;
4827 
4828  if (rtp_session->jb) {
4829  switch_jb_debug_level(rtp_session->jb, x);
4830  } else if (rtp_session->vb) {
4831  switch_jb_debug_level(rtp_session->vb, x);
4832  }
4833 
4834  return SWITCH_STATUS_SUCCESS;
4835 }
uint8_t switch_rtp_ready(switch_rtp_t *rtp_session)
Test if an RTP session is ready.
Definition: switch_rtp.c:5150
switch_jb_t * vb
Definition: switch_rtp.c:439
void switch_jb_debug_level(switch_jb_t *jb, uint8_t level)
switch_jb_t * jb
Definition: switch_rtp.c:438
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 3739 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().

3740 {
3742 
3743  if (!rtp_session) {
3744  return SWITCH_STATUS_FALSE;
3745  }
3746 
3747  switch_mutex_lock(rtp_session->ice_mutex);
3748 
3749  if (!rtp_session->dtls && !rtp_session->rtcp_dtls) {
3751  }
3752 
3753  if ((type & DTLS_TYPE_RTP)) {
3754  if (rtp_session->dtls && rtp_session->dtls == rtp_session->rtcp_dtls) {
3755  rtp_session->rtcp_dtls = NULL;
3756  }
3757 
3758  if (rtp_session->dtls) {
3759  free_dtls(&rtp_session->dtls);
3760  }
3761 
3762  if (rtp_session->jb) {
3763  switch_jb_reset(rtp_session->jb);
3764  }
3765 
3766  if (rtp_session->vb) {
3767  switch_jb_reset(rtp_session->vb);
3768  }
3769 
3770  if (rtp_session->vbw) {
3771  switch_jb_reset(rtp_session->vbw);
3772  }
3773 
3774  }
3775 
3776  if ((type & DTLS_TYPE_RTCP) && rtp_session->rtcp_dtls) {
3777  free_dtls(&rtp_session->rtcp_dtls);
3778  }
3779 
3780 
3781 #ifdef ENABLE_SRTP
3782  if (rtp_session->flags[SWITCH_RTP_FLAG_SECURE_SEND]) {
3783  int x;
3784 
3785  rtp_session->flags[SWITCH_RTP_FLAG_SECURE_SEND] = 0;
3786 
3787  for(x = 0; x < 2; x++) {
3788  if (rtp_session->send_ctx[x]) {
3789  srtp_dealloc(rtp_session->send_ctx[x]);
3790  rtp_session->send_ctx[x] = NULL;
3791  }
3792  }
3793  }
3794 
3795  if (rtp_session->flags[SWITCH_RTP_FLAG_SECURE_RECV]) {
3796  int x;
3797 
3798  rtp_session->flags[SWITCH_RTP_FLAG_SECURE_RECV] = 0;
3799 
3800  for (x = 0; x < 2; x++) {
3801  if (rtp_session->recv_ctx[x]) {
3802  srtp_dealloc(rtp_session->recv_ctx[x]);
3803  rtp_session->recv_ctx[x] = NULL;
3804  }
3805  }
3806  }
3807 #endif
3808 
3809  done:
3810 
3811  switch_mutex_unlock(rtp_session->ice_mutex);
3812 
3813  return status;
3814 }
static void free_dtls(switch_dtls_t **dtlsp)
Definition: switch_rtp.c:3347
switch_jb_t * vbw
Definition: switch_rtp.c:440
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:357
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:396
srtp_ctx_t * recv_ctx[2]
Definition: switch_rtp.c:358
switch_dtls_t * dtls
Definition: switch_rtp.c:370
switch_jb_t * vb
Definition: switch_rtp.c:439
switch_jb_t * jb
Definition: switch_rtp.c:438
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:433
void switch_jb_reset(switch_jb_t *jb)
switch_dtls_t * rtcp_dtls
Definition: switch_rtp.c:371

◆ 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 8067 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().

8068 {
8069  switch_size_t bytes = 0;
8070  switch_dtmf_t *_dtmf = NULL;
8071  void *pop;
8072 
8073  if (!switch_rtp_ready(rtp_session)) {
8074  return bytes;
8075  }
8076 
8077  switch_mutex_lock(rtp_session->dtmf_data.dtmf_mutex);
8078  if (switch_queue_trypop(rtp_session->dtmf_data.dtmf_inqueue, &pop) == SWITCH_STATUS_SUCCESS) {
8079 
8080  _dtmf = (switch_dtmf_t *)pop;
8081  *dtmf = *_dtmf;
8082  /* Only log DTMF buffer if sensitive_dtmf channel variable not set to true */
8084  switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(rtp_session->session), SWITCH_LOG_DEBUG,"RTP RECV DTMF %c:%d\n", dtmf->digit, dtmf->duration);
8085  }
8086  bytes++;
8087  free(pop);
8088  }
8090 
8091  return bytes;
8092 }
#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:5150
switch_status_t switch_queue_trypop(switch_queue_t *queue, void **data)
Definition: switch_apr.c:1264
uint32_t duration
Definition: switch_types.h:302
struct switch_rtp_rfc2833_data dtmf_data
Definition: switch_rtp.c:426
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:241
switch_status_t switch_mutex_lock(switch_mutex_t *lock)
Definition: switch_apr.c:308
switch_mutex_t * dtmf_mutex
Definition: switch_rtp.c:242
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:476
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 5189 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().

5190 {
5191  void *pop;
5192  switch_socket_t *sock;
5193 #ifdef ENABLE_SRTP
5194  int x;
5195 #endif
5196 
5197  if (!rtp_session || !*rtp_session || !(*rtp_session)->ready) {
5198  return;
5199  }
5200 
5201  if ((*rtp_session)->vb) {
5202  /* retrieve counter for ALL received NACKed packets */
5203  uint32_t nack_jb_ok = switch_jb_get_nack_success((*rtp_session)->vb);
5205  "NACK: Added to JB: [%u]\n", nack_jb_ok);
5206  }
5207 
5208  (*rtp_session)->flags[SWITCH_RTP_FLAG_SHUTDOWN] = 1;
5209 
5210  READ_INC((*rtp_session));
5211  WRITE_INC((*rtp_session));
5212 
5213  (*rtp_session)->ready = 0;
5214 
5215  WRITE_DEC((*rtp_session));
5216  READ_DEC((*rtp_session));
5217 
5218  if ((*rtp_session)->flags[SWITCH_RTP_FLAG_VAD]) {
5219  switch_rtp_disable_vad(*rtp_session);
5220  }
5221 
5222  switch_mutex_lock((*rtp_session)->flag_mutex);
5223 
5224  switch_rtp_kill_socket(*rtp_session);
5225 
5226  while (switch_queue_trypop((*rtp_session)->dtmf_data.dtmf_inqueue, &pop) == SWITCH_STATUS_SUCCESS) {
5227  switch_safe_free(pop);
5228  }
5229 
5230  while (switch_queue_trypop((*rtp_session)->dtmf_data.dtmf_queue, &pop) == SWITCH_STATUS_SUCCESS) {
5231  switch_safe_free(pop);
5232  }
5233 
5234  if ((*rtp_session)->jb) {
5235  switch_jb_destroy(&(*rtp_session)->jb);
5236  }
5237 
5238  if ((*rtp_session)->vb) {
5239  switch_jb_destroy(&(*rtp_session)->vb);
5240  }
5241 
5242  if ((*rtp_session)->vbw) {
5243  switch_jb_destroy(&(*rtp_session)->vbw);
5244  }
5245 
5246  if ((*rtp_session)->dtls && (*rtp_session)->dtls == (*rtp_session)->rtcp_dtls) {
5247  (*rtp_session)->rtcp_dtls = NULL;
5248  }
5249 
5250  if ((*rtp_session)->dtls) {
5251  free_dtls(&(*rtp_session)->dtls);
5252  }
5253 
5254  if ((*rtp_session)->rtcp_dtls) {
5255  free_dtls(&(*rtp_session)->rtcp_dtls);
5256  }
5257 
5258  if ((*rtp_session)->rtcp_sock_input == (*rtp_session)->sock_input) {
5259  (*rtp_session)->rtcp_sock_input = NULL;
5260  }
5261 
5262  if ((*rtp_session)->rtcp_sock_output == (*rtp_session)->sock_output) {
5263  (*rtp_session)->rtcp_sock_output = NULL;
5264  }
5265 
5266  sock = (*rtp_session)->sock_input;
5267  (*rtp_session)->sock_input = NULL;
5268  switch_socket_close(sock);
5269 
5270  if ((*rtp_session)->sock_output != sock) {
5271  sock = (*rtp_session)->sock_output;
5272  (*rtp_session)->sock_output = NULL;
5273  switch_socket_close(sock);
5274  }
5275 
5276  if ((sock = (*rtp_session)->rtcp_sock_input)) {
5277  (*rtp_session)->rtcp_sock_input = NULL;
5278  switch_socket_close(sock);
5279  }
5280 
5281  if ((*rtp_session)->rtcp_sock_output && (*rtp_session)->rtcp_sock_output != sock) {
5282  sock = (*rtp_session)->rtcp_sock_output;
5283  (*rtp_session)->rtcp_sock_output = NULL;
5284  switch_socket_close(sock);
5285  }
5286 
5287 #ifdef ENABLE_SRTP
5288  if ((*rtp_session)->flags[SWITCH_RTP_FLAG_SECURE_SEND]) {
5289  for(x = 0; x < 2; x++) {
5290  if ((*rtp_session)->send_ctx[x]) {
5291  srtp_dealloc((*rtp_session)->send_ctx[x]);
5292  (*rtp_session)->send_ctx[x] = NULL;
5293  }
5294  }
5295  (*rtp_session)->flags[SWITCH_RTP_FLAG_SECURE_SEND] = 0;
5296  }
5297 
5298  if ((*rtp_session)->flags[SWITCH_RTP_FLAG_SECURE_RECV]) {
5299  for (x = 0; x < 2; x++) {
5300  if ((*rtp_session)->recv_ctx[x]) {
5301  srtp_dealloc((*rtp_session)->recv_ctx[x]);
5302  (*rtp_session)->recv_ctx[x] = NULL;
5303  }
5304  }
5305  (*rtp_session)->flags[SWITCH_RTP_FLAG_SECURE_RECV] = 0;
5306  }
5307 #endif
5308 
5309  if ((*rtp_session)->timer.timer_interface) {
5310  switch_core_timer_destroy(&(*rtp_session)->timer);
5311  }
5312 
5313  if ((*rtp_session)->write_timer.timer_interface) {
5314  switch_core_timer_destroy(&(*rtp_session)->write_timer);
5315  }
5316 
5317  switch_rtp_release_port((*rtp_session)->rx_host, (*rtp_session)->rx_port);
5318  switch_mutex_unlock((*rtp_session)->flag_mutex);
5319 
5320  return;
5321 }
#define SWITCH_CHANNEL_SESSION_LOG(x)
static void free_dtls(switch_dtls_t **dtlsp)
Definition: switch_rtp.c:3347
#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:436
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:8818
#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:2613
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:5123

◆ 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 8818 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().

8819 {
8820 
8821  if (!rtp_session) {
8822  return SWITCH_STATUS_FALSE;
8823  }
8824 
8825  if (!rtp_session->flags[SWITCH_RTP_FLAG_VAD]) {
8826  return SWITCH_STATUS_GENERR;
8827  }
8830  return SWITCH_STATUS_SUCCESS;
8831 }
struct switch_rtp_vad_data vad_data
Definition: switch_rtp.c:425
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:200
uint32_t flags[SWITCH_RTP_FLAG_INVALID]
Definition: switch_rtp.c:396
void switch_rtp_clear_flag(switch_rtp_t *rtp_session, switch_rtp_flag_t flag)
Clear an RTP Flag.
Definition: switch_rtp.c:5434

◆ switch_rtp_dtls_state()

dtls_state_t switch_rtp_dtls_state ( switch_rtp_t rtp_session,
dtls_type_t  type 
)

Definition at line 3708 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().

3709 {
3710  dtls_state_t s = DS_OFF;
3711 
3712  if (!rtp_session) {
3713  return s;
3714  }
3715 
3716  switch_mutex_lock(rtp_session->ice_mutex);
3717 
3718  if (!rtp_session->dtls && !rtp_session->rtcp_dtls) {
3719  s = DS_OFF;
3720  goto done;
3721  }
3722 
3723  if ((type == DTLS_TYPE_RTP) && rtp_session->dtls) {
3724  s = rtp_session->dtls->state;
3725  goto done;
3726  }
3727 
3728  if ((type == DTLS_TYPE_RTCP) && rtp_session->rtcp_dtls) {
3729  s = rtp_session->rtcp_dtls->state;
3730  }
3731 
3732  done:
3733 
3734  switch_mutex_unlock(rtp_session->ice_mutex);
3735 
3736  return s;
3737 }
dtls_state_t state
Definition: switch_rtp.c:284
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:370
dtls_state_t
Definition: switch_core.h:166
switch_mutex_t * ice_mutex
Definition: switch_rtp.c:433
switch_dtls_t * rtcp_dtls
Definition: switch_rtp.c:371

◆ 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 8833 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().

8835 {
8836  if (!switch_rtp_ready(rtp_session)) {
8837  return SWITCH_STATUS_FALSE;
8838  }
8839 
8840  if (rtp_session->flags[SWITCH_RTP_FLAG_VAD]) {
8841  return SWITCH_STATUS_GENERR;
8842  }
8843 
8844  memset(&rtp_session->vad_data, 0, sizeof(rtp_session->vad_data));
8845 
8846  if (switch_true(switch_channel_get_variable(switch_core_session_get_channel(rtp_session->session), "fire_talk_events"))) {
8847  rtp_session->vad_data.fire_events |= VAD_FIRE_TALK;
8848  }
8849 
8850  if (switch_true(switch_channel_get_variable(switch_core_session_get_channel(rtp_session->session), "fire_not_talk_events"))) {
8851  rtp_session->vad_data.fire_events |= VAD_FIRE_NOT_TALK;
8852  }
8853 
8854 
8855  if (switch_core_codec_init(&rtp_session->vad_data.vad_codec,
8856  codec->implementation->iananame,
8857  codec->implementation->modname,
8858  NULL,
8860  codec->implementation->microseconds_per_packet / 1000,
8863  switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(rtp_session->session), SWITCH_LOG_ERROR, "Can't load codec?\n");
8864  return SWITCH_STATUS_FALSE;
8865  }
8866  switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(rtp_session->session), SWITCH_LOG_DEBUG, "Activate VAD codec %s %dms\n", codec->implementation->iananame,
8867  codec->implementation->microseconds_per_packet / 1000);
8868  rtp_session->vad_data.diff_level = 400;
8869  rtp_session->vad_data.hangunder = 15;
8870  rtp_session->vad_data.hangover = 40;
8871  rtp_session->vad_data.bg_len = 5;
8872  rtp_session->vad_data.bg_count = 5;
8873  rtp_session->vad_data.bg_level = 300;
8874  rtp_session->vad_data.read_codec = codec;
8875  rtp_session->vad_data.session = session;
8876  rtp_session->vad_data.flags = flags;
8877  rtp_session->vad_data.cng_freq = 50;
8878  rtp_session->vad_data.ts = 1;
8879  rtp_session->vad_data.start = 0;
8880  rtp_session->vad_data.next_scan = switch_epoch_time_now(NULL);
8881  rtp_session->vad_data.scan_freq = 0;
8882  if (switch_test_flag(&rtp_session->vad_data, SWITCH_VAD_FLAG_TALKING)) {
8883  rtp_session->vad_data.start_talking = switch_micro_time_now();
8884  }
8887  return SWITCH_STATUS_SUCCESS;
8888 }
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:5150
switch_core_session_t * session
struct switch_rtp_vad_data vad_data
Definition: switch_rtp.c:425
switch_vad_flag_t flags
Definition: switch_rtp.c:212
switch_codec_t vad_codec
Definition: switch_rtp.c:200
switch_core_session_t * session
Definition: switch_rtp.c:199
_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:396
#define switch_channel_get_variable(_c, _v)
switch_time_t start_talking
Definition: switch_rtp.c:218
#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:397
void switch_rtp_set_flag(switch_rtp_t *rtp_session, switch_rtp_flag_t flag)
Set an RTP Flag.
Definition: switch_rtp.c:5375
switch_core_session_t * session
Definition: switch_rtp.c:476
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:201

◆ switch_rtp_flush()

void switch_rtp_flush ( switch_rtp_t rtp_session)

Definition at line 5028 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().

5029 {
5030  if (!switch_rtp_ready(rtp_session)) {
5031  return;
5032  }
5033 
5035 }
uint8_t switch_rtp_ready(switch_rtp_t *rtp_session)
Test if an RTP session is ready.
Definition: switch_rtp.c:5150
void switch_rtp_set_flag(switch_rtp_t *rtp_session, switch_rtp_flag_t flag)
Set an RTP Flag.
Definition: switch_rtp.c:5375

◆ switch_rtp_get_core_session()

switch_core_session_t* switch_rtp_get_core_session ( switch_rtp_t rtp_session)

Definition at line 9241 of file switch_rtp.c.

References switch_rtp::session.

9242 {
9243  return rtp_session->session;
9244 }
switch_core_session_t * session
Definition: switch_rtp.c:476

◆ 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 5343 of file switch_rtp.c.

References switch_rtp::payload.

5344 {
5345  return rtp_session->payload;
5346 }
switch_payload_t payload
Definition: switch_rtp.c:381

◆ 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 5333 of file switch_rtp.c.

References switch_rtp::samples_per_interval.

5334 {
5335  return rtp_session->samples_per_interval;
5336 }
uint32_t samples_per_interval
Definition: switch_rtp.c:409

◆ switch_rtp_get_jitter_buffer()

switch_jb_t* switch_rtp_get_jitter_buffer ( switch_rtp_t rtp_session)

Definition at line 4729 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().

4730 {
4731  if (!switch_rtp_ready(rtp_session)) {
4732  return NULL;
4733  }
4734 
4735  return rtp_session->jb ? rtp_session->jb : rtp_session->vb;
4736 }
uint8_t switch_rtp_ready(switch_rtp_t *rtp_session)
Test if an RTP session is ready.
Definition: switch_rtp.c:5150
switch_jb_t * vb
Definition: switch_rtp.c:439
switch_jb_t * jb
Definition: switch_rtp.c:438

◆ switch_rtp_get_media_timer()

switch_timer_t* switch_rtp_get_media_timer ( switch_rtp_t rtp_session)

Definition at line 4715 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().

4716 {
4717 
4718  if (rtp_session && rtp_session->timer.timer_interface) {
4719  if (rtp_session->flags[SWITCH_RTP_FLAG_VIDEO]) {
4720  switch_core_timer_sync(&rtp_session->timer);
4721  }
4722  return &rtp_session->timer;
4723  }
4724 
4725  return NULL;
4726 }
switch_timer_interface_t * timer_interface
uint32_t flags[SWITCH_RTP_FLAG_INVALID]
Definition: switch_rtp.c:396
switch_timer_t timer
Definition: switch_rtp.c:434
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 9236 of file switch_rtp.c.

References switch_rtp::private_data.

9237 {
9238  return rtp_session->private_data;
9239 }
void * private_data
Definition: switch_rtp.c:383

◆ switch_rtp_get_random()

void switch_rtp_get_random ( void *  buf,
uint32_t  len 
)

Definition at line 2545 of file switch_rtp.c.

References switch_stun_random_string().

Referenced by switch_core_media_build_crypto().

2546 {
2547 #ifdef HAVE_OPENSSL
2548  RAND_bytes(buf, len);
2549 #else
2550  switch_stun_random_string(buf, len, NULL);
2551 #endif
2552 }
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 3037 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().

3038 {
3039  return zstr(rtp_session->remote_host_str) ? "0.0.0.0" : rtp_session->remote_host_str;
3040 }
char * remote_host_str
Definition: switch_rtp.c:405
#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 5328 of file switch_rtp.c.

References switch_rtp::sock_input.

5329 {
5330  return rtp_session->sock_input;
5331 }
switch_socket_t * sock_input
Definition: switch_rtp.c:326

◆ 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 9226 of file switch_rtp.c.

References switch_rtp::ssrc.

Referenced by switch_core_media_activate_rtp().

9227 {
9228  return rtp_session->ssrc;
9229 }
uint32_t ssrc
Definition: switch_rtp.c:376

◆ 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 9083 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().

9084 {
9085  switch_rtp_stats_t *s;
9086 
9087  if (!rtp_session) {
9088  return NULL;
9089  }
9090 
9091  switch_mutex_lock(rtp_session->flag_mutex);
9092  if (pool) {
9093  s = switch_core_alloc(pool, sizeof(*s));
9094  *s = rtp_session->stats;
9095  } else {
9096  s = &rtp_session->stats;
9097  }
9098 
9099  if (rtp_session->jb) {
9100  switch_jb_get_frames(rtp_session->jb, NULL, NULL, NULL, (uint32_t *)&s->inbound.largest_jb_size);
9101  }
9102 
9103  do_mos(rtp_session);
9104 
9105  switch_mutex_unlock(rtp_session->flag_mutex);
9106 
9107  return s;
9108 }
switch_rtp_numbers_t inbound
Definition: switch_types.h:771
switch_mutex_t * flag_mutex
Definition: switch_rtp.c:430
switch_size_t largest_jb_size
Definition: switch_types.h:703
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:454
switch_jb_t * jb
Definition: switch_rtp.c:438
static void do_mos(switch_rtp_t *rtp_session)
Definition: switch_rtp.c:1575

◆ 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 4776 of file switch_rtp.c.

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

Referenced by check_jb_sync().

4777 {
4778 
4779  if (rtp_session->vb) {
4780  return switch_jb_get_frames(rtp_session->vb, min_frame_len, max_frame_len, cur_frame_len, highest_frame_len);
4781  }
4782 
4783  return SWITCH_STATUS_FALSE;
4784 }
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:439

◆ switch_rtp_has_dtls()

int switch_rtp_has_dtls ( void  )

Definition at line 3700 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().

3700  {
3701 #ifdef HAVE_OPENSSL_DTLS_SRTP
3702  return 1;
3703 #else
3704  return 0;
3705 #endif
3706 }

◆ 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 8054 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().

8055 {
8056  switch_size_t has = 0;
8057 
8058  if (switch_rtp_ready(rtp_session)) {
8059  switch_mutex_lock(rtp_session->dtmf_data.dtmf_mutex);
8060  has = switch_queue_size(rtp_session->dtmf_data.dtmf_inqueue);
8062  }
8063 
8064  return has;
8065 }
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:5150
struct switch_rtp_rfc2833_data dtmf_data
Definition: switch_rtp.c:426
switch_status_t switch_mutex_unlock(switch_mutex_t *lock)
Definition: switch_apr.c:313
switch_queue_t * dtmf_inqueue
Definition: switch_rtp.c:241
switch_status_t switch_mutex_lock(switch_mutex_t *lock)
Definition: switch_apr.c:308
switch_mutex_t * dtmf_mutex
Definition: switch_rtp.c:242
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 1526 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().

1527 {
1528  if (global_init) {
1529  return;
1530  }
1532 #ifdef ENABLE_SRTP
1533  {
1534  srtp_err_status_t stat = srtp_init();
1535  if (stat == srtp_err_status_ok) {
1536  switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "SRTP (%s) initialized.\n", srtp_get_version_string());
1537  } else {
1538  switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Error initializing SRTP (%d).\n", stat);
1539  }
1540  }
1541 #endif
1544  global_init = 1;
1545 }
#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:818
#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:3677
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 2665 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().

2666 {
2667  rtp_session->rtp_bugs = bugs;
2668 
2669  if ((rtp_session->rtp_bugs & RTP_BUG_START_SEQ_AT_ZERO)) {
2670  rtp_session->seq = 0;
2671  }
2672 
2673 }
uint16_t seq
Definition: switch_rtp.c:375
switch_rtp_bug_flag_t rtp_bugs
Definition: switch_rtp.c:453

◆ 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 5123 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().

5124 {
5125  switch_assert(rtp_session != NULL);
5126  switch_mutex_lock(rtp_session->flag_mutex);
5127  if (rtp_session->flags[SWITCH_RTP_FLAG_IO]) {
5128  rtp_session->flags[SWITCH_RTP_FLAG_IO] = 0;
5129  if (rtp_session->sock_input) {
5130  ping_socket(rtp_session);
5132  }
5133  if (rtp_session->sock_output && rtp_session->sock_output != rtp_session->sock_input) {
5135  }
5136 
5137  if (rtp_session->flags[SWITCH_RTP_FLAG_ENABLE_RTCP]) {
5138  if (rtp_session->sock_input && rtp_session->rtcp_sock_input && rtp_session->rtcp_sock_input != rtp_session->sock_input) {
5139  ping_socket(rtp_session);
5141  }
5142  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) {
5144  }
5145  }
5146  }
5147  switch_mutex_unlock(rtp_session->flag_mutex);
5148 }
switch_mutex_t * flag_mutex
Definition: switch_rtp.c:430
switch_socket_t * sock_input
Definition: switch_rtp.c:326
switch_socket_t * rtcp_sock_input
Definition: switch_rtp.c:326
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:396
switch_socket_t * rtcp_sock_output
Definition: switch_rtp.c:326
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:3047
#define switch_assert(expr)
switch_socket_t * sock_output
Definition: switch_rtp.c:326

◆ 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 4626 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().

4636 {
4637  switch_rtp_t *rtp_session = NULL;
4638 
4639  if (zstr(rx_host)) {
4640  *err = "Missing local host";
4641  goto end;
4642  }
4643 
4644  if (!rx_port) {
4645  *err = "Missing local port";
4646  goto end;
4647  }
4648 
4649  if (zstr(tx_host)) {
4650  *err = "Missing remote host";
4651  goto end;
4652  }
4653 
4654  if (!tx_port) {
4655  *err = "Missing remote port";
4656  goto end;
4657  }
4658 
4659  if (switch_rtp_create(&rtp_session, payload, samples_per_interval, ms_per_packet, flags, timer_name, err, pool) != SWITCH_STATUS_SUCCESS) {
4660  goto end;
4661  }
4662 
4663  switch_mutex_lock(rtp_session->flag_mutex);
4664 
4665  if (switch_rtp_set_local_address(rtp_session, rx_host, rx_port, err) != SWITCH_STATUS_SUCCESS) {
4666  switch_mutex_unlock(rtp_session->flag_mutex);
4667  rtp_session = NULL;
4668  goto end;
4669  }
4670 
4671  if (switch_rtp_set_remote_address(rtp_session, tx_host, tx_port, 0, SWITCH_TRUE, err) != SWITCH_STATUS_SUCCESS) {
4672  switch_mutex_unlock(rtp_session->flag_mutex);
4673  rtp_session = NULL;
4674  goto end;
4675  }
4676 
4677  end:
4678 
4679  if (rtp_session) {
4680  switch_mutex_unlock(rtp_session->flag_mutex);
4681  rtp_session->ready = 2;
4682  rtp_session->rx_host = switch_core_strdup(rtp_session->pool, rx_host);
4683  rtp_session->rx_port = rx_port;
4686  } else {
4687  switch_rtp_release_port(rx_host, rx_port);
4688  }
4689 
4690  return rtp_session;
4691 }
switch_port_t rx_port
Definition: switch_rtp.c:400
switch_mutex_t * flag_mutex
Definition: switch_rtp.c:430
#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:436
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:3128
switch_memory_pool_t * pool
Definition: switch_rtp.c:397
void switch_rtp_set_flag(switch_rtp_t *rtp_session, switch_rtp_flag_t flag)
Set an RTP Flag.
Definition: switch_rtp.c:5375
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:4476
char * rx_host
Definition: switch_rtp.c:399
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:2783
void switch_rtp_release_port(const char *ip, switch_port_t port)
Definition: switch_rtp.c:2613

◆ 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 4738 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().

4739 {
4740  int new_val;
4741 
4742  if (rtp_session->pause_jb && !pause) {
4743  if (rtp_session->jb) {
4744  switch_jb_reset(rtp_session->jb);
4745  }
4746 
4747  if (rtp_session->vb) {
4748  switch_jb_reset(rtp_session->vb);
4749  }
4750  }
4751 
4752  new_val = pause ? 1 : -1;
4753 
4754  if (rtp_session->pause_jb + new_val > -1) {
4755  rtp_session->pause_jb += new_val;
4756  }
4757 
4759  "Jitterbuffer %s is %s\n", rtp_type(rtp_session), rtp_session->pause_jb ? "paused" : "enabled");
4760 
4761  return SWITCH_STATUS_SUCCESS;
4762 }
#define SWITCH_CHANNEL_SESSION_LOG(x)
#define rtp_type(rtp_session)
Definition: switch_rtp.c:544
switch_jb_t * vb
Definition: switch_rtp.c:439
switch_jb_t * jb
Definition: switch_rtp.c:438
switch_core_session_t * session
Definition: switch_rtp.c:476
void switch_jb_reset(switch_jb_t *jb)
uint8_t pause_jb
Definition: switch_rtp.c:469
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 2540 of file switch_rtp.c.

References check_rtcp_and_ice().

2541 {
2542  check_rtcp_and_ice(rtp_session);
2543 }
static int check_rtcp_and_ice(switch_rtp_t *rtp_session)
Definition: switch_rtp.c:2137

◆ 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 8094 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().

8095 {
8096 
8097  switch_dtmf_t *rdigit;
8098 
8099  if (!switch_rtp_ready(rtp_session)) {
8100  return SWITCH_STATUS_FALSE;
8101  }
8102 
8103  if ((rdigit = malloc(sizeof(*rdigit))) != 0) {
8104  *rdigit = *dtmf;
8105  if (rdigit->duration < switch_core_min_dtmf_duration(0)) {
8107  }
8108 
8109  if ((switch_queue_trypush(rtp_session->dtmf_data.dtmf_queue, rdigit)) != SWITCH_STATUS_SUCCESS) {
8110  free(rdigit);
8111  return SWITCH_STATUS_FALSE;
8112  }
8113  } else {
8114  abort();
8115  }
8116 
8117  return SWITCH_STATUS_SUCCESS;
8118 }
uint8_t switch_rtp_ready(switch_rtp_t *rtp_session)
Test if an RTP session is ready.
Definition: switch_rtp.c:5150
uint32_t duration
Definition: switch_types.h:302
struct switch_rtp_rfc2833_data dtmf_data
Definition: switch_rtp.c:426
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:225

◆ 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 8120 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().

8121 {
8122  switch_dtmf_t *rdigit;
8123 
8124  if (!switch_rtp_ready(rtp_session)) {
8125  return SWITCH_STATUS_FALSE;
8126  }
8127 
8128  if ((rdigit = malloc(sizeof(*rdigit))) != 0) {
8129  *rdigit = *dtmf;
8130  if (rdigit->duration < switch_core_min_dtmf_duration(0)) {
8132  }
8133 
8134  if ((switch_queue_trypush(rtp_session->dtmf_data.dtmf_inqueue, rdigit)) != SWITCH_STATUS_SUCCESS) {
8135  free(rdigit);
8136  return SWITCH_STATUS_FALSE;
8137  }
8138  } else {
8139  abort();
8140  }
8141 
8142  return SWITCH_STATUS_SUCCESS;
8143 }
uint8_t switch_rtp_ready(switch_rtp_t *rtp_session)
Test if an RTP session is ready.
Definition: switch_rtp.c:5150
uint32_t duration
Definition: switch_types.h:302
struct switch_rtp_rfc2833_data dtmf_data
Definition: switch_rtp.c:426
uint32_t switch_core_min_dtmf_duration(uint32_t duration)
Definition: switch_core.c:1744
switch_queue_t * dtmf_inqueue
Definition: switch_rtp.c:241
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 8145 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.

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

5151 {
5152  uint8_t ret;
5153 
5154  if (!rtp_session || !rtp_session->flag_mutex || rtp_session->flags[SWITCH_RTP_FLAG_SHUTDOWN]) {
5155  return 0;
5156  }
5157 
5158  switch_mutex_lock(rtp_session->flag_mutex);
5159  ret = (rtp_session->flags[SWITCH_RTP_FLAG_IO] && rtp_session->sock_input && rtp_session->sock_output && rtp_session->remote_addr
5160  && rtp_session->ready == 2) ? 1 : 0;
5161  switch_mutex_unlock(rtp_session->flag_mutex);
5162 
5163  return ret;
5164 }
switch_sockaddr_t * remote_addr
Definition: switch_rtp.c:344
switch_mutex_t * flag_mutex
Definition: switch_rtp.c:430
switch_socket_t * sock_input
Definition: switch_rtp.c:326
switch_status_t switch_mutex_unlock(switch_mutex_t *lock)
Definition: switch_apr.c:313
uint8_t ready
Definition: switch_rtp.c:436
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:396
switch_socket_t * sock_output
Definition: switch_rtp.c:326

◆ switch_rtp_release_port()

void switch_rtp_release_port ( const char *  ip,
switch_port_t  port 
)

Definition at line 2613 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().

2614 {
2615  switch_core_port_allocator_t *alloc = NULL;
2616 
2617  if (!ip || !port) {
2618  return;
2619  }
2620 
2622  if ((alloc = switch_core_hash_find(alloc_hash, ip))) {
2624  }
2626 
2627 }
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 5037 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().

5038 {
5039  if (!rtp_write_ready(rtp_session, 0, __LINE__) || rtp_session->tmmbr) {
5040  return SWITCH_STATUS_FALSE;
5041  }
5042 
5043  rtp_session->tmmbr = bps;
5044 
5045  return SWITCH_STATUS_SUCCESS;
5046 }
static int rtp_write_ready(switch_rtp_t *rtp_session, uint32_t bytes, int line)
Definition: switch_rtp.c:8273
uint32_t tmmbr
Definition: switch_rtp.c:340

◆ 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 2629 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().

2630 {
2631  switch_port_t port = 0;
2632  switch_core_port_allocator_t *alloc = NULL;
2633 
2636  if (!alloc) {
2638  abort();
2639  }
2640 
2642  }
2643 
2645  port = 0;
2646  }
2647 
2649  return port;
2650 }
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 3003 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().

3004 {
3005  if (!rtp_session) {
3006  return;
3007  }
3008 
3009  //rtp_session->seq = (uint16_t) rand();
3010  //rtp_session->ts = 0;
3011  memset(&rtp_session->ts_norm, 0, sizeof(rtp_session->ts_norm));
3012 
3013  rtp_session->last_stun = rtp_session->first_stun = 0;
3014  rtp_session->rtcp_sent_packets = 0;
3015  rtp_session->rtcp_last_sent = 0;
3016  rtp_session->last_adj = 0;
3017 
3018  //switch_rtp_del_dtls(rtp_session, DTLS_TYPE_RTP|DTLS_TYPE_RTCP);
3021  rtcp_stats_init(rtp_session);
3022 
3023  if (rtp_session->ice.ready) {
3024  switch_rtp_reset_vb(rtp_session);
3025  rtp_session->ice.ready = rtp_session->ice.rready = 0;
3026  rtp_session->ice.cand_responsive = 0;
3027  }
3028 
3029 }
switch_time_t rtcp_last_sent
Definition: switch_rtp.c:412
void switch_rtp_reset_vb(switch_rtp_t *rtp_session)
Definition: switch_rtp.c:2991
static void rtcp_stats_init(switch_rtp_t *rtp_session)
Definition: switch_rtp.c:1905
uint8_t cand_responsive
Definition: switch_rtp.c:265
switch_time_t last_adj
Definition: switch_rtp.c:481
void switch_rtp_set_flag(switch_rtp_t *rtp_session, switch_rtp_flag_t flag)
Set an RTP Flag.
Definition: switch_rtp.c:5375
switch_rtp_ice_t ice
Definition: switch_rtp.c:401
switch_time_t last_stun
Definition: switch_rtp.c:408
switch_time_t first_stun
Definition: switch_rtp.c:407
memset(buf, 0, buflen)
int rtcp_sent_packets
Definition: switch_rtp.c:463
ts_normalize_t ts_norm
Definition: switch_rtp.c:343

◆ switch_rtp_reset_jb()

void switch_rtp_reset_jb ( switch_rtp_t rtp_session)

Definition at line 2982 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().

2983 {
2984  if (switch_rtp_ready(rtp_session)) {
2985  if (rtp_session->jb) {
2986  switch_jb_reset(rtp_session->jb);
2987  }
2988  }
2989 }
uint8_t switch_rtp_ready(switch_rtp_t *rtp_session)
Test if an RTP session is ready.
Definition: switch_rtp.c:5150
switch_jb_t * jb
Definition: switch_rtp.c:438
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 3031 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().

3032 {
3033  rtp_session->missed_count = 0;
3034  rtp_session->last_media = switch_micro_time_now();
3035 }
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:443
uint32_t missed_count
Definition: switch_rtp.c:442

◆ 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 4709 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().

4710 {
4711  rtp_session->cng_pt = pt;
4712  rtp_session->flags[SWITCH_RTP_FLAG_AUTO_CNG] = 1;
4713 }
switch_payload_t cng_pt
Definition: switch_rtp.c:429
uint32_t flags[SWITCH_RTP_FLAG_INVALID]
Definition: switch_rtp.c:396

◆ 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 5338 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().

5339 {
5340  rtp_session->payload = payload;
5341 }
switch_payload_t payload
Definition: switch_rtp.c:381

◆ 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 2599 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().

2600 {
2601  if (port) {
2602  if (port_lock) {
2604  }
2605  END_PORT = port;
2606  if (port_lock) {
2608  }
2609  }
2610  return END_PORT;
2611 }
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 5375 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().

5376 {
5377  int old_flag = rtp_session->flags[flag];
5378 
5379  switch_mutex_lock(rtp_session->flag_mutex);
5380  rtp_session->flags[flag] = 1;
5381  switch_mutex_unlock(rtp_session->flag_mutex);
5382 
5383  if (flag == SWITCH_RTP_FLAG_PASSTHRU) {
5384  if (!old_flag) {
5386  }
5387  } else if (flag == SWITCH_RTP_FLAG_DTMF_ON) {
5388  rtp_session->stats.inbound.last_processed_seq = 0;
5389  } else if (flag == SWITCH_RTP_FLAG_FLUSH) {
5390  reset_jitter_seq(rtp_session);
5391  } else if (flag == SWITCH_RTP_FLAG_AUTOADJ) {
5392  rtp_session->autoadj_window = 20;
5393  rtp_session->autoadj_threshold = 10;
5394  rtp_session->autoadj_tally = 0;
5395 
5396  switch_mutex_lock(rtp_session->flag_mutex);
5397  rtp_session->flags[SWITCH_RTP_FLAG_RTCP_AUTOADJ] = 1;
5398  switch_mutex_unlock(rtp_session->flag_mutex);
5399 
5400  rtp_session->rtcp_autoadj_window = 20;
5401  rtp_session->rtcp_autoadj_threshold = 1;
5402  rtp_session->rtcp_autoadj_tally = 0;
5403 
5404  if (rtp_session->session) {
5405  switch_channel_t *channel = switch_core_session_get_channel(rtp_session->session);
5406  const char *x = switch_channel_get_variable(channel, "rtp_auto_adjust_threshold");
5407  if (x && *x) {
5408  int xn = atoi(x);
5409  if (xn > 0 && xn <= 65535) {
5410  rtp_session->autoadj_window = xn*2;
5411  rtp_session->autoadj_threshold = xn;
5412  }
5413  }
5414  }
5415 
5416 
5418 
5419 
5420  if (rtp_session->jb) {
5421  switch_jb_reset(rtp_session->jb);
5422  }
5423  } else if (flag == SWITCH_RTP_FLAG_NOBLOCK && rtp_session->sock_input) {
5425  }
5426 
5427 }
switch_rtp_numbers_t inbound
Definition: switch_types.h:771
uint32_t rtcp_autoadj_tally
Definition: switch_rtp.c:355
switch_mutex_t * flag_mutex
Definition: switch_rtp.c:430
switch_socket_t * sock_input
Definition: switch_rtp.c:326
switch_status_t switch_rtp_pause_jitter_buffer(switch_rtp_t *rtp_session, switch_bool_t pause)
Definition: switch_rtp.c:4738
uint32_t rtcp_autoadj_threshold
Definition: switch_rtp.c:354
void rtp_flush_read_buffer(switch_rtp_t *rtp_session, switch_rtp_flush_t flush)
Definition: switch_rtp.c:5638
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: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:396
#define switch_channel_get_variable(_c, _v)
uint32_t autoadj_threshold
Definition: switch_rtp.c:350
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:349
switch_rtp_stats_t stats
Definition: switch_rtp.c:454
switch_jb_t * jb
Definition: switch_rtp.c:438
#define SWITCH_SO_NONBLOCK
Definition: switch_apr.h:994
static void reset_jitter_seq(switch_rtp_t *rtp_session)
Definition: switch_rtp.c:1650
switch_core_session_t * session
Definition: switch_rtp.c:476
void switch_jb_reset(switch_jb_t *jb)
#define TRUE
uint32_t autoadj_tally
Definition: switch_rtp.c:351

◆ 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 5353 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().

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

◆ switch_rtp_set_interdigit_delay()

void switch_rtp_set_interdigit_delay ( switch_rtp_t rtp_session,
uint32_t  delay 
)

Definition at line 5323 of file switch_rtp.c.

References switch_rtp::interdigit_delay.

Referenced by switch_core_media_activate_rtp().

5324 {
5325  rtp_session->interdigit_delay = delay;
5326 }
uint32_t interdigit_delay
Definition: switch_rtp.c:475

◆ 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 4404 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().

4405 {
4406  rtp_session->ms_per_packet = ms_per_packet;
4407  rtp_session->samples_per_interval = rtp_session->conf_samples_per_interval = samples_per_interval;
4408  rtp_session->missed_count = 0;
4409  rtp_session->samples_per_second =
4410  (uint32_t) ((double) (1000.0f / (double) (rtp_session->ms_per_packet / 1000)) * (double) rtp_session->samples_per_interval);
4411 
4412  rtp_session->one_second = (rtp_session->samples_per_second / rtp_session->samples_per_interval);
4413 
4414  return SWITCH_STATUS_SUCCESS;
4415 }
uint32_t samples_per_second
Definition: switch_rtp.c:410
uint32_t missed_count
Definition: switch_rtp.c:442
uint32_t samples_per_interval
Definition: switch_rtp.c:409
uint32_t ms_per_packet
Definition: switch_rtp.c:414
uint32_t conf_samples_per_interval
Definition: switch_rtp.c:411
uint32_t one_second
Definition: switch_rtp.c:415

◆ 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 5348 of file switch_rtp.c.

References switch_rtp::invalid_handler.

5349 {
5350  rtp_session->invalid_handler = on_invalid;
5351 }
switch_rtp_invalid_handler_t invalid_handler
Definition: switch_rtp.c:382

◆ 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 2783 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().

2784 {
2785  switch_socket_t *new_sock = NULL, *old_sock = NULL;
2787  int j = 0;
2788 #ifndef WIN32
2789  char o[5] = "TEST", i[5] = "";
2790  switch_size_t len, ilen = 0;
2791  int x;
2792 #endif
2793 
2794  if (rtp_session->ready != 1) {
2795  if (!switch_rtp_ready(rtp_session)) {
2796  return SWITCH_STATUS_FALSE;
2797  }
2798 
2799  READ_INC(rtp_session);
2800  WRITE_INC(rtp_session);
2801 
2802  if (!switch_rtp_ready(rtp_session)) {
2803  goto done;
2804  }
2805  }
2806 
2807 
2808  *err = NULL;
2809 
2810  if (zstr(host) || !port) {
2811  *err = "Address Error";
2812  goto done;
2813  }
2814 
2815 
2816  rtp_session->local_host_str = switch_core_strdup(rtp_session->pool, host);
2817  rtp_session->local_port = port;
2818 
2819 
2820  if (switch_sockaddr_info_get(&rtp_session->local_addr, host, SWITCH_UNSPEC, port, 0, rtp_session->pool) != SWITCH_STATUS_SUCCESS) {
2821  *err = "Local Address Error!";
2822  goto done;
2823  }
2824 
2825 
2826  if (rtp_session->sock_input) {
2827  switch_rtp_kill_socket(rtp_session);
2828  }
2829 
2830  if (switch_socket_create(&new_sock, switch_sockaddr_get_family(rtp_session->local_addr), SOCK_DGRAM, 0, rtp_session->pool) != SWITCH_STATUS_SUCCESS) {
2831  *err = "Socket Error!";
2832  goto done;
2833  }
2834 
2836  *err = "Socket Error!";
2837  goto done;
2838  }
2839 
2840  if (rtp_session->flags[SWITCH_RTP_FLAG_VIDEO]) {
2841  switch_socket_opt_set(new_sock, SWITCH_SO_RCVBUF, 1572864);
2842  switch_socket_opt_set(new_sock, SWITCH_SO_SNDBUF, 1572864);
2843  } else {
2844  switch_socket_opt_set(new_sock, SWITCH_SO_RCVBUF, 851968);
2845  switch_socket_opt_set(new_sock, SWITCH_SO_SNDBUF, 851968);
2846  }
2847 
2848  if (switch_socket_bind(new_sock, rtp_session->local_addr) != SWITCH_STATUS_SUCCESS) {
2849  char *em = switch_core_sprintf(rtp_session->pool, "Bind Error! %s:%d", host, port);
2850  *err = em;
2851  goto done;
2852  }
2853 
2854 
2855  if ((j = atoi(host)) && j > 223 && j < 240) { /* mcast */
2856  if (switch_mcast_interface(new_sock, rtp_session->local_addr) != SWITCH_STATUS_SUCCESS) {
2857  *err = "Multicast Socket interface Error";
2858  goto done;
2859  }
2860 
2861  if (switch_mcast_join(new_sock, rtp_session->local_addr, NULL, NULL) != SWITCH_STATUS_SUCCESS) {
2862  *err = "Multicast Error";
2863  goto done;
2864  }
2865 
2866  if (rtp_session->session) {
2867  switch_channel_t *channel = switch_core_session_get_channel(rtp_session->session);
2868  const char *var;
2869 
2870  if ((var = switch_channel_get_variable(channel, "multicast_ttl"))) {
2871  int ttl = atoi(var);
2872 
2873  if (ttl > 0 && ttl < 256) {
2874  if (switch_mcast_hops(new_sock, (uint8_t) ttl) != SWITCH_STATUS_SUCCESS) {
2875  *err = "Mutlicast TTL set failed";
2876  goto done;
2877  }
2878 
2879  }
2880  }
2881 
2882  }
2883 
2884  }
2885 
2886 
2887 
2888 #ifndef WIN32
2889  len = sizeof(i);
2891 
2892  switch_socket_sendto(new_sock, rtp_session->local_addr, 0, (void *) o, &len);
2893 
2894  x = 0;
2895  while (!ilen) {
2896  switch_status_t status;
2897  ilen = len;
2898  status = switch_socket_recvfrom(rtp_session->from_addr, new_sock, 0, (void *) i, &ilen);
2899 
2900  if (status != SWITCH_STATUS_SUCCESS && status != SWITCH_STATUS_BREAK) {
2901  break;
2902  }
2903 
2904  if (++x > 1000) {
2905  break;
2906  }
2907  switch_cond_next();
2908  }
2910 
2911 #endif
2912 
2913  old_sock = rtp_session->sock_input;
2914  rtp_session->sock_input = new_sock;
2915  new_sock = NULL;
2916 
2917  if (rtp_session->flags[SWITCH_RTP_FLAG_USE_TIMER] || rtp_session->flags[SWITCH_RTP_FLAG_NOBLOCK] || rtp_session->flags[SWITCH_RTP_FLAG_VIDEO]) {
2920  }
2921 
2922  switch_socket_create_pollset(&rtp_session->read_pollfd, rtp_session->sock_input, SWITCH_POLLIN | SWITCH_POLLERR, rtp_session->pool);
2923 
2924  if (rtp_session->flags[SWITCH_RTP_FLAG_ENABLE_RTCP]) {
2925  if ((status = enable_local_rtcp_socket(rtp_session, err)) == SWITCH_STATUS_SUCCESS) {
2926  *err = "Success";
2927  }
2928  } else {
2929  status = SWITCH_STATUS_SUCCESS;
2930  *err = "Success";
2931  }
2932 
2934 
2935  done:
2936 
2937  if (new_sock) {
2938  switch_socket_close(new_sock);
2939  }
2940 
2941  if (old_sock) {
2942  switch_socket_close(old_sock);
2943  }
2944 
2945 
2946  if (rtp_session->ready != 1) {
2947  WRITE_DEC(rtp_session);
2948  READ_DEC(rtp_session);
2949  }
2950 
2951  return status;
2952 }
switch_pollfd_t * read_pollfd
Definition: switch_rtp.c:327
uint8_t switch_rtp_ready(switch_rtp_t *rtp_session)
Test if an RTP session is ready.
Definition: switch_rtp.c:5150
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:326
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:436
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:396
#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:404
#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:330
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:397
void switch_rtp_set_flag(switch_rtp_t *rtp_session, switch_rtp_flag_t flag)
Set an RTP Flag.
Definition: switch_rtp.c:5375
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:476
#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:420
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:5123
switch_sockaddr_t * from_addr
Definition: switch_rtp.c:398
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:2720

◆ switch_rtp_set_max_missed_packets()

void switch_rtp_set_max_missed_packets ( switch_rtp_t rtp_session,
uint32_t  max 
)

Definition at line 2966 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().

2967 {
2968  if (!switch_rtp_ready(rtp_session) || rtp_session->flags[SWITCH_RTP_FLAG_UDPTL]) {
2969  return;
2970  }
2971 
2972  if (rtp_session->missed_count > max) {
2973 
2975  "new max missed packets(%d->%d) greater than current missed packets(%d). RTP will timeout.\n",
2976  rtp_session->max_missed_packets, max, rtp_session->missed_count);
2977  }
2978 
2979  rtp_session->max_missed_packets = max;
2980 }
#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:5150
uint32_t max_missed_packets
Definition: switch_rtp.c:441
uint32_t flags[SWITCH_RTP_FLAG_INVALID]
Definition: switch_rtp.c:396
uint32_t missed_count
Definition: switch_rtp.c:442
switch_core_session_t * session
Definition: switch_rtp.c:476
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 2954 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().

2955 {
2956  if (!switch_rtp_ready(rtp_session) || rtp_session->flags[SWITCH_RTP_FLAG_UDPTL]) {
2957  return;
2958  }
2959 
2961  "%s MEDIA TIMEOUT %s set to %u\n", switch_core_session_get_name(rtp_session->session), rtp_type(rtp_session), ms);
2962  rtp_session->media_timeout = ms;
2963  switch_rtp_reset_media_timer(rtp_session);
2964 }
#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:5150
uint32_t media_timeout
Definition: switch_rtp.c:444
#define switch_core_session_get_name(_s)
Definition: switch_core.h:265
#define rtp_type(rtp_session)
Definition: switch_rtp.c:544
void switch_rtp_reset_media_timer(switch_rtp_t *rtp_session)
Definition: switch_rtp.c:3031
uint32_t flags[SWITCH_RTP_FLAG_INVALID]
Definition: switch_rtp.c:396
switch_core_session_t * session
Definition: switch_rtp.c:476
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 2652 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().

2653 {
2654 
2655  if (rtp_session) {
2656  switch_mutex_lock(rtp_session->flag_mutex);
2657  rtp_session->pmaps = pmap;
2658  switch_mutex_unlock(rtp_session->flag_mutex);
2659  return SWITCH_STATUS_SUCCESS;
2660  }
2661 
2662  return SWITCH_STATUS_FALSE;
2663 }
switch_mutex_t * flag_mutex
Definition: switch_rtp.c:430
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:477

◆ 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 9231 of file switch_rtp.c.

References switch_rtp::private_data.

9232 {
9233  rtp_session->private_data = private_data;
9234 }
void * private_data
Definition: switch_rtp.c:383

◆ 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 3128 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().

3130 {
3131  switch_sockaddr_t *remote_addr;
3133  *err = "Success";
3134 
3135  if (switch_sockaddr_info_get(&remote_addr, host, SWITCH_UNSPEC, port, 0, rtp_session->pool) != SWITCH_STATUS_SUCCESS || !remote_addr) {
3136  *err = "Remote Address Error!";
3137  return SWITCH_STATUS_FALSE;
3138  }
3139 
3140 
3141  switch_mutex_lock(rtp_session->write_mutex);
3142 
3143  rtp_session->remote_addr = remote_addr;
3144 
3145  if (change_adv_addr) {
3146  rtp_session->remote_host_str = switch_core_strdup(rtp_session->pool, host);
3147  rtp_session->remote_port = port;
3148  }
3149 
3150  rtp_session->eff_remote_host_str = switch_core_strdup(rtp_session->pool, host);
3151  rtp_session->eff_remote_port = port;
3152 
3153  if (rtp_session->sock_input && switch_sockaddr_get_family(rtp_session->remote_addr) == switch_sockaddr_get_family(rtp_session->local_addr)) {
3154  rtp_session->sock_output = rtp_session->sock_input;
3155  } else {
3156  if (rtp_session->sock_output && rtp_session->sock_output != rtp_session->sock_input) {
3157  switch_socket_close(rtp_session->sock_output);
3158  }
3159  if ((status = switch_socket_create(&rtp_session->sock_output,
3161  SOCK_DGRAM, 0, rtp_session->pool)) != SWITCH_STATUS_SUCCESS) {
3162 
3163  *err = "Socket Error!";
3164  }
3165  }
3166 
3167  if (rtp_session->dtls) {
3168  rtp_session->dtls->sock_output = rtp_session->sock_output;
3169 
3170  if (rtp_session->flags[SWITCH_RTP_FLAG_RTCP_MUX]) {
3171  status = switch_sockaddr_info_get(&rtp_session->dtls->remote_addr, host, SWITCH_UNSPEC, port, 0, rtp_session->pool);
3172  }
3173  }
3174 
3175 
3176  if (rtp_session->flags[SWITCH_RTP_FLAG_ENABLE_RTCP]) {
3177  if (rtp_session->flags[SWITCH_RTP_FLAG_RTCP_MUX]) {
3178  rtp_session->rtcp_remote_addr = rtp_session->remote_addr;
3179  rtp_session->rtcp_sock_output = rtp_session->sock_output;
3180  }/* else {
3181  if (remote_rtcp_port) {
3182  rtp_session->remote_rtcp_port = remote_rtcp_port;
3183  } else {
3184  rtp_session->remote_rtcp_port = rtp_session->eff_remote_port + 1;
3185  }
3186  status = enable_remote_rtcp_socket(rtp_session, err);
3187 
3188  if (rtp_session->rtcp_dtls) {
3189  //switch_sockaddr_info_get(&rtp_session->rtcp_dtls->remote_addr, host, SWITCH_UNSPEC, port, 0, rtp_session->pool);
3190  rtp_session->rtcp_dtls->remote_addr = rtp_session->rtcp_remote_addr;
3191  rtp_session->rtcp_dtls->sock_output = rtp_session->rtcp_sock_output;
3192  }
3193  }*/
3194  }
3195 
3196  switch_mutex_unlock(rtp_session->write_mutex);
3197 
3198  return status;
3199 }
switch_sockaddr_t * remote_addr
Definition: switch_rtp.c:291
switch_mutex_t * write_mutex
Definition: switch_rtp.c:432
switch_sockaddr_t * remote_addr
Definition: switch_rtp.c:344
#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:326
switch_port_t remote_port
Definition: switch_rtp.c:421
int32_t switch_sockaddr_get_family(switch_sockaddr_t *sa)
Definition: switch_apr.c:1006
char * remote_host_str
Definition: switch_rtp.c:405
switch_status_t switch_mutex_unlock(switch_mutex_t *lock)
Definition: switch_apr.c:313
switch_socket_t * sock_output
Definition: switch_rtp.c:290
switch_port_t eff_remote_port
Definition: switch_rtp.c:422
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:396
switch_sockaddr_t * local_addr
Definition: switch_rtp.c:330
switch_dtls_t * dtls
Definition: switch_rtp.c:370
switch_memory_pool_t * pool
Definition: switch_rtp.c:397
struct fspr_sockaddr_t switch_sockaddr_t
Definition: switch_apr.h:1029
switch_socket_t * rtcp_sock_output
Definition: switch_rtp.c:326
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:344
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:406
switch_socket_t * sock_output
Definition: switch_rtp.c:326

◆ switch_rtp_set_remote_ssrc()

switch_status_t switch_rtp_set_remote_ssrc ( switch_rtp_t rtp_session,
uint32_t  ssrc 
)

Definition at line 4469 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().

4470 {
4471  rtp_session->remote_ssrc = ssrc;
4472  rtp_session->flags[SWITCH_RTP_FLAG_DETECT_SSRC] = 0;
4473  return SWITCH_STATUS_SUCCESS;
4474 }
uint32_t flags[SWITCH_RTP_FLAG_INVALID]
Definition: switch_rtp.c:396
uint32_t remote_ssrc
Definition: switch_rtp.c:377

◆ switch_rtp_set_ssrc()

switch_status_t switch_rtp_set_ssrc ( switch_rtp_t rtp_session,
uint32_t  ssrc 
)

Definition at line 4461 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().

4462 {
4463  rtp_session->ssrc = ssrc;
4464  rtp_session->send_msg.header.ssrc = htonl(rtp_session->ssrc);
4465 
4466  return SWITCH_STATUS_SUCCESS;
4467 }
srtp_hdr_t header
Definition: switch_rtp.c:112
uint32_t ssrc
Definition: switch_rtp.c:376
rtp_msg_t send_msg
Definition: switch_rtp.c:331

◆ 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 2585 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().

2586 {
2587  if (port) {
2588  if (port_lock) {
2590  }
2591  START_PORT = port;
2592  if (port_lock) {
2594  }
2595  }
2596  return START_PORT;
2597 }
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 4693 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().

4694 {
4695  if (te > 95) {
4696  rtp_session->te = te;
4697  }
4698 }
switch_payload_t te
Definition: switch_rtp.c:427

◆ 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 4701 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().

4702 {
4703  if (te > 95) {
4704  rtp_session->recv_te = te;
4705  }
4706 }
switch_payload_t recv_te
Definition: switch_rtp.c:428

◆ 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 4786 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().

4787 {
4788  if (!switch_rtp_ready(rtp_session)) {
4789  return SWITCH_STATUS_FALSE;
4790  }
4791 
4792  if (!max_frames) {
4793  max_frames = rtp_session->last_max_vb_frames;
4794  }
4795 
4796  if (!max_frames || frames >= max_frames) {
4797  max_frames = frames * 10;
4798  }
4799 
4800  rtp_session->last_max_vb_frames = max_frames;
4801 
4802  if (!rtp_session->vb) {
4803  switch_jb_create(&rtp_session->vb, rtp_session->flags[SWITCH_RTP_FLAG_TEXT] ? SJB_TEXT : SJB_VIDEO, frames, max_frames, rtp_session->pool);
4804  switch_jb_set_session(rtp_session->vb, rtp_session->session);
4805  } else {
4806  switch_jb_set_frames(rtp_session->vb, frames, max_frames);
4807  }
4808 
4809  //switch_rtp_flush(rtp_session);
4811 
4812  switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(rtp_session->session), SWITCH_LOG_DEBUG1, "Setting video buffer %u Frames.\n", frames);
4813 
4814  return SWITCH_STATUS_SUCCESS;
4815 }
#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:5150
uint32_t last_max_vb_frames
Definition: switch_rtp.c:491
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:396
#define switch_core_session_request_video_refresh(_s)
Definition: switch_core.h:2892
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:439
switch_memory_pool_t * pool
Definition: switch_rtp.c:397
switch_core_session_t * session
Definition: switch_rtp.c:476
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 2555 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().

2556 {
2557  switch_core_port_allocator_t *alloc = NULL;
2558  switch_hash_index_t *hi;
2559  const void *var;
2560  void *val;
2561 
2562  if (!global_init) {
2563  return;
2564  }
2565 
2567 
2568  for (hi = switch_core_hash_first(alloc_hash); hi; hi = switch_core_hash_next(&hi)) {
2569  switch_core_hash_this(hi, &var, NULL, &val);
2570  if ((alloc = (switch_core_port_allocator_t *) val)) {
2571  switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "Destroy port allocator for %s\n", (char *) var);
2573  }
2574  }
2575 
2578 
2579 #ifdef ENABLE_SRTP
2580  srtp_crypto_kernel_shutdown();
2581 #endif
2583 }
#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:818
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:3687
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 5166 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().

5167 {
5168  if (!rtp_session) {
5169  return SWITCH_STATUS_FALSE;
5170  }
5171 
5172  if (rtp_session->flags[SWITCH_RTP_FLAG_VAD]) {
5174 
5175  switch_channel_set_variable_printf(channel, "vad_total_talk_time_ms", "%u", (uint32_t)rtp_session->vad_data.total_talk_time / 1000);
5176  switch_channel_set_variable_printf(channel, "vad_total_talk_time_sec", "%u", (uint32_t)rtp_session->vad_data.total_talk_time / 1000000);
5177  }
5178 
5179  do_mos(rtp_session);
5180 
5181  if (rtp_session->stats.inbound.error_log && !rtp_session->stats.inbound.error_log->stop) {
5182  rtp_session->stats.inbound.error_log->stop = switch_micro_time_now();
5183  }
5184 
5185  return SWITCH_STATUS_SUCCESS;
5186 }
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:220
switch_rtp_numbers_t inbound
Definition: switch_types.h:771
struct switch_rtp_vad_data vad_data
Definition: switch_rtp.c:425
switch_core_session_t * session
Definition: switch_rtp.c:199
_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:685
uint32_t flags[SWITCH_RTP_FLAG_INVALID]
Definition: switch_rtp.c:396
switch_rtp_stats_t stats
Definition: switch_rtp.c:454
struct error_period * error_log
Definition: switch_types.h:727
static void do_mos(switch_rtp_t *rtp_session)
Definition: switch_rtp.c:1575

◆ 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 5429 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().

5430 {
5431  return (uint32_t) rtp_session->flags[flags];
5432 }
uint32_t flags[SWITCH_RTP_FLAG_INVALID]
Definition: switch_rtp.c:396

◆ switch_rtp_udptl_mode()

switch_status_t switch_rtp_udptl_mode ( switch_rtp_t rtp_session)

Definition at line 3058 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().

3059 {
3060  switch_socket_t *sock;
3061 
3062  if (!switch_rtp_ready(rtp_session)) {
3063  return SWITCH_STATUS_FALSE;
3064  }
3065 
3067  ping_socket(rtp_session);
3068  }
3069 
3070  READ_INC(rtp_session);
3071  WRITE_INC(rtp_session);
3072 
3073  if (rtp_session->flags[SWITCH_RTP_FLAG_USE_TIMER] || rtp_session->timer.timer_interface) {
3074  switch_core_timer_destroy(&rtp_session->timer);
3075  memset(&rtp_session->timer, 0, sizeof(rtp_session->timer));
3077  }
3078 
3079  rtp_session->missed_count = 0;
3080  rtp_session->max_missed_packets = 0;
3081 
3082  rtp_session->flags[SWITCH_RTP_FLAG_ENABLE_RTCP] = 0;
3083 
3084  if (rtp_session->flags[SWITCH_RTP_FLAG_RTCP_MUX]) {
3085  rtp_session->rtcp_sock_input = NULL;
3086  rtp_session->rtcp_sock_output = NULL;
3087  } else {
3088  if (rtp_session->rtcp_sock_input && rtp_session->rtcp_sock_input != rtp_session->sock_input) {
3089  ping_socket(rtp_session);
3091  }
3092 
3093  if (rtp_session->rtcp_sock_output && rtp_session->rtcp_sock_output != rtp_session->rtcp_sock_input &&
3094  rtp_session->rtcp_sock_output != rtp_session->sock_input) {
3096  }
3097 
3098  if ((sock = rtp_session->rtcp_sock_input)) {
3099  rtp_session->rtcp_sock_input = NULL;
3100  switch_socket_close(sock);
3101 
3102  if (rtp_session->rtcp_sock_output && rtp_session->rtcp_sock_output != sock) {
3103  sock = rtp_session->rtcp_sock_output;
3104  rtp_session->rtcp_sock_output = NULL;
3105  switch_socket_close(sock);
3106  }
3107  }
3108  }
3109 
3114 
3115  WRITE_DEC(rtp_session);
3116  READ_DEC(rtp_session);
3117 
3120 
3121  switch_rtp_break(rtp_session);
3122 
3123  return SWITCH_STATUS_SUCCESS;
3124 
3125 }
uint8_t switch_rtp_ready(switch_rtp_t *rtp_session)
Test if an RTP session is ready.
Definition: switch_rtp.c:5150
uint32_t max_missed_packets
Definition: switch_rtp.c:441
#define WRITE_INC(rtp_session)
Definition: switch_rtp.c:69
switch_socket_t * sock_input
Definition: switch_rtp.c:326
switch_socket_t * rtcp_sock_input
Definition: switch_rtp.c:326
#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:396
#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:326
void switch_rtp_clear_flag(switch_rtp_t *rtp_session, switch_rtp_flag_t flag)
Clear an RTP Flag.
Definition: switch_rtp.c:5434
void switch_rtp_set_flag(switch_rtp_t *rtp_session, switch_rtp_flag_t flag)
Set an RTP Flag.
Definition: switch_rtp.c:5375
uint32_t missed_count
Definition: switch_rtp.c:442
#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:434
void switch_rtp_break(switch_rtp_t *rtp_session)
Definition: switch_rtp.c:5083
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:3047
uint32_t switch_rtp_test_flag(switch_rtp_t *rtp_session, switch_rtp_flag_t flags)
Test an RTP Flag.
Definition: switch_rtp.c:5429
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 5071 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().

5072 {
5073 
5074  if (!rtp_write_ready(rtp_session, 0, __LINE__)) {
5075  return;
5076  }
5077 
5078  if (rtp_session->flags[SWITCH_RTP_FLAG_VIDEO] && (rtp_session->ice.ice_user || rtp_session->flags[SWITCH_RTP_FLAG_PLI])) {
5079  rtp_session->pli_count = 1;
5080  }
5081 }
uint16_t pli_count
Definition: switch_rtp.c:338
uint32_t flags[SWITCH_RTP_FLAG_INVALID]
Definition: switch_rtp.c:396
static int rtp_write_ready(switch_rtp_t *rtp_session, uint32_t bytes, int line)
Definition: switch_rtp.c:8273
switch_rtp_ice_t ice
Definition: switch_rtp.c:401

◆ switch_rtp_video_refresh()

void switch_rtp_video_refresh ( switch_rtp_t rtp_session)

Definition at line 5059 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().

5060 {
5061 
5062  if (!rtp_write_ready(rtp_session, 0, __LINE__)) {
5063  return;
5064  }
5065 
5066  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])) {
5067  rtp_session->fir_count = 1;
5068  }
5069 }
uint32_t flags[SWITCH_RTP_FLAG_INVALID]
Definition: switch_rtp.c:396
uint16_t fir_count
Definition: switch_rtp.c:337
static int rtp_write_ready(switch_rtp_t *rtp_session, uint32_t bytes, int line)
Definition: switch_rtp.c:8273
switch_rtp_ice_t ice
Definition: switch_rtp.c:401

◆ 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 8890 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().

8891 {
8892  uint8_t fwd = 0;
8893  void *data = NULL;
8894  uint32_t len, ts = 0;
8895  switch_payload_t payload = 0;
8896  rtp_msg_t *send_msg = NULL;
8897  srtp_hdr_t local_header;
8898  int r = 0;
8899  switch_status_t status;
8900 
8901  if (!switch_rtp_ready(rtp_session) || !rtp_session->remote_addr) {
8902  return -1;
8903  }
8904 
8905  if (!rtp_write_ready(rtp_session, frame->datalen, __LINE__)) {
8907  }
8908 
8909  //if (rtp_session->flags[SWITCH_RTP_FLAG_VIDEO]) {
8910  // rtp_session->flags[SWITCH_RTP_FLAG_DEBUG_RTP_READ]++;
8911  // rtp_session->flags[SWITCH_RTP_FLAG_DEBUG_RTP_WRITE]++;
8912  //}
8913 
8914 
8916  rtp_session->flags[SWITCH_RTP_FLAG_PROXY_MEDIA] || rtp_session->flags[SWITCH_RTP_FLAG_UDPTL]) {
8917 
8918  //if (rtp_session->flags[SWITCH_RTP_FLAG_PROXY_MEDIA] || rtp_session->flags[SWITCH_RTP_FLAG_UDPTL]) {
8919  switch_size_t bytes;
8920  //char bufa[50];
8921 
8922  /* Fast PASS! */
8924  return 0;
8925  }
8926  bytes = frame->packetlen;
8927  //tx_host = switch_get_addr(bufa, sizeof(bufa), rtp_session->remote_addr);
8928 
8929  send_msg = frame->packet;
8930 
8931  if (!rtp_session->flags[SWITCH_RTP_FLAG_UDPTL] && !switch_test_flag(frame, SFF_UDPTL_PACKET)) {
8932 
8933  if (rtp_session->flags[SWITCH_RTP_FLAG_VIDEO] && rtp_session->payload > 0) {
8934  send_msg->header.pt = rtp_session->payload;
8935  }
8936 
8937  send_msg->header.ssrc = htonl(rtp_session->ssrc);
8938  send_msg->header.seq = htons(++rtp_session->seq);
8939  }
8940 
8941  if (rtp_session->flags[SWITCH_RTP_FLAG_DEBUG_RTP_WRITE]) {
8942  const char *tx_host;
8943  const char *old_host;
8944  const char *my_host;
8945 
8946  char bufa[50], bufb[50], bufc[50];
8947 
8948 
8949  tx_host = switch_get_addr(bufa, sizeof(bufa), rtp_session->rtp_from_addr);
8950  old_host = switch_get_addr(bufb, sizeof(bufb), rtp_session->remote_addr);
8951  my_host = switch_get_addr(bufc, sizeof(bufc), rtp_session->local_addr);
8952 
8954  "W %s b=%4ld %s:%u %s:%u %s:%u pt=%d ts=%u seq=%u m=%d\n",
8955  rtp_session->session ? switch_channel_get_name(switch_core_session_get_channel(rtp_session->session)) : "NoName",
8956  (long) bytes,
8957  my_host, switch_sockaddr_get_port(rtp_session->local_addr),
8958  old_host, rtp_session->remote_port,
8959  tx_host, switch_sockaddr_get_port(rtp_session->rtp_from_addr),
8960  send_msg->header.pt, ntohl(send_msg->header.ts), ntohs(send_msg->header.seq), send_msg->header.m);
8961 
8962  }
8963 
8964  if ((status = switch_socket_sendto(rtp_session->sock_output, rtp_session->remote_addr, 0, frame->packet, &bytes)) != SWITCH_STATUS_SUCCESS) {
8965  if (rtp_session->flags[SWITCH_RTP_FLAG_DEBUG_RTP_WRITE]) {
8966  switch_log_printf(SWITCH_CHANNEL_SESSION_LOG_CLEAN(rtp_session->session), SWITCH_LOG_ERROR, "bytes: %" SWITCH_SIZE_T_FMT ", status: %d", bytes, status);
8967  }
8968 
8969  return -1 * status;
8970  }
8971 
8972 
8973  rtp_session->stats.outbound.raw_bytes += bytes;
8974  rtp_session->stats.outbound.media_bytes += bytes;
8975  rtp_session->stats.outbound.media_packet_count++;
8976  rtp_session->stats.outbound.packet_count++;
8977  return (int) bytes;
8978  }
8979 
8980  fwd = (rtp_session->flags[SWITCH_RTP_FLAG_RAW_WRITE] &&
8982 
8983  if (!fwd && !rtp_session->sending_dtmf && !rtp_session->queue_delay && !rtp_session->flags[SWITCH_RTP_FLAG_VIDEO] &&
8984  rtp_session->flags[SWITCH_RTP_FLAG_RAW_WRITE] && (rtp_session->rtp_bugs & RTP_BUG_GEN_ONE_GEN_ALL)) {
8985 
8986  switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(rtp_session->session), SWITCH_LOG_WARNING, "Generating RTP locally but timestamp passthru is configured, disabling....\n");
8987  rtp_session->flags[SWITCH_RTP_FLAG_RAW_WRITE] = 0;
8988  rtp_session->flags[SWITCH_RTP_FLAG_RESET] = 1;
8989  }
8990 
8991  switch_assert(frame != NULL);
8992 
8993  if (switch_test_flag(frame, SFF_CNG)) {
8994  if (rtp_session->cng_pt != INVALID_PT) {
8995  payload = rtp_session->cng_pt;
8996  } else {
8997  return (int) frame->packetlen;
8998  }
8999  } else {
9000  payload = rtp_session->payload;
9001 #if 0
9002  if (rtp_session->pmaps && *rtp_session->pmaps) {
9003  payload_map_t *pmap;
9004  for (pmap = *rtp_session->pmaps; pmap; pmap = pmap->next) {
9005  if (pmap->current) {
9006  payload = pmap->pt;
9007  }
9008  }
9009  }
9010 #endif
9011  }
9012 
9013 
9014  if (switch_test_flag(frame, SFF_RTP_HEADER) || rtp_session->flags[SWITCH_RTP_FLAG_TEXT]) {
9015  switch_size_t wrote;
9016 
9017  wrote = switch_rtp_write_manual(rtp_session, frame->data, frame->datalen,
9018  frame->m, frame->payload, (uint32_t) (frame->timestamp), &frame->flags);
9019 
9020  rtp_session->stats.outbound.raw_bytes += wrote;
9021  rtp_session->stats.outbound.media_bytes += wrote;
9022  rtp_session->stats.outbound.media_packet_count++;
9023  rtp_session->stats.outbound.packet_count++;
9024 
9025  return wrote;
9026  }
9027 
9028  if (frame->pmap && rtp_session->pmaps && *rtp_session->pmaps) {
9029  payload_map_t *pmap;
9030 
9031  switch_mutex_lock(rtp_session->flag_mutex);
9032  for (pmap = *rtp_session->pmaps; pmap; pmap = pmap->next) {
9033  if (pmap->negotiated && pmap->hash == frame->pmap->hash) {
9034  payload = pmap->recv_pt;
9035  break;
9036  }
9037  }
9038  switch_mutex_unlock(rtp_session->flag_mutex);
9039  }
9040 
9041  if (fwd) {
9042  send_msg = frame->packet;
9043  local_header = send_msg->header;
9044  len = frame->packetlen;
9045  ts = 0;
9046 
9047  send_msg->header.pt = payload;
9048 
9050  send_msg->header.version = 2;
9051  send_msg->header.m = frame->m;
9052 
9053  send_msg->header.ts = htonl(frame->timestamp);
9054  if (frame->ssrc) {
9055  send_msg->header.ssrc = htonl(frame->ssrc);
9056  } else {
9057  send_msg->header.ssrc = htonl(rtp_session->ssrc);
9058  }
9059  }
9060 
9061  } else {
9062  data = frame->data;
9063  len = frame->datalen;
9064  ts = rtp_session->flags[SWITCH_RTP_FLAG_RAW_WRITE] ? (uint32_t) frame->timestamp : 0;
9065  }
9066 
9067  /*
9068  if (rtp_session->flags[SWITCH_RTP_FLAG_VIDEO]) {
9069  send_msg->header.pt = rtp_session->payload;
9070  }
9071  */
9072 
9073  r = rtp_common_write(rtp_session, send_msg, data, len, payload, ts, &frame->flags);
9074 
9075  if (send_msg) {
9076  send_msg->header = local_header;
9077  }
9078 
9079  return r;
9080 
9081 }
uint32_t queue_delay
Definition: switch_rtp.c:394
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:5150
switch_sockaddr_t * remote_addr
Definition: switch_rtp.c:344
switch_mutex_t * flag_mutex
Definition: switch_rtp.c:430
uint32_t timestamp
Definition: switch_frame.h:80
unsigned long hash
switch_port_t remote_port
Definition: switch_rtp.c:421
switch_size_t media_bytes
Definition: switch_types.h:694
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:429
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:8293
switch_size_t raw_bytes
Definition: switch_types.h:693
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:396
switch_sockaddr_t * rtp_from_addr
Definition: switch_rtp.c:398
switch_rtp_numbers_t outbound
Definition: switch_types.h:772
static int rtp_write_ready(switch_rtp_t *rtp_session, uint32_t bytes, int line)
Definition: switch_rtp.c:8273
uintptr_t switch_size_t
uint8_t negotiated
switch_sockaddr_t * local_addr
Definition: switch_rtp.c:330
uint16_t seq
Definition: switch_rtp.c:375
switch_payload_t pt
switch_size_t packet_count
Definition: switch_types.h:695
switch_rtp_stats_t stats
Definition: switch_rtp.c:454
#define SWITCH_CHANNEL_SESSION_LOG_CLEAN(x)
payload_map_t ** pmaps
Definition: switch_rtp.c:477
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:476
int8_t sending_dtmf
Definition: switch_rtp.c:379
switch_size_t media_packet_count
Definition: switch_types.h:697
switch_rtp_bug_flag_t rtp_bugs
Definition: switch_rtp.c:453
uint32_t ssrc
Definition: switch_rtp.c:376
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:381
switch_socket_t * sock_output
Definition: switch_rtp.c:326
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:9110

◆ 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 9110 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().

9112 {
9113  switch_size_t bytes;
9114  int ret = -1;
9115 
9116  if (!switch_rtp_ready(rtp_session) || !rtp_session->remote_addr || datalen > SWITCH_RTP_MAX_BUF_LEN) {
9117  return -1;
9118  }
9119 
9120  if (!rtp_write_ready(rtp_session, datalen, __LINE__)) {
9121  return 0;
9122  }
9123 
9124  if (payload == INVALID_PT) {
9125  return 0;
9126  }
9127 
9128  WRITE_INC(rtp_session);
9129 
9130  rtp_session->write_msg = rtp_session->send_msg;
9131  rtp_session->write_msg.header.seq = htons(++rtp_session->seq);
9132  rtp_session->write_msg.header.ts = htonl(ts);
9133  rtp_session->write_msg.header.pt = payload;
9134  rtp_session->write_msg.header.m = m;
9135  memcpy(rtp_session->write_msg.body, data, datalen);
9136 
9137  bytes = rtp_header_len + datalen;
9138 
9139  if (switch_rtp_write_raw(rtp_session, (void *) &rtp_session->write_msg, &bytes, SWITCH_TRUE) != SWITCH_STATUS_SUCCESS) {
9140  rtp_session->seq--;
9141  ret = -1;
9142  goto end;
9143  }
9144 
9145  if (((*flags) & SFF_RTP_HEADER)) {
9146  rtp_session->last_write_ts = ts;
9147  rtp_session->flags[SWITCH_RTP_FLAG_RESET] = 0;
9148  }
9149 
9150  ret = (int) bytes;
9151 
9152  end:
9153 
9154  WRITE_DEC(rtp_session);
9155 
9156  return ret;
9157 }
uint8_t switch_rtp_ready(switch_rtp_t *rtp_session)
Test if an RTP session is ready.
Definition: switch_rtp.c:5150
switch_sockaddr_t * remote_addr
Definition: switch_rtp.c:344
#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:396
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:8273
uintptr_t switch_size_t
uint16_t seq
Definition: switch_rtp.c:375
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:9161
rtp_msg_t write_msg
Definition: switch_rtp.c:445
srtp_hdr_t header
Definition: switch_rtp.c:112
uint32_t last_write_ts
Definition: switch_rtp.c:386
rtp_msg_t send_msg
Definition: switch_rtp.c:331
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 9161 of file switch_rtp.c.

References switch_rtp::flags, 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().

9162 {
9164 
9165  switch_assert(bytes);
9166 
9167  if (!switch_rtp_ready(rtp_session) || !rtp_session->remote_addr || *bytes > SWITCH_RTP_MAX_BUF_LEN) {
9168  return status;
9169  }
9170 
9171  if (!rtp_write_ready(rtp_session, *bytes, __LINE__)) {
9173  }
9174 
9175  WRITE_INC(rtp_session);
9176 
9177  if (process_encryption) {
9178 #ifdef ENABLE_SRTP
9179  switch_mutex_lock(rtp_session->ice_mutex);
9180  if (rtp_session->flags[SWITCH_RTP_FLAG_SECURE_SEND]) {
9181 
9182  int sbytes = (int) *bytes;
9183  srtp_err_status_t stat;
9184 
9185  if (rtp_session->flags[SWITCH_RTP_FLAG_SECURE_SEND_RESET]) {
9187  srtp_dealloc(rtp_session->send_ctx[rtp_session->srtp_idx_rtp]);
9188  rtp_session->send_ctx[rtp_session->srtp_idx_rtp] = NULL;
9189  if (srtp_create(&rtp_session->send_ctx[rtp_session->srtp_idx_rtp],
9190  &rtp_session->send_policy[rtp_session->srtp_idx_rtp]) || !rtp_session->send_ctx[rtp_session->srtp_idx_rtp]) {
9191  switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(rtp_session->session), SWITCH_LOG_ERROR, "Error! RE-Activating Secure RTP SEND\n");
9192  rtp_session->flags[SWITCH_RTP_FLAG_SECURE_SEND] = 0;
9193  status = SWITCH_STATUS_FALSE;
9194  switch_mutex_unlock(rtp_session->ice_mutex);
9195  goto end;
9196  } else {
9197  switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(rtp_session->session), SWITCH_LOG_INFO, "RE-Activating Secure RTP SEND\n");
9198  }
9199  }
9200 
9201  if (!rtp_session->flags[SWITCH_RTP_FLAG_SECURE_SEND_MKI]) {
9202  stat = srtp_protect(rtp_session->send_ctx[rtp_session->srtp_idx_rtp], &rtp_session->write_msg, &sbytes);
9203  } else {
9204  stat = srtp_protect_mki(rtp_session->send_ctx[rtp_session->srtp_idx_rtp], &rtp_session->write_msg, &sbytes, 1, SWITCH_CRYPTO_MKI_INDEX);
9205  }
9206 
9207  if (stat) {
9208  switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(rtp_session->session), SWITCH_LOG_ERROR, "Error: SRTP protection failed with code %d\n", stat);
9209  }
9210  *bytes = sbytes;
9211  }
9212  switch_mutex_unlock(rtp_session->ice_mutex);
9213 #endif
9214  }
9215 
9216  status = switch_socket_sendto(rtp_session->sock_output, rtp_session->remote_addr, 0, data, bytes);
9217 #if defined(ENABLE_SRTP)
9218  end:
9219 #endif
9220 
9221  WRITE_DEC(rtp_session);
9222 
9223  return status;
9224 }
#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:5150
switch_sockaddr_t * remote_addr
Definition: switch_rtp.c:344
#define WRITE_INC(rtp_session)
Definition: switch_rtp.c:69
srtp_policy_t send_policy[2]
Definition: switch_rtp.c:360
#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:357
#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:396
static int rtp_write_ready(switch_rtp_t *rtp_session, uint32_t bytes, int line)
Definition: switch_rtp.c:8273
void switch_rtp_clear_flag(switch_rtp_t *rtp_session, switch_rtp_flag_t flag)
Clear an RTP Flag.
Definition: switch_rtp.c:5434
rtp_msg_t write_msg
Definition: switch_rtp.c:445
switch_status_t
Common return values.
switch_mutex_t * ice_mutex
Definition: switch_rtp.c:433
switch_core_session_t * session
Definition: switch_rtp.c:476
int srtp_idx_rtp
Definition: switch_rtp.c:367
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:326

◆ 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 8247 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.

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

8196 {
8197  int bytes = 0;
8198 
8199  if (!switch_rtp_ready(rtp_session)) {
8200  return SWITCH_STATUS_FALSE;
8201  }
8202 
8203  bytes = rtp_common_read(rtp_session, &frame->payload, &frame->pmap, &frame->flags, io_flags);
8204 
8205  frame->data = RTP_BODY(rtp_session);
8206 
8207  if (!rtp_session->flags[SWITCH_RTP_FLAG_UDPTL] && (bytes < rtp_header_len || switch_test_flag(frame, SFF_CNG))) {
8208  frame->packet = NULL;
8209  frame->timestamp = 0;
8210  frame->seq = 0;
8211  frame->ssrc = 0;
8212  frame->m = 0;
8213  } else {
8214 
8215  frame->packet = &rtp_session->recv_msg;
8216  frame->packetlen = bytes;
8217  frame->source = __FILE__;
8218 
8219  switch_set_flag(frame, SFF_RAW_RTP);
8220  switch_set_flag(frame, SFF_EXTERNAL);
8221  if (frame->payload == rtp_session->recv_te) {
8222  switch_set_flag(frame, SFF_RFC2833);
8223  }
8224  frame->timestamp = ntohl(rtp_session->last_rtp_hdr.ts);
8225  frame->seq = (uint16_t) ntohs((uint16_t) rtp_session->last_rtp_hdr.seq);
8226  frame->ssrc = ntohl(rtp_session->last_rtp_hdr.ssrc);
8227  frame->m = rtp_session->last_rtp_hdr.m ? SWITCH_TRUE : SWITCH_FALSE;
8228  }
8229 
8230 
8231  if (bytes < 0) {
8232  frame->datalen = 0;
8233  return bytes == -2 ? SWITCH_STATUS_TIMEOUT : SWITCH_STATUS_GENERR;
8234  } else if (!rtp_session->flags[SWITCH_RTP_FLAG_UDPTL]) {
8235  if (bytes < rtp_header_len) {
8236  frame->datalen = 0;
8237  return SWITCH_STATUS_BREAK;
8238  } else {
8239  bytes -= rtp_header_len;
8240  }
8241  }
8242 
8243  frame->datalen = bytes;
8244  return SWITCH_STATUS_SUCCESS;
8245 }
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:5150
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:396
#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:345
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:7304
switch_payload_t recv_te
Definition: switch_rtp.c:428
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:373
#define rtp_header_len
Definition: switch_rtp.c:73