[Freeswitch-branches] [commit] r11407 - in freeswitch/branches/1.0/src: . mod/applications/mod_conference mod/endpoints/mod_sofia
FreeSWITCH SVN
mikej at freeswitch.org
Thu Jan 22 14:11:34 PST 2009
Author: mikej
Date: Thu Jan 22 16:11:34 2009
New Revision: 11407
Log:
core: fix media handling issues (r:11079-11082)
Modified:
freeswitch/branches/1.0/src/mod/applications/mod_conference/mod_conference.c
freeswitch/branches/1.0/src/mod/endpoints/mod_sofia/sofia.c
freeswitch/branches/1.0/src/switch_apr.c
freeswitch/branches/1.0/src/switch_channel.c
freeswitch/branches/1.0/src/switch_core_io.c
freeswitch/branches/1.0/src/switch_ivr.c
freeswitch/branches/1.0/src/switch_ivr_async.c
freeswitch/branches/1.0/src/switch_ivr_originate.c
Modified: freeswitch/branches/1.0/src/mod/applications/mod_conference/mod_conference.c
==============================================================================
--- freeswitch/branches/1.0/src/mod/applications/mod_conference/mod_conference.c (original)
+++ freeswitch/branches/1.0/src/mod/applications/mod_conference/mod_conference.c Thu Jan 22 16:11:34 2009
@@ -1552,6 +1552,13 @@
and mux it with any audio from other channels. */
while (switch_test_flag(member, MFLAG_RUNNING) && switch_channel_ready(channel)) {
+
+ if (switch_channel_test_flag(channel, CF_SERVICE)) {
+ switch_yield(100000);
+ continue;
+ }
+
+
/* Read a frame. */
status = switch_core_session_read_frame(member->session, &read_frame, SWITCH_IO_FLAG_NONE, 0);
@@ -2037,9 +2044,18 @@
}
switch_clear_flag_locked(member, MFLAG_FLUSH_BUFFER);
}
-
+
switch_mutex_unlock(member->flag_mutex);
+
+ if (switch_core_session_private_event_count(member->session)) {
+ switch_channel_set_flag(channel, CF_SERVICE);
+ switch_ivr_parse_all_events(member->session);
+ switch_channel_clear_flag(channel, CF_SERVICE);
+ switch_set_flag_locked(member, MFLAG_FLUSH_BUFFER);
+ switch_core_session_set_read_codec(member->session, &member->read_codec);
+ }
+
if (use_timer) {
switch_core_timer_next(&timer);
} else {
Modified: freeswitch/branches/1.0/src/mod/endpoints/mod_sofia/sofia.c
==============================================================================
--- freeswitch/branches/1.0/src/mod/endpoints/mod_sofia/sofia.c (original)
+++ freeswitch/branches/1.0/src/mod/endpoints/mod_sofia/sofia.c Thu Jan 22 16:11:34 2009
@@ -3562,6 +3562,22 @@
/* print debug info */
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "INFO DTMF(%c)\n", dtmf.digit);
+
+ if (switch_channel_test_flag(channel, CF_PROXY_MODE)) {
+ const char *uuid;
+ switch_core_session_t *session_b;
+
+ if ((uuid = switch_channel_get_variable(channel, SWITCH_SIGNAL_BOND_VARIABLE)) && (session_b = switch_core_session_locate(uuid))) {
+ while (switch_channel_has_dtmf(channel)) {
+ switch_dtmf_t idtmf = { 0, 0 };
+ if (switch_channel_dequeue_dtmf(channel, &idtmf) == SWITCH_STATUS_SUCCESS) {
+ switch_core_session_send_dtmf(session_b, &idtmf);
+ }
+ }
+
+ switch_core_session_rwunlock(session_b);
+ }
+ }
/* Send 200 OK response */
nua_respond(nh, SIP_200_OK, NUTAG_WITH_THIS(nua), TAG_END());
Modified: freeswitch/branches/1.0/src/switch_apr.c
==============================================================================
--- freeswitch/branches/1.0/src/switch_apr.c (original)
+++ freeswitch/branches/1.0/src/switch_apr.c Thu Jan 22 16:11:34 2009
@@ -761,9 +761,9 @@
SWITCH_DECLARE(switch_status_t) switch_socket_recvfrom(switch_sockaddr_t *from, switch_socket_t *sock, int32_t flags, char *buf, size_t *len)
{
- apr_status_t r;
+ apr_status_t r = SWITCH_STATUS_GENERR;
- if ((r = apr_socket_recvfrom(from, sock, flags, buf, len)) == APR_SUCCESS) {
+ if (from && sock && (r = apr_socket_recvfrom(from, sock, flags, buf, len)) == APR_SUCCESS) {
from->port = ntohs(from->sa.sin.sin_port);
/* from->ipaddr_ptr = &(from->sa.sin.sin_addr);
* from->ipaddr_ptr = inet_ntoa(from->sa.sin.sin_addr);
Modified: freeswitch/branches/1.0/src/switch_channel.c
==============================================================================
--- freeswitch/branches/1.0/src/switch_channel.c (original)
+++ freeswitch/branches/1.0/src/switch_channel.c Thu Jan 22 16:11:34 2009
@@ -1647,8 +1647,8 @@
msg.message_id = SWITCH_MESSAGE_INDICATE_PROGRESS;
msg.from = channel->name;
- status = switch_core_session_receive_message(channel->session, &msg);
-
+ status = switch_core_session_perform_receive_message(channel->session, &msg, file, func, line);
+
if (status == SWITCH_STATUS_SUCCESS) {
switch_channel_perform_mark_pre_answered(channel, file, func, line);
} else {
@@ -1679,7 +1679,7 @@
msg.message_id = SWITCH_MESSAGE_INDICATE_RINGING;
msg.from = channel->name;
- status = switch_core_session_receive_message(channel->session, &msg);
+ status = switch_core_session_perform_receive_message(channel->session, &msg, file, func, line);
if (status == SWITCH_STATUS_SUCCESS) {
switch_log_printf(SWITCH_CHANNEL_ID_LOG, file, func, line, NULL, SWITCH_LOG_NOTICE, "Ring Ready %s!\n", channel->name);
@@ -1784,7 +1784,7 @@
msg.message_id = SWITCH_MESSAGE_INDICATE_ANSWER;
msg.from = channel->name;
- status = switch_core_session_receive_message(channel->session, &msg);
+ status = switch_core_session_perform_receive_message(channel->session, &msg, file, func, line);
if (status == SWITCH_STATUS_SUCCESS) {
switch_channel_perform_mark_answered(channel, file, func, line);
Modified: freeswitch/branches/1.0/src/switch_core_io.c
==============================================================================
--- freeswitch/branches/1.0/src/switch_core_io.c (original)
+++ freeswitch/branches/1.0/src/switch_core_io.c Thu Jan 22 16:11:34 2009
@@ -539,10 +539,6 @@
switch_mutex_unlock(session->read_codec->mutex);
switch_mutex_unlock(session->codec_read_mutex);
- if (switch_core_session_private_event_count(session)) {
- switch_ivr_parse_all_events(session);
- }
-
return status;
}
Modified: freeswitch/branches/1.0/src/switch_ivr.c
==============================================================================
--- freeswitch/branches/1.0/src/switch_ivr.c (original)
+++ freeswitch/branches/1.0/src/switch_ivr.c Thu Jan 22 16:11:34 2009
@@ -41,6 +41,7 @@
SWITCH_DECLARE(switch_status_t) switch_ivr_sleep(switch_core_session_t *session, uint32_t ms, switch_bool_t sync, switch_input_args_t *args)
{
switch_channel_t *channel = switch_core_session_get_channel(session);
+ int media_ready = 0;
switch_status_t status = SWITCH_STATUS_SUCCESS;
switch_time_t start = switch_timestamp_now(), now, done = switch_timestamp_now() + (ms * 1000);
switch_frame_t *read_frame, cng_frame = { 0 };
@@ -53,10 +54,19 @@
switch_codec_t codec = { 0 };
int sval = 0;
const char *var;
+
+ if (!switch_channel_test_flag(channel, CF_PROXY_MODE) && !switch_channel_media_ready(channel) && !switch_channel_test_flag(channel, CF_SERVICE)) {
+ if ((status = switch_channel_pre_answer(channel)) != SWITCH_STATUS_SUCCESS) {
+ switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Cannot establish media.\n");
+ return SWITCH_STATUS_FALSE;
+ }
+ }
+
+ media_ready = (switch_channel_media_ready(channel) && !switch_channel_test_flag(channel, CF_SERVICE));
- if ((var = switch_channel_get_variable(channel, SWITCH_SEND_SILENCE_WHEN_IDLE_VARIABLE)) && (sval = atoi(var))) {
+ if (ms > 100 && media_ready && (var = switch_channel_get_variable(channel, SWITCH_SEND_SILENCE_WHEN_IDLE_VARIABLE)) && (sval = atoi(var))) {
switch_core_session_get_read_impl(session, &imp);
-
+
if (switch_core_codec_init(&codec,
"L16",
NULL,
@@ -81,12 +91,10 @@
write_frame.datalen = imp.decoded_bytes_per_packet;
write_frame.samples = write_frame.datalen / sizeof(int16_t);
- if (!switch_channel_media_ready(channel)) {
- if ((status = switch_channel_pre_answer(channel)) != SWITCH_STATUS_SUCCESS) {
- switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Cannot establish media.\n");
- return SWITCH_STATUS_FALSE;
- }
- }
+ }
+
+ if (!write_frame.datalen) {
+ sval = 0;
}
cng_frame.data = data;
@@ -94,7 +102,7 @@
cng_frame.buflen = 2;
switch_set_flag((&cng_frame), SFF_CNG);
- if (sync && !switch_channel_test_flag(channel, CF_PROXY_MODE)) {
+ if (sync && media_ready) {
switch_channel_audio_sync(channel);
}
@@ -161,29 +169,25 @@
}
}
- if (switch_channel_test_flag(channel, CF_PROXY_MODE)) {
+ if (!media_ready) {
switch_cond_next();
continue;
}
- if (switch_channel_test_flag(channel, CF_SERVICE) ||
- (!switch_channel_test_flag(channel, CF_ANSWERED) && !switch_channel_test_flag(channel, CF_EARLY_MEDIA))) {
- switch_cond_next();
- } else {
- status = switch_core_session_read_frame(session, &read_frame, SWITCH_IO_FLAG_NONE, 0);
- if (!SWITCH_READ_ACCEPTABLE(status)) {
- break;
- }
+ status = switch_core_session_read_frame(session, &read_frame, SWITCH_IO_FLAG_NONE, 0);
+
+ if (!SWITCH_READ_ACCEPTABLE(status)) {
+ break;
}
- if (sval) {
+ if (sval && write_frame.datalen) {
switch_generate_sln_silence((int16_t *) write_frame.data, write_frame.samples, sval);
switch_core_session_write_frame(session, &write_frame, SWITCH_IO_FLAG_NONE, 0);
} else {
switch_core_session_write_frame(session, &cng_frame, SWITCH_IO_FLAG_NONE, 0);
}
}
-
+
if (write_frame.codec) {
switch_core_codec_destroy(&codec);
}
Modified: freeswitch/branches/1.0/src/switch_ivr_async.c
==============================================================================
--- freeswitch/branches/1.0/src/switch_ivr_async.c (original)
+++ freeswitch/branches/1.0/src/switch_ivr_async.c Thu Jan 22 16:11:34 2009
@@ -1445,6 +1445,44 @@
#define SWITCH_META_VAR_KEY "__dtmf_meta"
+typedef struct {
+ switch_core_session_t *session;
+ const char *app;
+ int flags;
+} bch_t;
+
+static void *SWITCH_THREAD_FUNC bcast_thread(switch_thread_t *thread, void *obj)
+{
+ bch_t *bch = (bch_t *) obj;
+
+ switch_ivr_broadcast(switch_core_session_get_uuid(bch->session), bch->app, bch->flags);
+
+ return NULL;
+
+}
+static void broadcast_in_thread(switch_core_session_t *session, const char *app, int flags)
+{
+ switch_thread_t *thread;
+ switch_threadattr_t *thd_attr = NULL;
+ switch_memory_pool_t *pool;
+ bch_t *bch;
+
+ switch_assert(session);
+
+ pool = switch_core_session_get_pool(session);
+
+ bch = switch_core_session_alloc(session, sizeof(*bch));
+ bch->session = session;
+ bch->app = app;
+ bch->flags = flags;
+
+
+ switch_threadattr_create(&thd_attr, pool);
+ switch_threadattr_detach_set(thd_attr, 1);
+ switch_threadattr_stacksize_set(thd_attr, SWITCH_THREAD_STACKSIZE);
+ switch_thread_create(&thread, thd_attr, bcast_thread, bch, pool);
+}
+
static switch_status_t meta_on_dtmf(switch_core_session_t *session, const switch_dtmf_t *dtmf, switch_dtmf_direction_t direction)
{
switch_channel_t *channel = switch_core_session_get_channel(session);
@@ -1497,7 +1535,7 @@
if (ok && md->sr[direction].map[dval].app) {
uint32_t flags = md->sr[direction].map[dval].flags;
-
+
if ((md->sr[direction].map[dval].bind_flags & SBF_EXEC_OPPOSITE)) {
if (direction == SWITCH_DTMF_SEND) {
flags |= SMF_ECHO_ALEG;
@@ -1520,7 +1558,12 @@
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "%s Processing meta digit '%c' [%s]\n",
switch_channel_get_name(channel), dtmf->digit, md->sr[direction].map[dval].app);
- switch_ivr_broadcast(switch_core_session_get_uuid(session), md->sr[direction].map[dval].app, flags);
+
+ if (switch_channel_test_flag(channel, CF_PROXY_MODE)) {
+ broadcast_in_thread(session, md->sr[direction].map[dval].app, flags | SMF_REBRIDGE);
+ } else {
+ switch_ivr_broadcast(switch_core_session_get_uuid(session), md->sr[direction].map[dval].app, flags);
+ }
if ((md->sr[direction].map[dval].bind_flags & SBF_ONCE)) {
memset(&md->sr[direction].map[dval], 0, sizeof(md->sr[direction].map[dval]));
@@ -1589,7 +1632,7 @@
md->sr[SWITCH_DTMF_RECV].map[key].app = switch_core_session_strdup(session, app);
md->sr[SWITCH_DTMF_RECV].map[key].flags |= SMF_HOLD_BLEG;
md->sr[SWITCH_DTMF_RECV].map[key].bind_flags = bind_flags;
-
+
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_INFO, "Bound A-Leg: %d %s\n", key, app);
}
if ((bind_flags & SBF_DIAL_BLEG)) {
@@ -2157,6 +2200,10 @@
other_session = NULL;
}
+ if (switch_stristr("record", app)) {
+ nomedia = 0;
+ }
+
if ((flags & SMF_ECHO_ALEG)) {
if (switch_event_create(&event, SWITCH_EVENT_COMMAND) == SWITCH_STATUS_SUCCESS) {
switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, "call-command", "execute");
Modified: freeswitch/branches/1.0/src/switch_ivr_originate.c
==============================================================================
--- freeswitch/branches/1.0/src/switch_ivr_originate.c (original)
+++ freeswitch/branches/1.0/src/switch_ivr_originate.c Thu Jan 22 16:11:34 2009
@@ -41,7 +41,11 @@
if (!switch_channel_test_flag(channel, CF_PROXY_MODE)) {
while (switch_channel_get_state(channel) == CS_CONSUME_MEDIA && !switch_channel_test_flag(channel, CF_TAGGED)) {
- switch_ivr_sleep(session, 10, SWITCH_FALSE, NULL);
+ if (!switch_channel_media_ready(channel)) {
+ switch_yield(10000);
+ } else {
+ switch_ivr_sleep(session, 10, SWITCH_FALSE, NULL);
+ }
}
}
More information about the Freeswitch-branches
mailing list