             self.executeClosureAsyncOnSessionQueueIfNecessary {
                 if self.captureMode == .arKit {
                     self.configureSession()
+                    self.setupContextIfNecessary()
                 } else {
                     self.configureSession()
                     self.configureSessionDevices()

    internal var _videoCustomContextRenderingEnabled: Bool = false
    internal var _sessionVideoCustomContextImageBuffer: CVPixelBuffer?
    internal var _ciContext: CIContext?

    // AVFoundation
    

        }
    }
    
    private func setupContextIfNecessary() {
        if self._ciContext == nil {
            let options : [String : AnyObject] = [kCIContextWorkingColorSpace : CGColorSpaceCreateDeviceRGB(),
                                                  kCIContextUseSoftwareRenderer : NSNumber(booleanLiteral: false)]
            if let device = MTLCreateSystemDefaultDevice() {
                self._ciContext = CIContext(mtlDevice: device, options: options)
            } else if let eaglContext = EAGLContext(api: .openGLES2) {
                self._ciContext = CIContext(eaglContext: eaglContext, options: options)
            }
        }
    }
    
    private func setupPixelBufferPoolIfNecessary(_ pixelBuffer: CVPixelBuffer) {
        guard self._pixelBufferPool == nil else {
            return
        }
        
        let formatType = CVPixelBufferGetPixelFormatType(pixelBuffer)
        let width = CVPixelBufferGetWidth(pixelBuffer)
        let height = CVPixelBufferGetHeight(pixelBuffer)
        
        let pixelBufferPoolMinimumCount = 3
        let poolAttributes: [String:AnyObject] = [String(kCVPixelBufferPoolMinimumBufferCountKey): NSNumber(integerLiteral: pixelBufferPoolMinimumCount)]
        
        let pixelBufferAttributes: [String:AnyObject] = [String(kCVPixelBufferPixelFormatTypeKey) : NSNumber(integerLiteral: Int(formatType)),
                                                         String(kCVPixelBufferWidthKey) : NSNumber(value: width),
                                                         String(kCVPixelBufferHeightKey) : NSNumber(value: height),
                                                         String(kCVPixelBufferMetalCompatibilityKey) : NSNumber(booleanLiteral: true),
                                                         String(kCVPixelBufferIOSurfacePropertiesKey) : [:] as AnyObject ]
        
        var pixelBufferPool: CVPixelBufferPool? = nil
        let result = CVPixelBufferPoolCreate(kCFAllocatorDefault, poolAttributes as CFDictionary, pixelBufferAttributes as CFDictionary, &pixelBufferPool)
        if result == kCVReturnSuccess {
            self._pixelBufferPool = pixelBufferPool
        }
    }
    
}

// MARK: - AVCaptureVideoDataOutputSampleBufferDelegate, AVCaptureAudioDataOutputSampleBufferDelegate
