[vlc-devel] commit: Support for RIFF/MIDI files ( Rémi Denis-Courmont )

git version control git at videolan.org
Wed Apr 30 20:29:10 CEST 2008


vlc | branch: master | Rémi Denis-Courmont <rem at videolan.org> | Wed Apr 30 21:30:13 2008 +0300| [df3af6f13455675fb4815cee000ff17edffebc99]

Support for RIFF/MIDI files

> http://git.videolan.org/gitweb.cgi/vlc.git/?a=commit;h=df3af6f13455675fb4815cee000ff17edffebc99
---

 modules/demux/smf.c |   38 ++++++++++++++++++++++++++++++++++++++
 1 files changed, 38 insertions(+), 0 deletions(-)

diff --git a/modules/demux/smf.c b/modules/demux/smf.c
index 1ca2dbb..e9a92d9 100644
--- a/modules/demux/smf.c
+++ b/modules/demux/smf.c
@@ -87,6 +87,44 @@ static int Open (vlc_object_t * p_this)
     if (stream_Peek (stream, &peek, 14) < 14)
         return VLC_EGENERIC;
 
+    /* Skip RIFF MIDI header if present */
+    if (!memcmp (peek, "RIFF", 4) && !memcmp (peek + 8, "RMID", 4))
+    {
+        uint32_t riff_len = GetDWLE (peek + 4);
+
+        msg_Dbg (p_this, "detected RIFF MIDI file (%u bytes)",
+                 (unsigned)riff_len);
+        if ((stream_Read (stream, NULL, 12) < 12))
+            return VLC_EGENERIC;
+
+        /* Look for the RIFF data chunk */
+        for (;;)
+        {
+            char chnk_hdr[8];
+            uint32_t chnk_len;
+
+            if ((riff_len < 8)
+             || (stream_Read (stream, chnk_hdr, 8) < 8))
+                return VLC_EGENERIC;
+
+            riff_len -= 8;
+            chnk_len = GetDWLE (chnk_hdr + 4);
+            if (riff_len < chnk_len)
+                return VLC_EGENERIC;
+            riff_len -= chnk_len;
+
+            if (!memcmp (chnk_hdr, "data", 4))
+                break; /* found! */
+
+            if (stream_Read (stream, NULL, chnk_len) < (ssize_t)chnk_len)
+                return VLC_EGENERIC;
+        }
+
+        /* Read real SMF header. Assume RIFF data chunk length is proper. */
+        if (stream_Peek (stream, &peek, 14) < 14)
+            return VLC_EGENERIC;
+    }
+
     if (memcmp (peek, "MThd\x00\x00\x00\x06", 8))
         return VLC_EGENERIC;
     peek += 8;




More information about the vlc-devel mailing list