[PATCH 1/6] winecoreaudio: Introduce a helper to retrieve the time.

Huw Davies huw at codeweavers.com
Tue Nov 30 01:56:28 CST 2021


The motivation is that this will need to be called from a
non-Win32 thread and so shouldn't use the Win32 API.  An
added benefit is that it will eliminate the 16ms jitter
associated with GetTickCount().

The instance of the helper on the user-side is temporary.

Signed-off-by: Huw Davies <huw at codeweavers.com>
---
 dlls/winecoreaudio.drv/coremidi.c | 12 ++++++++++--
 dlls/winecoreaudio.drv/midi.c     | 13 +++++++++++--
 2 files changed, 21 insertions(+), 4 deletions(-)

diff --git a/dlls/winecoreaudio.drv/coremidi.c b/dlls/winecoreaudio.drv/coremidi.c
index 9dc9f452c29..2e92d9ac2cb 100644
--- a/dlls/winecoreaudio.drv/coremidi.c
+++ b/dlls/winecoreaudio.drv/coremidi.c
@@ -143,6 +143,14 @@ static void set_in_notify(struct notify_context *notify, struct midi_src *src, W
  *  CoreMIDI IO threaded callback,
  *  we can't call Wine debug channels, critical section or anything using NtCurrentTeb here.
  */
+static uint64_t get_time_ms(void)
+{
+    static mach_timebase_info_data_t timebase;
+
+    if (!timebase.denom) mach_timebase_info(&timebase);
+    return mach_absolute_time() / 1000000 * timebase.numer / timebase.denom;
+}
+
 static void midi_in_read_proc(const MIDIPacketList *pktlist, void *refCon, void *connRefCon)
 {
     CFMessagePortRef msg_port = CFMessagePortCreateRemote(kCFAllocatorDefault, midi_in_thread_port_name);
@@ -917,7 +925,7 @@ static DWORD midi_in_start(WORD dev_id)
         return MMSYSERR_BADDEVICEID;
     }
     srcs[dev_id].state = 1;
-    srcs[dev_id].startTime = NtGetTickCount();
+    srcs[dev_id].startTime = get_time_ms();
     return MMSYSERR_NOERROR;
 }
 
@@ -936,7 +944,7 @@ static DWORD midi_in_stop(WORD dev_id)
 
 static DWORD midi_in_reset(WORD dev_id, struct notify_context *notify)
 {
-    DWORD cur_time = NtGetTickCount();
+    DWORD cur_time = get_time_ms();
     DWORD err = MMSYSERR_NOERROR;
     struct midi_src *src;
     MIDIHDR *hdr;
diff --git a/dlls/winecoreaudio.drv/midi.c b/dlls/winecoreaudio.drv/midi.c
index dcb9a7e1b69..b3adb09886d 100644
--- a/dlls/winecoreaudio.drv/midi.c
+++ b/dlls/winecoreaudio.drv/midi.c
@@ -45,6 +45,7 @@
 
 WINE_DEFAULT_DEBUG_CHANNEL(midi);
 
+#include <mach/mach_time.h>
 #include <CoreAudio/CoreAudio.h>
 
 #define WINE_DEFINITIONS
@@ -61,6 +62,14 @@ static MIDIPortRef MIDIInPort = NULL;
 
 MIDISource *sources;
 
+static uint64_t get_time_ms(void)
+{
+    static mach_timebase_info_data_t timebase;
+
+    if (!timebase.denom) mach_timebase_info(&timebase);
+    return mach_absolute_time() / 1000000 * timebase.numer / timebase.denom;
+}
+
 static void notify_client(struct notify_context *notify)
 {
     TRACE("dev_id=%d msg=%d param1=%04lX param2=%04lX\n", notify->dev_id, notify->msg, notify->param_1, notify->param_2);
@@ -183,7 +192,7 @@ static CFDataRef MIDIIn_MessageHandler(CFMessagePortRef local, SInt32 msgid, CFD
                 }
 
                 midi_lock( TRUE );
-                currentTime = GetTickCount() - src->startTime;
+                currentTime = get_time_ms() - src->startTime;
 
                 while (len) {
                     LPMIDIHDR lpMidiHdr = src->lpQueueHdr;
@@ -218,7 +227,7 @@ static CFDataRef MIDIIn_MessageHandler(CFMessagePortRef local, SInt32 msgid, CFD
             }
 
             midi_lock( TRUE );
-            currentTime = GetTickCount() - src->startTime;
+            currentTime = get_time_ms() - src->startTime;
 
             while (pos < msg->length)
             {
-- 
2.23.0




More information about the wine-devel mailing list