diff options
author | wm4 <wm4@nowhere> | 2020-04-10 10:54:02 +0200 |
---|---|---|
committer | wm4 <wm4@nowhere> | 2020-04-10 10:59:18 +0200 |
commit | 8e74b085389fe0a7d998dac253a7965e253999bf (patch) | |
tree | dd81d08862f9718f070749697aaeaf7a6ba61a29 /stream | |
parent | 217c47ecb2d061c7c5df338d7ef57347748601a4 (diff) | |
download | mpv-8e74b085389fe0a7d998dac253a7965e253999bf.tar.bz2 mpv-8e74b085389fe0a7d998dac253a7965e253999bf.tar.xz |
stream: minor adjustment to buffer size limit logic
Instead of having 2 inconsistent limits on the upper possible buffer
size (option limit and allocation code), use a shared constant for them.
Diffstat (limited to 'stream')
-rw-r--r-- | stream/stream.c | 12 |
1 files changed, 6 insertions, 6 deletions
diff --git a/stream/stream.c b/stream/stream.c index c7339b4c66..d12ae93338 100644 --- a/stream/stream.c +++ b/stream/stream.c @@ -96,6 +96,9 @@ static const stream_info_t *const stream_list[] = { // Because of guarantees documented on STREAM_BUFFER_SIZE. // Half the buffer is used as forward buffer, the other for seek-back. #define STREAM_MIN_BUFFER_SIZE (STREAM_BUFFER_SIZE * 2) +// Sort of arbitrary; keep *2 of it comfortably within integer limits. +// Must be power of 2. +#define STREAM_MAX_BUFFER_SIZE (512 * 1024 * 1024) struct stream_opts { int64_t buffer_size; @@ -107,7 +110,7 @@ struct stream_opts { const struct m_sub_options stream_conf = { .opts = (const struct m_option[]){ {"stream-buffer-size", OPT_BYTE_SIZE(buffer_size), - M_RANGE(STREAM_MIN_BUFFER_SIZE, 512 * 1024 * 1024)}, + M_RANGE(STREAM_MIN_BUFFER_SIZE, STREAM_MAX_BUFFER_SIZE)}, {"load-unsafe-playlists", OPT_FLAG(load_unsafe_playlists)}, {0} }, @@ -269,14 +272,11 @@ static bool stream_resize_buffer(struct stream *s, uint32_t new) int old_pos = s->buf_cur - s->buf_start; new = MPMAX(new, old_used_len); - new = MPMAX(new, s->requested_buffer_size); - // This much is always required. - new = MPMAX(new, STREAM_MIN_BUFFER_SIZE); + new = MPMAX(new, s->requested_buffer_size); + new = MPMIN(new, STREAM_MAX_BUFFER_SIZE); new = mp_round_next_power_of_2(new); - if (!new || new > INT_MAX / 8) - return false; if (new == s->buffer_mask + 1) return true; |