CoreAudio crash - AVAudioIONodeImpl.mm:365: _GetHWFormat: required condition is false: hwFormat

Hi All,


I'm working with two application modules:


1) Recording module with this audioSession setup:



try audioSession.setCategory(AVAudioSessionCategoryRecord)
    try audioSession.setMode(AVAudioSessionModeMeasurement)
    try audioSession.setPreferredIOBufferDuration(0.05)
    try self.audioSession.setActive(true)



2) Recording module with this audioSession setup:


    try audioSession.setCategory(AVAudioSessionCategoryPlayback)
    try audioSession.setMode(AVAudioSessionModeDefault)
    try self.audioSession.setActive(true)



For each passage from 1->2 and 2-1 I have a

try self.audioSession.setActive(false)


If I pass from 1) module to 2) or redo 1) all works fine. Than if from 2) I come to 1) I get this error on

try self.audioSession.setActive(true)



This is the error:


ERROR: [0x16e10b000] >avae> AVAudioIONodeImpl.mm:365:

_GetHWFormat: required condition is false: hwFormat



What is this error related to? I can't find any help on Apple iOS documentation to understand where the problem can be.



Does anybody have any tip?

I think it is probably related to connections in AVAudioEngine. Like maybe you are not connected to the IO Node at all. I believe I ran into that in the past and that is what the problem was.

Changing categories / modes and activating / deactivating an audio session can completely reconfigure the audio system and changes routing and available devices and so on... So the real question isn't what you're doing with the Audio Session, it's how have you configured AVAudioEngine because that's where the problem is - AVAudioSession is just triggering the condition. We've had a number of these reports with only a couple of developers providing apps they say will reproduce the issue - please file a bug with something that we can use to duplicate this.


thank you.

Thank you for the support. How can I share my code with you?

I will prepare an app (simplification of mine) and share it with you.



Thank you

Filing a bug report with a test case that we can use to reproduce is the best thing to do. Thanks!

I submitted the problem:


issue # 30925278


Hope to have soon a feedback. I will let you know the answer

I did see this bug come in and it has been related to the other bugs we have describing the same issue (with different scenarios to reproduce). Very much has the feel of a race condition caused by routing changes and I'm doing what I can to raise the priority of the problem.


Appreciate you taking the time to submit the issue. Thanks!

It is likely that setting an audio session to false does not immediately and synchronously stop audio stuff (it's running in other hidden threads and/or OS processes). So if you try to configure a new audio session before the old one has skidded to a stop, the hardware resources are still locked up tight and can't be changed. Thus you get your error message.


The fix might be to wait one second (or so) before trying to change stuff that can't be changed (yet). That's probably enough time for audio stuff to really stop and be ready to start again.

Thank you very much for the support.

I am happy to help you find out what's going on and I hope my example will be useful to find out the problem.


Look forward to hearing from you.

Thanyou for the answer, audio session is a singleton in iOS, so actually I am not creating a new one. I have just tried to change setup.

Anyway, I tried with your advice but I still get the problem, even if some time has passed. It seems like it is a very deterministic situation so I think there is no link to time and changes to hardware.

Hi theanalogkid,


any news regarding this point? I still encounter the problem and I have to solve it since the app I am developing is going to be published soon...


Look forward to hearing from you.

I suggest contacting the Apple Media Evangelist (tidbits@apple.com), send your bug ID. This issue from the reports really appear to point to a race condition which will take sometime to isolate not to mention the time to make it into a general update.

Same issue here, but it works perfectly in the simulator.

Hi Dorian, the problem is an iOS bug which is still open. You can find here a work around I adopted:


http://stackoverflow.com/questions/42470848/coreaudio-crash-avaudioionodeimpl-mm365-gethwformat-required-condition-is


Hope it helps

Hi,


I'm encountering this same error message in my crash analytics. Is the bug still open?


thanks!

@ theanalogkid

are you still at apple? i've some detailed audio codec questions i'd like to ask you.

Hi,


This crash is still active and my app has it too on release products on AppStore. Cant reproduce on debug cases or cant reproduce for release app on all devices.


I use AVAudio like that and 12th line has a crash of "required condition is false: IsFormatSampleRateAndChannelCountValid(hwFormat)"



let recordingFormat: AVAudioFormat? = inputNode?.outputFormat(forBus: AVAudioNodeBus(0))
let inputFormat: AVAudioFormat? = inputNode?.inputFormat(forBus: AVAudioNodeBus(0))
var trueFormat: AVAudioFormat? = AVAudioFormat()
if inputFormat?.sampleRate == 0 {
            if let aChannels = AVAudioFormat(standardFormatWithSampleRate: 44100, channels: AVAudioChannelCount(2)) {
                trueFormat = aChannels
            }
}
else {
            trueFormat = inputFormat
}          
inputNode?.installTap(onBus: AVAudioNodeBus(0), bufferSize: AVAudioFrameCount(8192), format: trueFormat, block: { buffer, when in
            AppUtils.shared.recognitionRequest?.append(buffer)
})
AppUtils.shared.audioEngine?.prepare()


Hope there is a fix for it.


Thanks

Kaan

I don't know if this will work, but it did for me. I am also not 100% sure why it worked, but I think by changing the audio session mode from .measurement to .voicePrompt, it only requires voice input and not output. Therefore, with no output, the error of input format not matching output format cannot occur, because there is no output. Please find my bug fix below:


Old code with format matching error:


do {

AudioOutputUnitStop((audioEngine.inputNode.audioUnit)!)

AudioUnitUninitialize((audioEngine.inputNode.audioUnit)!)

try audioSession.setCategory(.playAndRecord, mode: .measurement, options: .duckOthers)

} catch let error {

print("\(error)")

}


New code without error:


do {

AudioOutputUnitStop((audioEngine.inputNode.audioUnit)!)

AudioUnitUninitialize((audioEngine.inputNode.audioUnit)!)

try audioSession.setCategory(.playAndRecord, mode: .voicePrompt, options: .duckOthers)

} catch let error {

print("\(error)")

}


I may be wrong as I am a novice still. But I hope this helps!

Any update/solution?

CoreAudio crash - AVAudioIONodeImpl.mm:365: _GetHWFormat: required condition is false: hwFormat
 
 
Q