mirror of
https://github.com/mpv-player/mpv
synced 2025-03-25 04:38:01 +00:00
win32: use a platform-specific unicode entry-point
Add a platform-specific entry-point for Windows. This will allow some platform-specific initialization to be added without the need for ugly ifdeffery in main.c. As an immediate advantage, mpv can now use a unicode entry-point and convert the command line arguments to UTF-8 before passing them to mpv_main, so osdep_preinit can be simplified a little bit.
This commit is contained in:
parent
6f46bafbd0
commit
ac7ecbe30c
@ -334,7 +334,7 @@ all: $(ALL_TARGETS)
|
||||
%.o: %.c
|
||||
$(CC) $(DEPFLAGS) $(CFLAGS) -c -o $@ $<
|
||||
|
||||
mpv: $(OBJECTS) player/main_fn.o
|
||||
mpv: $(OBJECTS) player/main-fn-unix.o
|
||||
$(CC) -o $@ $^ $(EXTRALIBS)
|
||||
|
||||
input/input.c: input/input_conf.h
|
||||
|
26
osdep/io.c
26
osdep/io.c
@ -121,32 +121,6 @@ char *mp_to_utf8(void *talloc_ctx, const wchar_t *s)
|
||||
#include <fcntl.h>
|
||||
#include <pthread.h>
|
||||
|
||||
//http://git.libav.org/?p=libav.git;a=blob;f=cmdutils.c;h=ade3f10ce2fc030e32e375a85fbd06c26d43a433#l161
|
||||
|
||||
static char** win32_argv_utf8;
|
||||
static int win32_argc;
|
||||
|
||||
void mp_get_converted_argv(int *argc, char ***argv)
|
||||
{
|
||||
if (!win32_argv_utf8) {
|
||||
win32_argc = 0;
|
||||
wchar_t **argv_w = CommandLineToArgvW(GetCommandLineW(), &win32_argc);
|
||||
if (win32_argc <= 0 || !argv_w)
|
||||
return;
|
||||
|
||||
win32_argv_utf8 = talloc_zero_array(NULL, char*, win32_argc + 1);
|
||||
|
||||
for (int i = 0; i < win32_argc; i++) {
|
||||
win32_argv_utf8[i] = mp_to_utf8(NULL, argv_w[i]);
|
||||
}
|
||||
|
||||
LocalFree(argv_w);
|
||||
}
|
||||
|
||||
*argc = win32_argc;
|
||||
*argv = win32_argv_utf8;
|
||||
}
|
||||
|
||||
static void copy_stat(struct mp_stat *dst, struct _stat64 *src)
|
||||
{
|
||||
dst->st_dev = src->st_dev;
|
||||
|
@ -65,8 +65,6 @@ char *mp_to_utf8(void *talloc_ctx, const wchar_t *s);
|
||||
#include <sys/stat.h>
|
||||
#include <fcntl.h>
|
||||
|
||||
void mp_get_converted_argv(int *argc, char ***argv);
|
||||
|
||||
int mp_printf(const char *format, ...);
|
||||
int mp_fprintf(FILE *stream, const char *format, ...);
|
||||
int mp_open(const char *filename, int oflag, ...);
|
||||
|
20
player/main-fn-win.c
Normal file
20
player/main-fn-win.c
Normal file
@ -0,0 +1,20 @@
|
||||
#include "config.h"
|
||||
#include "core.h"
|
||||
#include "osdep/io.h"
|
||||
|
||||
int wmain(int argc, wchar_t *argv[]);
|
||||
|
||||
// mpv does its own wildcard expansion in the option parser
|
||||
int _dowildcard = 0;
|
||||
|
||||
int wmain(int argc, wchar_t *argv[])
|
||||
{
|
||||
char **argv_u8 = talloc_zero_array(NULL, char*, argc + 1);
|
||||
for (int i = 0; i < argc; i++)
|
||||
argv_u8[i] = mp_to_utf8(argv_u8, argv[i]);
|
||||
|
||||
int ret = mpv_main(argc, argv_u8);
|
||||
|
||||
talloc_free(argv_u8);
|
||||
return ret;
|
||||
}
|
@ -275,19 +275,15 @@ static bool handle_help_options(struct MPContext *mpctx)
|
||||
return opt_exit;
|
||||
}
|
||||
|
||||
static void osdep_preinit(int *p_argc, char ***p_argv)
|
||||
static void osdep_preinit(int argc, char **argv)
|
||||
{
|
||||
char *enable_talloc = getenv("MPV_LEAK_REPORT");
|
||||
if (*p_argc > 1 && (strcmp((*p_argv)[1], "-leak-report") == 0 ||
|
||||
strcmp((*p_argv)[1], "--leak-report") == 0))
|
||||
if (argc > 1 && (strcmp(argv[1], "-leak-report") == 0 ||
|
||||
strcmp(argv[1], "--leak-report") == 0))
|
||||
enable_talloc = "1";
|
||||
if (enable_talloc && strcmp(enable_talloc, "1") == 0)
|
||||
talloc_enable_leak_report();
|
||||
|
||||
#ifdef __MINGW32__
|
||||
mp_get_converted_argv(p_argc, p_argv);
|
||||
#endif
|
||||
|
||||
#ifdef _WIN32
|
||||
// stop Windows from showing all kinds of annoying error dialogs
|
||||
SetErrorMode(SEM_FAILCRITICALERRORS | SEM_NOOPENFILEERRORBOX);
|
||||
@ -514,7 +510,7 @@ int mp_initialize(struct MPContext *mpctx, char **options)
|
||||
|
||||
int mpv_main(int argc, char *argv[])
|
||||
{
|
||||
osdep_preinit(&argc, &argv);
|
||||
osdep_preinit(argc, argv);
|
||||
|
||||
struct MPContext *mpctx = mp_create();
|
||||
struct MPOpts *opts = mpctx->opts;
|
||||
|
@ -53,8 +53,8 @@ def __add_mswin_flags__(ctx):
|
||||
|
||||
def __add_mingw_flags__(ctx):
|
||||
__add_mswin_flags__(ctx)
|
||||
ctx.env.CFLAGS += ['-D__USE_MINGW_ANSI_STDIO=1']
|
||||
ctx.env.LAST_LINKFLAGS += ['-mwindows']
|
||||
ctx.env.CFLAGS += ['-municode', '-D__USE_MINGW_ANSI_STDIO=1']
|
||||
ctx.env.LAST_LINKFLAGS += ['-municode', '-mwindows']
|
||||
|
||||
def __add_cygwin_flags__(ctx):
|
||||
__add_mswin_flags__(ctx)
|
||||
|
@ -71,6 +71,10 @@ 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")
|
||||
|
||||
getch2_c = {
|
||||
'win32': 'osdep/terminal-win.c',
|
||||
}.get(ctx.env.DEST_OS, "osdep/terminal-unix.c")
|
||||
@ -418,7 +422,7 @@ def build(ctx):
|
||||
if ctx.dependency_satisfied('cplayer'):
|
||||
ctx(
|
||||
target = "mpv",
|
||||
source = "player/main_fn.c",
|
||||
source = main_fn_c,
|
||||
use = ctx.dependencies_use() + ['objects'],
|
||||
includes = _all_includes(ctx),
|
||||
features = "c cprogram",
|
||||
|
Loading…
Reference in New Issue
Block a user