FreeSWITCH API Documentation  1.7.0
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[], 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[], char *timer_name, const char **err, switch_memory_pool_t *pool)
 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)
 
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)
 
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)
 

Detailed Description

Typedef Documentation

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 177 of file switch_rtp.h.

Function Documentation

void rtp_flush_read_buffer ( switch_rtp_t rtp_session,
switch_rtp_flush_t  flush 
)

Definition at line 4940 of file switch_rtp.c.

References 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(), switch_rtp_set_flag(), and switch_rtp_set_flags().

4941 {
4942 
4943  if (rtp_session->flags[SWITCH_RTP_FLAG_PROXY_MEDIA] ||
4944  rtp_session->flags[SWITCH_RTP_FLAG_UDPTL]) {
4945  return;
4946  }
4947 
4948 
4949  if (switch_rtp_ready(rtp_session)) {
4950  rtp_session->flags[SWITCH_RTP_FLAG_RESET] = 1;
4951  rtp_session->flags[SWITCH_RTP_FLAG_FLUSH] = 1;
4952  reset_jitter_seq(rtp_session);
4953 
4954  switch (flush) {
4957  break;
4960  break;
4961  default:
4962  break;
4963  }
4964  }
4965 }
uint8_t switch_rtp_ready(switch_rtp_t *rtp_session)
Test if an RTP session is ready.
Definition: switch_rtp.c:4452
uint32_t flags[SWITCH_RTP_FLAG_INVALID]
Definition: switch_rtp.c:372
void switch_rtp_clear_flag(switch_rtp_t *rtp_session, switch_rtp_flag_t flag)
Clear an RTP Flag.
Definition: switch_rtp.c:4747
void switch_rtp_set_flag(switch_rtp_t *rtp_session, switch_rtp_flag_t flag)
Set an RTP Flag.
Definition: switch_rtp.c:4702
static void reset_jitter_seq(switch_rtp_t *rtp_session)
Definition: switch_rtp.c:1595
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 7016 of file switch_rtp.c.

References SWITCH_RTP_FLAG_ENABLE_RTCP, SWITCH_STATUS_FALSE, SWITCH_STATUS_SUCCESS, and SWITCH_STATUS_TIMEOUT.

Referenced by switch_core_media_read_frame().

7017 {
7018 
7019  if (!rtp_session->flags[SWITCH_RTP_FLAG_ENABLE_RTCP]) {
7020  return SWITCH_STATUS_FALSE;
7021  }
7022 
7023  /* A fresh frame has been found! */
7024  if (rtp_session->rtcp_fresh_frame) {
7025  /* turn the flag off! */
7026  rtp_session->rtcp_fresh_frame = 0;
7027 
7028  *frame = rtp_session->rtcp_frame;
7029 
7030  return SWITCH_STATUS_SUCCESS;
7031  }
7032 
7033  return SWITCH_STATUS_TIMEOUT;
7034 }
switch_bool_t rtcp_fresh_frame
Definition: switch_rtp.c:437
uint32_t flags[SWITCH_RTP_FLAG_INVALID]
Definition: switch_rtp.c:372
switch_rtcp_frame_t rtcp_frame
Definition: switch_rtp.c:316
switch_status_t switch_rtp_ack_bitrate ( switch_rtp_t rtp_session,
uint32_t  bps 
)

Definition at line 4351 of file switch_rtp.c.

References rtp_write_ready(), SWITCH_STATUS_FALSE, and SWITCH_STATUS_SUCCESS.

Referenced by switch_core_media_receive_message().

4352 {
4353  if (!rtp_write_ready(rtp_session, 0, __LINE__) || rtp_session->tmmbn) {
4354  return SWITCH_STATUS_FALSE;
4355  }
4356 
4357  rtp_session->tmmbn = bps;
4358 
4359  return SWITCH_STATUS_SUCCESS;
4360 }
uint32_t tmmbn
Definition: switch_rtp.c:323
static int rtp_write_ready(switch_rtp_t *rtp_session, uint32_t bytes, int line)
Definition: switch_rtp.c:7161
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 4241 of file switch_rtp.c.

References switch_rtp_ice_t::addr, ice_s::cands, ice_s::chosen, icand_s::con_addr, icand_s::con_port, switch_rtp_ice_t::ice_params, switch_rtp_ice_t::ice_user, ICE_VANILLA, IPR_RTP, switch_rtp_ice_t::luser_ice, switch_rtp_ice_t::next_run, switch_rtp_ice_t::pass, switch_rtp_ice_t::proto, switch_rtp_ice_t::ready, switch_rtp_ice_t::rpass, switch_rtp_ice_t::rready, RTP_BUG_ACCEPT_ANY_PACKETS, rtp_type, 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().

4244 {
4245  char ice_user[80];
4246  char user_ice[80];
4247  char luser_ice[80];
4248  switch_rtp_ice_t *ice;
4249  char *host = NULL;
4250  switch_port_t port = 0;
4251  char bufc[50];
4252 
4253 
4254  switch_mutex_lock(rtp_session->ice_mutex);
4255 
4256  if (proto == IPR_RTP) {
4257  ice = &rtp_session->ice;
4258  rtp_session->flags[SWITCH_RTP_FLAG_PAUSE] = 0;
4259  rtp_session->flags[SWITCH_RTP_FLAG_MUTE] = 0;
4260  } else {
4261  ice = &rtp_session->rtcp_ice;
4262  }
4263 
4264  ice->proto = proto;
4265 
4266  if ((type & ICE_VANILLA)) {
4267  switch_snprintf(ice_user, sizeof(ice_user), "%s:%s", login, rlogin);
4268  switch_snprintf(user_ice, sizeof(user_ice), "%s:%s", rlogin, login);
4269  switch_snprintf(luser_ice, sizeof(user_ice), "%s%s", rlogin, login);
4270  ice->ready = ice->rready = 0;
4271  } else {
4272  switch_snprintf(ice_user, sizeof(ice_user), "%s%s", login, rlogin);
4273  switch_snprintf(user_ice, sizeof(user_ice), "%s%s", rlogin, login);
4274  ice->ready = ice->rready = 1;
4275  }
4276 
4277  ice->ice_user = switch_core_strdup(rtp_session->pool, ice_user);
4278  ice->user_ice = switch_core_strdup(rtp_session->pool, user_ice);
4279  ice->luser_ice = switch_core_strdup(rtp_session->pool, luser_ice);
4280  ice->type = type;
4281  ice->ice_params = ice_params;
4282  ice->pass = "";
4283  ice->rpass = "";
4285 
4286  if (password) {
4287  ice->pass = switch_core_strdup(rtp_session->pool, password);
4288  }
4289 
4290  if (rpassword) {
4291  ice->rpass = switch_core_strdup(rtp_session->pool, rpassword);
4292  }
4293 
4294  if ((ice->type & ICE_VANILLA) && ice->ice_params) {
4295  host = ice->ice_params->cands[ice->ice_params->chosen[ice->proto]][ice->proto].con_addr;
4296  port = ice->ice_params->cands[ice->ice_params->chosen[ice->proto]][ice->proto].con_port;
4297 
4298  if (!host || !port || switch_sockaddr_info_get(&ice->addr, host, SWITCH_UNSPEC, port, 0, rtp_session->pool) != SWITCH_STATUS_SUCCESS || !ice->addr) {
4299  switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(rtp_session->session), SWITCH_LOG_ERROR, "Error setting remote host!\n");
4300  return SWITCH_STATUS_FALSE;
4301  }
4302  } else {
4303  if (proto == IPR_RTP) {
4304  ice->addr = rtp_session->remote_addr;
4305  } else {
4306  ice->addr = rtp_session->rtcp_remote_addr;
4307  }
4308 
4309  host = (char *)switch_get_addr(bufc, sizeof(bufc), ice->addr);
4310  port = switch_sockaddr_get_port(ice->addr);
4311  }
4312 
4313  switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(rtp_session->session), SWITCH_LOG_NOTICE, "Activating %s %s ICE: %s %s:%d\n",
4314  proto == IPR_RTP ? "RTP" : "RTCP", rtp_type(rtp_session), ice_user, host, port);
4315 
4316 
4317  rtp_session->rtp_bugs |= RTP_BUG_ACCEPT_ANY_PACKETS;
4318 
4319 
4320  if (rtp_session->flags[SWITCH_RTP_FLAG_VIDEO]) {
4321  rtp_session->flags[SWITCH_RTP_FLAG_VIDEO_BREAK] = 1;
4322  switch_rtp_break(rtp_session);
4323  }
4324 
4325  switch_mutex_unlock(rtp_session->ice_mutex);
4326 
4327  return SWITCH_STATUS_SUCCESS;
4328 }
switch_time_t switch_micro_time_now(void)
Get the current epoch time in microseconds.
Definition: switch_time.c:310
#define SWITCH_CHANNEL_SESSION_LOG(x)
uint16_t switch_sockaddr_get_port(switch_sockaddr_t *sa)
Definition: switch_apr.c:916
switch_sockaddr_t * remote_addr
Definition: switch_rtp.c:326
int chosen[2]
Definition: switch_rtp.h:107
switch_sockaddr_t * addr
Definition: switch_rtp.c:244
#define switch_core_strdup(_pool, _todup)
Copy a string using memory allocation from a given pool.
Definition: switch_core.h:729
ice_t * ice_params
Definition: switch_rtp.c:248
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:246
#define rtp_type(rtp_session)
Definition: switch_rtp.c:513
switch_status_t switch_mutex_unlock(switch_mutex_t *lock)
Definition: switch_apr.c:290
switch_core_media_ice_type_t type
Definition: switch_rtp.c:247
switch_status_t switch_mutex_lock(switch_mutex_t *lock)
Definition: switch_apr.c:285
uint32_t flags[SWITCH_RTP_FLAG_INVALID]
Definition: switch_rtp.c:372
char * con_addr
Definition: switch_rtp.h:93
uint16_t switch_port_t
switch_rtp_ice_t rtcp_ice
Definition: switch_rtp.c:378
switch_memory_pool_t * pool
Definition: switch_rtp.c:373
ice_proto_t proto
Definition: switch_rtp.c:249
void switch_rtp_break(switch_rtp_t *rtp_session)
Definition: switch_rtp.c:4385
#define SWITCH_UNSPEC
Definition: switch_apr.h:1022
switch_mutex_t * ice_mutex
Definition: switch_rtp.c:410
switch_core_session_t * session
Definition: switch_rtp.c:446
switch_rtp_ice_t ice
Definition: switch_rtp.c:377
switch_rtp_bug_flag_t rtp_bugs
Definition: switch_rtp.c:427
icand_t cands[MAX_CAND][2]
Definition: switch_rtp.h:105
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:894
switch_sockaddr_t * rtcp_remote_addr
Definition: switch_rtp.c:326
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:817
switch_port_t con_port
Definition: switch_rtp.h:94
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 4146 of file switch_rtp.c.

References READ_DEC, READ_INC, SJB_AUDIO, switch_channel_get_variable_dup(), switch_core_session_get_channel(), SWITCH_FALSE, switch_jb_create(), switch_jb_set_frames(), switch_jb_set_session(), switch_jb_ts_mode(), switch_rtp_ready(), SWITCH_STATUS_FALSE, and switch_true().

Referenced by check_jb().

4151 {
4153 
4154  if (!switch_rtp_ready(rtp_session)) {
4155  return SWITCH_STATUS_FALSE;
4156  }
4157 
4158  if (queue_frames < 1) {
4159  queue_frames = 3;
4160  }
4161 
4162  if (max_queue_frames < queue_frames) {
4163  max_queue_frames = queue_frames * 3;
4164  }
4165 
4166 
4167 
4168  if (rtp_session->jb) {
4169  status = switch_jb_set_frames(rtp_session->jb, queue_frames, max_queue_frames);
4170  } else {
4171  READ_INC(rtp_session);
4172  status = switch_jb_create(&rtp_session->jb, SJB_AUDIO, queue_frames, max_queue_frames, rtp_session->pool);
4173  switch_jb_set_session(rtp_session->jb, rtp_session->session);
4175  switch_jb_ts_mode(rtp_session->jb, samples_per_packet, samples_per_second);
4176  }
4177  //switch_jb_debug_level(rtp_session->jb, 10);
4178  READ_DEC(rtp_session);
4179  }
4180 
4181 
4182 
4183  return status;
4184 }
uint8_t switch_rtp_ready(switch_rtp_t *rtp_session)
Test if an RTP session is ready.
Definition: switch_rtp.c:4452
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)
static int switch_true(const char *expr)
Evaluate the truthfullness of a string expression.
Definition: switch_utils.h:450
#define READ_DEC(rtp_session)
Definition: switch_rtp.c:61
_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_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:60
switch_status_t switch_jb_set_frames(switch_jb_t *jb, uint32_t min_frame_len, uint32_t max_frame_len)
switch_memory_pool_t * pool
Definition: switch_rtp.c:373
switch_jb_t * jb
Definition: switch_rtp.c:414
switch_status_t
Common return values.
switch_core_session_t * session
Definition: switch_rtp.c:446
void switch_jb_ts_mode(switch_jb_t *jb, uint32_t samples_per_frame, uint32_t samples_per_second)
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 4186 of file switch_rtp.c.

References enable_local_rtcp_socket(), enable_remote_rtcp_socket(), 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().

4187 {
4188  const char *err = NULL;
4189 
4190  if (!rtp_session->ms_per_packet) {
4191  return SWITCH_STATUS_FALSE;
4192  }
4193 
4194  rtp_session->flags[SWITCH_RTP_FLAG_ENABLE_RTCP] = 1;
4195 
4196  if (!(rtp_session->remote_rtcp_port = remote_port)) {
4197  rtp_session->remote_rtcp_port = rtp_session->remote_port + 1;
4198  }
4199 
4200  if (mux) {
4201  rtp_session->flags[SWITCH_RTP_FLAG_RTCP_MUX]++;
4202  }
4203 
4204 
4205  if (send_rate == -1) {
4206 
4207  rtp_session->flags[SWITCH_RTP_FLAG_RTCP_PASSTHRU] = 1;
4208  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);
4209  } else {
4210  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);
4211 
4212  rtp_session->rtcp_interval = send_rate;
4213  }
4214 
4215  if (rtp_session->flags[SWITCH_RTP_FLAG_RTCP_MUX]) {
4216 
4218  rtp_session->remote_rtcp_port, 0, rtp_session->pool) != SWITCH_STATUS_SUCCESS || !rtp_session->rtcp_remote_addr) {
4219  switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(rtp_session->session), SWITCH_LOG_ERROR, "RTCP MUX Remote Address Error!");
4220  return SWITCH_STATUS_FALSE;
4221  }
4222 
4223  rtp_session->rtcp_local_addr = rtp_session->local_addr;
4224  rtp_session->rtcp_from_addr = rtp_session->from_addr;
4225  rtp_session->rtcp_sock_input = rtp_session->sock_input;
4226  rtp_session->rtcp_sock_output = rtp_session->sock_output;
4227 
4228  rtp_session->rtcp_recv_msg_p = (rtcp_msg_t *) &rtp_session->recv_msg;
4229 
4230  return SWITCH_STATUS_SUCCESS;
4231 
4232  //return enable_remote_rtcp_socket(rtp_session, &err);
4233  } else {
4234  rtp_session->rtcp_recv_msg_p = (rtcp_msg_t *) &rtp_session->rtcp_recv_msg;
4235  }
4236 
4237  return enable_local_rtcp_socket(rtp_session, &err) || enable_remote_rtcp_socket(rtp_session, &err);
4238 
4239 }
#define SWITCH_CHANNEL_SESSION_LOG(x)
switch_sockaddr_t * rtcp_from_addr
Definition: switch_rtp.c:374
switch_sockaddr_t * rtcp_local_addr
Definition: switch_rtp.c:313
switch_port_t remote_rtcp_port
Definition: switch_rtp.c:400
switch_socket_t * sock_input
Definition: switch_rtp.c:309
switch_port_t remote_port
Definition: switch_rtp.c:398
switch_socket_t * rtcp_sock_input
Definition: switch_rtp.c:309
rtcp_msg_t rtcp_recv_msg
Definition: switch_rtp.c:328
uint32_t flags[SWITCH_RTP_FLAG_INVALID]
Definition: switch_rtp.c:372
switch_sockaddr_t * local_addr
Definition: switch_rtp.c:313
switch_memory_pool_t * pool
Definition: switch_rtp.c:373
switch_socket_t * rtcp_sock_output
Definition: switch_rtp.c:309
int rtcp_interval
Definition: switch_rtp.c:435
static switch_status_t enable_remote_rtcp_socket(switch_rtp_t *rtp_session, const char **err)
Definition: switch_rtp.c:2478
rtp_msg_t recv_msg
Definition: switch_rtp.c:327
#define SWITCH_UNSPEC
Definition: switch_apr.h:1022
switch_core_session_t * session
Definition: switch_rtp.c:446
uint32_t ms_per_packet
Definition: switch_rtp.c:391
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:374
switch_sockaddr_t * rtcp_remote_addr
Definition: switch_rtp.c:326
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:817
char * eff_remote_host_str
Definition: switch_rtp.c:382
static switch_status_t enable_local_rtcp_socket(switch_rtp_t *rtp_session, const char **err)
Definition: switch_rtp.c:2522
rtcp_msg_t * rtcp_recv_msg_p
Definition: switch_rtp.c:329
switch_socket_t * sock_output
Definition: switch_rtp.c:309
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 
)

Definition at line 3294 of file switch_rtp.c.

References switch_dtls_s::ca, switch_directories::certs_dir, DS_HANDSHAKE, dtls_set_state, DTLS_SRTP_FNAME, DTLS_TYPE_CLIENT, DTLS_TYPE_RTCP, DTLS_TYPE_RTP, DTLS_TYPE_SERVER, switch_dtls_s::local_fp, switch_dtls_s::pem, switch_dtls_s::pvt, switch_dtls_s::read_bio, switch_dtls_s::remote_addr, switch_dtls_s::remote_fp, switch_dtls_s::rsa, switch_dtls_s::rtp_session, rtp_type, switch_dtls_s::sock_output, switch_dtls_s::ssl, switch_dtls_s::ssl_ctx, switch_assert, SWITCH_CHANNEL_SESSION_LOG, switch_core_alloc, switch_core_cert_expand_fingerprint(), switch_core_sprintf(), switch_file_exists(), SWITCH_GLOBAL_dirs, SWITCH_LOG_CRIT, SWITCH_LOG_ERROR, SWITCH_LOG_INFO, switch_log_printf(), SWITCH_LOG_WARNING, 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().

