mirror of
https://github.com/asterisk/asterisk.git
synced 2025-09-18 18:58:22 +00:00
#6991. Take 3. (casper)
git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@24775 65c4cc65-6c06-0410-ace0-fbb531ad65f3
This commit is contained in:
42
app.c
42
app.c
@@ -540,14 +540,14 @@ static int __ast_play_and_record(struct ast_channel *chan, const char *playfile,
|
|||||||
int d = 0;
|
int d = 0;
|
||||||
char *fmts;
|
char *fmts;
|
||||||
char comment[256];
|
char comment[256];
|
||||||
int x, fmtcnt=1, res=-1,outmsg=0;
|
int x, fmtcnt = 1, res = -1, outmsg = 0;
|
||||||
struct ast_filestream *others[MAX_OTHER_FORMATS];
|
struct ast_filestream *others[MAX_OTHER_FORMATS];
|
||||||
char *sfmt[MAX_OTHER_FORMATS];
|
char *sfmt[MAX_OTHER_FORMATS];
|
||||||
char *stringp=NULL;
|
char *stringp = NULL;
|
||||||
time_t start, end;
|
time_t start, end;
|
||||||
struct ast_dsp *sildet=NULL; /* silence detector dsp */
|
struct ast_dsp *sildet = NULL; /* silence detector dsp */
|
||||||
int totalsilence = 0;
|
int totalsilence = 0;
|
||||||
int rfmt=0;
|
int rfmt = 0;
|
||||||
struct ast_silence_generator *silgen = NULL;
|
struct ast_silence_generator *silgen = NULL;
|
||||||
char prependfile[80];
|
char prependfile[80];
|
||||||
|
|
||||||
@@ -564,7 +564,7 @@ static int __ast_play_and_record(struct ast_channel *chan, const char *playfile,
|
|||||||
}
|
}
|
||||||
|
|
||||||
ast_log(LOG_DEBUG,"play_and_record: %s, %s, '%s'\n", playfile ? playfile : "<None>", recordfile, fmt);
|
ast_log(LOG_DEBUG,"play_and_record: %s, %s, '%s'\n", playfile ? playfile : "<None>", recordfile, fmt);
|
||||||
snprintf(comment,sizeof(comment),"Playing %s, Recording to: %s on %s\n", playfile ? playfile : "<None>", recordfile, chan->name);
|
snprintf(comment, sizeof(comment), "Playing %s, Recording to: %s on %s\n", playfile ? playfile : "<None>", recordfile, chan->name);
|
||||||
|
|
||||||
if (playfile || beep) {
|
if (playfile || beep) {
|
||||||
if (!beep)
|
if (!beep)
|
||||||
@@ -582,7 +582,7 @@ static int __ast_play_and_record(struct ast_channel *chan, const char *playfile,
|
|||||||
|
|
||||||
fmts = ast_strdupa(fmt);
|
fmts = ast_strdupa(fmt);
|
||||||
|
|
||||||
stringp=fmts;
|
stringp = fmts;
|
||||||
strsep(&stringp, "|");
|
strsep(&stringp, "|");
|
||||||
ast_log(LOG_DEBUG,"Recording Formats: sfmts=%s\n", fmts);
|
ast_log(LOG_DEBUG,"Recording Formats: sfmts=%s\n", fmts);
|
||||||
sfmt[0] = ast_strdupa(fmts);
|
sfmt[0] = ast_strdupa(fmts);
|
||||||
@@ -596,8 +596,8 @@ static int __ast_play_and_record(struct ast_channel *chan, const char *playfile,
|
|||||||
}
|
}
|
||||||
|
|
||||||
time(&start);
|
time(&start);
|
||||||
end=start; /* pre-initialize end to be same as start in case we never get into loop */
|
end = start; /* pre-initialize end to be same as start in case we never get into loop */
|
||||||
for (x=0;x<fmtcnt;x++) {
|
for (x = 0; x < fmtcnt; x++) {
|
||||||
others[x] = ast_writefile(prepend ? prependfile : recordfile, sfmt[x], comment, O_TRUNC, 0, 0700);
|
others[x] = ast_writefile(prepend ? prependfile : recordfile, sfmt[x], comment, O_TRUNC, 0, 0700);
|
||||||
if (option_verbose > 2)
|
if (option_verbose > 2)
|
||||||
ast_verbose(VERBOSE_PREFIX_3 "x=%d, open writing: %s format: %s, %p\n", x, prepend ? prependfile : recordfile, sfmt[x], others[x]);
|
ast_verbose(VERBOSE_PREFIX_3 "x=%d, open writing: %s format: %s, %p\n", x, prepend ? prependfile : recordfile, sfmt[x], others[x]);
|
||||||
@@ -638,7 +638,7 @@ static int __ast_play_and_record(struct ast_channel *chan, const char *playfile,
|
|||||||
/* Loop forever, writing the packets we read to the writer(s), until
|
/* Loop forever, writing the packets we read to the writer(s), until
|
||||||
we read a digit or get a hangup */
|
we read a digit or get a hangup */
|
||||||
struct ast_frame *f;
|
struct ast_frame *f;
|
||||||
for(;;) {
|
for (;;) {
|
||||||
res = ast_waitfor(chan, 2000);
|
res = ast_waitfor(chan, 2000);
|
||||||
if (!res) {
|
if (!res) {
|
||||||
ast_log(LOG_DEBUG, "One waitfor failed, trying another\n");
|
ast_log(LOG_DEBUG, "One waitfor failed, trying another\n");
|
||||||
@@ -659,7 +659,7 @@ static int __ast_play_and_record(struct ast_channel *chan, const char *playfile,
|
|||||||
break;
|
break;
|
||||||
if (f->frametype == AST_FRAME_VOICE) {
|
if (f->frametype == AST_FRAME_VOICE) {
|
||||||
/* write each format */
|
/* write each format */
|
||||||
for (x=0;x<fmtcnt;x++) {
|
for (x = 0; x < fmtcnt; x++) {
|
||||||
if (prepend && !others[x])
|
if (prepend && !others[x])
|
||||||
break;
|
break;
|
||||||
res = ast_writestream(others[x], f);
|
res = ast_writestream(others[x], f);
|
||||||
@@ -679,7 +679,7 @@ static int __ast_play_and_record(struct ast_channel *chan, const char *playfile,
|
|||||||
if (option_verbose > 2)
|
if (option_verbose > 2)
|
||||||
ast_verbose( VERBOSE_PREFIX_3 "Recording automatically stopped after a silence of %d seconds\n", totalsilence/1000);
|
ast_verbose( VERBOSE_PREFIX_3 "Recording automatically stopped after a silence of %d seconds\n", totalsilence/1000);
|
||||||
res = 'S';
|
res = 'S';
|
||||||
outmsg=2;
|
outmsg = 2;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -702,7 +702,7 @@ static int __ast_play_and_record(struct ast_channel *chan, const char *playfile,
|
|||||||
}
|
}
|
||||||
if (f->subclass == '#') {
|
if (f->subclass == '#') {
|
||||||
if (option_verbose > 2)
|
if (option_verbose > 2)
|
||||||
ast_verbose( VERBOSE_PREFIX_3 "User ended message by pressing %c\n", f->subclass);
|
ast_verbose(VERBOSE_PREFIX_3 "User ended message by pressing %c\n", f->subclass);
|
||||||
res = '#';
|
res = '#';
|
||||||
outmsg = 2;
|
outmsg = 2;
|
||||||
break;
|
break;
|
||||||
@@ -720,7 +720,7 @@ static int __ast_play_and_record(struct ast_channel *chan, const char *playfile,
|
|||||||
time(&end);
|
time(&end);
|
||||||
if (maxtime < (end - start)) {
|
if (maxtime < (end - start)) {
|
||||||
if (option_verbose > 2)
|
if (option_verbose > 2)
|
||||||
ast_verbose( VERBOSE_PREFIX_3 "Took too long, cutting it short...\n");
|
ast_verbose(VERBOSE_PREFIX_3 "Took too long, cutting it short...\n");
|
||||||
res = 't';
|
res = 't';
|
||||||
outmsg = 2;
|
outmsg = 2;
|
||||||
break;
|
break;
|
||||||
@@ -730,9 +730,9 @@ static int __ast_play_and_record(struct ast_channel *chan, const char *playfile,
|
|||||||
}
|
}
|
||||||
if (!f) {
|
if (!f) {
|
||||||
if (option_verbose > 2)
|
if (option_verbose > 2)
|
||||||
ast_verbose( VERBOSE_PREFIX_3 "User hung up\n");
|
ast_verbose(VERBOSE_PREFIX_3 "User hung up\n");
|
||||||
res = -1;
|
res = -1;
|
||||||
outmsg=1;
|
outmsg = 1;
|
||||||
} else {
|
} else {
|
||||||
ast_frfree(f);
|
ast_frfree(f);
|
||||||
}
|
}
|
||||||
@@ -740,13 +740,15 @@ static int __ast_play_and_record(struct ast_channel *chan, const char *playfile,
|
|||||||
} else {
|
} else {
|
||||||
ast_log(LOG_WARNING, "Error creating writestream '%s', format '%s'\n", recordfile, sfmt[x]);
|
ast_log(LOG_WARNING, "Error creating writestream '%s', format '%s'\n", recordfile, sfmt[x]);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!prepend) {
|
if (!prepend) {
|
||||||
if (silgen)
|
if (silgen)
|
||||||
ast_channel_stop_silence_generator(chan, silgen);
|
ast_channel_stop_silence_generator(chan, silgen);
|
||||||
}
|
}
|
||||||
*duration = end - start;
|
*duration = end - start;
|
||||||
|
|
||||||
if (!prepend) {
|
if (!prepend) {
|
||||||
for (x=0;x<fmtcnt;x++) {
|
for (x = 0; x < fmtcnt; x++) {
|
||||||
if (!others[x])
|
if (!others[x])
|
||||||
break;
|
break;
|
||||||
if (res > 0)
|
if (res > 0)
|
||||||
@@ -755,10 +757,12 @@ static int __ast_play_and_record(struct ast_channel *chan, const char *playfile,
|
|||||||
ast_closestream(others[x]);
|
ast_closestream(others[x]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (prepend && outmsg) {
|
if (prepend && outmsg) {
|
||||||
struct ast_filestream *realfiles[MAX_OTHER_FORMATS];
|
struct ast_filestream *realfiles[MAX_OTHER_FORMATS];
|
||||||
struct ast_frame *fr;
|
struct ast_frame *fr;
|
||||||
for (x=0;x<fmtcnt;x++) {
|
|
||||||
|
for (x = 0; x < fmtcnt; x++) {
|
||||||
snprintf(comment, sizeof(comment), "Opening the real file %s.%s\n", recordfile, sfmt[x]);
|
snprintf(comment, sizeof(comment), "Opening the real file %s.%s\n", recordfile, sfmt[x]);
|
||||||
realfiles[x] = ast_readfile(recordfile, sfmt[x], comment, O_RDONLY, 0, 0);
|
realfiles[x] = ast_readfile(recordfile, sfmt[x], comment, O_RDONLY, 0, 0);
|
||||||
if (!others[x] || !realfiles[x])
|
if (!others[x] || !realfiles[x])
|
||||||
@@ -767,7 +771,7 @@ static int __ast_play_and_record(struct ast_channel *chan, const char *playfile,
|
|||||||
ast_truncstream(others[x]);
|
ast_truncstream(others[x]);
|
||||||
/* add the original file too */
|
/* add the original file too */
|
||||||
while ((fr = ast_readframe(realfiles[x]))) {
|
while ((fr = ast_readframe(realfiles[x]))) {
|
||||||
ast_writestream(others[x],fr);
|
ast_writestream(others[x], fr);
|
||||||
ast_frfree(fr);
|
ast_frfree(fr);
|
||||||
}
|
}
|
||||||
ast_closestream(others[x]);
|
ast_closestream(others[x]);
|
||||||
@@ -783,7 +787,7 @@ static int __ast_play_and_record(struct ast_channel *chan, const char *playfile,
|
|||||||
}
|
}
|
||||||
if (outmsg == 2) {
|
if (outmsg == 2) {
|
||||||
ast_stream_and_wait(chan, "auth-thankyou", chan->language, "");
|
ast_stream_and_wait(chan, "auth-thankyou", chan->language, "");
|
||||||
}
|
}
|
||||||
if (sildet)
|
if (sildet)
|
||||||
ast_dsp_free(sildet);
|
ast_dsp_free(sildet);
|
||||||
return res;
|
return res;
|
||||||
|
Reference in New Issue
Block a user