linux-media.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH v2 1/9] Provide -Q option for setting the queue type
@ 2014-04-10 22:06 Sakari Ailus
  2014-04-10 22:06 ` [PATCH v2 2/9] Zero dev in main() Sakari Ailus
                   ` (8 more replies)
  0 siblings, 9 replies; 10+ messages in thread
From: Sakari Ailus @ 2014-04-10 22:06 UTC (permalink / raw)
  To: linux-media; +Cc: laurent.pinchart

Instead of guessing the queue type, allow setting it explicitly.

Signed-off-by: Sakari Ailus <sakari.ailus@iki.fi>
---
 yavta.c |   18 ++++++++++++++++--
 1 file changed, 16 insertions(+), 2 deletions(-)

diff --git a/yavta.c b/yavta.c
index 739463d..d7bccfd 100644
--- a/yavta.c
+++ b/yavta.c
@@ -1501,6 +1501,8 @@ static void usage(const char *argv0)
 	printf("-n, --nbufs n			Set the number of video buffers\n");
 	printf("-p, --pause			Pause before starting the video stream\n");
 	printf("-q, --quality n			MJPEG quality (0-100)\n");
+	printf("-Q, --queue-type		Buffer queue type (\"capture\", \"overlay\" or a\n");
+	printf("                                number)\n");
 	printf("-r, --get-control ctrl		Get control 'ctrl'\n");
 	printf("-R, --realtime=[priority]	Enable realtime RR scheduling\n");
 	printf("-s, --size WxH			Set the frame size\n");
@@ -1543,6 +1545,7 @@ static struct option opts[] = {
 	{"offset", 1, 0, OPT_USERPTR_OFFSET},
 	{"pause", 0, 0, 'p'},
 	{"quality", 1, 0, 'q'},
+	{"queue-type", 1, 0, 'Q'},
 	{"get-control", 1, 0, 'r'},
 	{"requeue-last", 0, 0, OPT_REQUEUE_LAST},
 	{"realtime", 2, 0, 'R'},
@@ -1564,7 +1567,7 @@ int main(int argc, char *argv[])
 
 	/* Options parsings */
 	const struct v4l2_format_info *info;
-	int do_file = 0, do_capture = 0, do_pause = 0;
+	int do_file = 0, do_capture = 0, do_pause = 0, queue_type = -1;
 	int do_set_time_per_frame = 0;
 	int do_enum_formats = 0, do_set_format = 0;
 	int do_enum_inputs = 0, do_set_input = 0;
@@ -1600,7 +1603,7 @@ int main(int argc, char *argv[])
 	unsigned int rt_priority = 1;
 
 	opterr = 0;
-	while ((c = getopt_long(argc, argv, "c::Cd:f:F::hi:Iln:pq:r:R::s:t:uw:", opts, NULL)) != -1) {
+	while ((c = getopt_long(argc, argv, "c::Cd:f:F::hi:Iln:pq:Q:r:R::s:t:uw:", opts, NULL)) != -1) {
 
 		switch (c) {
 		case 'c':
@@ -1652,6 +1655,14 @@ int main(int argc, char *argv[])
 		case 'q':
 			quality = atoi(optarg);
 			break;
+		case 'Q':
+			if (!strcmp(optarg, "capture"))
+				queue_type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
+			else if (!strcmp(optarg, "output"))
+				queue_type = V4L2_BUF_TYPE_VIDEO_OUTPUT;
+			else
+				queue_type = atoi(optarg);
+			break;
 		case 'r':
 			ctrl_name = strtol(optarg, &endptr, 0);
 			if (*endptr != 0) {
@@ -1761,6 +1772,9 @@ int main(int argc, char *argv[])
 	if (dev.type == (enum v4l2_buf_type)-1)
 		no_query = 1;
 
+	if (queue_type != -1)
+		dev.type = queue_type;
+
 	dev.memtype = memtype;
 
 	if (do_get_control) {
-- 
1.7.10.4


^ permalink raw reply related	[flat|nested] 10+ messages in thread

* [PATCH v2 2/9] Zero dev in main()
  2014-04-10 22:06 [PATCH v2 1/9] Provide -Q option for setting the queue type Sakari Ailus
@ 2014-04-10 22:06 ` Sakari Ailus
  2014-04-10 22:06 ` [PATCH v2 3/9] Use int for buffer queue type Sakari Ailus
                   ` (7 subsequent siblings)
  8 siblings, 0 replies; 10+ messages in thread
From: Sakari Ailus @ 2014-04-10 22:06 UTC (permalink / raw)
  To: linux-media; +Cc: laurent.pinchart

This is necessary since video_open() may not be always called soon

Signed-off-by: Sakari Ailus <sakari.ailus@iki.fi>
---
 yavta.c |    3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)

diff --git a/yavta.c b/yavta.c
index d7bccfd..18e1709 100644
--- a/yavta.c
+++ b/yavta.c
@@ -226,7 +226,6 @@ static int video_open(struct device *dev, const char *devname, int no_query)
 	unsigned int capabilities;
 	int ret;
 
-	memset(dev, 0, sizeof *dev);
 	dev->fd = -1;
 	dev->memtype = V4L2_MEMORY_MMAP;
 	dev->buffers = NULL;
@@ -1562,7 +1561,7 @@ static struct option opts[] = {
 int main(int argc, char *argv[])
 {
 	struct sched_param sched;
-	struct device dev;
+	struct device dev = { 0 };
 	int ret;
 
 	/* Options parsings */
-- 
1.7.10.4


^ permalink raw reply related	[flat|nested] 10+ messages in thread

* [PATCH v2 3/9] Use int for buffer queue type
  2014-04-10 22:06 [PATCH v2 1/9] Provide -Q option for setting the queue type Sakari Ailus
  2014-04-10 22:06 ` [PATCH v2 2/9] Zero dev in main() Sakari Ailus
@ 2014-04-10 22:06 ` Sakari Ailus
  2014-04-10 22:06 ` [PATCH v2 4/9] Separate querying capabilities and determining " Sakari Ailus
                   ` (6 subsequent siblings)
  8 siblings, 0 replies; 10+ messages in thread
From: Sakari Ailus @ 2014-04-10 22:06 UTC (permalink / raw)
  To: linux-media; +Cc: laurent.pinchart

This makes comparisons nicer.

Signed-off-by: Sakari Ailus <sakari.ailus@iki.fi>
---
 yavta.c |    2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/yavta.c b/yavta.c
index 18e1709..5a35bab 100644
--- a/yavta.c
+++ b/yavta.c
@@ -64,7 +64,7 @@ struct device
 {
 	int fd;
 
-	enum v4l2_buf_type type;
+	int type; /* buffer queue type */
 	enum v4l2_memory memtype;
 	unsigned int nbufs;
 	struct buffer *buffers;
-- 
1.7.10.4


^ permalink raw reply related	[flat|nested] 10+ messages in thread

* [PATCH v2 4/9] Separate querying capabilities and determining buffer queue type
  2014-04-10 22:06 [PATCH v2 1/9] Provide -Q option for setting the queue type Sakari Ailus
  2014-04-10 22:06 ` [PATCH v2 2/9] Zero dev in main() Sakari Ailus
  2014-04-10 22:06 ` [PATCH v2 3/9] Use int for buffer queue type Sakari Ailus
@ 2014-04-10 22:06 ` Sakari Ailus
  2014-04-10 22:06 ` [PATCH v2 5/9] Allow passing file descriptors to yavta Sakari Ailus
                   ` (5 subsequent siblings)
  8 siblings, 0 replies; 10+ messages in thread
From: Sakari Ailus @ 2014-04-10 22:06 UTC (permalink / raw)
  To: linux-media; +Cc: laurent.pinchart

Signed-off-by: Sakari Ailus <sakari.ailus@iki.fi>
---
 yavta.c |   78 ++++++++++++++++++++++++++++++++++-----------------------------
 1 file changed, 42 insertions(+), 36 deletions(-)

diff --git a/yavta.c b/yavta.c
index 5a35bab..12a6719 100644
--- a/yavta.c
+++ b/yavta.c
@@ -220,12 +220,8 @@ static const char *v4l2_format_name(unsigned int fourcc)
 	return name;
 }
 
-static int video_open(struct device *dev, const char *devname, int no_query)
+static int video_open(struct device *dev, const char *devname)
 {
-	struct v4l2_capability cap;
-	unsigned int capabilities;
-	int ret;
-
 	dev->fd = -1;
 	dev->memtype = V4L2_MEMORY_MMAP;
 	dev->buffers = NULL;
@@ -240,39 +236,46 @@ static int video_open(struct device *dev, const char *devname, int no_query)
 
 	printf("Device %s opened.\n", devname);
 
-	if (no_query) {
-		/* Assume capture device. */
-		dev->type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
-		return 0;
-	}
+	return 0;
+}
+
+static int video_querycap(struct device *dev, unsigned int *capabilities)
+{
+	struct v4l2_capability cap;
+	int ret;
 
 	memset(&cap, 0, sizeof cap);
 	ret = ioctl(dev->fd, VIDIOC_QUERYCAP, &cap);
 	if (ret < 0)
 		return 0;
 
-	capabilities = cap.capabilities & V4L2_CAP_DEVICE_CAPS
+	*capabilities = cap.capabilities & V4L2_CAP_DEVICE_CAPS
 		     ? cap.device_caps : cap.capabilities;
 
-	if (capabilities & V4L2_CAP_VIDEO_CAPTURE_MPLANE)
+	printf("Device `%s' on `%s' is a video %s (%s mplanes) device.\n",
+		cap.card, cap.bus_info,
+		video_is_capture(dev) ? "capture" : "output",
+		video_is_mplane(dev) ? "with" : "without");
+	return 0;
+}
+
+static int video_set_queue_type(struct device *dev, unsigned int capabilities)
+{
+	if (dev->type != -1) {
+	} else if (capabilities & V4L2_CAP_VIDEO_CAPTURE_MPLANE) {
 		dev->type = V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE;
-	else if (capabilities & V4L2_CAP_VIDEO_OUTPUT_MPLANE)
+	} else if (capabilities & V4L2_CAP_VIDEO_OUTPUT_MPLANE) {
 		dev->type = V4L2_BUF_TYPE_VIDEO_OUTPUT_MPLANE;
-	else if (capabilities & V4L2_CAP_VIDEO_CAPTURE)
+	} else if (capabilities & V4L2_CAP_VIDEO_CAPTURE) {
 		dev->type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
-	else if (capabilities & V4L2_CAP_VIDEO_OUTPUT)
+	} else if (capabilities & V4L2_CAP_VIDEO_OUTPUT) {
 		dev->type = V4L2_BUF_TYPE_VIDEO_OUTPUT;
-	else {
-		printf("Error opening device %s: neither video capture "
-			"nor video output supported.\n", devname);
-		close(dev->fd);
+	} else {
+		printf("Device supports neither capture nor output.\n");
 		return -EINVAL;
 	}
+	printf("Using buffer queue type %d\n", dev->type);
 
-	printf("Device `%s' on `%s' is a video %s (%s mplanes) device.\n",
-		cap.card, cap.bus_info,
-		video_is_capture(dev) ? "capture" : "output",
-		video_is_mplane(dev) ? "with" : "without");
 	return 0;
 }
 
@@ -1561,12 +1564,14 @@ static struct option opts[] = {
 int main(int argc, char *argv[])
 {
 	struct sched_param sched;
-	struct device dev = { 0 };
+	struct device dev = { .type = -1 };
 	int ret;
 
 	/* Options parsings */
 	const struct v4l2_format_info *info;
-	int do_file = 0, do_capture = 0, do_pause = 0, queue_type = -1;
+	/* Use video capture by default if query isn't done. */
+	unsigned int capabilities = V4L2_CAP_VIDEO_CAPTURE;
+	int do_file = 0, do_capture = 0, do_pause = 0;
 	int do_set_time_per_frame = 0;
 	int do_enum_formats = 0, do_set_format = 0;
 	int do_enum_inputs = 0, do_set_input = 0;
@@ -1656,11 +1661,11 @@ int main(int argc, char *argv[])
 			break;
 		case 'Q':
 			if (!strcmp(optarg, "capture"))
-				queue_type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
+				dev.type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
 			else if (!strcmp(optarg, "output"))
-				queue_type = V4L2_BUF_TYPE_VIDEO_OUTPUT;
+				dev.type = V4L2_BUF_TYPE_VIDEO_OUTPUT;
 			else
-				queue_type = atoi(optarg);
+				dev.type = atoi(optarg);
 			break;
 		case 'r':
 			ctrl_name = strtol(optarg, &endptr, 0);
@@ -1761,18 +1766,19 @@ int main(int argc, char *argv[])
 	if (!do_file)
 		filename = NULL;
 
-	/* Open the video device. If the device type isn't recognized, set the
-	 * --no-query option to avoid querying V4L2 subdevs.
-	 */
-	ret = video_open(&dev, argv[optind], no_query);
+	ret = video_open(&dev, argv[optind]);
 	if (ret < 0)
 		return 1;
 
-	if (dev.type == (enum v4l2_buf_type)-1)
-		no_query = 1;
+	if (!no_query) {
+		ret = video_querycap(&dev, &capabilities);
+		if (ret < 0)
+			return 1;
+	}
 
-	if (queue_type != -1)
-		dev.type = queue_type;
+	ret = video_set_queue_type(&dev, capabilities);
+	if (ret < 0)
+		return 1;
 
 	dev.memtype = memtype;
 
-- 
1.7.10.4


^ permalink raw reply related	[flat|nested] 10+ messages in thread

* [PATCH v2 5/9] Allow passing file descriptors to yavta
  2014-04-10 22:06 [PATCH v2 1/9] Provide -Q option for setting the queue type Sakari Ailus
                   ` (2 preceding siblings ...)
  2014-04-10 22:06 ` [PATCH v2 4/9] Separate querying capabilities and determining " Sakari Ailus
@ 2014-04-10 22:06 ` Sakari Ailus
  2014-04-10 22:06 ` [PATCH v2 6/9] Timestamp source for output buffers Sakari Ailus
                   ` (4 subsequent siblings)
  8 siblings, 0 replies; 10+ messages in thread
From: Sakari Ailus @ 2014-04-10 22:06 UTC (permalink / raw)
  To: linux-media; +Cc: laurent.pinchart

Signed-off-by: Sakari Ailus <sakari.ailus@iki.fi>
---
 yavta.c |   46 +++++++++++++++++++++++++++++++---------------
 1 file changed, 31 insertions(+), 15 deletions(-)

diff --git a/yavta.c b/yavta.c
index 12a6719..6f80311 100644
--- a/yavta.c
+++ b/yavta.c
@@ -63,6 +63,7 @@ struct buffer
 struct device
 {
 	int fd;
+	int opened;
 
 	int type; /* buffer queue type */
 	enum v4l2_memory memtype;
@@ -222,11 +223,6 @@ static const char *v4l2_format_name(unsigned int fourcc)
 
 static int video_open(struct device *dev, const char *devname)
 {
-	dev->fd = -1;
-	dev->memtype = V4L2_MEMORY_MMAP;
-	dev->buffers = NULL;
-	dev->type = (enum v4l2_buf_type)-1;
-
 	dev->fd = open(devname, O_RDWR);
 	if (dev->fd < 0) {
 		printf("Error opening device %s: %s (%d).\n", devname,
@@ -236,6 +232,8 @@ static int video_open(struct device *dev, const char *devname)
 
 	printf("Device %s opened.\n", devname);
 
+	dev->opened = 1;
+
 	return 0;
 }
 
@@ -287,7 +285,8 @@ static void video_close(struct device *dev)
 		free(dev->pattern[i]);
 
 	free(dev->buffers);
-	close(dev->fd);
+	if (dev->opened)
+		close(dev->fd);
 }
 
 static unsigned int get_control_type(struct device *dev, unsigned int id)
@@ -1513,6 +1512,7 @@ static void usage(const char *argv0)
 	printf("-w, --set-control 'ctrl value'	Set control 'ctrl' to 'value'\n");
 	printf("    --enum-formats		Enumerate formats\n");
 	printf("    --enum-inputs		Enumerate inputs\n");
+	printf("    --fd                        Use a numeric file descriptor insted of a device\n");
 	printf("    --no-query			Don't query capabilities on open\n");
 	printf("    --offset			User pointer buffer offset from page start\n");
 	printf("    --requeue-last		Requeue the last buffers before streamoff\n");
@@ -1529,6 +1529,7 @@ static void usage(const char *argv0)
 #define OPT_USERPTR_OFFSET	261
 #define OPT_REQUEUE_LAST	262
 #define OPT_STRIDE		263
+#define OPT_FD			264
 
 static struct option opts[] = {
 	{"capture", 2, 0, 'c'},
@@ -1536,6 +1537,7 @@ static struct option opts[] = {
 	{"delay", 1, 0, 'd'},
 	{"enum-formats", 0, 0, OPT_ENUM_FORMATS},
 	{"enum-inputs", 0, 0, OPT_ENUM_INPUTS},
+	{"fd", 1, 0, OPT_FD},
 	{"file", 2, 0, 'F'},
 	{"fill-frames", 0, 0, 'I'},
 	{"format", 1, 0, 'f'},
@@ -1564,7 +1566,11 @@ static struct option opts[] = {
 int main(int argc, char *argv[])
 {
 	struct sched_param sched;
-	struct device dev = { .type = -1 };
+	struct device dev = {
+		.fd = -1,
+		.memtype = V4L2_MEMORY_MMAP,
+		.type = -1,
+	};
 	int ret;
 
 	/* Options parsings */
@@ -1728,6 +1734,14 @@ int main(int argc, char *argv[])
 		case OPT_ENUM_INPUTS:
 			do_enum_inputs = 1;
 			break;
+		case OPT_FD:
+			dev.fd = atoi(optarg);
+			if (dev.fd < 0) {
+				printf("Bad file descriptor %d\n", dev.fd);
+				return 1;
+			}
+			printf("Using file descriptor %d\n", dev.fd);
+			break;
 		case OPT_NO_QUERY:
 			no_query = 1;
 			break;
@@ -1758,17 +1772,19 @@ int main(int argc, char *argv[])
 		return 1;
 	}
 
-	if (optind >= argc) {
-		usage(argv[0]);
-		return 1;
-	}
-
 	if (!do_file)
 		filename = NULL;
 
-	ret = video_open(&dev, argv[optind]);
-	if (ret < 0)
-		return 1;
+	if (dev.fd == -1) {
+		if (optind >= argc) {
+			usage(argv[0]);
+			return 1;
+		} else {
+			ret = video_open(&dev, argv[optind]);
+			if (ret < 0)
+				return 1;
+		}
+	}
 
 	if (!no_query) {
 		ret = video_querycap(&dev, &capabilities);
-- 
1.7.10.4


^ permalink raw reply related	[flat|nested] 10+ messages in thread

* [PATCH v2 6/9] Timestamp source for output buffers
  2014-04-10 22:06 [PATCH v2 1/9] Provide -Q option for setting the queue type Sakari Ailus
                   ` (3 preceding siblings ...)
  2014-04-10 22:06 ` [PATCH v2 5/9] Allow passing file descriptors to yavta Sakari Ailus
@ 2014-04-10 22:06 ` Sakari Ailus
  2014-04-10 22:06 ` [PATCH v2 7/9] Print timestamp type and source for dequeued buffers Sakari Ailus
                   ` (3 subsequent siblings)
  8 siblings, 0 replies; 10+ messages in thread
From: Sakari Ailus @ 2014-04-10 22:06 UTC (permalink / raw)
  To: linux-media; +Cc: laurent.pinchart

Signed-off-by: Sakari Ailus <sakari.ailus@iki.fi>
---
 yavta.c |   17 +++++++++++++++++
 1 file changed, 17 insertions(+)

diff --git a/yavta.c b/yavta.c
index 6f80311..a2e0666 100644
--- a/yavta.c
+++ b/yavta.c
@@ -72,6 +72,7 @@ struct device
 
 	unsigned int width;
 	unsigned int height;
+	uint32_t buffer_output_flags;
 
 	unsigned char num_planes;
 	struct v4l2_plane_pix_format plane_fmt[VIDEO_MAX_PLANES];
@@ -809,6 +810,9 @@ static int video_queue_buffer(struct device *dev, int index, enum buffer_fill_mo
 	buf.type = dev->type;
 	buf.memory = dev->memtype;
 
+	if (dev->type == V4L2_BUF_TYPE_VIDEO_OUTPUT)
+		buf.flags = dev->buffer_output_flags;
+
 	if (video_is_mplane(dev)) {
 		buf.m.planes = planes;
 		buf.length = dev->num_planes;
@@ -1516,6 +1520,7 @@ static void usage(const char *argv0)
 	printf("    --no-query			Don't query capabilities on open\n");
 	printf("    --offset			User pointer buffer offset from page start\n");
 	printf("    --requeue-last		Requeue the last buffers before streamoff\n");
+	printf("    --timestamp-source		Set timestamp source on output buffers [eof, soe]\n");
 	printf("    --skip n			Skip the first n frames\n");
 	printf("    --sleep-forever		Sleep forever after configuring the device\n");
 	printf("    --stride value		Line stride in bytes\n");
@@ -1530,6 +1535,7 @@ static void usage(const char *argv0)
 #define OPT_REQUEUE_LAST	262
 #define OPT_STRIDE		263
 #define OPT_FD			264
+#define OPT_TSTAMP_SRC		265
 
 static struct option opts[] = {
 	{"capture", 2, 0, 'c'},
@@ -1559,6 +1565,7 @@ static struct option opts[] = {
 	{"sleep-forever", 0, 0, OPT_SLEEP_FOREVER},
 	{"stride", 1, 0, OPT_STRIDE},
 	{"time-per-frame", 1, 0, 't'},
+	{"timestamp-source", 1, 0, OPT_TSTAMP_SRC},
 	{"userptr", 0, 0, 'u'},
 	{0, 0, 0, 0}
 };
@@ -1757,6 +1764,16 @@ int main(int argc, char *argv[])
 		case OPT_STRIDE:
 			stride = atoi(optarg);
 			break;
+		case OPT_TSTAMP_SRC:
+			if (!strcmp(optarg, "eof")) {
+				dev.buffer_output_flags |= V4L2_BUF_FLAG_TSTAMP_SRC_EOF;
+			} else if (!strcmp(optarg, "soe")) {
+				dev.buffer_output_flags |= V4L2_BUF_FLAG_TSTAMP_SRC_SOE;
+			} else {
+				printf("Invalid timestamp source %s\n", optarg);
+				return 1;
+			}
+			break;
 		case OPT_USERPTR_OFFSET:
 			userptr_offset = atoi(optarg);
 			break;
-- 
1.7.10.4


^ permalink raw reply related	[flat|nested] 10+ messages in thread

* [PATCH v2 7/9] Print timestamp type and source for dequeued buffers
  2014-04-10 22:06 [PATCH v2 1/9] Provide -Q option for setting the queue type Sakari Ailus
                   ` (4 preceding siblings ...)
  2014-04-10 22:06 ` [PATCH v2 6/9] Timestamp source for output buffers Sakari Ailus
@ 2014-04-10 22:06 ` Sakari Ailus
  2014-04-10 22:06 ` [PATCH v2 8/9] Support copy timestamps Sakari Ailus
                   ` (2 subsequent siblings)
  8 siblings, 0 replies; 10+ messages in thread
From: Sakari Ailus @ 2014-04-10 22:06 UTC (permalink / raw)
  To: linux-media; +Cc: laurent.pinchart

Signed-off-by: Sakari Ailus <sakari.ailus@iki.fi>
---
 yavta.c |   52 ++++++++++++++++++++++++++++++----------------------
 1 file changed, 30 insertions(+), 22 deletions(-)

diff --git a/yavta.c b/yavta.c
index a2e0666..9810dcf 100644
--- a/yavta.c
+++ b/yavta.c
@@ -659,6 +659,30 @@ static void video_buffer_fill_userptr(struct device *dev, struct buffer *buffer,
 		v4l2buf->m.planes[i].m.userptr = (unsigned long)buffer->mem[i];
 }
 
+static void get_ts_flags(uint32_t flags, const char **ts_type, const char **ts_source)
+{
+	switch (flags & V4L2_BUF_FLAG_TIMESTAMP_MASK) {
+	case V4L2_BUF_FLAG_TIMESTAMP_UNKNOWN:
+		*ts_type = "unknown";
+		break;
+	case V4L2_BUF_FLAG_TIMESTAMP_MONOTONIC:
+		*ts_type = "monotonic";
+		break;
+	default:
+		*ts_type = "invalid";
+	}
+	switch (flags & V4L2_BUF_FLAG_TSTAMP_SRC_MASK) {
+	case V4L2_BUF_FLAG_TSTAMP_SRC_EOF:
+		*ts_source = "EoF";
+		break;
+	case V4L2_BUF_FLAG_TSTAMP_SRC_SOE:
+		*ts_source = "SoE";
+		break;
+	default:
+		*ts_source = "invalid";
+	}
+}
+
 static int video_alloc_buffers(struct device *dev, int nbufs,
 	unsigned int offset, unsigned int padding)
 {
@@ -706,26 +730,7 @@ static int video_alloc_buffers(struct device *dev, int nbufs,
 				strerror(errno), errno);
 			return ret;
 		}
-		switch (buf.flags & V4L2_BUF_FLAG_TIMESTAMP_MASK) {
-		case V4L2_BUF_FLAG_TIMESTAMP_UNKNOWN:
-			ts_type = "unknown";
-			break;
-		case V4L2_BUF_FLAG_TIMESTAMP_MONOTONIC:
-			ts_type = "monotonic";
-			break;
-		default:
-			ts_type = "invalid";
-		}
-		switch (buf.flags & V4L2_BUF_FLAG_TSTAMP_SRC_MASK) {
-		case V4L2_BUF_FLAG_TSTAMP_SRC_EOF:
-			ts_source = "EoF";
-			break;
-		case V4L2_BUF_FLAG_TSTAMP_SRC_SOE:
-			ts_source = "SoE";
-			break;
-		default:
-			ts_source = "invalid";
-		}
+		get_ts_flags(buf.flags, &ts_type, &ts_source);
 		printf("length: %u offset: %u timestamp type/source: %s/%s\n",
 		       buf.length, buf.m.offset, ts_type, ts_source);
 
@@ -1393,6 +1398,7 @@ static int video_do_capture(struct device *dev, unsigned int nframes,
 	last.tv_usec = start.tv_nsec / 1000;
 
 	for (i = 0; i < nframes; ++i) {
+		const char *ts_type, *ts_source;
 		/* Dequeue a buffer. */
 		memset(&buf, 0, sizeof buf);
 		memset(planes, 0, sizeof planes);
@@ -1425,10 +1431,12 @@ static int video_do_capture(struct device *dev, unsigned int nframes,
 		fps = fps ? 1000000.0 / fps : 0.0;
 
 		clock_gettime(CLOCK_MONOTONIC, &ts);
-		printf("%u (%u) [%c] %u %u bytes %ld.%06ld %ld.%06ld %.3f fps\n", i, buf.index,
+		get_ts_flags(buf.flags, &ts_type, &ts_source);
+		printf("%u (%u) [%c] %u %u bytes %ld.%06ld %ld.%06ld %.3f fps tstamp type/src %s/%s\n", i, buf.index,
 			(buf.flags & V4L2_BUF_FLAG_ERROR) ? 'E' : '-',
 			buf.sequence, buf.bytesused, buf.timestamp.tv_sec,
-			buf.timestamp.tv_usec, ts.tv_sec, ts.tv_nsec/1000, fps);
+			buf.timestamp.tv_usec, ts.tv_sec, ts.tv_nsec/1000, fps,
+			ts_type, ts_source);
 
 		last = buf.timestamp;
 
-- 
1.7.10.4


^ permalink raw reply related	[flat|nested] 10+ messages in thread

* [PATCH v2 8/9] Support copy timestamps
  2014-04-10 22:06 [PATCH v2 1/9] Provide -Q option for setting the queue type Sakari Ailus
                   ` (5 preceding siblings ...)
  2014-04-10 22:06 ` [PATCH v2 7/9] Print timestamp type and source for dequeued buffers Sakari Ailus
@ 2014-04-10 22:06 ` Sakari Ailus
  2014-04-10 22:06 ` [PATCH v2 9/9] Set timestamp for output buffers if the timestamp type is copy Sakari Ailus
  2014-04-10 22:22 ` [PATCH v2 1/9] Provide -Q option for setting the queue type Sakari Ailus
  8 siblings, 0 replies; 10+ messages in thread
From: Sakari Ailus @ 2014-04-10 22:06 UTC (permalink / raw)
  To: linux-media; +Cc: laurent.pinchart

Signed-off-by: Sakari Ailus <sakari.ailus@iki.fi>
---
 yavta.c |    3 +++
 1 file changed, 3 insertions(+)

diff --git a/yavta.c b/yavta.c
index 9810dcf..124dd1d 100644
--- a/yavta.c
+++ b/yavta.c
@@ -668,6 +668,9 @@ static void get_ts_flags(uint32_t flags, const char **ts_type, const char **ts_s
 	case V4L2_BUF_FLAG_TIMESTAMP_MONOTONIC:
 		*ts_type = "monotonic";
 		break;
+	case V4L2_BUF_FLAG_TIMESTAMP_COPY:
+		*ts_type = "copy";
+		break;
 	default:
 		*ts_type = "invalid";
 	}
-- 
1.7.10.4


^ permalink raw reply related	[flat|nested] 10+ messages in thread

* [PATCH v2 9/9] Set timestamp for output buffers if the timestamp type is copy
  2014-04-10 22:06 [PATCH v2 1/9] Provide -Q option for setting the queue type Sakari Ailus
                   ` (6 preceding siblings ...)
  2014-04-10 22:06 ` [PATCH v2 8/9] Support copy timestamps Sakari Ailus
@ 2014-04-10 22:06 ` Sakari Ailus
  2014-04-10 22:22 ` [PATCH v2 1/9] Provide -Q option for setting the queue type Sakari Ailus
  8 siblings, 0 replies; 10+ messages in thread
From: Sakari Ailus @ 2014-04-10 22:06 UTC (permalink / raw)
  To: linux-media; +Cc: laurent.pinchart

Copy timestamp type will mean the timestamp is be copied from the source to
the destination buffer on mem-to-mem devices.

Signed-off-by: Sakari Ailus <sakari.ailus@iki.fi>
---
 yavta.c |   12 +++++++++++-
 1 file changed, 11 insertions(+), 1 deletion(-)

diff --git a/yavta.c b/yavta.c
index 124dd1d..251fe40 100644
--- a/yavta.c
+++ b/yavta.c
@@ -73,6 +73,7 @@ struct device
 	unsigned int width;
 	unsigned int height;
 	uint32_t buffer_output_flags;
+	uint32_t timestamp_type;
 
 	unsigned char num_planes;
 	struct v4l2_plane_pix_format plane_fmt[VIDEO_MAX_PLANES];
@@ -756,6 +757,7 @@ static int video_alloc_buffers(struct device *dev, int nbufs,
 			return ret;
 	}
 
+	dev->timestamp_type = buf.flags & V4L2_BUF_FLAG_TIMESTAMP_MASK;
 	dev->buffers = buffers;
 	dev->nbufs = rb.count;
 	return 0;
@@ -818,8 +820,16 @@ static int video_queue_buffer(struct device *dev, int index, enum buffer_fill_mo
 	buf.type = dev->type;
 	buf.memory = dev->memtype;
 
-	if (dev->type == V4L2_BUF_TYPE_VIDEO_OUTPUT)
+	if (dev->type == V4L2_BUF_TYPE_VIDEO_OUTPUT) {
 		buf.flags = dev->buffer_output_flags;
+		if (dev->timestamp_type == V4L2_BUF_FLAG_TIMESTAMP_COPY) {
+			struct timespec ts;
+			
+			clock_gettime(CLOCK_MONOTONIC, &ts);
+			buf.timestamp.tv_sec = ts.tv_sec;
+			buf.timestamp.tv_usec = ts.tv_nsec / 1000;
+		}
+	}
 
 	if (video_is_mplane(dev)) {
 		buf.m.planes = planes;
-- 
1.7.10.4


^ permalink raw reply related	[flat|nested] 10+ messages in thread

* Re: [PATCH v2 1/9] Provide -Q option for setting the queue type
  2014-04-10 22:06 [PATCH v2 1/9] Provide -Q option for setting the queue type Sakari Ailus
                   ` (7 preceding siblings ...)
  2014-04-10 22:06 ` [PATCH v2 9/9] Set timestamp for output buffers if the timestamp type is copy Sakari Ailus
@ 2014-04-10 22:22 ` Sakari Ailus
  8 siblings, 0 replies; 10+ messages in thread
From: Sakari Ailus @ 2014-04-10 22:22 UTC (permalink / raw)
  To: linux-media; +Cc: laurent.pinchart

Hi,

Sakari Ailus wrote:
> Instead of guessing the queue type, allow setting it explicitly.

These got out a little bit too fast... what would you expect git 
send-email to do if you press ^C?

Changes since v1:

- Replace --output (-o, for which getopt handling was actually missing) 
option with a more generic --queue-type (-Q) option.
- Cleaned up queue type setting; there are now separate functions for 
opening the video device, querying its capabilities and setting the 
queue type
- The user-set timestamp source flags are no longer printed
- Removed the accidental --userptr option handling change

-- 
Kind regards,

Sakari Ailus
sakari.ailus@iki.fi

^ permalink raw reply	[flat|nested] 10+ messages in thread

end of thread, other threads:[~2014-04-10 22:22 UTC | newest]

Thread overview: 10+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2014-04-10 22:06 [PATCH v2 1/9] Provide -Q option for setting the queue type Sakari Ailus
2014-04-10 22:06 ` [PATCH v2 2/9] Zero dev in main() Sakari Ailus
2014-04-10 22:06 ` [PATCH v2 3/9] Use int for buffer queue type Sakari Ailus
2014-04-10 22:06 ` [PATCH v2 4/9] Separate querying capabilities and determining " Sakari Ailus
2014-04-10 22:06 ` [PATCH v2 5/9] Allow passing file descriptors to yavta Sakari Ailus
2014-04-10 22:06 ` [PATCH v2 6/9] Timestamp source for output buffers Sakari Ailus
2014-04-10 22:06 ` [PATCH v2 7/9] Print timestamp type and source for dequeued buffers Sakari Ailus
2014-04-10 22:06 ` [PATCH v2 8/9] Support copy timestamps Sakari Ailus
2014-04-10 22:06 ` [PATCH v2 9/9] Set timestamp for output buffers if the timestamp type is copy Sakari Ailus
2014-04-10 22:22 ` [PATCH v2 1/9] Provide -Q option for setting the queue type Sakari Ailus

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).