FreeSWITCH API Documentation  1.7.0
Data Structures | Macros | Typedefs | Enumerations | Functions | Variables
switch_rtp.c File Reference
#include <switch.h>
#include <switch_private.h>
#include <switch_stun.h>
#include <apr_network_io.h>
#include <datatypes.h>
#include <srtp.h>
#include <srtp_priv.h>
#include <switch_ssl.h>
#include <switch_jitterbuffer.h>
+ Include dependency graph for switch_rtp.c:

Go to the source code of this file.

Data Structures

struct  rtp_msg_t
 
struct  rtcp_fir_t
 
struct  switch_rtcp_sdes_unit_s
 
struct  rtcp_tmmbx_t
 
struct  switch_rtcp_ext_hdr_t
 
struct  rtcp_ext_msg_t
 
struct  rtcp_msg_t
 
struct  switch_rtp_vad_data
 
struct  switch_rtp_rfc2833_data
 
struct  switch_rtp_ice_t
 
struct  switch_dtls_s
 
struct  ts_normalize_s
 
struct  switch_rtp
 
struct  switch_rtcp_report_block
 
struct  switch_rtcp_sr_head
 
struct  switch_rtcp_sender_info
 
struct  switch_rtcp_sender_report
 
struct  switch_rtcp_receiver_report
 

Macros

#define JITTER_LEAD_FRAMES   10
 
#define READ_INC(rtp_session)   switch_mutex_lock(rtp_session->read_mutex); rtp_session->reading++
 
#define READ_DEC(rtp_session)   switch_mutex_unlock(rtp_session->read_mutex); rtp_session->reading--
 
#define WRITE_INC(rtp_session)   switch_mutex_lock(rtp_session->write_mutex); rtp_session->writing++
 
#define WRITE_DEC(rtp_session)   switch_mutex_unlock(rtp_session->write_mutex); rtp_session->writing--
 
#define RTP_STUN_FREQ   1000000
 
#define rtp_header_len   12
 
#define RTP_START_PORT   16384
 
#define RTP_END_PORT   32768
 
#define MASTER_KEY_LEN   30
 
#define RTP_MAGIC_NUMBER   42
 
#define WARN_SRTP_ERRS   10
 
#define MAX_SRTP_ERRS   100
 
#define NTP_TIME_OFFSET   2208988800UL
 
#define ZRTP_MAGIC_COOKIE   0x5a525450
 
#define DTMF_SANITY   (rtp_session->one_second * 30)
 
#define rtp_session_name(_rtp_session)   _rtp_session->session ? switch_core_session_get_name(_rtp_session->session) : "-"
 
#define RTP_BODY(_s)   (char *) (_s->recv_msg.ebody ? _s->recv_msg.ebody : _s->recv_msg.body)
 
#define rtp_type(rtp_session)   rtp_session->flags[SWITCH_RTP_FLAG_VIDEO] ? "video" : "audio"
 
#define MAX_NACK   10
 
#define dtls_set_state(_dtls, _state)   switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(rtp_session->session), SWITCH_LOG_INFO, "Changing %s DTLS state from %s to %s\n", rtp_type(rtp_session), dtls_state_names(_dtls->state), dtls_state_names(_state)); _dtls->new_state = 1; _dtls->last_state = _dtls->state; _dtls->state = _state
 
#define cr_keylen   16
 
#define cr_saltlen   14
 
#define cr_kslen   30
 
#define return_cng_frame()   do_cng = 1; goto timer_check
 

Typedefs

typedef srtp_hdr_t rtp_hdr_t
 
typedef struct
switch_rtcp_sdes_unit_s 
switch_rtcp_sdes_unit_t
 
typedef struct switch_dtls_s switch_dtls_t
 
typedef int(* dtls_state_handler_t )(switch_rtp_t *, switch_dtls_t *)
 
typedef struct ts_normalize_s ts_normalize_t
 

Enumerations

enum  vad_talk_mask_t { VAD_FIRE_TALK = (1 << 0), VAD_FIRE_NOT_TALK = (1 << 1) }
 
enum  handle_rfc2833_result_t { RESULT_CONTINUE, RESULT_GOTO_END, RESULT_GOTO_RECVFROM, RESULT_GOTO_TIMERCHECK }
 

Functions

static switch_size_t do_flush (switch_rtp_t *rtp_session, int force, switch_size_t bytes_in)
 
static int dtls_state_handshake (switch_rtp_t *rtp_session, switch_dtls_t *dtls)
 
static int dtls_state_ready (switch_rtp_t *rtp_session, switch_dtls_t *dtls)
 
static int dtls_state_setup (switch_rtp_t *rtp_session, switch_dtls_t *dtls)
 
static int dtls_state_fail (switch_rtp_t *rtp_session, switch_dtls_t *dtls)
 
static void do_2833 (switch_rtp_t *rtp_session)
 
static void switch_rtp_change_ice_dest (switch_rtp_t *rtp_session, switch_rtp_ice_t *ice, const char *host, switch_port_t port)
 
static handle_rfc2833_result_t handle_rfc2833 (switch_rtp_t *rtp_session, switch_size_t bytes, int *do_cng)
 
static int rtp_write_ready (switch_rtp_t *rtp_session, uint32_t bytes, int line)
 
static int rtp_common_write (switch_rtp_t *rtp_session, rtp_msg_t *send_msg, void *data, uint32_t datalen, switch_payload_t payload, uint32_t timestamp, switch_frame_flag_t *flags)
 
static switch_status_t ice_out (switch_rtp_t *rtp_session, switch_rtp_ice_t *ice)
 
int icecmp (const char *them, switch_rtp_ice_t *ice)
 
static void handle_ice (switch_rtp_t *rtp_session, switch_rtp_ice_t *ice, void *data, switch_size_t len)
 
void switch_rtp_init (switch_memory_pool_t *pool)
 Initilize the RTP System. More...
 
static uint8_t get_next_write_ts (switch_rtp_t *rtp_session, uint32_t timestamp)
 
static void do_mos (switch_rtp_t *rtp_session, int force)
 
void burstr_calculate (int loss[], int received, double *burstr, double *lossr)
 
static void reset_jitter_seq (switch_rtp_t *rtp_session)
 
static void check_jitter (switch_rtp_t *rtp_session)
 
static void rtcp_generate_sender_info (switch_rtp_t *rtp_session, struct switch_rtcp_sender_info *sr)
 
static void rtcp_generate_report_block (switch_rtp_t *rtp_session, struct switch_rtcp_report_block *rtcp_report_block)
 
static void rtcp_stats_init (switch_rtp_t *rtp_session)
 
static int rtcp_stats (switch_rtp_t *rtp_session)
 
static void calc_bw_exp (uint32_t bps, uint8_t bits, rtcp_tmmbx_t *tmmbx)
 
static int using_ice (switch_rtp_t *rtp_session)
 
static int check_rtcp_and_ice (switch_rtp_t *rtp_session)
 
void switch_rtp_ping (switch_rtp_t *rtp_session)
 
void switch_rtp_get_random (void *buf, uint32_t len)
 
void switch_rtp_shutdown (void)
 
switch_port_t switch_rtp_set_start_port (switch_port_t port)
 Set/Get RTP start port. More...
 
switch_port_t switch_rtp_set_end_port (switch_port_t port)
 Set/Get RTP end port. More...
 
void switch_rtp_release_port (const char *ip, switch_port_t port)
 
switch_port_t switch_rtp_request_port (const char *ip)
 Request a new port to be used for media. More...
 
switch_status_t switch_rtp_set_payload_map (switch_rtp_t *rtp_session, payload_map_t **pmap)
 
void switch_rtp_intentional_bugs (switch_rtp_t *rtp_session, switch_rtp_bug_flag_t bugs)
 
static switch_status_t enable_remote_rtcp_socket (switch_rtp_t *rtp_session, const char **err)
 
static switch_status_t enable_local_rtcp_socket (switch_rtp_t *rtp_session, const char **err)
 
switch_status_t switch_rtp_set_local_address (switch_rtp_t *rtp_session, const char *host, switch_port_t port, const char **err)
 Assign a local address to the RTP session. More...
 
void switch_rtp_set_max_missed_packets (switch_rtp_t *rtp_session, uint32_t max)
 
void switch_rtp_reset_jb (switch_rtp_t *rtp_session)
 
void switch_rtp_reset_vb (switch_rtp_t *rtp_session)
 
void switch_rtp_reset (switch_rtp_t *rtp_session)
 
void switch_rtp_reset_media_timer (switch_rtp_t *rtp_session)
 
char * switch_rtp_get_remote_host (switch_rtp_t *rtp_session)
 
switch_port_t switch_rtp_get_remote_port (switch_rtp_t *rtp_session)
 
static void ping_socket (switch_rtp_t *rtp_session)
 
switch_status_t switch_rtp_udptl_mode (switch_rtp_t *rtp_session)
 
switch_status_t switch_rtp_set_remote_address (switch_rtp_t *rtp_session, const char *host, switch_port_t port, switch_port_t remote_rtcp_port, switch_bool_t change_adv_addr, const char **err)
 Assign a remote address to the RTP session. More...
 
static const char * dtls_state_names (dtls_state_t s)
 
static void free_dtls (switch_dtls_t **dtlsp)
 
static int do_dtls (switch_rtp_t *rtp_session, switch_dtls_t *dtls)
 
int switch_rtp_has_dtls (void)
 
dtls_state_t switch_rtp_dtls_state (switch_rtp_t *rtp_session, dtls_type_t type)
 
switch_status_t switch_rtp_del_dtls (switch_rtp_t *rtp_session, dtls_type_t type)
 
switch_status_t switch_rtp_add_dtls (switch_rtp_t *rtp_session, dtls_fingerprint_t *local_fp, dtls_fingerprint_t *remote_fp, dtls_type_t type)
 
switch_status_t switch_rtp_add_crypto_key (switch_rtp_t *rtp_session, switch_rtp_crypto_direction_t direction, uint32_t index, switch_rtp_crypto_key_type_t type, unsigned char *key, switch_size_t keylen)
 
switch_status_t switch_rtp_set_interval (switch_rtp_t *rtp_session, uint32_t ms_per_packet, uint32_t samples_per_interval)
 
switch_status_t switch_rtp_change_interval (switch_rtp_t *rtp_session, uint32_t ms_per_packet, uint32_t samples_per_interval)
 
switch_status_t switch_rtp_set_ssrc (switch_rtp_t *rtp_session, uint32_t ssrc)
 
switch_status_t switch_rtp_set_remote_ssrc (switch_rtp_t *rtp_session, uint32_t ssrc)
 
switch_status_t switch_rtp_create (switch_rtp_t **new_rtp_session, switch_payload_t payload, uint32_t samples_per_interval, uint32_t ms_per_packet, switch_rtp_flag_t flags[SWITCH_RTP_FLAG_INVALID], char *timer_name, const char **err, switch_memory_pool_t *pool)
 
switch_rtp_tswitch_rtp_new (const char *rx_host, switch_port_t rx_port, const char *tx_host, switch_port_t tx_port, switch_payload_t payload, uint32_t samples_per_interval, uint32_t ms_per_packet, switch_rtp_flag_t flags[SWITCH_RTP_FLAG_INVALID], char *timer_name, const char **err, switch_memory_pool_t *pool)
 
void switch_rtp_set_telephony_event (switch_rtp_t *rtp_session, switch_payload_t te)
 Set the payload type to consider RFC2833 DTMF. More...
 
void switch_rtp_set_telephony_recv_event (switch_rtp_t *rtp_session, switch_payload_t te)
 
void switch_rtp_set_cng_pt (switch_rtp_t *rtp_session, switch_payload_t pt)
 Set the payload type for comfort noise. More...
 
switch_timer_tswitch_rtp_get_media_timer (switch_rtp_t *rtp_session)
 
switch_jb_tswitch_rtp_get_jitter_buffer (switch_rtp_t *rtp_session)
 
switch_status_t switch_rtp_pause_jitter_buffer (switch_rtp_t *rtp_session, switch_bool_t pause)
 
switch_status_t switch_rtp_deactivate_jitter_buffer (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)
 
switch_status_t switch_rtp_set_video_buffer_size (switch_rtp_t *rtp_session, uint32_t frames, uint32_t max_frames)
 
switch_status_t switch_rtp_debug_jitter_buffer (switch_rtp_t *rtp_session, const char *name)
 
switch_status_t switch_rtp_activate_jitter_buffer (switch_rtp_t *rtp_session, uint32_t queue_frames, uint32_t max_queue_frames, uint32_t samples_per_packet, uint32_t samples_per_second)
 Acvite a jitter buffer on an RTP session. More...
 
switch_status_t switch_rtp_activate_rtcp (switch_rtp_t *rtp_session, int send_rate, switch_port_t remote_port, switch_bool_t mux)
 Activate sending RTCP Sender Reports (SR's) More...
 
switch_status_t switch_rtp_activate_ice (switch_rtp_t *rtp_session, char *login, char *rlogin, const char *password, const char *rpassword, ice_proto_t proto, switch_core_media_ice_type_t type, ice_t *ice_params)
 Acvite ICE on an RTP session. More...
 
void switch_rtp_flush (switch_rtp_t *rtp_session)
 
switch_status_t switch_rtp_req_bitrate (switch_rtp_t *rtp_session, uint32_t bps)
 
switch_status_t switch_rtp_ack_bitrate (switch_rtp_t *rtp_session, uint32_t bps)
 
void switch_rtp_video_refresh (switch_rtp_t *rtp_session)
 
void switch_rtp_video_loss (switch_rtp_t *rtp_session)
 
void switch_rtp_break (switch_rtp_t *rtp_session)
 
void switch_rtp_kill_socket (switch_rtp_t *rtp_session)
 Kill the socket on an existing RTP session. More...
 
uint8_t switch_rtp_ready (switch_rtp_t *rtp_session)
 Test if an RTP session is ready. More...
 
switch_status_t switch_rtp_sync_stats (switch_rtp_t *rtp_session)
 
void switch_rtp_destroy (switch_rtp_t **rtp_session)
 Destroy an RTP session. More...
 
void switch_rtp_set_interdigit_delay (switch_rtp_t *rtp_session, uint32_t delay)
 
switch_socket_tswitch_rtp_get_rtp_socket (switch_rtp_t *rtp_session)
 Retrieve the socket from an existing RTP session. More...
 
uint32_t switch_rtp_get_default_samples_per_interval (switch_rtp_t *rtp_session)
 Get the default samples per interval for a given RTP session. More...
 
void switch_rtp_set_default_payload (switch_rtp_t *rtp_session, switch_payload_t payload)
 Set the default payload number for a given RTP session. More...
 
uint32_t switch_rtp_get_default_payload (switch_rtp_t *rtp_session)
 Get the default payload number for a given RTP session. More...
 
void switch_rtp_set_invalid_handler (switch_rtp_t *rtp_session, switch_rtp_invalid_handler_t on_invalid)
 Set a callback function to execute when an invalid RTP packet is encountered. More...
 
void switch_rtp_set_flags (switch_rtp_t *rtp_session, switch_rtp_flag_t flags[SWITCH_RTP_FLAG_INVALID])
 
void switch_rtp_clear_flags (switch_rtp_t *rtp_session, switch_rtp_flag_t flags[SWITCH_RTP_FLAG_INVALID])
 
void switch_rtp_set_flag (switch_rtp_t *rtp_session, switch_rtp_flag_t flag)
 Set an RTP Flag. More...
 
uint32_t switch_rtp_test_flag (switch_rtp_t *rtp_session, switch_rtp_flag_t flags)
 Test an RTP Flag. More...
 
void switch_rtp_clear_flag (switch_rtp_t *rtp_session, switch_rtp_flag_t flag)
 Clear an RTP Flag. More...
 
static void set_dtmf_delay (switch_rtp_t *rtp_session, uint32_t ms, uint32_t max_ms)
 
void rtp_flush_read_buffer (switch_rtp_t *rtp_session, switch_rtp_flush_t flush)
 
static int jb_valid (switch_rtp_t *rtp_session)
 
static int check_recv_payload (switch_rtp_t *rtp_session)
 
static int get_recv_payload (switch_rtp_t *rtp_session)
 
static switch_status_t read_rtp_packet (switch_rtp_t *rtp_session, switch_size_t *bytes, switch_frame_flag_t *flags, switch_status_t poll_status, switch_bool_t return_jb_packet)
 
static void handle_nack (switch_rtp_t *rtp_session, uint32_t nack)
 
static switch_status_t process_rtcp_report (switch_rtp_t *rtp_session, rtcp_msg_t *msg, switch_size_t bytes)
 
static switch_status_t process_rtcp_packet (switch_rtp_t *rtp_session, switch_size_t *bytes)
 
static switch_status_t read_rtcp_packet (switch_rtp_t *rtp_session, switch_size_t *bytes, switch_frame_flag_t *flags)
 
static int rtp_common_read (switch_rtp_t *rtp_session, switch_payload_t *payload_type, payload_map_t **pmapP, switch_frame_flag_t *flags, switch_io_flag_t io_flags)
 
switch_byte_t switch_rtp_check_auto_adj (switch_rtp_t *rtp_session)
 
switch_size_t switch_rtp_has_dtmf (switch_rtp_t *rtp_session)
 Test for presence of DTMF on a given RTP session. More...
 
switch_size_t switch_rtp_dequeue_dtmf (switch_rtp_t *rtp_session, switch_dtmf_t *dtmf)
 Retrieve DTMF digits from a given RTP session. More...
 
switch_status_t switch_rtp_queue_rfc2833 (switch_rtp_t *rtp_session, const switch_dtmf_t *dtmf)
 Queue RFC2833 DTMF data into an RTP Session. More...
 
switch_status_t switch_rtp_queue_rfc2833_in (switch_rtp_t *rtp_session, const switch_dtmf_t *dtmf)
 Queue RFC2833 DTMF data into an RTP Session. More...
 
switch_status_t switch_rtp_read (switch_rtp_t *rtp_session, void *data, uint32_t *datalen, switch_payload_t *payload_type, switch_frame_flag_t *flags, switch_io_flag_t io_flags)
 Read data from a given RTP session. More...
 
switch_status_t switch_rtcp_zerocopy_read_frame (switch_rtp_t *rtp_session, switch_rtcp_frame_t *frame)
 Read RTCP data from a given RTP session without copying. More...
 
switch_status_t switch_rtp_zerocopy_read_frame (switch_rtp_t *rtp_session, switch_frame_t *frame, switch_io_flag_t io_flags)
 Read data from a given RTP session without copying. More...
 
switch_status_t switch_rtp_zerocopy_read (switch_rtp_t *rtp_session, void **data, uint32_t *datalen, switch_payload_t *payload_type, switch_frame_flag_t *flags, switch_io_flag_t io_flags)
 Read data from a given RTP session without copying. More...
 
switch_status_t switch_rtp_disable_vad (switch_rtp_t *rtp_session)
 Disable VAD on an RTP Session. More...
 
switch_status_t switch_rtp_enable_vad (switch_rtp_t *rtp_session, switch_core_session_t *session, switch_codec_t *codec, switch_vad_flag_t flags)
 Enable VAD on an RTP Session. More...
 
int switch_rtp_write_frame (switch_rtp_t *rtp_session, switch_frame_t *frame)
 Write data to a given RTP session. More...
 
switch_rtp_stats_tswitch_rtp_get_stats (switch_rtp_t *rtp_session, switch_memory_pool_t *pool)
 
int switch_rtp_write_manual (switch_rtp_t *rtp_session, void *data, uint32_t datalen, uint8_t m, switch_payload_t payload, uint32_t ts, switch_frame_flag_t *flags)
 Write data with a specified payload and sequence number to a given RTP session. More...
 
switch_status_t switch_rtp_write_raw (switch_rtp_t *rtp_session, void *data, switch_size_t *bytes, switch_bool_t process_encryption)
 
uint32_t switch_rtp_get_ssrc (switch_rtp_t *rtp_session)
 Retrieve the SSRC from a given RTP session. More...
 
void switch_rtp_set_private (switch_rtp_t *rtp_session, void *private_data)
 Associate an arbitrary data pointer with and RTP session. More...
 
void * switch_rtp_get_private (switch_rtp_t *rtp_session)
 Retrieve the private data from a given RTP session. More...
 

Variables

static const switch_payload_t INVALID_PT = 255
 
static switch_port_t START_PORT = RTP_START_PORT
 
static switch_port_t END_PORT = RTP_END_PORT
 
static switch_mutex_tport_lock = NULL
 
static switch_hash_talloc_hash = NULL
 
dtls_state_handler_t dtls_states [DS_INVALID] = {NULL, dtls_state_handshake, dtls_state_setup, dtls_state_ready, dtls_state_fail}
 
static int global_init = 0
 
static const char * dtls_state_names_t [] = {"OFF", "HANDSHAKE", "SETUP", "READY", "FAIL", "INVALID"}
 

Macro Definition Documentation

#define cr_keylen   16

Definition at line 3001 of file switch_rtp.c.

Referenced by dtls_state_setup().

#define cr_kslen   30

Definition at line 3003 of file switch_rtp.c.

Referenced by dtls_state_setup().

#define cr_saltlen   14

Definition at line 3002 of file switch_rtp.c.

Referenced by dtls_state_setup().

#define dtls_set_state (   _dtls,
  _state 
)    switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(rtp_session->session), SWITCH_LOG_INFO, "Changing %s DTLS state from %s to %s\n", rtp_type(rtp_session), dtls_state_names(_dtls->state), dtls_state_names(_state)); _dtls->new_state = 1; _dtls->last_state = _dtls->state; _dtls->state = _state

Definition at line 2999 of file switch_rtp.c.

Referenced by dtls_state_handshake(), dtls_state_setup(), and switch_rtp_add_dtls().

#define DTMF_SANITY   (rtp_session->one_second * 30)

Definition at line 77 of file switch_rtp.c.

Referenced by handle_rfc2833().

#define JITTER_LEAD_FRAMES   10

Definition at line 59 of file switch_rtp.c.

Referenced by check_jitter(), and rtp_common_read().

#define MASTER_KEY_LEN   30

Definition at line 69 of file switch_rtp.c.

#define MAX_NACK   10

Definition at line 1955 of file switch_rtp.c.

Referenced by check_rtcp_and_ice().

#define MAX_SRTP_ERRS   100

Definition at line 72 of file switch_rtp.c.

Referenced by read_rtp_packet().

#define NTP_TIME_OFFSET   2208988800UL
#define READ_DEC (   rtp_session)    switch_mutex_unlock(rtp_session->read_mutex); rtp_session->reading--
#define READ_INC (   rtp_session)    switch_mutex_lock(rtp_session->read_mutex); rtp_session->reading++
#define return_cng_frame ( )    do_cng = 1; goto timer_check

Definition at line 5131 of file switch_rtp.c.

Referenced by rtp_common_read().

#define RTP_BODY (   _s)    (char *) (_s->recv_msg.ebody ? _s->recv_msg.ebody : _s->recv_msg.body)
#define RTP_END_PORT   32768

Definition at line 68 of file switch_rtp.c.

#define rtp_header_len   12
#define RTP_MAGIC_NUMBER   42

Definition at line 70 of file switch_rtp.c.

#define rtp_session_name (   _rtp_session)    _rtp_session->session ? switch_core_session_get_name(_rtp_session->session) : "-"
#define RTP_START_PORT   16384

Definition at line 67 of file switch_rtp.c.

#define RTP_STUN_FREQ   1000000

Definition at line 65 of file switch_rtp.c.

Referenced by ice_out().

#define rtp_type (   rtp_session)    rtp_session->flags[SWITCH_RTP_FLAG_VIDEO] ? "video" : "audio"
#define WARN_SRTP_ERRS   10

Definition at line 71 of file switch_rtp.c.

Referenced by read_rtp_packet().

#define WRITE_DEC (   rtp_session)    switch_mutex_unlock(rtp_session->write_mutex); rtp_session->writing--
#define WRITE_INC (   rtp_session)    switch_mutex_lock(rtp_session->write_mutex); rtp_session->writing++
#define ZRTP_MAGIC_COOKIE   0x5a525450

Definition at line 74 of file switch_rtp.c.

Referenced by read_rtp_packet().

Typedef Documentation

typedef int(* dtls_state_handler_t)(switch_rtp_t *, switch_dtls_t *)

Definition at line 283 of file switch_rtp.c.

typedef srtp_hdr_t rtp_hdr_t

