metadata add audio_fmt to get_metadata_ex

tagcache.c add_tagcache() and potentially
skin_tokens.c wps_playlist_percent_prepare()

make calls to probe_file_format() prior to calling get_metadata_ex
resulting in some small amout of duplicated work
especially in the case of add_tagcache this can add
up to a lot of duplicated work

breaks out audio_fmt so these can supply the afmt other callers just
supply probe_file_format(trackname) in the function call

Change-Id: I8084213b8ee7e04d76dce0986beb83d443ac804b
This commit is contained in:
William Wilgus 2026-06-27 14:14:01 -04:00
parent 3e08b86e4b
commit 3cd286d8f8
6 changed files with 17 additions and 14 deletions

View file

@ -651,8 +651,8 @@ static bool buffer_handle(int handle_id, size_t to_buffer)
trigger_cpu_boost();
if (h->type == TYPE_ID3) {
get_metadata_ex(ringbuf_ptr(h->data),
h->fd, h->path, METADATA_CLOSE_FD_ON_EXIT);
get_metadata_ex(ringbuf_ptr(h->data), h->fd, h->path,
probe_file_format(h->path), METADATA_CLOSE_FD_ON_EXIT);
h->fd = -1; /* with above, behavior same as close_fd */
h->widx = ringbuf_add(h->data, h->filesize);
h->end = h->filesize;

View file

@ -297,7 +297,7 @@ void wps_playlist_percent_prepare(void)
if (afmt != last_afmt || last_bps == 0
|| amount <= 50 || (amount <= 250 && ata_disk_isssd())) // TODO tune this for harddisk devices
{
if (get_metadata_ex(tmp, fd, info.filename,
if (get_metadata_ex(tmp, fd, info.filename, afmt,
METADATA_EXCLUDE_ID3_PATH | METADATA_EXCLUDE_NORMALIZE))
{
secs = tmp->length / 1000;
@ -314,8 +314,8 @@ void wps_playlist_percent_prepare(void)
close(fd);
}
#else
if (get_metadata_ex(tmp, -1, info.filename,
METADATA_EXCLUDE_ID3_PATH | METADATA_EXCLUDE_NORMALIZE))
if (get_metadata_ex(tmp, -1, info.filename, probe_file_format(info.filename),
METADATA_EXCLUDE_ID3_PATH | METADATA_EXCLUDE_NORMALIZE))
{
secs = tmp->length / 1000;
mins = MIN(MAX(1, (secs + 30) / 60), 65535ul);/* minutes, rounded to nearest */

View file

@ -307,7 +307,8 @@ static bool retrieve_id3_tags(const int index, const char* name, struct mp3entry
if (!id3_retrieval_successful)
{
/* Read from disk: retrieves frequency, file size, and codec */
id3_retrieval_successful = get_metadata_ex(id3, -1, name, flags);
id3_retrieval_successful = get_metadata_ex(id3, -1, name,
probe_file_format(name), flags);
}
return id3_retrieval_successful;
}

View file

@ -2291,8 +2291,9 @@ static void NO_INLINE add_tagcache(char *path, unsigned long mtime)
}
/* Check if the file is supported. */
if (probe_file_format(path) == AFMT_UNKNOWN)
return ;
int afmt = probe_file_format(path);
if (afmt == AFMT_UNKNOWN)
return;
/* Check if the file is already cached. */
#if defined(HAVE_TC_RAMCACHE) && defined(HAVE_DIRCACHE)
@ -2338,7 +2339,7 @@ static void NO_INLINE add_tagcache(char *path, unsigned long mtime)
/*memset(&id3, 0, sizeof(struct mp3entry)); -- get_metadata does this for us */
memset(&entry, 0, sizeof(struct temp_file_entry));
memset(&tracknumfix, 0, sizeof(tracknumfix));
ret = get_metadata_ex(&id3, -1, path, METADATA_EXCLUDE_ID3_PATH);
ret = get_metadata_ex(&id3, -1, path, afmt, METADATA_EXCLUDE_ID3_PATH);
if (!ret)
{

View file

@ -420,11 +420,12 @@ unsigned int probe_file_format(const char *filename)
/* Get metadata for track - return false if parsing showed problems with the
* file that would prevent playback. supply a filedescriptor <0 and the file will be opened
* and closed automatically within the get_metadata call
* audio_fmt is AFMT_ enum provided by probe_file_format(trackname),
* get_metadata_ex allows flags to change the way get_metadata behaves
* METADATA_EXCLUDE_ID3_PATH won't copy filename path to the id3 path buffer
* METADATA_CLOSE_FD_ON_EXIT closes the open filedescriptor on exit
*/
bool get_metadata_ex(struct mp3entry* id3, int fd, const char* trackname, int flags)
bool get_metadata_ex(struct mp3entry* id3, int fd, const char* trackname, int audio_fmt, int flags)
{
bool success = true;
const struct afmt_entry *entry;
@ -449,7 +450,7 @@ bool get_metadata_ex(struct mp3entry* id3, int fd, const char* trackname, int fl
}
/* Take our best guess at the codec type based on file extension */
id3->codectype = probe_file_format(trackname);
id3->codectype = audio_fmt; /* use probe_file_format(trackname); */
/* default values for embedded cuesheets */
id3->has_embedded_cuesheet = false;
@ -517,7 +518,7 @@ log_on_exit:
bool get_metadata(struct mp3entry* id3, int fd, const char* trackname)
{
return get_metadata_ex(id3, fd, trackname, 0);
return get_metadata_ex(id3, fd, trackname, probe_file_format(trackname), 0);
}
#define MOVE_ENTRY(x) if (x) x += offset;

View file

@ -328,9 +328,9 @@ struct mp3entry {
bool is_asf_stream;
};
unsigned int probe_file_format(const char *filename);
unsigned int probe_file_format(const char *filename); /* returns audio_fmt */
bool get_metadata(struct mp3entry* id3, int fd, const char* trackname);
bool get_metadata_ex(struct mp3entry* id3, int fd, const char* trackname, int flags);
bool get_metadata_ex(struct mp3entry* id3, int fd, const char* trackname, int audio_fmt, int flags);
void adjust_mp3entry(struct mp3entry *entry, void *dest, const void *orig);
void copy_mp3entry(struct mp3entry *dest, const struct mp3entry *orig);
void wipe_mp3entry(struct mp3entry *id3);