summaryrefslogtreecommitdiff
path: root/libavformat/aviobuf.c
diff options
context:
space:
mode:
authorBryan Huh <bryan@box.com>2015-11-15 18:02:11 -0800
committerMichael Niedermayer <michael@niedermayer.cc>2015-11-16 12:14:03 +0100
commita01c24e8c591985b9aa17a8a1984b517541ef3be (patch)
tree8600cc247622117ec88316d3ab5f1fad624cbbe5 /libavformat/aviobuf.c
parentc9944f75961038e0631efa6d3637b9438c6d6238 (diff)
avformat/aviobuf: Improve readability of aviobuf (Add comments and docs)
Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
Diffstat (limited to 'libavformat/aviobuf.c')
-rw-r--r--libavformat/aviobuf.c7
1 files changed, 5 insertions, 2 deletions
diff --git a/libavformat/aviobuf.c b/libavformat/aviobuf.c
index 1b3d5f5b80..691bdaa9ad 100644
--- a/libavformat/aviobuf.c
+++ b/libavformat/aviobuf.c
@@ -213,6 +213,7 @@ int64_t avio_seek(AVIOContext *s, int64_t offset, int whence)
return AVERROR(EINVAL);
buffer_size = s->buf_end - s->buffer;
+ // pos is the absolute position that the beginning of s->buffer corresponds to in the file
pos = s->pos - (s->write_flag ? 0 : buffer_size);
if (whence != SEEK_CUR && whence != SEEK_SET)
@@ -227,7 +228,7 @@ int64_t avio_seek(AVIOContext *s, int64_t offset, int whence)
if (offset < 0)
return AVERROR(EINVAL);
- offset1 = offset - pos;
+ offset1 = offset - pos; // "offset1" is the relative offset from the beginning of s->buffer
if (!s->must_flush && (!s->direct || !s->seek) &&
offset1 >= 0 && offset1 <= buffer_size - s->write_flag) {
/* can do the seek inside the buffer */
@@ -545,7 +546,8 @@ int avio_read(AVIOContext *s, unsigned char *buf, int size)
if (len > size)
len = size;
if (len == 0 || s->write_flag) {
- if((s->direct || size > s->buffer_size) && !s->update_checksum){
+ if((s->direct || size > s->buffer_size) && !s->update_checksum) {
+ // bypass the buffer and read data directly into buf
if(s->read_packet)
len = s->read_packet(s->opaque, buf, size);
if (len <= 0) {
@@ -560,6 +562,7 @@ int avio_read(AVIOContext *s, unsigned char *buf, int size)
s->bytes_read += len;
size -= len;
buf += len;
+ // reset the buffer
s->buf_ptr = s->buffer;
s->buf_end = s->buffer/* + len*/;
}