Disable direct media per endpoint

Hi all,

I have two locations running FreePBX with Asterisk 13.16.
These locations are connected via PJSIP trunk over OpenVPN tunnel built between Asterisk servers.
Therefore, each Asterisk machine has two PJSIP transports: one on a physical interface for local endpoints, the other on a tunnel interface for the trunk.

In the above scenario, SIP signalling works fine, but RTP is not flowing between remote endpoints.
During troubleshooting I noticed that once a connection is established (INVITE -> 200 OK -> ACK), the outgoing Asterisk reinvites the remote Asterisk with SDP of the local endpoint, thus trying to establish the direct media connection.
Of course, this scenario will not work as the remote Asterisk does not know anything about local network.
Adding static routes through tunnel interface will not resolve the issue as tunnelling is performed on the Asterisk servers, not on gateway routers.

I have canreinvite=no in global PJSIP settings on both ends, but this parameter does not help.
I found out that Asterisk supports setting media flow mode per endpoint (parameter direct_media). When I added manually direct_media=no to pjsip.endpoint.conf, I got RTP streams flowing.

However, I have not found a corresponding parameter in FreePBX, extensions. Moreover, FreePBX does not communicate direct_media setting to Asterisk (no such lines in generated pjsip.*.conf files), and the latter treats it as yes according to the defaults.

Having this issue open, I am asking for a piece of adivce on the following:

  1. How can I disable direct media in FreePBX UI on an endpoint / extension level?
  2. If (1) is not possible, how can I disable direct media mode entirely for the whole node - taking into account that canreinvite=no does not work as designed?

I can provide configuration settings, packet traces and other supporting materials upon your request.
Thank you very much in advance.

Open an issue on the issue tracker to add this option.

Hi Andrew,

So, do you admit that setting media mode (direct / pass through) per endpoint is not implemented in FreePBX 13 with PJSIP stack? When I was writing this post, I supposed that I missed some parameter somewhere.

In any case, it is not still clear how should global setting Canreinvite work. Should not it forcibly route all the media through Asterisk and avoid re-invites with direct media in SDP?


There are always two connections for any call, and they can have different options, so setting the options globally wouldn’t necessarily be the best course of action. The fact that the setting is missing from the GUI is probably nothing more than an oversight that you can help rectify by submitting a feature request (since you need the option).

I set up the following workaround.

For each trunk deployed via tunnel I added the following lines into /etc/asterisk/pjsip.endpoint_custom_post.conf:

[Trunk name](+)

This file is not rewritten by FreePBX, so that this scenario should work.

I think you might want to add a “(+)” to the end of your trunk name: “[Trunk name] (+)”. It might not make any difference, but that addition tells the system to add the definitions to context. On the other hand, if it works - don’t mess with it.

1 Like

We can also add this option to freepbx.

I’m hoping he put in a ticket for that. Still, it’s nice to have a couple of ways to solve the problem. I love the “toolkit” feel of FreePBX, and this is one of the many places that stands out.

Hi Dave, I added a (+) sign - otherwise it did not work.
It was not visible here as I forgot backslashes to mask () symbols.