Skip to content

Commit c2fea1e

Browse files
committed
remove deprecations
1 parent 955249f commit c2fea1e

File tree

6 files changed

+104
-37
lines changed

6 files changed

+104
-37
lines changed

packages/camera/camera_avfoundation/example/ios/RunnerTests/FLTCamSetDeviceOrientationTests.swift

Lines changed: 31 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -19,13 +19,15 @@ final class FLTCamSetDeviceOrientationTests: XCTestCase {
1919
let mockCapturePhotoOutput = MockCapturePhotoOutput()
2020
let mockPhotoCaptureConnection = MockCaptureConnection()
2121
mockPhotoCaptureConnection.isVideoOrientationSupported = true
22+
mockPhotoCaptureConnection.isVideoRotationAngleSupported = true
2223

2324
mockCapturePhotoOutput.connectionWithMediaTypeStub = { _ in mockPhotoCaptureConnection }
2425
camera.capturePhotoOutput = mockCapturePhotoOutput
2526

2627
let mockCaptureVideoDataOutput = MockCaptureVideoDataOutput()
2728
let mockVideoCaptureConnection = MockCaptureConnection()
2829
mockVideoCaptureConnection.isVideoOrientationSupported = true
30+
mockVideoCaptureConnection.isVideoRotationAngleSupported = true
2931

3032
mockCaptureVideoDataOutput.connectionWithMediaTypeStub = { _ in mockVideoCaptureConnection }
3133
camera.captureVideoOutput = mockCaptureVideoDataOutput
@@ -35,72 +37,72 @@ final class FLTCamSetDeviceOrientationTests: XCTestCase {
3537

3638
func testSetDeviceOrientation_setsOrientationsOfCaptureConnections() {
3739
let (camera, mockPhotoCaptureConnection, mockVideoCaptureConnection) = createCamera()
38-
var photoSetVideoOrientationCalled = false
39-
mockPhotoCaptureConnection.setVideoOrientationStub = { orientation in
40+
41+
let photoSetVideoOrientationExpectation = expectation(description: "photo setVideoRotationAngle called")
42+
mockPhotoCaptureConnection.setVideoRotationAngleStub = { orientation in
4043
// Device orientation is flipped compared to video orientation. When UIDeviceOrientation
4144
// is landscape left the video orientation should be landscape right.
42-
XCTAssertEqual(orientation, .landscapeRight)
43-
photoSetVideoOrientationCalled = true
45+
XCTAssertEqual(orientation, 180)
46+
photoSetVideoOrientationExpectation.fulfill()
4447
}
45-
46-
var videoSetVideoOrientationCalled = false
47-
mockVideoCaptureConnection.setVideoOrientationStub = { orientation in
48+
49+
let videoSetVideoOrientationExpectation = expectation(description: "video setVideoRotationAngle called")
50+
mockVideoCaptureConnection.setVideoRotationAngleStub = { orientation in
4851
// Device orientation is flipped compared to video orientation. When UIDeviceOrientation
4952
// is landscape left the video orientation should be landscape right.
50-
XCTAssertEqual(orientation, .landscapeRight)
51-
videoSetVideoOrientationCalled = true
53+
XCTAssertEqual(orientation, 180)
54+
videoSetVideoOrientationExpectation.fulfill()
5255
}
5356

5457
camera.deviceOrientation = .landscapeLeft
55-
56-
XCTAssertTrue(photoSetVideoOrientationCalled)
57-
XCTAssertTrue(videoSetVideoOrientationCalled)
58+
59+
waitForExpectations(timeout: 30, handler: nil)
5860
}
5961

6062
func
6163
testSetDeviceOrientation_setsLockedOrientationsOfCaptureConnection_ifCaptureOrientationIsLocked()
6264
{
6365
let (camera, mockPhotoCaptureConnection, mockVideoCaptureConnection) = createCamera()
64-
var photoSetVideoOrientationCalled = false
65-
mockPhotoCaptureConnection.setVideoOrientationStub = { orientation in
66-
XCTAssertEqual(orientation, .portraitUpsideDown)
67-
photoSetVideoOrientationCalled = true
66+
let photoSetVideoOrientationExpectation = expectation(description: "photo setVideoRotationAngle called")
67+
photoSetVideoOrientationExpectation.expectedFulfillmentCount = 2
68+
mockPhotoCaptureConnection.setVideoRotationAngleStub = { orientation in
69+
XCTAssertEqual(orientation, 270)
70+
photoSetVideoOrientationExpectation.fulfill()
6871
}
69-
70-
var videoSetVideoOrientationCalled = false
71-
mockVideoCaptureConnection.setVideoOrientationStub = { orientation in
72-
XCTAssertEqual(orientation, .portraitUpsideDown)
73-
videoSetVideoOrientationCalled = true
72+
73+
let videoSetVideoOrientationExpectation = expectation(description: "video setVideoRotationAngle called")
74+
videoSetVideoOrientationExpectation.expectedFulfillmentCount = 2
75+
mockVideoCaptureConnection.setVideoRotationAngleStub = { orientation in
76+
XCTAssertEqual(orientation, 270)
77+
videoSetVideoOrientationExpectation.fulfill()
7478
}
75-
7679
camera.lockCaptureOrientation(FCPPlatformDeviceOrientation.portraitDown)
7780

7881
camera.deviceOrientation = .landscapeLeft
79-
80-
XCTAssertTrue(photoSetVideoOrientationCalled)
81-
XCTAssertTrue(videoSetVideoOrientationCalled)
82+
83+
waitForExpectations(timeout: 30, handler: nil)
8284
}
8385

8486
func testSetDeviceOrientation_doesNotSetOrientations_ifRecordingIsInProgress() {
8587
let (camera, mockPhotoCaptureConnection, mockVideoCaptureConnection) = createCamera()
8688

8789
camera.startVideoRecording(completion: { _ in }, messengerForStreaming: nil)
8890

89-
mockPhotoCaptureConnection.setVideoOrientationStub = { _ in XCTFail() }
90-
mockVideoCaptureConnection.setVideoOrientationStub = { _ in XCTFail() }
91+
mockPhotoCaptureConnection.setVideoRotationAngleStub = { _ in XCTFail() }
92+
mockVideoCaptureConnection.setVideoRotationAngleStub = { _ in XCTFail() }
9193

9294
camera.deviceOrientation = .landscapeLeft
9395
}
9496

9597
func testSetDeviceOrientation_doesNotSetOrientations_forDuplicateUpdates() {
9698
let (camera, mockPhotoCaptureConnection, mockVideoCaptureConnection) = createCamera()
9799
var photoSetVideoOrientationCallCount = 0
98-
mockPhotoCaptureConnection.setVideoOrientationStub = { _ in
100+
mockPhotoCaptureConnection.setVideoRotationAngleStub = { _ in
99101
photoSetVideoOrientationCallCount += 1
100102
}
101103

102104
var videoSetVideoOrientationCallCount = 0
103-
mockVideoCaptureConnection.setVideoOrientationStub = { _ in
105+
mockVideoCaptureConnection.setVideoRotationAngleStub = { _ in
104106
videoSetVideoOrientationCallCount += 1
105107
}
106108

packages/camera/camera_avfoundation/example/ios/RunnerTests/Mocks/MockCaptureConnection.swift

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ import camera_avfoundation
1212
/// A mock implementation of `FLTCaptureConnection` that allows injecting a custom implementation.
1313
final class MockCaptureConnection: NSObject, FLTCaptureConnection {
1414
var setVideoOrientationStub: ((AVCaptureVideoOrientation) -> Void)?
15+
var setVideoRotationAngleStub: ((CGFloat) -> Void)?
1516

1617
var connection: AVCaptureConnection {
1718
preconditionFailure("Attempted to access unimplemented property: connection")
@@ -23,7 +24,19 @@ final class MockCaptureConnection: NSObject, FLTCaptureConnection {
2324
setVideoOrientationStub?(newValue)
2425
}
2526
}
27+
28+
var videoRotationAngle: CGFloat {
29+
get { 90 }
30+
set {
31+
setVideoRotationAngleStub?(newValue)
32+
}
33+
}
2634
var inputPorts: [AVCaptureInput.Port] = []
2735
var isVideoMirroringSupported = false
2836
var isVideoOrientationSupported = false
37+
var isVideoRotationAngleSupported = false
38+
39+
func isVideoRotationAngleSupported(_ videoRotationAngle: CGFloat) -> Bool {
40+
isVideoRotationAngleSupported
41+
}
2942
}

packages/camera/camera_avfoundation/ios/camera_avfoundation/Sources/camera_avfoundation/DefaultCamera.swift

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -777,8 +777,14 @@ final class DefaultCamera: FLTCam, Camera {
777777
}
778778

779779
// Keep the same orientation the old connections had.
780-
if let oldConnection = oldConnection, newConnection.isVideoOrientationSupported {
781-
newConnection.videoOrientation = oldConnection.videoOrientation
780+
if #available(iOS 17.0, macos 14.0, *) {
781+
if let oldConnection = oldConnection, newConnection.isVideoRotationAngleSupported(oldConnection.videoRotationAngle) {
782+
newConnection.videoRotationAngle = oldConnection.videoRotationAngle
783+
}
784+
} else {
785+
if let oldConnection = oldConnection, newConnection.isVideoOrientationSupported {
786+
newConnection.videoOrientation = oldConnection.videoOrientation
787+
}
782788
}
783789

784790
// Add the new connections to the session.

packages/camera/camera_avfoundation/ios/camera_avfoundation/Sources/camera_avfoundation_objc/FLTCam.m

Lines changed: 31 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -185,13 +185,20 @@ - (void)updateOrientation:(UIDeviceOrientation)orientation
185185

186186
NSObject<FLTCaptureConnection> *connection =
187187
[captureOutput connectionWithMediaType:AVMediaTypeVideo];
188-
if (connection && connection.isVideoOrientationSupported) {
189-
connection.videoOrientation = [self getVideoOrientationForDeviceOrientation:orientation];
188+
if (@available(iOS 17.0, macos 14.0, *)) {
189+
CGFloat videoRotationAngle = [self getVideoRotationAngleForDeviceOrientation:orientation];
190+
if (connection && [connection isVideoRotationAngleSupported:videoRotationAngle]) {
191+
connection.videoRotationAngle = videoRotationAngle;
192+
}
193+
} else {
194+
if (connection && connection.isVideoOrientationSupported) {
195+
connection.videoOrientation = [self getVideoOrientationForDeviceOrientation:orientation];
196+
}
190197
}
191198
}
192199

193200
- (AVCaptureVideoOrientation)getVideoOrientationForDeviceOrientation:
194-
(UIDeviceOrientation)deviceOrientation {
201+
(UIDeviceOrientation)deviceOrientation API_DEPRECATED("Use getVideoRotationAngleForDeviceOrientation instead", macos(10.7, 14.0), ios(4.0, 17.0)) {
195202
if (deviceOrientation == UIDeviceOrientationPortrait) {
196203
return AVCaptureVideoOrientationPortrait;
197204
} else if (deviceOrientation == UIDeviceOrientationLandscapeLeft) {
@@ -209,6 +216,27 @@ - (AVCaptureVideoOrientation)getVideoOrientationForDeviceOrientation:
209216
}
210217
}
211218

219+
- (CGFloat)getVideoRotationAngleForDeviceOrientation:
220+
(UIDeviceOrientation)deviceOrientation API_AVAILABLE(macos(14.0), ios(17.0)) {
221+
switch (deviceOrientation) {
222+
case UIDeviceOrientationPortrait:
223+
return 90;
224+
case UIDeviceOrientationLandscapeLeft:
225+
// Note: device orientation is flipped compared to video orientation. When UIDeviceOrientation
226+
// is landscape left the video orientation should be landscape right.
227+
return 180;
228+
case UIDeviceOrientationLandscapeRight:
229+
// Note: device orientation is flipped compared to video orientation. When UIDeviceOrientation
230+
// is landscape right the video orientation should be landscape left.
231+
return 0;
232+
case UIDeviceOrientationPortraitUpsideDown:
233+
return 270;
234+
default:
235+
// Default to UIDeviceOrientationPortrait.
236+
return 90;
237+
}
238+
}
239+
212240
- (BOOL)setCaptureSessionPreset:(FCPPlatformResolutionPreset)resolutionPreset
213241
withError:(NSError **)error {
214242
switch (resolutionPreset) {

packages/camera/camera_avfoundation/ios/camera_avfoundation/Sources/camera_avfoundation_objc/FLTCaptureConnection.m

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,10 @@ - (BOOL)isVideoOrientationSupported {
2626
return self.connection.isVideoOrientationSupported;
2727
}
2828

29+
- (BOOL)isVideoRotationAngleSupported:(CGFloat)videoRotationAngle {
30+
return [self.connection isVideoRotationAngleSupported:videoRotationAngle];
31+
}
32+
2933
- (void)setVideoMirrored:(BOOL)videoMirrored {
3034
self.connection.videoMirrored = videoMirrored;
3135
}
@@ -38,10 +42,18 @@ - (void)setVideoOrientation:(AVCaptureVideoOrientation)videoOrientation {
3842
self.connection.videoOrientation = videoOrientation;
3943
}
4044

45+
- (void)setVideoRotationAngle:(CGFloat)videoRotationAngle {
46+
self.connection.videoRotationAngle = videoRotationAngle;
47+
}
48+
4149
- (AVCaptureVideoOrientation)videoOrientation {
4250
return self.connection.videoOrientation;
4351
}
4452

53+
- (AVCaptureVideoOrientation)videoRotationAngle {
54+
return self.connection.videoRotationAngle;
55+
}
56+
4557
- (NSArray<AVCaptureInputPort *> *)inputPorts {
4658
return self.connection.inputPorts;
4759
}

packages/camera/camera_avfoundation/ios/camera_avfoundation/Sources/camera_avfoundation_objc/include/camera_avfoundation/FLTCaptureConnection.h

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,16 +14,22 @@ NS_ASSUME_NONNULL_BEGIN
1414
@property(nonatomic, getter=isVideoMirrored) BOOL videoMirrored;
1515

1616
/// Corresponds to the `videoOrientation` property of `AVCaptureConnection`
17-
@property(nonatomic) AVCaptureVideoOrientation videoOrientation;
17+
@property(nonatomic) AVCaptureVideoOrientation videoOrientation API_DEPRECATED("Use -videoRotationAngle instead", macos(10.7, 14.0), ios(4.0, 17.0));
18+
19+
/// Corresponds to the `videoRotationAngle` property of `AVCaptureConnection`
20+
@property(nonatomic) CGFloat videoRotationAngle API_AVAILABLE(macos(14.0), ios(17.0));
1821

1922
/// Corresponds to the `inputPorts` property of `AVCaptureConnection`
2023
@property(nonatomic, readonly) NSArray<AVCaptureInputPort *> *inputPorts;
2124

2225
/// Corresponds to the `supportsVideoMirroring` property of `AVCaptureConnection`
23-
@property(nonatomic, readonly, getter=isVideoMirroringSupported) BOOL supportsVideoMirroring;
26+
@property(nonatomic, readonly, getter=isVideoMirroringSupported) BOOL supportsVideoMirroring API_DEPRECATED("Use -isVideoRotationAngleSupported: instead", macos(10.7, 14.0), ios(4.0, 17.0));
2427

2528
/// Corresponds to the `supportsVideoOrientation` property of `AVCaptureConnection`
26-
@property(nonatomic, readonly, getter=isVideoOrientationSupported) BOOL supportsVideoOrientation;
29+
@property(nonatomic, readonly, getter=isVideoOrientationSupported) BOOL supportsVideoOrientation API_DEPRECATED("Use -isVideoRotationAngleSupported: instead", macos(10.7, 14.0), ios(4.0, 17.0));
30+
31+
/// Corresponds to the `isVideoRotationAngleSupported:` method `AVCaptureConnection`
32+
- (BOOL)isVideoRotationAngleSupported:(CGFloat)videoRotationAngle;
2733

2834
@end
2935

0 commit comments

Comments
 (0)