diff --git a/src/events.c b/src/events.c
index d9b0ca0..b9c6f32 100644
--- a/src/events.c
+++ b/src/events.c
@@ -140,6 +140,9 @@ bool akvcam_events_enqueue(akvcam_events_t self,
const struct v4l2_event *event)
{
struct v4l2_event *qevent;
+#if LINUX_VERSION_CODE >= KERNEL_VERSION(5, 6, 0)
+ struct timespec64 ts;
+#endif
if (event->type != V4L2_EVENT_FRAME_SYNC) {
// Check if someone is subscribed to this event.
@@ -153,7 +156,13 @@ bool akvcam_events_enqueue(akvcam_events_t self,
qevent = akvcam_rbuffer_queue(self->events, event);
qevent->sequence = self->sequence++;
+#if LINUX_VERSION_CODE < KERNEL_VERSION(5, 6, 0)
ktime_get_ts(&qevent->timestamp);
+#else
+ ktime_get_ts64(&ts);
+ qevent->timestamp.tv_sec = ts.tv_sec;
+ qevent->timestamp.tv_nsec = ts.tv_nsec;
+#endif
memset(&qevent->reserved, 0, 8 * sizeof(__u32));
// Inform about the new event.
diff --git a/src/utils.c b/src/utils.c
index 06390f0..4465322 100644
--- a/src/utils.c
+++ b/src/utils.c
@@ -273,6 +273,7 @@ void akvcam_replace(char *str, char from, char to)
*str = to;
}
+#if LINUX_VERSION_CODE < KERNEL_VERSION(5, 6, 0)
void akvcam_get_timestamp(struct timeval *tv)
{
struct timespec ts;
@@ -280,3 +281,12 @@ void akvcam_get_timestamp(struct timeval *tv)
tv->tv_sec = ts.tv_sec;
tv->tv_usec = ts.tv_nsec / NSEC_PER_USEC;
}
+#else
+void akvcam_get_timestamp(struct __kernel_v4l2_timeval *tv)
+{
+ struct timespec64 ts;
+ ktime_get_ts64(&ts);
+ tv->tv_sec = ts.tv_sec;
+ tv->tv_usec = ts.tv_nsec / NSEC_PER_USEC;
+}
+#endif
diff --git a/src/utils.h b/src/utils.h
index 15671bd..a2d24c0 100644
--- a/src/utils.h
+++ b/src/utils.h
@@ -21,6 +21,9 @@
#include <linux/types.h>
#include <linux/version.h>
+#if LINUX_VERSION_CODE >= KERNEL_VERSION(5, 6, 0)
+#include <linux/videodev2.h>
+#endif
#define UNUSED(x) (void)(x)
#define AKVCAM_MAX_STRING_SIZE 1024
@@ -98,6 +101,10 @@ char *akvcam_strip_str_sub(const char *str,
char *akvcam_strip_move_str(char *str, AKVCAM_MEMORY_TYPE type);
size_t akvcam_str_count(const char *str, char c);
void akvcam_replace(char *str, char from, char to);
+#if LINUX_VERSION_CODE < KERNEL_VERSION(5, 6, 0)
void akvcam_get_timestamp(struct timeval *tv);
+#else
+void akvcam_get_timestamp(struct __kernel_v4l2_timeval *tv);
+#endif
#endif // AKVCAM_UTILS_H
Comments