From 134f3e97bf482b75c0eccbe5ac943a2a1d5a4ad6 Mon Sep 17 00:00:00 2001 From: Stefano Pigozzi Date: Mon, 4 Mar 2013 14:23:06 +0100 Subject: OSX: run native event loop in a separate thread This commit is a followup on the previous one and uses a solution I like more since it totally decouples the Cocoa code from mpv's core and tries to emulate a generic Cocoa application's lifecycle as much as possible without fighting the framework. mpv's main is executed in a pthread while the main thread runs the native cocoa event loop. All of the thread safety is mainly accomplished with additional logic in cocoa_common as to not increase complexity on the crossplatform parts of the code. --- osdep/macosx_application.h | 17 ++++++++--------- 1 file changed, 8 insertions(+), 9 deletions(-) (limited to 'osdep/macosx_application.h') diff --git a/osdep/macosx_application.h b/osdep/macosx_application.h index c2227ae05d..b0f7944512 100644 --- a/osdep/macosx_application.h +++ b/osdep/macosx_application.h @@ -22,9 +22,7 @@ struct input_ctx; struct mp_fifo; -// Playloop callback function pointer -typedef void(*play_loop_callback)(void *); -typedef int(*should_stop_callback)(void *); +typedef int (*mpv_main_fn)(int, char**); // Menu Keys identifing menu items typedef enum { @@ -35,22 +33,23 @@ typedef enum { MPM_ZOOM, } MPMenuKey; +// multithreaded wrapper for mpv_main +int cocoa_main(mpv_main_fn mpv_main, int argc, char *argv[]); + void cocoa_register_menu_item_action(MPMenuKey key, void* action); // initializes Cocoa application void init_cocoa_application(void); void terminate_cocoa_application(void); +void cocoa_autorelease_pool_alloc(void); +void cocoa_autorelease_pool_drain(void); // Runs the Cocoa Main Event Loop void cocoa_run_runloop(void); +void cocoa_stop_runloop(void); void cocoa_post_fake_event(void); -// Adds play_loop as a timer of the Main Cocoa Event Loop -void cocoa_run_loop_schedule(play_loop_callback callback, - should_stop_callback playback_stopped, - void *context, - struct input_ctx *input_context, - struct mp_fifo *key_fifo); +void cocoa_set_state(struct input_ctx *input_context, struct mp_fifo *key_fifo); void macosx_finder_args_preinit(int *argc, char ***argv); -- cgit v1.2.3