diff options
Diffstat (limited to 'stream/stream.c')
-rw-r--r-- | stream/stream.c | 70 |
1 files changed, 70 insertions, 0 deletions
diff --git a/stream/stream.c b/stream/stream.c index 27527a422c..b6f15348fb 100644 --- a/stream/stream.c +++ b/stream/stream.c @@ -403,6 +403,30 @@ int stream_fill_buffer(stream_t *s) return len; } +int stream_read(stream_t *s, char *mem, int total) +{ + int len = total; + while (len > 0) { + int x; + x = s->buf_len - s->buf_pos; + if (x == 0) { + if (!cache_stream_fill_buffer(s)) + return total - len; // EOF + x = s->buf_len - s->buf_pos; + } + if (s->buf_pos > s->buf_len) + mp_msg(MSGT_DEMUX, MSGL_WARN, + "stream_read: WARNING! s->buf_pos>s->buf_len\n"); + if (x > len) + x = len; + memcpy(mem, &s->buffer[s->buf_pos], x); + s->buf_pos += x; + mem += x; + len -= x; + } + return total; +} + int stream_write_buffer(stream_t *s, unsigned char *buf, int len) { int rd; @@ -523,6 +547,52 @@ int stream_seek_long(stream_t *s, int64_t pos) return 1; } +int stream_seek(stream_t *s, int64_t pos) +{ + + mp_dbg(MSGT_DEMUX, MSGL_DBG3, "seek to 0x%llX\n", (long long)pos); + + if (pos < 0) { + mp_msg(MSGT_DEMUX, MSGL_ERR, + "Invalid seek to negative position %llx!\n", + (long long)pos); + pos = 0; + } + if (pos < s->pos) { + int64_t x = pos - (s->pos - s->buf_len); + if (x >= 0) { + s->buf_pos = x; + s->eof = 0; +// putchar('*');fflush(stdout); + return 1; + } + } + + return cache_stream_seek_long(s, pos); +} + +int stream_skip(stream_t *s, int64_t len) +{ + if (len < 0 || + (len > 2 * STREAM_BUFFER_SIZE && (s->flags & MP_STREAM_SEEK_FW))) { + // negative or big skip! + return stream_seek(s, stream_tell(s) + len); + } + while (len > 0) { + int x = s->buf_len - s->buf_pos; + if (x == 0) { + if (!cache_stream_fill_buffer(s)) + return 0; // EOF + x = s->buf_len - s->buf_pos; + } + if (x > len) + x = len; + //memcpy(mem,&s->buf[s->buf_pos],x); + s->buf_pos += x; + len -= x; + } + return 1; +} void stream_reset(stream_t *s) { |