summaryrefslogtreecommitdiffstats
path: root/stream/stream.c
diff options
context:
space:
mode:
authorwm4 <wm4@nowhere>2013-05-24 11:56:49 +0200
committerwm4 <wm4@nowhere>2013-05-26 16:55:20 +0200
commit137c1032faca14b922fc79d8813eabf095be9c35 (patch)
tree94accfc0479368494477df903c7bd1230b221ca4 /stream/stream.c
parent58a7d81dc55835fb0f5cc6a3f14288d722f83c91 (diff)
downloadmpv-137c1032faca14b922fc79d8813eabf095be9c35.tar.bz2
mpv-137c1032faca14b922fc79d8813eabf095be9c35.tar.xz
stream: de-inline some larger functions
Tests with demux_mkv show that the speed doesn't change (or actually, it seems to be faster after this change). In any case, there is not the slightest reason why these should be inline. Functions for which this will (probably) actually matter, like stream_read_char, are still left inline. This was tested with demux_mkv's indexing. For broken files without index, demux_mkv creates an on-the-fly index. If you seek to a later part of the file, all data has to be read and parsed until the wanted position is found. This means demux_mkv will do mostly I/O, calling stream_read_char() and stream_read(). This should be the most I/O intensive non-deprecated part of mpv that uses the stream interface. (demux_lavf has its own buffering.)
Diffstat (limited to 'stream/stream.c')
-rw-r--r--stream/stream.c70
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)
{