From 0fcf13bc347aec224224bc2f15d1ea0055f3028d Mon Sep 17 00:00:00 2001 From: Anthony Minessale Date: Thu, 14 Sep 2006 22:11:30 +0000 Subject: [PATCH] misc git-svn-id: http://svn.freeswitch.org/svn/freeswitch/trunk@2704 d0543943-73ff-0310-b7d9-9358b9ac24b2 --- .../mod_conference/mod_conference.c | 13 +++- src/mod/codecs/mod_g711/mod_g711.c | 5 +- src/mod/endpoints/mod_exosip/mod_exosip.c | 2 +- .../timers/mod_threadtimer/mod_threadtimer.c | 71 ++++++++++++------- src/switch.c | 2 +- src/switch_core.c | 1 + 6 files changed, 60 insertions(+), 34 deletions(-) diff --git a/src/mod/applications/mod_conference/mod_conference.c b/src/mod/applications/mod_conference/mod_conference.c index 241949768d..b4c73242ac 100644 --- a/src/mod/applications/mod_conference/mod_conference.c +++ b/src/mod/applications/mod_conference/mod_conference.c @@ -709,6 +709,10 @@ static void conference_loop(conference_member_t *member) write_frame.data = data; write_frame.buflen = sizeof(data); write_frame.codec = &member->write_codec; + + if (switch_test_flag(member->conference, CFLAG_ANSWERED)) { + switch_channel_answer(channel); + } /* Start a thread to read data and feed it into the buffer and use this thread to generate output */ launch_input_thread(member, switch_core_session_get_pool(member->session)); @@ -957,7 +961,7 @@ static void conference_loop(conference_member_t *member) } } } /* Rinse ... Repeat */ - + switch_clear_flag_locked(member, MFLAG_RUNNING); switch_core_timer_destroy(&timer); @@ -2344,9 +2348,12 @@ static void conference_function(switch_core_session_t *session, char *data) if (conference_outcall(conference, session, bridgeto, 60, NULL, NULL, NULL) != SWITCH_STATUS_SUCCESS) { goto done; } - } //else + } else { // if we're not using "bridge:" set the conference answered flag - //switch_set_flag(conference, CFLAG_ANSWERED); + // and this isn't an outbound channel, answer the call + if (!switch_channel_test_flag(channel, CF_OUTBOUND)) + switch_set_flag(conference, CFLAG_ANSWERED); + } diff --git a/src/mod/codecs/mod_g711/mod_g711.c b/src/mod/codecs/mod_g711/mod_g711.c index 6be2ab432a..7df87473ae 100644 --- a/src/mod/codecs/mod_g711/mod_g711.c +++ b/src/mod/codecs/mod_g711/mod_g711.c @@ -187,7 +187,7 @@ static switch_status_t switch_g711a_destroy(switch_codec_t *codec) /* Registration */ -#if 0 + static const switch_codec_implementation_t g711u_8k_60ms_implementation = { /*.codec_type */ SWITCH_CODEC_TYPE_AUDIO, @@ -208,7 +208,7 @@ static const switch_codec_implementation_t g711u_8k_60ms_implementation = { /*.destroy */ switch_g711u_destroy }; - +#if 0 static const switch_codec_implementation_t g711u_8k_30ms_implementation = { /*.codec_type */ SWITCH_CODEC_TYPE_AUDIO, /*.ianacode */ 0, @@ -268,6 +268,7 @@ static const switch_codec_implementation_t g711u_8k_implementation = { /*.decode */ switch_g711u_decode, /*.destroy */ switch_g711u_destroy, ///*.next */ &g711u_16k_implementation + &g711u_8k_60ms_implementation }; diff --git a/src/mod/endpoints/mod_exosip/mod_exosip.c b/src/mod/endpoints/mod_exosip/mod_exosip.c index dc10213c81..a92232543d 100644 --- a/src/mod/endpoints/mod_exosip/mod_exosip.c +++ b/src/mod/endpoints/mod_exosip/mod_exosip.c @@ -585,7 +585,7 @@ static switch_status_t activate_rtp(struct private_object *tech_pvt) ms, flags, key, - "soft", + "thread_soft", &err, switch_core_session_get_pool(tech_pvt->session)); if (switch_rtp_ready(tech_pvt->rtp_session)) { diff --git a/src/mod/timers/mod_threadtimer/mod_threadtimer.c b/src/mod/timers/mod_threadtimer/mod_threadtimer.c index 8de6c371f6..aa9af9a6b4 100644 --- a/src/mod/timers/mod_threadtimer/mod_threadtimer.c +++ b/src/mod/timers/mod_threadtimer/mod_threadtimer.c @@ -37,16 +37,18 @@ static switch_memory_pool_t *module_pool = NULL; static struct { int32_t RUNNING; switch_mutex_t *mutex; + uint32_t timer_milliseconds; + uint32_t timer_microseconds; } globals; static const char modname[] = "mod_threadtimer"; #define MAX_ELEMENTS 1000 struct timer_private { - uint32_t tick; - uint32_t reference; + uint64_t tick; + uint64_t reference; uint32_t interval; - switch_mutex_t *mutex; + //switch_mutex_t *mutex; struct timer_private *next; }; @@ -60,11 +62,30 @@ typedef struct timer_head timer_head_t; static timer_head_t *TIMER_MATRIX[MAX_ELEMENTS+1]; +#define IDLE_SPEED 100 + +static inline void set_timer(void) +{ + uint32_t index = 0, min = IDLE_SPEED; + + for(index = 0; index < MAX_ELEMENTS; index++) { + if (TIMER_MATRIX[index] && TIMER_MATRIX[index]->private_info) { + if (min > index) { + min = index; + } + } + } + + globals.timer_milliseconds = min; + globals.timer_microseconds = min * 1000; +} + static inline switch_status_t timer_init(switch_timer_t *timer) { timer_private_t *private_info; timer_head_t *head; + if ((private_info = switch_core_alloc(timer->memory_pool, sizeof(*private_info)))) { timer->private_info = private_info; if (!TIMER_MATRIX[timer->interval]) { @@ -76,35 +97,28 @@ static inline switch_status_t timer_init(switch_timer_t *timer) head = TIMER_MATRIX[timer->interval]; - switch_mutex_init(&private_info->mutex, SWITCH_MUTEX_NESTED, timer->memory_pool); + //switch_mutex_init(&private_info->mutex, SWITCH_MUTEX_NESTED, timer->memory_pool); private_info->interval = timer->interval; switch_mutex_lock(head->mutex); private_info->next = head->private_info; head->private_info = private_info; switch_mutex_unlock(head->mutex); - + set_timer(); + return SWITCH_STATUS_SUCCESS; } return SWITCH_STATUS_MEMERR; } -#define MAX_TICKS 0xFFFFFF00 -#define check_overflow(p) if (p->reference > MAX_TICKS) {\ - switch_mutex_lock(p->mutex);\ - p->reference = p->tick = 0;\ - switch_mutex_unlock(p->mutex);\ - }\ - - static inline switch_status_t timer_step(switch_timer_t *timer) { timer_private_t *private_info = timer->private_info; - switch_mutex_lock(private_info->mutex); + //switch_mutex_lock(private_info->mutex); private_info->reference += private_info->interval; - switch_mutex_unlock(private_info->mutex); + //switch_mutex_unlock(private_info->mutex); return SWITCH_STATUS_SUCCESS; } @@ -119,7 +133,6 @@ static inline switch_status_t timer_next(switch_timer_t *timer) while (private_info->tick < private_info->reference) { switch_yield(1000); } - check_overflow(private_info); timer->samplecount += timer->samples; return SWITCH_STATUS_SUCCESS; @@ -131,15 +144,14 @@ static inline switch_status_t timer_check(switch_timer_t *timer) timer_private_t *private_info = timer->private_info; switch_status_t status; - switch_mutex_lock(private_info->mutex); + //switch_mutex_lock(private_info->mutex); if (private_info->tick < private_info->reference) { status = SWITCH_STATUS_FALSE; } else { private_info->reference += private_info->interval; - check_overflow(private_info); status = SWITCH_STATUS_SUCCESS; } - switch_mutex_unlock(private_info->mutex); + //switch_mutex_unlock(private_info->mutex); return status; } @@ -167,7 +179,7 @@ static inline switch_status_t timer_destroy(switch_timer_t *timer) last = ptr; } switch_mutex_unlock(head->mutex); - + set_timer(); timer->private_info = NULL; return SWITCH_STATUS_SUCCESS; } @@ -205,6 +217,8 @@ SWITCH_MOD_DECLARE(switch_status_t) switch_module_load(const switch_loadable_mod return SWITCH_STATUS_SUCCESS; } + + SWITCH_MOD_DECLARE(switch_status_t) switch_module_runtime(void) { switch_time_t reference = switch_time_now(); @@ -214,19 +228,22 @@ SWITCH_MOD_DECLARE(switch_status_t) switch_module_runtime(void) memset(&globals, 0, sizeof(globals)); switch_mutex_init(&globals.mutex, SWITCH_MUTEX_NESTED, module_pool); + globals.timer_microseconds = IDLE_SPEED * 1000; + globals.timer_milliseconds = IDLE_SPEED; globals.RUNNING = 1; while(globals.RUNNING == 1) { - reference += 1000; - + reference += globals.timer_microseconds; + //printf("TEST %d\n", globals.timer_microseconds); while (switch_time_now() < reference) { - switch_yield(500); + //switch_yield((reference - now) - 1000); + switch_yield(globals.timer_microseconds >> 1); } - current_ms++; + current_ms += globals.timer_milliseconds; - for (x = 0; x < 1000; x++) { + for (x = 0; x < MAX_ELEMENTS; x++) { int i = x, index; if (i == 0) { i = 1; @@ -237,9 +254,9 @@ SWITCH_MOD_DECLARE(switch_status_t) switch_module_runtime(void) if (TIMER_MATRIX[index] && TIMER_MATRIX[index]->private_info) { switch_mutex_lock(TIMER_MATRIX[index]->mutex); for (ptr = TIMER_MATRIX[index]->private_info; ptr; ptr = ptr->next) { - switch_mutex_lock(ptr->mutex); + //switch_mutex_lock(ptr->mutex); ptr->tick += ptr->interval; - switch_mutex_unlock(ptr->mutex); + //switch_mutex_unlock(ptr->mutex); } switch_mutex_unlock(TIMER_MATRIX[index]->mutex); } diff --git a/src/switch.c b/src/switch.c index ee05e50ee5..ed6a6ee5c2 100644 --- a/src/switch.c +++ b/src/switch.c @@ -62,7 +62,7 @@ static void set_high_priority() #ifdef WIN32 SetPriorityClass(GetCurrentProcess(), HIGH_PRIORITY_CLASS); #else - //nice(-20); + //nice(-19); #endif } diff --git a/src/switch_core.c b/src/switch_core.c index a5d4f0a7d5..9e8e8cd888 100644 --- a/src/switch_core.c +++ b/src/switch_core.c @@ -3624,6 +3624,7 @@ SWITCH_DECLARE(switch_status_t) switch_core_init_and_modload(char *console, cons switch_event_fire(&event); } +//#define USE_MLOCKALL #ifdef HAVE_MLOCKALL #ifdef USE_MLOCKALL mlockall(MCL_CURRENT|MCL_FUTURE);