diff options
author | wm4 <wm4@nowhere> | 2015-05-02 18:47:57 +0200 |
---|---|---|
committer | wm4 <wm4@nowhere> | 2015-05-02 18:59:58 +0200 |
commit | 1e7831070f6ae1af0a1a29b0d680ef2907bf8cf6 (patch) | |
tree | 0d5bc34cfcdf029b8a22deb98c4f0e73c4266d57 | |
parent | 19a5b20752ecc7465cf17781f908e12bf4ca136d (diff) |
build: move main-fn files to osdep
And split the Cocoa and Unix cases. Simplify the Cocoa case slightly by
calling mpv_main directly, instead of passing a function pointer. Also
add a comment explaining why Cocoa needs a special case at all.
-rw-r--r-- | old-makefile | 2 | ||||
-rw-r--r-- | osdep/macosx_application.h | 4 | ||||
-rw-r--r-- | osdep/macosx_application.m | 7 | ||||
-rw-r--r-- | osdep/main-fn-cocoa.c | 10 | ||||
-rw-r--r-- | osdep/main-fn-unix.c | 6 | ||||
-rw-r--r-- | osdep/main-fn-win.c (renamed from player/main-fn-win.c) | 4 | ||||
-rw-r--r-- | osdep/main-fn.h | 1 | ||||
-rw-r--r-- | player/core.h | 1 | ||||
-rw-r--r-- | player/main-fn-unix.c | 15 | ||||
-rw-r--r-- | player/main.c | 1 | ||||
-rw-r--r-- | wscript_build.py | 9 |
11 files changed, 31 insertions, 29 deletions
diff --git a/old-makefile b/old-makefile index d7b1f1f1dc..1cbde2f31f 100644 --- a/old-makefile +++ b/old-makefile @@ -335,7 +335,7 @@ all: $(ALL_TARGETS) %.o: %.c $(CC) $(DEPFLAGS) $(CFLAGS) -c -o $@ $< -mpv: $(OBJECTS) player/main-fn-unix.o +mpv: $(OBJECTS) osdep/main-fn-unix.o $(CC) -o $@ $^ $(EXTRALIBS) input/input.c: input/input_conf.h diff --git a/osdep/macosx_application.h b/osdep/macosx_application.h index c48d1154a0..fea34a3705 100644 --- a/osdep/macosx_application.h +++ b/osdep/macosx_application.h @@ -18,8 +18,6 @@ #ifndef MPV_MACOSX_APPLICATION #define MPV_MACOSX_APPLICATION -typedef int (*mpv_main_fn)(int, char**); - // Menu Keys identifing menu items typedef enum { MPM_H_SIZE, @@ -30,7 +28,7 @@ typedef enum { } MPMenuKey; // multithreaded wrapper for mpv_main -int cocoa_main(mpv_main_fn mpv_main, int argc, char *argv[]); +int cocoa_main(int argc, char *argv[]); void cocoa_register_menu_item_action(MPMenuKey key, void* action); #endif /* MPV_MACOSX_APPLICATION */ diff --git a/osdep/macosx_application.m b/osdep/macosx_application.m index 2ff3386f76..595c47e3c6 100644 --- a/osdep/macosx_application.m +++ b/osdep/macosx_application.m @@ -26,6 +26,7 @@ #include "osdep/macosx_compat.h" #import "osdep/macosx_events_objc.h" #include "osdep/threads.h" +#include "osdep/main-fn.h" #define MPV_PROTOCOL @"mpv://" @@ -252,7 +253,6 @@ static void terminate_cocoa_application(void) @end struct playback_thread_ctx { - mpv_main_fn mpv_main; int *argc; char ***argv; }; @@ -269,7 +269,7 @@ 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 = ctx->mpv_main(*ctx->argc, *ctx->argv); + int r = mpv_main(*ctx->argc, *ctx->argv); terminate_cocoa_application(); // normally never reached - unless the cocoa mainloop hasn't started yet exit(r); @@ -361,13 +361,12 @@ static bool bundle_started_from_finder(int argc, char **argv) } } -int cocoa_main(mpv_main_fn mpv_main, int argc, char *argv[]) +int cocoa_main(int argc, char *argv[]) { @autoreleasepool { application_instantiated = true; struct playback_thread_ctx ctx = {0}; - ctx.mpv_main = mpv_main; ctx.argc = &argc; ctx.argv = &argv; diff --git a/osdep/main-fn-cocoa.c b/osdep/main-fn-cocoa.c new file mode 100644 index 0000000000..eeed127ead --- /dev/null +++ b/osdep/main-fn-cocoa.c @@ -0,0 +1,10 @@ +#include "osdep/macosx_application.h" + +// This is needed because Cocoa absolutely requires creating the NSApplication +// singleton and running it in the "main" thread. It is apparently not +// possible to do this on a separate thread at all. It is not known how +// Apple managed this colossal fuckup. +int main(int argc, char *argv[]) +{ + return cocoa_main(argc, argv); +} diff --git a/osdep/main-fn-unix.c b/osdep/main-fn-unix.c new file mode 100644 index 0000000000..c30c4a91ec --- /dev/null +++ b/osdep/main-fn-unix.c @@ -0,0 +1,6 @@ +#include "main-fn.h" + +int main(int argc, char *argv[]) +{ + return mpv_main(argc, argv); +} diff --git a/player/main-fn-win.c b/osdep/main-fn-win.c index 28fc5b3c24..d8dbcd5a8b 100644 --- a/player/main-fn-win.c +++ b/osdep/main-fn-win.c @@ -2,10 +2,10 @@ #include "config.h" +#include "common/common.h" #include "osdep/io.h" #include "osdep/terminal.h" - -#include "core.h" +#include "osdep/main-fn.h" int wmain(int argc, wchar_t *argv[]); diff --git a/osdep/main-fn.h b/osdep/main-fn.h new file mode 100644 index 0000000000..8f20308c8b --- /dev/null +++ b/osdep/main-fn.h @@ -0,0 +1 @@ +int mpv_main(int argc, char *argv[]); diff --git a/player/core.h b/player/core.h index da9401be36..ea7694d02a 100644 --- a/player/core.h +++ b/player/core.h @@ -404,7 +404,6 @@ struct track *select_track(struct MPContext *mpctx, enum stream_type type, int tid, int ffid, char **langs); // main.c -int mpv_main(int argc, char *argv[]); int mp_initialize(struct MPContext *mpctx, char **argv); struct MPContext *mp_create(void); void mp_destroy(struct MPContext *mpctx); diff --git a/player/main-fn-unix.c b/player/main-fn-unix.c deleted file mode 100644 index 87e1681987..0000000000 --- a/player/main-fn-unix.c +++ /dev/null @@ -1,15 +0,0 @@ -#include "config.h" -#include "core.h" - -#if HAVE_COCOA -#include "osdep/macosx_application.h" -#endif - -int main(int argc, char *argv[]) -{ -#if HAVE_COCOA - return cocoa_main(mpv_main, argc, argv); -#else - return mpv_main(argc, argv); -#endif -} diff --git a/player/main.c b/player/main.c index 641be7a289..d4feeff61c 100644 --- a/player/main.c +++ b/player/main.c @@ -30,6 +30,7 @@ #include "osdep/io.h" #include "osdep/terminal.h" #include "osdep/timer.h" +#include "osdep/main-fn.h" #include "common/av_log.h" #include "common/codecs.h" diff --git a/wscript_build.py b/wscript_build.py index 89ec67c471..93642c4693 100644 --- a/wscript_build.py +++ b/wscript_build.py @@ -71,9 +71,12 @@ def build(ctx): source = "demux/ebml.c", target = "ebml_defs.c") - main_fn_c = { - 'win32': 'player/main-fn-win.c', - }.get(ctx.env.DEST_OS, "player/main-fn-unix.c") + if ctx.env.DEST_OS == 'win32': + main_fn_c = 'osdep/main-fn-win.c' + elif ctx.dependency_satisfied('cocoa'): + main_fn_c = 'osdep/main-fn-cocoa.c' + else: + main_fn_c = 'osdep/main-fn-unix.c' getch2_c = { 'win32': 'osdep/terminal-win.c', |