Skip to content
This repository was archived by the owner on Feb 22, 2023. It is now read-only.

Commit bd7b667

Browse files
committed
Update FPS range on Android to have correct brightness
1 parent 3ee1437 commit bd7b667

File tree

3 files changed

+46
-4
lines changed

3 files changed

+46
-4
lines changed

packages/camera/camera/CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
## 0.6.4+2
2+
3+
* Detect if selected camera supports auto focus and act accordingly on Android. This solves a problem where front facing cameras are not capturing the picture because auto focus is not supported.
4+
15
## 0.6.4+1
26

37
* Added closeCaptureSession() to stopVideoRecording in Camera.java to fix an Android 6 crash

packages/camera/camera/android/src/main/java/io/flutter/plugins/camera/Camera.java

Lines changed: 41 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@
3333
import android.os.Build.VERSION_CODES;
3434
import android.os.Handler;
3535
import android.os.Looper;
36+
import android.util.Log;
3637
import android.util.Range;
3738
import android.util.Rational;
3839
import android.util.Size;
@@ -96,6 +97,7 @@ public class Camera {
9697
private CameraRegions cameraRegions;
9798
private int exposureOffset;
9899
private boolean useAutoFocus;
100+
private Range<Integer> fpsRange;
99101

100102
public Camera(
101103
final Activity activity,
@@ -131,6 +133,7 @@ public void onOrientationChanged(int i) {
131133
orientationEventListener.enable();
132134

133135
cameraCharacteristics = cameraManager.getCameraCharacteristics(cameraName);
136+
initFps(cameraCharacteristics);
134137
sensorOrientation = cameraCharacteristics.get(CameraCharacteristics.SENSOR_ORIENTATION);
135138
isFrontFacing =
136139
cameraCharacteristics.get(CameraCharacteristics.LENS_FACING) == CameraMetadata.LENS_FACING_FRONT;
@@ -145,6 +148,26 @@ public void onOrientationChanged(int i) {
145148
cameraCharacteristics.get(CameraCharacteristics.SCALER_AVAILABLE_MAX_DIGITAL_ZOOM));
146149
}
147150

151+
private void initFps(CameraCharacteristics cameraCharacteristics){
152+
try {
153+
Range<Integer>[] ranges = cameraCharacteristics.get(CameraCharacteristics.CONTROL_AE_AVAILABLE_TARGET_FPS_RANGES);
154+
if(ranges != null) {
155+
for (Range<Integer> range : ranges) {
156+
int upper = range.getUpper();
157+
Log.i("Camera", "[FPS Range Available] is:" + range);
158+
if (upper >= 10) {
159+
if (fpsRange == null || upper < fpsRange.getUpper()) {
160+
fpsRange = range;
161+
}
162+
}
163+
}
164+
}
165+
} catch (Exception e) {
166+
e.printStackTrace();
167+
}
168+
Log.i("Camera", "[FPS Range] is:" + fpsRange);
169+
}
170+
148171
private void prepareMediaRecorder(String outputFilePath) throws IOException {
149172
if (mediaRecorder != null) {
150173
mediaRecorder.release();
@@ -268,9 +291,10 @@ public void onConfigured(@NonNull CameraCaptureSession session) {
268291
}
269292
cameraCaptureSession = session;
270293

294+
updateFpsRange();
271295
updateAutoFocus();
272-
updateExposure(exposureMode);
273296
updateFlash(flashMode);
297+
updateExposure(exposureMode);
274298

275299
refreshPreviewCaptureSession(
276300
onSuccessCallback,
@@ -589,8 +613,14 @@ public void stopVideoRecording(@NonNull final Result result) {
589613

590614
try {
591615
recordingVideo = false;
592-
closeCaptureSession();
593-
mediaRecorder.stop();
616+
617+
try {
618+
cameraCaptureSession.abortCaptures();
619+
mediaRecorder.stop();
620+
} catch (CameraAccessException | IllegalStateException e) {
621+
// Ignore exceptions and try to continue (changes are camera session already aborted capture)
622+
}
623+
594624
mediaRecorder.reset();
595625
startPreview();
596626
result.success(videoRecordingFile.getAbsolutePath());
@@ -865,6 +895,14 @@ public void setZoomLevel(@NonNull final Result result, float zoom) throws Camera
865895
result.success(null);
866896
}
867897

898+
private void updateFpsRange() {
899+
if (fpsRange == null) {
900+
return;
901+
}
902+
903+
captureRequestBuilder.set(CaptureRequest.CONTROL_AE_TARGET_FPS_RANGE, fpsRange);
904+
}
905+
868906
private void updateAutoFocus() {
869907
if (useAutoFocus) {
870908
int[] modes = cameraCharacteristics.get(

packages/camera/camera/pubspec.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ name: camera
22
description: A Flutter plugin for getting information about and controlling the
33
camera on Android and iOS. Supports previewing the camera feed, capturing images, capturing video,
44
and streaming image buffers to dart.
5-
version: 0.6.4+1
5+
version: 0.6.4+2
66
homepage: https://github.com/flutter/plugins/tree/master/packages/camera/camera
77

88
dependencies:

0 commit comments

Comments
 (0)