FreeSWITCH API Documentation  1.7.0
Data Structures | Macros | Typedefs | Enumerations | Functions | Variables
switch_core_media.c File Reference
#include <switch.h>
#include <switch_ssl.h>
#include <switch_stun.h>
#include <switch_nat.h>
#include "private/switch_core_pvt.h"
#include <switch_curl.h>
#include <errno.h>
#include <sofia-sip/sdp.h>
#include <sofia-sip/su.h>
+ Include dependency graph for switch_core_media.c:

Go to the source code of this file.

Data Structures

struct  secure_settings_s
 
struct  core_video_globals_s
 
struct  media_helper
 
struct  switch_rtp_engine_s
 
struct  switch_media_handle_s
 
struct  matches
 

Macros

#define RTCP_MUX
 
#define MAX_CODEC_CHECK_FRAMES   50
 
#define MAX_MISMATCH_FRAMES   5
 
#define type2str(type)   type == SWITCH_MEDIA_TYPE_VIDEO ? "video" : "audio"
 
#define VIDEO_REFRESH_FREQ   1000000
 
#define add_stat(_i, _s)
 
#define add_stat_double(_i, _s)
 
#define MAX_MATCHES   30
 
#define RA_PTR_LEN   512
 
#define SDPBUFLEN   65536
 

Typedefs

typedef struct secure_settings_s switch_secure_settings_t
 
typedef struct core_video_globals_s core_video_globals_t
 
typedef struct switch_rtp_engine_s switch_rtp_engine_t
 

Enumerations

enum  smh_flag_t { SMF_INIT = (1 << 0), SMF_READY = (1 << 1), SMF_JB_PAUSED = (1 << 2) }
 
enum  switch_rtp_crypto_mode_t { CRYPTO_MODE_OPTIONAL, CRYPTO_MODE_MANDATORY, CRYPTO_MODE_FORBIDDEN }
 

Functions

static switch_t38_options_tswitch_core_media_process_udptl (switch_core_session_t *session, sdp_session_t *sdp, sdp_media_t *m)
 
static void switch_core_media_find_zrtp_hash (switch_core_session_t *session, sdp_session_t *sdp)
 
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)
 
static void gen_ice (switch_core_session_t *session, switch_media_type_t type, const char *ip, switch_port_t port)
 
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)
 
static switch_media_flow_t sdp_media_flow (unsigned in)
 
static int get_channels (const char *name, int dft)
 
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)
 
uint32_t switch_core_media_get_video_fps (switch_core_session_t *session)
 
void switch_core_media_pass_zrtp_hash2 (switch_core_session_t *aleg_session, switch_core_session_t *bleg_session)
 
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)
 
switch_status_t switch_core_media_check_autoadj (switch_core_session_t *session)
 
switch_status_t switch_core_media_get_vid_params (switch_core_session_t *session, switch_vid_params_t *vid_params)
 
switch_t38_options_tswitch_core_media_extract_t38_options (switch_core_session_t *session, const char *r_sdp)
 
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)
 
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)
 
const char * switch_core_media_get_codec_string (switch_core_session_t *session)
 
void switch_core_session_clear_crypto (switch_core_session_t *session)
 
const char * switch_core_session_local_crypto_key (switch_core_session_t *session, switch_media_type_t type)
 
void switch_core_media_parse_rtp_bugs (switch_rtp_bug_flag_t *flag_pole, const char *str)
 
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)
 
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_core_media_set_rtp_session (switch_core_session_t *session, switch_media_type_t type, switch_rtp_t *rtp_session)
 
static void switch_core_session_get_recovery_crypto_key (switch_core_session_t *session, switch_media_type_t type)
 
static void switch_core_session_apply_crypto (switch_core_session_t *session, switch_media_type_t type)
 
static void switch_core_session_parse_crypto_prefs (switch_core_session_t *session)
 
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)
 
void switch_core_session_check_outgoing_crypto (switch_core_session_t *session)
 
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_stats (switch_core_session_t *session)
 
void switch_media_handle_destroy (switch_core_session_t *session)
 
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_set_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[SCMF_MAX])
 
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)
 
switch_media_flow_t switch_core_session_media_flow (switch_core_session_t *session, switch_media_type_t type)
 
switch_status_t switch_core_session_media_handle_ready (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_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)
 
static void check_jb (switch_core_session_t *session, const char *input, int32_t jb_msec, int32_t maxlen, switch_bool_t silent)
 
static void check_jb_sync (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)
 
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)
 
void switch_core_media_copy_t38_options (switch_t38_options_t *t38_options, switch_core_session_t *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)
 
static void switch_core_session_parse_codec_settings (switch_core_session_t *session, switch_media_type_t 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)
 
static void clear_ice (switch_core_session_t *session, switch_media_type_t type)
 
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)
 
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_media_check_video_codecs (switch_core_session_t *session)
 
static void generate_local_fingerprint (switch_media_handle_t *smh, switch_media_type_t type)
 
static int dtls_ok (switch_core_session_t *session)
 
switch_call_direction_t switch_ice_direction (switch_core_session_t *session)
 
static switch_status_t ip_choose_family (switch_media_handle_t *smh, const char *ip)
 
static switch_bool_t ip_possible (switch_media_handle_t *smh, const char *ip)
 
static switch_status_t check_ice (switch_media_handle_t *smh, switch_media_type_t type, sdp_session_t *sdp, sdp_media_t *m)
 
void switch_core_session_set_ice (switch_core_session_t *session)
 
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)
 
static void clear_pmaps (switch_rtp_engine_t *engine)
 
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)
 
int switch_core_media_toggle_hold (switch_core_session_t *session, int sendonly)
 
switch_file_handle_tswitch_core_media_get_video_file (switch_core_session_t *session, switch_rw_t rw)
 
static void *SWITCH_THREAD_FUNC video_write_thread (switch_thread_t *thread, void *obj)
 
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)
 
int next_cpu (void)
 
void switch_core_autobind_cpu (void)
 
static void *SWITCH_THREAD_FUNC video_helper_thread (switch_thread_t *thread, void *obj)
 
switch_status_t switch_core_session_start_video_thread (switch_core_session_t *session)
 
void switch_core_media_start_video_function (switch_core_session_t *session, switch_video_function_t video_function, void *user_data)
 
int switch_core_media_check_video_function (switch_core_session_t *session)
 
void switch_core_media_end_video_function (switch_core_session_t *session)
 
switch_bool_t switch_core_session_in_video_thread (switch_core_session_t *session)
 
switch_status_t switch_core_media_proxy_remote_addr (switch_core_session_t *session, const char *sdp_str)
 
int switch_core_media_check_nat (switch_media_handle_t *smh, const char *network_ip)
 
switch_status_t switch_core_media_ext_address_lookup (switch_core_session_t *session, char **ip, switch_port_t *port, const char *sourceip)
 
void switch_core_media_reset_autofix (switch_core_session_t *session, switch_media_type_t type)
 
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_deactivate_rtp (switch_core_session_t *session)
 
void switch_core_session_wake_video_thread (switch_core_session_t *session)
 
static void check_dtls_reinvite (switch_core_session_t *session, switch_rtp_engine_t *engine)
 
switch_status_t switch_core_media_activate_rtp (switch_core_session_t *session)
 
static const char * get_media_profile_name (switch_core_session_t *session, int secure)
 
static char * get_setup (switch_rtp_engine_t *engine, switch_core_session_t *session, switch_sdp_type_t sdp_type)
 
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)
 
void switch_core_media_check_dtmf_type (switch_core_session_t *session)
 
switch_status_t switch_core_media_sdp_map (const char *r_sdp, switch_event_t **fmtp, switch_event_t **pt)
 
void switch_core_media_set_local_sdp (switch_core_session_t *session, const char *sdp_str, switch_bool_t dup)
 
static void add_fb (char *buf, uint32_t buflen, int pt, int fir, int nack, int pli, int tmmbr)
 
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_absorb_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)
 
void switch_core_media_patch_sdp (switch_core_session_t *session)
 
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)
 
static int check_engine (switch_rtp_engine_t *engine)
 
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_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_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)
 
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_get_stats (switch_core_session_t *session, switch_media_type_t type, switch_memory_pool_t *pool)
 
switch_bool_t switch_core_media_check_udptl_mode (switch_core_session_t *session, switch_media_type_t type)
 
switch_status_t switch_core_media_udptl_mode (switch_core_session_t *session, switch_media_type_t type)
 
switch_jb_tswitch_core_media_get_jb (switch_core_session_t *session, 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)
 
static void add_audio_codec (sdp_rtpmap_t *map, const switch_codec_implementation_t *imp, int ptime, char *buf, switch_size_t buflen)
 
switch_status_t switch_core_media_codec_chosen (switch_core_session_t *session, switch_media_type_t type)
 
void switch_core_session_stop_media (switch_core_session_t *session)
 
void switch_core_media_check_outgoing_proxy (switch_core_session_t *session, switch_core_session_t *o_session)
 
void switch_core_media_recover_session (switch_core_session_t *session)
 
void switch_core_media_init (void)
 
void switch_core_media_deinit (void)
 
static int payload_number (const char *name)
 
static int find_pt (const char *sdp, const char *name)
 
char * switch_core_media_filter_sdp (const char *sdp_str, 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_timer_tswitch_core_media_get_timer (switch_core_session_t *session, switch_media_type_t mtype)
 
switch_status_t switch_core_session_request_video_refresh (switch_core_session_t *session)
 
switch_status_t switch_core_session_send_and_request_video_refresh (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_status_t switch_core_session_write_encoded_video_frame (switch_core_session_t *session, switch_frame_t *frame, switch_io_flag_t flags, int stream_id)
 
void switch_core_session_video_reinit (switch_core_session_t *session)
 
switch_status_t switch_core_session_write_video_frame (switch_core_session_t *session, switch_frame_t *frame, switch_io_flag_t flags, int stream_id)
 
switch_status_t switch_core_session_wait_for_video_input_params (switch_core_session_t *session, uint32_t timeout_ms)
 
switch_status_t switch_core_session_read_video_frame (switch_core_session_t *session, switch_frame_t **frame, switch_io_flag_t flags, int stream_id)
 
switch_status_t switch_core_session_set_video_read_callback (switch_core_session_t *session, switch_core_video_thread_callback_func_t func, void *user_data)
 
switch_status_t switch_core_session_video_read_callback (switch_core_session_t *session, switch_frame_t *frame)
 

Variables

static core_video_globals_t video_globals = { 0 }
 
static switch_srtp_crypto_suite_t SUITES [CRYPTO_INVALID]
 

Macro Definition Documentation

#define add_stat (   _i,
  _s 
)
Value:
switch_snprintf(var_name, sizeof(var_name), "rtp_%s_%s", switch_str_nil(prefix), _s) ; \
switch_snprintf(var_val, sizeof(var_val), "%" SWITCH_SIZE_T_FMT, _i); \
switch_channel_set_variable(channel, var_name, var_val)
int switch_snprintf(_Out_z_cap_(len) char *buf, _In_ switch_size_t len, _In_z_ _Printf_format_string_ const char *format,...)
#define switch_str_nil(s)
Make a null string a blank string instead.
Definition: switch_utils.h:903
#define switch_channel_set_variable(_channel, _var, _val)
#define SWITCH_SIZE_T_FMT

Definition at line 1484 of file switch_core_media.c.

Referenced by set_stats().

#define add_stat_double (   _i,
  _s 
)
Value:
switch_snprintf(var_name, sizeof(var_name), "rtp_%s_%s", switch_str_nil(prefix), _s) ; \
switch_snprintf(var_val, sizeof(var_val), "%0.2f", _i); \
switch_channel_set_variable(channel, var_name, var_val)
int switch_snprintf(_Out_z_cap_(len) char *buf, _In_ switch_size_t len, _In_z_ _Printf_format_string_ const char *format,...)
#define switch_str_nil(s)
Make a null string a blank string instead.
Definition: switch_utils.h:903
#define switch_channel_set_variable(_channel, _var, _val)

Definition at line 1489 of file switch_core_media.c.

Referenced by set_stats().

#define MAX_CODEC_CHECK_FRAMES   50

Definition at line 48 of file switch_core_media.c.

Referenced by switch_core_media_read_frame().

#define MAX_MATCHES   30

Definition at line 3610 of file switch_core_media.c.

#define MAX_MISMATCH_FRAMES   5

Definition at line 49 of file switch_core_media.c.

Referenced by switch_core_media_read_frame().

#define RA_PTR_LEN   512

Definition at line 5612 of file switch_core_media.c.

Referenced by switch_core_media_proxy_remote_addr().

#define RTCP_MUX

Definition at line 47 of file switch_core_media.c.

#define SDPBUFLEN   65536

Definition at line 7522 of file switch_core_media.c.

Referenced by switch_core_media_gen_local_sdp().

#define type2str (   type)    type == SWITCH_MEDIA_TYPE_VIDEO ? "video" : "audio"
#define VIDEO_REFRESH_FREQ   1000000

Typedef Documentation

Enumeration Type Documentation

enum smh_flag_t
Enumerator
SMF_INIT 
SMF_READY 
SMF_JB_PAUSED 

Definition at line 53 of file switch_core_media.c.

