Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Camera.release() takes 30 seconds to release the camera in Nexus 10. Is there any way to speed up the process?

I'm using the following code to release camera in onPause. But the line mCamera.release() takes 30 seconds on average to release the camera in Nexus 10 device. I've added logging before and after mCamera.release() and found that the time difference between printing these logs is 30 seconds.

private void releaseCamera() {
    if (mCamera != null) {
        previewing = false;
        mCamera.setPreviewCallback(null);
        if(mPreview != null)
        mPreview.getHolder().removeCallback(mPreview);
        Log.e("QR","Starting to call mCamera.release()");
        mCamera.release();
        Log.e("QR","Released Camera");
        mCamera = null;
    }
}

I'm calling mCamera.stopPreview() before calling releaseCamera()

Is there any way by which I can do it asynchrounously? Because it takes just less than a minute to go from the Camerapreview activity to the next activity.

Edit1: We reduced the preview size from the highest(1080x1920) to a middle range (480x800) and everything started working fine. Is the preview size has anything to do with the camera release in HAL?

like image 381
Dilip Avatar asked Jan 24 '14 04:01

Dilip


1 Answers

You can try to release the camera inside a Thread as a workaround for this, though this is not an ideal solution. You can launch your next activity while the release function executes in background

   new AsyncTask() {

        @Override
        protected Object doInBackground(Object... params) {
            releaseCamera();
            return null;
        };
    }.execute();
like image 150
SubinM Avatar answered Nov 14 '22 18:11

SubinM