-
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 1 commit
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
- Loading branch information
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -24,28 +24,29 @@ - (void)testResolutionPresetWithCanSetSessionPresetMax_mustUpdateCaptureSessionP | |
| OCMStub([videoSessionMock addInputWithNoConnections:[OCMArg any]]); // no-op | ||
| OCMStub([videoSessionMock canSetSessionPreset:[OCMArg any]]).andReturn(YES); | ||
| OCMExpect([videoSessionMock setSessionPreset:[OCMArg checkWithBlock:^BOOL(id value) { | ||
| // Return YES if the value is one of the expected presets | ||
| return [value isEqualToString:expectedUltraHighPreset] || [value isEqualToString:expectedMaxPreset]; | ||
| }]]); | ||
| // Return YES if the value is one of the expected presets | ||
| return [value isEqualToString:expectedUltraHighPreset] || | ||
| [value isEqualToString:expectedMaxPreset]; | ||
|
||
| }]]); | ||
|
|
||
| FLTCreateCamWithVideoCaptureSession(videoSessionMock, @"max"); | ||
|
|
||
|
|
||
| FLTCam *cam = FLTCreateCamWithVideoCaptureSession(videoSessionMock, @"max"); | ||
|
|
||
| OCMVerifyAll(videoSessionMock); | ||
| } | ||
|
|
||
| - (void)testResolutionPresetWithCanSetSessionPresetUltraHigh_mustUpdateCaptureSessionPreset { //TODO | ||
| - (void) | ||
| testResolutionPresetWithCanSetSessionPresetUltraHigh_mustUpdateCaptureSessionPreset { // TODO | ||
|
||
| NSString *expectedPreset = AVCaptureSessionPreset3840x2160; | ||
|
|
||
| id videoSessionMock = OCMClassMock([AVCaptureSession class]); | ||
| OCMStub([videoSessionMock addInputWithNoConnections:[OCMArg any]]); // no-op | ||
|
||
| OCMStub([videoSessionMock canSetSessionPreset:[OCMArg any]]).andReturn(YES); | ||
|
|
||
| // expect that setting "ultraHigh" resolutionPreset correctly updates videoCaptureSession | ||
| OCMExpect([videoSessionMock setSessionPreset:expectedPreset]); | ||
| FLTCam *cam = FLTCreateCamWithVideoCaptureSession(videoSessionMock, @"ultraHigh"); | ||
|
|
||
| FLTCreateCamWithVideoCaptureSession(videoSessionMock, @"ultraHigh"); | ||
|
|
||
| OCMVerifyAll(videoSessionMock); | ||
| } | ||
|
|
||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -347,25 +347,23 @@ - (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; | ||
| } | ||
| } | ||
| 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; | ||
| } | ||
| } | ||
| } | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Nit: This should be after the code below, enclosing the entire case implementation, otherwise the indentation is very confusing.
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. fixed everything Out of curiosity - what's your definition of nit in this context? I thought these are not compulsory
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I generally use it to indicate that something is a very small change. I wasn't aware there was a doc that equated it with being optional; I'll stop using it given that. |
||
| if ([_videoCaptureSession canSetSessionPreset:AVCaptureSessionPreset3840x2160]) { | ||
| _videoCaptureSession.sessionPreset = AVCaptureSessionPreset3840x2160; | ||
| _previewSize = CGSizeMake(3840, 2160); | ||
|
|
@@ -427,20 +425,20 @@ - (BOOL)setCaptureSessionPreset:(FLTResolutionPreset)resolutionPreset withError: | |
| } | ||
|
|
||
| /// 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; | ||
| } | ||
| - (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; | ||
| } | ||
| return bestFormat; | ||
| } | ||
|
|
||
| - (void)captureOutput:(AVCaptureOutput *)output | ||
|
|
||
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.
Nit: this file should be
...Tests.m, not...Test.m, to follow our standard convention.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