mirror of
https://github.com/yattee/yattee.git
synced 2025-01-11 07:17:11 +00:00
Add dropped frames counter
This commit is contained in:
parent
89ce589950
commit
0158048648
@ -6,6 +6,8 @@ import Logging
|
|||||||
import SwiftUI
|
import SwiftUI
|
||||||
|
|
||||||
final class MPVBackend: PlayerBackend {
|
final class MPVBackend: PlayerBackend {
|
||||||
|
static var clientUpdatesInterval = 1.0
|
||||||
|
|
||||||
private var logger = Logger(label: "mpv-backend")
|
private var logger = Logger(label: "mpv-backend")
|
||||||
|
|
||||||
var model: PlayerModel!
|
var model: PlayerModel!
|
||||||
@ -66,11 +68,15 @@ final class MPVBackend: PlayerBackend {
|
|||||||
client?.tracksCount ?? -1
|
client?.tracksCount ?? -1
|
||||||
}
|
}
|
||||||
|
|
||||||
|
var frameDropCount: Int {
|
||||||
|
client?.frameDropCount ?? 0
|
||||||
|
}
|
||||||
|
|
||||||
init(model: PlayerModel, controls: PlayerControlsModel? = nil) {
|
init(model: PlayerModel, controls: PlayerControlsModel? = nil) {
|
||||||
self.model = model
|
self.model = model
|
||||||
self.controls = controls
|
self.controls = controls
|
||||||
|
|
||||||
clientTimer = .init(timeInterval: 1)
|
clientTimer = .init(timeInterval: Self.clientUpdatesInterval)
|
||||||
clientTimer.eventHandler = getClientUpdates
|
clientTimer.eventHandler = getClientUpdates
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -272,15 +278,15 @@ final class MPVBackend: PlayerBackend {
|
|||||||
func closePiP(wasPlaying _: Bool) {}
|
func closePiP(wasPlaying _: Bool) {}
|
||||||
|
|
||||||
func updateControls() {
|
func updateControls() {
|
||||||
|
guard model.presentingPlayer else {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
DispatchQueue.main.async { [weak self] in
|
DispatchQueue.main.async { [weak self] in
|
||||||
guard let self = self else {
|
guard let self = self else {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
guard self.controls.player.presentingPlayer else {
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
self.logger.info("updating controls")
|
self.logger.info("updating controls")
|
||||||
self.controls.currentTime = self.currentTime ?? .zero
|
self.controls.currentTime = self.currentTime ?? .zero
|
||||||
self.controls.duration = self.playerItemDuration ?? .zero
|
self.controls.duration = self.playerItemDuration ?? .zero
|
||||||
|
@ -141,6 +141,10 @@ final class MPVClient: ObservableObject {
|
|||||||
CMTime.secondsInDefaultTimescale(mpv.isNil ? -1 : getDouble("time-pos"))
|
CMTime.secondsInDefaultTimescale(mpv.isNil ? -1 : getDouble("time-pos"))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
var frameDropCount: Int {
|
||||||
|
mpv.isNil ? 0 : getInt("frame-drop-count")
|
||||||
|
}
|
||||||
|
|
||||||
var duration: CMTime {
|
var duration: CMTime {
|
||||||
CMTime.secondsInDefaultTimescale(mpv.isNil ? -1 : getDouble("duration"))
|
CMTime.secondsInDefaultTimescale(mpv.isNil ? -1 : getDouble("duration"))
|
||||||
}
|
}
|
||||||
@ -320,11 +324,11 @@ final class MPVClient: ObservableObject {
|
|||||||
private func glUpdate(_ ctx: UnsafeMutableRawPointer?) {
|
private func glUpdate(_ ctx: UnsafeMutableRawPointer?) {
|
||||||
let glView = unsafeBitCast(ctx, to: MPVOGLView.self)
|
let glView = unsafeBitCast(ctx, to: MPVOGLView.self)
|
||||||
|
|
||||||
guard glView.needsDrawing else {
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
glView.queue.async {
|
glView.queue.async {
|
||||||
|
guard glView.needsDrawing else {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
glView.display()
|
glView.display()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -11,8 +11,6 @@ final class PlayerControlsModel: ObservableObject {
|
|||||||
@Published var timer: Timer?
|
@Published var timer: Timer?
|
||||||
@Published var playingFullscreen = false
|
@Published var playingFullscreen = false
|
||||||
|
|
||||||
private var throttle = Throttle(interval: 1)
|
|
||||||
|
|
||||||
var player: PlayerModel!
|
var player: PlayerModel!
|
||||||
|
|
||||||
var playbackTime: String {
|
var playbackTime: String {
|
||||||
@ -62,6 +60,7 @@ final class PlayerControlsModel: ObservableObject {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
player.backend.updateControls()
|
||||||
withAnimation(PlayerControls.animation) {
|
withAnimation(PlayerControls.animation) {
|
||||||
presentingControls = true
|
presentingControls = true
|
||||||
}
|
}
|
||||||
@ -147,8 +146,6 @@ final class PlayerControlsModel: ObservableObject {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func update() {
|
func update() {
|
||||||
throttle.execute { [weak self] in
|
player?.backend.updateControls()
|
||||||
self?.player?.backend.updateControls()
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -554,6 +554,10 @@ final class PlayerModel: ObservableObject {
|
|||||||
Windows.player.toggleFullScreen()
|
Windows.player.toggleFullScreen()
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#if os(iOS)
|
||||||
|
setNeedsDrawing(false)
|
||||||
|
#endif
|
||||||
|
|
||||||
controls.playingFullscreen = !isFullScreen
|
controls.playingFullscreen = !isFullScreen
|
||||||
|
|
||||||
#if os(iOS)
|
#if os(iOS)
|
||||||
@ -565,6 +569,10 @@ final class PlayerModel: ObservableObject {
|
|||||||
} else {
|
} else {
|
||||||
Orientation.lockOrientation(.allButUpsideDown, andRotateTo: .portrait)
|
Orientation.lockOrientation(.allButUpsideDown, andRotateTo: .portrait)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
DispatchQueue.main.asyncAfter(deadline: .now() + 0.2) { [weak self] in
|
||||||
|
self?.setNeedsDrawing(true)
|
||||||
|
}
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -256,8 +256,9 @@ struct PlayerControls: View {
|
|||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
@ViewBuilder private var backendButton: some View {
|
private var backendButton: some View {
|
||||||
button(player.activeBackend.label, width: 100) {
|
let label = "\(player.activeBackend.label)\(player.activeBackend == .mpv ? " - \(player.mpvBackend.frameDropCount)" : "")"
|
||||||
|
return button(label, width: 120) {
|
||||||
player.saveTime {
|
player.saveTime {
|
||||||
player.changeActiveBackend(from: player.activeBackend, to: player.activeBackend.next())
|
player.changeActiveBackend(from: player.activeBackend, to: player.activeBackend.next())
|
||||||
model.resetTimer()
|
model.resetTimer()
|
||||||
|
Loading…
Reference in New Issue
Block a user