All of lore.kernel.org
 help / color / mirror / Atom feed
* [yavta PATCH v3 00/11] Timestamp source and mem-to-mem device support
@ 2014-04-12 13:23 Sakari Ailus
  2014-04-12 13:23 ` [yavta PATCH v3 01/11] Separate device object initialisation and opening Sakari Ailus
                   ` (11 more replies)
  0 siblings, 12 replies; 14+ messages in thread
From: Sakari Ailus @ 2014-04-12 13:23 UTC (permalink / raw)
  To: linux-media; +Cc: laurent.pinchart

Hi,

This is the third version of the timestamp source and mem-to-mem device
support patchset.

Change since v2:

- struct device type remains enum v4l2_buf_type

- Added a struct which contains the 1:1 mapping between V4L2 buffer type,
  verbose textual representation of it (which already existed), and a
  command line option. A function for converting the former to the first is
  provided as well.

- struct device is no longer manipulated in main(), with the few exceptions
  that existed before the patchset. Instead, functions are provided to
  access it.

- -Q (--queue-type) has been replaced with -B (--buffer-type).

- Added a patch to shorten the timestamp type names.

- Added another patch to shorten the string printed for each dequeued
  buffer.

- Invalid buffer types are rejected now by yavta.

- Removed useless use of else.

-- 
Kind regards,
Sakari


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

* [yavta PATCH v3 01/11] Separate device object initialisation and opening
  2014-04-12 13:23 [yavta PATCH v3 00/11] Timestamp source and mem-to-mem device support Sakari Ailus
@ 2014-04-12 13:23 ` Sakari Ailus
  2014-04-12 13:23 ` [yavta PATCH v3 02/11] Provide functions for setting the buffer type and checking its validity Sakari Ailus
                   ` (10 subsequent siblings)
  11 siblings, 0 replies; 14+ messages in thread
From: Sakari Ailus @ 2014-04-12 13:23 UTC (permalink / raw)
  To: linux-media; +Cc: laurent.pinchart

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

diff --git a/yavta.c b/yavta.c
index 739463d..c7ad7b4 100644
--- a/yavta.c
+++ b/yavta.c
@@ -220,17 +220,20 @@ 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 void video_init(struct device *dev)
 {
-	struct v4l2_capability cap;
-	unsigned int capabilities;
-	int ret;
-
 	memset(dev, 0, sizeof *dev);
 	dev->fd = -1;
 	dev->memtype = V4L2_MEMORY_MMAP;
 	dev->buffers = NULL;
 	dev->type = (enum v4l2_buf_type)-1;
+}
+
+static int video_open(struct device *dev, const char *devname, int no_query)
+{
+	struct v4l2_capability cap;
+	unsigned int capabilities;
+	int ret;
 
 	dev->fd = open(devname, O_RDWR);
 	if (dev->fd < 0) {
@@ -1599,6 +1602,8 @@ int main(int argc, char *argv[])
 
 	unsigned int rt_priority = 1;
 
+	video_init(&dev);
+
 	opterr = 0;
 	while ((c = getopt_long(argc, argv, "c::Cd:f:F::hi:Iln:pq:r:R::s:t:uw:", opts, NULL)) != -1) {
 
-- 
1.7.10.4


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

* [yavta PATCH v3 02/11] Provide functions for setting the buffer type and checking its validity
  2014-04-12 13:23 [yavta PATCH v3 00/11] Timestamp source and mem-to-mem device support Sakari Ailus
  2014-04-12 13:23 ` [yavta PATCH v3 01/11] Separate device object initialisation and opening Sakari Ailus
