Improve performance and add statistics for MPV

This commit is contained in:
Arkadiusz Fal
2022-06-17 12:27:01 +02:00
parent 81b8cbd5f1
commit 15cdde17a6
7 changed files with 86 additions and 33 deletions

View File

@@ -82,15 +82,13 @@ extension Defaults.Keys {
static let visibleSections = Key<Set<VisibleSection>>("visibleSections", default: [.favorites, .subscriptions, .trending, .playlists])
#if os(macOS)
static let enableBetaChannel = Key<Bool>("enableBetaChannel", default: false)
#endif
#if os(iOS)
static let honorSystemOrientationLock = Key<Bool>("honorSystemOrientationLock", default: true)
static let enterFullscreenInLandscape = Key<Bool>("enterFullscreenInLandscape", default: UIDevice.current.userInterfaceIdiom == .phone)
static let lockOrientationInFullScreen = Key<Bool>("lockOrientationInFullScreen", default: false)
#endif
static let showMPVPlaybackStats = Key<Bool>("showMPVPlaybackStats", default: false)
}
enum ResolutionSetting: String, CaseIterable, Defaults.Serializable {

View File

@@ -1,3 +1,4 @@
import Defaults
import Foundation
import SDWebImageSwiftUI
import SwiftUI
@@ -22,6 +23,8 @@ struct PlayerControls: View {
@FocusState private var focusedField: Field?
#endif
@Default(.showMPVPlaybackStats) private var showMPVPlaybackStats
init(player: PlayerModel, thumbnails: ThumbnailsModel) {
self.player = player
self.thumbnails = thumbnails
@@ -49,6 +52,10 @@ struct PlayerControls: View {
Spacer()
Group {
if player.activeBackend == .mpv, showMPVPlaybackStats {
mpvPlaybackStats
}
timeline
.offset(y: 10)
.zIndex(1)
@@ -103,6 +110,30 @@ struct PlayerControls: View {
}
}
var mpvPlaybackStats: some View {
HStack {
Group {
Text("hw decoder: \(player.mpvBackend.hwDecoder)")
Text("dropped: \(player.mpvBackend.frameDropCount)")
Text("output fps: \(player.mpvBackend.outputFps)")
}
.padding(4)
#if os(macOS)
.background(VisualEffectBlur(material: .hudWindow))
#elseif os(iOS)
.background(VisualEffectBlur(blurStyle: .systemThinMaterial))
#else
.background(.thinMaterial)
#endif
.mask(RoundedRectangle(cornerRadius: 3))
Spacer()
}
#if !os(tvOS)
.font(.system(size: 9))
#endif
}
var timeline: some View {
TimelineView(duration: durationBinding, current: currentTimeBinding, cornerRadius: 0)
}
@@ -164,14 +195,11 @@ struct PlayerControls: View {
var buttonsBar: some View {
HStack {
#if !os(tvOS)
#if os(iOS)
hidePlayerButton
#endif
fullscreenButton
#if os(iOS)
pipButton
.padding(.leading, 5)
#endif
Spacer()
@@ -257,8 +285,7 @@ struct PlayerControls: View {
}
private var backendButton: some View {
let label = "\(player.activeBackend.label)\(player.activeBackend == .mpv ? " - \(player.mpvBackend.frameDropCount)" : "")"
return button(label, width: 120) {
button(player.activeBackend.label, width: 100) {
player.saveTime {
player.changeActiveBackend(from: player.activeBackend, to: player.activeBackend.next())
model.resetTimer()

View File

@@ -28,6 +28,8 @@ struct PlayerSettings: View {
@Default(.enableReturnYouTubeDislike) private var enableReturnYouTubeDislike
@Default(.showMPVPlaybackStats) private var showMPVPlaybackStats
#if os(iOS)
private var idiom: UIUserInterfaceIdiom {
UIDevice.current.userInterfaceIdiom
@@ -103,6 +105,10 @@ struct PlayerSettings: View {
lockOrientationInFullScreenToggle
}
#endif
Section(header: SettingsHeader(text: "Debugging")) {
showMPVPlaybackStatsToggle
}
}
}
@@ -232,11 +238,17 @@ struct PlayerSettings: View {
Toggle("Close PiP and open player when application enters foreground", isOn: $closePiPAndOpenPlayerOnEnteringForeground)
}
#endif
private var showMPVPlaybackStatsToggle: some View {
Toggle("Show MPV playback statistics", isOn: $showMPVPlaybackStats)
}
}
struct PlaybackSettings_Previews: PreviewProvider {
static var previews: some View {
PlayerSettings()
.injectFixtureEnvironmentObjects()
VStack(alignment: .leading) {
PlayerSettings()
}
.injectFixtureEnvironmentObjects()
}
}

View File

@@ -171,7 +171,7 @@ struct SettingsView: View {
case .browsing:
return 350
case .player:
return 450
return 500
case .history:
return 480
case .sponsorBlock: