Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
32 commits
Select commit Hold shift + click to select a range
b915f7d
Locked hacking
camsim99 Feb 20, 2024
0b33c78
This works but may need to swap in/out af points. I will see
camsim99 Feb 21, 2024
03b2095
Merge remote-tracking branch 'upstream/main' into camx_fmode
camsim99 Feb 21, 2024
f1bdb1f
Formatting
camsim99 Feb 21, 2024
bd1f1ba
Undo incorrect test changes
camsim99 Feb 21, 2024
24dd03b
Undo more changes
camsim99 Feb 21, 2024
f73c2fb
Add disableAutoCancel param + leave todos for case handling
camsim99 Feb 21, 2024
d4d1588
Formatting
camsim99 Feb 21, 2024
dd4f6b3
Add case logic
camsim99 Feb 22, 2024
b902c04
Add todo for AWB
camsim99 Feb 22, 2024
81a5170
Merge remote-tracking branch 'upstream/main' into camx_fmode
camsim99 Feb 22, 2024
72d2d5f
Manual testing
camsim99 Feb 26, 2024
32118bc
Self review
camsim99 Feb 26, 2024
da114ab
Start adding tests
camsim99 Feb 27, 2024
2965929
Add more tests
camsim99 Feb 27, 2024
861ae64
Adding more tests
camsim99 Feb 27, 2024
211962d
Merge remote-tracking branch 'upstream/main' into camx_fmode
camsim99 Feb 27, 2024
23d23ed
Finish adding tests
camsim99 Feb 27, 2024
49392ae
Self review 2
camsim99 Feb 27, 2024
faa61c5
Java fixes
camsim99 Feb 27, 2024
d025a79
Nits
camsim99 Feb 27, 2024
f8d1a6d
Add scott warning
camsim99 Feb 27, 2024
d4b4998
Merge remote-tracking branch 'upstream/main' into camx_fmode
camsim99 Feb 27, 2024
7b2fb39
Address part of review + bump version to 0.6.0
camsim99 Mar 6, 2024
7ff3bc6
Use results
camsim99 Mar 8, 2024
81d0453
Add todo fix resetting mode
camsim99 Mar 11, 2024
1ec2045
Final fixes
camsim99 Mar 11, 2024
92123c3
Fix tests
camsim99 Mar 11, 2024
94622d0
Merge remote-tracking branch 'upstream/main' into camx_fmode
camsim99 Mar 11, 2024
b3d72cb
Add additional tests
camsim99 Mar 11, 2024
54e8fd3
Avoid breaking readme
camsim99 Mar 18, 2024
9568190
Update packages/camera/camera_android_camerax/CHANGELOG.md
camsim99 Mar 19, 2024
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
Prev Previous commit
Next Next commit
Use results
  • Loading branch information
