Skip to content

[Camera] Add lens type information (iOS) #7653

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 24 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
ef3a2fd
add lens type info to camera plugin [ios-only]
lenzpaul Apr 1, 2025
3cfb74c
run pigeon generator
lenzpaul Apr 1, 2025
944eb04
Update tests
lenzpaul Apr 1, 2025
62323ed
updated versions and Changelogs
lenzpaul Apr 1, 2025
e79e957
adds dependency_overrides for federated plugin PR
lenzpaul Apr 1, 2025
6ae7c00
Add lens type information to camera plugin tests
lenzpaul Apr 1, 2025
ca60496
Add iOS version checks ensuring API availability for camera device types
lenzpaul Apr 1, 2025
e3bbf15
Apply formatting fixes
lenzpaul Apr 1, 2025
1fc8b22
created helper function for lens direction and type
lenzpaul Apr 1, 2025
a696017
Change lens type enum to only use UltraWide, Wide, and Telephoto
lenzpaul Apr 1, 2025
c138373
run pigeon gen and applied flutter_plugin_tools.dart formatting
lenzpaul Apr 1, 2025
83f62da
Update CHANGELOG and Fix CI errors
lenzpaul Apr 1, 2025
d90b0cf
Fix formatting for CI
lenzpaul Apr 1, 2025
85c0dc2
Refactor camera lens direction and type handling in CameraPlugin
lenzpaul Apr 1, 2025
a6c9bb6
Fix documentation for camera lens type descriptions in messages.dart …
lenzpaul Apr 1, 2025
8348554
run format script
lenzpaul Apr 1, 2025
5a69630
Remove unnecessary pubspec changes
lenzpaul Apr 1, 2025
2b797f6
Update camera_platform_interface to 2.9.0 and other minor changes
lenzpaul Apr 1, 2025
4b9335c
Bump camera_platform_interface to 2.10.0 and remove its dependency ov…
lenzpaul Apr 1, 2025
cdf2014
run pigeon generator
lenzpaul Apr 1, 2025
48959c5
Ran formatting script
lenzpaul Apr 1, 2025
a2ed93a
Fix CI issues
lenzpaul Apr 3, 2025
770657a
Fix CI issue: Remove Package.resolved file from iOS example project
lenzpaul Apr 3, 2025
17240e4
Bump version to 0.11.2 and update camera_avfoundation dependency to ^…
lenzpaul Apr 3, 2025
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
4 changes: 4 additions & 0 deletions packages/camera/camera/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
## 0.11.2

* Updates `camera_avfoundation` dependency to ^0.9.19 to include support for querying available lens types on iOS.

## 0.11.1

* Adds API support query for image streaming.
Expand Down
5 changes: 3 additions & 2 deletions packages/camera/camera/pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ description: A Flutter plugin for controlling the camera. Supports previewing
Dart.
repository: https://github.com/flutter/packages/tree/main/packages/camera/camera
issue_tracker: https://github.com/flutter/flutter/issues?q=is%3Aissue+is%3Aopen+label%3A%22p%3A+camera%22
version: 0.11.1
version: 0.11.2

environment:
sdk: ^3.6.0
Expand All @@ -23,7 +23,7 @@ flutter:
dependencies:
camera_android_camerax: ^0.6.13
camera_avfoundation: ^0.9.18
camera_platform_interface: ^2.9.0
camera_platform_interface: ^2.10.0
camera_web: ^0.3.3
flutter:
sdk: flutter
Expand All @@ -38,3 +38,4 @@ dev_dependencies:

topics:
- camera

5 changes: 4 additions & 1 deletion packages/camera/camera/test/camera_preview_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,10 @@ class FakeController extends ValueNotifier<CameraValue>
FakeController() : super(const CameraValue.uninitialized(fakeDescription));

static const CameraDescription fakeDescription = CameraDescription(
name: '', lensDirection: CameraLensDirection.back, sensorOrientation: 0);
name: '',
lensDirection: CameraLensDirection.back,
sensorOrientation: 0,
lensType: CameraLensType.ultraWide);