@ 2014-04-12 13:23 ` Sakari Ailus
  2014-04-12 13:23 ` [yavta PATCH v3 03/11] Separate querying capabilities and determining buffer queue type Sakari Ailus
                   ` (9 subsequent siblings)
  11 siblings, 0 replies; 14+ messages in thread
From: Sakari Ailus @ 2014-04-12 13:23 UTC (permalink / raw)
  To: linux-media; +Cc: laurent.pinchart

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

diff --git a/yavta.c b/yavta.c
index c7ad7b4..d8f0c59 100644
--- a/yavta.c
+++ b/yavta.c
@@ -220,6 +220,16 @@ static const char *v4l2_format_name(unsigned int fourcc)
 	return name;
 }
 
+static void video_set_buf_type(struct device *dev, enum v4l2_buf_type type)
+{
+	dev->type = type;
+}
+
+static bool video_has_valid_buf_type(struct device *dev)
+{
+	return (int)dev->type != -1;
+}
+
 static void video_init(struct device *dev)
 {
 	memset(dev, 0, sizeof *dev);
-- 
1.7.10.4


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

* [yavta PATCH v3 03/11] Separate querying capabilities and determining buffer queue type
  2014-04-12 13:23 [yavta PATCH v3 00/11] Timestamp source and mem-to-mem device support Sakari Ailus
  2014-04-12 13:23 ` [yavta PATCH v3 01/11] Separate device object initialisation and opening Sakari Ailus
  2014-04-12 13:23 ` [yavta PATCH v3 02/11] Provide functions for setting the buffer type and checking its validity Sakari Ailus
@ 2014-04-12 13:23 ` Sakari Ailus
  2014-04-12 13:23 ` [yavta PATCH v3 04/11] Make struct for buffer type and name mapping usable elsewhere Sakari Ailus
                   ` (8 subsequent siblings)
  11 siblings, 0 replies; 14+ messages in thread
From: Sakari Ailus @ 2014-04-12 13:23 UTC (permalink / raw)
  To: linux-media; +Cc: laurent.pinchart

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

diff --git a/yavta.c b/yavta.c
index d8f0c59..02a7403 100644
--- a/yavta.c
+++ b/yavta.c
@@ -239,12 +239,8 @@ static void video_init(struct device *dev)
 	dev->type = (enum v4l2_buf_type)-1;
 }
 
-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 = open(devname, O_RDWR);
 	if (dev->fd < 0) {
 		printf("Error opening device %s: %s (%d).\n", devname,
@@ -254,35 +250,22 @@ 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)
-		dev->type = V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE;
-	else if (capabilities & V4L2_CAP_VIDEO_OUTPUT_MPLANE)
-		dev->type = V4L2_BUF_TYPE_VIDEO_OUTPUT_MPLANE;
-	else if (capabilities & V4L2_CAP_VIDEO_CAPTURE)
-		dev->type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
-	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);
-		return -EINVAL;
-	}
-
 	printf("Device `%s' on `%s' is a video %s (%s mplanes) device.\n",
 		cap.card, cap.bus_info,
 		video_is_capture(dev) ? "capture" : "output",
@@ -290,6 +273,24 @@ static int video_open(struct device *dev, const char *devname, int no_query)
 	return 0;
 }
 
