Skip to content
Merged
Show file tree
Hide file tree
Changes from 6 commits
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
01ad812
Set higher resolution when using max preset
sergeidesenko Jul 30, 2023
5f5cabc
Merge remote-tracking branch 'upstream/main' into camera_avfoundation…
sergeidesenko Oct 27, 2023
f9f302f
chore: update changelog
sergeidesenko Oct 27, 2023
e5a33f6
chore: update changelog and pubspec
sergeidesenko Oct 27, 2023
d3ce411
refactor: add comments
sergeidesenko Oct 27, 2023
5813f25
chore: update pubspec
sergeidesenko Oct 27, 2023
60e043a
feat(tests): add convenience method for camera init
sergeidesenko Jan 22, 2024
9830404
feat(tests): add tests for setting resolutionPresets
sergeidesenko Jan 22, 2024
87b0c59
chore(tests): add tests file to .pbxproj
sergeidesenko Jan 22, 2024
0c29019
chore: fix formatting for updated files
sergeidesenko Jan 22, 2024
ae0210f
fix: don't update the changelog
sergeidesenko Jan 31, 2024
0c8b21a
refactor: remove todo and renaming
sergeidesenko Jan 31, 2024
37ffaa7
Merge remote-tracking branch 'upstream/main' into camera_avfoundation…
sergeidesenko Jan 31, 2024
70deac4
Merge branch 'main' into camera_avfoundation-max-resolution
sergeidesenko Feb 2, 2024
0fe1ac7
feat: add tests for different resolution presets
sergeidesenko Feb 2, 2024
c314755
refactor: update comment
sergeidesenko Feb 2, 2024
ec1b896
refactor: change tests to use DI
sergeidesenko Feb 2, 2024
5e6f1f5
refactor: rename method
sergeidesenko Feb 2, 2024
decce1e
refactor: rename method
sergeidesenko Feb 2, 2024
832cc7b
refactor: cleaner DI
sergeidesenko Feb 13, 2024
ddfe778
refactor: update comments
sergeidesenko Feb 21, 2024
5c01c8c
refactor: update comment to match arguments
sergeidesenko Feb 21, 2024
0c40901
refactor: rename types
sergeidesenko Feb 22, 2024
42e9cfa
Merge branch 'main' into camera_avfoundation-max-resolution
sergeidesenko Mar 1, 2024
8e019b3
refactor: address code review
sergeidesenko Mar 1, 2024
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
4 changes: 4 additions & 0 deletions packages/camera/camera/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
## 0.10.5+6

* Fixes bug where max resolution preset does not produce highest available resolution on iOS.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this doesn't need a bump

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fixed


## 0.10.5+5

* Fixes bug where old camera resources were not disposed when switching between camera descriptions.
Expand Down
2 changes: 1 addition & 1 deletion packages/camera/camera/pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ description: A Flutter plugin for controlling the camera. Supports previewing
Dart.
repository: https://github.com/flutter/packages/tree/main/packages/camera/camera
issue_tracker: https://github.com/flutter/flutter/issues?q=is%3Aissue+is%3Aopen+label%3A%22p%3A+camera%22
version: 0.10.5+5
version: 0.10.5+6

environment:
sdk: ">=2.19.0 <4.0.0"
Expand Down
4 changes: 4 additions & 0 deletions packages/camera/camera_avfoundation/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
## 0.9.13+7

* Fixes bug where max resolution preset does not produce highest available resolution on iOS.

## 0.9.13+6

* Fixes incorrect use of `NSError` that could cause crashes on launch.
Expand Down
40 changes: 40 additions & 0 deletions packages/camera/camera_avfoundation/ios/Classes/FLTCam.m
Original file line number Diff line number Diff line change
Expand Up @@ -348,6 +348,29 @@ - (NSString *)getTemporaryFilePathWithExtension:(NSString *)extension
- (BOOL)setCaptureSessionPreset:(FLTResolutionPreset)resolutionPreset withError:(NSError **)error {
switch (resolutionPreset) {
case FLTResolutionPresetMax:
{
AVCaptureDeviceFormat *bestFormat = [self getHighestResolutionFormatFor:_captureDevice];
if ( bestFormat ) {
_videoCaptureSession.sessionPreset = AVCaptureSessionPresetInputPriority;
if ( [_captureDevice lockForConfiguration:NULL] == YES ) {

// set best device format and finish device configuration
_captureDevice.activeFormat = bestFormat;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is this only required in best format but not other resolutions?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In all other cases device is configured with sessionPreset through capture session, like this:
_videoCaptureSession.sessionPreset = AVCaptureSessionPreset3840x2160;

The max resolution case is different because there is no predetermined option

[_captureDevice unlockForConfiguration];

// set preview size based on values from the current _captureDevice
_previewSize =
CGSizeMake(_captureDevice.activeFormat.highResolutionStillImageDimensions.width,
_captureDevice.activeFormat.highResolutionStillImageDimensions.height);
break;
}
}
}
if ([_videoCaptureSession canSetSessionPreset:AVCaptureSessionPreset3840x2160]) {
_videoCaptureSession.sessionPreset = AVCaptureSessionPreset3840x2160;
_previewSize = CGSizeMake(3840, 2160);
break;
}
case FLTResolutionPresetUltraHigh:
if ([_videoCaptureSession canSetSessionPreset:AVCaptureSessionPreset3840x2160]) {
_videoCaptureSession.sessionPreset = AVCaptureSessionPreset3840x2160;
Expand Down Expand Up @@ -403,6 +426,23 @@ - (BOOL)setCaptureSessionPreset:(FLTResolutionPreset)resolutionPreset withError:
return YES;
}

/// Finds the highest available resolution in terms of pixel count for the given device
- (AVCaptureDeviceFormat *)getHighestResolutionFormatFor:(AVCaptureDevice*)captureDevice {
AVCaptureDeviceFormat *bestFormat = nil;
NSUInteger maxPixelCount = 0;
for ( AVCaptureDeviceFormat *format in [_captureDevice formats] ) {
CMVideoDimensions res = CMVideoFormatDescriptionGetDimensions(format.formatDescription);
NSUInteger height = res.height;
NSUInteger width = res.width;
NSUInteger pixelCount = height * width;
if ( pixelCount > maxPixelCount ) {
maxPixelCount = pixelCount;
bestFormat = format;
}
}
return bestFormat;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

what if [_captureDevice formats] is empty? do we want to handle nil case?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We do handle it actually, this method returns nil if there is no bestFormat and switch case from setCaptureSessionPreset doesn't break and falls through to other cases

}

- (void)captureOutput:(AVCaptureOutput *)output
didOutputSampleBuffer:(CMSampleBufferRef)sampleBuffer
fromConnection:(AVCaptureConnection *)connection {
Expand Down
2 changes: 1 addition & 1 deletion packages/camera/camera_avfoundation/pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ name: camera_avfoundation
description: iOS implementation of the camera plugin.
repository: https://github.com/flutter/packages/tree/main/packages/camera/camera_avfoundation
issue_tracker: https://github.com/flutter/flutter/issues?q=is%3Aissue+is%3Aopen+label%3A%22p%3A+camera%22
version: 0.9.13+6
version: 0.9.13+7

environment:
sdk: ">=2.19.0 <4.0.0"
Expand Down