1
0
mirror of https://github.com/yattee/yattee.git synced 2025-01-10 19:40:33 +05:30

Improve MPV performance

This commit is contained in:
Arkadiusz Fal 2022-06-16 02:03:15 +02:00
parent 524fe7c087
commit 1cfe4b089f
4 changed files with 33 additions and 30 deletions

View File

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

View File

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

View File

@ -7,6 +7,7 @@ final class MPVOGLView: GLKView {
private var defaultFBO: GLint? private var defaultFBO: GLint?
var mpvGL: UnsafeMutableRawPointer? var mpvGL: UnsafeMutableRawPointer?
var queue = DispatchQueue(label: "stream.yattee.opengl", qos: .userInteractive)
var needsDrawing = true var needsDrawing = true
override init(frame: CGRect) { override init(frame: CGRect) {
@ -18,14 +19,9 @@ final class MPVOGLView: GLKView {
logger.info("frame size: \(frame.width) x \(frame.height)") logger.info("frame size: \(frame.width) x \(frame.height)")
super.init(frame: frame, context: context) super.init(frame: frame, context: context)
contentMode = .redraw
EAGLContext.setCurrent(context) EAGLContext.setCurrent(context)
drawableColorFormat = .RGBA8888
drawableDepthFormat = .formatNone
drawableStencilFormat = .formatNone
defaultFBO = -1 defaultFBO = -1
isOpaque = false isOpaque = false
@ -38,28 +34,30 @@ final class MPVOGLView: GLKView {
} }
override func draw(_: CGRect) { override func draw(_: CGRect) {
guard needsDrawing, let mpvGL = mpvGL else {
return
}
glGetIntegerv(UInt32(GL_FRAMEBUFFER_BINDING), &defaultFBO!) glGetIntegerv(UInt32(GL_FRAMEBUFFER_BINDING), &defaultFBO!)
var dims: [GLint] = [0, 0, 0, 0] var dims: [GLint] = [0, 0, 0, 0]
glGetIntegerv(GLenum(GL_VIEWPORT), &dims) glGetIntegerv(GLenum(GL_VIEWPORT), &dims)
if mpvGL != nil { var data = mpv_opengl_fbo(
var data = mpv_opengl_fbo( fbo: Int32(defaultFBO!),
fbo: Int32(defaultFBO!), w: Int32(dims[2]),
w: Int32(dims[2]), h: Int32(dims[3]),
h: Int32(dims[3]), internal_format: 0
internal_format: 0 )
) var flip: CInt = 1
var flip: CInt = 1 withUnsafeMutablePointer(to: &flip) { flip in
withUnsafeMutablePointer(to: &flip) { flip in withUnsafeMutablePointer(to: &data) { data in
withUnsafeMutablePointer(to: &data) { data in var params = [
var params = [ mpv_render_param(type: MPV_RENDER_PARAM_OPENGL_FBO, data: data),
mpv_render_param(type: MPV_RENDER_PARAM_OPENGL_FBO, data: data), mpv_render_param(type: MPV_RENDER_PARAM_FLIP_Y, data: flip),
mpv_render_param(type: MPV_RENDER_PARAM_FLIP_Y, data: flip), mpv_render_param()
mpv_render_param() ]
] mpv_render_context_render(OpaquePointer(mpvGL), &params)
mpv_render_context_render(OpaquePointer(mpvGL), &params)
}
} }
} }
} }

View File

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