[asterisk-dev] Feedback / handoff request for AGI "BACKGROUND"
command...
Josh McAllister
josh at singletouch.net
Thu Jul 20 16:15:40 MST 2006
Out of immediate neccessity I hacked together a new AGI command to
stream a file in the background (exec Background doesn't seem to work...
Does not return immediately). This has been briefly tested, and it does
indeed work. Usage:
BACKGROUND [file]
Yes, file is optional. Calling BACKGROUND with no parameters invokes
ast_stopstream which cuts off the stream, and makes us ready to stream
something else. You CAN NOT stream anything else until you've called
BACKGROUND with no params, or bad things may happen.
One feature I started to plan for, but didn't finish is for BACKGROUND
by itself to return the offset (endpos) of the backgrounded stream where
it was stopped.
Unfortunately my C skills are a bit lacking, I have very little time,
and this works for me as is, so I probably won't take it any further at
this time... But would love it if someone else could pick up on it.
Also, if anyone sees anything nasty, please let me know.
Thanks,
Josh McAllister
----
static int handle_background(struct ast_channel *chan, AGI *agi, int
argc, char *argv[])
{
int res;
struct ast_filestream *fs;
long sample_offset = 0;
long max_length;
ast_verbose(VERBOSE_PREFIX_3 "AGI Background (%s) (%s) (%s)\n",
argv[0], argv[1], argv[2]);
if (argc < 2) {
//res = ast_waitstream(chan, argv[3], agi->audio,
agi->ctrl);
//sample_offset = (chan->stream) ? ast_tellstream(fs) :
max_length;
ast_stopstream(chan);
fdprintf(agi->fd, "200 result=%d endpos=%ld\n", 200,
-1);
return RESULT_SUCCESS;
}
if (argc > 3)
return RESULT_SHOWUSAGE;
if ((argc > 2) && (sscanf(argv[2], "%ld", &sample_offset) != 1))
return RESULT_SHOWUSAGE;
ast_stopstream(chan);
fs = ast_openstream(chan, argv[1], chan->language);
if (!fs){
fdprintf(agi->fd, "200 result=%d endpos=%ld\n", 0,
sample_offset);
return RESULT_SUCCESS;
}
ast_seekstream(fs, 0, SEEK_END);
max_length = ast_tellstream(fs);
ast_seekstream(fs, sample_offset, SEEK_SET);
res = ast_applystream(chan, fs);
res = ast_playstream(fs);
if (res) {
fdprintf(agi->fd, "200 result=%d endpos=%ld\n", res,
sample_offset);
if (res >= 0)
return RESULT_SHOWUSAGE;
else
return RESULT_FAILURE;
}
fdprintf(agi->fd, "200 result=%d endpos=%ld\n", res,
sample_offset);
return RESULT_SUCCESS;
}
More information about the asterisk-dev
mailing list