Skip to content

Commit

Permalink
add enable/disable auto exposure
Browse files Browse the repository at this point in the history
  • Loading branch information
pedroSG94 committed Nov 14, 2024
1 parent 8b428e5 commit 9222c21
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -197,4 +197,14 @@ class Camera2Source(context: Context): VideoSource() {
}

fun isVideoStabilizationEnabled() = camera.isVideoStabilizationEnabled

fun enableAutoExposure(): Boolean {
return if (isRunning()) camera.enableAutoExposure() else false
}

fun disableAutoExposure() {
if (isRunning()) camera.disableAutoExposure()
}

fun isAutoExposureEnabled() = camera.isAutoExposureEnabled
}
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,8 @@ class Camera2ApiManager(context: Context) : CameraDevice.StateCallback() {
private set
var isAutoFocusEnabled: Boolean = true
private set
var isAutoExposureEnabled: Boolean = false
private set
var isRunning: Boolean = false
private set
private var fps = 30
Expand Down Expand Up @@ -296,6 +298,25 @@ class Camera2ApiManager(context: Context) : CameraDevice.StateCallback() {
}
}

fun enableAutoExposure(): Boolean {
val characteristics = cameraCharacteristics ?: return false
val builderInputSurface = this.builderInputSurface ?: return false
val modes = characteristics.secureGet(CameraCharacteristics.CONTROL_AVAILABLE_VIDEO_STABILIZATION_MODES) ?: return false
if (!modes.contains(CaptureRequest.CONTROL_AE_MODE_ON)) return false
builderInputSurface.set(CaptureRequest.CONTROL_AE_MODE, CaptureRequest.CONTROL_AE_MODE_ON)
isAutoExposureEnabled = true
return isAutoExposureEnabled
}

fun disableAutoExposure() {
val characteristics = cameraCharacteristics ?: return
val builderInputSurface = this.builderInputSurface ?: return
val modes = characteristics.secureGet(CameraCharacteristics.CONTROL_AVAILABLE_VIDEO_STABILIZATION_MODES) ?: return
if (!modes.contains(CaptureRequest.CONTROL_AE_MODE_ON)) return
builderInputSurface.set(CaptureRequest.CONTROL_AE_MODE, CaptureRequest.CONTROL_AE_MODE_OFF)
isAutoExposureEnabled = false
}

fun enableVideoStabilization(): Boolean {
val characteristics = cameraCharacteristics ?: return false
val builderInputSurface = this.builderInputSurface ?: return false
Expand Down
12 changes: 12 additions & 0 deletions library/src/main/java/com/pedro/library/base/Camera2Base.java
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,18 @@ public boolean isFaceDetectionEnabled() {
return cameraManager.isFaceDetectionEnabled();
}

public boolean enableAutoExposure() {
return cameraManager.enableAutoExposure();
}

public void disableAutoExposure() {
cameraManager.disableAutoExposure();
}

public boolean isAutoExposureEnabled() {
return cameraManager.isAutoExposureEnabled();
}

/**
* Enable EIS video stabilization
* Warning: Turning both OIS and EIS modes on may produce undesirable interaction, so it is recommended not to enable both at the same time.
Expand Down

0 comments on commit 9222c21

Please sign in to comment.