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.)
This commit is contained in:
wm4 2013-05-24 11:56:49 +02:00
parent 58a7d81dc5
commit 137c1032fa
2 changed files with 73 additions and 70 deletions

View File

@ -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)
{

View File

@ -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;
/*