summaryrefslogtreecommitdiffstats
path: root/android-utils
diff options
context:
space:
mode:
authorMamadou DIOP <bossiel@yahoo.fr>2015-08-17 01:56:35 +0200
committerMamadou DIOP <bossiel@yahoo.fr>2015-08-17 01:56:35 +0200
commit631fffee8a28b1bec5ed1f1d26a20e0135967f99 (patch)
tree74afe3bf3efe15aa82bcd0272b2b0f4d48c2d837 /android-utils
parent7908865936604036e6f200f1b5e069f8752f3a3a (diff)
downloaddoubango-631fffee8a28b1bec5ed1f1d26a20e0135967f99.zip
doubango-631fffee8a28b1bec5ed1f1d26a20e0135967f99.tar.gz
-
Diffstat (limited to 'android-utils')
-rw-r--r--android-utils/api.cxx12
-rw-r--r--android-utils/api.h32
-rw-r--r--android-utils/api.i14
-rw-r--r--android-utils/api.sh5
-rw-r--r--android-utils/buildAll.sh14
-rw-r--r--android-utils/cpu-features.c555
-rw-r--r--android-utils/cpu-features.h69
-rw-r--r--android-utils/droid-makefile52
-rw-r--r--android-utils/java/AndroidUtils.java50
-rw-r--r--android-utils/java/CpuFamily_t.java53
-rw-r--r--android-utils/java/CpuFeatures_t.java53
-rw-r--r--android-utils/java/utils.java12
-rw-r--r--android-utils/java/utilsJNI.java16
-rw-r--r--android-utils/makefile20
-rw-r--r--android-utils/utils_wrap.cxx502
-rw-r--r--android-utils/utils_wrap.h15
16 files changed, 1474 insertions, 0 deletions
diff --git a/android-utils/api.cxx b/android-utils/api.cxx
new file mode 100644
index 0000000..d9573c4
--- /dev/null
+++ b/android-utils/api.cxx
@@ -0,0 +1,12 @@
+#include "api.h"
+#include "cpu-features.h"
+
+uint64_t AndroidUtils::getCpuFamily()
+{
+ return (uint64_t)android_getCpuFamily();
+}
+
+uint64_t AndroidUtils::getCpuFeatures()
+{
+ return (uint64_t)android_getCpuFeatures();
+} \ No newline at end of file
diff --git a/android-utils/api.h b/android-utils/api.h
new file mode 100644
index 0000000..0b9dc54
--- /dev/null
+++ b/android-utils/api.h
@@ -0,0 +1,32 @@
+#ifndef ANDROID_UTILS_API_H
+#define ANDROID_UTILS_API_H
+
+#include <stdint.h>
+
+typedef enum CpuFamily_e
+{
+ UNKNOWN = 0,
+ ARM,
+ X86
+}
+CpuFamily_t;
+
+typedef enum CpuFeatures_e
+{
+ ARMv7 = 1,
+ VFPv3 = 2,
+ NEON = 4
+}
+CpuFeatures_t;
+
+class AndroidUtils
+{
+public:
+ AndroidUtils(){};
+ virtual ~AndroidUtils(){};
+
+ static uint64_t getCpuFamily();
+ static uint64_t getCpuFeatures();
+};
+
+#endif /* ANDROID_UTILS_API_H */
diff --git a/android-utils/api.i b/android-utils/api.i
new file mode 100644
index 0000000..b09a3ac
--- /dev/null
+++ b/android-utils/api.i
@@ -0,0 +1,14 @@
+%module utils
+%module(directors="1") utils
+
+%include "enums.swg"
+%include <stdint.i>
+%javaconst(1);
+
+%{
+#include "api.h"
+%}
+
+%nodefaultctor;
+%include "api.h"
+%clearnodefaultctor;
diff --git a/android-utils/api.sh b/android-utils/api.sh
new file mode 100644
index 0000000..64c3ebb
--- /dev/null
+++ b/android-utils/api.sh
@@ -0,0 +1,5 @@
+swig -c++ -java -package org.doubango.utils -outdir ./java -o ./utils_wrap.cxx ./api.i
+
+sed -i 's/dynamic_cast/static_cast/g' ./utils_wrap.cxx
+sed -i 's/AttachCurrentThread((void \*\*)/AttachCurrentThread((JNIEnv \*\*)/g' ./utils_wrap.cxx
+sed -i 's/AttachCurrentThreadAsDaemon((void \*\*)/AttachCurrentThreadAsDaemon((JNIEnv \*\*)/g' ./utils_wrap.cxx \ No newline at end of file
diff --git a/android-utils/buildAll.sh b/android-utils/buildAll.sh
new file mode 100644
index 0000000..45260ff
--- /dev/null
+++ b/android-utils/buildAll.sh
@@ -0,0 +1,14 @@
+#!/bin/bash
+# Build Android Utils for Google Android Systems
+
+for IS_NEON in no yes
+do
+
+for project in utils
+do
+ echo -e building "$project....\n"
+ make PROJECT=$project clean
+ make PROJECT=$project BT=shared NEON=$IS_NEON all
+done
+
+done
diff --git a/android-utils/cpu-features.c b/android-utils/cpu-features.c
new file mode 100644
index 0000000..70f5545
--- /dev/null
+++ b/android-utils/cpu-features.c
@@ -0,0 +1,555 @@
+/*
+ * Copyright (C) 2010 The Android Open Source Project
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * * Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * * Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in
+ * the documentation and/or other materials provided with the
+ * distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
+ * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
+ * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
+ * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
+ * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
+ * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
+ * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
+ * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ */
+
+/* ChangeLog for this library:
+ *
+ * NDK r7c: Fix CPU count computation. The old method only reported the
+ * number of _active_ CPUs when the library was initialized,
+ * which could be less than the real total.
+ *
+ * NDK r5: Handle buggy kernels which report a CPU Architecture number of 7
+ * for an ARMv6 CPU (see below).
+ *
+ * Handle kernels that only report 'neon', and not 'vfpv3'
+ * (VFPv3 is mandated by the ARM architecture is Neon is implemented)
+ *
+ * Handle kernels that only report 'vfpv3d16', and not 'vfpv3'
+ *
+ * Fix x86 compilation. Report ANDROID_CPU_FAMILY_X86 in
+ * android_getCpuFamily().
+ *
+ * NDK r4: Initial release
+ */
+#include <sys/system_properties.h>
+#ifdef __arm__
+#include <machine/cpu-features.h>
+#endif
+#include <pthread.h>
+#include "cpu-features.h"
+#include <stdio.h>
+#include <stdlib.h>
+#include <fcntl.h>
+#include <errno.h>
+
+static pthread_once_t g_once;
+static AndroidCpuFamily g_cpuFamily;
+static uint64_t g_cpuFeatures;
+static int g_cpuCount;
+
+static const int android_cpufeatures_debug = 0;
+
+#ifdef __arm__
+# define DEFAULT_CPU_FAMILY ANDROID_CPU_FAMILY_ARM
+#elif defined __i386__
+# define DEFAULT_CPU_FAMILY ANDROID_CPU_FAMILY_X86
+#else
+# define DEFAULT_CPU_FAMILY ANDROID_CPU_FAMILY_UNKNOWN
+#endif
+
+#define D(...) \
+ do { \
+ if (android_cpufeatures_debug) { \
+ printf(__VA_ARGS__); fflush(stdout); \
+ } \
+ } while (0)
+
+#ifdef __i386__
+static __inline__ void x86_cpuid(int func, int values[4])
+{
+ int a, b, c, d;
+ /* We need to preserve ebx since we're compiling PIC code */
+ /* this means we can't use "=b" for the second output register */
+ __asm__ __volatile__ ( \
+ "push %%ebx\n"
+ "cpuid\n" \
+ "mov %1, %%ebx\n"
+ "pop %%ebx\n"
+ : "=a" (a), "=r" (b), "=c" (c), "=d" (d) \
+ : "a" (func) \
+ );
+ values[0] = a;
+ values[1] = b;
+ values[2] = c;
+ values[3] = d;
+}
+#endif
+
+/* Read the content of /proc/cpuinfo into a user-provided buffer.
+ * Return the length of the data, or -1 on error. Does *not*
+ * zero-terminate the content. Will not read more
+ * than 'buffsize' bytes.
+ */
+static int
+read_file(const char* pathname, char* buffer, size_t buffsize)
+{
+ int fd, len;
+
+ fd = open(pathname, O_RDONLY);
+ if (fd < 0)
+ return -1;
+
+ do {
+ len = read(fd, buffer, buffsize);
+ } while (len < 0 && errno == EINTR);
+
+ close(fd);
+
+ return len;
+}
+
+/* Extract the content of a the first occurence of a given field in
+ * the content of /proc/cpuinfo and return it as a heap-allocated
+ * string that must be freed by the caller.
+ *
+ * Return NULL if not found
+ */
+static char*
+extract_cpuinfo_field(char* buffer, int buflen, const char* field)
+{
+ int fieldlen = strlen(field);
+ char* bufend = buffer + buflen;
+ char* result = NULL;
+ int len, ignore;
+ const char *p, *q;
+
+ /* Look for first field occurence, and ensures it starts the line.
+ */
+ p = buffer;
+ bufend = buffer + buflen;
+ for (;;) {
+ p = memmem(p, bufend-p, field, fieldlen);
+ if (p == NULL)
+ goto EXIT;
+
+ if (p == buffer || p[-1] == '\n')
+ break;
+
+ p += fieldlen;
+ }
+
+ /* Skip to the first column followed by a space */
+ p += fieldlen;
+ p = memchr(p, ':', bufend-p);
+ if (p == NULL || p[1] != ' ')
+ goto EXIT;
+
+ /* Find the end of the line */
+ p += 2;
+ q = memchr(p, '\n', bufend-p);
+ if (q == NULL)
+ q = bufend;
+
+ /* Copy the line into a heap-allocated buffer */
+ len = q-p;
+ result = malloc(len+1);
+ if (result == NULL)
+ goto EXIT;
+
+ memcpy(result, p, len);
+ result[len] = '\0';
+
+EXIT:
+ return result;
+}
+
+/* Like strlen(), but for constant string literals */
+#define STRLEN_CONST(x) ((sizeof(x)-1)
+
+
+/* Checks that a space-separated list of items contains one given 'item'.
+ * Returns 1 if found, 0 otherwise.
+ */
+static int
+has_list_item(const char* list, const char* item)
+{
+ const char* p = list;
+ int itemlen = strlen(item);
+
+ if (list == NULL)
+ return 0;
+
+ while (*p) {
+ const char* q;
+
+ /* skip spaces */
+ while (*p == ' ' || *p == '\t')
+ p++;
+
+ /* find end of current list item */
+ q = p;
+ while (*q && *q != ' ' && *q != '\t')
+ q++;
+
+ if (itemlen == q-p && !memcmp(p, item, itemlen))
+ return 1;
+
+ /* skip to next item */
+ p = q;
+ }
+ return 0;
+}
+
+/* Parse an decimal integer starting from 'input', but not going further
+ * than 'limit'. Return the value into '*result'.
+ *
+ * NOTE: Does not skip over leading spaces, or deal with sign characters.
+ * NOTE: Ignores overflows.
+ *
+ * The function returns NULL in case of error (bad format), or the new
+ * position after the decimal number in case of success (which will always
+ * be <= 'limit').
+ */
+static const char*
+parse_decimal(const char* input, const char* limit, int* result)
+{
+ const char* p = input;
+ int val = 0;
+ while (p < limit) {
+ int d = (*p - '0');
+ if ((unsigned)d >= 10U)
+ break;
+ val = val*10 + d;
+ p++;
+ }
+ if (p == input)
+ return NULL;
+
+ *result = val;
+ return p;
+}
+
+/* This small data type is used to represent a CPU list / mask, as read
+ * from sysfs on Linux. See http://www.kernel.org/doc/Documentation/cputopology.txt
+ *
+ * For now, we don't expect more than 32 cores on mobile devices, so keep
+ * everything simple.
+ */
+typedef struct {
+ uint32_t mask;
+} CpuList;
+
+static __inline__ void
+cpulist_init(CpuList* list) {
+ list->mask = 0;
+}
+
+static __inline__ void
+cpulist_and(CpuList* list1, CpuList* list2) {
+ list1->mask &= list2->mask;
+}
+
+static __inline__ void
+cpulist_set(CpuList* list, int index) {
+ if ((unsigned)index < 32) {
+ list->mask |= (uint32_t)(1U << index);
+ }
+}
+
+static __inline__ int
+cpulist_count(CpuList* list) {
+ return __builtin_popcount(list->mask);
+}
+
+/* Parse a textual list of cpus and store the result inside a CpuList object.
+ * Input format is the following:
+ * - comma-separated list of items (no spaces)
+ * - each item is either a single decimal number (cpu index), or a range made
+ * of two numbers separated by a single dash (-). Ranges are inclusive.
+ *
+ * Examples: 0
+ * 2,4-127,128-143
+ * 0-1
+ */
+static void
+cpulist_parse(CpuList* list, const char* line, int line_len)
+{
+ const char* p = line;
+ const char* end = p + line_len;
+ const char* q;
+
+ /* NOTE: the input line coming from sysfs typically contains a
+ * trailing newline, so take care of it in the code below
+ */
+ while (p < end && *p != '\n')
+ {
+ int val, start_value, end_value;
+
+ /* Find the end of current item, and put it into 'q' */
+ q = memchr(p, ',', end-p);
+ if (q == NULL) {
+ q = end;
+ }
+
+ /* Get first value */
+ p = parse_decimal(p, q, &start_value);
+ if (p == NULL)
+ goto BAD_FORMAT;
+
+ end_value = start_value;
+
+ /* If we're not at the end of the item, expect a dash and
+ * and integer; extract end value.
+ */
+ if (p < q && *p == '-') {
+ p = parse_decimal(p+1, q, &end_value);
+ if (p == NULL)
+ goto BAD_FORMAT;
+ }
+
+ /* Set bits CPU list bits */
+ for (val = start_value; val <= end_value; val++) {
+ cpulist_set(list, val);
+ }
+
+ /* Jump to next item */
+ p = q;
+ if (p < end)
+ p++;
+ }
+
+BAD_FORMAT:
+ ;
+}
+
+/* Read a CPU list from one sysfs file */
+static void
+cpulist_read_from(CpuList* list, const char* filename)
+{
+ char file[64];
+ int filelen;
+
+ cpulist_init(list);
+
+ filelen = read_file(filename, file, sizeof file);
+ if (filelen < 0) {
+ D("Could not read %s: %s\n", filename, strerror(errno));
+ return;
+ }
+
+ cpulist_parse(list, file, filelen);
+}
+
+/* Return the number of cpus present on a given device.
+ *
+ * To handle all weird kernel configurations, we need to compute the
+ * intersection of the 'present' and 'possible' CPU lists and count
+ * the result.
+ */
+static int
+get_cpu_count(void)
+{
+ CpuList cpus_present[1];
+ CpuList cpus_possible[1];
+
+ cpulist_read_from(cpus_present, "/sys/devices/system/cpu/present");
+ cpulist_read_from(cpus_possible, "/sys/devices/system/cpu/possible");
+
+ /* Compute the intersection of both sets to get the actual number of
+ * CPU cores that can be used on this device by the kernel.
+ */
+ cpulist_and(cpus_present, cpus_possible);
+
+ return cpulist_count(cpus_present);
+}
+
+static void
+android_cpuInit(void)
+{
+ char cpuinfo[4096];
+ int cpuinfo_len;
+
+ g_cpuFamily = DEFAULT_CPU_FAMILY;
+ g_cpuFeatures = 0;
+ g_cpuCount = 1;
+
+ cpuinfo_len = read_file("/proc/cpuinfo", cpuinfo, sizeof cpuinfo);
+ D("cpuinfo_len is (%d):\n%.*s\n", cpuinfo_len,
+ cpuinfo_len >= 0 ? cpuinfo_len : 0, cpuinfo);
+
+ if (cpuinfo_len < 0) /* should not happen */ {
+ return;
+ }
+
+ /* Count the CPU cores, the value may be 0 for single-core CPUs */
+ g_cpuCount = get_cpu_count();
+ if (g_cpuCount == 0) {
+ g_cpuCount = 1;
+ }
+
+ D("found cpuCount = %d\n", g_cpuCount);
+
+#ifdef __ARM_ARCH__
+ {
+ char* features = NULL;
+ char* architecture = NULL;
+
+ /* Extract architecture from the "CPU Architecture" field.
+ * The list is well-known, unlike the the output of
+ * the 'Processor' field which can vary greatly.
+ *
+ * See the definition of the 'proc_arch' array in
+ * $KERNEL/arch/arm/kernel/setup.c and the 'c_show' function in
+ * same file.
+ */
+ char* cpuArch = extract_cpuinfo_field(cpuinfo, cpuinfo_len, "CPU architecture");
+
+ if (cpuArch != NULL) {
+ char* end;
+ long archNumber;
+ int hasARMv7 = 0;
+
+ D("found cpuArch = '%s'\n", cpuArch);
+
+ /* read the initial decimal number, ignore the rest */
+ archNumber = strtol(cpuArch, &end, 10);
+
+ /* Here we assume that ARMv8 will be upwards compatible with v7
+ * in the future. Unfortunately, there is no 'Features' field to
+ * indicate that Thumb-2 is supported.
+ */
+ if (end > cpuArch && archNumber >= 7) {
+ hasARMv7 = 1;
+ }
+
+ /* Unfortunately, it seems that certain ARMv6-based CPUs
+ * report an incorrect architecture number of 7!
+ *
+ * See http://code.google.com/p/android/issues/detail?id=10812
+ *
+ * We try to correct this by looking at the 'elf_format'
+ * field reported by the 'Processor' field, which is of the
+ * form of "(v7l)" for an ARMv7-based CPU, and "(v6l)" for
+ * an ARMv6-one.
+ */
+ if (hasARMv7) {
+ char* cpuProc = extract_cpuinfo_field(cpuinfo, cpuinfo_len,
+ "Processor");
+ if (cpuProc != NULL) {
+ D("found cpuProc = '%s'\n", cpuProc);
+ if (has_list_item(cpuProc, "(v6l)")) {
+ D("CPU processor and architecture mismatch!!\n");
+ hasARMv7 = 0;
+ }
+ free(cpuProc);
+ }
+ }
+
+ if (hasARMv7) {
+ g_cpuFeatures |= ANDROID_CPU_ARM_FEATURE_ARMv7;
+ }
+
+ /* The LDREX / STREX instructions are available from ARMv6 */
+ if (archNumber >= 6) {
+ g_cpuFeatures |= ANDROID_CPU_ARM_FEATURE_LDREX_STREX;
+ }
+
+ free(cpuArch);
+ }
+
+ /* Extract the list of CPU features from 'Features' field */
+ char* cpuFeatures = extract_cpuinfo_field(cpuinfo, cpuinfo_len, "Features");
+
+ if (cpuFeatures != NULL) {
+
+ D("found cpuFeatures = '%s'\n", cpuFeatures);
+
+ if (has_list_item(cpuFeatures, "vfpv3"))
+ g_cpuFeatures |= ANDROID_CPU_ARM_FEATURE_VFPv3;
+
+ else if (has_list_item(cpuFeatures, "vfpv3d16"))
+ g_cpuFeatures |= ANDROID_CPU_ARM_FEATURE_VFPv3;
+
+ if (has_list_item(cpuFeatures, "neon")) {
+ /* Note: Certain kernels only report neon but not vfpv3
+ * in their features list. However, ARM mandates
+ * that if Neon is implemented, so must be VFPv3
+ * so always set the flag.
+ */
+ g_cpuFeatures |= ANDROID_CPU_ARM_FEATURE_NEON |
+ ANDROID_CPU_ARM_FEATURE_VFPv3;
+ }
+ free(cpuFeatures);
+ }
+ }
+#endif /* __ARM_ARCH__ */
+
+#ifdef __i386__
+ g_cpuFamily = ANDROID_CPU_FAMILY_X86;
+
+ int regs[4];
+
+/* According to http://en.wikipedia.org/wiki/CPUID */
+#define VENDOR_INTEL_b 0x756e6547
+#define VENDOR_INTEL_c 0x6c65746e
+#define VENDOR_INTEL_d 0x49656e69
+
+ x86_cpuid(0, regs);
+ int vendorIsIntel = (regs[1] == VENDOR_INTEL_b &&
+ regs[2] == VENDOR_INTEL_c &&
+ regs[3] == VENDOR_INTEL_d);
+
+ x86_cpuid(1, regs);
+ if ((regs[2] & (1 << 9)) != 0) {
+ g_cpuFeatures |= ANDROID_CPU_X86_FEATURE_SSSE3;
+ }
+ if ((regs[2] & (1 << 23)) != 0) {
+ g_cpuFeatures |= ANDROID_CPU_X86_FEATURE_POPCNT;
+ }
+ if (vendorIsIntel && (regs[2] & (1 << 22)) != 0) {
+ g_cpuFeatures |= ANDROID_CPU_X86_FEATURE_MOVBE;
+ }
+#endif
+
+#ifdef _MIPS_ARCH
+ g_cpuFamily = ANDROID_CPU_FAMILY_MIPS;
+#endif /* _MIPS_ARCH */
+}
+
+
+AndroidCpuFamily
+android_getCpuFamily(void)
+{
+ pthread_once(&g_once, android_cpuInit);
+ return g_cpuFamily;
+}
+
+
+uint64_t
+android_getCpuFeatures(void)
+{
+ pthread_once(&g_once, android_cpuInit);
+ return g_cpuFeatures;
+}
+
+
+int
+android_getCpuCount(void)
+{
+ pthread_once(&g_once, android_cpuInit);
+ return g_cpuCount;
+}
diff --git a/android-utils/cpu-features.h b/android-utils/cpu-features.h
new file mode 100644
index 0000000..e4026e2
--- /dev/null
+++ b/android-utils/cpu-features.h
@@ -0,0 +1,69 @@
+/*
+ * Copyright (C) 2010 The Android Open Source Project
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * * Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * * Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in
+ * the documentation and/or other materials provided with the
+ * distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
+ * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
+ * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
+ * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
+ * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
+ * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
+ * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
+ * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ */
+#ifndef CPU_FEATURES_H
+#define CPU_FEATURES_H
+
+#include <sys/cdefs.h>
+#include <stdint.h>
+
+__BEGIN_DECLS
+
+typedef enum {
+ ANDROID_CPU_FAMILY_UNKNOWN = 0,
+ ANDROID_CPU_FAMILY_ARM,
+ ANDROID_CPU_FAMILY_X86,
+ ANDROID_CPU_FAMILY_MIPS,
+
+ ANDROID_CPU_FAMILY_MAX /* do not remove */
+
+} AndroidCpuFamily;
+
+/* Return family of the device's CPU */
+extern AndroidCpuFamily android_getCpuFamily(void);
+
+enum {
+ ANDROID_CPU_ARM_FEATURE_ARMv7 = (1 << 0),
+ ANDROID_CPU_ARM_FEATURE_VFPv3 = (1 << 1),
+ ANDROID_CPU_ARM_FEATURE_NEON = (1 << 2),
+ ANDROID_CPU_ARM_FEATURE_LDREX_STREX = (1 << 3),
+};
+
+enum {
+ ANDROID_CPU_X86_FEATURE_SSSE3 = (1 << 0),
+ ANDROID_CPU_X86_FEATURE_POPCNT = (1 << 1),
+ ANDROID_CPU_X86_FEATURE_MOVBE = (1 << 2),
+};
+
+extern uint64_t android_getCpuFeatures(void);
+
+/* Return the number of CPU cores detected on this device. */
+extern int android_getCpuCount(void);
+
+__END_DECLS
+
+#endif /* CPU_FEATURES_H */
diff --git a/android-utils/droid-makefile b/android-utils/droid-makefile
new file mode 100644
index 0000000..cfa16ca
--- /dev/null
+++ b/android-utils/droid-makefile
@@ -0,0 +1,52 @@
+#Fixed point implementation
+
+APP := lib$(PROJECT)_$(MARCH).$(EXT)
+
+MY_DEFS :=
+
+ifeq ($(LT),shared)
+ _LT=Bdynamic
+else
+ _LT=Bstatic
+endif
+
+LIBS_3RD := -L$(OUTPUT)
+INCLUDES_3RD :=
+INCLUDES := $(INCLUDES_3RD)
+
+CFLAGS := $(CFLAGS_LIB) $(MY_DEFS) $(INCLUDES) -fno-rtti -fno-exceptions
+LDFLAGS := $(LDFLAGS_LIB) -L$(THIRDPARTIES_LIB) -L$(THIRDPARTIES_MARCH_LIB) $(FFMPEG_LDFLAGS) $(VPX_LDLAGS) $(WEBRTC_LDFLAGS) $(SPEEX_DSP_LDFLAGS) $(SPEEX_LDFLAGS) $(OPENCORE_ARM_LDFLAGS) $(BV16_LDFLAGS) $(ILBC_LDFLAGS) $(LIBGSM_LDFLAGS) $(G729_LDFLAGS) \
+ $(LIBSRTP_LDFLAGS) $(TLS_LDFLAGS) \
+ -Wl,-Bdynamic -lm -lstdc++ -lgcc -llog \
+ -Wl,-$(_LT)
+
+all: $(APP)
+
+OBJS = \
+ api.o \
+ cpu-features.o\
+ utils_wrap.o \
+
+$(APP): $(OBJS)
+ifeq ($(EXT), a)
+ $(AR) rcs $@ $^
+else
+ $(CC) $(LDFLAGS) -o $@ $^
+endif
+
+%.o: %.c
+ $(CC) -c $(INCLUDE) $(CFLAGS) $< -o $@
+%.o: %.cxx
+ $(CC) -c $(INCLUDE) $(CFLAGS) $< -o $@
+
+install: $(APP)
+ cp -f $(APP) ../thirdparties/android/lib
+
+shell:
+ $(ANDROID_SDK_ROOT)/tools/adb shell
+
+run:
+ $(ANDROID_SDK_ROOT)/tools/adb shell $(LIB_DIR)/$(APP)
+
+clean:
+ @rm -f $(OBJS) $(APP) \ No newline at end of file
diff --git a/android-utils/java/AndroidUtils.java b/android-utils/java/AndroidUtils.java
new file mode 100644
index 0000000..6fe4922
--- /dev/null
+++ b/android-utils/java/AndroidUtils.java
@@ -0,0 +1,50 @@
+/* ----------------------------------------------------------------------------
+ * This file was automatically generated by SWIG (http://www.swig.org).
+ * Version 2.0.4
+ *
+ * Do not make changes to this file unless you know what you are doing--modify
+ * the SWIG interface file instead.
+ * ----------------------------------------------------------------------------- */
+
+package org.doubango.utils;
+
+public class AndroidUtils {
+ private long swigCPtr;
+ protected boolean swigCMemOwn;
+
+ public AndroidUtils(long cPtr, boolean cMemoryOwn) {
+ swigCMemOwn = cMemoryOwn;
+ swigCPtr = cPtr;
+ }
+
+ public static long getCPtr(AndroidUtils obj) {
+ return (obj == null) ? 0 : obj.swigCPtr;
+ }
+
+ protected void finalize() {
+ delete();
+ }
+
+ public synchronized void delete() {
+ if (swigCPtr != 0) {
+ if (swigCMemOwn) {
+ swigCMemOwn = false;
+ utilsJNI.delete_AndroidUtils(swigCPtr);
+ }
+ swigCPtr = 0;
+ }
+ }
+
+ public AndroidUtils() {
+ this(utilsJNI.new_AndroidUtils(), true);
+ }
+
+ public static java.math.BigInteger getCpuFamily() {
+ return utilsJNI.AndroidUtils_getCpuFamily();
+ }
+
+ public static java.math.BigInteger getCpuFeatures() {
+ return utilsJNI.AndroidUtils_getCpuFeatures();
+ }
+
+}
diff --git a/android-utils/java/CpuFamily_t.java b/android-utils/java/CpuFamily_t.java
new file mode 100644
index 0000000..437d661
--- /dev/null
+++ b/android-utils/java/CpuFamily_t.java
@@ -0,0 +1,53 @@
+/* ----------------------------------------------------------------------------
+ * This file was automatically generated by SWIG (http://www.swig.org).
+ * Version 2.0.4
+ *
+ * Do not make changes to this file unless you know what you are doing--modify
+ * the SWIG interface file instead.
+ * ----------------------------------------------------------------------------- */
+
+package org.doubango.utils;
+
+public enum CpuFamily_t {
+ UNKNOWN(0),
+ ARM,
+ X86;
+
+ public final int swigValue() {
+ return swigValue;
+ }
+
+ public static CpuFamily_t swigToEnum(int swigValue) {
+ CpuFamily_t[] swigValues = CpuFamily_t.class.getEnumConstants();
+ if (swigValue < swigValues.length && swigValue >= 0 && swigValues[swigValue].swigValue == swigValue)
+ return swigValues[swigValue];
+ for (CpuFamily_t swigEnum : swigValues)
+ if (swigEnum.swigValue == swigValue)
+ return swigEnum;
+ throw new IllegalArgumentException("No enum " + CpuFamily_t.class + " with value " + swigValue);
+ }
+
+ @SuppressWarnings("unused")
+ private CpuFamily_t() {
+ this.swigValue = SwigNext.next++;
+ }
+
+ @SuppressWarnings("unused")
+ private CpuFamily_t(int swigValue) {
+ this.swigValue = swigValue;
+ SwigNext.next = swigValue+1;
+ }
+
+ @SuppressWarnings("unused")
+ private CpuFamily_t(CpuFamily_t swigEnum) {
+ this.swigValue = swigEnum.swigValue;
+ SwigNext.next = this.swigValue+1;
+ }
+
+ private final int swigValue;
+
+ private static class SwigNext {
+ private static int next = 0;
+ }
+}
+
diff --git a/android-utils/java/CpuFeatures_t.java b/android-utils/java/CpuFeatures_t.java
new file mode 100644
index 0000000..a92256a
--- /dev/null
+++ b/android-utils/java/CpuFeatures_t.java
@@ -0,0 +1,53 @@
+/* ----------------------------------------------------------------------------
+ * This file was automatically generated by SWIG (http://www.swig.org).
+ * Version 2.0.4
+ *
+ * Do not make changes to this file unless you know what you are doing--modify
+ * the SWIG interface file instead.
+ * ----------------------------------------------------------------------------- */
+
+package org.doubango.utils;
+
+public enum CpuFeatures_t {
+ ARMv7(1),
+ VFPv3(2),
+ NEON(4);
+
+ public final int swigValue() {
+ return swigValue;
+ }
+
+ public static CpuFeatures_t swigToEnum(int swigValue) {
+ CpuFeatures_t[] swigValues = CpuFeatures_t.class.getEnumConstants();
+ if (swigValue < swigValues.length && swigValue >= 0 && swigValues[swigValue].swigValue == swigValue)
+ return swigValues[swigValue];
+ for (CpuFeatures_t swigEnum : swigValues)
+ if (swigEnum.swigValue == swigValue)
+ return swigEnum;
+ throw new IllegalArgumentException("No enum " + CpuFeatures_t.class + " with value " + swigValue);
+ }
+
+ @SuppressWarnings("unused")
+ private CpuFeatures_t() {
+ this.swigValue = SwigNext.next++;
+ }
+
+ @SuppressWarnings("unused")
+ private CpuFeatures_t(int swigValue) {
+ this.swigValue = swigValue;
+ SwigNext.next = swigValue+1;
+ }
+
+ @SuppressWarnings("unused")
+ private CpuFeatures_t(CpuFeatures_t swigEnum) {
+ this.swigValue = swigEnum.swigValue;
+ SwigNext.next = this.swigValue+1;
+ }
+
+ private final int swigValue;
+
+ private static class SwigNext {
+ private static int next = 0;
+ }
+}
+
diff --git a/android-utils/java/utils.java b/android-utils/java/utils.java
new file mode 100644
index 0000000..e8d8cd3
--- /dev/null
+++ b/android-utils/java/utils.java
@@ -0,0 +1,12 @@
+/* ----------------------------------------------------------------------------
+ * This file was automatically generated by SWIG (http://www.swig.org).
+ * Version 2.0.4
+ *
+ * Do not make changes to this file unless you know what you are doing--modify
+ * the SWIG interface file instead.
+ * ----------------------------------------------------------------------------- */
+
+package org.doubango.utils;
+
+public class utils {
+}
diff --git a/android-utils/java/utilsJNI.java b/android-utils/java/utilsJNI.java
new file mode 100644
index 0000000..2db7900
--- /dev/null
+++ b/android-utils/java/utilsJNI.java
@@ -0,0 +1,16 @@
+/* ----------------------------------------------------------------------------
+ * This file was automatically generated by SWIG (http://www.swig.org).
+ * Version 2.0.4
+ *
+ * Do not make changes to this file unless you know what you are doing--modify
+ * the SWIG interface file instead.
+ * ----------------------------------------------------------------------------- */
+
+package org.doubango.utils;
+
+public class utilsJNI {
+ public final static native long new_AndroidUtils();
+ public final static native void delete_AndroidUtils(long jarg1);
+ public final static native java.math.BigInteger AndroidUtils_getCpuFamily();
+ public final static native java.math.BigInteger AndroidUtils_getCpuFeatures();
+}
diff --git a/android-utils/makefile b/android-utils/makefile
new file mode 100644
index 0000000..4f1f360
--- /dev/null
+++ b/android-utils/makefile
@@ -0,0 +1,20 @@
+include ../android-projects/root.mk
+
+ifeq ($(BT), shared)
+all:
+ ($(MAKE) -f droid-makefile all; \
+ $(STRIP) --strip-all --remove-section=.comment --remove-section=.note ./lib$(PROJECT)_$(MARCH).$(EXT); \
+ cp -f ./lib$(PROJECT)_$(MARCH).$(EXT) $(OUTPUT_DIR); \
+ )
+else
+all:
+ ($(MAKE) -f droid-makefile all; cp -f lib$(PROJECT)_$(MARCH).$(EXT) $(OUTPUT_DIR))
+endif
+
+clean:
+ ($(MAKE) -f droid-makefile clean)
+
+
+gdbserver:
+ $(ANDROID_SDK_ROOT)/tools/adb forward tcp:1234: tcp:1234
+ $(ANDROID_SDK_ROOT)/tools/adb shell $(EXEC_DIR)/gdbserver :1234 $(EXEC_DIR)/test \ No newline at end of file
diff --git a/android-utils/utils_wrap.cxx b/android-utils/utils_wrap.cxx
new file mode 100644
index 0000000..dd0f9b1
--- /dev/null
+++ b/android-utils/utils_wrap.cxx
@@ -0,0 +1,502 @@
+/* ----------------------------------------------------------------------------
+ * This file was automatically generated by SWIG (http://www.swig.org).
+ * Version 2.0.4
+ *
+ * This file is not intended to be easily readable and contains a number of
+ * coding conventions designed to improve portability and efficiency. Do not make
+ * changes to this file unless you know what you are doing--modify the SWIG
+ * interface file instead.
+ * ----------------------------------------------------------------------------- */
+
+#define SWIGJAVA
+#define SWIG_DIRECTORS
+
+
+#ifdef __cplusplus
+/* SwigValueWrapper is described in swig.swg */
+template<typename T> class SwigValueWrapper {
+ struct SwigMovePointer {
+ T *ptr;
+ SwigMovePointer(T *p) : ptr(p) { }
+ ~SwigMovePointer() { delete ptr; }
+ SwigMovePointer& operator=(SwigMovePointer& rhs) { T* oldptr = ptr; ptr = 0; delete oldptr; ptr = rhs.ptr; rhs.ptr = 0; return *this; }
+ } pointer;
+ SwigValueWrapper& operator=(const SwigValueWrapper<T>& rhs);
+ SwigValueWrapper(const SwigValueWrapper<T>& rhs);
+public:
+ SwigValueWrapper() : pointer(0) { }
+ SwigValueWrapper& operator=(const T& t) { SwigMovePointer tmp(new T(t)); pointer = tmp; return *this; }
+ operator T&() const { return *pointer.ptr; }
+ T *operator&() { return pointer.ptr; }
+};
+
+template <typename T> T SwigValueInit() {
+ return T();
+}
+#endif
+
+/* -----------------------------------------------------------------------------
+ * This section contains generic SWIG labels for method/variable
+ * declarations/attributes, and other compiler dependent labels.
+ * ----------------------------------------------------------------------------- */
+
+/* template workaround for compilers that cannot correctly implement the C++ standard */
+#ifndef SWIGTEMPLATEDISAMBIGUATOR
+# if defined(__SUNPRO_CC) && (__SUNPRO_CC <= 0x560)
+# define SWIGTEMPLATEDISAMBIGUATOR template
+# elif defined(__HP_aCC)
+/* Needed even with `aCC -AA' when `aCC -V' reports HP ANSI C++ B3910B A.03.55 */
+/* If we find a maximum version that requires this, the test would be __HP_aCC <= 35500 for A.03.55 */
+# define SWIGTEMPLATEDISAMBIGUATOR template
+# else
+# define SWIGTEMPLATEDISAMBIGUATOR
+# endif
+#endif
+
+/* inline attribute */
+#ifndef SWIGINLINE
+# if defined(__cplusplus) || (defined(__GNUC__) && !defined(__STRICT_ANSI__))
+# define SWIGINLINE inline
+# else
+# define SWIGINLINE
+# endif
+#endif
+
+/* attribute recognised by some compilers to avoid 'unused' warnings */
+#ifndef SWIGUNUSED
+# if defined(__GNUC__)
+# if !(defined(__cplusplus)) || (__GNUC__ > 3 || (__GNUC__ == 3 && __GNUC_MINOR__ >= 4))
+# define SWIGUNUSED __attribute__ ((__unused__))
+# else
+# define SWIGUNUSED
+# endif
+# elif defined(__ICC)
+# define SWIGUNUSED __attribute__ ((__unused__))
+# else
+# define SWIGUNUSED
+# endif
+#endif
+
+#ifndef SWIG_MSC_UNSUPPRESS_4505
+# if defined(_MSC_VER)
+# pragma warning(disable : 4505) /* unreferenced local function has been removed */
+# endif
+#endif
+
+#ifndef SWIGUNUSEDPARM
+# ifdef __cplusplus
+# define SWIGUNUSEDPARM(p)
+# else
+# define SWIGUNUSEDPARM(p) p SWIGUNUSED
+# endif
+#endif
+
+/* internal SWIG method */
+#ifndef SWIGINTERN
+# define SWIGINTERN static SWIGUNUSED
+#endif
+
+/* internal inline SWIG method */
+#ifndef SWIGINTERNINLINE
+# define SWIGINTERNINLINE SWIGINTERN SWIGINLINE
+#endif
+
+/* exporting methods */
+#if (__GNUC__ >= 4) || (__GNUC__ == 3 && __GNUC_MINOR__ >= 4)
+# ifndef GCC_HASCLASSVISIBILITY
+# define GCC_HASCLASSVISIBILITY
+# endif
+#endif
+
+#ifndef SWIGEXPORT
+# if defined(_WIN32) || defined(__WIN32__) || defined(__CYGWIN__)
+# if defined(STATIC_LINKED)
+# define SWIGEXPORT
+# else
+# define SWIGEXPORT __declspec(dllexport)
+# endif
+# else
+# if defined(__GNUC__) && defined(GCC_HASCLASSVISIBILITY)
+# define SWIGEXPORT __attribute__ ((visibility("default")))
+# else
+# define SWIGEXPORT
+# endif
+# endif
+#endif
+
+/* calling conventions for Windows */
+#ifndef SWIGSTDCALL
+# if defined(_WIN32) || defined(__WIN32__) || defined(__CYGWIN__)
+# define SWIGSTDCALL __stdcall
+# else
+# define SWIGSTDCALL
+# endif
+#endif
+
+/* Deal with Microsoft's attempt at deprecating C standard runtime functions */
+#if !defined(SWIG_NO_CRT_SECURE_NO_DEPRECATE) && defined(_MSC_VER) && !defined(_CRT_SECURE_NO_DEPRECATE)
+# define _CRT_SECURE_NO_DEPRECATE
+#endif
+
+/* Deal with Microsoft's attempt at deprecating methods in the standard C++ library */
+#if !defined(SWIG_NO_SCL_SECURE_NO_DEPRECATE) && defined(_MSC_VER) && !defined(_SCL_SECURE_NO_DEPRECATE)
+# define _SCL_SECURE_NO_DEPRECATE
+#endif
+
+
+
+/* Fix for jlong on some versions of gcc on Windows */
+#if defined(__GNUC__) && !defined(__INTEL_COMPILER)
+ typedef long long __int64;
+#endif
+
+/* Fix for jlong on 64-bit x86 Solaris */
+#if defined(__x86_64)
+# ifdef _LP64
+# undef _LP64
+# endif
+#endif
+
+#include <jni.h>
+#include <stdlib.h>
+#include <string.h>
+
+
+/* Support for throwing Java exceptions */
+typedef enum {
+ SWIG_JavaOutOfMemoryError = 1,
+ SWIG_JavaIOException,
+ SWIG_JavaRuntimeException,
+ SWIG_JavaIndexOutOfBoundsException,
+ SWIG_JavaArithmeticException,
+ SWIG_JavaIllegalArgumentException,
+ SWIG_JavaNullPointerException,
+ SWIG_JavaDirectorPureVirtual,
+ SWIG_JavaUnknownError
+} SWIG_JavaExceptionCodes;
+
+typedef struct {
+ SWIG_JavaExceptionCodes code;
+ const char *java_exception;
+} SWIG_JavaExceptions_t;
+
+
+static void SWIGUNUSED SWIG_JavaThrowException(JNIEnv *jenv, SWIG_JavaExceptionCodes code, const char *msg) {
+ jclass excep;
+ static const SWIG_JavaExceptions_t java_exceptions[] = {
+ { SWIG_JavaOutOfMemoryError, "java/lang/OutOfMemoryError" },
+ { SWIG_JavaIOException, "java/io/IOException" },
+ { SWIG_JavaRuntimeException, "java/lang/RuntimeException" },
+ { SWIG_JavaIndexOutOfBoundsException, "java/lang/IndexOutOfBoundsException" },
+ { SWIG_JavaArithmeticException, "java/lang/ArithmeticException" },
+ { SWIG_JavaIllegalArgumentException, "java/lang/IllegalArgumentException" },
+ { SWIG_JavaNullPointerException, "java/lang/NullPointerException" },
+ { SWIG_JavaDirectorPureVirtual, "java/lang/RuntimeException" },
+ { SWIG_JavaUnknownError, "java/lang/UnknownError" },
+ { (SWIG_JavaExceptionCodes)0, "java/lang/UnknownError" }
+ };
+ const SWIG_JavaExceptions_t *except_ptr = java_exceptions;
+
+ while (except_ptr->code != code && except_ptr->code)
+ except_ptr++;
+
+ jenv->ExceptionClear();
+ excep = jenv->FindClass(except_ptr->java_exception);
+ if (excep)
+ jenv->ThrowNew(excep, msg);
+}
+
+
+/* Contract support */
+
+#define SWIG_contract_assert(nullreturn, expr, msg) if (!(expr)) {SWIG_JavaThrowException(jenv, SWIG_JavaIllegalArgumentException, msg); return nullreturn; } else
+
+/* -----------------------------------------------------------------------------
+ * director.swg
+ *
+ * This file contains support for director classes that proxy
+ * method calls from C++ to Java extensions.
+ * ----------------------------------------------------------------------------- */
+
+#ifdef __cplusplus
+
+#if defined(DEBUG_DIRECTOR_OWNED)
+#include <iostream>
+#endif
+
+namespace Swig {
+ /* Java object wrapper */
+ class JObjectWrapper {
+ public:
+ JObjectWrapper() : jthis_(NULL), weak_global_(true) {
+ }
+
+ ~JObjectWrapper() {
+ jthis_ = NULL;
+ weak_global_ = true;
+ }
+
+ bool set(JNIEnv *jenv, jobject jobj, bool mem_own, bool weak_global) {
+ if (!jthis_) {
+ weak_global_ = weak_global;
+ if (jobj)
+ jthis_ = ((weak_global_ || !mem_own) ? jenv->NewWeakGlobalRef(jobj) : jenv->NewGlobalRef(jobj));
+#if defined(DEBUG_DIRECTOR_OWNED)
+ std::cout << "JObjectWrapper::set(" << jobj << ", " << (weak_global ? "weak_global" : "global_ref") << ") -> " << jthis_ << std::endl;
+#endif
+ return true;
+ } else {
+#if defined(DEBUG_DIRECTOR_OWNED)
+ std::cout << "JObjectWrapper::set(" << jobj << ", " << (weak_global ? "weak_global" : "global_ref") << ") -> already set" << std::endl;
+#endif
+ return false;
+ }
+ }
+
+ jobject get(JNIEnv *jenv) const {
+#if defined(DEBUG_DIRECTOR_OWNED)
+ std::cout << "JObjectWrapper::get(";
+ if (jthis_)
+ std::cout << jthis_;
+ else
+ std::cout << "null";
+ std::cout << ") -> return new local ref" << std::endl;
+#endif
+ return (jthis_ ? jenv->NewLocalRef(jthis_) : jthis_);
+ }
+
+ void release(JNIEnv *jenv) {
+#if defined(DEBUG_DIRECTOR_OWNED)
+ std::cout << "JObjectWrapper::release(" << jthis_ << "): " << (weak_global_ ? "weak global ref" : "global ref") << std::endl;
+#endif
+ if (jthis_) {
+ if (weak_global_) {
+ if (jenv->IsSameObject(jthis_, NULL) == JNI_FALSE)
+ jenv->DeleteWeakGlobalRef((jweak)jthis_);
+ } else
+ jenv->DeleteGlobalRef(jthis_);
+ }
+
+ jthis_ = NULL;
+ weak_global_ = true;
+ }
+
+ jobject peek() {
+ return jthis_;
+ }
+
+ /* Java proxy releases ownership of C++ object, C++ object is now
+ responsible for destruction (creates NewGlobalRef to pin Java
+ proxy) */
+ void java_change_ownership(JNIEnv *jenv, jobject jself, bool take_or_release) {
+ if (take_or_release) { /* Java takes ownership of C++ object's lifetime. */
+ if (!weak_global_) {
+ jenv->DeleteGlobalRef(jthis_);
+ jthis_ = jenv->NewWeakGlobalRef(jself);
+ weak_global_ = true;
+ }
+ } else { /* Java releases ownership of C++ object's lifetime */
+ if (weak_global_) {
+ jenv->DeleteWeakGlobalRef((jweak)jthis_);
+ jthis_ = jenv->NewGlobalRef(jself);
+ weak_global_ = false;
+ }
+ }
+ }
+
+ private:
+ /* pointer to Java object */
+ jobject jthis_;
+ /* Local or global reference flag */
+ bool weak_global_;
+ };
+
+ /* director base class */
+ class Director {
+ /* pointer to Java virtual machine */
+ JavaVM *swig_jvm_;
+
+ protected:
+#if defined (_MSC_VER) && (_MSC_VER<1300)
+ class JNIEnvWrapper;
+ friend class JNIEnvWrapper;
+#endif
+ /* Utility class for managing the JNI environment */
+ class JNIEnvWrapper {
+ const Director *director_;
+ JNIEnv *jenv_;
+ public:
+ JNIEnvWrapper(const Director *director) : director_(director), jenv_(0) {
+#if defined(SWIG_JAVA_ATTACH_CURRENT_THREAD_AS_DAEMON)
+ // Attach a daemon thread to the JVM. Useful when the JVM should not wait for
+ // the thread to exit upon shutdown. Only for jdk-1.4 and later.
+ director_->swig_jvm_->AttachCurrentThreadAsDaemon((JNIEnv **) &jenv_, NULL);
+#else
+ director_->swig_jvm_->AttachCurrentThread((JNIEnv **) &jenv_, NULL);
+#endif
+ }
+ ~JNIEnvWrapper() {
+#if !defined(SWIG_JAVA_NO_DETACH_CURRENT_THREAD)
+ // Some JVMs, eg jdk-1.4.2 and lower on Solaris have a bug and crash with the DetachCurrentThread call.
+ // However, without this call, the JVM hangs on exit when the thread was not created by the JVM and creates a memory leak.
+ director_->swig_jvm_->DetachCurrentThread();
+#endif
+ }
+ JNIEnv *getJNIEnv() const {
+ return jenv_;
+ }
+ };
+
+ /* Java object wrapper */
+ JObjectWrapper swig_self_;
+
+ /* Disconnect director from Java object */
+ void swig_disconnect_director_self(const char *disconn_method) {
+ JNIEnvWrapper jnienv(this) ;
+ JNIEnv *jenv = jnienv.getJNIEnv() ;
+ jobject jobj = swig_self_.peek();
+#if defined(DEBUG_DIRECTOR_OWNED)
+ std::cout << "Swig::Director::disconnect_director_self(" << jobj << ")" << std::endl;
+#endif
+ if (jobj && jenv->IsSameObject(jobj, NULL) == JNI_FALSE) {
+ jmethodID disconn_meth = jenv->GetMethodID(jenv->GetObjectClass(jobj), disconn_method, "()V");
+ if (disconn_meth) {
+#if defined(DEBUG_DIRECTOR_OWNED)
+ std::cout << "Swig::Director::disconnect_director_self upcall to " << disconn_method << std::endl;
+#endif
+ jenv->CallVoidMethod(jobj, disconn_meth);
+ }
+ }
+ }
+
+ public:
+ Director(JNIEnv *jenv) : swig_jvm_((JavaVM *) NULL), swig_self_() {
+ /* Acquire the Java VM pointer */
+ jenv->GetJavaVM(&swig_jvm_);
+ }
+
+ virtual ~Director() {
+ JNIEnvWrapper jnienv(this) ;
+ JNIEnv *jenv = jnienv.getJNIEnv() ;
+ swig_self_.release(jenv);
+ }
+
+ bool swig_set_self(JNIEnv *jenv, jobject jself, bool mem_own, bool weak_global) {
+ return swig_self_.set(jenv, jself, mem_own, weak_global);
+ }
+
+ jobject swig_get_self(JNIEnv *jenv) const {
+ return swig_self_.get(jenv);
+ }
+
+ // Change C++ object's ownership, relative to Java
+ void swig_java_change_ownership(JNIEnv *jenv, jobject jself, bool take_or_release) {
+ swig_self_.java_change_ownership(jenv, jself, take_or_release);
+ }
+ };
+}
+
+#endif /* __cplusplus */
+
+
+
+#include <stdint.h> // Use the C99 official header
+
+
+#include "api.h"
+
+
+
+/* ---------------------------------------------------
+ * C++ director class methods
+ * --------------------------------------------------- */
+
+#include "utils_wrap.h"
+
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+SWIGEXPORT jlong JNICALL Java_org_doubango_utils_utilsJNI_new_1AndroidUtils(JNIEnv *jenv, jclass jcls) {
+ jlong jresult = 0 ;
+ AndroidUtils *result = 0 ;
+
+ (void)jenv;
+ (void)jcls;
+ result = (AndroidUtils *)new AndroidUtils();
+ *(AndroidUtils **)&jresult = result;
+ return jresult;
+}
+
+
+SWIGEXPORT void JNICALL Java_org_doubango_utils_utilsJNI_delete_1AndroidUtils(JNIEnv *jenv, jclass jcls, jlong jarg1) {
+ AndroidUtils *arg1 = (AndroidUtils *) 0 ;
+
+ (void)jenv;
+ (void)jcls;
+ arg1 = *(AndroidUtils **)&jarg1;
+ delete arg1;
+}
+
+
+SWIGEXPORT jobject JNICALL Java_org_doubango_utils_utilsJNI_AndroidUtils_1getCpuFamily(JNIEnv *jenv, jclass jcls) {
+ jobject jresult = 0 ;
+ uint64_t result;
+
+ (void)jenv;
+ (void)jcls;
+ result = (uint64_t)AndroidUtils::getCpuFamily();
+ {
+ jbyteArray ba = jenv->NewByteArray(9);
+ jbyte* bae = jenv->GetByteArrayElements(ba, 0);
+ jclass clazz = jenv->FindClass("java/math/BigInteger");
+ jmethodID mid = jenv->GetMethodID(clazz, "<init>", "([B)V");
+ jobject bigint;
+ int i;
+
+ bae[0] = 0;
+ for(i=1; i<9; i++ ) {
+ bae[i] = (jbyte)(result>>8*(8-i));
+ }
+
+ jenv->ReleaseByteArrayElements(ba, bae, 0);
+ bigint = jenv->NewObject(clazz, mid, ba);
+ jresult = bigint;
+ }
+ return jresult;
+}
+
+
+SWIGEXPORT jobject JNICALL Java_org_doubango_utils_utilsJNI_AndroidUtils_1getCpuFeatures(JNIEnv *jenv, jclass jcls) {
+ jobject jresult = 0 ;
+ uint64_t result;
+
+ (void)jenv;
+ (void)jcls;
+ result = (uint64_t)AndroidUtils::getCpuFeatures();
+ {
+ jbyteArray ba = jenv->NewByteArray(9);
+ jbyte* bae = jenv->GetByteArrayElements(ba, 0);
+ jclass clazz = jenv->FindClass("java/math/BigInteger");
+ jmethodID mid = jenv->GetMethodID(clazz, "<init>", "([B)V");
+ jobject bigint;
+ int i;
+
+ bae[0] = 0;
+ for(i=1; i<9; i++ ) {
+ bae[i] = (jbyte)(result>>8*(8-i));
+ }
+
+ jenv->ReleaseByteArrayElements(ba, bae, 0);
+ bigint = jenv->NewObject(clazz, mid, ba);
+ jresult = bigint;
+ }
+ return jresult;
+}
+
+
+#ifdef __cplusplus
+}
+#endif
+
diff --git a/android-utils/utils_wrap.h b/android-utils/utils_wrap.h
new file mode 100644
index 0000000..9cc67f4
--- /dev/null
+++ b/android-utils/utils_wrap.h
@@ -0,0 +1,15 @@
+/* ----------------------------------------------------------------------------
+ * This file was automatically generated by SWIG (http://www.swig.org).
+ * Version 2.0.4
+ *
+ * This file is not intended to be easily readable and contains a number of
+ * coding conventions designed to improve portability and efficiency. Do not make
+ * changes to this file unless you know what you are doing--modify the SWIG
+ * interface file instead.
+ * ----------------------------------------------------------------------------- */
+
+#ifndef SWIG_utils_WRAP_H_
+#define SWIG_utils_WRAP_H_
+
+
+#endif
OpenPOWER on IntegriCloud