2021-02-19 20:41:49 +01:00
package com.mrousavy.camera
2021-02-19 16:28:14 +01:00
import android.graphics.ImageFormat
2021-12-30 11:39:17 +01:00
import androidx.camera.video.VideoRecordEvent.Finalize.VideoRecordError
2021-02-19 16:28:14 +01:00
abstract class CameraError (
2021-02-26 10:56:20 +01:00
/ * *
* The domain of the error . Error domains are used to group errors .
*
* Example : " permission "
* /
val domain : String ,
/ * *
* The id of the error . Errors are uniquely identified under a given domain .
*
* Example : " microphone-permission-denied "
* /
val id : String ,
/ * *
* A detailed error description of " what went wrong " .
*
* Example : " The microphone permission was denied! "
* /
message : String ,
/ * *
* A throwable that caused this error .
* /
cause : Throwable ? = null
) : Throwable ( " [ $domain / $id ] $message " , cause )
2021-02-19 16:28:14 +01:00
val CameraError . code : String
2021-02-26 10:56:20 +01:00
get ( ) = " $domain / $id "
2021-02-19 16:28:14 +01:00
2021-06-07 13:08:40 +02:00
class MicrophonePermissionError : CameraError ( " permission " , " microphone-permission-denied " , " The Microphone permission was denied! If you want to record Video without sound, pass `audio={false}`. " )
2021-02-26 10:56:20 +01:00
class CameraPermissionError : CameraError ( " permission " , " camera-permission-denied " , " The Camera permission was denied! " )
2021-02-19 16:28:14 +01:00
2021-02-26 10:56:20 +01:00
class InvalidTypeScriptUnionError ( unionName : String , unionValue : String ) : CameraError ( " parameter " , " invalid-parameter " , " The given value for $unionName could not be parsed! (Received: $unionValue ) " )
2021-02-19 16:28:14 +01:00
2021-02-26 10:56:20 +01:00
class NoCameraDeviceError : CameraError ( " device " , " no-device " , " No device was set! Use `getAvailableCameraDevices()` to select a suitable Camera device. " )
class InvalidCameraDeviceError ( cause : Throwable ) : CameraError ( " device " , " invalid-device " , " The given Camera device could not be found for use-case binding! " , cause )
2021-06-27 12:37:54 +02:00
class ParallelVideoProcessingNotSupportedError ( cause : Throwable ) : CameraError ( " device " , " parallel-video-processing-not-supported " , " The given LEGACY Camera device does not support parallel " +
" video processing (`video={true}` + `frameProcessor={...}`). Disable either `video` or `frameProcessor`. To find out if a device supports parallel video processing, check the `supportsParallelVideoProcessing` property on the CameraDevice. " +
2021-08-02 11:21:23 +02:00
" See https://mrousavy.github.io/react-native-vision-camera/docs/guides/devices#the-supportsparallelvideoprocessing-prop for more information. " , cause )
2021-02-19 16:28:14 +01:00
2021-02-26 10:56:20 +01:00
class FpsNotContainedInFormatError ( fps : Int ) : CameraError ( " format " , " invalid-fps " , " The given FPS were not valid for the currently selected format. Make sure you select a format which `frameRateRanges` includes $fps FPS! " )
class HdrNotContainedInFormatError ( ) : CameraError (
" format " , " invalid-hdr " ,
" The currently selected format does not support HDR capture! " +
" Make sure you select a format which `frameRateRanges` includes `supportsPhotoHDR`! "
)
class LowLightBoostNotContainedInFormatError ( ) : CameraError (
" format " , " invalid-low-light-boost " ,
" The currently selected format does not support low-light boost (night mode)! " +
" Make sure you select a format which includes `supportsLowLightBoost`. "
)
2021-02-19 16:28:14 +01:00
2021-02-26 10:56:20 +01:00
class CameraNotReadyError : CameraError ( " session " , " camera-not-ready " , " The Camera is not ready yet! Wait for the onInitialized() callback! " )
2021-02-19 16:28:14 +01:00
2021-06-07 13:08:40 +02:00
class VideoNotEnabledError : CameraError ( " capture " , " video-not-enabled " , " Video capture is disabled! Pass `video={true}` to enable video recordings. " )
class PhotoNotEnabledError : CameraError ( " capture " , " photo-not-enabled " , " Photo capture is disabled! Pass `photo={true}` to enable photo capture. " )
2021-02-26 10:56:20 +01:00
class InvalidFormatError ( format : Int ) : CameraError ( " capture " , " invalid-photo-format " , " The Photo has an invalid format! Expected ${ImageFormat.YUV_420_888} , actual: $format " )
2021-12-30 11:39:17 +01:00
class VideoEncoderError ( cause : Throwable ? ) : CameraError ( " capture " , " encoder-error " , " The recording failed while encoding. \n " +
" This error may be generated when the video or audio codec encounters an error during encoding. " +
" When this happens and the output file is generated, the output file is not properly constructed. " +
" The application will need to clean up the output file, such as deleting the file. " ,
cause )
class InvalidVideoOutputOptionsError ( cause : Throwable ? ) : CameraError ( " capture " , " invalid-video-options " ,
" The recording failed due to invalid output options. \n " +
" This error is generated when invalid output options have been used while preparing a recording " ,
cause )
class RecorderError ( cause : Throwable ? ) : CameraError ( " capture " , " recorder-error " ,
" The recording failed because the Recorder is in an unrecoverable error state. \n " +
" When this happens and the output file is generated, the output file is not properly constructed. " +
" The application will need to clean up the output file, such as deleting the file. " +
" Such an error will usually require creating a new Recorder object to start a new recording. " ,
cause )
class NoValidDataError ( cause : Throwable ? ) : CameraError ( " capture " , " no-valid-data " ,
" The recording failed because no valid data was produced to be recorded. \n " +
" This error is generated when the essential data for a recording to be played correctly is missing, for example, " +
" a recording must contain at least one key frame. The application will need to clean up the output file, such as deleting the file. " ,
cause )
class InactiveSourceError ( cause : Throwable ? ) : CameraError ( " capture " , " inactive-source " ,
" The recording failed because the source becomes inactive and stops sending frames. \n " +
" One case is that if camera is closed due to lifecycle stopped, the active recording will be finalized with this error, " +
" and the output will be generated, containing the frames produced before camera closing. " +
" Attempting to start a new recording will be finalized immediately if the source remains inactive and no output will be generated. " ,
cause )
class InsufficientStorageError ( cause : Throwable ? ) : CameraError ( " capture " , " insufficient-storage " ,
" The recording failed due to insufficient storage space. \n " +
" There are two possible cases that will cause this error. \n " +
" 1. The storage is already full before the recording starts, so no output file will be generated. \n " +
" 2. The storage becomes full during recording, so the output file will be generated. " ,
cause )
class FileSizeLimitReachedError ( cause : Throwable ? ) : CameraError ( " capture " , " file-size-limit-reached " ,
" The recording failed due to file size limitation. \n " +
" The file size limitation will refer to OutputOptions.getFileSizeLimit(). The output file will still be generated with this error. " ,
cause )
class NoRecordingInProgressError : CameraError ( " capture " , " no-recording-in-progress " , " No active recording in progress! " )
2021-02-19 16:28:14 +01:00
2021-02-26 10:56:20 +01:00
class ViewNotFoundError ( viewId : Int ) : CameraError ( " system " , " view-not-found " , " The given view (ID $viewId ) was not found in the view manager. " )
2021-02-19 16:28:14 +01:00
2021-12-30 11:39:17 +01:00
class UnknownCameraError ( cause : Throwable ? ) : CameraError ( " unknown " , " unknown " , cause ?. message ?: " An unknown camera error occured. " , cause )