Version 0.1.8 from FTP

git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@270 65c4cc65-6c06-0410-ace0-fbb531ad65f3
This commit is contained in:
Mark Spencer
2001-04-10 20:52:03 +00:00
parent 5f97dfdf34
commit b178be4766
2 changed files with 51 additions and 37 deletions

View File

@@ -33,6 +33,13 @@ static char *tdesc = "Silly MP3 Application";
static char *app = "MP3Player"; static char *app = "MP3Player";
static char *synopsis = "Play an MP3 file or stream";
static char *descrip =
" MP3Player(location) Executes mpg123 to play the given location\n"
" which typically would be a filename or a URL. Returns -1 on\n"
" hangup or 0 otherwise. User can exit by pressing any key\n.";
STANDARD_LOCAL_USER; STANDARD_LOCAL_USER;
LOCAL_USER_DECL; LOCAL_USER_DECL;
@@ -60,7 +67,7 @@ static int mp3_exec(struct ast_channel *chan, void *data)
int res=0; int res=0;
struct localuser *u; struct localuser *u;
int fds[2]; int fds[2];
int rfds[2]; int rfds[1 + AST_MAX_FDS];
int ms = -1; int ms = -1;
int pid; int pid;
int us; int us;
@@ -69,6 +76,7 @@ static int mp3_exec(struct ast_channel *chan, void *data)
struct timeval tv; struct timeval tv;
struct timeval last; struct timeval last;
struct ast_frame *f; struct ast_frame *f;
int x;
struct myframe { struct myframe {
struct ast_frame f; struct ast_frame f;
char offset[AST_FRIENDLY_OFFSET]; char offset[AST_FRIENDLY_OFFSET];
@@ -99,17 +107,23 @@ static int mp3_exec(struct ast_channel *chan, void *data)
pid = res; pid = res;
/* Order is important -- there's almost always going to be mp3... we want to prioritize the /* Order is important -- there's almost always going to be mp3... we want to prioritize the
user */ user */
rfds[0] = chan->fd; for (x=0;x<AST_MAX_FDS;x++)
rfds[1] = fds[0]; rfds[x] = chan->fds[x];
rfds[x] = fds[0];
for (;;) { for (;;) {
CHECK_BLOCKING(chan); CHECK_BLOCKING(chan);
res = ast_waitfor_n_fd(rfds, 2, &ms, &exception); res = ast_waitfor_n_fd(rfds, AST_MAX_FDS+1, &ms, &exception);
chan->blocking = 0; chan->blocking = 0;
if (res < 1) { if (res < 1) {
ast_log(LOG_DEBUG, "Hangup detected\n"); ast_log(LOG_DEBUG, "Hangup detected\n");
res = -1; res = -1;
break; break;
} else if (res == chan->fd) { }
for(x=0;x<AST_MAX_FDS;x++)
if (res == chan->fds[x])
break;
if (x < AST_MAX_FDS) {
if (exception) if (exception)
chan->exception = 1; chan->exception = 1;
f = ast_read(chan); f = ast_read(chan);
@@ -181,7 +195,7 @@ int unload_module(void)
int load_module(void) int load_module(void)
{ {
return ast_register_application(app, mp3_exec); return ast_register_application(app, mp3_exec, synopsis, descrip);
} }
char *description(void) char *description(void)

View File

@@ -363,11 +363,11 @@ static int modem_hangup(struct ast_channel *ast)
ast->state = AST_STATE_DOWN; ast->state = AST_STATE_DOWN;
memset(p->cid, 0, sizeof(p->cid)); memset(p->cid, 0, sizeof(p->cid));
((struct ast_modem_pvt *)(ast->pvt->pvt))->owner = NULL; ((struct ast_modem_pvt *)(ast->pvt->pvt))->owner = NULL;
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);
@@ -431,7 +431,7 @@ struct ast_channel *ast_modem_new(struct ast_modem_pvt *i, int state)
if (tmp) { if (tmp) {
snprintf(tmp->name, sizeof(tmp->name), "Modem[%s]/%s", i->mc->name, i->dev + 5); snprintf(tmp->name, sizeof(tmp->name), "Modem[%s]/%s", i->mc->name, i->dev + 5);
tmp->type = type; tmp->type = type;
tmp->fd = i->fd; tmp->fds[0] = i->fd;
tmp->nativeformats = i->mc->formats; tmp->nativeformats = i->mc->formats;
tmp->state = state; tmp->state = state;
if (state == AST_STATE_RING) if (state == AST_STATE_RING)
@@ -449,9 +449,9 @@ struct ast_channel *ast_modem_new(struct ast_modem_pvt *i, int state)
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();
if (state != AST_STATE_DOWN) { if (state != AST_STATE_DOWN) {
if (ast_pbx_start(tmp)) { if (ast_pbx_start(tmp)) {
@@ -493,14 +493,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
@@ -523,10 +523,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);
#if 0 #if 0
ast_log(LOG_DEBUG, "In monitor, n=%d, pid=%d\n", n, getpid()); ast_log(LOG_DEBUG, "In monitor, n=%d, pid=%d\n", n, getpid());
#endif #endif
@@ -541,7 +541,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;
} }
@@ -557,7 +557,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;
@@ -569,12 +569,12 @@ static int restart_monitor()
/* 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;
} }
@@ -586,11 +586,11 @@ static int restart_monitor()
} }
/* Start a new monitor */ /* Start a new monitor */
if (pthread_create(&monitor_thread, NULL, do_monitor, NULL) < 0) { if (pthread_create(&monitor_thread, NULL, do_monitor, NULL) < 0) {
pthread_mutex_unlock(&monlock); ast_pthread_mutex_unlock(&monlock);
ast_log(LOG_ERROR, "Unable to start monitor thread.\n"); ast_log(LOG_ERROR, "Unable to start monitor thread.\n");
return -1; return -1;
} }
pthread_mutex_unlock(&monlock); ast_pthread_mutex_unlock(&monlock);
return 0; return 0;
} }
@@ -674,7 +674,7 @@ static struct ast_channel *modem_request(char *type, int format, void *data)
strtok(dev, ":"); strtok(dev, ":");
oldformat = format; oldformat = format;
/* 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;
} }
@@ -697,7 +697,7 @@ static struct ast_channel *modem_request(char *type, int format, void *data)
if (!p) if (!p)
ast_log(LOG_WARNING, "Requested device '%s' does not exist\n", p->dev); ast_log(LOG_WARNING, "Requested device '%s' does not exist\n", p->dev);
pthread_mutex_unlock(&iflock); ast_pthread_mutex_unlock(&iflock);
return tmp; return tmp;
} }
@@ -714,7 +714,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;
@@ -731,9 +731,9 @@ 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();
pthread_mutex_unlock(&iflock); ast_pthread_mutex_unlock(&iflock);
return -1; return -1;
} }
} else if (!strcasecmp(v->name, "driver")) { } else if (!strcasecmp(v->name, "driver")) {
@@ -744,7 +744,7 @@ int load_module()
if (ast_load_resource(driver)) { if (ast_load_resource(driver)) {
ast_log(LOG_ERROR, "Failed to load driver %s\n", driver); ast_log(LOG_ERROR, "Failed to load driver %s\n", driver);
ast_destroy(cfg); ast_destroy(cfg);
pthread_mutex_unlock(&iflock); ast_pthread_mutex_unlock(&iflock);
unload_module(); unload_module();
return -1; return -1;
} }
@@ -774,7 +774,7 @@ int load_module()
} }
v = v->next; v = v->next;
} }
pthread_mutex_unlock(&iflock); ast_pthread_mutex_unlock(&iflock);
if (ast_channel_register(type, tdesc, /* XXX Don't know our types -- maybe we should register more than one XXX */ if (ast_channel_register(type, tdesc, /* XXX Don't know our types -- maybe we should register more than one XXX */
AST_FORMAT_SLINEAR, modem_request)) { AST_FORMAT_SLINEAR, modem_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);
@@ -793,7 +793,7 @@ int unload_module()
struct ast_modem_pvt *p, *pl; struct ast_modem_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) {
@@ -802,24 +802,24 @@ 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 > -1) { if (monitor_thread > -1) {
pthread_cancel(monitor_thread); pthread_cancel(monitor_thread);
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) {
@@ -832,7 +832,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;
@@ -844,9 +844,9 @@ int unload_module()
int usecount(void) int usecount(void)
{ {
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;
} }