hw_reg_t *init(hw_config_t *config, hw_callbacks_t *callbacks) { hw_reg_t *uart_reg; uint16_t start; uint16_t end; uart_state_t *state; int ret; int raw; struct termios pty_termios; hardware_callbacks = callbacks; uart_reg = malloc(sizeof(hw_reg_t) + sizeof(mem_remap_t)); if(!uart_reg) { perror("malloc"); exit(1); } memset(uart_reg, 0, sizeof(uart_reg)); if(!config_get_uint16(config, "mem_start", &start)) return NULL; if(!config_get_bool(config, "raw", &raw)) raw = 1; end = start + 8; uart_reg->hw_family = HW_FAMILY_SERIAL; uart_reg->memop = uart_memop; uart_reg->remapped_regions = 1; uart_reg->remap[0].mem_start = start; uart_reg->remap[0].mem_end = end; uart_reg->remap[0].readable = 1; uart_reg->remap[0].writable = 1; state = malloc(sizeof(uart_state_t)); if(!state) { perror("malloc"); exit(1); } memset(state, 0, sizeof(uart_state_t)); /* init the state */ state->LSR = LSR_TEMT | LSR_THRE; uart_reg->state = state; /* set up the pty */ state->pty = posix_openpt(O_RDWR); if(state->pty < 0) { perror("posix_openpt"); return NULL; } ret = grantpt(state->pty); if(ret) { perror("grantpt"); DEBUG("grantpt: %d", ret); return NULL; } ret = unlockpt(state->pty); if(ret) { perror("unlockpt"); return NULL; } if(raw) { tcgetattr(state->pty, &pty_termios); cfmakeraw(&pty_termios); tcsetattr(state->pty, TCSANOW, &pty_termios); } uart_reg->descr = strdup(ptsname(state->pty)); INFO("Opened pty for 16550 uart at %s", uart_reg->descr); NOTIFY("Opened pty for 16550 uart at %s", uart_reg->descr); /* now, start up an async listener thread */ if(pthread_mutex_init(&state->state_lock, NULL) < 0) { perror("pthread_mutex_init"); return NULL; } if(pthread_create(&state->listener_tid, NULL, listener_proc, state) < 0) { perror("pthread_create"); return NULL; } return uart_reg; }
static int child_setup(int sock_fd, struct clientinfo *clntinfo) { struct sockaddr_in t_in; struct sockaddr_in c_in; unsigned long int peer_ip = get_uint_peer_ip(sock_fd); struct sigaction sa; int i, ret; #ifdef HAVE_LIBWRAP struct request_info req; int libwrap_allow = 0; #endif if (peer_ip == (unsigned long int) UINT_MAX) { return -1; } if (stage_action("connect") < 0) { say(sock_fd, "421 Error setting up (see logfile)\r\n"); return -1; } /* The clients ignore the SIGHUP signal. Thus * the user can issue a killall -HUP jftpgw * and the master jftpgw process rereads its * configuration file without affecting the * child servers */ sa.sa_handler = SIG_IGN; sigemptyset(&sa.sa_mask); sa.sa_flags = 0; sigaction(SIGHUP, &sa, 0); /* And they just reap the status of exited children */ sa.sa_handler = reap_chld_info; sigemptyset(&sa.sa_mask); #ifndef WINDOWS sa.sa_flags = SA_RESTART; #endif sigaction(SIGCHLD, &sa, 0); for (i = 0; i < clntinfo->boundsocket_niface; i++) { close(clntinfo->boundsocket_list[i]); } free(clntinfo->boundsocket_list); clntinfo->boundsocket_list = (int*) 0; clntinfo->forward.passauth = 0; clntinfo->serversocket = -1; clntinfo->clientsocket = sock_fd; jlog(7, "Connection from %s", get_char_peer_ip(sock_fd)); c_in = socketinfo_get_local_sin(sock_fd); jlog(7, "Client tried to connect to %s on port %d", inet_ntoa(c_in.sin_addr), ntohs(c_in.sin_port)); clntinfo->addr_to_client = c_in.sin_addr.s_addr; clntinfo->proxy_ip = c_in.sin_addr.s_addr; clntinfo->proxy_port = ntohs(c_in.sin_port); /* see if we are in transparent mode */ t_in = socketinfo_get_transparent_target_sin(sock_fd); jlog(7, "Transparent target seems to be %s on port %d", inet_ntoa(t_in.sin_addr), ntohs(t_in.sin_port)); jlog(9, "Checking TAG_GLOBAL | TAG_FROM | TAG_PROXYIP | TAG_PROXYPORT | TAG_TIME | TAG_SERVERTYPE"); ret = config_shrink_config(peer_ip, /* source IP */ -1, /* dest IP */ (char*) 0, /* dest name */ 0, /* dest port */ (char*) 0, /* dest user */ -1, /* forwarded IP */ (char*) 0, /* forwarded destination */ 0, /* forwarded destinationport */ (char*) 0, /* forwarded username */ 0, /* set no specific time */ clntinfo->proxy_ip, /* ip of proxy if */ clntinfo->proxy_port, /* port of proxy if */ srvinfo.servertype, /* global variable */ &hostcache, TAG_CONNECTED ); if (ret != 0) { jlog(2, "Error shrinking config data"); return ret; } #ifndef HAVE_LIBWRAP srvinfo.tcp_wrapper = 0; #endif if (srvinfo.tcp_wrapper) { #ifdef HAVE_LIBWRAP /* use libwrap(tcp_wrapper) for access control * patch by <*****@*****.**>. * It is useful to check both keywords "jftpgw" and "ftp-gw" * for TIS Gauntlet flabour. */ request_init(&req, RQ_DAEMON, "ftp-gw", RQ_CLIENT_ADDR, conv_ip_to_char(peer_ip), NULL); libwrap_allow = hosts_access(&req); request_init(&req, RQ_DAEMON, "jftpgw", RQ_CLIENT_ADDR, conv_ip_to_char(peer_ip), NULL); if (libwrap_allow || hosts_access(&req)) { jlog(5, "%s is allowed by libwrap to connect.", conv_ip_to_char(peer_ip)); } else { say(sock_fd, "500 You are not allowed by libwrap to " "connect. Goodbye.\r\n"); jlog(5, "%s was not allowed to connect.", conv_ip_to_char(peer_ip)); close(sock_fd); return -2; } #endif } else { if ( ! config_get_option("access") || ! strcmp(config_get_option("access"), "allow") == 0) { say(sock_fd, "500 You are not allowed to " "connect. Goodbye.\r\n"); jlog(5, "%s was not allowed to connect.", conv_ip_to_char(peer_ip)); close(sock_fd); return -2; } else { jlog(6, "%s is allowed to connect.", conv_ip_to_char(peer_ip)); } } if (config_get_bool("transparent-proxy") && get_uint_peer_ip(sock_fd) == t_in.sin_addr.s_addr) { jlog(4, "proxy loop detected - machine connects to itself, disabling transparent proxy support"); } jlog(9, "Proxy loop check: peer_ip: %s, t_in_ip: %s", get_char_peer_ip(sock_fd), inet_ntoa(t_in.sin_addr)); #ifdef HAVE_LINUX_NETFILTER_IPV4_H jlog(9, "HAVE_LINUX_NETFILTER_IPV4_H true, c_in_ip: %s, t_in_port: %d, " "c_in_port: %d", inet_ntoa(c_in.sin_addr), ntohs(t_in.sin_port), ntohs(c_in.sin_port)); #endif if (config_get_bool("transparent-proxy") && /* see if the proxy loops. It loops when the source has the * same IP as the destination. There is no need for such a * configuration "in the wild". Is there? */ (!(get_uint_peer_ip(sock_fd) == t_in.sin_addr.s_addr) #ifdef HAVE_LINUX_NETFILTER_IPV4_H && !(t_in.sin_addr.s_addr == c_in.sin_addr.s_addr && t_in.sin_port == c_in.sin_port) #endif )) { jlog(9, "Enabling transparent proxy"); clntinfo->transparent = TRANSPARENT_YES; clntinfo->transparent_destination = t_in; } else { jlog(9, "No transparent proxy support"); clntinfo->transparent = TRANSPARENT_NO; clntinfo->transparent_destination.sin_port = 0; clntinfo->transparent_destination.sin_addr.s_addr = 0; } if (stage_action("connectsetup") < 0) { say(sock_fd, "421 Error setting up (see logfile)\r\n"); return -1; } /* set the target for the transparent proxy */ if (clntinfo->transparent == TRANSPARENT_YES) { char* colon; long int dport; if (config_get_option("transparent-forward") && config_compare_option("logintime", "connect")) { clntinfo->destination = strdup(config_get_option("transparent-forward")); jlog(9, "Enabling transparent forward to %s", clntinfo->destination); } else { clntinfo->destination = socketinfo_get_transparent_target_char(sock_fd); } colon = strchr(clntinfo->destination, ':'); if (!colon) { /* abort, shouldnt happen */ jlog(9, "Could not get transparent target properly"); clntinfo->transparent = TRANSPARENT_NO; return say_welcome(sock_fd); } *colon = '\0'; /* terminate destination */ colon++; /* skip to port number */ dport = strtol(colon, NULL, 10); if (errno == ERANGE && (dport == LONG_MIN || dport == LONG_MAX)) { clntinfo->destinationport = config_get_ioption("serverport", DEFAULTSERVERPORT); /* reverse for logging */ colon--; *colon = ':'; jlog(6, "Could not parse dest/port to connect to: %s", clntinfo->destination); return -1; } else { clntinfo->destinationport = dport; } } if ( ! config_compare_option("logintime", "connect") ) { ret = say_welcome(sock_fd); } else { ret = login(clntinfo, LOGIN_ST_CONNECTED); } /* seed the random number generator */ srand(time(NULL)); return ret; }
bool config_load_file(const char *path, bool set_defaults) { unsigned i; config_file_t *conf = NULL; if (path) { conf = config_file_new(path); if (!conf) return false; } else conf = open_default_config_file(); if (conf == NULL) return true; if (set_defaults) config_set_defaults(); char *save; char tmp_append_path[PATH_MAX]; // Don't destroy append_config_path. strlcpy(tmp_append_path, g_extern.append_config_path, sizeof(tmp_append_path)); const char *extra_path = strtok_r(tmp_append_path, ",", &save); while (extra_path) { RARCH_LOG("Appending config \"%s\"\n", extra_path); bool ret = config_append_file(conf, extra_path); if (!ret) RARCH_ERR("Failed to append config \"%s\"\n", extra_path); extra_path = strtok_r(NULL, ";", &save); } if (g_extern.verbose) { RARCH_LOG_OUTPUT("=== Config ===\n"); config_file_dump_all(conf, stderr); RARCH_LOG_OUTPUT("=== Config end ===\n"); } char tmp_str[PATH_MAX]; CONFIG_GET_FLOAT(video.xscale, "video_xscale"); CONFIG_GET_FLOAT(video.yscale, "video_yscale"); CONFIG_GET_INT(video.fullscreen_x, "video_fullscreen_x"); CONFIG_GET_INT(video.fullscreen_y, "video_fullscreen_y"); if (!g_extern.force_fullscreen) CONFIG_GET_BOOL(video.fullscreen, "video_fullscreen"); CONFIG_GET_BOOL(video.windowed_fullscreen, "video_windowed_fullscreen"); CONFIG_GET_INT(video.monitor_index, "video_monitor_index"); CONFIG_GET_BOOL(video.disable_composition, "video_disable_composition"); CONFIG_GET_BOOL(video.vsync, "video_vsync"); CONFIG_GET_BOOL(video.hard_sync, "video_hard_sync"); CONFIG_GET_INT(video.hard_sync_frames, "video_hard_sync_frames"); if (g_settings.video.hard_sync_frames > 3) g_settings.video.hard_sync_frames = 3; CONFIG_GET_BOOL(video.black_frame_insertion, "video_black_frame_insertion"); CONFIG_GET_INT(video.swap_interval, "video_swap_interval"); g_settings.video.swap_interval = max(g_settings.video.swap_interval, 1); g_settings.video.swap_interval = min(g_settings.video.swap_interval, 4); CONFIG_GET_BOOL(video.threaded, "video_threaded"); CONFIG_GET_BOOL(video.smooth, "video_smooth"); CONFIG_GET_BOOL(video.force_aspect, "video_force_aspect"); CONFIG_GET_BOOL(video.scale_integer, "video_scale_integer"); CONFIG_GET_BOOL(video.crop_overscan, "video_crop_overscan"); CONFIG_GET_FLOAT(video.aspect_ratio, "video_aspect_ratio"); CONFIG_GET_INT(video.aspect_ratio_idx, "aspect_ratio_index"); CONFIG_GET_BOOL(video.aspect_ratio_auto, "video_aspect_ratio_auto"); CONFIG_GET_FLOAT(video.refresh_rate, "video_refresh_rate"); CONFIG_GET_PATH(video.shader_path, "video_shader"); CONFIG_GET_BOOL(video.shader_enable, "video_shader_enable"); CONFIG_GET_BOOL(video.allow_rotate, "video_allow_rotate"); CONFIG_GET_PATH(video.font_path, "video_font_path"); CONFIG_GET_FLOAT(video.font_size, "video_font_size"); CONFIG_GET_BOOL(video.font_enable, "video_font_enable"); CONFIG_GET_BOOL(video.font_scale, "video_font_scale"); CONFIG_GET_FLOAT(video.msg_pos_x, "video_message_pos_x"); CONFIG_GET_FLOAT(video.msg_pos_y, "video_message_pos_y"); CONFIG_GET_INT(video.rotation, "video_rotation"); #ifdef RARCH_CONSOLE /* TODO - will be refactored later to make it more clean - it's more * important that it works for consoles right now */ CONFIG_GET_BOOL_EXTERN(console.screen.gamma_correction, "gamma_correction"); bool triple_buffering_enable = false; bool custom_bgm_enable = false; bool flicker_filter_enable = false; bool soft_filter_enable = false; #ifdef HAVE_RMENU if (config_get_path(conf, "menu_texture_path", tmp_str, sizeof(tmp_str))) strlcpy(g_extern.menu_texture_path, tmp_str, sizeof(g_extern.menu_texture_path)); #endif if (config_get_bool(conf, "triple_buffering_enable", &triple_buffering_enable)) { if (triple_buffering_enable) g_extern.lifecycle_state |= (1ULL << MODE_VIDEO_TRIPLE_BUFFERING_ENABLE); else g_extern.lifecycle_state &= ~(1ULL << MODE_VIDEO_TRIPLE_BUFFERING_ENABLE); } if (config_get_bool(conf, "custom_bgm_enable", &custom_bgm_enable)) { if (custom_bgm_enable) g_extern.lifecycle_state |= (1ULL << MODE_AUDIO_CUSTOM_BGM_ENABLE); else g_extern.lifecycle_state &= ~(1ULL << MODE_AUDIO_CUSTOM_BGM_ENABLE); } if (config_get_bool(conf, "flicker_filter_enable", &flicker_filter_enable)) { if (flicker_filter_enable) g_extern.lifecycle_state |= (1ULL << MODE_VIDEO_FLICKER_FILTER_ENABLE); else g_extern.lifecycle_state &= ~(1ULL << MODE_VIDEO_FLICKER_FILTER_ENABLE); } if (config_get_bool(conf, "soft_filter_enable", &soft_filter_enable)) { if (soft_filter_enable) g_extern.lifecycle_state |= (1ULL << MODE_VIDEO_SOFT_FILTER_ENABLE); else g_extern.lifecycle_state &= ~(1ULL << MODE_VIDEO_SOFT_FILTER_ENABLE); } CONFIG_GET_INT_EXTERN(console.screen.flicker_filter_index, "flicker_filter_index"); CONFIG_GET_INT_EXTERN(console.screen.soft_filter_index, "soft_filter_index"); #ifdef _XBOX1 CONFIG_GET_INT_EXTERN(console.sound.volume_level, "sound_volume_level"); #endif CONFIG_GET_INT_EXTERN(console.screen.resolutions.current.id, "current_resolution_id"); CONFIG_GET_INT_EXTERN(console.sound.mode, "sound_mode"); #endif CONFIG_GET_INT_EXTERN(state_slot, "state_slot"); CONFIG_GET_INT_EXTERN(console.screen.viewports.custom_vp.x, "custom_viewport_x"); CONFIG_GET_INT_EXTERN(console.screen.viewports.custom_vp.y, "custom_viewport_y"); CONFIG_GET_INT_EXTERN(console.screen.viewports.custom_vp.width, "custom_viewport_width"); CONFIG_GET_INT_EXTERN(console.screen.viewports.custom_vp.height, "custom_viewport_height"); unsigned msg_color = 0; if (config_get_hex(conf, "video_message_color", &msg_color)) { g_settings.video.msg_color_r = ((msg_color >> 16) & 0xff) / 255.0f; g_settings.video.msg_color_g = ((msg_color >> 8) & 0xff) / 255.0f; g_settings.video.msg_color_b = ((msg_color >> 0) & 0xff) / 255.0f; }
core_info_list_t *core_info_list_new(void) { size_t i; core_info_t *core_info = NULL; core_info_list_t *core_info_list = NULL; settings_t *settings = config_get_ptr(); struct string_list *contents = dir_list_new_special(NULL, DIR_LIST_CORES); if (!contents) return NULL; core_info_list = (core_info_list_t*)calloc(1, sizeof(*core_info_list)); if (!core_info_list) goto error; core_info = (core_info_t*)calloc(contents->size, sizeof(*core_info)); if (!core_info) goto error; core_info_list->list = core_info; core_info_list->count = contents->size; for (i = 0; i < contents->size; i++) { char info_path_base[PATH_MAX_LENGTH] = {0}; char info_path[PATH_MAX_LENGTH] = {0}; core_info[i].path = strdup(contents->elems[i].data); if (!core_info[i].path) break; fill_pathname_base(info_path_base, contents->elems[i].data, sizeof(info_path_base)); path_remove_extension(info_path_base); #if defined(RARCH_MOBILE) || (defined(RARCH_CONSOLE) && !defined(PSP)) char *substr = strrchr(info_path_base, '_'); if (substr) *substr = '\0'; #endif strlcat(info_path_base, ".info", sizeof(info_path_base)); fill_pathname_join(info_path, (*settings->libretro_info_path) ? settings->libretro_info_path : settings->libretro_directory, info_path_base, sizeof(info_path)); core_info[i].data = config_file_new(info_path); if (core_info[i].data) { unsigned count = 0; config_get_string(core_info[i].data, "display_name", &core_info[i].display_name); config_get_string(core_info[i].data, "corename", &core_info[i].core_name); config_get_string(core_info[i].data, "systemname", &core_info[i].systemname); config_get_string(core_info[i].data, "manufacturer", &core_info[i].system_manufacturer); config_get_uint(core_info[i].data, "firmware_count", &count); core_info[i].firmware_count = count; if (config_get_string(core_info[i].data, "supported_extensions", &core_info[i].supported_extensions) && core_info[i].supported_extensions) core_info[i].supported_extensions_list = string_split(core_info[i].supported_extensions, "|"); if (config_get_string(core_info[i].data, "authors", &core_info[i].authors) && core_info[i].authors) core_info[i].authors_list = string_split(core_info[i].authors, "|"); if (config_get_string(core_info[i].data, "permissions", &core_info[i].permissions) && core_info[i].permissions) core_info[i].permissions_list = string_split(core_info[i].permissions, "|"); if (config_get_string(core_info[i].data, "license", &core_info[i].licenses) && core_info[i].licenses) core_info[i].licenses_list = string_split(core_info[i].licenses, "|"); if (config_get_string(core_info[i].data, "categories", &core_info[i].categories) && core_info[i].categories) core_info[i].categories_list = string_split(core_info[i].categories, "|"); if (config_get_string(core_info[i].data, "database", &core_info[i].databases) && core_info[i].databases) core_info[i].databases_list = string_split(core_info[i].databases, "|"); if (config_get_string(core_info[i].data, "notes", &core_info[i].notes) && core_info[i].notes) core_info[i].note_list = string_split(core_info[i].notes, "|"); config_get_bool(core_info[i].data, "supports_no_game", &core_info[i].supports_no_game); } if (!core_info[i].display_name) core_info[i].display_name = strdup(path_basename(core_info[i].path)); } core_info_list_resolve_all_extensions(core_info_list); core_info_list_resolve_all_firmware(core_info_list); dir_list_free(contents); return core_info_list; error: if (contents) dir_list_free(contents); core_info_list_free(core_info_list); return NULL; }
static bool ffmpeg_init_config(struct ff_config_param *params, const char *config) { struct config_file_entry entry; char pix_fmt[64] = {0}; params->out_pix_fmt = PIX_FMT_NONE; params->scale_factor = 1; params->threads = 1; params->frame_drop_ratio = 1; if (!config) return true; params->conf = config_file_new(config); if (!params->conf) { RARCH_ERR("Failed to load FFmpeg config \"%s\".\n", config); return false; } config_get_array(params->conf, "vcodec", params->vcodec, sizeof(params->vcodec)); config_get_array(params->conf, "acodec", params->acodec, sizeof(params->acodec)); config_get_array(params->conf, "format", params->format, sizeof(params->format)); config_get_uint(params->conf, "threads", ¶ms->threads); if (!config_get_uint(params->conf, "frame_drop_ratio", ¶ms->frame_drop_ratio) || !params->frame_drop_ratio) params->frame_drop_ratio = 1; if (!config_get_bool(params->conf, "audio_enable", ¶ms->audio_enable)) params->audio_enable = true; config_get_uint(params->conf, "sample_rate", ¶ms->sample_rate); config_get_uint(params->conf, "scale_factor", ¶ms->scale_factor); params->audio_qscale = config_get_int(params->conf, "audio_global_quality", ¶ms->audio_global_quality); config_get_int(params->conf, "audio_bit_rate", ¶ms->audio_bit_rate); params->video_qscale = config_get_int(params->conf, "video_global_quality", ¶ms->video_global_quality); config_get_int(params->conf, "video_bit_rate", ¶ms->video_bit_rate); if (config_get_array(params->conf, "pix_fmt", pix_fmt, sizeof(pix_fmt))) { params->out_pix_fmt = av_get_pix_fmt(pix_fmt); if (params->out_pix_fmt == PIX_FMT_NONE) { RARCH_ERR("Cannot find pix_fmt \"%s\".\n", pix_fmt); return false; } } if (!config_get_entry_list_head(params->conf, &entry)) return true; do { if (strstr(entry.key, "video_") == entry.key) { const char *key = entry.key + strlen("video_"); av_dict_set(¶ms->video_opts, key, entry.value, 0); } else if (strstr(entry.key, "audio_") == entry.key) { const char *key = entry.key + strlen("audio_"); av_dict_set(¶ms->audio_opts, key, entry.value, 0); } } while (config_get_entry_list_next(&entry)); return true; }
bool config_load_file(const char *path) { config_file_t *conf = NULL; if (path) { conf = config_file_new(path); if (!conf) return false; } else conf = open_default_config_file(); if (conf == NULL) return true; char *save; char tmp_append_path[PATH_MAX]; // Don't destroy append_config_path. strlcpy(tmp_append_path, g_extern.append_config_path, sizeof(tmp_append_path)); const char *extra_path = strtok_r(tmp_append_path, ",", &save); while (extra_path) { RARCH_LOG("Appending config \"%s\"\n", extra_path); bool ret = config_append_file(conf, extra_path); if (!ret) RARCH_ERR("Failed to append config \"%s\"\n", extra_path); extra_path = strtok_r(NULL, ";", &save); } if (g_extern.verbose) { RARCH_LOG_OUTPUT("=== Config ===\n"); config_file_dump_all(conf, stderr); RARCH_LOG_OUTPUT("=== Config end ===\n"); } char tmp_str[PATH_MAX]; CONFIG_GET_FLOAT(video.xscale, "video_xscale"); CONFIG_GET_FLOAT(video.yscale, "video_yscale"); CONFIG_GET_INT(video.fullscreen_x, "video_fullscreen_x"); CONFIG_GET_INT(video.fullscreen_y, "video_fullscreen_y"); if (!g_extern.force_fullscreen) CONFIG_GET_BOOL(video.fullscreen, "video_fullscreen"); CONFIG_GET_BOOL(video.windowed_fullscreen, "video_windowed_fullscreen"); CONFIG_GET_INT(video.monitor_index, "video_monitor_index"); CONFIG_GET_BOOL(video.disable_composition, "video_disable_composition"); CONFIG_GET_BOOL(video.vsync, "video_vsync"); CONFIG_GET_BOOL(video.smooth, "video_smooth"); CONFIG_GET_BOOL(video.force_aspect, "video_force_aspect"); CONFIG_GET_BOOL(video.scale_integer, "video_scale_integer"); CONFIG_GET_BOOL(video.crop_overscan, "video_crop_overscan"); CONFIG_GET_FLOAT(video.aspect_ratio, "video_aspect_ratio"); CONFIG_GET_BOOL(video.aspect_ratio_auto, "video_aspect_ratio_auto"); CONFIG_GET_FLOAT(video.refresh_rate, "video_refresh_rate"); CONFIG_GET_PATH(video.cg_shader_path, "video_cg_shader"); CONFIG_GET_PATH(video.bsnes_shader_path, "video_bsnes_shader"); CONFIG_GET_PATH(video.second_pass_shader, "video_second_pass_shader"); CONFIG_GET_BOOL(video.render_to_texture, "video_render_to_texture"); CONFIG_GET_FLOAT(video.fbo.scale_x, "video_fbo_scale_x"); CONFIG_GET_FLOAT(video.fbo.scale_y, "video_fbo_scale_y"); CONFIG_GET_BOOL(video.second_pass_smooth, "video_second_pass_smooth"); CONFIG_GET_BOOL(video.allow_rotate, "video_allow_rotate"); CONFIG_GET_PATH(video.font_path, "video_font_path"); CONFIG_GET_FLOAT(video.font_size, "video_font_size"); CONFIG_GET_BOOL(video.font_enable, "video_font_enable"); CONFIG_GET_BOOL(video.font_scale, "video_font_scale"); CONFIG_GET_FLOAT(video.msg_pos_x, "video_message_pos_x"); CONFIG_GET_FLOAT(video.msg_pos_y, "video_message_pos_y"); #ifdef RARCH_CONSOLE /* TODO - will be refactored later to make it more clean - it's more * important that it works for consoles right now */ CONFIG_GET_INT(video.aspect_ratio_idx, "aspect_ratio_index"); CONFIG_GET_FLOAT(video.aspect_ratio, "video_aspect_ratio"); for (unsigned i = 0; i < MAX_PLAYERS; i++) { char cfg[64]; snprintf(cfg, sizeof(cfg), "input_dpad_emulation_p%u", i + 1); CONFIG_GET_INT(input.dpad_emulation[i], cfg); snprintf(cfg, sizeof(cfg), "input_device_p%u", i + 1); CONFIG_GET_INT(input.device[i], cfg); } #ifdef ANDROID CONFIG_GET_INT(input.icade_profile[0], "input_autodetect_icade_profile_pad1"); CONFIG_GET_INT(input.icade_profile[1], "input_autodetect_icade_profile_pad2"); CONFIG_GET_INT(input.icade_profile[2], "input_autodetect_icade_profile_pad3"); CONFIG_GET_INT(input.icade_profile[3], "input_autodetect_icade_profile_pad4"); #endif CONFIG_GET_BOOL_EXTERN(console.screen.gamma_correction, "gamma_correction"); bool msg_enable = false; bool throttle_enable = false; bool triple_buffering_enable = false; bool custom_bgm_enable = false; bool overscan_enable = false; bool screenshots_enable = false; bool flicker_filter_enable = false; bool soft_filter_enable = false; bool sram_dir_enable = false; bool state_dir_enable = false; if (config_get_path(conf, "default_rom_startup_dir", tmp_str, sizeof(tmp_str))) strlcpy(g_extern.console.main_wrap.default_rom_startup_dir, tmp_str, sizeof(g_extern.console.main_wrap.default_rom_startup_dir)); if (config_get_path(conf, "menu_texture_path", tmp_str, sizeof(tmp_str))) strlcpy(g_extern.console.menu_texture_path, tmp_str, sizeof(g_extern.console.menu_texture_path)); if (config_get_bool(conf, "info_msg_enable", &msg_enable)) { if (msg_enable) g_extern.lifecycle_mode_state |= (1ULL << MODE_INFO_DRAW); else g_extern.lifecycle_mode_state &= ~(1ULL << MODE_INFO_DRAW); } if (config_get_bool(conf, "throttle_enable", &throttle_enable)) { if (throttle_enable) g_extern.lifecycle_mode_state |= (1ULL << MODE_VIDEO_THROTTLE_ENABLE); else g_extern.lifecycle_mode_state &= ~(1ULL << MODE_VIDEO_THROTTLE_ENABLE); } if (config_get_bool(conf, "triple_buffering_enable", &triple_buffering_enable)) { if (triple_buffering_enable) g_extern.lifecycle_mode_state |= (1ULL << MODE_VIDEO_TRIPLE_BUFFERING_ENABLE); else g_extern.lifecycle_mode_state &= ~(1ULL << MODE_VIDEO_TRIPLE_BUFFERING_ENABLE); } if (config_get_bool(conf, "overscan_enable", &overscan_enable)) { if (overscan_enable) g_extern.lifecycle_mode_state |= (1ULL << MODE_VIDEO_OVERSCAN_ENABLE); else g_extern.lifecycle_mode_state &= ~(1ULL << MODE_VIDEO_OVERSCAN_ENABLE); } if (config_get_bool(conf, "custom_bgm_enable", &custom_bgm_enable)) { if (custom_bgm_enable) g_extern.lifecycle_mode_state |= (1ULL << MODE_AUDIO_CUSTOM_BGM_ENABLE); else g_extern.lifecycle_mode_state &= ~(1ULL << MODE_AUDIO_CUSTOM_BGM_ENABLE); } if (config_get_bool(conf, "screenshots_enable", &screenshots_enable)) { if (screenshots_enable) g_extern.lifecycle_mode_state |= (1ULL << MODE_VIDEO_SCREENSHOTS_ENABLE); else g_extern.lifecycle_mode_state &= ~(1ULL << MODE_VIDEO_SCREENSHOTS_ENABLE); } if (config_get_bool(conf, "flicker_filter_enable", &flicker_filter_enable)) { if (flicker_filter_enable) g_extern.lifecycle_mode_state |= (1ULL << MODE_VIDEO_FLICKER_FILTER_ENABLE); else g_extern.lifecycle_mode_state &= ~(1ULL << MODE_VIDEO_FLICKER_FILTER_ENABLE); } if (config_get_bool(conf, "soft_filter_enable", &soft_filter_enable)) { if (soft_filter_enable) g_extern.lifecycle_mode_state |= (1ULL << MODE_VIDEO_SOFT_FILTER_ENABLE); else g_extern.lifecycle_mode_state &= ~(1ULL << MODE_VIDEO_SOFT_FILTER_ENABLE); } if (config_get_bool(conf, "sram_dir_enable", &sram_dir_enable)) { if (sram_dir_enable) g_extern.lifecycle_mode_state |= (1ULL << MODE_LOAD_GAME_SRAM_DIR_ENABLE); else g_extern.lifecycle_mode_state &= ~(1ULL << MODE_LOAD_GAME_SRAM_DIR_ENABLE); } if (config_get_bool(conf, "savestate_dir_enable", &state_dir_enable)) { if (state_dir_enable) g_extern.lifecycle_mode_state |= (1ULL << MODE_LOAD_GAME_STATE_DIR_ENABLE); else g_extern.lifecycle_mode_state &= ~(1ULL << MODE_LOAD_GAME_STATE_DIR_ENABLE); } CONFIG_GET_FLOAT_EXTERN(console.screen.overscan_amount, "overscan_amount"); CONFIG_GET_INT_EXTERN(console.screen.flicker_filter_index, "flicker_filter_index"); CONFIG_GET_INT_EXTERN(console.screen.soft_filter_index, "soft_filter_index"); #ifdef _XBOX1 CONFIG_GET_INT_EXTERN(console.sound.volume_level, "sound_volume_level"); #endif CONFIG_GET_INT_EXTERN(console.screen.resolutions.current.id, "current_resolution_id"); CONFIG_GET_INT_EXTERN(state_slot, "state_slot"); CONFIG_GET_INT_EXTERN(audio_data.mute, "audio_mute"); CONFIG_GET_INT_EXTERN(console.screen.orientation, "screen_orientation"); CONFIG_GET_INT_EXTERN(console.sound.mode, "sound_mode"); CONFIG_GET_INT_EXTERN(console.screen.viewports.custom_vp.x, "custom_viewport_x"); CONFIG_GET_INT_EXTERN(console.screen.viewports.custom_vp.y, "custom_viewport_y"); CONFIG_GET_INT_EXTERN(console.screen.viewports.custom_vp.width, "custom_viewport_width"); CONFIG_GET_INT_EXTERN(console.screen.viewports.custom_vp.height, "custom_viewport_height"); #endif unsigned msg_color = 0; if (config_get_hex(conf, "video_message_color", &msg_color)) { g_settings.video.msg_color_r = ((msg_color >> 16) & 0xff) / 255.0f; g_settings.video.msg_color_g = ((msg_color >> 8) & 0xff) / 255.0f; g_settings.video.msg_color_b = ((msg_color >> 0) & 0xff) / 255.0f; }
void OBSProjector::UpdateMultiview() { multiviewScenes.clear(); multiviewLabels.clear(); struct obs_video_info ovi; obs_get_video_info(&ovi); uint32_t w = ovi.base_width; uint32_t h = ovi.base_height; fw = float(w); fh = float(h); ratio = fw / fh; struct obs_frontend_source_list scenes = {}; obs_frontend_get_scenes(&scenes); multiviewLabels.emplace_back(CreateLabel(Str("StudioMode.Preview"), h / 2)); multiviewLabels.emplace_back(CreateLabel(Str("StudioMode.Program"), h / 2)); multiviewLayout = static_cast<MultiviewLayout>(config_get_int( GetGlobalConfig(), "BasicWindow", "MultiviewLayout")); drawLabel = config_get_bool(GetGlobalConfig(), "BasicWindow", "MultiviewDrawNames"); drawSafeArea = config_get_bool(GetGlobalConfig(), "BasicWindow", "MultiviewDrawAreas"); mouseSwitching = config_get_bool(GetGlobalConfig(), "BasicWindow", "MultiviewMouseSwitch"); transitionOnDoubleClick = config_get_bool(GetGlobalConfig(), "BasicWindow", "TransitionOnDoubleClick"); switch(multiviewLayout) { case MultiviewLayout::HORIZONTAL_TOP_24_SCENES: pvwprgCX = fw / 3; pvwprgCY = fh / 3; maxSrcs = 24; break; default: pvwprgCX = fw / 2; pvwprgCY = fh / 2; maxSrcs = 8; } ppiCX = pvwprgCX - thicknessx2; ppiCY = pvwprgCY - thicknessx2; ppiScaleX = (pvwprgCX - thicknessx2) / fw; ppiScaleY = (pvwprgCY - thicknessx2) / fh; scenesCX = pvwprgCX / 2; scenesCY = pvwprgCY / 2; siCX = scenesCX - thicknessx2; siCY = scenesCY - thicknessx2; siScaleX = (scenesCX - thicknessx2) / fw; siScaleY = (scenesCY - thicknessx2) / fh; numSrcs = 0; size_t i = 0; while (i < scenes.sources.num && numSrcs < maxSrcs) { obs_source_t *src = scenes.sources.array[i++]; OBSData data = obs_source_get_private_settings(src); obs_data_release(data); obs_data_set_default_bool(data, "show_in_multiview", true); if (!obs_data_get_bool(data, "show_in_multiview")) continue; // We have a displayable source. numSrcs++; multiviewScenes.emplace_back(OBSGetWeakRef(src)); obs_source_inc_showing(src); std::string name = std::to_string(numSrcs) + " - " + obs_source_get_name(src); multiviewLabels.emplace_back(CreateLabel(name.c_str(), h / 3)); } obs_frontend_source_list_free(&scenes); }
static bool get_trace_config_enabled(void) { return config_get_bool(config, CONFIG_DEFAULT_SECTION, TRACE_CONFIG_ENABLED_KEY, false); }
// CGP static bool shader_parse_pass(config_file_t *conf, struct gfx_shader_pass *pass, unsigned i) { // Source char shader_name[64]; print_buf(shader_name, "shader%u", i); if (!config_get_path(conf, shader_name, pass->source.path, sizeof(pass->source.path))) { RARCH_ERR("Couldn't parse shader source (%s).\n", shader_name); return false; } // Smooth char filter_name_buf[64]; print_buf(filter_name_buf, "filter_linear%u", i); bool smooth = false; if (config_get_bool(conf, filter_name_buf, &smooth)) pass->filter = smooth ? RARCH_FILTER_LINEAR : RARCH_FILTER_NEAREST; else pass->filter = RARCH_FILTER_UNSPEC; // Wrapping mode char wrap_name_buf[64]; print_buf(wrap_name_buf, "wrap_mode%u", i); char wrap_mode[64]; if (config_get_array(conf, wrap_name_buf, wrap_mode, sizeof(wrap_mode))) pass->wrap = wrap_str_to_mode(wrap_mode); // Frame count mod char frame_count_mod[64] = {0}; char frame_count_mod_buf[64]; print_buf(frame_count_mod_buf, "frame_count_mod%u", i); if (config_get_array(conf, frame_count_mod_buf, frame_count_mod, sizeof(frame_count_mod))) pass->frame_count_mod = strtoul(frame_count_mod, NULL, 0); // FBO types and mipmapping char srgb_output_buf[64]; print_buf(srgb_output_buf, "srgb_framebuffer%u", i); config_get_bool(conf, srgb_output_buf, &pass->fbo.srgb_fbo); char fp_fbo_buf[64]; print_buf(fp_fbo_buf, "float_framebuffer%u", i); config_get_bool(conf, fp_fbo_buf, &pass->fbo.fp_fbo); char mipmap_buf[64]; print_buf(mipmap_buf, "mipmap_input%u", i); config_get_bool(conf, mipmap_buf, &pass->mipmap); // Scale struct gfx_fbo_scale *scale = &pass->fbo; char scale_type[64] = {0}; char scale_type_x[64] = {0}; char scale_type_y[64] = {0}; char scale_name_buf[64]; print_buf(scale_name_buf, "scale_type%u", i); config_get_array(conf, scale_name_buf, scale_type, sizeof(scale_type)); print_buf(scale_name_buf, "scale_type_x%u", i); config_get_array(conf, scale_name_buf, scale_type_x, sizeof(scale_type_x)); print_buf(scale_name_buf, "scale_type_y%u", i); config_get_array(conf, scale_name_buf, scale_type_y, sizeof(scale_type_y)); if (!*scale_type && !*scale_type_x && !*scale_type_y) return true; if (*scale_type) { strlcpy(scale_type_x, scale_type, sizeof(scale_type_x)); strlcpy(scale_type_y, scale_type, sizeof(scale_type_y)); } char attr_name_buf[64]; float fattr = 0.0f; int iattr = 0; scale->valid = true; scale->type_x = RARCH_SCALE_INPUT; scale->type_y = RARCH_SCALE_INPUT; scale->scale_x = 1.0; scale->scale_y = 1.0; if (*scale_type_x) { if (strcmp(scale_type_x, "source") == 0) scale->type_x = RARCH_SCALE_INPUT; else if (strcmp(scale_type_x, "viewport") == 0) scale->type_x = RARCH_SCALE_VIEWPORT; else if (strcmp(scale_type_x, "absolute") == 0) scale->type_x = RARCH_SCALE_ABSOLUTE; else { RARCH_ERR("Invalid attribute.\n"); return false; } } if (*scale_type_y) { if (strcmp(scale_type_y, "source") == 0) scale->type_y = RARCH_SCALE_INPUT; else if (strcmp(scale_type_y, "viewport") == 0) scale->type_y = RARCH_SCALE_VIEWPORT; else if (strcmp(scale_type_y, "absolute") == 0) scale->type_y = RARCH_SCALE_ABSOLUTE; else { RARCH_ERR("Invalid attribute.\n"); return false; } } if (scale->type_x == RARCH_SCALE_ABSOLUTE) { print_buf(attr_name_buf, "scale%u", i); if (config_get_int(conf, attr_name_buf, &iattr)) scale->abs_x = iattr; else { print_buf(attr_name_buf, "scale_x%u", i); if (config_get_int(conf, attr_name_buf, &iattr)) scale->abs_x = iattr; } } else { print_buf(attr_name_buf, "scale%u", i); if (config_get_float(conf, attr_name_buf, &fattr)) scale->scale_x = fattr; else { print_buf(attr_name_buf, "scale_x%u", i); if (config_get_float(conf, attr_name_buf, &fattr)) scale->scale_x = fattr; } } if (scale->type_y == RARCH_SCALE_ABSOLUTE) { print_buf(attr_name_buf, "scale%u", i); if (config_get_int(conf, attr_name_buf, &iattr)) scale->abs_y = iattr; else { print_buf(attr_name_buf, "scale_y%u", i); if (config_get_int(conf, attr_name_buf, &iattr)) scale->abs_y = iattr; } } else { print_buf(attr_name_buf, "scale%u", i); if (config_get_float(conf, attr_name_buf, &fattr)) scale->scale_y = fattr; else { print_buf(attr_name_buf, "scale_y%u", i); if (config_get_float(conf, attr_name_buf, &fattr)) scale->scale_y = fattr; } } return true; }
static bool get_btsnoop_turned_on(void) { return config_get_bool(config, CONFIG_DEFAULT_SECTION, BTSNOOP_TURNED_ON_KEY, false); }
static bool get_btsnoop_should_save_last(void) { return config_get_bool(config, CONFIG_DEFAULT_SECTION, BTSNOOP_SHOULD_SAVE_LAST_KEY, false); }
static core_info_list_t *core_info_list_new(void) { size_t i; core_info_t *core_info = NULL; core_info_list_t *core_info_list = NULL; struct string_list *contents = NULL; settings_t *settings = config_get_ptr(); if (!settings) return NULL; contents = dir_list_new_special( settings->directory.libretro, DIR_LIST_CORES, NULL); if (!contents) return NULL; core_info_list = (core_info_list_t*)calloc(1, sizeof(*core_info_list)); if (!core_info_list) goto error; core_info = (core_info_t*)calloc(contents->size, sizeof(*core_info)); if (!core_info) goto error; core_info_list->list = core_info; core_info_list->count = contents->size; for (i = 0; i < contents->size; i++) { config_file_t *conf = core_info_list_iterate(contents, i); if (conf) { bool tmp_bool = false; unsigned count = 0; config_get_string(conf, "display_name", &core_info[i].display_name); config_get_string(conf, "corename", &core_info[i].core_name); config_get_string(conf, "systemname", &core_info[i].systemname); config_get_string(conf, "manufacturer", &core_info[i].system_manufacturer); config_get_uint(conf, "firmware_count", &count); core_info[i].firmware_count = count; if (config_get_string(conf, "supported_extensions", &core_info[i].supported_extensions) && core_info[i].supported_extensions) core_info[i].supported_extensions_list = string_split(core_info[i].supported_extensions, "|"); if (config_get_string(conf, "authors", &core_info[i].authors) && core_info[i].authors) core_info[i].authors_list = string_split(core_info[i].authors, "|"); if (config_get_string(conf, "permissions", &core_info[i].permissions) && core_info[i].permissions) core_info[i].permissions_list = string_split(core_info[i].permissions, "|"); if (config_get_string(conf, "license", &core_info[i].licenses) && core_info[i].licenses) core_info[i].licenses_list = string_split(core_info[i].licenses, "|"); if (config_get_string(conf, "categories", &core_info[i].categories) && core_info[i].categories) core_info[i].categories_list = string_split(core_info[i].categories, "|"); if (config_get_string(conf, "database", &core_info[i].databases) && core_info[i].databases) core_info[i].databases_list = string_split(core_info[i].databases, "|"); if (config_get_string(conf, "notes", &core_info[i].notes) && core_info[i].notes) core_info[i].note_list = string_split(core_info[i].notes, "|"); if (config_get_bool(conf, "supports_no_game", &tmp_bool)) core_info[i].supports_no_game = tmp_bool; core_info[i].config_data = conf; } core_info[i].path = strdup(contents->elems[i].data); if (!core_info[i].display_name) core_info[i].display_name = strdup(path_basename(core_info[i].path)); } core_info_list_resolve_all_extensions(core_info_list); core_info_list_resolve_all_firmware(core_info_list); dir_list_free(contents); return core_info_list; error: if (contents) dir_list_free(contents); core_info_list_free(core_info_list); return NULL; }
/** recursively read the menu hierarchy */ MenuEntry *menu_read(MenuEntry *parent, const char *name) { static int id = 0; if ((name != NULL) && (config_has_section(name))) { MenuEntry *me = calloc(1, sizeof(MenuEntry)); // auto-NULL elements if (me == NULL) return NULL; // set common entries me->id = id++; me->name = strdup(name); if (me->name == NULL) { //menu_free(me); return NULL; } me->displayname = strdup(config_get_string(name, "DisplayName", 0, name)); if (me->displayname == NULL) { //menu_free(me); return NULL; } me->parent = parent; me->next = NULL; me->children = NULL; me->numChildren = 0; if (config_get_string(name, "Entry", 0, NULL) != NULL) { MenuEntry **addr = &me->children; const char *entryname; // it is a sub-menu me->type = MT_MENU; // read menu entries while ((entryname = config_get_string(name, "Entry", me->numChildren, NULL)) != NULL) { MenuEntry *entry = menu_read(me, entryname); if (entry == NULL) { //menu_free(me); return NULL; } me->numChildren++; *addr = entry; addr = &entry->next; } } else if (config_get_string(name, "Exec", 0, NULL) != NULL) { MenuEntry **addr = &me->children; const char *entryname; // it's a command to execute me->type = MT_EXEC; me->data.exec.command = strdup(config_get_string(name, "Exec", 0, "")); if (me->data.exec.command == NULL) { //menu_free(me); return NULL; } me->data.exec.feedback = config_get_bool(name, "Feedback", 0, 0); // try to read parameters while ((entryname = config_get_string(name, "Parameter", me->numChildren, NULL)) != NULL) { MenuEntry *entry = menu_read(me, entryname); if (entry == NULL) { //menu_free(me); return NULL; } me->numChildren++; *addr = entry; addr = &entry->next; } // automagically add an "Apply ?" action if ((me->numChildren > 0) && (addr != NULL)) *addr = menu_read(me, NULL); } else if (config_get_string(name, "Type", 0, NULL) != NULL) { // it's a command parameter const char *type; type = config_get_string(name, "Type", 0, ""); if (strcasecmp(type, "slider") == 0) { char buf[35]; me->type = MT_ARG_SLIDER; me->data.slider.value = config_get_int(name, "Value", 0, 0); me->data.slider.minval = config_get_int(name, "MinValue", 0, 0); me->data.slider.maxval = config_get_int(name, "MaxValue", 0, 1000); sprintf(buf, "%d", me->data.slider.minval); me->data.slider.mintext = strdup(config_get_string(name, "MinText", 0, buf)); sprintf(buf, "%d", me->data.slider.maxval); me->data.slider.maxtext = strdup(config_get_string(name, "MaxText", 0, buf)); me->data.slider.stepsize = config_get_int(name, "StepSize", 0, 1); } else if (strcasecmp(type, "ring") == 0) { const char *tmp; int numStrings = 0; int i = 0; me->type = MT_ARG_RING; me->data.ring.value = config_get_int(name, "Value", 0, 0); numStrings = config_has_key(name, "String"); me->data.ring.strings = calloc(sizeof(char *), numStrings+1); me->data.ring.strings[numStrings] = NULL; while ((tmp = config_get_string(name, "String", i, NULL)) != NULL) { me->data.ring.strings[i] = strdup(tmp); i++; } me->data.ring.strings[i] = NULL; } else if (strcasecmp(type, "numeric") == 0) { me->type = MT_ARG_NUMERIC; me->data.numeric.value = config_get_int(name, "Value", 0, 0); me->data.numeric.minval = config_get_int(name, "MinValue", 0, 0); me->data.numeric.maxval = config_get_int(name, "MaxValue", 0, 1000); } else if (strcasecmp(type, "alpha") == 0) { me->type = MT_ARG_ALPHA; me->data.alpha.value = strdup(config_get_string(name, "Value", 0, "")); me->data.alpha.minlen = config_get_int(name, "MinLength", 0, 0); me->data.alpha.maxlen = config_get_int(name, "MaxLength", 0, 100); me->data.alpha.allowed = strdup(config_get_string(name, "AllowedChars", 0, "ABCDEFGHIJKLMNOPQRSTUVWXYZ")); } else if (strcasecmp(type, "ip") == 0) { me->type = MT_ARG_IP; me->data.ip.value = strdup(config_get_string(name, "Value", 0, "")); me->data.ip.v6 = config_get_bool(name, "Value", 0, 0); } else if (strcasecmp(type, "checkbox") == 0) { const char *tmp; me->type = MT_ARG_CHECKBOX; me->data.checkbox.allow_gray = config_get_bool(name, "AllowGray", 0, 0); me->data.checkbox.value = (me->data.checkbox.allow_gray) ? config_get_tristate(name, "Value", 0, "gray", 0) : config_get_bool(name, "Value", 0, 0); // get replacement strings for different values tmp = config_get_string(name, "OffText", 0, NULL); me->data.checkbox.map[0] = (tmp != NULL) ? strdup(tmp) : NULL; tmp = config_get_string(name, "OnText", 0, NULL); me->data.checkbox.map[1] = (tmp != NULL) ? strdup(tmp) : NULL; tmp = config_get_string(name, "GrayText", 0, NULL); me->data.checkbox.map[2] = (tmp != NULL) ? strdup(tmp) : NULL; } else { report(RPT_DEBUG, "illegal parameter type"); //menu_free(me); return NULL; } } else { report(RPT_DEBUG, "unknown menu entry type"); //menu_free(me); return NULL; } return me; } else { /* the magic stuff: if name is NULL and parent is an EXEC entry, * then generate an Action entry with the name "Apply" */ if ((name == NULL) && (parent != NULL) && (parent->type = MT_EXEC)) { MenuEntry *me = calloc(1, sizeof(MenuEntry)); // auto-NULL elements if (me == NULL) return NULL; // set common entries me->id = id++; me->name = malloc(strlen(parent->name) + 10); if (me->name == NULL) { //menu_free(me); return NULL; } strcpy(me->name, "Apply_"); strcat(me->name, parent->name); me->displayname = strdup("Apply!"); if (me->displayname == NULL) { //menu_free(me); return NULL; } me->parent = parent; me->next = NULL; me->children = NULL; me->numChildren = 0; me->type = MT_ARG_ACTION | MT_AUTOMATIC; return me; } } return NULL; }
/** * video_shader_parse_pass: * @conf : Preset file to read from. * @pass : Shader passes handle. * @i : Index of shader pass. * * Parses shader pass from preset file. * * Returns: true (1) if successful, otherwise false (0). **/ static bool video_shader_parse_pass(config_file_t *conf, struct video_shader_pass *pass, unsigned i) { char shader_name[64]; char filter_name_buf[64]; char wrap_name_buf[64]; char wrap_mode[64]; char frame_count_mod_buf[64]; char srgb_output_buf[64]; char fp_fbo_buf[64]; char mipmap_buf[64]; char alias_buf[64]; char scale_name_buf[64]; char attr_name_buf[64]; char scale_type[64]; char scale_type_x[64]; char scale_type_y[64]; char frame_count_mod[64]; size_t path_size = PATH_MAX_LENGTH * sizeof(char); char *tmp_str = (char*)malloc(PATH_MAX_LENGTH * sizeof(char)); char *tmp_path = NULL; struct gfx_fbo_scale *scale = NULL; bool tmp_bool = false; float fattr = 0.0f; int iattr = 0; fp_fbo_buf[0] = mipmap_buf[0] = alias_buf[0] = scale_name_buf[0] = attr_name_buf[0] = scale_type[0] = scale_type_x[0] = scale_type_y[0] = frame_count_mod[0] = tmp_str[0] = shader_name[0] = filter_name_buf[0] = wrap_name_buf[0] = wrap_mode[0] = frame_count_mod_buf[0] = '\0'; srgb_output_buf[0] = '\0'; /* Source */ snprintf(shader_name, sizeof(shader_name), "shader%u", i); if (!config_get_path(conf, shader_name, tmp_str, path_size)) { RARCH_ERR("Couldn't parse shader source (%s).\n", shader_name); goto error; } tmp_path = (char*)malloc(PATH_MAX_LENGTH * sizeof(char)); strlcpy(tmp_path, tmp_str, path_size); path_resolve_realpath(tmp_path, path_size); if (!filestream_exists(tmp_path)) strlcpy(pass->source.path, tmp_str, sizeof(pass->source.path)); else strlcpy(pass->source.path, tmp_path, sizeof(pass->source.path)); free(tmp_path); /* Smooth */ snprintf(filter_name_buf, sizeof(filter_name_buf), "filter_linear%u", i); if (config_get_bool(conf, filter_name_buf, &tmp_bool)) { bool smooth = tmp_bool; pass->filter = smooth ? RARCH_FILTER_LINEAR : RARCH_FILTER_NEAREST; } else pass->filter = RARCH_FILTER_UNSPEC; /* Wrapping mode */ snprintf(wrap_name_buf, sizeof(wrap_name_buf), "wrap_mode%u", i); if (config_get_array(conf, wrap_name_buf, wrap_mode, sizeof(wrap_mode))) pass->wrap = wrap_str_to_mode(wrap_mode); /* Frame count mod */ snprintf(frame_count_mod_buf, sizeof(frame_count_mod_buf), "frame_count_mod%u", i); if (config_get_array(conf, frame_count_mod_buf, frame_count_mod, sizeof(frame_count_mod))) pass->frame_count_mod = (unsigned)strtoul(frame_count_mod, NULL, 0); /* FBO types and mipmapping */ snprintf(srgb_output_buf, sizeof(srgb_output_buf), "srgb_framebuffer%u", i); if (config_get_bool(conf, srgb_output_buf, &tmp_bool)) pass->fbo.srgb_fbo = tmp_bool; snprintf(fp_fbo_buf, sizeof(fp_fbo_buf), "float_framebuffer%u", i); if (config_get_bool(conf, fp_fbo_buf, &tmp_bool)) pass->fbo.fp_fbo = tmp_bool; snprintf(mipmap_buf, sizeof(mipmap_buf), "mipmap_input%u", i); if (config_get_bool(conf, mipmap_buf, &tmp_bool)) pass->mipmap = tmp_bool; snprintf(alias_buf, sizeof(alias_buf), "alias%u", i); if (!config_get_array(conf, alias_buf, pass->alias, sizeof(pass->alias))) *pass->alias = '\0'; /* Scale */ scale = &pass->fbo; snprintf(scale_name_buf, sizeof(scale_name_buf), "scale_type%u", i); config_get_array(conf, scale_name_buf, scale_type, sizeof(scale_type)); snprintf(scale_name_buf, sizeof(scale_name_buf), "scale_type_x%u", i); config_get_array(conf, scale_name_buf, scale_type_x, sizeof(scale_type_x)); snprintf(scale_name_buf, sizeof(scale_name_buf), "scale_type_y%u", i); config_get_array(conf, scale_name_buf, scale_type_y, sizeof(scale_type_y)); if (!*scale_type && !*scale_type_x && !*scale_type_y) { free(tmp_str); return true; } if (*scale_type) { strlcpy(scale_type_x, scale_type, sizeof(scale_type_x)); strlcpy(scale_type_y, scale_type, sizeof(scale_type_y)); } scale->valid = true; scale->type_x = RARCH_SCALE_INPUT; scale->type_y = RARCH_SCALE_INPUT; scale->scale_x = 1.0; scale->scale_y = 1.0; if (*scale_type_x) { if (string_is_equal(scale_type_x, "source")) scale->type_x = RARCH_SCALE_INPUT; else if (string_is_equal(scale_type_x, "viewport")) scale->type_x = RARCH_SCALE_VIEWPORT; else if (string_is_equal(scale_type_x, "absolute")) scale->type_x = RARCH_SCALE_ABSOLUTE; else { RARCH_ERR("Invalid attribute.\n"); goto error; } } if (*scale_type_y) { if (string_is_equal(scale_type_y, "source")) scale->type_y = RARCH_SCALE_INPUT; else if (string_is_equal(scale_type_y, "viewport")) scale->type_y = RARCH_SCALE_VIEWPORT; else if (string_is_equal(scale_type_y, "absolute")) scale->type_y = RARCH_SCALE_ABSOLUTE; else { RARCH_ERR("Invalid attribute.\n"); goto error; } } snprintf(attr_name_buf, sizeof(attr_name_buf), "scale%u", i); if (scale->type_x == RARCH_SCALE_ABSOLUTE) { if (config_get_int(conf, attr_name_buf, &iattr)) scale->abs_x = iattr; else { snprintf(attr_name_buf, sizeof(attr_name_buf), "scale_x%u", i); if (config_get_int(conf, attr_name_buf, &iattr)) scale->abs_x = iattr; } } else { if (config_get_float(conf, attr_name_buf, &fattr)) scale->scale_x = fattr; else { snprintf(attr_name_buf, sizeof(attr_name_buf), "scale_x%u", i); if (config_get_float(conf, attr_name_buf, &fattr)) scale->scale_x = fattr; } } snprintf(attr_name_buf, sizeof(attr_name_buf), "scale%u", i); if (scale->type_y == RARCH_SCALE_ABSOLUTE) { if (config_get_int(conf, attr_name_buf, &iattr)) scale->abs_y = iattr; else { snprintf(attr_name_buf, sizeof(attr_name_buf), "scale_y%u", i); if (config_get_int(conf, attr_name_buf, &iattr)) scale->abs_y = iattr; } } else { if (config_get_float(conf, attr_name_buf, &fattr)) scale->scale_y = fattr; else { snprintf(attr_name_buf, sizeof(attr_name_buf), "scale_y%u", i); if (config_get_float(conf, attr_name_buf, &fattr)) scale->scale_y = fattr; } } free(tmp_str); return true; error: free(tmp_str); return false; }
static bool input_overlay_load_desc(input_overlay_t *ol, config_file_t *conf, struct overlay_desc *desc, unsigned ol_index, unsigned desc_index, unsigned width, unsigned height, bool normalized, float alpha_mod, float range_mod) { bool ret = true; char overlay_desc_key[64]; snprintf(overlay_desc_key, sizeof(overlay_desc_key), "overlay%u_desc%u", ol_index, desc_index); char overlay_desc_image_key[64]; snprintf(overlay_desc_image_key, sizeof(overlay_desc_image_key), "overlay%u_desc%u_overlay", ol_index, desc_index); char image_path[PATH_MAX]; if (config_get_path(conf, overlay_desc_image_key, image_path, sizeof(image_path))) { char path[PATH_MAX]; fill_pathname_resolve_relative(path, ol->overlay_path, image_path, sizeof(path)); struct texture_image img = {0}; if (texture_image_load(&img, path)) desc->image = img; } char overlay_desc_normalized_key[64]; snprintf(overlay_desc_normalized_key, sizeof(overlay_desc_normalized_key), "overlay%u_desc%u_normalized", ol_index, desc_index); config_get_bool(conf, overlay_desc_normalized_key, &normalized); bool by_pixel = !normalized; if (by_pixel && (width == 0 || height == 0)) { RARCH_ERR("[Overlay]: Base overlay is not set and not using normalized coordinates.\n"); return false; } char overlay[256]; if (!config_get_array(conf, overlay_desc_key, overlay, sizeof(overlay))) { RARCH_ERR("[Overlay]: Didn't find key: %s.\n", overlay_desc_key); return false; } struct string_list *list = string_split(overlay, ", "); if (!list) { RARCH_ERR("[Overlay]: Failed to split overlay desc.\n"); return false; } if (list->size < 6) { string_list_free(list); RARCH_ERR("[Overlay]: Overlay desc is invalid. Requires at least 6 tokens.\n"); return false; } const char *x = list->elems[1].data; const char *y = list->elems[2].data; const char *box = list->elems[3].data; char *key = list->elems[0].data; char *save; desc->key_mask = 0; if (strcmp(key, "analog_left") == 0) desc->type = OVERLAY_TYPE_ANALOG_LEFT; else if (strcmp(key, "analog_right") == 0) desc->type = OVERLAY_TYPE_ANALOG_RIGHT; else if (strstr(key, "retrok_") == key) { desc->type = OVERLAY_TYPE_KEYBOARD; desc->key_mask = input_translate_str_to_rk(key + 7); } else { const char *tmp; desc->type = OVERLAY_TYPE_BUTTONS; for (tmp = strtok_r(key, "|", &save); tmp; tmp = strtok_r(NULL, "|", &save)) { if (strcmp(tmp, "nul") != 0) desc->key_mask |= UINT64_C(1) << input_translate_str_to_bind_id(tmp); } if (desc->key_mask & (UINT64_C(1) << RARCH_OVERLAY_NEXT)) { char overlay_target_key[64]; snprintf(overlay_target_key, sizeof(overlay_target_key), "overlay%u_desc%u_next_target", ol_index, desc_index); config_get_array(conf, overlay_target_key, desc->next_index_name, sizeof(desc->next_index_name)); } } float width_mod = by_pixel ? (1.0f / width) : 1.0f; float height_mod = by_pixel ? (1.0f / height) : 1.0f; desc->x = (float)strtod(x, NULL) * width_mod; desc->y = (float)strtod(y, NULL) * height_mod; if (!strcmp(box, "radial")) desc->hitbox = OVERLAY_HITBOX_RADIAL; else if (!strcmp(box, "rect")) desc->hitbox = OVERLAY_HITBOX_RECT; else { RARCH_ERR("[Overlay]: Hitbox type (%s) is invalid. Use \"radial\" or \"rect\".\n", box); ret = false; goto end; } if (desc->type == OVERLAY_TYPE_ANALOG_LEFT || desc->type == OVERLAY_TYPE_ANALOG_RIGHT) { if (desc->hitbox != OVERLAY_HITBOX_RADIAL) { RARCH_ERR("[Overlay]: Analog hitbox type must be \"radial\".\n"); ret = false; goto end; } char overlay_analog_saturate_key[64]; snprintf(overlay_analog_saturate_key, sizeof(overlay_analog_saturate_key), "overlay%u_desc%u_saturate_pct", ol_index, desc_index); if (!config_get_float(conf, overlay_analog_saturate_key, &desc->analog_saturate_pct)) desc->analog_saturate_pct = 1.0f; } desc->range_x = (float)strtod(list->elems[4].data, NULL) * width_mod; desc->range_y = (float)strtod(list->elems[5].data, NULL) * height_mod; desc->mod_x = desc->x - desc->range_x; desc->mod_w = 2.0f * desc->range_x; desc->mod_y = desc->y - desc->range_y; desc->mod_h = 2.0f * desc->range_y; char conf_key[64]; snprintf(conf_key, sizeof(conf_key), "overlay%u_desc%u_alpha_mod", ol_index, desc_index); desc->alpha_mod = alpha_mod; config_get_float(conf, conf_key, &desc->alpha_mod); snprintf(conf_key, sizeof(conf_key), "overlay%u_desc%u_range_mod", ol_index, desc_index); desc->range_mod = range_mod; config_get_float(conf, conf_key, &desc->range_mod); snprintf(conf_key, sizeof(conf_key), "overlay%u_desc%u_movable", ol_index, desc_index); desc->movable = false; desc->delta_x = 0.0f; desc->delta_y = 0.0f; config_get_bool(conf, conf_key, &desc->movable); desc->range_x_mod = desc->range_x; desc->range_y_mod = desc->range_y; end: if (list) string_list_free(list); return ret; }
int mpd_main(int argc, char *argv[]) { struct options options; clock_t start; bool create_db; GError *error = NULL; bool success; daemonize_close_stdin(); #ifdef HAVE_LOCALE_H /* initialize locale */ setlocale(LC_CTYPE,""); #endif g_set_application_name("Music Player Daemon"); /* enable GLib's thread safety code */ g_thread_init(NULL); io_thread_init(); winsock_init(); idle_init(); tag_pool_init(); config_global_init(); success = parse_cmdline(argc, argv, &options, &error); if (!success) { g_warning("%s", error->message); g_error_free(error); return EXIT_FAILURE; } if (!glue_daemonize_init(&options, &error)) { g_warning("%s", error->message); g_error_free(error); return EXIT_FAILURE; } stats_global_init(); tag_lib_init(); if (!log_init(options.verbose, options.log_stderr, &error)) { g_warning("%s", error->message); g_error_free(error); return EXIT_FAILURE; } success = listen_global_init(&error); if (!success) { g_warning("%s", error->message); g_error_free(error); return EXIT_FAILURE; } daemonize_set_user(); main_task = g_thread_self(); main_loop = g_main_loop_new(NULL, FALSE); main_cond = g_cond_new(); event_pipe_init(); event_pipe_register(PIPE_EVENT_IDLE, idle_event_emitted); event_pipe_register(PIPE_EVENT_SHUTDOWN, shutdown_event_emitted); path_global_init(); if (!glue_mapper_init(&error)) { g_warning("%s", error->message); g_error_free(error); return EXIT_FAILURE; } initPermissions(); playlist_global_init(); spl_global_init(); #ifdef ENABLE_ARCHIVE archive_plugin_init_all(); #endif if (!pcm_resample_global_init(&error)) { g_warning("%s", error->message); g_error_free(error); return EXIT_FAILURE; } decoder_plugin_init_all(); update_global_init(); create_db = !glue_db_init_and_load(); glue_sticker_init(); command_init(); initialize_decoder_and_player(); volume_init(); initAudioConfig(); audio_output_all_init(global_player_control); client_manager_init(); replay_gain_global_init(); if (!input_stream_global_init(&error)) { g_warning("%s", error->message); g_error_free(error); return EXIT_FAILURE; } playlist_list_global_init(); daemonize(options.daemon); setup_log_output(options.log_stderr); initSigHandlers(); if (!io_thread_start(&error)) { g_warning("%s", error->message); g_error_free(error); return EXIT_FAILURE; } initZeroconf(); player_create(global_player_control); if (create_db) { /* the database failed to load: recreate the database */ unsigned job = update_enqueue(NULL, true); if (job == 0) MPD_ERROR("directory update failed"); } if (!glue_state_file_init(&error)) { g_warning("%s", error->message); g_error_free(error); return EXIT_FAILURE; } success = config_get_bool(CONF_AUTO_UPDATE, false); #ifdef ENABLE_INOTIFY if (success && mapper_has_music_directory()) mpd_inotify_init(config_get_unsigned(CONF_AUTO_UPDATE_DEPTH, G_MAXUINT)); #else if (success) g_warning("inotify: auto_update was disabled. enable during compilation phase"); #endif config_global_check(); /* enable all audio outputs (if not already done by playlist_state_restore() */ pc_update_audio(global_player_control); #ifdef WIN32 win32_app_started(); #endif /* run the main loop */ g_main_loop_run(main_loop); #ifdef WIN32 win32_app_stopping(); #endif /* cleanup */ g_main_loop_unref(main_loop); #ifdef ENABLE_INOTIFY mpd_inotify_finish(); #endif state_file_finish(global_player_control); pc_kill(global_player_control); finishZeroconf(); client_manager_deinit(); listen_global_finish(); playlist_global_finish(); start = clock(); db_finish(); g_debug("db_finish took %f seconds", ((float)(clock()-start))/CLOCKS_PER_SEC); #ifdef ENABLE_SQLITE sticker_global_finish(); #endif g_cond_free(main_cond); event_pipe_deinit(); playlist_list_global_finish(); input_stream_global_finish(); audio_output_all_finish(); volume_finish(); mapper_finish(); path_global_finish(); finishPermissions(); pc_free(global_player_control); command_finish(); update_global_finish(); decoder_plugin_deinit_all(); #ifdef ENABLE_ARCHIVE archive_plugin_deinit_all(); #endif config_global_finish(); tag_pool_deinit(); idle_deinit(); stats_global_finish(); io_thread_deinit(); daemonize_finish(); #ifdef WIN32 WSACleanup(); #endif close_log_files(); return EXIT_SUCCESS; }
static bool input_overlay_load_overlay(input_overlay_t *ol, config_file_t *conf, const char *config_path, struct overlay *overlay, unsigned index) { size_t i; char overlay_path_key[64]; char overlay_name_key[64]; char overlay_path[PATH_MAX]; char overlay_resolved_path[PATH_MAX]; snprintf(overlay_path_key, sizeof(overlay_path_key), "overlay%u_overlay", index); if (config_get_path(conf, overlay_path_key, overlay_path, sizeof(overlay_path))) { struct texture_image img = {0}; fill_pathname_resolve_relative(overlay_resolved_path, config_path, overlay_path, sizeof(overlay_resolved_path)); if (texture_image_load(&img, overlay_resolved_path)) overlay->image = img; else { RARCH_ERR("[Overlay]: Failed to load image: %s.\n", overlay_resolved_path); return false; } } snprintf(overlay_name_key, sizeof(overlay_name_key), "overlay%u_name", index); config_get_array(conf, overlay_name_key, overlay->name, sizeof(overlay->name)); // By default, we stretch the overlay out in full. overlay->x = overlay->y = 0.0f; overlay->w = overlay->h = 1.0f; char overlay_rect_key[64]; snprintf(overlay_rect_key, sizeof(overlay_rect_key), "overlay%u_rect", index); char overlay_rect[256]; if (config_get_array(conf, overlay_rect_key, overlay_rect, sizeof(overlay_rect))) { struct string_list *list = string_split(overlay_rect, ", "); if (list->size < 4) { RARCH_ERR("[Overlay]: Failed to split rect \"%s\" into at least four tokens.\n", overlay_rect); return false; } overlay->x = (float)strtod(list->elems[0].data, NULL); overlay->y = (float)strtod(list->elems[1].data, NULL); overlay->w = (float)strtod(list->elems[2].data, NULL); overlay->h = (float)strtod(list->elems[3].data, NULL); string_list_free(list); } char overlay_full_screen_key[64]; snprintf(overlay_full_screen_key, sizeof(overlay_full_screen_key), "overlay%u_full_screen", index); overlay->full_screen = false; config_get_bool(conf, overlay_full_screen_key, &overlay->full_screen); char overlay_descs_key[64]; snprintf(overlay_descs_key, sizeof(overlay_descs_key), "overlay%u_descs", index); unsigned descs = 0; if (!config_get_uint(conf, overlay_descs_key, &descs)) { RARCH_ERR("[Overlay]: Failed to read number of descs from config key: %s.\n", overlay_descs_key); return false; } overlay->descs = (struct overlay_desc*)calloc(descs, sizeof(*overlay->descs)); if (!overlay->descs) { RARCH_ERR("[Overlay]: Failed to allocate descs.\n"); return false; } overlay->size = descs; char conf_key[64]; bool normalized = false; snprintf(conf_key, sizeof(conf_key), "overlay%u_normalized", index); config_get_bool(conf, conf_key, &normalized); float alpha_mod = 1.0f; snprintf(conf_key, sizeof(conf_key), "overlay%u_alpha_mod", index); config_get_float(conf, conf_key, &alpha_mod); float range_mod = 1.0f; snprintf(conf_key, sizeof(conf_key), "overlay%u_range_mod", index); config_get_float(conf, conf_key, &range_mod); for (i = 0; i < overlay->size; i++) { if (!input_overlay_load_desc(ol, conf, &overlay->descs[i], index, i, overlay->image.width, overlay->image.height, normalized, alpha_mod, range_mod)) { RARCH_ERR("[Overlay]: Failed to load overlay descs for overlay #%u.\n", (unsigned)i); return false; } } // Precache load image array for simplicity. overlay->load_images = (struct texture_image*)calloc(1 + overlay->size, sizeof(struct texture_image)); if (!overlay->load_images) { RARCH_ERR("[Overlay]: Failed to allocate load_images.\n"); return false; } if (overlay->image.pixels) overlay->load_images[overlay->load_images_size++] = overlay->image; for (i = 0; i < overlay->size; i++) { if (overlay->descs[i].image.pixels) { overlay->descs[i].image_index = overlay->load_images_size; overlay->load_images[overlay->load_images_size++] = overlay->descs[i].image; } } // Assume for now that scaling center is in the middle. // TODO: Make this configurable. overlay->block_scale = false; overlay->center_x = overlay->x + 0.5f * overlay->w; overlay->center_y = overlay->y + 0.5f * overlay->h; return true; }
bool audio_output_init(struct audio_output *ao, const struct config_param *param, GError **error_r) { const struct audio_output_plugin *plugin = NULL; GError *error = NULL; if (param) { const char *p; p = config_get_block_string(param, AUDIO_OUTPUT_TYPE, NULL); if (p == NULL) { g_set_error(error_r, audio_output_quark(), 0, "Missing \"type\" configuration"); return false; } plugin = audio_output_plugin_get(p); if (plugin == NULL) { g_set_error(error_r, audio_output_quark(), 0, "No such audio output plugin: %s", p); return false; } ao->name = config_get_block_string(param, AUDIO_OUTPUT_NAME, NULL); if (ao->name == NULL) { g_set_error(error_r, audio_output_quark(), 0, "Missing \"name\" configuration"); return false; } p = config_get_block_string(param, AUDIO_OUTPUT_FORMAT, NULL); if (p != NULL) { bool success = audio_format_parse(&ao->config_audio_format, p, true, error_r); if (!success) return false; } else audio_format_clear(&ao->config_audio_format); } else { g_warning("No \"%s\" defined in config file\n", CONF_AUDIO_OUTPUT); plugin = audio_output_detect(error_r); if (plugin == NULL) return false; g_message("Successfully detected a %s audio device", plugin->name); ao->name = "default detected output"; audio_format_clear(&ao->config_audio_format); } ao->plugin = plugin; ao->always_on = config_get_block_bool(param, "always_on", false); ao->enabled = config_get_block_bool(param, "enabled", true); ao->really_enabled = false; ao->open = false; ao->pause = false; ao->fail_timer = NULL; pcm_buffer_init(&ao->cross_fade_buffer); /* set up the filter chain */ ao->filter = filter_chain_new(); assert(ao->filter != NULL); /* create the replay_gain filter */ const char *replay_gain_handler = config_get_block_string(param, "replay_gain_handler", "software"); if (strcmp(replay_gain_handler, "none") != 0) { ao->replay_gain_filter = filter_new(&replay_gain_filter_plugin, param, NULL); assert(ao->replay_gain_filter != NULL); ao->replay_gain_serial = 0; ao->other_replay_gain_filter = filter_new(&replay_gain_filter_plugin, param, NULL); assert(ao->other_replay_gain_filter != NULL); ao->other_replay_gain_serial = 0; } else { ao->replay_gain_filter = NULL; ao->other_replay_gain_filter = NULL; } /* create the normalization filter (if configured) */ if (config_get_bool(CONF_VOLUME_NORMALIZATION, false)) { struct filter *normalize_filter = filter_new(&normalize_filter_plugin, NULL, NULL); assert(normalize_filter != NULL); filter_chain_append(ao->filter, autoconvert_filter_new(normalize_filter)); } filter_chain_parse(ao->filter, config_get_block_string(param, AUDIO_FILTERS, ""), &error ); // It's not really fatal - Part of the filter chain has been set up already // and even an empty one will work (if only with unexpected behaviour) if (error != NULL) { g_warning("Failed to initialize filter chain for '%s': %s", ao->name, error->message); g_error_free(error); } ao->thread = NULL; ao->command = AO_COMMAND_NONE; ao->mutex = g_mutex_new(); ao->cond = g_cond_new(); ao->data = ao_plugin_init(plugin, &ao->config_audio_format, param, error_r); if (ao->data == NULL) return false; ao->mixer = audio_output_load_mixer(ao->data, param, plugin->mixer_plugin, ao->filter, &error); if (ao->mixer == NULL && error != NULL) { g_warning("Failed to initialize hardware mixer for '%s': %s", ao->name, error->message); g_error_free(error); } /* use the hardware mixer for replay gain? */ if (strcmp(replay_gain_handler, "mixer") == 0) { if (ao->mixer != NULL) replay_gain_filter_set_mixer(ao->replay_gain_filter, ao->mixer, 100); else g_warning("No such mixer for output '%s'", ao->name); } else if (strcmp(replay_gain_handler, "software") != 0 && ao->replay_gain_filter != NULL) { g_set_error(error_r, audio_output_quark(), 0, "Invalid \"replay_gain_handler\" value"); return false; } /* the "convert" filter must be the last one in the chain */ ao->convert_filter = filter_new(&convert_filter_plugin, NULL, NULL); assert(ao->convert_filter != NULL); filter_chain_append(ao->filter, ao->convert_filter); /* done */ return true; }
OBSProjector::OBSProjector(QWidget *widget, obs_source_t *source_, int monitor, QString title, ProjectorType type_) : OBSQTDisplay (widget, Qt::Window), source (source_), removedSignal (obs_source_get_signal_handler(source), "remove", OBSSourceRemoved, this) { projectorTitle = std::move(title); savedMonitor = monitor; isWindow = savedMonitor < 0; type = type_; if (isWindow) { setWindowIcon(QIcon::fromTheme("obs", QIcon(":/res/images/obs.png"))); UpdateProjectorTitle(projectorTitle); windowedProjectors.push_back(this); resize(480, 270); } else { setWindowFlags(Qt::FramelessWindowHint | Qt::X11BypassWindowManagerHint); QScreen *screen = QGuiApplication::screens()[savedMonitor]; setGeometry(screen->geometry()); QAction *action = new QAction(this); action->setShortcut(Qt::Key_Escape); addAction(action); connect(action, SIGNAL(triggered()), this, SLOT(EscapeTriggered())); } SetAlwaysOnTop(this, config_get_bool(GetGlobalConfig(), "BasicWindow", "ProjectorAlwaysOnTop")); setAttribute(Qt::WA_DeleteOnClose, true); //disable application quit when last window closed setAttribute(Qt::WA_QuitOnClose, false); installEventFilter(CreateShortcutFilter()); auto addDrawCallback = [this] () { bool isMultiview = type == ProjectorType::Multiview; obs_display_add_draw_callback(GetDisplay(), isMultiview ? OBSRenderMultiview : OBSRender, this); obs_display_set_background_color(GetDisplay(), 0x000000); }; connect(this, &OBSQTDisplay::DisplayCreated, addDrawCallback); bool hideCursor = config_get_bool(GetGlobalConfig(), "BasicWindow", "HideProjectorCursor"); if (hideCursor && !isWindow) { QPixmap empty(16, 16); empty.fill(Qt::transparent); setCursor(QCursor(empty)); } if (type == ProjectorType::Multiview) { obs_enter_graphics(); // All essential action should be placed inside this area gs_render_start(true); gs_vertex2f(actionSafePercentage, actionSafePercentage); gs_vertex2f(actionSafePercentage, 1 - actionSafePercentage); gs_vertex2f(1 - actionSafePercentage, 1 - actionSafePercentage); gs_vertex2f(1 - actionSafePercentage, actionSafePercentage); gs_vertex2f(actionSafePercentage, actionSafePercentage); actionSafeMargin = gs_render_save(); // All graphics should be placed inside this area gs_render_start(true); gs_vertex2f(graphicsSafePercentage, graphicsSafePercentage); gs_vertex2f(graphicsSafePercentage, 1 - graphicsSafePercentage); gs_vertex2f(1 - graphicsSafePercentage, 1 - graphicsSafePercentage); gs_vertex2f(1 - graphicsSafePercentage, graphicsSafePercentage); gs_vertex2f(graphicsSafePercentage, graphicsSafePercentage); graphicsSafeMargin = gs_render_save(); // 4:3 safe area for widescreen gs_render_start(true); gs_vertex2f(fourByThreeSafePercentage, graphicsSafePercentage); gs_vertex2f(1 - fourByThreeSafePercentage, graphicsSafePercentage); gs_vertex2f(1 - fourByThreeSafePercentage, 1 - graphicsSafePercentage); gs_vertex2f(fourByThreeSafePercentage, 1 - graphicsSafePercentage); gs_vertex2f(fourByThreeSafePercentage, graphicsSafePercentage); fourByThreeSafeMargin = gs_render_save(); gs_render_start(true); gs_vertex2f(0.0f, 0.5f); gs_vertex2f(lineLength, 0.5f); leftLine = gs_render_save(); gs_render_start(true); gs_vertex2f(0.5f, 0.0f); gs_vertex2f(0.5f, lineLength); topLine = gs_render_save(); gs_render_start(true); gs_vertex2f(1.0f, 0.5f); gs_vertex2f(1 - lineLength, 0.5f); rightLine = gs_render_save(); obs_leave_graphics(); solid = obs_get_base_effect(OBS_EFFECT_SOLID); color = gs_effect_get_param_by_name(solid, "color"); UpdateMultiview(); multiviewProjectors.push_back(this); } App()->IncrementSleepInhibition(); if (source) obs_source_inc_showing(source); ready = true; show(); // We need it here to allow keyboard input in X11 to listen to Escape if (!isWindow) activateWindow(); }
static bool input_overlay_load_overlay(config_file_t *conf, const char *config_path, struct overlay *overlay, unsigned index) { char overlay_path_key[64]; char overlay_name_key[64]; char overlay_path[PATH_MAX]; char overlay_resolved_path[PATH_MAX]; snprintf(overlay_path_key, sizeof(overlay_path_key), "overlay%u_overlay", index); if (!config_get_path(conf, overlay_path_key, overlay_path, sizeof(overlay_path))) { RARCH_ERR("[Overlay]: Config key: %s is not set.\n", overlay_path_key); return false; } snprintf(overlay_name_key, sizeof(overlay_name_key), "overlay%u_name", index); config_get_array(conf, overlay_name_key, overlay->name, sizeof(overlay->name)); fill_pathname_resolve_relative(overlay_resolved_path, config_path, overlay_path, sizeof(overlay_resolved_path)); struct texture_image img = {0}; if (!texture_image_load(overlay_resolved_path, &img)) { RARCH_ERR("Failed to load image: %s.\n", overlay_path); return false; } overlay->image = img.pixels; overlay->width = img.width; overlay->height = img.height; // By default, we stretch the overlay out in full. overlay->x = overlay->y = 0.0f; overlay->w = overlay->h = 1.0f; char overlay_rect_key[64]; snprintf(overlay_rect_key, sizeof(overlay_rect_key), "overlay%u_rect", index); char overlay_rect[256]; if (config_get_array(conf, overlay_rect_key, overlay_rect, sizeof(overlay_rect))) { struct string_list *list = string_split(overlay_rect, ", "); if (list->size < 4) { RARCH_ERR("[Overlay]: Failed to split rect \"%s\" into at least four tokens.\n", overlay_rect); return false; } overlay->x = strtod(list->elems[0].data, NULL); overlay->y = strtod(list->elems[1].data, NULL); overlay->w = strtod(list->elems[2].data, NULL); overlay->h = strtod(list->elems[3].data, NULL); string_list_free(list); } char overlay_full_screen_key[64]; snprintf(overlay_full_screen_key, sizeof(overlay_full_screen_key), "overlay%u_full_screen", index); overlay->full_screen = false; config_get_bool(conf, overlay_full_screen_key, &overlay->full_screen); char overlay_descs_key[64]; snprintf(overlay_descs_key, sizeof(overlay_descs_key), "overlay%u_descs", index); unsigned descs = 0; if (!config_get_uint(conf, overlay_descs_key, &descs)) { RARCH_ERR("[Overlay]: Failed to read number of descs from config key: %s.\n", overlay_descs_key); return false; } overlay->descs = (struct overlay_desc*)calloc(descs, sizeof(*overlay->descs)); if (!overlay->descs) { RARCH_ERR("[Overlay]: Failed to allocate descs.\n"); return false; } overlay->size = descs; for (size_t i = 0; i < overlay->size; i++) { if (!input_overlay_load_desc(conf, &overlay->descs[i], index, i, img.width, img.height)) { RARCH_ERR("[Overlay]: Failed to load overlay descs for overlay #%u.\n", (unsigned)i); return false; } } // Assume for now that scaling center is in the middle. // TODO: Make this configurable. overlay->block_scale = false; overlay->center_x = overlay->x + 0.5f * overlay->w; overlay->center_y = overlay->y + 0.5f * overlay->h; return true; }
/* reads and parses configuration file */ static int process_configfile(char *configfile) { debug(RPT_DEBUG, "%s()", __FUNCTION__); /* Read server settings*/ if (config_read_file(configfile) != 0) { report(RPT_CRIT, "Could not read config file: %s", configfile); return -1; } if (bind_port == UNSET_INT) bind_port = config_get_int("Server", "Port", 0, UNSET_INT); if (strcmp(bind_addr, UNSET_STR) == 0) strncpy(bind_addr, config_get_string("Server", "Bind", 0, UNSET_STR), sizeof(bind_addr)); if (strcmp(user, UNSET_STR) == 0) strncpy(user, config_get_string("Server", "User", 0, UNSET_STR), sizeof(user)); if (default_duration == UNSET_INT) { default_duration = (config_get_float("Server", "WaitTime", 0, 0) * 1e6 / TIME_UNIT); if (default_duration == 0) default_duration = UNSET_INT; else if (default_duration * TIME_UNIT < 2e6) { report(RPT_WARNING, "Waittime should be at least 2 (seconds). Set to 2 seconds."); default_duration = 2e6 / TIME_UNIT; } } if (foreground_mode == UNSET_INT) { int fg = config_get_bool("Server", "Foreground", 0, UNSET_INT); if (fg != UNSET_INT) foreground_mode = fg; } if (rotate_server_screen == UNSET_INT) { rotate_server_screen = config_get_tristate("Server", "ServerScreen", 0, "blank", UNSET_INT); } if (backlight == UNSET_INT) { backlight = config_get_tristate("Server", "Backlight", 0, "open", UNSET_INT); } if (heartbeat == UNSET_INT) { heartbeat = config_get_tristate("Server", "Heartbeat", 0, "open", UNSET_INT); } if (autorotate == UNSET_INT) { autorotate = config_get_bool("Server", "AutoRotate", 0, DEFAULT_AUTOROTATE); } if (titlespeed == UNSET_INT) { int speed = config_get_int("Server", "TitleSpeed", 0, DEFAULT_TITLESPEED); /* set titlespeed */ titlespeed = (speed <= TITLESPEED_NO) ? TITLESPEED_NO : min(speed, TITLESPEED_MAX); } if (report_dest == UNSET_INT) { int rs = config_get_bool("Server", "ReportToSyslog", 0, UNSET_INT); if (rs != UNSET_INT) report_dest = (rs) ? RPT_DEST_SYSLOG : RPT_DEST_STDERR; } if (report_level == UNSET_INT) { report_level = config_get_int("Server", "ReportLevel", 0, UNSET_INT); } /* Read drivers */ /* If drivers have been specified on the command line, then do not * use the driver list from the config file. */ if (num_drivers == 0) { /* loop over all the Driver= directives to read the driver names */ while (1) { const char *s = config_get_string("Server", "Driver", num_drivers, NULL); if (s == NULL) break; if (s[0] != '\0') { drivernames[num_drivers] = strdup(s); if (drivernames[num_drivers] == NULL) { report(RPT_ERR, "alloc error storing driver name: %s", s); exit(EXIT_FAILURE); } num_drivers++; } } } return 0; }
/** * video_shader_parse_textures: * @conf : Preset file to read from. * @shader : Shader pass handle. * * Parses shader textures. * * Returns: true (1) if successful, otherwise false (0). **/ static bool video_shader_parse_textures(config_file_t *conf, struct video_shader *shader) { char textures[1024]; const char *id = NULL; char *save = NULL; char tmp_path[PATH_MAX_LENGTH]; textures[0] = '\0'; if (!config_get_array(conf, "textures", textures, sizeof(textures))) return true; for (id = strtok_r(textures, ";", &save); id && shader->luts < GFX_MAX_TEXTURES; shader->luts++, id = strtok_r(NULL, ";", &save)) { char id_filter[64]; char id_wrap[64]; char wrap_mode[64]; char id_mipmap[64]; bool mipmap = false; bool smooth = false; id_filter[0] = id_wrap[0] = wrap_mode[0] = id_mipmap[0] = '\0'; if (!config_get_array(conf, id, shader->lut[shader->luts].path, sizeof(shader->lut[shader->luts].path))) { RARCH_ERR("Cannot find path to texture \"%s\" ...\n", id); return false; } strlcpy(tmp_path, shader->lut[shader->luts].path, sizeof(tmp_path)); path_resolve_realpath(tmp_path, sizeof(tmp_path)); if (path_file_exists(tmp_path)) { strlcpy(shader->lut[shader->luts].path, tmp_path, sizeof(shader->lut[shader->luts].path)); } strlcpy(shader->lut[shader->luts].id, id, sizeof(shader->lut[shader->luts].id)); snprintf(id_filter, sizeof(id_filter), "%s_linear", id); if (config_get_bool(conf, id_filter, &smooth)) shader->lut[shader->luts].filter = smooth ? RARCH_FILTER_LINEAR : RARCH_FILTER_NEAREST; else shader->lut[shader->luts].filter = RARCH_FILTER_UNSPEC; snprintf(id_wrap, sizeof(id_wrap), "%s_wrap_mode", id); if (config_get_array(conf, id_wrap, wrap_mode, sizeof(wrap_mode))) shader->lut[shader->luts].wrap = wrap_str_to_mode(wrap_mode); snprintf(id_mipmap, sizeof(id_mipmap), "%s_mipmap", id); if (config_get_bool(conf, id_mipmap, &mipmap)) shader->lut[shader->luts].mipmap = mipmap; else shader->lut[shader->luts].mipmap = false; } return true; }
void scripts_load() { GSList* dir; GList* s; unsigned i; char path[PATH_MAX]; if (!scriptdata) { g_datalist_init(&scriptdata); } /* g_datalist_get_data(&scriptdata, "foo"); g_datalist_set_data_full(&scriptdata,"foo",value,g_free); */ for (dir = scriptdirs; dir; dir = g_slist_next(dir)) { GList* s = dir_to_list(dir->data, script_filter); scripts = merge_sorted_string_lists(scripts, s); } for (s = scripts; s; s = g_list_next(s)) { unsigned version; config_section_iterator* sit; Script* script; const char* filename = s->data; char* errtitle = _("Script error"); // already known? if (g_datalist_get_data(&scriptdata, filename)) { continue; } script = script_new(); snprintf(path, sizeof(path), "/scripts/%s/General", filename); config_push_prefix(path); version = config_get_int("xqf version"); script->summary = config_get_string("summary"); script->author = config_get_string("author"); script->license = config_get_string("license"); config_pop_prefix(); if (version > MAX_SCRIPT_VERSION) { dialog_ok(errtitle, _("Script %s has version %d, xqf only supports version %d."), filename, version, MAX_SCRIPT_VERSION); script_free(script); continue; } if (!script->summary) { dialog_ok(errtitle, _("Script %s missing summary."), filename); script_free(script); continue; } if (!script->author) { dialog_ok(errtitle, _("Script %s missing author."), filename); script_free(script); continue; } if (!script->license) { dialog_ok(errtitle, _("Script %s missing license."), filename); script_free(script); continue; } script->name = g_strdup(filename); snprintf(path, sizeof(path), "/scripts/%s/Action", filename); config_push_prefix(path); for (i = 0; i < NUM_ACTIONS; ++i) { gboolean on = config_get_bool(action_key[i]); if (on) { action[i] = g_slist_prepend(action[i], script); } } config_pop_prefix(); // treat script property 'enabled' as option as it has a widget // so it's easier to handle later { ScriptOption* opt; snprintf(path, sizeof(path), "/" CONFIG_FILE "/scripts/%s/enabled=false", filename); opt = scriptoption_new("bool"); opt->enable = config_get_bool(path); // Translator: whether this plugin script is enabled opt->name = _("Enabled"); opt->section = g_strdup("enabled"); script->options = g_slist_prepend(script->options, opt); } snprintf(path, sizeof(path), "/scripts/%s", filename); sit = config_init_section_iterator(path); while (sit) { char* sname = NULL; sit = config_section_iterator_next(sit, &sname); if (strlen(sname) > 7 && !strncmp(sname, "option ", 7)) { char* typestr; char* name; ScriptOption* opt; char settings_path[PATH_MAX]; snprintf(settings_path, sizeof(settings_path), "/" CONFIG_FILE "/scripts/%s/%s", filename, sname); snprintf(path, sizeof(path), "/scripts/%s/%s", filename, sname); config_push_prefix(path); typestr = config_get_string("type"); name = config_get_string("name"); opt = scriptoption_new(typestr); g_free(typestr); if (!opt || !name) { xqf_warning("script %s: invalid option %s", filename, sname+7); goto next; } opt->name = name; opt->section = sname; switch(opt->type) { case SCRIPT_OPTION_TYPE_LIST: { config_key_iterator* it; it = config_init_iterator(path); if (!opt->list) { opt->list = g_ptr_array_new(); } while (it) { char* key = NULL; char* val = NULL; it = config_iterator_next(it, &key, &val); if (!strncmp(key, "value",5)) { g_ptr_array_add(opt->list, val); } else { g_free(val); } g_free(key); } } // fall through case SCRIPT_OPTION_TYPE_STRING: case SCRIPT_OPTION_TYPE_INT: { char* defval = NULL; char* curval = NULL; defval = config_get_string("default"); curval = config_get_string(settings_path); if (curval) { opt->defval = g_strdup(curval); } else if (defval) { opt->defval = g_strdup(defval); } g_free(defval); g_free(curval); } break; case SCRIPT_OPTION_TYPE_BOOL: { gboolean defval; gboolean curval; int is_deflt = 0; defval = config_get_bool("default=false"); curval = config_get_bool_with_default(settings_path, &is_deflt); if (is_deflt) { opt->enable = defval; } else { opt->enable = curval; } } break; case SCRIPT_OPTION_TYPE_INVALID: xqf_error("unreachable code"); break; } script->options = g_slist_prepend(script->options, opt); next: config_pop_prefix(); } } script->options = g_slist_reverse(script->options); g_datalist_set_data_full(&scriptdata, filename, script, (GDestroyNotify)script_free); snprintf(path, sizeof(path), "/scripts/%s", filename); config_drop_file(path); } }
static core_info_list_t *core_info_list_new(const char *path) { size_t i; core_info_t *core_info = NULL; core_info_list_t *core_info_list = NULL; struct string_list *contents = dir_list_new_special( path, DIR_LIST_CORES, NULL); if (!contents) return NULL; core_info_list = (core_info_list_t*)calloc(1, sizeof(*core_info_list)); if (!core_info_list) goto error; core_info = (core_info_t*)calloc(contents->size, sizeof(*core_info)); if (!core_info) goto error; core_info_list->list = core_info; core_info_list->count = contents->size; for (i = 0; i < contents->size; i++) { char info_path[PATH_MAX_LENGTH]; info_path[0] = '\0'; if ( core_info_list_iterate(info_path, sizeof(info_path), contents, i) && path_is_valid(info_path)) { char *tmp = NULL; bool tmp_bool = false; unsigned count = 0; config_file_t *conf = config_file_new(info_path); if (!conf) continue; if (config_get_string(conf, "display_name", &tmp) && !string_is_empty(tmp)) { core_info[i].display_name = strdup(tmp); free(tmp); tmp = NULL; } if (config_get_string(conf, "corename", &tmp) && !string_is_empty(tmp)) { core_info[i].core_name = strdup(tmp); free(tmp); tmp = NULL; } if (config_get_string(conf, "systemname", &tmp) && !string_is_empty(tmp)) { core_info[i].systemname = strdup(tmp); free(tmp); tmp = NULL; } if (config_get_string(conf, "manufacturer", &tmp) && !string_is_empty(tmp)) { core_info[i].system_manufacturer = strdup(tmp); free(tmp); tmp = NULL; } config_get_uint(conf, "firmware_count", &count); core_info[i].firmware_count = count; if (config_get_string(conf, "supported_extensions", &tmp) && !string_is_empty(tmp)) { core_info[i].supported_extensions = strdup(tmp); core_info[i].supported_extensions_list = string_split(core_info[i].supported_extensions, "|"); free(tmp); tmp = NULL; } if (config_get_string(conf, "authors", &tmp) && !string_is_empty(tmp)) { core_info[i].authors = strdup(tmp); core_info[i].authors_list = string_split(core_info[i].authors, "|"); free(tmp); tmp = NULL; } if (config_get_string(conf, "permissions", &tmp) && !string_is_empty(tmp)) { core_info[i].permissions = strdup(tmp); core_info[i].permissions_list = string_split(core_info[i].permissions, "|"); free(tmp); tmp = NULL; } if (config_get_string(conf, "license", &tmp) && !string_is_empty(tmp)) { core_info[i].licenses = strdup(tmp); core_info[i].licenses_list = string_split(core_info[i].licenses, "|"); free(tmp); tmp = NULL; } if (config_get_string(conf, "categories", &tmp) && !string_is_empty(tmp)) { core_info[i].categories = strdup(tmp); core_info[i].categories_list = string_split(core_info[i].categories, "|"); free(tmp); tmp = NULL; } if (config_get_string(conf, "database", &tmp) && !string_is_empty(tmp)) { core_info[i].databases = strdup(tmp); core_info[i].databases_list = string_split(core_info[i].databases, "|"); free(tmp); tmp = NULL; } if (config_get_string(conf, "notes", &tmp) && !string_is_empty(tmp)) { core_info[i].notes = strdup(tmp); core_info[i].note_list = string_split(core_info[i].notes, "|"); free(tmp); tmp = NULL; } if (tmp) free(tmp); tmp = NULL; if (config_get_bool(conf, "supports_no_game", &tmp_bool)) core_info[i].supports_no_game = tmp_bool; core_info[i].config_data = conf; } if (!string_is_empty(contents->elems[i].data)) core_info[i].path = strdup(contents->elems[i].data); if (!core_info[i].display_name) core_info[i].display_name = strdup(path_basename(core_info[i].path)); } core_info_list_resolve_all_extensions(core_info_list); if (core_info_list) core_info_list_resolve_all_firmware(core_info_list); dir_list_free(contents); return core_info_list; error: if (contents) dir_list_free(contents); core_info_list_free(core_info_list); return NULL; }
/** * video_shader_parse_pass: * @conf : Preset file to read from. * @pass : Shader passes handle. * @i : Index of shader pass. * * Parses shader pass from preset file. * * Returns: true (1) if successful, otherwise false (0). **/ static bool video_shader_parse_pass(config_file_t *conf, struct video_shader_pass *pass, unsigned i) { char shader_name[64] = {0}; char filter_name_buf[64] = {0}; char wrap_name_buf[64] = {0}; char wrap_mode[64] = {0}; char frame_count_mod_buf[64] = {0}; char srgb_output_buf[64] = {0}; char fp_fbo_buf[64] = {0}; char mipmap_buf[64] = {0}; char alias_buf[64] = {0}; char scale_name_buf[64] = {0}; char attr_name_buf[64] = {0}; char scale_type[64] = {0}; char scale_type_x[64] = {0}; char scale_type_y[64] = {0}; char frame_count_mod[64] = {0}; struct gfx_fbo_scale *scale = NULL; bool smooth = false; float fattr = 0.0f; int iattr = 0; /* Source */ snprintf(shader_name, sizeof(shader_name), "shader%u", i); if (!config_get_path(conf, shader_name, pass->source.path, sizeof(pass->source.path))) { RARCH_ERR("Couldn't parse shader source (%s).\n", shader_name); return false; } /* Smooth */ snprintf(filter_name_buf, sizeof(filter_name_buf), "filter_linear%u", i); if (config_get_bool(conf, filter_name_buf, &smooth)) pass->filter = smooth ? RARCH_FILTER_LINEAR : RARCH_FILTER_NEAREST; else pass->filter = RARCH_FILTER_UNSPEC; /* Wrapping mode */ snprintf(wrap_name_buf, sizeof(wrap_name_buf), "wrap_mode%u", i); if (config_get_array(conf, wrap_name_buf, wrap_mode, sizeof(wrap_mode))) pass->wrap = wrap_str_to_mode(wrap_mode); /* Frame count mod */ snprintf(frame_count_mod_buf, sizeof(frame_count_mod_buf), "frame_count_mod%u", i); if (config_get_array(conf, frame_count_mod_buf, frame_count_mod, sizeof(frame_count_mod))) pass->frame_count_mod = strtoul(frame_count_mod, NULL, 0); /* FBO types and mipmapping */ snprintf(srgb_output_buf, sizeof(srgb_output_buf), "srgb_framebuffer%u", i); config_get_bool(conf, srgb_output_buf, &pass->fbo.srgb_fbo); snprintf(fp_fbo_buf, sizeof(fp_fbo_buf), "float_framebuffer%u", i); config_get_bool(conf, fp_fbo_buf, &pass->fbo.fp_fbo); snprintf(mipmap_buf, sizeof(mipmap_buf), "mipmap_input%u", i); config_get_bool(conf, mipmap_buf, &pass->mipmap); snprintf(alias_buf, sizeof(alias_buf), "alias%u", i); if (!config_get_array(conf, alias_buf, pass->alias, sizeof(pass->alias))) *pass->alias = '\0'; /* Scale */ scale = &pass->fbo; snprintf(scale_name_buf, sizeof(scale_name_buf), "scale_type%u", i); config_get_array(conf, scale_name_buf, scale_type, sizeof(scale_type)); snprintf(scale_name_buf, sizeof(scale_name_buf), "scale_type_x%u", i); config_get_array(conf, scale_name_buf, scale_type_x, sizeof(scale_type_x)); snprintf(scale_name_buf, sizeof(scale_name_buf), "scale_type_y%u", i); config_get_array(conf, scale_name_buf, scale_type_y, sizeof(scale_type_y)); if (!*scale_type && !*scale_type_x && !*scale_type_y) return true; if (*scale_type) { strlcpy(scale_type_x, scale_type, sizeof(scale_type_x)); strlcpy(scale_type_y, scale_type, sizeof(scale_type_y)); } scale->valid = true; scale->type_x = RARCH_SCALE_INPUT; scale->type_y = RARCH_SCALE_INPUT; scale->scale_x = 1.0; scale->scale_y = 1.0; if (*scale_type_x) { uint32_t scale_type_x_hash = djb2_calculate(scale_type_x); switch (scale_type_x_hash) { case SCALE_TYPE_SOURCE: scale->type_x = RARCH_SCALE_INPUT; break; case SCALE_TYPE_VIEWPORT: scale->type_x = RARCH_SCALE_VIEWPORT; break; case SCALE_TYPE_ABSOLUTE: scale->type_x = RARCH_SCALE_ABSOLUTE; break; default: RARCH_ERR("Invalid attribute.\n"); return false; } } if (*scale_type_y) { uint32_t scale_type_y_hash = djb2_calculate(scale_type_y); switch (scale_type_y_hash) { case SCALE_TYPE_SOURCE: scale->type_y = RARCH_SCALE_INPUT; break; case SCALE_TYPE_VIEWPORT: scale->type_y = RARCH_SCALE_VIEWPORT; break; case SCALE_TYPE_ABSOLUTE: scale->type_y = RARCH_SCALE_ABSOLUTE; break; default: RARCH_ERR("Invalid attribute.\n"); return false; } } snprintf(attr_name_buf, sizeof(attr_name_buf), "scale%u", i); if (scale->type_x == RARCH_SCALE_ABSOLUTE) { if (config_get_int(conf, attr_name_buf, &iattr)) scale->abs_x = iattr; else { snprintf(attr_name_buf, sizeof(attr_name_buf), "scale_x%u", i); if (config_get_int(conf, attr_name_buf, &iattr)) scale->abs_x = iattr; } } else { if (config_get_float(conf, attr_name_buf, &fattr)) scale->scale_x = fattr; else { snprintf(attr_name_buf, sizeof(attr_name_buf), "scale_x%u", i); if (config_get_float(conf, attr_name_buf, &fattr)) scale->scale_x = fattr; } } snprintf(attr_name_buf, sizeof(attr_name_buf), "scale%u", i); if (scale->type_y == RARCH_SCALE_ABSOLUTE) { if (config_get_int(conf, attr_name_buf, &iattr)) scale->abs_y = iattr; else { snprintf(attr_name_buf, sizeof(attr_name_buf), "scale_y%u", i); if (config_get_int(conf, attr_name_buf, &iattr)) scale->abs_y = iattr; } } else { if (config_get_float(conf, attr_name_buf, &fattr)) scale->scale_y = fattr; else { snprintf(attr_name_buf, sizeof(attr_name_buf), "scale_y%u", i); if (config_get_float(conf, attr_name_buf, &fattr)) scale->scale_y = fattr; } } return true; }
bool input_overlay_load_overlays(input_overlay_t *ol) { unsigned i; config_file_t *conf = NULL; if (!ol) return false; conf = config_file_new(ol->overlay_path); if (!conf) { RARCH_ERR("Failed to load config file: %s.\n", ol->overlay_path); return false; } if (!config_get_uint(conf, "overlays", &ol->config.overlays.size)) { RARCH_ERR("overlays variable not defined in config.\n"); goto error; } if (!ol->config.overlays.size) goto error; ol->overlays = (struct overlay*)calloc( ol->config.overlays.size, sizeof(*ol->overlays)); if (!ol->overlays) goto error; ol->size = ol->config.overlays.size; ol->pos = 0; ol->resolve_pos = 0; for (i = 0; i < ol->size; i++) { char conf_key[64]; char overlay_full_screen_key[64]; struct overlay *overlay = &ol->overlays[i]; if (!overlay) continue; snprintf(overlay->config.descs.key, sizeof(overlay->config.descs.key), "overlay%u_descs", i); if (!config_get_uint(conf, overlay->config.descs.key, &overlay->config.descs.size)) { RARCH_ERR("[Overlay]: Failed to read number of descs from config key: %s.\n", overlay->config.descs.key); goto error; } overlay->descs = (struct overlay_desc*) calloc(overlay->config.descs.size, sizeof(*overlay->descs)); if (!overlay->descs) { RARCH_ERR("[Overlay]: Failed to allocate descs.\n"); goto error; } overlay->size = overlay->config.descs.size; snprintf(overlay_full_screen_key, sizeof(overlay_full_screen_key), "overlay%u_full_screen", i); overlay->full_screen = false; config_get_bool(conf, overlay_full_screen_key, &overlay->full_screen); overlay->config.normalized = false; overlay->config.alpha_mod = 1.0f; overlay->config.range_mod = 1.0f; snprintf(conf_key, sizeof(conf_key), "overlay%u_normalized", i); config_get_bool(conf, conf_key, &overlay->config.normalized); snprintf(conf_key, sizeof(conf_key), "overlay%u_alpha_mod", i); config_get_float(conf, conf_key, &overlay->config.alpha_mod); snprintf(conf_key, sizeof(conf_key), "overlay%u_range_mod", i); config_get_float(conf, conf_key, &overlay->config.range_mod); /* Precache load image array for simplicity. */ overlay->load_images = (struct texture_image*) calloc(1 + overlay->size, sizeof(struct texture_image)); if (!overlay->load_images) { RARCH_ERR("[Overlay]: Failed to allocate load_images.\n"); goto error; } snprintf(overlay->config.paths.key, sizeof(overlay->config.paths.key), "overlay%u_overlay", i); config_get_path(conf, overlay->config.paths.key, overlay->config.paths.path, sizeof(overlay->config.paths.path)); if (overlay->config.paths.path[0] != '\0') { char overlay_resolved_path[PATH_MAX_LENGTH]; struct texture_image img = {0}; fill_pathname_resolve_relative(overlay_resolved_path, ol->overlay_path, overlay->config.paths.path, sizeof(overlay_resolved_path)); if (!texture_image_load(&img, overlay_resolved_path)) { RARCH_ERR("[Overlay]: Failed to load image: %s.\n", overlay_resolved_path); ol->loading_status = OVERLAY_IMAGE_TRANSFER_ERROR; goto error; } overlay->image = img; } snprintf(overlay->config.names.key, sizeof(overlay->config.names.key), "overlay%u_name", i); config_get_array(conf, overlay->config.names.key, overlay->name, sizeof(overlay->name)); /* By default, we stretch the overlay out in full. */ overlay->x = overlay->y = 0.0f; overlay->w = overlay->h = 1.0f; snprintf(overlay->config.rect.key, sizeof(overlay->config.rect.key), "overlay%u_rect", i); if (config_get_array(conf, overlay->config.rect.key, overlay->config.rect.array, sizeof(overlay->config.rect.array))) { struct string_list *list = string_split(overlay->config.rect.array, ", "); if (!list || list->size < 4) { RARCH_ERR("[Overlay]: Failed to split rect \"%s\" into at least four tokens.\n", overlay->config.rect.array); string_list_free(list); goto error; } overlay->x = (float)strtod(list->elems[0].data, NULL); overlay->y = (float)strtod(list->elems[1].data, NULL); overlay->w = (float)strtod(list->elems[2].data, NULL); overlay->h = (float)strtod(list->elems[3].data, NULL); string_list_free(list); } /* Assume for now that scaling center is in the middle. * TODO: Make this configurable. */ overlay->block_scale = false; overlay->center_x = overlay->x + 0.5f * overlay->w; overlay->center_y = overlay->y + 0.5f * overlay->h; } ol->state = OVERLAY_STATUS_DEFERRED_LOADING; config_file_free(conf); return true; error: config_file_free(conf); ol->state = OVERLAY_STATUS_DEFERRED_ERROR; return false; }