mirror of
https://github.com/signalwire/freeswitch.git
synced 2026-07-24 13:12:03 +00:00
add VAD
git-svn-id: http://svn.freeswitch.org/svn/freeswitch/trunk@1222 d0543943-73ff-0310-b7d9-9358b9ac24b2
This commit is contained in:
@@ -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);
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -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,
|
||||
|
||||
@@ -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")) {
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -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->
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -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;
|
||||
|
||||
Reference in New Issue
Block a user