[prev in list] [next in list] [prev in thread] [next in thread]
List: linaro-mm-sig
Subject: [Linaro-mm-sig] Patch for compiling libv4l2 in Android 5.0
From: Paramanand Singh <paramanand.singh () linaro ! org>
Date: 2015-03-19 6:36:47
Message-ID: CAAJ_XrSQNg9um8PY=TwZRGbP5SQVONRRb-qG_K8O5Dq8rYCzVA () mail ! gmail ! com
[Download RAW message or body]
[Attachment #2 (multipart/alternative)]
libv4l2: Changes for compilation in Android 5.0
Added Android makefiles for libv4l2 and
libv4lconvert. Minor changes to include
android-config.h. Changed the plugin
loading mechanism to avoid using
unsupported glob.h header. Current mechanism
supports a list of plugin search paths
including /system/lib and /vendor/lib.
Signed-off-by: Paramanand Singh <paramanand.singh@linaro.org>
diff --git a/android-config.h b/android-config.h
index f474330..9f12b8f 100644
--- a/android-config.h
+++ b/android-config.h
@@ -1,3 +1,5 @@
+#ifndef __V4L_ANDROID_CONFIG_H__
+#define __V4L_ANDROID_CONFIG_H__
/* config.h. Generated from config.h.in by configure. */
/* config.h.in. Generated from configure.ac by autoheader. */
@@ -358,3 +360,4 @@ getsubopt (char **optionp, char *const *tokens, char
**valuep)
return -1;
}
+#endif
diff --git a/lib/Android.mk b/lib/Android.mk
new file mode 100644
index 0000000..2e43120
--- /dev/null
+++ b/lib/Android.mk
@@ -0,0 +1,4 @@
+LOCAL_PATH:= $(call my-dir)
+include $(CLEAR_VARS)
+
+include $(call all-makefiles-under,$(LOCAL_PATH))
diff --git a/lib/libv4l2/Android.mk b/lib/libv4l2/Android.mk
new file mode 100644
index 0000000..7d723fb
--- /dev/null
+++ b/lib/libv4l2/Android.mk
@@ -0,0 +1,31 @@
+LOCAL_PATH:= $(call my-dir)
+
+include $(CLEAR_VARS)
+
+LOCAL_SRC_FILES := \
+ log.c \
+ libv4l2.c \
+ v4l2convert.c \
+ v4l2-plugin-android.c
+
+LOCAL_CFLAGS += -Wno-missing-field-initializers
+LOCAL_CFLAGS += -Wno-sign-compare
+
+LOCAL_C_INCLUDES := \
+ $(LOCAL_PATH)/../include \
+ $(LOCAL_PATH)/../../include \
+ $(LOCAL_PATH)/../.. \
+ $(TOP)/bionic/libc/upstream-openbsd/lib/libc/gen
+
+LOCAL_SHARED_LIBRARIES := \
+ libutils \
+ libcutils \
+ libdl \
+ libssl \
+ libz
+
+LOCAL_STATIC_LIBRARIES := libv4l_convert
+LOCAL_MODULE := libv4l2
+LOCAL_MODULE_TAGS := optional
+
+include $(BUILD_SHARED_LIBRARY)
diff --git a/lib/libv4l2/libv4l2.c b/lib/libv4l2/libv4l2.c
index 966a000..70a6fd2 100644
--- a/lib/libv4l2/libv4l2.c
+++ b/lib/libv4l2/libv4l2.c
@@ -55,7 +55,11 @@
When modifications are made, one should be careful that this behavior is
preserved.
*/
+#ifdef ANDROID
+#include <android-config.h>
+#else
#include <config.h>
+#endif
#include <errno.h>
#include <stdarg.h>
#include <stdio.h>
diff --git a/lib/libv4l2/log.c b/lib/libv4l2/log.c
index d1042ed..9d3eab1 100644
--- a/lib/libv4l2/log.c
+++ b/lib/libv4l2/log.c
@@ -18,7 +18,11 @@
# Foundation, Inc., 51 Franklin Street, Suite 500, Boston, MA 02110-1335
USA
*/
+#ifdef ANDROID
+#include <android-config.h>
+#else
#include <config.h>
+#endif
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
diff --git a/lib/libv4l2/v4l2-plugin-android.c
b/lib/libv4l2/v4l2-plugin-android.c
new file mode 100644
index 0000000..66c75a3
--- /dev/null
+++ b/lib/libv4l2/v4l2-plugin-android.c
@@ -0,0 +1,152 @@
+/*
+* Copyright (C) 2010 Nokia Corporation <multimedia@maemo.org>
+
+* This program is free software; you can redistribute it and/or modify
+* it under the terms of the GNU Lesser General Public License as published
by
+* the Free Software Foundation; either version 2.1 of the License, or
+* (at your option) any later version.
+*
+* This program is distributed in the hope that it will be useful,
+* but WITHOUT ANY WARRANTY; without even the implied warranty of
+* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+* Lesser General Public License for more details.
+*
+* You should have received a copy of the GNU Lesser General Public License
+* along with this program; if not, write to the Free Software
+* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+*/
+
+#ifdef ANDROID
+#include <android-config.h>
+#else
+#include <config.h>
+#endif
+#include <stdarg.h>
+#include <dlfcn.h>
+#include <fcntl.h>
+#include <sys/stat.h>
+#include <sys/mman.h>
+#include <sys/types.h>
+#include <dirent.h>
+#include <stdlib.h>
+#include <string.h>
+#include "libv4l2.h"
+#include "libv4l2-priv.h"
+#include "libv4l-plugin.h"
+
+/* libv4l plugin support:
+ it is provided by functions v4l2_plugin_[open,close,etc].
+
+ When open() is called libv4l dlopens files in
/usr/lib[64]/libv4l/plugins
+ 1 at a time and call open callback passing through the applications
+ parameters unmodified.
+
+ If a plugin is relevant for the specified device node, it can indicate
so
+ by returning a value other then -1 (the actual file descriptor).
+ As soon as a plugin returns another value then -1 plugin loading stops
and
+ information about it (fd and corresponding library handle) is stored.
For
+ each function v4l2_[ioctl,read,close,etc] is called corresponding
+ v4l2_plugin_* function which looks if there is loaded plugin for that
file
+ and call it's callbacks.
+
+ v4l2_plugin_* function indicates by it's first argument if plugin was
used,
+ and if it was not then v4l2_* functions proceed with their usual
behavior.
+*/
+
+/* list of plugin search paths */
+static const char *g_plugin_search_paths[] = {
+ "/system/lib/libv4l/plugins",
+ "/vendor/lib/libv4l/plugins",
+ NULL /* list terminator */
+};
+
+void v4l2_plugin_init(int fd, void **plugin_lib_ret, void
**plugin_priv_ret,
+ const struct libv4l_dev_ops **dev_ops_ret)
+{
+ char *error;
+ void *plugin_library = NULL;
+ const struct libv4l_dev_ops *libv4l2_plugin = NULL;
+ DIR *plugin_dir = NULL;
+ struct dirent *entry;
+ char *suffix = NULL;
+ int length, i;
+ char filename[256];
+
+ /* initialize output params */
+ *dev_ops_ret = v4lconvert_get_default_dev_ops();
+ *plugin_lib_ret = NULL;
+ *plugin_priv_ret = NULL;
+
+ /* read the plugin directory for "*.so" files */
+ for (i = 0; g_plugin_search_paths[i] != NULL; i++) {
+ plugin_dir = opendir(g_plugin_search_paths[i]);
+ if (plugin_dir == NULL) {
+ V4L2_LOG_ERR("PLUGIN: opening plugin directory (%s)
failed\n",
+ g_plugin_search_paths[i]);
+ continue;
+ }
+
+ while (entry = readdir(plugin_dir)) {
+ /* get last 3 letter suffix from the filename */
+ length = strlen(entry->d_name);
+ if (length > 3)
+ suffix = entry->d_name + (length - 3);
+
+ if (!suffix || strcmp(suffix, ".so")) {
+ suffix = NULL; /* reset for next iteration
*/
+ continue;
+ }
+
+ /* load library and get desired symbol */
+ sprintf(filename, "%s/%s",
g_plugin_search_paths[i], entry->d_name);
+ V4L2_LOG("PLUGIN: dlopen(%s);\n", filename);
+ plugin_library = dlopen(filename, RTLD_LAZY);
+ if (!plugin_library)
+ continue;
+
+ dlerror(); /* Clear any existing error */
+ libv4l2_plugin = (struct libv4l_dev_ops *)
+ dlsym(plugin_library, "libv4l2_plugin");
+ error = dlerror();
+ if (error != NULL) {
+ V4L2_LOG_ERR("PLUGIN: dlsym failed: %s\n",
error);
+ dlclose(plugin_library);
+ continue;
+ }
+
+ if (!libv4l2_plugin->init ||
+ !libv4l2_plugin->close ||
+ !libv4l2_plugin->ioctl) {
+ V4L2_LOG("PLUGIN: does not have all
mandatory ops\n");
+ dlclose(plugin_library);
+ continue;
+ }
+
+ *plugin_priv_ret = libv4l2_plugin->init(fd);
+ if (!*plugin_priv_ret) {
+ V4L2_LOG("PLUGIN: plugin open() returned
NULL\n");
+ dlclose(plugin_library);
+ continue;
+ }
+
+ /* exit loop when a suitable plugin is found */
+ *plugin_lib_ret = plugin_library;
+ *dev_ops_ret = libv4l2_plugin;
+ break;
+ }
+ closedir(plugin_dir);
+
+ /* exit loop when a suitable plugin is found */
+ if (*plugin_lib_ret && *plugin_priv_ret && *dev_ops_ret)
+ break;
+ }
+}
+
+void v4l2_plugin_cleanup(void *plugin_lib, void *plugin_priv,
+ const struct libv4l_dev_ops *dev_ops)
+{
+ if (plugin_lib) {
+ dev_ops->close(plugin_priv);
+ dlclose(plugin_lib);
+ }
+}
diff --git a/lib/libv4l2/v4l2convert.c b/lib/libv4l2/v4l2convert.c
index 9b46ab8..d046834 100644
--- a/lib/libv4l2/v4l2convert.c
+++ b/lib/libv4l2/v4l2convert.c
@@ -25,7 +25,11 @@
#define _LARGEFILE64_SOURCE 1
+#ifdef ANDROID
+#include <android-config.h>
+#else
#include <config.h>
+#endif
#include <stdarg.h>
#include <stdlib.h>
#include <fcntl.h>
@@ -111,6 +115,7 @@ LIBV4L_PUBLIC int open64(const char *file, int oflag,
...)
}
#endif
+#ifndef ANDROID
LIBV4L_PUBLIC int close(int fd)
{
return v4l2_close(fd);
@@ -156,4 +161,4 @@ LIBV4L_PUBLIC int munmap(void *start, size_t length)
{
return v4l2_munmap(start, length);
}
-
+#endif
diff --git a/lib/libv4lconvert/Android.mk b/lib/libv4lconvert/Android.mk
new file mode 100644
index 0000000..99a136b
--- /dev/null
+++ b/lib/libv4lconvert/Android.mk
@@ -0,0 +1,53 @@
+LOCAL_PATH:= $(call my-dir)
+
+include $(CLEAR_VARS)
+
+LOCAL_SRC_FILES := \
+ bayer.c \
+ cpia1.c \
+ crop.c \
+ flip.c \
+ helper.c \
+ hm12.c \
+ jidctflt.c \
+ jl2005bcd.c \
+ jpeg.c \
+ jpeg_memsrcdest.c \
+ jpgl.c \
+ libv4lconvert.c \
+ mr97310a.c \
+ pac207.c \
+ rgbyuv.c \
+ se401.c \
+ sn9c10x.c \
+ sn9c2028-decomp.c \
+ sn9c20x.c \
+ spca501.c \
+ spca561-decompress.c \
+ sq905c.c \
+ stv0680.c \
+ tinyjpeg.c \
+ control/libv4lcontrol.c \
+ processing/autogain.c \
+ processing/gamma.c \
+ processing/libv4lprocessing.c \
+ processing/whitebalance.c \
+
+LOCAL_CFLAGS += -Wno-missing-field-initializers
+LOCAL_CFLAGS += -Wno-sign-compare
+
+LOCAL_C_INCLUDES := \
+ $(LOCAL_PATH)/../include \
+ $(LOCAL_PATH)/../../include \
+ $(LOCAL_PATH)/../.. \
+
+LOCAL_SHARED_LIBRARIES := \
+ libutils \
+ libcutils \
+ libdl \
+ libz
+
+LOCAL_MODULE := libv4l_convert
+LOCAL_MODULE_TAGS := optional
+
+include $(BUILD_STATIC_LIBRARY)
diff --git a/lib/libv4lconvert/control/libv4lcontrol.c
b/lib/libv4lconvert/control/libv4lcontrol.c
index 325616c..74102d9 100644
--- a/lib/libv4lconvert/control/libv4lcontrol.c
+++ b/lib/libv4lconvert/control/libv4lcontrol.c
@@ -362,7 +362,7 @@ static int v4lcontrol_get_usb_info(struct
v4lcontrol_data *data,
int *speed)
{
FILE *f;
- int i, minor;
+ int i, minor_dev;
struct stat st;
char sysfs_name[512];
char c, *s, buf[32];
@@ -388,8 +388,8 @@ static int v4lcontrol_get_usb_info(struct
v4lcontrol_data *data,
s = fgets(buf, sizeof(buf), f);
fclose(f);
- if (s && sscanf(buf, "%*d:%d%c", &minor, &c) == 2 &&
- c == '\n' && minor == minor(st.st_rdev))
+ if (s && sscanf(buf, "%*d:%d%c", &minor_dev, &c) == 2 &&
+ c == '\n' && minor_dev == minor(st.st_rdev))
break;
}
if (i == 256)
@@ -716,6 +716,7 @@ struct v4lcontrol_data *v4lcontrol_create(int fd, void
*dev_ops_priv,
if (shm_name[i] == '/')
shm_name[i] = '-';
+#ifndef ANDROID
/* Open the shared memory object identified by shm_name */
shm_fd = shm_open(shm_name, (O_CREAT | O_EXCL | O_RDWR), (S_IREAD |
S_IWRITE));
if (shm_fd >= 0)
@@ -738,6 +739,7 @@ struct v4lcontrol_data *v4lcontrol_create(int fd, void
*dev_ops_priv,
}
} else
perror("libv4lcontrol: error creating shm segment failed");
+#endif
/* Fall back to malloc */
if (data->shm_values == NULL) {
diff --git a/lib/libv4lconvert/jl2005bcd.c b/lib/libv4lconvert/jl2005bcd.c
index 14171a1..5a29830 100644
--- a/lib/libv4lconvert/jl2005bcd.c
+++ b/lib/libv4lconvert/jl2005bcd.c
@@ -23,7 +23,11 @@
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
USA
*/
-#include <config.h>
+#ifdef ANDROID
+#include <android-config.h>
+#else
+#include <config.h>
+#endif
#include <stdlib.h>
#include <string.h>
diff --git a/lib/libv4lconvert/jpeg.c b/lib/libv4lconvert/jpeg.c
index 0142d44..15f8dec 100644
--- a/lib/libv4lconvert/jpeg.c
+++ b/lib/libv4lconvert/jpeg.c
@@ -16,7 +16,11 @@
# Foundation, Inc., 51 Franklin Street, Suite 500, Boston, MA 02110-1335
USA
*/
+#ifdef ANDROID
+#include <android-config.h>
+#else
#include <config.h>
+#endif
#include <errno.h>
#include <stdlib.h>
#include "libv4lconvert-priv.h"
diff --git a/lib/libv4lconvert/jpeg_memsrcdest.c
b/lib/libv4lconvert/jpeg_memsrcdest.c
index b70af8e..323e7af 100644
--- a/lib/libv4lconvert/jpeg_memsrcdest.c
+++ b/lib/libv4lconvert/jpeg_memsrcdest.c
@@ -16,7 +16,11 @@
/* this is not a core library module, so it doesn't define JPEG_INTERNALS
*/
+#ifdef ANDROID
+#include <android-config.h>
+#else
#include <config.h>
+#endif
#include <stdlib.h>
#include <stdio.h>
diff --git a/lib/libv4lconvert/libv4lconvert-priv.h
b/lib/libv4lconvert/libv4lconvert-priv.h
index ac1391e..c19bbd4 100644
--- a/lib/libv4lconvert/libv4lconvert-priv.h
+++ b/lib/libv4lconvert/libv4lconvert-priv.h
@@ -19,7 +19,11 @@
#ifndef __LIBV4LCONVERT_PRIV_H
#define __LIBV4LCONVERT_PRIV_H
+#ifdef ANDROID
+#include <android-config.h>
+#else
#include <config.h>
+#endif
#include <stdio.h>
#include <stdint.h>
#include <sys/types.h>
diff --git a/lib/libv4lconvert/libv4lconvert.c
b/lib/libv4lconvert/libv4lconvert.c
index e4aa54a..004dc72 100644
--- a/lib/libv4lconvert/libv4lconvert.c
+++ b/lib/libv4lconvert/libv4lconvert.c
@@ -16,7 +16,11 @@
# Foundation, Inc., 51 Franklin Street, Suite 500, Boston, MA 02110-1335
USA
*/
+#ifdef ANDROID
+#include <android-config.h>
+#else
#include <config.h>
+#endif
#include <errno.h>
#include <string.h>
#include <stdlib.h>
diff --git a/lib/libv4lconvert/libv4lsyscall-priv.h
b/lib/libv4lconvert/libv4lsyscall-priv.h
index cdd38bc..f548fb2 100644
--- a/lib/libv4lconvert/libv4lsyscall-priv.h
+++ b/lib/libv4lconvert/libv4lsyscall-priv.h
@@ -36,7 +36,7 @@
#ifdef linux
#include <sys/time.h>
-#include <syscall.h>
+#include <sys/syscall.h>
#include <linux/types.h>
#include <linux/ioctl.h>
/* On 32 bits archs we always use mmap2, on 64 bits archs there is no
mmap2 */
@@ -62,6 +62,10 @@
typedef off_t __off_t;
#endif
+#if defined(ANDROID)
+typedef off_t __off_t;
+#endif
+
#undef SYS_OPEN
#undef SYS_CLOSE
#undef SYS_IOCTL
[Attachment #5 (text/html)]
<div dir="ltr"> libv4l2: Changes for compilation in Android 5.0<br><div \
class="gmail_quote"> <br>
Added Android makefiles for libv4l2 and<br>
libv4lconvert. Minor changes to include<br>
android-config.h. Changed the plugin<br>
loading mechanism to avoid using<br>
unsupported glob.h header. Current mechanism<br>
supports a list of plugin search paths<br>
including /system/lib and /vendor/lib.<br>
<br>
Signed-off-by: Paramanand Singh <<a \
href="mailto:paramanand.singh@linaro.org">paramanand.singh@linaro.org</a>><br> \
<br>
diff --git a/android-config.h b/android-config.h<br>
index f474330..9f12b8f 100644<br>
--- a/android-config.h<br>
+++ b/android-config.h<br>
@@ -1,3 +1,5 @@<br>
+#ifndef __V4L_ANDROID_CONFIG_H__<br>
+#define __V4L_ANDROID_CONFIG_H__<br>
/* config.h. Generated from <a href="http://config.h.in" \
target="_blank">config.h.in</a> by configure. */<br> /* <a \
href="http://config.h.in" target="_blank">config.h.in</a>. Generated from <a \
href="http://configure.ac" target="_blank">configure.ac</a> by autoheader. */<br> \
<br> @@ -358,3 +360,4 @@ getsubopt (char **optionp, char *const *tokens, char \
**valuep)<br> <br>
return -1;<br>
}<br>
+#endif<br>
diff --git a/lib/Android.mk b/lib/Android.mk<br>
new file mode 100644<br>
index 0000000..2e43120<br>
--- /dev/null<br>
+++ b/lib/Android.mk<br>
@@ -0,0 +1,4 @@<br>
+LOCAL_PATH:= $(call my-dir)<br>
+include $(CLEAR_VARS)<br>
+<br>
+include $(call all-makefiles-under,$(LOCAL_PATH))<br>
diff --git a/lib/libv4l2/Android.mk b/lib/libv4l2/Android.mk<br>
new file mode 100644<br>
index 0000000..7d723fb<br>
--- /dev/null<br>
+++ b/lib/libv4l2/Android.mk<br>
@@ -0,0 +1,31 @@<br>
+LOCAL_PATH:= $(call my-dir)<br>
+<br>
+include $(CLEAR_VARS)<br>
+<br>
+LOCAL_SRC_FILES := \<br>
+ log.c \<br>
+ libv4l2.c \<br>
+ v4l2convert.c \<br>
+ v4l2-plugin-android.c<br>
+<br>
+LOCAL_CFLAGS += -Wno-missing-field-initializers<br>
+LOCAL_CFLAGS += -Wno-sign-compare<br>
+<br>
+LOCAL_C_INCLUDES := \<br>
+ $(LOCAL_PATH)/../include \<br>
+ $(LOCAL_PATH)/../../include \<br>
+ $(LOCAL_PATH)/../.. \<br>
+ $(TOP)/bionic/libc/upstream-openbsd/lib/libc/gen<br>
+<br>
+LOCAL_SHARED_LIBRARIES := \<br>
+ libutils \<br>
+ libcutils \<br>
+ libdl \<br>
+ libssl \<br>
+ libz<br>
+<br>
+LOCAL_STATIC_LIBRARIES := libv4l_convert<br>
+LOCAL_MODULE := libv4l2<br>
+LOCAL_MODULE_TAGS := optional<br>
+<br>
+include $(BUILD_SHARED_LIBRARY)<br>
diff --git a/lib/libv4l2/libv4l2.c b/lib/libv4l2/libv4l2.c<br>
index 966a000..70a6fd2 100644<br>
--- a/lib/libv4l2/libv4l2.c<br>
+++ b/lib/libv4l2/libv4l2.c<br>
@@ -55,7 +55,11 @@<br>
When modifications are made, one should be careful that this behavior is<br>
preserved.<br>
*/<br>
+#ifdef ANDROID<br>
+#include <android-config.h><br>
+#else<br>
#include <config.h><br>
+#endif<br>
#include <errno.h><br>
#include <stdarg.h><br>
#include <stdio.h><br>
diff --git a/lib/libv4l2/log.c b/lib/libv4l2/log.c<br>
index d1042ed..9d3eab1 100644<br>
--- a/lib/libv4l2/log.c<br>
+++ b/lib/libv4l2/log.c<br>
@@ -18,7 +18,11 @@<br>
# Foundation, Inc., 51 Franklin Street, Suite 500, Boston, MA 02110-1335 \
USA<br>
*/<br>
<br>
+#ifdef ANDROID<br>
+#include <android-config.h><br>
+#else<br>
#include <config.h><br>
+#endif<br>
#include <stdio.h><br>
#include <stdlib.h><br>
#include <string.h><br>
diff --git a/lib/libv4l2/v4l2-plugin-android.c \
b/lib/libv4l2/v4l2-plugin-android.c<br> new file mode 100644<br>
index 0000000..66c75a3<br>
--- /dev/null<br>
+++ b/lib/libv4l2/v4l2-plugin-android.c<br>
@@ -0,0 +1,152 @@<br>
+/*<br>
+* Copyright (C) 2010 Nokia Corporation <<a \
href="mailto:multimedia@maemo.org">multimedia@maemo.org</a>><br> +<br>
+* This program is free software; you can redistribute it and/or modify<br>
+* it under the terms of the GNU Lesser General Public License as published by<br>
+* the Free Software Foundation; either version 2.1 of the License, or<br>
+* (at your option) any later version.<br>
+*<br>
+* This program is distributed in the hope that it will be useful,<br>
+* but WITHOUT ANY WARRANTY; without even the implied warranty of<br>
+* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU<br>
+* Lesser General Public License for more details.<br>
+*<br>
+* You should have received a copy of the GNU Lesser General Public License<br>
+* along with this program; if not, write to the Free Software<br>
+* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA<br>
+*/<br>
+<br>
+#ifdef ANDROID<br>
+#include <android-config.h><br>
+#else<br>
+#include <config.h><br>
+#endif<br>
+#include <stdarg.h><br>
+#include <dlfcn.h><br>
+#include <fcntl.h><br>
+#include <sys/stat.h><br>
+#include <sys/mman.h><br>
+#include <sys/types.h><br>
+#include <dirent.h><br>
+#include <stdlib.h><br>
+#include <string.h><br>
+#include "libv4l2.h"<br>
+#include "libv4l2-priv.h"<br>
+#include "libv4l-plugin.h"<br>
+<br>
+/* libv4l plugin support:<br>
+ it is provided by functions v4l2_plugin_[open,close,etc].<br>
+<br>
+ When open() is called libv4l dlopens files in /usr/lib[64]/libv4l/plugins<br>
+ 1 at a time and call open callback passing through the applications<br>
+ parameters unmodified.<br>
+<br>
+ If a plugin is relevant for the specified device node, it can indicate so<br>
+ by returning a value other then -1 (the actual file descriptor).<br>
+ As soon as a plugin returns another value then -1 plugin loading stops and<br>
+ information about it (fd and corresponding library handle) is stored. For<br>
+ each function v4l2_[ioctl,read,close,etc] is called corresponding<br>
+ v4l2_plugin_* function which looks if there is loaded plugin for that file<br>
+ and call it's callbacks.<br>
+<br>
+ v4l2_plugin_* function indicates by it's first argument if plugin was \
used,<br> + and if it was not then v4l2_* functions proceed with their usual \
behavior.<br> +*/<br>
+<br>
+/* list of plugin search paths */<br>
+static const char *g_plugin_search_paths[] = {<br>
+ "/system/lib/libv4l/plugins",<br>
+ "/vendor/lib/libv4l/plugins",<br>
+ NULL /* list terminator */<br>
+};<br>
+<br>
+void v4l2_plugin_init(int fd, void **plugin_lib_ret, void **plugin_priv_ret,<br>
+ const struct libv4l_dev_ops **dev_ops_ret)<br>
+{<br>
+ char *error;<br>
+ void *plugin_library = NULL;<br>
+ const struct libv4l_dev_ops *libv4l2_plugin = NULL;<br>
+ DIR *plugin_dir = NULL;<br>
+ struct dirent *entry;<br>
+ char *suffix = NULL;<br>
+ int length, i;<br>
+ char filename[256];<br>
+<br>
+ /* initialize output params */<br>
+ *dev_ops_ret = v4lconvert_get_default_dev_ops();<br>
+ *plugin_lib_ret = NULL;<br>
+ *plugin_priv_ret = NULL;<br>
+<br>
+ /* read the plugin directory for "*.so" files */<br>
+ for (i = 0; g_plugin_search_paths[i] != NULL; i++) {<br>
+ plugin_dir = opendir(g_plugin_search_paths[i]);<br>
+ if (plugin_dir == NULL) {<br>
+ V4L2_LOG_ERR("PLUGIN: opening plugin \
directory (%s) failed\n",<br> + \
g_plugin_search_paths[i]);<br> + continue;<br>
+ }<br>
+<br>
+ while (entry = readdir(plugin_dir)) {<br>
+ /* get last 3 letter suffix from the filename \
*/<br> + length = strlen(entry->d_name);<br>
+ if (length > 3)<br>
+ suffix = entry->d_name + (length - \
3);<br> +<br>
+ if (!suffix || strcmp(suffix, ".so")) \
{<br> + suffix = NULL; /* reset for \
next iteration */<br> + continue;<br>
+ }<br>
+<br>
+ /* load library and get desired symbol */<br>
+ sprintf(filename, "%s/%s", \
g_plugin_search_paths[i], entry->d_name);<br> + \
V4L2_LOG("PLUGIN: dlopen(%s);\n", filename);<br> + \
plugin_library = dlopen(filename, RTLD_LAZY);<br> + \
if (!plugin_library)<br> + \
continue;<br> +<br>
+ dlerror(); /* Clear any existing error */<br>
+ libv4l2_plugin = (struct libv4l_dev_ops *)<br>
+ dlsym(plugin_library, \
"libv4l2_plugin");<br> + error = \
dlerror();<br> + if (error != NULL) {<br>
+ V4L2_LOG_ERR("PLUGIN: dlsym \
failed: %s\n", error);<br> + \
dlclose(plugin_library);<br> + \
continue;<br> + }<br>
+<br>
+ if (!libv4l2_plugin->init ||<br>
+ !libv4l2_plugin->close ||<br>
+ !libv4l2_plugin->ioctl) {<br>
+ V4L2_LOG("PLUGIN: does not have \
all mandatory ops\n");<br> + \
dlclose(plugin_library);<br> + \
continue;<br> + }<br>
+<br>
+ *plugin_priv_ret = \
libv4l2_plugin->init(fd);<br> + if \
(!*plugin_priv_ret) {<br> + \
V4L2_LOG("PLUGIN: plugin open() returned NULL\n");<br> + \
dlclose(plugin_library);<br> + \
continue;<br> + }<br>
+<br>
+ /* exit loop when a suitable plugin is found \
*/<br> + *plugin_lib_ret = plugin_library;<br>
+ *dev_ops_ret = libv4l2_plugin;<br>
+ break;<br>
+ }<br>
+ closedir(plugin_dir);<br>
+<br>
+ /* exit loop when a suitable plugin is found */<br>
+ if (*plugin_lib_ret && *plugin_priv_ret && \
*dev_ops_ret)<br> + break;<br>
+ }<br>
+}<br>
+<br>
+void v4l2_plugin_cleanup(void *plugin_lib, void *plugin_priv,<br>
+ const struct libv4l_dev_ops *dev_ops)<br>
+{<br>
+ if (plugin_lib) {<br>
+ dev_ops->close(plugin_priv);<br>
+ dlclose(plugin_lib);<br>
+ }<br>
+}<br>
diff --git a/lib/libv4l2/v4l2convert.c b/lib/libv4l2/v4l2convert.c<br>
index 9b46ab8..d046834 100644<br>
--- a/lib/libv4l2/v4l2convert.c<br>
+++ b/lib/libv4l2/v4l2convert.c<br>
@@ -25,7 +25,11 @@<br>
<br>
#define _LARGEFILE64_SOURCE 1<br>
<br>
+#ifdef ANDROID<br>
+#include <android-config.h><br>
+#else<br>
#include <config.h><br>
+#endif<br>
#include <stdarg.h><br>
#include <stdlib.h><br>
#include <fcntl.h><br>
@@ -111,6 +115,7 @@ LIBV4L_PUBLIC int open64(const char *file, int oflag, ...)<br>
}<br>
#endif<br>
<br>
+#ifndef ANDROID<br>
LIBV4L_PUBLIC int close(int fd)<br>
{<br>
return v4l2_close(fd);<br>
@@ -156,4 +161,4 @@ LIBV4L_PUBLIC int munmap(void *start, size_t length)<br>
{<br>
return v4l2_munmap(start, length);<br>
}<br>
-<br>
+#endif<br>
diff --git a/lib/libv4lconvert/Android.mk b/lib/libv4lconvert/Android.mk<br>
new file mode 100644<br>
index 0000000..99a136b<br>
--- /dev/null<br>
+++ b/lib/libv4lconvert/Android.mk<br>
@@ -0,0 +1,53 @@<br>
+LOCAL_PATH:= $(call my-dir)<br>
+<br>
+include $(CLEAR_VARS)<br>
+<br>
+LOCAL_SRC_FILES := \<br>
+ bayer.c \<br>
+ cpia1.c \<br>
+ crop.c \<br>
+ flip.c \<br>
+ helper.c \<br>
+ hm12.c \<br>
+ jidctflt.c \<br>
+ jl2005bcd.c \<br>
+ jpeg.c \<br>
+ jpeg_memsrcdest.c \<br>
+ jpgl.c \<br>
+ libv4lconvert.c \<br>
+ mr97310a.c \<br>
+ pac207.c \<br>
+ rgbyuv.c \<br>
+ se401.c \<br>
+ sn9c10x.c \<br>
+ sn9c2028-decomp.c \<br>
+ sn9c20x.c \<br>
+ spca501.c \<br>
+ spca561-decompress.c \<br>
+ sq905c.c \<br>
+ stv0680.c \<br>
+ tinyjpeg.c \<br>
+ control/libv4lcontrol.c \<br>
+ processing/autogain.c \<br>
+ processing/gamma.c \<br>
+ processing/libv4lprocessing.c \<br>
+ processing/whitebalance.c \<br>
+<br>
+LOCAL_CFLAGS += -Wno-missing-field-initializers<br>
+LOCAL_CFLAGS += -Wno-sign-compare<br>
+<br>
+LOCAL_C_INCLUDES := \<br>
+ $(LOCAL_PATH)/../include \<br>
+ $(LOCAL_PATH)/../../include \<br>
+ $(LOCAL_PATH)/../.. \<br>
+<br>
+LOCAL_SHARED_LIBRARIES := \<br>
+ libutils \<br>
+ libcutils \<br>
+ libdl \<br>
+ libz<br>
+<br>
+LOCAL_MODULE := libv4l_convert<br>
+LOCAL_MODULE_TAGS := optional<br>
+<br>
+include $(BUILD_STATIC_LIBRARY)<br>
diff --git a/lib/libv4lconvert/control/libv4lcontrol.c \
b/lib/libv4lconvert/control/libv4lcontrol.c<br> index 325616c..74102d9 100644<br>
--- a/lib/libv4lconvert/control/libv4lcontrol.c<br>
+++ b/lib/libv4lconvert/control/libv4lcontrol.c<br>
@@ -362,7 +362,7 @@ static int v4lcontrol_get_usb_info(struct v4lcontrol_data \
*data,<br> int *speed)<br>
{<br>
FILE *f;<br>
- int i, minor;<br>
+ int i, minor_dev;<br>
struct stat st;<br>
char sysfs_name[512];<br>
char c, *s, buf[32];<br>
@@ -388,8 +388,8 @@ static int v4lcontrol_get_usb_info(struct v4lcontrol_data \
*data,<br> s = fgets(buf, sizeof(buf), f);<br>
fclose(f);<br>
<br>
- if (s && sscanf(buf, "%*d:%d%c", \
&minor, &c) == 2 &&<br>
- c == '\n' && minor == \
minor(st.st_rdev))<br> + if (s && sscanf(buf, \
"%*d:%d%c", &minor_dev, &c) == 2 &&<br> + \
c == '\n' && minor_dev == minor(st.st_rdev))<br> break;<br>
}<br>
if (i == 256)<br>
@@ -716,6 +716,7 @@ struct v4lcontrol_data *v4lcontrol_create(int fd, void \
*dev_ops_priv,<br> if (shm_name[i] == '/')<br>
shm_name[i] = '-';<br>
<br>
+#ifndef ANDROID<br>
/* Open the shared memory object identified by shm_name */<br>
shm_fd = shm_open(shm_name, (O_CREAT | O_EXCL | O_RDWR), (S_IREAD | \
S_IWRITE));<br> if (shm_fd >= 0)<br>
@@ -738,6 +739,7 @@ struct v4lcontrol_data *v4lcontrol_create(int fd, void \
*dev_ops_priv,<br> }<br>
} else<br>
perror("libv4lcontrol: error creating shm segment \
failed");<br> +#endif<br>
<br>
/* Fall back to malloc */<br>
if (data->shm_values == NULL) {<br>
diff --git a/lib/libv4lconvert/jl2005bcd.c b/lib/libv4lconvert/jl2005bcd.c<br>
index 14171a1..5a29830 100644<br>
--- a/lib/libv4lconvert/jl2005bcd.c<br>
+++ b/lib/libv4lconvert/jl2005bcd.c<br>
@@ -23,7 +23,11 @@<br>
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA<br>
*/<br>
<br>
-#include <config.h><br>
+#ifdef ANDROID<br>
+#include <android-config.h><br>
+#else<br>
+#include <config.h><br>
+#endif<br>
#include <stdlib.h><br>
#include <string.h><br>
<br>
diff --git a/lib/libv4lconvert/jpeg.c b/lib/libv4lconvert/jpeg.c<br>
index 0142d44..15f8dec 100644<br>
--- a/lib/libv4lconvert/jpeg.c<br>
+++ b/lib/libv4lconvert/jpeg.c<br>
@@ -16,7 +16,11 @@<br>
# Foundation, Inc., 51 Franklin Street, Suite 500, Boston, MA 02110-1335 \
USA<br>
*/<br>
<br>
+#ifdef ANDROID<br>
+#include <android-config.h><br>
+#else<br>
#include <config.h><br>
+#endif<br>
#include <errno.h><br>
#include <stdlib.h><br>
#include "libv4lconvert-priv.h"<br>
diff --git a/lib/libv4lconvert/jpeg_memsrcdest.c \
b/lib/libv4lconvert/jpeg_memsrcdest.c<br> index b70af8e..323e7af 100644<br>
--- a/lib/libv4lconvert/jpeg_memsrcdest.c<br>
+++ b/lib/libv4lconvert/jpeg_memsrcdest.c<br>
@@ -16,7 +16,11 @@<br>
<br>
/* this is not a core library module, so it doesn't define JPEG_INTERNALS \
*/<br> <br>
+#ifdef ANDROID<br>
+#include <android-config.h><br>
+#else<br>
#include <config.h><br>
+#endif<br>
#include <stdlib.h><br>
#include <stdio.h><br>
<br>
diff --git a/lib/libv4lconvert/libv4lconvert-priv.h \
b/lib/libv4lconvert/libv4lconvert-priv.h<br> index ac1391e..c19bbd4 100644<br>
--- a/lib/libv4lconvert/libv4lconvert-priv.h<br>
+++ b/lib/libv4lconvert/libv4lconvert-priv.h<br>
@@ -19,7 +19,11 @@<br>
#ifndef __LIBV4LCONVERT_PRIV_H<br>
#define __LIBV4LCONVERT_PRIV_H<br>
<br>
+#ifdef ANDROID<br>
+#include <android-config.h><br>
+#else<br>
#include <config.h><br>
+#endif<br>
#include <stdio.h><br>
#include <stdint.h><br>
#include <sys/types.h><br>
diff --git a/lib/libv4lconvert/libv4lconvert.c \
b/lib/libv4lconvert/libv4lconvert.c<br> index e4aa54a..004dc72 100644<br>
--- a/lib/libv4lconvert/libv4lconvert.c<br>
+++ b/lib/libv4lconvert/libv4lconvert.c<br>
@@ -16,7 +16,11 @@<br>
# Foundation, Inc., 51 Franklin Street, Suite 500, Boston, MA 02110-1335 \
USA<br>
*/<br>
<br>
+#ifdef ANDROID<br>
+#include <android-config.h><br>
+#else<br>
#include <config.h><br>
+#endif<br>
#include <errno.h><br>
#include <string.h><br>
#include <stdlib.h><br>
diff --git a/lib/libv4lconvert/libv4lsyscall-priv.h \
b/lib/libv4lconvert/libv4lsyscall-priv.h<br> index cdd38bc..f548fb2 100644<br>
--- a/lib/libv4lconvert/libv4lsyscall-priv.h<br>
+++ b/lib/libv4lconvert/libv4lsyscall-priv.h<br>
@@ -36,7 +36,7 @@<br>
<br>
#ifdef linux<br>
#include <sys/time.h><br>
-#include <syscall.h><br>
+#include <sys/syscall.h><br>
#include <linux/types.h><br>
#include <linux/ioctl.h><br>
/* On 32 bits archs we always use mmap2, on 64 bits archs there is no mmap2 */<br>
@@ -62,6 +62,10 @@<br>
typedef off_t __off_t;<br>
#endif<br>
<br>
+#if defined(ANDROID)<br>
+typedef off_t __off_t;<br>
+#endif<br>
+<br>
#undef SYS_OPEN<br>
#undef SYS_CLOSE<br>
#undef SYS_IOCTL<br>
</div><br></div>
_______________________________________________
Linaro-mm-sig mailing list
Linaro-mm-sig@lists.linaro.org
http://lists.linaro.org/mailman/listinfo/linaro-mm-sig
[prev in list] [next in list] [prev in thread] [next in thread]
Configure |
About |
News |
Add a list |
Sponsored by KoreLogic