I’ve been searching Google and StackOverflow exhaustively and cannot find this. Maybe I’m missing something obvious. Thanks!
(This is because the Java implementation of the preview callback [even with buffer] is too inefficient.)
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
I made a little investigation on topic. This presentation (from p.277, Chinese) helped a lot.
Camera preview call chain
As others mentioned, you can get a buffer using a
Camera.setPreviewCallbackmethod.Here’s how it happens there (a verbose version):
Camera.startPreview()which is a native function.android_hardware_Camera_startPreviewcallsstartPreviewmethod of C++Cameraclass.Cameracalls astartPreviewmethod ofICamerainterfaceICameramakes anIPCcall to remote client.setCameraModemethod ofCameraServiceclass.CameraServicesets a window to display a preview and calls astartPreviewmethod ofCameraHardwareInterfaceclass.start_previewmethod on particularcamera_device_tdevice.I didn’t looked up further but it should perform a call to the driver.
dataCallbackofCameraServiceis invoked.handlePreviewDatamethod of client.ICameraClient.ICameraClientsends it overIPCto theCamera.Cameracalls a registered listener and passes buffer toJNI.Camera.addCallbackBufferthen it copies to the buffer first.Camerahandles the message and invokes aonPreviewFramemethod ofCamera.PreviewCallback.As you can see 2
IPCcalls were invoked and buffer was copied at least twice on steps 10, 11. First instance of raw buffer which is returned bycamera_device_tis hosted in another process and you cannot access it due to security checks inCameraService.Preview surface
However, when you set a preview surface using either
Camera.setPreviewTextureorCamera.setPreviewDisplayit is be passed directly to the camera device and refreshed in realtime without participation of all the chain above. As it’s documentation says:Java class
Surfacehas a method to retrieve it’s contents:But this API is hidden. See i.e. this question for a way to use it.