FreeSWITCH API Documentation  1.7.0
Data Structures | Macros | Typedefs | Enumerations | Functions
switch_core_media.h File Reference
#include <switch.h>
+ Include dependency graph for switch_core_media.h:
+ This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Data Structures

struct  switch_core_media_params_s
 

Macros

#define SWITCH_MAX_CAND_ACL   25
 
#define SWITCH_NO_CRYPTO_TAG   -1
 
#define switch_core_media_gen_key_frame(_session)
 
#define switch_core_media_write_bandwidth(_session, _val)
 
#define switch_core_media_read_lock(_s, _t)   switch_core_media_read_lock_unlock(_s, _t, SWITCH_TRUE)
 
#define switch_core_media_read_unlock(_s, _t)   switch_core_media_read_lock_unlock(_s, _t, SWITCH_FALSE)
 

Typedefs

typedef struct
switch_core_media_params_s 
switch_core_media_params_t
 

Enumerations

enum  switch_core_media_dtmf_t { DTMF_AUTO, DTMF_2833, DTMF_INFO, DTMF_NONE }
 
enum  switch_core_media_NDLB_t {
  SM_NDLB_ALLOW_BAD_IANANAME = (1 << 0), SM_NDLB_ALLOW_NONDUP_SDP = (1 << 1), SM_NDLB_ALLOW_CRYPTO_IN_AVP = (1 << 2), SM_NDLB_DISABLE_SRTP_AUTH = (1 << 3),
  SM_NDLB_SENDRECV_IN_SESSION = (1 << 4), SM_NDLB_NEVER_PATCH_REINVITE = (1 << 5)
}
 
enum  switch_core_media_flag_t {
  SCMF_RUNNING, SCMF_DISABLE_TRANSCODING, SCMF_AUTOFIX_TIMING, SCMF_CODEC_GREEDY,
  SCMF_CODEC_SCROOGE, SCMF_DISABLE_HOLD, SCMF_RENEG_ON_HOLD, SCMF_RENEG_ON_REINVITE,
  SCMF_LIBERAL_DTMF, SCMF_SUPPRESS_CNG, SCMF_DISABLE_RTP_AUTOADJ, SCMF_PASS_RFC2833,
  SCMF_AUTOFLUSH, SCMF_REWRITE_TIMESTAMPS, SCMF_RTP_AUTOFLUSH_DURING_BRIDGE, SCMF_MULTI_ANSWER_AUDIO,
  SCMF_MULTI_ANSWER_VIDEO, SCMF_MAX
}
 
enum  STUNFLAGS { STUN_FLAG_SET = (1 << 0), STUN_FLAG_PING = (1 << 1), STUN_FLAG_FUNNY = (1 << 2) }
 
enum  switch_core_media_vflag_t { VAD_IN = (1 << 0), VAD_OUT = (1 << 1) }
 

Functions

static const char * switch_media_type2str (switch_media_type_t type)
 
switch_status_t switch_media_handle_create (switch_media_handle_t **smhp, switch_core_session_t *session, switch_core_media_params_t *params)
 
void switch_media_handle_destroy (switch_core_session_t *session)
 
switch_media_handle_tswitch_core_session_get_media_handle (switch_core_session_t *session)
 
switch_status_t switch_core_session_clear_media_handle (switch_core_session_t *session)
 
switch_status_t switch_core_session_media_handle_ready (switch_core_session_t *session)
 
void switch_media_handle_set_media_flag (switch_media_handle_t *smh, switch_core_media_flag_t flag)
 
void switch_media_handle_clear_media_flag (switch_media_handle_t *smh, switch_core_media_flag_t flag)
 
int32_t switch_media_handle_test_media_flag (switch_media_handle_t *smh, switch_core_media_flag_t flag)
 
void switch_media_handle_set_media_flags (switch_media_handle_t *smh, switch_core_media_flag_t flags[])
 
void switch_core_session_check_outgoing_crypto (switch_core_session_t *session)
 
const char * switch_core_session_local_crypto_key (switch_core_session_t *session, switch_media_type_t type)
 
int switch_core_session_check_incoming_crypto (switch_core_session_t *session, const char *varname, switch_media_type_t type, const char *crypto, int crypto_tag, switch_sdp_type_t sdp_type)
 
uint32_t switch_core_media_get_video_fps (switch_core_session_t *session)
 
void switch_core_media_set_rtp_session (switch_core_session_t *session, switch_media_type_t type, switch_rtp_t *rtp_session)
 
const char * switch_core_media_get_codec_string (switch_core_session_t *session)
 
void switch_core_media_parse_rtp_bugs (switch_rtp_bug_flag_t *flag_pole, const char *str)
 
switch_t38_options_tswitch_core_media_extract_t38_options (switch_core_session_t *session, const char *r_sdp)
 
void switch_core_media_pass_zrtp_hash (switch_core_session_t *session)
 
const char * switch_core_media_get_zrtp_hash (switch_core_session_t *session, switch_media_type_t type, switch_bool_t local)
 
void switch_core_media_pass_zrtp_hash2 (switch_core_session_t *aleg_session, switch_core_session_t *bleg_session)
 
int switch_core_media_toggle_hold (switch_core_session_t *session, int sendonly)
 
void switch_core_media_copy_t38_options (switch_t38_options_t *t38_options, switch_core_session_t *session)
 
uint8_t switch_core_media_negotiate_sdp (switch_core_session_t *session, const char *r_sdp, uint8_t *proceed, switch_sdp_type_t sdp_type)
 
switch_status_t switch_core_media_set_video_codec (switch_core_session_t *session, int force)
 
switch_status_t switch_core_media_set_codec (switch_core_session_t *session, int force, uint32_t codec_flags)
 
void switch_core_media_check_video_codecs (switch_core_session_t *session)
 
switch_status_t switch_core_media_read_frame (switch_core_session_t *session, switch_frame_t **frame, switch_io_flag_t flags, int stream_id, switch_media_type_t type)
 
switch_status_t switch_core_media_write_frame (switch_core_session_t *session, switch_frame_t *frame, switch_io_flag_t flags, int stream_id, switch_media_type_t type)
 
int switch_core_media_check_nat (switch_media_handle_t *smh, const char *network_ip)
 
switch_status_t switch_core_media_choose_port (switch_core_session_t *session, switch_media_type_t type, int force)
 
switch_status_t switch_core_media_choose_ports (switch_core_session_t *session, switch_bool_t audio, switch_bool_t video)
 
void switch_core_media_check_dtmf_type (switch_core_session_t *session)
 
void switch_core_media_absorb_sdp (switch_core_session_t *session)
 
switch_status_t switch_core_media_proxy_remote_addr (switch_core_session_t *session, const char *sdp_str)
 
void switch_core_media_deactivate_rtp (switch_core_session_t *session)
 
switch_status_t switch_core_media_activate_rtp (switch_core_session_t *session)
 
switch_status_t switch_core_media_ext_address_lookup (switch_core_session_t *session, char **ip, switch_port_t *port, const char *sourceip)
 
switch_status_t switch_core_media_process_t38_passthru (switch_core_session_t *session, switch_core_session_t *other_session, switch_t38_options_t *t38_options)
 
void switch_core_media_gen_local_sdp (switch_core_session_t *session, switch_sdp_type_t sdp_type, const char *ip, switch_port_t port, const char *sr, int force)
 
void switch_core_media_set_local_sdp (switch_core_session_t *session, const char *sdp_str, switch_bool_t dup)
 
void switch_core_media_patch_sdp (switch_core_session_t *session)
 
void switch_core_media_set_udptl_image_sdp (switch_core_session_t *session, switch_t38_options_t *t38_options, int insist)
 
switch_core_media_params_tswitch_core_media_get_mparams (switch_media_handle_t *smh)
 
void switch_core_media_prepare_codecs (switch_core_session_t *session, switch_bool_t force)
 
void switch_core_media_start_udptl (switch_core_session_t *session, switch_t38_options_t *t38_options)
 
void switch_core_media_hard_mute (switch_core_session_t *session, switch_bool_t on)
 
switch_status_t switch_core_media_receive_message (switch_core_session_t *session, switch_core_session_message_t *msg)
 
void switch_core_media_break (switch_core_session_t *session, switch_media_type_t type)
 
void switch_core_media_kill_socket (switch_core_session_t *session, switch_media_type_t type)
 
switch_status_t switch_core_media_queue_rfc2833 (switch_core_session_t *session, switch_media_type_t type, const switch_dtmf_t *dtmf)
 
switch_status_t switch_core_media_queue_rfc2833_in (switch_core_session_t *session, switch_media_type_t type, const switch_dtmf_t *dtmf)
 
uint8_t switch_core_media_ready (switch_core_session_t *session, switch_media_type_t type)
 
void switch_core_media_set_telephony_event (switch_core_session_t *session, switch_media_type_t type, switch_payload_t te)
 
void switch_core_media_set_telephony_recv_event (switch_core_session_t *session, switch_media_type_t type, switch_payload_t te)
 
switch_rtp_stats_tswitch_core_media_stats (switch_core_session_t *session, switch_media_type_t type, switch_memory_pool_t *pool)
 
switch_status_t switch_core_media_udptl_mode (switch_core_session_t *session, switch_media_type_t type)
 
switch_bool_t switch_core_media_check_udptl_mode (switch_core_session_t *session, switch_media_type_t type)
 
void switch_core_media_set_rtp_flag (switch_core_session_t *session, switch_media_type_t type, switch_rtp_flag_t flag)
 
void switch_core_media_clear_rtp_flag (switch_core_session_t *session, switch_media_type_t type, switch_rtp_flag_t flag)
 
switch_jb_tswitch_core_media_get_jb (switch_core_session_t *session, switch_media_type_t type)
 
switch_rtp_stats_tswitch_core_media_get_stats (switch_core_session_t *session, switch_media_type_t type, switch_memory_pool_t *pool)
 
void switch_core_media_set_sdp_codec_string (switch_core_session_t *session, const char *r_sdp, switch_sdp_type_t sdp_type)
 
void switch_core_media_reset_autofix (switch_core_session_t *session, switch_media_type_t type)
 
void switch_core_media_check_outgoing_proxy (switch_core_session_t *session, switch_core_session_t *o_session)
 
switch_status_t switch_core_media_codec_chosen (switch_core_session_t *session, switch_media_type_t media)
 
void switch_core_media_recover_session (switch_core_session_t *session)
 
switch_status_t switch_core_media_add_ice_acl (switch_core_session_t *session, switch_media_type_t type, const char *acl_name)
 
void switch_core_session_set_ice (switch_core_session_t *session)
 
void switch_core_media_clear_ice (switch_core_session_t *session)
 
void switch_core_media_pause (switch_core_session_t *session)
 
void switch_core_media_resume (switch_core_session_t *session)
 
void switch_core_media_init (void)
 
void switch_core_media_deinit (void)
 
void switch_core_media_set_stats (switch_core_session_t *session)
 
void switch_core_media_sync_stats (switch_core_session_t *session)
 
void switch_core_session_wake_video_thread (switch_core_session_t *session)
 
void switch_core_session_clear_crypto (switch_core_session_t *session)
 
switch_status_t switch_core_session_get_payload_code (switch_core_session_t *session, switch_media_type_t type, const char *iananame, uint32_t rate, switch_payload_t *ptP, switch_payload_t *recv_ptP, char **fmtpP)
 
payload_map_tswitch_core_media_add_payload_map (switch_core_session_t *session, switch_media_type_t type, const char *name, const char *modname, const char *fmtp, switch_sdp_type_t sdp_type, uint32_t pt, uint32_t rate, uint32_t ptime, uint32_t channels, uint8_t negotiated)
 
switch_status_t switch_core_media_check_autoadj (switch_core_session_t *session)
 
switch_rtp_crypto_key_type_t switch_core_media_crypto_str2type (const char *str)
 
const char * switch_core_media_crypto_type2str (switch_rtp_crypto_key_type_t type)
 
int switch_core_media_crypto_keylen (switch_rtp_crypto_key_type_t type)
 
char * switch_core_media_filter_sdp (const char *sdp, const char *cmd, const char *arg)
 
char * switch_core_media_process_sdp_filter (const char *sdp, const char *cmd_buf, switch_core_session_t *session)
 
switch_status_t switch_core_media_codec_control (switch_core_session_t *session, switch_media_type_t mtype, switch_io_type_t iotype, switch_codec_control_command_t cmd, switch_codec_control_type_t ctype, void *cmd_data, switch_codec_control_type_t atype, void *cmd_arg, switch_codec_control_type_t *rtype, void **ret_data)
 
switch_timer_tswitch_core_media_get_timer (switch_core_session_t *session, switch_media_type_t mtype)
 
void switch_core_media_start_video_function (switch_core_session_t *session, switch_video_function_t video_function, void *user_data)
 
void switch_core_media_end_video_function (switch_core_session_t *session)
 
switch_status_t switch_core_session_start_video_thread (switch_core_session_t *session)
 
int switch_core_media_check_video_function (switch_core_session_t *session)
 
void switch_core_session_video_reinit (switch_core_session_t *session)
 
switch_status_t switch_core_media_read_lock_unlock (switch_core_session_t *session, switch_media_type_t type, switch_bool_t lock)
 
void switch_core_session_stop_media (switch_core_session_t *session)
 
switch_media_flow_t switch_core_session_media_flow (switch_core_session_t *session, switch_media_type_t type)
 
switch_status_t switch_core_media_get_vid_params (switch_core_session_t *session, switch_vid_params_t *vid_params)
 
switch_status_t switch_core_media_lock_video_file (switch_core_session_t *session, switch_rw_t rw)
 
switch_status_t switch_core_media_unlock_video_file (switch_core_session_t *session, switch_rw_t rw)
 
switch_status_t switch_core_media_set_video_file (switch_core_session_t *session, switch_file_handle_t *fh, switch_rw_t rw)
 
switch_file_handle_tswitch_core_media_get_video_file (switch_core_session_t *session, switch_rw_t rw)
 
switch_bool_t switch_core_session_in_video_thread (switch_core_session_t *session)
 
switch_bool_t switch_core_media_check_dtls (switch_core_session_t *session, switch_media_type_t type)
 
switch_status_t switch_core_media_set_outgoing_bitrate (switch_core_session_t *session, switch_media_type_t type, uint32_t bitrate)
 
switch_status_t switch_core_media_reset_jb (switch_core_session_t *session, switch_media_type_t type)
 
switch_status_t switch_core_session_wait_for_video_input_params (switch_core_session_t *session, uint32_t timeout_ms)
 

Macro Definition Documentation

#define switch_core_media_gen_key_frame (   _session)
Value:
SCC_VIDEO_GEN_KEYFRAME, SCCT_NONE, NULL, SCCT_NONE, NULL, NULL, NULL) \
switch_status_t switch_core_media_codec_control(switch_core_session_t *session, switch_media_type_t mtype, switch_io_type_t iotype, switch_codec_control_command_t cmd, switch_codec_control_type_t ctype, void *cmd_data, switch_codec_control_type_t atype, void *cmd_arg, switch_codec_control_type_t *rtype, void **ret_data)

Definition at line 325 of file switch_core_media.h.

Referenced by handle_nack(), process_rtcp_report(), switch_core_media_set_video_file(), switch_core_session_execute_application_get_flags(), switch_core_session_send_and_request_video_refresh(), switch_core_session_write_video_frame(), switch_ivr_record_file(), video_helper_thread(), and video_write_thread().

#define switch_core_media_read_lock (   _s,
  _t 
)    switch_core_media_read_lock_unlock(_s, _t, SWITCH_TRUE)

Definition at line 340 of file switch_core_media.h.

#define switch_core_media_read_unlock (   _s,
  _t 
)    switch_core_media_read_lock_unlock(_s, _t, SWITCH_FALSE)

Definition at line 341 of file switch_core_media.h.

#define switch_core_media_write_bandwidth (   _session,
  _val 
)
Value:
SCC_VIDEO_BANDWIDTH, SCCT_STRING, _val, SCCT_NONE, NULL, NULL, NULL) \
switch_status_t switch_core_media_codec_control(switch_core_session_t *session, switch_media_type_t mtype, switch_io_type_t iotype, switch_codec_control_command_t cmd, switch_codec_control_type_t ctype, void *cmd_data, switch_codec_control_type_t atype, void *cmd_arg, switch_codec_control_type_t *rtype, void **ret_data)

Definition at line 328 of file switch_core_media.h.

#define SWITCH_MAX_CAND_ACL   25

Definition at line 41 of file switch_core_media.h.

Referenced by switch_core_media_add_ice_acl().

#define SWITCH_NO_CRYPTO_TAG   -1

Typedef Documentation

Enumeration Type Documentation

enum STUNFLAGS
Enumerator
STUN_FLAG_SET 
STUN_FLAG_PING 
STUN_FLAG_FUNNY 

Definition at line 83 of file switch_core_media.h.

83  {
84  STUN_FLAG_SET = (1 << 0),
85  STUN_FLAG_PING = (1 << 1),
86  STUN_FLAG_FUNNY = (1 << 2)
87 } STUNFLAGS;
STUNFLAGS
Enumerator
DTMF_AUTO 
DTMF_2833 
DTMF_INFO 
DTMF_NONE 

Definition at line 44 of file switch_core_media.h.

Enumerator
SCMF_RUNNING 
SCMF_DISABLE_TRANSCODING 
SCMF_AUTOFIX_TIMING 
SCMF_CODEC_GREEDY 
SCMF_CODEC_SCROOGE 
SCMF_DISABLE_HOLD 
SCMF_RENEG_ON_HOLD 
SCMF_RENEG_ON_REINVITE 
SCMF_LIBERAL_DTMF 
SCMF_SUPPRESS_CNG 
SCMF_DISABLE_RTP_AUTOADJ 
SCMF_PASS_RFC2833 
SCMF_AUTOFLUSH 
SCMF_REWRITE_TIMESTAMPS 
SCMF_RTP_AUTOFLUSH_DURING_BRIDGE 
SCMF_MULTI_ANSWER_AUDIO 
SCMF_MULTI_ANSWER_VIDEO 
SCMF_MAX 

Definition at line 60 of file switch_core_media.h.

