Skip to content
This repository was archived by the owner on Feb 22, 2023. It is now read-only.
Closed
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 @@ -4,7 +4,7 @@

package io.flutter.plugins.camera;

import static io.flutter.plugins.camera.CameraUtils.computeBestPreviewSize;
import static io.flutter.plugins.camera.CameraUtils.computeBestCaptureSize;

import android.annotation.SuppressLint;
import android.annotation.TargetApi;
Expand Down Expand Up @@ -85,6 +85,7 @@ public class Camera {
private final String cameraName;
private final Size captureSize;
private final Size previewSize;
private final boolean enableTakePictureWithMaxResolution;
private final boolean enableAudio;
private final Context applicationContext;
private final CamcorderProfile recordingProfile;
Expand Down Expand Up @@ -125,12 +126,14 @@ public Camera(
final DartMessenger dartMessenger,
final String cameraName,
final String resolutionPreset,
final boolean enableTakePictureWithMaxResolution,
final boolean enableAudio)
throws CameraAccessException {
if (activity == null) {
throw new IllegalStateException("No activity available!");
}
this.cameraName = cameraName;
this.enableTakePictureWithMaxResolution = enableTakePictureWithMaxResolution;
this.enableAudio = enableAudio;
this.flutterTexture = flutterTexture;
this.dartMessenger = dartMessenger;
Expand All @@ -150,8 +153,18 @@ public Camera(
ResolutionPreset preset = ResolutionPreset.valueOf(resolutionPreset);
recordingProfile =
CameraUtils.getBestAvailableCamcorderProfileForResolutionPreset(cameraName, preset);
captureSize = new Size(recordingProfile.videoFrameWidth, recordingProfile.videoFrameHeight);
previewSize = computeBestPreviewSize(cameraName, preset);
previewSize = new Size(recordingProfile.videoFrameWidth, recordingProfile.videoFrameHeight);
if (enableTakePictureWithMaxResolution) {
captureSize =
computeBestCaptureSize(
cameraCharacteristics.get(CameraCharacteristics.SCALER_STREAM_CONFIGURATION_MAP));
Log.i("Camera", "enableTakePictureWithMaxResolution");
} else {
captureSize = new Size(recordingProfile.videoFrameWidth, recordingProfile.videoFrameHeight);
}
Log.i("Camera", "[Preview Resolution] :" + previewSize);
Log.i("Camera", "[Capture Resolution] :" + captureSize);

cameraZoom =
new CameraZoom(
cameraCharacteristics.get(CameraCharacteristics.SENSOR_INFO_ACTIVE_ARRAY_SIZE),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -82,16 +82,6 @@ static PlatformChannel.DeviceOrientation deserializeDeviceOrientation(String ori
}
}

static Size computeBestPreviewSize(String cameraName, ResolutionPreset preset) {
if (preset.ordinal() > ResolutionPreset.high.ordinal()) {
preset = ResolutionPreset.high;
}

CamcorderProfile profile =
getBestAvailableCamcorderProfileForResolutionPreset(cameraName, preset);
return new Size(profile.videoFrameWidth, profile.videoFrameHeight);
}

static Size computeBestCaptureSize(StreamConfigurationMap streamConfigurationMap) {
// For still image captures, we use the largest available size.
return Collections.max(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -352,6 +352,8 @@ void stopListening() {
private void instantiateCamera(MethodCall call, Result result) throws CameraAccessException {
String cameraName = call.argument("cameraName");
String resolutionPreset = call.argument("resolutionPreset");
boolean enableTakePictureWithMaxResolution =
call.argument("enableTakePictureWithMaxResolution");
boolean enableAudio = call.argument("enableAudio");
TextureRegistry.SurfaceTextureEntry flutterSurfaceTexture =
textureRegistry.createSurfaceTexture();
Expand All @@ -365,6 +367,7 @@ private void instantiateCamera(MethodCall call, Result result) throws CameraAcce
dartMessenger,
cameraName,
resolutionPreset,
enableTakePictureWithMaxResolution,
enableAudio);

Map<String, Object> reply = new HashMap<>();
Expand Down
8 changes: 7 additions & 1 deletion packages/camera/camera/ios/Classes/CameraPlugin.m
Original file line number Diff line number Diff line change
Expand Up @@ -306,6 +306,7 @@ @interface FLTCam : NSObject <FlutterTexture,
AVCaptureAudioDataOutputSampleBufferDelegate>
@property(readonly, nonatomic) int64_t textureId;
@property(nonatomic, copy) void (^onFrameAvailable)(void);
@property BOOL enableTakePictureWithMaxResolution;
@property BOOL enableAudio;
@property(nonatomic) FLTImageStreamHandler *imageStreamHandler;
@property(nonatomic) FlutterMethodChannel *methodChannel;
Expand Down Expand Up @@ -353,6 +354,7 @@ @implementation FLTCam {

- (instancetype)initWithCameraName:(NSString *)cameraName
resolutionPreset:(NSString *)resolutionPreset
enableTakePictureWithMaxResolution:(BOOL)enableTakePictureWithMaxResolution
enableAudio:(BOOL)enableAudio
orientation:(UIDeviceOrientation)orientation
dispatchQueue:(dispatch_queue_t)dispatchQueue
Expand All @@ -364,6 +366,7 @@ - (instancetype)initWithCameraName:(NSString *)cameraName
} @catch (NSError *e) {
*error = e;
}
_enableTakePictureWithMaxResolution = enableTakePictureWithMaxResolution;
_enableAudio = enableAudio;
_dispatchQueue = dispatchQueue;
_captureSession = [[AVCaptureSession alloc] init];
Expand Down Expand Up @@ -459,7 +462,8 @@ - (void)updateOrientation:(UIDeviceOrientation)orientation

- (void)captureToFile:(FlutterResult)result API_AVAILABLE(ios(10)) {
AVCapturePhotoSettings *settings = [AVCapturePhotoSettings photoSettings];
if (_resolutionPreset == max) {
if (_resolutionPreset == max || _enableTakePictureWithMaxResolution == true) {
NSLog(@"setHighResolutionPhotoEnabled");
[settings setHighResolutionPhotoEnabled:YES];
}

Expand Down Expand Up @@ -1332,10 +1336,12 @@ - (void)handleMethodCallAsync:(FlutterMethodCall *)call result:(FlutterResult)re
} else if ([@"create" isEqualToString:call.method]) {
NSString *cameraName = call.arguments[@"cameraName"];
NSString *resolutionPreset = call.arguments[@"resolutionPreset"];
NSNumber *enableTakePictureWithMaxResolution = call.arguments[@"enableTakePictureWithMaxResolution"];
NSNumber *enableAudio = call.arguments[@"enableAudio"];
NSError *error;
FLTCam *cam = [[FLTCam alloc] initWithCameraName:cameraName
resolutionPreset:resolutionPreset
enableTakePictureWithMaxResolution:[enableTakePictureWithMaxResolution boolValue]
enableAudio:[enableAudio boolValue]
orientation:[[UIDevice currentDevice] orientation]
dispatchQueue:_dispatchQueue
Expand Down
7 changes: 7 additions & 0 deletions packages/camera/camera/lib/src/camera_controller.dart
Original file line number Diff line number Diff line change
Expand Up @@ -206,6 +206,7 @@ class CameraController extends ValueNotifier<CameraValue> {
CameraController(
this.description,
this.resolutionPreset, {
this.enableTakePictureWithMaxResolution = false,
this.enableAudio = true,
this.imageFormatGroup,
}) : super(const CameraValue.uninitialized());
Expand All @@ -221,6 +222,11 @@ class CameraController extends ValueNotifier<CameraValue> {
/// See also: [ResolutionPreset].
final ResolutionPreset resolutionPreset;

/// Whether to use max resolution for takePicture method,
/// It may be higher than ResolutionPreset.max, because the max resolution is for still image.
/// When the value is false, resolution set in resolutionPreset will be used for takePicture.
final bool enableTakePictureWithMaxResolution;

/// Whether to include audio when recording a video.
final bool enableAudio;

Expand Down Expand Up @@ -272,6 +278,7 @@ class CameraController extends ValueNotifier<CameraValue> {
_cameraId = await CameraPlatform.instance.createCamera(
description,
resolutionPreset,
enableTakePictureWithMaxResolution: enableTakePictureWithMaxResolution,
enableAudio: enableAudio,
);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,7 @@ class MethodChannelCamera extends CameraPlatform {
Future<int> createCamera(
CameraDescription cameraDescription,
ResolutionPreset? resolutionPreset, {
bool enableTakePictureWithMaxResolution = false,
bool enableAudio = false,
}) async {
try {
Expand All @@ -91,6 +92,8 @@ class MethodChannelCamera extends CameraPlatform {
'resolutionPreset': resolutionPreset != null
? _serializeResolutionPreset(resolutionPreset)
: null,
'enableTakePictureWithMaxResolution':
enableTakePictureWithMaxResolution,
'enableAudio': enableAudio,
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ abstract class CameraPlatform extends PlatformInterface {
Future<int> createCamera(
CameraDescription cameraDescription,
ResolutionPreset? resolutionPreset, {
bool enableTakePictureWithMaxResolution = false,
bool enableAudio = false,
}) {
throw UnimplementedError('createCamera() is not implemented.');
Expand Down
4 changes: 4 additions & 0 deletions packages/connectivity/connectivity_macos/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
## 0.2.1

* Add `implements` to pubspec.yaml.

## 0.2.0

* Remove placeholder Dart file.
Expand Down
10 changes: 9 additions & 1 deletion packages/connectivity/connectivity_macos/pubspec.yaml
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
name: connectivity_macos
description: macOS implementation of the connectivity plugin.
version: 0.2.0
version: 0.2.1
homepage: https://github.com/flutter/plugins/tree/master/packages/connectivity/connectivity_macos

flutter:
plugin:
implements: connectivity_platform_interface
platforms:
macos:
pluginClass: ConnectivityPlugin
Expand All @@ -16,6 +17,13 @@ environment:
dependencies:
flutter:
sdk: flutter
# The implementation of this plugin doesn't explicitly depend on the method channel
# defined in the platform interface.
# To prevent potential breakages, this dependency is added.
#
# In the future, this plugin's platform code should be able to reference the
# interface's platform code. (Android already supports this).
connectivity_platform_interface: ^2.0.0

dev_dependencies:
pedantic: ^1.10.0
5 changes: 2 additions & 3 deletions packages/path_provider/path_provider/lib/path_provider.dart
Original file line number Diff line number Diff line change
Expand Up @@ -42,9 +42,8 @@ class MissingPlatformDirectoryException implements Exception {
}

PathProviderPlatform get _platform {
// This is to manually endorse Dart implementations until automatic
// registration of Dart plugins is implemented. For details see
// https://github.com/flutter/flutter/issues/52267.
// TODO(egarciad): Remove once auto registration lands on Flutter stable.
// https://github.com/flutter/flutter/issues/81421.
if (_manualDartRegistrationNeeded) {
// Only do the initial registration if it hasn't already been overridden
// with a non-default instance.
Expand Down
5 changes: 5 additions & 0 deletions packages/path_provider/path_provider_linux/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
## 2.0.1

* Add `implements` to pubspec.yaml.
* Add `registerWith` method to the main Dart class.

## 2.0.0

* Migrate to null safety.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import 'package:xdg_directories/xdg_directories.dart' as xdg;
/// This class implements the `package:path_provider` functionality for linux
class PathProviderLinux extends PathProviderPlatform {
/// Registers this class as the default instance of [PathProviderPlatform]
static void register() {
static void registerWith() {
PathProviderPlatform.instance = PathProviderLinux();
}

Expand Down
3 changes: 2 additions & 1 deletion packages/path_provider/path_provider_linux/pubspec.yaml
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
name: path_provider_linux
description: linux implementation of the path_provider plugin
version: 2.0.0
version: 2.0.1
homepage: https://github.com/flutter/plugins/tree/master/packages/path_provider/path_provider_linux

flutter:
plugin:
implements: path_provider
platforms:
linux:
dartPluginClass: PathProviderLinux
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,11 @@ import 'package:path_provider_platform_interface/path_provider_platform_interfac

void main() {
TestWidgetsFlutterBinding.ensureInitialized();
PathProviderLinux.register();
PathProviderLinux.registerWith();

setUp(() {});

tearDown(() {});
test('registered instance', () {
expect(PathProviderPlatform.instance, isA<PathProviderLinux>());
});

test('getTemporaryPath', () async {
final PathProviderPlatform plugin = PathProviderPlatform.instance;
Expand Down
4 changes: 4 additions & 0 deletions packages/path_provider/path_provider_macos/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
## 2.0.1

* Add `implements` to pubspec.yaml.

## 2.0.0

* Update Dart SDK constraint for null safety compatibility.
Expand Down
3 changes: 2 additions & 1 deletion packages/path_provider/path_provider_macos/pubspec.yaml
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
name: path_provider_macos
description: macOS implementation of the path_provider plugin
version: 2.0.0
version: 2.0.1
homepage: https://github.com/flutter/plugins/tree/master/packages/path_provider/path_provider_macos

flutter:
plugin:
implements: path_provider
platforms:
macos:
pluginClass: PathProviderPlugin
Expand Down
5 changes: 5 additions & 0 deletions packages/path_provider/path_provider_windows/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
## 2.0.2

* Add `implements` to pubspec.yaml.
* Add `registerWith()` to the Dart main class.

## 2.0.1

* Fix a crash when a known folder can't be located.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,11 @@ class VersionInfoQuerier {
///
/// This class implements the `package:path_provider` functionality for Windows.
class PathProviderWindows extends PathProviderPlatform {
/// Registers the Windows implementation.
static void registerWith() {
PathProviderPlatform.instance = PathProviderWindows();
}

/// The object to use for performing VerQueryValue calls.
@visibleForTesting
VersionInfoQuerier versionInfoQuerier = VersionInfoQuerier();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,11 @@ class PathProviderWindows extends PathProviderPlatform {
/// compile-time dependencies, and should never actually be created.
PathProviderWindows() : assert(false);

/// Registers the Windows implementation.
static void registerWith() {
PathProviderPlatform.instance = PathProviderWindows();
}

/// Stub; see comment on VersionInfoQuerier.
VersionInfoQuerier versionInfoQuerier = VersionInfoQuerier();

Expand Down
3 changes: 2 additions & 1 deletion packages/path_provider/path_provider_windows/pubspec.yaml
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
name: path_provider_windows
description: Windows implementation of the path_provider plugin
homepage: https://github.com/flutter/plugins/tree/master/packages/path_provider/path_provider_windows
version: 2.0.1
version: 2.0.2

flutter:
plugin:
implements: path_provider
platforms:
windows:
dartPluginClass: PathProviderWindows
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import 'dart:ffi';
import 'dart:io';

import 'package:flutter_test/flutter_test.dart';
import 'package:path_provider_platform_interface/path_provider_platform_interface.dart';
import 'package:path_provider_windows/path_provider_windows.dart';

// A fake VersionInfoQuerier that just returns preset responses.
Expand All @@ -18,6 +19,11 @@ class FakeVersionInfoQuerier implements VersionInfoQuerier {
}

void main() {
test('registered instance', () {
PathProviderWindows.registerWith();
expect(PathProviderPlatform.instance, isA<PathProviderWindows>());
});

test('getTemporaryPath', () async {
final PathProviderWindows pathProvider = PathProviderWindows();
expect(await pathProvider.getTemporaryPath(), contains(r'C:\'));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,8 @@ class SharedPreferences {
static bool _manualDartRegistrationNeeded = true;

static SharedPreferencesStorePlatform get _store {
// This is to manually endorse the Linux implementation until automatic
// registration of dart plugins is implemented. For details see
// https://github.com/flutter/flutter/issues/52267.
// TODO(egarciad): Remove once auto registration lands on Flutter stable.
// https://github.com/flutter/flutter/issues/81421.
if (_manualDartRegistrationNeeded) {
// Only do the initial registration if it hasn't already been overridden
// with a non-default instance.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
## 2.0.1

* Add `implements` to the pubspec.
* Add `registerWith` to the Dart main class.

## 2.0.0

* Migrate to null-safety.
Expand Down
Loading