RemoteIO to AVAudioEngine port

I have a RemoteIO unit that successfully playbacks the microphone samples in realtime via attached headphones. I need to get the same functionality ported using AVAudioEngine, but I can't seem to make a head start. Here is my code, all I do is connect inputNode to playerNode which crashes.

var engine: AVAudioEngine!
var playerNode: AVAudioPlayerNode!
var mixer: AVAudioMixerNode!
var engineRunning = false

private func setupAudioSession() {
    
    var options:AVAudioSession.CategoryOptions = [.allowBluetooth, .allowBluetoothA2DP]
    
    
    do {
        try AVAudioSession.sharedInstance().setCategory(AVAudioSession.Category.playAndRecord, mode: AVAudioSession.Mode.default, options: options)
        try AVAudioSession.sharedInstance().setAllowHapticsAndSystemSoundsDuringRecording(true)
        
    } catch {
        MPLog("Could not set audio session category")
    }
    let audioSession = AVAudioSession.sharedInstance()
    
    do {
        try audioSession.setActive(false)
        try audioSession.setPreferredSampleRate(Double(44100))
    } catch {
        print("Unable to deactivate Audio session")
    }
    
    do {
        try audioSession.setActive(true)
    } catch {
        print("Unable to activate AudioSession")
    }
}

private func setupAudioEngine() {
    self.engine = AVAudioEngine()
    self.playerNode = AVAudioPlayerNode()
   
    self.engine.attach(self.playerNode)
    
    engine.connect(self.engine.inputNode, to: self.playerNode, format: nil)
    
    do {
        try self.engine.start()
    }
    catch {
        print("error couldn't start engine")
    }

    engineRunning = true
}

But starting AVAudioEngine causes a crash:

libc++abi: terminating with uncaught exception of type NSException
*** Terminating app due to uncaught exception 'com.apple.coreaudio.avfaudio', reason: 
'required condition is false: inDestImpl->NumberInputs() > 0 || graphNodeDest->CanResizeNumberOfInputs()'
terminating with uncaught exception of type NSException

How do I get realtime record and playback of mic samples via headphones working?

I was able to fix this by connecting inputNode and outputNode of AVAudioEngine instead of playerNode and mixerNode. I had misconception about playerNode which was cleared from WWDC 2014 video.

RemoteIO to AVAudioEngine port
 
 
Q