amazon-chime-sdk-ios icon indicating copy to clipboard operation
amazon-chime-sdk-ios copied to clipboard

Audio issues when answering a call

Open javyduty opened this issue 2 years ago • 8 comments

Describe the bug Having issues with configuring audio when receiving calls. When I place a call it works as expected but when I answer a call it won't configure the audio and fails out. I guess I'm just looking for some general guidance as to what could be causing this discrepancy.

To Reproduce Steps to reproduce the behavior:

  1. Place a call from a different device
  2. Answer the call
  3. Cal connects but audio doesn't work
  4. Fails out call and attendee automatically drops

Expected behavior I expect that when I answer the call the AVAudioSession.setActive code doesn't fail with the error (OSStatus error 561017449.)

Logs

App[25333:2086171] pushRegistry:didReceiveIncomingPushWithPayload:forType:completion:
THE NAME OF THE PERSON CALLING IS - default
2022-09-23 19:58:53.182883+0200 App[25333:2086171] providerDidBegin
2022-09-23 19:58:53.198270+0200 App[25333:2086171] [INFO] Logger - Reported new incoming call successfully
2022-09-23 19:58:55.104843+0200 App[25333:2086171] provider:performAnswerCallAction:
START AUDIO CONFIG
2022-09-23 19:58:55.124620+0200 App[25333:2086171] [ERROR] Logger - Error configuring AVAudioSession: 
Error Domain=NSOSStatusErrorDomain Code=561017449 "(null)"
END AUDIO CONFIG

Screenshots

Test environment Info (please complete the following information):

  • Device: iPhone X
  • OS: 15.4
  • Version AmazonChimeSDK: 0.22.3
  • Version AmazonChimeSDKMedia: 0.17.7
  • Can you reproduce this in the demo app? No

Additional context In all honesty I am just looking for some general guidance. Everything is connecting as expected when I call out. No issues until I try to answer a call but the only issue with that is trying to configure the audio. It fails out with the error code above which I researched and means that another app is stopping my app from activating the audio but in this case I am receiving a call from a VOIP notification and answering it, connecting it and still it is failing. Is there a specific place that I should be configuring the audio so that this doesn't fail? Code provided below, any help would be greatly appreciated. I have been stuck on this for days.

func provider(_ provider: CXProvider, perform action: CXAnswerCallAction) {
        NSLog("provider:performAnswerCallAction:")
        
        ChimeCallManager.activeCall = true
        
        if ChimeCallManager.activeCall {
            configureAudioSession()

            action.fulfill()
        }
    }
    
func configureAudioSession() {
    print("START AUDIO CONFIG")
    let audioSession = AVAudioSession.sharedInstance()
    do {
        if audioSession.category != .playAndRecord {
            try audioSession.setCategory(AVAudioSession.Category.playAndRecord,
                                         options: AVAudioSession.CategoryOptions.allowBluetooth)
            try audioSession.setActive(true, options: .notifyOthersOnDeactivation) // <-------FAILS HERE WHEN RECEIVING CALL BUT WORKS WHEN PLACING A CALL
        }
        if audioSession.mode != .voiceChat {
            try audioSession.setMode(.voiceChat)
        }
    } catch {
        logger.error(msg: "Error configuring AVAudioSession: \(error)")
    }
    print("END AUDIO CONFIG")
}

func provider(_ provider: CXProvider, perform action: CXStartCallAction) {
  NSLog("provider:performStartCallAction:")
  
  configureAudioSession()
  ChimeCallManager.activeCall = true
  provider.reportOutgoingCall(with: action.callUUID, startedConnectingAt: Date())
  
  action.fulfill()
}

func startAudio() {
  let currentSession = ChimeCallManager.currentSession as! DefaultMeetingSession
  
  currentSession.audioVideo.addAudioVideoObserver(observer: self)
  currentSession.audioVideo.addRealtimeObserver(observer: self)
  
  do {
      try currentSession.audioVideo.start(callKitEnabled: true)
   } catch {
        logger.error(msg: "Error starting audioVideoFacade: \(error)")
    }
}

