         }
     }
     var startTime:CMTime?
+    var totalFrames = 0
+    var skippedFrames = 0
     
     let context = VSContext(device: MTLCreateSystemDefaultDevice()!)
     var runtime:VSRuntime?

    // For rendering
    lazy var commandQueue:MTLCommandQueue = self.context.device.makeCommandQueue()
    lazy var renderer:VSRenderer = VSRenderer(device:self.context.device, pixelFormat:self.context.pixelFormat)
    
    override func viewDidLoad() {
        super.viewDidLoad()


extension SampleViewController3 : VSCaptureSessionDelegate {
    func didCaptureOutput(session:VSCaptureSession, texture textureIn:MTLTexture, sampleBuffer:CMSampleBuffer, presentationTime:CMTime) {
        if self.recording {
            totalFrames += 1
        }
        if self.context.textureOut != nil {
            // The writer is behind. Skip this frame.
            if self.recording {
                skippedFrames += 1
            }
            return
        }
        self.context.set(texture: textureIn, sampleBuffer: sampleBuffer)
