]> git.sesse.net Git - vlc/blobdiff - modules/demux/smf.c
qt4/macosx: fixed the embedded vout setting
[vlc] / modules / demux / smf.c
index df0b0f5135fd24cb780c5dbb898b5f774c9e330f..26a6e0e944b9c584943c55a050b58b710f23f4a1 100644 (file)
  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
  *****************************************************************************/
 
+#ifdef HAVE_CONFIG_H
+# include "config.h"
+#endif
+
 #include <vlc/vlc.h>
 #include <vlc_demux.h>
 #include <vlc_aout.h>
@@ -26,6 +30,9 @@
 #include <vlc_charset.h>
 #include <limits.h>
 
+#define TEMPO_MIN  20
+#define TEMPO_MAX 250 /* Beats per minute */
+
 static int  Open  (vlc_object_t *);
 static void Close (vlc_object_t *);
 
@@ -348,16 +355,16 @@ int HandleMeta (demux_t *p_demux, mtrk_t *tr)
                 msg_Dbg (p_demux, "tempo: %uus/qn -> %u BPM",
                          (unsigned)uspqn, tempo);
 
-                if (tempo < 20)
+                if (tempo < TEMPO_MIN)
                 {
-                    msg_Warn (p_demux, "tempo too slow -> 20 BPM");
-                    tempo = 20;
+                    msg_Warn (p_demux, "tempo too slow -> %u BPM", TEMPO_MIN);
+                    tempo = TEMPO_MIN;
                 }
                 else
-                if (tempo > 240)
+                if (tempo > TEMPO_MAX)
                 {
-                    msg_Warn (p_demux, "tempo too fast -> 240 BPM");
-                    tempo = 240;
+                    msg_Warn (p_demux, "tempo too fast -> %u BPM", TEMPO_MAX);
+                    tempo = TEMPO_MAX;
                 }
                 date_Change (&p_sys->pts, p_sys->ppqn * tempo, 60);
             }
@@ -366,13 +373,29 @@ int HandleMeta (demux_t *p_demux, mtrk_t *tr)
             break;
 
         case 0x54: /* SMPTE offset */
+            if (length == 5)
+                msg_Warn (p_demux, "SMPTE offset not implemented");
+            else
+                ret = -1;
+            break;
+
         case 0x58: /* Time signature */
+            if (length == 4)
+                ;
+            else
+                ret = -1;
+            break;
+
         case 0x59: /* Key signature */
-            msg_Warn (p_demux, "unimplemented SMF Meta Event type 0x%02X (%d bytes)",
-                      type, length);
+            if (length == 2)
+                ;
+            else
+                ret = -1;
             break;
 
         case 0x7f: /* Proprietary event */
+            msg_Dbg (p_demux, "ignored proprietary SMF Meta Event (%d bytes)",
+                     length);
             break;
 
         default:
@@ -421,7 +444,7 @@ int HandleMessage (demux_t *p_demux, mtrk_t *tr)
                 case 0xFF: /* SMF Meta Event */
                     if (HandleMeta (p_demux, tr))
                         return -1;
-                    /* We MUST NOT pass this event to forward. It would be
+                    /* We MUST NOT pass this event forward. It would be
                      * confused as a MIDI Reset real-time event. */
                     goto skip;
                 case 0xF1:
@@ -521,8 +544,24 @@ static int Demux (demux_t *p_demux)
             next_pulse = track->next;
     }
 
+    mtime_t cur_tick = (date_Get (&p_sys->pts) + 9999) / 10000, last_tick;
     if (next_pulse != UINT64_MAX)
-        date_Increment (&p_sys->pts, next_pulse - pulse);
+        last_tick = date_Increment (&p_sys->pts, next_pulse - pulse) / 10000;
+    else
+        last_tick = cur_tick + 1;
+
+    /* MIDI Tick emulation (ping the decider every 10ms) */
+    while (cur_tick < last_tick)
+    {
+        block_t *tick = block_New (p_demux, 1);
+        if (tick == NULL)
+            break;
+
+        tick->p_buffer[0] = 0xF9;
+        tick->i_dts = tick->i_pts = cur_tick++ * 10000;
+        es_out_Send (p_demux->out, p_sys->es, tick);
+    }
+
     p_sys->pulse = next_pulse;
 
     return 1;
@@ -534,5 +573,22 @@ static int Demux (demux_t *p_demux)
  *****************************************************************************/
 static int Control (demux_t *p_demux, int i_query, va_list args)
 {
-    return demux2_vaControlHelper (p_demux->s, 0, -1, 0, 1, i_query, args);
+    demux_sys_t *p_sys = p_demux->p_sys;
+
+    switch (i_query)
+    {
+        case DEMUX_GET_TIME:
+        {
+            *(va_arg (args, int64_t *)) = date_Get (&p_sys->pts);
+            return 0;
+        }
+#if 0
+        /* TODO: */
+        case DEMUX_SET_TIME:
+        case DEMUX_GET_POSITION:
+        case DEMUX_SET_POSITION:
+        case DEMUX_GET_LENGTH:
+#endif
+    }
+    return VLC_EGENERIC;
 }