cameraextension icon indicating copy to clipboard operation
cameraextension copied to clipboard

I think this causes high CPU usage

Open michaelforrest opened this issue 1 year ago • 4 comments

I've been hammering on my own camera extension for a few months now and the example I was using (which I think was based on your example here) uses DispatchSource.makeTimerSource() to schedule this 3 times every frame instead of calling it continuously.

Your method appeals to me as it feels less hit and miss than polling every few milliseconds and hoping for the best, but it does seem to hike up the CPU usage.

I'm wondering if you've found the same thing and moved on from this way of polling the sample buffer or if there's something I don't know?

Thanks, I really appreciate you putting up this minimal sample - the documentation on this subject is SO thin on the ground! (Will we ever get our promised sample project?? seems unlikely at this point!)

https://github.com/ldenoue/cameraextension/blob/e1e97557d31cca8d3132676859bca84724b20d98/cameraextension/cameraextensionProvider.swift#L219

michaelforrest avatar Oct 09 '23 16:10 michaelforrest

This line is probably a better choice to anchor this issue :) https://github.com/ldenoue/cameraextension/blob/e1e97557d31cca8d3132676859bca84724b20d98/cameraextension/cameraextensionProvider.swift#L228

michaelforrest avatar Oct 09 '23 16:10 michaelforrest

Hi @michaelforrest, Have you got this high CPU usage issue fixed yet? Would you mind sharing your solution? Thanks.

JulianLian avatar Sep 05 '24 23:09 JulianLian

I think it's okay as it returns early if there's no buffer. Mine still basically looks like this.

michaelforrest avatar Sep 10 '24 11:09 michaelforrest

so what's your approach? did you publish it somewhere? Are you polling instead then? I followed a pattern I had found somewhere, but rewrote in Swift, as I can recollect.

ldenoue avatar Sep 10 '24 17:09 ldenoue