I am using <MLKit> to do extract text from the cam...
# ios
p
I am using MLKit to do extract text from the camera and I ran into this issue https://stackoverflow.com/questions/79103337/ios-camera-freezes-and-crashes-with-mlkit-barcode-scanning-in-kotlin-multiplatfo which causes the
AVCaptureVideoDataOutputSampleBufferDelegate
to hang (its methods are no longer called). This issue I was able to fix by calling GC.collect(). Now I face the next problem: I'm doing a database lookup with the extracted text which sometimes works and sometimes causes the same issue (delegate hangs). I get no logs (other than that the database lookup suceeded etc.). Presumably the thread/queue or delegate died again. How can I gain insight into what happens when it hangs?
I tried running "time profiler" from xcode, but I'm not familiar with its output or how to convert it to something readable. I also tried running my code inside a separate concurrent dispatch queue or running it in in Globalscope.launch() or on the ui thread neither of which improved things.
so in the end I was able to solve my issue by using a rendezvous channel that `trySend`s the extracted text. A dedicated worker (scoped to the relevant UI) `receive`s the text and does further processing (database lookup and such). That way we always handle the callback in
AVCaptureVideoDataOutputSampleBufferDelegate
immediately and drop the current frame if the last one is still processing.