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

[camera]Nickcullen darkcamera fix #1035

Closed
Closed
Changes from 2 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 @@ -26,6 +26,7 @@
import android.os.Bundle;
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import android.util.Range;
import android.util.Size;
import android.view.Display;
import android.view.OrientationEventListener;
Expand All @@ -38,6 +39,7 @@
import io.flutter.plugin.common.PluginRegistry;
import io.flutter.plugin.common.PluginRegistry.Registrar;
import io.flutter.view.FlutterView;

import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
Expand Down Expand Up @@ -289,6 +291,7 @@ private class Camera {
private Size videoSize;
private MediaRecorder mediaRecorder;
private boolean recordingVideo;
private Range<Integer> aeFPSRange;

Camera(final String cameraName, final String resolutionPreset, @NonNull final Result result) {

Expand Down Expand Up @@ -322,6 +325,8 @@ private class Camera {
isFrontFacing =
characteristics.get(CameraCharacteristics.LENS_FACING)
== CameraMetadata.LENS_FACING_FRONT;

setBestAERange(characteristics);
computeBestCaptureSize(streamConfigurationMap);
computeBestPreviewAndRecordingSize(streamConfigurationMap, minPreviewSize, captureSize);

Expand Down Expand Up @@ -395,6 +400,14 @@ private boolean hasAudioPermission() {
== PackageManager.PERMISSION_GRANTED;
}

private void setBestAERange(CameraCharacteristics characteristics) {
Range<Integer>[] fpsRanges = characteristics.get(CameraCharacteristics.CONTROL_AE_AVAILABLE_TARGET_FPS_RANGES);

if(fpsRanges.length > 0) {
aeFPSRange = fpsRanges[0];
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What makes the first returned range the "best"?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is the slowest FPS off the list, and from what I recall when attempting to fix this issue in my app was that the slowest FPS = better auto exposure result of the preview image. That and the fact that the stock camera app on the device is the same FPS I followed suit.

The range values can come in two different varieties:

  • (x,x) Where the FPS ranges are the same (I get 3 of these in that list on my device (7,7), (14,14) and (30,30))
  • (x, y) Where there is an allowed leeway for the FPS. But from what I recall when trying to fix this issue in my own project led to sporadic behaviour such as the preview image flicking between dark / normal exposure.

I can take a look again tonight and see if including one of the (x,y) ranges that has the largest range between the x and y component to see if this would produce a better overall frame-rate of the preview but all the while keeping the resulting auto exposure values sane?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I forgot to add, on newer/high end devices, the first value off that list of ranges is actually quite high. For example, I tested my app on my sisters Huawei p20 pro and the frame-rate was smooth and great exposure settings.

5 other people beta tested my app for Android and none of whom queried slow performance of the camera preview / dark images.

Granted this isn't a huge pool of people, but it does indicate that I improved my in app camera a lot this way.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey @NickCullen i have tried your code it solved the problem but when the camera start recording the screen zoom in and become dark again and after the recording is done it zoom outs and become light again. And the file also saved as dark recorded. Please help me out here.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi @jatinmadaan8 I made a comment a few minutes ago HERE about using continuous picture mode to use AE and AF settings from the preview. Could you give that a try?

As a side note though I notice you are talking about video here, I have no experience with the video side of things I'm afraid, I can only hope that this will resolve your issue.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hello @NickCullen i tried it today still no progress. I don't know for no reason when the recording starts it gets zoom and dark.

}
}

private void computeBestPreviewAndRecordingSize(
StreamConfigurationMap streamConfigurationMap, Size minPreviewSize, Size captureSize) {
Size[] sizes = streamConfigurationMap.getOutputSizes(SurfaceTexture.class);
Expand Down Expand Up @@ -738,8 +751,15 @@ public void onConfigured(@NonNull CameraCaptureSession session) {
}
try {
cameraCaptureSession = session;

captureRequestBuilder.set(
CaptureRequest.CONTROL_MODE, CameraMetadata.CONTROL_MODE_AUTO);

if(Camera.this.aeFPSRange != null) {
captureRequestBuilder.set(
CaptureRequest.CONTROL_AE_TARGET_FPS_RANGE, Camera.this.aeFPSRange);
}

cameraCaptureSession.setRepeatingRequest(captureRequestBuilder.build(), null, null);
} catch (CameraAccessException e) {
sendErrorEvent(e.getMessage());
Expand Down