Skip to content

Commit bf2e952

Browse files
committed
Migrate FLTCamConfiguration, FLTCamMediaSettingsAVWrapper, FLTCaptureOutput, FLTCapturePhotoOutput, FLTCaptureVideoDataOutput to Swift
1 parent 2d4f8ef commit bf2e952

29 files changed

+348
-571
lines changed

packages/camera/camera_avfoundation/CHANGELOG.md

Lines changed: 15 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,8 @@
1+
## 0.9.22+2
2+
3+
* Migrates `FLTCamConfiguration`, `FLTCamMediaSettingsAVWrapper` classes to Swift.
4+
* Migrates `FLTCaptureOutput`, `FLTCapturePhotoOutput`, `FLTCaptureVideoDataOutput` protocols to Swift.
5+
16
## 0.9.22+1
27

38
* Fixes crash on iOS when `enableAudio` is false.
@@ -80,14 +85,14 @@
8085
## 0.9.19+2
8186

8287
* Adds the `Camera` Swift protocol.
83-
* Adds `DefaultCamera`, a `FLTCam`-based implementation of the `Camera` protocol.
88+
* Adds `DefaultCamera`, a `FLTCam`\*based implementation of the `Camera` protocol.
8489
* Migrates sample buffer delegates and `FlutterTexture` protocol implementations to `DefaultCamera`.
8590

8691
## 0.9.19+1
8792

8893
* Adds `audioCaptureDeviceFactory` to `FLTCamConfiguration`.
89-
* Renames the `lockCaptureOrientation` method of Objective-C type `FLTCam` when exported to Swift.
90-
* Renames arguments of the `captureOutput` method of Objective-C type `FLTCam` when exported to Swift.
94+
* Renames the `lockCaptureOrientation` method of Objective\*C type `FLTCam` when exported to Swift.
95+
* Renames arguments of the `captureOutput` method of Objective\*C type `FLTCam` when exported to Swift.
9196
* Changes the `connection` argument type of the `captureOutput` method of the of `FLTCam` class to `AVCaptureConnection`.
9297
* Makes `minimum/maximumAvailableZoomFactor` and `minimum/maximumExposureOffset` fields of `FLTCam` readonly.
9398
* Updates minimum supported SDK version to Flutter 3.27/Dart 3.6.
@@ -109,7 +114,7 @@
109114
## 0.9.18+12
110115

111116
* Migrates test utils and mocks to Swift.
112-
* Renames the methods of Objective-C type `FLTCaptureSession` when exported to Swift.
117+
* Renames the methods of Objective\*C type `FLTCaptureSession` when exported to Swift.
113118

114119
## 0.9.18+11
115120

@@ -177,7 +182,7 @@
177182

178183
## 0.9.17+4
179184

180-
* Updates Pigeon for non-nullable collection type support.
185+
* Updates Pigeon for non\*nullable collection type support.
181186
* Updates minimum supported SDK version to Flutter 3.19/Dart 3.3.
182187

183188
## 0.9.17+3
@@ -210,12 +215,12 @@
210215

211216
## 0.9.16
212217

213-
* Converts Dart-to-host communcation to Pigeon.
218+
* Converts Dart*to*host communcation to Pigeon.
214219
* Fixes a race condition in camera disposal.
215220

216221
## 0.9.15+4
217222

218-
* Converts host-to-Dart communcation to Pigeon.
223+
* Converts host*to*Dart communcation to Pigeon.
219224

220225
## 0.9.15+3
221226

@@ -261,7 +266,7 @@
261266

262267
## 0.9.13+8
263268

264-
* Updates example app to use non-deprecated video_player method.
269+
* Updates example app to use non\*deprecated video_player method.
265270
* Updates minimum supported SDK version to Flutter 3.10/Dart 3.0.
266271

267272
## 0.9.13+7
@@ -288,7 +293,7 @@
288293

289294
## 0.9.13+2
290295

291-
* Removes obsolete null checks on non-nullable values.
296+
* Removes obsolete null checks on non\*nullable values.
292297
* Updates minimum supported SDK version to Flutter 3.3/Dart 2.18.
293298

294299
## 0.9.13+1
@@ -349,7 +354,7 @@
349354

350355
## 0.9.8+2
351356

352-
* Fixes exception in registerWith caused by the switch to an in-package method channel.
357+
* Fixes exception in registerWith caused by the switch to an in\*package method channel.
353358