Definition at line 86 of file switch_rtp.c.

typedef struct switch_dtls_s switch_dtls_t

Enumeration Type Documentation

Enumerator
RESULT_CONTINUE 
RESULT_GOTO_END 
RESULT_GOTO_RECVFROM 
RESULT_GOTO_TIMERCHECK 

Definition at line 503 of file switch_rtp.c.

Enumerator
VAD_FIRE_TALK 
VAD_FIRE_NOT_TALK 

Definition at line 185 of file switch_rtp.c.

185  {
186  VAD_FIRE_TALK = (1 << 0),
187  VAD_FIRE_NOT_TALK = (1 << 1)
vad_talk_mask_t
Definition: switch_rtp.c:185

Function Documentation

void burstr_calculate ( int  loss[],
int  received,
double *  burstr,
double *  lossr 
)

Definition at line 1570 of file switch_rtp.c.

References switch_rtcp_report_block::lost, and LOST_BURST_ANALYZE.

Referenced by check_jitter().

1571 {
1572  int lost = 0;
1573  int bursts = 0;
1574  int i;
1575 
1576  for ( i = 0; i < LOST_BURST_ANALYZE; i++ ) {
1577  lost += i * loss[i];
1578  bursts += loss[i];
1579  }
1580  if (received > 0 && bursts > 0) {
1581  *burstr = (double)((double)lost / (double)bursts) / (double)(1.0 / ( 1.0 - (double)lost / (double)received ));
1582  if (*burstr < 0) {
1583  *burstr = - *burstr;
1584  }
1585  } else {
1586  *burstr = 0;
1587  }
1588  if (received > 0) {
1589  *lossr = (double)((double)lost / (double)received);
1590  } else {
1591  *lossr = 0;
1592  }
1593 }
#define LOST_BURST_ANALYZE
Definition: switch_types.h:242
static void calc_bw_exp ( uint32_t  bps,
uint8_t  bits,
rtcp_tmmbx_t tmmbx 
)
static

Definition at line 1920 of file switch_rtp.c.

References rtcp_tmmbx_t::parts, and switch_assert.

Referenced by check_rtcp_and_ice().

1921 {
1922  uint32_t mantissa_max, i = 0;
1923  uint8_t exp = 0;
1924  uint32_t mantissa = 0;
1925  uint16_t overhead = 60;
1926 
1927  switch_assert(bits<=32);
1928 
1929  mantissa_max = (1 << bits) - 1;
1930 
1931  for (i = 0; i < 32; ++i) {
1932  if (bps <= (mantissa_max << i)) {
1933  exp = i;
1934  break;
1935  }
1936  }
1937 
1938  mantissa = (bps >> exp);
1939 
1940  tmmbx->parts[0] = (uint8_t) ((exp << 2) + ((mantissa >> 15) & 0x03));
1941  tmmbx->parts[1] = (uint8_t) (mantissa >> 7);
1942  tmmbx->parts[2] = (uint8_t) ((mantissa >> 1) + ((overhead >> 8) & 0x01));
1943  tmmbx->parts[3] = (uint8_t) (overhead);
1944 }
uint8_t parts[4]
Definition: switch_rtp.c:140
#define switch_assert(expr)
static void check_jitter ( switch_rtp_t rtp_session)
static

Definition at line 1604 of file switch_rtp.c.

References switch_rtp::bad_stream, burstr_calculate(), switch_rtp_numbers_t::burstrate, switch_rtp::clean_stream, do_mos(), switch_rtp::dtmf_data, switch_rtp_numbers_t::error_log, switch_rtp::flags, switch_rtp_numbers_t::flaws, switch_rtp_rfc2833_data::in_digit_ts, switch_rtp_stats_t::inbound, IPDV_THRESHOLD, switch_rtp_numbers_t::jitter_add, switch_rtp_numbers_t::jitter_addsq, switch_rtp::jitter_lead, JITTER_LEAD_FRAMES, switch_rtp_numbers_t::jitter_n, switch_rtp_numbers_t::last_loss, switch_rtp_numbers_t::last_proc_time, switch_rtp_numbers_t::last_processed_seq, switch_rtp::last_rtp_hdr, switch_rtp_numbers_t::loss, switch_rtp_numbers_t::lossrate, switch_rtcp_report_block::lost, LOST_BURST_CAPTURE, switch_rtp_numbers_t::max_variance, switch_rtp_numbers_t::mean_interval, switch_rtp_numbers_t::min_variance, error_period::next, switch_rtp::next_stat_check_time, switch_rtp::old_mean, switch_rtp::one_second, switch_rtp::recovering_stream, switch_rtp_numbers_t::recved, reset_jitter_seq(), rtp_session_name, rtp_type, switch_rtp::session, error_period::start, switch_rtp::stats, error_period::stop, SWITCH_CHANNEL_LOG, SWITCH_CHANNEL_SESSION_LOG, switch_core_session_alloc, SWITCH_FALSE, SWITCH_LOG_DEBUG1, SWITCH_LOG_DEBUG3, switch_log_printf(), switch_micro_time_now(), SWITCH_RTP_FLAG_DTMF_ON, SWITCH_RTP_FLAG_PAUSE, SWITCH_TRUE, and switch_rtp_numbers_t::variance.

Referenced by read_rtp_packet().

1605 {
1606  switch_time_t current_time;
1607  int64_t diff_time = 0, cur_diff = 0;
1608  int seq;
1609 
1610  current_time = switch_micro_time_now() / 1000;
1611 
1612  if (rtp_session->flags[SWITCH_RTP_FLAG_PAUSE] || rtp_session->flags[SWITCH_RTP_FLAG_DTMF_ON] || rtp_session->dtmf_data.in_digit_ts) {
1613  reset_jitter_seq(rtp_session);
1614  return;
1615  }
1616 
1617  if (++rtp_session->jitter_lead < JITTER_LEAD_FRAMES || !rtp_session->stats.inbound.last_proc_time) {
1618  rtp_session->stats.inbound.last_proc_time = current_time;
1619  return;
1620  }
1621 
1622  diff_time = (current_time - rtp_session->stats.inbound.last_proc_time);
1623  seq = (int)(uint16_t) ntohs((uint16_t) rtp_session->last_rtp_hdr.seq);
1624 
1625  /* Burst and Packet Loss */
1626  rtp_session->stats.inbound.recved++;
1627 
1628  if (rtp_session->stats.inbound.last_processed_seq > 0 && seq > (int)(rtp_session->stats.inbound.last_processed_seq + 1)) {
1629  int lost = (seq - rtp_session->stats.inbound.last_processed_seq - 1);
1630 
1631  switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(rtp_session->session), SWITCH_LOG_DEBUG1, "%s Got: %s seq %d but expected: %d lost: %d\n",
1632  rtp_session_name(rtp_session),
1633  rtp_type(rtp_session),
1634  seq,
1635  (rtp_session->stats.inbound.last_processed_seq + 1), lost);
1636  rtp_session->stats.inbound.last_loss++;
1637 
1638  if (rtp_session->stats.inbound.last_loss > 0 && rtp_session->stats.inbound.last_loss < LOST_BURST_CAPTURE) {
1639  rtp_session->stats.inbound.loss[rtp_session->stats.inbound.last_loss] += lost;
1640  }
1641 
1642  rtp_session->bad_stream++;
1643  rtp_session->stats.inbound.flaws += lost;
1644  } else {
1645  rtp_session->stats.inbound.last_loss = 0;
1646  }
1647 
1648  rtp_session->stats.inbound.last_processed_seq = seq;
1649 
1650  /* Burst and Packet Loss */
1651 
1652  if (current_time > rtp_session->next_stat_check_time) {
1653  rtp_session->next_stat_check_time = current_time + 5000;
1654  burstr_calculate(rtp_session->stats.inbound.loss, rtp_session->stats.inbound.recved,
1655  &(rtp_session->stats.inbound.burstrate), &(rtp_session->stats.inbound.lossrate));
1656  do_mos(rtp_session, SWITCH_TRUE);
1657  } else {
1658  do_mos(rtp_session, SWITCH_FALSE);
1659  }
1660 
1661  if (rtp_session->stats.inbound.last_loss || rtp_session->bad_stream) {
1662  if (rtp_session->session && (!rtp_session->stats.inbound.error_log || rtp_session->stats.inbound.error_log->stop)) {
1663  struct error_period *error = switch_core_session_alloc(rtp_session->session, sizeof(*error));
1664  error->start = switch_micro_time_now();
1665  error->next = rtp_session->stats.inbound.error_log;
1666  rtp_session->stats.inbound.error_log = error;
1667  }
1668 
1669  if (!rtp_session->stats.inbound.last_loss) {
1670  if (++rtp_session->recovering_stream > (rtp_session->one_second * 3)) {
1671  if (rtp_session->session && rtp_session->stats.inbound.error_log) {
1672  rtp_session->stats.inbound.error_log->stop = switch_micro_time_now();
1673  }
1674 
1675  rtp_session->bad_stream = 0;
1676  }
1677  } else {
1678  rtp_session->recovering_stream = 0;
1679  rtp_session->bad_stream++;
1680  }
1681  } else {
1682  rtp_session->recovering_stream = 0;
1683  rtp_session->clean_stream++;
1684  }
1685 
1686 
1687  if ( diff_time < 0 ) {
1688  diff_time = -diff_time;
1689  }
1690 
1691  rtp_session->stats.inbound.jitter_n++;
1692  rtp_session->stats.inbound.jitter_add += diff_time;
1693 
1694  cur_diff = (int64_t)(diff_time - rtp_session->stats.inbound.mean_interval);
1695 
1696  rtp_session->stats.inbound.jitter_addsq += (cur_diff * cur_diff);
1697  rtp_session->stats.inbound.last_proc_time = current_time;
1698 
1699  if (rtp_session->stats.inbound.jitter_n > 0) {
1700  double ipdv;
1701 
1702  rtp_session->stats.inbound.mean_interval = (double)rtp_session->stats.inbound.jitter_add / (double)rtp_session->stats.inbound.jitter_n;
1703 
1704  if (!rtp_session->old_mean) {
1705  rtp_session->old_mean = rtp_session->stats.inbound.mean_interval;
1706  }
1707 
1708  rtp_session->stats.inbound.variance = (double)rtp_session->stats.inbound.jitter_addsq / (double)rtp_session->stats.inbound.jitter_n;
1709 
1710  //printf("CHECK %d +%ld +%ld %f %f\n", rtp_session->timer.samplecount, diff_time, (diff_time * diff_time), rtp_session->stats.inbound.mean_interval, rtp_session->stats.inbound.variance);
1711 
1712  ipdv = rtp_session->old_mean - rtp_session->stats.inbound.mean_interval;
1713 
1714  if ( ipdv > IPDV_THRESHOLD ) { /* It shows Increasing Delays */
1715  switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG3, "Calculated Instantaneous Packet Delay Variation: %s packet %lf\n",
1716  rtp_type(rtp_session), ipdv);
1717  }
1718 
1719  if ( rtp_session->stats.inbound.variance < rtp_session->stats.inbound.min_variance || rtp_session->stats.inbound.min_variance == 0 ) {
1720  rtp_session->stats.inbound.min_variance = rtp_session->stats.inbound.variance;
1721  }
1722 
1723  if ( rtp_session->stats.inbound.variance > rtp_session->stats.inbound.max_variance ) {
1724  rtp_session->stats.inbound.max_variance = rtp_session->stats.inbound.variance;
1725  }
1726 
1727  rtp_session->old_mean = rtp_session->stats.inbound.mean_interval;
1728  }
1729 }
switch_time_t switch_micro_time_now(void)
Get the current epoch time in microseconds.
Definition: switch_time.c:310
switch_size_t flaws
Definition: switch_types.h:657
int loss[LOST_BURST_CAPTURE]
Definition: switch_types.h:653
#define SWITCH_CHANNEL_SESSION_LOG(x)
switch_rtp_numbers_t inbound
Definition: switch_types.h:690
#define SWITCH_CHANNEL_LOG
#define IPDV_THRESHOLD
Definition: switch_types.h:240
struct error_period * next
Definition: switch_types.h:622
#define rtp_session_name(_rtp_session)
Definition: switch_rtp.c:79
struct switch_rtp_rfc2833_data dtmf_data
Definition: switch_rtp.c:403
#define rtp_type(rtp_session)
Definition: switch_rtp.c:513
#define LOST_BURST_CAPTURE
Definition: switch_types.h:244
int64_t switch_time_t
Definition: switch_apr.h:188
int64_t stop
Definition: switch_types.h:621
#define JITTER_LEAD_FRAMES
Definition: switch_rtp.c:59
uint32_t flags[SWITCH_RTP_FLAG_INVALID]
Definition: switch_rtp.c:372
uint32_t clean_stream
Definition: switch_rtp.c:429
uint32_t recovering_stream
Definition: switch_rtp.c:431
int64_t start
Definition: switch_types.h:620
switch_rtp_stats_t stats
Definition: switch_rtp.c:428
struct error_period * error_log
Definition: switch_types.h:661
switch_time_t next_stat_check_time
Definition: switch_rtp.c:396
static void reset_jitter_seq(switch_rtp_t *rtp_session)
Definition: switch_rtp.c:1595
switch_core_session_t * session
Definition: switch_rtp.c:446
void burstr_calculate(int loss[], int received, double *burstr, double *lossr)
Definition: switch_rtp.c:1570
#define switch_core_session_alloc(_session, _memory)
Allocate memory from a session's pool.
Definition: switch_core.h:694
uint32_t jitter_lead
Definition: switch_rtp.c:394
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.
double old_mean
Definition: switch_rtp.c:395
uint32_t bad_stream
Definition: switch_rtp.c:430
rtp_hdr_t last_rtp_hdr
Definition: switch_rtp.c:351
uint32_t one_second
Definition: switch_rtp.c:392
static void do_mos(switch_rtp_t *rtp_session, int force)
Definition: switch_rtp.c:1521
static int check_recv_payload ( switch_rtp_t rtp_session)
static

Definition at line 5085 of file switch_rtp.c.

References payload_map_s::allocated, switch_rtp::flag_mutex, switch_rtp::last_rtp_hdr, payload_map_s::negotiated, payload_map_s::next, switch_rtp::pmaps, payload_map_s::pt, switch_mutex_lock(), and switch_mutex_unlock().

Referenced by read_rtp_packet(), and rtp_common_read().

5086 {
5087  int ok = 1;
5088 
5089  if (rtp_session->pmaps && *rtp_session->pmaps) {
5090  payload_map_t *pmap;
5091  ok = 0;
5092 
5093  switch_mutex_lock(rtp_session->flag_mutex);
5094 
5095  for (pmap = *rtp_session->pmaps; pmap && pmap->allocated; pmap = pmap->next) {
5096  if (!pmap->negotiated) {
5097  continue;
5098  }
5099 
5100  if (rtp_session->last_rtp_hdr.pt == pmap->pt) {
5101  ok = 1;
5102  }
5103  }
5104  switch_mutex_unlock(rtp_session->flag_mutex);
5105  }
5106 
5107  return ok;
5108 }
uint8_t allocated
switch_mutex_t * flag_mutex
Definition: switch_rtp.c:407
struct payload_map_s * next
switch_status_t switch_mutex_unlock(switch_mutex_t *lock)
Definition: switch_apr.c:290
switch_status_t switch_mutex_lock(switch_mutex_t *lock)
Definition: switch_apr.c:285
uint8_t negotiated
switch_payload_t pt
payload_map_t ** pmaps
Definition: switch_rtp.c:447
rtp_hdr_t last_rtp_hdr
Definition: switch_rtp.c:351
static int check_rtcp_and_ice ( switch_rtp_t rtp_session)
static

Definition at line 1956 of file switch_rtp.c.

References _RTCP_PSFB_FIR, _RTCP_PSFB_PLI, _RTCP_PT_PSFB, _RTCP_PT_RR, _RTCP_PT_RTPFB, _RTCP_PT_SDES, _RTCP_PT_SR, _RTCP_RTPFB_NACK, _RTCP_RTPFB_TMMBN, _RTCP_RTPFB_TMMBR, _RTCP_SDES_CNAME, _RTCP_SDES_NOTE, rtcp_msg_t::body, calc_bw_exp(), switch_rtp::cn, switch_rtp::cng_pt, switch_rtcp_hdr_s::count, switch_rtcp_numbers_t::cycle, switch_rtp::fir_count, switch_rtp::fir_seq, switch_rtp::flags, switch_rtcp_ext_hdr_t::fmt, get_next_write_ts(), rtp_msg_t::header, rtcp_msg_t::header, switch_rtcp_numbers_t::high_ext_seq_recv, switch_rtp::ice, ice_out(), switch_rtp_ice_t::ice_user, switch_rtp_stats_t::inbound, INVALID_PT, switch_rtcp_numbers_t::last_rpt_cycle, switch_rtcp_numbers_t::last_rpt_ext_seq, switch_rtcp_numbers_t::last_rpt_ts, switch_rtp::last_write_samplecount, switch_rtcp_sdes_unit_s::length, switch_rtcp_ext_hdr_t::length, switch_rtcp_hdr_s::length, MAX_NACK, switch_rtcp_ext_hdr_t::p, switch_rtcp_hdr_s::p, switch_rtp_numbers_t::period_packet_count, switch_rtcp_numbers_t::period_pkt_count, switch_rtp::pli_count, switch_rtcp_ext_hdr_t::pt, rtcp_fir_t::r1, rtcp_fir_t::r2, rtcp_fir_t::r3, switch_rtcp_ext_hdr_t::recv_ssrc, switch_rtp::remote_ssrc, switch_rtcp_sender_report::report_block, switch_rtcp_receiver_report::report_block, switch_rtp_ice_t::rready, switch_rtp_stats_t::rtcp, rtcp_generate_report_block(), rtcp_generate_sender_info(), switch_rtp::rtcp_ice, switch_rtp::rtcp_interval, switch_rtp::rtcp_last_sent, switch_rtp::rtcp_remote_addr, switch_rtp::rtcp_send_msg, switch_rtp::rtcp_sent_packets, switch_rtp::rtcp_sock_output, rtp_session_name, rtp_type, switch_timer::samplecount, switch_rtp::samples_per_interval, switch_rtp::send_ctx, switch_rtp::send_msg, switch_rtcp_ext_hdr_t::send_ssrc, switch_rtcp_sender_report::sender_info, switch_rtcp_numbers_t::sent_pkt_count, rtcp_fir_t::seq, switch_rtp::session, SFF_NONE, switch_rtp::srtp_idx_rtcp, rtcp_fir_t::ssrc, rtcp_tmmbx_t::ssrc, switch_rtp::ssrc, switch_rtcp_sender_report::ssrc, switch_rtcp_receiver_report::ssrc, switch_rtp::stats, SWITCH_CHANNEL_LOG, SWITCH_CHANNEL_SESSION_LOG, switch_get_addr(), switch_jb_pop_nack(), SWITCH_LOG_CRIT, SWITCH_LOG_DEBUG, SWITCH_LOG_DEBUG1, SWITCH_LOG_ERROR, switch_log_printf(), switch_micro_time_now(), SWITCH_RTP_FLAG_AUTO_CNG, SWITCH_RTP_FLAG_ENABLE_RTCP, SWITCH_RTP_FLAG_NACK, SWITCH_RTP_FLAG_PROXY_MEDIA, SWITCH_RTP_FLAG_RTCP_MUX, SWITCH_RTP_FLAG_RTCP_PASSTHRU, SWITCH_RTP_FLAG_SECURE_SEND, SWITCH_RTP_FLAG_UDPTL, SWITCH_RTP_FLAG_USE_TIMER, SWITCH_RTP_FLAG_VIDEO, switch_rtp_test_flag(), switch_rtp_write_manual(), switch_sockaddr_get_port(), switch_socket_sendto(), SWITCH_STATUS_GENERR, SWITCH_STATUS_SUCCESS, switch_rtp::timer, switch_rtp::tmmbn, switch_rtp::tmmbr, switch_rtp::ts, switch_rtcp_sdes_unit_s::type, switch_rtcp_hdr_s::type, using_ice(), switch_rtcp_sdes_unit_s::value, switch_rtp::vb, switch_rtcp_ext_hdr_t::version, and switch_rtcp_hdr_s::version.

Referenced by read_rtp_packet(), rtp_common_read(), and switch_rtp_ping().

1957 {
1958  int ret = 0;
1959  int rtcp_ok = 0, rtcp_fb = 0;
1961  int rate = 0, nack_ttl = 0;
1962  uint32_t cur_nack[MAX_NACK] = { 0 };
1963 
1964  if (!rtp_session->flags[SWITCH_RTP_FLAG_UDPTL] &&
1965  rtp_session->flags[SWITCH_RTP_FLAG_AUTO_CNG] &&
1966  rtp_session->send_msg.header.ts &&
1967  rtp_session->cng_pt != INVALID_PT &&
1968  (rtp_session->timer.samplecount - rtp_session->last_write_samplecount >= rtp_session->samples_per_interval * 60)) {
1969  uint8_t data[10] = { 0 };
1970  switch_frame_flag_t frame_flags = SFF_NONE;
1971  data[0] = 65;
1972  rtp_session->cn++;
1973 
1974  get_next_write_ts(rtp_session, 0);
1975  rtp_session->send_msg.header.ts = htonl(rtp_session->ts);
1976 
1977  switch_rtp_write_manual(rtp_session, (void *) data, 2, 0, rtp_session->cng_pt, ntohl(rtp_session->send_msg.header.ts), &frame_flags);
1978 
1979  if (switch_rtp_test_flag(rtp_session, SWITCH_RTP_FLAG_USE_TIMER)) {
1980  rtp_session->last_write_samplecount = rtp_session->timer.samplecount;
1981  }
1982  }
1983 
1984  rate = rtp_session->rtcp_interval;
1985 
1986  if (rtp_session->flags[SWITCH_RTP_FLAG_NACK] && rtp_session->vb) {
1987  int n;
1988  for (n = 0; n < MAX_NACK; n++) {
1989  uint32_t nack = switch_jb_pop_nack(rtp_session->vb);
1990 
1991  if (!nack) break;
1992 
1993  cur_nack[nack_ttl++] = nack;
1994  }
1995  }
1996 
1997 
1998 
1999  if (rtp_session->rtcp_sent_packets < 4) {
2000  rate = 4000;
2001  } else {
2002  if (rtp_session->pli_count || rtp_session->fir_count || nack_ttl || rtp_session->tmmbr || rtp_session->tmmbn) {
2003  //switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(rtp_session->session), SWITCH_LOG_ERROR, "MARK BW/FIR ETC %d %d\n", rtp_session->pli_count, rtp_session->fir_count);
2004  rtcp_ok = 1;
2005  rtcp_fb = 1;
2006  }
2007  }
2008 
2009  //switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(rtp_session->session), SWITCH_LOG_ERROR, "TIME CHECK %d > %d\n", (int)((now - rtp_session->rtcp_last_sent) / 1000), rate);
2010 
2011  if (!rtcp_ok && (!rtp_session->rtcp_last_sent || (int)((now - rtp_session->rtcp_last_sent) / 1000) > rate)) {
2012  //switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(rtp_session->session), SWITCH_LOG_ERROR, "TIME UP\n");
2013  rtcp_ok = 1;
2014  }
2015 
2016  if (rtcp_ok && using_ice(rtp_session)) {
2017  if (rtp_session->flags[SWITCH_RTP_FLAG_RTCP_MUX]) {
2018  if (!rtp_session->ice.rready) {
2019  rtcp_ok = 0;
2020  }
2021  } else {
2022  if (!rtp_session->rtcp_ice.rready) {
2023  rtcp_ok = 0;
2024  }
2025  }
2026  }
2027 
2028  //switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(rtp_session->session), SWITCH_LOG_ERROR, "WTF %d %d %d %d\n", rate, rtp_session->rtcp_sent_packets, rtcp_ok, nack_ttl);
2029 
2030  if (rtp_session->rtcp_sock_output && rtp_session->flags[SWITCH_RTP_FLAG_ENABLE_RTCP] && !rtp_session->flags[SWITCH_RTP_FLAG_RTCP_PASSTHRU] && rtcp_ok) {
2031  switch_rtcp_numbers_t * stats = &rtp_session->stats.rtcp;
2032  struct switch_rtcp_receiver_report *rr;
2033  struct switch_rtcp_sender_report *sr;
2034  struct switch_rtcp_report_block *rtcp_report_block;
2035  switch_size_t rtcp_bytes = sizeof(struct switch_rtcp_hdr_s)+sizeof(uint32_t); /* add size of the packet header and the ssrc */
2036  switch_rtcp_hdr_t *sdes;
2037  uint8_t *p;
2038  switch_size_t sdes_bytes = sizeof(struct switch_rtcp_hdr_s);
2039  uint32_t *ssrc;
2041 
2042  if (!rtcp_fb) {
2043  rtp_session->rtcp_last_sent = now;
2044  rtp_session->rtcp_sent_packets++;
2045  }
2046 
2047  rtp_session->rtcp_send_msg.header.version = 2;
2048  rtp_session->rtcp_send_msg.header.p = 0;
2049  rtp_session->rtcp_send_msg.header.count = 1;
2050 
2051 
2052  if (!rtp_session->stats.rtcp.sent_pkt_count) {
2053  rtp_session->rtcp_send_msg.header.type = _RTCP_PT_RR; /* Receiver report */
2054  rr=(struct switch_rtcp_receiver_report*) rtp_session->rtcp_send_msg.body;
2055  rr->ssrc = htonl(rtp_session->ssrc);
2056  rtcp_report_block = &rr->report_block;
2057  rtcp_bytes += sizeof(struct switch_rtcp_report_block);
2058  } else {
2059  struct switch_rtcp_sender_info *rtcp_sender_info;
2060  rtp_session->rtcp_send_msg.header.type = _RTCP_PT_SR; /* Sender report */
2061  sr = (struct switch_rtcp_sender_report*) rtp_session->rtcp_send_msg.body;
2062  sr->ssrc = htonl(rtp_session->ssrc);
2063  rtcp_sender_info = &sr->sender_info;
2064  rtcp_generate_sender_info(rtp_session, rtcp_sender_info);
2065  rtcp_report_block = &sr->report_block;
2066  rtcp_bytes += sizeof(struct switch_rtcp_sender_info) + sizeof(struct switch_rtcp_report_block);
2067  }
2068  rtcp_generate_report_block(rtp_session, rtcp_report_block);
2069 
2070  rtp_session->rtcp_send_msg.header.length = htons((uint16_t)(rtcp_bytes / 4) - 1);
2071 
2072  if (rtp_session->flags[SWITCH_RTP_FLAG_VIDEO]) {
2073  //if (rtp_session->remote_ssrc == 0) {
2074  // rtp_session->remote_ssrc = rtp_session->stats.rtcp.peer_ssrc;
2075  //}
2076 
2077  //if (rtp_session->remote_ssrc == 0) {
2078  // rtp_session->remote_ssrc = ntohl(rtp_session->last_rtp_hdr.ssrc);
2079  //}
2080 
2081 
2082  if (rtp_session->pli_count) {
2083  switch_rtcp_ext_hdr_t *ext_hdr;
2084 
2085  p = (uint8_t *) (&rtp_session->rtcp_send_msg) + rtcp_bytes;
2086  ext_hdr = (switch_rtcp_ext_hdr_t *) p;
2087 
2088  ext_hdr->version = 2;
2089  ext_hdr->p = 0;
2090  ext_hdr->fmt = _RTCP_PSFB_PLI;
2091  ext_hdr->pt = _RTCP_PT_PSFB;
2092 
2093  ext_hdr->send_ssrc = htonl(rtp_session->ssrc);
2094  ext_hdr->recv_ssrc = htonl(rtp_session->remote_ssrc);
2095 
2096  switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(rtp_session->session), SWITCH_LOG_DEBUG1, "Sending RTCP PLI\n");
2097 
2098  ext_hdr->length = htons((uint8_t)(sizeof(switch_rtcp_ext_hdr_t) / 4) - 1);
2099  rtcp_bytes += sizeof(switch_rtcp_ext_hdr_t);
2100  rtp_session->pli_count = 0;
2101  }
2102 
2103  if (rtp_session->flags[SWITCH_RTP_FLAG_NACK] && nack_ttl > 0) {
2104  int n = 0;
2105 
2106  for (n = 0; n < nack_ttl; n++) {
2107  switch_rtcp_ext_hdr_t *ext_hdr;
2108  uint32_t *nack;
2109  p = (uint8_t *) (&rtp_session->rtcp_send_msg) + rtcp_bytes;
2110  ext_hdr = (switch_rtcp_ext_hdr_t *) p;
2111 
2112  ext_hdr->version = 2;
2113  ext_hdr->p = 0;
2114  ext_hdr->fmt = _RTCP_RTPFB_NACK;
2115  ext_hdr->pt = _RTCP_PT_RTPFB;
2116  ext_hdr->send_ssrc = htonl(rtp_session->ssrc);
2117  ext_hdr->recv_ssrc = htonl(rtp_session->remote_ssrc);
2118  ext_hdr->length = htons(3);
2119  p += sizeof(switch_rtcp_ext_hdr_t);
2120  nack = (uint32_t *) p;
2121  *nack = cur_nack[n];
2122 
2123  switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(rtp_session->session), SWITCH_LOG_DEBUG1, "Sending RTCP NACK %u\n",
2124  ntohs(*nack & 0xFFFF));
2125 
2126  rtcp_bytes += sizeof(switch_rtcp_ext_hdr_t) + sizeof(cur_nack[n]);
2127  cur_nack[n] = 0;
2128  }
2129 
2130  nack_ttl = 0;
2131  }
2132 
2133  if (rtp_session->fir_count) {
2134  switch_rtcp_ext_hdr_t *ext_hdr;
2135  rtcp_fir_t *fir;
2136 
2137  p = (uint8_t *) (&rtp_session->rtcp_send_msg) + rtcp_bytes;
2138  ext_hdr = (switch_rtcp_ext_hdr_t *) p;
2139 
2140  p += sizeof(switch_rtcp_ext_hdr_t);
2141  fir = (rtcp_fir_t *) p;
2142 
2143  ext_hdr->version = 2;
2144  ext_hdr->p = 0;
2145  ext_hdr->fmt = _RTCP_PSFB_FIR;
2146  ext_hdr->pt = _RTCP_PT_PSFB;
2147 
2148  ext_hdr->send_ssrc = htonl(rtp_session->ssrc);
2149  ext_hdr->recv_ssrc = 0;
2150 
2151  fir->ssrc = htonl(rtp_session->remote_ssrc);
2152  fir->seq = rtp_session->fir_seq;
2153  fir->r1 = fir->r2 = fir->r3 = 0;
2154 
2155  switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(rtp_session->session), SWITCH_LOG_DEBUG1, "Sending RTCP FIR SEQ %d\n", rtp_session->fir_seq);
2156 
2157  rtp_session->fir_seq++;
2158 
2159  ext_hdr->length = htons((uint8_t)((sizeof(switch_rtcp_ext_hdr_t) + sizeof(rtcp_fir_t)) / 4) - 1);
2160  rtcp_bytes += sizeof(switch_rtcp_ext_hdr_t) + sizeof(rtcp_fir_t);
2161  rtp_session->fir_count = 0;
2162  }
2163 
2164  //if (!rtp_session->tmmbr && rtp_session->cur_tmmbr) {
2165  // rtp_session->tmmbr = rtp_session->cur_tmmbr;
2166  //}
2167 
2168  while (rtp_session->tmmbr || rtp_session->tmmbn) {
2169  switch_rtcp_ext_hdr_t *ext_hdr;
2170  rtcp_tmmbx_t *tmmbx;
2171  uint32_t bps = 0;
2172  p = (uint8_t *) (&rtp_session->rtcp_send_msg) + rtcp_bytes;
2173  ext_hdr = (switch_rtcp_ext_hdr_t *) p;
2174 
2175  p += sizeof(switch_rtcp_ext_hdr_t);
2176  tmmbx = (rtcp_tmmbx_t *) p;
2177 
2178  ext_hdr->version = 2;
2179  ext_hdr->p = 0;
2180  ext_hdr->pt = _RTCP_PT_RTPFB;
2181  ext_hdr->send_ssrc = htonl(rtp_session->ssrc);
2182  ext_hdr->recv_ssrc = 0;
2183 
2184  if (rtp_session->tmmbr) {
2185  switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(rtp_session->session), SWITCH_LOG_DEBUG1, "Sending RTCP TMMBR %u\n", rtp_session->tmmbr);
2186  ext_hdr->fmt = _RTCP_RTPFB_TMMBR;
2187  bps = rtp_session->tmmbr;
2188  rtp_session->tmmbr = 0;
2189  } else {
2190  switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(rtp_session->session), SWITCH_LOG_DEBUG1, "Sending RTCP TMMBN %u\n", rtp_session->tmmbr);
2191  ext_hdr->fmt = _RTCP_RTPFB_TMMBN;
2192  bps = rtp_session->tmmbn;
2193  rtp_session->tmmbn = 0;
2194  }
2195 
2196  tmmbx->ssrc = htonl(rtp_session->remote_ssrc);
2197  calc_bw_exp(bps, 17, tmmbx);
2198 
2199  ext_hdr->length = htons((uint8_t)((sizeof(switch_rtcp_ext_hdr_t) + sizeof(rtcp_tmmbx_t)) / 4) - 1);
2200  rtcp_bytes += sizeof(switch_rtcp_ext_hdr_t) + sizeof(rtcp_tmmbx_t);
2201  }
2202 
2203  }
2204 
2205  //SDES + CNAME
2206  p = (uint8_t *) (&rtp_session->rtcp_send_msg) + rtcp_bytes;
2207  sdes = (switch_rtcp_hdr_t *) p;
2208  sdes->version = 2;
2209  sdes->type = _RTCP_PT_SDES;
2210  sdes->count = 1;
2211  sdes->p = 0;
2212  p = (uint8_t *) (sdes) + sdes_bytes;
2213  ssrc = (uint32_t *) p;
2214  *ssrc = htonl(rtp_session->ssrc);
2215  sdes_bytes += sizeof(uint32_t);
2216 
2217 
2218  p = (uint8_t *) (sdes) + sdes_bytes;
2219  unit = (switch_rtcp_sdes_unit_t *) p;
2220  unit->type = _RTCP_SDES_CNAME;
2221  snprintf((char *)unit->value, 80, "%x", rtp_session->ssrc);
2222  unit->length = strlen((char *)unit->value);
2223  sdes_bytes += sizeof(switch_rtcp_sdes_unit_t) + unit->length;
2224 
2225 
2226  p += sizeof(switch_rtcp_sdes_unit_t) + unit->length;
2227  unit = (switch_rtcp_sdes_unit_t *) p;
2228  unit->type = _RTCP_SDES_NOTE;
2229  snprintf((char *)unit->value, 80, "FreeSWITCH.org -- Come to ClueCon.com");
2230  unit->length = strlen((char *)unit->value);
2231  sdes_bytes += sizeof(switch_rtcp_sdes_unit_t) + unit->length;
2232 
2233  sdes_bytes ++;//END
2234 
2235  sdes_bytes += 4 - (sdes_bytes % 4);
2236 
2237  sdes->length = htons((uint16_t)(sdes_bytes / 4) - 1);
2238  rtcp_bytes += sdes_bytes;
2239 
2240  /* Prepare next report */
2241 
2242  stats->last_rpt_cycle = stats->cycle;
2243  stats->last_rpt_ext_seq = stats->high_ext_seq_recv;
2244  stats->last_rpt_ts = rtp_session->timer.samplecount;
2245  stats->period_pkt_count = 0;
2246  stats->sent_pkt_count = 0;
2247 
2248 
2249 
2250 #ifdef ENABLE_SRTP
2251  if (rtp_session->flags[SWITCH_RTP_FLAG_SECURE_SEND]) {
2252  int sbytes = (int) rtcp_bytes;
2253  int stat = srtp_protect_rtcp(rtp_session->send_ctx[rtp_session->srtp_idx_rtcp], &rtp_session->rtcp_send_msg.header, &sbytes);
2254 
2255  if (stat) {
2256  switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(rtp_session->session), SWITCH_LOG_ERROR, "Error: SRTP RTCP protection failed with code %d\n", stat);
2257  goto end;
2258  } else {
2259  rtcp_bytes = sbytes;
2260  }
2261 
2262  }
2263 #endif
2264 
2265 #ifdef ENABLE_ZRTP
2266  /* ZRTP Send */
2267  if (zrtp_on && !rtp_session->flags[SWITCH_RTP_FLAG_PROXY_MEDIA]) {
2268  unsigned int sbytes = (int) rtcp_bytes;
2269  zrtp_status_t stat = zrtp_status_fail;
2270 
2271  stat = zrtp_process_rtcp(rtp_session->zrtp_stream, (void *) &rtp_session->rtcp_send_msg, &sbytes);
2272 
2273  switch (stat) {
2274  case zrtp_status_ok:
2275  break;
2276  case zrtp_status_drop:
2277  switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Error: zRTP protection drop with code %d\n", stat);
2278  ret = (int)rtcp_bytes;
2279  goto end;
2280  break;
2281  case zrtp_status_fail:
2282  switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Error: zRTP protection fail with code %d\n", stat);
2283  break;
2284  default:
2285  break;
2286  }
2287 
2288  rtcp_bytes = sbytes;
2289  }
2290 #endif
2291  //#define DEBUG_EXTRA
2292 #ifdef DEBUG_EXTRA
2293  {
2294  const char *old_host;
2295  char bufb[50];
2296  old_host = switch_get_addr(bufb, sizeof(bufb), rtp_session->rtcp_remote_addr);
2297  switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(rtp_session->session), SWITCH_LOG_CRIT, "%s SEND %s RTCP %s:%d %ld\n",
2298  rtp_session_name(rtp_session),
2299  rtp_type(rtp_session),
2300  old_host,
2302  rtcp_bytes);
2303  }
2304 #endif
2305  if (switch_socket_sendto(rtp_session->rtcp_sock_output, rtp_session->rtcp_remote_addr, 0, (void *)&rtp_session->rtcp_send_msg, &rtcp_bytes ) != SWITCH_STATUS_SUCCESS) {
2306  switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(rtp_session->session), SWITCH_LOG_DEBUG,"RTCP packet not written\n");
2307  } else {
2308  rtp_session->stats.inbound.period_packet_count = 0;
2309  }
2310  }
2311 
2312  if (rtp_session->ice.ice_user) {
2313  if (ice_out(rtp_session, &rtp_session->ice) == SWITCH_STATUS_GENERR) {
2314  ret = -1;
2315  goto end;
2316  }
2317  }
2318 
2319  if (!rtp_session->flags[SWITCH_RTP_FLAG_RTCP_MUX]) {
2320  if (rtp_session->rtcp_ice.ice_user) {
2321  if (ice_out(rtp_session, &rtp_session->rtcp_ice) == SWITCH_STATUS_GENERR) {
2322  ret = -1;
2323  goto end;
2324  }
2325  }
2326  }
2327 
2328  end:
2329 
2330  return ret;
2331 }
switch_time_t rtcp_last_sent
Definition: switch_rtp.c:389
switch_time_t switch_micro_time_now(void)
Get the current epoch time in microseconds.
Definition: switch_time.c:310
static void rtcp_generate_report_block(switch_rtp_t *rtp_session, struct switch_rtcp_report_block *rtcp_report_block)
Definition: switch_rtp.c:1756
switch_size_t period_packet_count
Definition: switch_types.h:630
#define SWITCH_CHANNEL_SESSION_LOG(x)
uint16_t switch_sockaddr_get_port(switch_sockaddr_t *sa)
Definition: switch_apr.c:916
switch_rtp_numbers_t inbound
Definition: switch_types.h:690
#define SWITCH_CHANNEL_LOG
static void rtcp_generate_sender_info(switch_rtp_t *rtp_session, struct switch_rtcp_sender_info *sr)
Definition: switch_rtp.c:1731
struct switch_rtcp_report_block report_block
Definition: switch_rtp.c:500
uint8_t r1
Definition: switch_rtp.c:123
int srtp_idx_rtcp
Definition: switch_rtp.c:346
uint8_t r3
Definition: switch_rtp.c:125
uint8_t fir_seq
Definition: switch_rtp.c:318
#define rtp_session_name(_rtp_session)
Definition: switch_rtp.c:79
unsigned char type
Definition: switch_rtp.c:133
switch_rtcp_hdr_t header
Definition: switch_rtp.c:180
uint16_t pli_count
Definition: switch_rtp.c:320
#define rtp_type(rtp_session)
Definition: switch_rtp.c:513
switch_payload_t cng_pt
Definition: switch_rtp.c:406
static switch_status_t ice_out(switch_rtp_t *rtp_session, switch_rtp_ice_t *ice)
Definition: switch_rtp.c:771
srtp_ctx_t * send_ctx[2]
Definition: switch_rtp.c:335
int64_t switch_time_t
Definition: switch_apr.h:188
switch_rtcp_numbers_t rtcp
Definition: switch_types.h:692
uint32_t tmmbn
Definition: switch_rtp.c:323
struct switch_rtcp_sender_info sender_info
Definition: switch_rtp.c:494
struct switch_rtcp_sdes_unit_s switch_rtcp_sdes_unit_t
switch_status_t switch_socket_sendto(switch_socket_t *sock, switch_sockaddr_t *where, int32_t flags, const char *buf, switch_size_t *len)
Definition: switch_apr.c:773
uint32_t ts
Definition: switch_rtp.c:362
uint32_t flags[SWITCH_RTP_FLAG_INVALID]
Definition: switch_rtp.c:372
uint8_t seq
Definition: switch_rtp.c:122
uint16_t fir_count
Definition: switch_rtp.c:319
rtcp_msg_t rtcp_send_msg
Definition: switch_rtp.c:315
uintptr_t switch_size_t
switch_rtp_ice_t rtcp_ice
Definition: switch_rtp.c:378
switch_jb_t * vb
Definition: switch_rtp.c:415
uint8_t r2
Definition: switch_rtp.c:124
uint32_t switch_frame_flag_t
switch_rtp_stats_t stats
Definition: switch_rtp.c:428
switch_socket_t * rtcp_sock_output
Definition: switch_rtp.c:309
uint8_t cn
Definition: switch_rtp.c:413
int rtcp_interval
Definition: switch_rtp.c:435
static int using_ice(switch_rtp_t *rtp_session)
Definition: switch_rtp.c:1946
uint32_t samples_per_interval
Definition: switch_rtp.c:386
srtp_hdr_t header
Definition: switch_rtp.c:112
switch_timer_t timer
Definition: switch_rtp.c:411
switch_core_session_t * session
Definition: switch_rtp.c:446
uint32_t switch_jb_pop_nack(switch_jb_t *jb)
uint32_t remote_ssrc
Definition: switch_rtp.c:355
switch_rtp_ice_t ice
Definition: switch_rtp.c:377
struct switch_rtcp_report_block report_block
Definition: switch_rtp.c:495
unsigned char length
Definition: switch_rtp.c:134
uint32_t ssrc
Definition: switch_rtp.c:354
void switch_log_printf(_In_ switch_text_channel_t channel, _In_z_ const char *file, _In_z_ const char *func, _In_ int line, _In_opt_z_ const char *userdata, _In_ switch_log_level_t level, _In_z_ _Printf_format_string_ const char *fmt,...) PRINTF_FUNCTION(7
Write log data to the logging engine.
uint32_t switch_rtp_test_flag(switch_rtp_t *rtp_session, switch_rtp_flag_t flags)
Test an RTP Flag.
Definition: switch_rtp.c:4742
char body[SWITCH_RTCP_MAX_BUF_LEN]
Definition: switch_rtp.c:181
uint32_t last_write_samplecount
Definition: switch_rtp.c:366
const char * switch_get_addr(char *buf, switch_size_t len, switch_sockaddr_t *in)
Definition: switch_apr.c:894
rtp_msg_t send_msg
Definition: switch_rtp.c:314
static const switch_payload_t INVALID_PT
Definition: switch_rtp.c:75
switch_sockaddr_t * rtcp_remote_addr
Definition: switch_rtp.c:326
uint32_t ssrc
Definition: switch_rtp.c:121
#define MAX_NACK
Definition: switch_rtp.c:1955
static void calc_bw_exp(uint32_t bps, uint8_t bits, rtcp_tmmbx_t *tmmbx)
Definition: switch_rtp.c:1920
uint32_t ssrc
Definition: switch_rtp.c:139
static uint8_t get_next_write_ts(switch_rtp_t *rtp_session, uint32_t timestamp)
Definition: switch_rtp.c:1490
int rtcp_sent_packets
Definition: switch_rtp.c:436
uint32_t tmmbr
Definition: switch_rtp.c:322
int switch_rtp_write_manual(switch_rtp_t *rtp_session, void *data, uint32_t datalen, uint8_t m, switch_payload_t payload, uint32_t ts, switch_frame_flag_t *flags)
Write data with a specified payload and sequence number to a given RTP session.
Definition: switch_rtp.c:7955
static void do_2833 ( switch_rtp_t rtp_session)
static

Definition at line 4784 of file switch_rtp.c.

References switch_rtp::delay_samples, switch_dtmf_t::digit, switch_rtp::dtmf_data, switch_rtp_numbers_t::dtmf_packet_count, switch_rtp_rfc2833_data::dtmf_queue, switch_dtmf_t::duration, switch_rtp::flags, switch_rtp::interdigit_delay, switch_rtp::last_write_samplecount, switch_rtp::last_write_ts, switch_rtp::max_next_write_samplecount, memset(), switch_rtp::need_mark, switch_rtp::next_write_samplecount, switch_rtp_rfc2833_data::out_digit, switch_rtp_rfc2833_data::out_digit_dur, switch_rtp_rfc2833_data::out_digit_packet, switch_rtp_rfc2833_data::out_digit_sofar, switch_rtp_rfc2833_data::out_digit_sub_sofar, switch_rtp_stats_t::outbound, switch_rtp::queue_delay, switch_rtp_numbers_t::raw_bytes, RTP_BUG_CISCO_SKIP_MARK_BIT_2833, RTP_BUG_SONUS_SEND_INVALID_TIMESTAMP_2833, switch_rtp::rtp_bugs, switch_timer::samplecount, switch_rtp::samples_per_interval, switch_rtp::sending_dtmf, switch_rtp::seq, switch_rtp::session, set_dtmf_delay(), switch_rtp::stats, SWITCH_CHANNEL_SESSION_LOG, switch_char_to_rfc2833(), SWITCH_LOG_DEBUG, switch_log_printf(), switch_queue_size(), switch_queue_trypop(), SWITCH_RTP_FLAG_RESET, SWITCH_RTP_FLAG_USE_TIMER, switch_rtp_write_manual(), SWITCH_STATUS_SUCCESS, switch_rtp::te, switch_rtp::timer, and switch_rtp_rfc2833_data::timestamp_dtmf.

Referenced by rtp_common_read().

4785 {
4786  switch_frame_flag_t flags = 0;
4787  uint32_t samples = rtp_session->samples_per_interval;
4788 
4789  if (!rtp_session->last_write_ts) {
4790  return;
4791  }
4792 
4793  if (rtp_session->dtmf_data.out_digit_dur > 0) {
4794  int x, loops = 1;
4795 
4796  rtp_session->dtmf_data.out_digit_sofar += samples;
4797  rtp_session->dtmf_data.out_digit_sub_sofar += samples;
4798 
4799  if (rtp_session->dtmf_data.out_digit_sub_sofar > 0xFFFF) {
4800  rtp_session->dtmf_data.out_digit_sub_sofar = samples;
4801  rtp_session->dtmf_data.timestamp_dtmf += 0xFFFF;
4802  }
4803 
4804  if (rtp_session->dtmf_data.out_digit_sofar >= rtp_session->dtmf_data.out_digit_dur) {
4805  rtp_session->dtmf_data.out_digit_packet[1] |= 0x80;
4806  loops = 3;
4807  }
4808 
4809  rtp_session->dtmf_data.out_digit_packet[2] = (unsigned char) (rtp_session->dtmf_data.out_digit_sub_sofar >> 8);
4810  rtp_session->dtmf_data.out_digit_packet[3] = (unsigned char) rtp_session->dtmf_data.out_digit_sub_sofar;
4811 
4812  for (x = 0; x < loops; x++) {
4813  switch_size_t wrote = switch_rtp_write_manual(rtp_session,
4814  rtp_session->dtmf_data.out_digit_packet, 4, 0,
4815  rtp_session->te, rtp_session->dtmf_data.timestamp_dtmf, &flags);
4816 
4817  rtp_session->stats.outbound.raw_bytes += wrote;
4818  rtp_session->stats.outbound.dtmf_packet_count++;
4819 
4820  if (loops == 1) {
4821  rtp_session->last_write_ts += samples;
4822 
4824  rtp_session->dtmf_data.timestamp_dtmf = rtp_session->last_write_ts;
4825  }
4826  }
4827 
4828  switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(rtp_session->session), SWITCH_LOG_DEBUG, "Send %s packet for [%c] ts=%u dur=%d/%d/%d seq=%d lw=%u\n",
4829  loops == 1 ? "middle" : "end", rtp_session->dtmf_data.out_digit,
4830  rtp_session->dtmf_data.timestamp_dtmf,
4831  rtp_session->dtmf_data.out_digit_sofar,
4832  rtp_session->dtmf_data.out_digit_sub_sofar, rtp_session->dtmf_data.out_digit_dur, rtp_session->seq, rtp_session->last_write_ts);
4833  }
4834 
4835  if (loops != 1) {
4836  rtp_session->sending_dtmf = 0;
4837  rtp_session->need_mark = 1;
4838 
4839  if (rtp_session->flags[SWITCH_RTP_FLAG_USE_TIMER]) {
4840  rtp_session->last_write_samplecount = rtp_session->timer.samplecount;
4841  }
4842 
4843  rtp_session->dtmf_data.out_digit_dur = 0;
4844 
4845  if (rtp_session->interdigit_delay) {
4846  set_dtmf_delay(rtp_session, rtp_session->interdigit_delay, rtp_session->interdigit_delay * 10);
4847  }
4848 
4849  return;
4850  }
4851  }
4852 
4853  if (!rtp_session->dtmf_data.out_digit_dur && rtp_session->dtmf_data.dtmf_queue && switch_queue_size(rtp_session->dtmf_data.dtmf_queue)) {
4854  void *pop;
4855 
4856  if (rtp_session->flags[SWITCH_RTP_FLAG_USE_TIMER]) {
4857  if (rtp_session->timer.samplecount < rtp_session->next_write_samplecount) {
4858  return;
4859  }
4860 
4861  if (rtp_session->timer.samplecount >= rtp_session->max_next_write_samplecount) {
4862  rtp_session->queue_delay = 0;
4863  }
4864 
4865  } else if (rtp_session->queue_delay) {
4866  if (rtp_session->delay_samples >= rtp_session->samples_per_interval) {
4867  rtp_session->delay_samples -= rtp_session->samples_per_interval;
4868  } else {
4869  rtp_session->delay_samples = 0;
4870  }
4871 
4872  if (!rtp_session->delay_samples) {
4873  rtp_session->queue_delay = 0;
4874  }
4875  }
4876 
4877  if (rtp_session->queue_delay) {
4878  return;
4879  }
4880 
4881 
4882  if (!rtp_session->sending_dtmf) {
4883  rtp_session->sending_dtmf = 1;
4884  }
4885 
4886  if (switch_queue_trypop(rtp_session->dtmf_data.dtmf_queue, &pop) == SWITCH_STATUS_SUCCESS) {
4887  switch_dtmf_t *rdigit = pop;
4888  switch_size_t wrote;
4889 
4890  if (rdigit->digit == 'w') {
4891  set_dtmf_delay(rtp_session, 500, 0);
4892  free(rdigit);
4893  return;
4894  }
4895 
4896  if (rdigit->digit == 'W') {
4897  set_dtmf_delay(rtp_session, 1000, 0);
4898  free(rdigit);
4899  return;
4900  }
4901 
4902 
4903 
4904  memset(rtp_session->dtmf_data.out_digit_packet, 0, 4);
4905  rtp_session->dtmf_data.out_digit_sofar = samples;
4906  rtp_session->dtmf_data.out_digit_sub_sofar = samples;
4907  rtp_session->dtmf_data.out_digit_dur = rdigit->duration;
4908  rtp_session->dtmf_data.out_digit = rdigit->digit;
4909  rtp_session->dtmf_data.out_digit_packet[0] = (unsigned char) switch_char_to_rfc2833(rdigit->digit);
4910  rtp_session->dtmf_data.out_digit_packet[1] = 13;
4911  rtp_session->dtmf_data.out_digit_packet[2] = (unsigned char) (rtp_session->dtmf_data.out_digit_sub_sofar >> 8);
4912  rtp_session->dtmf_data.out_digit_packet[3] = (unsigned char) rtp_session->dtmf_data.out_digit_sub_sofar;
4913 
4914 
4915  rtp_session->dtmf_data.timestamp_dtmf = rtp_session->last_write_ts + samples;
4916  rtp_session->last_write_ts = rtp_session->dtmf_data.timestamp_dtmf;
4917  rtp_session->flags[SWITCH_RTP_FLAG_RESET] = 0;
4918 
4919  wrote = switch_rtp_write_manual(rtp_session,
4920  rtp_session->dtmf_data.out_digit_packet,
4921  4,
4922  rtp_session->rtp_bugs & RTP_BUG_CISCO_SKIP_MARK_BIT_2833 ? 0 : 1,
4923  rtp_session->te, rtp_session->dtmf_data.timestamp_dtmf, &flags);
4924 
4925 
4926  rtp_session->stats.outbound.raw_bytes += wrote;
4927  rtp_session->stats.outbound.dtmf_packet_count++;
4928 
4929  switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(rtp_session->session), SWITCH_LOG_DEBUG, "Send start packet for [%c] ts=%u dur=%d/%d/%d seq=%d lw=%u\n",
4930  rtp_session->dtmf_data.out_digit,
4931  rtp_session->dtmf_data.timestamp_dtmf,
4932  rtp_session->dtmf_data.out_digit_sofar,
4933  rtp_session->dtmf_data.out_digit_sub_sofar, rtp_session->dtmf_data.out_digit_dur, rtp_session->seq, rtp_session->last_write_ts);
4934 
4935  free(rdigit);
4936  }
4937  }
4938 }
uint32_t queue_delay
Definition: switch_rtp.c:370
unsigned int switch_queue_size(switch_queue_t *queue)
Definition: switch_apr.c:1114
#define SWITCH_CHANNEL_SESSION_LOG(x)
unsigned char out_digit_packet[4]
Definition: switch_rtp.c:219
uint32_t delay_samples
Definition: switch_rtp.c:367
switch_status_t switch_queue_trypop(switch_queue_t *queue, void **data)
Definition: switch_apr.c:1140
static void set_dtmf_delay(switch_rtp_t *rtp_session, uint32_t ms, uint32_t max_ms)
Definition: switch_rtp.c:4763
uint32_t duration
Definition: switch_types.h:288
switch_size_t dtmf_packet_count
Definition: switch_types.h:634
uint32_t max_next_write_samplecount
Definition: switch_rtp.c:369
struct switch_rtp_rfc2833_data dtmf_data
Definition: switch_rtp.c:403
switch_size_t raw_bytes
Definition: switch_types.h:627
uint32_t flags[SWITCH_RTP_FLAG_INVALID]
Definition: switch_rtp.c:372
switch_rtp_numbers_t outbound
Definition: switch_types.h:691
uintptr_t switch_size_t
uint16_t seq
Definition: switch_rtp.c:353
uint8_t need_mark
Definition: switch_rtp.c:358
uint32_t switch_frame_flag_t
switch_rtp_stats_t stats
Definition: switch_rtp.c:428
unsigned char switch_char_to_rfc2833(char key)
Return the RFC2833 event based on an key character.
uint32_t samples_per_interval
Definition: switch_rtp.c:386
uint32_t interdigit_delay
Definition: switch_rtp.c:445
switch_timer_t timer
Definition: switch_rtp.c:411
uint32_t last_write_ts
Definition: switch_rtp.c:363
switch_core_session_t * session
Definition: switch_rtp.c:446
int8_t sending_dtmf
Definition: switch_rtp.c:357
unsigned int out_digit_sofar
Definition: switch_rtp.c:220
switch_rtp_bug_flag_t rtp_bugs
Definition: switch_rtp.c:427
switch_payload_t te
Definition: switch_rtp.c:404
switch_queue_t * dtmf_queue
Definition: switch_rtp.c:217
uint32_t next_write_samplecount
Definition: switch_rtp.c:368
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.
unsigned int out_digit_dur
Definition: switch_rtp.c:222
uint32_t last_write_samplecount
Definition: switch_rtp.c:366
unsigned int out_digit_sub_sofar
Definition: switch_rtp.c:221
memset(buf, 0, buflen)
int switch_rtp_write_manual(switch_rtp_t *rtp_session, void *data, uint32_t datalen, uint8_t m, switch_payload_t payload, uint32_t ts, switch_frame_flag_t *flags)
Write data with a specified payload and sequence number to a given RTP session.
Definition: switch_rtp.c:7955
static int do_dtls ( switch_rtp_t rtp_session,
switch_dtls_t dtls 
)
static

