AVCaptureVideoDataOutput and AVCaptureAudioDataOutput same queue

528 Views Asked by At

One of the recent sample codes from Apple uses same serial queue for receiving samples from AVCaptureVideoDataOutput and AVCaptureAudioDataOutput delegate. I need to know if this is acceptable practice from performance standpoint. Should one have different or single queue for both the sample buffer delegates? Particularly in the setting of multiple camera inputs/outputs, this becomes significant.

 private let dataOutputQueue = DispatchQueue(label: "data output queue")
 ...
 ...
 videoDataOutput.setSampleBufferDelegate(self, queue: dataOutputQueue)
 audioDataOutput.setSampleBufferDelegate(self, queue: dataOutputQueue)
1

There are 1 best solutions below

2
Bob de Graaf On

I guess when it comes to performance:

  1. It always depends on your situation. Perhaps for Apple's sample it was okay but maybe in your situation it really needs more.
  2. It's something you can try out for yourself. Try to get as many inputs as possible on the slowest device and see if the performance is still good enough.

There's a similar question where the performance wasn't good because of serial queues and the answer was to use concurrent queues, see here: Performance issues when using AVCaptureVideoDataOutput and AVCaptureAudioDataOutput

But once again, I suggest you try it out and see what works for you :)

Update

Here's a link that perfectly explains the differences and how to work with serial & concurrent queues: https://www.avanderlee.com/swift/concurrent-serial-dispatchqueue/