From 4cc1136433559620d4b8d6e759793b958af8ac7e Mon Sep 17 00:00:00 2001 From: Anthony Minessale Date: Tue, 6 Jan 2009 21:07:58 +0000 Subject: [PATCH] fix some media issues (shoud go into the 1.0 branch) git-svn-id: http://svn.freeswitch.org/svn/freeswitch/trunk@11079 d0543943-73ff-0310-b7d9-9358b9ac24b2 --- .../mod_conference/mod_conference.c | 18 ++++++- src/mod/endpoints/mod_sofia/sofia.c | 16 ++++++ src/switch_core_io.c | 4 -- src/switch_ivr.c | 5 +- src/switch_ivr_async.c | 53 +++++++++++++++++-- 5 files changed, 86 insertions(+), 10 deletions(-) diff --git a/src/mod/applications/mod_conference/mod_conference.c b/src/mod/applications/mod_conference/mod_conference.c index 3bb967ceb6..ccff794d08 100644 --- a/src/mod/applications/mod_conference/mod_conference.c +++ b/src/mod/applications/mod_conference/mod_conference.c @@ -1552,6 +1552,13 @@ static void *SWITCH_THREAD_FUNC conference_loop_input(switch_thread_t *thread, v 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 @@ static void conference_loop_output(conference_member_t *member) } 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 { diff --git a/src/mod/endpoints/mod_sofia/sofia.c b/src/mod/endpoints/mod_sofia/sofia.c index 580e92df57..a44da3a331 100644 --- a/src/mod/endpoints/mod_sofia/sofia.c +++ b/src/mod/endpoints/mod_sofia/sofia.c @@ -3562,6 +3562,22 @@ void sofia_handle_sip_i_info(nua_t *nua, sofia_profile_t *profile, nua_handle_t /* 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()); diff --git a/src/switch_core_io.c b/src/switch_core_io.c index b364ea1b94..968aaed540 100644 --- a/src/switch_core_io.c +++ b/src/switch_core_io.c @@ -539,10 +539,6 @@ SWITCH_DECLARE(switch_status_t) switch_core_session_read_frame(switch_core_sessi 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; } diff --git a/src/switch_ivr.c b/src/switch_ivr.c index d3bd1bc9d5..f934ba1f6e 100644 --- a/src/switch_ivr.c +++ b/src/switch_ivr.c @@ -54,9 +54,10 @@ SWITCH_DECLARE(switch_status_t) switch_ivr_sleep(switch_core_session_t *session, int sval = 0; const char *var; - if ((var = switch_channel_get_variable(channel, SWITCH_SEND_SILENCE_WHEN_IDLE_VARIABLE)) && (sval = atoi(var))) { + if (switch_channel_media_ready(channel) && (var = switch_channel_get_variable(channel, SWITCH_SEND_SILENCE_WHEN_IDLE_VARIABLE)) && (sval = atoi(var))) { + switch_channel_pre_answer(channel); switch_core_session_get_read_impl(session, &imp); - + if (switch_core_codec_init(&codec, "L16", NULL, diff --git a/src/switch_ivr_async.c b/src/switch_ivr_async.c index afcf51b421..83519925ce 100644 --- a/src/switch_ivr_async.c +++ b/src/switch_ivr_async.c @@ -1445,6 +1445,44 @@ typedef struct { #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 @@ static switch_status_t meta_on_dtmf(switch_core_session_t *session, const switch 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 @@ static switch_status_t meta_on_dtmf(switch_core_session_t *session, const switch 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 @@ SWITCH_DECLARE(switch_status_t) switch_ivr_bind_dtmf_meta_session(switch_core_se 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 @@ SWITCH_DECLARE(switch_status_t) switch_ivr_broadcast(const char *uuid, const cha 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");