From e03b970d1394be068c196cea3c059612f72604b8 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Adrien=20B=C3=A9raud?= <adrien.beraud@savoirfairelinux.com>
Date: Thu, 6 Oct 2016 16:02:51 -0400
Subject: [PATCH] android: enable vp8, cleanup

Fix and enable VPX on Android.
Since the Android build moved to clang and libc++,
it's no longer necessary to redefine some common
standard C++ methods.

Change-Id: I3488633782ded31bc260c5a234802ebd6f251377
---
 contrib/src/ffmpeg/rules.mak        |  5 ++--
 contrib/src/pjproject/isblank.patch |  8 ++++++
 contrib/src/pjproject/rules.mak     |  1 +
 contrib/src/vpx/rules.mak           |  2 +-
 src/ip_utils.h                      |  2 ++
 src/string_utils.h                  | 42 -----------------------------
 src/upnp/upnp_context.cpp           | 18 ++++++-------
 src/upnp/upnp_context.h             | 18 ++++++-------
 8 files changed, 32 insertions(+), 64 deletions(-)
 create mode 100644 contrib/src/pjproject/isblank.patch

diff --git a/contrib/src/ffmpeg/rules.mak b/contrib/src/ffmpeg/rules.mak
index 3ff65c545a..0dd4cfa653 100644
--- a/contrib/src/ffmpeg/rules.mak
+++ b/contrib/src/ffmpeg/rules.mak
@@ -37,9 +37,7 @@ FFMPEGCONF += \
 
 #librairies
 ifndef HAVE_ANDROID
-FFMPEGCONF += \
-		--enable-libx264 \
-		--enable-libvpx
+FFMPEGCONF += --enable-libx264
 endif
 
 #encoders/decoders
@@ -66,6 +64,7 @@ FFMPEGCONF += \
 		--enable-decoder=mjpegb \
 		--enable-libspeex \
 		--enable-libopus \
+		--enable-libvpx \
 		--enable-encoder=libspeex \
 		--enable-decoder=libspeex \
 		--enable-encoder=libopus \
diff --git a/contrib/src/pjproject/isblank.patch b/contrib/src/pjproject/isblank.patch
new file mode 100644
index 0000000000..98f6f1e827
--- /dev/null
+++ b/contrib/src/pjproject/isblank.patch
@@ -0,0 +1,8 @@
+--- pjproject/pjlib/include/pj/compat/ctype.h	2016-10-06 16:39:29.708512865 -0400
++++ pjproject/pjlib/include/pj/compat/ctype.h	2016-10-06 17:39:00.084513427 -0400
+@@ -43,5 +43,2 @@
+ 
+-#ifndef isblank
+-#   define isblank(c)	    (c==' ' || c=='\t')
+-#endif
+ 
diff --git a/contrib/src/pjproject/rules.mak b/contrib/src/pjproject/rules.mak
index f7ac9ede4c..da0e0fb4a0 100644
--- a/contrib/src/pjproject/rules.mak
+++ b/contrib/src/pjproject/rules.mak
@@ -69,6 +69,7 @@ endif
 	$(APPLY) $(SRC)/pjproject/notestsapps.patch
 ifdef HAVE_ANDROID
 	$(APPLY) $(SRC)/pjproject/android.patch
+	$(APPLY) $(SRC)/pjproject/isblank.patch
 endif
 	$(APPLY) $(SRC)/pjproject/ipv6.patch
 	$(APPLY) $(SRC)/pjproject/ice_config.patch
diff --git a/contrib/src/vpx/rules.mak b/contrib/src/vpx/rules.mak
index 3aa647abea..acfd37586d 100644
--- a/contrib/src/vpx/rules.mak
+++ b/contrib/src/vpx/rules.mak
@@ -117,7 +117,7 @@ ifdef HAVE_ANDROID
 # uses that path to look for the compiler (which we already know)
 VPX_CONF += --sdk-path=$(ANDROID_TOOLCHAIN)/bin
 # needed for cpu-features.h
