(API Change) libobs: Add profile_name_store_t parameter to obs_startup

Due to all the threads in libobs it wouldn't be safe to make that
parameter reconfigurable after libobs is initialized without adding
even more synchronization. On the other hand, adding a function to set
the name store before calling obs_startup would solve the problem of
passing a name store into libobs, but it can lead to more complicated
semantics for obs_get_profiler_name_store (e.g., should it always return
the current name store even if libobs isn't initialized until someone
calls set_name_store(NULL)? should obs_shutdown call
set_name_store(NULL)? Passing it as obs_startup parameter avoids
these (and hopefully other) potential misunderstandings
master
Palana 2015-08-02 12:06:00 +02:00
parent 8d3db084e8
commit 44b5afbd07
7 changed files with 39 additions and 9 deletions

View File

@ -323,6 +323,8 @@ struct obs_core {
proc_handler_t *procs;
char *locale;
bool name_store_owned;
profiler_name_store_t *name_store;
/* segmented into multiple sub-structures to keep things a bit more
* clean and organized */

View File

@ -687,10 +687,17 @@ extern const struct obs_source_info scene_info;
extern void log_system_info(void);
static bool obs_init(const char *locale)
static bool obs_init(const char *locale, profiler_name_store_t *store)
{
obs = bzalloc(sizeof(struct obs_core));
obs->name_store_owned = !store;
obs->name_store = store ? store : profiler_name_store_create();
if (!obs->name_store) {
blog(LOG_ERROR, "Couldn't create profiler name store");
return false;
}
log_system_info();
if (!obs_init_data())
@ -710,7 +717,7 @@ static bool obs_init(const char *locale)
extern void initialize_crash_handler(void);
#endif
bool obs_startup(const char *locale)
bool obs_startup(const char *locale, profiler_name_store_t *store)
{
bool success;
@ -723,7 +730,7 @@ bool obs_startup(const char *locale)
initialize_crash_handler();
#endif
success = obs_init(locale);
success = obs_init(locale, store);
if (!success)
obs_shutdown();
@ -769,6 +776,9 @@ void obs_shutdown(void)
free_module_path(obs->module_paths.array+i);
da_free(obs->module_paths);
if (obs->name_store_owned)
profiler_name_store_free(obs->name_store);
bfree(obs->locale);
bfree(obs);
obs = NULL;
@ -1708,3 +1718,11 @@ void obs_context_data_setname(struct obs_context_data *context,
pthread_mutex_unlock(&context->rename_cache_mutex);
}
profiler_name_store_t *obs_get_profiler_name_store(void)
{
if (!obs)
return NULL;
return obs->name_store;
}

View File

@ -19,6 +19,7 @@
#include "util/c99defs.h"
#include "util/bmem.h"
#include "util/profiler.h"
#include "util/text-lookup.h"
#include "graphics/graphics.h"
#include "graphics/vec2.h"
@ -241,8 +242,9 @@ struct obs_source_frame {
* Initializes OBS
*
* @param locale The locale to use for modules
* @param store The profiler name store for OBS to use or NULL
*/
EXPORT bool obs_startup(const char *locale);
EXPORT bool obs_startup(const char *locale, profiler_name_store_t *store);
/** Releases all data associated with OBS and terminates the OBS context */
EXPORT void obs_shutdown(void);
@ -264,6 +266,13 @@ EXPORT void obs_set_locale(const char *locale);
/** @return the current locale */
EXPORT const char *obs_get_locale(void);
/**
* Returns the profiler name store (see util/profiler.h) used by OBS, which is
* either a name store passed to obs_startup, an internal name store, or NULL
* in case obs_initialized() returns false.
*/
EXPORT profiler_name_store_t *obs_get_profiler_name_store(void);
/**
* Sets base video ouput base resolution/fps/format.
*

View File

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

View File

@ -599,7 +599,7 @@ bool OBSApp::OBSInit()
config_save(globalConfig);
}
obs_startup(locale.c_str());
obs_startup(locale.c_str(), GetProfilerNameStore());
mainWindow = new OBSBasic();
mainWindow->setAttribute(Qt::WA_DeleteOnClose, true);

View File

@ -41,7 +41,7 @@ using DisplayContext = OBSUniqueHandle<obs_display,
static void CreateOBS()
{
if (!obs_startup("en"))
if (!obs_startup("en", nullptr))
throw "Couldn't create OBS";
struct obs_video_info ovi;

View File

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