0
0
mirror of https://github.com/obsproject/obs-studio.git synced 2024-09-20 04:42:18 +02:00

(API Change) libobs: Add global module config path

API Changed:
---------------------------
From:
- bool obs_startup(const char *locale, profiler_name_store_t *store);

To:
- bool obs_startup(const char *locale, const char *module_config_path,
		profiler_name_store_t *store);

Summary:
---------------------------
This allows plugin modules to store plugin-specific configuration data
(rather than only allowing objects to store configuration data).  This
will be useful for things like caching data, for example looking up and
storing ingests from remote (rather than storing locally), or caching
font data (so it doesn't have to build a font cache each time), among
other things.

Also adds a module-specific directory for the UI
This commit is contained in:
jp9000 2015-08-09 05:09:07 -07:00
parent 0ce756acba
commit 2bd8ab7c09
6 changed files with 35 additions and 9 deletions

View File

@ -324,6 +324,7 @@ struct obs_core {
proc_handler_t *procs; proc_handler_t *procs;
char *locale; char *locale;
char *module_config_path;
bool name_store_owned; bool name_store_owned;
profiler_name_store_t *name_store; profiler_name_store_t *name_store;

View File

@ -687,7 +687,8 @@ extern const struct obs_source_info scene_info;
extern void log_system_info(void); extern void log_system_info(void);
static bool obs_init(const char *locale, profiler_name_store_t *store) static bool obs_init(const char *locale, const char *module_config_path,
profiler_name_store_t *store)
{ {
obs = bzalloc(sizeof(struct obs_core)); obs = bzalloc(sizeof(struct obs_core));
@ -707,6 +708,8 @@ static bool obs_init(const char *locale, profiler_name_store_t *store)
if (!obs_init_hotkeys()) if (!obs_init_hotkeys())
return false; return false;
if (module_config_path)
obs->module_config_path = bstrdup(module_config_path);
obs->locale = bstrdup(locale); obs->locale = bstrdup(locale);
obs_register_source(&scene_info); obs_register_source(&scene_info);
add_default_module_paths(); add_default_module_paths();
@ -718,7 +721,8 @@ extern void initialize_crash_handler(void);
#endif #endif
static const char *obs_startup_name = "obs_startup"; static const char *obs_startup_name = "obs_startup";
bool obs_startup(const char *locale, profiler_name_store_t *store) bool obs_startup(const char *locale, const char *module_config_path,
profiler_name_store_t *store)
{ {
bool success; bool success;
@ -733,7 +737,7 @@ bool obs_startup(const char *locale, profiler_name_store_t *store)
initialize_crash_handler(); initialize_crash_handler();
#endif #endif
success = obs_init(locale, store); success = obs_init(locale, module_config_path, store);
profile_end(obs_startup_name); profile_end(obs_startup_name);
if (!success) if (!success)
obs_shutdown(); obs_shutdown();
@ -783,6 +787,7 @@ void obs_shutdown(void)
if (obs->name_store_owned) if (obs->name_store_owned)
profiler_name_store_free(obs->name_store); profiler_name_store_free(obs->name_store);
bfree(obs->module_config_path);
bfree(obs->locale); bfree(obs->locale);
bfree(obs); bfree(obs);
obs = NULL; obs = NULL;

View File

@ -242,9 +242,12 @@ struct obs_source_frame {
* Initializes OBS * Initializes OBS
* *
* @param locale The locale to use for modules * @param locale The locale to use for modules
* @param module_config_path Path to module config storage directory
* (or NULL if none)
* @param store The profiler name store for OBS to use or NULL * @param store The profiler name store for OBS to use or NULL
*/ */
EXPORT bool obs_startup(const char *locale, profiler_name_store_t *store); EXPORT bool obs_startup(const char *locale, const char *module_config_path,
profiler_name_store_t *store);
/** Releases all data associated with OBS and terminates the OBS context */ /** Releases all data associated with OBS and terminates the OBS context */
EXPORT void obs_shutdown(void); EXPORT void obs_shutdown(void);

View File

@ -275,9 +275,10 @@ class OBSContext {
public: public:
inline OBSContext() {} inline OBSContext() {}
inline OBSContext(const char *locale, inline OBSContext(const char *locale,
const char *module_config_path=nullptr,
profiler_name_store *store=nullptr) profiler_name_store *store=nullptr)
{ {
obs_startup(locale, store); obs_startup(locale, module_config_path, store);
} }
inline ~OBSContext() inline ~OBSContext()

View File

@ -320,6 +320,10 @@ static bool MakeUserDirs()
if (!do_mkdir(path)) if (!do_mkdir(path))
return false; return false;
#endif #endif
if (GetConfigPath(path, sizeof(path), "obs-studio/plugin_config") <= 0)
return false;
if (!do_mkdir(path))
return false;
return true; return true;
} }
@ -592,6 +596,16 @@ const char *OBSApp::GetRenderModule() const
DL_D3D11 : DL_OPENGL; DL_D3D11 : DL_OPENGL;
} }
static bool StartupOBS(const char *locale, profiler_name_store_t *store)
{
char path[512];
if (GetConfigPath(path, sizeof(path), "obs-studio/plugin_config") <= 0)
return false;
return obs_startup(locale, path, store);
}
bool OBSApp::OBSInit() bool OBSApp::OBSInit()
{ {
ProfileScope("OBSApp::OBSInit"); ProfileScope("OBSApp::OBSInit");
@ -607,7 +621,9 @@ bool OBSApp::OBSInit()
config_save(globalConfig); config_save(globalConfig);
} }
obs_startup(locale.c_str(), GetProfilerNameStore()); if (!StartupOBS(locale.c_str(), GetProfilerNameStore()))
return false;
mainWindow = new OBSBasic(); mainWindow = new OBSBasic();
mainWindow->setAttribute(Qt::WA_DeleteOnClose, true); mainWindow->setAttribute(Qt::WA_DeleteOnClose, true);

View File

@ -82,7 +82,7 @@ static void CreateOBS(HWND hwnd)
RECT rc; RECT rc;
GetClientRect(hwnd, &rc); GetClientRect(hwnd, &rc);
if (!obs_startup("en-US", nullptr)) if (!obs_startup("en-US", nullptr, nullptr))
throw "Couldn't create OBS"; throw "Couldn't create OBS";
struct obs_video_info ovi; struct obs_video_info ovi;