Version 0.1.8 from FTP
git-svn-id: http://svn.digium.com/svn/asterisk/trunk@313 f38db490-d61c-443f-a65b-d21fe96a405b
This commit is contained in:
parent
a7de829e3a
commit
e509ea55c0
|
@ -253,6 +253,8 @@ static void vofr_dump_packet(struct vofr_hdr *vh, int len)
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
static struct ast_frame *vofr_read(struct ast_channel *ast);
|
||||||
|
|
||||||
static int vofr_xmit(struct vofr_pvt *p, char *data, int len)
|
static int vofr_xmit(struct vofr_pvt *p, char *data, int len)
|
||||||
{
|
{
|
||||||
int res;
|
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 */
|
/* Musta gotten hung up, or no ack on off hook */
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
f = ast_read(ast);
|
f = vofr_read(ast);
|
||||||
if (!f)
|
if (!f)
|
||||||
return -1;
|
return -1;
|
||||||
if ((f->frametype == AST_FRAME_CONTROL) &&
|
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 */
|
/* Musta gotten hung up, or no ack on off hook */
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
f = ast_read(ast);
|
f = vofr_read(ast);
|
||||||
if (!f)
|
if (!f)
|
||||||
return -1;
|
return -1;
|
||||||
|
|
||||||
|
@ -418,7 +420,7 @@ static int vofr_call(struct ast_channel *ast, char *dest, int timeout)
|
||||||
timeout = res;
|
timeout = res;
|
||||||
if (res) {
|
if (res) {
|
||||||
/* Ooh, read what's there. */
|
/* Ooh, read what's there. */
|
||||||
f = ast_read(ast);
|
f = vofr_read(ast);
|
||||||
if (!f)
|
if (!f)
|
||||||
return -1;
|
return -1;
|
||||||
if ((f->frametype == AST_FRAME_CONTROL) &&
|
if ((f->frametype == AST_FRAME_CONTROL) &&
|
||||||
|
@ -454,11 +456,11 @@ static int vofr_hangup(struct ast_channel *ast)
|
||||||
ast->state = AST_STATE_DOWN;
|
ast->state = AST_STATE_DOWN;
|
||||||
((struct vofr_pvt *)(ast->pvt->pvt))->owner = NULL;
|
((struct vofr_pvt *)(ast->pvt->pvt))->owner = NULL;
|
||||||
((struct vofr_pvt *)(ast->pvt->pvt))->ringgothangup = 0;
|
((struct vofr_pvt *)(ast->pvt->pvt))->ringgothangup = 0;
|
||||||
pthread_mutex_lock(&usecnt_lock);
|
ast_pthread_mutex_lock(&usecnt_lock);
|
||||||
usecnt--;
|
usecnt--;
|
||||||
if (usecnt < 0)
|
if (usecnt < 0)
|
||||||
ast_log(LOG_WARNING, "Usecnt < 0???\n");
|
ast_log(LOG_WARNING, "Usecnt < 0???\n");
|
||||||
pthread_mutex_unlock(&usecnt_lock);
|
ast_pthread_mutex_unlock(&usecnt_lock);
|
||||||
ast_update_use_count();
|
ast_update_use_count();
|
||||||
if (option_verbose > 2)
|
if (option_verbose > 2)
|
||||||
ast_verbose( VERBOSE_PREFIX_3 "Hungup '%s'\n", ast->name);
|
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) {
|
while(cnt > 0) {
|
||||||
cnt = ast_waitfor(ast, cnt);
|
cnt = ast_waitfor(ast, cnt);
|
||||||
if (cnt > 0) {
|
if (cnt > 0) {
|
||||||
res = read(ast->fd, buf, sizeof(buf));
|
res = read(ast->fds[0], buf, sizeof(buf));
|
||||||
#ifdef VOFRDUMPER
|
#ifdef VOFRDUMPER
|
||||||
vofr_dump_packet((void *)(buf +FR_API_MESS), res - FR_API_MESS);
|
vofr_dump_packet((void *)(buf +FR_API_MESS), res - FR_API_MESS);
|
||||||
#endif
|
#endif
|
||||||
|
@ -782,6 +784,17 @@ static int vofr_write(struct ast_channel *ast, struct ast_frame *frame)
|
||||||
return 0;
|
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)
|
static struct ast_channel *vofr_new(struct vofr_pvt *i, int state)
|
||||||
{
|
{
|
||||||
struct ast_channel *tmp;
|
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);
|
snprintf(tmp->name, sizeof(tmp->name), "AdtranVoFR/%s", i->sa.sll_device);
|
||||||
#endif
|
#endif
|
||||||
tmp->type = type;
|
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 */
|
/* Adtran VoFR supports only G723.1 format data. G711 (ulaw) would be nice too */
|
||||||
tmp->nativeformats = AST_FORMAT_G723_1;
|
tmp->nativeformats = AST_FORMAT_G723_1;
|
||||||
tmp->state = state;
|
tmp->state = state;
|
||||||
if (state == AST_STATE_RING)
|
if (state == AST_STATE_RING)
|
||||||
tmp->rings = 1;
|
tmp->rings = 1;
|
||||||
|
tmp->writeformat = AST_FORMAT_G723_1;
|
||||||
|
tmp->readformat = AST_FORMAT_G723_1;
|
||||||
tmp->pvt->pvt = i;
|
tmp->pvt->pvt = i;
|
||||||
tmp->pvt->send_digit = vofr_digit;
|
tmp->pvt->send_digit = vofr_digit;
|
||||||
tmp->pvt->call = vofr_call;
|
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->answer = vofr_answer;
|
||||||
tmp->pvt->read = vofr_read;
|
tmp->pvt->read = vofr_read;
|
||||||
tmp->pvt->write = vofr_write;
|
tmp->pvt->write = vofr_write;
|
||||||
|
tmp->pvt->fixup = vofr_fixup;
|
||||||
if (strlen(i->language))
|
if (strlen(i->language))
|
||||||
strncpy(tmp->language, i->language, sizeof(tmp->language));
|
strncpy(tmp->language, i->language, sizeof(tmp->language));
|
||||||
i->owner = tmp;
|
i->owner = tmp;
|
||||||
pthread_mutex_lock(&usecnt_lock);
|
ast_pthread_mutex_lock(&usecnt_lock);
|
||||||
usecnt++;
|
usecnt++;
|
||||||
pthread_mutex_unlock(&usecnt_lock);
|
ast_pthread_mutex_unlock(&usecnt_lock);
|
||||||
ast_update_use_count();
|
ast_update_use_count();
|
||||||
strncpy(tmp->context, i->context, sizeof(tmp->context));
|
strncpy(tmp->context, i->context, sizeof(tmp->context));
|
||||||
if (state != AST_STATE_DOWN) {
|
if (state != AST_STATE_DOWN) {
|
||||||
|
@ -899,14 +915,14 @@ static void *do_monitor(void *data)
|
||||||
for(;;) {
|
for(;;) {
|
||||||
/* Don't let anybody kill us right away. Nobody should lock the interface list
|
/* 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. */
|
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");
|
ast_log(LOG_ERROR, "Unable to grab monitor lock\n");
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
/* Lock the interface list */
|
/* 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");
|
ast_log(LOG_ERROR, "Unable to grab interface lock\n");
|
||||||
pthread_mutex_unlock(&monlock);
|
ast_pthread_mutex_unlock(&monlock);
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
/* Build the stuff we're going to select on, that is the socket of every
|
/* 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;
|
i = i->next;
|
||||||
}
|
}
|
||||||
/* Okay, now that we know what to do, release the interface lock */
|
/* 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 */
|
/* 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();
|
pthread_testcancel();
|
||||||
/* Wait indefinitely for something to happen */
|
/* Wait indefinitely for something to happen */
|
||||||
res = select(n + 1, &rfds, NULL, NULL, NULL);
|
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
|
/* Alright, lock the interface list again, and let's look and see what has
|
||||||
happened */
|
happened */
|
||||||
if (pthread_mutex_lock(&iflock)) {
|
if (ast_pthread_mutex_lock(&iflock)) {
|
||||||
ast_log(LOG_WARNING, "Unable to lock the interface list\n");
|
ast_log(LOG_WARNING, "Unable to lock the interface list\n");
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
@ -970,7 +986,7 @@ static void *do_monitor(void *data)
|
||||||
}
|
}
|
||||||
i=i->next;
|
i=i->next;
|
||||||
}
|
}
|
||||||
pthread_mutex_unlock(&iflock);
|
ast_pthread_mutex_unlock(&iflock);
|
||||||
}
|
}
|
||||||
/* Never reached */
|
/* Never reached */
|
||||||
return NULL;
|
return NULL;
|
||||||
|
@ -982,32 +998,27 @@ static int restart_monitor(void)
|
||||||
/* If we're supposed to be stopped -- stay stopped */
|
/* If we're supposed to be stopped -- stay stopped */
|
||||||
if (monitor_thread == -2)
|
if (monitor_thread == -2)
|
||||||
return 0;
|
return 0;
|
||||||
if (pthread_mutex_lock(&monlock)) {
|
if (ast_pthread_mutex_lock(&monlock)) {
|
||||||
ast_log(LOG_WARNING, "Unable to lock monitor\n");
|
ast_log(LOG_WARNING, "Unable to lock monitor\n");
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
if (monitor_thread == pthread_self()) {
|
if (monitor_thread == pthread_self()) {
|
||||||
pthread_mutex_unlock(&monlock);
|
ast_pthread_mutex_unlock(&monlock);
|
||||||
ast_log(LOG_WARNING, "Cannot kill myself\n");
|
ast_log(LOG_WARNING, "Cannot kill myself\n");
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
if (monitor_thread) {
|
if (monitor_thread) {
|
||||||
#if 0
|
/* Wake up the thread */
|
||||||
pthread_cancel(monitor_thread);
|
|
||||||
#endif
|
|
||||||
pthread_kill(monitor_thread, SIGURG);
|
pthread_kill(monitor_thread, SIGURG);
|
||||||
#if 0
|
} else {
|
||||||
pthread_join(monitor_thread, NULL);
|
/* Start a new monitor */
|
||||||
#endif
|
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;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
if (!monitor_thread)
|
ast_pthread_mutex_unlock(&monlock);
|
||||||
/* 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;
|
|
||||||
}
|
|
||||||
pthread_mutex_unlock(&monlock);
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1107,7 +1118,7 @@ static struct ast_channel *vofr_request(char *type, int format, void *data)
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
/* Search for an unowned channel */
|
/* 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");
|
ast_log(LOG_ERROR, "Unable to lock interface list???\n");
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
@ -1119,7 +1130,7 @@ static struct ast_channel *vofr_request(char *type, int format, void *data)
|
||||||
}
|
}
|
||||||
p = p->next;
|
p = p->next;
|
||||||
}
|
}
|
||||||
pthread_mutex_unlock(&iflock);
|
ast_pthread_mutex_unlock(&iflock);
|
||||||
restart_monitor();
|
restart_monitor();
|
||||||
return tmp;
|
return tmp;
|
||||||
}
|
}
|
||||||
|
@ -1136,7 +1147,7 @@ int load_module()
|
||||||
ast_log(LOG_ERROR, "Unable to load config %s\n", config);
|
ast_log(LOG_ERROR, "Unable to load config %s\n", config);
|
||||||
return -1;
|
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 */
|
/* 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");
|
ast_log(LOG_ERROR, "Unable to lock interface list???\n");
|
||||||
return -1;
|
return -1;
|
||||||
|
@ -1153,7 +1164,7 @@ int load_module()
|
||||||
} else {
|
} else {
|
||||||
ast_log(LOG_ERROR, "Unable to register channel '%s'\n", v->value);
|
ast_log(LOG_ERROR, "Unable to register channel '%s'\n", v->value);
|
||||||
ast_destroy(cfg);
|
ast_destroy(cfg);
|
||||||
pthread_mutex_unlock(&iflock);
|
ast_pthread_mutex_unlock(&iflock);
|
||||||
unload_module();
|
unload_module();
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
@ -1164,7 +1175,7 @@ int load_module()
|
||||||
}
|
}
|
||||||
v = v->next;
|
v = v->next;
|
||||||
}
|
}
|
||||||
pthread_mutex_unlock(&iflock);
|
ast_pthread_mutex_unlock(&iflock);
|
||||||
/* Make sure we can register our AdtranVoFR channel type */
|
/* Make sure we can register our AdtranVoFR channel type */
|
||||||
if (ast_channel_register(type, tdesc, AST_FORMAT_G723_1, vofr_request)) {
|
if (ast_channel_register(type, tdesc, AST_FORMAT_G723_1, vofr_request)) {
|
||||||
ast_log(LOG_ERROR, "Unable to register channel class %s\n", type);
|
ast_log(LOG_ERROR, "Unable to register channel class %s\n", type);
|
||||||
|
@ -1183,7 +1194,7 @@ int unload_module()
|
||||||
struct vofr_pvt *p, *pl;
|
struct vofr_pvt *p, *pl;
|
||||||
/* First, take us out of the channel loop */
|
/* First, take us out of the channel loop */
|
||||||
ast_channel_unregister(type);
|
ast_channel_unregister(type);
|
||||||
if (!pthread_mutex_lock(&iflock)) {
|
if (!ast_pthread_mutex_lock(&iflock)) {
|
||||||
/* Hangup all interfaces if they have an owner */
|
/* Hangup all interfaces if they have an owner */
|
||||||
p = iflist;
|
p = iflist;
|
||||||
while(p) {
|
while(p) {
|
||||||
|
@ -1192,25 +1203,25 @@ int unload_module()
|
||||||
p = p->next;
|
p = p->next;
|
||||||
}
|
}
|
||||||
iflist = NULL;
|
iflist = NULL;
|
||||||
pthread_mutex_unlock(&iflock);
|
ast_pthread_mutex_unlock(&iflock);
|
||||||
} else {
|
} else {
|
||||||
ast_log(LOG_WARNING, "Unable to lock the monitor\n");
|
ast_log(LOG_WARNING, "Unable to lock the monitor\n");
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
if (!pthread_mutex_lock(&monlock)) {
|
if (!ast_pthread_mutex_lock(&monlock)) {
|
||||||
if (monitor_thread) {
|
if (monitor_thread) {
|
||||||
pthread_cancel(monitor_thread);
|
pthread_cancel(monitor_thread);
|
||||||
pthread_kill(monitor_thread, SIGURG);
|
pthread_kill(monitor_thread, SIGURG);
|
||||||
pthread_join(monitor_thread, NULL);
|
pthread_join(monitor_thread, NULL);
|
||||||
}
|
}
|
||||||
monitor_thread = -2;
|
monitor_thread = -2;
|
||||||
pthread_mutex_unlock(&monlock);
|
ast_pthread_mutex_unlock(&monlock);
|
||||||
} else {
|
} else {
|
||||||
ast_log(LOG_WARNING, "Unable to lock the monitor\n");
|
ast_log(LOG_WARNING, "Unable to lock the monitor\n");
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!pthread_mutex_lock(&iflock)) {
|
if (!ast_pthread_mutex_lock(&iflock)) {
|
||||||
/* Destroy all the interfaces and free their memory */
|
/* Destroy all the interfaces and free their memory */
|
||||||
p = iflist;
|
p = iflist;
|
||||||
while(p) {
|
while(p) {
|
||||||
|
@ -1223,7 +1234,7 @@ int unload_module()
|
||||||
free(pl);
|
free(pl);
|
||||||
}
|
}
|
||||||
iflist = NULL;
|
iflist = NULL;
|
||||||
pthread_mutex_unlock(&iflock);
|
ast_pthread_mutex_unlock(&iflock);
|
||||||
} else {
|
} else {
|
||||||
ast_log(LOG_WARNING, "Unable to lock the monitor\n");
|
ast_log(LOG_WARNING, "Unable to lock the monitor\n");
|
||||||
return -1;
|
return -1;
|
||||||
|
@ -1235,9 +1246,9 @@ int unload_module()
|
||||||
int usecount()
|
int usecount()
|
||||||
{
|
{
|
||||||
int res;
|
int res;
|
||||||
pthread_mutex_lock(&usecnt_lock);
|
ast_pthread_mutex_lock(&usecnt_lock);
|
||||||
res = usecnt;
|
res = usecnt;
|
||||||
pthread_mutex_unlock(&usecnt_lock);
|
ast_pthread_mutex_unlock(&usecnt_lock);
|
||||||
return res;
|
return res;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Reference in New Issue