arnonym / ha-plugins

Home-Assistant SIP Gateway
Apache License 2.0
157 stars 19 forks source link

weird audio message behaviour on home network #61

Closed whi4 closed 1 year ago

whi4 commented 1 year ago

Hi, I am beginning to use this plugin and seem to be going along well.

I have used the "Call number for help" example from the homeassistant site and it works ok if I call an "external" number, like xxx@sip.linphone.org. The tts works ok, and tts works ok to my mediaplayers at home.

The weird thing is that it does not work if I call a phone connected to my fritzbox. My fritzbox is connected directly to the internet and I am using a google wifi for my home devices. So my homeassistant is on 192.168.86.x and my fritzbox is on 192.168.189.1. The fritz.box address does not work on my home wireless network (at the moment) and I have used to ip for the sip registration.

I hope the attached log file identifies why there is no sound on the phone.

`:55:25.556    pjsua_aud.c  ......Audio channel update..
19:55:25.556 ilbc0xb5046054  .......iLBC codec opened, mode=30
19:55:25.556 strm0xb5055034  .......VAD temporarily disabled
19:55:25.556 strm0xb5055034  .......Encoder stream started
19:55:25.556 strm0xb5055034  .......Decoder stream started
19:55:25.556  pjsua_media.c  ......Audio updated, stream #0: iLBC (sendrecv)
| 20:59:09.557194 [1] onCallMediaState call info state 5
| 20:59:09.557517 [1] Connected media 1
08:19:58.213 strm0xb5055034  VAD re-enabled
| 20:59:10.526608 [1] Call is established.
| 20:59:10.526893 [ ] Calling webhook sip_call_webhook_id with data {'event': 'call_established', 'caller': 'sip:**610@192.168.189.1', 'parsed_caller': '**610', 'sip_account': 1}
| 20:59:10.563233 [ ] Webhook response 200 b''
| 20:59:10.563877 [1] Playing message: This is the repeating message.
| 20:59:10.587613 [ ] Getting audio from "http://192.168.86.3:8123/api/tts_proxy/c59c73a5b9f55907d78e3b056d08773343623ae6_en_-_google_translate.mp3"
16:34:38.793    pjsua_aud.c !Creating file player: /tmp/tmpnvakqa72.wav..
16:34:38.793   wav_player.c  .File player '/tmp/tmpnvakqa72.wav' created: samp.rate=24000, ch=1, bufsize=4KB, filesize=119KB
16:34:38.793    pjsua_aud.c  .Player created, id=2, slot=4
16:34:38.793    pjsua_aud.c  Conf connect: 4 --> 1
16:34:38.793   conference.c  .Port 4 (/tmp/tmpnvakqa72.wav) transmitting to port 1 (sip:**610@192.168.189.1)
| 20:59:10.793615 [1] No action supplied
| 20:59:13.293075 [1] Playback done.
| 20:59:13.303426 [1] Scheduled post action: repeat_message
| 20:59:13.303829 [1] Playing message: This is the repeating message.
| 20:59:13.331658 [ ] Getting audio from "http://192.168.86.3:8123/api/tts_proxy/c59c73a5b9f55907d78e3b056d08773343623ae6_en_-_google_translate.mp3"
04:54:57.539    pjsua_aud.c !Destroying player 2..
04:54:57.539    pjsua_aud.c  Creating file player: /tmp/tmpzs64qzs4.wav..
11:23:13.540   wav_player.c  .File player '/tmp/tmpzs64qzs4.wav' created: samp.rate=24000, ch=1, bufsize=4KB, filesize=119KB
11:23:13.540    pjsua_aud.c  .Player created, id=2, slot=4
11:23:13.540    pjsua_aud.c  Conf connect: 4 --> 1
11:23:13.540   conference.c  .Port 4 (/tmp/tmpzs64qzs4.wav) transmitting to port 1 (sip:**610@192.168.189.1)
| 20:59:16.053541 [1] Playback done.
| 20:59:16.070702 [1] Scheduled post action: repeat_message
| 20:59:16.070952 [1] Playing message: This is the repeating message.
| 20:59:16.100108 [ ] Getting audio from "http://192.168.86.3:8123/api/tts_proxy/c59c73a5b9f55907d78e3b056d08773343623ae6_en_-_google_translate.mp3"
20:12:20.304    pjsua_aud.c !Destroying player 2..
02:40:36.305    pjsua_aud.c  Creating file player: /tmp/tmpvxr14bwz.wav..
02:40:36.305   wav_player.c  .File player '/tmp/tmpvxr14bwz.wav' created: samp.rate=24000, ch=1, bufsize=4KB, filesize=119KB
02:40:36.305    pjsua_aud.c  .Player created, id=2, slot=4
02:40:36.305    pjsua_aud.c  Conf connect: 4 --> 1
02:40:36.305   conference.c  .Port 4 (/tmp/tmpvxr14bwz.wav) transmitting to port 1 (sip:**610@192.168.189.1)
13:27:00.659   pjsua_core.c  .RX 774 bytes Request msg BYE/cseq=26140 (rdata0xb4fdd0b4) from UDP 192.168.189.1:5060:
BYE sip:homeassistant@192.168.189.22:5060;ob SIP/2.0

Via: SIP/2.0/UDP 192.168.189.1:5060;branch=z9hG4bKF2DBDF21E0EAE5A8

From: <sip:**610@192.168.189.1>;tag=4916BAAA0EF82B76

To: <sip:homeassistant@192.168.189.1>;tag=UBALvLVX8I7v-xMPfgZXJ0jNjcoLQcDX

Call-ID: MOwAoJuEb4Lv9kwU0cuMId0U8XbLRBXO

CSeq: 26140 BYE

X-RTP-Stat: CS=0;PS=214;ES=462;OS=10700;SP=0/0;SO=0;QS=-;PR=0;ER=462;OR=0;CR=0;SR=0;QR=-;PL=0,0;BL=0;LS=0;RB=0/0;SB=0/0;EN=iLBC-30,G722;DE=;JI=0,0;DL=0,0,0;IP=192.168.189.1:7080,192.168.86.3:4019

X-RTP-Stat-Add: DQ=0;DSS=0;DS=0;PLCS=0;JS=0

X-SIP-Stat: DRT=0;IR=0

Reason: Q.850; cause=16

Max-Forwards: 70

User-Agent: AVM FRITZ!Box 7490 (UI) 113.07.29 (Oct 26 2021)

Supported: 100rel,replaces,timer

Allow-Events: telephone-event,refer

Content-Length: 0

--end msg--
20:55:16.660   pjsua_core.c  .......TX 319 bytes Response msg 200/BYE/cseq=26140 (tdta0xb511eb34) to UDP 192.168.189.1:5060:
SIP/2.0 200 OK

Via: SIP/2.0/UDP 192.168.189.1:5060;received=192.168.189.1;branch=z9hG4bKF2DBDF21E0EAE5A8

Call-ID: MOwAoJuEb4Lv9kwU0cuMId0U8XbLRBXO

From: <sip:**610@192.168.189.1>;tag=4916BAAA0EF82B76

To: <sip:homeassistant@192.168.189.1>;tag=UBALvLVX8I7v-xMPfgZXJ0jNjcoLQcDX

CSeq: 26140 BYE

Content-Length:  0

--end msg--
20:55:16.660  pjsua_media.c  ......Call 1: deinitializing media..
20:55:16.660  pjsua_media.c  .......
  [DISCONNCTD] To: sip:**610@192.168.189.1;tag=4916BAAA0EF82B76

    Call time: 00h:00m:07s, 1st res in 106 ms, conn in 2203ms
    #0 audio iLBC @8kHz, sendrecv, peer=-
       SRTP status: Not active Crypto-suite: 
       ICE role: Unknown, state: Candidate Gathering, comp_cnt: 2
       RX pt=99, last update:00h:00m:02.225s ago
          total 0pkt 0B (0B +IP hdr) @avg=0bps/0bps
          pkt loss=0 (0.0%), discrd=0 (0.0%), dup=0 (0.0%), reord=0 (0.0%)
                (msec)    min     avg     max     last    dev
          loss period:   0.000   0.000   0.000   0.000   0.000
          jitter     :   0.000   0.000   0.000   0.000   0.000
       TX pt=99, ptime=30, last update:never
          total 181pkt 9.0KB (16.2KB +IP hdr) @avg=10.1Kbps/18.3Kbps
          pkt loss=0 (0.0%), dup=0 (0.0%), reorder=0 (0.0%)
                (msec)    min     avg     max     last    dev 
          loss period:   0.000   0.000   0.000   0.000   0.000
          jitter     :   0.000   0.000   0.000   0.000   0.000
       RTT msec      :   0.000   0.000   0.000   0.000   0.000
03:23:32.661  pjsua_media.c  ........Media stream call01:0 is destroyed
03:23:32.661        icetp00  .......Stopping ICE, reason=media stop requested
03:23:32.661  ice_session.c  .......ICE session 0xb6a5d9a4 destroyed
03:23:32.661        icetp00  .......ICE stream transport 0xb52dc004 destroyed
| 20:59:16.661804 [1] Call disconnected
| 20:59:16.662350 [ ] Calling webhook sip_call_webhook_id with data {'event': 'call_disconnected', 'caller': 'sip:**610@192.168.189.1', 'parsed_caller': '**610', 'sip_account': 1}
| 20:59:16.691315 [ ] Webhook response 200 b''
| 20:59:16.692056 [ ] Remove from state: sip:**610@192.168.189.1
20:55:17.660    pjsua_aud.c  Closing sound device after idle for 1 second(s)
20:55:17.660    pjsua_aud.c  .Closing null sound device..
whi4 commented 1 year ago

Sorry if that is hard to read. I am not sure how to neatly include the log.

Thanks in advance. The plug-in looks very useful

Regards, Robert

whi4 commented 1 year ago

I have a little more information:

Phone **610@fritz.box is actually a DECT handset that only supports G.726.

Is this codec currently supported?

Thanks, Robert

arnonym commented 1 year ago

Hi Robert,

currently the following audio codecs are supported: speex/16000/1, speex/8000/1, speex/32000/1, iLBC/8000/1, GSM/8000/1, PCMU/8000/1, PCMA/8000/1, G722/16000/1, opus/48000/2, L16/44100/2, L16/44100/1

Probably makes sense to look into that and install the libraries for pjsip so more codecs are supported.

In your case the question would be, if the fritz.box is able to re-encode the audio stream to the one that is supported on the particular device.

Regards, Arne

whi4 commented 1 year ago

Hi Arne,

Thanks for looking into this. I found this url: https://docs.pjsip.org/en/latest/overview/features_codec.html

The fritzbox 7490 does not seem to transcode for the dect handset. I cannot find any menu selections or info online.

Regards, Robert

whi4 commented 1 year ago

also this: https://en.avm.de/service/knowledge-base/dok/FRITZ-Box-7340-int/1008_Supported-voice-codecs-for-internet-telephony/

arnonym commented 1 year ago

The pjsip page says the Intel IPP codecs are deprecated: https://docs.pjsip.org/en/latest/specific-guides/audio/ipp.html#guide-ipp

Also using them in pjsip requires some sort of license: https://trac.pjsip.org/repos/wiki/Intel_IPP_Codecs#LinuxInstructions

Also it looks like these IPP codecs are optimized for Intel SIMD instructions, which are not available on ARM.

Not sure what to make from all of this, but it looks like there are some blockers.

Which DECT phone are we talking about?

whi4 commented 1 year ago

Hi Arne,

The additional libraries do not look promising, you are right.

I am using my fritzbox as a dect base station and have several panasonic dect phones around the house.

I have my hass system connected to wifi and was hoping to use your add-on to supplement the capabilities of the fritzbox.

I was planning to setup ha automations to divert incoming calls at particular times and also to attempt some limited conference calling.

It appears that the dect phones (in the 61x fritzbox range) do not behave like proper sip phones (in the 62x fritzbox range)

I was hoping to implement voice menus on the dect phones, but that now does not look likely.

Regards, Robert

arnonym commented 1 year ago

I guess you're out of luck here. Maybe you can try to run asterisk somewhere and have it transcode between the codecs, but that's probably not an easy task.

Sorry for not being able to help you

whi4 commented 1 year ago

Hi Arne

Thanks for your support here.

I have overcome this "problem" by setting up an additional sip account at linphone.org for the dect phone. (Within fritzbox the new sip account is a new phone number and only one dect phone will ring with that number)

The menu example works fine now (I am using sip:xxx@sip.linphone.org rather than sip:**610@fritz.box)

It looks like the fritzbox handles the local dect phone stuff differently when you call it locally.

I am looking forward to continuing to learn about your add-in.

Regards, Robert

arnonym commented 1 year ago

Hi Robert,

thanks for the feedback, glad you could overcome the hurdles! Have fun creating menus and stuff :-).

Arne