From fdbaf7df597b404be04cecbdc83dbc0551a5b996 Mon Sep 17 00:00:00 2001 From: William Wilgus Date: Fri, 5 Jul 2024 17:13:10 -0400 Subject: [Feature] playlist_viewer id3 title display Not sure this is a great idea from disk and battery standpoint but there is no reason you can't.. using the name buffer to fill title data prevent hitting the disk for each screen scroll add get_metadata_ex to allow flags METADATA_EXCLUDE_ID3_PATH prevent copying the filename to the ID3 struct METADATA_CLOSE_FD_ON_EXIT instead of seeking to the beginning the file is closed before get_metadata returns add logic to allow a invalid fd to signal that get_metadata should open and close the file within its call bugfix per Chris_s don't use the tagcache for the trackinfo Change-Id: Ic7a595b39a8d7a57f975312bc9c8bb4111f22a88 --- lib/rbcodec/metadata/metadata.c | 62 ++++++++++++++++++++++++++--------------- lib/rbcodec/metadata/metadata.h | 3 ++ 2 files changed, 42 insertions(+), 23 deletions(-) (limited to 'lib/rbcodec/metadata') diff --git a/lib/rbcodec/metadata/metadata.c b/lib/rbcodec/metadata/metadata.c index 19147ccdb3..28cef46d92 100644 --- a/lib/rbcodec/metadata/metadata.c +++ b/lib/rbcodec/metadata/metadata.c @@ -394,25 +394,19 @@ unsigned int probe_file_format(const char *filename) /* Note, that this returns false for successful, true for error! */ bool mp3info(struct mp3entry *entry, const char *filename) { - int fd; - bool result; - - fd = open(filename, O_RDONLY); - if (fd < 0) - return true; - - result = !get_metadata(entry, fd, filename); - - close(fd); - - return result; + return !get_metadata(entry, -1, filename); } /* Get metadata for track - return false if parsing showed problems with the - * file that would prevent playback. + * file that would prevent playback. supply a filedescriptor <0 and the file will be opened + * and closed automatically within the get_metadata call + * 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(struct mp3entry* id3, int fd, const char* trackname) +bool get_metadata_ex(struct mp3entry* id3, int fd, const char* trackname, int flags) { + bool success = true; const struct afmt_entry *entry; int logfd = 0; DEBUGF("Read metadata for %s\n", trackname); @@ -426,10 +420,20 @@ bool get_metadata(struct mp3entry* id3, int fd, const char* trackname) close(logfd); } } - /* Clear the mp3entry to avoid having bogus pointers appear */ wipe_mp3entry(id3); + if (fd < 0) + { + fd = open(trackname, O_RDONLY); + flags |= METADATA_CLOSE_FD_ON_EXIT; + if (fd < 0) + { + DEBUGF("Error opening %s\n", trackname); + return false; /*Failure*/ + } + } + /* Take our best guess at the codec type based on file extension */ id3->codectype = probe_file_format(trackname); @@ -443,19 +447,31 @@ bool get_metadata(struct mp3entry* id3, int fd, const char* trackname) if (!entry->parse_func) { DEBUGF("nothing to parse for %s (format %s)\n", trackname, entry->label); - return false; + success = false; } - - if (!entry->parse_func(fd, id3)) + else if (!entry->parse_func(fd, id3)) { DEBUGF("parsing %s failed (format: %s)\n", trackname, entry->label); - return false; + success = false; + wipe_mp3entry(id3); /* ensure the mp3entry is clear */ } - lseek(fd, 0, SEEK_SET); - strlcpy(id3->path, trackname, sizeof(id3->path)); - /* We have successfully read the metadata from the file */ - return true; + if ((flags & METADATA_CLOSE_FD_ON_EXIT)) + close(fd); + else + lseek(fd, 0, SEEK_SET); + + if (success && (flags & METADATA_EXCLUDE_ID3_PATH) == 0) + { + strlcpy(id3->path, trackname, sizeof(id3->path)); + } + /* have we successfully read the metadata from the file? */ + return success; +} + +bool get_metadata(struct mp3entry* id3, int fd, const char* trackname) +{ + return get_metadata_ex(id3, fd, trackname, 0); } #define MOVE_ENTRY(x) if (x) x += offset; diff --git a/lib/rbcodec/metadata/metadata.h b/lib/rbcodec/metadata/metadata.h index b30979334a..a0ba0376c6 100644 --- a/lib/rbcodec/metadata/metadata.h +++ b/lib/rbcodec/metadata/metadata.h @@ -24,6 +24,8 @@ #include "platform.h" +#define METADATA_EXCLUDE_ID3_PATH (0x01) /* don't copy filename path to the id3 path buffer */ +#define METADATA_CLOSE_FD_ON_EXIT (0x02) /* close the filedescriptor when finished */ /* Audio file types. */ /* NOTE: The values of the AFMT_* items are used for the %fc tag in the WPS - so new entries MUST be added to the end to maintain compatibility. @@ -323,6 +325,7 @@ struct mp3entry { unsigned int probe_file_format(const char *filename); 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 mp3info(struct mp3entry *entry, const char *filename); void adjust_mp3entry(struct mp3entry *entry, void *dest, const void *orig); void copy_mp3entry(struct mp3entry *dest, const struct mp3entry *orig); -- cgit v1.2.3