diff options
Diffstat (limited to 'main/file.c')
-rw-r--r-- | main/file.c | 44 |
1 files changed, 37 insertions, 7 deletions
diff --git a/main/file.c b/main/file.c index 52f5af58d..076b31dd7 100644 --- a/main/file.c +++ b/main/file.c @@ -1237,11 +1237,18 @@ struct ast_filestream *ast_writefile(const char *filename, const char *type, con /*! * \brief the core of all waitstream() functions */ -static int waitstream_core(struct ast_channel *c, const char *breakon, - const char *forward, const char *reverse, int skip_ms, - int audiofd, int cmdfd, const char *context) +static int waitstream_core(struct ast_channel *c, + const char *breakon, + const char *forward, + const char *reverse, + int skip_ms, + int audiofd, + int cmdfd, + const char *context, + ast_waitstream_fr_cb cb) { const char *orig_chan_name = NULL; + int err = 0; if (!breakon) @@ -1257,6 +1264,11 @@ static int waitstream_core(struct ast_channel *c, const char *breakon, if (ast_test_flag(ast_channel_flags(c), AST_FLAG_MASQ_NOSTREAM)) orig_chan_name = ast_strdupa(ast_channel_name(c)); + if (ast_channel_stream(c) && cb) { + long ms_len = ast_tellstream(ast_channel_stream(c)) / (ast_format_rate(&ast_channel_stream(c)->fmt->format) / 1000); + cb(c, ms_len, AST_WAITSTREAM_CB_START); + } + while (ast_channel_stream(c)) { int res; int ms; @@ -1318,6 +1330,7 @@ static int waitstream_core(struct ast_channel *c, const char *breakon, return res; } } else { + enum ast_waitstream_fr_cb_values cb_val = 0; res = fr->subclass.integer; if (strchr(forward, res)) { int eoftest; @@ -1328,13 +1341,19 @@ static int waitstream_core(struct ast_channel *c, const char *breakon, } else { ungetc(eoftest, ast_channel_stream(c)->f); } + cb_val = AST_WAITSTREAM_CB_FASTFORWARD; } else if (strchr(reverse, res)) { ast_stream_rewind(ast_channel_stream(c), skip_ms); + cb_val = AST_WAITSTREAM_CB_REWIND; } else if (strchr(breakon, res)) { ast_frfree(fr); ast_clear_flag(ast_channel_flags(c), AST_FLAG_END_DTMF_ONLY); return res; } + if (cb_val && cb) { + long ms_len = ast_tellstream(ast_channel_stream(c)) / (ast_format_rate(&ast_channel_stream(c)->fmt->format) / 1000); + cb(c, ms_len, cb_val); + } } break; case AST_FRAME_CONTROL: @@ -1385,21 +1404,32 @@ static int waitstream_core(struct ast_channel *c, const char *breakon, return (err || ast_channel_softhangup_internal_flag(c)) ? -1 : 0; } +int ast_waitstream_fr_w_cb(struct ast_channel *c, + const char *breakon, + const char *forward, + const char *reverse, + int ms, + ast_waitstream_fr_cb cb) +{ + return waitstream_core(c, breakon, forward, reverse, ms, + -1 /* no audiofd */, -1 /* no cmdfd */, NULL /* no context */, cb); +} + int ast_waitstream_fr(struct ast_channel *c, const char *breakon, const char *forward, const char *reverse, int ms) { return waitstream_core(c, breakon, forward, reverse, ms, - -1 /* no audiofd */, -1 /* no cmdfd */, NULL /* no context */); + -1 /* no audiofd */, -1 /* no cmdfd */, NULL /* no context */, NULL /* no callback */); } int ast_waitstream(struct ast_channel *c, const char *breakon) { - return waitstream_core(c, breakon, NULL, NULL, 0, -1, -1, NULL); + return waitstream_core(c, breakon, NULL, NULL, 0, -1, -1, NULL, NULL /* no callback */); } int ast_waitstream_full(struct ast_channel *c, const char *breakon, int audiofd, int cmdfd) { return waitstream_core(c, breakon, NULL, NULL, 0, - audiofd, cmdfd, NULL /* no context */); + audiofd, cmdfd, NULL /* no context */, NULL /* no callback */); } int ast_waitstream_exten(struct ast_channel *c, const char *context) @@ -1410,7 +1440,7 @@ int ast_waitstream_exten(struct ast_channel *c, const char *context) if (!context) context = ast_channel_context(c); return waitstream_core(c, NULL, NULL, NULL, 0, - -1, -1, context); + -1, -1, context, NULL /* no callback */); } /* |