@override
Future<void> dispose() async {
Expand Down
5 changes: 4 additions & 1 deletion packages/camera/camera_avfoundation/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
## 0.9.19

* Adds lensType in the PlatformCameraDescription

## 0.9.18+13

* Migrates test utils and mocks to Swift.
Expand Down Expand Up @@ -66,7 +70,6 @@
## 0.9.17+6

* Updates minimum supported SDK version to Flutter 3.22/Dart 3.4.
* Removes OCMock usage from permission tests

## 0.9.17+5

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -362,7 +362,7 @@
97C146EC1CF9000F007C117D /* Resources */,
9705A1C41CF9048500538489 /* Embed Frameworks */,
3B06AD1E1E4923F5004D2608 /* Thin Binary */,
2B62C73988DE02487EF557D4 /* [CP] Copy Pods Resources */,
9398D213E0DC7FA444659627 /* [CP] Copy Pods Resources */,
);
buildRules = (
);
Expand Down Expand Up @@ -500,6 +500,28 @@
shellScript = "diff \"${PODS_PODFILE_DIR_PATH}/Podfile.lock\" \"${PODS_ROOT}/Manifest.lock\" > /dev/null\nif [ $? != 0 ] ; then\n # print error to STDERR\n echo \"error: The sandbox is not in sync with the Podfile.lock. Run 'pod install' or update your CocoaPods installation.\" >&2\n exit 1\nfi\n# This output is used by Xcode 'outputs' to avoid re-running this script phase.\necho \"SUCCESS\" > \"${SCRIPT_OUTPUT_FILE_0}\"\n";
showEnvVarsInLog = 0;
};
9398D213E0DC7FA444659627 /* [CP] Copy Pods Resources */ = {
isa = PBXShellScriptBuildPhase;
buildActionMask = 2147483647;
files = (
);
inputPaths = (
"${PODS_ROOT}/Target Support Files/Pods-Runner/Pods-Runner-resources.sh",
"${PODS_CONFIGURATION_BUILD_DIR}/camera_avfoundation/camera_avfoundation_privacy.bundle",
"${PODS_CONFIGURATION_BUILD_DIR}/path_provider_foundation/path_provider_foundation_privacy.bundle",
"${PODS_CONFIGURATION_BUILD_DIR}/video_player_avfoundation/video_player_avfoundation_privacy.bundle",
);
name = "[CP] Copy Pods Resources";
outputPaths = (
"${TARGET_BUILD_DIR}/${UNLOCALIZED_RESOURCES_FOLDER_PATH}/camera_avfoundation_privacy.bundle",
"${TARGET_BUILD_DIR}/${UNLOCALIZED_RESOURCES_FOLDER_PATH}/path_provider_foundation_privacy.bundle",
"${TARGET_BUILD_DIR}/${UNLOCALIZED_RESOURCES_FOLDER_PATH}/video_player_avfoundation_privacy.bundle",
);
runOnlyForDeploymentPostprocessing = 0;
shellPath = /bin/sh;
shellScript = "\"${PODS_ROOT}/Target Support Files/Pods-Runner/Pods-Runner-resources.sh\"\n";
showEnvVarsInLog = 0;
};
9740EEB61CF901F6004384FC /* Run Script */ = {
isa = PBXShellScriptBuildPhase;
alwaysOutOfDate = 1;
Expand Down
2 changes: 1 addition & 1 deletion packages/camera/camera_avfoundation/example/pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ dependencies:
# The example app is bundled with the plugin so we use a path dependency on
# the parent directory to use the current plugin's version.
path: ../
camera_platform_interface: ^2.7.0
camera_platform_interface: ^2.10.0
flutter:
sdk: flutter
path_provider: ^2.0.0
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,37 @@
message:error.localizedDescription
details:error.domain];
}
static void FCPGetLensDirectionAndType(AVCaptureDevice *device,
FCPPlatformCameraLensDirection *lensDirection,
FCPPlatformCameraLensType *lensType) {
switch (device.position) {
case AVCaptureDevicePositionBack:
*lensDirection = FCPPlatformCameraLensDirectionBack;
break;
case AVCaptureDevicePositionFront:
*lensDirection = FCPPlatformCameraLensDirectionFront;
break;
case AVCaptureDevicePositionUnspecified:
*lensDirection = FCPPlatformCameraLensDirectionExternal;
break;
}

if ([device.deviceType isEqualToString:AVCaptureDeviceTypeBuiltInWideAngleCamera]) {
*lensType = FCPPlatformCameraLensTypeWide;
} else if ([device.deviceType isEqualToString:AVCaptureDeviceTypeBuiltInTelephotoCamera]) {
*lensType = FCPPlatformCameraLensTypeTelephoto;
} else if (@available(iOS 13.0, *)) {
if ([device.deviceType isEqualToString:AVCaptureDeviceTypeBuiltInUltraWideCamera]) {
*lensType = FCPPlatformCameraLensTypeUltraWide;
} else if ([device.deviceType isEqualToString:AVCaptureDeviceTypeBuiltInDualWideCamera]) {
*lensType = FCPPlatformCameraLensTypeWide;
} else {
*lensType = FCPPlatformCameraLensTypeUnknown;
}
} else {
*lensType = FCPPlatformCameraLensTypeUnknown;
}
}

