Skip to content

Commit

Permalink
chore: Organize code
Browse files Browse the repository at this point in the history
  • Loading branch information
mrousavy committed Feb 14, 2024
1 parent ad33dd9 commit 3699ccd
Showing 1 changed file with 14 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package com.mrousavy.camera.core.capture
import android.hardware.camera2.CameraCharacteristics
import android.hardware.camera2.CameraDevice
import android.hardware.camera2.CaptureRequest
import android.os.Build
import android.util.Range
import com.mrousavy.camera.core.CameraDeviceDetails
import com.mrousavy.camera.core.InvalidFpsError
Expand All @@ -14,7 +15,7 @@ import com.mrousavy.camera.types.Torch
import com.mrousavy.camera.types.VideoStabilizationMode

class RepeatingCaptureRequest(
val enableVideoPipeline: Boolean,
private val enableVideoPipeline: Boolean,
torch: Torch = Torch.OFF,
private val fps: Int? = null,
private val videoStabilizationMode: VideoStabilizationMode = VideoStabilizationMode.OFF,
Expand All @@ -34,8 +35,10 @@ class RepeatingCaptureRequest(
}

private fun getBestDigitalStabilizationMode(deviceDetails: CameraDeviceDetails): Int {
if (deviceDetails.digitalStabilizationModes.contains(CameraCharacteristics.CONTROL_VIDEO_STABILIZATION_MODE_PREVIEW_STABILIZATION)) {
return CameraCharacteristics.CONTROL_VIDEO_STABILIZATION_MODE_PREVIEW_STABILIZATION
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.TIRAMISU) {
if (deviceDetails.digitalStabilizationModes.contains(CameraCharacteristics.CONTROL_VIDEO_STABILIZATION_MODE_PREVIEW_STABILIZATION)) {
return CameraCharacteristics.CONTROL_VIDEO_STABILIZATION_MODE_PREVIEW_STABILIZATION
}
}
return CameraCharacteristics.CONTROL_VIDEO_STABILIZATION_MODE_ON
}
Expand Down Expand Up @@ -87,16 +90,14 @@ class RepeatingCaptureRequest(
if (!format.videoStabilizationModes.contains(videoStabilizationMode)) {
throw InvalidVideoStabilizationMode(videoStabilizationMode)
}
}
when (videoStabilizationMode) {
VideoStabilizationMode.OFF -> {
// do nothing
}
VideoStabilizationMode.STANDARD -> {
builder.set(CaptureRequest.CONTROL_VIDEO_STABILIZATION_MODE, getBestDigitalStabilizationMode(deviceDetails))
}
VideoStabilizationMode.CINEMATIC, VideoStabilizationMode.CINEMATIC_EXTENDED -> {
builder.set(CaptureRequest.LENS_OPTICAL_STABILIZATION_MODE, CaptureRequest.LENS_OPTICAL_STABILIZATION_MODE_ON)
when (videoStabilizationMode) {
VideoStabilizationMode.STANDARD -> {
builder.set(CaptureRequest.CONTROL_VIDEO_STABILIZATION_MODE, getBestDigitalStabilizationMode(deviceDetails))
}
VideoStabilizationMode.CINEMATIC, VideoStabilizationMode.CINEMATIC_EXTENDED -> {
builder.set(CaptureRequest.LENS_OPTICAL_STABILIZATION_MODE, CaptureRequest.LENS_OPTICAL_STABILIZATION_MODE_ON)
}
else -> throw InvalidVideoStabilizationMode(videoStabilizationMode)
}
}

Expand Down

0 comments on commit 3699ccd

Please sign in to comment.