Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


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

* Migrates `FLTCameraDeviceDiscovering` and `FLTDeviceOrientationProviding` classes to Swift.

## 0.9.22+3

* Updates examples to use the new RadioGroup API instead of deprecated Radio parameters.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 `FLTCameraDeviceDiscovering` protocol which allows injecting a custom
/// Mock implementation of `FLTCameraDeviceDiscoverer` protocol which allows injecting a custom
/// implementation for session discovery.
final class MockCameraDeviceDiscoverer: NSObject, FLTCameraDeviceDiscovering {
final class MockCameraDeviceDiscoverer: NSObject, CameraDeviceDiscoverer {
var discoverySessionStub:
(
(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,17 @@
// 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

final class MockDeviceOrientationProvider: NSObject, FLTDeviceOrientationProviding {
final class MockDeviceOrientationProvider: NSObject, DeviceOrientationProvider {
var orientationStub: (() -> UIDeviceOrientation)?

func orientation() -> UIDeviceOrientation {
var orientation: UIDeviceOrientation {
return orientationStub?() ?? .unknown
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ class CameraConfiguration {
var assetWriterFactory: AssetWriterFactory
var inputPixelBufferAdaptorFactory: InputPixelBufferAdaptorFactory
var videoDimensionsConverter: VideoDimensionsConverter
var deviceOrientationProvider: FLTDeviceOrientationProviding
var deviceOrientationProvider: DeviceOrientationProvider
let initialCameraName: String
var orientation: UIDeviceOrientation

Expand All @@ -67,7 +67,7 @@ class CameraConfiguration {
self.captureDeviceInputFactory = captureDeviceInputFactory
self.initialCameraName = initialCameraName
self.orientation = UIDevice.current.orientation
self.deviceOrientationProvider = FLTDefaultDeviceOrientationProvider()
self.deviceOrientationProvider = DefaultDeviceOrientationProvider()

self.videoDimensionsConverter = { format in
return CMVideoFormatDescriptionGetDimensions(format.formatDescription)
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
// 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 Objective-C part of the implementation when SwiftPM is used.
#if canImport(camera_avfoundation_objc)
import camera_avfoundation_objc
#endif

/// A protocol which abstracts the discovery of camera devices.
/// It is a thin wrapper around `AVCaptureDiscoverySession` and it exists to allow mocking in tests.
protocol CameraDeviceDiscoverer {
func discoverySession(
withDeviceTypes deviceTypes: [AVCaptureDevice.DeviceType],
mediaType: AVMediaType,
position: AVCaptureDevice.Position
) -> [FLTCaptureDevice]
}

/// The default implementation of the `CameraDeviceDiscoverer` protocol.
/// It wraps a call to `AVCaptureDeviceDiscoverySession`.
class DefaultCameraDeviceDiscoverer: NSObject, CameraDeviceDiscoverer {
func discoverySession(
withDeviceTypes deviceTypes: [AVCaptureDevice.DeviceType],
mediaType: AVMediaType,
position: AVCaptureDevice.Position
) -> [FLTCaptureDevice] {
let discoverySession = AVCaptureDevice.DiscoverySession(
deviceTypes: deviceTypes,
mediaType: mediaType,
position: position
)

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

return deviceControllers
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ public final class CameraPlugin: NSObject, FlutterPlugin {
private let registry: FlutterTextureRegistry
private let messenger: FlutterBinaryMessenger
private let globalEventAPI: FCPCameraGlobalEventApi
private let deviceDiscoverer: FLTCameraDeviceDiscovering
private let deviceDiscoverer: CameraDeviceDiscoverer
private let permissionManager: FLTCameraPermissionManager
private let captureDeviceFactory: VideoCaptureDeviceFactory
private let captureSessionFactory: CaptureSessionFactory
Expand All @@ -31,7 +31,7 @@ public final class CameraPlugin: NSObject, FlutterPlugin {
registry: registrar.textures(),
messenger: registrar.messenger(),
globalAPI: FCPCameraGlobalEventApi(binaryMessenger: registrar.messenger()),
deviceDiscoverer: FLTDefaultCameraDeviceDiscoverer(),
deviceDiscoverer: DefaultCameraDeviceDiscoverer(),
permissionManager: FLTCameraPermissionManager(
permissionService: FLTDefaultPermissionService()),
deviceFactory: { name in
Expand All @@ -50,7 +50,7 @@ public final class CameraPlugin: NSObject, FlutterPlugin {
registry: FlutterTextureRegistry,
messenger: FlutterBinaryMessenger,
globalAPI: FCPCameraGlobalEventApi,
deviceDiscoverer: FLTCameraDeviceDiscovering,
deviceDiscoverer: CameraDeviceDiscoverer,
permissionManager: FLTCameraPermissionManager,
deviceFactory: @escaping VideoCaptureDeviceFactory,
captureSessionFactory: @escaping CaptureSessionFactory,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ final class DefaultCamera: NSObject, Camera {
/// Allows for alternate implementations in tests.
private let videoDimensionsConverter: VideoDimensionsConverter

private let deviceOrientationProvider: FLTDeviceOrientationProviding
private let deviceOrientationProvider: DeviceOrientationProvider
private let motionManager = CMMotionManager()

private(set) var captureDevice: FLTCaptureDevice
Expand Down Expand Up @@ -858,7 +858,7 @@ final class DefaultCamera: NSObject, Camera {
return
}

let orientation = deviceOrientationProvider.orientation()
let orientation = deviceOrientationProvider.orientation
try? captureDevice.lockForConfiguration()
// A nil point resets to the center.
captureDevice.setFocusPointOfInterest(
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
// 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 UIKit

/// A protocol which provides the current device orientation.
/// It exists to allow replacing UIDevice in tests.
protocol DeviceOrientationProvider {
/// Returns the physical orientation of the device.
var orientation: UIDeviceOrientation { get }
}

/// A default implementation of DeviceOrientationProvider which uses orientation
/// of the current device from UIDevice.
@objc public class DefaultDeviceOrientationProvider: NSObject, DeviceOrientationProvider {
@objc public var orientation: UIDeviceOrientation {
return UIDevice.current.orientation
}
}

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#import "FLTCameraDeviceDiscovering.h"
#import "FLTCameraPermissionManager.h"
#import "FLTCaptureDevice.h"
#import "QueueUtils.h"
Expand Down
2 changes: 1 addition & 1 deletion packages/camera/camera_avfoundation/pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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+3
version: 0.9.22+4

environment:
sdk: ^3.9.0
Expand Down