Definition at line 3144 of file switch_rtp.c.

References buf, switch_dtls_s::bytes, switch_dtls_s::data, switch_rtp::ice, switch_rtp_ice_t::ice_user, switch_dtls_s::read_bio, switch_rtp_ice_t::ready, switch_dtls_s::remote_addr, switch_rtp_ice_t::rready, rtp_type, switch_rtp::session, switch_dtls_s::sock_output, switch_dtls_s::ssl, switch_dtls_s::state, SWITCH_CHANNEL_SESSION_LOG, SWITCH_LOG_ERROR, switch_log_printf(), switch_socket_sendto(), SWITCH_STATUS_SUCCESS, and switch_dtls_s::write_bio.

Referenced by read_rtcp_packet(), and read_rtp_packet().

3145 {
3146  int r = 0, ret = 0, len;
3147  switch_size_t bytes;
3148  unsigned char buf[4096] = "";
3149  int ready = rtp_session->ice.ice_user ? (rtp_session->ice.rready && rtp_session->ice.ready) : 1;
3150 
3151 
3152  if (!dtls->bytes && !ready) {
3153  return 0;
3154  }
3155 
3156  if ((ret = BIO_write(dtls->read_bio, dtls->data, (int)dtls->bytes)) != (int)dtls->bytes && dtls->bytes > 0) {
3157  ret = SSL_get_error(dtls->ssl, ret);
3158  switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(rtp_session->session), SWITCH_LOG_ERROR, "%s DTLS packet read err %d\n", rtp_type(rtp_session), ret);
3159  }
3160 
3161  if (dtls_states[dtls->state]) {
3162  r = dtls_states[dtls->state](rtp_session, dtls);
3163  }
3164 
3165  if ((len = BIO_read(dtls->write_bio, buf, sizeof(buf))) > 0) {
3166  bytes = len;
3167 
3168  if (switch_socket_sendto(dtls->sock_output, dtls->remote_addr, 0, (void *)buf, &bytes ) != SWITCH_STATUS_SUCCESS) {
3169  switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(rtp_session->session), SWITCH_LOG_ERROR, "%s DTLS packet not written\n", rtp_type(rtp_session));
3170  }
3171  }
3172 
3173 
3174 
3175  return r;
3176 }
#define SWITCH_CHANNEL_SESSION_LOG(x)
BIO * write_bio
Definition: switch_rtp.c:265
switch_sockaddr_t * remote_addr
Definition: switch_rtp.c:275
BIO * read_bio
Definition: switch_rtp.c:264
dtls_state_t state
Definition: switch_rtp.c:268
#define rtp_type(rtp_session)
Definition: switch_rtp.c:513
switch_socket_t * sock_output
Definition: switch_rtp.c:274
switch_byte_t switch_byte_t * buf
switch_status_t switch_socket_sendto(switch_socket_t *sock, switch_sockaddr_t *where, int32_t flags, const char *buf, switch_size_t *len)
Definition: switch_apr.c:773
dtls_state_handler_t dtls_states[DS_INVALID]
Definition: switch_rtp.c:291
uintptr_t switch_size_t
switch_core_session_t * session
Definition: switch_rtp.c:446
switch_rtp_ice_t ice
Definition: switch_rtp.c:377
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_size_t bytes
Definition: switch_rtp.c:272
static switch_size_t do_flush ( switch_rtp_t rtp_session,
int  force,
switch_size_t  bytes_in 
)
static

Definition at line 4983 of file switch_rtp.c.

References FALSE, switch_rtp::flags, switch_rtp_numbers_t::flush_packet_count, switch_rtp::from_addr, handle_rfc2833(), switch_rtp_stats_t::inbound, switch_rtp::jb, jb_valid(), switch_rtp::last_rtp_hdr, switch_rtp_numbers_t::packet_count, switch_rtp::pause_jb, switch_rtp_numbers_t::raw_bytes, READ_DEC, READ_INC, switch_rtp::recv_msg, switch_rtp::recv_te, reset_jitter_seq(), rtp_header_len, switch_rtp::session, switch_rtp::sock_input, switch_rtp::stats, switch_channel_get_name(), SWITCH_CHANNEL_LOG, SWITCH_CHANNEL_SESSION_LOG, switch_core_session_get_channel(), switch_core_session_request_video_refresh(), switch_jb_reset(), SWITCH_LOG_CONSOLE, SWITCH_LOG_ERROR, switch_log_printf(), switch_rtp_clear_flag(), SWITCH_RTP_FLAG_DEBUG_RTP_READ, SWITCH_RTP_FLAG_DTMF_ON, SWITCH_RTP_FLAG_NOBLOCK, SWITCH_RTP_FLAG_PROXY_MEDIA, SWITCH_RTP_FLAG_UDPTL, SWITCH_RTP_FLAG_VIDEO, switch_rtp_ready(), switch_rtp_set_flag(), SWITCH_SO_NONBLOCK, switch_socket_opt_set(), switch_socket_recvfrom(), TRUE, switch_rtp::vb, and switch_rtp::vbw.

Referenced by rtp_common_read().

4984 {
4985  int was_blocking = 0;
4986  switch_size_t bytes;
4987  uint32_t flushed = 0;
4988  switch_size_t bytes_out = 0;
4989 
4990  if (!switch_rtp_ready(rtp_session)) {
4991  return 0;
4992  }
4993 
4994  reset_jitter_seq(rtp_session);
4995 
4996  if (!force) {
4997  if (rtp_session->flags[SWITCH_RTP_FLAG_PROXY_MEDIA] ||
4998  rtp_session->flags[SWITCH_RTP_FLAG_UDPTL] ||
4999  rtp_session->flags[SWITCH_RTP_FLAG_DTMF_ON]
5000  ) {
5001  return 0;
5002  }
5003  }
5004 
5005  READ_INC(rtp_session);
5006 
5007  if (switch_rtp_ready(rtp_session) ) {
5008 
5009  if (rtp_session->jb && !rtp_session->pause_jb && jb_valid(rtp_session)) {
5010  //switch_jb_reset(rtp_session->jb);
5011  bytes_out = bytes_in;
5012  goto end;
5013  }
5014 
5015  if (rtp_session->vbw) {
5016  switch_jb_reset(rtp_session->vbw);
5017  }
5018 
5019  if (rtp_session->vb) {
5020  //switch_jb_reset(rtp_session->vb);
5021  bytes_out = bytes_in;
5022  goto end;
5023  }
5024 
5025  if (rtp_session->flags[SWITCH_RTP_FLAG_DEBUG_RTP_READ]) {
5027  SWITCH_LOG_CONSOLE, "%s FLUSH\n",
5028  rtp_session->session ? switch_channel_get_name(switch_core_session_get_channel(rtp_session->session)) : "NoName"
5029  );
5030  }
5031 
5032  if (!rtp_session->flags[SWITCH_RTP_FLAG_NOBLOCK]) {
5033  was_blocking = 1;
5036  }
5037 
5038  do {
5039  if (switch_rtp_ready(rtp_session)) {
5040  bytes = sizeof(rtp_msg_t);
5041  switch_socket_recvfrom(rtp_session->from_addr, rtp_session->sock_input, 0, (void *) &rtp_session->recv_msg, &bytes);
5042 
5043  if (bytes) {
5044  int do_cng = 0;
5045 
5046  /* Make sure to handle RFC2833 packets, even if we're flushing the packets */
5047  if (bytes > rtp_header_len && rtp_session->last_rtp_hdr.pt == rtp_session->recv_te) {
5048  handle_rfc2833(rtp_session, bytes, &do_cng);
5049 #ifdef DEBUG_2833
5050  switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "*** RTP packet handled in flush loop %d ***\n", do_cng);
5051 #endif
5052  }
5053 
5054  flushed++;
5055 
5056  rtp_session->stats.inbound.raw_bytes += bytes;
5057  rtp_session->stats.inbound.flush_packet_count++;
5058  rtp_session->stats.inbound.packet_count++;
5059  }
5060  } else {
5061  break;
5062  }
5063  } while (bytes > 0);
5064 
5065  if (was_blocking && switch_rtp_ready(rtp_session)) {
5068  }
5069 
5070 
5071  if (rtp_session->flags[SWITCH_RTP_FLAG_VIDEO] && rtp_session->session) {
5072  //int type = 1; // sum flags: 1 encoder; 2; decoder
5073  //switch_core_media_codec_control(rtp_session->session, SWITCH_MEDIA_TYPE_VIDEO, SWITCH_IO_READ, SCC_VIDEO_RESET, SCCT_INT, (void *)&type, NULL, NULL);
5075  }
5076  }
5077 
5078  end:
5079 
5080  READ_DEC(rtp_session);
5081 
5082  return bytes_out;
5083 }
#define SWITCH_CHANNEL_SESSION_LOG(x)
switch_rtp_numbers_t inbound
Definition: switch_types.h:690
uint8_t switch_rtp_ready(switch_rtp_t *rtp_session)
Test if an RTP session is ready.
Definition: switch_rtp.c:4452
#define SWITCH_CHANNEL_LOG
switch_socket_t * sock_input
Definition: switch_rtp.c:309
switch_jb_t * vbw
Definition: switch_rtp.c:416
switch_status_t switch_socket_recvfrom(switch_sockaddr_t *from, switch_socket_t *sock, int32_t flags, char *buf, size_t *len)
Definition: switch_apr.c:936
#define READ_DEC(rtp_session)
Definition: switch_rtp.c:61
_Ret_ switch_channel_t * switch_core_session_get_channel(_In_ switch_core_session_t *session)
Retrieve a pointer to the channel object associated with a given session.
switch_size_t raw_bytes
Definition: switch_types.h:627
uint32_t flags[SWITCH_RTP_FLAG_INVALID]
Definition: switch_rtp.c:372
#define READ_INC(rtp_session)
Definition: switch_rtp.c:60
switch_status_t switch_socket_opt_set(switch_socket_t *sock, int32_t opt, int32_t on)
Definition: switch_apr.c:823
uintptr_t switch_size_t
switch_size_t packet_count
Definition: switch_types.h:629
switch_jb_t * vb
Definition: switch_rtp.c:415
switch_rtp_stats_t stats
Definition: switch_rtp.c:428
void switch_rtp_clear_flag(switch_rtp_t *rtp_session, switch_rtp_flag_t flag)
Clear an RTP Flag.
Definition: switch_rtp.c:4747
void switch_rtp_set_flag(switch_rtp_t *rtp_session, switch_rtp_flag_t flag)
Set an RTP Flag.
Definition: switch_rtp.c:4702
switch_status_t switch_core_session_request_video_refresh(switch_core_session_t *session)
switch_jb_t * jb
Definition: switch_rtp.c:414
#define SWITCH_SO_NONBLOCK
Definition: switch_apr.h:994
rtp_msg_t recv_msg
Definition: switch_rtp.c:327
#define FALSE
static void reset_jitter_seq(switch_rtp_t *rtp_session)
Definition: switch_rtp.c:1595
switch_core_session_t * session
Definition: switch_rtp.c:446
switch_size_t flush_packet_count
Definition: switch_types.h:636
void switch_jb_reset(switch_jb_t *jb)
uint8_t pause_jb
Definition: switch_rtp.c:441
static int jb_valid(switch_rtp_t *rtp_session)
Definition: switch_rtp.c:4967
switch_payload_t recv_te
Definition: switch_rtp.c:405
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 handle_rfc2833_result_t handle_rfc2833(switch_rtp_t *rtp_session, switch_size_t bytes, int *do_cng)
Definition: switch_rtp.c:539
#define TRUE
switch_sockaddr_t * from_addr
Definition: switch_rtp.c:374
rtp_hdr_t last_rtp_hdr
Definition: switch_rtp.c:351
char * switch_channel_get_name(switch_channel_t *channel)
Retrieve the name of a given channel.
#define rtp_header_len
Definition: switch_rtp.c:66
static void do_mos ( switch_rtp_t rtp_session,
int  force 
)
static

Definition at line 1521 of file switch_rtp.c.

References switch_rtp::bad_stream, switch_rtp::consecutive_flaws, switch_rtp_numbers_t::flaws, switch_rtp_stats_t::inbound, switch_rtp_numbers_t::last_flaw, switch_rtp_numbers_t::max_variance, switch_rtp_numbers_t::min_variance, switch_rtp_numbers_t::mos, switch_rtp_numbers_t::R, switch_rtp_numbers_t::recved, rtp_session_name, rtp_type, switch_rtp::session, switch_rtp::stats, SWITCH_CHANNEL_SESSION_LOG, SWITCH_LOG_DEBUG3, switch_log_printf(), and switch_rtp_numbers_t::variance.

Referenced by check_jitter(), rtp_common_read(), switch_rtp_get_stats(), and switch_rtp_sync_stats().

