Dilip
Dilip

Reputation: 1162

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?

Upvotes: 12

Views: 1321

Answers (3)

Sergey Maslenyuk
Sergey Maslenyuk

Reputation: 103

I don't have needed level of reputation to add a comment so I'll put it here:

new Thread(new Runnable(){
public void run(){
    camera.stopPreview();
camera.setPreviewCallback(null);
camera.unlock();
camera.release();
camera = null;
}

}).start();

When the release call will be run in separate thread it will cause a problem to other application that uses camera and will be launched on top of that. I'm also looking for the solution. I don't have Nexus10. We have own device.

Upvotes: 0

user3278897
user3278897

Reputation: 1004

Dilip, it is know issue in the Nexus 10, Check this Nexus 10 camera.release hangs for 30 seconds.

We tried with these things,

camera.stopPreview();
camera.setPreviewCallback(null);
camera.unlock();
camera.release();
camera = null;

It is working for me, but i have to test this same code on other devices too (it is good put the above code in try/catch statements ).

Also, you can add this functionality in thread:

new Thread(new Runnable(){
    public void run(){
        camera.stopPreview();
    camera.setPreviewCallback(null);
    camera.unlock();
    camera.release();
    camera = null;
    }
}).start();

Try to create camera management code with Camera2 API, hopefully this will not cause problem, check this http://blog.csdn.net/torvalbill/article/details/40376145

Upvotes: 1

SubinM
SubinM

Reputation: 384

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();

Upvotes: 5

Related Questions