diff --git a/packages/camera/camera/test/camera_preview_test.dart b/packages/camera/camera/test/camera_preview_test.dart index 139c5534124..be672d1bbb2 100644 --- a/packages/camera/camera/test/camera_preview_test.dart +++ b/packages/camera/camera/test/camera_preview_test.dart @@ -18,6 +18,7 @@ class FakeController extends ValueNotifier name: '', lensDirection: CameraLensDirection.back, sensorOrientation: 0, + lensType: CameraLensType.ultraWide, ); @override diff --git a/packages/camera/camera_avfoundation/CHANGELOG.md b/packages/camera/camera_avfoundation/CHANGELOG.md index 797d053b5e2..e0db258bb56 100644 --- a/packages/camera/camera_avfoundation/CHANGELOG.md +++ b/packages/camera/camera_avfoundation/CHANGELOG.md @@ -1,3 +1,7 @@ +## 0.9.22 + +* Adds lensType in the PlatformCameraDescription + ## 0.9.21+4 * Migrates `updateOrientation` and `setCaptureSessionPreset` methods to Swift. diff --git a/packages/camera/camera_avfoundation/example/ios/RunnerTests/Mocks/MockCaptureDevice.swift b/packages/camera/camera_avfoundation/example/ios/RunnerTests/Mocks/MockCaptureDevice.swift index b294b1e3e1c..64ab36e43e0 100644 --- a/packages/camera/camera_avfoundation/example/ios/RunnerTests/Mocks/MockCaptureDevice.swift +++ b/packages/camera/camera_avfoundation/example/ios/RunnerTests/Mocks/MockCaptureDevice.swift @@ -32,6 +32,7 @@ class MockCaptureDevice: NSObject, FLTCaptureDevice { var uniqueID = "" var position = AVCaptureDevice.Position.unspecified + var deviceType = AVCaptureDevice.DeviceType.builtInWideAngleCamera var activeFormat: FLTCaptureDeviceFormat { get { diff --git a/packages/camera/camera_avfoundation/example/pubspec.yaml b/packages/camera/camera_avfoundation/example/pubspec.yaml index 7aa5ff10832..4b9a5b5a5e5 100644 --- a/packages/camera/camera_avfoundation/example/pubspec.yaml +++ b/packages/camera/camera_avfoundation/example/pubspec.yaml @@ -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 diff --git a/packages/camera/camera_avfoundation/ios/camera_avfoundation/Sources/camera_avfoundation/CameraPlugin.swift b/packages/camera/camera_avfoundation/ios/camera_avfoundation/Sources/camera_avfoundation/CameraPlugin.swift index a6029e5436c..9f9fc7b3f3d 100644 --- a/packages/camera/camera_avfoundation/ios/camera_avfoundation/Sources/camera_avfoundation/CameraPlugin.swift +++ b/packages/camera/camera_avfoundation/ios/camera_avfoundation/Sources/camera_avfoundation/CameraPlugin.swift @@ -145,22 +145,12 @@ extension CameraPlugin: FCPCameraApi { var reply: [FCPPlatformCameraDescription] = [] for device in devices { - var lensFacing: FCPPlatformCameraLensDirection - - switch device.position { - case .back: - lensFacing = .back - case .front: - lensFacing = .front - case .unspecified: - lensFacing = .external - @unknown default: - lensFacing = .external - } - + let lensFacing = strongSelf.platformLensDirection(for: device) + let lensType = strongSelf.platformLensType(for: device) let cameraDescription = FCPPlatformCameraDescription.make( withName: device.uniqueID, - lensDirection: lensFacing + lensDirection: lensFacing, + lensType: lensType ) reply.append(cameraDescription) } @@ -169,6 +159,35 @@ extension CameraPlugin: FCPCameraApi { } } + private func platformLensDirection(for device: FLTCaptureDevice) -> FCPPlatformCameraLensDirection + { + switch device.position { + case .back: + return .back + case .front: + return .front + case .unspecified: + return .external + @unknown default: + return .external + } + } + + private func platformLensType(for device: FLTCaptureDevice) -> FCPPlatformCameraLensType { + switch device.deviceType { + case .builtInWideAngleCamera: + return .wide + case .builtInTelephotoCamera: + return .telephoto + case .builtInUltraWideCamera: + return .ultraWide + case .builtInDualWideCamera: + return .wide + default: + return .unknown + } + } + public func createCamera( withName cameraName: String, settings: FCPPlatformMediaSettings, diff --git a/packages/camera/camera_avfoundation/ios/camera_avfoundation/Sources/camera_avfoundation_objc/FLTCaptureDevice.m b/packages/camera/camera_avfoundation/ios/camera_avfoundation/Sources/camera_avfoundation_objc/FLTCaptureDevice.m index 68f486f91f4..35ccd9790bb 100644 --- a/packages/camera/camera_avfoundation/ios/camera_avfoundation/Sources/camera_avfoundation_objc/FLTCaptureDevice.m +++ b/packages/camera/camera_avfoundation/ios/camera_avfoundation/Sources/camera_avfoundation_objc/FLTCaptureDevice.m @@ -30,6 +30,10 @@ - (AVCaptureDevicePosition)position { return self.device.position; } +- (AVCaptureDeviceType)deviceType { + return self.device.deviceType; +} + // Format/Configuration - (NSObject *)activeFormat { return [[FLTDefaultCaptureDeviceFormat alloc] initWithFormat:self.device.activeFormat]; diff --git a/packages/camera/camera_avfoundation/ios/camera_avfoundation/Sources/camera_avfoundation_objc/include/camera_avfoundation/FLTCaptureDevice.h b/packages/camera/camera_avfoundation/ios/camera_avfoundation/Sources/camera_avfoundation_objc/include/camera_avfoundation/FLTCaptureDevice.h index 3244e70fc73..0d18df9ed9c 100644 --- a/packages/camera/camera_avfoundation/ios/camera_avfoundation/Sources/camera_avfoundation_objc/include/camera_avfoundation/FLTCaptureDevice.h +++ b/packages/camera/camera_avfoundation/ios/camera_avfoundation/Sources/camera_avfoundation_objc/include/camera_avfoundation/FLTCaptureDevice.h @@ -24,6 +24,9 @@ NS_ASSUME_NONNULL_BEGIN // Position/Orientation @property(nonatomic, readonly) AVCaptureDevicePosition position; +// Lens type +@property(nonatomic, readonly) AVCaptureDeviceType deviceType; + // Format/Configuration @property(nonatomic, retain) NSObject *activeFormat; @property(nonatomic, readonly) NSArray *> *formats; diff --git a/packages/camera/camera_avfoundation/ios/camera_avfoundation/Sources/camera_avfoundation_objc/include/camera_avfoundation/messages.g.h b/packages/camera/camera_avfoundation/ios/camera_avfoundation/Sources/camera_avfoundation_objc/include/camera_avfoundation/messages.g.h index 23e4fb77246..782d3df866f 100644 --- a/packages/camera/camera_avfoundation/ios/camera_avfoundation/Sources/camera_avfoundation_objc/include/camera_avfoundation/messages.g.h +++ b/packages/camera/camera_avfoundation/ios/camera_avfoundation/Sources/camera_avfoundation_objc/include/camera_avfoundation/messages.g.h @@ -1,7 +1,7 @@ // Copyright 2013 The Flutter Authors // 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 @@ -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, @@ -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 diff --git a/packages/camera/camera_avfoundation/ios/camera_avfoundation/Sources/camera_avfoundation_objc/messages.g.m b/packages/camera/camera_avfoundation/ios/camera_avfoundation/Sources/camera_avfoundation_objc/messages.g.m index f0543adc6c4..0a86f9e9f96 100644 --- a/packages/camera/camera_avfoundation/ios/camera_avfoundation/Sources/camera_avfoundation_objc/messages.g.m +++ b/packages/camera/camera_avfoundation/ios/camera_avfoundation/Sources/camera_avfoundation_objc/messages.g.m @@ -1,7 +1,7 @@ // Copyright 2013 The Flutter Authors // 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 "./include/camera_avfoundation/messages.g.h" @@ -49,6 +49,16 @@ - (instancetype)initWithValue:(FCPPlatformCameraLensDirection)value { } @end +@implementation FCPPlatformCameraLensTypeBox +- (instancetype)initWithValue:(FCPPlatformCameraLensType)value { + self = [super init]; + if (self) { + _value = value; + } + return self; +} +@end + @implementation FCPPlatformDeviceOrientationBox - (instancetype)initWithValue:(FCPPlatformDeviceOrientation)value { self = [super init]; @@ -152,10 +162,12 @@ + (nullable FCPPlatformSize *)nullableFromList:(NSArray *)list; @implementation FCPPlatformCameraDescription + (instancetype)makeWithName:(NSString *)name - lensDirection:(FCPPlatformCameraLensDirection)lensDirection { + lensDirection:(FCPPlatformCameraLensDirection)lensDirection + lensType:(FCPPlatformCameraLensType)lensType { FCPPlatformCameraDescription *pigeonResult = [[FCPPlatformCameraDescription alloc] init]; pigeonResult.name = name; pigeonResult.lensDirection = lensDirection; + pigeonResult.lensType = lensType; return pigeonResult; } + (FCPPlatformCameraDescription *)fromList:(NSArray *)list { @@ -164,6 +176,8 @@ + (FCPPlatformCameraDescription *)fromList:(NSArray *)list { FCPPlatformCameraLensDirectionBox *boxedFCPPlatformCameraLensDirection = GetNullableObjectAtIndex(list, 1); pigeonResult.lensDirection = boxedFCPPlatformCameraLensDirection.value; + FCPPlatformCameraLensTypeBox *boxedFCPPlatformCameraLensType = GetNullableObjectAtIndex(list, 2); + pigeonResult.lensType = boxedFCPPlatformCameraLensType.value; return pigeonResult; } + (nullable FCPPlatformCameraDescription *)nullableFromList:(NSArray *)list { @@ -173,6 +187,7 @@ + (nullable FCPPlatformCameraDescription *)nullableFromList:(NSArray *)list return @[ self.name ?: [NSNull null], [[FCPPlatformCameraLensDirectionBox alloc] initWithValue:self.lensDirection], + [[FCPPlatformCameraLensTypeBox alloc] initWithValue:self.lensType], ]; } @end @@ -315,56 +330,62 @@ - (nullable id)readValueOfType:(UInt8)type { initWithValue:[enumAsNumber integerValue]]; } case 130: { + NSNumber *enumAsNumber = [self readValue]; + return enumAsNumber == nil + ? nil + : [[FCPPlatformCameraLensTypeBox alloc] initWithValue:[enumAsNumber integerValue]]; + } + case 131: { NSNumber *enumAsNumber = [self readValue]; return enumAsNumber == nil ? nil : [[FCPPlatformDeviceOrientationBox alloc] initWithValue:[enumAsNumber integerValue]]; } - case 131: { + case 132: { NSNumber *enumAsNumber = [self readValue]; return enumAsNumber == nil ? nil : [[FCPPlatformExposureModeBox alloc] initWithValue:[enumAsNumber integerValue]]; } - case 132: { + case 133: { NSNumber *enumAsNumber = [self readValue]; return enumAsNumber == nil ? nil : [[FCPPlatformFlashModeBox alloc] initWithValue:[enumAsNumber integerValue]]; } - case 133: { + case 134: { NSNumber *enumAsNumber = [self readValue]; return enumAsNumber == nil ? nil : [[FCPPlatformFocusModeBox alloc] initWithValue:[enumAsNumber integerValue]]; } - case 134: { + case 135: { NSNumber *enumAsNumber = [self readValue]; return enumAsNumber == nil ? nil : [[FCPPlatformImageFileFormatBox alloc] initWithValue:[enumAsNumber integerValue]]; } - case 135: { + case 136: { NSNumber *enumAsNumber = [self readValue]; return enumAsNumber == nil ? nil : [[FCPPlatformImageFormatGroupBox alloc] initWithValue:[enumAsNumber integerValue]]; } - case 136: { + case 137: { NSNumber *enumAsNumber = [self readValue]; return enumAsNumber == nil ? nil : [[FCPPlatformResolutionPresetBox alloc] initWithValue:[enumAsNumber integerValue]]; } - case 137: - return [FCPPlatformCameraDescription fromList:[self readValue]]; case 138: - return [FCPPlatformCameraState fromList:[self readValue]]; + return [FCPPlatformCameraDescription fromList:[self readValue]]; case 139: - return [FCPPlatformMediaSettings fromList:[self readValue]]; + return [FCPPlatformCameraState fromList:[self readValue]]; case 140: - return [FCPPlatformPoint fromList:[self readValue]]; + return [FCPPlatformMediaSettings fromList:[self readValue]]; case 141: + return [FCPPlatformPoint fromList:[self readValue]]; + case 142: return [FCPPlatformSize fromList:[self readValue]]; default: return [super readValueOfType:type]; @@ -380,48 +401,52 @@ - (void)writeValue:(id)value { FCPPlatformCameraLensDirectionBox *box = (FCPPlatformCameraLensDirectionBox *)value; [self writeByte:129]; [self writeValue:(value == nil ? [NSNull null] : [NSNumber numberWithInteger:box.value])]; + } else if ([value isKindOfClass:[FCPPlatformCameraLensTypeBox class]]) { + FCPPlatformCameraLensTypeBox *box = (FCPPlatformCameraLensTypeBox *)value; + [self writeByte:130]; + [self writeValue:(value == nil ? [NSNull null] : [NSNumber numberWithInteger:box.value])]; } else if ([value isKindOfClass:[FCPPlatformDeviceOrientationBox class]]) { FCPPlatformDeviceOrientationBox *box = (FCPPlatformDeviceOrientationBox *)value; - [self writeByte:130]; + [self writeByte:131]; [self writeValue:(value == nil ? [NSNull null] : [NSNumber numberWithInteger:box.value])]; } else if ([value isKindOfClass:[FCPPlatformExposureModeBox class]]) { FCPPlatformExposureModeBox *box = (FCPPlatformExposureModeBox *)value; - [self writeByte:131]; + [self writeByte:132]; [self writeValue:(value == nil ? [NSNull null] : [NSNumber numberWithInteger:box.value])]; } else if ([value isKindOfClass:[FCPPlatformFlashModeBox class]]) { FCPPlatformFlashModeBox *box = (FCPPlatformFlashModeBox *)value; - [self writeByte:132]; + [self writeByte:133]; [self writeValue:(value == nil ? [NSNull null] : [NSNumber numberWithInteger:box.value])]; } else if ([value isKindOfClass:[FCPPlatformFocusModeBox class]]) { FCPPlatformFocusModeBox *box = (FCPPlatformFocusModeBox *)value; - [self writeByte:133]; + [self writeByte:134]; [self writeValue:(value == nil ? [NSNull null] : [NSNumber numberWithInteger:box.value])]; } else if ([value isKindOfClass:[FCPPlatformImageFileFormatBox class]]) { FCPPlatformImageFileFormatBox *box = (FCPPlatformImageFileFormatBox *)value; - [self writeByte:134]; + [self writeByte:135]; [self writeValue:(value == nil ? [NSNull null] : [NSNumber numberWithInteger:box.value])]; } else if ([value isKindOfClass:[FCPPlatformImageFormatGroupBox class]]) { FCPPlatformImageFormatGroupBox *box = (FCPPlatformImageFormatGroupBox *)value; - [self writeByte:135]; + [self writeByte:136]; [self writeValue:(value == nil ? [NSNull null] : [NSNumber numberWithInteger:box.value])]; } else if ([value isKindOfClass:[FCPPlatformResolutionPresetBox class]]) { FCPPlatformResolutionPresetBox *box = (FCPPlatformResolutionPresetBox *)value; - [self writeByte:136]; + [self writeByte:137]; [self writeValue:(value == nil ? [NSNull null] : [NSNumber numberWithInteger:box.value])]; } else if ([value isKindOfClass:[FCPPlatformCameraDescription class]]) { - [self writeByte:137]; + [self writeByte:138]; [self writeValue:[value toList]]; } else if ([value isKindOfClass:[FCPPlatformCameraState class]]) { - [self writeByte:138]; + [self writeByte:139]; [self writeValue:[value toList]]; } else if ([value isKindOfClass:[FCPPlatformMediaSettings class]]) { - [self writeByte:139]; + [self writeByte:140]; [self writeValue:[value toList]]; } else if ([value isKindOfClass:[FCPPlatformPoint class]]) { - [self writeByte:140]; + [self writeByte:141]; [self writeValue:[value toList]]; } else if ([value isKindOfClass:[FCPPlatformSize class]]) { - [self writeByte:141]; + [self writeByte:142]; [self writeValue:[value toList]]; } else { [super writeValue:value]; diff --git a/packages/camera/camera_avfoundation/lib/src/messages.g.dart b/packages/camera/camera_avfoundation/lib/src/messages.g.dart index f771611beab..50fe099314e 100644 --- a/packages/camera/camera_avfoundation/lib/src/messages.g.dart +++ b/packages/camera/camera_avfoundation/lib/src/messages.g.dart @@ -1,7 +1,7 @@ // Copyright 2013 The Flutter Authors // 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 // ignore_for_file: public_member_api_docs, non_constant_identifier_names, avoid_as, unused_import, unnecessary_parenthesis, prefer_null_aware_operators, omit_local_variable_types, unused_shown_name, unnecessary_import, no_leading_underscores_for_local_identifiers @@ -43,6 +43,20 @@ enum PlatformCameraLensDirection { external, } +enum PlatformCameraLensType { + /// A built-in wide-angle camera device type. + wide, + + /// A built-in camera device type with a longer focal length than a wide-angle camera. + telephoto, + + /// A built-in camera device type with a shorter focal length than a wide-angle camera. + ultraWide, + + /// Unknown camera device type. + unknown, +} + enum PlatformDeviceOrientation { portraitUp, landscapeLeft, @@ -64,7 +78,11 @@ enum PlatformImageFormatGroup { bgra8888, yuv420 } enum PlatformResolutionPreset { low, medium, high, veryHigh, ultraHigh, max } class PlatformCameraDescription { - PlatformCameraDescription({required this.name, required this.lensDirection}); + PlatformCameraDescription({ + required this.name, + required this.lensDirection, + required this.lensType, + }); /// The name of the camera device. String name; @@ -72,8 +90,11 @@ class PlatformCameraDescription { /// The direction the camera is facing. PlatformCameraLensDirection lensDirection; + /// The type of the camera lens. + PlatformCameraLensType lensType; + Object encode() { - return [name, lensDirection]; + return [name, lensDirection, lensType]; } static PlatformCameraDescription decode(Object result) { @@ -81,6 +102,7 @@ class PlatformCameraDescription { return PlatformCameraDescription( name: result[0]! as String, lensDirection: result[1]! as PlatformCameraLensDirection, + lensType: result[2]! as PlatformCameraLensType, ); } } @@ -219,41 +241,44 @@ class _PigeonCodec extends StandardMessageCodec { } else if (value is PlatformCameraLensDirection) { buffer.putUint8(129); writeValue(buffer, value.index); - } else if (value is PlatformDeviceOrientation) { + } else if (value is PlatformCameraLensType) { buffer.putUint8(130); writeValue(buffer, value.index); - } else if (value is PlatformExposureMode) { + } else if (value is PlatformDeviceOrientation) { buffer.putUint8(131); writeValue(buffer, value.index); - } else if (value is PlatformFlashMode) { + } else if (value is PlatformExposureMode) { buffer.putUint8(132); writeValue(buffer, value.index); - } else if (value is PlatformFocusMode) { + } else if (value is PlatformFlashMode) { buffer.putUint8(133); writeValue(buffer, value.index); - } else if (value is PlatformImageFileFormat) { + } else if (value is PlatformFocusMode) { buffer.putUint8(134); writeValue(buffer, value.index); - } else if (value is PlatformImageFormatGroup) { + } else if (value is PlatformImageFileFormat) { buffer.putUint8(135); writeValue(buffer, value.index); - } else if (value is PlatformResolutionPreset) { + } else if (value is PlatformImageFormatGroup) { buffer.putUint8(136); writeValue(buffer, value.index); - } else if (value is PlatformCameraDescription) { + } else if (value is PlatformResolutionPreset) { buffer.putUint8(137); + writeValue(buffer, value.index); + } else if (value is PlatformCameraDescription) { + buffer.putUint8(138); writeValue(buffer, value.encode()); } else if (value is PlatformCameraState) { - buffer.putUint8(138); + buffer.putUint8(139); writeValue(buffer, value.encode()); } else if (value is PlatformMediaSettings) { - buffer.putUint8(139); + buffer.putUint8(140); writeValue(buffer, value.encode()); } else if (value is PlatformPoint) { - buffer.putUint8(140); + buffer.putUint8(141); writeValue(buffer, value.encode()); } else if (value is PlatformSize) { - buffer.putUint8(141); + buffer.putUint8(142); writeValue(buffer, value.encode()); } else { super.writeValue(buffer, value); @@ -268,34 +293,37 @@ class _PigeonCodec extends StandardMessageCodec { return value == null ? null : PlatformCameraLensDirection.values[value]; case 130: final int? value = readValue(buffer) as int?; - return value == null ? null : PlatformDeviceOrientation.values[value]; + return value == null ? null : PlatformCameraLensType.values[value]; case 131: final int? value = readValue(buffer) as int?; - return value == null ? null : PlatformExposureMode.values[value]; + return value == null ? null : PlatformDeviceOrientation.values[value]; case 132: final int? value = readValue(buffer) as int?; - return value == null ? null : PlatformFlashMode.values[value]; + return value == null ? null : PlatformExposureMode.values[value]; case 133: final int? value = readValue(buffer) as int?; - return value == null ? null : PlatformFocusMode.values[value]; + return value == null ? null : PlatformFlashMode.values[value]; case 134: final int? value = readValue(buffer) as int?; - return value == null ? null : PlatformImageFileFormat.values[value]; + return value == null ? null : PlatformFocusMode.values[value]; case 135: final int? value = readValue(buffer) as int?; - return value == null ? null : PlatformImageFormatGroup.values[value]; + return value == null ? null : PlatformImageFileFormat.values[value]; case 136: final int? value = readValue(buffer) as int?; - return value == null ? null : PlatformResolutionPreset.values[value]; + return value == null ? null : PlatformImageFormatGroup.values[value]; case 137: - return PlatformCameraDescription.decode(readValue(buffer)!); + final int? value = readValue(buffer) as int?; + return value == null ? null : PlatformResolutionPreset.values[value]; case 138: - return PlatformCameraState.decode(readValue(buffer)!); + return PlatformCameraDescription.decode(readValue(buffer)!); case 139: - return PlatformMediaSettings.decode(readValue(buffer)!); + return PlatformCameraState.decode(readValue(buffer)!); case 140: - return PlatformPoint.decode(readValue(buffer)!); + return PlatformMediaSettings.decode(readValue(buffer)!); case 141: + return PlatformPoint.decode(readValue(buffer)!); + case 142: return PlatformSize.decode(readValue(buffer)!); default: return super.readValueOfType(type, buffer); diff --git a/packages/camera/camera_avfoundation/lib/src/utils.dart b/packages/camera/camera_avfoundation/lib/src/utils.dart index 80cdc2e5e48..3308bcc6fd5 100644 --- a/packages/camera/camera_avfoundation/lib/src/utils.dart +++ b/packages/camera/camera_avfoundation/lib/src/utils.dart @@ -15,6 +15,7 @@ CameraDescription cameraDescriptionFromPlatform( name: camera.name, lensDirection: cameraLensDirectionFromPlatform(camera.lensDirection), sensorOrientation: 90, + lensType: cameraLensTypeFromPlatform(camera.lensType), ); } @@ -29,6 +30,16 @@ CameraLensDirection cameraLensDirectionFromPlatform( }; } +/// Converts a Pigeon [PlatformCameraLensType] to a [CameraLensType]. +CameraLensType cameraLensTypeFromPlatform(PlatformCameraLensType type) { + return switch (type) { + PlatformCameraLensType.wide => CameraLensType.wide, + PlatformCameraLensType.telephoto => CameraLensType.telephoto, + PlatformCameraLensType.ultraWide => CameraLensType.ultraWide, + PlatformCameraLensType.unknown => CameraLensType.unknown, + }; +} + /// Convents the given device orientation to Pigeon. PlatformDeviceOrientation serializeDeviceOrientation( DeviceOrientation orientation, diff --git a/packages/camera/camera_avfoundation/pigeons/messages.dart b/packages/camera/camera_avfoundation/pigeons/messages.dart index 4427fa28567..f4bdd8d998d 100644 --- a/packages/camera/camera_avfoundation/pigeons/messages.dart +++ b/packages/camera/camera_avfoundation/pigeons/messages.dart @@ -30,6 +30,21 @@ enum PlatformCameraLensDirection { external, } +// Pigeon version of CameraLensDirection. +enum PlatformCameraLensType { + /// A built-in wide-angle camera device type. + wide, + + /// A built-in camera device type with a longer focal length than a wide-angle camera. + telephoto, + + /// A built-in camera device type with a shorter focal length than a wide-angle camera. + ultraWide, + + /// Unknown camera device type. + unknown, +} + // Pigeon version of DeviceOrientation. enum PlatformDeviceOrientation { portraitUp, @@ -58,13 +73,20 @@ enum PlatformResolutionPreset { low, medium, high, veryHigh, ultraHigh, max } // Pigeon version of CameraDescription. class PlatformCameraDescription { - PlatformCameraDescription({required this.name, required this.lensDirection}); + PlatformCameraDescription({ + required this.name, + required this.lensDirection, + required this.lensType, + }); /// The name of the camera device. final String name; /// The direction the camera is facing. final PlatformCameraLensDirection lensDirection; + + /// The type of the camera lens. + final PlatformCameraLensType lensType; } // Pigeon version of the data needed for a CameraInitializedEvent. diff --git a/packages/camera/camera_avfoundation/pubspec.yaml b/packages/camera/camera_avfoundation/pubspec.yaml index 4603ead6659..4c8e589abf9 100644 --- a/packages/camera/camera_avfoundation/pubspec.yaml +++ b/packages/camera/camera_avfoundation/pubspec.yaml @@ -2,7 +2,7 @@ name: camera_avfoundation description: iOS implementation of the camera plugin. repository: https://github.com/flutter/packages/tree/main/packages/camera/camera_avfoundation issue_tracker: https://github.com/flutter/flutter/issues?q=is%3Aissue+is%3Aopen+label%3A%22p%3A+camera%22 -version: 0.9.21+4 +version: 0.9.22 environment: sdk: ^3.9.0 @@ -17,7 +17,7 @@ flutter: dartPluginClass: AVFoundationCamera dependencies: - camera_platform_interface: ^2.9.0 + camera_platform_interface: ^2.10.0 flutter: sdk: flutter stream_transform: ^2.0.0 diff --git a/packages/camera/camera_avfoundation/test/avfoundation_camera_test.dart b/packages/camera/camera_avfoundation/test/avfoundation_camera_test.dart index 6a504422899..ec31faf9c27 100644 --- a/packages/camera/camera_avfoundation/test/avfoundation_camera_test.dart +++ b/packages/camera/camera_avfoundation/test/avfoundation_camera_test.dart @@ -407,10 +407,12 @@ void main() { PlatformCameraDescription( name: 'Test 1', lensDirection: PlatformCameraLensDirection.front, + lensType: PlatformCameraLensType.ultraWide, ), PlatformCameraDescription( name: 'Test 2', lensDirection: PlatformCameraLensDirection.back, + lensType: PlatformCameraLensType.telephoto, ), ]; when(mockApi.getAvailableCameras()).thenAnswer((_) async => returnData); @@ -424,6 +426,10 @@ void main() { cameras[i].lensDirection, cameraLensDirectionFromPlatform(returnData[i].lensDirection), ); + expect( + cameras[i].lensType, + cameraLensTypeFromPlatform(returnData[i].lensType), + ); // This value isn't provided by the platform, so is hard-coded to 90. expect(cameras[i].sensorOrientation, 90); }