ldenoue / cameraextension

sample camera extension using coremedia io
MIT License
63 stars 11 forks source link

I think this causes high CPU usage #2

Open michaelforrest opened 1 year ago

michaelforrest commented 1 year ago

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 commented 1 year ago

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

JulianLian commented 1 month ago

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

michaelforrest commented 1 month ago

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

ldenoue commented 1 month ago

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.