Skip to content

Commit

Permalink
avformat/aviobuf: fix avio_flush() for read streams
Browse files Browse the repository at this point in the history
avio_flush() did nothing useful for read streams. Fix it to behave as
expected, and discard the currently read buffer properly.

Signed-off-by: Michael Niedermayer <[email protected]>
  • Loading branch information
wm4 authored and michaelni committed Sep 30, 2014
1 parent 07de0db commit c8422f0
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 3 deletions.
8 changes: 6 additions & 2 deletions libavformat/avio.h
Original file line number Diff line number Diff line change
Expand Up @@ -289,10 +289,14 @@ int url_feof(AVIOContext *s);
int avio_printf(AVIOContext *s, const char *fmt, ...) av_printf_format(2, 3);

/**
* Force flushing of buffered data to the output s.
* Force flushing of buffered data.
*
* Force the buffered data to be immediately written to the output,
* For write streams, force the buffered data to be immediately written to the output,
* without to wait to fill the internal buffer.
*
* For read streams, discard all currently buffered data, and advance the
* reported file position to that of the underlying stream. This does not
* read new data, and does not perform any seeks.
*/
void avio_flush(AVIOContext *s);

Expand Down
4 changes: 3 additions & 1 deletion libavformat/aviobuf.c
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ static void writeout(AVIOContext *s, const uint8_t *data, int len)

static void flush_buffer(AVIOContext *s)
{
if (s->buf_ptr > s->buffer) {
if (s->write_flag && s->buf_ptr > s->buffer) {
writeout(s, s->buffer, s->buf_ptr - s->buffer);
if (s->update_checksum) {
s->checksum = s->update_checksum(s->checksum, s->checksum_ptr,
Expand All @@ -148,6 +148,8 @@ static void flush_buffer(AVIOContext *s)
}
}
s->buf_ptr = s->buffer;
if (!s->write_flag)
s->buf_end = s->buffer;
}

void avio_w8(AVIOContext *s, int b)
Expand Down

0 comments on commit c8422f0

Please sign in to comment.