mirror of
https://github.com/yattee/yattee.git
synced 2025-08-09 20:24:06 +00:00
Add dropped frames counter
This commit is contained in:
@@ -6,6 +6,8 @@ import Logging
|
||||
import SwiftUI
|
||||
|
||||
final class MPVBackend: PlayerBackend {
|
||||
static var clientUpdatesInterval = 1.0
|
||||
|
||||
private var logger = Logger(label: "mpv-backend")
|
||||
|
||||
var model: PlayerModel!
|
||||
@@ -66,11 +68,15 @@ final class MPVBackend: PlayerBackend {
|
||||
client?.tracksCount ?? -1
|
||||
}
|
||||
|
||||
var frameDropCount: Int {
|
||||
client?.frameDropCount ?? 0
|
||||
}
|
||||
|
||||
init(model: PlayerModel, controls: PlayerControlsModel? = nil) {
|
||||
self.model = model
|
||||
self.controls = controls
|
||||
|
||||
clientTimer = .init(timeInterval: 1)
|
||||
clientTimer = .init(timeInterval: Self.clientUpdatesInterval)
|
||||
clientTimer.eventHandler = getClientUpdates
|
||||
}
|
||||
|
||||
@@ -272,15 +278,15 @@ final class MPVBackend: PlayerBackend {
|
||||
func closePiP(wasPlaying _: Bool) {}
|
||||
|
||||
func updateControls() {
|
||||
guard model.presentingPlayer else {
|
||||
return
|
||||
}
|
||||
|
||||
DispatchQueue.main.async { [weak self] in
|
||||
guard let self = self else {
|
||||
return
|
||||
}
|
||||
|
||||
guard self.controls.player.presentingPlayer else {
|
||||
return
|
||||
}
|
||||
|
||||
self.logger.info("updating controls")
|
||||
self.controls.currentTime = self.currentTime ?? .zero
|
||||
self.controls.duration = self.playerItemDuration ?? .zero
|
||||
|
@@ -141,6 +141,10 @@ final class MPVClient: ObservableObject {
|
||||
CMTime.secondsInDefaultTimescale(mpv.isNil ? -1 : getDouble("time-pos"))
|
||||
}
|
||||
|
||||
var frameDropCount: Int {
|
||||
mpv.isNil ? 0 : getInt("frame-drop-count")
|
||||
}
|
||||
|
||||
var duration: CMTime {
|
||||
CMTime.secondsInDefaultTimescale(mpv.isNil ? -1 : getDouble("duration"))
|
||||
}
|
||||
@@ -320,11 +324,11 @@ final class MPVClient: ObservableObject {
|
||||
private func glUpdate(_ ctx: UnsafeMutableRawPointer?) {
|
||||
let glView = unsafeBitCast(ctx, to: MPVOGLView.self)
|
||||
|
||||
guard glView.needsDrawing else {
|
||||
return
|
||||
}
|
||||
|
||||
glView.queue.async {
|
||||
guard glView.needsDrawing else {
|
||||
return
|
||||
}
|
||||
|
||||
glView.display()
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user