Improve MPV performance

This commit is contained in:
Arkadiusz Fal 2022-06-16 02:03:15 +02:00
parent 0a797db129
commit e91c7fb2d5
4 changed files with 33 additions and 30 deletions

View File

@ -273,9 +273,17 @@ final class MPVBackend: PlayerBackend {
func updateControls() {
DispatchQueue.main.async { [weak self] in
self?.logger.info("updating controls")
self?.controls.currentTime = self?.currentTime ?? .zero
self?.controls.duration = self?.playerItemDuration ?? .zero
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
}
}
@ -296,8 +304,6 @@ final class MPVBackend: PlayerBackend {
private var handleSegmentsThrottle = Throttle(interval: 1)
private func getClientUpdates() {
self.logger.info("getting client updates")
currentTime = client?.currentTime
playerItemDuration = client?.duration

View File

@ -324,8 +324,8 @@ final class MPVClient: ObservableObject {
return
}
DispatchQueue.main.async {
glView.setNeedsDisplay()
glView.queue.async {
glView.display()
}
}

View File

@ -7,6 +7,7 @@ final class MPVOGLView: GLKView {
private var defaultFBO: GLint?
var mpvGL: UnsafeMutableRawPointer?
var queue = DispatchQueue(label: "stream.yattee.opengl", qos: .userInteractive)
var needsDrawing = true
override init(frame: CGRect) {
@ -18,14 +19,9 @@ final class MPVOGLView: GLKView {
logger.info("frame size: \(frame.width) x \(frame.height)")
super.init(frame: frame, context: context)
contentMode = .redraw
EAGLContext.setCurrent(context)
drawableColorFormat = .RGBA8888
drawableDepthFormat = .formatNone
drawableStencilFormat = .formatNone
defaultFBO = -1
isOpaque = false
@ -38,12 +34,15 @@ final class MPVOGLView: GLKView {
}
override func draw(_: CGRect) {
guard needsDrawing, let mpvGL = mpvGL else {
return
}
glGetIntegerv(UInt32(GL_FRAMEBUFFER_BINDING), &defaultFBO!)
var dims: [GLint] = [0, 0, 0, 0]
glGetIntegerv(GLenum(GL_VIEWPORT), &dims)
if mpvGL != nil {
var data = mpv_opengl_fbo(
fbo: Int32(defaultFBO!),
w: Int32(dims[2]),
@ -62,7 +61,6 @@ final class MPVOGLView: GLKView {
}
}
}
}
required init?(coder aDecoder: NSCoder) {
super.init(coder: aDecoder)

View File

@ -156,7 +156,6 @@ struct VideoPlayerView: View {
return // swiftlint:disable:this implicit_return
}
player.backend.setNeedsDrawing(false)
let drag = value.translation.height
guard drag > 0 else {