后台的CallKit音频初始化错误-首次通话后音频不起作用

时间:2019-02-11 09:26:58

标签: ios swift audio pjsip callkit

我最近在我的iOS App中添加了pjsip VoIP功能。在应用程序处于活动状态时,使用pjsip不会带来任何问题,我既可以接听电话,也可以进行通话。

但是我似乎在后台的声音设备有问题。我从后台收到的第一个电话工作正常,可以听到声音,并且可以正常关闭。

问题是在第一次通话后,我从后台接听电话时听不到声音。如果在应用程序处于活动状态时拨打或接听电话,然后转到后台接听电话,也会发生同样的情况。 当我关闭应用程序时,从后台进行的第一个“通话”再次正常工作。

我不知道是什么原因造成的。

我尝试通过CallManager手动关闭所有呼叫,并且在服务器端终止呼叫时呼叫CXEndCallAction,以使CallKit正常关闭。

我很乐意发布特定的代码段落,但是目前,我不知道问题可能在哪里……


更新:

我发现pjsip coreaudio的第二次初始化不同。

现在的问题是,如何正确重置pjsip中的CoreAudio?

成功的呼叫初始化:

11:03:01.615 tsx0x1030710a8  .....State changed from Trying to 
Proceeding, event=TX_MSG
11:03:01.615 dlg0x1030840a8  ......Transaction tsx0x1030710a8 state changed to Proceeding
2019-02-13 11:03:01.615745+0100 VarioCallCTI[11928:2820452] Incoming call from "Matthias" <sip:238@80.80.245.33>
11:03:01.618    pjsua_aud.c  ..Set sound device: capture=0, playback=0
11:03:01.618    pjsua_aud.c !Set sound device: capture=0, playback=0
11:03:01.619    pjsua_aud.c !...Opening sound device PCM@16000/1/20ms
11:03:01.619 coreaudio_dev.  ....Using VoiceProcessingIO audio unit
2019-02-13 11:03:01.808024+0100 VarioCallCTI[11928:2820452] [aurioc] 1029: failed: '!int' (enable 3, outf< 1 ch,  16000 Hz, Int16> inf< 1 ch,  16000 Hz, Int16>)
11:03:01.851    pjsua_aud.c  ...Opening sound device PCM@44100/1/20ms
11:03:01.851 coreaudio_dev.  ....Using VoiceProcessingIO audio unit
2019-02-13 11:03:01.859854+0100 VarioCallCTI[11928:2820452] [aurioc] 1029: failed: '!int' (enable 3, outf< 1 ch,  44100 Hz, Int16> inf< 1 ch,  44100 Hz, Int16>)
11:03:01.860    pjsua_aud.c  ...Opening sound device PCM@48000/1/20ms
11:03:01.860 coreaudio_dev.  ....Using VoiceProcessingIO audio unit
2019-02-13 11:03:01.867061+0100 VarioCallCTI[11928:2820452] [aurioc] 1029: failed: '!int' (enable 3, outf< 1 ch,  48000 Hz, Int16> inf< 1 ch,  48000 Hz, Int16>)
11:03:01.867    pjsua_aud.c  ...Opening sound device PCM@32000/1/20ms
11:03:01.867 coreaudio_dev.  ....Using VoiceProcessingIO audio unit
2019-02-13 11:03:01.874321+0100 VarioCallCTI[11928:2820452] [aurioc] 1029: failed: '!int' (enable 3, outf< 1 ch,  32000 Hz, Int16> inf< 1 ch,  32000 Hz, Int16>)
11:03:01.875    pjsua_aud.c  ...Opening sound device PCM@16000/1/20ms
11:03:01.875 coreaudio_dev.  ....Using VoiceProcessingIO audio unit
2019-02-13 11:03:01.881126+0100 VarioCallCTI[11928:2820452] [aurioc] 1029: failed: '!int' (enable 3, outf< 1 ch,  16000 Hz, Int16> inf< 1 ch,  16000 Hz, Int16>)
11:03:01.881    pjsua_aud.c  ...Opening sound device PCM@8000/1/20ms
11:03:01.881 coreaudio_dev.  ....Using VoiceProcessingIO audio unit
2019-02-13 11:03:01.888214+0100 VarioCallCTI[11928:2820452] [aurioc] 1029: failed: '!int' (enable 3, outf< 1 ch,   8000 Hz, Int16> inf< 1 ch,   8000 Hz, Int16>)
11:03:01.888    pjsua_aud.c  ...Unable to open sound device: Unknown error -560117684 [status=-560117684]
Error in Setting of Audio Devices - IncomingCall
TESTPRINT FOR NOTIFICATION INFO: eingehender anruf von 238
TESTPRINT FOR NOTIFICATION INFO: 238

