mirror of
https://github.com/mpv-player/mpv
synced 2024-12-28 10:02:17 +00:00
stream: remove inline buffer optimization
Was probably worthless, and I can't measure a difference anymore (I used to be able and it still seemed worth doing so back then). When the default buffer size is enlarged in the next commit, the inline buffer probably won't even be useful in theory, because the data will rarely be on the same page as the other stream fields. It surely makes the inline buffer seem like a ridiculous micro-optimization. Farewell...
This commit is contained in:
parent
f37f4de849
commit
b4466cf0d4
@ -95,6 +95,10 @@ static const stream_info_t *const stream_list[] = {
|
||||
NULL
|
||||
};
|
||||
|
||||
// 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)
|
||||
|
||||
struct stream_opts {
|
||||
int64_t buffer_size;
|
||||
};
|
||||
@ -104,12 +108,12 @@ struct stream_opts {
|
||||
const struct m_sub_options stream_conf = {
|
||||
.opts = (const struct m_option[]){
|
||||
OPT_BYTE_SIZE("stream-buffer-size", buffer_size, 0,
|
||||
STREAM_FIXED_BUFFER_SIZE, 512 * 1024 * 1024),
|
||||
STREAM_MIN_BUFFER_SIZE, 512 * 1024 * 1024),
|
||||
{0}
|
||||
},
|
||||
.size = sizeof(struct stream_opts),
|
||||
.defaults = &(const struct stream_opts){
|
||||
.buffer_size = STREAM_FIXED_BUFFER_SIZE,
|
||||
.buffer_size = STREAM_MIN_BUFFER_SIZE,
|
||||
},
|
||||
};
|
||||
|
||||
@ -244,7 +248,7 @@ static bool stream_resize_buffer(struct stream *s, uint32_t new)
|
||||
new = MPMAX(new, s->requested_buffer_size);
|
||||
|
||||
// This much is always required.
|
||||
new = MPMAX(new, STREAM_FIXED_BUFFER_SIZE);
|
||||
new = MPMAX(new, STREAM_MIN_BUFFER_SIZE);
|
||||
|
||||
new = mp_round_next_power_of_2(new);
|
||||
if (!new || new > INT_MAX / 8)
|
||||
@ -255,15 +259,7 @@ static bool stream_resize_buffer(struct stream *s, uint32_t new)
|
||||
|
||||
MP_DBG(s, "resize stream to %d bytes\n", new);
|
||||
|
||||
uint8_t *nbuf = s->buffer_inline;
|
||||
if (new > STREAM_FIXED_BUFFER_SIZE) {
|
||||
nbuf = ta_alloc_size(s, new);
|
||||
} else {
|
||||
static_assert(MP_IS_POWER_OF_2(STREAM_FIXED_BUFFER_SIZE), "");
|
||||
assert(new == STREAM_FIXED_BUFFER_SIZE);
|
||||
}
|
||||
assert(nbuf != s->buffer);
|
||||
|
||||
void *nbuf = ta_alloc_size(s, new);
|
||||
if (!nbuf)
|
||||
return false; // oom; tolerate it, caller needs to check if required
|
||||
|
||||
@ -276,8 +272,7 @@ static bool stream_resize_buffer(struct stream *s, uint32_t new)
|
||||
s->buf_cur = old_pos;
|
||||
s->buf_end = new_len;
|
||||
|
||||
if (s->buffer != s->buffer_inline)
|
||||
ta_free(s->buffer);
|
||||
ta_free(s->buffer);
|
||||
|
||||
s->buffer = nbuf;
|
||||
s->buffer_mask = new - 1;
|
||||
|
@ -31,8 +31,6 @@
|
||||
// Minimum guaranteed buffer and seek-back size. For any reads <= of this size,
|
||||
// it's guaranteed that you can seek back by <= of this size again.
|
||||
#define STREAM_BUFFER_SIZE 2048
|
||||
// (Half of this is typically reserved for seeking back.)
|
||||
#define STREAM_FIXED_BUFFER_SIZE (STREAM_BUFFER_SIZE * 2)
|
||||
|
||||
// stream->mode
|
||||
#define STREAM_READ 0
|
||||
@ -174,8 +172,6 @@ typedef struct stream {
|
||||
|
||||
unsigned int buffer_mask; // buffer_size-1, where buffer_size == 2**n
|
||||
uint8_t *buffer;
|
||||
|
||||
uint8_t buffer_inline[STREAM_FIXED_BUFFER_SIZE];
|
||||
} stream_t;
|
||||
|
||||
// Non-inline version with stream_read_char().
|
||||
|
Loading…
Reference in New Issue
Block a user