354359
## 0.9.8+1
355360

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ final class CameraSessionPresetsTests: XCTestCase {
3535
}
3636

3737
let configuration = CameraTestUtils.createTestCameraConfiguration()
38-
configuration.captureDeviceFactory = { _ in captureDeviceMock }
38+
configuration.videoCaptureDeviceFactory = { _ in captureDeviceMock }
3939
configuration.videoDimensionsForFormat = { format in
4040
return CMVideoDimensions(width: 1, height: 1)
4141
}
@@ -65,7 +65,7 @@ final class CameraSessionPresetsTests: XCTestCase {
6565
configuration.videoCaptureSession = videoSessionMock
6666
configuration.mediaSettings = CameraTestUtils.createDefaultMediaSettings(
6767
resolutionPreset: FCPPlatformResolutionPreset.max)
68-
configuration.captureDeviceFactory = { _ in MockCaptureDevice() }
68+
configuration.videoCaptureDeviceFactory = { _ in MockCaptureDevice() }
6969

7070
let _ = CameraTestUtils.createTestCamera(configuration)
7171

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,7 @@ private final class TestMediaSettingsAVWrapper: FLTCamMediaSettingsAVWrapper {
106106
}
107107

108108
override func recommendedVideoSettingsForAssetWriter(
109-
withFileType fileType: AVFileType, for output: FLTCaptureVideoDataOutput
109+
withFileType fileType: AVFileType, for output: CaptureVideoDataOutput
110110
) -> [String: Any]? {
111111
return [:]
112112
}

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

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,8 @@ enum CameraTestUtils {
2626
enableAudio: true)
2727
}
2828

