gentlsrc: use GEV buffer timestamps if available for unix reference time

This commit is contained in:
Joshua M. Doe
2021-05-26 09:06:54 -04:00
parent 6c4eedde70
commit 765662aa82
3 changed files with 148 additions and 0 deletions

43
common/get_unix_ns.h Normal file
View File

@@ -0,0 +1,43 @@
#ifndef _GET_UNIX_NS_H_
#define _GET_UNIX_NS_H_
#include <gmodule.h>
typedef struct _MYFILETIME
{
guint32 dwLowDateTime;
guint32 dwHighDateTime;
} MYFILETIME;
typedef void (*GetSystemTimeFunc) (MYFILETIME * lpSystemTimeAsFileTime);
static guint64
get_unix_ns ()
{
MYFILETIME ftime;
LARGE_INTEGER ltime;
static GetSystemTimeFunc time_func = NULL;
if (!time_func) {
GModule *module;
module = g_module_open ("Kernel32.dll", G_MODULE_BIND_LAZY);
if (module) {
if (!g_module_symbol (module, "GetSystemTimePreciseAsFileTime",
(gpointer *) & time_func) || time_func == NULL) {
GST_WARNING
("Couldn't find GetSystemTimePreciseAsFileTime, falling back to GetSystemTimeAsFileTime");
if (!g_module_symbol (module, "GetSystemTimeAsFileTime",
(gpointer *) & time_func) || time_func == NULL) {
GST_WARNING
("Couldn't find GetSystemTimeAsFileTime, something is very wrong");
}
}
}
}
//GetSystemTimePreciseAsFileTime(&ftime);
time_func (&ftime);
ltime.HighPart = ftime.dwHighDateTime;
ltime.LowPart = ftime.dwLowDateTime;
ltime.QuadPart -= 11644473600000 * 10000;
return ltime.QuadPart * 100;
}
#endif /* _GET_UNIX_NS_H_ */