Index: pjproject/trunk/aconfigure
===================================================================
--- pjproject/trunk/aconfigure	(revision 5655)
+++ pjproject/trunk/aconfigure	(revision 5656)
@@ -691,4 +691,5 @@
 ac_srtp_shutdown_present
 ac_srtp_deinit_present
+ac_external_srtp_lib
 ac_external_srtp
 ac_external_gsm
@@ -758,5 +759,4 @@
 oldincludedir
 includedir
-runstatedir
 localstatedir
 sharedstatedir
@@ -883,5 +883,4 @@
 sharedstatedir='${prefix}/com'
 localstatedir='${prefix}/var'
-runstatedir='${localstatedir}/run'
 includedir='${prefix}/include'
 oldincludedir='/usr/include'
@@ -1136,13 +1135,4 @@
     silent=yes ;;
 
-  -runstatedir | --runstatedir | --runstatedi | --runstated \
-  | --runstate | --runstat | --runsta | --runst | --runs \
-  | --run | --ru | --r)
-    ac_prev=runstatedir ;;
-  -runstatedir=* | --runstatedir=* | --runstatedi=* | --runstated=* \
-  | --runstate=* | --runstat=* | --runsta=* | --runst=* | --runs=* \
-  | --run=* | --ru=* | --r=*)
-    runstatedir=$ac_optarg ;;
-
   -sbindir | --sbindir | --sbindi | --sbind | --sbin | --sbi | --sb)
     ac_prev=sbindir ;;
@@ -1282,5 +1272,5 @@
 		datadir sysconfdir sharedstatedir localstatedir includedir \
 		oldincludedir docdir infodir htmldir dvidir pdfdir psdir \
-		libdir localedir mandir runstatedir
+		libdir localedir mandir
 do
   eval ac_val=\$$ac_var
@@ -1435,5 +1425,4 @@
   --sharedstatedir=DIR    modifiable architecture-independent data [PREFIX/com]
   --localstatedir=DIR     modifiable single-machine data [PREFIX/var]
-  --runstatedir=DIR       modifiable per-process data [LOCALSTATEDIR/run]
   --libdir=DIR            object code libraries [EPREFIX/lib]
   --includedir=DIR        C header files [PREFIX/include]
@@ -6010,4 +5999,5 @@
 
 
+
 # Check whether --with-external-srtp was given.
 if test "${with_external_srtp+set}" = set; then :
@@ -6019,5 +6009,5 @@
 		cat confdefs.h - <<_ACEOF >conftest.$ac_ext
 /* end confdefs.h.  */
-#include <srtp/srtp.h>
+#include <srtp2/srtp.h>
 
 int
@@ -6030,10 +6020,32 @@
 _ACEOF
 if ac_fn_c_try_compile "$LINENO"; then :
-  { $as_echo "$as_me:${as_lineno-$LINENO}: result: yes!!" >&5
-$as_echo "yes!!" >&6; }
+  { $as_echo "$as_me:${as_lineno-$LINENO}: result: yes: version 2.x" >&5
+$as_echo "yes: version 2.x" >&6; }
+				   ac_external_srtp="2"
+				   ac_external_srtp_lib="srtp2"
+
+else
+  cat confdefs.h - <<_ACEOF >conftest.$ac_ext
+/* end confdefs.h.  */
+#include <srtp/srtp.h>
+
+int
+main ()
+{
+srtp_init();
+  ;
+  return 0;
+}
+_ACEOF
+if ac_fn_c_try_compile "$LINENO"; then :
+  { $as_echo "$as_me:${as_lineno-$LINENO}: result: yes: version 1.x" >&5
+$as_echo "yes: version 1.x" >&6; }
 				   ac_external_srtp="1"
+				   ac_external_srtp_lib="srtp"
 
 else
   as_fn_error $? "Unable to use SRTP. If SRTP development files are not available in the default locations, use CFLAGS and LDFLAGS env var to set the include/lib paths" "$LINENO" 5
+fi
+rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext
 fi
 rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext
@@ -6044,16 +6056,17 @@
 
 
-if test "x$ac_external_srtp" = "x1"; then
+if test "x$ac_external_srtp" != "x0"; then
 	ac_srtp_deinit_present=0
 
 	ac_srtp_shutdown_present=0
 
-	{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for srtp_deinit in -lsrtp" >&5
-$as_echo_n "checking for srtp_deinit in -lsrtp... " >&6; }
-if ${ac_cv_lib_srtp_srtp_deinit+:} false; then :
+	as_ac_Lib=`$as_echo "ac_cv_lib_$ac_external_srtp_lib''_srtp_deinit" | $as_tr_sh`
+{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for srtp_deinit in -l$ac_external_srtp_lib" >&5
+$as_echo_n "checking for srtp_deinit in -l$ac_external_srtp_lib... " >&6; }
+if eval \${$as_ac_Lib+:} false; then :
   $as_echo_n "(cached) " >&6
 else
   ac_check_lib_save_LIBS=$LIBS
