From 5d584d0d83c063006ba1b731046d309123b7409c Mon Sep 17 00:00:00 2001
From: Jason Parker <jparker@digium.com>
Date: Tue, 12 Mar 2013 19:08:59 +0000
Origin: http://svnview.digium.com/svn/asterisk?view=rev&rev=382900
Subject: Switch to using external pjproject libraries.

ICE/STUN/TURN support in res_rtp_asterisk is also now optional.

(With minor backport adjustments for branch 11)

--- a/build_tools/menuselect-deps.in
+++ b/build_tools/menuselect-deps.in
@@ -43,6 +43,7 @@ OPENH323=@PBX_OPENH323@
 OSPTK=@PBX_OSPTK@
 OSS=@PBX_OSS@
 PGSQL=@PBX_PGSQL@
+PJPROJECT=@PBX_PJPROJECT@
 POPT=@PBX_POPT@
 PORTAUDIO=@PBX_PORTAUDIO@
 PRI=@PBX_PRI@
--- a/configure.ac
+++ b/configure.ac
@@ -425,6 +425,7 @@ AST_EXT_LIB_SETUP([OPENR2], [MFR2], [ope
 AST_EXT_LIB_SETUP([OSPTK], [OSP Toolkit], [osptk])
 AST_EXT_LIB_SETUP([OSS], [Open Sound System], [oss])
 AST_EXT_LIB_SETUP([PGSQL], [PostgreSQL], [postgres])
+AST_EXT_LIB_SETUP([PJPROJECT], [PJPROJECT], [pjproject])
 AST_EXT_LIB_SETUP([POPT], [popt], [popt])
 AST_EXT_LIB_SETUP([PORTAUDIO], [PortAudio], [portaudio])
 AST_EXT_LIB_SETUP([PRI], [ISDN PRI], [pri])
@@ -1996,6 +1997,8 @@ if test "${PG_CONFIG}" != No; then
    fi
 fi
 
+AST_PKG_CONFIG_CHECK([PJPROJECT], [libpjproject])
+
 AST_EXT_LIB_CHECK([POPT], [popt], [poptStrerror], [popt.h])
 
 AST_EXT_LIB_CHECK([PORTAUDIO], [portaudio], [Pa_GetDeviceCount], [portaudio.h])
--- a/include/asterisk/autoconfig.h.in
+++ b/include/asterisk/autoconfig.h.in
@@ -551,6 +551,9 @@
 /* Define to indicate presence of the pg_encoding_to_char API. */
 #undef HAVE_PGSQL_pg_encoding_to_char
 
+/* Define if your system has the PJPROJECT libraries. */
+#undef HAVE_PJPROJECT
+
 /* Define to 1 if your system defines IP_PKTINFO. */
 #undef HAVE_PKTINFO
 
--- a/makeopts.in
+++ b/makeopts.in
@@ -214,6 +214,9 @@ OSS_LIB=@OSS_LIB@ @FFMPEG_LIB@ @SDL_LIB@
 PGSQL_INCLUDE=@PGSQL_INCLUDE@
 PGSQL_LIB=@PGSQL_LIB@
 
+PJPROJECT_INCLUDE=@PJPROJECT_INCLUDE@
+PJPROJECT_LIB=@PJPROJECT_LIB@
+
 POPT_INCLUDE=@POPT_INCLUDE@
 POPT_LIB=@POPT_LIB@
 
--- a/res/Makefile
+++ b/res/Makefile
@@ -67,29 +67,8 @@ endif
 ael/pval.o: ael/pval.c
 
 clean::
-	@if [ -f pjproject/build.mak ]; then $(MAKE) -C pjproject realclean; fi
 	rm -f snmp/*.o snmp/*.i ael/*.o ael/*.i ais/*.o ais/*.i
 
-dist-clean::
-	rm -f pjproject/build.mak
-
-pjproject/build.mak: pjproject/aconfigure
-	(cd pjproject && CFLAGS="-fPIC" ./configure --build=$(BUILD_PLATFORM) --host=$(HOST_PLATFORM) --disable-floating-point --disable-sound --disable-oss --disable-speex-aec --disable-l16-codec --disable-gsm-codec --disable-g722-codec --disable-g7221-codec --disable-speex-codec --disable-ilbc-codec --disable-g711-codec)
-
-ifneq ($(findstring $(MAKECMDGOALS),all),)
--include pjproject/build.mak
-endif
-
-.PHONY: FORCE
-FORCE:
-
-$(PJ_LIB_FILES): FORCE
-	$(MAKE) -C $(patsubst %/lib/,%,$(dir $@))/build/ ../lib/$(notdir $@)
-
-ifeq ($(subst 1:0,1,$(UUID)), 1)
+ifeq ($(subst 1:0,1,$(PJPROJECT)), 1)
-res_rtp_asterisk.o: $(PJ_LIB_FILES)
 res_rtp_asterisk.o: _ASTCFLAGS+=-DUSE_PJPROJECT
-res_rtp_asterisk.o: _ASTCFLAGS+=$(PJ_CFLAGS)
-res_rtp_asterisk.so: _ASTLDFLAGS+=$(PJ_LDFLAGS)
-res_rtp_asterisk.so: LIBS+=$(PJ_LDLIBS)
-endif
\ No newline at end of file
+endif
--- a/res/res_rtp_asterisk.c
+++ b/res/res_rtp_asterisk.c
@@ -29,7 +29,7 @@
  */
 
 /*** MODULEINFO
-	<use type="external">uuid</use>
+	<use type="external">pjproject</use>
 	<support_level>core</support_level>
  ***/
 
@@ -52,9 +52,9 @@ ASTERISK_FILE_VERSION(__FILE__, "$Revision: 397604 $")
  * here since it is used internally by pjlib. The only other option would be to modify pjlib... which won't happen. */
 #undef bzero
 #define bzero bzero
-#include "pjlib.h"
-#include "pjlib-util.h"
-#include "pjnath.h"
+#include <pjlib.h>
+#include <pjlib-util.h>
+#include <pjnath.h>
 #endif
 
 #include "asterisk/stun.h"
@@ -1801,7 +1801,7 @@ static int ast_rtp_new(struct ast_rtp_instance *instance,
 	passwd = pj_str(rtp->local_passwd);
 
 	/* Create an ICE session for ICE negotiation */
-	if (icesupport && pj_ice_sess_create(&stun_config, NULL, PJ_ICE_SESS_ROLE_UNKNOWN, 2, &ast_rtp_ice_sess_cb, &ufrag, &passwd, &rtp->ice) == PJ_SUCCESS) {
+	if (icesupport && pj_ice_sess_create(&stun_config, NULL, PJ_ICE_SESS_ROLE_UNKNOWN, 2, &ast_rtp_ice_sess_cb, &ufrag, &passwd, NULL, &rtp->ice) == PJ_SUCCESS) {
 		/* Make this available for the callbacks */
 		rtp->ice->user_data = rtp;
 
