android / android/camera-samples

Camera2Video black preview depending on video resolution

未关闭
#331 1 条评论 2 个 reaction 已指派 1 人 已被 @owahltinez 认领 在 GitHub 查看
主要语言
Kotlin
星标
5.5k
派生
2.4k
PR 合并指标
30 天内没有已合并 PR

描述

I'm having this problem with Huawei phones (P40, P40 pro, Mate 30 Pro). If I choose 1280x720 or 640x480 it will show a black preview and it will throw this exception:

`2020-11-11 11:51:42.551 24901-5788/com.android.example.camera2.video E/CameraFragment: Camera 1 error: (4) Fatal (device)
java.lang.RuntimeException: Camera 1 error: (4) Fatal (device)
at com.example.android.camera2.video.fragments.CameraFragment$openCamera$$inlined$suspendCancellableCoroutine$lambda$1.onError(CameraFragment.kt:351)
at android.hardware.camera2.impl.CameraDeviceImpl$CameraDeviceCallbacks.notifyError(CameraDeviceImpl.java:2022)
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 android.os.Handler.handleCallback(Handler.java:900)
at android.os.Handler.dispatchMessage(Handler.java:103)
at android.os.Looper.loop(Looper.java:219)
at android.os.HandlerThread.run(HandlerThread.java:67)
2020-11-11 11:51:43.792 24901-5788/com.android.example.camera2.video 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:2534)
at android.hardware.camera2.impl.CameraDeviceImpl.stopRepeating(CameraDeviceImpl.java:1131)
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:242)
at android.os.Handler.handleCallback(Handler.java:900)
at android.os.Handler.dispatchMessage(Handler.java:103)
at android.os.Looper.loop(Looper.java:219)
at android.os.HandlerThread.run(HandlerThread.java:67)`

I found that the problem is in the creation of `recorderSurface`, when it execute `createRecorder` and it set `setVideoSize` with the chosen resolutions it will throw the exception and shows a black preview. If I set `setVideoSize` with 1920x1080 resolution in the creation of `recourderSurface` and the chosen resolution in `recorder` it will be just fine but I don't know if it will crash in other devices different than huawei brand...I've tried in a xiaomi mi 9 se and it works fine.

贡献指南

打开贡献指南

评估

这个 Issue 还没有评估数据。

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。