Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add UPnP support for SIP UDP and media UDP transports #3184

Merged
merged 4 commits into from
Jul 21, 2022
Merged

Add UPnP support for SIP UDP and media UDP transports #3184

merged 4 commits into from
Jul 21, 2022

Conversation

sauwming
Copy link
Member

@sauwming sauwming commented Jul 14, 2022

Steps to add UPnP support:

  • For Debian/Ubuntu, just install libupnp-dev
  • Download libupnp from https://github.com/pupnp/pupnp
  • Build libupnp by following the instructions. Check the build note below for some recommendations.
  • Configure PJSIP and make sure there is the following output:
    checking UPnP usability... yes
  • Enable UPnP in your app by setting pjsua_config.enable_upnp or UaConfig::enableUpnp.

Build recommendation forlibupnp :
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 configuring libupnp 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: change HTTP_DEFAULT_TIMEOUT (default 30 secs)
  • upnp/src/inc/upnpapi.h: change UPNP_TIMEOUT (default 30 secs)

Build instructions for Windows:

  • Run cmake -DDOWNLOAD_AND_BUILD_DEPS=ON to download build pthreads-win32 dependency as well. Open the generated VS solution and build libupnp.
  • Add #define PJNATH_HAS_UPNP 1 in your config_site.h.
  • Add the UPnP include and library directories to your projects. If you use static library, define UPNP_STATIC_LIB in pjnath project property as well. You will need three libraries: libpthread, libupnp, and libixml.
  • Windows build troubleshooting:
    • Static library linking failure, function __imp_* not found. For some reason, the generated VS projects generated by cmake above use an incorrect compilation flag. The solution is to change Properties-C/C++-Code Generation-Runtime Library from Multi-threaded Debug DLL (/MDd) to Multi-threaded Debug (/MTd). Then rebuild everything.
    • Various runtime assertions in secure string functions such as strcpy_s or strcat_s. libupnp overwrites standard string functions in order to use the secure version in ixml/inc/posix_overwrites.h, such as #define strcat(arg1, arg2) strcat_s(arg1, sizeof(arg1), arg2). Unfortunately, this doesn't work if arg1 is of type char * (instead of char[]). 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 function UpnpInit2() 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 passing NULL and let libupnp find the first suitable interface for you should probably work in most circumstances.

Tested with libupnp 1.14.x.

@sauwming sauwming marked this pull request as draft July 18, 2022 08:07
@sauwming sauwming marked this pull request as ready for review July 18, 2022 08:12
pjlib-util/include/pjlib-util/upnp.h Outdated Show resolved Hide resolved
pjlib-util/src/pjlib-util/upnp.c Outdated Show resolved Hide resolved
pjlib-util/src/pjlib-util/upnp.c Show resolved Hide resolved
pjlib-util/src/pjlib-util/upnp.c Show resolved Hide resolved
pjlib-util/src/pjlib-util/upnp.c Show resolved Hide resolved
@sauwming sauwming merged commit 82247cb into master Jul 21, 2022
@sauwming sauwming deleted the upnp branch July 21, 2022 03:25
@sauwming sauwming mentioned this pull request Jul 29, 2022
wosrediinanatour pushed a commit to wosrediinanatour/pjproject that referenced this pull request Jan 16, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants