This repository was archived by the owner on Feb 22, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 9.8k
[camera] android-rework part 8: Supporting modules for final implementation #4054
Merged
fluttergithubbot
merged 59 commits into
flutter:master
from
Baseflow:camera-android/supporting_functionality
Jul 8, 2021
Merged
Changes from all commits
Commits
Show all changes
59 commits
Select commit
Hold shift + click to select a range
2b7aa9b
Base classes to support Android camera features
mvanbeusekom f780742
Fixed formatting
mvanbeusekom 76bc5bd
Applied feedback from PR
mvanbeusekom 0bbed99
Added Android FPS range, resolution and sensor orientation features
mvanbeusekom 1ba738d
Use mockito-inline
mvanbeusekom de4e70f
Merge remote-tracking branch 'upstream/master' into camera-android/fp…
mvanbeusekom 728346a
Fix issue Pixel 4A
mvanbeusekom c014fe3
Merge remote-tracking branch 'upstream/master' into camera-android/fp…
mvanbeusekom 84f5e73
Added API documentation
mvanbeusekom f763f77
Processed feedback on PR
mvanbeusekom 4a7c73a
Fix formatting
mvanbeusekom a890919
Fix formatting
mvanbeusekom f60a0d3
Merge remote-tracking branch 'upstream/master'
BeMacized 55a6702
Only exclude 60 FPS limit for Pixel 4a
mvanbeusekom cd53321
Removed redundant empty line
mvanbeusekom 35831d3
Fixed comment
mvanbeusekom a9f3142
Test Pixel 4a workaround
mvanbeusekom 551800e
Add tests for orientation updates
mvanbeusekom 68cbc56
Fix formatting
mvanbeusekom 1b137c2
Fix formatting
mvanbeusekom 6514a00
Added missing license header
mvanbeusekom baae5f6
Add feature classes for exposure- and focus point functionality.
BeMacized cae8a90
Merge remote-tracking branch 'upstream/master'
BeMacized 94fed08
Added noise reduction feature
BeMacized be05e67
Merge branch 'camera-android/noise_reduction_feature' into camera-and…
BeMacized a68b9fb
Merge branch 'camera-android/exposure_focus_point_features' into came…
BeMacized e5253c1
Merge remote-tracking branch 'origin/camera-android/fps_resolution_se…
BeMacized 4f169ab
Implemented PR feedback
BeMacized 3a68294
Implemented PR feedback
BeMacized 70dbbd5
Add supporting functionality for android refactor
BeMacized 8e65f33
Merge branch 'camera-android/exposure_focus_point_features' into came…
BeMacized 2c64ea2
Merge branch 'camera-android/noise_reduction_feature' into camera-and…
BeMacized ab332ee
Update packages/camera/camera/android/src/main/java/io/flutter/plugin…
BeMacized bc16dd3
Update packages/camera/camera/android/src/main/java/io/flutter/plugin…
BeMacized a85e312
Update packages/camera/camera/android/src/main/java/io/flutter/plugin…
BeMacized 84d6db2
Update packages/camera/camera/android/src/main/java/io/flutter/plugin…
BeMacized 071e879
Update packages/camera/camera/android/src/main/java/io/flutter/plugin…
BeMacized 273762b
Update packages/camera/camera/android/src/test/java/io/flutter/plugin…
BeMacized e9e9bc5
Update packages/camera/camera/android/src/test/java/io/flutter/plugin…
BeMacized 1af5437
Update packages/camera/camera/android/src/test/java/io/flutter/plugin…
BeMacized b49b743
Added documentation to DartMessenger
mvanbeusekom 5b8c0d8
Update packages/camera/camera/android/src/main/java/io/flutter/plugin…
BeMacized 62a2f21
Add missing CaptureTimeoutsWrapper documentation
BeMacized 43c0716
Update packages/camera/camera/android/src/main/java/io/flutter/plugin…
BeMacized 24c6c9a
Added documentation to the CameraCaptureCallback
mvanbeusekom fc2d78b
Merge branch 'camera-android/supporting_functionality' of github.com:…
mvanbeusekom b2536d4
Add missing documentation for ImageSaver runnable
BeMacized 1748503
Merge remote-tracking branch 'origin/camera-android/supporting_functi…
BeMacized 3118680
Update packages/camera/camera/android/src/main/java/io/flutter/plugin…
BeMacized 7dbbdce
Added documentation to the CameraFeatureFactory
mvanbeusekom 2b2bea3
Configure log tag in one place and optimised loggin
mvanbeusekom 7f0180e
Accept cameraName as String
mvanbeusekom 24af367
Format
mvanbeusekom a987711
Changes required for integrating main camera class
BeMacized 66a713d
Merge branch 'camera-android/fps_resolution_sensor_features' into cam…
BeMacized ce9df6c
Changes required for integrating main camera class
BeMacized 32cb969
Remove debug statement
BeMacized d215ac7
Merge branch 'master' into camera-android/supporting_functionality
BeMacized 914b187
Merge branch 'master' into camera-android/supporting_functionality
BeMacized File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
168 changes: 168 additions & 0 deletions
168
.../camera/camera/android/src/main/java/io/flutter/plugins/camera/CameraCaptureCallback.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,168 @@ | ||
// Copyright 2013 The Flutter Authors. All rights reserved. | ||
// Use of this source code is governed by a BSD-style license that can be | ||
// found in the LICENSE file. | ||
|
||
package io.flutter.plugins.camera; | ||
|
||
import android.hardware.camera2.CameraCaptureSession; | ||
import android.hardware.camera2.CameraCaptureSession.CaptureCallback; | ||
import android.hardware.camera2.CaptureRequest; | ||
import android.hardware.camera2.CaptureResult; | ||
import android.hardware.camera2.TotalCaptureResult; | ||
import android.util.Log; | ||
import androidx.annotation.NonNull; | ||
import io.flutter.plugins.camera.types.CaptureTimeoutsWrapper; | ||
|
||
/** | ||
* A callback object for tracking the progress of a {@link android.hardware.camera2.CaptureRequest} | ||
* submitted to the camera device. | ||
*/ | ||
class CameraCaptureCallback extends CaptureCallback { | ||
private static final String TAG = "CameraCaptureCallback"; | ||
private final CameraCaptureStateListener cameraStateListener; | ||
private CameraState cameraState; | ||
private final CaptureTimeoutsWrapper captureTimeouts; | ||
|
||
private CameraCaptureCallback( | ||
@NonNull CameraCaptureStateListener cameraStateListener, | ||
@NonNull CaptureTimeoutsWrapper captureTimeouts) { | ||
cameraState = CameraState.STATE_PREVIEW; | ||
this.cameraStateListener = cameraStateListener; | ||
this.captureTimeouts = captureTimeouts; | ||
} | ||
|
||
/** | ||
* Creates a new instance of the {@link CameraCaptureCallback} class. | ||
* | ||
* @param cameraStateListener instance which will be called when the camera state changes. | ||
* @param captureTimeouts specifying the different timeout counters that should be taken into | ||
* account. | ||
* @return a configured instance of the {@link CameraCaptureCallback} class. | ||
*/ | ||
public static CameraCaptureCallback create( | ||
@NonNull CameraCaptureStateListener cameraStateListener, | ||
@NonNull CaptureTimeoutsWrapper captureTimeouts) { | ||
return new CameraCaptureCallback(cameraStateListener, captureTimeouts); | ||
} | ||
|
||
/** | ||
* Gets the current {@link CameraState}. | ||
* | ||
* @return the current {@link CameraState}. | ||
*/ | ||
public CameraState getCameraState() { | ||
return cameraState; | ||
} | ||
|
||
/** | ||
* Sets the {@link CameraState}. | ||
* | ||
* @param state the camera is currently in. | ||
*/ | ||
public void setCameraState(@NonNull CameraState state) { | ||
cameraState = state; | ||
} | ||
|
||
private void process(CaptureResult result) { | ||
Integer aeState = result.get(CaptureResult.CONTROL_AE_STATE); | ||
Integer afState = result.get(CaptureResult.CONTROL_AF_STATE); | ||
|
||
if (cameraState != CameraState.STATE_PREVIEW) { | ||
Log.d( | ||
TAG, | ||
"CameraCaptureCallback | state: " | ||
+ cameraState | ||
+ " | afState: " | ||
+ afState | ||
+ " | aeState: " | ||
+ aeState); | ||
} | ||
|
||
switch (cameraState) { | ||
case STATE_PREVIEW: | ||
{ | ||
// We have nothing to do when the camera preview is working normally. | ||
break; | ||
} | ||
case STATE_WAITING_FOCUS: | ||
{ | ||
if (afState == null) { | ||
return; | ||
} else if (afState == CaptureResult.CONTROL_AF_STATE_FOCUSED_LOCKED | ||
|| afState == CaptureResult.CONTROL_AF_STATE_NOT_FOCUSED_LOCKED) { | ||
handleWaitingFocusState(aeState); | ||
} else if (captureTimeouts.getPreCaptureFocusing().getIsExpired()) { | ||
Log.w(TAG, "Focus timeout, moving on with capture"); | ||
handleWaitingFocusState(aeState); | ||
} | ||
|
||
break; | ||
} | ||
case STATE_WAITING_PRECAPTURE_START: | ||
{ | ||
// CONTROL_AE_STATE can be null on some devices | ||
if (aeState == null | ||
|| aeState == CaptureResult.CONTROL_AE_STATE_CONVERGED | ||
|| aeState == CaptureResult.CONTROL_AE_STATE_PRECAPTURE | ||
|| aeState == CaptureResult.CONTROL_AE_STATE_FLASH_REQUIRED) { | ||
setCameraState(CameraState.STATE_WAITING_PRECAPTURE_DONE); | ||
} else if (captureTimeouts.getPreCaptureMetering().getIsExpired()) { | ||
Log.w(TAG, "Metering timeout waiting for pre-capture to start, moving on with capture"); | ||
|
||
setCameraState(CameraState.STATE_WAITING_PRECAPTURE_DONE); | ||
} | ||
break; | ||
} | ||
case STATE_WAITING_PRECAPTURE_DONE: | ||
{ | ||
// CONTROL_AE_STATE can be null on some devices | ||
if (aeState == null || aeState != CaptureResult.CONTROL_AE_STATE_PRECAPTURE) { | ||
cameraStateListener.onConverged(); | ||
} else if (captureTimeouts.getPreCaptureMetering().getIsExpired()) { | ||
Log.w( | ||
TAG, "Metering timeout waiting for pre-capture to finish, moving on with capture"); | ||
cameraStateListener.onConverged(); | ||
} | ||
|
||
break; | ||
} | ||
} | ||
} | ||
|
||
private void handleWaitingFocusState(Integer aeState) { | ||
// CONTROL_AE_STATE can be null on some devices | ||
if (aeState == null || aeState == CaptureRequest.CONTROL_AE_STATE_CONVERGED) { | ||
cameraStateListener.onConverged(); | ||
} else { | ||
cameraStateListener.onPrecapture(); | ||
} | ||
} | ||
|
||
@Override | ||
public void onCaptureProgressed( | ||
@NonNull CameraCaptureSession session, | ||
@NonNull CaptureRequest request, | ||
@NonNull CaptureResult partialResult) { | ||
process(partialResult); | ||
} | ||
|
||
@Override | ||
public void onCaptureCompleted( | ||
@NonNull CameraCaptureSession session, | ||
@NonNull CaptureRequest request, | ||
@NonNull TotalCaptureResult result) { | ||
process(result); | ||
} | ||
|
||
/** An interface that describes the different state changes implementers can be informed about. */ | ||
interface CameraCaptureStateListener { | ||
|
||
/** Called when the {@link android.hardware.camera2.CaptureRequest} has been converged. */ | ||
void onConverged(); | ||
|
||
/** | ||
* Called when the {@link android.hardware.camera2.CaptureRequest} enters the pre-capture state. | ||
*/ | ||
void onPrecapture(); | ||
} | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
27 changes: 27 additions & 0 deletions
27
packages/camera/camera/android/src/main/java/io/flutter/plugins/camera/CameraState.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
// Copyright 2013 The Flutter Authors. All rights reserved. | ||
// Use of this source code is governed by a BSD-style license that can be | ||
// found in the LICENSE file. | ||
|
||
package io.flutter.plugins.camera; | ||
|
||
/** | ||
* These are the states that the camera can be in. The camera can only take one photo at a time so | ||
* this state describes the state of the camera itself. The camera works like a pipeline where we | ||
* feed it requests through. It can only process one tasks at a time. | ||
*/ | ||
public enum CameraState { | ||
/** Idle, showing preview and not capturing anything. */ | ||
STATE_PREVIEW, | ||
|
||
/** Starting and waiting for autofocus to complete. */ | ||
STATE_WAITING_FOCUS, | ||
|
||
/** Start performing autoexposure. */ | ||
STATE_WAITING_PRECAPTURE_START, | ||
|
||
/** waiting for autoexposure to complete. */ | ||
STATE_WAITING_PRECAPTURE_DONE, | ||
|
||
/** Capturing an image. */ | ||
STATE_CAPTURING, | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.