Skip to content
Open
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 @@ -15,6 +15,7 @@ import android.util.Size
import androidx.camera.camera2.Camera2Config
import androidx.camera.camera2.interop.ExperimentalCamera2Interop
import androidx.camera.core.*
import androidx.camera.core.impl.utils.CameraOrientationUtil
import androidx.camera.lifecycle.ProcessCameraProvider
import androidx.camera.video.FileOutputOptions
import androidx.camera.video.VideoRecordEvent
Expand Down Expand Up @@ -124,6 +125,7 @@ class CameraAwesomeX : CameraInterface, FlutterPlugin, ActivityAware {
zoom: Double,
mirrorFrontCamera: Boolean,
enablePhysicalButton: Boolean,
enableRotation: Boolean,
flashMode: String,
captureMode: String,
enableImageStream: Boolean,
Expand Down Expand Up @@ -162,8 +164,10 @@ class CameraAwesomeX : CameraInterface, FlutterPlugin, ActivityAware {
this.enableAudioRecording = videoOptions?.enableAudio ?: true
}
this.exifPreferences = exifPreferences
orientationStreamListener =
OrientationStreamListener(activity!!, listOf(sensorOrientationListener, cameraState))
if (enableRotation) {
orientationStreamListener =
OrientationStreamListener(activity!!, listOf(sensorOrientationListener, cameraState))
}
imageStreamChannel.setStreamHandler(cameraState)
if (mode != CaptureModes.ANALYSIS_ONLY) {
cameraState.updateLifecycle(activity!!)
Expand Down Expand Up @@ -380,7 +384,7 @@ class CameraAwesomeX : CameraInterface, FlutterPlugin, ActivityAware {
val outputFileOptions =
ImageCapture.OutputFileOptions.Builder(imageFile).setMetadata(metadata).build()
// for (imageCapture in cameraState.imageCaptures) {
imageCapture.targetRotation = orientationStreamListener!!.surfaceOrientation
imageCapture.targetRotation = if (orientationStreamListener != null) orientationStreamListener!!.surfaceOrientation else CameraOrientationUtil.degreesToSurfaceRotation(0)
imageCapture.takePicture(outputFileOptions,
ContextCompat.getMainExecutor(activity!!),
object : ImageCapture.OnImageSavedCallback {
Expand Down Expand Up @@ -511,7 +515,7 @@ class CameraAwesomeX : CameraInterface, FlutterPlugin, ActivityAware {
}
}
}
videoCapture.targetRotation = orientationStreamListener!!.surfaceOrientation
videoCapture.targetRotation = if (orientationStreamListener != null) orientationStreamListener!!.surfaceOrientation else CameraOrientationUtil.degreesToSurfaceRotation(0)
cameraState.recordings!!.add(videoCapture.output.prepareRecording(
activity!!, FileOutputOptions.Builder(File(paths[index]!!)).build()
).apply { if (cameraState.enableAudioRecording && !ignoreAudio) withAudioEnabled() }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -759,7 +759,7 @@ private object CameraInterfaceCodec : StandardMessageCodec() {

/** Generated interface from Pigeon that represents a handler of messages from Flutter. */
interface CameraInterface {
fun setupCamera(sensors: List<PigeonSensor>, aspectRatio: String, zoom: Double, mirrorFrontCamera: Boolean, enablePhysicalButton: Boolean, flashMode: String, captureMode: String, enableImageStream: Boolean, exifPreferences: ExifPreferences, videoOptions: VideoOptions?, callback: (Result<Boolean>) -> Unit)
fun setupCamera(sensors: List<PigeonSensor>, aspectRatio: String, zoom: Double, mirrorFrontCamera: Boolean, enablePhysicalButton: Boolean, enableRotation: Boolean, flashMode: String, captureMode: String, enableImageStream: Boolean, exifPreferences: ExifPreferences, videoOptions: VideoOptions?, callback: (Result<Boolean>) -> Unit)
fun checkPermissions(permissions: List<String>): List<String>
/**
* Returns given [CamerAwesomePermission] list (as String). Location permission might be
Expand Down Expand Up @@ -826,12 +826,13 @@ interface CameraInterface {
val zoomArg = args[2] as Double
val mirrorFrontCameraArg = args[3] as Boolean
val enablePhysicalButtonArg = args[4] as Boolean
val flashModeArg = args[5] as String
val captureModeArg = args[6] as String
val enableImageStreamArg = args[7] as Boolean
val exifPreferencesArg = args[8] as ExifPreferences
val videoOptionsArg = args[9] as VideoOptions?
api.setupCamera(sensorsArg, aspectRatioArg, zoomArg, mirrorFrontCameraArg, enablePhysicalButtonArg, flashModeArg, captureModeArg, enableImageStreamArg, exifPreferencesArg, videoOptionsArg) { result: Result<Boolean> ->
val enableRotationArg = args[5] as Boolean
val flashModeArg = args[6] as String
val captureModeArg = args[7] as String
val enableImageStreamArg = args[8] as Boolean
val exifPreferencesArg = args[9] as ExifPreferences
val videoOptionsArg = args[10] as VideoOptions?
api.setupCamera(sensorsArg, aspectRatioArg, zoomArg, mirrorFrontCameraArg, enablePhysicalButtonArg, enableRotationArg, flashModeArg, captureModeArg, enableImageStreamArg, exifPreferencesArg, videoOptionsArg) { result: Result<Boolean> ->
val error = result.exceptionOrNull()
if (error != null) {
reply.reply(wrapError(error))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ AVCaptureAudioDataOutputSampleBufferDelegate>
@property(readonly, nonatomic) AspectRatio aspectRatio;
@property(readonly, nonatomic) CupertinoVideoOptions *videoOptions;
@property(readonly, nonatomic) VideoRecordingQuality recordingQuality;
@property(readonly, nonatomic) bool enableRotation;
@property(readonly, nonatomic) CameraPreviewTexture* previewTexture;
@property(readonly, nonatomic) bool saveGPSLocation;
@property(readonly, nonatomic) bool mirrorFrontCamera;
Expand All @@ -72,6 +73,7 @@ AVCaptureAudioDataOutputSampleBufferDelegate>
streamImages:(BOOL)streamImages
mirrorFrontCamera:(BOOL)mirrorFrontCamera
enablePhysicalButton:(BOOL)enablePhysicalButton
enableRotation:(BOOL)enableRotation
aspectRatioMode:(AspectRatio)aspectRatioMode
captureMode:(CaptureModes)captureMode
completion:(nonnull void (^)(NSNumber * _Nullable, FlutterError * _Nullable))completion
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ - (instancetype)initWithCameraSensor:(PigeonSensorPosition)sensor
streamImages:(BOOL)streamImages
mirrorFrontCamera:(BOOL)mirrorFrontCamera
enablePhysicalButton:(BOOL)enablePhysicalButton
enableRotation:(BOOL)enableRotation
aspectRatioMode:(AspectRatio)aspectRatioMode
captureMode:(CaptureModes)captureMode
completion:(nonnull void (^)(NSNumber * _Nullable, FlutterError * _Nullable))completion
Expand All @@ -33,6 +34,7 @@ - (instancetype)initWithCameraSensor:(PigeonSensorPosition)sensor
_mirrorFrontCamera = mirrorFrontCamera;
_videoOptions = videoOptions;
_recordingQuality = recordingQuality;
_enableRotation = enableRotation;

// Creating capture session
_captureSession = [[AVCaptureSession alloc] init];
Expand Down Expand Up @@ -61,11 +63,15 @@ - (instancetype)initWithCameraSensor:(PigeonSensorPosition)sensor
// Controllers init
_videoController = [[VideoController alloc] init];
_imageStreamController = [[ImageStreamController alloc] initWithStreamImages:streamImages];
_motionController = [[MotionController alloc] init];
if (_enableRotation) {
_motionController = [[MotionController alloc] init];
}
_locationController = [[LocationController alloc] init];
_physicalButtonController = [[PhysicalButtonController alloc] init];

[_motionController startMotionDetection];
if (_motionController != nil) {
[_motionController startMotionDetection];
}

if (enablePhysicalButton) {
[_physicalButtonController startListening];
Expand Down Expand Up @@ -434,7 +440,7 @@ - (void)refresh {
- (void)takePictureAtPath:(NSString *)path completion:(nonnull void (^)(NSNumber * _Nullable, FlutterError * _Nullable))completion {
// Instanciate camera picture obj
CameraPictureController *cameraPicture = [[CameraPictureController alloc] initWithPath:path
orientation:_motionController.deviceOrientation
orientation:_enableRotation ? _motionController.deviceOrientation : UIDeviceOrientationPortrait
sensorPosition:_cameraSensorPosition
saveGPSLocation:_saveGPSLocation
mirrorFrontCamera:_mirrorFrontCamera
Expand Down
3 changes: 2 additions & 1 deletion ios/Classes/CamerawesomePlugin.m
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ + (void)registerWithRegistrar:(NSObject<FlutterPluginRegistrar>*)registrar {

#pragma mark - Camera engine methods

- (void)setupCameraSensors:(nonnull NSArray<PigeonSensor *> *)sensors aspectRatio:(nonnull NSString *)aspectRatio zoom:(nonnull NSNumber *)zoom mirrorFrontCamera:(nonnull NSNumber *)mirrorFrontCamera enablePhysicalButton:(nonnull NSNumber *)enablePhysicalButton flashMode:(nonnull NSString *)flashMode captureMode:(nonnull NSString *)captureMode enableImageStream:(nonnull NSNumber *)enableImageStream exifPreferences:(nonnull ExifPreferences *)exifPreferences videoOptions:(nullable VideoOptions *)videoOptions completion:(nonnull void (^)(NSNumber * _Nullable, FlutterError * _Nullable))completion {
- (void)setupCameraSensors:(nonnull NSArray<PigeonSensor *> *)sensors aspectRatio:(nonnull NSString *)aspectRatio zoom:(nonnull NSNumber *)zoom mirrorFrontCamera:(nonnull NSNumber *)mirrorFrontCamera enablePhysicalButton:(nonnull NSNumber *)enablePhysicalButton enableRotation:(nonnull NSNumber *)enableRotation flashMode:(nonnull NSString *)flashMode captureMode:(nonnull NSString *)captureMode enableImageStream:(nonnull NSNumber *)enableImageStream exifPreferences:(nonnull ExifPreferences *)exifPreferences videoOptions:(nullable VideoOptions *)videoOptions completion:(nonnull void (^)(NSNumber * _Nullable, FlutterError * _Nullable))completion {

CaptureModes captureModeType = [CaptureModeUtils captureModeFromCaptureModeType:captureMode];
if (![CameraPermissionsController checkAndRequestPermission]) {
Expand Down Expand Up @@ -128,6 +128,7 @@ - (void)setupCameraSensors:(nonnull NSArray<PigeonSensor *> *)sensors aspectRati
streamImages:[enableImageStream boolValue]
mirrorFrontCamera:[mirrorFrontCamera boolValue]
enablePhysicalButton:[enablePhysicalButton boolValue]
enableRotation:[enableRotation boolValue]
aspectRatioMode:aspectRatioMode
captureMode:captureModeType
completion:completion
Expand Down
2 changes: 1 addition & 1 deletion ios/Classes/Pigeon/Pigeon.h
Original file line number Diff line number Diff line change
Expand Up @@ -268,7 +268,7 @@ extern void AnalysisImageUtilsSetup(id<FlutterBinaryMessenger> binaryMessenger,
NSObject<FlutterMessageCodec> *CameraInterfaceGetCodec(void);

@protocol CameraInterface
- (void)setupCameraSensors:(NSArray<PigeonSensor *> *)sensors aspectRatio:(NSString *)aspectRatio zoom:(NSNumber *)zoom mirrorFrontCamera:(NSNumber *)mirrorFrontCamera enablePhysicalButton:(NSNumber *)enablePhysicalButton flashMode:(NSString *)flashMode captureMode:(NSString *)captureMode enableImageStream:(NSNumber *)enableImageStream exifPreferences:(ExifPreferences *)exifPreferences videoOptions:(nullable VideoOptions *)videoOptions completion:(void (^)(NSNumber *_Nullable, FlutterError *_Nullable))completion;
- (void)setupCameraSensors:(NSArray<PigeonSensor *> *)sensors aspectRatio:(NSString *)aspectRatio zoom:(NSNumber *)zoom mirrorFrontCamera:(NSNumber *)mirrorFrontCamera enablePhysicalButton:(NSNumber *)enablePhysicalButton enableRotation:(NSNumber *)enableRotation flashMode:(NSString *)flashMode captureMode:(NSString *)captureMode enableImageStream:(NSNumber *)enableImageStream exifPreferences:(ExifPreferences *)exifPreferences videoOptions:(nullable VideoOptions *)videoOptions completion:(void (^)(NSNumber *_Nullable, FlutterError *_Nullable))completion;
/// @return `nil` only when `error != nil`.
- (nullable NSArray<NSString *> *)checkPermissionsPermissions:(NSArray<NSString *> *)permissions error:(FlutterError *_Nullable *_Nonnull)error;
/// Returns given [CamerAwesomePermission] list (as String). Location permission might be
Expand Down
15 changes: 8 additions & 7 deletions ios/Classes/Pigeon/Pigeon.m
Original file line number Diff line number Diff line change
Expand Up @@ -672,20 +672,21 @@ void CameraInterfaceSetup(id<FlutterBinaryMessenger> binaryMessenger, NSObject<C
binaryMessenger:binaryMessenger
codec:CameraInterfaceGetCodec()];
if (api) {
NSCAssert([api respondsToSelector:@selector(setupCameraSensors:aspectRatio:zoom:mirrorFrontCamera:enablePhysicalButton:flashMode:captureMode:enableImageStream:exifPreferences:videoOptions:completion:)], @"CameraInterface api (%@) doesn't respond to @selector(setupCameraSensors:aspectRatio:zoom:mirrorFrontCamera:enablePhysicalButton:flashMode:captureMode:enableImageStream:exifPreferences:videoOptions:completion:)", api);
NSCAssert([api respondsToSelector:@selector(setupCameraSensors:aspectRatio:zoom:mirrorFrontCamera:enablePhysicalButton:enableRotation:flashMode:captureMode:enableImageStream:exifPreferences:videoOptions:completion:)], @"CameraInterface api (%@) doesn't respond to @selector(setupCameraSensors:aspectRatio:zoom:mirrorFrontCamera:enablePhysicalButton:enableRotation:flashMode:captureMode:enableImageStream:exifPreferences:videoOptions:completion:)", api);
[channel setMessageHandler:^(id _Nullable message, FlutterReply callback) {
NSArray *args = message;
NSArray<PigeonSensor *> *arg_sensors = GetNullableObjectAtIndex(args, 0);
NSString *arg_aspectRatio = GetNullableObjectAtIndex(args, 1);
NSNumber *arg_zoom = GetNullableObjectAtIndex(args, 2);
NSNumber *arg_mirrorFrontCamera = GetNullableObjectAtIndex(args, 3);
NSNumber *arg_enablePhysicalButton = GetNullableObjectAtIndex(args, 4);
NSString *arg_flashMode = GetNullableObjectAtIndex(args, 5);
NSString *arg_captureMode = GetNullableObjectAtIndex(args, 6);
NSNumber *arg_enableImageStream = GetNullableObjectAtIndex(args, 7);
ExifPreferences *arg_exifPreferences = GetNullableObjectAtIndex(args, 8);
VideoOptions *arg_videoOptions = GetNullableObjectAtIndex(args, 9);
[api setupCameraSensors:arg_sensors aspectRatio:arg_aspectRatio zoom:arg_zoom mirrorFrontCamera:arg_mirrorFrontCamera enablePhysicalButton:arg_enablePhysicalButton flashMode:arg_flashMode captureMode:arg_captureMode enableImageStream:arg_enableImageStream exifPreferences:arg_exifPreferences videoOptions:arg_videoOptions completion:^(NSNumber *_Nullable output, FlutterError *_Nullable error) {
NSNumber *arg_enableRotation = GetNullableObjectAtIndex(args, 5);
NSString *arg_flashMode = GetNullableObjectAtIndex(args, 6);
NSString *arg_captureMode = GetNullableObjectAtIndex(args, 7);
NSNumber *arg_enableImageStream = GetNullableObjectAtIndex(args, 8);
ExifPreferences *arg_exifPreferences = GetNullableObjectAtIndex(args, 9);
VideoOptions *arg_videoOptions = GetNullableObjectAtIndex(args, 10);
[api setupCameraSensors:arg_sensors aspectRatio:arg_aspectRatio zoom:arg_zoom mirrorFrontCamera:arg_mirrorFrontCamera enablePhysicalButton:arg_enablePhysicalButton enableRotation:arg_enableRotation flashMode:arg_flashMode captureMode:arg_captureMode enableImageStream:arg_enableImageStream exifPreferences:arg_exifPreferences videoOptions:arg_videoOptions completion:^(NSNumber *_Nullable output, FlutterError *_Nullable error) {
callback(wrapResult(output, error));
}];
}];
Expand Down
4 changes: 3 additions & 1 deletion lib/camerawesome_plugin.dart
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,8 @@ class CamerawesomePlugin {
static Future<bool?> init(
SensorConfig sensorConfig,
bool enableImageStream,
bool enablePhysicalButton, {
bool enablePhysicalButton,
bool enableRotation, {
CaptureMode captureMode = CaptureMode.photo,
required ExifPreferences exifPreferences,
required VideoOptions? videoOptions,
Expand All @@ -195,6 +196,7 @@ class CamerawesomePlugin {
sensorConfig.zoom,
mirrorFrontCamera,
enablePhysicalButton,
enableRotation,
sensorConfig.flashMode.name.toUpperCase(),
captureMode.name.toUpperCase(),
enableImageStream,
Expand Down
2 changes: 2 additions & 0 deletions lib/pigeon.dart
Original file line number Diff line number Diff line change
Expand Up @@ -737,6 +737,7 @@ class CameraInterface {
double arg_zoom,
bool arg_mirrorFrontCamera,
bool arg_enablePhysicalButton,
bool arg_enableRotation,
String arg_flashMode,
String arg_captureMode,
bool arg_enableImageStream,
Expand All @@ -751,6 +752,7 @@ class CameraInterface {
arg_zoom,
arg_mirrorFrontCamera,
arg_enablePhysicalButton,
arg_enableRotation,
arg_flashMode,
arg_captureMode,
arg_enableImageStream,
Expand Down
5 changes: 5 additions & 0 deletions lib/src/orchestrator/camera_context.dart
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,8 @@ class CameraContext {

final bool enablePhysicalButton;

final bool enableRotation;

/// allows to create dynamic analysis using the current preview
/// Image analysis controller. You may use it to start or stop image analysis.
final AnalysisController? analysisController;
Expand Down Expand Up @@ -69,6 +71,7 @@ class CameraContext {
required this.exifPreferences,
required this.filterController,
required this.enablePhysicalButton,
required this.enableRotation,
required this.availableFilters,
this.onPermissionsResult,
}) {
Expand All @@ -91,12 +94,14 @@ class CameraContext {
required ExifPreferences exifPreferences,
required AwesomeFilter filter,
required bool enablePhysicalButton,
required bool enableRotation,
List<AwesomeFilter>? availableFilters,
}) : this._(
initialCaptureMode: initialCaptureMode,
sensorConfigController: BehaviorSubject.seeded(sensorConfig),
filterController: BehaviorSubject.seeded(filter),
enablePhysicalButton: enablePhysicalButton,
enableRotation: enableRotation,
onPermissionsResult: onPermissionsResult,
saveConfig: saveConfig,
analysisController: onImageForAnalysis != null
Expand Down
Loading