+static int cap_get_buf_type(unsigned int capabilities)
+{
+	if (capabilities & V4L2_CAP_VIDEO_CAPTURE_MPLANE) {
+		return V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE;
+	} else if (capabilities & V4L2_CAP_VIDEO_OUTPUT_MPLANE) {
+		return V4L2_BUF_TYPE_VIDEO_OUTPUT_MPLANE;
+	} else if (capabilities & V4L2_CAP_VIDEO_CAPTURE) {
+		return  V4L2_BUF_TYPE_VIDEO_CAPTURE;
+	} else if (capabilities & V4L2_CAP_VIDEO_OUTPUT) {
+		return V4L2_BUF_TYPE_VIDEO_OUTPUT;
+	} else {
+		printf("Device supports neither capture nor output.\n");
+		return -EINVAL;
+	}
+
+	return 0;
+}
+
 static void video_close(struct device *dev)
 {
 	unsigned int i;
@@ -1577,6 +1578,8 @@ int main(int argc, char *argv[])
 
 	/* Options parsings */
 	const struct v4l2_format_info *info;
+	/* 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;
@@ -1766,15 +1769,22 @@ 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 (!no_query) {
+		ret = video_querycap(&dev, &capabilities);
+		if (ret < 0)
+			return 1;
+	}
+
+	ret = cap_get_buf_type(capabilities);
 	if (ret < 0)
 		return 1;
 
-	if (dev.type == (enum v4l2_buf_type)-1)
-		no_query = 1;
+	if (!video_is_buf_type_valid(&dev))
+		video_set_buf_type(&dev, ret);
 
 	dev.memtype = memtype;
 
-- 
1.7.10.4


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

* [yavta PATCH v3 04/11] Make struct for buffer type and name mapping usable elsewhere
  2014-04-12 13:23 [yavta PATCH v3 00/11] Timestamp source and mem-to-mem device support Sakari Ailus
                   ` (2 preceding siblings ...)
  2014-04-12 13:23 ` [yavta PATCH v3 03/11] Separate querying capabilities and determining buffer queue type Sakari Ailus
@ 2014-04-12 13:23 ` Sakari Ailus
  2014-04-12 13:23 ` [yavta PATCH v3 05/11] Provide -B option for setting the buffer type Sakari Ailus
                   ` (7 subsequent siblings)
  11 siblings, 0 replies; 14+ messages in thread
From: Sakari Ailus @ 2014-04-12 13:23 UTC (permalink / raw)
  To: linux-media; +Cc: laurent.pinchart

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

diff --git a/yavta.c b/yavta.c
index 02a7403..01f61d2 100644
--- a/yavta.c
+++ b/yavta.c
@@ -97,24 +97,24 @@ static bool video_is_output(struct device *dev)
 	       dev->type == V4L2_BUF_TYPE_VIDEO_OUTPUT;
 }
 
+static struct {
+ 	enum v4l2_buf_type type;
+	const char *name;
+} buf_types[] = {
+	{ V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE, "Video capture mplanes", },
+	{ V4L2_BUF_TYPE_VIDEO_OUTPUT_MPLANE, "Video output", },
+	{ V4L2_BUF_TYPE_VIDEO_CAPTURE, "Video capture" },
+	{ V4L2_BUF_TYPE_VIDEO_OUTPUT, "Video output mplanes" },
+	{ V4L2_BUF_TYPE_VIDEO_OVERLAY, "Video overlay" },
+};
+
 static const char *v4l2_buf_type_name(enum v4l2_buf_type type)
 {
-	static struct {
-		enum v4l2_buf_type type;
-		const char *name;
-	} names[] = {
-		{ V4L2_BUF_TYPE_VIDEO_CAPTURE, "Video capture" },
-		{ V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE, "Video capture mplanes" },
-		{ V4L2_BUF_TYPE_VIDEO_OUTPUT, "Video output" },
-		{ V4L2_BUF_TYPE_VIDEO_OUTPUT_MPLANE, "Video output mplanes" },
-		{ V4L2_BUF_TYPE_VIDEO_OVERLAY, "Video overlay" },
-	};
-
 	unsigned int i;
 
-	for (i = 0; i < ARRAY_SIZE(names); ++i) {
-		if (names[i].type == type)
-			return names[i].name;
+	for (i = 0; i < ARRAY_SIZE(buf_types); ++i) {
+		if (buf_types[i].type == type)
+			return buf_types[i].name;
 	}
 
 	if (type & V4L2_BUF_TYPE_PRIVATE)
-- 
1.7.10.4


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

* [yavta PATCH v3 05/11] Provide -B option for setting the buffer type
  2014-04-12 13:23 [yavta PATCH v3 00/11] Timestamp source and mem-to-mem device support Sakari Ailus
                   ` (3 preceding siblings ...)
  2014-04-12 13:23 ` [yavta PATCH v3 04/11] Make struct for buffer type and name mapping usable elsewhere Sakari Ailus
@ 2014-04-12 13:23 ` Sakari Ailus
  2014-04-12 13:23 ` [yavta PATCH v3 06/11] Allow passing file descriptors to yavta Sakari Ailus
                   ` (6 subsequent siblings)
  11 siblings, 0 replies; 14+ messages in thread
From: Sakari Ailus @ 2014-04-12 13:23 UTC (permalink / raw)
  To: linux-media; +Cc: laurent.pinchart

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

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

diff --git a/yavta.c b/yavta.c
index 01f61d2..78ebf21 100644
--- a/yavta.c
+++ b/yavta.c
@@ -99,15 +99,34 @@ static bool video_is_output(struct device *dev)
 
 static struct {
  	enum v4l2_buf_type type;
+ 	bool supported;
 	const char *name;
+	const char *string;
 } buf_types[] = {
-	{ V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE, "Video capture mplanes", },
-	{ V4L2_BUF_TYPE_VIDEO_OUTPUT_MPLANE, "Video output", },
-	{ V4L2_BUF_TYPE_VIDEO_CAPTURE, "Video capture" },
-	{ V4L2_BUF_TYPE_VIDEO_OUTPUT, "Video output mplanes" },
-	{ V4L2_BUF_TYPE_VIDEO_OVERLAY, "Video overlay" },
+	{ V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE, 1, "Video capture mplanes", "capture-mplane", },
+	{ V4L2_BUF_TYPE_VIDEO_OUTPUT_MPLANE, 1, "Video output", "output-mplane", },
+	{ V4L2_BUF_TYPE_VIDEO_CAPTURE, 1, "Video capture", "capture", },
+	{ V4L2_BUF_TYPE_VIDEO_OUTPUT, 1, "Video output mplanes", "output", },
+	{ V4L2_BUF_TYPE_VIDEO_OVERLAY, 0, "Video overlay", "overlay" },
 };
 
+static int v4l2_buf_type_from_string(const char *str)
+{
+	unsigned int i;
+
+	for (i = 0; i < ARRAY_SIZE(buf_types); i++) {
+		if (!buf_types[i].supported)
+			continue;
+
+		if (strcmp(buf_types[i].string, str))
+			continue;
+
+		return buf_types[i].type;
+	}
+
+	return -1;
+}
+
 static const char *v4l2_buf_type_name(enum v4l2_buf_type type)
 {
 	unsigned int i;
@@ -1500,6 +1519,8 @@ static void usage(const char *argv0)
 {
 	printf("Usage: %s [options] device\n", argv0);
 	printf("Supported options:\n");
+	printf("-B, --buffer-type		Buffer type (\"capture\", \"output\",\n");
+	printf("                                \"capture-mplane\" or \"output-mplane\")\n");
 	printf("-c, --capture[=nframes]		Capture frames\n");
 	printf("-C, --check-overrun		Verify dequeued frames for buffer overrun\n");
 	printf("-d, --delay			Delay (in ms) before requeuing buffers\n");
@@ -1541,6 +1562,7 @@ static void usage(const char *argv0)
 #define OPT_STRIDE		263
 
 static struct option opts[] = {
+	{"buffer-type", 1, 0, 'B'},
 	{"capture", 2, 0, 'c'},
 	{"check-overrun", 0, 0, 'C'},
 	{"delay", 1, 0, 'd'},
@@ -1618,9 +1640,17 @@ int main(int argc, char *argv[])
 	video_init(&dev);
 
 	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, "B:c::Cd:f:F::hi:Iln:pq:r:R::s:t:uw:", opts, NULL)) != -1) {
 
 		switch (c) {
+		case 'B':
+			ret = v4l2_buf_type_from_string(optarg);
+			if (ret == -1) {
+				printf("Bad buffer type \"%s\"\n", optarg);
+				return 1;
+			}
+			video_set_buf_type(&dev, ret);
+			break;
 		case 'c':
 			do_capture = 1;
 			if (optarg)
@@ -1783,7 +1813,7 @@ int main(int argc, char *argv[])
 	if (ret < 0)
 		return 1;
 
-	if (!video_is_buf_type_valid(&dev))
+	if (!video_has_valid_buf_type(&dev))
 		video_set_buf_type(&dev, ret);
 
 	dev.memtype = memtype;
-- 
1.7.10.4


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

* [yavta PATCH v3 06/11] Allow passing file descriptors to yavta
  2014-04-12 13:23 [yavta PATCH v3 00/11] Timestamp source and mem-to-mem device support Sakari Ailus
                   ` (4 preceding siblings ...)
  2014-04-12 13:23 ` [yavta PATCH v3 05/11] Provide -B option for setting the buffer type Sakari Ailus
@ 2014-04-12 13:23 ` Sakari Ailus
  2014-04-12 13:23 ` [yavta PATCH v3 07/11] Timestamp source for output buffers Sakari Ailus
                   ` (5 subsequent siblings)
  11 siblings, 0 replies; 14+ messages in thread
From: Sakari Ailus @ 2014-04-12 13:23 UTC (permalink / raw)
  To: linux-media; +Cc: laurent.pinchart

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

diff --git a/yavta.c b/yavta.c
index 78ebf21..98f5e05 100644
--- a/yavta.c
+++ b/yavta.c
@@ -63,6 +63,7 @@ struct buffer
 struct device
 {
 	int fd;
+	int opened;
 
 	enum v4l2_buf_type type;
 	enum v4l2_memory memtype;
@@ -258,8 +259,30 @@ static void video_init(struct device *dev)
 	dev->type = (enum v4l2_buf_type)-1;
 }
 
+static bool video_has_fd(struct device *dev)
+{
+	return dev->fd != -1;
+}
+
+static int video_set_fd(struct device *dev, int fd)
+{
+	if (video_has_fd(dev)) {
+		printf("Can't set fd (already open).\n");
+		return -1;
+	}
+
+	dev->fd = fd;
+
+	return 0;
+}
+
 static int video_open(struct device *dev, const char *devname)
 {
+	if (video_has_fd(dev)) {
+		printf("Can't open device (already open).\n");
+		return -1;
+	}
+
 	dev->fd = open(devname, O_RDWR);
 	if (dev->fd < 0) {
 		printf("Error opening device %s: %s (%d).\n", devname,
@@ -269,6 +292,8 @@ static int video_open(struct device *dev, const char *devname)
 
 	printf("Device %s opened.\n", devname);
 
+	dev->opened = 1;
+
 	return 0;
 }
 
@@ -318,7 +343,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)
@@ -1544,6 +1570,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");
@@ -1560,6 +1587,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[] = {
 	{"buffer-type", 1, 0, 'B'},
@@ -1568,6 +1596,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'},
@@ -1761,6 +1790,15 @@ int main(int argc, char *argv[])
 		case OPT_ENUM_INPUTS:
 			do_enum_inputs = 1;
 			break;
+		case OPT_FD:
+			ret = atoi(optarg);
+			if (ret < 0) {
+				printf("Bad file descriptor %d\n", ret);
+				return 1;
+			}
+			printf("Using file descriptor %d\n", ret);
+			video_set_fd(&dev, ret);
+			break;
 		case OPT_NO_QUERY:
 			no_query = 1;
 			break;
@@ -1791,17 +1829,18 @@ 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 (!video_has_fd(&dev)) {
+		if (optind >= argc) {
+			usage(argv[0]);
+			return 1;
+		}
+		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] 14+ messages in thread

* [yavta PATCH v3 07/11] Timestamp source for output buffers
  2014-04-12 13:23 [yavta PATCH v3 00/11] Timestamp source and mem-to-mem device support Sakari Ailus
                   ` (5 preceding siblings ...)
  2014-04-12 13:23 ` [yavta PATCH v3 06/11] Allow passing file descriptors to yavta Sakari Ailus
@ 2014-04-12 13:23 ` Sakari Ailus
  2014-04-12 13:24 ` [yavta PATCH v3 08/11] Print timestamp type and source for dequeued buffers Sakari Ailus
                   ` (4 subsequent siblings)
  11 siblings, 0 replies; 14+ messages in thread
From: Sakari Ailus @ 2014-04-12 13:23 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 98f5e05..a0f8570 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];
@@ -867,6 +868,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;
@@ -1574,6 +1578,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");
@@ -1588,6 +1593,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[] = {
 	{"buffer-type", 1, 0, 'B'},
@@ -1617,6 +1623,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}
 };
@@ -1814,6 +1821,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] 14+ messages in thread

* [yavta PATCH v3 08/11] Print timestamp type and source for dequeued buffers
  2014-04-12 13:23 [yavta PATCH v3 00/11] Timestamp source and mem-to-mem device support Sakari Ailus
                   ` (6 preceding siblings ...)
  2014-04-12 13:23 ` [yavta PATCH v3 07/11] Timestamp source for output buffers Sakari Ailus
@ 2014-04-12 13:24 ` Sakari Ailus
  2014-04-12 13:24 ` [yavta PATCH v3 09/11] Shorten dequeued buffer info print Sakari Ailus
                   ` (3 subsequent siblings)
  11 siblings, 0 replies; 14+ messages in thread
From: Sakari Ailus @ 2014-04-12 13:24 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 a0f8570..5516675 100644
--- a/yavta.c
+++ b/yavta.c
@@ -717,6 +717,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)
 {
@@ -764,26 +788,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);
 
@@ -1451,6 +1456,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);
@@ -1483,10 +1489,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 ts %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] 14+ messages in thread

* [yavta PATCH v3 09/11] Shorten dequeued buffer info print
  2014-04-12 13:23 [yavta PATCH v3 00/11] Timestamp source and mem-to-mem device support Sakari Ailus
                   ` (7 preceding siblings ...)
  2014-04-12 13:24 ` [yavta PATCH v3 08/11] Print timestamp type and source for dequeued buffers Sakari Ailus
@ 2014-04-12 13:24 ` Sakari Ailus
  2014-04-12 13:24 ` [yavta PATCH v3 10/11] Support copy timestamps Sakari Ailus
                   ` (2 subsequent siblings)
  11 siblings, 0 replies; 14+ messages in thread
From: Sakari Ailus @ 2014-04-12 13:24 UTC (permalink / raw)
  To: linux-media; +Cc: laurent.pinchart

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

diff --git a/yavta.c b/yavta.c
index 5516675..e81e058 100644
--- a/yavta.c
+++ b/yavta.c
@@ -721,13 +721,13 @@ static void get_ts_flags(uint32_t flags, const char **ts_type, const char **ts_s
 {
 	switch (flags & V4L2_BUF_FLAG_TIMESTAMP_MASK) {
 	case V4L2_BUF_FLAG_TIMESTAMP_UNKNOWN:
-		*ts_type = "unknown";
+		*ts_type = "unk";
 		break;
 	case V4L2_BUF_FLAG_TIMESTAMP_MONOTONIC:
-		*ts_type = "monotonic";
+		*ts_type = "mono";
 		break;
 	default:
-		*ts_type = "invalid";
+		*ts_type = "inv";
 	}
 	switch (flags & V4L2_BUF_FLAG_TSTAMP_SRC_MASK) {
 	case V4L2_BUF_FLAG_TSTAMP_SRC_EOF:
@@ -737,7 +737,7 @@ static void get_ts_flags(uint32_t flags, const char **ts_type, const char **ts_s
 		*ts_source = "SoE";
 		break;
 	default:
-		*ts_source = "invalid";
+		*ts_source = "inv";
 	}
 }
 
@@ -1490,7 +1490,7 @@ static int video_do_capture(struct device *dev, unsigned int nframes,
 
 		clock_gettime(CLOCK_MONOTONIC, &ts);
 		get_ts_flags(buf.flags, &ts_type, &ts_source);
-		printf("%u (%u) [%c] %u %u bytes %ld.%06ld %ld.%06ld %.3f fps ts %s/%s\n", i, buf.index,
+		printf("%u (%u) [%c] %u %u B %ld.%06ld %ld.%06ld %.3f fps ts %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,
-- 
1.7.10.4


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

* [yavta PATCH v3 10/11] Support copy timestamps
  2014-04-12 13:23 [yavta PATCH v3 00/11] Timestamp source and mem-to-mem device support Sakari Ailus
                   ` (8 preceding siblings ...)
  2014-04-12 13:24 ` [yavta PATCH v3 09/11] Shorten dequeued buffer info print Sakari Ailus
@ 2014-04-12 13:24 ` Sakari Ailus
  2014-04-12 13:24 ` [yavta PATCH v3 11/11] Set timestamp for output buffers if the timestamp type is copy Sakari Ailus
  2014-04-16 18:21 ` [yavta PATCH v3 00/11] Timestamp source and mem-to-mem device support Laurent Pinchart
  11 siblings, 0 replies; 14+ messages in thread
From: Sakari Ailus @ 2014-04-12 13:24 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 e81e058..c878c0d 100644
--- a/yavta.c
+++ b/yavta.c
@@ -726,6 +726,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 = "mono";
 		break;
+	case V4L2_BUF_FLAG_TIMESTAMP_COPY:
+		*ts_type = "copy";
+		break;
 	default:
 		*ts_type = "inv";
 	}
-- 
1.7.10.4


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

* [yavta PATCH v3 11/11] Set timestamp for output buffers if the timestamp type is copy
  2014-04-12 13:23 [yavta PATCH v3 00/11] Timestamp source and mem-to-mem device support Sakari Ailus
                   ` (9 preceding siblings ...)
  2014-04-12 13:24 ` [yavta PATCH v3 10/11] Support copy timestamps Sakari Ailus
@ 2014-04-12 13:24 ` Sakari Ailus
  2014-04-16 18:21 ` [yavta PATCH v3 00/11] Timestamp source and mem-to-mem device support Laurent Pinchart
  11 siblings, 0 replies; 14+ messages in thread
From: Sakari Ailus @ 2014-04-12 13:24 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 c878c0d..9eb5e9c 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];
@@ -814,6 +815,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;
@@ -876,8 +878,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] 14+ messages in thread

* Re: [yavta PATCH v3 00/11] Timestamp source and mem-to-mem device support
  2014-04-12 13:23 [yavta PATCH v3 00/11] Timestamp source and mem-to-mem device support Sakari Ailus
                   ` (10 preceding siblings ...)
  2014-04-12 13:24 ` [yavta PATCH v3 11/11] Set timestamp for output buffers if the timestamp type is copy Sakari Ailus
@ 2014-04-16 18:21 ` Laurent Pinchart
  2014-04-16 18:23   ` Sakari Ailus
  11 siblings, 1 reply; 14+ messages in thread
From: Laurent Pinchart @ 2014-04-16 18:21 UTC (permalink / raw)
  To: Sakari Ailus; +Cc: linux-media

Hi Sakari,

Thank you for the patches.

On Saturday 12 April 2014 16:23:52 Sakari Ailus wrote:
> Hi,
> 
> This is the third version of the timestamp source and mem-to-mem device
> support patchset.
> 
> Change since v2:
> 
> - struct device type remains enum v4l2_buf_type
> 
> - Added a struct which contains the 1:1 mapping between V4L2 buffer type,
>   verbose textual representation of it (which already existed), and a
>   command line option. A function for converting the former to the first is
>   provided as well.
> 
> - struct device is no longer manipulated in main(), with the few exceptions
>   that existed before the patchset. Instead, functions are provided to
>   access it.
> 
> - -Q (--queue-type) has been replaced with -B (--buffer-type).
> 
> - Added a patch to shorten the timestamp type names.
> 
> - Added another patch to shorten the string printed for each dequeued
>   buffer.
> 
> - Invalid buffer types are rejected now by yavta.
> 
> - Removed useless use of else.

Applied with whitespace fixes and the following change to 07/11.

@@ -867,6 +868,9 @@ static int video_queue_buffer(struct device *dev,
 	buf.type = dev->type;
 	buf.memory = dev->memtype;
 
-	if (dev->type == V4L2_BUF_TYPE_VIDEO_OUTPUT)
+	if (video_is_output(dev))
 		buf.flags = dev->buffer_output_flags;
 
 	if (video_is_mplane(dev)) {

-- 
Regards,

Laurent Pinchart


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

* Re: [yavta PATCH v3 00/11] Timestamp source and mem-to-mem device support
  2014-04-16 18:21 ` [yavta PATCH v3 00/11] Timestamp source and mem-to-mem device support Laurent Pinchart
@ 2014-04-16 18:23   ` Sakari Ailus
  0 siblings, 0 replies; 14+ messages in thread
From: Sakari Ailus @ 2014-04-16 18:23 UTC (permalink / raw)
  To: Laurent Pinchart; +Cc: linux-media

On Wed, Apr 16, 2014 at 08:21:54PM +0200, Laurent Pinchart wrote:
> Applied with whitespace fixes and the following change to 07/11.
> 
> @@ -867,6 +868,9 @@ static int video_queue_buffer(struct device *dev,
>  	buf.type = dev->type;
>  	buf.memory = dev->memtype;
>  
> -	if (dev->type == V4L2_BUF_TYPE_VIDEO_OUTPUT)
> +	if (video_is_output(dev))
>  		buf.flags = dev->buffer_output_flags;
>  
>  	if (video_is_mplane(dev)) {
> 

Thank you!

-- 
Sakari Ailus
e-mail: sakari.ailus@iki.fi	XMPP: sailus@retiisi.org.uk

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

end of thread, other threads:[~2014-04-16 18:23 UTC | newest]

Thread overview: 14+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2014-04-12 13:23 [yavta PATCH v3 00/11] Timestamp source and mem-to-mem device support Sakari Ailus
2014-04-12 13:23 ` [yavta PATCH v3 01/11] Separate device object initialisation and opening Sakari Ailus
2014-04-12 13:23 ` [yavta PATCH v3 02/11] Provide functions for setting the buffer type and checking its validity Sakari Ailus
2014-04-12 13:23 ` [yavta PATCH v3 03/11] Separate querying capabilities and determining buffer queue type Sakari Ailus
2014-04-12 13:23 ` [yavta PATCH v3 04/11] Make struct for buffer type and name mapping usable elsewhere Sakari Ailus
2014-04-12 13:23 ` [yavta PATCH v3 05/11] Provide -B option for setting the buffer type Sakari Ailus
2014-04-12 13:23 ` [yavta PATCH v3 06/11] Allow passing file descriptors to yavta Sakari Ailus
2014-04-12 13:23 ` [yavta PATCH v3 07/11] Timestamp source for output buffers Sakari Ailus
2014-04-12 13:24 ` [yavta PATCH v3 08/11] Print timestamp type and source for dequeued buffers Sakari Ailus
2014-04-12 13:24 ` [yavta PATCH v3 09/11] Shorten dequeued buffer info print Sakari Ailus
2014-04-12 13:24 ` [yavta PATCH v3 10/11] Support copy timestamps Sakari Ailus
2014-04-12 13:24 ` [yavta PATCH v3 11/11] Set timestamp for output buffers if the timestamp type is copy Sakari Ailus
2014-04-16 18:21 ` [yavta PATCH v3 00/11] Timestamp source and mem-to-mem device support Laurent Pinchart
2014-04-16 18:23   ` Sakari Ailus

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.