-LIBS="-lsrtp  $LIBS"
+LIBS="-l$ac_external_srtp_lib  $LIBS"
 cat confdefs.h - <<_ACEOF >conftest.$ac_ext
 /* end confdefs.h.  */
@@ -6075,7 +6088,7 @@
 _ACEOF
 if ac_fn_c_try_link "$LINENO"; then :
-  ac_cv_lib_srtp_srtp_deinit=yes
-else
-  ac_cv_lib_srtp_srtp_deinit=no
+  eval "$as_ac_Lib=yes"
+else
+  eval "$as_ac_Lib=no"
 fi
 rm -f core conftest.err conftest.$ac_objext \
@@ -6083,18 +6096,20 @@
 LIBS=$ac_check_lib_save_LIBS
 fi
-{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_cv_lib_srtp_srtp_deinit" >&5
-$as_echo "$ac_cv_lib_srtp_srtp_deinit" >&6; }
-if test "x$ac_cv_lib_srtp_srtp_deinit" = xyes; then :
+eval ac_res=\$$as_ac_Lib
+	       { $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_res" >&5
+$as_echo "$ac_res" >&6; }
+if eval test \"x\$"$as_ac_Lib"\" = x"yes"; then :
   ac_srtp_deinit_present=1
 fi
 
 	if test "x$ac_srtp_deinit_present" != "x1"; then
-		{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for srtp_shutdown in -lsrtp" >&5
-$as_echo_n "checking for srtp_shutdown in -lsrtp... " >&6; }
-if ${ac_cv_lib_srtp_srtp_shutdown+:} false; then :
+		as_ac_Lib=`$as_echo "ac_cv_lib_$ac_external_srtp_lib''_srtp_shutdown" | $as_tr_sh`
+{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for srtp_shutdown in -l$ac_external_srtp_lib" >&5
+$as_echo_n "checking for srtp_shutdown in -l$ac_external_srtp_lib... " >&6; }
+if eval \${$as_ac_Lib+:} false; then :
   $as_echo_n "(cached) " >&6
 else
   ac_check_lib_save_LIBS=$LIBS
-LIBS="-lsrtp  $LIBS"
+LIBS="-l$ac_external_srtp_lib  $LIBS"
 cat confdefs.h - <<_ACEOF >conftest.$ac_ext
 /* end confdefs.h.  */
@@ -6116,7 +6131,7 @@
 _ACEOF
 if ac_fn_c_try_link "$LINENO"; then :
-  ac_cv_lib_srtp_srtp_shutdown=yes
-else
-  ac_cv_lib_srtp_srtp_shutdown=no
+  eval "$as_ac_Lib=yes"
+else
+  eval "$as_ac_Lib=no"
 fi
 rm -f core conftest.err conftest.$ac_objext \
@@ -6124,7 +6139,8 @@
 LIBS=$ac_check_lib_save_LIBS
 fi
-{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_cv_lib_srtp_srtp_shutdown" >&5
-$as_echo "$ac_cv_lib_srtp_srtp_shutdown" >&6; }
-if test "x$ac_cv_lib_srtp_srtp_shutdown" = xyes; then :
+eval ac_res=\$$as_ac_Lib
+	       { $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_res" >&5
+$as_echo "$ac_res" >&6; }
+if eval test \"x\$"$as_ac_Lib"\" = x"yes"; then :
   ac_srtp_shutdown_present=1
 fi
Index: pjproject/trunk/aconfigure.ac
===================================================================
--- pjproject/trunk/aconfigure.ac	(revision 5655)
+++ pjproject/trunk/aconfigure.ac	(revision 5656)
@@ -567,4 +567,5 @@
 dnl # Use external SRTP installation
 AC_SUBST(ac_external_srtp,0)
+AC_SUBST(ac_external_srtp_lib)
 AC_ARG_WITH(external-srtp,
     AS_HELP_STRING([--with-external-srtp],
@@ -574,11 +575,19 @@
 		# Test SRTP installation
 		AC_MSG_CHECKING([if external SRTP devkit is installed])
-		AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[#include <srtp/srtp.h>
+		AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[#include <srtp2/srtp.h>
 						     ]],
 						  [srtp_init();])],
-				  [AC_MSG_RESULT(yes!!)
+				  [AC_MSG_RESULT(yes: version 2.x)
+				   ac_external_srtp="2"
+				   ac_external_srtp_lib="srtp2"
+				   ],
+				  [AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[#include <srtp/srtp.h>
+						     ]],
+						  [srtp_init();])],
+				  [AC_MSG_RESULT(yes: version 1.x)
 				   ac_external_srtp="1"
+				   ac_external_srtp_lib="srtp"
 				   ],
-				  [AC_MSG_ERROR([Unable to use SRTP. If SRTP development files are not available in the default locations, use CFLAGS and LDFLAGS env var to set the include/lib paths])])
+				  [AC_MSG_ERROR([Unable to use SRTP. If SRTP development files are not available in the default locations, use CFLAGS and LDFLAGS env var to set the include/lib paths])])])
 	fi
     ]
@@ -586,10 +595,10 @@
 
 dnl # For external SRTP, check availability of srtp_deinit() or srtp_shutdown()
