From 792844f8732b294b6badd8d80c29aa03cf6f3ca1 Mon Sep 17 00:00:00 2001 From: wm4 Date: Mon, 26 Aug 2013 23:28:05 +0200 Subject: stream: read at least a full buffer with stream_peek() Until now, stream_peek() read only the bare minimum it had to read from the stream. But this could cause problems, such as being very inefficient when peeking a lot, or conflicting with ability to seek back. (The latter issue can be caused by peeking a few bytes, and then doing a stream_read() with a size that is 1 byte longer: this would read the peeked data, then call stream_fill_buffer(), which throws away the previously peeked bytes - so you can't seek back anymore. This is mitigated by a hack in demux_open(): it peeks a full buffer, to avoid that peeking/reading during demuxer probing [or before that, in a stream filter] can cause the buffer to be dropped.) --- stream/stream.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'stream') diff --git a/stream/stream.c b/stream/stream.c index ebd582de73..8fde847743 100644 --- a/stream/stream.c +++ b/stream/stream.c @@ -550,7 +550,7 @@ struct bstr stream_peek(stream_t *s, int len) memmove(s->buffer, &s->buffer[s->buf_pos], buf_valid); // Fill rest of the buffer. while (buf_valid < len) { - int chunk = len - buf_valid; + int chunk = MPMAX(len - buf_valid, STREAM_BUFFER_SIZE); if (s->sector_size) chunk = STREAM_BUFFER_SIZE; assert(buf_valid + chunk <= TOTAL_BUFFER_SIZE); -- cgit v1.2.3