mirror of
https://github.com/HaishinKit/HaishinKit.swift.git
synced 2026-05-07 20:12:28 +00:00
27 lines
487 B
Swift
27 lines
487 B
Swift
import CoreMedia
|
|
|
|
struct FrameTracker {
|
|
static let seconds = 1.0
|
|
|
|
private(set) var frameRate: Int = 0
|
|
private var count = 0
|
|
private var rotated: CMTime = .zero
|
|
|
|
init() {
|
|
}
|
|
|
|
mutating func update(_ time: CMTime) {
|
|
count += 1
|
|
if Self.seconds <= (time - rotated).seconds {
|
|
rotated = time
|
|
frameRate = count
|
|
count = 0
|
|
}
|
|
}
|
|
|
|
mutating func clear() {
|
|
count = 0
|
|
rotated = .zero
|
|
}
|
|
}
|