javyduty avatar Sep 23 '22 18:09 javyduty

Just fixed this, drove me crazy but the issue was that I was not configuring the audio before reporting the call to CallKit. Basically I had to call the configureAudioSession before reportIncomingCall so that the audio configuration is passed into CallKit. Hope this helps someone else facing this issue from days of google searches.

javyduty avatar Sep 23 '22 19:09 javyduty

I got past the issue but still no audio seeing this in the logs

App[68947:3492893] [ERROR] Logger - xal_core_audio: is_input = 1, callback requested number of frames = 278 > max_bufsize = 256
App[68947:3492893] [ERROR] Logger - xal_core_audio: is_input = 0, callback requested number of frames = 279 > max_bufsize = 278

javyduty avatar Sep 23 '22 21:09 javyduty

Also this prints out whenever I stop the audioVideoFacade

App[69195:3505373] provider:performEndCallAction:
App[69195:3505373] [INFO] Logger - API/DefaultAudioVideoFacade/stop
App[69195:3505574] [INFO] Logger - Stopping VideoClient
App[69195:3505820] [ERROR] Logger - xal_core_audio: AudioUnitRender failed -50
App[69195:3505820] [ERROR] Logger - xal_core_audio: AudioUnitRender failed -50
App[69195:3505820] [ERROR] Logger - xal_core_audio: AudioUnitRender failed -50
App[69195:3505373] [INFO] Logger - AudioClient State: finishDisconnecting Status: ok
App[69195:3505820] [ERROR] Logger - xal_core_audio: AudioUnitRender failed -50
App[69195:3505820] [ERROR] Logger - xal_core_audio: AudioUnitRender failed -50
App[69195:3505820] [ERROR] Logger - xal_core_audio: AudioUnitRender failed -50
App[69195:3505820] [ERROR] Logger - xal_core_audio: AudioUnitRender failed -50
App[69195:3505820] [ERROR] Logger - xal_core_audio: AudioUnitRender failed -50
App[69195:3505820] [ERROR] Logger - xal_core_audio: AudioUnitRender failed -50
App[69195:3505820] [ERROR] Logger - xal_core_audio: AudioUnitRender failed -50
App[69195:3505820] [ERROR] Logger - xal_core_audio: AudioUnitRender failed -50
App[69195:3505373] [INFO] Logger - videoClientDidStop
VIDEO SESSION STOPPED WITH STATUS - ok
App[69195:3505574] [INFO] Logger - Torch is not available on current camera.
App[69195:3505574] [INFO] Logger - VideoClient is being destroyed
App[69195:3505820] [ERROR] Logger - xal_core_audio: AudioUnitRender failed -50
App[69195:3505820] [ERROR] Logger - xal_core_audio: AudioUnitRender failed -50
App[69195:3505820] [ERROR] Logger - xal_core_audio: AudioUnitRender failed -50
App[69195:3505820] [ERROR] Logger - xal_core_audio: AudioUnitRender failed -50

javyduty avatar Sep 23 '22 21:09 javyduty

Current situation

Audio Calls:

  1. When the app on both phones are closed and a call is placed from one phone to another the call connects as expected, no issues.
  2. After number 1. I hang up, apps still open and make another call. Audio doesn't connect.
  3. After number 1. I close the app on the receiving phone and attempt to call again. Audio doesn't connect.

Video Calls:

  1. When the app on both phones are closed and a call is placed from one phone to another the call connects as expected, no issues.
  2. After number 1. I hang up, apps still open and make another call. Video doesn't connect, audio doesn't connect.
  3. After number 1. I close the app on the receiving phone and attempt to call again. Video doesn't connect, audio doesn't connect.

Configuration:

