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