53  {
54  SMF_INIT = (1 << 0),
55  SMF_READY = (1 << 1),
56  SMF_JB_PAUSED = (1 << 2)
57 } smh_flag_t;
smh_flag_t
Enumerator
CRYPTO_MODE_OPTIONAL 
CRYPTO_MODE_MANDATORY 
CRYPTO_MODE_FORBIDDEN 

Definition at line 89 of file switch_core_media.c.

Function Documentation

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

Definition at line 306 of file switch_core_media.c.

References CF_ZRTP_PASSTHRU_REQ, switch_core_session::channel, switch_media_handle_s::engines, switch_rtp_engine_s::local_sdp_zrtp_hash, switch_core_session::media_handle, switch_rtp_engine_s::remote_sdp_zrtp_hash, SWITCH_CHANNEL_CHANNEL_LOG, switch_channel_set_variable, switch_channel_test_flag(), switch_core_session_strdup, SWITCH_LOG_DEBUG, SWITCH_LOG_DEBUG1, and switch_log_printf().

Referenced by switch_core_media_pass_zrtp_hash2().

307 {
308  switch_rtp_engine_t *aleg_engine;
309  switch_rtp_engine_t *bleg_engine;
310 
311  if (!aleg_session->media_handle || !bleg_session->media_handle) return;
312  aleg_engine = &aleg_session->media_handle->engines[type];
313  bleg_engine = &bleg_session->media_handle->engines[type];
314 
315 
316 
318  "Deciding whether to pass zrtp-hash between a-leg and b-leg\n");
319 
320  if (!(switch_channel_test_flag(aleg_session->channel, CF_ZRTP_PASSTHRU_REQ))) {
322  "CF_ZRTP_PASSTHRU_REQ not set on a-leg, so not propagating zrtp-hash\n");
323  return;
324  }
325 
326  if (aleg_engine->remote_sdp_zrtp_hash) {
327  switch_log_printf(SWITCH_CHANNEL_CHANNEL_LOG(aleg_session->channel), SWITCH_LOG_DEBUG, "Passing a-leg remote zrtp-hash (audio) to b-leg\n");
328  bleg_engine->local_sdp_zrtp_hash = switch_core_session_strdup(bleg_session, aleg_engine->remote_sdp_zrtp_hash);
329  switch_channel_set_variable(bleg_session->channel, "l_sdp_audio_zrtp_hash", bleg_engine->local_sdp_zrtp_hash);
330  }
331 
332  if (bleg_engine->remote_sdp_zrtp_hash) {
333  switch_log_printf(SWITCH_CHANNEL_CHANNEL_LOG(aleg_session->channel), SWITCH_LOG_DEBUG, "Passing b-leg remote zrtp-hash (audio) to a-leg\n");
334  aleg_engine->local_sdp_zrtp_hash = switch_core_session_strdup(aleg_session, bleg_engine->remote_sdp_zrtp_hash);
335  switch_channel_set_variable(aleg_session->channel, "l_sdp_audio_zrtp_hash", aleg_engine->local_sdp_zrtp_hash);
336  }
337 }
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_engine_t engines[SWITCH_MEDIA_TYPE_TOTAL]
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_channel_set_variable(_channel, _var, _val)
#define SWITCH_CHANNEL_CHANNEL_LOG(x)
static void add_audio_codec ( sdp_rtpmap_t *  map,
const switch_codec_implementation_t imp,
int  ptime,
char *  buf,
switch_size_t  buflen 
)
static

Definition at line 9993 of file switch_core_media.c.

References switch_codec_fmtp::bits_per_second, switch_codec_fmtp::microseconds_per_packet, switch_codec_implementation::modname, switch_core_codec_parse_fmtp(), switch_default_ptime(), switch_known_bitrate(), switch_snprintf(), SWITCH_STATUS_SUCCESS, and zstr.

Referenced by switch_core_media_set_r_sdp_codec_string().

9994 {
9995  int codec_ms = ptime;
9996  uint32_t map_bit_rate = 0, map_channels = 1;
9997  char ptstr[20] = "";
9998  char ratestr[20] = "";
9999  char bitstr[20] = "";
10000  switch_codec_fmtp_t codec_fmtp = { 0 };
10001 
10002  if (!codec_ms) {
10003  codec_ms = switch_default_ptime(map->rm_encoding, map->rm_pt);
10004  }
10005 
10006  map_channels = map->rm_params ? atoi(map->rm_params) : 1;
10007  map_bit_rate = switch_known_bitrate((switch_payload_t)map->rm_pt);
10008 
10009  if (!ptime && !strcasecmp(map->rm_encoding, "g723")) {
10010  ptime = codec_ms = 30;
10011  }
10012 
10013  if (zstr(map->rm_fmtp)) {
10014  if (!strcasecmp(map->rm_encoding, "ilbc")) {
10015  ptime = codec_ms = 30;
10016  map_bit_rate = 13330;
10017  } else if (!strcasecmp(map->rm_encoding, "isac")) {
10018  ptime = codec_ms = 30;
10019  map_bit_rate = 32000;
10020  }
10021  } else {
10022  if ((switch_core_codec_parse_fmtp(map->rm_encoding, map->rm_fmtp, map->rm_rate, &codec_fmtp)) == SWITCH_STATUS_SUCCESS) {
10023  if (codec_fmtp.bits_per_second) {
10024  map_bit_rate = codec_fmtp.bits_per_second;
10025  }
10026  if (codec_fmtp.microseconds_per_packet) {
10027  codec_ms = (codec_fmtp.microseconds_per_packet / 1000);
10028  }
10029  }
10030  }
10031 
10032  if (map->rm_rate) {
10033  switch_snprintf(ratestr, sizeof(ratestr), "@%uh", (unsigned int) map->rm_rate);
10034  }
10035 
10036  if (codec_ms) {
10037  switch_snprintf(ptstr, sizeof(ptstr), "@%di", codec_ms);
10038  }
10039 
10040  if (map_bit_rate) {
10041  switch_snprintf(bitstr, sizeof(bitstr), "@%db", map_bit_rate);
10042  }
10043 
10044  if (map_channels > 1) {
10045  switch_snprintf(bitstr, sizeof(bitstr), "@%dc", map_channels);
10046  }
10047 
10048  switch_snprintf(buf + strlen(buf), buflen - strlen(buf), ",%s.%s%s%s%s", imp->modname, map->rm_encoding, ratestr, ptstr, bitstr);
10049 
10050 }
switch_status_t switch_core_codec_parse_fmtp(const char *codec_name, const char *fmtp, uint32_t rate, switch_codec_fmtp_t *codec_fmtp)
int switch_snprintf(_Out_z_cap_(len) char *buf, _In_ switch_size_t len, _In_z_ _Printf_format_string_ const char *format,...)
static uint32_t switch_known_bitrate(switch_payload_t payload)
Definition: switch_utils.h:418
#define zstr(x)
Definition: switch_utils.h:281
switch_byte_t switch_byte_t * buf
uint32_t switch_default_ptime(const char *name, uint32_t number)
Definition: switch_core.c:2026
switch_byte_t switch_byte_t uint32_t buflen
uint8_t switch_payload_t
static void add_fb ( char *  buf,
uint32_t  buflen,
int  pt,
int  fir,
int  nack,
int  pli,
int  tmmbr 
)
static

Definition at line 7501 of file switch_core_media.c.

References switch_snprintf().

Referenced by switch_core_media_gen_local_sdp().

7502 {
7503  if (fir) {
7504  switch_snprintf(buf + strlen(buf), buflen - strlen(buf), "a=rtcp-fb:%d ccm fir\r\n", pt);
7505  }
7506 
7507  if (tmmbr) {
7508  switch_snprintf(buf + strlen(buf), buflen - strlen(buf), "a=rtcp-fb:%d ccm tmmbr\r\n", pt);
7509  }
7510 
7511  if (nack) {
7512  switch_snprintf(buf + strlen(buf), buflen - strlen(buf), "a=rtcp-fb:%d nack\r\n", pt);
7513  }
7514 
7515  if (pli) {
7516  switch_snprintf(buf + strlen(buf), buflen - strlen(buf), "a=rtcp-fb:%d nack pli\r\n", pt);
7517  }
7518 
7519 }
int switch_snprintf(_Out_z_cap_(len) char *buf, _In_ switch_size_t len, _In_z_ _Printf_format_string_ const char *format,...)
switch_byte_t switch_byte_t * buf
switch_byte_t switch_byte_t uint32_t buflen
static void check_dtls_reinvite ( switch_core_session_t session,
switch_rtp_engine_t engine 
)
static

Definition at line 6193 of file switch_core_media.c.

References CF_REINVITE, switch_core_session::channel, switch_rtp_engine_s::dtls_controller, dtls_ok(), DTLS_TYPE_CLIENT, DTLS_TYPE_RTCP, DTLS_TYPE_RTP, DTLS_TYPE_SERVER, switch_rtp_engine_s::local_dtls_fingerprint, switch_rtp_engine_s::new_dtls, switch_rtp_engine_s::remote_dtls_fingerprint, switch_rtp_engine_s::rtcp_mux, switch_rtp_engine_s::rtp_session, dtls_fp_s::str, SWITCH_CHANNEL_SESSION_LOG, switch_channel_test_flag(), SWITCH_LOG_INFO, switch_log_printf(), switch_rtp_add_dtls(), switch_rtp_has_dtls(), switch_rtp_engine_s::type, type2str, and zstr.

Referenced by switch_core_media_activate_rtp().

6194 {
6195  if (switch_channel_test_flag(session->channel, CF_REINVITE) && engine->new_dtls) {
6196 
6197  if (!zstr(engine->local_dtls_fingerprint.str) && switch_rtp_has_dtls() && dtls_ok(session)) {
6198  dtls_type_t xtype, dtype = engine->dtls_controller ? DTLS_TYPE_CLIENT : DTLS_TYPE_SERVER;
6199 
6200  switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_INFO, "RE-SETTING %s DTLS\n", type2str(engine->type));
6201 
6202  xtype = DTLS_TYPE_RTP;
6203  if (engine->rtcp_mux > 0) xtype |= DTLS_TYPE_RTCP;
6204 
6205  switch_rtp_add_dtls(engine->rtp_session, &engine->local_dtls_fingerprint, &engine->remote_dtls_fingerprint, dtype | xtype);
6206 
6207  if (engine->rtcp_mux < 1) {
6208  xtype = DTLS_TYPE_RTCP;
6209  switch_rtp_add_dtls(engine->rtp_session, &engine->local_dtls_fingerprint, &engine->remote_dtls_fingerprint, dtype | xtype);
6210  }
6211 
6212  }
6213  engine->new_dtls = 0;
6214  }
6215 }
#define SWITCH_CHANNEL_SESSION_LOG(x)
char str[MAX_FPSTRLEN]
Definition: switch_core.h:154
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 zstr(x)
Definition: switch_utils.h:281
switch_channel_t * channel
switch_rtp_t * rtp_session
int switch_rtp_has_dtls(void)
Definition: switch_rtp.c:3207
dtls_fingerprint_t local_dtls_fingerprint
dtls_type_t
Definition: switch_core.h:157
dtls_fingerprint_t remote_dtls_fingerprint
static int dtls_ok(switch_core_session_t *session)
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 type2str(type)
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_media_type_t type
static int check_engine ( switch_rtp_engine_t engine)
static

Definition at line 9176 of file switch_core_media.c.

References DS_FAIL, DS_READY, DTLS_TYPE_RTP, switch_rtp_engine_s::read_frame, switch_rtp_engine_s::rtp_session, SWITCH_READ_ACCEPTABLE, switch_rtp_dtls_state(), and switch_rtp_zerocopy_read_frame().

Referenced by switch_core_media_check_dtls().

9177 {
9179  int flags = 0;
9180  switch_status_t status;
9181 
9182  if (dtls_state == DS_READY || dtls_state >= DS_FAIL) return 0;
9183 
9184  status = switch_rtp_zerocopy_read_frame(engine->rtp_session, &engine->read_frame, flags);
9185 
9186  if (!SWITCH_READ_ACCEPTABLE(status)) {
9187  return 0;
9188  }
9189 
9190  return 1;
9191 }
dtls_state_t switch_rtp_dtls_state(switch_rtp_t *rtp_session, dtls_type_t type)
Definition: switch_rtp.c:3215
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
switch_rtp_t * rtp_session
switch_status_t
Common return values.
dtls_state_t
Definition: switch_core.h:164
#define SWITCH_READ_ACCEPTABLE(status)
Definition: switch_utils.h:995
static switch_status_t check_ice ( switch_media_handle_t smh,
switch_media_type_t  type,
sdp_session_t *  sdp,
sdp_media_t *  m 
)
static

Definition at line 3229 of file switch_core_media.c.

References switch_rtp_engine_s::cand_acl, switch_rtp_engine_s::cand_acl_count, ice_s::cand_idx, icand_s::cand_type, ice_s::cands, CF_DTLS, CF_ICE, CF_RECOVERING, CF_REINVITE, switch_core_session::channel, ice_s::chosen, icand_s::component_id, icand_s::con_addr, icand_s::con_port, switch_rtp_engine_s::cur_payload_map, switch_rtp_engine_s::dtls_controller, dtls_ok(), switch_media_handle_s::engines, icand_s::foundation, generate_local_fingerprint(), icand_s::generation, ICE_CONTROLLED, ICE_GOOGLE_JINGLE, switch_rtp_engine_s::ice_in, switch_rtp_engine_s::ice_out, ICE_VANILLA, if(), ip_choose_family(), ip_possible(), IPR_RTCP, IPR_RTP, ice_s::is_chosen, MAX_CAND, switch_media_handle_s::mparams, switch_rtp_engine_s::new_dtls, switch_rtp_engine_s::new_ice, ice_s::options, icand_s::priority, ice_s::pwd, icand_s::raddr, icand_s::ready, switch_rtp_engine_s::remote_dtls_fingerprint, switch_core_media_params_s::remote_ip, switch_rtp_engine_s::remote_rtcp_ice_addr, switch_rtp_engine_s::remote_rtcp_ice_port, switch_rtp_engine_s::remote_rtcp_port, switch_rtp_engine_s::remote_rtp_ice_addr, switch_rtp_engine_s::remote_rtp_ice_port, payload_map_s::remote_sdp_ip, payload_map_s::remote_sdp_port, switch_rtp_engine_s::remote_ssrc, icand_s::rport, 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_rtp_engine_s::rtp_session, switch_media_handle_s::session, dtls_fp_s::str, SWITCH_CALL_DIRECTION_OUTBOUND, switch_channel_get_name(), switch_channel_get_variable, SWITCH_CHANNEL_SESSION_LOG, switch_channel_set_flag, switch_channel_set_variable, switch_channel_test_flag(), switch_check_network_list_ip, switch_core_session_strdup, switch_ice_direction(), SWITCH_LOG_DEBUG, SWITCH_LOG_DEBUG1, SWITCH_LOG_ERROR, SWITCH_LOG_INFO, switch_log_printf(), SWITCH_LOG_WARNING, SWITCH_MEDIA_TYPE_VIDEO, SWITCH_REMOTE_MEDIA_IP_VARIABLE, SWITCH_REMOTE_MEDIA_PORT_VARIABLE, switch_rtp_activate_ice(), switch_rtp_activate_rtcp(), switch_rtp_has_dtls(), switch_rtp_ready(), switch_rtp_set_remote_ssrc(), switch_set_string, switch_snprintf(), switch_split, SWITCH_STATUS_BREAK, SWITCH_STATUS_FALSE, SWITCH_STATUS_SUCCESS, switch_stristr(), SWITCH_TRUE, icand_s::transport, dtls_fp_s::type, type2str, ice_s::ufrag, and zstr.

Referenced by switch_core_media_negotiate_sdp().

3230 {
3231  switch_rtp_engine_t *engine = &smh->engines[type];
3232  sdp_attribute_t *attr;
3233  int i = 0, got_rtcp_mux = 0;
3234  const char *val;
3235  int ice_seen = 0, cid = 0, ai = 0;
3236 
3237  //if (engine->ice_in.is_chosen[0] && engine->ice_in.is_chosen[1]) {
3238  //return SWITCH_STATUS_SUCCESS;
3239  //}
3240 
3241  engine->ice_in.chosen[0] = 0;
3242  engine->ice_in.chosen[1] = 0;
3243  engine->ice_in.is_chosen[0] = 0;
3244  engine->ice_in.is_chosen[1] = 0;
3245  engine->ice_in.cand_idx[0] = 0;
3246  engine->ice_in.cand_idx[1] = 0;
3247  engine->remote_ssrc = 0;
3248 
3249  if (m) {
3250  attr = m->m_attributes;
3251  } else {
3252  attr = sdp->sdp_attributes;
3253  }
3254 
3255  for (; attr; attr = attr->a_next) {
3256  char *data;
3257  char *fields[15];
3258  int argc = 0, j = 0;
3259 
3260  if (zstr(attr->a_name)) {
3261  continue;
3262  }
3263 
3264  if (!strcasecmp(attr->a_name, "ice-ufrag")) {
3265  if (engine->ice_in.ufrag && !strcmp(engine->ice_in.ufrag, attr->a_value)) {
3266  engine->new_ice = 0;
3267  } else {
3268  engine->ice_in.ufrag = switch_core_session_strdup(smh->session, attr->a_value);
3269  engine->new_ice = 1;
3270  }
3271  ice_seen++;
3272  } else if (!strcasecmp(attr->a_name, "ice-pwd")) {
3273  if (!engine->ice_in.pwd || strcmp(engine->ice_in.pwd, attr->a_value)) {
3274  engine->ice_in.pwd = switch_core_session_strdup(smh->session, attr->a_value);
3275  }
3276  } else if (!strcasecmp(attr->a_name, "ice-options")) {
3277  engine->ice_in.options = switch_core_session_strdup(smh->session, attr->a_value);
3278  } else if (!strcasecmp(attr->a_name, "setup")) {
3279  if (!strcasecmp(attr->a_value, "passive") || !strcasecmp(attr->a_value, "actpass")) {
3280  if (!engine->dtls_controller) {
3281  engine->new_dtls = 1;
3282  engine->new_ice = 1;
3283  }
3284  engine->dtls_controller = 1;
3285  } else if (!strcasecmp(attr->a_value, "active")) {
3286  if (engine->dtls_controller) {
3287  engine->new_dtls = 1;
3288  engine->new_ice = 1;
3289  }
3290  engine->dtls_controller = 0;
3291  }
3292  } else if (switch_rtp_has_dtls() && dtls_ok(smh->session) && !strcasecmp(attr->a_name, "fingerprint") && !zstr(attr->a_value)) {
3293  char *p;
3294 
3295  engine->remote_dtls_fingerprint.type = switch_core_session_strdup(smh->session, attr->a_value);
3296 
3297  if ((p = strchr(engine->remote_dtls_fingerprint.type, ' '))) {
3298  *p++ = '\0';
3299 
3301  !zstr(engine->remote_dtls_fingerprint.str) && !strcmp(engine->remote_dtls_fingerprint.str, p)) {
3302  engine->new_dtls = 0;
3303  } else {
3305  engine->new_dtls = 1;
3306  engine->new_ice = 1;
3307  }
3308  }
3309 
3310 
3311  //if (strcasecmp(engine->remote_dtls_fingerprint.type, "sha-256")) {
3312  // switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(smh->session), SWITCH_LOG_WARNING, "Unsupported fingerprint type.\n");
3313  //engine->local_dtls_fingerprint.type = NULL;
3314  //engine->remote_dtls_fingerprint.type = NULL;
3315  //}
3316 
3317 
3318  generate_local_fingerprint(smh, type);
3320 
3321  } else if (!engine->remote_ssrc && !strcasecmp(attr->a_name, "ssrc") && attr->a_value) {
3322  engine->remote_ssrc = (uint32_t) atol(attr->a_value);
3323 
3324  if (engine->rtp_session && engine->remote_ssrc) {
3326  }
3327 
3328 
3329 #ifdef RTCP_MUX
3330  } else if (!strcasecmp(attr->a_name, "rtcp-mux")) {
3331  engine->rtcp_mux = SWITCH_TRUE;
3333  got_rtcp_mux++;
3334 #endif
3335  } else if (!strcasecmp(attr->a_name, "candidate")) {
3337 
3338  if (!engine->cand_acl_count) {
3339  engine->cand_acl[engine->cand_acl_count++] = "wan.auto";
3340  switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(smh->session), SWITCH_LOG_WARNING, "NO candidate ACL defined, Defaulting to wan.auto\n");
3341  }
3342 
3343 
3344  if (!switch_stristr(" udp ", attr->a_value)) {
3345  continue;
3346  }
3347 
3348  data = switch_core_session_strdup(smh->session, attr->a_value);
3349 
3350  argc = switch_split(data, ' ', fields);
3351 
3352  cid = fields[1] ? atoi(fields[1]) - 1 : 0;
3353 
3354  if (argc < 5 || engine->ice_in.cand_idx[cid] >= MAX_CAND - 1) {
3356  continue;
3357  }
3358 
3359  for (i = 0; i < argc; i++) {
3360  switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(smh->session), SWITCH_LOG_DEBUG1, "CAND %d [%s]\n", i, fields[i]);
3361  }
3362 
3363  if (!ip_possible(smh, fields[4])) {
3365  "Drop %s Candidate cid: %d proto: %s type: %s addr: %s:%s (no network path)\n",
3366  type == SWITCH_MEDIA_TYPE_VIDEO ? "video" : "audio",
3367  cid+1, fields[2], fields[7], fields[4], fields[5]);
3368  continue;
3369  } else {
3371  "Save %s Candidate cid: %d proto: %s type: %s addr: %s:%s\n",
3372  type == SWITCH_MEDIA_TYPE_VIDEO ? "video" : "audio",
3373  cid+1, fields[2], fields[7], fields[4], fields[5]);
3374  }
3375 
3376 
3377  engine->ice_in.cands[engine->ice_in.cand_idx[cid]][cid].foundation = switch_core_session_strdup(smh->session, fields[0]);
3378  engine->ice_in.cands[engine->ice_in.cand_idx[cid]][cid].component_id = atoi(fields[1]);
3379  engine->ice_in.cands[engine->ice_in.cand_idx[cid]][cid].transport = switch_core_session_strdup(smh->session, fields[2]);
3380  engine->ice_in.cands[engine->ice_in.cand_idx[cid]][cid].priority = atol(fields[3]);
3381  engine->ice_in.cands[engine->ice_in.cand_idx[cid]][cid].con_addr = switch_core_session_strdup(smh->session, fields[4]);
3382  engine->ice_in.cands[engine->ice_in.cand_idx[cid]][cid].con_port = (switch_port_t)atoi(fields[5]);
3383 
3384  j = 6;
3385 
3386  while(j < argc && fields[j+1]) {
3387  if (!strcasecmp(fields[j], "typ")) {
3388  engine->ice_in.cands[engine->ice_in.cand_idx[cid]][cid].cand_type = switch_core_session_strdup(smh->session, fields[j+1]);
3389  } else if (!strcasecmp(fields[j], "raddr")) {
3390  engine->ice_in.cands[engine->ice_in.cand_idx[cid]][cid].raddr = switch_core_session_strdup(smh->session, fields[j+1]);
3391  } else if (!strcasecmp(fields[j], "rport")) {
3392  engine->ice_in.cands[engine->ice_in.cand_idx[cid]][cid].rport = (switch_port_t)atoi(fields[j+1]);
3393  } else if (!strcasecmp(fields[j], "generation")) {
3394  engine->ice_in.cands[engine->ice_in.cand_idx[cid]][cid].generation = switch_core_session_strdup(smh->session, fields[j+1]);
3395  }
3396 
3397  j += 2;
3398  }
3399 
3400  engine->ice_in.cand_idx[cid]++;
3401  }
3402  }
3403 
3404  if (!ice_seen) {
3405  return SWITCH_STATUS_SUCCESS;
3406  }
3407 
3408 
3409  for (cid = 0; cid < 2; cid++) {
3410  switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(smh->session), SWITCH_LOG_DEBUG, "Searching for %s candidate.\n", cid ? "rtcp" : "rtp");
3411 
3412  for (ai = 0; ai < engine->cand_acl_count; ai++) {
3413  for (i = 0; i < engine->ice_in.cand_idx[cid]; i++) {
3414  if (switch_check_network_list_ip(engine->ice_in.cands[i][cid].con_addr, engine->cand_acl[ai])) {
3416  "Choose %s candidate, index %d, %s:%d\n", cid ? "rtcp" : "rtp", i,
3417  engine->ice_in.cands[i][cid].con_addr, engine->ice_in.cands[i][cid].con_port);
3418 
3419  engine->ice_in.chosen[cid] = i;
3420  engine->ice_in.is_chosen[cid] = 1;
3421  engine->ice_in.cands[i][cid].ready++;
3422  ip_choose_family(smh, engine->ice_in.cands[i][cid].con_addr);
3423 
3424  if (cid == 0 && got_rtcp_mux && engine->ice_in.cand_idx[1] < MAX_CAND) {
3425 
3427  "Choose same candidate, index %d, for rtcp based on rtcp-mux attribute %s:%d\n", engine->ice_in.cand_idx[1],
3428  engine->ice_in.cands[i][cid].con_addr, engine->ice_in.cands[i][cid].con_port);
3429 
3430 
3431  engine->ice_in.cands[engine->ice_in.cand_idx[1]][1] = engine->ice_in.cands[i][0];
3432  engine->ice_in.chosen[1] = engine->ice_in.cand_idx[1];
3433  engine->ice_in.is_chosen[1] = 1;
3434  engine->ice_in.cand_idx[1]++;
3435 
3436  goto done_choosing;
3437  }
3438 
3439  goto next_cid;
3440  }
3441  }
3442  }
3443 
3444  next_cid:
3445 
3446  continue;
3447  }
3448 
3449  done_choosing:
3450 
3451 
3452  if (!engine->ice_in.is_chosen[0] || !engine->ice_in.is_chosen[1]) {
3453  /* PUNT */
3454  switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(smh->session), SWITCH_LOG_DEBUG, "%s no suitable candidates found.\n",
3456  return SWITCH_STATUS_FALSE;
3457  }
3458 
3459  for (i = 0; i < 2; i++) {
3460  if (engine->ice_in.cands[engine->ice_in.chosen[i]][i].ready) {
3461  if (zstr(engine->ice_in.ufrag) || zstr(engine->ice_in.pwd)) {
3462  engine->ice_in.cands[engine->ice_in.chosen[i]][i].ready = 0;
3463  }
3464  }
3465  }
3466 
3467 
3468  if (engine->ice_in.cands[engine->ice_in.chosen[0]][0].con_addr && engine->ice_in.cands[engine->ice_in.chosen[0]][0].con_port) {
3469  char tmp[80] = "";
3470  engine->cur_payload_map->remote_sdp_ip = switch_core_session_strdup(smh->session, (char *) engine->ice_in.cands[engine->ice_in.chosen[0]][0].con_addr);
3472  "setting remote %s ice addr to index %d %s:%d based on candidate\n", type2str(type), engine->ice_in.chosen[0],
3473  engine->ice_in.cands[engine->ice_in.chosen[0]][0].con_addr, engine->ice_in.cands[engine->ice_in.chosen[0]][0].con_port);
3474  engine->ice_in.cands[engine->ice_in.chosen[0]][0].ready++;
3475 
3476  engine->remote_rtp_ice_port = (switch_port_t) engine->ice_in.cands[engine->ice_in.chosen[0]][0].con_port;
3477  engine->remote_rtp_ice_addr = switch_core_session_strdup(smh->session, engine->ice_in.cands[engine->ice_in.chosen[0]][0].con_addr);
3478 
3479  engine->cur_payload_map->remote_sdp_ip = switch_core_session_strdup(smh->session, (char *) engine->ice_in.cands[engine->ice_in.chosen[0]][0].con_addr);
3480  engine->cur_payload_map->remote_sdp_port = (switch_port_t) engine->ice_in.cands[engine->ice_in.chosen[0]][0].con_port;
3481 
3482  if (!smh->mparams->remote_ip) {
3484  }
3485 
3486  switch_snprintf(tmp, sizeof(tmp), "%d", engine->ice_in.cands[engine->ice_in.chosen[0]][0].con_port);
3489  }
3490 
3491  if (engine->ice_in.cands[engine->ice_in.chosen[1]][1].con_port) {
3493  "Setting remote rtcp %s addr to %s:%d based on candidate\n", type2str(type),
3494  engine->ice_in.cands[engine->ice_in.chosen[1]][1].con_addr, engine->ice_in.cands[engine->ice_in.chosen[1]][1].con_port);
3495  engine->remote_rtcp_ice_port = engine->ice_in.cands[engine->ice_in.chosen[1]][1].con_port;
3496  engine->remote_rtcp_ice_addr = switch_core_session_strdup(smh->session, engine->ice_in.cands[engine->ice_in.chosen[1]][1].con_addr);
3497 
3498  engine->remote_rtcp_port = engine->ice_in.cands[engine->ice_in.chosen[1]][1].con_port;
3499  }
3500 
3501 
3502  if (m && !got_rtcp_mux) {
3503  engine->rtcp_mux = -1;
3504  }
3505 
3507  if (switch_rtp_ready(engine->rtp_session) && engine->ice_in.cands[engine->ice_in.chosen[0]][0].ready && engine->new_ice) {
3508  switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(smh->session), SWITCH_LOG_INFO, "RE-Activating %s ICE\n", type2str(type));
3509 
3511  engine->ice_in.ufrag,
3512  engine->ice_out.ufrag,
3513  engine->ice_out.pwd,
3514  engine->ice_in.pwd,
3515  IPR_RTP,
3516 #ifdef GOOGLE_ICE
3518  NULL
3519 #else
3520  switch_ice_direction(smh->session) ==
3522  &engine->ice_in
3523 #endif
3524  );
3525 
3526 
3527  engine->new_ice = 0;
3528  }
3529 
3530 
3531  if (engine->rtp_session && ((val = switch_channel_get_variable(smh->session->channel,
3532  type == SWITCH_MEDIA_TYPE_VIDEO ?
3533  "rtcp_video_interval_msec" : "rtcp_audio_interval_msec"))
3534  || (val = type == SWITCH_MEDIA_TYPE_VIDEO ?
3536 
3537  switch_port_t remote_rtcp_port = engine->remote_rtcp_port;
3538 
3539  if (remote_rtcp_port) {
3540  if (!strcasecmp(val, "passthru")) {
3541  switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(smh->session), SWITCH_LOG_INFO, "Activating %s RTCP PASSTHRU PORT %d\n",
3542  type2str(type), remote_rtcp_port);
3543  switch_rtp_activate_rtcp(engine->rtp_session, -1, remote_rtcp_port, engine->rtcp_mux > 0);
3544  } else {
3545  int interval = atoi(val);
3546  if (interval < 100 || interval > 500000) {
3548  "Invalid rtcp interval spec [%d] must be between 100 and 500000\n", interval);
3549  interval = 5000;
3550  }
3551 
3552  switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(smh->session), SWITCH_LOG_INFO, "Activating %s RTCP PORT %d\n", type2str(type), remote_rtcp_port);
3553  switch_rtp_activate_rtcp(engine->rtp_session, interval, remote_rtcp_port, engine->rtcp_mux > 0);
3554  }
3555  }
3556  }
3557 
3558  if (engine->rtp_session && engine->ice_in.cands[engine->ice_in.chosen[1]][1].ready) {
3559  if (engine->rtcp_mux > 0 && !strcmp(engine->ice_in.cands[engine->ice_in.chosen[1]][1].con_addr, engine->ice_in.cands[engine->ice_in.chosen[0]][0].con_addr)
3560  && engine->ice_in.cands[engine->ice_in.chosen[1]][1].con_port == engine->ice_in.cands[engine->ice_in.chosen[0]][0].con_port) {
3561  switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(smh->session), SWITCH_LOG_INFO, "Skipping %s RTCP ICE (Same as RTP)\n", type2str(type));
3562  } else {
3563  switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(smh->session), SWITCH_LOG_INFO, "Activating %s RTCP ICE\n", type2str(type));
3564 
3566  engine->ice_in.ufrag,
3567  engine->ice_out.ufrag,
3568  engine->ice_out.pwd,
3569  engine->ice_in.pwd,
3570  IPR_RTCP,
3571 #ifdef GOOGLE_ICE
3573  NULL
3574 #else
3575  switch_ice_direction(smh->session) ==
3577  &engine->ice_in
3578 #endif
3579  );
3580  }
3581 
3582  }
3583 
3584  }
3585 
3586  return ice_seen ? SWITCH_STATUS_SUCCESS : SWITCH_STATUS_BREAK;
3587 }
char * generation
Definition: switch_rtp.h:98
int cand_idx[2]
Definition: switch_rtp.h:106
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
int chosen[2]
Definition: switch_rtp.h:107
char * remote_sdp_ip
#define switch_split(_data, _delim, _array)
Definition: switch_utils.h:342
char * foundation
Definition: switch_rtp.h:89
char * raddr
Definition: switch_rtp.h:96
static void generate_local_fingerprint(switch_media_handle_t *smh, switch_media_type_t type)
char str[MAX_FPSTRLEN]
Definition: switch_core.h:154
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.
char * type
Definition: switch_core.h:153
#define switch_check_network_list_ip(_ip_str, _list_name)
Definition: switch_core.h:2404
#define zstr(x)
Definition: switch_utils.h:281
#define SWITCH_REMOTE_MEDIA_IP_VARIABLE
Definition: switch_types.h:210
if((uint32_t)(unpack->cur-unpack->buf) > unpack->buflen)
switch_port_t remote_rtp_ice_port
switch_channel_t * channel
switch_rtp_t * rtp_session
int switch_rtp_has_dtls(void)
Definition: switch_rtp.c:3207
static switch_status_t ip_choose_family(switch_media_handle_t *smh, const char *ip)
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
payload_map_t * cur_payload_map
char * con_addr
Definition: switch_rtp.h:93
switch_status_t switch_rtp_set_remote_ssrc(switch_rtp_t *rtp_session, uint32_t ssrc)
Definition: switch_rtp.c:3733
char * cand_type
Definition: switch_rtp.h:95
char * options
Definition: switch_rtp.h:111
uint8_t ready
Definition: switch_rtp.h:99
uint16_t switch_port_t
char * ufrag
Definition: switch_rtp.h:109
char * transport
Definition: switch_rtp.h:91
dtls_fingerprint_t remote_dtls_fingerprint
switch_call_direction_t switch_ice_direction(switch_core_session_t *session)
switch_rtp_engine_t engines[SWITCH_MEDIA_TYPE_TOTAL]
#define MAX_CAND
Definition: switch_rtp.h:102
static int dtls_ok(switch_core_session_t *session)
char * pwd
Definition: switch_rtp.h:110
int component_id
Definition: switch_rtp.h:90
char * cand_acl[SWITCH_MAX_CAND_ACL]
#define switch_channel_set_flag(_c, _f)
#define switch_set_string(_dst, _src)
Definition: switch_utils.h:665
#define type2str(type)
#define SWITCH_REMOTE_MEDIA_PORT_VARIABLE
Definition: switch_types.h:211
switch_port_t remote_rtcp_port
icand_t cands[MAX_CAND][2]
Definition: switch_rtp.h:105
int is_chosen[2]
Definition: switch_rtp.h:108
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
uint32_t priority
Definition: switch_rtp.h:92
#define switch_core_session_strdup(_session, _todup)
Copy a string using memory allocation from a session's pool.
Definition: switch_core.h:717
static switch_bool_t ip_possible(switch_media_handle_t *smh, const char *ip)
switch_port_t remote_rtcp_ice_port
#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_core_media_params_t * mparams
switch_port_t con_port
Definition: switch_rtp.h:94
switch_port_t rport
Definition: switch_rtp.h:97
static void check_jb ( switch_core_session_t session,
const char *  input,
int32_t  jb_msec,
int32_t  maxlen,
switch_bool_t  silent 
)
static

