summaryrefslogtreecommitdiffstats
path: root/stream
diff options
context:
space:
mode:
Diffstat (limited to 'stream')
-rw-r--r--stream/stream.c70
-rw-r--r--stream/stream.h73
2 files changed, 73 insertions, 70 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)
{
diff --git a/stream/stream.h b/stream/stream.h
index ad2d7dd19a..5d74433c0b 100644
--- a/stream/stream.h
+++ b/stream/stream.h
@@ -299,30 +299,6 @@ inline static unsigned int stream_read_int24(stream_t *s)
return y;
}
-inline static 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;
-}
-
unsigned char *stream_read_line(stream_t *s, unsigned char *mem, int max,
int utf16);
@@ -336,52 +312,9 @@ inline static int64_t stream_tell(stream_t *s)
return s->pos + s->buf_pos - s->buf_len;
}
-inline static 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);
-}
-
-inline static 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;
-}
+int stream_skip(stream_t *s, int64_t len);
+int stream_seek(stream_t *s, int64_t pos);
+int stream_read(stream_t *s, char *mem, int total);
struct MPOpts;
/*