iOS Ignoring enqueueSampleBuffer because status is failed

允我心安 提交于 2019-12-24 01:53:41

问题


When I restart app from here: https://github.com/zweigraf/face-landmarking-ios picture from camera doesn't appear and printing error: "Ignoring enqueueSampleBuffer because status is failed".

The problem is probably in captureOutput from SessionHandler.swift


回答1:


I find a solution! Thanks to Why does AVSampleBufferDisplayLayer fail with Operation Interrupted (-11847)?

If you had similar problem you need to set AVSampleBufferDisplayLayer each time app entering foreground. Like this:

//AppDelegate.swift
func applicationWillEnterForeground(_ application: UIApplication) {
    // Called as part of the transition from the background to the active state; here you can undo many of the changes made on entering the background.

    viewcontroller?.setLayer()
}


//ViewController.swift
func setLayer() {
    sessionHandler.layer = AVSampleBufferDisplayLayer()
    sessionHandler.layer.frame = preview.bounds
    sessionHandler.layer.videoGravity = AVLayerVideoGravityResizeAspectFill
    preview.layer.addSublayer(sessionHandler.layer)
}

and don't forget to remove sublayer:

func applicationDidEnterBackground(_ application: UIApplication) {
    // Use this method to release shared resources, save user data, invalidate timers, and store enough application state information to restore your application to its current state in case it is terminated later.
    // If your application supports background execution, this method is called instead of applicationWillTerminate: when the user quits.

    viewcontroller?.sessionHandler.layer.removeFromSuperlayer()
}


来源:https://stackoverflow.com/questions/43687169/ios-ignoring-enqueuesamplebuffer-because-status-is-failed

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!