switch_rtp windows tweaks and type changes.

git-svn-id: http://svn.freeswitch.org/svn/freeswitch/trunk@1026 d0543943-73ff-0310-b7d9-9358b9ac24b2
This commit is contained in:
Michael Jerris
2006-04-04 04:15:39 +00:00
parent ab65eb3873
commit 7f03b92fe6
7 changed files with 88 additions and 67 deletions
+2 -8
View File
@@ -38,13 +38,6 @@
extern "C" {
#endif
#ifdef WIN32
#include <winsock2.h>
typedef SOCKET switch_raw_socket_t;
#else
typedef int switch_raw_socket_t;
#endif
#ifdef __ICC
#pragma warning (disable:810 869 981 279 1469 188)
#endif
@@ -67,8 +60,9 @@ typedef int switch_raw_socket_t;
* C4204: nonstandard extension used : non-constant aggregate initializer
* C4706: assignment within conditional expression
* C4055: type cast from data pointer to function pointer (apr carries function pointers as data pointers)
* C4214: nonstandard extension used : bit field types other than int
*/
#pragma warning(disable:4152 4054 4100 4142 4200 4204 4706 4055)
#pragma warning(disable:4152 4054 4100 4142 4200 4204 4706 4055 4214)
#if (_MSC_VER >= 1400) // VC8+
#ifndef _CRT_SECURE_NO_DEPRECATE
+15 -19
View File
@@ -55,31 +55,27 @@ typedef void (*switch_rtp_invalid_handler)(switch_rtp *rtp_session,
switch_sockaddr_t *from_addr);
switch_rtp *switch_rtp_new(char *rx_ip,
int rx_port,
SWITCH_DECLARE(switch_rtp *)switch_rtp_new(char *rx_ip,
switch_port_t rx_port,
char *tx_ip,
int tx_port,
switch_port_t tx_port,
int payload,
switch_rtp_flag_t flags,
const char **err,
switch_memory_pool *pool);
void switch_rtp_destroy(switch_rtp **rtp_session);
switch_socket_t *switch_rtp_get_rtp_socket(switch_rtp *rtp_session);
void switch_rtp_set_invald_handler(switch_rtp *rtp_session, switch_rtp_invalid_handler on_invalid);
int switch_rtp_read(switch_rtp *rtp_session, void *data, uint32_t datalen, int *payload_type);
int switch_rtp_zerocopy_read(switch_rtp *rtp_session, void **data, int *payload_type);
int switch_rtp_write(switch_rtp *rtp_session, void *data, int datalen, uint32_t ts);
int switch_rtp_write_payload(switch_rtp *rtp_session, void *data, int datalen, int payload, uint32_t ts, uint32_t mseq);
uint32_t switch_rtp_start(switch_rtp *rtp_session);
uint32_t switch_rtp_get_ssrc(switch_rtp *rtp_session);
void switch_rtp_killread(switch_rtp *rtp_session);
void switch_rtp_set_private(switch_rtp *rtp_session, void *private_data);
void *switch_rtp_get_private(switch_rtp *rtp_session);
#include <switch.h>
SWITCH_DECLARE(void) switch_rtp_destroy(switch_rtp **rtp_session);
SWITCH_DECLARE(switch_socket_t *)switch_rtp_get_rtp_socket(switch_rtp *rtp_session);
SWITCH_DECLARE(void) switch_rtp_set_invald_handler(switch_rtp *rtp_session, switch_rtp_invalid_handler on_invalid);
SWITCH_DECLARE(int) switch_rtp_read(switch_rtp *rtp_session, void *data, uint32_t datalen, int *payload_type);
SWITCH_DECLARE(int) switch_rtp_zerocopy_read(switch_rtp *rtp_session, void **data, int *payload_type);
SWITCH_DECLARE(int) switch_rtp_write(switch_rtp *rtp_session, void *data, int datalen, uint32_t ts);
SWITCH_DECLARE(int) switch_rtp_write_payload(switch_rtp *rtp_session, void *data, int datalen, uint8_t payload, uint32_t ts, uint16_t mseq);
SWITCH_DECLARE(uint32_t) switch_rtp_start(switch_rtp *rtp_session);
SWITCH_DECLARE(uint32_t) switch_rtp_get_ssrc(switch_rtp *rtp_session);
SWITCH_DECLARE(void) switch_rtp_killread(switch_rtp *rtp_session);
SWITCH_DECLARE(void) switch_rtp_set_private(switch_rtp *rtp_session, void *private_data);
SWITCH_DECLARE(void *)switch_rtp_get_private(switch_rtp *rtp_session);
#ifdef __cplusplus
}
@@ -131,7 +131,7 @@ struct private_object {
unsigned char out_digit_packet[4];
unsigned int out_digit_sofar;
unsigned int out_digit_dur;
unsigned int out_digit_seq;
uint16_t out_digit_seq;
int32_t timestamp_send;
int32_t timestamp_recv;
int32_t timestamp_dtmf;
+11 -11
View File
@@ -80,8 +80,8 @@ static struct {
int bytes_per_frame;
char *dialplan;
int port;
int rtp_start;
int rtp_end;
switch_port_t rtp_start;
switch_port_t rtp_end;
char *codec_string;
char *codec_order[SWITCH_MAX_CODECS];
int codec_order_last;
@@ -114,9 +114,9 @@ struct private_object {
sdp_message_t *remote_sdp;
sdp_message_t *local_sdp;
char remote_sdp_audio_ip[50];
int remote_sdp_audio_port;
switch_port_t remote_sdp_audio_port;
char local_sdp_audio_ip[50];
int local_sdp_audio_port;
switch_port_t local_sdp_audio_port;
char call_id[50];
int ssrc;
char last_digit;
@@ -129,13 +129,13 @@ struct private_object {
unsigned char out_digit_packet[4];
unsigned int out_digit_sofar;
unsigned int out_digit_dur;
unsigned int out_digit_seq;
uint16_t out_digit_seq;
};
static int next_rtp_port(void)
static switch_port_t next_rtp_port(void)
{
int port;
switch_port_t port;
switch_mutex_lock(globals.port_lock);
port = globals.rtp_start;
@@ -1176,7 +1176,7 @@ static switch_status exosip_create_call(eXosip_event_t * event)
remote_med = eXosip_get_audio_media(remote_sdp);
snprintf(tech_pvt->remote_sdp_audio_ip, 50, conn->c_addr);
tech_pvt->remote_sdp_audio_port = atoi(remote_med->m_port);
tech_pvt->remote_sdp_audio_port = (switch_port_t)atoi(remote_med->m_port);
snprintf(tech_pvt->call_id, sizeof(tech_pvt->call_id), "%d", event->cid);
eXosip_lock();
@@ -1346,7 +1346,7 @@ static void handle_answer(eXosip_event_t * event)
remote_med = eXosip_get_audio_media(remote_sdp);
/* Grab IP/port */
tech_pvt->remote_sdp_audio_port = atoi(remote_med->m_port);
tech_pvt->remote_sdp_audio_port = (switch_port_t)atoi(remote_med->m_port);
snprintf(tech_pvt->remote_sdp_audio_ip, 50, conn->c_addr);
/* Grab codec elements */
@@ -1576,9 +1576,9 @@ static int config_exosip(int reload)
globals.codec_order_last =
switch_separate_string(globals.codec_string, ',', globals.codec_order, SWITCH_MAX_CODECS);
} else if (!strcmp(var, "rtp_min_port")) {
globals.rtp_start = atoi(val);
globals.rtp_start = (switch_port_t)atoi(val);
} else if (!strcmp(var, "rtp_max_port")) {
globals.rtp_end = atoi(val);
globals.rtp_end = (switch_port_t)atoi(val);
} else if (!strcmp(var, "codec_ms")) {
globals.codec_ms = atoi(val);
} else if (!strcmp(var, "dtmf_duration")) {
+23 -23
View File
@@ -73,7 +73,7 @@ struct switch_rtp {
rtp_msg_t recv_msg;
srtp_ctx_t *recv_ctx;
uint32_t seq;
uint16_t seq;
uint32_t payload;
switch_rtp_invalid_handler invalid_handler;
@@ -98,10 +98,10 @@ static void init_rtp(void)
}
switch_rtp *switch_rtp_new(char *rx_ip,
int rx_port,
SWITCH_DECLARE(switch_rtp *)switch_rtp_new(char *rx_ip,
switch_port_t rx_port,
char *tx_ip,
int tx_port,
switch_port_t tx_port,
int payload,
switch_rtp_flag_t flags,
const char **err,
@@ -176,7 +176,7 @@ switch_rtp *switch_rtp_new(char *rx_ip,
rtp_session->send_msg.header.ts = 0;
rtp_session->send_msg.header.seq = (uint16_t) rand();
rtp_session->send_msg.header.m = 0;
rtp_session->send_msg.header.pt = htonl(payload);
rtp_session->send_msg.header.pt = (uint8_t)htonl(payload);
rtp_session->send_msg.header.version = 2;
rtp_session->send_msg.header.p = 0;
rtp_session->send_msg.header.x = 0;
@@ -187,7 +187,7 @@ switch_rtp *switch_rtp_new(char *rx_ip,
rtp_session->recv_msg.header.ts = 0;
rtp_session->recv_msg.header.seq = 0;
rtp_session->recv_msg.header.m = 0;
rtp_session->recv_msg.header.pt = htonl(payload);
rtp_session->recv_msg.header.pt = (uint8_t)htonl(payload);
rtp_session->recv_msg.header.version = 2;
rtp_session->recv_msg.header.p = 0;
rtp_session->recv_msg.header.x = 0;
@@ -201,7 +201,7 @@ switch_rtp *switch_rtp_new(char *rx_ip,
return rtp_session;
}
void switch_rtp_killread(switch_rtp *rtp_session)
SWITCH_DECLARE(void) switch_rtp_killread(switch_rtp *rtp_session)
{
apr_socket_shutdown(rtp_session->sock, APR_SHUTDOWN_READWRITE);
switch_clear_flag(rtp_session, SWITCH_RTP_FLAG_IO);
@@ -209,7 +209,7 @@ void switch_rtp_killread(switch_rtp *rtp_session)
}
void switch_rtp_destroy(switch_rtp **rtp_session)
SWITCH_DECLARE(void) switch_rtp_destroy(switch_rtp **rtp_session)
{
switch_rtp_killread(*rtp_session);
@@ -218,19 +218,19 @@ void switch_rtp_destroy(switch_rtp **rtp_session)
return;
}
switch_socket_t *switch_rtp_get_rtp_socket(switch_rtp *rtp_session)
SWITCH_DECLARE(switch_socket_t *)switch_rtp_get_rtp_socket(switch_rtp *rtp_session)
{
return rtp_session->sock;
}
void switch_rtp_set_invald_handler(switch_rtp *rtp_session, switch_rtp_invalid_handler on_invalid)
SWITCH_DECLARE(void) switch_rtp_set_invald_handler(switch_rtp *rtp_session, switch_rtp_invalid_handler on_invalid)
{
rtp_session->invalid_handler = on_invalid;
}
int switch_rtp_read(switch_rtp *rtp_session, void *data, uint32_t datalen, int *payload_type)
SWITCH_DECLARE(int) switch_rtp_read(switch_rtp *rtp_session, void *data, uint32_t datalen, int *payload_type)
{
switch_size_t bytes;
uint32_t bytes;
if (!switch_test_flag(rtp_session, SWITCH_RTP_FLAG_IO)) {
return -1;
@@ -257,9 +257,9 @@ int switch_rtp_read(switch_rtp *rtp_session, void *data, uint32_t datalen, int *
}
int switch_rtp_zerocopy_read(switch_rtp *rtp_session, void **data, int *payload_type)
SWITCH_DECLARE(int) switch_rtp_zerocopy_read(switch_rtp *rtp_session, void **data, int *payload_type)
{
switch_size_t bytes;
uint32_t bytes;
*data = NULL;
if (!switch_test_flag(rtp_session, SWITCH_RTP_FLAG_IO)) {
@@ -285,7 +285,7 @@ int switch_rtp_zerocopy_read(switch_rtp *rtp_session, void **data, int *payload_
return bytes - rtp_header_len;
}
int switch_rtp_write(switch_rtp *rtp_session, void *data, int datalen, uint32_t ts)
SWITCH_DECLARE(int) switch_rtp_write(switch_rtp *rtp_session, void *data, int datalen, uint32_t ts)
{
switch_size_t bytes;
@@ -304,10 +304,10 @@ int switch_rtp_write(switch_rtp *rtp_session, void *data, int datalen, uint32_t
bytes = datalen + rtp_header_len;
switch_socket_sendto(rtp_session->sock, rtp_session->remote_addr, 0, (void*)&rtp_session->send_msg, &bytes);
return bytes;
return (int)bytes;
}
int switch_rtp_write_payload(switch_rtp *rtp_session, void *data, int datalen, int payload, uint32_t ts, uint32_t mseq)
SWITCH_DECLARE(int) switch_rtp_write_payload(switch_rtp *rtp_session, void *data, int datalen, uint8_t payload, uint32_t ts, uint16_t mseq)
{
switch_size_t bytes;
@@ -317,32 +317,32 @@ int switch_rtp_write_payload(switch_rtp *rtp_session, void *data, int datalen, i
rtp_session->ts += ts;
rtp_session->send_msg.header.seq = htons(mseq);
rtp_session->send_msg.header.ts = htonl(rtp_session->ts);
rtp_session->send_msg.header.pt = htonl(payload);
rtp_session->send_msg.header.pt = (uint8_t)htonl(payload);
memcpy(rtp_session->send_msg.body, data, datalen);
bytes = datalen + rtp_header_len;
switch_socket_sendto(rtp_session->sock, rtp_session->remote_addr, 0, (void*)&rtp_session->send_msg, &bytes);
return bytes;
return (int)bytes;
}
uint32_t switch_rtp_start(switch_rtp *rtp_session)
SWITCH_DECLARE(uint32_t) switch_rtp_start(switch_rtp *rtp_session)
{
switch_set_flag(rtp_session, SWITCH_RTP_FLAG_IO);
return 0;
}
uint32_t switch_rtp_get_ssrc(switch_rtp *rtp_session)
SWITCH_DECLARE(uint32_t) switch_rtp_get_ssrc(switch_rtp *rtp_session)
{
return rtp_session->send_msg.header.ssrc;
}
void switch_rtp_set_private(switch_rtp *rtp_session, void *private_data)
SWITCH_DECLARE(void) switch_rtp_set_private(switch_rtp *rtp_session, void *private_data)
{
rtp_session->private_data = private_data;
}
void *switch_rtp_get_private(switch_rtp *rtp_session)
SWITCH_DECLARE(void *)switch_rtp_get_private(switch_rtp *rtp_session)
{
return rtp_session->private_data;
}