提交 604379fd authored 作者: Anthony Minessale's avatar Anthony Minessale

1 of many PRI/SIP gateway related updates

git-svn-id: http://svn.freeswitch.org/svn/freeswitch/trunk@647 d0543943-73ff-0310-b7d9-9358b9ac24b2
上级 fe3e9942
...@@ -81,21 +81,29 @@ static void *audio_bridge_thread(switch_thread *thread, void *obj) ...@@ -81,21 +81,29 @@ static void *audio_bridge_thread(switch_thread *thread, void *obj)
break; break;
} }
/* If this call is running on early media and it answers for real, pass it along... */
if (!ans_b && switch_channel_test_flag(chan_a, CF_ANSWERED)) { if (!ans_b && switch_channel_test_flag(chan_a, CF_ANSWERED)) {
switch_channel_answer(chan_b); if (!switch_channel_test_flag(chan_b, CF_ANSWERED)) {
switch_channel_answer(chan_b);
}
ans_b++;
} }
if (!ans_a && switch_channel_test_flag(chan_b, CF_ANSWERED)) { if (!ans_a && switch_channel_test_flag(chan_b, CF_ANSWERED)) {
switch_channel_answer(chan_a); if (!switch_channel_test_flag(chan_a, CF_ANSWERED)) {
switch_channel_answer(chan_a);
}
ans_a++;
} }
/* if 1 channel has DTMF pass it to the other */
if (switch_channel_has_dtmf(chan_a)) { if (switch_channel_has_dtmf(chan_a)) {
char dtmf[128]; char dtmf[128];
switch_channel_dequeue_dtmf(chan_a, dtmf, sizeof(dtmf)); switch_channel_dequeue_dtmf(chan_a, dtmf, sizeof(dtmf));
switch_core_session_send_dtmf(session_b, dtmf); switch_core_session_send_dtmf(session_b, dtmf);
} }
/* read audio from 1 channel and write it to the other */
if (switch_core_session_read_frame(session_a, &read_frame, -1, stream_id) == SWITCH_STATUS_SUCCESS if (switch_core_session_read_frame(session_a, &read_frame, -1, stream_id) == SWITCH_STATUS_SUCCESS
&& read_frame->datalen) { && read_frame->datalen) {
if (switch_core_session_write_frame(session_b, read_frame, -1, stream_id) != SWITCH_STATUS_SUCCESS) { if (switch_core_session_write_frame(session_b, read_frame, -1, stream_id) != SWITCH_STATUS_SUCCESS) {
......
...@@ -70,12 +70,12 @@ typedef enum { ...@@ -70,12 +70,12 @@ typedef enum {
} TFLAGS; } TFLAGS;
#define PACKET_LEN 160 #define PACKET_LEN 160
#define DEFAULT_BYTES_PER_FRAME 160 #define DEFAULT_MTU 160
static struct { static struct {
int debug; int debug;
int panic; int panic;
int bytes_per_frame; int mtu;
char *dialplan; char *dialplan;
} globals; } globals;
...@@ -84,6 +84,7 @@ struct wanpipe_pri_span { ...@@ -84,6 +84,7 @@ struct wanpipe_pri_span {
int dchan; int dchan;
unsigned int bchans; unsigned int bchans;
int node; int node;
int mtu;
int pswitch; int pswitch;
char *dialplan; char *dialplan;
unsigned int l1; unsigned int l1;
...@@ -521,7 +522,7 @@ static switch_status wanpipe_read_frame(switch_core_session *session, switch_fra ...@@ -521,7 +522,7 @@ static switch_status wanpipe_read_frame(switch_core_session *session, switch_fra
*frame = NULL; *frame = NULL;
memset(tech_pvt->databuf, 0, sizeof(tech_pvt->databuf)); memset(tech_pvt->databuf, 0, sizeof(tech_pvt->databuf));
while (bytes < globals.bytes_per_frame) { while (bytes < globals.mtu) {
if ((res = sangoma_socket_waitfor(tech_pvt->socket, timeout, POLLIN | POLLERR)) < 0) { if ((res = sangoma_socket_waitfor(tech_pvt->socket, timeout, POLLIN | POLLERR)) < 0) {
return SWITCH_STATUS_GENERR; return SWITCH_STATUS_GENERR;
} else if (res == 0) { } else if (res == 0) {
...@@ -563,17 +564,19 @@ static switch_status wanpipe_write_frame(switch_core_session *session, switch_fr ...@@ -563,17 +564,19 @@ static switch_status wanpipe_write_frame(switch_core_session *session, switch_fr
tech_pvt = switch_core_session_get_private(session); tech_pvt = switch_core_session_get_private(session);
assert(tech_pvt != NULL); assert(tech_pvt != NULL);
return SWITCH_STATUS_SUCCESS;
while (bytes > 0) { while (bytes > 0) {
sangoma_socket_waitfor(tech_pvt->socket, -1, POLLOUT | POLLERR | POLLHUP); sangoma_socket_waitfor(tech_pvt->socket, -1, POLLOUT | POLLERR | POLLHUP);
res = sangoma_sendmsg_socket(tech_pvt->socket, res = sangoma_sendmsg_socket(tech_pvt->socket,
&tech_pvt->hdrframe, sizeof(tech_pvt->hdrframe), bp, PACKET_LEN, 0); &tech_pvt->hdrframe, sizeof(tech_pvt->hdrframe), bp, PACKET_LEN, 0);
if (res < 0) { if (res < 0) {
switch_console_printf(SWITCH_CHANNEL_CONSOLE, switch_console_printf(SWITCH_CHANNEL_CONSOLE,
"Bad Write frame len %d write %d bytes returned %d errno %d!\n", frame->datalen, "Bad Write frame len %d write %d bytes returned %d (%s)!\n", frame->datalen,
PACKET_LEN, res, errno); PACKET_LEN, res, strerror(errno));
if (errno == EBUSY) { if (errno == EBUSY) {
continue; continue;
} }
switch_console_printf(SWITCH_CHANNEL_CONSOLE, "Write Failed!\n");
status = SWITCH_STATUS_GENERR; status = SWITCH_STATUS_GENERR;
break; break;
} else { } else {
...@@ -742,6 +745,7 @@ static int on_proceed(struct sangoma_pri *spri, sangoma_pri_event_t event_type, ...@@ -742,6 +745,7 @@ static int on_proceed(struct sangoma_pri *spri, sangoma_pri_event_t event_type,
return 0; return 0;
} }
#if 0
static int on_ringing(struct sangoma_pri *spri, sangoma_pri_event_t event_type, pri_event *event) static int on_ringing(struct sangoma_pri *spri, sangoma_pri_event_t event_type, pri_event *event)
{ {
switch_core_session *session; switch_core_session *session;
...@@ -771,6 +775,7 @@ static int on_ringing(struct sangoma_pri *spri, sangoma_pri_event_t event_type, ...@@ -771,6 +775,7 @@ static int on_ringing(struct sangoma_pri *spri, sangoma_pri_event_t event_type,
return 0; return 0;
} }
#endif
static int on_ring(struct sangoma_pri *spri, sangoma_pri_event_t event_type, pri_event *event) static int on_ring(struct sangoma_pri *spri, sangoma_pri_event_t event_type, pri_event *event)
{ {
...@@ -901,10 +906,11 @@ static void *pri_thread_run(switch_thread *thread, void *obj) ...@@ -901,10 +906,11 @@ static void *pri_thread_run(switch_thread *thread, void *obj)
{ {
struct sangoma_pri *spri = obj; struct sangoma_pri *spri = obj;
struct channel_map chanmap; struct channel_map chanmap;
switch_event *s_event; switch_event *s_event;
SANGOMA_MAP_PRI_EVENT((*spri), SANGOMA_PRI_EVENT_ANY, on_anything); SANGOMA_MAP_PRI_EVENT((*spri), SANGOMA_PRI_EVENT_ANY, on_anything);
SANGOMA_MAP_PRI_EVENT((*spri), SANGOMA_PRI_EVENT_RING, on_ring); SANGOMA_MAP_PRI_EVENT((*spri), SANGOMA_PRI_EVENT_RING, on_ring);
SANGOMA_MAP_PRI_EVENT((*spri), SANGOMA_PRI_EVENT_RINGING, on_ringing); //SANGOMA_MAP_PRI_EVENT((*spri), SANGOMA_PRI_EVENT_RINGING, on_ringing);
//SANGOMA_MAP_PRI_EVENT((*spri), SANGOMA_PRI_EVENT_SETUP_ACK, on_ringing); //SANGOMA_MAP_PRI_EVENT((*spri), SANGOMA_PRI_EVENT_SETUP_ACK, on_ringing);
SANGOMA_MAP_PRI_EVENT((*spri), SANGOMA_PRI_EVENT_PROCEEDING, on_proceed); SANGOMA_MAP_PRI_EVENT((*spri), SANGOMA_PRI_EVENT_PROCEEDING, on_proceed);
SANGOMA_MAP_PRI_EVENT((*spri), SANGOMA_PRI_EVENT_ANSWER, on_answer); SANGOMA_MAP_PRI_EVENT((*spri), SANGOMA_PRI_EVENT_ANSWER, on_answer);
...@@ -946,7 +952,7 @@ static int config_wanpipe(int reload) ...@@ -946,7 +952,7 @@ static int config_wanpipe(int reload)
char *cf = "wanpipe.conf"; char *cf = "wanpipe.conf";
int current_span = 0; int current_span = 0;
globals.bytes_per_frame = DEFAULT_BYTES_PER_FRAME; globals.mtu = DEFAULT_MTU;
if (!switch_config_open_file(&cfg, cf)) { if (!switch_config_open_file(&cfg, cf)) {
...@@ -958,8 +964,8 @@ static int config_wanpipe(int reload) ...@@ -958,8 +964,8 @@ static int config_wanpipe(int reload)
if (!strcasecmp(cfg.category, "settings")) { if (!strcasecmp(cfg.category, "settings")) {
if (!strcmp(var, "debug")) { if (!strcmp(var, "debug")) {
globals.debug = atoi(val); globals.debug = atoi(val);
} else if (!strcmp(var, "bpf")) { } else if (!strcmp(var, "mtu")) {
globals.bytes_per_frame = atoi(val); globals.mtu = atoi(val);
} }
} else if (!strcasecmp(cfg.category, "span")) { } else if (!strcasecmp(cfg.category, "span")) {
if (!strcmp(var, "span")) { if (!strcmp(var, "span")) {
...@@ -1019,6 +1025,14 @@ static int config_wanpipe(int reload) ...@@ -1019,6 +1025,14 @@ static int config_wanpipe(int reload)
SPANS[current_span]->l1 = str2l1(val); SPANS[current_span]->l1 = str2l1(val);
} else if (!strcmp(var, "dialplan")) { } else if (!strcmp(var, "dialplan")) {
set_global_dialplan(val); set_global_dialplan(val);
} else if (!strcmp(var, "mtu")) {
int mtu = atoi(val);
if (mtu >= 10 && mtu < 960) {
SPANS[current_span]->mtu = mtu;
} else {
switch_console_printf(SWITCH_CHANNEL_CONSOLE, "Invalid MTU (%s)!\n", val);
}
} }
} }
} }
...@@ -1029,6 +1043,8 @@ static int config_wanpipe(int reload) ...@@ -1029,6 +1043,8 @@ static int config_wanpipe(int reload)
set_global_dialplan("default"); set_global_dialplan("default");
} }
for(current_span = 1; current_span < MAX_SPANS; current_span++) { for(current_span = 1; current_span < MAX_SPANS; current_span++) {
if (SPANS[current_span]) { if (SPANS[current_span]) {
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论