]> git.ipfire.org Git - thirdparty/asterisk.git/commitdiff
Allow playback of formats that don't support seeking
authorKinsey Moore <kmoore@digium.com>
Thu, 5 Jan 2012 22:06:46 +0000 (22:06 +0000)
committerKinsey Moore <kmoore@digium.com>
Thu, 5 Jan 2012 22:06:46 +0000 (22:06 +0000)
ast_streamfile previously did unconditional seeking on files that broke
playback of formats that don't support that functionality.  This patch avoids
the seek that was causing the problem.  This regression was introduced in
r158062.

(closes issue ASTERISK-18994)
Patch-by: Timo Teras
git-svn-id: https://origsvn.digium.com/svn/asterisk/branches/1.8@349731 65c4cc65-6c06-0410-ace0-fbb531ad65f3

main/file.c

index d432bdc755b9e115bb221a217064515fd36fde8d..18ef8ca944b990141c61303190b9d8c604e63a30 100644 (file)
@@ -949,6 +949,7 @@ int ast_streamfile(struct ast_channel *chan, const char *filename, const char *p
        struct ast_filestream *fs;
        struct ast_filestream *vfs=NULL;
        char fmt[256];
+       off_t pos;
        int seekattempt;
        int res;
 
@@ -961,12 +962,17 @@ int ast_streamfile(struct ast_channel *chan, const char *filename, const char *p
        /* check to see if there is any data present (not a zero length file),
         * done this way because there is no where for ast_openstream_full to
         * return the file had no data. */
-       seekattempt = fseek(fs->f, -1, SEEK_END);
-       if (seekattempt && errno == EINVAL) {
-               /* Zero-length file, as opposed to a pipe */
-               return 0;
+       pos = ftello(fs->f);
+       seekattempt = fseeko(fs->f, -1, SEEK_END);
+       if (seekattempt) {
+               if (errno == EINVAL) {
+                       /* Zero-length file, as opposed to a pipe */
+                       return 0;
+               } else {
+                       ast_seekstream(fs, 0, SEEK_SET);
+               }
        } else {
-               ast_seekstream(fs, 0, SEEK_SET);
+               fseeko(fs->f, pos, SEEK_SET);
        }
 
        vfs = ast_openvstream(chan, filename, preflang);