buffering: remove bufgettail/bufcuttail

These operations can only be used in limited circumstances and have
exactly one user. bufgettail especially seems of dubious value; how
often do you need to read N bytes from the end of a file without
changing the file position?

strip_tags() was the only function using them, to strip off ID3v1
and APE tags off the end of buffered tracks. This would save only
32-192 bytes per track -- if the container format uses APE/ID3v1.
It hardly seems worth the effort.

Change-Id: I8fc3c1408517eda6126e75e76d76daea904b50eb
This commit is contained in:
Aidan MacDonald 2022-03-26 21:54:23 +00:00 committed by Solomon Peachy
parent 931d616071
commit 9e93796407
6 changed files with 1 additions and 119 deletions

View file

@ -1436,62 +1436,6 @@ 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
============================

View file

@ -46,8 +46,7 @@ enum data_type {
#define ERR_FILE_ERROR -4
#define ERR_HANDLE_NOT_DONE -5
#define ERR_UNSUPPORTED_TYPE -6
#define ERR_WRONG_THREAD -7
#define ERR_BITMAP_TOO_LARGE -8
#define ERR_BITMAP_TOO_LARGE -7
/* Initialise the buffering subsystem */
void buffering_init(void) INIT_ATTR;
@ -68,8 +67,6 @@ bool buffering_reset(char *buf, size_t buflen);
* bufftell : Return the handle's file read position
* bufread : Copy data from a handle to a buffer
* bufgetdata: Obtain a pointer for linear access to a "size" amount of data
* bufgettail: Out-of-band get the last size bytes of a handle.
* bufcuttail: Out-of-band remove the trailing 'size' bytes of a handle.
*
* NOTE: bufread and bufgetdata will block the caller until the requested
* amount of data is ready (unless EOF is reached).
@ -85,8 +82,6 @@ int bufadvance(int handle_id, off_t offset);
off_t bufftell(int handle_id);
ssize_t bufread(int handle_id, size_t size, void *dest);
ssize_t bufgetdata(int handle_id, size_t size, void **data);
ssize_t bufgettail(int handle_id, size_t size, void **data);
ssize_t bufcuttail(int handle_id, size_t size);
/***************************************************************************
* SECONDARY FUNCTIONS

View file

@ -3467,9 +3467,6 @@ static void buffer_event_finished_callback(unsigned short id, void *ev_data)
break;
case TYPE_PACKET_AUDIO:
/* Strip any useless trailing tags that are left. */
strip_tags(hid);
/* Fall-through */
case TYPE_ATOMIC_AUDIO:
LOGFQUEUE("buffering > audio Q_AUDIO_HANDLE_FINISHED: %d", hid);
audio_queue_post(Q_AUDIO_HANDLE_FINISHED, hid);

View file

@ -211,13 +211,6 @@ bool bufclose(int handle_id)
\return
\description
ssize_t bufcuttail(int handle_id, size_t size)
\group buffering API
\param handle_id
\param size
\return
\description
ssize_t bufgetdata(int handle_id, size_t size, void **data)
\group buffering API
\param handle_id
@ -226,14 +219,6 @@ ssize_t bufgetdata(int handle_id, size_t size, void **data)
\return
\description
ssize_t bufgettail(int handle_id, size_t size, void **data)
\group buffering API
\param handle_id
\param size
\param data
\return
\description
int bufopen(const char *file, size_t offset, enum data_type type)
\group buffering API
\param file

View file

@ -458,44 +458,6 @@ bool get_metadata(struct mp3entry* id3, int fd, const char* trackname)
return true;
}
#ifndef __PCTOOL__
void strip_tags(int handle_id)
{
static const unsigned char tag[] = "TAG";
static const unsigned char apetag[] = "APETAGEX";
size_t len, version;
void *tail;
if (bufgettail(handle_id, 128, &tail) != 128)
return;
if (memcmp(tail, tag, 3) == 0)
{
/* Skip id3v1 tag */
logf("Cutting off ID3v1 tag");
bufcuttail(handle_id, 128);
}
/* Get a new tail, as the old one may have been cut */
if (bufgettail(handle_id, 32, &tail) != 32)
return;
/* Check for APE tag (look for the APE tag footer) */
if (memcmp(tail, apetag, 8) != 0)
return;
/* Read the version and length from the footer */
version = get_long_le(&((unsigned char *)tail)[8]);
len = get_long_le(&((unsigned char *)tail)[12]);
if (version == 2000)
len += 32; /* APEv2 has a 32 byte header */
/* Skip APE tag */
logf("Cutting off APE tag (%ldB)", len);
bufcuttail(handle_id, len);
}
#endif /* ! __PCTOOL__ */
#define MOVE_ENTRY(x) if (x) x += offset;
void adjust_mp3entry(struct mp3entry *entry, void *dest, const void *orig)

View file

@ -333,7 +333,6 @@ void wipe_mp3entry(struct mp3entry *id3);
void fill_metadata_from_path(struct mp3entry *id3, const char *trackname);
int get_audio_base_codec_type(int type);
void strip_tags(int handle_id);
bool rbcodec_format_is_atomic(int afmt);
bool format_buffers_with_offset(int afmt);