Main Page | Modules | Class Hierarchy | Alphabetical List | Data Structures | Directories | File List | Data Fields | Globals | Related Pages

switch_rtp.c File Reference


Data Structures

struct  rtp_msg_t
struct  switch_rtp_vad_data
struct  switch_rtp_rfc2833_data
struct  switch_rtp

Defines

#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_header_len   12
#define RTP_START_PORT   16384
#define RTP_END_PORT   32768
#define MASTER_KEY_LEN   30
#define RTP_MAGIC_NUMBER   42
#define MAX_SRTP_ERRS   10

Typedefs

typedef srtp_hdr_t rtp_hdr_t

Functions

void switch_rtp_init (switch_memory_pool_t *pool)
 Initilize the RTP System.
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.
switch_port_t switch_rtp_set_end_port (switch_port_t port)
 Set/Get RTP end port.
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.
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.
void switch_rtp_set_max_missed_packets (switch_rtp_t *rtp_session, uint32_t max)
switch_status_t switch_rtp_set_remote_address (switch_rtp_t *rtp_session, const char *host, switch_port_t port, const char **err)
 Assign a remote address to the RTP session.
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_create (switch_rtp_t **new_rtp_session, switch_payload_t payload, uint32_t samples_per_interval, uint32_t ms_per_packet, switch_rtp_flag_t flags, char *timer_name, const char **err, switch_memory_pool_t *pool)
 create a new RTP session handle
switch_rtp_tswitch_rtp_new (const char *rx_host, switch_port_t rx_port, const char *tx_host, switch_port_t tx_port, switch_payload_t payload, uint32_t samples_per_interval, uint32_t ms_per_packet, switch_rtp_flag_t flags, char *timer_name, const char **err, switch_memory_pool_t *pool)
 prepare a new RTP session handle and fully initilize it
void switch_rtp_set_telephony_event (switch_rtp_t *rtp_session, switch_payload_t te)
 Set the payload type to consider RFC2833 DTMF.
void switch_rtp_set_cng_pt (switch_rtp_t *rtp_session, switch_payload_t pt)
 Set the payload type for comfort noise.
switch_status_t switch_rtp_activate_jitter_buffer (switch_rtp_t *rtp_session, uint32_t queue_frames)
 Acvite a jitter buffer on an RTP session.
switch_status_t switch_rtp_activate_ice (switch_rtp_t *rtp_session, char *login, char *rlogin)
 Acvite ICE on an 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.
uint8_t switch_rtp_ready (switch_rtp_t *rtp_session)
 Test if an RTP session is ready.
void switch_rtp_destroy (switch_rtp_t **rtp_session)
 Destroy an RTP session.
switch_socket_tswitch_rtp_get_rtp_socket (switch_rtp_t *rtp_session)
 Retrieve the socket from an existing RTP session.
void switch_rtp_set_default_samples_per_interval (switch_rtp_t *rtp_session, uint16_t samples_per_interval)
 Set the default samples per interval for a given RTP session.
uint32_t switch_rtp_get_default_samples_per_interval (switch_rtp_t *rtp_session)
 Get the default samples per interval for a given RTP session.
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.
uint32_t switch_rtp_get_default_payload (switch_rtp_t *rtp_session)
 Get the default payload number for a given RTP session.
void switch_rtp_set_invald_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.
void switch_rtp_set_flag (switch_rtp_t *rtp_session, switch_rtp_flag_t flags)
 Set an RTP Flag.
uint32_t switch_rtp_test_flag (switch_rtp_t *rtp_session, switch_rtp_flag_t flags)
 Test an RTP Flag.
void switch_rtp_clear_flag (switch_rtp_t *rtp_session, switch_rtp_flag_t flags)
 Clear an RTP Flag.
switch_size_t switch_rtp_has_dtmf (switch_rtp_t *rtp_session)
 Test for presence of DTMF on a given RTP session.
switch_size_t switch_rtp_dequeue_dtmf (switch_rtp_t *rtp_session, switch_dtmf_t *dtmf)
 Retrieve DTMF digits from a given RTP session.
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.
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.
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.
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.
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.
switch_status_t switch_rtp_disable_vad (switch_rtp_t *rtp_session)
 Disable VAD on an RTP Session.
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.
int switch_rtp_write_frame (switch_rtp_t *rtp_session, switch_frame_t *frame)
 Write data to a given RTP session.
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.
uint32_t switch_rtp_get_ssrc (switch_rtp_t *rtp_session)
 Retrieve the SSRC from a given RTP session.
void switch_rtp_set_private (switch_rtp_t *rtp_session, void *private_data)
 Associate an arbitrary data pointer with and RTP session.
void * switch_rtp_get_private (switch_rtp_t *rtp_session)
 Retrieve the private data from a given RTP session.


