diff --git a/package/android/src/main/java/com/mrousavy/camera/core/CameraError.kt b/package/android/src/main/java/com/mrousavy/camera/core/CameraError.kt index e7f888b4ab..d11f18fb0b 100644 --- a/package/android/src/main/java/com/mrousavy/camera/core/CameraError.kt +++ b/package/android/src/main/java/com/mrousavy/camera/core/CameraError.kt @@ -49,12 +49,6 @@ class NoCameraDeviceError : ) class PixelFormatNotSupportedError(format: String) : CameraError("device", "pixel-format-not-supported", "The pixelFormat $format is not supported on the given Camera Device!") -class LowLightBoostNotSupportedError : - CameraError( - "device", - "low-light-boost-not-supported", - "The currently selected camera device does not support low-light boost! Select a device where `device.supportsLowLightBoost` is true." - ) class FlashUnavailableError : CameraError( "device", @@ -183,7 +177,6 @@ class NoRecordingInProgressError : class RecordingCanceledError : CameraError("capture", "recording-canceled", "The active recording was canceled.") class FileIOError(throwable: Throwable) : CameraError("capture", "file-io-error", "An unexpected File IO error occurred! Error: ${throwable.message}.", throwable) -class InsufficientStorageError : CameraError("capture", "insufficient-storage", "There is not enough storage space available.") class RecordingInProgressError : CameraError( "capture", diff --git a/package/android/src/main/java/com/mrousavy/camera/core/CameraSession.kt b/package/android/src/main/java/com/mrousavy/camera/core/CameraSession.kt index 34003c4c63..025e26bc4e 100644 --- a/package/android/src/main/java/com/mrousavy/camera/core/CameraSession.kt +++ b/package/android/src/main/java/com/mrousavy/camera/core/CameraSession.kt @@ -195,15 +195,19 @@ class CameraSession(private val context: Context, private val callback: Callback } } - private fun assetFormatRequirement(propName: String, format: CameraDeviceFormat?, requirement: (format: CameraDeviceFormat) -> Boolean) { + private fun assertFormatRequirement( + propName: String, + format: CameraDeviceFormat?, + throwIfNotMet: CameraError, + requirement: (format: CameraDeviceFormat) -> Boolean + ) { if (format == null) { // we need a format for this to work. throw PropRequiresFormatToBeNonNullError(propName) } val isSupported = requirement(format) if (!isSupported) { - // TODO: Throw actual Camera Device error - throw Error("$propName is not supported!") + throw throwIfNotMet } } @@ -225,13 +229,13 @@ class CameraSession(private val context: Context, private val callback: Callback val preview = Preview.Builder().also { preview -> // Configure Preview Output if (configuration.videoStabilizationMode.isAtLeast(VideoStabilizationMode.CINEMATIC)) { - assetFormatRequirement("videoStabilizationMode", format) { + assertFormatRequirement("videoStabilizationMode", format, InvalidVideoStabilizationMode(configuration.videoStabilizationMode)) { it.videoStabilizationModes.contains(configuration.videoStabilizationMode) } preview.setPreviewStabilizationEnabled(true) } if (fpsRange != null) { - assetFormatRequirement("fps", format) { + assertFormatRequirement("fps", format, InvalidFpsError(fpsRange.upper)) { fpsRange.lower >= it.minFps && fpsRange.upper <= it.maxFps } preview.setTargetFrameRate(fpsRange) @@ -287,17 +291,20 @@ class CameraSession(private val context: Context, private val callback: Callback // Configure Video Output video.setMirrorMode(MirrorMode.MIRROR_MODE_ON_FRONT_ONLY) if (configuration.videoStabilizationMode.isAtLeast(VideoStabilizationMode.STANDARD)) { - assetFormatRequirement("videoStabilizationMode", format) { + assertFormatRequirement("videoStabilizationMode", format, InvalidVideoStabilizationMode(configuration.videoStabilizationMode)) { it.videoStabilizationModes.contains(configuration.videoStabilizationMode) } video.setVideoStabilizationEnabled(true) } if (fpsRange != null) { - assetFormatRequirement("fps", format) { fpsRange.lower >= it.minFps && fpsRange.upper <= it.maxFps } + assertFormatRequirement("fps", format, InvalidFpsError(fpsRange.upper)) { + fpsRange.lower >= it.minFps && + fpsRange.upper <= it.maxFps + } video.setTargetFrameRate(fpsRange) } if (videoConfig.config.enableHdr) { - assetFormatRequirement("videoHdr", format) { it.supportsVideoHdr } + assertFormatRequirement("videoHdr", format, InvalidVideoHdrError()) { it.supportsVideoHdr } video.setDynamicRange(DynamicRange.HDR_UNSPECIFIED_10_BIT) } if (format != null) {