Audio Errors on iOS

115 views
Skip to first unread message

Gordon Grech

unread,
Oct 1, 2024, 6:03:25 PM10/1/24
to baresip
Hello all,

I am trying to integrate Baresip on iOS using CallKit. My main app is written in Rust. I am currently implementing incoming calls. Call routing works very well, however I am having a hard time when it comes to audio. I am facing several issues, however the most problematic one is one way audio. I.e. Microphone generally works however speaker never works. I am using Baresip and re version 3.15.0.

My audio config looks like this:

#audio_path /usr/local/share/baresip
audio_player audiounit,default
audio_source audiounit,default
audio_alert     audiounit,default
#ausrc_srate 48000
#auplay_srate 48000
#ausrc_channels 1
#auplay_channels 1
#audio_txmode poll # poll, thread
audio_level     no
ausrc_format s16 # s16, float, ..
auplay_format s16 # s16, float, ..
auenc_format s16 # s16, float, ..
audec_format s16 # s16, float, ..
audio_buffer 20-160 # ms
audio_buffer_mode fixed # fixed, adaptive
audio_silence -35.0 # in [dB]
audio_telev_pt 101 # payload type for telephone-event

And here is a trace of the errors:

Oct  1 22:55:41 uc-app-mobile[5935] <Notice>: uag: add local address fd94:4a4c:6139::1
Oct  1 22:55:41 uc-app-mobile[5935] <Notice>: opus: fmtp="stereo=1;sprop-stereo=1;maxaveragebitrate=28000"
Oct  1 22:55:41 uc-app-mobile[5935] <Notice>: aucodec: opus/48000/2
Oct  1 22:55:41 uc-app-mobile[5935] <Notice>: audiounit: using component 'Apple: AUVoiceIO'
Oct  1 22:55:41 uc-app-mobile[5935] <Notice>: audiounit: using component 'Apple: AUConverter'
Oct  1 22:55:41 uc-app-mobile[5935] <Notice>: auplay: audiounit
Oct  1 22:55:41 uc-app-mobile[5935] <Notice>: ausrc: audiounit
Oct  1 22:55:41 uc-app-mobile[5935] <Notice>: \134^[[31mmodule avcapture.so: No such file or directory [2]
Oct  1 22:55:41 uc-app-mobile[5935] <Notice>: \134^[[;muuid: generated new UUID in /private/var/mobile/Containers/Data/Application/11C1FE58-AED4-45F5-B71F-5EB4585698D8/Library/Application Support/com.nebry.uc.app/sip/uuid
Oct  1 22:55:41 uc-app-mobile[5935] <Notice>: uuid: loaded UUID 1ef4b92a-b083-533e-2e79-2d9140d11b3f from file /private/var/mobile/Containers/Data/Application/11C1FE58-AED4-45F5-B71F-5EB4585698D8/Library/Application Support/com.nebry.uc.app/sip/uuid
Oct  1 22:55:41 uc-app-mobile[5935] <Notice>: mediaenc: srtp
Oct  1 22:55:41 uc-app-mobile[5935] <Notice>: mediaenc: srtp-mand
Oct  1 22:55:41 uc-app-mobile[5935] <Notice>: mediaenc: srtp-mandf
Oct  1 22:55:41 uc-app-mobile[5935] <Notice>: module: loading app account.so
Oct  1 22:55:41 uc-app-mobile[5935] <Notice>: ua: ua_register sip:user@--
Oct  1 22:55:41 uc-app-mobile[5935] <Notice>: Populated 1 account
Oct  1 22:55:41 uc-app-mobile[5935] <Notice>: module: loading app netroam.so
Oct  1 22:55:41 uc-app-mobile[5935] <Notice>: Populated 1 audio codec
Oct  1 22:55:41 uc-app-mobile[5935] <Notice>: Populated 0 audio filters
Oct  1 22:55:41 uc-app-mobile[5935] <Notice>: Populated 0 video codecs
Oct  1 22:55:41 uc-app-mobile[5935] <Notice>: Populated 0 video filters
Oct  1 22:55:41 uc-app-mobile[5935] <Notice>: \134^[[;mC-019238d6-3b60-7276-b737-e1abb51a338e@--net: Using media encryption 'srtp-mand'
Oct  1 22:55:41 uc-app-mobile[5935] <Notice>: ua: ua_register sip:C-019238d6-3b60-7276-b737-e1abb51a338e@--:5061
Oct  1 22:55:41 uc-app-mobile[5935] <Notice>: C-019238d6-3b60-7276-b737-e1abb51a338e@--.net: (prio 0) {0/TLS/v4} 200 OK (Nebry UC Gateway 1.0) [1 binding]
Oct  1 22:55:41 uc-app-mobile[5935] <Notice>: ua: sipsess connect via TLS x.x.x.x:5061 --> 192.168.0.17:49461
Oct  1 22:55:41 uc-app-mobile[5935] <Notice>: C-019238d6-3b60-7276-b737-e1abb51a338e@--.net: selected for C-019238d6-3b60-7276-b737-e1abb51a338e-0x11bd08540
Oct  1 22:55:41 uc-app-mobile[5935] <Notice>: ua: using connection-address x.x.x.x of SDP offer
Oct  1 22:55:41 uc-app-mobile[5935] <Notice>: call: alloc with params laddr=192.168.0.17, af=AF_INET, use_rtp=1
Oct  1 22:55:41 uc-app-mobile[5935] <Notice>: call: use_video=0
Oct  1 22:55:41 uc-app-mobile[5935] <Notice>: stream: audio: starting mediaenc 'srtp-mand' (wait_secure=0)
Oct  1 22:55:41 uc-app-mobile[5935] <Notice>: call: answering call on line 1 from sip:10...@x.x.x.x with 200
Oct  1 22:55:41 uc-app-mobile[5935] <Notice>: stream: update 'audio'
Oct  1 22:55:41 uc-app-mobile[5935] <Notice>: stream: disable audio RTP receiver
Oct  1 22:55:41 uc-app-mobile[5935] <Notice>: stream: disable audio RTP sender
Oct  1 22:55:41 uc-app-mobile[5935] <Notice>: stream: audio: starting mediaenc 'srtp-mand' (wait_secure=0)
Oct  1 22:55:41 uc-app-mobile[5935] <Notice>: srtp: audio: SRTP is Enabled (cryptosuite=AES_CM_128_HMAC_SHA1_80)
Oct  1 22:55:41 uc-app-mobile[5935] <Notice>: call: mediaenc event 'Secure' (audio,AES_CM_128_HMAC_SHA1_80)
Oct  1 22:55:41 uc-app-mobile[5935] <Notice>: stream: enable audio RTP sender
Oct  1 22:55:41 uc-app-mobile[5935] <Notice>: stream: audio: starting RTCP with remote x.x.x.x:14981
Oct  1 22:55:41 uc-app-mobile[5935] <Notice>: audio: update
Oct  1 22:55:41 uc-app-mobile[5935] <Notice>: audio: Set audio decoder: opus 48000Hz 2ch
Oct  1 22:55:41 uc-app-mobile[5935] <Notice>: \134^[[31maudiounit: player failed: 561017449 (!pri)
Oct  1 22:55:41 uc-app-mobile[5935] <Notice>: \134^[[;m\134^[[31maudio: start_player failed (audiounit.default): Operation not supported by device [19]
Oct  1 22:55:41 uc-app-mobile[5935] <Notice>: \134^[[;maudio: Set audio encoder: opus 48000Hz 2ch
Oct  1 22:55:41 uc-app-mobile[5935] <Notice>: opus: encoder fmtp ()2024-10-01 22:55:41.758 uc-app-mobile[5935:2958641] Failed to handle CXAnswerCallAction: Error Domain=NSOSStatusErrorDomain Code=561017449 "Session activation failed" UserInfo={NSLocalizedDescription=Session activation failed}.

After a while I get flooded with these:
 
Oct  1 22:55:42 uc-app-mobile(libEmbeddedSystemAUs.dylib)[5935] <Error>: throwing -1
Oct  1 22:55:42 uc-app-mobile(libEmbeddedSystemAUs.dylib)[5935] <Error>:   from <private>, render err: -1
Oct  1 22:55:42 uc-app-mobile(libEmbeddedSystemAUs.dylib)[5935] <Error>: throwing -1
Oct  1 22:55:42 uc-app-mobile(libEmbeddedSystemAUs.dylib)[5935] <Error>:   from <private>, render err: -1
Oct  1 22:55:42 uc-app-mobile(libEmbeddedSystemAUs.dylib)[5935] <Error>: throwing -1
Oct  1 22:55:42 uc-app-mobile(libEmbeddedSystemAUs.dylib)[5935] <Error>:   from <private>, render err: -1

I have experimented a lot in Swift and with configuration params, not much seems to change. In general my approach in callkit is as follows:

    override init() {
        NSLog("Inintalizing call manager")
        provider = CXProvider(configuration: CallManager.providerConfiguration())
        super.init()
        provider.setDelegate(self, queue: nil)
        do {
            try configureAudioSession()
        } catch {
            NSLog("Failed to handle init: \(error).")
        }
    }

    func provider(_ provider: CXProvider, perform action: CXAnswerCallAction) {
        do {
            activateAudioSession()
            try Job.callAnswer(callId: action.callUUID.uuidString.lowercased())
            action.fulfill()
            NSLog("Call answered successfully")
        } catch {
            NSLog("Failed to handle CXAnswerCallAction: \(error).")
            action.fail()
        }
    }

    func configureAudioSession() throws {
        let audioSession = AVAudioSession.sharedInstance()
        try audioSession.setCategory(.playAndRecord, mode: .voiceChat, options: [])
    }

    func activateAudioSession() throws {
        let audioSession = AVAudioSession.sharedInstance()
        try audioSession.setActive(true)
    }

Any help would be immensely appreciated.

Gordon


Gordon Grech

unread,
Oct 2, 2024, 5:49:30 PM10/2/24
to baresip
After additional troubleshooting it does seem that the failure is originating from audiounit/player.c specifically the below: 

ret = AudioUnitInitialize(st->au);
if (ret)
goto out;

I will keep on testing tomorrow. 

Gordon Grech

unread,
Oct 3, 2024, 6:57:59 AM10/3/24
to baresip
I found a solution to the audio problem. Call must be answered from didActivate audioSession not in action: CXAnswerCallAction. 

It seems that in CXAnswerCallAction the ausioSession is busy because of the ringer. I am still getting a lot of errors, but at least now audio works both ways. 
Reply all
Reply to author
Forward
0 new messages