Skip to content

Commit 6d399db

Browse files
committed
add lockExposure to Camera2Source
Based on: pedroSG94#1863
1 parent 4e02d78 commit 6d399db

File tree

3 files changed

+37
-0
lines changed

3 files changed

+37
-0
lines changed

encoder/src/main/java/com/pedro/encoder/input/sources/video/Camera2Source.kt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -269,4 +269,8 @@ class Camera2Source(context: Context): VideoSource() {
269269
size?.let { checkResolutionSupported(it.width, it.height) }
270270
camera.setRequiredResolution(size)
271271
}
272+
273+
fun lockExposure(enabled: Boolean) = camera.lockExposure(enabled)
274+
275+
fun isLockExposureEnabled() = camera.isLockExposureEnabled()
272276
}

encoder/src/main/java/com/pedro/encoder/input/video/Camera2ApiManager.kt

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,8 @@ class Camera2ApiManager(context: Context) : CameraDevice.StateCallback() {
9696
private set
9797
var isAutoWhiteBalanceEnabled: Boolean = true
9898
private set
99+
var lockExposureEnabled: Boolean = false
100+
private set
99101
var isRunning: Boolean = false
100102
private set
101103
private var fps = 30
@@ -313,6 +315,17 @@ class Camera2ApiManager(context: Context) : CameraDevice.StateCallback() {
313315
}
314316
}
315317

318+
fun lockExposure(enabled: Boolean): Boolean {
319+
val builderInputSurface = this.builderInputSurface ?: return false
320+
builderInputSurface.set(CaptureRequest.CONTROL_AE_LOCK, enabled)
321+
if (applyRequest(builderInputSurface)) {
322+
lockExposureEnabled = enabled
323+
return true
324+
} else return false
325+
}
326+
327+
fun isLockExposureEnabled() = lockExposureEnabled
328+
316329
/**
317330
* @param mode value from CameraCharacteristics.CONTROL_AWB_MODE_*
318331
*/

library/src/main/java/com/pedro/library/base/Camera2Base.java

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -966,6 +966,26 @@ public boolean tapToFocus(View view, MotionEvent event) {
966966
return cameraManager.tapToFocus(view, event);
967967
}
968968

969+
970+
/**
971+
* Lock or unlock exposure
972+
*
973+
* @param enabled true to lock exposure, false to unlock
974+
* @return true if successful, false otherwise
975+
*/
976+
public boolean lockExposure(boolean enabled) {
977+
return cameraManager.lockExposure(enabled);
978+
}
979+
980+
/**
981+
* Check if exposure is locked
982+
*
983+
* @return true if exposure is locked, false otherwise
984+
*/
985+
public boolean isLockExposureEnabled() {
986+
return cameraManager.isLockExposureEnabled();
987+
}
988+
969989
public GlInterface getGlInterface() {
970990
return glInterface;
971991
}

0 commit comments

Comments
 (0)