Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add cam2api features #1822

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -477,8 +477,12 @@ private void updateCaptureRequest() {
}

if (recordingVideo) {
captureRequestBuilder.set(CaptureRequest.CONTROL_AE_TARGET_FPS_RANGE, new Range<Integer>(30, 60));
Range<Integer> targetFpsRange = selectOptimalFpsRange();
captureRequestBuilder.set(CaptureRequest.CONTROL_AE_TARGET_FPS_RANGE, targetFpsRange);
captureRequestBuilder.set(CaptureRequest.CONTROL_CAPTURE_INTENT, CaptureRequest.CONTROL_CAPTURE_INTENT_VIDEO_RECORD);

isStabilizationAvailable(captureRequestBuilder);
isAutoFocusAvailable(captureRequestBuilder);
}

if (sensorSize != null && Math.abs(currentZoom - 1f) >= 0.01f) {
Expand All @@ -502,6 +506,71 @@ private void updateCaptureRequest() {
}
}

private Range<Integer> selectOptimalFpsRange() {
Range<Integer>[] fpsRange = cameraCharacteristics.get(CameraCharacteristics.CONTROL_AE_AVAILABLE_TARGET_FPS_RANGES);
Range<Integer> optimalRange = new Range<>(30, 30);

assert fpsRange != null;
for (Range<Integer> range : fpsRange) {
if (range.getLower() <= 30 && range.getUpper() >= 30) {
optimalRange = range;
break;
}
}

FileLog.d("Camera2Session selected FPS range: " + optimalRange);
return optimalRange;
}

private void isStabilizationAvailable(CaptureRequest.Builder builder) {
if (setModeIfAvailable(
CameraCharacteristics.LENS_INFO_AVAILABLE_OPTICAL_STABILIZATION,
CaptureRequest.LENS_OPTICAL_STABILIZATION_MODE_ON,
builder,
CaptureRequest.LENS_OPTICAL_STABILIZATION_MODE)) {
builder.set(
CaptureRequest.CONTROL_VIDEO_STABILIZATION_MODE,
CaptureRequest.CONTROL_VIDEO_STABILIZATION_MODE_OFF);
FileLog.d("Camera2Sessions use OpticalImageStabilization");
} else if (setModeIfAvailable(
CameraCharacteristics.CONTROL_AVAILABLE_VIDEO_STABILIZATION_MODES,
CaptureRequest.CONTROL_VIDEO_STABILIZATION_MODE_ON,
builder,
CaptureRequest.CONTROL_VIDEO_STABILIZATION_MODE)) {
builder.set(
CaptureRequest.LENS_OPTICAL_STABILIZATION_MODE,
CaptureRequest.LENS_OPTICAL_STABILIZATION_MODE_OFF);
FileLog.d("Camera2Sessions use ElectronicImageStabilization");
} else {
FileLog.d("Camera2Sessions stabilization is not available");
}
}

private void isAutoFocusAvailable(CaptureRequest.Builder builder) {
if (setModeIfAvailable(
CameraCharacteristics.CONTROL_AF_AVAILABLE_MODES,
CaptureRequest.CONTROL_AF_MODE_CONTINUOUS_VIDEO,
builder,
CaptureRequest.CONTROL_AF_MODE)) {
FileLog.d("Camera2Sessions use continuous AF");
} else {
FileLog.d("Camera2Sessions AF is not available");
}
}

private boolean setModeIfAvailable(
CameraCharacteristics.Key<int[]> key,
int desiredMode,
CaptureRequest.Builder builder,
CaptureRequest.Key<Integer> requestKey) {
int[] availableModes = cameraCharacteristics.get(key);
if (availableModes != null && Arrays.stream(availableModes).anyMatch(mode -> mode == desiredMode)) {
builder.set(requestKey, desiredMode);
return true;
}
return false;
}

public boolean takePicture(final File file, Utilities.Callback<Integer> whenDone) {
if (cameraDevice == null || captureSession == null) return false;
try {
Expand Down