@@ -762,66 +762,67 @@ final class DefaultCamera: FLTCam, Camera {
762762 if let eventSink = imageStreamHandler? . eventSink,
763763 streamingPendingFramesCount < maxStreamingPendingFramesCount
764764 {
765- streamingPendingFramesCount += 1
766-
767- let pixelBuffer = CMSampleBufferGetImageBuffer ( sampleBuffer) !
768- // Must lock base address before accessing the pixel data
769- CVPixelBufferLockBaseAddress ( pixelBuffer, . readOnly)
770-
771- let imageWidth = CVPixelBufferGetWidth ( pixelBuffer)
772- let imageHeight = CVPixelBufferGetHeight ( pixelBuffer)
773-
774- var planes : [ [ String : Any ] ] = [ ]
775-
776- let isPlanar = CVPixelBufferIsPlanar ( pixelBuffer)
777- let planeCount = isPlanar ? CVPixelBufferGetPlaneCount ( pixelBuffer) : 1
778-
779- for i in 0 ..< planeCount {
780- let planeAddress : UnsafeMutableRawPointer ?
781- let bytesPerRow : Int
782- let height : Int
783- let width : Int
784-
785- if isPlanar {
786- planeAddress = CVPixelBufferGetBaseAddressOfPlane ( pixelBuffer, i)
787- bytesPerRow = CVPixelBufferGetBytesPerRowOfPlane ( pixelBuffer, i)
788- height = CVPixelBufferGetHeightOfPlane ( pixelBuffer, i)
789- width = CVPixelBufferGetWidthOfPlane ( pixelBuffer, i)
790- } else {
791- planeAddress = CVPixelBufferGetBaseAddress ( pixelBuffer)
792- bytesPerRow = CVPixelBufferGetBytesPerRow ( pixelBuffer)
793- height = CVPixelBufferGetHeight ( pixelBuffer)
794- width = CVPixelBufferGetWidth ( pixelBuffer)
765+ if let pixelBuffer = CMSampleBufferGetImageBuffer ( sampleBuffer) {
766+ streamingPendingFramesCount += 1
767+
768+ // Must lock base address before accessing the pixel data
769+ CVPixelBufferLockBaseAddress ( pixelBuffer, . readOnly)
770+
771+ let imageWidth = CVPixelBufferGetWidth ( pixelBuffer)
772+ let imageHeight = CVPixelBufferGetHeight ( pixelBuffer)
773+
774+ var planes : [ [ String : Any ] ] = [ ]
775+
776+ let isPlanar = CVPixelBufferIsPlanar ( pixelBuffer)
777+ let planeCount = isPlanar ? CVPixelBufferGetPlaneCount ( pixelBuffer) : 1
778+
779+ for i in 0 ..< planeCount {
780+ let planeAddress : UnsafeMutableRawPointer ?
781+ let bytesPerRow : Int
782+ let height : Int
783+ let width : Int
784+
785+ if isPlanar {
786+ planeAddress = CVPixelBufferGetBaseAddressOfPlane ( pixelBuffer, i)
787+ bytesPerRow = CVPixelBufferGetBytesPerRowOfPlane ( pixelBuffer, i)
788+ height = CVPixelBufferGetHeightOfPlane ( pixelBuffer, i)
789+ width = CVPixelBufferGetWidthOfPlane ( pixelBuffer, i)
790+ } else {
791+ planeAddress = CVPixelBufferGetBaseAddress ( pixelBuffer)
792+ bytesPerRow = CVPixelBufferGetBytesPerRow ( pixelBuffer)
793+ height = CVPixelBufferGetHeight ( pixelBuffer)
794+ width = CVPixelBufferGetWidth ( pixelBuffer)
795+ }
796+
797+ let length = bytesPerRow * height
798+ let bytes = Data ( bytes: planeAddress!, count: length)
799+
800+ let planeBuffer : [ String : Any ] = [
801+ " bytesPerRow " : bytesPerRow,
802+ " width " : width,
803+ " height " : height,
804+ " bytes " : FlutterStandardTypedData ( bytes: bytes) ,
805+ ]
806+ planes. append ( planeBuffer)
795807 }
796808
797- let length = bytesPerRow * height
798- let bytes = Data ( bytes: planeAddress!, count: length)
799-
800- let planeBuffer : [ String : Any ] = [
801- " bytesPerRow " : bytesPerRow,
802- " width " : width,
803- " height " : height,
804- " bytes " : FlutterStandardTypedData ( bytes: bytes) ,
809+ // Lock the base address before accessing pixel data, and unlock it afterwards.
810+ // Done accessing the `pixelBuffer` at this point.
811+ CVPixelBufferUnlockBaseAddress ( pixelBuffer, . readOnly)
812+
813+ let imageBuffer : [ String : Any ] = [
814+ " width " : imageWidth,
815+ " height " : imageHeight,
816+ " format " : videoFormat,
817+ " planes " : planes,
818+ " lensAperture " : Double ( captureDevice. lensAperture ( ) ) ,
819+ " sensorExposureTime " : Int ( captureDevice. exposureDuration ( ) . seconds * 1_000_000_000 ) ,
820+ " sensorSensitivity " : Double ( captureDevice. iso ( ) ) ,
805821 ]
806- planes. append ( planeBuffer)
807- }
808822
809- // Lock the base address before accessing pixel data, and unlock it afterwards.
810- // Done accessing the `pixelBuffer` at this point.
811- CVPixelBufferUnlockBaseAddress ( pixelBuffer, . readOnly)
812-
813- let imageBuffer : [ String : Any ] = [
814- " width " : imageWidth,
815- " height " : imageHeight,
816- " format " : videoFormat,
817- " planes " : planes,
818- " lensAperture " : Double ( captureDevice. lensAperture ( ) ) ,
819- " sensorExposureTime " : Int ( captureDevice. exposureDuration ( ) . seconds * 1_000_000_000 ) ,
820- " sensorSensitivity " : Double ( captureDevice. iso ( ) ) ,
821- ]
822-
823- DispatchQueue . main. async {
824- eventSink ( imageBuffer)
823+ DispatchQueue . main. async {
824+ eventSink ( imageBuffer)
825+ }
825826 }
826827 }
827828 }
0 commit comments