From dcb580035786fdebe58c5146941bc9700cab842b Mon Sep 17 00:00:00 2001 From: wm4 Date: Wed, 19 Apr 2017 12:35:42 +0200 Subject: [PATCH] osx: fix deadlock on exit with libmpv on OSX There is explicit code to handle the libmpv case, but it expects that a dispatch queue is running. This is not necessarily the case. E.g. edit the simple.c mpv example not to do any playback and to destroy the mpv handle immediately. It will freeze on exit, because nothing will release the mpv_handle. I'm not sure how this should be fixed, so disable it for now in library mode. --- osdep/macosx_events.m | 19 +++++++++++-------- 1 file changed, 11 insertions(+), 8 deletions(-) diff --git a/osdep/macosx_events.m b/osdep/macosx_events.m index fc7118de4c..dbdef2f255 100644 --- a/osdep/macosx_events.m +++ b/osdep/macosx_events.m @@ -53,7 +53,7 @@ - (BOOL)handleMediaKey:(NSEvent *)event; - (NSEvent *)handleKey:(NSEvent *)event; -- (void)setMpvHandle:(struct mpv_handle *)ctx; +- (BOOL)setMpvHandle:(struct mpv_handle *)ctx; - (void)readEvents; - (void)startAppleRemote; - (void)stopAppleRemote; @@ -217,11 +217,12 @@ static void wakeup(void *context) void cocoa_set_mpv_handle(struct mpv_handle *ctx) { - [[EventsResponder sharedInstance] setMpvHandle:ctx]; - mpv_observe_property(ctx, 0, "duration", MPV_FORMAT_DOUBLE); - mpv_observe_property(ctx, 0, "time-pos", MPV_FORMAT_DOUBLE); - mpv_observe_property(ctx, 0, "pause", MPV_FORMAT_FLAG); - mpv_set_wakeup_callback(ctx, wakeup, NULL); + if ([[EventsResponder sharedInstance] setMpvHandle:ctx]) { + mpv_observe_property(ctx, 0, "duration", MPV_FORMAT_DOUBLE); + mpv_observe_property(ctx, 0, "time-pos", MPV_FORMAT_DOUBLE); + mpv_observe_property(ctx, 0, "pause", MPV_FORMAT_FLAG); + mpv_set_wakeup_callback(ctx, wakeup, NULL); + } } @implementation EventsResponder @@ -305,12 +306,14 @@ void cocoa_set_mpv_handle(struct mpv_handle *ctx) _is_application = isApplication; } -- (void)setMpvHandle:(struct mpv_handle *)ctx +- (BOOL)setMpvHandle:(struct mpv_handle *)ctx { if (_is_application) { dispatch_sync(dispatch_get_main_queue(), ^{ _ctx = ctx; }); + return YES; } else { - _ctx = ctx; + mpv_detach_destroy(ctx); + return NO; } }