Define Documentation

#define MASTER_KEY_LEN   30
 

#define MAX_SRTP_ERRS   10
 

#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 RTP_END_PORT   32768
 

#define rtp_header_len   12
 

#define RTP_MAGIC_NUMBER   42
 

#define RTP_START_PORT   16384
 

#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++
 


Typedef Documentation

typedef srtp_hdr_t rtp_hdr_t
 


Function Documentation

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
 

00552 {
00553         switch_rtp_crypto_key_t *crypto_key;
00554         srtp_policy_t *policy;
00555         err_status_t stat;
00556         switch_status_t status = SWITCH_STATUS_SUCCESS;
00557 
00558         if (direction >= SWITCH_RTP_CRYPTO_MAX || keylen > SWITCH_RTP_MAX_CRYPTO_LEN) {
00559                 return SWITCH_STATUS_FALSE;
00560         } 
00561 
00562         crypto_key = switch_core_alloc(rtp_session->pool, sizeof(*crypto_key));
00563                 
00564         if (direction == SWITCH_RTP_CRYPTO_RECV) {
00565                 policy = &rtp_session->recv_policy;
00566         } else {
00567                 policy = &rtp_session->send_policy;
00568         }
00569 
00570         crypto_key->type = type;
00571         crypto_key->index = index;
00572         memcpy(crypto_key->key, key, keylen);
00573         crypto_key->next = rtp_session->crypto_keys[direction];
00574         rtp_session->crypto_keys[direction] = crypto_key;
00575 
00576         memset(policy, 0, sizeof(*policy));
00577 
00578         switch(crypto_key->type) {
00579         case AES_CM_128_HMAC_SHA1_80:
00580                 crypto_policy_set_aes_cm_128_hmac_sha1_80(&policy->rtp);
00581                 break;
00582         case AES_CM_128_HMAC_SHA1_32:
00583                 crypto_policy_set_aes_cm_128_hmac_sha1_32(&policy->rtp);
00584                 break;
00585         default:
00586                 break;
00587         }
00588 
00589         policy->next = NULL;    
00590         policy->key = (uint8_t *) crypto_key->key;
00591         crypto_policy_set_rtcp_default(&policy->rtcp);
00592         policy->rtcp.sec_serv = sec_serv_none;
00593 
00594         policy->rtp.sec_serv = sec_serv_conf_and_auth;
00595         switch(direction) {
00596         case SWITCH_RTP_CRYPTO_RECV:
00597                 policy->ssrc.type = ssrc_any_inbound;
00598 
00599                 if (switch_test_flag(rtp_session, SWITCH_RTP_FLAG_SECURE_RECV)) {
00600                         switch_set_flag(rtp_session, SWITCH_RTP_FLAG_SECURE_RECV_RESET);
00601                 } else {
00602                         if ((stat = srtp_create(&rtp_session->recv_ctx, policy))) {
00603                                 status = SWITCH_STATUS_FALSE;
00604                         }
00605 
00606                         if (status == SWITCH_STATUS_SUCCESS) {
00607                                 switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_INFO, "Activating Secure RTP RECV\n");
00608                                 switch_set_flag(rtp_session, SWITCH_RTP_FLAG_SECURE_RECV);
00609                         } else {
00610                                 switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Error allocating srtp [%d]\n", stat);
00611                                 return status;
00612                         }
00613                 }
00614                 break;
00615         case SWITCH_RTP_CRYPTO_SEND:
00616                 policy->ssrc.type = ssrc_specific;
00617                 policy->ssrc.value = rtp_session->ssrc;
00618 
00619                 if (switch_test_flag(rtp_session, SWITCH_RTP_FLAG_SECURE_SEND)) {
00620                         switch_set_flag(rtp_session, SWITCH_RTP_FLAG_SECURE_SEND_RESET);
00621                 } else {
00622                         if ((stat = srtp_create(&rtp_session->send_ctx, policy))) {
00623                                 status = SWITCH_STATUS_FALSE;
00624                         }
00625 
00626                         if (status == SWITCH_STATUS_SUCCESS) {
00627                                 switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_INFO, "Activating Secure RTP SEND\n");
00628                                 switch_set_flag(rtp_session, SWITCH_RTP_FLAG_SECURE_SEND);
00629                         } else {
00630                                 switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Error allocating srtp [%d]\n", stat);
00631                                 return status;
00632                         }
00633                 }
00634 
00635                 break;
00636         default:
00637                 abort();
00638                 break;
00639         }
00640 
00641         return SWITCH_STATUS_SUCCESS;
00642 }

Here is the call graph for this function:


Generated on Mon May 26 22:06:52 2008 for FreeSWITCH by  doxygen 1.3.9.1