7 struct timeval epoch_time;
8 struct timespec monotonic_time;
10 gettimeofday(&epoch_time, NULL);
11 clock_gettime(CLOCK_MONOTONIC, &monotonic_time);
13 const int64_t uptime_ms =
14 monotonic_time.tv_sec * 1000 +
static_cast<int64_t
>(
15 std::round(monotonic_time.tv_nsec / 1000000.0));
16 const int64_t epoch_ms =
17 epoch_time.tv_sec * 1000 +
static_cast<int64_t
>(
18 std::round(epoch_time.tv_usec / 1000.0));
20 return static_cast<time_t
>((epoch_ms - uptime_ms) / 1000);
25 timespec img_timestamp;
27 int64_t buffer_time_us = (buffer_time.tv_sec * 1000000) + buffer_time.tv_usec;
28 buffer_time_us += epoch_time_shift_us;
30 img_timestamp.tv_sec = (buffer_time_us / 1000000);
31 img_timestamp.tv_nsec = (buffer_time_us % 1000000) * 1000;
41 r = ioctl(fd, request, arg);
43 }
while (-1 == r && EINTR == errno);
58 }
catch (std::out_of_range
const &) {
60 unsigned char clipped_val = val < 0 ? 0 : static_cast<unsigned char>(val);
61 return val > 255 ? 255 : clipped_val;