29-
/// Creates a test `FLTCamConfiguration` with a default mock setup.
30-
static func createTestCameraConfiguration() -> FLTCamConfiguration {
29+
/// Creates a test `CameraConfiguration` with a default mock setup.
30+
static func createTestCameraConfiguration() -> CameraConfiguration {
3131
let captureSessionQueue = DispatchQueue(label: "capture_session_queue")
3232

3333
let videoSessionMock = MockCaptureSession()
@@ -56,7 +56,7 @@ enum CameraTestUtils {
5656
currentFormat = format
5757
}
5858

59-
let configuration = FLTCamConfiguration(
59+
let configuration = CameraConfiguration(
6060
mediaSettings: createDefaultMediaSettings(
6161
resolutionPreset: FCPPlatformResolutionPreset.medium),
6262
mediaSettingsWrapper: FLTCamMediaSettingsAVWrapper(),
@@ -81,7 +81,7 @@ enum CameraTestUtils {
8181
return configuration
8282
}
8383

84-
static func createTestCamera(_ configuration: FLTCamConfiguration) -> DefaultCamera {
84+
static func createTestCamera(_ configuration: CameraConfiguration) -> DefaultCamera {
8585
return (try? DefaultCamera(configuration: configuration))!
8686
}
8787

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ final class FLTCamExposureTests: XCTestCase {
1717
let mockDeviceOrientationProvider = MockDeviceOrientationProvider()
1818

1919
let configuration = CameraTestUtils.createTestCameraConfiguration()
20-
configuration.captureDeviceFactory = { _ in mockDevice }
20+
configuration.videoCaptureDeviceFactory = { _ in mockDevice }
2121
configuration.deviceOrientationProvider = mockDeviceOrientationProvider
2222
let camera = CameraTestUtils.createTestCamera(configuration)
2323

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ final class FLTCamSetFocusModeTests: XCTestCase {
1818
let mockDeviceOrientationProvider = MockDeviceOrientationProvider()
1919

2020
let configuration = CameraTestUtils.createTestCameraConfiguration()
21-
configuration.captureDeviceFactory = { _ in mockDevice }
21+
configuration.videoCaptureDeviceFactory = { _ in mockDevice }
2222
configuration.deviceOrientationProvider = mockDeviceOrientationProvider
2323
let camera = CameraTestUtils.createTestCamera(configuration)
2424

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

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ final class FLTCamSetFlashModeTests: XCTestCase {
1818
let mockCapturePhotoOutput = MockCapturePhotoOutput()
1919

2020
let configuration = CameraTestUtils.createTestCameraConfiguration()
21-
configuration.captureDeviceFactory = { _ in mockDevice }
21+
configuration.videoCaptureDeviceFactory = { _ in mockDevice }
2222
let camera = CameraTestUtils.createTestCamera(configuration)
2323
camera.capturePhotoOutput = mockCapturePhotoOutput
2424

@@ -87,9 +87,7 @@ final class FLTCamSetFlashModeTests: XCTestCase {
8787
func testSetFlashModeWithNonTorchMode_setsTrochModeOff_ifTorchModeIsEnabled() {
8888
let (camera, mockDevice, mockCapturePhotoOutput) = createCamera()
8989

90-
mockCapturePhotoOutput.supportedFlashModes = [
91-
NSNumber(value: AVCaptureDevice.FlashMode.auto.rawValue)
92-
]
90+
mockCapturePhotoOutput.supportedFlashModes = [.auto]
9391

9492
mockDevice.hasFlash = true
9593
// Torch mode is enabled

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ final class FLTCamZoomTests: XCTestCase {
1717
let mockDevice = MockCaptureDevice()
1818

1919
let configuration = CameraTestUtils.createTestCameraConfiguration()
20-
configuration.captureDeviceFactory = { _ in mockDevice }
20+
configuration.videoCaptureDeviceFactory = { _ in mockDevice }
2121
let camera = CameraTestUtils.createTestCamera(configuration)
2222

2323
return (camera, mockDevice)

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

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
// Use of this source code is governed by a BSD-style license that can be
33
// found in the LICENSE file.
44

5-
import camera_avfoundation
5+
@testable import camera_avfoundation
66

77
// Import Objective-C part of the implementation when SwiftPM is used.
88
#if canImport(camera_avfoundation_objc)
@@ -11,11 +11,11 @@ import camera_avfoundation
1111

1212
/// Mock implementation of `FLTCapturePhotoOutput` protocol which allows injecting a custom
1313
/// implementation.
14-
final class MockCapturePhotoOutput: NSObject, FLTCapturePhotoOutput {
14+
final class MockCapturePhotoOutput: NSObject, CapturePhotoOutput {
1515
var avOutput = AVCapturePhotoOutput()
1616
var availablePhotoCodecTypes: [AVVideoCodecType] = []
17-
var highResolutionCaptureEnabled = false
18-
var supportedFlashModes: [NSNumber] = []
17+
var isHighResolutionCaptureEnabled = false
18+
var supportedFlashModes: [AVCaptureDevice.FlashMode] = []
1919

2020
// Stub that is called when the corresponding public method is called.
2121
var capturePhotoWithSettingsStub:
@@ -29,7 +29,7 @@ final class MockCapturePhotoOutput: NSObject, FLTCapturePhotoOutput {
2929
capturePhotoWithSettingsStub?(settings, delegate)
3030
}
3131

32-
func connection(withMediaType mediaType: AVMediaType) -> FLTCaptureConnection? {
32+
func connection(with mediaType: AVMediaType) -> FLTCaptureConnection? {
3333
return connectionWithMediaTypeStub?(mediaType)
3434
}
3535
}

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

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
// Use of this source code is governed by a BSD-style license that can be
33
// found in the LICENSE file.
44

5-
import camera_avfoundation
5+
@testable import camera_avfoundation
66

77
// Import Objective-C part of the implementation when SwiftPM is used.
88
#if canImport(camera_avfoundation_objc)
@@ -11,15 +11,14 @@ import camera_avfoundation
1111

1212
/// Mock implementation of `FLTCaptureVideoDataOutput` protocol which allows injecting a custom
1313
/// implementation.
14-
class MockCaptureVideoDataOutput: NSObject, FLTCaptureVideoDataOutput {
15-
14+
class MockCaptureVideoDataOutput: NSObject, CaptureVideoDataOutput {
1615
var avOutput = AVCaptureVideoDataOutput()
1716
var alwaysDiscardsLateVideoFrames = false
18-
var videoSettings: [String: Any] = [:]
17+
var videoSettings: [String: Any]! = [:]
1918

2019
var connectionWithMediaTypeStub: ((AVMediaType) -> FLTCaptureConnection?)?
2120

22-
func connection(withMediaType mediaType: AVMediaType) -> FLTCaptureConnection? {
21+
func connection(with mediaType: AVMediaType) -> FLTCaptureConnection? {
2322
return connectionWithMediaTypeStub?(mediaType)
2423
}
2524

0 commit comments

Comments
 (0)