1
mirror of https://github.com/mpv-player/mpv synced 2024-10-22 08:51:57 +02:00

mplayer: move highly OS specific initialization code out of main()

The intention is to make the main() function smaller (which is at
about 1000 lines currently).

This commit also changes the order of some initializations, but that
should be safe.
This commit is contained in:
wm4 2012-08-03 05:09:55 +02:00
parent 4ced6d4e78
commit 11648493db

View File

@ -3424,27 +3424,62 @@ static void detach_ptw32(void)
}
#endif
/* This preprocessor directive is a hack to generate a mplayer-nomain.o object
* file for some tools to link against. */
#ifndef DISABLE_MAIN
int main(int argc, char *argv[])
static void osdep_preinit(int *p_argc, char ***p_argv)
{
#ifdef PTW32_STATIC_LIB
pthread_win32_process_attach_np();
pthread_win32_thread_attach_np();
atexit(detach_ptw32);
#endif
if (argc > 1 && (!strcmp(argv[1], "-leak-report")
|| !strcmp(argv[1], "--leak-report")))
talloc_enable_leak_report();
GetCpuCaps(&gCpuCaps);
#ifdef __MINGW32__
mp_get_converted_argv(&argc, &argv);
#endif
char *mem_ptr;
#ifdef PTW32_STATIC_LIB
pthread_win32_process_attach_np();
pthread_win32_thread_attach_np();
atexit(detach_ptw32);
#endif
// movie info:
InitTimer();
srand(GetTimerMS());
#if (defined(__MINGW32__) || defined(__CYGWIN__)) && defined(CONFIG_WIN32DLL)
set_path_env();
#endif
#if defined(__MINGW32__) || defined(__CYGWIN__)
{
HMODULE kernel32 = GetModuleHandle("Kernel32.dll");
BOOL WINAPI (*setDEP)(DWORD) = NULL;
BOOL WINAPI (*setDllDir)(LPCTSTR) = NULL;
if (kernel32) {
setDEP = GetProcAddress(kernel32, "SetProcessDEPPolicy");
setDllDir = GetProcAddress(kernel32, "SetDllDirectoryA");
}
if (setDEP)
setDEP(3);
if (setDllDir)
setDllDir("");
}
// stop Windows from showing all kinds of annoying error dialogs
SetErrorMode(0x8003);
// request 1ms timer resolution
timeBeginPeriod(1);
#endif
#ifdef HAVE_TERMCAP
load_termcap(NULL); // load key-codes
#endif
}
/* This preprocessor directive is a hack to generate a mplayer-nomain.o object
* file for some tools to link against. */
#ifndef DISABLE_MAIN
int main(int argc, char *argv[])
{
osdep_preinit(&argc, &argv);
if (argc > 1 && (!strcmp(argv[1], "-leak-report")
|| !strcmp(argv[1], "--leak-report")))
talloc_enable_leak_report();
/* Flag indicating whether MPlayer should exit without playing anything. */
int opt_exit = 0;
@ -3461,9 +3496,6 @@ int main(int argc, char *argv[])
.terminal_osd_text = talloc_strdup(mpctx, ""),
};
InitTimer();
srand(GetTimerMS());
mp_msg_init();
init_libav();
screenshot_init(mpctx);
@ -3485,12 +3517,6 @@ int main(int argc, char *argv[])
print_version(false);
print_libav_versions();
GetCpuCaps(&gCpuCaps);
#if (defined(__MINGW32__) || defined(__CYGWIN__)) && defined(CONFIG_WIN32DLL)
set_path_env();
#endif
parse_cfgfiles(mpctx, mpctx->mconfig);
mpctx->playlist = talloc_struct(mpctx, struct playlist, {0});
@ -3502,26 +3528,6 @@ int main(int argc, char *argv[])
opt_exit = 1;
}
#if defined(__MINGW32__) || defined(__CYGWIN__)
{
HMODULE kernel32 = GetModuleHandle("Kernel32.dll");
BOOL WINAPI (*setDEP)(DWORD) = NULL;
BOOL WINAPI (*setDllDir)(LPCTSTR) = NULL;
if (kernel32) {
setDEP = GetProcAddress(kernel32, "SetProcessDEPPolicy");
setDllDir = GetProcAddress(kernel32, "SetDllDirectoryA");
}
if (setDEP)
setDEP(3);
if (setDllDir)
setDllDir("");
}
// stop Windows from showing all kinds of annoying error dialogs
SetErrorMode(0x8003);
// request 1ms timer resolution
timeBeginPeriod(1);
#endif
#ifdef CONFIG_PRIORITY
set_priority();
#endif
@ -3540,6 +3546,7 @@ int main(int argc, char *argv[])
/* Check codecs.conf. */
if (!codecs_file || !parse_codec_cfg(codecs_file)) {
char *mem_ptr;
if (!parse_codec_cfg(mem_ptr = get_path("codecs.conf"))) {
if (!parse_codec_cfg(MPLAYER_CONFDIR "/codecs.conf")) {
if (!parse_codec_cfg(NULL))
@ -3628,10 +3635,6 @@ int main(int argc, char *argv[])
mpctx->osd = osd_create(opts, mpctx->ass_library);
#ifdef HAVE_TERMCAP
load_termcap(NULL); // load key-codes
#endif
// ========== Init keyboard FIFO (connection to libvo) ============
// Init input system