 
     var previewLayer: AVCaptureVideoPreviewLayer?
     var frameCount = 0
+    var running: Bool = false
 
     var metalDevice: MTLDevice?
     var metalLib: MTLLibrary?

            print("Frame #\(self.frameCount)")
        }*/
        self.frameCount++
        if self.frameCount % 100 != 1 {
            return
        }


        // Prepare output
        let out = AVCaptureVideoDataOutput()
        out.videoSettings = [kCVPixelBufferPixelFormatTypeKey as String: Int(kCVPixelFormatType_32BGRA)]
        out.alwaysDiscardsLateVideoFrames = true
        let queue = dispatch_queue_create("input frames queue", DISPATCH_QUEUE_SERIAL)
        out.setSampleBufferDelegate(self, queue:queue)
        if !session.canAddOutput(out) {
