-
[안드로이드 kotlin] The camera device has encountered a serious error안드로이드(kotlin)/에러 관련 2022. 4. 20. 14:20
<에러 로그>
D/Camera2CameraImpl: CameraDevice.onError(): 0 failed with ERROR_CAMERA_DISABLED while in OPENED state. Will attempt recovering from error.
E/Camera2CameraImpl: Error observed on open (or opening) camera device 0: ERROR_CAMERA_DISABLED closing camera.
D/Camera2CameraImpl: {Camera@5184eed[id=0]} Transitioning camera internal state: OPENED --> CLOSING
D/CameraStateRegistry: Recalculating open cameras:
Camera State
-------------------------------------------------------------------
Camera@5184eed[id=0] CLOSING
Camera@a518e88[id=2] UNKNOWN
Camera@cb50d6e[id=1] UNKNOWN
-------------------------------------------------------------------
Open count: 1 (Max allowed: 1)
D/Camera2CameraImpl: {Camera@5184eed[id=0]} Resetting Capture Session
D/StreamStateObserver: Update Preview stream state to IDLE
E/CameraCaptureSession: Session 0: Exception while stopping repeating:
android.hardware.camera2.CameraAccessException: CAMERA_ERROR (3): The camera device has encountered a serious error
at android.hardware.camera2.impl.CameraDeviceImpl.checkIfCameraClosedOrInError(CameraDeviceImpl.java:2553)
at android.hardware.camera2.impl.CameraDeviceImpl.stopRepeating(CameraDeviceImpl.java:1141)
at android.hardware.camera2.impl.CameraCaptureSessionImpl.close(CameraCaptureSessionImpl.java:526)
at androidx.camera.camera2.internal.SynchronizedCaptureSessionBaseImpl.close(SynchronizedCaptureSessionBaseImpl.java:435)
at androidx.camera.camera2.internal.CaptureSession.release(CaptureSession.java:438)
at androidx.camera.camera2.internal.Camera2CameraImpl.releaseSession(Camera2CameraImpl.java:483)
at androidx.camera.camera2.internal.Camera2CameraImpl.resetCaptureSession(Camera2CameraImpl.java:1098)
at androidx.camera.camera2.internal.Camera2CameraImpl.closeCamera(Camera2CameraImpl.java:397)
at androidx.camera.camera2.internal.Camera2CameraImpl$StateCallback.handleErrorOnOpen(Camera2CameraImpl.java:1482)
at androidx.camera.camera2.internal.Camera2CameraImpl$StateCallback.onError(Camera2CameraImpl.java:1446)
at androidx.camera.camera2.internal.CameraDeviceStateCallbacks$ComboDeviceStateCallback.onError(CameraDeviceStateCallbacks.java:119)
at android.hardware.camera2.impl.CameraDeviceImpl$CameraDeviceCallbacks.notifyError(CameraDeviceImpl.java:2042)
at android.hardware.camera2.impl.CameraDeviceImpl$CameraDeviceCallbacks.lambda$Sm85frAzwGZVMAK-NE_gwckYXVQ(Unknown Source:0)
at android.hardware.camera2.impl.-$$Lambda$CameraDeviceImpl$CameraDeviceCallbacks$Sm85frAzwGZVMAK-NE_gwckYXVQ.accept(Unknown Source:8)
at com.android.internal.util.function.pooled.PooledLambdaImpl.doInvoke(PooledLambdaImpl.java:271)
at com.android.internal.util.function.pooled.PooledLambdaImpl.invoke(PooledLambdaImpl.java:195)
at com.android.internal.util.function.pooled.OmniFunction.run(OmniFunction.java:86)
at androidx.camera.core.impl.utils.executor.SequentialExecutor$1.run(SequentialExecutor.java:109)
at androidx.camera.core.impl.utils.executor.SequentialExecutor$QueueWorker.workOnQueue(SequentialExecutor.java:229)
at androidx.camera.core.impl.utils.executor.SequentialExecutor$QueueWorker.run(SequentialExecutor.java:171)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1167)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:641)
at java.lang.Thread.run(Thread.java:919)
D/Camera2CameraImpl: {Camera@5184eed[id=0]} Releasing session in state CLOSING
D/CaptureSession: CameraCaptureSession.onClosed()
D/DeferrableSurface: use count-1, useCount=0 closed=false androidx.camera.core.impl.ImmediateSurface@5c075a6
D/DeferrableSurface: Surface no longer in use[total_surfaces=2, used_surfaces=1](androidx.camera.core.impl.ImmediateSurface@5c075a6}
D/DeferrableSurface: use count-1, useCount=0 closed=true androidx.camera.core.SurfaceRequest$2@a11aa0b
D/DeferrableSurface: Surface no longer in use[total_surfaces=2, used_surfaces=0](androidx.camera.core.SurfaceRequest$2@a11aa0b}
D/DeferrableSurface: Surface terminated[total_surfaces=1, used_surfaces=0](androidx.camera.core.SurfaceRequest$2@a11aa0b}카메라 기능이 필요해서 camerax 를 사용하고 custom dialog 를 만들어서 나타나도록 만들었습니다. 사진 촬영은 잘 되지만 사진 촬영 후에 화면을 끄거 시간이 잠시 지나면(약 30초~1분 사이) 위와 같은 에러 로그가 나타났습니다.
물론 자동으로 문제가 있는 내용을 파악해서 open 되어있는 카메라를 자동으로 close 해주는것 같긴 하지만 위 에러에서도 나타나있듯이 serious error 일수도 있으니까 안나타나도록 하는게 좋을것 같습니다.
문제가 나타나게 된 원인은 dialog 가 종료 되어 카메라를 더이상 하용하지 않는데 camera device 가 계속 open 되어있는것 인듯 싶었습니다.
그래서 dialog 를 dismiss 하기 전에 shutdown 해주는 코드를 추가하였습니다.
기본적인 camerax 사용 방법은 android developer sample을 참조하시면 될 것 같습니다.
lateinit var cameraExecutor: ExecutorService val lifeCycleOwner: MyLifecycleOwner ... imageCapture?.takePicture( outputOptions, ContextCompat.getMainExecutor(context), object : ImageCapture.OnImageSavedCallback { override fun onImageSaved(outputFileResults: ImageCapture.OutputFileResults) { ... // 여기에 아래 두 줄을 추가 cameraExecutor.shutdown() lifeCycleOwner.stop() }
(카메라 종료 코드 추가)
camerax 의 전체 코드 중 촬영하는 부분만 표시하였습니다.
저장한 이미지를 callback 받는 지점안에 onImageSaved() method 안에 cameraExecutor.shutdown() 와 lifeCycleOwner.stop() 을 사용하면 에러가 나타나지 않습니다.
'안드로이드(kotlin) > 에러 관련' 카테고리의 다른 글