// running in provider(_ provider: didActivate)
try currentSession.audioVideo.start(callKitEnabled: true)
// configure audio function
print("START AUDIO CONFIG")
let audioSession = AVAudioSession.sharedInstance()
do {
  if isVideoCall {
      if audioSession.categoryOptions != .defaultToSpeaker {
          try audioSession.setCategory(AVAudioSession.Category.playAndRecord, options: [.defaultToSpeaker, .allowBluetooth])
          try audioSession.overrideOutputAudioPort(AVAudioSession.PortOverride.speaker)
          try audioSession.setActive(true)
      }
      if audioSession.mode != .videoChat {
          try audioSession.setMode(.videoChat)
      }
  } else {
      if audioSession.category != .playAndRecord {
          try audioSession.setCategory(AVAudioSession.Category.playAndRecord,
                                       options: AVAudioSession.CategoryOptions.allowBluetooth)
          try audioSession.setActive(true, options: .notifyOthersOnDeactivation)
      }
      if audioSession.mode != .voiceChat {
          try audioSession.setMode(.voiceChat)
      }
  }
} catch {
  logger.error(msg: "Error configuring AVAudioSession: \(error)")
}
print("END AUDIO CONFIG")
// when handling incoming voip push notification
configureAudioSession()

reportIncomingCall(from: caller, uuid: meetingId)
// running in provider(_ provider:  CXStartCallAction)
configureAudioSession()

provider.reportOutgoingCall(with: action.callUUID, startedConnectingAt: Date())

javyduty avatar Sep 24 '22 00:09 javyduty

Hi @javyduty, for the current situation it seems any additional call after the previous call can't make it through. I'm not sure about how your app behavior on start call and end call, does it clean up the configuration you made for the audio and video, does it call stop on audioVideo in SDK?

linsang21 avatar Sep 30 '22 20:09 linsang21

@linsang21 Thanks for the response. I am using a singleton to control the call as far as the DefaultMeetingSession and everything that is needed to configure that. I am also starting the audioVideo facade in the didActivate function of the provider. I am calling stop on the audioVideo facade in the didDeactivate of the provider. I will debug the endCall action in the provider (which I call from the view controller that has the video for the calls and the observers) I have noticed that either the observers don't get called on the second call or they get called after I end the call. Very strange, however when the app is completely closed, the call connects as expected.

// running in provider(_ provider: didDeactivate)
guard let currentSession = ChimeCallManager.currentSession as? DefaultMeetingSession else { return }
currentSession.audioVideo.stop()

javyduty avatar Sep 30 '22 21:09 javyduty

Hi @javyduty have you looked at this blogpost and our demo app implementation for CallKit integration. Hopefully that can help you on implementing this.

zhinang-amazon avatar Oct 11 '22 18:10 zhinang-amazon

@zhinang-amazon thanks for the response. I actually used that guide to set everything up and I have looked through the implementation on here for CallKit as well. There was a point where I had things working and connecting. I was looking for some more clarity on the errors that popped up in the log specifically this one that pops up when I end the call

App[69195:3505820] [ERROR] Logger - xal_core_audio: AudioUnitRender failed -50

Oddly enough when I start the call it says that it connected successfully but I can't hear anything on one phone and on the other I hear static as though it has connected. For clarity the dialing out phone has static and the receiving one has no sound. Same issue with video calls except that the video also does not connect. I'd like to be able to debug and fix these issues on my own, is there a resource for the error codes that I can reference?

javyduty avatar Oct 12 '22 16:10 javyduty

Hi we removed the code and pushed to minimal-callkit branch. Could you see if this helps?

hokyungh avatar Oct 21 '22 16:10 hokyungh

Thanks so much for this! I will check it out and let you know.

javyduty avatar Oct 25 '22 18:10 javyduty

Close for now, please open a support case if you still experience this issue.

georgezy-amzn avatar Nov 03 '22 00:11 georgezy-amzn

I know the issue is closed, just wanted to thank you again and let you know that minimal-call kit worked great!

javyduty avatar Mar 01 '23 02:03 javyduty