1521  {
1522 
1523  if ((switch_size_t)rtp_session->stats.inbound.recved < rtp_session->stats.inbound.flaws) {
1524  rtp_session->stats.inbound.flaws = 0;
1525  }
1526 
1527  if (rtp_session->stats.inbound.recved > 0 &&
1528  rtp_session->stats.inbound.flaws && (force || rtp_session->stats.inbound.last_flaw != rtp_session->stats.inbound.flaws)) {
1529  int R;
1530 
1531  if (rtp_session->consecutive_flaws++) {
1532  int diff, penalty;
1533 
1534  diff = (rtp_session->stats.inbound.flaws - rtp_session->stats.inbound.last_flaw);
1535 
1536  if (diff < 1) diff = 1;
1537 
1538  penalty = diff * 2;
1539 
1540  switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(rtp_session->session), SWITCH_LOG_DEBUG3, "%s %s %d consecutive flaws, adding %d flaw penalty\n",
1541  rtp_session_name(rtp_session), rtp_type(rtp_session),
1542  rtp_session->consecutive_flaws, penalty);
1543  rtp_session->bad_stream++;
1544  rtp_session->stats.inbound.flaws += penalty;
1545  }
1546 
1547  R = (int)((double)((double)(rtp_session->stats.inbound.recved - rtp_session->stats.inbound.flaws) / (double)rtp_session->stats.inbound.recved) * 100.0);
1548 
1549  if (R < 0 || R > 100) R = 100;
1550 
1551  rtp_session->stats.inbound.R = R;
1552  rtp_session->stats.inbound.mos = 1 + (0.035) * R + (.000007) * R * (R-60) * (100-R);
1553  rtp_session->stats.inbound.last_flaw = rtp_session->stats.inbound.flaws;
1554  switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(rtp_session->session), SWITCH_LOG_DEBUG3, "%s %s stat %0.2f %ld/%d flaws: %ld mos: %0.2f v: %0.2f %0.2f/%0.2f\n",
1555  rtp_session_name(rtp_session),
1556  rtp_type(rtp_session),
1557  rtp_session->stats.inbound.R,
1558  (long int)(rtp_session->stats.inbound.recved - rtp_session->stats.inbound.flaws), rtp_session->stats.inbound.recved,
1559  (long int)rtp_session->stats.inbound.flaws,
1560  rtp_session->stats.inbound.mos,
1561  rtp_session->stats.inbound.variance,
1562  rtp_session->stats.inbound.min_variance,
1563  rtp_session->stats.inbound.max_variance
1564  );
1565  } else {
1566  rtp_session->consecutive_flaws = 0;
1567  }
1568 }
switch_size_t flaws
Definition: switch_types.h:657
#define SWITCH_CHANNEL_SESSION_LOG(x)
switch_rtp_numbers_t inbound
Definition: switch_types.h:690
uint32_t consecutive_flaws
Definition: switch_rtp.c:393
#define rtp_session_name(_rtp_session)
Definition: switch_rtp.c:79
switch_size_t last_flaw
Definition: switch_types.h:658
#define rtp_type(rtp_session)
Definition: switch_rtp.c:513
uintptr_t switch_size_t
switch_rtp_stats_t stats
Definition: switch_rtp.c:428
switch_core_session_t * session
Definition: switch_rtp.c:446
void switch_log_printf(_In_ switch_text_channel_t channel, _In_z_ const char *file, _In_z_ const char *func, _In_ int line, _In_opt_z_ const char *userdata, _In_ switch_log_level_t level, _In_z_ _Printf_format_string_ const char *fmt,...) PRINTF_FUNCTION(7
Write log data to the logging engine.
uint32_t bad_stream
Definition: switch_rtp.c:430
static int dtls_state_fail ( switch_rtp_t rtp_session,
switch_dtls_t dtls 
)
static

Definition at line 3089 of file switch_rtp.c.

References switch_rtp::session, SWITCH_CAUSE_DESTINATION_OUT_OF_ORDER, switch_channel_hangup, and switch_core_session_get_channel().

3090 {
3091  if (rtp_session->session) {
3092  switch_channel_t *channel = switch_core_session_get_channel(rtp_session->session);
3094  }
3095 
3096  return -1;
3097 }
#define switch_channel_hangup(channel, hangup_cause)
Hangup a channel flagging it's state machine to end.
_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_core_session_t * session
Definition: switch_rtp.c:446
static int dtls_state_handshake ( switch_rtp_t rtp_session,
switch_dtls_t dtls 
)
static

Definition at line 3100 of file switch_rtp.c.

References DS_FAIL, DS_SETUP, dtls_set_state, rtp_type, switch_rtp::session, switch_dtls_s::ssl, SWITCH_CHANNEL_SESSION_LOG, SWITCH_LOG_ERROR, and switch_log_printf().

3101 {
3102  int ret;
3103 
3104  if ((ret = SSL_do_handshake(dtls->ssl)) != 1){
3105  switch((ret = SSL_get_error(dtls->ssl, ret))){
3106  case SSL_ERROR_WANT_READ:
3107  case SSL_ERROR_WANT_WRITE:
3108  case SSL_ERROR_NONE:
3109  break;
3110  default:
3111  switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(rtp_session->session), SWITCH_LOG_ERROR, "%s Handshake failure %d\n", rtp_type(rtp_session), ret);
3112  dtls_set_state(dtls, DS_FAIL);
3113  return -1;
3114  }
3115  }
3116 
3117  if (SSL_is_init_finished(dtls->ssl)) {
3118  dtls_set_state(dtls, DS_SETUP);
3119  }
3120 
3121  return 0;
3122 }
#define SWITCH_CHANNEL_SESSION_LOG(x)
#define rtp_type(rtp_session)
Definition: switch_rtp.c:513
#define dtls_set_state(_dtls, _state)
Definition: switch_rtp.c:2999
switch_core_session_t * session
Definition: switch_rtp.c:446
void switch_log_printf(_In_ switch_text_channel_t channel, _In_z_ const char *file, _In_z_ const char *func, _In_ int line, _In_opt_z_ const char *userdata, _In_ switch_log_level_t level, _In_z_ _Printf_format_string_ const char *fmt,...) PRINTF_FUNCTION(7
Write log data to the logging engine.
static const char* dtls_state_names ( dtls_state_t  s)
static

Definition at line 2989 of file switch_rtp.c.

References DS_INVALID.

2990 {
2991  if (s > DS_INVALID) {
2992  s = DS_INVALID;
2993  }
2994 
2995  return dtls_state_names_t[s];
2996 }
static const char * dtls_state_names_t[]
Definition: switch_rtp.c:2988
static int dtls_state_ready ( switch_rtp_t rtp_session,
switch_dtls_t dtls 
)
static

Definition at line 3072 of file switch_rtp.c.

References switch_rtp::flags, switch_dtls_s::new_state, switch_rtp::session, switch_core_session_get_partner, switch_core_session_request_video_refresh(), switch_core_session_rwunlock(), SWITCH_RTP_FLAG_VIDEO, and SWITCH_STATUS_SUCCESS.

3073 {
3074 
3075  if (dtls->new_state) {
3076  if (rtp_session->flags[SWITCH_RTP_FLAG_VIDEO]) {
3077  switch_core_session_t *other_session;
3078 
3079  if (rtp_session->session && switch_core_session_get_partner(rtp_session->session, &other_session) == SWITCH_STATUS_SUCCESS) {
3081  switch_core_session_rwunlock(other_session);
3082  }
3083  }
3084  dtls->new_state = 0;
3085  }
3086  return 0;
3087 }
uint32_t flags[SWITCH_RTP_FLAG_INVALID]
Definition: switch_rtp.c:372
#define switch_core_session_get_partner(_session, _partner)
Definition: switch_core.h:1002
void switch_core_session_rwunlock(_In_ switch_core_session_t *session)
Unlock a read or write lock on as given session.
switch_status_t switch_core_session_request_video_refresh(switch_core_session_t *session)
switch_core_session_t * session
Definition: switch_rtp.c:446
uint8_t new_state
Definition: switch_rtp.c:270
static int dtls_state_setup ( switch_rtp_t rtp_session,
switch_dtls_t dtls 
)
static

Definition at line 3005 of file switch_rtp.c.

References AES_CM_128_HMAC_SHA1_80, cr_keylen, cr_kslen, cr_saltlen, DS_FAIL, DS_READY, switch_rtp::dtls, dtls_set_state, DTLS_TYPE_CLIENT, DTLS_TYPE_SERVER, switch_dtls_s::remote_fp, switch_rtp::rtcp_dtls, rtp_type, switch_rtp::session, switch_dtls_s::ssl, SWITCH_CHANNEL_SESSION_LOG, switch_core_cert_extract_fingerprint(), switch_core_cert_verify(), SWITCH_LOG_ERROR, SWITCH_LOG_INFO, switch_log_printf(), switch_rtp_add_crypto_key(), SWITCH_RTP_CRYPTO_RECV, SWITCH_RTP_CRYPTO_RECV_RTCP, SWITCH_RTP_CRYPTO_SEND, SWITCH_RTP_CRYPTO_SEND_RTCP, and switch_dtls_s::type.

3006 {
3007  X509 *cert;
3008  int r = 0;
3009 
3010  if ((dtls->type & DTLS_TYPE_SERVER)) {
3011  r = 1;
3012  } else if ((cert = SSL_get_peer_certificate(dtls->ssl))) {
3015  X509_free(cert);
3016  }
3017 
3018  if (!r) {
3019  switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(rtp_session->session), SWITCH_LOG_ERROR, "%s Fingerprint Verification Failed!\n", rtp_type(rtp_session));
3020  dtls_set_state(dtls, DS_FAIL);
3021  return -1;
3022  } else {
3023  uint8_t raw_key_data[cr_kslen*2] = { 0 };
3024  unsigned char *local_key, *remote_key, *local_salt, *remote_salt;
3025  unsigned char local_key_buf[cr_kslen] = {0}, remote_key_buf[cr_kslen] = {0};
3026 
3027  switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(rtp_session->session), SWITCH_LOG_INFO, "%s Fingerprint Verified.\n", rtp_type(rtp_session));
3028 
3029 #ifdef HAVE_OPENSSL_DTLS_SRTP
3030  if (!SSL_export_keying_material(dtls->ssl, raw_key_data, sizeof(raw_key_data), "EXTRACTOR-dtls_srtp", 19, NULL, 0, 0)) {
3031  switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(rtp_session->session), SWITCH_LOG_ERROR, "%s Key material export failure\n", rtp_type(rtp_session));
3032  dtls_set_state(dtls, DS_FAIL);
3033  return -1;
3034  }
3035 #else
3036  return -1;
3037 #endif
3038 
3039  if ((dtls->type & DTLS_TYPE_CLIENT)) {
3040  local_key = raw_key_data;
3041  remote_key = local_key + cr_keylen;
3042  local_salt = remote_key + cr_keylen;
3043  remote_salt = local_salt + cr_saltlen;
3044 
3045  } else {
3046  remote_key = raw_key_data;
3047  local_key = remote_key + cr_keylen;
3048  remote_salt = local_key + cr_keylen;
3049  local_salt = remote_salt + cr_saltlen;
3050  }
3051 
3052  memcpy(local_key_buf, local_key, cr_keylen);
3053  memcpy(local_key_buf + cr_keylen, local_salt, cr_saltlen);
3054 
3055  memcpy(remote_key_buf, remote_key, cr_keylen);
3056  memcpy(remote_key_buf + cr_keylen, remote_salt, cr_saltlen);
3057 
3058  if (dtls == rtp_session->rtcp_dtls && rtp_session->rtcp_dtls != rtp_session->dtls) {
3061  } else {
3064  }
3065  }
3066 
3067  dtls_set_state(dtls, DS_READY);
3068 
3069  return 0;
3070 }
dtls_fingerprint_t * remote_fp
Definition: switch_rtp.c:267
switch_status_t switch_rtp_add_crypto_key(switch_rtp_t *rtp_session, switch_rtp_crypto_direction_t direction, uint32_t index, switch_rtp_crypto_key_type_t type, unsigned char *key, switch_size_t keylen)
Definition: switch_rtp.c:3468
#define SWITCH_CHANNEL_SESSION_LOG(x)
int switch_core_cert_verify(dtls_fingerprint_t *fp)
#define cr_kslen
Definition: switch_rtp.c:3003
#define rtp_type(rtp_session)
Definition: switch_rtp.c:513
switch_dtls_t * dtls
Definition: switch_rtp.c:348
#define dtls_set_state(_dtls, _state)
Definition: switch_rtp.c:2999
int switch_core_cert_extract_fingerprint(X509 *x509, dtls_fingerprint_t *fp)
switch_core_session_t * session
Definition: switch_rtp.c:446
switch_dtls_t * rtcp_dtls
Definition: switch_rtp.c:349
dtls_type_t type
Definition: switch_rtp.c:271
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 cr_saltlen
Definition: switch_rtp.c:3002
#define cr_keylen
Definition: switch_rtp.c:3001
static switch_status_t enable_local_rtcp_socket ( switch_rtp_t rtp_session,
const char **  err 
)
static

Definition at line 2522 of file switch_rtp.c.

References switch_rtp::flags, switch_rtp::from_addr, switch_rtp::local_host_str, switch_rtp::local_port, switch_rtp::pool, switch_rtp::rtcp_from_addr, switch_rtp::rtcp_local_addr, switch_rtp::rtcp_read_pollfd, switch_rtp::rtcp_sock_input, switch_rtp::session, SWITCH_CHANNEL_SESSION_LOG, switch_get_addr(), SWITCH_LOG_ERROR, switch_log_printf(), SWITCH_POLLERR, SWITCH_POLLIN, SWITCH_RTP_FLAG_ENABLE_RTCP, SWITCH_SO_REUSEADDR, switch_sockaddr_get_family(), switch_sockaddr_get_port(), switch_sockaddr_info_get(), switch_socket_bind(), switch_socket_close(), switch_socket_create(), switch_socket_create_pollset(), switch_socket_opt_set(), SWITCH_STATUS_FALSE, SWITCH_STATUS_SUCCESS, and SWITCH_UNSPEC.

Referenced by switch_rtp_activate_rtcp(), and switch_rtp_set_local_address().

2522  {
2523 
2524  const char *host = rtp_session->local_host_str;
2525  switch_port_t port = rtp_session->local_port;
2526  switch_socket_t *rtcp_new_sock = NULL, *rtcp_old_sock = NULL;
2528  char bufa[50];
2529 
2530  if (rtp_session->flags[SWITCH_RTP_FLAG_ENABLE_RTCP]) {
2531  if (switch_sockaddr_info_get(&rtp_session->rtcp_local_addr, host, SWITCH_UNSPEC, port+1, 0, rtp_session->pool) != SWITCH_STATUS_SUCCESS) {
2532  *err = "RTCP Local Address Error!";
2533  goto done;
2534  }
2535 
2536  if (switch_socket_create(&rtcp_new_sock, switch_sockaddr_get_family(rtp_session->rtcp_local_addr), SOCK_DGRAM, 0, rtp_session->pool) != SWITCH_STATUS_SUCCESS) {
2537  *err = "RTCP Socket Error!";
2538  goto done;
2539  }
2540 
2542  *err = "RTCP Socket Error!";
2543  goto done;
2544  }
2545 
2546  if (switch_socket_bind(rtcp_new_sock, rtp_session->rtcp_local_addr) != SWITCH_STATUS_SUCCESS) {
2547  *err = "RTCP Bind Error!";
2548  goto done;
2549  }
2550 
2551  if (switch_sockaddr_info_get(&rtp_session->rtcp_from_addr, switch_get_addr(bufa, sizeof(bufa), rtp_session->from_addr),
2552  SWITCH_UNSPEC, switch_sockaddr_get_port(rtp_session->from_addr) + 1, 0, rtp_session->pool) != SWITCH_STATUS_SUCCESS) {
2553  *err = "RTCP From Address Error!";
2554  goto done;
2555  }
2556 
2557  rtcp_old_sock = rtp_session->rtcp_sock_input;
2558  rtp_session->rtcp_sock_input = rtcp_new_sock;
2559  rtcp_new_sock = NULL;
2560 
2561  switch_socket_create_pollset(&rtp_session->rtcp_read_pollfd, rtp_session->rtcp_sock_input, SWITCH_POLLIN | SWITCH_POLLERR, rtp_session->pool);
2562 
2563  done:
2564 
2565  if (*err) {
2566 
2567  switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(rtp_session->session), SWITCH_LOG_ERROR, "Error allocating rtcp [%s]\n", *err);
2568  status = SWITCH_STATUS_FALSE;
2569  }
2570 
2571  if (rtcp_new_sock) {
2572  switch_socket_close(rtcp_new_sock);
2573  }
2574 
2575  if (rtcp_old_sock) {
2576  switch_socket_close(rtcp_old_sock);
2577  }
2578  } else {
2579  status = SWITCH_STATUS_FALSE;
2580  }
2581 
2582  return status;
2583 }
#define SWITCH_CHANNEL_SESSION_LOG(x)
uint16_t switch_sockaddr_get_port(switch_sockaddr_t *sa)
Definition: switch_apr.c:916
switch_sockaddr_t * rtcp_from_addr
Definition: switch_rtp.c:374
switch_status_t switch_socket_bind(switch_socket_t *sock, switch_sockaddr_t *sa)
Definition: switch_apr.c:719
switch_sockaddr_t * rtcp_local_addr
Definition: switch_rtp.c:313
switch_socket_t * rtcp_sock_input
Definition: switch_rtp.c:309
int32_t switch_sockaddr_get_family(switch_sockaddr_t *sa)
Definition: switch_apr.c:921
#define SWITCH_POLLIN
Definition: switch_apr.h:1321
#define SWITCH_POLLERR
Definition: switch_apr.h:1324
uint32_t flags[SWITCH_RTP_FLAG_INVALID]
Definition: switch_rtp.c:372
char * local_host_str
Definition: switch_rtp.c:380
switch_status_t switch_socket_opt_set(switch_socket_t *sock, int32_t opt, int32_t on)
Definition: switch_apr.c:823
uint16_t switch_port_t
switch_memory_pool_t * pool
Definition: switch_rtp.c:373
switch_status_t switch_socket_create(switch_socket_t **new_sock, int family, int type, int protocol, switch_memory_pool_t *pool)
Definition: switch_apr.c:704
switch_status_t
Common return values.
switch_status_t switch_socket_create_pollset(switch_pollfd_t **poll, switch_socket_t *sock, int16_t flags, switch_memory_pool_t *pool)
Create a set of file descriptors to poll from a socket.
Definition: switch_apr.c:1032
switch_status_t switch_socket_close(switch_socket_t *sock)
Definition: switch_apr.c:714
#define SWITCH_UNSPEC
Definition: switch_apr.h:1022
switch_core_session_t * session
Definition: switch_rtp.c:446
#define SWITCH_SO_REUSEADDR
Definition: switch_apr.h:995
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_pollfd_t * rtcp_read_pollfd
Definition: switch_rtp.c:310
const char * switch_get_addr(char *buf, switch_size_t len, switch_sockaddr_t *in)
Definition: switch_apr.c:894
switch_port_t local_port
Definition: switch_rtp.c:397
switch_sockaddr_t * from_addr
Definition: switch_rtp.c:374
struct apr_socket_t switch_socket_t
Definition: switch_apr.h:1026
switch_status_t switch_sockaddr_info_get(switch_sockaddr_t **sa, const char *hostname, int32_t family, switch_port_t port, int32_t flags, switch_memory_pool_t *pool)
Definition: switch_apr.c:817
static switch_status_t enable_remote_rtcp_socket ( switch_rtp_t rtp_session,
const char **  err 
)
static

Definition at line 2478 of file switch_rtp.c.

References switch_rtp::eff_remote_host_str, switch_rtp::flags, switch_rtp::pool, switch_rtp::remote_rtcp_port, switch_rtp::rtcp_local_addr, switch_rtp::rtcp_remote_addr, switch_rtp::rtcp_sock_input, switch_rtp::rtcp_sock_output, switch_rtp::session, SWITCH_CHANNEL_SESSION_LOG, switch_get_addr(), SWITCH_LOG_DEBUG, switch_log_printf(), SWITCH_RTP_FLAG_ENABLE_RTCP, switch_sockaddr_get_family(), switch_sockaddr_info_get(), switch_socket_close(), switch_socket_create(), SWITCH_STATUS_FALSE, SWITCH_STATUS_SUCCESS, and SWITCH_UNSPEC.

Referenced by switch_rtp_activate_rtcp(), and switch_rtp_set_remote_address().

