diff options
author | Marton Balint <cus@passwd.hu> | 2020-09-29 00:48:34 +0300 |
---|---|---|
committer | Marton Balint <cus@passwd.hu> | 2020-10-09 22:07:18 +0300 |
commit | da74a740617be53bc83b6b952cfb9b8866ccc222 (patch) | |
tree | f9eaf744eadfb35fa2b88cb1add5064f9ee17779 /libavformat/avio_internal.h | |
parent | 1490a682dc06d868c5170635cad92948c7f28cfb (diff) |
avformat/aviobuf: discard part of the IO buffer in ffio_ensure_seekback if needed
Previously ffio_ensure_seekback never flushed the buffer, so successive
ffio_ensure_seekback calls were all respected. This could eventually cause
unlimited memory and CPU usage if a demuxer called ffio_ensure_seekback on all
it's read data.
Most demuxers however only rely on being able to seek back till the position of
the last ffio_ensure_seekback call, therefore we change the semantics of
ffio_ensure_seekback so that a new call can invalidate seek guarantees of the
old. In order to support some level of "nested" ffio_ensure_seekback calls, we
document that the function only invalidates the old window (and potentially
discards the already read data from the IO buffer), if the newly requested
window does not fit into the old one.
This way we limit the memory usage for ffio_ensure_seekback calls requesting
consecutive data windows.
Signed-off-by: Marton Balint <cus@passwd.hu>
Diffstat (limited to 'libavformat/avio_internal.h')
-rw-r--r-- | libavformat/avio_internal.h | 4 |
1 files changed, 3 insertions, 1 deletions
diff --git a/libavformat/avio_internal.h b/libavformat/avio_internal.h index c575df8035..fe87f2a288 100644 --- a/libavformat/avio_internal.h +++ b/libavformat/avio_internal.h @@ -100,7 +100,9 @@ int ffio_realloc_buf(AVIOContext *s, int buf_size); * * Will ensure that when reading sequentially up to buf_size, seeking * within the current pos and pos+buf_size is possible. - * Once the stream position moves outside this window this guarantee is lost. + * Once the stream position moves outside this window or another + * ffio_ensure_seekback call requests a buffer outside this window this + * guarantee is lost. */ int ffio_ensure_seekback(AVIOContext *s, int64_t buf_size); |