diff options
author | William Wilgus <wilgus.william@gmail.com> | 2024-07-05 17:13:10 -0400 |
---|---|---|
committer | William Wilgus <me.theuser@yahoo.com> | 2024-07-09 01:40:02 -0400 |
commit | fdbaf7df597b404be04cecbdc83dbc0551a5b996 (patch) | |
tree | f4254d2ed63ce1174d9710a315678aeaf921399b /lib/rbcodec | |
parent | 07cf87419189f8730eff53bb74669856a42a2016 (diff) | |
download | rockbox-fdbaf7df597b404be04cecbdc83dbc0551a5b996.tar.gz rockbox-fdbaf7df597b404be04cecbdc83dbc0551a5b996.zip |
[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
Diffstat (limited to 'lib/rbcodec')
-rw-r--r-- | lib/rbcodec/metadata/metadata.c | 62 | ||||
-rw-r--r-- | lib/rbcodec/metadata/metadata.h | 3 |
2 files changed, 42 insertions, 23 deletions
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) | |||
394 | /* Note, that this returns false for successful, true for error! */ | 394 | /* Note, that this returns false for successful, true for error! */ |
395 | bool mp3info(struct mp3entry *entry, const char *filename) | 395 | bool mp3info(struct mp3entry *entry, const char *filename) |
396 | { | 396 | { |
397 | int fd; | 397 | return !get_metadata(entry, -1, filename); |
398 | bool result; | ||
399 | |||
400 | fd = open(filename, O_RDONLY); | ||
401 | if (fd < 0) | ||
402 | return true; | ||
403 | |||
404 | result = !get_metadata(entry, fd, filename); | ||
405 | |||
406 | close(fd); | ||
407 | |||
408 | return result; | ||
409 | } | 398 | } |
410 | 399 | ||
411 | /* Get metadata for track - return false if parsing showed problems with the | 400 | /* Get metadata for track - return false if parsing showed problems with the |
412 | * file that would prevent playback. | 401 | * file that would prevent playback. supply a filedescriptor <0 and the file will be opened |
402 | * and closed automatically within the get_metadata call | ||
403 | * get_metadata_ex allows flags to change the way get_metadata behaves | ||
404 | * METADATA_EXCLUDE_ID3_PATH won't copy filename path to the id3 path buffer | ||
405 | * METADATA_CLOSE_FD_ON_EXIT closes the open filedescriptor on exit | ||
413 | */ | 406 | */ |
414 | bool get_metadata(struct mp3entry* id3, int fd, const char* trackname) | 407 | bool get_metadata_ex(struct mp3entry* id3, int fd, const char* trackname, int flags) |
415 | { | 408 | { |
409 | bool success = true; | ||
416 | const struct afmt_entry *entry; | 410 | const struct afmt_entry *entry; |
417 | int logfd = 0; | 411 | int logfd = 0; |
418 | DEBUGF("Read metadata for %s\n", trackname); | 412 | DEBUGF("Read metadata for %s\n", trackname); |
@@ -426,10 +420,20 @@ bool get_metadata(struct mp3entry* id3, int fd, const char* trackname) | |||
426 | close(logfd); | 420 | close(logfd); |
427 | } | 421 | } |
428 | } | 422 | } |
429 | |||
430 | /* Clear the mp3entry to avoid having bogus pointers appear */ | 423 | /* Clear the mp3entry to avoid having bogus pointers appear */ |
431 | wipe_mp3entry(id3); | 424 | wipe_mp3entry(id3); |
432 | 425 | ||
426 | if (fd < 0) | ||
427 | { | ||
428 | fd = open(trackname, O_RDONLY); | ||
429 | flags |= METADATA_CLOSE_FD_ON_EXIT; | ||
430 | if (fd < 0) | ||
431 | { | ||
432 | DEBUGF("Error opening %s\n", trackname); | ||
433 | return false; /*Failure*/ | ||
434 | } | ||
435 | } | ||
436 | |||
433 | /* Take our best guess at the codec type based on file extension */ | 437 | /* Take our best guess at the codec type based on file extension */ |
434 | id3->codectype = probe_file_format(trackname); | 438 | id3->codectype = probe_file_format(trackname); |
435 | 439 | ||
@@ -443,19 +447,31 @@ bool get_metadata(struct mp3entry* id3, int fd, const char* trackname) | |||
443 | if (!entry->parse_func) | 447 | if (!entry->parse_func) |
444 | { | 448 | { |
445 | DEBUGF("nothing to parse for %s (format %s)\n", trackname, entry->label); | 449 | DEBUGF("nothing to parse for %s (format %s)\n", trackname, entry->label); |
446 | return false; | 450 | success = false; |
447 | } | 451 | } |
448 | 452 | else if (!entry->parse_func(fd, id3)) | |
449 | if (!entry->parse_func(fd, id3)) | ||
450 | { | 453 | { |
451 | DEBUGF("parsing %s failed (format: %s)\n", trackname, entry->label); | 454 | DEBUGF("parsing %s failed (format: %s)\n", trackname, entry->label); |
452 | return false; | 455 | success = false; |
456 | wipe_mp3entry(id3); /* ensure the mp3entry is clear */ | ||
453 | } | 457 | } |
454 | 458 | ||
455 | lseek(fd, 0, SEEK_SET); | 459 | if ((flags & METADATA_CLOSE_FD_ON_EXIT)) |
456 | strlcpy(id3->path, trackname, sizeof(id3->path)); | 460 | close(fd); |
457 | /* We have successfully read the metadata from the file */ | 461 | else |
458 | return true; | 462 | lseek(fd, 0, SEEK_SET); |
463 | |||
464 | if (success && (flags & METADATA_EXCLUDE_ID3_PATH) == 0) | ||
465 | { | ||
466 | strlcpy(id3->path, trackname, sizeof(id3->path)); | ||
467 | } | ||
468 | /* have we successfully read the metadata from the file? */ | ||
469 | return success; | ||
470 | } | ||
471 | |||
472 | bool get_metadata(struct mp3entry* id3, int fd, const char* trackname) | ||
473 | { | ||
474 | return get_metadata_ex(id3, fd, trackname, 0); | ||
459 | } | 475 | } |
460 | 476 | ||
461 | #define MOVE_ENTRY(x) if (x) x += offset; | 477 | #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 @@ | |||
24 | 24 | ||
25 | #include "platform.h" | 25 | #include "platform.h" |
26 | 26 | ||
27 | #define METADATA_EXCLUDE_ID3_PATH (0x01) /* don't copy filename path to the id3 path buffer */ | ||
28 | #define METADATA_CLOSE_FD_ON_EXIT (0x02) /* close the filedescriptor when finished */ | ||
27 | /* Audio file types. */ | 29 | /* Audio file types. */ |
28 | /* NOTE: The values of the AFMT_* items are used for the %fc tag in the WPS | 30 | /* NOTE: The values of the AFMT_* items are used for the %fc tag in the WPS |
29 | - so new entries MUST be added to the end to maintain compatibility. | 31 | - so new entries MUST be added to the end to maintain compatibility. |
@@ -323,6 +325,7 @@ struct mp3entry { | |||
323 | 325 | ||
324 | unsigned int probe_file_format(const char *filename); | 326 | unsigned int probe_file_format(const char *filename); |
325 | bool get_metadata(struct mp3entry* id3, int fd, const char* trackname); | 327 | bool get_metadata(struct mp3entry* id3, int fd, const char* trackname); |
328 | bool get_metadata_ex(struct mp3entry* id3, int fd, const char* trackname, int flags); | ||
326 | bool mp3info(struct mp3entry *entry, const char *filename); | 329 | bool mp3info(struct mp3entry *entry, const char *filename); |
327 | void adjust_mp3entry(struct mp3entry *entry, void *dest, const void *orig); | 330 | void adjust_mp3entry(struct mp3entry *entry, void *dest, const void *orig); |
328 | void copy_mp3entry(struct mp3entry *dest, const struct mp3entry *orig); | 331 | void copy_mp3entry(struct mp3entry *dest, const struct mp3entry *orig); |