diff options
Diffstat (limited to 'main')
-rw-r--r-- | main/asterisk.c | 30 | ||||
-rw-r--r-- | main/channel.c | 62 | ||||
-rw-r--r-- | main/file.c | 25 | ||||
-rw-r--r-- | main/timing.c | 74 |
4 files changed, 86 insertions, 105 deletions
diff --git a/main/asterisk.c b/main/asterisk.c index 5651bbd68..0474d6375 100644 --- a/main/asterisk.c +++ b/main/asterisk.c @@ -3299,35 +3299,7 @@ int main(int argc, char *argv[]) printf("%s", term_quit()); exit(1); } -#ifdef HAVE_DAHDI - { - int fd; - int x = 160; - fd = open("/dev/dahdi/timer", O_RDWR); - if (fd >= 0) { - if (ioctl(fd, DAHDI_TIMERCONFIG, &x)) { - ast_log(LOG_ERROR, "You have DAHDI built and drivers loaded, but the DAHDI timer test failed to set DAHDI_TIMERCONFIG to %d.\n", x); - exit(1); - } - if ((x = ast_wait_for_input(fd, 300)) < 0) { - ast_log(LOG_ERROR, "You have DAHDI built and drivers loaded, but the DAHDI timer could not be polled during the DAHDI timer test.\n"); - exit(1); - } - if (!x) { - const char dahdi_timer_error[] = { - "Asterisk has detected a problem with your DAHDI configuration and will shutdown for your protection. You have options:" - "\n\t1. You only have to compile DAHDI support into Asterisk if you need it. One option is to recompile without DAHDI support." - "\n\t2. You only have to load DAHDI drivers if you want to take advantage of DAHDI services. One option is to unload DAHDI modules if you don't need them." - "\n\t3. If you need DAHDI services, you must correctly configure DAHDI." - }; - ast_log(LOG_ERROR, "%s\n", dahdi_timer_error); - usleep(100); - exit(1); - } - close(fd); - } - } -#endif + threadstorage_init(); astobj2_init(); diff --git a/main/channel.c b/main/channel.c index 4f97c1008..e73e121d6 100644 --- a/main/channel.c +++ b/main/channel.c @@ -61,6 +61,7 @@ ASTERISK_FILE_VERSION(__FILE__, "$Revision$") #include "asterisk/threadstorage.h" #include "asterisk/slinfactory.h" #include "asterisk/audiohook.h" +#include "asterisk/timing.h" #ifdef HAVE_EPOLL #include <sys/epoll.h> @@ -808,27 +809,19 @@ struct ast_channel *ast_channel_alloc(int needqueue, int state, const char *cid_ #endif } -#ifdef HAVE_DAHDI - tmp->timingfd = open("/dev/dahdi/timer", O_RDWR); + tmp->timingfd = ast_timer_open(); if (tmp->timingfd > -1) { - /* Check if timing interface supports new - ping/pong scheme */ - flags = 1; - if (!ioctl(tmp->timingfd, DAHDI_TIMERPONG, &flags)) - needqueue = 0; + needqueue = 0; } -#else - tmp->timingfd = -1; -#endif if (needqueue) { if (pipe(tmp->alertpipe)) { ast_log(LOG_WARNING, "Channel allocation failed: Can't create alert pipe!\n"); alertpipe_failed: -#ifdef HAVE_DAHDI - if (tmp->timingfd > -1) - close(tmp->timingfd); -#endif + if (tmp->timingfd > -1) { + ast_timer_close(tmp->timingfd); + } + sched_context_destroy(tmp->sched); ast_string_field_free_memory(tmp); ast_free(tmp); @@ -1007,10 +1000,8 @@ int ast_queue_frame(struct ast_channel *chan, struct ast_frame *fin) if (write(chan->alertpipe[1], &blah, sizeof(blah)) != sizeof(blah)) ast_log(LOG_WARNING, "Unable to write to alert pipe on %s, frametype/subclass %d/%d (qlen = %d): %s!\n", chan->name, f->frametype, f->subclass, qlen, strerror(errno)); -#ifdef HAVE_DAHDI } else if (chan->timingfd > -1) { - ioctl(chan->timingfd, DAHDI_TIMERPING, &blah); -#endif + ast_timer_enable_continuous(chan->timingfd); } else if (ast_test_flag(chan, AST_FLAG_BLOCKING)) { pthread_kill(chan->blocker, SIGURG); } @@ -1343,7 +1334,7 @@ void ast_channel_free(struct ast_channel *chan) if ((fd = chan->alertpipe[1]) > -1) close(fd); if ((fd = chan->timingfd) > -1) - close(fd); + ast_timer_close(fd); #ifdef HAVE_EPOLL for (i = 0; i < AST_MAX_FDS; i++) { if (chan->epfd_data[i]) @@ -1795,7 +1786,7 @@ int ast_activate_generator(struct ast_channel *chan, struct ast_generator *gen, } if (!res) { - ast_settimeout(chan, 160, generator_force, chan); + ast_settimeout(chan, 50, generator_force, chan); chan->generator = gen; } @@ -2181,21 +2172,26 @@ int ast_waitfordigit(struct ast_channel *c, int ms) return ast_waitfordigit_full(c, ms, -1, -1); } -int ast_settimeout(struct ast_channel *c, int samples, int (*func)(const void *data), void *data) +int ast_settimeout(struct ast_channel *c, unsigned int rate, int (*func)(const void *data), void *data) { - int res = -1; -#ifdef HAVE_DAHDI - if (c->timingfd > -1) { - if (!func) { - samples = 0; - data = 0; - } - ast_debug(1, "Scheduling timer at %d sample intervals\n", samples); - res = ioctl(c->timingfd, DAHDI_TIMERCONFIG, &samples); - c->timingfunc = func; - c->timingdata = data; + int res; + + if (c->timingfd == -1) { + return -1; + } + + if (!func) { + rate = 0; + data = NULL; } -#endif + + ast_debug(1, "Scheduling timer at %u timer ticks per second\n", rate); + + res = ast_timer_set_rate(c->timingfd, rate); + + c->timingfunc = func; + c->timingdata = data; + return res; } @@ -2334,7 +2330,7 @@ static void ast_read_generator_actions(struct ast_channel *chan, struct ast_fram } else if (f->frametype == AST_FRAME_CNG) { if (chan->generator && !chan->timingfunc && (chan->timingfd > -1)) { ast_debug(1, "Generator got CNG, switching to timed mode\n"); - ast_settimeout(chan, 160, generator_force, chan); + ast_settimeout(chan, 50, generator_force, chan); } } } diff --git a/main/file.c b/main/file.c index 15b6a5d88..8e27c58a0 100644 --- a/main/file.c +++ b/main/file.c @@ -29,6 +29,7 @@ ASTERISK_FILE_VERSION(__FILE__, "$Revision$") #include <dirent.h> #include <sys/stat.h> +#include <math.h> #include "asterisk/_private.h" /* declare ast_file_init() */ #include "asterisk/paths.h" /* use ast_config_AST_DATA_DIR */ @@ -659,21 +660,17 @@ static enum fsread_res ast_readaudio_callback(struct ast_filestream *s) } } if (whennext != s->lasttimeout) { -#ifdef HAVE_DAHDI if (s->owner->timingfd > -1) { - int zap_timer_samples = whennext; - int rate; - /* whennext is in samples, but DAHDI timers operate in 8 kHz samples. */ - if ((rate = ast_format_rate(s->fmt->format)) != 8000) { - float factor; - factor = ((float) rate) / ((float) 8000.0); - zap_timer_samples = (int) ( ((float) zap_timer_samples) / factor ); - } - ast_settimeout(s->owner, zap_timer_samples, ast_fsread_audio, s); - } else -#endif + float samp_rate = (float) ast_format_rate(s->fmt->format); + unsigned int rate; + + rate = (unsigned int) roundf(samp_rate / ((float) whennext)); + + ast_settimeout(s->owner, rate, ast_fsread_audio, s); + } else { s->owner->streamid = ast_sched_add(s->owner->sched, whennext / (ast_format_rate(s->fmt->format) / 1000), ast_fsread_audio, s); + } s->lasttimeout = whennext; return FSREAD_SUCCESS_NOSCHED; } @@ -681,9 +678,7 @@ static enum fsread_res ast_readaudio_callback(struct ast_filestream *s) return_failure: s->owner->streamid = -1; -#ifdef HAVE_DAHDI ast_settimeout(s->owner, 0, NULL, NULL); -#endif return FSREAD_FAILURE; } @@ -792,9 +787,7 @@ int ast_closestream(struct ast_filestream *f) if (f->fmt->format & AST_FORMAT_AUDIO_MASK) { f->owner->stream = NULL; AST_SCHED_DEL(f->owner->sched, f->owner->streamid); -#ifdef HAVE_DAHDI ast_settimeout(f->owner, 0, NULL, NULL); -#endif } else { f->owner->vstream = NULL; AST_SCHED_DEL(f->owner->sched, f->owner->vstreamid); diff --git a/main/timing.c b/main/timing.c index d87ebcc15..6de1a29dd 100644 --- a/main/timing.c +++ b/main/timing.c @@ -30,7 +30,7 @@ ASTERISK_FILE_VERSION(__FILE__, "$Revision$") #include "asterisk/timing.h" #include "asterisk/lock.h" -AST_MUTEX_DEFINE_STATIC(lock); +AST_RWLOCK_DEFINE_STATIC(lock); static struct ast_timing_functions timer_funcs; @@ -38,6 +38,7 @@ void *ast_install_timing_functions(struct ast_timing_functions *funcs) { if (!funcs->timer_open || !funcs->timer_close || + !funcs->timer_set_rate || !funcs->timer_ack || !funcs->timer_get_event || !funcs->timer_enable_continuous || @@ -45,94 +46,113 @@ void *ast_install_timing_functions(struct ast_timing_functions *funcs) return NULL; } - ast_mutex_lock(&lock); + ast_rwlock_wrlock(&lock); if (timer_funcs.timer_open) { - ast_mutex_unlock(&lock); + ast_rwlock_unlock(&lock); + ast_log(LOG_NOTICE, "Multiple timing modules are loaded. You should only load one.\n"); return NULL; } timer_funcs = *funcs; - ast_mutex_unlock(&lock); + ast_rwlock_unlock(&lock); return &timer_funcs; } void ast_uninstall_timing_functions(void *handle) { - ast_mutex_lock(&lock); + ast_rwlock_wrlock(&lock); if (handle != &timer_funcs) { - ast_mutex_unlock(&lock); + ast_rwlock_unlock(&lock); return; } memset(&timer_funcs, 0, sizeof(timer_funcs)); - ast_mutex_unlock(&lock); + ast_rwlock_unlock(&lock); } -int ast_timer_open(unsigned int rate) +int ast_timer_open(void) { int timer; - ast_mutex_lock(&lock); + ast_rwlock_rdlock(&lock); if (!timer_funcs.timer_open) { - ast_mutex_unlock(&lock); + ast_rwlock_unlock(&lock); return -1; } - timer = timer_funcs.timer_open(rate); + timer = timer_funcs.timer_open(); - ast_mutex_unlock(&lock); + ast_rwlock_unlock(&lock); return timer; } void ast_timer_close(int timer) { - ast_mutex_lock(&lock); + ast_rwlock_rdlock(&lock); if (!timer_funcs.timer_close) { - ast_mutex_unlock(&lock); + ast_rwlock_unlock(&lock); return; } timer_funcs.timer_close(timer); - ast_mutex_unlock(&lock); + ast_rwlock_unlock(&lock); +} + +int ast_timer_set_rate(int handle, unsigned int rate) +{ + int res; + + ast_rwlock_rdlock(&lock); + + if (!timer_funcs.timer_set_rate) { + ast_rwlock_unlock(&lock); + return -1; + } + + res = timer_funcs.timer_set_rate(handle, rate); + + ast_rwlock_unlock(&lock); + + return res; } void ast_timer_ack(int handle, unsigned int quantity) { - ast_mutex_lock(&lock); + ast_rwlock_rdlock(&lock); if (!timer_funcs.timer_ack) { - ast_mutex_unlock(&lock); + ast_rwlock_unlock(&lock); return; } timer_funcs.timer_ack(handle, quantity); - ast_mutex_unlock(&lock); + ast_rwlock_unlock(&lock); } int ast_timer_enable_continuous(int handle) { int result; - ast_mutex_lock(&lock); + ast_rwlock_rdlock(&lock); if (!timer_funcs.timer_enable_continuous) { - ast_mutex_unlock(&lock); + ast_rwlock_unlock(&lock); return -1; } result = timer_funcs.timer_enable_continuous(handle); - ast_mutex_unlock(&lock); + ast_rwlock_unlock(&lock); return result; } @@ -141,16 +161,16 @@ int ast_timer_disable_continous(int handle) { int result; - ast_mutex_lock(&lock); + ast_rwlock_rdlock(&lock); if (!timer_funcs.timer_disable_continuous) { - ast_mutex_unlock(&lock); + ast_rwlock_unlock(&lock); return -1; } result = timer_funcs.timer_disable_continuous(handle); - ast_mutex_unlock(&lock); + ast_rwlock_unlock(&lock); return result; } @@ -159,16 +179,16 @@ enum ast_timing_event ast_timer_get_event(int handle) { enum ast_timing_event result; - ast_mutex_lock(&lock); + ast_rwlock_rdlock(&lock); if (!timer_funcs.timer_get_event) { - ast_mutex_unlock(&lock); + ast_rwlock_unlock(&lock); return -1; } result = timer_funcs.timer_get_event(handle); - ast_mutex_unlock(&lock); + ast_rwlock_unlock(&lock); return result; } |