1414#import " FLTThreadSafeFlutterResult.h"
1515#import " FLTThreadSafeMethodChannel.h"
1616#import " FLTThreadSafeTextureRegistry.h"
17+ #import " FlashMode.h"
1718
1819@interface FLTSavePhotoDelegate : NSObject <AVCapturePhotoCaptureDelegate>
1920@property (readonly , nonatomic ) NSString *path;
@@ -113,34 +114,6 @@ - (void)captureOutput:(AVCapturePhotoOutput *)output
113114}
114115@end
115116
116- // Mirrors FlashMode in flash_mode.dart
117- typedef enum {
118- FlashModeOff,
119- FlashModeAuto,
120- FlashModeAlways,
121- FlashModeTorch,
122- } FlashMode;
123-
124- static FlashMode getFlashModeForString (NSString *mode) {
125- if ([mode isEqualToString: @" off" ]) {
126- return FlashModeOff;
127- } else if ([mode isEqualToString: @" auto" ]) {
128- return FlashModeAuto;
129- } else if ([mode isEqualToString: @" always" ]) {
130- return FlashModeAlways;
131- } else if ([mode isEqualToString: @" torch" ]) {
132- return FlashModeTorch;
133- } else {
134- NSError *error = [NSError errorWithDomain: NSCocoaErrorDomain
135- code: NSURLErrorUnknown
136- userInfo: @{
137- NSLocalizedDescriptionKey : [NSString
138- stringWithFormat: @" Unknown flash mode %@ " , mode]
139- }];
140- @throw error;
141- }
142- }
143-
144117static OSType getVideoFormatFromString (NSString *videoFormatString) {
145118 if ([videoFormatString isEqualToString: @" bgra8888" ]) {
146119 return kCVPixelFormatType_32BGRA ;
@@ -152,20 +125,6 @@ static OSType getVideoFormatFromString(NSString *videoFormatString) {
152125 }
153126}
154127
155- static AVCaptureFlashMode getAVCaptureFlashModeForFlashMode (FlashMode mode) {
156- switch (mode) {
157- case FlashModeOff:
158- return AVCaptureFlashModeOff;
159- case FlashModeAuto:
160- return AVCaptureFlashModeAuto;
161- case FlashModeAlways:
162- return AVCaptureFlashModeOn;
163- case FlashModeTorch:
164- default :
165- return -1 ;
166- }
167- }
168-
169128// Mirrors ExposureMode in camera.dart
170129typedef enum {
171130 ExposureModeAuto,
@@ -349,7 +308,7 @@ @interface FLTCam : NSObject <FlutterTexture,
349308@property (assign , nonatomic ) ResolutionPreset resolutionPreset;
350309@property (assign , nonatomic ) ExposureMode exposureMode;
351310@property (assign , nonatomic ) FocusMode focusMode;
352- @property (assign , nonatomic ) FlashMode flashMode;
311+ @property (assign , nonatomic ) FLTFlashMode flashMode;
353312@property (assign , nonatomic ) UIDeviceOrientation lockedCaptureOrientation;
354313@property (assign , nonatomic ) CMTime lastVideoSampleTime;
355314@property (assign , nonatomic ) CMTime lastAudioSampleTime;
@@ -386,7 +345,7 @@ - (instancetype)initWithCameraName:(NSString *)cameraName
386345 _captureSessionQueue = captureSessionQueue;
387346 _captureSession = [[AVCaptureSession alloc ] init ];
388347 _captureDevice = [AVCaptureDevice deviceWithUniqueID: cameraName];
389- _flashMode = _captureDevice.hasFlash ? FlashModeAuto : FlashModeOff ;
348+ _flashMode = _captureDevice.hasFlash ? FLTFlashModeAuto : FLTFlashModeOff ;
390349 _exposureMode = ExposureModeAuto;
391350 _focusMode = FocusModeAuto;
392351 _lockedCaptureOrientation = UIDeviceOrientationUnknown;
@@ -488,7 +447,7 @@ - (void)captureToFile:(FLTThreadSafeFlutterResult *)result API_AVAILABLE(ios(10)
488447 [settings setHighResolutionPhotoEnabled: YES ];
489448 }
490449
491- AVCaptureFlashMode avFlashMode = getAVCaptureFlashModeForFlashMode (_flashMode);
450+ AVCaptureFlashMode avFlashMode = FLTGetAVCaptureFlashModeForFLTFlashMode (_flashMode);
492451 if (avFlashMode != -1 ) {
493452 [settings setFlashMode: avFlashMode];
494453 }
@@ -933,14 +892,14 @@ - (void)unlockCaptureOrientationWithResult:(FLTThreadSafeFlutterResult *)result
933892}
934893
935894- (void )setFlashModeWithResult : (FLTThreadSafeFlutterResult *)result mode : (NSString *)modeStr {
936- FlashMode mode;
895+ FLTFlashMode mode;
937896 @try {
938- mode = getFlashModeForString (modeStr);
897+ mode = FLTGetFLTFlashModeForString (modeStr);
939898 } @catch (NSError *e) {
940899 [result sendError: e];
941900 return ;
942901 }
943- if (mode == FlashModeTorch ) {
902+ if (mode == FLTFlashModeTorch ) {
944903 if (!_captureDevice.hasTorch ) {
945904 [result sendErrorWithCode: @" setFlashModeFailed"
946905 message: @" Device does not support torch mode"
@@ -965,7 +924,7 @@ - (void)setFlashModeWithResult:(FLTThreadSafeFlutterResult *)result mode:(NSStri
965924 details: nil ];
966925 return ;
967926 }
968- AVCaptureFlashMode avFlashMode = getAVCaptureFlashModeForFlashMode (mode);
927+ AVCaptureFlashMode avFlashMode = FLTGetAVCaptureFlashModeForFLTFlashMode (mode);
969928 if (![_capturePhotoOutput.supportedFlashModes
970929 containsObject: [NSNumber numberWithInt: ((int )avFlashMode)]]) {
971930 [result sendErrorWithCode: @" setFlashModeFailed"
@@ -1281,7 +1240,7 @@ - (BOOL)setupWriterForPath:(NSString *)path {
12811240 [_audioOutput setSampleBufferDelegate: self queue: _captureSessionQueue];
12821241 }
12831242
1284- if (_flashMode == FlashModeTorch ) {
1243+ if (_flashMode == FLTFlashModeTorch ) {
12851244 [self .captureDevice lockForConfiguration: nil ];
12861245 [self .captureDevice setTorchMode: AVCaptureTorchModeOn];
12871246 [self .captureDevice unlockForConfiguration ];
0 commit comments