From 17ea88b11424e60080e24f1a655dae68d6546b35 Mon Sep 17 00:00:00 2001 From: Hans Verkuil Date: Mon, 24 Feb 2014 15:53:49 +0100 Subject: [PATCH] v4l2-ctl: set timestamp for output buffers. When streaming to a VIDEO_OUTPUT device, and if the timestamp mask of the buffer is V4L2_BUF_FLAG_TIMESTAMP_COPY, then we need to set a timestamp. Signed-off-by: Hans Verkuil --- utils/v4l2-ctl/v4l2-ctl-streaming.cpp | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/utils/v4l2-ctl/v4l2-ctl-streaming.cpp b/utils/v4l2-ctl/v4l2-ctl-streaming.cpp index 4918fa9..70aaebf 100644 --- a/utils/v4l2-ctl/v4l2-ctl-streaming.cpp +++ b/utils/v4l2-ctl/v4l2-ctl-streaming.cpp @@ -81,6 +81,17 @@ void streaming_usage(void) ); } +static void setTimeStamp(struct v4l2_buffer &buf) +{ + struct timespec ts; + + if ((buf.flags & V4L2_BUF_FLAG_TIMESTAMP_MASK) != V4L2_BUF_FLAG_TIMESTAMP_COPY) + return; + clock_gettime(CLOCK_MONOTONIC, &ts); + buf.timestamp.tv_sec = ts.tv_sec; + buf.timestamp.tv_usec = ts.tv_nsec / 1000; +} + static const flag_def flags_def[] = { { V4L2_BUF_FLAG_MAPPED, "mapped" }, { V4L2_BUF_FLAG_QUEUED, "queued" }, @@ -429,6 +440,8 @@ static int do_setup_out_buffers(int fd, buffers &b, FILE *fin) if (!fin || !fill_buffer_from_file(b, buf.index, fin)) fill_buffer(b.bufs[i][0], &fmt.fmt.pix); } + if (V4L2_TYPE_IS_OUTPUT(buf.type)) + setTimeStamp(buf); if (doioctl(fd, VIDIOC_QBUF, &buf)) return -1; } @@ -579,6 +592,8 @@ static int do_handle_out(int fd, buffers &b, FILE *fin, } else { buf.bytesused = buf.length; } + if (V4L2_TYPE_IS_OUTPUT(buf.type)) + setTimeStamp(buf); if (test_ioctl(fd, VIDIOC_QBUF, &buf)) return -1; -- 2.7.4