Add UPnP support for SIP UDP and media UDP transports #3184
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Steps to add UPnP support:
libupnp-dev
libupnp
from https://github.com/pupnp/pupnplibupnp
by following the instructions. Check the build note below for some recommendations.checking UPnP usability... yes
pjsua_config.enable_upnp
orUaConfig::enableUpnp
.Build recommendation for
libupnp
:By default,
libupnp
send its requests using blocking sockets. This may cause long timeout delay (in our test, it can take more than 1 minute) if your router/IGD (Internet Gateway Device) suddenly goes offline or in the network disconnection scenario. To overcome this, enable non-blocking option for the sockets by configuringlibupnp
with:./configure --disable-blocking_tcp_connections [--enable-debug]
(
--enable-debug
is used to get debugging info and enable logging).Next, even though the socket is now non-blocking, the default timeout set by
libupnp
is also quite long (30 secs). Unfortunately, the timeout is not configurable, so you may need to modify it directly in the following files:upnp/src/inc/httpreadwrite.h:
changeHTTP_DEFAULT_TIMEOUT
(default 30 secs)upnp/src/inc/upnpapi.h
: changeUPNP_TIMEOUT
(default 30 secs)Build instructions for Windows:
cmake -DDOWNLOAD_AND_BUILD_DEPS=ON
to download buildpthreads-win32
dependency as well. Open the generated VS solution and buildlibupnp
.#define PJNATH_HAS_UPNP 1
in yourconfig_site.h
.UPNP_STATIC_LIB
inpjnath
project property as well. You will need three libraries:libpthread
,libupnp
, andlibixml
.__imp_*
not found. For some reason, the generated VS projects generated bycmake
above use an incorrect compilation flag. The solution is to changeProperties-C/C++-Code Generation-Runtime Library
fromMulti-threaded Debug DLL (/MDd) to Multi-threaded Debug (/MTd)
. Then rebuild everything.strcpy_s
orstrcat_s
.libupnp
overwrites standard string functions in order to use the secure version inixml/inc/posix_overwrites.h
, such as#define strcat(arg1, arg2) strcat_s(arg1, sizeof(arg1), arg2)
. Unfortunately, this doesn't work ifarg1
is of typechar *
(instead ofchar[]
). The workaround is to comment these redefinitions. Then rebuild all and ignore all the unsafe string warnings thrown out by VS.Known limitation:
libupnp
initialisation functionUpnpInit2()
expects an interface name as its parameter, however currently there's no PJSIP API to get the interface name.pj_enum_ip_interface()
will only enumerate the interface addresses. The parameter is optional though, so passingNULL
and letlibupnp
find the first suitable interface for you should probably work in most circumstances.Tested with
libupnp
1.14.x.