Skip to content

Commit 380b68d

Browse files
committed
Migrate FLTCaptureConnection class to Swift
1 parent 4385dea commit 380b68d

File tree

9 files changed

+45
-104
lines changed

9 files changed

+45
-104
lines changed

packages/camera/camera_avfoundation/CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
## 0.9.22+6
2+
3+
* Migrates `FLTCaptureConnection` class to Swift.
4+
15
## 0.9.22+5
26

37
* Migrates `FLTCaptureDevice`, `FLTCaptureSession`, and `FLTFormatUtils` classes to Swift.

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,15 @@
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)
99
import camera_avfoundation_objc
1010
#endif
1111

12-
/// A mock implementation of `FLTCaptureConnection` that allows injecting a custom implementation.
13-
final class MockCaptureConnection: NSObject, FLTCaptureConnection {
12+
/// A mock implementation of `CaptureConnection` that allows injecting a custom implementation.
13+
final class MockCaptureConnection: NSObject, CaptureConnection {
1414
var setVideoOrientationStub: ((AVCaptureVideoOrientation) -> Void)?
1515

1616
var connection: AVCaptureConnection {

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,14 +22,14 @@ final class MockCapturePhotoOutput: NSObject, CapturePhotoOutput {
2222
((_ settings: AVCapturePhotoSettings, _ delegate: AVCapturePhotoCaptureDelegate) -> Void)?
2323

2424
// Stub that is called when the corresponding public method is called.
25-
var connectionWithMediaTypeStub: ((_ mediaType: AVMediaType) -> FLTCaptureConnection?)?
25+
var connectionWithMediaTypeStub: ((_ mediaType: AVMediaType) -> CaptureConnection?)?
2626

2727
func capturePhoto(with settings: AVCapturePhotoSettings, delegate: AVCapturePhotoCaptureDelegate)
2828
{
2929
capturePhotoWithSettingsStub?(settings, delegate)
3030
}
3131

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

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,9 @@ class MockCaptureVideoDataOutput: NSObject, CaptureVideoDataOutput {
1616
var alwaysDiscardsLateVideoFrames = false
1717
var videoSettings: [String: Any]! = [:]
1818

19-
var connectionWithMediaTypeStub: ((AVMediaType) -> FLTCaptureConnection?)?
19+
var connectionWithMediaTypeStub: ((AVMediaType) -> CaptureConnection?)?
2020

21-
func connection(with mediaType: AVMediaType) -> FLTCaptureConnection? {
21+
func connection(with mediaType: AVMediaType) -> CaptureConnection? {
2222
return connectionWithMediaTypeStub?(mediaType)
2323
}
2424

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
// Copyright 2013 The Flutter Authors
2+
// Use of this source code is governed by a BSD-style license that can be
3+
// found in the LICENSE file.
4+
5+
import AVFoundation
6+
7+
/// A protocol which is a direct passthrough to `AVCaptureConnection`. It exists to allow replacing
8+
/// `AVCaptureConnection` in tests.
9+
protocol CaptureConnection: NSObjectProtocol {
10+
/// Corresponds to the `isVideoMirrored` property of `AVCaptureConnection`
11+
var isVideoMirrored: Bool { get set }
12+
13+
/// Corresponds to the `videoOrientation` property of `AVCaptureConnection`
14+
var videoOrientation: AVCaptureVideoOrientation { get set }
15+
16+
/// Corresponds to the `inputPorts` property of `AVCaptureConnection`
17+
var inputPorts: [AVCaptureInput.Port] { get }
18+
19+
/// Corresponds to the `supportsVideoMirroring` property of `AVCaptureConnection`
20+
var isVideoMirroringSupported: Bool { get }
21+
22+
/// Corresponds to the `supportsVideoOrientation` property of `AVCaptureConnection`
23+
var isVideoOrientationSupported: Bool { get }
24+
}
25+
26+
extension AVCaptureConnection: CaptureConnection {}

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

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ import Foundation
1414
/// `AVCaptureOutput` in tests.
1515
protocol CaptureOutput {
1616
/// Returns a connection with the specified media type, or nil if no such connection exists.
17-
func connection(with mediaType: AVMediaType) -> FLTCaptureConnection?
17+
func connection(with mediaType: AVMediaType) -> CaptureConnection?
1818
}
1919

2020
/// A protocol which is a direct passthrough to `AVCaptureVideoDataOutput`. It exists to allow
@@ -41,9 +41,9 @@ extension AVCaptureVideoDataOutput: CaptureVideoDataOutput {
4141
return self
4242
}
4343

44-
func connection(with mediaType: AVMediaType) -> FLTCaptureConnection? {
45-
guard let connection: AVCaptureConnection = connection(with: mediaType) else { return nil }
46-
return FLTDefaultCaptureConnection(connection: connection)
44+
func connection(with mediaType: AVMediaType) -> (any CaptureConnection)? {
45+
let connection: AVCaptureConnection? = connection(with: mediaType)
46+
return connection
4747
}
4848
}
4949

@@ -72,8 +72,8 @@ extension AVCapturePhotoOutput: CapturePhotoOutput {
7272
return self
7373
}
7474

75-
func connection(with mediaType: AVMediaType) -> FLTCaptureConnection? {
76-
guard let connection: AVCaptureConnection = connection(with: mediaType) else { return nil }
77-
return FLTDefaultCaptureConnection(connection: connection)
75+
func connection(with mediaType: AVMediaType) -> CaptureConnection? {
76+
let connection: AVCaptureConnection? = connection(with: mediaType)
77+
return connection
7878
}
7979
}

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

Lines changed: 0 additions & 49 deletions
This file was deleted.

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

Lines changed: 0 additions & 40 deletions
This file was deleted.

packages/camera/camera_avfoundation/pubspec.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ name: camera_avfoundation
22
description: iOS implementation of the camera plugin.
33
repository: https://github.com/flutter/packages/tree/main/packages/camera/camera_avfoundation
44
issue_tracker: https://github.com/flutter/flutter/issues?q=is%3Aissue+is%3Aopen+label%3A%22p%3A+camera%22
5-
version: 0.9.22+5
5+
version: 0.9.22+6
66

77
environment:
88
sdk: ^3.9.0

0 commit comments

Comments
 (0)