Skip to content
Open
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
4 changes: 4 additions & 0 deletions packages/camera/camera_avfoundation/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
## 0.9.22+5

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

## 0.9.22+4

* Migrates `FLTCameraDeviceDiscovering` and `FLTDeviceOrientationProviding` classes to Swift.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,8 @@ final class CameraSessionPresetsTests: XCTestCase {
}
let captureFormatMock = MockCaptureDeviceFormat()
let captureDeviceMock = MockCaptureDevice()
captureDeviceMock.formats = [captureFormatMock]
captureDeviceMock.activeFormat = captureFormatMock
captureDeviceMock.fltFormats = [captureFormatMock]
captureDeviceMock.fltActiveFormat = captureFormatMock
captureDeviceMock.lockForConfigurationStub = {
lockForConfigurationExpectation.fulfill()
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,31 +39,31 @@ private final class TestMediaSettingsAVWrapper: FLTCamMediaSettingsAVWrapper {
videoSettingsExpectation = test.expectation(description: "videoSettingsExpectation")
}

override func lockDevice(_ captureDevice: FLTCaptureDevice) throws {
override func lockDevice(_ captureDevice: CaptureDevice) throws {
lockExpectation.fulfill()
}

override func unlockDevice(_ captureDevice: FLTCaptureDevice) {
override func unlockDevice(_ captureDevice: CaptureDevice) {
unlockExpectation.fulfill()
}

override func beginConfiguration(for videoCaptureSession: FLTCaptureSession) {
override func beginConfiguration(for videoCaptureSession: CaptureSession) {
beginConfigurationExpectation.fulfill()
}

override func commitConfiguration(for videoCaptureSession: FLTCaptureSession) {
override func commitConfiguration(for videoCaptureSession: CaptureSession) {
commitConfigurationExpectation.fulfill()
}

override func setMinFrameDuration(_ duration: CMTime, on captureDevice: FLTCaptureDevice) {
override func setMinFrameDuration(_ duration: CMTime, on captureDevice: CaptureDevice) {
// FLTCam allows to set frame rate with 1/10 precision.
let expectedDuration = CMTimeMake(value: 10, timescale: Int32(testFramesPerSecond * 10))
if duration == expectedDuration {
minFrameDurationExpectation.fulfill()
}
}

override func setMaxFrameDuration(_ duration: CMTime, on captureDevice: FLTCaptureDevice) {
override func setMaxFrameDuration(_ duration: CMTime, on captureDevice: CaptureDevice) {
// FLTCam allows to set frame rate with 1/10 precision.
let expectedDuration = CMTimeMake(value: 10, timescale: Int32(testFramesPerSecond * 10))
if duration == expectedDuration {
Expand Down Expand Up @@ -203,7 +203,7 @@ final class CameraSettingsTests: XCTestCase {
configuration.mediaSettings = settings
let camera = CameraTestUtils.createTestCamera(configuration)

let range = camera.captureDevice.activeFormat.videoSupportedFrameRateRanges[0]
let range = camera.captureDevice.fltActiveFormat.videoSupportedFrameRateRanges[0]
Copy link
Contributor

Choose a reason for hiding this comment

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

why are we renaming it?

XCTAssertLessThanOrEqual(range.minFrameRate, 60)
XCTAssertGreaterThanOrEqual(range.maxFrameRate, 60)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ enum CameraTestUtils {
captureDeviceFormatMock2.videoSupportedFrameRateRanges = [frameRateRangeMock2]

let captureDeviceMock = MockCaptureDevice()
captureDeviceMock.formats = [captureDeviceFormatMock1, captureDeviceFormatMock2]
captureDeviceMock.fltFormats = [captureDeviceFormatMock1, captureDeviceFormatMock2]

var currentFormat: FLTCaptureDeviceFormat = captureDeviceFormatMock1

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,15 +18,15 @@ final class MockCameraDeviceDiscoverer: NSObject, CameraDeviceDiscoverer {
_ deviceTypes: [AVCaptureDevice.DeviceType],
_ mediaType: AVMediaType,
_ position: AVCaptureDevice.Position
) -> [NSObject & FLTCaptureDevice]?
) -> [NSObject & CaptureDevice]?
)?

/// A stub that replaces the default implementation of
/// `discoverySessionWithDeviceTypes:mediaType:position`.
func discoverySession(
withDeviceTypes deviceTypes: [AVCaptureDevice.DeviceType], mediaType: AVMediaType,
position: AVCaptureDevice.Position
) -> [FLTCaptureDevice] {
) -> [CaptureDevice] {
return discoverySessionStub?(deviceTypes, mediaType, position) ?? []
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
// 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 Objective-C part of the implementation when SwiftPM is used.
#if canImport(camera_avfoundation_objc)
Expand All @@ -11,7 +11,7 @@ import camera_avfoundation

/// A mock implementation of `FLTCaptureDevice` that allows mocking the class
/// properties.
class MockCaptureDevice: NSObject, FLTCaptureDevice {
class MockCaptureDevice: NSObject, CaptureDevice {
var activeFormatStub: (() -> FLTCaptureDeviceFormat)?
var setActiveFormatStub: ((FLTCaptureDeviceFormat) -> Void)?
var getTorchModeStub: (() -> AVCaptureDevice.TorchMode)?
Expand All @@ -26,15 +26,15 @@ class MockCaptureDevice: NSObject, FLTCaptureDevice {
var setVideoZoomFactorStub: ((CGFloat) -> Void)?
var lockForConfigurationStub: (() throws -> Void)?

var device: AVCaptureDevice {
var avDevice: AVCaptureDevice {
preconditionFailure("Attempted to access unimplemented property: device")
}

var uniqueID = ""
var position = AVCaptureDevice.Position.unspecified
var deviceType = AVCaptureDevice.DeviceType.builtInWideAngleCamera

var activeFormat: FLTCaptureDeviceFormat {
var fltActiveFormat: FLTCaptureDeviceFormat {
Copy link
Contributor

Choose a reason for hiding this comment

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

is FLTCaptureDeviceFormat still in ObjC or is it migrated to Swift?

get {
activeFormatStub?() ?? MockCaptureDeviceFormat()
}
Expand All @@ -43,7 +43,7 @@ class MockCaptureDevice: NSObject, FLTCaptureDevice {
}
}

var formats: [FLTCaptureDeviceFormat] = []
var fltFormats: [FLTCaptureDeviceFormat] = []
var hasFlash = false
var hasTorch = false
var isTorchAvailable = false
Expand Down Expand Up @@ -78,20 +78,28 @@ class MockCaptureDevice: NSObject, FLTCaptureDevice {
return isFocusModeSupportedStub?(mode) ?? false
}

var focusMode: AVCaptureDevice.FocusMode {
get { .autoFocus }
set { setFocusModeStub?(newValue) }
}

func setFocusMode(_ focusMode: AVCaptureDevice.FocusMode) {
setFocusModeStub?(focusMode)
}

func setFocusPointOfInterest(_ point: CGPoint) {
setFocusPointOfInterestStub?(point)
var focusPointOfInterest: CGPoint {
get { CGPoint.zero }
set { setFocusPointOfInterestStub?(newValue) }
}

func setExposureMode(_ exposureMode: AVCaptureDevice.ExposureMode) {
setExposureModeStub?(exposureMode)
var exposureMode: AVCaptureDevice.ExposureMode {
get { .autoExpose }
set { setExposureModeStub?(newValue) }
}

func setExposurePointOfInterest(_ point: CGPoint) {
setExposurePointOfInterestStub?(point)
var exposurePointOfInterest: CGPoint {
get { CGPoint.zero }
set { setExposurePointOfInterestStub?(newValue) }
}

func setExposureTargetBias(_ bias: Float, completionHandler handler: ((CMTime) -> Void)? = nil) {
Expand All @@ -102,17 +110,11 @@ class MockCaptureDevice: NSObject, FLTCaptureDevice {
return isExposureModeSupportedStub?(mode) ?? false
}

func lensAperture() -> Float {
return 0
}
var lensAperture: Float { 0 }

func exposureDuration() -> CMTime {
return CMTime(value: 1, timescale: 1)
}
var exposureDuration: CMTime { CMTime(value: 1, timescale: 1) }

func iso() -> Float {
return 0
}
var iso: Float { 0 }

func lockForConfiguration() throws {
try lockForConfigurationStub?()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
// 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 Objective-C part of the implementation when SwiftPM is used.
#if canImport(camera_avfoundation_objc)
Expand All @@ -11,8 +11,8 @@ import camera_avfoundation

///// A mocked implementation of FLTCaptureDeviceInputFactory which allows injecting a custom
///// implementation.
final class MockCaptureDeviceInputFactory: NSObject, FLTCaptureDeviceInputFactory {
func deviceInput(with device: FLTCaptureDevice) throws -> FLTCaptureInput {
final class MockCaptureDeviceInputFactory: NSObject, CaptureDeviceInputFactory {
func deviceInput(with device: CaptureDevice) throws -> CaptureInput {
return MockCaptureInput()
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
// 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 Objective-C part of the implementation when SwiftPM is used.
#if canImport(camera_avfoundation_objc)
Expand All @@ -11,8 +11,8 @@ import camera_avfoundation

/// A mocked implementation of FLTCaptureInput which allows injecting a custom
/// implementation.
final class MockCaptureInput: NSObject, FLTCaptureInput {
var input: AVCaptureInput {
final class MockCaptureInput: NSObject, CaptureInput {
var avInput: AVCaptureInput {
preconditionFailure("Attempted to access unimplemented property: input")
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
// 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 Objective-C part of the implementation when SwiftPM is used.
#if canImport(camera_avfoundation_objc)
Expand All @@ -11,7 +11,7 @@ import camera_avfoundation

/// Mock implementation of `FLTCaptureSession` protocol which allows injecting a custom
/// implementation.
final class MockCaptureSession: NSObject, FLTCaptureSession {
final class MockCaptureSession: NSObject, CaptureSession {
var setSessionPresetStub: ((AVCaptureSession.Preset) -> Void)?
var beginConfigurationStub: (() -> Void)?
var commitConfigurationStub: (() -> Void)?
Expand Down Expand Up @@ -56,13 +56,13 @@ final class MockCaptureSession: NSObject, FLTCaptureSession {
return canSetSessionPresetStub?(preset) ?? true
}

func addInputWithNoConnections(_ input: FLTCaptureInput) {}
func addInputWithNoConnections(_ input: CaptureInput) {}

func addOutputWithNoConnections(_ output: AVCaptureOutput) {}

func addConnection(_: AVCaptureConnection) {}

func addInput(_: FLTCaptureInput) {}
func addInput(_: CaptureInput) {}

func addOutput(_ output: AVCaptureOutput) {

Expand All @@ -71,11 +71,11 @@ final class MockCaptureSession: NSObject, FLTCaptureSession {
}
}

func removeInput(_: FLTCaptureInput) {}
func removeInput(_: CaptureInput) {}

func removeOutput(_: AVCaptureOutput) {}

func canAddInput(_: FLTCaptureInput) -> Bool {
func canAddInput(_: CaptureInput) -> Bool {
return true
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,27 +19,27 @@ private class FakeMediaSettingsAVWrapper: FLTCamMediaSettingsAVWrapper {
self.inputMock = inputMock
}

override func lockDevice(_ captureDevice: FLTCaptureDevice) throws {
override func lockDevice(_ captureDevice: CaptureDevice) throws {
// No-op.
}

override func unlockDevice(_ captureDevice: FLTCaptureDevice) {
override func unlockDevice(_ captureDevice: CaptureDevice) {
// No-op.
}

override func beginConfiguration(for videoCaptureSession: FLTCaptureSession) {
override func beginConfiguration(for videoCaptureSession: CaptureSession) {
// No-op.
}

override func commitConfiguration(for videoCaptureSession: FLTCaptureSession) {
override func commitConfiguration(for videoCaptureSession: CaptureSession) {
// No-op.
}

override func setMinFrameDuration(_ duration: CMTime, on captureDevice: FLTCaptureDevice) {
override func setMinFrameDuration(_ duration: CMTime, on captureDevice: CaptureDevice) {
// No-op.
}

override func setMaxFrameDuration(_ duration: CMTime, on captureDevice: FLTCaptureDevice) {
override func setMaxFrameDuration(_ duration: CMTime, on captureDevice: CaptureDevice) {
// No-op.
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,11 @@ import UIKit

/// Factory block returning an FLTCaptureDevice.
/// Used in tests to inject a video capture device into DefaultCamera.
typealias VideoCaptureDeviceFactory = (_ cameraName: String) -> FLTCaptureDevice
typealias VideoCaptureDeviceFactory = (_ cameraName: String) -> CaptureDevice

typealias AudioCaptureDeviceFactory = () -> FLTCaptureDevice
typealias AudioCaptureDeviceFactory = () -> CaptureDevice

typealias CaptureSessionFactory = () -> FLTCaptureSession
typealias CaptureSessionFactory = () -> CaptureSession

typealias AssetWriterFactory = (_ assetUrl: URL, _ fileType: AVFileType) throws -> FLTAssetWriter

Expand All @@ -35,11 +35,11 @@ class CameraConfiguration {
var mediaSettings: FCPPlatformMediaSettings
var mediaSettingsWrapper: FLTCamMediaSettingsAVWrapper
var captureSessionQueue: DispatchQueue
var videoCaptureSession: FLTCaptureSession
var audioCaptureSession: FLTCaptureSession
var videoCaptureSession: CaptureSession
var audioCaptureSession: CaptureSession
var videoCaptureDeviceFactory: VideoCaptureDeviceFactory
let audioCaptureDeviceFactory: AudioCaptureDeviceFactory
let captureDeviceInputFactory: FLTCaptureDeviceInputFactory
let captureDeviceInputFactory: CaptureDeviceInputFactory
var assetWriterFactory: AssetWriterFactory
var inputPixelBufferAdaptorFactory: InputPixelBufferAdaptorFactory
var videoDimensionsConverter: VideoDimensionsConverter
Expand All @@ -54,7 +54,7 @@ class CameraConfiguration {
audioCaptureDeviceFactory: @escaping AudioCaptureDeviceFactory,
captureSessionFactory: @escaping CaptureSessionFactory,
captureSessionQueue: DispatchQueue,
captureDeviceInputFactory: FLTCaptureDeviceInputFactory,
captureDeviceInputFactory: CaptureDeviceInputFactory,
initialCameraName: String
) {
self.mediaSettings = mediaSettings
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ protocol CameraDeviceDiscoverer {
withDeviceTypes deviceTypes: [AVCaptureDevice.DeviceType],
mediaType: AVMediaType,
position: AVCaptureDevice.Position
) -> [FLTCaptureDevice]
) -> [CaptureDevice]
}

/// The default implementation of the `CameraDeviceDiscoverer` protocol.
Expand All @@ -26,18 +26,11 @@ class DefaultCameraDeviceDiscoverer: NSObject, CameraDeviceDiscoverer {
withDeviceTypes deviceTypes: [AVCaptureDevice.DeviceType],
mediaType: AVMediaType,
position: AVCaptureDevice.Position
) -> [FLTCaptureDevice] {
let discoverySession = AVCaptureDevice.DiscoverySession(
) -> [CaptureDevice] {
return AVCaptureDevice.DiscoverySession(
deviceTypes: deviceTypes,
mediaType: mediaType,
position: position
)

let devices = discoverySession.devices
let deviceControllers = devices.map { device in
FLTDefaultCaptureDevice(device: device) as FLTCaptureDevice
}

return deviceControllers
).devices
}
}
Loading