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  if ((!a_engine->no_crypto && switch_channel_test_flag(session->channel, CF_SECURE)) ||
8121  generate_m(session, bp, SDPBUFLEN - strlen(buf), port, family, ip, cur_ptime, append_audio, sr, use_cng, cng_type, map, 1, sdp_type);
8122  bp = (buf + strlen(buf));
8123 
8124  if (smh->crypto_mode == CRYPTO_MODE_MANDATORY) {
8125  both = 0;
8126  }
8127  }
8128 
8130  both = 0;
8131  }
8132 
8133  if (both) {
8134  generate_m(session, bp, SDPBUFLEN - strlen(buf), port, family, ip, cur_ptime, append_audio, sr, use_cng, cng_type, map, 0, sdp_type);
8135  }
8136  }
8137 
8138  }
8139  }
8140 
8141  }
8142 
8143  video:
8144 
8148  switch_snprintf(buf + strlen(buf), SDPBUFLEN - strlen(buf), "m=video 0 %s 19\r\n",
8149  get_media_profile_name(session,
8152  a_engine->crypto_type != CRYPTO_INVALID || switch_channel_test_flag(session->channel, CF_DTLS)));
8153  }
8154  } else {
8157  v_engine->no_crypto = 1;
8158  }
8159  }
8160 
8161 
8162  if (!v_engine->local_sdp_port) {
8163  switch_core_media_choose_port(session, SWITCH_MEDIA_TYPE_VIDEO, 0);
8164  }
8165 
8166  //if (switch_channel_test_flag(session->channel, CF_AVPF)) {
8167  // switch_media_handle_set_media_flag(smh, SCMF_MULTI_ANSWER_VIDEO);
8168  //}
8169 
8170  if ((v_port = v_engine->adv_sdp_port)) {
8171  int loops;
8172 
8173  for (loops = 0; loops < 2; loops++) {
8174 
8176  gen_ice(session, SWITCH_MEDIA_TYPE_VIDEO, ip, (switch_port_t)v_port);
8177  }
8178 
8179 
8180  switch_snprintf(buf + strlen(buf), SDPBUFLEN - strlen(buf), "m=video %d %s",
8181  v_port,
8182  get_media_profile_name(session,
8183  (loops == 0 && switch_channel_test_flag(session->channel, CF_SECURE)
8185  a_engine->crypto_type != CRYPTO_INVALID || switch_channel_test_flag(session->channel, CF_DTLS)));
8186 
8187 
8188 
8189 
8190  /*****************************/
8191  if (v_engine->codec_negotiated) {
8192  payload_map_t *pmap;
8194  switch_snprintf(buf + strlen(buf), SDPBUFLEN - strlen(buf), " %d", v_engine->cur_payload_map->agreed_pt);
8195 
8198  for (pmap = v_engine->cur_payload_map; pmap && pmap->allocated; pmap = pmap->next) {
8199  if (pmap->pt != v_engine->cur_payload_map->pt && pmap->negotiated) {
8200  switch_snprintf(buf + strlen(buf), SDPBUFLEN - strlen(buf), " %d", pmap->pt);
8201  }
8202  }
8204  }
8205 
8206  } else if (smh->mparams->num_codecs) {
8207  int i;
8208  int already_did[128] = { 0 };
8209  for (i = 0; i < smh->mparams->num_codecs; i++) {
8210  const switch_codec_implementation_t *imp = smh->codecs[i];
8211 
8212 
8213  if (imp->codec_type != SWITCH_CODEC_TYPE_VIDEO) {
8214  continue;
8215  }
8216 
8219  continue;
8220  }
8221 
8222  if (smh->ianacodes[i] < 128) {
8223  if (already_did[smh->ianacodes[i]]) {
8224  continue;
8225  }
8226  already_did[smh->ianacodes[i]] = 1;
8227  }
8228 
8229  switch_snprintf(buf + strlen(buf), SDPBUFLEN - strlen(buf), " %d", smh->ianacodes[i]);
8230 
8231  if (!ptime) {
8232  ptime = imp->microseconds_per_packet / 1000;
8233  }
8234  }
8235  }
8236 
8237  switch_snprintf(buf + strlen(buf), SDPBUFLEN - strlen(buf), "\r\n");
8238 
8239 
8240  if (v_engine->codec_negotiated) {
8241  const char *of;
8242  payload_map_t *pmap;
8243 
8244  //if (!strcasecmp(v_engine->cur_payload_map->rm_encoding, "VP8")) {
8245  // vp8 = v_engine->cur_payload_map->pt;
8246  //}
8247 
8248  //if (!strcasecmp(v_engine->cur_payload_map->rm_encoding, "red")) {
8249  // red = v_engine->cur_payload_map->pt;
8250  //}
8251 
8252  rate = v_engine->cur_payload_map->rm_rate;
8253  switch_snprintf(buf + strlen(buf), SDPBUFLEN - strlen(buf), "a=rtpmap:%d %s/%ld\r\n",
8254  v_engine->cur_payload_map->pt, v_engine->cur_payload_map->rm_encoding,
8255  v_engine->cur_payload_map->rm_rate);
8256 
8257 
8259  pass_fmtp = v_engine->cur_payload_map->rm_fmtp;
8260  } else {
8261 
8262  pass_fmtp = NULL;
8263 
8264  if (switch_channel_get_partner_uuid(session->channel)) {
8265  if ((of = switch_channel_get_variable_partner(session->channel, "rtp_video_fmtp"))) {
8266  pass_fmtp = of;
8267  }
8268  }
8269 
8270  if (ov_fmtp) {
8271  pass_fmtp = ov_fmtp;
8272  } else if (switch_true(switch_channel_get_variable_dup(session->channel, "rtp_mirror_fmtp", SWITCH_FALSE, -1))) {
8273  pass_fmtp = switch_channel_get_variable(session->channel, "rtp_video_fmtp");
8274  }
8275  }
8276 
8277  if (pass_fmtp) {
8278  switch_snprintf(buf + strlen(buf), SDPBUFLEN - strlen(buf), "a=fmtp:%d %s\r\n", v_engine->cur_payload_map->pt, pass_fmtp);
8279  }
8280 
8281 
8284  for (pmap = v_engine->cur_payload_map; pmap && pmap->allocated; pmap = pmap->next) {
8285  if (pmap->pt != v_engine->cur_payload_map->pt && pmap->negotiated) {
8286  switch_snprintf(buf + strlen(buf), SDPBUFLEN - strlen(buf), "a=rtpmap:%d %s/%ld\r\n",
8287  pmap->pt, pmap->iananame, pmap->rate);
8288 
8289  }
8290  }
8292  }
8293 
8294 
8295  if (append_video) {
8296  switch_snprintf(buf + strlen(buf), SDPBUFLEN - strlen(buf), "%s%s", append_video, end_of(append_video) == '\n' ? "" : "\r\n");
8297  }
8298 
8299  if (v_engine->smode == SWITCH_MEDIA_FLOW_SENDONLY) {
8300  switch_snprintf(buf + strlen(buf), SDPBUFLEN - strlen(buf), "%s", "a=sendonly\r\n");
8301  } else if (v_engine->smode == SWITCH_MEDIA_FLOW_RECVONLY) {
8302  switch_snprintf(buf + strlen(buf), SDPBUFLEN - strlen(buf), "%s", "a=recvonly\r\n");
8303  }
8304 
8305  } else if (smh->mparams->num_codecs) {
8306  int i;
8307  int already_did[128] = { 0 };
8308 
8309  for (i = 0; i < smh->mparams->num_codecs; i++) {
8310  const switch_codec_implementation_t *imp = smh->codecs[i];
8311  char *fmtp = NULL;
8312  uint32_t ianacode = smh->ianacodes[i];
8313  int channels;
8314 
8315  if (imp->codec_type != SWITCH_CODEC_TYPE_VIDEO) {
8316  continue;
8317  }
8318 
8321  continue;
8322  }
8323 
8324  if (ianacode < 128) {
8325  if (already_did[ianacode]) {
8326  continue;
8327  }
8328  already_did[ianacode] = 1;
8329  }
8330 
8331  if (!rate) {
8332  rate = imp->samples_per_second;
8333  }
8334 
8335  channels = get_channels(imp->iananame, imp->number_of_channels);
8336 
8337  //if (!strcasecmp(imp->iananame, "VP8")) {
8338  // vp8 = ianacode;
8339  //}
8340 
8341  //if (!strcasecmp(imp->iananame, "red")) {
8342  // red = ianacode;
8343  //}
8344 
8345  if (channels > 1) {
8346  switch_snprintf(buf + strlen(buf), SDPBUFLEN - strlen(buf), "a=rtpmap:%d %s/%d/%d\r\n", ianacode, imp->iananame,
8347  imp->samples_per_second, channels);
8348  } else {
8349  switch_snprintf(buf + strlen(buf), SDPBUFLEN - strlen(buf), "a=rtpmap:%d %s/%d\r\n", ianacode, imp->iananame,
8350  imp->samples_per_second);
8351  }
8352 
8353  if (!zstr(ov_fmtp)) {
8354  fmtp = (char *) ov_fmtp;
8355  } else {
8356 
8357  if (map) {
8358  fmtp = switch_event_get_header(map, imp->iananame);
8359  }
8360 
8361  if (smh->fmtps[i]) {
8362  fmtp = smh->fmtps[i];
8363  }
8364 
8365  if (zstr(fmtp)) fmtp = imp->fmtp;
8366 
8367  if (zstr(fmtp)) fmtp = (char *) pass_fmtp;
8368  }
8369 
8370  if (!zstr(fmtp) && strcasecmp(fmtp, "_blank_")) {
8371  switch_snprintf(buf + strlen(buf), SDPBUFLEN - strlen(buf), "a=fmtp:%d %s\r\n", ianacode, fmtp);
8372  }
8373  }
8374 
8375  }
8376 
8377  if ((is_outbound || switch_channel_test_flag(session->channel, CF_RECOVERING))
8379  generate_local_fingerprint(smh, SWITCH_MEDIA_TYPE_VIDEO);
8380  }
8381 
8382 
8383  if (!zstr(v_engine->local_dtls_fingerprint.type)) {
8384  switch_snprintf(buf + strlen(buf), SDPBUFLEN - strlen(buf), "a=fingerprint:%s %s\na=setup:%s\r\n", v_engine->local_dtls_fingerprint.type,
8385  v_engine->local_dtls_fingerprint.str, get_setup(v_engine, session, sdp_type));
8386  }
8387 
8388 
8389  if (smh->mparams->rtcp_video_interval_msec) {
8390  if (v_engine->rtcp_mux > 0) {
8391  switch_snprintf(buf + strlen(buf), SDPBUFLEN - strlen(buf), "a=rtcp-mux\r\n");
8392  switch_snprintf(buf + strlen(buf), SDPBUFLEN - strlen(buf), "a=rtcp:%d IN %s %s\r\n", v_port, family, ip);
8393  } else {
8394  switch_snprintf(buf + strlen(buf), SDPBUFLEN - strlen(buf), "a=rtcp:%d IN %s %s\r\n", v_port + 1, family, ip);
8395  }
8396  }
8397 
8398 
8399  if (!(vbw = switch_channel_get_variable(smh->session->channel, "rtp_video_max_bandwidth"))) {
8400  vbw = switch_channel_get_variable(smh->session->channel, "rtp_video_max_bandwidth_in");
8401  }
8402 
8403  if (!vbw) {
8404  vbw = "1mb";
8405  }
8406 
8408 
8409  if (bw > 0) {
8410  switch_snprintf(buf + strlen(buf), SDPBUFLEN - strlen(buf), "b=AS:%d\r\n", bw);
8411  //switch_snprintf(buf + strlen(buf), SDPBUFLEN - strlen(buf), "b=TIAS:%d\r\n", bw);
8412  }
8413 
8414  if (sdp_type == SDP_TYPE_REQUEST) {
8415  fir++;
8416  pli++;
8417  nack++;
8418  tmmbr++;
8419  }
8420 
8421  /* DFF nack pli etc */
8422  //nack = v_engine->nack = 0;
8423  //pli = v_engine->pli = 0;
8424 
8425 
8426  if (v_engine->codec_negotiated) {
8427  add_fb(buf, SDPBUFLEN, v_engine->cur_payload_map->agreed_pt, v_engine->fir || fir,
8428  v_engine->nack || nack, v_engine->pli || pli, v_engine->tmmbr || tmmbr);
8429 
8432  for (pmap = v_engine->cur_payload_map; pmap && pmap->allocated; pmap = pmap->next) {
8433  if (pmap->pt != v_engine->cur_payload_map->pt && pmap->negotiated) {
8434  add_fb(buf, SDPBUFLEN, pmap->pt, v_engine->fir || fir, v_engine->nack || nack, v_engine->pli || pli, v_engine->tmmbr || tmmbr);
8435  }
8436  }
8438  }
8439 
8440  } else if (smh->mparams->num_codecs) {
8441  int i;
8442  int already_did[128] = { 0 };
8443  for (i = 0; i < smh->mparams->num_codecs; i++) {
8444  const switch_codec_implementation_t *imp = smh->codecs[i];
8445 
8446 
8447  if (imp->codec_type != SWITCH_CODEC_TYPE_VIDEO) {
8448  continue;
8449  }
8450 
8453  continue;
8454  }
8455 
8456  if (smh->ianacodes[i] < 128) {
8457  if (already_did[smh->ianacodes[i]]) {
8458  continue;
8459  }
8460  already_did[smh->ianacodes[i]] = 1;
8461  }
8462 
8463  add_fb(buf, SDPBUFLEN, smh->ianacodes[i], v_engine->fir || fir, v_engine->nack || nack, v_engine->pli || pli, v_engine->pli || pli);
8464  }
8465 
8466  }
8467 
8468  //switch_snprintf(buf + strlen(buf), SDPBUFLEN - strlen(buf), "a=ssrc:%u\r\n", v_engine->ssrc);
8469 
8470  if (v_engine->ice_out.cands[0][0].ready) {
8471  char tmp1[11] = "";
8472  char tmp2[11] = "";
8473  uint32_t c1 = (2^24)*126 + (2^8)*65535 + (2^0)*(256 - 1);
8474  //uint32_t c2 = (2^24)*126 + (2^8)*65535 + (2^0)*(256 - 2);
8475  //uint32_t c3 = (2^24)*126 + (2^8)*65534 + (2^0)*(256 - 1);
8476  //uint32_t c4 = (2^24)*126 + (2^8)*65534 + (2^0)*(256 - 2);
8477 
8478  uint32_t c2 = c1 - 1;
8479  uint32_t c3 = c1 - 2;
8480  uint32_t c4 = c1 - 3;
8481 
8482  tmp1[10] = '\0';
8483  tmp2[10] = '\0';
8484  switch_stun_random_string(tmp1, 10, "0123456789");
8485  switch_stun_random_string(tmp2, 10, "0123456789");
8486 
8487  ice_out = &v_engine->ice_out;
8488 
8489 
8490  switch_snprintf(buf + strlen(buf), SDPBUFLEN - strlen(buf), "a=ssrc:%u cname:%s\r\n", v_engine->ssrc, smh->cname);
8491  switch_snprintf(buf + strlen(buf), SDPBUFLEN - strlen(buf), "a=ssrc:%u msid:%s v0\r\n", v_engine->ssrc, smh->msid);
8492  switch_snprintf(buf + strlen(buf), SDPBUFLEN - strlen(buf), "a=ssrc:%u mslabel:%s\r\n", v_engine->ssrc, smh->msid);
8493  switch_snprintf(buf + strlen(buf), SDPBUFLEN - strlen(buf), "a=ssrc:%u label:%sv0\r\n", v_engine->ssrc, smh->msid);
8494 
8495 
8496 
8497  switch_snprintf(buf + strlen(buf), SDPBUFLEN - strlen(buf), "a=ice-ufrag:%s\r\n", ice_out->ufrag);
8498  switch_snprintf(buf + strlen(buf), SDPBUFLEN - strlen(buf), "a=ice-pwd:%s\r\n", ice_out->pwd);
8499 
8500 
8501  switch_snprintf(buf + strlen(buf), SDPBUFLEN - strlen(buf), "a=candidate:%s 1 %s %u %s %d typ host generation 0\r\n",
8502  tmp1, ice_out->cands[0][0].transport, c1,
8503  ice_out->cands[0][0].con_addr, ice_out->cands[0][0].con_port
8504  );
8505 
8506  if (!zstr(v_engine->local_sdp_ip) && !zstr(ice_out->cands[0][0].con_addr) &&
8507  strcmp(v_engine->local_sdp_ip, ice_out->cands[0][0].con_addr)
8508  && v_engine->local_sdp_port != ice_out->cands[0][0].con_port) {
8509 
8510  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",
8511  tmp2, ice_out->cands[0][0].transport, c3,
8512  ice_out->cands[0][0].con_addr, ice_out->cands[0][0].con_port,
8513  v_engine->local_sdp_ip, v_engine->local_sdp_port
8514  );
8515  }
8516 
8517 
8518  if (v_engine->rtcp_mux < 1 || is_outbound || switch_channel_test_flag(session->channel, CF_RECOVERING)) {
8519 
8520  switch_snprintf(buf + strlen(buf), SDPBUFLEN - strlen(buf), "a=candidate:%s 2 %s %u %s %d typ host generation 0\r\n",
8521  tmp1, ice_out->cands[0][0].transport, c2,
8522  ice_out->cands[0][0].con_addr, ice_out->cands[0][0].con_port + (v_engine->rtcp_mux > 0 ? 0 : 1)
8523  );
8524 
8525 
8526  if (!zstr(v_engine->local_sdp_ip) && !zstr(ice_out->cands[0][1].con_addr) &&
8527  strcmp(v_engine->local_sdp_ip, ice_out->cands[0][1].con_addr)
8528  && v_engine->local_sdp_port != ice_out->cands[0][1].con_port) {
8529 
8530  switch_snprintf(buf + strlen(buf), SDPBUFLEN - strlen(buf), "a=candidate:%s 2 %s %u %s %d typ srflx generation 0\r\n",
8531  tmp2, ice_out->cands[0][0].transport, c4,
8532  ice_out->cands[0][0].con_addr, ice_out->cands[0][0].con_port + (v_engine->rtcp_mux > 0 ? 0 : 1),
8533  v_engine->local_sdp_ip, v_engine->local_sdp_port + (v_engine->rtcp_mux > 0 ? 0 : 1)
8534  );
8535  }
8536  }
8537 
8538 
8539 
8540 #ifdef GOOGLE_ICE
8541  switch_snprintf(buf + strlen(buf), SDPBUFLEN - strlen(buf), "a=ice-options:google-ice\r\n");
8542 #endif
8543  }
8544 
8545 
8546 
8547  if (loops == 0 && switch_channel_test_flag(session->channel, CF_SECURE) && !switch_channel_test_flag(session->channel, CF_DTLS)) {
8548  int i;
8549 
8550  for (i = 0; smh->crypto_suite_order[i] != CRYPTO_INVALID; i++) {
8552 
8553  if ((a_engine->crypto_type == j || a_engine->crypto_type == CRYPTO_INVALID) && !zstr(a_engine->ssec[j].local_crypto_key)) {
8554  switch_snprintf(buf + strlen(buf), SDPBUFLEN - strlen(buf), "a=crypto:%s\r\n", v_engine->ssec[j].local_crypto_key);
8555  }
8556  }
8557  //switch_snprintf(buf + strlen(buf), sizeof(buf) - strlen(buf), "a=encryption:optional\r\n");
8558  }
8559 
8560 
8561  if (local_sdp_video_zrtp_hash) {
8562  switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_DEBUG, "Adding video a=zrtp-hash:%s\n", local_sdp_video_zrtp_hash);
8563  switch_snprintf(buf + strlen(buf), SDPBUFLEN - strlen(buf), "a=zrtp-hash:%s\r\n", local_sdp_video_zrtp_hash);
8564  }
8565 
8566 
8567  if (switch_channel_test_flag(session->channel, CF_DTLS) ||
8570  break;
8571  }
8572  }
8573  }
8574 
8575  }
8576 
8577 
8578  if (map) {
8579  switch_event_destroy(&map);
8580  }
8581 
8582  if (ptmap) {
8583  switch_event_destroy(&ptmap);
8584  }
8585 
8587 
8588  switch_safe_free(buf);
8589 }
#define SWITCH_MAX_CODECS
Definition: switch_types.h:558
uint8_t allocated
#define SWITCH_CHANNEL_SESSION_LOG(x)
#define SWITCH_CHANNEL_LOG
switch_rtp_crypto_key_type_t
static char * get_setup(switch_rtp_engine_t *engine, switch_core_session_t *session, switch_sdp_type_t sdp_type)
switch_status_t switch_core_media_set_video_codec(switch_core_session_t *session, int force)
const char * switch_channel_get_partner_uuid(switch_channel_t *channel)
unsigned long rm_rate
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)
unsigned long adv_rm_rate
static int get_channels(const char *name, int dft)
Representation of an event.
Definition: switch_event.h:80
void switch_core_media_check_dtmf_type(switch_core_session_t *session)
static void generate_local_fingerprint(switch_media_handle_t *smh, switch_media_type_t type)
switch_media_flow_t smode
char str[MAX_FPSTRLEN]
Definition: switch_core.h:154
const char * switch_core_media_get_zrtp_hash(switch_core_session_t *session, switch_media_type_t type, switch_bool_t local)
const switch_codec_implementation_t * codecs[SWITCH_MAX_CODECS]
#define SDPBUFLEN
#define end_of(_s)
Definition: switch_utils.h:616
const char * switch_channel_get_variable_dup(switch_channel_t *channel, const char *varname, switch_bool_t dup, int idx)
Retrieve a variable from a given channel.
switch_rtp_crypto_mode_t crypto_mode
static void gen_ice(switch_core_session_t *session, switch_media_type_t type, const char *ip, switch_port_t port)
static switch_srtp_crypto_suite_t SUITES[CRYPTO_INVALID]
switch_payload_t ianacodes[SWITCH_MAX_CODECS]
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.
static int32_t switch_parse_bandwidth_string(const char *bwv)
switch_secure_settings_t ssec[CRYPTO_INVALID+1]
static void switch_core_session_parse_crypto_prefs(switch_core_session_t *session)
char * type
Definition: switch_core.h:153
struct payload_map_s * next
switch_media_handle_t * media_handle
char * fmtps[SWITCH_MAX_CODECS]
#define zstr(x)
Definition: switch_utils.h:281
void switch_core_media_set_local_sdp(switch_core_session_t *session, const char *sdp_str, switch_bool_t dup)
static switch_status_t ice_out(switch_rtp_t *rtp_session, switch_rtp_ice_t *ice)
Definition: switch_rtp.c:771
switch_status_t switch_mutex_unlock(switch_mutex_t *lock)
Definition: switch_apr.c:290
switch_rtp_crypto_key_type_t crypto_suite_order[CRYPTO_INVALID+1]
#define SWITCH_RTCP_AUDIO_INTERVAL_MSEC
Definition: switch_types.h:234
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)
const switch_codec_implementation_t * implementation
switch_byte_t switch_byte_t * buf
switch_channel_t * channel
void switch_stun_random_string(char *buf, uint16_t len, char *set)
Writes random characters into a buffer.
Definition: switch_stun.c:125
int rates[SWITCH_MAX_CODECS]
int switch_rtp_has_dtls(void)
Definition: switch_rtp.c:3207
switch_codec_t read_codec
switch_status_t switch_mutex_lock(switch_mutex_t *lock)
Definition: switch_apr.c:285
switch_media_flow_t rmode
#define switch_channel_get_variable(_c, _v)
switch_core_session_t * session
#define switch_zmalloc(ptr, len)
payload_map_t * cur_payload_map
#define switch_safe_free(it)
Free a pointer and set it to NULL unless it already is NULL.
Definition: switch_utils.h:789
switch_core_media_dtmf_t dtmf_type
char * con_addr
Definition: switch_rtp.h:93
dtls_fingerprint_t local_dtls_fingerprint
switch_payload_t dtmf_ianacodes[SWITCH_MAX_CODECS]
uint8_t ready
Definition: switch_rtp.h:99
uint8_t negotiated
switch_payload_t pt
uint16_t switch_port_t
switch_port_t local_sdp_port
#define switch_core_session_get_partner(_session, _partner)
Definition: switch_core.h:1002
void switch_core_session_rwunlock(_In_ switch_core_session_t *session)
Unlock a read or write lock on as given session.
char * ufrag
Definition: switch_rtp.h:109
#define SWITCH_RTCP_VIDEO_INTERVAL_MSEC
Definition: switch_types.h:235
char * transport
Definition: switch_rtp.h:91
static void add_fb(char *buf, uint32_t buflen, int pt, int fir, int nack, int pli, int tmmbr)
const char * switch_channel_get_variable_partner(switch_channel_t *channel, const char *varname)
switch_rtp_engine_t engines[SWITCH_MEDIA_TYPE_TOTAL]
void switch_core_session_check_outgoing_crypto(switch_core_session_t *session)
static int dtls_ok(switch_core_session_t *session)
char * pwd
Definition: switch_rtp.h:110
switch_port_t adv_sdp_port
#define switch_event_get_header(_e, _h)
Definition: switch_event.h:172
#define switch_channel_set_flag(_c, _f)
switch_call_direction_t switch_channel_direction(switch_channel_t *channel)
switch_status_t switch_core_media_choose_port(switch_core_session_t *session, switch_media_type_t type, int force)
switch_payload_t cng_ianacodes[SWITCH_MAX_CODECS]
switch_payload_t agreed_pt
static void generate_m(switch_core_session_t *session, char *buf, size_t buflen, switch_port_t port, const char *family, const char *ip, int cur_ptime, const char *append_audio, const char *sr, int use_cng, int cng_type, switch_event_t *map, int secure, switch_sdp_type_t sdp_type)
icand_t cands[MAX_CAND][2]
Definition: switch_rtp.h:105
time_t switch_epoch_time_now(time_t *t)
Get the current epoch time.
Definition: switch_time.c:321
switch_core_media_NDLB_t ndlb
static const char * get_media_profile_name(switch_core_session_t *session, int secure)
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.
A table of settings and callbacks that define a paticular implementation of a codec.
static int switch_false(const char *expr)
Evaluate the falsefullness of a string expression.
Definition: switch_utils.h:482
#define switch_core_session_strdup(_session, _todup)
Copy a string using memory allocation from a session's pool.
Definition: switch_core.h:717
void switch_event_destroy(switch_event_t **event)
Destroy an event.
switch_port_t proxy_sdp_port
switch_mutex_t * sdp_mutex
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)
#define switch_channel_set_variable(_channel, _var, _val)
char * switch_channel_get_name(switch_channel_t *channel)
Retrieve the name of a given channel.
memset(buf, 0, buflen)
switch_core_media_params_t * mparams
uint8_t switch_payload_t
switch_port_t con_port
Definition: switch_rtp.h:94
switch_rtp_crypto_key_type_t type
Definition: switch_rtp.h:67
char * rm_encoding
switch_rtp_crypto_key_type_t crypto_type
const char* switch_core_media_get_codec_string ( switch_core_session_t session)

Definition at line 842 of file switch_core_media.c.

References switch_core_media_params_s::inbound_codec_string, switch_media_handle_s::mparams, switch_core_media_params_s::outbound_codec_string, switch_assert, SWITCH_CALL_DIRECTION_OUTBOUND, switch_channel_direction(), switch_channel_get_variable, and zstr.

Referenced by switch_core_media_prepare_codecs(), and switch_core_media_set_sdp_codec_string().

843 {
844  const char *preferred = NULL, *fallback = NULL;
846 
847  switch_assert(session);
848 
849  if (!(smh = session->media_handle)) {
850  preferred = "PCMU";
851  fallback = "PCMU";
852  } else {
853 
854  if (!(preferred = switch_channel_get_variable(session->channel, "absolute_codec_string"))) {
855  preferred = switch_channel_get_variable(session->channel, "codec_string");
856  }
857 
858  if (!preferred) {
860  preferred = smh->mparams->outbound_codec_string;
861  fallback = smh->mparams->inbound_codec_string;
862 
863  } else {
864  preferred = smh->mparams->inbound_codec_string;
865  fallback = smh->mparams->outbound_codec_string;
866  }
867  }
868  }
869 
870  return !zstr(preferred) ? preferred : fallback;
871 }
switch_media_handle_t * media_handle
#define zstr(x)
Definition: switch_utils.h:281
switch_channel_t * channel
#define switch_channel_get_variable(_c, _v)
switch_call_direction_t switch_channel_direction(switch_channel_t *channel)
#define switch_assert(expr)
switch_core_media_params_t * mparams
switch_jb_t* switch_core_media_get_jb ( switch_core_session_t session,
switch_media_type_t  type 
)

Definition at line 9949 of file switch_core_media.c.

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

9950 {
9951  switch_media_handle_t *smh;
9952 
9953  switch_assert(session);
9954 
9955  if (!(smh = session->media_handle)) {
9956  return NULL;
9957  }
9958 
9959  if (switch_rtp_ready(smh->engines[type].rtp_session)) {
9961  }
9962 
9963  return NULL;
9964 }
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_jb_t * switch_rtp_get_jitter_buffer(switch_rtp_t *rtp_session)
Definition: switch_rtp.c:4050
switch_rtp_t * rtp_session
switch_rtp_engine_t engines[SWITCH_MEDIA_TYPE_TOTAL]
#define switch_assert(expr)
switch_core_media_params_t* switch_core_media_get_mparams ( switch_media_handle_t smh)

Definition at line 1793 of file switch_core_media.c.

References switch_assert.

1794 {
1795  switch_assert(smh);
1796  return smh->mparams;
1797 }
#define switch_assert(expr)
switch_core_media_params_t * mparams
switch_rtp_stats_t* switch_core_media_get_stats ( switch_core_session_t session,
switch_media_type_t  type,
switch_memory_pool_t pool 
)

Definition at line 9895 of file switch_core_media.c.

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

Referenced by set_stats(), switch_core_standard_on_hangup(), switch_ivr_set_json_call_stats(), and switch_ivr_set_xml_call_stats().

9896 {
9897  switch_media_handle_t *smh;
9898 
9899  switch_assert(session);
9900 
9901  if (!(smh = session->media_handle)) {
9902  return NULL;
9903  }
9904 
9905  if (smh->engines[type].rtp_session) {
9906  return switch_rtp_get_stats(smh->engines[type].rtp_session, pool);
9907  }
9908 
9909  return NULL;
9910 }
switch_memory_pool_t * pool
switch_media_handle_t * media_handle
switch_rtp_t * rtp_session
switch_rtp_engine_t engines[SWITCH_MEDIA_TYPE_TOTAL]
switch_rtp_stats_t * switch_rtp_get_stats(switch_rtp_t *rtp_session, switch_memory_pool_t *pool)
Definition: switch_rtp.c:7928
#define switch_assert(expr)
switch_timer_t* switch_core_media_get_timer ( switch_core_session_t session,
switch_media_type_t  mtype 
)

Definition at line 10892 of file switch_core_media.c.

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

Referenced by switch_core_session_write_video_frame().

10893 {
10894  switch_rtp_engine_t *engine = NULL;
10895  switch_media_handle_t *smh = NULL;
10896 
10897  switch_assert(session);
10898 
10899  if (!(smh = session->media_handle)) {
10900  return NULL;
10901  }
10902 
10903  if (!(engine = &smh->engines[mtype])) {
10904  return NULL;
10905  }
10906 
10907  return switch_rtp_get_media_timer(engine->rtp_session);
10908 
10909 }
switch_media_handle_t * media_handle
switch_rtp_t * rtp_session
switch_timer_t * switch_rtp_get_media_timer(switch_rtp_t *rtp_session)
Definition: switch_rtp.c:4036
switch_rtp_engine_t engines[SWITCH_MEDIA_TYPE_TOTAL]
#define switch_assert(expr)
switch_status_t switch_core_media_get_vid_params ( switch_core_session_t session,
switch_vid_params_t vid_params 
)

Definition at line 569 of file switch_core_media.c.

References switch_assert, SWITCH_STATUS_FALSE, SWITCH_STATUS_SUCCESS, and switch_media_handle_s::vid_params.

Referenced by switch_ivr_record_file().

570 {
572 
573  switch_assert(session);
574 
575  if (!(smh = session->media_handle)) {
576  return SWITCH_STATUS_FALSE;
577  }
578 
579  *vid_params = smh->vid_params;
580 
581  return SWITCH_STATUS_SUCCESS;
582 }
switch_media_handle_t * media_handle
switch_vid_params_t vid_params
#define switch_assert(expr)
switch_file_handle_t* switch_core_media_get_video_file ( switch_core_session_t session,
switch_rw_t  rw 
)

Definition at line 5039 of file switch_core_media.c.

References CF_VIDEO, switch_media_handle_s::engines, media_helper::file_read_mutex, media_helper::file_write_mutex, switch_rtp_engine_s::mh, switch_assert, switch_channel_test_flag(), SWITCH_MEDIA_TYPE_VIDEO, switch_mutex_lock(), switch_mutex_unlock(), SWITCH_RW_READ, switch_media_handle_s::video_read_fh, and switch_media_handle_s::video_write_fh.

5040 {
5041  switch_media_handle_t *smh;
5042  switch_rtp_engine_t *v_engine;
5044 
5045  switch_assert(session);
5046 
5047  if (!switch_channel_test_flag(session->channel, CF_VIDEO)) {
5048  return NULL;
5049  }
5050 
5051  if (!(smh = session->media_handle)) {
5052  return NULL;
5053  }
5054 
5055  v_engine = &smh->engines[SWITCH_MEDIA_TYPE_VIDEO];
5056 
5057 
5058 
5059  if (rw == SWITCH_RW_READ) {
5061  fh = smh->video_read_fh;
5063  } else {
5065  fh = smh->video_write_fh;
5067  }
5068 
5069 
5070 
5071  return fh;
5072 }
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_status_t switch_mutex_unlock(switch_mutex_t *lock)
Definition: switch_apr.c:290
switch_channel_t * channel
switch_status_t switch_mutex_lock(switch_mutex_t *lock)
Definition: switch_apr.c:285
switch_mutex_t * file_write_mutex
switch_rtp_engine_t engines[SWITCH_MEDIA_TYPE_TOTAL]
switch_mutex_t * file_read_mutex
switch_file_handle_t * video_write_fh
switch_file_handle_t * video_read_fh
struct media_helper mh
#define switch_assert(expr)
uint32_t switch_core_media_get_video_fps ( switch_core_session_t session)

Definition at line 339 of file switch_core_media.c.

References CF_VIDEO, core_video_globals_s::fps, switch_vid_params_s::fps, switch_assert, switch_channel_set_variable_printf(), switch_channel_test_flag(), switch_epoch_time_now(), switch_round_to_step(), SWITCH_STATUS_FALSE, switch_media_handle_s::vid_frames, switch_media_handle_s::vid_params, and switch_media_handle_s::vid_started.

Referenced by check_jb_sync(), and switch_core_media_read_frame().

340 {
342  time_t now;
343  uint32_t fps;
344 
345  switch_assert(session);
346 
347  if (!(smh = session->media_handle)) {
348  return SWITCH_STATUS_FALSE;
349  }
350 
351  if (!switch_channel_test_flag(session->channel, CF_VIDEO)) {
352  return 0;
353  }
354 
355  now = switch_epoch_time_now(NULL);
356 
357  if (!(smh->vid_started && smh->vid_frames && smh->vid_started < now)) {
358  return 0;
359  }
360 
361  fps = switch_round_to_step(smh->vid_frames / (now - smh->vid_started), 5);
362 
363  if (smh->vid_frames > 1000) {
364  smh->vid_started = switch_epoch_time_now(NULL);
365  smh->vid_frames = 1;
366  }
367 
368  if (fps > 0) {
369  video_globals.fps = fps;
370 
371  if (smh->vid_params.fps != fps) {
372  switch_channel_set_variable_printf(session->channel, "video_fps", "%d", fps);
373  smh->vid_params.fps = fps;
374  }
375  }
376 
377  return fps;
378 }
switch_status_t switch_channel_set_variable_printf(switch_channel_t *channel, const char *varname, const char *fmt,...)
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_vid_params_t vid_params
static core_video_globals_t video_globals
time_t switch_epoch_time_now(time_t *t)
Get the current epoch time.
Definition: switch_time.c:321
static uint32_t switch_round_to_step(uint32_t num, uint32_t step)
Definition: switch_utils.h:50
#define switch_assert(expr)
const char* switch_core_media_get_zrtp_hash ( switch_core_session_t session,
switch_media_type_t  type,
switch_bool_t  local 
)

Definition at line 406 of file switch_core_media.c.

References switch_rtp_engine_s::local_sdp_zrtp_hash, and switch_rtp_engine_s::remote_sdp_zrtp_hash.

Referenced by generate_m(), and switch_core_media_gen_local_sdp().

407 {
408  switch_rtp_engine_t *engine;
409  if (!session->media_handle) return NULL;
410 
411  engine = &session->media_handle->engines[type];
412 
413  if (local) {
414  return engine->local_sdp_zrtp_hash;
415  }
416 
417 
418  return engine->remote_sdp_zrtp_hash;
419 
420 }
switch_media_handle_t * media_handle
switch_rtp_engine_t engines[SWITCH_MEDIA_TYPE_TOTAL]
void switch_core_media_hard_mute ( switch_core_session_t session,
switch_bool_t  on 
)

Definition at line 9165 of file switch_core_media.c.

References switch_core_session_message::from, switch_core_session_message::message_id, switch_core_session_message::numeric_arg, switch_core_session_receive_message, and SWITCH_MESSAGE_INDICATE_HARD_MUTE.

Referenced by switch_core_media_bug_add().

9166 {
9167  switch_core_session_message_t msg = { 0 };
9168 
9169  msg.from = __FILE__;
9170 
9172  msg.numeric_arg = on;
9173  switch_core_session_receive_message(session, &msg);
9174 }
switch_core_session_message_types_t message_id
Definition: switch_core.h:181
A message object designed to allow unlike technologies to exchange data.
Definition: switch_core.h:177
#define switch_core_session_receive_message(_session, _message)
Definition: switch_core.h:1217
void switch_core_media_init ( void  )

Definition at line 10611 of file switch_core_media.c.

References core_video_globals_s::cpu_count, core_video_globals_s::cur_cpu, DTLS_SRTP_FNAME, core_video_globals_s::mutex, core_video_globals_s::pool, switch_core_cpu_count(), switch_core_gen_certs(), switch_core_new_memory_pool, switch_mutex_init(), and SWITCH_MUTEX_NESTED.

Referenced by switch_core_init().

10612 {
10614 
10616  video_globals.cur_cpu = 0;
10617 
10620 
10621 }
#define switch_core_new_memory_pool(p)
Create a new sub memory pool from the core's master pool.
Definition: switch_core.h:631
uint32_t switch_core_cpu_count(void)
Definition: switch_core.c:1042
#define SWITCH_MUTEX_NESTED
Definition: switch_apr.h:318
switch_memory_pool_t * pool
switch_mutex_t * mutex
switch_status_t switch_mutex_init(switch_mutex_t **lock, unsigned int flags, switch_memory_pool_t *pool)
Definition: switch_apr.c:270
static core_video_globals_t video_globals
#define DTLS_SRTP_FNAME
Definition: switch_core.h:146
int switch_core_gen_certs(const char *prefix)
void switch_core_media_kill_socket ( switch_core_session_t session,
switch_media_type_t  type 
)

Definition at line 9765 of file switch_core_media.c.

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

9766 {
9767  switch_media_handle_t *smh;
9768 
9769  switch_assert(session);
9770 
9771  if (!(smh = session->media_handle)) {
9772  return;
9773  }
9774 
9775  if (switch_rtp_ready(smh->engines[type].rtp_session)) {
9777  }
9778 }
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_kill_socket(switch_rtp_t *rtp_session)
Kill the socket on an existing RTP session.
Definition: switch_rtp.c:4425
#define switch_assert(expr)
switch_status_t switch_core_media_lock_video_file ( switch_core_session_t session,
switch_rw_t  rw 
)

Definition at line 5156 of file switch_core_media.c.

References CF_VIDEO, switch_media_handle_s::engines, media_helper::file_read_mutex, media_helper::file_write_mutex, switch_rtp_engine_s::mh, switch_assert, switch_channel_test_flag(), SWITCH_MEDIA_TYPE_VIDEO, switch_mutex_lock(), SWITCH_RW_READ, SWITCH_STATUS_FALSE, and SWITCH_STATUS_SUCCESS.

Referenced by switch_ivr_record_file().

5157 {
5158  switch_media_handle_t *smh;
5159  switch_rtp_engine_t *v_engine;
5160 
5161  switch_assert(session);
5162 
5163  if (!switch_channel_test_flag(session->channel, CF_VIDEO)) {
5164  return SWITCH_STATUS_FALSE;
5165  }
5166 
5167  if (!(smh = session->media_handle)) {
5168  return SWITCH_STATUS_FALSE;
5169  }
5170 
5171  v_engine = &smh->engines[SWITCH_MEDIA_TYPE_VIDEO];
5172 
5173  if (rw == SWITCH_RW_READ) {
5175  } else {
5177  }
5178 
5179  return SWITCH_STATUS_SUCCESS;
5180 
5181 }
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_status_t switch_mutex_lock(switch_mutex_t *lock)
Definition: switch_apr.c:285
switch_mutex_t * file_write_mutex
switch_rtp_engine_t engines[SWITCH_MEDIA_TYPE_TOTAL]
switch_mutex_t * file_read_mutex
struct media_helper mh
#define switch_assert(expr)
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 
)

Definition at line 3647 of file switch_core_media.c.

References switch_codec_fmtp::actual_samples_per_second, switch_codec_implementation::actual_samples_per_second, payload_map_s::adv_channels, payload_map_s::adv_rm_rate, payload_map_s::agreed_pt, payload_map_s::allocated, switch_core_media_params_s::auto_rtp_bugs, payload_map_s::bitrate, switch_codec_fmtp::bits_per_second, switch_codec_implementation::bits_per_second, CF_ANSWERED, CF_APP_T38, CF_APP_T38_NEGOTIATED, CF_AUDIO_PAUSE, CF_AVPF_MOZ, CF_DTLS, CF_DTLS_OK, CF_LIBERAL_DTMF, CF_NOVIDEO, CF_PROXY_MEDIA, CF_PROXY_MODE, CF_RECOVERING, CF_REINVITE, CF_T38_PASSTHRU, CF_VIDEO_READY, CF_VIDEO_SDP_RECVD, switch_core_session::channel, payload_map_s::channels, check_ice(), clear_pmaps(), switch_core_media_params_s::cng_pt, switch_core_media_params_s::cng_rate, switch_core_media_params_s::codec_flags, matches::codec_idx, payload_map_s::codec_ms, switch_rtp_engine_s::codec_negotiated, switch_codec_implementation::codec_type, switch_media_handle_s::codecs, switch_media_handle_s::crypto_mode, CRYPTO_MODE_MANDATORY, switch_rtp_engine_s::cur_payload_map, payload_map_s::current, dtls_ok(), DTMF_2833, DTMF_AUTO, DTMF_INFO, DTMF_NONE, switch_core_media_params_s::dtmf_type, switch_media_handle_s::engines, switch_rtp_engine_s::fir, switch_core_session_message::from, greedy_sort(), switch_core_media_params_s::hold_laps, switch_codec_implementation::ianacode, switch_codec_implementation::iananame, payload_map_s::iananame, if(), matches::imp, switch_codec::implementation, matches::map, switch_rtp_engine_s::max_missed_hold_packets, switch_rtp_engine_s::max_missed_packets, memset(), switch_core_session_message::message_id, switch_codec_fmtp::microseconds_per_packet, switch_codec_implementation::microseconds_per_packet, switch_codec_implementation::modname, switch_media_handle_s::mparams, switch_rtp_engine_s::nack, switch_core_media_params_s::ndlb, switch_media_handle_s::negotiated_codecs, switch_rtp_engine_s::new_dtls, switch_rtp_engine_s::new_ice, payload_map_s::next, switch_core_media_params_s::num_codecs, switch_media_handle_s::num_negotiated_codecs, switch_codec_implementation::number_of_channels, switch_media_handle_s::origin, switch_rtp_engine_s::pli, payload_map_s::pt, matches::rate, switch_rtp_engine_s::read_codec, switch_rtp_engine_s::read_impl, payload_map_s::recv_pt, switch_core_media_params_s::recv_te, switch_rtp_engine_s::reject_avp, switch_t38_options_t::remote_ip, switch_t38_options_t::remote_port, switch_rtp_engine_s::remote_rtcp_port, payload_map_s::remote_sdp_ip, payload_map_s::remote_sdp_port, switch_rtp_engine_s::reset_codec, 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_core_media_params_s::rtcp_video_interval_msec, RTP_BUG_CISCO_SKIP_MARK_BIT_2833, RTP_BUG_SONUS_SEND_INVALID_TIMESTAMP_2833, switch_rtp_engine_s::rtp_bugs, switch_rtp_engine_s::rtp_session, switch_codec_implementation::samples_per_second, SCMF_CODEC_GREEDY, SCMF_CODEC_SCROOGE, SCMF_DISABLE_HOLD, SCMF_LIBERAL_DTMF, SCMF_RENEG_ON_HOLD, SCMF_RENEG_ON_REINVITE, SCMF_SUPPRESS_CNG, switch_rtp_engine_s::sdp_bw, sdp_media_flow(), switch_media_handle_s::sdp_mutex, SDP_TYPE_REQUEST, SDP_TYPE_RESPONSE, switch_media_handle_s::session, skip(), SM_NDLB_ALLOW_BAD_IANANAME, SM_NDLB_ALLOW_CRYPTO_IN_AVP, switch_rtp_engine_s::smode, switch_codec_fmtp::stereo, switch_core_session_message::string_arg, switch_assert, SWITCH_CALL_DIRECTION_INBOUND, SWITCH_CALL_DIRECTION_OUTBOUND, SWITCH_CAUSE_INCOMPATIBLE_DESTINATION, switch_channel_clear_app_flag_key(), switch_channel_clear_flag(), switch_channel_direction(), 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_app_flag_key(), switch_channel_test_flag(), SWITCH_CODEC_TYPE_AUDIO, SWITCH_CODEC_TYPE_VIDEO, switch_core_codec_parse_fmtp(), switch_core_codec_ready(), switch_core_media_add_payload_map(), switch_core_media_check_autoadj(), switch_core_media_check_video_codecs(), switch_core_media_copy_t38_options(), switch_core_media_find_zrtp_hash(), switch_core_media_get_offered_pt(), switch_core_media_pass_zrtp_hash(), switch_core_media_prepare_codecs(), switch_core_media_process_udptl(), switch_core_media_set_codec(), switch_core_media_set_video_codec(), switch_core_media_toggle_hold(), switch_core_session_alloc, switch_core_session_check_incoming_crypto(), switch_core_session_get_channel(), switch_core_session_get_partner, switch_core_session_parse_crypto_prefs(), switch_core_session_queue_message(), switch_core_session_rwunlock(), switch_core_session_set_ice(), switch_core_session_strdup, switch_default_ptime(), SWITCH_FALSE, switch_false(), switch_known_bitrate(), switch_loadable_module_get_codecs_sorted(), SWITCH_LOG_DEBUG, SWITCH_LOG_ERROR, switch_log_printf(), SWITCH_LOG_WARNING, SWITCH_MEDIA_FLOW_DISABLED, SWITCH_MEDIA_FLOW_RECVONLY, SWITCH_MEDIA_FLOW_SENDONLY, SWITCH_MEDIA_FLOW_SENDRECV, switch_media_handle_test_media_flag(), SWITCH_MEDIA_TYPE_AUDIO, SWITCH_MEDIA_TYPE_VIDEO, SWITCH_MESSAGE_INDICATE_REQUEST_IMAGE_MEDIA, switch_mutex_lock(), switch_mutex_unlock(), SWITCH_REMOTE_MEDIA_IP_VARIABLE, SWITCH_REMOTE_MEDIA_PORT_VARIABLE, SWITCH_REMOTE_VIDEO_IP_VARIABLE, SWITCH_REMOTE_VIDEO_PORT_VARIABLE, SWITCH_RTCP_AUDIO_INTERVAL_MSEC, SWITCH_RTCP_VIDEO_INTERVAL_MSEC, switch_rtp_get_remote_host(), switch_rtp_get_remote_port(), switch_rtp_has_dtls(), switch_rtp_ready(), switch_rtp_set_cng_pt(), switch_rtp_set_default_payload(), switch_rtp_set_max_missed_packets(), switch_rtp_set_remote_address(), switch_rtp_set_telephony_event(), switch_rtp_set_telephony_recv_event(), switch_snprintf(), SWITCH_STATUS_FALSE, SWITCH_STATUS_SUCCESS, switch_stristr(), SWITCH_TRUE, switch_true(), switch_core_media_params_s::te, switch_core_media_params_s::te_rate, switch_rtp_engine_s::tmmbr, and zstr.

3648 {
3649  uint8_t match = 0;
3650  uint8_t vmatch = 0;
3651  switch_payload_t best_te = 0, cng_pt = 0;
3652  unsigned long best_te_rate = 8000, cng_rate = 8000;
3653  sdp_media_t *m;
3654  sdp_attribute_t *attr;
3655  int ptime = 0, dptime = 0, maxptime = 0, dmaxptime = 0;
3656  int sendonly = 0, recvonly = 0;
3657  int greedy = 0, x = 0, skip = 0;
3659  const char *val;
3660  const char *crypto = NULL;
3661  int got_crypto = 0, got_video_crypto = 0, got_audio = 0, saw_audio = 0, got_avp = 0, got_video_avp = 0, got_video_savp = 0, got_savp = 0, got_udptl = 0, got_webrtc = 0;
3662  int scrooge = 0;
3663  sdp_parser_t *parser = NULL;
3664  sdp_session_t *sdp;
3665  int reneg = 1;
3666  const switch_codec_implementation_t **codec_array;
3667  int total_codecs;
3668  switch_rtp_engine_t *a_engine, *v_engine;
3669  switch_media_handle_t *smh;
3670  uint32_t near_rate = 0;
3671  const switch_codec_implementation_t *mimp = NULL, *near_match = NULL;
3672  sdp_rtpmap_t *mmap = NULL, *near_map = NULL;
3673  struct matches matches[MAX_MATCHES] = { { 0 } };
3674  struct matches near_matches[MAX_MATCHES] = { { 0 } };
3675  int codec_ms = 0;
3676  uint32_t remote_codec_rate = 0, fmtp_remote_codec_rate = 0;
3677  const char *tmp;
3678  int m_idx = 0;
3679  int nm_idx = 0;
3680 
3681  switch_assert(session);
3682 
3683  if (!(smh = session->media_handle)) {
3684  return 0;
3685  }
3686 
3687  a_engine = &smh->engines[SWITCH_MEDIA_TYPE_AUDIO];
3688  v_engine = &smh->engines[SWITCH_MEDIA_TYPE_VIDEO];
3689 
3690  codec_array = smh->codecs;
3691  total_codecs = smh->mparams->num_codecs;
3692 
3693  if (!(parser = sdp_parse(NULL, r_sdp, (int) strlen(r_sdp), 0))) {
3694  return 0;
3695  }
3696 
3697  if (!(sdp = sdp_session(parser))) {
3698  sdp_parser_free(parser);
3699  return 0;
3700  }
3701 
3703 
3704  if (dtls_ok(session) && (tmp = switch_channel_get_variable(smh->session->channel, "webrtc_enable_dtls")) && switch_false(tmp)) {
3707  }
3708 
3709  v_engine->new_dtls = 1;
3710  v_engine->new_ice = 1;
3711  a_engine->new_dtls = 1;
3712  a_engine->new_ice = 1;
3713  a_engine->reject_avp = 0;
3714 
3716 
3717  clear_pmaps(a_engine);
3718  clear_pmaps(v_engine);
3719 
3720  if (proceed) *proceed = 1;
3721 
3724 
3725  if ((val = switch_channel_get_variable(channel, "rtp_codec_negotiation"))) {
3726  if (!strcasecmp(val, "generous")) {
3727  greedy = 0;
3728  scrooge = 0;
3729  } else if (!strcasecmp(val, "greedy")) {
3730  greedy = 1;
3731  scrooge = 0;
3732  } else if (!strcasecmp(val, "scrooge")) {
3733  scrooge = 1;
3734  greedy = 1;
3735  } else {
3736  switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_DEBUG, "rtp_codec_negotiation ignored invalid value : '%s' \n", val );
3737  }
3738  }
3739 
3740  if ((smh->origin = switch_core_session_strdup(session, (char *) sdp->sdp_origin->o_username))) {
3741 
3743 
3744  if (strstr(smh->origin, "CiscoSystemsSIP-GW-UserAgent")) {
3746  switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_DEBUG, "Activate Buggy RFC2833 Mode!\n");
3747  }
3748  }
3749 
3751  if (strstr(smh->origin, "Sonus_UAC")) {
3754  "Hello,\nI see you have a Sonus!\n"
3755  "FYI, Sonus cannot follow the RFC on the proper way to send DTMF.\n"
3756  "Sadly, my creator had to spend several hours figuring this out so I thought you'd like to know that!\n"
3757  "Don't worry, DTMF will work but you may want to ask them to fix it......\n");
3758  }
3759  }
3760  }
3761 
3762  if ((val = switch_channel_get_variable(session->channel, "rtp_liberal_dtmf")) && switch_true(val)) {
3764  }
3765 
3766  if (switch_stristr("T38FaxFillBitRemoval:", r_sdp) || switch_stristr("T38FaxTranscodingMMR:", r_sdp) ||
3767  switch_stristr("T38FaxTranscodingJBIG:", r_sdp)) {
3768  switch_channel_set_variable(session->channel, "t38_broken_boolean", "true");
3769  }
3770 
3771  switch_core_media_find_zrtp_hash(session, sdp);
3773 
3774  check_ice(smh, SWITCH_MEDIA_TYPE_AUDIO, sdp, NULL);
3775  check_ice(smh, SWITCH_MEDIA_TYPE_VIDEO, sdp, NULL);
3776 
3777  if ((sdp->sdp_connection && sdp->sdp_connection->c_address && !strcmp(sdp->sdp_connection->c_address, "0.0.0.0"))) {
3778  switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_WARNING, "RFC2543 from March 1999 called; They want their 0.0.0.0 hold method back.....\n");
3779  sendonly = 2; /* global sendonly always wins */
3780  }
3781 
3782  for (m = sdp->sdp_media; m; m = m->m_next) {
3783  sdp_connection_t *connection;
3784  switch_core_session_t *other_session;
3785 
3786  if (!m->m_port) {
3787  continue;
3788  }
3789 
3790  if (m->m_type == sdp_media_audio) {
3791  saw_audio = 1;
3792  }
3793 
3794  ptime = dptime;
3795  maxptime = dmaxptime;
3796 
3797  if (m->m_proto == sdp_proto_extended_srtp || m->m_proto == sdp_proto_extended_rtp) {
3798  got_webrtc++;
3799  switch_core_session_set_ice(session);
3800  }
3801 
3802  if (m->m_proto_name && !strcasecmp(m->m_proto_name, "UDP/TLS/RTP/SAVPF")) {
3804  }
3805 
3806  if (m->m_proto_name && !strcasecmp(m->m_proto_name, "UDP/RTP/AVPF")) {
3808  }
3809 
3810  if (m->m_proto == sdp_proto_srtp || m->m_proto == sdp_proto_extended_srtp) {
3811  if (m->m_type == sdp_media_audio) {
3812  got_savp++;
3813  } else {
3814  got_video_savp++;
3815  }
3816  } else if (m->m_proto == sdp_proto_rtp) {
3817  if (m->m_type == sdp_media_audio) {
3818  got_avp++;
3819  } else {
3820  got_video_avp++;
3821  }
3822  } else if (m->m_proto == sdp_proto_udptl) {
3823  got_udptl++;
3824  }
3825 
3826  if (got_udptl && m->m_type == sdp_media_image && m->m_port) {
3827  switch_t38_options_t *t38_options = switch_core_media_process_udptl(session, sdp, m);
3828 
3830  match = 1;
3831  goto done;
3832  }
3833 
3834  if (switch_true(switch_channel_get_variable(channel, "refuse_t38"))) {
3836  match = 0;
3837  goto done;
3838  } else {
3839  const char *var = switch_channel_get_variable(channel, "t38_passthru");
3841 
3842 
3843  if (switch_channel_test_app_flag_key("T38", session->channel, CF_APP_T38)) {
3844  if (proceed) *proceed = 0;
3845  }
3846 
3847  if (var) {
3848  if (!(pass = switch_true(var))) {
3849  if (!strcasecmp(var, "once")) {
3850  pass = 2;
3851  }
3852  }
3853  }
3854 
3855  if ((pass == 2 && switch_channel_test_flag(smh->session->channel, CF_T38_PASSTHRU))
3856  || !switch_channel_test_flag(session->channel, CF_REINVITE) ||
3857 
3860  !switch_rtp_ready(a_engine->rtp_session)) {
3861  pass = 0;
3862  }
3863 
3864  if (pass && switch_core_session_get_partner(session, &other_session) == SWITCH_STATUS_SUCCESS) {
3865  switch_channel_t *other_channel = switch_core_session_get_channel(other_session);
3867  char *remote_host = switch_rtp_get_remote_host(a_engine->rtp_session);
3868  switch_port_t remote_port = switch_rtp_get_remote_port(a_engine->rtp_session);
3869  char tmp[32] = "";
3870 
3871 
3872  if (!switch_channel_test_flag(other_channel, CF_ANSWERED)) {
3874  SWITCH_LOG_WARNING, "%s Error Passing T.38 to unanswered channel %s\n",
3875  switch_channel_get_name(session->channel), switch_channel_get_name(other_channel));
3876  switch_core_session_rwunlock(other_session);
3877 
3878  pass = 0;
3879  match = 0;
3880  goto done;
3881  }
3882 
3883 
3884  if (switch_true(switch_channel_get_variable(session->channel, "t38_broken_boolean")) &&
3885  switch_true(switch_channel_get_variable(session->channel, "t38_pass_broken_boolean"))) {
3886  switch_channel_set_variable(other_channel, "t38_broken_boolean", "true");
3887  }
3888 
3889  a_engine->cur_payload_map->remote_sdp_ip = switch_core_session_strdup(session, t38_options->remote_ip);
3890  a_engine->cur_payload_map->remote_sdp_port = t38_options->remote_port;
3891 
3892  if (remote_host && remote_port && !strcmp(remote_host, a_engine->cur_payload_map->remote_sdp_ip) && remote_port == a_engine->cur_payload_map->remote_sdp_port) {
3893  switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_DEBUG, "Audio params are unchanged for %s.\n",
3894  switch_channel_get_name(session->channel));
3895  } else {
3896  const char *err = NULL;
3897 
3898  switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_DEBUG, "Audio params changed for %s from %s:%d to %s:%d\n",
3899  switch_channel_get_name(session->channel),
3900  remote_host, remote_port, a_engine->cur_payload_map->remote_sdp_ip, a_engine->cur_payload_map->remote_sdp_port);
3901 
3902  switch_snprintf(tmp, sizeof(tmp), "%d", a_engine->cur_payload_map->remote_sdp_port);
3905 
3908  switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_ERROR, "AUDIO RTP REPORTS ERROR: [%s]\n", err);
3910  }
3911 
3913  }
3914 
3915 
3916 
3917  switch_core_media_copy_t38_options(t38_options, other_session);
3918 
3921 
3922  msg = switch_core_session_alloc(other_session, sizeof(*msg));
3924  msg->from = __FILE__;
3925  msg->string_arg = switch_core_session_strdup(other_session, r_sdp);
3926  switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_DEBUG, "Passing T38 req to other leg.\n%s\n", r_sdp);
3927  switch_core_session_queue_message(other_session, msg);
3928  switch_core_session_rwunlock(other_session);
3929  }
3930  }
3931 
3932 
3933  /* do nothing here, mod_fax will trigger a response (if it's listening =/) */
3934  match = 1;
3935  goto done;
3936  } else if (m->m_type == sdp_media_audio && m->m_port && got_audio && got_savp) {
3937  a_engine->reject_avp = 1;
3938  } else if (m->m_type == sdp_media_audio && m->m_port && !got_audio) {
3939  sdp_rtpmap_t *map;
3940  int ice = 0;
3941 
3942  nm_idx = 0;
3943  m_idx = 0;
3944  memset(matches, 0, sizeof(matches[0]) * MAX_MATCHES);
3945  memset(near_matches, 0, sizeof(near_matches[0]) * MAX_MATCHES);
3946 
3947  if (!sendonly && (m->m_mode == sdp_sendonly || m->m_mode == sdp_inactive)) {
3948  sendonly = 1;
3949  }
3950 
3951  if (!sendonly && m->m_connections && m->m_connections->c_address && !strcmp(m->m_connections->c_address, "0.0.0.0")) {
3952  sendonly = 1;
3953  }
3954 
3955 
3956  a_engine->rmode = sdp_media_flow(m->m_mode);
3957 
3958  if (sdp_type == SDP_TYPE_REQUEST) {
3959  switch(a_engine->rmode) {
3961  switch_channel_set_variable(smh->session->channel, "audio_media_flow", "sendonly");
3962  a_engine->smode = SWITCH_MEDIA_FLOW_SENDONLY;
3963  break;
3965  switch_channel_set_variable(smh->session->channel, "audio_media_flow", "recvonly");
3966  a_engine->smode = SWITCH_MEDIA_FLOW_RECVONLY;
3967  break;
3968  default:
3969  switch_channel_set_variable(smh->session->channel, "audio_media_flow", "sendrecv");
3970  a_engine->smode = SWITCH_MEDIA_FLOW_SENDRECV;
3971  break;
3972  }
3973  }
3974 
3975  for (attr = sdp->sdp_attributes; attr; attr = attr->a_next) {
3976  if (zstr(attr->a_name)) {
3977  continue;
3978  }
3979 
3980 
3981  if (!strncasecmp(attr->a_name, "ice", 3)) {
3982  ice++;
3983  } else if (sendonly < 2 && !strcasecmp(attr->a_name, "sendonly")) {
3984  sendonly = 1;
3985  switch_channel_set_variable(session->channel, "media_audio_mode", "recvonly");
3986  } else if (sendonly < 2 && !strcasecmp(attr->a_name, "inactive")) {
3987  sendonly = 1;
3988  switch_channel_set_variable(session->channel, "media_audio_mode", "inactive");
3989  } else if (!strcasecmp(attr->a_name, "recvonly")) {
3990  switch_channel_set_variable(session->channel, "media_audio_mode", "sendonly");
3991  recvonly = 1;
3992 
3993  if (switch_rtp_ready(a_engine->rtp_session)) {
3995  a_engine->max_missed_hold_packets = 0;
3996  a_engine->max_missed_packets = 0;
3997  } else {
3998  switch_channel_set_variable(session->channel, "rtp_timeout_sec", "0");
3999  switch_channel_set_variable(session->channel, "rtp_hold_timeout_sec", "0");
4000  }
4001  } else if (sendonly < 2 && !strcasecmp(attr->a_name, "sendrecv")) {
4002  sendonly = 0;
4003  } else if (!strcasecmp(attr->a_name, "ptime")) {
4004  ptime = dptime = atoi(attr->a_value);
4005  } else if (!strcasecmp(attr->a_name, "maxptime")) {
4006  maxptime = dmaxptime = atoi(attr->a_value);
4007  }
4008  }
4009 
4010  if (sendonly == 2 && ice) {
4011  sendonly = 0;
4012  }
4013 
4014 
4015  if (sendonly != 1 && recvonly != 1) {
4016  switch_channel_set_variable(session->channel, "media_audio_mode", NULL);
4017  }
4018 
4019  if (sdp_type == SDP_TYPE_RESPONSE) {
4020  if (sendonly) {
4021  a_engine->smode = sdp_media_flow(sdp_sendonly);
4022  } else if (recvonly) {
4023  a_engine->smode = sdp_media_flow(sdp_recvonly);
4024  }
4025  }
4026 
4027 
4029  || ((val = switch_channel_get_variable(session->channel, "rtp_disable_hold"))
4030  && switch_true(val)))
4031  && !smh->mparams->hold_laps) {
4032  smh->mparams->hold_laps++;
4033  if (switch_core_media_toggle_hold(session, sendonly)) {
4035  if ((val = switch_channel_get_variable(session->channel, "rtp_renegotiate_codec_on_hold"))) {
4036  reneg = switch_true(val);
4037  }
4038  }
4039  }
4040 
4041  if (reneg) {
4043 
4044  if ((val = switch_channel_get_variable(session->channel, "rtp_renegotiate_codec_on_reinvite"))) {
4045  reneg = switch_true(val);
4046  }
4047  }
4048 
4049  if (session->bugs) {
4051  "Session is connected to a media bug. "
4052  "Re-Negotiation implicitly disabled.\n");
4053  reneg = 0;
4054  }
4055 
4057  reneg = 0;
4058  }
4059 
4060  if (sdp_type == SDP_TYPE_RESPONSE && smh->num_negotiated_codecs) {
4061  /* response to re-invite or update, only negotiated codecs are valid */
4062  reneg = 0;
4063  }
4064 
4065 
4066  if (!reneg && smh->num_negotiated_codecs) {
4067  codec_array = smh->negotiated_codecs;
4068  total_codecs = smh->num_negotiated_codecs;
4069  } else if (reneg) {
4070  smh->mparams->num_codecs = 0;
4072  codec_array = smh->codecs;
4073  total_codecs = smh->mparams->num_codecs;
4074  }
4075 
4076 
4077  if (switch_rtp_has_dtls() && dtls_ok(session)) {
4078  for (attr = m->m_attributes; attr; attr = attr->a_next) {
4079 
4080  if (!strcasecmp(attr->a_name, "fingerprint") && !zstr(attr->a_value)) {
4081  got_crypto = 1;
4082  }
4083  }
4084  }
4085 
4086  for (attr = m->m_attributes; attr; attr = attr->a_next) {
4087 
4088  if (!strcasecmp(attr->a_name, "rtcp") && attr->a_value) {
4089  switch_channel_set_variable(session->channel, "rtp_remote_audio_rtcp_port", attr->a_value);
4090  a_engine->remote_rtcp_port = (switch_port_t)atoi(attr->a_value);
4091  if (!smh->mparams->rtcp_audio_interval_msec) {
4093  }
4094  } else if (!strcasecmp(attr->a_name, "ptime") && attr->a_value) {
4095  ptime = atoi(attr->a_value);
4096  } else if (!strcasecmp(attr->a_name, "maxptime") && attr->a_value) {
4097  maxptime = atoi(attr->a_value);
4098  } else if (got_crypto < 1 && !strcasecmp(attr->a_name, "crypto") && !zstr(attr->a_value)) {
4099  int crypto_tag;
4100 
4101  if (!(smh->mparams->ndlb & SM_NDLB_ALLOW_CRYPTO_IN_AVP) &&
4102  !switch_true(switch_channel_get_variable(session->channel, "rtp_allow_crypto_in_avp"))) {
4103  if (m->m_proto != sdp_proto_srtp && !got_webrtc) {
4104  switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_ERROR, "a=crypto in RTP/AVP, refer to rfc3711\n");
4105  match = 0;
4106  goto done;
4107  }
4108  }
4109 
4110  crypto = attr->a_value;
4111  crypto_tag = atoi(crypto);
4112  got_crypto = switch_core_session_check_incoming_crypto(session,
4113  "rtp_has_crypto", SWITCH_MEDIA_TYPE_AUDIO, crypto, crypto_tag, sdp_type);
4114 
4115  }
4116  }
4117 
4118  if (got_crypto == -1 && got_savp && !got_avp && !got_webrtc) {
4119  switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_WARNING, "Declining invite with only SAVP because secure media is administratively disabled\n");
4120  match = 0;
4121  break;
4122  }
4123 
4124  connection = sdp->sdp_connection;
4125  if (m->m_connections) {
4126  connection = m->m_connections;
4127  }
4128 
4129  if (!connection) {
4130  switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_ERROR, "Cannot find a c= line in the sdp at media or session level!\n");
4131  match = 0;
4132  break;
4133  }
4134 
4135  x = 0;
4136 
4137  for (map = m->m_rtpmaps; map; map = map->rm_next) {
4138  int32_t i;
4139  const char *rm_encoding;
4140  uint32_t map_bit_rate = 0;
4141  switch_codec_fmtp_t codec_fmtp = { 0 };
4142  int map_channels = map->rm_params ? atoi(map->rm_params) : 1;
4143 
4144  if (!(rm_encoding = map->rm_encoding)) {
4145  rm_encoding = "";
4146  }
4147 
4148 
4149  if (!strcasecmp(rm_encoding, "telephone-event")) {
4150  if (!best_te || map->rm_rate == a_engine->cur_payload_map->rm_rate) {
4151  best_te = (switch_payload_t) map->rm_pt;
4152  best_te_rate = map->rm_rate;
4153  switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_DEBUG, "Set telephone-event payload to %u@%ld\n", best_te, best_te_rate);
4154  }
4155  continue;
4156  }
4157 
4158  if (!switch_media_handle_test_media_flag(smh, SCMF_SUPPRESS_CNG) && !cng_pt && !strcasecmp(rm_encoding, "CN")) {
4159  cng_pt = (switch_payload_t) map->rm_pt;
4160  if (a_engine->rtp_session) {
4161  switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_DEBUG, "Set comfort noise payload to %u\n", cng_pt);
4162  switch_rtp_set_cng_pt(a_engine->rtp_session, smh->mparams->cng_pt);
4163  }
4164  continue;
4165  }
4166 
4167 
4168  if (x++ < skip) {
4169  continue;
4170  }
4171 
4172  if (match) {
4173  continue;
4174  }
4175 
4176  codec_ms = ptime;
4177 
4178  if (switch_channel_get_variable(session->channel, "rtp_h_X-Broken-PTIME") && a_engine->read_impl.microseconds_per_packet) {
4179  switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_DEBUG, "Overwriting ptime from a known broken endpoint with the currently used value of %d ms\n", a_engine->read_impl.microseconds_per_packet / 1000);
4180  codec_ms = a_engine->read_impl.microseconds_per_packet / 1000;
4181  }
4182 
4183  if (maxptime && (!codec_ms || codec_ms > maxptime)) {
4184  codec_ms = maxptime;
4185  }
4186 
4187  if (!codec_ms) {
4188  codec_ms = switch_default_ptime(rm_encoding, map->rm_pt);
4189  }
4190 
4191  map_bit_rate = switch_known_bitrate((switch_payload_t)map->rm_pt);
4192 
4193  if (!ptime && !strcasecmp(map->rm_encoding, "g723")) {
4194  codec_ms = 30;
4195  }
4196 
4197  remote_codec_rate = map->rm_rate;
4198  fmtp_remote_codec_rate = 0;
4199  memset(&codec_fmtp, 0, sizeof(codec_fmtp));
4200 
4201  if (zstr(map->rm_fmtp)) {
4202  if (!strcasecmp(map->rm_encoding, "ilbc")) {
4203  codec_ms = 30;
4204  map_bit_rate = 13330;
4205  } else if (!strcasecmp(map->rm_encoding, "isac")) {
4206  codec_ms = 30;
4207  map_bit_rate = 32000;
4208  }
4209  } else {
4210  if ((switch_core_codec_parse_fmtp(map->rm_encoding, map->rm_fmtp, map->rm_rate, &codec_fmtp)) == SWITCH_STATUS_SUCCESS) {
4211  if (codec_fmtp.bits_per_second) {
4212  map_bit_rate = codec_fmtp.bits_per_second;
4213  }
4214  if (codec_fmtp.microseconds_per_packet) {
4215  codec_ms = (codec_fmtp.microseconds_per_packet / 1000);
4216  }
4217  if (codec_fmtp.actual_samples_per_second) {
4218  fmtp_remote_codec_rate = codec_fmtp.actual_samples_per_second;
4219  }
4220  if (codec_fmtp.stereo) {
4221  map_channels = 2;
4222  } else if (!strcasecmp(map->rm_encoding, "opus")) {
4223  map_channels = 1;
4224  }
4225  }
4226  }
4227 
4228  for (i = 0; i < smh->mparams->num_codecs && i < total_codecs; i++) {
4229  const switch_codec_implementation_t *imp = codec_array[i];
4230  uint32_t bit_rate = imp->bits_per_second;
4231  uint32_t codec_rate = imp->samples_per_second;
4232 
4233  if (imp->codec_type != SWITCH_CODEC_TYPE_AUDIO) {
4234  continue;
4235  }
4236 
4237  switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_DEBUG, "Audio Codec Compare [%s:%d:%u:%d:%u:%d]/[%s:%d:%u:%d:%u:%d]\n",
4238  rm_encoding, map->rm_pt, (int) remote_codec_rate, codec_ms, map_bit_rate, map_channels,
4239  imp->iananame, imp->ianacode, codec_rate, imp->microseconds_per_packet / 1000, bit_rate, imp->number_of_channels);
4240  if ((zstr(map->rm_encoding) || (smh->mparams->ndlb & SM_NDLB_ALLOW_BAD_IANANAME)) && map->rm_pt < 96) {
4241  match = (map->rm_pt == imp->ianacode) ? 1 : 0;
4242  } else {
4243  match = (!strcasecmp(rm_encoding, imp->iananame) &&
4244  ((map->rm_pt < 96 && imp->ianacode < 96) || (map->rm_pt > 95 && imp->ianacode > 95)) &&
4245  (remote_codec_rate == codec_rate || fmtp_remote_codec_rate == imp->actual_samples_per_second)) ? 1 : 0;
4246  if (fmtp_remote_codec_rate) {
4247  remote_codec_rate = fmtp_remote_codec_rate;
4248  }
4249  }
4250 
4251  if (match && bit_rate && map_bit_rate && map_bit_rate != bit_rate && strcasecmp(map->rm_encoding, "ilbc") &&
4252  strcasecmp(map->rm_encoding, "isac")) {
4253  /* if a bit rate is specified and doesn't match, this is not a codec match, except for ILBC */
4254  match = 0;
4255  }
4256 
4257  if (match && remote_codec_rate && codec_rate && remote_codec_rate != codec_rate && (!strcasecmp(map->rm_encoding, "pcma") ||
4258  !strcasecmp(map->rm_encoding, "pcmu"))) {
4259  /* if the sampling rate is specified and doesn't match, this is not a codec match for G.711 */
4260  switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_DEBUG, "sampling rates have to match for G.711\n");
4261  match = 0;
4262  }
4263 
4264  if (match) {
4265  if (scrooge) {
4267  "Bah HUMBUG! Sticking with %s@%uh@%ui\n",
4268  imp->iananame, imp->samples_per_second, imp->microseconds_per_packet / 1000);
4269  } else if ((ptime && codec_ms && codec_ms * 1000 != imp->microseconds_per_packet) || remote_codec_rate != codec_rate) {
4270  /* ptime does not match */
4271  match = 0;
4272 
4274  "Audio Codec Compare [%s:%d:%u:%d:%u:%d] is saved as a near-match\n",
4275  imp->iananame, imp->ianacode, codec_rate, imp->microseconds_per_packet / 1000, bit_rate, imp->number_of_channels);
4276 
4277  near_matches[nm_idx].codec_idx = i;
4278  near_matches[nm_idx].rate = remote_codec_rate;
4279  near_matches[nm_idx].imp = imp;
4280  near_matches[nm_idx].map = map;
4281  nm_idx++;
4282 
4283  continue;
4284  }
4285 
4286  matches[m_idx].codec_idx = i;
4287  matches[m_idx].rate = codec_rate;
4288  matches[m_idx].imp = imp;
4289  matches[m_idx].map = map;
4290  m_idx++;
4291 
4293  "Audio Codec Compare [%s:%d:%u:%d:%u:%d] ++++ is saved as a match\n",
4294  imp->iananame, imp->ianacode, codec_rate, imp->microseconds_per_packet / 1000, bit_rate, imp->number_of_channels);
4295 
4296  if (m_idx >= MAX_MATCHES) {
4297  break;
4298  }
4299 
4300  match = 0;
4301  }
4302  }
4303 
4304  if (m_idx >= MAX_MATCHES) {
4305  break;
4306  }
4307  }
4308 
4309  if (smh->crypto_mode == CRYPTO_MODE_MANDATORY && got_crypto < 1) {
4310  switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_WARNING, "Crypto not negotiated but required.\n");
4311  match = 0;
4312  m_idx = nm_idx = 0;
4313  }
4314 
4315 
4316  if (!m_idx && nm_idx) {
4317  int j;
4318 
4319  for(j = 0; j < nm_idx; j++) {
4320  const switch_codec_implementation_t *search[1];
4321  char *prefs[1];
4322  char tmp[80];
4323  int num;
4324  const switch_codec_implementation_t *timp = NULL;
4325 
4326  near_rate = near_matches[j].rate;
4327  near_match = near_matches[j].imp;
4328  near_map = near_matches[j].map;
4329 
4330  switch_snprintf(tmp, sizeof(tmp), "%s@%uh@%ui%dc", near_match->iananame, near_rate ? near_rate : near_match->samples_per_second,
4331  codec_ms, near_match->number_of_channels);
4332 
4333  prefs[0] = tmp;
4334  num = switch_loadable_module_get_codecs_sorted(search, 1, prefs, 1);
4335 
4336  if (num) {
4337  timp = search[0];
4338  } else {
4339  timp = near_match;
4340  }
4341 
4342  if (!maxptime || timp->microseconds_per_packet / 1000 <= maxptime) {
4343  switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_DEBUG, "Substituting codec %s@%ui@%uh@%dc\n",
4345  match = 1;
4346 
4347  matches[m_idx].codec_idx = near_matches[j].codec_idx;
4348  matches[m_idx].rate = near_rate;
4349  matches[m_idx].imp = timp;
4350  matches[m_idx].map = near_map;
4351  m_idx++;
4352 
4353  break;
4354  }
4355  }
4356  }
4357 
4358  if (m_idx) {
4359  int j;
4360 
4361  if (greedy) { /* sort in favor of mine */
4362  greedy_sort(smh, matches, m_idx, codec_array, total_codecs);
4363  }
4364 
4365  match = 1;
4366  a_engine->codec_negotiated = 1;
4367  smh->num_negotiated_codecs = 0;
4368 
4369  for(j = 0; j < m_idx; j++) {
4372  matches[j].map->rm_encoding,
4373  matches[j].imp->modname,
4374  matches[j].map->rm_fmtp,
4375  sdp_type,
4376  matches[j].map->rm_pt,
4377  matches[j].imp->samples_per_second,
4378  matches[j].imp->microseconds_per_packet / 1000,
4379  matches[j].imp->number_of_channels,
4380  SWITCH_TRUE);
4381 
4382  mimp = matches[j].imp;
4383  mmap = matches[j].map;
4384 
4385  if (j == 0) {
4386  a_engine->cur_payload_map = pmap;
4387  a_engine->cur_payload_map->current = 1;
4388  if (a_engine->rtp_session) {
4389  switch_rtp_set_default_payload(a_engine->rtp_session, pmap->pt);
4390  }
4391  }
4392 
4393  pmap->rm_encoding = switch_core_session_strdup(session, (char *) mmap->rm_encoding);
4394  pmap->iananame = switch_core_session_strdup(session, (char *) mimp->iananame);
4395  pmap->recv_pt = (switch_payload_t) mmap->rm_pt;
4396  pmap->rm_rate = mimp->samples_per_second;
4397  pmap->adv_rm_rate = mimp->samples_per_second;
4398  if (strcasecmp(mimp->iananame, "g722")) {
4399  pmap->rm_rate = mimp->actual_samples_per_second;
4400  }
4401  pmap->codec_ms = mimp->microseconds_per_packet / 1000;
4402  pmap->bitrate = mimp->bits_per_second;
4403  pmap->channels = mmap->rm_params ? atoi(mmap->rm_params) : 1;
4404 
4405  if (!strcasecmp((char *) mmap->rm_encoding, "opus")) {
4406  if (pmap->channels == 1) {
4407  switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_WARNING, "Invalid SDP for opus. Don't ask.. but it needs a /2\n");
4408  pmap->adv_channels = 1;
4409  } else {
4410  pmap->adv_channels = 2; /* IKR ???*/
4411  }
4412  if (!zstr((char *) mmap->rm_fmtp) && switch_stristr("stereo=1", (char *) mmap->rm_fmtp)) {
4413  pmap->channels = 2;
4414  } else {
4415  pmap->channels = 1;
4416  }
4417  } else {
4418  pmap->adv_channels = pmap->channels;
4419  }
4420 
4421  pmap->remote_sdp_ip = switch_core_session_strdup(session, (char *) connection->c_address);
4422  pmap->remote_sdp_port = (switch_port_t) m->m_port;
4423  pmap->rm_fmtp = switch_core_session_strdup(session, (char *) mmap->rm_fmtp);
4424 
4425  pmap->agreed_pt = (switch_payload_t) mmap->rm_pt;
4426  smh->negotiated_codecs[smh->num_negotiated_codecs++] = mimp;
4427  pmap->recv_pt = (switch_payload_t)mmap->rm_pt;
4428 
4429  }
4430  }
4431 
4432  if (match) {
4433  char tmp[50];
4434  //const char *mirror = switch_channel_get_variable(session->channel, "rtp_mirror_remote_audio_codec_payload");
4435 
4436 
4437  switch_snprintf(tmp, sizeof(tmp), "%d", a_engine->cur_payload_map->remote_sdp_port);
4440 
4441 
4442  if (a_engine->cur_payload_map->pt == smh->mparams->te) {
4443  switch_payload_t pl = 0;
4444  payload_map_t *pmap;
4445 
4447  for (pmap = a_engine->cur_payload_map; pmap && pmap->allocated; pmap = pmap->next) {
4448  if (pmap->pt > pl) {
4449  pl = pmap->pt;
4450  }
4451  }
4453 
4454  smh->mparams->te = (switch_payload_t) ++pl;
4455  }
4456 
4457 
4458 
4459 #if 0
4460  if (!switch_true(mirror) &&
4463  switch_core_media_get_offered_pt(session, matches[0].imp, &a_engine->cur_payload_map->recv_pt);
4464  }
4465 #endif
4466 
4467  switch_snprintf(tmp, sizeof(tmp), "%d", a_engine->cur_payload_map->recv_pt);
4468  switch_channel_set_variable(session->channel, "rtp_audio_recv_pt", tmp);
4469 
4470  if (a_engine->read_impl.iananame) {
4471  if (!switch_core_codec_ready(&a_engine->read_codec) ||
4472  ((strcasecmp(matches[0].imp->iananame, a_engine->read_impl.iananame) ||
4473  matches[0].imp->microseconds_per_packet != a_engine->read_impl.microseconds_per_packet ||
4474  matches[0].imp->samples_per_second != a_engine->read_impl.samples_per_second
4475  ))) {
4476 
4477  a_engine->reset_codec = 1;
4478  }
4479  } else if (switch_core_media_set_codec(session, 0, smh->mparams->codec_flags) != SWITCH_STATUS_SUCCESS) {
4480  match = 0;
4481  }
4482 
4483  if (match) {
4484  if (check_ice(smh, SWITCH_MEDIA_TYPE_AUDIO, sdp, m) == SWITCH_STATUS_FALSE) {
4485  match = 0;
4486  got_audio = 0;
4487  } else {
4488  got_audio = 1;
4489  }
4490  }
4491 
4492  }
4493 
4494  for (map = m->m_rtpmaps; map; map = map->rm_next) {
4495  const char *rm_encoding;
4496 
4497  if (!(rm_encoding = map->rm_encoding)) {
4498  rm_encoding = "";
4499  }
4500 
4501  if (!strcasecmp(rm_encoding, "telephone-event")) {
4502  if (!best_te || map->rm_rate == a_engine->cur_payload_map->adv_rm_rate) {
4503  best_te = (switch_payload_t) map->rm_pt;
4504  best_te_rate = map->rm_rate;
4505  switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_DEBUG, "Set telephone-event payload to %u@%lu\n", best_te, best_te_rate);
4506  }
4507  continue;
4508  }
4509 
4510  if (!switch_media_handle_test_media_flag(smh, SCMF_SUPPRESS_CNG) && !strcasecmp(rm_encoding, "CN")) {
4511 
4512  if (!cng_pt || map->rm_rate == a_engine->cur_payload_map->adv_rm_rate) {
4513  cng_pt = (switch_payload_t) map->rm_pt;
4514  cng_rate = map->rm_rate;
4515 
4516  if (a_engine->rtp_session) {
4517  switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_DEBUG, "Set comfort noise payload to %u@%lu\n", cng_pt, cng_rate);
4518  switch_rtp_set_cng_pt(a_engine->rtp_session, smh->mparams->cng_pt);
4519  }
4520  }
4521  continue;
4522  }
4523  }
4524 
4525  if (cng_rate != a_engine->cur_payload_map->adv_rm_rate) {
4526  cng_rate = 8000;
4527  }
4528 
4529  if (best_te_rate != a_engine->cur_payload_map->adv_rm_rate) {
4530  best_te_rate = 8000;
4531  }
4532 
4533  if (!best_te && (switch_media_handle_test_media_flag(smh, SCMF_LIBERAL_DTMF) ||
4536  "No 2833 in SDP. Liberal DTMF mode adding %d as telephone-event.\n", smh->mparams->te);
4537  best_te = smh->mparams->te;
4538  }
4539 
4540  if (best_te) {
4541  smh->mparams->te_rate = best_te_rate;
4542 
4543  if (smh->mparams->dtmf_type == DTMF_AUTO) {
4544  if (sdp_type == SDP_TYPE_REQUEST) {
4545  smh->mparams->te = smh->mparams->recv_te = (switch_payload_t) best_te;
4546  switch_channel_set_variable(session->channel, "dtmf_type", "rfc2833");
4547  smh->mparams->dtmf_type = DTMF_2833;
4548  } else {
4549  smh->mparams->te = (switch_payload_t) best_te;
4550  switch_channel_set_variable(session->channel, "dtmf_type", "rfc2833");
4551  smh->mparams->dtmf_type = DTMF_2833;
4552  }
4553  }
4554 
4555  if (a_engine->rtp_session) {
4557  switch_channel_set_variable_printf(session->channel, "rtp_2833_send_payload", "%d", smh->mparams->te);
4559  switch_channel_set_variable_printf(session->channel, "rtp_2833_recv_payload", "%d", smh->mparams->recv_te);
4560  }
4561 
4562 
4563  switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_DEBUG, "%s Set 2833 dtmf send payload to %u recv payload to %u\n",
4564  switch_channel_get_name(session->channel), smh->mparams->te, smh->mparams->recv_te);
4565 
4566 
4567  } else {
4568  /* by default, use SIP INFO if 2833 is not in the SDP */
4569  if (!switch_false(switch_channel_get_variable(channel, "rtp_info_when_no_2833"))) {
4570  switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_DEBUG, "No 2833 in SDP. Disable 2833 dtmf and switch to INFO\n");
4571  switch_channel_set_variable(session->channel, "dtmf_type", "info");
4572  smh->mparams->dtmf_type = DTMF_INFO;
4573  smh->mparams->recv_te = smh->mparams->te = 0;
4574  } else {
4575  switch_channel_set_variable(session->channel, "dtmf_type", "none");
4576  smh->mparams->dtmf_type = DTMF_NONE;
4577  smh->mparams->recv_te = smh->mparams->te = 0;
4578  }
4579  }
4580 
4581  } else if (m->m_type == sdp_media_video && m->m_port) {
4582  sdp_rtpmap_t *map;
4583  const char *rm_encoding;
4584  const switch_codec_implementation_t *mimp = NULL;
4585  int i;
4586 
4587  vmatch = 0;
4588  nm_idx = 0;
4589  m_idx = 0;
4590  memset(matches, 0, sizeof(matches[0]) * MAX_MATCHES);
4591  memset(near_matches, 0, sizeof(near_matches[0]) * MAX_MATCHES);
4592 
4593  switch_channel_set_variable(session->channel, "video_possible", "true");
4595 
4596  connection = sdp->sdp_connection;
4597  if (m->m_connections) {
4598  connection = m->m_connections;
4599  }
4600 
4601  if (!connection) {
4602  switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_ERROR, "Cannot find a c= line in the sdp at media or session level!\n");
4603  match = 0;
4604  break;
4605  }
4606 
4607  v_engine->rmode = sdp_media_flow(m->m_mode);
4608 
4609  if (sdp_type == SDP_TYPE_REQUEST) {
4610  sdp_bandwidth_t *bw;
4611  int tias = 0;
4612 
4613  for (bw = m->m_bandwidths; bw; bw = bw->b_next) {
4614  if (bw->b_modifier == sdp_bw_as && !tias) {
4615  v_engine->sdp_bw = bw->b_value / 1024;
4616  } else if (bw->b_modifier == sdp_bw_tias) {
4617  tias = 1;
4618  v_engine->sdp_bw = bw->b_value / 1024;
4619  }
4620  }
4621 
4622  switch(v_engine->rmode) {
4624  switch_channel_set_variable(smh->session->channel, "video_media_flow", "sendonly");
4625  v_engine->smode = SWITCH_MEDIA_FLOW_SENDONLY;
4627  break;
4629  switch_channel_set_variable(smh->session->channel, "video_media_flow", "recvonly");
4630  v_engine->smode = SWITCH_MEDIA_FLOW_RECVONLY;
4631  break;
4632  default:
4633  switch_channel_set_variable(smh->session->channel, "video_media_flow", "sendrecv");
4634  v_engine->smode = SWITCH_MEDIA_FLOW_SENDRECV;
4635  break;
4636  }
4637  }
4638 
4639 
4640  for (map = m->m_rtpmaps; map; map = map->rm_next) {
4641 
4642  if (switch_rtp_has_dtls() && dtls_ok(session)) {
4643  for (attr = m->m_attributes; attr; attr = attr->a_next) {
4644  if (!strcasecmp(attr->a_name, "fingerprint") && !zstr(attr->a_value)) {
4645  got_video_crypto = 1;
4646  }
4647  }
4648  }
4649 
4650  for (attr = m->m_attributes; attr; attr = attr->a_next) {
4651  if (!strcasecmp(attr->a_name, "framerate") && attr->a_value) {
4652  //framerate = atoi(attr->a_value);
4653  } else if (!strcasecmp(attr->a_name, "rtcp-fb")) {
4654  if (!zstr(attr->a_value)) {
4655  if (switch_stristr("fir", attr->a_value)) {
4656  v_engine->fir++;
4657  }
4658 
4659  if (switch_stristr("pli", attr->a_value)) {
4660  v_engine->pli++;
4661  }
4662 
4663  if (switch_stristr("nack", attr->a_value)) {
4664  v_engine->nack++;
4665  }
4666 
4667  if (switch_stristr("tmmbr", attr->a_value)) {
4668  v_engine->tmmbr++;
4669  }
4670 
4672  }
4673  } else if (!strcasecmp(attr->a_name, "rtcp") && attr->a_value && !strcmp(attr->a_value, "1")) {
4674  switch_channel_set_variable(session->channel, "rtp_remote_video_rtcp_port", attr->a_value);
4675  v_engine->remote_rtcp_port = (switch_port_t)atoi(attr->a_value);
4676  if (!smh->mparams->rtcp_video_interval_msec) {
4678  }
4679  } else if (!got_video_crypto && !strcasecmp(attr->a_name, "crypto") && !zstr(attr->a_value)) {
4680  int crypto_tag;
4681 
4682  if (!(smh->mparams->ndlb & SM_NDLB_ALLOW_CRYPTO_IN_AVP) &&
4683  !switch_true(switch_channel_get_variable(session->channel, "rtp_allow_crypto_in_avp"))) {
4684  if (m->m_proto != sdp_proto_srtp && !got_webrtc) {
4685  switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_ERROR, "a=crypto in RTP/AVP, refer to rfc3711\n");
4686  match = 0;
4687  goto done;
4688  }
4689  }
4690 
4691  crypto = attr->a_value;
4692  crypto_tag = atoi(crypto);
4693 
4694  got_video_crypto = switch_core_session_check_incoming_crypto(session,
4695  "rtp_has_video_crypto",
4696  SWITCH_MEDIA_TYPE_VIDEO, crypto, crypto_tag, sdp_type);
4697 
4698  }
4699  }
4700 
4701  if (!(rm_encoding = map->rm_encoding)) {
4702  rm_encoding = "";
4703  }
4704 
4705  for (i = 0; i < total_codecs; i++) {
4706  const switch_codec_implementation_t *imp = codec_array[i];
4707 
4708  if (imp->codec_type != SWITCH_CODEC_TYPE_VIDEO) {
4709  continue;
4710  }
4711 
4714  continue;
4715  }
4716 
4717  switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_DEBUG, "Video Codec Compare [%s:%d]/[%s:%d]\n",
4718  rm_encoding, map->rm_pt, imp->iananame, imp->ianacode);
4719  if ((zstr(map->rm_encoding) || (smh->mparams->ndlb & SM_NDLB_ALLOW_BAD_IANANAME)) && map->rm_pt < 96) {
4720  vmatch = (map->rm_pt == imp->ianacode) ? 1 : 0;
4721  } else {
4722  vmatch = strcasecmp(rm_encoding, imp->iananame) ? 0 : 1;
4723  }
4724 
4725  if (vmatch && (map->rm_rate == imp->samples_per_second)) {
4726  matches[m_idx].imp = imp;
4727  matches[m_idx].map = map;
4728 
4729  switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_DEBUG, "Video Codec Compare [%s:%d] +++ is saved as a match\n",
4730  imp->iananame, imp->ianacode);
4731  m_idx++;
4732  }
4733 
4734  vmatch = 0;
4735  }
4736  }
4737 
4738  if (smh->crypto_mode == CRYPTO_MODE_MANDATORY && got_video_crypto < 1) {
4739  switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_WARNING, "Crypto not negotiated but required.\n");
4740  vmatch = 0;
4741  m_idx = 0;
4742  }
4743 
4744  if (m_idx) {
4745  char tmp[50];
4746  //const char *mirror = switch_channel_get_variable(session->channel, "rtp_mirror_remote_video_codec_payload");
4747  int j = 0;
4748 
4749  if (greedy) { /* sort in favor of mine */
4750  greedy_sort(smh, matches, m_idx, codec_array, total_codecs);
4751  }
4752 
4753  vmatch = 1;
4754  v_engine->codec_negotiated = 1;
4755 
4756  for(j = 0; j < m_idx; j++) {
4759  matches[j].map->rm_encoding,
4760  matches[j].imp->modname,
4761  matches[j].map->rm_fmtp,
4762  sdp_type,
4763  matches[j].map->rm_pt,
4764  matches[j].imp->samples_per_second,
4765  matches[j].imp->microseconds_per_packet / 1000,
4766  matches[j].imp->number_of_channels,
4767  SWITCH_TRUE);
4768 
4769  if (j == 0) {
4770  v_engine->cur_payload_map = pmap;
4771  v_engine->cur_payload_map->current = 1;
4772  if (v_engine->rtp_session) {
4773  switch_rtp_set_default_payload(v_engine->rtp_session, pmap->pt);
4774  }
4775  }
4776 
4777  mimp = matches[j].imp;
4778  map = matches[j].map;
4779 
4780  pmap->rm_encoding = switch_core_session_strdup(session, (char *) map->rm_encoding);
4781  pmap->recv_pt = (switch_payload_t) map->rm_pt;
4782  pmap->rm_rate = map->rm_rate;
4783  pmap->codec_ms = mimp->microseconds_per_packet / 1000;
4784 
4785 
4786  pmap->remote_sdp_ip = switch_core_session_strdup(session, (char *) connection->c_address);
4787  pmap->remote_sdp_port = (switch_port_t) m->m_port;
4788 
4789  pmap->rm_fmtp = switch_core_session_strdup(session, (char *) map->rm_fmtp);
4790 
4791  pmap->agreed_pt = (switch_payload_t) map->rm_pt;
4792 
4793  smh->negotiated_codecs[smh->num_negotiated_codecs++] = mimp;
4794 
4795 #if 0
4796  if (j == 0 && (!switch_true(mirror) && switch_channel_direction(channel) == SWITCH_CALL_DIRECTION_OUTBOUND)) {
4797  switch_core_media_get_offered_pt(session, mimp, &pmap->recv_pt);
4798  }
4799 #endif
4800  }
4801 
4802 
4803 
4804  switch_snprintf(tmp, sizeof(tmp), "%d", v_engine->cur_payload_map->remote_sdp_port);
4807  switch_channel_set_variable(session->channel, "rtp_video_fmtp", v_engine->cur_payload_map->rm_fmtp);
4808  switch_snprintf(tmp, sizeof(tmp), "%d", v_engine->cur_payload_map->agreed_pt);
4809  switch_channel_set_variable(session->channel, "rtp_video_pt", tmp);
4811  switch_snprintf(tmp, sizeof(tmp), "%d", v_engine->cur_payload_map->recv_pt);
4812  switch_channel_set_variable(session->channel, "rtp_video_recv_pt", tmp);
4813 
4814  if (switch_core_codec_ready(&v_engine->read_codec) && strcasecmp(matches[0].imp->iananame, v_engine->read_codec.implementation->iananame)) {
4815  v_engine->reset_codec = 1;
4816  }
4817 
4819  if (check_ice(smh, SWITCH_MEDIA_TYPE_VIDEO, sdp, m) == SWITCH_STATUS_FALSE) {
4820  vmatch = 0;
4821  }
4822  }
4823  }
4824  }
4825  }
4826 
4827  if (!saw_audio) {
4828  payload_map_t *pmap;
4829 
4830  a_engine->rmode = SWITCH_MEDIA_FLOW_DISABLED;
4831  switch_channel_set_variable(smh->session->channel, "audio_media_flow", "inactive");
4832 
4833 
4834  pmap = switch_core_media_add_payload_map(session,
4836  "L16",
4837  NULL,
4838  NULL,
4840  97,
4841  8000,
4842  20,
4843  1,
4844  SWITCH_TRUE);
4845 
4846  pmap->remote_sdp_ip = "127.0.0.1";
4847  pmap->remote_sdp_port = 9999;
4848  pmap->agreed_pt = 97;
4849  pmap->recv_pt = 97;
4850  pmap->codec_ms = 20;
4851  a_engine->cur_payload_map = pmap;
4853  }
4854 
4855 
4856  if (!match && vmatch) match = 1;
4857 
4858  done:
4859 
4860  if (parser) {
4861  sdp_parser_free(parser);
4862  }
4863 
4864  smh->mparams->cng_pt = cng_pt;
4865  smh->mparams->cng_rate = cng_rate;
4866 
4867  return match;
4868 }
switch_status_t switch_channel_set_variable_printf(switch_channel_t *channel, const char *varname, const char *fmt,...)
#define switch_channel_hangup(channel, hangup_cause)
Hangup a channel flagging it's state machine to end.
uint8_t allocated
#define SWITCH_CHANNEL_SESSION_LOG(x)
switch_status_t switch_core_codec_parse_fmtp(const char *codec_name, const char *fmtp, uint32_t rate, switch_codec_fmtp_t *codec_fmtp)
uint8_t switch_rtp_ready(switch_rtp_t *rtp_session)
Test if an RTP session is ready.
Definition: switch_rtp.c:4452
static switch_t38_options_t * switch_core_media_process_udptl(switch_core_session_t *session, sdp_session_t *sdp, sdp_media_t *m)
switch_core_session_message_types_t message_id
Definition: switch_core.h:181
static switch_media_flow_t sdp_media_flow(unsigned in)
switch_status_t switch_core_media_set_video_codec(switch_core_session_t *session, int force)
static switch_status_t check_ice(switch_media_handle_t *smh, switch_media_type_t type, sdp_session_t *sdp, sdp_media_t *m)
unsigned long rm_rate
unsigned long adv_rm_rate
char * remote_sdp_ip
static void clear_pmaps(switch_rtp_engine_t *engine)
switch_media_flow_t smode
const switch_codec_implementation_t * codecs[SWITCH_MAX_CODECS]
void switch_core_session_set_ice(switch_core_session_t *session)
switch_rtp_crypto_mode_t crypto_mode
switch_status_t switch_core_session_queue_message(_In_ switch_core_session_t *session, _In_ switch_core_session_message_t *message)
Queue a message on a session.
switch_status_t switch_core_media_get_offered_pt(switch_core_session_t *session, const switch_codec_implementation_t *mimp, switch_payload_t *pt)
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
const switch_codec_implementation_t * negotiated_codecs[SWITCH_MAX_CODECS]
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.
static void switch_core_session_parse_crypto_prefs(switch_core_session_t *session)
static uint32_t switch_known_bitrate(switch_payload_t payload)
Definition: switch_utils.h:418
A message object designed to allow unlike technologies to exchange data.
Definition: switch_core.h:177
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
struct payload_map_s * next
switch_media_handle_t * media_handle
#define zstr(x)
Definition: switch_utils.h:281
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
switch_status_t switch_mutex_unlock(switch_mutex_t *lock)
Definition: switch_apr.c:290
#define MAX_MATCHES
_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.
sdp_rtpmap_t * map
void switch_channel_clear_app_flag_key(const char *app, switch_channel_t *channel, uint32_t flags)
void switch_core_media_check_video_codecs(switch_core_session_t *session)
#define SWITCH_RTCP_AUDIO_INTERVAL_MSEC
Definition: switch_types.h:234
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)
const switch_codec_implementation_t * implementation
#define SWITCH_REMOTE_MEDIA_IP_VARIABLE
Definition: switch_types.h:210
if((uint32_t)(unpack->cur-unpack->buf) > unpack->buflen)
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_mutex_lock(switch_mutex_t *lock)
Definition: switch_apr.c:285
switch_media_flow_t rmode
#define switch_channel_get_variable(_c, _v)
switch_core_session_t * session
payload_map_t * cur_payload_map
switch_core_media_dtmf_t dtmf_type
switch_media_bug_t * bugs
switch_payload_t pt
uint16_t switch_port_t
uint32_t switch_default_ptime(const char *name, uint32_t number)
Definition: switch_core.c:2026
#define switch_core_session_get_partner(_session, _partner)
Definition: switch_core.h:1002
static void switch_core_media_find_zrtp_hash(switch_core_session_t *session, sdp_session_t *sdp)
int switch_core_media_toggle_hold(switch_core_session_t *session, int sendonly)
static void greedy_sort(switch_media_handle_t *smh, struct matches *matches, int m_idx, const switch_codec_implementation_t **codec_array, int total_codecs)
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
uint32_t bitrate
void switch_core_session_rwunlock(_In_ switch_core_session_t *session)
Unlock a read or write lock on as given session.
#define SWITCH_RTCP_VIDEO_INTERVAL_MSEC
Definition: switch_types.h:235
switch_status_t switch_core_media_check_autoadj(switch_core_session_t *session)
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
void switch_core_media_copy_t38_options(switch_t38_options_t *t38_options, switch_core_session_t *session)
int switch_loadable_module_get_codecs_sorted(const switch_codec_implementation_t **array, int arraylen, char **prefs, int preflen)
Retrieve the list of loaded codecs into an array based on another array showing the sorted order...
char * switch_rtp_get_remote_host(switch_rtp_t *rtp_session)
Definition: switch_rtp.c:2822
void switch_core_media_pass_zrtp_hash(switch_core_session_t *session)
switch_rtp_engine_t engines[SWITCH_MEDIA_TYPE_TOTAL]
const switch_codec_implementation_t * imp
static int dtls_ok(switch_core_session_t *session)
const char * remote_ip
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
#define SWITCH_REMOTE_VIDEO_PORT_VARIABLE
Definition: switch_types.h:213
#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_port_t remote_rtcp_port
switch_rtp_bug_flag_t auto_rtp_bugs
switch_payload_t agreed_pt
static const char * skip(const char *in)
Definition: switch_json.c:270
switch_rtp_bug_flag_t rtp_bugs
switch_core_media_NDLB_t ndlb
#define switch_core_session_alloc(_session, _memory)
Allocate memory from a session's pool.
Definition: switch_core.h:694
static switch_bool_t switch_core_codec_ready(switch_codec_t *codec)
void switch_log_printf(_In_ switch_text_channel_t channel, _In_z_ const char *file, _In_z_ const char *func, _In_ int line, _In_opt_z_ const char *userdata, _In_ switch_log_level_t level, _In_z_ _Printf_format_string_ const char *fmt,...) PRINTF_FUNCTION(7
Write log data to the logging engine.
switch_payload_t recv_pt
const char * switch_stristr(const char *instr, const char *str)
A table of settings and callbacks that define a paticular implementation of a codec.
switch_port_t remote_sdp_port
static int switch_false(const char *expr)
Evaluate the falsefullness of a string expression.
Definition: switch_utils.h:482
#define switch_core_session_strdup(_session, _todup)
Copy a string using memory allocation from a session's pool.
Definition: switch_core.h:717
switch_mutex_t * sdp_mutex
void switch_channel_clear_flag(switch_channel_t *channel, switch_channel_flag_t flag)
Clear given flag(s) from a channel.
int switch_channel_test_app_flag_key(const char *app, switch_channel_t *channel, uint32_t flags)
#define switch_assert(expr)
#define switch_channel_set_variable(_channel, _var, _val)
char * switch_channel_get_name(switch_channel_t *channel)
Retrieve the name of a given channel.
memset(buf, 0, buflen)
switch_core_media_params_t * mparams
uint32_t codec_ms
uint8_t switch_payload_t
void switch_core_media_prepare_codecs(switch_core_session_t *session, switch_bool_t force)
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)
#define SWITCH_REMOTE_VIDEO_IP_VARIABLE
Definition: switch_types.h:212
char * rm_encoding
void switch_core_media_parse_rtp_bugs ( switch_rtp_bug_flag_t flag_pole,
const char *  str 
)

Definition at line 915 of file switch_core_media.c.

References RTP_BUG_ACCEPT_ANY_PACKETS, RTP_BUG_ACCEPT_ANY_PAYLOAD, RTP_BUG_ALWAYS_AUTO_ADJUST, RTP_BUG_CHANGE_SSRC_ON_MARKER, RTP_BUG_CISCO_SKIP_MARK_BIT_2833, RTP_BUG_FLUSH_JB_ON_DTMF, RTP_BUG_GEN_ONE_GEN_ALL, RTP_BUG_IGNORE_DTMF_DURATION, RTP_BUG_IGNORE_MARK_BIT, RTP_BUG_NEVER_SEND_MARKER, RTP_BUG_SEND_LINEAR_TIMESTAMPS, RTP_BUG_SONUS_SEND_INVALID_TIMESTAMP_2833, RTP_BUG_START_SEQ_AT_ZERO, and switch_stristr().

Referenced by switch_core_media_activate_rtp().

916 {
917 
918  if (switch_stristr("clear", str)) {
919  *flag_pole = 0;
920  }
921 
922  if (switch_stristr("CISCO_SKIP_MARK_BIT_2833", str)) {
923  *flag_pole |= RTP_BUG_CISCO_SKIP_MARK_BIT_2833;
924  }
925 
926  if (switch_stristr("~CISCO_SKIP_MARK_BIT_2833", str)) {
927  *flag_pole &= ~RTP_BUG_CISCO_SKIP_MARK_BIT_2833;
928  }
929 
930  if (switch_stristr("SONUS_SEND_INVALID_TIMESTAMP_2833", str)) {
932  }
933 
934  if (switch_stristr("~SONUS_SEND_INVALID_TIMESTAMP_2833", str)) {
936  }
937 
938  if (switch_stristr("IGNORE_MARK_BIT", str)) {
939  *flag_pole |= RTP_BUG_IGNORE_MARK_BIT;
940  }
941 
942  if (switch_stristr("~IGNORE_MARK_BIT", str)) {
943  *flag_pole &= ~RTP_BUG_IGNORE_MARK_BIT;
944  }
945 
946  if (switch_stristr("SEND_LINEAR_TIMESTAMPS", str)) {
947  *flag_pole |= RTP_BUG_SEND_LINEAR_TIMESTAMPS;
948  }
949 
950  if (switch_stristr("~SEND_LINEAR_TIMESTAMPS", str)) {
951  *flag_pole &= ~RTP_BUG_SEND_LINEAR_TIMESTAMPS;
952  }
953 
954  if (switch_stristr("START_SEQ_AT_ZERO", str)) {
955  *flag_pole |= RTP_BUG_START_SEQ_AT_ZERO;
956  }
957 
958  if (switch_stristr("~START_SEQ_AT_ZERO", str)) {
959  *flag_pole &= ~RTP_BUG_START_SEQ_AT_ZERO;
960  }
961 
962  if (switch_stristr("NEVER_SEND_MARKER", str)) {
963  *flag_pole |= RTP_BUG_NEVER_SEND_MARKER;
964  }
965 
966  if (switch_stristr("~NEVER_SEND_MARKER", str)) {
967  *flag_pole &= ~RTP_BUG_NEVER_SEND_MARKER;
968  }
969 
970  if (switch_stristr("IGNORE_DTMF_DURATION", str)) {
971  *flag_pole |= RTP_BUG_IGNORE_DTMF_DURATION;
972  }
973 
974  if (switch_stristr("~IGNORE_DTMF_DURATION", str)) {
975  *flag_pole &= ~RTP_BUG_IGNORE_DTMF_DURATION;
976  }
977 
978  if (switch_stristr("ACCEPT_ANY_PACKETS", str)) {
979  *flag_pole |= RTP_BUG_ACCEPT_ANY_PACKETS;
980  }
981 
982  if (switch_stristr("~ACCEPT_ANY_PACKETS", str)) {
983  *flag_pole &= ~RTP_BUG_ACCEPT_ANY_PACKETS;
984  }
985 
986  if (switch_stristr("ACCEPT_ANY_PAYLOAD", str)) {
987  *flag_pole |= RTP_BUG_ACCEPT_ANY_PAYLOAD;
988  }
989 
990  if (switch_stristr("~ACCEPT_ANY_PAYLOAD", str)) {
991  *flag_pole &= ~RTP_BUG_ACCEPT_ANY_PAYLOAD;
992  }
993 
994  if (switch_stristr("GEN_ONE_GEN_ALL", str)) {
995  *flag_pole |= RTP_BUG_GEN_ONE_GEN_ALL;
996  }
997 
998  if (switch_stristr("~GEN_ONE_GEN_ALL", str)) {
999  *flag_pole &= ~RTP_BUG_GEN_ONE_GEN_ALL;
1000  }
1001 
1002  if (switch_stristr("CHANGE_SSRC_ON_MARKER", str)) {
1003  *flag_pole |= RTP_BUG_CHANGE_SSRC_ON_MARKER;
1004  }
1005 
1006  if (switch_stristr("~CHANGE_SSRC_ON_MARKER", str)) {
1007  *flag_pole &= ~RTP_BUG_CHANGE_SSRC_ON_MARKER;
1008  }
1009 
1010  if (switch_stristr("FLUSH_JB_ON_DTMF", str)) {
1011  *flag_pole |= RTP_BUG_FLUSH_JB_ON_DTMF;
1012  }
1013 
1014  if (switch_stristr("~FLUSH_JB_ON_DTMF", str)) {
1015  *flag_pole &= ~RTP_BUG_FLUSH_JB_ON_DTMF;
1016  }
1017 
1018  if (switch_stristr("ALWAYS_AUTO_ADJUST", str)) {
1020  }
1021 
1022  if (switch_stristr("~ALWAYS_AUTO_ADJUST", str)) {
1024  }
1025 }
const char * switch_stristr(const char *instr, const char *str)
void switch_core_media_pass_zrtp_hash ( switch_core_session_t session)

Definition at line 387 of file switch_core_media.c.

References CF_ZRTP_PASSTHRU_REQ, SWITCH_CHANNEL_CHANNEL_LOG, switch_channel_test_flag(), switch_core_media_pass_zrtp_hash2(), switch_core_session_get_channel(), switch_core_session_get_partner, switch_core_session_rwunlock(), SWITCH_LOG_DEBUG1, switch_log_printf(), and SWITCH_STATUS_SUCCESS.

Referenced by switch_core_media_negotiate_sdp(), and switch_core_media_set_r_sdp_codec_string().

388 {
390 
391  switch_core_session_t *other_session;
392  switch_log_printf(SWITCH_CHANNEL_CHANNEL_LOG(channel), SWITCH_LOG_DEBUG1, "Deciding whether to pass zrtp-hash between legs\n");
394  switch_log_printf(SWITCH_CHANNEL_CHANNEL_LOG(channel), SWITCH_LOG_DEBUG1, "CF_ZRTP_PASSTHRU_REQ not set, so not propagating zrtp-hash\n");
395  return;
396  } else if (!(switch_core_session_get_partner(session, &other_session) == SWITCH_STATUS_SUCCESS)) {
397  switch_log_printf(SWITCH_CHANNEL_CHANNEL_LOG(channel), SWITCH_LOG_DEBUG1, "No partner channel found, so not propagating zrtp-hash\n");
398  return;
399  } else {
400  switch_log_printf(SWITCH_CHANNEL_CHANNEL_LOG(channel), SWITCH_LOG_DEBUG1, "Found peer channel; propagating zrtp-hash if set\n");
401  switch_core_media_pass_zrtp_hash2(session, other_session);
402  switch_core_session_rwunlock(other_session);
403  }
404 }
void switch_core_media_pass_zrtp_hash2(switch_core_session_t *aleg_session, switch_core_session_t *bleg_session)
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.
_Ret_ switch_channel_t * switch_core_session_get_channel(_In_ switch_core_session_t *session)
Retrieve a pointer to the channel object associated with a given session.
#define switch_core_session_get_partner(_session, _partner)
Definition: switch_core.h:1002
void switch_core_session_rwunlock(_In_ switch_core_session_t *session)
Unlock a read or write lock on as given session.
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_CHANNEL_CHANNEL_LOG(x)
void switch_core_media_pass_zrtp_hash2 ( switch_core_session_t aleg_session,
switch_core_session_t bleg_session 
)

Definition at line 380 of file switch_core_media.c.

References _switch_core_media_pass_zrtp_hash2(), SWITCH_MEDIA_TYPE_AUDIO, and SWITCH_MEDIA_TYPE_VIDEO.

Referenced by switch_core_media_pass_zrtp_hash().

381 {
382  _switch_core_media_pass_zrtp_hash2(aleg_session, bleg_session, SWITCH_MEDIA_TYPE_AUDIO);
383  _switch_core_media_pass_zrtp_hash2(aleg_session, bleg_session, SWITCH_MEDIA_TYPE_VIDEO);
384 }
static void _switch_core_media_pass_zrtp_hash2(switch_core_session_t *aleg_session, switch_core_session_t *bleg_session, switch_media_type_t type)
void switch_core_media_patch_sdp ( switch_core_session_t session)

Definition at line 8792 of file switch_core_media.c.

References switch_rtp_engine_s::adv_sdp_ip, switch_rtp_engine_s::adv_sdp_port, CF_ANSWERED, CF_REINVITE, CF_VIDEO_POSSIBLE, clear_pmaps(), switch_rtp_engine_s::codec_negotiated, switch_rtp_engine_s::cur_payload_map, switch_media_handle_s::engines, switch_rtp_engine_s::local_sdp_ip, switch_rtp_engine_s::local_sdp_port, switch_core_media_params_s::local_sdp_str, switch_media_handle_s::mparams, switch_core_media_params_s::ndlb, switch_media_handle_s::owner_id, switch_rtp_engine_s::rtp_session, SDP_TYPE_RESPONSE, switch_core_media_params_s::sdp_username, switch_media_handle_s::session_id, switch_core_media_params_s::sipip, SM_NDLB_NEVER_PATCH_REINVITE, switch_assert, switch_channel_down, switch_channel_get_name(), switch_channel_media_ready, SWITCH_CHANNEL_SESSION_LOG, switch_channel_set_flag, switch_channel_test_flag(), switch_core_media_activate_rtp(), switch_core_media_add_payload_map(), switch_core_media_choose_port(), switch_core_media_set_local_sdp(), switch_core_media_set_video_codec(), switch_core_session_alloc, switch_epoch_time_now(), SWITCH_FALSE, SWITCH_LOG_DEBUG, SWITCH_LOG_ERROR, switch_log_printf(), SWITCH_MEDIA_TYPE_AUDIO, SWITCH_MEDIA_TYPE_VIDEO, switch_rtp_ready(), switch_snprintf(), SWITCH_STATUS_SUCCESS, switch_stristr(), SWITCH_TRUE, and zstr.

8793 {
8794  switch_size_t len;
8795  char *p, *q, *pe, *qe;
8796  int has_video = 0, has_audio = 0, has_ip = 0;
8797  char port_buf[25] = "";
8798  char vport_buf[25] = "";
8799  char *new_sdp;
8800  int bad = 0;
8801  switch_media_handle_t *smh;
8802  switch_rtp_engine_t *a_engine, *v_engine;
8803  payload_map_t *pmap;
8804 
8805  switch_assert(session);
8806 
8807  if (!(smh = session->media_handle)) {
8808  return;
8809  }
8810 
8811  a_engine = &smh->engines[SWITCH_MEDIA_TYPE_AUDIO];
8812  v_engine = &smh->engines[SWITCH_MEDIA_TYPE_VIDEO];
8813 
8814  if (zstr(smh->mparams->local_sdp_str)) {
8815  return;
8816  }
8817 
8818  len = strlen(smh->mparams->local_sdp_str) * 2;
8819 
8820  if (!(smh->mparams->ndlb & SM_NDLB_NEVER_PATCH_REINVITE)) {
8821  if (switch_channel_test_flag(session->channel, CF_ANSWERED) &&
8822  (switch_stristr("sendonly", smh->mparams->local_sdp_str) || switch_stristr("0.0.0.0", smh->mparams->local_sdp_str))) {
8823  switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_DEBUG, "Skip patch on hold SDP\n");
8824  return;
8825  }
8826  }
8827 
8828  if (zstr(a_engine->local_sdp_ip) || !a_engine->local_sdp_port) {// || switch_channel_test_flag(session->channel, CF_PROXY_MEDIA)) {
8831  switch_channel_get_name(session->channel));
8832  return;
8833  }
8834 
8835  clear_pmaps(a_engine);
8836 
8837  pmap = switch_core_media_add_payload_map(session,
8839  "PROXY",
8840  NULL,
8841  NULL,
8843  0,
8844  8000,
8845  20,
8846  1,
8847  SWITCH_TRUE);
8848 
8849  a_engine->cur_payload_map = pmap;
8850 
8851  }
8852 
8853  new_sdp = switch_core_session_alloc(session, len);
8854  switch_snprintf(port_buf, sizeof(port_buf), "%u", a_engine->local_sdp_port);
8855 
8856 
8857  p = smh->mparams->local_sdp_str;
8858  q = new_sdp;
8859  pe = p + strlen(p);
8860  qe = q + len - 1;
8861 
8862 
8863  while (p && *p) {
8864  if (p >= pe) {
8865  bad = 1;
8866  goto end;
8867  }
8868 
8869  if (q >= qe) {
8870  bad = 2;
8871  goto end;
8872  }
8873 
8874  if (a_engine->local_sdp_ip && !strncmp("c=IN IP", p, 7)) {
8875  strncpy(q, p, 7);
8876  p += 7;
8877  q += 7;
8878  strncpy(q, strchr(a_engine->adv_sdp_ip, ':') ? "6 " : "4 ", 2);
8879  p +=2;
8880  q +=2;
8881  strncpy(q, a_engine->adv_sdp_ip, strlen(a_engine->adv_sdp_ip));
8882  q += strlen(a_engine->adv_sdp_ip);
8883 
8884  while (p && *p && ((*p >= '0' && *p <= '9') || *p == '.' || *p == ':' || (*p >= 'A' && *p <= 'F') || (*p >= 'a' && *p <= 'f'))) {
8885  if (p >= pe) {
8886  bad = 3;
8887  goto end;
8888  }
8889  p++;
8890  }
8891 
8892  has_ip++;
8893 
8894  } else if (!strncmp("o=", p, 2)) {
8895  char *oe = strchr(p, '\n');
8896  switch_size_t len;
8897 
8898  if (oe) {
8899  const char *family = "IP4";
8900  char o_line[1024] = "";
8901 
8902  if (oe >= pe) {
8903  bad = 5;
8904  goto end;
8905  }
8906 
8907  len = (oe - p);
8908  p += len;
8909 
8910 
8911  family = strchr(smh->mparams->sipip, ':') ? "IP6" : "IP4";
8912 
8913  if (!smh->owner_id) {
8914  smh->owner_id = (uint32_t) switch_epoch_time_now(NULL) * 31821U + 13849U;
8915  }
8916 
8917  if (!smh->session_id) {
8918  smh->session_id = smh->owner_id;
8919  }
8920 
8921  smh->session_id++;
8922 
8923 
8924  snprintf(o_line, sizeof(o_line), "o=%s %010u %010u IN %s %s\r\n",
8925  smh->mparams->sdp_username, smh->owner_id, smh->session_id, family, smh->mparams->sipip);
8926 
8927  strncpy(q, o_line, strlen(o_line));
8928  q += strlen(o_line) - 1;
8929 
8930  }
8931 
8932  } else if (!strncmp("s=", p, 2)) {
8933  char *se = strchr(p, '\n');
8934  switch_size_t len;
8935 
8936  if (se) {
8937  char s_line[1024] = "";
8938 
8939  if (se >= pe) {
8940  bad = 5;
8941  goto end;
8942  }
8943 
8944  len = (se - p);
8945  p += len;
8946 
8947  snprintf(s_line, sizeof(s_line), "s=%s\r\n", smh->mparams->sdp_username);
8948 
8949  strncpy(q, s_line, strlen(s_line));
8950  q += strlen(s_line) - 1;
8951 
8952  }
8953 
8954  } else if ((!strncmp("m=audio ", p, 8) && *(p + 8) != '0') || (!strncmp("m=image ", p, 8) && *(p + 8) != '0')) {
8955  strncpy(q, p, 8);
8956  p += 8;
8957 
8958  if (p >= pe) {
8959  bad = 4;
8960  goto end;
8961  }
8962 
8963 
8964  q += 8;
8965 
8966  if (q >= qe) {
8967  bad = 5;
8968  goto end;
8969  }
8970 
8971 
8972  strncpy(q, port_buf, strlen(port_buf));
8973  q += strlen(port_buf);
8974 
8975  if (q >= qe) {
8976  bad = 6;
8977  goto end;
8978  }
8979 
8980  while (p && *p && (*p >= '0' && *p <= '9')) {
8981  if (p >= pe) {
8982  bad = 7;
8983  goto end;
8984  }
8985  p++;
8986  }
8987 
8988  has_audio++;
8989 
8990  } else if (!strncmp("m=video ", p, 8) && *(p + 8) != '0') {
8991  if (!has_video) {
8993  clear_pmaps(v_engine);
8994  pmap = switch_core_media_add_payload_map(session,
8996  "PROXY-VID",
8997  NULL,
8998  NULL,
9000  0,
9001  90000,
9002  90000,
9003  1,
9004  SWITCH_TRUE);
9005  v_engine->cur_payload_map = pmap;
9006 
9007  switch_snprintf(vport_buf, sizeof(vport_buf), "%u", v_engine->adv_sdp_port);
9008 
9009  if (switch_channel_media_ready(session->channel) && !switch_rtp_ready(v_engine->rtp_session)) {
9013  }
9014 
9015  v_engine->codec_negotiated = 1;
9017  }
9018 
9019  strncpy(q, p, 8);
9020  p += 8;
9021 
9022  if (p >= pe) {
9023  bad = 8;
9024  goto end;
9025  }
9026 
9027  q += 8;
9028 
9029  if (q >= qe) {
9030  bad = 9;
9031  goto end;
9032  }
9033 
9034  strncpy(q, vport_buf, strlen(vport_buf));
9035  q += strlen(vport_buf);
9036 
9037  if (q >= qe) {
9038  bad = 10;
9039  goto end;
9040  }
9041 
9042  while (p && *p && (*p >= '0' && *p <= '9')) {
9043 
9044  if (p >= pe) {
9045  bad = 11;
9046  goto end;
9047  }
9048 
9049  p++;
9050  }
9051 
9052  has_video++;
9053  }
9054 
9055  while (p && *p && *p != '\n') {
9056 
9057  if (p >= pe) {
9058  bad = 12;
9059  goto end;
9060  }
9061 
9062  if (q >= qe) {
9063  bad = 13;
9064  goto end;
9065  }
9066 
9067  *q++ = *p++;
9068  }
9069 
9070  if (p >= pe) {
9071  bad = 14;
9072  goto end;
9073  }
9074 
9075  if (q >= qe) {
9076  bad = 15;
9077  goto end;
9078  }
9079 
9080  *q++ = *p++;
9081 
9082  }
9083 
9084  end:
9085 
9086  if (bad) {
9087  return;
9088  }
9089 
9090 
9091  if (switch_channel_down(session->channel)) {
9093  return;
9094  }
9095 
9096 
9097  if (!has_ip && !has_audio) {
9098  switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_DEBUG, "%s SDP has no audio in it.\n%s\n",
9100  return;
9101  }
9102 
9103 
9104  switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_DEBUG, "%s Patched SDP\n---\n%s\n+++\n%s\n",
9105  switch_channel_get_name(session->channel), smh->mparams->local_sdp_str, new_sdp);
9106 
9107  switch_core_media_set_local_sdp(session, new_sdp, SWITCH_FALSE);
9108 
9109 }
#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)
static void clear_pmaps(switch_rtp_engine_t *engine)
#define switch_channel_media_ready(_channel)
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.
switch_media_handle_t * media_handle
#define zstr(x)
Definition: switch_utils.h:281
void switch_core_media_set_local_sdp(switch_core_session_t *session, const char *sdp_str, switch_bool_t dup)
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
switch_rtp_t * rtp_session
payload_map_t * cur_payload_map
uintptr_t switch_size_t
switch_port_t local_sdp_port
switch_status_t switch_core_media_activate_rtp(switch_core_session_t *session)
#define switch_channel_down(_channel)
switch_rtp_engine_t engines[SWITCH_MEDIA_TYPE_TOTAL]
switch_port_t adv_sdp_port
#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)
time_t switch_epoch_time_now(time_t *t)
Get the current epoch time.
Definition: switch_time.c:321
switch_core_media_NDLB_t ndlb
#define switch_core_session_alloc(_session, _memory)
Allocate memory from a session's pool.
Definition: switch_core.h:694
void switch_log_printf(_In_ switch_text_channel_t channel, _In_z_ const char *file, _In_z_ const char *func, _In_ int line, _In_opt_z_ const char *userdata, _In_ switch_log_level_t level, _In_z_ _Printf_format_string_ const char *fmt,...) PRINTF_FUNCTION(7
Write log data to the logging engine.
const char * switch_stristr(const char *instr, const char *str)
#define switch_assert(expr)
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_pause ( switch_core_session_t session)

Definition at line 3037 of file switch_core_media.c.

References switch_media_handle_s::engines, switch_rtp_engine_s::rtp_session, switch_assert, SWITCH_MEDIA_TYPE_AUDIO, SWITCH_MEDIA_TYPE_VIDEO, SWITCH_RTP_FLAG_PAUSE, and switch_rtp_set_flag().

3038 {
3039  switch_rtp_engine_t *a_engine, *v_engine;
3040  switch_media_handle_t *smh;
3041 
3042  switch_assert(session);
3043 
3044  if (!(smh = session->media_handle)) {
3045  return;
3046  }
3047 
3048  a_engine = &smh->engines[SWITCH_MEDIA_TYPE_AUDIO];
3049  v_engine = &smh->engines[SWITCH_MEDIA_TYPE_VIDEO];
3050 
3051  if (a_engine->rtp_session) {
3053  }
3054 
3055  if (v_engine->rtp_session) {
3057  }
3058 }
switch_media_handle_t * media_handle
switch_rtp_t * rtp_session
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)
void switch_core_media_prepare_codecs ( switch_core_session_t session,
switch_bool_t  force 
)

Definition at line 1799 of file switch_core_media.c.

References CF_PROXY_MEDIA, CF_PROXY_MODE, switch_media_handle_s::codec_order, switch_media_handle_s::codec_order_last, switch_media_handle_s::codecs, switch_media_handle_s::media_flags, switch_media_handle_s::mparams, switch_core_media_params_s::num_codecs, switch_media_handle_s::payload_space, SCMF_DISABLE_TRANSCODING, switch_media_handle_s::session, switch_assert, switch_channel_get_variable, switch_channel_get_variable_dup(), switch_channel_set_variable, switch_channel_test_flag(), switch_core_media_get_codec_string(), switch_core_session_sprintf(), switch_core_session_strdup, SWITCH_FALSE, switch_loadable_module_get_codecs_sorted(), SWITCH_MAX_CODECS, SWITCH_ORIGINATOR_CODEC_VARIABLE, switch_separate_string(), and switch_true().

Referenced by switch_core_media_negotiate_sdp(), and switch_core_media_receive_message().

1800 {
1801  const char *abs, *codec_string = NULL;
1802  const char *ocodec = NULL, *val;
1803  switch_media_handle_t *smh;
1804  char *tmp_codec_string;
1805 
1806  switch_assert(session);
1807 
1808  if (!(smh = session->media_handle)) {
1809  return;
1810  }
1811 
1813  return;
1814  }
1815 
1816  if (force) {
1817  smh->mparams->num_codecs = 0;
1818  }
1819 
1820  if (smh->mparams->num_codecs) {
1821  return;
1822  }
1823 
1824  smh->payload_space = 0;
1825 
1826  switch_assert(smh->session != NULL);
1827 
1828  if ((abs = switch_channel_get_variable(session->channel, "absolute_codec_string"))) {
1829  codec_string = abs;
1830  goto ready;
1831  }
1832 
1833  val = switch_channel_get_variable_dup(session->channel, "media_mix_inbound_outbound_codecs", SWITCH_FALSE, -1);
1834  if (!val || !switch_true(val)) {
1836  codec_string = ocodec;
1837  goto ready;
1838  }
1839  }
1840 
1841  if (!(codec_string = switch_channel_get_variable(session->channel, "codec_string"))) {
1842  codec_string = switch_core_media_get_codec_string(smh->session);
1843  }
1844 
1845  if (codec_string && *codec_string == '=') {
1846  codec_string++;
1847  goto ready;
1848  }
1849 
1850  if (ocodec) {
1851  if (!codec_string || (smh->media_flags[SCMF_DISABLE_TRANSCODING])) {
1852  codec_string = ocodec;
1853  } else {
1854  if (!(codec_string = switch_core_session_sprintf(smh->session, "%s,%s", ocodec, codec_string))) {
1855  codec_string = ocodec;
1856  }
1857  }
1858  }
1859 
1860  ready:
1861 
1862  if (!codec_string) {
1863  codec_string = "PCMU@20i,PCMA@20i,speex@20i";
1864  }
1865 
1866  tmp_codec_string = switch_core_session_strdup(smh->session, codec_string);
1867  switch_channel_set_variable(session->channel, "rtp_use_codec_string", codec_string);
1868  smh->codec_order_last = switch_separate_string(tmp_codec_string, ',', smh->codec_order, SWITCH_MAX_CODECS);
1870 
1871 }
#define SWITCH_MAX_CODECS
Definition: switch_types.h:558
char * switch_core_session_sprintf(_In_ switch_core_session_t *session, _In_z_ _Printf_format_string_ const char *fmt,...)
printf-style style printing routine. The data is output to a string allocated from the session ...
switch_core_media_flag_t media_flags[SCMF_MAX]
const switch_codec_implementation_t * codecs[SWITCH_MAX_CODECS]
const char * switch_channel_get_variable_dup(switch_channel_t *channel, const char *varname, switch_bool_t dup, int idx)
Retrieve a variable from a given channel.
static 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
#define SWITCH_ORIGINATOR_CODEC_VARIABLE
Definition: switch_types.h:205
unsigned int switch_separate_string(_In_ char *buf, char delim, _Post_count_(return) char **array, unsigned int arraylen)
Separate a string into an array based on a character delimiter.
switch_channel_t * channel
#define switch_channel_get_variable(_c, _v)
switch_core_session_t * session
int switch_loadable_module_get_codecs_sorted(const switch_codec_implementation_t **array, int arraylen, char **prefs, int preflen)
Retrieve the list of loaded codecs into an array based on another array showing the sorted order...
const char * switch_core_media_get_codec_string(switch_core_session_t *session)
#define switch_core_session_strdup(_session, _todup)
Copy a string using memory allocation from a session's pool.
Definition: switch_core.h:717
char * codec_order[SWITCH_MAX_CODECS]
#define switch_assert(expr)
#define switch_channel_set_variable(_channel, _var, _val)
switch_core_media_params_t * mparams
char* switch_core_media_process_sdp_filter ( const char *  sdp,
const char *  cmd_buf,
switch_core_session_t session 
)

Definition at line 10841 of file switch_core_media.c.

References SWITCH_CHANNEL_CHANNEL_LOG, switch_channel_get_name(), switch_core_media_filter_sdp(), switch_core_session_get_channel(), switch_core_session_strdup, switch_find_end_paren(), SWITCH_LOG_DEBUG, switch_log_printf(), SWITCH_LOG_WARNING, switch_safe_free, switch_split, and zstr.

Referenced by switch_channel_pass_sdp().

10842 {
10844  char *cmd = switch_core_session_strdup(session, cmd_buf);
10845  int argc = 0;
10846  char *argv[50];
10847  int x = 0;
10848  char *patched_sdp = NULL;
10849 
10850  argc = switch_split(cmd, '|', argv);
10851 
10852  for (x = 0; x < argc; x++) {
10853  char *command = argv[x];
10854  char *arg = strchr(command, '(');
10855 
10856  if (arg) {
10857  char *e = switch_find_end_paren(arg, '(', ')');
10858  *arg++ = '\0';
10859  if (e) *e = '\0';
10860  }
10861 
10862  if (zstr(command) || zstr(arg)) {
10863  switch_log_printf(SWITCH_CHANNEL_CHANNEL_LOG(channel), SWITCH_LOG_WARNING, "%s SDP FILTER PARSE ERROR\n", switch_channel_get_name(channel));
10864  } else {
10865  char *tmp_sdp = NULL;
10866 
10867  if (patched_sdp) {
10868  tmp_sdp = switch_core_media_filter_sdp(patched_sdp, command, arg);
10869  } else {
10870  tmp_sdp = switch_core_media_filter_sdp(sdp, command, arg);
10871  }
10872 
10873 
10875  "%s Filter command %s(%s)\nFROM:\n==========\n%s\nTO:\n==========\n%s\n\n",
10876  switch_channel_get_name(channel),
10877  command, arg, patched_sdp ? patched_sdp : sdp, tmp_sdp);
10878 
10879 
10880  if (tmp_sdp) {
10881  switch_safe_free(patched_sdp);
10882  patched_sdp = tmp_sdp;
10883  }
10884  }
10885  }
10886 
10887  return patched_sdp;
10888 
10889 }
char * switch_find_end_paren(const char *s, char open, char close)
Definition: switch_utils.c:661
#define switch_split(_data, _delim, _array)
Definition: switch_utils.h:342
#define zstr(x)
Definition: switch_utils.h:281
_Ret_ switch_channel_t * switch_core_session_get_channel(_In_ switch_core_session_t *session)
Retrieve a pointer to the channel object associated with a given session.
#define switch_safe_free(it)
Free a pointer and set it to NULL unless it already is NULL.
Definition: switch_utils.h:789
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
char * switch_core_media_filter_sdp(const char *sdp_str, const char *cmd, const char *arg)
char * switch_channel_get_name(switch_channel_t *channel)
Retrieve the name of a given channel.
#define SWITCH_CHANNEL_CHANNEL_LOG(x)
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 
)

Definition at line 616 of file switch_core_media.c.

References switch_rtp_engine_s::cur_payload_map, switch_media_handle_s::engines, payload_map_s::remote_sdp_ip, payload_map_s::remote_sdp_port, switch_rtp_engine_s::rtp_session, switch_assert, SWITCH_CAUSE_INCOMPATIBLE_DESTINATION, switch_channel_get_name(), switch_channel_hangup, SWITCH_CHANNEL_SESSION_LOG, switch_channel_set_variable, switch_core_media_copy_t38_options(), switch_core_session_strdup, SWITCH_LOG_DEBUG, SWITCH_LOG_ERROR, switch_log_printf(), SWITCH_MEDIA_TYPE_AUDIO, SWITCH_REMOTE_MEDIA_IP_VARIABLE, SWITCH_REMOTE_MEDIA_PORT_VARIABLE, switch_rtp_get_remote_host(), switch_rtp_get_remote_port(), switch_rtp_set_remote_address(), switch_snprintf(), SWITCH_STATUS_FALSE, SWITCH_STATUS_SUCCESS, and SWITCH_TRUE.

618 {
619  char *remote_host;
620  switch_port_t remote_port;
621  char tmp[32] = "";
622  switch_rtp_engine_t *a_engine;
624 
625  switch_assert(session);
626 
627  if (!(smh = session->media_handle)) {
628  return SWITCH_STATUS_FALSE;
629  }
630 
631  a_engine = &smh->engines[SWITCH_MEDIA_TYPE_AUDIO];
632 
633  remote_host = switch_rtp_get_remote_host(a_engine->rtp_session);
634  remote_port = switch_rtp_get_remote_port(a_engine->rtp_session);
635 
636  a_engine->cur_payload_map->remote_sdp_ip = switch_core_session_strdup(session, t38_options->remote_ip);
637  a_engine->cur_payload_map->remote_sdp_port = t38_options->remote_port;
638 
639  if (remote_host && remote_port && !strcmp(remote_host, a_engine->cur_payload_map->remote_sdp_ip) &&
640  remote_port == a_engine->cur_payload_map->remote_sdp_port) {
642  "Audio params are unchanged for %s.\n",
643  switch_channel_get_name(session->channel));
644  } else {
645  const char *err = NULL;
646 
648  "Audio params changed for %s from %s:%d to %s:%d\n",
650  remote_host, remote_port, a_engine->cur_payload_map->remote_sdp_ip, a_engine->cur_payload_map->remote_sdp_port);
651 
652  switch_snprintf(tmp, sizeof(tmp), "%d", a_engine->cur_payload_map->remote_sdp_port);
657  switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_ERROR, "AUDIO RTP REPORTS ERROR: [%s]\n", err);
659  }
660  }
661 
662  switch_core_media_copy_t38_options(t38_options, other_session);
663 
664  return SWITCH_STATUS_SUCCESS;
665 
666 }
#define switch_channel_hangup(channel, hangup_cause)
Hangup a channel flagging it's state machine to end.
#define SWITCH_CHANNEL_SESSION_LOG(x)
char * remote_sdp_ip
int switch_snprintf(_Out_z_cap_(len) char *buf, _In_ switch_size_t len, _In_z_ _Printf_format_string_ const char *format,...)
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 SWITCH_REMOTE_MEDIA_IP_VARIABLE
Definition: switch_types.h:210
switch_channel_t * channel
switch_rtp_t * rtp_session
payload_map_t * cur_payload_map
uint16_t switch_port_t
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
void switch_core_media_copy_t38_options(switch_t38_options_t *t38_options, switch_core_session_t *session)
char * switch_rtp_get_remote_host(switch_rtp_t *rtp_session)
Definition: switch_rtp.c:2822
switch_rtp_engine_t engines[SWITCH_MEDIA_TYPE_TOTAL]
const char * remote_ip
#define SWITCH_REMOTE_MEDIA_PORT_VARIABLE
Definition: switch_types.h:211
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
#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)
char * switch_channel_get_name(switch_channel_t *channel)
Retrieve the name of a given channel.
switch_status_t switch_core_media_proxy_remote_addr ( switch_core_session_t session,
const char *  sdp_str 
)

Definition at line 5613 of file switch_core_media.c.

References CF_AVPF, CF_PROXY_MODE, CF_VIDEO, CF_VIDEO_POSSIBLE, switch_rtp_engine_s::check_frames, switch_rtp_engine_s::cur_payload_map, switch_media_handle_s::engines, switch_media_handle_s::mparams, RA_PTR_LEN, switch_rtp_engine_s::remote_rtcp_port, payload_map_s::remote_sdp_ip, payload_map_s::remote_sdp_port, switch_core_media_params_s::remote_sdp_str, switch_rtp_engine_s::rtp_session, SCMF_AUTOFIX_TIMING, SCMF_DISABLE_RTP_AUTOADJ, switch_assert, switch_channel_get_variable, SWITCH_CHANNEL_SESSION_LOG, switch_channel_set_flag, switch_channel_test_flag(), switch_core_session_strdup, switch_goto_status, SWITCH_LOG_DEBUG, SWITCH_LOG_ERROR, switch_log_printf(), switch_media_handle_test_media_flag(), SWITCH_MEDIA_TYPE_AUDIO, SWITCH_MEDIA_TYPE_VIDEO, SWITCH_RTP_FLAG_AUTOADJ, switch_rtp_get_remote_host(), switch_rtp_get_remote_port(), switch_rtp_ready(), switch_rtp_set_flag(), switch_rtp_set_remote_address(), SWITCH_STATUS_BREAK, SWITCH_STATUS_FALSE, SWITCH_STATUS_GENERR, SWITCH_STATUS_SUCCESS, switch_stristr(), SWITCH_TRUE, switch_true(), and zstr.

Referenced by switch_core_media_activate_rtp().

5614 {
5615  const char *err;
5616  char rip[RA_PTR_LEN] = "";
5617  char rp[RA_PTR_LEN] = "";
5618  char rvp[RA_PTR_LEN] = "";
5619  char *p, *ip_ptr = NULL, *port_ptr = NULL, *vid_port_ptr = NULL, *pe;
5620  int x;
5621  const char *val;
5623  switch_rtp_engine_t *a_engine, *v_engine;
5624  switch_media_handle_t *smh;
5625 
5626  switch_assert(session);
5627 
5628  if (!(smh = session->media_handle)) {
5629  return SWITCH_STATUS_FALSE;
5630  }
5631 
5632  a_engine = &smh->engines[SWITCH_MEDIA_TYPE_AUDIO];
5633  v_engine = &smh->engines[SWITCH_MEDIA_TYPE_VIDEO];
5634 
5635  if (zstr(sdp_str)) {
5636  sdp_str = smh->mparams->remote_sdp_str;
5637  }
5638 
5639  if (zstr(sdp_str)) {
5640  goto end;
5641  }
5642 
5643  if ((p = (char *) switch_stristr("c=IN IP4 ", sdp_str)) || (p = (char *) switch_stristr("c=IN IP6 ", sdp_str))) {
5644  ip_ptr = p + 9;
5645  }
5646 
5647  if ((p = (char *) switch_stristr("m=audio ", sdp_str))) {
5648  port_ptr = p + 8;
5649  }
5650 
5651  if ((p = (char *) switch_stristr("m=image ", sdp_str))) {
5652  char *tmp = p + 8;
5653 
5654  if (tmp && atoi(tmp)) {
5655  port_ptr = tmp;
5656  }
5657  }
5658 
5659  if ((p = (char *) switch_stristr("m=video ", sdp_str))) {
5660  vid_port_ptr = p + 8;
5661  }
5662 
5663  if (!(ip_ptr && port_ptr)) {
5664  goto end;
5665  }
5666 
5667  p = ip_ptr;
5668  pe = p + strlen(p);
5669  x = 0;
5670  while (x < sizeof(rip) - 1 && p && *p && ((*p >= '0' && *p <= '9') || *p == '.' || *p == ':' || (*p >= 'a' && *p <= 'f') || (*p >= 'A' && *p <= 'F'))) {
5671  rip[x++] = *p;
5672  p++;
5673  if (p >= pe) {
5674  goto end;
5675  }
5676  }
5677 
5678  p = port_ptr;
5679  x = 0;
5680  while (x < sizeof(rp) - 1 && p && *p && (*p >= '0' && *p <= '9')) {
5681  rp[x++] = *p;
5682  p++;
5683  if (p >= pe) {
5684  goto end;
5685  }
5686  }
5687 
5688  p = vid_port_ptr;
5689  x = 0;
5690  while (x < sizeof(rvp) - 1 && p && *p && (*p >= '0' && *p <= '9')) {
5691  rvp[x++] = *p;
5692  p++;
5693  if (p >= pe) {
5694  goto end;
5695  }
5696  }
5697 
5698  if (!(*rip && *rp)) {
5700  goto end;
5701  }
5702 
5703  a_engine->cur_payload_map->remote_sdp_ip = switch_core_session_strdup(session, rip);
5704  a_engine->cur_payload_map->remote_sdp_port = (switch_port_t) atoi(rp);
5705 
5706  if (*rvp) {
5707  v_engine->cur_payload_map->remote_sdp_ip = switch_core_session_strdup(session, rip);
5708  v_engine->cur_payload_map->remote_sdp_port = (switch_port_t) atoi(rvp);
5711  }
5712 
5713  if (v_engine->cur_payload_map->remote_sdp_ip && v_engine->cur_payload_map->remote_sdp_port) {
5714  if (!strcmp(v_engine->cur_payload_map->remote_sdp_ip, rip) && atoi(rvp) == v_engine->cur_payload_map->remote_sdp_port) {
5715  switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_DEBUG, "Remote video address:port [%s:%d] has not changed.\n",
5717  } else {
5720  if (switch_rtp_ready(v_engine->rtp_session)) {
5721  const char *rport = NULL;
5722  switch_port_t remote_rtcp_port = v_engine->remote_rtcp_port;
5723 
5724  if (!remote_rtcp_port) {
5725  if ((rport = switch_channel_get_variable(session->channel, "rtp_remote_video_rtcp_port"))) {
5726  remote_rtcp_port = (switch_port_t)atoi(rport);
5727  }
5728  }
5729 
5730 
5732  v_engine->cur_payload_map->remote_sdp_port, remote_rtcp_port, SWITCH_TRUE, &err) != SWITCH_STATUS_SUCCESS) {
5733  switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_ERROR, "VIDEO RTP REPORTS ERROR: [%s]\n", err);
5734  } else {
5735  switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_DEBUG, "VIDEO RTP CHANGING DEST TO: [%s:%d]\n",
5738  !((val = switch_channel_get_variable(session->channel, "disable_rtp_auto_adjust")) && switch_true(val)) &&
5740  /* Reactivate the NAT buster flag. */
5742  }
5744  v_engine->check_frames = 0;
5745  }
5746  }
5747  }
5748  }
5749  }
5750 
5751  if (switch_rtp_ready(a_engine->rtp_session)) {
5752  char *remote_host = switch_rtp_get_remote_host(a_engine->rtp_session);
5753  switch_port_t remote_port = switch_rtp_get_remote_port(a_engine->rtp_session);
5754  const char *rport = NULL;
5755  switch_port_t remote_rtcp_port = 0;
5756 
5757  if (remote_host && remote_port && !strcmp(remote_host, a_engine->cur_payload_map->remote_sdp_ip) && remote_port == a_engine->cur_payload_map->remote_sdp_port) {
5758  switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_DEBUG, "Remote address:port [%s:%d] has not changed.\n",
5761  } else if (remote_host && ( (strcmp(remote_host, "0.0.0.0") == 0) ||
5762  (strcmp(a_engine->cur_payload_map->remote_sdp_ip, "0.0.0.0") == 0))) {
5763 
5765  "Remote address changed from [%s] to [%s]. Ignoring...\n",
5766  a_engine->cur_payload_map->remote_sdp_ip, remote_host);
5768  }
5769 
5770  if ((rport = switch_channel_get_variable(session->channel, "rtp_remote_audio_rtcp_port"))) {
5771  remote_rtcp_port = (switch_port_t)atoi(rport);
5772  }
5773 
5774 
5776  a_engine->cur_payload_map->remote_sdp_port, remote_rtcp_port, SWITCH_TRUE, &err) != SWITCH_STATUS_SUCCESS) {
5777  switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_ERROR, "AUDIO RTP REPORTS ERROR: [%s]\n", err);
5778  status = SWITCH_STATUS_GENERR;
5779  } else {
5780  switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_DEBUG, "AUDIO RTP CHANGING DEST TO: [%s:%d]\n",
5783  !((val = switch_channel_get_variable(session->channel, "disable_rtp_auto_adjust")) && switch_true(val)) &&
5785  /* Reactivate the NAT buster flag. */
5787  }
5789  a_engine->check_frames = 0;
5790  }
5791  status = SWITCH_STATUS_SUCCESS;
5792  }
5793  }
5794 
5795  end:
5796 
5797  return status;
5798 }
#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
char * remote_sdp_ip
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_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
switch_channel_t * channel
switch_rtp_t * rtp_session
#define switch_channel_get_variable(_c, _v)
payload_map_t * cur_payload_map
uint16_t switch_port_t
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
#define RA_PTR_LEN
void switch_rtp_set_flag(switch_rtp_t *rtp_session, switch_rtp_flag_t flag)
Set an RTP Flag.
Definition: switch_rtp.c:4702
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]
#define switch_goto_status(_status, _label)
Definition: switch_utils.h:256
#define switch_channel_set_flag(_c, _f)
switch_port_t remote_rtcp_port
void switch_log_printf(_In_ switch_text_channel_t channel, _In_z_ const char *file, _In_z_ const char *func, _In_ int line, _In_opt_z_ const char *userdata, _In_ switch_log_level_t level, _In_z_ _Printf_format_string_ const char *fmt,...) PRINTF_FUNCTION(7
Write log data to the logging engine.
const char * switch_stristr(const char *instr, const char *str)
switch_port_t remote_sdp_port
#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_core_media_params_t * mparams
switch_status_t switch_core_media_queue_rfc2833 ( switch_core_session_t session,
switch_media_type_t  type,
const switch_dtmf_t dtmf 
)

Definition at line 9781 of file switch_core_media.c.

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

9782 {
9783  switch_media_handle_t *smh;
9784 
9785  switch_assert(session);
9786 
9787  if (!(smh = session->media_handle)) {
9788  return SWITCH_STATUS_FALSE;
9789  }
9790 
9791  if (switch_rtp_ready(smh->engines[type].rtp_session)) {
9792  return switch_rtp_queue_rfc2833(smh->engines[type].rtp_session, dtmf);
9793  }
9794 
9795  return SWITCH_STATUS_FALSE;
9796 }
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]
switch_status_t switch_rtp_queue_rfc2833(switch_rtp_t *rtp_session, const switch_dtmf_t *dtmf)
Queue RFC2833 DTMF data into an RTP Session.
Definition: switch_rtp.c:6935
#define switch_assert(expr)
switch_status_t switch_core_media_queue_rfc2833_in ( switch_core_session_t session,
switch_media_type_t  type,
const switch_dtmf_t dtmf 
)

Definition at line 9799 of file switch_core_media.c.

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

9800 {
9801  switch_media_handle_t *smh;
9802 
9803  switch_assert(session);
9804 
9805  if (!(smh = session->media_handle)) {
9806  return SWITCH_STATUS_FALSE;
9807  }
9808 
9809  if (switch_rtp_ready(smh->engines[type].rtp_session)) {
9810  return switch_rtp_queue_rfc2833_in(smh->engines[type].rtp_session, dtmf);
9811  }
9812 
9813  return SWITCH_STATUS_FALSE;
9814 }
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]
switch_status_t switch_rtp_queue_rfc2833_in(switch_rtp_t *rtp_session, const switch_dtmf_t *dtmf)
Queue RFC2833 DTMF data into an RTP Session.
Definition: switch_rtp.c:6961
#define switch_assert(expr)
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 
)

Definition at line 2138 of file switch_core_media.c.

References payload_map_s::agreed_pt, CF_LEG_HOLDING, CF_NOT_READY, switch_rtp_engine_s::check_frames, check_jb(), check_jb_sync(), switch_core_media_params_s::cng_pt, switch_core_media_params_s::codec_flags, payload_map_s::codec_ms, switch_rtp_engine_s::codec_negotiated, switch_rtp_engine_s::cur_payload_map, payload_map_s::current, switch_frame::datalen, switch_rtcp_report_block_frame::dlsr, switch_codec_implementation::encoded_bytes_per_packet, switch_media_handle_s::engines, switch_frame::flags, switch_rtcp_report_block_frame::fraction, switch_rtcp_report_block_frame::highest_sequence_number_received, payload_map_s::iananame, switch_frame::img, switch_codec::implementation, switch_rtcp_report_block_frame::jitter, switch_rtp_engine_s::last_codec_ms, switch_rtp_engine_s::last_seq, switch_rtp_engine_s::last_ts, switch_rtcp_report_block_frame::loss_avg, switch_rtcp_report_block_frame::lost, switch_rtcp_report_block_frame::lsr, switch_frame::m, MAX_CODEC_CHECK_FRAMES, MAX_MISMATCH_FRAMES, switch_rtp_engine_s::max_missed_hold_packets, switch_rtp_engine_s::max_missed_packets, switch_media_handle_s::media_flags, memset(), switch_rtp_engine_s::mismatch_count, switch_media_handle_s::mparams, payload_map_s::negotiated, payload_map_s::next, switch_rtcp_frame::ntp_lsw, switch_rtcp_frame::ntp_msw, switch_rtcp_frame::octect_count, switch_rtcp_frame::packet_count, switch_frame::payload, switch_rtp_engine_s::payload_map, payload_map_s::pt, switch_frame::rate, switch_rtp_engine_s::read_codec, switch_rtp_engine_s::read_frame, switch_rtp_engine_s::read_impl, switch_media_handle_s::read_mutex, payload_map_s::recv_pt, switch_core_media_params_s::recv_te, switch_rtcp_frame::report_count, switch_rtcp_frame::reports, switch_rtp_engine_s::reset_codec, switch_rtp_engine_s::rtp_session, switch_frame::samples, switch_codec_implementation::samples_per_packet, switch_codec_implementation::samples_per_second, SCMF_AUTOFIX_TIMING, SCMF_RUNNING, switch_media_handle_s::sdp_mutex, switch_frame::seq, SFF_CNG, SFF_NONE, SFF_PROXY_PACKET, skip(), switch_rtcp_report_block_frame::ssrc, switch_rtcp_frame::ssrc, switch_assert, SWITCH_CAUSE_MEDIA_TIMEOUT, switch_channel_execute_on(), switch_channel_get_name(), switch_channel_get_variable, switch_channel_hangup, switch_channel_queue_dtmf(), SWITCH_CHANNEL_SESSION_LOG, switch_channel_set_variable_printf(), switch_channel_test_flag(), switch_channel_up_nosig, switch_core_codec_ready(), switch_core_media_get_video_fps(), switch_core_media_set_codec(), switch_core_media_set_video_codec(), switch_core_session_get_uuid(), switch_epoch_time_now(), switch_event_add_header_string(), switch_event_create, switch_event_fire, SWITCH_EVENT_RECV_RTCP_MESSAGE, SWITCH_FALSE, switch_goto_status, SWITCH_LOG_DEBUG, SWITCH_LOG_DEBUG1, SWITCH_LOG_DEBUG10, switch_log_printf(), SWITCH_LOG_WARNING, SWITCH_MEDIA_TYPE_AUDIO, SWITCH_MEDIA_TYPE_VIDEO, switch_mutex_lock(), switch_mutex_trylock(), switch_mutex_unlock(), switch_rtcp_zerocopy_read_frame(), switch_rtp_dequeue_dtmf(), switch_rtp_has_dtmf(), switch_rtp_ready(), switch_rtp_set_max_missed_packets(), switch_rtp_zerocopy_read_frame(), switch_set_flag, SWITCH_STACK_BOTTOM, SWITCH_STATUS_BREAK, SWITCH_STATUS_FALSE, SWITCH_STATUS_GENERR, SWITCH_STATUS_INUSE, SWITCH_STATUS_SUCCESS, SWITCH_STATUS_TIMEOUT, switch_test_flag, switch_time_now(), SWITCH_TIME_T_FMT, switch_core_media_params_s::te, switch_frame::timestamp, switch_rtcp_frame::timestamp, type2str, switch_media_handle_s::vid_frames, and switch_media_handle_s::vid_started.

2140 {
2141  switch_rtcp_frame_t rtcp_frame;
2142  switch_rtp_engine_t *engine;
2143  switch_status_t status;
2144  switch_media_handle_t *smh;
2145  int do_cng = 0;
2146 
2147  switch_assert(session);
2148 
2149  if (!(smh = session->media_handle)) {
2150  return SWITCH_STATUS_FALSE;
2151  }
2152 
2153  if (!smh->media_flags[SCMF_RUNNING]) {
2154  return SWITCH_STATUS_FALSE;
2155  }
2156 
2157  engine = &smh->engines[type];
2158 
2159  if (!engine->read_codec.implementation || !switch_core_codec_ready(&engine->read_codec)) {
2160  return SWITCH_STATUS_FALSE;
2161  }
2162 
2164  return SWITCH_STATUS_FALSE;
2165  }
2166 
2167  if (smh->read_mutex[type] && switch_mutex_trylock(smh->read_mutex[type]) != SWITCH_STATUS_SUCCESS) {
2168  /* return CNG, another thread is already reading */
2169  switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_DEBUG1, "%s is already being read for %s\n",
2170  switch_channel_get_name(session->channel), type2str(type));
2171  return SWITCH_STATUS_INUSE;
2172  }
2173 
2174 
2175  engine->read_frame.datalen = 0;
2176  engine->read_frame.flags = SFF_NONE;
2177  engine->read_frame.m = SWITCH_FALSE;
2178  engine->read_frame.img = NULL;
2179 
2180  while (smh->media_flags[SCMF_RUNNING] && engine->read_frame.datalen == 0) {
2181  engine->read_frame.flags = SFF_NONE;
2182  status = switch_rtp_zerocopy_read_frame(engine->rtp_session, &engine->read_frame, flags);
2183  if (status != SWITCH_STATUS_SUCCESS && status != SWITCH_STATUS_BREAK) {
2184  if (status == SWITCH_STATUS_TIMEOUT) {
2185 
2186  if (switch_channel_get_variable(session->channel, "execute_on_media_timeout")) {
2187  *frame = &engine->read_frame;
2188  switch_set_flag((*frame), SFF_CNG);
2189  (*frame)->datalen = engine->read_impl.encoded_bytes_per_packet;
2190  memset((*frame)->data, 0, (*frame)->datalen);
2191  switch_channel_execute_on(session->channel, "execute_on_media_timeout");
2193  }
2194 
2195 
2197  }
2198  goto end;
2199  }
2200 
2202  status = SWITCH_STATUS_INUSE;
2203  goto end;
2204  }
2205 
2206  if (status == SWITCH_STATUS_BREAK) {
2207  goto end;
2208  }
2209 
2210  if (type == SWITCH_MEDIA_TYPE_VIDEO && engine->read_frame.m) {
2211 
2212  if (!smh->vid_started) {
2213  smh->vid_started = switch_epoch_time_now(NULL);
2214  }
2215  smh->vid_frames++;
2216 
2217  if ((smh->vid_frames % 15) == 0) {
2219  }
2220 
2221  if (smh->vid_frames == 1 || ((smh->vid_frames % 300) == 0)) {
2222  check_jb_sync(session);
2223  }
2224  }
2225 
2226 
2227  /* re-set codec if necessary */
2228  if (engine->reset_codec > 0) {
2229  const char *val;
2230  int rtp_timeout_sec = 0;
2231  int rtp_hold_timeout_sec = 0;
2232 
2233  engine->reset_codec = 0;
2234 
2235  if (switch_rtp_ready(engine->rtp_session)) {
2236  if (type == SWITCH_MEDIA_TYPE_VIDEO) {
2238  } else {
2240  *frame = NULL;
2242  }
2243  }
2244 
2245  if (type == SWITCH_MEDIA_TYPE_AUDIO && engine->read_impl.samples_per_second) {
2246  if ((val = switch_channel_get_variable(session->channel, "rtp_timeout_sec"))) {
2247  int v = atoi(val);
2248  if (v >= 0) {
2249  rtp_timeout_sec = v;
2250  }
2251  }
2252 
2253  if ((val = switch_channel_get_variable(session->channel, "rtp_hold_timeout_sec"))) {
2254  int v = atoi(val);
2255  if (v >= 0) {
2256  rtp_hold_timeout_sec = v;
2257  }
2258  }
2259 
2260  if (rtp_timeout_sec) {
2261  engine->max_missed_packets = (engine->read_impl.samples_per_second * rtp_timeout_sec) /
2262  engine->read_impl.samples_per_packet;
2263 
2265  if (!rtp_hold_timeout_sec) {
2266  rtp_hold_timeout_sec = rtp_timeout_sec * 10;
2267  }
2268  }
2269 
2270  if (rtp_hold_timeout_sec) {
2271  engine->max_missed_hold_packets = (engine->read_impl.samples_per_second * rtp_hold_timeout_sec) /
2272  engine->read_impl.samples_per_packet;
2273  }
2274  }
2275  }
2276 
2277  check_jb(session, NULL, 0, 0, SWITCH_FALSE);
2278 
2279  engine->check_frames = 0;
2280  engine->last_ts = 0;
2281  engine->last_seq = 0;
2282 
2283  do_cng = 1;
2284  }
2285 
2286  if (do_cng) {
2287  /* return CNG for now */
2288  *frame = &engine->read_frame;
2289  switch_set_flag((*frame), SFF_CNG);
2290  (*frame)->datalen = engine->read_impl.encoded_bytes_per_packet;
2291  memset((*frame)->data, 0, (*frame)->datalen);
2293  }
2294 
2295 
2296  /* Try to read an RTCP frame, if successful raise an event */
2297  if (switch_rtcp_zerocopy_read_frame(engine->rtp_session, &rtcp_frame) == SWITCH_STATUS_SUCCESS) {
2298  switch_event_t *event;
2299 
2301  char value[30];
2302  char header[50];
2303  int i;
2304 
2305  char *uuid = switch_core_session_get_uuid(session);
2306  if (uuid) {
2308  }
2309 
2310  snprintf(value, sizeof(value), "%.8x", rtcp_frame.ssrc);
2311  switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, "SSRC", value);
2312 
2313  snprintf(value, sizeof(value), "%u", rtcp_frame.ntp_msw);
2314  switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, "NTP-Most-Significant-Word", value);
2315 
2316  snprintf(value, sizeof(value), "%u", rtcp_frame.ntp_lsw);
2317  switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, "NTP-Least-Significant-Word", value);
2318 
2319  snprintf(value, sizeof(value), "%u", rtcp_frame.timestamp);
2320  switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, "RTP-Timestamp", value);
2321 
2322  snprintf(value, sizeof(value), "%u", rtcp_frame.packet_count);
2323  switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, "Sender-Packet-Count", value);
2324 
2325  snprintf(value, sizeof(value), "%u", rtcp_frame.octect_count);
2326  switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, "Octect-Packet-Count", value);
2327 
2328  snprintf(value, sizeof(value), "%u", engine->read_frame.timestamp);
2329  switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, "Last-RTP-Timestamp", value);
2330 
2331  snprintf(value, sizeof(value), "%u", engine->read_frame.rate);
2332  switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, "RTP-Rate", value);
2333 
2334  snprintf(value, sizeof(value), "%" SWITCH_TIME_T_FMT, switch_time_now());
2335  switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, "Capture-Time", value);
2336 
2337  // Add sources info
2338  for (i = 0; i < rtcp_frame.report_count; i++) {
2339  snprintf(header, sizeof(header), "Source%u-SSRC", i);
2340  snprintf(value, sizeof(value), "%.8x", rtcp_frame.reports[i].ssrc);
2341  switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, header, value);
2342  snprintf(header, sizeof(header), "Source%u-Fraction", i);
2343  snprintf(value, sizeof(value), "%u", rtcp_frame.reports[i].fraction);
2344  switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, header, value);
2345  snprintf(header, sizeof(header), "Source%u-Lost", i);
2346  snprintf(value, sizeof(value), "%u", rtcp_frame.reports[i].lost);
2347  switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, header, value);
2348  snprintf(header, sizeof(header), "Source%u-Loss-Avg", i);
2349  snprintf(value, sizeof(value), "%u", rtcp_frame.reports[i].loss_avg);
2350  switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, header, value);
2351  snprintf(header, sizeof(header), "Source%u-Highest-Sequence-Number-Received", i);
2352  snprintf(value, sizeof(value), "%u", rtcp_frame.reports[i].highest_sequence_number_received);
2353  switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, header, value);
2354  snprintf(header, sizeof(header), "Source%u-Jitter", i);
2355  snprintf(value, sizeof(value), "%u", rtcp_frame.reports[i].jitter);
2356  switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, header, value);
2357  snprintf(header, sizeof(header), "Source%u-LSR", i);
2358  snprintf(value, sizeof(value), "%u", rtcp_frame.reports[i].lsr);
2359  switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, header, value);
2360  snprintf(header, sizeof(header), "Source%u-DLSR", i);
2361  snprintf(value, sizeof(value), "%u", rtcp_frame.reports[i].dlsr);
2362  switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, header, value);
2363  }
2364 
2365  switch_event_fire(&event);
2366  switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_DEBUG10, "Dispatched RTCP event\n");
2367  }
2368  }
2369 
2370  /* Fast PASS! */
2371  if (switch_test_flag((&engine->read_frame), SFF_PROXY_PACKET)) {
2372  *frame = &engine->read_frame;
2374  }
2375 
2376  if (switch_rtp_has_dtmf(engine->rtp_session)) {
2377  switch_dtmf_t dtmf = { 0 };
2378  switch_rtp_dequeue_dtmf(engine->rtp_session, &dtmf);
2379  switch_channel_queue_dtmf(session->channel, &dtmf);
2380  }
2381 
2382  if (engine->read_frame.datalen > 0) {
2383  uint32_t bytes = 0;
2384  int frames = 1;
2385 
2386  /* autofix timing */
2387  if (!switch_test_flag((&engine->read_frame), SFF_CNG)) {
2388  if (!engine->read_codec.implementation || !switch_core_codec_ready(&engine->read_codec)) {
2389  *frame = NULL;
2391  }
2392 
2393  /* check for timing issues */
2395 
2396 
2397  engine->check_frames++;
2398 
2399  if (!engine->read_impl.encoded_bytes_per_packet) {
2401  goto skip;
2402  }
2403 
2404  if (smh->media_flags[SCMF_AUTOFIX_TIMING] && (engine->read_frame.datalen % 10) == 0) {
2405 
2406  if (engine->last_ts && engine->read_frame.datalen != engine->read_impl.encoded_bytes_per_packet) {
2407 
2408  uint32_t codec_ms = (int) (engine->read_frame.timestamp -
2409  engine->last_ts) / (engine->read_impl.samples_per_second / 1000);
2410 
2411  if (engine->last_seq && (int) (engine->read_frame.seq - engine->last_seq) > 1) {
2412  switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_DEBUG, "Correcting calculated ptime value from %d to %d to compensate for %d lost packet(s)\n", codec_ms, codec_ms / (int) (engine->read_frame.seq - engine->last_seq), (int) (engine->read_frame.seq - engine->last_seq - 1));
2413  codec_ms = codec_ms / (int) (engine->read_frame.seq - engine->last_seq);
2414  }
2415 
2416  if ((codec_ms % 10) != 0 || codec_ms > engine->read_impl.samples_per_packet * 10) {
2417  engine->last_ts = 0;
2418  engine->last_seq = 0;
2419  goto skip;
2420  }
2421 
2422 
2423  if (engine->last_codec_ms && engine->last_codec_ms == codec_ms) {
2424  engine->mismatch_count++;
2425  }
2426 
2427  engine->last_codec_ms = codec_ms;
2428 
2429  if (engine->mismatch_count > MAX_MISMATCH_FRAMES) {
2430  if (codec_ms != engine->cur_payload_map->codec_ms) {
2431 
2432  if (codec_ms > 120) { /* yeah right */
2434  "Your phone is trying to send timestamps that suggest an increment of %dms per packet\n"
2435  "That seems hard to believe so I am going to go on ahead and um ignore that, mmkay?\n",
2436  (int) codec_ms);
2438  goto skip;
2439  }
2440 
2441  engine->read_frame.datalen = 0;
2442 
2443  if (codec_ms != engine->cur_payload_map->codec_ms) {
2445  "Asynchronous PTIME not supported, changing our end from %d to %d\n",
2446  (int) engine->cur_payload_map->codec_ms,
2447  (int) codec_ms
2448  );
2449 
2450  switch_channel_set_variable_printf(session->channel, "rtp_h_X-Broken-PTIME", "Adv=%d;Sent=%d",
2451  (int) engine->cur_payload_map->codec_ms, (int) codec_ms);
2452 
2453  engine->cur_payload_map->codec_ms = codec_ms;
2454 
2455  /* mark to re-set codec */
2456  engine->reset_codec = 2;
2457  }
2458  }
2459  }
2460 
2461  } else {
2462  engine->mismatch_count = 0;
2463  }
2464 
2465  engine->last_ts = engine->read_frame.timestamp;
2466  engine->last_seq = engine->read_frame.seq;
2467 
2468 
2469  } else {
2470  engine->mismatch_count = 0;
2471  engine->last_ts = 0;
2472  engine->last_seq = 0;
2473  }
2474  }
2475 
2476  /* autofix payload type */
2477 
2478  if (!engine->reset_codec &&
2479  engine->codec_negotiated &&
2480  (!smh->mparams->cng_pt || engine->read_frame.payload != smh->mparams->cng_pt) &&
2481  (!smh->mparams->recv_te || engine->read_frame.payload != smh->mparams->recv_te) &&
2482  (!smh->mparams->te || engine->read_frame.payload != smh->mparams->te) &&
2483  engine->read_frame.payload != engine->cur_payload_map->recv_pt &&
2484  engine->read_frame.payload != engine->cur_payload_map->agreed_pt &&
2485  engine->read_frame.payload != engine->cur_payload_map->pt) {
2486 
2487  payload_map_t *pmap;
2488 
2489 
2491  "alternate payload received (received %d, expecting %d)\n",
2492  (int) engine->read_frame.payload, (int) engine->cur_payload_map->agreed_pt);
2493 
2494 
2495  /* search for payload type */
2497  for (pmap = engine->payload_map; pmap; pmap = pmap->next) {
2498  if (engine->read_frame.payload == pmap->recv_pt && pmap->negotiated) {
2499  engine->cur_payload_map = pmap;
2500  engine->cur_payload_map->current = 1;
2502  "Changing current codec to %s (payload type %d).\n",
2503  pmap->iananame, pmap->pt);
2504 
2505  /* mark to re-set codec */
2506  engine->reset_codec = 1;
2507  break;
2508  }
2509  }
2511 
2512  if (!engine->reset_codec) {
2514  "Could not change to payload type %d, ignoring...\n",
2515  (int) engine->read_frame.payload);
2516  }
2517  }
2518 
2519  skip:
2520 
2521  if ((bytes = engine->read_impl.encoded_bytes_per_packet)) {
2522  frames = (engine->read_frame.datalen / bytes);
2523  }
2524  engine->read_frame.samples = (int) (frames * engine->read_impl.samples_per_packet);
2525 
2526  if (engine->read_frame.datalen == 0) {
2527  continue;
2528  }
2529  }
2530  break;
2531  }
2532  }
2533 
2534  if (engine->read_frame.datalen == 0) {
2535  *frame = NULL;
2536  }
2537 
2538  *frame = &engine->read_frame;
2539 
2540  status = SWITCH_STATUS_SUCCESS;
2541 
2542  end:
2543 
2544  if (smh->read_mutex[type]) {
2545  switch_mutex_unlock(smh->read_mutex[type]);
2546  }
2547 
2548  return status;
2549 }
switch_status_t switch_channel_set_variable_printf(switch_channel_t *channel, const char *varname, const char *fmt,...)
#define switch_event_fire(event)
Fire an event filling in most of the arguements with obvious values.
Definition: switch_event.h:412
#define switch_channel_hangup(channel, hangup_cause)
Hangup a channel flagging it's state machine to end.
switch_status_t switch_channel_execute_on(switch_channel_t *channel, const char *variable_prefix)
switch_bool_t m
Definition: switch_frame.h:72
#define SWITCH_CHANNEL_SESSION_LOG(x)
#define switch_set_flag(obj, flag)
Set a flag on an arbitrary object.
Definition: switch_utils.h:631
switch_core_media_flag_t media_flags[SCMF_MAX]
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_mutex_trylock(switch_mutex_t *lock)
Definition: switch_apr.c:295
switch_status_t switch_channel_queue_dtmf(_In_ switch_channel_t *channel, _In_ const switch_dtmf_t *dtmf)
Queue DTMF on a given channel.
switch_status_t switch_core_media_set_video_codec(switch_core_session_t *session, int force)
uint32_t timestamp
Definition: switch_frame.h:69
Representation of an event.
Definition: switch_event.h:80
struct switch_rtcp_report_block_frame reports[MAX_REPORT_BLOCKS]
switch_status_t switch_core_media_set_codec(switch_core_session_t *session, int force, uint32_t codec_flags)
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
void switch_rtp_set_max_missed_packets(switch_rtp_t *rtp_session, uint32_t max)
Definition: switch_rtp.c:2753
struct payload_map_s * next
switch_media_handle_t * media_handle
switch_status_t switch_mutex_unlock(switch_mutex_t *lock)
Definition: switch_apr.c:290
switch_frame_t read_frame
switch_status_t switch_rtp_zerocopy_read_frame(switch_rtp_t *rtp_session, switch_frame_t *frame, switch_io_flag_t io_flags)
Read data from a given RTP session without copying.
Definition: switch_rtp.c:7036
uint16_t seq
Definition: switch_frame.h:70
const switch_codec_implementation_t * implementation
switch_channel_t * channel
switch_rtp_t * rtp_session
uint32_t datalen
Definition: switch_frame.h:57
switch_codec_t read_codec
switch_frame_flag_t flags
Definition: switch_frame.h:74
switch_status_t switch_mutex_lock(switch_mutex_t *lock)
Definition: switch_apr.c:285
uint32_t rate
Definition: switch_frame.h:63
#define switch_channel_get_variable(_c, _v)
switch_status_t switch_event_add_header_string(switch_event_t *event, switch_stack_t stack, const char *header_name, const char *data)
Add a string header to an event.
payload_map_t * cur_payload_map
#define SWITCH_TIME_T_FMT
uint8_t negotiated
switch_payload_t pt
switch_size_t switch_rtp_has_dtmf(switch_rtp_t *rtp_session)
Test for presence of DTMF on a given RTP session.
Definition: switch_rtp.c:6898
static void check_jb_sync(switch_core_session_t *session)
char * switch_core_session_get_uuid(_In_ switch_core_session_t *session)
Retrieve the unique identifier from a session.
static void check_jb(switch_core_session_t *session, const char *input, int32_t jb_msec, int32_t maxlen, switch_bool_t silent)
switch_image_t * img
Definition: switch_frame.h:77
switch_status_t
Common return values.
switch_rtp_engine_t engines[SWITCH_MEDIA_TYPE_TOTAL]
#define switch_goto_status(_status, _label)
Definition: switch_utils.h:256
switch_size_t switch_rtp_dequeue_dtmf(switch_rtp_t *rtp_session, switch_dtmf_t *dtmf)
Retrieve DTMF digits from a given RTP session.
Definition: switch_rtp.c:6911
An abstraction of a rtcp frame.
#define switch_event_create(event, id)
Create a new event assuming it will not be custom event and therefore hiding the unused parameters...
Definition: switch_event.h:383
uint32_t samples
Definition: switch_frame.h:61
switch_codec_implementation_t read_impl
#define type2str(type)
switch_payload_t agreed_pt
static const char * skip(const char *in)
Definition: switch_json.c:270
time_t switch_epoch_time_now(time_t *t)
Get the current epoch time.
Definition: switch_time.c:321
switch_payload_t payload
Definition: switch_frame.h:67
#define switch_test_flag(obj, flag)
Test for the existance of a flag on an arbitary object.
Definition: switch_utils.h:624
static switch_bool_t switch_core_codec_ready(switch_codec_t *codec)
void switch_log_printf(_In_ switch_text_channel_t channel, _In_z_ const char *file, _In_z_ const char *func, _In_ int line, _In_opt_z_ const char *userdata, _In_ switch_log_level_t level, _In_z_ _Printf_format_string_ const char *fmt,...) PRINTF_FUNCTION(7
Write log data to the logging engine.
switch_payload_t recv_pt
#define switch_channel_up_nosig(_channel)
#define MAX_CODEC_CHECK_FRAMES
uint32_t switch_core_media_get_video_fps(switch_core_session_t *session)
switch_mutex_t * sdp_mutex
#define switch_assert(expr)
switch_mutex_t * read_mutex[2]
switch_time_t switch_time_now(void)
Definition: switch_apr.c:302
#define MAX_MISMATCH_FRAMES
char * switch_channel_get_name(switch_channel_t *channel)
Retrieve the name of a given channel.
switch_status_t switch_rtcp_zerocopy_read_frame(switch_rtp_t *rtp_session, switch_rtcp_frame_t *frame)
Read RTCP data from a given RTP session without copying.
Definition: switch_rtp.c:7016
memset(buf, 0, buflen)
switch_core_media_params_t * mparams
uint32_t codec_ms
switch_status_t switch_core_media_read_lock_unlock ( switch_core_session_t session,
switch_media_type_t  type,
switch_bool_t  lock 
)

Definition at line 2094 of file switch_core_media.c.

References CF_NOT_READY, switch_media_handle_s::engines, switch_codec::implementation, switch_media_handle_s::media_flags, switch_rtp_engine_s::read_codec, switch_media_handle_s::read_mutex, switch_rtp_engine_s::rtp_session, SCMF_RUNNING, switch_assert, switch_channel_get_name(), SWITCH_CHANNEL_SESSION_LOG, switch_channel_test_flag(), switch_channel_up_nosig, switch_core_codec_ready(), SWITCH_LOG_DEBUG1, switch_log_printf(), switch_mutex_trylock(), switch_mutex_unlock(), switch_rtp_ready(), SWITCH_STATUS_FALSE, SWITCH_STATUS_INUSE, SWITCH_STATUS_SUCCESS, and type2str.

2095 {
2096  switch_rtp_engine_t *engine;
2097  switch_media_handle_t *smh;
2098 
2099  switch_assert(session);
2100 
2101  if (!(smh = session->media_handle)) {
2102  return SWITCH_STATUS_FALSE;
2103  }
2104 
2105  if (!smh->media_flags[SCMF_RUNNING]) {
2106  return SWITCH_STATUS_FALSE;
2107  }
2108 
2109  engine = &smh->engines[type];
2110 
2111  if (!engine->read_codec.implementation || !switch_core_codec_ready(&engine->read_codec)) {
2112  return SWITCH_STATUS_FALSE;
2113  }
2114 
2115  switch_assert(engine->rtp_session != NULL);
2116 
2117 
2119  return SWITCH_STATUS_FALSE;
2120  }
2121 
2122  if (lock) {
2123  if (smh->read_mutex[type] && switch_mutex_trylock(smh->read_mutex[type]) != SWITCH_STATUS_SUCCESS) {
2124  /* return CNG, another thread is already reading */
2125  switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_DEBUG1, "%s is already being read for %s\n",
2126  switch_channel_get_name(session->channel), type2str(type));
2127  return SWITCH_STATUS_INUSE;
2128  }
2129  } else {
2130  switch_mutex_unlock(smh->read_mutex[type]);
2131  }
2132 
2133  return SWITCH_STATUS_SUCCESS;
2134 }
#define SWITCH_CHANNEL_SESSION_LOG(x)
switch_core_media_flag_t media_flags[SCMF_MAX]
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_mutex_trylock(switch_mutex_t *lock)
Definition: switch_apr.c:295
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_status_t switch_mutex_unlock(switch_mutex_t *lock)
Definition: switch_apr.c:290
const switch_codec_implementation_t * implementation
switch_channel_t * channel
switch_rtp_t * rtp_session
switch_codec_t read_codec
switch_rtp_engine_t engines[SWITCH_MEDIA_TYPE_TOTAL]
#define type2str(type)
static switch_bool_t switch_core_codec_ready(switch_codec_t *codec)
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_channel_up_nosig(_channel)
#define switch_assert(expr)
switch_mutex_t * read_mutex[2]
char * switch_channel_get_name(switch_channel_t *channel)
Retrieve the name of a given channel.
uint8_t switch_core_media_ready ( switch_core_session_t session,
switch_media_type_t  type 
)

Definition at line 9817 of file switch_core_media.c.

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

Referenced by switch_core_media_recover_session().

9818 {
9819  switch_media_handle_t *smh;
9820 
9821  switch_assert(session);
9822 
9823  if (!(smh = session->media_handle)) {
9824  return 0;
9825  }
9826 
9827  return switch_rtp_ready(smh->engines[type].rtp_session);
9828 }
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]
#define switch_assert(expr)
switch_status_t switch_core_media_receive_message ( switch_core_session_t session,
switch_core_session_message_t msg 
)

Definition at line 9278 of file switch_core_media.c.

References CC_FS_RTP, CF_AUTOFLUSH_DURING_BRIDGE, CF_CONFERENCE, CF_CONFERENCE_RESET_MEDIA, CF_FS_RTP, CF_JITTERBUFFER, CF_NOTIMER_DURING_BRIDGE, CF_PASS_RFC2833, CF_PROXY_MODE, CF_RTP_NOTIMER_DURING_BRIDGE, CF_VIDEO, CF_VIDEO_POSSIBLE, check_jb(), clear_pmaps(), switch_rtp_engine_s::codec_negotiated, switch_rtp_engine_s::cur_payload_map, switch_media_handle_s::engines, if(), switch_core_media_params_s::local_sdp_str, switch_media_handle_s::media_flags, switch_media_handle_s::mparams, switch_media_handle_s::mutex, switch_media_handle_s::num_negotiated_codecs, switch_rtp_engine_s::read_codec, payload_map_s::rm_encoding, rtp_flush_read_buffer(), switch_rtp_engine_s::rtp_session, SCC_CODEC_SPECIFIC, SCC_DEBUG, SCCT_INT, SCCT_NONE, SCCT_STRING, SCMF_RENEG_ON_REINVITE, SCMF_RTP_AUTOFLUSH_DURING_BRIDGE, SDP_TYPE_REQUEST, SMF_JB_PAUSED, switch_assert, switch_channel_audio_sync, switch_channel_clear_flag(), switch_channel_down, switch_channel_get_name(), switch_channel_get_partner_uuid(), switch_channel_get_private(), switch_channel_get_variable, SWITCH_CHANNEL_SESSION_LOG, switch_channel_set_flag, switch_channel_set_variable, switch_channel_set_variable_printf(), switch_channel_test_cap_partner(), switch_channel_test_flag(), switch_channel_test_flag_partner(), switch_clear_flag, switch_core_codec_control(), switch_core_media_absorb_sdp(), switch_core_media_check_video_codecs(), switch_core_media_gen_local_sdp(), switch_core_media_prepare_codecs(), switch_core_media_set_local_sdp(), switch_core_media_start_udptl(), switch_core_session_enable_heartbeat(), switch_core_session_get_channel(), switch_core_session_get_partner, switch_core_session_locate, switch_core_session_receive_message, switch_core_session_rwunlock(), SWITCH_FALSE, switch_false(), SWITCH_IO_READ, SWITCH_IO_WRITE, SWITCH_LOG_DEBUG, SWITCH_LOG_ERROR, switch_log_printf(), SWITCH_LOG_WARNING, switch_media_handle_set_media_flag(), SWITCH_MEDIA_TYPE_AUDIO, SWITCH_MEDIA_TYPE_VIDEO, SWITCH_MESSAGE_INDICATE_3P_MEDIA, SWITCH_MESSAGE_INDICATE_3P_NOMEDIA, SWITCH_MESSAGE_INDICATE_AUDIO_DATA, SWITCH_MESSAGE_INDICATE_AUDIO_SYNC, SWITCH_MESSAGE_INDICATE_BITRATE_ACK, SWITCH_MESSAGE_INDICATE_BITRATE_REQ, SWITCH_MESSAGE_INDICATE_BRIDGE, SWITCH_MESSAGE_INDICATE_CODEC_DEBUG_REQ, SWITCH_MESSAGE_INDICATE_CODEC_SPECIFIC_REQ, SWITCH_MESSAGE_INDICATE_DEBUG_MEDIA, SWITCH_MESSAGE_INDICATE_HARD_MUTE, SWITCH_MESSAGE_INDICATE_JITTER_BUFFER, SWITCH_MESSAGE_INDICATE_MEDIA, SWITCH_MESSAGE_INDICATE_MEDIA_RENEG, SWITCH_MESSAGE_INDICATE_NOMEDIA, SWITCH_MESSAGE_INDICATE_PROXY_MEDIA, SWITCH_MESSAGE_INDICATE_TRANSCODING_NECESSARY, SWITCH_MESSAGE_INDICATE_UDPTL_MODE, SWITCH_MESSAGE_INDICATE_UNBRIDGE, SWITCH_MESSAGE_INDICATE_VIDEO_REFRESH_REQ, SWITCH_MESSAGE_INDICATE_VIDEO_SYNC, SWITCH_MESSAGE_RESAMPLE_EVENT, switch_mutex_lock(), switch_mutex_unlock(), SWITCH_REMOTE_MEDIA_IP_VARIABLE, SWITCH_REMOTE_MEDIA_PORT_VARIABLE, switch_rtp_ack_bitrate(), switch_rtp_clear_flag(), switch_rtp_clear_flags(), SWITCH_RTP_FLAG_DEBUG_RTP_READ, SWITCH_RTP_FLAG_DEBUG_RTP_WRITE, SWITCH_RTP_FLAG_FIR, SWITCH_RTP_FLAG_INVALID, SWITCH_RTP_FLAG_MUTE, SWITCH_RTP_FLAG_PASS_RFC2833, SWITCH_RTP_FLAG_PLI, SWITCH_RTP_FLAG_PROXY_MEDIA, SWITCH_RTP_FLAG_UDPTL, SWITCH_RTP_FLAG_USE_TIMER, switch_rtp_flush(), SWITCH_RTP_FLUSH_ONCE, SWITCH_RTP_FLUSH_STICK, SWITCH_RTP_FLUSH_UNSTICK, switch_rtp_pause_jitter_buffer(), switch_rtp_ready(), switch_rtp_req_bitrate(), switch_rtp_reset_jb(), switch_rtp_set_flag(), switch_rtp_set_flags(), switch_rtp_test_flag(), switch_rtp_video_loss(), switch_rtp_video_refresh(), switch_set_flag, SWITCH_STATUS_FALSE, SWITCH_STATUS_SUCCESS, switch_test_flag, SWITCH_TRUE, switch_true(), switch_rtp_engine_s::write_codec, and zstr.

Referenced by switch_core_session_perform_receive_message().

9279 {
9280  switch_media_handle_t *smh;
9281  switch_rtp_engine_t *a_engine, *v_engine;
9283 
9284  switch_assert(session);
9285 
9286  if (!(smh = session->media_handle)) {
9287  return SWITCH_STATUS_FALSE;
9288  }
9289 
9290  if (switch_channel_down(session->channel)) {
9291  return SWITCH_STATUS_FALSE;
9292  }
9293 
9294  a_engine = &smh->engines[SWITCH_MEDIA_TYPE_AUDIO];
9295  v_engine = &smh->engines[SWITCH_MEDIA_TYPE_VIDEO];
9296 
9297  switch (msg->message_id) {
9298 
9300  {
9301  if (switch_rtp_ready(a_engine->rtp_session)) {
9303  switch_rtp_reset_jb(a_engine->rtp_session);
9304  }
9305 
9308  }
9309  }
9310  break;
9311 
9313  {
9314  if (v_engine->rtp_session) {
9317  }// else {
9320  }
9321  // }
9322  }
9323  }
9324 
9325  break;
9326 
9328  {
9329  if (switch_rtp_ready(a_engine->rtp_session)) {
9330  if (msg->numeric_arg) {
9332  } else {
9334  }
9335  }
9336  }
9337  break;
9338 
9340  {
9341  if (switch_rtp_ready(a_engine->rtp_session)) {
9342  check_jb(session, msg->string_arg, 0, 0, SWITCH_FALSE);
9343  }
9344  }
9345  break;
9346 
9348  if (a_engine->rtp_session) {
9349  if (session->bugs && msg->numeric_arg) {
9351  "%s has a media bug, hard mute not allowed.\n", switch_channel_get_name(session->channel));
9352  } else {
9353  if (msg->numeric_arg) {
9355  } else {
9357  }
9358 
9360  }
9361  }
9362 
9363  break;
9364 
9366  {
9367  if (v_engine->rtp_session) {
9369  }
9370  }
9371  break;
9372 
9374  {
9375  if (v_engine->rtp_session) {
9377  }
9378  }
9379  break;
9380 
9382  {
9383  switch_rtp_engine_t *engine = &smh->engines[msg->numeric_reply];
9384  uint32_t level = (uint32_t) msg->numeric_arg;
9385 
9386  if (engine->rtp_session) {
9387  switch_core_codec_control(&engine->read_codec, SCC_DEBUG, SCCT_INT, (void *)&level, SCCT_NONE, NULL, NULL, NULL);
9388  switch_core_codec_control(&engine->write_codec, SCC_DEBUG, SCCT_INT, (void *)&level, SCCT_NONE, NULL, NULL, NULL);
9389  }
9390  }
9391  break;
9392 
9394  {
9395  switch_rtp_engine_t *engine;
9399  void *reply = NULL;
9400 
9401  if (!strcasecmp(msg->string_array_arg[0], "video")) {
9402  type = SWITCH_MEDIA_TYPE_VIDEO;
9403  }
9404 
9405  if (!strcasecmp(msg->string_array_arg[1], "write")) {
9406  iotype = SWITCH_IO_WRITE;
9407  }
9408 
9409  engine = &smh->engines[type];
9410 
9411  if (engine->rtp_session) {
9412  if (iotype == SWITCH_IO_READ) {
9414  SCCT_STRING, (void *)msg->string_array_arg[2],
9415  SCCT_STRING, (void *)msg->string_array_arg[3], &reply_type, &reply);
9416  } else {
9418  SCCT_STRING, (void *)msg->string_array_arg[2],
9419  SCCT_STRING, (void *)msg->string_array_arg[3], &reply_type, &reply);
9420  }
9421 
9422 
9423  if (reply_type == SCCT_STRING) {
9424  msg->string_array_arg[4] = (char *)reply;
9425  }
9426  }
9427  }
9428  break;
9429 
9431  {
9432  switch_rtp_t *rtp = a_engine->rtp_session;
9433  const char *direction = msg->string_array_arg[0];
9434 
9435  if (direction && *direction == 'v') {
9436  direction++;
9437  rtp = v_engine->rtp_session;
9438  }
9439 
9440  if (switch_rtp_ready(rtp) && !zstr(direction) && !zstr(msg->string_array_arg[1])) {
9442  int both = !strcasecmp(direction, "both");
9443  int set = 0;
9444 
9445  if (both || !strcasecmp(direction, "read")) {
9447  set++;
9448  }
9449 
9450  if (both || !strcasecmp(direction, "write")) {
9452  set++;
9453  }
9454 
9455  if (set) {
9456  if (switch_true(msg->string_array_arg[1])) {
9457  switch_rtp_set_flags(rtp, flags);
9458  } else {
9459  switch_rtp_clear_flags(rtp, flags);
9460  }
9461  } else {
9462  switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_ERROR, "Invalid Options\n");
9463  }
9464  }
9465  }
9466  goto end;
9469  switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_WARNING, "Pass 2833 mode may not work on a transcoded call.\n");
9470  }
9471  goto end;
9472 
9474  {
9475 
9476  if (switch_rtp_ready(a_engine->rtp_session)) {
9477  const char *val;
9478  int ok = 0;
9479 
9480  if (!switch_channel_test_flag(session->channel, CF_VIDEO) &&
9481  (!(val = switch_channel_get_variable(session->channel, "rtp_jitter_buffer_during_bridge")) || switch_false(val))) {
9484  "%s PAUSE Jitterbuffer\n", switch_channel_get_name(session->channel));
9487  }
9488  }
9489 
9493  "%s activate passthru 2833 mode.\n", switch_channel_get_name(session->channel));
9494  }
9495 
9496 
9497  if ((val = switch_channel_get_variable(session->channel, "rtp_notimer_during_bridge"))) {
9498  ok = switch_true(val);
9499  } else {
9501  }
9502 
9504  ok = 0;
9505  }
9506 
9507  if (ok) {
9509  //switch_rtp_clear_flag(a_engine->rtp_session, SWITCH_RTP_FLAG_NOBLOCK);
9511  }
9512 
9514  /* these are not compat */
9515  ok = 0;
9516  } else {
9517  if ((val = switch_channel_get_variable(session->channel, "rtp_autoflush_during_bridge"))) {
9518  ok = switch_true(val);
9519  } else {
9521  }
9522  }
9523 
9524  if (ok) {
9527  } else {
9529  }
9530 
9531  }
9532  }
9533  goto end;
9535  if (switch_rtp_ready(a_engine->rtp_session)) {
9536 
9537  if (switch_test_flag(smh, SMF_JB_PAUSED)) {
9541  "%s RESUME Jitterbuffer\n", switch_channel_get_name(session->channel));
9543  }
9544  }
9545 
9546 
9548  switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_DEBUG, "%s deactivate passthru 2833 mode.\n",
9549  switch_channel_get_name(session->channel));
9551  }
9552 
9557  //switch_rtp_set_flag(a_engine->rtp_session, SWITCH_RTP_FLAG_NOBLOCK);
9558  }
9560  }
9561 
9565  } else {
9567  }
9568 
9569  }
9570  goto end;
9572  if (switch_rtp_ready(a_engine->rtp_session)) {
9574  //switch_rtp_reset_jb(a_engine->rtp_session);
9575  }
9576  goto end;
9577 
9579  if (switch_rtp_ready(v_engine->rtp_session)) {
9580  switch_rtp_flush(v_engine->rtp_session);
9581  //switch_rtp_reset_jb(v_engine->rtp_session);
9582  }
9583  goto end;
9586  {
9587 
9588  a_engine->codec_negotiated = 0;
9589  v_engine->codec_negotiated = 0;
9590 
9591  if (session->track_duration) {
9593  }
9594  }
9595  break;
9596 
9600  break;
9602  {
9603  const char *uuid;
9604  switch_core_session_t *other_session;
9605  switch_channel_t *other_channel;
9606  const char *ip = NULL, *port = NULL;
9607 
9609 
9611 
9612  if (switch_true(switch_channel_get_variable(session->channel, "bypass_keep_codec"))) {
9613  switch_channel_set_variable(session->channel, "absolute_codec_string", switch_channel_get_variable(session->channel, "ep_codec_string"));
9614  }
9615 
9616 
9617  if ((uuid = switch_channel_get_partner_uuid(session->channel))
9618  && (other_session = switch_core_session_locate(uuid))) {
9619  other_channel = switch_core_session_get_channel(other_session);
9622  switch_core_session_rwunlock(other_session);
9623 
9624  if (ip && port) {
9626  clear_pmaps(a_engine);
9627  clear_pmaps(v_engine);
9628  switch_core_media_gen_local_sdp(session, SDP_TYPE_REQUEST, ip, (switch_port_t)atoi(port), NULL, 1);
9629  }
9630  }
9631 
9632 
9633  if (!smh->mparams->local_sdp_str) {
9635  }
9636 
9637  if (session->track_duration) {
9639  }
9640 
9641  }
9642  break;
9643 
9644 
9645  default:
9646  break;
9647  }
9648 
9649 
9650  if (smh->mutex) switch_mutex_lock(smh->mutex);
9651 
9652 
9653  if (switch_channel_down(session->channel)) {
9654  status = SWITCH_STATUS_FALSE;
9655  goto end_lock;
9656  }
9657 
9658  switch (msg->message_id) {
9660  {
9661  switch_core_session_t *nsession;
9662 
9663  if (msg->string_arg) {
9664  switch_channel_set_variable(session->channel, "absolute_codec_string", NULL);
9665  if (*msg->string_arg == '=') {
9666  switch_channel_set_variable(session->channel, "codec_string", msg->string_arg);
9667  } else {
9668  switch_channel_set_variable_printf(session->channel, "codec_string", "=%s%s%s,%s",
9669  v_engine->cur_payload_map->rm_encoding ? v_engine->cur_payload_map->rm_encoding : "",
9670  v_engine->cur_payload_map->rm_encoding ? "," : "",
9671  a_engine->cur_payload_map->rm_encoding, msg->string_arg);
9672  }
9673 
9674 
9675  a_engine->codec_negotiated = 0;
9676  v_engine->codec_negotiated = 0;
9677  smh->num_negotiated_codecs = 0;
9681  switch_core_media_gen_local_sdp(session, SDP_TYPE_REQUEST, NULL, 0, NULL, 1);
9682  }
9683 
9685 
9686  if (msg->numeric_arg && switch_core_session_get_partner(session, &nsession) == SWITCH_STATUS_SUCCESS) {
9687  msg->numeric_arg = 0;
9688  switch_core_session_receive_message(nsession, msg);
9689  switch_core_session_rwunlock(nsession);
9690  }
9691 
9692  }
9693  break;
9694 
9696  {
9697  if (switch_rtp_ready(a_engine->rtp_session)) {
9698  if (msg->numeric_arg) {
9702  }
9703 
9705 
9706  } else {
9707  if (switch_test_flag(smh, SMF_JB_PAUSED)) {
9711  }
9712  }
9713  }
9714  }
9715  }
9716  break;
9717 
9719  {
9720  switch_t38_options_t *t38_options = switch_channel_get_private(session->channel, "t38_options");
9721 
9722  if (t38_options) {
9723  switch_core_media_start_udptl(session, t38_options);
9724  }
9725 
9726  }
9727 
9728 
9729  default:
9730  break;
9731  }
9732 
9733 
9734  end_lock:
9735 
9736  if (smh->mutex) switch_mutex_unlock(smh->mutex);
9737 
9738  end:
9739 
9740  if (switch_channel_down(session->channel)) {
9741  status = SWITCH_STATUS_FALSE;
9742  }
9743 
9744  return status;
9745 
9746 }
switch_status_t switch_channel_set_variable_printf(switch_channel_t *channel, const char *varname, const char *fmt,...)
#define SWITCH_CHANNEL_SESSION_LOG(x)
#define switch_set_flag(obj, flag)
Set a flag on an arbitrary object.
Definition: switch_utils.h:631
switch_core_media_flag_t media_flags[SCMF_MAX]
uint8_t switch_rtp_ready(switch_rtp_t *rtp_session)
Test if an RTP session is ready.
Definition: switch_rtp.c:4452
switch_core_session_message_types_t message_id
Definition: switch_core.h:181
uint32_t switch_channel_test_flag_partner(switch_channel_t *channel, switch_channel_flag_t flag)
const char * switch_channel_get_partner_uuid(switch_channel_t *channel)
switch_status_t switch_rtp_ack_bitrate(switch_rtp_t *rtp_session, uint32_t bps)
Definition: switch_rtp.c:4351
static void clear_pmaps(switch_rtp_engine_t *engine)
switch_status_t switch_rtp_pause_jitter_buffer(switch_rtp_t *rtp_session, switch_bool_t pause)
Definition: switch_rtp.c:4059
const char * string_array_arg[MESSAGE_STRING_ARG_MAX]
Definition: switch_core.h:209
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
void rtp_flush_read_buffer(switch_rtp_t *rtp_session, switch_rtp_flush_t flush)
Definition: switch_rtp.c:4940
#define zstr(x)
Definition: switch_utils.h:281
void switch_core_media_set_local_sdp(switch_core_session_t *session, const char *sdp_str, switch_bool_t dup)
switch_status_t switch_mutex_unlock(switch_mutex_t *lock)
Definition: switch_apr.c:290
_Ret_ switch_channel_t * switch_core_session_get_channel(_In_ switch_core_session_t *session)
Retrieve a pointer to the channel object associated with a given session.
#define switch_clear_flag(obj, flag)
Clear a flag on an arbitrary object while locked.
Definition: switch_utils.h:655
void switch_core_media_check_video_codecs(switch_core_session_t *session)
void switch_core_session_enable_heartbeat(switch_core_session_t *session, uint32_t seconds)
switch_codec_t write_codec
switch_codec_control_type_t
#define SWITCH_REMOTE_MEDIA_IP_VARIABLE
Definition: switch_types.h:210
if((uint32_t)(unpack->cur-unpack->buf) > unpack->buflen)
#define switch_channel_audio_sync(_c)
switch_channel_t * channel
switch_rtp_t * rtp_session
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)
switch_codec_t read_codec
switch_status_t switch_mutex_lock(switch_mutex_t *lock)
Definition: switch_apr.c:285
uint32_t switch_channel_test_cap_partner(switch_channel_t *channel, switch_channel_cap_t cap)
#define switch_channel_get_variable(_c, _v)
void switch_rtp_set_flags(switch_rtp_t *rtp_session, switch_rtp_flag_t flags[SWITCH_RTP_FLAG_INVALID])
Definition: switch_rtp.c:4660
payload_map_t * cur_payload_map
void switch_core_media_start_udptl(switch_core_session_t *session, switch_t38_options_t *t38_options)
void switch_rtp_video_loss(switch_rtp_t *rtp_session)
Definition: switch_rtp.c:4374
switch_media_bug_t * bugs
uint16_t switch_port_t
#define switch_core_session_get_partner(_session, _partner)
Definition: switch_core.h:1002
#define switch_core_session_receive_message(_session, _message)
Definition: switch_core.h:1217
void switch_core_session_rwunlock(_In_ switch_core_session_t *session)
Unlock a read or write lock on as given session.
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_clear_flag(switch_rtp_t *rtp_session, switch_rtp_flag_t flag)
Clear an RTP Flag.
Definition: switch_rtp.c:4747
void switch_rtp_set_flag(switch_rtp_t *rtp_session, switch_rtp_flag_t flag)
Set an RTP Flag.
Definition: switch_rtp.c:4702
#define switch_channel_down(_channel)
switch_status_t
Common return values.
switch_rtp_engine_t engines[SWITCH_MEDIA_TYPE_TOTAL]
void * switch_channel_get_private(switch_channel_t *channel, const char *key)
Retrieve private from a given channel.
switch_mutex_t * mutex
void switch_rtp_flush(switch_rtp_t *rtp_session)
Definition: switch_rtp.c:4331
void switch_rtp_reset_jb(switch_rtp_t *rtp_session)
Definition: switch_rtp.c:2769
#define switch_core_session_locate(uuid_str)
Locate a session based on it's uuid.
Definition: switch_core.h:916
switch_rtp_flag_t
RTP Related Flags.
Definition: switch_types.h:723
#define switch_channel_set_flag(_c, _f)
void switch_rtp_clear_flags(switch_rtp_t *rtp_session, switch_rtp_flag_t flags[SWITCH_RTP_FLAG_INVALID])
Definition: switch_rtp.c:4691
#define SWITCH_REMOTE_MEDIA_PORT_VARIABLE
Definition: switch_types.h:211
#define switch_test_flag(obj, flag)
Test for the existance of a flag on an arbitary object.
Definition: switch_utils.h:624
void switch_log_printf(_In_ switch_text_channel_t channel, _In_z_ const char *file, _In_z_ const char *func, _In_ int line, _In_opt_z_ const char *userdata, _In_ switch_log_level_t level, _In_z_ _Printf_format_string_ const char *fmt,...) PRINTF_FUNCTION(7
Write log data to the logging engine.
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
static int switch_false(const char *expr)
Evaluate the falsefullness of a string expression.
Definition: switch_utils.h:482
switch_io_type_t
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)
#define switch_channel_set_variable(_channel, _var, _val)
void switch_rtp_video_refresh(switch_rtp_t *rtp_session)
Definition: switch_rtp.c:4362
char * switch_channel_get_name(switch_channel_t *channel)
Retrieve the name of a given channel.
switch_status_t switch_rtp_req_bitrate(switch_rtp_t *rtp_session, uint32_t bps)
Definition: switch_rtp.c:4340
switch_core_media_params_t * mparams
void switch_core_media_prepare_codecs(switch_core_session_t *session, switch_bool_t force)
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_absorb_sdp(switch_core_session_t *session)
void switch_media_handle_set_media_flag(switch_media_handle_t *smh, switch_core_media_flag_t flag)
char * rm_encoding
switch_media_type_t
void switch_core_media_recover_session ( switch_core_session_t session)

Definition at line 10431 of file switch_core_media.c.

References 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, CF_PROXY_MODE, CF_SECURE, CF_VIDEO, CF_VIDEO_POSSIBLE, switch_core_session::channel, payload_map_s::channels, switch_core_media_params_s::codec_flags, payload_map_s::codec_ms, switch_rtp_engine_s::codec_negotiated, switch_media_handle_s::codec_order, switch_media_handle_s::codec_order_last, switch_media_handle_s::codecs, secure_settings_s::crypto_tag, switch_rtp_engine_s::crypto_type, switch_rtp_engine_s::cur_payload_map, switch_media_handle_s::engines, switch_core_media_params_s::extrtpip, payload_map_s::iananame, switch_srtp_crypto_suite_s::keylen, secure_settings_s::local_crypto_key, secure_settings_s::local_raw_key, switch_rtp_engine_s::local_sdp_ip, switch_rtp_engine_s::local_sdp_port, switch_media_handle_s::mparams, switch_core_media_params_s::num_codecs, switch_media_handle_s::payload_space, payload_map_s::pt, payload_map_s::recv_pt, switch_core_media_params_s::recv_te, secure_settings_s::remote_crypto_key, secure_settings_s::remote_raw_key, payload_map_s::remote_sdp_ip, payload_map_s::remote_sdp_port, switch_core_media_params_s::remote_sdp_str, payload_map_s::rm_encoding, payload_map_s::rm_fmtp, payload_map_s::rm_rate, switch_rtp_engine_s::rtp_session, switch_core_media_params_s::rtpip, SDP_TYPE_REQUEST, switch_media_handle_s::session, switch_rtp_engine_s::ssec, SWITCH_ADVERTISED_MEDIA_IP_VARIABLE, switch_assert, switch_channel_get_variable, switch_channel_set_flag, switch_channel_set_variable_printf(), switch_channel_test_flag(), switch_core_media_activate_rtp(), switch_core_media_add_crypto(), switch_core_media_gen_local_sdp(), switch_core_media_ready(), switch_core_media_set_codec(), switch_core_media_set_video_codec(), switch_core_session_get_recovery_crypto_key(), switch_core_session_strdup, switch_loadable_module_get_codecs_sorted(), SWITCH_LOCAL_MEDIA_IP_VARIABLE, SWITCH_LOCAL_MEDIA_PORT_VARIABLE, SWITCH_LOCAL_VIDEO_IP_VARIABLE, SWITCH_LOCAL_VIDEO_PORT_VARIABLE, SWITCH_MAX_CODECS, SWITCH_MEDIA_TYPE_AUDIO, SWITCH_MEDIA_TYPE_VIDEO, SWITCH_R_SDP_VARIABLE, SWITCH_REMOTE_MEDIA_IP_VARIABLE, SWITCH_REMOTE_MEDIA_PORT_VARIABLE, SWITCH_REMOTE_VIDEO_IP_VARIABLE, SWITCH_REMOTE_VIDEO_PORT_VARIABLE, switch_rtp_add_crypto_key(), SWITCH_RTP_CRYPTO_RECV, SWITCH_RTP_CRYPTO_SEND, switch_rtp_set_telephony_event(), switch_rtp_set_telephony_recv_event(), switch_separate_string(), SWITCH_STATUS_SUCCESS, switch_core_media_params_s::te, switch_core_media_params_s::timer_name, and zstr.

Referenced by recover_callback().

10432 {
10433  const char *ip;
10434  const char *port;
10435  const char *a_ip;
10436  const char *r_ip;
10437  const char *r_port;
10438  const char *tmp;
10439  switch_rtp_engine_t *a_engine, *v_engine;
10440  switch_media_handle_t *smh;
10441 
10442  switch_assert(session);
10443 
10444  if (!(smh = session->media_handle)) {
10445  return;
10446  }
10447 
10450 
10451  if (switch_channel_test_flag(session->channel, CF_PROXY_MODE) || !(ip && port)) {
10452  return;
10453  } else {
10457  }
10458 
10459  a_engine = &smh->engines[SWITCH_MEDIA_TYPE_AUDIO];
10460  v_engine = &smh->engines[SWITCH_MEDIA_TYPE_VIDEO];
10461 
10462  a_engine->cur_payload_map->iananame = a_engine->cur_payload_map->rm_encoding = (char *) switch_channel_get_variable(session->channel, "rtp_use_codec_name");
10463  a_engine->cur_payload_map->rm_fmtp = (char *) switch_channel_get_variable(session->channel, "rtp_use_codec_fmtp");
10464 
10466  smh->mparams->remote_sdp_str = switch_core_session_strdup(session, tmp);
10467  }
10468 
10469  if ((tmp = switch_channel_get_variable(session->channel, "rtp_use_timer_name"))) {
10470  smh->mparams->timer_name = switch_core_session_strdup(session, tmp);
10471  }
10472 
10473  if ((tmp = switch_channel_get_variable(session->channel, "rtp_last_audio_codec_string"))) {
10474  const char *vtmp = switch_channel_get_variable(session->channel, "rtp_last_video_codec_string");
10475  switch_channel_set_variable_printf(session->channel, "rtp_use_codec_string", "%s%s%s", tmp, vtmp ? "," : "", vtmp ? vtmp : "");
10476  }
10477 
10478  if ((tmp = switch_channel_get_variable(session->channel, "rtp_use_codec_string"))) {
10479  char *tmp_codec_string = switch_core_session_strdup(smh->session, tmp);
10480  smh->codec_order_last = switch_separate_string(tmp_codec_string, ',', smh->codec_order, SWITCH_MAX_CODECS);
10482  }
10483 
10484  if ((tmp = switch_channel_get_variable(session->channel, "rtp_2833_send_payload"))) {
10485  smh->mparams->te = (switch_payload_t)atoi(tmp);
10486  }
10487 
10488  if ((tmp = switch_channel_get_variable(session->channel, "rtp_2833_recv_payload"))) {
10489  smh->mparams->recv_te = (switch_payload_t)atoi(tmp);
10490  }
10491 
10492  if ((tmp = switch_channel_get_variable(session->channel, "rtp_use_codec_rate"))) {
10493  a_engine->cur_payload_map->rm_rate = atoi(tmp);
10494  a_engine->cur_payload_map->adv_rm_rate = a_engine->cur_payload_map->rm_rate;
10495  }
10496 
10497  if ((tmp = switch_channel_get_variable(session->channel, "rtp_use_codec_ptime"))) {
10498  a_engine->cur_payload_map->codec_ms = atoi(tmp);
10499  }
10500 
10501  if ((tmp = switch_channel_get_variable(session->channel, "rtp_use_codec_channels"))) {
10502  a_engine->cur_payload_map->channels = atoi(tmp);
10503  }
10504 
10505  if ((tmp = switch_channel_get_variable(session->channel, "rtp_use_pt"))) {
10506  a_engine->cur_payload_map->pt = a_engine->cur_payload_map->agreed_pt = (switch_payload_t)(smh->payload_space = atoi(tmp));
10507  }
10508 
10509  if ((tmp = switch_channel_get_variable(session->channel, "rtp_audio_recv_pt"))) {
10510  a_engine->cur_payload_map->recv_pt = (switch_payload_t)atoi(tmp);
10511  }
10512 
10513  switch_core_media_set_codec(session, 0, smh->mparams->codec_flags);
10514 
10515  a_engine->adv_sdp_ip = smh->mparams->extrtpip = (char *) ip;
10516  a_engine->adv_sdp_port = a_engine->local_sdp_port = (switch_port_t)atoi(port);
10517  a_engine->codec_negotiated = 1;
10518 
10519  if (!zstr(ip)) {
10520  a_engine->local_sdp_ip = switch_core_session_strdup(session, ip);
10521  smh->mparams->rtpip = a_engine->local_sdp_ip;
10522  }
10523 
10524  if (!zstr(a_ip)) {
10525  a_engine->adv_sdp_ip = switch_core_session_strdup(session, a_ip);
10526  }
10527 
10528  if (r_ip && r_port) {
10529  a_engine->cur_payload_map->remote_sdp_ip = (char *) r_ip;
10530  a_engine->cur_payload_map->remote_sdp_port = (switch_port_t)atoi(r_port);
10531  }
10532 
10533  if (switch_channel_test_flag(session->channel, CF_VIDEO)) {
10534  if ((tmp = switch_channel_get_variable(session->channel, "rtp_use_video_pt"))) {
10535  v_engine->cur_payload_map->pt = v_engine->cur_payload_map->agreed_pt = (switch_payload_t)atoi(tmp);
10536  }
10537 
10538  if ((tmp = switch_channel_get_variable(session->channel, "rtp_video_recv_pt"))) {
10539  v_engine->cur_payload_map->recv_pt = (switch_payload_t)atoi(tmp);
10540  }
10541 
10542  v_engine->cur_payload_map->rm_encoding = (char *) switch_channel_get_variable(session->channel, "rtp_use_video_codec_name");
10543  v_engine->cur_payload_map->rm_fmtp = (char *) switch_channel_get_variable(session->channel, "rtp_use_video_codec_fmtp");
10544  v_engine->codec_negotiated = 1;
10545 
10550 
10552 
10553  if ((tmp = switch_channel_get_variable(session->channel, "rtp_use_video_codec_rate"))) {
10554  v_engine->cur_payload_map->rm_rate = atoi(tmp);
10555  v_engine->cur_payload_map->adv_rm_rate = v_engine->cur_payload_map->rm_rate;
10556  }
10557 
10558  if ((tmp = switch_channel_get_variable(session->channel, "rtp_use_video_codec_ptime"))) {
10559  v_engine->cur_payload_map->codec_ms = atoi(tmp);
10560  }
10561 
10562  v_engine->adv_sdp_port = v_engine->local_sdp_port = (switch_port_t)atoi(port);
10563  v_engine->local_sdp_ip = smh->mparams->rtpip;
10564 
10565  if (r_ip && r_port) {
10566  v_engine->cur_payload_map->remote_sdp_ip = (char *) r_ip;
10567  v_engine->cur_payload_map->remote_sdp_port = (switch_port_t)atoi(r_port);
10568  }
10569  }
10570 
10571  switch_core_media_gen_local_sdp(session, SDP_TYPE_REQUEST, NULL, 0, NULL, 1);
10573 
10575  return;
10576  }
10577 
10580 
10581 
10582  if ((tmp = switch_channel_get_variable(session->channel, "rtp_last_audio_local_crypto_key")) && a_engine->ssec[a_engine->crypto_type].remote_crypto_key) {
10583  int idx = atoi(tmp);
10584 
10585  a_engine->ssec[a_engine->crypto_type].local_crypto_key = switch_core_session_strdup(session, tmp);
10589 
10591  a_engine->crypto_type,
10592  a_engine->ssec[a_engine->crypto_type].local_raw_key,
10593  SUITES[a_engine->crypto_type].keylen);
10594 
10596  a_engine->ssec[a_engine->crypto_type].crypto_tag,
10597  a_engine->crypto_type,
10598  a_engine->ssec[a_engine->crypto_type].remote_raw_key,
10599  SUITES[a_engine->crypto_type].keylen);
10600  }
10601 
10602 
10606  }
10607 
10608 }
switch_status_t switch_channel_set_variable_printf(switch_channel_t *channel, const char *varname, const char *fmt,...)
#define SWITCH_MAX_CODECS
Definition: switch_types.h:558
unsigned char remote_raw_key[SWITCH_RTP_MAX_CRYPTO_LEN]
switch_status_t switch_core_media_set_video_codec(switch_core_session_t *session, int force)
unsigned long rm_rate
uint8_t switch_core_media_ready(switch_core_session_t *session, switch_media_type_t type)
unsigned long adv_rm_rate
char * remote_sdp_ip
#define SWITCH_LOCAL_VIDEO_IP_VARIABLE
Definition: switch_types.h:214
const switch_codec_implementation_t * codecs[SWITCH_MAX_CODECS]
switch_status_t switch_rtp_add_crypto_key(switch_rtp_t *rtp_session, switch_rtp_crypto_direction_t direction, uint32_t index, switch_rtp_crypto_key_type_t type, unsigned char *key, switch_size_t keylen)
Definition: switch_rtp.c:3468
#define SWITCH_LOCAL_VIDEO_PORT_VARIABLE
Definition: switch_types.h:215
static switch_srtp_crypto_suite_t SUITES[CRYPTO_INVALID]
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
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_secure_settings_t ssec[CRYPTO_INVALID+1]
#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
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
unsigned char local_raw_key[SWITCH_RTP_MAX_CRYPTO_LEN]
#define SWITCH_REMOTE_MEDIA_IP_VARIABLE
Definition: switch_types.h:210
unsigned int switch_separate_string(_In_ char *buf, char delim, _Post_count_(return) char **array, unsigned int arraylen)
Separate a string into an array based on a character delimiter.
switch_channel_t * channel
switch_rtp_t * rtp_session
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)
#define switch_channel_get_variable(_c, _v)
switch_core_session_t * session
payload_map_t * cur_payload_map
switch_payload_t pt
uint16_t switch_port_t
switch_port_t local_sdp_port
switch_status_t switch_core_media_activate_rtp(switch_core_session_t *session)
#define SWITCH_LOCAL_MEDIA_IP_VARIABLE
Definition: switch_types.h:207
static void switch_core_session_get_recovery_crypto_key(switch_core_session_t *session, switch_media_type_t type)
#define SWITCH_R_SDP_VARIABLE
Definition: switch_types.h:196
int switch_loadable_module_get_codecs_sorted(const switch_codec_implementation_t **array, int arraylen, char **prefs, int preflen)
Retrieve the list of loaded codecs into an array based on another array showing the sorted order...
switch_rtp_engine_t engines[SWITCH_MEDIA_TYPE_TOTAL]
switch_port_t adv_sdp_port
#define SWITCH_REMOTE_VIDEO_PORT_VARIABLE
Definition: switch_types.h:213
#define switch_channel_set_flag(_c, _f)
#define SWITCH_REMOTE_MEDIA_PORT_VARIABLE
Definition: switch_types.h:211
switch_payload_t agreed_pt
switch_status_t switch_core_media_add_crypto(switch_secure_settings_t *ssec, const char *key_str, switch_rtp_crypto_direction_t direction)
switch_payload_t recv_pt
switch_port_t remote_sdp_port
#define switch_core_session_strdup(_session, _todup)
Copy a string using memory allocation from a session's pool.
Definition: switch_core.h:717
char * codec_order[SWITCH_MAX_CODECS]
#define switch_assert(expr)
switch_core_media_params_t * mparams
uint32_t codec_ms
uint8_t switch_payload_t
#define SWITCH_REMOTE_VIDEO_IP_VARIABLE
Definition: switch_types.h:212
char * rm_encoding
switch_rtp_crypto_key_type_t crypto_type
void switch_core_media_reset_autofix ( switch_core_session_t session,
switch_media_type_t  type 
)

Definition at line 5892 of file switch_core_media.c.

References switch_rtp_engine_s::check_frames, switch_media_handle_s::engines, switch_rtp_engine_s::last_seq, switch_rtp_engine_s::last_ts, and switch_assert.

5893 {
5894  switch_rtp_engine_t *engine;
5895  switch_media_handle_t *smh;
5896 
5897  switch_assert(session);
5898 
5899  if (!(smh = session->media_handle)) {
5900  return;
5901  }
5902 
5903  engine = &smh->engines[type];
5904 
5905  engine->check_frames = 0;
5906  engine->last_ts = 0;
5907  engine->last_seq = 0;
5908 }
switch_media_handle_t * media_handle
switch_rtp_engine_t engines[SWITCH_MEDIA_TYPE_TOTAL]
#define switch_assert(expr)
switch_status_t switch_core_media_reset_jb ( switch_core_session_t session,
switch_media_type_t  type 
)

Definition at line 9256 of file switch_core_media.c.

References switch_media_handle_s::engines, switch_rtp_engine_s::rtp_session, switch_assert, switch_rtp_ready(), switch_rtp_reset_jb(), SWITCH_STATUS_FALSE, and SWITCH_STATUS_SUCCESS.

9257 {
9258  switch_media_handle_t *smh;
9259  switch_rtp_engine_t *engine;
9260 
9261  switch_assert(session);
9262 
9263  if (!(smh = session->media_handle)) {
9264  return SWITCH_STATUS_FALSE;
9265  }
9266 
9267  engine = &smh->engines[type];
9268 
9269  if (switch_rtp_ready(engine->rtp_session)) {
9271  return SWITCH_STATUS_SUCCESS;
9272  }
9273 
9274  return SWITCH_STATUS_FALSE;
9275 }
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_reset_jb(switch_rtp_t *rtp_session)
Definition: switch_rtp.c:2769
#define switch_assert(expr)
void switch_core_media_resume ( switch_core_session_t session)

Definition at line 3060 of file switch_core_media.c.

References switch_media_handle_s::engines, switch_rtp_engine_s::rtp_session, switch_assert, SWITCH_MEDIA_TYPE_AUDIO, SWITCH_MEDIA_TYPE_VIDEO, switch_rtp_clear_flag(), and SWITCH_RTP_FLAG_PAUSE.

3061 {
3062  switch_rtp_engine_t *a_engine, *v_engine;
3063  switch_media_handle_t *smh;
3064 
3065  switch_assert(session);
3066 
3067  if (!(smh = session->media_handle)) {
3068  return;
3069  }
3070 
3071  a_engine = &smh->engines[SWITCH_MEDIA_TYPE_AUDIO];
3072  v_engine = &smh->engines[SWITCH_MEDIA_TYPE_VIDEO];
3073 
3074  if (a_engine->rtp_session) {
3076  }
3077 
3078  if (v_engine->rtp_session) {
3080  }
3081 }
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_set_codec ( switch_core_session_t session,
int  force,
uint32_t  codec_flags 
)

Definition at line 2825 of file switch_core_media.c.

References switch_codec_implementation::actual_samples_per_second, switch_codec::agreed_pt, payload_map_s::agreed_pt, payload_map_s::bitrate, switch_codec_implementation::bits_per_second, switch_frame::channels, payload_map_s::channels, switch_frame::codec, payload_map_s::codec_ms, switch_rtp_engine_s::codec_settings, switch_rtp_engine_s::cur_payload_map, switch_media_handle_s::engines, switch_codec::fmtp_out, payload_map_s::fmtp_out, switch_codec_implementation::iananame, payload_map_s::iananame, switch_codec::implementation, switch_codec_implementation::microseconds_per_packet, payload_map_s::modname, switch_codec_implementation::number_of_channels, payload_map_s::pt, switch_frame::rate, switch_rtp_engine_s::read_codec, switch_rtp_engine_s::read_frame, switch_rtp_engine_s::read_impl, payload_map_s::rm_fmtp, payload_map_s::rm_rate, switch_rtp_engine_s::rtp_session, switch_codec_implementation::samples_per_packet, switch_codec_implementation::samples_per_second, switch_codec::session, switch_assert, SWITCH_CAUSE_DESTINATION_OUT_OF_ORDER, SWITCH_CAUSE_INCOMPATIBLE_DESTINATION, switch_channel_audio_sync, switch_channel_get_name(), switch_channel_hangup, SWITCH_CHANNEL_SESSION_LOG, switch_channel_set_variable, switch_channel_set_variable_printf(), SWITCH_CODEC_FLAG_DECODE, SWITCH_CODEC_FLAG_ENCODE, switch_core_codec_destroy(), switch_core_codec_init_with_bitrate(), switch_core_codec_ready(), switch_core_session_get_pool(), switch_core_session_lock_codec_read(), switch_core_session_lock_codec_write(), switch_core_session_parse_codec_settings(), switch_core_session_reset(), switch_core_session_set_read_impl(), switch_core_session_set_real_read_codec(), switch_core_session_set_write_codec(), switch_core_session_set_write_impl(), switch_core_session_strdup, switch_core_session_unlock_codec_read(), switch_core_session_unlock_codec_write(), switch_goto_status, SWITCH_LOG_DEBUG, SWITCH_LOG_ERROR, SWITCH_LOG_NOTICE, switch_log_printf(), SWITCH_MEDIA_TYPE_AUDIO, switch_mutex_lock(), switch_mutex_unlock(), switch_resample_destroy(), switch_rtp_change_interval(), switch_rtp_ready(), switch_rtp_reset_jb(), switch_rtp_set_default_payload(), SWITCH_STATUS_FALSE, SWITCH_STATUS_SUCCESS, switch_yield, switch_rtp_engine_s::write_codec, and switch_rtp_engine_s::write_impl.

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

2826 {
2828  int resetting = 0;
2829  switch_media_handle_t *smh;
2830  switch_rtp_engine_t *a_engine;
2831 
2832  switch_assert(session);
2833 
2834  if (!(smh = session->media_handle)) {
2835  return SWITCH_STATUS_FALSE;
2836  }
2837  a_engine = &smh->engines[SWITCH_MEDIA_TYPE_AUDIO];
2838 
2839  if (!a_engine->cur_payload_map->iananame) {
2840  switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_DEBUG, "No audio codec available\n");
2842  }
2843 
2844  if (switch_core_codec_ready(&a_engine->read_codec)) {
2845  if (!force) {
2847  }
2848 
2849  if (strcasecmp(a_engine->read_impl.iananame, a_engine->cur_payload_map->iananame) ||
2850  (uint32_t) a_engine->read_impl.microseconds_per_packet / 1000 != a_engine->cur_payload_map->codec_ms ||
2851  a_engine->read_impl.samples_per_second != a_engine->cur_payload_map->rm_rate ) {
2852 
2853  if (session->read_resampler) {
2856  switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_NOTICE, "Deactivating read resampler\n");
2858  }
2859 
2860  if (session->write_resampler) {
2863  switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_NOTICE, "Deactivating write resampler\n");
2865  }
2866 
2867  switch_core_session_reset(session, 0, 0);
2869 
2871  "Changing Codec from %s@%dms@%dhz to %s@%dms@%luhz\n",
2872  a_engine->read_impl.iananame,
2873  a_engine->read_impl.microseconds_per_packet / 1000,
2875 
2876  a_engine->cur_payload_map->iananame,
2877  a_engine->cur_payload_map->codec_ms,
2878  a_engine->cur_payload_map->rm_rate);
2879 
2883  resetting = 1;
2888  } else {
2889  switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_DEBUG, "Already using %s\n", a_engine->read_impl.iananame);
2891  }
2892  }
2893 
2894 
2896 
2898  a_engine->cur_payload_map->iananame,
2899  a_engine->cur_payload_map->modname,
2900  a_engine->cur_payload_map->rm_fmtp,
2901  a_engine->cur_payload_map->rm_rate,
2902  a_engine->cur_payload_map->codec_ms,
2903  a_engine->cur_payload_map->channels,
2904  a_engine->cur_payload_map->bitrate,
2907  switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_ERROR, "Can't load codec?\n");
2910  }
2911 
2912  a_engine->read_codec.session = session;
2913 
2914 
2916  a_engine->cur_payload_map->iananame,
2917  a_engine->cur_payload_map->modname,
2918  a_engine->cur_payload_map->rm_fmtp,
2919  a_engine->cur_payload_map->rm_rate,
2920  a_engine->cur_payload_map->codec_ms,
2921  a_engine->cur_payload_map->channels,
2922  a_engine->cur_payload_map->bitrate,
2925  switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_ERROR, "Can't load codec?\n");
2928  }
2929 
2930  a_engine->write_codec.session = session;
2931 
2932  if (switch_rtp_ready(a_engine->rtp_session)) {
2934  switch_rtp_reset_jb(a_engine->rtp_session);
2935  }
2936 
2937  switch_channel_set_variable(session->channel, "rtp_use_codec_name", a_engine->cur_payload_map->iananame);
2938  switch_channel_set_variable(session->channel, "rtp_use_codec_fmtp", a_engine->cur_payload_map->rm_fmtp);
2939  switch_channel_set_variable_printf(session->channel, "rtp_use_codec_rate", "%d", a_engine->cur_payload_map->rm_rate);
2940  switch_channel_set_variable_printf(session->channel, "rtp_use_codec_ptime", "%d", a_engine->cur_payload_map->codec_ms);
2941  switch_channel_set_variable_printf(session->channel, "rtp_use_codec_channels", "%d", a_engine->cur_payload_map->channels);
2942  switch_channel_set_variable_printf(session->channel, "rtp_last_audio_codec_string", "%s@%dh@%di@%dc",
2943  a_engine->cur_payload_map->iananame, a_engine->cur_payload_map->rm_rate, a_engine->cur_payload_map->codec_ms, a_engine->cur_payload_map->channels);
2944 
2947 
2948  a_engine->read_impl = *a_engine->read_codec.implementation;
2949  a_engine->write_impl = *a_engine->write_codec.implementation;
2950 
2953 
2954  if (switch_rtp_ready(a_engine->rtp_session)) {
2956 
2962  }
2963  }
2964 
2965  a_engine->read_frame.rate = a_engine->cur_payload_map->rm_rate;
2966 
2967  if (!switch_core_codec_ready(&a_engine->read_codec)) {
2968  switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_ERROR, "Can't load codec?\n");
2970  }
2971 
2972  switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_DEBUG, "Set Codec %s %s/%ld %d ms %d samples %d bits %d channels\n",
2974  a_engine->cur_payload_map->codec_ms,
2976  a_engine->read_frame.codec = &a_engine->read_codec;
2977  a_engine->read_frame.channels = a_engine->read_impl.number_of_channels;
2978  a_engine->write_codec.agreed_pt = a_engine->cur_payload_map->agreed_pt;
2979  a_engine->read_codec.agreed_pt = a_engine->cur_payload_map->agreed_pt;
2980 
2981  if (force != 2) {
2983  switch_core_session_set_write_codec(session, &a_engine->write_codec);
2984  }
2985 
2986  a_engine->cur_payload_map->fmtp_out = switch_core_session_strdup(session, a_engine->write_codec.fmtp_out);
2987 
2988  if (switch_rtp_ready(a_engine->rtp_session)) {
2990  }
2991 
2992  end:
2993 
2994  if (resetting) {
2997  }
2998 
2999  return status;
3000 }
switch_status_t switch_channel_set_variable_printf(switch_channel_t *channel, const char *varname, const char *fmt,...)
switch_core_session_t * session
#define switch_channel_hangup(channel, hangup_cause)
Hangup a channel flagging it's state machine to end.
switch_audio_resampler_t * write_resampler
#define SWITCH_CHANNEL_SESSION_LOG(x)
uint8_t switch_rtp_ready(switch_rtp_t *rtp_session)
Test if an RTP session is ready.
Definition: switch_rtp.c:4452
void switch_core_session_reset(_In_ switch_core_session_t *session, switch_bool_t flush_dtmf, switch_bool_t reset_read_codec)
Reset the buffers and resampler on a session.
unsigned long rm_rate
switch_status_t switch_core_session_set_read_impl(switch_core_session_t *session, const switch_codec_implementation_t *impp)
void switch_core_session_lock_codec_read(_In_ switch_core_session_t *session)
switch_codec_settings_t codec_settings
switch_status_t switch_core_codec_destroy(switch_codec_t *codec)
Destroy an initalized codec handle.
void switch_resample_destroy(switch_audio_resampler_t **resampler)
Destroy an existing resampler handle.
switch_codec_t * codec
Definition: switch_frame.h:45
static void switch_core_session_parse_codec_settings(switch_core_session_t *session, switch_media_type_t type)
switch_media_handle_t * media_handle
switch_status_t switch_mutex_unlock(switch_mutex_t *lock)
Definition: switch_apr.c:290
switch_frame_t read_frame
switch_codec_t write_codec
const switch_codec_implementation_t * implementation
#define switch_yield(ms)
Wait a desired number of microseconds and yield the CPU.
Definition: switch_utils.h:908
#define switch_channel_audio_sync(_c)
switch_channel_t * channel
switch_rtp_t * rtp_session
switch_audio_resampler_t * read_resampler
switch_codec_t read_codec
switch_status_t switch_mutex_lock(switch_mutex_t *lock)
Definition: switch_apr.c:285
uint32_t rate
Definition: switch_frame.h:63
payload_map_t * cur_payload_map
switch_mutex_t * resample_mutex
switch_payload_t pt
switch_payload_t agreed_pt
uint32_t bitrate
switch_status_t switch_core_codec_init_with_bitrate(switch_codec_t *codec, const char *codec_name, const char *fmtp, const char *modname, uint32_t rate, int ms, int channels, uint32_t bitrate, uint32_t flags, const switch_codec_settings_t *codec_settings, switch_memory_pool_t *pool)
switch_status_t
Common return values.
switch_rtp_engine_t engines[SWITCH_MEDIA_TYPE_TOTAL]
#define switch_goto_status(_status, _label)
Definition: switch_utils.h:256
void switch_core_session_lock_codec_write(_In_ switch_core_session_t *session)
void switch_rtp_reset_jb(switch_rtp_t *rtp_session)
Definition: switch_rtp.c:2769
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
uint32_t channels
Definition: switch_frame.h:65
switch_codec_implementation_t read_impl
switch_status_t switch_rtp_change_interval(switch_rtp_t *rtp_session, uint32_t ms_per_packet, uint32_t samples_per_interval)
Definition: switch_rtp.c:3687
switch_payload_t agreed_pt
switch_status_t switch_core_session_set_write_codec(_In_ switch_core_session_t *session, switch_codec_t *codec)
Assign the write codec to a given session.
static switch_bool_t switch_core_codec_ready(switch_codec_t *codec)
void switch_log_printf(_In_ switch_text_channel_t channel, _In_z_ const char *file, _In_z_ const char *func, _In_ int line, _In_opt_z_ const char *userdata, _In_ switch_log_level_t level, _In_z_ _Printf_format_string_ const char *fmt,...) PRINTF_FUNCTION(7
Write log data to the logging engine.
void switch_core_session_unlock_codec_write(_In_ switch_core_session_t *session)
#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_codec_implementation_t write_impl
char * switch_channel_get_name(switch_channel_t *channel)
Retrieve the name of a given channel.
switch_status_t switch_core_session_set_write_impl(switch_core_session_t *session, const switch_codec_implementation_t *impp)
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.
void switch_core_session_unlock_codec_read(_In_ switch_core_session_t *session)
switch_status_t switch_core_session_set_real_read_codec(_In_ switch_core_session_t *session, switch_codec_t *codec)
Assign the original read codec to a given session. This is the read codec used by an endpoint...
void switch_core_media_set_local_sdp ( switch_core_session_t session,
const char *  sdp_str,
switch_bool_t  dup 
)

Definition at line 7485 of file switch_core_media.c.

References switch_core_media_params_s::local_sdp_str, switch_media_handle_s::mparams, switch_media_handle_s::sdp_mutex, switch_assert, switch_channel_set_variable, switch_core_session_strdup, switch_mutex_lock(), and switch_mutex_unlock().

Referenced by switch_core_media_absorb_sdp(), switch_core_media_gen_local_sdp(), switch_core_media_patch_sdp(), switch_core_media_receive_message(), and switch_core_media_set_udptl_image_sdp().

7486 {
7487  switch_media_handle_t *smh;
7488 
7489  switch_assert(session);
7490 
7491  if (!(smh = session->media_handle)) {
7492  return;
7493  }
7494 
7495  if (smh->sdp_mutex) switch_mutex_lock(smh->sdp_mutex);
7496  smh->mparams->local_sdp_str = dup ? switch_core_session_strdup(session, sdp_str) : (char *) sdp_str;
7497  switch_channel_set_variable(session->channel, "rtp_local_sdp_str", smh->mparams->local_sdp_str);
7498  if (smh->sdp_mutex) switch_mutex_unlock(smh->sdp_mutex);
7499 }
switch_media_handle_t * media_handle
switch_status_t switch_mutex_unlock(switch_mutex_t *lock)
Definition: switch_apr.c:290
switch_channel_t * channel
switch_status_t switch_mutex_lock(switch_mutex_t *lock)
Definition: switch_apr.c:285
#define switch_core_session_strdup(_session, _todup)
Copy a string using memory allocation from a session's pool.
Definition: switch_core.h:717
switch_mutex_t * sdp_mutex
#define switch_assert(expr)
#define switch_channel_set_variable(_channel, _var, _val)
switch_core_media_params_t * mparams
switch_status_t switch_core_media_set_outgoing_bitrate ( switch_core_session_t session,
switch_media_type_t  type,
uint32_t  bitrate 
)

Definition at line 9231 of file switch_core_media.c.

References switch_media_handle_s::engines, SCC_VIDEO_BANDWIDTH, SCCT_INT, SCCT_NONE, switch_channel_down, switch_core_codec_control(), switch_core_codec_ready(), SWITCH_STATUS_FALSE, and switch_rtp_engine_s::write_codec.

9232 {
9233  switch_media_handle_t *smh;
9234  switch_rtp_engine_t *engine;
9236 
9237  if (!(smh = session->media_handle)) {
9238  return SWITCH_STATUS_FALSE;
9239  }
9240 
9241  if (switch_channel_down(session->channel)) {
9242  return SWITCH_STATUS_FALSE;
9243  }
9244 
9245  engine = &smh->engines[type];
9246 
9247  if (switch_core_codec_ready(&engine->write_codec)) {
9249  SCCT_INT, &bitrate, SCCT_NONE, NULL, NULL, NULL);
9250  }
9251 
9252  return status;
9253 }
switch_media_handle_t * media_handle
switch_codec_t write_codec
switch_channel_t * channel
#define switch_channel_down(_channel)
switch_status_t
Common return values.
switch_rtp_engine_t engines[SWITCH_MEDIA_TYPE_TOTAL]
static switch_bool_t switch_core_codec_ready(switch_codec_t *codec)
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_set_rtp_flag ( switch_core_session_t session,
switch_media_type_t  type,
switch_rtp_flag_t  flag 
)

Definition at line 9831 of file switch_core_media.c.

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

9832 {
9833  switch_media_handle_t *smh;
9834 
9835  switch_assert(session);
9836 
9837  if (!(smh = session->media_handle)) {
9838  return;
9839  }
9840 
9841  if (switch_rtp_ready(smh->engines[type].rtp_session)) {
9842  switch_rtp_set_flag(smh->engines[type].rtp_session, flag);
9843  }
9844 }
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_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)
void switch_core_media_set_rtp_session ( switch_core_session_t session,
switch_media_type_t  type,
switch_rtp_t rtp_session 
)

Definition at line 1151 of file switch_core_media.c.

References switch_rtp_engine_s::rtp_session, and switch_rtp_engine_s::type.

1152 {
1153  switch_rtp_engine_t *engine;
1154  if (!session->media_handle) return;
1155  engine = &session->media_handle->engines[type];
1156  engine->rtp_session = rtp_session;
1157  engine->type = type;
1158 }
switch_media_handle_t * media_handle
switch_rtp_t * rtp_session
switch_rtp_engine_t engines[SWITCH_MEDIA_TYPE_TOTAL]
switch_media_type_t type
void switch_core_media_set_sdp_codec_string ( switch_core_session_t session,
const char *  r_sdp,
switch_sdp_type_t  sdp_type 
)

Definition at line 9968 of file switch_core_media.c.

References switch_assert, switch_core_media_get_codec_string(), and switch_core_media_set_r_sdp_codec_string().

9969 {
9970  sdp_parser_t *parser;
9971  sdp_session_t *sdp;
9972  switch_media_handle_t *smh;
9973 
9974  switch_assert(session);
9975 
9976  if (!(smh = session->media_handle)) {
9977  return;
9978  }
9979 
9980 
9981  if ((parser = sdp_parse(NULL, r_sdp, (int) strlen(r_sdp), 0))) {
9982 
9983  if ((sdp = sdp_session(parser))) {
9985  }
9986 
9987  sdp_parser_free(parser);
9988  }
9989 
9990 }
static void switch_core_media_set_r_sdp_codec_string(switch_core_session_t *session, const char *codec_string, sdp_session_t *sdp, switch_sdp_type_t sdp_type)
switch_media_handle_t * media_handle
const char * switch_core_media_get_codec_string(switch_core_session_t *session)
#define switch_assert(expr)
void switch_core_media_set_stats ( switch_core_session_t session)

Definition at line 1562 of file switch_core_media.c.

References set_stats(), switch_core_media_sync_stats(), SWITCH_MEDIA_TYPE_AUDIO, and SWITCH_MEDIA_TYPE_VIDEO.

Referenced by switch_core_session_hangup_state(), and switch_core_standard_on_hangup().

1563 {
1564 
1565  if (!session->media_handle) {
1566  return;
1567  }
1568 
1570 
1571  set_stats(session, SWITCH_MEDIA_TYPE_AUDIO, "audio");
1572  set_stats(session, SWITCH_MEDIA_TYPE_VIDEO, "video");
1573 }
switch_media_handle_t * media_handle
static void set_stats(switch_core_session_t *session, switch_media_type_t type, const char *prefix)
void switch_core_media_sync_stats(switch_core_session_t *session)
void switch_core_media_set_telephony_event ( switch_core_session_t session,
switch_media_type_t  type,
switch_payload_t  te 
)

Definition at line 9863 of file switch_core_media.c.

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

9864 {
9865  switch_media_handle_t *smh;
9866 
9867  switch_assert(session);
9868 
9869  if (!(smh = session->media_handle)) {
9870  return;
9871  }
9872 
9873  if (switch_rtp_ready(smh->engines[type].rtp_session)) {
9875  }
9876 }
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
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
switch_rtp_t * rtp_session
switch_rtp_engine_t engines[SWITCH_MEDIA_TYPE_TOTAL]
#define switch_assert(expr)
void switch_core_media_set_telephony_recv_event ( switch_core_session_t session,
switch_media_type_t  type,
switch_payload_t  te 
)

Definition at line 9879 of file switch_core_media.c.

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

9880 {
9881  switch_media_handle_t *smh;
9882 
9883  switch_assert(session);
9884 
9885  if (!(smh = session->media_handle)) {
9886  return;
9887  }
9888 
9889  if (switch_rtp_ready(smh->engines[type].rtp_session)) {
9891  }
9892 }
uint8_t switch_rtp_ready(switch_rtp_t *rtp_session)
Test if an RTP session is ready.
Definition: switch_rtp.c:4452
void switch_rtp_set_telephony_recv_event(switch_rtp_t *rtp_session, switch_payload_t te)
Definition: switch_rtp.c:4022
switch_media_handle_t * media_handle
switch_rtp_t * rtp_session
switch_rtp_engine_t engines[SWITCH_MEDIA_TYPE_TOTAL]
#define switch_assert(expr)
void switch_core_media_set_udptl_image_sdp ( switch_core_session_t session,
switch_t38_options_t t38_options,
int  insist 
)

Definition at line 8643 of file switch_core_media.c.

References switch_rtp_engine_s::adv_sdp_ip, switch_rtp_engine_s::adv_sdp_port, buf, switch_media_handle_s::engines, switch_core_media_params_s::local_sdp_str, switch_media_handle_s::mparams, switch_media_handle_s::owner_id, switch_rtp_engine_s::proxy_sdp_ip, switch_rtp_engine_s::proxy_sdp_port, switch_core_media_params_s::sdp_username, switch_media_handle_s::session_id, switch_assert, switch_channel_get_name(), switch_channel_get_variable, SWITCH_CHANNEL_LOG, SWITCH_CHANNEL_SESSION_LOG, switch_core_media_set_local_sdp(), switch_epoch_time_now(), SWITCH_LOG_CRIT, SWITCH_LOG_DEBUG, switch_log_printf(), SWITCH_MEDIA_TYPE_AUDIO, switch_snprintf(), SWITCH_TRUE, and switch_true().

8644 {
8645  char buf[2048] = "";
8646  char max_buf[128] = "";
8647  char max_data[128] = "";
8648  const char *ip;
8649  uint32_t port;
8650  const char *family = "IP4";
8651  const char *username;
8652  const char *bit_removal_on = "a=T38FaxFillBitRemoval\r\n";
8653  const char *bit_removal_off = "";
8654 
8655  const char *mmr_on = "a=T38FaxTranscodingMMR\r\n";
8656  const char *mmr_off = "";
8657 
8658  const char *jbig_on = "a=T38FaxTranscodingJBIG\r\n";
8659  const char *jbig_off = "";
8660  const char *var;
8661  int broken_boolean;
8662  switch_media_handle_t *smh;
8663  switch_rtp_engine_t *a_engine;
8664 
8665  switch_assert(session);
8666 
8667  if (!(smh = session->media_handle)) {
8668  return;
8669  }
8670 
8671  a_engine = &smh->engines[SWITCH_MEDIA_TYPE_AUDIO];
8672 
8673 
8674  switch_assert(t38_options);
8675 
8676  ip = t38_options->local_ip;
8677  port = t38_options->local_port;
8678  username = smh->mparams->sdp_username;
8679 
8680  var = switch_channel_get_variable(session->channel, "t38_broken_boolean");
8681 
8682  broken_boolean = switch_true(var);
8683 
8684 
8685  if (!ip) {
8686  if (!(ip = a_engine->adv_sdp_ip)) {
8687  ip = a_engine->proxy_sdp_ip;
8688  }
8689  }
8690 
8691  if (!ip) {
8693  return;
8694  }
8695 
8696  if (!port) {
8697  if (!(port = a_engine->adv_sdp_port)) {
8698  port = a_engine->proxy_sdp_port;
8699  }
8700  }
8701 
8702  if (!port) {
8704  return;
8705  }
8706 
8707  if (!smh->owner_id) {
8708  smh->owner_id = (uint32_t) switch_epoch_time_now(NULL) - port;
8709  }
8710 
8711  if (!smh->session_id) {
8712  smh->session_id = smh->owner_id;
8713  }
8714 
8715  smh->session_id++;
8716 
8717  family = strchr(ip, ':') ? "IP6" : "IP4";
8718 
8719 
8720  switch_snprintf(buf, sizeof(buf),
8721  "v=0\r\n"
8722  "o=%s %010u %010u IN %s %s\r\n"
8723  "s=%s\r\n" "c=IN %s %s\r\n" "t=0 0\r\n", username, smh->owner_id, smh->session_id, family, ip, username, family, ip);
8724 
8725  if (t38_options->T38FaxMaxBuffer) {
8726  switch_snprintf(max_buf, sizeof(max_buf), "a=T38FaxMaxBuffer:%d\r\n", t38_options->T38FaxMaxBuffer);
8727  };
8728 
8729  if (t38_options->T38FaxMaxDatagram) {
8730  switch_snprintf(max_data, sizeof(max_data), "a=T38FaxMaxDatagram:%d\r\n", t38_options->T38FaxMaxDatagram);
8731  };
8732 
8733 
8734 
8735 
8736  if (broken_boolean) {
8737  bit_removal_on = "a=T38FaxFillBitRemoval:1\r\n";
8738  bit_removal_off = "a=T38FaxFillBitRemoval:0\r\n";
8739 
8740  mmr_on = "a=T38FaxTranscodingMMR:1\r\n";
8741  mmr_off = "a=T38FaxTranscodingMMR:0\r\n";
8742 
8743  jbig_on = "a=T38FaxTranscodingJBIG:1\r\n";
8744  jbig_off = "a=T38FaxTranscodingJBIG:0\r\n";
8745 
8746  }
8747 
8748 
8749  switch_snprintf(buf + strlen(buf), sizeof(buf) - strlen(buf),
8750  "m=image %d udptl t38\r\n"
8751  "a=T38FaxVersion:%d\r\n"
8752  "a=T38MaxBitRate:%d\r\n"
8753  "%s"
8754  "%s"
8755  "%s"
8756  "a=T38FaxRateManagement:%s\r\n"
8757  "%s"
8758  "%s"
8759  "a=T38FaxUdpEC:%s\r\n",
8760  //"a=T38VendorInfo:%s\r\n",
8761  port,
8762  t38_options->T38FaxVersion,
8763  t38_options->T38MaxBitRate,
8764  t38_options->T38FaxFillBitRemoval ? bit_removal_on : bit_removal_off,
8765  t38_options->T38FaxTranscodingMMR ? mmr_on : mmr_off,
8766  t38_options->T38FaxTranscodingJBIG ? jbig_on : jbig_off,
8767  t38_options->T38FaxRateManagement,
8768  max_buf,
8769  max_data,
8770  t38_options->T38FaxUdpEC
8771  //t38_options->T38VendorInfo ? t38_options->T38VendorInfo : "0 0 0"
8772  );
8773 
8774 
8775 
8776  if (insist) {
8777  switch_snprintf(buf + strlen(buf), sizeof(buf) - strlen(buf), "m=audio 0 RTP/AVP 19\r\n");
8778  }
8779 
8781 
8782 
8783  switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_DEBUG, "%s image media sdp:\n%s\n",
8785 
8786 
8787 }
#define SWITCH_CHANNEL_SESSION_LOG(x)
#define SWITCH_CHANNEL_LOG
switch_bool_t T38FaxTranscodingMMR
const char * T38FaxRateManagement
switch_bool_t T38FaxTranscodingJBIG
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
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)
switch_byte_t switch_byte_t * buf
switch_channel_t * channel
#define switch_channel_get_variable(_c, _v)
const char * T38FaxUdpEC
switch_rtp_engine_t engines[SWITCH_MEDIA_TYPE_TOTAL]
switch_port_t adv_sdp_port
time_t switch_epoch_time_now(time_t *t)
Get the current epoch time.
Definition: switch_time.c:321
void switch_log_printf(_In_ switch_text_channel_t channel, _In_z_ const char *file, _In_z_ const char *func, _In_ int line, _In_opt_z_ const char *userdata, _In_ switch_log_level_t level, _In_z_ _Printf_format_string_ const char *fmt,...) PRINTF_FUNCTION(7
Write log data to the logging engine.
switch_bool_t T38FaxFillBitRemoval
switch_port_t proxy_sdp_port
#define switch_assert(expr)
char * switch_channel_get_name(switch_channel_t *channel)
Retrieve the name of a given channel.
switch_core_media_params_t * mparams
const char * local_ip
switch_status_t switch_core_media_set_video_codec ( switch_core_session_t session,
int  force 
)

Definition at line 2720 of file switch_core_media.c.

References switch_codec::agreed_pt, payload_map_s::agreed_pt, switch_frame::codec, payload_map_s::codec_ms, switch_rtp_engine_s::codec_negotiated, switch_rtp_engine_s::codec_settings, switch_rtp_engine_s::cur_payload_map, switch_media_handle_s::engines, switch_codec::fmtp_out, switch_core_session_message::from, switch_codec_implementation::iananame, switch_codec::implementation, switch_core_session_message::message_id, payload_map_s::modname, switch_frame::rate, switch_rtp_engine_s::read_codec, switch_rtp_engine_s::read_frame, payload_map_s::rm_encoding, payload_map_s::rm_fmtp, payload_map_s::rm_rate, switch_rtp_engine_s::rtp_session, switch_codec_implementation::samples_per_second, switch_assert, switch_channel_get_name(), SWITCH_CHANNEL_SESSION_LOG, switch_channel_set_variable, switch_channel_set_variable_printf(), SWITCH_CODEC_FLAG_DECODE, SWITCH_CODEC_FLAG_ENCODE, switch_core_codec_destroy(), switch_core_codec_init, switch_core_codec_ready(), switch_core_session_get_pool(), switch_core_session_parse_codec_settings(), switch_core_session_receive_message, switch_core_session_set_video_read_codec(), switch_core_session_set_video_write_codec(), switch_core_session_strdup, SWITCH_LOG_DEBUG, SWITCH_LOG_ERROR, switch_log_printf(), SWITCH_MEDIA_TYPE_VIDEO, SWITCH_MESSAGE_INDICATE_VIDEO_REFRESH_REQ, switch_rtp_ready(), switch_rtp_set_default_payload(), SWITCH_STATUS_FALSE, SWITCH_STATUS_SUCCESS, and switch_rtp_engine_s::write_codec.

Referenced by switch_core_media_activate_rtp(), switch_core_media_gen_local_sdp(), switch_core_media_negotiate_sdp(), switch_core_media_patch_sdp(), switch_core_media_read_frame(), and switch_core_media_recover_session().

2721 {
2722  switch_media_handle_t *smh;
2723  switch_rtp_engine_t *v_engine;
2724 
2725  switch_assert(session);
2726 
2727  if (!(smh = session->media_handle)) {
2728  return SWITCH_STATUS_FALSE;
2729  }
2730  v_engine = &smh->engines[SWITCH_MEDIA_TYPE_VIDEO];
2731 
2732 
2733  if (!v_engine->codec_negotiated) {
2734  return SWITCH_STATUS_FALSE;
2735  }
2736 
2737  if (v_engine->read_codec.implementation && switch_core_codec_ready(&v_engine->read_codec)) {
2738  if (!force) {
2739  return SWITCH_STATUS_SUCCESS;
2740  }
2741  if (strcasecmp(v_engine->read_codec.implementation->iananame, v_engine->cur_payload_map->rm_encoding) ||
2743 
2744  switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_DEBUG, "Changing Codec from %s to %s\n",
2748  } else {
2749  switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_DEBUG, "Already using %s\n",
2750  v_engine->read_codec.implementation->iananame);
2751  return SWITCH_STATUS_SUCCESS;
2752  }
2753  }
2754 
2756 
2757  if (switch_core_codec_init(&v_engine->read_codec,
2758  v_engine->cur_payload_map->rm_encoding,
2759  v_engine->cur_payload_map->modname,
2760  v_engine->cur_payload_map->rm_fmtp,
2761  v_engine->cur_payload_map->rm_rate,
2762  0,
2763  1,
2766  switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_ERROR, "Can't load codec?\n");
2767  return SWITCH_STATUS_FALSE;
2768  } else {
2769  if (switch_core_codec_init(&v_engine->write_codec,
2770  v_engine->cur_payload_map->rm_encoding,
2771  v_engine->cur_payload_map->modname,
2772  v_engine->cur_payload_map->rm_fmtp,
2773  v_engine->cur_payload_map->rm_rate,
2774  0,
2775  1,
2778  switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_ERROR, "Can't load codec?\n");
2779  return SWITCH_STATUS_FALSE;
2780  } else {
2781  v_engine->read_frame.rate = v_engine->cur_payload_map->rm_rate;
2782  switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_DEBUG, "Set VIDEO Codec %s %s/%ld %d ms\n",
2784  v_engine->cur_payload_map->rm_rate, v_engine->cur_payload_map->codec_ms);
2785  v_engine->read_frame.codec = &v_engine->read_codec;
2786 
2787  v_engine->write_codec.fmtp_out = switch_core_session_strdup(session, v_engine->write_codec.fmtp_out);
2788 
2789  v_engine->write_codec.agreed_pt = v_engine->cur_payload_map->agreed_pt;
2790  v_engine->read_codec.agreed_pt = v_engine->cur_payload_map->agreed_pt;
2793 
2794 
2795  switch_channel_set_variable_printf(session->channel, "rtp_last_video_codec_string", "%s@%dh",
2796  v_engine->cur_payload_map->rm_encoding, v_engine->cur_payload_map->rm_rate);
2797 
2798 
2799  if (switch_rtp_ready(v_engine->rtp_session)) {
2800  switch_core_session_message_t msg = { 0 };
2801 
2802  msg.from = __FILE__;
2804 
2806 
2807  //XX
2808 
2809  switch_core_session_receive_message(session, &msg);
2810 
2811 
2812  }
2813 
2814  switch_channel_set_variable(session->channel, "rtp_use_video_codec_name", v_engine->cur_payload_map->rm_encoding);
2815  switch_channel_set_variable(session->channel, "rtp_use_video_codec_fmtp", v_engine->cur_payload_map->rm_fmtp);
2816  switch_channel_set_variable_printf(session->channel, "rtp_use_video_codec_rate", "%d", v_engine->cur_payload_map->rm_rate);
2817  switch_channel_set_variable_printf(session->channel, "rtp_use_video_codec_ptime", "%d", 0);
2818  }
2819  }
2820  return SWITCH_STATUS_SUCCESS;
2821 }
switch_status_t switch_channel_set_variable_printf(switch_channel_t *channel, const char *varname, const char *fmt,...)
#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_core_session_message_types_t message_id
Definition: switch_core.h:181
unsigned long rm_rate
switch_status_t switch_core_session_set_video_read_codec(_In_ switch_core_session_t *session, switch_codec_t *codec)
Assign the video_read codec to a given session.
switch_status_t switch_core_session_set_video_write_codec(_In_ switch_core_session_t *session, switch_codec_t *codec)
Assign the video_write codec to a given session.
switch_codec_settings_t codec_settings
switch_status_t switch_core_codec_destroy(switch_codec_t *codec)
Destroy an initalized codec handle.
switch_codec_t * codec
Definition: switch_frame.h:45
A message object designed to allow unlike technologies to exchange data.
Definition: switch_core.h:177
static void switch_core_session_parse_codec_settings(switch_core_session_t *session, switch_media_type_t type)
switch_media_handle_t * media_handle
switch_frame_t read_frame
switch_codec_t write_codec
const switch_codec_implementation_t * implementation
switch_channel_t * channel
switch_rtp_t * rtp_session
switch_codec_t read_codec
uint32_t rate
Definition: switch_frame.h:63
payload_map_t * cur_payload_map
#define switch_core_codec_init(_codec, _codec_name, _modname, _fmtp, _rate, _ms, _channels, _flags, _codec_settings, _pool)
Initialize a codec handle.
Definition: switch_core.h:1602
switch_payload_t agreed_pt
#define switch_core_session_receive_message(_session, _message)
Definition: switch_core.h:1217
switch_rtp_engine_t engines[SWITCH_MEDIA_TYPE_TOTAL]
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_payload_t agreed_pt
static switch_bool_t switch_core_codec_ready(switch_codec_t *codec)
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)
char * switch_channel_get_name(switch_channel_t *channel)
Retrieve the name of a given channel.
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.
char * rm_encoding
switch_status_t switch_core_media_set_video_file ( switch_core_session_t session,
switch_file_handle_t fh,
switch_rw_t  rw 
)

Definition at line 5209 of file switch_core_media.c.

References CF_VIDEO, CF_VIDEO_DECODED_READ, CF_VIDEO_READ_FILE_ATTACHED, CF_VIDEO_WRITE_FILE_ATTACHED, switch_media_handle_s::engines, media_helper::file_read_mutex, media_helper::file_write_mutex, switch_rtp_engine_s::mh, switch_assert, switch_channel_clear_flag(), switch_channel_clear_flag_recursive(), SWITCH_CHANNEL_SESSION_LOG, switch_channel_set_flag, switch_channel_set_flag_recursive(), switch_channel_test_flag(), switch_channel_video_sync, switch_core_file_has_video(), switch_core_media_gen_key_frame, switch_core_session_get_pool(), switch_core_session_start_video_thread(), switch_core_session_video_reset(), switch_core_session_wake_video_thread(), SWITCH_LOG_ERROR, switch_log_printf(), SWITCH_MEDIA_TYPE_VIDEO, switch_mutex_lock(), switch_mutex_unlock(), SWITCH_RW_READ, SWITCH_STATUS_FALSE, SWITCH_STATUS_SUCCESS, switch_thread_create(), switch_thread_join(), SWITCH_THREAD_STACKSIZE, switch_threadattr_create(), switch_threadattr_stacksize_set(), SWITCH_TRUE, switch_media_handle_s::video_read_fh, switch_media_handle_s::video_write_fh, switch_media_handle_s::video_write_thread, video_write_thread(), and switch_media_handle_s::video_write_thread_running.

Referenced by switch_ivr_play_file(), and switch_ivr_record_file().

5210 {
5211  switch_media_handle_t *smh;
5212  switch_rtp_engine_t *v_engine;
5213 
5214  switch_assert(session);
5215 
5216  if (!(smh = session->media_handle)) {
5217  return SWITCH_STATUS_FALSE;
5218  }
5219 
5220  if (!smh->video_read_fh && !smh->video_read_fh && !switch_channel_test_flag(session->channel, CF_VIDEO)) {
5221  return SWITCH_STATUS_FALSE;
5222  }
5223 
5224  if (fh && !switch_core_file_has_video(fh, SWITCH_TRUE)) {
5225  return SWITCH_STATUS_FALSE;
5226  }
5227 
5228  v_engine = &smh->engines[SWITCH_MEDIA_TYPE_VIDEO];
5229 
5231 
5232  //if (!v_engine->media_thread) {
5233  // return SWITCH_STATUS_FALSE;
5234  //}
5235 
5236 
5237 
5238  if (rw == SWITCH_RW_READ) {
5240 
5241  if (fh && smh->video_read_fh) {
5242  switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_ERROR, "File is already open\n");
5244  return SWITCH_STATUS_FALSE;
5245  }
5246 
5247 
5248  if (fh) {
5251  } else if (smh->video_read_fh) {
5254  }
5255 
5256  if (!fh) {
5258  }
5259 
5260  smh->video_read_fh = fh;
5261 
5263 
5264  } else {
5266  if (fh && smh->video_write_fh) {
5267  switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_ERROR, "File is already open\n");
5268  smh->video_write_fh = fh;
5270  return SWITCH_STATUS_SUCCESS;
5271  }
5272 
5273  if (fh) {
5275  } else {
5277  }
5278 
5280 
5281  if (fh) {
5282  switch_threadattr_t *thd_attr = NULL;
5283 
5286  smh->video_write_thread_running = 1;
5288  }
5289 
5290  if (!fh && smh->video_write_thread) {
5291  switch_status_t st;
5292 
5293  if (smh->video_write_thread_running > 0) {
5294  smh->video_write_thread_running = -1;
5295  }
5299  smh->video_write_thread = NULL;
5300  }
5301 
5302  smh->video_write_fh = fh;
5303 
5305  }
5306 
5307  if (!fh) switch_channel_video_sync(session->channel);
5308 
5310 
5311 
5312  return SWITCH_STATUS_SUCCESS;
5313 }
switch_status_t switch_core_session_start_video_thread(switch_core_session_t *session)
#define switch_core_media_gen_key_frame(_session)
void switch_channel_set_flag_recursive(switch_channel_t *channel, switch_channel_flag_t flag)
#define SWITCH_CHANNEL_SESSION_LOG(x)
switch_status_t switch_threadattr_stacksize_set(switch_threadattr_t *attr, switch_size_t stacksize)
Definition: switch_apr.c:660
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_thread_t * video_write_thread
switch_status_t switch_mutex_unlock(switch_mutex_t *lock)
Definition: switch_apr.c:290
static void *SWITCH_THREAD_FUNC video_write_thread(switch_thread_t *thread, void *obj)
switch_status_t switch_thread_join(switch_status_t *retval, switch_thread_t *thd)
Definition: switch_apr.c:1255
switch_channel_t * channel
switch_status_t switch_mutex_lock(switch_mutex_t *lock)
Definition: switch_apr.c:285
#define SWITCH_THREAD_STACKSIZE
Definition: switch_types.h:551
#define switch_channel_video_sync(_c)
switch_mutex_t * file_write_mutex
void switch_core_session_video_reset(switch_core_session_t *session)
switch_status_t
Common return values.
switch_rtp_engine_t engines[SWITCH_MEDIA_TYPE_TOTAL]
switch_mutex_t * file_read_mutex
#define switch_channel_set_flag(_c, _f)
switch_bool_t switch_core_file_has_video(switch_file_handle_t *fh, switch_bool_t CHECK_OPEN)
void switch_core_session_wake_video_thread(switch_core_session_t *session)
switch_file_handle_t * video_write_fh
switch_file_handle_t * video_read_fh
void switch_channel_clear_flag_recursive(switch_channel_t *channel, switch_channel_flag_t flag)
void switch_log_printf(_In_ switch_text_channel_t channel, _In_z_ const char *file, _In_z_ const char *func, _In_ int line, _In_opt_z_ const char *userdata, _In_ switch_log_level_t level, _In_z_ _Printf_format_string_ const char *fmt,...) PRINTF_FUNCTION(7
Write log data to the logging engine.
switch_status_t switch_threadattr_create(switch_threadattr_t **new_attr, switch_memory_pool_t *pool)
Definition: switch_apr.c:642
switch_status_t switch_thread_create(switch_thread_t **new_thread, switch_threadattr_t *attr, switch_thread_start_t func, void *data, switch_memory_pool_t *cont)
Definition: switch_apr.c:675
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_memory_pool_t * switch_core_session_get_pool(_In_ switch_core_session_t *session)
Retrieve the memory pool from a session.
void switch_core_media_start_udptl ( switch_core_session_t session,
switch_t38_options_t t38_options 
)

Definition at line 9112 of file switch_core_media.c.

References CF_AVPF, CF_NOTIMER_DURING_BRIDGE, switch_media_handle_s::engines, switch_rtp::remote_port, switch_rtp_engine_s::rtp_session, SCMF_DISABLE_RTP_AUTOADJ, switch_assert, switch_channel_clear_flag(), switch_channel_down, switch_channel_get_variable, SWITCH_CHANNEL_SESSION_LOG, switch_channel_test_flag(), SWITCH_LOG_DEBUG, SWITCH_LOG_ERROR, switch_log_printf(), switch_media_handle_test_media_flag(), SWITCH_MEDIA_TYPE_AUDIO, SWITCH_RTP_FLAG_AUTOADJ, switch_rtp_get_remote_host(), switch_rtp_get_remote_port(), switch_rtp_ready(), switch_rtp_set_flag(), switch_rtp_set_remote_address(), switch_rtp_udptl_mode(), SWITCH_STATUS_SUCCESS, SWITCH_TRUE, and switch_true().

Referenced by switch_core_media_receive_message().

9113 {
9114  switch_media_handle_t *smh;
9115  switch_rtp_engine_t *a_engine;
9116 
9117  switch_assert(session);
9118 
9119  if (!(smh = session->media_handle)) {
9120  return;
9121  }
9122 
9123  if (switch_channel_down(session->channel)) {
9124  return;
9125  }
9126 
9127  a_engine = &smh->engines[SWITCH_MEDIA_TYPE_AUDIO];
9128 
9129 
9130  if (switch_rtp_ready(a_engine->rtp_session)) {
9131  char *remote_host = switch_rtp_get_remote_host(a_engine->rtp_session);
9132  switch_port_t remote_port = switch_rtp_get_remote_port(a_engine->rtp_session);
9133  const char *err, *val;
9134 
9137 
9138  if (!t38_options || !t38_options->remote_ip) {
9139  switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_DEBUG, "No remote address\n");
9140  return;
9141  }
9142 
9143  if (remote_host && remote_port && remote_port == t38_options->remote_port && !strcmp(remote_host, t38_options->remote_ip)) {
9144  switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_DEBUG, "Remote address:port [%s:%d] has not changed.\n",
9145  t38_options->remote_ip, t38_options->remote_port);
9146  return;
9147  }
9148 
9149  if (switch_rtp_set_remote_address(a_engine->rtp_session, t38_options->remote_ip,
9150  t38_options->remote_port, 0, SWITCH_TRUE, &err) != SWITCH_STATUS_SUCCESS) {
9151  switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_ERROR, "IMAGE UDPTL REPORTS ERROR: [%s]\n", err);
9152  } else {
9153  switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_DEBUG, "IMAGE UDPTL CHANGING DEST TO: [%s:%d]\n",
9154  t38_options->remote_ip, t38_options->remote_port);
9156  !((val = switch_channel_get_variable(session->channel, "disable_udptl_auto_adjust")) && switch_true(val))) {
9157  /* Reactivate the NAT buster flag. */
9159  }
9160  }
9161  }
9162 }
#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
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_port_t switch_rtp_get_remote_port(switch_rtp_t *rtp_session)
Definition: switch_rtp.c:2827
switch_media_handle_t * media_handle
switch_status_t switch_rtp_udptl_mode(switch_rtp_t *rtp_session)
Definition: switch_rtp.c:2843
switch_channel_t * channel
switch_rtp_t * rtp_session
#define switch_channel_get_variable(_c, _v)
uint16_t switch_port_t
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
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)
char * switch_rtp_get_remote_host(switch_rtp_t *rtp_session)
Definition: switch_rtp.c:2822
switch_rtp_engine_t engines[SWITCH_MEDIA_TYPE_TOTAL]
const char * remote_ip
void switch_log_printf(_In_ switch_text_channel_t channel, _In_z_ const char *file, _In_z_ const char *func, _In_ int line, _In_opt_z_ const char *userdata, _In_ switch_log_level_t level, _In_z_ _Printf_format_string_ const char *fmt,...) PRINTF_FUNCTION(7
Write log data to the logging engine.
void switch_channel_clear_flag(switch_channel_t *channel, switch_channel_flag_t flag)
Clear given flag(s) from a channel.
#define switch_assert(expr)
void switch_core_media_start_video_function ( switch_core_session_t session,
switch_video_function_t  video_function,
void *  user_data 
)

Definition at line 5540 of file switch_core_media.c.

References switch_media_handle_s::control_mutex, switch_core_session_start_video_thread(), switch_core_session_video_reset(), switch_mutex_lock(), switch_mutex_unlock(), switch_media_handle_s::video_function, switch_media_handle_s::video_function_running, and switch_media_handle_s::video_user_data.

5541 {
5542  switch_media_handle_t *smh;
5543 
5544  if (!(smh = session->media_handle)) {
5545  return;
5546  }
5547 
5549 
5551  if (!smh->video_function_running) {
5552  smh->video_function = video_function;
5553  smh->video_user_data = user_data;
5555  }
5557 }
switch_status_t switch_core_session_start_video_thread(switch_core_session_t *session)
switch_video_function_t video_function
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
void switch_core_session_video_reset(switch_core_session_t *session)
switch_rtp_stats_t* switch_core_media_stats ( switch_core_session_t session,
switch_media_type_t  type,
switch_memory_pool_t pool 
)
void switch_core_media_sync_stats ( switch_core_session_t session)

Definition at line 1538 of file switch_core_media.c.

References switch_media_handle_s::engines, switch_rtp_engine_s::rtp_session, switch_assert, SWITCH_MEDIA_TYPE_AUDIO, SWITCH_MEDIA_TYPE_VIDEO, and switch_rtp_sync_stats().

Referenced by switch_core_media_set_stats().

1539 {
1540  switch_media_handle_t *smh;
1541  switch_rtp_engine_t *a_engine, *v_engine;
1542 
1543  switch_assert(session);
1544 
1545  if (!(smh = session->media_handle)) {
1546  return;
1547  }
1548 
1549  a_engine = &smh->engines[SWITCH_MEDIA_TYPE_AUDIO];
1550  v_engine = &smh->engines[SWITCH_MEDIA_TYPE_VIDEO];
1551 
1552  if (a_engine->rtp_session) {
1554  }
1555 
1556  if (v_engine->rtp_session) {
1558  }
1559 
1560 }
switch_media_handle_t * media_handle
switch_rtp_t * rtp_session
switch_rtp_engine_t engines[SWITCH_MEDIA_TYPE_TOTAL]
#define switch_assert(expr)
switch_status_t switch_rtp_sync_stats(switch_rtp_t *rtp_session)
Definition: switch_rtp.c:4468
int switch_core_media_toggle_hold ( switch_core_session_t session,
int  sendonly 
)

Definition at line 4872 of file switch_core_media.c.

References CF_ANSWERED, CF_BROADCAST, CF_BYPASS_MEDIA_AFTER_HOLD, CF_EVENT_LOCK_PRI, CF_HOLD, CF_HOLD_LOCK, CF_PROTO_HOLD, CF_SLA_BARGE, CF_SLA_BARGING, CF_SUSPEND, switch_media_handle_s::engines, switch_rtp_engine_s::max_missed_hold_packets, switch_rtp_engine_s::max_missed_packets, switch_rtp_engine_s::rtp_session, SMF_ECHO_ALEG, SMF_LOOP, SMF_PRIORITY, SMF_REBRIDGE, switch_assert, switch_channel_clear_flag(), switch_channel_get_hold_music(), switch_channel_get_variable, switch_channel_get_variable_dup(), switch_channel_mark_hold(), switch_channel_presence, switch_channel_set_flag, switch_channel_stop_broadcast, switch_channel_test_flag(), switch_channel_wait_for_flag(), switch_core_media_check_autoadj(), switch_core_session_get_channel(), switch_core_session_get_partner, switch_core_session_get_uuid(), switch_core_session_rwunlock(), SWITCH_FALSE, switch_ivr_bg_media(), switch_ivr_broadcast(), switch_ivr_hold_uuid(), switch_ivr_unhold(), SWITCH_MEDIA_TYPE_AUDIO, SWITCH_MEDIA_TYPE_VIDEO, switch_rtp_clear_flag(), SWITCH_RTP_FLAG_PAUSE, switch_rtp_reset_media_timer(), switch_rtp_set_flag(), switch_rtp_set_max_missed_packets(), SWITCH_STATUS_SUCCESS, switch_stristr(), SWITCH_TRUE, switch_true(), and switch_yield.

Referenced by switch_core_media_activate_rtp(), and switch_core_media_negotiate_sdp().

4873 {
4874  int changed = 0;
4875  switch_rtp_engine_t *a_engine, *v_engine;
4876  switch_media_handle_t *smh;
4877  switch_core_session_t *b_session = NULL;
4878  switch_channel_t *b_channel = NULL;
4879 
4880  switch_assert(session);
4881 
4882  if (!(smh = session->media_handle)) {
4883  return 0;
4884  }
4885 
4886  a_engine = &smh->engines[SWITCH_MEDIA_TYPE_AUDIO];
4887  v_engine = &smh->engines[SWITCH_MEDIA_TYPE_VIDEO];
4888 
4889 
4890  if (switch_core_session_get_partner(session, &b_session) == SWITCH_STATUS_SUCCESS) {
4891  b_channel = switch_core_session_get_channel(b_session);
4892  }
4893 
4894  if (sendonly && switch_channel_test_flag(session->channel, CF_ANSWERED)) {
4896  const char *stream;
4897  const char *msg = "hold";
4898  const char *info;
4899 
4901  (!b_channel || switch_channel_test_flag(b_channel, CF_EVENT_LOCK_PRI))) {
4902  switch_channel_mark_hold(session->channel, sendonly);
4904  changed = 0;
4905  goto end;
4906  }
4907 
4908  info = switch_channel_get_variable(session->channel, "presence_call_info");
4909 
4910  if (info) {
4911  if (switch_stristr("private", info)) {
4912  msg = "hold-private";
4913  }
4914  }
4915 
4916  if (a_engine->rtp_session) {
4918  }
4919 
4920  if (v_engine->rtp_session) {
4922  }
4923 
4926  switch_channel_presence(session->channel, "unknown", msg, NULL);
4927  changed = 1;
4928 
4929  if (a_engine->max_missed_hold_packets && a_engine->rtp_session) {
4931  }
4932 
4933  if (!(stream = switch_channel_get_hold_music(session->channel))) {
4934  stream = "local_stream://moh";
4935  }
4936 
4937 
4938  if (stream && strcasecmp(stream, "silence") && (!b_channel || !switch_channel_test_flag(b_channel, CF_EVENT_LOCK_PRI))) {
4939  if (!strcasecmp(stream, "indicate_hold")) {
4943  } else {
4946  switch_yield(250000);
4947  }
4948  }
4949 
4950  }
4951  } else {
4955 
4956  if (a_engine->rtp_session) {
4958  }
4959 
4960  if (v_engine->rtp_session) {
4962  }
4963 
4964  changed = 1;
4965  }
4966 
4968 
4970  int media_on_hold_a = switch_true(switch_channel_get_variable_dup(session->channel, "bypass_media_resume_on_hold", SWITCH_FALSE, -1));
4971  int media_on_hold_b = 0;
4972  int bypass_after_hold_a = 0;
4973  int bypass_after_hold_b = 0;
4974 
4975  if (media_on_hold_a) {
4976  bypass_after_hold_a = switch_true(switch_channel_get_variable_dup(session->channel, "bypass_media_after_hold", SWITCH_FALSE, -1));
4977  }
4978 
4979  if (b_channel) {
4980  if ((media_on_hold_b = switch_true(switch_channel_get_variable_dup(b_channel, "bypass_media_resume_on_hold", SWITCH_FALSE, -1)))) {
4981  bypass_after_hold_b = switch_true(switch_channel_get_variable_dup(b_channel, "bypass_media_after_hold", SWITCH_FALSE, -1));
4982  }
4983  }
4984 
4985  switch_yield(250000);
4986 
4987  if (b_channel && (switch_channel_test_flag(session->channel, CF_BYPASS_MEDIA_AFTER_HOLD) ||
4988  switch_channel_test_flag(b_channel, CF_BYPASS_MEDIA_AFTER_HOLD) || bypass_after_hold_a || bypass_after_hold_b)) {
4989  /* try to stay out from media stream */
4991  }
4992 
4993  if (a_engine->max_missed_packets && a_engine->rtp_session) {
4996  }
4997 
4998  if (b_channel) {
4999  if (switch_channel_test_flag(session->channel, CF_HOLD)) {
5000  switch_ivr_unhold(b_session);
5003  } else {
5004  switch_channel_stop_broadcast(b_channel);
5005  switch_channel_wait_for_flag(b_channel, CF_BROADCAST, SWITCH_FALSE, 5000, NULL);
5006  }
5007  }
5008 
5010 
5013  switch_channel_presence(session->channel, "unknown", "unhold", NULL);
5014 
5015  if (a_engine->rtp_session) {
5017  }
5018 
5019  if (v_engine->rtp_session) {
5021  }
5022 
5023  changed = 1;
5024  }
5025  }
5026 
5027 
5028  end:
5029 
5030  if (b_session) {
5031  switch_core_session_rwunlock(b_session);
5032  }
5033 
5034 
5035  return changed;
5036 }
void switch_ivr_bg_media(const char *uuid, switch_media_flag_t flags, switch_bool_t on, switch_bool_t is3p, uint32_t delay)
Definition: switch_ivr.c:2014
#define switch_channel_stop_broadcast(_channel)
#define switch_channel_presence(_a, _b, _c, _d)
switch_status_t switch_ivr_broadcast(const char *uuid, const char *path, switch_media_flag_t flags)
Signal the session to broadcast audio.
const char * switch_channel_get_variable_dup(switch_channel_t *channel, const char *varname, switch_bool_t dup, int idx)
Retrieve a variable from a given channel.
static 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.
void switch_rtp_set_max_missed_packets(switch_rtp_t *rtp_session, uint32_t max)
Definition: switch_rtp.c:2753
switch_media_handle_t * media_handle
void switch_rtp_reset_media_timer(switch_rtp_t *rtp_session)
Definition: switch_rtp.c:2817
_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_channel_mark_hold(switch_channel_t *channel, switch_bool_t on)
#define switch_yield(ms)
Wait a desired number of microseconds and yield the CPU.
Definition: switch_utils.h:908
switch_channel_t * channel
switch_rtp_t * rtp_session
const char * switch_channel_get_hold_music(switch_channel_t *channel)
#define switch_channel_get_variable(_c, _v)
#define switch_core_session_get_partner(_session, _partner)
Definition: switch_core.h:1002
void switch_core_session_rwunlock(_In_ switch_core_session_t *session)
Unlock a read or write lock on as given session.
char * switch_core_session_get_uuid(_In_ switch_core_session_t *session)
Retrieve the unique identifier from a session.
switch_status_t switch_core_media_check_autoadj(switch_core_session_t *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
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]
switch_status_t switch_ivr_unhold(switch_core_session_t *session)
Signal the session with a protocol specific unhold message.
Definition: switch_ivr.c:1515
#define switch_channel_set_flag(_c, _f)
const char * switch_stristr(const char *instr, const char *str)
switch_status_t switch_channel_wait_for_flag(switch_channel_t *channel, switch_channel_flag_t want_flag, switch_bool_t pres, uint32_t to, switch_channel_t *super_channel)
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_status_t switch_ivr_hold_uuid(const char *uuid, const char *message, switch_bool_t moh)
Signal the session with a protocol specific hold message.
Definition: switch_ivr.c:1481
switch_status_t switch_core_media_udptl_mode ( switch_core_session_t session,
switch_media_type_t  type 
)

Definition at line 9931 of file switch_core_media.c.

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

9932 {
9933  switch_media_handle_t *smh;
9934 
9935  switch_assert(session);
9936 
9937  if (!(smh = session->media_handle)) {
9938  return SWITCH_STATUS_FALSE;
9939  }
9940 
9941  if (switch_rtp_ready(smh->engines[type].rtp_session)) {
9942  return switch_rtp_udptl_mode(smh->engines[type].rtp_session);
9943  }
9944 
9945  return SWITCH_STATUS_FALSE;
9946 }
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_status_t switch_rtp_udptl_mode(switch_rtp_t *rtp_session)
Definition: switch_rtp.c:2843
switch_rtp_t * rtp_session
switch_rtp_engine_t engines[SWITCH_MEDIA_TYPE_TOTAL]
#define switch_assert(expr)
switch_status_t switch_core_media_unlock_video_file ( switch_core_session_t session,
switch_rw_t  rw 
)

Definition at line 5183 of file switch_core_media.c.

References CF_VIDEO, switch_media_handle_s::engines, media_helper::file_read_mutex, media_helper::file_write_mutex, switch_rtp_engine_s::mh, switch_assert, switch_channel_test_flag(), SWITCH_MEDIA_TYPE_VIDEO, switch_mutex_unlock(), SWITCH_RW_READ, SWITCH_STATUS_FALSE, and SWITCH_STATUS_SUCCESS.

Referenced by switch_ivr_record_file().

5184 {
5185  switch_media_handle_t *smh;
5186  switch_rtp_engine_t *v_engine;
5187 
5188  switch_assert(session);
5189 
5190  if (!switch_channel_test_flag(session->channel, CF_VIDEO)) {
5191  return SWITCH_STATUS_FALSE;
5192  }
5193 
5194  if (!(smh = session->media_handle)) {
5195  return SWITCH_STATUS_FALSE;
5196  }
5197 
5198  v_engine = &smh->engines[SWITCH_MEDIA_TYPE_VIDEO];
5199 
5200  if (rw == SWITCH_RW_READ) {
5202  } else {
5204  }
5205 
5206  return SWITCH_STATUS_SUCCESS;
5207 }
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_status_t switch_mutex_unlock(switch_mutex_t *lock)
Definition: switch_apr.c:290
switch_channel_t * channel
switch_mutex_t * file_write_mutex
switch_rtp_engine_t engines[SWITCH_MEDIA_TYPE_TOTAL]
switch_mutex_t * file_read_mutex
struct media_helper mh
#define switch_assert(expr)
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 
)

Definition at line 2552 of file switch_core_media.c.

References CF_VIDEO_ONLY, switch_codec_implementation::encoded_bytes_per_packet, switch_media_handle_s::engines, switch_codec::implementation, switch_media_handle_s::media_flags, switch_rtp_engine_s::read_codec, switch_rtp_engine_s::read_impl, switch_rtp_engine_s::rtp_session, switch_codec_implementation::samples_per_packet, SCMF_RUNNING, SFF_CNG, SFF_PROXY_PACKET, switch_assert, switch_channel_ready, switch_channel_test_flag(), switch_core_codec_ready(), SWITCH_MEDIA_TYPE_AUDIO, switch_rtp_ready(), switch_rtp_write_frame(), SWITCH_STATUS_FALSE, SWITCH_STATUS_GENERR, SWITCH_STATUS_SUCCESS, switch_test_flag, switch_yield, and switch_rtp_engine_s::timestamp_send.

2554 {
2556  int bytes = 0, samples = 0, frames = 0;
2557  switch_rtp_engine_t *engine;
2558  switch_media_handle_t *smh;
2559 
2560  switch_assert(session);
2561 
2562  if (!(smh = session->media_handle)) {
2563  return SWITCH_STATUS_FALSE;
2564  }
2565 
2566  if (!smh->media_flags[SCMF_RUNNING]) {
2567  return SWITCH_STATUS_FALSE;
2568  }
2569 
2570  engine = &smh->engines[type];
2571 
2572 
2574  return SWITCH_STATUS_SUCCESS;
2575  }
2576 
2577  while (!(engine->read_codec.implementation && switch_rtp_ready(engine->rtp_session))) {
2578  if (switch_channel_ready(session->channel)) {
2579  switch_yield(10000);
2580  } else {
2581  return SWITCH_STATUS_GENERR;
2582  }
2583  }
2584 
2585  if (!engine->read_codec.implementation || !switch_core_codec_ready(&engine->read_codec)) {
2586  return SWITCH_STATUS_GENERR;
2587  }
2588 
2589 
2590  if (!engine->read_codec.implementation || !switch_core_codec_ready(&engine->read_codec)) {
2591  return SWITCH_STATUS_FALSE;
2592  }
2593 
2594  if (!switch_test_flag(frame, SFF_CNG) && !switch_test_flag(frame, SFF_PROXY_PACKET)) {
2595  if (engine->read_impl.encoded_bytes_per_packet) {
2596  bytes = engine->read_impl.encoded_bytes_per_packet;
2597  frames = ((int) frame->datalen / bytes);
2598  } else
2599  frames = 1;
2600 
2601  samples = frames * engine->read_impl.samples_per_packet;
2602  }
2603 
2604  engine->timestamp_send += samples;
2605 
2606  if (switch_rtp_write_frame(engine->rtp_session, frame) < 0) {
2607  status = SWITCH_STATUS_FALSE;
2608  }
2609 
2610 
2611  return status;
2612 }
switch_core_media_flag_t media_flags[SCMF_MAX]
uint8_t switch_rtp_ready(switch_rtp_t *rtp_session)
Test if an RTP session is ready.
Definition: switch_rtp.c:4452
#define switch_channel_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
const switch_codec_implementation_t * implementation
#define switch_yield(ms)
Wait a desired number of microseconds and yield the CPU.
Definition: switch_utils.h:908
switch_channel_t * channel
switch_rtp_t * rtp_session
uint32_t datalen
Definition: switch_frame.h:57
switch_codec_t read_codec
switch_status_t
Common return values.
switch_rtp_engine_t engines[SWITCH_MEDIA_TYPE_TOTAL]
int switch_rtp_write_frame(switch_rtp_t *rtp_session, switch_frame_t *frame)
Write data to a given RTP session.
Definition: switch_rtp.c:7726
switch_codec_implementation_t read_impl
#define switch_test_flag(obj, flag)
Test for the existance of a flag on an arbitary object.
Definition: switch_utils.h:624
static switch_bool_t switch_core_codec_ready(switch_codec_t *codec)
#define switch_assert(expr)
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 
)

Definition at line 1325 of file switch_core_media.c.

References CF_AVPF, CF_SECURE, switch_core_session::channel, CRYPTO_INVALID, switch_media_handle_s::crypto_mode, CRYPTO_MODE_FORBIDDEN, switch_media_handle_s::crypto_suite_order, secure_settings_s::crypto_tag, secure_settings_s::crypto_type, switch_rtp_engine_s::crypto_type, switch_srtp_crypto_suite_s::keylen, secure_settings_s::local_crypto_key, secure_settings_s::local_raw_key, switch_srtp_crypto_suite_s::name, secure_settings_s::remote_crypto_key, secure_settings_s::remote_raw_key, switch_rtp_engine_s::rtp_session, SDP_TYPE_REQUEST, switch_media_handle_s::session, switch_rtp_engine_s::ssec, SWITCH_CHANNEL_SESSION_LOG, switch_channel_set_flag, switch_channel_set_variable, switch_channel_set_variable_printf(), switch_channel_test_flag(), switch_core_media_add_crypto(), switch_core_media_build_crypto(), switch_core_media_crypto_type2str(), switch_core_session_strdup, SWITCH_LOG_DEBUG, switch_log_printf(), SWITCH_MEDIA_TYPE_AUDIO, SWITCH_MEDIA_TYPE_VIDEO, switch_rtp_add_crypto_key(), SWITCH_RTP_CRYPTO_RECV, SWITCH_RTP_CRYPTO_SEND, switch_rtp_ready(), switch_stristr(), switch_srtp_crypto_suite_s::type, switch_rtp_engine_s::type, and zstr.

Referenced by switch_core_media_negotiate_sdp().

1328 {
1329  int got_crypto = 0;
1330  int i = 0;
1331  int ctype = 0;
1332  const char *vval = NULL;
1333  switch_rtp_engine_t *engine;
1334  switch_media_handle_t *smh;
1335 
1336  if (!(smh = session->media_handle)) {
1337  return 0;
1338  }
1339 
1340  if (smh->crypto_mode == CRYPTO_MODE_FORBIDDEN) {
1341  return -1;
1342  }
1343 
1344  if (switch_channel_test_flag(session->channel, CF_AVPF)) {
1345  return 0;
1346  }
1347 
1348  engine = &session->media_handle->engines[type];
1349 
1350  for (i = 0; smh->crypto_suite_order[i] != CRYPTO_INVALID; i++) {
1352 
1353  switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_DEBUG,"looking for crypto suite [%s] in [%s]\n", SUITES[j].name, crypto);
1354 
1355  if (switch_stristr(SUITES[j].name, crypto)) {
1356  ctype = SUITES[j].type;
1357  vval = SUITES[j].name;
1358  switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_DEBUG, "Found suite %s\n", vval);
1359  switch_channel_set_variable(session->channel, "rtp_secure_media_negotiated", vval);
1360  break;
1361  }
1362  }
1363 
1364  if (engine->ssec[engine->crypto_type].remote_crypto_key && switch_rtp_ready(engine->rtp_session)) {
1365  /* Compare all the key. The tag may remain the same even if key changed */
1366  if (crypto && engine->crypto_type != CRYPTO_INVALID && !strcmp(crypto, engine->ssec[engine->crypto_type].remote_crypto_key)) {
1367  switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_DEBUG, "Existing key is still valid.\n");
1368  got_crypto = 1;
1369  } else {
1370  const char *a = switch_stristr("AE", engine->ssec[engine->crypto_type].remote_crypto_key);
1371  const char *b = switch_stristr("AE", crypto);
1372 
1373  if (sdp_type == SDP_TYPE_REQUEST) {
1374  if (!vval) {
1375  switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_DEBUG, "Unsupported Crypto [%s]\n", crypto);
1376  goto end;
1377  }
1378  switch_channel_set_variable(session->channel, varname, vval);
1379 
1380  switch_core_media_build_crypto(session->media_handle, type, crypto_tag, ctype, SWITCH_RTP_CRYPTO_SEND, 1);
1382  engine->ssec[engine->crypto_type].local_raw_key, SUITES[ctype].keylen);
1383  }
1384 
1385  if (a && b && !strncasecmp(a, b, 23)) {
1386  engine->crypto_type = ctype;
1387 
1388  switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_DEBUG, "Change Remote key to [%s]\n", crypto);
1389  engine->ssec[engine->crypto_type].remote_crypto_key = switch_core_session_strdup(session, crypto);
1390 
1391  if (engine->type == SWITCH_MEDIA_TYPE_AUDIO) {
1392  switch_channel_set_variable(session->channel, "srtp_remote_audio_crypto_key", crypto);
1393  switch_channel_set_variable_printf(session->channel, "srtp_remote_audio_crypto_tag", "%d", crypto_tag);
1394  switch_channel_set_variable_printf(session->channel, "srtp_remote_audio_crypto_type", "%s", switch_core_media_crypto_type2str(ctype));
1395  } else if (engine->type == SWITCH_MEDIA_TYPE_VIDEO) {
1396  switch_channel_set_variable(session->channel, "srtp_remote_video_crypto_key", crypto);
1397  switch_channel_set_variable_printf(session->channel, "srtp_remote_video_crypto_tag", "%d", crypto_tag);
1398  switch_channel_set_variable_printf(session->channel, "srtp_remote_video_crypto_type", "%s", switch_core_media_crypto_type2str(ctype));
1399  }
1400 
1401  engine->ssec[engine->crypto_type].crypto_tag = crypto_tag;
1402 
1403 
1407  engine->ssec[engine->crypto_type].crypto_type, engine->ssec[engine->crypto_type].remote_raw_key, SUITES[engine->ssec[engine->crypto_type].crypto_type].keylen);
1408  }
1409  got_crypto++;
1410 
1411  } else {
1412  switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_DEBUG, "Ignoring unacceptable key\n");
1413  }
1414  }
1415  } else if (!switch_rtp_ready(engine->rtp_session)) {
1416 
1417  if (!vval) {
1418  switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_DEBUG, "Unsupported Crypto [%s]\n", crypto);
1419  goto end;
1420  }
1421 
1422  engine->crypto_type = ctype;
1423  engine->ssec[engine->crypto_type].remote_crypto_key = switch_core_session_strdup(session, crypto);
1424  switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_DEBUG, "Set Remote Key [%s]\n", engine->ssec[engine->crypto_type].remote_crypto_key);
1425  if (engine->type == SWITCH_MEDIA_TYPE_AUDIO) {
1426  switch_channel_set_variable(session->channel, "srtp_remote_audio_crypto_key", crypto);
1427  switch_channel_set_variable_printf(session->channel, "srtp_remote_audio_crypto_type", "%s", switch_core_media_crypto_type2str(ctype));
1428  } else if (engine->type == SWITCH_MEDIA_TYPE_VIDEO) {
1429  switch_channel_set_variable(session->channel, "srtp_remote_video_crypto_key", crypto);
1430  switch_channel_set_variable_printf(session->channel, "srtp_remote_video_crypto_type", "%s", switch_core_media_crypto_type2str(ctype));
1431  }
1432 
1433  engine->ssec[engine->crypto_type].crypto_tag = crypto_tag;
1434  got_crypto++;
1435 
1436  switch_channel_set_variable(session->channel, varname, vval);
1438 
1439  if (zstr(engine->ssec[engine->crypto_type].local_crypto_key)) {
1440  switch_core_media_build_crypto(session->media_handle, type, crypto_tag, ctype, SWITCH_RTP_CRYPTO_SEND, 1);
1441  }
1442  }
1443 
1444  end:
1445 
1446  return got_crypto;
1447 }
switch_status_t switch_channel_set_variable_printf(switch_channel_t *channel, const char *varname, const char *fmt,...)
unsigned char remote_raw_key[SWITCH_RTP_MAX_CRYPTO_LEN]
#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_rtp_crypto_key_type_t
const char * switch_core_media_crypto_type2str(switch_rtp_crypto_key_type_t type)
switch_status_t switch_rtp_add_crypto_key(switch_rtp_t *rtp_session, switch_rtp_crypto_direction_t direction, uint32_t index, switch_rtp_crypto_key_type_t type, unsigned char *key, switch_size_t keylen)
Definition: switch_rtp.c:3468
switch_rtp_crypto_mode_t crypto_mode
static switch_srtp_crypto_suite_t SUITES[CRYPTO_INVALID]
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_secure_settings_t ssec[CRYPTO_INVALID+1]
switch_media_handle_t * media_handle
#define zstr(x)
Definition: switch_utils.h:281
switch_rtp_crypto_key_type_t crypto_suite_order[CRYPTO_INVALID+1]
unsigned char local_raw_key[SWITCH_RTP_MAX_CRYPTO_LEN]
switch_channel_t * channel
switch_rtp_t * rtp_session
switch_core_session_t * session
switch_rtp_engine_t engines[SWITCH_MEDIA_TYPE_TOTAL]
static switch_status_t switch_core_media_build_crypto(switch_media_handle_t *smh, switch_media_type_t type, int index, switch_rtp_crypto_key_type_t ctype, switch_rtp_crypto_direction_t direction, int force)
#define switch_channel_set_flag(_c, _f)
switch_status_t switch_core_media_add_crypto(switch_secure_settings_t *ssec, const char *key_str, switch_rtp_crypto_direction_t direction)
void switch_log_printf(_In_ switch_text_channel_t channel, _In_z_ const char *file, _In_z_ const char *func, _In_ int line, _In_opt_z_ const char *userdata, _In_ switch_log_level_t level, _In_z_ _Printf_format_string_ const char *fmt,...) PRINTF_FUNCTION(7
Write log data to the logging engine.
const char * switch_stristr(const char *instr, const char *str)
#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_channel_set_variable(_channel, _var, _val)
switch_rtp_crypto_key_type_t crypto_type
switch_media_type_t type
switch_rtp_crypto_key_type_t type
Definition: switch_rtp.h:67
switch_rtp_crypto_key_type_t crypto_type
void switch_core_session_check_outgoing_crypto ( switch_core_session_t session)

Definition at line 1450 of file switch_core_media.c.

References CF_AVPF, CF_SECURE, CRYPTO_INVALID, switch_media_handle_s::crypto_mode, CRYPTO_MODE_MANDATORY, CRYPTO_MODE_OPTIONAL, switch_media_handle_s::crypto_suite_order, switch_channel_set_flag, switch_channel_test_flag(), switch_core_media_build_crypto(), switch_core_session_get_channel(), switch_core_session_media_handle_ready(), SWITCH_MEDIA_TYPE_AUDIO, SWITCH_MEDIA_TYPE_VIDEO, SWITCH_NO_CRYPTO_TAG, SWITCH_RTP_CRYPTO_SEND, and SWITCH_STATUS_SUCCESS.

Referenced by switch_core_media_gen_local_sdp().

1451 {
1453  switch_media_handle_t *smh;
1454  int i;
1455 
1457  return;
1458  }
1459 
1460  if (!(smh = session->media_handle)) {
1461  return;
1462  }
1463 
1465  return;
1466  }
1467 
1468  if (switch_channel_test_flag(session->channel, CF_AVPF)) {
1469  return;
1470  }
1471 
1473 
1474  for (i = 0; smh->crypto_suite_order[i] != CRYPTO_INVALID; i++) {
1477 
1480  }
1481 
1482 }
switch_rtp_crypto_mode_t crypto_mode
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_rtp_crypto_key_type_t crypto_suite_order[CRYPTO_INVALID+1]
_Ret_ switch_channel_t * switch_core_session_get_channel(_In_ switch_core_session_t *session)
Retrieve a pointer to the channel object associated with a given session.
switch_channel_t * channel
switch_status_t switch_core_session_media_handle_ready(switch_core_session_t *session)
#define SWITCH_NO_CRYPTO_TAG
static switch_status_t switch_core_media_build_crypto(switch_media_handle_t *smh, switch_media_type_t type, int index, switch_rtp_crypto_key_type_t ctype, switch_rtp_crypto_direction_t direction, int force)
#define switch_channel_set_flag(_c, _f)
void switch_core_session_clear_crypto ( switch_core_session_t session)

Definition at line 873 of file switch_core_media.c.

References CRYPTO_INVALID, switch_media_handle_s::engines, memset(), switch_rtp_engine_s::ssec, switch_channel_set_variable, SWITCH_MEDIA_TYPE_AUDIO, and SWITCH_MEDIA_TYPE_VIDEO.

874 {
875  int i;
877 
878  const char *vars[] = { "rtp_last_audio_local_crypto_key",
879  "srtp_remote_audio_crypto_key",
880  "srtp_remote_audio_crypto_tag",
881  "srtp_remote_audio_crypto_type",
882  "srtp_remote_video_crypto_key",
883  "srtp_remote_video_crypto_tag",
884  "srtp_remote_video_crypto_type",
885  "rtp_secure_media",
886  "rtp_secure_media_inbound",
887  "rtp_secure_media_outbound",
888  NULL};
889 
890  for(i = 0; vars[i] ;i++) {
891  switch_channel_set_variable(session->channel, vars[i], NULL);
892  }
893 
894  if (!(smh = session->media_handle)) {
895  return;
896  }
897  for (i = 0; i < CRYPTO_INVALID; i++) {
900  }
901 
902 }
switch_secure_settings_t ssec[CRYPTO_INVALID+1]
switch_media_handle_t * media_handle
switch_channel_t * channel
switch_rtp_engine_t engines[SWITCH_MEDIA_TYPE_TOTAL]
#define switch_channel_set_variable(_channel, _var, _val)
memset(buf, 0, buflen)
switch_status_t switch_core_session_clear_media_handle ( switch_core_session_t session)

Definition at line 1784 of file switch_core_media.c.

References SWITCH_STATUS_FALSE, and SWITCH_STATUS_SUCCESS.

1785 {
1786  if (!session->media_handle) {
1787  return SWITCH_STATUS_FALSE;
1788  }
1789 
1790  return SWITCH_STATUS_SUCCESS;
1791 }
switch_media_handle_t * media_handle
switch_media_handle_t* switch_core_session_get_media_handle ( switch_core_session_t session)

Definition at line 1775 of file switch_core_media.c.

References switch_core_session_media_handle_ready(), and SWITCH_STATUS_SUCCESS.

1776 {
1778  return session->media_handle;
1779  }
1780 
1781  return NULL;
1782 }
switch_media_handle_t * media_handle
switch_status_t switch_core_session_media_handle_ready(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 
)

Definition at line 668 of file switch_core_media.c.

References payload_map_s::allocated, switch_media_handle_s::engines, payload_map_s::iananame, payload_map_s::next, switch_rtp_engine_s::payload_map, payload_map_s::pt, payload_map_s::rate, payload_map_s::recv_pt, payload_map_s::rm_fmtp, switch_media_handle_s::sdp_mutex, switch_assert, switch_mutex_lock(), switch_mutex_unlock(), SWITCH_STATUS_FALSE, SWITCH_STATUS_SUCCESS, and zstr.

Referenced by switch_core_media_gen_local_sdp().

675 {
676  payload_map_t *pmap;
678  switch_rtp_engine_t *engine;
679  switch_payload_t pt = 0, recv_pt = 0;
680  int found = 0;
681  char *fmtp = NULL;
682 
683  switch_assert(session);
684 
685  if (!(smh = session->media_handle)) {
686  return SWITCH_STATUS_FALSE;
687  }
688 
689  engine = &smh->engines[type];
690 
692  for (pmap = engine->payload_map; pmap ; pmap = pmap->next) {
693 
694  if (!pmap->allocated) continue;
695 
696  if (!strcasecmp(pmap->iananame, iananame) && (!rate || (rate == pmap->rate))) {
697  pt = pmap->pt;
698  recv_pt = pmap->recv_pt;
699  fmtp = pmap->rm_fmtp;
700  found++;
701  break;
702  }
703  }
705 
706  if (found) {
707  if (ptP) {
708  *ptP = pt;
709  }
710  if (recv_ptP) {
711  *recv_ptP = recv_pt;
712  }
713 
714  if (!zstr(fmtp) && fmtpP) {
715  *fmtpP = fmtp;
716  }
717 
718  return SWITCH_STATUS_SUCCESS;
719  }
720 
721  return SWITCH_STATUS_FALSE;
722 
723 }
uint8_t allocated
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
switch_payload_t pt
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
switch_bool_t switch_core_session_in_video_thread ( switch_core_session_t session)

Definition at line 5594 of file switch_core_media.c.

References switch_media_handle_s::engines, switch_assert, SWITCH_FALSE, SWITCH_MEDIA_TYPE_VIDEO, switch_thread_equal(), switch_thread_self(), SWITCH_TRUE, and switch_rtp_engine_s::thread_id.

5595 {
5596  switch_rtp_engine_t *v_engine;
5597  switch_media_handle_t *smh;
5598 
5599  switch_assert(session);
5600 
5601  if (!(smh = session->media_handle)) {
5602  return SWITCH_FALSE;
5603  }
5604 
5605  v_engine = &smh->engines[SWITCH_MEDIA_TYPE_VIDEO];
5606 
5608 }
switch_thread_id_t thread_id
switch_media_handle_t * media_handle
int switch_thread_equal(switch_thread_id_t tid1, switch_thread_id_t tid2)
Compare two thread ids.
Definition: switch_apr.c:88
switch_rtp_engine_t engines[SWITCH_MEDIA_TYPE_TOTAL]
switch_thread_id_t switch_thread_self(void)
Definition: switch_apr.c:79
#define switch_assert(expr)
const char* switch_core_session_local_crypto_key ( switch_core_session_t session,
switch_media_type_t  type 
)

Definition at line 904 of file switch_core_media.c.

905 {
906  if (!session->media_handle) {
907  return NULL;
908  }
909 
910  return session->media_handle->engines[type].ssec[session->media_handle->engines[type].crypto_type].local_crypto_key;
911 }
switch_secure_settings_t ssec[CRYPTO_INVALID+1]
switch_media_handle_t * media_handle
switch_rtp_engine_t engines[SWITCH_MEDIA_TYPE_TOTAL]
switch_rtp_crypto_key_type_t crypto_type
switch_media_flow_t switch_core_session_media_flow ( switch_core_session_t session,
switch_media_type_t  type 
)

Definition at line 1740 of file switch_core_media.c.

References switch_media_handle_s::engines, switch_media_handle_s::media_flags, SCMF_RUNNING, switch_rtp_engine_s::smode, switch_assert, and SWITCH_MEDIA_FLOW_SENDRECV.

Referenced by switch_core_session_write_encoded_video_frame(), and switch_core_session_write_video_frame().

1741 {
1743  switch_media_handle_t *smh;
1744  switch_rtp_engine_t *engine = NULL;
1745 
1746  switch_assert(session);
1747 
1748  if (!(smh = session->media_handle)) {
1749  goto end;
1750  }
1751 
1752  if (!smh->media_flags[SCMF_RUNNING]) {
1753  goto end;
1754  }
1755 
1756  engine = &smh->engines[type];
1757  flow = engine->smode;
1758 
1759  end:
1760 
1761  return flow;
1762 }
switch_core_media_flag_t media_flags[SCMF_MAX]
switch_media_flow_t smode
switch_media_handle_t * media_handle
switch_rtp_engine_t engines[SWITCH_MEDIA_TYPE_TOTAL]
switch_media_flow_t
#define switch_assert(expr)
switch_status_t switch_core_session_media_handle_ready ( switch_core_session_t session)

Definition at line 1764 of file switch_core_media.c.

References SMF_INIT, SWITCH_STATUS_FALSE, SWITCH_STATUS_SUCCESS, and switch_test_flag.

Referenced by switch_core_session_check_outgoing_crypto(), and switch_core_session_get_media_handle().

1765 {
1766  if (session->media_handle && switch_test_flag(session->media_handle, SMF_INIT)) {
1767  return SWITCH_STATUS_SUCCESS;
1768  }
1769 
1770  return SWITCH_STATUS_FALSE;
1771 }
switch_media_handle_t * media_handle
#define switch_test_flag(obj, flag)
Test for the existance of a flag on an arbitary object.
Definition: switch_utils.h:624
void switch_core_session_set_ice ( switch_core_session_t session)

Definition at line 3592 of file switch_core_media.c.

References CF_AVPF, CF_ICE, CF_VERBOSE_SDP, switch_media_handle_s::mparams, switch_core_media_params_s::rtcp_audio_interval_msec, switch_core_media_params_s::rtcp_video_interval_msec, switch_assert, switch_channel_set_flag, SWITCH_RTCP_AUDIO_INTERVAL_MSEC, and SWITCH_RTCP_VIDEO_INTERVAL_MSEC.

Referenced by switch_core_media_negotiate_sdp().

3593 {
3594  switch_media_handle_t *smh;
3595 
3596  switch_assert(session);
3597 
3598  if (!(smh = session->media_handle)) {
3599  return;
3600  }
3601 
3607 
3608 }
switch_media_handle_t * media_handle
#define SWITCH_RTCP_AUDIO_INTERVAL_MSEC
Definition: switch_types.h:234
switch_channel_t * channel
#define SWITCH_RTCP_VIDEO_INTERVAL_MSEC
Definition: switch_types.h:235
#define switch_channel_set_flag(_c, _f)
#define switch_assert(expr)
switch_core_media_params_t * mparams
switch_status_t switch_core_session_start_video_thread ( switch_core_session_t session)

Definition at line 5494 of file switch_core_media.c.

References payload_map_s::agreed_pt, CF_VIDEO, media_helper::cond, media_helper::cond_mutex, switch_media_handle_s::control_mutex, switch_rtp_engine_s::cur_payload_map, switch_media_handle_s::engines, media_helper::file_read_mutex, media_helper::file_write_mutex, switch_rtp_engine_s::media_thread, switch_rtp_engine_s::mh, pool, switch_media_handle_s::read_mutex, switch_rtp_engine_s::rtp_session, media_helper::session, SWITCH_CHANNEL_SESSION_LOG, switch_channel_test_flag(), switch_core_session_get_name, switch_core_session_get_pool(), SWITCH_LOG_DEBUG, switch_log_printf(), SWITCH_MEDIA_TYPE_VIDEO, switch_mutex_init(), switch_mutex_lock(), SWITCH_MUTEX_NESTED, switch_mutex_unlock(), switch_rtp_set_default_payload(), SWITCH_STATUS_FALSE, SWITCH_STATUS_NOTIMPL, SWITCH_STATUS_SUCCESS, switch_thread_cond_create(), switch_thread_create(), SWITCH_THREAD_STACKSIZE, switch_threadattr_create(), switch_threadattr_stacksize_set(), video_helper_thread(), and switch_media_handle_s::write_mutex.

Referenced by switch_channel_set_flag_value(), switch_core_media_activate_rtp(), switch_core_media_set_video_file(), switch_core_media_start_video_function(), and switch_core_session_set_video_read_callback().

5495 {
5496  switch_threadattr_t *thd_attr = NULL;
5498  switch_rtp_engine_t *v_engine = NULL;
5499  switch_media_handle_t *smh;
5500 
5501  if (!switch_channel_test_flag(session->channel, CF_VIDEO)) {
5502  return SWITCH_STATUS_NOTIMPL;
5503  }
5504 
5505  if (!(smh = session->media_handle)) {
5506  return SWITCH_STATUS_FALSE;
5507  }
5508 
5509  v_engine = &smh->engines[SWITCH_MEDIA_TYPE_VIDEO];
5510 
5512 
5513  if (v_engine->media_thread) {
5515  return SWITCH_STATUS_FALSE;
5516  }
5517 
5518  switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_DEBUG, "%s Starting Video thread\n", switch_core_session_get_name(session));
5519 
5520  if (v_engine->rtp_session) {
5522  }
5523 
5524  v_engine->mh.session = session;
5525  switch_threadattr_create(&thd_attr, pool);
5527 
5528  switch_thread_cond_create(&v_engine->mh.cond, pool);
5534  switch_thread_create(&v_engine->media_thread, thd_attr, video_helper_thread, &v_engine->mh, switch_core_session_get_pool(session));
5535 
5537  return SWITCH_STATUS_SUCCESS;
5538 }
switch_status_t switch_thread_cond_create(switch_thread_cond_t **cond, switch_memory_pool_t *pool)
Definition: switch_apr.c:350
#define SWITCH_CHANNEL_SESSION_LOG(x)
switch_core_session_t * session
switch_status_t switch_threadattr_stacksize_set(switch_threadattr_t *attr, switch_size_t stacksize)
Definition: switch_apr.c:660
switch_memory_pool_t * pool
switch_thread_cond_t * cond
#define switch_core_session_get_name(_s)
Definition: switch_core.h:271
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_status_t switch_mutex_unlock(switch_mutex_t *lock)
Definition: switch_apr.c:290
#define SWITCH_MUTEX_NESTED
Definition: switch_apr.h:318
switch_channel_t * channel
switch_rtp_t * rtp_session
switch_status_t switch_mutex_lock(switch_mutex_t *lock)
Definition: switch_apr.c:285
#define SWITCH_THREAD_STACKSIZE
Definition: switch_types.h:551
switch_mutex_t * file_write_mutex
payload_map_t * cur_payload_map
switch_status_t switch_mutex_init(switch_mutex_t **lock, unsigned int flags, switch_memory_pool_t *pool)
Definition: switch_apr.c:270
switch_mutex_t * control_mutex
switch_rtp_engine_t engines[SWITCH_MEDIA_TYPE_TOTAL]
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_mutex_t * file_read_mutex
switch_thread_t * media_thread
switch_payload_t agreed_pt
switch_mutex_t * cond_mutex
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.
switch_status_t switch_threadattr_create(switch_threadattr_t **new_attr, switch_memory_pool_t *pool)
Definition: switch_apr.c:642
switch_status_t switch_thread_create(switch_thread_t **new_thread, switch_threadattr_t *attr, switch_thread_start_t func, void *data, switch_memory_pool_t *cont)
Definition: switch_apr.c:675
static void *SWITCH_THREAD_FUNC video_helper_thread(switch_thread_t *thread, void *obj)
struct media_helper mh
switch_mutex_t * read_mutex[2]
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]
void switch_core_session_stop_media ( switch_core_session_t session)

Definition at line 10296 of file switch_core_media.c.

References ice_s::cands, CF_VIDEO_READY, switch_core_session::channel, ice_s::chosen, switch_media_handle_s::cname, icand_s::component_id, switch_media_handle_s::engines, icand_s::foundation, gen_ice(), switch_rtp_engine_s::ice_in, switch_rtp_engine_s::ice_out, dtls_fp_s::len, switch_rtp_engine_s::local_dtls_fingerprint, switch_media_handle_s::msid, switch_media_handle_s::owner_id, ice_s::pwd, switch_rtp_engine_s::read_codec, icand_s::ready, switch_rtp_engine_s::remote_ssrc, switch_rtp_engine_s::rtp_session, SCC_VIDEO_RESET, SCCT_INT, SCCT_NONE, switch_media_handle_s::session, switch_media_handle_s::session_id, switch_assert, switch_channel_clear_flag(), switch_core_codec_control(), switch_core_codec_ready(), switch_core_session_request_video_refresh(), switch_core_session_wake_video_thread(), SWITCH_MEDIA_TYPE_AUDIO, SWITCH_MEDIA_TYPE_VIDEO, switch_rtp_reset(), ice_s::ufrag, and switch_rtp_engine_s::write_codec.

10297 {
10298  switch_rtp_engine_t *a_engine, *v_engine;
10299  switch_media_handle_t *smh;
10300  int type;
10301 
10302  switch_assert(session);
10303 
10304  if (!(smh = session->media_handle)) {
10305  return;
10306  }
10307 
10308  a_engine = &smh->engines[SWITCH_MEDIA_TYPE_AUDIO];
10309  v_engine = &smh->engines[SWITCH_MEDIA_TYPE_VIDEO];
10310 
10311  if (switch_core_codec_ready(&v_engine->read_codec)) {
10312  type = 1;
10313  switch_core_codec_control(&v_engine->read_codec, SCC_VIDEO_RESET, SCCT_INT, (void *)&type, SCCT_NONE, NULL, NULL, NULL);
10314  }
10315 
10316  if (switch_core_codec_ready(&v_engine->write_codec)) {
10317  type = 2;
10318  switch_core_codec_control(&v_engine->write_codec, SCC_VIDEO_RESET, SCCT_INT, (void *)&type, SCCT_NONE, NULL, NULL, NULL);
10319  }
10320 
10321  if (a_engine->rtp_session) {
10322  switch_rtp_reset(a_engine->rtp_session);
10323  }
10324 
10325  if (v_engine->rtp_session) {
10326  switch_rtp_reset(v_engine->rtp_session);
10327  }
10328 
10329 
10330  smh->msid = NULL;
10331  smh->cname = NULL;
10332  v_engine->ice_out.ufrag = NULL;
10333  v_engine->ice_out.pwd = NULL;
10334  v_engine->ice_out.cands[0][0].foundation = NULL;
10335  v_engine->ice_out.cands[0][0].component_id = 0;
10336 
10337 
10338  a_engine->ice_out.ufrag = NULL;
10339  a_engine->ice_out.pwd = NULL;
10340  a_engine->ice_out.cands[0][0].foundation = NULL;
10341  a_engine->ice_out.cands[0][0].component_id = 0;
10342 
10343  if (v_engine->ice_in.cands[v_engine->ice_in.chosen[0]][0].ready) {
10344  gen_ice(smh->session, SWITCH_MEDIA_TYPE_VIDEO, NULL, 0);
10345  }
10346 
10347  if (a_engine->ice_in.cands[a_engine->ice_in.chosen[0]][0].ready) {
10348  gen_ice(smh->session, SWITCH_MEDIA_TYPE_AUDIO, NULL, 0);
10349  }
10350 
10351  smh->owner_id = 0;
10352  smh->session_id = 0;
10353 
10354  a_engine->local_dtls_fingerprint.len = 0;
10355  v_engine->local_dtls_fingerprint.len = 0;
10356 
10357  a_engine->remote_ssrc = 0;
10358  v_engine->remote_ssrc = 0;
10359 
10363 }
void switch_rtp_reset(switch_rtp_t *rtp_session)
Definition: switch_rtp.c:2789
int chosen[2]
Definition: switch_rtp.h:107
char * foundation
Definition: switch_rtp.h:89
static void gen_ice(switch_core_session_t *session, switch_media_type_t type, const char *ip, switch_port_t port)
switch_media_handle_t * media_handle
switch_codec_t write_codec
switch_status_t switch_core_session_request_video_refresh(switch_core_session_t *session)
switch_channel_t * channel
switch_rtp_t * rtp_session
switch_codec_t read_codec
switch_core_session_t * session
dtls_fingerprint_t local_dtls_fingerprint
uint8_t ready
Definition: switch_rtp.h:99
char * ufrag
Definition: switch_rtp.h:109
switch_rtp_engine_t engines[SWITCH_MEDIA_TYPE_TOTAL]
uint32_t len
Definition: switch_core.h:151
char * pwd
Definition: switch_rtp.h:110
int component_id
Definition: switch_rtp.h:90
void switch_core_session_wake_video_thread(switch_core_session_t *session)
icand_t cands[MAX_CAND][2]
Definition: switch_rtp.h:105
static switch_bool_t switch_core_codec_ready(switch_codec_t *codec)
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_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_session_video_reinit ( switch_core_session_t session)

Definition at line 11037 of file switch_core_media.c.

References SCC_VIDEO_RESET, SCCT_INT, SCCT_NONE, switch_assert, switch_channel_down, switch_core_media_codec_control(), switch_core_session_request_video_refresh(), switch_core_session_send_and_request_video_refresh(), SWITCH_IO_READ, SWITCH_MEDIA_TYPE_VIDEO, switch_media_handle_s::video_init, and switch_media_handle_s::video_last_key_time.

Referenced by handle_ice(), and switch_core_session_write_video_frame().

11038 {
11039  switch_media_handle_t *smh;
11040  int type;
11041 
11042  switch_assert(session);
11043 
11044  if (!(smh = session->media_handle)) {
11045  return;
11046  }
11047 
11048  if (switch_channel_down(session->channel)) {
11049  return;
11050  }
11051 
11052  smh->video_init = 0;
11053  smh->video_last_key_time = 0;
11055 
11056  type = 1;
11059 
11060 }
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_media_handle_t * media_handle
switch_status_t switch_core_session_request_video_refresh(switch_core_session_t *session)
switch_channel_t * channel
switch_status_t switch_core_session_send_and_request_video_refresh(switch_core_session_t *session)
#define switch_channel_down(_channel)
#define switch_assert(expr)
switch_time_t video_last_key_time
switch_status_t switch_core_session_wait_for_video_input_params ( switch_core_session_t session,
uint32_t  timeout_ms 
)

Definition at line 11267 of file switch_core_media.c.

References CF_VIDEO_DECODED_READ, CF_VIDEO_READY, switch_media_handle_s::engines, switch_vid_params_s::fps, switch_vid_params_s::height, switch_codec_implementation::microseconds_per_packet, switch_rtp_engine_s::smode, switch_assert, switch_channel_ready, switch_channel_test_flag(), switch_core_session_get_read_impl(), switch_core_session_read_frame(), switch_core_session_request_video_refresh(), SWITCH_IO_FLAG_NONE, SWITCH_MEDIA_FLOW_SENDONLY, SWITCH_MEDIA_TYPE_VIDEO, SWITCH_READ_ACCEPTABLE, SWITCH_STATUS_FALSE, SWITCH_STATUS_GENERR, SWITCH_STATUS_NOTIMPL, SWITCH_STATUS_SUCCESS, SWITCH_STATUS_TIMEOUT, core_video_globals_s::synced, switch_media_handle_s::vid_params, and switch_vid_params_s::width.

Referenced by switch_ivr_record_file().

11268 {
11269  switch_media_handle_t *smh;
11270  switch_codec_implementation_t read_impl = { 0 };
11271  switch_rtp_engine_t *v_engine = NULL;
11272 
11273  switch_assert(session != NULL);
11274 
11275  if (!(smh = session->media_handle)) {
11276  return SWITCH_STATUS_FALSE;
11277  }
11278 
11280  return SWITCH_STATUS_GENERR;;
11281  }
11282 
11283  v_engine = &smh->engines[SWITCH_MEDIA_TYPE_VIDEO];
11284 
11285  if (v_engine->smode == SWITCH_MEDIA_FLOW_SENDONLY) {
11286  return SWITCH_STATUS_NOTIMPL;
11287  }
11288 
11289  switch_core_session_get_read_impl(session, &read_impl);
11290 
11291  while(switch_channel_ready(session->channel) && timeout_ms > 0) {
11292  switch_frame_t *read_frame;
11293  switch_status_t status;
11294 
11295  if (video_globals.synced &&
11297  return SWITCH_STATUS_SUCCESS;
11298  }
11299 
11301  status = switch_core_session_read_frame(session, &read_frame, SWITCH_IO_FLAG_NONE, 0);
11302 
11303  if (!SWITCH_READ_ACCEPTABLE(status)) {
11304  return SWITCH_STATUS_FALSE;
11305  }
11306 
11307  timeout_ms -= (read_impl.microseconds_per_packet / 1000);
11308  }
11309 
11310  return SWITCH_STATUS_TIMEOUT;
11311 
11312 }
#define switch_channel_ready(_channel)
switch_media_flow_t smode
uint32_t switch_channel_test_flag(switch_channel_t *channel, switch_channel_flag_t flag)
Test for presence of given flag on a given channel.
switch_status_t switch_core_session_read_frame(_In_ switch_core_session_t *session, switch_frame_t **frame, switch_io_flag_t flags, int stream_id)
Read a frame from a session.
switch_media_handle_t * media_handle
switch_status_t switch_core_session_get_read_impl(switch_core_session_t *session, switch_codec_implementation_t *impp)
switch_status_t switch_core_session_request_video_refresh(switch_core_session_t *session)
switch_channel_t * channel
switch_vid_params_t vid_params
static core_video_globals_t video_globals
An abstraction of a data frame.
Definition: switch_frame.h:43
switch_status_t
Common return values.
switch_rtp_engine_t engines[SWITCH_MEDIA_TYPE_TOTAL]
A table of settings and callbacks that define a paticular implementation of a codec.
#define switch_assert(expr)
#define SWITCH_READ_ACCEPTABLE(status)
Definition: switch_utils.h:995
void switch_core_session_wake_video_thread ( switch_core_session_t session)

Definition at line 6162 of file switch_core_media.c.

References media_helper::cond, media_helper::cond_mutex, switch_media_handle_s::engines, switch_core_media_params_s::external_video_source, switch_rtp_engine_s::media_thread, switch_rtp_engine_s::mh, switch_media_handle_s::mparams, switch_rtp_engine_s::rtp_session, switch_channel_get_name(), SWITCH_CHANNEL_SESSION_LOG, switch_log_printf(), SWITCH_LOG_WARNING, SWITCH_MEDIA_TYPE_VIDEO, switch_mutex_trylock(), switch_mutex_unlock(), SWITCH_STATUS_SUCCESS, and switch_thread_cond_broadcast().

Referenced by switch_channel_clear_flag(), switch_core_media_set_video_file(), switch_core_session_run(), and switch_core_session_stop_media().

6163 {
6164  switch_media_handle_t *smh;
6165  switch_rtp_engine_t *v_engine;
6166 
6167  if (!(smh = session->media_handle)) {
6168  return;
6169  }
6170 
6171  v_engine = &smh->engines[SWITCH_MEDIA_TYPE_VIDEO];
6172 
6173  if ((!smh->mparams->external_video_source) && (!v_engine->rtp_session)) {
6174  return;
6175  }
6176 
6177  if (!v_engine->media_thread) {
6178  return;
6179  }
6180 
6181  if (!v_engine->mh.cond_mutex) {
6182  switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_WARNING, "Channel %s has no cond?\n",
6183  switch_channel_get_name(session->channel));
6184  return;
6185  }
6186 
6189  switch_mutex_unlock(v_engine->mh.cond_mutex);
6190  }
6191 }
#define SWITCH_CHANNEL_SESSION_LOG(x)
switch_status_t switch_mutex_trylock(switch_mutex_t *lock)
Definition: switch_apr.c:295
switch_thread_cond_t * cond
switch_media_handle_t * media_handle
switch_status_t switch_mutex_unlock(switch_mutex_t *lock)
Definition: switch_apr.c:290
switch_channel_t * channel
switch_rtp_t * rtp_session
switch_rtp_engine_t engines[SWITCH_MEDIA_TYPE_TOTAL]
switch_thread_t * media_thread
switch_mutex_t * cond_mutex
void switch_log_printf(_In_ switch_text_channel_t channel, _In_z_ const char *file, _In_z_ const char *func, _In_ int line, _In_opt_z_ const char *userdata, _In_ switch_log_level_t level, _In_z_ _Printf_format_string_ const char *fmt,...) PRINTF_FUNCTION(7
Write log data to the logging engine.
switch_status_t switch_thread_cond_broadcast(switch_thread_cond_t *cond)
Definition: switch_apr.c:376
struct media_helper mh
char * switch_channel_get_name(switch_channel_t *channel)
Retrieve the name of a given channel.
switch_core_media_params_t * mparams
void switch_media_handle_clear_media_flag ( switch_media_handle_t smh,
switch_core_media_flag_t  flag 
)

Definition at line 1727 of file switch_core_media.c.

References switch_assert.

1728 {
1729  switch_assert(smh);
1730 
1731  smh->media_flags[flag] = 0;
1732 }
switch_core_media_flag_t media_flags[SCMF_MAX]
#define switch_assert(expr)
switch_status_t switch_media_handle_create ( switch_media_handle_t **  smhp,
switch_core_session_t session,
switch_core_media_params_t params 
)

Definition at line 1621 of file switch_core_media.c.

References CF_DTLS_OK, CRYPTO_INVALID, switch_core_session::media_handle, SCMF_RUNNING, switch_media_handle_s::session, SMF_INIT, switch_channel_set_flag, switch_channel_set_variable, switch_core_alloc, switch_core_session_alloc, switch_core_session_get_pool(), SWITCH_MEDIA_FLOW_SENDRECV, SWITCH_MEDIA_TYPE_AUDIO, SWITCH_MEDIA_TYPE_VIDEO, switch_mutex_init(), SWITCH_MUTEX_NESTED, SWITCH_RTP_MAX_BUF_LEN, switch_set_flag, SWITCH_STATUS_FALSE, SWITCH_STATUS_SUCCESS, and zstr.

1622 {
1624  switch_media_handle_t *smh = NULL;
1625  int i;
1626 
1627  *smhp = NULL;
1628 
1629  if (zstr(params->sdp_username)) {
1630  params->sdp_username = "FreeSWITCH";
1631  }
1632 
1633 
1634  if ((session->media_handle = switch_core_session_alloc(session, (sizeof(*smh))))) {
1635  session->media_handle->session = session;
1636 
1637 
1638  *smhp = session->media_handle;
1640  session->media_handle->media_flags[SCMF_RUNNING] = 1;
1644 
1645  for (i = 0; i < CRYPTO_INVALID; i++) {
1647  }
1648 
1652 
1653 
1654  switch_channel_set_variable(session->channel, "video_media_flow", "sendrecv");
1655  switch_channel_set_variable(session->channel, "audio_media_flow", "sendrecv");
1656 
1659 
1660  for (i = 0; i < CRYPTO_INVALID; i++) {
1662  }
1663 
1664  session->media_handle->mparams = params;
1665 
1666  if (!session->media_handle->mparams->video_key_freq) {
1667  session->media_handle->mparams->video_key_freq = 10000000;
1668  }
1669 
1670  if (!session->media_handle->mparams->video_key_first) {
1671  session->media_handle->mparams->video_key_first = 1000000;
1672  }
1673 
1674 
1675  for (i = 0; i <= CRYPTO_INVALID; i++) {
1677  }
1678 
1682 
1684  (uint32_t) ((intptr_t) &session->media_handle->engines[SWITCH_MEDIA_TYPE_AUDIO] + (uint32_t) time(NULL));
1685 
1687  (uint32_t) ((intptr_t) &session->media_handle->engines[SWITCH_MEDIA_TYPE_VIDEO] + (uint32_t) time(NULL) / 2);
1688 
1696 
1698 
1699  status = SWITCH_STATUS_SUCCESS;
1700  }
1701 
1702 
1703  return status;
1704 }
struct switch_video_codec_settings video
#define switch_set_flag(obj, flag)
Set a flag on an arbitrary object.
Definition: switch_utils.h:631
switch_core_media_flag_t media_flags[SCMF_MAX]
#define SWITCH_RTP_MAX_BUF_LEN
Definition: switch_rtp.h:44
switch_media_flow_t smode
switch_codec_settings_t codec_settings
switch_secure_settings_t ssec[CRYPTO_INVALID+1]
payload_map_t * payload_map
switch_media_handle_t * media_handle
#define zstr(x)
Definition: switch_utils.h:281
switch_rtp_crypto_key_type_t crypto_suite_order[CRYPTO_INVALID+1]
switch_frame_t read_frame
#define SWITCH_MUTEX_NESTED
Definition: switch_apr.h:318
uint32_t buflen
Definition: switch_frame.h:59
switch_channel_t * channel
#define switch_core_alloc(_pool, _mem)
Allocate memory directly from a memory pool.
Definition: switch_core.h:682
switch_core_session_t * session
payload_map_t * cur_payload_map
switch_status_t switch_mutex_init(switch_mutex_t **lock, unsigned int flags, switch_memory_pool_t *pool)
Definition: switch_apr.c:270
switch_mutex_t * control_mutex
switch_memory_pool_t * pool
switch_status_t
Common return values.
switch_rtp_engine_t engines[SWITCH_MEDIA_TYPE_TOTAL]
switch_mutex_t * mutex
#define switch_channel_set_flag(_c, _f)
#define switch_core_session_alloc(_session, _memory)
Allocate memory from a session's pool.
Definition: switch_core.h:694
switch_mutex_t * sdp_mutex
#define switch_channel_set_variable(_channel, _var, _val)
switch_rtp_crypto_key_type_t crypto_type
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_media_type_t type
switch_rtp_crypto_key_type_t crypto_type
void switch_media_handle_destroy ( switch_core_session_t session)

Definition at line 1577 of file switch_core_media.c.

References switch_media_handle_s::engines, switch_rtp_engine_s::read_codec, switch_assert, switch_core_codec_destroy(), switch_core_codec_ready(), switch_core_media_deactivate_rtp(), switch_core_session_unset_read_codec(), switch_core_session_unset_write_codec(), switch_core_timer_destroy(), SWITCH_MEDIA_TYPE_AUDIO, SWITCH_MEDIA_TYPE_VIDEO, switch_timer::timer_interface, switch_media_handle_s::video_timer, and switch_rtp_engine_s::write_codec.

1578 {
1579  switch_media_handle_t *smh;
1580  switch_rtp_engine_t *a_engine, *v_engine;
1581 
1582  switch_assert(session);
1583 
1584  if (!(smh = session->media_handle)) {
1585  return;
1586  }
1587 
1588  a_engine = &smh->engines[SWITCH_MEDIA_TYPE_AUDIO];
1589  v_engine = &smh->engines[SWITCH_MEDIA_TYPE_VIDEO];
1590 
1591 
1592  if (smh->video_timer.timer_interface) {
1594  }
1595 
1596  if (switch_core_codec_ready(&a_engine->read_codec)) {
1598  }
1599 
1600  if (switch_core_codec_ready(&a_engine->write_codec)) {
1602  }
1603 
1604  if (switch_core_codec_ready(&v_engine->read_codec)) {
1606  }
1607 
1608  if (switch_core_codec_ready(&v_engine->write_codec)) {
1610  }
1611 
1615 
1616 
1617 
1618 }
switch_status_t switch_core_codec_destroy(switch_codec_t *codec)
Destroy an initalized codec handle.
switch_media_handle_t * media_handle
void switch_core_session_unset_write_codec(_In_ switch_core_session_t *session)
switch_codec_t write_codec
switch_timer_interface_t * timer_interface
switch_codec_t read_codec
switch_status_t switch_core_timer_destroy(switch_timer_t *timer)
Destroy an allocated timer.
switch_rtp_engine_t engines[SWITCH_MEDIA_TYPE_TOTAL]
static switch_bool_t switch_core_codec_ready(switch_codec_t *codec)
void switch_core_session_unset_read_codec(_In_ switch_core_session_t *session)
switch_timer_t video_timer
#define switch_assert(expr)
void switch_core_media_deactivate_rtp(switch_core_session_t *session)
void switch_media_handle_set_media_flag ( switch_media_handle_t smh,
switch_core_media_flag_t  flag 
)

Definition at line 1706 of file switch_core_media.c.

References switch_assert.

Referenced by switch_core_media_receive_message().

1707 {
1708  switch_assert(smh);
1709 
1710  smh->media_flags[flag] = 1;
1711 
1712 }
switch_core_media_flag_t media_flags[SCMF_MAX]
#define switch_assert(expr)
void switch_media_handle_set_media_flags ( switch_media_handle_t smh,
switch_core_media_flag_t  flags[] 
)
int32_t switch_media_handle_test_media_flag ( switch_media_handle_t smh,
switch_core_media_flag_t  flag 
)
static const char* switch_media_type2str ( switch_media_type_t  type)
inlinestatic

Definition at line 177 of file switch_core_media.h.

References SWITCH_MEDIA_TYPE_AUDIO, and SWITCH_MEDIA_TYPE_VIDEO.

Referenced by switch_core_media_choose_port().

178 {
179  switch(type) {
181  return "audio";
183  return "video";
184  default:
185  return "!ERR";
186 
187  }
188 }