0

I have an Android application that uses a surfaceview to display a camera preview.

However, the image is shaky, and this warning appears in logcat:

Skipped 61 frames!  The application may be doing too much work on its main thread

I'd be happy to share my code here, but the code is made up of three classes, a CameraActivity, a CameraPreview class (extends SurfaceView), and another custom view that sits on top of the CameraPreview.

This seems like a lot of code to just plop in a stackoverflow question, and since I have no idea what to look for in terms of a cause of this, I'm not sure how to even narrow it down.

I'd be happy to edit the question with relevant code snippets if that would help, or if anyone has any ideas of why this might be happening, I am all ears.

johncorser
  • 9,262
  • 17
  • 57
  • 102
  • Search the method 'onPreviewFrame', and post the code inside. It is where you can receive frame data from main thread. – yushulx Mar 11 '15 at 06:27
  • Are you sending the preview directly to the SurfaceView, or are you capturing the preview and then rendering it on the SurfaceView yourself? – fadden Mar 11 '15 at 15:58
  • I am sending the preview directly to the SurfaceView, this way I can see what I am about to capture before I capture it – johncorser Mar 11 '15 at 15:59

1 Answers1

2

If the Skipped XX frames warning appears again and again, you probably do too much on the main thread. To keep the app responsive, the rule number 1 is to shift all processing off the main thread. The best approach is to use a secondary HandlerThread for all camera-related work.

If the in your app uses preview callback, make sure that you use setPreviewCallbackWithBuffer(), otherwise the garbage collector may bring even a powerful device to crawl. If your onPreviewFrame() method may take a while, consider using a ThreadPool executor to actually process your frames.

Community
  • 1
  • 1
Alex Cohn
  • 56,089
  • 9
  • 113
  • 307