$subject
>From 40591ddc0f25992fe1accbe0fc33afc2cd1cd1d1 Mon Sep 17 00:00:00 2001 From: Vladimir Pantelic <[email protected]> Date: Fri, 14 Mar 2014 15:25:19 +0100 Subject: [PATCH] http: allow to seek to the end of a file
Seeking to the end of the file is a valid operation but not supported by HTTP using bytes ranges. Therefore just remember the offset and return, the next http_read() will set EOF correctly. Signed-off-by: Vladimir Pantelic <[email protected]> --- libavformat/http.c | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) diff --git a/libavformat/http.c b/libavformat/http.c index 948930a..a31b24b 100644 --- a/libavformat/http.c +++ b/libavformat/http.c @@ -909,10 +909,13 @@ static int64_t http_seek(URLContext *h, int64_t off, int whence) int old_buf_size, ret; AVDictionary *options = NULL; - if (whence == AVSEEK_SIZE) + if (whence == AVSEEK_SIZE) { + if (s->filesize == -1) + return AVERROR(ENOSYS); return s->filesize; - else if ((whence == SEEK_CUR && off == 0) || - (whence == SEEK_SET && off == s->off)) + } + if ((whence == SEEK_CUR && off == 0) || + (whence == SEEK_SET && off == s->off)) return s->off; else if ((s->filesize == -1 && whence == SEEK_END) || h->is_streamed) return AVERROR(ENOSYS); @@ -927,6 +930,14 @@ static int64_t http_seek(URLContext *h, int64_t off, int whence) off += s->filesize; s->off = off; + if (s->filesize > 0) { + /* seeking to the actual filesize is valid, + * the next read will fail and set EOF */ + if (off == s->filesize) + return off; + if (off > s->filesize) + return AVERROR(EINVAL); + } /* if it fails, continue on old connection */ av_dict_copy(&options, s->chained_options, 0); if ((ret = http_open_cnx(h, &options)) < 0) { -- 1.8.1.4
_______________________________________________ libav-devel mailing list [email protected] https://lists.libav.org/mailman/listinfo/libav-devel
