Revert "buffering: remove bufgettail/bufcuttail"

This reverts commit 9e93796407.

Fixes FS#13626, which is caused by non-audio ID3v1/APE tags at
the end of the audio data stream.

Change-Id: Ic69af14a5d1264b7896a54b5f2ad314022dd98ac
This commit is contained in:
Solomon Peachy 2025-05-20 07:33:10 -04:00
parent 3cb4e63253
commit 2bd88936f7
5 changed files with 107 additions and 2 deletions

View file

@ -1440,6 +1440,62 @@ ssize_t bufgetdata(int handle_id, size_t size, void **data)
return size;
}
ssize_t bufgettail(int handle_id, size_t size, void **data)
{
if (thread_self() != buffering_thread_id)
return ERR_WRONG_THREAD; /* only from buffering thread */
/* We don't support tail requests of > guardbuf_size, for simplicity */
if (size > GUARD_BUFSIZE)
return ERR_INVALID_VALUE;
const struct memory_handle *h = find_handle(handle_id);
if (!h)
return ERR_HANDLE_NOT_FOUND;
if (h->end >= h->filesize) {
size_t tidx = ringbuf_sub_empty(h->widx, size);
if (tidx + size > buffer_len) {
size_t copy_n = tidx + size - buffer_len;
memcpy(guard_buffer, ringbuf_ptr(0), copy_n);
}
*data = ringbuf_ptr(tidx);
}
else {
size = ERR_HANDLE_NOT_DONE;
}
return size;
}
ssize_t bufcuttail(int handle_id, size_t size)
{
if (thread_self() != buffering_thread_id)
return ERR_WRONG_THREAD; /* only from buffering thread */
struct memory_handle *h = find_handle(handle_id);
if (!h)
return ERR_HANDLE_NOT_FOUND;
if (h->end >= h->filesize) {
/* Cannot trim to before read position */
size_t available = h->end - MAX(h->start, h->pos);
if (available < size)
size = available;
h->widx = ringbuf_sub_empty(h->widx, size);
h->filesize -= size;
h->end -= size;
} else {
size = ERR_HANDLE_NOT_DONE;
}
return size;
}
/*
SECONDARY EXPORTED FUNCTIONS
============================