1
0
mirror of https://gitlab.xiph.org/xiph/icecast-server.git synced 2025-01-03 14:56:34 -05:00

Feature: Added code that can undo the effect of offsets

This commit is contained in:
Philipp Schafft 2018-08-15 13:53:24 +00:00
parent 18e410cf24
commit a92b39becd

View File

@ -61,9 +61,20 @@ void buffer_preallocate(buffer_t *buffer, size_t request)
void *n;
size_t newlen;
/* TODO: use this function to clean up the effects of buffer->offset */
if (!buffer)
return;
if (!buffer || !request)
/* Remove the offset if it makes sense to do so. */
if (buffer->offset == buffer->fill) {
buffer->offset = 0;
buffer->fill = 0;
} else if ((2*buffer->offset) < buffer->fill || buffer->offset >= 512 || (buffer->offset > 128 && buffer->offset >= request)) {
buffer->fill -= buffer->offset;
memmove(buffer->buffer, buffer->buffer + buffer->offset, buffer->fill);
buffer->offset = 0;
}
if (!request)
return;
newlen = buffer->fill + request;
@ -145,6 +156,9 @@ int buffer_shift(buffer_t *buffer, size_t amount)
buffer->offset += amount;
/* run cleanup */
buffer_preallocate(buffer, 0);
return 0;
}