diff options
author | Stefano Pigozzi <stefano.pigozzi@gmail.com> | 2013-02-23 18:28:22 +0100 |
---|---|---|
committer | Stefano Pigozzi <stefano.pigozzi@gmail.com> | 2013-05-12 15:27:54 +0200 |
commit | afdc9c4ae2e69a9ced6c3c6580df19edfedea36a (patch) | |
tree | 552186adca34cd6c1b6fb89656badde9e140a297 /core/mplayer.c | |
parent | 6a2a8880e92442a70696cac217773f1078023084 (diff) | |
download | mpv-afdc9c4ae2e69a9ced6c3c6580df19edfedea36a.tar.bz2 mpv-afdc9c4ae2e69a9ced6c3c6580df19edfedea36a.tar.xz |
OSX: use native Cocoa's event loop
Schedule mpv's playloop as a high frequency timer inside the main Cocoa event
loop. This has the benefit to allow accessing menus as well as resizing the
window without the playback being blocked and allows to remove countless hacks
from the code that involved manually pumping the event loop as well simulating
manually some of the Cocoa default behaviours.
A huge improvement consists in removing NSApplicationLoad. This is a C function
defined in the Cocoa header and implements a minimal OSX application under ther
hood so that you can use the Cocoa GUI toolkit from C/C++ without having to
respect the Cocoa standards in terms of application initialization. This was
bad because the behaviour implemented by NSApplicationLoad was hard to customize
and had several gotchas especially in the menu department.
mpv was changed to be just a nib-less application. All the Cocoa part is still
generated in code but the event handling is now not dissimilar to what is
present in a stock Mac application.
As a part of reviewing the initialization process, I also removed all of
`osdep/macosx_finder_args`. The useful parts of the code were moved to
`osdep/macosx_appication` which has the broaded responsibility of managing the
full lifecycle of the Cocoa application. By consequence the
`--enable-macosx-finder` configure switch was killed as well, as this feature
is always enabled.
Another change the users will notice is that when using a bundle the `--quiet`
option will be inserted much earlier in the initializaion process. This results
in mpv not spamming mpv.log anymore with all the initialization outputs.
Diffstat (limited to 'core/mplayer.c')
-rw-r--r-- | core/mplayer.c | 45 |
1 files changed, 43 insertions, 2 deletions
diff --git a/core/mplayer.c b/core/mplayer.c index 72871bd0f0..2e79e80c14 100644 --- a/core/mplayer.c +++ b/core/mplayer.c @@ -86,6 +86,10 @@ #include "video/out/x11_common.h" #endif +#ifdef CONFIG_COCOA +#include "osdep/macosx_application.h" +#endif + #include "audio/out/ao.h" #include "core/codecs.h" @@ -607,7 +611,14 @@ static MP_NORETURN void exit_player(struct MPContext *mpctx, talloc_free(mpctx); +#ifdef CONFIG_COCOA + terminate_cocoa_application(); + // never reach here: + // terminate calls exit itself, just silence compiler warning + exit(0); +#else exit(rc); +#endif } static void mk_config_dir(char *subdir) @@ -3792,6 +3803,32 @@ static void run_playloop(struct MPContext *mpctx) execute_queued_seek(mpctx); } +static void run_playloop_opaque_callback(void *context) +{ + run_playloop((struct MPContext *)context); +} + +static int check_stop_play(void *context) +{ + struct MPContext *mpctx = context; + return mpctx->stop_play; +} + +static void schedule_run_playloop(struct MPContext *mpctx) +{ + + #ifdef CONFIG_COCOA + cocoa_run_loop_schedule(run_playloop_opaque_callback, + check_stop_play, + mpctx, // passed in as opaque type + mpctx->input, + mpctx->key_fifo); + cocoa_run_runloop(); + #else + while (!check_stop_play(mpctx)) + run_playloop(mpctx); + #endif +} static int read_keys(void *ctx, int fd) { @@ -4395,8 +4432,7 @@ goto_enable_cache: ; if (mpctx->opts.pause) pause_player(mpctx); - while (!mpctx->stop_play) - run_playloop(mpctx); + schedule_run_playloop(mpctx); mp_msg(MSGT_GLOBAL, MSGL_V, "EOF code: %d \n", mpctx->stop_play); @@ -4585,6 +4621,11 @@ static void osdep_preinit(int *p_argc, char ***p_argv) GetCpuCaps(&gCpuCaps); +#ifdef CONFIG_COCOA + init_cocoa_application(); + macosx_finder_args_preinit(p_argc, p_argv); +#endif + #ifdef __MINGW32__ mp_get_converted_argv(p_argc, p_argv); #endif |