From patchwork Thu Mar 19 06:24:47 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Paramanand Singh X-Patchwork-Id: 46327 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-wi0-f197.google.com (mail-wi0-f197.google.com [209.85.212.197]) by ip-10-151-82-157.ec2.internal (Postfix) with ESMTPS id B0B2D2159D for ; Wed, 25 Mar 2015 16:59:37 +0000 (UTC) Received: by wivr20 with SMTP id r20sf6954098wiv.0 for ; Wed, 25 Mar 2015 09:59:37 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:delivered-to:mime-version:date:message-id:from :to:cc:subject:precedence:list-id:list-unsubscribe:list-archive :list-post:list-help:list-subscribe:content-type:errors-to:sender :x-original-sender:x-original-authentication-results:mailing-list; bh=XTJ9Sw/J45UEidD0gOR+/uEgGZPLq/6WBqVtTBoRnFE=; b=h85QJKPhCoz4nyjfg/YX1vDqRAfuAUJKTucqYRBcpkWgCLLoW9mJmoe4tOt4+pdyJM SbiaM9nVVgaQTjB5dA+14nQbN8lOk4hpkXi9xGaIYtwBsO6jUviuLtyf05SOxYNrmsOh GJ7zh0zj35d1H/vgecpjdE4IelLQvBdSCFWdzcFFyDB3hP2wGF2IqYkrsrXx/pQmaX7u Rbux6Yt8nUc/SAcv1im5doclbCTzX7qH5saQXi48zItMaQTtkRBj1QFNIo55lxRcLSmp 6GeakJPPfNFmRefJh/URRjNTmvnyJVutNtfsnRWLVtzy/eR8+S1nzILDZ5ItIimQ0UdV 3bNw== X-Gm-Message-State: ALoCoQnWzvKxLFQbLbPbkSc1rc3S7gTtIV2rZfnY5hPqUDDNTEvd+N3tGnan2VOZukwauf1I27jX X-Received: by 10.194.95.67 with SMTP id di3mr2329848wjb.0.1427302776983; Wed, 25 Mar 2015 09:59:36 -0700 (PDT) X-BeenThere: patchwork-forward@linaro.org Received: by 10.152.42.206 with SMTP id q14ls150086lal.49.gmail; Wed, 25 Mar 2015 09:59:36 -0700 (PDT) X-Received: by 10.112.73.104 with SMTP id k8mr9165636lbv.120.1427302776778; Wed, 25 Mar 2015 09:59:36 -0700 (PDT) Received: from mail-lb0-f172.google.com (mail-lb0-f172.google.com. [209.85.217.172]) by mx.google.com with ESMTPS id bd15si2442254lab.132.2015.03.25.09.59.36 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 25 Mar 2015 09:59:36 -0700 (PDT) Received-SPF: pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.217.172 as permitted sender) client-ip=209.85.217.172; Received: by lbcmq2 with SMTP id mq2so22388006lbc.0 for ; Wed, 25 Mar 2015 09:59:36 -0700 (PDT) X-Received: by 10.152.8.161 with SMTP id s1mr867245laa.41.1427302776105; Wed, 25 Mar 2015 09:59:36 -0700 (PDT) X-Forwarded-To: patchwork-forward@linaro.org X-Forwarded-For: patch@linaro.org patchwork-forward@linaro.org Delivered-To: patches@linaro.org Received: by 10.112.57.201 with SMTP id k9csp85913lbq; Wed, 25 Mar 2015 09:59:35 -0700 (PDT) X-Received: by 10.180.38.15 with SMTP id c15mr40010386wik.74.1427302774774; Wed, 25 Mar 2015 09:59:34 -0700 (PDT) Received: from ip-10-35-177-41.ec2.internal (lists.linaro.org. [54.225.227.206]) by mx.google.com with ESMTPS id nj10si23529361wic.103.2015.03.25.09.59.04 (version=TLSv1 cipher=RC4-SHA bits=128/128); Wed, 25 Mar 2015 09:59:34 -0700 (PDT) Received-SPF: none (google.com: linaro-mm-sig-bounces@lists.linaro.org does not designate permitted sender hosts) client-ip=54.225.227.206; Received: from localhost ([127.0.0.1] helo=ip-10-35-177-41.ec2.internal) by ip-10-35-177-41.ec2.internal with esmtp (Exim 4.76) (envelope-from ) id 1Yaodx-00072D-OS; Wed, 25 Mar 2015 16:59:01 +0000 Received: from mail-ig0-f173.google.com ([209.85.213.173]) by ip-10-35-177-41.ec2.internal with esmtp (Exim 4.76) (envelope-from ) id 1YYTsz-0005DZ-8u for linaro-mm-sig@lists.linaro.org; Thu, 19 Mar 2015 06:24:53 +0000 Received: by igcau2 with SMTP id au2so84412423igc.0 for ; Wed, 18 Mar 2015 23:24:48 -0700 (PDT) MIME-Version: 1.0 X-Received: by 10.107.165.68 with SMTP id o65mr117776514ioe.56.1426746287829; Wed, 18 Mar 2015 23:24:47 -0700 (PDT) Received: by 10.65.14.164 with HTTP; Wed, 18 Mar 2015 23:24:47 -0700 (PDT) Date: Thu, 19 Mar 2015 11:54:47 +0530 Message-ID: From: Paramanand Singh To: linux-media@vger.kernel.org X-Mailman-Approved-At: Wed, 25 Mar 2015 16:58:56 +0000 Cc: Linaro MM SIG Mailman List Subject: [Linaro-mm-sig] Patch for compiling libv4l2 in Android 5.0 X-BeenThere: linaro-mm-sig@lists.linaro.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: , List-Help: , List-Subscribe: , Errors-To: linaro-mm-sig-bounces@lists.linaro.org Sender: linaro-mm-sig-bounces@lists.linaro.org X-Removed-Original-Auth: Dkim didn't pass. X-Original-Sender: paramanand.singh@linaro.org X-Original-Authentication-Results: mx.google.com; spf=pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.217.172 as permitted sender) smtp.mail=patch+caf_=patchwork-forward=linaro.org@linaro.org Mailing-list: list patchwork-forward@linaro.org; contact patchwork-forward+owners@linaro.org X-Google-Group-Id: 836684582541 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 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 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 +#else #include +#endif #include #include #include 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 +#else #include +#endif #include #include #include 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 + +* 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 +#else +#include +#endif +#include +#include +#include +#include +#include +#include +#include +#include +#include +#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 +#else #include +#endif #include #include #include @@ -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 +#ifdef ANDROID +#include +#else +#include +#endif #include #include 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 +#else #include +#endif #include #include #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 +#else #include +#endif #include #include 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 +#else #include +#endif #include #include #include 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 +#else #include +#endif #include #include #include 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 -#include +#include #include #include /* On 32 bits archs we always use mmap2, on 64 bits archs there is no