iosswiftwebrtc

iOS - WebRTC one way audio only with Opus Codec


I have a swift project that uses the GoogleWebRTC pod.

When trying to negotiate the OPUS codec for audio calls i find that the peer connection is successfully setup, however i am experiencing one way audio. SRTP is being sent from my iPhone to the other party successfully, and SRTP is being sent from the other party to my iPhone, however my phone/app is not playing the incoming SRTP to the user. If i negotiate any other codec (G722 for example) then i get 2 way audio, it's just when i try to negotiate OPUS that i don't hear any incoming audio on my iPhone.

Couldn't see anything relevant in the logs, but looking for some pointers on how to troubleshoot this or what could potentially be the cause of this issue.

I'm using the google WebRTC iOS SDK.

Here is the code in my webrtc class where i initialize the audio session if that helps.

   private func configureAudioSession() {
        self.rtcAudioSession.lockForConfiguration()
        do {
            try self.rtcAudioSession.setCategory(AVAudioSession.Category.playAndRecord.rawValue)
            try self.rtcAudioSession.setMode(AVAudioSession.Mode.voiceChat.rawValue)
        } catch let error {
            debugPrint("Error changeing AVAudioSession category: \(error)")
        }
        self.rtcAudioSession.unlockForConfiguration()
    }

Solution

  • For anybody else who stumbles across this, I wasn't using the audiosession provided by callkit in the didActivate method of the callprovider protocol.

    Here's my amended configureAudioSession

    private func configureAudioSession() {
        self.rtcAudioSession.lockForConfiguration()
        do {
             self.rtcAudioSession.useManualAudio = true
             self.rtcAudioSession.isAudioEnabled = false
            try self.rtcAudioSession.setCategory(AVAudioSession.Category.playAndRecord.rawValue)
            try self.rtcAudioSession.setMode(AVAudioSession.Mode.voiceChat.rawValue)
        } catch let error {
            debugPrint("Error changeing AVAudioSession category: \(error)")
        }
        self.rtcAudioSession.unlockForConfiguration()
    }
    

    And then in my provider delegate

     func provider(_ provider: CXProvider, didActivate audioSession: AVAudioSession) {
            print("Received \(#function)")
            
            webRTCClient.rtcAudioSession.audioSessionDidActivate(audioSession)
            webRTCClient.rtcAudioSession.isAudioEnabled = true
            // Start call audio media, now that the audio session has been activated after having its priority boosted.
            //   startAudio()
        }