3295 {
3296  switch_dtls_t *dtls;
3297  int ret;
3298  const char *kind = "";
3299  BIO *bio;
3300  DH *dh;
3301 #ifndef OPENSSL_NO_EC
3302  EC_KEY* ecdh;
3303 #endif
3304 
3305 #ifndef HAVE_OPENSSL_DTLS_SRTP
3306  return SWITCH_STATUS_FALSE;
3307 #endif
3308 
3309  if (!switch_rtp_ready(rtp_session)) {
3310  return SWITCH_STATUS_FALSE;
3311  }
3312 
3313  if (!((type & DTLS_TYPE_RTP) || (type & DTLS_TYPE_RTCP)) || !((type & DTLS_TYPE_CLIENT) || (type & DTLS_TYPE_SERVER))) {
3314  switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(rtp_session->session), SWITCH_LOG_CRIT, "INVALID TYPE!\n");
3315  }
3316 
3317  switch_rtp_del_dtls(rtp_session, type);
3318 
3319  if ((type & DTLS_TYPE_RTP) && (type & DTLS_TYPE_RTCP)) {
3320  kind = "RTP/RTCP";
3321  } else if ((type & DTLS_TYPE_RTP)) {
3322  kind = "RTP";
3323  } else {
3324  kind = "RTCP";
3325  }
3326 
3328  "Activate %s %s DTLS %s\n", kind, rtp_type(rtp_session), (type & DTLS_TYPE_SERVER) ? "server" : "client");
3329 
3330  if (((type & DTLS_TYPE_RTP) && rtp_session->dtls) || ((type & DTLS_TYPE_RTCP) && rtp_session->rtcp_dtls)) {
3331  switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(rtp_session->session), SWITCH_LOG_WARNING, "DTLS ALREADY INIT\n");
3332  return SWITCH_STATUS_FALSE;
3333  }
3334 
3335  dtls = switch_core_alloc(rtp_session->pool, sizeof(*dtls));
3336 
3338 
3339  if (switch_file_exists(dtls->pem, rtp_session->pool) == SWITCH_STATUS_SUCCESS) {
3340  dtls->pvt = dtls->rsa = dtls->pem;
3341  } else {
3344  }
3345 
3346  dtls->ca = switch_core_sprintf(rtp_session->pool, "%s%sca-bundle.crt", SWITCH_GLOBAL_dirs.certs_dir, SWITCH_PATH_SEPARATOR);
3347 
3348  dtls->ssl_ctx = SSL_CTX_new((type & DTLS_TYPE_SERVER) ? DTLSv1_server_method() : DTLSv1_client_method());
3349  switch_assert(dtls->ssl_ctx);
3350 
3351  bio = BIO_new_file(dtls->pem, "r");
3352  dh = PEM_read_bio_DHparams(bio, NULL, NULL, NULL);
3353  BIO_free(bio);
3354  if (dh) {
3355  SSL_CTX_set_tmp_dh(dtls->ssl_ctx, dh);
3356  DH_free(dh);
3357  }
3358 
3359  SSL_CTX_set_mode(dtls->ssl_ctx, SSL_MODE_AUTO_RETRY);
3360 
3361  //SSL_CTX_set_verify(dtls->ssl_ctx, SSL_VERIFY_PEER | SSL_VERIFY_FAIL_IF_NO_PEER_CERT, NULL);
3362  SSL_CTX_set_verify(dtls->ssl_ctx, SSL_VERIFY_NONE, NULL);
3363 
3364  SSL_CTX_set_cipher_list(dtls->ssl_ctx, "ALL");
3365 
3366 #ifdef HAVE_OPENSSL_DTLS_SRTP
3367  //SSL_CTX_set_tlsext_use_srtp(dtls->ssl_ctx, "SRTP_AES128_CM_SHA1_80:SRTP_AES128_CM_SHA1_32");
3368  SSL_CTX_set_tlsext_use_srtp(dtls->ssl_ctx, "SRTP_AES128_CM_SHA1_80");
3369 #endif
3370 
3371  dtls->type = type;
3372  dtls->read_bio = BIO_new(BIO_s_mem());
3373  switch_assert(dtls->read_bio);
3374 
3375  dtls->write_bio = BIO_new(BIO_s_mem());
3376  switch_assert(dtls->write_bio);
3377 
3378  BIO_set_mem_eof_return(dtls->read_bio, -1);
3379  BIO_set_mem_eof_return(dtls->write_bio, -1);
3380 
3381  if ((ret=SSL_CTX_use_certificate_file(dtls->ssl_ctx, dtls->rsa, SSL_FILETYPE_PEM)) != 1) {
3382  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));
3383  return SWITCH_STATUS_FALSE;
3384  }
3385 
3386  if ((ret=SSL_CTX_use_PrivateKey_file(dtls->ssl_ctx, dtls->pvt, SSL_FILETYPE_PEM)) != 1) {
3387  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));
3388  return SWITCH_STATUS_FALSE;
3389  }
3390 
3391  if (SSL_CTX_check_private_key(dtls->ssl_ctx) == 0) {
3392  switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(rtp_session->session), SWITCH_LOG_ERROR, "%s DTLS check key failed\n", rtp_type(rtp_session));
3393  return SWITCH_STATUS_FALSE;
3394  }
3395 
3396  if (!zstr(dtls->ca) && switch_file_exists(dtls->ca, rtp_session->pool) == SWITCH_STATUS_SUCCESS
3397  && (ret = SSL_CTX_load_verify_locations(dtls->ssl_ctx, dtls->ca, NULL)) != 1) {
3398  switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(rtp_session->session), SWITCH_LOG_ERROR, "%s DTLS check chain cert failed [%d]\n",
3399  rtp_type(rtp_session) ,
3400  SSL_get_error(dtls->ssl, ret));
3401  return SWITCH_STATUS_FALSE;
3402  }
3403 
3404  dtls->ssl = SSL_new(dtls->ssl_ctx);
3405 
3406  SSL_set_bio(dtls->ssl, dtls->read_bio, dtls->write_bio);
3407  SSL_set_mode(dtls->ssl, SSL_MODE_AUTO_RETRY);
3408  SSL_set_read_ahead(dtls->ssl, 1);
3409  //SSL_set_verify(dtls->ssl, (SSL_VERIFY_PEER | SSL_VERIFY_FAIL_IF_NO_PEER_CERT), cb_verify_peer);
3410 
3411 #ifndef OPENSSL_NO_EC
3412  ecdh = EC_KEY_new_by_curve_name(NID_X9_62_prime256v1);
3413  if (!ecdh) {
3414  return SWITCH_STATUS_FALSE;
3415  }
3416  SSL_set_options(dtls->ssl, SSL_OP_SINGLE_ECDH_USE);
3417  SSL_set_tmp_ecdh(dtls->ssl, ecdh);
3418  EC_KEY_free(ecdh);
3419 #endif
3420 
3421  SSL_set_verify(dtls->ssl, SSL_VERIFY_NONE, NULL);
3422  SSL_set_app_data(dtls->ssl, dtls);
3423 
3424  BIO_ctrl(dtls->read_bio, BIO_CTRL_DGRAM_SET_MTU, 1400, NULL);
3425  BIO_ctrl(dtls->write_bio, BIO_CTRL_DGRAM_SET_MTU, 1400, NULL);
3426  SSL_set_mtu(dtls->ssl, 1400);
3427  BIO_ctrl(dtls->write_bio, BIO_C_SET_BUFF_SIZE, 1400, NULL);
3428  BIO_ctrl(dtls->read_bio, BIO_C_SET_BUFF_SIZE, 1400, NULL);
3429 
3430 
3431 
3432  dtls->local_fp = local_fp;
3433  dtls->remote_fp = remote_fp;
3434  dtls->rtp_session = rtp_session;
3435 
3436  switch_core_cert_expand_fingerprint(remote_fp, remote_fp->str);
3437 
3438  if ((type & DTLS_TYPE_RTP)) {
3439  rtp_session->dtls = dtls;
3440  dtls->sock_output = rtp_session->sock_output;
3441  dtls->remote_addr = rtp_session->remote_addr;
3442  }
3443 
3444  if ((type & DTLS_TYPE_RTCP)) {
3445  rtp_session->rtcp_dtls = dtls;
3446  if (!(type & DTLS_TYPE_RTP)) {
3447  dtls->sock_output = rtp_session->rtcp_sock_output;
3448  dtls->remote_addr = rtp_session->rtcp_remote_addr;
3449  }
3450  }
3451 
3452  if ((type & DTLS_TYPE_SERVER)) {
3453  SSL_set_accept_state(dtls->ssl);
3454  } else {
3455  SSL_set_connect_state(dtls->ssl);
3456  }
3457 
3459 
3460  rtp_session->flags[SWITCH_RTP_FLAG_VIDEO_BREAK] = 1;
3461  switch_rtp_break(rtp_session);
3462 
3463  return SWITCH_STATUS_SUCCESS;
3464 
3465 }
SSL_CTX * ssl_ctx
Definition: switch_rtp.c:262
dtls_fingerprint_t * remote_fp
Definition: switch_rtp.c:267
#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:4452
BIO * write_bio
Definition: switch_rtp.c:265
switch_status_t switch_rtp_del_dtls(switch_rtp_t *rtp_session, dtls_type_t type)
Definition: switch_rtp.c:3232
switch_sockaddr_t * remote_addr
Definition: switch_rtp.c:275
switch_sockaddr_t * remote_addr
Definition: switch_rtp.c:326
BIO * read_bio
Definition: switch_rtp.c:264
char str[MAX_FPSTRLEN]
Definition: switch_core.h:154
#define zstr(x)
Definition: switch_utils.h:281
#define rtp_type(rtp_session)
Definition: switch_rtp.c:513
switch_socket_t * sock_output
Definition: switch_rtp.c:274
#define SWITCH_PATH_SEPARATOR
Definition: switch_types.h:122
uint32_t flags[SWITCH_RTP_FLAG_INVALID]
Definition: switch_rtp.c:372
#define switch_core_alloc(_pool, _mem)
Allocate memory directly from a memory pool.
Definition: switch_core.h:682
struct switch_rtp * rtp_session
Definition: switch_rtp.c:280
int switch_core_cert_expand_fingerprint(dtls_fingerprint_t *fp, const char *str)
switch_dtls_t * dtls
Definition: switch_rtp.c:348
#define dtls_set_state(_dtls, _state)
Definition: switch_rtp.c:2999
#define DTLS_SRTP_FNAME
Definition: switch_core.h:146
switch_directories SWITCH_GLOBAL_dirs
Definition: switch_core.c:60
switch_memory_pool_t * pool
Definition: switch_rtp.c:373
switch_socket_t * rtcp_sock_output
Definition: switch_rtp.c:309
switch_status_t switch_file_exists(const char *filename, switch_memory_pool_t *pool)
Definition: switch_apr.c:496
void switch_rtp_break(switch_rtp_t *rtp_session)
Definition: switch_rtp.c:4385
switch_core_session_t * session
Definition: switch_rtp.c:446
switch_dtls_t * rtcp_dtls
Definition: switch_rtp.c:349
dtls_type_t type
Definition: switch_rtp.c:271
dtls_fingerprint_t * local_fp
Definition: switch_rtp.c:266
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:326
switch_socket_t * sock_output
Definition: switch_rtp.c:309
void switch_rtp_break ( switch_rtp_t rtp_session)

Definition at line 4385 of file switch_rtp.c.

References CF_VIDEO_BREAK, ping_socket(), 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().

4386 {
4387  if (!switch_rtp_ready(rtp_session)) {
4388  return;
4389  }
4390 
4391  if (rtp_session->flags[SWITCH_RTP_FLAG_VIDEO]) {
4392  int ret = 1;
4393 
4394  if (rtp_session->flags[SWITCH_RTP_FLAG_VIDEO_BREAK]) {
4395  rtp_session->flags[SWITCH_RTP_FLAG_VIDEO_BREAK] = 0;
4396  ret = 0;
4397  } else if (rtp_session->session) {
4398  switch_channel_t *channel = switch_core_session_get_channel(rtp_session->session);
4399  if (switch_channel_test_flag(channel, CF_VIDEO_BREAK)) {
4401  ret = 0;
4402  }
4403  }
4404 
4405  if (ret) return;
4406 
4407  switch_rtp_video_refresh(rtp_session);
4408  }
4409 
4410  switch_mutex_lock(rtp_session->flag_mutex);
4411  rtp_session->flags[SWITCH_RTP_FLAG_BREAK] = 1;
4412 
4413  if (rtp_session->flags[SWITCH_RTP_FLAG_NOBLOCK]) {
4414  switch_mutex_unlock(rtp_session->flag_mutex);
4415  return;
4416  }
4417 
4418  if (rtp_session->sock_input) {
4419  ping_socket(rtp_session);
4420  }
4421 
4422  switch_mutex_unlock(rtp_session->flag_mutex);
4423 }
uint8_t switch_rtp_ready(switch_rtp_t *rtp_session)
Test if an RTP session is ready.
Definition: switch_rtp.c:4452
switch_mutex_t * flag_mutex
Definition: switch_rtp.c:407
switch_socket_t * sock_input
Definition: switch_rtp.c:309
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:290
_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:285
uint32_t flags[SWITCH_RTP_FLAG_INVALID]
Definition: switch_rtp.c:372
switch_core_session_t * session
Definition: switch_rtp.c:446
static void ping_socket(switch_rtp_t *rtp_session)
Definition: switch_rtp.c:2832
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:4362
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 3687 of file switch_rtp.c.

References memset(), READ_DEC, READ_INC, 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, WRITE_DEC, and WRITE_INC.

Referenced by switch_core_media_set_codec().

3688 {
3690  int change_timer = 0;
3691 
3692  if (rtp_session->ms_per_packet && rtp_session->ms_per_packet != ms_per_packet) {
3693  change_timer = 1;
3694  }
3695 
3696  switch_rtp_set_interval(rtp_session, ms_per_packet, samples_per_interval);
3697 
3698  if (change_timer && rtp_session->timer_name) {
3699  READ_INC(rtp_session);
3700  WRITE_INC(rtp_session);
3701 
3702  if (rtp_session->timer.timer_interface) {
3703  switch_core_timer_destroy(&rtp_session->timer);
3704  }
3705  if ((status = switch_core_timer_init(&rtp_session->timer,
3706  rtp_session->timer_name, ms_per_packet / 1000,
3707  samples_per_interval, rtp_session->pool)) == SWITCH_STATUS_SUCCESS) {
3708 
3710  "RE-Starting timer [%s] %d bytes per %dms\n", rtp_session->timer_name, samples_per_interval, ms_per_packet / 1000);
3711  } else {
3712 
3713  memset(&rtp_session->timer, 0, sizeof(rtp_session->timer));
3715  "Problem RE-Starting timer [%s] %d bytes per %dms\n", rtp_session->timer_name, samples_per_interval, ms_per_packet / 1000);
3716  }
3717 
3718  WRITE_DEC(rtp_session);
3719  READ_DEC(rtp_session);
3720  }
3721 
3722  return status;
3723 }
#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:62
#define READ_DEC(rtp_session)
Definition: switch_rtp.c:61
#define WRITE_DEC(rtp_session)
Definition: switch_rtp.c:63
switch_timer_interface_t * timer_interface
#define READ_INC(rtp_session)
Definition: switch_rtp.c:60
char * timer_name
Definition: switch_rtp.c:379
switch_status_t switch_core_timer_destroy(switch_timer_t *timer)
Destroy an allocated timer.
switch_memory_pool_t * pool
Definition: switch_rtp.c:373
switch_status_t
Common return values.
switch_timer_t timer
Definition: switch_rtp.c:411
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:3674
switch_core_session_t * session
Definition: switch_rtp.c:446
uint32_t ms_per_packet
Definition: switch_rtp.c:391
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_byte_t switch_rtp_check_auto_adj ( switch_rtp_t rtp_session)

Definition at line 6893 of file switch_rtp.c.

6894 {
6895  return rtp_session->auto_adj_used;
6896 }
switch_byte_t auto_adj_used
Definition: switch_rtp.c:440
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 4747 of file switch_rtp.c.

References FALSE, reset_jitter_seq(), switch_mutex_lock(), switch_mutex_unlock(), SWITCH_RTP_FLAG_DTMF_ON, SWITCH_RTP_FLAG_NOBLOCK, SWITCH_RTP_FLAG_PAUSE, SWITCH_SO_NONBLOCK, and switch_socket_opt_set().

Referenced by do_flush(), handle_ice(), read_rtp_packet(), rtp_common_read(), rtp_common_write(), rtp_flush_read_buffer(), switch_core_media_clear_rtp_flag(), switch_core_media_receive_message(), switch_core_media_resume(), switch_core_media_toggle_hold(), switch_rtp_create(), switch_rtp_disable_vad(), switch_rtp_udptl_mode(), switch_rtp_write_frame(), switch_rtp_write_raw(), and switch_rtp_zerocopy_read_frame().

4748 {
4749 
4750  switch_mutex_lock(rtp_session->flag_mutex);
4751  rtp_session->flags[flag] = 0;
4752  switch_mutex_unlock(rtp_session->flag_mutex);
4753 
4754  if (flag == SWITCH_RTP_FLAG_DTMF_ON) {
4755  rtp_session->stats.inbound.last_processed_seq = 0;
4756  } else if (flag == SWITCH_RTP_FLAG_PAUSE) {
4757  reset_jitter_seq(rtp_session);
4758  } else if (flag == SWITCH_RTP_FLAG_NOBLOCK && rtp_session->sock_input) {
4760  }
4761 }
switch_rtp_numbers_t inbound
Definition: switch_types.h:690
switch_mutex_t * flag_mutex
Definition: switch_rtp.c:407
switch_socket_t * sock_input
Definition: switch_rtp.c:309
switch_status_t switch_mutex_unlock(switch_mutex_t *lock)
Definition: switch_apr.c:290
switch_status_t switch_mutex_lock(switch_mutex_t *lock)
Definition: switch_apr.c:285
uint32_t flags[SWITCH_RTP_FLAG_INVALID]
Definition: switch_rtp.c:372
switch_status_t switch_socket_opt_set(switch_socket_t *sock, int32_t opt, int32_t on)
Definition: switch_apr.c:823
switch_rtp_stats_t stats
Definition: switch_rtp.c:428
#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:1595
void switch_rtp_clear_flags ( switch_rtp_t rtp_session,
switch_rtp_flag_t  flags[SWITCH_RTP_FLAG_INVALID] 
)

Definition at line 4691 of file switch_rtp.c.

References SWITCH_RTP_FLAG_INVALID.

Referenced by switch_core_media_receive_message().

4692 {
4693  int i;
4694 
4695  for(i = 0; i < SWITCH_RTP_FLAG_INVALID; i++) {
4696  if (flags[i]) {
4697  rtp_session->flags[i] = 0;
4698  }
4699  }
4700 }
uint32_t flags[SWITCH_RTP_FLAG_INVALID]
Definition: switch_rtp.c:372
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[],
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
switch_status_t switch_rtp_deactivate_jitter_buffer ( switch_rtp_t rtp_session)

Definition at line 4079 of file switch_rtp.c.

References SWITCH_RTP_FLAG_KILL_JB, switch_rtp_ready(), SWITCH_STATUS_FALSE, and SWITCH_STATUS_SUCCESS.

Referenced by check_jb().

4080 {
4081 
4082  if (!switch_rtp_ready(rtp_session) || !rtp_session->jb) {
4083  return SWITCH_STATUS_FALSE;
4084  }
4085 
4086  rtp_session->flags[SWITCH_RTP_FLAG_KILL_JB]++;
4087 
4088  return SWITCH_STATUS_SUCCESS;
4089 }
uint8_t switch_rtp_ready(switch_rtp_t *rtp_session)
Test if an RTP session is ready.
Definition: switch_rtp.c:4452
uint32_t flags[SWITCH_RTP_FLAG_INVALID]
Definition: switch_rtp.c:372
switch_jb_t * jb
Definition: switch_rtp.c:414
switch_status_t switch_rtp_debug_jitter_buffer ( switch_rtp_t rtp_session,
const char *  name 
)

Definition at line 4126 of file switch_rtp.c.

References switch_jb_debug_level(), switch_rtp_ready(), SWITCH_STATUS_FALSE, and SWITCH_STATUS_SUCCESS.

Referenced by check_jb().

4127 {
4128  int x = 0;
4129 
4130  if (!switch_rtp_ready(rtp_session)) {
4131  return SWITCH_STATUS_FALSE;
4132  }
4133 
4134  if (name) x = atoi(name);
4135  if (x < 0) x = 0;
4136 
4137  if (rtp_session->jb) {
4138  switch_jb_debug_level(rtp_session->jb, x);
4139  } else if (rtp_session->vb) {
4140  switch_jb_debug_level(rtp_session->vb, x);
4141  }
4142 
4143  return SWITCH_STATUS_SUCCESS;
4144 }
uint8_t switch_rtp_ready(switch_rtp_t *rtp_session)
Test if an RTP session is ready.
Definition: switch_rtp.c:4452
switch_jb_t * vb
Definition: switch_rtp.c:415
void switch_jb_debug_level(switch_jb_t *jb, uint8_t level)
switch_jb_t * jb
Definition: switch_rtp.c:414
switch_status_t switch_rtp_del_dtls ( switch_rtp_t rtp_session,
dtls_type_t  type 
)

Definition at line 3232 of file switch_rtp.c.

References DTLS_TYPE_RTCP, DTLS_TYPE_RTP, free_dtls(), switch_jb_reset(), SWITCH_RTP_FLAG_SECURE_RECV, SWITCH_RTP_FLAG_SECURE_SEND, SWITCH_STATUS_FALSE, and SWITCH_STATUS_SUCCESS.

