Skip to content

Commit

Permalink
fix: Ensure format is properly checked for equality (mrousavy#2083)
Browse files Browse the repository at this point in the history
* fix: Properly check for equality in `CameraDeviceFormat`

* Update CameraSession.kt

* fix: Fix `autoFocusSystem` parsing

* Format
  • Loading branch information
mrousavy authored Oct 25, 2023
1 parent d626fb0 commit 684f400
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 56 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -347,11 +347,6 @@ class CameraSession(private val context: Context, private val cameraManager: Cam
codeScannerOutput = output
}

if (outputs.isEmpty()) {
Log.w(TAG, "Cannot create Camera Session without any outputs. Aborting...")
return
}

// Create new session
captureSession = cameraDevice.createCaptureSession(cameraManager, outputs, { session ->
if (this.captureSession == session) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,11 @@ data class CameraDeviceFormat(
val maxISO: Double,
val fieldOfView: Double,
val maxZoom: Double,
val videoStabilizationModes: Array<VideoStabilizationMode>,
val videoStabilizationModes: List<VideoStabilizationMode>,
val autoFocusSystem: AutoFocusSystem,
val supportsVideoHDR: Boolean,
val supportsPhotoHDR: Boolean,
val pixelFormats: Array<PixelFormat>,
val pixelFormats: List<PixelFormat>,
val supportsDepthCapture: Boolean
) {
val photoSize: Size
Expand Down Expand Up @@ -48,59 +48,13 @@ data class CameraDeviceFormat(
value.getDouble("maxISO"),
value.getDouble("fieldOfView"),
value.getDouble("maxZoom"),
videoStabilizationModes.toTypedArray(),
videoStabilizationModes,
autoFocusSystem,
value.getBoolean("supportsVideoHDR"),
value.getBoolean("supportsPhotoHDR"),
pixelFormats.toTypedArray(),
pixelFormats,
value.getBoolean("supportsDepthCapture")
)
}
}

override fun equals(other: Any?): Boolean {
if (this === other) return true
if (javaClass != other?.javaClass) return false

other as CameraDeviceFormat

if (videoWidth != other.videoWidth) return false
if (videoHeight != other.videoHeight) return false
if (photoWidth != other.photoWidth) return false
if (photoHeight != other.photoHeight) return false
if (minFps != other.minFps) return false
if (maxFps != other.maxFps) return false
if (minISO != other.minISO) return false
if (maxISO != other.maxISO) return false
if (fieldOfView != other.fieldOfView) return false
if (maxZoom != other.maxZoom) return false
if (!videoStabilizationModes.contentEquals(other.videoStabilizationModes)) return false
if (autoFocusSystem != other.autoFocusSystem) return false
if (supportsVideoHDR != other.supportsVideoHDR) return false
if (supportsPhotoHDR != other.supportsPhotoHDR) return false
if (!pixelFormats.contentEquals(other.pixelFormats)) return false
if (supportsDepthCapture != other.supportsDepthCapture) return false

return true
}

override fun hashCode(): Int {
var result = videoWidth
result = 31 * result + videoHeight
result = 31 * result + photoWidth
result = 31 * result + photoHeight
result = 31 * result + minFps.hashCode()
result = 31 * result + maxFps.hashCode()
result = 31 * result + minISO.hashCode()
result = 31 * result + maxISO.hashCode()
result = 31 * result + fieldOfView.hashCode()
result = 31 * result + maxZoom.hashCode()
result = 31 * result + videoStabilizationModes.contentHashCode()
result = 31 * result + autoFocusSystem.hashCode()
result = 31 * result + supportsVideoHDR.hashCode()
result = 31 * result + supportsPhotoHDR.hashCode()
result = 31 * result + pixelFormats.contentHashCode()
result = 31 * result + supportsDepthCapture.hashCode()
return result
}
}
2 changes: 1 addition & 1 deletion package/ios/Types/AutoFocusSystem.swift
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import Foundation

enum AutoFocusSystem: String, JSUnionValue {
case contrastDetection = "contrast-detection"
case phaseDetection
case phaseDetection = "phase-detection"
case none

init(jsValue: String) throws {
Expand Down

0 comments on commit 684f400

Please sign in to comment.