@interface CameraPlugin ()
@property(readonly, nonatomic) NSObject<FlutterTextureRegistry> *registry;
Expand Down Expand Up @@ -148,21 +179,15 @@ - (void)availableCamerasWithCompletion:
position:AVCaptureDevicePositionUnspecified];
NSMutableArray<FCPPlatformCameraDescription *> *reply =
[[NSMutableArray alloc] initWithCapacity:devices.count];
for (NSObject<FLTCaptureDevice> *device in devices) {

for (AVCaptureDevice *device in devices) {
FCPPlatformCameraLensDirection lensFacing;
switch (device.position) {
case AVCaptureDevicePositionBack:
lensFacing = FCPPlatformCameraLensDirectionBack;
break;
case AVCaptureDevicePositionFront:
lensFacing = FCPPlatformCameraLensDirectionFront;
break;
case AVCaptureDevicePositionUnspecified:
lensFacing = FCPPlatformCameraLensDirectionExternal;
break;
}
FCPPlatformCameraLensType lensType;
FCPGetLensDirectionAndType(device, &lensFacing, &lensType);

[reply addObject:[FCPPlatformCameraDescription makeWithName:device.uniqueID
lensDirection:lensFacing]];
lensDirection:lensFacing
lensType:lensType]];
}
completion(reply, nil);
});
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// 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.
// Autogenerated from Pigeon (v22.4.2), do not edit directly.
// Autogenerated from Pigeon (v22.7.4), do not edit directly.
// See also: https://pub.dev/packages/pigeon

#import <Foundation/Foundation.h>
Expand All @@ -28,6 +28,23 @@ typedef NS_ENUM(NSUInteger, FCPPlatformCameraLensDirection) {
- (instancetype)initWithValue:(FCPPlatformCameraLensDirection)value;
@end

typedef NS_ENUM(NSUInteger, FCPPlatformCameraLensType) {
/// A built-in wide-angle camera device type.
FCPPlatformCameraLensTypeWide = 0,
/// A built-in camera device type with a longer focal length than a wide-angle camera.
FCPPlatformCameraLensTypeTelephoto = 1,
/// A built-in camera device type with a shorter focal length than a wide-angle camera.
FCPPlatformCameraLensTypeUltraWide = 2,
/// Unknown camera device type.
FCPPlatformCameraLensTypeUnknown = 3,
};

/// Wrapper for FCPPlatformCameraLensType to allow for nullability.
@interface FCPPlatformCameraLensTypeBox : NSObject
@property(nonatomic, assign) FCPPlatformCameraLensType value;
- (instancetype)initWithValue:(FCPPlatformCameraLensType)value;
@end

typedef NS_ENUM(NSUInteger, FCPPlatformDeviceOrientation) {
FCPPlatformDeviceOrientationPortraitUp = 0,
FCPPlatformDeviceOrientationLandscapeLeft = 1,
Expand Down Expand Up @@ -124,11 +141,14 @@ typedef NS_ENUM(NSUInteger, FCPPlatformResolutionPreset) {
/// `init` unavailable to enforce nonnull fields, see the `make` class method.
- (instancetype)init NS_UNAVAILABLE;
+ (instancetype)makeWithName:(NSString *)name
lensDirection:(FCPPlatformCameraLensDirection)lensDirection;
lensDirection:(FCPPlatformCameraLensDirection)lensDirection
lensType:(FCPPlatformCameraLensType)lensType;
/// The name of the camera device.
@property(nonatomic, copy) NSString *name;
/// The direction the camera is facing.
@property(nonatomic, assign) FCPPlatformCameraLensDirection lensDirection;
/// The type of the camera lens.
@property(nonatomic, assign) FCPPlatformCameraLensType lensType;
@end

@interface FCPPlatformCameraState : NSObject
Expand Down
Loading