diff options
Diffstat (limited to 'osdep')
-rw-r--r-- | osdep/io.h | 4 | ||||
-rw-r--r-- | osdep/macOS_mpv_helper.swift | 37 | ||||
-rw-r--r-- | osdep/macOS_swift_bridge.h | 1 | ||||
-rw-r--r-- | osdep/macosx_application.h | 6 | ||||
-rw-r--r-- | osdep/macosx_application.m | 76 | ||||
-rw-r--r-- | osdep/macosx_application_objc.h | 2 | ||||
-rw-r--r-- | osdep/macosx_events.m | 21 | ||||
-rw-r--r-- | osdep/macosx_menubar.m | 4 | ||||
-rw-r--r-- | osdep/posix-spawn.h | 4 | ||||
-rw-r--r-- | osdep/strnlen.h | 4 |
10 files changed, 100 insertions, 59 deletions
diff --git a/osdep/io.h b/osdep/io.h index e0d6284baa..7e8a267541 100644 --- a/osdep/io.h +++ b/osdep/io.h @@ -33,7 +33,7 @@ #include <glob.h> #endif -#ifdef __ANDROID__ +#if HAVE_ANDROID # include <unistd.h> # include <stdio.h> @@ -58,7 +58,7 @@ static inline int mp_fseeko(FILE* fp, off64_t offset, int whence) { } #define fseeko(f,p,w) mp_fseeko((f), (p), (w)) -#endif // __ANDROID__ +#endif // HAVE_ANDROID #ifndef O_BINARY #define O_BINARY 0 diff --git a/osdep/macOS_mpv_helper.swift b/osdep/macOS_mpv_helper.swift index b023c4f098..8f6221d87c 100644 --- a/osdep/macOS_mpv_helper.swift +++ b/osdep/macOS_mpv_helper.swift @@ -21,6 +21,12 @@ import OpenGL.GL3 let glDummy: @convention(c) () -> Void = {} +extension Bool { + init(_ num: Int32) { + self.init(num > 0) + } +} + class MPVHelper: NSObject { var mpvHandle: OpaquePointer? @@ -28,7 +34,9 @@ class MPVHelper: NSObject { var mpvLog: OpaquePointer? var inputContext: OpaquePointer? var mpctx: UnsafeMutablePointer<MPContext>? + var macOpts: macos_opts? var fbo: GLint = 1 + let deinitLock = NSLock() init(_ mpv: OpaquePointer) { super.init() @@ -38,6 +46,12 @@ class MPVHelper: NSObject { mpctx = UnsafeMutablePointer<MPContext>(mp_client_get_core(mpvHandle)) inputContext = mpctx!.pointee.input + if let app = NSApp as? Application { + let ptr = mp_get_config_group(mpctx!, mp_client_get_global(mpvHandle), + app.getMacOSConf()) + macOpts = UnsafeMutablePointer<macos_opts>(OpaquePointer(ptr))!.pointee + } + mpv_observe_property(mpvHandle, 0, "ontop", MPV_FORMAT_FLAG) mpv_observe_property(mpvHandle, 0, "border", MPV_FORMAT_FLAG) mpv_observe_property(mpvHandle, 0, "keepaspect-window", MPV_FORMAT_FLAG) @@ -45,6 +59,7 @@ class MPVHelper: NSObject { } func initRender() { + var advanced: CInt = 1 let api = UnsafeMutableRawPointer(mutating: (MPV_RENDER_API_TYPE_OPENGL as NSString).utf8String) var pAddress = mpv_opengl_init_params(get_proc_address: getProcAddress, get_proc_address_ctx: nil, @@ -52,6 +67,7 @@ class MPVHelper: NSObject { var params: [mpv_render_param] = [ mpv_render_param(type: MPV_RENDER_PARAM_API_TYPE, data: api), mpv_render_param(type: MPV_RENDER_PARAM_OPENGL_INIT_PARAMS, data: &pAddress), + mpv_render_param(type: MPV_RENDER_PARAM_ADVANCED_CONTROL, data: &advanced), mpv_render_param() ] @@ -97,13 +113,26 @@ class MPVHelper: NSObject { func reportRenderFlip() { if mpvRenderContext == nil { return } - mpv_render_context_report_swap(mpvRenderContext) + mpv_render_context_report_swap(mpvRenderContext) + } + + func isRenderUpdateFrame() -> Bool { + deinitLock.lock() + if mpvRenderContext == nil { + deinitLock.unlock() + return false + } + let flags: UInt64 = mpv_render_context_update(mpvRenderContext) + deinitLock.unlock() + return flags & UInt64(MPV_RENDER_UPDATE_FRAME.rawValue) > 0 } - func drawRender(_ surface: NSSize) { + func drawRender(_ surface: NSSize, skip: Bool = false) { + deinitLock.lock() if mpvRenderContext != nil { var i: GLint = 0 var flip: CInt = 1 + var skip: CInt = skip ? 1 : 0 glGetIntegerv(GLenum(GL_DRAW_FRAMEBUFFER_BINDING), &i) // CAOpenGLLayer has ownership of FBO zero yet can return it to us, // so only utilize a newly received FBO ID if it is nonzero. @@ -116,6 +145,7 @@ class MPVHelper: NSObject { var params: [mpv_render_param] = [ 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_SKIP_RENDERING, data: &skip), mpv_render_param() ] mpv_render_context_render(mpvRenderContext, ¶ms); @@ -123,6 +153,7 @@ class MPVHelper: NSObject { glClearColor(0, 0, 0, 1) glClear(GLbitfield(GL_COLOR_BUFFER_BIT)) } + deinitLock.unlock() } func setRenderICCProfile(_ profile: NSColorSpace) { @@ -245,8 +276,10 @@ class MPVHelper: NSObject { func deinitRender() { mpv_render_context_set_update_callback(mpvRenderContext, nil, nil) mp_render_context_set_control_callback(mpvRenderContext, nil, nil) + deinitLock.lock() mpv_render_context_free(mpvRenderContext) mpvRenderContext = nil + deinitLock.unlock() } func deinitMPV(_ destroy: Bool = false) { diff --git a/osdep/macOS_swift_bridge.h b/osdep/macOS_swift_bridge.h index b0121d2a0f..4204b514d1 100644 --- a/osdep/macOS_swift_bridge.h +++ b/osdep/macOS_swift_bridge.h @@ -23,6 +23,7 @@ #include "video/out/libmpv.h" #include "libmpv/render_gl.h" +#include "options/m_config.h" #include "player/core.h" #include "input/input.h" #include "video/out/win_state.h" diff --git a/osdep/macosx_application.h b/osdep/macosx_application.h index 96a861fa35..0301e49fcb 100644 --- a/osdep/macosx_application.h +++ b/osdep/macosx_application.h @@ -20,6 +20,12 @@ #include "osdep/macosx_menubar.h" +struct macos_opts { + int macos_title_bar_style; + int macos_fs_animation_duration; + int cocoa_cb_sw_renderer; +}; + // multithreaded wrapper for mpv_main int cocoa_main(int argc, char *argv[]); void cocoa_register_menu_item_action(MPMenuKey key, void* action); diff --git a/osdep/macosx_application.m b/osdep/macosx_application.m index 4bc8eec0eb..086d51fef3 100644 --- a/osdep/macosx_application.m +++ b/osdep/macosx_application.m @@ -40,11 +40,6 @@ #define MPV_PROTOCOL @"mpv://" -struct macos_opts { - int macos_title_bar_style; - int macos_fs_animation_duration; -}; - #define OPT_BASE_STRUCT struct macos_opts const struct m_sub_options macos_conf = { .opts = (const struct m_option[]) { @@ -54,11 +49,14 @@ const struct m_sub_options macos_conf = { OPT_CHOICE_OR_INT("macos-fs-animation-duration", macos_fs_animation_duration, 0, 0, 1000, ({"default", -1})), + OPT_CHOICE("cocoa-cb-sw-renderer", cocoa_cb_sw_renderer, 0, + ({"auto", -1}, {"no", 0}, {"yes", 1})), {0} }, .size = sizeof(struct macos_opts), .defaults = &(const struct macos_opts){ .macos_fs_animation_duration = -1, + .cocoa_cb_sw_renderer = -1, }, }; @@ -66,13 +64,7 @@ const struct m_sub_options macos_conf = { // running in libmpv mode, and cocoa_main() was never called. static bool application_instantiated; -struct playback_thread_ctx { - int *argc; - char ***argv; -}; - static pthread_t playback_thread_id; -static struct playback_thread_ctx thread_ctx = {0}; @interface Application () { @@ -92,18 +84,6 @@ static void terminate_cocoa_application(void) [NSApp terminate:NSApp]; } -static void *playback_thread(void *ctx_obj) -{ - mpthread_set_name("playback core (OSX)"); - @autoreleasepool { - struct playback_thread_ctx *ctx = (struct playback_thread_ctx*) ctx_obj; - int r = mpv_main(*ctx->argc, *ctx->argv); - terminate_cocoa_application(); - // normally never reached - unless the cocoa mainloop hasn't started yet - exit(r); - } -} - @implementation Application @synthesize menuBar = _menu_bar; @synthesize openCount = _open_count; @@ -141,20 +121,15 @@ static void *playback_thread(void *ctx_obj) [super dealloc]; } -- (void)initMPVCore -{ - pthread_create(&playback_thread_id, NULL, playback_thread, &thread_ctx); - [[EventsResponder sharedInstance] waitForInputContext]; -} - static const char macosx_icon[] = #include "osdep/macosx_icon.inc" ; - (NSImage *)getMPVIcon { + // The C string contains a trailing null, so we strip it away NSData *icon_data = [NSData dataWithBytesNoCopy:(void *)macosx_icon - length:sizeof(macosx_icon) + length:sizeof(macosx_icon) - 1 freeWhenDone:NO]; return [[NSImage alloc] initWithData:icon_data]; } @@ -187,9 +162,14 @@ static const char macosx_icon[] = - (void)setMpvHandle:(struct mpv_handle *)ctx { - if (_cocoa_cb) { - [_cocoa_cb setMpvHandle:ctx]; - } +#if HAVE_MACOS_COCOA_CB + [NSApp setCocoaCB:[[CocoaCB alloc] init:ctx]]; +#endif +} + +- (const struct m_sub_options *)getMacOSConf +{ + return &macos_conf; } - (void)queueCommand:(char *)cmd @@ -255,6 +235,11 @@ static const char macosx_icon[] = } @end +struct playback_thread_ctx { + int *argc; + char ***argv; +}; + static void cocoa_run_runloop(void) { NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init]; @@ -262,6 +247,18 @@ static void cocoa_run_runloop(void) [pool drain]; } +static void *playback_thread(void *ctx_obj) +{ + mpthread_set_name("playback core (OSX)"); + @autoreleasepool { + struct playback_thread_ctx *ctx = (struct playback_thread_ctx*) ctx_obj; + int r = mpv_main(*ctx->argc, *ctx->argv); + terminate_cocoa_application(); + // normally never reached - unless the cocoa mainloop hasn't started yet + exit(r); + } +} + void cocoa_register_menu_item_action(MPMenuKey key, void* action) { if (application_instantiated) @@ -274,10 +271,6 @@ static void init_cocoa_application(bool regular) [NSApp setDelegate:NSApp]; [NSApp setMenuBar:[[MenuBar alloc] init]]; -#if HAVE_MACOS_COCOA_CB - [NSApp setCocoaCB:[[CocoaCB alloc] init]]; -#endif - // Will be set to Regular from cocoa_common during UI creation so that we // don't create an icon when playing audio only files. [NSApp setActivationPolicy: regular ? @@ -339,8 +332,9 @@ int cocoa_main(int argc, char *argv[]) application_instantiated = true; [[EventsResponder sharedInstance] setIsApplication:YES]; - thread_ctx.argc = &argc; - thread_ctx.argv = &argv; + struct playback_thread_ctx ctx = {0}; + ctx.argc = &argc; + ctx.argv = &argv; if (bundle_started_from_finder(argv)) { setup_bundle(&argc, argv); @@ -353,8 +347,8 @@ int cocoa_main(int argc, char *argv[]) init_cocoa_application(false); } - if (![NSApp cocoaCB]) - [NSApp initMPVCore]; + pthread_create(&playback_thread_id, NULL, playback_thread, &ctx); + [[EventsResponder sharedInstance] waitForInputContext]; cocoa_run_runloop(); // This should never be reached: cocoa_run_runloop blocks until the diff --git a/osdep/macosx_application_objc.h b/osdep/macosx_application_objc.h index 22e6f7e525..1685c99ba8 100644 --- a/osdep/macosx_application_objc.h +++ b/osdep/macosx_application_objc.h @@ -31,7 +31,7 @@ struct mpv_handle; - (void)stopMPV:(char *)cmd; - (void)openFiles:(NSArray *)filenames; - (void)setMpvHandle:(struct mpv_handle *)ctx; -- (void)initMPVCore; +- (const struct m_sub_options *)getMacOSConf; @property(nonatomic, retain) MenuBar *menuBar; @property(nonatomic, assign) size_t openCount; diff --git a/osdep/macosx_events.m b/osdep/macosx_events.m index 0d46c0e906..a354378777 100644 --- a/osdep/macosx_events.m +++ b/osdep/macosx_events.m @@ -375,7 +375,8 @@ void cocoa_set_mpv_handle(struct mpv_handle *ctx) - (void)restartMediaKeys { - CGEventTapEnable(self->_mk_tap_port, true); + if (self->_mk_tap_port) + CGEventTapEnable(self->_mk_tap_port, true); } - (void)setHighestPriotityMediaKeysTap @@ -410,10 +411,10 @@ void cocoa_set_mpv_handle(struct mpv_handle *ctx) tap_event_callback, self); - assert(self->_mk_tap_port != nil); - - NSMachPort *port = (NSMachPort *)self->_mk_tap_port; - [[NSRunLoop mainRunLoop] addPort:port forMode:NSRunLoopCommonModes]; + if (self->_mk_tap_port) { + NSMachPort *port = (NSMachPort *)self->_mk_tap_port; + [[NSRunLoop mainRunLoop] addPort:port forMode:NSRunLoopCommonModes]; + } }); } @@ -421,10 +422,12 @@ void cocoa_set_mpv_handle(struct mpv_handle *ctx) { dispatch_async(dispatch_get_main_queue(), ^{ NSMachPort *port = (NSMachPort *)self->_mk_tap_port; - CGEventTapEnable(self->_mk_tap_port, false); - [[NSRunLoop mainRunLoop] removePort:port forMode:NSRunLoopCommonModes]; - CFRelease(self->_mk_tap_port); - self->_mk_tap_port = nil; + if (port) { + CGEventTapEnable(self->_mk_tap_port, false); + [[NSRunLoop mainRunLoop] removePort:port forMode:NSRunLoopCommonModes]; + CFRelease(self->_mk_tap_port); + self->_mk_tap_port = nil; + } }); } diff --git a/osdep/macosx_menubar.m b/osdep/macosx_menubar.m index 931079a552..558a33a905 100644 --- a/osdep/macosx_menubar.m +++ b/osdep/macosx_menubar.m @@ -602,7 +602,7 @@ - (NSMenu *)mainMenu { NSMenu *mainMenu = [[NSMenu alloc] initWithTitle:@"MainMenu"]; - NSApp.servicesMenu = [NSMenu alloc]; + [NSApp setServicesMenu:[[NSMenu alloc] init]]; for(id mMenu in menuTree) { NSMenu *menu = [[NSMenu alloc] initWithTitle:mMenu[@"name"]]; @@ -633,7 +633,7 @@ } if ([subMenu[@"name"] isEqual:@"Services"]) { - iItem.submenu = NSApp.servicesMenu; + iItem.submenu = [NSApp servicesMenu]; } } } diff --git a/osdep/posix-spawn.h b/osdep/posix-spawn.h index d8bf874c98..fdba50149c 100644 --- a/osdep/posix-spawn.h +++ b/osdep/posix-spawn.h @@ -19,7 +19,9 @@ #pragma once -#ifdef __ANDROID__ +#include "config.h" + +#if HAVE_ANDROID // posix_spawn(p) does not exist at all on Android #include "osdep/android/posix-spawn.h" #else diff --git a/osdep/strnlen.h b/osdep/strnlen.h index 0a971d0ab0..e66932a89a 100644 --- a/osdep/strnlen.h +++ b/osdep/strnlen.h @@ -20,7 +20,9 @@ #ifndef MP_OSDEP_STRNLEN #define MP_OSDEP_STRNLEN -#ifdef __ANDROID__ +#include "config.h" + +#if HAVE_ANDROID // strnlen is broken on current android ndk, see https://code.google.com/p/android/issues/detail?id=74741 #include "osdep/android/strnlen.h" #define strnlen freebsd_strnlen |