From 8e74b085389fe0a7d998dac253a7965e253999bf Mon Sep 17 00:00:00 2001 From: wm4 Date: Fri, 10 Apr 2020 10:54:02 +0200 Subject: 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. --- stream/stream.c | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) (limited to 'stream') 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; -- cgit v1.2.3