From b88adca781294ab9fefcbf4dcf08b91592142462 Mon Sep 17 00:00:00 2001 From: Arkadiusz Fal Date: Fri, 17 Jun 2022 13:43:11 +0200 Subject: [PATCH] Add buffering and cache length to stats --- Model/Player/Backends/MPVBackend.swift | 8 ++++++++ Model/Player/Backends/MPVClient.swift | 8 ++++++++ Shared/Player/Controls/PlayerControls.swift | 4 +++- 3 files changed, 19 insertions(+), 1 deletion(-) diff --git a/Model/Player/Backends/MPVBackend.swift b/Model/Player/Backends/MPVBackend.swift index 37fcc291..29a4843b 100644 --- a/Model/Player/Backends/MPVBackend.swift +++ b/Model/Player/Backends/MPVBackend.swift @@ -80,6 +80,14 @@ final class MPVBackend: PlayerBackend { client?.hwDecoder ?? "unknown" } + var bufferingState: Double { + client?.bufferingState ?? 0 + } + + var cacheDuration: Double { + client?.cacheDuration ?? 0 + } + init(model: PlayerModel, controls: PlayerControlsModel? = nil) { self.model = model self.controls = controls diff --git a/Model/Player/Backends/MPVClient.swift b/Model/Player/Backends/MPVClient.swift index bbcf2bd5..16788a29 100644 --- a/Model/Player/Backends/MPVClient.swift +++ b/Model/Player/Backends/MPVClient.swift @@ -155,6 +155,14 @@ final class MPVClient: ObservableObject { mpv.isNil ? "unknown" : (getString("hwdec-current") ?? "unknown") } + var bufferingState: Double { + mpv.isNil ? 0.0 : getDouble("cache-buffering-state") + } + + var cacheDuration: Double { + mpv.isNil ? 0.0 : getDouble("demuxer-cache-duration") + } + var duration: CMTime { CMTime.secondsInDefaultTimescale(mpv.isNil ? -1 : getDouble("duration")) } diff --git a/Shared/Player/Controls/PlayerControls.swift b/Shared/Player/Controls/PlayerControls.swift index b12e270b..084243a0 100644 --- a/Shared/Player/Controls/PlayerControls.swift +++ b/Shared/Player/Controls/PlayerControls.swift @@ -115,7 +115,9 @@ struct PlayerControls: View { Group { Text("hw decoder: \(player.mpvBackend.hwDecoder)") Text("dropped: \(player.mpvBackend.frameDropCount)") - Text("output fps: \(player.mpvBackend.outputFps)") + Text("video: \(String(format: "%.2ffps", player.mpvBackend.outputFps))") + Text("buffering: \(String(format: "%.0f%%", player.mpvBackend.bufferingState))") + Text("cache: \(String(format: "%.2fs", player.mpvBackend.cacheDuration))") } .padding(4) #if os(macOS)