From 35150b83d488c9ebfa3e2d5ab4e3af78dc60ee0c Mon Sep 17 00:00:00 2001 From: "roman.artiukhin" Date: Wed, 20 Sep 2023 16:08:45 +0300 Subject: Codecs: mp4: Fix sbr detections for some files Use logic from libfaad/mp4.c AudioSpecificConfig2 for sbr detection Fixes FS#12856 Change-Id: I235aa27830aa99f1307b303347f7affe7deafbe3 --- lib/rbcodec/metadata/mp4.c | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/lib/rbcodec/metadata/mp4.c b/lib/rbcodec/metadata/mp4.c index 7686165a0d..1540e93738 100644 --- a/lib/rbcodec/metadata/mp4.c +++ b/lib/rbcodec/metadata/mp4.c @@ -213,6 +213,7 @@ static bool read_mp4_esds(int fd, struct mp3entry* id3, uint32_t* size) { unsigned char buf[8] = {0}; bool sbr = false; + bool sbr_signaled = false; lseek(fd, 4, SEEK_CUR); /* Version and flags. */ read(fd, buf, 1); /* Verify ES_DescrTag. */ @@ -282,6 +283,7 @@ static bool read_mp4_esds(int fd, struct mp3entry* id3, uint32_t* size) * Object type - 5 bits * Frequency index - 4 bits * Channel configuration - 4 bits + * Also see libfaad/mp4.c AudioSpecificConfig2 (consider using it instead of manual parsing) */ bits = get_long_be(buf); type = bits >> 27; /* Object type - 5 bits */ @@ -326,6 +328,7 @@ static bool read_mp4_esds(int fd, struct mp3entry* id3, uint32_t* size) if (type == 5) { sbr = bits >> 31; + sbr_signaled = true; if (sbr) { @@ -353,13 +356,11 @@ static bool read_mp4_esds(int fd, struct mp3entry* id3, uint32_t* size) } } - if (!sbr && (id3->frequency <= 24000) && (length <= 2)) + if (!sbr && !sbr_signaled && id3->frequency <= 24000) { - /* Double the frequency for low-frequency files without a "long" - * DecSpecificConfig header. The file may or may not contain SBR, - * but here we guess it does if the header is short. This can - * fail on some files, but it's the best we can do, short of - * decoding (parts of) the file. + /* As stated in libfaad/mp4.c AudioSpecificConfig2: + * no SBR signalled, this could mean either implicit signalling or no SBR in this file + * MPEG specification states: assume SBR on files with samplerate <= 24000 Hz */ id3->frequency *= 2; sbr = true; -- cgit v1.2.3