Skip to content
Draft
Show file tree
Hide file tree
Changes from all 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
4 changes: 4 additions & 0 deletions packages/camera/camera_avfoundation/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
## 0.9.21+4

* Add lensType to CameraDescription

## 0.9.21+3

* Removes code for versions of iOS older than 13.0.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,18 +38,22 @@ final class AvailableCamerasTest: XCTestCase {
let wideAngleCamera = MockCaptureDevice()
wideAngleCamera.uniqueID = "0"
wideAngleCamera.position = .back
wideAngleCamera.deviceType = .builtInWideAngleCamera

let frontFacingCamera = MockCaptureDevice()
frontFacingCamera.uniqueID = "1"
frontFacingCamera.position = .front
frontFacingCamera.deviceType = .builtInWideAngleCamera

let ultraWideCamera = MockCaptureDevice()
ultraWideCamera.uniqueID = "2"
ultraWideCamera.position = .back
ultraWideCamera.deviceType = .builtInUltraWideCamera

let telephotoCamera = MockCaptureDevice()
telephotoCamera.uniqueID = "3"
telephotoCamera.position = .back
telephotoCamera.deviceType = .builtInTelephotoCamera

var requiredTypes: [AVCaptureDevice.DeviceType] = [
.builtInWideAngleCamera, .builtInTelephotoCamera, .builtInUltraWideCamera,
Expand Down Expand Up @@ -84,10 +88,12 @@ final class AvailableCamerasTest: XCTestCase {
let wideAngleCamera = MockCaptureDevice()
wideAngleCamera.uniqueID = "0"
wideAngleCamera.position = .back
wideAngleCamera.deviceType = .builtInWideAngleCamera

let frontFacingCamera = MockCaptureDevice()
frontFacingCamera.uniqueID = "1"
frontFacingCamera.position = .front
frontFacingCamera.deviceType = .builtInWideAngleCamera

var requiredTypes: [AVCaptureDevice.DeviceType] = [
.builtInWideAngleCamera, .builtInTelephotoCamera, .builtInUltraWideCamera,
Expand Down Expand Up @@ -121,6 +127,7 @@ final class AvailableCamerasTest: XCTestCase {
let unspecifiedCamera = MockCaptureDevice()
unspecifiedCamera.uniqueID = "0"
unspecifiedCamera.position = .unspecified
unspecifiedCamera.deviceType =

Choose a reason for hiding this comment

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

critical

This line contains a syntax error and will cause a compilation failure. It seems like an incomplete assignment. To test the .unknown lens type mapping, you could assign a device type that is not explicitly handled in the CameraPlugin's switch statement, for example .builtInDualCamera.

Suggested change
unspecifiedCamera.deviceType =
unspecifiedCamera.deviceType = .builtInDualCamera


var requiredTypes: [AVCaptureDevice.DeviceType] = [
.builtInWideAngleCamera, .builtInTelephotoCamera, .builtInUltraWideCamera,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ class MockCaptureDevice: NSObject, FLTCaptureDevice {

var uniqueID = ""
var position = AVCaptureDevice.Position.unspecified
var deviceType: AVCaptureDevice.DeviceType? = nil

Choose a reason for hiding this comment

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

high

The deviceType property is declared as optional (AVCaptureDevice.DeviceType?), but the FLTCaptureDevice protocol it conforms to defines it as a non-optional property. This mismatch can lead to runtime errors. Please make it non-optional and provide a default value to align with the protocol.

Suggested change
var deviceType: AVCaptureDevice.DeviceType? = nil
var deviceType: AVCaptureDevice.DeviceType = .builtInWideAngleCamera


var activeFormat: FLTCaptureDeviceFormat {
get {
Expand Down
2 changes: 2 additions & 0 deletions packages/camera/camera_avfoundation/example/lib/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -585,6 +585,8 @@ class _CameraExampleHomeState extends State<CameraExampleHome>
}

onNewCameraSelected(description);

showInSnackBar('Selected lens type: ${description.lensType.name}.');
}

if (_cameras.isEmpty) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -157,10 +157,24 @@ extension CameraPlugin: FCPCameraApi {
@unknown default:
lensFacing = .external
}
print(device.deviceType)

Choose a reason for hiding this comment

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

medium

This print statement appears to be for debugging purposes and should be removed before merging.

var lensType: FCPPlatformCameraLensType

switch device.deviceType {
case .builtInWideAngleCamera:
lensType = .wide
case .builtInUltraWideCamera:
lensType = .ultraWide
case .builtInTelephotoCamera:
lensType = .telephoto
default:
lensType = .unknown
}

let cameraDescription = FCPPlatformCameraDescription.make(
withName: device.uniqueID,
lensDirection: lensFacing
lensDirection: lensFacing,
lensType: lensType
)
reply.append(cameraDescription)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,11 @@ - (AVCaptureDevicePosition)position {
return self.device.position;
}

// Lens type
- (AVCaptureDeviceType)deviceType {
return self.device.deviceType;
}

// Format/Configuration
- (NSObject<FLTCaptureDeviceFormat> *)activeFormat {
return [[FLTDefaultCaptureDeviceFormat alloc] initWithFormat:self.device.activeFormat];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,9 @@ NS_ASSUME_NONNULL_BEGIN
// Position/Orientation
@property(nonatomic, readonly) AVCaptureDevicePosition position;

// Device type
@property(nonatomic, readonly) AVCaptureDeviceType deviceType;

// Format/Configuration
@property(nonatomic, retain) NSObject<FLTCaptureDeviceFormat> *activeFormat;
@property(nonatomic, readonly) NSArray<NSObject<FLTCaptureDeviceFormat> *> *formats;
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,79 +141,79 @@ 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;
@property(nonatomic, copy) NSString * name;
/// The direction the camera is facing.
@property(nonatomic, assign) FCPPlatformCameraLensDirection lensDirection;
/// The type of the camera lense
@property(nonatomic, assign) FCPPlatformCameraLensType lensType;
@end

@interface FCPPlatformCameraState : NSObject
/// `init` unavailable to enforce nonnull fields, see the `make` class method.
- (instancetype)init NS_UNAVAILABLE;
+ (instancetype)makeWithPreviewSize:(FCPPlatformSize *)previewSize
exposureMode:(FCPPlatformExposureMode)exposureMode
focusMode:(FCPPlatformFocusMode)focusMode
exposurePointSupported:(BOOL)exposurePointSupported
focusPointSupported:(BOOL)focusPointSupported;
exposureMode:(FCPPlatformExposureMode)exposureMode
focusMode:(FCPPlatformFocusMode)focusMode
exposurePointSupported:(BOOL )exposurePointSupported
focusPointSupported:(BOOL )focusPointSupported;
/// The size of the preview, in pixels.
@property(nonatomic, strong) FCPPlatformSize *previewSize;
@property(nonatomic, strong) FCPPlatformSize * previewSize;
/// The default exposure mode
@property(nonatomic, assign) FCPPlatformExposureMode exposureMode;
/// The default focus mode
@property(nonatomic, assign) FCPPlatformFocusMode focusMode;
/// Whether setting exposure points is supported.
@property(nonatomic, assign) BOOL exposurePointSupported;
@property(nonatomic, assign) BOOL exposurePointSupported;
/// Whether setting focus points is supported.
@property(nonatomic, assign) BOOL focusPointSupported;
@property(nonatomic, assign) BOOL focusPointSupported;
@end

@interface FCPPlatformMediaSettings : NSObject
/// `init` unavailable to enforce nonnull fields, see the `make` class method.
- (instancetype)init NS_UNAVAILABLE;
+ (instancetype)makeWithResolutionPreset:(FCPPlatformResolutionPreset)resolutionPreset
framesPerSecond:(nullable NSNumber *)framesPerSecond
videoBitrate:(nullable NSNumber *)videoBitrate
audioBitrate:(nullable NSNumber *)audioBitrate
enableAudio:(BOOL)enableAudio;
framesPerSecond:(nullable NSNumber *)framesPerSecond
videoBitrate:(nullable NSNumber *)videoBitrate
audioBitrate:(nullable NSNumber *)audioBitrate
enableAudio:(BOOL )enableAudio;
@property(nonatomic, assign) FCPPlatformResolutionPreset resolutionPreset;
@property(nonatomic, strong, nullable) NSNumber *framesPerSecond;
@property(nonatomic, strong, nullable) NSNumber *videoBitrate;
@property(nonatomic, strong, nullable) NSNumber *audioBitrate;
@property(nonatomic, assign) BOOL enableAudio;
@property(nonatomic, strong, nullable) NSNumber * framesPerSecond;
@property(nonatomic, strong, nullable) NSNumber * videoBitrate;
@property(nonatomic, strong, nullable) NSNumber * audioBitrate;
@property(nonatomic, assign) BOOL enableAudio;
@end

@interface FCPPlatformPoint : NSObject
/// `init` unavailable to enforce nonnull fields, see the `make` class method.
- (instancetype)init NS_UNAVAILABLE;
+ (instancetype)makeWithX:(double)x y:(double)y;
@property(nonatomic, assign) double x;
@property(nonatomic, assign) double y;
+ (instancetype)makeWithX:(double )x
y:(double )y;
@property(nonatomic, assign) double x;
@property(nonatomic, assign) double y;
@end

@interface FCPPlatformSize : NSObject
/// `init` unavailable to enforce nonnull fields, see the `make` class method.
- (instancetype)init NS_UNAVAILABLE;
+ (instancetype)makeWithWidth:(double)width height:(double)height;
@property(nonatomic, assign) double width;
@property(nonatomic, assign) double height;
+ (instancetype)makeWithWidth:(double )width
height:(double )height;
@property(nonatomic, assign) double width;
@property(nonatomic, assign) double height;
@end

/// The codec used by all APIs.
NSObject<FlutterMessageCodec> *FCPGetMessagesCodec(void);

@protocol FCPCameraApi
/// Returns the list of available cameras.
- (void)availableCamerasWithCompletion:(void (^)(NSArray<FCPPlatformCameraDescription *> *_Nullable,
FlutterError *_Nullable))completion;
- (void)availableCamerasWithCompletion:(void (^)(NSArray<FCPPlatformCameraDescription *> *_Nullable, FlutterError *_Nullable))completion;
/// Create a new camera with the given settings, and returns its ID.
- (void)createCameraWithName:(NSString *)cameraName
settings:(FCPPlatformMediaSettings *)settings
completion:(void (^)(NSNumber *_Nullable, FlutterError *_Nullable))completion;
- (void)createCameraWithName:(NSString *)cameraName settings:(FCPPlatformMediaSettings *)settings completion:(void (^)(NSNumber *_Nullable, FlutterError *_Nullable))completion;
/// Initializes the camera with the given ID.
- (void)initializeCamera:(NSInteger)cameraId
withImageFormat:(FCPPlatformImageFormatGroup)imageFormat
completion:(void (^)(FlutterError *_Nullable))completion;
- (void)initializeCamera:(NSInteger)cameraId withImageFormat:(FCPPlatformImageFormatGroup)imageFormat completion:(void (^)(FlutterError *_Nullable))completion;
/// Begins streaming frames from the camera.
- (void)startImageStreamWithCompletion:(void (^)(FlutterError *_Nullable))completion;
/// Stops streaming frames from the camera.
Expand All @@ -210,53 +227,44 @@ NSObject<FlutterMessageCodec> *FCPGetMessagesCodec(void);
/// and any associated resources can be cleaned up.
- (void)disposeCamera:(NSInteger)cameraId completion:(void (^)(FlutterError *_Nullable))completion;
/// Locks the camera capture to the current device orientation.
- (void)lockCaptureOrientation:(FCPPlatformDeviceOrientation)orientation
completion:(void (^)(FlutterError *_Nullable))completion;
- (void)lockCaptureOrientation:(FCPPlatformDeviceOrientation)orientation completion:(void (^)(FlutterError *_Nullable))completion;
/// Unlocks camera capture orientation, allowing it to automatically adapt to
/// device orientation.
- (void)unlockCaptureOrientationWithCompletion:(void (^)(FlutterError *_Nullable))completion;
/// Takes a picture with the current settings, and returns the path to the
/// resulting file.
- (void)takePictureWithCompletion:(void (^)(NSString *_Nullable,
FlutterError *_Nullable))completion;
- (void)takePictureWithCompletion:(void (^)(NSString *_Nullable, FlutterError *_Nullable))completion;
/// Does any preprocessing necessary before beginning to record video.
- (void)prepareForVideoRecordingWithCompletion:(void (^)(FlutterError *_Nullable))completion;
/// Begins recording video, optionally enabling streaming to Dart at the same
/// time.
- (void)startVideoRecordingWithStreaming:(BOOL)enableStream
completion:(void (^)(FlutterError *_Nullable))completion;
- (void)startVideoRecordingWithStreaming:(BOOL)enableStream completion:(void (^)(FlutterError *_Nullable))completion;
/// Stops recording video, and results the path to the resulting file.
- (void)stopVideoRecordingWithCompletion:(void (^)(NSString *_Nullable,
FlutterError *_Nullable))completion;
- (void)stopVideoRecordingWithCompletion:(void (^)(NSString *_Nullable, FlutterError *_Nullable))completion;
/// Pauses video recording.
- (void)pauseVideoRecordingWithCompletion:(void (^)(FlutterError *_Nullable))completion;
/// Resumes a previously paused video recording.
- (void)resumeVideoRecordingWithCompletion:(void (^)(FlutterError *_Nullable))completion;
/// Switches the camera to the given flash mode.
- (void)setFlashMode:(FCPPlatformFlashMode)mode
completion:(void (^)(FlutterError *_Nullable))completion;
- (void)setFlashMode:(FCPPlatformFlashMode)mode completion:(void (^)(FlutterError *_Nullable))completion;
/// Switches the camera to the given exposure mode.
- (void)setExposureMode:(FCPPlatformExposureMode)mode
completion:(void (^)(FlutterError *_Nullable))completion;
- (void)setExposureMode:(FCPPlatformExposureMode)mode completion:(void (^)(FlutterError *_Nullable))completion;
/// Anchors auto-exposure to the given point in (0,1) coordinate space.
///
/// A null value resets to the default exposure point.
- (void)setExposurePoint:(nullable FCPPlatformPoint *)point
completion:(void (^)(FlutterError *_Nullable))completion;
- (void)setExposurePoint:(nullable FCPPlatformPoint *)point completion:(void (^)(FlutterError *_Nullable))completion;
/// Returns the minimum exposure offset supported by the camera.
- (void)getMinimumExposureOffset:(void (^)(NSNumber *_Nullable, FlutterError *_Nullable))completion;
/// Returns the maximum exposure offset supported by the camera.
- (void)getMaximumExposureOffset:(void (^)(NSNumber *_Nullable, FlutterError *_Nullable))completion;
/// Sets the exposure offset manually to the given value.
- (void)setExposureOffset:(double)offset completion:(void (^)(FlutterError *_Nullable))completion;
/// Switches the camera to the given focus mode.
- (void)setFocusMode:(FCPPlatformFocusMode)mode
completion:(void (^)(FlutterError *_Nullable))completion;
- (void)setFocusMode:(FCPPlatformFocusMode)mode completion:(void (^)(FlutterError *_Nullable))completion;
/// Anchors auto-focus to the given point in (0,1) coordinate space.
///
/// A null value resets to the default focus point.
- (void)setFocusPoint:(nullable FCPPlatformPoint *)point
completion:(void (^)(FlutterError *_Nullable))completion;
- (void)setFocusPoint:(nullable FCPPlatformPoint *)point completion:(void (^)(FlutterError *_Nullable))completion;
/// Returns the minimum zoom level supported by the camera.
- (void)getMinimumZoomLevel:(void (^)(NSNumber *_Nullable, FlutterError *_Nullable))completion;
/// Returns the maximum zoom level supported by the camera.
Expand All @@ -270,40 +278,33 @@ NSObject<FlutterMessageCodec> *FCPGetMessagesCodec(void);
/// Changes the camera used while recording video.
///
/// This should only be called while video recording is active.
- (void)updateDescriptionWhileRecordingCameraName:(NSString *)cameraName
completion:(void (^)(FlutterError *_Nullable))completion;
- (void)updateDescriptionWhileRecordingCameraName:(NSString *)cameraName completion:(void (^)(FlutterError *_Nullable))completion;
/// Sets the file format used for taking pictures.
- (void)setImageFileFormat:(FCPPlatformImageFileFormat)format
completion:(void (^)(FlutterError *_Nullable))completion;
- (void)setImageFileFormat:(FCPPlatformImageFileFormat)format completion:(void (^)(FlutterError *_Nullable))completion;
@end

extern void SetUpFCPCameraApi(id<FlutterBinaryMessenger> binaryMessenger,
NSObject<FCPCameraApi> *_Nullable api);
extern void SetUpFCPCameraApi(id<FlutterBinaryMessenger> binaryMessenger, NSObject<FCPCameraApi> *_Nullable api);

extern void SetUpFCPCameraApiWithSuffix(id<FlutterBinaryMessenger> binaryMessenger, NSObject<FCPCameraApi> *_Nullable api, NSString *messageChannelSuffix);

extern void SetUpFCPCameraApiWithSuffix(id<FlutterBinaryMessenger> binaryMessenger,
NSObject<FCPCameraApi> *_Nullable api,
NSString *messageChannelSuffix);

/// Handler for native callbacks that are not tied to a specific camera ID.
@interface FCPCameraGlobalEventApi : NSObject
- (instancetype)initWithBinaryMessenger:(id<FlutterBinaryMessenger>)binaryMessenger;
- (instancetype)initWithBinaryMessenger:(id<FlutterBinaryMessenger>)binaryMessenger
messageChannelSuffix:(nullable NSString *)messageChannelSuffix;
- (instancetype)initWithBinaryMessenger:(id<FlutterBinaryMessenger>)binaryMessenger messageChannelSuffix:(nullable NSString *)messageChannelSuffix;
/// Called when the device's physical orientation changes.
- (void)deviceOrientationChangedOrientation:(FCPPlatformDeviceOrientation)orientation
completion:(void (^)(FlutterError *_Nullable))completion;
- (void)deviceOrientationChangedOrientation:(FCPPlatformDeviceOrientation)orientation completion:(void (^)(FlutterError *_Nullable))completion;
@end


/// Handler for native callbacks that are tied to a specific camera ID.
///
/// This is intended to be initialized with the camera ID as a suffix.
@interface FCPCameraEventApi : NSObject
- (instancetype)initWithBinaryMessenger:(id<FlutterBinaryMessenger>)binaryMessenger;
- (instancetype)initWithBinaryMessenger:(id<FlutterBinaryMessenger>)binaryMessenger
messageChannelSuffix:(nullable NSString *)messageChannelSuffix;
- (instancetype)initWithBinaryMessenger:(id<FlutterBinaryMessenger>)binaryMessenger messageChannelSuffix:(nullable NSString *)messageChannelSuffix;
/// Called when the camera is inialitized for use.
- (void)initializedWithState:(FCPPlatformCameraState *)initialState
completion:(void (^)(FlutterError *_Nullable))completion;
- (void)initializedWithState:(FCPPlatformCameraState *)initialState completion:(void (^)(FlutterError *_Nullable))completion;
/// Called when an error occurs in the camera.
///
/// This should be used for errors that occur outside of the context of
Expand Down
Loading