fix: Fix divison by zero in Performance Sample collector (#416)

* fix: Fix divison by zero in Performance Sample collector

* use `isEmpty`
This commit is contained in:
Marc Rousavy 2021-09-08 17:18:12 +02:00 committed by GitHub
parent 47266399cc
commit f9dbb6921c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 5 additions and 0 deletions

View File

@ -236,6 +236,7 @@ extension CameraView: AVCaptureVideoDataOutputSampleBufferDelegate, AVCaptureAud
private func evaluateNewPerformanceSamples() { private func evaluateNewPerformanceSamples() {
lastFrameProcessorPerformanceEvaluation = DispatchTime.now() lastFrameProcessorPerformanceEvaluation = DispatchTime.now()
guard let videoDevice = videoDeviceInput?.device else { return } guard let videoDevice = videoDeviceInput?.device else { return }
guard frameProcessorPerformanceDataCollector.hasEnoughData else { return }
let maxFrameProcessorFps = Double(videoDevice.activeVideoMinFrameDuration.timescale) * Double(videoDevice.activeVideoMinFrameDuration.value) let maxFrameProcessorFps = Double(videoDevice.activeVideoMinFrameDuration.timescale) * Double(videoDevice.activeVideoMinFrameDuration.value)
let averageFps = 1.0 / frameProcessorPerformanceDataCollector.averageExecutionTimeSeconds let averageFps = 1.0 / frameProcessorPerformanceDataCollector.averageExecutionTimeSeconds

View File

@ -28,6 +28,10 @@ class FrameProcessorPerformanceDataCollector {
private var counter = 0 private var counter = 0
private var lastEvaluation = -1 private var lastEvaluation = -1
var hasEnoughData: Bool {
return !performanceSamples.isEmpty
}
var averageExecutionTimeSeconds: Double { var averageExecutionTimeSeconds: Double {
let sum = performanceSamples.reduce(0, +) let sum = performanceSamples.reduce(0, +)
let average = sum / Double(performanceSamples.count) let average = sum / Double(performanceSamples.count)