I am currently developing face detection with with a camera library & mlkit.
Camera library provides a FrameProcessor in which I am getting Frame in a stream manner. I have written FrameProcessingTask inside a suspend function.
Inside cameralib FrameProcessor is called inside a ThreadPoolExecutor
mFrameProcessingExecutor.execute(new Runnable() {
@Override
public void run() {
for (FrameProcessor processor : mFrameProcessors) {
try {
processor.process(frame);
} catch (Exception e) {
LOG.w("Frame processor crashed:", e);
}
}
frame.release();
}
});
In my side I have written :
private val processor = FrameProcessor { frame ->
runBlocking { // used runBlocking to bridge suspend coroutine
frameProcessingTask(frame)
}
}
suspend fun frameProcessingTask(frame: Frame) = withContext(Dispatchers.Default)
//face detection & processing code written here.
}
My question :
- is it right to use
runBlockinginsideExecutoras it's called continuously in each frame. - what happened to suspend
runBlockingpart ifExecutorcanceled the task - what happened if
processor.process(frame);called again beforeframeProcessingTaskfinished it's task.