From 600bccdf2aafba49f3aa19c774c3cdc025e93368 Mon Sep 17 00:00:00 2001 From: wm4 Date: Sat, 14 Dec 2013 00:51:00 +0100 Subject: stream: add function for dropping the buffer And use it in demux_lavf.c. It looks like otherwise, some data might be left over, depending on how the hell av_seek_frame() behaves. --- demux/demux_lavf.c | 1 + stream/stream.c | 12 ++++++++++-- stream/stream.h | 1 + 3 files changed, 12 insertions(+), 2 deletions(-) diff --git a/demux/demux_lavf.c b/demux/demux_lavf.c index 357e173322..4accb6d8fb 100644 --- a/demux/demux_lavf.c +++ b/demux/demux_lavf.c @@ -902,6 +902,7 @@ redo: * call the new API instead of relying on av_seek_frame() to do this * for us. */ + stream_drop_buffers(demuxer->stream); avio_flush(priv->avfc->pb); av_seek_frame(priv->avfc, 0, stream_tell(demuxer->stream), AVSEEK_FLAG_BYTE); diff --git a/stream/stream.c b/stream/stream.c index b7c373b6d4..ecda83e4aa 100644 --- a/stream/stream.c +++ b/stream/stream.c @@ -604,6 +604,15 @@ static int stream_skip_read(struct stream *s, int64_t len) return 1; } +// Drop the internal buffer. Note that this will advance the stream position +// (as seen by stream_tell()), because the real stream position is ahead of the +// logical stream position by the amount of buffered but not yet read data. +void stream_drop_buffers(stream_t *s) +{ + s->buf_pos = s->buf_len = 0; + s->eof = 0; +} + // Seek function bypassing the local stream buffer. static int stream_seek_unbuffered(stream_t *s, int64_t newpos) { @@ -631,8 +640,7 @@ static int stream_seek_unbuffered(stream_t *s, int64_t newpos) // Unlike stream_seek_unbuffered(), it still fills the local buffer. static int stream_seek_long(stream_t *s, int64_t pos) { - s->buf_pos = s->buf_len = 0; - s->eof = 0; + stream_drop_buffers(s); if (s->mode == STREAM_WRITE) { if (!(s->flags & MP_STREAM_SEEK) || !s->seek(s, pos)) diff --git a/stream/stream.h b/stream/stream.h index 6182d6414d..a3592a692d 100644 --- a/stream/stream.h +++ b/stream/stream.h @@ -239,6 +239,7 @@ int stream_seek(stream_t *s, int64_t pos); int stream_read(stream_t *s, char *mem, int total); int stream_read_partial(stream_t *s, char *buf, int buf_size); struct bstr stream_peek(stream_t *s, int len); +void stream_drop_buffers(stream_t *s); struct MPOpts; -- cgit v1.2.3