1From 713aa60e33b8ec3ae241b07a76a0db435c6ffe54 Mon Sep 17 00:00:00 2001
2From: Jeffy Chen <jeffy.chen@rock-chips.com>
3Date: Sun, 28 Apr 2019 15:31:53 +0800
4Subject: [PATCH 1/6] libv4l2: Support mmap() to libv4l-plugin
5
6Signed-off-by: Jeffy Chen <jeffy.chen@rock-chips.com>
7---
8 lib/include/libv4l-plugin.h |  2 ++
9 lib/libv4l2/libv4l2.c       | 10 ++++++++++
10 2 files changed, 12 insertions(+)
11
12diff --git a/lib/include/libv4l-plugin.h b/lib/include/libv4l-plugin.h
13index 23b2dfb..acb0a54 100644
14--- a/lib/include/libv4l-plugin.h
15+++ b/lib/include/libv4l-plugin.h
16@@ -32,6 +32,8 @@ struct libv4l_dev_ops {
17     int (*ioctl)(void *dev_ops_priv, int fd, unsigned long int request, void *arg);
18     ssize_t (*read)(void *dev_ops_priv, int fd, void *buffer, size_t n);
19     ssize_t (*write)(void *dev_ops_priv, int fd, const void *buffer, size_t n);
20+    void * (*mmap)(void *dev_ops_priv, void *start, size_t length, int prot,
21+		   int flags, int fd, int64_t offset);
22     /* For future plugin API extension, plugins implementing the current API
23        must set these all to NULL, as future versions may check for these */
24     void (*reserved1)(void);
25diff --git a/lib/libv4l2/libv4l2.c b/lib/libv4l2/libv4l2.c
26index 9ebf8c1..0c02bec 100644
27--- a/lib/libv4l2/libv4l2.c
28+++ b/lib/libv4l2/libv4l2.c
29@@ -1627,6 +1627,16 @@ void *v4l2_mmap(void *start, size_t length, int prot, int flags, int fd,
30 	void *result;
31
32 	index = v4l2_get_index(fd);
33+	if (index != -1 && devices[index].dev_ops->mmap) {
34+		pthread_mutex_lock(&devices[index].stream_lock);
35+		result = devices[index].dev_ops->mmap(
36+				devices[index].dev_ops_priv, start,
37+				length, prot, flags, fd, offset);
38+
39+		pthread_mutex_unlock(&devices[index].stream_lock);
40+		return result;
41+	}
42+
43 	if (index == -1 ||
44 			/* Check if the mmap data matches our answer to QUERY_BUF. If it doesn't,
45 			   let the kernel handle it (to allow for mmap-based non capture use) */
46--
472.20.1
48
49