呼叫初始化失败:

    11:03:49.840 tsx0x103064ea8  .....State changed from Trying to Proceeding, event=TX_MSG
11:03:49.840 dlg0x1030906a8  ......Transaction tsx0x103064ea8 state changed to Proceeding
2019-02-13 11:03:49.841013+0100 VarioCallCTI[11928:2820906] Incoming call from "Matthias" <sip:238@80.80.245.33>
11:03:49.842    pjsua_aud.c  ..Set sound device: capture=0, playback=0

11:03:49.842    pjsua_aud.c  ...Opening sound device PCM@16000/1/20ms
11:03:49.842 coreaudio_dev.  ....Using VoiceProcessingIO audio unit
11:03:49.847    pjsua_aud.c !Set sound device: capture=0, playback=0
2019-02-13 11:03:50.276837+0100 VarioCallCTI[11928:2820280] [avas] AVAudioSessionPortImpl.mm:56:ValidateRequiredFields: Unknown selected data source for Port Speaker (type: Speaker)
2019-02-13 11:03:50.277597+0100 VarioCallCTI[11928:2820280] [avas] AVAudioSessionPortImpl.mm:56:ValidateRequiredFields: Unknown selected data source for Port Receiver (type: Receiver)
2019-02-13 11:03:50.292488+0100 VarioCallCTI[11928:2820280] [avas] AVAudioSessionPortImpl.mm:56:ValidateRequiredFields: Unknown selected data source for Port Receiver (type: Receiver)
2019-02-13 11:03:50.293379+0100 VarioCallCTI[11928:2820280] [avas] AVAudioSessionPortImpl.mm:56:ValidateRequiredFields: Unknown selected data source for Port Receiver (type: Receiver)
11:03:50.383 coreaudio_dev. !....core audio stream started
Setting of Audio Devices Successfull - IncomingCall











TESTPRINT FOR NOTIFICATION INFO: eingehender anruf von 238
TESTPRINT FOR NOTIFICATION INFO: 238

1 个答案:

答案 0 :(得分:0)

我已经找到了解决问题的方法。

由于PJSIP库Init导致coreAudio在iOS所需的优先级缓冲未完全完成之前进行初始化,因此我不得不打开CallKit并在CallKit-ProviderDelegate中的PJSIP服务器上注册

  func reportIncomingCall(uuid: UUID, handle: String, hasVideo: Bool = false, completion: ((NSError?) -> Void)?) {
let update = CXCallUpdate()
update.remoteHandle = CXHandle(type: .generic, value: handle)
update.hasVideo = hasVideo
//MARK: Final Working Solution
print("Starting PJSIP after PUSH")
pjsipfunctions.init().registersip(mainUser.sipData["User"], mainUser.sipData["Password"], mainUser.sipData["Server"])

provider.reportNewIncomingCall(with: uuid, update: update) { error in
  if error == nil {
    let call = Call(uuid: uuid, handle: handle)
    self.callManager.add(call: call)
    userTerminatedCall = false

  }

  completion?(error as? NSError)
}
}
}