mirror of
https://github.com/mpv-player/mpv
synced 2025-01-12 01:49:33 +00:00
mp_ring: fix mp_ring_read_cb() when read wraps around
previously, mp_ring_read_cb() would allow reading past the end of the ringbuffer when buffered > available. mp_ring_read() had logic for splitting the read into two, which I duplicated into mp_ring_read_cb().
This commit is contained in:
parent
5c3abb9082
commit
16450fab3f
@ -99,9 +99,17 @@ int mp_ring_read_cb(struct mp_ring *buffer, void *ctx, int len,
|
||||
int read_len = FFMIN(len, buffered);
|
||||
int read_ptr = mp_ring_get_rpos(buffer) % size;
|
||||
|
||||
func(ctx, buffer->buffer + read_ptr, read_len);
|
||||
int len1 = FFMIN(size - read_ptr, read_len);
|
||||
int len2 = read_len - len1;
|
||||
|
||||
return mp_ring_drain(buffer, read_len);
|
||||
func(ctx, buffer->buffer + read_ptr, len1);
|
||||
if (len2 > 0)
|
||||
func(ctx, buffer->buffer, len2);
|
||||
|
||||
mp_atomic_add_and_fetch(&buffer->rpos, read_len);
|
||||
mp_memory_barrier();
|
||||
|
||||
return read_len;
|
||||
}
|
||||
|
||||
int mp_ring_write(struct mp_ring *buffer, unsigned char *src, int len)
|
||||
|
Loading…
Reference in New Issue
Block a user