Commit 081bd66b by Daniel Dahan

update CaptureSession internals

parent a53a6fe5
...@@ -49,16 +49,6 @@ public class CaptureSession : NSObject { ...@@ -49,16 +49,6 @@ public class CaptureSession : NSObject {
private lazy var videoQueue: dispatch_queue_t = dispatch_queue_create("io.materialkit.CaptureSession", nil) private lazy var videoQueue: dispatch_queue_t = dispatch_queue_create("io.materialkit.CaptureSession", nil)
// //
// :name: videoDevice
//
private lazy var videoDevice: AVCaptureDevice = AVCaptureDevice.defaultDeviceWithMediaType(AVMediaTypeVideo)
//
// :name: audioDevice
//
private lazy var audioDevice: AVCaptureDevice = AVCaptureDevice.defaultDeviceWithMediaType(AVMediaTypeAudio)
//
// :name: activeVideoInput // :name: activeVideoInput
// //
private var activeVideoInput: AVCaptureDeviceInput? private var activeVideoInput: AVCaptureDeviceInput?
...@@ -134,22 +124,31 @@ public class CaptureSession : NSObject { ...@@ -134,22 +124,31 @@ public class CaptureSession : NSObject {
} }
/** /**
:name: cameraSupportsTapToFocus
*/
public var cameraSupportsTapToFocus: Bool {
return true
}
/**
:name: focusMode :name: focusMode
*/ */
public var focusMode: AVCaptureFocusMode { public var focusMode: AVCaptureFocusMode {
get { get {
return videoDevice.focusMode return activeCamera!.focusMode
} }
set(value) { set(value) {
var error: NSError? var error: NSError?
if isFocusModeSupported(focusMode) { if isFocusModeSupported(focusMode) {
do { do {
try videoDevice.lockForConfiguration() let device: AVCaptureDevice = activeCamera!
videoDevice.focusMode = focusMode try device.lockForConfiguration()
videoDevice.unlockForConfiguration() device.focusMode = focusMode
device.unlockForConfiguration()
} catch let e as NSError { } catch let e as NSError {
error = e error = e
} }
} else {
error = NSError(domain: "[MaterialKit Error: Unsupported focusMode.]", code: 0, userInfo: nil) error = NSError(domain: "[MaterialKit Error: Unsupported focusMode.]", code: 0, userInfo: nil)
} }
if let e: NSError = error { if let e: NSError = error {
...@@ -223,14 +222,14 @@ public class CaptureSession : NSObject { ...@@ -223,14 +222,14 @@ public class CaptureSession : NSObject {
:name: isFocusModeSupported :name: isFocusModeSupported
*/ */
public func isFocusModeSupported(focusMode: AVCaptureFocusMode) -> Bool { public func isFocusModeSupported(focusMode: AVCaptureFocusMode) -> Bool {
return videoDevice.isFocusModeSupported(focusMode) return activeVideoInput!.device.isFocusModeSupported(focusMode)
} }
/** /**
:name: isExposureModeSupported :name: isExposureModeSupported
*/ */
public func isExposureModeSupported(exposureMode: AVCaptureExposureMode) -> Bool { public func isExposureModeSupported(exposureMode: AVCaptureExposureMode) -> Bool {
return videoDevice.isExposureModeSupported(exposureMode) return activeVideoInput!.device.isExposureModeSupported(exposureMode)
} }
// //
...@@ -248,7 +247,7 @@ public class CaptureSession : NSObject { ...@@ -248,7 +247,7 @@ public class CaptureSession : NSObject {
// //
private func prepareVideoInput() { private func prepareVideoInput() {
do { do {
activeVideoInput = try AVCaptureDeviceInput(device: videoDevice) activeVideoInput = try AVCaptureDeviceInput(device: AVCaptureDevice.defaultDeviceWithMediaType(AVMediaTypeVideo))
if session.canAddInput(activeVideoInput) { if session.canAddInput(activeVideoInput) {
session.addInput(activeVideoInput) session.addInput(activeVideoInput)
} }
...@@ -262,7 +261,7 @@ public class CaptureSession : NSObject { ...@@ -262,7 +261,7 @@ public class CaptureSession : NSObject {
// //
private func prepareAudioInput() { private func prepareAudioInput() {
do { do {
activeAudioInput = try AVCaptureDeviceInput(device: audioDevice) activeAudioInput = try AVCaptureDeviceInput(device: AVCaptureDevice.defaultDeviceWithMediaType(AVMediaTypeAudio))
if session.canAddInput(activeAudioInput) { if session.canAddInput(activeAudioInput) {
session.addInput(activeAudioInput) session.addInput(activeAudioInput)
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment