[asterisk-commits] oej: branch oej/pinequeue-trunk r367560 - in /team/oej/pinequeue-trunk: apps/...
SVN commits to the Asterisk project
asterisk-commits at lists.digium.com
Thu May 24 07:10:24 CDT 2012
Author: oej
Date: Thu May 24 07:10:18 2012
New Revision: 367560
URL: http://svnview.digium.com/svn/asterisk?view=rev&rev=367560
Log:
Fixing small fixes from Mark's review in reviewboard. Larger restructuring is saved for "general overhaul" later.
Modified:
team/oej/pinequeue-trunk/apps/app_queue.c
team/oej/pinequeue-trunk/include/asterisk/channel.h
team/oej/pinequeue-trunk/main/say.c
Modified: team/oej/pinequeue-trunk/apps/app_queue.c
URL: http://svnview.digium.com/svn/asterisk/team/oej/pinequeue-trunk/apps/app_queue.c?view=diff&rev=367560&r1=367559&r2=367560
==============================================================================
--- team/oej/pinequeue-trunk/apps/app_queue.c (original)
+++ team/oej/pinequeue-trunk/apps/app_queue.c Thu May 24 07:10:18 2012
@@ -2791,7 +2791,7 @@
/* We have an exact match */
if (!ast_goto_if_exists(qe->chan, qe->context, qe->digits, 1)) {
- qe->valid_digits = 1; /* there it is, the only indication */
+ qe->valid_digits = 1;
/* Return 1 on a successful goto */
return 1;
}
@@ -4944,10 +4944,6 @@
res2 = ast_autoservice_start(qe->chan);
- /* instead of starting autoservice and jacking this thread to push sound to the
- peer channel, let's set up a background player to the peer channel and
- get on with life in this thread. */
-
if (qe->parent->memberdelay) {
ast_log(LOG_NOTICE, "Delaying member connect for %d seconds\n", qe->parent->memberdelay);
res2 |= ast_safe_sleep(peer, qe->parent->memberdelay * 1000);
@@ -4956,9 +4952,7 @@
play_file(peer, announce, ringing, qe->moh);;
}
if (!res2 && qe->parent->reportholdtime) {
- int res3;
- res3 = play_file(peer, qe->parent->sound_reporthold, ringing, qe->moh);
- if (!res3) {
+ if(!play_file(peer, qe->parent->sound_reporthold, ringing, qe->moh)) {
int holdtime, holdtimesecs;
time(&now);
@@ -6177,7 +6171,7 @@
struct ast_channel *chan;
struct ast_filestream *stream;
int sample_queue;
- char filename[512];
+ char filename[PATH_MAX];
struct ast_queue_streamfile_info *aqsi;
};
@@ -6314,7 +6308,7 @@
struct ast_queue_streamfile_info *aqsi = NULL;
struct gen_state *generatordata;
struct ast_queue_streamfile_name *sfn = NULL;
- char playfilename[512];
+ char playfilename[PATH_MAX];
if (!background_prompts) {
if (ast_strlen_zero(filename)) {
@@ -6337,6 +6331,7 @@
}
/* look up the datastore and the play_finished struct, and set appropriate values */
+ ast_channel_lock(chan);
if ((datastore = ast_channel_datastore_find(chan, ast_prompt_list(), NULL))) {
aqsi = datastore->data;
if (aqsi) { /* copy this stuff into place */
@@ -6347,8 +6342,10 @@
}
} else {
ast_log(LOG_ERROR, "Can't find the ast_prompt_list datastore! on chan %s\n", ast_channel_name(chan));
+ ast_channel_unlock(chan);
return 1; /* Why continue, if I can't access the datastore & list? */
}
+ ast_channel_unlock(chan);
ast_debug(2, "---- Background prompts now playing: %d\n", aqsi->now_playing);
if (aqsi->now_playing == 0) {
@@ -6358,9 +6355,7 @@
if (!AST_LIST_EMPTY(&aqsi->flist)) {
sfn = AST_LIST_REMOVE_HEAD(&aqsi->flist, list);
ast_copy_string(playfilename, sfn->filename, sizeof(playfilename));
- ringing = aqsi->ringing;
- moh = aqsi->moh;
- free(sfn);
+ ast_free(sfn);
}
if (ast_strlen_zero(playfilename)) {
if (ringing) {
@@ -6380,12 +6375,23 @@
return 0;
}
}
+ /* If the filename doesn't exist, do not queue it up */
+ if (!ast_fileexists(filename, NULL, chan->language)) {
+ ast_log(LOG_ERROR, "Filename %s does not exist, not queued for playing out on chan %s\n", filename, ast_channel_name(chan));
+ return 0;
+ }
++
+
AST_LIST_LOCK(&aqsi->flist);
if (aqsi->now_playing) {
struct ast_queue_streamfile_name *fn = ast_calloc(1, sizeof(*fn));
fn->filename = ast_strdup(filename);
+ if (!fn || !fn->filename) {
+ AST_LIST_UNLOCK(&aqsi->flist);
+ return 1;
+ }
ast_debug(3, "Background prompts: queued sound file %s for playing on chan %s\n", filename, ast_channel_name(chan));
/* link the struct into the current ast_queue_streamfile_info struct */
@@ -6401,12 +6407,11 @@
ast_moh_stop(chan);
}
ast_stopstream(chan);
- ast_autoservice_stop(chan);
/* Create generator to start playing audio without waiting */
generatordata = ast_calloc(1, sizeof(struct gen_state));
if (!generatordata) {
- ast_log(LOG_ERROR, "Can't allocate generator input\n");
+ AST_LIST_UNLOCK(&aqsi->flist);
return 1;
}
ast_copy_string(generatordata->filename, playfilename, sizeof(generatordata->filename));
@@ -6416,7 +6421,6 @@
/* Starting new generator on channel. */
if (ast_activate_generator(chan, &play_file_gen, generatordata)) {
ast_log(LOG_ERROR, "Not playing requested prompt %s. Generator failed on %s.\n", playfilename, ast_channel_name(chan));
- /* oops, the current file has problems */
/* restore the moh */
if (ringing) {
ast_indicate(chan, AST_CONTROL_RINGING);
@@ -6445,7 +6449,6 @@
while (!AST_LIST_EMPTY(&playdata->flist)) {
fn = AST_LIST_REMOVE_HEAD(&playdata->flist, list);
ast_free(fn->filename);
-
ast_free(fn);
}
AST_LIST_UNLOCK(&playdata->flist);
@@ -6476,8 +6479,8 @@
int qcontinue = 0;
int max_penalty, min_penalty;
enum queue_result reason = QUEUE_UNKNOWN;
- struct ast_datastore *datastore;
- struct ast_queue_streamfile_info *aqsi;
+ struct ast_datastore *datastore = NULL;
+ struct ast_queue_streamfile_info *aqsi = NULL;
/* whether to exit Queue application after the timeout hits */
int tries = 0;
@@ -6609,22 +6612,24 @@
S_COR(ast_channel_caller(chan)->id.number.valid, ast_channel_caller(chan)->id.number.str, ""),
qe.opos);
if (background_prompts) {
- aqsi = calloc(1,sizeof(struct ast_queue_streamfile_info));
- datastore = NULL;
+ aqsi = ast_calloc(1, sizeof(struct ast_queue_streamfile_info));
/* Set up the channel datastore for the playlist of prompts
that we're going to play in the background while the call
is in the queue.
*/
datastore = ast_datastore_alloc(ast_prompt_list(), NULL);
- aqsi->qe = &qe;
- aqsi->chan = chan;
- aqsi->ringing = ringing;
- aqsi->now_playing = 0;
- strcpy(aqsi->moh, qe.moh);
- AST_LIST_HEAD_INIT(&aqsi->flist);
- datastore->data = aqsi;
- ast_channel_datastore_add(chan, datastore);
+ if (datastore && aqsi) {
+ /* Allocation succeeded */
+ aqsi->qe = &qe;
+ aqsi->chan = chan;
+ aqsi->ringing = ringing;
+ aqsi->now_playing = 0;
+ ast_copy_string(aqsi->moh, qe.moh, sizeof(aqsi->moh));
+ AST_LIST_HEAD_INIT(&aqsi->flist);
+ datastore->data = aqsi;
+ ast_channel_datastore_add(chan, datastore);
+ }
}
copy_rules(&qe, args.rule);
@@ -6661,7 +6666,7 @@
}
if (background_prompts) {
- play_file(qe.chan, NULL, ringing, qe.moh); /* OEJ - Trigger next prompt */
+ play_file(qe.chan, NULL, ringing, qe.moh); /* Trigger next prompt */
}
if (makeannouncement) {
/* Make a position announcement, if enabled */
Modified: team/oej/pinequeue-trunk/include/asterisk/channel.h
URL: http://svnview.digium.com/svn/asterisk/team/oej/pinequeue-trunk/include/asterisk/channel.h?view=diff&rev=367560&r1=367559&r2=367560
==============================================================================
--- team/oej/pinequeue-trunk/include/asterisk/channel.h (original)
+++ team/oej/pinequeue-trunk/include/asterisk/channel.h Thu May 24 07:10:18 2012
@@ -3524,14 +3524,14 @@
/*! \brief Information data about background playing of prompts */
struct ast_queue_streamfile_info {
- void (*digitHandler)(void *data, char digit); /* a func ptr to the handler that will do what needs doing when the streaming of a soundfile is finished */
+ void (*digitHandler)(void *data, char digit); /*!< a func ptr to the handler that will do what needs doing when the streaming of a soundfile is finished */
struct queue_ent *qe;
- AST_LIST_HEAD(,ast_queue_streamfile_name) flist; /* a list of other sound files that need to be played in sequence */
- struct ast_channel *chan;
- int ringing;
- char moh[80];
- int now_playing;
- int valid_exit; /* if valid_exit() in app_queue is true */
+ AST_LIST_HEAD(,ast_queue_streamfile_name) flist; /*!< a list of other sound files that need to be played in sequence */
+ struct ast_channel *chan; /*!< The channel we operate on */
+ int ringing; /*!< Queues: If we play ringing instead of music on hold in this queue */
+ char moh[80]; /*!< Musiconhold for this channel */
+ int now_playing; /*!< Set when we have a playlist and are streaming audio from it */
+ int valid_exit; /*!< if valid_exit() in app_queue is true */
};
Modified: team/oej/pinequeue-trunk/main/say.c
URL: http://svnview.digium.com/svn/asterisk/team/oej/pinequeue-trunk/main/say.c?view=diff&rev=367560&r1=367559&r2=367560
==============================================================================
--- team/oej/pinequeue-trunk/main/say.c (original)
+++ team/oej/pinequeue-trunk/main/say.c Thu May 24 07:10:18 2012
@@ -419,51 +419,51 @@
if ((datastore = ast_channel_datastore_find(chan, ast_prompt_list(), NULL))) {
/* app_queue wants to schedule this instead of play & wait */
struct ast_queue_streamfile_info *aqsi = datastore->data;
- if (aqsi) {
- AST_LIST_LOCK(&aqsi->flist);
- if (aqsi->now_playing) {
- struct ast_queue_streamfile_name *fn = ast_calloc(1, sizeof(*fn));
-
- fn->filename = ast_strdup(file);
- ast_debug(3, "----> Adding file %s to playlist for %s\n", file, ast_channel_name(chan));
-
- /* link the struct into the current ast_queue_streamfile_info struct */
- AST_LIST_INSERT_TAIL(&aqsi->flist, fn, list);
+ if (!aqsi) {
+ return 0;
+ }
+ AST_LIST_LOCK(&aqsi->flist);
+ if (aqsi->now_playing) {
+ struct ast_queue_streamfile_name *fn = ast_calloc(1, sizeof(*fn));
+
+ fn->filename = ast_strdup(file);
+ ast_debug(3, "----> Adding file %s to playlist for %s\n", file, ast_channel_name(chan));
+
+ /* link the struct into the current ast_queue_streamfile_info struct */
+ AST_LIST_INSERT_TAIL(&aqsi->flist, fn, list);
+ } else {
+ /* if not playing, then start playing this file */
+ if (aqsi->ringing) {
+ ast_indicate(aqsi->chan,-1);
} else {
- /* if not playing, then start playing this file */
+ ast_moh_stop(aqsi->chan);
+ }
+
+ ast_stopstream(aqsi->chan);
+ ast_autoservice_stop(aqsi->chan);
+ res = ast_streamfile(aqsi->chan, file, ast_channel_language(aqsi->chan)); /* begin the streaming */
+ while (res && !AST_LIST_EMPTY(&aqsi->flist)) {
+ struct ast_queue_streamfile_name *fn;
+ fn = AST_LIST_REMOVE_HEAD(&aqsi->flist, list);
+ ast_debug(3,"Start streaming file %s\n", fn->filename);
+ res = ast_streamfile(aqsi->chan, fn->filename, ast_channel_language(aqsi->chan));
+ }
+
+ if (res) {
+ /* oops, the current file has problems */
+ /* restore the moh */
if (aqsi->ringing) {
- ast_indicate(aqsi->chan,-1);
+ ast_indicate(aqsi->chan, AST_CONTROL_RINGING);
} else {
- ast_moh_stop(aqsi->chan);
- }
-
- ast_stopstream(aqsi->chan);
- ast_autoservice_stop(aqsi->chan);
- res = ast_streamfile(aqsi->chan, file, ast_channel_language(aqsi->chan)); /* begin the streaming */
- while (res && !AST_LIST_EMPTY(&aqsi->flist)) {
- struct ast_queue_streamfile_name *fn;
- fn = AST_LIST_REMOVE_HEAD(&aqsi->flist, list);
- ast_debug(3,"Start streaming file %s\n", fn->filename);
- res = ast_streamfile(aqsi->chan, fn->filename, ast_channel_language(aqsi->chan));
- }
-
- if (res) {
- /* oops, the current file has problems */
- /* restore the moh */
- if (aqsi->ringing) {
- ast_indicate(aqsi->chan, AST_CONTROL_RINGING);
- } else {
- ast_moh_start(aqsi->chan, aqsi->moh, NULL);
- }
- AST_LIST_UNLOCK(&aqsi->flist);
- return 1;
- }
- aqsi->now_playing = 1; /* We have begun playback */
- ast_autoservice_start(aqsi->chan); /* this will let the sound file play in a different thread */
- }
- AST_LIST_UNLOCK(&aqsi->flist);
- return 0;
- }
+ ast_moh_start(aqsi->chan, aqsi->moh, NULL);
+ }
+ AST_LIST_UNLOCK(&aqsi->flist);
+ return 1;
+ }
+ aqsi->now_playing = 1; /* We have begun playback */
+ ast_autoservice_start(aqsi->chan); /* this will let the sound file play in a different thread */
+ }
+ AST_LIST_UNLOCK(&aqsi->flist);
return 0;
}
/* otherwise, exactly business as usual */
More information about the asterisk-commits
mailing list