-
Notifications
You must be signed in to change notification settings - Fork 3.6k
[camera_avfoundation] Set highest available resolution for ResolutionPreset.Max #5245
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 6 commits
01ad812
5f5cabc
f9f302f
e5a33f6
d3ce411
5813f25
60e043a
9830404
87b0c59
0c29019
ae0210f
0c8b21a
37ffaa7
70deac4
0fe1ac7
c314755
ec1b896
5e6f1f5
decce1e
832cc7b
ddfe778
5c01c8c
0c40901
42e9cfa
8e019b3
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -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; | ||
|
||
| [_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; | ||
|
|
@@ -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; | ||
|
||
| } | ||
|
|
||
| - (void)captureOutput:(AVCaptureOutput *)output | ||
| didOutputSampleBuffer:(CMSampleBufferRef)sampleBuffer | ||
| fromConnection:(AVCaptureConnection *)connection { | ||
|
|
||
There was a problem hiding this comment.
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
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
fixed