Skip to content

Commit 1de60a0

Browse files
committed
lock unlock focus feature done
1 parent 03d866a commit 1de60a0

File tree

5 files changed

+232
-62
lines changed

5 files changed

+232
-62
lines changed

app/src/main/java/com/googleresearch/capturesync/CaptureRequestFactory.java

Lines changed: 15 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -17,22 +17,31 @@
1717
package com.googleresearch.capturesync;
1818

1919
import static android.hardware.camera2.CameraDevice.TEMPLATE_PREVIEW;
20+
import static android.hardware.camera2.CameraDevice.TEMPLATE_MANUAL;
2021
import static android.hardware.camera2.CameraMetadata.CONTROL_AE_MODE_OFF;
2122
import static android.hardware.camera2.CameraMetadata.CONTROL_AF_MODE_AUTO;
23+
import static android.hardware.camera2.CameraMetadata.CONTROL_AF_MODE_CONTINUOUS_VIDEO;
24+
import static android.hardware.camera2.CameraMetadata.CONTROL_AF_MODE_OFF;
25+
import static android.hardware.camera2.CameraMetadata.CONTROL_AF_TRIGGER_CANCEL;
26+
import static android.hardware.camera2.CameraMetadata.CONTROL_AF_TRIGGER_IDLE;
2227
import static android.hardware.camera2.CameraMetadata.CONTROL_AWB_MODE_AUTO;
2328
import static android.hardware.camera2.CameraMetadata.CONTROL_MODE_AUTO;
2429
import static android.hardware.camera2.CaptureRequest.CONTROL_AE_MODE;
2530
import static android.hardware.camera2.CaptureRequest.CONTROL_AF_MODE;
2631
import static android.hardware.camera2.CaptureRequest.CONTROL_AF_MODE_CONTINUOUS_PICTURE;
32+
import static android.hardware.camera2.CaptureRequest.CONTROL_AF_TRIGGER;
2733
import static android.hardware.camera2.CaptureRequest.CONTROL_AWB_MODE;
2834
import static android.hardware.camera2.CaptureRequest.CONTROL_MODE;
35+
import static android.hardware.camera2.CaptureRequest.LENS_FOCUS_DISTANCE;
2936
import static android.hardware.camera2.CaptureRequest.SENSOR_EXPOSURE_TIME;
3037
import static android.hardware.camera2.CaptureRequest.SENSOR_SENSITIVITY;
3138

3239
import android.hardware.camera2.CameraAccessException;
3340
import android.hardware.camera2.CameraDevice;
3441
import android.hardware.camera2.CaptureRequest;
3542
import android.view.Surface;
43+
import android.widget.Toast;
44+
3645
import com.googleresearch.capturesync.ImageMetadataSynchronizer.CaptureRequestTag;
3746
import java.util.ArrayList;
3847
import java.util.List;
@@ -61,23 +70,16 @@ public CaptureRequest.Builder makePreview(
6170
CaptureRequest.Builder builder = device.createCaptureRequest(TEMPLATE_PREVIEW);
6271
if (wantAutoExp) {
6372
builder.set(CONTROL_AE_MODE, CONTROL_AWB_MODE_AUTO);
64-
6573
} else {
6674
// Manually set exposure and sensitivity using UI sliders on the leader.
6775
builder.set(CONTROL_AE_MODE, CONTROL_AE_MODE_OFF);
6876
builder.set(SENSOR_EXPOSURE_TIME, sensorExposureTimeNs);
6977
builder.set(SENSOR_SENSITIVITY, sensorSensitivity);
7078
}
71-
79+
builder.set(CONTROL_AF_TRIGGER, CONTROL_AF_TRIGGER_CANCEL);
80+
builder.set(CONTROL_AF_MODE, CONTROL_AF_MODE_OFF);
7281
// Auto white balance used, these could be locked and sent from the leader instead.
7382
builder.set(CONTROL_AWB_MODE, CONTROL_AWB_MODE_AUTO);
74-
if(enableFocus==true){
75-
builder.set(CONTROL_AF_MODE, CONTROL_AF_MODE_CONTINUOUS_PICTURE);
76-
}else{
77-
builder.set(CONTROL_AF_MODE, CONTROL_AF_MODE_AUTO);
78-
}
79-
80-
8183

8284
if (viewfinderSurface != null) {
8385
builder.addTarget(viewfinderSurface);
@@ -91,6 +93,7 @@ public CaptureRequest.Builder makePreview(
9193
return builder;
9294
}
9395

96+
9497
/**
9598
* An alternative capture request for video,
9699
* includes everything from preview + mediaRecorder
@@ -114,10 +117,13 @@ public CaptureRequest.Builder makeVideo(
114117

115118
public CaptureRequest.Builder makeFrameInjectionRequest(
116119
long desiredExposureTimeNs, List<Surface> imageSurfaces) throws CameraAccessException {
120+
117121
CaptureRequest.Builder builder = device.createCaptureRequest(TEMPLATE_PREVIEW);
118122
builder.set(CONTROL_MODE, CONTROL_MODE_AUTO);
119123
builder.set(CONTROL_AE_MODE, CONTROL_AE_MODE_OFF);
120124
builder.set(SENSOR_EXPOSURE_TIME, desiredExposureTimeNs);
125+
builder.set(CONTROL_AF_TRIGGER, CONTROL_AF_TRIGGER_CANCEL);
126+
builder.set(CONTROL_AF_MODE, CONTROL_AF_MODE_OFF);
121127
// TODO: Inserting frame duration directly would be more accurate than inserting exposure since
122128
// {@code frame duration ~ exposure + variable overhead}. However setting frame duration may not
123129
// be supported on many android devices, so we use exposure time here.

app/src/main/java/com/googleresearch/capturesync/ImageMetadataSynchronizer.java

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,10 @@
1616

1717
package com.googleresearch.capturesync;
1818

19+
import static android.hardware.camera2.CameraMetadata.CONTROL_AF_MODE_AUTO;
20+
import static android.hardware.camera2.CameraMetadata.CONTROL_AF_MODE_OFF;
21+
import static android.hardware.camera2.CaptureRequest.CONTROL_AF_MODE;
22+
1923
import android.hardware.camera2.CameraCaptureSession;
2024
import android.hardware.camera2.CameraCaptureSession.CaptureCallback;
2125
import android.hardware.camera2.CaptureRequest;
@@ -377,6 +381,13 @@ private void createCaptureCallback() {
377381
@Override
378382
public void onCaptureCompleted(
379383
CameraCaptureSession session, CaptureRequest request, TotalCaptureResult result) {
384+
Float focusDistance = result.get(CaptureResult.LENS_FOCUS_DISTANCE);
385+
if (focusDistance != null) {
386+
context.setCurrentFocusDistance(focusDistance);
387+
} else {
388+
focusDistance = context.getCurrentFocusDistance();
389+
context.setCurrentFocusDistance(0.0f);
390+
}
380391
if (closed) {
381392
return;
382393
}

0 commit comments

Comments
 (0)