Why is AVAudioEngine unable to convert the format from my bluetooth headphones Input?

286 views Asked by At

I have been using AVAudioEngine to take audio from the mic and send it out over a WebRTC connection. When I use the iPhone device mic, this seems to work as expected. But if I run the app with bluetooth headphones connected, the engine reports this error when trying to start:

[avae]  AVAudioEngine.mm:160   Engine@0x2833e1790: could not initialize, error = -10868
[avae]  AVAEInternal.h:109   [AVAudioEngineGraph.mm:1397:Initialize: (err = AUGraphParser::InitializeActiveNodesInInputChain(ThisGraph, *GetInputNode())): error -10868
Error starting audio engine: The operation couldn’t be completed. (com.apple.coreaudio.avfaudio error -10868.)

I see that Error code -10878 is:

@constant       kAudioUnitErr_FormatNotSupported
Returned if an input or output format is not supported
...
kAudioUnitErr_FormatNotSupported        = -10868

but that doesn't seem like it can be quite correct. I know that the output format is supported because the same format works correctly when my headphones are not attached. And I am pretty sure that the input format is supported because I am able to simply hook up Headphones InputNode -> Mixer -> Headphones OutputNode and correctly hear the audio from the mic.

So I can only assume that this means the format conversion is not supported.

My Questions:

  1. Is this a bug?
  2. Is there any way I can work around this?

Notes:

  • My full audio graph looks like this, where all the "mixers" are just AVAudioMixerNodes:
// InputNode (Mic)  ->  Mic Mixer -\
//                                   >->    WebRTC Mixer -> Tap -> WebRTC Framework
// AudioPlayer 1 -> Player Mixer  -/
//
// AudioPlayer 2 -> Player Mixer -----> LocalOutputMixer -> OutputNode (Device Speakers/Headphones)

but the issue still happens even if I simplify down to this:

InputNode (Mic)  ->  Mixer -> Tap -> WebRTC Framework

Specifically it happens when a single mixer node is connected with an input format and output format as follows:

  • The input format is:
(lldb) po audioEngine.inputNode.inputFormat(forBus: 0).streamDescription.pointee
▿ AudioStreamBasicDescription
  - mSampleRate : 16000.0
  - mFormatID : 1819304813
  - mFormatFlags : 41
  - mBytesPerPacket : 4
  - mFramesPerPacket : 1
  - mBytesPerFrame : 4
  - mChannelsPerFrame : 1
  - mBitsPerChannel : 32
  - mReserved : 0
  • The output format WebRTC expects is:
▿ AudioStreamBasicDescription
          - mSampleRate : 48000.0
          - mFormatID : 1819304813
          - mFormatFlags : 12
          - mBytesPerPacket : 2
          - mFramesPerPacket : 1
          - mBytesPerFrame : 2
          - mChannelsPerFrame : 1
          - mBitsPerChannel : 16
          - mReserved : 0
  • My headphones are Jaybird Freedom 2.
0

There are 0 answers