Wednesday, 30 December 2020

android.hardware.camera2.CameraAccessException: CAMERA_DISCONNECTED (2): cancelRequest:473: Camera device no longer alive

Running my app, I can see the perfect Camera View, now I open the inbuilt Camera app and again switch to my own app (here, I am getting only black screen)

Log

2020-12-26 16:57:45.696 16445-16768/app.video I/CameraManagerGlobal: Camera 0 facing CAMERA_FACING_BACK state now CAMERA_STATE_IDLE for client app.video API Level 2
2020-12-26 16:57:45.883 16445-16768/app.video I/CameraManagerGlobal: Camera 0 facing CAMERA_FACING_BACK state now CAMERA_STATE_CLOSED for client app.video API Level 2
2020-12-26 16:57:45.886 16445-16596/app.video E/CameraCaptureSession: Session 0: Exception while stopping repeating: 
    android.hardware.camera2.CameraAccessException: CAMERA_DISCONNECTED (2): cancelRequest:473: Camera device no longer alive
        at android.hardware.camera2.CameraManager.throwAsPublicException(CameraManager.java:1127)
        at android.hardware.camera2.impl.ICameraDeviceUserWrapper.cancelRequest(ICameraDeviceUserWrapper.java:97)
        at android.hardware.camera2.impl.CameraDeviceImpl.stopRepeating(CameraDeviceImpl.java:1151)
        at android.hardware.camera2.impl.CameraCaptureSessionImpl.close(CameraCaptureSessionImpl.java:526)
        at android.hardware.camera2.impl.CameraCaptureSessionImpl$2.onDisconnected(CameraCaptureSessionImpl.java:737)
        at android.hardware.camera2.impl.CameraDeviceImpl$7.run(CameraDeviceImpl.java:244)
        at android.os.Handler.handleCallback(Handler.java:883)
        at android.os.Handler.dispatchMessage(Handler.java:100)
        at android.os.Looper.loop(Looper.java:237)
        at android.os.HandlerThread.run(HandlerThread.java:67)
     Caused by: android.os.ServiceSpecificException: cancelRequest:473: Camera device no longer alive (code 4)
        at android.os.Parcel.createException(Parcel.java:2102)
        at android.os.Parcel.readException(Parcel.java:2056)
        at android.os.Parcel.readException(Parcel.java:2004)
        at android.hardware.camera2.ICameraDeviceUser$Stub$Proxy.cancelRequest(ICameraDeviceUser.java:676)
        at android.hardware.camera2.impl.ICameraDeviceUserWrapper.cancelRequest(ICameraDeviceUserWrapper.java:95)
        at android.hardware.camera2.impl.CameraDeviceImpl.stopRepeating(CameraDeviceImpl.java:1151) 
        at android.hardware.camera2.impl.CameraCaptureSessionImpl.close(CameraCaptureSessionImpl.java:526) 
        at android.hardware.camera2.impl.CameraCaptureSessionImpl$2.onDisconnected(CameraCaptureSessionImpl.java:737) 
        at android.hardware.camera2.impl.CameraDeviceImpl$7.run(CameraDeviceImpl.java:244) 
        at android.os.Handler.handleCallback(Handler.java:883) 
        at android.os.Handler.dispatchMessage(Handler.java:100) 
        at android.os.Looper.loop(Looper.java:237) 
        at android.os.HandlerThread.run(HandlerThread.java:67) 
2020-12-26 16:57:45.886 16445-16596/app.video I/org.webrtc.Logging: Camera2Session: Stop internal
2020-12-26 16:57:45.887 16445-16596/app.video I/org.webrtc.Logging: SurfaceTextureHelper: stopListening()
2020-12-26 16:57:45.887 16445-16468/app.video W/app.video: Long monitor contention with owner CaptureThread (16596) at boolean android.os.BinderProxy.transactNative(int, android.os.Parcel, android.os.Parcel, int)(BinderProxy.java:-2) waiters=0 in void android.hardware.camera2.impl.CameraDeviceImpl$CameraDeviceCallbacks.onCaptureStarted(android.hardware.camera2.impl.CaptureResultExtras, long) for 381ms
2020-12-26 16:57:45.890 16445-16596/app.video I/org.webrtc.Logging: Camera2Session: Stop done
2020-12-26 16:57:45.890 16445-16596/app.video I/org.webrtc.Logging: CameraCapturer: Stop capture
2020-12-26 16:57:45.890 16445-16596/app.video I/org.webrtc.Logging: CameraCapturer: Stop capture: Nulling session
2020-12-26 16:57:45.891 16445-16596/app.video I/org.webrtc.Logging: CameraCapturer: Stop capture done
2020-12-26 16:57:45.891 16445-16596/app.video I/org.webrtc.Logging: Camera2Session: Camera device closed.
2020-12-26 16:57:45.892 16445-16596/app.video I/org.webrtc.Logging: Camera2Session: Stop camera2 session on camera 0
2020-12-26 16:57:45.892 16445-16768/app.video I/CameraManagerGlobal: Camera 1 facing CAMERA_FACING_FRONT state now CAMERA_STATE_OPEN for client com.sec.android.app.camera API Level 1
2020-12-26 16:57:46.274 16445-16839/app.video I/CameraManagerGlobal: Camera 1 facing CAMERA_FACING_FRONT state now CAMERA_STATE_ACTIVE for client com.sec.android.app.camera API Level 1

XML

<com.src.webrtc.android.VideoView
     android:id="@+id/main_view"
     android:layout_width="wrap_content"
     android:layout_height="wrap_content" />

CODE

override fun onCreate(savedInstanceState: Bundle?) {
    super.onCreate(savedInstanceState)

    viewModel = ViewModelProvider(
        this,
        ViewModelFactory.getInstance(application)
    ).get(MainViewModel::class.java)

    binding = DataBindingUtil.setContentView(this, R.layout.activity_main)
    binding.viewModel = this.viewModel
    binding.lifecycleOwner = this

    binding.apply {
        peerViews.add(mainView)
        peerViews.add(subView1)
        for (i in viewRenderers.indices) {
            viewRenderers[i].setTarget(peerViews[i])
        }
    }

    viewModel.room.observe(this, Observer {
        Log.d(TAG, "observe room $it")
        if (it != null) {
            binding.mainView.apply {
                init(null)
                setScalingType(RendererCommon.ScalingType.SCALE_ASPECT_FIT)
                setEnableHardwareScaler(false)
            }
            initSubView(it, binding.subView1)
        } else {
            binding.mainView.clearImage()
            binding.subView1.clearImage()
            Handler().postDelayed({
                binding.mainView.release()
                binding.subView1.release()
            }, 100)
        }
    })

}


from android.hardware.camera2.CameraAccessException: CAMERA_DISCONNECTED (2): cancelRequest:473: Camera device no longer alive

No comments:

Post a Comment