diff options
author | Russell Bryant <russell@russellbryant.com> | 2007-06-08 21:02:46 +0000 |
---|---|---|
committer | Russell Bryant <russell@russellbryant.com> | 2007-06-08 21:02:46 +0000 |
commit | 68492b239c6a309d0339f02dc82a77e3ec5c9c4b (patch) | |
tree | 9980f4b3704ece77e3b9166bc57e0a5e33c971c6 /main/app.c | |
parent | 334d8d9dc484f1a52d19bd530a6c4d0f98246b5c (diff) |
Add an option for ControlPlayback to be able to start at an offset from
the beginning of the file. Also, add a channel variable that indicates
the location in the file where the Playback was stopped.
(closes issue #7655, patch from sharkey)
git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@68502 65c4cc65-6c06-0410-ace0-fbb531ad65f3
Diffstat (limited to 'main/app.c')
-rw-r--r-- | main/app.c | 32 |
1 files changed, 29 insertions, 3 deletions
diff --git a/main/app.c b/main/app.c index b3fd264f1..22a29218e 100644 --- a/main/app.c +++ b/main/app.c @@ -395,13 +395,17 @@ int ast_linear_stream(struct ast_channel *chan, const char *filename, int fd, in int ast_control_streamfile(struct ast_channel *chan, const char *file, const char *fwd, const char *rev, const char *stop, const char *pause, - const char *restart, int skipms) + const char *restart, int skipms, long *offsetms) { char *breaks = NULL; char *end = NULL; int blen = 2; int res; long pause_restart_point = 0; + long offset = 0; + + if (offsetms) + offset = *offsetms * 8; /* XXX Assumes 8kHz */ if (stop) blen += strlen(stop); @@ -440,9 +444,18 @@ int ast_control_streamfile(struct ast_channel *chan, const char *file, ast_seekstream(chan->stream, pause_restart_point, SEEK_SET); pause_restart_point = 0; } - else if (end) { - ast_seekstream(chan->stream, 0, SEEK_END); + else if (end || offset < 0) { + if (offset == -8) + offset = 0; + ast_verbose(VERBOSE_PREFIX_3 "ControlPlayback seek to offset %ld from end\n", offset); + + ast_seekstream(chan->stream, offset, SEEK_END); end = NULL; + offset = 0; + } else if (offset) { + ast_verbose(VERBOSE_PREFIX_3 "ControlPlayback seek to offset %ld\n", offset); + ast_seekstream(chan->stream, offset, SEEK_SET); + offset = 0; }; res = ast_waitstream_fr(chan, breaks, fwd, rev, skipms); } @@ -482,6 +495,19 @@ int ast_control_streamfile(struct ast_channel *chan, const char *file, break; } + if (pause_restart_point) { + offset = pause_restart_point; + } else { + if (chan->stream) { + offset = ast_tellstream(chan->stream); + } else { + offset = -8; /* indicate end of file */ + } + } + + if (offsetms) + *offsetms = offset / 8; /* samples --> ms ... XXX Assumes 8 kHz */ + ast_stopstream(chan); return res; |