Skip to content

[camera_avfoundation] Implementation swift migration - part 4 #9219

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

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions packages/camera/camera_avfoundation/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
## 0.9.19+2

* Adds the `Camera` Swift protocol.
* Adds `DefaultCamera`, a `FLTCam`-based implementation of the `Camera` protocol.
* Migrates sample buffer delegates and `FlutterTexture` protocol implementations to `DefaultCamera`.

## 0.9.19+1

* Adds `audioCaptureDeviceFactory` to `FLTCamConfiguration`.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,11 @@

import XCTest

@testable import camera_avfoundation

// Import Objectice-C part of the implementation when SwiftPM is used.
#if canImport(camera_avfoundation_objc)
import camera_avfoundation_objc
#else
import camera_avfoundation
#endif

/// Utils for creating default class instances used in tests
Expand Down Expand Up @@ -81,16 +81,16 @@ enum CameraTestUtils {
return configuration
}

static func createTestCamera(_ configuration: FLTCamConfiguration) -> FLTCam {
return FLTCam(configuration: configuration, error: nil)
static func createTestCamera(_ configuration: FLTCamConfiguration) -> DefaultCamera {
return DefaultCamera(configuration: configuration, error: nil)
}

static func createTestCamera() -> FLTCam {
static func createTestCamera() -> DefaultCamera {
return createTestCamera(createTestCameraConfiguration())
}

static func createCameraWithCaptureSessionQueue(_ captureSessionQueue: DispatchQueue)
-> FLTCam
-> DefaultCamera
{
let configuration = createTestCameraConfiguration()
configuration.captureSessionQueue = captureSessionQueue
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import XCTest
#endif

final class FLTCamExposureTests: XCTestCase {
private func createCamera() -> (FLTCam, MockCaptureDevice, MockDeviceOrientationProvider) {
private func createCamera() -> (Camera, MockCaptureDevice, MockDeviceOrientationProvider) {
let mockDevice = MockCaptureDevice()
let mockDeviceOrientationProvider = MockDeviceOrientationProvider()

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import XCTest
#endif

final class FLTCamSetFocusModeTests: XCTestCase {
private func createCamera() -> (FLTCam, MockCaptureDevice, MockDeviceOrientationProvider) {
private func createCamera() -> (Camera, MockCaptureDevice, MockDeviceOrientationProvider) {
let mockDevice = MockCaptureDevice()
let mockDeviceOrientationProvider = MockDeviceOrientationProvider()

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import XCTest
#endif

final class FLTCamSetDeviceOrientationTests: XCTestCase {
private func createCamera() -> (FLTCam, MockCaptureConnection, MockCaptureConnection) {
private func createCamera() -> (Camera, MockCaptureConnection, MockCaptureConnection) {
let camera = CameraTestUtils.createTestCamera()

let mockCapturePhotoOutput = MockCapturePhotoOutput()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import XCTest
#endif

final class FLTCamSetFlashModeTests: XCTestCase {
private func createCamera() -> (FLTCam, MockCaptureDevice, MockCapturePhotoOutput) {
private func createCamera() -> (Camera, MockCaptureDevice, MockCapturePhotoOutput) {
let mockDevice = MockCaptureDevice()
let mockCapturePhotoOutput = MockCapturePhotoOutput()

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import XCTest
#endif

final class FLTCamZoomTests: XCTestCase {
private func createCamera() -> (FLTCam, MockCaptureDevice) {
private func createCamera() -> (Camera, MockCaptureDevice) {
let mockDevice = MockCaptureDevice()

let configuration = CameraTestUtils.createTestCameraConfiguration()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,14 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

import camera_avfoundation
@testable import camera_avfoundation

// Import Objectice-C part of the implementation when SwiftPM is used.
#if canImport(camera_avfoundation_objc)
import camera_avfoundation_objc
#endif

final class MockCamera: FLTCam {
final class MockCamera: NSObject, Camera {
var setDartApiStub: ((FCPCameraEventApi?) -> Void)?
var setOnFrameAvailableStub: (((() -> Void)?) -> Void)?
var getMinimumExposureOffsetStub: (() -> CGFloat)?
Expand Down Expand Up @@ -42,7 +42,7 @@ final class MockCamera: FLTCam {
var startImageStreamStub: ((FlutterBinaryMessenger) -> Void)?
var stopImageStreamStub: (() -> Void)?

override var dartAPI: FCPCameraEventApi {
var dartAPI: FCPCameraEventApi? {
get {
preconditionFailure("Attempted to access unimplemented property: dartAPI")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why this change?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

same q for other proeprties

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This mock used to extend the FLTCam class now it's implementing the Camera protocol so there is no super implementation to fall back to

}
Expand All @@ -51,7 +51,7 @@ final class MockCamera: FLTCam {
}
}

override var onFrameAvailable: (() -> Void) {
var onFrameAvailable: (() -> Void)? {
get {
preconditionFailure("Attempted to access unimplemented property: onFrameAvailable")
}
Expand All @@ -60,147 +60,149 @@ final class MockCamera: FLTCam {
}
}

override var minimumExposureOffset: CGFloat {
var videoFormat: FourCharCode = kCVPixelFormatType_32BGRA

var isPreviewPaused: Bool = false

var minimumExposureOffset: CGFloat {
return getMinimumExposureOffsetStub?() ?? 0
}

override var maximumExposureOffset: CGFloat {
var maximumExposureOffset: CGFloat {
return getMaximumExposureOffsetStub?() ?? 0
}

override var minimumAvailableZoomFactor: CGFloat {
var minimumAvailableZoomFactor: CGFloat {
return getMinimumAvailableZoomFactorStub?() ?? 0
}

override var maximumAvailableZoomFactor: CGFloat {
var maximumAvailableZoomFactor: CGFloat {
return getMaximumAvailableZoomFactorStub?() ?? 0
}

override func setUpCaptureSessionForAudioIfNeeded() {
func setUpCaptureSessionForAudioIfNeeded() {
setUpCaptureSessionForAudioIfNeededStub?()
}

override func reportInitializationState() {}
func reportInitializationState() {}

override func receivedImageStreamData() {
func receivedImageStreamData() {
receivedImageStreamDataStub?()
}

override func start() {
func start() {
startStub?()
}

override func stop() {}
func stop() {}

override func startVideoRecording(
func startVideoRecording(
completion: @escaping (FlutterError?) -> Void,
messengerForStreaming messenger: FlutterBinaryMessenger?
) {
startVideoRecordingStub?(completion, messenger)
}

override func pauseVideoRecording() {
func pauseVideoRecording() {
pauseVideoRecordingStub?()
}

override func resumeVideoRecording() {
func resumeVideoRecording() {
resumeVideoRecordingStub?()
}

override func stopVideoRecording(completion: @escaping (String?, FlutterError?) -> Void) {
func stopVideoRecording(completion: @escaping (String?, FlutterError?) -> Void) {
stopVideoRecordingStub?(completion)
}

override func captureToFile(completion: @escaping (String?, FlutterError?) -> Void) {
func captureToFile(completion: @escaping (String?, FlutterError?) -> Void) {
captureToFileStub?(completion)
}

override func setDeviceOrientation(_ orientation: UIDeviceOrientation) {
func setDeviceOrientation(_ orientation: UIDeviceOrientation) {
setDeviceOrientationStub?(orientation)
}

override func lockCaptureOrientation(_ orientation: FCPPlatformDeviceOrientation) {
func lockCaptureOrientation(_ orientation: FCPPlatformDeviceOrientation) {
lockCaptureOrientationStub?(orientation)
}

override func unlockCaptureOrientation() {
func unlockCaptureOrientation() {
unlockCaptureOrientationStub?()
}

override func setImageFileFormat(_ fileFormat: FCPPlatformImageFileFormat) {
func setImageFileFormat(_ fileFormat: FCPPlatformImageFileFormat) {
setImageFileFormatStub?(fileFormat)
}

override func setExposureMode(_ mode: FCPPlatformExposureMode) {
func setExposureMode(_ mode: FCPPlatformExposureMode) {
setExposureModeStub?(mode)
}

override func setExposureOffset(_ offset: Double) {
func setExposureOffset(_ offset: Double) {
setExposureOffsetStub?(offset)
}

override func setExposurePoint(
func setExposurePoint(
_ point: FCPPlatformPoint?, withCompletion: @escaping (FlutterError?) -> Void
) {
setExposurePointStub?(point, withCompletion)
}

override func setFocusMode(_ mode: FCPPlatformFocusMode) {
func setFocusMode(_ mode: FCPPlatformFocusMode) {
setFocusModeStub?(mode)
}

override func setFocusPoint(
_ point: FCPPlatformPoint?, completion: @escaping (FlutterError?) -> Void
) {
func setFocusPoint(_ point: FCPPlatformPoint?, completion: @escaping (FlutterError?) -> Void) {
setFocusPointStub?(point, completion)
}

override func setZoomLevel(
func setZoomLevel(
_ zoom: CGFloat,
withCompletion completion: @escaping (FlutterError?) -> Void
) {
setZoomLevelStub?(zoom, completion)
}

override func setFlashMode(
func setFlashMode(
_ mode: FCPPlatformFlashMode,
withCompletion completion: @escaping (FlutterError?) -> Void
) {
setFlashModeStub?(mode, completion)
}

override func pausePreview() {
func pausePreview() {
pausePreviewStub?()
}

override func resumePreview() {
func resumePreview() {
resumePreviewStub?()
}

override func setDescriptionWhileRecording(
func setDescriptionWhileRecording(
_ cameraName: String,
withCompletion completion: @escaping (FlutterError?) -> Void
) {
setDescriptionWhileRecordingStub?(cameraName, completion)
}

override func startImageStream(with messenger: FlutterBinaryMessenger) {
func startImageStream(with messenger: FlutterBinaryMessenger) {
startImageStreamStub?(messenger)
}

override func stopImageStream() {
func stopImageStream() {
stopImageStreamStub?()
}

override func captureOutput(
func captureOutput(
_ output: AVCaptureOutput,
didOutput sampleBuffer: CMSampleBuffer,
from connection: AVCaptureConnection
) {}

override func close() {}
func close() {}

override func copyPixelBuffer() -> Unmanaged<CVPixelBuffer>? {
func copyPixelBuffer() -> Unmanaged<CVPixelBuffer>? {
return nil
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import XCTest

/// Includes test cases related to photo capture operations for FLTCam class.
final class PhotoCaptureTests: XCTestCase {
private func createCam(with captureSessionQueue: DispatchQueue) -> FLTCam {
private func createCam(with captureSessionQueue: DispatchQueue) -> DefaultCamera {
let configuration = CameraTestUtils.createTestCameraConfiguration()
configuration.captureSessionQueue = captureSessionQueue
return CameraTestUtils.createTestCamera(configuration)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ private class FakeMediaSettingsAVWrapper: FLTCamMediaSettingsAVWrapper {
/// Includes test cases related to sample buffer handling for FLTCam class.
final class CameraSampleBufferTests: XCTestCase {
private func createCamera() -> (
FLTCam,
DefaultCamera,
MockAssetWriter,
MockAssetWriterInputPixelBufferAdaptor,
MockAssetWriterInput
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ private class MockImageStreamHandler: FLTImageStreamHandler {

final class StreamingTests: XCTestCase {
private func createCamera() -> (
FLTCam,
DefaultCamera,
AVCaptureOutput,
CMSampleBuffer,
AVCaptureConnection
Expand Down
Loading