-VPX_CONF += --extra-cflags="-I$(ANDROID_NDK)/sources/cpufeatures/"
+VPX_CONF += --extra-cflags="-I$(ANDROID_NDK)/sources/cpufeatures/ -fvisibility=hidden"
 # set an explicit alternative libc since the sysroot override can make it blank
 VPX_CONF += --libc=$(SYSROOT)
 LOCAL_HOSTVARS=$(HOSTVARS)
diff --git a/src/ip_utils.h b/src/ip_utils.h
index 63a1cfc50a..e704839f0f 100644
--- a/src/ip_utils.h
+++ b/src/ip_utils.h
@@ -21,7 +21,9 @@
 #ifndef IP_UTILS_H_
 #define IP_UTILS_H_
 
+extern "C" {
 #include <pjlib.h>
+}
 
 #ifdef HAVE_CONFIG
  #include <config.h>
diff --git a/src/string_utils.h b/src/string_utils.h
index 707c88f33a..d2b8c813a5 100644
--- a/src/string_utils.h
+++ b/src/string_utils.h
@@ -25,10 +25,6 @@
 #include <string>
 #include <vector>
 
-#ifdef __ANDROID__
-#include <sstream>
-#endif
-
 namespace ring {
 
 constexpr static const char* TRUE_STR = "true";
@@ -48,42 +44,6 @@ std::wstring to_wstring(const std::string& s);
 
 #endif
 
-#ifdef __ANDROID__
-
-// Rationale:
-// Some strings functions are not available on Android NDK as explained here:
-// http://stackoverflow.com/questions/17950814/how-to-use-stdstoul-and-stdstoull-in-android/18124627#18124627
-// We implement them by ourself as well as possible here.
-
-template <typename T>
-inline std::string
-to_string(T &&value)
-{
-    std::ostringstream os;
-    os << value;
-    return os.str();
-}
-
-static inline int
-stoi(const std::string& str)
-{
-    int v;
-    std::istringstream os(str);
-    os >> v;
-    return v;
-}
-
-static inline double
-stod(const std::string& str)
-{
-    double v;
-    std::istringstream os(str);
-    os >> v;
-    return v;
-}
-
-#else
-
 template <typename T>
 inline std::string
 to_string(T &&value)
@@ -103,8 +63,6 @@ stod(const std::string& str)
     return std::stod(str);
 }
 
-#endif
-
 std::string trim(const std::string &s);
 
 std::vector<std::string>
diff --git a/src/upnp/upnp_context.cpp b/src/upnp/upnp_context.cpp
index 4b55061311..6ccadaa34a 100644
--- a/src/upnp/upnp_context.cpp
+++ b/src/upnp/upnp_context.cpp
@@ -24,15 +24,6 @@
 
 #include "upnp_context.h"
 
-#include <string>
-#include <set>
-#include <mutex>
-#include <memory>
-#include <condition_variable>
-#include <random>
-#include <chrono>
-#include <cstdlib> // for std::free
-
 #if HAVE_LIBUPNP
 #include <upnp/upnp.h>
 #include <upnp/upnptools.h>
@@ -50,6 +41,15 @@
 #include <opendht/rng.h>
 using random_device = dht::crypto::random_device;
 
+#include <string>
+#include <set>
+#include <mutex>
+#include <memory>
+#include <condition_variable>
+#include <random>
+#include <chrono>
+#include <cstdlib> // for std::free
+
 namespace ring { namespace upnp {
 
 /**
diff --git a/src/upnp/upnp_context.h b/src/upnp/upnp_context.h
index a2aa196add..c5d8c41dbc 100644
--- a/src/upnp/upnp_context.h
+++ b/src/upnp/upnp_context.h
@@ -24,15 +24,6 @@
 #include "config.h"
 #endif
 
-#include <set>
-#include <map>
-#include <mutex>
-#include <memory>
-#include <condition_variable>
-#include <chrono>
-#include <atomic>
-#include <thread>
-
 #if HAVE_LIBUPNP
 #ifdef _WIN32
 #define UPNP_STATIC_LIB
@@ -50,6 +41,15 @@
 #include "noncopyable.h"
 #include "upnp_igd.h"
 
+#include <set>
+#include <map>
+#include <mutex>
+#include <memory>
+#include <condition_variable>
+#include <chrono>
+#include <atomic>
+#include <thread>
+
 namespace ring {
 class IpAddr;
 }
-- 
GitLab