diff --git a/packages/camera/camera_avfoundation/CHANGELOG.md b/packages/camera/camera_avfoundation/CHANGELOG.md index c37b5a7f628..5898b5f6488 100644 --- a/packages/camera/camera_avfoundation/CHANGELOG.md +++ b/packages/camera/camera_avfoundation/CHANGELOG.md @@ -1,3 +1,8 @@ +## 0.9.21+2 + +* Migrates `DefaultCamera` initialization to Swift. +* Removes unused `textureId` field of `FLTCam` class. + ## 0.9.21+1 * Migrates `startImageStream` and `setUpCaptureSessionForAudioIfNeeded` methods to Swift. diff --git a/packages/camera/camera_avfoundation/example/ios/RunnerTests/AvailableCamerasTests.swift b/packages/camera/camera_avfoundation/example/ios/RunnerTests/AvailableCamerasTests.swift index e52bc49081f..ecc64e89cb4 100644 --- a/packages/camera/camera_avfoundation/example/ios/RunnerTests/AvailableCamerasTests.swift +++ b/packages/camera/camera_avfoundation/example/ios/RunnerTests/AvailableCamerasTests.swift @@ -7,7 +7,7 @@ import XCTest @testable import camera_avfoundation -// Import Objectice-C part of the implementation when SwiftPM is used. +// Import Objective-C part of the implementation when SwiftPM is used. #if canImport(camera_avfoundation_objc) import camera_avfoundation_objc #endif diff --git a/packages/camera/camera_avfoundation/example/ios/RunnerTests/CameraInitRaceConditionsTests.swift b/packages/camera/camera_avfoundation/example/ios/RunnerTests/CameraInitRaceConditionsTests.swift index b71f71f7d52..28965ea9226 100644 --- a/packages/camera/camera_avfoundation/example/ios/RunnerTests/CameraInitRaceConditionsTests.swift +++ b/packages/camera/camera_avfoundation/example/ios/RunnerTests/CameraInitRaceConditionsTests.swift @@ -6,7 +6,7 @@ import XCTest @testable import camera_avfoundation -// Import Objectice-C part of the implementation when SwiftPM is used. +// Import Objective-C part of the implementation when SwiftPM is used. #if canImport(camera_avfoundation_objc) import camera_avfoundation_objc #endif diff --git a/packages/camera/camera_avfoundation/example/ios/RunnerTests/CameraMethodChannelTests.swift b/packages/camera/camera_avfoundation/example/ios/RunnerTests/CameraMethodChannelTests.swift index 127b3066d79..05118df929d 100644 --- a/packages/camera/camera_avfoundation/example/ios/RunnerTests/CameraMethodChannelTests.swift +++ b/packages/camera/camera_avfoundation/example/ios/RunnerTests/CameraMethodChannelTests.swift @@ -7,7 +7,7 @@ import XCTest @testable import camera_avfoundation -// Import Objectice-C part of the implementation when SwiftPM is used. +// Import Objective-C part of the implementation when SwiftPM is used. #if canImport(camera_avfoundation_objc) import camera_avfoundation_objc #endif diff --git a/packages/camera/camera_avfoundation/example/ios/RunnerTests/CameraOrientationTests.swift b/packages/camera/camera_avfoundation/example/ios/RunnerTests/CameraOrientationTests.swift index 61d9b1daaec..d7fc0bf8d68 100644 --- a/packages/camera/camera_avfoundation/example/ios/RunnerTests/CameraOrientationTests.swift +++ b/packages/camera/camera_avfoundation/example/ios/RunnerTests/CameraOrientationTests.swift @@ -8,7 +8,7 @@ import XCTest @testable import camera_avfoundation -// Import Objectice-C part of the implementation when SwiftPM is used. +// Import Objective-C part of the implementation when SwiftPM is used. #if canImport(camera_avfoundation_objc) import camera_avfoundation_objc #endif diff --git a/packages/camera/camera_avfoundation/example/ios/RunnerTests/CameraPermissionTests.swift b/packages/camera/camera_avfoundation/example/ios/RunnerTests/CameraPermissionTests.swift index 3820696ad91..51997dee6e9 100644 --- a/packages/camera/camera_avfoundation/example/ios/RunnerTests/CameraPermissionTests.swift +++ b/packages/camera/camera_avfoundation/example/ios/RunnerTests/CameraPermissionTests.swift @@ -7,7 +7,7 @@ import XCTest @testable import camera_avfoundation -// Import Objectice-C part of the implementation when SwiftPM is used. +// Import Objective-C part of the implementation when SwiftPM is used. #if canImport(camera_avfoundation_objc) import camera_avfoundation_objc #endif diff --git a/packages/camera/camera_avfoundation/example/ios/RunnerTests/CameraPluginCreateCameraTests.swift b/packages/camera/camera_avfoundation/example/ios/RunnerTests/CameraPluginCreateCameraTests.swift index c6e3b5344d9..2624f8917a2 100644 --- a/packages/camera/camera_avfoundation/example/ios/RunnerTests/CameraPluginCreateCameraTests.swift +++ b/packages/camera/camera_avfoundation/example/ios/RunnerTests/CameraPluginCreateCameraTests.swift @@ -6,7 +6,7 @@ import XCTest @testable import camera_avfoundation -// Import Objectice-C part of the implementation when SwiftPM is used. +// Import Objective-C part of the implementation when SwiftPM is used. #if canImport(camera_avfoundation_objc) import camera_avfoundation_objc #endif diff --git a/packages/camera/camera_avfoundation/example/ios/RunnerTests/CameraPluginDelegatingMethodTests.swift b/packages/camera/camera_avfoundation/example/ios/RunnerTests/CameraPluginDelegatingMethodTests.swift index 9bae2981990..9064a55ca26 100644 --- a/packages/camera/camera_avfoundation/example/ios/RunnerTests/CameraPluginDelegatingMethodTests.swift +++ b/packages/camera/camera_avfoundation/example/ios/RunnerTests/CameraPluginDelegatingMethodTests.swift @@ -6,7 +6,7 @@ import XCTest @testable import camera_avfoundation -// Import Objectice-C part of the implementation when SwiftPM is used. +// Import Objective-C part of the implementation when SwiftPM is used. #if canImport(camera_avfoundation_objc) import camera_avfoundation_objc #endif diff --git a/packages/camera/camera_avfoundation/example/ios/RunnerTests/CameraPluginInitializeCameraTests.swift b/packages/camera/camera_avfoundation/example/ios/RunnerTests/CameraPluginInitializeCameraTests.swift index 97ea3f76a84..208aa13a01c 100644 --- a/packages/camera/camera_avfoundation/example/ios/RunnerTests/CameraPluginInitializeCameraTests.swift +++ b/packages/camera/camera_avfoundation/example/ios/RunnerTests/CameraPluginInitializeCameraTests.swift @@ -6,7 +6,7 @@ import XCTest @testable import camera_avfoundation -// Import Objectice-C part of the implementation when SwiftPM is used. +// Import Objective-C part of the implementation when SwiftPM is used. #if canImport(camera_avfoundation_objc) import camera_avfoundation_objc #endif diff --git a/packages/camera/camera_avfoundation/example/ios/RunnerTests/CameraPreviewPauseTests.swift b/packages/camera/camera_avfoundation/example/ios/RunnerTests/CameraPreviewPauseTests.swift index 37cd99ce019..01c385602cb 100644 --- a/packages/camera/camera_avfoundation/example/ios/RunnerTests/CameraPreviewPauseTests.swift +++ b/packages/camera/camera_avfoundation/example/ios/RunnerTests/CameraPreviewPauseTests.swift @@ -7,7 +7,7 @@ import XCTest @testable import camera_avfoundation -// Import Objectice-C part of the implementation when SwiftPM is used. +// Import Objective-C part of the implementation when SwiftPM is used. #if canImport(camera_avfoundation_objc) import camera_avfoundation_objc #endif diff --git a/packages/camera/camera_avfoundation/example/ios/RunnerTests/CameraPropertiesTests.swift b/packages/camera/camera_avfoundation/example/ios/RunnerTests/CameraPropertiesTests.swift index 4b9cda2d93e..46d7f4a5d8e 100644 --- a/packages/camera/camera_avfoundation/example/ios/RunnerTests/CameraPropertiesTests.swift +++ b/packages/camera/camera_avfoundation/example/ios/RunnerTests/CameraPropertiesTests.swift @@ -8,7 +8,7 @@ import XCTest @testable import camera_avfoundation -// Import Objectice-C part of the implementation when SwiftPM is used. +// Import Objective-C part of the implementation when SwiftPM is used. #if canImport(camera_avfoundation_objc) import camera_avfoundation_objc #endif diff --git a/packages/camera/camera_avfoundation/example/ios/RunnerTests/CameraSessionPresetsTests.swift b/packages/camera/camera_avfoundation/example/ios/RunnerTests/CameraSessionPresetsTests.swift index 4b19116629e..1762cca186d 100644 --- a/packages/camera/camera_avfoundation/example/ios/RunnerTests/CameraSessionPresetsTests.swift +++ b/packages/camera/camera_avfoundation/example/ios/RunnerTests/CameraSessionPresetsTests.swift @@ -7,7 +7,7 @@ import XCTest @testable import camera_avfoundation -// Import Objectice-C part of the implementation when SwiftPM is used. +// Import Objective-C part of the implementation when SwiftPM is used. #if canImport(camera_avfoundation_objc) import camera_avfoundation_objc #endif diff --git a/packages/camera/camera_avfoundation/example/ios/RunnerTests/CameraSettingsTests.swift b/packages/camera/camera_avfoundation/example/ios/RunnerTests/CameraSettingsTests.swift index 55cd0ba815c..81bf4ebe15a 100644 --- a/packages/camera/camera_avfoundation/example/ios/RunnerTests/CameraSettingsTests.swift +++ b/packages/camera/camera_avfoundation/example/ios/RunnerTests/CameraSettingsTests.swift @@ -7,7 +7,7 @@ import XCTest @testable import camera_avfoundation -// Import Objectice-C part of the implementation when SwiftPM is used. +// Import Objective-C part of the implementation when SwiftPM is used. #if canImport(camera_avfoundation_objc) import camera_avfoundation_objc #endif diff --git a/packages/camera/camera_avfoundation/example/ios/RunnerTests/CameraTestUtils.swift b/packages/camera/camera_avfoundation/example/ios/RunnerTests/CameraTestUtils.swift index e21497d1a1e..fd0cc75b6e2 100644 --- a/packages/camera/camera_avfoundation/example/ios/RunnerTests/CameraTestUtils.swift +++ b/packages/camera/camera_avfoundation/example/ios/RunnerTests/CameraTestUtils.swift @@ -6,7 +6,7 @@ import XCTest @testable import camera_avfoundation -// Import Objectice-C part of the implementation when SwiftPM is used. +// Import Objective-C part of the implementation when SwiftPM is used. #if canImport(camera_avfoundation_objc) import camera_avfoundation_objc #endif @@ -82,7 +82,7 @@ enum CameraTestUtils { } static func createTestCamera(_ configuration: FLTCamConfiguration) -> DefaultCamera { - return DefaultCamera(configuration: configuration, error: nil) + return (try? DefaultCamera(configuration: configuration))! } static func createTestCamera() -> DefaultCamera { diff --git a/packages/camera/camera_avfoundation/example/ios/RunnerTests/FLTCamExposureTests.swift b/packages/camera/camera_avfoundation/example/ios/RunnerTests/FLTCamExposureTests.swift index 20952741f71..69a3dd1b390 100644 --- a/packages/camera/camera_avfoundation/example/ios/RunnerTests/FLTCamExposureTests.swift +++ b/packages/camera/camera_avfoundation/example/ios/RunnerTests/FLTCamExposureTests.swift @@ -6,7 +6,7 @@ import XCTest @testable import camera_avfoundation -// Import Objectice-C part of the implementation when SwiftPM is used. +// Import Objective-C part of the implementation when SwiftPM is used. #if canImport(camera_avfoundation_objc) import camera_avfoundation_objc #endif diff --git a/packages/camera/camera_avfoundation/example/ios/RunnerTests/FLTCamFocusTests.swift b/packages/camera/camera_avfoundation/example/ios/RunnerTests/FLTCamFocusTests.swift index 580ebdab109..a5569b5b28b 100644 --- a/packages/camera/camera_avfoundation/example/ios/RunnerTests/FLTCamFocusTests.swift +++ b/packages/camera/camera_avfoundation/example/ios/RunnerTests/FLTCamFocusTests.swift @@ -7,7 +7,7 @@ import XCTest @testable import camera_avfoundation -// Import Objectice-C part of the implementation when SwiftPM is used. +// Import Objective-C part of the implementation when SwiftPM is used. #if canImport(camera_avfoundation_objc) import camera_avfoundation_objc #endif diff --git a/packages/camera/camera_avfoundation/example/ios/RunnerTests/FLTCamSetDeviceOrientationTests.swift b/packages/camera/camera_avfoundation/example/ios/RunnerTests/FLTCamSetDeviceOrientationTests.swift index d7fbb505b7e..319a10e4a34 100644 --- a/packages/camera/camera_avfoundation/example/ios/RunnerTests/FLTCamSetDeviceOrientationTests.swift +++ b/packages/camera/camera_avfoundation/example/ios/RunnerTests/FLTCamSetDeviceOrientationTests.swift @@ -7,7 +7,7 @@ import XCTest @testable import camera_avfoundation -// Import Objectice-C part of the implementation when SwiftPM is used. +// Import Objective-C part of the implementation when SwiftPM is used. #if canImport(camera_avfoundation_objc) import camera_avfoundation_objc #endif diff --git a/packages/camera/camera_avfoundation/example/ios/RunnerTests/FLTCamSetFlashModeTests.swift b/packages/camera/camera_avfoundation/example/ios/RunnerTests/FLTCamSetFlashModeTests.swift index 29ade54f7fe..3ef99c982e0 100644 --- a/packages/camera/camera_avfoundation/example/ios/RunnerTests/FLTCamSetFlashModeTests.swift +++ b/packages/camera/camera_avfoundation/example/ios/RunnerTests/FLTCamSetFlashModeTests.swift @@ -7,7 +7,7 @@ import XCTest @testable import camera_avfoundation -// Import Objectice-C part of the implementation when SwiftPM is used. +// Import Objective-C part of the implementation when SwiftPM is used. #if canImport(camera_avfoundation_objc) import camera_avfoundation_objc #endif diff --git a/packages/camera/camera_avfoundation/example/ios/RunnerTests/FLTCamZoomTests.swift b/packages/camera/camera_avfoundation/example/ios/RunnerTests/FLTCamZoomTests.swift index 618d87edde3..2f3e9a32fe6 100644 --- a/packages/camera/camera_avfoundation/example/ios/RunnerTests/FLTCamZoomTests.swift +++ b/packages/camera/camera_avfoundation/example/ios/RunnerTests/FLTCamZoomTests.swift @@ -7,7 +7,7 @@ import XCTest @testable import camera_avfoundation -// Import Objectice-C part of the implementation when SwiftPM is used. +// Import Objective-C part of the implementation when SwiftPM is used. #if canImport(camera_avfoundation_objc) import camera_avfoundation_objc #endif diff --git a/packages/camera/camera_avfoundation/example/ios/RunnerTests/Mocks/MockAssetWriter.swift b/packages/camera/camera_avfoundation/example/ios/RunnerTests/Mocks/MockAssetWriter.swift index a725e958b05..4728c6a585a 100644 --- a/packages/camera/camera_avfoundation/example/ios/RunnerTests/Mocks/MockAssetWriter.swift +++ b/packages/camera/camera_avfoundation/example/ios/RunnerTests/Mocks/MockAssetWriter.swift @@ -4,7 +4,7 @@ import camera_avfoundation -// Import Objectice-C part of the implementation when SwiftPM is used. +// Import Objective-C part of the implementation when SwiftPM is used. #if canImport(camera_avfoundation_objc) import camera_avfoundation_objc #endif diff --git a/packages/camera/camera_avfoundation/example/ios/RunnerTests/Mocks/MockAssetWriterInput.swift b/packages/camera/camera_avfoundation/example/ios/RunnerTests/Mocks/MockAssetWriterInput.swift index cc373a5852f..1f956e17744 100644 --- a/packages/camera/camera_avfoundation/example/ios/RunnerTests/Mocks/MockAssetWriterInput.swift +++ b/packages/camera/camera_avfoundation/example/ios/RunnerTests/Mocks/MockAssetWriterInput.swift @@ -4,7 +4,7 @@ import camera_avfoundation -// Import Objectice-C part of the implementation when SwiftPM is used. +// Import Objective-C part of the implementation when SwiftPM is used. #if canImport(camera_avfoundation_objc) import camera_avfoundation_objc #endif diff --git a/packages/camera/camera_avfoundation/example/ios/RunnerTests/Mocks/MockAssetWriterInputPixelBufferAdaptor.swift b/packages/camera/camera_avfoundation/example/ios/RunnerTests/Mocks/MockAssetWriterInputPixelBufferAdaptor.swift index 0b4069614ca..da8fe049246 100644 --- a/packages/camera/camera_avfoundation/example/ios/RunnerTests/Mocks/MockAssetWriterInputPixelBufferAdaptor.swift +++ b/packages/camera/camera_avfoundation/example/ios/RunnerTests/Mocks/MockAssetWriterInputPixelBufferAdaptor.swift @@ -4,7 +4,7 @@ import camera_avfoundation -// Import Objectice-C part of the implementation when SwiftPM is used. +// Import Objective-C part of the implementation when SwiftPM is used. #if canImport(camera_avfoundation_objc) import camera_avfoundation_objc #endif diff --git a/packages/camera/camera_avfoundation/example/ios/RunnerTests/Mocks/MockCamera.swift b/packages/camera/camera_avfoundation/example/ios/RunnerTests/Mocks/MockCamera.swift index 1996b785fb6..d5e11aae9bb 100644 --- a/packages/camera/camera_avfoundation/example/ios/RunnerTests/Mocks/MockCamera.swift +++ b/packages/camera/camera_avfoundation/example/ios/RunnerTests/Mocks/MockCamera.swift @@ -4,7 +4,7 @@ @testable import camera_avfoundation -// Import Objectice-C part of the implementation when SwiftPM is used. +// Import Objective-C part of the implementation when SwiftPM is used. #if canImport(camera_avfoundation_objc) import camera_avfoundation_objc #endif diff --git a/packages/camera/camera_avfoundation/example/ios/RunnerTests/Mocks/MockCameraDeviceDiscoverer.swift b/packages/camera/camera_avfoundation/example/ios/RunnerTests/Mocks/MockCameraDeviceDiscoverer.swift index c8ddda5ee59..d9ed29648c7 100644 --- a/packages/camera/camera_avfoundation/example/ios/RunnerTests/Mocks/MockCameraDeviceDiscoverer.swift +++ b/packages/camera/camera_avfoundation/example/ios/RunnerTests/Mocks/MockCameraDeviceDiscoverer.swift @@ -4,7 +4,7 @@ import camera_avfoundation -// Import Objectice-C part of the implementation when SwiftPM is used. +// Import Objective-C part of the implementation when SwiftPM is used. #if canImport(camera_avfoundation_objc) import camera_avfoundation_objc #endif diff --git a/packages/camera/camera_avfoundation/example/ios/RunnerTests/Mocks/MockCaptureConnection.swift b/packages/camera/camera_avfoundation/example/ios/RunnerTests/Mocks/MockCaptureConnection.swift index a700364818b..2ee3559ff5f 100644 --- a/packages/camera/camera_avfoundation/example/ios/RunnerTests/Mocks/MockCaptureConnection.swift +++ b/packages/camera/camera_avfoundation/example/ios/RunnerTests/Mocks/MockCaptureConnection.swift @@ -4,7 +4,7 @@ import camera_avfoundation -// Import Objectice-C part of the implementation when SwiftPM is used. +// Import Objective-C part of the implementation when SwiftPM is used. #if canImport(camera_avfoundation_objc) import camera_avfoundation_objc #endif diff --git a/packages/camera/camera_avfoundation/example/ios/RunnerTests/Mocks/MockCaptureDevice.swift b/packages/camera/camera_avfoundation/example/ios/RunnerTests/Mocks/MockCaptureDevice.swift index 660c1a83d50..32d5ed1b430 100644 --- a/packages/camera/camera_avfoundation/example/ios/RunnerTests/Mocks/MockCaptureDevice.swift +++ b/packages/camera/camera_avfoundation/example/ios/RunnerTests/Mocks/MockCaptureDevice.swift @@ -4,7 +4,7 @@ import camera_avfoundation -// Import Objectice-C part of the implementation when SwiftPM is used. +// Import Objective-C part of the implementation when SwiftPM is used. #if canImport(camera_avfoundation_objc) import camera_avfoundation_objc #endif diff --git a/packages/camera/camera_avfoundation/example/ios/RunnerTests/Mocks/MockCaptureDeviceFormat.swift b/packages/camera/camera_avfoundation/example/ios/RunnerTests/Mocks/MockCaptureDeviceFormat.swift index be58b746c26..7e80b87d4a1 100644 --- a/packages/camera/camera_avfoundation/example/ios/RunnerTests/Mocks/MockCaptureDeviceFormat.swift +++ b/packages/camera/camera_avfoundation/example/ios/RunnerTests/Mocks/MockCaptureDeviceFormat.swift @@ -4,7 +4,7 @@ import camera_avfoundation -// Import Objectice-C part of the implementation when SwiftPM is used. +// Import Objective-C part of the implementation when SwiftPM is used. #if canImport(camera_avfoundation_objc) import camera_avfoundation_objc #endif diff --git a/packages/camera/camera_avfoundation/example/ios/RunnerTests/Mocks/MockCaptureDeviceInputFactory.swift b/packages/camera/camera_avfoundation/example/ios/RunnerTests/Mocks/MockCaptureDeviceInputFactory.swift index 01a20c22a05..d084f7626c8 100644 --- a/packages/camera/camera_avfoundation/example/ios/RunnerTests/Mocks/MockCaptureDeviceInputFactory.swift +++ b/packages/camera/camera_avfoundation/example/ios/RunnerTests/Mocks/MockCaptureDeviceInputFactory.swift @@ -4,7 +4,7 @@ import camera_avfoundation -// Import Objectice-C part of the implementation when SwiftPM is used. +// Import Objective-C part of the implementation when SwiftPM is used. #if canImport(camera_avfoundation_objc) import camera_avfoundation_objc #endif diff --git a/packages/camera/camera_avfoundation/example/ios/RunnerTests/Mocks/MockCaptureInput.swift b/packages/camera/camera_avfoundation/example/ios/RunnerTests/Mocks/MockCaptureInput.swift index 9ebf87ccf8b..423887c7b54 100644 --- a/packages/camera/camera_avfoundation/example/ios/RunnerTests/Mocks/MockCaptureInput.swift +++ b/packages/camera/camera_avfoundation/example/ios/RunnerTests/Mocks/MockCaptureInput.swift @@ -4,7 +4,7 @@ import camera_avfoundation -// Import Objectice-C part of the implementation when SwiftPM is used. +// Import Objective-C part of the implementation when SwiftPM is used. #if canImport(camera_avfoundation_objc) import camera_avfoundation_objc #endif diff --git a/packages/camera/camera_avfoundation/example/ios/RunnerTests/Mocks/MockCapturePhotoOutput.swift b/packages/camera/camera_avfoundation/example/ios/RunnerTests/Mocks/MockCapturePhotoOutput.swift index 59e5b1703a1..34d28eb71cc 100644 --- a/packages/camera/camera_avfoundation/example/ios/RunnerTests/Mocks/MockCapturePhotoOutput.swift +++ b/packages/camera/camera_avfoundation/example/ios/RunnerTests/Mocks/MockCapturePhotoOutput.swift @@ -4,7 +4,7 @@ import camera_avfoundation -// Import Objectice-C part of the implementation when SwiftPM is used. +// Import Objective-C part of the implementation when SwiftPM is used. #if canImport(camera_avfoundation_objc) import camera_avfoundation_objc #endif diff --git a/packages/camera/camera_avfoundation/example/ios/RunnerTests/Mocks/MockCaptureSession.swift b/packages/camera/camera_avfoundation/example/ios/RunnerTests/Mocks/MockCaptureSession.swift index 9218fa8dd89..5d895f87c90 100644 --- a/packages/camera/camera_avfoundation/example/ios/RunnerTests/Mocks/MockCaptureSession.swift +++ b/packages/camera/camera_avfoundation/example/ios/RunnerTests/Mocks/MockCaptureSession.swift @@ -4,7 +4,7 @@ import camera_avfoundation -// Import Objectice-C part of the implementation when SwiftPM is used. +// Import Objective-C part of the implementation when SwiftPM is used. #if canImport(camera_avfoundation_objc) import camera_avfoundation_objc #endif diff --git a/packages/camera/camera_avfoundation/example/ios/RunnerTests/Mocks/MockCaptureVideoDataOutput.swift b/packages/camera/camera_avfoundation/example/ios/RunnerTests/Mocks/MockCaptureVideoDataOutput.swift index 05784d652c7..0a578a4cb92 100644 --- a/packages/camera/camera_avfoundation/example/ios/RunnerTests/Mocks/MockCaptureVideoDataOutput.swift +++ b/packages/camera/camera_avfoundation/example/ios/RunnerTests/Mocks/MockCaptureVideoDataOutput.swift @@ -4,7 +4,7 @@ import camera_avfoundation -// Import Objectice-C part of the implementation when SwiftPM is used. +// Import Objective-C part of the implementation when SwiftPM is used. #if canImport(camera_avfoundation_objc) import camera_avfoundation_objc #endif diff --git a/packages/camera/camera_avfoundation/example/ios/RunnerTests/Mocks/MockDeviceOrientationProvider.swift b/packages/camera/camera_avfoundation/example/ios/RunnerTests/Mocks/MockDeviceOrientationProvider.swift index 203fa5ba1c7..ff5ed191946 100644 --- a/packages/camera/camera_avfoundation/example/ios/RunnerTests/Mocks/MockDeviceOrientationProvider.swift +++ b/packages/camera/camera_avfoundation/example/ios/RunnerTests/Mocks/MockDeviceOrientationProvider.swift @@ -4,7 +4,7 @@ import camera_avfoundation -// Import Objectice-C part of the implementation when SwiftPM is used. +// Import Objective-C part of the implementation when SwiftPM is used. #if canImport(camera_avfoundation_objc) import camera_avfoundation_objc #endif diff --git a/packages/camera/camera_avfoundation/example/ios/RunnerTests/Mocks/MockEventChannel.swift b/packages/camera/camera_avfoundation/example/ios/RunnerTests/Mocks/MockEventChannel.swift index 7e10b2c3998..82ab5829b1e 100644 --- a/packages/camera/camera_avfoundation/example/ios/RunnerTests/Mocks/MockEventChannel.swift +++ b/packages/camera/camera_avfoundation/example/ios/RunnerTests/Mocks/MockEventChannel.swift @@ -4,7 +4,7 @@ import camera_avfoundation -// Import Objectice-C part of the implementation when SwiftPM is used. +// Import Objective-C part of the implementation when SwiftPM is used. #if canImport(camera_avfoundation_objc) import camera_avfoundation_objc #endif diff --git a/packages/camera/camera_avfoundation/example/ios/RunnerTests/Mocks/MockFLTCameraPermissionManager.swift b/packages/camera/camera_avfoundation/example/ios/RunnerTests/Mocks/MockFLTCameraPermissionManager.swift index 0a4bdac00ef..9c6b3d33dbf 100644 --- a/packages/camera/camera_avfoundation/example/ios/RunnerTests/Mocks/MockFLTCameraPermissionManager.swift +++ b/packages/camera/camera_avfoundation/example/ios/RunnerTests/Mocks/MockFLTCameraPermissionManager.swift @@ -4,7 +4,7 @@ import camera_avfoundation -// Import Objectice-C part of the implementation when SwiftPM is used. +// Import Objective-C part of the implementation when SwiftPM is used. #if canImport(camera_avfoundation_objc) import camera_avfoundation_objc #endif diff --git a/packages/camera/camera_avfoundation/example/ios/RunnerTests/Mocks/MockFrameRateRange.swift b/packages/camera/camera_avfoundation/example/ios/RunnerTests/Mocks/MockFrameRateRange.swift index e0010c648e8..07c3fe524c4 100644 --- a/packages/camera/camera_avfoundation/example/ios/RunnerTests/Mocks/MockFrameRateRange.swift +++ b/packages/camera/camera_avfoundation/example/ios/RunnerTests/Mocks/MockFrameRateRange.swift @@ -4,7 +4,7 @@ import camera_avfoundation -// Import Objectice-C part of the implementation when SwiftPM is used. +// Import Objective-C part of the implementation when SwiftPM is used. #if canImport(camera_avfoundation_objc) import camera_avfoundation_objc #endif diff --git a/packages/camera/camera_avfoundation/example/ios/RunnerTests/Mocks/MockGlobalEventApi.swift b/packages/camera/camera_avfoundation/example/ios/RunnerTests/Mocks/MockGlobalEventApi.swift index e38df02dc73..aa3bd229413 100644 --- a/packages/camera/camera_avfoundation/example/ios/RunnerTests/Mocks/MockGlobalEventApi.swift +++ b/packages/camera/camera_avfoundation/example/ios/RunnerTests/Mocks/MockGlobalEventApi.swift @@ -4,7 +4,7 @@ import camera_avfoundation -// Import Objectice-C part of the implementation when SwiftPM is used. +// Import Objective-C part of the implementation when SwiftPM is used. #if canImport(camera_avfoundation_objc) import camera_avfoundation_objc #endif diff --git a/packages/camera/camera_avfoundation/example/ios/RunnerTests/Mocks/MockWritableData.swift b/packages/camera/camera_avfoundation/example/ios/RunnerTests/Mocks/MockWritableData.swift index c353a7ac744..df1debd96b2 100644 --- a/packages/camera/camera_avfoundation/example/ios/RunnerTests/Mocks/MockWritableData.swift +++ b/packages/camera/camera_avfoundation/example/ios/RunnerTests/Mocks/MockWritableData.swift @@ -4,7 +4,7 @@ import camera_avfoundation -// Import Objectice-C part of the implementation when SwiftPM is used. +// Import Objective-C part of the implementation when SwiftPM is used. #if canImport(camera_avfoundation_objc) import camera_avfoundation_objc #endif diff --git a/packages/camera/camera_avfoundation/example/ios/RunnerTests/PhotoCaptureTests.swift b/packages/camera/camera_avfoundation/example/ios/RunnerTests/PhotoCaptureTests.swift index 6611f514db9..5fcc2cb2798 100644 --- a/packages/camera/camera_avfoundation/example/ios/RunnerTests/PhotoCaptureTests.swift +++ b/packages/camera/camera_avfoundation/example/ios/RunnerTests/PhotoCaptureTests.swift @@ -7,7 +7,7 @@ import XCTest @testable import camera_avfoundation -// Import Objectice-C part of the implementation when SwiftPM is used. +// Import Objective-C part of the implementation when SwiftPM is used. #if canImport(camera_avfoundation_objc) import camera_avfoundation_objc #endif @@ -32,8 +32,7 @@ final class PhotoCaptureTests: XCTestCase { let mockOutput = MockCapturePhotoOutput() mockOutput.capturePhotoWithSettingsStub = { settings, photoDelegate in let delegate = - cam.inProgressSavePhotoDelegates.object(forKey: settings.uniqueID) - as? FLTSavePhotoDelegate + cam.inProgressSavePhotoDelegates[settings.uniqueID] // Completion runs on IO queue. let ioQueue = DispatchQueue(label: "io_queue") ioQueue.async { @@ -66,8 +65,7 @@ final class PhotoCaptureTests: XCTestCase { let mockOutput = MockCapturePhotoOutput() mockOutput.capturePhotoWithSettingsStub = { settings, photoDelegate in let delegate = - cam.inProgressSavePhotoDelegates.object(forKey: settings.uniqueID) - as? FLTSavePhotoDelegate + cam.inProgressSavePhotoDelegates[settings.uniqueID] // Completion runs on IO queue. let ioQueue = DispatchQueue(label: "io_queue") ioQueue.async { @@ -101,8 +99,7 @@ final class PhotoCaptureTests: XCTestCase { mockOutput.availablePhotoCodecTypes = [AVVideoCodecType.hevc] mockOutput.capturePhotoWithSettingsStub = { settings, photoDelegate in let delegate = - cam.inProgressSavePhotoDelegates.object(forKey: settings.uniqueID) - as? FLTSavePhotoDelegate + cam.inProgressSavePhotoDelegates[settings.uniqueID] // Completion runs on IO queue. let ioQueue = DispatchQueue(label: "io_queue") ioQueue.async { @@ -136,8 +133,7 @@ final class PhotoCaptureTests: XCTestCase { let mockOutput = MockCapturePhotoOutput() mockOutput.capturePhotoWithSettingsStub = { settings, photoDelegate in let delegate = - cam.inProgressSavePhotoDelegates.object(forKey: settings.uniqueID) - as? FLTSavePhotoDelegate + cam.inProgressSavePhotoDelegates[settings.uniqueID] // Completion runs on IO queue. let ioQueue = DispatchQueue(label: "io_queue") ioQueue.async { @@ -185,8 +181,7 @@ final class PhotoCaptureTests: XCTestCase { let mockOutput = MockCapturePhotoOutput() mockOutput.capturePhotoWithSettingsStub = { settings, photoDelegate in let delegate = - cam.inProgressSavePhotoDelegates.object(forKey: settings.uniqueID) - as? FLTSavePhotoDelegate + cam.inProgressSavePhotoDelegates[settings.uniqueID] // Completion runs on IO queue. let ioQueue = DispatchQueue(label: "io_queue") ioQueue.async { diff --git a/packages/camera/camera_avfoundation/example/ios/RunnerTests/QueueUtilsTests.swift b/packages/camera/camera_avfoundation/example/ios/RunnerTests/QueueUtilsTests.swift index 47f26d9e633..cb3b06489ed 100644 --- a/packages/camera/camera_avfoundation/example/ios/RunnerTests/QueueUtilsTests.swift +++ b/packages/camera/camera_avfoundation/example/ios/RunnerTests/QueueUtilsTests.swift @@ -6,7 +6,7 @@ import XCTest @testable import camera_avfoundation -// Import Objectice-C part of the implementation when SwiftPM is used. +// Import Objective-C part of the implementation when SwiftPM is used. #if canImport(camera_avfoundation_objc) import camera_avfoundation_objc #endif diff --git a/packages/camera/camera_avfoundation/example/ios/RunnerTests/SampleBufferTests.swift b/packages/camera/camera_avfoundation/example/ios/RunnerTests/SampleBufferTests.swift index eeef97b292a..8d4c2e8f837 100644 --- a/packages/camera/camera_avfoundation/example/ios/RunnerTests/SampleBufferTests.swift +++ b/packages/camera/camera_avfoundation/example/ios/RunnerTests/SampleBufferTests.swift @@ -7,7 +7,7 @@ import XCTest @testable import camera_avfoundation -// Import Objectice-C part of the implementation when SwiftPM is used. +// Import Objective-C part of the implementation when SwiftPM is used. #if canImport(camera_avfoundation_objc) import camera_avfoundation_objc #endif diff --git a/packages/camera/camera_avfoundation/example/ios/RunnerTests/SavePhotoDelegateTests.swift b/packages/camera/camera_avfoundation/example/ios/RunnerTests/SavePhotoDelegateTests.swift index 4bea59b6be3..c5aafcc5b46 100644 --- a/packages/camera/camera_avfoundation/example/ios/RunnerTests/SavePhotoDelegateTests.swift +++ b/packages/camera/camera_avfoundation/example/ios/RunnerTests/SavePhotoDelegateTests.swift @@ -7,7 +7,7 @@ import XCTest @testable import camera_avfoundation -// Import Objectice-C part of the implementation when SwiftPM is used. +// Import Objective-C part of the implementation when SwiftPM is used. #if canImport(camera_avfoundation_objc) import camera_avfoundation_objc #endif diff --git a/packages/camera/camera_avfoundation/example/ios/RunnerTests/StreamingTests.swift b/packages/camera/camera_avfoundation/example/ios/RunnerTests/StreamingTests.swift index 497923bd06f..c2296cff926 100644 --- a/packages/camera/camera_avfoundation/example/ios/RunnerTests/StreamingTests.swift +++ b/packages/camera/camera_avfoundation/example/ios/RunnerTests/StreamingTests.swift @@ -7,7 +7,7 @@ import XCTest @testable import camera_avfoundation -// Import Objectice-C part of the implementation when SwiftPM is used. +// Import Objective-C part of the implementation when SwiftPM is used. #if canImport(camera_avfoundation_objc) import camera_avfoundation_objc #endif diff --git a/packages/camera/camera_avfoundation/example/ios/RunnerTests/ThreadSafeEventChannelTests.swift b/packages/camera/camera_avfoundation/example/ios/RunnerTests/ThreadSafeEventChannelTests.swift index b2eed05f364..127219895d1 100644 --- a/packages/camera/camera_avfoundation/example/ios/RunnerTests/ThreadSafeEventChannelTests.swift +++ b/packages/camera/camera_avfoundation/example/ios/RunnerTests/ThreadSafeEventChannelTests.swift @@ -6,7 +6,7 @@ import XCTest @testable import camera_avfoundation -// Import Objectice-C part of the implementation when SwiftPM is used. +// Import Objective-C part of the implementation when SwiftPM is used. #if canImport(camera_avfoundation_objc) import camera_avfoundation_objc #endif diff --git a/packages/camera/camera_avfoundation/ios/camera_avfoundation/Sources/camera_avfoundation/Camera.swift b/packages/camera/camera_avfoundation/ios/camera_avfoundation/Sources/camera_avfoundation/Camera.swift index 1acb3e2a90c..38d21a7cf6a 100644 --- a/packages/camera/camera_avfoundation/ios/camera_avfoundation/Sources/camera_avfoundation/Camera.swift +++ b/packages/camera/camera_avfoundation/ios/camera_avfoundation/Sources/camera_avfoundation/Camera.swift @@ -6,7 +6,7 @@ import AVFoundation import CoreMotion import Flutter -// Import Objectice-C part of the implementation when SwiftPM is used. +// Import Objective-C part of the implementation when SwiftPM is used. #if canImport(camera_avfoundation_objc) import camera_avfoundation_objc #endif diff --git a/packages/camera/camera_avfoundation/ios/camera_avfoundation/Sources/camera_avfoundation/CameraPlugin.swift b/packages/camera/camera_avfoundation/ios/camera_avfoundation/Sources/camera_avfoundation/CameraPlugin.swift index 3b3eaaae051..ce8ccf59d6c 100644 --- a/packages/camera/camera_avfoundation/ios/camera_avfoundation/Sources/camera_avfoundation/CameraPlugin.swift +++ b/packages/camera/camera_avfoundation/ios/camera_avfoundation/Sources/camera_avfoundation/CameraPlugin.swift @@ -5,7 +5,7 @@ import Flutter import ObjectiveC -// Import Objectice-C part of the implementation when SwiftPM is used. +// Import Objective-C part of the implementation when SwiftPM is used. #if canImport(camera_avfoundation_objc) import camera_avfoundation_objc #endif @@ -248,12 +248,9 @@ extension CameraPlugin: FCPCameraApi { initialCameraName: name ) - var error: NSError? - let newCamera = DefaultCamera(configuration: camConfiguration, error: &error) + do { + let newCamera = try DefaultCamera(configuration: camConfiguration) - if let error = error { - completion(nil, CameraPlugin.flutterErrorFromNSError(error)) - } else { camera?.close() camera = newCamera @@ -261,6 +258,8 @@ extension CameraPlugin: FCPCameraApi { guard let strongSelf = self else { return } completion(NSNumber(value: strongSelf.registry.register(newCamera)), nil) } + } catch let error as NSError { + completion(nil, CameraPlugin.flutterErrorFromNSError(error)) } } diff --git a/packages/camera/camera_avfoundation/ios/camera_avfoundation/Sources/camera_avfoundation/DefaultCamera.swift b/packages/camera/camera_avfoundation/ios/camera_avfoundation/Sources/camera_avfoundation/DefaultCamera.swift index 022ceb2367e..683241ee2e1 100644 --- a/packages/camera/camera_avfoundation/ios/camera_avfoundation/Sources/camera_avfoundation/DefaultCamera.swift +++ b/packages/camera/camera_avfoundation/ios/camera_avfoundation/Sources/camera_avfoundation/DefaultCamera.swift @@ -4,13 +4,16 @@ import CoreMotion -// Import Objectice-C part of the implementation when SwiftPM is used. +// Import Objective-C part of the implementation when SwiftPM is used. #if canImport(camera_avfoundation_objc) import camera_avfoundation_objc #endif final class DefaultCamera: FLTCam, Camera { - override var videoFormat: FourCharCode { + var dartAPI: FCPCameraEventApi? + var onFrameAvailable: (() -> Void)? + + var videoFormat: FourCharCode = kCVPixelFormatType_32BGRA { didSet { captureVideoOutput.videoSettings = [ kCVPixelBufferPixelFormatTypeKey as String: videoFormat @@ -18,6 +21,8 @@ final class DefaultCamera: FLTCam, Camera { } } + private(set) var isPreviewPaused = false + override var deviceOrientation: UIDeviceOrientation { get { super.deviceOrientation } set { @@ -42,11 +47,55 @@ final class DefaultCamera: FLTCam, Camera { /// Videos are written to disk by `videoAdaptor` on an internal queue managed by AVFoundation. private let photoIOQueue = DispatchQueue(label: "io.flutter.camera.photoIOQueue") + /// All DefaultCamera's state access and capture session related operations should be run on this queue. + private let captureSessionQueue: DispatchQueue + + private let mediaSettings: FCPPlatformMediaSettings + private let mediaSettingsAVWrapper: FLTCamMediaSettingsAVWrapper + + /// A wrapper for AVCaptureDevice creation to allow for dependency injection in tests. + private let captureDeviceFactory: CaptureDeviceFactory + private let audioCaptureDeviceFactory: AudioCaptureDeviceFactory + private let captureDeviceInputFactory: FLTCaptureDeviceInputFactory + private let assetWriterFactory: AssetWriterFactory + private let inputPixelBufferAdaptorFactory: InputPixelBufferAdaptorFactory + + private let deviceOrientationProvider: FLTDeviceOrientationProviding + + private var videoWriter: FLTAssetWriter? + private var videoWriterInput: FLTAssetWriterInput? + private var audioWriterInput: FLTAssetWriterInput? + private var videoAdaptor: FLTAssetWriterInputPixelBufferAdaptor? + + /// A dictionary to retain all in-progress FLTSavePhotoDelegates. The key of the dictionary is the + /// AVCapturePhotoSettings's uniqueID for each photo capture operation, and the value is the + /// FLTSavePhotoDelegate that handles the result of each photo capture operation. Note that photo + /// capture operations may overlap, so FLTCam has to keep track of multiple delegates in progress, + /// instead of just a single delegate reference. + private(set) var inProgressSavePhotoDelegates = [Int64: FLTSavePhotoDelegate]() + + private var imageStreamHandler: FLTImageStreamHandler? + /// Tracks the latest pixel buffer sent from AVFoundation's sample buffer delegate callback. /// Used to deliver the latest pixel buffer to the flutter engine via the `copyPixelBuffer` API. private var latestPixelBuffer: CVPixelBuffer? + + private var videoRecordingPath: String? + private var isRecordingPaused = false + private var isFirstVideoSample = false + private var videoIsDisconnected = false + private var audioIsDisconnected = false + private var isAudioSetup = false private var lastVideoSampleTime = CMTime.zero private var lastAudioSampleTime = CMTime.zero + private var videoTimeOffset = CMTime.zero + private var audioTimeOffset = CMTime.zero + + /// True when images from the camera are being streamed. + private(set) var isStreamingImages = false + + /// Number of frames currently pending processing. + private var streamingPendingFramesCount = 0 /// Maximum number of frames pending processing. /// To limit memory consumption, limit the number of frames pending processing. @@ -56,6 +105,7 @@ final class DefaultCamera: FLTCam, Camera { private var exposureMode = FCPPlatformExposureMode.auto private var focusMode = FCPPlatformFocusMode.auto + private var flashMode: FCPPlatformFlashMode private static func flutterErrorFromNSError(_ error: NSError) -> FlutterError { return FlutterError( @@ -92,6 +142,95 @@ final class DefaultCamera: FLTCam, Camera { return (captureVideoInput, captureVideoOutput, connection) } + init(configuration: FLTCamConfiguration) throws { + captureSessionQueue = configuration.captureSessionQueue + mediaSettings = configuration.mediaSettings + mediaSettingsAVWrapper = configuration.mediaSettingsWrapper + captureDeviceFactory = configuration.captureDeviceFactory + audioCaptureDeviceFactory = configuration.audioCaptureDeviceFactory + captureDeviceInputFactory = configuration.captureDeviceInputFactory + assetWriterFactory = configuration.assetWriterFactory + inputPixelBufferAdaptorFactory = configuration.inputPixelBufferAdaptorFactory + deviceOrientationProvider = configuration.deviceOrientationProvider + + let captureDevice = captureDeviceFactory(configuration.initialCameraName) + flashMode = captureDevice.hasFlash ? .auto : .off + + super.init() + + videoCaptureSession = configuration.videoCaptureSession + audioCaptureSession = configuration.audioCaptureSession + videoDimensionsForFormat = configuration.videoDimensionsForFormat + + self.captureDevice = captureDevice + + capturePhotoOutput = FLTDefaultCapturePhotoOutput(photoOutput: AVCapturePhotoOutput()) + capturePhotoOutput.highResolutionCaptureEnabled = true + + videoCaptureSession.automaticallyConfiguresApplicationAudioSession = false + audioCaptureSession.automaticallyConfiguresApplicationAudioSession = false + + deviceOrientation = configuration.orientation + + let connection: AVCaptureConnection + (captureVideoInput, captureVideoOutput, connection) = try DefaultCamera.createConnection( + captureDevice: captureDevice, + videoFormat: videoFormat, + captureDeviceInputFactory: configuration.captureDeviceInputFactory) + + captureVideoOutput.setSampleBufferDelegate(self, queue: captureSessionQueue) + + videoCaptureSession.addInputWithNoConnections(captureVideoInput) + videoCaptureSession.addOutputWithNoConnections(captureVideoOutput.avOutput) + videoCaptureSession.addConnection(connection) + + videoCaptureSession.addOutput(capturePhotoOutput.avOutput) + + motionManager.startAccelerometerUpdates() + + if mediaSettings.framesPerSecond != nil { + // The frame rate can be changed only on a locked for configuration device. + try mediaSettingsAVWrapper.lockDevice(captureDevice) + mediaSettingsAVWrapper.beginConfiguration(for: videoCaptureSession) + + // Possible values for presets are hard-coded in FLT interface having + // corresponding AVCaptureSessionPreset counterparts. + // If _resolutionPreset is not supported by camera there is + // fallback to lower resolution presets. + // If none can be selected there is error condition. + do { + try setCaptureSessionPreset(mediaSettings.resolutionPreset) + } catch { + videoCaptureSession.commitConfiguration() + captureDevice.unlockForConfiguration() + throw error + } + + FLTSelectBestFormatForRequestedFrameRate( + captureDevice, + mediaSettings, + videoDimensionsForFormat) + + if let framesPerSecond = mediaSettings.framesPerSecond { + // Set frame rate with 1/10 precision allowing non-integral values. + let fpsNominator = floor(framesPerSecond.doubleValue * 10.0) + let duration = CMTimeMake(value: 10, timescale: Int32(fpsNominator)) + + mediaSettingsAVWrapper.setMinFrameDuration(duration, on: captureDevice) + mediaSettingsAVWrapper.setMaxFrameDuration(duration, on: captureDevice) + } + + mediaSettingsAVWrapper.commitConfiguration(for: videoCaptureSession) + mediaSettingsAVWrapper.unlockDevice(captureDevice) + } else { + // If the frame rate is not important fall to a less restrictive + // behavior (no configuration locking). + try setCaptureSessionPreset(mediaSettings.resolutionPreset) + } + + updateOrientation() + } + func setUpCaptureSessionForAudioIfNeeded() { // Don't setup audio twice or we will lose the audio. guard !mediaSettings.enableAudio || !isAudioSetup else { return } @@ -443,8 +582,9 @@ final class DefaultCamera: FLTCam, Camera { guard let strongSelf = self else { return } strongSelf.captureSessionQueue.async { [weak self] in - self?.inProgressSavePhotoDelegates.removeObject( - forKey: settings.uniqueID) + self?.inProgressSavePhotoDelegates.removeValue( + forKey: + settings.uniqueID) } if let error = error { diff --git a/packages/camera/camera_avfoundation/ios/camera_avfoundation/Sources/camera_avfoundation_objc/FLTCam.m b/packages/camera/camera_avfoundation/ios/camera_avfoundation/Sources/camera_avfoundation_objc/FLTCam.m index 62c5eae2829..c1f3675fb9f 100644 --- a/packages/camera/camera_avfoundation/ios/camera_avfoundation/Sources/camera_avfoundation_objc/FLTCam.m +++ b/packages/camera/camera_avfoundation/ios/camera_avfoundation/Sources/camera_avfoundation_objc/FLTCam.m @@ -19,151 +19,10 @@ #import "./include/camera_avfoundation/QueueUtils.h" #import "./include/camera_avfoundation/messages.g.h" -@interface FLTCam () - -@property(readonly, nonatomic) int64_t textureId; - -@property(readonly, nonatomic) CGSize captureSize; -@property(strong, nonatomic) - NSObject *assetWriterPixelBufferAdaptor; -@property(strong, nonatomic) AVCaptureVideoDataOutput *videoOutput; - -/// A wrapper for CMVideoFormatDescriptionGetDimensions. -/// Allows for alternate implementations in tests. -@property(nonatomic, copy) VideoDimensionsForFormat videoDimensionsForFormat; - +@interface FLTCam () @end @implementation FLTCam - -NSString *const errorMethod = @"error"; - -- (instancetype)initWithConfiguration:(nonnull FLTCamConfiguration *)configuration - error:(NSError **)error { - self = [super init]; - NSAssert(self, @"super init cannot be nil"); - _mediaSettings = configuration.mediaSettings; - _mediaSettingsAVWrapper = configuration.mediaSettingsWrapper; - - _captureSessionQueue = configuration.captureSessionQueue; - _videoCaptureSession = configuration.videoCaptureSession; - _audioCaptureSession = configuration.audioCaptureSession; - _captureDeviceFactory = configuration.captureDeviceFactory; - _audioCaptureDeviceFactory = configuration.audioCaptureDeviceFactory; - _captureDevice = _captureDeviceFactory(configuration.initialCameraName); - _captureDeviceInputFactory = configuration.captureDeviceInputFactory; - _videoDimensionsForFormat = configuration.videoDimensionsForFormat; - _flashMode = _captureDevice.hasFlash ? FCPPlatformFlashModeAuto : FCPPlatformFlashModeOff; - _lockedCaptureOrientation = UIDeviceOrientationUnknown; - _deviceOrientation = configuration.orientation; - _videoFormat = kCVPixelFormatType_32BGRA; - _inProgressSavePhotoDelegates = [NSMutableDictionary dictionary]; - _fileFormat = FCPPlatformImageFileFormatJpeg; - _videoCaptureSession.automaticallyConfiguresApplicationAudioSession = NO; - _audioCaptureSession.automaticallyConfiguresApplicationAudioSession = NO; - _assetWriterFactory = configuration.assetWriterFactory; - _inputPixelBufferAdaptorFactory = configuration.inputPixelBufferAdaptorFactory; - - NSError *localError = nil; - AVCaptureConnection *connection = [self createConnection:&localError]; - if (localError) { - if (error != nil) { - *error = localError; - } - return nil; - } - - [_videoCaptureSession addInputWithNoConnections:_captureVideoInput]; - [_videoCaptureSession addOutputWithNoConnections:_captureVideoOutput.avOutput]; - [_videoCaptureSession addConnection:connection]; - - _capturePhotoOutput = - [[FLTDefaultCapturePhotoOutput alloc] initWithPhotoOutput:[AVCapturePhotoOutput new]]; - [_capturePhotoOutput setHighResolutionCaptureEnabled:YES]; - [_videoCaptureSession addOutput:_capturePhotoOutput.avOutput]; - - _motionManager = [[CMMotionManager alloc] init]; - [_motionManager startAccelerometerUpdates]; - - _deviceOrientationProvider = configuration.deviceOrientationProvider; - - if (_mediaSettings.framesPerSecond) { - // The frame rate can be changed only on a locked for configuration device. - if ([_mediaSettingsAVWrapper lockDevice:_captureDevice error:error]) { - [_mediaSettingsAVWrapper beginConfigurationForSession:_videoCaptureSession]; - - // Possible values for presets are hard-coded in FLT interface having - // corresponding AVCaptureSessionPreset counterparts. - // If _resolutionPreset is not supported by camera there is - // fallback to lower resolution presets. - // If none can be selected there is error condition. - if (![self setCaptureSessionPreset:_mediaSettings.resolutionPreset withError:error]) { - [_videoCaptureSession commitConfiguration]; - [_captureDevice unlockForConfiguration]; - return nil; - } - - FLTSelectBestFormatForRequestedFrameRate(_captureDevice, _mediaSettings, - _videoDimensionsForFormat); - - // Set frame rate with 1/10 precision allowing not integral values. - int fpsNominator = floor([_mediaSettings.framesPerSecond doubleValue] * 10.0); - CMTime duration = CMTimeMake(10, fpsNominator); - - [_mediaSettingsAVWrapper setMinFrameDuration:duration onDevice:_captureDevice]; - [_mediaSettingsAVWrapper setMaxFrameDuration:duration onDevice:_captureDevice]; - - [_mediaSettingsAVWrapper commitConfigurationForSession:_videoCaptureSession]; - [_mediaSettingsAVWrapper unlockDevice:_captureDevice]; - } else { - return nil; - } - } else { - // If the frame rate is not important fall to a less restrictive - // behavior (no configuration locking). - if (![self setCaptureSessionPreset:_mediaSettings.resolutionPreset withError:error]) { - return nil; - } - } - - [self updateOrientation]; - - return self; -} - -- (AVCaptureConnection *)createConnection:(NSError **)error { - // Setup video capture input. - _captureVideoInput = [_captureDeviceInputFactory deviceInputWithDevice:_captureDevice - error:error]; - - // Test the return value of the `deviceInputWithDevice` method to see whether an error occurred. - // Don’t just test to see whether the error pointer was set to point to an error. - // See: - // https://developer.apple.com/library/archive/documentation/Cocoa/Conceptual/ProgrammingWithObjectiveC/ErrorHandling/ErrorHandling.html - if (!_captureVideoInput) { - return nil; - } - - // Setup video capture output. - _captureVideoOutput = [[FLTDefaultCaptureVideoDataOutput alloc] - initWithCaptureVideoOutput:[AVCaptureVideoDataOutput new]]; - _captureVideoOutput.videoSettings = - @{(NSString *)kCVPixelBufferPixelFormatTypeKey : @(_videoFormat)}; - [_captureVideoOutput setAlwaysDiscardsLateVideoFrames:YES]; - [_captureVideoOutput setSampleBufferDelegate:self queue:_captureSessionQueue]; - - // Setup video capture connection. - AVCaptureConnection *connection = - [AVCaptureConnection connectionWithInputPorts:_captureVideoInput.ports - output:_captureVideoOutput.avOutput]; - if ([_captureDevice position] == AVCaptureDevicePositionFront) { - connection.videoMirrored = YES; - } - - return connection; -} - - (void)updateOrientation { if (_isRecording) { return; diff --git a/packages/camera/camera_avfoundation/ios/camera_avfoundation/Sources/camera_avfoundation_objc/include/camera_avfoundation/FLTCam.h b/packages/camera/camera_avfoundation/ios/camera_avfoundation/Sources/camera_avfoundation_objc/include/camera_avfoundation/FLTCam.h index 6cb0fdc4de0..67d01405f8a 100644 --- a/packages/camera/camera_avfoundation/ios/camera_avfoundation/Sources/camera_avfoundation_objc/include/camera_avfoundation/FLTCam.h +++ b/packages/camera/camera_avfoundation/ios/camera_avfoundation/Sources/camera_avfoundation_objc/include/camera_avfoundation/FLTCam.h @@ -23,58 +23,28 @@ NS_ASSUME_NONNULL_BEGIN // captureDevice is assignable for the Swift DefaultCamera subclass @property(strong, nonatomic) NSObject *captureDevice; @property(readonly, nonatomic) CGSize previewSize; -@property(assign, nonatomic) BOOL isPreviewPaused; -@property(nonatomic, copy, nullable) void (^onFrameAvailable)(void); -/// The API instance used to communicate with the Dart side of the plugin. Once initially set, this -/// should only ever be accessed on the main thread. -@property(nonatomic, nullable) FCPCameraEventApi *dartAPI; -// Format used for video and image streaming. -@property(assign, nonatomic) FourCharCode videoFormat; @property(assign, nonatomic) FCPPlatformImageFileFormat fileFormat; // Properties exposed for the Swift DefaultCamera subclass -@property(nonatomic, nullable) FLTImageStreamHandler *imageStreamHandler; -/// Number of frames currently pending processing. -@property(assign, nonatomic) int streamingPendingFramesCount; -@property(assign, nonatomic) BOOL isFirstVideoSample; @property(assign, nonatomic) BOOL isRecording; -@property(assign, nonatomic) BOOL isRecordingPaused; -@property(strong, nonatomic, nullable) NSObject *videoWriter; -@property(assign, nonatomic) BOOL videoIsDisconnected; -@property(assign, nonatomic) BOOL audioIsDisconnected; -@property(assign, nonatomic) CMTime videoTimeOffset; -@property(assign, nonatomic) CMTime audioTimeOffset; -@property(strong, nonatomic, nullable) NSObject *videoWriterInput; -@property(strong, nonatomic, nullable) NSObject *audioWriterInput; -@property(nullable) NSObject *videoAdaptor; -@property(readonly, nonatomic) NSObject *videoCaptureSession; -@property(readonly, nonatomic) NSObject *audioCaptureSession; -@property(readonly, nonatomic) NSObject *deviceOrientationProvider; +// videoCaptureSession is assignable for the Swift DefaultCamera subclass +@property(strong, nonatomic) NSObject *videoCaptureSession; +// audioCaptureSession is assignable for the Swift DefaultCamera subclass +@property(strong, nonatomic) NSObject *audioCaptureSession; @property(assign, nonatomic) UIDeviceOrientation lockedCaptureOrientation; @property(assign, nonatomic) UIDeviceOrientation deviceOrientation; -@property(assign, nonatomic) FCPPlatformFlashMode flashMode; @property(nonatomic) CMMotionManager *motionManager; -@property(strong, nonatomic, nullable) NSString *videoRecordingPath; -@property(nonatomic, copy) CaptureDeviceFactory captureDeviceFactory; @property(strong, nonatomic) NSObject *captureVideoInput; -@property(readonly, nonatomic) NSObject *captureDeviceInputFactory; -/// All FLTCam's state access and capture session related operations should be on run on this queue. -@property(strong, nonatomic) dispatch_queue_t captureSessionQueue; -@property(nonatomic, copy) AssetWriterFactory assetWriterFactory; -@property(readonly, nonatomic) FLTCamMediaSettingsAVWrapper *mediaSettingsAVWrapper; -@property(readonly, nonatomic) FCPPlatformMediaSettings *mediaSettings; -@property(nonatomic, copy) InputPixelBufferAdaptorFactory inputPixelBufferAdaptorFactory; -@property(assign, nonatomic) BOOL isAudioSetup; -/// A wrapper for AVCaptureDevice creation to allow for dependency injection in tests. -@property(nonatomic, copy) AudioCaptureDeviceFactory audioCaptureDeviceFactory; - -/// Initializes an `FLTCam` instance with the given configuration. -/// @param error report to the caller if any error happened creating the camera. -- (instancetype)initWithConfiguration:(FLTCamConfiguration *)configuration error:(NSError **)error; +/// A wrapper for CMVideoFormatDescriptionGetDimensions. +/// Allows for alternate implementations in tests. +@property(nonatomic, copy) VideoDimensionsForFormat videoDimensionsForFormat; // Methods exposed for the Swift DefaultCamera subclass - (void)updateOrientation; +- (BOOL)setCaptureSessionPreset:(FCPPlatformResolutionPreset)resolutionPreset + withError:(NSError **)error; + @end NS_ASSUME_NONNULL_END diff --git a/packages/camera/camera_avfoundation/ios/camera_avfoundation/Sources/camera_avfoundation_objc/include/camera_avfoundation/FLTCam_Test.h b/packages/camera/camera_avfoundation/ios/camera_avfoundation/Sources/camera_avfoundation_objc/include/camera_avfoundation/FLTCam_Test.h index a604a22fd39..f8cad6c7804 100644 --- a/packages/camera/camera_avfoundation/ios/camera_avfoundation/Sources/camera_avfoundation_objc/include/camera_avfoundation/FLTCam_Test.h +++ b/packages/camera/camera_avfoundation/ios/camera_avfoundation/Sources/camera_avfoundation_objc/include/camera_avfoundation/FLTCam_Test.h @@ -20,15 +20,4 @@ /// The output for photo capturing. Exposed setter for unit tests. @property(strong, nonatomic) NSObject *capturePhotoOutput; -/// True when images from the camera are being streamed. -@property(assign, nonatomic) BOOL isStreamingImages; - -/// A dictionary to retain all in-progress FLTSavePhotoDelegates. The key of the dictionary is the -/// AVCapturePhotoSettings's uniqueID for each photo capture operation, and the value is the -/// FLTSavePhotoDelegate that handles the result of each photo capture operation. Note that photo -/// capture operations may overlap, so FLTCam has to keep track of multiple delegates in progress, -/// instead of just a single delegate reference. -@property(readonly, nonatomic) - NSMutableDictionary *inProgressSavePhotoDelegates; - @end diff --git a/packages/camera/camera_avfoundation/pubspec.yaml b/packages/camera/camera_avfoundation/pubspec.yaml index ba90f6ab57c..210a4b5a71a 100644 --- a/packages/camera/camera_avfoundation/pubspec.yaml +++ b/packages/camera/camera_avfoundation/pubspec.yaml @@ -2,7 +2,7 @@ name: camera_avfoundation description: iOS implementation of the camera plugin. repository: https://github.com/flutter/packages/tree/main/packages/camera/camera_avfoundation issue_tracker: https://github.com/flutter/flutter/issues?q=is%3Aissue+is%3Aopen+label%3A%22p%3A+camera%22 -version: 0.9.21+1 +version: 0.9.21+2 environment: sdk: ^3.6.0