git-svn-id: http://svn.freeswitch.org/svn/freeswitch/trunk@1222 d0543943-73ff-0310-b7d9-9358b9ac24b2
This commit is contained in:
Anthony Minessale 2006-04-21 22:31:08 +00:00
parent c0e494a7d6
commit a9f86cb58a
17 changed files with 382 additions and 36 deletions

View File

@ -123,6 +123,10 @@ rtp-ip => guess
; exosip/!myrealm!1000@dest
;srtp:myrealm => ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff
; VAD choose one (out is a good choice);
; vad => in
; vad => out
; vad => both
;---- WOOMERA PROTOCOL
;--------------------------------------------------------------------------------
@ -262,3 +266,8 @@ codec_prefs => PCMU
;rtp-ip => my_lan_ip
;ext-rtp-ip => stun:stun.server.com
exten => 1000
; VAD choose one
; vad => in
; vad => out
; vad => both

View File

@ -77,8 +77,12 @@ struct switch_caller_profile {
char *ani;
/*! ANI II (when applicable) */
char *ani2;
/*! RDNIS */
char *rdnis;
/*! Destination Number */
char *destination_number;
/*! channel type */
char *source;
/*! channel name */
char *chan_name;
/*! unique id */
@ -154,6 +158,8 @@ SWITCH_DECLARE(switch_caller_profile *) switch_caller_profile_new(switch_memory_
char *network_addr,
char *ani,
char *ani2,
char *rdnis,
char *source,
char *destination_number);
/*!

View File

@ -263,6 +263,23 @@ SWITCH_DECLARE(switch_status) switch_rtp_zerocopy_read_frame(switch_rtp *rtp_ses
*/
SWITCH_DECLARE(int) switch_rtp_write(switch_rtp *rtp_session, void *data, uint32_t datalen, uint32_t ts, switch_frame_flag *flags);
/*!
\brief Enable VAD on an RTP Session
\param rtp_session the RTP session
\param session the core session associated with the RTP session
\param codec the codec the channel is currenty using
\param flags flags for control
\return SWITCH_STAUTS_SUCCESS on success
*/
SWITCH_DECLARE(switch_status) switch_rtp_enable_vad(switch_rtp *rtp_session, switch_core_session *session, switch_codec *codec, switch_vad_flag_t flags);
/*!
\brief Disable VAD on an RTP Session
\param rtp_session the RTP session
\return SWITCH_STAUTS_SUCCESS on success
*/
SWITCH_DECLARE(switch_status) switch_rtp_disable_vad(switch_rtp *rtp_session);
/*!
\brief Write data to a given RTP session
\param rtp_session the RTP session to write to

View File

@ -94,27 +94,47 @@ SWITCH_DECLARE_DATA extern switch_directories SWITCH_GLOBAL_dirs;
#define SWITCH_TRUE 1
#define SWITCH_FALSE 0
/*!
\enum switch_vad_flags
\brief RTP Related Flags
<pre>
SWITCH_VAD_FLAG_TALKING - Currently Talking
SWITCH_VAD_FLAG_EVENTS_TALK - Fire events when talking is detected
SWITCH_VAD_FLAG_EVENTS_NOTALK - Fire events when not talking is detected
</pre>
*/
typedef enum {
SWITCH_VAD_FLAG_TALKING = ( 1 << 0 ),
SWITCH_VAD_FLAG_EVENTS_TALK = ( 1 << 1 ),
SWITCH_VAD_FLAG_EVENTS_NOTALK = ( 1 << 2 ),
} switch_vad_flag_t;
/*!
\enum switch_rtp_flag_t
\brief RTP Related Flags
<pre>
SWITCH_RTP_FLAG_NOBLOCK - Do not block
SWITCH_RTP_FLAG_IO - IO is ready
SWITCH_RTP_FLAG_USE_TIMER - Timeout Reads and replace with a CNG Frame
SWITCH_RTP_FLAG_SECURE - Secure RTP
SWITCH_RTP_FLAG_AUTOADJ - Auto-Adjust the dest based on the source
SWITCH_RTP_FLAG_RAW_WRITE - Try to forward packets unscathed
SWITCH_RTP_FLAG_GOOGLEHACK - Convert payload from 102 to 97
SWITCH_RTP_FLAG_NOBLOCK - Do not block
SWITCH_RTP_FLAG_IO - IO is ready
SWITCH_RTP_FLAG_USE_TIMER - Timeout Reads and replace with a CNG Frame
SWITCH_RTP_FLAG_TIMER_RECLOCK - Resync the timer to the current clock on slips
SWITCH_RTP_FLAG_SECURE - Secure RTP
SWITCH_RTP_FLAG_AUTOADJ - Auto-Adjust the dest based on the source
SWITCH_RTP_FLAG_RAW_WRITE - Try to forward packets unscathed
SWITCH_RTP_FLAG_GOOGLEHACK - Convert payload from 102 to 97
SWITCH_RTP_FLAG_VAD - Enable VAD
</pre>
*/
typedef enum {
SWITCH_RTP_FLAG_NOBLOCK = ( 1 << 0),
SWITCH_RTP_FLAG_IO = (1 << 1),
SWITCH_RTP_FLAG_USE_TIMER = (1 << 2),
SWITCH_RTP_FLAG_SECURE = (1 << 3),
SWITCH_RTP_FLAG_AUTOADJ = (1 << 4),
SWITCH_RTP_FLAG_RAW_WRITE = (1 << 5),
SWITCH_RTP_FLAG_GOOGLEHACK = (1 << 6)
SWITCH_RTP_FLAG_TIMER_RECLOCK = (1 << 3),
SWITCH_RTP_FLAG_SECURE = (1 << 4),
SWITCH_RTP_FLAG_AUTOADJ = (1 << 5),
SWITCH_RTP_FLAG_RAW_WRITE = (1 << 6),
SWITCH_RTP_FLAG_GOOGLEHACK = (1 << 7),
SWITCH_RTP_FLAG_VAD = (1 << 8)
} switch_rtp_flag_t;
/*!
@ -484,6 +504,8 @@ typedef enum {
SWITCH_EVENT_SHUTDOWN - The system has been shutdown
SWITCH_EVENT_PUBLISH - Publish
SWITCH_EVENT_UNPUBLISH - UnPublish
SWITCH_EVENT_TALK - Talking Detected
SWITCH_EVENT_NOTALK - Not Talking Detected
SWITCH_EVENT_ALL - All events at once
</pre>
@ -505,6 +527,8 @@ typedef enum {
SWITCH_EVENT_SHUTDOWN,
SWITCH_EVENT_PUBLISH,
SWITCH_EVENT_UNPUBLISH,
SWITCH_EVENT_TALK,
SWITCH_EVENT_NOTALK,
SWITCH_EVENT_ALL
} switch_event_t;

View File

@ -59,7 +59,12 @@ static void audio_bridge_function(switch_core_session *session, char *data)
caller_caller_profile->dialplan,
caller_caller_profile->caller_id_name,
caller_caller_profile->caller_id_number,
caller_caller_profile->network_addr, NULL, NULL, chan_data);
caller_caller_profile->network_addr,
NULL,
NULL,
caller_caller_profile->rdnis,
caller_caller_profile->source,
chan_data);

View File

@ -82,6 +82,11 @@ static switch_caller_extension *dialplan_hunt(switch_core_session *session)
skip = 1;
} else if (!strcasecmp(exten_name, "inbound") && switch_channel_test_flag(channel, CF_OUTBOUND)) {
skip = 1;
} else if (*exten_name == 's' && *(exten_name+1) == ':') {
exten_name += 2;
if (strcasecmp(exten_name, caller_profile->source)) {
skip = 1;
}
}
}

View File

@ -51,6 +51,9 @@ typedef enum {
TFLAG_CODEC_READY = (1 << 8),
TFLAG_TRANSPORT = (1 << 9),
TFLAG_ANSWER = (1 << 10),
TFLAG_VAD_IN = ( 1 << 11),
TFLAG_VAD_OUT = ( 1 << 12),
TFLAG_VAD = ( 1 << 13)
} TFLAGS;
typedef enum {
@ -83,8 +86,8 @@ struct mdl_profile {
char *extip;
char *lanaddr;
char *exten;
unsigned int flags;
ldl_handle_t *handle;
unsigned int flags;
};
struct private_object {
@ -282,9 +285,16 @@ static int activate_rtp(struct private_object *tech_pvt)
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "RTP ERROR %s\n", err);
switch_channel_hangup(channel);
return -1;
} else {
uint8_t vad_in = switch_test_flag(tech_pvt, TFLAG_VAD_IN) ? 1 : 0;
uint8_t vad_out = switch_test_flag(tech_pvt, TFLAG_VAD_OUT) ? 1 : 0;
uint8_t inb = switch_test_flag(tech_pvt, TFLAG_OUTBOUND) ? 0 : 1;
switch_rtp_activate_ice(tech_pvt->rtp_session, tech_pvt->remote_user, tech_pvt->local_user);
if ((vad_in && inb) || (vad_out && !inb)) {
switch_rtp_enable_vad(tech_pvt->rtp_session, tech_pvt->session, &tech_pvt->read_codec, SWITCH_VAD_FLAG_TALKING);
switch_set_flag(tech_pvt, TFLAG_VAD);
}
}
switch_rtp_activate_ice(tech_pvt->rtp_session, tech_pvt->remote_user, tech_pvt->local_user);
return 0;
}
@ -1017,6 +1027,8 @@ static switch_status channel_outgoing_channel(switch_core_session *session, swit
switch_core_session_add_stream(*new_session, NULL);
if ((tech_pvt = (struct private_object *) switch_core_session_alloc(*new_session, sizeof(struct private_object))) != 0) {
memset(tech_pvt, 0, sizeof(*tech_pvt));
tech_pvt->flags |= globals.flags;
tech_pvt->flags |= mdl_profile->flags;
channel = switch_core_session_get_channel(*new_session);
switch_core_session_set_private(*new_session, tech_pvt);
tech_pvt->session = *new_session;
@ -1167,6 +1179,7 @@ static switch_status load_config(void)
globals.codec_rates_last =
switch_separate_string(globals.codec_rates_string, ',', globals.codec_rates, SWITCH_MAX_CODECS);
}
} else if (!strcasecmp(cfg.category, "interface")) {
if (!globals.init) {
ldl_global_init(globals.debug);
@ -1204,6 +1217,17 @@ static switch_status load_config(void)
profile->lanaddr = switch_core_strdup(module_pool, val);
} else if (!strcmp(var, "exten")) {
profile->exten = switch_core_strdup(module_pool, val);
} else if (!strcmp(var, "vad")) {
if (!strcasecmp(val, "in")) {
switch_set_flag(profile, TFLAG_VAD_IN);
} else if (!strcasecmp(val, "out")) {
switch_set_flag(profile, TFLAG_VAD_OUT);
} else if (!strcasecmp(val, "both")) {
switch_set_flag(profile, TFLAG_VAD_IN);
switch_set_flag(profile, TFLAG_VAD_OUT);
} else {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Invald option %s for VAD\n", val);
}
}
}
}
@ -1262,6 +1286,8 @@ static ldl_status handle_signalling(ldl_handle_t *handle, ldl_session_t *dlsessi
switch_core_session_add_stream(session, NULL);
if ((tech_pvt = (struct private_object *) switch_core_session_alloc(session, sizeof(struct private_object))) != 0) {
memset(tech_pvt, 0, sizeof(*tech_pvt));
tech_pvt->flags |= globals.flags;
tech_pvt->flags |= profile->flags;
channel = switch_core_session_get_channel(session);
switch_core_session_set_private(session, tech_pvt);
tech_pvt->session = session;
@ -1269,6 +1295,7 @@ static ldl_status handle_signalling(ldl_handle_t *handle, ldl_session_t *dlsessi
tech_pvt->profile = profile;
tech_pvt->local_port = switch_rtp_request_port();
switch_set_flag(tech_pvt, TFLAG_ANSWER);
} else {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "Hey where is my memory pool?\n");
switch_core_session_destroy(&session);
@ -1284,6 +1311,8 @@ static ldl_status handle_signalling(ldl_handle_t *handle, ldl_session_t *dlsessi
ldl_session_get_ip(dlsession),
NULL,
NULL,
NULL,
(char *)modname,
profile->exten)) != 0) {
char name[128];
snprintf(name, sizeof(name), "DingaLing/%s-%04x", tech_pvt->caller_profile->destination_number,

View File

@ -67,8 +67,10 @@ typedef enum {
TFLAG_BYE = (1 << 8),
TFLAG_ANS = (1 << 9),
TFLAG_EARLY_MEDIA = (1 << 10),
TFLAG_SECURE = (1 << 11)
TFLAG_SECURE = (1 << 11),
TFLAG_VAD_IN = ( 1 << 12),
TFLAG_VAD_OUT = ( 1 << 13),
TFLAG_VAD = ( 1 << 14)
} TFLAGS;
@ -505,13 +507,22 @@ static switch_status activate_rtp(struct private_object *tech_pvt)
tech_pvt->read_codec.codec_interface->ianacode,
tech_pvt->read_codec.implementation->encoded_bytes_per_frame,
ms,
SWITCH_RTP_FLAG_NOBLOCK | SWITCH_RTP_FLAG_RAW_WRITE,
SWITCH_RTP_FLAG_USE_TIMER | SWITCH_RTP_FLAG_TIMER_RECLOCK | SWITCH_RTP_FLAG_RAW_WRITE,
key,
&err, switch_core_session_get_pool(tech_pvt->session));
if (tech_pvt->rtp_session) {
uint8_t vad_in = switch_test_flag(tech_pvt, TFLAG_VAD_IN) ? 1 : 0;
uint8_t vad_out = switch_test_flag(tech_pvt, TFLAG_VAD_OUT) ? 1 : 0;
uint8_t inb = switch_test_flag(tech_pvt, TFLAG_OUTBOUND) ? 0 : 1;
tech_pvt->ssrc = switch_rtp_get_ssrc(tech_pvt->rtp_session);
switch_set_flag(tech_pvt, TFLAG_RTP);
if ((vad_in && inb) || (vad_out && !inb)) {
switch_rtp_enable_vad(tech_pvt->rtp_session, tech_pvt->session, &tech_pvt->read_codec, SWITCH_VAD_FLAG_TALKING);
switch_set_flag(tech_pvt, TFLAG_VAD);
}
} else {
switch_channel *channel = switch_core_session_get_channel(tech_pvt->session);
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "RTP REPORTS ERROR: [%s]\n", err);
@ -965,6 +976,7 @@ static switch_status exosip_outgoing_channel(switch_core_session *session, switc
if ((tech_pvt =
(struct private_object *) switch_core_session_alloc(*new_session, sizeof(struct private_object))) != 0) {
memset(tech_pvt, 0, sizeof(*tech_pvt));
tech_pvt->flags = globals.flags;
channel = switch_core_session_get_channel(*new_session);
switch_core_session_set_private(*new_session, tech_pvt);
tech_pvt->session = *new_session;
@ -1097,6 +1109,7 @@ static switch_status exosip_create_call(eXosip_event_t * event)
switch_core_session_add_stream(session, NULL);
if ((tech_pvt = (struct private_object *) switch_core_session_alloc(session, sizeof(struct private_object))) != 0) {
memset(tech_pvt, 0, sizeof(*tech_pvt));
tech_pvt->flags = globals.flags;
channel = switch_core_session_get_channel(session);
switch_core_session_set_private(session, tech_pvt);
tech_pvt->session = session;
@ -1113,8 +1126,6 @@ static switch_status exosip_create_call(eXosip_event_t * event)
tech_pvt->realm = switch_core_session_strdup(session, osip_header_get_value(tedious));
}
if (!(from = osip_message_get_from(event->request))) {
switch_core_session_destroy(&session);
return SWITCH_STATUS_MEMERR;
@ -1148,7 +1159,11 @@ static switch_status exosip_create_call(eXosip_event_t * event)
displayname,
username,
event->request->from->url->host,
NULL, NULL, event->request->req_uri->username)) != 0) {
NULL,
NULL,
NULL,
(char *)modname,
event->request->req_uri->username)) != 0) {
switch_channel_set_caller_profile(channel, tech_pvt->caller_profile);
}
@ -1666,6 +1681,17 @@ static int config_exosip(int reload)
globals.debug = atoi(val);
} else if (!strcmp(var, "port")) {
globals.port = atoi(val);
} else if (!strcmp(var, "vad")) {
if (!strcasecmp(val, "in")) {
switch_set_flag(&globals, TFLAG_VAD_IN);
} else if (!strcasecmp(val, "out")) {
switch_set_flag(&globals, TFLAG_VAD_OUT);
} else if (!strcasecmp(val, "both")) {
switch_set_flag(&globals, TFLAG_VAD_IN);
switch_set_flag(&globals, TFLAG_VAD_OUT);
} else {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Invald option %s for VAD\n", val);
}
} else if (!strcmp(var, "ext-rtp-ip")) {
set_global_extrtpip(val);
} else if (!strcmp(var, "rtp-ip")) {

View File

@ -1001,7 +1001,10 @@ SWITCH_MOD_DECLARE(switch_status) switch_module_runtime(void)
iaxevent->ies.calling_number,
iax_get_peer_ip(iaxevent->session),
iaxevent->ies.calling_ani,
NULL, iaxevent->ies.called_number)) != 0) {
NULL,
NULL,
(char *)modname,
iaxevent->ies.called_number)) != 0) {
char name[128];
snprintf(name, sizeof(name), "IAX/%s-%04x", tech_pvt->caller_profile->destination_number,
rand() & 0xffff);

View File

@ -811,7 +811,7 @@ static switch_status place_call(char *dest, char *out, size_t outlen)
if ((tech_pvt->caller_profile = switch_caller_profile_new(switch_core_session_get_pool(session),
globals.dialplan,
globals.cid_name,
globals.cid_num, NULL, NULL, NULL, dest)) != 0) {
globals.cid_num, NULL, NULL, NULL, NULL, (char *)modname, dest)) != 0) {
char name[128];
snprintf(name, sizeof(name), "PortAudio/%s-%04x",
tech_pvt->caller_profile->destination_number ? tech_pvt->caller_profile->

View File

@ -1133,6 +1133,8 @@ static int on_ring(struct sangoma_pri *spri, sangoma_pri_event_t event_type, pri
event->ring.callingani,
switch_strlen_zero(ani2str) ? NULL : ani2str,
NULL,
NULL,
(char *)modname,
event->ring.callednum))) {
switch_channel_set_caller_profile(channel, tech_pvt->caller_profile);
}

View File

@ -375,6 +375,7 @@ static switch_status woomerachan_read_frame(switch_core_session *session, switch
switch_channel *channel = NULL;
struct private_object *tech_pvt = NULL;
switch_frame *pframe;
switch_size_t len;
channel = switch_core_session_get_channel(session);
assert(channel != NULL);
@ -393,8 +394,9 @@ static switch_status woomerachan_read_frame(switch_core_session *session, switch
pframe = &tech_pvt->frame;
*frame = pframe;
pframe->datalen = sizeof(tech_pvt->databuf);
if (switch_socket_recvfrom(tech_pvt->udpread, tech_pvt->udp_socket, 0, tech_pvt->databuf, &pframe->datalen) == SWITCH_STATUS_SUCCESS) {
len = sizeof(tech_pvt->databuf);
if (switch_socket_recvfrom(tech_pvt->udpread, tech_pvt->udp_socket, 0, tech_pvt->databuf, &len) == SWITCH_STATUS_SUCCESS) {
pframe->datalen = len;
pframe->samples = (int) pframe->datalen / 2;
return SWITCH_STATUS_SUCCESS;
}
@ -407,8 +409,9 @@ static switch_status woomerachan_write_frame(switch_core_session *session, switc
{
switch_channel *channel = NULL;
struct private_object *tech_pvt = NULL;
switch_size_t len;
//switch_frame *pframe;
channel = switch_core_session_get_channel(session);
assert(channel != NULL);
@ -420,7 +423,9 @@ static switch_status woomerachan_write_frame(switch_core_session *session, switc
}
//pframe = &tech_pvt->frame;
if (switch_socket_sendto(tech_pvt->udp_socket, tech_pvt->udpwrite, 0, frame->data, &frame->datalen) == SWITCH_STATUS_SUCCESS) {
len = frame->datalen;
if (switch_socket_sendto(tech_pvt->udp_socket, tech_pvt->udpwrite, 0, frame->data, &len) == SWITCH_STATUS_SUCCESS) {
frame->datalen = len;
return SWITCH_STATUS_SUCCESS;
}
@ -1063,7 +1068,7 @@ static void *woomera_channel_thread_run(switch_thread *thread, void *obj)
if ((tech_pvt->caller_profile = switch_caller_profile_new(switch_core_session_get_pool(session),
tech_pvt->profile->dialplan,
cid_name, cid_num, ip, NULL, NULL, exten)) != 0) {
cid_name, cid_num, ip, NULL, NULL, NULL, (char *)modname, exten)) != 0) {
char name[128];
snprintf(name, sizeof(name), "Woomera/%s-%04x", tech_pvt->caller_profile->destination_number,
rand() & 0xffff);

View File

@ -979,6 +979,7 @@ static JSBool session_construct(JSContext *cx, JSObject *obj, uintN argc, jsval
char *network_addr = "";
char *ani = "";
char *ani2 = "";
char *rdnis = "";
*rval = BOOLEAN_TO_JSVAL( JS_FALSE );
@ -1010,13 +1011,16 @@ static JSBool session_construct(JSContext *cx, JSObject *obj, uintN argc, jsval
if (argc > 8) {
ani2 = JS_GetStringBytes(JS_ValueToString(cx, argv[8]));
}
if (argc > 9) {
rdnis = JS_GetStringBytes(JS_ValueToString(cx, argv[9]));
}
if (switch_core_new_memory_pool(&pool) != SWITCH_STATUS_SUCCESS) {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CRIT, "OH OH no pool\n");
return JS_FALSE;
}
caller_profile = switch_caller_profile_new(pool, dialplan, cid_name, cid_num, network_addr, ani, ani2, dest);
caller_profile = switch_caller_profile_new(pool, dialplan, cid_name, cid_num, network_addr, ani, ani2, rdnis, (char *)modname, dest);
if (switch_core_session_outgoing_channel(session, channel_type, caller_profile, &peer_session, pool) == SWITCH_STATUS_SUCCESS) {
jss = switch_core_session_alloc(peer_session, sizeof(*jss));
jss->session = peer_session;

View File

@ -36,7 +36,11 @@ SWITCH_DECLARE(switch_caller_profile *) switch_caller_profile_new(switch_memory_
char *caller_id_name,
char *caller_id_number,
char *network_addr,
char *ani, char *ani2, char *destination_number)
char *ani,
char *ani2,
char *rdnis,
char *source,
char *destination_number)
{
@ -49,6 +53,8 @@ SWITCH_DECLARE(switch_caller_profile *) switch_caller_profile_new(switch_memory_
profile->network_addr = switch_core_strdup(pool, network_addr);
profile->ani = switch_core_strdup(pool, ani);
profile->ani2 = switch_core_strdup(pool, ani2);
profile->rdnis = switch_core_strdup(pool, rdnis);
profile->source = switch_core_strdup(pool, source);
profile->destination_number = switch_core_strdup(pool, destination_number);
}
@ -56,8 +62,8 @@ SWITCH_DECLARE(switch_caller_profile *) switch_caller_profile_new(switch_memory_
}
SWITCH_DECLARE(switch_caller_profile *) switch_caller_profile_clone(switch_core_session *session,
switch_caller_profile *tocopy)
SWITCH_DECLARE(switch_caller_profile *) switch_caller_profile_clone(switch_core_session *session, switch_caller_profile *tocopy)
{
switch_caller_profile *profile = NULL;
if ((profile = switch_core_session_alloc(session, sizeof(switch_caller_profile))) != 0) {
@ -67,8 +73,10 @@ SWITCH_DECLARE(switch_caller_profile *) switch_caller_profile_clone(switch_core_
profile->ani2 = switch_core_session_strdup(session, tocopy->ani2);
profile->caller_id_number = switch_core_session_strdup(session, tocopy->caller_id_number);
profile->network_addr = switch_core_session_strdup(session, tocopy->network_addr);
profile->rdnis = switch_core_session_strdup(session, tocopy->rdnis);
profile->destination_number = switch_core_session_strdup(session, tocopy->destination_number);
profile->uuid = switch_core_session_strdup(session, tocopy->uuid);
profile->source = switch_core_session_strdup(session, tocopy->source);
profile->chan_name = switch_core_session_strdup(session, tocopy->chan_name);
}
@ -112,6 +120,14 @@ SWITCH_DECLARE(void) switch_caller_profile_event_set_data(switch_caller_profile
snprintf(header_name, sizeof(header_name), "%s-Unique-ID", prefix);
switch_event_add_header(event, SWITCH_STACK_BOTTOM, header_name, caller_profile->uuid);
}
if (caller_profile->source) {
snprintf(header_name, sizeof(header_name), "%s-RDNIS", prefix);
switch_event_add_header(event, SWITCH_STACK_BOTTOM, header_name, caller_profile->source);
}
if (caller_profile->rdnis) {
snprintf(header_name, sizeof(header_name), "%s-RDNIS", prefix);
switch_event_add_header(event, SWITCH_STACK_BOTTOM, header_name, caller_profile->rdnis);
}
if (caller_profile->chan_name) {
snprintf(header_name, sizeof(header_name), "%s-Channel-Name", prefix);
switch_event_add_header(event, SWITCH_STACK_BOTTOM, header_name, caller_profile->chan_name);

View File

@ -373,7 +373,9 @@ SWITCH_DECLARE(switch_status) switch_core_codec_decode(switch_codec *codec,
uint32_t encoded_data_len,
uint32_t encoded_rate,
void *decoded_data,
uint32_t *decoded_data_len, uint32_t *decoded_rate, unsigned int *flag)
uint32_t *decoded_data_len,
uint32_t *decoded_rate,
unsigned int *flag)
{
assert(codec != NULL);

View File

@ -99,6 +99,8 @@ static char *EVENT_NAMES[] = {
"SHUTDOWN",
"PUBLISH",
"UNPUBLISH",
"TALK",
"NOTALK",
"ALL"
};

View File

@ -57,6 +57,29 @@ typedef struct {
char body[SWITCH_RTP_MAX_BUF_LEN];
} rtp_msg_t;
struct switch_rtp_vad_data {
switch_core_session *session;
switch_codec vad_codec;
switch_codec *read_codec;
uint32_t bg_level;
uint32_t bg_count;
uint32_t bg_len;
uint32_t diff_level;
uint8_t hangunder;
uint8_t hangunder_hits;
uint8_t hangover;
uint8_t hangover_hits;
uint8_t cng_freq;
uint8_t cng_count;
switch_vad_flag_t flags;
uint32_t ts;
uint8_t start;
uint8_t start_count;
uint8_t scan_freq;
time_t next_scan;
};
struct switch_rtp {
switch_socket_t *sock;
@ -89,6 +112,7 @@ struct switch_rtp {
uint32_t remote_port;
uint8_t stuncount;
switch_buffer *packet_buffer;
struct switch_rtp_vad_data vad_data;
};
static int global_init = 0;
@ -427,6 +451,9 @@ SWITCH_DECLARE(void) switch_rtp_destroy(switch_rtp **rtp_session)
switch_rtp_kill_socket(*rtp_session);
switch_socket_close((*rtp_session)->sock);
if (switch_test_flag((*rtp_session), SWITCH_RTP_FLAG_VAD)) {
switch_rtp_disable_vad(*rtp_session);
}
if (switch_test_flag((*rtp_session), SWITCH_RTP_FLAG_SECURE)) {
srtp_dealloc((*rtp_session)->recv_ctx);
srtp_dealloc((*rtp_session)->send_ctx);
@ -525,7 +552,11 @@ static int rtp_common_read(switch_rtp *rtp_session, switch_payload_t *payload_ty
rtp_session->recv_msg.header.pt = SWITCH_RTP_CNG_PAYLOAD;
*flags |= SFF_CNG;
/* Set the next waypoint and return a CNG frame */
rtp_session->next_read += rtp_session->ms_per_packet;
if (switch_test_flag(rtp_session, SWITCH_RTP_FLAG_TIMER_RECLOCK)) {
rtp_session->next_read = switch_time_now() + rtp_session->ms_per_packet;
} else {
rtp_session->next_read += rtp_session->ms_per_packet;
}
*payload_type = SWITCH_RTP_CNG_PAYLOAD;
return SWITCH_RTP_CNG_PAYLOAD;
}
@ -642,6 +673,7 @@ static int rtp_common_write(switch_rtp *rtp_session, void *data, uint32_t datale
uint8_t packetize = (rtp_session->packet_size > datalen && (payload == rtp_session->payload)) ? 1 : 0;
uint8_t fwd = (switch_test_flag(rtp_session, SWITCH_RTP_FLAG_RAW_WRITE) && (*flags & SFF_RAW_RTP)) ? 1 : 0;
rtp_msg_t *send_msg;
uint8_t send = 1;
if (fwd) {
bytes = datalen;
@ -649,7 +681,7 @@ static int rtp_common_write(switch_rtp *rtp_session, void *data, uint32_t datale
} else {
send_msg = &rtp_session->send_msg;
send_msg->header.pt = payload;
send_msg->header.m = m;
send_msg->header.m = m ? 1 : 0;
if (packetize) {
if (!rtp_session->packet_buffer) {
if (switch_buffer_create(rtp_session->pool, &rtp_session->packet_buffer, rtp_session->packet_size * 2) != SWITCH_STATUS_SUCCESS) {
@ -685,8 +717,120 @@ static int rtp_common_write(switch_rtp *rtp_session, void *data, uint32_t datale
if (switch_test_flag(rtp_session, SWITCH_RTP_FLAG_GOOGLEHACK) && rtp_session->send_msg.header.pt == 97) {
rtp_session->recv_msg.header.pt = 102;
}
switch_socket_sendto(rtp_session->sock, rtp_session->remote_addr, 0, (void*)send_msg, &bytes);
if (switch_test_flag(rtp_session, SWITCH_RTP_FLAG_VAD)) {
int16_t decoded[SWITCH_RECCOMMENDED_BUFFER_SIZE/sizeof(int16_t)];
uint32_t rate;
uint32_t flags;
uint32_t len = sizeof(decoded);
send = 0;
time_t now = time(NULL);
if (rtp_session->vad_data.scan_freq && rtp_session->vad_data.next_scan <= now) {
rtp_session->vad_data.bg_count = rtp_session->vad_data.bg_level = 0;
rtp_session->vad_data.next_scan = now + rtp_session->vad_data.scan_freq;
//printf("RESCAN\n");
}
if (switch_core_codec_decode(&rtp_session->vad_data.vad_codec,
rtp_session->vad_data.read_codec,
data,
datalen,
rtp_session->vad_data.read_codec->implementation->samples_per_second,
decoded,
&len,
&rate,
&flags) == SWITCH_STATUS_SUCCESS) {
double energy = 0;
uint32_t x, y = 0, z = len / sizeof(int16_t);
uint32_t score = 0;
if (z) {
for (x = 0; x < z; x++) {
energy += abs(decoded[y] * 1.0);
y += rtp_session->vad_data.read_codec->implementation->number_of_channels;
}
if (++rtp_session->vad_data.start_count < rtp_session->vad_data.start) {
send = 1;
} else {
score = energy / z;
if (score && (rtp_session->vad_data.bg_count < rtp_session->vad_data.bg_len)) {
rtp_session->vad_data.bg_level += score;
if (++rtp_session->vad_data.bg_count == rtp_session->vad_data.bg_len) {
rtp_session->vad_data.bg_level /= rtp_session->vad_data.bg_len;
rtp_session->vad_data.bg_level += (rtp_session->vad_data.bg_level / 3);
//printf("AVG %u\n", rtp_session->vad_data.bg_level);
}
send = 1;
} else {
if (score > rtp_session->vad_data.bg_level) {
uint32_t diff = score - rtp_session->vad_data.bg_level;
if (rtp_session->vad_data.hangover_hits) {
rtp_session->vad_data.hangover_hits--;
}
if (diff >= rtp_session->vad_data.diff_level || ++rtp_session->vad_data.hangunder_hits >= rtp_session->vad_data.hangunder) {
switch_set_flag(&rtp_session->vad_data, SWITCH_VAD_FLAG_TALKING);
send_msg->header.m = 1;
rtp_session->vad_data.hangover_hits = rtp_session->vad_data.hangunder_hits = rtp_session->vad_data.cng_count = 0;
if (switch_test_flag(&rtp_session->vad_data, SWITCH_VAD_FLAG_EVENTS_TALK)) {
switch_event *event;
if (switch_event_create(&event, SWITCH_EVENT_TALK) == SWITCH_STATUS_SUCCESS) {
switch_channel *channel = switch_core_session_get_channel(rtp_session->vad_data.session);
switch_channel_event_set_data(channel, event);
switch_event_fire(&event);
}
}
}
} else {
if (rtp_session->vad_data.hangunder_hits) {
rtp_session->vad_data.hangunder_hits--;
}
if (switch_test_flag(&rtp_session->vad_data, SWITCH_VAD_FLAG_TALKING)) {
if (++rtp_session->vad_data.hangover_hits >= rtp_session->vad_data.hangover) {
switch_clear_flag(&rtp_session->vad_data, SWITCH_VAD_FLAG_TALKING);
rtp_session->vad_data.hangover_hits = rtp_session->vad_data.hangunder_hits = rtp_session->vad_data.cng_count = 0;
if (switch_test_flag(&rtp_session->vad_data, SWITCH_VAD_FLAG_EVENTS_NOTALK)) {
switch_event *event;
if (switch_event_create(&event, SWITCH_EVENT_NOTALK) == SWITCH_STATUS_SUCCESS) {
switch_channel *channel = switch_core_session_get_channel(rtp_session->vad_data.session);
switch_channel_event_set_data(channel, event);
switch_event_fire(&event);
}
}
}
}
}
}
}
if (switch_test_flag(&rtp_session->vad_data, SWITCH_VAD_FLAG_TALKING)) {
send = 1;
} else {
if (++rtp_session->vad_data.cng_count >= rtp_session->vad_data.cng_freq) {
rtp_session->send_msg.header.pt = SWITCH_RTP_CNG_PAYLOAD;
memset(rtp_session->send_msg.body, 255, SWITCH_RTP_CNG_PAYLOAD);
rtp_session->send_msg.header.ts = htonl(rtp_session->vad_data.ts);
rtp_session->vad_data.ts++;
bytes = SWITCH_RTP_CNG_PAYLOAD;
send = 1;
rtp_session->vad_data.cng_count = 0;
}
}
}
} else {
return SWITCH_STATUS_GENERR;
}
}
if (send) {
switch_socket_sendto(rtp_session->sock, rtp_session->remote_addr, 0, (void*)send_msg, &bytes);
}
if (rtp_session->ice_user) {
if (ice_out(rtp_session) != SWITCH_STATUS_SUCCESS) {
return -1;
@ -697,6 +841,53 @@ static int rtp_common_write(switch_rtp *rtp_session, void *data, uint32_t datale
}
SWITCH_DECLARE(switch_status) switch_rtp_disable_vad(switch_rtp *rtp_session)
{
if (!switch_test_flag(rtp_session, SWITCH_RTP_FLAG_VAD)) {
return SWITCH_STATUS_GENERR;
}
switch_core_codec_destroy(&rtp_session->vad_data.vad_codec);
switch_clear_flag(rtp_session, SWITCH_RTP_FLAG_VAD);
return SWITCH_STATUS_SUCCESS;
}
SWITCH_DECLARE(switch_status) switch_rtp_enable_vad(switch_rtp *rtp_session, switch_core_session *session, switch_codec *codec, switch_vad_flag_t flags)
{
if (switch_test_flag(rtp_session, SWITCH_RTP_FLAG_VAD)) {
return SWITCH_STATUS_GENERR;
}
memset(&rtp_session->vad_data, 0, sizeof(rtp_session->vad_data));
if (switch_core_codec_init(&rtp_session->vad_data.vad_codec,
codec->codec_interface->iananame,
codec->implementation->samples_per_second,
codec->implementation->microseconds_per_frame / 1000,
codec->implementation->number_of_channels,
SWITCH_CODEC_FLAG_ENCODE | SWITCH_CODEC_FLAG_DECODE,
NULL,
rtp_session->pool) != SWITCH_STATUS_SUCCESS) {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Can't load codec?\n");
return SWITCH_STATUS_FALSE;
}
rtp_session->vad_data.diff_level = 400;
rtp_session->vad_data.hangunder = 15;
rtp_session->vad_data.hangover = 40;
rtp_session->vad_data.bg_len = 20;
rtp_session->vad_data.read_codec = codec;
rtp_session->vad_data.session = session;
rtp_session->vad_data.flags = flags;
rtp_session->vad_data.cng_freq = 50;
rtp_session->vad_data.ts = 1;
rtp_session->vad_data.start = 5;
rtp_session->vad_data.next_scan = time(NULL);
rtp_session->vad_data.scan_freq = 0;
switch_set_flag(rtp_session, SWITCH_RTP_FLAG_VAD);
return SWITCH_STATUS_SUCCESS;
}
SWITCH_DECLARE(int) switch_rtp_write(switch_rtp *rtp_session, void *data, uint32_t datalen, uint32_t ts, switch_frame_flag *flags)
{