Mercurial > libavformat.hg
changeset 1323:e9bf6926aecf libavformat
simplify url_fseek()
author | michael |
---|---|
date | Fri, 22 Sep 2006 10:03:04 +0000 |
parents | 95f56c7b24eb |
children | 024cf76ac4d1 |
files | aviobuf.c |
diffstat | 1 files changed, 25 insertions(+), 40 deletions(-) [+] |
line wrap: on
line diff
--- a/aviobuf.c Thu Sep 21 07:31:53 2006 +0000 +++ b/aviobuf.c Fri Sep 22 10:03:04 2006 +0000 @@ -106,56 +106,41 @@ offset_t url_fseek(ByteIOContext *s, offset_t offset, int whence) { offset_t offset1; + offset_t pos= s->pos - (s->write_flag ? 0 : (s->buf_end - s->buffer)); if (whence != SEEK_CUR && whence != SEEK_SET) return -EINVAL; + if (whence == SEEK_CUR) { + offset1 = pos + (s->buf_ptr - s->buffer); + if (offset == 0) + return offset1; + offset += offset1; + } + offset1 = offset - pos; + if (!s->must_flush && + offset1 >= 0 && offset1 < (s->buf_end - s->buffer)) { + /* can do the seek inside the buffer */ + s->buf_ptr = s->buffer + offset1; + } else { + if (!s->seek) + return -EPIPE; + #ifdef CONFIG_MUXERS - if (s->write_flag) { - if (whence == SEEK_CUR) { - offset1 = s->pos + (s->buf_ptr - s->buffer); - if (offset == 0) - return offset1; - offset += offset1; - } - offset1 = offset - s->pos; - if (!s->must_flush && - offset1 >= 0 && offset1 < (s->buf_end - s->buffer)) { - /* can do the seek inside the buffer */ - s->buf_ptr = s->buffer + offset1; - } else { - if (!s->seek) - return -EPIPE; + if (s->write_flag) { flush_buffer(s); s->must_flush = 1; - s->buf_ptr = s->buffer; - s->seek(s->opaque, offset, SEEK_SET); - s->pos = offset; - } - } else + } else #endif //CONFIG_MUXERS - { - if (whence == SEEK_CUR) { - offset1 = s->pos - (s->buf_end - s->buffer) + (s->buf_ptr - s->buffer); - if (offset == 0) - return offset1; - offset += offset1; + { + s->buf_end = s->buffer; } - offset1 = offset - (s->pos - (s->buf_end - s->buffer)); - if (offset1 >= 0 && offset1 <= (s->buf_end - s->buffer)) { - /* can do the seek inside the buffer */ - s->buf_ptr = s->buffer + offset1; - } else { - if (!s->seek) - return -EPIPE; - s->buf_ptr = s->buffer; - s->buf_end = s->buffer; - if (s->seek(s->opaque, offset, SEEK_SET) == (offset_t)-EPIPE) - return -EPIPE; - s->pos = offset; - } - s->eof_reached = 0; + s->buf_ptr = s->buffer; + if (s->seek(s->opaque, offset, SEEK_SET) == (offset_t)-EPIPE) + return -EPIPE; + s->pos = offset; } + s->eof_reached = 0; return offset; }