SDL_mixer: update to latest drmp3 (28864)

From 2886493e092c2dae53d30b86ff9e7be766a172be Mon Sep 17 00:00:00 2001
From: Ozkan Sezer <[EMAIL REDACTED]>
Date: Wed, 12 Mar 2025 09:15:50 +0300
Subject: [PATCH] update to latest drmp3

---
 src/codecs/dr_libs/README.md |  6 ++++--
 src/codecs/dr_libs/dr_mp3.h  | 32 ++++++++++++++++++++++++++++----
 2 files changed, 32 insertions(+), 6 deletions(-)

diff --git a/src/codecs/dr_libs/README.md b/src/codecs/dr_libs/README.md
index 6e8ca4086..c98f100e8 100644
--- a/src/codecs/dr_libs/README.md
+++ b/src/codecs/dr_libs/README.md
@@ -1,10 +1,11 @@
 <h4 align="center">Public domain, single file audio decoding libraries for C and C++.</h4>
 
 <p align="center">
-    <a href="https://discord.gg/9vpqbjU"><img src="https://img.shields.io/discord/712952679415939085?label=discord&logo=discord" alt="discord"></a>
-    <a href="https://twitter.com/mackron"><img src="https://img.shields.io/twitter/follow/mackron?style=flat&label=twitter&color=1da1f2&logo=twitter" alt="twitter"></a>
+    <a href="https://discord.gg/9vpqbjU"><img src="https://img.shields.io/discord/712952679415939085?label=discord&logo=discord&style=flat-square" alt="discord"></a>
 </p>
 
+All development of released libraries happens on the master branch. There may exist some decoder-specific branches for work in progress. Check tags for the latest version of a particular library.
+
 
 Library                                         | Description
 ----------------------------------------------- | -----------
@@ -19,3 +20,4 @@ Below are some of my other libraries you may be interested in.
 Library                                           | Description
 ------------------------------------------------- | -----------
 [miniaudio](https://github.com/mackron/miniaudio) | A public domain, single file library for audio playback and recording.
+
diff --git a/src/codecs/dr_libs/dr_mp3.h b/src/codecs/dr_libs/dr_mp3.h
index 1ea12060f..d764ea6d3 100644
--- a/src/codecs/dr_libs/dr_mp3.h
+++ b/src/codecs/dr_libs/dr_mp3.h
@@ -3202,8 +3202,17 @@ static drmp3_bool32 drmp3_init_internal(drmp3* pMP3, drmp3_read_proc onRead, drm
                         pTagData += 21;
 
                         if (pTagData - pFirstFrameData + 14 < firstFrameInfo.frame_bytes) {
-                            pMP3->delayInPCMFrames   = (( (drmp3_uint32)pTagData[0]        << 4) | ((drmp3_uint32)pTagData[1] >> 4)) + (528 + 1);
-                            pMP3->paddingInPCMFrames = ((((drmp3_uint32)pTagData[1] & 0xF) << 8) | ((drmp3_uint32)pTagData[2]     )) - (528 + 1);
+                            int delayInPCMFrames;
+                            int paddingInPCMFrames;
+
+                            delayInPCMFrames   = (( (drmp3_uint32)pTagData[0]        << 4) | ((drmp3_uint32)pTagData[1] >> 4)) + (528 + 1);
+                            paddingInPCMFrames = ((((drmp3_uint32)pTagData[1] & 0xF) << 8) | ((drmp3_uint32)pTagData[2]     )) - (528 + 1);
+                            if (paddingInPCMFrames < 0) {
+                                paddingInPCMFrames = 0; /* Padding cannot be negative. Probably a malformed file. Ignore. */
+                            }
+                            
+                            pMP3->delayInPCMFrames   = (drmp3_uint32)delayInPCMFrames;
+                            pMP3->paddingInPCMFrames = (drmp3_uint32)paddingInPCMFrames;
                         }
                     }
 
@@ -4515,15 +4524,30 @@ DRMP3_API drmp3_bool32 drmp3_get_mp3_and_pcm_frame_count(drmp3* pMP3, drmp3_uint
 
 DRMP3_API drmp3_uint64 drmp3_get_pcm_frame_count(drmp3* pMP3)
 {
+    drmp3_uint64 totalPCMFrameCount;
+
     if (pMP3 == NULL) {
         return 0;
     }
 
     if (pMP3->totalPCMFrameCount != DRMP3_UINT64_MAX) {
-        return (drmp3_uint64)pMP3->totalPCMFrameCount - pMP3->paddingInPCMFrames - pMP3->delayInPCMFrames;
+        totalPCMFrameCount = pMP3->totalPCMFrameCount;
+
+        if (totalPCMFrameCount >= pMP3->delayInPCMFrames) {
+            totalPCMFrameCount -= pMP3->delayInPCMFrames;
+        } else {
+            /* The delay is greater than the frame count reported by the Xing/Info tag. Assume it's invalid and ignore. */
+        }
+
+        if (totalPCMFrameCount >= pMP3->paddingInPCMFrames) {
+            totalPCMFrameCount -= pMP3->paddingInPCMFrames;
+        } else {
+            /* The padding is greater than the frame count reported by the Xing/Info tag. Assume it's invalid and ignore. */
+        }
+
+        return totalPCMFrameCount;
     } else {
         /* Unknown frame count. Need to calculate it. */
-        drmp3_uint64 totalPCMFrameCount;
         if (!drmp3_get_mp3_and_pcm_frame_count(pMP3, NULL, &totalPCMFrameCount)) {
             return 0;
         }