14
14
#import " FLTThreadSafeFlutterResult.h"
15
15
#import " FLTThreadSafeMethodChannel.h"
16
16
#import " FLTThreadSafeTextureRegistry.h"
17
+ #import " FlashMode.h"
17
18
18
19
@interface FLTSavePhotoDelegate : NSObject <AVCapturePhotoCaptureDelegate>
19
20
@property (readonly , nonatomic ) NSString *path;
@@ -113,34 +114,6 @@ - (void)captureOutput:(AVCapturePhotoOutput *)output
113
114
}
114
115
@end
115
116
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
-
144
117
static OSType getVideoFormatFromString (NSString *videoFormatString) {
145
118
if ([videoFormatString isEqualToString: @" bgra8888" ]) {
146
119
return kCVPixelFormatType_32BGRA ;
@@ -152,20 +125,6 @@ static OSType getVideoFormatFromString(NSString *videoFormatString) {
152
125
}
153
126
}
154
127
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
-
169
128
// Mirrors ExposureMode in camera.dart
170
129
typedef enum {
171
130
ExposureModeAuto,
@@ -349,7 +308,7 @@ @interface FLTCam : NSObject <FlutterTexture,
349
308
@property (assign , nonatomic ) ResolutionPreset resolutionPreset;
350
309
@property (assign , nonatomic ) ExposureMode exposureMode;
351
310
@property (assign , nonatomic ) FocusMode focusMode;
352
- @property (assign , nonatomic ) FlashMode flashMode;
311
+ @property (assign , nonatomic ) FLTFlashMode flashMode;
353
312
@property (assign , nonatomic ) UIDeviceOrientation lockedCaptureOrientation;
354
313
@property (assign , nonatomic ) CMTime lastVideoSampleTime;
355
314
@property (assign , nonatomic ) CMTime lastAudioSampleTime;
@@ -386,7 +345,7 @@ - (instancetype)initWithCameraName:(NSString *)cameraName
386
345
_captureSessionQueue = captureSessionQueue;
387
346
_captureSession = [[AVCaptureSession alloc ] init ];
388
347
_captureDevice = [AVCaptureDevice deviceWithUniqueID: cameraName];
389
- _flashMode = _captureDevice.hasFlash ? FlashModeAuto : FlashModeOff ;
348
+ _flashMode = _captureDevice.hasFlash ? FLTFlashModeAuto : FLTFlashModeOff ;
390
349
_exposureMode = ExposureModeAuto;
391
350
_focusMode = FocusModeAuto;
392
351
_lockedCaptureOrientation = UIDeviceOrientationUnknown;
@@ -488,7 +447,7 @@ - (void)captureToFile:(FLTThreadSafeFlutterResult *)result API_AVAILABLE(ios(10)
488
447
[settings setHighResolutionPhotoEnabled: YES ];
489
448
}
490
449
491
- AVCaptureFlashMode avFlashMode = getAVCaptureFlashModeForFlashMode (_flashMode);
450
+ AVCaptureFlashMode avFlashMode = FLTGetAVCaptureFlashModeForFLTFlashMode (_flashMode);
492
451
if (avFlashMode != -1 ) {
493
452
[settings setFlashMode: avFlashMode];
494
453
}
@@ -933,14 +892,14 @@ - (void)unlockCaptureOrientationWithResult:(FLTThreadSafeFlutterResult *)result
933
892
}
934
893
935
894
- (void )setFlashModeWithResult : (FLTThreadSafeFlutterResult *)result mode : (NSString *)modeStr {
936
- FlashMode mode;
895
+ FLTFlashMode mode;
937
896
@try {
938
- mode = getFlashModeForString (modeStr);
897
+ mode = FLTGetFLTFlashModeForString (modeStr);
939
898
} @catch (NSError *e) {
940
899
[result sendError: e];
941
900
return ;
942
901
}
943
- if (mode == FlashModeTorch ) {
902
+ if (mode == FLTFlashModeTorch ) {
944
903
if (!_captureDevice.hasTorch ) {
945
904
[result sendErrorWithCode: @" setFlashModeFailed"
946
905
message: @" Device does not support torch mode"
@@ -965,7 +924,7 @@ - (void)setFlashModeWithResult:(FLTThreadSafeFlutterResult *)result mode:(NSStri
965
924
details: nil ];
966
925
return ;
967
926
}
968
- AVCaptureFlashMode avFlashMode = getAVCaptureFlashModeForFlashMode (mode);
927
+ AVCaptureFlashMode avFlashMode = FLTGetAVCaptureFlashModeForFLTFlashMode (mode);
969
928
if (![_capturePhotoOutput.supportedFlashModes
970
929
containsObject: [NSNumber numberWithInt: ((int )avFlashMode)]]) {
971
930
[result sendErrorWithCode: @" setFlashModeFailed"
@@ -1281,7 +1240,7 @@ - (BOOL)setupWriterForPath:(NSString *)path {
1281
1240
[_audioOutput setSampleBufferDelegate: self queue: _captureSessionQueue];
1282
1241
}
1283
1242
1284
- if (_flashMode == FlashModeTorch ) {
1243
+ if (_flashMode == FLTFlashModeTorch ) {
1285
1244
[self .captureDevice lockForConfiguration: nil ];
1286
1245
[self .captureDevice setTorchMode: AVCaptureTorchModeOn];
1287
1246
[self .captureDevice unlockForConfiguration ];
0 commit comments