I am trying to add multiple audio AVCaptureDeviceInputs to an AVCaptureSession (macOS).
My understanding is that AVCaptureConnections are automatically created between compatible inputs and outputs.
I can successfully add a single camera and audio device absolutely fine. My problem comes when adding a second audio device. I would like to overlay the audio from multiple sources.
Audio inputs are added as follows:
for device in newDevices {
do {
let newAudioDeviceInput = try AVCaptureDeviceInput(device: device)
if self.captureSession.canAddInput(newAudioDeviceInput) {
self.captureSession.addInput(newAudioDeviceInput)
self.audioDeviceInputs.append(newAudioDeviceInput)
}
} catch {
errors.append(error)
}
}
print(captureSession.inputs.count)
successfully shows the correct number of inputs
Output is added as follows:
let audioDataOutput = AVCaptureAudioDataOutput()
audioDataOutput.setSampleBufferDelegate(delegate, queue: queue)
if self.captureSession.canAddOutput(audioDataOutput) {
self.captureSession.addOutput(audioDataOutput)
self.audioDataOutput = audioDataOutput
} else {
throw Error.cannotAddOutput
}
A single AVCaptureConnection is created between the first input added and the output, but no subsequent inputs are added to the connection.
I'm really struggling to find any decent documentation on this, so any suggestions much appreciated. My expectation would be each additional AVCaptureDeviceInput would be added to the same connection inputs array.