From c53e9ba27d77d24efc2d65de17b311a883251a99 Mon Sep 17 00:00:00 2001 From: Roman Artiukhin Date: Mon, 23 Jun 2025 18:53:16 +0300 Subject: [PATCH] metadata: mp4: Fill disc/track count Show Track Info now shows Discnum/Tracknum as "i/n" (e.g., "1/3" for disc 1 of 3). Previously, it only showed the disc/track number without the total count. Change-Id: If6b2a73ad0fecc27aaee371f8c860031eacca796 --- lib/rbcodec/metadata/mp4.c | 36 ++++++++++++++++++++++++------------ 1 file changed, 24 insertions(+), 12 deletions(-) diff --git a/lib/rbcodec/metadata/mp4.c b/lib/rbcodec/metadata/mp4.c index 706a50e503..e365d4f4dd 100644 --- a/lib/rbcodec/metadata/mp4.c +++ b/lib/rbcodec/metadata/mp4.c @@ -367,6 +367,28 @@ static bool read_mp4_esds(int fd, struct mp3entry* id3, uint32_t* size) return sbr; } +static void read_mp4_tag_i_from_n(int fd, int *i, char** i_from_n_string, uint32_t size, unsigned int *buffer_left, char **buffer) +{ + uint16_t x[3]; + *i = 0; + *i_from_n_string = NULL; + if (read_mp4_tag(fd, size, (char*) &x, sizeof(x)) == sizeof(x)) + { + *i = betoh16(x[1]); + int n = betoh16(x[2]); + if (n > 0) + { + int string_length = snprintf(*buffer, *buffer_left, "%d/%d", *i, n) + 1; + if (string_length <= *buffer_left) + { + *i_from_n_string = *buffer; + *buffer += string_length; + *buffer_left -= string_length; + } + } + } +} + static bool read_mp4_tags(int fd, struct mp3entry* id3, uint32_t size_left) { @@ -456,21 +478,11 @@ static bool read_mp4_tags(int fd, struct mp3entry* id3, break; case MP4_disk: - { - unsigned short n[2]; - id3->discnum = 0; - if (read_mp4_tag(fd, size, (char*) &n, sizeof(n)) == sizeof(n)) - id3->discnum = betoh16(n[1]); - } + read_mp4_tag_i_from_n(fd, &id3->discnum, &id3->disc_string, size, &buffer_left, &buffer); break; case MP4_trkn: - { - unsigned short n[2]; - id3->tracknum = 0; - if (read_mp4_tag(fd, size, (char*) &n, sizeof(n)) == sizeof(n)) - id3->tracknum = betoh16(n[1]); - } + read_mp4_tag_i_from_n(fd, &id3->tracknum, &id3->track_string, size, &buffer_left, &buffer); break; #ifdef HAVE_ALBUMART