Skip to content
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

[avfoundation] Add camera specifics to PlatformCameraDescription #8323

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
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
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ - (void)availableCamerasWithCompletion:
[@[ AVCaptureDeviceTypeBuiltInWideAngleCamera, AVCaptureDeviceTypeBuiltInTelephotoCamera ]
mutableCopy];
if (@available(iOS 13.0, *)) {
[discoveryDevices addObject:AVCaptureDeviceTypeBuiltInUltraWideCamera];
[discoveryDevices addObjectsFromArray:@[AVCaptureDeviceTypeBuiltInUltraWideCamera, AVCaptureDeviceTypeBuiltInTripleCamera, AVCaptureDeviceTypeBuiltInDualWideCamera, AVCaptureDeviceTypeBuiltInDualCamera]];
}
AVCaptureDeviceDiscoverySession *discoverySession = [AVCaptureDeviceDiscoverySession
discoverySessionWithDeviceTypes:discoveryDevices
Expand All @@ -131,8 +131,35 @@ - (void)availableCamerasWithCompletion:
lensFacing = FCPPlatformCameraLensDirectionExternal;
break;
}
FCPPlatformCaptureDeviceType deviceType = FCPPlatformCaptureDeviceTypeUnknown;
// AVCaptureDeviceType is a constant, and hence can't be used in a switch/case statement.
if (device.deviceType == AVCaptureDeviceTypeExternal) {
deviceType = FCPPlatformCaptureDeviceTypeExternal;
}
if (device.deviceType == AVCaptureDeviceTypeBuiltInWideAngleCamera) {
deviceType = FCPPlatformCaptureDeviceTypeBuiltInWideAngleCamera;
}
if (device.deviceType == AVCaptureDeviceTypeBuiltInTelephotoCamera) {
deviceType = FCPPlatformCaptureDeviceTypeBuiltInTelephotoCamera;
}
if (device.deviceType == AVCaptureDeviceTypeBuiltInUltraWideCamera) {
deviceType = FCPPlatformCaptureDeviceTypeBuiltInUltraWideCamera;
}
if (device.deviceType == AVCaptureDeviceTypeBuiltInDualCamera) {
deviceType = FCPPlatformCaptureDeviceTypeBuiltInDualCamera;
}
if (device.deviceType == AVCaptureDeviceTypeBuiltInDualWideCamera) {
deviceType = FCPPlatformCaptureDeviceTypeBuiltInDualWideCamera;
}
if (device.deviceType == AVCaptureDeviceTypeBuiltInTripleCamera) {
deviceType = FCPPlatformCaptureDeviceTypeBuiltInTripleCamera;
}
[reply addObject:[FCPPlatformCameraDescription makeWithName:device.uniqueID
lensDirection:lensFacing]];
lensDirection:lensFacing
deviceType: deviceType
manufacturer: device.manufacturer
model: device.modelID
localisedName: device.localizedName]];
}
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.6.2), do not edit directly.
// See also: https://pub.dev/packages/pigeon

#import <Foundation/Foundation.h>
Expand Down Expand Up @@ -114,6 +114,24 @@ typedef NS_ENUM(NSUInteger, FCPPlatformResolutionPreset) {
- (instancetype)initWithValue:(FCPPlatformResolutionPreset)value;
@end

/// Pigeon version of AVCaptureDeviceType.
typedef NS_ENUM(NSUInteger, FCPPlatformCaptureDeviceType) {
FCPPlatformCaptureDeviceTypeExternal = 0,
FCPPlatformCaptureDeviceTypeBuiltInWideAngleCamera = 1,
FCPPlatformCaptureDeviceTypeBuiltInTelephotoCamera = 2,
FCPPlatformCaptureDeviceTypeBuiltInUltraWideCamera = 3,
FCPPlatformCaptureDeviceTypeBuiltInDualCamera = 4,
FCPPlatformCaptureDeviceTypeBuiltInDualWideCamera = 5,
FCPPlatformCaptureDeviceTypeBuiltInTripleCamera = 6,
FCPPlatformCaptureDeviceTypeUnknown = 7,
};

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

@class FCPPlatformCameraDescription;
@class FCPPlatformCameraState;
@class FCPPlatformMediaSettings;
Expand All @@ -124,79 +142,84 @@ 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
deviceType:(FCPPlatformCaptureDeviceType)deviceType
manufacturer:(NSString *)manufacturer
model:(NSString *)model
localisedName:(NSString *)localisedName;
/// 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;
@property(nonatomic, assign) FCPPlatformCaptureDeviceType deviceType;
@property(nonatomic, copy) NSString * manufacturer;
@property(nonatomic, copy) NSString * model;
@property(nonatomic, copy) NSString * localisedName;
@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 +233,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 +284,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
Loading