Referenced by switch_rtp_add_dtls().

3233 {
3234 
3235  if (!rtp_session || (!rtp_session->dtls && !rtp_session->rtcp_dtls)) {
3236  return SWITCH_STATUS_FALSE;
3237  }
3238 
3239  if ((type & DTLS_TYPE_RTP)) {
3240  if (rtp_session->dtls && rtp_session->dtls == rtp_session->rtcp_dtls) {
3241  rtp_session->rtcp_dtls = NULL;
3242  }
3243 
3244  if (rtp_session->dtls) {
3245  free_dtls(&rtp_session->dtls);
3246  }
3247 
3248  if (rtp_session->jb) {
3249  switch_jb_reset(rtp_session->jb);
3250  }
3251 
3252  if (rtp_session->vb) {
3253  switch_jb_reset(rtp_session->vb);
3254  }
3255 
3256  if (rtp_session->vbw) {
3257  switch_jb_reset(rtp_session->vbw);
3258  }
3259 
3260  }
3261 
3262  if ((type & DTLS_TYPE_RTCP) && rtp_session->rtcp_dtls) {
3263  free_dtls(&rtp_session->rtcp_dtls);
3264  }
3265 
3266 
3267 #ifdef ENABLE_SRTP
3268  if (rtp_session->flags[SWITCH_RTP_FLAG_SECURE_SEND]) {
3269  int x;
3270  for(x = 0; x < 2; x++) {
3271  if (rtp_session->send_ctx[x]) {
3272  srtp_dealloc(rtp_session->send_ctx[x]);
3273  rtp_session->send_ctx[x] = NULL;
3274  }
3275  }
3276  rtp_session->flags[SWITCH_RTP_FLAG_SECURE_SEND] = 0;
3277  }
3278 
3279  if (rtp_session->flags[SWITCH_RTP_FLAG_SECURE_RECV]) {
3280  int x;
3281  for (x = 0; x < 2; x++) {
3282  if (rtp_session->recv_ctx[x]) {
3283  srtp_dealloc(rtp_session->recv_ctx[x]);
3284  rtp_session->recv_ctx[x] = NULL;
3285  }
3286  }
3287  rtp_session->flags[SWITCH_RTP_FLAG_SECURE_RECV] = 0;
3288  }
3289 #endif
3290 
3291  return SWITCH_STATUS_SUCCESS;
3292 }
static void free_dtls(switch_dtls_t **dtlsp)
Definition: switch_rtp.c:3124
switch_jb_t * vbw
Definition: switch_rtp.c:416
srtp_ctx_t * send_ctx[2]
Definition: switch_rtp.c:335
uint32_t flags[SWITCH_RTP_FLAG_INVALID]
Definition: switch_rtp.c:372
srtp_ctx_t * recv_ctx[2]
Definition: switch_rtp.c:336
switch_dtls_t * dtls
Definition: switch_rtp.c:348
switch_jb_t * vb
Definition: switch_rtp.c:415
switch_jb_t * jb
Definition: switch_rtp.c:414
void switch_jb_reset(switch_jb_t *jb)
switch_dtls_t * rtcp_dtls
Definition: switch_rtp.c:349
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 6911 of file switch_rtp.c.

References SWITCH_CHANNEL_SESSION_LOG, SWITCH_LOG_DEBUG, switch_log_printf(), switch_mutex_lock(), switch_mutex_unlock(), switch_queue_trypop(), switch_rtp_ready(), and SWITCH_STATUS_SUCCESS.

Referenced by switch_core_media_read_frame().

6912 {
6913  switch_size_t bytes = 0;
6914  switch_dtmf_t *_dtmf = NULL;
6915  void *pop;
6916 
6917  if (!switch_rtp_ready(rtp_session)) {
6918  return bytes;
6919  }
6920 
6921  switch_mutex_lock(rtp_session->dtmf_data.dtmf_mutex);
6922  if (switch_queue_trypop(rtp_session->dtmf_data.dtmf_inqueue, &pop) == SWITCH_STATUS_SUCCESS) {
6923 
6924  _dtmf = (switch_dtmf_t *) pop;
6925  *dtmf = *_dtmf;
6926  switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(rtp_session->session), SWITCH_LOG_DEBUG, "RTP RECV DTMF %c:%d\n", dtmf->digit, dtmf->duration);
6927  bytes++;
6928  free(pop);
6929  }
6931 
6932  return bytes;
6933 }
#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:4452
switch_status_t switch_queue_trypop(switch_queue_t *queue, void **data)
Definition: switch_apr.c:1140
uint32_t duration
Definition: switch_types.h:288
struct switch_rtp_rfc2833_data dtmf_data
Definition: switch_rtp.c:403
switch_status_t switch_mutex_unlock(switch_mutex_t *lock)
Definition: switch_apr.c:290
switch_queue_t * dtmf_inqueue
Definition: switch_rtp.c:233
switch_status_t switch_mutex_lock(switch_mutex_t *lock)
Definition: switch_apr.c:285
switch_mutex_t * dtmf_mutex
Definition: switch_rtp.c:234
uintptr_t switch_size_t
switch_core_session_t * session
Definition: switch_rtp.c:446
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.
void switch_rtp_destroy ( switch_rtp_t **  rtp_session)

Destroy an RTP session.

Parameters
rtp_sessionan RTP session to destroy

Definition at line 4491 of file switch_rtp.c.

References free_dtls(), READ_DEC, READ_INC, switch_core_timer_destroy(), switch_jb_destroy(), switch_mutex_lock(), switch_mutex_unlock(), switch_queue_trypop(), switch_rtp_disable_vad(), SWITCH_RTP_FLAG_PROXY_MEDIA, 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, SWITCH_ZRTP_FLAG_SECURE_RECV, SWITCH_ZRTP_FLAG_SECURE_SEND, WRITE_DEC, and WRITE_INC.

Referenced by switch_core_media_deactivate_rtp().

4492 {
4493  void *pop;
4494  switch_socket_t *sock;
4495 #ifdef ENABLE_SRTP
4496  int x;
4497 #endif
4498 
4499  if (!rtp_session || !*rtp_session || !(*rtp_session)->ready) {
4500  return;
4501  }
4502 
4503  (*rtp_session)->flags[SWITCH_RTP_FLAG_SHUTDOWN] = 1;
4504 
4505  READ_INC((*rtp_session));
4506  WRITE_INC((*rtp_session));
4507 
4508  (*rtp_session)->ready = 0;
4509 
4510  READ_DEC((*rtp_session));
4511  WRITE_DEC((*rtp_session));
4512 
4513  if ((*rtp_session)->flags[SWITCH_RTP_FLAG_VAD]) {
4514  switch_rtp_disable_vad(*rtp_session);
4515  }
4516 
4517  switch_mutex_lock((*rtp_session)->flag_mutex);
4518 
4519  switch_rtp_kill_socket(*rtp_session);
4520 
4521  while (switch_queue_trypop((*rtp_session)->dtmf_data.dtmf_inqueue, &pop) == SWITCH_STATUS_SUCCESS) {
4522  switch_safe_free(pop);
4523  }
4524 
4525  while (switch_queue_trypop((*rtp_session)->dtmf_data.dtmf_queue, &pop) == SWITCH_STATUS_SUCCESS) {
4526  switch_safe_free(pop);
4527  }
4528 
4529  if ((*rtp_session)->jb) {
4530  switch_jb_destroy(&(*rtp_session)->jb);
4531  }
4532 
4533  if ((*rtp_session)->vb) {
4534  switch_jb_destroy(&(*rtp_session)->vb);
4535  }
4536 
4537  if ((*rtp_session)->vbw) {
4538  switch_jb_destroy(&(*rtp_session)->vbw);
4539  }
4540 
4541  if ((*rtp_session)->dtls && (*rtp_session)->dtls == (*rtp_session)->rtcp_dtls) {
4542  (*rtp_session)->rtcp_dtls = NULL;
4543  }
4544 
4545  if ((*rtp_session)->dtls) {
4546  free_dtls(&(*rtp_session)->dtls);
4547  }
4548 
4549  if ((*rtp_session)->rtcp_dtls) {
4550  free_dtls(&(*rtp_session)->rtcp_dtls);
4551  }
4552 
4553 
4554  sock = (*rtp_session)->sock_input;
4555  (*rtp_session)->sock_input = NULL;
4556  switch_socket_close(sock);
4557 
4558  if ((*rtp_session)->sock_output != sock) {
4559  sock = (*rtp_session)->sock_output;
4560  (*rtp_session)->sock_output = NULL;
4561  switch_socket_close(sock);
4562  }
4563 
4564  if ((sock = (*rtp_session)->rtcp_sock_input)) {
4565  (*rtp_session)->rtcp_sock_input = NULL;
4566  switch_socket_close(sock);
4567 
4568  if ((*rtp_session)->rtcp_sock_output && (*rtp_session)->rtcp_sock_output != sock) {
4569  if ((sock = (*rtp_session)->rtcp_sock_output)) {
4570  (*rtp_session)->rtcp_sock_output = NULL;
4571  switch_socket_close(sock);
4572  }
4573  }
4574  }
4575 
4576 #ifdef ENABLE_SRTP
4577  if ((*rtp_session)->flags[SWITCH_RTP_FLAG_SECURE_SEND]) {
4578  for(x = 0; x < 2; x++) {
4579  if ((*rtp_session)->send_ctx[x]) {
4580  srtp_dealloc((*rtp_session)->send_ctx[x]);
4581  (*rtp_session)->send_ctx[x] = NULL;
4582  }
4583  }
4584  (*rtp_session)->flags[SWITCH_RTP_FLAG_SECURE_SEND] = 0;
4585  }
4586 
4587  if ((*rtp_session)->flags[SWITCH_RTP_FLAG_SECURE_RECV]) {
4588  for (x = 0; x < 2; x++) {
4589  if ((*rtp_session)->recv_ctx[x]) {
4590  srtp_dealloc((*rtp_session)->recv_ctx[x]);
4591  (*rtp_session)->recv_ctx[x] = NULL;
4592  }
4593  }
4594  (*rtp_session)->flags[SWITCH_RTP_FLAG_SECURE_RECV] = 0;
4595  }
4596 #endif
4597 
4598 #ifdef ENABLE_ZRTP
4599  /* ZRTP */
4600  if (zrtp_on && !(*rtp_session)->flags[SWITCH_RTP_FLAG_PROXY_MEDIA]) {
4601 
4602  if ((*rtp_session)->zrtp_stream != NULL) {
4603  zrtp_stream_stop((*rtp_session)->zrtp_stream);
4604  }
4605 
4606  if ((*rtp_session)->flags[SWITCH_ZRTP_FLAG_SECURE_SEND]) {
4607  (*rtp_session)->flags[SWITCH_ZRTP_FLAG_SECURE_SEND] = 0;
4608  }
4609 
4610  if ((*rtp_session)->flags[SWITCH_ZRTP_FLAG_SECURE_RECV]) {
4611  (*rtp_session)->flags[SWITCH_ZRTP_FLAG_SECURE_RECV] = 0;
4612  }
4613 
4614  if ((*rtp_session)->zrtp_session) {
4615  zrtp_session_down((*rtp_session)->zrtp_session);
4616  (*rtp_session)->zrtp_session = NULL;
4617  }
4618  }
4619 #endif
4620  if ((*rtp_session)->timer.timer_interface) {
4621  switch_core_timer_destroy(&(*rtp_session)->timer);
4622  }
4623 
4624  switch_rtp_release_port((*rtp_session)->rx_host, (*rtp_session)->rx_port);
4625  switch_mutex_unlock((*rtp_session)->flag_mutex);
4626 
4627  return;
4628 }
static void free_dtls(switch_dtls_t **dtlsp)
Definition: switch_rtp.c:3124
#define WRITE_INC(rtp_session)
Definition: switch_rtp.c:62
switch_status_t switch_queue_trypop(switch_queue_t *queue, void **data)
Definition: switch_apr.c:1140
switch_status_t switch_jb_destroy(switch_jb_t **jbp)
#define READ_DEC(rtp_session)
Definition: switch_rtp.c:61
switch_status_t switch_mutex_unlock(switch_mutex_t *lock)
Definition: switch_apr.c:290
#define WRITE_DEC(rtp_session)
Definition: switch_rtp.c:63
uint8_t ready
Definition: switch_rtp.c:412
switch_status_t switch_mutex_lock(switch_mutex_t *lock)
Definition: switch_apr.c:285
switch_status_t switch_rtp_disable_vad(switch_rtp_t *rtp_session)
Disable VAD on an RTP Session.
Definition: switch_rtp.c:7654
#define switch_safe_free(it)
Free a pointer and set it to NULL unless it already is NULL.
Definition: switch_utils.h:789
#define READ_INC(rtp_session)
Definition: switch_rtp.c:60
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:714
void switch_rtp_release_port(const char *ip, switch_port_t port)
Definition: switch_rtp.c:2415
void switch_rtp_kill_socket(switch_rtp_t *rtp_session)
Kill the socket on an existing RTP session.
Definition: switch_rtp.c:4425
struct apr_socket_t switch_socket_t
Definition: switch_apr.h:1026
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 7654 of file switch_rtp.c.

References switch_core_codec_destroy(), switch_rtp_clear_flag(), SWITCH_RTP_FLAG_VAD, SWITCH_STATUS_FALSE, SWITCH_STATUS_GENERR, and SWITCH_STATUS_SUCCESS.

Referenced by switch_rtp_destroy().

7655 {
7656 
7657  if (!rtp_session) {
7658  return SWITCH_STATUS_FALSE;
7659  }
7660 
7661  if (!rtp_session->flags[SWITCH_RTP_FLAG_VAD]) {
7662  return SWITCH_STATUS_GENERR;
7663  }
7666  return SWITCH_STATUS_SUCCESS;
7667 }
struct switch_rtp_vad_data vad_data
Definition: switch_rtp.c:402
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:192
uint32_t flags[SWITCH_RTP_FLAG_INVALID]
Definition: switch_rtp.c:372
void switch_rtp_clear_flag(switch_rtp_t *rtp_session, switch_rtp_flag_t flag)
Clear an RTP Flag.
Definition: switch_rtp.c:4747
dtls_state_t switch_rtp_dtls_state ( switch_rtp_t rtp_session,
dtls_type_t  type 
)

Definition at line 3215 of file switch_rtp.c.

References DS_OFF, DTLS_TYPE_RTCP, and DTLS_TYPE_RTP.

Referenced by check_engine().

3216 {
3217  if (!rtp_session || (!rtp_session->dtls && !rtp_session->rtcp_dtls)) {
3218  return DS_OFF;
3219  }
3220 
3221  if ((type == DTLS_TYPE_RTP) && rtp_session->dtls) {
3222  return rtp_session->dtls->state;
3223  }
3224 
3225  if ((type == DTLS_TYPE_RTCP) && rtp_session->rtcp_dtls) {
3226  return rtp_session->rtcp_dtls->state;
3227  }
3228 
3229  return DS_OFF;
3230 }
dtls_state_t state
Definition: switch_rtp.c:268
switch_dtls_t * dtls
Definition: switch_rtp.c:348
switch_dtls_t * rtcp_dtls
Definition: switch_rtp.c:349
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 7669 of file switch_rtp.c.

References memset(), 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_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_time_now(), switch_true(), SWITCH_VAD_FLAG_CNG, SWITCH_VAD_FLAG_TALKING, VAD_FIRE_NOT_TALK, and VAD_FIRE_TALK.

Referenced by switch_core_media_activate_rtp().

7671 {
7672  if (!switch_rtp_ready(rtp_session)) {
7673  return SWITCH_STATUS_FALSE;
7674  }
7675 
7676  if (rtp_session->flags[SWITCH_RTP_FLAG_VAD]) {
7677  return SWITCH_STATUS_GENERR;
7678  }
7679 
7680  memset(&rtp_session->vad_data, 0, sizeof(rtp_session->vad_data));
7681 
7682  if (switch_true(switch_channel_get_variable(switch_core_session_get_channel(rtp_session->session), "fire_talk_events"))) {
7683  rtp_session->vad_data.fire_events |= VAD_FIRE_TALK;
7684  }
7685 
7686  if (switch_true(switch_channel_get_variable(switch_core_session_get_channel(rtp_session->session), "fire_not_talk_events"))) {
7687  rtp_session->vad_data.fire_events |= VAD_FIRE_NOT_TALK;
7688  }
7689 
7690 
7691  if (switch_core_codec_init(&rtp_session->vad_data.vad_codec,
7692  codec->implementation->iananame,
7693  codec->implementation->modname,
7694  NULL,
7696  codec->implementation->microseconds_per_packet / 1000,
7699  switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(rtp_session->session), SWITCH_LOG_ERROR, "Can't load codec?\n");
7700  return SWITCH_STATUS_FALSE;
7701  }
7702  switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(rtp_session->session), SWITCH_LOG_DEBUG, "Activate VAD codec %s %dms\n", codec->implementation->iananame,
7703  codec->implementation->microseconds_per_packet / 1000);
7704  rtp_session->vad_data.diff_level = 400;
7705  rtp_session->vad_data.hangunder = 15;
7706  rtp_session->vad_data.hangover = 40;
7707  rtp_session->vad_data.bg_len = 5;
7708  rtp_session->vad_data.bg_count = 5;
7709  rtp_session->vad_data.bg_level = 300;
7710  rtp_session->vad_data.read_codec = codec;
7711  rtp_session->vad_data.session = session;
7712  rtp_session->vad_data.flags = flags;
7713  rtp_session->vad_data.cng_freq = 50;
7714  rtp_session->vad_data.ts = 1;
7715  rtp_session->vad_data.start = 0;
7716  rtp_session->vad_data.next_scan = switch_epoch_time_now(NULL);
7717  rtp_session->vad_data.scan_freq = 0;
7718  if (switch_test_flag(&rtp_session->vad_data, SWITCH_VAD_FLAG_TALKING)) {
7719  rtp_session->vad_data.start_talking = switch_time_now();
7720  }
7723  return SWITCH_STATUS_SUCCESS;
7724 }
#define SWITCH_CHANNEL_SESSION_LOG(x)
#define switch_set_flag(obj, flag)
Set a flag on an arbitrary object.
Definition: switch_utils.h:631
uint8_t switch_rtp_ready(switch_rtp_t *rtp_session)
Test if an RTP session is ready.
Definition: switch_rtp.c:4452
switch_core_session_t * session
struct switch_rtp_vad_data vad_data
Definition: switch_rtp.c:402
switch_vad_flag_t flags
Definition: switch_rtp.c:204
static int switch_true(const char *expr)
Evaluate the truthfullness of a string expression.
Definition: switch_utils.h:450
switch_codec_t vad_codec
Definition: switch_rtp.c:192
switch_core_session_t * session
Definition: switch_rtp.c:191
_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:372
#define switch_channel_get_variable(_c, _v)
switch_time_t start_talking
Definition: switch_rtp.c:210
#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:1602
switch_memory_pool_t * pool
Definition: switch_rtp.c:373
void switch_rtp_set_flag(switch_rtp_t *rtp_session, switch_rtp_flag_t flag)
Set an RTP Flag.
Definition: switch_rtp.c:4702
switch_core_session_t * session
Definition: switch_rtp.c:446
time_t switch_epoch_time_now(time_t *t)
Get the current epoch time.
Definition: switch_time.c:321
#define switch_test_flag(obj, flag)
Test for the existance of a flag on an arbitary object.
Definition: switch_utils.h:624
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_time_t switch_time_now(void)
Definition: switch_apr.c:302
memset(buf, 0, buflen)
switch_codec_t * read_codec
Definition: switch_rtp.c:193
void switch_rtp_flush ( switch_rtp_t rtp_session)

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

4332 {
4333  if (!switch_rtp_ready(rtp_session)) {
4334  return;
4335  }
4336 
4338 }
uint8_t switch_rtp_ready(switch_rtp_t *rtp_session)
Test if an RTP session is ready.
Definition: switch_rtp.c:4452
void switch_rtp_set_flag(switch_rtp_t *rtp_session, switch_rtp_flag_t flag)
Set an RTP Flag.
Definition: switch_rtp.c:4702
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 4650 of file switch_rtp.c.

4651 {
4652  return rtp_session->payload;
4653 }
switch_payload_t payload
Definition: switch_rtp.c:359
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 4640 of file switch_rtp.c.

4641 {
4642  return rtp_session->samples_per_interval;
4643 }
uint32_t samples_per_interval
Definition: switch_rtp.c:386
switch_jb_t* switch_rtp_get_jitter_buffer ( switch_rtp_t rtp_session)

Definition at line 4050 of file switch_rtp.c.

References switch_rtp_ready().

Referenced by switch_core_media_get_jb().

4051 {
4052  if (!switch_rtp_ready(rtp_session) || !rtp_session->jb) {
4053  return NULL;
4054  }
4055 
4056  return rtp_session->jb;
4057 }
uint8_t switch_rtp_ready(switch_rtp_t *rtp_session)
Test if an RTP session is ready.
Definition: switch_rtp.c:4452
switch_jb_t * jb
Definition: switch_rtp.c:414
switch_timer_t* switch_rtp_get_media_timer ( switch_rtp_t rtp_session)

Definition at line 4036 of file switch_rtp.c.

References switch_core_timer_sync(), and SWITCH_RTP_FLAG_VIDEO.

Referenced by switch_core_media_get_timer().

4037 {
4038 
4039  if (rtp_session && rtp_session->timer.timer_interface) {
4040  if (rtp_session->flags[SWITCH_RTP_FLAG_VIDEO]) {
4041  switch_core_timer_sync(&rtp_session->timer);
4042  }
4043  return &rtp_session->timer;
4044  }
4045 
4046  return NULL;
4047 }
switch_timer_interface_t * timer_interface
uint32_t flags[SWITCH_RTP_FLAG_INVALID]
Definition: switch_rtp.c:372
switch_timer_t timer
Definition: switch_rtp.c:411
switch_status_t switch_core_timer_sync(switch_timer_t *timer)
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 8099 of file switch_rtp.c.

8100 {
8101  return rtp_session->private_data;
8102 }
void * private_data
Definition: switch_rtp.c:361
void switch_rtp_get_random ( void *  buf,
uint32_t  len 
)

Definition at line 2338 of file switch_rtp.c.

References switch_stun_random_string().

Referenced by switch_core_media_build_crypto().

2339 {
2340 #ifdef ENABLE_SRTP
2341  crypto_get_random(buf, len);
2342 #else
2343  switch_stun_random_string(buf, len, NULL);
2344 #endif
2345 }
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
char* switch_rtp_get_remote_host ( switch_rtp_t rtp_session)

Definition at line 2822 of file switch_rtp.c.

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

2823 {
2824  return zstr(rtp_session->remote_host_str) ? "0.0.0.0" : rtp_session->remote_host_str;
2825 }
char * remote_host_str
Definition: switch_rtp.c:381
#define zstr(x)
Definition: switch_utils.h:281
switch_port_t switch_rtp_get_remote_port ( switch_rtp_t rtp_session)
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 4635 of file switch_rtp.c.

4636 {
4637  return rtp_session->sock_input;
4638 }
switch_socket_t * sock_input
Definition: switch_rtp.c:309
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 8089 of file switch_rtp.c.

Referenced by switch_core_media_activate_rtp().

8090 {
8091  return rtp_session->ssrc;
8092 }
uint32_t ssrc
Definition: switch_rtp.c:354
switch_rtp_stats_t* switch_rtp_get_stats ( switch_rtp_t rtp_session,
switch_memory_pool_t pool 
)

Definition at line 7928 of file switch_rtp.c.

References do_mos(), switch_rtp_stats_t::inbound, switch_rtp_numbers_t::largest_jb_size, switch_core_alloc, SWITCH_FALSE, switch_jb_get_frames(), switch_mutex_lock(), and switch_mutex_unlock().

Referenced by switch_core_media_get_stats().

7929 {
7930  switch_rtp_stats_t *s;
7931 
7932  if (!rtp_session) {
7933  return NULL;
7934  }
7935 
7936  switch_mutex_lock(rtp_session->flag_mutex);
7937  if (pool) {
7938  s = switch_core_alloc(pool, sizeof(*s));
7939  *s = rtp_session->stats;
7940  } else {
7941  s = &rtp_session->stats;
7942  }
7943 
7944  if (rtp_session->jb) {
7945  switch_jb_get_frames(rtp_session->jb, NULL, NULL, NULL, (uint32_t *)&s->inbound.largest_jb_size);
7946  }
7947 
7948  do_mos(rtp_session, SWITCH_FALSE);
7949 
7950  switch_mutex_unlock(rtp_session->flag_mutex);
7951 
7952  return s;
7953 }
switch_rtp_numbers_t inbound
Definition: switch_types.h:690
switch_mutex_t * flag_mutex
Definition: switch_rtp.c:407
switch_size_t largest_jb_size
Definition: switch_types.h:637
switch_memory_pool_t * pool
switch_status_t switch_mutex_unlock(switch_mutex_t *lock)
Definition: switch_apr.c:290
switch_status_t switch_mutex_lock(switch_mutex_t *lock)
Definition: switch_apr.c:285
#define switch_core_alloc(_pool, _mem)
Allocate memory directly from a memory pool.
Definition: switch_core.h:682
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:428
switch_jb_t * jb
Definition: switch_rtp.c:414
static void do_mos(switch_rtp_t *rtp_session, int force)
Definition: switch_rtp.c:1521
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 4091 of file switch_rtp.c.

References switch_jb_get_frames(), and SWITCH_STATUS_FALSE.

Referenced by check_jb_sync().

4092 {
4093 
4094  if (rtp_session->vb) {
4095  return switch_jb_get_frames(rtp_session->vb, min_frame_len, max_frame_len, cur_frame_len, highest_frame_len);
4096  }
4097 
4098  return SWITCH_STATUS_FALSE;
4099 }
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:415
int switch_rtp_has_dtls ( void  )

Definition at line 3207 of file switch_rtp.c.

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

3207  {
3208 #ifdef HAVE_OPENSSL_DTLS_SRTP
3209  return 1;
3210 #else
3211  return 0;
3212 #endif
3213 }
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 6898 of file switch_rtp.c.

References switch_mutex_lock(), switch_mutex_unlock(), switch_queue_size(), and switch_rtp_ready().

Referenced by switch_core_media_read_frame().

6899 {
6900  switch_size_t has = 0;
6901 
6902  if (switch_rtp_ready(rtp_session)) {
6903  switch_mutex_lock(rtp_session->dtmf_data.dtmf_mutex);
6904  has = switch_queue_size(rtp_session->dtmf_data.dtmf_inqueue);
6906  }
6907 
6908  return has;
6909 }
unsigned int switch_queue_size(switch_queue_t *queue)
Definition: switch_apr.c:1114
uint8_t switch_rtp_ready(switch_rtp_t *rtp_session)
Test if an RTP session is ready.
Definition: switch_rtp.c:4452
struct switch_rtp_rfc2833_data dtmf_data
Definition: switch_rtp.c:403
switch_status_t switch_mutex_unlock(switch_mutex_t *lock)
Definition: switch_apr.c:290
switch_queue_t * dtmf_inqueue
Definition: switch_rtp.c:233
switch_status_t switch_mutex_lock(switch_mutex_t *lock)
Definition: switch_apr.c:285
switch_mutex_t * dtmf_mutex
Definition: switch_rtp.c:234
uintptr_t switch_size_t
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 1442 of file switch_rtp.c.

References switch_directories::db_dir, port_lock, SSHF_NO_DEL, SSHF_NONE, SWITCH_CHANNEL_LOG, switch_core_get_variable_pdup(), switch_core_hash_init, switch_core_set_variable(), switch_epoch_time_now(), SWITCH_GLOBAL_dirs, SWITCH_LOG_CRIT, switch_log_printf(), switch_mutex_init(), SWITCH_MUTEX_NESTED, SWITCH_PATH_SEPARATOR, switch_scheduler_add_task(), switch_snprintf(), and switch_true().

Referenced by switch_core_init().

1443 {
1444 #ifdef ENABLE_ZRTP
1445  const char *zid_string = switch_core_get_variable_pdup("switch_serial", pool);
1446  const char *zrtp_enabled = switch_core_get_variable_pdup("zrtp_enabled", pool);
1447  zrtp_config_t zrtp_config;
1448  char zrtp_cache_path[256] = "";
1449  zrtp_on = zrtp_enabled ? switch_true(zrtp_enabled) : 0;
1450 #endif
1451  if (global_init) {
1452  return;
1453  }
1455 #ifdef ENABLE_ZRTP
1456  if (zrtp_on) {
1457  uint32_t cache_len;
1458  zrtp_config_defaults(&zrtp_config);
1459  strcpy(zrtp_config.client_id, "FreeSWITCH");
1460  zrtp_config.is_mitm = 1;
1461  zrtp_config.lic_mode = ZRTP_LICENSE_MODE_ACTIVE;
1462  switch_snprintf(zrtp_cache_path, sizeof(zrtp_cache_path), "%s%szrtp.dat", SWITCH_GLOBAL_dirs.db_dir, SWITCH_PATH_SEPARATOR);
1463  cache_len=(uint32_t)strlen(zrtp_cache_path);
1464  ZSTR_SET_EMPTY(zrtp_config.def_cache_path);
1465  zrtp_config.def_cache_path.length = cache_len > zrtp_config.def_cache_path.max_length ? zrtp_config.def_cache_path.max_length : (uint16_t)cache_len;
1466  strncpy(zrtp_config.def_cache_path.buffer, zrtp_cache_path, zrtp_config.def_cache_path.max_length);
1467  zrtp_config.cb.event_cb.on_zrtp_protocol_event = (void (*)(zrtp_stream_t*,zrtp_protocol_event_t))zrtp_event_callback;
1468  zrtp_config.cb.misc_cb.on_send_packet = zrtp_send_rtp_callback;
1469  zrtp_config.cb.event_cb.on_zrtp_security_event = (void (*)(zrtp_stream_t*,zrtp_security_event_t))zrtp_event_callback;
1470  zrtp_log_set_log_engine((zrtp_log_engine *) zrtp_logger);
1471  zrtp_log_set_level(4);
1472  if (zrtp_status_ok == zrtp_init(&zrtp_config, &zrtp_global)) {
1473  memcpy(zid, zid_string, 12);
1474  switch_scheduler_add_task(switch_epoch_time_now(NULL) + 900, zrtp_cache_save_callback, "zrtp_cache_save", "core", 0, NULL,
1476  } else {
1477  switch_core_set_variable("zrtp_enabled", NULL);
1478  zrtp_on = 0;
1479  switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CRIT, "ZRTP init failed!\n");
1480  }
1481  }
1482 #endif
1483 #ifdef ENABLE_SRTP
1484  srtp_init();
1485 #endif
1487  global_init = 1;
1488 }
#define SWITCH_CHANNEL_LOG
#define switch_core_hash_init(_hash)
Definition: switch_core.h:1390
char * switch_core_get_variable_pdup(_In_z_ const char *varname, switch_memory_pool_t *pool)
switch_memory_pool_t * pool
void switch_core_set_variable(_In_z_ const char *varname, _In_opt_z_ const char *value)
Add a global variable to the core.
int switch_snprintf(_Out_z_cap_(len) char *buf, _In_ switch_size_t len, _In_z_ _Printf_format_string_ const char *format,...)
static int switch_true(const char *expr)
Evaluate the truthfullness of a string expression.
Definition: switch_utils.h:450
uint32_t switch_scheduler_add_task(time_t task_runtime, switch_scheduler_func_t func, const char *desc, const char *group, uint32_t cmd_id, void *cmd_arg, switch_scheduler_flag_t flags)
Schedule a task in the future.
static int global_init
Definition: switch_rtp.c:766
#define SWITCH_MUTEX_NESTED
Definition: switch_apr.h:318
#define SWITCH_PATH_SEPARATOR
Definition: switch_types.h:122
static switch_mutex_t * port_lock
Definition: switch_rtp.c:83
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:270
switch_directories SWITCH_GLOBAL_dirs
Definition: switch_core.c:60
time_t switch_epoch_time_now(time_t *t)
Get the current epoch time.
Definition: switch_time.c:321
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.
void switch_rtp_intentional_bugs ( switch_rtp_t rtp_session,
switch_rtp_bug_flag_t  bugs 
)

Definition at line 2467 of file switch_rtp.c.

References RTP_BUG_START_SEQ_AT_ZERO.

Referenced by switch_core_media_activate_rtp().

2468 {
2469  rtp_session->rtp_bugs = bugs;
2470 
2471  if ((rtp_session->rtp_bugs & RTP_BUG_START_SEQ_AT_ZERO)) {
2472  rtp_session->seq = 0;
2473  }
2474 
2475 }
uint16_t seq
Definition: switch_rtp.c:353
switch_rtp_bug_flag_t rtp_bugs
Definition: switch_rtp.c:427
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 4425 of file switch_rtp.c.

References ping_socket(), 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().

4426 {
4427  switch_assert(rtp_session != NULL);
4428  switch_mutex_lock(rtp_session->flag_mutex);
4429  if (rtp_session->flags[SWITCH_RTP_FLAG_IO]) {
4430  rtp_session->flags[SWITCH_RTP_FLAG_IO] = 0;
4431  if (rtp_session->sock_input) {
4432  ping_socket(rtp_session);
4434  }
4435  if (rtp_session->sock_output && rtp_session->sock_output != rtp_session->sock_input) {
4437  }
4438 
4439  if (rtp_session->flags[SWITCH_RTP_FLAG_ENABLE_RTCP]) {
4440  if (rtp_session->rtcp_sock_input) {
4441  ping_socket(rtp_session);
4443  }
4444  if (rtp_session->rtcp_sock_output && rtp_session->rtcp_sock_output != rtp_session->rtcp_sock_input) {
4446  }
4447  }
4448  }
4449  switch_mutex_unlock(rtp_session->flag_mutex);
4450 }
switch_mutex_t * flag_mutex
Definition: switch_rtp.c:407
switch_socket_t * sock_input
Definition: switch_rtp.c:309
switch_socket_t * rtcp_sock_input
Definition: switch_rtp.c:309
switch_status_t switch_mutex_unlock(switch_mutex_t *lock)
Definition: switch_apr.c:290
switch_status_t switch_mutex_lock(switch_mutex_t *lock)
Definition: switch_apr.c:285
uint32_t flags[SWITCH_RTP_FLAG_INVALID]
Definition: switch_rtp.c:372
switch_socket_t * rtcp_sock_output
Definition: switch_rtp.c:309
switch_status_t switch_socket_shutdown(switch_socket_t *sock, switch_shutdown_how_e how)
Definition: switch_apr.c:709
static void ping_socket(switch_rtp_t *rtp_session)
Definition: switch_rtp.c:2832
#define switch_assert(expr)
switch_socket_t * sock_output
Definition: switch_rtp.c:309
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[],
char *  timer_name,
const char **  err,
switch_memory_pool_t pool 
)

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
Returns
the new RTP session or NULL on failure

Referenced by switch_core_media_activate_rtp().

switch_status_t switch_rtp_pause_jitter_buffer ( switch_rtp_t rtp_session,
switch_bool_t  pause 
)

Definition at line 4059 of file switch_rtp.c.

References switch_jb_reset(), switch_rtp_ready(), SWITCH_STATUS_FALSE, and SWITCH_STATUS_SUCCESS.

Referenced by check_jb(), and switch_core_media_receive_message().

4060 {
4061 
4062  if (!switch_rtp_ready(rtp_session) || !rtp_session->jb) {
4063  return SWITCH_STATUS_FALSE;
4064  }
4065 
4066  if (!!pause == !!rtp_session->pause_jb) {
4067  return SWITCH_STATUS_FALSE;
4068  }
4069 
4070  if (rtp_session->pause_jb && !pause) {
4071  switch_jb_reset(rtp_session->jb);
4072  }
4073 
4074  rtp_session->pause_jb = pause ? 1 : 0;
4075 
4076  return SWITCH_STATUS_SUCCESS;
4077 }
uint8_t switch_rtp_ready(switch_rtp_t *rtp_session)
Test if an RTP session is ready.
Definition: switch_rtp.c:4452
switch_jb_t * jb
Definition: switch_rtp.c:414
void switch_jb_reset(switch_jb_t *jb)
uint8_t pause_jb
Definition: switch_rtp.c:441
void switch_rtp_ping ( switch_rtp_t rtp_session)

Definition at line 2333 of file switch_rtp.c.

References check_rtcp_and_ice().

2334 {
2335  check_rtcp_and_ice(rtp_session);
2336 }
static int check_rtcp_and_ice(switch_rtp_t *rtp_session)
Definition: switch_rtp.c:1956
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 6935 of file switch_rtp.c.

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

6936 {
6937 
6938  switch_dtmf_t *rdigit;
6939 
6940  if (!switch_rtp_ready(rtp_session)) {
6941  return SWITCH_STATUS_FALSE;
6942  }
6943 
6944  if ((rdigit = malloc(sizeof(*rdigit))) != 0) {
6945  *rdigit = *dtmf;
6946  if (rdigit->duration < switch_core_min_dtmf_duration(0)) {
6948  }
6949 
6950  if ((switch_queue_trypush(rtp_session->dtmf_data.dtmf_queue, rdigit)) != SWITCH_STATUS_SUCCESS) {
6951  free(rdigit);
6952  return SWITCH_STATUS_FALSE;
6953  }
6954  } else {
6955  abort();
6956  }
6957 
6958  return SWITCH_STATUS_SUCCESS;
6959 }
uint8_t switch_rtp_ready(switch_rtp_t *rtp_session)
Test if an RTP session is ready.
Definition: switch_rtp.c:4452
uint32_t duration
Definition: switch_types.h:288
struct switch_rtp_rfc2833_data dtmf_data
Definition: switch_rtp.c:403
uint32_t switch_core_min_dtmf_duration(uint32_t duration)
Definition: switch_core.c:1704
switch_status_t switch_queue_trypush(switch_queue_t *queue, void *data)
Definition: switch_apr.c:1155
switch_queue_t * dtmf_queue
Definition: switch_rtp.c:217
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 6961 of file switch_rtp.c.

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

6962 {
6963  switch_dtmf_t *rdigit;
6964 
6965  if (!switch_rtp_ready(rtp_session)) {
6966  return SWITCH_STATUS_FALSE;
6967  }
6968 
6969  if ((rdigit = malloc(sizeof(*rdigit))) != 0) {
6970  *rdigit = *dtmf;
6971  if (rdigit->duration < switch_core_min_dtmf_duration(0)) {
6973  }
6974 
6975  if ((switch_queue_trypush(rtp_session->dtmf_data.dtmf_inqueue, rdigit)) != SWITCH_STATUS_SUCCESS) {
6976  free(rdigit);
6977  return SWITCH_STATUS_FALSE;
6978  }
6979  } else {
6980  abort();
6981  }
6982 
6983  return SWITCH_STATUS_SUCCESS;
6984 }
uint8_t switch_rtp_ready(switch_rtp_t *rtp_session)
Test if an RTP session is ready.
Definition: switch_rtp.c:4452
uint32_t duration
Definition: switch_types.h:288
struct switch_rtp_rfc2833_data dtmf_data
Definition: switch_rtp.c:403
uint32_t switch_core_min_dtmf_duration(uint32_t duration)
Definition: switch_core.c:1704
switch_queue_t * dtmf_inqueue
Definition: switch_rtp.c:233
switch_status_t switch_queue_trypush(switch_queue_t *queue, void *data)
Definition: switch_apr.c:1155
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 6986 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.

6988 {
6989  int bytes = 0;
6990 
6991  if (!switch_rtp_ready(rtp_session)) {
6992  return SWITCH_STATUS_FALSE;
6993  }
6994 
6995  bytes = rtp_common_read(rtp_session, payload_type, NULL, flags, io_flags);
6996 
6997  if (bytes < 0) {
6998  *datalen = 0;
6999  return bytes == -2 ? SWITCH_STATUS_TIMEOUT : SWITCH_STATUS_GENERR;
7000  } else if (bytes == 0) {
7001  *datalen = 0;
7002  return SWITCH_STATUS_BREAK;
7003  } else {
7004  if (bytes > rtp_header_len) {
7005  bytes -= rtp_header_len;
7006  }
7007  }
7008 
7009  *datalen = bytes;
7010 
7011  memcpy(data, RTP_BODY(rtp_session), bytes);
7012 
7013  return SWITCH_STATUS_SUCCESS;
7014 }
uint8_t switch_rtp_ready(switch_rtp_t *rtp_session)
Test if an RTP session is ready.
Definition: switch_rtp.c:4452
#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:6140
#define rtp_header_len
Definition: switch_rtp.c:66
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 4452 of file switch_rtp.c.

References switch_mutex_lock(), switch_mutex_unlock(), SWITCH_RTP_FLAG_IO, and SWITCH_RTP_FLAG_SHUTDOWN.

Referenced by check_ice(), 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_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_pause_jitter_buffer(), 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_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().

4453 {
4454  uint8_t ret;
4455 
4456  if (!rtp_session || !rtp_session->flag_mutex || rtp_session->flags[SWITCH_RTP_FLAG_SHUTDOWN]) {
4457  return 0;
4458  }
4459 
4460  switch_mutex_lock(rtp_session->flag_mutex);
4461  ret = (rtp_session->flags[SWITCH_RTP_FLAG_IO] && rtp_session->sock_input && rtp_session->sock_output && rtp_session->remote_addr
4462  && rtp_session->ready == 2) ? 1 : 0;
4463  switch_mutex_unlock(rtp_session->flag_mutex);
4464 
4465  return ret;
4466 }
switch_sockaddr_t * remote_addr
Definition: switch_rtp.c:326
switch_mutex_t * flag_mutex
Definition: switch_rtp.c:407
switch_socket_t * sock_input
Definition: switch_rtp.c:309
switch_status_t switch_mutex_unlock(switch_mutex_t *lock)
Definition: switch_apr.c:290
uint8_t ready
Definition: switch_rtp.c:412
switch_status_t switch_mutex_lock(switch_mutex_t *lock)
Definition: switch_apr.c:285
uint32_t flags[SWITCH_RTP_FLAG_INVALID]
Definition: switch_rtp.c:372
switch_socket_t * sock_output
Definition: switch_rtp.c:309
void switch_rtp_release_port ( const char *  ip,
switch_port_t  port 
)

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

2416 {
2417  switch_core_port_allocator_t *alloc = NULL;
2418 
2419  if (!ip || !port) {
2420  return;
2421  }
2422 
2424  if ((alloc = switch_core_hash_find(alloc_hash, ip))) {
2426  }
2428 
2429 }
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:290
static switch_mutex_t * port_lock
Definition: switch_rtp.c:83
switch_status_t switch_mutex_lock(switch_mutex_t *lock)
Definition: switch_apr.c:285
static switch_hash_t * alloc_hash
Definition: switch_rtp.c:109
switch_status_t switch_rtp_req_bitrate ( switch_rtp_t rtp_session,
uint32_t  bps 
)

Definition at line 4340 of file switch_rtp.c.

References rtp_write_ready(), SWITCH_STATUS_FALSE, and SWITCH_STATUS_SUCCESS.

Referenced by switch_core_media_receive_message().

4341 {
4342  if (!rtp_write_ready(rtp_session, 0, __LINE__) || rtp_session->tmmbr) {
4343  return SWITCH_STATUS_FALSE;
4344  }
4345 
4346  rtp_session->tmmbr = bps;
4347 
4348  return SWITCH_STATUS_SUCCESS;
4349 }
static int rtp_write_ready(switch_rtp_t *rtp_session, uint32_t bytes, int line)
Definition: switch_rtp.c:7161
uint32_t tmmbr
Definition: switch_rtp.c:322
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 2431 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().

2432 {
2433  switch_port_t port = 0;
2434  switch_core_port_allocator_t *alloc = NULL;
2435 
2437  alloc = switch_core_hash_find(alloc_hash, ip);
2438  if (!alloc) {
2440  abort();
2441  }
2442 
2443  switch_core_hash_insert(alloc_hash, ip, alloc);
2444  }
2445 
2447  port = 0;
2448  }
2449 
2451  return port;
2452 }
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:290
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:83
switch_status_t switch_mutex_lock(switch_mutex_t *lock)
Definition: switch_apr.c:285
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:81
static switch_port_t END_PORT
Definition: switch_rtp.c:82
#define switch_core_hash_insert(_h, _k, _d)
Definition: switch_core.h:1410
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.
void switch_rtp_reset ( switch_rtp_t rtp_session)

Definition at line 2789 of file switch_rtp.c.

References memset(), rtcp_stats_init(), SWITCH_RTP_FLAG_MUTE, SWITCH_RTP_FLAG_PAUSE, switch_rtp_reset_vb(), and switch_rtp_set_flag().

Referenced by clear_ice(), and switch_core_session_stop_media().

2790 {
2791  if (!rtp_session) {
2792  return;
2793  }
2794 
2795  rtp_session->seq = (uint16_t) rand();
2796  rtp_session->ts = 0;
2797  memset(&rtp_session->ts_norm, 0, sizeof(rtp_session->ts_norm));
2798 
2799  rtp_session->last_stun = rtp_session->first_stun = 0;
2800  rtp_session->wrong_addrs = 0;
2801  rtp_session->rtcp_sent_packets = 0;
2802  rtp_session->rtcp_last_sent = 0;
2803  rtp_session->ice_adj = 0;
2804 
2805  //switch_rtp_del_dtls(rtp_session, DTLS_TYPE_RTP|DTLS_TYPE_RTCP);
2808  rtcp_stats_init(rtp_session);
2809 
2810  if (rtp_session->ice.ready) {
2811  switch_rtp_reset_vb(rtp_session);
2812  rtp_session->ice.ready = rtp_session->ice.rready = 0;
2813  }
2814 
2815 }
switch_time_t rtcp_last_sent
Definition: switch_rtp.c:389
void switch_rtp_reset_vb(switch_rtp_t *rtp_session)
Definition: switch_rtp.c:2778
static void rtcp_stats_init(switch_rtp_t *rtp_session)
Definition: switch_rtp.c:1816
uint32_t ts
Definition: switch_rtp.c:362
uint16_t seq
Definition: switch_rtp.c:353
void switch_rtp_set_flag(switch_rtp_t *rtp_session, switch_rtp_flag_t flag)
Set an RTP Flag.
Definition: switch_rtp.c:4702
switch_rtp_ice_t ice
Definition: switch_rtp.c:377
switch_time_t last_stun
Definition: switch_rtp.c:384
switch_time_t first_stun
Definition: switch_rtp.c:383
uint32_t wrong_addrs
Definition: switch_rtp.c:385
memset(buf, 0, buflen)
int rtcp_sent_packets
Definition: switch_rtp.c:436
ts_normalize_t ts_norm
Definition: switch_rtp.c:325
void switch_rtp_reset_jb ( switch_rtp_t rtp_session)

Definition at line 2769 of file switch_rtp.c.

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

2770 {
2771  if (switch_rtp_ready(rtp_session)) {
2772  if (rtp_session->jb) {
2773  switch_jb_reset(rtp_session->jb);
2774  }
2775  }
2776 }
uint8_t switch_rtp_ready(switch_rtp_t *rtp_session)
Test if an RTP session is ready.
Definition: switch_rtp.c:4452
switch_jb_t * jb
Definition: switch_rtp.c:414
void switch_jb_reset(switch_jb_t *jb)
void switch_rtp_reset_media_timer ( switch_rtp_t rtp_session)

Definition at line 2817 of file switch_rtp.c.

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

2818 {
2819  rtp_session->missed_count = 0;
2820 }
uint32_t missed_count
Definition: switch_rtp.c:418
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 4030 of file switch_rtp.c.

References SWITCH_RTP_FLAG_AUTO_CNG.

Referenced by switch_core_media_activate_rtp(), and switch_core_media_negotiate_sdp().

4031 {
4032  rtp_session->cng_pt = pt;
4033  rtp_session->flags[SWITCH_RTP_FLAG_AUTO_CNG] = 1;
4034 }
switch_payload_t cng_pt
Definition: switch_rtp.c:406
uint32_t flags[SWITCH_RTP_FLAG_INVALID]
Definition: switch_rtp.c:372
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 4645 of file switch_rtp.c.

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

4646 {
4647  rtp_session->payload = payload;
4648 }
switch_payload_t payload
Definition: switch_rtp.c:359
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 2401 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().

2402 {
2403  if (port) {
2404  if (port_lock) {
2406  }
2407  END_PORT = port;
2408  if (port_lock) {
2410  }
2411  }
2412  return END_PORT;
2413 }
switch_status_t switch_mutex_unlock(switch_mutex_t *lock)
Definition: switch_apr.c:290
static switch_mutex_t * port_lock
Definition: switch_rtp.c:83
switch_status_t switch_mutex_lock(switch_mutex_t *lock)
Definition: switch_apr.c:285
static switch_port_t END_PORT
Definition: switch_rtp.c:82
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 4702 of file switch_rtp.c.

References reset_jitter_seq(), rtp_flush_read_buffer(), 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_FLUSH_ONCE, SWITCH_SO_NONBLOCK, switch_socket_opt_set(), and TRUE.

Referenced by do_flush(), handle_ice(), read_rtp_packet(), rtp_common_read(), rtp_flush_read_buffer(), switch_core_media_activate_rtp(), switch_core_media_check_autoadj(), 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_rtp_create(), switch_rtp_enable_vad(), switch_rtp_flush(), switch_rtp_new(), switch_rtp_reset(), switch_rtp_set_local_address(), and switch_rtp_udptl_mode().

4703 {
4704 
4705  switch_mutex_lock(rtp_session->flag_mutex);
4706  rtp_session->flags[flag] = 1;
4707  switch_mutex_unlock(rtp_session->flag_mutex);
4708 
4709  if (flag == SWITCH_RTP_FLAG_DTMF_ON) {
4710  rtp_session->stats.inbound.last_processed_seq = 0;
4711  } else if (flag == SWITCH_RTP_FLAG_FLUSH) {
4712  reset_jitter_seq(rtp_session);
4713  } else if (flag == SWITCH_RTP_FLAG_AUTOADJ) {
4714  rtp_session->autoadj_window = 20;
4715  rtp_session->autoadj_threshold = 10;
4716  rtp_session->autoadj_tally = 0;
4717  if (rtp_session->session) {
4718  switch_channel_t *channel = switch_core_session_get_channel(rtp_session->session);
4719  const char *x = switch_channel_get_variable(channel, "rtp_auto_adjust_threshold");
4720  if (x && *x) {
4721  int xn = atoi(x);
4722  if (xn > 0 && xn <= 65535) {
4723  rtp_session->autoadj_window = xn*2;
4724  rtp_session->autoadj_threshold = xn;
4725  }
4726  }
4727  }
4728 
4729 
4731 
4732 
4733  if (rtp_session->jb) {
4734  switch_jb_reset(rtp_session->jb);
4735  }
4736  } else if (flag == SWITCH_RTP_FLAG_NOBLOCK && rtp_session->sock_input) {
4738  }
4739 
4740 }
switch_rtp_numbers_t inbound
Definition: switch_types.h:690
switch_mutex_t * flag_mutex
Definition: switch_rtp.c:407
switch_socket_t * sock_input
Definition: switch_rtp.c:309
void rtp_flush_read_buffer(switch_rtp_t *rtp_session, switch_rtp_flush_t flush)
Definition: switch_rtp.c:4940
switch_status_t switch_mutex_unlock(switch_mutex_t *lock)
Definition: switch_apr.c:290
_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:285
uint32_t flags[SWITCH_RTP_FLAG_INVALID]
Definition: switch_rtp.c:372
#define switch_channel_get_variable(_c, _v)
uint32_t autoadj_threshold
Definition: switch_rtp.c:332
switch_status_t switch_socket_opt_set(switch_socket_t *sock, int32_t opt, int32_t on)
Definition: switch_apr.c:823
uint32_t autoadj_window
Definition: switch_rtp.c:331
switch_rtp_stats_t stats
Definition: switch_rtp.c:428
switch_jb_t * jb
Definition: switch_rtp.c:414
#define SWITCH_SO_NONBLOCK
Definition: switch_apr.h:994
static void reset_jitter_seq(switch_rtp_t *rtp_session)
Definition: switch_rtp.c:1595
switch_core_session_t * session
Definition: switch_rtp.c:446
void switch_jb_reset(switch_jb_t *jb)
#define TRUE
uint32_t autoadj_tally
Definition: switch_rtp.c:333
void switch_rtp_set_flags ( switch_rtp_t rtp_session,
switch_rtp_flag_t  flags[SWITCH_RTP_FLAG_INVALID] 
)

Definition at line 4660 of file switch_rtp.c.

References rtp_flush_read_buffer(), switch_channel_get_variable, switch_core_session_get_channel(), SWITCH_RTP_FLAG_AUTOADJ, SWITCH_RTP_FLAG_INVALID, SWITCH_RTP_FLAG_NOBLOCK, SWITCH_RTP_FLUSH_ONCE, SWITCH_SO_NONBLOCK, switch_socket_opt_set(), and TRUE.

Referenced by switch_core_media_receive_message(), and switch_rtp_create().

4661 {
4662  int i;
4663 
4664  for(i = 0; i < SWITCH_RTP_FLAG_INVALID; i++) {
4665  if (flags[i]) {
4666  rtp_session->flags[i] = flags[i];
4667 
4668  if (i == SWITCH_RTP_FLAG_AUTOADJ) {
4669  rtp_session->autoadj_window = 20;
4670  rtp_session->autoadj_threshold = 10;
4671  rtp_session->autoadj_tally = 0;
4672  if (rtp_session->session) {
4673  switch_channel_t *channel = switch_core_session_get_channel(rtp_session->session);
4674  const char *x = switch_channel_get_variable(channel, "rtp_auto_adjust_threshold");
4675  if (x && *x) {
4676  int xn = atoi(x);
4677  if (xn > 0 && xn <= 65535) {
4678  rtp_session->autoadj_window = xn*2;
4679  rtp_session->autoadj_threshold = xn;
4680  }
4681  }
4682  }
4684  } else if (i == SWITCH_RTP_FLAG_NOBLOCK && rtp_session->sock_input) {
4686  }
4687  }
4688  }
4689 }
switch_socket_t * sock_input
Definition: switch_rtp.c:309
void rtp_flush_read_buffer(switch_rtp_t *rtp_session, switch_rtp_flush_t flush)
Definition: switch_rtp.c:4940
_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 flags[SWITCH_RTP_FLAG_INVALID]
Definition: switch_rtp.c:372
#define switch_channel_get_variable(_c, _v)
uint32_t autoadj_threshold
Definition: switch_rtp.c:332
switch_status_t switch_socket_opt_set(switch_socket_t *sock, int32_t opt, int32_t on)
Definition: switch_apr.c:823
uint32_t autoadj_window
Definition: switch_rtp.c:331
#define SWITCH_SO_NONBLOCK
Definition: switch_apr.h:994
switch_core_session_t * session
Definition: switch_rtp.c:446
#define TRUE
uint32_t autoadj_tally
Definition: switch_rtp.c:333
void switch_rtp_set_interdigit_delay ( switch_rtp_t rtp_session,
uint32_t  delay 
)

Definition at line 4630 of file switch_rtp.c.

Referenced by switch_core_media_activate_rtp().

4631 {
4632  rtp_session->interdigit_delay = delay;
4633 }
uint32_t interdigit_delay
Definition: switch_rtp.c:445
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 3674 of file switch_rtp.c.

References SWITCH_STATUS_SUCCESS.

Referenced by switch_rtp_change_interval(), and switch_rtp_create().

3675 {
3676  rtp_session->ms_per_packet = ms_per_packet;
3677  rtp_session->samples_per_interval = rtp_session->conf_samples_per_interval = samples_per_interval;
3678  rtp_session->missed_count = 0;
3679  rtp_session->samples_per_second =
3680  (uint32_t) ((double) (1000.0f / (double) (rtp_session->ms_per_packet / 1000)) * (double) rtp_session->samples_per_interval);
3681 
3682  rtp_session->one_second = (rtp_session->samples_per_second / rtp_session->samples_per_interval);
3683 
3684  return SWITCH_STATUS_SUCCESS;
3685 }
uint32_t samples_per_second
Definition: switch_rtp.c:387
uint32_t missed_count
Definition: switch_rtp.c:418
uint32_t samples_per_interval
Definition: switch_rtp.c:386
uint32_t ms_per_packet
Definition: switch_rtp.c:391
uint32_t conf_samples_per_interval
Definition: switch_rtp.c:388
uint32_t one_second
Definition: switch_rtp.c:392
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 4655 of file switch_rtp.c.

4656 {
4657  rtp_session->invalid_handler = on_invalid;
4658 }
switch_rtp_invalid_handler_t invalid_handler
Definition: switch_rtp.c:360
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 2585 of file switch_rtp.c.

References enable_local_rtcp_socket(), FALSE, READ_DEC, READ_INC, 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().

2586 {
2587  switch_socket_t *new_sock = NULL, *old_sock = NULL;
2589  int j = 0;
2590 #ifndef WIN32
2591  char o[5] = "TEST", i[5] = "";
2592  switch_size_t len, ilen = 0;
2593  int x;
2594 #endif
2595 
2596  if (rtp_session->ready != 1) {
2597  if (!switch_rtp_ready(rtp_session)) {
2598  return SWITCH_STATUS_FALSE;
2599  }
2600 
2601  WRITE_INC(rtp_session);
2602  READ_INC(rtp_session);
2603 
2604  if (!switch_rtp_ready(rtp_session)) {
2605  goto done;
2606  }
2607  }
2608 
2609 
2610  *err = NULL;
2611 
2612  if (zstr(host) || !port) {
2613  *err = "Address Error";
2614  goto done;
2615  }
2616 
2617 
2618  rtp_session->local_host_str = switch_core_strdup(rtp_session->pool, host);
2619  rtp_session->local_port = port;
2620 
2621 
2622  if (switch_sockaddr_info_get(&rtp_session->local_addr, host, SWITCH_UNSPEC, port, 0, rtp_session->pool) != SWITCH_STATUS_SUCCESS) {
2623  *err = "Local Address Error!";
2624  goto done;
2625  }
2626 
2627 
2628  if (rtp_session->sock_input) {
2629  switch_rtp_kill_socket(rtp_session);
2630  }
2631 
2632  if (switch_socket_create(&new_sock, switch_sockaddr_get_family(rtp_session->local_addr), SOCK_DGRAM, 0, rtp_session->pool) != SWITCH_STATUS_SUCCESS) {
2633  *err = "Socket Error!";
2634  goto done;
2635  }
2636 
2638  *err = "Socket Error!";
2639  goto done;
2640  }
2641 
2642  if (rtp_session->flags[SWITCH_RTP_FLAG_VIDEO]) {
2643  switch_socket_opt_set(new_sock, SWITCH_SO_RCVBUF, 1572864);
2644  switch_socket_opt_set(new_sock, SWITCH_SO_SNDBUF, 1572864);
2645  }
2646 
2647  if (switch_socket_bind(new_sock, rtp_session->local_addr) != SWITCH_STATUS_SUCCESS) {
2648  char *em = switch_core_sprintf(rtp_session->pool, "Bind Error! %s:%d", host, port);
2649  *err = em;
2650  goto done;
2651  }
2652 
2653 
2654  if ((j = atoi(host)) && j > 223 && j < 240) { /* mcast */
2655  if (switch_mcast_interface(new_sock, rtp_session->local_addr) != SWITCH_STATUS_SUCCESS) {
2656  *err = "Multicast Socket interface Error";
2657  goto done;
2658  }
2659 
2660  if (switch_mcast_join(new_sock, rtp_session->local_addr, NULL, NULL) != SWITCH_STATUS_SUCCESS) {
2661  *err = "Multicast Error";
2662  goto done;
2663  }
2664 
2665  if (rtp_session->session) {
2666  switch_channel_t *channel = switch_core_session_get_channel(rtp_session->session);
2667  const char *var;
2668 
2669  if ((var = switch_channel_get_variable(channel, "multicast_ttl"))) {
2670  int ttl = atoi(var);
2671 
2672  if (ttl > 0 && ttl < 256) {
2673  if (switch_mcast_hops(new_sock, (uint8_t) ttl) != SWITCH_STATUS_SUCCESS) {
2674  *err = "Mutlicast TTL set failed";
2675  goto done;
2676  }
2677 
2678  }
2679  }
2680 
2681  }
2682 
2683  }
2684 
2685 
2686 
2687 #ifndef WIN32
2688  len = sizeof(i);
2690 
2691  switch_socket_sendto(new_sock, rtp_session->local_addr, 0, (void *) o, &len);
2692 
2693  x = 0;
2694  while (!ilen) {
2695  switch_status_t status;
2696  ilen = len;
2697  status = switch_socket_recvfrom(rtp_session->from_addr, new_sock, 0, (void *) i, &ilen);
2698 
2699  if (status != SWITCH_STATUS_SUCCESS && status != SWITCH_STATUS_BREAK) {
2700  break;
2701  }
2702 
2703  if (++x > 1000) {
2704  break;
2705  }
2706  switch_cond_next();
2707  }
2709 
2710 #endif
2711 
2712  old_sock = rtp_session->sock_input;
2713  rtp_session->sock_input = new_sock;
2714  new_sock = NULL;
2715 
2716  if (rtp_session->flags[SWITCH_RTP_FLAG_USE_TIMER] || rtp_session->flags[SWITCH_RTP_FLAG_NOBLOCK] || rtp_session->flags[SWITCH_RTP_FLAG_VIDEO]) {
2719  }
2720 
2721  switch_socket_create_pollset(&rtp_session->read_pollfd, rtp_session->sock_input, SWITCH_POLLIN | SWITCH_POLLERR, rtp_session->pool);
2722 
2723  if (rtp_session->flags[SWITCH_RTP_FLAG_ENABLE_RTCP]) {
2724  if ((status = enable_local_rtcp_socket(rtp_session, err)) == SWITCH_STATUS_SUCCESS) {
2725  *err = "Success";
2726  }
2727  } else {
2728  status = SWITCH_STATUS_SUCCESS;
2729  *err = "Success";
2730  }
2731 
2733 
2734  done:
2735 
2736  if (new_sock) {
2737  switch_socket_close(new_sock);
2738  }
2739 
2740  if (old_sock) {
2741  switch_socket_close(old_sock);
2742  }
2743 
2744 
2745  if (rtp_session->ready != 1) {
2746  WRITE_DEC(rtp_session);
2747  READ_DEC(rtp_session);
2748  }
2749 
2750  return status;
2751 }
switch_pollfd_t * read_pollfd
Definition: switch_rtp.c:310
uint8_t switch_rtp_ready(switch_rtp_t *rtp_session)
Test if an RTP session is ready.
Definition: switch_rtp.c:4452
switch_status_t switch_socket_bind(switch_socket_t *sock, switch_sockaddr_t *sa)
Definition: switch_apr.c:719
switch_status_t switch_mcast_hops(switch_socket_t *sock, uint8_t ttl)
Definition: switch_apr.c:876
#define WRITE_INC(rtp_session)
Definition: switch_rtp.c:62
#define switch_core_strdup(_pool, _todup)
Copy a string using memory allocation from a given pool.
Definition: switch_core.h:729
switch_socket_t * sock_input
Definition: switch_rtp.c:309
int32_t switch_sockaddr_get_family(switch_sockaddr_t *sa)
Definition: switch_apr.c:921
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:936
#define SWITCH_POLLIN
Definition: switch_apr.h:1321
#define READ_DEC(rtp_session)
Definition: switch_rtp.c:61
#define SWITCH_POLLERR
Definition: switch_apr.h:1324
#define zstr(x)
Definition: switch_utils.h:281
_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:63
uint8_t ready
Definition: switch_rtp.c:412
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:773
uint32_t flags[SWITCH_RTP_FLAG_INVALID]
Definition: switch_rtp.c:372
#define switch_channel_get_variable(_c, _v)
char * local_host_str
Definition: switch_rtp.c:380
#define READ_INC(rtp_session)
Definition: switch_rtp.c:60
switch_status_t switch_socket_opt_set(switch_socket_t *sock, int32_t opt, int32_t on)
Definition: switch_apr.c:823
uintptr_t switch_size_t
switch_sockaddr_t * local_addr
Definition: switch_rtp.c:313
switch_status_t switch_mcast_interface(switch_socket_t *sock, switch_sockaddr_t *iface)
Definition: switch_apr.c:886
void switch_cond_next(void)
Definition: switch_time.c:638
switch_memory_pool_t * pool
Definition: switch_rtp.c:373
void switch_rtp_set_flag(switch_rtp_t *rtp_session, switch_rtp_flag_t flag)
Set an RTP Flag.
Definition: switch_rtp.c:4702
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:704
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_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:1032
switch_status_t switch_socket_close(switch_socket_t *sock)
Definition: switch_apr.c:714
#define SWITCH_UNSPEC
Definition: switch_apr.h:1022
#define FALSE
switch_core_session_t * session
Definition: switch_rtp.c:446
#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:871
#define TRUE
switch_port_t local_port
Definition: switch_rtp.c:397
void switch_rtp_kill_socket(switch_rtp_t *rtp_session)
Kill the socket on an existing RTP session.
Definition: switch_rtp.c:4425
switch_sockaddr_t * from_addr
Definition: switch_rtp.c:374
char * switch_core_sprintf(_In_ switch_memory_pool_t *pool, _In_z_ _Printf_format_string_ const char *fmt,...)
printf-style style printing routine. The data is output to a string allocated from the pool ...
struct apr_socket_t switch_socket_t
Definition: switch_apr.h:1026
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:817
static switch_status_t enable_local_rtcp_socket(switch_rtp_t *rtp_session, const char **err)
Definition: switch_rtp.c:2522
void switch_rtp_set_max_missed_packets ( switch_rtp_t rtp_session,
uint32_t  max 
)

Definition at line 2753 of file switch_rtp.c.

References SWITCH_CHANNEL_SESSION_LOG, switch_log_printf(), SWITCH_LOG_WARNING, SWITCH_RTP_FLAG_UDPTL, and switch_rtp_ready().

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

2754 {
2755  if (!switch_rtp_ready(rtp_session) || rtp_session->flags[SWITCH_RTP_FLAG_UDPTL]) {
2756  return;
2757  }
2758 
2759  if (rtp_session->missed_count >= max) {
2760 
2762  "new max missed packets(%d->%d) greater than current missed packets(%d). RTP will timeout.\n",
2763  rtp_session->missed_count, max, rtp_session->missed_count);
2764  }
2765 
2766  rtp_session->max_missed_packets = max;
2767 }
#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:4452
uint32_t max_missed_packets
Definition: switch_rtp.c:417
uint32_t flags[SWITCH_RTP_FLAG_INVALID]
Definition: switch_rtp.c:372
uint32_t missed_count
Definition: switch_rtp.c:418
switch_core_session_t * session
Definition: switch_rtp.c:446
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_status_t switch_rtp_set_payload_map ( switch_rtp_t rtp_session,
payload_map_t **  pmap 
)

Definition at line 2454 of file switch_rtp.c.

References switch_mutex_lock(), switch_mutex_unlock(), SWITCH_STATUS_FALSE, and SWITCH_STATUS_SUCCESS.

Referenced by switch_core_media_activate_rtp().

2455 {
2456 
2457  if (rtp_session) {
2458  switch_mutex_lock(rtp_session->flag_mutex);
2459  rtp_session->pmaps = pmap;
2460  switch_mutex_unlock(rtp_session->flag_mutex);
2461  return SWITCH_STATUS_SUCCESS;
2462  }
2463 
2464  return SWITCH_STATUS_FALSE;
2465 }
switch_mutex_t * flag_mutex
Definition: switch_rtp.c:407
switch_status_t switch_mutex_unlock(switch_mutex_t *lock)
Definition: switch_apr.c:290
switch_status_t switch_mutex_lock(switch_mutex_t *lock)
Definition: switch_apr.c:285
payload_map_t ** pmaps
Definition: switch_rtp.c:447
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 8094 of file switch_rtp.c.

8095 {
8096  rtp_session->private_data = private_data;
8097 }
void * private_data
Definition: switch_rtp.c:361
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 2913 of file switch_rtp.c.

References enable_remote_rtcp_socket(), switch_core_strdup, switch_cp_addr(), 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, and SWITCH_UNSPEC.

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

2915 {
2916  switch_sockaddr_t *remote_addr;
2918  *err = "Success";
2919 
2920  if (switch_sockaddr_info_get(&remote_addr, host, SWITCH_UNSPEC, port, 0, rtp_session->pool) != SWITCH_STATUS_SUCCESS || !remote_addr) {
2921  *err = "Remote Address Error!";
2922  return SWITCH_STATUS_FALSE;
2923  }
2924 
2925 
2926  switch_mutex_lock(rtp_session->write_mutex);
2927 
2928  rtp_session->remote_addr = remote_addr;
2929  switch_cp_addr(rtp_session->rtp_from_addr, rtp_session->remote_addr);
2930 
2931  if (change_adv_addr) {
2932  rtp_session->remote_host_str = switch_core_strdup(rtp_session->pool, host);
2933  rtp_session->remote_port = port;
2934  }
2935 
2936  rtp_session->eff_remote_host_str = switch_core_strdup(rtp_session->pool, host);
2937  rtp_session->eff_remote_port = port;
2938 
2939  if (rtp_session->sock_input && switch_sockaddr_get_family(rtp_session->remote_addr) == switch_sockaddr_get_family(rtp_session->local_addr)) {
2940  rtp_session->sock_output = rtp_session->sock_input;
2941  } else {
2942  if (rtp_session->sock_output && rtp_session->sock_output != rtp_session->sock_input) {
2943  switch_socket_close(rtp_session->sock_output);
2944  }
2945  if ((status = switch_socket_create(&rtp_session->sock_output,
2947  SOCK_DGRAM, 0, rtp_session->pool)) != SWITCH_STATUS_SUCCESS) {
2948 
2949  *err = "Socket Error!";
2950  }
2951  }
2952 
2953  if (rtp_session->dtls) {
2954  rtp_session->dtls->sock_output = rtp_session->sock_output;
2955 
2956  if (rtp_session->flags[SWITCH_RTP_FLAG_RTCP_MUX]) {
2957  switch_sockaddr_info_get(&rtp_session->dtls->remote_addr, host, SWITCH_UNSPEC, port, 0, rtp_session->pool);
2958  }
2959  }
2960 
2961 
2962  if (rtp_session->flags[SWITCH_RTP_FLAG_ENABLE_RTCP]) {
2963  if (rtp_session->flags[SWITCH_RTP_FLAG_RTCP_MUX]) {
2964  rtp_session->rtcp_remote_addr = rtp_session->remote_addr;
2965  rtp_session->rtcp_sock_output = rtp_session->sock_output;
2966  } else {
2967  if (remote_rtcp_port) {
2968  rtp_session->remote_rtcp_port = remote_rtcp_port;
2969  } else {
2970  rtp_session->remote_rtcp_port = rtp_session->eff_remote_port + 1;
2971  }
2972  status = enable_remote_rtcp_socket(rtp_session, err);
2973 
2974  if (rtp_session->rtcp_dtls) {
2975  //switch_sockaddr_info_get(&rtp_session->rtcp_dtls->remote_addr, host, SWITCH_UNSPEC, port, 0, rtp_session->pool);
2976  rtp_session->rtcp_dtls->remote_addr = rtp_session->rtcp_remote_addr;
2977  rtp_session->rtcp_dtls->sock_output = rtp_session->rtcp_sock_output;
2978  }
2979  }
2980  }
2981 
2982  switch_mutex_unlock(rtp_session->write_mutex);
2983 
2984  return status;
2985 }
switch_sockaddr_t * remote_addr
Definition: switch_rtp.c:275
switch_mutex_t * write_mutex
Definition: switch_rtp.c:409
switch_sockaddr_t * remote_addr
Definition: switch_rtp.c:326
switch_port_t remote_rtcp_port
Definition: switch_rtp.c:400
#define switch_core_strdup(_pool, _todup)
Copy a string using memory allocation from a given pool.
Definition: switch_core.h:729
switch_socket_t * sock_input
Definition: switch_rtp.c:309
switch_port_t remote_port
Definition: switch_rtp.c:398
int32_t switch_sockaddr_get_family(switch_sockaddr_t *sa)
Definition: switch_apr.c:921
char * remote_host_str
Definition: switch_rtp.c:381
switch_status_t switch_mutex_unlock(switch_mutex_t *lock)
Definition: switch_apr.c:290
switch_socket_t * sock_output
Definition: switch_rtp.c:274
switch_port_t eff_remote_port
Definition: switch_rtp.c:399
struct apr_sockaddr_t switch_sockaddr_t
Definition: switch_apr.h:1029
switch_status_t switch_mutex_lock(switch_mutex_t *lock)
Definition: switch_apr.c:285
uint32_t flags[SWITCH_RTP_FLAG_INVALID]
Definition: switch_rtp.c:372
switch_sockaddr_t * rtp_from_addr
Definition: switch_rtp.c:374
switch_sockaddr_t * local_addr
Definition: switch_rtp.c:313
switch_dtls_t * dtls
Definition: switch_rtp.c:348
switch_memory_pool_t * pool
Definition: switch_rtp.c:373
switch_socket_t * rtcp_sock_output
Definition: switch_rtp.c:309
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:704
switch_status_t
Common return values.
static switch_status_t enable_remote_rtcp_socket(switch_rtp_t *rtp_session, const char **err)
Definition: switch_rtp.c:2478
switch_status_t switch_socket_close(switch_socket_t *sock)
Definition: switch_apr.c:714
#define SWITCH_UNSPEC
Definition: switch_apr.h:1022
switch_dtls_t * rtcp_dtls
Definition: switch_rtp.c:349
switch_sockaddr_t * rtcp_remote_addr
Definition: switch_rtp.c:326
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:817
char * eff_remote_host_str
Definition: switch_rtp.c:382
int switch_cp_addr(switch_sockaddr_t *sa1, switch_sockaddr_t *sa2)
switch_socket_t * sock_output
Definition: switch_rtp.c:309
switch_status_t switch_rtp_set_remote_ssrc ( switch_rtp_t rtp_session,
uint32_t  ssrc 
)

Definition at line 3733 of file switch_rtp.c.

References SWITCH_STATUS_SUCCESS.

Referenced by check_ice(), and switch_core_media_activate_rtp().

3734 {
3735  rtp_session->remote_ssrc = ssrc;
3736 
3737  return SWITCH_STATUS_SUCCESS;
3738 }
uint32_t remote_ssrc
Definition: switch_rtp.c:355
switch_status_t switch_rtp_set_ssrc ( switch_rtp_t rtp_session,
uint32_t  ssrc 
)

Definition at line 3725 of file switch_rtp.c.

References SWITCH_STATUS_SUCCESS.

Referenced by rtp_common_write(), and switch_core_media_activate_rtp().

3726 {
3727  rtp_session->ssrc = ssrc;
3728  rtp_session->send_msg.header.ssrc = htonl(rtp_session->ssrc);
3729 
3730  return SWITCH_STATUS_SUCCESS;
3731 }
srtp_hdr_t header
Definition: switch_rtp.c:112
uint32_t ssrc
Definition: switch_rtp.c:354
rtp_msg_t send_msg
Definition: switch_rtp.c:314
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 2387 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().

2388 {
2389  if (port) {
2390  if (port_lock) {
2392  }
2393  START_PORT = port;
2394  if (port_lock) {
2396  }
2397  }
2398  return START_PORT;
2399 }
switch_status_t switch_mutex_unlock(switch_mutex_t *lock)
Definition: switch_apr.c:290
static switch_mutex_t * port_lock
Definition: switch_rtp.c:83
switch_status_t switch_mutex_lock(switch_mutex_t *lock)
Definition: switch_apr.c:285
static switch_port_t START_PORT
Definition: switch_rtp.c:81
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 4014 of file switch_rtp.c.

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

4015 {
4016  if (te > 95) {
4017  rtp_session->te = te;
4018  }
4019 }
switch_payload_t te
Definition: switch_rtp.c:404
void switch_rtp_set_telephony_recv_event ( switch_rtp_t rtp_session,
switch_payload_t  te 
)

Definition at line 4022 of file switch_rtp.c.

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

4023 {
4024  if (te > 95) {
4025  rtp_session->recv_te = te;
4026  }
4027 }
switch_payload_t recv_te
Definition: switch_rtp.c:405
switch_status_t switch_rtp_set_video_buffer_size ( switch_rtp_t rtp_session,
uint32_t  frames,
uint32_t  max_frames 
)

Definition at line 4101 of file switch_rtp.c.

References 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_ready(), SWITCH_STATUS_FALSE, and SWITCH_STATUS_SUCCESS.

Referenced by check_jb(), and check_jb_sync().

4102 {
4103  if (!switch_rtp_ready(rtp_session)) {
4104  return SWITCH_STATUS_FALSE;
4105  }
4106 
4107  if (!max_frames) {
4108  max_frames = 50;
4109  }
4110 
4111  if (!rtp_session->vb) {
4112  switch_jb_create(&rtp_session->vb, SJB_VIDEO, frames, max_frames, rtp_session->pool);
4113  switch_jb_set_session(rtp_session->vb, rtp_session->session);
4114  } else {
4115  switch_jb_set_frames(rtp_session->vb, frames, max_frames);
4116  }
4117 
4118  //switch_rtp_flush(rtp_session);
4120 
4121  switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(rtp_session->session), SWITCH_LOG_DEBUG1, "Setting video buffer %u Frames.\n", frames);
4122 
4123  return SWITCH_STATUS_SUCCESS;
4124 }
#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:4452
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)
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:415
switch_memory_pool_t * pool
Definition: switch_rtp.c:373
switch_status_t switch_core_session_request_video_refresh(switch_core_session_t *session)
switch_core_session_t * session
Definition: switch_rtp.c:446
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.
void switch_rtp_shutdown ( void  )

Definition at line 2348 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(), and switch_mutex_unlock().

Referenced by switch_core_destroy().

2349 {
2350  switch_core_port_allocator_t *alloc = NULL;
2351  switch_hash_index_t *hi;
2352  const void *var;
2353  void *val;
2354 
2355  if (!global_init) {
2356  return;
2357  }
2358 
2360 
2361  for (hi = switch_core_hash_first(alloc_hash); hi; hi = switch_core_hash_next(&hi)) {
2362  switch_core_hash_this(hi, &var, NULL, &val);
2363  if ((alloc = (switch_core_port_allocator_t *) val)) {
2364  switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "Destroy port allocator for %s\n", (char *) var);
2366  }
2367  }
2368 
2371 
2372 #ifdef ENABLE_ZRTP
2373  if (zrtp_on) {
2374  zrtp_status_t status = zrtp_status_ok;
2375 
2376  status = zrtp_def_cache_store(zrtp_global);
2377  switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "Saving ZRTP cache: %s\n", zrtp_status_ok == status ? "OK" : "FAIL");
2378  zrtp_down(zrtp_global);
2379  }
2380 #endif
2381 #ifdef ENABLE_SRTP
2382  crypto_kernel_shutdown();
2383 #endif
2384 
2385 }
#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:766
switch_status_t switch_mutex_unlock(switch_mutex_t *lock)
Definition: switch_apr.c:290
static switch_mutex_t * port_lock
Definition: switch_rtp.c:83
switch_status_t switch_mutex_lock(switch_mutex_t *lock)
Definition: switch_apr.c:285
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:1501
switch_status_t switch_rtp_sync_stats ( switch_rtp_t rtp_session)

Definition at line 4468 of file switch_rtp.c.

References do_mos(), switch_channel_set_variable_printf(), switch_core_session_get_channel(), switch_micro_time_now(), SWITCH_RTP_FLAG_VAD, SWITCH_STATUS_FALSE, SWITCH_STATUS_SUCCESS, and SWITCH_TRUE.

Referenced by switch_core_media_sync_stats().

4469 {
4470  if (!rtp_session) {
4471  return SWITCH_STATUS_FALSE;
4472  }
4473 
4474  if (rtp_session->flags[SWITCH_RTP_FLAG_VAD]) {
4476 
4477  switch_channel_set_variable_printf(channel, "vad_total_talk_time_ms", "%u", (uint32_t)rtp_session->vad_data.total_talk_time / 1000);
4478  switch_channel_set_variable_printf(channel, "vad_total_talk_time_sec", "%u", (uint32_t)rtp_session->vad_data.total_talk_time / 1000000);
4479  }
4480 
4481  do_mos(rtp_session, SWITCH_TRUE);
4482 
4483  if (rtp_session->stats.inbound.error_log && !rtp_session->stats.inbound.error_log->stop) {
4484  rtp_session->stats.inbound.error_log->stop = switch_micro_time_now();
4485  }
4486 
4487  return SWITCH_STATUS_SUCCESS;
4488 }
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:310
switch_time_t total_talk_time
Definition: switch_rtp.c:212
switch_rtp_numbers_t inbound
Definition: switch_types.h:690
struct switch_rtp_vad_data vad_data
Definition: switch_rtp.c:402
switch_core_session_t * session
Definition: switch_rtp.c:191
_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:621
uint32_t flags[SWITCH_RTP_FLAG_INVALID]
Definition: switch_rtp.c:372
switch_rtp_stats_t stats
Definition: switch_rtp.c:428
struct error_period * error_log
Definition: switch_types.h:661
static void do_mos(switch_rtp_t *rtp_session, int force)
Definition: switch_rtp.c:1521
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 4742 of file switch_rtp.c.

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

4743 {
4744  return (uint32_t) rtp_session->flags[flags];
4745 }
uint32_t flags[SWITCH_RTP_FLAG_INVALID]
Definition: switch_rtp.c:372
switch_status_t switch_rtp_udptl_mode ( switch_rtp_t rtp_session)

Definition at line 2843 of file switch_rtp.c.

References FALSE, memset(), ping_socket(), READ_DEC, READ_INC, 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, WRITE_DEC, and WRITE_INC.

Referenced by switch_core_media_activate_rtp(), switch_core_media_start_udptl(), and switch_core_media_udptl_mode().

2844 {
2845  switch_socket_t *sock;
2846 
2847  if (!switch_rtp_ready(rtp_session)) {
2848  return SWITCH_STATUS_FALSE;
2849  }
2850 
2852  ping_socket(rtp_session);
2853  }
2854 
2855  READ_INC(rtp_session);
2856  WRITE_INC(rtp_session);
2857 
2858  if (rtp_session->flags[SWITCH_RTP_FLAG_USE_TIMER] || rtp_session->timer.timer_interface) {
2859  switch_core_timer_destroy(&rtp_session->timer);
2860  memset(&rtp_session->timer, 0, sizeof(rtp_session->timer));
2862  }
2863 
2864  rtp_session->missed_count = 0;
2865  rtp_session->max_missed_packets = 0;
2866 
2867  rtp_session->flags[SWITCH_RTP_FLAG_ENABLE_RTCP] = 0;
2868 
2869  if (rtp_session->rtcp_sock_input) {
2870  ping_socket(rtp_session);
2872  }
2873 
2874  if (rtp_session->rtcp_sock_output && rtp_session->rtcp_sock_output != rtp_session->rtcp_sock_input) {
2876  }
2877 
2878  if (rtp_session->flags[SWITCH_RTP_FLAG_RTCP_MUX]) {
2879  rtp_session->rtcp_sock_input = NULL;
2880  rtp_session->rtcp_sock_output = NULL;
2881  } else {
2882  if ((sock = rtp_session->rtcp_sock_input)) {
2883  rtp_session->rtcp_sock_input = NULL;
2884  switch_socket_close(sock);
2885 
2886  if (rtp_session->rtcp_sock_output && rtp_session->rtcp_sock_output != sock) {
2887  if ((sock = rtp_session->rtcp_sock_output)) {
2888  rtp_session->rtcp_sock_output = NULL;
2889  switch_socket_close(sock);
2890  }
2891  }
2892  }
2893  }
2894 
2899 
2900  WRITE_DEC(rtp_session);
2901  READ_DEC(rtp_session);
2902 
2905 
2906  switch_rtp_break(rtp_session);
2907 
2908  return SWITCH_STATUS_SUCCESS;
2909 
2910 }
uint8_t switch_rtp_ready(switch_rtp_t *rtp_session)
Test if an RTP session is ready.
Definition: switch_rtp.c:4452
uint32_t max_missed_packets
Definition: switch_rtp.c:417
#define WRITE_INC(rtp_session)
Definition: switch_rtp.c:62
switch_socket_t * sock_input
Definition: switch_rtp.c:309
switch_socket_t * rtcp_sock_input
Definition: switch_rtp.c:309
#define READ_DEC(rtp_session)
Definition: switch_rtp.c:61
#define WRITE_DEC(rtp_session)
Definition: switch_rtp.c:63
switch_timer_interface_t * timer_interface
uint32_t flags[SWITCH_RTP_FLAG_INVALID]
Definition: switch_rtp.c:372
#define READ_INC(rtp_session)
Definition: switch_rtp.c:60
switch_status_t switch_socket_opt_set(switch_socket_t *sock, int32_t opt, int32_t on)
Definition: switch_apr.c:823
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:309
void switch_rtp_clear_flag(switch_rtp_t *rtp_session, switch_rtp_flag_t flag)
Clear an RTP Flag.
Definition: switch_rtp.c:4747
void switch_rtp_set_flag(switch_rtp_t *rtp_session, switch_rtp_flag_t flag)
Set an RTP Flag.
Definition: switch_rtp.c:4702
uint32_t missed_count
Definition: switch_rtp.c:418
#define SWITCH_SO_NONBLOCK
Definition: switch_apr.h:994
switch_status_t switch_socket_close(switch_socket_t *sock)
Definition: switch_apr.c:714
switch_timer_t timer
Definition: switch_rtp.c:411
void switch_rtp_break(switch_rtp_t *rtp_session)
Definition: switch_rtp.c:4385
switch_status_t switch_socket_shutdown(switch_socket_t *sock, switch_shutdown_how_e how)
Definition: switch_apr.c:709
#define FALSE
static void ping_socket(switch_rtp_t *rtp_session)
Definition: switch_rtp.c:2832
uint32_t switch_rtp_test_flag(switch_rtp_t *rtp_session, switch_rtp_flag_t flags)
Test an RTP Flag.
Definition: switch_rtp.c:4742
struct apr_socket_t switch_socket_t
Definition: switch_apr.h:1026
memset(buf, 0, buflen)
void switch_rtp_video_loss ( switch_rtp_t rtp_session)

Definition at line 4374 of file switch_rtp.c.

References rtp_write_ready(), SWITCH_RTP_FLAG_PLI, and SWITCH_RTP_FLAG_VIDEO.

Referenced by switch_core_media_receive_message().

4375 {
4376  if (!rtp_write_ready(rtp_session, 0, __LINE__)) {
4377  return;
4378  }
4379 
4380  if (rtp_session->flags[SWITCH_RTP_FLAG_VIDEO] && (rtp_session->ice.ice_user || rtp_session->flags[SWITCH_RTP_FLAG_PLI])) {
4381  rtp_session->pli_count = 1;
4382  }
4383 }
uint16_t pli_count
Definition: switch_rtp.c:320
uint32_t flags[SWITCH_RTP_FLAG_INVALID]
Definition: switch_rtp.c:372
static int rtp_write_ready(switch_rtp_t *rtp_session, uint32_t bytes, int line)
Definition: switch_rtp.c:7161
switch_rtp_ice_t ice
Definition: switch_rtp.c:377
void switch_rtp_video_refresh ( switch_rtp_t rtp_session)

Definition at line 4362 of file switch_rtp.c.

References rtp_write_ready(), SWITCH_RTP_FLAG_FIR, and SWITCH_RTP_FLAG_VIDEO.

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

4363 {
4364 
4365  if (!rtp_write_ready(rtp_session, 0, __LINE__)) {
4366  return;
4367  }
4368 
4369  if (rtp_session->flags[SWITCH_RTP_FLAG_VIDEO] && (rtp_session->ice.ice_user || rtp_session->flags[SWITCH_RTP_FLAG_FIR])) {
4370  rtp_session->fir_count = 1;
4371  }
4372 }
uint32_t flags[SWITCH_RTP_FLAG_INVALID]
Definition: switch_rtp.c:372
uint16_t fir_count
Definition: switch_rtp.c:319
static int rtp_write_ready(switch_rtp_t *rtp_session, uint32_t bytes, int line)
Definition: switch_rtp.c:7161
switch_rtp_ice_t ice
Definition: switch_rtp.c:377
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 7726 of file switch_rtp.c.

References payload_map_s::current, payload_map_s::hash, rtp_msg_t::header, INVALID_PT, payload_map_s::negotiated, payload_map_s::next, payload_map_s::pt, payload_map_s::recv_pt, RTP_BUG_GEN_ONE_GEN_ALL, rtp_common_write(), rtp_write_ready(), SFF_CNG, SFF_PROXY_PACKET, SFF_RAW_RTP, SFF_RAW_RTP_PARSE_FRAME, SFF_RTP_HEADER, SFF_UDPTL_PACKET, switch_assert, switch_channel_get_partner_uuid(), switch_channel_get_private(), SWITCH_CHANNEL_SESSION_LOG, switch_core_session_get_channel(), switch_core_session_locate, switch_core_session_rwunlock(), switch_log_printf(), SWITCH_LOG_WARNING, switch_mutex_lock(), switch_mutex_unlock(), switch_rtp_clear_flag(), SWITCH_RTP_FLAG_PROXY_MEDIA, SWITCH_RTP_FLAG_RAW_WRITE, SWITCH_RTP_FLAG_RESET, SWITCH_RTP_FLAG_UDPTL, SWITCH_RTP_FLAG_VIDEO, switch_rtp_ready(), switch_rtp_write_manual(), switch_socket_sendto(), SWITCH_STATUS_SUCCESS, switch_test_flag, SWITCH_ZRTP_FLAG_SECURE_MITM_RECV, and SWITCH_ZRTP_FLAG_SECURE_MITM_SEND.

Referenced by switch_core_media_write_frame().

7727 {
7728  uint8_t fwd = 0;
7729  void *data = NULL;
7730  uint32_t len, ts = 0;
7731  switch_payload_t payload = 0;
7732  rtp_msg_t *send_msg = NULL;
7733  srtp_hdr_t local_header;
7734  int r = 0;
7735 
7736  if (!switch_rtp_ready(rtp_session) || !rtp_session->remote_addr) {
7737  return -1;
7738  }
7739 
7740  if (!rtp_write_ready(rtp_session, frame->datalen, __LINE__)) {
7741  return 0;
7742  }
7743 
7744  //if (rtp_session->flags[SWITCH_RTP_FLAG_VIDEO]) {
7745  // rtp_session->flags[SWITCH_RTP_FLAG_DEBUG_RTP_READ]++;
7746  // rtp_session->flags[SWITCH_RTP_FLAG_DEBUG_RTP_WRITE]++;
7747  //}
7748 
7749 
7751  rtp_session->flags[SWITCH_RTP_FLAG_PROXY_MEDIA] || rtp_session->flags[SWITCH_RTP_FLAG_UDPTL]) {
7752 
7753  //if (rtp_session->flags[SWITCH_RTP_FLAG_PROXY_MEDIA] || rtp_session->flags[SWITCH_RTP_FLAG_UDPTL]) {
7754  switch_size_t bytes;
7755  //char bufa[50];
7756 
7757  /* Fast PASS! */
7759  return 0;
7760  }
7761  bytes = frame->packetlen;
7762  //tx_host = switch_get_addr(bufa, sizeof(bufa), rtp_session->remote_addr);
7763 
7764  send_msg = frame->packet;
7765 
7766  if (!rtp_session->flags[SWITCH_RTP_FLAG_UDPTL] && !switch_test_flag(frame, SFF_UDPTL_PACKET)) {
7767 
7768  if (rtp_session->flags[SWITCH_RTP_FLAG_VIDEO] && rtp_session->payload > 0) {
7769  send_msg->header.pt = rtp_session->payload;
7770  }
7771 
7772  send_msg->header.ssrc = htonl(rtp_session->ssrc);
7773  send_msg->header.seq = htons(++rtp_session->seq);
7774  }
7775 
7776  if (switch_socket_sendto(rtp_session->sock_output, rtp_session->remote_addr, 0, frame->packet, &bytes) != SWITCH_STATUS_SUCCESS) {
7777  return -1;
7778  }
7779 
7780 
7781  rtp_session->stats.outbound.raw_bytes += bytes;
7782  rtp_session->stats.outbound.media_bytes += bytes;
7783  rtp_session->stats.outbound.media_packet_count++;
7784  rtp_session->stats.outbound.packet_count++;
7785  return (int) bytes;
7786  }
7787 #ifdef ENABLE_ZRTP
7788  if (zrtp_on && rtp_session->flags[SWITCH_ZRTP_FLAG_SECURE_MITM_SEND]) {
7789  zrtp_session_info_t zrtp_session_info;
7790 
7791  if (zrtp_status_ok == zrtp_session_get(rtp_session->zrtp_session, &zrtp_session_info)) {
7792  if (zrtp_session_info.sas_is_ready) {
7793 
7794  switch_channel_t *channel = switch_core_session_get_channel(rtp_session->session);
7795 
7796  const char *uuid = switch_channel_get_partner_uuid(channel);
7797  if (uuid) {
7798  switch_core_session_t *other_session;
7799 
7800  if ((other_session = switch_core_session_locate(uuid))) {
7801  switch_channel_t *other_channel = switch_core_session_get_channel(other_session);
7802  switch_rtp_t *other_rtp_session = switch_channel_get_private(other_channel, "__zrtp_audio_rtp_session");
7803 
7804 
7805  if (other_rtp_session) {
7806  if (zrtp_status_ok == zrtp_session_get(other_rtp_session->zrtp_session, &zrtp_session_info)) {
7807  if (rtp_session->zrtp_mitm_tries > ZRTP_MITM_TRIES) {
7808  rtp_session->flags[SWITCH_ZRTP_FLAG_SECURE_MITM_RECV] = 0;
7809  rtp_session->flags[SWITCH_ZRTP_FLAG_SECURE_MITM_SEND] = 0;
7812  } else if (zrtp_status_ok == zrtp_resolve_mitm_call(other_rtp_session->zrtp_stream, rtp_session->zrtp_stream)) {
7813  rtp_session->flags[SWITCH_ZRTP_FLAG_SECURE_MITM_RECV] = 0;
7814  rtp_session->flags[SWITCH_ZRTP_FLAG_SECURE_MITM_SEND] = 0;
7817  rtp_session->zrtp_mitm_tries++;
7818  }
7819  rtp_session->zrtp_mitm_tries++;
7820  }
7821  }
7822 
7823  switch_core_session_rwunlock(other_session);
7824  }
7825  }
7826  }
7827  }
7828  }
7829 #endif
7830 
7831  fwd = (rtp_session->flags[SWITCH_RTP_FLAG_RAW_WRITE] &&
7833 
7834  if (!fwd && !rtp_session->sending_dtmf && !rtp_session->queue_delay &&
7835  rtp_session->flags[SWITCH_RTP_FLAG_RAW_WRITE] && (rtp_session->rtp_bugs & RTP_BUG_GEN_ONE_GEN_ALL)) {
7836 
7837  switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(rtp_session->session), SWITCH_LOG_WARNING, "Generating RTP locally but timestamp passthru is configured, disabling....\n");
7838  rtp_session->flags[SWITCH_RTP_FLAG_RAW_WRITE] = 0;
7839  rtp_session->flags[SWITCH_RTP_FLAG_RESET] = 1;
7840  }
7841 
7842  switch_assert(frame != NULL);
7843 
7844  if (switch_test_flag(frame, SFF_CNG)) {
7845  if (rtp_session->cng_pt != INVALID_PT) {
7846  payload = rtp_session->cng_pt;
7847  } else {
7848  return (int) frame->packetlen;
7849  }
7850  } else {
7851  payload = rtp_session->payload;
7852 #if 0
7853  if (rtp_session->pmaps && *rtp_session->pmaps) {
7854  payload_map_t *pmap;
7855  for (pmap = *rtp_session->pmaps; pmap; pmap = pmap->next) {
7856  if (pmap->current) {
7857  payload = pmap->pt;
7858  }
7859  }
7860  }
7861 #endif
7862  }
7863 
7864  if (switch_test_flag(frame, SFF_RTP_HEADER)) {
7865  switch_size_t wrote = switch_rtp_write_manual(rtp_session, frame->data, frame->datalen,
7866  frame->m, frame->payload, (uint32_t) (frame->timestamp), &frame->flags);
7867 
7868  rtp_session->stats.outbound.raw_bytes += wrote;
7869  rtp_session->stats.outbound.media_bytes += wrote;
7870  rtp_session->stats.outbound.media_packet_count++;
7871  rtp_session->stats.outbound.packet_count++;
7872  }
7873 
7874  if (frame->pmap && rtp_session->pmaps && *rtp_session->pmaps) {
7875  payload_map_t *pmap;
7876 
7877  switch_mutex_lock(rtp_session->flag_mutex);
7878  for (pmap = *rtp_session->pmaps; pmap; pmap = pmap->next) {
7879  if (pmap->negotiated && pmap->hash == frame->pmap->hash) {
7880  payload = pmap->recv_pt;
7881  break;
7882  }
7883  }
7884  switch_mutex_unlock(rtp_session->flag_mutex);
7885  }
7886 
7887  if (fwd) {
7888  send_msg = frame->packet;
7889  local_header = send_msg->header;
7890  len = frame->packetlen;
7891  ts = 0;
7892 
7893  send_msg->header.pt = payload;
7894 
7896  send_msg->header.version = 2;
7897  send_msg->header.m = frame->m;
7898  send_msg->header.ts = htonl(frame->timestamp);
7899  if (frame->ssrc) {
7900  send_msg->header.ssrc = htonl(frame->ssrc);
7901  } else {
7902  send_msg->header.ssrc = htonl(rtp_session->ssrc);
7903  }
7904  }
7905 
7906  } else {
7907  data = frame->data;
7908  len = frame->datalen;
7909  ts = rtp_session->flags[SWITCH_RTP_FLAG_RAW_WRITE] ? (uint32_t) frame->timestamp : 0;
7910  }
7911 
7912  /*
7913  if (rtp_session->flags[SWITCH_RTP_FLAG_VIDEO]) {
7914  send_msg->header.pt = rtp_session->payload;
7915  }
7916  */
7917 
7918  r = rtp_common_write(rtp_session, send_msg, data, len, payload, ts, &frame->flags);
7919 
7920  if (send_msg) {
7921  send_msg->header = local_header;
7922  }
7923 
7924  return r;
7925 
7926 }
uint32_t queue_delay
Definition: switch_rtp.c:370
switch_bool_t m
Definition: switch_frame.h:72
#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:4452
const char * switch_channel_get_partner_uuid(switch_channel_t *channel)
switch_sockaddr_t * remote_addr
Definition: switch_rtp.c:326
switch_mutex_t * flag_mutex
Definition: switch_rtp.c:407
uint32_t timestamp
Definition: switch_frame.h:69
unsigned long hash
switch_size_t media_bytes
Definition: switch_types.h:628
uint32_t ssrc
Definition: switch_frame.h:71
struct payload_map_s * next
switch_payload_t cng_pt
Definition: switch_rtp.c:406
switch_status_t switch_mutex_unlock(switch_mutex_t *lock)
Definition: switch_apr.c:290
_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:7183
switch_size_t raw_bytes
Definition: switch_types.h:627
uint32_t datalen
Definition: switch_frame.h:57
uint32_t packetlen
Definition: switch_frame.h:51
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:773
switch_frame_flag_t flags
Definition: switch_frame.h:74
switch_status_t switch_mutex_lock(switch_mutex_t *lock)
Definition: switch_apr.c:285
payload_map_t * pmap
Definition: switch_frame.h:76
uint32_t flags[SWITCH_RTP_FLAG_INVALID]
Definition: switch_rtp.c:372
switch_rtp_numbers_t outbound
Definition: switch_types.h:691
static int rtp_write_ready(switch_rtp_t *rtp_session, uint32_t bytes, int line)
Definition: switch_rtp.c:7161
uintptr_t switch_size_t
uint8_t negotiated
uint16_t seq
Definition: switch_rtp.c:353
switch_payload_t pt
switch_size_t packet_count
Definition: switch_types.h:629
switch_rtp_stats_t stats
Definition: switch_rtp.c:428
void switch_core_session_rwunlock(_In_ switch_core_session_t *session)
Unlock a read or write lock on as given session.
void switch_rtp_clear_flag(switch_rtp_t *rtp_session, switch_rtp_flag_t flag)
Clear an RTP Flag.
Definition: switch_rtp.c:4747
payload_map_t ** pmaps
Definition: switch_rtp.c:447
void * packet
Definition: switch_frame.h:49
void * switch_channel_get_private(switch_channel_t *channel, const char *key)
Retrieve private from a given channel.
srtp_hdr_t header
Definition: switch_rtp.c:112
#define switch_core_session_locate(uuid_str)
Locate a session based on it's uuid.
Definition: switch_core.h:916
switch_core_session_t * session
Definition: switch_rtp.c:446
int8_t sending_dtmf
Definition: switch_rtp.c:357
switch_size_t media_packet_count
Definition: switch_types.h:631
switch_rtp_bug_flag_t rtp_bugs
Definition: switch_rtp.c:427
uint32_t ssrc
Definition: switch_rtp.c:354
switch_payload_t payload
Definition: switch_frame.h:67
#define switch_test_flag(obj, flag)
Test for the existance of a flag on an arbitary object.
Definition: switch_utils.h:624
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
static const switch_payload_t INVALID_PT
Definition: switch_rtp.c:75
#define switch_assert(expr)
switch_payload_t payload
Definition: switch_rtp.c:359
switch_socket_t * sock_output
Definition: switch_rtp.c:309
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:7955
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 7955 of file switch_rtp.c.

References INVALID_PT, rtp_header_len, rtp_write_ready(), 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, and WRITE_INC.

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

7957 {
7958  switch_size_t bytes;
7959  int ret = -1;
7960 
7961  if (!switch_rtp_ready(rtp_session) || !rtp_session->remote_addr || datalen > SWITCH_RTP_MAX_BUF_LEN) {
7962  return -1;
7963  }
7964 
7965  if (!rtp_write_ready(rtp_session, datalen, __LINE__)) {
7966  return 0;
7967  }
7968 
7969  if (payload == INVALID_PT) {
7970  return 0;
7971  }
7972 
7973  WRITE_INC(rtp_session);
7974 
7975  rtp_session->write_msg = rtp_session->send_msg;
7976  rtp_session->write_msg.header.seq = htons(++rtp_session->seq);
7977  rtp_session->write_msg.header.ts = htonl(ts);
7978  rtp_session->write_msg.header.pt = payload;
7979  rtp_session->write_msg.header.m = m;
7980  memcpy(rtp_session->write_msg.body, data, datalen);
7981 
7982  bytes = rtp_header_len + datalen;
7983 
7984  if (switch_rtp_write_raw(rtp_session, (void *) &rtp_session->write_msg, &bytes, SWITCH_TRUE) != SWITCH_STATUS_SUCCESS) {
7985  rtp_session->seq--;
7986  ret = -1;
7987  goto end;
7988  }
7989 
7990  if (((*flags) & SFF_RTP_HEADER)) {
7991  rtp_session->last_write_ts = ts;
7992  rtp_session->flags[SWITCH_RTP_FLAG_RESET] = 0;
7993  }
7994 
7995  ret = (int) bytes;
7996 
7997  end:
7998 
7999  WRITE_DEC(rtp_session);
8000 
8001  return ret;
8002 }
char body[SWITCH_RTP_MAX_BUF_LEN]
Definition: switch_rtp.c:113
uint8_t switch_rtp_ready(switch_rtp_t *rtp_session)
Test if an RTP session is ready.
Definition: switch_rtp.c:4452
switch_sockaddr_t * remote_addr
Definition: switch_rtp.c:326
#define WRITE_INC(rtp_session)
Definition: switch_rtp.c:62
#define SWITCH_RTP_MAX_BUF_LEN
Definition: switch_rtp.h:44
#define WRITE_DEC(rtp_session)
Definition: switch_rtp.c:63
uint32_t flags[SWITCH_RTP_FLAG_INVALID]
Definition: switch_rtp.c:372
static int rtp_write_ready(switch_rtp_t *rtp_session, uint32_t bytes, int line)
Definition: switch_rtp.c:7161
uintptr_t switch_size_t
uint16_t seq
Definition: switch_rtp.c:353
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:8006
rtp_msg_t write_msg
Definition: switch_rtp.c:419
srtp_hdr_t header
Definition: switch_rtp.c:112
uint32_t last_write_ts
Definition: switch_rtp.c:363
rtp_msg_t send_msg
Definition: switch_rtp.c:314
static const switch_payload_t INVALID_PT
Definition: switch_rtp.c:75
#define rtp_header_len
Definition: switch_rtp.c:66
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 8006 of file switch_rtp.c.

References rtp_write_ready(), switch_assert, SWITCH_CHANNEL_LOG, SWITCH_CHANNEL_SESSION_LOG, SWITCH_FALSE, SWITCH_LOG_ERROR, SWITCH_LOG_INFO, switch_log_printf(), switch_rtp_clear_flag(), SWITCH_RTP_FLAG_PROXY_MEDIA, SWITCH_RTP_FLAG_SECURE_SEND, SWITCH_RTP_FLAG_SECURE_SEND_RESET, SWITCH_RTP_MAX_BUF_LEN, switch_rtp_ready(), switch_socket_sendto(), SWITCH_STATUS_FALSE, SWITCH_STATUS_NOT_INITALIZED, SWITCH_STATUS_SUCCESS, WRITE_DEC, and WRITE_INC.

Referenced by handle_nack(), and switch_rtp_write_manual().

8007 {
8009 
8010  switch_assert(bytes);
8011 
8012  if (!switch_rtp_ready(rtp_session) || !rtp_session->remote_addr || *bytes > SWITCH_RTP_MAX_BUF_LEN) {
8013  return status;
8014  }
8015 
8016  if (!rtp_write_ready(rtp_session, *bytes, __LINE__)) {
8018  }
8019 
8020  WRITE_INC(rtp_session);
8021 
8022  if (process_encryption) {
8023  process_encryption = SWITCH_FALSE;
8024 #ifdef ENABLE_SRTP
8025  if (rtp_session->flags[SWITCH_RTP_FLAG_SECURE_SEND]) {
8026 
8027  int sbytes = (int) *bytes;
8028  err_status_t stat;
8029 
8030  if (rtp_session->flags[SWITCH_RTP_FLAG_SECURE_SEND_RESET]) {
8032  srtp_dealloc(rtp_session->send_ctx[rtp_session->srtp_idx_rtp]);
8033  rtp_session->send_ctx[rtp_session->srtp_idx_rtp] = NULL;
8034  if ((stat = srtp_create(&rtp_session->send_ctx[rtp_session->srtp_idx_rtp],
8035  &rtp_session->send_policy[rtp_session->srtp_idx_rtp])) || !rtp_session->send_ctx[rtp_session->srtp_idx_rtp]) {
8036  switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(rtp_session->session), SWITCH_LOG_ERROR, "Error! RE-Activating Secure RTP SEND\n");
8037  rtp_session->flags[SWITCH_RTP_FLAG_SECURE_SEND] = 0;
8038  status = SWITCH_STATUS_FALSE;
8039  goto end;
8040  } else {
8041  switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(rtp_session->session), SWITCH_LOG_INFO, "RE-Activating Secure RTP SEND\n");
8042  }
8043  }
8044 
8045  stat = srtp_protect(rtp_session->send_ctx[rtp_session->srtp_idx_rtp], &rtp_session->write_msg.header, &sbytes);
8046  if (stat) {
8047  switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(rtp_session->session), SWITCH_LOG_ERROR, "Error: SRTP protection failed with code %d\n", stat);
8048  }
8049  *bytes = sbytes;
8050  }
8051 #endif
8052 #ifdef ENABLE_ZRTP
8053  /* ZRTP Send */
8054  if (zrtp_on && !rtp_session->flags[SWITCH_RTP_FLAG_PROXY_MEDIA]) {
8055  unsigned int sbytes = (int) *bytes;
8056  zrtp_status_t stat = zrtp_status_fail;
8057 
8058  stat = zrtp_process_rtp(rtp_session->zrtp_stream, (void *) &rtp_session->write_msg, &sbytes);
8059 
8060  switch (stat) {
8061  case zrtp_status_ok:
8062  break;
8063  case zrtp_status_drop:
8064  switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Error: zRTP protection drop with code %d\n", stat);
8065  status = SWITCH_STATUS_SUCCESS;
8066  goto end;
8067  break;
8068  case zrtp_status_fail:
8069  switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Error: zRTP protection fail with code %d\n", stat);
8070  break;
8071  default:
8072  break;
8073  }
8074 
8075  *bytes = sbytes;
8076  }
8077 #endif
8078  }
8079 
8080  status = switch_socket_sendto(rtp_session->sock_output, rtp_session->remote_addr, 0, data, bytes);
8081 
8082  end:
8083 
8084  WRITE_DEC(rtp_session);
8085 
8086  return status;
8087 }
#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:4452
#define SWITCH_CHANNEL_LOG
switch_sockaddr_t * remote_addr
Definition: switch_rtp.c:326
#define WRITE_INC(rtp_session)
Definition: switch_rtp.c:62
srtp_policy_t send_policy[2]
Definition: switch_rtp.c:338
#define SWITCH_RTP_MAX_BUF_LEN
Definition: switch_rtp.h:44
srtp_ctx_t * send_ctx[2]
Definition: switch_rtp.c:335
#define WRITE_DEC(rtp_session)
Definition: switch_rtp.c:63
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:773
uint32_t flags[SWITCH_RTP_FLAG_INVALID]
Definition: switch_rtp.c:372
static int rtp_write_ready(switch_rtp_t *rtp_session, uint32_t bytes, int line)
Definition: switch_rtp.c:7161
void switch_rtp_clear_flag(switch_rtp_t *rtp_session, switch_rtp_flag_t flag)
Clear an RTP Flag.
Definition: switch_rtp.c:4747
rtp_msg_t write_msg
Definition: switch_rtp.c:419
switch_status_t
Common return values.
srtp_hdr_t header
Definition: switch_rtp.c:112
switch_core_session_t * session
Definition: switch_rtp.c:446
int srtp_idx_rtp
Definition: switch_rtp.c:345
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:309
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 7135 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.

7138 {
7139  int bytes = 0;
7140 
7141  if (!switch_rtp_ready(rtp_session)) {
7142  return SWITCH_STATUS_FALSE;
7143  }
7144 
7145  bytes = rtp_common_read(rtp_session, payload_type, NULL, flags, io_flags);
7146  *data = RTP_BODY(rtp_session);
7147 
7148  if (bytes < 0) {
7149  *datalen = 0;
7150  return SWITCH_STATUS_GENERR;
7151  } else {
7152  if (bytes > rtp_header_len) {
7153  bytes -= rtp_header_len;
7154  }
7155  }
7156 
7157  *datalen = bytes;
7158  return SWITCH_STATUS_SUCCESS;
7159 }
uint8_t switch_rtp_ready(switch_rtp_t *rtp_session)
Test if an RTP session is ready.
Definition: switch_rtp.c:4452
#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:6140
#define rtp_header_len
Definition: switch_rtp.c:66
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 7036 of file switch_rtp.c.

References switch_rtp::read_mutex, RTP_BODY, rtp_common_read(), rtp_header_len, SFF_CNG, SFF_RAW_RTP, SFF_RFC2833, SWITCH_CALL_DIRECTION_INBOUND, switch_channel_direction(), switch_channel_get_partner_uuid(), switch_channel_get_private(), switch_core_session_get_channel(), switch_core_session_locate, switch_core_session_rwunlock(), SWITCH_FALSE, switch_mutex_lock(), switch_mutex_unlock(), switch_rtp_clear_flag(), 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, SWITCH_ZRTP_FLAG_SECURE_MITM_RECV, and SWITCH_ZRTP_FLAG_SECURE_MITM_SEND.

Referenced by check_engine(), and switch_core_media_read_frame().

7037 {
7038  int bytes = 0;
7039 
7040  if (!switch_rtp_ready(rtp_session)) {
7041  return SWITCH_STATUS_FALSE;
7042  }
7043 
7044  bytes = rtp_common_read(rtp_session, &frame->payload, &frame->pmap, &frame->flags, io_flags);
7045 
7046  frame->data = RTP_BODY(rtp_session);
7047 
7048  if (!rtp_session->flags[SWITCH_RTP_FLAG_UDPTL] && (bytes < rtp_header_len || switch_test_flag(frame, SFF_CNG))) {
7049  frame->packet = NULL;
7050  frame->timestamp = 0;
7051  frame->seq = 0;
7052  frame->ssrc = 0;
7053  frame->m = 0;
7054  } else {
7055 
7056  frame->packet = &rtp_session->recv_msg;
7057  frame->packetlen = bytes;
7058  frame->source = __FILE__;
7059 
7060  switch_set_flag(frame, SFF_RAW_RTP);
7061  if (frame->payload == rtp_session->recv_te) {
7062  switch_set_flag(frame, SFF_RFC2833);
7063  }
7064  frame->timestamp = ntohl(rtp_session->last_rtp_hdr.ts);
7065  frame->seq = (uint16_t) ntohs((uint16_t) rtp_session->last_rtp_hdr.seq);
7066  frame->ssrc = ntohl(rtp_session->last_rtp_hdr.ssrc);
7067  frame->m = rtp_session->last_rtp_hdr.m ? SWITCH_TRUE : SWITCH_FALSE;
7068  }
7069 
7070 #ifdef ENABLE_ZRTP
7071  if (zrtp_on && rtp_session->flags[SWITCH_ZRTP_FLAG_SECURE_MITM_RECV]) {
7072  zrtp_session_info_t zrtp_session_info;
7073 
7074  if (rtp_session->zrtp_session && (zrtp_status_ok == zrtp_session_get(rtp_session->zrtp_session, &zrtp_session_info))) {
7075  if (zrtp_session_info.sas_is_ready) {
7076 
7077  switch_channel_t *channel = switch_core_session_get_channel(rtp_session->session);
7078 
7079  const char *uuid = switch_channel_get_partner_uuid(channel);
7080  if (uuid) {
7081  switch_core_session_t *other_session;
7082 
7083  if ((other_session = switch_core_session_locate(uuid))) {
7084  switch_channel_t *other_channel = switch_core_session_get_channel(other_session);
7085  switch_rtp_t *other_rtp_session = switch_channel_get_private(other_channel, "__zrtp_audio_rtp_session");
7086 
7087  if (other_rtp_session) {
7089  switch_mutex_lock(other_rtp_session->read_mutex);
7090  if (zrtp_status_ok == zrtp_session_get(other_rtp_session->zrtp_session, &zrtp_session_info)) {
7091  if (rtp_session->zrtp_mitm_tries > ZRTP_MITM_TRIES) {
7094  rtp_session->flags[SWITCH_ZRTP_FLAG_SECURE_MITM_RECV] = 0;
7095  rtp_session->flags[SWITCH_ZRTP_FLAG_SECURE_MITM_SEND] = 0;
7096  } else if (zrtp_status_ok == zrtp_resolve_mitm_call(other_rtp_session->zrtp_stream, rtp_session->zrtp_stream)) {
7097  rtp_session->flags[SWITCH_ZRTP_FLAG_SECURE_MITM_RECV] = 0;
7098  rtp_session->flags[SWITCH_ZRTP_FLAG_SECURE_MITM_SEND] = 0;
7101  rtp_session->zrtp_mitm_tries++;
7102  }
7103  }
7104  switch_mutex_unlock(other_rtp_session->read_mutex);
7105  }
7106  }
7107 
7108  switch_core_session_rwunlock(other_session);
7109  }
7110  }
7111  }
7112  } else {
7113  rtp_session->flags[SWITCH_ZRTP_FLAG_SECURE_MITM_RECV] = 0;
7114  rtp_session->flags[SWITCH_ZRTP_FLAG_SECURE_MITM_SEND] = 0;
7115  }
7116  }
7117 #endif
7118 
7119  if (bytes < 0) {
7120  frame->datalen = 0;
7121  return bytes == -2 ? SWITCH_STATUS_TIMEOUT : SWITCH_STATUS_GENERR;
7122  } else if (!rtp_session->flags[SWITCH_RTP_FLAG_UDPTL]) {
7123  if (bytes < rtp_header_len) {
7124  frame->datalen = 0;
7125  return SWITCH_STATUS_BREAK;
7126  } else {
7127  bytes -= rtp_header_len;
7128  }
7129  }
7130 
7131  frame->datalen = bytes;
7132  return SWITCH_STATUS_SUCCESS;
7133 }
switch_bool_t m
Definition: switch_frame.h:72
#define switch_set_flag(obj, flag)
Set a flag on an arbitrary object.
Definition: switch_utils.h:631
uint8_t switch_rtp_ready(switch_rtp_t *rtp_session)
Test if an RTP session is ready.
Definition: switch_rtp.c:4452
const char * switch_channel_get_partner_uuid(switch_channel_t *channel)
uint32_t timestamp
Definition: switch_frame.h:69
const char * source
Definition: switch_frame.h:47
uint32_t ssrc
Definition: switch_frame.h:71
switch_status_t switch_mutex_unlock(switch_mutex_t *lock)
Definition: switch_apr.c:290
_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.
uint16_t seq
Definition: switch_frame.h:70
uint32_t datalen
Definition: switch_frame.h:57
uint32_t packetlen
Definition: switch_frame.h:51
switch_frame_flag_t flags
Definition: switch_frame.h:74
switch_status_t switch_mutex_lock(switch_mutex_t *lock)
Definition: switch_apr.c:285
payload_map_t * pmap
Definition: switch_frame.h:76
uint32_t flags[SWITCH_RTP_FLAG_INVALID]
Definition: switch_rtp.c:372
void switch_core_session_rwunlock(_In_ switch_core_session_t *session)
Unlock a read or write lock on as given session.
#define RTP_BODY(_s)
Definition: switch_rtp.c:118
void switch_rtp_clear_flag(switch_rtp_t *rtp_session, switch_rtp_flag_t flag)
Clear an RTP Flag.
Definition: switch_rtp.c:4747
void * packet
Definition: switch_frame.h:49
switch_mutex_t * read_mutex
Definition: switch_rtp.c:408
void * switch_channel_get_private(switch_channel_t *channel, const char *key)
Retrieve private from a given channel.
rtp_msg_t recv_msg
Definition: switch_rtp.c:327
#define switch_core_session_locate(uuid_str)
Locate a session based on it's uuid.
Definition: switch_core.h:916
switch_core_session_t * session
Definition: switch_rtp.c:446
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:6140
switch_call_direction_t switch_channel_direction(switch_channel_t *channel)
switch_payload_t recv_te
Definition: switch_rtp.c:405
switch_payload_t payload
Definition: switch_frame.h:67
#define switch_test_flag(obj, flag)
Test for the existance of a flag on an arbitary object.
Definition: switch_utils.h:624
rtp_hdr_t last_rtp_hdr
Definition: switch_rtp.c:351
#define rtp_header_len
Definition: switch_rtp.c:66