2478  {
2479 
2481 
2482  if (rtp_session->flags[SWITCH_RTP_FLAG_ENABLE_RTCP]) {
2483 
2485  rtp_session->remote_rtcp_port, 0, rtp_session->pool) != SWITCH_STATUS_SUCCESS || !rtp_session->rtcp_remote_addr) {
2486  *err = "RTCP Remote Address Error!";
2487  return SWITCH_STATUS_FALSE;
2488  } else {
2489  const char *host;
2490  char bufa[50];
2491 
2492  host = switch_get_addr(bufa, sizeof(bufa), rtp_session->rtcp_remote_addr);
2493 
2495  "Setting RTCP remote addr to %s:%d %d\n", host, rtp_session->remote_rtcp_port, rtp_session->rtcp_remote_addr->family);
2496  }
2497 
2498  if (rtp_session->rtcp_sock_input && switch_sockaddr_get_family(rtp_session->rtcp_remote_addr) ==
2500  rtp_session->rtcp_sock_output = rtp_session->rtcp_sock_input;
2501  } else {
2502 
2503  if (rtp_session->rtcp_sock_output && rtp_session->rtcp_sock_output != rtp_session->rtcp_sock_input) {
2504  switch_socket_close(rtp_session->rtcp_sock_output);
2505  }
2506 
2507  if ((status = switch_socket_create(&rtp_session->rtcp_sock_output,
2509  SOCK_DGRAM, 0, rtp_session->pool)) != SWITCH_STATUS_SUCCESS) {
2510  *err = "RTCP Socket Error!";
2511  }
2512  }
2513 
2514  } else {
2515  *err = "RTCP NOT ACTIVE!";
2516  }
2517 
2518  return status;
2519 
2520 }
#define SWITCH_CHANNEL_SESSION_LOG(x)
switch_sockaddr_t * rtcp_local_addr
Definition: switch_rtp.c:313
switch_port_t remote_rtcp_port
Definition: switch_rtp.c:400
switch_socket_t * rtcp_sock_input
Definition: switch_rtp.c:309
int32_t switch_sockaddr_get_family(switch_sockaddr_t *sa)
Definition: switch_apr.c:921
uint32_t flags[SWITCH_RTP_FLAG_INVALID]
Definition: switch_rtp.c:372
switch_memory_pool_t * pool
Definition: switch_rtp.c:373
switch_socket_t * rtcp_sock_output
Definition: switch_rtp.c:309
switch_status_t switch_socket_create(switch_socket_t **new_sock, int family, int type, int protocol, switch_memory_pool_t *pool)
Definition: switch_apr.c:704
switch_status_t
Common return values.
switch_status_t switch_socket_close(switch_socket_t *sock)
Definition: switch_apr.c:714
#define SWITCH_UNSPEC
Definition: switch_apr.h:1022
switch_core_session_t * session
Definition: switch_rtp.c:446
void switch_log_printf(_In_ switch_text_channel_t channel, _In_z_ const char *file, _In_z_ const char *func, _In_ int line, _In_opt_z_ const char *userdata, _In_ switch_log_level_t level, _In_z_ _Printf_format_string_ const char *fmt,...) PRINTF_FUNCTION(7
Write log data to the logging engine.
const char * switch_get_addr(char *buf, switch_size_t len, switch_sockaddr_t *in)
Definition: switch_apr.c:894
switch_sockaddr_t * rtcp_remote_addr
Definition: switch_rtp.c:326
switch_status_t switch_sockaddr_info_get(switch_sockaddr_t **sa, const char *hostname, int32_t family, switch_port_t port, int32_t flags, switch_memory_pool_t *pool)
Definition: switch_apr.c:817
char * eff_remote_host_str
Definition: switch_rtp.c:382
static void free_dtls ( switch_dtls_t **  dtlsp)
static

Definition at line 3124 of file switch_rtp.c.

References switch_dtls_s::ssl, and switch_dtls_s::ssl_ctx.

Referenced by switch_rtp_del_dtls(), and switch_rtp_destroy().

3125 {
3126  switch_dtls_t *dtls;
3127 
3128  if (!dtlsp) {
3129  return;
3130  }
3131 
3132  dtls = *dtlsp;
3133  *dtlsp = NULL;
3134 
3135  if (dtls->ssl) {
3136  SSL_free(dtls->ssl);
3137  }
3138 
3139  if (dtls->ssl_ctx) {
3140  SSL_CTX_free(dtls->ssl_ctx);
3141  }
3142 }
SSL_CTX * ssl_ctx
Definition: switch_rtp.c:262
static uint8_t get_next_write_ts ( switch_rtp_t rtp_session,
uint32_t  timestamp 
)
static

Definition at line 1490 of file switch_rtp.c.

References switch_rtp::last_write_ts, RTP_BUG_NEVER_SEND_MARKER, RTP_BUG_SEND_LINEAR_TIMESTAMPS, switch_rtp::rtp_bugs, switch_timer::samplecount, switch_rtp::samples_per_interval, SWITCH_RTP_FLAG_USE_TIMER, switch_rtp_test_flag(), switch_rtp::timer, and switch_rtp::ts.

Referenced by check_rtcp_and_ice(), and rtp_common_write().

1491 {
1492  uint8_t m = 0;
1493 
1494  if (rtp_session->rtp_bugs & RTP_BUG_SEND_LINEAR_TIMESTAMPS) {
1495  rtp_session->ts += rtp_session->samples_per_interval;
1496  if (rtp_session->ts <= rtp_session->last_write_ts && rtp_session->ts > 0) {
1497  rtp_session->ts = rtp_session->last_write_ts + rtp_session->samples_per_interval;
1498  }
1499  } else if (timestamp) {
1500  rtp_session->ts = (uint32_t) timestamp;
1501  /* Send marker bit if timestamp is lower/same as before (resetted/new timer) */
1502  if (rtp_session->ts <= rtp_session->last_write_ts && !(rtp_session->rtp_bugs & RTP_BUG_NEVER_SEND_MARKER)) {
1503  m++;
1504  }
1505  } else if (switch_rtp_test_flag(rtp_session, SWITCH_RTP_FLAG_USE_TIMER)) {
1506  rtp_session->ts = rtp_session->timer.samplecount;
1507 
1508  if (rtp_session->ts <= rtp_session->last_write_ts && rtp_session->ts > 0) {
1509  rtp_session->ts = rtp_session->last_write_ts + rtp_session->samples_per_interval;
1510  }
1511  } else {
1512  rtp_session->ts += rtp_session->samples_per_interval;
1513  if (rtp_session->ts <= rtp_session->last_write_ts && rtp_session->ts > 0) {
1514  rtp_session->ts = rtp_session->last_write_ts + rtp_session->samples_per_interval;
1515  }
1516  }
1517 
1518  return m;
1519 }
uint32_t ts
Definition: switch_rtp.c:362
uint32_t samples_per_interval
Definition: switch_rtp.c:386
switch_timer_t timer
Definition: switch_rtp.c:411
uint32_t last_write_ts
Definition: switch_rtp.c:363
switch_rtp_bug_flag_t rtp_bugs
Definition: switch_rtp.c:427
uint32_t switch_rtp_test_flag(switch_rtp_t *rtp_session, switch_rtp_flag_t flags)
Test an RTP Flag.
Definition: switch_rtp.c:4742
static int get_recv_payload ( switch_rtp_t rtp_session)
static

Definition at line 5110 of file switch_rtp.c.

References payload_map_s::allocated, switch_rtp::flag_mutex, payload_map_s::negotiated, payload_map_s::next, switch_rtp::pmaps, payload_map_s::pt, switch_mutex_lock(), and switch_mutex_unlock().

Referenced by read_rtp_packet().

5111 {
5112  int r = -1;
5113 
5114  if (rtp_session->pmaps && *rtp_session->pmaps) {
5115  payload_map_t *pmap;
5116 
5117  switch_mutex_lock(rtp_session->flag_mutex);
5118 
5119  for (pmap = *rtp_session->pmaps; pmap && pmap->allocated; pmap = pmap->next) {
5120  if (pmap->negotiated) {
5121  r = pmap->pt;
5122  break;
5123  }
5124  }
5125  switch_mutex_unlock(rtp_session->flag_mutex);
5126  }
5127 
5128  return r;
5129 }
uint8_t allocated
switch_mutex_t * flag_mutex
Definition: switch_rtp.c:407
struct payload_map_s * next
switch_status_t switch_mutex_unlock(switch_mutex_t *lock)
Definition: switch_apr.c:290
switch_status_t switch_mutex_lock(switch_mutex_t *lock)
Definition: switch_apr.c:285
uint8_t negotiated
switch_payload_t pt
payload_map_t ** pmaps
Definition: switch_rtp.c:447
static void handle_ice ( switch_rtp_t rtp_session,
switch_rtp_ice_t ice,
void *  data,
switch_size_t  len 
)
static

Definition at line 865 of file switch_rtp.c.

References switch_rtp_ice_t::addr, switch_rtp::auto_adj_used, buf, ice_s::cand_idx, icand_s::cand_type, ice_s::cands, ice_s::chosen, switch_stun_error_code_t::code, icand_s::con_addr, icand_s::con_port, DS_READY, switch_rtp::dtls, switch_rtp::first_stun, switch_rtp::flags, switch_core_session_message::from, switch_rtp::from_addr, switch_stun_packet_t::header, switch_rtp::ice, switch_rtp::ice_adj, ICE_CONTROLLED, ICE_GOOGLE_JINGLE, switch_rtp::ice_mutex, switch_rtp_ice_t::ice_params, switch_rtp_ice_t::ice_user, ICE_VANILLA, icecmp(), switch_stun_packet_header_t::id, IPR_RTP, switch_rtp_ice_t::last_ok, switch_rtp_ice_t::last_sent_id, switch_rtp::last_stun, switch_stun_packet_header_t::length, memset(), switch_core_session_message::message_id, switch_rtp_ice_t::missed_count, switch_stun_error_code_t::number, switch_core_session_message::numeric_arg, switch_rtp_ice_t::pass, switch_core_session_message::pointer_arg, switch_rtp::pool, icand_s::priority, switch_rtp_ice_t::proto, READ_DEC, READ_INC, switch_rtp_ice_t::ready, switch_stun_error_code_t::reason, switch_rtp::remote_addr, switch_rtp::remote_port, switch_rtp_ice_t::rready, switch_rtp::rtcp_from_addr, switch_rtp::rtcp_ice, switch_rtp::rtcp_sock_output, RTP_BUG_ALWAYS_AUTO_ADJUST, switch_rtp::rtp_bugs, rtp_session_name, rtp_type, switch_rtp::session, switch_rtp::sock_output, switch_dtls_s::state, switch_channel_get_variable, SWITCH_CHANNEL_SESSION_LOG, switch_channel_set_variable, switch_cmp_addr(), switch_core_session_get_channel(), switch_core_session_receive_message, switch_core_session_video_reinit(), SWITCH_FALSE, switch_get_addr(), SWITCH_LOG_DEBUG, SWITCH_LOG_DEBUG4, SWITCH_LOG_DEBUG8, SWITCH_LOG_ERROR, SWITCH_LOG_INFO, SWITCH_LOG_NOTICE, switch_log_printf(), SWITCH_LOG_WARNING, SWITCH_MESSAGE_INDICATE_STUN_ERROR, switch_micro_time_now(), switch_mutex_lock(), switch_mutex_unlock(), switch_rtp_change_ice_dest(), switch_rtp_clear_flag(), SWITCH_RTP_FLAG_AUTOADJ, SWITCH_RTP_FLAG_RTCP_MUX, SWITCH_RTP_FLAG_VIDEO, switch_rtp_ready(), switch_rtp_set_flag(), switch_rtp_set_remote_address(), switch_snprintf(), switch_sockaddr_get_port(), switch_sockaddr_info_get(), switch_socket_sendto(), SWITCH_STATUS_SUCCESS, SWITCH_STUN_ATTR_ERROR_CODE, SWITCH_STUN_ATTR_MAPPED_ADDRESS, SWITCH_STUN_ATTR_PRIORITY, SWITCH_STUN_ATTR_USE_CAND, SWITCH_STUN_ATTR_USERNAME, SWITCH_STUN_ATTR_XOR_MAPPED_ADDRESS, switch_stun_attribute_padded_length, SWITCH_STUN_BINDING_ERROR_RESPONSE, SWITCH_STUN_BINDING_REQUEST, SWITCH_STUN_BINDING_RESPONSE, switch_stun_packet_attribute_add_fingerprint(), switch_stun_packet_attribute_add_integrity(), switch_stun_packet_attribute_add_username(), switch_stun_packet_attribute_add_xor_binded_address(), switch_stun_packet_attribute_get_mapped_address(), switch_stun_packet_attribute_get_username(), switch_stun_packet_attribute_get_xor_mapped_address(), switch_stun_packet_build_header(), switch_stun_packet_first_attribute, switch_stun_packet_length, switch_stun_packet_next_attribute, switch_stun_packet_parse(), SWITCH_STUN_TYPE_ATTRIBUTE, SWITCH_STUN_TYPE_PACKET_TYPE, switch_stun_value_to_name(), SWITCH_UNSPEC, switch_stun_packet_header_t::type, switch_stun_packet_attribute_t::type, switch_rtp_ice_t::type, switch_rtp_ice_t::user_ice, switch_stun_packet_attribute_t::value, WRITE_DEC, WRITE_INC, switch_rtp::wrong_addrs, and zstr.

Referenced by process_rtcp_packet(), read_rtcp_packet(), and read_rtp_packet().

866 {
867  switch_stun_packet_t *packet;
869  void *end_buf;
870  char username[34] = { 0 };
871  unsigned char buf[512] = { 0 };
872  switch_size_t cpylen = len;
873  int xlen = 0;
874  int ok = 1;
875  uint32_t *pri = NULL;
876  int is_rtcp = ice == &rtp_session->rtcp_ice;
877  uint32_t elapsed;
878  switch_time_t ref_point;
879 
880  //if (rtp_session->flags[SWITCH_RTP_FLAG_VIDEO]) {
881  // switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(rtp_session->session), SWITCH_LOG_WARNING, "WTF OK %s CALL\n", rtp_type(rtp_session));
882  //}
883 
884  if (!switch_rtp_ready(rtp_session) || zstr(ice->user_ice) || zstr(ice->ice_user)) {
885  return;
886  }
887 
888  switch_mutex_lock(rtp_session->ice_mutex);
889 
890  READ_INC(rtp_session);
891  WRITE_INC(rtp_session);
892 
893  if (!switch_rtp_ready(rtp_session)) {
894  goto end;
895  }
896 
897  if (cpylen > sizeof(buf)) {
898  cpylen = sizeof(buf);
899  }
900 
901 
902  memcpy(buf, data, cpylen);
903  packet = switch_stun_packet_parse(buf, (uint32_t)cpylen);
904  if (!packet) {
905  switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(rtp_session->session), SWITCH_LOG_ERROR, "Invalid STUN/ICE packet received %ld bytes\n", (long)cpylen);
906  goto end;
907 
908  }
909 
910  rtp_session->last_stun = switch_micro_time_now();
911 
912  if (!rtp_session->first_stun) {
913  rtp_session->first_stun = rtp_session->last_stun;
914  }
915 
916  if (ice->last_ok) {
917  ref_point = ice->last_ok;
918  } else {
919  ref_point = rtp_session->first_stun;
920  }
921 
922  elapsed = (unsigned int) ((switch_micro_time_now() - ref_point) / 1000);
923 
924 
925  end_buf = buf + ((sizeof(buf) > packet->header.length) ? packet->header.length : sizeof(buf));
926 
928  switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(rtp_session->session), SWITCH_LOG_DEBUG8, "%s STUN PACKET TYPE: %s\n",
930  do {
931  switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(rtp_session->session), SWITCH_LOG_DEBUG8, "|---: %s STUN ATTR %d %x %s\n", rtp_type(rtp_session), attr->type, attr->type,
933 
934  switch (attr->type) {
936  {
937  ice->rready = 1;
938  }
939  break;
941  {
943  uint32_t code = (err->code * 100) + err->number;
944 
945  switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(rtp_session->session), SWITCH_LOG_WARNING, "%s got %s stun binding response %u %s\n",
946  rtp_session_name(rtp_session),
947  rtp_type(rtp_session),
948  code,
949  err->reason
950  );
951 
952  if ((ice->type & ICE_VANILLA) && code == 487) {
953  if ((ice->type & ICE_CONTROLLED)) {
954  switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(rtp_session->session), SWITCH_LOG_WARNING, "%s STUN Changing role to CONTROLLING\n", rtp_type(rtp_session));
955  ice->type &= ~ICE_CONTROLLED;
956  } else {
957  switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(rtp_session->session), SWITCH_LOG_WARNING, "%s STUN Changing role to CONTROLLED\n", rtp_type(rtp_session));
958  ice->type |= ICE_CONTROLLED;
959  }
961  }
962 
963  }
964  break;
966  if (attr->type) {
967  char ip[50];
968  uint16_t port;
969  switch_stun_packet_attribute_get_mapped_address(attr, ip, sizeof(ip), &port);
970  switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(rtp_session->session), SWITCH_LOG_DEBUG8, "|------: %s:%d\n", ip, port);
971  }
972  break;
974  if (attr->type) {
975  char ip[50];
976  uint16_t port;
977  switch_stun_packet_attribute_get_xor_mapped_address(attr, &packet->header, ip, sizeof(ip), &port);
978  switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(rtp_session->session), SWITCH_LOG_DEBUG8, "|------: %s:%d\n", ip, port);
979  }
980  break;
982  if (attr->type) {
983  switch_stun_packet_attribute_get_username(attr, username, sizeof(username));
984  switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(rtp_session->session), SWITCH_LOG_DEBUG8, "|------: %s\n", username);
985  }
986  break;
987 
989  {
990  uint32_t priority = 0;
991  pri = (uint32_t *) attr->value;
992  priority = ntohl(*pri);
993  switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(rtp_session->session), SWITCH_LOG_DEBUG8, "|------: %u\n", priority);
994  ok = priority == ice->ice_params->cands[ice->ice_params->chosen[ice->proto]][ice->proto].priority;
995  }
996  break;
997  }
998 
999  if (!switch_stun_packet_next_attribute(attr, end_buf)) {
1000  break;
1001  }
1002 
1003  xlen += 4 + switch_stun_attribute_padded_length(attr);
1004  } while (xlen <= packet->header.length);
1005 
1006  if ((ice->type & ICE_GOOGLE_JINGLE) && ok) {
1007  ok = !strcmp(ice->user_ice, username);
1008  }
1009 
1011  goto end;
1012  }
1013 
1014  if ((ice->type & ICE_VANILLA)) {
1015  char foo1[13] = "", foo2[13] = "";
1016  if (!ok) ok = !memcmp(packet->header.id, ice->last_sent_id, 12);
1017 
1018  if (packet->header.type == SWITCH_STUN_BINDING_RESPONSE) {
1019  ok = 1;
1020  if (!ice->rready) {
1021  if (rtp_session->flags[SWITCH_RTP_FLAG_RTCP_MUX]) {
1022  rtp_session->ice.rready = 1;
1023  rtp_session->rtcp_ice.rready = 1;
1024  } else {
1025  ice->rready = 1;
1026  }
1027 
1028  if (rtp_session->flags[SWITCH_RTP_FLAG_VIDEO]) {
1030  }
1031  }
1032  }
1033 
1034  memcpy(foo1, packet->header.id, 12);
1035  memcpy(foo2, ice->last_sent_id, 12);
1036 
1037  if (!ok && ice == &rtp_session->ice && rtp_session->rtcp_ice.ice_params && pri &&
1038  *pri == rtp_session->rtcp_ice.ice_params->cands[rtp_session->rtcp_ice.ice_params->chosen[1]][1].priority) {
1039  ice = &rtp_session->rtcp_ice;
1040  ok = 1;
1041  }
1042 
1043  if (!zstr(username)) {
1044  if (!icecmp(username, ice)) {
1045  ok = 1;
1046  } else if(!zstr(rtp_session->rtcp_ice.user_ice) && !icecmp(username, &rtp_session->rtcp_ice)) {
1047  ice = &rtp_session->rtcp_ice;
1048  ok = 1;
1049  }
1050  }
1051 
1052  if (ok) {
1053  ice->missed_count = 0;
1054  } else {
1055  switch_rtp_ice_t *icep[2] = { &rtp_session->ice, &rtp_session->rtcp_ice };
1056  switch_port_t port = 0;
1057  char *host = NULL;
1058 
1059  if (elapsed > 20000 && pri) {
1060  int i, j;
1061  uint32_t old;
1062  //const char *tx_host;
1063  const char *old_host, *err = NULL;
1064  //char bufa[50];
1065  char bufb[50];
1066  char adj_port[6];
1067  switch_channel_t *channel = NULL;
1068 
1069 
1070  ice->missed_count++;
1072 
1073 
1074  if (rtp_session->session) {
1075  channel = switch_core_session_get_channel(rtp_session->session);
1076  }
1077 
1078  //ice->ice_params->cands[ice->ice_params->chosen][ice->proto].priority;
1079  for (j = 0; j < 2; j++) {
1080  if (!icep[j] || !icep[j]->ice_params) {
1081  continue;
1082  }
1083  for (i = 0; i < icep[j]->ice_params->cand_idx[icep[j]->proto]; i++) {
1084  if (icep[j]->ice_params && icep[j]->ice_params->cands[i][icep[j]->proto].priority == *pri) {
1085  if (j == IPR_RTP) {
1086  icep[j]->ice_params->chosen[j] = i;
1087  switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(rtp_session->session), SWITCH_LOG_INFO, "Change candidate index to %d\n", i);
1088  }
1089 
1090  ice = icep[j];
1091  ok = 1;
1092 
1093  if (j != IPR_RTP) {
1094  break;
1095  }
1096 
1097  old = rtp_session->remote_port;
1098 
1099  //tx_host = switch_get_addr(bufa, sizeof(bufa), rtp_session->from_addr);
1100  old_host = switch_get_addr(bufb, sizeof(bufb), rtp_session->remote_addr);
1101 
1102  host = ice->ice_params->cands[ice->ice_params->chosen[ice->proto]][ice->proto].con_addr;
1103  port = ice->ice_params->cands[ice->ice_params->chosen[ice->proto]][ice->proto].con_port;
1104 
1105  if (!host || !port) {
1106  switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(rtp_session->session), SWITCH_LOG_ERROR, "Error setting remote host!\n");
1107  return;
1108  }
1109 
1111  "%s ICE Auto Changing port from %s:%u to %s:%u\n", rtp_type(rtp_session), old_host, old, host, port);
1112 
1113 
1114  if (channel) {
1115  switch_channel_set_variable(channel, "remote_media_ip_reported", switch_channel_get_variable(channel, "remote_media_ip"));
1116  switch_channel_set_variable(channel, "remote_media_ip", host);
1117  switch_channel_set_variable(channel, "rtp_auto_adjust_ip", host);
1118  switch_snprintf(adj_port, sizeof(adj_port), "%u", port);
1119  switch_channel_set_variable(channel, "remote_media_port_reported", switch_channel_get_variable(channel, "remote_media_port"));
1120  switch_channel_set_variable(channel, "remote_media_port", adj_port);
1121  switch_channel_set_variable(channel, "rtp_auto_adjust_port", adj_port);
1122  switch_channel_set_variable(channel, "rtp_auto_candidate_adjust", "true");
1123  }
1124  rtp_session->auto_adj_used = 1;
1125 
1126 
1127  switch_rtp_set_remote_address(rtp_session, host, port, 0, SWITCH_FALSE, &err);
1128  if (switch_sockaddr_info_get(&ice->addr, host, SWITCH_UNSPEC, port, 0, rtp_session->pool) != SWITCH_STATUS_SUCCESS ||
1129  !ice->addr) {
1130  switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(rtp_session->session), SWITCH_LOG_ERROR, "Error setting remote host!\n");
1131  return;
1132  }
1133 
1134  if ((rtp_session->rtp_bugs & RTP_BUG_ALWAYS_AUTO_ADJUST)) {
1136  } else {
1138  }
1139 
1140  }
1141  }
1142  }
1143  }
1144  }
1145  }
1146 
1147  if (ice->missed_count > 5 && !(ice->type & ICE_GOOGLE_JINGLE)) {
1148  switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(rtp_session->session), SWITCH_LOG_WARNING, "missed too many: %d, looking for new ICE dest.\n",
1149  ice->missed_count);
1150  ice->rready = 0;
1151  ok = 1;
1152  }
1153 
1154 
1155  //if (rtp_session->flags[SWITCH_RTP_FLAG_VIDEO] || 1) {
1156  // switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(rtp_session->session), SWITCH_LOG_WARNING, "WTF OK %s %d\n", rtp_type(rtp_session), ok);
1157  //}
1158 
1159  if (ok) {
1160  const char *host = NULL, *host2 = NULL;
1161  switch_port_t port = 0, port2 = 0;
1162  char buf[80] = "";
1163  char buf2[80] = "";
1164 
1165  if (packet->header.type == SWITCH_STUN_BINDING_REQUEST) {
1166  uint8_t stunbuf[512];
1167  switch_stun_packet_t *rpacket;
1168  const char *remote_ip;
1169  switch_size_t bytes;
1170  char ipbuf[50];
1171  switch_sockaddr_t *from_addr = rtp_session->from_addr;
1172  switch_socket_t *sock_output = rtp_session->sock_output;
1173  uint8_t do_adj = 0;
1175  int cmp = 0;
1176 
1177  if (is_rtcp) {
1178  from_addr = rtp_session->rtcp_from_addr;
1179  sock_output = rtp_session->rtcp_sock_output;
1180  }
1181 
1182  if (!ice->ready) {
1183  ice->ready = 1;
1184  }
1185 
1186  memset(stunbuf, 0, sizeof(stunbuf));
1188 
1189  if ((ice->type & ICE_GOOGLE_JINGLE)) {
1190  switch_stun_packet_attribute_add_username(rpacket, username, (uint16_t)strlen(username));
1191  }
1192 
1193  remote_ip = switch_get_addr(ipbuf, sizeof(ipbuf), from_addr);
1194 
1195  switch_stun_packet_attribute_add_xor_binded_address(rpacket, (char *) remote_ip, switch_sockaddr_get_port(from_addr), from_addr->family);
1196 
1197  if ((ice->type & ICE_VANILLA)) {
1200  }
1201 
1202  bytes = switch_stun_packet_length(rpacket);
1203 
1204  host = switch_get_addr(buf, sizeof(buf), from_addr);
1205  port = switch_sockaddr_get_port(from_addr);
1206  host2 = switch_get_addr(buf2, sizeof(buf2), ice->addr);
1207  port2 = switch_sockaddr_get_port(ice->addr);
1208  cmp = switch_cmp_addr(from_addr, ice->addr);
1209 
1211  "STUN from %s:%d %s\n", host, port, cmp ? "EXPECTED" : "IGNORED");
1212 
1213  if (cmp) {
1214  ice->last_ok = now;
1215  rtp_session->wrong_addrs = 0;
1216  } else {
1217  if (((rtp_session->dtls && rtp_session->dtls->state != DS_READY) || !ice->ready || !ice->rready) &&
1218  rtp_session->wrong_addrs > 2 && rtp_session->ice_adj == 0) {
1219  do_adj++;
1220  rtp_session->ice_adj = 1;
1221  rtp_session->wrong_addrs = 0;
1222  } else if (rtp_session->wrong_addrs > 10 || elapsed >= 10000) {
1223  do_adj++;
1224  }
1225 
1226  if (!do_adj) {
1227  rtp_session->wrong_addrs++;
1228  }
1229  }
1230 
1231  if ((ice->type & ICE_VANILLA) && ice->ice_params && do_adj) {
1232  int i = 0;
1233 
1234  ice->missed_count = 0;
1235  ice->rready = 1;
1236 
1237  for (i = 0; i <= ice->ice_params->cand_idx[ice->proto]; i++) {
1238  if (ice->ice_params->cands[i][ice->proto].con_port == port) {
1239  if (!strcmp(ice->ice_params->cands[i][ice->proto].con_addr, host) &&
1240  !strcmp(ice->ice_params->cands[i][ice->proto].cand_type, "relay")) {
1241 
1242  if (elapsed < 1000) {
1244  "Skiping RELAY stun/%s/dtls port change from %s:%u to %s:%u\n", is_rtcp ? "rtcp" : "rtp",
1245  host2, port2,
1246  host, port);
1247 
1248  goto end;
1249  }
1250 
1251  break;
1252  }
1253  }
1254  }
1255 
1257  "Auto Changing %s stun/%s/dtls port from %s:%u to %s:%u\n", rtp_type(rtp_session), is_rtcp ? "rtcp" : "rtp",
1258  host2, port2,
1259  host, port);
1260 
1261  switch_rtp_change_ice_dest(rtp_session, ice, host, port);
1262  ice->last_ok = now;
1263  rtp_session->wrong_addrs = 0;
1264  }
1265  if (cmp) {
1266  switch_socket_sendto(sock_output, from_addr, 0, (void *) rpacket, &bytes);
1267  }
1268  }
1269  } else if (packet->header.type == SWITCH_STUN_BINDING_ERROR_RESPONSE) {
1270 
1271  if (rtp_session->session) {
1272  switch_core_session_message_t msg = { 0 };
1273  msg.from = __FILE__;
1274  msg.numeric_arg = packet->header.type;
1275  msg.pointer_arg = packet;
1277  switch_core_session_receive_message(rtp_session->session, &msg);
1279  "STUN/ICE binding error received on %s channel\n", rtp_session->flags[SWITCH_RTP_FLAG_VIDEO] ? "video" : "audio");
1280  }
1281 
1282  }
1283 
1284 
1285 
1286 
1287  end:
1288  switch_mutex_unlock(rtp_session->ice_mutex);
1289  READ_DEC(rtp_session);
1290  WRITE_DEC(rtp_session);
1291 }
switch_time_t switch_micro_time_now(void)
Get the current epoch time in microseconds.
Definition: switch_time.c:310
int cand_idx[2]
Definition: switch_rtp.h:106
#define SWITCH_CHANNEL_SESSION_LOG(x)
uint16_t switch_sockaddr_get_port(switch_sockaddr_t *sa)
Definition: switch_apr.c:916
uint8_t switch_rtp_ready(switch_rtp_t *rtp_session)
Test if an RTP session is ready.
Definition: switch_rtp.c:4452
switch_sockaddr_t * rtcp_from_addr
Definition: switch_rtp.c:374
switch_core_session_message_types_t message_id
Definition: switch_core.h:181
uint8_t switch_stun_packet_attribute_add_fingerprint(switch_stun_packet_t *packet)
Definition: switch_stun.c:552
switch_sockaddr_t * remote_addr
Definition: switch_rtp.c:326
int chosen[2]
Definition: switch_rtp.h:107
switch_sockaddr_t * addr
Definition: switch_rtp.c:244
#define WRITE_INC(rtp_session)
Definition: switch_rtp.c:62
switch_port_t remote_port
Definition: switch_rtp.c:398
ice_t * ice_params
Definition: switch_rtp.c:248
switch_time_t last_ok
Definition: switch_rtp.c:255
#define rtp_session_name(_rtp_session)
Definition: switch_rtp.c:79
int switch_snprintf(_Out_z_cap_(len) char *buf, _In_ switch_size_t len, _In_z_ _Printf_format_string_ const char *format,...)
#define READ_DEC(rtp_session)
Definition: switch_rtp.c:61
switch_stun_packet_t * switch_stun_packet_build_header(switch_stun_message_t type, char *id, uint8_t *buf)
Prepare a new outbound packet of a certian type and id.
Definition: switch_stun.c:431
A message object designed to allow unlike technologies to exchange data.
Definition: switch_core.h:177
#define zstr(x)
Definition: switch_utils.h:281
dtls_state_t state
Definition: switch_rtp.c:268
int switch_cmp_addr(switch_sockaddr_t *sa1, switch_sockaddr_t *sa2)
#define rtp_type(rtp_session)
Definition: switch_rtp.c:513
switch_status_t switch_mutex_unlock(switch_mutex_t *lock)
Definition: switch_apr.c:290
_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.
uint8_t switch_stun_packet_attribute_add_username(switch_stun_packet_t *packet, char *username, uint16_t ulen)
Add a username packet attribute.
Definition: switch_stun.c:616
int64_t switch_time_t
Definition: switch_apr.h:188
switch_core_media_ice_type_t type
Definition: switch_rtp.c:247
switch_byte_t switch_byte_t * buf
#define WRITE_DEC(rtp_session)
Definition: switch_rtp.c:63
int icecmp(const char *them, switch_rtp_ice_t *ice)
Definition: switch_rtp.c:856
switch_status_t switch_socket_sendto(switch_socket_t *sock, switch_sockaddr_t *where, int32_t flags, const char *buf, switch_size_t *len)
Definition: switch_apr.c:773
struct apr_sockaddr_t switch_sockaddr_t
Definition: switch_apr.h:1029
switch_status_t switch_mutex_lock(switch_mutex_t *lock)
Definition: switch_apr.c:285
uint32_t flags[SWITCH_RTP_FLAG_INVALID]
Definition: switch_rtp.c:372
#define switch_stun_packet_first_attribute(packet, attribute)
set a switch_stun_packet_attribute_t pointer to point at the first attribute in a packet ...
Definition: switch_stun.h:277
#define switch_channel_get_variable(_c, _v)
#define switch_stun_attribute_padded_length(attribute)
Obtain the padded length of an attribute's value.
Definition: switch_stun.h:268
char * con_addr
Definition: switch_rtp.h:93
#define READ_INC(rtp_session)
Definition: switch_rtp.c:60
switch_byte_t auto_adj_used
Definition: switch_rtp.c:440
#define switch_stun_packet_length(packet)
Obtain the correct length in bytes of a stun packet.
Definition: switch_stun.h:295
char last_sent_id[13]
Definition: switch_rtp.c:254
char * cand_type
Definition: switch_rtp.h:95
uintptr_t switch_size_t
uint16_t switch_port_t
switch_dtls_t * dtls
Definition: switch_rtp.c:348
switch_rtp_ice_t rtcp_ice
Definition: switch_rtp.c:378
switch_status_t switch_rtp_set_remote_address(switch_rtp_t *rtp_session, const char *host, switch_port_t port, switch_port_t remote_rtcp_port, switch_bool_t change_adv_addr, const char **err)
Assign a remote address to the RTP session.
Definition: switch_rtp.c:2913
#define switch_core_session_receive_message(_session, _message)
Definition: switch_core.h:1217
switch_memory_pool_t * pool
Definition: switch_rtp.c:373
switch_socket_t * rtcp_sock_output
Definition: switch_rtp.c:309
void switch_rtp_clear_flag(switch_rtp_t *rtp_session, switch_rtp_flag_t flag)
Clear an RTP Flag.
Definition: switch_rtp.c:4747
switch_stun_packet_header_t header
Definition: switch_stun.h:133
#define switch_stun_packet_next_attribute(attribute, end)
Increment an attribute pointer to the next attribute in it's packet.
Definition: switch_stun.h:286
void switch_rtp_set_flag(switch_rtp_t *rtp_session, switch_rtp_flag_t flag)
Set an RTP Flag.
Definition: switch_rtp.c:4702
char * switch_stun_packet_attribute_get_username(switch_stun_packet_attribute_t *attribute, char *username, uint16_t len)
Extract a username from a packet attribute.
Definition: switch_stun.c:423
ice_proto_t proto
Definition: switch_rtp.c:249
#define SWITCH_UNSPEC
Definition: switch_apr.h:1022
uint8_t switch_stun_packet_attribute_get_xor_mapped_address(switch_stun_packet_attribute_t *attribute, switch_stun_packet_header_t *header, char *ipstr, switch_size_t iplen, uint16_t *port)
Definition: switch_stun.c:394
switch_mutex_t * ice_mutex
Definition: switch_rtp.c:410
void switch_core_session_video_reinit(switch_core_session_t *session)
switch_core_session_t * session
Definition: switch_rtp.c:446
switch_stun_packet_t * switch_stun_packet_parse(uint8_t *buf, uint32_t len)
Prepare a raw packet for parsing.
Definition: switch_stun.c:144
switch_rtp_ice_t ice
Definition: switch_rtp.c:377
switch_rtp_bug_flag_t rtp_bugs
Definition: switch_rtp.c:427
icand_t cands[MAX_CAND][2]
Definition: switch_rtp.h:105
void switch_log_printf(_In_ switch_text_channel_t channel, _In_z_ const char *file, _In_z_ const char *func, _In_ int line, _In_opt_z_ const char *userdata, _In_ switch_log_level_t level, _In_z_ _Printf_format_string_ const char *fmt,...) PRINTF_FUNCTION(7
Write log data to the logging engine.
uint8_t switch_stun_packet_attribute_add_xor_binded_address(switch_stun_packet_t *packet, char *ipstr, uint16_t port, int family)
Definition: switch_stun.c:485
uint32_t priority
Definition: switch_rtp.h:92
const char * switch_get_addr(char *buf, switch_size_t len, switch_sockaddr_t *in)
Definition: switch_apr.c:894
const char * switch_stun_value_to_name(int32_t type, uint32_t value)
Obtain a printable string form of a given value.
Definition: switch_stun.c:347
switch_time_t last_stun
Definition: switch_rtp.c:384
switch_sockaddr_t * from_addr
Definition: switch_rtp.c:374
struct apr_socket_t switch_socket_t
Definition: switch_apr.h:1026
switch_time_t first_stun
Definition: switch_rtp.c:383
#define switch_channel_set_variable(_channel, _var, _val)
switch_status_t switch_sockaddr_info_get(switch_sockaddr_t **sa, const char *hostname, int32_t family, switch_port_t port, int32_t flags, switch_memory_pool_t *pool)
Definition: switch_apr.c:817
static void switch_rtp_change_ice_dest(switch_rtp_t *rtp_session, switch_rtp_ice_t *ice, const char *host, switch_port_t port)
Definition: switch_rtp.c:516
uint8_t switch_stun_packet_attribute_get_mapped_address(switch_stun_packet_attribute_t *attribute, char *ipstr, switch_size_t iplen, uint16_t *port)
Extract a mapped address (IP:PORT) from a packet attribute.
Definition: switch_stun.c:377
uint32_t wrong_addrs
Definition: switch_rtp.c:385
memset(buf, 0, buflen)
switch_socket_t * sock_output
Definition: switch_rtp.c:309
uint8_t switch_stun_packet_attribute_add_integrity(switch_stun_packet_t *packet, const char *pass)
Definition: switch_stun.c:535
switch_port_t con_port
Definition: switch_rtp.h:94
static void handle_nack ( switch_rtp_t rtp_session,
uint32_t  nack 
)
static

Definition at line 5763 of file switch_rtp.c.

References switch_rtp::flags, rtp_msg_t::header, switch_rtp::local_addr, switch_rtp::remote_addr, switch_rtp::remote_port, switch_rtp::rtcp_from_addr, switch_rtp::session, switch_channel_get_name(), SWITCH_CHANNEL_SESSION_LOG, SWITCH_CHANNEL_SESSION_LOG_CLEAN, switch_core_media_gen_key_frame, switch_core_session_get_channel(), SWITCH_FALSE, switch_get_addr(), switch_jb_get_packet_by_seq(), SWITCH_LOG_CONSOLE, SWITCH_LOG_DEBUG1, switch_log_printf(), SWITCH_RTP_FLAG_DEBUG_RTP_WRITE, SWITCH_RTP_FLAG_NACK, switch_rtp_write_raw(), switch_sockaddr_get_port(), SWITCH_STATUS_SUCCESS, and switch_rtp::vbw.

Referenced by process_rtcp_report().

5764 {
5765  switch_size_t bytes = 0;
5766  rtp_msg_t send_msg[1] = {{{0}}};
5767  uint16_t seq = (uint16_t) (nack & 0xFFFF);
5768  uint16_t blp = (uint16_t) (nack >> 16);
5769  int i;
5770  const char *tx_host = NULL;
5771  const char *old_host = NULL;
5772  const char *my_host = NULL;
5773  char bufa[50], bufb[50], bufc[50];
5774 
5775  if (!(rtp_session->flags[SWITCH_RTP_FLAG_NACK] && rtp_session->vbw)) {
5776  return; /* not enabled */
5777  }
5778 
5779  if (rtp_session->flags[SWITCH_RTP_FLAG_DEBUG_RTP_WRITE]) {
5780  tx_host = switch_get_addr(bufa, sizeof(bufa), rtp_session->rtcp_from_addr);
5781  old_host = switch_get_addr(bufb, sizeof(bufb), rtp_session->remote_addr);
5782  my_host = switch_get_addr(bufc, sizeof(bufc), rtp_session->local_addr);
5783  }
5784 
5785  switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(rtp_session->session), SWITCH_LOG_DEBUG1, "Got NACK [%u][0x%x] for seq %u\n", nack, nack, ntohs(seq));
5786 
5787  if (switch_jb_get_packet_by_seq(rtp_session->vbw, seq, (switch_rtp_packet_t *) send_msg, &bytes) == SWITCH_STATUS_SUCCESS) {
5788 
5789  if (rtp_session->flags[SWITCH_RTP_FLAG_DEBUG_RTP_WRITE]) {
5791  "X %s b=%4ld %s:%u %s:%u %s:%u pt=%d ts=%u seq=%u m=%d\n",
5792  rtp_session->session ? switch_channel_get_name(switch_core_session_get_channel(rtp_session->session)) : "NoName",
5793  (long) bytes,
5794  my_host, switch_sockaddr_get_port(rtp_session->local_addr),
5795  old_host, rtp_session->remote_port,
5796  tx_host, switch_sockaddr_get_port(rtp_session->rtcp_from_addr),
5797  send_msg->header.pt, ntohl(send_msg->header.ts), ntohs(send_msg->header.seq), send_msg->header.m);
5798 
5799  }
5800  //switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_WARNING, "RE----SEND %u\n", ntohs(send_msg->header.seq));
5801  switch_rtp_write_raw(rtp_session, (void *) send_msg, &bytes, SWITCH_FALSE);
5802  } else {
5803  switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(rtp_session->session), SWITCH_LOG_DEBUG1, "Cannot send NACK for seq %u\n", ntohs(seq));
5804  }
5805 
5806  blp = ntohs(blp);
5807  for (i = 0; i < 16; i++) {
5808  if (blp & (1 << i)) {
5809  switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(rtp_session->session), SWITCH_LOG_DEBUG1, "Also Got NACK for seq %u\n", ntohs(seq) + i + 1);
5810  /* If they are missing more than one, may as well gen a key frame for good measure */
5812  if (switch_jb_get_packet_by_seq(rtp_session->vbw, htons(ntohs(seq) + i + 1), (switch_rtp_packet_t *) &send_msg, &bytes) == SWITCH_STATUS_SUCCESS) {
5813  if (rtp_session->flags[SWITCH_RTP_FLAG_DEBUG_RTP_WRITE]) {
5815  "X %s b=%4ld %s:%u %s:%u %s:%u pt=%d ts=%u seq=%u m=%d\n",
5816  rtp_session->session ? switch_channel_get_name(switch_core_session_get_channel(rtp_session->session)) : "NoName",
5817  (long) bytes,
5818  my_host, switch_sockaddr_get_port(rtp_session->local_addr),
5819  old_host, rtp_session->remote_port,
5820  tx_host, switch_sockaddr_get_port(rtp_session->rtcp_from_addr),
5821  send_msg->header.pt, ntohl(send_msg->header.ts), ntohs(send_msg->header.seq), send_msg->header.m);
5822 
5823  }
5824  //switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_WARNING, "RE----SEND %u\n", ntohs(send_msg->header.seq));
5825  switch_rtp_write_raw(rtp_session, (void *) &send_msg, &bytes, SWITCH_FALSE);
5826  } else {
5827  switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(rtp_session->session), SWITCH_LOG_DEBUG1, "Cannot send NACK for seq %u\n", ntohs(seq) + i);
5828  }
5829  }
5830  }
5831 }
switch_status_t switch_jb_get_packet_by_seq(switch_jb_t *jb, uint16_t seq, switch_rtp_packet_t *packet, switch_size_t *len)
#define switch_core_media_gen_key_frame(_session)
#define SWITCH_CHANNEL_SESSION_LOG(x)
uint16_t switch_sockaddr_get_port(switch_sockaddr_t *sa)
Definition: switch_apr.c:916
switch_sockaddr_t * rtcp_from_addr
Definition: switch_rtp.c:374
switch_sockaddr_t * remote_addr
Definition: switch_rtp.c:326
switch_port_t remote_port
Definition: switch_rtp.c:398
switch_jb_t * vbw
Definition: switch_rtp.c:416
_Ret_ switch_channel_t * switch_core_session_get_channel(_In_ switch_core_session_t *session)
Retrieve a pointer to the channel object associated with a given session.
uint32_t flags[SWITCH_RTP_FLAG_INVALID]
Definition: switch_rtp.c:372
uintptr_t switch_size_t
switch_sockaddr_t * local_addr
Definition: switch_rtp.c:313
switch_status_t switch_rtp_write_raw(switch_rtp_t *rtp_session, void *data, switch_size_t *bytes, switch_bool_t process_encryption)
Definition: switch_rtp.c:8006
#define SWITCH_CHANNEL_SESSION_LOG_CLEAN(x)
srtp_hdr_t header
Definition: switch_rtp.c:112
switch_core_session_t * session
Definition: switch_rtp.c:446
void switch_log_printf(_In_ switch_text_channel_t channel, _In_z_ const char *file, _In_z_ const char *func, _In_ int line, _In_opt_z_ const char *userdata, _In_ switch_log_level_t level, _In_z_ _Printf_format_string_ const char *fmt,...) PRINTF_FUNCTION(7
Write log data to the logging engine.
const char * switch_get_addr(char *buf, switch_size_t len, switch_sockaddr_t *in)
Definition: switch_apr.c:894
char * switch_channel_get_name(switch_channel_t *channel)
Retrieve the name of a given channel.
static handle_rfc2833_result_t handle_rfc2833 ( switch_rtp_t rtp_session,
switch_size_t  bytes,
int *  do_cng 
)
static

Definition at line 539 of file switch_rtp.c.

References switch_dtmf_t::digit, switch_rtp::dtmf_data, DTMF_SANITY, switch_dtmf_t::duration, switch_rtp_rfc2833_data::first_digit, switch_rtp::flags, switch_rtp_rfc2833_data::flip, switch_rtp_rfc2833_data::in_digit_queued, switch_rtp_rfc2833_data::in_digit_sanity, switch_rtp_rfc2833_data::in_digit_seq, switch_rtp_rfc2833_data::in_digit_ts, switch_rtp_rfc2833_data::in_interleaved, switch_rtp_stats_t::inbound, switch_rtp::jb, switch_rtp_rfc2833_data::last_digit, switch_rtp_rfc2833_data::last_duration, switch_rtp_rfc2833_data::last_in_digit_ts, switch_rtp_numbers_t::last_processed_seq, switch_rtp::last_rtp_hdr, switch_rtp::pool, switch_rtp::recv_te, RESULT_CONTINUE, RESULT_GOTO_END, RESULT_GOTO_RECVFROM, RESULT_GOTO_TIMERCHECK, RTP_BODY, RTP_BUG_FLUSH_JB_ON_DTMF, RTP_BUG_IGNORE_DTMF_DURATION, switch_rtp::rtp_bugs, rtp_header_len, switch_rtp::session, switch_rtp::stats, SWITCH_CHANNEL_LOG, SWITCH_CHANNEL_SESSION_LOG, switch_cond_next(), switch_core_memory_pool_get_data(), switch_core_min_dtmf_duration(), SWITCH_DTMF_RTP, switch_jb_reset(), SWITCH_LOG_DEBUG, SWITCH_LOG_ERROR, switch_log_printf(), SWITCH_LOG_WARNING, switch_rfc2833_to_char(), SWITCH_RTP_FLAG_DTMF_ON, SWITCH_RTP_FLAG_PASS_RFC2833, SWITCH_RTP_FLAG_PROXY_MEDIA, switch_rtp_queue_rfc2833_in(), and switch_rtp_ready().

Referenced by do_flush(), and rtp_common_read().

540 {
541 
542  if (rtp_session->flags[SWITCH_RTP_FLAG_DTMF_ON]) {
543  rtp_session->flags[SWITCH_RTP_FLAG_DTMF_ON]++;
544 
545  if (rtp_session->flags[SWITCH_RTP_FLAG_DTMF_ON] > DTMF_SANITY) {
546  rtp_session->flags[SWITCH_RTP_FLAG_DTMF_ON] = 0;
547  } else {
548  rtp_session->stats.inbound.last_processed_seq = 0;
549  }
550  }
551 
552 
553 #ifdef DEBUG_2833
554  if (rtp_session->dtmf_data.in_digit_sanity && !(rtp_session->dtmf_data.in_digit_sanity % 100)) {
555  switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "sanity %d %ld\n", rtp_session->dtmf_data.in_digit_sanity, bytes);
556  }
557 #endif
558 
559  if (rtp_session->dtmf_data.in_digit_sanity && !--rtp_session->dtmf_data.in_digit_sanity) {
560 
561  rtp_session->dtmf_data.last_digit = 0;
562  rtp_session->dtmf_data.in_digit_ts = 0;
563  rtp_session->dtmf_data.in_digit_queued = 0;
564  switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(rtp_session->session), SWITCH_LOG_ERROR, "Failed DTMF sanity check.\n");
565  }
566 
567  /* RFC2833 ... like all RFC RE: VoIP, guaranteed to drive you to insanity!
568  We know the real rules here, but if we enforce them, it's an interop nightmare so,
569  we put up with as much as we can so we don't have to deal with being punished for
570  doing it right. Nice guys finish last!
571  */
572 
573  if (bytes > rtp_header_len && !rtp_session->flags[SWITCH_RTP_FLAG_PROXY_MEDIA] &&
574  rtp_session->last_rtp_hdr.pt == rtp_session->recv_te) {
575  switch_size_t len = bytes - rtp_header_len;
576  unsigned char *packet = (unsigned char *) RTP_BODY(rtp_session);
577  int end;
578  uint16_t duration;
579  char key;
580  uint16_t in_digit_seq;
581  uint32_t ts;
582 
583  rtp_session->stats.inbound.last_processed_seq = 0;
584 
585  if (!(packet[0] || packet[1] || packet[2] || packet[3]) && len >= 8) {
586  packet += 4;
587  len -= 4;
588  switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(rtp_session->session), SWITCH_LOG_WARNING, "DTMF payload offset by 4 bytes.\n");
589  }
590 
591  if (!(packet[0] || packet[1] || packet[2] || packet[3]) && rtp_session->dtmf_data.in_digit_ts) {
592  switch_core_session_t *session = switch_core_memory_pool_get_data(rtp_session->pool, "__session");
593  switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_ERROR, "Failed DTMF payload check.\n");
594  rtp_session->dtmf_data.last_digit = 0;
595  rtp_session->dtmf_data.in_digit_ts = 0;
596  rtp_session->dtmf_data.in_digit_sanity = 0;
597  rtp_session->dtmf_data.in_digit_queued = 0;
598  }
599 
600  end = packet[1] & 0x80 ? 1 : 0;
601  duration = (packet[2] << 8) + packet[3];
602  key = switch_rfc2833_to_char(packet[0]);
603  in_digit_seq = ntohs((uint16_t) rtp_session->last_rtp_hdr.seq);
604  ts = htonl(rtp_session->last_rtp_hdr.ts);
605 
606  if (rtp_session->flags[SWITCH_RTP_FLAG_PASS_RFC2833]) {
607 
608  if (end) {
609  rtp_session->flags[SWITCH_RTP_FLAG_DTMF_ON] = DTMF_SANITY - 3;
610  } else if (!rtp_session->flags[SWITCH_RTP_FLAG_DTMF_ON]) {
611  rtp_session->flags[SWITCH_RTP_FLAG_DTMF_ON] = 1;
612  }
613 
614  return RESULT_CONTINUE;
615  }
616 
617  if (in_digit_seq < rtp_session->dtmf_data.in_digit_seq) {
618  if (rtp_session->dtmf_data.in_digit_seq - in_digit_seq > 100) {
619  rtp_session->dtmf_data.in_digit_seq = 0;
620  }
621  }
622 #ifdef DEBUG_2833
623  switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "packet[%d]: %02x %02x %02x %02x\n", (int) len, (unsigned char) packet[0], (unsigned char) packet[1], (unsigned char) packet[2], (unsigned char) packet[3]);
624 #endif
625 
626  if (in_digit_seq > rtp_session->dtmf_data.in_digit_seq) {
627 
628  rtp_session->dtmf_data.in_digit_seq = in_digit_seq;
629 #ifdef DEBUG_2833
630 
631  switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "read: %c %u %u %u %u %d %d %s\n",
632  key, in_digit_seq, rtp_session->dtmf_data.in_digit_seq,
633  ts, duration, rtp_session->last_rtp_hdr.m, end, end && !rtp_session->dtmf_data.in_digit_ts ? "ignored" : "");
634 #endif
635 
636 
637  if (rtp_session->dtmf_data.in_digit_ts && rtp_session->dtmf_data.in_digit_ts != ts) {
638  switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "TS changed from last packet, resetting....\n");
639  rtp_session->dtmf_data.last_digit = 0;
640  rtp_session->dtmf_data.in_digit_ts = 0;
641  rtp_session->dtmf_data.in_digit_sanity = 0;
642  rtp_session->dtmf_data.in_digit_queued = 0;
643  }
644 
645 
646  if (!rtp_session->dtmf_data.in_digit_queued && rtp_session->dtmf_data.in_digit_ts) {
647  if ((rtp_session->rtp_bugs & RTP_BUG_IGNORE_DTMF_DURATION)) {
649 #ifdef DEBUG_2833
650  switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Early Queuing digit %c:%d\n", dtmf.digit, dtmf.duration / 8);
651 #endif
652  switch_rtp_queue_rfc2833_in(rtp_session, &dtmf);
653  rtp_session->dtmf_data.in_digit_queued = 1;
654  }
655 
656  if (rtp_session->jb && (rtp_session->rtp_bugs & RTP_BUG_FLUSH_JB_ON_DTMF)) {
657  switch_jb_reset(rtp_session->jb);
658  }
659 
660  }
661 
662  /* only set sanity if we do NOT ignore the packet */
663  if (rtp_session->dtmf_data.in_digit_ts) {
664  rtp_session->dtmf_data.in_digit_sanity = 2000;
665  }
666 
667  if (rtp_session->dtmf_data.last_duration > duration &&
668  rtp_session->dtmf_data.last_duration > 0xFC17 && ts == rtp_session->dtmf_data.in_digit_ts) {
669  rtp_session->dtmf_data.flip++;
670  }
671 
672  if (end) {
673  if (!rtp_session->dtmf_data.in_digit_ts && rtp_session->dtmf_data.last_in_digit_ts != ts) {
674 #ifdef DEBUG_2833
675  switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "start with end packet %d\n", ts);
676 #endif
677  rtp_session->dtmf_data.last_in_digit_ts = ts;
678  rtp_session->dtmf_data.in_digit_ts = ts;
679  rtp_session->dtmf_data.first_digit = key;
680  rtp_session->dtmf_data.in_digit_sanity = 2000;
681  }
682  if (rtp_session->dtmf_data.in_digit_ts) {
683  switch_dtmf_t dtmf = { key, duration, 0, SWITCH_DTMF_RTP };
684 
685  if (ts > rtp_session->dtmf_data.in_digit_ts) {
686  dtmf.duration += (ts - rtp_session->dtmf_data.in_digit_ts);
687  }
688  if (rtp_session->dtmf_data.flip) {
689  dtmf.duration += rtp_session->dtmf_data.flip * 0xFFFF;
690  rtp_session->dtmf_data.flip = 0;
691 #ifdef DEBUG_2833
693 #endif
694  }
695 #ifdef DEBUG_2833
696  switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "done digit=%c ts=%u start_ts=%u dur=%u ddur=%u\n",
697  dtmf.digit, ts, rtp_session->dtmf_data.in_digit_ts, duration, dtmf.duration);
698 #endif
699 
700  if (!(rtp_session->rtp_bugs & RTP_BUG_IGNORE_DTMF_DURATION) && !rtp_session->dtmf_data.in_digit_queued) {
701 #ifdef DEBUG_2833
702  switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Queuing digit %c:%d\n", dtmf.digit, dtmf.duration / 8);
703 #endif
704  switch_rtp_queue_rfc2833_in(rtp_session, &dtmf);
705  }
706 
707  rtp_session->dtmf_data.last_digit = rtp_session->dtmf_data.first_digit;
708 
709  rtp_session->dtmf_data.in_digit_ts = 0;
710  rtp_session->dtmf_data.in_digit_sanity = 0;
711  rtp_session->dtmf_data.in_digit_queued = 0;
712  *do_cng = 1;
713  } else {
714  if (!switch_rtp_ready(rtp_session)) {
715  return RESULT_GOTO_END;
716  }
718  return RESULT_GOTO_RECVFROM;
719  }
720 
721  } else if (!rtp_session->dtmf_data.in_digit_ts) {
722 #ifdef DEBUG_2833
723  switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "start %d [%c]\n", ts, key);
724 #endif
725  rtp_session->dtmf_data.in_digit_ts = ts;
726  rtp_session->dtmf_data.last_in_digit_ts = ts;
727  rtp_session->dtmf_data.first_digit = key;
728  rtp_session->dtmf_data.in_digit_sanity = 2000;
729  }
730 
731  rtp_session->dtmf_data.last_duration = duration;
732  } else {
733 #ifdef DEBUG_2833
734  switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "drop: %c %u %u %u %u %d %d\n",
735  key, in_digit_seq, rtp_session->dtmf_data.in_digit_seq, ts, duration, rtp_session->last_rtp_hdr.m, end);
736 #endif
738  return RESULT_GOTO_RECVFROM;
739  }
740  }
741 
742  if (bytes && rtp_session->dtmf_data.in_digit_ts) {
743  if (!switch_rtp_ready(rtp_session)) {
744  return RESULT_GOTO_END;
745  }
746 
747  if (!rtp_session->dtmf_data.in_interleaved && rtp_session->last_rtp_hdr.pt != rtp_session->recv_te) {
748  /* Drat, they are sending audio still as well as DTMF ok fine..... *sigh* */
749  rtp_session->dtmf_data.in_interleaved = 1;
750  }
751 
752  if (rtp_session->dtmf_data.in_interleaved || (rtp_session->rtp_bugs & RTP_BUG_IGNORE_DTMF_DURATION)) {
753  if (rtp_session->last_rtp_hdr.pt == rtp_session->recv_te) {
754  return RESULT_GOTO_RECVFROM;
755  }
756  } else {
757  *do_cng = 1;
758  return RESULT_GOTO_TIMERCHECK;
759  }
760  }
761 
762  return RESULT_CONTINUE;
763 }
#define SWITCH_CHANNEL_SESSION_LOG(x)
switch_rtp_numbers_t inbound
Definition: switch_types.h:690
uint8_t switch_rtp_ready(switch_rtp_t *rtp_session)
Test if an RTP session is ready.
Definition: switch_rtp.c:4452
#define SWITCH_CHANNEL_LOG
#define DTMF_SANITY
Definition: switch_rtp.c:77
void * switch_core_memory_pool_get_data(switch_memory_pool_t *pool, const char *key)
uint32_t duration
Definition: switch_types.h:288
struct switch_rtp_rfc2833_data dtmf_data
Definition: switch_rtp.c:403
uint32_t switch_core_min_dtmf_duration(uint32_t duration)
Definition: switch_core.c:1704
uint32_t flags[SWITCH_RTP_FLAG_INVALID]
Definition: switch_rtp.c:372
uintptr_t switch_size_t
char switch_rfc2833_to_char(int event)
Return the RFC2833 character based on an event id.
void switch_cond_next(void)
Definition: switch_time.c:638
switch_rtp_stats_t stats
Definition: switch_rtp.c:428
switch_memory_pool_t * pool
Definition: switch_rtp.c:373
#define RTP_BODY(_s)
Definition: switch_rtp.c:118
switch_jb_t * jb
Definition: switch_rtp.c:414
switch_core_session_t * session
Definition: switch_rtp.c:446
void switch_jb_reset(switch_jb_t *jb)
switch_rtp_bug_flag_t rtp_bugs
Definition: switch_rtp.c:427
switch_payload_t recv_te
Definition: switch_rtp.c:405
void switch_log_printf(_In_ switch_text_channel_t channel, _In_z_ const char *file, _In_z_ const char *func, _In_ int line, _In_opt_z_ const char *userdata, _In_ switch_log_level_t level, _In_z_ _Printf_format_string_ const char *fmt,...) PRINTF_FUNCTION(7
Write log data to the logging engine.
switch_status_t switch_rtp_queue_rfc2833_in(switch_rtp_t *rtp_session, const switch_dtmf_t *dtmf)
Queue RFC2833 DTMF data into an RTP Session.
Definition: switch_rtp.c:6961
rtp_hdr_t last_rtp_hdr
Definition: switch_rtp.c:351
#define rtp_header_len
Definition: switch_rtp.c:66
static switch_status_t ice_out ( switch_rtp_t rtp_session,
switch_rtp_ice_t ice 
)
static

Definition at line 771 of file switch_rtp.c.

References switch_rtp_ice_t::addr, buf, ice_s::cands, ice_s::chosen, switch_stun_packet_t::header, ICE_CONTROLLED, switch_rtp_ice_t::ice_params, switch_rtp_ice_t::ice_user, ICE_VANILLA, switch_stun_packet_header_t::id, switch_rtp_ice_t::last_sent_id, switch_rtp::last_stun, switch_rtp_ice_t::next_run, icand_s::priority, switch_rtp_ice_t::proto, READ_DEC, READ_INC, switch_rtp_ice_t::rpass, switch_rtp::rtcp_ice, switch_rtp::rtcp_sock_output, rtp_session_name, RTP_STUN_FREQ, rtp_type, switch_rtp_ice_t::sending, switch_rtp::session, switch_rtp::sock_output, switch_assert, SWITCH_CHANNEL_SESSION_LOG, SWITCH_LOG_CRIT, SWITCH_LOG_ERROR, switch_log_printf(), switch_micro_time_now(), switch_snprintf(), switch_socket_sendto(), SWITCH_STATUS_BREAK, SWITCH_STATUS_FALSE, SWITCH_STATUS_SUCCESS, SWITCH_STUN_BINDING_REQUEST, switch_stun_packet_attribute_add_controlled(), switch_stun_packet_attribute_add_controlling(), switch_stun_packet_attribute_add_fingerprint(), switch_stun_packet_attribute_add_integrity(), switch_stun_packet_attribute_add_priority(), switch_stun_packet_attribute_add_software(), switch_stun_packet_attribute_add_use_candidate(), switch_stun_packet_attribute_add_username(), switch_stun_packet_build_header(), switch_stun_packet_length, switch_version_revision_human(), and switch_rtp_ice_t::type.

Referenced by check_rtcp_and_ice(), generate_m(), and switch_core_media_gen_local_sdp().

772 {
773  uint8_t buf[256] = { 0 };
774  switch_stun_packet_t *packet;
775  unsigned int elapsed;
776  switch_size_t bytes;
778  //switch_sockaddr_t *remote_addr = rtp_session->remote_addr;
779  switch_socket_t *sock_output = rtp_session->sock_output;
781 
782  if (ice->next_run && ice->next_run > now) {
783  return SWITCH_STATUS_BREAK;
784  }
785 
786  ice->next_run = now + RTP_STUN_FREQ;
787 
788  if (ice == &rtp_session->rtcp_ice && rtp_session->rtcp_sock_output) {
789  sock_output = rtp_session->rtcp_sock_output;
790  }
791 
792  if (!sock_output) {
793  return SWITCH_STATUS_FALSE;
794  }
795 
796  switch_assert(rtp_session != NULL);
797  switch_assert(ice->ice_user != NULL);
798 
799  READ_INC(rtp_session);
800 
801  if (rtp_session->last_stun) {
802  elapsed = (unsigned int) ((switch_micro_time_now() - rtp_session->last_stun) / 1000);
803 
804  if (elapsed > 30000) {
805  switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(rtp_session->session), SWITCH_LOG_ERROR, "No %s stun for a long time!\n", rtp_type(rtp_session));
806  rtp_session->last_stun = switch_micro_time_now();
807  //status = SWITCH_STATUS_GENERR;
808  //goto end;
809  }
810  }
811 
813  switch_stun_packet_attribute_add_username(packet, ice->ice_user, (uint16_t)strlen(ice->ice_user));
814 
815  memcpy(ice->last_sent_id, packet->header.id, 12);
816 
817  //if (ice->pass && ice->type == ICE_GOOGLE_JINGLE) {
818  // switch_stun_packet_attribute_add_password(packet, ice->pass, (uint16_t)strlen(ice->pass));
819  //}
820 
821  if ((ice->type & ICE_VANILLA)) {
822  char sw[128] = "";
823 
825 
826  switch_snprintf(sw, sizeof(sw), "FreeSWITCH (%s)", switch_version_revision_human());
827  switch_stun_packet_attribute_add_software(packet, sw, (uint16_t)strlen(sw));
828 
829  if ((ice->type & ICE_CONTROLLED)) {
831  } else {
834  }
835 
838  }
839 
840 
841  bytes = switch_stun_packet_length(packet);
842 
843 #ifdef DEBUG_EXTRA
844  switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(rtp_session->session), SWITCH_LOG_CRIT, "%s send %s stun\n", rtp_session_name(rtp_session), rtp_type(rtp_session));
845 #endif
846  switch_socket_sendto(sock_output, ice->addr, 0, (void *) packet, &bytes);
847 
848  ice->sending = 3;
849 
850  // end:
851  READ_DEC(rtp_session);
852 
853  return status;
854 }
uint8_t switch_stun_packet_attribute_add_software(switch_stun_packet_t *packet, char *software, uint16_t ulen)
Definition: switch_stun.c:640
switch_time_t switch_micro_time_now(void)
Get the current epoch time in microseconds.
Definition: switch_time.c:310
#define SWITCH_CHANNEL_SESSION_LOG(x)
uint8_t switch_stun_packet_attribute_add_priority(switch_stun_packet_t *packet, uint32_t priority)
Definition: switch_stun.c:521
#define RTP_STUN_FREQ
Definition: switch_rtp.c:65
uint8_t switch_stun_packet_attribute_add_fingerprint(switch_stun_packet_t *packet)
Definition: switch_stun.c:552
uint8_t switch_stun_packet_attribute_add_controlling(switch_stun_packet_t *packet)
Definition: switch_stun.c:585
int chosen[2]
Definition: switch_rtp.h:107
switch_sockaddr_t * addr
Definition: switch_rtp.c:244
ice_t * ice_params
Definition: switch_rtp.c:248
#define rtp_session_name(_rtp_session)
Definition: switch_rtp.c:79
int switch_snprintf(_Out_z_cap_(len) char *buf, _In_ switch_size_t len, _In_z_ _Printf_format_string_ const char *format,...)
switch_time_t next_run
Definition: switch_rtp.c:246
#define READ_DEC(rtp_session)
Definition: switch_rtp.c:61
switch_stun_packet_t * switch_stun_packet_build_header(switch_stun_message_t type, char *id, uint8_t *buf)
Prepare a new outbound packet of a certian type and id.
Definition: switch_stun.c:431
#define rtp_type(rtp_session)
Definition: switch_rtp.c:513
uint8_t switch_stun_packet_attribute_add_use_candidate(switch_stun_packet_t *packet)
Definition: switch_stun.c:574
uint8_t switch_stun_packet_attribute_add_username(switch_stun_packet_t *packet, char *username, uint16_t ulen)
Add a username packet attribute.
Definition: switch_stun.c:616
int64_t switch_time_t
Definition: switch_apr.h:188
switch_core_media_ice_type_t type
Definition: switch_rtp.c:247
switch_byte_t switch_byte_t * buf
switch_status_t switch_socket_sendto(switch_socket_t *sock, switch_sockaddr_t *where, int32_t flags, const char *buf, switch_size_t *len)
Definition: switch_apr.c:773
#define READ_INC(rtp_session)
Definition: switch_rtp.c:60
#define switch_stun_packet_length(packet)
Obtain the correct length in bytes of a stun packet.
Definition: switch_stun.h:295
char last_sent_id[13]
Definition: switch_rtp.c:254
uintptr_t switch_size_t
switch_rtp_ice_t rtcp_ice
Definition: switch_rtp.c:378
switch_socket_t * rtcp_sock_output
Definition: switch_rtp.c:309
switch_stun_packet_header_t header
Definition: switch_stun.h:133
switch_status_t
Common return values.
ice_proto_t proto
Definition: switch_rtp.c:249
switch_core_session_t * session
Definition: switch_rtp.c:446
icand_t cands[MAX_CAND][2]
Definition: switch_rtp.h:105
uint8_t switch_stun_packet_attribute_add_controlled(switch_stun_packet_t *packet)
Definition: switch_stun.c:600
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 priority
Definition: switch_rtp.h:92
switch_time_t last_stun
Definition: switch_rtp.c:384
const char * switch_version_revision_human(void)
struct apr_socket_t switch_socket_t
Definition: switch_apr.h:1026
#define switch_assert(expr)
switch_socket_t * sock_output
Definition: switch_rtp.c:309
uint8_t switch_stun_packet_attribute_add_integrity(switch_stun_packet_t *packet, const char *pass)
Definition: switch_stun.c:535
int icecmp ( const char *  them,
switch_rtp_ice_t ice 
)

