try out new builtin RTP using srtp lib

git-svn-id: http://svn.freeswitch.org/svn/freeswitch/trunk@1012 d0543943-73ff-0310-b7d9-9358b9ac24b2
This commit is contained in:
Anthony Minessale
2006-04-03 21:00:13 +00:00
parent e0fee29284
commit 828e03715f
15 changed files with 589 additions and 72 deletions
@@ -64,6 +64,8 @@ static void playback_function(switch_core_session *session, char *data)
channel = switch_core_session_get_channel(session);
assert(channel != NULL);
switch_channel_answer(channel);
if (switch_ivr_play_file(session, NULL, file_name, timer_name, on_dtmf, NULL, 0) != SWITCH_STATUS_SUCCESS) {
switch_channel_hangup(channel);
}
+1 -1
View File
@@ -3,7 +3,7 @@ LDFLAGS += -ldingaling -ljrtp
all: depends $(MODNAME).$(DYNAMIC_LIB_EXTEN)
depends:
MAKE=$(MAKE) $(BASE)/build/buildlib.sh $(BASE) install jrtplib --prefix=$(PREFIX) --disable-gst
#MAKE=$(MAKE) $(BASE)/build/buildlib.sh $(BASE) install jrtplib --prefix=$(PREFIX) --disable-gst
MAKE=$(MAKE) $(BASE)/build/buildlib.sh $(BASE) install iksemel-1.2.tar.gz --prefix=$(PREFIX)
MAKE=$(MAKE) $(BASE)/build/buildlib.sh $(BASE) install libdingaling --prefix=$(PREFIX)
+29 -24
View File
@@ -32,7 +32,6 @@
#include <switch.h>
#include <libdingaling.h>
#include <stun_parser.h>
#include <jrtplib3/jrtp4c.h>
#ifdef _MSC_VER
#include <Winsock2.h>
#else
@@ -113,7 +112,7 @@ struct private_object {
switch_codec_interface *codecs[SWITCH_MAX_CODECS];
unsigned int num_codecs;
int codec_index;
struct jrtp4c *rtp_session;
struct switch_rtp *rtp_session;
ldl_session_t *dlsession;
char *remote_ip;
uint16_t remote_port;
@@ -121,7 +120,7 @@ struct private_object {
char *remote_user;
unsigned int cand_id;
unsigned int desc_id;
jrtp_socket_t rtp_sock;
switch_raw_socket_t rtp_sock;
char last_digit;
unsigned int dc;
time_t last_digit_time;
@@ -177,7 +176,7 @@ static switch_status channel_write_frame(switch_core_session *session, switch_fr
static switch_status channel_kill_channel(switch_core_session *session, int sig);
static ldl_status handle_signalling(ldl_handle_t *handle, ldl_session_t *dlsession, ldl_signal_t signal, char *msg);
static ldl_status handle_response(ldl_handle_t *handle, char *id);
static void stun_callback(struct jrtp4c *jrtp4c, jrtp_socket_t sock, void *data, unsigned int len, uint32_t ip, uint16_t port);
static void stun_callback(struct switch_rtp *switch_rtp, switch_raw_socket_t sock, void *data, unsigned int len, uint32_t ip, uint16_t port);
static switch_status load_config(void);
@@ -361,6 +360,7 @@ static void *SWITCH_THREAD_FUNC negotiate_thread_run(switch_thread *thread, void
switch_core_session_set_read_codec(session, &tech_pvt->read_codec);
switch_core_session_set_write_codec(session, &tech_pvt->write_codec);
//switch_set_flag(tech_pvt, TFLAG_SILENCE);
//printf("WAIT %s %d\n", switch_channel_get_name(channel), switch_test_flag(tech_pvt, TFLAG_OUTBOUND));
@@ -465,7 +465,7 @@ static switch_status channel_on_hangup(switch_core_session *session)
}
if (tech_pvt->rtp_session) {
jrtp4c_destroy(&tech_pvt->rtp_session);
switch_rtp_destroy(&tech_pvt->rtp_session);
switch_console_printf(SWITCH_CHANNEL_CONSOLE, "NUKE RTP\n");
tech_pvt->rtp_session = NULL;
}
@@ -498,7 +498,7 @@ static switch_status channel_kill_channel(switch_core_session *session, int sig)
ldl_session_terminate(tech_pvt->dlsession);
}
if (tech_pvt->rtp_session) {
jrtp4c_killread(tech_pvt->rtp_session);
switch_rtp_killread(tech_pvt->rtp_session);
}
switch_console_printf(SWITCH_CHANNEL_CONSOLE, "%s CHANNEL KILL\n", switch_channel_get_name(channel));
}
@@ -582,7 +582,7 @@ static switch_status channel_read_frame(switch_core_session *session, switch_fra
while (!switch_test_flag(tech_pvt, TFLAG_BYE) && switch_test_flag(tech_pvt, TFLAG_IO) && tech_pvt->read_frame.datalen == 0) {
payload = -1;
tech_pvt->read_frame.datalen = jrtp4c_read(tech_pvt->rtp_session, tech_pvt->read_frame.data, sizeof(tech_pvt->read_buf), &payload);
tech_pvt->read_frame.datalen = switch_rtp_read(tech_pvt->rtp_session, tech_pvt->read_frame.data, sizeof(tech_pvt->read_buf), &payload);
if (switch_test_flag(tech_pvt, TFLAG_SILENCE)) {
if (tech_pvt->read_frame.datalen) {
switch_clear_flag(tech_pvt, TFLAG_SILENCE);
@@ -631,9 +631,9 @@ static switch_status channel_read_frame(switch_core_session *session, switch_fra
}
if (switch_test_flag(tech_pvt->profile, PFLAG_GENSILENCE)) {
if ((switch_test_flag(tech_pvt, TFLAG_SILENCE) || payload == 13) && tech_pvt->cng_frame.datalen) {
memset(tech_pvt->cng_frame.data, 255, tech_pvt->cng_frame.datalen);
*frame = &tech_pvt->cng_frame;
//printf("GENERATE bytes=%d payload=%d frames=%d samples=%d ms=%d ts=%d sampcount=%d\n", tech_pvt->cng_frame.datalen, payload, frames, samples, ms, tech_pvt->timestamp_recv, tech_pvt->read_frame.samples);
switch_set_flag(tech_pvt, TFLAG_SILENCE);
@@ -767,9 +767,11 @@ static switch_status channel_write_frame(switch_core_session *session, switch_fr
for (x = 0; x < loops; x++) {
jrtp4c_write_payload(tech_pvt->rtp_session, tech_pvt->out_digit_packet, 4, 101, ts, tech_pvt->out_digit_seq);
switch_rtp_write_payload(tech_pvt->rtp_session, tech_pvt->out_digit_packet, 4, 101, ts, tech_pvt->out_digit_seq);
/*
printf("Send %s packet for [%c] ts=%d sofar=%u dur=%d\n", loops == 1 ? "middle" : "end", tech_pvt->out_digit, ts,
tech_pvt->out_digit_sofar, duration);
*/
}
}
@@ -790,9 +792,11 @@ static switch_status channel_write_frame(switch_core_session *session, switch_fr
ts = tech_pvt->timestamp_dtmf += samples;
tech_pvt->out_digit_seq++;
for (x = 0; x < 3; x++) {
jrtp4c_write_payload(tech_pvt->rtp_session, tech_pvt->out_digit_packet, 4, 101, ts, tech_pvt->out_digit_seq);
switch_rtp_write_payload(tech_pvt->rtp_session, tech_pvt->out_digit_packet, 4, 101, ts, tech_pvt->out_digit_seq);
/*
printf("Send start packet for [%c] ts=%d sofar=%u dur=%d\n", tech_pvt->out_digit, ts,
tech_pvt->out_digit_sofar, 0);
*/
}
free(rdigit);
@@ -803,10 +807,10 @@ static switch_status channel_write_frame(switch_core_session *session, switch_fr
//printf("%s send %d bytes %d samples in %d frames taking up %d ms ts=%d\n", switch_channel_get_name(channel), frame->datalen, samples, frames, ms, tech_pvt->timestamp_send);
//printf("%s send %d bytes %d samples in %d frames ts=%d\n", switch_channel_get_name(channel), frame->datalen, samples, frames, tech_pvt->timestamp_send);
jrtp4c_write(tech_pvt->rtp_session, frame->data, (int) frame->datalen, samples);
switch_rtp_write(tech_pvt->rtp_session, frame->data, (int) frame->datalen, samples);
tech_pvt->timestamp_send += (int) samples;
switch_clear_flag(tech_pvt, TFLAG_WRITING);
@@ -1335,21 +1339,22 @@ static ldl_status handle_signalling(ldl_handle_t *handle, ldl_session_t *dlsessi
const char *err;
switch_console_printf(SWITCH_CHANNEL_CONSOLE, "SETUP RTP %s:%d -> %s:%d\n", profile->ip, cand[0].port, tech_pvt->remote_ip, tech_pvt->remote_port);
if (!(tech_pvt->rtp_session = jrtp4c_new(profile->ip,
cand[0].port,
tech_pvt->remote_ip,
tech_pvt->remote_port,
tech_pvt->codec_num,
8000, &err))) {
if (!(tech_pvt->rtp_session = switch_rtp_new(profile->ip,
cand[0].port,
tech_pvt->remote_ip,
tech_pvt->remote_port,
tech_pvt->codec_num,
switch_test_flag(tech_pvt->profile, PFLAG_GENSILENCE) ? SWITCH_RTP_NOBLOCK : 0,
&err, switch_core_session_get_pool(tech_pvt->session)))) {
switch_console_printf(SWITCH_CHANNEL_CONSOLE, "RTP ERROR %s\n", err);
switch_channel_hangup(channel);
return LDL_STATUS_FALSE;
}
tech_pvt->rtp_sock = jrtp4c_get_rtp_socket(tech_pvt->rtp_session);
jrtp4c_set_invald_handler(tech_pvt->rtp_session, stun_callback);
jrtp4c_set_private(tech_pvt->rtp_session, tech_pvt);
tech_pvt->rtp_sock = switch_rtp_get_rtp_socket(tech_pvt->rtp_session);
switch_rtp_set_invald_handler(tech_pvt->rtp_session, stun_callback);
switch_rtp_set_private(tech_pvt->rtp_session, tech_pvt);
switch_set_flag(tech_pvt, TFLAG_RTP_READY);
jrtp4c_start(tech_pvt->rtp_session);
switch_rtp_start(tech_pvt->rtp_session);
}
return LDL_STATUS_SUCCESS;
@@ -1386,7 +1391,7 @@ static ldl_status handle_response(ldl_handle_t *handle, char *id)
return LDL_STATUS_SUCCESS;
}
static void stun_callback(struct jrtp4c *jrtp4c, jrtp_socket_t sock, void *data, unsigned int len, uint32_t ip, uint16_t port)
static void stun_callback(struct switch_rtp *switch_rtp, switch_raw_socket_t sock, void *data, unsigned int len, uint32_t ip, uint16_t port)
{
stun_packet_t *packet;
stun_packet_attribute_t *attr;
@@ -1394,7 +1399,7 @@ static void stun_callback(struct jrtp4c *jrtp4c, jrtp_socket_t sock, void *data,
struct private_object *tech_pvt;
unsigned char buf[512] = {0};
tech_pvt = jrtp4c_get_private(jrtp4c);
tech_pvt = switch_rtp_get_private(switch_rtp);
assert(tech_pvt != NULL);
memcpy(buf, data, len);
+1 -1
View File
@@ -10,7 +10,7 @@ endif
all: depends $(OBJS) $(MODNAME).$(DYNAMIC_LIB_EXTEN)
depends:
MAKE=$(MAKE) $(BASE)/build/buildlib.sh $(BASE) install jrtplib --prefix=$(PREFIX) --disable-gst
#MAKE=$(MAKE) $(BASE)/build/buildlib.sh $(BASE) install jrtplib --prefix=$(PREFIX) --disable-gst
MAKE=$(MAKE) $(BASE)/build/buildlib.sh $(BASE) install libosip2-2.2.2.tar.gz --prefix=$(PREFIX)
MAKE=$(MAKE) $(BASE)/build/buildlib.sh $(BASE) install libeXosip2-2.2.3-pre1.tar.gz --disable-josua --prefix=$(PREFIX)
+23 -23
View File
@@ -32,7 +32,6 @@
#define HAVE_APR
#include <switch.h>
#include <jrtplib3/jrtp4c.h>
#include <eXosip2/eXosip.h>
#include <osip2/osip_mt.h>
#include <osip_rfc3264.h>
@@ -101,8 +100,7 @@ struct private_object {
switch_frame cng_frame;
switch_codec read_codec;
switch_codec write_codec;
unsigned char read_buf[SWITCH_RECCOMMENDED_BUFFER_SIZE];
unsigned char cng_buf[SWITCH_RECCOMMENDED_BUFFER_SIZE];
unsigned char cng_buf[320];
switch_caller_profile *caller_profile;
int cid;
int did;
@@ -111,7 +109,7 @@ struct private_object {
int32_t timestamp_recv;
int32_t timestamp_dtmf;
int payload_num;
struct jrtp4c *rtp_session;
struct switch_rtp *rtp_session;
struct osip_rfc3264 *sdp_config;
sdp_message_t *remote_sdp;
sdp_message_t *local_sdp;
@@ -248,8 +246,8 @@ static switch_status exosip_on_init(switch_core_session *session)
tech_pvt = switch_core_session_get_private(session);
assert(tech_pvt != NULL);
tech_pvt->read_frame.data = tech_pvt->read_buf;
tech_pvt->read_frame.buflen = sizeof(tech_pvt->read_buf);
tech_pvt->read_frame.data = tech_pvt->cng_buf;
tech_pvt->read_frame.buflen = sizeof(tech_pvt->cng_buf);
tech_pvt->cng_frame.data = tech_pvt->cng_buf;
tech_pvt->cng_frame.buflen = sizeof(tech_pvt->cng_buf);
@@ -422,11 +420,11 @@ static void deactivate_rtp(struct private_object *tech_pvt)
loops++;
}
/*
if ((sock = jrtp4c_get_rtp_socket(tech_pvt->rtp_session)) > -1) {
if ((sock = switch_rtp_get_rtp_socket(tech_pvt->rtp_session)) > -1) {
close(sock);
}
*/
jrtp4c_destroy(&tech_pvt->rtp_session);
switch_rtp_destroy(&tech_pvt->rtp_session);
tech_pvt->rtp_session = NULL;
switch_mutex_unlock(tech_pvt->rtp_lock);
}
@@ -469,17 +467,18 @@ static void activate_rtp(struct private_object *tech_pvt)
tech_pvt->remote_sdp_audio_port, tech_pvt->read_codec.codec_interface->ianacode, ms);
tech_pvt->rtp_session = jrtp4c_new(tech_pvt->local_sdp_audio_ip,
tech_pvt->local_sdp_audio_port,
tech_pvt->remote_sdp_audio_ip,
tech_pvt->remote_sdp_audio_port,
tech_pvt->read_codec.codec_interface->ianacode,
tech_pvt->read_codec.implementation->samples_per_second, &err);
tech_pvt->rtp_session = switch_rtp_new(tech_pvt->local_sdp_audio_ip,
tech_pvt->local_sdp_audio_port,
tech_pvt->remote_sdp_audio_ip,
tech_pvt->remote_sdp_audio_port,
tech_pvt->read_codec.codec_interface->ianacode,
0,
&err, switch_core_session_get_pool(tech_pvt->session));
if (tech_pvt->rtp_session) {
tech_pvt->ssrc = jrtp4c_get_ssrc(tech_pvt->rtp_session);
jrtp4c_start(tech_pvt->rtp_session);
tech_pvt->ssrc = switch_rtp_get_ssrc(tech_pvt->rtp_session);
switch_rtp_start(tech_pvt->rtp_session);
switch_set_flag(tech_pvt, TFLAG_RTP);
} else {
switch_channel *channel = switch_core_session_get_channel(tech_pvt->session);
@@ -565,7 +564,7 @@ static switch_status exosip_read_frame(switch_core_session *session, switch_fram
while (!switch_test_flag(tech_pvt, TFLAG_BYE) && switch_test_flag(tech_pvt, TFLAG_IO)
&& tech_pvt->read_frame.datalen == 0) {
now = switch_time_now();
tech_pvt->read_frame.datalen = jrtp4c_read(tech_pvt->rtp_session, tech_pvt->read_frame.data, sizeof(tech_pvt->read_buf), &payload);
tech_pvt->read_frame.datalen = switch_rtp_zerocopy_read(tech_pvt->rtp_session, &tech_pvt->read_frame.data, &payload);
if (switch_test_flag(tech_pvt, TFLAG_SILENCE)) {
if (tech_pvt->read_frame.datalen) {
@@ -659,7 +658,8 @@ static switch_status exosip_read_frame(switch_core_session *session, switch_fram
}
} else {
memset(tech_pvt->read_buf, 0, 160);
memset(tech_pvt->cng_buf, 0, 160);
tech_pvt->read_frame.data = tech_pvt->cng_buf;
tech_pvt->read_frame.datalen = 160;
}
@@ -735,7 +735,7 @@ static switch_status exosip_write_frame(switch_core_session *session, switch_fra
for (x = 0; x < loops; x++) {
jrtp4c_write_payload(tech_pvt->rtp_session, tech_pvt->out_digit_packet, 4, 101, ts, tech_pvt->out_digit_seq);
switch_rtp_write_payload(tech_pvt->rtp_session, tech_pvt->out_digit_packet, 4, 101, ts, tech_pvt->out_digit_seq);
printf("Send %s packet for [%c] ts=%d sofar=%u dur=%d\n",
loops == 1 ? "middle" : "end",
tech_pvt->out_digit,
@@ -762,7 +762,7 @@ static switch_status exosip_write_frame(switch_core_session *session, switch_fra
ts = tech_pvt->timestamp_dtmf += samples;
tech_pvt->out_digit_seq++;
for (x = 0; x < 3; x++) {
jrtp4c_write_payload(tech_pvt->rtp_session, tech_pvt->out_digit_packet, 4, 101, ts, tech_pvt->out_digit_seq);
switch_rtp_write_payload(tech_pvt->rtp_session, tech_pvt->out_digit_packet, 4, 101, ts, tech_pvt->out_digit_seq);
printf("Send start packet for [%c] ts=%d sofar=%u dur=%d\n", tech_pvt->out_digit, ts,
tech_pvt->out_digit_sofar, 0);
}
@@ -776,7 +776,7 @@ static switch_status exosip_write_frame(switch_core_session *session, switch_fra
//printf("%s %s->%s send %d bytes %d samples in %d frames taking up %d ms ts=%d\n", switch_channel_get_name(channel), tech_pvt->local_sdp_audio_ip, tech_pvt->remote_sdp_audio_ip, frame->datalen, samples, frames, ms, tech_pvt->timestamp_send);
jrtp4c_write(tech_pvt->rtp_session, frame->data, (int) frame->datalen, samples);
switch_rtp_write(tech_pvt->rtp_session, frame->data, (int) frame->datalen, samples);
tech_pvt->timestamp_send += (int) samples;
switch_clear_flag(tech_pvt, TFLAG_WRITING);
@@ -801,7 +801,7 @@ static switch_status exosip_kill_channel(switch_core_session *session, int sig)
switch_set_flag(tech_pvt, TFLAG_BYE);
if (tech_pvt->rtp_session) {
jrtp4c_killread(tech_pvt->rtp_session);
switch_rtp_killread(tech_pvt->rtp_session);
}
return SWITCH_STATUS_SUCCESS;