Skip to content

Commit

Permalink
fix: Fix divison by zero in Performance Sample collector (#416)
Browse files Browse the repository at this point in the history
* fix: Fix divison by zero in Performance Sample collector

* use `isEmpty`
  • Loading branch information
mrousavy committed Sep 8, 2021
1 parent 4726639 commit f9dbb69
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 0 deletions.
1 change: 1 addition & 0 deletions ios/CameraView+RecordVideo.swift
Original file line number Diff line number Diff line change
Expand Up @@ -236,6 +236,7 @@ extension CameraView: AVCaptureVideoDataOutputSampleBufferDelegate, AVCaptureAud
private func evaluateNewPerformanceSamples() {
lastFrameProcessorPerformanceEvaluation = DispatchTime.now()
guard let videoDevice = videoDeviceInput?.device else { return }
guard frameProcessorPerformanceDataCollector.hasEnoughData else { return }

let maxFrameProcessorFps = Double(videoDevice.activeVideoMinFrameDuration.timescale) * Double(videoDevice.activeVideoMinFrameDuration.value)
let averageFps = 1.0 / frameProcessorPerformanceDataCollector.averageExecutionTimeSeconds
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,10 @@ class FrameProcessorPerformanceDataCollector {
private var counter = 0
private var lastEvaluation = -1

var hasEnoughData: Bool {
return !performanceSamples.isEmpty
}

var averageExecutionTimeSeconds: Double {
let sum = performanceSamples.reduce(0, +)
let average = sum / Double(performanceSamples.count)
Expand Down

0 comments on commit f9dbb69

Please sign in to comment.