Definition at line 856 of file switch_rtp.c.

References switch_rtp_ice_t::luser_ice, and switch_rtp_ice_t::user_ice.

Referenced by handle_ice().

857 {
858  if (strchr(them, ':')) {
859  return strcmp(them, ice->user_ice);
860  }
861 
862  return strcmp(them, ice->luser_ice);
863 }
static int jb_valid ( switch_rtp_t rtp_session)
static

Definition at line 4967 of file switch_rtp.c.

References DS_READY, switch_rtp::dtls, switch_rtp::ice, switch_rtp_ice_t::ice_user, switch_rtp_ice_t::ready, switch_rtp_ice_t::rready, and switch_dtls_s::state.

Referenced by do_flush(), read_rtp_packet(), and rtp_common_read().

4968 {
4969  if (rtp_session->ice.ice_user) {
4970  if (!rtp_session->ice.ready && rtp_session->ice.rready) {
4971  return 0;
4972  }
4973  }
4974 
4975  if (rtp_session->dtls && rtp_session->dtls->state != DS_READY) {
4976  return 0;
4977  }
4978 
4979  return 1;
4980 }
dtls_state_t state
Definition: switch_rtp.c:268
switch_dtls_t * dtls
Definition: switch_rtp.c:348
switch_rtp_ice_t ice
Definition: switch_rtp.c:377
static void ping_socket ( switch_rtp_t rtp_session)
static

