From 68492b239c6a309d0339f02dc82a77e3ec5c9c4b Mon Sep 17 00:00:00 2001 From: Russell Bryant Date: Fri, 8 Jun 2007 21:02:46 +0000 Subject: 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 --- main/app.c | 32 +++++++++++++++++++++++++++++--- 1 file changed, 29 insertions(+), 3 deletions(-) (limited to 'main') 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; -- cgit v1.2.3