2021-02-19 08:28:05 -07:00
|
|
|
//
|
|
|
|
// CameraError.swift
|
2021-06-21 14:42:46 -06:00
|
|
|
// mrousavy
|
2021-02-19 08:28:05 -07:00
|
|
|
//
|
|
|
|
// Created by Marc Rousavy on 14.01.21.
|
2021-06-01 05:07:57 -06:00
|
|
|
// Copyright © 2021 mrousavy. All rights reserved.
|
2021-02-19 08:28:05 -07:00
|
|
|
//
|
|
|
|
|
|
|
|
import Foundation
|
|
|
|
|
2021-03-09 02:53:29 -07:00
|
|
|
// MARK: - PermissionError
|
|
|
|
|
2021-02-19 08:28:05 -07:00
|
|
|
enum PermissionError: String {
|
|
|
|
case microphone = "microphone-permission-denied"
|
|
|
|
case camera = "camera-permission-denied"
|
|
|
|
|
|
|
|
var code: String {
|
|
|
|
return rawValue
|
|
|
|
}
|
|
|
|
|
|
|
|
var message: String {
|
|
|
|
switch self {
|
|
|
|
case .microphone:
|
2021-06-07 05:08:40 -06:00
|
|
|
return "The Microphone permission was denied! If you want to record Videos without sound, pass `audio={false}`."
|
2021-02-19 08:28:05 -07:00
|
|
|
case .camera:
|
|
|
|
return "The Camera permission was denied!"
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-03-09 02:53:29 -07:00
|
|
|
// MARK: - ParameterError
|
|
|
|
|
2021-02-19 08:28:05 -07:00
|
|
|
enum ParameterError {
|
|
|
|
case invalid(unionName: String, receivedValue: String)
|
|
|
|
case unsupportedOutput(outputDescriptor: String)
|
|
|
|
case unsupportedInput(inputDescriptor: String)
|
|
|
|
case invalidCombination(provided: String, missing: String)
|
|
|
|
|
|
|
|
var code: String {
|
|
|
|
switch self {
|
|
|
|
case .invalid:
|
|
|
|
return "invalid-parameter"
|
|
|
|
case .unsupportedOutput:
|
|
|
|
return "unsupported-output"
|
|
|
|
case .unsupportedInput:
|
|
|
|
return "unsupported-input"
|
|
|
|
case .invalidCombination:
|
|
|
|
return "invalid-combination"
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
var message: String {
|
|
|
|
switch self {
|
|
|
|
case let .invalid(unionName: unionName, receivedValue: receivedValue):
|
|
|
|
return "The value \"\(receivedValue)\" could not be parsed to type \(unionName)!"
|
|
|
|
case let .unsupportedOutput(outputDescriptor: output):
|
|
|
|
return "The output \"\(output)\" is not supported!"
|
|
|
|
case let .unsupportedInput(inputDescriptor: input):
|
|
|
|
return "The input \"\(input)\" is not supported!"
|
|
|
|
case let .invalidCombination(provided: provided, missing: missing):
|
|
|
|
return "Invalid combination! If \"\(provided)\" is provided, \"\(missing)\" also has to be set!"
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-03-09 02:53:29 -07:00
|
|
|
// MARK: - DeviceError
|
|
|
|
|
2021-02-19 08:28:05 -07:00
|
|
|
enum DeviceError: String {
|
|
|
|
case configureError = "configuration-error"
|
|
|
|
case noDevice = "no-device"
|
|
|
|
case invalid = "invalid-device"
|
2023-08-21 04:50:14 -06:00
|
|
|
case flashUnavailable = "flash-unavailable"
|
2021-02-19 08:28:05 -07:00
|
|
|
case microphoneUnavailable = "microphone-unavailable"
|
|
|
|
case lowLightBoostNotSupported = "low-light-boost-not-supported"
|
|
|
|
case focusNotSupported = "focus-not-supported"
|
|
|
|
case notAvailableOnSimulator = "camera-not-available-on-simulator"
|
2023-09-01 07:07:16 -06:00
|
|
|
case pixelFormatNotSupported = "pixel-format-not-supported"
|
2021-02-19 08:28:05 -07:00
|
|
|
|
|
|
|
var code: String {
|
|
|
|
return rawValue
|
|
|
|
}
|
|
|
|
|
|
|
|
var message: String {
|
|
|
|
switch self {
|
|
|
|
case .configureError:
|
|
|
|
return "Failed to lock the device for configuration."
|
|
|
|
case .noDevice:
|
2023-09-25 04:57:03 -06:00
|
|
|
return "No device was set! Use `useCameraDevice(..)` or `Camera.getAvailableCameraDevices()` to select a suitable Camera device."
|
2021-02-19 08:28:05 -07:00
|
|
|
case .invalid:
|
2023-09-25 04:57:03 -06:00
|
|
|
return "The given Camera device was invalid. Use `useCameraDevice(..)` or `Camera.getAvailableCameraDevices()` to select a suitable Camera device."
|
2023-08-21 04:50:14 -06:00
|
|
|
case .flashUnavailable:
|
2024-01-08 04:13:05 -07:00
|
|
|
return "The Camera Device does not have a flash unit! Select a device where `device.hasFlash`/`device.hasTorch` is true."
|
2021-02-19 08:28:05 -07:00
|
|
|
case .lowLightBoostNotSupported:
|
2024-01-08 04:13:05 -07:00
|
|
|
return "The currently selected camera device does not support low-light boost! Select a device where `device.supportsLowLightBoost` is true."
|
2021-02-19 08:28:05 -07:00
|
|
|
case .focusNotSupported:
|
2024-02-08 07:16:58 -07:00
|
|
|
return "The currently selected camera device does not support focusing!"
|
2021-02-19 08:28:05 -07:00
|
|
|
case .microphoneUnavailable:
|
|
|
|
return "The microphone was unavailable."
|
|
|
|
case .notAvailableOnSimulator:
|
|
|
|
return "The Camera is not available on the iOS Simulator!"
|
2023-09-01 07:07:16 -06:00
|
|
|
case .pixelFormatNotSupported:
|
|
|
|
return "The given pixelFormat is not supported on the given Camera Device!"
|
2021-02-19 08:28:05 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-03-09 02:53:29 -07:00
|
|
|
// MARK: - FormatError
|
|
|
|
|
2021-02-19 08:28:05 -07:00
|
|
|
enum FormatError {
|
|
|
|
case invalidFps(fps: Int)
|
2023-11-15 10:33:12 -07:00
|
|
|
case invalidVideoHdr
|
2021-02-19 08:28:05 -07:00
|
|
|
case invalidFormat
|
2023-09-21 08:30:05 -06:00
|
|
|
case incompatiblePixelFormatWithHDR
|
2021-02-19 08:28:05 -07:00
|
|
|
|
|
|
|
var code: String {
|
|
|
|
switch self {
|
|
|
|
case .invalidFormat:
|
|
|
|
return "invalid-format"
|
|
|
|
case .invalidFps:
|
|
|
|
return "invalid-fps"
|
2023-11-15 10:33:12 -07:00
|
|
|
case .invalidVideoHdr:
|
|
|
|
return "invalid-video-hdr"
|
2023-09-21 08:30:05 -06:00
|
|
|
case .incompatiblePixelFormatWithHDR:
|
|
|
|
return "incompatible-pixel-format-with-hdr-setting"
|
2021-02-19 08:28:05 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
var message: String {
|
|
|
|
switch self {
|
|
|
|
case .invalidFormat:
|
2023-09-25 04:57:03 -06:00
|
|
|
return "The given format was invalid. Did you check if the current device supports the given format in `device.formats`?"
|
2021-02-19 08:28:05 -07:00
|
|
|
case let .invalidFps(fps):
|
2023-08-21 04:50:14 -06:00
|
|
|
return "The given format cannot run at \(fps) FPS! Make sure your FPS is lower than `format.maxFps` but higher than `format.minFps`."
|
2023-11-15 10:33:12 -07:00
|
|
|
case .invalidVideoHdr:
|
|
|
|
return "The currently selected format does not support 10-bit Video HDR streaming! Make sure you select a format which includes `supportsVideoHdr`!"
|
2023-09-21 08:30:05 -06:00
|
|
|
case .incompatiblePixelFormatWithHDR:
|
|
|
|
return "The currently selected pixelFormat is not compatible with HDR! HDR only works with the `yuv` pixelFormat."
|
2021-02-19 08:28:05 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-03-09 02:53:29 -07:00
|
|
|
// MARK: - SessionError
|
|
|
|
|
2021-02-23 02:27:31 -07:00
|
|
|
enum SessionError {
|
|
|
|
case cameraNotReady
|
2021-06-03 06:16:02 -06:00
|
|
|
case audioSessionFailedToActivate
|
2021-03-29 03:32:00 -06:00
|
|
|
case audioInUseByOtherApp
|
2021-02-19 08:28:05 -07:00
|
|
|
|
|
|
|
var code: String {
|
2021-02-23 02:27:31 -07:00
|
|
|
switch self {
|
|
|
|
case .cameraNotReady:
|
|
|
|
return "camera-not-ready"
|
2021-03-29 03:32:00 -06:00
|
|
|
case .audioInUseByOtherApp:
|
|
|
|
return "audio-in-use-by-other-app"
|
2021-06-03 06:16:02 -06:00
|
|
|
case .audioSessionFailedToActivate:
|
|
|
|
return "audio-session-failed-to-activate"
|
2021-02-23 02:27:31 -07:00
|
|
|
}
|
2021-02-19 08:28:05 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
var message: String {
|
|
|
|
switch self {
|
|
|
|
case .cameraNotReady:
|
|
|
|
return "The Camera is not ready yet! Wait for the onInitialized() callback!"
|
2021-03-29 03:32:00 -06:00
|
|
|
case .audioInUseByOtherApp:
|
|
|
|
return "The audio session is already in use by another app with higher priority!"
|
2021-06-03 06:16:02 -06:00
|
|
|
case .audioSessionFailedToActivate:
|
|
|
|
return "Failed to activate Audio Session!"
|
2021-02-19 08:28:05 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-03-09 02:53:29 -07:00
|
|
|
// MARK: - CaptureError
|
|
|
|
|
2021-02-19 08:28:05 -07:00
|
|
|
enum CaptureError {
|
|
|
|
case recordingInProgress
|
|
|
|
case noRecordingInProgress
|
|
|
|
case fileError
|
2023-10-13 10:33:20 -06:00
|
|
|
case createTempFileError(message: String? = nil)
|
2024-07-16 02:50:21 -06:00
|
|
|
case createRecordingDirectoryError(message: String? = nil)
|
2021-05-06 06:11:55 -06:00
|
|
|
case createRecorderError(message: String? = nil)
|
2021-06-07 05:08:40 -06:00
|
|
|
case videoNotEnabled
|
|
|
|
case photoNotEnabled
|
2021-06-09 06:56:56 -06:00
|
|
|
case aborted
|
2024-01-24 03:48:38 -07:00
|
|
|
case insufficientStorage
|
2021-02-19 08:28:05 -07:00
|
|
|
case unknown(message: String? = nil)
|
|
|
|
|
|
|
|
var code: String {
|
|
|
|
switch self {
|
|
|
|
case .recordingInProgress:
|
|
|
|
return "recording-in-progress"
|
|
|
|
case .noRecordingInProgress:
|
|
|
|
return "no-recording-in-progress"
|
|
|
|
case .fileError:
|
|
|
|
return "file-io-error"
|
|
|
|
case .createTempFileError:
|
|
|
|
return "create-temp-file-error"
|
2024-07-16 02:50:21 -06:00
|
|
|
case .createRecordingDirectoryError:
|
|
|
|
return "create-recording-directory-error"
|
2021-05-06 06:11:55 -06:00
|
|
|
case .createRecorderError:
|
|
|
|
return "create-recorder-error"
|
2021-06-07 05:08:40 -06:00
|
|
|
case .videoNotEnabled:
|
|
|
|
return "video-not-enabled"
|
|
|
|
case .photoNotEnabled:
|
|
|
|
return "photo-not-enabled"
|
2024-01-24 03:48:38 -07:00
|
|
|
case .insufficientStorage:
|
|
|
|
return "insufficient-storage"
|
2021-06-09 06:56:56 -06:00
|
|
|
case .aborted:
|
|
|
|
return "aborted"
|
2021-02-19 08:28:05 -07:00
|
|
|
case .unknown:
|
|
|
|
return "unknown"
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
var message: String {
|
|
|
|
switch self {
|
|
|
|
case .recordingInProgress:
|
|
|
|
return "There is already an active video recording in progress! Did you call startRecording() twice?"
|
|
|
|
case .noRecordingInProgress:
|
|
|
|
return "There was no active video recording in progress! Did you call stopRecording() twice?"
|
|
|
|
case .fileError:
|
|
|
|
return "An unexpected File IO error occured!"
|
2023-10-13 10:33:20 -06:00
|
|
|
case let .createTempFileError(message: message):
|
|
|
|
return "Failed to create a temporary file! \(message ?? "(no additional message)")"
|
2024-07-16 02:50:21 -06:00
|
|
|
case let .createRecordingDirectoryError(message: message):
|
|
|
|
return "Failed to create a recording directory! \(message ?? "(no additional message)")"
|
2021-05-06 06:11:55 -06:00
|
|
|
case let .createRecorderError(message: message):
|
|
|
|
return "Failed to create the AVAssetWriter (Recorder)! \(message ?? "(no additional message)")"
|
2021-06-07 05:08:40 -06:00
|
|
|
case .videoNotEnabled:
|
|
|
|
return "Video capture is disabled! Pass `video={true}` to enable video recordings."
|
|
|
|
case .photoNotEnabled:
|
|
|
|
return "Photo capture is disabled! Pass `photo={true}` to enable photo capture."
|
2021-06-09 06:56:56 -06:00
|
|
|
case .aborted:
|
|
|
|
return "The capture has been stopped before any input data arrived."
|
2024-01-24 03:48:38 -07:00
|
|
|
case .insufficientStorage:
|
|
|
|
return "There is not enough storage space available."
|
2021-02-19 08:28:05 -07:00
|
|
|
case let .unknown(message: message):
|
|
|
|
return message ?? "An unknown error occured while capturing a video/photo."
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-10-04 04:53:52 -06:00
|
|
|
// MARK: - CodeScannerError
|
|
|
|
|
|
|
|
enum CodeScannerError {
|
|
|
|
case notCompatibleWithOutputs
|
|
|
|
case codeTypeNotSupported(codeType: String)
|
|
|
|
|
|
|
|
var code: String {
|
|
|
|
switch self {
|
|
|
|
case .notCompatibleWithOutputs:
|
|
|
|
return "not-compatible-with-outputs"
|
|
|
|
case .codeTypeNotSupported:
|
|
|
|
return "code-type-not-supported"
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
var message: String {
|
|
|
|
switch self {
|
|
|
|
case .notCompatibleWithOutputs:
|
|
|
|
return "The Code Scanner is not supported in combination with the current outputs! Either disable video or photo outputs."
|
|
|
|
case let .codeTypeNotSupported(codeType: codeType):
|
|
|
|
return "The codeType \"\(codeType)\" is not supported by the Code Scanner!"
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-03-09 02:53:29 -07:00
|
|
|
// MARK: - CameraError
|
|
|
|
|
2021-02-19 08:28:05 -07:00
|
|
|
enum CameraError: Error {
|
|
|
|
case permission(_ id: PermissionError)
|
|
|
|
case parameter(_ id: ParameterError)
|
|
|
|
case device(_ id: DeviceError)
|
|
|
|
case format(_ id: FormatError)
|
|
|
|
case session(_ id: SessionError)
|
|
|
|
case capture(_ id: CaptureError)
|
2023-10-04 04:53:52 -06:00
|
|
|
case codeScanner(_ id: CodeScannerError)
|
2023-10-13 10:33:20 -06:00
|
|
|
case unknown(message: String? = nil, cause: NSError? = nil)
|
2021-02-19 08:28:05 -07:00
|
|
|
|
|
|
|
var code: String {
|
|
|
|
switch self {
|
|
|
|
case let .permission(id: id):
|
|
|
|
return "permission/\(id.code)"
|
|
|
|
case let .parameter(id: id):
|
|
|
|
return "parameter/\(id.code)"
|
|
|
|
case let .device(id: id):
|
|
|
|
return "device/\(id.code)"
|
|
|
|
case let .format(id: id):
|
|
|
|
return "format/\(id.code)"
|
|
|
|
case let .session(id: id):
|
|
|
|
return "session/\(id.code)"
|
|
|
|
case let .capture(id: id):
|
|
|
|
return "capture/\(id.code)"
|
2023-10-04 04:53:52 -06:00
|
|
|
case let .codeScanner(id: id):
|
|
|
|
return "code-scanner/\(id.code)"
|
2021-02-19 08:28:05 -07:00
|
|
|
case .unknown:
|
|
|
|
return "unknown/unknown"
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
var message: String {
|
|
|
|
switch self {
|
|
|
|
case let .permission(id: id):
|
|
|
|
return id.message
|
|
|
|
case let .parameter(id: id):
|
|
|
|
return id.message
|
|
|
|
case let .device(id: id):
|
|
|
|
return id.message
|
|
|
|
case let .format(id: id):
|
|
|
|
return id.message
|
|
|
|
case let .session(id: id):
|
|
|
|
return id.message
|
|
|
|
case let .capture(id: id):
|
|
|
|
return id.message
|
2023-10-04 04:53:52 -06:00
|
|
|
case let .codeScanner(id: id):
|
|
|
|
return id.message
|
2023-10-13 10:33:20 -06:00
|
|
|
case let .unknown(message: message, cause: cause):
|
|
|
|
return message ?? cause?.description ?? "An unexpected error occured."
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
var cause: NSError? {
|
|
|
|
switch self {
|
|
|
|
case let .unknown(message: _, cause: cause):
|
|
|
|
return cause
|
|
|
|
default:
|
|
|
|
return nil
|
2021-02-19 08:28:05 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|