mirror of
https://github.com/yattee/yattee.git
synced 2024-12-23 22:13:41 +00:00
Improve MPV performance
This commit is contained in:
parent
0a797db129
commit
e91c7fb2d5
@ -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
|
||||
|
||||
|
@ -324,8 +324,8 @@ final class MPVClient: ObservableObject {
|
||||
return
|
||||
}
|
||||
|
||||
DispatchQueue.main.async {
|
||||
glView.setNeedsDisplay()
|
||||
glView.queue.async {
|
||||
glView.display()
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -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,28 +34,30 @@ 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]),
|
||||
h: Int32(dims[3]),
|
||||
internal_format: 0
|
||||
)
|
||||
var flip: CInt = 1
|
||||
withUnsafeMutablePointer(to: &flip) { flip in
|
||||
withUnsafeMutablePointer(to: &data) { data in
|
||||
var params = [
|
||||
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()
|
||||
]
|
||||
mpv_render_context_render(OpaquePointer(mpvGL), ¶ms)
|
||||
}
|
||||
var data = mpv_opengl_fbo(
|
||||
fbo: Int32(defaultFBO!),
|
||||
w: Int32(dims[2]),
|
||||
h: Int32(dims[3]),
|
||||
internal_format: 0
|
||||
)
|
||||
var flip: CInt = 1
|
||||
withUnsafeMutablePointer(to: &flip) { flip in
|
||||
withUnsafeMutablePointer(to: &data) { data in
|
||||
var params = [
|
||||
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()
|
||||
]
|
||||
mpv_render_context_render(OpaquePointer(mpvGL), ¶ms)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -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 {
|
||||
|
Loading…
Reference in New Issue
Block a user