AudioQueue will not make sound under Bluetooth HFP and AVAudioSessionCategoryPlayAndRecord

Hello!


I am making a VoIP app, and using AudioQueue for both record and playback.

AVAudioSession was set by following code:


[session setCategory:AVAudioSessionCategoryPlayAndRecord withOptions:
          AVAudioSessionCategoryOptionMixWithOthers |  //AVAudioSessionCategoryOptionDuckOthers | //
          AVAudioSessionCategoryOptionAllowBluetooth error:nil]


Everything works fine using built-in speaker/microphone, as well as a wired headset.


But once I connected my bluetooth HFP device (eg. Airpods)


[session setPreferredInput:hfpdevice error:nil];


The usage of microphone is re-routed to my airpods correctly, but my airpods do not make any sound from the AudioQueue.



AudioStreamBasicDescription audioFormat;
    bzero(&audioFormat, sizeof(AudioStreamBasicDescription));
    audioFormat.mSampleRate         = 44100;
    audioFormat.mFormatID           = kAudioFormatLinearPCM;
    audioFormat.mFormatFlags        = kAudioFormatFlagIsSignedInteger |
    kAudioFormatFlagsNativeEndian |
    kAudioFormatFlagIsPacked;
    audioFormat.mFramesPerPacket    = 1;
    audioFormat.mChannelsPerFrame   = 1;
    audioFormat.mBitsPerChannel     = 16;
    audioFormat.mBytesPerPacket = audioFormat.mBytesPerFrame = (audioFormat.mBitsPerChannel / 8) * audioFormat.mChannelsPerFrame;

Replies

Hello,

I have met the same problem as you mentioned above. I failed to use AudioQueue play PCM data with AVAudioSessionCategoryOptionAllowBluetooth. But when I use AVAudioSessionCategoryOptionAllowBluetoothA2DP, it works fine. I wonder how you solve this problem. Thank you.

Similar behavior here, but both avplayer and audioQueue failed to play. When airpods are connected, setting category to AVAudioSessionCategoryPlayAndRecord with AVAudioSessionCategoryOptionAllowBluetooth results in audio silence, only AVAudioSessionCategoryOptionAllowBluetoothA2DP is working.