-if test "x$ac_external_srtp" = "x1"; then
+if test "x$ac_external_srtp" != "x0"; then
 	AC_SUBST(ac_srtp_deinit_present,0)
 	AC_SUBST(ac_srtp_shutdown_present,0)
-	AC_CHECK_LIB(srtp,srtp_deinit,[ac_srtp_deinit_present=1])
+	AC_CHECK_LIB($ac_external_srtp_lib,srtp_deinit,[ac_srtp_deinit_present=1])
 	if test "x$ac_srtp_deinit_present" != "x1"; then
-		AC_CHECK_LIB(srtp,srtp_shutdown,[ac_srtp_shutdown_present=1])
+		AC_CHECK_LIB($ac_external_srtp_lib,srtp_shutdown,[ac_srtp_shutdown_present=1])
 	fi
 fi
Index: pjproject/trunk/build.mak.in
===================================================================
--- pjproject/trunk/build.mak.in	(revision 5655)
+++ pjproject/trunk/build.mak.in	(revision 5656)
@@ -29,7 +29,7 @@
 export APP_THIRD_PARTY_LIB_FILES :=
 
-ifeq (@ac_external_srtp@,1)
+ifneq (@ac_external_srtp@,0)
 # External SRTP library
-APP_THIRD_PARTY_EXT += -lsrtp
+APP_THIRD_PARTY_EXT += -l@ac_external_srtp_lib@
 else
 APP_THIRD_PARTY_LIB_FILES += $(PJ_DIR)/third_party/lib/libsrtp-$(LIB_SUFFIX)
Index: pjproject/trunk/pjmedia/build/os-auto.mak.in
===================================================================
--- pjproject/trunk/pjmedia/build/os-auto.mak.in	(revision 5655)
+++ pjproject/trunk/pjmedia/build/os-auto.mak.in	(revision 5656)
@@ -149,7 +149,7 @@
 # SRTP
 #
-ifeq (@ac_external_srtp@,1)
+ifneq (@ac_external_srtp@,0)
 # External SRTP
-export CFLAGS += -DPJMEDIA_EXTERNAL_SRTP=1
+export CFLAGS += -DPJMEDIA_EXTERNAL_SRTP=@ac_external_srtp@
 # SRTP srtp_deinit()/srtp_shutdown() API availability settings
 export CFLAGS += -DPJMEDIA_SRTP_HAS_DEINIT=@ac_srtp_deinit_present@ \
Index: pjproject/trunk/pjmedia/src/pjmedia/transport_srtp.c
===================================================================
--- pjproject/trunk/pjmedia/src/pjmedia/transport_srtp.c	(revision 5655)
+++ pjproject/trunk/pjmedia/src/pjmedia/transport_srtp.c	(revision 5656)
@@ -45,8 +45,34 @@
 #endif
 
-#if defined(PJMEDIA_EXTERNAL_SRTP) && (PJMEDIA_EXTERNAL_SRTP != 0)
+#if defined(PJMEDIA_EXTERNAL_SRTP)
+
+#if (PJMEDIA_EXTERNAL_SRTP == 1) 	/* External SRTP 1.x */
 #  include <srtp/srtp.h>
 #  include <srtp/crypto_kernel.h>
-#else
+#define srtp_crypto_policy_t 		crypto_policy_t
+#define srtp_cipher_type_id_t 		cipher_type_id_t
+#define srtp_cipher_type_t		cipher_type_t
+#define srtp_auth_type_id_t 		auth_type_id_t
+#define srtp_sec_serv_t			sec_serv_t
+#define srtp_err_status_t		err_status_t
+#define srtp_err_status_ok		err_status_ok
+#define srtp_err_status_replay_old	err_status_replay_old
+#define srtp_err_status_replay_fail	err_status_replay_fail
+#define srtp_crypto_policy_set_aes_cm_256_hmac_sha1_32 \
+	     crypto_policy_set_aes_cm_256_hmac_sha1_32
+#define srtp_crypto_policy_set_aes_cm_256_hmac_sha1_80 \
+	     crypto_policy_set_aes_cm_256_hmac_sha1_80
+#define SRTP_NULL_CIPHER		NULL_CIPHER
+#define SRTP_NULL_AUTH			NULL_AUTH
+#define SRTP_AES_ICM_128		AES_ICM
+#define SRTP_AES_ICM_256		AES_ICM
+#define SRTP_HMAC_SHA1			HMAC_SHA1
+
+#else				 	/* External SRTP 2.x */
+#  include <srtp2/srtp.h>
+#  include <srtp2/cipher.h>
+#endif
+
+#else					/* Bundled SRTP */
 #  include <srtp.h>
 #  include <crypto_kernel.h>
Index: pjproject/trunk/third_party/build/os-auto.mak.in
===================================================================
--- pjproject/trunk/third_party/build/os-auto.mak.in	(revision 5655)
+++ pjproject/trunk/third_party/build/os-auto.mak.in	(revision 5656)
@@ -40,5 +40,5 @@
 endif
 
-ifeq (@ac_external_srtp@,1)
+ifneq (@ac_external_srtp@,0)
 # External SRTP
 else
