/** * Driver ownership - set this to true if the platform in question needs to 'own' * the respective handle and therefore skip regular RetroArch * driver teardown/reiniting procedure. * * If to true, the 'free' function will get skipped. It is * then up to the driver implementation to properly handle * 'reiniting' inside the 'init' function and make sure it * returns the existing handle instead of allocating and * returning a pointer to a new handle. * * Typically, if a driver intends to make use of this, it should * set this to true at the end of its 'init' function. **/ void driver_uninit(int flags) { core_info_deinit_list(); core_info_free_current_core(); #ifdef HAVE_MENU if (flags & DRIVER_MENU_MASK) menu_driver_ctl(RARCH_MENU_CTL_DEINIT, NULL); #endif if ((flags & DRIVER_LOCATION_MASK) && !location_driver_ctl(RARCH_LOCATION_CTL_OWNS_DRIVER, NULL)) location_driver_ctl(RARCH_LOCATION_CTL_DEINIT, NULL); if ((flags & DRIVER_CAMERA_MASK) && !camera_driver_ctl(RARCH_CAMERA_CTL_OWNS_DRIVER, NULL)) camera_driver_ctl(RARCH_CAMERA_CTL_DEINIT, NULL); if ((flags & DRIVER_WIFI_MASK) && !wifi_driver_ctl(RARCH_WIFI_CTL_OWNS_DRIVER, NULL)) wifi_driver_ctl(RARCH_WIFI_CTL_DEINIT, NULL); if (flags & DRIVER_LED) led_driver_free(); if (flags & DRIVERS_VIDEO_INPUT) video_driver_free(); if (flags & DRIVER_AUDIO_MASK) audio_driver_deinit(); if ((flags & DRIVER_VIDEO_MASK) && !video_driver_owns_driver()) video_driver_destroy_data(); if ((flags & DRIVER_INPUT_MASK) && !input_driver_owns_driver()) input_driver_destroy_data(); if ((flags & DRIVER_AUDIO_MASK) && !audio_driver_owns_driver()) audio_driver_destroy_data(); if (flags & DRIVER_MIDI_MASK) midi_driver_free(); }
bool driver_wifi_start(void) { return wifi_driver_ctl(RARCH_WIFI_CTL_START, NULL); }
void driver_wifi_stop(void) { wifi_driver_ctl(RARCH_WIFI_CTL_START, NULL); }
bool wifi_driver_ctl(enum rarch_wifi_ctl_state state, void *data) { settings_t *settings = config_get_ptr(); switch (state) { case RARCH_WIFI_CTL_DESTROY: wifi_driver_active = false; wifi_driver_data_own = false; wifi_driver = NULL; wifi_data = NULL; break; case RARCH_WIFI_CTL_SET_OWN_DRIVER: wifi_driver_data_own = true; break; case RARCH_WIFI_CTL_UNSET_OWN_DRIVER: wifi_driver_data_own = false; break; case RARCH_WIFI_CTL_OWNS_DRIVER: return wifi_driver_data_own; case RARCH_WIFI_CTL_SET_ACTIVE: wifi_driver_active = true; break; case RARCH_WIFI_CTL_FIND_DRIVER: { int i; driver_ctx_info_t drv; drv.label = "wifi_driver"; drv.s = settings->wifi.driver; driver_ctl(RARCH_DRIVER_CTL_FIND_INDEX, &drv); i = drv.len; if (i >= 0) wifi_driver = (const wifi_driver_t*)wifi_driver_find_handle(i); else { unsigned d; RARCH_ERR("Couldn't find any wifi driver named \"%s\"\n", settings->wifi.driver); RARCH_LOG_OUTPUT("Available wifi drivers are:\n"); for (d = 0; wifi_driver_find_handle(d); d++) RARCH_LOG_OUTPUT("\t%s\n", wifi_driver_find_ident(d)); RARCH_WARN("Going to default to first wifi driver...\n"); wifi_driver = (const wifi_driver_t*)wifi_driver_find_handle(0); if (!wifi_driver) retroarch_fail(1, "find_wifi_driver()"); } } break; case RARCH_WIFI_CTL_UNSET_ACTIVE: wifi_driver_active = false; break; case RARCH_WIFI_CTL_IS_ACTIVE: return wifi_driver_active; case RARCH_WIFI_CTL_DEINIT: if (wifi_data && wifi_driver) { if (wifi_driver->free) wifi_driver->free(wifi_data); } wifi_data = NULL; break; case RARCH_WIFI_CTL_STOP: if ( wifi_driver && wifi_driver->stop && wifi_data) wifi_driver->stop(wifi_data); break; case RARCH_WIFI_CTL_START: if (wifi_driver && wifi_data && wifi_driver->start) { if (settings->wifi.allow) return wifi_driver->start(wifi_data); } return false; case RARCH_WIFI_CTL_SET_CB: { /*struct retro_wifi_callback *cb = (struct retro_wifi_callback*)data; wifi_cb = *cb;*/ } break; case RARCH_WIFI_CTL_INIT: /* Resource leaks will follow if wifi is initialized twice. */ if (wifi_data) return false; wifi_driver_ctl(RARCH_WIFI_CTL_FIND_DRIVER, NULL); wifi_data = wifi_driver->init(); if (!wifi_data) { RARCH_ERR("Failed to initialize wifi driver. Will continue without wifi.\n"); wifi_driver_ctl(RARCH_WIFI_CTL_UNSET_ACTIVE, NULL); } /*if (wifi_cb.initialized) wifi_cb.initialized();*/ break; default: break; } return false; }
bool driver_ctl(enum driver_ctl_state state, void *data) { switch (state) { case RARCH_DRIVER_CTL_DEINIT: video_driver_destroy(); audio_driver_destroy(); input_driver_destroy(); #ifdef HAVE_MENU menu_driver_destroy(); #endif location_driver_ctl(RARCH_LOCATION_CTL_DESTROY, NULL); camera_driver_ctl(RARCH_CAMERA_CTL_DESTROY, NULL); wifi_driver_ctl(RARCH_WIFI_CTL_DESTROY, NULL); core_uninit_libretro_callbacks(); break; case RARCH_DRIVER_CTL_INIT_PRE: audio_driver_find_driver(); video_driver_find_driver(); input_driver_find_driver(); camera_driver_ctl(RARCH_CAMERA_CTL_FIND_DRIVER, NULL); wifi_driver_ctl(RARCH_WIFI_CTL_FIND_DRIVER, NULL); find_location_driver(); #ifdef HAVE_MENU menu_driver_ctl(RARCH_MENU_CTL_FIND_DRIVER, NULL); #endif break; case RARCH_DRIVER_CTL_SET_REFRESH_RATE: { float *hz = (float*)data; video_monitor_set_refresh_rate(*hz); audio_driver_monitor_set_rate(); driver_adjust_system_rates(); } break; case RARCH_DRIVER_CTL_UPDATE_SYSTEM_AV_INFO: { const struct retro_system_av_info **info = (const struct retro_system_av_info**)data; if (info) return driver_update_system_av_info(*info); } return false; case RARCH_DRIVER_CTL_FIND_FIRST: { driver_ctx_info_t *drv = (driver_ctx_info_t*)data; if (!drv) return false; return driver_find_first(drv->label, drv->s, drv->len); } case RARCH_DRIVER_CTL_FIND_LAST: { driver_ctx_info_t *drv = (driver_ctx_info_t*)data; if (!drv) return false; return driver_find_last(drv->label, drv->s, drv->len); } case RARCH_DRIVER_CTL_FIND_PREV: { driver_ctx_info_t *drv = (driver_ctx_info_t*)data; if (!drv) return false; return driver_find_prev(drv->label, drv->s, drv->len); } case RARCH_DRIVER_CTL_FIND_NEXT: { driver_ctx_info_t *drv = (driver_ctx_info_t*)data; if (!drv) return false; return driver_find_next(drv->label, drv->s, drv->len); } case RARCH_DRIVER_CTL_FIND_INDEX: { driver_ctx_info_t *drv = (driver_ctx_info_t*)data; if (!drv) return false; drv->len = driver_find_index(drv->label, drv->s); } break; case RARCH_DRIVER_CTL_NONE: default: break; } return true; }
/** * drivers_init: * @flags : Bitmask of drivers to initialize. * * Initializes drivers. * @flags determines which drivers get initialized. **/ void drivers_init(int flags) { bool video_is_threaded = false; if (flags & DRIVER_VIDEO_MASK) video_driver_unset_own_driver(); if (flags & DRIVER_AUDIO_MASK) audio_driver_unset_own_driver(); if (flags & DRIVER_INPUT_MASK) input_driver_unset_own_driver(); if (flags & DRIVER_CAMERA_MASK) camera_driver_ctl(RARCH_CAMERA_CTL_UNSET_OWN_DRIVER, NULL); if (flags & DRIVER_LOCATION_MASK) location_driver_ctl(RARCH_LOCATION_CTL_UNSET_OWN_DRIVER, NULL); if (flags & DRIVER_WIFI_MASK) wifi_driver_ctl(RARCH_WIFI_CTL_UNSET_OWN_DRIVER, NULL); #ifdef HAVE_MENU /* By default, we want the menu to persist through driver reinits. */ menu_driver_ctl(RARCH_MENU_CTL_SET_OWN_DRIVER, NULL); #endif if (flags & (DRIVER_VIDEO_MASK | DRIVER_AUDIO_MASK)) driver_adjust_system_rates(); if (flags & DRIVER_VIDEO_MASK) { struct retro_hw_render_callback *hwr = video_driver_get_hw_context(); video_driver_monitor_reset(); video_driver_init(&video_is_threaded); if (!video_driver_is_video_cache_context_ack() && hwr->context_reset) hwr->context_reset(); video_driver_unset_video_cache_context_ack(); rarch_ctl(RARCH_CTL_SET_FRAME_TIME_LAST, NULL); } if (flags & DRIVER_AUDIO_MASK) { audio_driver_init(); audio_driver_new_devices_list(); } /* Only initialize camera driver if we're ever going to use it. */ if ((flags & DRIVER_CAMERA_MASK) && camera_driver_ctl(RARCH_CAMERA_CTL_IS_ACTIVE, NULL)) camera_driver_ctl(RARCH_CAMERA_CTL_INIT, NULL); /* Only initialize location driver if we're ever going to use it. */ if ((flags & DRIVER_LOCATION_MASK) && location_driver_ctl(RARCH_LOCATION_CTL_IS_ACTIVE, NULL)) init_location(); core_info_init_current_core(); #ifdef HAVE_MENU if (flags & DRIVER_VIDEO_MASK) { if (flags & DRIVER_MENU_MASK) menu_driver_init(video_is_threaded); } #endif if (flags & (DRIVER_VIDEO_MASK | DRIVER_AUDIO_MASK)) { /* Keep non-throttled state as good as possible. */ if (input_driver_is_nonblock_state()) driver_set_nonblock_state(); } if (flags & DRIVER_LED_MASK) { led_driver_init(); } if (flags & DRIVER_MIDI_MASK) midi_driver_init(); }