60  {
78  SCMF_MAX
switch_core_media_flag_t
Enumerator
SM_NDLB_ALLOW_BAD_IANANAME 
SM_NDLB_ALLOW_NONDUP_SDP 
SM_NDLB_ALLOW_CRYPTO_IN_AVP 
SM_NDLB_DISABLE_SRTP_AUTH 
SM_NDLB_SENDRECV_IN_SESSION 
SM_NDLB_NEVER_PATCH_REINVITE 

Definition at line 51 of file switch_core_media.h.

Enumerator
VAD_IN 
VAD_OUT 

Definition at line 89 of file switch_core_media.h.

89  {
90  VAD_IN = (1 << 0),
91  VAD_OUT = (1 << 1)
switch_core_media_vflag_t

Function Documentation

void switch_core_media_absorb_sdp ( switch_core_session_t session)

Definition at line 8594 of file switch_core_media.c.

References switch_media_handle_s::engines, if(), switch_rtp_engine_s::proxy_sdp_ip, switch_rtp_engine_s::proxy_sdp_port, switch_assert, SWITCH_B_SDP_VARIABLE, switch_channel_get_variable, switch_core_media_set_local_sdp(), switch_core_session_strdup, SWITCH_MEDIA_TYPE_AUDIO, and SWITCH_TRUE.

Referenced by switch_core_media_receive_message().

8595 {
8596  const char *sdp_str;
8597  switch_rtp_engine_t *a_engine;
8598  switch_media_handle_t *smh;
8599 
8600  switch_assert(session);
8601 
8602  if (!(smh = session->media_handle)) {
8603  return;
8604  }
8605 
8606  a_engine = &smh->engines[SWITCH_MEDIA_TYPE_AUDIO];
8607 
8608  if ((sdp_str = switch_channel_get_variable(session->channel, SWITCH_B_SDP_VARIABLE))) {
8609  sdp_parser_t *parser;
8610  sdp_session_t *sdp;
8611  sdp_media_t *m;
8612  sdp_connection_t *connection;
8613 
8614  if ((parser = sdp_parse(NULL, sdp_str, (int) strlen(sdp_str), 0))) {
8615  if ((sdp = sdp_session(parser))) {
8616  for (m = sdp->sdp_media; m; m = m->m_next) {
8617  if (m->m_type != sdp_media_audio || !m->m_port) {
8618  continue;
8619  }
8620 
8621  connection = sdp->sdp_connection;
8622  if (m->m_connections) {
8623  connection = m->m_connections;
8624  }
8625 
8626  if (connection) {
8627  a_engine->proxy_sdp_ip = switch_core_session_strdup(session, connection->c_address);
8628  }
8629  a_engine->proxy_sdp_port = (switch_port_t) m->m_port;
8630  if (a_engine->proxy_sdp_ip && a_engine->proxy_sdp_port) {
8631  break;
8632  }
8633  }
8634  }
8635  sdp_parser_free(parser);
8636  }
8637  switch_core_media_set_local_sdp(session, sdp_str, SWITCH_TRUE);
8638  }
8639 }
switch_media_handle_t * media_handle
void switch_core_media_set_local_sdp(switch_core_session_t *session, const char *sdp_str, switch_bool_t dup)
if((uint32_t)(unpack->cur-unpack->buf) > unpack->buflen)
switch_channel_t * channel
#define switch_channel_get_variable(_c, _v)
uint16_t switch_port_t
switch_rtp_engine_t engines[SWITCH_MEDIA_TYPE_TOTAL]
#define SWITCH_B_SDP_VARIABLE
Definition: switch_types.h:198
#define switch_core_session_strdup(_session, _todup)
Copy a string using memory allocation from a session's pool.
Definition: switch_core.h:717
switch_port_t proxy_sdp_port
#define switch_assert(expr)
switch_status_t switch_core_media_activate_rtp ( switch_core_session_t session)

Definition at line 6218 of file switch_core_media.c.

References switch_rtp_engine_s::adv_sdp_ip, payload_map_s::agreed_pt, switch_core_media_params_s::auto_rtp_bugs, ice_s::cands, CF_AVPF, CF_FS_RTP, CF_NOTIMER_DURING_BRIDGE, CF_PASS_RFC2833, CF_PROTO_HOLD, CF_PROXY_MEDIA, CF_PROXY_MODE, CF_REINVITE, CF_SECURE, CF_VIDEO, CF_VIDEO_POSSIBLE, CF_ZRTP_PASSTHRU, check_dtls_reinvite(), check_jb(), ice_s::chosen, switch_core_media_params_s::cng_pt, switch_core_media_params_s::codec_flags, payload_map_s::codec_ms, icand_s::con_addr, icand_s::con_port, CRYPTO_INVALID, switch_rtp_engine_s::crypto_type, switch_rtp_engine_s::cur_payload_map, switch_rtp_engine_s::dtls_controller, dtls_ok(), DTLS_TYPE_CLIENT, DTLS_TYPE_RTCP, DTLS_TYPE_RTP, DTLS_TYPE_SERVER, switch_core_media_params_s::dtmf_delay, switch_media_handle_s::engines, switch_rtp_engine_s::fir, gen_ice(), switch_codec_implementation::iananame, ICE_CONTROLLED, ICE_GOOGLE_JINGLE, switch_rtp_engine_s::ice_in, switch_rtp_engine_s::ice_out, ICE_VANILLA, IPR_RTCP, IPR_RTP, switch_rtp_engine_s::local_dtls_fingerprint, switch_rtp_engine_s::local_sdp_ip, switch_rtp_engine_s::local_sdp_port, switch_core_media_params_s::manual_rtp_bugs, switch_core_media_params_s::manual_video_rtp_bugs, switch_rtp_engine_s::max_missed_hold_packets, switch_rtp_engine_s::max_missed_packets, memset(), switch_codec_implementation::microseconds_per_packet, switch_media_handle_s::mparams, switch_rtp_engine_s::nack, payload_map_s::negotiated, switch_rtp_engine_s::payload_map, switch_rtp_engine_s::pli, ice_s::pwd, switch_rtp_engine_s::read_codec, switch_rtp_engine_s::read_impl, switch_media_handle_s::read_mutex, icand_s::ready, switch_core_media_params_s::recv_te, switch_rtp_engine_s::remote_dtls_fingerprint, switch_rtp_engine_s::remote_rtcp_port, payload_map_s::remote_sdp_ip, payload_map_s::remote_sdp_port, switch_rtp_engine_s::remote_ssrc, payload_map_s::rm_encoding, switch_core_media_params_s::rtcp_audio_interval_msec, switch_rtp_engine_s::rtcp_mux, switch_core_media_params_s::rtcp_video_interval_msec, RTP_BUG_IGNORE_MARK_BIT, RTP_BUG_SEND_LINEAR_TIMESTAMPS, switch_rtp_engine_s::rtp_bugs, switch_core_media_params_s::rtp_hold_timeout_sec, switch_rtp_engine_s::rtp_session, switch_core_media_params_s::rtp_timeout_sec, switch_codec_implementation::samples_per_packet, switch_codec_implementation::samples_per_second, SCMF_AUTOFLUSH, SCMF_DISABLE_RTP_AUTOADJ, SCMF_PASS_RFC2833, SCMF_REWRITE_TIMESTAMPS, SCMF_SUPPRESS_CNG, switch_media_handle_s::session, switch_rtp_engine_s::ssrc, dtls_fp_s::str, SWITCH_ADVERTISED_MEDIA_IP_VARIABLE, switch_assert, SWITCH_CALL_DIRECTION_INBOUND, SWITCH_CALL_DIRECTION_OUTBOUND, SWITCH_CAUSE_DESTINATION_OUT_OF_ORDER, switch_channel_clear_flag(), switch_channel_direction(), switch_channel_down, switch_channel_get_name(), switch_channel_get_variable, switch_channel_hangup, SWITCH_CHANNEL_SESSION_LOG, switch_channel_set_flag, switch_channel_set_variable, switch_channel_set_variable_printf(), switch_channel_test_flag(), switch_channel_up, switch_core_media_check_video_codecs(), switch_core_media_choose_port(), switch_core_media_parse_rtp_bugs(), switch_core_media_proxy_remote_addr(), switch_core_media_set_codec(), switch_core_media_set_video_codec(), switch_core_media_toggle_hold(), switch_core_recovery_track(), switch_core_session_apply_crypto(), switch_core_session_get_channel(), switch_core_session_get_pool(), switch_core_session_start_video_thread(), SWITCH_FALSE, switch_ice_direction(), SWITCH_LOCAL_MEDIA_IP_VARIABLE, SWITCH_LOCAL_MEDIA_PORT_VARIABLE, SWITCH_LOCAL_VIDEO_IP_VARIABLE, SWITCH_LOCAL_VIDEO_PORT_VARIABLE, SWITCH_LOG_DEBUG, SWITCH_LOG_ERROR, SWITCH_LOG_INFO, switch_log_printf(), switch_media_handle_test_media_flag(), SWITCH_MEDIA_TYPE_AUDIO, SWITCH_MEDIA_TYPE_VIDEO, switch_mutex_init(), SWITCH_MUTEX_NESTED, SWITCH_REMOTE_MEDIA_IP_VARIABLE, SWITCH_REMOTE_MEDIA_PORT_VARIABLE, switch_rtp_activate_ice(), switch_rtp_activate_rtcp(), switch_rtp_add_dtls(), switch_rtp_enable_vad(), SWITCH_RTP_FLAG_AUTO_CNG, SWITCH_RTP_FLAG_AUTOADJ, SWITCH_RTP_FLAG_AUTOFLUSH, SWITCH_RTP_FLAG_BYTESWAP, SWITCH_RTP_FLAG_DATAWAIT, SWITCH_RTP_FLAG_FIR, SWITCH_RTP_FLAG_GEN_TS_DELTA, SWITCH_RTP_FLAG_INVALID, SWITCH_RTP_FLAG_NACK, SWITCH_RTP_FLAG_NOBLOCK, SWITCH_RTP_FLAG_PLI, SWITCH_RTP_FLAG_PROXY_MEDIA, SWITCH_RTP_FLAG_RAW_WRITE, SWITCH_RTP_FLAG_TMMBR, SWITCH_RTP_FLAG_USE_TIMER, SWITCH_RTP_FLAG_VIDEO, switch_rtp_get_remote_host(), switch_rtp_get_remote_port(), switch_rtp_get_ssrc(), switch_rtp_has_dtls(), switch_rtp_intentional_bugs(), switch_rtp_new(), switch_rtp_ready(), switch_rtp_reset_media_timer(), switch_rtp_set_cng_pt(), switch_rtp_set_default_payload(), switch_rtp_set_flag(), switch_rtp_set_interdigit_delay(), switch_rtp_set_max_missed_packets(), switch_rtp_set_payload_map(), switch_rtp_set_remote_address(), switch_rtp_set_remote_ssrc(), switch_rtp_set_ssrc(), switch_rtp_set_telephony_event(), switch_rtp_set_telephony_recv_event(), switch_rtp_udptl_mode(), switch_snprintf(), SWITCH_STATUS_FALSE, SWITCH_STATUS_SUCCESS, switch_str_nil, SWITCH_TRUE, switch_true(), SWITCH_VAD_FLAG_EVENTS_NOTALK, SWITCH_VAD_FLAG_EVENTS_TALK, SWITCH_VAD_FLAG_TALKING, switch_core_media_params_s::te, switch_core_media_params_s::timer_name, switch_rtp_engine_s::tmmbr, ice_s::ufrag, VAD_IN, VAD_OUT, switch_core_media_params_s::vflags, switch_media_handle_s::write_mutex, and zstr.

Referenced by switch_core_media_patch_sdp(), and switch_core_media_recover_session().

6220 {
6221  const char *err = NULL;
6222  const char *val = NULL;
6225  char tmp[50];
6226  char *timer_name = NULL;
6227  const char *var;
6228  switch_rtp_engine_t *a_engine, *v_engine;
6229  switch_media_handle_t *smh;
6230 
6231  switch_assert(session);
6232 
6233  if (!(smh = session->media_handle)) {
6234  return SWITCH_STATUS_FALSE;
6235  }
6236 
6237  a_engine = &smh->engines[SWITCH_MEDIA_TYPE_AUDIO];
6238  v_engine = &smh->engines[SWITCH_MEDIA_TYPE_VIDEO];
6239 
6240 
6241  if (switch_channel_down(session->channel)) {
6242  return SWITCH_STATUS_FALSE;
6243  }
6244 
6245 
6246  if (switch_rtp_ready(a_engine->rtp_session)) {
6248  }
6249 
6250  if (a_engine->crypto_type != CRYPTO_INVALID) {
6252  }
6253 
6255  status = SWITCH_STATUS_SUCCESS;
6256  goto end;
6257  }
6258 
6259  if (!switch_channel_test_flag(session->channel, CF_REINVITE)) {
6260  if (switch_rtp_ready(a_engine->rtp_session)) {
6262  goto video;
6263  }
6264 
6265  status = SWITCH_STATUS_SUCCESS;
6266  goto end;
6267  }
6268  }
6269 
6270  if ((status = switch_core_media_set_codec(session, 0, smh->mparams->codec_flags)) != SWITCH_STATUS_SUCCESS) {
6271  goto end;
6272  }
6273 
6275 
6276 
6277  memset(flags, 0, sizeof(flags));
6278  flags[SWITCH_RTP_FLAG_DATAWAIT]++;
6279 
6281  !((val = switch_channel_get_variable(session->channel, "disable_rtp_auto_adjust")) && switch_true(val))) {
6282  flags[SWITCH_RTP_FLAG_AUTOADJ]++;
6283  }
6284 
6286  || ((val = switch_channel_get_variable(session->channel, "pass_rfc2833")) && switch_true(val))) {
6288  }
6289 
6290 
6292  || ((val = switch_channel_get_variable(session->channel, "rtp_autoflush")) && switch_true(val))) {
6293  flags[SWITCH_RTP_FLAG_AUTOFLUSH]++;
6294  }
6295 
6297  ((val = switch_channel_get_variable(session->channel, "rtp_rewrite_timestamps")) && switch_true(val)))) {
6298  flags[SWITCH_RTP_FLAG_RAW_WRITE]++;
6299  }
6300 
6302  smh->mparams->cng_pt = 0;
6303  } else if (smh->mparams->cng_pt) {
6304  flags[SWITCH_RTP_FLAG_AUTO_CNG]++;
6305  }
6306 
6307 #if __BYTE_ORDER == __LITTLE_ENDIAN
6308  if (!strcasecmp(a_engine->read_impl.iananame, "L16")) {
6309  flags[SWITCH_RTP_FLAG_BYTESWAP]++;
6310  }
6311 #endif
6312 
6313  if ((flags[SWITCH_RTP_FLAG_BYTESWAP]) && (val = switch_channel_get_variable(session->channel, "rtp_disable_byteswap")) && switch_true(val)) {
6314  flags[SWITCH_RTP_FLAG_BYTESWAP] = 0;
6315  }
6316 
6317  if ((val = switch_channel_get_variable(session->channel, "rtp_gen_ts_delta")) && switch_true(val)) {
6318  flags[SWITCH_RTP_FLAG_GEN_TS_DELTA] = 1;
6319  }
6320 
6321  if (a_engine->rtp_session && switch_channel_test_flag(session->channel, CF_REINVITE)) {
6322  //const char *ip = switch_channel_get_variable(session->channel, SWITCH_LOCAL_MEDIA_IP_VARIABLE);
6323  //const char *port = switch_channel_get_variable(session->channel, SWITCH_LOCAL_MEDIA_PORT_VARIABLE);
6324  char *remote_host = switch_rtp_get_remote_host(a_engine->rtp_session);
6325  switch_port_t remote_port = switch_rtp_get_remote_port(a_engine->rtp_session);
6326 
6327  if (remote_host && remote_port && !strcmp(remote_host, a_engine->cur_payload_map->remote_sdp_ip) &&
6328  remote_port == a_engine->cur_payload_map->remote_sdp_port) {
6329  switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_DEBUG, "Audio params are unchanged for %s.\n",
6330  switch_channel_get_name(session->channel));
6331  a_engine->cur_payload_map->negotiated = 1;
6332  //XX
6333  goto video;
6334  } else {
6335  switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_DEBUG, "Audio params changed for %s from %s:%d to %s:%d\n",
6336  switch_channel_get_name(session->channel),
6337  remote_host, remote_port, a_engine->cur_payload_map->remote_sdp_ip, a_engine->cur_payload_map->remote_sdp_port);
6338 
6339  switch_snprintf(tmp, sizeof(tmp), "%d", a_engine->cur_payload_map->remote_sdp_port);
6342  }
6343  }
6344 
6346  switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_DEBUG, "AUDIO RTP [%s] %s port %d -> %s port %d codec: %u ms: %d\n",
6347  switch_channel_get_name(session->channel),
6348  a_engine->local_sdp_ip,
6349  a_engine->local_sdp_port,
6350  a_engine->cur_payload_map->remote_sdp_ip,
6352 
6353  //XX
6354  }
6355 
6356  switch_snprintf(tmp, sizeof(tmp), "%d", a_engine->local_sdp_port);
6360 
6361  if (a_engine->rtp_session && switch_channel_test_flag(session->channel, CF_REINVITE)) {
6362  const char *rport = NULL;
6363  switch_port_t remote_rtcp_port = a_engine->remote_rtcp_port;
6364 
6365  if (!remote_rtcp_port) {
6366  if ((rport = switch_channel_get_variable(session->channel, "rtp_remote_audio_rtcp_port"))) {
6367  remote_rtcp_port = (switch_port_t)atoi(rport);
6368  }
6369  }
6370 
6372  remote_rtcp_port, SWITCH_TRUE, &err) != SWITCH_STATUS_SUCCESS) {
6373  switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_ERROR, "AUDIO RTP REPORTS ERROR: [%s]\n", err);
6374  } else {
6375  switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_DEBUG, "AUDIO RTP CHANGING DEST TO: [%s:%d]\n",
6377 
6378  if (switch_channel_test_flag(session->channel, CF_PROTO_HOLD) && strcmp(a_engine->cur_payload_map->remote_sdp_ip, "0.0.0.0")) {
6379  switch_core_media_toggle_hold(session, 0);
6380  }
6381 
6382 
6384  !((val = switch_channel_get_variable(session->channel, "disable_rtp_auto_adjust")) && switch_true(val)) &&
6386  /* Reactivate the NAT buster flag. */
6388  }
6389  }
6390 
6391  if (session && a_engine) {
6392  check_dtls_reinvite(session, a_engine);
6393  }
6394 
6395  goto video;
6396  }
6397 
6399  switch_core_media_proxy_remote_addr(session, NULL);
6400 
6401  memset(flags, 0, sizeof(flags));
6402  flags[SWITCH_RTP_FLAG_DATAWAIT]++;
6403  flags[SWITCH_RTP_FLAG_PROXY_MEDIA]++;
6404 
6406  !((val = switch_channel_get_variable(session->channel, "disable_rtp_auto_adjust")) && switch_true(val))) {
6407  flags[SWITCH_RTP_FLAG_AUTOADJ]++;
6408  }
6409  timer_name = NULL;
6410 
6412  "PROXY AUDIO RTP [%s] %s:%d->%s:%d codec: %u ms: %d\n",
6413  switch_channel_get_name(session->channel),
6414  a_engine->cur_payload_map->remote_sdp_ip,
6415  a_engine->cur_payload_map->remote_sdp_port,
6416  a_engine->cur_payload_map->remote_sdp_ip,
6418 
6419  if (switch_rtp_ready(a_engine->rtp_session)) {
6421  }
6422 
6423  } else {
6424  timer_name = smh->mparams->timer_name;
6425 
6426  if ((var = switch_channel_get_variable(session->channel, "rtp_timer_name"))) {
6427  timer_name = (char *) var;
6428  }
6429  }
6430 
6431  if (switch_channel_up(session->channel)) {
6432  switch_channel_set_variable(session->channel, "rtp_use_timer_name", timer_name);
6433 
6434  a_engine->rtp_session = switch_rtp_new(a_engine->local_sdp_ip,
6435  a_engine->local_sdp_port,
6436  a_engine->cur_payload_map->remote_sdp_ip,
6437  a_engine->cur_payload_map->remote_sdp_port,
6438  a_engine->cur_payload_map->agreed_pt,
6439  a_engine->read_impl.samples_per_packet,
6440  a_engine->cur_payload_map->codec_ms * 1000,
6441  flags, timer_name, &err, switch_core_session_get_pool(session));
6442 
6443  if (switch_rtp_ready(a_engine->rtp_session)) {
6444  switch_rtp_set_payload_map(a_engine->rtp_session, &a_engine->payload_map);
6445  }
6446  }
6447 
6448  if (switch_rtp_ready(a_engine->rtp_session)) {
6449  uint8_t vad_in = (smh->mparams->vflags & VAD_IN);
6450  uint8_t vad_out = (smh->mparams->vflags & VAD_OUT);
6452  const char *ssrc;
6453 
6456 
6457  //switch_core_media_set_rtp_session(session, SWITCH_MEDIA_TYPE_AUDIO, a_engine->rtp_session);
6458 
6459  if ((ssrc = switch_channel_get_variable(session->channel, "rtp_use_ssrc"))) {
6460  uint32_t ssrc_ul = (uint32_t) strtoul(ssrc, NULL, 10);
6461  switch_rtp_set_ssrc(a_engine->rtp_session, ssrc_ul);
6462  a_engine->ssrc = ssrc_ul;
6463  } else {
6464  switch_rtp_set_ssrc(a_engine->rtp_session, a_engine->ssrc);
6465  }
6466 
6467  if (a_engine->remote_ssrc) {
6468  switch_rtp_set_remote_ssrc(a_engine->rtp_session, a_engine->remote_ssrc);
6469  }
6470 
6472 
6473  switch_channel_set_variable_printf(session->channel, "rtp_use_pt", "%d", a_engine->cur_payload_map->agreed_pt);
6474 
6475  if ((val = switch_channel_get_variable(session->channel, "rtp_enable_vad_in")) && switch_true(val)) {
6476  vad_in = 1;
6477  }
6478  if ((val = switch_channel_get_variable(session->channel, "rtp_enable_vad_out")) && switch_true(val)) {
6479  vad_out = 1;
6480  }
6481 
6482  if ((val = switch_channel_get_variable(session->channel, "rtp_disable_vad_in")) && switch_true(val)) {
6483  vad_in = 0;
6484  }
6485  if ((val = switch_channel_get_variable(session->channel, "rtp_disable_vad_out")) && switch_true(val)) {
6486  vad_out = 0;
6487  }
6488 
6489 
6490  a_engine->ssrc = switch_rtp_get_ssrc(a_engine->rtp_session);
6491  switch_channel_set_variable_printf(session->channel, "rtp_use_ssrc", "%u", a_engine->ssrc);
6492 
6493 
6494 
6496  a_engine->rtp_bugs |= RTP_BUG_IGNORE_MARK_BIT;
6497  }
6498 
6499  if ((val = switch_channel_get_variable(session->channel, "rtp_manual_rtp_bugs"))) {
6500  switch_core_media_parse_rtp_bugs(&a_engine->rtp_bugs, val);
6501  }
6502 
6503  //if (switch_channel_test_flag(session->channel, CF_AVPF)) {
6504  // smh->mparams->manual_rtp_bugs = RTP_BUG_SEND_LINEAR_TIMESTAMPS;
6505  //}
6506 
6508 
6509  if ((vad_in && inb) || (vad_out && !inb)) {
6511 
6512  switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_DEBUG, "AUDIO RTP Engage VAD for %s ( %s %s )\n",
6513  switch_channel_get_name(switch_core_session_get_channel(session)), vad_in ? "in" : "", vad_out ? "out" : "");
6514  }
6515 
6516 
6517  if (a_engine->ice_in.cands[a_engine->ice_in.chosen[0]][0].ready) {
6518 
6519  gen_ice(session, SWITCH_MEDIA_TYPE_AUDIO, NULL, 0);
6520 
6521  switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_INFO, "Activating Audio ICE\n");
6522 
6524  a_engine->ice_in.ufrag,
6525  a_engine->ice_out.ufrag,
6526  a_engine->ice_out.pwd,
6527  a_engine->ice_in.pwd,
6528  IPR_RTP,
6529 #ifdef GOOGLE_ICE
6531  NULL
6532 #else
6533  switch_ice_direction(session) ==
6535  &a_engine->ice_in
6536 #endif
6537  );
6538 
6539 
6540 
6541  }
6542 
6543 
6544 
6545  if ((val = switch_channel_get_variable(session->channel, "rtcp_audio_interval_msec")) || (val = smh->mparams->rtcp_audio_interval_msec)) {
6546  const char *rport = switch_channel_get_variable(session->channel, "rtp_remote_audio_rtcp_port");
6547  switch_port_t remote_rtcp_port = a_engine->remote_rtcp_port;
6548 
6549  if (!remote_rtcp_port && rport) {
6550  remote_rtcp_port = (switch_port_t)atoi(rport);
6551  }
6552 
6553  if (!strcasecmp(val, "passthru")) {
6554  switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_INFO, "Activating RTCP PASSTHRU PORT %d\n", remote_rtcp_port);
6555  switch_rtp_activate_rtcp(a_engine->rtp_session, -1, remote_rtcp_port, a_engine->rtcp_mux > 0);
6556  } else if (remote_rtcp_port) {
6557  int interval = atoi(val);
6558  if (interval < 100 || interval > 500000) {
6560  "Invalid rtcp interval spec [%d] must be between 100 and 500000\n", interval);
6561  interval = 5000;
6562  }
6563 
6564  switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_DEBUG, "Activating RTCP PORT %d\n", remote_rtcp_port);
6565  switch_rtp_activate_rtcp(a_engine->rtp_session, interval, remote_rtcp_port, a_engine->rtcp_mux > 0);
6566 
6567  }
6568 
6569  if (a_engine->ice_in.cands[a_engine->ice_in.chosen[1]][1].ready) {
6570  if (a_engine->rtcp_mux > 0 && !strcmp(a_engine->ice_in.cands[a_engine->ice_in.chosen[1]][1].con_addr, a_engine->ice_in.cands[a_engine->ice_in.chosen[0]][0].con_addr)
6571  && a_engine->ice_in.cands[a_engine->ice_in.chosen[1]][1].con_port == a_engine->ice_in.cands[a_engine->ice_in.chosen[0]][0].con_port) {
6572  switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_INFO, "Skipping RTCP ICE (Same as RTP)\n");
6573  } else {
6574  switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_INFO, "Activating RTCP ICE\n");
6575 
6577  a_engine->ice_in.ufrag,
6578  a_engine->ice_out.ufrag,
6579  a_engine->ice_out.pwd,
6580  a_engine->ice_in.pwd,
6581  IPR_RTCP,
6582 #ifdef GOOGLE_ICE
6583  ICE_GOOGLE_JINGLE,
6584  NULL
6585 #else
6586  switch_ice_direction(session) ==
6588  &a_engine->ice_in
6589 #endif
6590  );
6591  }
6592 
6593  }
6594  }
6595 
6596  if (!zstr(a_engine->local_dtls_fingerprint.str) && switch_rtp_has_dtls() && dtls_ok(smh->session)) {
6597  dtls_type_t xtype, dtype = a_engine->dtls_controller ? DTLS_TYPE_CLIENT : DTLS_TYPE_SERVER;
6598 
6599  //if (switch_channel_test_flag(smh->session->channel, CF_3PCC)) {
6600  // dtype = (dtype == DTLS_TYPE_CLIENT) ? DTLS_TYPE_SERVER : DTLS_TYPE_CLIENT;
6601  //}
6602 
6603  xtype = DTLS_TYPE_RTP;
6604  if (a_engine->rtcp_mux > 0 && smh->mparams->rtcp_audio_interval_msec) xtype |= DTLS_TYPE_RTCP;
6605 
6606  switch_rtp_add_dtls(a_engine->rtp_session, &a_engine->local_dtls_fingerprint, &a_engine->remote_dtls_fingerprint, dtype | xtype);
6607 
6608  if (a_engine->rtcp_mux < 1 && smh->mparams->rtcp_audio_interval_msec) {
6609  xtype = DTLS_TYPE_RTCP;
6610  switch_rtp_add_dtls(a_engine->rtp_session, &a_engine->local_dtls_fingerprint, &a_engine->remote_dtls_fingerprint, dtype | xtype);
6611  }
6612 
6613  }
6614 
6615  check_jb(session, NULL, 0, 0, SWITCH_FALSE);
6616 
6617  if ((val = switch_channel_get_variable(session->channel, "rtp_timeout_sec"))) {
6618  int v = atoi(val);
6619  if (v >= 0) {
6620  smh->mparams->rtp_timeout_sec = v;
6621  }
6622  }
6623 
6624  if ((val = switch_channel_get_variable(session->channel, "rtp_hold_timeout_sec"))) {
6625  int v = atoi(val);
6626  if (v >= 0) {
6627  smh->mparams->rtp_hold_timeout_sec = v;
6628  }
6629  }
6630 
6631  if (smh->mparams->rtp_timeout_sec) {
6633 
6635  if (!smh->mparams->rtp_hold_timeout_sec) {
6637  }
6638  }
6639 
6640  if (smh->mparams->rtp_hold_timeout_sec) {
6642  }
6643 
6644  if (smh->mparams->te) {
6645  switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_DEBUG, "%s Set 2833 dtmf send payload to %u\n",
6646  switch_channel_get_name(session->channel), smh->mparams->te);
6648  switch_channel_set_variable_printf(session->channel, "rtp_2833_send_payload", "%d", smh->mparams->te);
6649  }
6650 
6651  if (smh->mparams->recv_te) {
6652  switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_DEBUG, "%s Set 2833 dtmf receive payload to %u\n",
6653  switch_channel_get_name(session->channel), smh->mparams->recv_te);
6655  switch_channel_set_variable_printf(session->channel, "rtp_2833_recv_payload", "%d", smh->mparams->recv_te);
6656  }
6657 
6658  //XX
6659 
6661  ((val = switch_channel_get_variable(session->channel, "supress_cng")) && switch_true(val)) ||
6662  ((val = switch_channel_get_variable(session->channel, "suppress_cng")) && switch_true(val))) {
6663  smh->mparams->cng_pt = 0;
6664  }
6665 
6666  if (((val = switch_channel_get_variable(session->channel, "rtp_digit_delay")))) {
6667  int delayi = atoi(val);
6668  if (delayi < 0) delayi = 0;
6669  smh->mparams->dtmf_delay = (uint32_t) delayi;
6670  }
6671 
6672 
6673  if (smh->mparams->dtmf_delay) {
6676  "%s Set rtp dtmf delay to %u\n", switch_channel_get_name(session->channel), smh->mparams->dtmf_delay);
6677 
6678  }
6679 
6681  switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_DEBUG, "Set comfort noise payload to %u\n", smh->mparams->cng_pt);
6682  switch_rtp_set_cng_pt(a_engine->rtp_session, smh->mparams->cng_pt);
6683  }
6684 
6686 
6687  switch_snprintf(tmp, sizeof(tmp), "%d", a_engine->cur_payload_map->remote_sdp_port);
6690 
6691 
6693  switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_INFO, "Activating ZRTP PROXY MODE\n");
6694  switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_DEBUG, "Disable NOTIMER_DURING_BRIDGE\n");
6696  switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_DEBUG, "Activating audio UDPTL mode\n");
6698  }
6699 
6700 
6701 
6702 
6703 
6704 
6705  video:
6706 
6709  }
6710 
6712  /******************************************************************************************/
6713  if (v_engine->rtp_session && switch_channel_test_flag(session->channel, CF_REINVITE)) {
6714  //const char *ip = switch_channel_get_variable(session->channel, SWITCH_LOCAL_MEDIA_IP_VARIABLE);
6715  //const char *port = switch_channel_get_variable(session->channel, SWITCH_LOCAL_MEDIA_PORT_VARIABLE);
6716  char *remote_host = switch_rtp_get_remote_host(v_engine->rtp_session);
6717  switch_port_t remote_port = switch_rtp_get_remote_port(v_engine->rtp_session);
6718 
6719 
6720 
6721  if (remote_host && remote_port && !strcmp(remote_host, v_engine->cur_payload_map->remote_sdp_ip) && remote_port == v_engine->cur_payload_map->remote_sdp_port) {
6722  switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_DEBUG, "Video params are unchanged for %s.\n",
6723  switch_channel_get_name(session->channel));
6724  v_engine->cur_payload_map->negotiated = 1;
6725  goto video_up;
6726  } else {
6727  switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_DEBUG, "Video params changed for %s from %s:%d to %s:%d\n",
6728  switch_channel_get_name(session->channel),
6729  remote_host, remote_port, v_engine->cur_payload_map->remote_sdp_ip, v_engine->cur_payload_map->remote_sdp_port);
6730  }
6731  }
6732 
6734  if (switch_rtp_ready(v_engine->rtp_session)) {
6736  "VIDEO RTP [%s] %s port %d -> %s port %d codec: %u\n", switch_channel_get_name(session->channel),
6737  v_engine->local_sdp_ip, v_engine->local_sdp_port, v_engine->cur_payload_map->remote_sdp_ip,
6738  v_engine->cur_payload_map->remote_sdp_port, v_engine->cur_payload_map->agreed_pt);
6739 
6741  }
6742  }
6743 
6744  switch_snprintf(tmp, sizeof(tmp), "%d", v_engine->local_sdp_port);
6747 
6748 
6749  if (v_engine->rtp_session && switch_channel_test_flag(session->channel, CF_REINVITE)) {
6750  const char *rport = NULL;
6751  switch_port_t remote_rtcp_port = v_engine->remote_rtcp_port;
6752 
6753  //switch_channel_clear_flag(session->channel, CF_REINVITE);
6754 
6755  if (!remote_rtcp_port) {
6756  if ((rport = switch_channel_get_variable(session->channel, "rtp_remote_video_rtcp_port"))) {
6757  remote_rtcp_port = (switch_port_t)atoi(rport);
6758  }
6759  }
6760 
6762  (v_engine->rtp_session, v_engine->cur_payload_map->remote_sdp_ip, v_engine->cur_payload_map->remote_sdp_port, remote_rtcp_port, SWITCH_TRUE,
6763  &err) != SWITCH_STATUS_SUCCESS) {
6764  switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_ERROR, "VIDEO RTP REPORTS ERROR: [%s]\n", err);
6765  } else {
6766  switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_DEBUG, "VIDEO RTP CHANGING DEST TO: [%s:%d]\n",
6769  !((val = switch_channel_get_variable(session->channel, "disable_rtp_auto_adjust")) && switch_true(val))) {
6770  /* Reactivate the NAT buster flag. */
6772  }
6773 
6774  }
6775  goto video_up;
6776  }
6777 
6779  switch_core_media_proxy_remote_addr(session, NULL);
6780 
6781  memset(flags, 0, sizeof(flags));
6782  flags[SWITCH_RTP_FLAG_PROXY_MEDIA]++;
6783  flags[SWITCH_RTP_FLAG_DATAWAIT]++;
6784 
6786  !((val = switch_channel_get_variable(session->channel, "disable_rtp_auto_adjust")) && switch_true(val))) {
6787  flags[SWITCH_RTP_FLAG_AUTOADJ]++;
6788  }
6789  timer_name = NULL;
6790 
6792  "PROXY VIDEO RTP [%s] %s:%d->%s:%d codec: %u ms: %d\n",
6793  switch_channel_get_name(session->channel),
6794  a_engine->cur_payload_map->remote_sdp_ip,
6795  v_engine->local_sdp_port,
6796  v_engine->cur_payload_map->remote_sdp_ip,
6798 
6799  if (switch_rtp_ready(v_engine->rtp_session)) {
6801  }
6802  } else {
6803  timer_name = smh->mparams->timer_name;
6804 
6805  if ((var = switch_channel_get_variable(session->channel, "rtp_timer_name"))) {
6806  timer_name = (char *) var;
6807  }
6808  }
6809 
6810  /******************************************************************************************/
6811 
6812  if (v_engine->rtp_session) {
6813  goto video_up;
6814  }
6815 
6816 
6817  if (!v_engine->local_sdp_port) {
6819  }
6820 
6821  memset(flags, 0, sizeof(flags));
6822  flags[SWITCH_RTP_FLAG_DATAWAIT]++;
6823  flags[SWITCH_RTP_FLAG_RAW_WRITE]++;
6824 
6826  !((val = switch_channel_get_variable(session->channel, "disable_rtp_auto_adjust")) && switch_true(val)) &&
6828  flags[SWITCH_RTP_FLAG_AUTOADJ]++;
6829  }
6830 
6832  flags[SWITCH_RTP_FLAG_PROXY_MEDIA]++;
6833  }
6835 
6836  flags[SWITCH_RTP_FLAG_USE_TIMER] = 0;
6837  flags[SWITCH_RTP_FLAG_NOBLOCK] = 0;
6838  flags[SWITCH_RTP_FLAG_VIDEO]++;
6839 
6840  if (v_engine->fir) {
6841  flags[SWITCH_RTP_FLAG_FIR]++;
6842  }
6843 
6844  if (v_engine->pli) {
6845  flags[SWITCH_RTP_FLAG_PLI]++;
6846  }
6847 
6848  if (v_engine->nack) {
6849  flags[SWITCH_RTP_FLAG_NACK]++;
6850  }
6851 
6852  if (v_engine->tmmbr) {
6853  flags[SWITCH_RTP_FLAG_TMMBR]++;
6854  }
6855 
6856  v_engine->rtp_session = switch_rtp_new(a_engine->local_sdp_ip,
6857  v_engine->local_sdp_port,
6858  v_engine->cur_payload_map->remote_sdp_ip,
6859  v_engine->cur_payload_map->remote_sdp_port,
6860  v_engine->cur_payload_map->agreed_pt,
6861  1, 90000, flags, NULL, &err, switch_core_session_get_pool(session));
6862 
6863 
6864  switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_DEBUG, "%sVIDEO RTP [%s] %s:%d->%s:%d codec: %u ms: %d [%s]\n",
6865  switch_channel_test_flag(session->channel, CF_PROXY_MEDIA) ? "PROXY " : "",
6866  switch_channel_get_name(session->channel),
6867  a_engine->local_sdp_ip,
6868  v_engine->local_sdp_port,
6869  v_engine->cur_payload_map->remote_sdp_ip,
6871  0, switch_rtp_ready(v_engine->rtp_session) ? "SUCCESS" : err);
6872 
6873 
6874  if (switch_rtp_ready(v_engine->rtp_session)) {
6875  const char *ssrc;
6876 
6877  if (v_engine->fir) {
6879  }
6880 
6881  if (v_engine->pli) {
6883  }
6884 
6885  switch_rtp_set_payload_map(v_engine->rtp_session, &v_engine->payload_map);
6888 
6889  if ((ssrc = switch_channel_get_variable(session->channel, "rtp_use_video_ssrc"))) {
6890  uint32_t ssrc_ul = (uint32_t) strtoul(ssrc, NULL, 10);
6891  switch_rtp_set_ssrc(v_engine->rtp_session, ssrc_ul);
6892  v_engine->ssrc = ssrc_ul;
6893  } else {
6894  switch_rtp_set_ssrc(v_engine->rtp_session, v_engine->ssrc);
6895  }
6896 
6897  if (v_engine->remote_ssrc) {
6898  switch_rtp_set_remote_ssrc(v_engine->rtp_session, v_engine->remote_ssrc);
6899  }
6900 
6901  if (v_engine->ice_in.cands[v_engine->ice_in.chosen[0]][0].ready) {
6902 
6903  gen_ice(session, SWITCH_MEDIA_TYPE_VIDEO, NULL, 0);
6904 
6905  switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_INFO, "Activating Video ICE\n");
6906 
6908  v_engine->ice_in.ufrag,
6909  v_engine->ice_out.ufrag,
6910  v_engine->ice_out.pwd,
6911  v_engine->ice_in.pwd,
6912  IPR_RTP,
6913 #ifdef GOOGLE_ICE
6914  ICE_GOOGLE_JINGLE,
6915  NULL
6916 #else
6917  switch_ice_direction(session) ==
6919  &v_engine->ice_in
6920 #endif
6921  );
6922 
6923 
6924  }
6925 
6926  if ((val = switch_channel_get_variable(session->channel, "rtcp_video_interval_msec")) || (val = smh->mparams->rtcp_video_interval_msec)) {
6927  const char *rport = switch_channel_get_variable(session->channel, "rtp_remote_video_rtcp_port");
6928  switch_port_t remote_port = v_engine->remote_rtcp_port;
6929 
6930  if (rport) {
6931  remote_port = (switch_port_t)atoi(rport);
6932  }
6933  if (!strcasecmp(val, "passthru")) {
6934  switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_INFO, "Activating VIDEO RTCP PASSTHRU PORT %d\n", remote_port);
6935  switch_rtp_activate_rtcp(v_engine->rtp_session, -1, remote_port, v_engine->rtcp_mux > 0);
6936  } else {
6937  int interval = atoi(val);
6938  if (interval < 100 || interval > 500000) {
6940  "Invalid rtcp interval spec [%d] must be between 100 and 500000\n", interval);
6941  interval = 5000;
6942  }
6944  "Activating VIDEO RTCP PORT %d interval %d mux %d\n", remote_port, interval, v_engine->rtcp_mux);
6945  switch_rtp_activate_rtcp(v_engine->rtp_session, interval, remote_port, v_engine->rtcp_mux > 0);
6946 
6947  }
6948 
6949 
6950  if (v_engine->ice_in.cands[v_engine->ice_in.chosen[1]][1].ready) {
6951 
6952  if (v_engine->rtcp_mux > 0 && !strcmp(v_engine->ice_in.cands[v_engine->ice_in.chosen[1]][1].con_addr, v_engine->ice_in.cands[v_engine->ice_in.chosen[0]][0].con_addr)
6953  && v_engine->ice_in.cands[v_engine->ice_in.chosen[1]][1].con_port == v_engine->ice_in.cands[v_engine->ice_in.chosen[0]][0].con_port) {
6954  switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_INFO, "Skipping VIDEO RTCP ICE (Same as VIDEO RTP)\n");
6955  } else {
6956 
6957  switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_INFO, "Activating VIDEO RTCP ICE\n");
6959  v_engine->ice_in.ufrag,
6960  v_engine->ice_out.ufrag,
6961  v_engine->ice_out.pwd,
6962  v_engine->ice_in.pwd,
6963  IPR_RTCP,
6964 #ifdef GOOGLE_ICE
6965  ICE_GOOGLE_JINGLE,
6966  NULL
6967 #else
6968  switch_ice_direction(session) ==
6970  &v_engine->ice_in
6971 #endif
6972  );
6973 
6974 
6975 
6976  }
6977 
6978  }
6979  }
6980 
6981  if (!zstr(v_engine->local_dtls_fingerprint.str) && switch_rtp_has_dtls() && dtls_ok(smh->session)) {
6982  dtls_type_t xtype,
6983  dtype = v_engine->dtls_controller ? DTLS_TYPE_CLIENT : DTLS_TYPE_SERVER;
6984  xtype = DTLS_TYPE_RTP;
6985  if (v_engine->rtcp_mux > 0 && smh->mparams->rtcp_video_interval_msec) xtype |= DTLS_TYPE_RTCP;
6986 
6987  switch_rtp_add_dtls(v_engine->rtp_session, &v_engine->local_dtls_fingerprint, &v_engine->remote_dtls_fingerprint, dtype | xtype);
6988 
6989  if (v_engine->rtcp_mux < 1 && smh->mparams->rtcp_video_interval_msec) {
6990  xtype = DTLS_TYPE_RTCP;
6991  switch_rtp_add_dtls(v_engine->rtp_session, &v_engine->local_dtls_fingerprint, &v_engine->remote_dtls_fingerprint, dtype | xtype);
6992  }
6993  }
6994 
6995 
6996  if ((val = switch_channel_get_variable(session->channel, "rtp_manual_video_rtp_bugs"))) {
6997  switch_core_media_parse_rtp_bugs(&v_engine->rtp_bugs, val);
6998  }
6999 
7000  if (switch_channel_test_flag(session->channel, CF_AVPF)) {
7002  }
7003 
7005 
7006  //XX
7007 
7008 
7009  switch_channel_set_variable_printf(session->channel, "rtp_use_video_pt", "%d", v_engine->cur_payload_map->agreed_pt);
7010  v_engine->ssrc = switch_rtp_get_ssrc(v_engine->rtp_session);
7011  switch_channel_set_variable_printf(session->channel, "rtp_use_video_ssrc", "%u", v_engine->ssrc);
7012 
7014 
7015 
7017  switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_DEBUG, "Activating video UDPTL mode\n");
7019  }
7020 
7021  } else {
7022  switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_ERROR, "VIDEO RTP REPORTS ERROR: [%s]\n", switch_str_nil(err));
7024  goto end;
7025  }
7026  }
7027 
7028  } else {
7029  switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_ERROR, "AUDIO RTP REPORTS ERROR: [%s]\n", switch_str_nil(err));
7031  status = SWITCH_STATUS_FALSE;
7032  goto end;
7033  }
7034 
7035  video_up:
7036 
7037  if (session && v_engine) {
7038  check_dtls_reinvite(session, v_engine);
7039  }
7040 
7041  status = SWITCH_STATUS_SUCCESS;
7042 
7043  end:
7044 
7046 
7047  switch_core_recovery_track(session);
7048 
7049  return status;
7050 
7051 }
switch_status_t switch_channel_set_variable_printf(switch_channel_t *channel, const char *varname, const char *fmt,...)
switch_status_t switch_core_session_start_video_thread(switch_core_session_t *session)
#define switch_channel_hangup(channel, hangup_cause)
Hangup a channel flagging it's state machine to end.
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)
Definition: switch_rtp.c:4186
#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_core_media_set_video_codec(switch_core_session_t *session, int force)
int chosen[2]
Definition: switch_rtp.h:107
#define switch_channel_up(_channel)
char * remote_sdp_ip
static void switch_core_session_apply_crypto(switch_core_session_t *session, switch_media_type_t type)
#define SWITCH_LOCAL_VIDEO_IP_VARIABLE
Definition: switch_types.h:214
switch_core_media_vflag_t vflags
char str[MAX_FPSTRLEN]
Definition: switch_core.h:154
switch_status_t switch_rtp_set_payload_map(switch_rtp_t *rtp_session, payload_map_t **pmap)
Definition: switch_rtp.c:2454
void switch_rtp_intentional_bugs(switch_rtp_t *rtp_session, switch_rtp_bug_flag_t bugs)
Definition: switch_rtp.c:2467
static void gen_ice(switch_core_session_t *session, switch_media_type_t type, const char *ip, switch_port_t port)
void switch_core_media_parse_rtp_bugs(switch_rtp_bug_flag_t *flag_pole, const char *str)
#define SWITCH_LOCAL_VIDEO_PORT_VARIABLE
Definition: switch_types.h:215
switch_status_t switch_core_media_set_codec(switch_core_session_t *session, int force, uint32_t codec_flags)
void switch_rtp_set_telephony_recv_event(switch_rtp_t *rtp_session, switch_payload_t te)
Definition: switch_rtp.c:4022
int32_t switch_media_handle_test_media_flag(switch_media_handle_t *smh, switch_core_media_flag_t flag)
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_channel_test_flag(switch_channel_t *channel, switch_channel_flag_t flag)
Test for presence of given flag on a given channel.
payload_map_t * payload_map
#define SWITCH_ADVERTISED_MEDIA_IP_VARIABLE
Definition: switch_types.h:209
switch_rtp_bug_flag_t manual_video_rtp_bugs
void switch_rtp_set_max_missed_packets(switch_rtp_t *rtp_session, uint32_t max)
Definition: switch_rtp.c:2753
switch_port_t switch_rtp_get_remote_port(switch_rtp_t *rtp_session)
Definition: switch_rtp.c:2827
switch_media_handle_t * media_handle
#define zstr(x)
Definition: switch_utils.h:281
#define SWITCH_LOCAL_MEDIA_PORT_VARIABLE
Definition: switch_types.h:208
switch_status_t switch_rtp_udptl_mode(switch_rtp_t *rtp_session)
Definition: switch_rtp.c:2843
void switch_rtp_reset_media_timer(switch_rtp_t *rtp_session)
Definition: switch_rtp.c:2817
void switch_rtp_set_telephony_event(switch_rtp_t *rtp_session, switch_payload_t te)
Set the payload type to consider RFC2833 DTMF.
Definition: switch_rtp.c:4014
_Ret_ switch_channel_t * switch_core_session_get_channel(_In_ switch_core_session_t *session)
Retrieve a pointer to the channel object associated with a given session.
void switch_core_recovery_track(switch_core_session_t *session)
void switch_core_media_check_video_codecs(switch_core_session_t *session)
#define SWITCH_MUTEX_NESTED
Definition: switch_apr.h:318
#define SWITCH_REMOTE_MEDIA_IP_VARIABLE
Definition: switch_types.h:210
switch_channel_t * channel
switch_rtp_t * rtp_session
int switch_rtp_has_dtls(void)
Definition: switch_rtp.c:3207
switch_codec_t read_codec
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.
Definition: switch_rtp.c:4241
#define switch_channel_get_variable(_c, _v)
switch_core_session_t * session
static void check_dtls_reinvite(switch_core_session_t *session, switch_rtp_engine_t *engine)
payload_map_t * cur_payload_map
char * con_addr
Definition: switch_rtp.h:93
dtls_fingerprint_t local_dtls_fingerprint
switch_status_t switch_mutex_init(switch_mutex_t **lock, unsigned int flags, switch_memory_pool_t *pool)
Definition: switch_apr.c:270
switch_status_t switch_rtp_set_remote_ssrc(switch_rtp_t *rtp_session, uint32_t ssrc)
Definition: switch_rtp.c:3733
switch_status_t switch_rtp_set_ssrc(switch_rtp_t *rtp_session, uint32_t ssrc)
Definition: switch_rtp.c:3725
uint8_t ready
Definition: switch_rtp.h:99
uint8_t negotiated
uint16_t switch_port_t
switch_port_t local_sdp_port
int switch_core_media_toggle_hold(switch_core_session_t *session, int sendonly)
switch_status_t switch_rtp_set_remote_address(switch_rtp_t *rtp_session, const char *host, switch_port_t port, switch_port_t remote_rtcp_port, switch_bool_t change_adv_addr, const char **err)
Assign a remote address to the RTP session.
Definition: switch_rtp.c:2913
char * ufrag
Definition: switch_rtp.h:109
static void check_jb(switch_core_session_t *session, const char *input, int32_t jb_msec, int32_t maxlen, switch_bool_t silent)
void switch_rtp_set_cng_pt(switch_rtp_t *rtp_session, switch_payload_t pt)
Set the payload type for comfort noise.
Definition: switch_rtp.c:4030
dtls_type_t
Definition: switch_core.h:157
switch_rtp_bug_flag_t manual_rtp_bugs
#define SWITCH_LOCAL_MEDIA_IP_VARIABLE
Definition: switch_types.h:207
#define switch_str_nil(s)
Make a null string a blank string instead.
Definition: switch_utils.h:903
dtls_fingerprint_t remote_dtls_fingerprint
void switch_rtp_set_flag(switch_rtp_t *rtp_session, switch_rtp_flag_t flag)
Set an RTP Flag.
Definition: switch_rtp.c:4702
#define switch_channel_down(_channel)
switch_call_direction_t switch_ice_direction(switch_core_session_t *session)
char * switch_rtp_get_remote_host(switch_rtp_t *rtp_session)
Definition: switch_rtp.c:2822
switch_status_t
Common return values.
switch_rtp_engine_t engines[SWITCH_MEDIA_TYPE_TOTAL]
uint32_t switch_rtp_get_ssrc(switch_rtp_t *rtp_session)
Retrieve the SSRC from a given RTP session.
Definition: switch_rtp.c:8089
static int dtls_ok(switch_core_session_t *session)
switch_rtp_flag_t
RTP Related Flags.
Definition: switch_types.h:723
char * pwd
Definition: switch_rtp.h:110
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.
Definition: switch_rtp.c:4645
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: switch_rtp.c:3294
#define switch_channel_set_flag(_c, _f)
switch_call_direction_t switch_channel_direction(switch_channel_t *channel)
switch_codec_implementation_t read_impl
#define SWITCH_REMOTE_MEDIA_PORT_VARIABLE
Definition: switch_types.h:211
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
switch_port_t remote_rtcp_port
switch_rtp_bug_flag_t auto_rtp_bugs
switch_status_t switch_core_media_choose_port(switch_core_session_t *session, switch_media_type_t type, int force)
switch_payload_t agreed_pt
icand_t cands[MAX_CAND][2]
Definition: switch_rtp.h:105
switch_rtp_bug_flag_t rtp_bugs
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.
Definition: switch_rtp.c:7669
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_port_t remote_sdp_port
switch_status_t switch_core_media_proxy_remote_addr(switch_core_session_t *session, const char *sdp_str)
void switch_channel_clear_flag(switch_channel_t *channel, switch_channel_flag_t flag)
Clear given flag(s) from a channel.
#define switch_assert(expr)
switch_mutex_t * read_mutex[2]
#define switch_channel_set_variable(_channel, _var, _val)
char * switch_channel_get_name(switch_channel_t *channel)
Retrieve the name of a given channel.
void switch_rtp_set_interdigit_delay(switch_rtp_t *rtp_session, uint32_t delay)
Definition: switch_rtp.c:4630
memset(buf, 0, buflen)
switch_core_media_params_t * mparams
uint32_t codec_ms
switch_memory_pool_t * switch_core_session_get_pool(_In_ switch_core_session_t *session)
Retrieve the memory pool from a session.
switch_mutex_t * write_mutex[2]
switch_port_t con_port
Definition: switch_rtp.h:94
char * rm_encoding
switch_rtp_crypto_key_type_t crypto_type
switch_status_t switch_core_media_add_ice_acl ( switch_core_session_t session,
switch_media_type_t  type,
const char *  acl_name 
)

Definition at line 3085 of file switch_core_media.c.

References switch_rtp_engine_s::cand_acl, switch_rtp_engine_s::cand_acl_count, switch_media_handle_s::engines, switch_assert, switch_core_session_strdup, SWITCH_MAX_CAND_ACL, SWITCH_STATUS_FALSE, and SWITCH_STATUS_SUCCESS.

3086 {
3087  switch_media_handle_t *smh;
3088  switch_rtp_engine_t *engine;
3089 
3090  switch_assert(session);
3091 
3092  if (!(smh = session->media_handle)) {
3093  return SWITCH_STATUS_FALSE;
3094  }
3095 
3096  engine = &smh->engines[type];
3097 
3098  if (engine->cand_acl_count < SWITCH_MAX_CAND_ACL) {
3099  engine->cand_acl[engine->cand_acl_count++] = switch_core_session_strdup(session, acl_name);
3100  return SWITCH_STATUS_SUCCESS;
3101  }
3102 
3103  return SWITCH_STATUS_FALSE;
3104 }
switch_media_handle_t * media_handle
#define SWITCH_MAX_CAND_ACL
switch_rtp_engine_t engines[SWITCH_MEDIA_TYPE_TOTAL]
char * cand_acl[SWITCH_MAX_CAND_ACL]
#define switch_core_session_strdup(_session, _todup)
Copy a string using memory allocation from a session's pool.
Definition: switch_core.h:717
#define switch_assert(expr)
payload_map_t* switch_core_media_add_payload_map ( switch_core_session_t session,
switch_media_type_t  type,
const char *  name,
const char *  modname,
const char *  fmtp,
switch_sdp_type_t  sdp_type,
uint32_t  pt,
uint32_t  rate,
uint32_t  ptime,
uint32_t  channels,
uint8_t  negotiated 
)

Definition at line 726 of file switch_core_media.c.

References payload_map_s::allocated, payload_map_s::channels, switch_media_handle_s::engines, payload_map_s::hash, payload_map_s::iananame, payload_map_s::modname, payload_map_s::negotiated, payload_map_s::next, switch_rtp_engine_s::payload_map, switch_rtp_engine_s::pmap_tail, payload_map_s::pt, payload_map_s::ptime, payload_map_s::rate, payload_map_s::recv_pt, payload_map_s::rm_encoding, payload_map_s::rm_fmtp, switch_media_handle_s::sdp_mutex, payload_map_s::sdp_type, SDP_TYPE_REQUEST, switch_assert, switch_ci_hashfunc_default(), switch_core_alloc, switch_core_strdup, switch_mutex_lock(), switch_mutex_unlock(), payload_map_s::type, and zstr.

Referenced by switch_core_media_check_outgoing_proxy(), switch_core_media_gen_local_sdp(), switch_core_media_negotiate_sdp(), switch_core_media_patch_sdp(), and switch_core_media_set_r_sdp_codec_string().

737 {
738  payload_map_t *pmap;
739  int exists = 0;
741  switch_rtp_engine_t *engine;
742  int local_pt = 0;
743 
744  switch_assert(session);
745 
746  if (!(smh = session->media_handle)) {
747  return NULL;
748  }
749 
750  engine = &smh->engines[type];
751 
753 
754  for (pmap = engine->payload_map; pmap && pmap->allocated; pmap = pmap->next) {
755  exists = (!strcasecmp(name, pmap->iananame) && pmap->pt == pt && (!pmap->rate || rate == pmap->rate) && (!pmap->ptime || pmap->ptime == ptime));
756 
757  if (exists) {
758 
759  if (!zstr(fmtp) && !zstr(pmap->rm_fmtp)) {
760  if (strcmp(pmap->rm_fmtp, fmtp)) {
761  exists = 0;
762  local_pt = pmap->pt;
763  continue;
764  }
765  }
766 
767  break;
768  }
769  }
770 
771 
772  if (!exists) {
773  switch_ssize_t hlen = -1;
774 
775  if (engine->payload_map && !engine->payload_map->allocated) {
776  pmap = engine->payload_map;
777  } else {
778  pmap = switch_core_alloc(session->pool, sizeof(*pmap));
779  }
780 
781  pmap->type = type;
782  pmap->iananame = switch_core_strdup(session->pool, name);
783  pmap->rm_encoding = pmap->iananame;
784  pmap->hash = switch_ci_hashfunc_default(pmap->iananame, &hlen);
785  pmap->channels = 1;
786  }
787 
788  pmap->sdp_type = sdp_type;
789 
790  if (ptime) {
791  pmap->ptime = ptime;
792  }
793 
794  if (rate) {
795  pmap->rate = rate;
796  }
797 
798  if (channels) {
799  pmap->channels = channels;
800  }
801 
802  if (modname) {
803  pmap->modname = switch_core_strdup(session->pool, modname);
804  }
805 
806  if (!zstr(fmtp) && (zstr(pmap->rm_fmtp) || strcmp(pmap->rm_fmtp, fmtp))) {
807  pmap->rm_fmtp = switch_core_strdup(session->pool, fmtp);
808  }
809 
810  pmap->allocated = 1;
811 
812  pmap->recv_pt = (switch_payload_t) pt;
813 
814 
815  if (sdp_type == SDP_TYPE_REQUEST || !exists) {
816  pmap->pt = (switch_payload_t) (local_pt ? local_pt : pt);
817  }
818 
819  if (negotiated) {
820  pmap->negotiated = negotiated;
821  }
822 
823  if (!exists) {
824  if (pmap == engine->payload_map) {
825  engine->pmap_tail = pmap;
826  } else if (!engine->payload_map) {
827  engine->payload_map = engine->pmap_tail = pmap;
828  } else {
829  engine->pmap_tail->next = pmap;
830  engine->pmap_tail = engine->pmap_tail->next;
831  }
832  }
833 
835 
836  return pmap;
837 }
uint8_t allocated
#define switch_core_strdup(_pool, _todup)
Copy a string using memory allocation from a given pool.
Definition: switch_core.h:729
unsigned long hash
unsigned int switch_ci_hashfunc_default(const char *char_key, switch_ssize_t *klen)
Definition: switch_apr.c:98
payload_map_t * payload_map
struct payload_map_s * next
switch_media_handle_t * media_handle
#define zstr(x)
Definition: switch_utils.h:281
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
intptr_t switch_ssize_t
#define switch_core_alloc(_pool, _mem)
Allocate memory directly from a memory pool.
Definition: switch_core.h:682
switch_sdp_type_t sdp_type
uint8_t negotiated
switch_payload_t pt
uint32_t ptime
payload_map_t * pmap_tail
switch_media_type_t type
switch_memory_pool_t * pool
switch_rtp_engine_t engines[SWITCH_MEDIA_TYPE_TOTAL]
switch_payload_t recv_pt
switch_mutex_t * sdp_mutex
#define switch_assert(expr)
uint8_t switch_payload_t
char * rm_encoding
void switch_core_media_break ( switch_core_session_t session,
switch_media_type_t  type 
)

Definition at line 9749 of file switch_core_media.c.

References switch_media_handle_s::engines, switch_rtp_engine_s::rtp_session, switch_assert, switch_rtp_break(), and switch_rtp_ready().

Referenced by switch_channel_queue_dtmf().

9750 {
9751  switch_media_handle_t *smh;
9752 
9753  switch_assert(session);
9754 
9755  if (!(smh = session->media_handle)) {
9756  return;
9757  }
9758 
9759  if (switch_rtp_ready(smh->engines[type].rtp_session)) {
9760  switch_rtp_break(smh->engines[type].rtp_session);
9761  }
9762 }
uint8_t switch_rtp_ready(switch_rtp_t *rtp_session)
Test if an RTP session is ready.
Definition: switch_rtp.c:4452
switch_media_handle_t * media_handle
switch_rtp_t * rtp_session
switch_rtp_engine_t engines[SWITCH_MEDIA_TYPE_TOTAL]
void switch_rtp_break(switch_rtp_t *rtp_session)
Definition: switch_rtp.c:4385
#define switch_assert(expr)
switch_status_t switch_core_media_check_autoadj ( switch_core_session_t session)

Definition at line 533 of file switch_core_media.c.

References CF_AVPF, switch_media_handle_s::engines, switch_rtp_engine_s::rtp_session, SCMF_DISABLE_RTP_AUTOADJ, switch_assert, switch_channel_get_variable, switch_channel_test_flag(), switch_media_handle_test_media_flag(), SWITCH_MEDIA_TYPE_AUDIO, SWITCH_MEDIA_TYPE_VIDEO, SWITCH_RTP_FLAG_AUTOADJ, switch_rtp_set_flag(), SWITCH_STATUS_FALSE, SWITCH_STATUS_SUCCESS, and switch_true().

Referenced by switch_channel_perform_mark_answered(), switch_channel_perform_mark_pre_answered(), switch_core_media_negotiate_sdp(), and switch_core_media_toggle_hold().

534 {
535  switch_rtp_engine_t *a_engine;
536  switch_rtp_engine_t *v_engine;
538  const char *val;
539  int x = 0;
540 
541  switch_assert(session);
542 
543  if (!(smh = session->media_handle)) {
544  return SWITCH_STATUS_FALSE;
545  }
546 
547  a_engine = &smh->engines[SWITCH_MEDIA_TYPE_AUDIO];
548  v_engine = &smh->engines[SWITCH_MEDIA_TYPE_VIDEO];
549 
551  !((val = switch_channel_get_variable(session->channel, "disable_rtp_auto_adjust")) && switch_true(val)) &&
553  /* Reactivate the NAT buster flag. */
554 
555  if (a_engine->rtp_session) {
557  x++;
558  }
559 
560  if (v_engine->rtp_session) {
562  x++;
563  }
564  }
565 
567 }
int32_t switch_media_handle_test_media_flag(switch_media_handle_t *smh, switch_core_media_flag_t flag)
static int switch_true(const char *expr)
Evaluate the truthfullness of a string expression.
Definition: switch_utils.h:450
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_media_handle_t * media_handle
switch_channel_t * channel
switch_rtp_t * rtp_session
#define switch_channel_get_variable(_c, _v)
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_engine_t engines[SWITCH_MEDIA_TYPE_TOTAL]
#define switch_assert(expr)
switch_bool_t switch_core_media_check_dtls ( switch_core_session_t session,
switch_media_type_t  type 
)

Definition at line 9193 of file switch_core_media.c.

References CF_DTLS, check_engine(), switch_media_handle_s::engines, switch_rtp_engine_s::rmode, switch_rtp_engine_s::rtp_session, switch_assert, switch_channel_media_up, switch_channel_ready, switch_channel_test_flag(), SWITCH_FALSE, SWITCH_MEDIA_FLOW_DISABLED, and SWITCH_TRUE.

Referenced by switch_channel_perform_mark_answered(), switch_channel_perform_mark_pre_answered(), and video_helper_thread().

9194 {
9195  switch_media_handle_t *smh;
9196  switch_rtp_engine_t *engine;
9197  int checking = 0;
9198 
9199  switch_assert(session);
9200 
9201  if (!(smh = session->media_handle)) {
9202  return SWITCH_FALSE;
9203  }
9204 
9205  if (!switch_channel_media_up(session->channel)) {
9206  return SWITCH_FALSE;
9207  }
9208 
9209  if (!switch_channel_test_flag(session->channel, CF_DTLS)) {
9210  return SWITCH_TRUE;
9211  }
9212 
9213  engine = &smh->engines[type];
9214 
9215  if (engine->rmode == SWITCH_MEDIA_FLOW_DISABLED) {
9216  return SWITCH_TRUE;
9217  }
9218 
9219  do {
9220  if (engine->rtp_session) checking = check_engine(engine);
9221  } while (switch_channel_ready(session->channel) && checking);
9222 
9223  if (!checking) {
9224  return SWITCH_TRUE;
9225  }
9226 
9227  return SWITCH_FALSE;
9228 }
#define switch_channel_ready(_channel)
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_media_handle_t * media_handle
switch_channel_t * channel
switch_rtp_t * rtp_session
switch_media_flow_t rmode
switch_rtp_engine_t engines[SWITCH_MEDIA_TYPE_TOTAL]
static int check_engine(switch_rtp_engine_t *engine)
#define switch_assert(expr)
#define switch_channel_media_up(_channel)
void switch_core_media_check_dtmf_type ( switch_core_session_t session)

Definition at line 7403 of file switch_core_media.c.

References DTMF_2833, DTMF_INFO, DTMF_NONE, switch_core_media_params_s::dtmf_type, switch_media_handle_s::mparams, switch_assert, and switch_channel_get_variable.

Referenced by switch_core_media_gen_local_sdp().

7404 {
7405  const char *val;
7406  switch_media_handle_t *smh;
7407 
7408  switch_assert(session);
7409 
7410  if (!(smh = session->media_handle)) {
7411  return;
7412  }
7413 
7414  if ((val = switch_channel_get_variable(session->channel, "dtmf_type"))) {
7415  if (!strcasecmp(val, "rfc2833")) {
7416  smh->mparams->dtmf_type = DTMF_2833;
7417  } else if (!strcasecmp(val, "info")) {
7418  smh->mparams->dtmf_type = DTMF_INFO;
7419  } else if (!strcasecmp(val, "none")) {
7420  smh->mparams->dtmf_type = DTMF_NONE;
7421  }
7422  }
7423 }
switch_media_handle_t * media_handle
switch_channel_t * channel
#define switch_channel_get_variable(_c, _v)
switch_core_media_dtmf_t dtmf_type
#define switch_assert(expr)
switch_core_media_params_t * mparams
int switch_core_media_check_nat ( switch_media_handle_t smh,
const char *  network_ip 
)

Definition at line 5801 of file switch_core_media.c.

References switch_assert, and switch_check_network_list_ip.

Referenced by switch_core_media_choose_port(), and switch_core_media_deactivate_rtp().

5802 {
5803  switch_assert(network_ip);
5804 
5805  return (smh->mparams->extsipip &&
5806  !switch_check_network_list_ip(network_ip, "loopback.auto") &&
5807  !switch_check_network_list_ip(network_ip, smh->mparams->local_network));
5808 }
#define switch_check_network_list_ip(_ip_str, _list_name)
Definition: switch_core.h:2404
#define switch_assert(expr)
switch_core_media_params_t * mparams
void switch_core_media_check_outgoing_proxy ( switch_core_session_t session,
switch_core_session_t o_session 
)

Definition at line 10368 of file switch_core_media.c.

References CF_PROXY_MEDIA, CF_VIDEO, CF_VIDEO_POSSIBLE, clear_pmaps(), switch_rtp_engine_s::cur_payload_map, switch_media_handle_s::engines, SDP_TYPE_RESPONSE, switch_assert, switch_channel_get_variable, switch_channel_set_flag, switch_channel_test_flag(), switch_core_media_add_payload_map(), switch_core_media_choose_port(), SWITCH_MEDIA_TYPE_AUDIO, SWITCH_MEDIA_TYPE_VIDEO, SWITCH_R_SDP_VARIABLE, switch_stristr(), and SWITCH_TRUE.

10369 {
10370  switch_rtp_engine_t *a_engine, *v_engine;
10371  switch_media_handle_t *smh;
10372  const char *r_sdp = NULL;
10373  payload_map_t *pmap;
10374 
10375  switch_assert(session);
10376 
10377  if (!switch_channel_test_flag(o_session->channel, CF_PROXY_MEDIA)) {
10378  return;
10379  }
10380 
10381  if (!(smh = session->media_handle)) {
10382  return;
10383  }
10384 
10386 
10387  a_engine = &smh->engines[SWITCH_MEDIA_TYPE_AUDIO];
10388  v_engine = &smh->engines[SWITCH_MEDIA_TYPE_VIDEO];
10389 
10391 
10392  clear_pmaps(a_engine);
10393  clear_pmaps(v_engine);
10394 
10395  pmap = switch_core_media_add_payload_map(session,
10397  "PROXY",
10398  NULL,
10399  NULL,
10401  0,
10402  8000,
10403  20,
10404  1,
10405  SWITCH_TRUE);
10406 
10407  a_engine->cur_payload_map = pmap;
10408 
10409  if (switch_stristr("m=video", r_sdp)) {
10411  pmap = switch_core_media_add_payload_map(session,
10413  "PROXY-VID",
10414  NULL,
10415  NULL,
10417  0,
10418  90000,
10419  90000,
10420  1,
10421  SWITCH_TRUE);
10422 
10423  v_engine->cur_payload_map = pmap;
10424 
10427  }
10428 }
static void clear_pmaps(switch_rtp_engine_t *engine)
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_media_handle_t * media_handle
payload_map_t * switch_core_media_add_payload_map(switch_core_session_t *session, switch_media_type_t type, const char *name, const char *modname, const char *fmtp, switch_sdp_type_t sdp_type, uint32_t pt, uint32_t rate, uint32_t ptime, uint32_t channels, uint8_t negotiated)
switch_channel_t * channel
#define switch_channel_get_variable(_c, _v)
payload_map_t * cur_payload_map
#define SWITCH_R_SDP_VARIABLE
Definition: switch_types.h:196
switch_rtp_engine_t engines[SWITCH_MEDIA_TYPE_TOTAL]
#define switch_channel_set_flag(_c, _f)
switch_status_t switch_core_media_choose_port(switch_core_session_t *session, switch_media_type_t type, int force)
const char * switch_stristr(const char *instr, const char *str)
#define switch_assert(expr)
switch_bool_t switch_core_media_check_udptl_mode ( switch_core_session_t session,
switch_media_type_t  type 
)

Definition at line 9913 of file switch_core_media.c.

References switch_media_handle_s::engines, switch_rtp_engine_s::rtp_session, switch_assert, SWITCH_FALSE, SWITCH_RTP_FLAG_UDPTL, switch_rtp_ready(), switch_rtp_test_flag(), and SWITCH_TRUE.

9914 {
9915  switch_media_handle_t *smh;
9916 
9917  switch_assert(session);
9918 
9919  if (!(smh = session->media_handle)) {
9920  return SWITCH_FALSE;
9921  }
9922 
9923  if (switch_rtp_ready(smh->engines[type].rtp_session)) {
9925  }
9926 
9927  return SWITCH_FALSE;
9928 }
uint8_t switch_rtp_ready(switch_rtp_t *rtp_session)
Test if an RTP session is ready.
Definition: switch_rtp.c:4452
switch_media_handle_t * media_handle
switch_rtp_t * rtp_session
switch_rtp_engine_t engines[SWITCH_MEDIA_TYPE_TOTAL]
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
#define switch_assert(expr)
void switch_core_media_check_video_codecs ( switch_core_session_t session)

Definition at line 3107 of file switch_core_media.c.

References CF_NOVIDEO, CF_VIDEO_POSSIBLE, switch_codec_implementation::codec_type, switch_media_handle_s::codecs, switch_media_handle_s::mparams, switch_core_media_params_s::num_codecs, switch_assert, SWITCH_CALL_DIRECTION_INBOUND, switch_channel_direction(), switch_channel_set_flag, switch_channel_test_flag(), SWITCH_CODEC_TYPE_VIDEO, and switch_media_handle_s::video_count.

Referenced by switch_core_media_activate_rtp(), switch_core_media_choose_ports(), switch_core_media_negotiate_sdp(), and switch_core_media_receive_message().

3108 {
3109  switch_media_handle_t *smh;
3110 
3111  switch_assert(session);
3112 
3113  if (!(smh = session->media_handle)) {
3114  return;
3115  }
3116 
3118  int i;
3119  smh->video_count = 0;
3120  for (i = 0; i < smh->mparams->num_codecs; i++) {
3121 
3122  if (smh->codecs[i]->codec_type == SWITCH_CODEC_TYPE_VIDEO) {
3125  continue;
3126  }
3127  smh->video_count++;
3128  }
3129  }
3130  if (smh->video_count) {
3132  }
3133  }
3134 }
const switch_codec_implementation_t * codecs[SWITCH_MAX_CODECS]
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_media_handle_t * media_handle
switch_channel_t * channel
#define switch_channel_set_flag(_c, _f)
switch_call_direction_t switch_channel_direction(switch_channel_t *channel)
#define switch_assert(expr)
switch_core_media_params_t * mparams
int switch_core_media_check_video_function ( switch_core_session_t session)

Definition at line 5559 of file switch_core_media.c.

References switch_media_handle_s::control_mutex, switch_mutex_lock(), switch_mutex_unlock(), and switch_media_handle_s::video_function_running.

Referenced by audio_bridge_thread().

5560 {
5561  switch_media_handle_t *smh;
5562  int r;
5563 
5564  if (!(smh = session->media_handle)) {
5565  return 0;
5566  }
5567 
5569  r = (smh->video_function_running > 0);
5571 
5572  return r;
5573 }
switch_media_handle_t * media_handle
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
switch_mutex_t * control_mutex
switch_status_t switch_core_media_choose_port ( switch_core_session_t session,
switch_media_type_t  type,
int  force 
)

Definition at line 5913 of file switch_core_media.c.

References switch_core_media_params_s::adv_sdp_audio_ip, switch_rtp_engine_s::adv_sdp_ip, switch_rtp_engine_s::adv_sdp_port, CF_PROXY_MEDIA, CF_PROXY_MODE, switch_media_handle_s::engines, switch_core_media_params_s::extrtpip, switch_rtp_engine_s::local_sdp_ip, switch_rtp_engine_s::local_sdp_port, switch_media_handle_s::mparams, switch_core_media_params_s::remote_ip, switch_core_media_params_s::rtpip, SWITCH_ADVERTISED_MEDIA_IP_VARIABLE, switch_assert, switch_channel_get_variable, SWITCH_CHANNEL_SESSION_LOG, switch_channel_set_variable, switch_channel_set_variable_printf(), switch_channel_test_flag(), switch_core_media_check_nat(), switch_core_media_ext_address_lookup(), switch_core_session_strdup, SWITCH_FALSE, SWITCH_LOCAL_MEDIA_IP_VARIABLE, SWITCH_LOCAL_MEDIA_PORT_VARIABLE, SWITCH_LOCAL_VIDEO_IP_VARIABLE, SWITCH_LOCAL_VIDEO_PORT_VARIABLE, SWITCH_LOG_CRIT, switch_log_printf(), switch_media_type2str(), SWITCH_MEDIA_TYPE_AUDIO, switch_nat_add_mapping(), SWITCH_NAT_UDP, switch_rtp_release_port(), switch_rtp_request_port(), switch_snprintf(), SWITCH_STATUS_FALSE, SWITCH_STATUS_SUCCESS, and zstr.

Referenced by switch_core_media_activate_rtp(), switch_core_media_check_outgoing_proxy(), switch_core_media_choose_ports(), switch_core_media_gen_local_sdp(), and switch_core_media_patch_sdp().

5914 {
5915  char *lookup_rtpip; /* Pointer to externally looked up address */
5916  switch_port_t sdp_port; /* The external port to be sent in the SDP */
5917  const char *use_ip = NULL; /* The external IP to be sent in the SDP */
5918  switch_rtp_engine_t *engine;
5919  switch_media_handle_t *smh;
5920  const char *tstr = switch_media_type2str(type);
5921  char vname[128] = "";
5922 
5923  switch_assert(session);
5924 
5925  if (!(smh = session->media_handle)) {
5926  return SWITCH_STATUS_FALSE;
5927  }
5928 
5929  engine = &smh->engines[type];
5930 
5931  lookup_rtpip = smh->mparams->rtpip;
5932 
5933  /* Don't do anything if we're in proxy mode or if a (remote) port already has been found */
5934  if (!force) {
5937  return SWITCH_STATUS_SUCCESS;
5938  }
5939  }
5940 
5941  /* Release the local sdp port */
5942  if (engine->local_sdp_port) {
5944  }
5945 
5946  /* Request a local port from the core's allocator */
5947  if (!(engine->local_sdp_port = switch_rtp_request_port(smh->mparams->rtpip))) {
5948  switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_CRIT, "No %s RTP ports available!\n", tstr);
5949  return SWITCH_STATUS_FALSE;
5950  }
5951 
5952  engine->local_sdp_ip = smh->mparams->rtpip;
5953 
5954 
5955  sdp_port = engine->local_sdp_port;
5956 
5957  /* Check if NAT is detected */
5958  if (!zstr(smh->mparams->remote_ip) && switch_core_media_check_nat(smh, smh->mparams->remote_ip)) {
5959  /* Yes, map the port through switch_nat */
5961 
5962  switch_snprintf(vname, sizeof(vname), "rtp_adv_%s_ip", tstr);
5963 
5964  /* Find an IP address to use */
5965  if (!(use_ip = switch_channel_get_variable(session->channel, vname))
5966  && !zstr(smh->mparams->extrtpip)) {
5967  use_ip = smh->mparams->extrtpip;
5968  }
5969 
5970  if (use_ip) {
5971  if (switch_core_media_ext_address_lookup(session, &lookup_rtpip, &sdp_port, use_ip) != SWITCH_STATUS_SUCCESS) {
5972  /* Address lookup was required and fail (external ip was "host:..." or "stun:...") */
5973  return SWITCH_STATUS_FALSE;
5974  } else {
5975  /* Address properly resolved, use it as external ip */
5976  use_ip = lookup_rtpip;
5977  }
5978  } else {
5979  /* No external ip found, use the profile's rtp ip */
5980  use_ip = smh->mparams->rtpip;
5981  }
5982  } else {
5983  /* No NAT traversal required, use the profile's rtp ip */
5984  use_ip = smh->mparams->rtpip;
5985  }
5986 
5987  engine->adv_sdp_port = sdp_port;
5988  engine->adv_sdp_ip = smh->mparams->adv_sdp_audio_ip = smh->mparams->extrtpip = switch_core_session_strdup(session, use_ip);
5989 
5990 
5991  if (type == SWITCH_MEDIA_TYPE_AUDIO) {
5995  } else {
5998  }
5999 
6000  return SWITCH_STATUS_SUCCESS;
6001 }
switch_status_t switch_channel_set_variable_printf(switch_channel_t *channel, const char *varname, const char *fmt,...)
#define SWITCH_CHANNEL_SESSION_LOG(x)
int switch_core_media_check_nat(switch_media_handle_t *smh, const char *network_ip)
#define SWITCH_LOCAL_VIDEO_IP_VARIABLE
Definition: switch_types.h:214
switch_status_t switch_core_media_ext_address_lookup(switch_core_session_t *session, char **ip, switch_port_t *port, const char *sourceip)
switch_status_t switch_nat_add_mapping(switch_port_t port, switch_nat_ip_proto_t proto, switch_port_t *external_port, switch_bool_t sticky)
Maps a port through the NAT Traversal System.
Definition: switch_nat.c:619
#define SWITCH_LOCAL_VIDEO_PORT_VARIABLE
Definition: switch_types.h:215
int switch_snprintf(_Out_z_cap_(len) char *buf, _In_ switch_size_t len, _In_z_ _Printf_format_string_ const char *format,...)
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.
#define SWITCH_ADVERTISED_MEDIA_IP_VARIABLE
Definition: switch_types.h:209
switch_media_handle_t * media_handle
#define zstr(x)
Definition: switch_utils.h:281
#define SWITCH_LOCAL_MEDIA_PORT_VARIABLE
Definition: switch_types.h:208
static const char * switch_media_type2str(switch_media_type_t type)
switch_channel_t * channel
#define switch_channel_get_variable(_c, _v)
uint16_t switch_port_t
switch_port_t local_sdp_port
#define SWITCH_LOCAL_MEDIA_IP_VARIABLE
Definition: switch_types.h:207
switch_port_t switch_rtp_request_port(const char *ip)
Request a new port to be used for media.
Definition: switch_rtp.c:2431
switch_rtp_engine_t engines[SWITCH_MEDIA_TYPE_TOTAL]
switch_port_t adv_sdp_port
void switch_rtp_release_port(const char *ip, switch_port_t port)
Definition: switch_rtp.c:2415
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_session_strdup(_session, _todup)
Copy a string using memory allocation from a session's pool.
Definition: switch_core.h:717
#define switch_assert(expr)
#define switch_channel_set_variable(_channel, _var, _val)
switch_core_media_params_t * mparams
switch_status_t switch_core_media_choose_ports ( switch_core_session_t session,
switch_bool_t  audio,
switch_bool_t  video 
)

Definition at line 6003 of file switch_core_media.c.

References CF_VIDEO_POSSIBLE, switch_core_session::channel, switch_media_handle_s::mparams, switch_core_media_params_s::rtpip, switch_media_handle_s::session, SWITCH_CAUSE_BEARERCAPABILITY_NOTAVAIL, switch_channel_get_name(), switch_channel_hangup, SWITCH_CHANNEL_SESSION_LOG, switch_channel_test_flag(), switch_core_media_check_video_codecs(), switch_core_media_choose_port(), SWITCH_LOG_ERROR, switch_log_printf(), SWITCH_MEDIA_TYPE_AUDIO, SWITCH_MEDIA_TYPE_VIDEO, SWITCH_STATUS_FALSE, SWITCH_STATUS_SUCCESS, and zstr.

6004 {
6006  switch_media_handle_t *smh;
6007 
6008  if (!(smh = session->media_handle)) {
6009  return SWITCH_STATUS_FALSE;
6010  }
6011 
6012  if (zstr(smh->mparams->rtpip)) {
6013 
6014  switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_ERROR, "%s has no media ip\n",
6017 
6018  return SWITCH_STATUS_FALSE;
6019  }
6020 
6021  if (audio && (status = switch_core_media_choose_port(session, SWITCH_MEDIA_TYPE_AUDIO, 0)) == SWITCH_STATUS_SUCCESS) {
6022  if (video) {
6026  }
6027  }
6028  }
6029 
6030  return status;
6031 }
#define switch_channel_hangup(channel, hangup_cause)
Hangup a channel flagging it's state machine to end.
#define SWITCH_CHANNEL_SESSION_LOG(x)
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_media_handle_t * media_handle
#define zstr(x)
Definition: switch_utils.h:281
void switch_core_media_check_video_codecs(switch_core_session_t *session)
switch_channel_t * channel
switch_core_session_t * session
switch_status_t
Common return values.
switch_status_t switch_core_media_choose_port(switch_core_session_t *session, switch_media_type_t type, int force)
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_channel_get_name(switch_channel_t *channel)
Retrieve the name of a given channel.
switch_core_media_params_t * mparams
void switch_core_media_clear_ice ( switch_core_session_t session)

Definition at line 3030 of file switch_core_media.c.

References clear_ice(), SWITCH_MEDIA_TYPE_AUDIO, and SWITCH_MEDIA_TYPE_VIDEO.

3031 {
3034 
3035 }
static void clear_ice(switch_core_session_t *session, switch_media_type_t type)
void switch_core_media_clear_rtp_flag ( switch_core_session_t session,
switch_media_type_t  type,
switch_rtp_flag_t  flag 
)

Definition at line 9847 of file switch_core_media.c.

References switch_media_handle_s::engines, switch_rtp_engine_s::rtp_session, switch_assert, switch_rtp_clear_flag(), and switch_rtp_ready().

9848 {
9849  switch_media_handle_t *smh;
9850 
9851  switch_assert(session);
9852 
9853  if (!(smh = session->media_handle)) {
9854  return;
9855  }
9856 
9857  if (switch_rtp_ready(smh->engines[type].rtp_session)) {
9858  switch_rtp_clear_flag(smh->engines[type].rtp_session, flag);
9859  }
9860 }
uint8_t switch_rtp_ready(switch_rtp_t *rtp_session)
Test if an RTP session is ready.
Definition: switch_rtp.c:4452
switch_media_handle_t * media_handle
switch_rtp_t * rtp_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
switch_rtp_engine_t engines[SWITCH_MEDIA_TYPE_TOTAL]
#define switch_assert(expr)
switch_status_t switch_core_media_codec_chosen ( switch_core_session_t session,
switch_media_type_t  media 
)

Definition at line 10276 of file switch_core_media.c.

References switch_rtp_engine_s::cur_payload_map, switch_media_handle_s::engines, payload_map_s::iananame, switch_assert, SWITCH_STATUS_FALSE, and SWITCH_STATUS_SUCCESS.

10277 {
10278  switch_rtp_engine_t *engine;
10279  switch_media_handle_t *smh;
10280 
10281  switch_assert(session);
10282 
10283  if (!(smh = session->media_handle)) {
10284  return SWITCH_STATUS_FALSE;
10285  }
10286 
10287  engine = &smh->engines[type];
10288 
10289  if (engine->cur_payload_map->iananame) {
10290  return SWITCH_STATUS_SUCCESS;
10291  }
10292 
10293  return SWITCH_STATUS_FALSE;
10294 }
switch_media_handle_t * media_handle
payload_map_t * cur_payload_map
switch_rtp_engine_t engines[SWITCH_MEDIA_TYPE_TOTAL]
#define switch_assert(expr)
switch_status_t switch_core_media_codec_control ( switch_core_session_t session,
switch_media_type_t  mtype,
switch_io_type_t  iotype,
switch_codec_control_command_t  cmd,
switch_codec_control_type_t  ctype,
void *  cmd_data,
switch_codec_control_type_t  atype,
void *  cmd_arg,
switch_codec_control_type_t rtype,
void **  ret_data 
)

Definition at line 10953 of file switch_core_media.c.

References CF_VIDEO, CF_VIDEO_REFRESH_REQ, switch_media_handle_s::engines, switch_media_handle_s::last_codec_refresh, switch_rtp_engine_s::read_codec, SCC_VIDEO_GEN_KEYFRAME, switch_assert, switch_channel_set_flag, switch_channel_test_flag(), switch_core_codec_control(), switch_core_codec_ready(), SWITCH_IO_READ, SWITCH_MEDIA_TYPE_VIDEO, switch_micro_time_now(), SWITCH_STATUS_BREAK, SWITCH_STATUS_FALSE, SWITCH_STATUS_NOTIMPL, VIDEO_REFRESH_FREQ, and switch_rtp_engine_s::write_codec.

Referenced by process_rtcp_report(), and switch_core_session_video_reinit().

10963 {
10964  switch_rtp_engine_t *engine = NULL;
10965  switch_media_handle_t *smh = NULL;
10966  switch_codec_t *codec = NULL;
10967 
10968  switch_assert(session);
10969 
10970  if (!(smh = session->media_handle)) {
10971  return SWITCH_STATUS_FALSE;
10972  }
10973 
10974  if (!(engine = &smh->engines[mtype])) {
10975  return SWITCH_STATUS_NOTIMPL;
10976  }
10977 
10978  if (iotype == SWITCH_IO_READ) {
10979  codec = &engine->read_codec;
10980  } else {
10981  codec = &engine->write_codec;
10982  }
10983 
10984  if (!switch_core_codec_ready(codec)) {
10985  return SWITCH_STATUS_FALSE;
10986  }
10987 
10988  if (mtype == SWITCH_MEDIA_TYPE_VIDEO) {
10989  if (!switch_channel_test_flag(session->channel, CF_VIDEO)) {
10990  return SWITCH_STATUS_FALSE;
10991  }
10992  }
10993 
10994  if (codec) {
10995  if (cmd == SCC_VIDEO_GEN_KEYFRAME) {
10997 
10998  if (smh->last_codec_refresh && (now - smh->last_codec_refresh) < VIDEO_REFRESH_FREQ) {
10999  return SWITCH_STATUS_BREAK;
11000  }
11001 
11002  smh->last_codec_refresh = now;
11004  }
11005 
11006  return switch_core_codec_control(codec, cmd, ctype, cmd_data, atype, cmd_arg, rtype, ret_data);
11007  }
11008 
11009  return SWITCH_STATUS_FALSE;
11010 }
switch_time_t switch_micro_time_now(void)
Get the current epoch time in microseconds.
Definition: switch_time.c:310
#define VIDEO_REFRESH_FREQ
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_media_handle_t * media_handle
switch_time_t last_codec_refresh
switch_codec_t write_codec
int64_t switch_time_t
Definition: switch_apr.h:188
switch_channel_t * channel
switch_codec_t read_codec
switch_rtp_engine_t engines[SWITCH_MEDIA_TYPE_TOTAL]
#define switch_channel_set_flag(_c, _f)
static switch_bool_t switch_core_codec_ready(switch_codec_t *codec)
#define switch_assert(expr)
switch_status_t switch_core_codec_control(switch_codec_t *codec, switch_codec_control_command_t cmd, switch_codec_control_type_t ctype, void *cmd_data, switch_codec_control_type_t atype, void *cmd_arg, switch_codec_control_type_t *rtype, void **ret_data)
send control data using a codec handle
void switch_core_media_copy_t38_options ( switch_t38_options_t t38_options,
switch_core_session_t session 
)

Definition at line 2616 of file switch_core_media.c.

References switch_t38_options_t::remote_ip, switch_t38_options_t::remote_port, switch_assert, switch_channel_get_private(), switch_channel_set_private(), switch_core_session_alloc, switch_core_session_get_channel(), switch_core_session_strdup, switch_t38_options_t::T38FaxFillBitRemoval, switch_t38_options_t::T38FaxMaxBuffer, switch_t38_options_t::T38FaxMaxDatagram, switch_t38_options_t::T38FaxRateManagement, switch_t38_options_t::T38FaxTranscodingJBIG, switch_t38_options_t::T38FaxTranscodingMMR, switch_t38_options_t::T38FaxUdpEC, switch_t38_options_t::T38MaxBitRate, and switch_t38_options_t::T38VendorInfo.

Referenced by switch_core_media_negotiate_sdp(), and switch_core_media_process_t38_passthru().

2617 {
2619  switch_t38_options_t *local_t38_options = switch_channel_get_private(channel, "t38_options");
2620 
2621  switch_assert(t38_options);
2622 
2623  if (!local_t38_options) {
2624  local_t38_options = switch_core_session_alloc(session, sizeof(switch_t38_options_t));
2625  }
2626 
2627  local_t38_options->T38MaxBitRate = t38_options->T38MaxBitRate;
2628  local_t38_options->T38FaxFillBitRemoval = t38_options->T38FaxFillBitRemoval;
2629  local_t38_options->T38FaxTranscodingMMR = t38_options->T38FaxTranscodingMMR;
2630  local_t38_options->T38FaxTranscodingJBIG = t38_options->T38FaxTranscodingJBIG;
2631  local_t38_options->T38FaxRateManagement = switch_core_session_strdup(session, t38_options->T38FaxRateManagement);
2632  local_t38_options->T38FaxMaxBuffer = t38_options->T38FaxMaxBuffer;
2633  local_t38_options->T38FaxMaxDatagram = t38_options->T38FaxMaxDatagram;
2634  local_t38_options->T38FaxUdpEC = switch_core_session_strdup(session, t38_options->T38FaxUdpEC);
2635  local_t38_options->T38VendorInfo = switch_core_session_strdup(session, t38_options->T38VendorInfo);
2636  local_t38_options->remote_ip = switch_core_session_strdup(session, t38_options->remote_ip);
2637  local_t38_options->remote_port = t38_options->remote_port;
2638 
2639 
2640  switch_channel_set_private(channel, "t38_options", local_t38_options);
2641 
2642 }
switch_status_t switch_channel_set_private(switch_channel_t *channel, const char *key, const void *private_info)
Set private data on channel.
switch_bool_t T38FaxTranscodingMMR
const char * T38FaxRateManagement
switch_bool_t T38FaxTranscodingJBIG
_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 char * T38VendorInfo
const char * T38FaxUdpEC
void * switch_channel_get_private(switch_channel_t *channel, const char *key)
Retrieve private from a given channel.
const char * remote_ip
#define switch_core_session_alloc(_session, _memory)
Allocate memory from a session's pool.
Definition: switch_core.h:694
switch_bool_t T38FaxFillBitRemoval
#define switch_core_session_strdup(_session, _todup)
Copy a string using memory allocation from a session's pool.
Definition: switch_core.h:717
#define switch_assert(expr)
int switch_core_media_crypto_keylen ( switch_rtp_crypto_key_type_t  type)

Definition at line 274 of file switch_core_media.c.

References CRYPTO_INVALID, switch_srtp_crypto_suite_s::keylen, and switch_assert.

275 {
277  return SUITES[type].keylen;
278 }
static switch_srtp_crypto_suite_t SUITES[CRYPTO_INVALID]
#define switch_assert(expr)
switch_rtp_crypto_key_type_t switch_core_media_crypto_str2type ( const char *  str)

Definition at line 253 of file switch_core_media.c.

References CRYPTO_INVALID, and switch_srtp_crypto_suite_s::type.

Referenced by switch_core_media_add_crypto(), and switch_core_session_get_recovery_crypto_key().

254 {
255  int i;
256 
257  for (i = 0; i < CRYPTO_INVALID; i++) {
258  if (!strncasecmp(str, SUITES[i].name, strlen(SUITES[i].name))) {
259  return SUITES[i].type;
260  }
261  }
262 
263  return CRYPTO_INVALID;
264 }
static switch_srtp_crypto_suite_t SUITES[CRYPTO_INVALID]
switch_rtp_crypto_key_type_t type
Definition: switch_rtp.h:67
const char* switch_core_media_crypto_type2str ( switch_rtp_crypto_key_type_t  type)

Definition at line 267 of file switch_core_media.c.

References CRYPTO_INVALID, switch_srtp_crypto_suite_s::name, and switch_assert.

Referenced by switch_core_session_check_incoming_crypto().

268 {
270  return SUITES[type].name;
271 }
static switch_srtp_crypto_suite_t SUITES[CRYPTO_INVALID]
#define switch_assert(expr)
void switch_core_media_deactivate_rtp ( switch_core_session_t session)

Definition at line 6036 of file switch_core_media.c.

References CF_VIDEO_PASSIVE, switch_media_handle_s::engines, switch_rtp_engine_s::local_sdp_port, switch_rtp_engine_s::media_thread, switch_rtp_engine_s::mh, switch_media_handle_s::mparams, switch_core_media_params_s::remote_ip, switch_rtp_engine_s::rtp_session, switch_core_media_params_s::rtpip, switch_assert, switch_channel_clear_flag(), switch_core_media_check_nat(), SWITCH_MEDIA_TYPE_AUDIO, SWITCH_MEDIA_TYPE_VIDEO, switch_nat_del_mapping(), SWITCH_NAT_UDP, switch_rtp_destroy(), switch_rtp_release_port(), switch_thread_join(), media_helper::up, and zstr.

Referenced by switch_media_handle_destroy().

6037 {
6038  switch_rtp_engine_t *a_engine, *v_engine;
6039  switch_media_handle_t *smh;
6040 
6041  switch_assert(session);
6042 
6043  if (!(smh = session->media_handle)) {
6044  return;
6045  }
6046 
6047  a_engine = &smh->engines[SWITCH_MEDIA_TYPE_AUDIO];
6048  v_engine = &smh->engines[SWITCH_MEDIA_TYPE_VIDEO];
6049 
6050  if (v_engine->media_thread) {
6051  switch_status_t st;
6053 
6054  v_engine->mh.up = 0;
6055  switch_thread_join(&st, v_engine->media_thread);
6056  v_engine->media_thread = NULL;
6057  }
6058 
6059  if (v_engine->rtp_session) {
6060  switch_rtp_destroy(&v_engine->rtp_session);
6061  } else if (v_engine->local_sdp_port) {
6063  }
6064 
6065 
6066  if (v_engine->local_sdp_port > 0 && !zstr(smh->mparams->remote_ip) &&
6070  }
6071 
6072 
6073  if (a_engine->rtp_session) {
6074  switch_rtp_destroy(&a_engine->rtp_session);
6075  } else if (a_engine->local_sdp_port) {
6077  }
6078 
6079  if (a_engine->local_sdp_port > 0 && !zstr(smh->mparams->remote_ip) &&
6083  }
6084 
6085 }
int switch_core_media_check_nat(switch_media_handle_t *smh, const char *network_ip)
switch_media_handle_t * media_handle
#define zstr(x)
Definition: switch_utils.h:281
switch_status_t switch_thread_join(switch_status_t *retval, switch_thread_t *thd)
Definition: switch_apr.c:1255
void switch_rtp_destroy(switch_rtp_t **rtp_session)
Destroy an RTP session.
Definition: switch_rtp.c:4491
switch_channel_t * channel
switch_rtp_t * rtp_session
uint16_t switch_port_t
switch_port_t local_sdp_port
switch_status_t switch_nat_del_mapping(switch_port_t port, switch_nat_ip_proto_t proto)
Deletes a NAT mapping.
Definition: switch_nat.c:625
switch_status_t
Common return values.
switch_rtp_engine_t engines[SWITCH_MEDIA_TYPE_TOTAL]
switch_thread_t * media_thread
void switch_rtp_release_port(const char *ip, switch_port_t port)
Definition: switch_rtp.c:2415
void switch_channel_clear_flag(switch_channel_t *channel, switch_channel_flag_t flag)
Clear given flag(s) from a channel.
struct media_helper mh
#define switch_assert(expr)
switch_core_media_params_t * mparams
void switch_core_media_deinit ( void  )

Definition at line 10623 of file switch_core_media.c.

References core_video_globals_s::pool, and switch_core_destroy_memory_pool.

Referenced by switch_core_destroy().

10624 {
10626 }
#define switch_core_destroy_memory_pool(p)
Returns a subpool back to the main pool.
Definition: switch_core.h:640
switch_memory_pool_t * pool
static core_video_globals_t video_globals
void switch_core_media_end_video_function ( switch_core_session_t session)

Definition at line 5575 of file switch_core_media.c.

References switch_media_handle_s::control_mutex, switch_mutex_lock(), switch_mutex_unlock(), switch_yield, and switch_media_handle_s::video_function_running.

Referenced by audio_bridge_thread().

5576 {
5577  switch_media_handle_t *smh;
5578 
5579  if (!(smh = session->media_handle)) {
5580  return;
5581  }
5582 
5584  if (smh->video_function_running > 0) {
5585  smh->video_function_running = -1;
5586  }
5588 
5589  while(smh->video_function_running != 0) {
5590  switch_yield(10000);
5591  }
5592 }
switch_media_handle_t * media_handle
switch_status_t switch_mutex_unlock(switch_mutex_t *lock)
Definition: switch_apr.c:290
#define switch_yield(ms)
Wait a desired number of microseconds and yield the CPU.
Definition: switch_utils.h:908
switch_status_t switch_mutex_lock(switch_mutex_t *lock)
Definition: switch_apr.c:285
switch_mutex_t * control_mutex
switch_status_t switch_core_media_ext_address_lookup ( switch_core_session_t session,
char **  ip,
switch_port_t port,
const char *  sourceip 
)

Definition at line 5811 of file switch_core_media.c.

References switch_media_handle_s::mparams, pool, switch_core_media_params_s::rtpip, STUN_FLAG_SET, switch_core_media_params_s::stun_flags, switch_core_media_params_s::stun_ip, switch_core_media_params_s::stun_port, switch_assert, SWITCH_CHANNEL_LOG, switch_core_session_get_pool(), switch_core_session_strdup, SWITCH_LOG_DEBUG, SWITCH_LOG_ERROR, switch_log_printf(), switch_safe_free, SWITCH_STATUS_FALSE, SWITCH_STATUS_SUCCESS, SWITCH_STUN_DEFAULT_PORT, switch_stun_host_lookup(), switch_stun_lookup(), switch_yield, and zstr.

Referenced by switch_core_media_choose_port().

5813 {
5814  char *error = "";
5816  int x;
5817  switch_port_t myport = *port;
5819  char *stun_ip = NULL;
5820  switch_media_handle_t *smh;
5822 
5823  switch_assert(session);
5824 
5825  if (!(smh = session->media_handle)) {
5826  return SWITCH_STATUS_FALSE;
5827  }
5828 
5829  if (!sourceip) {
5830  return status;
5831  }
5832 
5833  if (!strncasecmp(sourceip, "host:", 5)) {
5834  status = (*ip = switch_stun_host_lookup(sourceip + 5, pool)) ? SWITCH_STATUS_SUCCESS : SWITCH_STATUS_FALSE;
5835  } else if (!strncasecmp(sourceip, "stun:", 5)) {
5836  char *p;
5837 
5838  stun_ip = strdup(sourceip + 5);
5839 
5840  if ((p = strchr(stun_ip, ':'))) {
5841  int iport;
5842  *p++ = '\0';
5843  iport = atoi(p);
5844  if (iport > 0 && iport < 0xFFFF) {
5845  stun_port = (switch_port_t) iport;
5846  }
5847  }
5848 
5849  if (zstr(stun_ip)) {
5850  switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "STUN Failed! NO STUN SERVER\n");
5851  goto out;
5852  }
5853 
5854  for (x = 0; x < 5; x++) {
5855  if ((status = switch_stun_lookup(ip, port, stun_ip, stun_port, &error, pool)) != SWITCH_STATUS_SUCCESS) {
5856  switch_yield(100000);
5857  } else {
5858  break;
5859  }
5860  }
5861  if (status != SWITCH_STATUS_SUCCESS) {
5862  switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "STUN Failed! %s:%d [%s]\n", stun_ip, stun_port, error);
5863  goto out;
5864  }
5865  if (!*ip) {
5866  switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "STUN Failed! No IP returned\n");
5867  goto out;
5868  }
5869  switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "STUN Success [%s]:[%d]\n", *ip, *port);
5870  status = SWITCH_STATUS_SUCCESS;
5871 
5872  if (myport == *port && !strcmp(*ip, smh->mparams->rtpip)) {
5873  switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "STUN Not Required ip and port match. [%s]:[%d]\n", *ip, *port);
5874  } else {
5875  smh->mparams->stun_ip = switch_core_session_strdup(session, stun_ip);
5876  smh->mparams->stun_port = stun_port;
5877  smh->mparams->stun_flags |= STUN_FLAG_SET;
5878  }
5879  } else {
5880  *ip = (char *) sourceip;
5881  status = SWITCH_STATUS_SUCCESS;
5882  }
5883 
5884  out:
5885 
5886  switch_safe_free(stun_ip);
5887 
5888  return status;
5889 }
#define SWITCH_CHANNEL_LOG
switch_memory_pool_t * pool
char * switch_stun_host_lookup(const char *host, switch_memory_pool_t *pool)
Definition: switch_stun.c:688
switch_media_handle_t * media_handle
#define zstr(x)
Definition: switch_utils.h:281
#define SWITCH_STUN_DEFAULT_PORT
Definition: switch_stun.h:41
#define switch_yield(ms)
Wait a desired number of microseconds and yield the CPU.
Definition: switch_utils.h:908
#define switch_safe_free(it)
Free a pointer and set it to NULL unless it already is NULL.
Definition: switch_utils.h:789
uint16_t switch_port_t
switch_status_t
Common return values.
struct apr_pool_t switch_memory_pool_t
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_session_strdup(_session, _todup)
Copy a string using memory allocation from a session's pool.
Definition: switch_core.h:717
#define switch_assert(expr)
switch_status_t switch_stun_lookup(char **ip, switch_port_t *port, char *stunip, switch_port_t stunport, char **err, switch_memory_pool_t *pool)
Perform a stun lookup.
Definition: switch_stun.c:698
switch_core_media_params_t * mparams
switch_memory_pool_t * switch_core_session_get_pool(_In_ switch_core_session_t *session)
Retrieve the memory pool from a session.
switch_t38_options_t* switch_core_media_extract_t38_options ( switch_core_session_t session,
const char *  r_sdp 
)

Definition at line 584 of file switch_core_media.c.

References switch_core_media_process_udptl().

585 {
586  sdp_media_t *m;
587  sdp_parser_t *parser = NULL;
588  sdp_session_t *sdp;
589  switch_t38_options_t *t38_options = NULL;
590 
591  if (!(parser = sdp_parse(NULL, r_sdp, (int) strlen(r_sdp), 0))) {
592  return NULL;
593  }
594 
595  if (!(sdp = sdp_session(parser))) {
596  sdp_parser_free(parser);
597  return NULL;
598  }
599 
600  for (m = sdp->sdp_media; m; m = m->m_next) {
601  if (m->m_proto == sdp_proto_udptl && m->m_type == sdp_media_image && m->m_port) {
602  t38_options = switch_core_media_process_udptl(session, sdp, m);
603  break;
604  }
605  }
606 
607  sdp_parser_free(parser);
608 
609  return t38_options;
610 
611 }
static switch_t38_options_t * switch_core_media_process_udptl(switch_core_session_t *session, sdp_session_t *sdp, sdp_media_t *m)
char* switch_core_media_filter_sdp ( const char *  sdp,
const char *  cmd,
const char *  arg 
)

Definition at line 10688 of file switch_core_media.c.

References end_of_p, find_pt(), payload_number(), skip(), and switch_is_leading_number().

Referenced by switch_core_media_process_sdp_filter().

10689 {
10690  char *new_sdp = NULL;
10691  int pt = -1, te = -1;
10692  switch_size_t len;
10693  const char *i;
10694  char *o;
10695  int in_m = 0, m_tally = 0, slash = 0;
10696  int number = 0, skip = 0;
10697  int remove = !strcasecmp(cmd, "remove");
10698  int only = !strcasecmp(cmd, "only");
10699  char *end = end_of_p((char *)sdp_str);
10700  int tst;
10701  end++;
10702 
10703 
10704  if (remove || only) {
10705  pt = payload_number(arg);
10706 
10707  if (pt < 0) {
10708  pt = find_pt(sdp_str, arg);
10709  }
10710  } else {
10711  return NULL;
10712  }
10713 
10714  if (only) {
10715  te = find_pt(sdp_str, "telephone-event");
10716  }
10717 
10718 
10719  len = strlen(sdp_str) + 2;
10720  new_sdp = malloc(len);
10721  o = new_sdp;
10722  i = sdp_str;
10723 
10724 
10725  while(i && *i && i < end) {
10726 
10727  if (*i == 'm' && *(i+1) == '=') {
10728  in_m = 1;
10729  m_tally++;
10730  }
10731 
10732  if (in_m) {
10733  if (*i == '\r' || *i == '\n') {
10734  in_m = 0;
10735  slash = 0;
10736  } else {
10737  if (*i == '/') {
10738  slash++;
10739  while(*i != ' ' && i < end) {
10740  *o++ = *i++;
10741  }
10742 
10743  *o++ = *i++;
10744  }
10745 
10746  if (slash && switch_is_leading_number(i)) {
10747 
10748 
10749  number = atoi(i);
10750 
10751  while(i < end && ((*i > 47 && *i < 58) || *i == ' ')) {
10752 
10753  if (remove) {
10754  tst = (number != pt);
10755  } else {
10756  tst = (number == pt || number == te);
10757  }
10758 
10759  if (tst) {
10760  *o++ = *i;
10761  }
10762  i++;
10763 
10764  if (*i == ' ') {
10765  break;
10766  }
10767 
10768  }
10769 
10770  if (remove) {
10771  tst = (number == pt);
10772  } else {
10773  tst = (number != pt && number != te);
10774  }
10775 
10776  if (tst) {
10777  skip++;
10778  }
10779  }
10780  }
10781  }
10782 
10783  while (i < end && !strncasecmp(i, "a=rtpmap:", 9)) {
10784  const char *t = i + 9;
10785 
10786  number = atoi(t);
10787 
10788  if (remove) {
10789  tst = (number == pt);
10790  } else {
10791  tst = (number != pt && number != te);
10792  }
10793 
10794  while(i < end && (*i != '\r' && *i != '\n')) {
10795  if (!tst) *o++ = *i;
10796  i++;
10797  }
10798 
10799  while(i < end && (*i == '\r' || *i == '\n')) {
10800  if (!tst) *o++ = *i;
10801  i++;
10802  }
10803  }
10804 
10805  while (i < end && !strncasecmp(i, "a=fmtp:", 7)) {
10806  const char *t = i + 7;
10807 
10808  number = atoi(t);
10809 
10810  if (remove) {
10811  tst = (number == pt);
10812  } else {
10813  tst = (number != pt && number != te);
10814  }
10815 
10816  while(i < end && (*i != '\r' && *i != '\n')) {
10817  if (!tst) *o++ = *i;
10818  i++;
10819  }
10820 
10821  while(i < end && (*i == '\r' || *i == '\n')) {
10822  if (!tst) *o++ = *i;
10823  i++;
10824  }
10825  }
10826 
10827  if (!skip) {
10828  *o++ = *i;
10829  }
10830 
10831  skip = 0;
10832 
10833  i++;
10834  }
10835 
10836  *o = '\0';
10837 
10838  return new_sdp;
10839 }
static int payload_number(const char *name)
switch_bool_t switch_is_leading_number(const char *str)
#define end_of_p(_s)
Definition: switch_utils.h:617
static int find_pt(const char *sdp, const char *name)
uintptr_t switch_size_t
static const char * skip(const char *in)
Definition: switch_json.c:270
void switch_core_media_gen_local_sdp ( switch_core_session_t session,
switch_sdp_type_t  sdp_type,
const char *  ip,
switch_port_t  port,
const char *  sr,
int  force 
)

Definition at line 7523 of file switch_core_media.c.

References add_fb(), payload_map_s::adv_channels, payload_map_s::adv_rm_rate, switch_rtp_engine_s::adv_sdp_ip, switch_rtp_engine_s::adv_sdp_port, payload_map_s::agreed_pt, payload_map_s::allocated, buf, ice_s::cands, CF_3PCC, CF_AVPF, CF_DROP_DTMF, CF_DTLS, CF_DTLS_OK, CF_ICE, CF_LIBERAL_DTMF, CF_NOVIDEO, CF_PROXY_MEDIA, CF_PROXY_MODE, CF_PROXY_OFF, CF_RECOVERING, CF_SECURE, CF_VERBOSE_SDP, CF_VIDEO_POSSIBLE, CF_VIDEO_SDP_RECVD, switch_core_session::channel, switch_media_handle_s::cname, switch_media_handle_s::cng_ianacodes, switch_core_media_params_s::cng_pt, switch_core_media_params_s::cng_rate, switch_rtp_engine_s::codec_negotiated, switch_codec_implementation::codec_type, switch_media_handle_s::codecs, icand_s::con_addr, icand_s::con_port, CRYPTO_INVALID, switch_media_handle_s::crypto_mode, CRYPTO_MODE_FORBIDDEN, CRYPTO_MODE_MANDATORY, switch_media_handle_s::crypto_suite_order, switch_rtp_engine_s::crypto_type, switch_rtp_engine_s::cur_payload_map, dtls_ok(), DTMF_2833, switch_media_handle_s::dtmf_ianacodes, switch_core_media_params_s::dtmf_type, end_of, switch_media_handle_s::engines, switch_rtp_engine_s::fir, switch_codec_implementation::fmtp, payload_map_s::fmtp_out, switch_media_handle_s::fmtps, gen_ice(), generate_local_fingerprint(), generate_m(), get_channels(), get_media_profile_name(), get_setup(), switch_codec_implementation::ianacode, switch_media_handle_s::ianacodes, switch_codec_implementation::iananame, payload_map_s::iananame, switch_rtp_engine_s::ice_out, ice_out(), switch_codec::implementation, secure_settings_s::local_crypto_key, switch_rtp_engine_s::local_dtls_fingerprint, switch_rtp_engine_s::local_sdp_ip, switch_rtp_engine_s::local_sdp_port, memset(), switch_codec_implementation::microseconds_per_packet, switch_codec_implementation::modname, switch_media_handle_s::mparams, switch_media_handle_s::msid, switch_rtp_engine_s::nack, switch_core_media_params_s::ndlb, payload_map_s::negotiated, payload_map_s::next, switch_rtp_engine_s::no_crypto, switch_core_media_params_s::num_codecs, switch_media_handle_s::num_rates, switch_codec_implementation::number_of_channels, switch_media_handle_s::owner_id, switch_media_handle_s::payload_space, switch_rtp_engine_s::pli, switch_rtp_engine_s::proxy_sdp_ip, switch_rtp_engine_s::proxy_sdp_port, payload_map_s::pt, ice_s::pwd, payload_map_s::rate, switch_media_handle_s::rates, switch_rtp_engine_s::read_codec, icand_s::ready, switch_rtp_engine_s::reject_avp, payload_map_s::rm_encoding, payload_map_s::rm_fmtp, payload_map_s::rm_rate, switch_rtp_engine_s::rmode, switch_core_media_params_s::rtcp_audio_interval_msec, switch_rtp_engine_s::rtcp_mux, switch_core_media_params_s::rtcp_video_interval_msec, switch_codec_implementation::samples_per_second, SCMF_LIBERAL_DTMF, SCMF_MULTI_ANSWER_AUDIO, SCMF_MULTI_ANSWER_VIDEO, SCMF_SUPPRESS_CNG, switch_media_handle_s::sdp_mutex, SDP_TYPE_REQUEST, switch_core_media_params_s::sdp_username, SDPBUFLEN, switch_media_handle_s::session, switch_media_handle_s::session_id, SM_NDLB_SENDRECV_IN_SESSION, switch_rtp_engine_s::smode, switch_rtp_engine_s::ssec, switch_rtp_engine_s::ssrc, dtls_fp_s::str, switch_assert, SWITCH_CALL_DIRECTION_INBOUND, SWITCH_CALL_DIRECTION_OUTBOUND, switch_channel_clear_flag(), switch_channel_direction(), switch_channel_get_name(), switch_channel_get_partner_uuid(), switch_channel_get_variable, switch_channel_get_variable_dup(), switch_channel_get_variable_partner(), SWITCH_CHANNEL_LOG, SWITCH_CHANNEL_SESSION_LOG, switch_channel_set_flag, switch_channel_set_variable, switch_channel_test_flag(), SWITCH_CODEC_TYPE_AUDIO, SWITCH_CODEC_TYPE_VIDEO, switch_core_media_add_payload_map(), switch_core_media_check_dtmf_type(), switch_core_media_choose_port(), switch_core_media_get_zrtp_hash(), switch_core_media_set_local_sdp(), switch_core_media_set_video_codec(), switch_core_session_check_outgoing_crypto(), switch_core_session_get_partner, switch_core_session_get_payload_code(), switch_core_session_parse_crypto_prefs(), switch_core_session_rwunlock(), switch_core_session_strdup, switch_epoch_time_now(), switch_event_destroy(), switch_event_get_header, SWITCH_FALSE, switch_false(), SWITCH_LOG_CRIT, SWITCH_LOG_DEBUG, switch_log_printf(), SWITCH_MAX_CODECS, SWITCH_MEDIA_FLOW_DISABLED, SWITCH_MEDIA_FLOW_RECVONLY, SWITCH_MEDIA_FLOW_SENDONLY, switch_media_handle_test_media_flag(), SWITCH_MEDIA_TYPE_AUDIO, SWITCH_MEDIA_TYPE_VIDEO, switch_mutex_lock(), switch_mutex_unlock(), switch_parse_bandwidth_string(), SWITCH_RTCP_AUDIO_INTERVAL_MSEC, SWITCH_RTCP_VIDEO_INTERVAL_MSEC, switch_rtp_has_dtls(), switch_safe_free, switch_snprintf(), SWITCH_STATUS_SUCCESS, switch_stun_random_string(), SWITCH_TRUE, switch_true(), switch_zmalloc, switch_core_media_params_s::te, switch_core_media_params_s::te_rate, switch_rtp_engine_s::tmmbr, icand_s::transport, switch_srtp_crypto_suite_s::type, dtls_fp_s::type, ice_s::ufrag, and zstr.

Referenced by switch_core_media_receive_message(), and switch_core_media_recover_session().

7524 {
7525  char *buf;
7526  int ptime = 0;
7527  uint32_t rate = 0;
7528  uint32_t v_port;
7529  int use_cng = 1;
7530  const char *val;
7531  const char *family;
7532  const char *pass_fmtp = switch_channel_get_variable(session->channel, "rtp_video_fmtp");
7533  const char *ov_fmtp = switch_channel_get_variable(session->channel, "rtp_force_video_fmtp");
7534  const char *append_audio = switch_channel_get_variable(session->channel, "rtp_append_audio_sdp");
7535  const char *append_video = switch_channel_get_variable(session->channel, "rtp_append_video_sdp");
7536  char srbuf[128] = "";
7537  const char *var_val;
7538  const char *username;
7539  const char *fmtp_out;
7540  const char *fmtp_out_var = switch_channel_get_variable(session->channel, "rtp_force_audio_fmtp");
7541  switch_event_t *map = NULL, *ptmap = NULL;
7542  //const char *b_sdp = NULL;
7543  //const char *local_audio_crypto_key = switch_core_session_local_crypto_key(session, SWITCH_MEDIA_TYPE_AUDIO);
7544  const char *local_sdp_audio_zrtp_hash = switch_core_media_get_zrtp_hash(session, SWITCH_MEDIA_TYPE_AUDIO, SWITCH_TRUE);
7545  const char *local_sdp_video_zrtp_hash = switch_core_media_get_zrtp_hash(session, SWITCH_MEDIA_TYPE_VIDEO, SWITCH_TRUE);
7546  const char *tmp;
7547  switch_rtp_engine_t *a_engine, *v_engine;
7548  switch_media_handle_t *smh;
7549  ice_t *ice_out;
7550  //int vp8 = 0;
7551  //int red = 0;
7552  payload_map_t *pmap;
7553  int is_outbound = switch_channel_direction(session->channel) == SWITCH_CALL_DIRECTION_OUTBOUND;
7554  const char *vbw;
7555  int bw = 256;
7556  uint8_t fir = 0, nack = 0, pli = 0, tmmbr = 0;
7557 
7558  switch_assert(session);
7559 
7560  if (!(smh = session->media_handle)) {
7561  return;
7562  }
7563 
7564  a_engine = &smh->engines[SWITCH_MEDIA_TYPE_AUDIO];
7565  v_engine = &smh->engines[SWITCH_MEDIA_TYPE_VIDEO];
7566 
7567  if (switch_true(switch_channel_get_variable(session->channel, "rtcp_mux"))) {
7568  a_engine->rtcp_mux = 1;
7569  v_engine->rtcp_mux = 1;
7570  }
7571 
7572  if (!smh->mparams->rtcp_audio_interval_msec) {
7573  smh->mparams->rtcp_audio_interval_msec = (char *)switch_channel_get_variable(session->channel, "rtcp_audio_interval_msec");
7574  }
7575 
7576  if (!smh->mparams->rtcp_video_interval_msec) {
7577  smh->mparams->rtcp_video_interval_msec = (char *)switch_channel_get_variable(session->channel, "rtcp_video_interval_msec");
7578  }
7579 
7580  if (dtls_ok(session) && (tmp = switch_channel_get_variable(smh->session->channel, "webrtc_enable_dtls")) && switch_false(tmp)) {
7583  }
7584 
7585  if (switch_channel_test_flag(session->channel, CF_PROXY_OFF) && (tmp = switch_channel_get_variable(smh->session->channel, "uuid_media_secure_media"))) {
7586  switch_channel_set_variable(smh->session->channel, "rtp_secure_media", tmp);
7589  }
7590 
7591  if (is_outbound || switch_channel_test_flag(session->channel, CF_RECOVERING) ||
7593  if (!switch_channel_test_flag(session->channel, CF_AVPF) &&
7594  switch_true(switch_channel_get_variable(session->channel, "media_webrtc"))) {
7599  }
7600 
7601  if ( switch_rtp_has_dtls() && dtls_ok(session)) {
7602  if (switch_channel_test_flag(session->channel, CF_AVPF) ||
7603  switch_true(switch_channel_get_variable(smh->session->channel, "rtp_use_dtls"))) {
7607  }
7608  }
7611  }
7612 
7613  fmtp_out = a_engine->cur_payload_map->fmtp_out;
7614  username = smh->mparams->sdp_username;
7615 
7616 
7617  switch_zmalloc(buf, SDPBUFLEN);
7618 
7620 
7622  ((val = switch_channel_get_variable(session->channel, "supress_cng")) && switch_true(val)) ||
7623  ((val = switch_channel_get_variable(session->channel, "suppress_cng")) && switch_true(val))) {
7624  use_cng = 0;
7625  smh->mparams->cng_pt = 0;
7626  }
7627 
7628 
7629 
7630 
7631  if (!smh->payload_space) {
7632  int i;
7633 
7634  /* it could be 98 but chrome reserves 98 and 99 for some internal stuff even though they should not.
7635  Everyone expects dtmf to be at 101 and Its not worth the trouble so we'll start at 102 */
7636  smh->payload_space = 102;
7637  memset(smh->rates, 0, sizeof(smh->rates));
7638  smh->num_rates = 0;
7639 
7640  for (i = 0; i < smh->mparams->num_codecs; i++) {
7641  int j;
7642  smh->ianacodes[i] = smh->codecs[i]->ianacode;
7643 
7644  if (smh->codecs[i]->codec_type != SWITCH_CODEC_TYPE_AUDIO) {
7645  continue;
7646  }
7647 
7648  if (sdp_type == SDP_TYPE_REQUEST) {
7649  for (j = 0; j < SWITCH_MAX_CODECS; j++) {
7650  if (smh->rates[j] == 0) {
7651  break;
7652  }
7653 
7654  if (smh->rates[j] == smh->codecs[i]->samples_per_second) {
7655  goto do_next;
7656  }
7657  }
7658 
7659  smh->rates[smh->num_rates++] = smh->codecs[i]->samples_per_second;
7660  }
7661 
7662  do_next:
7663  continue;
7664  }
7665 
7666  if (sdp_type == SDP_TYPE_REQUEST) {
7667  switch_core_session_t *orig_session = NULL;
7668 
7669  switch_core_session_get_partner(session, &orig_session);
7670 
7671  for (i = 0; i < smh->mparams->num_codecs; i++) {
7672  const switch_codec_implementation_t *imp = smh->codecs[i];
7673  switch_payload_t orig_pt = 0;
7674  char *orig_fmtp = NULL;
7675 
7676  //smh->ianacodes[i] = imp->ianacode;
7677 
7678  if (smh->ianacodes[i] > 64) {
7679  if (smh->mparams->dtmf_type == DTMF_2833 && smh->mparams->te > 95 && smh->mparams->te == smh->payload_space) {
7680  smh->payload_space++;
7681  }
7683  smh->mparams->cng_pt && use_cng && smh->mparams->cng_pt == smh->payload_space) {
7684  smh->payload_space++;
7685  }
7686 
7687  if (orig_session &&
7690  imp->iananame, imp->samples_per_second, &orig_pt, NULL, &orig_fmtp) == SWITCH_STATUS_SUCCESS) {
7691  if (orig_pt == smh->mparams->te) {
7692  smh->mparams->te = (switch_payload_t)smh->payload_space++;
7693  }
7694 
7695  smh->ianacodes[i] = orig_pt;
7696 
7697  if (orig_fmtp) {
7698  smh->fmtps[i] = switch_core_session_strdup(session, orig_fmtp);
7699  }
7700  } else {
7701  smh->ianacodes[i] = (switch_payload_t)smh->payload_space++;
7702  }
7703  }
7704 
7706  imp->codec_type == SWITCH_CODEC_TYPE_AUDIO ? SWITCH_MEDIA_TYPE_AUDIO : SWITCH_MEDIA_TYPE_VIDEO,
7707  imp->iananame,
7708  imp->modname,
7709  NULL,
7710  sdp_type,
7711  smh->ianacodes[i],
7712  imp->samples_per_second,
7713  imp->microseconds_per_packet / 1000,
7714  imp->number_of_channels,
7715  SWITCH_FALSE);
7716  }
7717 
7718  for (i = 0; i < smh->num_rates; i++) {
7719  if (smh->rates[i] == 8000 || smh->num_rates == 1) {
7720  smh->dtmf_ianacodes[i] = smh->mparams->te;
7721  smh->cng_ianacodes[i] = smh->mparams->cng_pt;
7722  } else {
7723  int j = 0;
7724 
7725  for (j = 0; j < smh->mparams->num_codecs; j++) {
7726  if (smh->ianacodes[j] == smh->payload_space) {
7727  smh->payload_space++;
7728  break;
7729  }
7730  }
7731 
7732  smh->dtmf_ianacodes[i] = (switch_payload_t)smh->payload_space++;
7733  smh->cng_ianacodes[i] = (switch_payload_t)smh->payload_space++;
7734  }
7735  }
7736 
7737 
7738  if (orig_session) {
7739  switch_core_session_rwunlock(orig_session);
7740  }
7741  }
7742  }
7743 
7744  if (fmtp_out_var) {
7745  fmtp_out = fmtp_out_var;
7746  }
7747 
7748  val = switch_channel_get_variable(session->channel, "verbose_sdp");
7749 
7750  if (!val || switch_true(val)) {
7752  }
7753 
7754  if (!force && !ip && zstr(sr)
7756  switch_safe_free(buf);
7757  return;
7758  }
7759 
7760  if (!ip) {
7761  if (!(ip = a_engine->adv_sdp_ip)) {
7762  ip = a_engine->proxy_sdp_ip;
7763  }
7764  }
7765 
7766  if (!ip) {
7768  switch_safe_free(buf);
7769  return;
7770  }
7771 
7772  if (!port) {
7773  if (!(port = a_engine->adv_sdp_port)) {
7774  port = a_engine->proxy_sdp_port;
7775  }
7776  }
7777 
7778  if (!port) {
7780  switch_safe_free(buf);
7781  return;
7782  }
7783 
7784  //if (!a_engine->cur_payload_map->rm_encoding && (b_sdp = switch_channel_get_variable(session->channel, SWITCH_B_SDP_VARIABLE))) {
7785  //switch_core_media_sdp_map(b_sdp, &map, &ptmap);
7786  //}
7787 
7788  if (zstr(sr)) {
7789  if (a_engine->smode == SWITCH_MEDIA_FLOW_SENDONLY) {
7790  sr = "sendonly";
7791  } else if (a_engine->smode == SWITCH_MEDIA_FLOW_RECVONLY) {
7792  sr = "recvonly";
7793  } else {
7794  sr = "sendrecv";
7795  }
7796 
7797  if ((var_val = switch_channel_get_variable(session->channel, "origination_audio_mode"))) {
7798  if (!strcasecmp(sr, "sendonly") || !strcasecmp(sr, "recvonly") || !strcasecmp(sr, "sendrecv")) {
7799  sr = var_val;
7800  }
7801  switch_channel_set_variable(session->channel, "origination_audio_mode", NULL);
7802  }
7803 
7804  if (zstr(sr)) {
7805  sr = "sendrecv";
7806  }
7807  }
7808 
7809  if (!smh->owner_id) {
7810  smh->owner_id = (uint32_t) switch_epoch_time_now(NULL) - port;
7811  }
7812 
7813  if (!smh->session_id) {
7814  smh->session_id = smh->owner_id;
7815  }
7816 
7817  if (switch_true(switch_channel_get_variable_dup(session->channel, "drop_dtmf", SWITCH_FALSE, -1))) {
7819  }
7820 
7821  smh->session_id++;
7822 
7823  if ((smh->mparams->ndlb & SM_NDLB_SENDRECV_IN_SESSION) ||
7824  ((var_val = switch_channel_get_variable(session->channel, "ndlb_sendrecv_in_session")) && switch_true(var_val))) {
7825  if (!zstr(sr)) {
7826  switch_snprintf(srbuf, sizeof(srbuf), "a=%s\r\n", sr);
7827  }
7828  sr = NULL;
7829  }
7830 
7831  family = strchr(ip, ':') ? "IP6" : "IP4";
7833  "v=0\r\n"
7834  "o=%s %010u %010u IN %s %s\r\n"
7835  "s=%s\r\n"
7836  "c=IN %s %s\r\n"
7837  "t=0 0\r\n"
7838  "%s",
7839  username, smh->owner_id, smh->session_id, family, ip, username, family, ip, srbuf);
7840 
7841 
7842  if (a_engine->rmode == SWITCH_MEDIA_FLOW_DISABLED) {
7843  goto video;
7844  }
7845 
7847  gen_ice(session, SWITCH_MEDIA_TYPE_AUDIO, ip, port);
7848  switch_snprintf(buf + strlen(buf), SDPBUFLEN - strlen(buf), "a=msid-semantic: WMS %s\r\na=end-of-candidates\r\n", smh->msid);
7849  }
7850 
7851  if (a_engine->codec_negotiated) {
7852  switch_snprintf(buf + strlen(buf), SDPBUFLEN - strlen(buf), "m=audio %d %s", port,
7853  get_media_profile_name(session, !a_engine->no_crypto &&
7854  (switch_channel_test_flag(session->channel, CF_DTLS) || a_engine->crypto_type != CRYPTO_INVALID)));
7855 
7856 
7857  switch_snprintf(buf + strlen(buf), SDPBUFLEN - strlen(buf), " %d", a_engine->cur_payload_map->pt);
7858 
7859 
7862  for (pmap = a_engine->cur_payload_map; pmap && pmap->allocated; pmap = pmap->next) {
7863  if (pmap->pt != a_engine->cur_payload_map->pt) {
7864  switch_snprintf(buf + strlen(buf), SDPBUFLEN - strlen(buf), " %d", pmap->pt);
7865  }
7866  }
7868  }
7869 
7871  switch_channel_test_flag(session->channel, CF_LIBERAL_DTMF)) && smh->mparams->te > 95) {
7872  switch_snprintf(buf + strlen(buf), SDPBUFLEN - strlen(buf), " %d", smh->mparams->te);
7873  }
7874 
7875  if (!switch_media_handle_test_media_flag(smh, SCMF_SUPPRESS_CNG) && smh->mparams->cng_pt && use_cng) {
7876  switch_snprintf(buf + strlen(buf), SDPBUFLEN - strlen(buf), " %d", smh->mparams->cng_pt);
7877  }
7878 
7879  switch_snprintf(buf + strlen(buf), SDPBUFLEN - strlen(buf), "\r\n");
7880 
7881 
7882  rate = a_engine->cur_payload_map->adv_rm_rate;
7883 
7884  if (!a_engine->cur_payload_map->adv_channels) {
7886  }
7887 
7888  if (a_engine->cur_payload_map->adv_channels > 1) {
7889  switch_snprintf(buf + strlen(buf), SDPBUFLEN - strlen(buf), "a=rtpmap:%d %s/%d/%d\r\n",
7890  a_engine->cur_payload_map->agreed_pt, a_engine->cur_payload_map->rm_encoding, rate, a_engine->cur_payload_map->adv_channels);
7891  } else {
7892  switch_snprintf(buf + strlen(buf), SDPBUFLEN - strlen(buf), "a=rtpmap:%d %s/%d\r\n",
7893  a_engine->cur_payload_map->agreed_pt, a_engine->cur_payload_map->rm_encoding, rate);
7894  }
7895 
7896  if (fmtp_out) {
7897  switch_snprintf(buf + strlen(buf), SDPBUFLEN - strlen(buf), "a=fmtp:%d %s\r\n", a_engine->cur_payload_map->agreed_pt, fmtp_out);
7898  }
7899 
7902  for (pmap = a_engine->cur_payload_map; pmap && pmap->allocated; pmap = pmap->next) {
7903  if (pmap->pt != a_engine->cur_payload_map->pt) {
7904  switch_snprintf(buf + strlen(buf), SDPBUFLEN - strlen(buf), "a=rtpmap:%d %s/%ld\r\n",
7905  pmap->pt, pmap->iananame,
7906  pmap->rate);
7907  }
7908  }
7910  }
7911 
7912 
7913  if (a_engine->read_codec.implementation && !ptime) {
7914  ptime = a_engine->read_codec.implementation->microseconds_per_packet / 1000;
7915  }
7916 
7917 
7920  && smh->mparams->te > 95) {
7921 
7922  if (switch_channel_test_flag(session->channel, CF_AVPF)) {
7923  switch_snprintf(buf + strlen(buf), SDPBUFLEN - strlen(buf), "a=rtpmap:%d telephone-event/%d\r\n",
7924  smh->mparams->te, smh->mparams->te_rate);
7925  } else {
7926  switch_snprintf(buf + strlen(buf), SDPBUFLEN - strlen(buf), "a=rtpmap:%d telephone-event/%d\na=fmtp:%d 0-16\r\n",
7927  smh->mparams->te, smh->mparams->te_rate, smh->mparams->te);
7928  }
7929  }
7930 
7932  switch_snprintf(buf + strlen(buf), SDPBUFLEN - strlen(buf), "a=silenceSupp:off - - - -\r\n");
7933  } else if (smh->mparams->cng_pt && use_cng) {
7934  switch_snprintf(buf + strlen(buf), SDPBUFLEN - strlen(buf), "a=rtpmap:%d CN/%lu\r\n", smh->mparams->cng_pt, smh->mparams->cng_rate);
7935 
7936  if (!a_engine->codec_negotiated) {
7937  smh->mparams->cng_pt = 0;
7938  }
7939  }
7940 
7941  if (append_audio) {
7942  switch_snprintf(buf + strlen(buf), SDPBUFLEN - strlen(buf), "%s%s", append_audio, end_of(append_audio) == '\n' ? "" : "\r\n");
7943  }
7944 
7945  if (ptime) {
7946  switch_snprintf(buf + strlen(buf), SDPBUFLEN - strlen(buf), "a=ptime:%d\r\n", ptime);
7947  }
7948 
7949 
7950  if (local_sdp_audio_zrtp_hash) {
7951  switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_DEBUG, "Adding audio a=zrtp-hash:%s\r\n",
7952  local_sdp_audio_zrtp_hash);
7953  switch_snprintf(buf + strlen(buf), SDPBUFLEN - strlen(buf), "a=zrtp-hash:%s\r\n",
7954  local_sdp_audio_zrtp_hash);
7955  }
7956 
7957  if (!zstr(sr)) {
7958  switch_snprintf(buf + strlen(buf), SDPBUFLEN - strlen(buf), "a=%s\r\n", sr);
7959  }
7960 
7961 
7962  if (!zstr(a_engine->local_dtls_fingerprint.type)) {
7963  switch_snprintf(buf + strlen(buf), SDPBUFLEN - strlen(buf), "a=fingerprint:%s %s\na=setup:%s\r\n",
7964  a_engine->local_dtls_fingerprint.type,
7965  a_engine->local_dtls_fingerprint.str, get_setup(a_engine, session, sdp_type));
7966  }
7967 
7968  if (smh->mparams->rtcp_audio_interval_msec) {
7969  if (a_engine->rtcp_mux > 0) {
7970  switch_snprintf(buf + strlen(buf), SDPBUFLEN - strlen(buf), "a=rtcp-mux\r\n");
7971  switch_snprintf(buf + strlen(buf), SDPBUFLEN - strlen(buf), "a=rtcp:%d IN %s %s\r\n", port, family, ip);
7972  } else {
7973  switch_snprintf(buf + strlen(buf), SDPBUFLEN - strlen(buf), "a=rtcp:%d IN %s %s\r\n", port + 1, family, ip);
7974  }
7975  }
7976 
7977  //switch_snprintf(buf + strlen(buf), SDPBUFLEN - strlen(buf), "a=ssrc:%u\r\n", a_engine->ssrc);
7978 
7979  if (a_engine->ice_out.cands[0][0].ready) {
7980  char tmp1[11] = "";
7981  char tmp2[11] = "";
7982  uint32_t c1 = (2^24)*126 + (2^8)*65535 + (2^0)*(256 - 1);
7983  //uint32_t c2 = (2^24)*126 + (2^8)*65535 + (2^0)*(256 - 2);
7984  //uint32_t c3 = (2^24)*126 + (2^8)*65534 + (2^0)*(256 - 1);
7985  //uint32_t c4 = (2^24)*126 + (2^8)*65534 + (2^0)*(256 - 2);
7986 
7987  uint32_t c2 = c1 - 1;
7988  uint32_t c3 = c1 - 2;
7989  uint32_t c4 = c1 - 3;
7990 
7991  tmp1[10] = '\0';
7992  tmp2[10] = '\0';
7993  switch_stun_random_string(tmp1, 10, "0123456789");
7994  switch_stun_random_string(tmp2, 10, "0123456789");
7995 
7996  ice_out = &a_engine->ice_out;
7997 
7998 
7999  switch_snprintf(buf + strlen(buf), SDPBUFLEN - strlen(buf), "a=ice-ufrag:%s\r\n", ice_out->ufrag);
8000  switch_snprintf(buf + strlen(buf), SDPBUFLEN - strlen(buf), "a=ice-pwd:%s\r\n", ice_out->pwd);
8001 
8002 
8003  switch_snprintf(buf + strlen(buf), SDPBUFLEN - strlen(buf), "a=candidate:%s 1 %s %u %s %d typ host generation 0\r\n",
8004  tmp1, ice_out->cands[0][0].transport, c1,
8005  ice_out->cands[0][0].con_addr, ice_out->cands[0][0].con_port
8006  );
8007 
8008  if (!zstr(a_engine->local_sdp_ip) && !zstr(ice_out->cands[0][0].con_addr) &&
8009  strcmp(a_engine->local_sdp_ip, ice_out->cands[0][0].con_addr)
8010  && a_engine->local_sdp_port != ice_out->cands[0][0].con_port) {
8011 
8012  switch_snprintf(buf + strlen(buf), SDPBUFLEN - strlen(buf), "a=candidate:%s 1 %s %u %s %d typ srflx raddr %s rport %d generation 0\r\n",
8013  tmp2, ice_out->cands[0][0].transport, c3,
8014  ice_out->cands[0][0].con_addr, ice_out->cands[0][0].con_port,
8015  a_engine->local_sdp_ip, a_engine->local_sdp_port
8016  );
8017  }
8018 
8019 
8020  if (a_engine->rtcp_mux < 1 || is_outbound || switch_channel_test_flag(session->channel, CF_RECOVERING)) {
8021 
8022  switch_snprintf(buf + strlen(buf), SDPBUFLEN - strlen(buf), "a=candidate:%s 2 %s %u %s %d typ host generation 0\r\n",
8023  tmp1, ice_out->cands[0][0].transport, c2,
8024  ice_out->cands[0][0].con_addr, ice_out->cands[0][0].con_port + (a_engine->rtcp_mux > 0 ? 0 : 1)
8025  );
8026 
8027 
8028 
8029  if (!zstr(a_engine->local_sdp_ip) && !zstr(ice_out->cands[0][0].con_addr) &&
8030  strcmp(a_engine->local_sdp_ip, ice_out->cands[0][0].con_addr)
8031  && a_engine->local_sdp_port != ice_out->cands[0][0].con_port) {
8032 
8033  switch_snprintf(buf + strlen(buf), SDPBUFLEN - strlen(buf), "a=candidate:%s 2 %s %u %s %d typ srflx raddr %s rport %d generation 0\r\n",
8034  tmp2, ice_out->cands[0][0].transport, c4,
8035  ice_out->cands[0][0].con_addr, ice_out->cands[0][0].con_port + (a_engine->rtcp_mux > 0 ? 0 : 1),
8036  a_engine->local_sdp_ip, a_engine->local_sdp_port + (a_engine->rtcp_mux > 0 ? 0 : 1)
8037  );
8038  }
8039  }
8040 
8041 
8042  switch_snprintf(buf + strlen(buf), SDPBUFLEN - strlen(buf), "a=ssrc:%u cname:%s\r\n", a_engine->ssrc, smh->cname);
8043  switch_snprintf(buf + strlen(buf), SDPBUFLEN - strlen(buf), "a=ssrc:%u msid:%s a0\r\n", a_engine->ssrc, smh->msid);
8044  switch_snprintf(buf + strlen(buf), SDPBUFLEN - strlen(buf), "a=ssrc:%u mslabel:%s\r\n", a_engine->ssrc, smh->msid);
8045  switch_snprintf(buf + strlen(buf), SDPBUFLEN - strlen(buf), "a=ssrc:%u label:%sa0\r\n", a_engine->ssrc, smh->msid);
8046 
8047 
8048 #ifdef GOOGLE_ICE
8049  switch_snprintf(buf + strlen(buf), SDPBUFLEN - strlen(buf), "a=ice-options:google-ice\r\n");
8050 #endif
8051  }
8052 
8053  if (a_engine->crypto_type != CRYPTO_INVALID && !switch_channel_test_flag(session->channel, CF_DTLS) &&
8054  !zstr(a_engine->ssec[a_engine->crypto_type].local_crypto_key) && switch_channel_test_flag(session->channel, CF_SECURE)) {
8055 
8056  switch_snprintf(buf + strlen(buf), SDPBUFLEN - strlen(buf), "a=crypto:%s\r\n", a_engine->ssec[a_engine->crypto_type].local_crypto_key);
8057  //switch_snprintf(buf + strlen(buf), SDPBUFLEN - strlen(buf), "a=encryption:optional\r\n");
8058  }
8059 
8060  if (a_engine->reject_avp) {
8061  switch_snprintf(buf + strlen(buf), SDPBUFLEN - strlen(buf), "m=audio 0 RTP/AVP 19\r\n");
8062  }
8063 
8064  } else if (smh->mparams->num_codecs) {
8065  int i;
8066  int cur_ptime = 0, this_ptime = 0, cng_type = 0;
8067  const char *mult;
8068 
8069  if (!switch_media_handle_test_media_flag(smh, SCMF_SUPPRESS_CNG) && smh->mparams->cng_pt && use_cng) {
8070  cng_type = smh->mparams->cng_pt;
8071 
8072  if (!a_engine->codec_negotiated) {
8073  smh->mparams->cng_pt = 0;
8074  }
8075  }
8076 
8077  mult = switch_channel_get_variable(session->channel, "sdp_m_per_ptime");
8078 
8079  if (switch_channel_test_flag(session->channel, CF_AVPF) || (mult && switch_false(mult))) {
8080  char *bp = buf;
8081  int both = (switch_channel_test_flag(session->channel, CF_AVPF) || switch_channel_test_flag(session->channel, CF_DTLS)) ? 0 : 1;
8082 
8083  if ((!a_engine->no_crypto && switch_channel_test_flag(session->channel, CF_SECURE)) ||
8085  generate_m(session, buf, SDPBUFLEN, port, family, ip, 0, append_audio, sr, use_cng, cng_type, map, 1, sdp_type);
8086  bp = (buf + strlen(buf));
8087 
8088  if (smh->crypto_mode == CRYPTO_MODE_MANDATORY) {
8089  both = 0;
8090  }
8091 
8092  }
8093 
8094  if (both) {
8095  generate_m(session, bp, SDPBUFLEN - strlen(buf), port, family, ip, 0, append_audio, sr, use_cng, cng_type, map, 0, sdp_type);
8096  }
8097 
8098  } else {
8099 
8100  for (i = 0; i < smh->mparams->num_codecs; i++) {
8101  const switch_codec_implementation_t *imp = smh->codecs[i];
8102 
8103  if (imp->codec_type != SWITCH_CODEC_TYPE_AUDIO) {
8104  continue;
8105  }
8106 
8107  this_ptime = imp->microseconds_per_packet / 1000;
8108 
8109  if (!strcasecmp(imp->iananame, "ilbc") || !strcasecmp(imp->iananame, "isac")) {
8110  this_ptime = 20;
8111  }
8112 
8113  if (cur_ptime != this_ptime) {
8114  char *bp = buf;
8115  int both = 1;
8116 
8117  cur_ptime = this_ptime;
8118 
8119