AVCaptureSession startRunning is slow

AVCaptureSession's startRunning method is thread blocking and seems to be slow. What is this method doing behind the scenes?

For context: I'm working on Simulator Camera support and I have a 'fake' AVCaptureDevice that might be causing this. My hypothesis is that AVCaptureSession tries to connect to the device and waits for a notification to be posted back.

I'd love to find a way to let my fake device message AVCaptureSession that it's connected.

@AvdLee If you're concerned about AVFoundation perf, maybe you'd like to boost and comment on this issue: https://developer.apple.com/forums/thread/743518

AVFoundation uses nearly 50% CPU by default because of Reactions, and there's apparently no way to turn it off!

Hi there, AVCaptureSession and all of its inputs and outputs are meant to be messaged on a dedicated serial queue. This is documented well in the AVCaptureSession.h header as well as in the AVFoundation camera documentation. Any calls that affect the underlying hardware configuration (such as starting or stopping the hardware) are blocking calls. They block until the operation has succeeded. For a change of cameras or change of formats, this could be on the order of 100 to 500 milliseconds.

You should never call AVCaptureSession on the main thread.

Yes, there is some communication between server processes and the client app process that drive the blocking and unblocking.

Thanks a lot for these insights, but I lack the answer I was looking for.

What exact message/notification is send from an AVCaptureDevice towards AVCaptureSession that will result in finished the startRunning method?

Once I know this, I can simulate a connected hardware device and help thousands of developers work on their camera apps in the Simulator.

AVCaptureSession startRunning is slow
 
 
Q