avfoundation - Camera frames dropped after changing camera iOS -
my method didoutputsamplebuffer
called until switch cameras using function:
func switchcameras() { capturesession.beginconfiguration() capturesession.sessionpreset = avcapturesessionpresetmedium var error : nserror? = nil input in capturesession.inputs { capturesession.removeinput(input as! avcaptureinput) } if currentcamera == "back" { currentcamera = "front" if capturesession.canaddinput(avcapturedeviceinput(device: frontcamera, error: &error)) { capturesession.addinput(avcapturedeviceinput(device: frontcamera, error: &error)) } else { print(error) } } else { currentcamera = "back" if capturesession.canaddinput(avcapturedeviceinput(device: backcamera, error: &error)) { capturesession.addinput(avcapturedeviceinput(device: backcamera, error: &error)) } else { } } print("chagned") capturesession.commitconfiguration() }
after switching, frames dropped in method, can't take picture. after 5 seconds, frames come back.
func captureoutput(captureoutput: avcaptureoutput!, didoutputsamplebuffer samplebuffer: cmsamplebuffer!, fromconnection connection: avcaptureconnection!) { connection.videoorientation = avcapturevideoorientation.portrait if capture == true { self.capture = false var newbuffer = samplebuffer self.capturepicture(newbuffer) } }
if need more code let me know.
i solved changing output queue dispatch_queue_serial
.
let output = avcapturevideodataoutput() output.videosettings = [kcvpixelbufferpixelformattypekey nsstring:kcvpixelformattype_32bgra] let queue = dispatch_queue_create("cameraqueue", dispatch_queue_serial) output.setsamplebufferdelegate(self, queue: dispatch_get_main_queue())
Comments
Post a Comment