首页 > 代码库 > OBS源码解析(1)main函数

OBS源码解析(1)main函数

int main(int argc, char *argv[])
{
#ifndef _WIN32
signal(SIGPIPE, SIG_IGN);
#endif

#ifdef _WIN32

/*OpenProcessToken函数用来打开与进程相关联的访问令牌,设置crash处理句柄*/
load_debug_privilege();
base_set_crash_handler(main_crash_handler, nullptr);
#endif

/*初始化log句柄*/

base_get_log_handler(&def_log_handler, nullptr);

#if defined(USE_XDG) && defined(IS_UNIX)
move_to_xdg();
#endif

/*解析命令行输入参数,设置相应工作状态*/

for (int i = 1; i < argc; i++) {
if (arg_is(argv[i], "--portable", "-p")) {
portable_mode = true;

} else if (arg_is(argv[i], "--startstreaming", nullptr)) {
opt_start_streaming = true;

} else if (arg_is(argv[i], "--startrecording", nullptr)) {
opt_start_recording = true;

} else if (arg_is(argv[i], "--collection", nullptr)) {
if (++i < argc) opt_starting_collection = argv[i];

} else if (arg_is(argv[i], "--profile", nullptr)) {
if (++i < argc) opt_starting_profile = argv[i];

} else if (arg_is(argv[i], "--scene", nullptr)) {
if (++i < argc) opt_starting_scene = argv[i];
}
}
#if !OBS_UNIX_STRUCTURE
if (!portable_mode) {
portable_mode =
os_file_exists(BASE_PATH "/portable_mode") ||
os_file_exists(BASE_PATH "/obs_portable_mode") ||
os_file_exists(BASE_PATH "/portable_mode.txt") ||
os_file_exists(BASE_PATH "/obs_portable_mode.txt");
}
#endif

/*更新设置*/

upgrade_settings();

fstream logFile;

/*初始化curl接口*/

curl_global_init(CURL_GLOBAL_ALL);

/*运行程序主逻辑*/
int ret = run_program(logFile, argc, argv);

blog(LOG_INFO, "Number of memory leaks: %ld", bnum_allocs());
base_set_log_handler(nullptr, nullptr);
return ret;
}

OBS源码解析(1)main函数