From e509ea55c0c06ddd5bc57d6ed8e47fae3aa6ce66 Mon Sep 17 00:00:00 2001 From: markster Date: Sun, 6 May 2001 14:50:50 +0000 Subject: Version 0.1.8 from FTP git-svn-id: http://svn.digium.com/svn/asterisk/trunk@313 f38db490-d61c-443f-a65b-d21fe96a405b --- channels/chan_vofr.c | 101 ++++++++++++++++++++++++++++----------------------- 1 file changed, 56 insertions(+), 45 deletions(-) diff --git a/channels/chan_vofr.c b/channels/chan_vofr.c index cfd669eb0..836c1de34 100755 --- a/channels/chan_vofr.c +++ b/channels/chan_vofr.c @@ -253,6 +253,8 @@ static void vofr_dump_packet(struct vofr_hdr *vh, int len) #endif +static struct ast_frame *vofr_read(struct ast_channel *ast); + static int vofr_xmit(struct vofr_pvt *p, char *data, int len) { int res; @@ -360,7 +362,7 @@ static int vofr_call(struct ast_channel *ast, char *dest, int timeout) /* Musta gotten hung up, or no ack on off hook */ return -1; } - f = ast_read(ast); + f = vofr_read(ast); if (!f) return -1; if ((f->frametype == AST_FRAME_CONTROL) && @@ -390,7 +392,7 @@ static int vofr_call(struct ast_channel *ast, char *dest, int timeout) /* Musta gotten hung up, or no ack on off hook */ return -1; } - f = ast_read(ast); + f = vofr_read(ast); if (!f) return -1; @@ -418,7 +420,7 @@ static int vofr_call(struct ast_channel *ast, char *dest, int timeout) timeout = res; if (res) { /* Ooh, read what's there. */ - f = ast_read(ast); + f = vofr_read(ast); if (!f) return -1; if ((f->frametype == AST_FRAME_CONTROL) && @@ -454,11 +456,11 @@ static int vofr_hangup(struct ast_channel *ast) ast->state = AST_STATE_DOWN; ((struct vofr_pvt *)(ast->pvt->pvt))->owner = NULL; ((struct vofr_pvt *)(ast->pvt->pvt))->ringgothangup = 0; - pthread_mutex_lock(&usecnt_lock); + ast_pthread_mutex_lock(&usecnt_lock); usecnt--; if (usecnt < 0) ast_log(LOG_WARNING, "Usecnt < 0???\n"); - pthread_mutex_unlock(&usecnt_lock); + ast_pthread_mutex_unlock(&usecnt_lock); ast_update_use_count(); if (option_verbose > 2) ast_verbose( VERBOSE_PREFIX_3 "Hungup '%s'\n", ast->name); @@ -484,7 +486,7 @@ static int vofr_answer(struct ast_channel *ast) while(cnt > 0) { cnt = ast_waitfor(ast, cnt); if (cnt > 0) { - res = read(ast->fd, buf, sizeof(buf)); + res = read(ast->fds[0], buf, sizeof(buf)); #ifdef VOFRDUMPER vofr_dump_packet((void *)(buf +FR_API_MESS), res - FR_API_MESS); #endif @@ -782,6 +784,17 @@ static int vofr_write(struct ast_channel *ast, struct ast_frame *frame) return 0; } +static int vofr_fixup(struct ast_channel *oldchan, struct ast_channel *newchan) +{ + struct vofr_pvt *p = newchan->pvt->pvt; + if (p->owner != oldchan) { + ast_log(LOG_WARNING, "old channel wasn't %p but was %p\n", oldchan, p->owner); + return -1; + } + p->owner = newchan; + return 0; +} + static struct ast_channel *vofr_new(struct vofr_pvt *i, int state) { struct ast_channel *tmp; @@ -793,12 +806,14 @@ static struct ast_channel *vofr_new(struct vofr_pvt *i, int state) snprintf(tmp->name, sizeof(tmp->name), "AdtranVoFR/%s", i->sa.sll_device); #endif tmp->type = type; - tmp->fd = i->s; + tmp->fds[0] = i->s; /* Adtran VoFR supports only G723.1 format data. G711 (ulaw) would be nice too */ tmp->nativeformats = AST_FORMAT_G723_1; tmp->state = state; if (state == AST_STATE_RING) tmp->rings = 1; + tmp->writeformat = AST_FORMAT_G723_1; + tmp->readformat = AST_FORMAT_G723_1; tmp->pvt->pvt = i; tmp->pvt->send_digit = vofr_digit; tmp->pvt->call = vofr_call; @@ -806,12 +821,13 @@ static struct ast_channel *vofr_new(struct vofr_pvt *i, int state) tmp->pvt->answer = vofr_answer; tmp->pvt->read = vofr_read; tmp->pvt->write = vofr_write; + tmp->pvt->fixup = vofr_fixup; if (strlen(i->language)) strncpy(tmp->language, i->language, sizeof(tmp->language)); i->owner = tmp; - pthread_mutex_lock(&usecnt_lock); + ast_pthread_mutex_lock(&usecnt_lock); usecnt++; - pthread_mutex_unlock(&usecnt_lock); + ast_pthread_mutex_unlock(&usecnt_lock); ast_update_use_count(); strncpy(tmp->context, i->context, sizeof(tmp->context)); if (state != AST_STATE_DOWN) { @@ -899,14 +915,14 @@ static void *do_monitor(void *data) for(;;) { /* Don't let anybody kill us right away. Nobody should lock the interface list and wait for the monitor list, but the other way around is okay. */ - if (pthread_mutex_lock(&monlock)) { + if (ast_pthread_mutex_lock(&monlock)) { ast_log(LOG_ERROR, "Unable to grab monitor lock\n"); return NULL; } /* Lock the interface list */ - if (pthread_mutex_lock(&iflock)) { + if (ast_pthread_mutex_lock(&iflock)) { ast_log(LOG_ERROR, "Unable to grab interface lock\n"); - pthread_mutex_unlock(&monlock); + ast_pthread_mutex_unlock(&monlock); return NULL; } /* Build the stuff we're going to select on, that is the socket of every @@ -930,10 +946,10 @@ static void *do_monitor(void *data) i = i->next; } /* Okay, now that we know what to do, release the interface lock */ - pthread_mutex_unlock(&iflock); + ast_pthread_mutex_unlock(&iflock); /* And from now on, we're okay to be killed, so release the monitor lock as well */ - pthread_mutex_unlock(&monlock); + ast_pthread_mutex_unlock(&monlock); pthread_testcancel(); /* Wait indefinitely for something to happen */ res = select(n + 1, &rfds, NULL, NULL, NULL); @@ -946,7 +962,7 @@ static void *do_monitor(void *data) } /* Alright, lock the interface list again, and let's look and see what has happened */ - if (pthread_mutex_lock(&iflock)) { + if (ast_pthread_mutex_lock(&iflock)) { ast_log(LOG_WARNING, "Unable to lock the interface list\n"); continue; } @@ -970,7 +986,7 @@ static void *do_monitor(void *data) } i=i->next; } - pthread_mutex_unlock(&iflock); + ast_pthread_mutex_unlock(&iflock); } /* Never reached */ return NULL; @@ -982,32 +998,27 @@ static int restart_monitor(void) /* If we're supposed to be stopped -- stay stopped */ if (monitor_thread == -2) return 0; - if (pthread_mutex_lock(&monlock)) { + if (ast_pthread_mutex_lock(&monlock)) { ast_log(LOG_WARNING, "Unable to lock monitor\n"); return -1; } if (monitor_thread == pthread_self()) { - pthread_mutex_unlock(&monlock); + ast_pthread_mutex_unlock(&monlock); ast_log(LOG_WARNING, "Cannot kill myself\n"); return -1; } if (monitor_thread) { -#if 0 - pthread_cancel(monitor_thread); -#endif + /* Wake up the thread */ pthread_kill(monitor_thread, SIGURG); -#if 0 - pthread_join(monitor_thread, NULL); -#endif - } - if (!monitor_thread) - /* Start a new monitor */ - if (pthread_create(&monitor_thread, NULL, do_monitor, NULL) < 0) { - pthread_mutex_unlock(&monlock); - ast_log(LOG_ERROR, "Unable to start monitor thread.\n"); - return -1; + } else { + /* Start a new monitor */ + if (pthread_create(&monitor_thread, NULL, do_monitor, NULL) < 0) { + ast_pthread_mutex_unlock(&monlock); + ast_log(LOG_ERROR, "Unable to start monitor thread.\n"); + return -1; + } } - pthread_mutex_unlock(&monlock); + ast_pthread_mutex_unlock(&monlock); return 0; } @@ -1107,7 +1118,7 @@ static struct ast_channel *vofr_request(char *type, int format, void *data) return NULL; } /* Search for an unowned channel */ - if (pthread_mutex_lock(&iflock)) { + if (ast_pthread_mutex_lock(&iflock)) { ast_log(LOG_ERROR, "Unable to lock interface list???\n"); return NULL; } @@ -1119,7 +1130,7 @@ static struct ast_channel *vofr_request(char *type, int format, void *data) } p = p->next; } - pthread_mutex_unlock(&iflock); + ast_pthread_mutex_unlock(&iflock); restart_monitor(); return tmp; } @@ -1136,7 +1147,7 @@ int load_module() ast_log(LOG_ERROR, "Unable to load config %s\n", config); return -1; } - if (pthread_mutex_lock(&iflock)) { + if (ast_pthread_mutex_lock(&iflock)) { /* It's a little silly to lock it, but we mind as well just to be sure */ ast_log(LOG_ERROR, "Unable to lock interface list???\n"); return -1; @@ -1153,7 +1164,7 @@ int load_module() } else { ast_log(LOG_ERROR, "Unable to register channel '%s'\n", v->value); ast_destroy(cfg); - pthread_mutex_unlock(&iflock); + ast_pthread_mutex_unlock(&iflock); unload_module(); return -1; } @@ -1164,7 +1175,7 @@ int load_module() } v = v->next; } - pthread_mutex_unlock(&iflock); + ast_pthread_mutex_unlock(&iflock); /* Make sure we can register our AdtranVoFR channel type */ if (ast_channel_register(type, tdesc, AST_FORMAT_G723_1, vofr_request)) { ast_log(LOG_ERROR, "Unable to register channel class %s\n", type); @@ -1183,7 +1194,7 @@ int unload_module() struct vofr_pvt *p, *pl; /* First, take us out of the channel loop */ ast_channel_unregister(type); - if (!pthread_mutex_lock(&iflock)) { + if (!ast_pthread_mutex_lock(&iflock)) { /* Hangup all interfaces if they have an owner */ p = iflist; while(p) { @@ -1192,25 +1203,25 @@ int unload_module() p = p->next; } iflist = NULL; - pthread_mutex_unlock(&iflock); + ast_pthread_mutex_unlock(&iflock); } else { ast_log(LOG_WARNING, "Unable to lock the monitor\n"); return -1; } - if (!pthread_mutex_lock(&monlock)) { + if (!ast_pthread_mutex_lock(&monlock)) { if (monitor_thread) { pthread_cancel(monitor_thread); pthread_kill(monitor_thread, SIGURG); pthread_join(monitor_thread, NULL); } monitor_thread = -2; - pthread_mutex_unlock(&monlock); + ast_pthread_mutex_unlock(&monlock); } else { ast_log(LOG_WARNING, "Unable to lock the monitor\n"); return -1; } - if (!pthread_mutex_lock(&iflock)) { + if (!ast_pthread_mutex_lock(&iflock)) { /* Destroy all the interfaces and free their memory */ p = iflist; while(p) { @@ -1223,7 +1234,7 @@ int unload_module() free(pl); } iflist = NULL; - pthread_mutex_unlock(&iflock); + ast_pthread_mutex_unlock(&iflock); } else { ast_log(LOG_WARNING, "Unable to lock the monitor\n"); return -1; @@ -1235,9 +1246,9 @@ int unload_module() int usecount() { int res; - pthread_mutex_lock(&usecnt_lock); + ast_pthread_mutex_lock(&usecnt_lock); res = usecnt; - pthread_mutex_unlock(&usecnt_lock); + ast_pthread_mutex_unlock(&usecnt_lock); return res; } -- cgit v1.2.3