37a3548a81
* Nuke CameraX * fix: Run View Finder on UI Thread * Open Camera, set up Threads * fix init * Mirror if needed * Try PreviewView * Use max resolution * Add `hardwareLevel` property * Check if output type is supported * Replace `frameRateRanges` with `minFps` and `maxFps` * Remove `isHighestPhotoQualitySupported` * Remove `colorSpace` The native platforms will use the best / most accurate colorSpace by default anyways. * HDR * Check from format * fix * Remove `supportsParallelVideoProcessing` * Correctly return video/photo sizes on Android now. Finally * Log all Device props * Log if optimized usecase is used * Cleanup * Configure Camera Input only once * Revert "Configure Camera Input only once" This reverts commit 0fd6c03f54c7566cb5592053720c4a8743aba92e. * Extract Camera configuration * Try to reconfigure all * Hook based * Properly set up `CameraSession` * Delete unused * fix: Fix recreate when outputs change * Update NativePreviewView.kt * Use callback for closing * Catch CameraAccessException * Finally got it stable * Remove isMirrored * Implement `takePhoto()` * Add ExifInterface library * Run findViewById on UI Thread * Add Photo Output Surface to takePhoto * Fix Video Stabilization Modes * Optimize Imports * More logs * Update CameraSession.kt * Close Image * Use separate Executor in CameraQueue * Delete hooks * Use same Thread again * If opened, call error * Update CameraSession.kt * Log HW level * fix: Don't enable Stream Use Case if it's not 100% supported * Move some stuff * Cleanup PhotoOutputSynchronizer * Try just open in suspend fun * Some synchronization fixes * fix logs * Update CameraDevice+createCaptureSession.kt * Update CameraDevice+createCaptureSession.kt * fixes * fix: Use Snapshot Template for speed capture prio * Use PREVIEW template for repeating request * Use `TEMPLATE_RECORD` if video use-case is attached * Use `isRunning` flag * Recreate session everytime on active/inactive * Lazily get values in capture session * Stability * Rebuild session if outputs change * Set `didOutputsChange` back to false * Capture first in lock * Try * kinda fix it? idk * fix: Keep Outputs * Refactor into single method * Update CameraView.kt * Use Enums for type safety * Implement Orientation (I think) * Move RefCount management to Java (Frame) * Don't crash when dropping a Frame * Prefer Devices with higher max resolution * Prefer multi-cams * Use FastImage for Media Page * Return orientation in takePhoto() * Load orientation from EXIF Data * Add `isMirrored` props and documentation for PhotoFile * fix: Return `not-determined` on Android * Update CameraViewModule.kt * chore: Upgrade packages * fix: Fix Metro Config * Cleanup config * Properly mirror Images on save * Prepare MediaRecorder * Start/Stop MediaRecorder * Remove `takeSnapshot()` It no longer works on Android and never worked on iOS. Users could use useFrameProcessor to take a Snapshot * Use `MediaCodec` * Move to `VideoRecording` class * Cleanup Snapshot * Create `SkiaPreviewView` hybrid class * Create OpenGL context * Create `SkiaPreviewView` * Fix texture creation missing context * Draw red frame * Somehow get it working * Add Skia CMake setup * Start looping * Init OpenGL * Refactor into `SkiaRenderer` * Cleanup PreviewSize * Set up * Only re-render UI if there is a new Frame * Preview * Fix init * Try rendering Preview * Update SkiaPreviewView.kt * Log version * Try using Skia (fail) * Drawwwww!!!!!!!!!! 🎉 * Use Preview Size * Clear first * Refactor into SkiaRenderer * Add `previewType: "none"` on iOS * Simplify a lot * Draw Camera? For some reason? I have no idea anymore * Fix OpenGL errors * Got it kinda working again? * Actually draw Frame woah * Clean up code * Cleanup * Update on main * Synchronize render calls * holy shit * Update SkiaRenderer.cpp * Update SkiaRenderer.cpp * Refactor * Update SkiaRenderer.cpp * Check for `NO_INPUT_TEXTURE`^ * Post & Wait * Set input size * Add Video back again * Allow session without preview * Convert JPEG to byte[] * feat: Use `ImageReader` and use YUV Image Buffers in Skia Context (#1689) * Try to pass YUV Buffers as Pixmaps * Create pixmap! * Clean up * Render to preview * Only render if we have an output surface * Update SkiaRenderer.cpp * Fix Y+U+V sampling code * Cleanup * Fix Semaphore 0 * Use 4:2:0 YUV again idk * Update SkiaRenderer.h * Set minSdk to 26 * Set surface * Revert "Set minSdk to 26" This reverts commit c4085b7c16c628532e5c2d68cf7ed11c751d0b48. * Set previewType * feat: Video Recording with Camera2 (#1691) * Rename * Update CameraSession.kt * Use `SurfaceHolder` instead of `SurfaceView` for output * Update CameraOutputs.kt * Update CameraSession.kt * fix: Fix crash when Preview is null * Check if snapshot capture is supported * Update RecordingSession.kt * S * Use `MediaRecorder` * Make audio optional * Add Torch * Output duration * Update RecordingSession.kt * Start RecordingSession * logs * More log * Base for preparing pass-through Recording * Use `ImageWriter` to append Images to the Recording Surface * Stream PRIVATE GPU_SAMPLED_IMAGE Images * Add flags * Close session on stop * Allow customizing `videoCodec` and `fileType` * Enable Torch * Fix Torch Mode * Fix comparing outputs with hashCode * Update CameraSession.kt * Correctly pass along Frame Processor * fix: Use AUDIO_BIT_RATE of 16 * 44,1Khz * Use CAMCORDER instead of MIC microphone * Use 1 channel * fix: Use `Orientation` * Add `native` PixelFormat * Update iOS to latest Skia integration * feat: Add `pixelFormat` property to Camera * Catch error in configureSession * Fix JPEG format * Clean up best match finder * Update CameraDeviceDetails.kt * Clamp sizes by maximum CamcorderProfile size * Remove `getAvailableVideoCodecs` * chore: release 3.0.0-rc.5 * Use maximum video size of RECORD as default * Update CameraDeviceDetails.kt * Add a todo * Add JSON device to issue report * Prefer `full` devices and flash * Lock to 30 FPS on Samsung * Implement Zoom * Refactor * Format -> PixelFormat * fix: Feat `pixelFormat` -> `pixelFormats` * Update TROUBLESHOOTING.mdx * Format * fix: Implement `zoom` for Photo Capture * fix: Don't run if `isActive` is `false` * fix: Call `examplePlugin(frame)` * fix: Fix Flash * fix: Use `react-native-worklets-core`! * fix: Fix import
321 lines
9.7 KiB
Swift
321 lines
9.7 KiB
Swift
//
|
|
// CameraError.swift
|
|
// mrousavy
|
|
//
|
|
// Created by Marc Rousavy on 14.01.21.
|
|
// Copyright © 2021 mrousavy. All rights reserved.
|
|
//
|
|
|
|
import Foundation
|
|
|
|
// MARK: - PermissionError
|
|
|
|
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:
|
|
return "The Microphone permission was denied! If you want to record Videos without sound, pass `audio={false}`."
|
|
case .camera:
|
|
return "The Camera permission was denied!"
|
|
}
|
|
}
|
|
}
|
|
|
|
// MARK: - ParameterError
|
|
|
|
enum ParameterError {
|
|
case invalid(unionName: String, receivedValue: String)
|
|
case unsupportedOS(unionName: String, receivedValue: String, supportedOnOs: 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 .unsupportedOS:
|
|
return "unsupported-os"
|
|
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 .unsupportedOS(unionName: unionName, receivedValue: receivedValue, supportedOnOs: os):
|
|
return "The value \"\(receivedValue)\" for type \(unionName) is not supported on the current iOS version! Required OS: \(os) or higher"
|
|
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!"
|
|
}
|
|
}
|
|
}
|
|
|
|
// MARK: - DeviceError
|
|
|
|
enum DeviceError: String {
|
|
case configureError = "configuration-error"
|
|
case noDevice = "no-device"
|
|
case invalid = "invalid-device"
|
|
case flashUnavailable = "flash-unavailable"
|
|
case microphoneUnavailable = "microphone-unavailable"
|
|
case lowLightBoostNotSupported = "low-light-boost-not-supported"
|
|
case focusNotSupported = "focus-not-supported"
|
|
case notAvailableOnSimulator = "camera-not-available-on-simulator"
|
|
|
|
var code: String {
|
|
return rawValue
|
|
}
|
|
|
|
var message: String {
|
|
switch self {
|
|
case .configureError:
|
|
return "Failed to lock the device for configuration."
|
|
case .noDevice:
|
|
return "No device was set! Use `getAvailableCameraDevices()` to select a suitable Camera device."
|
|
case .invalid:
|
|
return "The given Camera device was invalid. Use `getAvailableCameraDevices()` to select a suitable Camera device."
|
|
case .flashUnavailable:
|
|
return "The Camera Device does not have a flash unit! Make sure you select a device where `hasFlash`/`hasTorch` is true!"
|
|
case .lowLightBoostNotSupported:
|
|
return "The currently selected camera device does not support low-light boost! Make sure you select a device where `supportsLowLightBoost` is true!"
|
|
case .focusNotSupported:
|
|
return "The currently selected camera device does not support focussing!"
|
|
case .microphoneUnavailable:
|
|
return "The microphone was unavailable."
|
|
case .notAvailableOnSimulator:
|
|
return "The Camera is not available on the iOS Simulator!"
|
|
}
|
|
}
|
|
}
|
|
|
|
// MARK: - FormatError
|
|
|
|
enum FormatError {
|
|
case invalidFps(fps: Int)
|
|
case invalidHdr
|
|
case invalidFormat
|
|
|
|
var code: String {
|
|
switch self {
|
|
case .invalidFormat:
|
|
return "invalid-format"
|
|
case .invalidFps:
|
|
return "invalid-fps"
|
|
case .invalidHdr:
|
|
return "invalid-hdr"
|
|
}
|
|
}
|
|
|
|
var message: String {
|
|
switch self {
|
|
case .invalidFormat:
|
|
return "The given format was invalid. Did you check if the current device supports the given format by using `getAvailableCameraDevices(...)`?"
|
|
case let .invalidFps(fps):
|
|
return "The given format cannot run at \(fps) FPS! Make sure your FPS is lower than `format.maxFps` but higher than `format.minFps`."
|
|
case .invalidHdr:
|
|
return "The currently selected format does not support HDR capture! Make sure you select a format which includes `supportsPhotoHDR`!"
|
|
}
|
|
}
|
|
}
|
|
|
|
// MARK: - SessionError
|
|
|
|
enum SessionError {
|
|
case cameraNotReady
|
|
case audioSessionSetupFailed(reason: String)
|
|
case audioSessionFailedToActivate
|
|
case audioInUseByOtherApp
|
|
|
|
var code: String {
|
|
switch self {
|
|
case .cameraNotReady:
|
|
return "camera-not-ready"
|
|
case .audioSessionSetupFailed:
|
|
return "audio-session-setup-failed"
|
|
case .audioInUseByOtherApp:
|
|
return "audio-in-use-by-other-app"
|
|
case .audioSessionFailedToActivate:
|
|
return "audio-session-failed-to-activate"
|
|
}
|
|
}
|
|
|
|
var message: String {
|
|
switch self {
|
|
case .cameraNotReady:
|
|
return "The Camera is not ready yet! Wait for the onInitialized() callback!"
|
|
case let .audioSessionSetupFailed(reason):
|
|
return "The audio session failed to setup! \(reason)"
|
|
case .audioInUseByOtherApp:
|
|
return "The audio session is already in use by another app with higher priority!"
|
|
case .audioSessionFailedToActivate:
|
|
return "Failed to activate Audio Session!"
|
|
}
|
|
}
|
|
}
|
|
|
|
// MARK: - CaptureError
|
|
|
|
enum CaptureError {
|
|
case invalidPhotoFormat
|
|
case recordingInProgress
|
|
case noRecordingInProgress
|
|
case fileError
|
|
case createTempFileError
|
|
case createRecorderError(message: String? = nil)
|
|
case invalidPhotoCodec
|
|
case videoNotEnabled
|
|
case photoNotEnabled
|
|
case aborted
|
|
case unknown(message: String? = nil)
|
|
|
|
var code: String {
|
|
switch self {
|
|
case .invalidPhotoFormat:
|
|
return "invalid-photo-format"
|
|
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"
|
|
case .createRecorderError:
|
|
return "create-recorder-error"
|
|
case .invalidPhotoCodec:
|
|
return "invalid-photo-codec"
|
|
case .videoNotEnabled:
|
|
return "video-not-enabled"
|
|
case .photoNotEnabled:
|
|
return "photo-not-enabled"
|
|
case .aborted:
|
|
return "aborted"
|
|
case .unknown:
|
|
return "unknown"
|
|
}
|
|
}
|
|
|
|
var message: String {
|
|
switch self {
|
|
case .invalidPhotoFormat:
|
|
return "The given photo format was invalid!"
|
|
case .invalidPhotoCodec:
|
|
return "The given photo codec was invalid!"
|
|
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!"
|
|
case .createTempFileError:
|
|
return "Failed to create a temporary file!"
|
|
case let .createRecorderError(message: message):
|
|
return "Failed to create the AVAssetWriter (Recorder)! \(message ?? "(no additional message)")"
|
|
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."
|
|
case .aborted:
|
|
return "The capture has been stopped before any input data arrived."
|
|
case let .unknown(message: message):
|
|
return message ?? "An unknown error occured while capturing a video/photo."
|
|
}
|
|
}
|
|
}
|
|
|
|
// MARK: - SystemError
|
|
|
|
enum SystemError: String {
|
|
case noManager = "no-camera-manager"
|
|
case skiaUnavailable = "skia-unavailable"
|
|
case frameProcessorsUnavailable = "frame-processors-unavailable"
|
|
|
|
var code: String {
|
|
return rawValue
|
|
}
|
|
|
|
var message: String {
|
|
switch self {
|
|
case .noManager:
|
|
return "No Camera Manager was found."
|
|
case .skiaUnavailable:
|
|
return "Skia Integration is unavailable - is @shopify/react-native-skia installed?"
|
|
case .frameProcessorsUnavailable:
|
|
return "Frame Processors are unavailable - is react-native-worklets-core installed?"
|
|
}
|
|
}
|
|
}
|
|
|
|
// MARK: - CameraError
|
|
|
|
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)
|
|
case system(_ id: SystemError)
|
|
case unknown(message: String? = nil)
|
|
|
|
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)"
|
|
case let .system(id: id):
|
|
return "system/\(id.code)"
|
|
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
|
|
case let .system(id: id):
|
|
return id.message
|
|
case let .unknown(message: message):
|
|
return message ?? "An unexpected error occured."
|
|
}
|
|
}
|
|
}
|