@@ -3,6 +3,7 @@ package com.mrousavy.camera.core
3
3
import android.annotation.SuppressLint
4
4
import android.graphics.ImageFormat
5
5
import android.hardware.camera2.CameraCharacteristics
6
+ import android.util.Log
6
7
import android.util.Range
7
8
import android.util.Size
8
9
import android.util.SizeF
@@ -36,6 +37,10 @@ import kotlin.math.sqrt
36
37
@SuppressLint(" RestrictedApi" )
37
38
@Suppress(" FoldInitializerAndIfToElvis" )
38
39
class CameraDeviceDetails (private val cameraInfo : CameraInfo , extensionsManager : ExtensionsManager ) {
40
+ companion object {
41
+ private const val TAG = " CameraDeviceDetails"
42
+ }
43
+
39
44
// Generic props available on all implementations
40
45
private val cameraId = cameraInfo.id ? : throw NoCameraDeviceError ()
41
46
private val position = Position .fromLensFacing(cameraInfo.lensFacing)
@@ -113,24 +118,36 @@ class CameraDeviceDetails(private val cameraInfo: CameraInfo, extensionsManager:
113
118
val dynamicRangeProfiles = videoCapabilities.supportedDynamicRanges
114
119
115
120
dynamicRangeProfiles.forEach { dynamicRange ->
116
- val qualities = videoCapabilities.getSupportedQualities(dynamicRange)
117
- val videoSizes = qualities.map { it as ConstantQuality }.flatMap { it.typicalSizes }
118
- val photoSizes = cameraInfoInternal.getSupportedResolutions(ImageFormat .JPEG )
119
- val fpsRanges = cameraInfo.supportedFrameRateRanges
120
- val minFps = fpsRanges.minOf { it.lower }
121
- val maxFps = fpsRanges.maxOf { it.upper }
122
-
123
- videoSizes.forEach { videoSize ->
124
- // not every size supports the maximum FPS range
125
- val maxFpsForSize = CamcorderProfileUtils .getMaximumFps(cameraId, videoSize) ? : maxFps
126
- // if the FPS range for this size is even smaller than min FPS, we need to clamp that as well.
127
- val minFpsForSize = min(minFps, maxFpsForSize)
128
- val fpsRange = Range (minFpsForSize, maxFpsForSize)
129
-
130
- photoSizes.forEach { photoSize ->
131
- val map = buildFormatMap(photoSize, videoSize, fpsRange)
132
- array.pushMap(map)
121
+ try {
122
+ val qualities = videoCapabilities.getSupportedQualities(dynamicRange)
123
+ val videoSizes = qualities.map { it as ConstantQuality }.flatMap { it.typicalSizes }
124
+ val photoSizes = cameraInfoInternal.getSupportedResolutions(ImageFormat .JPEG )
125
+ val fpsRanges = cameraInfo.supportedFrameRateRanges
126
+ val minFps = fpsRanges.minOf { it.lower }
127
+ val maxFps = fpsRanges.maxOf { it.upper }
128
+
129
+ videoSizes.forEach { videoSize ->
130
+ try {
131
+ // not every size supports the maximum FPS range
132
+ val maxFpsForSize = CamcorderProfileUtils .getMaximumFps(cameraId, videoSize) ? : maxFps
133
+ // if the FPS range for this size is even smaller than min FPS, we need to clamp that as well.
134
+ val minFpsForSize = min(minFps, maxFpsForSize)
135
+ val fpsRange = Range (minFpsForSize, maxFpsForSize)
136
+
137
+ photoSizes.forEach { photoSize ->
138
+ try {
139
+ val map = buildFormatMap(photoSize, videoSize, fpsRange)
140
+ array.pushMap(map)
141
+ } catch (error: Throwable ) {
142
+ Log .w(TAG , " Photo size ${photoSize.width} x${photoSize.height} cannot be used as a format!" , error)
143
+ }
144
+ }
145
+ } catch (error: Throwable ) {
146
+ Log .w(TAG , " Video size ${videoSize.width} x${videoSize.height} cannot be used as a format!" , error)
147
+ }
133
148
}
149
+ } catch (error: Throwable ) {
150
+ Log .w(TAG , " Dynamic Range Profile $dynamicRange cannot be used as a format!" , error)
134
151
}
135
152
}
136
153
0 commit comments