livekit / sip

SIP to WebRTC bridge for LiveKit
70 stars 18 forks source link

SIP connectivity - "media-failed" error on connect after invite #105

Open kwaternion opened 4 weeks ago

kwaternion commented 4 weeks ago

Hi,

I'm trying to make a SIP connectivity to livekit-sip. I cloned the repo, build dockers. I had to disable "network_mode: host"- since I couldn't make connectivity between components. I adapted the composer as follows::

services:
  redis:
    image: redis
    volumes:
      - redis_data:/data
    expose:
      - 6379
    command: redis-server --bind 0.0.0.0
  livekit:
    image: livekit/livekit-server
    command: --dev --redis-host redis:6379 --bind 0.0.0.0 
    ports:
     - 7880:7880
  sip:
    image: livekit/sip
    environment:
      SIP_CONFIG_BODY: |
        api_key: devkey
        api_secret: secret
        redis:
          address: redis:6379
        ws_url: ws://livekit:7880
        sip_port: 5060
        rtp_port: 10000-101000
        use_external_ip: true
        logging:
          level: 'debug'
        bind_address: '0.0.0.0'
    ports:
      - "5060:5060"
      - "10000-10100:10000-10100/udp"
volumes:
  redis_data:

Server seems to start-up properly:

livekit-1  | 2024-06-07T19:43:03.253Z   INFO    livekit server/main.go:208      starting in development mode
livekit-1  | 2024-06-07T19:43:03.254Z   INFO    livekit server/main.go:211      no keys provided, using placeholder keys   {"API Key": "devkey", "API Secret": "secret"}
livekit-1  | 2024-06-07T19:43:03.256Z   INFO    livekit hwstats/cpu_linux.go:76 failed reading cgroup specific cpu stats, falling back to system wide implementation
livekit-1  | 2024-06-07T19:43:03.259Z   INFO    livekit redis/redis.go:142      connecting to redis{"simple": true, "addr": "redis:6379"}
livekit-1  | 2024-06-07T19:43:03.382Z   INFO    livekit service/server.go:243   starting LiveKit server    {"portHttp": 7880, "nodeID": "ND_NMLK64YNZzpb", "nodeIP": "172.18.0.3", "version": "1.6.1", "bindAddresses": ["0.0.0.0"], "rtc.portTCP": 7881, "rtc.portUDP": {"Start":7882,"End":0}}
sip-1      | 2024-06-07T19:43:04.479Z   INFOG   sipekit redis/redis.go:142122   connecting to redisal se{"nodeID": "NE_2qp9pQWC2rh5", "simple": true, "addr": "redis:6379"}
sip-1      | 2024-06-07T19:43:04.488Z   DEBUG   sip     sip/service.go:80       starting sip service    {"nodeID": "NE_2qp9pQWC2rh5", "version": "0.0.1"}
sip-1      | 2024-06-07T19:43:04.589Z   INFO    sip     sip/client.go:78        client starting {"nodeID": "NE_2qp9pQWC2rh5", "local": "172.18.0.4", "external": "79.184.12.236"}
sip-1      | 2024-06-07T19:43:04.629Z   INFO    sip     sip/server.go:198       server starting {"nodeID": "NE_2qp9pQWC2rh5", "local": "172.18.0.4", "external": "79.184.12.236"}
sip-1      | 2024-06-07T19:43:04.629Z   INFO    sip     sip/server.go:151       sip signaling listening on      {"nodeID": "NE_2qp9pQWC2rh5", "local": "172.18.0.4", "external": "79.184.12.236", "port": 5060, "proto": "udp"}
sip-1      | 2024-06-07T19:43:04.629Z   INFO    sip     sip/server.go:170       sip signaling listening on      {"nodeID": "NE_2qp9pQWC2rh5", "local": "172.18.0.4", "external": "79.184.12.236", "port": 5060, "proto": "tcp"}
sip-1      | 2024-06-07T19:43:04.629Z   DEBUG   sip     sip/service.go:112      sip service ready       {"nodeID": "NE_2qp9pQWC2rh5"}
sip-1      | 2024-06-07T19:43:04.629Z   DEBUG   sip     service/service.go:89   starting service        {"nodeID": "NE_2qp9pQWC2rh5", "version": "0.0.1"}
sip-1      | 2024-06-07T19:43:04.629Z   DEBUG   sip     service/service.go:112  service ready   {"nodeID": "NE_2qp9pQWC2rh5"}