Definition at line 1875 of file switch_core_media.c.

References CF_JITTERBUFFER, CF_JITTERBUFFER_PLC, switch_core_session::channel, switch_media_handle_s::engines, switch_codec::implementation, switch_core_media_params_s::jb_msec, switch_core_session::media_handle, switch_codec_implementation::microseconds_per_packet, switch_media_handle_s::mparams, switch_rtp_engine_s::read_codec, switch_rtp_engine_s::read_impl, switch_rtp_engine_s::rtp_session, switch_codec_implementation::samples_per_packet, switch_codec_implementation::samples_per_second, switch_assert, switch_channel_get_variable, SWITCH_CHANNEL_SESSION_LOG, switch_channel_set_flag, switch_channel_set_variable, SWITCH_FALSE, switch_false(), SWITCH_LOG_DEBUG, SWITCH_LOG_ERROR, switch_log_printf(), SWITCH_LOG_WARNING, SWITCH_MEDIA_TYPE_AUDIO, SWITCH_MEDIA_TYPE_VIDEO, switch_rtp_activate_jitter_buffer(), switch_rtp_deactivate_jitter_buffer(), switch_rtp_debug_jitter_buffer(), switch_rtp_pause_jitter_buffer(), switch_rtp_set_video_buffer_size(), SWITCH_STATUS_SUCCESS, SWITCH_TRUE, and zstr.

Referenced by check_jb_sync(), switch_core_media_activate_rtp(), switch_core_media_read_frame(), and switch_core_media_receive_message().

1876 {
1877  const char *val;
1878  switch_media_handle_t *smh;
1879  switch_rtp_engine_t *a_engine = NULL, *v_engine = NULL;
1880 
1881  switch_assert(session);
1882 
1883  if (!(smh = session->media_handle)) {
1884  return;
1885  }
1886 
1887  a_engine = &smh->engines[SWITCH_MEDIA_TYPE_AUDIO];
1888  v_engine = &smh->engines[SWITCH_MEDIA_TYPE_VIDEO];
1889 
1890 
1891  if (!zstr(input)) {
1892  const char *s;
1893  if (a_engine->rtp_session) {
1894  if (!strcasecmp(input, "pause")) {
1896  return;
1897  } else if (!strcasecmp(input, "resume")) {
1899  return;
1900  } else if (!strcasecmp(input, "stop")) {
1902  return;
1903  } else if (!strncasecmp(input, "debug:", 6)) {
1904  s = input + 6;
1905  if (s && !strcmp(s, "off")) {
1906  s = NULL;
1907  }
1909  return;
1910  }
1911 
1912  switch_channel_set_variable(session->channel, "jitterbuffer_msec", input);
1913  }
1914 
1915  if (v_engine->rtp_session) {
1916  if (!strncasecmp(input, "vbsize:", 7)) {
1917  int frames = 0, max_frames = 0;
1918  s = input + 7;
1919 
1920  frames = atoi(s);
1921 
1922  if ((s = strchr(s, ':')) && *(s+1) != '\0') {
1923  max_frames = atoi(s+1);
1924  }
1925 
1926  if (frames > 0) {
1927  switch_rtp_set_video_buffer_size(v_engine->rtp_session, frames, max_frames);
1928  }
1929  return;
1930  } else if (!strncasecmp(input, "vdebug:", 7)) {
1931  s = input + 7;
1932 
1933  if (s && !strcmp(s, "off")) {
1934  s = NULL;
1935  }
1936  switch_rtp_debug_jitter_buffer(v_engine->rtp_session, s);
1937  return;
1938  }
1939  }
1940  }
1941 
1942 
1943  if (jb_msec || (val = switch_channel_get_variable(session->channel, "jitterbuffer_msec")) || (val = smh->mparams->jb_msec)) {
1944  char *p;
1945 
1946  if (!jb_msec) {
1947  jb_msec = atoi(val);
1948 
1949  if (strchr(val, 'p') && jb_msec > 0) {
1950  jb_msec *= -1;
1951  }
1952 
1953  if ((p = strchr(val, ':'))) {
1954  p++;
1955  maxlen = atoi(p);
1956 
1957  if (strchr(p, 'p') && maxlen > 0) {
1958  maxlen *= -1;
1959  }
1960  }
1961  }
1962 
1963  if (jb_msec < 0 && jb_msec > -1000) {
1964  jb_msec = (a_engine->read_codec.implementation->microseconds_per_packet / 1000) * abs(jb_msec);
1965  }
1966 
1967  if (maxlen < 0 && maxlen > -1000) {
1968  maxlen = (a_engine->read_codec.implementation->microseconds_per_packet / 1000) * abs(maxlen);
1969  }
1970 
1971  if (jb_msec < 10 || jb_msec > 10000) {
1973  "Invalid Jitterbuffer spec [%d] must be between 10 and 10000\n", jb_msec);
1974  } else {
1975  int qlen, maxqlen = 50;
1976 
1977  qlen = jb_msec / (a_engine->read_impl.microseconds_per_packet / 1000);
1978 
1979  if (maxlen) {
1980  maxqlen = maxlen / (a_engine->read_impl.microseconds_per_packet / 1000);
1981  }
1982 
1983  if (maxqlen < qlen) {
1984  maxqlen = qlen * 5;
1985  }
1986  if (switch_rtp_activate_jitter_buffer(a_engine->rtp_session, qlen, maxqlen,
1987  a_engine->read_impl.samples_per_packet,
1989  if (!silent) {
1991  SWITCH_LOG_DEBUG, "Setting Jitterbuffer to %dms (%d frames) (%d max frames)\n",
1992  jb_msec, qlen, maxqlen);
1993  }
1995  if (!switch_false(switch_channel_get_variable(session->channel, "rtp_jitter_buffer_plc"))) {
1997  }
1998  } else if (!silent) {
2000  SWITCH_LOG_WARNING, "Error Setting Jitterbuffer to %dms (%d frames)\n", jb_msec, qlen);
2001  }
2002 
2003  }
2004  }
2005 
2006 }
#define SWITCH_CHANNEL_SESSION_LOG(x)
switch_status_t switch_rtp_pause_jitter_buffer(switch_rtp_t *rtp_session, switch_bool_t pause)
Definition: switch_rtp.c:4059
switch_media_handle_t * media_handle
#define zstr(x)
Definition: switch_utils.h:281
switch_status_t switch_rtp_deactivate_jitter_buffer(switch_rtp_t *rtp_session)
Definition: switch_rtp.c:4079
const switch_codec_implementation_t * implementation
switch_channel_t * channel
switch_rtp_t * rtp_session
switch_status_t switch_rtp_activate_jitter_buffer(switch_rtp_t *rtp_session, uint32_t queue_frames, uint32_t max_queue_frames, uint32_t samples_per_packet, uint32_t samples_per_second)
Acvite a jitter buffer on an RTP session.
Definition: switch_rtp.c:4146
switch_codec_t read_codec
#define switch_channel_get_variable(_c, _v)
switch_rtp_engine_t engines[SWITCH_MEDIA_TYPE_TOTAL]
#define switch_channel_set_flag(_c, _f)
switch_codec_implementation_t read_impl
switch_status_t switch_rtp_set_video_buffer_size(switch_rtp_t *rtp_session, uint32_t frames, uint32_t max_frames)
Definition: switch_rtp.c:4101
switch_status_t switch_rtp_debug_jitter_buffer(switch_rtp_t *rtp_session, const char *name)
Definition: switch_rtp.c:4126
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.
static int switch_false(const char *expr)
Evaluate the falsefullness of a string expression.
Definition: switch_utils.h:482
#define switch_assert(expr)
#define switch_channel_set_variable(_channel, _var, _val)
switch_core_media_params_t * mparams
static void check_jb_sync ( switch_core_session_t session)
static

Definition at line 2008 of file switch_core_media.c.

References CF_VIDEO, switch_core_session::channel, check_jb(), switch_media_handle_s::engines, core_video_globals_s::fps, switch_core_session::media_handle, switch_rtp_engine_s::rtp_session, switch_assert, switch_channel_get_name(), switch_channel_get_variable_dup(), SWITCH_CHANNEL_SESSION_LOG, switch_channel_test_flag(), switch_core_media_get_video_fps(), switch_core_session_get_uuid(), SWITCH_FALSE, SWITCH_LOG_DEBUG1, switch_log_printf(), SWITCH_MEDIA_TYPE_VIDEO, switch_rtp_get_video_buffer_size(), switch_rtp_set_video_buffer_size(), SWITCH_TRUE, and core_video_globals_s::synced.

Referenced by switch_core_media_read_frame().

2009 {
2010  int32_t jb_sync_msec = 0;
2011  uint32_t fps = 0, frames = 0;
2012  uint32_t min_frames = 0;
2013  uint32_t max_frames = 0;
2014  uint32_t cur_frames = 0;
2015  switch_media_handle_t *smh;
2016  switch_rtp_engine_t *v_engine = NULL;
2017  int sync_audio = 0, sync_video = 0;
2018 
2019  const char *var;
2020 
2021  switch_assert(session);
2022 
2023  if (!switch_channel_test_flag(session->channel, CF_VIDEO)) {
2024  return;
2025  }
2026 
2027  if (!(smh = session->media_handle)) {
2028  return;
2029  }
2030 
2031  v_engine = &smh->engines[SWITCH_MEDIA_TYPE_VIDEO];
2032 
2033  if ((var = switch_channel_get_variable_dup(session->channel, "jb_av_sync_msec", SWITCH_FALSE, -1))) {
2034  int tmp;
2035  char *p;
2036 
2037  if (!strcasecmp(var, "disabled")) {
2038  return;
2039  }
2040 
2041  tmp = atol(var);
2042 
2043  if (tmp && tmp > -50 && tmp < 10000) {
2044  jb_sync_msec = tmp;
2045  }
2046 
2047  if ((p = strchr(var, ':'))) {
2048  p++;
2049  frames = atoi(p);
2050  }
2051  }
2052 
2053  fps = switch_core_media_get_video_fps(session);
2054 
2055  switch_rtp_get_video_buffer_size(v_engine->rtp_session, &min_frames, &max_frames, &cur_frames, NULL);
2056 
2057  if (!frames) {
2058  if (cur_frames != min_frames) {
2059  frames = cur_frames;
2060  } else {
2061  frames = fps / 7.5;
2062  if (frames < 1) frames = 1;
2063  sync_audio = 1;
2064  }
2065  }
2066 
2067  if (!jb_sync_msec) {
2068  jb_sync_msec = frames * 75;
2069  }
2070 
2071 
2072  if (frames != cur_frames) {
2073  switch_rtp_set_video_buffer_size(v_engine->rtp_session, frames, 0);
2074  sync_audio = 1;
2075  sync_video = 1;
2076  }
2077 
2079  SWITCH_LOG_DEBUG1, "%s %s \"%s\" Sync A/V JB to %dms %u VFrames FPS %u a:%s v:%s\n",
2081  switch_channel_get_name(session->channel),
2082  switch_channel_get_variable_dup(session->channel, "caller_id_name", SWITCH_FALSE, -1),
2083  jb_sync_msec, frames, video_globals.fps, sync_audio ? "yes" : "no", sync_video ? "yes" : "no");
2084 
2085  if (sync_audio) {
2086  check_jb(session, NULL, jb_sync_msec, 0, SWITCH_TRUE);
2087  }
2088 
2090 }
#define SWITCH_CHANNEL_SESSION_LOG(x)
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.
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_status_t switch_rtp_get_video_buffer_size(switch_rtp_t *rtp_session, uint32_t *min_frame_len, uint32_t *max_frame_len, uint32_t *cur_frame_len, uint32_t *highest_frame_len)
Definition: switch_rtp.c:4091
static core_video_globals_t video_globals
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_rtp_engine_t engines[SWITCH_MEDIA_TYPE_TOTAL]
switch_status_t switch_rtp_set_video_buffer_size(switch_rtp_t *rtp_session, uint32_t frames, uint32_t max_frames)
Definition: switch_rtp.c:4101
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_core_media_get_video_fps(switch_core_session_t *session)
#define switch_assert(expr)
char * switch_channel_get_name(switch_channel_t *channel)
Retrieve the name of a given channel.
static void clear_ice ( switch_core_session_t session,
switch_media_type_t  type 
)
static

Definition at line 3001 of file switch_core_media.c.

References ice_s::cand_idx, ice_s::chosen, switch_media_handle_s::engines, switch_rtp_engine_s::ice_in, ice_s::is_chosen, switch_core_session::media_handle, memset(), switch_rtp_engine_s::remote_rtcp_port, switch_rtp_engine_s::rtp_session, switch_assert, and switch_rtp_reset().

Referenced by switch_core_media_clear_ice().

3002 {
3003  switch_media_handle_t *smh;
3004  switch_rtp_engine_t *engine;
3005 
3006  switch_assert(session);
3007 
3008  if (!(smh = session->media_handle)) {
3009  return;
3010  }
3011 
3012  engine = &smh->engines[type];
3013 
3014  engine->ice_in.chosen[0] = 0;
3015  engine->ice_in.chosen[1] = 0;
3016  engine->ice_in.is_chosen[0] = 0;
3017  engine->ice_in.is_chosen[1] = 0;
3018  engine->ice_in.cand_idx[0] = 0;
3019  engine->ice_in.cand_idx[1] = 0;
3020  memset(&engine->ice_in, 0, sizeof(engine->ice_in));
3021  engine->remote_rtcp_port = 0;
3022 
3023  if (engine->rtp_session) {
3024  switch_rtp_reset(engine->rtp_session);
3025  }
3026 
3027 }
int cand_idx[2]
Definition: switch_rtp.h:106
void switch_rtp_reset(switch_rtp_t *rtp_session)
Definition: switch_rtp.c:2789
int chosen[2]
Definition: switch_rtp.h:107
switch_media_handle_t * media_handle
switch_rtp_t * rtp_session
switch_rtp_engine_t engines[SWITCH_MEDIA_TYPE_TOTAL]
switch_port_t remote_rtcp_port
int is_chosen[2]
Definition: switch_rtp.h:108
#define switch_assert(expr)
memset(buf, 0, buflen)
static void clear_pmaps ( switch_rtp_engine_t engine)
static

Definition at line 3636 of file switch_core_media.c.

References payload_map_s::allocated, payload_map_s::current, payload_map_s::negotiated, payload_map_s::next, and switch_rtp_engine_s::payload_map.

Referenced by switch_core_media_check_outgoing_proxy(), switch_core_media_negotiate_sdp(), switch_core_media_patch_sdp(), and switch_core_media_receive_message().

3637 {
3638  payload_map_t *pmap;
3639 
3640  for (pmap = engine->payload_map; pmap && pmap->allocated; pmap = pmap->next) {
3641  pmap->negotiated = 0;
3642  pmap->current = 0;
3643  }
3644 }
uint8_t allocated
payload_map_t * payload_map
struct payload_map_s * next
uint8_t negotiated
static int dtls_ok ( switch_core_session_t session)
static

Definition at line 3152 of file switch_core_media.c.

References CF_DTLS_OK, switch_core_session::channel, and switch_channel_test_flag().

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

3153 {
3154  return switch_channel_test_flag(session->channel, CF_DTLS_OK);
3155 }
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_channel_t * channel
static int find_pt ( const char *  sdp,
const char *  name 
)
static

Definition at line 10665 of file switch_core_media.c.

References end_of_p, and switch_stristr().

Referenced by switch_core_media_filter_sdp().

10666 {
10667  const char *p;
10668 
10669  if ((p = switch_stristr(name, sdp))) {
10670  if (p < end_of_p(sdp) && *(p+strlen(name)) == '/' && *(p-1) == ' ') {
10671  p -= 2;
10672 
10673  while(*p > 47 && *p < 58) {
10674  p--;
10675  }
10676  p++;
10677 
10678  if (p) {
10679  return atoi(p);
10680  }
10681  }
10682  }
10683 
10684  return -1;
10685 }
#define end_of_p(_s)
Definition: switch_utils.h:617
const char * switch_stristr(const char *instr, const char *str)
static void gen_ice ( switch_core_session_t session,
switch_media_type_t  type,
const char *  ip,
switch_port_t  port 
)
static

Definition at line 6089 of file switch_core_media.c.

References ice_s::cands, switch_media_handle_s::cname, icand_s::component_id, icand_s::con_addr, icand_s::con_port, switch_media_handle_s::engines, icand_s::foundation, icand_s::generation, switch_rtp_engine_s::ice_out, switch_core_session::media_handle, switch_media_handle_s::msid, icand_s::priority, ice_s::pwd, icand_s::ready, switch_rtp_engine_s::rtcp_mux, switch_assert, switch_core_session_strdup, switch_stun_random_string(), SWITCH_TRUE, icand_s::transport, ice_s::ufrag, and zstr.

Referenced by generate_m(), switch_core_media_activate_rtp(), switch_core_media_gen_local_sdp(), and switch_core_session_stop_media().

6090 {
6091  switch_media_handle_t *smh;
6092  switch_rtp_engine_t *engine;
6093  char tmp[33] = "";
6094 
6095  switch_assert(session);
6096 
6097  if (!(smh = session->media_handle)) {
6098  return;
6099  }
6100 
6101  engine = &smh->engines[type];
6102 
6103 #ifdef RTCP_MUX
6104  if (!engine->rtcp_mux) {// && type == SWITCH_MEDIA_TYPE_AUDIO) {
6105  engine->rtcp_mux = SWITCH_TRUE;
6106  }
6107 #endif
6108 
6109  if (!smh->msid) {
6110  switch_stun_random_string(tmp, 32, NULL);
6111  tmp[32] = '\0';
6112  smh->msid = switch_core_session_strdup(session, tmp);
6113  }
6114 
6115  if (!smh->cname) {
6116  switch_stun_random_string(tmp, 16, NULL);
6117  tmp[16] = '\0';
6118  smh->cname = switch_core_session_strdup(session, tmp);
6119  }
6120 
6121  if (!engine->ice_out.ufrag) {
6122  switch_stun_random_string(tmp, 16, NULL);
6123  tmp[16] = '\0';
6124  engine->ice_out.ufrag = switch_core_session_strdup(session, tmp);
6125  }
6126 
6127  if (!engine->ice_out.pwd) {
6128  switch_stun_random_string(tmp, 24, NULL);
6129  tmp[24] = '\0';
6130  engine->ice_out.pwd = switch_core_session_strdup(session, tmp);
6131  }
6132 
6133  if (!engine->ice_out.cands[0][0].foundation) {
6134  switch_stun_random_string(tmp, 10, "0123456789");
6135  tmp[10] = '\0';
6136  engine->ice_out.cands[0][0].foundation = switch_core_session_strdup(session, tmp);
6137  }
6138 
6139  engine->ice_out.cands[0][0].transport = "udp";
6140 
6141  if (!engine->ice_out.cands[0][0].component_id) {
6142  engine->ice_out.cands[0][0].component_id = 1;
6143  engine->ice_out.cands[0][0].priority = (2^24)*126 + (2^8)*65535 + (2^0)*(256 - engine->ice_out.cands[0][0].component_id);
6144  }
6145 
6146  if (!zstr(ip)) {
6147  engine->ice_out.cands[0][0].con_addr = switch_core_session_strdup(session, ip);
6148  }
6149 
6150  if (port) {
6151  engine->ice_out.cands[0][0].con_port = port;
6152  }
6153 
6154  engine->ice_out.cands[0][0].generation = "0";
6155  //add rport stuff later
6156 
6157  engine->ice_out.cands[0][0].ready = 1;
6158 
6159 
6160 }
char * generation
Definition: switch_rtp.h:98
char * foundation
Definition: switch_rtp.h:89
switch_media_handle_t * media_handle
#define zstr(x)
Definition: switch_utils.h:281
void switch_stun_random_string(char *buf, uint16_t len, char *set)
Writes random characters into a buffer.
Definition: switch_stun.c:125
char * con_addr
Definition: switch_rtp.h:93
uint8_t ready
Definition: switch_rtp.h:99
char * ufrag
Definition: switch_rtp.h:109
char * transport
Definition: switch_rtp.h:91
switch_rtp_engine_t engines[SWITCH_MEDIA_TYPE_TOTAL]
char * pwd
Definition: switch_rtp.h:110
int component_id
Definition: switch_rtp.h:90
icand_t cands[MAX_CAND][2]
Definition: switch_rtp.h:105
uint32_t priority
Definition: switch_rtp.h:92
#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_port_t con_port
Definition: switch_rtp.h:94
static void generate_local_fingerprint ( switch_media_handle_t smh,
switch_media_type_t  type 
)
static

Definition at line 3137 of file switch_core_media.c.

References DTLS_SRTP_FNAME, switch_media_handle_s::engines, dtls_fp_s::len, switch_rtp_engine_s::local_dtls_fingerprint, switch_rtp_engine_s::remote_dtls_fingerprint, switch_core_cert_gen_fingerprint(), and dtls_fp_s::type.

Referenced by check_ice(), and switch_core_media_gen_local_sdp().

3138 {
3139  switch_rtp_engine_t *engine = &smh->engines[type];
3140 
3141  if (!engine->local_dtls_fingerprint.len) {
3142  if (engine->remote_dtls_fingerprint.type) {
3144  } else {
3145  engine->local_dtls_fingerprint.type = "sha-256";
3146  }
3148  }
3149 }
char * type
Definition: switch_core.h:153
int switch_core_cert_gen_fingerprint(const char *prefix, dtls_fingerprint_t *fp)
dtls_fingerprint_t local_dtls_fingerprint
#define DTLS_SRTP_FNAME
Definition: switch_core.h:146
dtls_fingerprint_t remote_dtls_fingerprint
switch_rtp_engine_t engines[SWITCH_MEDIA_TYPE_TOTAL]
uint32_t len
Definition: switch_core.h:151
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 
)
static

Definition at line 7096 of file switch_core_media.c.

References switch_codec_implementation::bits_per_second, ice_s::cands, CF_AVPF, CF_DTLS, CF_LIBERAL_DTMF, CF_RECOVERING, CF_VERBOSE_SDP, switch_core_session::channel, switch_media_handle_s::cname, switch_media_handle_s::cng_ianacodes, 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_suite_order, switch_rtp_engine_s::crypto_type, DTMF_2833, switch_media_handle_s::dtmf_ianacodes, switch_core_media_params_s::dtmf_type, end_of, switch_media_handle_s::engines, switch_codec_implementation::fmtp, switch_media_handle_s::fmtps, gen_ice(), get_channels(), get_media_profile_name(), get_setup(), switch_media_handle_s::ianacodes, switch_codec_implementation::iananame, switch_rtp_engine_s::ice_out, ice_out(), 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, switch_core_session::media_handle, memset(), switch_codec_implementation::microseconds_per_packet, switch_media_handle_s::mparams, switch_media_handle_s::msid, switch_core_media_params_s::num_codecs, switch_media_handle_s::num_rates, switch_codec_implementation::number_of_channels, ice_s::pwd, switch_media_handle_s::rates, icand_s::ready, switch_core_media_params_s::rtcp_audio_interval_msec, switch_rtp_engine_s::rtcp_mux, switch_codec_implementation::samples_per_second, SCMF_LIBERAL_DTMF, SCMF_SUPPRESS_CNG, switch_rtp_engine_s::ssec, switch_rtp_engine_s::ssrc, dtls_fp_s::str, switch_assert, SWITCH_CALL_DIRECTION_OUTBOUND, switch_channel_direction(), SWITCH_CHANNEL_SESSION_LOG, switch_channel_test_flag(), SWITCH_CODEC_TYPE_AUDIO, switch_core_media_get_zrtp_hash(), switch_event_get_header, SWITCH_LOG_DEBUG, switch_log_printf(), switch_media_handle_test_media_flag(), SWITCH_MEDIA_TYPE_AUDIO, switch_snprintf(), switch_stun_random_string(), SWITCH_TRUE, switch_core_media_params_s::te, icand_s::transport, switch_srtp_crypto_suite_s::type, dtls_fp_s::type, ice_s::ufrag, and zstr.

Referenced by switch_core_media_gen_local_sdp().

