diff --git a/packages/camera/camera_avfoundation/CHANGELOG.md b/packages/camera/camera_avfoundation/CHANGELOG.md index 25cda6a520c..1f2d8615df1 100644 --- a/packages/camera/camera_avfoundation/CHANGELOG.md +++ b/packages/camera/camera_avfoundation/CHANGELOG.md @@ -1,3 +1,7 @@ +## 0.9.22+7 + +* Migrates `FLTCaptureConnection`, `FLTCaptureDeviceFormat` and `FLTAssetWriter` classes to Swift. + ## 0.9.22+6 * Updates to Pigeon 26. diff --git a/packages/camera/camera_avfoundation/example/ios/RunnerTests/CameraSettingsTests.swift b/packages/camera/camera_avfoundation/example/ios/RunnerTests/CameraSettingsTests.swift index 8729b3f4fb1..ce2ac065176 100644 --- a/packages/camera/camera_avfoundation/example/ios/RunnerTests/CameraSettingsTests.swift +++ b/packages/camera/camera_avfoundation/example/ios/RunnerTests/CameraSettingsTests.swift @@ -72,7 +72,7 @@ private final class TestMediaSettingsAVWrapper: FLTCamMediaSettingsAVWrapper { } override func assetWriterAudioInput(withOutputSettings outputSettings: [String: Any]?) - -> FLTAssetWriterInput + -> AssetWriterInput { if let bitrate = outputSettings?[AVEncoderBitRateKey] as? Int, bitrate == testAudioBitrate { audioSettingsExpectation.fulfill() @@ -81,7 +81,7 @@ private final class TestMediaSettingsAVWrapper: FLTCamMediaSettingsAVWrapper { } override func assetWriterVideoInput(withOutputSettings outputSettings: [String: Any]?) - -> FLTAssetWriterInput + -> AssetWriterInput { if let compressionProperties = outputSettings?[AVVideoCompressionPropertiesKey] as? [String: Any], @@ -101,7 +101,7 @@ private final class TestMediaSettingsAVWrapper: FLTCamMediaSettingsAVWrapper { return MockAssetWriterInput() } - override func addInput(_ writerInput: FLTAssetWriterInput, to writer: FLTAssetWriter) { + override func addInput(_ writerInput: AssetWriterInput, to writer: AssetWriter) { // No-op. } @@ -203,7 +203,7 @@ final class CameraSettingsTests: XCTestCase { configuration.mediaSettings = settings let camera = CameraTestUtils.createTestCamera(configuration) - let range = camera.captureDevice.flutterActiveFormat.videoSupportedFrameRateRanges[0] + let range = camera.captureDevice.flutterActiveFormat.flutterVideoSupportedFrameRateRanges[0] XCTAssertLessThanOrEqual(range.minFrameRate, 60) XCTAssertGreaterThanOrEqual(range.maxFrameRate, 60) } diff --git a/packages/camera/camera_avfoundation/example/ios/RunnerTests/CameraTestUtils.swift b/packages/camera/camera_avfoundation/example/ios/RunnerTests/CameraTestUtils.swift index 10a7802cca2..2442831f0a6 100644 --- a/packages/camera/camera_avfoundation/example/ios/RunnerTests/CameraTestUtils.swift +++ b/packages/camera/camera_avfoundation/example/ios/RunnerTests/CameraTestUtils.swift @@ -39,17 +39,17 @@ enum CameraTestUtils { let frameRateRangeMock1 = MockFrameRateRange.init(minFrameRate: 3, maxFrameRate: 30) let captureDeviceFormatMock1 = MockCaptureDeviceFormat() - captureDeviceFormatMock1.videoSupportedFrameRateRanges = [frameRateRangeMock1] + captureDeviceFormatMock1.flutterVideoSupportedFrameRateRanges = [frameRateRangeMock1] let frameRateRangeMock2 = MockFrameRateRange.init(minFrameRate: 3, maxFrameRate: 60) let captureDeviceFormatMock2 = MockCaptureDeviceFormat() - captureDeviceFormatMock2.videoSupportedFrameRateRanges = [frameRateRangeMock2] + captureDeviceFormatMock2.flutterVideoSupportedFrameRateRanges = [frameRateRangeMock2] let captureDeviceMock = MockCaptureDevice() captureDeviceMock.flutterFormats = [captureDeviceFormatMock1, captureDeviceFormatMock2] - var currentFormat: FLTCaptureDeviceFormat = captureDeviceFormatMock1 + var currentFormat: CaptureDeviceFormat = captureDeviceFormatMock1 captureDeviceMock.activeFormatStub = { currentFormat } captureDeviceMock.setActiveFormatStub = { format in 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 45be267358c..9abf84bee2a 100644 --- a/packages/camera/camera_avfoundation/example/ios/RunnerTests/Mocks/MockAssetWriter.swift +++ b/packages/camera/camera_avfoundation/example/ios/RunnerTests/Mocks/MockAssetWriter.swift @@ -2,16 +2,16 @@ // 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) import camera_avfoundation_objc #endif -/// Mock implementation of `FLTAssetWriter` protocol which allows injecting a custom +/// Mock implementation of `AssetWriter` protocol which allows injecting a custom /// implementation. -final class MockAssetWriter: NSObject, FLTAssetWriter { +final class MockAssetWriter: NSObject, AssetWriter { var statusStub: (() -> AVAssetWriter.Status)? var startWritingStub: (() -> Bool)? var finishWritingStub: ((() -> Void) -> Void)? 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 9b6d7e2ca89..e7f45c472f0 100644 --- a/packages/camera/camera_avfoundation/example/ios/RunnerTests/Mocks/MockAssetWriterInput.swift +++ b/packages/camera/camera_avfoundation/example/ios/RunnerTests/Mocks/MockAssetWriterInput.swift @@ -2,25 +2,25 @@ // 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) import camera_avfoundation_objc #endif -/// Mock implementation of `FLTAssetWriterInput` protocol which allows injecting a custom +/// Mock implementation of `AssetWriterInput` protocol which allows injecting a custom /// implementation. -final class MockAssetWriterInput: NSObject, FLTAssetWriterInput { +final class MockAssetWriterInput: NSObject, AssetWriterInput { var appendStub: ((CMSampleBuffer) -> Bool)? - var input: AVAssetWriterInput { - preconditionFailure("Attempted to access unimplemented property: input") + var avInput: AVAssetWriterInput { + preconditionFailure("Attempted to access unimplemented property: avInput") } var expectsMediaDataInRealTime = false - var readyForMoreMediaData = false + var isReadyForMoreMediaData = false func append(_ sampleBuffer: CMSampleBuffer) -> Bool { return appendStub?(sampleBuffer) ?? false 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 f8d6731d469..cd1559c8765 100644 --- a/packages/camera/camera_avfoundation/example/ios/RunnerTests/Mocks/MockAssetWriterInputPixelBufferAdaptor.swift +++ b/packages/camera/camera_avfoundation/example/ios/RunnerTests/Mocks/MockAssetWriterInputPixelBufferAdaptor.swift @@ -2,17 +2,16 @@ // 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) import camera_avfoundation_objc #endif -/// Mock implementation of `FLTAssetWriterInputPixelBufferAdaptor` protocol which allows injecting a custom +/// Mock implementation of `AssetWriterInputPixelBufferAdaptor` protocol which allows injecting a custom /// implementation. -final class MockAssetWriterInputPixelBufferAdaptor: NSObject, FLTAssetWriterInputPixelBufferAdaptor -{ +final class MockAssetWriterInputPixelBufferAdaptor: NSObject, AssetWriterInputPixelBufferAdaptor { var appendStub: ((CVPixelBuffer, CMTime) -> Bool)? func append(_ pixelBuffer: CVPixelBuffer, withPresentationTime presentationTime: CMTime) -> Bool { 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 f65e0ce3c21..3f4cc9184fb 100644 --- a/packages/camera/camera_avfoundation/example/ios/RunnerTests/Mocks/MockCaptureConnection.swift +++ b/packages/camera/camera_avfoundation/example/ios/RunnerTests/Mocks/MockCaptureConnection.swift @@ -2,15 +2,15 @@ // 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) import camera_avfoundation_objc #endif -/// A mock implementation of `FLTCaptureConnection` that allows injecting a custom implementation. -final class MockCaptureConnection: NSObject, FLTCaptureConnection { +/// A mock implementation of `CaptureConnection` that allows injecting a custom implementation. +final class MockCaptureConnection: NSObject, CaptureConnection { var setVideoOrientationStub: ((AVCaptureVideoOrientation) -> Void)? var connection: AVCaptureConnection { 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 0e2a4442a39..51263bb2ec3 100644 --- a/packages/camera/camera_avfoundation/example/ios/RunnerTests/Mocks/MockCaptureDevice.swift +++ b/packages/camera/camera_avfoundation/example/ios/RunnerTests/Mocks/MockCaptureDevice.swift @@ -12,8 +12,8 @@ /// A mock implementation of `FLTCaptureDevice` that allows mocking the class /// properties. class MockCaptureDevice: NSObject, CaptureDevice { - var activeFormatStub: (() -> FLTCaptureDeviceFormat)? - var setActiveFormatStub: ((FLTCaptureDeviceFormat) -> Void)? + var activeFormatStub: (() -> CaptureDeviceFormat)? + var setActiveFormatStub: ((CaptureDeviceFormat) -> Void)? var getTorchModeStub: (() -> AVCaptureDevice.TorchMode)? var setTorchModeStub: ((AVCaptureDevice.TorchMode) -> Void)? var isFocusModeSupportedStub: ((AVCaptureDevice.FocusMode) -> Bool)? @@ -34,7 +34,7 @@ class MockCaptureDevice: NSObject, CaptureDevice { var position = AVCaptureDevice.Position.unspecified var deviceType = AVCaptureDevice.DeviceType.builtInWideAngleCamera - var flutterActiveFormat: FLTCaptureDeviceFormat { + var flutterActiveFormat: CaptureDeviceFormat { get { activeFormatStub?() ?? MockCaptureDeviceFormat() } @@ -43,7 +43,7 @@ class MockCaptureDevice: NSObject, CaptureDevice { } } - var flutterFormats: [FLTCaptureDeviceFormat] = [] + var flutterFormats: [CaptureDeviceFormat] = [] var hasFlash = false var hasTorch = false var isTorchAvailable = false 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 b34040ae0cf..0afa79f5967 100644 --- a/packages/camera/camera_avfoundation/example/ios/RunnerTests/Mocks/MockCaptureDeviceFormat.swift +++ b/packages/camera/camera_avfoundation/example/ios/RunnerTests/Mocks/MockCaptureDeviceFormat.swift @@ -2,20 +2,20 @@ // 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) import camera_avfoundation_objc #endif -/// A mock implementation of `FLTCaptureDeviceFormat` that allows mocking the class +/// A mock implementation of `CaptureDeviceFormat` that allows mocking the class /// properties. -final class MockCaptureDeviceFormat: NSObject, FLTCaptureDeviceFormat { +final class MockCaptureDeviceFormat: NSObject, CaptureDeviceFormat { /// The format associated with the capture device. - var format: AVCaptureDevice.Format { - preconditionFailure("Attempted to access unimplemented property: format") + var avFormat: AVCaptureDevice.Format { + preconditionFailure("Attempted to access unimplemented property: avFormat") } var _formatDescription: CMVideoFormatDescription? @@ -26,7 +26,7 @@ final class MockCaptureDeviceFormat: NSObject, FLTCaptureDeviceFormat { } /// The array of frame rate ranges supported by the video format. - var videoSupportedFrameRateRanges: [FLTFrameRateRange] = [] + var flutterVideoSupportedFrameRateRanges: [FrameRateRange] = [] override init() { super.init() 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 ad8f480f22c..9eb358aaf82 100644 --- a/packages/camera/camera_avfoundation/example/ios/RunnerTests/Mocks/MockCapturePhotoOutput.swift +++ b/packages/camera/camera_avfoundation/example/ios/RunnerTests/Mocks/MockCapturePhotoOutput.swift @@ -22,14 +22,14 @@ final class MockCapturePhotoOutput: NSObject, CapturePhotoOutput { ((_ settings: AVCapturePhotoSettings, _ delegate: AVCapturePhotoCaptureDelegate) -> Void)? // Stub that is called when the corresponding public method is called. - var connectionWithMediaTypeStub: ((_ mediaType: AVMediaType) -> FLTCaptureConnection?)? + var connectionWithMediaTypeStub: ((_ mediaType: AVMediaType) -> CaptureConnection?)? func capturePhoto(with settings: AVCapturePhotoSettings, delegate: AVCapturePhotoCaptureDelegate) { capturePhotoWithSettingsStub?(settings, delegate) } - func connection(with mediaType: AVMediaType) -> FLTCaptureConnection? { + func connection(with mediaType: AVMediaType) -> CaptureConnection? { return connectionWithMediaTypeStub?(mediaType) } } 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 98d1296a8b2..654d7dd5d05 100644 --- a/packages/camera/camera_avfoundation/example/ios/RunnerTests/Mocks/MockCaptureVideoDataOutput.swift +++ b/packages/camera/camera_avfoundation/example/ios/RunnerTests/Mocks/MockCaptureVideoDataOutput.swift @@ -16,9 +16,9 @@ class MockCaptureVideoDataOutput: NSObject, CaptureVideoDataOutput { var alwaysDiscardsLateVideoFrames = false var videoSettings: [String: Any]! = [:] - var connectionWithMediaTypeStub: ((AVMediaType) -> FLTCaptureConnection?)? + var connectionWithMediaTypeStub: ((AVMediaType) -> CaptureConnection?)? - func connection(with mediaType: AVMediaType) -> FLTCaptureConnection? { + func connection(with mediaType: AVMediaType) -> CaptureConnection? { return connectionWithMediaTypeStub?(mediaType) } 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 866e108d211..b6afb3016ba 100644 --- a/packages/camera/camera_avfoundation/example/ios/RunnerTests/Mocks/MockFrameRateRange.swift +++ b/packages/camera/camera_avfoundation/example/ios/RunnerTests/Mocks/MockFrameRateRange.swift @@ -2,20 +2,20 @@ // 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) import camera_avfoundation_objc #endif -/// A mock implementation of `FLTFrameRateRange` that allows mocking the class properties. -final class MockFrameRateRange: NSObject, FLTFrameRateRange { - var minFrameRate: Float - var maxFrameRate: Float +/// A mock implementation of `FrameRateRange` that allows mocking the class properties. +final class MockFrameRateRange: NSObject, FrameRateRange { + var minFrameRate: Float64 + var maxFrameRate: Float64 /// Initializes a `MockFrameRateRange` with the given frame rate range. - init(minFrameRate: Float, maxFrameRate: Float) { + init(minFrameRate: Float64, maxFrameRate: Float64) { self.minFrameRate = minFrameRate self.maxFrameRate = maxFrameRate } diff --git a/packages/camera/camera_avfoundation/example/ios/RunnerTests/SampleBufferTests.swift b/packages/camera/camera_avfoundation/example/ios/RunnerTests/SampleBufferTests.swift index 13252520776..86130035d14 100644 --- a/packages/camera/camera_avfoundation/example/ios/RunnerTests/SampleBufferTests.swift +++ b/packages/camera/camera_avfoundation/example/ios/RunnerTests/SampleBufferTests.swift @@ -44,18 +44,18 @@ private class FakeMediaSettingsAVWrapper: FLTCamMediaSettingsAVWrapper { } override func assetWriterAudioInput(withOutputSettings outputSettings: [String: Any]?) - -> FLTAssetWriterInput + -> AssetWriterInput { return inputMock } override func assetWriterVideoInput(withOutputSettings outputSettings: [String: Any]?) - -> FLTAssetWriterInput + -> AssetWriterInput { return inputMock } - override func addInput(_ writerInput: FLTAssetWriterInput, to writer: FLTAssetWriter) { + override func addInput(_ writerInput: AssetWriterInput, to writer: AssetWriter) { // No-op. } @@ -175,7 +175,7 @@ final class CameraSampleBufferTests: XCTestCase { writtenSamples.append("video") return true } - inputMock.readyForMoreMediaData = true + inputMock.isReadyForMoreMediaData = true inputMock.appendStub = { buffer in writtenSamples.append("audio") return true @@ -222,7 +222,7 @@ final class CameraSampleBufferTests: XCTestCase { } var audioAppended = false - inputMock.readyForMoreMediaData = true + inputMock.isReadyForMoreMediaData = true inputMock.appendStub = { buffer in let sampleTime = CMSampleBufferGetPresentationTimeStamp(buffer) XCTAssert(CMTIME_IS_NUMERIC(sampleTime)) @@ -262,7 +262,7 @@ final class CameraSampleBufferTests: XCTestCase { camera.startVideoRecording(completion: { error in }, messengerForStreaming: nil) - inputMock.readyForMoreMediaData = true + inputMock.isReadyForMoreMediaData = true sampleAppended = false camera.captureOutput( camera.captureVideoOutput.avOutput, @@ -270,7 +270,7 @@ final class CameraSampleBufferTests: XCTestCase { from: testVideoConnection) XCTAssertTrue(sampleAppended, "Sample was not appended.") - inputMock.readyForMoreMediaData = false + inputMock.isReadyForMoreMediaData = false sampleAppended = false camera.captureOutput( camera.captureVideoOutput.avOutput, @@ -327,7 +327,7 @@ final class CameraSampleBufferTests: XCTestCase { return true } - inputMock.readyForMoreMediaData = true + inputMock.isReadyForMoreMediaData = true camera.startVideoRecording(completion: { error in }, messengerForStreaming: nil) diff --git a/packages/camera/camera_avfoundation/ios/camera_avfoundation/Sources/camera_avfoundation/AssetWriter.swift b/packages/camera/camera_avfoundation/ios/camera_avfoundation/Sources/camera_avfoundation/AssetWriter.swift new file mode 100644 index 00000000000..d86662a9b8b --- /dev/null +++ b/packages/camera/camera_avfoundation/ios/camera_avfoundation/Sources/camera_avfoundation/AssetWriter.swift @@ -0,0 +1,45 @@ +// Copyright 2013 The Flutter Authors +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +import AVFoundation +import Foundation + +/// A protocol that is a direct passthrough to `AVAssetWriter`. It is used to allow for mocking +/// `AVAssetWriter` in tests. +protocol AssetWriter: NSObjectProtocol { + var status: AVAssetWriter.Status { get } + var error: Error? { get } + + func startWriting() -> Bool + func finishWriting(completionHandler handler: @escaping @Sendable () -> Void) + func startSession(atSourceTime startTime: CMTime) + func add(_ input: AVAssetWriterInput) +} + +/// A protocol that is a direct passthrough to `AVAssetWriterInput`. It is used to allow for mocking +/// `AVAssetWriterInput` in tests. +protocol AssetWriterInput: NSObjectProtocol { + /// The underlying `AVAssetWriterInput` instance. This exists so that the input + /// can be extracted when adding to an AVAssetWriter. + var avInput: AVAssetWriterInput { get } + + var expectsMediaDataInRealTime: Bool { get set } + var isReadyForMoreMediaData: Bool { get } + + func append(_ sampleBuffer: CMSampleBuffer) -> Bool +} + +/// A protocol that is a direct passthrough to `AVAssetWriterInputPixelBufferAdaptor`. It is used to +/// allow for mocking `AVAssetWriterInputPixelBufferAdaptor` in tests. +protocol AssetWriterInputPixelBufferAdaptor: NSObjectProtocol { + func append(_ pixelBuffer: CVPixelBuffer, withPresentationTime presentationTime: CMTime) -> Bool +} + +extension AVAssetWriter: AssetWriter {} + +extension AVAssetWriterInput: AssetWriterInput { + var avInput: AVAssetWriterInput { self } +} + +extension AVAssetWriterInputPixelBufferAdaptor: AssetWriterInputPixelBufferAdaptor {} diff --git a/packages/camera/camera_avfoundation/ios/camera_avfoundation/Sources/camera_avfoundation/CameraConfiguration.swift b/packages/camera/camera_avfoundation/ios/camera_avfoundation/Sources/camera_avfoundation/CameraConfiguration.swift index 9bac99def92..8e60ae35dd0 100644 --- a/packages/camera/camera_avfoundation/ios/camera_avfoundation/Sources/camera_avfoundation/CameraConfiguration.swift +++ b/packages/camera/camera_avfoundation/ios/camera_avfoundation/Sources/camera_avfoundation/CameraConfiguration.swift @@ -19,12 +19,12 @@ typealias AudioCaptureDeviceFactory = () -> CaptureDevice typealias CaptureSessionFactory = () -> CaptureSession -typealias AssetWriterFactory = (_ assetUrl: URL, _ fileType: AVFileType) throws -> FLTAssetWriter +typealias AssetWriterFactory = (_ assetUrl: URL, _ fileType: AVFileType) throws -> AssetWriter typealias InputPixelBufferAdaptorFactory = ( - _ input: FLTAssetWriterInput, _ settings: [String: Any]? + _ input: AssetWriterInput, _ settings: [String: Any]? ) -> - FLTAssetWriterInputPixelBufferAdaptor + AssetWriterInputPixelBufferAdaptor /// A configuration object that centralizes dependencies for `DefaultCamera`. class CameraConfiguration { @@ -70,22 +70,14 @@ class CameraConfiguration { } self.assetWriterFactory = { url, fileType in - var error: NSError? - let writer = FLTDefaultAssetWriter(url: url, fileType: fileType, error: &error) - - if let error = error { - throw error - } - - return writer + return try AVAssetWriter(outputURL: url, fileType: fileType) } self.inputPixelBufferAdaptorFactory = { assetWriterInput, sourcePixelBufferAttributes in - let adaptor = AVAssetWriterInputPixelBufferAdaptor( - assetWriterInput: assetWriterInput.input, + return AVAssetWriterInputPixelBufferAdaptor( + assetWriterInput: assetWriterInput.avInput, sourcePixelBufferAttributes: sourcePixelBufferAttributes ) - return FLTDefaultAssetWriterInputPixelBufferAdaptor(adaptor: adaptor) } } } diff --git a/packages/camera/camera_avfoundation/ios/camera_avfoundation/Sources/camera_avfoundation/CaptureConnection.swift b/packages/camera/camera_avfoundation/ios/camera_avfoundation/Sources/camera_avfoundation/CaptureConnection.swift new file mode 100644 index 00000000000..d63f71edf28 --- /dev/null +++ b/packages/camera/camera_avfoundation/ios/camera_avfoundation/Sources/camera_avfoundation/CaptureConnection.swift @@ -0,0 +1,26 @@ +// Copyright 2013 The Flutter Authors +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +import AVFoundation + +/// A protocol which is a direct passthrough to `AVCaptureConnection`. It exists to allow replacing +/// `AVCaptureConnection` in tests. +protocol CaptureConnection: NSObjectProtocol { + /// Corresponds to the `isVideoMirrored` property of `AVCaptureConnection` + var isVideoMirrored: Bool { get set } + + /// Corresponds to the `videoOrientation` property of `AVCaptureConnection` + var videoOrientation: AVCaptureVideoOrientation { get set } + + /// Corresponds to the `inputPorts` property of `AVCaptureConnection` + var inputPorts: [AVCaptureInput.Port] { get } + + /// Corresponds to the `supportsVideoMirroring` property of `AVCaptureConnection` + var isVideoMirroringSupported: Bool { get } + + /// Corresponds to the `supportsVideoOrientation` property of `AVCaptureConnection` + var isVideoOrientationSupported: Bool { get } +} + +extension AVCaptureConnection: CaptureConnection {} diff --git a/packages/camera/camera_avfoundation/ios/camera_avfoundation/Sources/camera_avfoundation/CaptureDevice.swift b/packages/camera/camera_avfoundation/ios/camera_avfoundation/Sources/camera_avfoundation/CaptureDevice.swift index c8d6437ceef..f24b53581a9 100644 --- a/packages/camera/camera_avfoundation/ios/camera_avfoundation/Sources/camera_avfoundation/CaptureDevice.swift +++ b/packages/camera/camera_avfoundation/ios/camera_avfoundation/Sources/camera_avfoundation/CaptureDevice.swift @@ -27,8 +27,8 @@ protocol CaptureDevice: NSObjectProtocol { var deviceType: AVCaptureDevice.DeviceType { get } // Format/Configuration - var flutterActiveFormat: FLTCaptureDeviceFormat { get set } - var flutterFormats: [FLTCaptureDeviceFormat] { get } + var flutterActiveFormat: CaptureDeviceFormat { get set } + var flutterFormats: [CaptureDeviceFormat] { get } // Flash/Torch var hasFlash: Bool { get } @@ -91,14 +91,12 @@ protocol CaptureDeviceInputFactory: NSObjectProtocol { extension AVCaptureDevice: CaptureDevice { var avDevice: AVCaptureDevice { self } - var flutterActiveFormat: FLTCaptureDeviceFormat { - get { FLTDefaultCaptureDeviceFormat.init(format: activeFormat) } - set { activeFormat = newValue.format } + var flutterActiveFormat: CaptureDeviceFormat { + get { activeFormat } + set { activeFormat = newValue.avFormat } } - var flutterFormats: [FLTCaptureDeviceFormat] { - return self.formats.map { FLTDefaultCaptureDeviceFormat.init(format: $0) } - } + var flutterFormats: [CaptureDeviceFormat] { formats } } extension AVCaptureInput: CaptureInput { diff --git a/packages/camera/camera_avfoundation/ios/camera_avfoundation/Sources/camera_avfoundation/CaptureDeviceFormat.swift b/packages/camera/camera_avfoundation/ios/camera_avfoundation/Sources/camera_avfoundation/CaptureDeviceFormat.swift new file mode 100644 index 00000000000..6905e36a953 --- /dev/null +++ b/packages/camera/camera_avfoundation/ios/camera_avfoundation/Sources/camera_avfoundation/CaptureDeviceFormat.swift @@ -0,0 +1,31 @@ +// Copyright 2013 The Flutter Authors +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +import AVFoundation + +/// A protocol which is a direct passthrough to `AVFrameRateRange`. It exists to allow replacing +/// `AVFrameRateRange` in tests as it has no public initializer. +protocol FrameRateRange: NSObjectProtocol { + var minFrameRate: Float64 { get } + var maxFrameRate: Float64 { get } +} + +/// A protocol which is a direct passthrough to `AVCaptureDeviceFormat`. It exists to allow +/// replacing `AVCaptureDeviceFormat` in tests as it has no public initializer. +protocol CaptureDeviceFormat: NSObjectProtocol { + /// The underlying `AVCaptureDeviceFormat` instance. This exists so that the format + /// can be extracted when setting the active format on a device. + var avFormat: AVCaptureDevice.Format { get } + + var formatDescription: CMFormatDescription { get } + var flutterVideoSupportedFrameRateRanges: [FrameRateRange] { get } +} + +extension AVFrameRateRange: FrameRateRange {} + +extension AVCaptureDevice.Format: CaptureDeviceFormat { + var avFormat: AVCaptureDevice.Format { self } + + var flutterVideoSupportedFrameRateRanges: [FrameRateRange] { videoSupportedFrameRateRanges } +} diff --git a/packages/camera/camera_avfoundation/ios/camera_avfoundation/Sources/camera_avfoundation/CaptureOutput.swift b/packages/camera/camera_avfoundation/ios/camera_avfoundation/Sources/camera_avfoundation/CaptureOutput.swift index fba320728d6..0d899f56190 100644 --- a/packages/camera/camera_avfoundation/ios/camera_avfoundation/Sources/camera_avfoundation/CaptureOutput.swift +++ b/packages/camera/camera_avfoundation/ios/camera_avfoundation/Sources/camera_avfoundation/CaptureOutput.swift @@ -3,7 +3,6 @@ // found in the LICENSE file. import AVFoundation -import Foundation // Import Objective-C part of the implementation when SwiftPM is used. #if canImport(camera_avfoundation_objc) @@ -14,7 +13,7 @@ import Foundation /// `AVCaptureOutput` in tests. protocol CaptureOutput { /// Returns a connection with the specified media type, or nil if no such connection exists. - func connection(with mediaType: AVMediaType) -> FLTCaptureConnection? + func connection(with mediaType: AVMediaType) -> CaptureConnection? } /// A protocol which is a direct passthrough to `AVCaptureVideoDataOutput`. It exists to allow @@ -41,9 +40,9 @@ extension AVCaptureVideoDataOutput: CaptureVideoDataOutput { return self } - func connection(with mediaType: AVMediaType) -> FLTCaptureConnection? { - guard let connection: AVCaptureConnection = connection(with: mediaType) else { return nil } - return FLTDefaultCaptureConnection(connection: connection) + func connection(with mediaType: AVMediaType) -> CaptureConnection? { + let connection: AVCaptureConnection? = connection(with: mediaType) + return connection } } @@ -72,8 +71,8 @@ extension AVCapturePhotoOutput: CapturePhotoOutput { return self } - func connection(with mediaType: AVMediaType) -> FLTCaptureConnection? { - guard let connection: AVCaptureConnection = connection(with: mediaType) else { return nil } - return FLTDefaultCaptureConnection(connection: connection) + func connection(with mediaType: AVMediaType) -> CaptureConnection? { + let connection: AVCaptureConnection? = connection(with: mediaType) + return connection } } 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 29a3afd9d5b..b6c87e06c73 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 @@ -67,11 +67,11 @@ final class DefaultCamera: NSObject, Camera { var capturePhotoOutput: CapturePhotoOutput private var captureVideoInput: CaptureInput - private var videoWriter: FLTAssetWriter? - private var videoWriterInput: FLTAssetWriterInput? - private var audioWriterInput: FLTAssetWriterInput? - private var assetWriterPixelBufferAdaptor: FLTAssetWriterInputPixelBufferAdaptor? - private var videoAdaptor: FLTAssetWriterInputPixelBufferAdaptor? + private var videoWriter: AssetWriter? + private var videoWriterInput: AssetWriterInput? + private var audioWriterInput: AssetWriterInput? + private var assetWriterPixelBufferAdaptor: AssetWriterInputPixelBufferAdaptor? + private var videoAdaptor: AssetWriterInputPixelBufferAdaptor? /// 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 @@ -309,11 +309,11 @@ final class DefaultCamera: NSObject, Camera { /// Finds the highest available resolution in terms of pixel count for the given device. /// Preferred are formats with the same subtype as current activeFormat. private func highestResolutionFormat(forCaptureDevice captureDevice: CaptureDevice) - -> FLTCaptureDeviceFormat? + -> CaptureDeviceFormat? { let preferredSubType = CMFormatDescriptionGetMediaSubType( captureDevice.flutterActiveFormat.formatDescription) - var bestFormat: FLTCaptureDeviceFormat? = nil + var bestFormat: CaptureDeviceFormat? = nil var maxPixelCount: UInt = 0 var isBestSubTypePreferred = false @@ -510,7 +510,8 @@ final class DefaultCamera: NSObject, Camera { // didOutputSampleBuffer had chance to call startWriting and lag at start of video // https://github.com/flutter/flutter/issues/132016 // https://github.com/flutter/flutter/issues/151319 - videoWriter?.startWriting() + // Result ignored in line with the Objective-C implementation + let _ = videoWriter?.startWriting() isFirstVideoSample = true isRecording = true isRecordingPaused = false @@ -524,7 +525,7 @@ final class DefaultCamera: NSObject, Camera { private func setupWriter(forPath path: String) -> Bool { setUpCaptureSessionForAudioIfNeeded() - let videoWriter: FLTAssetWriter + let videoWriter: AssetWriter do { videoWriter = try assetWriterFactory(URL(fileURLWithPath: path), .mp4) @@ -1218,8 +1219,9 @@ final class DefaultCamera: NSObject, Camera { let nextSampleTime = CMTimeSubtract(lastVideoSampleTime, videoTimeOffset) // do not append sample buffer when readyForMoreMediaData is NO to avoid crash // https://github.com/flutter/flutter/issues/132073 - if videoWriterInput?.readyForMoreMediaData ?? false { - videoAdaptor?.append(nextBuffer!, withPresentationTime: nextSampleTime) + if videoWriterInput?.isReadyForMoreMediaData ?? false { + // Result ignored in line with the Objective-C implementation + let _ = videoAdaptor?.append(nextBuffer!, withPresentationTime: nextSampleTime) } } else { let dur = CMSampleBufferGetDuration(sampleBuffer) @@ -1368,7 +1370,7 @@ final class DefaultCamera: NSObject, Camera { } return } - if audioWriterInput?.readyForMoreMediaData ?? false { + if audioWriterInput?.isReadyForMoreMediaData ?? false { if !(audioWriterInput?.append(sampleBuffer) ?? false) { reportErrorMessage("Unable to write to audio input") } diff --git a/packages/camera/camera_avfoundation/ios/camera_avfoundation/Sources/camera_avfoundation/FormatUtils.swift b/packages/camera/camera_avfoundation/ios/camera_avfoundation/Sources/camera_avfoundation/FormatUtils.swift index 98e7f90f054..11c2b255b82 100644 --- a/packages/camera/camera_avfoundation/ios/camera_avfoundation/Sources/camera_avfoundation/FormatUtils.swift +++ b/packages/camera/camera_avfoundation/ios/camera_avfoundation/Sources/camera_avfoundation/FormatUtils.swift @@ -11,17 +11,17 @@ import AVFoundation /// Determines the video dimensions (width and height) for a given capture device format. /// Used in tests to mock CMVideoFormatDescriptionGetDimensions. -typealias VideoDimensionsConverter = (FLTCaptureDeviceFormat) -> CMVideoDimensions +typealias VideoDimensionsConverter = (CaptureDeviceFormat) -> CMVideoDimensions enum FormatUtils { /// Returns frame rate supported by format closest to targetFrameRate. - static private func bestFrameRate(for format: FLTCaptureDeviceFormat, targetFrameRate: Double) + static private func bestFrameRate(for format: CaptureDeviceFormat, targetFrameRate: Double) -> Double { var bestFrameRate: Double = 0 var minDistance: Double = Double.greatestFiniteMagnitude - for range in format.videoSupportedFrameRateRanges { + for range in format.flutterVideoSupportedFrameRateRanges { let frameRate = min( max(targetFrameRate, Double(range.minFrameRate)), Double(range.maxFrameRate)) let distance = abs(frameRate - targetFrameRate) diff --git a/packages/camera/camera_avfoundation/ios/camera_avfoundation/Sources/camera_avfoundation/MediaSettingsAVWrapper.swift b/packages/camera/camera_avfoundation/ios/camera_avfoundation/Sources/camera_avfoundation/MediaSettingsAVWrapper.swift index b74557c0af8..42b6bf046c5 100644 --- a/packages/camera/camera_avfoundation/ios/camera_avfoundation/Sources/camera_avfoundation/MediaSettingsAVWrapper.swift +++ b/packages/camera/camera_avfoundation/ios/camera_avfoundation/Sources/camera_avfoundation/MediaSettingsAVWrapper.swift @@ -4,7 +4,6 @@ import AVFoundation import CoreMedia -import Foundation // Import Objective-C part of the implementation when SwiftPM is used. #if canImport(camera_avfoundation_objc) @@ -65,31 +64,29 @@ class FLTCamMediaSettingsAVWrapper { /// Creates a new input of the audio media type to receive sample buffers for writing to /// the output file. /// - Parameter outputSettings: The settings used for encoding the audio appended to the output. - /// - Returns: An instance of `FLTAssetWriterInput`. + /// - Returns: An instance of `AssetWriterInput`. func assetWriterAudioInput(withOutputSettings outputSettings: [String: Any]?) - -> FLTAssetWriterInput + -> AssetWriterInput { - let input = AVAssetWriterInput(mediaType: .audio, outputSettings: outputSettings) - return FLTDefaultAssetWriterInput(input: input) + return AVAssetWriterInput(mediaType: .audio, outputSettings: outputSettings) } /// Creates a new input of the video media type to receive sample buffers for writing to /// the output file. /// - Parameter outputSettings: The settings used for encoding the video appended to the output. - /// - Returns: An instance of `FLTAssetWriterInput`. + /// - Returns: An instance of `AssetWriterInput`. func assetWriterVideoInput(withOutputSettings outputSettings: [String: Any]?) - -> FLTAssetWriterInput + -> AssetWriterInput { - let input = AVAssetWriterInput(mediaType: .video, outputSettings: outputSettings) - return FLTDefaultAssetWriterInput(input: input) + return AVAssetWriterInput(mediaType: .video, outputSettings: outputSettings) } /// Adds an input to the asset writer. /// - Parameters: - /// - writerInput: The `FLTAssetWriterInput` object to be added. - /// - writer: The `FLTAssetWriter` object. - func addInput(_ writerInput: FLTAssetWriterInput, to writer: FLTAssetWriter) { - writer.add(writerInput.input) + /// - writerInput: The `AssetWriterInput` object to be added. + /// - writer: The `AssetWriter` object. + func addInput(_ writerInput: AssetWriterInput, to writer: AssetWriter) { + writer.add(writerInput.avInput) } /// Specifies the recommended video settings for `FLTCaptureVideoDataOutput`. diff --git a/packages/camera/camera_avfoundation/ios/camera_avfoundation/Sources/camera_avfoundation_objc/FLTAssetWriter.m b/packages/camera/camera_avfoundation/ios/camera_avfoundation/Sources/camera_avfoundation_objc/FLTAssetWriter.m deleted file mode 100644 index ce81673d806..00000000000 --- a/packages/camera/camera_avfoundation/ios/camera_avfoundation/Sources/camera_avfoundation_objc/FLTAssetWriter.m +++ /dev/null @@ -1,98 +0,0 @@ -// Copyright 2013 The Flutter Authors -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -#import "./include/camera_avfoundation/FLTAssetWriter.h" - -@interface FLTDefaultAssetWriter () -@property(nonatomic, strong) AVAssetWriter *writer; -@end - -@implementation FLTDefaultAssetWriter - -- (instancetype)initWithURL:(NSURL *)url fileType:(AVFileType)fileType error:(NSError **)error { - self = [super init]; - if (self) { - _writer = [[AVAssetWriter alloc] initWithURL:url fileType:fileType error:error]; - } - return self; -} - -- (BOOL)startWriting { - return [_writer startWriting]; -} - -- (void)finishWritingWithCompletionHandler:(void (^)(void))handler { - [_writer finishWritingWithCompletionHandler:handler]; -} - -- (AVAssetWriterStatus)status { - return _writer.status; -} - -- (NSError *)error { - return _writer.error; -} - -- (void)startSessionAtSourceTime:(CMTime)startTime { - return [_writer startSessionAtSourceTime:startTime]; -} - -- (void)addInput:(AVAssetWriterInput *)input { - return [_writer addInput:input]; -} - -@end - -@interface FLTDefaultAssetWriterInput () -@property(nonatomic, strong) AVAssetWriterInput *input; -@end - -@implementation FLTDefaultAssetWriterInput - -- (instancetype)initWithInput:(AVAssetWriterInput *)input { - self = [super init]; - if (self) { - _input = input; - } - return self; -} - -- (BOOL)appendSampleBuffer:(CMSampleBufferRef)sampleBuffer { - return [_input appendSampleBuffer:sampleBuffer]; -} - -- (BOOL)expectsMediaDataInRealTime { - return [_input expectsMediaDataInRealTime]; -} - -- (void)setExpectsMediaDataInRealTime:(BOOL)expectsMediaDataInRealTime { - _input.expectsMediaDataInRealTime = expectsMediaDataInRealTime; -} - -- (BOOL)readyForMoreMediaData { - return _input.readyForMoreMediaData; -} - -@end - -@interface FLTDefaultAssetWriterInputPixelBufferAdaptor () -@property(nonatomic, strong) AVAssetWriterInputPixelBufferAdaptor *adaptor; -@end - -@implementation FLTDefaultAssetWriterInputPixelBufferAdaptor - -- (instancetype)initWithAdaptor:(AVAssetWriterInputPixelBufferAdaptor *)adaptor { - self = [super init]; - if (self) { - _adaptor = adaptor; - } - return self; -} - -- (BOOL)appendPixelBuffer:(CVPixelBufferRef)pixelBuffer - withPresentationTime:(CMTime)presentationTime { - return [_adaptor appendPixelBuffer:pixelBuffer withPresentationTime:presentationTime]; -} - -@end diff --git a/packages/camera/camera_avfoundation/ios/camera_avfoundation/Sources/camera_avfoundation_objc/FLTCaptureConnection.m b/packages/camera/camera_avfoundation/ios/camera_avfoundation/Sources/camera_avfoundation_objc/FLTCaptureConnection.m deleted file mode 100644 index 3a3eef81caf..00000000000 --- a/packages/camera/camera_avfoundation/ios/camera_avfoundation/Sources/camera_avfoundation_objc/FLTCaptureConnection.m +++ /dev/null @@ -1,49 +0,0 @@ -// Copyright 2013 The Flutter Authors -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -#import "./include/camera_avfoundation/FLTCaptureConnection.h" - -@interface FLTDefaultCaptureConnection () -@property(nonatomic, strong) AVCaptureConnection *connection; -@end - -@implementation FLTDefaultCaptureConnection - -- (instancetype)initWithConnection:(AVCaptureConnection *)connection { - self = [super init]; - if (self) { - _connection = connection; - } - return self; -} - -- (BOOL)isVideoMirroringSupported { - return self.connection.isVideoMirroringSupported; -} - -- (BOOL)isVideoOrientationSupported { - return self.connection.isVideoOrientationSupported; -} - -- (void)setVideoMirrored:(BOOL)videoMirrored { - self.connection.videoMirrored = videoMirrored; -} - -- (BOOL)isVideoMirrored { - return self.connection.isVideoMirrored; -} - -- (void)setVideoOrientation:(AVCaptureVideoOrientation)videoOrientation { - self.connection.videoOrientation = videoOrientation; -} - -- (AVCaptureVideoOrientation)videoOrientation { - return self.connection.videoOrientation; -} - -- (NSArray *)inputPorts { - return self.connection.inputPorts; -} - -@end diff --git a/packages/camera/camera_avfoundation/ios/camera_avfoundation/Sources/camera_avfoundation_objc/FLTCaptureDeviceFormat.m b/packages/camera/camera_avfoundation/ios/camera_avfoundation/Sources/camera_avfoundation_objc/FLTCaptureDeviceFormat.m deleted file mode 100644 index 315b6880973..00000000000 --- a/packages/camera/camera_avfoundation/ios/camera_avfoundation/Sources/camera_avfoundation_objc/FLTCaptureDeviceFormat.m +++ /dev/null @@ -1,59 +0,0 @@ -// Copyright 2013 The Flutter Authors -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -#import "FLTCaptureDeviceFormat.h" - -@interface FLTDefaultFrameRateRange () -@property(nonatomic, strong) AVFrameRateRange *range; -@end - -@implementation FLTDefaultFrameRateRange - -- (instancetype)initWithRange:(AVFrameRateRange *)range { - self = [super init]; - if (self) { - _range = range; - } - return self; -} - -- (float)minFrameRate { - return _range.minFrameRate; -} - -- (float)maxFrameRate { - return _range.maxFrameRate; -} - -@end - -@interface FLTDefaultCaptureDeviceFormat () -@property(nonatomic, strong) AVCaptureDeviceFormat *format; -@end - -@implementation FLTDefaultCaptureDeviceFormat - -- (instancetype)initWithFormat:(AVCaptureDeviceFormat *)format { - self = [super init]; - if (self) { - _format = format; - } - return self; -} - -- (CMFormatDescriptionRef)formatDescription { - return _format.formatDescription; -} - -- (NSArray *> *)videoSupportedFrameRateRanges { - NSMutableArray> *ranges = - [NSMutableArray arrayWithCapacity:_format.videoSupportedFrameRateRanges.count]; - for (AVFrameRateRange *range in _format.videoSupportedFrameRateRanges) { - FLTDefaultFrameRateRange *wrapper = [[FLTDefaultFrameRateRange alloc] initWithRange:range]; - [ranges addObject:wrapper]; - } - return ranges; -} - -@end diff --git a/packages/camera/camera_avfoundation/ios/camera_avfoundation/Sources/camera_avfoundation_objc/include/camera_avfoundation/FLTAssetWriter.h b/packages/camera/camera_avfoundation/ios/camera_avfoundation/Sources/camera_avfoundation_objc/include/camera_avfoundation/FLTAssetWriter.h deleted file mode 100644 index b4d913964c8..00000000000 --- a/packages/camera/camera_avfoundation/ios/camera_avfoundation/Sources/camera_avfoundation_objc/include/camera_avfoundation/FLTAssetWriter.h +++ /dev/null @@ -1,75 +0,0 @@ -// Copyright 2013 The Flutter Authors -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -@import Foundation; -@import AVFoundation; - -NS_ASSUME_NONNULL_BEGIN - -/// A protocol that is a direct passthrough to `AVAssetWriter`. It is used to allow for mocking -/// `AVAssetWriter` in tests. -@protocol FLTAssetWriter - -@property(nonatomic, readonly) AVAssetWriterStatus status; -@property(readonly, nullable) NSError *error; - -- (BOOL)startWriting; -- (void)finishWritingWithCompletionHandler:(void (^)(void))handler; -- (void)startSessionAtSourceTime:(CMTime)startTime; -- (void)addInput:(AVAssetWriterInput *)input; - -@end - -/// A protocol that is a direct passthrough to `AVAssetWriterInput`. It is used to allow for mocking -/// `AVAssetWriterInput` in tests. -@protocol FLTAssetWriterInput - -/// The underlying `AVAssetWriterInput` instance. All method and property calls will be forwarded -/// to this instance. -@property(nonatomic, readonly) AVAssetWriterInput *input; - -@property(nonatomic, assign) BOOL expectsMediaDataInRealTime; -@property(nonatomic, readonly) BOOL readyForMoreMediaData; - -- (BOOL)appendSampleBuffer:(CMSampleBufferRef)sampleBuffer; - -@end - -/// A protocol that is a direct passthrough to `AVAssetWriterInputPixelBufferAdaptor`. It is used to -/// allow for mocking `AVAssetWriterInputPixelBufferAdaptor` in tests. -@protocol FLTAssetWriterInputPixelBufferAdaptor -- (BOOL)appendPixelBuffer:(CVPixelBufferRef)pixelBuffer - withPresentationTime:(CMTime)presentationTime; -@end - -/// A default implementation of `FLTAssetWriter` which creates an `AVAssetWriter` instance and -/// forwards calls to it. -@interface FLTDefaultAssetWriter : NSObject - -/// Creates an `AVAssetWriter` instance with the given URL and file type. It takes the same params -/// as the `AVAssetWriter`'s initializer. -- (instancetype)initWithURL:(NSURL *)url fileType:(AVFileType)fileType error:(NSError **)error; - -@end - -/// A default implementation of `FLTAssetWriterInput` which forwards calls to the -/// underlying `AVAssetWriterInput`. -@interface FLTDefaultAssetWriterInput : NSObject - -/// Creates a wrapper around the `input` which will forward calls to it. -- (instancetype)initWithInput:(AVAssetWriterInput *)input; - -@end - -/// A default implementation of `FLTAssetWriterInputPixelBufferAdaptor` which forwards calls to the -/// underlying `AVAssetWriterInputPixelBufferAdaptor`. -@interface FLTDefaultAssetWriterInputPixelBufferAdaptor - : NSObject - -/// Creates a wrapper around the `adaptor` which will forward calls to it. -- (instancetype)initWithAdaptor:(AVAssetWriterInputPixelBufferAdaptor *)adaptor; - -@end - -NS_ASSUME_NONNULL_END diff --git a/packages/camera/camera_avfoundation/ios/camera_avfoundation/Sources/camera_avfoundation_objc/include/camera_avfoundation/FLTCaptureConnection.h b/packages/camera/camera_avfoundation/ios/camera_avfoundation/Sources/camera_avfoundation_objc/include/camera_avfoundation/FLTCaptureConnection.h deleted file mode 100644 index 3fd5d1c084e..00000000000 --- a/packages/camera/camera_avfoundation/ios/camera_avfoundation/Sources/camera_avfoundation_objc/include/camera_avfoundation/FLTCaptureConnection.h +++ /dev/null @@ -1,40 +0,0 @@ -// Copyright 2013 The Flutter Authors -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -@import AVFoundation; - -NS_ASSUME_NONNULL_BEGIN - -/// A protocol which is a direct passthrough to `AVCaptureConnection`. It exists to allow replacing -/// `AVCaptureConnection` in tests. -@protocol FLTCaptureConnection - -/// Corresponds to the `videoMirrored` property of `AVCaptureConnection` -@property(nonatomic, getter=isVideoMirrored) BOOL videoMirrored; - -/// Corresponds to the `videoOrientation` property of `AVCaptureConnection` -@property(nonatomic) AVCaptureVideoOrientation videoOrientation; - -/// Corresponds to the `inputPorts` property of `AVCaptureConnection` -@property(nonatomic, readonly) NSArray *inputPorts; - -/// Corresponds to the `supportsVideoMirroring` property of `AVCaptureConnection` -@property(nonatomic, readonly, getter=isVideoMirroringSupported) BOOL supportsVideoMirroring; - -/// Corresponds to the `supportsVideoOrientation` property of `AVCaptureConnection` -@property(nonatomic, readonly, getter=isVideoOrientationSupported) BOOL supportsVideoOrientation; - -@end - -/// A default implementation of the `FLTCaptureConnection` protocol. It wraps an instance -/// of `AVCaptureConnection`. -@interface FLTDefaultCaptureConnection : NSObject - -/// Initializes a `FLTDefaultCaptureConnection` with the given `AVCaptureConnection`. -/// All methods and property calls are passed through to this connection. -- (instancetype)initWithConnection:(AVCaptureConnection *)connection; - -@end - -NS_ASSUME_NONNULL_END diff --git a/packages/camera/camera_avfoundation/ios/camera_avfoundation/Sources/camera_avfoundation_objc/include/camera_avfoundation/FLTCaptureDeviceFormat.h b/packages/camera/camera_avfoundation/ios/camera_avfoundation/Sources/camera_avfoundation_objc/include/camera_avfoundation/FLTCaptureDeviceFormat.h deleted file mode 100644 index 08a7d1bfedc..00000000000 --- a/packages/camera/camera_avfoundation/ios/camera_avfoundation/Sources/camera_avfoundation_objc/include/camera_avfoundation/FLTCaptureDeviceFormat.h +++ /dev/null @@ -1,51 +0,0 @@ -// Copyright 2013 The Flutter Authors -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -@import AVFoundation; -@import Foundation; - -NS_ASSUME_NONNULL_BEGIN - -/// A protocol which is a direct passthrough to `FLTFrameRateRange`. It exists to allow replacing -/// `AVFrameRateRange` in tests as it has no public initializer. -@protocol FLTFrameRateRange - -@property(readonly, nonatomic) float minFrameRate; -@property(readonly, nonatomic) float maxFrameRate; - -@end - -/// A protocol which is a direct passthrough to `AVCaptureDeviceFormat`. It exists to allow -/// replacing `AVCaptureDeviceFormat` in tests as it has no public initializer. -@protocol FLTCaptureDeviceFormat - -/// The underlying `AVCaptureDeviceFormat` instance that this object wraps. -@property(nonatomic, readonly) AVCaptureDeviceFormat *format; - -@property(nonatomic, readonly) CMFormatDescriptionRef formatDescription; -@property(nonatomic, readonly) - NSArray *> *videoSupportedFrameRateRanges; - -@end - -/// A default implementation of `FLTFrameRateRange` that wraps an `AVFrameRateRange` instance. -@interface FLTDefaultFrameRateRange : NSObject - -/// Initializes the object with an `AVFrameRateRange` instance. All method and property calls are -/// forwarded to this wrapped instance. -- (instancetype)initWithRange:(AVFrameRateRange *)range; - -@end - -/// A default implementation of `FLTCaptureDeviceFormat` that wraps an `AVCaptureDeviceFormat` -/// instance. -@interface FLTDefaultCaptureDeviceFormat : NSObject - -/// Initializes the object with an `AVCaptureDeviceFormat` instance. All method and property calls -/// are forwarded to this wrapped instance. -- (instancetype)initWithFormat:(AVCaptureDeviceFormat *)format; - -@end - -NS_ASSUME_NONNULL_END diff --git a/packages/camera/camera_avfoundation/pubspec.yaml b/packages/camera/camera_avfoundation/pubspec.yaml index dd391e086cb..136bd30317e 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.22+6 +version: 0.9.22+7 environment: sdk: ^3.9.0