I'm writing an Android app that obtains continuous updates from the camera and processes them whenever onPreviewFrame(byte[] data, Camera camera) is called.
The problem is that onPreviewFrame is only getting called around 8-10 times per second, as opposed to 30 times (which I expected for a 30 FPS camera). I think it's because my UI is receiving all of the camera callbacks as opposed to a separate thread.
Here is my SurfaceView that holds the camera and receives camera callbacks:
public class CameraPreview extends SurfaceView implements SurfaceHolder.Callback, Callback {
private Camera mCamera;
...
mCamera.setPreviewCallback(new Camera.PreviewCallback() {
@Override
public void onPreviewFrame(byte[] data, Camera camera) {
//Frame received (about 8 per second)
And here is the code where I open the camera (in my main activity):
final Camera camera = getCameraInstance(); //calls camera.open()
mPreview = new CameraPreview(this, camera);
How should I go about using a thread, Asynctask, or Handler to make the camera callbacks happen on the side? And how would I receive these updates in the UI thread?