From f92a4ca9f22e3bbc497768c2683d44c8ca3f53f0 Mon Sep 17 00:00:00 2001 From: Jay Wang Date: Tue, 21 Jun 2016 12:34:16 -0700 Subject: SnapdragonCamera: Reorder logic when closing cameras Re-order calls to unlink all cameras and close sessions before closing any devices. CRs-Fixed: 993611 Change-Id: I0e753a5286799ff59637333cc00231c96709a3e7 --- src/com/android/camera/CaptureModule.java | 64 ++++++++++++++++--------------- 1 file changed, 34 insertions(+), 30 deletions(-) diff --git a/src/com/android/camera/CaptureModule.java b/src/com/android/camera/CaptureModule.java index ba576306c..5178d49d2 100644 --- a/src/com/android/camera/CaptureModule.java +++ b/src/com/android/camera/CaptureModule.java @@ -1185,46 +1185,50 @@ public class CaptureModule implements CameraModule, PhotoController, */ private void closeCamera() { Log.d(TAG, "closeCamera"); - try { - mCameraOpenCloseLock.acquire(); - if(mPostProcessor != null) { - mPostProcessor.onClose(); - } - if(mFrameProcessor != null) { - mFrameProcessor.onClose(); - } - for (int i = 0; i < MAX_NUM_CAM; i++) { - if (null != mCaptureSession[i]) { - if (mIsLinked) { - unLinkBayerMono(i); - try { - mCaptureSession[i].capture(mPreviewRequestBuilder[i].build(), null, - mCameraHandler); - } catch (CameraAccessException e) { - e.printStackTrace(); - } + if(mPostProcessor != null) { + mPostProcessor.onClose(); + } + + if(mFrameProcessor != null) { + mFrameProcessor.onClose(); + } + + for (int i = 0; i < MAX_NUM_CAM; i++) { + if (null != mCaptureSession[i]) { + if (mIsLinked) { + unLinkBayerMono(i); + try { + mCaptureSession[i].capture(mPreviewRequestBuilder[i].build(), null, + mCameraHandler); + } catch (CameraAccessException e) { + e.printStackTrace(); } - mCaptureSession[i].close(); - mCaptureSession[i] = null; } + mCaptureSession[i].close(); + mCaptureSession[i] = null; + } - if (null != mImageReader[i]) { - mImageReader[i].close(); - mImageReader[i] = null; - } + if (null != mImageReader[i]) { + mImageReader[i].close(); + mImageReader[i] = null; + } + } + /* no need to set this in the callback and handle asynchronously. This is the same + reason as why we release the semaphore here, not in camera close callback function + as we don't have to protect the case where camera open() gets called during camera + close(). The low level framework/HAL handles the synchronization for open() + happens after close() */ + mIsLinked = false; + try { + mCameraOpenCloseLock.acquire(); + for (int i = 0; i < MAX_NUM_CAM; i++) { if (null != mCameraDevice[i]) { mCameraDevice[i].close(); mCameraDevice[i] = null; mCameraOpened[i] = false; } } - /* no need to set this in the callback and handle asynchronously. This is the same - reason as why we release the semaphore here, not in camera close callback function - as we don't have to protect the case where camera open() gets called during camera - close(). The low level framework/HAL handles the synchronization for open() - happens after close() */ - mIsLinked = false; } catch (InterruptedException e) { mCameraOpenCloseLock.release(); throw new RuntimeException("Interrupted while trying to lock camera closing.", e); -- cgit v1.2.3