camsim99 committed Mar 8, 2024
commit 7ff3bc6c491d04a8d457b582f7443acac942936a
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ import 'device_orientation_manager.dart';
import 'exposure_state.dart';
import 'fallback_strategy.dart';
import 'focus_metering_action.dart';
import 'focus_metering_result.dart';
import 'image_analysis.dart';
import 'image_capture.dart';
import 'image_proxy.dart';
Expand Down Expand Up @@ -517,6 +518,8 @@ class AndroidCameraCameraX extends CameraPlatform {
/// * Locked focus mode is unset by setting [FocusMode.auto].
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This maps to camera_android's behavior.

@override
Future<void> setFocusMode(int cameraId, FocusMode mode) async {
MeteringPoint? autoFocusPoint;
bool? disableAutoCancel;
switch (mode) {
case FocusMode.auto:
if (_currentFocusMode == FocusMode.auto) {
Expand All @@ -527,7 +530,7 @@ class AndroidCameraCameraX extends CameraPlatform {

// Determine auto-focus point to restore, if any. We do not restore
// default auto-focus point if set previously to lock focus.
final MeteringPoint? autoFocusPoint = _defaultFocusPointLocked
final MeteringPoint? unLockedFocusPoint = _defaultFocusPointLocked
? null
: currentFocusMeteringAction!.meteringPointInfos
.where(((MeteringPoint, int?) meteringPointInfo) =>
Expand All @@ -536,10 +539,8 @@ class AndroidCameraCameraX extends CameraPlatform {
.first
.$1;
_defaultFocusPointLocked = false;

await _startFocusAndMeteringFor(
meteringPoint: autoFocusPoint,
meteringMode: FocusMeteringAction.flagAf);
autoFocusPoint = unLockedFocusPoint;
disableAutoCancel = false;
case FocusMode.locked:
MeteringPoint? lockedFocusPoint;

Expand All @@ -562,11 +563,20 @@ class AndroidCameraCameraX extends CameraPlatform {
_defaultFocusPointLocked = true;
}

await _startFocusAndMeteringFor(
meteringPoint: lockedFocusPoint,
meteringMode: FocusMeteringAction.flagAf,
disableAutoCancel: true);
autoFocusPoint = lockedFocusPoint;
disableAutoCancel = true;
}
// Start appropriate focus and metering action.
final bool focusAndMeteringWasSuccessful = await _startFocusAndMeteringFor(
meteringPoint: autoFocusPoint,
meteringMode: FocusMeteringAction.flagAf,
disableAutoCancel: disableAutoCancel);

if (!focusAndMeteringWasSuccessful) {
// Do not update current focus mode.
return;
}

// Update current focus mode.
_currentFocusMode = mode;
Copy link
Member

Choose a reason for hiding this comment

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

Just to check my understanding, if we call this method setFocusMode with FocusMode.locked, and then we get an OperationCancelledException in the java code, do we currently still update the _currentFocusMode here to locked, even though it isn't set?

I know we return a success value of null, and then add an 'error' to the cameraErrorStreamController, but I don't know what the exact consequence of doing that are and if it would prevent us getting into a state here where _currentFocusMode doesn't align with the current actual focus mode.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ah this is a good catch--thank you! I actually need to utilize the FocusMeteringResult here to make sure we don't get out of sync in cases like this.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Changed this logic to depend on the result of the FocusMeteringResult and added tests to make sure that the current focus mode doesn't update when the call failed (tested by making calls to setFocusPoint/setExposurePoint to see if auto-canceled was enabled/disabled as we'd expect).


Expand Down Expand Up @@ -1200,11 +1210,11 @@ class AndroidCameraCameraX extends CameraPlatform {

// Methods for configuring auto-focus and auto-exposure:

Future<void> _startFocusAndMeteringForPoint(
Future<bool> _startFocusAndMeteringForPoint(
{required Point<double>? point,
required int meteringMode,
bool disableAutoCancel = false}) async {
await _startFocusAndMeteringFor(
return _startFocusAndMeteringFor(
meteringPoint: point == null
? null
: proxy.createMeteringPoint(
Expand All @@ -1213,7 +1223,8 @@ class AndroidCameraCameraX extends CameraPlatform {
disableAutoCancel: disableAutoCancel);
}

/// Starts a focus and metering action.
/// Starts a focus and metering action and returns whether or not it was
/// successful.
///
/// This method will modify and start the current action's [MeteringPoint]s
/// overriden with the [meteringPoint] provided for the specified
Expand All @@ -1233,7 +1244,7 @@ class AndroidCameraCameraX extends CameraPlatform {
/// to [currentFocusMeteringAction] that do not share a metering mode with
/// [meteringPoint]. If [meteringPoint] and [currentFocusMeteringAction] are
/// null, then focus and metering will be canceled.
Future<void> _startFocusAndMeteringFor(
Future<bool> _startFocusAndMeteringFor(
{required MeteringPoint? meteringPoint,
required int meteringMode,
bool disableAutoCancel = false}) async {
Expand All @@ -1243,7 +1254,7 @@ class AndroidCameraCameraX extends CameraPlatform {
if (currentFocusMeteringAction == null) {
// Attempting to clear a metering point from a previous action, but no
// such action exists.
return;
return false;
}

// Remove metering point with specified meteringMode from current focus
Expand All @@ -1264,7 +1275,7 @@ class AndroidCameraCameraX extends CameraPlatform {
// started focus and metering actions.
await cameraControl.cancelFocusAndMetering();
currentFocusMeteringAction = null;
return;
return true;
}
currentFocusMeteringAction = proxy.createFocusMeteringAction(
newMeteringPointInfos, disableAutoCancel);
Expand Down Expand Up @@ -1296,6 +1307,8 @@ class AndroidCameraCameraX extends CameraPlatform {
newMeteringPointInfos, disableAutoCancel);
}

await cameraControl.startFocusAndMetering(currentFocusMeteringAction!);
final FocusMeteringResult? result =
await cameraControl.startFocusAndMetering(currentFocusMeteringAction!);
return await result?.isFocusSuccessful() ?? false;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,9 @@ class _CameraControlHostApiImpl extends CameraControlHostApi {
} on PlatformException catch (e) {
SystemServices.cameraErrorStreamController
.add(e.message ?? 'Starting focus and metering failed.');
return Future<FocusMeteringResult?>.value();
// Surfacing error to differentiate an operation cancellation from an
// illegal argument exception at a plugin layer.
rethrow;
}
}

Expand Down