| From 47e9c005788494a6410a3bdcb596cf36212658e2 Mon Sep 17 00:00:00 2001 |
| From: Hans Verkuil <hverkuil-cisco@xs4all.nl> |
| Date: Wed, 24 Oct 2018 06:50:34 -0400 |
| Subject: [PATCH] FROMGIT: media: videodev2.h: add v4l2_timeval_to_ns inline |
| function |
| |
| We want to be able to uniquely identify buffers for stateless |
| codecs. The internal timestamp (a u64) as stored internally in the |
| kernel is a suitable candidate for that, but in struct v4l2_buffer |
| it is represented as a struct timeval. |
| |
| Add a v4l2_timeval_to_ns() function that converts the struct timeval |
| into a u64 in the same way that the kernel does. This makes it possible |
| to use this u64 elsewhere as a unique identifier of the buffer. |
| |
| Since timestamps are also copied from the output buffer to the |
| corresponding capture buffer(s) by M2M devices, the u64 can be |
| used to refer to both output and capture buffers. |
| |
| The plan is that in the future we redesign struct v4l2_buffer and use |
| u64 for the timestamp instead of a struct timeval (which has lots of |
| problems with 32 vs 64 bit and y2038 layout changes), and then there |
| is no more need to use this function. |
| |
| BUG=chromium:902656 |
| TEST=Checked that kernel was building for Kukui. |
| |
| Signed-off-by: Hans Verkuil <hverkuil-cisco@xs4all.nl> |
| Signed-off-by: Mauro Carvalho Chehab <mchehab+samsung@kernel.org> |
| (cherry picked from commit c2eb8effb265ac5cdd960d8e61ecb931e9c767cd |
| git://linuxtv.org/media_tree.git master) |
| Signed-off-by: Alexandre Courbot <acourbot@chromium.org> |
| |
| Change-Id: Id70d70f5cf5c8a13c18958d9aafc10da72a4e136 |
| --- |
| include/uapi/linux/videodev2.h | 12 ++++++++++++ |
| 1 file changed, 12 insertions(+) |
| |
| diff --git a/include/uapi/linux/videodev2.h b/include/uapi/linux/videodev2.h |
| index e3e14c8781334..5772274b115bb 100644 |
| --- a/include/uapi/linux/videodev2.h |
| +++ b/include/uapi/linux/videodev2.h |
| @@ -966,6 +966,18 @@ struct v4l2_buffer { |
| }; |
| }; |
| |
| +/** |
| + * v4l2_timeval_to_ns - Convert timeval to nanoseconds |
| + * @ts: pointer to the timeval variable to be converted |
| + * |
| + * Returns the scalar nanosecond representation of the timeval |
| + * parameter. |
| + */ |
| +static inline __u64 v4l2_timeval_to_ns(const struct timeval *tv) |
| +{ |
| + return (__u64)tv->tv_sec * 1000000000ULL + tv->tv_usec * 1000; |
| +} |
| + |
| /* Flags for 'flags' field */ |
| /* Buffer is mapped (flag) */ |
| #define V4L2_BUF_FLAG_MAPPED 0x00000001 |
| -- |
| 2.20.1.321.g9e740568ce-goog |
| |