Skip to content

Commit

Permalink
Added alert in case videoCamera isn't available in FilterDisplayViewC…
Browse files Browse the repository at this point in the history
…ontroller
  • Loading branch information
rounak committed Apr 17, 2016
1 parent 437b4bc commit 3e8b340
Showing 1 changed file with 22 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -9,48 +9,51 @@ class FilterDisplayViewController: UIViewController, UISplitViewControllerDelega
@IBOutlet var filterSlider: UISlider?
@IBOutlet var filterView: RenderView?

let videoCamera:Camera
let videoCamera:Camera?
var blendImage:PictureInput?

required init(coder aDecoder: NSCoder)
{
do {
videoCamera = try Camera(sessionPreset:AVCaptureSessionPreset640x480, location:.BackFacing)
videoCamera.runBenchmark = true
videoCamera!.runBenchmark = true
} catch {
fatalError("Couldn't initialize camera with error: \(error)")
videoCamera = nil
print("Couldn't initialize camera with error: \(error)")
}

super.init(coder: aDecoder)!
}

var filterOperation: FilterOperationInterface? {
didSet {
self.configureView()
}
}

var filterOperation: FilterOperationInterface?

func configureView() {
if videoCamera == nil {
let errorAlertController = UIAlertController(title: NSLocalizedString("Error", comment: "Error"), message: "Couldn't initialize camera", preferredStyle: .Alert)
errorAlertController.addAction(UIAlertAction(title: NSLocalizedString("OK", comment: "OK"), style: .Default, handler: nil))
self.presentViewController(errorAlertController, animated: true, completion: nil)
return
}
if let currentFilterConfiguration = self.filterOperation {
self.title = currentFilterConfiguration.titleName

// Configure the filter chain, ending with the view
if let view = self.filterView {
switch currentFilterConfiguration.filterOperationType {
case .SingleInput:
videoCamera.addTarget(currentFilterConfiguration.filter)
videoCamera!.addTarget(currentFilterConfiguration.filter)
currentFilterConfiguration.filter.addTarget(view)
case .Blend:
videoCamera.addTarget(currentFilterConfiguration.filter)
videoCamera!.addTarget(currentFilterConfiguration.filter)
self.blendImage = PictureInput(imageName:blendImageName)
self.blendImage?.addTarget(currentFilterConfiguration.filter)
self.blendImage?.processImage()
currentFilterConfiguration.filter.addTarget(view)
case let .Custom(filterSetupFunction:setupFunction):
currentFilterConfiguration.configureCustomFilter(setupFunction(camera:videoCamera, filter:currentFilterConfiguration.filter, outputView:view))
currentFilterConfiguration.configureCustomFilter(setupFunction(camera:videoCamera!, filter:currentFilterConfiguration.filter, outputView:view))
}

videoCamera.startCapture()
videoCamera!.startCapture()
}

// Hide or display the slider, based on whether the filter needs it
Expand Down Expand Up @@ -86,9 +89,12 @@ class FilterDisplayViewController: UIViewController, UISplitViewControllerDelega
}

override func viewWillDisappear(animated: Bool) {
videoCamera.stopCapture()
videoCamera.removeAllTargets()
blendImage?.removeAllTargets()
if let videoCamera = videoCamera {
videoCamera.stopCapture()
videoCamera.removeAllTargets()
blendImage?.removeAllTargets()
}

super.viewWillDisappear(animated)
}

Expand Down

0 comments on commit 3e8b340

Please sign in to comment.