Thanks @craig, I am using the livePreview in the SDK and this is the code taken from the sample app that cause 80-100% cpu usage. Do you happen to have sample code of iteration only through the current chunk that you can share with the community?
repeat {
var soi: Int?
var eoi: Int?
var i = 0
dataBuffer.withUnsafeBytes { (bytes: UnsafePointer<UInt8>) -> 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))
completionHandler(frameData, nil, nil)
dataBuffer = dataBuffer.subdata(in: (end + 1)..<dataBuffer.count)
} while dataBuffer.count >= 4
I have also tried the following, but it was still yielding 80-100% cpu usage
var soi: Int?
var eoi: Int?
var i = 0
dataBuffer.withUnsafeBytes { bytes in
while i < self.dataBuffer.count - 1 {
if self.JPEG_SOI[0] == bytes[i] && self.JPEG_SOI[1] == bytes[i + 1] {
soi = i
i += 1
break
}
i += 1
}
while i < self.dataBuffer.count - 1 {
if self.JPEG_EOI[0] == bytes[i] && self.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))
completionHandler(frameData, nil, nil)
dataBuffer = dataBuffer.subdata(in: (end + 1)..<dataBuffer.count)