I am able to see image on the test page: https://meet.livekit.io/

Now I am trying to make a connection via SIP (Microsip local, Windows 11). There is a trace of the connection on the servers:

sip-1      | 2024-06-07T19:45:55.381Z   INFO    sip     sip/inbound.go:173      processing invite {"nodeID": "NE_2qp9pQWC2rh5", "callID": "SCL_dbcR5CVJMT59", "fromIP": "172.18.0.1:44752", "toIP": "localhost:5060", "sipTag": "676c4540ebc045e1813bad8d59627536", "fromHost": "antisip.com", "fromUser": "john4321", "toHost": "localhost", "toUser": "+123"}
livekit-1  | 2024-06-07T19:45:55.387Z   DEBUG   livekit service/ioservice_sip.go:96     SIP trunk matched for auth {"to-user": "+123", "from-user": "john4321", "sip-trunk": "ST_cUnbkdfLEWLp"}
livekit-1  | 2024-06-07T19:45:55.390Z   DEBUG   livekit service/ioservice_sip.go:62     SIP trunk matched  {"to-user": "+123", "from-user": "john4321", "sip-trunk": "ST_cUnbkdfLEWLp"}
livekit-1  | 2024-06-07T19:45:55.390Z   DEBUG   livekit service/ioservice_sip.go:76     SIP dispatch rule matched  {"to-user": "+123", "from-user": "john4321", "sip-trunk": "ST_cUnbkdfLEWLp", "sip-rule": "SDR_4X4pL2vyVTga"}
sip-1      | 2024-06-07T19:45:55.391Z   INFO    sip     sip/inbound.go:534      Closing inbound call       {"nodeID": "NE_2qp9pQWC2rh5", "callID": "SCL_dbcR5CVJMT59", "fromIP": "172.18.0.1:44752", "toIP": "localhost:5060", "sipTag": "676c4540ebc045e1813bad8d59627536", "fromHost": "antisip.com", "fromUser": "john4321", "toHost": "localhost", "toUser": "+123", "sipTrunk": "ST_cUnbkdfLEWLp", "sipRule": "SDR_4X4pL2vyVTga", "reason": "media-failed"}

Disconnection reason: media-failed.

I tried different SIP clients: Zoiper, Microsip. Also tried dockercompose in Windows, and in WSL2 via dockercompose and standalone servers. In all configurations the error is the same.

I also tried the client test app from: sip/test/client/main.go Here the error is:

024/06/07 19:40:20 INFO media address addr=[::]:54141
panic: media-timeout

goroutine 52 [running]:
github.com/livekit/sip/pkg/siptest.NewClient.func1()
        /home/john/projects/sip/pkg/siptest/client.go:66 +0x25
github.com/livekit/sip/pkg/media/rtp.(*Conn).onTimeout.func1()
        /home/john/projects/sip/pkg/media/rtp/conn.go:174 +0x108
created by github.com/livekit/sip/pkg/media/rtp.(*Conn).onTimeout in goroutine 1
        /home/john/projects/sip/pkg/media/rtp/conn.go:162 +0x67
exit status 2

Please let me try to trace the error or problem. Or any hints how to solve the problem.

kwaternion commented 3 weeks ago

Justo to add some more information on that issue. Finally I've managed to use a app from: sip/test/client/main.go to stream a voice into meets webpage. I used the file from: https://siobud.com/audio.mkv But there are two issues with that: 1) The sound when listened on the meet room is very choppy/glitchy. Possibly, sounds like a transcoding/codecs issue. 2) It times out/terminates after around 30s, go application returns: "panic: media-timeout", although the input file is almost 3min long.

Moreover, I made one more test. I used the same "go" example (sip/test/client/main.go) to connect to another SIP client, here Microsip instead of livekit server with meet room, to interdependently verify the connectivity. The Microsip sees the incoming connection and it can be accepted. Nevertheless, the sound (should be file audio played by "go" app) is not audible (red icon of the connection in the Microsip), and again, after around 30s it times out. Tested on various configurations, such us: Linux machine, Windows, and Windows + WSL.

Hope it will give some hints or directions to trace the issue.

dennwc commented 3 weeks ago

Thank you for all the details! I currently investigating audio quality issues similar to what you mentioned. Will check this as well once I'm done.