Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Patch 3.0.1 #74

Merged
merged 7 commits into from
Dec 16, 2024
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
2 changes: 1 addition & 1 deletion MijickCamera.podspec
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ Pod::Spec.new do |s|
Camera made simple. The ultimate camera library that significantly reduces implementation time and effort. Written with and for SwiftUI.
DESC

s.version = '3.0.0'
s.version = '3.0.1'
s.ios.deployment_target = '14.0'
s.swift_version = '6.0'

Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,6 @@ private extension CameraManagerNotificationCenter {
// MARK: Reset
extension CameraManagerNotificationCenter {
func reset() {
NotificationCenter.default.removeObserver(self, name: .AVCaptureSessionWasInterrupted, object: parent.captureSession)
NotificationCenter.default.removeObserver(self, name: .AVCaptureSessionWasInterrupted, object: parent?.captureSession)
}
}
19 changes: 13 additions & 6 deletions Sources/Internal/Manager/CameraManager.swift
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ import AVKit
private(set) var captureSession: any CaptureSession
private(set) var frontCameraInput: (any CaptureDeviceInput)?
private(set) var backCameraInput: (any CaptureDeviceInput)?
private(set) var audioInput: (any CaptureDeviceInput)?

// MARK: Output
private(set) var photoOutput: CameraManagerPhotoOutput = .init()
Expand All @@ -37,11 +36,10 @@ import AVKit
private(set) var notificationCenterManager: CameraManagerNotificationCenter = .init()

// MARK: Initializer
init<CS: CaptureSession, CDI: CaptureDeviceInput>(captureSession: CS, fontCameraInput: CDI?, backCameraInput: CDI?, audioInput: CDI?) {
init<CS: CaptureSession, CDI: CaptureDeviceInput>(captureSession: CS, captureDeviceInputType: CDI.Type) {
self.captureSession = captureSession
self.frontCameraInput = fontCameraInput
self.backCameraInput = backCameraInput
self.audioInput = audioInput
self.frontCameraInput = CDI.get(mediaType: .video, position: .front)
self.backCameraInput = CDI.get(mediaType: .video, position: .back)
}
}

Expand Down Expand Up @@ -80,7 +78,7 @@ private extension CameraManager {
}
func setupDeviceInputs() throws(MCameraError) {
try captureSession.add(input: getCameraInput())
if attributes.isAudioSourceAvailable { try captureSession.add(input: audioInput) }
if let audioInput = getAudioInput() { try captureSession.add(input: audioInput) }
}
func setupDeviceOutput() throws(MCameraError) {
try photoOutput.setup(parent: self)
Expand All @@ -102,6 +100,15 @@ private extension CameraManager {
}}
}
private extension CameraManager {
func getAudioInput() -> (any CaptureDeviceInput)? {
guard attributes.isAudioSourceAvailable,
let deviceInput = frontCameraInput ?? backCameraInput
else { return nil }

let captureDeviceInputType = type(of: deviceInput)
let audioInput = captureDeviceInputType.get(mediaType: .audio, position: .unspecified)
return audioInput
}
nonisolated func startCaptureSession() async throws {
await captureSession.startRunning()
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,9 @@ class MockCaptureSession: NSObject, CaptureSession { required override init() {}


extension MockCaptureSession {
func startRunning() {
func startRunning() { Task { @MainActor in
_isRunning = true
}
}}
func stopRunningAndReturnNewInstance() -> any CaptureSession {
_isRunning = false
return MockCaptureSession()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,14 @@ import SwiftUI
@MainActor class CameraFocusIndicatorView {
var image: UIImage = .init(resource: .mijickIconCrosshair)
var tintColor: UIColor = .init(resource: .mijickBackgroundYellow)
var size: CGFloat = 92
var size: CGFloat = 96
}

// MARK: Create
extension CameraFocusIndicatorView {
func create(at touchPoint: CGPoint) -> UIImageView {
let focusIndicator = UIImageView(image: image)
focusIndicator.contentMode = .scaleAspectFit
focusIndicator.tintColor = tintColor
focusIndicator.frame.size = .init(width: size, height: size)
focusIndicator.frame.origin.x = touchPoint.x - size / 2
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,7 @@ import AVKit
public extension MCamera {
init() { self.init(manager: .init(
captureSession: AVCaptureSession(),
fontCameraInput: AVCaptureDeviceInput.get(mediaType: .video, position: .front),
backCameraInput: AVCaptureDeviceInput.get(mediaType: .video, position: .back),
audioInput: AVCaptureDeviceInput.get(mediaType: .audio, position: .unspecified)
captureDeviceInputType: AVCaptureDeviceInput.self
))}
}

Expand Down
6 changes: 2 additions & 4 deletions Tests/Tests+CameraManager.swift
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,7 @@ import SwiftUI
@MainActor @Suite("Camera Manager Tests") struct CameraManagerTests {
var cameraManager: CameraManager = .init(
captureSession: MockCaptureSession(),
fontCameraInput: MockDeviceInput.get(mediaType: .video, position: .front),
backCameraInput: MockDeviceInput.get(mediaType: .video, position: .back),
audioInput: MockDeviceInput.get(mediaType: .audio, position: .unspecified)
captureDeviceInputType: MockDeviceInput.self
)
}

Expand Down Expand Up @@ -385,7 +383,7 @@ private extension CameraManagerTests {

cameraManager.initialize(in: cameraView)
try await cameraManager.setup()
await Task.sleep(seconds: 2)
await Task.sleep(seconds: 10)
}
}
private extension CameraManagerTests {
Expand Down