@@ -355,6 +355,8 @@ @interface FLTCam : NSObject <FlutterTexture,
355
355
@property (assign , nonatomic ) CMTime lastAudioSampleTime;
356
356
@property (assign , nonatomic ) CMTime videoTimeOffset;
357
357
@property (assign , nonatomic ) CMTime audioTimeOffset;
358
+ // Format used for video and image streaming.
359
+ @property (assign , nonatomic ) FourCharCode videoFormat;
358
360
@property (nonatomic ) CMMotionManager *motionManager;
359
361
@property AVAssetWriterInputPixelBufferAdaptor *videoAdaptor;
360
362
@end
@@ -365,8 +367,6 @@ @implementation FLTCam {
365
367
dispatch_queue_t _captureSessionQueue;
366
368
UIDeviceOrientation _deviceOrientation;
367
369
}
368
- // Format used for video and image streaming.
369
- FourCharCode videoFormat = kCVPixelFormatType_32BGRA ;
370
370
NSString *const errorMethod = @" error" ;
371
371
372
372
- (instancetype )initWithCameraName : (NSString *)cameraName
@@ -391,6 +391,7 @@ - (instancetype)initWithCameraName:(NSString *)cameraName
391
391
_focusMode = FocusModeAuto;
392
392
_lockedCaptureOrientation = UIDeviceOrientationUnknown;
393
393
_deviceOrientation = orientation;
394
+ _videoFormat = kCVPixelFormatType_32BGRA ;
394
395
395
396
NSError *localError = nil ;
396
397
_captureVideoInput = [AVCaptureDeviceInput deviceInputWithDevice: _captureDevice
@@ -403,7 +404,7 @@ - (instancetype)initWithCameraName:(NSString *)cameraName
403
404
404
405
_captureVideoOutput = [AVCaptureVideoDataOutput new ];
405
406
_captureVideoOutput.videoSettings =
406
- @{(NSString *)kCVPixelBufferPixelFormatTypeKey : @(videoFormat )};
407
+ @{(NSString *)kCVPixelBufferPixelFormatTypeKey : @(_videoFormat )};
407
408
[_captureVideoOutput setAlwaysDiscardsLateVideoFrames: YES ];
408
409
[_captureVideoOutput setSampleBufferDelegate: self queue: dispatch_get_main_queue ()];
409
410
@@ -441,6 +442,12 @@ - (void)stop {
441
442
[_captureSession stopRunning ];
442
443
}
443
444
445
+ - (void )setVideoFormat : (OSType )videoFormat {
446
+ _videoFormat = videoFormat;
447
+ _captureVideoOutput.videoSettings =
448
+ @{(NSString *)kCVPixelBufferPixelFormatTypeKey : @(videoFormat)};
449
+ }
450
+
444
451
- (void )setDeviceOrientation : (UIDeviceOrientation)orientation {
445
452
if (_deviceOrientation == orientation) {
446
453
return ;
@@ -680,7 +687,7 @@ - (void)captureOutput:(AVCaptureOutput *)output
680
687
NSMutableDictionary *imageBuffer = [NSMutableDictionary dictionary ];
681
688
imageBuffer[@" width" ] = [NSNumber numberWithUnsignedLong: imageWidth];
682
689
imageBuffer[@" height" ] = [NSNumber numberWithUnsignedLong: imageHeight];
683
- imageBuffer[@" format" ] = @(videoFormat );
690
+ imageBuffer[@" format" ] = @(_videoFormat );
684
691
imageBuffer[@" planes" ] = planes;
685
692
imageBuffer[@" lensAperture" ] = [NSNumber numberWithFloat: [_captureDevice lensAperture ]];
686
693
Float64 exposureDuration = CMTimeGetSeconds ([_captureDevice exposureDuration ]);
@@ -1246,7 +1253,7 @@ - (BOOL)setupWriterForPath:(NSString *)path {
1246
1253
_videoAdaptor = [AVAssetWriterInputPixelBufferAdaptor
1247
1254
assetWriterInputPixelBufferAdaptorWithAssetWriterInput: _videoWriterInput
1248
1255
sourcePixelBufferAttributes: @{
1249
- (NSString *)kCVPixelBufferPixelFormatTypeKey : @(videoFormat )
1256
+ (NSString *)kCVPixelBufferPixelFormatTypeKey : @(_videoFormat )
1250
1257
}];
1251
1258
1252
1259
NSParameterAssert (_videoWriterInput);
@@ -1464,7 +1471,7 @@ - (void)handleMethodCallAsync:(FlutterMethodCall *)call
1464
1471
NSUInteger cameraId = ((NSNumber *)argsMap[@" cameraId" ]).unsignedIntegerValue ;
1465
1472
if ([@" initialize" isEqualToString: call.method]) {
1466
1473
NSString *videoFormatValue = ((NSString *)argsMap[@" imageFormatGroup" ]);
1467
- videoFormat = getVideoFormatFromString (videoFormatValue);
1474
+ [_camera setVideoFormat: getVideoFormatFromString (videoFormatValue)] ;
1468
1475
1469
1476
__weak CameraPlugin *weakSelf = self;
1470
1477
_camera.onFrameAvailable = ^{
0 commit comments