我一直在努力围绕着这个http直播流。我只是不了解它,是的,我已经阅读了很多苹果文档并观看了WWDC视频,但是仍然非常困惑。
我想使用Ricoh Theta V camera实施实时360度预览以捕获照片并将其保存到云中。我已经使用Open Spherical Camera API完成了360度显示图像的实现。但是我的Live preview太慢了,当我移动相机时,它更新帧的时间太晚了。
下面是我的LivePreviewClass代码-
let completionHandler: ((Data?, URLResponse?, Error?) -> Void)
var dataBuffer = Data()
init(completionHandler: @escaping ((Data?, URLResponse?, Error?) -> Void)) {
self.completionHandler = completionHandler
}
@objc func urlSession(_ session: URLSession, dataTask: URLSessionDataTask, didReceive data: Data) {
dataBuffer.append(data)
repeat {
var soi: NSInteger?
var eoi: NSInteger?
var i : NSInteger = 0
dataBuffer.withUnsafeBytes { (bytes: UnsafeRawBufferPointer) -> Void in
while i < dataBuffer.count - 1 {
if JPEG_SOI[0] == bytes[i] && JPEG_SOI[1] == bytes[i + 1] {
soi = i
i += 1
break
}
i += 1
}
while i < dataBuffer.count - 1 {
if JPEG_EOI[0] == bytes[i] && JPEG_EOI[1] == bytes[i + 1] {
i += 1
eoi = i
break
}
i += 1
}
}
guard let start = soi, let end = eoi else {
return
}
let frameData = dataBuffer.subdata(in: start..<(end + 1))
self.completionHandler(frameData, nil, nil)
dataBuffer = dataBuffer.subdata(in: (end + 1)..<dataBuffer.count)
} while dataBuffer.count >= 4
}
@objc func urlSession(_ session: URLSession, task: URLSessionTask, didCompleteWithError error: Error?) {
session.invalidateAndCancel()
self.completionHandler(nil, nil, error)
}