1*4882a593SmuzhiyunFrom af8250adf4cdb6ba10c0d5560eb9cd974fbe3c93 Mon Sep 17 00:00:00 2001 2*4882a593SmuzhiyunFrom: Jeffy Chen <jeffy.chen@rock-chips.com> 3*4882a593SmuzhiyunDate: Tue, 14 Dec 2021 17:09:52 +0800 4*4882a593SmuzhiyunSubject: [PATCH 6/7] Support builtin v4l plugins 5*4882a593Smuzhiyun 6*4882a593SmuzhiyunUse --enable-builtin-plugins to enable it. 7*4882a593Smuzhiyun 8*4882a593SmuzhiyunOnly support mplane plugin for now. 9*4882a593Smuzhiyun 10*4882a593SmuzhiyunSigned-off-by: Jeffy Chen <jeffy.chen@rock-chips.com> 11*4882a593Smuzhiyun--- 12*4882a593Smuzhiyun configure.ac | 13 ++++++ 13*4882a593Smuzhiyun lib/Makefile.am | 4 +- 14*4882a593Smuzhiyun lib/libv4l-mplane/Makefile.am | 9 ++++ 15*4882a593Smuzhiyun lib/libv4l-mplane/libv4l-mplane.c | 4 ++ 16*4882a593Smuzhiyun lib/libv4l2/Makefile.am | 3 ++ 17*4882a593Smuzhiyun lib/libv4l2/libv4l2-priv.h | 16 +++---- 18*4882a593Smuzhiyun lib/libv4l2/libv4l2.c | 73 +++++++++++++++++++++++++++++++ 19*4882a593Smuzhiyun lib/libv4l2/v4l2-plugin.c | 8 ++-- 20*4882a593Smuzhiyun 8 files changed, 116 insertions(+), 14 deletions(-) 21*4882a593Smuzhiyun 22*4882a593Smuzhiyundiff --git a/configure.ac b/configure.ac 23*4882a593Smuzhiyunindex 98bbbeb..7bfc393 100644 24*4882a593Smuzhiyun--- a/configure.ac 25*4882a593Smuzhiyun+++ b/configure.ac 26*4882a593Smuzhiyun@@ -539,6 +539,14 @@ AC_ARG_ENABLE(bpf, 27*4882a593Smuzhiyun esac] 28*4882a593Smuzhiyun ) 29*4882a593Smuzhiyun 30*4882a593Smuzhiyun+AC_ARG_ENABLE(builtin-plugins, 31*4882a593Smuzhiyun+ AS_HELP_STRING([--enable-builtin-plugins], [enable builtin libv4l plugins]), 32*4882a593Smuzhiyun+ [case "${enableval}" in 33*4882a593Smuzhiyun+ yes | no ) ;; 34*4882a593Smuzhiyun+ *) AC_MSG_ERROR(bad value ${enableval} for --enable-builtin-plugins) ;; 35*4882a593Smuzhiyun+ esac] 36*4882a593Smuzhiyun+) 37*4882a593Smuzhiyun+ 38*4882a593Smuzhiyun PKG_CHECK_MODULES([SDL2], [sdl2 SDL2_image], [sdl_pc=yes], [sdl_pc=no]) 39*4882a593Smuzhiyun AM_CONDITIONAL([HAVE_SDL], [test x$sdl_pc = xyes]) 40*4882a593Smuzhiyun 41*4882a593Smuzhiyun@@ -555,6 +563,7 @@ AM_CONDITIONAL([WITH_V4LUTILS], [test x$enable_v4l_utils != xno -a x$linux_o 42*4882a593Smuzhiyun AM_CONDITIONAL([WITH_QV4L2], [test x${qt_pkgconfig} = xtrue -a x$enable_qv4l2 != xno]) 43*4882a593Smuzhiyun AM_CONDITIONAL([WITH_QVIDCAP], [test x${qt_desktop_opengl} = xyes -a x$enable_qvidcap != xno]) 44*4882a593Smuzhiyun AM_CONDITIONAL([WITH_V4L_PLUGINS], [test x$enable_dyn_libv4l != xno -a x$enable_shared != xno]) 45*4882a593Smuzhiyun+AM_CONDITIONAL([WITH_V4L_BUILTIN_PLUGINS], [test x$enable_builtin_plugins = xyes]) 46*4882a593Smuzhiyun AM_CONDITIONAL([WITH_V4L_WRAPPERS], [test x$enable_dyn_libv4l != xno -a x$enable_shared != xno]) 47*4882a593Smuzhiyun AM_CONDITIONAL([WITH_QTGL], [test x${qt_desktop_opengl} = xyes]) 48*4882a593Smuzhiyun AM_CONDITIONAL([WITH_GCONV], [test x$enable_gconv = xyes -a x$enable_shared = xyes -a x$with_gconvdir != x -a -f $with_gconvdir/gconv-modules]) 49*4882a593Smuzhiyun@@ -607,6 +616,9 @@ AM_COND_IF([WITH_QVIDCAP], [USE_QVIDCAP="yes"], [USE_QVIDCAP="no"]) 50*4882a593Smuzhiyun AM_COND_IF([WITH_V4L_PLUGINS], [USE_V4L_PLUGINS="yes" 51*4882a593Smuzhiyun AC_DEFINE([HAVE_V4L_PLUGINS], [1], [V4L plugin support enabled])], 52*4882a593Smuzhiyun [USE_V4L_PLUGINS="no"]) 53*4882a593Smuzhiyun+AM_COND_IF([WITH_V4L_BUILTIN_PLUGINS], [USE_V4L_BUILTIN_PLUGINS="yes" 54*4882a593Smuzhiyun+ AC_DEFINE([HAVE_V4L_BUILTIN_PLUGINS], [1], [V4L builtin plugin support enabled])], 55*4882a593Smuzhiyun+ [USE_V4L_BUILTIN_PLUGINS="no"]) 56*4882a593Smuzhiyun AM_COND_IF([WITH_V4L_WRAPPERS], [USE_V4L_WRAPPERS="yes"], [USE_V4L_WRAPPERS="no"]) 57*4882a593Smuzhiyun AM_COND_IF([WITH_GCONV], [USE_GCONV="yes"], [USE_GCONV="no"]) 58*4882a593Smuzhiyun AM_COND_IF([WITH_V4L2_CTL_LIBV4L], [USE_V4L2_CTL_LIBV4L="yes"], [USE_V4L2_CTL_LIBV4L="no"]) 59*4882a593Smuzhiyun@@ -653,6 +665,7 @@ compile time options summary 60*4882a593Smuzhiyun 61*4882a593Smuzhiyun dynamic libv4l : $USE_DYN_LIBV4L 62*4882a593Smuzhiyun v4l_plugins : $USE_V4L_PLUGINS 63*4882a593Smuzhiyun+ v4l_builtin_plugins : $USE_V4L_BUILTIN_PLUGINS 64*4882a593Smuzhiyun v4l_wrappers : $USE_V4L_WRAPPERS 65*4882a593Smuzhiyun libdvbv5 : $USE_LIBDVBV5 66*4882a593Smuzhiyun dvbv5-daemon : $USE_DVBV5_REMOTE 67*4882a593Smuzhiyundiff --git a/lib/Makefile.am b/lib/Makefile.am 68*4882a593Smuzhiyunindex a105c95..4952d6d 100644 69*4882a593Smuzhiyun--- a/lib/Makefile.am 70*4882a593Smuzhiyun+++ b/lib/Makefile.am 71*4882a593Smuzhiyun@@ -1,9 +1,9 @@ 72*4882a593Smuzhiyun SUBDIRS = \ 73*4882a593Smuzhiyun+ libv4l-mplane \ 74*4882a593Smuzhiyun libv4lconvert \ 75*4882a593Smuzhiyun libv4l2 \ 76*4882a593Smuzhiyun libv4l1 \ 77*4882a593Smuzhiyun- libv4l2rds \ 78*4882a593Smuzhiyun- libv4l-mplane 79*4882a593Smuzhiyun+ libv4l2rds 80*4882a593Smuzhiyun 81*4882a593Smuzhiyun if WITH_LIBDVBV5 82*4882a593Smuzhiyun SUBDIRS += \ 83*4882a593Smuzhiyundiff --git a/lib/libv4l-mplane/Makefile.am b/lib/libv4l-mplane/Makefile.am 84*4882a593Smuzhiyunindex 5264ecf..4c0ba0a 100644 85*4882a593Smuzhiyun--- a/lib/libv4l-mplane/Makefile.am 86*4882a593Smuzhiyun+++ b/lib/libv4l-mplane/Makefile.am 87*4882a593Smuzhiyun@@ -1,7 +1,16 @@ 88*4882a593Smuzhiyun+if WITH_V4L_BUILTIN_PLUGINS 89*4882a593Smuzhiyun+noinst_LTLIBRARIES = libv4l-mplane.la 90*4882a593Smuzhiyun+else 91*4882a593Smuzhiyun if WITH_V4L_PLUGINS 92*4882a593Smuzhiyun libv4l2plugin_LTLIBRARIES = libv4l-mplane.la 93*4882a593Smuzhiyun endif 94*4882a593Smuzhiyun+endif 95*4882a593Smuzhiyun 96*4882a593Smuzhiyun libv4l_mplane_la_SOURCES = libv4l-mplane.c 97*4882a593Smuzhiyun+if WITH_V4L_BUILTIN_PLUGINS 98*4882a593Smuzhiyun+libv4l_mplane_la_CPPFLAGS = -static 99*4882a593Smuzhiyun+libv4l_mplane_la_LDFLAGS = -static 100*4882a593Smuzhiyun+else 101*4882a593Smuzhiyun libv4l_mplane_la_CPPFLAGS = $(CFLAG_VISIBILITY) 102*4882a593Smuzhiyun libv4l_mplane_la_LDFLAGS = -avoid-version -module -shared -export-dynamic -lpthread 103*4882a593Smuzhiyun+endif 104*4882a593Smuzhiyundiff --git a/lib/libv4l-mplane/libv4l-mplane.c b/lib/libv4l-mplane/libv4l-mplane.c 105*4882a593Smuzhiyunindex db22b0b..fcd522e 100644 106*4882a593Smuzhiyun--- a/lib/libv4l-mplane/libv4l-mplane.c 107*4882a593Smuzhiyun+++ b/lib/libv4l-mplane/libv4l-mplane.c 108*4882a593Smuzhiyun@@ -609,7 +609,11 @@ static ssize_t plugin_write(void *dev_ops_priv, int fd, const void *buf, 109*4882a593Smuzhiyun return SYS_WRITE(fd, buf, len); 110*4882a593Smuzhiyun } 111*4882a593Smuzhiyun 112*4882a593Smuzhiyun+#ifdef HAVE_V4L_BUILTIN_PLUGINS 113*4882a593Smuzhiyun+const struct libv4l_dev_ops libv4l2_plugin_mplane = { 114*4882a593Smuzhiyun+#else 115*4882a593Smuzhiyun PLUGIN_PUBLIC const struct libv4l_dev_ops libv4l2_plugin = { 116*4882a593Smuzhiyun+#endif 117*4882a593Smuzhiyun .init = &plugin_init, 118*4882a593Smuzhiyun .close = &plugin_close, 119*4882a593Smuzhiyun .ioctl = &plugin_ioctl, 120*4882a593Smuzhiyundiff --git a/lib/libv4l2/Makefile.am b/lib/libv4l2/Makefile.am 121*4882a593Smuzhiyunindex 3a1bb90..1250d84 100644 122*4882a593Smuzhiyun--- a/lib/libv4l2/Makefile.am 123*4882a593Smuzhiyun+++ b/lib/libv4l2/Makefile.am 124*4882a593Smuzhiyun@@ -23,6 +23,9 @@ endif 125*4882a593Smuzhiyun libv4l2_la_CPPFLAGS = $(CFLAG_VISIBILITY) $(ENFORCE_LIBV4L_STATIC) 126*4882a593Smuzhiyun libv4l2_la_LDFLAGS = $(LIBV4L2_VERSION) -lpthread $(DLOPEN_LIBS) $(ENFORCE_LIBV4L_STATIC) 127*4882a593Smuzhiyun libv4l2_la_LIBADD = ../libv4lconvert/libv4lconvert.la 128*4882a593Smuzhiyun+if WITH_V4L_BUILTIN_PLUGINS 129*4882a593Smuzhiyun+libv4l2_la_LIBADD += ../libv4l-mplane/libv4l-mplane.la 130*4882a593Smuzhiyun+endif 131*4882a593Smuzhiyun 132*4882a593Smuzhiyun v4l2convert_la_SOURCES = v4l2convert.c 133*4882a593Smuzhiyun v4l2convert_la_LIBADD = libv4l2.la 134*4882a593Smuzhiyundiff --git a/lib/libv4l2/libv4l2-priv.h b/lib/libv4l2/libv4l2-priv.h 135*4882a593Smuzhiyunindex cce6de4..cc8c4f5 100644 136*4882a593Smuzhiyun--- a/lib/libv4l2/libv4l2-priv.h 137*4882a593Smuzhiyun+++ b/lib/libv4l2/libv4l2-priv.h 138*4882a593Smuzhiyun@@ -109,20 +109,20 @@ struct v4l2_dev_info { 139*4882a593Smuzhiyun 140*4882a593Smuzhiyun /* From v4l2-plugin.c */ 141*4882a593Smuzhiyun #if defined(HAVE_V4L_PLUGINS) 142*4882a593Smuzhiyun-void v4l2_plugin_init(int fd, void **plugin_lib_ret, void **plugin_priv_ret, 143*4882a593Smuzhiyun- const struct libv4l_dev_ops **dev_ops_ret); 144*4882a593Smuzhiyun-void v4l2_plugin_cleanup(void *plugin_lib, void *plugin_priv, 145*4882a593Smuzhiyun- const struct libv4l_dev_ops *dev_ops); 146*4882a593Smuzhiyun+void v4l2_dyn_plugin_init(int fd, void **plugin_lib_ret, void **plugin_priv_ret, 147*4882a593Smuzhiyun+ const struct libv4l_dev_ops **dev_ops_ret); 148*4882a593Smuzhiyun+void v4l2_dyn_plugin_cleanup(void *plugin_lib, void *plugin_priv, 149*4882a593Smuzhiyun+ const struct libv4l_dev_ops *dev_ops); 150*4882a593Smuzhiyun #else 151*4882a593Smuzhiyun-static inline void v4l2_plugin_init(int fd, void **plugin_lib_ret, void **plugin_priv_ret, 152*4882a593Smuzhiyun- const struct libv4l_dev_ops **dev_ops_ret) 153*4882a593Smuzhiyun+static inline void v4l2_dyn_plugin_init(int fd, void **plugin_lib_ret, void **plugin_priv_ret, 154*4882a593Smuzhiyun+ const struct libv4l_dev_ops **dev_ops_ret) 155*4882a593Smuzhiyun { 156*4882a593Smuzhiyun *dev_ops_ret = v4lconvert_get_default_dev_ops(); 157*4882a593Smuzhiyun *plugin_lib_ret = NULL; 158*4882a593Smuzhiyun *plugin_priv_ret = NULL; 159*4882a593Smuzhiyun } 160*4882a593Smuzhiyun-static inline void v4l2_plugin_cleanup(void *plugin_lib, void *plugin_priv, 161*4882a593Smuzhiyun- const struct libv4l_dev_ops *dev_ops) 162*4882a593Smuzhiyun+static inline void v4l2_dyn_plugin_cleanup(void *plugin_lib, void *plugin_priv, 163*4882a593Smuzhiyun+ const struct libv4l_dev_ops *dev_ops) 164*4882a593Smuzhiyun { 165*4882a593Smuzhiyun } 166*4882a593Smuzhiyun #endif /* WITH_V4L_PLUGINS */ 167*4882a593Smuzhiyundiff --git a/lib/libv4l2/libv4l2.c b/lib/libv4l2/libv4l2.c 168*4882a593Smuzhiyunindex 0b17888..949a020 100644 169*4882a593Smuzhiyun--- a/lib/libv4l2/libv4l2.c 170*4882a593Smuzhiyun+++ b/lib/libv4l2/libv4l2.c 171*4882a593Smuzhiyun@@ -74,6 +74,8 @@ 172*4882a593Smuzhiyun #include "libv4l2-priv.h" 173*4882a593Smuzhiyun #include "libv4l-plugin.h" 174*4882a593Smuzhiyun 175*4882a593Smuzhiyun+#define ARRAY_SIZE(x) (sizeof(x) / sizeof((x)[0])) 176*4882a593Smuzhiyun+ 177*4882a593Smuzhiyun /* Note these flags are stored together with the flags passed to v4l2_fd_open() 178*4882a593Smuzhiyun in v4l2_dev_info's flags member, so care should be taken that the do not 179*4882a593Smuzhiyun use the same bits! */ 180*4882a593Smuzhiyun@@ -618,6 +620,77 @@ static void v4l2_update_fps(int index, struct v4l2_streamparm *parm) 181*4882a593Smuzhiyun devices[index].fps = 0; 182*4882a593Smuzhiyun } 183*4882a593Smuzhiyun 184*4882a593Smuzhiyun+#ifdef HAVE_V4L_BUILTIN_PLUGINS 185*4882a593Smuzhiyun+extern const struct libv4l_dev_ops libv4l2_plugin_mplane; 186*4882a593Smuzhiyun+ 187*4882a593Smuzhiyun+void v4l2_builtin_plugin_init(int fd, void **plugin_priv_ret, 188*4882a593Smuzhiyun+ const struct libv4l_dev_ops **dev_ops_ret) 189*4882a593Smuzhiyun+{ 190*4882a593Smuzhiyun+ const struct libv4l_dev_ops *builtin_plugins[] = { 191*4882a593Smuzhiyun+ &libv4l2_plugin_mplane, 192*4882a593Smuzhiyun+ }; 193*4882a593Smuzhiyun+ const struct libv4l_dev_ops *libv4l2_plugin = NULL; 194*4882a593Smuzhiyun+ int i; 195*4882a593Smuzhiyun+ 196*4882a593Smuzhiyun+ *dev_ops_ret = NULL; 197*4882a593Smuzhiyun+ *plugin_priv_ret = NULL; 198*4882a593Smuzhiyun+ 199*4882a593Smuzhiyun+ for (i = 0; i < ARRAY_SIZE(builtin_plugins); i++) { 200*4882a593Smuzhiyun+ V4L2_LOG("PLUGIN: try builtin(%d);\n", i); 201*4882a593Smuzhiyun+ 202*4882a593Smuzhiyun+ libv4l2_plugin = builtin_plugins[i]; 203*4882a593Smuzhiyun+ 204*4882a593Smuzhiyun+ if (!libv4l2_plugin->init || 205*4882a593Smuzhiyun+ !libv4l2_plugin->close || 206*4882a593Smuzhiyun+ !libv4l2_plugin->ioctl) { 207*4882a593Smuzhiyun+ V4L2_LOG("PLUGIN: does not have all mandatory ops\n"); 208*4882a593Smuzhiyun+ continue; 209*4882a593Smuzhiyun+ } 210*4882a593Smuzhiyun+ 211*4882a593Smuzhiyun+ *plugin_priv_ret = libv4l2_plugin->init(fd); 212*4882a593Smuzhiyun+ if (!*plugin_priv_ret) { 213*4882a593Smuzhiyun+ V4L2_LOG("PLUGIN: plugin init() returned NULL\n"); 214*4882a593Smuzhiyun+ continue; 215*4882a593Smuzhiyun+ } 216*4882a593Smuzhiyun+ 217*4882a593Smuzhiyun+ *dev_ops_ret = libv4l2_plugin; 218*4882a593Smuzhiyun+ break; 219*4882a593Smuzhiyun+ } 220*4882a593Smuzhiyun+} 221*4882a593Smuzhiyun+ 222*4882a593Smuzhiyun+void v4l2_builtin_plugin_cleanup(void *plugin_priv, 223*4882a593Smuzhiyun+ const struct libv4l_dev_ops *dev_ops) 224*4882a593Smuzhiyun+{ 225*4882a593Smuzhiyun+ dev_ops->close(plugin_priv); 226*4882a593Smuzhiyun+} 227*4882a593Smuzhiyun+#endif /* HAVE_V4L_PLUGINS */ 228*4882a593Smuzhiyun+ 229*4882a593Smuzhiyun+void v4l2_plugin_init(int fd, void **plugin_lib_ret, void **plugin_priv_ret, 230*4882a593Smuzhiyun+ const struct libv4l_dev_ops **dev_ops_ret) 231*4882a593Smuzhiyun+{ 232*4882a593Smuzhiyun+#ifdef HAVE_V4L_BUILTIN_PLUGINS 233*4882a593Smuzhiyun+ *plugin_lib_ret = NULL; 234*4882a593Smuzhiyun+ v4l2_builtin_plugin_init(fd, plugin_priv_ret, dev_ops_ret); 235*4882a593Smuzhiyun+ if (*dev_ops_ret) 236*4882a593Smuzhiyun+ return; 237*4882a593Smuzhiyun+#endif 238*4882a593Smuzhiyun+ 239*4882a593Smuzhiyun+ v4l2_dyn_plugin_init(fd, plugin_lib_ret, plugin_priv_ret, dev_ops_ret); 240*4882a593Smuzhiyun+} 241*4882a593Smuzhiyun+ 242*4882a593Smuzhiyun+void v4l2_plugin_cleanup(void *plugin_lib, void *plugin_priv, 243*4882a593Smuzhiyun+ const struct libv4l_dev_ops *dev_ops) 244*4882a593Smuzhiyun+{ 245*4882a593Smuzhiyun+#ifdef HAVE_V4L_BUILTIN_PLUGINS 246*4882a593Smuzhiyun+ if (!plugin_lib) { 247*4882a593Smuzhiyun+ v4l2_builtin_plugin_cleanup(plugin_priv, dev_ops); 248*4882a593Smuzhiyun+ return; 249*4882a593Smuzhiyun+ } 250*4882a593Smuzhiyun+#endif 251*4882a593Smuzhiyun+ 252*4882a593Smuzhiyun+ v4l2_dyn_plugin_cleanup(plugin_lib, plugin_priv, dev_ops); 253*4882a593Smuzhiyun+} 254*4882a593Smuzhiyun+ 255*4882a593Smuzhiyun int v4l2_open(const char *file, int oflag, ...) 256*4882a593Smuzhiyun { 257*4882a593Smuzhiyun int fd; 258*4882a593Smuzhiyundiff --git a/lib/libv4l2/v4l2-plugin.c b/lib/libv4l2/v4l2-plugin.c 259*4882a593Smuzhiyunindex ff42eed..f65baaa 100644 260*4882a593Smuzhiyun--- a/lib/libv4l2/v4l2-plugin.c 261*4882a593Smuzhiyun+++ b/lib/libv4l2/v4l2-plugin.c 262*4882a593Smuzhiyun@@ -48,8 +48,8 @@ 263*4882a593Smuzhiyun 264*4882a593Smuzhiyun #define PLUGINS_PATTERN LIBV4L2_PLUGIN_DIR "/*.so" 265*4882a593Smuzhiyun 266*4882a593Smuzhiyun-void v4l2_plugin_init(int fd, void **plugin_lib_ret, void **plugin_priv_ret, 267*4882a593Smuzhiyun- const struct libv4l_dev_ops **dev_ops_ret) 268*4882a593Smuzhiyun+void v4l2_dyn_plugin_init(int fd, void **plugin_lib_ret, void **plugin_priv_ret, 269*4882a593Smuzhiyun+ const struct libv4l_dev_ops **dev_ops_ret) 270*4882a593Smuzhiyun { 271*4882a593Smuzhiyun char *error; 272*4882a593Smuzhiyun int glob_ret, i; 273*4882a593Smuzhiyun@@ -110,8 +110,8 @@ leave: 274*4882a593Smuzhiyun globfree(&globbuf); 275*4882a593Smuzhiyun } 276*4882a593Smuzhiyun 277*4882a593Smuzhiyun-void v4l2_plugin_cleanup(void *plugin_lib, void *plugin_priv, 278*4882a593Smuzhiyun- const struct libv4l_dev_ops *dev_ops) 279*4882a593Smuzhiyun+void v4l2_dyn_plugin_cleanup(void *plugin_lib, void *plugin_priv, 280*4882a593Smuzhiyun+ const struct libv4l_dev_ops *dev_ops) 281*4882a593Smuzhiyun { 282*4882a593Smuzhiyun if (plugin_lib) { 283*4882a593Smuzhiyun dev_ops->close(plugin_priv); 284*4882a593Smuzhiyun-- 285*4882a593Smuzhiyun2.20.1 286*4882a593Smuzhiyun 287