Index: pjproject/trunk/aconfigure.ac
===================================================================
--- pjproject/trunk/aconfigure.ac	(revision 5416)
+++ pjproject/trunk/aconfigure.ac	(revision 5428)
@@ -594,4 +594,26 @@
 				   ],
 				  [AC_MSG_ERROR([Unable to use external libyuv. If libyuv development files are not available in the default locations, use CFLAGS and LDFLAGS env var to set the include/lib paths])])
+	fi
+    ]
+    )
+
+
+dnl # Use external webrtc installation
+AC_SUBST(ac_external_webrtc,0)
+AC_ARG_WITH(external-webrtc,
+    AS_HELP_STRING([--with-external-webrtc],
+		   [Use external webrtc development files, not the one in "third_party" directory. When this option is set, make sure that webrtc is accessible to use (hint: use CFLAGS and LDFLAGS env var to set the include/lib paths)]),
+    [
+	if test "x$with_external_webrtc" != "xno"; then
+		# Test webrtc installation
+		AC_MSG_CHECKING([if external webrtc devkit is installed])
+		AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[#include <webrtc/modules/audio_processing/aec/aec_core.h>
+						     #include <webrtc/modules/audio_processing/aec/include/echo_cancellation.h>
+		]],
+						  [WebRtcAec_Create();])],
+				  [AC_MSG_RESULT(yes!!)
+				   ac_external_webrtc="1"
+				   ],
+				  [AC_MSG_ERROR([Unable to use external webrtc. If webrtc development files are not available in the default locations, use CFLAGS and LDFLAGS env var to set the include/lib paths])])
 	fi
     ]
@@ -1244,80 +1266,4 @@
 
 
-dnl # WebRtc alt prefix
-AC_ARG_WITH(webrtc,
-            AS_HELP_STRING([--with-webrtc=DIR],
-		           [Specify alternate WebRtc prefix]),
-            [],
-            [with_webrtc=no]
-            )
-
-dnl # Do not use default webrtc installation if we are cross-compiling
-if test "x$ac_cross_compile" != "x" -a "x$with_webrtc" = "xno"; then
-    enable_webrtc=no
-fi	      
-	      
-dnl # WebRtc
-AC_SUBST(ac_webrtc_cflags)
-AC_SUBST(ac_webrtc_ldflags)
-AC_ARG_ENABLE(webrtc,
-	      AS_HELP_STRING([--disable-webrtc],
-			     [Exclude webrtc in the build]),
-	      [if test "$enable_webrtc" = "no"; then
-		AC_MSG_RESULT([Checking if webrtc is disabled...yes])
-	       fi],
-	      [
-		  if test "x$with_webrtc" != "xno" -a "x$with_webrtc" != "x"; then
-		        WEBRTC_PREFIX=$with_webrtc
-		  	WEBRTC_CFLAGS="-I$WEBRTC_PREFIX/src"
-		  	
-			case $target in
-			    *-apple-darwin_ios*)
-				case $ARCH in
-				    *arm*)
-				    WEBRTC_CFLAGS="-DPJMEDIA_WEBRTC_AEC_USE_MOBILE=1 $WEBRTC_CFLAGS"
-				    WEBRTC_LDFLAGS="-L$WEBRTC_PREFIX/src/out_ios/Release-iphoneos"
-				    WEBRTC_LIBS="-laudio_processing_neon -lcommon_audio_neon"
-				    ;;
-				*)
-				    ;;
-				esac
-				;;			
-			    *mingw* | *cygw* | *win32* | *w32* | *darwin* | *linux* | *android*)
-			        WEBRTC_LDFLAGS="-L$WEBRTC_PREFIX/src/out/Release"
-			        WEBRTC_LIBS="-laudio_processing_sse2" 
-				;;
-			    *)
-				;;
-			esac		  	
-		  	
-			AC_MSG_RESULT([Using webrtc prefix... $with_webrtc])
-		  else
-		  	WEBRTC_CFLAGS=""
-			WEBRTC_LDFLAGS="" 
-		  fi
-		  		  
-		  WEBRTC_LIBS="$WEBRTC_LIBS -laudio_processing -lcommon_audio -lsystem_wrappers"
-		  
-		  SAVED_LIBS="$LIBS"
-		  SAVED_LDFLAGS="$LDFLAGS"
-		  SAVED_CFLAGS="$CFLAGS"
-		  
-		  LIBS="$WEBRTC_LIBS $LIBS"
-		  LDFLAGS="$WEBRTC_LDFLAGS $LDFLAGS"
-		  CFLAGS="$WEBRTC_CFLAGS $CFLAGS"
-		  
-		  AC_CHECK_LIB(audio_processing,
-			       WebRtcAec_Process,
-			       [ ac_webrtc_cflags="-DPJMEDIA_HAS_WEBRTC_AEC=1 $WEBRTC_CFLAGS"
-		  		 ac_webrtc_ldflags="$WEBRTC_LDFLAGS $WEBRTC_LIBS"
-			       ],
-			       [ LIBS="$SAVED_LIBS"
-				 LDFLAGS="$SAVED_LDFLAGS"
-				 CFLAGS="$SAVED_CFLAGS"
-			       ],
-			       []
-			       )
-	      ])
-
 dnl ########################################################
 dnl # Intel IPP support
@@ -1820,4 +1766,61 @@
 
 
+dnl # Include webrtc
+AC_SUBST(ac_no_webrtc)
+AC_SUBST(ac_webrtc_instset)
+AC_SUBST(ac_webrtc_cflags)
+AC_SUBST(ac_webrtc_ldflags)
+AC_ARG_ENABLE(libwebrtc,
+	      AS_HELP_STRING([--disable-libwebrtc],
+			     [Exclude libwebrtc in the build]),
+	      [if test "$enable_libwebrtc" = "no"; then
+		[ac_no_webrtc=1]
+		AC_DEFINE(PJMEDIA_HAS_LIBWEBRTC,0)
+		AC_MSG_RESULT([Checking if libwebrtc is disabled...yes])
+	       fi],
+	      [
+		  AC_MSG_RESULT([Checking if libwebrtc is disabled...no])
+		  case $target in
+		      *-apple-darwin_ios*)
+			case $target in
+			    *arm*)
+				ac_webrtc_instset=neon
+			    	;;
+			    *)
+				ac_webrtc_instset=sse2
+			    	;;
+			esac
+		        ;;
+		      *android*)
+			case $TARGET_ABI in
+			    armeabi-v7a)
+				ac_webrtc_instset=neon
+				ac_webrtc_cflags="-mfloat-abi=softfp -mfpu=neon"
+			    	;;
+			    armeabi)
+				ac_webrtc_instset=neon
+				ac_webrtc_cflags="-mfloat-abi=softfp -mfpu=neon -march=armv7"
+			    	;;
+			    arm64*)
+				ac_webrtc_instset=neon
+				ac_webrtc_cflags="-DWEBRTC_ARCH_ARM64"
+			    	;;
+			    mips*)
+			    	ac_webrtc_instset=mips
+			        ;;
+			    *)
+				ac_webrtc_instset=sse2
+			    	;;
+			esac
+		        ;;
+		     *mingw* | *cygw* | *win32* | *w32* | *darwin* | *linux*)
+			ac_webrtc_instset=sse2
+			;;
+		     *)
+			;;
+		esac	
+	      ])
+
+
 dnl ##########################################
 dnl #
