[media] v4l: Helper function for obtaining timestamps
authorSakari Ailus <sakari.ailus@iki.fi>
Sat, 15 Sep 2012 10:51:47 +0000 (07:51 -0300)
committerMauro Carvalho Chehab <mchehab@redhat.com>
Fri, 21 Dec 2012 12:53:43 +0000 (10:53 -0200)
v4l2_get_timestamp() produces a monotonic timestamp but unlike
ktime_get_ts(), it uses struct timeval instead of struct timespec, saving
the drivers the conversion job when getting timestamps for v4l2_buffer's
timestamp field.

Signed-off-by: Sakari Ailus <sakari.ailus@iki.fi>
Acked-by: Hans Verkuil <hans.verkuil@cisco.com>
Signed-off-by: Mauro Carvalho Chehab <mchehab@redhat.com>
drivers/media/v4l2-core/v4l2-common.c
include/media/v4l2-common.h

index 380ddd89fa4c6f8d6c1bb1b612eeb97fa8420a9f..614316f9b7a47d2dd2111932ee109ef7fd1bb17e 100644 (file)
@@ -978,3 +978,13 @@ const struct v4l2_frmsize_discrete *v4l2_find_nearest_format(
        return best;
 }
 EXPORT_SYMBOL_GPL(v4l2_find_nearest_format);
+
+void v4l2_get_timestamp(struct timeval *tv)
+{
+       struct timespec ts;
+
+       ktime_get_ts(&ts);
+       tv->tv_sec = ts.tv_sec;
+       tv->tv_usec = ts.tv_nsec / NSEC_PER_USEC;
+}
+EXPORT_SYMBOL_GPL(v4l2_get_timestamp);
index 1a0b2db4c5d318c80b135d5a69b7f4b34659327c..ec7c9c00b256948f41c00d7c8315f59fa0e5e0d4 100644 (file)
@@ -225,4 +225,6 @@ bool v4l2_detect_gtf(unsigned frame_height, unsigned hfreq, unsigned vsync,
 
 struct v4l2_fract v4l2_calc_aspect_ratio(u8 hor_landscape, u8 vert_portrait);
 
+void v4l2_get_timestamp(struct timeval *tv);
+
 #endif /* V4L2_COMMON_H_ */