Definition at line 2832 of file switch_rtp.c.

References switch_rtp::flags, switch_rtp::local_addr, switch_rtp::rtcp_local_addr, switch_rtp::rtcp_sock_input, switch_rtp::sock_input, SWITCH_RTP_FLAG_ENABLE_RTCP, and switch_socket_sendto().

Referenced by switch_rtp_break(), switch_rtp_kill_socket(), and switch_rtp_udptl_mode().

2833 {
2834  uint32_t o = UINT_MAX;
2835  switch_size_t len = sizeof(o);
2836  switch_socket_sendto(rtp_session->sock_input, rtp_session->local_addr, 0, (void *) &o, &len);
2837 
2838  if (rtp_session->flags[SWITCH_RTP_FLAG_ENABLE_RTCP] && rtp_session->rtcp_sock_input) {
2839  switch_socket_sendto(rtp_session->rtcp_sock_input, rtp_session->rtcp_local_addr, 0, (void *) &o, &len);
2840  }
2841 }
switch_sockaddr_t * rtcp_local_addr
Definition: switch_rtp.c:313
switch_socket_t * sock_input
Definition: switch_rtp.c:309
switch_socket_t * rtcp_sock_input
Definition: switch_rtp.c:309
switch_status_t switch_socket_sendto(switch_socket_t *sock, switch_sockaddr_t *where, int32_t flags, const char *buf, switch_size_t *len)
Definition: switch_apr.c:773
uint32_t flags[SWITCH_RTP_FLAG_INVALID]
Definition: switch_rtp.c:372
uintptr_t switch_size_t
switch_sockaddr_t * local_addr
Definition: switch_rtp.c:313
static switch_status_t process_rtcp_packet ( switch_rtp_t rtp_session,
switch_size_t bytes 
)
static

Definition at line 5984 of file switch_rtp.c.

References handle_ice(), rtcp_msg_t::header, switch_rtp::ice, switch_rtp_ice_t::ice_user, switch_rtcp_hdr_s::length, process_rtcp_report(), switch_rtp::rtcp_ice, switch_rtp::rtcp_recv_msg_p, switch_rtp::session, SWITCH_CHANNEL_SESSION_LOG, switch_log_printf(), SWITCH_LOG_WARNING, SWITCH_SIZE_T_FMT, SWITCH_STATUS_BREAK, SWITCH_STATUS_FALSE, SWITCH_STATUS_SUCCESS, switch_rtcp_hdr_s::type, and switch_rtcp_hdr_s::version.

Referenced by read_rtcp_packet(), and rtp_common_read().

5985 {
5986  switch_size_t len;
5987  switch_size_t remain = *bytes;
5989  rtcp_msg_t *msg = rtp_session->rtcp_recv_msg_p;
5990 
5991  if (msg->header.version != 2) {
5992  if (msg->header.version == 0) {
5993  if (rtp_session->ice.ice_user) {
5994  handle_ice(rtp_session, &rtp_session->rtcp_ice, (void *) msg, *bytes);
5995  }
5996  return SWITCH_STATUS_SUCCESS;
5997  } else {
5999  SWITCH_LOG_WARNING, "Received an unsupported RTCP packet version %d\n", msg->header.version);
6000  return SWITCH_STATUS_FALSE;
6001  }
6002  }
6003 
6004  do {
6005  len = ((switch_size_t)ntohs(msg->header.length) * 4) + 4;
6006 
6007  if (msg->header.version != 2 || !(msg->header.type > 199 && msg->header.type < 208)) {
6009  "INVALID RTCP PACKET TYPE %d VER %d LEN %" SWITCH_SIZE_T_FMT "\n", msg->header.type,
6010  msg->header.version, len);
6011  status = SWITCH_STATUS_BREAK;
6012  break;
6013  }
6014 
6015  //switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(rtp_session->session), SWITCH_LOG_CRIT,
6016  //"WTF BYTES %ld REMAIN %ld PACKET TYPE %d LEN %ld\n", *bytes, remain, msg->header.type, len);
6017 
6018  if (len > remain) {
6020  "RTCP INVALID LENGTH %" SWITCH_SIZE_T_FMT "\n", len);
6021  len = remain;
6022  }
6023 
6024  status = process_rtcp_report(rtp_session, msg, len);
6025 
6026  if (remain > len) {
6027  unsigned char *p = (unsigned char *) msg;
6028  p += len;
6029  msg = (rtcp_msg_t *) p;
6030  }
6031 
6032  remain -= len;
6033 
6034  } while (remain >= 4);
6035 
6036  return status;
6037 }
#define SWITCH_CHANNEL_SESSION_LOG(x)
switch_rtcp_hdr_t header
Definition: switch_rtp.c:180
uintptr_t switch_size_t
switch_rtp_ice_t rtcp_ice
Definition: switch_rtp.c:378
static void handle_ice(switch_rtp_t *rtp_session, switch_rtp_ice_t *ice, void *data, switch_size_t len)
Definition: switch_rtp.c:865
switch_status_t
Common return values.
switch_core_session_t * session
Definition: switch_rtp.c:446
switch_rtp_ice_t ice
Definition: switch_rtp.c:377
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_SIZE_T_FMT
rtcp_msg_t * rtcp_recv_msg_p
Definition: switch_rtp.c:329
static switch_status_t process_rtcp_report(switch_rtp_t *rtp_session, rtcp_msg_t *msg, switch_size_t bytes)
Definition: switch_rtp.c:5833
static switch_status_t process_rtcp_report ( switch_rtp_t rtp_session,
rtcp_msg_t msg,
switch_size_t  bytes 
)
static

Definition at line 5833 of file switch_rtp.c.

References _RTCP_PSFB_FIR, _RTCP_PSFB_PLI, _RTCP_PT_PSFB, _RTCP_PT_RR, _RTCP_PT_RTPFB, _RTCP_PT_SR, _RTCP_RTPFB_NACK, rtcp_ext_msg_t::body, rtcp_msg_t::body, switch_rtcp_hdr_s::count, switch_rtcp_report_block_frame::dlsr, switch_rtcp_report_block::dlsr, switch_rtp::flags, switch_rtcp_ext_hdr_t::fmt, switch_rtcp_report_block_frame::fraction, switch_rtcp_report_block::fraction, handle_nack(), rtcp_ext_msg_t::header, rtcp_msg_t::header, switch_rtcp_report_block_frame::highest_sequence_number_received, switch_rtcp_report_block::highest_sequence_number_received, if(), switch_rtcp_report_block_frame::jitter, switch_rtcp_report_block::jitter, switch_rtcp_numbers_t::last_recv_lsr_local, switch_rtcp_numbers_t::last_recv_lsr_peer, switch_rtcp_ext_hdr_t::length, switch_rtcp_hdr_s::length, switch_rtcp_report_block_frame::loss_avg, switch_rtcp_report_block_frame::lost, switch_rtcp_report_block::lost, switch_rtcp_report_block_frame::lsr, switch_rtcp_report_block::lsr, MAX_REPORT_BLOCKS, memset(), switch_rtcp_frame::ntp_lsw, switch_rtcp_sender_info::ntp_lsw, switch_rtcp_frame::ntp_msw, switch_rtcp_sender_info::ntp_msw, NTP_TIME_OFFSET, switch_rtcp_sender_info::oc, switch_rtcp_frame::octect_count, switch_rtcp_numbers_t::octet_count, switch_rtcp_hdr_s::p, switch_rtcp_frame::packet_count, switch_rtcp_numbers_t::packet_count, switch_rtcp_frame::packet_type, switch_rtcp_sender_info::pc, switch_rtcp_numbers_t::peer_ssrc, switch_rtcp_frame::report_count, switch_rtcp_frame::reports, switch_rtp_stats_t::rtcp, switch_rtp::rtcp_frame, switch_rtp::rtcp_fresh_frame, switch_rtp::rtcp_recv_msg_p, switch_rtcp_report_block_frame::rtt_avg, SCC_AUDIO_PACKET_LOSS, SCCT_INT, SCCT_NONE, switch_rtcp_sender_report::sender_info, switch_rtp::session, switch_rtcp_report_block_frame::ssrc, switch_rtcp_frame::ssrc, switch_rtcp_report_block::ssrc, switch_rtcp_sender_report::ssrc, switch_rtcp_receiver_report::ssrc, switch_rtp::stats, SWITCH_CHANNEL_SESSION_LOG, switch_core_media_codec_control(), switch_core_media_gen_key_frame, SWITCH_IO_WRITE, switch_jb_reset(), SWITCH_LOG_DEBUG1, SWITCH_LOG_DEBUG10, SWITCH_LOG_DEBUG3,