7100 {
7101  int i = 0;
7102  int rate;
7103  int already_did[128] = { 0 };
7104  int ptime = 0, noptime = 0;
7105  const char *local_sdp_audio_zrtp_hash;
7106  switch_media_handle_t *smh;
7107  switch_rtp_engine_t *a_engine;
7108 
7109  switch_assert(session);
7110 
7111  if (!(smh = session->media_handle)) {
7112  return;
7113  }
7114 
7115  a_engine = &smh->engines[SWITCH_MEDIA_TYPE_AUDIO];
7116 
7117  //switch_snprintf(buf + strlen(buf), buflen - strlen(buf), "m=audio %d RTP/%sAVP%s",
7118  //port, secure ? "S" : "", switch_channel_test_flag(session->channel, CF_AVPF) ? "F" : "");
7119 
7120  switch_snprintf(buf + strlen(buf), buflen - strlen(buf), "m=audio %d %s", port,
7121  get_media_profile_name(session, secure || a_engine->crypto_type != CRYPTO_INVALID));
7122 
7123  for (i = 0; i < smh->mparams->num_codecs; i++) {
7124  const switch_codec_implementation_t *imp = smh->codecs[i];
7125  int this_ptime = (imp->microseconds_per_packet / 1000);
7126 
7127  if (!strcasecmp(imp->iananame, "ilbc") || !strcasecmp(imp->iananame, "isac") ) {
7128  this_ptime = 20;
7129  }
7130 
7131  if (imp->codec_type != SWITCH_CODEC_TYPE_AUDIO) {
7132  continue;
7133  }
7134 
7135  if (!noptime) {
7136  if (!cur_ptime) {
7137  if (!ptime) {
7138  ptime = this_ptime;
7139  }
7140  } else {
7141  if (this_ptime != cur_ptime) {
7142  continue;
7143  }
7144  }
7145  }
7146 
7147  if (smh->ianacodes[i] < 128) {
7148  if (already_did[smh->ianacodes[i]]) {
7149  continue;
7150  }
7151 
7152  already_did[smh->ianacodes[i]] = 1;
7153  }
7154 
7155 
7156  switch_snprintf(buf + strlen(buf), buflen - strlen(buf), " %d", smh->ianacodes[i]);
7157  }
7158 
7159  if (smh->mparams->dtmf_type == DTMF_2833 && smh->mparams->te > 95) {
7160  int i;
7161  for (i = 0; i < smh->num_rates; i++) {
7162  if (smh->dtmf_ianacodes[i]) {
7163  switch_snprintf(buf + strlen(buf), buflen - strlen(buf), " %d", smh->dtmf_ianacodes[i]);
7164  }
7165  if (smh->cng_ianacodes[i] && !switch_media_handle_test_media_flag(smh, SCMF_SUPPRESS_CNG) && cng_type && use_cng) {
7166  switch_snprintf(buf + strlen(buf), buflen - strlen(buf), " %d", smh->cng_ianacodes[i]);
7167  }
7168  }
7169  }
7170 
7171  //if (!switch_media_handle_test_media_flag(smh, SCMF_SUPPRESS_CNG) && cng_type && use_cng) {
7172  //switch_snprintf(buf + strlen(buf), buflen - strlen(buf), " %d", cng_type);
7173  //}
7174 
7175  switch_snprintf(buf + strlen(buf), buflen - strlen(buf), "\r\n");
7176 
7177 
7178  memset(already_did, 0, sizeof(already_did));
7179 
7180 
7181  for (i = 0; i < smh->mparams->num_codecs; i++) {
7182  const switch_codec_implementation_t *imp = smh->codecs[i];
7183  char *fmtp = imp->fmtp;
7184  int this_ptime = imp->microseconds_per_packet / 1000;
7185 
7186  if (imp->codec_type != SWITCH_CODEC_TYPE_AUDIO) {
7187  continue;
7188  }
7189 
7190  if (!strcasecmp(imp->iananame, "ilbc") || !strcasecmp(imp->iananame, "isac")) {
7191  this_ptime = 20;
7192  }
7193 
7194  if (!noptime) {
7195  if (!cur_ptime) {
7196  if (!ptime) {
7197  ptime = this_ptime;
7198  }
7199  } else {
7200  if (this_ptime != cur_ptime) {
7201  continue;
7202  }
7203  }
7204  }
7205 
7206  if (smh->ianacodes[i] < 128) {
7207  if (already_did[smh->ianacodes[i]]) {
7208  continue;
7209  }
7210 
7211  already_did[smh->ianacodes[i]] = 1;
7212  }
7213 
7214  rate = imp->samples_per_second;
7215 
7216  if (map) {
7217  char key[128] = "";
7218  char *check = NULL;
7219  switch_snprintf(key, sizeof(key), "%s:%u", imp->iananame, imp->bits_per_second);
7220 
7221  if ((check = switch_event_get_header(map, key)) || (check = switch_event_get_header(map, imp->iananame))) {
7222  fmtp = check;
7223  }
7224  }
7225 
7226  if (smh->fmtps[i]) {
7227  fmtp = smh->fmtps[i];
7228  }
7229 
7230  if (smh->ianacodes[i] > 95 || switch_channel_test_flag(session->channel, CF_VERBOSE_SDP)) {
7231  int channels = get_channels(imp->iananame, imp->number_of_channels);
7232 
7233  if (channels > 1) {
7234  switch_snprintf(buf + strlen(buf), buflen - strlen(buf), "a=rtpmap:%d %s/%d/%d\r\n", smh->ianacodes[i], imp->iananame, rate, channels);
7235 
7236  } else {
7237  switch_snprintf(buf + strlen(buf), buflen - strlen(buf), "a=rtpmap:%d %s/%d\r\n", smh->ianacodes[i], imp->iananame, rate);
7238  }
7239  }
7240 
7241  if (fmtp) {
7242  switch_snprintf(buf + strlen(buf), buflen - strlen(buf), "a=fmtp:%d %s\r\n", smh->ianacodes[i], fmtp);
7243  }
7244  }
7245 
7246 
7248  switch_channel_test_flag(session->channel, CF_LIBERAL_DTMF)) && smh->mparams->te > 95) {
7249 
7250  for (i = 0; i < smh->num_rates; i++) {
7251  if (switch_channel_test_flag(session->channel, CF_AVPF)) {
7252  switch_snprintf(buf + strlen(buf), buflen - strlen(buf), "a=rtpmap:%d telephone-event/%d\r\n",
7253  smh->dtmf_ianacodes[i], smh->rates[i]);
7254  } else {
7255  switch_snprintf(buf + strlen(buf), buflen - strlen(buf), "a=rtpmap:%d telephone-event/%d\r\na=fmtp:%d 0-16\r\n",
7256  smh->dtmf_ianacodes[i], smh->rates[i], smh->dtmf_ianacodes[i]);
7257  }
7258  }
7259  }
7260 
7261  if (!zstr(a_engine->local_dtls_fingerprint.type) && secure) {
7262  switch_snprintf(buf + strlen(buf), buflen - strlen(buf), "a=fingerprint:%s %s\na=setup:%s\r\n", a_engine->local_dtls_fingerprint.type,
7263  a_engine->local_dtls_fingerprint.str, get_setup(a_engine, session, sdp_type));
7264  }
7265 
7266  if (smh->mparams->rtcp_audio_interval_msec) {
7267  if (a_engine->rtcp_mux > 0) {
7268  switch_snprintf(buf + strlen(buf), buflen - strlen(buf), "a=rtcp-mux\r\n");
7269  switch_snprintf(buf + strlen(buf), buflen - strlen(buf), "a=rtcp:%d IN %s %s\r\n", port, family, ip);
7270  } else {
7271  switch_snprintf(buf + strlen(buf), buflen - strlen(buf), "a=rtcp:%d IN %s %s\r\n", port + 1, family, ip);
7272  }
7273  }
7274 
7275  //switch_snprintf(buf + strlen(buf), SDPBUFLEN - strlen(buf), "a=ssrc:%u\r\n", a_engine->ssrc);
7276 
7277  if (a_engine->ice_out.cands[0][0].ready) {
7278  char tmp1[11] = "";
7279  char tmp2[11] = "";
7280  uint32_t c1 = (2^24)*126 + (2^8)*65535 + (2^0)*(256 - 1);
7281  uint32_t c2 = c1 - 1;
7282 
7283  //uint32_t c2 = (2^24)*126 + (2^8)*65535 + (2^0)*(256 - 2);
7284  //uint32_t c3 = (2^24)*126 + (2^8)*65534 + (2^0)*(256 - 1);
7285  //uint32_t c4 = (2^24)*126 + (2^8)*65534 + (2^0)*(256 - 2);
7286  ice_t *ice_out;
7287 
7288  tmp1[10] = '\0';
7289  tmp2[10] = '\0';
7290  switch_stun_random_string(tmp1, 10, "0123456789");
7291  switch_stun_random_string(tmp2, 10, "0123456789");
7292 
7293  gen_ice(session, SWITCH_MEDIA_TYPE_AUDIO, NULL, 0);
7294 
7295  ice_out = &a_engine->ice_out;
7296 
7297  switch_snprintf(buf + strlen(buf), buflen - strlen(buf), "a=ssrc:%u cname:%s\r\n", a_engine->ssrc, smh->cname);
7298  switch_snprintf(buf + strlen(buf), buflen - strlen(buf), "a=ssrc:%u msid:%s a0\r\n", a_engine->ssrc, smh->msid);
7299  switch_snprintf(buf + strlen(buf), buflen - strlen(buf), "a=ssrc:%u mslabel:%s\r\n", a_engine->ssrc, smh->msid);
7300  switch_snprintf(buf + strlen(buf), buflen - strlen(buf), "a=ssrc:%u label:%sa0\r\n", a_engine->ssrc, smh->msid);
7301 
7302 
7303  switch_snprintf(buf + strlen(buf), buflen - strlen(buf), "a=ice-ufrag:%s\r\n", ice_out->ufrag);
7304  switch_snprintf(buf + strlen(buf), buflen - strlen(buf), "a=ice-pwd:%s\r\n", ice_out->pwd);
7305 
7306 
7307  switch_snprintf(buf + strlen(buf), buflen - strlen(buf), "a=candidate:%s 1 %s %u %s %d typ host generation 0\r\n",
7308  tmp1, ice_out->cands[0][0].transport, c1,
7309  ice_out->cands[0][0].con_addr, ice_out->cands[0][0].con_port
7310  );
7311 
7312  if (!zstr(a_engine->local_sdp_ip) && !zstr(ice_out->cands[0][0].con_addr) &&
7313  strcmp(a_engine->local_sdp_ip, ice_out->cands[0][0].con_addr)
7314  && a_engine->local_sdp_port != ice_out->cands[0][0].con_port) {
7315 
7316  switch_snprintf(buf + strlen(buf), buflen - strlen(buf), "a=candidate:%s 1 %s %u %s %d typ srflx raddr %s rport %d generation 0\r\n",
7317  tmp2, ice_out->cands[0][0].transport, c2,
7318  ice_out->cands[0][0].con_addr, ice_out->cands[0][0].con_port,
7319  a_engine->local_sdp_ip, a_engine->local_sdp_port
7320  );
7321  }
7322 
7324 
7325 
7326  switch_snprintf(buf + strlen(buf), buflen - strlen(buf), "a=candidate:%s 2 %s %u %s %d typ host generation 0\r\n",
7327  tmp1, ice_out->cands[0][0].transport, c1,
7328  ice_out->cands[0][0].con_addr, ice_out->cands[0][0].con_port + (a_engine->rtcp_mux > 0 ? 0 : 1)
7329  );
7330 
7331  if (!zstr(a_engine->local_sdp_ip) && !zstr(ice_out->cands[0][1].con_addr) &&
7332  strcmp(a_engine->local_sdp_ip, ice_out->cands[0][1].con_addr)
7333  && a_engine->local_sdp_port != ice_out->cands[0][1].con_port) {
7334 
7335  switch_snprintf(buf + strlen(buf), buflen - strlen(buf), "a=candidate:%s 2 %s %u %s %d typ srflx raddr %s rport %d generation 0\r\n",
7336  tmp2, ice_out->cands[0][0].transport, c2,
7337  ice_out->cands[0][0].con_addr, ice_out->cands[0][0].con_port + (a_engine->rtcp_mux > 0 ? 0 : 1),
7338  a_engine->local_sdp_ip, a_engine->local_sdp_port + (a_engine->rtcp_mux > 0 ? 0 : 1)
7339  );
7340  }
7341  }
7342 
7343 
7344 
7345 #ifdef GOOGLE_ICE
7346  switch_snprintf(buf + strlen(buf), buflen - strlen(buf), "a=ice-options:google-ice\r\n");
7347 #endif
7348  }
7349 
7350 
7351  if (secure && !switch_channel_test_flag(session->channel, CF_DTLS)) {
7352  int i;
7353 
7354  for (i = 0; smh->crypto_suite_order[i] != CRYPTO_INVALID; i++) {
7356 
7357  if ((a_engine->crypto_type == j || a_engine->crypto_type == CRYPTO_INVALID) && !zstr(a_engine->ssec[j].local_crypto_key)) {
7358  switch_snprintf(buf + strlen(buf), buflen - strlen(buf), "a=crypto:%s\r\n", a_engine->ssec[j].local_crypto_key);
7359  }
7360  }
7361  //switch_snprintf(buf + strlen(buf), sizeof(buf) - strlen(buf), "a=encryption:optional\r\n");
7362  }
7363 
7364  if (cng_type) {
7365  for (i = 0; i < smh->num_rates; i++) {
7366  //if (smh->rates[i] == 8000) {
7367  // switch_snprintf(buf + strlen(buf), buflen - strlen(buf), "a=rtpmap:%d CN/%d\r\n", cng_type, smh->rates[i]);
7368  //} else {
7369  switch_snprintf(buf + strlen(buf), buflen - strlen(buf), "a=rtpmap:%d CN/%d\r\n", smh->cng_ianacodes[i], smh->rates[i]);
7370  //}
7371  }
7372  } else {
7374  switch_snprintf(buf + strlen(buf), buflen - strlen(buf), "a=silenceSupp:off - - - -\r\n");
7375  }
7376  }
7377 
7378  if (append_audio) {
7379  switch_snprintf(buf + strlen(buf), buflen - strlen(buf), "%s%s", append_audio, end_of(append_audio) == '\n' ? "" : "\r\n");
7380  }
7381 
7382  if (!cur_ptime) {
7383  cur_ptime = ptime;
7384  }
7385 
7386  if (!noptime && cur_ptime) {
7387  switch_snprintf(buf + strlen(buf), buflen - strlen(buf), "a=ptime:%d\r\n", cur_ptime);
7388  }
7389 
7390  local_sdp_audio_zrtp_hash = switch_core_media_get_zrtp_hash(session, SWITCH_MEDIA_TYPE_AUDIO, SWITCH_TRUE);
7391 
7392  if (local_sdp_audio_zrtp_hash) {
7393  switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_DEBUG, "Adding audio a=zrtp-hash:%s\n", local_sdp_audio_zrtp_hash);
7394  switch_snprintf(buf + strlen(buf), buflen - strlen(buf), "a=zrtp-hash:%s\r\n", local_sdp_audio_zrtp_hash);
7395  }
7396 
7397  if (!zstr(sr)) {
7398  switch_snprintf(buf + strlen(buf), buflen - strlen(buf), "a=%s\r\n", sr);
7399  }
7400 }
#define SWITCH_CHANNEL_SESSION_LOG(x)
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)
static int get_channels(const char *name, int dft)
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 end_of(_s)
Definition: switch_utils.h:616
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,...)
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]
char * type
Definition: switch_core.h:153
switch_media_handle_t * media_handle
char * fmtps[SWITCH_MAX_CODECS]
#define zstr(x)
Definition: switch_utils.h:281
static switch_status_t ice_out(switch_rtp_t *rtp_session, switch_rtp_ice_t *ice)
Definition: switch_rtp.c:771
switch_rtp_crypto_key_type_t crypto_suite_order[CRYPTO_INVALID+1]
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]
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
switch_byte_t switch_byte_t uint32_t buflen
switch_port_t local_sdp_port
char * ufrag
Definition: switch_rtp.h:109
char * transport
Definition: switch_rtp.h:91
switch_rtp_engine_t engines[SWITCH_MEDIA_TYPE_TOTAL]
char * pwd
Definition: switch_rtp.h:110
#define switch_event_get_header(_e, _h)
Definition: switch_event.h:172
switch_call_direction_t switch_channel_direction(switch_channel_t *channel)
switch_payload_t cng_ianacodes[SWITCH_MAX_CODECS]
icand_t cands[MAX_CAND][2]
Definition: switch_rtp.h:105
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.
#define switch_assert(expr)
memset(buf, 0, buflen)
switch_core_media_params_t * mparams
switch_port_t con_port
Definition: switch_rtp.h:94
switch_rtp_crypto_key_type_t type
Definition: switch_rtp.h:67
switch_rtp_crypto_key_type_t crypto_type
static int get_channels ( const char *  name,
int  dft 
)
static

Definition at line 296 of file switch_core_media.c.

References switch_core_get_variable(), switch_true(), and zstr.

Referenced by generate_m(), and switch_core_media_gen_local_sdp().

297 {
298 
299  if (!zstr(name) && !switch_true(switch_core_get_variable("NDLB_broken_opus_sdp")) && !strcasecmp(name, "opus")) {
300  return 2; /* IKR???*/
301  }
302 
303  return dft ? dft : 1;
304 }
static int switch_true(const char *expr)
Evaluate the truthfullness of a string expression.
Definition: switch_utils.h:450
#define zstr(x)
Definition: switch_utils.h:281
char * switch_core_get_variable(_In_z_ const char *varname)
Retrieve a global variable from the core.
static const char* get_media_profile_name ( switch_core_session_t session,
int  secure 
)
static

Definition at line 7053 of file switch_core_media.c.

References CF_AVPF, CF_AVPF_MOZ, CF_DTLS, switch_core_session::channel, switch_assert, and switch_channel_test_flag().

Referenced by generate_m(), and switch_core_media_gen_local_sdp().

7054 {
7055  switch_assert(session);
7056 
7057  if (switch_channel_test_flag(session->channel, CF_AVPF)) {
7058  if (switch_channel_test_flag(session->channel, CF_DTLS) || secure) {
7059  if (switch_channel_test_flag(session->channel, CF_AVPF_MOZ)) {
7060  return "UDP/TLS/RTP/SAVPF";
7061  } else {
7062  return "RTP/SAVPF";
7063  }
7064  } else {
7065  if (switch_channel_test_flag(session->channel, CF_AVPF_MOZ)) {
7066  return "UDP/AVPF";
7067  } else {
7068  return "RTP/AVPF";
7069  }
7070  }
7071  }
7072 
7073  if (secure) {
7074  return "RTP/SAVP";
7075  }
7076 
7077  return "RTP/AVP";
7078 
7079 }
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_channel_t * channel
#define switch_assert(expr)
static char* get_setup ( switch_rtp_engine_t engine,
switch_core_session_t session,
switch_sdp_type_t  sdp_type 
)
static

Definition at line 7081 of file switch_core_media.c.

References switch_rtp_engine_s::dtls_controller, switch_rtp_engine_s::new_dtls, switch_rtp_engine_s::new_ice, and SDP_TYPE_REQUEST.

Referenced by generate_m(), and switch_core_media_gen_local_sdp().

7082 {
7083 
7084  if (sdp_type == SDP_TYPE_REQUEST) {
7085  engine->dtls_controller = 0;
7086  engine->new_dtls = 1;
7087  engine->new_ice = 1;
7088  return "actpass";
7089  } else {
7090  return engine->dtls_controller ? "active" : "passive";
7091  }
7092 }
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 
)
static

Definition at line 3618 of file switch_core_media.c.

References matches::imp, switch_media_handle_s::mparams, and switch_core_media_params_s::num_codecs.

Referenced by switch_core_media_negotiate_sdp().

3619 {
3620  int j = 0, f = 0, g;
3621  struct matches mtmp[MAX_MATCHES] = { { 0 } };
3622  for(j = 0; j < m_idx; j++) {
3623  *&mtmp[j] = *&matches[j];
3624  }
3625  for (g = 0; g < smh->mparams->num_codecs && g < total_codecs; g++) {
3626  const switch_codec_implementation_t *imp = codec_array[g];
3627 
3628  for(j = 0; j < m_idx; j++) {
3629  if (mtmp[j].imp == imp) {
3630  *&matches[f++] = *&mtmp[j];
3631  }
3632  }
3633  }
3634 }
#define MAX_MATCHES
const switch_codec_implementation_t * imp
A table of settings and callbacks that define a paticular implementation of a codec.
switch_core_media_params_t * mparams
static switch_status_t ip_choose_family ( switch_media_handle_t smh,
const char *  ip 
)
static

Definition at line 3183 of file switch_core_media.c.

References switch_core_session::channel, switch_media_handle_s::mparams, switch_core_media_params_s::rtpip, switch_core_media_params_s::rtpip4, switch_core_media_params_s::rtpip6, switch_media_handle_s::session, switch_channel_get_name(), SWITCH_CHANNEL_SESSION_LOG, SWITCH_LOG_DEBUG, switch_log_printf(), SWITCH_STATUS_FALSE, SWITCH_STATUS_SUCCESS, and zstr.

Referenced by check_ice().

3184 {
3186 
3187  if (zstr(ip)) {
3188  return status;
3189  }
3190 
3191  if (strchr(ip, ':')) {
3192  if (!zstr(smh->mparams->rtpip6)) {
3193  smh->mparams->rtpip = smh->mparams->rtpip6;
3194  switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(smh->session), SWITCH_LOG_DEBUG, "%s choosing family v6\n",
3196  status = SWITCH_STATUS_SUCCESS;
3197  }
3198  } else {
3199  if (!zstr(smh->mparams->rtpip4)) {
3200  smh->mparams->rtpip = smh->mparams->rtpip4;
3201  switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(smh->session), SWITCH_LOG_DEBUG, "%s choosing family v4\n",
3203  status = SWITCH_STATUS_SUCCESS;
3204  }
3205  }
3206 
3207  return status;
3208 }
#define SWITCH_CHANNEL_SESSION_LOG(x)
#define zstr(x)
Definition: switch_utils.h:281
switch_channel_t * channel
switch_core_session_t * session
switch_status_t
Common return values.
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
static switch_bool_t ip_possible ( switch_media_handle_t smh,
const char *  ip 
)
static

Definition at line 3211 of file switch_core_media.c.

References switch_media_handle_s::mparams, switch_core_media_params_s::rtpip4, switch_core_media_params_s::rtpip6, SWITCH_FALSE, and zstr.

Referenced by check_ice().

3212 {
3214 
3215  if (zstr(ip)) {
3216  return r;
3217  }
3218 
3219  if (strchr(ip, ':')) {
3220  r = (switch_bool_t) !zstr(smh->mparams->rtpip6);
3221  } else {
3222  r = (switch_bool_t) !zstr(smh->mparams->rtpip4);
3223  }
3224 
3225  return r;
3226 }
switch_bool_t
Definition: switch_types.h:405
#define zstr(x)
Definition: switch_utils.h:281
switch_core_media_params_t * mparams
int next_cpu ( void  )

Definition at line 5315 of file switch_core_media.c.

References core_video_globals_s::cpu_count, core_video_globals_s::cur_cpu, core_video_globals_s::mutex, SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG1, switch_log_printf(), switch_mutex_lock(), and switch_mutex_unlock().

Referenced by switch_core_autobind_cpu().

5316 {
5317  int x = 0;
5318 
5320  x = video_globals.cur_cpu++;
5322  video_globals.cur_cpu = 0;
5323  }
5325  switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG1, "Binding to CPU %d\n", x);
5326 
5327  return x;
5328 }
#define SWITCH_CHANNEL_LOG
switch_status_t switch_mutex_unlock(switch_mutex_t *lock)
Definition: switch_apr.c:290
switch_mutex_t * mutex
switch_status_t switch_mutex_lock(switch_mutex_t *lock)
Definition: switch_apr.c:285
static core_video_globals_t video_globals
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.
static int payload_number ( const char *  name)
static

Definition at line 10628 of file switch_core_media.c.

Referenced by switch_core_media_filter_sdp().

10629 {
10630  if (!strcasecmp(name, "pcmu")) {
10631  return 0;
10632  }
10633 
10634  if (!strcasecmp(name, "pcma")) {
10635  return 8;
10636  }
10637 
10638  if (!strcasecmp(name, "gsm")) {
10639  return 3;
10640  }
10641 
10642  if (!strcasecmp(name, "g722")) {
10643  return 9;
10644  }
10645 
10646  if (!strcasecmp(name, "g729")) {
10647  return 18;
10648  }
10649 
10650  if (!strcasecmp(name, "dvi4")) {
10651  return 5;
10652  }
10653 
10654  if (!strcasecmp(name, "h261")) {
10655  return 31;
10656  }
10657 
10658  if (!strcasecmp(name, "h263")) {
10659  return 34;
10660  }
10661 
10662  return -1;
10663 }
static switch_media_flow_t sdp_media_flow ( unsigned  in)
inlinestatic

Definition at line 280 of file switch_core_media.c.

References SWITCH_MEDIA_FLOW_INACTIVE, SWITCH_MEDIA_FLOW_RECVONLY, SWITCH_MEDIA_FLOW_SENDONLY, and SWITCH_MEDIA_FLOW_SENDRECV.

Referenced by switch_core_media_negotiate_sdp().

281 {
282  switch(in) {
283  case sdp_sendonly:
285  case sdp_recvonly:
287  case sdp_sendrecv:
289  case sdp_inactive:
291  }
292 
294 }
switch_byte_t in
static void set_stats ( switch_core_session_t session,
switch_media_type_t  type,
const char *  prefix 
)
static

Definition at line 1494 of file switch_core_media.c.

References add_stat, add_stat_double, switch_rtp_numbers_t::burstrate, switch_rtp_numbers_t::cng_packet_count, switch_rtp_numbers_t::dtmf_packet_count, switch_rtp_numbers_t::flaws, switch_rtp_numbers_t::flush_packet_count, switch_rtp_stats_t::inbound, switch_rtp_numbers_t::jb_packet_count, switch_rtp_numbers_t::largest_jb_size, switch_rtp_numbers_t::lossrate, switch_rtp_numbers_t::max_variance, switch_rtp_numbers_t::mean_interval, switch_rtp_numbers_t::media_bytes, switch_rtp_numbers_t::media_packet_count, switch_rtp_numbers_t::min_variance, switch_rtp_numbers_t::mos, switch_rtcp_numbers_t::octet_count, switch_rtp_stats_t::outbound, switch_rtp_numbers_t::packet_count, switch_rtcp_numbers_t::packet_count, switch_rtp_numbers_t::R, switch_rtp_numbers_t::raw_bytes, switch_rtp_stats_t::rtcp, switch_rtp_numbers_t::skip_packet_count, switch_rtp_numbers_t::std_deviation, switch_core_media_get_stats(), switch_core_session_get_channel(), and switch_rtp_numbers_t::variance.

Referenced by switch_core_media_set_stats().

1495 {
1496  switch_rtp_stats_t *stats = switch_core_media_get_stats(session, type, NULL);
1498 
1499  char var_name[256] = "", var_val[35] = "";
1500 
1501  if (stats) {
1502  stats->inbound.std_deviation = sqrt(stats->inbound.variance);
1503 
1504  add_stat(stats->inbound.raw_bytes, "in_raw_bytes");
1505  add_stat(stats->inbound.media_bytes, "in_media_bytes");
1506  add_stat(stats->inbound.packet_count, "in_packet_count");
1507  add_stat(stats->inbound.media_packet_count, "in_media_packet_count");
1508  add_stat(stats->inbound.skip_packet_count, "in_skip_packet_count");
1509  add_stat(stats->inbound.jb_packet_count, "in_jitter_packet_count");
1510  add_stat(stats->inbound.dtmf_packet_count, "in_dtmf_packet_count");
1511  add_stat(stats->inbound.cng_packet_count, "in_cng_packet_count");
1512  add_stat(stats->inbound.flush_packet_count, "in_flush_packet_count");
1513  add_stat(stats->inbound.largest_jb_size, "in_largest_jb_size");
1514  add_stat_double(stats->inbound.min_variance, "in_jitter_min_variance");
1515  add_stat_double(stats->inbound.max_variance, "in_jitter_max_variance");
1516  add_stat_double(stats->inbound.lossrate, "in_jitter_loss_rate");
1517  add_stat_double(stats->inbound.burstrate, "in_jitter_burst_rate");
1518  add_stat_double(stats->inbound.mean_interval, "in_mean_interval");
1519  add_stat(stats->inbound.flaws, "in_flaw_total");
1520  add_stat_double(stats->inbound.R, "in_quality_percentage");
1521  add_stat_double(stats->inbound.mos, "in_mos");
1522 
1523 
1524  add_stat(stats->outbound.raw_bytes, "out_raw_bytes");
1525  add_stat(stats->outbound.media_bytes, "out_media_bytes");
1526  add_stat(stats->outbound.packet_count, "out_packet_count");
1527  add_stat(stats->outbound.media_packet_count, "out_media_packet_count");
1528  add_stat(stats->outbound.skip_packet_count, "out_skip_packet_count");
1529  add_stat(stats->outbound.dtmf_packet_count, "out_dtmf_packet_count");
1530  add_stat(stats->outbound.cng_packet_count, "out_cng_packet_count");
1531 
1532  add_stat(stats->rtcp.packet_count, "rtcp_packet_count");
1533  add_stat(stats->rtcp.octet_count, "rtcp_octet_count");
1534 
1535  }
1536 }
switch_size_t flaws
Definition: switch_types.h:657
#define add_stat(_i, _s)
switch_rtp_numbers_t inbound
Definition: switch_types.h:690
switch_size_t largest_jb_size
Definition: switch_types.h:637
switch_size_t media_bytes
Definition: switch_types.h:628
switch_size_t dtmf_packet_count
Definition: switch_types.h:634
_Ret_ switch_channel_t * switch_core_session_get_channel(_In_ switch_core_session_t *session)
Retrieve a pointer to the channel object associated with a given session.
switch_rtcp_numbers_t rtcp
Definition: switch_types.h:692
switch_size_t raw_bytes
Definition: switch_types.h:627
switch_rtp_stats_t * switch_core_media_get_stats(switch_core_session_t *session, switch_media_type_t type, switch_memory_pool_t *pool)
switch_rtp_numbers_t outbound
Definition: switch_types.h:691
switch_size_t packet_count
Definition: switch_types.h:629
switch_size_t jb_packet_count
Definition: switch_types.h:633
switch_size_t skip_packet_count
Definition: switch_types.h:632
#define add_stat_double(_i, _s)
switch_size_t flush_packet_count
Definition: switch_types.h:636
switch_size_t media_packet_count
Definition: switch_types.h:631
switch_size_t cng_packet_count
Definition: switch_types.h:635
void switch_core_autobind_cpu ( void  )

Definition at line 5330 of file switch_core_media.c.

References core_video_globals_s::cpu_count, next_cpu(), and switch_core_thread_set_cpu_affinity().

Referenced by video_helper_thread().

5331 {
5332  if (video_globals.cpu_count > 1) {
5334  }
5335 }
switch_status_t switch_core_thread_set_cpu_affinity(int cpu)
Definition: switch_core.c:1723
int next_cpu(void)
static core_video_globals_t video_globals
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