diff options
author | Michael Niedermayer <michaelni@gmx.at> | 2006-09-22 10:03:04 +0000 |
---|---|---|
committer | Michael Niedermayer <michaelni@gmx.at> | 2006-09-22 10:03:04 +0000 |
commit | f40d17398db11d70eb638b2bc12e133dfc6f14c9 (patch) | |
tree | 3e44ea67eb07107b4f7590552a1f11fc729bea50 /libavformat/aviobuf.c | |
parent | 8e06f20abf1f8bbd3580b2992231d039e0c9d77b (diff) | |
download | ffmpeg-streaming-f40d17398db11d70eb638b2bc12e133dfc6f14c9.zip ffmpeg-streaming-f40d17398db11d70eb638b2bc12e133dfc6f14c9.tar.gz |
simplify url_fseek()
Originally committed as revision 6316 to svn://svn.ffmpeg.org/ffmpeg/trunk
Diffstat (limited to 'libavformat/aviobuf.c')
-rw-r--r-- | libavformat/aviobuf.c | 63 |
1 files changed, 24 insertions, 39 deletions
diff --git a/libavformat/aviobuf.c b/libavformat/aviobuf.c index b0f8136..e0832c6 100644 --- a/libavformat/aviobuf.c +++ b/libavformat/aviobuf.c @@ -106,56 +106,41 @@ void put_flush_packet(ByteIOContext *s) 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; - } - 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; } |