mirror of https://github.com/mpv-player/mpv
cocoa-cb: use a separate mpv_handle for cocoa-cb to simplify shutdown
This commit is contained in:
parent
7e07e1a087
commit
2a4bf7ca22
|
@ -95,12 +95,6 @@ class AppHub: NSObject {
|
|||
|
||||
switch event.pointee.event_id {
|
||||
case MPV_EVENT_SHUTDOWN:
|
||||
#if HAVE_MACOS_COCOA_CB
|
||||
if let app = NSApp as? Application, app.cocoaCB?.isShuttingDown ?? false {
|
||||
mpv = nil;
|
||||
return
|
||||
}
|
||||
#endif
|
||||
mpv_destroy(mpv)
|
||||
mpv = nil
|
||||
default: break
|
||||
|
|
|
@ -175,7 +175,8 @@ static const char mac_icon[] =
|
|||
{
|
||||
#if HAVE_MACOS_COCOA_CB
|
||||
if (!_cocoa_cb) {
|
||||
[NSApp setCocoaCB:[[CocoaCB alloc] init:ctx]];
|
||||
mpv_handle *mpv = mpv_create_client(ctx, "cocoacb");
|
||||
[NSApp setCocoaCB:[[CocoaCB alloc] init:mpv]];
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
|
|
@ -26,7 +26,7 @@ class LibmpvHelper {
|
|||
var mpvHandle: OpaquePointer?
|
||||
var mpvRenderContext: OpaquePointer?
|
||||
var fbo: GLint = 1
|
||||
let deinitLock = NSLock()
|
||||
let uninitLock = NSLock()
|
||||
|
||||
init(_ mpv: OpaquePointer, _ mpLog: OpaquePointer?) {
|
||||
mpvHandle = mpv
|
||||
|
@ -93,18 +93,18 @@ class LibmpvHelper {
|
|||
}
|
||||
|
||||
func isRenderUpdateFrame() -> Bool {
|
||||
deinitLock.lock()
|
||||
uninitLock.lock()
|
||||
if mpvRenderContext == nil {
|
||||
deinitLock.unlock()
|
||||
uninitLock.unlock()
|
||||
return false
|
||||
}
|
||||
let flags: UInt64 = mpv_render_context_update(mpvRenderContext)
|
||||
deinitLock.unlock()
|
||||
uninitLock.unlock()
|
||||
return flags & UInt64(MPV_RENDER_UPDATE_FRAME.rawValue) > 0
|
||||
}
|
||||
|
||||
func drawRender(_ surface: NSSize, _ depth: GLint, _ ctx: CGLContextObj, skip: Bool = false) {
|
||||
deinitLock.lock()
|
||||
uninitLock.lock()
|
||||
if mpvRenderContext != nil {
|
||||
var i: GLint = 0
|
||||
let flip: CInt = 1
|
||||
|
@ -137,7 +137,7 @@ class LibmpvHelper {
|
|||
|
||||
if !skip { CGLFlushDrawable(ctx) }
|
||||
|
||||
deinitLock.unlock()
|
||||
uninitLock.unlock()
|
||||
}
|
||||
|
||||
func setRenderICCProfile(_ profile: NSColorSpace) {
|
||||
|
@ -168,19 +168,14 @@ class LibmpvHelper {
|
|||
}
|
||||
}
|
||||
|
||||
func deinitRender() {
|
||||
func uninit() {
|
||||
mpv_render_context_set_update_callback(mpvRenderContext, nil, nil)
|
||||
mp_render_context_set_control_callback(mpvRenderContext, nil, nil)
|
||||
deinitLock.lock()
|
||||
uninitLock.lock()
|
||||
mpv_render_context_free(mpvRenderContext)
|
||||
mpvRenderContext = nil
|
||||
deinitLock.unlock()
|
||||
}
|
||||
|
||||
func deinitMPV(_ destroy: Bool = false) {
|
||||
if destroy {
|
||||
mpv_destroy(mpvHandle)
|
||||
}
|
||||
mpv_destroy(mpvHandle)
|
||||
mpvHandle = nil
|
||||
uninitLock.unlock()
|
||||
}
|
||||
}
|
||||
|
|
|
@ -21,7 +21,7 @@ class CocoaCB: Common {
|
|||
var libmpv: LibmpvHelper
|
||||
var layer: GLLayer?
|
||||
|
||||
@objc var isShuttingDown: Bool = false
|
||||
var isShuttingDown: Bool = false
|
||||
|
||||
enum State {
|
||||
case uninitialized
|
||||
|
@ -199,7 +199,7 @@ class CocoaCB: Common {
|
|||
return super.control(vo, events: events, request: request, data: data)
|
||||
}
|
||||
|
||||
func shutdown(_ destroy: Bool = false) {
|
||||
func shutdown() {
|
||||
isShuttingDown = window?.isAnimating ?? false ||
|
||||
window?.isInFullscreen ?? false && option.vo.native_fs
|
||||
if window?.isInFullscreen ?? false && !(window?.isAnimating ?? false) {
|
||||
|
@ -211,14 +211,13 @@ class CocoaCB: Common {
|
|||
uninitCommon()
|
||||
|
||||
layer?.lockCglContext()
|
||||
libmpv.deinitRender()
|
||||
libmpv.uninit()
|
||||
layer?.unlockCglContext()
|
||||
libmpv.deinitMPV(destroy)
|
||||
}
|
||||
|
||||
func checkShutdown() {
|
||||
if isShuttingDown {
|
||||
shutdown(true)
|
||||
shutdown()
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue