tayler6000 / pyVoIP

Pure python VoIP/SIP/RTP library. Currently supports PCMA, PCMU, and telephone-event
https://pypi.org/project/pyVoIP/
GNU General Public License v3.0
224 stars 94 forks source link

Some apps send STUN packets over same port as RTP and cause issue #98

Open SEIDO-JP opened 1 year ago

SEIDO-JP commented 1 year ago

Hi,

Linphone App is sending STUN packet on the same port as RTP packets, at the beginning of conversation, which cause RTP parser in RTP.py to not working properly - and You can't disable it or change STUN port in Linphone.

Screenshot 2023-01-20 at 14 20 26

In this situation RTP parser "thinks" that this STUN packet is RTP packet and try to... parse this packet here: https://github.com/tayler6000/pyVoIP/blob/765cb1f6830d5b2fe0accb45265ca8ff76c49999/pyVoIP/RTP.py#L252-L259

My solution looks like this:

Screenshot 2023-01-20 at 14 25 00

What do You think about it?

xyc0815 commented 1 year ago

Normaly Linphone semds all SIP communication to the right SIP port and RTP to the right RTP. Please check your IP / Port configuration that you bind the right ports and IP addresses against the VoIPPhone start port and IP and the data you get from the Linphone app in the SIP data. Are you behind a NAT? One problem you can have from Linphone ist that the Linphone app sends ACK and BYE not from the port defined in SIP data.

The next thing here is from my point of view, that the RTP parts starts to early. Please see https://github.com/tayler6000/pyVoIP/issues/89.

jrozhon commented 1 year ago

This is a standard behavior of Linphone. They have an option to turn off ICE negotiation but it does not suppress STUN requests even if you have no stun server configured.

Basically, your solution is OK. Perhaps a better way of doing it would be filtering out packets starting with 2-zero bits as this is the "mark" of the STUN protocol packet. RTP should have a version number in first two bits and it should be always set to 2.

The RFCs in question: https://www.rfc-editor.org/rfc/rfc5389#section-6 https://www.rfc-editor.org/rfc/rfc3550#section-5.1