Skip to content

Commit

Permalink
fix: app crash when running on device with not cameras and having cam…
Browse files Browse the repository at this point in the history
…era permission

fixes: #264
  • Loading branch information
Albert Koczy committed Oct 7, 2022
1 parent b88d8f2 commit 85ff29b
Showing 1 changed file with 10 additions and 1 deletion.
11 changes: 10 additions & 1 deletion app/app/src/main/java/com/octo4a/camera/CameraService.kt
Original file line number Diff line number Diff line change
Expand Up @@ -209,6 +209,15 @@ class CameraService : LifecycleService(), MJpegFrameProvider {
) {
return
}
// ensure that the cameras are enumerated
cameraEnumerationRepository.enumerateCameras()
// check if the device has any cameras at all
// some TV boxes have no cameras at all, and it causes cameraSelector to throw an exception
if(cameraEnumerationRepository.enumeratedCameras.value?.isEmpty() != false) {
return
}



val cameraProviderFuture = ProcessCameraProvider.getInstance(applicationContext)
val out = ByteArrayOutputStream()
Expand All @@ -234,7 +243,7 @@ class CameraService : LifecycleService(), MJpegFrameProvider {
if (listenerCount > 0 || latestFrame.isEmpty()) {
val isI420 = (image.planes[1].pixelStride == 1)

var nv21: ByteArray = if (isI420) nativeUtils.yuvToNv21Slow(image)!! else nativeUtils.toNv21(image)!!
var nv21: ByteArray = if (isI420) nativeUtils.yuvToNv21Slow(image) else nativeUtils.toNv21(image)!!

var realWidth = image.width
var realHeight = image.height
Expand Down

0 comments on commit 85ff29b

Please sign in to comment.